@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,194 +1,171 @@
1
- import * as assert from 'assert';
2
- import { beforeEach, describe, it } from 'mocha';
3
- import { Block } from '..';
4
-
5
- import * as fixtures from './fixtures/block.json';
6
-
7
- describe('Block', () => {
8
- describe('version', () => {
9
- it('should be interpreted as an int32le', () => {
10
- const blockHex =
11
- 'ffffffff000000000000000000000000000000000000000000000000000000000000' +
12
- '00004141414141414141414141414141414141414141414141414141414141414141' +
13
- '01000000020000000300000000';
14
- const block = Block.fromHex(blockHex);
15
- assert.strictEqual(-1, block.version);
16
- assert.strictEqual(1, block.timestamp);
17
- });
18
- });
19
-
20
- describe('calculateTarget', () => {
21
- fixtures.targets.forEach(f => {
22
- it('returns ' + f.expected + ' for 0x' + f.bits, () => {
23
- const bits = parseInt(f.bits, 16);
24
-
25
- assert.strictEqual(
26
- Block.calculateTarget(bits).toString('hex'),
27
- f.expected,
28
- );
29
- });
30
- });
31
- });
32
-
33
- describe('fromBuffer/fromHex', () => {
34
- fixtures.valid.forEach(f => {
35
- it('imports ' + f.description, () => {
36
- const block = Block.fromHex(f.hex);
37
-
38
- assert.strictEqual(block.version, f.version);
39
- assert.strictEqual(block.prevHash!.toString('hex'), f.prevHash);
40
- assert.strictEqual(
41
- block.merkleRoot!.toString('hex'),
42
- f.merkleRoot,
43
- );
44
- if (block.witnessCommit) {
45
- assert.strictEqual(
46
- block.witnessCommit.toString('hex'),
47
- f.witnessCommit,
48
- );
49
- }
50
- assert.strictEqual(block.timestamp, f.timestamp);
51
- assert.strictEqual(block.bits, f.bits);
52
- assert.strictEqual(block.nonce, f.nonce);
53
- assert.strictEqual(!block.transactions, f.hex.length === 160);
54
- if (f.size && f.strippedSize && f.weight) {
55
- assert.strictEqual(block.byteLength(false, true), f.size);
56
- assert.strictEqual(
57
- block.byteLength(false, false),
58
- f.strippedSize,
59
- );
60
- assert.strictEqual(block.weight(), f.weight);
61
- }
62
- });
63
- });
64
-
65
- fixtures.invalid.forEach(f => {
66
- it('throws on ' + f.exception, () => {
67
- assert.throws(() => {
68
- Block.fromHex(f.hex);
69
- }, new RegExp(f.exception));
70
- });
71
- });
72
- });
73
-
74
- describe('toBuffer/toHex', () => {
75
- fixtures.valid.forEach(f => {
76
- let block: Block;
77
-
78
- beforeEach(() => {
79
- block = Block.fromHex(f.hex);
80
- });
81
-
82
- it('exports ' + f.description, () => {
83
- assert.strictEqual(block.toHex(true), f.hex.slice(0, 160));
84
- assert.strictEqual(block.toHex(), f.hex);
85
- });
86
- });
87
- });
88
-
89
- describe('getHash/getId', () => {
90
- fixtures.valid.forEach(f => {
91
- let block: Block;
92
-
93
- beforeEach(() => {
94
- block = Block.fromHex(f.hex);
95
- });
96
-
97
- it('returns ' + f.id + ' for ' + f.description, () => {
98
- assert.strictEqual(block.getHash().toString('hex'), f.hash);
99
- assert.strictEqual(block.getId(), f.id);
100
- });
101
- });
102
- });
103
-
104
- describe('getUTCDate', () => {
105
- fixtures.valid.forEach(f => {
106
- let block: Block;
107
-
108
- beforeEach(() => {
109
- block = Block.fromHex(f.hex);
110
- });
111
-
112
- it('returns UTC date of ' + f.id, () => {
113
- const utcDate = block.getUTCDate().getTime();
114
-
115
- assert.strictEqual(utcDate, f.timestamp * 1e3);
116
- });
117
- });
118
- });
119
-
120
- describe('calculateMerkleRoot', () => {
121
- it('should throw on zero-length transaction array', () => {
122
- assert.throws(() => {
123
- Block.calculateMerkleRoot([]);
124
- }, /Cannot compute merkle root for zero transactions/);
125
- });
126
-
127
- fixtures.valid.forEach(f => {
128
- if (f.hex.length === 160) return;
129
-
130
- let block: Block;
131
-
132
- beforeEach(() => {
133
- block = Block.fromHex(f.hex);
134
- });
135
-
136
- it('returns ' + f.merkleRoot + ' for ' + f.id, () => {
137
- assert.strictEqual(
138
- Block.calculateMerkleRoot(block.transactions!).toString(
139
- 'hex',
140
- ),
141
- f.merkleRoot,
142
- );
143
- });
144
-
145
- if (f.witnessCommit) {
146
- it(
147
- 'returns witness commit ' +
148
- f.witnessCommit +
149
- ' for ' +
150
- f.id,
151
- () => {
152
- assert.strictEqual(
153
- Block.calculateMerkleRoot(
154
- block.transactions!,
155
- true,
156
- ).toString('hex'),
157
- f.witnessCommit,
158
- );
159
- },
160
- );
161
- }
162
- });
163
- });
164
-
165
- describe('checkTxRoots', () => {
166
- fixtures.valid.forEach(f => {
167
- if (f.hex.length === 160) return;
168
-
169
- let block: Block;
170
-
171
- beforeEach(() => {
172
- block = Block.fromHex(f.hex);
173
- });
174
-
175
- it('returns ' + f.valid + ' for ' + f.id, () => {
176
- assert.strictEqual(block.checkTxRoots(), true);
177
- });
178
- });
179
- });
180
-
181
- describe('checkProofOfWork', () => {
182
- fixtures.valid.forEach(f => {
183
- let block: Block;
184
-
185
- beforeEach(() => {
186
- block = Block.fromHex(f.hex);
187
- });
188
-
189
- it('returns ' + f.valid + ' for ' + f.id, () => {
190
- assert.strictEqual(block.checkProofOfWork(), f.valid);
191
- });
192
- });
193
- });
194
- });
1
+ import assert from 'assert';
2
+ import { beforeEach, describe, it } from 'mocha';
3
+ import { Block } from '../src/index.js';
4
+
5
+ import fixtures from './fixtures/block.json' with { type: 'json' };
6
+
7
+ describe('Block', () => {
8
+ describe('version', () => {
9
+ it('should be interpreted as an int32le', () => {
10
+ const blockHex =
11
+ 'ffffffff000000000000000000000000000000000000000000000000000000000000' +
12
+ '00004141414141414141414141414141414141414141414141414141414141414141' +
13
+ '01000000020000000300000000';
14
+ const block = Block.fromHex(blockHex);
15
+ assert.strictEqual(-1, block.version);
16
+ assert.strictEqual(1, block.timestamp);
17
+ });
18
+ });
19
+
20
+ describe('calculateTarget', () => {
21
+ fixtures.targets.forEach((f) => {
22
+ it('returns ' + f.expected + ' for 0x' + f.bits, () => {
23
+ const bits = parseInt(f.bits, 16);
24
+
25
+ assert.strictEqual(Block.calculateTarget(bits).toString('hex'), f.expected);
26
+ });
27
+ });
28
+ });
29
+
30
+ describe('fromBuffer/fromHex', () => {
31
+ fixtures.valid.forEach((f) => {
32
+ it('imports ' + f.description, () => {
33
+ const block = Block.fromHex(f.hex);
34
+
35
+ assert.strictEqual(block.version, f.version);
36
+ assert.strictEqual(block.prevHash!.toString('hex'), f.prevHash);
37
+ assert.strictEqual(block.merkleRoot!.toString('hex'), f.merkleRoot);
38
+ if (block.witnessCommit) {
39
+ assert.strictEqual(block.witnessCommit.toString('hex'), f.witnessCommit);
40
+ }
41
+ assert.strictEqual(block.timestamp, f.timestamp);
42
+ assert.strictEqual(block.bits, f.bits);
43
+ assert.strictEqual(block.nonce, f.nonce);
44
+ assert.strictEqual(!block.transactions, f.hex.length === 160);
45
+ if (f.size && f.strippedSize && f.weight) {
46
+ assert.strictEqual(block.byteLength(false, true), f.size);
47
+ assert.strictEqual(block.byteLength(false, false), f.strippedSize);
48
+ assert.strictEqual(block.weight(), f.weight);
49
+ }
50
+ });
51
+ });
52
+
53
+ fixtures.invalid.forEach((f) => {
54
+ it('throws on ' + f.exception, () => {
55
+ assert.throws(() => {
56
+ Block.fromHex(f.hex);
57
+ }, new RegExp(f.exception));
58
+ });
59
+ });
60
+ });
61
+
62
+ describe('toBuffer/toHex', () => {
63
+ fixtures.valid.forEach((f) => {
64
+ let block: Block;
65
+
66
+ beforeEach(() => {
67
+ block = Block.fromHex(f.hex);
68
+ });
69
+
70
+ it('exports ' + f.description, () => {
71
+ assert.strictEqual(block.toHex(true), f.hex.slice(0, 160));
72
+ assert.strictEqual(block.toHex(), f.hex);
73
+ });
74
+ });
75
+ });
76
+
77
+ describe('getHash/getId', () => {
78
+ fixtures.valid.forEach((f) => {
79
+ let block: Block;
80
+
81
+ beforeEach(() => {
82
+ block = Block.fromHex(f.hex);
83
+ });
84
+
85
+ it('returns ' + f.id + ' for ' + f.description, () => {
86
+ assert.strictEqual(block.getHash().toString('hex'), f.hash);
87
+ assert.strictEqual(block.getId(), f.id);
88
+ });
89
+ });
90
+ });
91
+
92
+ describe('getUTCDate', () => {
93
+ fixtures.valid.forEach((f) => {
94
+ let block: Block;
95
+
96
+ beforeEach(() => {
97
+ block = Block.fromHex(f.hex);
98
+ });
99
+
100
+ it('returns UTC date of ' + f.id, () => {
101
+ const utcDate = block.getUTCDate().getTime();
102
+
103
+ assert.strictEqual(utcDate, f.timestamp * 1e3);
104
+ });
105
+ });
106
+ });
107
+
108
+ describe('calculateMerkleRoot', () => {
109
+ it('should throw on zero-length transaction array', () => {
110
+ assert.throws(() => {
111
+ Block.calculateMerkleRoot([]);
112
+ }, /Cannot compute merkle root for zero transactions/);
113
+ });
114
+
115
+ fixtures.valid.forEach((f) => {
116
+ if (f.hex.length === 160) return;
117
+
118
+ let block: Block;
119
+
120
+ beforeEach(() => {
121
+ block = Block.fromHex(f.hex);
122
+ });
123
+
124
+ it('returns ' + f.merkleRoot + ' for ' + f.id, () => {
125
+ assert.strictEqual(
126
+ Block.calculateMerkleRoot(block.transactions!).toString('hex'),
127
+ f.merkleRoot,
128
+ );
129
+ });
130
+
131
+ if (f.witnessCommit) {
132
+ it('returns witness commit ' + f.witnessCommit + ' for ' + f.id, () => {
133
+ assert.strictEqual(
134
+ Block.calculateMerkleRoot(block.transactions!, true).toString('hex'),
135
+ f.witnessCommit,
136
+ );
137
+ });
138
+ }
139
+ });
140
+ });
141
+
142
+ describe('checkTxRoots', () => {
143
+ fixtures.valid.forEach((f) => {
144
+ if (f.hex.length === 160) return;
145
+
146
+ let block: Block;
147
+
148
+ beforeEach(() => {
149
+ block = Block.fromHex(f.hex);
150
+ });
151
+
152
+ it('returns ' + f.valid + ' for ' + f.id, () => {
153
+ assert.strictEqual(block.checkTxRoots(), true);
154
+ });
155
+ });
156
+ });
157
+
158
+ describe('checkProofOfWork', () => {
159
+ fixtures.valid.forEach((f) => {
160
+ let block: Block;
161
+
162
+ beforeEach(() => {
163
+ block = Block.fromHex(f.hex);
164
+ });
165
+
166
+ it('returns ' + f.valid + ' for ' + f.id, () => {
167
+ assert.strictEqual(block.checkProofOfWork(), f.valid);
168
+ });
169
+ });
170
+ });
171
+ });