added name into recovery uri

This commit is contained in:
Sebastian 2022-10-21 12:12:35 -03:00
parent 5ba7956f49
commit 805e2c4d7c
No known key found for this signature in database
GPG Key ID: BE4FF68352439FC1
2 changed files with 18 additions and 16 deletions

View File

@ -1281,6 +1281,7 @@ export enum BackupProposalStatus {
export interface BackupRecovery { export interface BackupRecovery {
walletRootPriv: string; walletRootPriv: string;
providers: { providers: {
name: string;
url: string; url: string;
}[]; }[];
} }

View File

@ -373,10 +373,13 @@ export function constructPayPullUri(args: {
} }
export function constructRecoveryUri(args: BackupRecovery): string { export function constructRecoveryUri(args: BackupRecovery): string {
const key = args.walletRootPriv const key = args.walletRootPriv;
const urls = args.providers.map(p => `p=${canonicalizeBaseUrl(p.url)}`).join("&") //FIXME: name may contain non valid characters
const urls = args.providers
.map((p) => `${p.name}=${canonicalizeBaseUrl(p.url)}`)
.join("&");
return `taler://recovery/${key}?${urls}` return `taler://recovery/${key}?${urls}`;
} }
export function parseRecoveryUri(uri: string): BackupRecovery | undefined { export function parseRecoveryUri(uri: string): BackupRecovery | undefined {
const pi = parseProtoInfo(uri, "recovery"); const pi = parseProtoInfo(uri, "recovery");
@ -385,26 +388,24 @@ export function parseRecoveryUri(uri: string): BackupRecovery | undefined {
} }
const idx = pi.rest.indexOf("?"); const idx = pi.rest.indexOf("?");
if (idx === -1) { if (idx === -1) {
return undefined return undefined;
} }
const path = pi.rest.slice(0, idx) const path = pi.rest.slice(0, idx);
const params = pi.rest.slice(idx + 1) const params = pi.rest.slice(idx + 1);
if (!path || !params) { if (!path || !params) {
return undefined; return undefined;
} }
const parts = path.split("/"); const parts = path.split("/");
const walletRootPriv = parts[0]; const walletRootPriv = parts[0];
if (!walletRootPriv) return undefined if (!walletRootPriv) return undefined;
const providers = new Array<{ url: string }>(); const providers = new Array<{ name: string; url: string }>();
const args = params.split("&") const args = params.split("&");
for (const param in args) { for (const param in args) {
const eq = args[param].indexOf("=") const eq = args[param].indexOf("=");
if (eq === -1) return undefined; if (eq === -1) return undefined;
const name = args[param].slice(0, eq) const name = args[param].slice(0, eq);
const value = args[param].slice(eq + 1) const url = args[param].slice(eq + 1);
if (name !== "p" || !value) return undefined; providers.push({ name, url });
providers.push({ url: value })
} }
return { walletRootPriv, providers } return { walletRootPriv, providers };
} }