aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-util
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2022-03-24 16:02:38 -0300
committerSebastian <sebasjm@gmail.com>2022-03-24 16:02:38 -0300
commitf45ef767016a425d04cce7755b27aceff292603c (patch)
tree8e6e2aa47bf282d3db08f54264f2c9db2179ba90 /packages/taler-util
parent2c6b83ffea8d7b898d7ccb52b2b026c2e4ba6f24 (diff)
esbuild configuration
Diffstat (limited to 'packages/taler-util')
-rw-r--r--packages/taler-util/package.json3
-rw-r--r--packages/taler-util/src/bitcoin.ts8
-rw-r--r--packages/taler-util/src/payto.ts33
3 files changed, 36 insertions, 8 deletions
diff --git a/packages/taler-util/package.json b/packages/taler-util/package.json
index 6a46de897..42ca8cb2a 100644
--- a/packages/taler-util/package.json
+++ b/packages/taler-util/package.json
@@ -2,9 +2,6 @@
"name": "@gnu-taler/taler-util",
"version": "0.9.0-dev.1",
"description": "Generic helper functionality for GNU Taler",
- "exports": {
- ".": "./lib/index.node.js"
- },
"module": "./lib/index.node.js",
"main": "./lib/index.node.js",
"browser": {
diff --git a/packages/taler-util/src/bitcoin.ts b/packages/taler-util/src/bitcoin.ts
index f4d3cfeb9..85a176dc6 100644
--- a/packages/taler-util/src/bitcoin.ts
+++ b/packages/taler-util/src/bitcoin.ts
@@ -24,8 +24,8 @@ import * as segwit from "./segwit_addr"
*/
export interface SegwitAddrs {
- segwitAddr1: string,
- segwitAddr2: string,
+ addr1: string,
+ addr2: string,
}
function buf2hex(buffer: Uint8Array) { // buffer is an ArrayBuffer
@@ -57,8 +57,8 @@ export function generateFakeSegwitAddress(reservePub: string, addr: string): Seg
if (prefix === undefined) throw new Error('unknown bitcoin net')
return {
- segwitAddr1: segwit.default.encode(prefix, 0, first_part),
- segwitAddr2: segwit.default.encode(prefix, 0, second_part),
+ addr1: segwit.default.encode(prefix, 0, first_part),
+ addr2: segwit.default.encode(prefix, 0, second_part),
}
}
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,