lightning 4.10.5 → 4.11.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.
Files changed (28) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +2 -0
  3. package/grpc/protos/lightning.proto +38 -0
  4. package/index.js +4 -0
  5. package/lnd_methods/index.js +4 -0
  6. package/lnd_methods/macaroon/index.d.ts +1 -0
  7. package/lnd_methods/macaroon/methods.json +8 -0
  8. package/lnd_methods/macaroon/subscribe_to_rpc_requests.d.ts +143 -0
  9. package/lnd_methods/offchain/get_failed_payments.d.ts +136 -0
  10. package/lnd_methods/offchain/get_failed_payments.js +1 -1
  11. package/lnd_methods/offchain/get_payment.d.ts +36 -0
  12. package/lnd_methods/offchain/get_payment.js +1 -0
  13. package/lnd_methods/offchain/index.d.ts +1 -0
  14. package/lnd_methods/offchain/index.js +4 -0
  15. package/lnd_methods/offchain/probe_for_route.d.ts +4 -0
  16. package/lnd_methods/offchain/send_message_to_peer.js +76 -0
  17. package/lnd_methods/offchain/subscribe_to_peer_messages.js +63 -0
  18. package/lnd_methods/onchain/propose_channel.d.ts +1 -1
  19. package/lnd_methods/unauthenticated/get_wallet_status.d.ts +3 -1
  20. package/lnd_methods/unauthenticated/subscribe_to_wallet_status.d.ts +2 -0
  21. package/lnd_responses/index.js +2 -0
  22. package/lnd_responses/rpc_peer_message_as_message.js +44 -0
  23. package/package.json +6 -6
  24. package/test/lnd_methods/offchain/test_send_message_to_peer.js +68 -0
  25. package/test/lnd_methods/offchain/test_subscribe_to_peer_messages.js +132 -0
  26. package/test/lnd_responses/test_rpc_peer_message_as_message.js +67 -0
  27. package/test/typescript/get_failed_payments.test-d.ts +31 -0
  28. package/test/typescript/subscribe_to_rpc_requests.test-d.ts +46 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Versions
2
2
 
3
+ ## 4.11.1
4
+
5
+ - `getFailedPayments`: Add method to get past failed payments
6
+ - `subscribeToRpcRequests`: Add method to listen to and interact with RPC requests
7
+
8
+ ## 4.10.7
9
+
10
+ - `getPayment`: Expand type definitions to match result data
11
+
3
12
  ## 4.10.5
4
13
 
5
14
  - `getInvoice`, `getInvoices`, `subscribeToInvoice`, `subscribeToInvoices`:
package/README.md CHANGED
@@ -131,6 +131,8 @@ Methods exported by this library support typescript, but ln-service includes add
131
131
  channels on the node.
132
132
  - [getConnectedWatchtowers](https://github.com/alexbosworth/ln-service#getconnectedwatchtowers):
133
133
  List watchtowers that were added
134
+ - [getFailedPayments](https://github.com/alexbosworth/ln-service#getfailedpayments): List out
135
+ past payments that failed.
134
136
  - [getFeeRates](https://github.com/alexbosworth/ln-service#getfeerates): List routing fee rates
135
137
  and routing policies of channels on the node.
136
138
  - [getForwardingConfidence](https://github.com/alexbosworth/ln-service#getforwardingconfidence):
@@ -557,6 +557,44 @@ 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
+ // Message type. This value needs to be in the custom range (>= 32768).
593
+ uint32 type = 2;
594
+ // Raw message data.
595
+ bytes data = 3;
596
+ }
597
+ message SendCustomMessageResponse {
560
598
  }
561
599
 
562
600
  message Utxo {
package/index.js CHANGED
@@ -37,6 +37,7 @@ const {getChannelBalance} = require('./lnd_methods');
37
37
  const {getChannels} = require('./lnd_methods');
38
38
  const {getClosedChannels} = require('./lnd_methods');
39
39
  const {getConnectedWatchtowers} = require('./lnd_methods');
40
+ const {getFailedPayments} = require('./lnd_methods');
40
41
  const {getFeeRates} = require('./lnd_methods');
41
42
  const {getForwardingConfidence} = require('./lnd_methods');
42
43
  const {getForwardingReputations} = require('./lnd_methods');
@@ -114,6 +115,7 @@ const {subscribeToPayViaRequest} = require('./lnd_methods');
114
115
  const {subscribeToPayViaRoutes} = require('./lnd_methods');
115
116
  const {subscribeToPeers} = require('./lnd_methods');
116
117
  const {subscribeToProbeForRoute} = require('./lnd_methods');
118
+ const {subscribeToRpcRequests} = require('./lnd_methods');
117
119
  const {subscribeToTransactions} = require('./lnd_methods');
118
120
  const {subscribeToWalletStatus} = require('./lnd_methods');
119
121
  const {unauthenticatedLndGrpc} = require('./lnd_grpc');
@@ -169,6 +171,7 @@ module.exports = {
169
171
  getChannels,
170
172
  getClosedChannels,
171
173
  getConnectedWatchtowers,
174
+ getFailedPayments,
172
175
  getFeeRates,
173
176
  getForwardingConfidence,
174
177
  getForwardingReputations,
@@ -246,6 +249,7 @@ module.exports = {
246
249
  subscribeToPayViaRoutes,
247
250
  subscribeToPeers,
248
251
  subscribeToProbeForRoute,
252
+ subscribeToRpcRequests,
249
253
  subscribeToTransactions,
250
254
  subscribeToWalletStatus,
251
255
  unauthenticatedLndGrpc,
@@ -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,
@@ -1,4 +1,5 @@
1
1
  export * from './get_access_ids';
2
2
  export * from './grant_access';
3
3
  export * from './revoke_access';
4
+ export * from './subscribe_to_rpc_requests';
4
5
  export * from './verify_access';
@@ -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"
@@ -442,6 +446,10 @@
442
446
  "method": "SendToRouteV2",
443
447
  "type": "router"
444
448
  },
449
+ "subscribeToPeerMessages": {
450
+ "method": "SubscribeCustomMessages",
451
+ "type": "default"
452
+ },
445
453
  "subscribeToPeers": {
446
454
  "method": "SubscribePeerEvents",
447
455
  "type": "default"
@@ -0,0 +1,143 @@
1
+ import {
2
+ AuthenticatedLightningArgs,
3
+ AuthenticatedLightningMethod,
4
+ LightningMethod,
5
+ } from '../../typescript';
6
+
7
+ export type SubscribeToRpcRequestsArgs = AuthenticatedLightningArgs<{
8
+ /** RPC Middleware Interception Name String */
9
+ id?: string;
10
+ /** Intercept Channel Closes Bool */
11
+ is_intercepting_close_channel_requests?: boolean;
12
+ /** Intercept Channel Opens Bool */
13
+ is_intercepting_open_channel_requests?: boolean;
14
+ /** Intercept Pay Via Route Bool */
15
+ is_intercepting_pay_via_routes_requests?: boolean;
16
+ }>;
17
+
18
+ export type SubscribeToRpcRequestsResult = {
19
+ /** RPC Request Subscription EventEmitter Object */
20
+ subscription: NodeJS.EventEmitter;
21
+ };
22
+
23
+ export type SubscribeToRpcRequestsCommonEvent = {
24
+ /** Request Id Number */
25
+ id: number;
26
+ /** Base64 Encoded Macaroon String */
27
+ macaroon?: string;
28
+ /** RPC URI String */
29
+ uri?: string;
30
+ };
31
+
32
+ export type SubscribeToRpcRequestsEvent<TRequest> =
33
+ Required<SubscribeToRpcRequestsCommonEvent> & {
34
+ accept: LightningMethod;
35
+ reject: LightningMethod<{
36
+ /** Rejection String */
37
+ message: string;
38
+ }>;
39
+ request: TRequest;
40
+ };
41
+
42
+ /** A channel close request was intercepted: by default it will be rejected */
43
+ export type SubscribeToRpcRequestsCloseChannelRequestEvent =
44
+ SubscribeToRpcRequestsEvent<{
45
+ /** Request Sending Local Channel Funds To Address String */
46
+ address?: string;
47
+ /** Is Force Close Bool */
48
+ is_force_close?: boolean;
49
+ /** Confirmation Target Number */
50
+ target_confirmations?: number;
51
+ /** Tokens Per Virtual Byte Number */
52
+ tokens_per_vbyte?: number;
53
+ /** Transaction Id Hex String */
54
+ transaction_id: string;
55
+ /** Transaction Output Index Number */
56
+ transaction_vout: number;
57
+ }>;
58
+
59
+ /** A channel open request was intercepted: by default it will be rejected */
60
+ export type SubscribeToRpcRequestsOpenChannelRequestEvent =
61
+ SubscribeToRpcRequestsEvent<{
62
+ /** Chain Fee Tokens Per VByte Number */
63
+ chain_fee_tokens_per_vbyte?: number;
64
+ /** Prefer Cooperative Close To Address String */
65
+ cooperative_close_address?: string;
66
+ /** Tokens to Gift To Partner Number */
67
+ give_tokens?: number;
68
+ /** Channel is Private Bool */
69
+ is_private?: boolean;
70
+ /** Local Tokens Number */
71
+ local_tokens: number;
72
+ /** Spend UTXOs With Minimum Confirmations Number */
73
+ min_confirmations?: number;
74
+ /** Minimum HTLC Millitokens String */
75
+ min_htlc_mtokens?: string;
76
+ /** Public Key Hex String */
77
+ partner_public_key: string;
78
+ /** Peer Output CSV Delay Number */
79
+ partner_csv_delay?: number;
80
+ }>;
81
+
82
+ /** A pay to route request was intercepted: by default it will be rejected */
83
+ export type SubscribeToRpcRequestsPayViaRouteRequestEvent =
84
+ SubscribeToRpcRequestsEvent<{
85
+ /** Payment Hash Hex String */
86
+ id: string;
87
+ route: {
88
+ /** Route Fee Tokens Number */
89
+ fee: number;
90
+ /** Route Fee Millitokens String */
91
+ fee_mtokens: string;
92
+ hops: {
93
+ /** Standard Format Channel Id String */
94
+ channel: string;
95
+ /** Channel Capacity Tokens Number */
96
+ channel_capacity: number;
97
+ /** Fee Tokens Number */
98
+ fee: number;
99
+ /** Fee Millitokens String */
100
+ fee_mtokens: string;
101
+ /** Forward Tokens Number */
102
+ forward: number;
103
+ /** Forward Millitokens String */
104
+ forward_mtokens: string;
105
+ /** Forward Edge Public Key Hex String */
106
+ public_key: string;
107
+ /** Timeout Block Height Number */
108
+ timeout?: number;
109
+ }[];
110
+ /** Total Fee-Inclusive Millitokens String */
111
+ mtokens: string;
112
+ /** Payment Identifier Hex String */
113
+ payment?: string;
114
+ /** Timeout Block Height Number */
115
+ timeout?: number;
116
+ /** Total Fee-Inclusive Tokens Number */
117
+ tokens: number;
118
+ /** Total Payment Millitokens String */
119
+ total_mtokens?: string;
120
+ };
121
+ }>;
122
+
123
+ export type SubscribeToRpcRequestsRequestEvent =
124
+ SubscribeToRpcRequestsCommonEvent;
125
+
126
+ export type SubscribeToRpcRequestsResponseEvent =
127
+ SubscribeToRpcRequestsCommonEvent;
128
+
129
+ /**
130
+ * Subscribe to RPC requests and their responses
131
+ *
132
+ * `accept` and `reject` methods can be used with cbk or Promise syntax
133
+ *
134
+ * Requires `macaroon:write` permission
135
+ *
136
+ * LND must be running with "RPC middleware" enabled: `rpcmiddleware.enable=1`
137
+ *
138
+ * This method is not supported in LND 0.13.3 and below
139
+ */
140
+ export const subscribeToRpcRequests: AuthenticatedLightningMethod<
141
+ SubscribeToRpcRequestsArgs,
142
+ SubscribeToRpcRequestsResult
143
+ >;
@@ -0,0 +1,136 @@
1
+ import {
2
+ AuthenticatedLightningArgs,
3
+ AuthenticatedLightningMethod,
4
+ PaginationArgs,
5
+ } from '../../typescript';
6
+
7
+ export type GetFailedPaymentsArgs = AuthenticatedLightningArgs<PaginationArgs>;
8
+
9
+ export type GetFailedPaymentsResult = {
10
+ payments: {
11
+ attempts: {
12
+ failure?: {
13
+ /** Error Type Code Number */
14
+ code: number;
15
+ details?: {
16
+ /** Standard Format Channel Id String */
17
+ channel?: string;
18
+ /** Error Associated Block Height Number */
19
+ height?: number;
20
+ /** Failed Hop Index Number */
21
+ index?: number;
22
+ /** Error Millitokens String */
23
+ mtokens?: string;
24
+ policy?: {
25
+ /** Base Fee Millitokens String */
26
+ base_fee_mtokens: string;
27
+ /** Locktime Delta Number */
28
+ cltv_delta: number;
29
+ /** Fees Charged in Millitokens Per Million Number */
30
+ fee_rate: number;
31
+ /** Channel is Disabled Bool */
32
+ is_disabled?: boolean;
33
+ /** Maximum HLTC Millitokens Value String */
34
+ max_htlc_mtokens: string;
35
+ /** Minimum HTLC Millitokens Value String */
36
+ min_htlc_mtokens: string;
37
+ /** Updated At ISO 8601 Date String */
38
+ updated_at: string;
39
+ };
40
+ /** Error CLTV Timeout Height Number */
41
+ timeout_height?: number;
42
+ update?: {
43
+ /** Chain Id Hex String */
44
+ chain: string;
45
+ /** Channel Flags Number */
46
+ channel_flags: number;
47
+ /** Extra Opaque Data Hex String */
48
+ extra_opaque_data: string;
49
+ /** Message Flags Number */
50
+ message_flags: number;
51
+ /** Channel Update Signature Hex String */
52
+ signature: string;
53
+ };
54
+ };
55
+ /** Error Message String */
56
+ message: string;
57
+ };
58
+ /** Payment Add Index Number */
59
+ index?: number;
60
+ /** Payment Confirmed At ISO 8601 Date String */
61
+ confirmed_at?: string;
62
+ /** Payment Attempt Succeeded Bool */
63
+ is_confirmed: boolean;
64
+ /** Payment Attempt Failed Bool */
65
+ is_failed: boolean;
66
+ /** Payment Attempt is Waiting For Resolution Bool */
67
+ is_pending: boolean;
68
+ route: {
69
+ /** Route Fee Tokens Number */
70
+ fee: number;
71
+ /** Route Fee Millitokens String */
72
+ fee_mtokens: string;
73
+ hops: {
74
+ /** Standard Format Channel Id String */
75
+ channel: string;
76
+ /** Channel Capacity Tokens Number */
77
+ channel_capacity: number;
78
+ /** Fee Number */
79
+ fee: number;
80
+ /** Fee Millitokens String */
81
+ fee_mtokens: string;
82
+ /** Forward Tokens Number */
83
+ forward: number;
84
+ /** Forward Millitokens String */
85
+ forward_mtokens: string;
86
+ /** Forward Edge Public Key Hex String */
87
+ public_key?: string;
88
+ /** Timeout Block Height Number */
89
+ timeout?: number;
90
+ }[];
91
+ /** Total Fee-Inclusive Millitokens String */
92
+ mtokens: string;
93
+ /** Payment Identifier Hex String */
94
+ payment?: string;
95
+ /** Timeout Block Height Number */
96
+ timeout: number;
97
+ /** Total Fee-Inclusive Tokens Number */
98
+ tokens: number;
99
+ /** Total Millitokens String */
100
+ total_mtokens?: string;
101
+ };
102
+ }[];
103
+ /** Payment at ISO-8601 Date String */
104
+ created_at: string;
105
+ /** Destination Node Public Key Hex String */
106
+ destination?: string;
107
+ /** Payment Preimage Hash String */
108
+ id: string;
109
+ /** Payment Add Index Number */
110
+ index?: number;
111
+ /** Payment is Confirmed Bool */
112
+ is_confirmed: boolean;
113
+ /** Transaction Is Outgoing Bool */
114
+ is_outgoing: boolean;
115
+ /** Millitokens Attempted to Pay to Destination String */
116
+ mtokens: string;
117
+ /** BOLT 11 Payment Request String */
118
+ request?: string;
119
+ /** Payment Tokens Attempted to Pay Rounded Up Number */
120
+ safe_tokens: number;
121
+ /** Rounded Down Tokens Attempted to Pay to Destination Number */
122
+ tokens: number;
123
+ }[];
124
+ /** Next Opaque Paging Token String */
125
+ next?: string;
126
+ };
127
+
128
+ /**
129
+ * Get failed payments made through channels.
130
+ *
131
+ * Requires `offchain:read` permission
132
+ */
133
+ export const getFailedPayments: AuthenticatedLightningMethod<
134
+ GetFailedPaymentsArgs,
135
+ GetFailedPaymentsResult
136
+ >;
@@ -8,7 +8,7 @@ const {sortBy} = require('./../../arrays');
8
8
  const defaultLimit = 250;
9
9
  const {isArray} = Array;
10
10
  const isFailed = payment => !!payment && payment.status === 'FAILED';
11
- const lastPageFirstIndexOffset = 1;
11
+ const lastPageFirstIndexOffset = 0;
12
12
  const method = 'listPayments';
13
13
  const {parse} = JSON;
14
14
  const {stringify} = JSON;
@@ -32,6 +32,8 @@ export type GetPaymentResult = {
32
32
  created_at: string;
33
33
  /** Payment Destination Public Key Hex */
34
34
  destination: string;
35
+ /** Total Fee Tokens To Pay */
36
+ fee: number;
35
37
  /** Total Fee Millitokens To Pay */
36
38
  fee_mtokens: string;
37
39
  hops: {
@@ -56,6 +58,40 @@ export type GetPaymentResult = {
56
58
  id: string;
57
59
  /** Total Millitokens Paid */
58
60
  mtokens: string;
61
+ paths: {
62
+ /** Total Path Fee Tokens */
63
+ fee: number;
64
+ /** Total Path Fee Millitokens */
65
+ fee_mtokens: string;
66
+ hops: {
67
+ /** Standard Format Channel Id */
68
+ channel: string;
69
+ /** Channel Capacity Tokens */
70
+ channel_capacity: number;
71
+ /** Routing Fee Tokens */
72
+ fee: number;
73
+ /** Fee Millitokens */
74
+ fee_mtokens: string;
75
+ /** Forwarded Tokens */
76
+ forward: number;
77
+ /** Forward Millitokens */
78
+ forward_mtokens: string;
79
+ /** Public Key Hex */
80
+ public_key: string;
81
+ /** Timeout Block Height */
82
+ timeout: number;
83
+ }[];
84
+ /** Total Path Millitokens Paid */
85
+ mtokens: string;
86
+ /** MPP Payment Identifying Nonce */
87
+ payment: string;
88
+ /** Expiration Block Height */
89
+ timeout: number;
90
+ /** Path Tokens Paid */
91
+ tokens: number;
92
+ /** Total Millitokens Paid On All Paths */
93
+ total_mtokens: string;
94
+ }[]
59
95
  /** BOLT 11 Payment Request */
60
96
  request?: string;
61
97
  /** Payment Forwarding Fee Rounded Up Tokens */
@@ -53,6 +53,7 @@ const type = 'router';
53
53
  channel_capacity: <Channel Capacity Tokens Number>
54
54
  fee: <Fee Tokens Rounded Down Number>
55
55
  fee_mtokens: <Fee Millitokens String>
56
+ forward: <Forwarded Tokens Number>
56
57
  forward_mtokens: <Forward Millitokens String>
57
58
  public_key: <Public Key Hex String>
58
59
  timeout: <Timeout Block Height Number>
@@ -14,6 +14,7 @@ export * from './get_channel_balance';
14
14
  export * from './get_channels';
15
15
  export * from './get_closed_channels';
16
16
  export * from './get_connected_watchtowers';
17
+ export * from './get_failed_payments';
17
18
  export * from './get_fee_rates';
18
19
  export * from './get_forwarding_confidence';
19
20
  export * from './get_forwarding_reputations';
@@ -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,
@@ -118,6 +118,10 @@ export type ProbeForRouteResult = {
118
118
  /**
119
119
  * Probe to find a successful route
120
120
  *
121
+ * When probing to a payment request, make sure to specify the fields encoded in the payment request such as `cltv_delta`.
122
+ *
123
+ * If `total_mtokens` are specified, a `payment` nonce is required.
124
+ *
121
125
  * Requires `offchain:write` permission
122
126
  */
123
127
  export const probeForRoute: AuthenticatedLightningMethod<
@@ -0,0 +1,76 @@
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
+ console.log("ERR", err)
67
+ return cbk([503, 'UnexpectedErrorSendingMessageToPeer', {err}]);
68
+ }
69
+
70
+ return cbk();
71
+ });
72
+ }],
73
+ },
74
+ returnResult({reject, resolve}, cbk));
75
+ });
76
+ };
@@ -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
+ };
@@ -34,7 +34,7 @@ export type ProposeChannelArgs = AuthenticatedLightningArgs<{
34
34
  * Channel proposals can allow for cooperative close delays or external funding
35
35
  flows.
36
36
  *
37
- * Requires `offchain:write`, `onchain:write` permissions
37
+ * Requires `address:read`, `offchain:write`, `onchain:write` permissions
38
38
  *
39
39
  * Requires LND compiled with `walletrpc` build tag
40
40
  */
@@ -24,7 +24,9 @@ export type GetWalletStatusResult = {
24
24
  /**
25
25
  * Get wallet status.
26
26
  *
27
- * Requires `info:read` permission
27
+ * This method is not supported on LND 0.12.1 and below
28
+ *
29
+ * `is_ready` is not supported on LND 0.13.3 and below
28
30
  */
29
31
  export const getWalletStatus: UnauthenticatedLightningMethod<
30
32
  {lnd: UnauthenticatedLnd},
@@ -24,5 +24,7 @@ export type SubscribeToWalletStatusStartingEvent = EmptyObject;
24
24
  * Subscribe to wallet status events
25
25
  *
26
26
  * This method is not supported on LND 0.12.1 and below
27
+ *
28
+ * `ready` is not supported on LND 0.13.3 and below
27
29
  */
28
30
  export const subscribeToWalletStatus: UnauthenticatedLightningSubscription;
@@ -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,10 +7,10 @@
7
7
  "url": "https://github.com/alexbosworth/lightning/issues"
8
8
  },
9
9
  "dependencies": {
10
- "@grpc/grpc-js": "1.3.7",
11
- "@grpc/proto-loader": "0.6.5",
10
+ "@grpc/grpc-js": "1.4.1",
11
+ "@grpc/proto-loader": "0.6.6",
12
12
  "@types/express": "4.17.13",
13
- "@types/node": "16.10.3",
13
+ "@types/node": "16.11.1",
14
14
  "@types/request": "2.48.7",
15
15
  "@types/ws": "8.2.0",
16
16
  "async": "3.2.1",
@@ -29,8 +29,8 @@
29
29
  "devDependencies": {
30
30
  "@alexbosworth/node-fetch": "2.6.2",
31
31
  "@alexbosworth/tap": "15.0.10",
32
- "tsd": "0.17.0",
33
- "typescript": "4.4.3",
32
+ "tsd": "0.18.0",
33
+ "typescript": "4.4.4",
34
34
  "ws": "8.2.3"
35
35
  },
36
36
  "engines": {
@@ -56,5 +56,5 @@
56
56
  "directory": "test/typescript"
57
57
  },
58
58
  "types": "index.d.ts",
59
- "version": "4.10.5"
59
+ "version": "4.11.1"
60
60
  }
@@ -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
+ });
@@ -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
+ });
@@ -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
+ });
@@ -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
+ );