@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.
- 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 +2 -1
- package/build/address.js +68 -13
- 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 +91 -15
- package/src/block.ts +2 -2
- package/src/bufferutils.ts +15 -7
- package/src/index.ts +86 -86
- package/src/networks.ts +12 -0
- package/src/psbt/bip371.ts +441 -441
- package/src/psbt/psbtutils.ts +320 -319
- package/src/psbt.ts +8 -8
- package/test/address.spec.ts +55 -77
- package/test/bitcoin.core.spec.ts +47 -69
- package/test/block.spec.ts +23 -46
- package/test/bufferutils.spec.ts +32 -95
- package/test/crypto.spec.ts +9 -15
- package/test/fixtures/address.json +3 -3
- package/test/integration/addresses.spec.ts +12 -24
- package/test/integration/bip32.spec.ts +10 -31
- package/test/integration/blocks.spec.ts +2 -2
- package/test/integration/cltv.spec.ts +21 -63
- package/test/integration/csv.spec.ts +30 -105
- package/test/integration/payments.spec.ts +16 -41
- package/test/integration/taproot.spec.ts +31 -75
- package/test/integration/transactions.spec.ts +37 -138
- package/test/payments.spec.ts +95 -106
- package/test/payments.utils.ts +20 -63
- package/test/psbt.spec.ts +100 -229
- package/test/script.spec.ts +26 -50
- package/test/script_number.spec.ts +6 -9
- package/test/script_signature.spec.ts +7 -7
- package/test/transaction.spec.ts +46 -96
- package/test/ts-node-register.js +3 -1
- package/test/tsconfig.json +4 -1
- package/test/types.spec.ts +7 -12
- 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
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import ECPairFactory from 'ecpair';
|
|
1
|
+
import assert from 'assert';
|
|
2
|
+
import { ECPairFactory } from 'ecpair';
|
|
3
3
|
import * as ecc from 'tiny-secp256k1';
|
|
4
4
|
import { before, describe, it } from 'mocha';
|
|
5
|
-
import * as bitcoin from '
|
|
6
|
-
import { regtestUtils } from './_regtest';
|
|
5
|
+
import * as bitcoin from '../../src/index.js';
|
|
6
|
+
import { regtestUtils } from './_regtest.js';
|
|
7
|
+
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
import bip65 from 'bip65';
|
|
7
10
|
|
|
8
11
|
const ECPair = ECPairFactory(ecc);
|
|
9
12
|
const regtest = regtestUtils.network;
|
|
10
|
-
const bip65 = require('bip65');
|
|
11
13
|
|
|
12
14
|
function toOutputScript(address: string): Buffer {
|
|
13
15
|
return bitcoin.address.toOutputScript(address, regtest);
|
|
@@ -17,14 +19,8 @@ function idToHash(txid: string): Buffer {
|
|
|
17
19
|
return Buffer.from(txid, 'hex').reverse();
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
const alice = ECPair.fromWIF(
|
|
21
|
-
|
|
22
|
-
regtest,
|
|
23
|
-
);
|
|
24
|
-
const bob = ECPair.fromWIF(
|
|
25
|
-
'cMkopUXKWsEzAjfa1zApksGRwjVpJRB3831qM9W4gKZsLwjHXA9x',
|
|
26
|
-
regtest,
|
|
27
|
-
);
|
|
22
|
+
const alice = ECPair.fromWIF('cScfkGjbzzoeewVWmU2hYPUHeVGJRDdFt7WhmrVVGkxpmPP8BHWe', regtest);
|
|
23
|
+
const bob = ECPair.fromWIF('cMkopUXKWsEzAjfa1zApksGRwjVpJRB3831qM9W4gKZsLwjHXA9x', regtest);
|
|
28
24
|
|
|
29
25
|
describe('bitcoinjs-lib (transactions w/ CLTV)', () => {
|
|
30
26
|
// force update MTP
|
|
@@ -38,11 +34,7 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', () => {
|
|
|
38
34
|
publicKey: Buffer;
|
|
39
35
|
}
|
|
40
36
|
|
|
41
|
-
function cltvCheckSigOutput(
|
|
42
|
-
aQ: KeyPair,
|
|
43
|
-
bQ: KeyPair,
|
|
44
|
-
lockTime: number,
|
|
45
|
-
): Buffer {
|
|
37
|
+
function cltvCheckSigOutput(aQ: KeyPair, bQ: KeyPair, lockTime: number): Buffer {
|
|
46
38
|
return bitcoin.script.fromASM(
|
|
47
39
|
`
|
|
48
40
|
OP_IF
|
|
@@ -87,18 +79,11 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', () => {
|
|
|
87
79
|
tx.addOutput(toOutputScript(regtestUtils.RANDOM_ADDRESS), 7e4);
|
|
88
80
|
|
|
89
81
|
// {Alice's signature} OP_TRUE
|
|
90
|
-
const signatureHash = tx.hashForSignature(
|
|
91
|
-
0,
|
|
92
|
-
redeemScript,
|
|
93
|
-
hashType,
|
|
94
|
-
);
|
|
82
|
+
const signatureHash = tx.hashForSignature(0, redeemScript, hashType);
|
|
95
83
|
const redeemScriptSig = bitcoin.payments.p2sh({
|
|
96
84
|
redeem: {
|
|
97
85
|
input: bitcoin.script.compile([
|
|
98
|
-
bitcoin.script.signature.encode(
|
|
99
|
-
alice.sign(signatureHash),
|
|
100
|
-
hashType,
|
|
101
|
-
),
|
|
86
|
+
bitcoin.script.signature.encode(alice.sign(signatureHash), hashType),
|
|
102
87
|
bitcoin.opcodes.OP_TRUE,
|
|
103
88
|
]),
|
|
104
89
|
output: redeemScript,
|
|
@@ -140,18 +125,11 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', () => {
|
|
|
140
125
|
tx.addOutput(toOutputScript(regtestUtils.RANDOM_ADDRESS), 7e4);
|
|
141
126
|
|
|
142
127
|
// {Alice's signature} OP_TRUE
|
|
143
|
-
const signatureHash = tx.hashForSignature(
|
|
144
|
-
0,
|
|
145
|
-
redeemScript,
|
|
146
|
-
hashType,
|
|
147
|
-
);
|
|
128
|
+
const signatureHash = tx.hashForSignature(0, redeemScript, hashType);
|
|
148
129
|
const redeemScriptSig = bitcoin.payments.p2sh({
|
|
149
130
|
redeem: {
|
|
150
131
|
input: bitcoin.script.compile([
|
|
151
|
-
bitcoin.script.signature.encode(
|
|
152
|
-
alice.sign(signatureHash),
|
|
153
|
-
hashType,
|
|
154
|
-
),
|
|
132
|
+
bitcoin.script.signature.encode(alice.sign(signatureHash), hashType),
|
|
155
133
|
bitcoin.opcodes.OP_TRUE,
|
|
156
134
|
]),
|
|
157
135
|
output: redeemScript,
|
|
@@ -195,22 +173,12 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', () => {
|
|
|
195
173
|
tx.addOutput(toOutputScript(regtestUtils.RANDOM_ADDRESS), 8e4);
|
|
196
174
|
|
|
197
175
|
// {Alice's signature} {Bob's signature} OP_FALSE
|
|
198
|
-
const signatureHash = tx.hashForSignature(
|
|
199
|
-
0,
|
|
200
|
-
redeemScript,
|
|
201
|
-
hashType,
|
|
202
|
-
);
|
|
176
|
+
const signatureHash = tx.hashForSignature(0, redeemScript, hashType);
|
|
203
177
|
const redeemScriptSig = bitcoin.payments.p2sh({
|
|
204
178
|
redeem: {
|
|
205
179
|
input: bitcoin.script.compile([
|
|
206
|
-
bitcoin.script.signature.encode(
|
|
207
|
-
|
|
208
|
-
hashType,
|
|
209
|
-
),
|
|
210
|
-
bitcoin.script.signature.encode(
|
|
211
|
-
bob.sign(signatureHash),
|
|
212
|
-
hashType,
|
|
213
|
-
),
|
|
180
|
+
bitcoin.script.signature.encode(alice.sign(signatureHash), hashType),
|
|
181
|
+
bitcoin.script.signature.encode(bob.sign(signatureHash), hashType),
|
|
214
182
|
bitcoin.opcodes.OP_FALSE,
|
|
215
183
|
]),
|
|
216
184
|
output: redeemScript,
|
|
@@ -250,22 +218,12 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', () => {
|
|
|
250
218
|
tx.addOutput(toOutputScript(regtestUtils.RANDOM_ADDRESS), 1e4);
|
|
251
219
|
|
|
252
220
|
// {Alice's signature} OP_TRUE
|
|
253
|
-
const signatureHash = tx.hashForSignature(
|
|
254
|
-
0,
|
|
255
|
-
redeemScript,
|
|
256
|
-
hashType,
|
|
257
|
-
);
|
|
221
|
+
const signatureHash = tx.hashForSignature(0, redeemScript, hashType);
|
|
258
222
|
const redeemScriptSig = bitcoin.payments.p2sh({
|
|
259
223
|
redeem: {
|
|
260
224
|
input: bitcoin.script.compile([
|
|
261
|
-
bitcoin.script.signature.encode(
|
|
262
|
-
|
|
263
|
-
hashType,
|
|
264
|
-
),
|
|
265
|
-
bitcoin.script.signature.encode(
|
|
266
|
-
bob.sign(signatureHash),
|
|
267
|
-
hashType,
|
|
268
|
-
),
|
|
225
|
+
bitcoin.script.signature.encode(alice.sign(signatureHash), hashType),
|
|
226
|
+
bitcoin.script.signature.encode(bob.sign(signatureHash), hashType),
|
|
269
227
|
bitcoin.opcodes.OP_TRUE,
|
|
270
228
|
]),
|
|
271
229
|
output: redeemScript,
|
|
@@ -273,7 +231,7 @@ describe('bitcoinjs-lib (transactions w/ CLTV)', () => {
|
|
|
273
231
|
}).input;
|
|
274
232
|
tx.setInputScript(0, redeemScriptSig!);
|
|
275
233
|
|
|
276
|
-
await regtestUtils.broadcast(tx.toHex()).catch(err => {
|
|
234
|
+
await regtestUtils.broadcast(tx.toHex()).catch((err) => {
|
|
277
235
|
assert.throws(() => {
|
|
278
236
|
if (err) throw err;
|
|
279
237
|
}, /Error: non-final/);
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { PsbtInput } from 'bip174/src/lib/interfaces';
|
|
3
|
-
import ECPairFactory from 'ecpair';
|
|
1
|
+
import assert from 'assert';
|
|
2
|
+
import { PsbtInput } from 'bip174/src/lib/interfaces.js';
|
|
3
|
+
import { ECPairFactory } from 'ecpair';
|
|
4
4
|
import * as ecc from 'tiny-secp256k1';
|
|
5
5
|
import { before, 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
|
+
// @ts-ignore
|
|
10
|
+
import bip68 from 'bip68';
|
|
11
|
+
import * as varuint from 'varuint-bitcoin';
|
|
8
12
|
|
|
9
13
|
const ECPair = ECPairFactory(ecc);
|
|
10
14
|
const regtest = regtestUtils.network;
|
|
11
|
-
const bip68 = require('bip68');
|
|
12
|
-
const varuint = require('varuint-bitcoin');
|
|
13
15
|
|
|
14
16
|
function toOutputScript(address: string): Buffer {
|
|
15
17
|
return bitcoin.address.toOutputScript(address, regtest);
|
|
@@ -19,22 +21,10 @@ function idToHash(txid: string): Buffer {
|
|
|
19
21
|
return Buffer.from(txid, 'hex').reverse();
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
const alice = ECPair.fromWIF(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
);
|
|
26
|
-
const bob = ECPair.fromWIF(
|
|
27
|
-
'cMkopUXKWsEzAjfa1zApksGRwjVpJRB3831qM9W4gKZsLwjHXA9x',
|
|
28
|
-
regtest,
|
|
29
|
-
);
|
|
30
|
-
const charles = ECPair.fromWIF(
|
|
31
|
-
'cMkopUXKWsEzAjfa1zApksGRwjVpJRB3831qM9W4gKZsMSb4Ubnf',
|
|
32
|
-
regtest,
|
|
33
|
-
);
|
|
34
|
-
const dave = ECPair.fromWIF(
|
|
35
|
-
'cMkopUXKWsEzAjfa1zApksGRwjVpJRB3831qM9W4gKZsMwS4pqnx',
|
|
36
|
-
regtest,
|
|
37
|
-
);
|
|
24
|
+
const alice = ECPair.fromWIF('cScfkGjbzzoeewVWmU2hYPUHeVGJRDdFt7WhmrVVGkxpmPP8BHWe', regtest);
|
|
25
|
+
const bob = ECPair.fromWIF('cMkopUXKWsEzAjfa1zApksGRwjVpJRB3831qM9W4gKZsLwjHXA9x', regtest);
|
|
26
|
+
const charles = ECPair.fromWIF('cMkopUXKWsEzAjfa1zApksGRwjVpJRB3831qM9W4gKZsMSb4Ubnf', regtest);
|
|
27
|
+
const dave = ECPair.fromWIF('cMkopUXKWsEzAjfa1zApksGRwjVpJRB3831qM9W4gKZsMwS4pqnx', regtest);
|
|
38
28
|
|
|
39
29
|
describe('bitcoinjs-lib (transactions w/ CSV)', () => {
|
|
40
30
|
// force update MTP
|
|
@@ -49,11 +39,7 @@ describe('bitcoinjs-lib (transactions w/ CSV)', () => {
|
|
|
49
39
|
}
|
|
50
40
|
|
|
51
41
|
// IF MTP (from when confirmed) > seconds, _alice can redeem
|
|
52
|
-
function csvCheckSigOutput(
|
|
53
|
-
_alice: KeyPair,
|
|
54
|
-
_bob: KeyPair,
|
|
55
|
-
sequence: number,
|
|
56
|
-
): Buffer {
|
|
42
|
+
function csvCheckSigOutput(_alice: KeyPair, _bob: KeyPair, sequence: number): Buffer {
|
|
57
43
|
return bitcoin.script.fromASM(
|
|
58
44
|
`
|
|
59
45
|
OP_IF
|
|
@@ -197,32 +183,22 @@ describe('bitcoinjs-lib (transactions w/ CSV)', () => {
|
|
|
197
183
|
tx.addOutput(toOutputScript(regtestUtils.RANDOM_ADDRESS), 1e4);
|
|
198
184
|
|
|
199
185
|
// {Alice's signature} OP_TRUE
|
|
200
|
-
const signatureHash = tx.hashForSignature(
|
|
201
|
-
0,
|
|
202
|
-
p2sh.redeem!.output!,
|
|
203
|
-
hashType,
|
|
204
|
-
);
|
|
186
|
+
const signatureHash = tx.hashForSignature(0, p2sh.redeem!.output!, hashType);
|
|
205
187
|
const redeemScriptSig = bitcoin.payments.p2sh({
|
|
206
188
|
network: regtest,
|
|
207
189
|
redeem: {
|
|
208
190
|
network: regtest,
|
|
209
191
|
output: p2sh.redeem!.output,
|
|
210
192
|
input: bitcoin.script.compile([
|
|
211
|
-
bitcoin.script.signature.encode(
|
|
212
|
-
|
|
213
|
-
hashType,
|
|
214
|
-
),
|
|
215
|
-
bitcoin.script.signature.encode(
|
|
216
|
-
bob.sign(signatureHash),
|
|
217
|
-
hashType,
|
|
218
|
-
),
|
|
193
|
+
bitcoin.script.signature.encode(alice.sign(signatureHash), hashType),
|
|
194
|
+
bitcoin.script.signature.encode(bob.sign(signatureHash), hashType),
|
|
219
195
|
bitcoin.opcodes.OP_TRUE,
|
|
220
196
|
]),
|
|
221
197
|
},
|
|
222
198
|
}).input;
|
|
223
199
|
tx.setInputScript(0, redeemScriptSig!);
|
|
224
200
|
|
|
225
|
-
await regtestUtils.broadcast(tx.toHex()).catch(err => {
|
|
201
|
+
await regtestUtils.broadcast(tx.toHex()).catch((err: unknown) => {
|
|
226
202
|
assert.throws(() => {
|
|
227
203
|
if (err) throw err;
|
|
228
204
|
}, /Error: non-BIP68-final/);
|
|
@@ -241,14 +217,7 @@ describe('bitcoinjs-lib (transactions w/ CSV)', () => {
|
|
|
241
217
|
const sequence2 = bip68.encode({ blocks: 5 });
|
|
242
218
|
const p2sh = bitcoin.payments.p2sh({
|
|
243
219
|
redeem: {
|
|
244
|
-
output: complexCsvOutput(
|
|
245
|
-
alice,
|
|
246
|
-
bob,
|
|
247
|
-
charles,
|
|
248
|
-
dave,
|
|
249
|
-
sequence1,
|
|
250
|
-
sequence2,
|
|
251
|
-
),
|
|
220
|
+
output: complexCsvOutput(alice, bob, charles, dave, sequence1, sequence2),
|
|
252
221
|
},
|
|
253
222
|
network: regtest,
|
|
254
223
|
});
|
|
@@ -262,11 +231,7 @@ describe('bitcoinjs-lib (transactions w/ CSV)', () => {
|
|
|
262
231
|
tx.addOutput(toOutputScript(regtestUtils.RANDOM_ADDRESS), 7e4);
|
|
263
232
|
|
|
264
233
|
// OP_0 {Bob sig} {Charles sig} OP_TRUE OP_TRUE
|
|
265
|
-
const signatureHash = tx.hashForSignature(
|
|
266
|
-
0,
|
|
267
|
-
p2sh.redeem!.output!,
|
|
268
|
-
hashType,
|
|
269
|
-
);
|
|
234
|
+
const signatureHash = tx.hashForSignature(0, p2sh.redeem!.output!, hashType);
|
|
270
235
|
const redeemScriptSig = bitcoin.payments.p2sh({
|
|
271
236
|
network: regtest,
|
|
272
237
|
redeem: {
|
|
@@ -274,14 +239,8 @@ describe('bitcoinjs-lib (transactions w/ CSV)', () => {
|
|
|
274
239
|
output: p2sh.redeem!.output,
|
|
275
240
|
input: bitcoin.script.compile([
|
|
276
241
|
bitcoin.opcodes.OP_0,
|
|
277
|
-
bitcoin.script.signature.encode(
|
|
278
|
-
|
|
279
|
-
hashType,
|
|
280
|
-
),
|
|
281
|
-
bitcoin.script.signature.encode(
|
|
282
|
-
charles.sign(signatureHash),
|
|
283
|
-
hashType,
|
|
284
|
-
),
|
|
242
|
+
bitcoin.script.signature.encode(bob.sign(signatureHash), hashType),
|
|
243
|
+
bitcoin.script.signature.encode(charles.sign(signatureHash), hashType),
|
|
285
244
|
bitcoin.opcodes.OP_TRUE,
|
|
286
245
|
bitcoin.opcodes.OP_TRUE,
|
|
287
246
|
]),
|
|
@@ -311,14 +270,7 @@ describe('bitcoinjs-lib (transactions w/ CSV)', () => {
|
|
|
311
270
|
const sequence2 = bip68.encode({ blocks: 5 });
|
|
312
271
|
const p2sh = bitcoin.payments.p2sh({
|
|
313
272
|
redeem: {
|
|
314
|
-
output: complexCsvOutput(
|
|
315
|
-
alice,
|
|
316
|
-
bob,
|
|
317
|
-
charles,
|
|
318
|
-
dave,
|
|
319
|
-
sequence1,
|
|
320
|
-
sequence2,
|
|
321
|
-
),
|
|
273
|
+
output: complexCsvOutput(alice, bob, charles, dave, sequence1, sequence2),
|
|
322
274
|
},
|
|
323
275
|
network: regtest,
|
|
324
276
|
});
|
|
@@ -332,11 +284,7 @@ describe('bitcoinjs-lib (transactions w/ CSV)', () => {
|
|
|
332
284
|
tx.addOutput(toOutputScript(regtestUtils.RANDOM_ADDRESS), 7e4);
|
|
333
285
|
|
|
334
286
|
// OP_0 {Bob sig} {Alice mediator sig} OP_FALSE OP_TRUE
|
|
335
|
-
const signatureHash = tx.hashForSignature(
|
|
336
|
-
0,
|
|
337
|
-
p2sh.redeem!.output!,
|
|
338
|
-
hashType,
|
|
339
|
-
);
|
|
287
|
+
const signatureHash = tx.hashForSignature(0, p2sh.redeem!.output!, hashType);
|
|
340
288
|
const redeemScriptSig = bitcoin.payments.p2sh({
|
|
341
289
|
network: regtest,
|
|
342
290
|
redeem: {
|
|
@@ -344,14 +292,8 @@ describe('bitcoinjs-lib (transactions w/ CSV)', () => {
|
|
|
344
292
|
output: p2sh.redeem!.output,
|
|
345
293
|
input: bitcoin.script.compile([
|
|
346
294
|
bitcoin.opcodes.OP_0,
|
|
347
|
-
bitcoin.script.signature.encode(
|
|
348
|
-
|
|
349
|
-
hashType,
|
|
350
|
-
),
|
|
351
|
-
bitcoin.script.signature.encode(
|
|
352
|
-
alice.sign(signatureHash),
|
|
353
|
-
hashType,
|
|
354
|
-
),
|
|
295
|
+
bitcoin.script.signature.encode(bob.sign(signatureHash), hashType),
|
|
296
|
+
bitcoin.script.signature.encode(alice.sign(signatureHash), hashType),
|
|
355
297
|
bitcoin.opcodes.OP_0,
|
|
356
298
|
bitcoin.opcodes.OP_TRUE,
|
|
357
299
|
]),
|
|
@@ -384,14 +326,7 @@ describe('bitcoinjs-lib (transactions w/ CSV)', () => {
|
|
|
384
326
|
const sequence2 = bip68.encode({ blocks: 5 });
|
|
385
327
|
const p2sh = bitcoin.payments.p2sh({
|
|
386
328
|
redeem: {
|
|
387
|
-
output: complexCsvOutput(
|
|
388
|
-
alice,
|
|
389
|
-
bob,
|
|
390
|
-
charles,
|
|
391
|
-
dave,
|
|
392
|
-
sequence1,
|
|
393
|
-
sequence2,
|
|
394
|
-
),
|
|
329
|
+
output: complexCsvOutput(alice, bob, charles, dave, sequence1, sequence2),
|
|
395
330
|
},
|
|
396
331
|
network: regtest,
|
|
397
332
|
});
|
|
@@ -405,21 +340,14 @@ describe('bitcoinjs-lib (transactions w/ CSV)', () => {
|
|
|
405
340
|
tx.addOutput(toOutputScript(regtestUtils.RANDOM_ADDRESS), 7e4);
|
|
406
341
|
|
|
407
342
|
// {Alice mediator sig} OP_FALSE
|
|
408
|
-
const signatureHash = tx.hashForSignature(
|
|
409
|
-
0,
|
|
410
|
-
p2sh.redeem!.output!,
|
|
411
|
-
hashType,
|
|
412
|
-
);
|
|
343
|
+
const signatureHash = tx.hashForSignature(0, p2sh.redeem!.output!, hashType);
|
|
413
344
|
const redeemScriptSig = bitcoin.payments.p2sh({
|
|
414
345
|
network: regtest,
|
|
415
346
|
redeem: {
|
|
416
347
|
network: regtest,
|
|
417
348
|
output: p2sh.redeem!.output,
|
|
418
349
|
input: bitcoin.script.compile([
|
|
419
|
-
bitcoin.script.signature.encode(
|
|
420
|
-
alice.sign(signatureHash),
|
|
421
|
-
hashType,
|
|
422
|
-
),
|
|
350
|
+
bitcoin.script.signature.encode(alice.sign(signatureHash), hashType),
|
|
423
351
|
bitcoin.opcodes.OP_0,
|
|
424
352
|
]),
|
|
425
353
|
},
|
|
@@ -471,10 +399,7 @@ function csvGetFinalScripts(
|
|
|
471
399
|
output: script,
|
|
472
400
|
// This logic should be more strict and make sure the pubkeys in the
|
|
473
401
|
// meaningful script are the ones signing in the PSBT etc.
|
|
474
|
-
input: bitcoin.script.compile([
|
|
475
|
-
input.partialSig![0].signature,
|
|
476
|
-
bitcoin.opcodes.OP_TRUE,
|
|
477
|
-
]),
|
|
402
|
+
input: bitcoin.script.compile([input.partialSig![0].signature, bitcoin.opcodes.OP_TRUE]),
|
|
478
403
|
};
|
|
479
404
|
if (isP2WSH && isSegwit)
|
|
480
405
|
payment = bitcoin.payments.p2wsh({
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import ECPairFactory from 'ecpair';
|
|
1
|
+
import { ECPairFactory } from 'ecpair';
|
|
2
2
|
import * as ecc from 'tiny-secp256k1';
|
|
3
3
|
import { describe, it } from 'mocha';
|
|
4
|
-
import * as bitcoin from '
|
|
5
|
-
import { regtestUtils } from './_regtest';
|
|
4
|
+
import * as bitcoin from '../../src/index.js';
|
|
5
|
+
import { regtestUtils } from './_regtest.js';
|
|
6
|
+
import * as fs from 'node:fs';
|
|
6
7
|
|
|
7
8
|
const ECPair = ECPairFactory(ecc);
|
|
8
9
|
const NETWORK = regtestUtils.network;
|
|
9
|
-
const keyPairs = [
|
|
10
|
-
ECPair.makeRandom({ network: NETWORK }),
|
|
11
|
-
ECPair.makeRandom({ network: NETWORK }),
|
|
12
|
-
];
|
|
10
|
+
const keyPairs = [ECPair.makeRandom({ network: NETWORK }), ECPair.makeRandom({ network: NETWORK })];
|
|
13
11
|
|
|
14
12
|
async function buildAndSign(
|
|
15
13
|
depends: any,
|
|
@@ -34,26 +32,24 @@ async function buildAndSign(
|
|
|
34
32
|
});
|
|
35
33
|
|
|
36
34
|
if (depends.signatures) {
|
|
37
|
-
keyPairs.forEach(keyPair => {
|
|
35
|
+
keyPairs.forEach((keyPair) => {
|
|
38
36
|
psbt.signInput(0, keyPair);
|
|
39
37
|
});
|
|
40
38
|
} else if (depends.signature) {
|
|
41
39
|
psbt.signInput(0, keyPairs[0]);
|
|
42
40
|
}
|
|
43
41
|
|
|
44
|
-
return regtestUtils.broadcast(
|
|
45
|
-
psbt.finalizeAllInputs().extractTransaction().toHex(),
|
|
46
|
-
);
|
|
42
|
+
return regtestUtils.broadcast(psbt.finalizeAllInputs().extractTransaction().toHex());
|
|
47
43
|
}
|
|
48
44
|
|
|
49
|
-
['p2ms', 'p2pk', 'p2pkh', 'p2wpkh'].forEach(k => {
|
|
50
|
-
const fixtures =
|
|
45
|
+
['p2ms', 'p2pk', 'p2pkh', 'p2wpkh'].forEach((k) => {
|
|
46
|
+
const fixtures = JSON.parse(fs.readFileSync('test/fixtures/' + k + '.json', 'utf8'));
|
|
51
47
|
const { depends } = fixtures.dynamic;
|
|
52
48
|
const fn: any = (bitcoin.payments as any)[k];
|
|
53
49
|
|
|
54
50
|
const base: any = {};
|
|
55
51
|
if (depends.pubkey) base.pubkey = keyPairs[0].publicKey;
|
|
56
|
-
if (depends.pubkeys) base.pubkeys = keyPairs.map(x => x.publicKey);
|
|
52
|
+
if (depends.pubkeys) base.pubkeys = keyPairs.map((x) => x.publicKey);
|
|
57
53
|
if (depends.m) base.m = base.pubkeys.length;
|
|
58
54
|
|
|
59
55
|
const { output } = fn(base);
|
|
@@ -66,21 +62,14 @@ async function buildAndSign(
|
|
|
66
62
|
});
|
|
67
63
|
|
|
68
64
|
it(
|
|
69
|
-
'can (as P2SH(' +
|
|
70
|
-
k +
|
|
71
|
-
')) broadcast as an output, and be spent as an input',
|
|
65
|
+
'can (as P2SH(' + k + ')) broadcast as an output, and be spent as an input',
|
|
72
66
|
async () => {
|
|
73
67
|
const p2sh = bitcoin.payments.p2sh({
|
|
74
68
|
redeem: { output },
|
|
75
69
|
network: NETWORK,
|
|
76
70
|
});
|
|
77
71
|
Object.assign(depends, { prevOutScriptType: 'p2sh-' + k });
|
|
78
|
-
await buildAndSign(
|
|
79
|
-
depends,
|
|
80
|
-
p2sh.output,
|
|
81
|
-
p2sh.redeem!.output,
|
|
82
|
-
undefined,
|
|
83
|
-
);
|
|
72
|
+
await buildAndSign(depends, p2sh.output, p2sh.redeem!.output, undefined);
|
|
84
73
|
},
|
|
85
74
|
);
|
|
86
75
|
|
|
@@ -88,28 +77,19 @@ async function buildAndSign(
|
|
|
88
77
|
if (k === 'p2wpkh') return;
|
|
89
78
|
|
|
90
79
|
it(
|
|
91
|
-
'can (as P2WSH(' +
|
|
92
|
-
k +
|
|
93
|
-
')) broadcast as an output, and be spent as an input',
|
|
80
|
+
'can (as P2WSH(' + k + ')) broadcast as an output, and be spent as an input',
|
|
94
81
|
async () => {
|
|
95
82
|
const p2wsh = bitcoin.payments.p2wsh({
|
|
96
83
|
redeem: { output },
|
|
97
84
|
network: NETWORK,
|
|
98
85
|
});
|
|
99
86
|
Object.assign(depends, { prevOutScriptType: 'p2wsh-' + k });
|
|
100
|
-
await buildAndSign(
|
|
101
|
-
depends,
|
|
102
|
-
p2wsh.output,
|
|
103
|
-
undefined,
|
|
104
|
-
p2wsh.redeem!.output,
|
|
105
|
-
);
|
|
87
|
+
await buildAndSign(depends, p2wsh.output, undefined, p2wsh.redeem!.output);
|
|
106
88
|
},
|
|
107
89
|
);
|
|
108
90
|
|
|
109
91
|
it(
|
|
110
|
-
'can (as P2SH(P2WSH(' +
|
|
111
|
-
k +
|
|
112
|
-
'))) broadcast as an output, and be spent as an input',
|
|
92
|
+
'can (as P2SH(P2WSH(' + k + '))) broadcast as an output, and be spent as an input',
|
|
113
93
|
async () => {
|
|
114
94
|
const p2wsh = bitcoin.payments.p2wsh({
|
|
115
95
|
redeem: { output },
|
|
@@ -123,12 +103,7 @@ async function buildAndSign(
|
|
|
123
103
|
Object.assign(depends, {
|
|
124
104
|
prevOutScriptType: 'p2sh-p2wsh-' + k,
|
|
125
105
|
});
|
|
126
|
-
await buildAndSign(
|
|
127
|
-
depends,
|
|
128
|
-
p2sh.output,
|
|
129
|
-
p2sh.redeem!.output,
|
|
130
|
-
p2wsh.redeem!.output,
|
|
131
|
-
);
|
|
106
|
+
await buildAndSign(depends, p2sh.output, p2sh.redeem!.output, p2wsh.redeem!.output);
|
|
132
107
|
},
|
|
133
108
|
);
|
|
134
109
|
});
|