@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.
- 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/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
|
@@ -1,151 +1,130 @@
|
|
|
1
|
-
import
|
|
2
|
-
import BIP32Factory from 'bip32';
|
|
3
|
-
import * as ecc from 'tiny-secp256k1';
|
|
4
|
-
import * as bip39 from 'bip39';
|
|
5
|
-
import { describe, it } from 'mocha';
|
|
6
|
-
import * as bitcoin from '
|
|
7
|
-
|
|
8
|
-
const bip32 = BIP32Factory(ecc);
|
|
9
|
-
|
|
10
|
-
function getAddress(node: any, network?: any): string {
|
|
11
|
-
return bitcoin.payments.p2pkh({ pubkey: node.publicKey, network }).address!;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
describe('bitcoinjs-lib (BIP32)', () => {
|
|
15
|
-
it('can import a BIP32 testnet xpriv and export to WIF', () => {
|
|
16
|
-
const xpriv =
|
|
17
|
-
'tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK';
|
|
18
|
-
const node = bip32.fromBase58(xpriv, bitcoin.networks.testnet);
|
|
19
|
-
|
|
20
|
-
assert.strictEqual(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const
|
|
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
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
// receive addresses
|
|
132
|
-
assert.strictEqual(
|
|
133
|
-
getAddress(root.derivePath("m/0'/0/0")),
|
|
134
|
-
'1AVQHbGuES57wD68AJi7Gcobc3RZrfYWTC',
|
|
135
|
-
);
|
|
136
|
-
assert.strictEqual(
|
|
137
|
-
getAddress(root.derivePath("m/0'/0/1")),
|
|
138
|
-
'1Ad6nsmqDzbQo5a822C9bkvAfrYv9mc1JL',
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
// change addresses
|
|
142
|
-
assert.strictEqual(
|
|
143
|
-
getAddress(root.derivePath("m/0'/1/0")),
|
|
144
|
-
'1349KVc5NgedaK7DvuD4xDFxL86QN1Hvdn',
|
|
145
|
-
);
|
|
146
|
-
assert.strictEqual(
|
|
147
|
-
getAddress(root.derivePath("m/0'/1/1")),
|
|
148
|
-
'1EAvj4edpsWcSer3duybAd4KiR4bCJW5J6',
|
|
149
|
-
);
|
|
150
|
-
});
|
|
151
|
-
});
|
|
1
|
+
import assert from 'assert';
|
|
2
|
+
import { BIP32Factory } from 'bip32';
|
|
3
|
+
import * as ecc from 'tiny-secp256k1';
|
|
4
|
+
import * as bip39 from 'bip39';
|
|
5
|
+
import { describe, it } from 'mocha';
|
|
6
|
+
import * as bitcoin from '../../src/index.js';
|
|
7
|
+
|
|
8
|
+
const bip32 = BIP32Factory(ecc);
|
|
9
|
+
|
|
10
|
+
function getAddress(node: any, network?: any): string {
|
|
11
|
+
return bitcoin.payments.p2pkh({ pubkey: node.publicKey, network }).address!;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
describe('bitcoinjs-lib (BIP32)', () => {
|
|
15
|
+
it('can import a BIP32 testnet xpriv and export to WIF', () => {
|
|
16
|
+
const xpriv =
|
|
17
|
+
'tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK';
|
|
18
|
+
const node = bip32.fromBase58(xpriv, bitcoin.networks.testnet);
|
|
19
|
+
|
|
20
|
+
assert.strictEqual(node.toWIF(), 'cQfoY67cetFNunmBUX5wJiw3VNoYx3gG9U9CAofKE6BfiV1fSRw7');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('can export a BIP32 xpriv, then import it', () => {
|
|
24
|
+
const mnemonic =
|
|
25
|
+
'praise you muffin lion enable neck grocery crumble super myself license ghost';
|
|
26
|
+
const seed = bip39.mnemonicToSeedSync(mnemonic);
|
|
27
|
+
const node = bip32.fromSeed(seed);
|
|
28
|
+
const strng = node.toBase58();
|
|
29
|
+
const restored = bip32.fromBase58(strng);
|
|
30
|
+
|
|
31
|
+
assert.strictEqual(getAddress(node), getAddress(restored)); // same public key
|
|
32
|
+
assert.strictEqual(node.toWIF(), restored.toWIF()); // same private key
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('can export a BIP32 xpub', () => {
|
|
36
|
+
const mnemonic =
|
|
37
|
+
'praise you muffin lion enable neck grocery crumble super myself license ghost';
|
|
38
|
+
const seed = bip39.mnemonicToSeedSync(mnemonic);
|
|
39
|
+
const node = bip32.fromSeed(seed);
|
|
40
|
+
const strng = node.neutered().toBase58();
|
|
41
|
+
|
|
42
|
+
assert.strictEqual(
|
|
43
|
+
strng,
|
|
44
|
+
'xpub661MyMwAqRbcGhVeaVfEBA25e3cP9DsJQZoE8iep5fZSxy3TnPBNBgWnMZx56oreNc48ZoTkQfatNJ9VWnQ7ZcLZcVStpaXLTeG8bGrzX3n',
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('can create a BIP32, bitcoin, account 0, external address', () => {
|
|
49
|
+
const path = "m/0'/0/0";
|
|
50
|
+
const root = bip32.fromSeed(
|
|
51
|
+
Buffer.from('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd', 'hex'),
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const child1 = root.derivePath(path);
|
|
55
|
+
|
|
56
|
+
// option 2, manually
|
|
57
|
+
const child1b = root.deriveHardened(0).derive(0).derive(0);
|
|
58
|
+
|
|
59
|
+
assert.strictEqual(getAddress(child1), '1JHyB1oPXufr4FXkfitsjgNB5yRY9jAaa7');
|
|
60
|
+
assert.strictEqual(getAddress(child1b), '1JHyB1oPXufr4FXkfitsjgNB5yRY9jAaa7');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('can create a BIP44, bitcoin, account 0, external address', () => {
|
|
64
|
+
const root = bip32.fromSeed(
|
|
65
|
+
Buffer.from('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd', 'hex'),
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const child1 = root.derivePath("m/44'/0'/0'/0/0");
|
|
69
|
+
|
|
70
|
+
// option 2, manually
|
|
71
|
+
const child1b = root
|
|
72
|
+
.deriveHardened(44)
|
|
73
|
+
.deriveHardened(0)
|
|
74
|
+
.deriveHardened(0)
|
|
75
|
+
.derive(0)
|
|
76
|
+
.derive(0);
|
|
77
|
+
|
|
78
|
+
assert.strictEqual(getAddress(child1), '12Tyvr1U8A3ped6zwMEU5M8cx3G38sP5Au');
|
|
79
|
+
assert.strictEqual(getAddress(child1b), '12Tyvr1U8A3ped6zwMEU5M8cx3G38sP5Au');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('can create a BIP49, bitcoin testnet, account 0, external address', () => {
|
|
83
|
+
const mnemonic =
|
|
84
|
+
'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about';
|
|
85
|
+
const seed = bip39.mnemonicToSeedSync(mnemonic);
|
|
86
|
+
const root = bip32.fromSeed(seed);
|
|
87
|
+
|
|
88
|
+
const path = "m/49'/1'/0'/0/0";
|
|
89
|
+
const child = root.derivePath(path);
|
|
90
|
+
|
|
91
|
+
const { address } = bitcoin.payments.p2sh({
|
|
92
|
+
redeem: bitcoin.payments.p2wpkh({
|
|
93
|
+
pubkey: child.publicKey,
|
|
94
|
+
network: bitcoin.networks.testnet,
|
|
95
|
+
}),
|
|
96
|
+
network: bitcoin.networks.testnet,
|
|
97
|
+
});
|
|
98
|
+
assert.strictEqual(address, '2Mww8dCYPUpKHofjgcXcBCEGmniw9CoaiD2');
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('can use BIP39 to generate BIP32 addresses', () => {
|
|
102
|
+
// var mnemonic = bip39.generateMnemonic()
|
|
103
|
+
const mnemonic =
|
|
104
|
+
'praise you muffin lion enable neck grocery crumble super myself license ghost';
|
|
105
|
+
assert(bip39.validateMnemonic(mnemonic));
|
|
106
|
+
|
|
107
|
+
const seed = bip39.mnemonicToSeedSync(mnemonic);
|
|
108
|
+
const root = bip32.fromSeed(seed);
|
|
109
|
+
|
|
110
|
+
// receive addresses
|
|
111
|
+
assert.strictEqual(
|
|
112
|
+
getAddress(root.derivePath("m/0'/0/0")),
|
|
113
|
+
'1AVQHbGuES57wD68AJi7Gcobc3RZrfYWTC',
|
|
114
|
+
);
|
|
115
|
+
assert.strictEqual(
|
|
116
|
+
getAddress(root.derivePath("m/0'/0/1")),
|
|
117
|
+
'1Ad6nsmqDzbQo5a822C9bkvAfrYv9mc1JL',
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
// change addresses
|
|
121
|
+
assert.strictEqual(
|
|
122
|
+
getAddress(root.derivePath("m/0'/1/0")),
|
|
123
|
+
'1349KVc5NgedaK7DvuD4xDFxL86QN1Hvdn',
|
|
124
|
+
);
|
|
125
|
+
assert.strictEqual(
|
|
126
|
+
getAddress(root.derivePath("m/0'/1/1")),
|
|
127
|
+
'1EAvj4edpsWcSer3duybAd4KiR4bCJW5J6',
|
|
128
|
+
);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { describe, it } from 'mocha';
|
|
3
|
-
import * as bitcoin from '
|
|
4
|
-
|
|
5
|
-
describe('bitcoinjs-lib (blocks)', () => {
|
|
6
|
-
it('can extract a height from a CoinBase transaction', () => {
|
|
7
|
-
// from 00000000000000000097669cdca131f24d40c4cc7d80eaa65967a2d09acf6ce6
|
|
8
|
-
const txHex =
|
|
9
|
-
'010000000001010000000000000000000000000000000000000000000000000000000' +
|
|
10
|
-
'000000000ffffffff50037f9a07174d696e656420627920416e74506f6f6c685b205a' +
|
|
11
|
-
'2b1f7bfabe6d6d36afe1910eca9405b66f97750940a656e38e2c0312958190ff8e98f' +
|
|
12
|
-
'd16761d220400000000000000aa340000d49f0000ffffffff02b07fc3660000000019' +
|
|
13
|
-
'76a9148349212dc27ce3ab4c5b29b85c4dec643d764b1788ac0000000000000000266' +
|
|
14
|
-
'a24aa21a9ed72d9432948505e3d3062f1307a3f027a5dea846ff85e47159680919c12' +
|
|
15
|
-
'bf1e40012000000000000000000000000000000000000000000000000000000000000' +
|
|
16
|
-
'0000000000000';
|
|
17
|
-
const tx = bitcoin.Transaction.fromHex(txHex);
|
|
18
|
-
|
|
19
|
-
assert.strictEqual(tx.ins.length, 1);
|
|
20
|
-
const script = tx.ins[0].script;
|
|
21
|
-
// bitcoin.script.decompile(script) // returns [] :(
|
|
22
|
-
|
|
23
|
-
assert.strictEqual(script[0], 0x03);
|
|
24
|
-
const heightBuffer = script.slice(1, 4);
|
|
25
|
-
const height = bitcoin.script.number.decode(heightBuffer);
|
|
26
|
-
assert.strictEqual(height, 498303);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
1
|
+
import assert from 'assert';
|
|
2
|
+
import { describe, it } from 'mocha';
|
|
3
|
+
import * as bitcoin from '../../src/index.js';
|
|
4
|
+
|
|
5
|
+
describe('bitcoinjs-lib (blocks)', () => {
|
|
6
|
+
it('can extract a height from a CoinBase transaction', () => {
|
|
7
|
+
// from 00000000000000000097669cdca131f24d40c4cc7d80eaa65967a2d09acf6ce6
|
|
8
|
+
const txHex =
|
|
9
|
+
'010000000001010000000000000000000000000000000000000000000000000000000' +
|
|
10
|
+
'000000000ffffffff50037f9a07174d696e656420627920416e74506f6f6c685b205a' +
|
|
11
|
+
'2b1f7bfabe6d6d36afe1910eca9405b66f97750940a656e38e2c0312958190ff8e98f' +
|
|
12
|
+
'd16761d220400000000000000aa340000d49f0000ffffffff02b07fc3660000000019' +
|
|
13
|
+
'76a9148349212dc27ce3ab4c5b29b85c4dec643d764b1788ac0000000000000000266' +
|
|
14
|
+
'a24aa21a9ed72d9432948505e3d3062f1307a3f027a5dea846ff85e47159680919c12' +
|
|
15
|
+
'bf1e40012000000000000000000000000000000000000000000000000000000000000' +
|
|
16
|
+
'0000000000000';
|
|
17
|
+
const tx = bitcoin.Transaction.fromHex(txHex);
|
|
18
|
+
|
|
19
|
+
assert.strictEqual(tx.ins.length, 1);
|
|
20
|
+
const script = tx.ins[0].script;
|
|
21
|
+
// bitcoin.script.decompile(script) // returns [] :(
|
|
22
|
+
|
|
23
|
+
assert.strictEqual(script[0], 0x03);
|
|
24
|
+
const heightBuffer = script.slice(1, 4);
|
|
25
|
+
const height = bitcoin.script.number.decode(heightBuffer);
|
|
26
|
+
assert.strictEqual(height, 498303);
|
|
27
|
+
});
|
|
28
|
+
});
|