[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-wallet-core] 01/06: add payto stringify
From: |
gnunet |
Subject: |
[taler-wallet-core] 01/06: add payto stringify |
Date: |
Mon, 11 Apr 2022 16:36:49 +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 56c2a9c6a659fdb80a037677a1e7b0ce5e5d4c79
Author: Sebastian <sebasjm@gmail.com>
AuthorDate: Mon Apr 11 11:31:33 2022 -0300
add payto stringify
---
packages/taler-util/src/payto.ts | 48 +++++++++++++++++++++++++++++++---------
1 file changed, 38 insertions(+), 10 deletions(-)
diff --git a/packages/taler-util/src/payto.ts b/packages/taler-util/src/payto.ts
index a7736ea7..c9889160 100644
--- a/packages/taler-util/src/payto.ts
+++ b/packages/taler-util/src/payto.ts
@@ -51,6 +51,19 @@ interface PaytoUriBitcoin extends PaytoUriGeneric {
const paytoPfx = "payto://";
+
+
+function buildSegwitGenerator(result: PaytoUriBitcoin, targetPath: string) {
+ //generate segwit address just once, save addr in payto object
+ //and use it as cache
+ return function generateSegwitAddress(reserve: string): { addr1: string,
addr2: string } {
+ if (result.addr1 && result.addr2) return { addr1: result.addr1, addr2:
result.addr2 };
+ const { addr1, addr2 } = generateFakeSegwitAddress(reserve, targetPath)
+ result.addr1 = addr1
+ result.addr2 = addr2
+ return { addr1, addr2 }
+ }
+}
/**
* Add query parameters to a payto URI
*/
@@ -66,6 +79,30 @@ export function addPaytoQueryParams(
return paytoPfx + acct + "?" + searchParams.toString();
}
+/**
+ * Serialize a PaytoURI into a valid payto:// string
+ *
+ * @param p
+ * @returns
+ */
+export function stringifyPaytoUri(p: PaytoUri): string {
+ const url = `${paytoPfx}${p.targetType}//${p.targetPath}`
+ if (p.params) {
+ const search = Object.entries(p.params)
+ .map(([key, value]) => `${key}=${value}`)
+ .join("&");
+ return `${url}?${search}`
+ }
+ return url
+}
+
+/**
+ * Parse a valid payto:// uri into a PaytoUri object
+ * RFC 8905
+ *
+ * @param s
+ * @returns
+ */
export function parsePaytoUri(s: string): PaytoUri | undefined {
if (!s.startsWith(paytoPfx)) {
return undefined;
@@ -123,16 +160,7 @@ export function parsePaytoUri(s: string): PaytoUri |
undefined {
generateSegwitAddress: (): any => null
}
- //generate segwit address just once, save addr in payto object
- //and use it as cache
- function generateSegwitAddress(reserve: string) {
- if (result.addr1 && result.addr2) return { addr1: result.addr1, addr2:
result.addr2 };
- const { addr1, addr2 } = generateFakeSegwitAddress(reserve, targetPath)
- result.addr1 = addr1
- result.addr2 = addr2
- return { addr1, addr2 }
- }
- result.generateSegwitAddress = generateSegwitAddress
+ result.generateSegwitAddress = buildSegwitGenerator(result, targetPath)
return result;
}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [taler-wallet-core] branch master updated (fae6c420 -> ccb50c63), gnunet, 2022/04/11
- [taler-wallet-core] 04/06: terms of service stories into its own scenarios (removed from withdraw), gnunet, 2022/04/11
- [taler-wallet-core] 02/06: fix ref for copy and paste, gnunet, 2022/04/11
- [taler-wallet-core] 05/06: missing index file, gnunet, 2022/04/11
- [taler-wallet-core] 01/06: add payto stringify,
gnunet <=
- [taler-wallet-core] 03/06: show amount nicely, into a component, gnunet, 2022/04/11
- [taler-wallet-core] 06/06: new test api to test hooks rendering iteration, testing state of withdraw page, gnunet, 2022/04/11