gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] 01/02: parse and construct taler recovery URI


From: gnunet
Subject: [taler-wallet-core] 01/02: parse and construct taler recovery URI
Date: Thu, 20 Oct 2022 19:55:00 +0200

This is an automated email from the git hooks/post-receive script.

sebasjm pushed a commit to branch master
in repository wallet-core.

commit 8390c60031b87e034a1bb6b830910faa6c2cc4e6
Author: Sebastian <sebasjm@gmail.com>
AuthorDate: Thu Oct 20 14:53:29 2022 -0300

    parse and construct taler recovery URI
---
 packages/taler-util/src/taleruri.ts | 46 +++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/packages/taler-util/src/taleruri.ts 
b/packages/taler-util/src/taleruri.ts
index baca3efac..45f9a90f2 100644
--- a/packages/taler-util/src/taleruri.ts
+++ b/packages/taler-util/src/taleruri.ts
@@ -14,7 +14,9 @@
  GNU Taler; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
  */
 
+import { BackupRecovery } from "./backup-types.js";
 import { canonicalizeBaseUrl } from "./helpers.js";
+import { initNodePrng } from "./prng-node.js";
 import { URLSearchParams, URL } from "./url.js";
 
 export interface PayUriResult {
@@ -95,6 +97,7 @@ export enum TalerUriType {
   TalerNotifyReserve = "taler-notify-reserve",
   TalerPayPush = "taler-pay-push",
   TalerPayPull = "taler-pay-pull",
+  TalerRecovery = "taler-recovery",
   TalerDevExperiment = "taler-dev-experiment",
   Unknown = "unknown",
 }
@@ -107,6 +110,12 @@ const talerActionPayPush = "pay-push";
  */
 export function classifyTalerUri(s: string): TalerUriType {
   const sl = s.toLowerCase();
+  if (sl.startsWith("taler://recovery/")) {
+    return TalerUriType.TalerRecovery;
+  }
+  if (sl.startsWith("taler+http://recovery/";)) {
+    return TalerUriType.TalerRecovery;
+  }
   if (sl.startsWith("taler://pay/")) {
     return TalerUriType.TalerPay;
   }
@@ -362,3 +371,40 @@ export function constructPayPullUri(args: {
   }
   return `${proto}://pay-pull/${url.host}${url.pathname}${args.contractPriv}`;
 }
+
+export function constructRecoveryUri(args: BackupRecovery): string {
+  const key = args.walletRootPriv
+  const urls = args.providers.map(p => 
`p=${canonicalizeBaseUrl(p.url)}`).join("&")
+
+  return `taler://recovery/${key}?${urls}`
+}
+export function parseRecoveryUri(uri: string): BackupRecovery | undefined {
+  const pi = parseProtoInfo(uri, "recovery");
+  if (!pi) {
+    return undefined;
+  }
+  const idx = pi.rest.indexOf("?");
+  if (idx === -1) {
+    return undefined
+  }
+  const path = pi.rest.slice(0, idx)
+  const params = pi.rest.slice(idx + 1)
+  if (!path || !params) {
+    return undefined;
+  }
+  const parts = path.split("/");
+  const walletRootPriv = parts[0];
+  if (!walletRootPriv) return undefined
+  const providers = new Array<{ url: string }>();
+  const args = params.split("&")
+  for (const param in args) {
+    const eq = args[param].indexOf("=")
+    if (eq === -1) return undefined;
+    const name = args[param].slice(0, eq)
+    const value = args[param].slice(eq + 1)
+    if (name !== "p" || !value) return undefined;
+    providers.push({ url: value })
+  }
+  return { walletRootPriv, providers }
+}
+

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]