lightning 4.10.7 → 4.12.1
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 +10 -0
- package/README.md +2 -0
- package/grpc/protos/lightning.proto +53 -0
- package/grpc/protos/signer.proto +6 -0
- package/grpc/protos/walletkit.proto +10 -0
- package/grpc/protos/walletunlocker.proto +66 -0
- package/index.js +4 -0
- package/lnd_methods/index.js +4 -0
- package/lnd_methods/macaroon/index.d.ts +1 -0
- package/lnd_methods/macaroon/methods.json +9 -0
- package/lnd_methods/macaroon/subscribe_to_rpc_requests.d.ts +143 -0
- package/lnd_methods/offchain/get_failed_payments.d.ts +136 -0
- package/lnd_methods/offchain/index.d.ts +1 -0
- package/lnd_methods/offchain/index.js +4 -0
- package/lnd_methods/offchain/probe_for_route.d.ts +4 -0
- package/lnd_methods/offchain/send_message_to_peer.js +75 -0
- package/lnd_methods/offchain/subscribe_to_pay_via_routes.js +22 -0
- package/lnd_methods/offchain/subscribe_to_peer_messages.js +63 -0
- package/lnd_methods/onchain/propose_channel.d.ts +1 -1
- package/lnd_methods/unauthenticated/get_wallet_status.d.ts +3 -1
- package/lnd_methods/unauthenticated/subscribe_to_wallet_status.d.ts +2 -0
- package/lnd_responses/index.js +2 -0
- package/lnd_responses/rpc_peer_message_as_message.js +44 -0
- package/package.json +6 -6
- package/test/lnd_methods/offchain/test_pay_via_routes.js +11 -9
- package/test/lnd_methods/offchain/test_send_message_to_peer.js +68 -0
- package/test/lnd_methods/offchain/test_subscribe_to_pay_via_routes.js +81 -34
- package/test/lnd_methods/offchain/test_subscribe_to_peer_messages.js +132 -0
- package/test/lnd_methods/offchain/test_subscribe_to_probe_for_route.js +3 -0
- package/test/lnd_responses/test_rpc_peer_message_as_message.js +67 -0
- package/test/protos/protos.json +5 -5
- package/test/typescript/get_failed_payments.test-d.ts +31 -0
- package/test/typescript/subscribe_to_rpc_requests.test-d.ts +46 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
const EventEmitter = require('events');
|
|
2
|
+
|
|
3
|
+
const {test} = require('@alexbosworth/tap');
|
|
4
|
+
|
|
5
|
+
const {subscribeToPeerMessages} = require('./../../../lnd_methods');
|
|
6
|
+
|
|
7
|
+
const makeLnd = overrides => {
|
|
8
|
+
const data = {
|
|
9
|
+
data: Buffer.alloc(1),
|
|
10
|
+
peer: Buffer.alloc(33, 3),
|
|
11
|
+
type: 44444,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
Object.keys(overrides).forEach(k => data[k] = overrides[k]);
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
default: {
|
|
18
|
+
SubscribeCustomMessages: ({}) => {
|
|
19
|
+
const emitter = new EventEmitter();
|
|
20
|
+
|
|
21
|
+
emitter.cancel = () => {};
|
|
22
|
+
|
|
23
|
+
if (overrides.data === undefined) {
|
|
24
|
+
process.nextTick(() => emitter.emit('data', data));
|
|
25
|
+
} else {
|
|
26
|
+
process.nextTick(() => emitter.emit('data', overrides.data));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return emitter;
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const tests = [
|
|
36
|
+
{
|
|
37
|
+
args: {
|
|
38
|
+
lnd: {
|
|
39
|
+
default: {
|
|
40
|
+
SubscribeCustomMessages: ({}) => {
|
|
41
|
+
const emitter = new EventEmitter();
|
|
42
|
+
|
|
43
|
+
emitter.cancel = () => {};
|
|
44
|
+
|
|
45
|
+
process.nextTick(() => emitter.emit('end'));
|
|
46
|
+
process.nextTick(() => emitter.emit('status'));
|
|
47
|
+
process.nextTick(() => emitter.emit('error', 'err'));
|
|
48
|
+
|
|
49
|
+
return emitter;
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
description: 'Errors are returned',
|
|
55
|
+
error: 'err',
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
args: {
|
|
59
|
+
lnd: {
|
|
60
|
+
default: {
|
|
61
|
+
SubscribeCustomMessages: ({}) => {
|
|
62
|
+
const emitter = new EventEmitter();
|
|
63
|
+
|
|
64
|
+
emitter.cancel = () => {};
|
|
65
|
+
|
|
66
|
+
process.nextTick(() => emitter.emit('error', {
|
|
67
|
+
details: 'Cancelled on client',
|
|
68
|
+
}));
|
|
69
|
+
|
|
70
|
+
return emitter;
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
description: 'Errors are returned',
|
|
76
|
+
error: {details: 'Cancelled on client'},
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
args: {lnd: makeLnd({peer: null})},
|
|
80
|
+
description: 'A peer is expected',
|
|
81
|
+
error: [503, 'ExpectedPeerPublicKeyBytesToDerivePeerMessage'],
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
args: {lnd: makeLnd({})},
|
|
85
|
+
description: 'Peer message event emitted',
|
|
86
|
+
expected: {
|
|
87
|
+
message: '00',
|
|
88
|
+
public_key: Buffer.alloc(33, 3).toString('hex'),
|
|
89
|
+
type: 44444,
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
];
|
|
93
|
+
|
|
94
|
+
tests.forEach(({args, description, error, expected}) => {
|
|
95
|
+
return test(description, ({end, equal, strictSame, throws}) => {
|
|
96
|
+
try {
|
|
97
|
+
subscribeToPeerMessages({});
|
|
98
|
+
} catch (err) {
|
|
99
|
+
strictSame(
|
|
100
|
+
err,
|
|
101
|
+
new Error('ExpectedLndToSubscribeToPeerMessages'), 'Needs lnd');
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const sub = subscribeToPeerMessages(args);
|
|
105
|
+
|
|
106
|
+
if (!!error) {
|
|
107
|
+
sub.once('error', err => {
|
|
108
|
+
strictSame(err, error, 'Got expected error');
|
|
109
|
+
|
|
110
|
+
subscribeToPeerMessages(args);
|
|
111
|
+
|
|
112
|
+
process.nextTick(() => {
|
|
113
|
+
sub.removeAllListeners();
|
|
114
|
+
|
|
115
|
+
return end();
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
} else {
|
|
119
|
+
if (!expected) {
|
|
120
|
+
return end();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
sub.once('message_received', message => {
|
|
124
|
+
strictSame(message, expected, 'Got message received');
|
|
125
|
+
|
|
126
|
+
return end();
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return;
|
|
131
|
+
});
|
|
132
|
+
});
|
|
@@ -4,6 +4,8 @@ const {getInfoResponse} = require('./../fixtures');
|
|
|
4
4
|
const {queryRoutesResponse} = require('./../fixtures');
|
|
5
5
|
const {subscribeToProbeForRoute} = require('./../../../');
|
|
6
6
|
|
|
7
|
+
const deletePayment = ({}, cbk) => cbk();
|
|
8
|
+
|
|
7
9
|
const expectedRoute = {
|
|
8
10
|
confidence: 1000000,
|
|
9
11
|
fee: 0,
|
|
@@ -41,6 +43,7 @@ const makeLnd = ({count, getInfo, sendToRouteV2}) => {
|
|
|
41
43
|
|
|
42
44
|
const lnd = {
|
|
43
45
|
default: {
|
|
46
|
+
deletePayment,
|
|
44
47
|
getInfo: getInfo || (({}, cbk) => cbk(null, getInfoResponse)),
|
|
45
48
|
queryRoutes: ({}, cbk) => {
|
|
46
49
|
if (returnedRoutes === (count || 1)) {
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const {test} = require('@alexbosworth/tap');
|
|
2
|
+
|
|
3
|
+
const {rpcPeerMessageAsMessage} = require('./../../lnd_responses');
|
|
4
|
+
|
|
5
|
+
const makeArgs = overrides => {
|
|
6
|
+
const response = {
|
|
7
|
+
data: Buffer.alloc(1),
|
|
8
|
+
peer: Buffer.alloc(33, 3),
|
|
9
|
+
type: 44444,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
Object.keys(overrides || {}).forEach(key => response[key] = overrides[key]);
|
|
13
|
+
|
|
14
|
+
return response;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
const makeExpected = overrides => {
|
|
19
|
+
const expected = {
|
|
20
|
+
message: '00',
|
|
21
|
+
public_key: '030303030303030303030303030303030303030303030303030303030303030303',
|
|
22
|
+
type: 44444,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
Object.keys(overrides || {}).forEach(key => expected[key] = overrides[key]);
|
|
26
|
+
|
|
27
|
+
return expected;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const tests = [
|
|
31
|
+
{
|
|
32
|
+
description: 'RPC peer message is expected',
|
|
33
|
+
error: 'ExpectedRpcMessageToDerivePeerMessage',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
args: makeArgs({data: undefined}),
|
|
37
|
+
description: 'data is expected',
|
|
38
|
+
error: 'ExpectedPeerMessageDataToDerivePeerMessage',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
args: makeArgs({peer: undefined}),
|
|
42
|
+
description: 'peer public key is expected',
|
|
43
|
+
error: 'ExpectedPeerPublicKeyBytesToDerivePeerMessage',
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
args: makeArgs({type: undefined}),
|
|
47
|
+
description: 'type is expected',
|
|
48
|
+
error: 'ExpectedCustomMessageTypeNumberToDeriveMessage',
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
args: makeArgs({}),
|
|
52
|
+
description: 'RPC peer message is mapped to message',
|
|
53
|
+
expected: makeExpected({}),
|
|
54
|
+
},
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
tests.forEach(({args, description, error, expected}) => {
|
|
58
|
+
return test(description, ({end, strictSame, throws}) => {
|
|
59
|
+
if (!!error) {
|
|
60
|
+
throws(() => rpcPeerMessageAsMessage(args), new Error(error), 'Got err');
|
|
61
|
+
} else {
|
|
62
|
+
strictSame(rpcPeerMessageAsMessage(args), expected, 'Mapped to message');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return end();
|
|
66
|
+
});
|
|
67
|
+
});
|
package/test/protos/protos.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"overrides": [
|
|
3
|
-
["lightning",
|
|
4
|
-
["lightning",
|
|
5
|
-
["lightning",
|
|
6
|
-
["lightning",
|
|
7
|
-
["lightning",
|
|
3
|
+
["lightning", 1212],
|
|
4
|
+
["lightning", 1218],
|
|
5
|
+
["lightning", 1226],
|
|
6
|
+
["lightning", 1233],
|
|
7
|
+
["lightning", 3431],
|
|
8
8
|
["router", 100],
|
|
9
9
|
["walletkit", 3],
|
|
10
10
|
["walletunlocker", 2]
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {expectError, expectType} from 'tsd';
|
|
2
|
+
import {AuthenticatedLnd} from '../../lnd_grpc';
|
|
3
|
+
import {getFailedPayments, GetFailedPaymentsResult} from '../../lnd_methods';
|
|
4
|
+
|
|
5
|
+
const lnd = {} as AuthenticatedLnd;
|
|
6
|
+
const limit = 1;
|
|
7
|
+
const token = 'token';
|
|
8
|
+
|
|
9
|
+
expectError(getFailedPayments());
|
|
10
|
+
expectError(getFailedPayments({}));
|
|
11
|
+
expectError(getFailedPayments({lnd, limit, token})); // ExpectedNoLimitWhenPagingPayFailuresWithToken
|
|
12
|
+
|
|
13
|
+
expectType<GetFailedPaymentsResult>(await getFailedPayments({lnd}));
|
|
14
|
+
expectType<GetFailedPaymentsResult>(await getFailedPayments({lnd, limit}));
|
|
15
|
+
expectType<GetFailedPaymentsResult>(await getFailedPayments({lnd, token}));
|
|
16
|
+
|
|
17
|
+
expectType<void>(
|
|
18
|
+
getFailedPayments({lnd}, (error, result) => {
|
|
19
|
+
expectType<GetFailedPaymentsResult>(result);
|
|
20
|
+
})
|
|
21
|
+
);
|
|
22
|
+
expectType<void>(
|
|
23
|
+
getFailedPayments({lnd, limit}, (error, result) => {
|
|
24
|
+
expectType<GetFailedPaymentsResult>(result);
|
|
25
|
+
})
|
|
26
|
+
);
|
|
27
|
+
expectType<void>(
|
|
28
|
+
getFailedPayments({lnd, token}, (error, result) => {
|
|
29
|
+
expectType<GetFailedPaymentsResult>(result);
|
|
30
|
+
})
|
|
31
|
+
);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {expectError, expectType} from 'tsd';
|
|
2
|
+
import {AuthenticatedLnd} from '../../lnd_grpc';
|
|
3
|
+
import {
|
|
4
|
+
subscribeToRpcRequests,
|
|
5
|
+
SubscribeToRpcRequestsResult,
|
|
6
|
+
} from '../../lnd_methods';
|
|
7
|
+
|
|
8
|
+
const lnd = {} as AuthenticatedLnd;
|
|
9
|
+
const id = 'id';
|
|
10
|
+
const is_intercepting_close_channel_requests = true;
|
|
11
|
+
const is_intercepting_open_channel_requests = true;
|
|
12
|
+
const is_intercepting_pay_via_routes_requests = true;
|
|
13
|
+
|
|
14
|
+
expectError(subscribeToRpcRequests());
|
|
15
|
+
expectError(subscribeToRpcRequests({}));
|
|
16
|
+
|
|
17
|
+
expectType<SubscribeToRpcRequestsResult>(await subscribeToRpcRequests({lnd}));
|
|
18
|
+
expectType<SubscribeToRpcRequestsResult>(
|
|
19
|
+
await subscribeToRpcRequests({
|
|
20
|
+
lnd,
|
|
21
|
+
id,
|
|
22
|
+
is_intercepting_close_channel_requests,
|
|
23
|
+
is_intercepting_open_channel_requests,
|
|
24
|
+
is_intercepting_pay_via_routes_requests,
|
|
25
|
+
})
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
expectType<void>(
|
|
29
|
+
subscribeToRpcRequests({lnd}, (err, res) => {
|
|
30
|
+
expectType<SubscribeToRpcRequestsResult>(res);
|
|
31
|
+
})
|
|
32
|
+
);
|
|
33
|
+
expectType<void>(
|
|
34
|
+
subscribeToRpcRequests(
|
|
35
|
+
{
|
|
36
|
+
lnd,
|
|
37
|
+
id,
|
|
38
|
+
is_intercepting_close_channel_requests,
|
|
39
|
+
is_intercepting_open_channel_requests,
|
|
40
|
+
is_intercepting_pay_via_routes_requests,
|
|
41
|
+
},
|
|
42
|
+
(err, res) => {
|
|
43
|
+
expectType<SubscribeToRpcRequestsResult>(res);
|
|
44
|
+
}
|
|
45
|
+
)
|
|
46
|
+
);
|