bolt07 1.8.2 → 1.8.4
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 +1 -1
- package/LICENSE +1 -1
- package/package.json +2 -5
- package/routing/route_from_hops.js +10 -12
- package/test/addresses/test_decode_socket.js +4 -2
- package/test/addresses/test_encode_base32.js +41 -0
- package/test/addresses/test_encode_socket.js +4 -2
- package/test/ids/test_chan_format.js +10 -3
- package/test/ids/test_chan_number.js +10 -3
- package/test/ids/test_components_from_buffer.js +3 -2
- package/test/ids/test_decode_chan_id.js +12 -5
- package/test/ids/test_encode_chan_id.js +16 -5
- package/test/ids/test_raw_chan_id.js +10 -3
- package/test/routing/test_hops_from_channels.js +4 -2
- package/test/routing/test_policy_fee.js +5 -3
- package/test/routing/test_route_from_channels.js +4 -2
- package/test/routing/test_route_from_hops.js +4 -2
package/CHANGELOG.md
CHANGED
package/LICENSE
CHANGED
package/package.json
CHANGED
|
@@ -10,9 +10,6 @@
|
|
|
10
10
|
"bn.js": "5.2.1"
|
|
11
11
|
},
|
|
12
12
|
"description": "Utilities for working with bolt07 data formats",
|
|
13
|
-
"devDependencies": {
|
|
14
|
-
"@alexbosworth/tap": "15.0.11"
|
|
15
|
-
},
|
|
16
13
|
"keywords": [
|
|
17
14
|
"bolt",
|
|
18
15
|
"channel-id",
|
|
@@ -29,7 +26,7 @@
|
|
|
29
26
|
"url": "https://github.com/alexbosworth/bolt07.git"
|
|
30
27
|
},
|
|
31
28
|
"scripts": {
|
|
32
|
-
"test": "
|
|
29
|
+
"test": "npx nyc@15.1 node --experimental-test-coverage --test"
|
|
33
30
|
},
|
|
34
|
-
"version": "1.8.
|
|
31
|
+
"version": "1.8.4"
|
|
35
32
|
}
|
|
@@ -58,15 +58,13 @@ const minFee = 0;
|
|
|
58
58
|
}
|
|
59
59
|
*/
|
|
60
60
|
module.exports = args => {
|
|
61
|
-
const {height, hops, mtokens} = args;
|
|
62
|
-
|
|
63
61
|
const finalCltvDelta = args.cltv_delta || defaultCltvBuffer;
|
|
64
62
|
|
|
65
|
-
if (height === undefined) {
|
|
63
|
+
if (args.height === undefined) {
|
|
66
64
|
throw new Error('ExpectedChainHeightForRoute');
|
|
67
65
|
}
|
|
68
66
|
|
|
69
|
-
if (!isArray(hops) || !hops.length) {
|
|
67
|
+
if (!isArray(args.hops) || !args.hops.length) {
|
|
70
68
|
throw new Error('ExpectedHopsToConstructRouteFrom');
|
|
71
69
|
}
|
|
72
70
|
|
|
@@ -74,12 +72,12 @@ module.exports = args => {
|
|
|
74
72
|
throw new Error('ExpectedInitialCltvDeltaToConstructRouteFromHops');
|
|
75
73
|
}
|
|
76
74
|
|
|
77
|
-
if (!mtokens) {
|
|
75
|
+
if (!args.mtokens) {
|
|
78
76
|
throw new Error('ExpectedMillitokensToSendAcrossHops');
|
|
79
77
|
}
|
|
80
78
|
|
|
81
79
|
// Check hops for validity
|
|
82
|
-
hops.forEach((hop, i) => {
|
|
80
|
+
args.hops.forEach((hop, i) => {
|
|
83
81
|
if (hop.base_fee_mtokens === undefined) {
|
|
84
82
|
throw new Error('ExpectedHopBaseFeeMillitokensForRouteConstruction');
|
|
85
83
|
}
|
|
@@ -103,12 +101,12 @@ module.exports = args => {
|
|
|
103
101
|
return;
|
|
104
102
|
});
|
|
105
103
|
|
|
106
|
-
let forwardMtokens = BigInt(mtokens);
|
|
107
|
-
const [firstHop] = hops.slice();
|
|
108
|
-
let timeoutHeight = height + finalCltvDelta;
|
|
104
|
+
let forwardMtokens = BigInt(args.mtokens);
|
|
105
|
+
const [firstHop] = args.hops.slice();
|
|
106
|
+
let timeoutHeight = args.height + finalCltvDelta;
|
|
109
107
|
|
|
110
108
|
// To construct the route, we need to go backwards from the end
|
|
111
|
-
const backwardsPath = hops.slice().reverse().map((hop, i, hops) => {
|
|
109
|
+
const backwardsPath = args.hops.slice().reverse().map((hop, i, hops) => {
|
|
112
110
|
let feeMtokens = BigInt(minFee);
|
|
113
111
|
|
|
114
112
|
if (!!i) {
|
|
@@ -138,9 +136,9 @@ module.exports = args => {
|
|
|
138
136
|
.map(n => BigInt(n.fee_mtokens))
|
|
139
137
|
.reduce((sum, n) => sum + n, BigInt(minFee));
|
|
140
138
|
|
|
141
|
-
const totalMtokens = totalFeeMtokens + BigInt(mtokens);
|
|
139
|
+
const totalMtokens = totalFeeMtokens + BigInt(args.mtokens);
|
|
142
140
|
|
|
143
|
-
if (hops.length === 1) {
|
|
141
|
+
if (args.hops.length === 1) {
|
|
144
142
|
timeoutHeight -= args.initial_cltv;
|
|
145
143
|
}
|
|
146
144
|
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
const
|
|
1
|
+
const strictSame = require('node:assert').strict.deepStrictEqual;
|
|
2
|
+
const test = require('node:test');
|
|
3
|
+
const {throws} = require('node:assert').strict;
|
|
2
4
|
|
|
3
5
|
const {decodeSocket} = require('./../../');
|
|
4
6
|
|
|
@@ -53,7 +55,7 @@ const tests = [
|
|
|
53
55
|
];
|
|
54
56
|
|
|
55
57
|
tests.forEach(({args, description, error, expected}) => {
|
|
56
|
-
return test(description, (
|
|
58
|
+
return test(description, (t, end) => {
|
|
57
59
|
if (!!error) {
|
|
58
60
|
throws(() => decodeSocket(args), new Error(error), 'Got expected error');
|
|
59
61
|
} else {
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const strictSame = require('node:assert').strict.deepStrictEqual;
|
|
2
|
+
const test = require('node:test');
|
|
3
|
+
const {throws} = require('node:assert').strict;
|
|
4
|
+
|
|
5
|
+
const encodeBase32 = require('./../../addresses/encode_base32');
|
|
6
|
+
|
|
7
|
+
const tests = [
|
|
8
|
+
{
|
|
9
|
+
args: {data: ''},
|
|
10
|
+
description: 'Encode nil data as base32',
|
|
11
|
+
expected: {base32: ''},
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
args: {data: '73'},
|
|
15
|
+
description: 'Encode short data as base32',
|
|
16
|
+
expected: {base32: 'om'},
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
args: {
|
|
20
|
+
data: 'f2fc2319bd29457ccd01e8e194ee9bd7e97298b6610df4ab0f3d5baa0b2d7ccf69829edb74edef',
|
|
21
|
+
},
|
|
22
|
+
description: 'Encode long data as base32',
|
|
23
|
+
expected: {
|
|
24
|
+
base32: '6l6cggn5ffcxztib5dqzj3u327uxfgfwmeg7jkyphvn2ucznpthwtau63n2o33y',
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
tests.forEach(({args, description, error, expected}) => {
|
|
30
|
+
return test(description, (t, end) => {
|
|
31
|
+
if (!!error) {
|
|
32
|
+
throws(() => encodeBase32(args), new Error(error), 'Got expected error');
|
|
33
|
+
} else {
|
|
34
|
+
const res = encodeBase32(args);
|
|
35
|
+
|
|
36
|
+
strictSame(res, expected, 'Got expected result');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return end();
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
const
|
|
1
|
+
const strictSame = require('node:assert').strict.deepStrictEqual;
|
|
2
|
+
const test = require('node:test');
|
|
3
|
+
const {throws} = require('node:assert').strict;
|
|
2
4
|
|
|
3
5
|
const {encodeSocket} = require('./../../');
|
|
4
6
|
|
|
@@ -40,7 +42,7 @@ const tests = [
|
|
|
40
42
|
];
|
|
41
43
|
|
|
42
44
|
tests.forEach(({args, description, error, expected}) => {
|
|
43
|
-
return test(description, (
|
|
45
|
+
return test(description, (t, end) => {
|
|
44
46
|
if (!!error) {
|
|
45
47
|
throws(() => encodeSocket(args), new Error(error), 'Got expected error');
|
|
46
48
|
} else {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
const
|
|
1
|
+
const strictSame = require('node:assert').strict.deepStrictEqual;
|
|
2
|
+
const test = require('node:test');
|
|
3
|
+
const {throws} = require('node:assert').strict;
|
|
2
4
|
|
|
3
5
|
const {chanFormat} = require('./../../');
|
|
4
6
|
|
|
@@ -23,6 +25,11 @@ const tests = [
|
|
|
23
25
|
description: 'Standard bitcoin channel',
|
|
24
26
|
expected: {channel: '537136x2080x1'},
|
|
25
27
|
},
|
|
28
|
+
{
|
|
29
|
+
args: {number: '17592186044416000010'},
|
|
30
|
+
description: 'SCID alias type id',
|
|
31
|
+
expected: {channel: '16000000x0x10'},
|
|
32
|
+
},
|
|
26
33
|
{
|
|
27
34
|
args: {},
|
|
28
35
|
description: 'An id or number is required',
|
|
@@ -31,7 +38,7 @@ const tests = [
|
|
|
31
38
|
];
|
|
32
39
|
|
|
33
40
|
tests.forEach(({args, description, error, expected}) => {
|
|
34
|
-
return test(description, (
|
|
41
|
+
return test(description, (t, end) => {
|
|
35
42
|
if (!!error) {
|
|
36
43
|
throws(() => chanFormat(args), new Error(error), 'Got expected error');
|
|
37
44
|
|
|
@@ -40,7 +47,7 @@ tests.forEach(({args, description, error, expected}) => {
|
|
|
40
47
|
|
|
41
48
|
const {channel} = chanFormat(args);
|
|
42
49
|
|
|
43
|
-
|
|
50
|
+
strictSame(channel, expected.channel, 'Channel formatted returned');
|
|
44
51
|
|
|
45
52
|
return end();
|
|
46
53
|
});
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
const
|
|
1
|
+
const strictSame = require('node:assert').strict.deepStrictEqual;
|
|
2
|
+
const test = require('node:test');
|
|
3
|
+
const {throws} = require('node:assert').strict;
|
|
2
4
|
|
|
3
5
|
const {chanNumber} = require('./../../');
|
|
4
6
|
|
|
@@ -23,6 +25,11 @@ const tests = [
|
|
|
23
25
|
description: 'Standard bitcoin channel',
|
|
24
26
|
expected: {number: '590587277833404417'},
|
|
25
27
|
},
|
|
28
|
+
{
|
|
29
|
+
args: {channel: '16000000x0x10'},
|
|
30
|
+
description: 'SCID alias channel id',
|
|
31
|
+
expected: {number: '17592186044416000010'},
|
|
32
|
+
},
|
|
26
33
|
{
|
|
27
34
|
args: {},
|
|
28
35
|
description: 'Channel or id is required',
|
|
@@ -31,7 +38,7 @@ const tests = [
|
|
|
31
38
|
];
|
|
32
39
|
|
|
33
40
|
tests.forEach(({args, description, error, expected}) => {
|
|
34
|
-
return test(description, (
|
|
41
|
+
return test(description, (t, end) => {
|
|
35
42
|
if (!!error) {
|
|
36
43
|
throws(() => chanNumber(args), new Error(error), 'Got expected error');
|
|
37
44
|
|
|
@@ -40,7 +47,7 @@ tests.forEach(({args, description, error, expected}) => {
|
|
|
40
47
|
|
|
41
48
|
const {number} = chanNumber(args);
|
|
42
49
|
|
|
43
|
-
|
|
50
|
+
strictSame(number, expected.number, 'Channel id number returned');
|
|
44
51
|
|
|
45
52
|
return end();
|
|
46
53
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
const
|
|
1
|
+
const test = require('node:test');
|
|
2
|
+
const {throws} = require('node:assert').strict;
|
|
2
3
|
|
|
3
4
|
const componentsFromBuffer = require('./../../ids/components_from_buffer');
|
|
4
5
|
|
|
@@ -16,7 +17,7 @@ const tests = [
|
|
|
16
17
|
];
|
|
17
18
|
|
|
18
19
|
tests.forEach(({args, description, error, expected}) => {
|
|
19
|
-
return test(description, (
|
|
20
|
+
return test(description, (t, end) => {
|
|
20
21
|
if (!!error) {
|
|
21
22
|
throws(() => componentsFromBuffer(args), new Error(error), 'Got error');
|
|
22
23
|
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
const
|
|
1
|
+
const strictSame = require('node:assert').strict.deepStrictEqual;
|
|
2
|
+
const test = require('node:test');
|
|
3
|
+
const {throws} = require('node:assert').strict;
|
|
2
4
|
|
|
3
5
|
const {decodeChanId} = require('./../../');
|
|
4
6
|
|
|
@@ -33,6 +35,11 @@ const tests = [
|
|
|
33
35
|
description: 'Standard bitcoin channel id',
|
|
34
36
|
expected: {block_height: 537136, block_index: 2080, output_index: 1},
|
|
35
37
|
},
|
|
38
|
+
{
|
|
39
|
+
args: {number: '17592186044416000010'},
|
|
40
|
+
description: 'SCID alias channel id',
|
|
41
|
+
expected: {block_height: 16000000, block_index: 0, output_index: 10},
|
|
42
|
+
},
|
|
36
43
|
{
|
|
37
44
|
args: {},
|
|
38
45
|
description: 'Id or channel or number is required',
|
|
@@ -46,7 +53,7 @@ const tests = [
|
|
|
46
53
|
];
|
|
47
54
|
|
|
48
55
|
tests.forEach(({args, description, error, expected}) => {
|
|
49
|
-
return test(description, (
|
|
56
|
+
return test(description, (t, end) => {
|
|
50
57
|
if (!!error) {
|
|
51
58
|
throws(() => decodeChanId(args), new Error(error), 'Got expected err');
|
|
52
59
|
|
|
@@ -55,9 +62,9 @@ tests.forEach(({args, description, error, expected}) => {
|
|
|
55
62
|
|
|
56
63
|
const decoded = decodeChanId(args);
|
|
57
64
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
65
|
+
strictSame(decoded.block_height, expected.block_height, 'Block height');
|
|
66
|
+
strictSame(decoded.block_index, expected.block_index, 'Block index');
|
|
67
|
+
strictSame(decoded.output_index, expected.output_index, 'Output index');
|
|
61
68
|
|
|
62
69
|
return end();
|
|
63
70
|
});
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
const
|
|
1
|
+
const strictSame = require('node:assert').strict.deepStrictEqual;
|
|
2
|
+
const test = require('node:test');
|
|
3
|
+
const {throws} = require('node:assert').strict;
|
|
2
4
|
|
|
3
5
|
const {encodeChanId} = require('./../../');
|
|
4
6
|
|
|
@@ -21,6 +23,15 @@ const tests = [
|
|
|
21
23
|
number: '590587277833404417',
|
|
22
24
|
},
|
|
23
25
|
},
|
|
26
|
+
{
|
|
27
|
+
args: {block_height: 16000000, block_index: 0, output_index: 10},
|
|
28
|
+
description: 'SCID alias channel id',
|
|
29
|
+
expected: {
|
|
30
|
+
channel: '16000000x0x10',
|
|
31
|
+
id: 'f42400000000000a',
|
|
32
|
+
number: '17592186044416000010',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
24
35
|
{
|
|
25
36
|
args: {},
|
|
26
37
|
description: 'Expected block height',
|
|
@@ -39,7 +50,7 @@ const tests = [
|
|
|
39
50
|
];
|
|
40
51
|
|
|
41
52
|
tests.forEach(({args, description, error, expected}) => {
|
|
42
|
-
return test(description, (
|
|
53
|
+
return test(description, (t, end) => {
|
|
43
54
|
if (!!error) {
|
|
44
55
|
throws(() => encodeChanId(args), new Error(error), 'Got expected err');
|
|
45
56
|
|
|
@@ -48,9 +59,9 @@ tests.forEach(({args, description, error, expected}) => {
|
|
|
48
59
|
|
|
49
60
|
const encoded = encodeChanId(args);
|
|
50
61
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
62
|
+
strictSame(encoded.channel, expected.channel, 'Channel components');
|
|
63
|
+
strictSame(encoded.id, expected.id, 'Channel id returned');
|
|
64
|
+
strictSame(encoded.number, expected.number, 'Channel number returned');
|
|
54
65
|
|
|
55
66
|
return end();
|
|
56
67
|
});
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
const
|
|
1
|
+
const strictSame = require('node:assert').strict.deepStrictEqual;
|
|
2
|
+
const test = require('node:test');
|
|
3
|
+
const {throws} = require('node:assert').strict;
|
|
2
4
|
|
|
3
5
|
const {rawChanId} = require('./../../');
|
|
4
6
|
|
|
@@ -23,6 +25,11 @@ const tests = [
|
|
|
23
25
|
description: 'Standard bitcoin channel id',
|
|
24
26
|
expected: {id: '0832300008200001'},
|
|
25
27
|
},
|
|
28
|
+
{
|
|
29
|
+
args: {number: '17592186044416000010'},
|
|
30
|
+
description: 'SCID alias channel id',
|
|
31
|
+
expected: {id: 'f42400000000000a'},
|
|
32
|
+
},
|
|
26
33
|
{
|
|
27
34
|
args: {},
|
|
28
35
|
description: 'Number is required',
|
|
@@ -31,7 +38,7 @@ const tests = [
|
|
|
31
38
|
];
|
|
32
39
|
|
|
33
40
|
tests.forEach(({args, description, error, expected}) => {
|
|
34
|
-
return test(description, (
|
|
41
|
+
return test(description, (t, end) => {
|
|
35
42
|
if (!!error) {
|
|
36
43
|
throws(() => rawChanId(args), new Error(error), 'Got expected error');
|
|
37
44
|
|
|
@@ -40,7 +47,7 @@ tests.forEach(({args, description, error, expected}) => {
|
|
|
40
47
|
|
|
41
48
|
const {id} = rawChanId(args);
|
|
42
49
|
|
|
43
|
-
|
|
50
|
+
strictSame(id, expected.id, 'Raw channel id returned');
|
|
44
51
|
|
|
45
52
|
return end();
|
|
46
53
|
});
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
const
|
|
1
|
+
const strictSame = require('node:assert').strict.deepStrictEqual;
|
|
2
|
+
const test = require('node:test');
|
|
3
|
+
const {throws} = require('node:assert').strict;
|
|
2
4
|
|
|
3
5
|
const betaChannels = require('./../fixtures/graph_beta').channels;
|
|
4
6
|
const charlieChannels = require('./../fixtures/graph_charlie').channels;
|
|
@@ -274,7 +276,7 @@ const tests = [
|
|
|
274
276
|
];
|
|
275
277
|
|
|
276
278
|
tests.forEach(({args, description, error, expected}) => {
|
|
277
|
-
return test(description, (
|
|
279
|
+
return test(description, (t, end) => {
|
|
278
280
|
if (!!error) {
|
|
279
281
|
throws(() => hopsFromChannels(args), new Error(error), 'Got error');
|
|
280
282
|
} else {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
const
|
|
1
|
+
const strictSame = require('node:assert').strict.deepStrictEqual;
|
|
2
|
+
const test = require('node:test');
|
|
3
|
+
const {throws} = require('node:assert').strict;
|
|
2
4
|
|
|
3
5
|
const policyFee = require('./../../routing/policy_fee');
|
|
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(() => policyFee(args), new Error(error), 'Got expected error');
|
|
37
39
|
} else {
|
|
38
|
-
|
|
40
|
+
strictSame(policyFee(args).fee_mtokens, expected.fee_mtokens, 'Fee');
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
return end();
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
const
|
|
1
|
+
const strictSame = require('node:assert').strict.deepStrictEqual;
|
|
2
|
+
const test = require('node:test');
|
|
3
|
+
const {throws} = require('node:assert').strict;
|
|
2
4
|
|
|
3
5
|
const {routeFromChannels} = require('./../../');
|
|
4
6
|
|
|
@@ -938,7 +940,7 @@ const tests = [
|
|
|
938
940
|
];
|
|
939
941
|
|
|
940
942
|
tests.forEach(({args, description, error, expected}) => {
|
|
941
|
-
return test(description, (
|
|
943
|
+
return test(description, (t, end) => {
|
|
942
944
|
if (!!error) {
|
|
943
945
|
throws(() => routeFromChannels(args), new Error(error), 'Got error');
|
|
944
946
|
} else {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
const
|
|
1
|
+
const strictSame = require('node:assert').strict.deepStrictEqual;
|
|
2
|
+
const test = require('node:test');
|
|
3
|
+
const {throws} = require('node:assert').strict;
|
|
2
4
|
|
|
3
5
|
const {routeFromHops} = require('./../../');
|
|
4
6
|
|
|
@@ -340,7 +342,7 @@ const tests = [
|
|
|
340
342
|
];
|
|
341
343
|
|
|
342
344
|
tests.forEach(({args, description, error, expected}) => {
|
|
343
|
-
return test(description, (
|
|
345
|
+
return test(description, (t, end) => {
|
|
344
346
|
if (!!error) {
|
|
345
347
|
throws(() => routeFromHops(args), new Error(error), 'Got expected err');
|
|
346
348
|
} else {
|