diff options
Diffstat (limited to 'packages/taler-util/src/taleruri.ts')
-rw-r--r-- | packages/taler-util/src/taleruri.ts | 52 |
1 files changed, 15 insertions, 37 deletions
diff --git a/packages/taler-util/src/taleruri.ts b/packages/taler-util/src/taleruri.ts index e641f1d27..bd63fd103 100644 --- a/packages/taler-util/src/taleruri.ts +++ b/packages/taler-util/src/taleruri.ts @@ -35,8 +35,8 @@ export interface PayUriResult { merchantBaseUrl: string; orderId: string; sessionId: string; - claimToken: string | undefined; - noncePriv: string | undefined; + claimToken?: string; + noncePriv?: string; } export interface PayTemplateUriResult { @@ -96,10 +96,7 @@ export interface DevExperimentUri { export interface BackupRestoreUri { type: TalerUriAction.Restore; walletRootPriv: string; - providers: { - name: string; - url: string; - }[]; + providers: Array<string>; } /** @@ -535,9 +532,9 @@ export function parseRefundUri(s: string): RefundUriResult | undefined { return undefined; } const host = parts[0].toLowerCase(); - // const sessionId = parts[parts.length - 1]; - const orderId = parts[parts.length - 1]; - const pathSegments = parts.slice(1, parts.length - 1); + const sessionId = parts[parts.length - 1]; + const orderId = parts[parts.length - 2]; + const pathSegments = parts.slice(1, parts.length - 2); const hostAndSegments = [host, ...pathSegments].join("/"); const merchantBaseUrl = canonicalizeBaseUrl( `${pi.innerProto}://${hostAndSegments}/`, @@ -576,10 +573,12 @@ export function parseRestoreUri(uri: string): BackupRestoreUri | undefined { const walletRootPriv = parts[0]; if (!walletRootPriv) return undefined; - const providers = new Array<{ name: string; url: string }>(); + const providers = new Array<string>(); parts[1].split(",").map((name) => { - const url = canonicalizeBaseUrl(`${pi.innerProto}://${name}/`); - providers.push({ name, url }); + const url = canonicalizeBaseUrl( + `${pi.innerProto}://${decodeURIComponent(name)}/`, + ); + providers.push(url); }); return { type: TalerUriAction.Restore, @@ -597,10 +596,7 @@ export function parseRestoreUri(uri: string): BackupRestoreUri | undefined { */ export function constructRecoveryUri(args: { walletRootPriv: string; - providers: { - name: string; - url: string; - }[]; + providers: string[]; }): string { return stringifyRestoreUri(args); } @@ -652,26 +648,6 @@ export function stringifyPayUri({ claimToken, noncePriv, }: Omit<PayUriResult, "type">): string { - // const base = canonicalizeBaseUrl(merchantBaseUrl); - // const url = new URL(base); - // const isHttp = base.startsWith("http://"); - // let result = isHttp ? `taler+http://pay/` : `taler://pay/`; - // result += url.hostname; - // if (url.port != "") { - // result += `:${url.port}`; - // } - // result += `${url.pathname}${orderId}/${sessionId}`; - // const qp = new URLSearchParams(); - // if (claimToken) { - // qp.append("c", claimToken); - // } - // if (noncePriv) { - // qp.append("n", noncePriv); - // } - // const queryPart = qp.toString(); - // if (queryPart) { - // result += "?" + queryPart; - // } const { proto, path, query } = getUrlInfo(merchantBaseUrl, { c: claimToken, n: noncePriv, @@ -700,7 +676,9 @@ export function stringifyRestoreUri({ providers, walletRootPriv, }: Omit<BackupRestoreUri, "type">): string { - const list = providers.map((p) => `${new URL(p.url).hostname}`).join("m"); + const list = providers + .map((url) => `${encodeURIComponent(new URL(url).href)}`) + .join(","); return `taler://restore/${walletRootPriv}/${list}`; } |