@bitcoinerlab/descriptors 2.3.0 → 2.3.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.
@@ -111,6 +111,7 @@ const applyPR2137 = (psbt) => {
111
111
  results.push(true);
112
112
  }
113
113
  catch (err) {
114
+ void err;
114
115
  results.push(false);
115
116
  }
116
117
  }
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { Network, Payment, Psbt } from 'bitcoinjs-lib';
3
4
  import type { PartialSig } from 'bip174/src/lib/interfaces';
4
5
  import { BIP32API } from 'bip32';
@@ -221,6 +221,7 @@ function DescriptorsFactory(ecc) {
221
221
  output = bitcoinjs_lib_1.address.toOutputScript(matchedAddress, network);
222
222
  }
223
223
  catch (e) {
224
+ void e;
224
225
  throw new Error(`Error: invalid address ${matchedAddress}`);
225
226
  }
226
227
  try {
@@ -228,32 +229,42 @@ function DescriptorsFactory(ecc) {
228
229
  isSegwit = false;
229
230
  isTaproot = false;
230
231
  }
231
- catch (e) { }
232
+ catch (e) {
233
+ void e;
234
+ }
232
235
  try {
233
236
  payment = p2sh({ output, network });
234
237
  // It assumes that an addr(SH_ADDRESS) is always a add(SH_WPKH) address
235
238
  isSegwit = true;
236
239
  isTaproot = false;
237
240
  }
238
- catch (e) { }
241
+ catch (e) {
242
+ void e;
243
+ }
239
244
  try {
240
245
  payment = p2wpkh({ output, network });
241
246
  isSegwit = true;
242
247
  isTaproot = false;
243
248
  }
244
- catch (e) { }
249
+ catch (e) {
250
+ void e;
251
+ }
245
252
  try {
246
253
  payment = p2wsh({ output, network });
247
254
  isSegwit = true;
248
255
  isTaproot = false;
249
256
  }
250
- catch (e) { }
257
+ catch (e) {
258
+ void e;
259
+ }
251
260
  try {
252
261
  payment = p2tr({ output, network });
253
262
  isSegwit = true;
254
263
  isTaproot = true;
255
264
  }
256
- catch (e) { }
265
+ catch (e) {
266
+ void e;
267
+ }
257
268
  if (!payment) {
258
269
  throw new Error(`Error: invalid address ${matchedAddress}`);
259
270
  }
@@ -489,7 +500,7 @@ function DescriptorsFactory(ecc) {
489
500
  return (0, miniscript_1.expandMiniscript)({
490
501
  miniscript,
491
502
  isSegwit,
492
- isTaproot: false,
503
+ isTaproot: false, //TODO:
493
504
  network,
494
505
  BIP32,
495
506
  ECPair
@@ -758,6 +769,7 @@ function DescriptorsFactory(ecc) {
758
769
  return true;
759
770
  }
760
771
  catch (err) {
772
+ void err;
761
773
  return false;
762
774
  }
763
775
  }
@@ -767,6 +779,7 @@ function DescriptorsFactory(ecc) {
767
779
  return true;
768
780
  }
769
781
  catch (err) {
782
+ void err;
770
783
  return false;
771
784
  }
772
785
  }
@@ -776,6 +789,7 @@ function DescriptorsFactory(ecc) {
776
789
  return true;
777
790
  }
778
791
  catch (err) {
792
+ void err;
779
793
  return false;
780
794
  }
781
795
  }
@@ -785,6 +799,7 @@ function DescriptorsFactory(ecc) {
785
799
  return true;
786
800
  }
787
801
  catch (err) {
802
+ void err;
788
803
  return false;
789
804
  }
790
805
  }
@@ -794,6 +809,7 @@ function DescriptorsFactory(ecc) {
794
809
  return true;
795
810
  }
796
811
  catch (err) {
812
+ void err;
797
813
  return false;
798
814
  }
799
815
  }
@@ -848,13 +864,14 @@ function DescriptorsFactory(ecc) {
848
864
  signatures) {
849
865
  if (this.isSegwit() && !isSegwitTx)
850
866
  throw new Error(`a tx is segwit if at least one input is segwit`);
851
- const errorMsg = 'Input type not implemented. Currently supported: pkh(KEY), wpkh(KEY), tr(KEY), \
852
- sh(wpkh(KEY)), sh(wsh(MINISCRIPT)), sh(MINISCRIPT), wsh(MINISCRIPT), \
853
- addr(PKH_ADDRESS), addr(WPKH_ADDRESS), addr(SH_WPKH_ADDRESS), addr(SINGLE_KEY_ADDRESS).';
854
867
  //expand any miniscript-based descriptor. If not miniscript-based, then it's
855
868
  //an addr() descriptor. For those, we can only guess their type.
856
869
  const expansion = this.expand().expandedExpression;
857
870
  const { isPKH, isWPKH, isSH, isTR } = this.guessOutput();
871
+ const errorMsg = `Input type not implemented. Currently supported: pkh(KEY), wpkh(KEY), tr(KEY), \
872
+ sh(wpkh(KEY)), sh(wsh(MINISCRIPT)), sh(MINISCRIPT), wsh(MINISCRIPT), \
873
+ addr(PKH_ADDRESS), addr(WPKH_ADDRESS), addr(SH_WPKH_ADDRESS), addr(SINGLE_KEY_ADDRESS). \
874
+ expansion=${expansion}, isPKH=${isPKH}, isWPKH=${isWPKH}, isSH=${isSH}, isTR=${isTR}.`;
858
875
  if (!expansion && !isPKH && !isWPKH && !isSH && !isTR)
859
876
  throw new Error(errorMsg);
860
877
  const firstSignature = signatures && typeof signatures[0] === 'object'
@@ -967,32 +984,27 @@ addr(PKH_ADDRESS), addr(WPKH_ADDRESS), addr(SH_WPKH_ADDRESS), addr(SINGLE_KEY_AD
967
984
  * output in a tx.
968
985
  */
969
986
  outputWeight() {
970
- const errorMsg = 'Output type not implemented. Currently supported: pkh(KEY), wpkh(KEY), tr(ANYTHING), \
971
- sh(ANYTHING), wsh(ANYTHING), addr(PKH_ADDRESS), addr(WPKH_ADDRESS), \
972
- addr(SH_WPKH_ADDRESS), addr(TR_ADDRESS)';
973
987
  //expand any miniscript-based descriptor. If not miniscript-based, then it's
974
988
  //an addr() descriptor. For those, we can only guess their type.
975
- const expansion = this.expand().expandedExpression;
976
989
  const { isPKH, isWPKH, isSH, isWSH, isTR } = this.guessOutput();
977
- if (!expansion && !isPKH && !isWPKH && !isSH && !isTR)
978
- throw new Error(errorMsg);
979
- if (expansion ? expansion.startsWith('pkh(') : isPKH) {
990
+ const errorMsg = `Output type not implemented. Currently supported: pkh=${isPKH}, wpkh=${isWPKH}, tr=${isTR}, sh=${isSH} and wsh=${isWSH}.`;
991
+ if (isPKH) {
980
992
  // (p2pkh:26) + (amount:8)
981
993
  return 34 * 4;
982
994
  }
983
- else if (expansion ? expansion.startsWith('wpkh(') : isWPKH) {
995
+ else if (isWPKH) {
984
996
  // (p2wpkh:23) + (amount:8)
985
997
  return 31 * 4;
986
998
  }
987
- else if (expansion ? expansion.startsWith('sh(') : isSH) {
999
+ else if (isSH) {
988
1000
  // (p2sh:24) + (amount:8)
989
1001
  return 32 * 4;
990
1002
  }
991
- else if (expansion ? expansion.startsWith('wsh(') : isWSH) {
1003
+ else if (isWSH) {
992
1004
  // (p2wsh:35) + (amount:8)
993
1005
  return 43 * 4;
994
1006
  }
995
- else if (expansion ? expansion.startsWith('tr(') : isTR) {
1007
+ else if (isTR) {
996
1008
  // (script_pubKey_length:1) + (p2t2(OP_1 OP_PUSH32 <schnorr_public_key>):34) + (amount:8)
997
1009
  return 43 * 4;
998
1010
  }
package/dist/ledger.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { DescriptorInstance, OutputInstance } from './descriptors';
3
4
  import { Network, Psbt } from 'bitcoinjs-lib';
4
5
  import type { TinySecp256k1Interface } from './types';
package/dist/ledger.js CHANGED
@@ -60,9 +60,11 @@ async function importAndValidateLedgerBitcoin(ledgerClient) {
60
60
  // to require 'ledger-bitcoin' unconditionally, leading to potential errors if
61
61
  // 'ledger-bitcoin' is not installed (given it's an optional peerDependency).
62
62
  // To bypass this, we directly use require:
63
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
63
64
  ledgerBitcoinModule = require('ledger-bitcoin');
64
65
  }
65
66
  catch (error) {
67
+ void error;
66
68
  throw new Error('Could not import "ledger-bitcoin". This is a peer dependency and needs to be installed explicitly. Please run "npm install ledger-bitcoin" to use Ledger Hardware Wallet functionality.');
67
69
  }
68
70
  const { AppClient } = ledgerBitcoinModule;
@@ -173,6 +175,7 @@ async function getLedgerXpub({ originPath, ledgerClient, ledgerState, ledgerMana
173
175
  xpub = await ledgerClient.getExtendedPubkey(`m${originPath}`, false);
174
176
  }
175
177
  catch (err) {
178
+ void err;
176
179
  xpub = await ledgerClient.getExtendedPubkey(`m${originPath}`, true);
177
180
  }
178
181
  if (typeof xpub !== 'string')
@@ -438,7 +441,7 @@ async function registerLedgerWallet({ descriptor, ledgerClient, ledgerState, led
438
441
  const { Output } = (0, descriptors_1.DescriptorsFactory)(ledgerManager.ecc);
439
442
  output = new Output({
440
443
  descriptor,
441
- ...(descriptor.includes('*') ? { index: 0 } : {}),
444
+ ...(descriptor.includes('*') ? { index: 0 } : {}), //if ranged set any index
442
445
  network: ledgerManager.network
443
446
  });
444
447
  }
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { Network } from 'bitcoinjs-lib';
3
4
  import type { ECPairAPI } from 'ecpair';
4
5
  import type { BIP32API } from 'bip32';
package/dist/psbt.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import type { PsbtInput } from 'bip174/src/lib/interfaces';
3
4
  import type { KeyInfo } from './types';
4
5
  import { Network, Psbt } from 'bitcoinjs-lib';
package/dist/signers.js CHANGED
@@ -74,6 +74,7 @@ function signECPair({ psbt, ecpair }) {
74
74
  results.push(true);
75
75
  }
76
76
  catch (err) {
77
+ void err;
77
78
  results.push(false);
78
79
  }
79
80
  }
package/dist/types.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import type { ECPairInterface } from 'ecpair';
3
4
  import type { BIP32Interface } from 'bip32';
4
5
  import type { Payment, Network } from 'bitcoinjs-lib';
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.0",
5
+ "version": "2.3.2",
6
6
  "author": "Jose-Luis Landabaso",
7
7
  "license": "MIT",
8
8
  "repository": {
@@ -34,7 +34,7 @@
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": "eslint --ignore-path .gitignore --ext .ts src/ 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/",
38
38
  "ensureTester": "./node_modules/@bitcoinerlab/configs/scripts/ensureTester.sh",
39
39
  "test:integration:soft": "npm run ensureTester && node test/integration/standardOutputs.js && echo \"\\n\\n\" && node test/integration/miniscript.js",
40
40
  "test:integration:ledger": "npm run ensureTester && node test/integration/ledger.js",
@@ -56,7 +56,6 @@
56
56
  }
57
57
  },
58
58
  "devDependencies": {
59
- "@bitcoinerlab/configs": "github:bitcoinerlab/configs",
60
59
  "@ledgerhq/hw-transport-node-hid": "^6.27.12",
61
60
  "@types/lodash.memoize": "^4.1.9",
62
61
  "bip39": "^3.0.4",
@@ -67,6 +66,7 @@
67
66
  "yargs": "^17.7.2"
68
67
  },
69
68
  "dependencies": {
69
+ "@bitcoinerlab/configs": "^1.3.0",
70
70
  "@bitcoinerlab/miniscript": "^1.4.0",
71
71
  "@bitcoinerlab/secp256k1": "^1.2.0",
72
72
  "bip32": "^4.0.0",