@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.
Files changed (71) 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/build/address.d.ts +1 -1
  7. package/build/address.js +12 -5
  8. package/build/block.js +2 -2
  9. package/build/bufferutils.js +5 -5
  10. package/build/networks.d.ts +1 -0
  11. package/build/networks.js +11 -0
  12. package/build/psbt/psbtutils.js +2 -2
  13. package/build/psbt.js +3 -7
  14. package/package.json +26 -26
  15. package/src/address.ts +20 -6
  16. package/src/block.ts +233 -233
  17. package/src/bufferutils.ts +188 -180
  18. package/src/index.ts +86 -86
  19. package/src/networks.ts +12 -0
  20. package/src/psbt/bip371.ts +441 -441
  21. package/src/psbt/psbtutils.ts +4 -3
  22. package/src/psbt.ts +2187 -2187
  23. package/test/address.spec.ts +155 -177
  24. package/test/bitcoin.core.spec.ts +212 -234
  25. package/test/block.spec.ts +171 -194
  26. package/test/bufferutils.spec.ts +450 -513
  27. package/test/crypto.spec.ts +49 -55
  28. package/test/fixtures/address.json +3 -3
  29. package/test/integration/addresses.spec.ts +142 -154
  30. package/test/integration/bip32.spec.ts +130 -151
  31. package/test/integration/blocks.spec.ts +28 -28
  32. package/test/integration/cltv.spec.ts +241 -283
  33. package/test/integration/csv.spec.ts +452 -527
  34. package/test/integration/payments.spec.ts +110 -135
  35. package/test/integration/taproot.spec.ts +663 -707
  36. package/test/integration/transactions.spec.ts +668 -769
  37. package/test/payments.spec.ts +114 -125
  38. package/test/payments.utils.ts +165 -208
  39. package/test/psbt.spec.ts +1285 -1414
  40. package/test/script.spec.ts +186 -210
  41. package/test/script_number.spec.ts +26 -29
  42. package/test/script_signature.spec.ts +66 -66
  43. package/test/transaction.spec.ts +337 -387
  44. package/test/ts-node-register.js +7 -5
  45. package/test/tsconfig.json +4 -1
  46. package/test/types.spec.ts +53 -58
  47. package/.nyc_output/6368a5b2-daa5-4821-8ed0-b742d6fc7eab.json +0 -1
  48. package/.nyc_output/processinfo/6368a5b2-daa5-4821-8ed0-b742d6fc7eab.json +0 -1
  49. package/.nyc_output/processinfo/index.json +0 -1
  50. package/test/address.spec.js +0 -124
  51. package/test/bitcoin.core.spec.js +0 -170
  52. package/test/block.spec.js +0 -141
  53. package/test/bufferutils.spec.js +0 -427
  54. package/test/crypto.spec.js +0 -41
  55. package/test/integration/_regtest.js +0 -7
  56. package/test/integration/addresses.spec.js +0 -116
  57. package/test/integration/bip32.spec.js +0 -85
  58. package/test/integration/blocks.spec.js +0 -26
  59. package/test/integration/cltv.spec.js +0 -199
  60. package/test/integration/csv.spec.js +0 -362
  61. package/test/integration/payments.spec.js +0 -98
  62. package/test/integration/taproot.spec.js +0 -532
  63. package/test/integration/transactions.spec.js +0 -561
  64. package/test/payments.spec.js +0 -97
  65. package/test/payments.utils.js +0 -190
  66. package/test/psbt.spec.js +0 -1044
  67. package/test/script.spec.js +0 -151
  68. package/test/script_number.spec.js +0 -24
  69. package/test/script_signature.spec.js +0 -52
  70. package/test/transaction.spec.js +0 -269
  71. package/test/types.spec.js +0 -46
@@ -1,283 +1,241 @@
1
- import * as assert from 'assert';
2
- import ECPairFactory from 'ecpair';
3
- import * as ecc from 'tiny-secp256k1';
4
- import { before, describe, it } from 'mocha';
5
- import * as bitcoin from '../..';
6
- import { regtestUtils } from './_regtest';
7
-
8
- const ECPair = ECPairFactory(ecc);
9
- const regtest = regtestUtils.network;
10
- const bip65 = require('bip65');
11
-
12
- function toOutputScript(address: string): Buffer {
13
- return bitcoin.address.toOutputScript(address, regtest);
14
- }
15
-
16
- function idToHash(txid: string): Buffer {
17
- return Buffer.from(txid, 'hex').reverse();
18
- }
19
-
20
- const alice = ECPair.fromWIF(
21
- 'cScfkGjbzzoeewVWmU2hYPUHeVGJRDdFt7WhmrVVGkxpmPP8BHWe',
22
- regtest,
23
- );
24
- const bob = ECPair.fromWIF(
25
- 'cMkopUXKWsEzAjfa1zApksGRwjVpJRB3831qM9W4gKZsLwjHXA9x',
26
- regtest,
27
- );
28
-
29
- describe('bitcoinjs-lib (transactions w/ CLTV)', () => {
30
- // force update MTP
31
- before(async () => {
32
- await regtestUtils.mine(11);
33
- });
34
-
35
- const hashType = bitcoin.Transaction.SIGHASH_ALL;
36
-
37
- interface KeyPair {
38
- publicKey: Buffer;
39
- }
40
-
41
- function cltvCheckSigOutput(
42
- aQ: KeyPair,
43
- bQ: KeyPair,
44
- lockTime: number,
45
- ): Buffer {
46
- return bitcoin.script.fromASM(
47
- `
48
- OP_IF
49
- ${bitcoin.script.number.encode(lockTime).toString('hex')}
50
- OP_CHECKLOCKTIMEVERIFY
51
- OP_DROP
52
- OP_ELSE
53
- ${bQ.publicKey.toString('hex')}
54
- OP_CHECKSIGVERIFY
55
- OP_ENDIF
56
- ${aQ.publicKey.toString('hex')}
57
- OP_CHECKSIG
58
- `
59
- .trim()
60
- .replace(/\s+/g, ' '),
61
- );
62
- }
63
-
64
- function utcNow(): number {
65
- return Math.floor(Date.now() / 1000);
66
- }
67
-
68
- // expiry past, {Alice's signature} OP_TRUE
69
- it(
70
- 'can create (and broadcast via 3PBP) a Transaction where Alice can redeem ' +
71
- 'the output after the expiry (in the past)',
72
- async () => {
73
- // 3 hours ago
74
- const lockTime = bip65.encode({ utc: utcNow() - 3600 * 3 });
75
- const redeemScript = cltvCheckSigOutput(alice, bob, lockTime);
76
- const { address } = bitcoin.payments.p2sh({
77
- redeem: { output: redeemScript, network: regtest },
78
- network: regtest,
79
- });
80
-
81
- // fund the P2SH(CLTV) address
82
- const unspent = await regtestUtils.faucet(address!, 1e5);
83
- const tx = new bitcoin.Transaction();
84
- tx.locktime = lockTime;
85
- // Note: nSequence MUST be <= 0xfffffffe otherwise OP_CHECKLOCKTIMEVERIFY will fail.
86
- tx.addInput(idToHash(unspent.txId), unspent.vout, 0xfffffffe);
87
- tx.addOutput(toOutputScript(regtestUtils.RANDOM_ADDRESS), 7e4);
88
-
89
- // {Alice's signature} OP_TRUE
90
- const signatureHash = tx.hashForSignature(
91
- 0,
92
- redeemScript,
93
- hashType,
94
- );
95
- const redeemScriptSig = bitcoin.payments.p2sh({
96
- redeem: {
97
- input: bitcoin.script.compile([
98
- bitcoin.script.signature.encode(
99
- alice.sign(signatureHash),
100
- hashType,
101
- ),
102
- bitcoin.opcodes.OP_TRUE,
103
- ]),
104
- output: redeemScript,
105
- },
106
- }).input;
107
- tx.setInputScript(0, redeemScriptSig!);
108
-
109
- await regtestUtils.broadcast(tx.toHex());
110
-
111
- await regtestUtils.verify({
112
- txId: tx.getId(),
113
- address: regtestUtils.RANDOM_ADDRESS,
114
- vout: 0,
115
- value: 7e4,
116
- });
117
- },
118
- );
119
-
120
- // expiry will pass, {Alice's signature} OP_TRUE
121
- it(
122
- 'can create (and broadcast via 3PBP) a Transaction where Alice can redeem ' +
123
- 'the output after the expiry (in the future)',
124
- async () => {
125
- const height = await regtestUtils.height();
126
- // 5 blocks from now
127
- const lockTime = bip65.encode({ blocks: height + 5 });
128
- const redeemScript = cltvCheckSigOutput(alice, bob, lockTime);
129
- const { address } = bitcoin.payments.p2sh({
130
- redeem: { output: redeemScript, network: regtest },
131
- network: regtest,
132
- });
133
-
134
- // fund the P2SH(CLTV) address
135
- const unspent = await regtestUtils.faucet(address!, 1e5);
136
- const tx = new bitcoin.Transaction();
137
- tx.locktime = lockTime;
138
- // Note: nSequence MUST be <= 0xfffffffe otherwise OP_CHECKLOCKTIMEVERIFY will fail.
139
- tx.addInput(idToHash(unspent.txId), unspent.vout, 0xfffffffe);
140
- tx.addOutput(toOutputScript(regtestUtils.RANDOM_ADDRESS), 7e4);
141
-
142
- // {Alice's signature} OP_TRUE
143
- const signatureHash = tx.hashForSignature(
144
- 0,
145
- redeemScript,
146
- hashType,
147
- );
148
- const redeemScriptSig = bitcoin.payments.p2sh({
149
- redeem: {
150
- input: bitcoin.script.compile([
151
- bitcoin.script.signature.encode(
152
- alice.sign(signatureHash),
153
- hashType,
154
- ),
155
- bitcoin.opcodes.OP_TRUE,
156
- ]),
157
- output: redeemScript,
158
- },
159
- }).input;
160
- tx.setInputScript(0, redeemScriptSig!);
161
-
162
- // TODO: test that it failures _prior_ to expiry, unfortunately, race conditions when run concurrently
163
- // ...
164
- // into the future!
165
- await regtestUtils.mine(5);
166
- await regtestUtils.broadcast(tx.toHex());
167
- await regtestUtils.verify({
168
- txId: tx.getId(),
169
- address: regtestUtils.RANDOM_ADDRESS,
170
- vout: 0,
171
- value: 7e4,
172
- });
173
- },
174
- );
175
-
176
- // expiry ignored, {Bob's signature} {Alice's signature} OP_FALSE
177
- it(
178
- 'can create (and broadcast via 3PBP) a Transaction where Alice and Bob can ' +
179
- 'redeem the output at any time',
180
- async () => {
181
- // two hours ago
182
- const lockTime = bip65.encode({ utc: utcNow() - 3600 * 2 });
183
- const redeemScript = cltvCheckSigOutput(alice, bob, lockTime);
184
- const { address } = bitcoin.payments.p2sh({
185
- redeem: { output: redeemScript, network: regtest },
186
- network: regtest,
187
- });
188
-
189
- // fund the P2SH(CLTV) address
190
- const unspent = await regtestUtils.faucet(address!, 2e5);
191
- const tx = new bitcoin.Transaction();
192
- tx.locktime = lockTime;
193
- // Note: nSequence MUST be <= 0xfffffffe otherwise OP_CHECKLOCKTIMEVERIFY will fail.
194
- tx.addInput(idToHash(unspent.txId), unspent.vout, 0xfffffffe);
195
- tx.addOutput(toOutputScript(regtestUtils.RANDOM_ADDRESS), 8e4);
196
-
197
- // {Alice's signature} {Bob's signature} OP_FALSE
198
- const signatureHash = tx.hashForSignature(
199
- 0,
200
- redeemScript,
201
- hashType,
202
- );
203
- const redeemScriptSig = bitcoin.payments.p2sh({
204
- redeem: {
205
- input: bitcoin.script.compile([
206
- bitcoin.script.signature.encode(
207
- alice.sign(signatureHash),
208
- hashType,
209
- ),
210
- bitcoin.script.signature.encode(
211
- bob.sign(signatureHash),
212
- hashType,
213
- ),
214
- bitcoin.opcodes.OP_FALSE,
215
- ]),
216
- output: redeemScript,
217
- },
218
- }).input;
219
- tx.setInputScript(0, redeemScriptSig!);
220
-
221
- await regtestUtils.broadcast(tx.toHex());
222
- await regtestUtils.verify({
223
- txId: tx.getId(),
224
- address: regtestUtils.RANDOM_ADDRESS,
225
- vout: 0,
226
- value: 8e4,
227
- });
228
- },
229
- );
230
-
231
- // expiry in the future, {Alice's signature} OP_TRUE
232
- it(
233
- 'can create (but fail to broadcast via 3PBP) a Transaction where Alice ' +
234
- 'attempts to redeem before the expiry',
235
- async () => {
236
- // two hours from now
237
- const lockTime = bip65.encode({ utc: utcNow() + 3600 * 2 });
238
- const redeemScript = cltvCheckSigOutput(alice, bob, lockTime);
239
- const { address } = bitcoin.payments.p2sh({
240
- redeem: { output: redeemScript, network: regtest },
241
- network: regtest,
242
- });
243
-
244
- // fund the P2SH(CLTV) address
245
- const unspent = await regtestUtils.faucet(address!, 2e4);
246
- const tx = new bitcoin.Transaction();
247
- tx.locktime = lockTime;
248
- // Note: nSequence MUST be <= 0xfffffffe otherwise OP_CHECKLOCKTIMEVERIFY will fail.
249
- tx.addInput(idToHash(unspent.txId), unspent.vout, 0xfffffffe);
250
- tx.addOutput(toOutputScript(regtestUtils.RANDOM_ADDRESS), 1e4);
251
-
252
- // {Alice's signature} OP_TRUE
253
- const signatureHash = tx.hashForSignature(
254
- 0,
255
- redeemScript,
256
- hashType,
257
- );
258
- const redeemScriptSig = bitcoin.payments.p2sh({
259
- redeem: {
260
- input: bitcoin.script.compile([
261
- bitcoin.script.signature.encode(
262
- alice.sign(signatureHash),
263
- hashType,
264
- ),
265
- bitcoin.script.signature.encode(
266
- bob.sign(signatureHash),
267
- hashType,
268
- ),
269
- bitcoin.opcodes.OP_TRUE,
270
- ]),
271
- output: redeemScript,
272
- },
273
- }).input;
274
- tx.setInputScript(0, redeemScriptSig!);
275
-
276
- await regtestUtils.broadcast(tx.toHex()).catch(err => {
277
- assert.throws(() => {
278
- if (err) throw err;
279
- }, /Error: non-final/);
280
- });
281
- },
282
- );
283
- });
1
+ import assert from 'assert';
2
+ import { ECPairFactory } from 'ecpair';
3
+ import * as ecc from 'tiny-secp256k1';
4
+ import { before, describe, it } from 'mocha';
5
+ import * as bitcoin from '../../src/index.js';
6
+ import { regtestUtils } from './_regtest.js';
7
+
8
+ // @ts-ignore
9
+ import bip65 from 'bip65';
10
+
11
+ const ECPair = ECPairFactory(ecc);
12
+ const regtest = regtestUtils.network;
13
+
14
+ function toOutputScript(address: string): Buffer {
15
+ return bitcoin.address.toOutputScript(address, regtest);
16
+ }
17
+
18
+ function idToHash(txid: string): Buffer {
19
+ return Buffer.from(txid, 'hex').reverse();
20
+ }
21
+
22
+ const alice = ECPair.fromWIF('cScfkGjbzzoeewVWmU2hYPUHeVGJRDdFt7WhmrVVGkxpmPP8BHWe', regtest);
23
+ const bob = ECPair.fromWIF('cMkopUXKWsEzAjfa1zApksGRwjVpJRB3831qM9W4gKZsLwjHXA9x', regtest);
24
+
25
+ describe('bitcoinjs-lib (transactions w/ CLTV)', () => {
26
+ // force update MTP
27
+ before(async () => {
28
+ await regtestUtils.mine(11);
29
+ });
30
+
31
+ const hashType = bitcoin.Transaction.SIGHASH_ALL;
32
+
33
+ interface KeyPair {
34
+ publicKey: Buffer;
35
+ }
36
+
37
+ function cltvCheckSigOutput(aQ: KeyPair, bQ: KeyPair, lockTime: number): Buffer {
38
+ return bitcoin.script.fromASM(
39
+ `
40
+ OP_IF
41
+ ${bitcoin.script.number.encode(lockTime).toString('hex')}
42
+ OP_CHECKLOCKTIMEVERIFY
43
+ OP_DROP
44
+ OP_ELSE
45
+ ${bQ.publicKey.toString('hex')}
46
+ OP_CHECKSIGVERIFY
47
+ OP_ENDIF
48
+ ${aQ.publicKey.toString('hex')}
49
+ OP_CHECKSIG
50
+ `
51
+ .trim()
52
+ .replace(/\s+/g, ' '),
53
+ );
54
+ }
55
+
56
+ function utcNow(): number {
57
+ return Math.floor(Date.now() / 1000);
58
+ }
59
+
60
+ // expiry past, {Alice's signature} OP_TRUE
61
+ it(
62
+ 'can create (and broadcast via 3PBP) a Transaction where Alice can redeem ' +
63
+ 'the output after the expiry (in the past)',
64
+ async () => {
65
+ // 3 hours ago
66
+ const lockTime = bip65.encode({ utc: utcNow() - 3600 * 3 });
67
+ const redeemScript = cltvCheckSigOutput(alice, bob, lockTime);
68
+ const { address } = bitcoin.payments.p2sh({
69
+ redeem: { output: redeemScript, network: regtest },
70
+ network: regtest,
71
+ });
72
+
73
+ // fund the P2SH(CLTV) address
74
+ const unspent = await regtestUtils.faucet(address!, 1e5);
75
+ const tx = new bitcoin.Transaction();
76
+ tx.locktime = lockTime;
77
+ // Note: nSequence MUST be <= 0xfffffffe otherwise OP_CHECKLOCKTIMEVERIFY will fail.
78
+ tx.addInput(idToHash(unspent.txId), unspent.vout, 0xfffffffe);
79
+ tx.addOutput(toOutputScript(regtestUtils.RANDOM_ADDRESS), 7e4);
80
+
81
+ // {Alice's signature} OP_TRUE
82
+ const signatureHash = tx.hashForSignature(0, redeemScript, hashType);
83
+ const redeemScriptSig = bitcoin.payments.p2sh({
84
+ redeem: {
85
+ input: bitcoin.script.compile([
86
+ bitcoin.script.signature.encode(alice.sign(signatureHash), hashType),
87
+ bitcoin.opcodes.OP_TRUE,
88
+ ]),
89
+ output: redeemScript,
90
+ },
91
+ }).input;
92
+ tx.setInputScript(0, redeemScriptSig!);
93
+
94
+ await regtestUtils.broadcast(tx.toHex());
95
+
96
+ await regtestUtils.verify({
97
+ txId: tx.getId(),
98
+ address: regtestUtils.RANDOM_ADDRESS,
99
+ vout: 0,
100
+ value: 7e4,
101
+ });
102
+ },
103
+ );
104
+
105
+ // expiry will pass, {Alice's signature} OP_TRUE
106
+ it(
107
+ 'can create (and broadcast via 3PBP) a Transaction where Alice can redeem ' +
108
+ 'the output after the expiry (in the future)',
109
+ async () => {
110
+ const height = await regtestUtils.height();
111
+ // 5 blocks from now
112
+ const lockTime = bip65.encode({ blocks: height + 5 });
113
+ const redeemScript = cltvCheckSigOutput(alice, bob, lockTime);
114
+ const { address } = bitcoin.payments.p2sh({
115
+ redeem: { output: redeemScript, network: regtest },
116
+ network: regtest,
117
+ });
118
+
119
+ // fund the P2SH(CLTV) address
120
+ const unspent = await regtestUtils.faucet(address!, 1e5);
121
+ const tx = new bitcoin.Transaction();
122
+ tx.locktime = lockTime;
123
+ // Note: nSequence MUST be <= 0xfffffffe otherwise OP_CHECKLOCKTIMEVERIFY will fail.
124
+ tx.addInput(idToHash(unspent.txId), unspent.vout, 0xfffffffe);
125
+ tx.addOutput(toOutputScript(regtestUtils.RANDOM_ADDRESS), 7e4);
126
+
127
+ // {Alice's signature} OP_TRUE
128
+ const signatureHash = tx.hashForSignature(0, redeemScript, hashType);
129
+ const redeemScriptSig = bitcoin.payments.p2sh({
130
+ redeem: {
131
+ input: bitcoin.script.compile([
132
+ bitcoin.script.signature.encode(alice.sign(signatureHash), hashType),
133
+ bitcoin.opcodes.OP_TRUE,
134
+ ]),
135
+ output: redeemScript,
136
+ },
137
+ }).input;
138
+ tx.setInputScript(0, redeemScriptSig!);
139
+
140
+ // TODO: test that it failures _prior_ to expiry, unfortunately, race conditions when run concurrently
141
+ // ...
142
+ // into the future!
143
+ await regtestUtils.mine(5);
144
+ await regtestUtils.broadcast(tx.toHex());
145
+ await regtestUtils.verify({
146
+ txId: tx.getId(),
147
+ address: regtestUtils.RANDOM_ADDRESS,
148
+ vout: 0,
149
+ value: 7e4,
150
+ });
151
+ },
152
+ );
153
+
154
+ // expiry ignored, {Bob's signature} {Alice's signature} OP_FALSE
155
+ it(
156
+ 'can create (and broadcast via 3PBP) a Transaction where Alice and Bob can ' +
157
+ 'redeem the output at any time',
158
+ async () => {
159
+ // two hours ago
160
+ const lockTime = bip65.encode({ utc: utcNow() - 3600 * 2 });
161
+ const redeemScript = cltvCheckSigOutput(alice, bob, lockTime);
162
+ const { address } = bitcoin.payments.p2sh({
163
+ redeem: { output: redeemScript, network: regtest },
164
+ network: regtest,
165
+ });
166
+
167
+ // fund the P2SH(CLTV) address
168
+ const unspent = await regtestUtils.faucet(address!, 2e5);
169
+ const tx = new bitcoin.Transaction();
170
+ tx.locktime = lockTime;
171
+ // Note: nSequence MUST be <= 0xfffffffe otherwise OP_CHECKLOCKTIMEVERIFY will fail.
172
+ tx.addInput(idToHash(unspent.txId), unspent.vout, 0xfffffffe);
173
+ tx.addOutput(toOutputScript(regtestUtils.RANDOM_ADDRESS), 8e4);
174
+
175
+ // {Alice's signature} {Bob's signature} OP_FALSE
176
+ const signatureHash = tx.hashForSignature(0, redeemScript, hashType);
177
+ const redeemScriptSig = bitcoin.payments.p2sh({
178
+ redeem: {
179
+ input: bitcoin.script.compile([
180
+ bitcoin.script.signature.encode(alice.sign(signatureHash), hashType),
181
+ bitcoin.script.signature.encode(bob.sign(signatureHash), hashType),
182
+ bitcoin.opcodes.OP_FALSE,
183
+ ]),
184
+ output: redeemScript,
185
+ },
186
+ }).input;
187
+ tx.setInputScript(0, redeemScriptSig!);
188
+
189
+ await regtestUtils.broadcast(tx.toHex());
190
+ await regtestUtils.verify({
191
+ txId: tx.getId(),
192
+ address: regtestUtils.RANDOM_ADDRESS,
193
+ vout: 0,
194
+ value: 8e4,
195
+ });
196
+ },
197
+ );
198
+
199
+ // expiry in the future, {Alice's signature} OP_TRUE
200
+ it(
201
+ 'can create (but fail to broadcast via 3PBP) a Transaction where Alice ' +
202
+ 'attempts to redeem before the expiry',
203
+ async () => {
204
+ // two hours from now
205
+ const lockTime = bip65.encode({ utc: utcNow() + 3600 * 2 });
206
+ const redeemScript = cltvCheckSigOutput(alice, bob, lockTime);
207
+ const { address } = bitcoin.payments.p2sh({
208
+ redeem: { output: redeemScript, network: regtest },
209
+ network: regtest,
210
+ });
211
+
212
+ // fund the P2SH(CLTV) address
213
+ const unspent = await regtestUtils.faucet(address!, 2e4);
214
+ const tx = new bitcoin.Transaction();
215
+ tx.locktime = lockTime;
216
+ // Note: nSequence MUST be <= 0xfffffffe otherwise OP_CHECKLOCKTIMEVERIFY will fail.
217
+ tx.addInput(idToHash(unspent.txId), unspent.vout, 0xfffffffe);
218
+ tx.addOutput(toOutputScript(regtestUtils.RANDOM_ADDRESS), 1e4);
219
+
220
+ // {Alice's signature} OP_TRUE
221
+ const signatureHash = tx.hashForSignature(0, redeemScript, hashType);
222
+ const redeemScriptSig = bitcoin.payments.p2sh({
223
+ redeem: {
224
+ input: bitcoin.script.compile([
225
+ bitcoin.script.signature.encode(alice.sign(signatureHash), hashType),
226
+ bitcoin.script.signature.encode(bob.sign(signatureHash), hashType),
227
+ bitcoin.opcodes.OP_TRUE,
228
+ ]),
229
+ output: redeemScript,
230
+ },
231
+ }).input;
232
+ tx.setInputScript(0, redeemScriptSig!);
233
+
234
+ await regtestUtils.broadcast(tx.toHex()).catch((err) => {
235
+ assert.throws(() => {
236
+ if (err) throw err;
237
+ }, /Error: non-final/);
238
+ });
239
+ },
240
+ );
241
+ });