@btc-vision/bitcoin 6.3.5 → 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.
- 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/browser/psbt/psbtutils.d.ts +1 -1
- package/build/address.d.ts +1 -1
- package/build/address.js +12 -5
- 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 +20 -6
- package/src/block.ts +233 -233
- package/src/bufferutils.ts +188 -180
- package/src/index.ts +86 -86
- package/src/networks.ts +12 -0
- package/src/psbt/bip371.ts +441 -441
- package/src/psbt/psbtutils.ts +4 -3
- package/src/psbt.ts +2187 -2187
- package/test/address.spec.ts +155 -177
- package/test/bitcoin.core.spec.ts +212 -234
- package/test/block.spec.ts +171 -194
- package/test/bufferutils.spec.ts +450 -513
- package/test/crypto.spec.ts +49 -55
- package/test/fixtures/address.json +3 -3
- package/test/integration/addresses.spec.ts +142 -154
- package/test/integration/bip32.spec.ts +130 -151
- package/test/integration/blocks.spec.ts +28 -28
- package/test/integration/cltv.spec.ts +241 -283
- package/test/integration/csv.spec.ts +452 -527
- package/test/integration/payments.spec.ts +110 -135
- package/test/integration/taproot.spec.ts +663 -707
- package/test/integration/transactions.spec.ts +668 -769
- package/test/payments.spec.ts +114 -125
- package/test/payments.utils.ts +165 -208
- package/test/psbt.spec.ts +1285 -1414
- package/test/script.spec.ts +186 -210
- package/test/script_number.spec.ts +26 -29
- package/test/script_signature.spec.ts +66 -66
- package/test/transaction.spec.ts +337 -387
- package/test/ts-node-register.js +7 -5
- package/test/tsconfig.json +4 -1
- package/test/types.spec.ts +53 -58
- 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
package/test/address.spec.ts
CHANGED
|
@@ -1,177 +1,155 @@
|
|
|
1
|
-
import
|
|
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
|
|
7
|
-
|
|
8
|
-
import { initEccLib } from '../src';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
fixtures.bech32.forEach(f => {
|
|
124
|
-
if (!f.
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
|
+
});
|