@alexbosworth/blockchain 4.8.0 → 4.10.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/CHANGELOG.md +8 -0
- package/README.md +34 -0
- package/index.js +2 -0
- package/package.json +12 -2
- package/script/conf/networks.json +27 -0
- package/script/index.js +2 -0
- package/script/output_script_for_address.js +96 -0
- package/.gitattributes +0 -1
- package/.tm_properties +0 -1
- package/test/5bit/test_bytes_as_words.js +0 -49
- package/test/5bit/test_words_as_bytes.js +0 -79
- package/test/addresses/test_bech32_type.js +0 -29
- package/test/addresses/test_decode_base58.js +0 -109
- package/test/addresses/test_decode_base58_address.js +0 -94
- package/test/addresses/test_decode_bech32.js +0 -49
- package/test/addresses/test_decode_bech32_address.js +0 -188
- package/test/addresses/test_encode_base58_address.js +0 -127
- package/test/addresses/test_encode_bech32.js +0 -69
- package/test/addresses/test_encode_bech32_address.js +0 -167
- package/test/fixtures/tx_invalid.json +0 -397
- package/test/fixtures/tx_valid.json +0 -528
- package/test/hashes/test_hash_for_p2pkh.js +0 -54
- package/test/hashes/test_hash_for_p2wpkh.js +0 -54
- package/test/hashes/test_id_for_block.js +0 -38
- package/test/hashes/test_no_locktime_id_for_transaction.js +0 -56
- package/test/hashes/test_previous_block_id.js +0 -38
- package/test/numbers/test_compact_int_as_number.js +0 -104
- package/test/numbers/test_encode_push_bytes_count.js +0 -82
- package/test/numbers/test_number_as_compact_int.js +0 -77
- package/test/numbers/test_number_as_little_endian.js +0 -77
- package/test/numbers/test_parse_push_bytes_count.js +0 -67
- package/test/script/test_p2ms_script.js +0 -106
- package/test/script/test_p2pkh_output_script.js +0 -41
- package/test/script/test_p2sh_output_script.js +0 -41
- package/test/script/test_p2tr_output_script.js +0 -43
- package/test/script/test_p2wpkh_output_script.js +0 -41
- package/test/script/test_p2wsh_output_script.js +0 -43
- package/test/script/test_script_as_script_elements.js +0 -84
- package/test/script/test_script_elements_as_script.js +0 -72
- package/test/transactions/test_components_of_transaction.js +0 -352
- package/test/transactions/test_core_tx_vectors.js +0 -70
- package/test/transactions/test_id_for_transaction.js +0 -72
- package/test/transactions/test_non_witness_hash_to_sign.js +0 -404
- package/test/transactions/test_query_transactions.js +0 -87
- package/test/transactions/test_size_of_transaction.js +0 -84
- package/test/transactions/test_transaction_from_components.js +0 -281
- package/test/transactions/test_unsigned_tx_from_psbt.js +0 -89
- package/test/transactions/test_v0_hash_to_sign.js +0 -262
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
const {deepEqual} = require('node:assert').strict;
|
|
2
|
-
const test = require('node:test');
|
|
3
|
-
const {throws} = require('node:assert').strict;
|
|
4
|
-
|
|
5
|
-
const {decodeBech32Address} = require('./../../');
|
|
6
|
-
|
|
7
|
-
const hexAsBuffer = hex => Buffer.from(hex, 'hex');
|
|
8
|
-
|
|
9
|
-
const tests = [
|
|
10
|
-
{
|
|
11
|
-
args: {
|
|
12
|
-
address: 'tc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vq5zuyut',
|
|
13
|
-
},
|
|
14
|
-
description: 'Invalid human-readable part',
|
|
15
|
-
error: 'ExpectedKnownBech32AddressPrefixToDecodeBech32',
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
args: {
|
|
19
|
-
address: 'bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqh2y7hd',
|
|
20
|
-
},
|
|
21
|
-
description: 'Invalid checksum (Bech32 instead of Bech32m)',
|
|
22
|
-
error: 'ExpectedUseOfLaterVersionBech32PostInitialSegwit',
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
args: {
|
|
26
|
-
address: 'tb1z0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqglt7rf',
|
|
27
|
-
},
|
|
28
|
-
description: 'Invalid tb checksum (Bech32 instead of Bech32m)',
|
|
29
|
-
error: 'ExpectedUseOfLaterVersionBech32PostInitialSegwit',
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
args: {
|
|
33
|
-
address: 'BC1S0XLXVLHEMJA6C4DQV22UAPCTQUPFHLXM9H8Z3K2E72Q4K9HCZ7VQ54WELL',
|
|
34
|
-
},
|
|
35
|
-
description: 'Invalid BC checksum (Bech32 instead of Bech32m)',
|
|
36
|
-
error: 'ExpectedUseOfLaterVersionBech32PostInitialSegwit',
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
args: {address: 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kemeawh'},
|
|
40
|
-
description: 'Invalid checksum (Bech32m instead of Bech32)',
|
|
41
|
-
error: 'ExpectedInitialSegwitTypeForInitialSegwitVersion',
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
args: {
|
|
45
|
-
address: 'tb1q0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vq24jc47',
|
|
46
|
-
},
|
|
47
|
-
description: 'Invalid tb checksum (Bech32m instead of Bech32)',
|
|
48
|
-
error: 'ExpectedInitialSegwitTypeForInitialSegwitVersion',
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
args: {
|
|
52
|
-
address: 'bc1p38j9r5y49hruaue7wxjce0updqjuyyx0kh56v8s25huc6995vvpql3jow4',
|
|
53
|
-
},
|
|
54
|
-
description: 'Invalid character in checksum',
|
|
55
|
-
error: 'ExpectedAllKnownCharactersForBech32EncodedString',
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
args: {
|
|
59
|
-
address: 'BC130XLXVLHEMJA6C4DQV22UAPCTQUPFHLXM9H8Z3K2E72Q4K9HCZ7VQ7ZWS8R',
|
|
60
|
-
},
|
|
61
|
-
description: 'Invalid witness version',
|
|
62
|
-
error: 'UnexpectedHighSegwitWitnessVersion',
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
args: {address: 'bc1pw5dgrnzv'},
|
|
66
|
-
description: 'Invalid program length (1 byte)',
|
|
67
|
-
error: 'UnexpectedSizeOfBech32AddressProgram',
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
args: {
|
|
71
|
-
address: 'bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7v8n0nx0muaewav253zgeav',
|
|
72
|
-
},
|
|
73
|
-
description: 'Invalid program length (41 bytes)',
|
|
74
|
-
error: 'UnexpectedSizeOfBech32AddressProgram',
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
args: {address: 'BC1QR508D6QEJXTDG4Y5R3ZARVARYV98GJ9P'},
|
|
78
|
-
description: 'Invalid program length for witness version 0 (per BIP141)',
|
|
79
|
-
error: 'UnexpectedBech32AddressProgramSizeForV0Address',
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
args: {
|
|
83
|
-
address: 'tb1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vq47Zagq',
|
|
84
|
-
},
|
|
85
|
-
description: 'Mixed case',
|
|
86
|
-
error: 'ExpectedSingleCasingStyleForBech32EncodedString',
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
args: {
|
|
90
|
-
address: 'bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7v07qwwzcrf',
|
|
91
|
-
},
|
|
92
|
-
description: 'zero padding of more than 4 bits',
|
|
93
|
-
error: 'ExpectedNoPaddingWordsToConvertToDataBytes',
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
args: {
|
|
97
|
-
address: 'tb1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vpggkg4j',
|
|
98
|
-
},
|
|
99
|
-
description: 'Non-zero padding in 8-to-5 conversion',
|
|
100
|
-
error: 'UnexpectedNonZeroPadding',
|
|
101
|
-
},
|
|
102
|
-
{
|
|
103
|
-
args: {address: 'bc1gmk9yu'},
|
|
104
|
-
description: 'Empty data section',
|
|
105
|
-
error: 'ExpectedNonEmptyWitnessCommitmentDataInBech32Address',
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
args: {address: 'BC1QW508D6QEJXTDG4Y5R3ZARVARY0C5XW7KV8F3T4'},
|
|
109
|
-
description: 'Details are returned for a btc1q address',
|
|
110
|
-
expected: {
|
|
111
|
-
prefix: 'bc',
|
|
112
|
-
program: hexAsBuffer('751e76e8199196d454941c45d1b3a323f1433bd6'),
|
|
113
|
-
version: 0,
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
args: {
|
|
118
|
-
address: 'tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sl5k7',
|
|
119
|
-
},
|
|
120
|
-
description: 'Details are returned for a tb1q address',
|
|
121
|
-
expected: {
|
|
122
|
-
prefix: 'tb',
|
|
123
|
-
program: hexAsBuffer('1863143c14c5166804bd19203356da136c985678cd4d27a1b8c6329604903262'),
|
|
124
|
-
version: 0,
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
args: {
|
|
129
|
-
address: 'bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7kt5nd6y',
|
|
130
|
-
},
|
|
131
|
-
description: 'Details are returned for a bc1p address',
|
|
132
|
-
expected: {
|
|
133
|
-
prefix: 'bc',
|
|
134
|
-
program: hexAsBuffer('751e76e8199196d454941c45d1b3a323f1433bd6751e76e8199196d454941c45d1b3a323f1433bd6'),
|
|
135
|
-
version: 1,
|
|
136
|
-
},
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
args: {address: 'BC1SW50QGDZ25J'},
|
|
140
|
-
description: 'Details are returned for a short bc1 address',
|
|
141
|
-
expected: {prefix: 'bc', program: hexAsBuffer('751e'), version: 16},
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
args: {address: 'bc1zw508d6qejxtdg4y5r3zarvaryvaxxpcs'},
|
|
145
|
-
description: 'Details are returned for a midsize bc1 address',
|
|
146
|
-
expected: {
|
|
147
|
-
prefix: 'bc',
|
|
148
|
-
program: hexAsBuffer('751e76e8199196d454941c45d1b3a323'),
|
|
149
|
-
version: 2,
|
|
150
|
-
},
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
args: {
|
|
154
|
-
address: 'tb1qqqqqp399et2xygdj5xreqhjjvcmzhxw4aywxecjdzew6hylgvsesrxh6hy',
|
|
155
|
-
},
|
|
156
|
-
description: 'Details are returned for a zero starting tb address',
|
|
157
|
-
expected: {
|
|
158
|
-
prefix: 'tb',
|
|
159
|
-
program: hexAsBuffer('000000c4a5cad46221b2a187905e5266362b99d5e91c6ce24d165dab93e86433'),
|
|
160
|
-
version: 0,
|
|
161
|
-
},
|
|
162
|
-
},
|
|
163
|
-
{
|
|
164
|
-
args: {
|
|
165
|
-
address: 'bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqzk5jj0',
|
|
166
|
-
},
|
|
167
|
-
description: 'Details are returned for a bc1 v1 address',
|
|
168
|
-
expected: {
|
|
169
|
-
prefix: 'bc',
|
|
170
|
-
program: hexAsBuffer('79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'),
|
|
171
|
-
version: 1,
|
|
172
|
-
},
|
|
173
|
-
},
|
|
174
|
-
];
|
|
175
|
-
|
|
176
|
-
tests.forEach(({args, description, error, expected}) => {
|
|
177
|
-
return test(description, (t, end) => {
|
|
178
|
-
if (!!error) {
|
|
179
|
-
throws(() => decodeBech32Address(args), new Error(error), 'Err');
|
|
180
|
-
} else {
|
|
181
|
-
const res = decodeBech32Address(args);
|
|
182
|
-
|
|
183
|
-
deepEqual(res, expected, 'Got expected result');
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
return end();
|
|
187
|
-
});
|
|
188
|
-
});
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
const {deepEqual} = require('node:assert').strict;
|
|
2
|
-
const test = require('node:test');
|
|
3
|
-
const {throws} = require('node:assert').strict;
|
|
4
|
-
|
|
5
|
-
const {encodeBase58Address} = require('./../../');
|
|
6
|
-
|
|
7
|
-
const hexAsBuffer = hex => Buffer.from(hex, 'hex');
|
|
8
|
-
|
|
9
|
-
const tests = [
|
|
10
|
-
{
|
|
11
|
-
args: {},
|
|
12
|
-
description: 'A hash is expected',
|
|
13
|
-
error: 'ExpectedOutputHashToEncodeBase58Address',
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
args: {hash: hexAsBuffer('00')},
|
|
17
|
-
description: 'A 20 byte hash is expected',
|
|
18
|
-
error: 'Expected20ByteHashToEncodeBase58Address',
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
args: {hash: hexAsBuffer('404371705fa9bd789a2fcd52d2c580b65d35549d')},
|
|
22
|
-
description: 'A version number is expected',
|
|
23
|
-
error: 'ExpectedScriptVersionNumberToEncodeBase58Address',
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
args: {
|
|
27
|
-
hash: hexAsBuffer('404371705fa9bd789a2fcd52d2c580b65d35549d'),
|
|
28
|
-
version: -1,
|
|
29
|
-
},
|
|
30
|
-
description: 'A non-negative version number is expected',
|
|
31
|
-
error: 'ExpectedScriptVersionNumberToEncodeBase58Address',
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
args: {
|
|
35
|
-
hash: hexAsBuffer('404371705fa9bd789a2fcd52d2c580b65d35549d'),
|
|
36
|
-
version: 1.5,
|
|
37
|
-
},
|
|
38
|
-
description: 'An integer version number is expected',
|
|
39
|
-
error: 'ExpectedScriptVersionNumberToEncodeBase58Address',
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
args: {
|
|
43
|
-
hash: hexAsBuffer('404371705fa9bd789a2fcd52d2c580b65d35549d'),
|
|
44
|
-
version: 256,
|
|
45
|
-
},
|
|
46
|
-
description: 'A single byte version number is expected',
|
|
47
|
-
error: 'UnexpectedHighScriptVersionToEncodeBase58Address',
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
args: {
|
|
51
|
-
hash: hexAsBuffer('404371705fa9bd789a2fcd52d2c580b65d35549d'),
|
|
52
|
-
version: 0,
|
|
53
|
-
},
|
|
54
|
-
description: 'An address is returned for a p2pkh hash and version',
|
|
55
|
-
expected: {address: '16ro3Jptwo4asSevZnsRX6vfRS24TGE6uK'},
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
args: {
|
|
59
|
-
hash: hexAsBuffer('e9c3dd0c07aac76179ebc76a6c78d4d67c6c160a'),
|
|
60
|
-
version: 5,
|
|
61
|
-
},
|
|
62
|
-
description: 'An address is returned for a p2sh hash and version',
|
|
63
|
-
expected: {address: '3P14159f73E4gFr7JterCCQh9QjiTjiZrG'},
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
args: {
|
|
67
|
-
hash: hexAsBuffer('243f1394f44554f4ce3fd68649c19adc483ce924'),
|
|
68
|
-
version: 111,
|
|
69
|
-
},
|
|
70
|
-
description: 'An address is returned for a testnet p2pkh hash and version',
|
|
71
|
-
expected: {address: 'mipcBbFg9gMiCh81Kj8tqqdgoZub1ZJRfn'},
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
args: {
|
|
75
|
-
hash: hexAsBuffer('243f1394f44554f4ce3fd68649c19adc483ce924'),
|
|
76
|
-
version: 196,
|
|
77
|
-
},
|
|
78
|
-
description: 'An address is returned for a testnet p2sh hash and version',
|
|
79
|
-
expected: {address: '2MvYsspbAW1kBiXyNQPSz4VmZJSomMgYyUb'},
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
args: {
|
|
83
|
-
hash: hexAsBuffer('0000000000000000000000000000000000000000'),
|
|
84
|
-
version: 0,
|
|
85
|
-
},
|
|
86
|
-
description: 'Leading zero bytes are preserved as leading ones',
|
|
87
|
-
expected: {address: '1111111111111111111114oLvT2'},
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
args: {
|
|
91
|
-
hash: hexAsBuffer('ffffffffffffffffffffffffffffffffffffffff'),
|
|
92
|
-
version: 0,
|
|
93
|
-
},
|
|
94
|
-
description: 'A maximum value hash is encoded with a zero version',
|
|
95
|
-
expected: {address: '1QLbz7JHiBTspS962RLKV8GndWFwi5j6Qr'},
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
args: {
|
|
99
|
-
hash: hexAsBuffer('0000000000000000000000000000000000000000'),
|
|
100
|
-
version: 255,
|
|
101
|
-
},
|
|
102
|
-
description: 'A minimum value hash is encoded with the maximum version',
|
|
103
|
-
expected: {address: '2mcBp5h1U41ARYXZ6EywGeyQcVdhYP7dFob'},
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
args: {
|
|
107
|
-
hash: hexAsBuffer('ffffffffffffffffffffffffffffffffffffffff'),
|
|
108
|
-
version: 255,
|
|
109
|
-
},
|
|
110
|
-
description: 'A maximum value hash is encoded with the maximum version',
|
|
111
|
-
expected: {address: '2n1XR4oJkmBdJMxhBGQGb96gQ88xUyGML1i'},
|
|
112
|
-
},
|
|
113
|
-
];
|
|
114
|
-
|
|
115
|
-
tests.forEach(({args, description, error, expected}) => {
|
|
116
|
-
return test(description, (t, end) => {
|
|
117
|
-
if (!!error) {
|
|
118
|
-
throws(() => encodeBase58Address(args), new Error(error), 'Err');
|
|
119
|
-
} else {
|
|
120
|
-
const res = encodeBase58Address(args);
|
|
121
|
-
|
|
122
|
-
deepEqual(res, expected, 'Got expected result');
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return end();
|
|
126
|
-
});
|
|
127
|
-
});
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
const {deepEqual} = require('node:assert').strict;
|
|
2
|
-
const test = require('node:test');
|
|
3
|
-
const {throws} = require('node:assert').strict;
|
|
4
|
-
|
|
5
|
-
const encodeBech32 = require('./../../addresses/encode_bech32');
|
|
6
|
-
|
|
7
|
-
const tests = [
|
|
8
|
-
{
|
|
9
|
-
args: {prefix: 'tc', type: 'bech32', words: [0]},
|
|
10
|
-
description: 'A known prefix is expected',
|
|
11
|
-
error: 'ExpectedKnownBech32AddressPrefixToEncodeBech32',
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
args: {prefix: 'bc', type: 'bech32k', words: [0]},
|
|
15
|
-
description: 'A known bech32 type is expected',
|
|
16
|
-
error: 'ExpectedKnownBech32TypeToEncodeBech32String',
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
args: {prefix: 'bc', type: 'bech32'},
|
|
20
|
-
description: 'An array of data words is expected',
|
|
21
|
-
error: 'ExpectedArrayOfDataWordsToEncodeBech32String',
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
args: {prefix: 'bc', type: 'bech32', words: [1.5]},
|
|
25
|
-
description: 'Integer data words are expected',
|
|
26
|
-
error: 'ExpectedIntegerDataWordsToEncodeBech32String',
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
args: {prefix: 'bc', type: 'bech32', words: [NaN]},
|
|
30
|
-
description: 'Numeric data words are expected',
|
|
31
|
-
error: 'ExpectedIntegerDataWordsToEncodeBech32String',
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
args: {prefix: 'bc', type: 'bech32', words: [32]},
|
|
35
|
-
description: 'Data words within the word value range are expected',
|
|
36
|
-
error: 'Expected5BitDataWordValuesToEncodeBech32String',
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
args: {
|
|
40
|
-
prefix: 'bc',
|
|
41
|
-
type: 'bech32',
|
|
42
|
-
words: [
|
|
43
|
-
0, 14, 20, 15, 7, 13, 26, 0, 25, 18, 6, 11, 13, 8, 21, 4, 20, 3, 17,
|
|
44
|
-
2, 29, 3, 12, 29, 3, 4, 15, 24, 20, 6, 14, 30, 22,
|
|
45
|
-
],
|
|
46
|
-
},
|
|
47
|
-
description: 'Words are encoded as a bech32 string',
|
|
48
|
-
expected: {encoded: 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4'},
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
args: {prefix: 'bc', type: 'bech32m', words: [16, 14, 20, 15, 0]},
|
|
52
|
-
description: 'Words are encoded as a bech32m string',
|
|
53
|
-
expected: {encoded: 'bc1sw50qgdz25j'},
|
|
54
|
-
},
|
|
55
|
-
];
|
|
56
|
-
|
|
57
|
-
tests.forEach(({args, description, error, expected}) => {
|
|
58
|
-
return test(description, (t, end) => {
|
|
59
|
-
if (!!error) {
|
|
60
|
-
throws(() => encodeBech32(args), new Error(error), 'Err');
|
|
61
|
-
} else {
|
|
62
|
-
const res = encodeBech32(args);
|
|
63
|
-
|
|
64
|
-
deepEqual(res, expected, 'Got expected result');
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return end();
|
|
68
|
-
});
|
|
69
|
-
});
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
const {deepEqual} = require('node:assert').strict;
|
|
2
|
-
const test = require('node:test');
|
|
3
|
-
const {throws} = require('node:assert').strict;
|
|
4
|
-
|
|
5
|
-
const {encodeBech32Address} = require('./../../');
|
|
6
|
-
|
|
7
|
-
const hexAsBuffer = hex => Buffer.from(hex, 'hex');
|
|
8
|
-
|
|
9
|
-
const tests = [
|
|
10
|
-
{
|
|
11
|
-
args: {prefix: 'bc', version: 0},
|
|
12
|
-
description: 'A witness program is expected',
|
|
13
|
-
error: 'ExpectedWitnessProgramToEncodeBech32Address',
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
args: {prefix: 'bc', program: hexAsBuffer('75'), version: 16},
|
|
17
|
-
description: 'A minimum length witness program is expected',
|
|
18
|
-
error: 'UnexpectedSizeOfProgramToEncodeBech32Address',
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
args: {
|
|
22
|
-
prefix: 'bc',
|
|
23
|
-
program: hexAsBuffer('751e76e8199196d454941c45d1b3a323f1433bd6751e76e8199196d454941c45d1b3a323f1433bd675'),
|
|
24
|
-
version: 1,
|
|
25
|
-
},
|
|
26
|
-
description: 'A maximum length witness program is expected',
|
|
27
|
-
error: 'UnexpectedSizeOfProgramToEncodeBech32Address',
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
args: {
|
|
31
|
-
prefix: 'bc',
|
|
32
|
-
program: hexAsBuffer('751e76e8199196d454941c45d1b3a323f1433bd6'),
|
|
33
|
-
},
|
|
34
|
-
description: 'A witness version is expected',
|
|
35
|
-
error: 'ExpectedKnownWitnessVersionToEncodeBech32Address',
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
args: {
|
|
39
|
-
prefix: 'bc',
|
|
40
|
-
program: hexAsBuffer('751e76e8199196d454941c45d1b3a323f1433bd6'),
|
|
41
|
-
version: 17,
|
|
42
|
-
},
|
|
43
|
-
description: 'A witness version within the known range is expected',
|
|
44
|
-
error: 'UnexpectedHighSegwitWitnessVersion',
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
args: {
|
|
48
|
-
prefix: 'bc',
|
|
49
|
-
program: hexAsBuffer('751e76e8199196d454941c45d1b3a323f1433b'),
|
|
50
|
-
version: 0,
|
|
51
|
-
},
|
|
52
|
-
description: 'A known program length for witness version 0 is expected',
|
|
53
|
-
error: 'UnexpectedBech32AddressProgramSizeForV0Address',
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
args: {
|
|
57
|
-
prefix: 'tc',
|
|
58
|
-
program: hexAsBuffer('751e76e8199196d454941c45d1b3a323f1433bd6'),
|
|
59
|
-
version: 0,
|
|
60
|
-
},
|
|
61
|
-
description: 'A known human readable prefix is expected',
|
|
62
|
-
error: 'ExpectedKnownBech32AddressPrefixToEncodeBech32',
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
args: {
|
|
66
|
-
prefix: 'bc',
|
|
67
|
-
program: hexAsBuffer('751e76e8199196d454941c45d1b3a323f1433bd6'),
|
|
68
|
-
version: 0,
|
|
69
|
-
},
|
|
70
|
-
description: 'An address is encoded for a bc1q output',
|
|
71
|
-
expected: {address: 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4'},
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
args: {
|
|
75
|
-
prefix: 'tb',
|
|
76
|
-
program: hexAsBuffer('1863143c14c5166804bd19203356da136c985678cd4d27a1b8c6329604903262'),
|
|
77
|
-
version: 0,
|
|
78
|
-
},
|
|
79
|
-
description: 'An address is encoded for a tb1q output',
|
|
80
|
-
expected: {
|
|
81
|
-
address: 'tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sl5k7',
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
args: {
|
|
86
|
-
prefix: 'bc',
|
|
87
|
-
program: hexAsBuffer('751e76e8199196d454941c45d1b3a323f1433bd6751e76e8199196d454941c45d1b3a323f1433bd6'),
|
|
88
|
-
version: 1,
|
|
89
|
-
},
|
|
90
|
-
description: 'An address is encoded for a bc1p output',
|
|
91
|
-
expected: {
|
|
92
|
-
address: 'bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7kt5nd6y',
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
args: {prefix: 'bc', program: hexAsBuffer('751e'), version: 16},
|
|
97
|
-
description: 'An address is encoded for a short bc1 output',
|
|
98
|
-
expected: {address: 'bc1sw50qgdz25j'},
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
args: {
|
|
102
|
-
prefix: 'bc',
|
|
103
|
-
program: hexAsBuffer('751e76e8199196d454941c45d1b3a323'),
|
|
104
|
-
version: 2,
|
|
105
|
-
},
|
|
106
|
-
description: 'An address is encoded for a midsize bc1 output',
|
|
107
|
-
expected: {address: 'bc1zw508d6qejxtdg4y5r3zarvaryvaxxpcs'},
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
args: {
|
|
111
|
-
prefix: 'tb',
|
|
112
|
-
program: hexAsBuffer('000000c4a5cad46221b2a187905e5266362b99d5e91c6ce24d165dab93e86433'),
|
|
113
|
-
version: 0,
|
|
114
|
-
},
|
|
115
|
-
description: 'An address is encoded for a zero starting tb output',
|
|
116
|
-
expected: {
|
|
117
|
-
address: 'tb1qqqqqp399et2xygdj5xreqhjjvcmzhxw4aywxecjdzew6hylgvsesrxh6hy',
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
args: {
|
|
122
|
-
prefix: 'tb',
|
|
123
|
-
program: hexAsBuffer('000000c4a5cad46221b2a187905e5266362b99d5e91c6ce24d165dab93e86433'),
|
|
124
|
-
version: 1,
|
|
125
|
-
},
|
|
126
|
-
description: 'An address is encoded for a zero starting tb1 v1 output',
|
|
127
|
-
expected: {
|
|
128
|
-
address: 'tb1pqqqqp399et2xygdj5xreqhjjvcmzhxw4aywxecjdzew6hylgvsesf3hn0c',
|
|
129
|
-
},
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
args: {
|
|
133
|
-
prefix: 'bc',
|
|
134
|
-
program: hexAsBuffer('79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'),
|
|
135
|
-
version: 1,
|
|
136
|
-
},
|
|
137
|
-
description: 'An address is encoded for a bc1 v1 output',
|
|
138
|
-
expected: {
|
|
139
|
-
address: 'bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqzk5jj0',
|
|
140
|
-
},
|
|
141
|
-
},
|
|
142
|
-
{
|
|
143
|
-
args: {
|
|
144
|
-
prefix: 'bcrt',
|
|
145
|
-
program: hexAsBuffer('79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'),
|
|
146
|
-
version: 1,
|
|
147
|
-
},
|
|
148
|
-
description: 'An address is encoded for a bcrt1 regtest v1 output',
|
|
149
|
-
expected: {
|
|
150
|
-
address: 'bcrt1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqc8gma6',
|
|
151
|
-
},
|
|
152
|
-
},
|
|
153
|
-
];
|
|
154
|
-
|
|
155
|
-
tests.forEach(({args, description, error, expected}) => {
|
|
156
|
-
return test(description, (t, end) => {
|
|
157
|
-
if (!!error) {
|
|
158
|
-
throws(() => encodeBech32Address(args), new Error(error), 'Err');
|
|
159
|
-
} else {
|
|
160
|
-
const res = encodeBech32Address(args);
|
|
161
|
-
|
|
162
|
-
deepEqual(res, expected, 'Got expected result');
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return end();
|
|
166
|
-
});
|
|
167
|
-
});
|