From f45ef767016a425d04cce7755b27aceff292603c Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 24 Mar 2022 16:02:38 -0300 Subject: esbuild configuration --- packages/taler-util/src/payto.ts | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'packages/taler-util/src/payto.ts') diff --git a/packages/taler-util/src/payto.ts b/packages/taler-util/src/payto.ts index fc3380555..a7736ea74 100644 --- a/packages/taler-util/src/payto.ts +++ b/packages/taler-util/src/payto.ts @@ -14,9 +14,10 @@ GNU Taler; see the file COPYING. If not, see */ +import { generateFakeSegwitAddress } from "./index.js"; import { URLSearchParams } from "./url.js"; -export type PaytoUri = PaytoUriUnknown | PaytoUriIBAN | PaytoUriTalerBank; +export type PaytoUri = PaytoUriUnknown | PaytoUriIBAN | PaytoUriTalerBank | PaytoUriBitcoin; interface PaytoUriGeneric { targetType: string; @@ -41,6 +42,13 @@ interface PaytoUriTalerBank extends PaytoUriGeneric { account: string; } +interface PaytoUriBitcoin extends PaytoUriGeneric { + isKnown: true; + targetType: 'bitcoin', + generateSegwitAddress: (r: string) => { addr1: string, addr2: string }; + addr1?: string, addr2?: string, +} + const paytoPfx = "payto://"; /** @@ -104,6 +112,29 @@ export function parsePaytoUri(s: string): PaytoUri | undefined { iban: targetPath }; + } + if (targetType === 'bitcoin') { + + const result: PaytoUriBitcoin = { + isKnown: true, + targetPath, + targetType, + params, + 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 + return result; + } return { targetPath, -- cgit v1.2.3