@bitcoinerlab/descriptors 2.3.3 → 2.3.5

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.
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import { Network, Payment, Psbt } from 'bitcoinjs-lib';
4
2
  import type { PartialSig } from 'bip174/src/lib/interfaces';
5
3
  import { BIP32API } from 'bip32';
@@ -31,7 +29,7 @@ import type { TinySecp256k1Interface, Preimage, TimeConstraints, Expansion, Expa
31
29
  * [@bitcoinerlab/secp256k1](https://github.com/bitcoinerlab/secp256k1).
32
30
  */
33
31
  export declare function DescriptorsFactory(ecc: TinySecp256k1Interface): {
34
- /** @deprecated */ Descriptor: {
32
+ /** @deprecated @hidden */ Descriptor: {
35
33
  new ({ expression, ...rest }: {
36
34
  expression: string;
37
35
  index?: number;
@@ -41,18 +39,18 @@ export declare function DescriptorsFactory(ecc: TinySecp256k1Interface): {
41
39
  preimages?: Preimage[];
42
40
  signersPubKeys?: Buffer[];
43
41
  }): {
44
- readonly "__#1@#payment": Payment;
45
- readonly "__#1@#preimages": Preimage[];
46
- readonly "__#1@#signersPubKeys": Buffer[];
47
- readonly "__#1@#miniscript"?: string;
48
- readonly "__#1@#witnessScript"?: Buffer;
49
- readonly "__#1@#redeemScript"?: Buffer;
50
- readonly "__#1@#isSegwit"?: boolean;
51
- readonly "__#1@#isTaproot"?: boolean;
52
- readonly "__#1@#expandedExpression"?: string;
53
- readonly "__#1@#expandedMiniscript"?: string;
54
- readonly "__#1@#expansionMap"?: ExpansionMap;
55
- readonly "__#1@#network": Network;
42
+ readonly "__#private@#payment": Payment;
43
+ readonly "__#private@#preimages": Preimage[];
44
+ readonly "__#private@#signersPubKeys": Buffer[];
45
+ readonly "__#private@#miniscript"?: string;
46
+ readonly "__#private@#witnessScript"?: Buffer;
47
+ readonly "__#private@#redeemScript"?: Buffer;
48
+ readonly "__#private@#isSegwit"?: boolean;
49
+ readonly "__#private@#isTaproot"?: boolean;
50
+ readonly "__#private@#expandedExpression"?: string;
51
+ readonly "__#private@#expandedMiniscript"?: string;
52
+ readonly "__#private@#expansionMap"?: ExpansionMap;
53
+ readonly "__#private@#network": Network;
56
54
  /**
57
55
  * Gets the TimeConstraints (nSequence and nLockTime) of the miniscript
58
56
  * descriptor as passed in the constructor, just using the expression,
@@ -67,7 +65,7 @@ export declare function DescriptorsFactory(ecc: TinySecp256k1Interface): {
67
65
  * When running getScriptSatisfaction, using the final signatures,
68
66
  * satisfyMiniscript verifies that the time constraints did not change.
69
67
  */
70
- "__#1@#getTimeConstraints"(): TimeConstraints | undefined;
68
+ "__#private@#getTimeConstraints"(): TimeConstraints | undefined;
71
69
  /**
72
70
  * Creates and returns an instance of bitcoinjs-lib
73
71
  * [`Payment`](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/ts_src/payments/index.ts)'s interface with the `scriptPubKey` of this `Output`.
@@ -92,7 +90,7 @@ export declare function DescriptorsFactory(ecc: TinySecp256k1Interface): {
92
90
  * Important: As mentioned above, note that this function only applies to
93
91
  * miniscript descriptors.
94
92
  */
95
- getScriptSatisfaction(signatures: PartialSig[] | 'DANGEROUSLY_USE_FAKE_SIGNATURES'): Buffer;
93
+ getScriptSatisfaction(signatures: PartialSig[] | "DANGEROUSLY_USE_FAKE_SIGNATURES"): Buffer;
96
94
  /**
97
95
  * Gets the nSequence required to fulfill this `Output`.
98
96
  */
@@ -165,7 +163,7 @@ export declare function DescriptorsFactory(ecc: TinySecp256k1Interface): {
165
163
  * Note however that tr(MINISCRIPT) is not yet supported for non-single-key
166
164
  * expressions.
167
165
  */
168
- inputWeight(isSegwitTx: boolean, signatures: PartialSig[] | 'DANGEROUSLY_USE_FAKE_SIGNATURES'): number;
166
+ inputWeight(isSegwitTx: boolean, signatures: PartialSig[] | "DANGEROUSLY_USE_FAKE_SIGNATURES"): number;
169
167
  /**
170
168
  * Computes the Weight Unit contributions of this Output as if it were the
171
169
  * output in a tx.
@@ -232,15 +230,15 @@ export declare function DescriptorsFactory(ecc: TinySecp256k1Interface): {
232
230
  /**
233
231
  * Adds this output as an output of the provided `psbt` with the given
234
232
  * value.
235
- *
236
- * @param psbt - The Partially Signed Bitcoin Transaction.
237
- * @param value - The value for the output in satoshis.
233
+ * @param params - The parameters for the method.
234
+ * @param params.psbt - The Partially Signed Bitcoin Transaction.
235
+ * @param params.value - The value for the output in satoshis.
238
236
  */
239
237
  updatePsbtAsOutput({ psbt, value }: {
240
238
  psbt: Psbt;
241
239
  value: number;
242
240
  }): void;
243
- "__#1@#assertPsbtInput"({ psbt, index }: {
241
+ "__#private@#assertPsbtInput"({ psbt, index }: {
244
242
  psbt: Psbt;
245
243
  index: number;
246
244
  }): void;
@@ -354,18 +352,18 @@ export declare function DescriptorsFactory(ecc: TinySecp256k1Interface): {
354
352
  */
355
353
  signersPubKeys?: Buffer[];
356
354
  }): {
357
- readonly "__#1@#payment": Payment;
358
- readonly "__#1@#preimages": Preimage[];
359
- readonly "__#1@#signersPubKeys": Buffer[];
360
- readonly "__#1@#miniscript"?: string;
361
- readonly "__#1@#witnessScript"?: Buffer;
362
- readonly "__#1@#redeemScript"?: Buffer;
363
- readonly "__#1@#isSegwit"?: boolean;
364
- readonly "__#1@#isTaproot"?: boolean;
365
- readonly "__#1@#expandedExpression"?: string;
366
- readonly "__#1@#expandedMiniscript"?: string;
367
- readonly "__#1@#expansionMap"?: ExpansionMap;
368
- readonly "__#1@#network": Network;
355
+ readonly "__#private@#payment": Payment;
356
+ readonly "__#private@#preimages": Preimage[];
357
+ readonly "__#private@#signersPubKeys": Buffer[];
358
+ readonly "__#private@#miniscript"?: string;
359
+ readonly "__#private@#witnessScript"?: Buffer;
360
+ readonly "__#private@#redeemScript"?: Buffer;
361
+ readonly "__#private@#isSegwit"?: boolean;
362
+ readonly "__#private@#isTaproot"?: boolean;
363
+ readonly "__#private@#expandedExpression"?: string;
364
+ readonly "__#private@#expandedMiniscript"?: string;
365
+ readonly "__#private@#expansionMap"?: ExpansionMap;
366
+ readonly "__#private@#network": Network;
369
367
  /**
370
368
  * Gets the TimeConstraints (nSequence and nLockTime) of the miniscript
371
369
  * descriptor as passed in the constructor, just using the expression,
@@ -380,7 +378,7 @@ export declare function DescriptorsFactory(ecc: TinySecp256k1Interface): {
380
378
  * When running getScriptSatisfaction, using the final signatures,
381
379
  * satisfyMiniscript verifies that the time constraints did not change.
382
380
  */
383
- "__#1@#getTimeConstraints"(): TimeConstraints | undefined;
381
+ "__#private@#getTimeConstraints"(): TimeConstraints | undefined;
384
382
  /**
385
383
  * Creates and returns an instance of bitcoinjs-lib
386
384
  * [`Payment`](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/ts_src/payments/index.ts)'s interface with the `scriptPubKey` of this `Output`.
@@ -405,7 +403,7 @@ export declare function DescriptorsFactory(ecc: TinySecp256k1Interface): {
405
403
  * Important: As mentioned above, note that this function only applies to
406
404
  * miniscript descriptors.
407
405
  */
408
- getScriptSatisfaction(signatures: PartialSig[] | 'DANGEROUSLY_USE_FAKE_SIGNATURES'): Buffer;
406
+ getScriptSatisfaction(signatures: PartialSig[] | "DANGEROUSLY_USE_FAKE_SIGNATURES"): Buffer;
409
407
  /**
410
408
  * Gets the nSequence required to fulfill this `Output`.
411
409
  */
@@ -478,7 +476,7 @@ export declare function DescriptorsFactory(ecc: TinySecp256k1Interface): {
478
476
  * Note however that tr(MINISCRIPT) is not yet supported for non-single-key
479
477
  * expressions.
480
478
  */
481
- inputWeight(isSegwitTx: boolean, signatures: PartialSig[] | 'DANGEROUSLY_USE_FAKE_SIGNATURES'): number;
479
+ inputWeight(isSegwitTx: boolean, signatures: PartialSig[] | "DANGEROUSLY_USE_FAKE_SIGNATURES"): number;
482
480
  /**
483
481
  * Computes the Weight Unit contributions of this Output as if it were the
484
482
  * output in a tx.
@@ -545,15 +543,15 @@ export declare function DescriptorsFactory(ecc: TinySecp256k1Interface): {
545
543
  /**
546
544
  * Adds this output as an output of the provided `psbt` with the given
547
545
  * value.
548
- *
549
- * @param psbt - The Partially Signed Bitcoin Transaction.
550
- * @param value - The value for the output in satoshis.
546
+ * @param params - The parameters for the method.
547
+ * @param params.psbt - The Partially Signed Bitcoin Transaction.
548
+ * @param params.value - The value for the output in satoshis.
551
549
  */
552
550
  updatePsbtAsOutput({ psbt, value }: {
553
551
  psbt: Psbt;
554
552
  value: number;
555
553
  }): void;
556
- "__#1@#assertPsbtInput"({ psbt, index }: {
554
+ "__#private@#assertPsbtInput"({ psbt, index }: {
557
555
  psbt: Psbt;
558
556
  index: number;
559
557
  }): void;
@@ -17,13 +17,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
17
17
  }) : function(o, v) {
18
18
  o["default"] = v;
19
19
  });
20
- var __importStar = (this && this.__importStar) || function (mod) {
21
- if (mod && mod.__esModule) return mod;
22
- var result = {};
23
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
24
- __setModuleDefault(result, mod);
25
- return result;
26
- };
20
+ var __importStar = (this && this.__importStar) || (function () {
21
+ var ownKeys = function(o) {
22
+ ownKeys = Object.getOwnPropertyNames || function (o) {
23
+ var ar = [];
24
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
25
+ return ar;
26
+ };
27
+ return ownKeys(o);
28
+ };
29
+ return function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
36
+ })();
27
37
  var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
28
38
  if (kind === "m") throw new TypeError("Private method is not writable");
29
39
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
@@ -39,7 +49,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
49
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
50
  };
41
51
  Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.DescriptorsFactory = void 0;
52
+ exports.DescriptorsFactory = DescriptorsFactory;
43
53
  const lodash_memoize_1 = __importDefault(require("lodash.memoize"));
44
54
  const bitcoinjs_lib_1 = require("bitcoinjs-lib");
45
55
  const varuint_bitcoin_1 = require("varuint-bitcoin");
@@ -122,6 +132,22 @@ function evaluate({ descriptor, checksumRequired, index }) {
122
132
  }
123
133
  return evaluatedDescriptor;
124
134
  }
135
+ // Helper: parse sortedmulti(M, k1, k2,...)
136
+ function parseSortedMulti(inner) {
137
+ // inner: "2,key1,key2,key3"
138
+ const parts = inner.split(',').map(p => p.trim());
139
+ if (parts.length < 2)
140
+ throw new Error(`sortedmulti(): must contain M and at least one key: ${inner}`);
141
+ const m = Number(parts[0]);
142
+ if (!Number.isInteger(m) || m < 1 || m > 20)
143
+ throw new Error(`sortedmulti(): invalid M=${parts[0]}`);
144
+ const keyExpressions = parts.slice(1);
145
+ if (keyExpressions.length < m)
146
+ throw new Error(`sortedmulti(): M cannot exceed number of keys: ${inner}`);
147
+ if (keyExpressions.length > 20)
148
+ throw new Error(`sortedmulti(): descriptors support up to 20 keys (per BIP 380/383).`);
149
+ return { m, keyExpressions };
150
+ }
125
151
  /**
126
152
  * Constructs the necessary functions and classes for working with descriptors
127
153
  * using an external elliptic curve (ecc) library.
@@ -178,7 +204,7 @@ function DescriptorsFactory(ecc) {
178
204
  });
179
205
  };
180
206
  /**
181
- * @hidden
207
+ * @overload
182
208
  * To be removed in v3.0 and replaced by the version with the signature that
183
209
  * does not accept descriptors
184
210
  */
@@ -349,6 +375,97 @@ function DescriptorsFactory(ecc) {
349
375
  payment = p2wpkh({ pubkey, network });
350
376
  }
351
377
  }
378
+ // sortedmulti script expressions
379
+ // sh(sortedmulti())
380
+ else if (canonicalExpression.match(RE.reShSortedMultiAnchored)) {
381
+ isSegwit = false;
382
+ isTaproot = false;
383
+ const inner = canonicalExpression.match(RE.reShSortedMultiAnchored)?.[1];
384
+ if (!inner)
385
+ throw new Error(`Error extracting sortedmulti() in ${descriptor}`);
386
+ const { m, keyExpressions } = parseSortedMulti(inner);
387
+ const pKEs = keyExpressions.map(k => parseKeyExpression({ keyExpression: k, network, isSegwit: false }));
388
+ const map = {};
389
+ pKEs.forEach((pke, i) => (map['@' + i] = pke));
390
+ expansionMap = map;
391
+ expandedExpression =
392
+ 'sh(sortedmulti(' +
393
+ [m, ...Object.keys(expansionMap).map(k => k)].join(',') +
394
+ '))';
395
+ if (!isCanonicalRanged) {
396
+ const pubkeys = pKEs.map(p => {
397
+ if (!p.pubkey)
398
+ throw new Error(`Error: key has no pubkey`);
399
+ return p.pubkey;
400
+ });
401
+ pubkeys.sort((a, b) => a.compare(b));
402
+ const redeem = bitcoinjs_lib_1.payments.p2ms({ m, pubkeys, network });
403
+ redeemScript = redeem.output;
404
+ if (!redeemScript)
405
+ throw new Error(`Error creating redeemScript`);
406
+ payment = bitcoinjs_lib_1.payments.p2sh({ redeem, network });
407
+ }
408
+ }
409
+ // wsh(sortedmulti())
410
+ else if (canonicalExpression.match(RE.reWshSortedMultiAnchored)) {
411
+ isSegwit = true;
412
+ isTaproot = false;
413
+ const inner = canonicalExpression.match(RE.reWshSortedMultiAnchored)?.[1];
414
+ if (!inner)
415
+ throw new Error(`Error extracting sortedmulti() in ${descriptor}`);
416
+ const { m, keyExpressions } = parseSortedMulti(inner);
417
+ const pKEs = keyExpressions.map(k => parseKeyExpression({ keyExpression: k, network, isSegwit: true }));
418
+ const map = {};
419
+ pKEs.forEach((pke, i) => (map['@' + i] = pke));
420
+ expansionMap = map;
421
+ expandedExpression =
422
+ 'wsh(sortedmulti(' +
423
+ [m, ...Object.keys(expansionMap).map(k => k)].join(',') +
424
+ '))';
425
+ if (!isCanonicalRanged) {
426
+ const pubkeys = pKEs.map(p => {
427
+ if (!p.pubkey)
428
+ throw new Error(`Error: key has no pubkey`);
429
+ return p.pubkey;
430
+ });
431
+ pubkeys.sort((a, b) => a.compare(b));
432
+ const redeem = bitcoinjs_lib_1.payments.p2ms({ m, pubkeys, network });
433
+ witnessScript = redeem.output;
434
+ if (!witnessScript)
435
+ throw new Error(`Error computing witnessScript`);
436
+ payment = bitcoinjs_lib_1.payments.p2wsh({ redeem, network });
437
+ }
438
+ }
439
+ // sh(wsh(sortedmulti()))
440
+ else if (canonicalExpression.match(RE.reShWshSortedMultiAnchored)) {
441
+ isSegwit = true;
442
+ isTaproot = false;
443
+ const inner = canonicalExpression.match(RE.reShWshSortedMultiAnchored)?.[1];
444
+ if (!inner)
445
+ throw new Error(`Error extracting sortedmulti() in ${descriptor}`);
446
+ const { m, keyExpressions } = parseSortedMulti(inner);
447
+ const pKEs = keyExpressions.map(k => parseKeyExpression({ keyExpression: k, network, isSegwit: true }));
448
+ const map = {};
449
+ pKEs.forEach((pke, i) => (map['@' + i] = pke));
450
+ expansionMap = map;
451
+ expandedExpression =
452
+ 'sh(wsh(sortedmulti(' +
453
+ [m, ...Object.keys(expansionMap).map(k => k)].join(',') +
454
+ ')))';
455
+ if (!isCanonicalRanged) {
456
+ const pubkeys = pKEs.map(p => {
457
+ if (!p.pubkey)
458
+ throw new Error(`Error: key has no pubkey`);
459
+ return p.pubkey;
460
+ });
461
+ pubkeys.sort((a, b) => a.compare(b));
462
+ const redeem = bitcoinjs_lib_1.payments.p2ms({ m, pubkeys, network });
463
+ const wsh = bitcoinjs_lib_1.payments.p2wsh({ redeem, network });
464
+ witnessScript = redeem.output;
465
+ redeemScript = wsh.output;
466
+ payment = bitcoinjs_lib_1.payments.p2sh({ redeem: wsh, network });
467
+ }
468
+ }
352
469
  //sh(wsh(miniscript))
353
470
  else if (canonicalExpression.match(RE.reShWshMiniscriptAnchored)) {
354
471
  isSegwit = true;
@@ -1090,9 +1207,9 @@ expansion=${expansion}, isPKH=${isPKH}, isWPKH=${isWPKH}, isSH=${isSH}, isTR=${i
1090
1207
  /**
1091
1208
  * Adds this output as an output of the provided `psbt` with the given
1092
1209
  * value.
1093
- *
1094
- * @param psbt - The Partially Signed Bitcoin Transaction.
1095
- * @param value - The value for the output in satoshis.
1210
+ * @param params - The parameters for the method.
1211
+ * @param params.psbt - The Partially Signed Bitcoin Transaction.
1212
+ * @param params.value - The value for the output in satoshis.
1096
1213
  */
1097
1214
  updatePsbtAsOutput({ psbt, value }) {
1098
1215
  psbt.addOutput({ script: this.getScriptPubKey(), value });
@@ -1251,7 +1368,7 @@ expansion=${expansion}, isPKH=${isPKH}, isWPKH=${isWPKH}, isSH=${isSH}, isTR=${i
1251
1368
  }
1252
1369
  return {
1253
1370
  // deprecated TAG must also be below so it is exported to descriptors.d.ts
1254
- /** @deprecated */ Descriptor,
1371
+ /** @deprecated @hidden */ Descriptor,
1255
1372
  Output,
1256
1373
  parseKeyExpression,
1257
1374
  expand,
@@ -1259,4 +1376,3 @@ expansion=${expansion}, isPKH=${isPKH}, isWPKH=${isWPKH}, isSH=${isSH}, isTR=${i
1259
1376
  BIP32
1260
1377
  };
1261
1378
  }
1262
- exports.DescriptorsFactory = DescriptorsFactory;
package/dist/index.d.ts CHANGED
@@ -34,10 +34,15 @@ export { keyExpressionBIP32, keyExpressionLedger } from './keyExpressions';
34
34
  import * as scriptExpressions from './scriptExpressions';
35
35
  export { scriptExpressions };
36
36
  import { LedgerState, getLedgerMasterFingerPrint, getLedgerXpub, registerLedgerWallet, assertLedgerApp, LedgerManager } from './ledger';
37
+ /** @namespace */
37
38
  export declare const ledger: {
39
+ /** @function */
38
40
  getLedgerMasterFingerPrint: typeof getLedgerMasterFingerPrint;
41
+ /** @function */
39
42
  getLedgerXpub: typeof getLedgerXpub;
43
+ /** @function */
40
44
  registerLedgerWallet: typeof registerLedgerWallet;
45
+ /** @function */
41
46
  assertLedgerApp: typeof assertLedgerApp;
42
47
  };
43
48
  export type { LedgerState, LedgerManager };
package/dist/index.js CHANGED
@@ -17,15 +17,26 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
17
17
  }) : function(o, v) {
18
18
  o["default"] = v;
19
19
  });
20
- var __importStar = (this && this.__importStar) || function (mod) {
21
- if (mod && mod.__esModule) return mod;
22
- var result = {};
23
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
24
- __setModuleDefault(result, mod);
25
- return result;
26
- };
20
+ var __importStar = (this && this.__importStar) || (function () {
21
+ var ownKeys = function(o) {
22
+ ownKeys = Object.getOwnPropertyNames || function (o) {
23
+ var ar = [];
24
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
25
+ return ar;
26
+ };
27
+ return ownKeys(o);
28
+ };
29
+ return function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
36
+ })();
27
37
  Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.ledger = exports.scriptExpressions = exports.keyExpressionLedger = exports.keyExpressionBIP32 = exports.finalizePsbt = exports.signers = exports.checksum = exports.DescriptorsFactory = void 0;
38
+ exports.ledger = exports.scriptExpressions = exports.keyExpressionLedger = exports.keyExpressionBIP32 = exports.signers = exports.checksum = exports.DescriptorsFactory = void 0;
39
+ exports.finalizePsbt = finalizePsbt;
29
40
  // Some dependencies (like hash-base) assume process.version exists.
30
41
  // In React Native / Hermes, process is defined but version is not.
31
42
  // Note: we only polyfill if process already exists but is incomplete.
@@ -69,16 +80,20 @@ function finalizePsbt({ psbt, outputs, descriptors, validate = true }) {
69
80
  throw new Error(`outputs not provided`);
70
81
  outputs.forEach((output, inputIndex) => output.finalizePsbtInput({ index: inputIndex, psbt, validate }));
71
82
  }
72
- exports.finalizePsbt = finalizePsbt;
73
83
  var keyExpressions_1 = require("./keyExpressions");
74
84
  Object.defineProperty(exports, "keyExpressionBIP32", { enumerable: true, get: function () { return keyExpressions_1.keyExpressionBIP32; } });
75
85
  Object.defineProperty(exports, "keyExpressionLedger", { enumerable: true, get: function () { return keyExpressions_1.keyExpressionLedger; } });
76
86
  const scriptExpressions = __importStar(require("./scriptExpressions"));
77
87
  exports.scriptExpressions = scriptExpressions;
78
88
  const ledger_1 = require("./ledger");
89
+ /** @namespace */
79
90
  exports.ledger = {
91
+ /** @function */
80
92
  getLedgerMasterFingerPrint: ledger_1.getLedgerMasterFingerPrint,
93
+ /** @function */
81
94
  getLedgerXpub: ledger_1.getLedgerXpub,
95
+ /** @function */
82
96
  registerLedgerWallet: ledger_1.registerLedgerWallet,
97
+ /** @function */
83
98
  assertLedgerApp: ledger_1.assertLedgerApp
84
99
  };
@@ -61,7 +61,7 @@ export declare function keyExpressionLedger({ ledgerManager, originPath, keyPath
61
61
  index?: number | undefined | '*';
62
62
  keyPath?: string | undefined;
63
63
  }): Promise<string>;
64
- /** @deprecated @hidden */
64
+ /** @hidden */
65
65
  export declare function keyExpressionLedger({ ledgerClient, ledgerState, originPath, keyPath, change, index }: {
66
66
  ledgerClient: unknown;
67
67
  ledgerState: LedgerState;
@@ -17,15 +17,27 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
17
17
  }) : function(o, v) {
18
18
  o["default"] = v;
19
19
  });
20
- var __importStar = (this && this.__importStar) || function (mod) {
21
- if (mod && mod.__esModule) return mod;
22
- var result = {};
23
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
24
- __setModuleDefault(result, mod);
25
- return result;
26
- };
20
+ var __importStar = (this && this.__importStar) || (function () {
21
+ var ownKeys = function(o) {
22
+ ownKeys = Object.getOwnPropertyNames || function (o) {
23
+ var ar = [];
24
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
25
+ return ar;
26
+ };
27
+ return ownKeys(o);
28
+ };
29
+ return function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
36
+ })();
27
37
  Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.keyExpressionBIP32 = exports.keyExpressionLedger = exports.parseKeyExpression = void 0;
38
+ exports.parseKeyExpression = parseKeyExpression;
39
+ exports.keyExpressionLedger = keyExpressionLedger;
40
+ exports.keyExpressionBIP32 = keyExpressionBIP32;
29
41
  const bitcoinjs_lib_1 = require("bitcoinjs-lib");
30
42
  const ledger_1 = require("./ledger");
31
43
  const RE = __importStar(require("./re"));
@@ -188,7 +200,6 @@ function parseKeyExpression({ keyExpression, isSegwit, isTaproot, ECPair, BIP32,
188
200
  ...(path !== undefined ? { path } : {})
189
201
  };
190
202
  }
191
- exports.parseKeyExpression = parseKeyExpression;
192
203
  function assertChangeIndexKeyPath({ change, index, keyPath }) {
193
204
  if (!((change === undefined && index === undefined) ||
194
205
  (change !== undefined && index !== undefined)))
@@ -196,7 +207,7 @@ function assertChangeIndexKeyPath({ change, index, keyPath }) {
196
207
  if ((change !== undefined) === (keyPath !== undefined))
197
208
  throw new Error(`Error: Pass either change and index or a keyPath`);
198
209
  }
199
- /** @hidden */
210
+ /** @overload */
200
211
  async function keyExpressionLedger({ ledgerClient, ledgerState, ledgerManager, originPath, keyPath, change, index }) {
201
212
  if (ledgerManager && (ledgerClient || ledgerState))
202
213
  throw new Error(`ledgerClient and ledgerState have been deprecated`);
@@ -217,7 +228,6 @@ async function keyExpressionLedger({ ledgerClient, ledgerState, ledgerManager, o
217
228
  else
218
229
  return `${keyRoot}/${change}/${index}`;
219
230
  }
220
- exports.keyExpressionLedger = keyExpressionLedger;
221
231
  /**
222
232
  * Constructs a key expression string from its constituent components.
223
233
  *
@@ -239,4 +249,3 @@ function keyExpressionBIP32({ masterNode, originPath, keyPath, change, index, is
239
249
  else
240
250
  return `${keyRoot}/${change}/${index}`;
241
251
  }
242
- exports.keyExpressionBIP32 = keyExpressionBIP32;
package/dist/ledger.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import { DescriptorInstance, OutputInstance } from './descriptors';
4
2
  import { Network, Psbt } from 'bitcoinjs-lib';
5
3
  import type { TinySecp256k1Interface } from './types';
@@ -71,16 +69,20 @@ export type LedgerManager = {
71
69
  ecc: TinySecp256k1Interface;
72
70
  network: Network;
73
71
  };
74
- /** Retrieves the masterFingerPrint of a Ledger device */
72
+ /**
73
+ * Retrieves the masterFingerPrint of a Ledger device
74
+ */
75
75
  export declare function getLedgerMasterFingerPrint({ ledgerManager }: {
76
76
  ledgerManager: LedgerManager;
77
77
  }): Promise<Buffer>;
78
- /** @deprecated @hidden */
78
+ /** @hidden */
79
79
  export declare function getLedgerMasterFingerPrint({ ledgerClient, ledgerState }: {
80
80
  ledgerClient: unknown;
81
81
  ledgerState: LedgerState;
82
82
  }): Promise<Buffer>;
83
- /** Retrieves the xpub of a certain originPath of a Ledger device */
83
+ /**
84
+ * Retrieves the xpub of a certain originPath of a Ledger device
85
+ */
84
86
  export declare function getLedgerXpub({ originPath, ledgerManager }: {
85
87
  originPath: string;
86
88
  ledgerManager: LedgerManager;
@@ -153,7 +155,6 @@ export declare function ledgerPolicyFromOutput({ output, ledgerClient, ledgerSta
153
155
  * all addresses (both external and internal).
154
156
  * - This means that the registered Ledger Policy is a generalized version of the descriptor,
155
157
  * not assuming specific values for the keyPath.
156
- *
157
158
  */
158
159
  export declare function registerLedgerWallet({ descriptor, ledgerManager, policyName }: {
159
160
  descriptor: string;
@@ -162,7 +163,6 @@ export declare function registerLedgerWallet({ descriptor, ledgerManager, policy
162
163
  policyName: string;
163
164
  }): Promise<void>;
164
165
  /**
165
- * @deprecated
166
166
  * @hidden
167
167
  */
168
168
  export declare function registerLedgerWallet({ descriptor, ledgerClient, ledgerState, policyName }: {
package/dist/ledger.js CHANGED
@@ -2,7 +2,16 @@
2
2
  // Copyright (c) 2023 Jose-Luis Landabaso - https://bitcoinerlab.com
3
3
  // Distributed under the MIT software license
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.ledgerPolicyFromState = exports.comparePolicies = exports.ledgerPolicyFromStandard = exports.registerLedgerWallet = exports.ledgerPolicyFromOutput = exports.ledgerPolicyFromPsbtInput = exports.getLedgerXpub = exports.getLedgerMasterFingerPrint = exports.assertLedgerApp = exports.importAndValidateLedgerBitcoin = void 0;
5
+ exports.importAndValidateLedgerBitcoin = importAndValidateLedgerBitcoin;
6
+ exports.assertLedgerApp = assertLedgerApp;
7
+ exports.getLedgerMasterFingerPrint = getLedgerMasterFingerPrint;
8
+ exports.getLedgerXpub = getLedgerXpub;
9
+ exports.ledgerPolicyFromPsbtInput = ledgerPolicyFromPsbtInput;
10
+ exports.ledgerPolicyFromOutput = ledgerPolicyFromOutput;
11
+ exports.registerLedgerWallet = registerLedgerWallet;
12
+ exports.ledgerPolicyFromStandard = ledgerPolicyFromStandard;
13
+ exports.comparePolicies = comparePolicies;
14
+ exports.ledgerPolicyFromState = ledgerPolicyFromState;
6
15
  /*
7
16
  * Notes on Ledger implementation:
8
17
  *
@@ -73,7 +82,6 @@ async function importAndValidateLedgerBitcoin(ledgerClient) {
73
82
  }
74
83
  return ledgerBitcoinModule;
75
84
  }
76
- exports.importAndValidateLedgerBitcoin = importAndValidateLedgerBitcoin;
77
85
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
78
86
  async function ledgerAppInfo(transport) {
79
87
  const r = await transport.send(0xb0, 0x01, 0x00, 0x00);
@@ -115,7 +123,6 @@ async function assertLedgerApp({ transport, name, minVersion }) {
115
123
  throw new Error(`Error: please upgrade ${name} to version ${minVersion}`);
116
124
  }
117
125
  }
118
- exports.assertLedgerApp = assertLedgerApp;
119
126
  function isLedgerStandard({ ledgerTemplate, keyRoots, network = bitcoinjs_lib_1.networks.bitcoin }) {
120
127
  if (keyRoots.length !== 1)
121
128
  return false;
@@ -136,7 +143,7 @@ function isLedgerStandard({ ledgerTemplate, keyRoots, network = bitcoinjs_lib_1.
136
143
  return true;
137
144
  return false;
138
145
  }
139
- /** @hidden */
146
+ /** @overload */
140
147
  async function getLedgerMasterFingerPrint({ ledgerClient, ledgerState, ledgerManager }) {
141
148
  if (ledgerManager && (ledgerClient || ledgerState))
142
149
  throw new Error(`ledgerClient and ledgerState have been deprecated`);
@@ -154,7 +161,6 @@ async function getLedgerMasterFingerPrint({ ledgerClient, ledgerState, ledgerMan
154
161
  }
155
162
  return masterFingerprint;
156
163
  }
157
- exports.getLedgerMasterFingerPrint = getLedgerMasterFingerPrint;
158
164
  /** @hidden */
159
165
  async function getLedgerXpub({ originPath, ledgerClient, ledgerState, ledgerManager }) {
160
166
  if (ledgerManager && (ledgerClient || ledgerState))
@@ -184,7 +190,6 @@ async function getLedgerXpub({ originPath, ledgerClient, ledgerState, ledgerMana
184
190
  }
185
191
  return xpub;
186
192
  }
187
- exports.getLedgerXpub = getLedgerXpub;
188
193
  /**
189
194
  * Checks whether there is a policy in ledgerState that the ledger
190
195
  * could use to sign this psbt input.
@@ -326,7 +331,6 @@ async function ledgerPolicyFromPsbtInput({ ledgerManager, psbt, index }) {
326
331
  }
327
332
  return;
328
333
  }
329
- exports.ledgerPolicyFromPsbtInput = ledgerPolicyFromPsbtInput;
330
334
  /**
331
335
  * Given an output, it extracts its descriptor and converts it to a Ledger
332
336
  * Wallet Policy, that is, its keyRoots and template.
@@ -414,11 +418,10 @@ async function ledgerPolicyFromOutput({ output, ledgerClient, ledgerState }) {
414
418
  });
415
419
  return { ledgerTemplate, keyRoots };
416
420
  }
417
- exports.ledgerPolicyFromOutput = ledgerPolicyFromOutput;
418
421
  /**
419
422
  * To be removed in v3.0 and replaced by a version that does not accept
420
423
  * descriptors
421
- * @hidden
424
+ * @overload
422
425
  **/
423
426
  async function registerLedgerWallet({ descriptor, ledgerClient, ledgerState, ledgerManager, policyName }) {
424
427
  if (typeof descriptor !== 'string' && ledgerManager)
@@ -487,7 +490,6 @@ async function registerLedgerWallet({ descriptor, ledgerClient, ledgerState, led
487
490
  ledgerState.policies.push(policy);
488
491
  }
489
492
  }
490
- exports.registerLedgerWallet = registerLedgerWallet;
491
493
  /**
492
494
  * Retrieve a standard ledger policy or null if it does correspond.
493
495
  **/
@@ -508,7 +510,6 @@ async function ledgerPolicyFromStandard({ output, ledgerClient, ledgerState }) {
508
510
  return { ledgerTemplate, keyRoots };
509
511
  return null;
510
512
  }
511
- exports.ledgerPolicyFromStandard = ledgerPolicyFromStandard;
512
513
  function compareKeyRoots(arr1, arr2) {
513
514
  if (arr1.length !== arr2.length) {
514
515
  return false;
@@ -524,7 +525,6 @@ function comparePolicies(policyA, policyB) {
524
525
  return (compareKeyRoots(policyA.keyRoots, policyB.keyRoots) &&
525
526
  policyA.ledgerTemplate === policyB.ledgerTemplate);
526
527
  }
527
- exports.comparePolicies = comparePolicies;
528
528
  /**
529
529
  * Retrieve a ledger policy from ledgerState or null if it does not exist yet.
530
530
  **/
@@ -550,4 +550,3 @@ async function ledgerPolicyFromState({ output, ledgerClient, ledgerState }) {
550
550
  return null;
551
551
  }
552
552
  }
553
- exports.ledgerPolicyFromState = ledgerPolicyFromState;
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import { Network } from 'bitcoinjs-lib';
4
2
  import type { ECPairAPI } from 'ecpair';
5
3
  import type { BIP32API } from 'bip32';
@@ -17,15 +17,28 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
17
17
  }) : function(o, v) {
18
18
  o["default"] = v;
19
19
  });
20
- var __importStar = (this && this.__importStar) || function (mod) {
21
- if (mod && mod.__esModule) return mod;
22
- var result = {};
23
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
24
- __setModuleDefault(result, mod);
25
- return result;
26
- };
20
+ var __importStar = (this && this.__importStar) || (function () {
21
+ var ownKeys = function(o) {
22
+ ownKeys = Object.getOwnPropertyNames || function (o) {
23
+ var ar = [];
24
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
25
+ return ar;
26
+ };
27
+ return ownKeys(o);
28
+ };
29
+ return function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
36
+ })();
27
37
  Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.numberEncodeAsm = exports.satisfyMiniscript = exports.miniscript2Script = exports.expandMiniscript = void 0;
38
+ exports.expandMiniscript = expandMiniscript;
39
+ exports.miniscript2Script = miniscript2Script;
40
+ exports.satisfyMiniscript = satisfyMiniscript;
41
+ exports.numberEncodeAsm = numberEncodeAsm;
29
42
  const bitcoinjs_lib_1 = require("bitcoinjs-lib");
30
43
  const keyExpressions_1 = require("./keyExpressions");
31
44
  const RE = __importStar(require("./re"));
@@ -72,7 +85,6 @@ function expandMiniscript({ miniscript, isSegwit, isTaproot, network = bitcoinjs
72
85
  }
73
86
  return { expandedMiniscript, expansionMap };
74
87
  }
75
- exports.expandMiniscript = expandMiniscript;
76
88
  /**
77
89
  * Particularize an expanded ASM expression using the variables in
78
90
  * expansionMap.
@@ -114,7 +126,6 @@ function miniscript2Script({ expandedMiniscript, expansionMap }) {
114
126
  }
115
127
  return bitcoinjs_lib_1.script.fromASM(substituteAsm({ expandedAsm: compiled.asm, expansionMap }));
116
128
  }
117
- exports.miniscript2Script = miniscript2Script;
118
129
  /**
119
130
  * Assumptions:
120
131
  * The attacker does not have access to any of the private keys of public keys
@@ -181,7 +192,6 @@ function satisfyMiniscript({ expandedMiniscript, expansionMap, signatures = [],
181
192
  nSequence: sat.nSequence
182
193
  };
183
194
  }
184
- exports.satisfyMiniscript = satisfyMiniscript;
185
195
  /**
186
196
  *
187
197
  * Use this function instead of bitcoinjs-lib's equivalent `script.number.encode`
@@ -246,4 +256,3 @@ function numberEncodeAsm(number) {
246
256
  else
247
257
  return bitcoinjs_lib_1.script.number.encode(number).toString('hex');
248
258
  }
249
- exports.numberEncodeAsm = numberEncodeAsm;
package/dist/psbt.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import type { PsbtInput } from 'bip174/src/lib/interfaces';
4
2
  import type { KeyInfo } from './types';
5
3
  import { Network, Psbt } from 'bitcoinjs-lib';
package/dist/psbt.js CHANGED
@@ -2,7 +2,8 @@
2
2
  // Copyright (c) 2025 Jose-Luis Landabaso - https://bitcoinerlab.com
3
3
  // Distributed under the MIT software license
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.updatePsbt = exports.finalScriptsFuncFactory = void 0;
5
+ exports.finalScriptsFuncFactory = finalScriptsFuncFactory;
6
+ exports.updatePsbt = updatePsbt;
6
7
  const bitcoinjs_lib_1 = require("bitcoinjs-lib");
7
8
  const varuint_bitcoin_1 = require("varuint-bitcoin");
8
9
  function reverseBuffer(buffer) {
@@ -82,7 +83,6 @@ function finalScriptsFuncFactory(scriptSatisfaction, network) {
82
83
  };
83
84
  return finalScriptsFunc;
84
85
  }
85
- exports.finalScriptsFuncFactory = finalScriptsFuncFactory;
86
86
  /**
87
87
  * Important: Read comments on descriptor.updatePsbt regarding not passing txHex
88
88
  */
@@ -207,4 +207,3 @@ function updatePsbt({ psbt, vout, txHex, txId, value, sequence, locktime, keysIn
207
207
  psbt.addInput(input);
208
208
  return psbt.data.inputs.length - 1;
209
209
  }
210
- exports.updatePsbt = updatePsbt;
package/dist/re.d.ts CHANGED
@@ -14,6 +14,8 @@ export declare const reXprvKey: string;
14
14
  export declare const reNonSegwitKeyExp: string;
15
15
  export declare const reSegwitKeyExp: string;
16
16
  export declare const reTaprootKeyExp: string;
17
+ export declare const reNonSegwitSortedMulti: string;
18
+ export declare const reSegwitSortedMulti: string;
17
19
  export declare const anchorStartAndEnd: (re: string) => string;
18
20
  export declare const rePkAnchored: string;
19
21
  export declare const reAddrAnchored: string;
@@ -21,6 +23,9 @@ export declare const rePkhAnchored: string;
21
23
  export declare const reWpkhAnchored: string;
22
24
  export declare const reShWpkhAnchored: string;
23
25
  export declare const reTrSingleKeyAnchored: string;
26
+ export declare const reShSortedMultiAnchored: string;
27
+ export declare const reWshSortedMultiAnchored: string;
28
+ export declare const reShWshSortedMultiAnchored: string;
24
29
  export declare const reShMiniscriptAnchored: string;
25
30
  export declare const reShWshMiniscriptAnchored: string;
26
31
  export declare const reWshMiniscriptAnchored: string;
package/dist/re.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // Copyright (c) 2025 Jose-Luis Landabaso - https://bitcoinerlab.com
3
3
  // Distributed under the MIT software license
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.reWshMiniscriptAnchored = exports.reShWshMiniscriptAnchored = exports.reShMiniscriptAnchored = exports.reTrSingleKeyAnchored = exports.reShWpkhAnchored = exports.reWpkhAnchored = exports.rePkhAnchored = exports.reAddrAnchored = exports.rePkAnchored = exports.anchorStartAndEnd = exports.reTaprootKeyExp = exports.reSegwitKeyExp = exports.reNonSegwitKeyExp = exports.reXprvKey = exports.reXpubKey = exports.rePath = exports.reXprv = exports.reXpub = exports.reWIF = exports.reTaprootPubKey = exports.reSegwitPubKey = exports.reNonSegwitPubKey = exports.reChecksum = exports.reOrigin = exports.reMasterFingerprint = exports.reOriginPath = void 0;
5
+ exports.reWshMiniscriptAnchored = exports.reShWshMiniscriptAnchored = exports.reShMiniscriptAnchored = exports.reShWshSortedMultiAnchored = exports.reWshSortedMultiAnchored = exports.reShSortedMultiAnchored = exports.reTrSingleKeyAnchored = exports.reShWpkhAnchored = exports.reWpkhAnchored = exports.rePkhAnchored = exports.reAddrAnchored = exports.rePkAnchored = exports.anchorStartAndEnd = exports.reSegwitSortedMulti = exports.reNonSegwitSortedMulti = exports.reTaprootKeyExp = exports.reSegwitKeyExp = exports.reNonSegwitKeyExp = exports.reXprvKey = exports.reXpubKey = exports.rePath = exports.reXprv = exports.reXpub = exports.reWIF = exports.reTaprootPubKey = exports.reSegwitPubKey = exports.reNonSegwitPubKey = exports.reChecksum = exports.reOrigin = exports.reMasterFingerprint = exports.reOriginPath = void 0;
6
6
  const checksum_1 = require("./checksum");
7
7
  //Regular expressions cheat sheet:
8
8
  //https://www.keycdn.com/support/regex-cheat-sheet
@@ -55,6 +55,8 @@ const rePkh = String.raw `pkh\(${exports.reNonSegwitKeyExp}\)`;
55
55
  const reWpkh = String.raw `wpkh\(${exports.reSegwitKeyExp}\)`;
56
56
  const reShWpkh = String.raw `sh\(wpkh\(${exports.reSegwitKeyExp}\)\)`;
57
57
  const reTrSingleKey = String.raw `tr\(${exports.reTaprootKeyExp}\)`; // TODO: tr(KEY,TREE) not yet supported. TrSingleKey used for tr(KEY)
58
+ exports.reNonSegwitSortedMulti = String.raw `sortedmulti\(((?:1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20)(?:,${exports.reNonSegwitKeyExp})+)\)`;
59
+ exports.reSegwitSortedMulti = String.raw `sortedmulti\(((?:1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20)(?:,${exports.reSegwitKeyExp})+)\)`;
58
60
  const reMiniscript = String.raw `(.*?)`; //Matches anything. We assert later in the code that miniscripts are valid and sane.
59
61
  //RegExp makers:
60
62
  const makeReSh = (re) => String.raw `sh\(${re}\)`;
@@ -69,6 +71,9 @@ exports.rePkhAnchored = (0, exports.anchorStartAndEnd)(composeChecksum(rePkh));
69
71
  exports.reWpkhAnchored = (0, exports.anchorStartAndEnd)(composeChecksum(reWpkh));
70
72
  exports.reShWpkhAnchored = (0, exports.anchorStartAndEnd)(composeChecksum(reShWpkh));
71
73
  exports.reTrSingleKeyAnchored = (0, exports.anchorStartAndEnd)(composeChecksum(reTrSingleKey));
74
+ exports.reShSortedMultiAnchored = (0, exports.anchorStartAndEnd)(composeChecksum(makeReSh(exports.reNonSegwitSortedMulti)));
75
+ exports.reWshSortedMultiAnchored = (0, exports.anchorStartAndEnd)(composeChecksum(makeReWsh(exports.reSegwitSortedMulti)));
76
+ exports.reShWshSortedMultiAnchored = (0, exports.anchorStartAndEnd)(composeChecksum(makeReShWsh(exports.reSegwitSortedMulti)));
72
77
  exports.reShMiniscriptAnchored = (0, exports.anchorStartAndEnd)(composeChecksum(makeReSh(reMiniscript)));
73
78
  exports.reShWshMiniscriptAnchored = (0, exports.anchorStartAndEnd)(composeChecksum(makeReShWsh(reMiniscript)));
74
79
  exports.reWshMiniscriptAnchored = (0, exports.anchorStartAndEnd)(composeChecksum(makeReWsh(reMiniscript)));
@@ -1,13 +1,14 @@
1
1
  import { Network } from 'bitcoinjs-lib';
2
2
  import type { LedgerState, LedgerManager } from './ledger';
3
3
  import type { BIP32Interface } from 'bip32';
4
+ /** @function */
4
5
  export declare const pkhBIP32: ({ masterNode, network, keyPath, account, change, index, isPublic }: {
5
6
  masterNode: BIP32Interface;
6
7
  /** @default networks.bitcoin */
7
8
  network?: Network;
8
9
  account: number;
9
10
  change?: number | undefined;
10
- index?: number | undefined | '*';
11
+ index?: number | undefined | "*";
11
12
  keyPath?: string;
12
13
  /**
13
14
  * Compute an xpub or xprv
@@ -15,13 +16,14 @@ export declare const pkhBIP32: ({ masterNode, network, keyPath, account, change,
15
16
  */
16
17
  isPublic?: boolean;
17
18
  }) => string;
19
+ /** @function */
18
20
  export declare const shWpkhBIP32: ({ masterNode, network, keyPath, account, change, index, isPublic }: {
19
21
  masterNode: BIP32Interface;
20
22
  /** @default networks.bitcoin */
21
23
  network?: Network;
22
24
  account: number;
23
25
  change?: number | undefined;
24
- index?: number | undefined | '*';
26
+ index?: number | undefined | "*";
25
27
  keyPath?: string;
26
28
  /**
27
29
  * Compute an xpub or xprv
@@ -29,13 +31,14 @@ export declare const shWpkhBIP32: ({ masterNode, network, keyPath, account, chan
29
31
  */
30
32
  isPublic?: boolean;
31
33
  }) => string;
34
+ /** @function */
32
35
  export declare const wpkhBIP32: ({ masterNode, network, keyPath, account, change, index, isPublic }: {
33
36
  masterNode: BIP32Interface;
34
37
  /** @default networks.bitcoin */
35
38
  network?: Network;
36
39
  account: number;
37
40
  change?: number | undefined;
38
- index?: number | undefined | '*';
41
+ index?: number | undefined | "*";
39
42
  keyPath?: string;
40
43
  /**
41
44
  * Compute an xpub or xprv
@@ -43,13 +46,14 @@ export declare const wpkhBIP32: ({ masterNode, network, keyPath, account, change
43
46
  */
44
47
  isPublic?: boolean;
45
48
  }) => string;
49
+ /** @function */
46
50
  export declare const trBIP32: ({ masterNode, network, keyPath, account, change, index, isPublic }: {
47
51
  masterNode: BIP32Interface;
48
52
  /** @default networks.bitcoin */
49
53
  network?: Network;
50
54
  account: number;
51
55
  change?: number | undefined;
52
- index?: number | undefined | '*';
56
+ index?: number | undefined | "*";
53
57
  keyPath?: string;
54
58
  /**
55
59
  * Compute an xpub or xprv
@@ -57,13 +61,14 @@ export declare const trBIP32: ({ masterNode, network, keyPath, account, change,
57
61
  */
58
62
  isPublic?: boolean;
59
63
  }) => string;
64
+ /** @function */
60
65
  export declare const pkhLedger: {
61
66
  ({ ledgerManager, account, keyPath, change, index }: {
62
67
  ledgerManager: LedgerManager;
63
68
  account: number;
64
69
  keyPath?: string;
65
70
  change?: number | undefined;
66
- index?: number | undefined | '*';
71
+ index?: number | undefined | "*";
67
72
  }): Promise<string>;
68
73
  ({ ledgerClient, ledgerState, network, account, keyPath, change, index }: {
69
74
  ledgerClient: unknown;
@@ -73,16 +78,17 @@ export declare const pkhLedger: {
73
78
  account: number;
74
79
  keyPath?: string;
75
80
  change?: number | undefined;
76
- index?: number | undefined | '*';
81
+ index?: number | undefined | "*";
77
82
  }): Promise<string>;
78
83
  };
84
+ /** @function */
79
85
  export declare const shWpkhLedger: {
80
86
  ({ ledgerManager, account, keyPath, change, index }: {
81
87
  ledgerManager: LedgerManager;
82
88
  account: number;
83
89
  keyPath?: string;
84
90
  change?: number | undefined;
85
- index?: number | undefined | '*';
91
+ index?: number | undefined | "*";
86
92
  }): Promise<string>;
87
93
  ({ ledgerClient, ledgerState, network, account, keyPath, change, index }: {
88
94
  ledgerClient: unknown;
@@ -92,16 +98,17 @@ export declare const shWpkhLedger: {
92
98
  account: number;
93
99
  keyPath?: string;
94
100
  change?: number | undefined;
95
- index?: number | undefined | '*';
101
+ index?: number | undefined | "*";
96
102
  }): Promise<string>;
97
103
  };
104
+ /** @function */
98
105
  export declare const wpkhLedger: {
99
106
  ({ ledgerManager, account, keyPath, change, index }: {
100
107
  ledgerManager: LedgerManager;
101
108
  account: number;
102
109
  keyPath?: string;
103
110
  change?: number | undefined;
104
- index?: number | undefined | '*';
111
+ index?: number | undefined | "*";
105
112
  }): Promise<string>;
106
113
  ({ ledgerClient, ledgerState, network, account, keyPath, change, index }: {
107
114
  ledgerClient: unknown;
@@ -111,16 +118,17 @@ export declare const wpkhLedger: {
111
118
  account: number;
112
119
  keyPath?: string;
113
120
  change?: number | undefined;
114
- index?: number | undefined | '*';
121
+ index?: number | undefined | "*";
115
122
  }): Promise<string>;
116
123
  };
124
+ /** @function */
117
125
  export declare const trLedger: {
118
126
  ({ ledgerManager, account, keyPath, change, index }: {
119
127
  ledgerManager: LedgerManager;
120
128
  account: number;
121
129
  keyPath?: string;
122
130
  change?: number | undefined;
123
- index?: number | undefined | '*';
131
+ index?: number | undefined | "*";
124
132
  }): Promise<string>;
125
133
  ({ ledgerClient, ledgerState, network, account, keyPath, change, index }: {
126
134
  ledgerClient: unknown;
@@ -130,6 +138,6 @@ export declare const trLedger: {
130
138
  account: number;
131
139
  keyPath?: string;
132
140
  change?: number | undefined;
133
- index?: number | undefined | '*';
141
+ index?: number | undefined | "*";
134
142
  }): Promise<string>;
135
143
  };
@@ -40,12 +40,16 @@ function standardExpressionsBIP32Maker(purpose, scriptTemplate) {
40
40
  }
41
41
  return standardScriptExpressionBIP32;
42
42
  }
43
+ /** @function */
43
44
  exports.pkhBIP32 = standardExpressionsBIP32Maker(44, 'pkh(KEYEXPRESSION)');
45
+ /** @function */
44
46
  exports.shWpkhBIP32 = standardExpressionsBIP32Maker(49, 'sh(wpkh(KEYEXPRESSION))');
47
+ /** @function */
45
48
  exports.wpkhBIP32 = standardExpressionsBIP32Maker(84, 'wpkh(KEYEXPRESSION)');
49
+ /** @function */
46
50
  exports.trBIP32 = standardExpressionsBIP32Maker(86, 'tr(KEYEXPRESSION)');
47
51
  function standardExpressionsLedgerMaker(purpose, scriptTemplate) {
48
- /** @hidden */
52
+ /** @overload */
49
53
  async function standardScriptExpressionLedger({ ledgerClient, ledgerState, ledgerManager, network, account, keyPath, change, index }) {
50
54
  if (ledgerManager && (ledgerClient || ledgerState))
51
55
  throw new Error(`ledgerClient and ledgerState have been deprecated`);
@@ -72,7 +76,11 @@ function standardExpressionsLedgerMaker(purpose, scriptTemplate) {
72
76
  }
73
77
  return standardScriptExpressionLedger;
74
78
  }
79
+ /** @function */
75
80
  exports.pkhLedger = standardExpressionsLedgerMaker(44, 'pkh(KEYEXPRESSION)');
81
+ /** @function */
76
82
  exports.shWpkhLedger = standardExpressionsLedgerMaker(49, 'sh(wpkh(KEYEXPRESSION))');
83
+ /** @function */
77
84
  exports.wpkhLedger = standardExpressionsLedgerMaker(84, 'wpkh(KEYEXPRESSION)');
85
+ /** @function */
78
86
  exports.trLedger = standardExpressionsLedgerMaker(86, 'tr(KEYEXPRESSION)');
package/dist/signers.d.ts CHANGED
@@ -70,7 +70,6 @@ export declare function signInputLedger({ psbt, index, ledgerManager }: {
70
70
  ledgerManager: LedgerManager;
71
71
  }): Promise<void>;
72
72
  /**
73
- * @deprecated
74
73
  * @hidden
75
74
  */
76
75
  export declare function signInputLedger({ psbt, index, descriptor, ledgerClient, ledgerState }: {
@@ -95,7 +94,6 @@ export declare function signLedger({ psbt, ledgerManager }: {
95
94
  ledgerManager: LedgerManager;
96
95
  }): Promise<void>;
97
96
  /**
98
- * @deprecated
99
97
  * @hidden
100
98
  */
101
99
  export declare function signLedger({ psbt, descriptors, ledgerClient, ledgerState }: {
package/dist/signers.js CHANGED
@@ -2,7 +2,12 @@
2
2
  // Copyright (c) 2025 Jose-Luis Landabaso - https://bitcoinerlab.com
3
3
  // Distributed under the MIT software license
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.signLedger = exports.signInputLedger = exports.signBIP32 = exports.signInputBIP32 = exports.signECPair = exports.signInputECPair = void 0;
5
+ exports.signInputECPair = signInputECPair;
6
+ exports.signECPair = signECPair;
7
+ exports.signInputBIP32 = signInputBIP32;
8
+ exports.signBIP32 = signBIP32;
9
+ exports.signInputLedger = signInputLedger;
10
+ exports.signLedger = signLedger;
6
11
  const bip371_1 = require("bitcoinjs-lib/src/psbt/bip371");
7
12
  const bip341_1 = require("bitcoinjs-lib/src/payments/bip341");
8
13
  const ledger_1 = require("./ledger");
@@ -42,7 +47,6 @@ function signInputECPair({ psbt, index, ecpair }) {
42
47
  else
43
48
  psbt.signInput(index, ecpair);
44
49
  }
45
- exports.signInputECPair = signInputECPair;
46
50
  /**
47
51
  * Signs all inputs of a PSBT with an ECPair.
48
52
  *
@@ -82,17 +86,14 @@ function signECPair({ psbt, ecpair }) {
82
86
  throw new Error('No inputs were signed');
83
87
  }
84
88
  }
85
- exports.signECPair = signECPair;
86
89
  function signInputBIP32({ psbt, index, node }) {
87
90
  (0, applyPR2137_1.applyPR2137)(psbt);
88
91
  psbt.signInputHD(index, node);
89
92
  }
90
- exports.signInputBIP32 = signInputBIP32;
91
93
  function signBIP32({ psbt, masterNode }) {
92
94
  (0, applyPR2137_1.applyPR2137)(psbt);
93
95
  psbt.signAllInputsHD(masterNode);
94
96
  }
95
- exports.signBIP32 = signBIP32;
96
97
  const ledgerSignaturesForInputIndex = (index, ledgerSignatures) => ledgerSignatures
97
98
  .filter(([i]) => i === index)
98
99
  .map(([_i, partialSignature]) => ({
@@ -102,7 +103,7 @@ const ledgerSignaturesForInputIndex = (index, ledgerSignatures) => ledgerSignatu
102
103
  /**
103
104
  * To be removed in v3.0 and replaced by a version that does not accept
104
105
  * descriptor
105
- * @hidden
106
+ * @overload
106
107
  */
107
108
  async function signInputLedger({ psbt, index, descriptor, ledgerClient, ledgerState, ledgerManager }) {
108
109
  if (!descriptor && !ledgerManager)
@@ -178,11 +179,10 @@ async function signInputLedger({ psbt, index, descriptor, ledgerClient, ledgerSt
178
179
  partialSig: ledgerSignaturesForInputIndex(index, ledgerSignatures)
179
180
  });
180
181
  }
181
- exports.signInputLedger = signInputLedger;
182
182
  /**
183
183
  * To be removed in v3.0 and replaced by a version that does not accept
184
184
  * descriptors
185
- * @hidden
185
+ * @overload
186
186
  */
187
187
  async function signLedger({ psbt, descriptors, ledgerClient, ledgerState, ledgerManager }) {
188
188
  if (!descriptors && !ledgerManager)
@@ -252,4 +252,3 @@ async function signLedger({ psbt, descriptors, ledgerClient, ledgerState, ledger
252
252
  }
253
253
  }
254
254
  }
255
- exports.signLedger = signLedger;
package/dist/types.d.ts CHANGED
@@ -1,12 +1,9 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import type { ECPairInterface } from 'ecpair';
4
2
  import type { BIP32Interface } from 'bip32';
5
3
  import type { Payment, Network } from 'bitcoinjs-lib';
6
4
  /**
7
5
  * Preimage
8
- * @alias Preimage
9
- * @memberof Descriptor
6
+ * See {@link Output}
10
7
  */
11
8
  export type Preimage = {
12
9
  /**
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@bitcoinerlab/descriptors",
3
3
  "description": "This library parses and creates Bitcoin Miniscript Descriptors and generates Partially Signed Bitcoin Transactions (PSBTs). It provides PSBT finalizers and signers for single-signature, BIP32 and Hardware Wallets.",
4
4
  "homepage": "https://github.com/bitcoinerlab/descriptors",
5
- "version": "2.3.3",
5
+ "version": "2.3.5",
6
6
  "author": "Jose-Luis Landabaso",
7
7
  "license": "MIT",
8
8
  "repository": {
@@ -34,15 +34,15 @@
34
34
  "build:fixtures": "node test/tools/generateBitcoinCoreFixtures.js -i test/fixtures/descriptor_tests.cpp | npx prettier --parser typescript > test/fixtures/bitcoinCore.ts",
35
35
  "build:test": "npm run build:fixtures && tsc --project ./node_modules/@bitcoinerlab/configs/tsconfig.test.json --resolveJsonModule",
36
36
  "build": "npm run build:src && npm run build:test",
37
- "lint": "if [ \"$ESLINT_USE_FLAT_CONFIG\" != false ]; then echo '\n⚠️ WARNING: ESLINT_USE_FLAT_CONFIG is not set to \"false\".\n Editors may show different results than the CLI linter.\n To fix permanently, add this to your ~/.bashrc or ~/.zshrc:\n\n export ESLINT_USE_FLAT_CONFIG=false\n'; fi; ESLINT_USE_FLAT_CONFIG=false eslint --ignore-path .gitignore --ext .ts src/ test/",
37
+ "lint": "./node_modules/@bitcoinerlab/configs/scripts/lint.sh",
38
38
  "ensureTester": "./node_modules/@bitcoinerlab/configs/scripts/ensureTester.sh",
39
- "test:integration:soft": "npm run ensureTester && node test/integration/standardOutputs.js && echo \"\\n\\n\" && node test/integration/miniscript.js",
39
+ "test:integration:soft": "npm run ensureTester && node test/integration/standardOutputs.js && echo \"\n\n\" && node test/integration/miniscript.js && echo \"\n\n\" && node test/integration/sortedmulti.js",
40
40
  "test:integration:ledger": "npm run ensureTester && node test/integration/ledger.js",
41
- "test:integration:deprecated": "npm run ensureTester && node test/integration/standardOutputs-deprecated.js && echo \"\\n\\n\" && node test/integration/miniscript-deprecated.js && echo \"\\n\\n\" && node test/integration/ledger-deprecated.js",
41
+ "test:integration:deprecated": "npm run ensureTester && node test/integration/standardOutputs-deprecated.js && echo \"\n\n\" && node test/integration/miniscript-deprecated.js && echo \"\n\n\" && node test/integration/ledger-deprecated.js",
42
42
  "test:unit": "jest",
43
43
  "test": "npm run lint && npm run build && npm run test:unit && npm run test:integration:soft",
44
44
  "testledger": "npm run lint && npm run build && npm run test:integration:ledger",
45
- "prepublishOnly": "npm run test && echo \"\\n\\n\" && npm run test:integration:deprecated && npm run test:integration:ledger"
45
+ "prepublishOnly": "npm run test && echo \"\n\n\" && npm run test:integration:deprecated && npm run test:integration:ledger"
46
46
  },
47
47
  "files": [
48
48
  "dist"
@@ -56,21 +56,21 @@
56
56
  }
57
57
  },
58
58
  "devDependencies": {
59
+ "@bitcoinerlab/configs": "^2.0.0",
59
60
  "@ledgerhq/hw-transport-node-hid": "^6.27.12",
60
61
  "@types/lodash.memoize": "^4.1.9",
61
62
  "bip39": "^3.0.4",
62
63
  "bip65": "^1.0.3",
63
64
  "bip68": "^1.0.4",
64
65
  "ledger-bitcoin": "^0.2.2",
65
- "regtest-client": "^0.2.0",
66
+ "regtest-client": "^0.2.1",
66
67
  "yargs": "^17.7.2"
67
68
  },
68
69
  "dependencies": {
69
- "@bitcoinerlab/configs": "^1.3.0",
70
- "@bitcoinerlab/miniscript": "^1.4.0",
70
+ "@bitcoinerlab/miniscript": "^1.4.3",
71
71
  "@bitcoinerlab/secp256k1": "^1.2.0",
72
72
  "bip32": "^4.0.0",
73
- "bitcoinjs-lib": "^6.1.3",
73
+ "bitcoinjs-lib": "^6.1.7",
74
74
  "ecpair": "^2.1.0",
75
75
  "lodash.memoize": "^4.1.2",
76
76
  "varuint-bitcoin": "^1.1.2"