@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.
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 +2 -1
  7. package/build/address.js +68 -13
  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 +91 -15
  16. package/src/block.ts +2 -2
  17. package/src/bufferutils.ts +15 -7
  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 +320 -319
  22. package/src/psbt.ts +8 -8
  23. package/test/address.spec.ts +55 -77
  24. package/test/bitcoin.core.spec.ts +47 -69
  25. package/test/block.spec.ts +23 -46
  26. package/test/bufferutils.spec.ts +32 -95
  27. package/test/crypto.spec.ts +9 -15
  28. package/test/fixtures/address.json +3 -3
  29. package/test/integration/addresses.spec.ts +12 -24
  30. package/test/integration/bip32.spec.ts +10 -31
  31. package/test/integration/blocks.spec.ts +2 -2
  32. package/test/integration/cltv.spec.ts +21 -63
  33. package/test/integration/csv.spec.ts +30 -105
  34. package/test/integration/payments.spec.ts +16 -41
  35. package/test/integration/taproot.spec.ts +31 -75
  36. package/test/integration/transactions.spec.ts +37 -138
  37. package/test/payments.spec.ts +95 -106
  38. package/test/payments.utils.ts +20 -63
  39. package/test/psbt.spec.ts +100 -229
  40. package/test/script.spec.ts +26 -50
  41. package/test/script_number.spec.ts +6 -9
  42. package/test/script_signature.spec.ts +7 -7
  43. package/test/transaction.spec.ts +46 -96
  44. package/test/ts-node-register.js +3 -1
  45. package/test/tsconfig.json +4 -1
  46. package/test/types.spec.ts +7 -12
  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,9 +1,10 @@
1
- import * as assert from 'assert';
1
+ import assert from 'assert';
2
2
  import { describe, it } from 'mocha';
3
- import * as bscript from '../src/script';
4
- import * as fixtures from './fixtures/script.json';
3
+ import * as bscript from '../src/script.js';
4
+ import fixtures from './fixtures/script.json' with { type: 'json' };
5
5
 
6
- const minimalData = require('minimaldata');
6
+ // @ts-ignore
7
+ import minimalData from 'minimaldata';
7
8
 
8
9
  describe('script', () => {
9
10
  // TODO
@@ -13,26 +14,24 @@ describe('script', () => {
13
14
  });
14
15
  it('rejects smaller than 33', () => {
15
16
  for (let i = 0; i < 33; i++) {
16
- assert.strictEqual(
17
- false,
18
- bscript.isCanonicalPubKey(Buffer.allocUnsafe(i)),
19
- );
17
+ assert.strictEqual(false, bscript.isCanonicalPubKey(Buffer.allocUnsafe(i)));
20
18
  }
21
19
  });
22
20
  });
21
+
23
22
  describe.skip('isCanonicalScriptSignature', () => {
24
23
  assert.ok(true);
25
24
  });
26
25
 
27
26
  describe('fromASM/toASM', () => {
28
- fixtures.valid.forEach(f => {
27
+ fixtures.valid.forEach((f) => {
29
28
  it('encodes/decodes ' + f.asm, () => {
30
29
  const script = bscript.fromASM(f.asm);
31
30
  assert.strictEqual(bscript.toASM(script), f.asm);
32
31
  });
33
32
  });
34
33
 
35
- fixtures.invalid.fromASM.forEach(f => {
34
+ fixtures.invalid.fromASM.forEach((f) => {
36
35
  it('throws ' + f.description, () => {
37
36
  assert.throws(() => {
38
37
  bscript.fromASM(f.script);
@@ -57,7 +56,7 @@ describe('script', () => {
57
56
  });
58
57
 
59
58
  describe('fromASM/toASM (templates)', () => {
60
- fixtures.valid2.forEach(f => {
59
+ fixtures.valid2.forEach((f) => {
61
60
  if (f.inputHex) {
62
61
  const ih = bscript.toASM(Buffer.from(f.inputHex, 'hex'));
63
62
 
@@ -79,7 +78,7 @@ describe('script', () => {
79
78
  });
80
79
 
81
80
  describe('isPushOnly', () => {
82
- fixtures.valid.forEach(f => {
81
+ fixtures.valid.forEach((f) => {
83
82
  it('returns ' + !!f.stack + ' for ' + f.asm, () => {
84
83
  const script = bscript.fromASM(f.asm);
85
84
  const chunks = bscript.decompile(script);
@@ -90,7 +89,7 @@ describe('script', () => {
90
89
  });
91
90
 
92
91
  describe('toStack', () => {
93
- fixtures.valid.forEach(f => {
92
+ fixtures.valid.forEach((f) => {
94
93
  it('returns ' + !!f.stack + ' for ' + f.asm, () => {
95
94
  if (!f.stack || !f.asm) return;
96
95
 
@@ -98,7 +97,7 @@ describe('script', () => {
98
97
 
99
98
  const stack = bscript.toStack(script);
100
99
  assert.deepStrictEqual(
101
- stack.map(x => {
100
+ stack.map((x) => {
102
101
  return x.toString('hex');
103
102
  }),
104
103
  f.stack,
@@ -114,16 +113,14 @@ describe('script', () => {
114
113
  });
115
114
 
116
115
  describe('compile (via fromASM)', () => {
117
- fixtures.valid.forEach(f => {
116
+ fixtures.valid.forEach((f) => {
118
117
  it('compiles ' + f.asm, () => {
119
118
  const scriptSig = bscript.fromASM(f.asm);
120
119
 
121
120
  assert.strictEqual(scriptSig.toString('hex'), f.script);
122
121
 
123
122
  if (f.nonstandard) {
124
- const scriptSigNS = bscript.fromASM(
125
- f.nonstandard.scriptSig,
126
- );
123
+ const scriptSigNS = bscript.fromASM(f.nonstandard.scriptSig);
127
124
 
128
125
  assert.strictEqual(scriptSigNS.toString('hex'), f.script);
129
126
  }
@@ -132,14 +129,11 @@ describe('script', () => {
132
129
  });
133
130
 
134
131
  describe('decompile', () => {
135
- fixtures.valid.forEach(f => {
132
+ fixtures.valid.forEach((f) => {
136
133
  it('decompiles ' + f.asm, () => {
137
134
  const chunks = bscript.decompile(Buffer.from(f.script, 'hex'));
138
135
 
139
- assert.strictEqual(
140
- bscript.compile(chunks!).toString('hex'),
141
- f.script,
142
- );
136
+ assert.strictEqual(bscript.compile(chunks!).toString('hex'), f.script);
143
137
  assert.strictEqual(bscript.toASM(chunks!), f.asm);
144
138
 
145
139
  if (f.nonstandard) {
@@ -147,40 +141,25 @@ describe('script', () => {
147
141
  Buffer.from(f.nonstandard.scriptSigHex, 'hex'),
148
142
  );
149
143
 
150
- assert.strictEqual(
151
- bscript.compile(chunksNS!).toString('hex'),
152
- f.script,
153
- );
144
+ assert.strictEqual(bscript.compile(chunksNS!).toString('hex'), f.script);
154
145
 
155
146
  // toASM converts verbatim, only `compile` transforms the script to a minimalpush compliant script
156
- assert.strictEqual(
157
- bscript.toASM(chunksNS!),
158
- f.nonstandard.scriptSig,
159
- );
147
+ assert.strictEqual(bscript.toASM(chunksNS!), f.nonstandard.scriptSig);
160
148
  }
161
149
  });
162
150
  });
163
151
 
164
- fixtures.invalid.decompile.forEach(f => {
165
- it(
166
- 'fails to decompile ' +
167
- f.script +
168
- ', because "' +
169
- f.description +
170
- '"',
171
- () => {
172
- const chunks = bscript.decompile(
173
- Buffer.from(f.script, 'hex'),
174
- );
152
+ fixtures.invalid.decompile.forEach((f) => {
153
+ it('fails to decompile ' + f.script + ', because "' + f.description + '"', () => {
154
+ const chunks = bscript.decompile(Buffer.from(f.script, 'hex'));
175
155
 
176
- assert.strictEqual(chunks, null);
177
- },
178
- );
156
+ assert.strictEqual(chunks, null);
157
+ });
179
158
  });
180
159
  });
181
160
 
182
161
  describe('SCRIPT_VERIFY_MINIMALDATA policy', () => {
183
- fixtures.valid.forEach(f => {
162
+ fixtures.valid.forEach((f) => {
184
163
  it('compliant for scriptSig ' + f.asm, () => {
185
164
  const script = Buffer.from(f.script, 'hex');
186
165
 
@@ -195,10 +174,7 @@ describe('script', () => {
195
174
 
196
175
  assert(
197
176
  minimalData(script),
198
- 'Failed for ' +
199
- num +
200
- ' length script: ' +
201
- script.toString('hex'),
177
+ 'Failed for ' + num + ' length script: ' + script.toString('hex'),
202
178
  );
203
179
  });
204
180
  }
@@ -1,16 +1,13 @@
1
- import * as assert from 'assert';
1
+ import assert from 'assert';
2
2
  import { describe, it } from 'mocha';
3
- import * as scriptNumber from '../src/script_number';
4
- import * as fixtures from './fixtures/script_number.json';
3
+ import * as scriptNumber from '../src/script_number.js';
4
+ import fixtures from './fixtures/script_number.json' with { type: 'json' };
5
5
 
6
6
  describe('script-number', () => {
7
7
  describe('decode', () => {
8
- fixtures.forEach(f => {
8
+ fixtures.forEach((f) => {
9
9
  it(f.hex + ' returns ' + f.number, () => {
10
- const actual = scriptNumber.decode(
11
- Buffer.from(f.hex, 'hex'),
12
- f.bytes,
13
- );
10
+ const actual = scriptNumber.decode(Buffer.from(f.hex, 'hex'), f.bytes);
14
11
 
15
12
  assert.strictEqual(actual, f.number);
16
13
  });
@@ -18,7 +15,7 @@ describe('script-number', () => {
18
15
  });
19
16
 
20
17
  describe('encode', () => {
21
- fixtures.forEach(f => {
18
+ fixtures.forEach((f) => {
22
19
  it(f.number + ' returns ' + f.hex, () => {
23
20
  const actual = scriptNumber.encode(f.number);
24
21
 
@@ -1,7 +1,7 @@
1
- import * as assert from 'assert';
1
+ import assert from 'assert';
2
2
  import { describe, it } from 'mocha';
3
- import { signature as bscriptSig } from '../src/script';
4
- import * as fixtures from './fixtures/signature.json';
3
+ import { signature as bscriptSig } from '../src/script.js';
4
+ import fixtures from './fixtures/signature.json' with { type: 'json' };
5
5
 
6
6
  describe('Script Signatures', () => {
7
7
  function fromRaw(signature: { r: string; s: string }): Buffer {
@@ -22,7 +22,7 @@ describe('Script Signatures', () => {
22
22
  }
23
23
 
24
24
  describe('encode', () => {
25
- fixtures.valid.forEach(f => {
25
+ fixtures.valid.forEach((f) => {
26
26
  it('encodes ' + f.hex, () => {
27
27
  const buffer = bscriptSig.encode(fromRaw(f.raw), f.hashType);
28
28
 
@@ -30,7 +30,7 @@ describe('Script Signatures', () => {
30
30
  });
31
31
  });
32
32
 
33
- fixtures.invalid.forEach(f => {
33
+ fixtures.invalid.forEach((f) => {
34
34
  if (!f.raw) return;
35
35
 
36
36
  it('throws ' + f.exception, () => {
@@ -44,7 +44,7 @@ describe('Script Signatures', () => {
44
44
  });
45
45
 
46
46
  describe('decode', () => {
47
- fixtures.valid.forEach(f => {
47
+ fixtures.valid.forEach((f) => {
48
48
  it('decodes ' + f.hex, () => {
49
49
  const decode = bscriptSig.decode(Buffer.from(f.hex, 'hex'));
50
50
 
@@ -53,7 +53,7 @@ describe('Script Signatures', () => {
53
53
  });
54
54
  });
55
55
 
56
- fixtures.invalid.forEach(f => {
56
+ fixtures.invalid.forEach((f) => {
57
57
  it('throws on ' + f.hex, () => {
58
58
  const buffer = Buffer.from(f.hex, 'hex');
59
59
 
@@ -1,8 +1,8 @@
1
- import * as assert from 'assert';
1
+ import assert from 'assert';
2
2
  import { beforeEach, describe, it } from 'mocha';
3
- import { Transaction } from '..';
4
- import * as bscript from '../src/script';
5
- import * as fixtures from './fixtures/transaction.json';
3
+ import { Transaction } from '../src/index.js';
4
+ import * as bscript from '../src/script.js';
5
+ import fixtures from './fixtures/transaction.json' with { type: 'json' };
6
6
 
7
7
  describe('Transaction', () => {
8
8
  function fromRaw(raw: any, noWitness?: boolean): Transaction {
@@ -58,14 +58,11 @@ describe('Transaction', () => {
58
58
  });
59
59
 
60
60
  if (f.whex) {
61
- it(
62
- 'imports ' + f.description + ' (' + id + ') as witness',
63
- () => {
64
- const actual = Transaction.fromHex(f.whex);
61
+ it('imports ' + f.description + ' (' + id + ') as witness', () => {
62
+ const actual = Transaction.fromHex(f.whex);
65
63
 
66
- assert.strictEqual(actual.toHex(), f.whex);
67
- },
68
- );
64
+ assert.strictEqual(actual.toHex(), f.whex);
65
+ });
69
66
  }
70
67
  }
71
68
 
@@ -73,7 +70,7 @@ describe('Transaction', () => {
73
70
  fixtures.hashForSignature.forEach(importExport);
74
71
  fixtures.hashForWitnessV0.forEach(importExport);
75
72
 
76
- fixtures.invalid.fromBuffer.forEach(f => {
73
+ fixtures.invalid.fromBuffer.forEach((f) => {
77
74
  it('throws on ' + f.exception, () => {
78
75
  assert.throws(() => {
79
76
  Transaction.fromHex(f.hex);
@@ -90,20 +87,17 @@ describe('Transaction', () => {
90
87
  });
91
88
 
92
89
  describe('toBuffer/toHex', () => {
93
- fixtures.valid.forEach(f => {
90
+ fixtures.valid.forEach((f) => {
94
91
  it('exports ' + f.description + ' (' + f.id + ')', () => {
95
92
  const actual = fromRaw(f.raw, true);
96
93
  assert.strictEqual(actual.toHex(), f.hex);
97
94
  });
98
95
 
99
96
  if (f.whex) {
100
- it(
101
- 'exports ' + f.description + ' (' + f.id + ') as witness',
102
- () => {
103
- const wactual = fromRaw(f.raw);
104
- assert.strictEqual(wactual.toHex(), f.whex);
105
- },
106
- );
97
+ it('exports ' + f.description + ' (' + f.id + ') as witness', () => {
98
+ const wactual = fromRaw(f.raw);
99
+ assert.strictEqual(wactual.toHex(), f.whex);
100
+ });
107
101
  }
108
102
  });
109
103
 
@@ -127,38 +121,28 @@ describe('Transaction', () => {
127
121
  });
128
122
 
129
123
  describe('hasWitnesses', () => {
130
- fixtures.valid.forEach(f => {
131
- it(
132
- 'detects if the transaction has witnesses: ' +
133
- (f.whex ? 'true' : 'false'),
134
- () => {
135
- assert.strictEqual(
136
- Transaction.fromHex(
137
- f.whex ? f.whex : f.hex,
138
- ).hasWitnesses(),
139
- !!f.whex,
140
- );
141
- },
142
- );
124
+ fixtures.valid.forEach((f) => {
125
+ it('detects if the transaction has witnesses: ' + (f.whex ? 'true' : 'false'), () => {
126
+ assert.strictEqual(
127
+ Transaction.fromHex(f.whex ? f.whex : f.hex).hasWitnesses(),
128
+ !!f.whex,
129
+ );
130
+ });
143
131
  });
144
132
  });
145
133
 
146
134
  describe('weight/virtualSize', () => {
147
135
  it('computes virtual size', () => {
148
- fixtures.valid.forEach(f => {
149
- const transaction = Transaction.fromHex(
150
- f.whex ? f.whex : f.hex,
151
- );
136
+ fixtures.valid.forEach((f) => {
137
+ const transaction = Transaction.fromHex(f.whex ? f.whex : f.hex);
152
138
 
153
139
  assert.strictEqual(transaction.virtualSize(), f.virtualSize);
154
140
  });
155
141
  });
156
142
 
157
143
  it('computes weight', () => {
158
- fixtures.valid.forEach(f => {
159
- const transaction = Transaction.fromHex(
160
- f.whex ? f.whex : f.hex,
161
- );
144
+ fixtures.valid.forEach((f) => {
145
+ const transaction = Transaction.fromHex(f.whex ? f.whex : f.hex);
162
146
 
163
147
  assert.strictEqual(transaction.weight(), f.weight);
164
148
  });
@@ -189,7 +173,7 @@ describe('Transaction', () => {
189
173
  assert.strictEqual(tx.ins[0].sequence, 0xffffffff);
190
174
  });
191
175
 
192
- fixtures.invalid.addInput.forEach(f => {
176
+ fixtures.invalid.addInput.forEach((f) => {
193
177
  it('throws on ' + f.exception, () => {
194
178
  const tx = new Transaction();
195
179
  const hash = Buffer.from(f.hash, 'hex');
@@ -210,7 +194,7 @@ describe('Transaction', () => {
210
194
  });
211
195
 
212
196
  describe('clone', () => {
213
- fixtures.valid.forEach(f => {
197
+ fixtures.valid.forEach((f) => {
214
198
  let actual: Transaction;
215
199
  let expected: Transaction;
216
200
 
@@ -231,15 +215,12 @@ describe('Transaction', () => {
231
215
 
232
216
  describe('getHash/getId', () => {
233
217
  function verify(f: any): void {
234
- it(
235
- 'should return the id for ' + f.id + '(' + f.description + ')',
236
- () => {
237
- const tx = Transaction.fromHex(f.whex || f.hex);
218
+ it('should return the id for ' + f.id + '(' + f.description + ')', () => {
219
+ const tx = Transaction.fromHex(f.whex || f.hex);
238
220
 
239
- assert.strictEqual(tx.getHash().toString('hex'), f.hash);
240
- assert.strictEqual(tx.getId(), f.id);
241
- },
242
- );
221
+ assert.strictEqual(tx.getHash().toString('hex'), f.hash);
222
+ assert.strictEqual(tx.getId(), f.id);
223
+ });
243
224
  }
244
225
 
245
226
  fixtures.valid.forEach(verify);
@@ -247,20 +228,11 @@ describe('Transaction', () => {
247
228
 
248
229
  describe('isCoinbase', () => {
249
230
  function verify(f: any): void {
250
- it(
251
- 'should return ' +
252
- f.coinbase +
253
- ' for ' +
254
- f.id +
255
- '(' +
256
- f.description +
257
- ')',
258
- () => {
259
- const tx = Transaction.fromHex(f.hex);
231
+ it('should return ' + f.coinbase + ' for ' + f.id + '(' + f.description + ')', () => {
232
+ const tx = Transaction.fromHex(f.hex);
260
233
 
261
- assert.strictEqual(tx.isCoinbase(), f.coinbase);
262
- },
263
- );
234
+ assert.strictEqual(tx.isCoinbase(), f.coinbase);
235
+ });
264
236
  }
265
237
 
266
238
  fixtures.valid.forEach(verify);
@@ -281,14 +253,8 @@ describe('Transaction', () => {
281
253
  tx.addOutput(randScript, 5000000000);
282
254
 
283
255
  const original = (tx as any).__toBuffer;
284
- (tx as any).__toBuffer = function (
285
- this: Transaction,
286
- a: any,
287
- b: any,
288
- c: any,
289
- ): any {
290
- if (c !== false)
291
- throw new Error('hashForSignature MUST pass false');
256
+ (tx as any).__toBuffer = function (this: Transaction, a: any, b: any, c: any): any {
257
+ if (c !== false) throw new Error('hashForSignature MUST pass false');
292
258
 
293
259
  return original.call(this, a, b, c);
294
260
  };
@@ -303,7 +269,7 @@ describe('Transaction', () => {
303
269
  });
304
270
  });
305
271
 
306
- fixtures.hashForSignature.forEach(f => {
272
+ fixtures.hashForSignature.forEach((f) => {
307
273
  it(
308
274
  'should return ' +
309
275
  f.hash +
@@ -314,9 +280,7 @@ describe('Transaction', () => {
314
280
  const script = bscript.fromASM(f.script);
315
281
 
316
282
  assert.strictEqual(
317
- tx
318
- .hashForSignature(f.inIndex, script, f.type)
319
- .toString('hex'),
283
+ tx.hashForSignature(f.inIndex, script, f.type).toString('hex'),
320
284
  f.hash,
321
285
  );
322
286
  },
@@ -325,7 +289,7 @@ describe('Transaction', () => {
325
289
  });
326
290
 
327
291
  describe('hashForWitnessV0', () => {
328
- fixtures.hashForWitnessV0.forEach(f => {
292
+ fixtures.hashForWitnessV0.forEach((f) => {
329
293
  it(
330
294
  'should return ' +
331
295
  f.hash +
@@ -336,14 +300,7 @@ describe('Transaction', () => {
336
300
  const script = bscript.fromASM(f.script);
337
301
 
338
302
  assert.strictEqual(
339
- tx
340
- .hashForWitnessV0(
341
- f.inIndex,
342
- script,
343
- f.value,
344
- f.type,
345
- )
346
- .toString('hex'),
303
+ tx.hashForWitnessV0(f.inIndex, script, f.value, f.type).toString('hex'),
347
304
  f.hash,
348
305
  );
349
306
  },
@@ -352,25 +309,18 @@ describe('Transaction', () => {
352
309
  });
353
310
 
354
311
  describe('taprootSigning', () => {
355
- fixtures.taprootSigning.forEach(f => {
312
+ fixtures.taprootSigning.forEach((f) => {
356
313
  const tx = Transaction.fromHex(f.txHex);
357
- const prevOutScripts = f.utxos.map(({ scriptHex }) =>
358
- Buffer.from(scriptHex, 'hex'),
359
- );
314
+ const prevOutScripts = f.utxos.map(({ scriptHex }) => Buffer.from(scriptHex, 'hex'));
360
315
  const values = f.utxos.map(({ value }) => value);
361
316
 
362
- f.cases.forEach(c => {
317
+ f.cases.forEach((c) => {
363
318
  let hash: Buffer;
364
319
 
365
320
  it(`should hash to ${c.hash} for ${f.description}:${c.vin}`, () => {
366
321
  const hashType = Buffer.from(c.typeHex, 'hex').readUInt8(0);
367
322
 
368
- hash = tx.hashForWitnessV1(
369
- c.vin,
370
- prevOutScripts,
371
- values,
372
- hashType,
373
- );
323
+ hash = tx.hashForWitnessV1(c.vin, prevOutScripts, values, hashType);
374
324
  assert.strictEqual(hash.toString('hex'), c.hash);
375
325
  });
376
326
  });
@@ -1,5 +1,7 @@
1
1
  // This file is required to run mocha tests on the TS files directly
2
2
 
3
- require('ts-node').register({
3
+ import { register } from 'ts-node';
4
+
5
+ register({
4
6
  project: 'test/tsconfig.json',
5
7
  });
@@ -1,9 +1,11 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "target": "ESNext",
4
- "module": "commonjs",
4
+ "module": "esnext",
5
+ "moduleResolution": "nodenext",
5
6
  "outDir": "../",
6
7
  "declaration": false,
8
+ "allowSyntheticDefaultImports": true,
7
9
  "rootDir": "../",
8
10
  "rootDirs": [
9
11
  "../src",
@@ -16,6 +18,7 @@
16
18
  "lib": [
17
19
  "ES2021"
18
20
  ],
21
+ "resolvePackageJsonImports": true,
19
22
  "allowJs": false,
20
23
  "resolveJsonModule": true,
21
24
  "strict": true,
@@ -1,8 +1,9 @@
1
- import * as assert from 'assert';
1
+ import assert from 'assert';
2
2
  import { describe, it } from 'mocha';
3
- import * as types from '../src/types';
3
+ import * as types from '../src/types.js';
4
4
 
5
- const typeforce = require('typeforce');
5
+ // @ts-ignore
6
+ import typeforce from 'typeforce';
6
7
 
7
8
  describe('types', () => {
8
9
  describe('Buffer Hash160/Hash256', () => {
@@ -16,17 +17,11 @@ describe('types', () => {
16
17
 
17
18
  it('return true for oneOf', () => {
18
19
  assert.doesNotThrow(() => {
19
- typeforce(
20
- types.oneOf(types.Hash160bit, types.Hash256bit),
21
- buffer32byte,
22
- );
20
+ typeforce(types.oneOf(types.Hash160bit, types.Hash256bit), buffer32byte);
23
21
  });
24
22
 
25
23
  assert.doesNotThrow(() => {
26
- typeforce(
27
- types.oneOf(types.Hash256bit, types.Hash160bit),
28
- buffer32byte,
29
- );
24
+ typeforce(types.oneOf(types.Hash256bit, types.Hash160bit), buffer32byte);
30
25
  });
31
26
  });
32
27
 
@@ -49,7 +44,7 @@ describe('types', () => {
49
44
  { value: 20999999 * 1e8, result: true },
50
45
  { value: 21000000 * 1e8, result: true },
51
46
  { value: 21000001 * 1e8, result: false },
52
- ].forEach(f => {
47
+ ].forEach((f) => {
53
48
  it('returns ' + f.result + ' for valid for ' + f.value, () => {
54
49
  assert.strictEqual(types.Satoshi(f.value), f.result);
55
50
  });