@bitcoinerlab/descriptors 2.0.0 → 2.0.2

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.
@@ -66,6 +66,23 @@ export declare function DescriptorsFactory(ecc: TinySecp256k1Interface): {
66
66
  * satisfyMiniscript verifies that the time constraints did not change.
67
67
  */
68
68
  "__#1@#getTimeConstraints"(): TimeConstraints | undefined;
69
+ /**
70
+ * Retrieves the byte length of the script satisfaction for a Miniscript-based
71
+ * descriptor, using only the expression, signers' public keys, and preimages
72
+ * provided in the constructor.
73
+ *
74
+ * Useful in scenarios like coin selection algorithms for transaction creation,
75
+ * where signatures are not yet available. Since signatures are still to be
76
+ * computed, the function assigns a standard length of 72 bytes for each
77
+ * signature. However, note that this may not always be completely accurate,
78
+ * as approximately 50% of signatures are 71 bytes in length
79
+ * (source: https://transactionfee.info/charts/bitcoin-script-ecdsa-length/).
80
+ * The function returns the byte length for a worst-case scenario.
81
+ *
82
+ * @returns The byte length of the compiled script satisfaction, or `undefined`
83
+ * if this was not a miniscript-based descriptor.
84
+ */
85
+ getScriptSatisfactionSize(): number | undefined;
69
86
  /**
70
87
  * Creates and returns an instance of bitcoinjs-lib
71
88
  * [`Payment`](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/ts_src/payments/index.ts)'s interface with the `scriptPubKey` of this `Output`.
@@ -304,6 +321,23 @@ export declare function DescriptorsFactory(ecc: TinySecp256k1Interface): {
304
321
  * satisfyMiniscript verifies that the time constraints did not change.
305
322
  */
306
323
  "__#1@#getTimeConstraints"(): TimeConstraints | undefined;
324
+ /**
325
+ * Retrieves the byte length of the script satisfaction for a Miniscript-based
326
+ * descriptor, using only the expression, signers' public keys, and preimages
327
+ * provided in the constructor.
328
+ *
329
+ * Useful in scenarios like coin selection algorithms for transaction creation,
330
+ * where signatures are not yet available. Since signatures are still to be
331
+ * computed, the function assigns a standard length of 72 bytes for each
332
+ * signature. However, note that this may not always be completely accurate,
333
+ * as approximately 50% of signatures are 71 bytes in length
334
+ * (source: https://transactionfee.info/charts/bitcoin-script-ecdsa-length/).
335
+ * The function returns the byte length for a worst-case scenario.
336
+ *
337
+ * @returns The byte length of the compiled script satisfaction, or `undefined`
338
+ * if this was not a miniscript-based descriptor.
339
+ */
340
+ getScriptSatisfactionSize(): number | undefined;
307
341
  /**
308
342
  * Creates and returns an instance of bitcoinjs-lib
309
343
  * [`Payment`](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/ts_src/payments/index.ts)'s interface with the `scriptPubKey` of this `Output`.
@@ -481,6 +481,49 @@ function DescriptorsFactory(ecc) {
481
481
  }
482
482
  }
483
483
  }
484
+ /**
485
+ * Retrieves the byte length of the script satisfaction for a Miniscript-based
486
+ * descriptor, using only the expression, signers' public keys, and preimages
487
+ * provided in the constructor.
488
+ *
489
+ * Useful in scenarios like coin selection algorithms for transaction creation,
490
+ * where signatures are not yet available. Since signatures are still to be
491
+ * computed, the function assigns a standard length of 72 bytes for each
492
+ * signature. However, note that this may not always be completely accurate,
493
+ * as approximately 50% of signatures are 71 bytes in length
494
+ * (source: https://transactionfee.info/charts/bitcoin-script-ecdsa-length/).
495
+ * The function returns the byte length for a worst-case scenario.
496
+ *
497
+ * @returns The byte length of the compiled script satisfaction, or `undefined`
498
+ * if this was not a miniscript-based descriptor.
499
+ */
500
+ getScriptSatisfactionSize() {
501
+ const miniscript = __classPrivateFieldGet(this, _Output_miniscript, "f");
502
+ const preimages = __classPrivateFieldGet(this, _Output_preimages, "f");
503
+ const expandedMiniscript = __classPrivateFieldGet(this, _Output_expandedMiniscript, "f");
504
+ const expansionMap = __classPrivateFieldGet(this, _Output_expansionMap, "f");
505
+ const signersPubKeys = __classPrivateFieldGet(this, _Output_signersPubKeys, "f");
506
+ //Create a method. solvePreimages to solve them.
507
+ if (miniscript) {
508
+ if (expandedMiniscript === undefined || expansionMap === undefined)
509
+ throw new Error(`Error: cannot get script satisfactions from not expanded miniscript ${miniscript}`);
510
+ //We create some fakeSignatures since we may not have them yet.
511
+ const fakeSignatures = signersPubKeys.map(pubkey => ({
512
+ pubkey,
513
+ // https://transactionfee.info/charts/bitcoin-script-ecdsa-length/
514
+ signature: Buffer.alloc(72, 0)
515
+ }));
516
+ const { scriptSatisfaction } = (0, miniscript_1.satisfyMiniscript)({
517
+ expandedMiniscript,
518
+ expansionMap,
519
+ signatures: fakeSignatures,
520
+ preimages
521
+ });
522
+ return scriptSatisfaction.length;
523
+ }
524
+ else
525
+ return undefined;
526
+ }
484
527
  /**
485
528
  * Creates and returns an instance of bitcoinjs-lib
486
529
  * [`Payment`](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/ts_src/payments/index.ts)'s interface with the `scriptPubKey` of this `Output`.
@@ -750,7 +793,8 @@ function DescriptorsFactory(ecc) {
750
793
  //signatures don't matter
751
794
  const fakeSignatures = signersPubKeys.map(pubkey => ({
752
795
  pubkey,
753
- signature: Buffer.alloc(64, 0)
796
+ // https://transactionfee.info/charts/bitcoin-script-ecdsa-length/
797
+ signature: Buffer.alloc(72, 0)
754
798
  }));
755
799
  const { nLockTime, nSequence } = (0, miniscript_1.satisfyMiniscript)({
756
800
  expandedMiniscript,
@@ -45,11 +45,13 @@ exports.shWpkhBIP32 = standardExpressionsBIP32Maker(49, 'sh(wpkh(KEYEXPRESSION))
45
45
  exports.wpkhBIP32 = standardExpressionsBIP32Maker(84, 'wpkh(KEYEXPRESSION)');
46
46
  function standardExpressionsLedgerMaker(purpose, scriptTemplate) {
47
47
  /** @hidden */
48
- async function standardScriptExpressionLedger({ ledgerClient, ledgerState, ledgerManager, network = bitcoinjs_lib_1.networks.bitcoin, account, keyPath, change, index }) {
48
+ async function standardScriptExpressionLedger({ ledgerClient, ledgerState, ledgerManager, network, account, keyPath, change, index }) {
49
49
  if (ledgerManager && (ledgerClient || ledgerState))
50
50
  throw new Error(`ledgerClient and ledgerState have been deprecated`);
51
51
  if (ledgerManager && network)
52
52
  throw new Error(`ledgerManager already includes the network object`);
53
+ if (!ledgerManager && !network)
54
+ network = bitcoinjs_lib_1.networks.bitcoin;
53
55
  if (ledgerManager)
54
56
  ({ ledgerClient, ledgerState, network } = ledgerManager);
55
57
  if (!ledgerClient || !ledgerState)
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.0.0",
5
+ "version": "2.0.2",
6
6
  "author": "Jose-Luis Landabaso",
7
7
  "license": "MIT",
8
8
  "repository": {