@btc-vision/bitcoin 6.4.0 → 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.
- package/build/address.d.ts +1 -0
- package/build/address.js +56 -8
- package/build/networks.js +6 -6
- package/package.json +1 -1
- package/src/address.ts +71 -9
- package/src/block.ts +233 -233
- package/src/bufferutils.ts +188 -188
- package/src/networks.ts +6 -6
- package/src/psbt/psbtutils.ts +320 -320
- package/src/psbt.ts +2187 -2187
- package/test/address.spec.ts +155 -155
- package/test/bitcoin.core.spec.ts +212 -212
- package/test/block.spec.ts +171 -171
- package/test/bufferutils.spec.ts +450 -450
- package/test/crypto.spec.ts +49 -49
- package/test/integration/addresses.spec.ts +142 -142
- package/test/integration/bip32.spec.ts +130 -130
- package/test/integration/blocks.spec.ts +28 -28
- package/test/integration/cltv.spec.ts +241 -241
- package/test/integration/csv.spec.ts +452 -452
- package/test/integration/payments.spec.ts +110 -110
- package/test/integration/taproot.spec.ts +663 -663
- package/test/integration/transactions.spec.ts +668 -668
- package/test/payments.spec.ts +114 -114
- package/test/payments.utils.ts +165 -165
- package/test/psbt.spec.ts +1285 -1285
- package/test/script.spec.ts +186 -186
- package/test/script_number.spec.ts +26 -26
- package/test/script_signature.spec.ts +66 -66
- package/test/transaction.spec.ts +337 -337
- package/test/ts-node-register.js +7 -7
- package/test/types.spec.ts +53 -53
package/test/block.spec.ts
CHANGED
|
@@ -1,171 +1,171 @@
|
|
|
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
|
-
});
|
|
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
|
+
});
|