taler-typescript-core

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

commit 3465664febdc0b7b917e9e9300b1680b13d7e5c7
parent fc3592a0bd0af758261b3bf552b943268eaaad78
Author: Florian Dold <dold@taler.net>
Date:   Mon, 20 Jul 2026 13:58:58 +0200

util: do not throw parsing invalid crock32 in payto URI when ignoreComponentError is set

Diffstat:
Mpackages/taler-util/src/payto.test.ts | 23+++++++++++++++++++++++
Mpackages/taler-util/src/payto.ts | 4++--
2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/packages/taler-util/src/payto.test.ts b/packages/taler-util/src/payto.test.ts @@ -197,3 +197,26 @@ test("void payto URI", () => { Result.isOk(Paytos.fromString("payto://void/foo?receiver-name=Bla")), ); }); + +test("taler-reserve payto with an unparseable reservePub does not throw when ignoring component errors", () => { + const bad = "payto://taler-reserve/exchange.example.com/not-valid-crock!!"; + + // Without ignoreComponentError, this is reported as a normal error result. + const strict = Paytos.fromString(bad); + assert.strictEqual(strict.tag, "error"); + + // With ignoreComponentError, parsing must not throw, and must fall back + // to a documented (zero-filled, still 32 bytes) sentinel instead of + // re-decoding the raw (invalid) string. + const lenient = Paytos.fromString(bad, { ignoreComponentError: true }); + if (lenient.tag === "error") { + assert.fail("expected an ok result with ignoreComponentError set"); + throw Error(); + } + if (lenient.value.targetType !== PaytoType.TalerReserve) { + assert.fail(lenient.value.targetType); + throw Error(); + } + assert.strictEqual(lenient.value.reservePub.length, 32); + assert.ok(lenient.value.reservePub.every((b) => b === 0)); +}); diff --git a/packages/taler-util/src/payto.ts b/packages/taler-util/src/payto.ts @@ -746,7 +746,7 @@ export namespace Paytos { return Result.of<URI>( createTalerReserve( exchange ?? (cs[0] as HostPortPath), - Result.isOk(pubRes) ? pubRes.value : decodeCrock(reservePub), + Result.isOk(pubRes) ? pubRes.value : new Uint8Array(32), params, ), ); @@ -782,7 +782,7 @@ export namespace Paytos { return Result.of<URI>( createTalerReserveHttp( exchange ?? (cs[0] as HostPortPath), - Result.isOk(pubRes) ? pubRes.value : decodeCrock(reservePub), + Result.isOk(pubRes) ? pubRes.value : new Uint8Array(32), params, ), );