taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit 0dd975e825daf88440824d2452f85c95daf72c57
parent 71e938bd96d0d0a8b1954a48cb1bd9e7d93a1e56
Author: Florian Dold <dold@taler.net>
Date:   Tue, 21 Jul 2026 10:52:38 +0200

util: match account restrictions against the normalized payto

Both callers pass a full URI straight from the bank, which usually carries
a receiver-name parameter, so an account the exchange allows was refused
locally.

Diffstat:
Mpackages/taler-util/src/account-restrictions.ts | 24++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/packages/taler-util/src/account-restrictions.ts b/packages/taler-util/src/account-restrictions.ts @@ -14,13 +14,33 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ +import { Paytos } from "./payto.js"; +import { Result } from "./result.js"; import { InternationalizedString } from "./types-taler-common.js"; import { AccountRestriction } from "./types-taler-exchange.js"; +/** + * Restrictions apply to the normalized payto://-URI. Callers hand us + * whatever the bank or the user supplied, which typically still carries a + * receiver-name parameter, so normalize here. A URI we cannot parse is + * matched as given rather than rejected outright, leaving the verdict to + * the regex. + */ +function normalizeForMatching( + paytoUri: Paytos.FullPaytoString | Paytos.NormalizedPaytoString | string, +): string { + const parsed = Paytos.fromString(paytoUri as Paytos.FullPaytoString); + if (Result.isError(parsed)) { + return paytoUri; + } + return Paytos.toNormalizedString(parsed.value); +} + export function checkAccountRestriction( - paytoUri: string, + paytoUri: Paytos.FullPaytoString | Paytos.NormalizedPaytoString | string, restrictions: AccountRestriction[], ): { ok: boolean; hint?: string; hintI18n?: InternationalizedString } { + const normalizedPayto = normalizeForMatching(paytoUri); for (const myRestriction of restrictions) { switch (myRestriction.type) { case "deny": @@ -37,7 +57,7 @@ export function checkAccountRestriction( hintI18n: myRestriction.human_hint_i18n, }; } - if (!regex.test(paytoUri)) { + if (!regex.test(normalizedPayto)) { return { ok: false, hint: myRestriction.human_hint,