@scure/btc-signer 1.8.0 → 2.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/README.md +15 -12
  2. package/_type_test.js +10 -12
  3. package/_type_test.js.map +1 -1
  4. package/index.js +17 -61
  5. package/index.js.map +1 -1
  6. package/musig2.d.ts +2 -2
  7. package/musig2.d.ts.map +1 -1
  8. package/musig2.js +93 -91
  9. package/musig2.js.map +1 -1
  10. package/p2p.d.ts +7 -8
  11. package/p2p.d.ts.map +1 -1
  12. package/p2p.js +32 -38
  13. package/p2p.js.map +1 -1
  14. package/package.json +33 -70
  15. package/payment.js +73 -96
  16. package/payment.js.map +1 -1
  17. package/psbt.d.ts +224 -224
  18. package/psbt.d.ts.map +1 -1
  19. package/psbt.js +58 -63
  20. package/psbt.js.map +1 -1
  21. package/script.d.ts +125 -120
  22. package/script.d.ts.map +1 -1
  23. package/script.js +46 -146
  24. package/script.js.map +1 -1
  25. package/src/_type_test.ts +2 -2
  26. package/src/musig2.ts +45 -53
  27. package/src/p2p.ts +31 -43
  28. package/src/psbt.ts +7 -7
  29. package/src/script.ts +29 -26
  30. package/src/transaction.ts +31 -24
  31. package/src/utils.ts +45 -26
  32. package/src/utxo.ts +1 -1
  33. package/transaction.d.ts +23 -28
  34. package/transaction.d.ts.map +1 -1
  35. package/transaction.js +140 -154
  36. package/transaction.js.map +1 -1
  37. package/utils.d.ts +13 -7
  38. package/utils.d.ts.map +1 -1
  39. package/utils.js +60 -62
  40. package/utils.js.map +1 -1
  41. package/utxo.d.ts +45 -45
  42. package/utxo.d.ts.map +1 -1
  43. package/utxo.js +63 -59
  44. package/utxo.js.map +1 -1
  45. package/esm/_type_test.d.ts +0 -2
  46. package/esm/_type_test.d.ts.map +0 -1
  47. package/esm/_type_test.js +0 -57
  48. package/esm/_type_test.js.map +0 -1
  49. package/esm/index.d.ts +0 -22
  50. package/esm/index.d.ts.map +0 -1
  51. package/esm/index.js +0 -22
  52. package/esm/index.js.map +0 -1
  53. package/esm/musig2.d.ts +0 -148
  54. package/esm/musig2.d.ts.map +0 -1
  55. package/esm/musig2.js +0 -405
  56. package/esm/musig2.js.map +0 -1
  57. package/esm/p2p.d.ts +0 -38
  58. package/esm/p2p.d.ts.map +0 -1
  59. package/esm/p2p.js +0 -156
  60. package/esm/p2p.js.map +0 -1
  61. package/esm/package.json +0 -1
  62. package/esm/payment.d.ts +0 -200
  63. package/esm/payment.d.ts.map +0 -1
  64. package/esm/payment.js +0 -697
  65. package/esm/payment.js.map +0 -1
  66. package/esm/psbt.d.ts +0 -820
  67. package/esm/psbt.d.ts.map +0 -1
  68. package/esm/psbt.js +0 -409
  69. package/esm/psbt.js.map +0 -1
  70. package/esm/script.d.ts +0 -170
  71. package/esm/script.d.ts.map +0 -1
  72. package/esm/script.js +0 -356
  73. package/esm/script.js.map +0 -1
  74. package/esm/transaction.d.ts +0 -171
  75. package/esm/transaction.d.ts.map +0 -1
  76. package/esm/transaction.js +0 -1182
  77. package/esm/transaction.js.map +0 -1
  78. package/esm/utils.d.ts +0 -35
  79. package/esm/utils.d.ts.map +0 -1
  80. package/esm/utils.js +0 -118
  81. package/esm/utils.js.map +0 -1
  82. package/esm/utxo.d.ts +0 -198
  83. package/esm/utxo.d.ts.map +0 -1
  84. package/esm/utxo.js +0 -461
  85. package/esm/utxo.js.map +0 -1
  86. package/src/package.json +0 -3
package/p2p.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"p2p.js","sourceRoot":"","sources":["src/p2p.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;GAkBG;;;AAEH,4DAA4D;AAE5D,wDAKsC;AAEtC,uDAA6D;AAC7D,+CAAkD;AAClD,yCAAwC;AAExC,MAAM,EAAE,GAAG,qBAAS,CAAC,KAAK,CAAC,EAAE,CAAC;AAC9B,MAAM,KAAK,GAAG,qBAAS,CAAC,eAAe,CAAC;AAExC,MAAM,GAAG,GA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GAAG,CAAC,CAAC,CAAC;QACtD,MAAM,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAC7B,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACzC,CAAC;IACD,uBAAuB;IACvB,qBAAqB,EAAE,CACrB,cAA0B,EAC1B,eAA2B,EAC3B,aAAyB,EACzB,UAAmB,EACP,EAAE;QACd,MAAM,IAAI,GAAG,MAAM,CAAC,aAAa,EAAE,SAAS,EAAE,eAAe,CAAC,CAAC;QAC/D,MAAM,MAAM,GAAG,MAAM,CAAC,eAAe,EAAE,SAAS,EAAE,iBAAiB,CAAC,CAAC;QACrE,MAAM,SAAS,GAAG,cAAc,CAAC,eAAe,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;QACzE,MAAM,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAC1D,OAAO,UAAU,CAAC,4BAA4B,EAAE,GAAG,IAAI,EAAE,SAAS,CAAC,CAAC;IACtE,CAAC;CACF,CAAC"}
package/package.json CHANGED
@@ -1,87 +1,38 @@
1
1
  {
2
2
  "name": "@scure/btc-signer",
3
- "version": "1.8.0",
3
+ "version": "2.0.0-beta.1",
4
4
  "description": "Audited & minimal library for Bitcoin. Handle transactions, Schnorr, Taproot, UTXO & PSBT",
5
5
  "files": [
6
- "esm",
7
- "src",
8
6
  "*.js",
9
7
  "*.d.ts",
10
8
  "*.js.map",
11
- "*.d.ts.map"
9
+ "*.d.ts.map",
10
+ "src"
12
11
  ],
13
- "main": "./index.js",
14
- "module": "./esm/index.js",
15
- "types": "./index.d.ts",
16
12
  "dependencies": {
17
- "@noble/curves": "~1.9.0",
18
- "@noble/hashes": "~1.8.0",
19
- "@scure/base": "~1.2.5",
20
- "micro-packed": "~0.7.3"
13
+ "@noble/curves": "2.0.0-beta.3",
14
+ "@noble/hashes": "2.0.0-beta.5",
15
+ "@scure/base": "2.0.0-beta.1",
16
+ "micro-packed": "0.8.0-beta.1"
21
17
  },
22
18
  "devDependencies": {
23
- "@paulmillr/jsbt": "0.3.3",
19
+ "@paulmillr/jsbt": "0.4.2",
24
20
  "@scure/bip32": "~1.7.0",
25
- "micro-bmark": "0.4.1",
26
- "micro-should": "0.5.2",
27
- "prettier": "3.5.3",
28
- "typescript": "5.8.3"
29
- },
30
- "exports": {
31
- ".": {
32
- "import": "./esm/index.js",
33
- "require": "./index.js"
34
- },
35
- "./index": {
36
- "import": "./esm/index.js",
37
- "require": "./index.js"
38
- },
39
- "./musig2": {
40
- "import": "./esm/musig2.js",
41
- "require": "./musig2.js"
42
- },
43
- "./payment": {
44
- "import": "./esm/payment.js",
45
- "require": "./payment.js"
46
- },
47
- "./psbt": {
48
- "import": "./esm/psbt.js",
49
- "require": "./psbt.js"
50
- },
51
- "./script": {
52
- "import": "./esm/script.js",
53
- "require": "./script.js"
54
- },
55
- "./transaction": {
56
- "import": "./esm/transaction.js",
57
- "require": "./transaction.js"
58
- },
59
- "./utils": {
60
- "import": "./esm/utils.js",
61
- "require": "./utils.js"
62
- },
63
- "./utxo": {
64
- "import": "./esm/utxo.js",
65
- "require": "./utxo.js"
66
- }
67
- },
68
- "sideEffects": false,
69
- "author": "Paul Miller (https://paulmillr.com)",
70
- "license": "MIT",
71
- "homepage": "https://github.com/paulmillr/scure-btc-signer",
72
- "repository": {
73
- "type": "git",
74
- "url": "git+https://github.com/paulmillr/scure-btc-signer.git"
21
+ "micro-bmark": "0.4.2",
22
+ "micro-should": "0.5.3",
23
+ "prettier": "3.6.2",
24
+ "typescript": "5.9.2"
75
25
  },
76
26
  "scripts": {
77
- "build": "tsc && tsc -p tsconfig.cjs.json",
78
- "build:release": "npx jsbt esbuild test/build",
79
- "lint": "prettier --check src",
80
- "format": "prettier --write src",
81
- "test": "node test/index.js",
82
- "test:big": "node test/slow.test.js",
83
- "test:bun": "bun test/index.js",
27
+ "build": "tsc",
28
+ "build:clean": "rm -f *.{js,d.ts,js.map,d.ts.map}",
29
+ "build:release": "npx --no @paulmillr/jsbt esbuild test/build",
30
+ "format": "prettier --write src test/*.test.*",
31
+ "test": "node --no-warnings test/index.ts",
32
+ "test:bun": "bun test/index.ts",
84
33
  "test:deno": "deno --allow-env --allow-read test/index.js",
34
+ "test:node20": "cd test; npx tsc; node compiled/test/index.js",
35
+ "test:big": "node test/slow.test.ts",
85
36
  "test:extended": "node --experimental-loader ./test/bitcoinjs-test/esm-loader.js ./test/bitcoinjs-test/index.test.js"
86
37
  },
87
38
  "keywords": [
@@ -100,5 +51,17 @@
100
51
  "p2wsh",
101
52
  "p2tr"
102
53
  ],
103
- "funding": "https://paulmillr.com/funding/"
54
+ "homepage": "https://paulmillr.com/noble/#scure",
55
+ "funding": "https://paulmillr.com/funding/",
56
+ "repository": {
57
+ "type": "git",
58
+ "url": "git+https://github.com/paulmillr/scure-btc-signer.git"
59
+ },
60
+ "type": "module",
61
+ "main": "index.js",
62
+ "module": "index.js",
63
+ "types": "index.d.ts",
64
+ "sideEffects": false,
65
+ "author": "Paul Miller (https://paulmillr.com)",
66
+ "license": "MIT"
104
67
  }
package/payment.js CHANGED
@@ -1,32 +1,19 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._sortPubkeys = exports.p2tr_pk = exports.p2tr_ns = exports.tapLeafHash = exports.TAP_LEAF_VERSION = exports.p2ms = exports.p2wpkh = exports.p2wsh = exports.p2sh = exports.p2pkh = exports.p2pk = exports.OutScript = void 0;
4
- exports.checkScript = checkScript;
5
- exports.taprootListToTree = taprootListToTree;
6
- exports.p2tr = p2tr;
7
- exports.combinations = combinations;
8
- exports.p2tr_ms = p2tr_ms;
9
- exports.getAddress = getAddress;
10
- exports.multisig = multisig;
11
- exports.sortedMultisig = sortedMultisig;
12
- exports.WIF = WIF;
13
- exports.Address = Address;
14
- const base_1 = require("@scure/base");
15
- const P = require("micro-packed");
16
- const psbt_ts_1 = require("./psbt.js");
17
- const script_ts_1 = require("./script.js");
18
- const u = require("./utils.js");
19
- const utils_ts_1 = require("./utils.js");
1
+ import { bech32, bech32m, createBase58check, hex } from '@scure/base';
2
+ import * as P from 'micro-packed';
3
+ import { TaprootControlBlock } from "./psbt.js";
4
+ import { OpToNum, Script, VarBytes } from "./script.js";
5
+ import * as u from "./utils.js";
6
+ import { NETWORK } from "./utils.js";
20
7
  const OutP2A = {
21
8
  encode(from) {
22
- if (from.length !== 2 || from[0] !== 1 || !u.isBytes(from[1]) || base_1.hex.encode(from[1]) !== '4e73')
9
+ if (from.length !== 2 || from[0] !== 1 || !u.isBytes(from[1]) || hex.encode(from[1]) !== '4e73')
23
10
  return;
24
- return { type: 'p2a', script: script_ts_1.Script.encode(from) };
11
+ return { type: 'p2a', script: Script.encode(from) };
25
12
  },
26
13
  decode: (to) => {
27
14
  if (to.type !== 'p2a')
28
15
  return;
29
- return [1, base_1.hex.decode('4e73')];
16
+ return [1, hex.decode('4e73')];
30
17
  },
31
18
  };
32
19
  function isValidPubkey(pub, type) {
@@ -151,7 +138,7 @@ const OutTRMS = {
151
138
  if (from[last] !== 'NUMEQUAL' || from[1] !== 'CHECKSIG')
152
139
  return;
153
140
  const pubkeys = [];
154
- const m = (0, script_ts_1.OpToNum)(from[last - 1]);
141
+ const m = OpToNum(from[last - 1]);
155
142
  if (typeof m !== 'number')
156
143
  return;
157
144
  for (let i = 0; i < last - 1; i++) {
@@ -179,9 +166,9 @@ const OutTRMS = {
179
166
  };
180
167
  const OutUnknown = {
181
168
  encode(from) {
182
- return { type: 'unknown', script: script_ts_1.Script.encode(from) };
169
+ return { type: 'unknown', script: Script.encode(from) };
183
170
  },
184
- decode: (to) => to.type === 'unknown' ? script_ts_1.Script.decode(to.script) : undefined,
171
+ decode: (to) => to.type === 'unknown' ? Script.decode(to.script) : undefined,
185
172
  };
186
173
  // /Payments
187
174
  const OutScripts = [
@@ -202,9 +189,9 @@ const OutScripts = [
202
189
  // - removeOutScript
203
190
  // - We can do that as log we modify array in-place
204
191
  // - Actually is very hard, since there is sign/finalize logic
205
- const _OutScript = P.apply(script_ts_1.Script, P.coders.match(OutScripts));
192
+ const _OutScript = P.apply(Script, P.coders.match(OutScripts));
206
193
  // We can validate this once, because of packed & coders
207
- exports.OutScript = P.validate(_OutScript, (i) => {
194
+ export const OutScript = P.validate(_OutScript, (i) => {
208
195
  if (i.type === 'pk' && !isValidPubkey(i.pubkey, u.PubT.ecdsa))
209
196
  throw new Error('OutScript/pk: wrong key');
210
197
  if ((i.type === 'pkh' || i.type === 'sh' || i.type === 'wpkh') &&
@@ -241,22 +228,22 @@ exports.OutScript = P.validate(_OutScript, (i) => {
241
228
  function checkWSH(s, witnessScript) {
242
229
  if (!u.equalBytes(s.hash, u.sha256(witnessScript)))
243
230
  throw new Error('checkScript: wsh wrong witnessScript hash');
244
- const w = exports.OutScript.decode(witnessScript);
231
+ const w = OutScript.decode(witnessScript);
245
232
  if (w.type === 'tr' || w.type === 'tr_ns' || w.type === 'tr_ms')
246
233
  throw new Error(`checkScript: P2${w.type} cannot be wrapped in P2SH`);
247
234
  if (w.type === 'wpkh' || w.type === 'sh')
248
235
  throw new Error(`checkScript: P2${w.type} cannot be wrapped in P2WSH`);
249
236
  }
250
- function checkScript(script, redeemScript, witnessScript) {
237
+ export function checkScript(script, redeemScript, witnessScript) {
251
238
  if (script) {
252
- const s = exports.OutScript.decode(script);
239
+ const s = OutScript.decode(script);
253
240
  // ms||pk maybe work, but there will be no address, hard to spend
254
241
  if (s.type === 'tr_ns' || s.type === 'tr_ms' || s.type === 'ms' || s.type == 'pk')
255
242
  throw new Error(`checkScript: non-wrapped ${s.type}`);
256
243
  if (s.type === 'sh' && redeemScript) {
257
244
  if (!u.equalBytes(s.hash, u.hash160(redeemScript)))
258
245
  throw new Error('checkScript: sh wrong redeemScript hash');
259
- const r = exports.OutScript.decode(redeemScript);
246
+ const r = OutScript.decode(redeemScript);
260
247
  if (r.type === 'tr' || r.type === 'tr_ns' || r.type === 'tr_ms')
261
248
  throw new Error(`checkScript: P2${r.type} cannot be wrapped in P2SH`);
262
249
  // Not sure if this unspendable, but we cannot represent this via PSBT
@@ -267,7 +254,7 @@ function checkScript(script, redeemScript, witnessScript) {
267
254
  checkWSH(s, witnessScript);
268
255
  }
269
256
  if (redeemScript) {
270
- const r = exports.OutScript.decode(redeemScript);
257
+ const r = OutScript.decode(redeemScript);
271
258
  if (r.type === 'wsh' && witnessScript)
272
259
  checkWSH(r, witnessScript);
273
260
  }
@@ -275,44 +262,42 @@ function checkScript(script, redeemScript, witnessScript) {
275
262
  function uniqPubkey(pubkeys) {
276
263
  const map = {};
277
264
  for (const pub of pubkeys) {
278
- const key = base_1.hex.encode(pub);
265
+ const key = hex.encode(pub);
279
266
  if (map[key])
280
- throw new Error(`Multisig: non-uniq pubkey: ${pubkeys.map(base_1.hex.encode)}`);
267
+ throw new Error(`Multisig: non-uniq pubkey: ${pubkeys.map(hex.encode)}`);
281
268
  map[key] = true;
282
269
  }
283
270
  }
284
- const p2pk = (pubkey, _network = utils_ts_1.NETWORK) => {
271
+ export const p2pk = (pubkey, _network = NETWORK) => {
285
272
  // network is unused
286
273
  if (!isValidPubkey(pubkey, u.PubT.ecdsa))
287
274
  throw new Error('P2PK: invalid publicKey');
288
- return { type: 'pk', script: exports.OutScript.encode({ type: 'pk', pubkey }) };
275
+ return { type: 'pk', script: OutScript.encode({ type: 'pk', pubkey }) };
289
276
  };
290
- exports.p2pk = p2pk;
291
- const p2pkh = (publicKey, network = utils_ts_1.NETWORK) => {
277
+ export const p2pkh = (publicKey, network = NETWORK) => {
292
278
  if (!isValidPubkey(publicKey, u.PubT.ecdsa))
293
279
  throw new Error('P2PKH: invalid publicKey');
294
280
  const hash = u.hash160(publicKey);
295
281
  return {
296
282
  type: 'pkh',
297
- script: exports.OutScript.encode({ type: 'pkh', hash }),
283
+ script: OutScript.encode({ type: 'pkh', hash }),
298
284
  address: Address(network).encode({ type: 'pkh', hash }),
299
285
  hash,
300
286
  };
301
287
  };
302
- exports.p2pkh = p2pkh;
303
- const p2sh = (child, network = utils_ts_1.NETWORK) => {
288
+ export const p2sh = (child, network = NETWORK) => {
304
289
  // It is already tested inside noble-hashes and checkScript
305
290
  const cs = child.script;
306
291
  if (!u.isBytes(cs))
307
292
  throw new Error(`Wrong script: ${typeof child.script}, expected Uint8Array`);
308
293
  const hash = u.hash160(cs);
309
- const script = exports.OutScript.encode({ type: 'sh', hash });
294
+ const script = OutScript.encode({ type: 'sh', hash });
310
295
  checkScript(script, cs, child.witnessScript);
311
296
  if (child.witnessScript) {
312
297
  return {
313
298
  type: 'sh',
314
299
  redeemScript: cs,
315
- script: exports.OutScript.encode({ type: 'sh', hash }),
300
+ script: OutScript.encode({ type: 'sh', hash }),
316
301
  address: Address(network).encode({ type: 'sh', hash }),
317
302
  hash,
318
303
  witnessScript: child.witnessScript,
@@ -322,30 +307,28 @@ const p2sh = (child, network = utils_ts_1.NETWORK) => {
322
307
  return {
323
308
  type: 'sh',
324
309
  redeemScript: cs,
325
- script: exports.OutScript.encode({ type: 'sh', hash }),
310
+ script: OutScript.encode({ type: 'sh', hash }),
326
311
  address: Address(network).encode({ type: 'sh', hash }),
327
312
  hash,
328
313
  };
329
314
  }
330
315
  };
331
- exports.p2sh = p2sh;
332
- const p2wsh = (child, network = utils_ts_1.NETWORK) => {
316
+ export const p2wsh = (child, network = NETWORK) => {
333
317
  const cs = child.script;
334
318
  if (!u.isBytes(cs))
335
319
  throw new Error(`Wrong script: ${typeof cs}, expected Uint8Array`);
336
320
  const hash = u.sha256(cs);
337
- const script = exports.OutScript.encode({ type: 'wsh', hash });
321
+ const script = OutScript.encode({ type: 'wsh', hash });
338
322
  checkScript(script, undefined, cs);
339
323
  return {
340
324
  type: 'wsh',
341
325
  witnessScript: cs,
342
- script: exports.OutScript.encode({ type: 'wsh', hash }),
326
+ script: OutScript.encode({ type: 'wsh', hash }),
343
327
  address: Address(network).encode({ type: 'wsh', hash }),
344
328
  hash,
345
329
  };
346
330
  };
347
- exports.p2wsh = p2wsh;
348
- const p2wpkh = (publicKey, network = utils_ts_1.NETWORK) => {
331
+ export const p2wpkh = (publicKey, network = NETWORK) => {
349
332
  if (!isValidPubkey(publicKey, u.PubT.ecdsa))
350
333
  throw new Error('P2WPKH: invalid publicKey');
351
334
  if (publicKey.length === 65)
@@ -353,28 +336,26 @@ const p2wpkh = (publicKey, network = utils_ts_1.NETWORK) => {
353
336
  const hash = u.hash160(publicKey);
354
337
  return {
355
338
  type: 'wpkh',
356
- script: exports.OutScript.encode({ type: 'wpkh', hash }),
339
+ script: OutScript.encode({ type: 'wpkh', hash }),
357
340
  address: Address(network).encode({ type: 'wpkh', hash }),
358
341
  hash,
359
342
  };
360
343
  };
361
- exports.p2wpkh = p2wpkh;
362
- const p2ms = (m, pubkeys, allowSamePubkeys = false) => {
344
+ export const p2ms = (m, pubkeys, allowSamePubkeys = false) => {
363
345
  if (!allowSamePubkeys)
364
346
  uniqPubkey(pubkeys);
365
347
  return {
366
348
  type: 'ms',
367
- script: exports.OutScript.encode({ type: 'ms', pubkeys, m }),
349
+ script: OutScript.encode({ type: 'ms', pubkeys, m }),
368
350
  };
369
351
  };
370
- exports.p2ms = p2ms;
371
352
  function checkTaprootScript(script, internalPubKey, allowUnknownOutputs = false, customScripts) {
372
- const out = exports.OutScript.decode(script);
353
+ const out = OutScript.decode(script);
373
354
  if (out.type === 'unknown') {
374
355
  // NOTE: this check should be before allowUnknownOutputs, otherwise it will
375
356
  // disable custom. All custom scripts for taproot should have prefix 'tr_'
376
357
  if (customScripts) {
377
- const cs = P.apply(script_ts_1.Script, P.coders.match(customScripts));
358
+ const cs = P.apply(Script, P.coders.match(customScripts));
378
359
  const c = cs.decode(script);
379
360
  if (c !== undefined) {
380
361
  if (typeof c.type !== 'string' || !c.type.startsWith('tr_'))
@@ -406,7 +387,7 @@ function checkTaprootScript(script, internalPubKey, allowUnknownOutputs = false,
406
387
  }
407
388
  }
408
389
  // Helper for generating binary tree from list, with weights
409
- function taprootListToTree(taprootList) {
390
+ export function taprootListToTree(taprootList) {
410
391
  // Clone input in order to not corrupt it
411
392
  const lst = Array.from(taprootList);
412
393
  // We have at least 2 elements => can create branch
@@ -462,7 +443,7 @@ function taprootHashTree(tree, internalPubKey, allowUnknownOutputs = false, cust
462
443
  // Earliest tree walk where we can validate tapScripts
463
444
  if (tree.tapLeafScript || (tree.tapMerkleRoot && !u.equalBytes(tree.tapMerkleRoot, P.EMPTY)))
464
445
  throw new Error('P2TR: tapRoot leafScript cannot have tree');
465
- const script = typeof leafScript === 'string' ? base_1.hex.decode(leafScript) : leafScript;
446
+ const script = typeof leafScript === 'string' ? hex.decode(leafScript) : leafScript;
466
447
  if (!u.isBytes(script))
467
448
  throw new Error(`checkScript: wrong script type=${script}`);
468
449
  checkTaprootScript(script, internalPubKey, allowUnknownOutputs, customScripts);
@@ -470,7 +451,7 @@ function taprootHashTree(tree, internalPubKey, allowUnknownOutputs = false, cust
470
451
  type: 'leaf',
471
452
  version,
472
453
  script,
473
- hash: (0, exports.tapLeafHash)(script, version),
454
+ hash: tapLeafHash(script, version),
474
455
  };
475
456
  }
476
457
  // If tree / branch is not binary tree, convert it
@@ -488,15 +469,14 @@ function taprootHashTree(tree, internalPubKey, allowUnknownOutputs = false, cust
488
469
  [lH, rH] = [rH, lH];
489
470
  return { type: 'branch', left, right, hash: u.tagSchnorr('TapBranch', lH, rH) };
490
471
  }
491
- exports.TAP_LEAF_VERSION = 0xc0;
492
- const tapLeafHash = (script, version = exports.TAP_LEAF_VERSION) => u.tagSchnorr('TapLeaf', new Uint8Array([version]), script_ts_1.VarBytes.encode(script));
493
- exports.tapLeafHash = tapLeafHash;
494
- function p2tr(internalPubKey, tree, network = utils_ts_1.NETWORK, allowUnknownOutputs = false, customScripts) {
472
+ export const TAP_LEAF_VERSION = 0xc0;
473
+ export const tapLeafHash = (script, version = TAP_LEAF_VERSION) => u.tagSchnorr('TapLeaf', new Uint8Array([version]), VarBytes.encode(script));
474
+ export function p2tr(internalPubKey, tree, network = NETWORK, allowUnknownOutputs = false, customScripts) {
495
475
  // Unspendable
496
476
  if (!internalPubKey && !tree)
497
477
  throw new Error('p2tr: should have pubKey or scriptTree (or both)');
498
478
  const pubKey = typeof internalPubKey === 'string'
499
- ? base_1.hex.decode(internalPubKey)
479
+ ? hex.decode(internalPubKey)
500
480
  : internalPubKey || u.TAPROOT_UNSPENDABLE_KEY;
501
481
  if (!isValidPubkey(pubKey, u.PubT.schnorr))
502
482
  throw new Error('p2tr: non-schnorr pubkey');
@@ -506,15 +486,15 @@ function p2tr(internalPubKey, tree, network = utils_ts_1.NETWORK, allowUnknownOu
506
486
  const [tweakedPubkey, parity] = u.taprootTweakPubkey(pubKey, tapMerkleRoot);
507
487
  const leaves = taprootWalkTree(hashedTree).map((l) => ({
508
488
  ...l,
509
- controlBlock: psbt_ts_1.TaprootControlBlock.encode({
510
- version: (l.version || exports.TAP_LEAF_VERSION) + parity,
489
+ controlBlock: TaprootControlBlock.encode({
490
+ version: (l.version || TAP_LEAF_VERSION) + parity,
511
491
  internalKey: pubKey,
512
492
  merklePath: l.path,
513
493
  }),
514
494
  }));
515
495
  return {
516
496
  type: 'tr',
517
- script: exports.OutScript.encode({ type: 'tr', pubkey: tweakedPubkey }),
497
+ script: OutScript.encode({ type: 'tr', pubkey: tweakedPubkey }),
518
498
  address: Address(network).encode({ type: 'tr', pubkey: tweakedPubkey }),
519
499
  // For tests
520
500
  tweakedPubkey,
@@ -522,8 +502,8 @@ function p2tr(internalPubKey, tree, network = utils_ts_1.NETWORK, allowUnknownOu
522
502
  tapInternalKey: pubKey,
523
503
  leaves,
524
504
  tapLeafScript: leaves.map((l) => [
525
- psbt_ts_1.TaprootControlBlock.decode(l.controlBlock),
526
- u.concatBytes(l.script, new Uint8Array([l.version || exports.TAP_LEAF_VERSION])),
505
+ TaprootControlBlock.decode(l.controlBlock),
506
+ u.concatBytes(l.script, new Uint8Array([l.version || TAP_LEAF_VERSION])),
527
507
  ]),
528
508
  tapMerkleRoot,
529
509
  };
@@ -532,7 +512,7 @@ function p2tr(internalPubKey, tree, network = utils_ts_1.NETWORK, allowUnknownOu
532
512
  const tweakedPubkey = u.taprootTweakPubkey(pubKey, P.EMPTY)[0];
533
513
  return {
534
514
  type: 'tr',
535
- script: exports.OutScript.encode({ type: 'tr', pubkey: tweakedPubkey }),
515
+ script: OutScript.encode({ type: 'tr', pubkey: tweakedPubkey }),
536
516
  address: Address(network).encode({ type: 'tr', pubkey: tweakedPubkey }),
537
517
  // For tests
538
518
  tweakedPubkey,
@@ -542,7 +522,7 @@ function p2tr(internalPubKey, tree, network = utils_ts_1.NETWORK, allowUnknownOu
542
522
  }
543
523
  }
544
524
  // Returns all combinations of size M from lst
545
- function combinations(m, list) {
525
+ export function combinations(m, list) {
546
526
  const res = [];
547
527
  if (!Array.isArray(list))
548
528
  throw new Error('combinations: lst arg should be array');
@@ -575,47 +555,44 @@ function combinations(m, list) {
575
555
  }
576
556
  return res;
577
557
  }
578
- const p2tr_ns = (m, pubkeys, allowSamePubkeys = false) => {
558
+ export const p2tr_ns = (m, pubkeys, allowSamePubkeys = false) => {
579
559
  if (!allowSamePubkeys)
580
560
  uniqPubkey(pubkeys);
581
561
  return combinations(m, pubkeys).map((i) => ({
582
562
  type: 'tr_ns',
583
- script: exports.OutScript.encode({ type: 'tr_ns', pubkeys: i }),
563
+ script: OutScript.encode({ type: 'tr_ns', pubkeys: i }),
584
564
  }));
585
565
  };
586
- exports.p2tr_ns = p2tr_ns;
587
- const p2tr_pk = (pubkey) => (0, exports.p2tr_ns)(1, [pubkey], undefined)[0];
588
- exports.p2tr_pk = p2tr_pk;
589
- function p2tr_ms(m, pubkeys, allowSamePubkeys = false) {
566
+ export const p2tr_pk = (pubkey) => p2tr_ns(1, [pubkey], undefined)[0];
567
+ export function p2tr_ms(m, pubkeys, allowSamePubkeys = false) {
590
568
  if (!allowSamePubkeys)
591
569
  uniqPubkey(pubkeys);
592
570
  return {
593
571
  type: 'tr_ms',
594
- script: exports.OutScript.encode({ type: 'tr_ms', pubkeys, m }),
572
+ script: OutScript.encode({ type: 'tr_ms', pubkeys, m }),
595
573
  };
596
574
  }
597
575
  // Simple pubkey address, without complex scripts
598
- function getAddress(type, privKey, network = utils_ts_1.NETWORK) {
576
+ export function getAddress(type, privKey, network = NETWORK) {
599
577
  if (type === 'tr') {
600
578
  return p2tr(u.pubSchnorr(privKey), undefined, network).address;
601
579
  }
602
580
  const pubKey = u.pubECDSA(privKey);
603
581
  if (type === 'pkh')
604
- return (0, exports.p2pkh)(pubKey, network).address;
582
+ return p2pkh(pubKey, network).address;
605
583
  if (type === 'wpkh')
606
- return (0, exports.p2wpkh)(pubKey, network).address;
584
+ return p2wpkh(pubKey, network).address;
607
585
  throw new Error(`getAddress: unknown type=${type}`);
608
586
  }
609
- const _sortPubkeys = (pubkeys) => Array.from(pubkeys).sort(u.compareBytes);
610
- exports._sortPubkeys = _sortPubkeys;
611
- function multisig(m, pubkeys, sorted = false, witness = false, network = utils_ts_1.NETWORK) {
612
- const ms = (0, exports.p2ms)(m, sorted ? (0, exports._sortPubkeys)(pubkeys) : pubkeys);
613
- return witness ? (0, exports.p2wsh)(ms, network) : (0, exports.p2sh)(ms, network);
587
+ export const _sortPubkeys = (pubkeys) => Array.from(pubkeys).sort(u.compareBytes);
588
+ export function multisig(m, pubkeys, sorted = false, witness = false, network = NETWORK) {
589
+ const ms = p2ms(m, sorted ? _sortPubkeys(pubkeys) : pubkeys);
590
+ return witness ? p2wsh(ms, network) : p2sh(ms, network);
614
591
  }
615
- function sortedMultisig(m, pubkeys, witness = false, network = utils_ts_1.NETWORK) {
592
+ export function sortedMultisig(m, pubkeys, witness = false, network = NETWORK) {
616
593
  return multisig(m, pubkeys, true, witness, network);
617
594
  }
618
- const base58check = (0, base_1.createBase58check)(u.sha256);
595
+ const base58check = createBase58check(u.sha256);
619
596
  function validateWitness(version, data) {
620
597
  if (data.length < 2 || data.length > 40)
621
598
  throw new Error('Witness: invalid length');
@@ -624,15 +601,15 @@ function validateWitness(version, data) {
624
601
  if (version === 0 && !(data.length === 20 || data.length === 32))
625
602
  throw new Error('Witness: invalid length for version');
626
603
  }
627
- function programToWitness(version, data, network = utils_ts_1.NETWORK) {
604
+ function programToWitness(version, data, network = NETWORK) {
628
605
  validateWitness(version, data);
629
- const coder = version === 0 ? base_1.bech32 : base_1.bech32m;
606
+ const coder = version === 0 ? bech32 : bech32m;
630
607
  return coder.encode(network.bech32, [version].concat(coder.toWords(data)));
631
608
  }
632
609
  function formatKey(hashed, prefix) {
633
610
  return base58check.encode(u.concatBytes(Uint8Array.from(prefix), hashed));
634
611
  }
635
- function WIF(network = utils_ts_1.NETWORK) {
612
+ export function WIF(network = NETWORK) {
636
613
  return {
637
614
  encode(privKey) {
638
615
  const compressed = u.concatBytes(privKey, new Uint8Array([0x01]));
@@ -653,7 +630,7 @@ function WIF(network = utils_ts_1.NETWORK) {
653
630
  };
654
631
  }
655
632
  // Returns OutType, which can be used to create outscript
656
- function Address(network = utils_ts_1.NETWORK) {
633
+ export function Address(network = NETWORK) {
657
634
  return {
658
635
  encode(from) {
659
636
  const { type } = from;
@@ -676,20 +653,20 @@ function Address(network = utils_ts_1.NETWORK) {
676
653
  if (network.bech32 && address.toLowerCase().startsWith(`${network.bech32}1`)) {
677
654
  let res;
678
655
  try {
679
- res = base_1.bech32.decode(address);
656
+ res = bech32.decode(address);
680
657
  if (res.words[0] !== 0)
681
658
  throw new Error(`bech32: wrong version=${res.words[0]}`);
682
659
  }
683
660
  catch (_) {
684
661
  // Starting from version 1 it is decoded as bech32m
685
- res = base_1.bech32m.decode(address);
662
+ res = bech32m.decode(address);
686
663
  if (res.words[0] === 0)
687
664
  throw new Error(`bech32m: wrong version=${res.words[0]}`);
688
665
  }
689
666
  if (res.prefix !== network.bech32)
690
667
  throw new Error(`wrong bech32 prefix=${res.prefix}`);
691
668
  const [version, ...program] = res.words;
692
- const data = base_1.bech32.fromWords(program);
669
+ const data = bech32.fromWords(program);
693
670
  validateWitness(version, data);
694
671
  if (version === 0 && data.length === 32)
695
672
  return { type: 'wsh', hash: data };