@alexbosworth/blockchain 4.7.2 → 4.9.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 +51 -0
- package/addresses/decode_base58.js +119 -0
- package/addresses/decode_base58_address.js +3 -95
- package/addresses/index.js +2 -0
- package/index.js +4 -0
- package/package.json +12 -2
- package/script/conf/networks.json +22 -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_address.js +0 -70
- 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,54 +0,0 @@
|
|
|
1
|
-
const {deepStrictEqual} = require('node:assert').strict;
|
|
2
|
-
const {throws} = require('node:assert').strict;
|
|
3
|
-
const test = require('node:test');
|
|
4
|
-
|
|
5
|
-
const {hashForP2pkh} = require('./../../');
|
|
6
|
-
|
|
7
|
-
const bufferFromHex = hex => Buffer.from(hex, 'hex');
|
|
8
|
-
|
|
9
|
-
const tests = [
|
|
10
|
-
{
|
|
11
|
-
args: {},
|
|
12
|
-
description: 'A public key is required',
|
|
13
|
-
error: 'ExpectedPublicKeyToDerivePublicKeyHash160',
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
args: {
|
|
17
|
-
key: bufferFromHex('0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8'),
|
|
18
|
-
},
|
|
19
|
-
description: 'A compressed public key is required',
|
|
20
|
-
error: 'ExpectedCompressedPublicKeyToDerivePublicKeyHash160',
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
args: {
|
|
24
|
-
key: bufferFromHex('0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'),
|
|
25
|
-
},
|
|
26
|
-
description: 'A hash is derived for the BIP 173 example public key',
|
|
27
|
-
expected: {
|
|
28
|
-
hash: bufferFromHex('751e76e8199196d454941c45d1b3a323f1433bd6'),
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
args: {
|
|
33
|
-
key: bufferFromHex('025476c2e83188368da1ff3e292e7acafcdb3566bb0ad253f62fc70f07aeee6357'),
|
|
34
|
-
},
|
|
35
|
-
description: 'A hash is derived for the BIP 143 example public key',
|
|
36
|
-
expected: {
|
|
37
|
-
hash: bufferFromHex('1d0f172a0ecb48aee1be1f2687d2963ae33f71a1'),
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
];
|
|
41
|
-
|
|
42
|
-
tests.forEach(({args, description, error, expected}) => {
|
|
43
|
-
return test(description, (t, end) => {
|
|
44
|
-
if (!!error) {
|
|
45
|
-
throws(() => hashForP2pkh(args), new Error(error), 'Got err');
|
|
46
|
-
} else {
|
|
47
|
-
const res = hashForP2pkh(args);
|
|
48
|
-
|
|
49
|
-
deepStrictEqual(res, expected, 'Got expected result');
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return end();
|
|
53
|
-
});
|
|
54
|
-
});
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
const {deepStrictEqual} = require('node:assert').strict;
|
|
2
|
-
const {throws} = require('node:assert').strict;
|
|
3
|
-
const test = require('node:test');
|
|
4
|
-
|
|
5
|
-
const {hashForP2wpkh} = require('./../../');
|
|
6
|
-
|
|
7
|
-
const bufferFromHex = hex => Buffer.from(hex, 'hex');
|
|
8
|
-
|
|
9
|
-
const tests = [
|
|
10
|
-
{
|
|
11
|
-
args: {},
|
|
12
|
-
description: 'A public key is required',
|
|
13
|
-
error: 'ExpectedPublicKeyToDerivePublicKeyHash160',
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
args: {
|
|
17
|
-
key: bufferFromHex('0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8'),
|
|
18
|
-
},
|
|
19
|
-
description: 'A compressed public key is required',
|
|
20
|
-
error: 'ExpectedCompressedPublicKeyToDerivePublicKeyHash160',
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
args: {
|
|
24
|
-
key: bufferFromHex('0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'),
|
|
25
|
-
},
|
|
26
|
-
description: 'A hash is derived for the BIP 173 example public key',
|
|
27
|
-
expected: {
|
|
28
|
-
hash: bufferFromHex('751e76e8199196d454941c45d1b3a323f1433bd6'),
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
args: {
|
|
33
|
-
key: bufferFromHex('025476c2e83188368da1ff3e292e7acafcdb3566bb0ad253f62fc70f07aeee6357'),
|
|
34
|
-
},
|
|
35
|
-
description: 'A hash is derived for the BIP 143 example public key',
|
|
36
|
-
expected: {
|
|
37
|
-
hash: bufferFromHex('1d0f172a0ecb48aee1be1f2687d2963ae33f71a1'),
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
];
|
|
41
|
-
|
|
42
|
-
tests.forEach(({args, description, error, expected}) => {
|
|
43
|
-
return test(description, (t, end) => {
|
|
44
|
-
if (!!error) {
|
|
45
|
-
throws(() => hashForP2wpkh(args), new Error(error), 'Got err');
|
|
46
|
-
} else {
|
|
47
|
-
const res = hashForP2wpkh(args);
|
|
48
|
-
|
|
49
|
-
deepStrictEqual(res, expected, 'Got expected result');
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return end();
|
|
53
|
-
});
|
|
54
|
-
});
|
|
@@ -1,38 +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 {idForBlock} = require('./../../');
|
|
6
|
-
|
|
7
|
-
const hexAsBuffer = hex => Buffer.from(hex, 'hex');
|
|
8
|
-
|
|
9
|
-
const tests = [
|
|
10
|
-
{
|
|
11
|
-
args: {block: ''},
|
|
12
|
-
description: 'A hex encoded block is required',
|
|
13
|
-
error: 'ExpectedHexEncodedBlockToGetIdFor',
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
args: {
|
|
17
|
-
block: '0000002006226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f6ebc0169bfbbf66c1f36b5f203e724805717d5e045579851d3a9cd26c89c6e460ca36364ffff7f200000000001020000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff03510101ffffffff0200f2052a0100000017a914a9974100aeee974a20cda9a2f545704a0ab54fdc870000000000000000266a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf90120000000000000000000000000000000000000000000000000000000000000000000000000',
|
|
18
|
-
},
|
|
19
|
-
description: 'A block id is returned',
|
|
20
|
-
expected: {
|
|
21
|
-
id: '77a525d242a5bb062983a852658c4b917d623e49ef1bdf66e94c9c79d2f2e8fe',
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
];
|
|
25
|
-
|
|
26
|
-
tests.forEach(({args, description, error, expected}) => {
|
|
27
|
-
return test(description, (t, end) => {
|
|
28
|
-
if (!!error) {
|
|
29
|
-
throws(() => idForBlock(args), new Error(error), 'Err');
|
|
30
|
-
} else {
|
|
31
|
-
const res = idForBlock(args);
|
|
32
|
-
|
|
33
|
-
deepEqual(res, expected, 'Got expected result');
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return end();
|
|
37
|
-
});
|
|
38
|
-
});
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
const {deepEqual} = require('node:assert').strict;
|
|
2
|
-
const {throws} = require('node:assert').strict;
|
|
3
|
-
const test = require('node:test');
|
|
4
|
-
|
|
5
|
-
const {noLocktimeIdForTransaction} = require('./../../');
|
|
6
|
-
|
|
7
|
-
const hexAsBuffer = hex => Buffer.from(hex, 'hex');
|
|
8
|
-
|
|
9
|
-
const tests = [
|
|
10
|
-
{
|
|
11
|
-
args: {},
|
|
12
|
-
description: 'A data buffer with a transaction is required',
|
|
13
|
-
error: 'ExpectedDataBufferToReadTransactionDataOutOf',
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
args: {
|
|
17
|
-
buffer: hexAsBuffer('02000000000103ae8caf3aad8861142597a29d6377f524a55f4542d5294c8292ce123a956d3e520000000000ffffffff9cbb1c5531a677b90c489d75a198a14f02d49e554ab9cdaa17bd956b127724570200000000ffffffff9cbb1c5531a677b90c489d75a198a14f02d49e554ab9cdaa17bd956b127724570100000000ffffffff0640420f0000000000160014eaa9b76637b1ad340b6efadf773a73b53637d5b6de91f62901000000225120f4c82416bcb08422c195af995e1d248d1378d8b48dafa9f45bc213b83101d49240420f00000000001600148729d17b2aa507ab19051a028384bc6e0ce25e455e368900000000002251200249ccc5af06fa5642f12d42d2a34bfbb08688d54a9b99d07b98619b35df03b440420f0000000000160014d2d59a8a59f997cbc8888411010faf1658e0e3465e368900000000002251207febd720c78518b52aa1a2443823cc8f55e373910f616e112d5d7bd622fe1ab2024830450221008ac71eff4d7e298941be012fc14f0ac9bf62ae6ffeac13522bb27b5b4108d3aa0220192a69ad6fdb86b1e09c7fdcaaafeb58d25060e44199c734dc0d7d385b5d800d0121029943eaccd3987fa495a6b4f47f2fafeb0521e4e12f39498d9465a564ef75329602483045022100f9cde9adb00c0a6c62dae8604ca750039201288c0dafff952461da3caf05e3ae0220679c01f2518413951de3b62531b1cf36bb92562e3bd4197f0fa6e6e3e231272e0121027326b48c9f2729597e328ab6d05f5af75866e1ffa203fadf78387a3b202ff80d0247304402202550beec478845af2df929abf85708f9fcceaae31377f2e01d803e2acf7b426f022036c312b1e38ca333fe70aa37d3093387ac7486f08438eb8eed323699594468cb012102275a197f7ccfece19cf0532b068b6e38ceceda146e791875ecbdc55500bb7efe00000000'),
|
|
18
|
-
},
|
|
19
|
-
description: 'No locktime id converted at zero locktime',
|
|
20
|
-
expected: {
|
|
21
|
-
id: '341db42c1d42e468b34f7c1f4b02af6932baa2760ad777c557e4e432a61535d0',
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
args: {
|
|
26
|
-
buffer: hexAsBuffer('02000000000103ae8caf3aad8861142597a29d6377f524a55f4542d5294c8292ce123a956d3e520000000000ffffffff9cbb1c5531a677b90c489d75a198a14f02d49e554ab9cdaa17bd956b127724570200000000ffffffff9cbb1c5531a677b90c489d75a198a14f02d49e554ab9cdaa17bd956b127724570100000000ffffffff0640420f0000000000160014eaa9b76637b1ad340b6efadf773a73b53637d5b6de91f62901000000225120f4c82416bcb08422c195af995e1d248d1378d8b48dafa9f45bc213b83101d49240420f00000000001600148729d17b2aa507ab19051a028384bc6e0ce25e455e368900000000002251200249ccc5af06fa5642f12d42d2a34bfbb08688d54a9b99d07b98619b35df03b440420f0000000000160014d2d59a8a59f997cbc8888411010faf1658e0e3465e368900000000002251207febd720c78518b52aa1a2443823cc8f55e373910f616e112d5d7bd622fe1ab20247304402204fcc9416a9e908cba10595b15c7f455dcae87a7201f984fb79812de0ea7f562c02203acda03ae03a8c40ab314820e99ff09b77cf103131f73225cd228d74a4946e990121029943eaccd3987fa495a6b4f47f2fafeb0521e4e12f39498d9465a564ef7532960247304402204cb0db22579d5e2f9aafaaf9c99e3a96fe5f85b39065c9007506bfa686f311b402206f213de9e805010d84b64f31d65e0619114044dac6bb2c17aa7742f7e98d5f400121027326b48c9f2729597e328ab6d05f5af75866e1ffa203fadf78387a3b202ff80d02483045022100cc54a394ccb687a74f463412349a0f2defb7ec139819530ce06ff5392b4094f40220783fbad9afaa90459fa10f2af8a4225bc1027b6b06d7b886c75a836cad603017012102275a197f7ccfece19cf0532b068b6e38ceceda146e791875ecbdc55500bb7efe37000000'),
|
|
27
|
-
},
|
|
28
|
-
description: 'No locktime id converted at non zero locktime',
|
|
29
|
-
expected: {
|
|
30
|
-
id: '341db42c1d42e468b34f7c1f4b02af6932baa2760ad777c557e4e432a61535d0',
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
args: {
|
|
35
|
-
buffer: hexAsBuffer('010000000148c84b39d73d315d9688062359c93bb8bdff77c1cd5875d683f6fa80ae1839651a0000006a4730440220174ba43251b22da52004c0fff73a9f2137b6451c1d2086f0b6a7b7cea893c17f02200e7c36d341432e93abe80e69eed13d918197decdb0a904f245b9ece66ba01bec012102247749b00e239c8be840125258a0e76a82dd7af10615b7675a06d7c6f5c3125dffffffff019e7f05000000000017a914fe5feb6a940b2c302cad971e2c4173ebbbe0ec108700000000'),
|
|
36
|
-
},
|
|
37
|
-
description: 'A non-segwit transaction is converted',
|
|
38
|
-
expected: {
|
|
39
|
-
id: '9eaa27ed0730c9de294d8539525af0f79379961c76e99362410850b122ed3bc9',
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
];
|
|
43
|
-
|
|
44
|
-
tests.forEach(({args, description, error, expected}) => {
|
|
45
|
-
return test(description, (t, end) => {
|
|
46
|
-
if (!!error) {
|
|
47
|
-
throws(() => noLocktimeIdForTransaction(args), new Error(error), 'Err');
|
|
48
|
-
} else {
|
|
49
|
-
const res = noLocktimeIdForTransaction(args);
|
|
50
|
-
|
|
51
|
-
deepEqual(res, expected, 'Got expected result');
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return end();
|
|
55
|
-
});
|
|
56
|
-
});
|
|
@@ -1,38 +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 {previousBlockId} = require('./../../');
|
|
6
|
-
|
|
7
|
-
const hexAsBuffer = hex => Buffer.from(hex, 'hex');
|
|
8
|
-
|
|
9
|
-
const tests = [
|
|
10
|
-
{
|
|
11
|
-
args: {block: ''},
|
|
12
|
-
description: 'A hex encoded block is required',
|
|
13
|
-
error: 'ExpectedHexEncodedBlockToDerivePreviousBlockId',
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
args: {
|
|
17
|
-
block: '00609c32519912209ce3196c09d7a409035874057780d4072fa31adc1f0000000000000090882aac112a7353ffc0cf13ebc8196620bc83c810b03bd5d6678b536a203c4b1a45d264f4422e193e7ea2ab01010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff1a03ceb625012013090909200909200904631e00a3290000000000ffffffff02be40250000000000160014820d4a343a44e915c36494995c2899abe37418930000000000000000266a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf90120000000000000000000000000000000000000000000000000000000000000000000000000',
|
|
18
|
-
},
|
|
19
|
-
description: 'The previous block id is returned',
|
|
20
|
-
expected: {
|
|
21
|
-
previous: '000000000000001fdc1aa32f07d480770574580309a4d7096c19e39c20129951',
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
];
|
|
25
|
-
|
|
26
|
-
tests.forEach(({args, description, error, expected}) => {
|
|
27
|
-
return test(description, (t, end) => {
|
|
28
|
-
if (!!error) {
|
|
29
|
-
throws(() => previousBlockId(args), new Error(error), 'Error returned');
|
|
30
|
-
} else {
|
|
31
|
-
const res = previousBlockId(args);
|
|
32
|
-
|
|
33
|
-
deepEqual(res, expected, 'Got expected result');
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return end();
|
|
37
|
-
});
|
|
38
|
-
});
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
const {deepStrictEqual} = require('node:assert').strict;
|
|
2
|
-
const {throws} = require('node:assert').strict;
|
|
3
|
-
const test = require('node:test');
|
|
4
|
-
|
|
5
|
-
const {compactIntAsNumber} = require('./../../');
|
|
6
|
-
|
|
7
|
-
const tests = [
|
|
8
|
-
{
|
|
9
|
-
args: {encoded: ''},
|
|
10
|
-
description: 'Encoded bytes are expected',
|
|
11
|
-
error: 'ExpectedBufferToConvertCompactIntegerToNumber',
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
args: {encoded: 'ffffffffffffffffff'},
|
|
15
|
-
description: 'Too large numbers are not supported',
|
|
16
|
-
error: 'ExpectedSafeSizeEncodedCompactInteger',
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
args: {encoded: '00', start: 1},
|
|
20
|
-
description: 'A size byte within the encoded bytes is expected',
|
|
21
|
-
error: 'ExpectedCompactIntegerSizeByteToConvertToNumber',
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
args: {encoded: 'fdff'},
|
|
25
|
-
description: 'A complete encoded number is expected',
|
|
26
|
-
error: 'ExpectedFullEncodedCompactIntegerToConvertToNumber',
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
args: {encoded: 'fdfc00'},
|
|
30
|
-
description: 'A two byte encoding of a one byte number is rejected',
|
|
31
|
-
error: 'ExpectedMinimallyEncodedCompactIntegerNumber',
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
args: {encoded: 'feffff0000'},
|
|
35
|
-
description: 'A four byte encoding of a two byte number is rejected',
|
|
36
|
-
error: 'ExpectedMinimallyEncodedCompactIntegerNumber',
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
args: {encoded: 'ffffffffff00000000'},
|
|
40
|
-
description: 'An eight byte encoding of a four byte number is rejected',
|
|
41
|
-
error: 'ExpectedMinimallyEncodedCompactIntegerNumber',
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
args: {encoded: '00'},
|
|
45
|
-
description: 'Smallest possible one byte number decoded',
|
|
46
|
-
expected: {bytes: 1, number: 0},
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
args: {encoded: 'fc'},
|
|
50
|
-
description: 'Largest possible one byte number decoded',
|
|
51
|
-
expected: {bytes: 1, number: 252},
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
args: {encoded: '00fcffffff', start: 1},
|
|
55
|
-
description: 'Largest possible one byte number decoded with offset',
|
|
56
|
-
expected: {bytes: 1, number: 252},
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
args: {encoded: 'fdfd00'},
|
|
60
|
-
description: 'Smallest possible two byte number decoded',
|
|
61
|
-
expected: {bytes: 3, number: 253},
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
args: {encoded: 'fdffff'},
|
|
65
|
-
description: 'Largest possible two byte number decoded',
|
|
66
|
-
expected: {bytes: 3, number: 65535}
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
args: {encoded: 'fe00000100'},
|
|
70
|
-
description: 'Smallest possible four byte number decoded',
|
|
71
|
-
expected: {bytes: 5, number: 65536},
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
args: {encoded: 'feffffffff'},
|
|
75
|
-
description: 'Largest possible four byte number decoded',
|
|
76
|
-
expected: {bytes: 5, number: 4294967295},
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
args: {encoded: 'ff0000000001000000'},
|
|
80
|
-
description: 'Smallest possible eight byte number decoded',
|
|
81
|
-
expected: {bytes: 9, number: 4294967296},
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
args: {encoded: 'ffffffffffffff1f00'},
|
|
85
|
-
description: 'Max safe integer decoded',
|
|
86
|
-
expected: {bytes: 9, number: 9007199254740991},
|
|
87
|
-
},
|
|
88
|
-
];
|
|
89
|
-
|
|
90
|
-
tests.forEach(({args, description, error, expected}) => {
|
|
91
|
-
return test(description, (t, end) => {
|
|
92
|
-
args.encoded = !!args.encoded ? Buffer.from(args.encoded, 'hex') : null;
|
|
93
|
-
|
|
94
|
-
if (!!error) {
|
|
95
|
-
throws(() => compactIntAsNumber(args), new Error(error), 'Error');
|
|
96
|
-
} else {
|
|
97
|
-
const res = compactIntAsNumber(args);
|
|
98
|
-
|
|
99
|
-
deepStrictEqual(res, expected, 'Got expected result');
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return end();
|
|
103
|
-
});
|
|
104
|
-
});
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
const {deepStrictEqual} = require('node:assert').strict;
|
|
2
|
-
const {throws} = require('node:assert').strict;
|
|
3
|
-
const test = require('node:test');
|
|
4
|
-
|
|
5
|
-
const {encodePushBytesCount} = require('./../../numbers');
|
|
6
|
-
|
|
7
|
-
const tests = [
|
|
8
|
-
{
|
|
9
|
-
args: {},
|
|
10
|
-
description: 'A count number is required',
|
|
11
|
-
error: 'ExpectedPushBytesCountNumberToEncode',
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
args: {count: -1},
|
|
15
|
-
description: 'A non-negative count number is required',
|
|
16
|
-
error: 'ExpectedPushBytesCountNumberToEncode',
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
args: {count: 1.5},
|
|
20
|
-
description: 'An integer count number is required',
|
|
21
|
-
error: 'ExpectedPushBytesCountNumberToEncode',
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
args: {count: 4294967296},
|
|
25
|
-
description: 'A count beyond OP_PUSHDATA4 size is rejected',
|
|
26
|
-
error: 'UnexpectedlyLargePushBytesCountToEncode',
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
args: {count: 0},
|
|
30
|
-
description: 'A zero count is encoded as a direct byte',
|
|
31
|
-
expected: {encoded: Buffer.from('00', 'hex')},
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
args: {count: 75},
|
|
35
|
-
description: 'The largest direct push count is encoded as a direct byte',
|
|
36
|
-
expected: {encoded: Buffer.from('4b', 'hex')},
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
args: {count: 76},
|
|
40
|
-
description: 'The smallest OP_PUSHDATA1 count is encoded',
|
|
41
|
-
expected: {encoded: Buffer.from('4c4c', 'hex')},
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
args: {count: 255},
|
|
45
|
-
description: 'The largest OP_PUSHDATA1 count is encoded',
|
|
46
|
-
expected: {encoded: Buffer.from('4cff', 'hex')},
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
args: {count: 256},
|
|
50
|
-
description: 'The smallest OP_PUSHDATA2 count is encoded',
|
|
51
|
-
expected: {encoded: Buffer.from('4d0001', 'hex')},
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
args: {count: 65535},
|
|
55
|
-
description: 'The largest OP_PUSHDATA2 count is encoded',
|
|
56
|
-
expected: {encoded: Buffer.from('4dffff', 'hex')},
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
args: {count: 65536},
|
|
60
|
-
description: 'The smallest OP_PUSHDATA4 count is encoded',
|
|
61
|
-
expected: {encoded: Buffer.from('4e00000100', 'hex')},
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
args: {count: 4294967295},
|
|
65
|
-
description: 'The largest OP_PUSHDATA4 count is encoded',
|
|
66
|
-
expected: {encoded: Buffer.from('4effffffff', 'hex')},
|
|
67
|
-
},
|
|
68
|
-
];
|
|
69
|
-
|
|
70
|
-
tests.forEach(({args, description, error, expected}) => {
|
|
71
|
-
return test(description, (t, end) => {
|
|
72
|
-
if (!!error) {
|
|
73
|
-
throws(() => encodePushBytesCount(args), new Error(error), 'Got err');
|
|
74
|
-
} else {
|
|
75
|
-
const res = encodePushBytesCount(args);
|
|
76
|
-
|
|
77
|
-
deepStrictEqual(res, expected, 'Got expected result');
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return end();
|
|
81
|
-
});
|
|
82
|
-
});
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
const {deepStrictEqual} = require('node:assert').strict;
|
|
2
|
-
const {throws} = require('node:assert').strict;
|
|
3
|
-
const test = require('node:test');
|
|
4
|
-
|
|
5
|
-
const {numberAsCompactInt} = require('./../../');
|
|
6
|
-
|
|
7
|
-
const tests = [
|
|
8
|
-
{
|
|
9
|
-
args: {number: 0.1},
|
|
10
|
-
description: 'Fractional numbers are not allowed',
|
|
11
|
-
error: 'ExpectedEncodeSafeNumberToEncodeAsCompactInteger',
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
args: {number: -1},
|
|
15
|
-
description: 'Negative numbers are not allowed',
|
|
16
|
-
error: 'ExpectedNonNegativeNumberToEncodeAsCompactInteger',
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
args: {number: Number.MAX_SAFE_INTEGER + 1},
|
|
20
|
-
description: 'Large numbers are not allowed',
|
|
21
|
-
error: 'ExpectedEncodeSafeNumberToEncodeAsCompactInteger',
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
args: {number: 0},
|
|
25
|
-
description: 'Smallest possible one byte number encoded',
|
|
26
|
-
expected: '00',
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
args: {number: 252},
|
|
30
|
-
description: 'Largest possible one byte number encoded',
|
|
31
|
-
expected: 'fc',
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
args: {number: 253},
|
|
35
|
-
description: 'Smallest possible two byte number encoded',
|
|
36
|
-
expected: 'fdfd00',
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
args: {number: 65535},
|
|
40
|
-
description: 'Largest possible two byte number encoded',
|
|
41
|
-
expected: 'fdffff',
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
args: {number: 65536},
|
|
45
|
-
description: 'Smallest possible four byte number encoded',
|
|
46
|
-
expected: 'fe00000100',
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
args: {number: 4294967295},
|
|
50
|
-
description: 'Largest possible four byte number encoded',
|
|
51
|
-
expected: 'feffffffff',
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
args: {number: 4294967296},
|
|
55
|
-
description: 'Smallest possible eight byte number encoded',
|
|
56
|
-
expected: 'ff0000000001000000',
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
args: {number: 9007199254740991},
|
|
60
|
-
description: 'Max safe integer encoded',
|
|
61
|
-
expected: 'ffffffffffffff1f00',
|
|
62
|
-
},
|
|
63
|
-
];
|
|
64
|
-
|
|
65
|
-
tests.forEach(({args, description, error, expected}) => {
|
|
66
|
-
return test(description, (t, end) => {
|
|
67
|
-
if (!!error) {
|
|
68
|
-
throws(() => numberAsCompactInt(args), new Error(error), 'Error');
|
|
69
|
-
} else {
|
|
70
|
-
const res = numberAsCompactInt(args);
|
|
71
|
-
|
|
72
|
-
deepStrictEqual(res.encoded.toString('hex'), expected, 'Got result');
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return end();
|
|
76
|
-
});
|
|
77
|
-
});
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
const {deepStrictEqual} = require('node:assert').strict;
|
|
2
|
-
const {throws} = require('node:assert').strict;
|
|
3
|
-
const test = require('node:test');
|
|
4
|
-
|
|
5
|
-
const {numberAsLittleEndian} = require('./../../numbers');
|
|
6
|
-
|
|
7
|
-
const tests = [
|
|
8
|
-
{
|
|
9
|
-
args: {bytes: 7, number: 1},
|
|
10
|
-
description: 'A supported bytes count is required',
|
|
11
|
-
error: 'ExpectedBytesCountToEncodeNumberAsLittleEndian',
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
args: {bytes: 4, number: '1'},
|
|
15
|
-
description: 'A number to encode is required',
|
|
16
|
-
error: 'ExpectedNumberToEncodeAsLittleEndianBytes',
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
args: {bytes: 1, number: 256},
|
|
20
|
-
description: 'A number within the byte range is required',
|
|
21
|
-
error: 'ExpectedNumberInByteRangeToEncodeAsLittleEndian',
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
args: {bytes: 4, number: -1},
|
|
25
|
-
description: 'A negative number requires the signed flag',
|
|
26
|
-
error: 'ExpectedNumberInByteRangeToEncodeAsLittleEndian',
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
args: {bytes: 4, is_signed: true, number: -2147483649},
|
|
30
|
-
description: 'A negative number within the byte range is required',
|
|
31
|
-
error: 'ExpectedNumberInByteRangeToEncodeAsLittleEndian',
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
args: {bytes: 4, is_signed: true, number: 2147483648},
|
|
35
|
-
description: 'A signed number within the signed range is required',
|
|
36
|
-
error: 'ExpectedNumberInByteRangeToEncodeAsLittleEndian',
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
args: {bytes: 1, number: 255},
|
|
40
|
-
description: 'A single byte number is encoded',
|
|
41
|
-
expected: {encoded: Buffer.from('ff', 'hex')},
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
args: {bytes: 4, number: 16843009},
|
|
45
|
-
description: 'A four byte number is encoded as little endian',
|
|
46
|
-
expected: {encoded: Buffer.from('01010101', 'hex')},
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
args: {bytes: 4, is_signed: true, number: -1},
|
|
50
|
-
description: 'A negative number is encoded as twos complement',
|
|
51
|
-
expected: {encoded: Buffer.from('ffffffff', 'hex')},
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
args: {bytes: 8, number: 987654321},
|
|
55
|
-
description: 'An eight byte number is encoded as little endian',
|
|
56
|
-
expected: {encoded: Buffer.from('b168de3a00000000', 'hex')},
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
args: {bytes: 8, is_signed: true, number: -1},
|
|
60
|
-
description: 'A negative eight byte number is encoded as twos complement',
|
|
61
|
-
expected: {encoded: Buffer.from('ffffffffffffffff', 'hex')},
|
|
62
|
-
},
|
|
63
|
-
];
|
|
64
|
-
|
|
65
|
-
tests.forEach(({args, description, error, expected}) => {
|
|
66
|
-
return test(description, (t, end) => {
|
|
67
|
-
if (!!error) {
|
|
68
|
-
throws(() => numberAsLittleEndian(args), new Error(error), 'Got error');
|
|
69
|
-
} else {
|
|
70
|
-
const res = numberAsLittleEndian(args);
|
|
71
|
-
|
|
72
|
-
deepStrictEqual(res, expected, 'Got expected result');
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return end();
|
|
76
|
-
});
|
|
77
|
-
});
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
const {deepStrictEqual} = require('node:assert').strict;
|
|
2
|
-
const test = require('node:test');
|
|
3
|
-
|
|
4
|
-
const {parsePushBytesCount} = require('./../../numbers');
|
|
5
|
-
|
|
6
|
-
const hexAsBuffer = hex => Buffer.from(hex, 'hex');
|
|
7
|
-
|
|
8
|
-
const tests = [
|
|
9
|
-
{
|
|
10
|
-
args: {offset: 0, script: hexAsBuffer('4f00000000')},
|
|
11
|
-
description: 'An unsupported op code is not parsed as a push',
|
|
12
|
-
expected: undefined,
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
args: {offset: 0, script: hexAsBuffer('00')},
|
|
16
|
-
description: 'A zero byte count is parsed as a direct push',
|
|
17
|
-
expected: {bytes: hexAsBuffer('00'), count: 0},
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
args: {offset: 0, script: hexAsBuffer('4b' + 'ff'.repeat(75))},
|
|
21
|
-
description: 'The largest direct push byte count is parsed',
|
|
22
|
-
expected: {bytes: hexAsBuffer('4b'), count: 75},
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
args: {offset: 0, script: hexAsBuffer('4c4c' + 'ff'.repeat(76))},
|
|
26
|
-
description: 'An OP_PUSHDATA1 byte count is parsed',
|
|
27
|
-
expected: {bytes: hexAsBuffer('4c4c'), count: 76},
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
args: {offset: 0, script: hexAsBuffer('4c')},
|
|
31
|
-
description: 'An OP_PUSHDATA1 without a length byte is not parsed',
|
|
32
|
-
expected: {},
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
args: {offset: 0, script: hexAsBuffer('4d0001' + 'ff'.repeat(256))},
|
|
36
|
-
description: 'An OP_PUSHDATA2 byte count is parsed',
|
|
37
|
-
expected: {bytes: hexAsBuffer('4d0001'), count: 256},
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
args: {offset: 0, script: hexAsBuffer('4dff')},
|
|
41
|
-
description: 'An OP_PUSHDATA2 with a short length is not parsed',
|
|
42
|
-
expected: {},
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
args: {offset: 0, script: hexAsBuffer('4e70110100')},
|
|
46
|
-
description: 'An OP_PUSHDATA4 byte count is parsed',
|
|
47
|
-
expected: {bytes: hexAsBuffer('4e70110100'), count: 70000},
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
args: {offset: 0, script: hexAsBuffer('4e112233')},
|
|
51
|
-
description: 'An OP_PUSHDATA4 with a short length is not parsed',
|
|
52
|
-
expected: {},
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
args: {offset: 2, script: hexAsBuffer('ffff4c4c')},
|
|
56
|
-
description: 'A push byte count is parsed at an offset',
|
|
57
|
-
expected: {bytes: hexAsBuffer('4c4c'), count: 76},
|
|
58
|
-
},
|
|
59
|
-
];
|
|
60
|
-
|
|
61
|
-
tests.forEach(({args, description, expected}) => {
|
|
62
|
-
return test(description, (t, end) => {
|
|
63
|
-
deepStrictEqual(parsePushBytesCount(args), expected, 'Got expected');
|
|
64
|
-
|
|
65
|
-
return end();
|
|
66
|
-
});
|
|
67
|
-
});
|