commit 4b4ebfba34811416347cdf691c420a62472e4102
parent bb89eca3f423d7365a409d56bbbdadd265e74bf4
Author: Florian Dold <florian@dold.me>
Date: Sat, 18 Jul 2026 18:27:35 +0200
remove more deprecated helper usages
Diffstat:
8 files changed, 63 insertions(+), 190 deletions(-)
diff --git a/packages/taler-merchant-webui/src/components/form/InputPaytoForm.tsx b/packages/taler-merchant-webui/src/components/form/InputPaytoForm.tsx
@@ -24,7 +24,6 @@ import {
TranslatedString,
Paytos,
Result,
- stringifyPaytoUri,
} from "@gnu-taler/taler-util";
import { useTranslationContext } from "@gnu-taler/web-util/browser";
import { Fragment, VNode, h } from "preact";
@@ -306,7 +305,15 @@ export function InputPaytoForm<T>({
isKnown: false as const,
} as PaytoUri);
- const str = !pto ? undefined : stringifyPaytoUri(pto);
+ const str = !pto
+ ? undefined
+ : Paytos.toFullString({
+ targetType: pto.targetType,
+ fullPath: pto.targetPath,
+ normalizedPath: pto.targetPath,
+ displayName: pto.targetPath,
+ params: pto.params,
+ } as unknown as Paytos.URI);
const regexError = checkServerRegex(i18n, str, config.payment_target_regex);
diff --git a/packages/taler-util/src/payto.test.ts b/packages/taler-util/src/payto.test.ts
@@ -18,107 +18,11 @@ import assert from "node:assert";
import { test } from "node:test";
import {
- PaytoString,
addPaytoQueryParams,
- parsePaytoUri,
- stringifyPaytoUri,
+ HostPortPath,
+ PaytoType,
+ Paytos,
} from "./payto.js";
-
-test("basic payto parsing", (t) => {
- const r1 = parsePaytoUri("https://example.com/");
- assert.strictEqual(r1, undefined);
-
- const r2 = parsePaytoUri("payto:blabla");
- assert.strictEqual(r2, undefined);
-
- const r3 = parsePaytoUri("payto://x-taler-bank/123");
- assert.strictEqual(r3?.targetType, "x-taler-bank");
- assert.strictEqual(r3?.targetPath, "123");
-});
-
-test("basic x-taler-bank payto string", (t) => {
- const result = parsePaytoUri(
- "payto://x-taler-bank/bank.demo.taler.net/asd/accountName",
- );
- assert.strictEqual(result?.targetType, "x-taler-bank");
- assert.strictEqual(result?.targetPath, "bank.demo.taler.net/asd/accountName");
- if (!result) {
- assert.fail();
- throw Error();
- }
- if (!result.isKnown) {
- assert.fail();
- throw Error();
- }
- if (result.targetType !== "x-taler-bank") {
- assert.fail();
- throw Error();
- }
- assert.strictEqual(result.host, "bank.demo.taler.net");
- assert.strictEqual(result.account, "accountName");
-});
-
-test("parsing payto and stringify again", (t) => {
- const payto1 =
- "payto://iban/DE1231231231?reciever-name=John%20Doe" as PaytoString;
-
- assert.strictEqual(stringifyPaytoUri(parsePaytoUri(payto1)!), payto1);
-});
-test("parsing payto with % carh", (t) => {
- const payto1 =
- "payto://iban/DE7763544441436?receiver-name=Test%20123%2B-%24%25%5E%3Cem%3Ehi%3C%2Fem%3E" as PaytoString;
-
- assert.strictEqual(stringifyPaytoUri(parsePaytoUri(payto1)!), payto1);
-});
-
-test("adding payto query params", (t) => {
- const payto1 =
- "payto://iban/DE1231231231?receiver-name=John%20Doe" as PaytoString;
- const out1 = addPaytoQueryParams(payto1, {});
- assert.deepStrictEqual(payto1, out1);
-
- const out2 = addPaytoQueryParams(payto1, {
- message: "42",
- });
- assert.deepStrictEqual(
- out2,
- "payto://iban/DE1231231231?receiver-name=John%20Doe&message=42",
- );
-});
-
-test("parsing payto and stringify again but with cyclos", (t) => {
- const payto1 =
- "payto://cyclos/communities.cyclos.org/utrecht/31000163100000000?reciever-name=John%20Doe" as PaytoString;
-
- assert.strictEqual(stringifyPaytoUri(parsePaytoUri(payto1)!), payto1);
-});
-
-test("basic cyclos payto string", (t) => {
- const result = parsePaytoUri(
- "payto://cyclos/communities.cyclos.org/utrecht/31000163100000000",
- );
- assert.strictEqual(result?.targetType, "cyclos");
- assert.strictEqual(
- result?.targetPath,
- "communities.cyclos.org/utrecht/31000163100000000",
- );
- if (!result) {
- assert.fail();
- throw Error();
- }
- if (!result.isKnown) {
- assert.fail();
- throw Error();
- }
- if (result.targetType !== "cyclos") {
- assert.fail();
- throw Error();
- }
- assert.strictEqual(result.host, "communities.cyclos.org");
- assert.strictEqual(result.account, "31000163100000000");
-});
-
-import { HostPortPath, PaytoType, Paytos } from "./payto.js";
import { Result } from "./result.js";
test("basic payto parsing", (t) => {
@@ -155,10 +59,7 @@ test("basic x-taler-bank payto string", (t) => {
}
assert.strictEqual(result.normalizedPath, "bank.demo.taler.net/accountName");
assert.strictEqual(result.host, "bank.demo.taler.net");
- assert.strictEqual(
- result.url,
- "https://bank.demo.taler.net/" as HostPortPath,
- );
+ assert.strictEqual(result.url, "https://bank.demo.taler.net/" as HostPortPath);
assert.strictEqual(result.account, "accountName");
});
@@ -208,7 +109,7 @@ test("parsing payto with % carh", (t) => {
);
});
-test("adding payto query params", (t) => {
+test("adding payto query params via toFullString", (t) => {
const payto1 =
"payto://iban/DE1231231231?receiver-name=John%20Doe" as Paytos.FullPaytoString;
const p = Result.unpack(Paytos.fromString(payto1));
@@ -221,6 +122,20 @@ test("adding payto query params", (t) => {
);
});
+test("addPaytoQueryParams adds and preserves params", (t) => {
+ const payto1 = "payto://iban/DE1231231231?receiver-name=John%20Doe";
+ const out1 = addPaytoQueryParams(payto1, {});
+ assert.deepStrictEqual(payto1, out1);
+
+ const out2 = addPaytoQueryParams(payto1, {
+ message: "42",
+ });
+ assert.deepStrictEqual(
+ out2,
+ "payto://iban/DE1231231231?receiver-name=John%20Doe&message=42",
+ );
+});
+
test("basic cyclos payto string", (t) => {
{
const result = Result.unpack(
diff --git a/packages/taler-wallet-core/src/common.ts b/packages/taler-wallet-core/src/common.ts
@@ -55,6 +55,9 @@ import {
getQrCodesForPayto,
j2s,
succeedOrThrow,
+ decodeCrock,
+ HostPortPath,
+ Paytos,
} from "@gnu-taler/taler-util";
import { HttpRequestOptions, HttpResponse } from "@gnu-taler/taler-util/http";
import {
@@ -1300,3 +1303,18 @@ export function augmentTransferOptions(
}
return res;
}
+
+/**
+ * Build the canonical taler-reserve(-http) full payto-URI for a reserve at an
+ * exchange, replacing the deprecated talerPaytoFromExchangeReserve.
+ */
+export function reservePaytoFromExchange(
+ exchangeBaseUrl: string,
+ reservePub: string,
+): Paytos.FullPaytoString {
+ const pub = decodeCrock(reservePub);
+ const uri = exchangeBaseUrl.startsWith("http://")
+ ? Paytos.createTalerReserveHttp(exchangeBaseUrl as HostPortPath, pub)
+ : Paytos.createTalerReserve(exchangeBaseUrl as HostPortPath, pub);
+ return Paytos.toFullString(uri);
+}
diff --git a/packages/taler-wallet-core/src/exchanges.ts b/packages/taler-wallet-core/src/exchanges.ts
@@ -109,7 +109,6 @@ import {
makeErrorDetail,
makeTalerErrorDetail,
stringifyScopeInfo,
- talerPaytoFromExchangeReserve,
} from "@gnu-taler/taler-util";
import {
HttpRequestLibrary,
@@ -135,6 +134,7 @@ import {
getExchangeTosStatusFromRecord,
getExchangeUpdateStatusFromRecord,
getRetryDuration,
+ reservePaytoFromExchange,
} from "./common.js";
import {
DenomLossStatus,
@@ -3971,7 +3971,7 @@ async function handleExchangeKycPendingLegitimization(
accountPub: reserve.reservePub,
});
- const reservePayto = talerPaytoFromExchangeReserve(
+ const reservePayto = reservePaytoFromExchange(
exchange.baseUrl,
reserve.reservePub,
);
diff --git a/packages/taler-wallet-core/src/pay-peer-pull-credit.ts b/packages/taler-wallet-core/src/pay-peer-pull-credit.ts
@@ -49,7 +49,6 @@ import {
encodeCrock,
getRandomBytes,
j2s,
- talerPaytoFromExchangeReserve,
} from "@gnu-taler/taler-util";
import {
PendingTaskType,
@@ -63,6 +62,7 @@ import {
getGenericRecordHandle,
requireExchangeTosAcceptedOrThrow,
runWithClientCancellation,
+ reservePaytoFromExchange,
} from "./common.js";
import {
PeerPullPaymentCreditStatus,
@@ -805,7 +805,7 @@ async function processPeerPullCreditCreatePurse(
const contractTerms: PeerContractTerms = contractTermsRecord.contractTermsRaw;
- const reservePayto = talerPaytoFromExchangeReserve(
+ const reservePayto = reservePaytoFromExchange(
pullIni.exchangeBaseUrl,
mergeReserve.reservePub,
);
diff --git a/packages/taler-wallet-core/src/pay-peer-push-credit.ts b/packages/taler-wallet-core/src/pay-peer-push-credit.ts
@@ -52,7 +52,6 @@ import {
encodeCrock,
getRandomBytes,
j2s,
- talerPaytoFromExchangeReserve,
} from "@gnu-taler/taler-util";
import {
PendingTaskType,
@@ -65,6 +64,7 @@ import {
genericWaitForStateVal,
getGenericRecordHandle,
requireExchangeTosAcceptedOrThrow,
+ reservePaytoFromExchange,
} from "./common.js";
import {
PeerPushCreditStatus,
@@ -821,7 +821,7 @@ async function processPendingMerge(
AbsoluteTime.fromPreciseTimestamp(timestamp),
);
- const reservePayto = talerPaytoFromExchangeReserve(
+ const reservePayto = reservePaytoFromExchange(
peerInc.exchangeBaseUrl,
mergeReserveInfo.reservePub,
);
diff --git a/packages/taler-wallet-webextension/src/wallet/DepositPage/stories.tsx b/packages/taler-wallet-webextension/src/wallet/DepositPage/stories.tsx
@@ -19,7 +19,7 @@
* @author Sebastian Javier Marchano (sebasjm)
*/
-import { Amounts, stringifyPaytoUri } from "@gnu-taler/taler-util";
+import { Amounts } from "@gnu-taler/taler-util";
import * as tests from "@gnu-taler/web-util/testing";
import { nullFunction } from "../../mui/handlers.js";
import { ReadyView } from "./views.js";
@@ -35,13 +35,7 @@ export const WithNoAccountForIBAN = tests.createExample(ReadyView, {
value: "",
onChange: nullFunction,
},
- currentAccount: stringifyPaytoUri({
- isKnown: true,
- targetType: "iban",
- iban: "ABCD1234",
- params: {},
- targetPath: "/ABCD1234",
- }),
+ currentAccount: "payto://iban//ABCD1234",
currency: "USD",
amount: {
onInput: nullFunction,
@@ -67,13 +61,7 @@ export const WithIBANAccountTypeSelected = tests.createExample(ReadyView, {
value: "asdlkajsdlk",
onChange: nullFunction,
},
- currentAccount: stringifyPaytoUri({
- isKnown: true,
- targetType: "iban",
- iban: "ABCD1234",
- params: {},
- targetPath: "/ABCD1234",
- }),
+ currentAccount: "payto://iban//ABCD1234",
currency: "USD",
amount: {
onInput: nullFunction,
@@ -99,13 +87,7 @@ export const NewBitcoinAccountTypeSelected = tests.createExample(ReadyView, {
value: "asdlkajsdlk",
onChange: nullFunction,
},
- currentAccount: stringifyPaytoUri({
- isKnown: true,
- targetType: "iban",
- iban: "ABCD1234",
- params: {},
- targetPath: "/ABCD1234",
- }),
+ currentAccount: "payto://iban//ABCD1234",
onAddAccount: {},
currency: "USD",
amount: {
diff --git a/packages/taler-wallet-webextension/src/wallet/ManageAccount/stories.tsx b/packages/taler-wallet-webextension/src/wallet/ManageAccount/stories.tsx
@@ -19,7 +19,6 @@
* @author Sebastian Javier Marchano (sebasjm)
*/
-import { stringifyPaytoUri } from "@gnu-taler/taler-util";
import * as tests from "@gnu-taler/web-util/testing";
import { nullFunction } from "../../mui/handlers.js";
import { ReadyView } from "./views.js";
@@ -56,28 +55,14 @@ export const JustTwoBitcoinAccounts = tests.createExample(ReadyView, {
label: "my bitcoin addr",
currencies: ["BTC"],
kycCompleted: false,
- paytoUri: stringifyPaytoUri({
- targetType: "bitcoin",
- segwitAddrs: [],
- isKnown: true,
- address: "bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh",
- targetPath: "bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh",
- params: {},
- }),
+ paytoUri: "payto://bitcoin/bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh",
},
{
bankAccountId: "acct:2",
label: "my other addr",
currencies: ["BTC"],
kycCompleted: true,
- paytoUri: stringifyPaytoUri({
- targetType: "bitcoin",
- segwitAddrs: [],
- address: "bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh",
- isKnown: true,
- targetPath: "bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh",
- params: {},
- }),
+ paytoUri: "payto://bitcoin/bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh",
},
],
},
@@ -111,13 +96,7 @@ export const WithAllTypeOfAccounts = tests.createExample(ReadyView, {
label: "my bank",
currencies: ["ARS"],
kycCompleted: true,
- paytoUri: stringifyPaytoUri({
- targetType: "iban",
- iban: "ASDQWEQWE",
- isKnown: true,
- targetPath: "/ASDQWEQWE",
- params: {},
- }),
+ paytoUri: "payto://iban//ASDQWEQWE",
},
],
"x-taler-bank": [
@@ -126,14 +105,7 @@ export const WithAllTypeOfAccounts = tests.createExample(ReadyView, {
label: "my xtaler bank",
currencies: ["ARS"],
kycCompleted: true,
- paytoUri: stringifyPaytoUri({
- targetType: "x-taler-bank",
- host: "localhost",
- account: "123",
- isKnown: true,
- targetPath: "localhost/123",
- params: {},
- }),
+ paytoUri: "payto://x-taler-bank/localhost/123",
},
],
bitcoin: [
@@ -142,28 +114,14 @@ export const WithAllTypeOfAccounts = tests.createExample(ReadyView, {
label: "my bitcoin addr",
currencies: ["BTC"],
kycCompleted: false,
- paytoUri: stringifyPaytoUri({
- targetType: "bitcoin",
- segwitAddrs: [],
- isKnown: true,
- address: "bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh",
- targetPath: "bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh",
- params: {},
- }),
+ paytoUri: "payto://bitcoin/bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh",
},
{
bankAccountId: "acct:2",
label: "my other addr",
currencies: ["BTC"],
kycCompleted: true,
- paytoUri: stringifyPaytoUri({
- targetType: "bitcoin",
- segwitAddrs: [],
- isKnown: true,
- address: "bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh",
- targetPath: "bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh",
- params: {},
- }),
+ paytoUri: "payto://bitcoin/bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh",
},
],
},
@@ -197,14 +155,7 @@ export const AddingIbanAccount = tests.createExample(ReadyView, {
label: "my bank",
currencies: ["ARS"],
kycCompleted: true,
- paytoUri: stringifyPaytoUri({
- targetType: "iban",
- iban: "ASDQWEQWE",
- bic: "SANDBOX",
- isKnown: true,
- targetPath: "SANDBOX/ASDQWEQWE",
- params: {},
- }),
+ paytoUri: "payto://iban/SANDBOX/ASDQWEQWE",
},
],
"x-taler-bank": [],