@btc-vision/bitcoin 6.3.6 → 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.
- package/.mocharc.json +13 -0
- package/browser/address.d.ts +1 -1
- package/browser/index.js +1 -1
- package/browser/index.js.LICENSE.txt +3 -3
- package/browser/networks.d.ts +1 -0
- package/build/address.d.ts +1 -1
- package/build/address.js +12 -5
- package/build/block.js +2 -2
- package/build/bufferutils.js +5 -5
- package/build/networks.d.ts +1 -0
- package/build/networks.js +11 -0
- package/build/psbt/psbtutils.js +2 -2
- package/build/psbt.js +3 -7
- package/package.json +26 -26
- package/src/address.ts +20 -6
- package/src/block.ts +233 -233
- package/src/bufferutils.ts +188 -180
- package/src/index.ts +86 -86
- package/src/networks.ts +12 -0
- package/src/psbt/bip371.ts +441 -441
- package/src/psbt/psbtutils.ts +4 -3
- package/src/psbt.ts +2187 -2187
- package/test/address.spec.ts +155 -177
- package/test/bitcoin.core.spec.ts +212 -234
- package/test/block.spec.ts +171 -194
- package/test/bufferutils.spec.ts +450 -513
- package/test/crypto.spec.ts +49 -55
- package/test/fixtures/address.json +3 -3
- package/test/integration/addresses.spec.ts +142 -154
- package/test/integration/bip32.spec.ts +130 -151
- package/test/integration/blocks.spec.ts +28 -28
- package/test/integration/cltv.spec.ts +241 -283
- package/test/integration/csv.spec.ts +452 -527
- package/test/integration/payments.spec.ts +110 -135
- package/test/integration/taproot.spec.ts +663 -707
- package/test/integration/transactions.spec.ts +668 -769
- package/test/payments.spec.ts +114 -125
- package/test/payments.utils.ts +165 -208
- package/test/psbt.spec.ts +1285 -1414
- package/test/script.spec.ts +186 -210
- package/test/script_number.spec.ts +26 -29
- package/test/script_signature.spec.ts +66 -66
- package/test/transaction.spec.ts +337 -387
- package/test/ts-node-register.js +7 -5
- package/test/tsconfig.json +4 -1
- package/test/types.spec.ts +53 -58
- package/.nyc_output/6368a5b2-daa5-4821-8ed0-b742d6fc7eab.json +0 -1
- package/.nyc_output/processinfo/6368a5b2-daa5-4821-8ed0-b742d6fc7eab.json +0 -1
- package/.nyc_output/processinfo/index.json +0 -1
- package/test/address.spec.js +0 -124
- package/test/bitcoin.core.spec.js +0 -170
- package/test/block.spec.js +0 -141
- package/test/bufferutils.spec.js +0 -427
- package/test/crypto.spec.js +0 -41
- package/test/integration/_regtest.js +0 -7
- package/test/integration/addresses.spec.js +0 -116
- package/test/integration/bip32.spec.js +0 -85
- package/test/integration/blocks.spec.js +0 -26
- package/test/integration/cltv.spec.js +0 -199
- package/test/integration/csv.spec.js +0 -362
- package/test/integration/payments.spec.js +0 -98
- package/test/integration/taproot.spec.js +0 -532
- package/test/integration/transactions.spec.js +0 -561
- package/test/payments.spec.js +0 -97
- package/test/payments.utils.js +0 -190
- package/test/psbt.spec.js +0 -1044
- package/test/script.spec.js +0 -151
- package/test/script_number.spec.js +0 -24
- package/test/script_signature.spec.js +0 -52
- package/test/transaction.spec.js +0 -269
- package/test/types.spec.js +0 -46
package/test/block.spec.ts
CHANGED
|
@@ -1,194 +1,171 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { beforeEach, describe, it } from 'mocha';
|
|
3
|
-
import { Block } from '
|
|
4
|
-
|
|
5
|
-
import
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
+
});
|