@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,19 +1,19 @@
1
- import * as assert from 'assert';
1
+ import assert from 'assert';
2
2
  import { describe, it } from 'mocha';
3
- import * as bufferutils from '../src/bufferutils';
4
- import { BufferReader, BufferWriter } from '../src/bufferutils';
3
+ import * as bufferutils from '../src/bufferutils.js';
4
+ import { BufferReader, BufferWriter } from '../src/bufferutils.js';
5
5
 
6
- import * as fixtures from './fixtures/bufferutils.json';
6
+ import fixtures from './fixtures/bufferutils.json' with { type: 'json' };
7
7
 
8
- const varuint = require('varuint-bitcoin');
8
+ import * as varuint from 'varuint-bitcoin';
9
9
 
10
10
  describe('bufferutils', () => {
11
11
  function concatToBuffer(values: number[][]): Buffer {
12
- return Buffer.concat(values.map(data => Buffer.from(data)));
12
+ return Buffer.concat(values.map((data) => Buffer.from(data)));
13
13
  }
14
14
 
15
15
  describe('readUInt64LE', () => {
16
- fixtures.valid.forEach(f => {
16
+ fixtures.valid.forEach((f) => {
17
17
  it('decodes ' + f.hex, () => {
18
18
  const buffer = Buffer.from(f.hex, 'hex');
19
19
  const num = bufferutils.readUInt64LE(buffer, 0);
@@ -22,7 +22,7 @@ describe('bufferutils', () => {
22
22
  });
23
23
  });
24
24
 
25
- fixtures.invalid.readUInt64LE.forEach(f => {
25
+ fixtures.invalid.readUInt64LE.forEach((f) => {
26
26
  it('throws on ' + f.description, () => {
27
27
  const buffer = Buffer.from(f.hex, 'hex');
28
28
 
@@ -34,7 +34,7 @@ describe('bufferutils', () => {
34
34
  });
35
35
 
36
36
  describe('writeUInt64LE', () => {
37
- fixtures.valid.forEach(f => {
37
+ fixtures.valid.forEach((f) => {
38
38
  it('encodes ' + f.dec, () => {
39
39
  const buffer = Buffer.alloc(8, 0);
40
40
 
@@ -43,7 +43,7 @@ describe('bufferutils', () => {
43
43
  });
44
44
  });
45
45
 
46
- fixtures.invalid.writeUInt64LE.forEach(f => {
46
+ fixtures.invalid.writeUInt64LE.forEach((f) => {
47
47
  it('throws on ' + f.description, () => {
48
48
  const buffer = Buffer.alloc(8, 0);
49
49
 
@@ -77,9 +77,7 @@ describe('bufferutils', () => {
77
77
  it('writeUint8', () => {
78
78
  const values = [0, 1, 254, 255];
79
79
  const expectedBuffer = Buffer.from([0, 1, 0xfe, 0xff]);
80
- const bufferWriter = new BufferWriter(
81
- Buffer.allocUnsafe(expectedBuffer.length),
82
- );
80
+ const bufferWriter = new BufferWriter(Buffer.allocUnsafe(expectedBuffer.length));
83
81
  values.forEach((v: number) => {
84
82
  const expectedOffset = bufferWriter.offset + 1;
85
83
  bufferWriter.writeUInt8(v);
@@ -89,14 +87,7 @@ describe('bufferutils', () => {
89
87
  });
90
88
 
91
89
  it('writeInt32', () => {
92
- const values = [
93
- 0,
94
- 1,
95
- Math.pow(2, 31) - 2,
96
- Math.pow(2, 31) - 1,
97
- -1,
98
- -Math.pow(2, 31),
99
- ];
90
+ const values = [0, 1, Math.pow(2, 31) - 2, Math.pow(2, 31) - 1, -1, -Math.pow(2, 31)];
100
91
  const expectedBuffer = concatToBuffer([
101
92
  [0, 0, 0, 0],
102
93
  [1, 0, 0, 0],
@@ -105,9 +96,7 @@ describe('bufferutils', () => {
105
96
  [0xff, 0xff, 0xff, 0xff],
106
97
  [0x00, 0x00, 0x00, 0x80],
107
98
  ]);
108
- const bufferWriter = new BufferWriter(
109
- Buffer.allocUnsafe(expectedBuffer.length),
110
- );
99
+ const bufferWriter = new BufferWriter(Buffer.allocUnsafe(expectedBuffer.length));
111
100
  values.forEach((value: number) => {
112
101
  const expectedOffset = bufferWriter.offset + 4;
113
102
  bufferWriter.writeInt32(value);
@@ -125,9 +114,7 @@ describe('bufferutils', () => {
125
114
  [0, 0, 1, 0],
126
115
  [0xff, 0xff, 0xff, 0xff],
127
116
  ]);
128
- const bufferWriter = new BufferWriter(
129
- Buffer.allocUnsafe(expectedBuffer.length),
130
- );
117
+ const bufferWriter = new BufferWriter(Buffer.allocUnsafe(expectedBuffer.length));
131
118
  values.forEach((value: number) => {
132
119
  const expectedOffset = bufferWriter.offset + 4;
133
120
  bufferWriter.writeUInt32(value);
@@ -137,21 +124,14 @@ describe('bufferutils', () => {
137
124
  });
138
125
 
139
126
  it('writeUInt64', () => {
140
- const values = [
141
- 0,
142
- 1,
143
- Math.pow(2, 32),
144
- Number.MAX_SAFE_INTEGER /* 2^53 - 1 */,
145
- ];
127
+ const values = [0, 1, Math.pow(2, 32), Number.MAX_SAFE_INTEGER /* 2^53 - 1 */];
146
128
  const expectedBuffer = concatToBuffer([
147
129
  [0, 0, 0, 0, 0, 0, 0, 0],
148
130
  [1, 0, 0, 0, 0, 0, 0, 0],
149
131
  [0, 0, 0, 0, 1, 0, 0, 0],
150
132
  [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00],
151
133
  ]);
152
- const bufferWriter = new BufferWriter(
153
- Buffer.allocUnsafe(expectedBuffer.length),
154
- );
134
+ const bufferWriter = new BufferWriter(Buffer.allocUnsafe(expectedBuffer.length));
155
135
  values.forEach((value: number) => {
156
136
  const expectedOffset = bufferWriter.offset + 8;
157
137
  bufferWriter.writeUInt64(value);
@@ -193,12 +173,9 @@ describe('bufferutils', () => {
193
173
  [0xff, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00],
194
174
  [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00],
195
175
  ]);
196
- const bufferWriter = new BufferWriter(
197
- Buffer.allocUnsafe(expectedBuffer.length),
198
- );
176
+ const bufferWriter = new BufferWriter(Buffer.allocUnsafe(expectedBuffer.length));
199
177
  values.forEach((value: number) => {
200
- const expectedOffset =
201
- bufferWriter.offset + varuint.encodingLength(value);
178
+ const expectedOffset = bufferWriter.offset + varuint.encodingLength(value);
202
179
  bufferWriter.writeVarInt(value);
203
180
  testBuffer(bufferWriter, expectedBuffer, expectedOffset);
204
181
  });
@@ -208,9 +185,7 @@ describe('bufferutils', () => {
208
185
  it('writeSlice', () => {
209
186
  const values = [[], [1], [1, 2, 3, 4], [254, 255]];
210
187
  const expectedBuffer = concatToBuffer(values);
211
- const bufferWriter = new BufferWriter(
212
- Buffer.allocUnsafe(expectedBuffer.length),
213
- );
188
+ const bufferWriter = new BufferWriter(Buffer.allocUnsafe(expectedBuffer.length));
214
189
  values.forEach((v: number[]) => {
215
190
  const expectedOffset = bufferWriter.offset + v.length;
216
191
  bufferWriter.writeSlice(Buffer.from(v));
@@ -223,11 +198,7 @@ describe('bufferutils', () => {
223
198
  });
224
199
 
225
200
  it('writeVarSlice', () => {
226
- const values = [
227
- Buffer.alloc(1, 1),
228
- Buffer.alloc(252, 2),
229
- Buffer.alloc(253, 3),
230
- ];
201
+ const values = [Buffer.alloc(1, 1), Buffer.alloc(252, 2), Buffer.alloc(253, 3)];
231
202
  const expectedBuffer = Buffer.concat([
232
203
  Buffer.from([0x01, 0x01]),
233
204
  Buffer.from([0xfc]),
@@ -235,14 +206,10 @@ describe('bufferutils', () => {
235
206
  Buffer.from([0xfd, 0xfd, 0x00]),
236
207
  Buffer.alloc(253, 0x03),
237
208
  ]);
238
- const bufferWriter = new BufferWriter(
239
- Buffer.allocUnsafe(expectedBuffer.length),
240
- );
209
+ const bufferWriter = new BufferWriter(Buffer.allocUnsafe(expectedBuffer.length));
241
210
  values.forEach((value: Buffer) => {
242
211
  const expectedOffset =
243
- bufferWriter.offset +
244
- varuint.encodingLength(value.length) +
245
- value.length;
212
+ bufferWriter.offset + varuint.encodingLength(value.length) + value.length;
246
213
  bufferWriter.writeVarSlice(value);
247
214
  testBuffer(bufferWriter, expectedBuffer, expectedOffset);
248
215
  });
@@ -268,16 +235,13 @@ describe('bufferutils', () => {
268
235
  ),
269
236
  ]);
270
237
 
271
- const bufferWriter = new BufferWriter(
272
- Buffer.allocUnsafe(expectedBuffer.length),
273
- );
238
+ const bufferWriter = new BufferWriter(Buffer.allocUnsafe(expectedBuffer.length));
274
239
  values.forEach((value: Buffer[]) => {
275
240
  const expectedOffset =
276
241
  bufferWriter.offset +
277
242
  varuint.encodingLength(value.length) +
278
243
  value.reduce(
279
- (sum: number, v) =>
280
- sum + varuint.encodingLength(v.length) + v.length,
244
+ (sum: number, v) => sum + varuint.encodingLength(v.length) + v.length,
281
245
  0,
282
246
  );
283
247
  bufferWriter.writeVector(value);
@@ -302,9 +266,7 @@ describe('bufferutils', () => {
302
266
  bufferReader: BufferReader,
303
267
  value: Buffer | number,
304
268
  expectedValue: Buffer | number,
305
- expectedOffset: number = Buffer.isBuffer(expectedValue)
306
- ? expectedValue.length
307
- : 0,
269
+ expectedOffset: number = Buffer.isBuffer(expectedValue) ? expectedValue.length : 0,
308
270
  ): void {
309
271
  assert.strictEqual(bufferReader.offset, expectedOffset);
310
272
  if (Buffer.isBuffer(expectedValue)) {
@@ -329,14 +291,7 @@ describe('bufferutils', () => {
329
291
  });
330
292
 
331
293
  it('readInt32', () => {
332
- const values = [
333
- 0,
334
- 1,
335
- Math.pow(2, 31) - 2,
336
- Math.pow(2, 31) - 1,
337
- -1,
338
- -Math.pow(2, 31),
339
- ];
294
+ const values = [0, 1, Math.pow(2, 31) - 2, Math.pow(2, 31) - 1, -1, -Math.pow(2, 31)];
340
295
  const buffer = concatToBuffer([
341
296
  [0, 0, 0, 0],
342
297
  [1, 0, 0, 0],
@@ -371,12 +326,7 @@ describe('bufferutils', () => {
371
326
  });
372
327
 
373
328
  it('readUInt64', () => {
374
- const values = [
375
- 0,
376
- 1,
377
- Math.pow(2, 32),
378
- Number.MAX_SAFE_INTEGER /* 2^53 - 1 */,
379
- ];
329
+ const values = [0, 1, Math.pow(2, 32), Number.MAX_SAFE_INTEGER /* 2^53 - 1 */];
380
330
  const buffer = concatToBuffer([
381
331
  [0, 0, 0, 0, 0, 0, 0, 0],
382
332
  [1, 0, 0, 0, 0, 0, 0, 0],
@@ -426,8 +376,7 @@ describe('bufferutils', () => {
426
376
  ]);
427
377
  const bufferReader = new BufferReader(buffer);
428
378
  values.forEach((value: number) => {
429
- const expectedOffset =
430
- bufferReader.offset + varuint.encodingLength(value);
379
+ const expectedOffset = bufferReader.offset + varuint.encodingLength(value);
431
380
  const val = bufferReader.readVarInt();
432
381
  testValue(bufferReader, val, value, expectedOffset);
433
382
  });
@@ -448,11 +397,7 @@ describe('bufferutils', () => {
448
397
  });
449
398
 
450
399
  it('readVarSlice', () => {
451
- const values = [
452
- Buffer.alloc(1, 1),
453
- Buffer.alloc(252, 2),
454
- Buffer.alloc(253, 3),
455
- ];
400
+ const values = [Buffer.alloc(1, 1), Buffer.alloc(252, 2), Buffer.alloc(253, 3)];
456
401
  const buffer = Buffer.concat([
457
402
  Buffer.from([0x01, 0x01]),
458
403
  Buffer.from([0xfc]),
@@ -463,9 +408,7 @@ describe('bufferutils', () => {
463
408
  const bufferReader = new BufferReader(buffer);
464
409
  values.forEach((value: Buffer) => {
465
410
  const expectedOffset =
466
- bufferReader.offset +
467
- varuint.encodingLength(value.length) +
468
- value.length;
411
+ bufferReader.offset + varuint.encodingLength(value.length) + value.length;
469
412
  const val = bufferReader.readVarSlice();
470
413
  testValue(bufferReader, val, value, expectedOffset);
471
414
  });
@@ -496,17 +439,11 @@ describe('bufferutils', () => {
496
439
  bufferReader.offset +
497
440
  varuint.encodingLength(value.length) +
498
441
  value.reduce(
499
- (sum: number, v) =>
500
- sum + varuint.encodingLength(v.length) + v.length,
442
+ (sum: number, v) => sum + varuint.encodingLength(v.length) + v.length,
501
443
  0,
502
444
  );
503
445
  const val = bufferReader.readVector();
504
- testValue(
505
- bufferReader,
506
- Buffer.concat(val),
507
- Buffer.concat(value),
508
- expectedOffset,
509
- );
446
+ testValue(bufferReader, Buffer.concat(val), Buffer.concat(value), expectedOffset);
510
447
  });
511
448
  });
512
449
  });
@@ -1,13 +1,13 @@
1
- import * as assert from 'assert';
1
+ import assert from 'assert';
2
2
  import { describe, it } from 'mocha';
3
- import { crypto as bcrypto, TaggedHashPrefix } from '..';
4
- import * as fixtures from './fixtures/crypto.json';
5
- import { sha256, TAGGED_HASH_PREFIXES, TAGS } from '../src/crypto';
3
+ import { crypto as bcrypto, TaggedHashPrefix } from '../src/index.js';
4
+ import fixtures from './fixtures/crypto.json' with { type: 'json' };
5
+ import { sha256, TAGGED_HASH_PREFIXES, TAGS } from '../src/crypto.js';
6
6
 
7
7
  describe('crypto', () => {
8
- ['hash160', 'hash256', 'ripemd160', 'sha1', 'sha256'].forEach(algorithm => {
8
+ ['hash160', 'hash256', 'ripemd160', 'sha1', 'sha256'].forEach((algorithm) => {
9
9
  describe(algorithm, () => {
10
- fixtures.hashes.forEach(f => {
10
+ fixtures.hashes.forEach((f) => {
11
11
  const fn = (bcrypto as any)[algorithm];
12
12
  const expected = (f as any)[algorithm];
13
13
 
@@ -22,18 +22,12 @@ describe('crypto', () => {
22
22
  });
23
23
 
24
24
  describe('taggedHash', () => {
25
- fixtures.taggedHash.forEach(f => {
25
+ fixtures.taggedHash.forEach((f) => {
26
26
  const bytes = Buffer.from(f.hex, 'hex');
27
27
  const expected = Buffer.from(f.result, 'hex');
28
28
  it(`returns ${f.result} for taggedHash "${f.tag}" of ${f.hex}`, () => {
29
- const actual = bcrypto.taggedHash(
30
- f.tag as TaggedHashPrefix,
31
- bytes,
32
- );
33
- assert.strictEqual(
34
- actual.toString('hex'),
35
- expected.toString('hex'),
36
- );
29
+ const actual = bcrypto.taggedHash(f.tag as TaggedHashPrefix, bytes);
30
+ assert.strictEqual(actual.toString('hex'), expected.toString('hex'));
37
31
  });
38
32
  });
39
33
  });
@@ -86,7 +86,7 @@
86
86
  },
87
87
  {
88
88
  "network": "bitcoin",
89
- "bech32": "BC1SW50QGDZ25J",
89
+ "bech32": "opnet1sw50qpgryz8",
90
90
  "version": 16,
91
91
  "data": "751e",
92
92
  "script": "OP_16 751e"
@@ -133,7 +133,7 @@
133
133
  "data": "751e76e8199196d454941c45d1b3a323"
134
134
  },
135
135
  {
136
- "address": "BC1SW50QGDZ25J",
136
+ "address": "bc1sw50qgdz25j",
137
137
  "version": 16,
138
138
  "prefix": "bc",
139
139
  "data": "751e"
@@ -222,7 +222,7 @@
222
222
  },
223
223
  {
224
224
  "exception": "has an invalid prefix",
225
- "address": "BC1SW50QGDZ25J",
225
+ "address": "bc1sw50qgdz25j",
226
226
  "network": {
227
227
  "bech32": "foo"
228
228
  }
@@ -1,9 +1,9 @@
1
- import * as assert from 'assert';
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 { 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
7
 
8
8
  const ECPair = ECPairFactory(ecc);
9
9
  const dhttp = regtestUtils.dhttp;
@@ -35,9 +35,7 @@ describe('bitcoinjs-lib (addresses)', () => {
35
35
  );
36
36
 
37
37
  it('can import an address via WIF', () => {
38
- const keyPair = ECPair.fromWIF(
39
- 'KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn',
40
- );
38
+ const keyPair = ECPair.fromWIF('KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn');
41
39
  const { address } = bitcoin.payments.p2pkh({
42
40
  pubkey: keyPair.publicKey,
43
41
  });
@@ -50,7 +48,7 @@ describe('bitcoinjs-lib (addresses)', () => {
50
48
  '026477115981fe981a6918a6297d9803c4dc04f328f22041bedff886bbc2962e01',
51
49
  '02c96db2302d19b43d4c69368babace7854cc84eb9e061cde51cfa77ca4a22b8b9',
52
50
  '03c6103b3b83e4a24a0e33a4df246ef11772f9992663db0c35759a5e2ebf68d8e9',
53
- ].map(hex => Buffer.from(hex, 'hex'));
51
+ ].map((hex) => Buffer.from(hex, 'hex'));
54
52
  const { address } = bitcoin.payments.p2sh({
55
53
  redeem: bitcoin.payments.p2ms({ m: 2, pubkeys }),
56
54
  });
@@ -59,23 +57,16 @@ describe('bitcoinjs-lib (addresses)', () => {
59
57
  });
60
58
 
61
59
  it('can generate a SegWit address', () => {
62
- const keyPair = ECPair.fromWIF(
63
- 'KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn',
64
- );
60
+ const keyPair = ECPair.fromWIF('KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn');
65
61
  const { address } = bitcoin.payments.p2wpkh({
66
62
  pubkey: keyPair.publicKey,
67
63
  });
68
64
 
69
- assert.strictEqual(
70
- address,
71
- 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4',
72
- );
65
+ assert.strictEqual(address, 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4');
73
66
  });
74
67
 
75
68
  it('can generate a SegWit address (via P2SH)', () => {
76
- const keyPair = ECPair.fromWIF(
77
- 'KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn',
78
- );
69
+ const keyPair = ECPair.fromWIF('KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn');
79
70
  const { address } = bitcoin.payments.p2sh({
80
71
  redeem: bitcoin.payments.p2wpkh({ pubkey: keyPair.publicKey }),
81
72
  });
@@ -89,7 +80,7 @@ describe('bitcoinjs-lib (addresses)', () => {
89
80
  '02c96db2302d19b43d4c69368babace7854cc84eb9e061cde51cfa77ca4a22b8b9',
90
81
  '023e4740d0ba639e28963f3476157b7cf2fb7c6fdf4254f97099cf8670b505ea59',
91
82
  '03c6103b3b83e4a24a0e33a4df246ef11772f9992663db0c35759a5e2ebf68d8e9',
92
- ].map(hex => Buffer.from(hex, 'hex'));
83
+ ].map((hex) => Buffer.from(hex, 'hex'));
93
84
  const { address } = bitcoin.payments.p2wsh({
94
85
  redeem: bitcoin.payments.p2ms({ m: 3, pubkeys }),
95
86
  });
@@ -104,7 +95,7 @@ describe('bitcoinjs-lib (addresses)', () => {
104
95
  const pubkeys = [
105
96
  '026477115981fe981a6918a6297d9803c4dc04f328f22041bedff886bbc2962e01',
106
97
  '02c96db2302d19b43d4c69368babace7854cc84eb9e061cde51cfa77ca4a22b8b9',
107
- ].map(hex => Buffer.from(hex, 'hex'));
98
+ ].map((hex) => Buffer.from(hex, 'hex'));
108
99
  const { address } = bitcoin.payments.p2sh({
109
100
  redeem: bitcoin.payments.p2wsh({
110
101
  redeem: bitcoin.payments.p2ms({ m: 2, pubkeys }),
@@ -123,10 +114,7 @@ describe('bitcoinjs-lib (addresses)', () => {
123
114
  });
124
115
 
125
116
  // bitcoin testnet P2PKH addresses start with a 'm' or 'n'
126
- assert.strictEqual(
127
- address!.startsWith('m') || address!.startsWith('n'),
128
- true,
129
- );
117
+ assert.strictEqual(address!.startsWith('m') || address!.startsWith('n'), true);
130
118
  });
131
119
 
132
120
  it('can generate a Litecoin address', () => {
@@ -1,9 +1,9 @@
1
- import * as assert from 'assert';
2
- import BIP32Factory from 'bip32';
1
+ import assert from 'assert';
2
+ import { BIP32Factory } from 'bip32';
3
3
  import * as ecc from 'tiny-secp256k1';
4
4
  import * as bip39 from 'bip39';
5
5
  import { describe, it } from 'mocha';
6
- import * as bitcoin from '../..';
6
+ import * as bitcoin from '../../src/index.js';
7
7
 
8
8
  const bip32 = BIP32Factory(ecc);
9
9
 
@@ -17,10 +17,7 @@ describe('bitcoinjs-lib (BIP32)', () => {
17
17
  'tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK';
18
18
  const node = bip32.fromBase58(xpriv, bitcoin.networks.testnet);
19
19
 
20
- assert.strictEqual(
21
- node.toWIF(),
22
- 'cQfoY67cetFNunmBUX5wJiw3VNoYx3gG9U9CAofKE6BfiV1fSRw7',
23
- );
20
+ assert.strictEqual(node.toWIF(), 'cQfoY67cetFNunmBUX5wJiw3VNoYx3gG9U9CAofKE6BfiV1fSRw7');
24
21
  });
25
22
 
26
23
  it('can export a BIP32 xpriv, then import it', () => {
@@ -51,10 +48,7 @@ describe('bitcoinjs-lib (BIP32)', () => {
51
48
  it('can create a BIP32, bitcoin, account 0, external address', () => {
52
49
  const path = "m/0'/0/0";
53
50
  const root = bip32.fromSeed(
54
- Buffer.from(
55
- 'dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd',
56
- 'hex',
57
- ),
51
+ Buffer.from('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd', 'hex'),
58
52
  );
59
53
 
60
54
  const child1 = root.derivePath(path);
@@ -62,22 +56,13 @@ describe('bitcoinjs-lib (BIP32)', () => {
62
56
  // option 2, manually
63
57
  const child1b = root.deriveHardened(0).derive(0).derive(0);
64
58
 
65
- assert.strictEqual(
66
- getAddress(child1),
67
- '1JHyB1oPXufr4FXkfitsjgNB5yRY9jAaa7',
68
- );
69
- assert.strictEqual(
70
- getAddress(child1b),
71
- '1JHyB1oPXufr4FXkfitsjgNB5yRY9jAaa7',
72
- );
59
+ assert.strictEqual(getAddress(child1), '1JHyB1oPXufr4FXkfitsjgNB5yRY9jAaa7');
60
+ assert.strictEqual(getAddress(child1b), '1JHyB1oPXufr4FXkfitsjgNB5yRY9jAaa7');
73
61
  });
74
62
 
75
63
  it('can create a BIP44, bitcoin, account 0, external address', () => {
76
64
  const root = bip32.fromSeed(
77
- Buffer.from(
78
- 'dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd',
79
- 'hex',
80
- ),
65
+ Buffer.from('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd', 'hex'),
81
66
  );
82
67
 
83
68
  const child1 = root.derivePath("m/44'/0'/0'/0/0");
@@ -90,14 +75,8 @@ describe('bitcoinjs-lib (BIP32)', () => {
90
75
  .derive(0)
91
76
  .derive(0);
92
77
 
93
- assert.strictEqual(
94
- getAddress(child1),
95
- '12Tyvr1U8A3ped6zwMEU5M8cx3G38sP5Au',
96
- );
97
- assert.strictEqual(
98
- getAddress(child1b),
99
- '12Tyvr1U8A3ped6zwMEU5M8cx3G38sP5Au',
100
- );
78
+ assert.strictEqual(getAddress(child1), '12Tyvr1U8A3ped6zwMEU5M8cx3G38sP5Au');
79
+ assert.strictEqual(getAddress(child1b), '12Tyvr1U8A3ped6zwMEU5M8cx3G38sP5Au');
101
80
  });
102
81
 
103
82
  it('can create a BIP49, bitcoin testnet, account 0, external address', () => {
@@ -1,6 +1,6 @@
1
- import * as assert from 'assert';
1
+ import assert from 'assert';
2
2
  import { describe, it } from 'mocha';
3
- import * as bitcoin from '../..';
3
+ import * as bitcoin from '../../src/index.js';
4
4
 
5
5
  describe('bitcoinjs-lib (blocks)', () => {
6
6
  it('can extract a height from a CoinBase transaction', () => {