diff options
author | Sebastian <sebasjm@gmail.com> | 2022-03-24 16:02:38 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2022-03-24 16:02:38 -0300 |
commit | f45ef767016a425d04cce7755b27aceff292603c (patch) | |
tree | 8e6e2aa47bf282d3db08f54264f2c9db2179ba90 /packages/taler-util/src/payto.ts | |
parent | 2c6b83ffea8d7b898d7ccb52b2b026c2e4ba6f24 (diff) | |
download | wallet-core-f45ef767016a425d04cce7755b27aceff292603c.tar.xz |
esbuild configuration
Diffstat (limited to 'packages/taler-util/src/payto.ts')
-rw-r--r-- | packages/taler-util/src/payto.ts | 33 |
1 files changed, 32 insertions, 1 deletions
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 <http://www.gnu.org/licenses/> */ +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://"; /** @@ -105,6 +113,29 @@ export function parsePaytoUri(s: string): PaytoUri | undefined { }; } + 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, targetType, |