bolt01 1.2.5 → 2.0.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 +5 -1
- package/arrays/sort_by_big_int.js +1 -2
- package/big_size/encode_big_size.js +3 -3
- package/package.json +3 -6
- package/test/arrays/test_sort_by_big_int.js +6 -4
- package/test/big_size/test_decode_big_size.js +6 -4
- package/test/big_size/test_encode_big_size.js +5 -3
- package/test/tlv_record/test_decode_tlv_record.js +5 -3
- package/test/tlv_record/test_encode_tlv_record.js +5 -3
- package/test/tlv_stream/test_decode_tlv_stream.js +5 -3
- package/test/tlv_stream/test_encode_tlv_stream.js +5 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
const BN = require('bn.js');
|
|
2
2
|
|
|
3
|
+
const max8BitNumber = BigInt(0xfc);
|
|
4
|
+
const max16BitNumber = BigInt(0xffff);
|
|
5
|
+
const max32BitNumber = BigInt(0xffffffff);
|
|
3
6
|
const tagAsUint8 = n => new BN(n).toString(16, 2);
|
|
4
7
|
const tagAsUint16 = n => `fd${new BN(n).toString(16, 4)}`;
|
|
5
8
|
const tagAsUint32 = n => `fe${new BN(n).toString(16, 8)}`;
|
|
6
9
|
const tagAsUint64 = n => `ff${new BN(n).toString(16, 16)}`;
|
|
7
|
-
const max8BitNumber = BigInt(0xfc);
|
|
8
|
-
const max16BitNumber = BigInt(0xffff);
|
|
9
|
-
const max32BitNumber = BigInt(0xffffffff);
|
|
10
10
|
|
|
11
11
|
/** Given a numeric value, encode it as BOLT 01 "BigSize" bytes
|
|
12
12
|
|
package/package.json
CHANGED
|
@@ -10,11 +10,8 @@
|
|
|
10
10
|
"bn.js": "5.2.1"
|
|
11
11
|
},
|
|
12
12
|
"description": "Lightning Network BOLT-01 methods",
|
|
13
|
-
"devDependencies": {
|
|
14
|
-
"@alexbosworth/tap": "15.0.11"
|
|
15
|
-
},
|
|
16
13
|
"engines": {
|
|
17
|
-
"node": ">=
|
|
14
|
+
"node": ">=16"
|
|
18
15
|
},
|
|
19
16
|
"keywords": [
|
|
20
17
|
"lightning-network"
|
|
@@ -27,7 +24,7 @@
|
|
|
27
24
|
"url": "https://github.com/alexbosworth/bolt01.git"
|
|
28
25
|
},
|
|
29
26
|
"scripts": {
|
|
30
|
-
"test": "
|
|
27
|
+
"test": "npx nyc@15.1.0 node --experimental-test-coverage --test test/arrays/*.js test/big_size/*.js test/tlv_record/*.js test/tlv_stream/*.js"
|
|
31
28
|
},
|
|
32
|
-
"version": "
|
|
29
|
+
"version": "2.0.0"
|
|
33
30
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const {deepStrictEqual} = require('node:assert').strict;
|
|
2
|
+
const test = require('node:test');
|
|
3
|
+
const {throws} = require('node:assert').strict;
|
|
2
4
|
|
|
3
5
|
const {sortByBigInt} = require('./../../arrays');
|
|
4
6
|
|
|
@@ -11,7 +13,7 @@ const tests = [
|
|
|
11
13
|
{
|
|
12
14
|
args: {array: []},
|
|
13
15
|
description: 'An attribute to sort by is required',
|
|
14
|
-
error: '
|
|
16
|
+
error: 'ExpectedAttributeToSortArrayByBigInt',
|
|
15
17
|
},
|
|
16
18
|
{
|
|
17
19
|
args: {array: [{foo: 1}, {foo: 2}, {foo: 3}], attribute: 'foo'},
|
|
@@ -31,13 +33,13 @@ const tests = [
|
|
|
31
33
|
];
|
|
32
34
|
|
|
33
35
|
tests.forEach(({args, description, error, expected}) => {
|
|
34
|
-
return test(description, (
|
|
36
|
+
return test(description, (t, end) => {
|
|
35
37
|
if (!!error) {
|
|
36
38
|
throws(() => sortByBigInt(args), new Error(error), 'Got expected error');
|
|
37
39
|
} else {
|
|
38
40
|
const {sorted} = sortByBigInt(args);
|
|
39
41
|
|
|
40
|
-
|
|
42
|
+
deepStrictEqual(sorted, expected.sorted, 'Array is sorted as expected');
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
return end();
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const {deepStrictEqual} = require('node:assert').strict;
|
|
2
|
+
const test = require('node:test');
|
|
3
|
+
const {throws} = require('node:assert').strict;
|
|
2
4
|
|
|
3
5
|
const {decodeBigSize} = require('./../../');
|
|
4
6
|
|
|
@@ -96,14 +98,14 @@ const tests = [
|
|
|
96
98
|
];
|
|
97
99
|
|
|
98
100
|
tests.forEach(({args, description, error, expected}) => {
|
|
99
|
-
return test(description, (
|
|
101
|
+
return test(description, (t, end) => {
|
|
100
102
|
if (!!error) {
|
|
101
103
|
throws(() => decodeBigSize(args), new Error(error), 'Got error');
|
|
102
104
|
} else {
|
|
103
105
|
const value = decodeBigSize(args);
|
|
104
106
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
+
deepStrictEqual(value.decoded, expected.decoded, 'Got expected result');
|
|
108
|
+
deepStrictEqual(value.length, expected.length, 'Got expected length');
|
|
107
109
|
}
|
|
108
110
|
|
|
109
111
|
return end();
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const {deepStrictEqual} = require('node:assert').strict;
|
|
2
|
+
const test = require('node:test');
|
|
3
|
+
const {throws} = require('node:assert').strict;
|
|
2
4
|
|
|
3
5
|
const {encodeBigSize} = require('./../../');
|
|
4
6
|
|
|
@@ -51,13 +53,13 @@ const tests = [
|
|
|
51
53
|
];
|
|
52
54
|
|
|
53
55
|
tests.forEach(({args, description, error, expected}) => {
|
|
54
|
-
return test(description, (
|
|
56
|
+
return test(description, (t, end) => {
|
|
55
57
|
if (!!error) {
|
|
56
58
|
throws(() => encodeBigSize(args), new Error(error), 'Got error');
|
|
57
59
|
} else {
|
|
58
60
|
const {encoded} = encodeBigSize(args);
|
|
59
61
|
|
|
60
|
-
|
|
62
|
+
deepStrictEqual(encoded, expected.encoded, 'Got expected result');
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
return end();
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const {deepStrictEqual} = require('node:assert').strict;
|
|
2
|
+
const test = require('node:test');
|
|
3
|
+
const {throws} = require('node:assert').strict;
|
|
2
4
|
|
|
3
5
|
const {decodeTlvRecord} = require('./../../');
|
|
4
6
|
|
|
@@ -56,11 +58,11 @@ const tests = [
|
|
|
56
58
|
];
|
|
57
59
|
|
|
58
60
|
tests.forEach(({args, description, error, expected}) => {
|
|
59
|
-
return test(description, (
|
|
61
|
+
return test(description, (t, end) => {
|
|
60
62
|
if (!!error) {
|
|
61
63
|
throws(() => decodeTlvRecord(args), new Error(error), 'Got error');
|
|
62
64
|
} else {
|
|
63
|
-
|
|
65
|
+
deepStrictEqual(decodeTlvRecord(args), expected, 'Got expected result');
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
return end();
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const {deepStrictEqual} = require('node:assert').strict;
|
|
2
|
+
const test = require('node:test');
|
|
3
|
+
const {throws} = require('node:assert').strict;
|
|
2
4
|
|
|
3
5
|
const {encodeTlvRecord} = require('./../../');
|
|
4
6
|
|
|
@@ -16,11 +18,11 @@ const tests = [
|
|
|
16
18
|
];
|
|
17
19
|
|
|
18
20
|
tests.forEach(({args, description, error, expected}) => {
|
|
19
|
-
return test(description, (
|
|
21
|
+
return test(description, (t, end) => {
|
|
20
22
|
if (!!error) {
|
|
21
23
|
throws(() => encodeTlvRecord(args), new Error(error), 'Got error');
|
|
22
24
|
} else {
|
|
23
|
-
|
|
25
|
+
deepStrictEqual(encodeTlvRecord(args), expected, 'Got expected result');
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
return end();
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const {deepStrictEqual} = require('node:assert').strict;
|
|
2
|
+
const test = require('node:test');
|
|
3
|
+
const {throws} = require('node:assert').strict;
|
|
2
4
|
|
|
3
5
|
const {decodeTlvStream} = require('./../../');
|
|
4
6
|
|
|
@@ -26,11 +28,11 @@ const tests = [
|
|
|
26
28
|
];
|
|
27
29
|
|
|
28
30
|
tests.forEach(({args, description, error, expected}) => {
|
|
29
|
-
return test(description, (
|
|
31
|
+
return test(description, (t, end) => {
|
|
30
32
|
if (!!error) {
|
|
31
33
|
throws(() => decodeTlvStream(args), new Error(error), 'Got error');
|
|
32
34
|
} else {
|
|
33
|
-
|
|
35
|
+
deepStrictEqual(decodeTlvStream(args), expected, 'Got expected result');
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
return end();
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
const {
|
|
1
|
+
const {deepStrictEqual} = require('node:assert').strict;
|
|
2
|
+
const test = require('node:test');
|
|
3
|
+
const {throws} = require('node:assert').strict;
|
|
2
4
|
|
|
3
5
|
const {encodeTlvStream} = require('./../../');
|
|
4
6
|
|
|
@@ -31,11 +33,11 @@ const tests = [
|
|
|
31
33
|
];
|
|
32
34
|
|
|
33
35
|
tests.forEach(({args, description, error, expected}) => {
|
|
34
|
-
return test(description, (
|
|
36
|
+
return test(description, (t, end) => {
|
|
35
37
|
if (!!error) {
|
|
36
38
|
throws(() => encodeTlvStream(args), new Error(error), 'Got error');
|
|
37
39
|
} else {
|
|
38
|
-
|
|
40
|
+
deepStrictEqual(encodeTlvStream(args), expected, 'Got expected result');
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
return end();
|