@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,177 +1,155 @@
1
- import * as assert from 'assert';
2
- import { describe, it } from 'mocha';
3
- import * as ecc from 'tiny-secp256k1';
4
- import * as baddress from '../src/address';
5
- import * as bscript from '../src/script';
6
- import * as fixtures from './fixtures/address.json';
7
-
8
- import { initEccLib } from '../src';
9
-
10
- const NETWORKS = Object.assign(
11
- {
12
- litecoin: {
13
- messagePrefix: '\x19Litecoin Signed Message:\n',
14
- bip32: {
15
- public: 0x019da462,
16
- private: 0x019d9cfe,
17
- },
18
- pubKeyHash: 0x30,
19
- scriptHash: 0x32,
20
- wif: 0xb0,
21
- },
22
- },
23
- require('../src/networks'),
24
- );
25
-
26
- describe('address', () => {
27
- describe('fromBase58Check', () => {
28
- fixtures.standard.forEach(f => {
29
- if (!f.base58check) return;
30
-
31
- it('decodes ' + f.base58check, () => {
32
- const decode = baddress.fromBase58Check(f.base58check);
33
-
34
- assert.strictEqual(decode.version, f.version);
35
- assert.strictEqual(decode.hash.toString('hex'), f.hash);
36
- });
37
- });
38
-
39
- fixtures.invalid.fromBase58Check.forEach(f => {
40
- it('throws on ' + f.exception, () => {
41
- assert.throws(() => {
42
- baddress.fromBase58Check(f.address);
43
- }, new RegExp(f.address + ' ' + f.exception));
44
- });
45
- });
46
- });
47
-
48
- describe('fromBech32', () => {
49
- fixtures.standard.forEach(f => {
50
- if (!f.bech32) return;
51
-
52
- it('decodes ' + f.bech32, () => {
53
- const actual = baddress.fromBech32(f.bech32);
54
-
55
- assert.strictEqual(actual.version, f.version);
56
- assert.strictEqual(actual.prefix, NETWORKS[f.network].bech32);
57
- assert.strictEqual(actual.data.toString('hex'), f.data);
58
- });
59
- });
60
-
61
- fixtures.invalid.bech32.forEach(f => {
62
- it(
63
- 'decode fails for ' + f.address + '(' + f.exception + ')',
64
- () => {
65
- assert.throws(() => {
66
- baddress.fromBech32(f.address);
67
- }, new RegExp(f.exception));
68
- },
69
- );
70
- });
71
- });
72
-
73
- describe('fromOutputScript', () => {
74
- initEccLib(ecc);
75
- fixtures.standard.forEach(f => {
76
- it(
77
- 'encodes ' + f.script.slice(0, 30) + '... (' + f.network + ')',
78
- () => {
79
- const script = bscript.fromASM(f.script);
80
- const address = baddress.fromOutputScript(
81
- script,
82
- NETWORKS[f.network],
83
- );
84
-
85
- assert.strictEqual(
86
- address,
87
- f.base58check || f.bech32!.toLowerCase(),
88
- );
89
- },
90
- );
91
- });
92
-
93
- fixtures.invalid.fromOutputScript.forEach(f => {
94
- it(
95
- 'throws when ' + f.script.slice(0, 30) + '... ' + f.exception,
96
- () => {
97
- const script = bscript.fromASM(f.script);
98
-
99
- assert.throws(() => {
100
- baddress.fromOutputScript(script, undefined);
101
- }, new RegExp(f.exception));
102
- },
103
- );
104
- });
105
- });
106
-
107
- describe('toBase58Check', () => {
108
- fixtures.standard.forEach(f => {
109
- if (!f.base58check) return;
110
-
111
- it('encodes ' + f.hash + ' (' + f.network + ')', () => {
112
- const address = baddress.toBase58Check(
113
- Buffer.from(f.hash, 'hex'),
114
- f.version,
115
- );
116
-
117
- assert.strictEqual(address, f.base58check);
118
- });
119
- });
120
- });
121
-
122
- describe('toBech32', () => {
123
- fixtures.bech32.forEach(f => {
124
- if (!f.address) return;
125
- const data = Buffer.from(f.data, 'hex');
126
-
127
- it('encode ' + f.address, () => {
128
- assert.deepStrictEqual(
129
- baddress.toBech32(data, f.version, f.prefix),
130
- f.address.toLowerCase(),
131
- );
132
- });
133
- });
134
-
135
- // TODO: These fixtures (according to TypeScript) have none of the data used below
136
- fixtures.invalid.bech32.forEach((f: any) => {
137
- if (!f.prefix || f.version === undefined || f.data === undefined)
138
- return;
139
-
140
- it('encode fails (' + f.exception, () => {
141
- assert.throws(() => {
142
- baddress.toBech32(
143
- Buffer.from(f.data, 'hex'),
144
- f.version,
145
- f.prefix,
146
- );
147
- }, new RegExp(f.exception));
148
- });
149
- });
150
- });
151
-
152
- describe('toOutputScript', () => {
153
- fixtures.standard.forEach(f => {
154
- it(
155
- 'decodes ' + f.script.slice(0, 30) + '... (' + f.network + ')',
156
- () => {
157
- const script = baddress.toOutputScript(
158
- (f.base58check || f.bech32)!,
159
- NETWORKS[f.network],
160
- );
161
-
162
- assert.strictEqual(bscript.toASM(script), f.script);
163
- },
164
- );
165
- });
166
-
167
- fixtures.invalid.toOutputScript.forEach(f => {
168
- it('throws when ' + (f.exception || f.paymentException), () => {
169
- const exception =
170
- f.paymentException || `${f.address} ${f.exception}`;
171
- assert.throws(() => {
172
- baddress.toOutputScript(f.address, f.network as any);
173
- }, new RegExp(exception));
174
- });
175
- });
176
- });
177
- });
1
+ import assert from 'assert';
2
+ import { describe, it } from 'mocha';
3
+ import * as ecc from 'tiny-secp256k1';
4
+ import * as baddress from '../src/address.js';
5
+ import * as bscript from '../src/script.js';
6
+ import fixtures from './fixtures/address.json' with { type: 'json' };
7
+
8
+ import { initEccLib, Network } from '../src/index.js';
9
+
10
+ import * as networks from '../src/networks.js';
11
+
12
+ const NETWORKS: Record<string, Network> = Object.assign(
13
+ {
14
+ litecoin: {
15
+ messagePrefix: '\x19Litecoin Signed Message:\n',
16
+ bip32: {
17
+ public: 0x019da462,
18
+ private: 0x019d9cfe,
19
+ },
20
+ pubKeyHash: 0x30,
21
+ scriptHash: 0x32,
22
+ wif: 0xb0,
23
+ },
24
+ },
25
+ networks,
26
+ );
27
+
28
+ describe('address', () => {
29
+ describe('fromBase58Check', () => {
30
+ fixtures.standard.forEach((f) => {
31
+ if (!f.base58check) return;
32
+
33
+ it('decodes ' + f.base58check, () => {
34
+ const decode = baddress.fromBase58Check(f.base58check);
35
+
36
+ assert.strictEqual(decode.version, f.version);
37
+ assert.strictEqual(decode.hash.toString('hex'), f.hash);
38
+ });
39
+ });
40
+
41
+ fixtures.invalid.fromBase58Check.forEach((f) => {
42
+ it('throws on ' + f.exception, () => {
43
+ assert.throws(
44
+ () => {
45
+ baddress.fromBase58Check(f.address);
46
+ },
47
+ new RegExp(f.address + ' ' + f.exception),
48
+ );
49
+ });
50
+ });
51
+ });
52
+
53
+ describe('fromBech32', () => {
54
+ fixtures.standard.forEach((f) => {
55
+ if (!f.bech32) return;
56
+
57
+ it('decodes ' + f.bech32, () => {
58
+ const actual = baddress.fromBech32(f.bech32);
59
+
60
+ assert.strictEqual(actual.version, f.version);
61
+ assert.strictEqual(actual.prefix, NETWORKS[f.network].bech32);
62
+ assert.strictEqual(actual.data.toString('hex'), f.data);
63
+ });
64
+ });
65
+
66
+ fixtures.invalid.bech32.forEach((f) => {
67
+ it('decode fails for ' + f.address + '(' + f.exception + ')', () => {
68
+ assert.throws(() => {
69
+ baddress.fromBech32(f.address);
70
+ }, new RegExp(f.exception));
71
+ });
72
+ });
73
+ });
74
+
75
+ describe('fromOutputScript', () => {
76
+ initEccLib(ecc);
77
+ fixtures.standard.forEach((f) => {
78
+ it('encodes ' + f.script.slice(0, 30) + '... (' + f.network + ')', () => {
79
+ const script = bscript.fromASM(f.script);
80
+ const address = baddress.fromOutputScript(script, NETWORKS[f.network]);
81
+
82
+ assert.strictEqual(address, f.base58check || f.bech32!.toLowerCase());
83
+ });
84
+ });
85
+
86
+ fixtures.invalid.fromOutputScript.forEach((f) => {
87
+ it('throws when ' + f.script.slice(0, 30) + '... ' + f.exception, () => {
88
+ const script = bscript.fromASM(f.script);
89
+
90
+ assert.throws(() => {
91
+ baddress.fromOutputScript(script, undefined);
92
+ }, new RegExp(f.exception));
93
+ });
94
+ });
95
+ });
96
+
97
+ describe('toBase58Check', () => {
98
+ fixtures.standard.forEach((f) => {
99
+ if (!f.base58check) return;
100
+
101
+ it('encodes ' + f.hash + ' (' + f.network + ')', () => {
102
+ const address = baddress.toBase58Check(Buffer.from(f.hash, 'hex'), f.version);
103
+
104
+ assert.strictEqual(address, f.base58check);
105
+ });
106
+ });
107
+ });
108
+
109
+ describe('toBech32', () => {
110
+ fixtures.bech32.forEach((f) => {
111
+ if (!f.address) return;
112
+ const data = Buffer.from(f.data, 'hex');
113
+
114
+ it('encode ' + f.address, () => {
115
+ assert.deepStrictEqual(
116
+ baddress.toBech32(data, f.version, f.prefix),
117
+ f.address.toLowerCase(),
118
+ );
119
+ });
120
+ });
121
+
122
+ // TODO: These fixtures (according to TypeScript) have none of the data used below
123
+ fixtures.invalid.bech32.forEach((f: any) => {
124
+ if (!f.prefix || f.version === undefined || f.data === undefined) return;
125
+
126
+ it('encode fails (' + f.exception, () => {
127
+ assert.throws(() => {
128
+ baddress.toBech32(Buffer.from(f.data, 'hex'), f.version, f.prefix);
129
+ }, new RegExp(f.exception));
130
+ });
131
+ });
132
+ });
133
+
134
+ describe('toOutputScript', () => {
135
+ fixtures.standard.forEach((f) => {
136
+ it('decodes ' + f.script.slice(0, 30) + '... (' + f.network + ')', () => {
137
+ const script = baddress.toOutputScript(
138
+ (f.base58check || f.bech32)!,
139
+ NETWORKS[f.network],
140
+ );
141
+
142
+ assert.strictEqual(bscript.toASM(script), f.script);
143
+ });
144
+ });
145
+
146
+ fixtures.invalid.toOutputScript.forEach((f) => {
147
+ it('throws when ' + (f.exception || f.paymentException), () => {
148
+ const exception = f.paymentException || `${f.address} ${f.exception}`;
149
+ assert.throws(() => {
150
+ baddress.toOutputScript(f.address, f.network as any);
151
+ }, new RegExp(exception));
152
+ });
153
+ });
154
+ });
155
+ });