commit 292d7bb92412ed106a80d484ebab1d46e2c8d2f1
parent 351096408318dd0aae597062080aa811e93bdc9a
Author: Sebastian <sebasjm@gmail.com>
Date: Mon, 6 Jan 2025 19:43:43 -0300
added payto taler
Diffstat:
2 files changed, 48 insertions(+), 1 deletion(-)
diff --git a/packages/taler-util/src/payto.ts b/packages/taler-util/src/payto.ts
@@ -35,6 +35,7 @@ import { URLSearchParams } from "./url.js";
export type PaytoUri =
| PaytoUriUnknown
| PaytoUriIBAN
+ | PaytoUriTaler
| PaytoUriTalerBank
| PaytoUriBitcoin;
@@ -77,6 +78,13 @@ export interface PaytoUriIBAN extends PaytoUriGeneric {
bic?: string;
}
+export interface PaytoUriTaler extends PaytoUriGeneric {
+ isKnown: true;
+ targetType: "taler";
+ exchange: string;
+ reservePub: string;
+}
+
export interface PaytoUriTalerBank extends PaytoUriGeneric {
isKnown: true;
targetType: "x-taler-bank";
@@ -93,7 +101,7 @@ export interface PaytoUriBitcoin extends PaytoUriGeneric {
const paytoPfx = "payto://";
-export type PaytoType = "iban" | "bitcoin" | "x-taler-bank";
+export type PaytoType = "iban" | "bitcoin" | "x-taler-bank" | "taler";
export function buildPayto(
type: "iban",
@@ -102,6 +110,12 @@ export function buildPayto(
params?: Record<string, string>,
): PaytoUriIBAN;
export function buildPayto(
+ type: "taler",
+ exchange: string,
+ reservePub: string,
+ params?: Record<string, string>,
+): PaytoUriIBAN;
+export function buildPayto(
type: "bitcoin",
address: string,
reserve: string | undefined,
@@ -155,6 +169,18 @@ export function buildPayto(
};
return result;
}
+ case "taler": {
+ if (!second) throw Error("missing reservePub for payto://taler");
+ const result: PaytoUriTaler = {
+ isKnown: true,
+ targetType: "taler",
+ exchange: first,
+ reservePub: second,
+ params,
+ targetPath: `${first}/${second}`,
+ };
+ return result;
+ }
default: {
const unknownType: never = type;
throw Error(`unknown payto:// type ${unknownType}`);
@@ -254,6 +280,10 @@ export function hashNormalizedPaytoUri(p: PaytoUri | string): Uint8Array {
break;
case "bitcoin":
paytoStr = `payto://bitcoin/${p.address}`;
+ break;
+ case "taler":
+ paytoStr = `payto://taler/${p.exchange}/${p.reservePub}`;
+ break;
}
}
return hashTruncate32(stringToBytes(paytoStr + "\0"));
@@ -320,6 +350,19 @@ export function parsePaytoUri(s: string): PaytoUri | undefined {
params[k] = v; //decodeURIComponent(v);
});
+ if (targetType === "taler") {
+ const parts = targetPath.split("/");
+ const exchange = parts[0];
+ const reservePub = parts[1];
+ return {
+ targetPath,
+ targetType,
+ params,
+ isKnown: true,
+ exchange,
+ reservePub,
+ };
+ }
if (targetType === "x-taler-bank") {
const parts = targetPath.split("/");
const host = parts[0];
diff --git a/packages/taler-util/src/taleruri.ts b/packages/taler-util/src/taleruri.ts
@@ -695,6 +695,10 @@ export function stringifyWithdrawUri({
return `${proto}://withdraw/${path}${withdrawalOperationId}`;
}
+export function getURLHostnamePortPath(baseUrl: string) {
+ return getUrlInfo(baseUrl).path;
+}
+
/**
* Use baseUrl to defined http or https
* create path using host+port+pathname