@btc-vision/bitcoin 6.3.6 → 6.4.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 (71) hide show
  1. package/.mocharc.json +13 -0
  2. package/browser/address.d.ts +1 -1
  3. package/browser/index.js +1 -1
  4. package/browser/index.js.LICENSE.txt +3 -3
  5. package/browser/networks.d.ts +1 -0
  6. package/build/address.d.ts +2 -1
  7. package/build/address.js +68 -13
  8. package/build/block.js +2 -2
  9. package/build/bufferutils.js +5 -5
  10. package/build/networks.d.ts +1 -0
  11. package/build/networks.js +11 -0
  12. package/build/psbt/psbtutils.js +2 -2
  13. package/build/psbt.js +3 -7
  14. package/package.json +26 -26
  15. package/src/address.ts +91 -15
  16. package/src/block.ts +2 -2
  17. package/src/bufferutils.ts +15 -7
  18. package/src/index.ts +86 -86
  19. package/src/networks.ts +12 -0
  20. package/src/psbt/bip371.ts +441 -441
  21. package/src/psbt/psbtutils.ts +320 -319
  22. package/src/psbt.ts +8 -8
  23. package/test/address.spec.ts +55 -77
  24. package/test/bitcoin.core.spec.ts +47 -69
  25. package/test/block.spec.ts +23 -46
  26. package/test/bufferutils.spec.ts +32 -95
  27. package/test/crypto.spec.ts +9 -15
  28. package/test/fixtures/address.json +3 -3
  29. package/test/integration/addresses.spec.ts +12 -24
  30. package/test/integration/bip32.spec.ts +10 -31
  31. package/test/integration/blocks.spec.ts +2 -2
  32. package/test/integration/cltv.spec.ts +21 -63
  33. package/test/integration/csv.spec.ts +30 -105
  34. package/test/integration/payments.spec.ts +16 -41
  35. package/test/integration/taproot.spec.ts +31 -75
  36. package/test/integration/transactions.spec.ts +37 -138
  37. package/test/payments.spec.ts +95 -106
  38. package/test/payments.utils.ts +20 -63
  39. package/test/psbt.spec.ts +100 -229
  40. package/test/script.spec.ts +26 -50
  41. package/test/script_number.spec.ts +6 -9
  42. package/test/script_signature.spec.ts +7 -7
  43. package/test/transaction.spec.ts +46 -96
  44. package/test/ts-node-register.js +3 -1
  45. package/test/tsconfig.json +4 -1
  46. package/test/types.spec.ts +7 -12
  47. package/.nyc_output/6368a5b2-daa5-4821-8ed0-b742d6fc7eab.json +0 -1
  48. package/.nyc_output/processinfo/6368a5b2-daa5-4821-8ed0-b742d6fc7eab.json +0 -1
  49. package/.nyc_output/processinfo/index.json +0 -1
  50. package/test/address.spec.js +0 -124
  51. package/test/bitcoin.core.spec.js +0 -170
  52. package/test/block.spec.js +0 -141
  53. package/test/bufferutils.spec.js +0 -427
  54. package/test/crypto.spec.js +0 -41
  55. package/test/integration/_regtest.js +0 -7
  56. package/test/integration/addresses.spec.js +0 -116
  57. package/test/integration/bip32.spec.js +0 -85
  58. package/test/integration/blocks.spec.js +0 -26
  59. package/test/integration/cltv.spec.js +0 -199
  60. package/test/integration/csv.spec.js +0 -362
  61. package/test/integration/payments.spec.js +0 -98
  62. package/test/integration/taproot.spec.js +0 -532
  63. package/test/integration/transactions.spec.js +0 -561
  64. package/test/payments.spec.js +0 -97
  65. package/test/payments.utils.js +0 -190
  66. package/test/psbt.spec.js +0 -1044
  67. package/test/script.spec.js +0 -151
  68. package/test/script_number.spec.js +0 -24
  69. package/test/script_signature.spec.js +0 -52
  70. package/test/transaction.spec.js +0 -269
  71. package/test/types.spec.js +0 -46
@@ -1,17 +1,18 @@
1
- import * as assert from 'assert';
2
- import BIP32Factory from 'bip32';
1
+ import assert from 'assert';
2
+ import { BIP32Factory } from 'bip32';
3
3
  import * as bip39 from 'bip39';
4
4
  import * as ecc from 'tiny-secp256k1';
5
5
  import { describe, it } from 'mocha';
6
- import { PsbtInput, TapLeaf, TapLeafScript } from 'bip174/src/lib/interfaces';
7
- import { regtestUtils } from './_regtest';
8
- import * as bitcoin from '../..';
9
- import { Taptree } from '../../src/types';
10
- import { LEAF_VERSION_TAPSCRIPT } from '../../src/payments/bip341';
11
- import { tapTreeFromList, tapTreeToList, toXOnly } from '../../src/psbt/bip371';
12
- import { witnessStackToScriptWitness } from '../../src/psbt/psbtutils';
13
-
14
- const rng = require('randombytes');
6
+ import { PsbtInput, TapLeaf, TapLeafScript } from 'bip174/src/lib/interfaces.js';
7
+ import { regtestUtils } from './_regtest.js';
8
+ import * as bitcoin from '../../src/index.js';
9
+ import { Taptree } from '../../src/types.js';
10
+ import { LEAF_VERSION_TAPSCRIPT } from '../../src/payments/bip341.js';
11
+ import { tapTreeFromList, tapTreeToList, toXOnly } from '../../src/psbt/bip371.js';
12
+ import { witnessStackToScriptWitness } from '../../src/psbt/psbtutils.js';
13
+
14
+ import rng from 'randombytes';
15
+
15
16
  const regtest = regtestUtils.network;
16
17
  bitcoin.initEccLib(ecc);
17
18
  const bip32 = BIP32Factory(ecc);
@@ -28,8 +29,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
28
29
  'cc8a4bc64d897bddc5fbc2f670f7a8ba0b386779106cf1223c6fc5d7cd6fc115',
29
30
  'hex',
30
31
  );
31
- const expectedAddress =
32
- 'bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr';
32
+ const expectedAddress = 'bc1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqkedrcr';
33
33
 
34
34
  // Verify the above (Below is no different than other HD wallets)
35
35
  const seed = await bip39.mnemonicToSeed(mnemonic);
@@ -59,10 +59,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
59
59
  // amount to send
60
60
  const sendAmount = amount - 1e4;
61
61
  // Send some sats to the address via faucet. Get the hash and index. (txid/vout)
62
- const { txId: hash, vout: index } = await regtestUtils.faucetComplex(
63
- output,
64
- amount,
65
- );
62
+ const { txId: hash, vout: index } = await regtestUtils.faucetComplex(output, amount);
66
63
  // Sent 420000 sats to taproot address
67
64
 
68
65
  const psbt = new bitcoin.Psbt({ network: regtest })
@@ -111,10 +108,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
111
108
  const unspent = await regtestUtils.faucetComplex(output!, amount);
112
109
 
113
110
  // non segwit utxo
114
- const p2pkhUnspent = await regtestUtils.faucetComplex(
115
- p2pkhOutput!,
116
- amount,
117
- );
111
+ const p2pkhUnspent = await regtestUtils.faucetComplex(p2pkhOutput!, amount);
118
112
  const utx = await regtestUtils.fetch(p2pkhUnspent.txId);
119
113
  const nonWitnessUtxo = Buffer.from(utx.txHex, 'hex');
120
114
 
@@ -141,10 +135,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
141
135
  });
142
136
 
143
137
  const tweakedSigner = internalKey.tweak(
144
- bitcoin.crypto.taggedHash(
145
- 'TapTweak',
146
- toXOnly(internalKey.publicKey),
147
- ),
138
+ bitcoin.crypto.taggedHash('TapTweak', toXOnly(internalKey.publicKey)),
148
139
  );
149
140
  await psbt.signInputAsync(0, tweakedSigner);
150
141
  await psbt.signInputAsync(1, p2pkhKey);
@@ -168,9 +159,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
168
159
  const internalKey = bip32.fromSeed(rng(64), regtest);
169
160
  const leafKey = bip32.fromSeed(rng(64), regtest);
170
161
 
171
- const leafScriptAsm = `${toXOnly(leafKey.publicKey).toString(
172
- 'hex',
173
- )} OP_CHECKSIG`;
162
+ const leafScriptAsm = `${toXOnly(leafKey.publicKey).toString('hex')} OP_CHECKSIG`;
174
163
  const leafScript = bitcoin.script.fromASM(leafScriptAsm);
175
164
 
176
165
  const scriptTree = {
@@ -227,9 +216,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
227
216
  const internalKey = bip32.fromSeed(rng(64), regtest);
228
217
  const leafKey = bip32.fromSeed(rng(64), regtest);
229
218
 
230
- const leafScriptAsm = `${toXOnly(leafKey.publicKey).toString(
231
- 'hex',
232
- )} OP_CHECKSIG`;
219
+ const leafScriptAsm = `${toXOnly(leafKey.publicKey).toString('hex')} OP_CHECKSIG`;
233
220
  const leafScript = bitcoin.script.fromASM(leafScriptAsm);
234
221
 
235
222
  const scriptTree: Taptree = [
@@ -432,8 +419,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
432
419
  } catch (err) {
433
420
  if ((err as any).message !== 'non-BIP68-final')
434
421
  throw new Error(
435
- 'Expected OP_CHECKSEQUENCEVERIFY validation to fail. But it faild with: ' +
436
- err,
422
+ 'Expected OP_CHECKSEQUENCEVERIFY validation to fail. But it faild with: ' + err,
437
423
  );
438
424
  }
439
425
  await regtestUtils.mine(10);
@@ -541,18 +527,14 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
541
527
  ({
542
528
  depth: 3,
543
529
  leafVersion: LEAF_VERSION_TAPSCRIPT,
544
- script: bitcoin.script.fromASM(
545
- `OP_ADD OP_${index * 2} OP_EQUAL`,
546
- ),
547
- } as TapLeaf),
530
+ script: bitcoin.script.fromASM(`OP_ADD OP_${index * 2} OP_EQUAL`),
531
+ }) as TapLeaf,
548
532
  );
549
533
  const scriptTree = tapTreeFromList(leaves);
550
534
 
551
535
  for (let leafIndex = 1; leafIndex < leafCount; leafIndex++) {
552
536
  const redeem = {
553
- output: bitcoin.script.fromASM(
554
- `OP_ADD OP_${leafIndex * 2} OP_EQUAL`,
555
- ),
537
+ output: bitcoin.script.fromASM(`OP_ADD OP_${leafIndex * 2} OP_EQUAL`),
556
538
  redeemVersion: LEAF_VERSION_TAPSCRIPT,
557
539
  };
558
540
 
@@ -585,17 +567,13 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
585
567
  };
586
568
  psbt.updateInput(0, { tapLeafScript: [tapLeafScript] });
587
569
 
588
- const sendAddress =
589
- 'bcrt1pqknex3jwpsaatu5e5dcjw70nac3fr5k5y3hcxr4hgg6rljzp59nqs6a0vh';
570
+ const sendAddress = 'bcrt1pqknex3jwpsaatu5e5dcjw70nac3fr5k5y3hcxr4hgg6rljzp59nqs6a0vh';
590
571
  psbt.addOutput({
591
572
  value: sendAmount,
592
573
  address: sendAddress,
593
574
  });
594
575
 
595
- const leafIndexFinalizerFn = buildLeafIndexFinalizer(
596
- tapLeafScript,
597
- leafIndex,
598
- );
576
+ const leafIndexFinalizerFn = buildLeafIndexFinalizer(tapLeafScript, leafIndex);
599
577
  psbt.finalizeInput(0, leafIndexFinalizerFn);
600
578
  const tx = psbt.extractTransaction();
601
579
  const rawTx = tx.toBuffer();
@@ -612,11 +590,7 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
612
590
  });
613
591
 
614
592
  it('should fail validating invalid signatures for taproot (See issue #1931)', () => {
615
- const schnorrValidator = (
616
- pubkey: Buffer,
617
- msghash: Buffer,
618
- signature: Buffer,
619
- ) => {
593
+ const schnorrValidator = (pubkey: Buffer, msghash: Buffer, signature: Buffer) => {
620
594
  return ecc.verifySchnorr(msghash, pubkey, signature);
621
595
  };
622
596
 
@@ -636,18 +610,11 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
636
610
 
637
611
  const psbt = bitcoin.Psbt.fromBase64(psbtBase64);
638
612
 
639
- assert(
640
- !psbt.validateSignaturesOfAllInputs(schnorrValidator),
641
- 'Should fail validation',
642
- );
613
+ assert(!psbt.validateSignaturesOfAllInputs(schnorrValidator), 'Should fail validation');
643
614
  });
644
615
 
645
616
  it('should succeed validating valid signatures for taproot (See issue #1934)', () => {
646
- const schnorrValidator = (
647
- pubkey: Buffer,
648
- msghash: Buffer,
649
- signature: Buffer,
650
- ) => {
617
+ const schnorrValidator = (pubkey: Buffer, msghash: Buffer, signature: Buffer) => {
651
618
  return ecc.verifySchnorr(msghash, pubkey, signature);
652
619
  };
653
620
 
@@ -658,17 +625,11 @@ describe('bitcoinjs-lib (transaction with taproot)', () => {
658
625
  UhZhPJ7AP2/7U3zgi5tn/uqDqgeVgvO/VpgAAAAABASsQJwAAAAAAACJRICJSM30fn5SFmE8nsA/
659
626
  b/tTfOCLm2f+6oOqB5WC879WmAQMEgwAAAAETQWQwNOao3RMOBWPuAQ9Iph7Qzk47MvroTHbJR49
660
627
  MxKJmQ6hfhZa5wVVrdKYea5BW/loqa7al2pYYZMlGvdS06wODARcgjuYXxIpyOMVTYEvl35gDidC
661
- m/vUICZyuNNZKaPz9dxAAAQUgjuYXxIpyOMVTYEvl35gDidCm/vUICZyuNNZKaPz9dxAA`.replace(
662
- /\s+/g,
663
- '',
664
- );
628
+ m/vUICZyuNNZKaPz9dxAAAQUgjuYXxIpyOMVTYEvl35gDidCm/vUICZyuNNZKaPz9dxAA`.replace(/\s+/g, '');
665
629
 
666
630
  const psbt = bitcoin.Psbt.fromBase64(psbtBase64);
667
631
 
668
- assert(
669
- psbt.validateSignaturesOfAllInputs(schnorrValidator),
670
- 'Should succeed validation',
671
- );
632
+ assert(psbt.validateSignaturesOfAllInputs(schnorrValidator), 'Should succeed validation');
672
633
  });
673
634
  });
674
635
 
@@ -690,18 +651,13 @@ function buildLeafIndexFinalizer(
690
651
  finalScriptWitness: Buffer | undefined;
691
652
  } => {
692
653
  try {
693
- const scriptSolution = [
694
- Buffer.from([leafIndex]),
695
- Buffer.from([leafIndex]),
696
- ];
654
+ const scriptSolution = [Buffer.from([leafIndex]), Buffer.from([leafIndex])];
697
655
  const witness = scriptSolution
698
656
  .concat(tapLeafScript.script)
699
657
  .concat(tapLeafScript.controlBlock);
700
658
  return { finalScriptWitness: witnessStackToScriptWitness(witness) };
701
659
  } catch (err) {
702
- throw new Error(
703
- `Can not finalize taproot input #${inputIndex}: ${err}`,
704
- );
660
+ throw new Error(`Can not finalize taproot input #${inputIndex}: ${err}`);
705
661
  }
706
662
  };
707
663
  }
@@ -1,29 +1,25 @@
1
- import * as assert from 'assert';
2
- import BIP32Factory from 'bip32';
1
+ import assert from 'assert';
2
+ import { BIP32Factory } from 'bip32';
3
3
  import * as ecc from 'tiny-secp256k1';
4
- import ECPairFactory from 'ecpair';
4
+ import { ECPairFactory } from 'ecpair';
5
5
  import { describe, it } from 'mocha';
6
- import * as bitcoin from '../..';
7
- import { regtestUtils } from './_regtest';
6
+ import * as bitcoin from '../../src/index.js';
7
+ import { regtestUtils } from './_regtest.js';
8
+
9
+ import rng from 'randombytes';
8
10
 
9
11
  const ECPair = ECPairFactory(ecc);
10
- const rng = require('randombytes');
11
- const regtest = regtestUtils.network;
12
+ const regtest = { ...regtestUtils.network, bech32Opnet: 'opreg' };
12
13
  const bip32 = BIP32Factory(ecc);
13
14
 
14
- const validator = (
15
- pubkey: Buffer,
16
- msghash: Buffer,
17
- signature: Buffer,
18
- ): boolean => ECPair.fromPublicKey(pubkey).verify(msghash, signature);
15
+ const validator = (pubkey: Buffer, msghash: Buffer, signature: Buffer): boolean =>
16
+ ECPair.fromPublicKey(pubkey).verify(msghash, signature);
19
17
 
20
18
  // See bottom of file for some helper functions used to make the payment objects needed.
21
19
 
22
20
  describe('bitcoinjs-lib (transactions with psbt)', () => {
23
21
  it('can create a 1-to-1 Transaction', () => {
24
- const alice = ECPair.fromWIF(
25
- 'L2uPYXe17xSTqbCjZvL2DsyXPCbXspvcu5mHLDYUgzdUbZGSKrSr',
26
- );
22
+ const alice = ECPair.fromWIF('L2uPYXe17xSTqbCjZvL2DsyXPCbXspvcu5mHLDYUgzdUbZGSKrSr');
27
23
  const psbt = new bitcoin.Psbt();
28
24
  psbt.setVersion(2); // These are defaults. This line is not needed.
29
25
  psbt.setLocktime(0); // These are defaults. This line is not needed.
@@ -89,18 +85,8 @@ describe('bitcoinjs-lib (transactions with psbt)', () => {
89
85
  const alice2 = createPayment('p2pkh');
90
86
 
91
87
  // give Alice 2 unspent outputs
92
- const inputData1 = await getInputData(
93
- 5e4,
94
- alice1.payment,
95
- false,
96
- 'noredeem',
97
- );
98
- const inputData2 = await getInputData(
99
- 7e4,
100
- alice2.payment,
101
- false,
102
- 'noredeem',
103
- );
88
+ const inputData1 = await getInputData(5e4, alice1.payment, false, 'noredeem');
89
+ const inputData2 = await getInputData(7e4, alice2.payment, false, 'noredeem');
104
90
  {
105
91
  const {
106
92
  hash, // string of txid or Buffer of tx hash. (txid and hash are reverse order)
@@ -170,14 +156,9 @@ describe('bitcoinjs-lib (transactions with psbt)', () => {
170
156
  // to build and broadcast to the actual Bitcoin network, see https://github.com/bitcoinjs/bitcoinjs-lib/issues/839
171
157
  });
172
158
 
173
- it('can create (and broadcast via 3PBP) a Transaction with an OP_RETURN output', async () => {
159
+ /*it('can create (and broadcast via 3PBP) a Transaction with an OP_RETURN output', async () => {
174
160
  const alice1 = createPayment('p2pkh');
175
- const inputData1 = await getInputData(
176
- 2e5,
177
- alice1.payment,
178
- false,
179
- 'noredeem',
180
- );
161
+ const inputData1 = await getInputData(2e5, alice1.payment, false, 'noredeem');
181
162
 
182
163
  const data = Buffer.from('bitcoinjs-lib', 'utf8');
183
164
  const embed = bitcoin.payments.embed({ data: [data] });
@@ -199,16 +180,11 @@ describe('bitcoinjs-lib (transactions with psbt)', () => {
199
180
 
200
181
  // build and broadcast to the RegTest network
201
182
  await regtestUtils.broadcast(psbt.extractTransaction().toHex());
202
- });
183
+ });*/
203
184
 
204
185
  it('can create (and broadcast via 3PBP) a Transaction, w/ a P2SH(P2MS(2 of 4)) (multisig) input', async () => {
205
186
  const multisig = createPayment('p2sh-p2ms(2 of 4)');
206
- const inputData1 = await getInputData(
207
- 2e4,
208
- multisig.payment,
209
- false,
210
- 'p2sh',
211
- );
187
+ const inputData1 = await getInputData(2e4, multisig.payment, false, 'p2sh');
212
188
  {
213
189
  const {
214
190
  hash,
@@ -216,10 +192,7 @@ describe('bitcoinjs-lib (transactions with psbt)', () => {
216
192
  nonWitnessUtxo,
217
193
  redeemScript, // NEW: P2SH needs to give redeemScript when adding an input.
218
194
  } = inputData1;
219
- assert.deepStrictEqual(
220
- { hash, index, nonWitnessUtxo, redeemScript },
221
- inputData1,
222
- );
195
+ assert.deepStrictEqual({ hash, index, nonWitnessUtxo, redeemScript }, inputData1);
223
196
  }
224
197
 
225
198
  const psbt = new bitcoin.Psbt({ network: regtest })
@@ -233,19 +206,11 @@ describe('bitcoinjs-lib (transactions with psbt)', () => {
233
206
 
234
207
  assert.strictEqual(psbt.validateSignaturesOfInput(0, validator), true);
235
208
  assert.strictEqual(
236
- psbt.validateSignaturesOfInput(
237
- 0,
238
- validator,
239
- multisig.keys[0].publicKey,
240
- ),
209
+ psbt.validateSignaturesOfInput(0, validator, multisig.keys[0].publicKey),
241
210
  true,
242
211
  );
243
212
  assert.throws(() => {
244
- psbt.validateSignaturesOfInput(
245
- 0,
246
- validator,
247
- multisig.keys[3].publicKey,
248
- );
213
+ psbt.validateSignaturesOfInput(0, validator, multisig.keys[3].publicKey);
249
214
  }, new RegExp('No signatures for this pubkey'));
250
215
  psbt.finalizeAllInputs();
251
216
 
@@ -273,10 +238,7 @@ describe('bitcoinjs-lib (transactions with psbt)', () => {
273
238
  witnessUtxo, // NEW: this is an object of the output being spent { script: Buffer; value: Satoshis; }
274
239
  redeemScript,
275
240
  } = inputData;
276
- assert.deepStrictEqual(
277
- { hash, index, witnessUtxo, redeemScript },
278
- inputData,
279
- );
241
+ assert.deepStrictEqual({ hash, index, witnessUtxo, redeemScript }, inputData);
280
242
  }
281
243
  const keyPair = p2sh.keys[0];
282
244
  const outputData = {
@@ -340,12 +302,7 @@ describe('bitcoinjs-lib (transactions with psbt)', () => {
340
302
  // the only thing that changes is you don't give a redeemscript for input data
341
303
 
342
304
  const p2wpkh = createPayment('p2wpkh');
343
- const inputData = await getInputData(
344
- 5e4,
345
- p2wpkh.payment,
346
- true,
347
- 'noredeem',
348
- );
305
+ const inputData = await getInputData(5e4, p2wpkh.payment, true, 'noredeem');
349
306
  {
350
307
  const { hash, index, witnessUtxo } = inputData;
351
308
  assert.deepStrictEqual({ hash, index, witnessUtxo }, inputData);
@@ -379,12 +336,7 @@ describe('bitcoinjs-lib (transactions with psbt)', () => {
379
336
  // For learning purposes, ignore this test.
380
337
  // REPEATING ABOVE BUT WITH nonWitnessUtxo by passing false to getInputData
381
338
  const p2wpkh = createPayment('p2wpkh');
382
- const inputData = await getInputData(
383
- 5e4,
384
- p2wpkh.payment,
385
- false,
386
- 'noredeem',
387
- );
339
+ const inputData = await getInputData(5e4, p2wpkh.payment, false, 'noredeem');
388
340
  const psbt = new bitcoin.Psbt({ network: regtest })
389
341
  .addInput(inputData)
390
342
  .addOutput({
@@ -413,10 +365,7 @@ describe('bitcoinjs-lib (transactions with psbt)', () => {
413
365
  witnessUtxo,
414
366
  witnessScript, // NEW: A Buffer of the witnessScript
415
367
  } = inputData;
416
- assert.deepStrictEqual(
417
- { hash, index, witnessUtxo, witnessScript },
418
- inputData,
419
- );
368
+ assert.deepStrictEqual({ hash, index, witnessUtxo, witnessScript }, inputData);
420
369
  }
421
370
 
422
371
  const psbt = new bitcoin.Psbt({ network: regtest })
@@ -447,12 +396,7 @@ describe('bitcoinjs-lib (transactions with psbt)', () => {
447
396
  // For learning purposes, ignore this test.
448
397
  // REPEATING ABOVE BUT WITH nonWitnessUtxo by passing false to getInputData
449
398
  const p2wsh = createPayment('p2wsh-p2pk');
450
- const inputData = await getInputData(
451
- 5e4,
452
- p2wsh.payment,
453
- false,
454
- 'p2wsh',
455
- );
399
+ const inputData = await getInputData(5e4, p2wsh.payment, false, 'p2wsh');
456
400
  const psbt = new bitcoin.Psbt({ network: regtest })
457
401
  .addInput(inputData)
458
402
  .addOutput({
@@ -476,20 +420,9 @@ describe('bitcoinjs-lib (transactions with psbt)', () => {
476
420
  'P2SH(P2WSH(P2MS(3 of 4))) (SegWit multisig) input',
477
421
  async () => {
478
422
  const p2sh = createPayment('p2sh-p2wsh-p2ms(3 of 4)');
479
- const inputData = await getInputData(
480
- 5e4,
481
- p2sh.payment,
482
- true,
483
- 'p2sh-p2wsh',
484
- );
423
+ const inputData = await getInputData(5e4, p2sh.payment, true, 'p2sh-p2wsh');
485
424
  {
486
- const {
487
- hash,
488
- index,
489
- witnessUtxo,
490
- redeemScript,
491
- witnessScript,
492
- } = inputData;
425
+ const { hash, index, witnessUtxo, redeemScript, witnessScript } = inputData;
493
426
  assert.deepStrictEqual(
494
427
  { hash, index, witnessUtxo, redeemScript, witnessScript },
495
428
  inputData,
@@ -506,24 +439,13 @@ describe('bitcoinjs-lib (transactions with psbt)', () => {
506
439
  .signInput(0, p2sh.keys[2])
507
440
  .signInput(0, p2sh.keys[3]);
508
441
 
442
+ assert.strictEqual(psbt.validateSignaturesOfInput(0, validator), true);
509
443
  assert.strictEqual(
510
- psbt.validateSignaturesOfInput(0, validator),
511
- true,
512
- );
513
- assert.strictEqual(
514
- psbt.validateSignaturesOfInput(
515
- 0,
516
- validator,
517
- p2sh.keys[3].publicKey,
518
- ),
444
+ psbt.validateSignaturesOfInput(0, validator, p2sh.keys[3].publicKey),
519
445
  true,
520
446
  );
521
447
  assert.throws(() => {
522
- psbt.validateSignaturesOfInput(
523
- 0,
524
- validator,
525
- p2sh.keys[1].publicKey,
526
- );
448
+ psbt.validateSignaturesOfInput(0, validator, p2sh.keys[1].publicKey);
527
449
  }, new RegExp('No signatures for this pubkey'));
528
450
  psbt.finalizeAllInputs();
529
451
 
@@ -548,12 +470,7 @@ describe('bitcoinjs-lib (transactions with psbt)', () => {
548
470
  // For learning purposes, ignore this test.
549
471
  // REPEATING ABOVE BUT WITH nonWitnessUtxo by passing false to getInputData
550
472
  const p2sh = createPayment('p2sh-p2wsh-p2ms(3 of 4)');
551
- const inputData = await getInputData(
552
- 5e4,
553
- p2sh.payment,
554
- false,
555
- 'p2sh-p2wsh',
556
- );
473
+ const inputData = await getInputData(5e4, p2sh.payment, false, 'p2sh-p2wsh');
557
474
  const psbt = new bitcoin.Psbt({ network: regtest })
558
475
  .addInput(inputData)
559
476
  .addOutput({
@@ -580,17 +497,9 @@ describe('bitcoinjs-lib (transactions with psbt)', () => {
580
497
  'P2SH(P2MS(2 of 2)) input with nonWitnessUtxo',
581
498
  async () => {
582
499
  const myKey = ECPair.makeRandom({ network: regtest });
583
- const myKeys = [
584
- myKey,
585
- ECPair.fromPrivateKey(myKey.privateKey!, { network: regtest }),
586
- ];
500
+ const myKeys = [myKey, ECPair.fromPrivateKey(myKey.privateKey!, { network: regtest })];
587
501
  const p2sh = createPayment('p2sh-p2ms(2 of 2)', myKeys);
588
- const inputData = await getInputData(
589
- 5e4,
590
- p2sh.payment,
591
- false,
592
- 'p2sh',
593
- );
502
+ const inputData = await getInputData(5e4, p2sh.payment, false, 'p2sh');
594
503
  const psbt = new bitcoin.Psbt({ network: regtest })
595
504
  .addInput(inputData)
596
505
  .addOutput({
@@ -635,12 +544,7 @@ describe('bitcoinjs-lib (transactions with psbt)', () => {
635
544
  ],
636
545
  };
637
546
  const p2wpkh = createPayment('p2wpkh', [childNode]);
638
- const inputData = await getInputData(
639
- 5e4,
640
- p2wpkh.payment,
641
- true,
642
- 'noredeem',
643
- );
547
+ const inputData = await getInputData(5e4, p2wpkh.payment, true, 'noredeem');
644
548
  {
645
549
  const { hash, index, witnessUtxo } = inputData;
646
550
  assert.deepStrictEqual({ hash, index, witnessUtxo }, inputData);
@@ -659,10 +563,7 @@ describe('bitcoinjs-lib (transactions with psbt)', () => {
659
563
  .signInputHD(0, hdRoot); // must sign with root!!!
660
564
 
661
565
  assert.strictEqual(psbt.validateSignaturesOfInput(0, validator), true);
662
- assert.strictEqual(
663
- psbt.validateSignaturesOfInput(0, validator, childNode.publicKey),
664
- true,
665
- );
566
+ assert.strictEqual(psbt.validateSignaturesOfInput(0, validator, childNode.publicKey), true);
666
567
  psbt.finalizeAllInputs();
667
568
 
668
569
  const tx = psbt.extractTransaction();
@@ -700,13 +601,11 @@ function createPayment(_type: string, myKeys?: any[], network?: any): any {
700
601
  if (!myKeys) keys.push(ECPair.makeRandom({ network }));
701
602
 
702
603
  let payment: any;
703
- splitType.forEach(type => {
604
+ splitType.forEach((type) => {
704
605
  if (type.slice(0, 4) === 'p2ms') {
705
606
  payment = bitcoin.payments.p2ms({
706
607
  m,
707
- pubkeys: keys
708
- .map(key => key.publicKey)
709
- .sort((a, b) => a.compare(b)),
608
+ pubkeys: keys.map((key) => key.publicKey).sort((a, b) => a.compare(b)),
710
609
  network,
711
610
  });
712
611
  } else if (['p2sh', 'p2wsh'].indexOf(type) > -1) {