@btc-vision/bitcoin 6.4.0 → 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.
- package/build/address.d.ts +1 -0
- package/build/address.js +56 -8
- package/build/networks.js +6 -6
- package/package.json +1 -1
- package/src/address.ts +71 -9
- package/src/block.ts +233 -233
- package/src/bufferutils.ts +188 -188
- package/src/networks.ts +6 -6
- package/src/psbt/psbtutils.ts +320 -320
- package/src/psbt.ts +2187 -2187
- package/test/address.spec.ts +155 -155
- package/test/bitcoin.core.spec.ts +212 -212
- package/test/block.spec.ts +171 -171
- package/test/bufferutils.spec.ts +450 -450
- package/test/crypto.spec.ts +49 -49
- package/test/integration/addresses.spec.ts +142 -142
- package/test/integration/bip32.spec.ts +130 -130
- package/test/integration/blocks.spec.ts +28 -28
- package/test/integration/cltv.spec.ts +241 -241
- package/test/integration/csv.spec.ts +452 -452
- package/test/integration/payments.spec.ts +110 -110
- package/test/integration/taproot.spec.ts +663 -663
- package/test/integration/transactions.spec.ts +668 -668
- package/test/payments.spec.ts +114 -114
- package/test/payments.utils.ts +165 -165
- package/test/psbt.spec.ts +1285 -1285
- package/test/script.spec.ts +186 -186
- package/test/script_number.spec.ts +26 -26
- package/test/script_signature.spec.ts +66 -66
- package/test/transaction.spec.ts +337 -337
- package/test/ts-node-register.js +7 -7
- package/test/types.spec.ts +53 -53
package/test/address.spec.ts
CHANGED
|
@@ -1,155 +1,155 @@
|
|
|
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
|
-
});
|
|
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
|
+
});
|