@btc-vision/bitcoin 6.3.5 → 6.4.0

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 (72) 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/browser/psbt/psbtutils.d.ts +1 -1
  7. package/build/address.d.ts +1 -1
  8. package/build/address.js +12 -5
  9. package/build/block.js +2 -2
  10. package/build/bufferutils.js +5 -5
  11. package/build/networks.d.ts +1 -0
  12. package/build/networks.js +11 -0
  13. package/build/psbt/psbtutils.js +2 -2
  14. package/build/psbt.js +3 -7
  15. package/package.json +26 -26
  16. package/src/address.ts +20 -6
  17. package/src/block.ts +233 -233
  18. package/src/bufferutils.ts +188 -180
  19. package/src/index.ts +86 -86
  20. package/src/networks.ts +12 -0
  21. package/src/psbt/bip371.ts +441 -441
  22. package/src/psbt/psbtutils.ts +4 -3
  23. package/src/psbt.ts +2187 -2187
  24. package/test/address.spec.ts +155 -177
  25. package/test/bitcoin.core.spec.ts +212 -234
  26. package/test/block.spec.ts +171 -194
  27. package/test/bufferutils.spec.ts +450 -513
  28. package/test/crypto.spec.ts +49 -55
  29. package/test/fixtures/address.json +3 -3
  30. package/test/integration/addresses.spec.ts +142 -154
  31. package/test/integration/bip32.spec.ts +130 -151
  32. package/test/integration/blocks.spec.ts +28 -28
  33. package/test/integration/cltv.spec.ts +241 -283
  34. package/test/integration/csv.spec.ts +452 -527
  35. package/test/integration/payments.spec.ts +110 -135
  36. package/test/integration/taproot.spec.ts +663 -707
  37. package/test/integration/transactions.spec.ts +668 -769
  38. package/test/payments.spec.ts +114 -125
  39. package/test/payments.utils.ts +165 -208
  40. package/test/psbt.spec.ts +1285 -1414
  41. package/test/script.spec.ts +186 -210
  42. package/test/script_number.spec.ts +26 -29
  43. package/test/script_signature.spec.ts +66 -66
  44. package/test/transaction.spec.ts +337 -387
  45. package/test/ts-node-register.js +7 -5
  46. package/test/tsconfig.json +4 -1
  47. package/test/types.spec.ts +53 -58
  48. package/.nyc_output/6368a5b2-daa5-4821-8ed0-b742d6fc7eab.json +0 -1
  49. package/.nyc_output/processinfo/6368a5b2-daa5-4821-8ed0-b742d6fc7eab.json +0 -1
  50. package/.nyc_output/processinfo/index.json +0 -1
  51. package/test/address.spec.js +0 -124
  52. package/test/bitcoin.core.spec.js +0 -170
  53. package/test/block.spec.js +0 -141
  54. package/test/bufferutils.spec.js +0 -427
  55. package/test/crypto.spec.js +0 -41
  56. package/test/integration/_regtest.js +0 -7
  57. package/test/integration/addresses.spec.js +0 -116
  58. package/test/integration/bip32.spec.js +0 -85
  59. package/test/integration/blocks.spec.js +0 -26
  60. package/test/integration/cltv.spec.js +0 -199
  61. package/test/integration/csv.spec.js +0 -362
  62. package/test/integration/payments.spec.js +0 -98
  63. package/test/integration/taproot.spec.js +0 -532
  64. package/test/integration/transactions.spec.js +0 -561
  65. package/test/payments.spec.js +0 -97
  66. package/test/payments.utils.js +0 -190
  67. package/test/psbt.spec.js +0 -1044
  68. package/test/script.spec.js +0 -151
  69. package/test/script_number.spec.js +0 -24
  70. package/test/script_signature.spec.js +0 -52
  71. package/test/transaction.spec.js +0 -269
  72. package/test/types.spec.js +0 -46
@@ -1,135 +1,110 @@
1
- import ECPairFactory from 'ecpair';
2
- import * as ecc from 'tiny-secp256k1';
3
- import { describe, it } from 'mocha';
4
- import * as bitcoin from '../..';
5
- import { regtestUtils } from './_regtest';
6
-
7
- const ECPair = ECPairFactory(ecc);
8
- const NETWORK = regtestUtils.network;
9
- const keyPairs = [
10
- ECPair.makeRandom({ network: NETWORK }),
11
- ECPair.makeRandom({ network: NETWORK }),
12
- ];
13
-
14
- async function buildAndSign(
15
- depends: any,
16
- prevOutput: any,
17
- redeemScript: any,
18
- witnessScript: any,
19
- ): Promise<null> {
20
- const unspent = await regtestUtils.faucetComplex(prevOutput, 5e4);
21
- const utx = await regtestUtils.fetch(unspent.txId);
22
-
23
- const psbt = new bitcoin.Psbt({ network: NETWORK })
24
- .addInput({
25
- hash: unspent.txId,
26
- index: unspent.vout,
27
- nonWitnessUtxo: Buffer.from(utx.txHex, 'hex'),
28
- ...(redeemScript ? { redeemScript } : {}),
29
- ...(witnessScript ? { witnessScript } : {}),
30
- })
31
- .addOutput({
32
- address: regtestUtils.RANDOM_ADDRESS,
33
- value: 2e4,
34
- });
35
-
36
- if (depends.signatures) {
37
- keyPairs.forEach(keyPair => {
38
- psbt.signInput(0, keyPair);
39
- });
40
- } else if (depends.signature) {
41
- psbt.signInput(0, keyPairs[0]);
42
- }
43
-
44
- return regtestUtils.broadcast(
45
- psbt.finalizeAllInputs().extractTransaction().toHex(),
46
- );
47
- }
48
-
49
- ['p2ms', 'p2pk', 'p2pkh', 'p2wpkh'].forEach(k => {
50
- const fixtures = require('../fixtures/' + k);
51
- const { depends } = fixtures.dynamic;
52
- const fn: any = (bitcoin.payments as any)[k];
53
-
54
- const base: any = {};
55
- if (depends.pubkey) base.pubkey = keyPairs[0].publicKey;
56
- if (depends.pubkeys) base.pubkeys = keyPairs.map(x => x.publicKey);
57
- if (depends.m) base.m = base.pubkeys.length;
58
-
59
- const { output } = fn(base);
60
- if (!output) throw new TypeError('Missing output');
61
-
62
- describe('bitcoinjs-lib (payments - ' + k + ')', () => {
63
- it('can broadcast as an output, and be spent as an input', async () => {
64
- Object.assign(depends, { prevOutScriptType: k });
65
- await buildAndSign(depends, output, undefined, undefined);
66
- });
67
-
68
- it(
69
- 'can (as P2SH(' +
70
- k +
71
- ')) broadcast as an output, and be spent as an input',
72
- async () => {
73
- const p2sh = bitcoin.payments.p2sh({
74
- redeem: { output },
75
- network: NETWORK,
76
- });
77
- Object.assign(depends, { prevOutScriptType: 'p2sh-' + k });
78
- await buildAndSign(
79
- depends,
80
- p2sh.output,
81
- p2sh.redeem!.output,
82
- undefined,
83
- );
84
- },
85
- );
86
-
87
- // NOTE: P2WPKH cannot be wrapped in P2WSH, consensus fail
88
- if (k === 'p2wpkh') return;
89
-
90
- it(
91
- 'can (as P2WSH(' +
92
- k +
93
- ')) broadcast as an output, and be spent as an input',
94
- async () => {
95
- const p2wsh = bitcoin.payments.p2wsh({
96
- redeem: { output },
97
- network: NETWORK,
98
- });
99
- Object.assign(depends, { prevOutScriptType: 'p2wsh-' + k });
100
- await buildAndSign(
101
- depends,
102
- p2wsh.output,
103
- undefined,
104
- p2wsh.redeem!.output,
105
- );
106
- },
107
- );
108
-
109
- it(
110
- 'can (as P2SH(P2WSH(' +
111
- k +
112
- '))) broadcast as an output, and be spent as an input',
113
- async () => {
114
- const p2wsh = bitcoin.payments.p2wsh({
115
- redeem: { output },
116
- network: NETWORK,
117
- });
118
- const p2sh = bitcoin.payments.p2sh({
119
- redeem: { output: p2wsh.output },
120
- network: NETWORK,
121
- });
122
-
123
- Object.assign(depends, {
124
- prevOutScriptType: 'p2sh-p2wsh-' + k,
125
- });
126
- await buildAndSign(
127
- depends,
128
- p2sh.output,
129
- p2sh.redeem!.output,
130
- p2wsh.redeem!.output,
131
- );
132
- },
133
- );
134
- });
135
- });
1
+ import { ECPairFactory } from 'ecpair';
2
+ import * as ecc from 'tiny-secp256k1';
3
+ import { describe, it } from 'mocha';
4
+ import * as bitcoin from '../../src/index.js';
5
+ import { regtestUtils } from './_regtest.js';
6
+ import * as fs from 'node:fs';
7
+
8
+ const ECPair = ECPairFactory(ecc);
9
+ const NETWORK = regtestUtils.network;
10
+ const keyPairs = [ECPair.makeRandom({ network: NETWORK }), ECPair.makeRandom({ network: NETWORK })];
11
+
12
+ async function buildAndSign(
13
+ depends: any,
14
+ prevOutput: any,
15
+ redeemScript: any,
16
+ witnessScript: any,
17
+ ): Promise<null> {
18
+ const unspent = await regtestUtils.faucetComplex(prevOutput, 5e4);
19
+ const utx = await regtestUtils.fetch(unspent.txId);
20
+
21
+ const psbt = new bitcoin.Psbt({ network: NETWORK })
22
+ .addInput({
23
+ hash: unspent.txId,
24
+ index: unspent.vout,
25
+ nonWitnessUtxo: Buffer.from(utx.txHex, 'hex'),
26
+ ...(redeemScript ? { redeemScript } : {}),
27
+ ...(witnessScript ? { witnessScript } : {}),
28
+ })
29
+ .addOutput({
30
+ address: regtestUtils.RANDOM_ADDRESS,
31
+ value: 2e4,
32
+ });
33
+
34
+ if (depends.signatures) {
35
+ keyPairs.forEach((keyPair) => {
36
+ psbt.signInput(0, keyPair);
37
+ });
38
+ } else if (depends.signature) {
39
+ psbt.signInput(0, keyPairs[0]);
40
+ }
41
+
42
+ return regtestUtils.broadcast(psbt.finalizeAllInputs().extractTransaction().toHex());
43
+ }
44
+
45
+ ['p2ms', 'p2pk', 'p2pkh', 'p2wpkh'].forEach((k) => {
46
+ const fixtures = JSON.parse(fs.readFileSync('test/fixtures/' + k + '.json', 'utf8'));
47
+ const { depends } = fixtures.dynamic;
48
+ const fn: any = (bitcoin.payments as any)[k];
49
+
50
+ const base: any = {};
51
+ if (depends.pubkey) base.pubkey = keyPairs[0].publicKey;
52
+ if (depends.pubkeys) base.pubkeys = keyPairs.map((x) => x.publicKey);
53
+ if (depends.m) base.m = base.pubkeys.length;
54
+
55
+ const { output } = fn(base);
56
+ if (!output) throw new TypeError('Missing output');
57
+
58
+ describe('bitcoinjs-lib (payments - ' + k + ')', () => {
59
+ it('can broadcast as an output, and be spent as an input', async () => {
60
+ Object.assign(depends, { prevOutScriptType: k });
61
+ await buildAndSign(depends, output, undefined, undefined);
62
+ });
63
+
64
+ it(
65
+ 'can (as P2SH(' + k + ')) broadcast as an output, and be spent as an input',
66
+ async () => {
67
+ const p2sh = bitcoin.payments.p2sh({
68
+ redeem: { output },
69
+ network: NETWORK,
70
+ });
71
+ Object.assign(depends, { prevOutScriptType: 'p2sh-' + k });
72
+ await buildAndSign(depends, p2sh.output, p2sh.redeem!.output, undefined);
73
+ },
74
+ );
75
+
76
+ // NOTE: P2WPKH cannot be wrapped in P2WSH, consensus fail
77
+ if (k === 'p2wpkh') return;
78
+
79
+ it(
80
+ 'can (as P2WSH(' + k + ')) broadcast as an output, and be spent as an input',
81
+ async () => {
82
+ const p2wsh = bitcoin.payments.p2wsh({
83
+ redeem: { output },
84
+ network: NETWORK,
85
+ });
86
+ Object.assign(depends, { prevOutScriptType: 'p2wsh-' + k });
87
+ await buildAndSign(depends, p2wsh.output, undefined, p2wsh.redeem!.output);
88
+ },
89
+ );
90
+
91
+ it(
92
+ 'can (as P2SH(P2WSH(' + k + '))) broadcast as an output, and be spent as an input',
93
+ async () => {
94
+ const p2wsh = bitcoin.payments.p2wsh({
95
+ redeem: { output },
96
+ network: NETWORK,
97
+ });
98
+ const p2sh = bitcoin.payments.p2sh({
99
+ redeem: { output: p2wsh.output },
100
+ network: NETWORK,
101
+ });
102
+
103
+ Object.assign(depends, {
104
+ prevOutScriptType: 'p2sh-p2wsh-' + k,
105
+ });
106
+ await buildAndSign(depends, p2sh.output, p2sh.redeem!.output, p2wsh.redeem!.output);
107
+ },
108
+ );
109
+ });
110
+ });