lightning 4.11.0 → 4.12.2

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 CHANGED
@@ -1,6 +1,11 @@
1
1
  # Versions
2
2
 
3
- ## 4.11.0
3
+ ## 4.12.2
4
+
5
+ - `probeForRoute`, `subscribeToProbeForRoute`, `subscribeToPayViaRoutes`,
6
+ `payViaRoutes`: When probing (no hash), delete the payment failure record after the probe
7
+
8
+ ## 4.11.1
4
9
 
5
10
  - `getFailedPayments`: Add method to get past failed payments
6
11
  - `subscribeToRpcRequests`: Add method to listen to and interact with RPC requests
@@ -557,6 +557,47 @@ service Lightning {
557
557
  */
558
558
  rpc RegisterRPCMiddleware (stream RPCMiddlewareResponse)
559
559
  returns (stream RPCMiddlewareRequest);
560
+
561
+ /* lncli: `sendcustom`
562
+ SendCustomMessage sends a custom peer message.
563
+ */
564
+ rpc SendCustomMessage (SendCustomMessageRequest)
565
+ returns (SendCustomMessageResponse);
566
+
567
+ /* lncli: `subscribecustom`
568
+ SubscribeCustomMessages subscribes to a stream of incoming custom peer
569
+ messages.
570
+ */
571
+ rpc SubscribeCustomMessages (SubscribeCustomMessagesRequest)
572
+ returns (stream CustomMessage);
573
+ }
574
+
575
+ message SubscribeCustomMessagesRequest {
576
+ }
577
+
578
+ message CustomMessage {
579
+ // Peer from which the message originates
580
+ bytes peer = 1;
581
+
582
+ // Message type. This value will be in the custom range (>= 32768).
583
+ uint32 type = 2;
584
+
585
+ // Raw message data
586
+ bytes data = 3;
587
+ }
588
+
589
+ message SendCustomMessageRequest {
590
+ // Peer to send the message to
591
+ bytes peer = 1;
592
+
593
+ // Message type. This value needs to be in the custom range (>= 32768).
594
+ uint32 type = 2;
595
+
596
+ // Raw message data.
597
+ bytes data = 3;
598
+ }
599
+
600
+ message SendCustomMessageResponse {
560
601
  }
561
602
 
562
603
  message Utxo {
@@ -834,6 +875,9 @@ message ChannelAcceptRequest {
834
875
  // A bit-field which the initiator uses to specify proposed channel
835
876
  // behavior.
836
877
  uint32 channel_flags = 13;
878
+
879
+ // The commitment type the initiator wishes to use for the proposed channel.
880
+ CommitmentType commitment_type = 14;
837
881
  }
838
882
 
839
883
  message ChannelAcceptResponse {
@@ -1188,6 +1232,15 @@ enum CommitmentType {
1188
1232
  been broadcast.
1189
1233
  */
1190
1234
  ANCHORS = 2;
1235
+
1236
+ /*
1237
+ A channel that uses a commitment type that builds upon the anchors
1238
+ commitment format, but in addition requires a CLTV clause to spend outputs
1239
+ paying to the channel initiator. This is intended for use on leased channels
1240
+ to guarantee that the channel initiator has no incentives to close a leased
1241
+ channel before its maturity date.
1242
+ */
1243
+ SCRIPT_ENFORCED_LEASE = 4;
1191
1244
  }
1192
1245
 
1193
1246
  message ChannelConstraints {
@@ -193,6 +193,12 @@ message SignMessageReq {
193
193
 
194
194
  // Double-SHA256 hash instead of just the default single round.
195
195
  bool double_hash = 3;
196
+
197
+ /*
198
+ Use the compact (pubkey recoverable) format instead of the raw lnwire
199
+ format.
200
+ */
201
+ bool compact_sig = 4;
196
202
  }
197
203
  message SignMessageResp {
198
204
  /*
@@ -286,6 +286,16 @@ message AddrRequest {
286
286
  default wallet account is used.
287
287
  */
288
288
  string account = 1;
289
+
290
+ /*
291
+ The type of address to derive.
292
+ */
293
+ AddressType type = 2;
294
+
295
+ /*
296
+ Whether a change address should be derived.
297
+ */
298
+ bool change = 3;
289
299
  }
290
300
  message AddrResponse {
291
301
  /*
@@ -176,6 +176,15 @@ message InitWalletRequest {
176
176
  mainnet).
177
177
  */
178
178
  uint64 extended_master_key_birthday_timestamp = 8;
179
+
180
+ /*
181
+ watch_only is the third option of initializing a wallet: by importing
182
+ account xpubs only and therefore creating a watch-only wallet that does not
183
+ contain any private keys. That means the wallet won't be able to sign for
184
+ any of the keys and _needs_ to be run with a remote signer that has the
185
+ corresponding private keys and can serve signing RPC requests.
186
+ */
187
+ WatchOnly watch_only = 9;
179
188
  }
180
189
  message InitWalletResponse {
181
190
  /*
@@ -188,6 +197,63 @@ message InitWalletResponse {
188
197
  bytes admin_macaroon = 1;
189
198
  }
190
199
 
200
+ message WatchOnly {
201
+ /*
202
+ The unix timestamp in seconds of when the master key was created. lnd will
203
+ only start scanning for funds in blocks that are after the birthday which
204
+ can speed up the process significantly. If the birthday is not known, this
205
+ should be left at its default value of 0 in which case lnd will start
206
+ scanning from the first SegWit block (481824 on mainnet).
207
+ */
208
+ uint64 master_key_birthday_timestamp = 1;
209
+
210
+ /*
211
+ The fingerprint of the root key (also known as the key with derivation path
212
+ m/) from which the account public keys were derived from. This may be
213
+ required by some hardware wallets for proper identification and signing. The
214
+ bytes must be in big-endian order.
215
+ */
216
+ bytes master_key_fingerprint = 2;
217
+
218
+ /*
219
+ The list of accounts to import. There _must_ be an account for all of lnd's
220
+ main key scopes: BIP49/BIP84 (m/49'/0'/0', m/84'/0'/0', note that the
221
+ coin type is always 0, even for testnet/regtest) and lnd's internal key
222
+ scope (m/1017'/<coin_type>'/<account>'), where account is the key family as
223
+ defined in `keychain/derivation.go` (currently indices 0 to 9).
224
+ */
225
+ repeated WatchOnlyAccount accounts = 3;
226
+ }
227
+
228
+ message WatchOnlyAccount {
229
+ /*
230
+ Purpose is the first number in the derivation path, must be either 49, 84
231
+ or 1017.
232
+ */
233
+ uint32 purpose = 1;
234
+
235
+ /*
236
+ Coin type is the second number in the derivation path, this is _always_ 0
237
+ for purposes 49 and 84. It only needs to be set to 1 for purpose 1017 on
238
+ testnet or regtest.
239
+ */
240
+ uint32 coin_type = 2;
241
+
242
+ /*
243
+ Account is the third number in the derivation path. For purposes 49 and 84
244
+ at least the default account (index 0) needs to be created but optional
245
+ additional accounts are allowed. For purpose 1017 there needs to be exactly
246
+ one account for each of the key families defined in `keychain/derivation.go`
247
+ (currently indices 0 to 9)
248
+ */
249
+ uint32 account = 3;
250
+
251
+ /*
252
+ The extended public key at depth 3 for the given account.
253
+ */
254
+ string xpub = 4;
255
+ }
256
+
191
257
  message UnlockWalletRequest {
192
258
  /*
193
259
  wallet_password should be the current valid passphrase for the daemon. This
@@ -84,6 +84,7 @@ const {recoverFundsFromChannels} = require('./offchain');
84
84
  const {removePeer} = require('./peers');
85
85
  const {requestChainFeeIncrease} = require('./onchain');
86
86
  const {revokeAccess} = require('./macaroon');
87
+ const {sendMessageToPeer} = require('./offchain');
87
88
  const {sendToChainAddress} = require('./onchain');
88
89
  const {sendToChainAddresses} = require('./onchain');
89
90
  const {sendToChainOutputScripts} = require('./onchain');
@@ -110,6 +111,7 @@ const {subscribeToPastPayments} = require('./offchain');
110
111
  const {subscribeToPayViaDetails} = require('./offchain');
111
112
  const {subscribeToPayViaRequest} = require('./offchain');
112
113
  const {subscribeToPayViaRoutes} = require('./offchain');
114
+ const {subscribeToPeerMessages} = require('./offchain');
113
115
  const {subscribeToPeers} = require('./peers');
114
116
  const {subscribeToProbeForRoute} = require('./offchain');
115
117
  const {subscribeToRpcRequests} = require('./macaroon');
@@ -214,6 +216,7 @@ module.exports = {
214
216
  removePeer,
215
217
  requestChainFeeIncrease,
216
218
  revokeAccess,
219
+ sendMessageToPeer,
217
220
  sendToChainAddress,
218
221
  sendToChainAddresses,
219
222
  sendToChainOutputScripts,
@@ -240,6 +243,7 @@ module.exports = {
240
243
  subscribeToPayViaDetails,
241
244
  subscribeToPayViaRequest,
242
245
  subscribeToPayViaRoutes,
246
+ subscribeToPeerMessages,
243
247
  subscribeToPeers,
244
248
  subscribeToProbeForRoute,
245
249
  subscribeToRpcRequests,
@@ -334,6 +334,10 @@
334
334
  "method": "DeleteMacaroonId",
335
335
  "type": "default"
336
336
  },
337
+ "sendMessageToPeer": {
338
+ "method": "SendCustomMessage",
339
+ "type": "default"
340
+ },
337
341
  "sendToChainAddress": {
338
342
  "method": "SendCoins",
339
343
  "type": "default"
@@ -439,9 +443,14 @@
439
443
  "type": "router"
440
444
  },
441
445
  "subscribeToPayViaRoutes": {
446
+ "depends_on": ["deletePayment"],
442
447
  "method": "SendToRouteV2",
443
448
  "type": "router"
444
449
  },
450
+ "subscribeToPeerMessages": {
451
+ "method": "SubscribeCustomMessages",
452
+ "type": "default"
453
+ },
445
454
  "subscribeToPeers": {
446
455
  "method": "SubscribePeerEvents",
447
456
  "type": "default"
@@ -32,6 +32,7 @@ const payViaRoutes = require('./pay_via_routes');
32
32
  const probeForRoute = require('./probe_for_route');
33
33
  const recoverFundsFromChannel = require('./recover_funds_from_channel');
34
34
  const recoverFundsFromChannels = require('./recover_funds_from_channels');
35
+ const sendMessageToPeer = require('./send_message_to_peer');
35
36
  const subscribeToBackups = require('./subscribe_to_backups');
36
37
  const subscribeToChannels = require('./subscribe_to_channels');
37
38
  const subscribeToForwardRequests = require('./subscribe_to_forward_requests');
@@ -42,6 +43,7 @@ const subscribeToPastPayments = require('./subscribe_to_past_payments');
42
43
  const subscribeToPayViaDetails = require('./subscribe_to_pay_via_details');
43
44
  const subscribeToPayViaRequest = require('./subscribe_to_pay_via_request');
44
45
  const subscribeToPayViaRoutes = require('./subscribe_to_pay_via_routes');
46
+ const subscribeToPeerMessages = require('./subscribe_to_peer_messages');
45
47
  const subscribeToProbeForRoute = require('./subscribe_to_probe_for_route');
46
48
  const updateConnectedWatchtower = require('./update_connected_watchtower');
47
49
  const updatePathfindingSettings = require('./update_pathfinding_settings');
@@ -84,6 +86,7 @@ module.exports = {
84
86
  probeForRoute,
85
87
  recoverFundsFromChannel,
86
88
  recoverFundsFromChannels,
89
+ sendMessageToPeer,
87
90
  subscribeToBackups,
88
91
  subscribeToChannels,
89
92
  subscribeToForwardRequests,
@@ -94,6 +97,7 @@ module.exports = {
94
97
  subscribeToPayViaDetails,
95
98
  subscribeToPayViaRequest,
96
99
  subscribeToPayViaRoutes,
100
+ subscribeToPeerMessages,
97
101
  subscribeToProbeForRoute,
98
102
  updateConnectedWatchtower,
99
103
  updatePathfindingSettings,
@@ -0,0 +1,75 @@
1
+ const asyncAuto = require('async/auto');
2
+ const {returnResult} = require('asyncjs-util');
3
+
4
+ const {isLnd} = require('./../../lnd_requests');
5
+
6
+ const bufferFromHex = hex => Buffer.from(hex, 'hex');
7
+ const defaultMessageType = 32768;
8
+ const isHex = n => !!n && !(n.length % 2) && /^[0-9A-F]*$/i.test(n);
9
+ const isPublicKey = n => !!n && /^[0-9A-F]{66}$/i.test(n);
10
+ const method = 'sendCustomMessage';
11
+ const notSupported = /unknown/;
12
+ const type = 'default';
13
+
14
+ /** Send a custom message to a connected peer
15
+
16
+ If specified, message type is expected to be between 32768 and 65535
17
+
18
+ Message data should not be larger than 65533 bytes
19
+
20
+ Note: this method is not supported in LND versions 0.13.3 and below
21
+
22
+ Requires `offchain:write` permission
23
+
24
+ {
25
+ lnd: <Authenticated LND API Object>
26
+ message: <Message Hex String>
27
+ public_key: <To Peer Public Key Hex String>
28
+ [type]: <Message Type Number>
29
+ }
30
+
31
+ @returns via cbk or Promise
32
+ */
33
+ module.exports = (args, cbk) => {
34
+ return new Promise((resolve, reject) => {
35
+ return asyncAuto({
36
+ // Check arguments
37
+ validate: cbk => {
38
+ if (!isLnd({method, type, lnd: args.lnd})) {
39
+ return cbk([400, 'ExpectedAuthenticatedLndToSendMessageToPeer']);
40
+ }
41
+
42
+ if (!isHex(args.message)) {
43
+ return cbk([400, 'ExpectedCustomMessageDataToSendToPeer']);
44
+ }
45
+
46
+ if (!isPublicKey(args.public_key)) {
47
+ return cbk([400, 'ExpectedPeerPublicKeyToSendMessageTo']);
48
+ }
49
+
50
+ return cbk();
51
+ },
52
+
53
+ // Send the message to the peer
54
+ send: ['validate', ({}, cbk) => {
55
+ return args.lnd[type][method]({
56
+ data: bufferFromHex(args.message),
57
+ peer: bufferFromHex(args.public_key),
58
+ type: args.type || defaultMessageType,
59
+ },
60
+ err => {
61
+ if (!!err && notSupported.test(err.details)) {
62
+ return cbk([501, 'SendMessageToPeerMethodNotSupported']);
63
+ }
64
+
65
+ if (!!err) {
66
+ return cbk([503, 'UnexpectedErrorSendingMessageToPeer', {err}]);
67
+ }
68
+
69
+ return cbk();
70
+ });
71
+ }],
72
+ },
73
+ returnResult({reject, resolve}, cbk));
74
+ });
75
+ };
@@ -16,6 +16,7 @@ const {rpcRouteFromRoute} = require('./../../lnd_requests');
16
16
  const msAsISO = ms => new Date(ms).toISOString();
17
17
  const {isArray} = Array;
18
18
  const isHash = n => /^[0-9A-F]{64}$/i.test(n);
19
+ const hexAsBytes = hex => Buffer.from(hex, 'hex');
19
20
  const method = 'sendToRouteV2';
20
21
  const notFoundIndex = -1;
21
22
  const {now} = Date;
@@ -292,6 +293,27 @@ module.exports = args => {
292
293
  return cbk(null, keys);
293
294
  }],
294
295
 
296
+ // Attempt to clean up failed probe state
297
+ deleteProbe: ['attempt', ({attempt}, cbk) => {
298
+ // Exit early when the payment didn't fail
299
+ if (!attempt.failure) {
300
+ return cbk();
301
+ }
302
+
303
+ // Exit early when this is a real payment
304
+ if (!!args.id) {
305
+ return cbk();
306
+ }
307
+
308
+ args.lnd.default.deletePayment({
309
+ payment_hash: hexAsBytes(id),
310
+ },
311
+ err => {
312
+ // Ignore errors trying to clean up probe data
313
+ return cbk();
314
+ });
315
+ }],
316
+
295
317
  // Parsed out failure
296
318
  failure: ['attempt', 'keys', ({attempt, keys}, cbk) => {
297
319
  if (!attempt.failure) {
@@ -0,0 +1,63 @@
1
+ const EventEmitter = require('events');
2
+
3
+ const asyncAuto = require('async/auto');
4
+ const {returnResult} = require('asyncjs-util');
5
+
6
+ const {emitSubscriptionError} = require('./../../grpc');
7
+ const {handleRemoveListener} = require('./../../grpc');
8
+ const {isLnd} = require('./../../lnd_requests');
9
+ const {rpcPeerMessageAsMessage} = require('./../../lnd_responses');
10
+
11
+ const events = ['message_received'];
12
+ const method = 'SubscribeCustomMessages';
13
+ const type = 'default';
14
+
15
+ /** Subscribe to incoming peer messages
16
+
17
+ Requires `offchain:read` permission
18
+
19
+ This method is not supported in LND 0.13.3 and below
20
+
21
+ {
22
+ lnd: <Authenticated LND API Object>
23
+ }
24
+
25
+ @returns
26
+ <EventEmitter Object>
27
+
28
+ // A message was received from a peer
29
+ @event 'message_received'
30
+ {
31
+ message: <Message Hex String>
32
+ public_key: <From Peer Public Key Hex String>
33
+ type: <Message Type Number>
34
+ }
35
+ */
36
+ module.exports = ({lnd}) => {
37
+ if (!isLnd({lnd, method, type})) {
38
+ throw new Error('ExpectedLndToSubscribeToPeerMessages');
39
+ }
40
+
41
+ const emitter = new EventEmitter();
42
+ const subscription = lnd[type][method]({});
43
+
44
+ const errored = emitSubscriptionError({emitter, subscription});
45
+
46
+ // Terminate subscription when all listeners are removed
47
+ handleRemoveListener({subscription, emitter, events});
48
+
49
+ subscription.on('end', () => emitter.emit('end'));
50
+ subscription.on('error', err => errored(err));
51
+ subscription.on('status', n => emitter.emit('status', n));
52
+
53
+ subscription.on('data', message => {
54
+ try {
55
+ // Notify listeners of the message
56
+ emitter.emit('message_received', rpcPeerMessageAsMessage(message));
57
+ } catch (err) {
58
+ return errored([503, err.message]);
59
+ }
60
+ });
61
+
62
+ return emitter;
63
+ };
@@ -31,6 +31,7 @@ const rpcNodeAsNode = require('./rpc_node_as_node');
31
31
  const rpcOutpointAsUpdate = require('./rpc_outpoint_as_update');
32
32
  const rpcPaymentAsPayment = require('./rpc_payment_as_payment');
33
33
  const rpcPeerAsPeer = require('./rpc_peer_as_peer');
34
+ const rpcPeerMessageAsMessage = require('./rpc_peer_message_as_message');
34
35
  const rpcRequestUpdateAsEvent = require('./rpc_request_update_as_event');
35
36
  const rpcResolutionAsResolution = require('./rpc_resolution_as_resolution');
36
37
  const rpcRouteAsRoute = require('./rpc_route_as_route');
@@ -72,6 +73,7 @@ module.exports = {
72
73
  rpcOutpointAsUpdate,
73
74
  rpcPaymentAsPayment,
74
75
  rpcPeerAsPeer,
76
+ rpcPeerMessageAsMessage,
75
77
  rpcRequestUpdateAsEvent,
76
78
  rpcResolutionAsResolution,
77
79
  rpcRouteAsRoute,
@@ -0,0 +1,44 @@
1
+ const bufferAsHex = buffer => buffer.toString('hex');
2
+ const {isBuffer} = Buffer;
3
+
4
+ /** Map an RPC peer message to message details
5
+
6
+ {
7
+ data: <Message Data Buffer Object>
8
+ peer: <Peer Public Key Buffer Object>
9
+ type: <Message Type Number>
10
+ }
11
+
12
+ @throws
13
+ <Error>
14
+
15
+ @returns
16
+ {
17
+ message: <Message Data Hex String>
18
+ public_key: <Peer Public Key Hex String>
19
+ type: <Message Type Number>
20
+ }
21
+ */
22
+ module.exports = args => {
23
+ if (!args) {
24
+ throw new Error('ExpectedRpcMessageToDerivePeerMessage');
25
+ }
26
+
27
+ if (!isBuffer(args.data)) {
28
+ throw new Error('ExpectedPeerMessageDataToDerivePeerMessage');
29
+ }
30
+
31
+ if (!isBuffer(args.peer)) {
32
+ throw new Error('ExpectedPeerPublicKeyBytesToDerivePeerMessage');
33
+ }
34
+
35
+ if (!args.type) {
36
+ throw new Error('ExpectedCustomMessageTypeNumberToDeriveMessage');
37
+ }
38
+
39
+ return {
40
+ message: bufferAsHex(args.data),
41
+ public_key: bufferAsHex(args.peer),
42
+ type: args.type,
43
+ };
44
+ };
package/package.json CHANGED
@@ -7,22 +7,22 @@
7
7
  "url": "https://github.com/alexbosworth/lightning/issues"
8
8
  },
9
9
  "dependencies": {
10
- "@grpc/grpc-js": "1.4.1",
11
- "@grpc/proto-loader": "0.6.5",
10
+ "@grpc/grpc-js": "1.4.2",
11
+ "@grpc/proto-loader": "0.6.6",
12
12
  "@types/express": "4.17.13",
13
- "@types/node": "16.11.1",
13
+ "@types/node": "16.11.6",
14
14
  "@types/request": "2.48.7",
15
15
  "@types/ws": "8.2.0",
16
- "async": "3.2.1",
17
- "asyncjs-util": "1.2.6",
16
+ "async": "3.2.2",
17
+ "asyncjs-util": "1.2.7",
18
18
  "bitcoinjs-lib": "5.2.0",
19
19
  "bn.js": "5.2.0",
20
20
  "body-parser": "1.19.0",
21
- "bolt07": "1.7.3",
21
+ "bolt07": "1.7.4",
22
22
  "bolt09": "0.2.0",
23
23
  "cbor": "8.0.2",
24
24
  "express": "4.17.1",
25
- "invoices": "2.0.0",
25
+ "invoices": "2.0.1",
26
26
  "psbt": "1.1.10"
27
27
  },
28
28
  "description": "Lightning Network client library",
@@ -56,5 +56,5 @@
56
56
  "directory": "test/typescript"
57
57
  },
58
58
  "types": "index.d.ts",
59
- "version": "4.11.0"
59
+ "version": "4.12.2"
60
60
  }
@@ -4,6 +4,8 @@ const {payViaRoutes} = require('./../../../');
4
4
 
5
5
  const preimage = Buffer.alloc(32);
6
6
 
7
+ const deletePayment = ({}, cbk) => cbk();
8
+
7
9
  const getInfo = ({}, cbk) => {
8
10
  return cbk(null, {
9
11
  alias: '',
@@ -37,7 +39,7 @@ const tests = [
37
39
  {
38
40
  args: {
39
41
  lnd: {
40
- default: {getInfo},
42
+ default: {deletePayment, getInfo},
41
43
  router: {sendToRouteV2: ({}, cbk) => cbk(null, {})},
42
44
  },
43
45
  },
@@ -47,7 +49,7 @@ const tests = [
47
49
  {
48
50
  args: {
49
51
  lnd: {
50
- default: {getInfo},
52
+ default: {deletePayment, getInfo},
51
53
  router: {sendToRouteV2: ({}, cbk) => cbk(null, {})},
52
54
  },
53
55
  routes: [],
@@ -58,7 +60,7 @@ const tests = [
58
60
  {
59
61
  args: {
60
62
  lnd: {
61
- default: {getInfo},
63
+ default: {deletePayment, getInfo},
62
64
  router: {sendToRouteV2: ({}, cbk) => cbk(null, {})},
63
65
  },
64
66
  routes: [{
@@ -85,7 +87,7 @@ const tests = [
85
87
  {
86
88
  args: {
87
89
  lnd: {
88
- default: {getInfo},
90
+ default: {deletePayment, getInfo},
89
91
  router: {sendToRouteV2: ({}, cbk) => cbk('err')},
90
92
  },
91
93
  routes: [{
@@ -116,7 +118,7 @@ const tests = [
116
118
  {
117
119
  args: {
118
120
  lnd: {
119
- default: {getInfo},
121
+ default: {deletePayment, getInfo},
120
122
  router: {sendToRouteV2: ({}, cbk) => cbk(null, {})},
121
123
  },
122
124
  routes: [{
@@ -142,7 +144,7 @@ const tests = [
142
144
  {
143
145
  args: {
144
146
  lnd: {
145
- default: {getInfo},
147
+ default: {deletePayment, getInfo},
146
148
  router: {sendToRouteV2: ({}, cbk) => cbk(null, {})},
147
149
  },
148
150
  routes: [{
@@ -169,7 +171,7 @@ const tests = [
169
171
  {
170
172
  args: {
171
173
  lnd: {
172
- default: {getInfo},
174
+ default: {deletePayment, getInfo},
173
175
  router: {
174
176
  sendToRouteV2: ({}, cbk) => {
175
177
  return cbk(null, {
@@ -223,7 +225,7 @@ const tests = [
223
225
  {
224
226
  args: {
225
227
  lnd: {
226
- default: {getInfo},
228
+ default: {deletePayment, getInfo},
227
229
  router: {
228
230
  sendToRouteV2: ({}, cbk) => {
229
231
  return cbk(null, {
@@ -319,7 +321,7 @@ const tests = [
319
321
  {
320
322
  args: {
321
323
  lnd: {
322
- default: {getInfo},
324
+ default: {deletePayment, getInfo},
323
325
  router: {sendToRouteV2: ({}, cbk) => cbk(null, {preimage})},
324
326
  },
325
327
  routes: [{
@@ -0,0 +1,68 @@
1
+ const {test} = require('@alexbosworth/tap');
2
+
3
+ const {sendMessageToPeer} = require('./../../../lnd_methods');
4
+
5
+ const makeLnd = ({err}) => {
6
+ return {default: {sendCustomMessage: ({}, cbk) => cbk(err)}};
7
+ };
8
+
9
+ const makeArgs = override => {
10
+ const args = {
11
+ lnd: makeLnd({}),
12
+ message: Buffer.from('message').toString('hex'),
13
+ public_key: Buffer.alloc(33, 3).toString('hex'),
14
+ type: 40000,
15
+ };
16
+
17
+ Object.keys(override || {}).forEach(key => args[key] = override[key]);
18
+
19
+ return args;
20
+ };
21
+
22
+ const tests = [
23
+ {
24
+ args: makeArgs({lnd: undefined}),
25
+ description: 'LND is required',
26
+ error: [400, 'ExpectedAuthenticatedLndToSendMessageToPeer'],
27
+ },
28
+ {
29
+ args: makeArgs({message: undefined}),
30
+ description: 'A message is required',
31
+ error: [400, 'ExpectedCustomMessageDataToSendToPeer'],
32
+ },
33
+ {
34
+ args: makeArgs({public_key: undefined}),
35
+ description: 'A public key is required',
36
+ error: [400, 'ExpectedPeerPublicKeyToSendMessageTo'],
37
+ },
38
+ {
39
+ args: makeArgs({lnd: makeLnd({err: {details: 'unknown service'}})}),
40
+ description: 'Unimplemented error is returned',
41
+ error: [501, 'SendMessageToPeerMethodNotSupported'],
42
+ },
43
+ {
44
+ args: makeArgs({lnd: makeLnd({err: 'err'})}),
45
+ description: 'Server error is returned',
46
+ error: [503, 'UnexpectedErrorSendingMessageToPeer', {err: 'err'}],
47
+ },
48
+ {
49
+ args: makeArgs({}),
50
+ description: 'Message is sent to peer',
51
+ },
52
+ {
53
+ args: makeArgs({type: undefined}),
54
+ description: 'Message with default type is sent to peer',
55
+ },
56
+ ];
57
+
58
+ tests.forEach(({args, description, error, expected}) => {
59
+ return test(description, async ({end, equal, rejects}) => {
60
+ if (!!error) {
61
+ await rejects(sendMessageToPeer(args), error, 'Got expected error');
62
+ } else {
63
+ await sendMessageToPeer(args);
64
+ }
65
+
66
+ return end();
67
+ });
68
+ });
@@ -2,6 +2,8 @@ const {test} = require('@alexbosworth/tap');
2
2
 
3
3
  const {subscribeToPayViaRoutes} = require('./../../../');
4
4
 
5
+ const deletePayment = ({}, cbk) => cbk();
6
+
5
7
  const route = {
6
8
  fee: 1,
7
9
  fee_mtokens: '1000',
@@ -27,28 +29,39 @@ const tests = [
27
29
  error: 'ExpectedAuthenticatedLndToPayViaRoutes',
28
30
  },
29
31
  {
30
- args: {lnd: {router: {sendToRouteV2: ({}) => {}}}},
32
+ args: {
33
+ lnd: {default: {deletePayment}, router: {sendToRouteV2: ({}) => {}}},
34
+ },
31
35
  description: 'Routes are required',
32
36
  error: 'ExpectedArrayOfPaymentRoutesToPayViaRoutes',
33
37
  },
34
38
  {
35
- args: {lnd: {router: {sendToRouteV2: ({}) => {}}}, routes: []},
39
+ args: {
40
+ lnd: {default: {deletePayment}, router: {sendToRouteV2: ({}) => {}}},
41
+ routes: [],
42
+ },
36
43
  description: 'Non empty routes are required',
37
44
  error: 'ExpectedArrayOfPaymentRoutesToPayViaRoutes',
38
45
  },
39
46
  {
40
- args: {lnd: {router: {sendToRouteV2: ({}) => {}}}, routes: [{}]},
47
+ args: {
48
+ lnd: {default: {deletePayment}, router: {sendToRouteV2: ({}) => {}}},
49
+ routes: [{}],
50
+ },
41
51
  description: 'Route must have hops',
42
52
  error: 'ExpectedRouteHopsToPayViaRoutes',
43
53
  },
44
54
  {
45
- args: {lnd: {router: {sendToRouteV2: ({}) => {}}}, routes: [{hops: [{}]}]},
55
+ args: {
56
+ lnd: {default: {deletePayment}, router: {sendToRouteV2: ({}) => {}}},
57
+ routes: [{hops: [{}]}],
58
+ },
46
59
  description: 'Hops must have public keys',
47
60
  error: 'ExpectedPublicKeyInPayViaRouteHops',
48
61
  },
49
62
  {
50
63
  args: {
51
- lnd: {router: {sendToRouteV2: ({}) => {}}},
64
+ lnd: {default: {deletePayment}, router: {sendToRouteV2: ({}) => {}}},
52
65
  routes: [{hops: [{public_key: 'public_key'}]}],
53
66
  },
54
67
  description: 'Hops must have channel ids',
@@ -56,7 +69,7 @@ const tests = [
56
69
  },
57
70
  {
58
71
  args: {
59
- lnd: {router: {sendToRouteV2: ({}) => {}}},
72
+ lnd: {default: {deletePayment}, router: {sendToRouteV2: ({}) => {}}},
60
73
  routes: [{hops: [{public_key: 'public_key'}]}],
61
74
  },
62
75
  description: 'Hops must have channel ids',
@@ -65,6 +78,7 @@ const tests = [
65
78
  {
66
79
  args: {
67
80
  lnd: {
81
+ default: {deletePayment},
68
82
  router: {
69
83
  sendToRouteV2: ({}, cbk) => cbk({details: 'unknown wire error'}),
70
84
  },
@@ -77,6 +91,7 @@ const tests = [
77
91
  {
78
92
  args: {
79
93
  lnd: {
94
+ default: {deletePayment},
80
95
  router: {
81
96
  sendToRouteV2: ({}, cbk) => cbk({
82
97
  details: 'payment attempt not completed before timeout',
@@ -90,7 +105,10 @@ const tests = [
90
105
  },
91
106
  {
92
107
  args: {
93
- lnd: {router: {sendToRouteV2: ({}, cbk) => cbk('err')}},
108
+ lnd: {
109
+ default: {deletePayment},
110
+ router: {sendToRouteV2: ({}, cbk) => cbk('err')},
111
+ },
94
112
  routes: [route],
95
113
  },
96
114
  description: 'An unexpected payment error is passed back',
@@ -102,7 +120,10 @@ const tests = [
102
120
  },
103
121
  {
104
122
  args: {
105
- lnd: {router: {sendToRouteV2: ({}, cbk) => cbk()}},
123
+ lnd: {
124
+ default: {deletePayment},
125
+ router: {sendToRouteV2: ({}, cbk) => cbk()},
126
+ },
106
127
  routes: [route],
107
128
  },
108
129
  description: 'A result is expected from sendToRoute',
@@ -115,9 +136,14 @@ const tests = [
115
136
  {
116
137
  args: {
117
138
  id: Buffer.alloc(32).toString('hex'),
118
- lnd: {router: {sendToRouteV2: ({}, cbk) => cbk(null, {
119
- preimage: Buffer.alloc(32),
120
- })}},
139
+ lnd: {
140
+ default: {deletePayment},
141
+ router: {
142
+ sendToRouteV2: ({}, cbk) => cbk(null, {
143
+ preimage: Buffer.alloc(32),
144
+ }),
145
+ },
146
+ },
121
147
  routes: [route, route],
122
148
  },
123
149
  description: 'A success is returned',
@@ -142,9 +168,14 @@ const tests = [
142
168
  {
143
169
  args: {
144
170
  id: Buffer.alloc(32).toString('hex'),
145
- lnd: {router: {sendToRouteV2: ({}, cbk) => cbk(null, {
146
- preimage: 'preimage',
147
- })}},
171
+ lnd: {
172
+ default: {deletePayment},
173
+ router: {
174
+ sendToRouteV2: ({}, cbk) => cbk(null, {
175
+ preimage: 'preimage',
176
+ }),
177
+ },
178
+ },
148
179
  routes: [route],
149
180
  },
150
181
  description: 'A success is returned',
@@ -156,13 +187,18 @@ const tests = [
156
187
  },
157
188
  {
158
189
  args: {
159
- lnd: {router: {sendToRouteV2: ({}, cbk) => cbk(null, {
160
- failure: {
161
- chan_id: '1',
162
- code: 'UNKNOWN_FAILURE',
190
+ lnd: {
191
+ default: {deletePayment},
192
+ router: {
193
+ sendToRouteV2: ({}, cbk) => cbk(null, {
194
+ failure: {
195
+ chan_id: '1',
196
+ code: 'UNKNOWN_FAILURE',
197
+ },
198
+ preimage: Buffer.alloc(Number()),
199
+ }),
163
200
  },
164
- preimage: Buffer.alloc(Number()),
165
- })}},
201
+ },
166
202
  routes: [route],
167
203
  },
168
204
  description: 'A routing failure is returned',
@@ -184,14 +220,19 @@ const tests = [
184
220
  },
185
221
  {
186
222
  args: {
187
- lnd: {router: {sendToRouteV2: ({}, cbk) => cbk(null, {
188
- failure: {
189
- chan_id: '1',
190
- code: 'UNKNOWN_FAILURE',
191
- failure_source_index: 2,
223
+ lnd: {
224
+ default: {deletePayment},
225
+ router: {
226
+ sendToRouteV2: ({}, cbk) => cbk(null, {
227
+ failure: {
228
+ chan_id: '1',
229
+ code: 'UNKNOWN_FAILURE',
230
+ failure_source_index: 2,
231
+ },
232
+ preimage: Buffer.alloc(Number()),
233
+ }),
192
234
  },
193
- preimage: Buffer.alloc(Number()),
194
- })}},
235
+ },
195
236
  routes: [
196
237
  {
197
238
  fee: 1,
@@ -280,14 +321,19 @@ const tests = [
280
321
  },
281
322
  {
282
323
  args: {
283
- lnd: {router: {sendToRouteV2: ({}, cbk) => cbk(null, {
284
- failure: {
285
- chan_id: '1',
286
- code: 'UNKNOWN_FAILURE',
287
- failure_source_index: 1,
324
+ lnd: {
325
+ default: {deletePayment},
326
+ router: {
327
+ sendToRouteV2: ({}, cbk) => cbk(null, {
328
+ failure: {
329
+ chan_id: '1',
330
+ code: 'UNKNOWN_FAILURE',
331
+ failure_source_index: 1,
332
+ },
333
+ preimage: Buffer.alloc(Number()),
334
+ }),
288
335
  },
289
- preimage: Buffer.alloc(Number()),
290
- })}},
336
+ },
291
337
  routes: [route],
292
338
  },
293
339
  description: 'A routing failure is returned from the destination',
@@ -310,6 +356,7 @@ const tests = [
310
356
  {
311
357
  args: {
312
358
  lnd: {
359
+ default: {deletePayment},
313
360
  router: {
314
361
  sendToRouteV2: ({}, cbk) => {
315
362
  return setTimeout(() => cbk({details: 'unknown wire error'}), 100);
@@ -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
+ });
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "overrides": [
3
- ["lightning", 1168],
4
- ["lightning", 1174],
5
- ["lightning", 1182],
6
- ["lightning", 1189],
7
- ["lightning", 3378],
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]