lightning 5.6.3 → 5.8.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.
@@ -0,0 +1,20 @@
1
+ name: "Unit test"
2
+
3
+ on:
4
+ pull_request:
5
+ branches: [ master ]
6
+
7
+ jobs:
8
+ unit-test:
9
+ name: Node ${{ matrix.node }} unit test on ${{ matrix.os }}
10
+ runs-on: ${{ matrix.os }}
11
+ strategy:
12
+ matrix:
13
+ os: [ubuntu-latest]
14
+ node: ['12', '14', '16']
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+ - uses: actions/setup-node@v2
18
+ - run: npm install
19
+ - name: Run unit tests
20
+ run: npm test
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Versions
2
2
 
3
+ ## 5.8.1
4
+
5
+ - `getMasterPublicKeys`: Add method to lookup wallet extended public keys
6
+
7
+ ## 5.7.1
8
+
9
+ - `fundPsbt`: Correct ECPair import dependency in control flow
10
+
11
+ ## 5.7.0
12
+
13
+ - `getPendingPayments`: Add method to get a list of in-flight payments
14
+
3
15
  ## 5.6.3
4
16
 
5
17
  - `payViaRoutes`, `subscribeToPayViaRoutes`: Add support for relay messages
package/README.md CHANGED
@@ -157,6 +157,8 @@ To access unauthenticated methods like the wallet unlocker, use
157
157
  open invoices and received payments.
158
158
  - [getLockedUtxos](https://github.com/alexbosworth/ln-service#getlockedutxos): List the UTXOs
159
159
  that are currently reserved and unavailable to coin selection.
160
+ - [getMasterPublicKeys](https://github.com/alexbosworth/ln-service#getmasterpublickeys):
161
+ List out master seed derived extended public keys and derivation paths.
160
162
  - [getMethods](https://github.com/alexbosworth/ln-service#getmethods): List RPC methods and
161
163
  permissions required to use them.
162
164
  - [getNetworkCentrality](https://github.com/alexbosworth/ln-service#getnetworkcentrality):
@@ -178,6 +180,8 @@ To access unauthenticated methods like the wallet unlocker, use
178
180
  Calculate the unconfirmed on-chain balance.
179
181
  - [getPendingChannels](https://github.com/alexbosworth/ln-service#getpendingchannels): List
180
182
  details of opening or closing channels.
183
+ - [getPendingPayments](https://github.com/alexbosworth/ln-service#getpendingpayments): List out
184
+ past pending payments.
181
185
  - [getPublicKey](https://github.com/alexbosworth/ln-service#getpublickey): Derive a public key at
182
186
  a given index.
183
187
  - [getRouteConfidence](https://github.com/alexbosworth/ln-service#getrouteconfidence): Check a
@@ -753,7 +753,8 @@ message SendRequest {
753
753
  The maximum number of satoshis that will be paid as a fee of the payment.
754
754
  This value can be represented either as a percentage of the amount being
755
755
  sent, or as a fixed amount of the maximum fee the user is willing the pay to
756
- send the payment.
756
+ send the payment. If not specified, lnd will use a default value of 100%
757
+ fees for small amounts (<=1k sat) or 5% fees for larger amounts.
757
758
  */
758
759
  FeeLimit fee_limit = 8;
759
760
 
@@ -2574,7 +2575,8 @@ message QueryRoutesRequest {
2574
2575
  The maximum number of satoshis that will be paid as a fee of the payment.
2575
2576
  This value can be represented either as a percentage of the amount being
2576
2577
  sent, or as a fixed amount of the maximum fee the user is willing the pay to
2577
- send the payment.
2578
+ send the payment. If not specified, lnd will use a default value of 100%
2579
+ fees for small amounts (<=1k sat) or 5% fees for larger amounts.
2578
2580
  */
2579
2581
  FeeLimit fee_limit = 5;
2580
2582
 
@@ -781,6 +781,21 @@ message ForwardHtlcInterceptResponse {
781
781
 
782
782
  // The preimage in case the resolve action is Settle.
783
783
  bytes preimage = 3;
784
+
785
+ // Encrypted failure message in case the resolve action is Fail.
786
+ //
787
+ // If failure_message is specified, the failure_code field must be set
788
+ // to zero.
789
+ bytes failure_message = 4;
790
+
791
+ // Return the specified failure code in case the resolve action is Fail. The
792
+ // message data fields are populated automatically.
793
+ //
794
+ // If a non-zero failure_code is specified, failure_message must not be set.
795
+ //
796
+ // For backwards-compatibility reasons, TEMPORARY_CHANNEL_FAILURE is the
797
+ // default value for this field.
798
+ lnrpc.Failure.FailureCode failure_code = 5;
784
799
  }
785
800
 
786
801
  enum ResolveHoldForwardAction {
package/index.js CHANGED
@@ -60,6 +60,7 @@ const {getPayments} = require('./lnd_methods');
60
60
  const {getPeers} = require('./lnd_methods');
61
61
  const {getPendingChainBalance} = require('./lnd_methods');
62
62
  const {getPendingChannels} = require('./lnd_methods');
63
+ const {getPendingPayments} = require('./lnd_methods');
63
64
  const {getPublicKey} = require('./lnd_methods');
64
65
  const {getRouteConfidence} = require('./lnd_methods');
65
66
  const {getRouteThroughHops} = require('./lnd_methods');
@@ -199,6 +200,7 @@ module.exports = {
199
200
  getPeers,
200
201
  getPendingChainBalance,
201
202
  getPendingChannels,
203
+ getPendingPayments,
202
204
  getPublicKey,
203
205
  getRouteConfidence,
204
206
  getRouteThroughHops,
@@ -58,6 +58,7 @@ const {getPayments} = require('./offchain');
58
58
  const {getPeers} = require('./peers');
59
59
  const {getPendingChainBalance} = require('./onchain');
60
60
  const {getPendingChannels} = require('./offchain');
61
+ const {getPendingPayments} = require('./offchain');
61
62
  const {getPublicKey} = require('./address');
62
63
  const {getRouteConfidence} = require('./generic');
63
64
  const {getRouteThroughHops} = require('./offchain');
@@ -193,6 +194,7 @@ module.exports = {
193
194
  getPeers,
194
195
  getPendingChainBalance,
195
196
  getPendingChannels,
197
+ getPendingPayments,
196
198
  getPublicKey,
197
199
  getRouteConfidence,
198
200
  getRouteThroughHops,
@@ -230,6 +230,10 @@
230
230
  "method": "PendingChannels",
231
231
  "type": "default"
232
232
  },
233
+ "getPendingPayments": {
234
+ "method": "ListPayments",
235
+ "type": "default"
236
+ },
233
237
  "getPublicKey": {
234
238
  "methods": ["DeriveKey", "DeriveNextKey"],
235
239
  "type": "wallet"
@@ -0,0 +1,136 @@
1
+ import {
2
+ AuthenticatedLightningArgs,
3
+ AuthenticatedLightningMethod,
4
+ PaginationArgs,
5
+ } from '../../typescript';
6
+
7
+ export type GetPendingPaymentsArgs = AuthenticatedLightningArgs<PaginationArgs>;
8
+
9
+ export type GetPendingPaymentsResult = {
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
+ /** Pending 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 Pending 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 pending payments made through channels.
130
+ *
131
+ * Requires `offchain:read` permission
132
+ */
133
+ export const getPendingPayments: AuthenticatedLightningMethod<
134
+ GetPendingPaymentsArgs,
135
+ GetPendingPaymentsResult
136
+ >;
@@ -0,0 +1,190 @@
1
+ const asyncAuto = require('async/auto');
2
+ const {returnResult} = require('asyncjs-util');
3
+
4
+ const {isLnd} = require('./../../lnd_requests');
5
+ const {rpcPaymentAsPayment} = require('./../../lnd_responses');
6
+ const {sortBy} = require('./../../arrays');
7
+
8
+ const defaultLimit = 250;
9
+ const {isArray} = Array;
10
+ const isPending = payment => !!payment && payment.status === 'IN_FLIGHT';
11
+ const lastPageFirstIndexOffset = 1;
12
+ const method = 'listPayments';
13
+ const {parse} = JSON;
14
+ const {stringify} = JSON;
15
+ const type = 'default';
16
+
17
+ /** Get pending payments made through channels.
18
+
19
+ Requires `offchain:read` permission
20
+
21
+ {
22
+ [limit]: <Page Result Limit Number>
23
+ lnd: <Authenticated LND API Object>
24
+ [token]: <Opaque Paging Token String>
25
+ }
26
+
27
+ @returns via cbk or Promise
28
+ {
29
+ payments: [{
30
+ attempts: [{
31
+ [failure]: {
32
+ code: <Error Type Code Number>
33
+ [details]: {
34
+ [channel]: <Standard Format Channel Id String>
35
+ [height]: <Error Associated Block Height Number>
36
+ [index]: <Failed Hop Index Number>
37
+ [mtokens]: <Error Millitokens String>
38
+ [policy]: {
39
+ base_fee_mtokens: <Base Fee Millitokens String>
40
+ cltv_delta: <Locktime Delta Number>
41
+ fee_rate: <Fees Charged in Millitokens Per Million Number>
42
+ [is_disabled]: <Channel is Disabled Bool>
43
+ max_htlc_mtokens: <Maximum HLTC Millitokens Value String>
44
+ min_htlc_mtokens: <Minimum HTLC Millitokens Value String>
45
+ updated_at: <Updated At ISO 8601 Date String>
46
+ }
47
+ [timeout_height]: <Error CLTV Timeout Height Number>
48
+ [update]: {
49
+ chain: <Chain Id Hex String>
50
+ channel_flags: <Channel Flags Number>
51
+ extra_opaque_data: <Extra Opaque Data Hex String>
52
+ message_flags: <Message Flags Number>
53
+ signature: <Channel Update Signature Hex String>
54
+ }
55
+ }
56
+ message: <Error Message String>
57
+ }
58
+ [index]: <Payment Add Index Number>
59
+ [confirmed_at]: <Payment Confirmed At ISO 8601 Date String>
60
+ is_confirmed: <Payment Attempt Succeeded Bool>
61
+ is_failed: <Payment Attempt Failed Bool>
62
+ is_pending: <Payment Attempt is Waiting For Resolution Bool>
63
+ route: {
64
+ fee: <Route Fee Tokens Number>
65
+ fee_mtokens: <Route Fee Millitokens String>
66
+ hops: [{
67
+ channel: <Standard Format Channel Id String>
68
+ channel_capacity: <Channel Capacity Tokens Number>
69
+ fee: <Fee Number>
70
+ fee_mtokens: <Fee Millitokens String>
71
+ forward: <Forward Tokens Number>
72
+ forward_mtokens: <Forward Millitokens String>
73
+ [public_key]: <Forward Edge Public Key Hex String>
74
+ [timeout]: <Timeout Block Height Number>
75
+ }]
76
+ mtokens: <Total Fee-Inclusive Millitokens String>
77
+ [payment]: <Payment Identifier Hex String>
78
+ timeout: <Timeout Block Height Number>
79
+ tokens: <Total Fee-Inclusive Tokens Number>
80
+ [total_mtokens]: <Total Millitokens String>
81
+ }
82
+ }]
83
+ created_at: <Payment at ISO-8601 Date String>
84
+ [destination]: <Destination Node Public Key Hex String>
85
+ id: <Payment Preimage Hash String>
86
+ [index]: <Payment Add Index Number>
87
+ is_confirmed: <Payment is Confirmed Bool>
88
+ is_outgoing: <Transaction Is Outgoing Bool>
89
+ mtokens: <Millitokens Attempted to Pay to Destination String>
90
+ [request]: <BOLT 11 Payment Request String>
91
+ safe_tokens: <Payment Tokens Attempted to Pay Rounded Up Number>
92
+ tokens: <Rounded Down Tokens Attempted to Pay to Destination Number>
93
+ }]
94
+ [next]: <Next Opaque Paging Token String>
95
+ }
96
+ */
97
+ module.exports = ({limit, lnd, token}, cbk) => {
98
+ return new Promise((resolve, reject) => {
99
+ return asyncAuto({
100
+ // Check arguments
101
+ validate: cbk => {
102
+ if (!!limit && !!token) {
103
+ return cbk([400, 'ExpectedNoLimitPagingPendingPaymentsWithToken']);
104
+ }
105
+
106
+ if (!isLnd({lnd, method, type})) {
107
+ return cbk([400, 'ExpectedLndForGetPendingPaymentsRequest']);
108
+ }
109
+
110
+ return cbk();
111
+ },
112
+
113
+ // Get all payments
114
+ listPayments: ['validate', ({}, cbk) => {
115
+ let offset;
116
+ let resultsLimit = limit || defaultLimit;
117
+
118
+ if (!!token) {
119
+ try {
120
+ const pagingToken = parse(token);
121
+
122
+ offset = pagingToken.offset;
123
+ resultsLimit = pagingToken.limit;
124
+ } catch (err) {
125
+ return cbk([400, 'ExpectedValidPagingTokenForGetPending', {err}]);
126
+ }
127
+ }
128
+
129
+ return lnd[type][method]({
130
+ include_incomplete: true,
131
+ index_offset: offset || Number(),
132
+ max_payments: resultsLimit,
133
+ reversed: true,
134
+ },
135
+ (err, res) => {
136
+ if (!!err) {
137
+ return cbk([503, 'UnexpectedGetPendingPaymentsError', {err}]);
138
+ }
139
+
140
+ if (!res || !isArray(res.payments)) {
141
+ return cbk([503, 'ExpectedPendingPaymentsInListPaymentsResponse']);
142
+ }
143
+
144
+ if (typeof res.last_index_offset !== 'string') {
145
+ return cbk([503, 'ExpectedLastIndexOffsetWhenRequestingPending']);
146
+ }
147
+
148
+ const lastOffset = Number(res.last_index_offset);
149
+ const offset = Number(res.first_index_offset);
150
+
151
+ const token = stringify({offset, limit: resultsLimit});
152
+
153
+ return cbk(null, {
154
+ payments: res.payments.filter(isPending),
155
+ token: offset <= lastPageFirstIndexOffset ? undefined : token,
156
+ });
157
+ });
158
+ }],
159
+
160
+ // Check and map payments
161
+ foundPayments: ['listPayments', ({listPayments}, cbk) => {
162
+ try {
163
+ const payments = listPayments.payments.map(rpcPaymentAsPayment);
164
+
165
+ return cbk(null, payments);
166
+ } catch (err) {
167
+ return cbk([503, err.message]);
168
+ }
169
+ }],
170
+
171
+ // Final found pending payments
172
+ payments: [
173
+ 'foundPayments',
174
+ 'listPayments',
175
+ ({foundPayments, listPayments}, cbk) =>
176
+ {
177
+ const payments = sortBy({
178
+ array: foundPayments,
179
+ attribute: 'created_at',
180
+ });
181
+
182
+ return cbk(null, {
183
+ next: listPayments.token || undefined,
184
+ payments: payments.sorted.reverse(),
185
+ });
186
+ }],
187
+ },
188
+ returnResult({reject, resolve, of: 'payments'}, cbk));
189
+ });
190
+ };
@@ -24,6 +24,7 @@ export * from './get_pathfinding_settings';
24
24
  export * from './get_payment';
25
25
  export * from './get_payments';
26
26
  export * from './get_pending_channels';
27
+ export * from './get_pending_payments';
27
28
  export * from './get_route_through_hops';
28
29
  export * from './is_destination_payable';
29
30
  export * from './pay_via_payment_details';
@@ -24,6 +24,7 @@ const getPathfindingSettings = require('./get_pathfinding_settings');
24
24
  const getPayment = require('./get_payment');
25
25
  const getPayments = require('./get_payments');
26
26
  const getPendingChannels = require('./get_pending_channels');
27
+ const getPendingPayments = require('./get_pending_payments');
27
28
  const getRouteThroughHops = require('./get_route_through_hops');
28
29
  const isDestinationPayable = require('./is_destination_payable');
29
30
  const pay = require('./pay');
@@ -79,6 +80,7 @@ module.exports = {
79
80
  getPayment,
80
81
  getPayments,
81
82
  getPendingChannels,
83
+ getPendingPayments,
82
84
  getRouteThroughHops,
83
85
  isDestinationPayable,
84
86
  pay,
@@ -96,6 +96,11 @@ module.exports = ({lnd}) => {
96
96
  return;
97
97
  }
98
98
 
99
+ // Exit early when there is no payment
100
+ if (!res.payment) {
101
+ return;
102
+ }
103
+
99
104
  // Emit payment details
100
105
  return emitter.emit(event, res.payment);
101
106
  });
@@ -205,7 +205,7 @@ module.exports = (args, cbk) => {
205
205
  }],
206
206
 
207
207
  // Derive the raw transaction from the funded PSBT
208
- tx: ['fund', ({ecp, fund}, cbk) => {
208
+ tx: ['ecp', 'fund', ({ecp, fund}, cbk) => {
209
209
  const {psbt} = fund;
210
210
 
211
211
  try {
@@ -0,0 +1,28 @@
1
+ import {
2
+ AuthenticatedLightningArgs,
3
+ AuthenticatedLightningMethod,
4
+ } from '../../typescript';
5
+
6
+ export type GetMasterPublicKeysArgs = AuthenticatedLightningArgs;
7
+
8
+ export type GetMasterPublicKeysResult = {
9
+ keys: {
10
+ /** Key Derivation Path String> */
11
+ derivation_path: string;
12
+ /** Base58 Encoded Master Public Key String> */
13
+ extended_public_key: string;
14
+ /** Used External Keys Count Number> */
15
+ external_key_count: number;
16
+ /** Used Internal Keys Count Number> */
17
+ internal_key_count: number;
18
+ /** Node has Master Private Key Bool> */
19
+ is_watch_only: boolean;
20
+ /** Account Name String> */
21
+ named: string;
22
+ }[];
23
+ };
24
+
25
+ export const getMasterPublicKeys: AuthenticatedLightningMethod<
26
+ GetMasterPublicKeysArgs,
27
+ GetMasterPublicKeysResult
28
+ >;
@@ -8,6 +8,7 @@ export * from './get_chain_fee_estimate';
8
8
  export * from './get_chain_fee_rate';
9
9
  export * from './get_chain_transactions';
10
10
  export * from './get_locked_utxos';
11
+ export * from './get_master_public_keys';
11
12
  export * from './get_pending_chain_balance';
12
13
  export * from './get_sweep_transactions';
13
14
  export * from './get_utxos';
@@ -23,8 +23,8 @@ const type = 'default';
23
23
 
24
24
  Requires `offchain:write`, `onchain:write` permissions
25
25
 
26
- After getting the addresses and tokens to fund, use `fundChannels` within ten
27
- minutes to fund the channels.
26
+ After getting the addresses and tokens to fund, use `fundPendingChannels`
27
+ within ten minutes to fund the channels.
28
28
 
29
29
  If you do not fund the channels, be sure to `cancelPendingChannel` on each
30
30
  channel that was not funded.
package/package.json CHANGED
@@ -7,26 +7,26 @@
7
7
  "url": "https://github.com/alexbosworth/lightning/issues"
8
8
  },
9
9
  "dependencies": {
10
- "@grpc/grpc-js": "1.5.4",
10
+ "@grpc/grpc-js": "1.5.5",
11
11
  "@grpc/proto-loader": "0.6.9",
12
12
  "@types/express": "4.17.13",
13
- "@types/node": "17.0.16",
13
+ "@types/node": "17.0.18",
14
14
  "@types/request": "2.48.8",
15
15
  "@types/ws": "8.2.2",
16
16
  "async": "3.2.3",
17
17
  "asyncjs-util": "1.2.8",
18
18
  "bitcoinjs-lib": "6.0.1",
19
19
  "bn.js": "5.2.0",
20
- "body-parser": "1.19.1",
20
+ "body-parser": "1.19.2",
21
21
  "bolt07": "1.8.0",
22
- "bolt09": "0.2.1",
22
+ "bolt09": "0.2.2",
23
23
  "cbor": "8.1.0",
24
24
  "ecpair": "2.0.1",
25
25
  "express": "4.17.2",
26
26
  "invoices": "2.0.4",
27
27
  "psbt": "2.0.0",
28
28
  "tiny-secp256k1": "2.2.0",
29
- "type-fest": "2.11.1"
29
+ "type-fest": "2.11.2"
30
30
  },
31
31
  "description": "Lightning Network client library",
32
32
  "devDependencies": {
@@ -59,5 +59,5 @@
59
59
  "directory": "test/typescript"
60
60
  },
61
61
  "types": "index.d.ts",
62
- "version": "5.6.3"
62
+ "version": "5.8.1"
63
63
  }
@@ -1,6 +1,6 @@
1
1
  const {test} = require('@alexbosworth/tap');
2
2
 
3
- const {getPayments} = require('./../../../');
3
+ const {getFailedPayments} = require('./../../../');
4
4
 
5
5
  const makeLnd = args => {
6
6
  return {
@@ -64,41 +64,41 @@ const tests = [
64
64
  {
65
65
  args: makeArgs({limit: 1, token: 'token'}),
66
66
  description: 'A limit cannot be passed with a token',
67
- error: [400, 'UnexpectedLimitWhenPagingPaymentsWithToken'],
67
+ error: [400, 'ExpectedNoLimitWhenPagingPayFailuresWithToken'],
68
68
  },
69
69
  {
70
70
  args: makeArgs({lnd: undefined}),
71
71
  description: 'LND is required',
72
- error: [400, 'ExpectedLndForGetPaymentsRequest'],
72
+ error: [400, 'ExpectedLndForGetFailedPaymentsRequest'],
73
73
  },
74
74
  {
75
75
  args: makeArgs({token: 'token'}),
76
76
  description: 'A valid token is required',
77
- error: [400, 'ExpectedValidPagingTokenForPaymentReq'],
77
+ error: [400, 'ExpectedValidPagingTokenForGetFailed'],
78
78
  },
79
79
  {
80
80
  args: makeArgs({lnd: {default: {listPayments: ({}, cbk) => cbk('err')}}}),
81
81
  description: 'Errors from LND are passed back',
82
- error: [503, 'UnexpectedGetPaymentsError', {err: 'err'}],
82
+ error: [503, 'UnexpectedGetFailedPaymentsError', {err: 'err'}],
83
83
  },
84
84
  {
85
85
  args: makeArgs({lnd: {default: {listPayments: ({}, cbk) => cbk()}}}),
86
86
  description: 'A response is expected from LND',
87
- error: [503, 'ExpectedPaymentsInListPaymentsResponse'],
87
+ error: [503, 'ExpectedFailedPaymentsInListPaymentsResponse'],
88
88
  },
89
89
  {
90
90
  args: makeArgs({
91
91
  lnd: {default: {listPayments: ({}, cbk) => cbk(null, {})}},
92
92
  }),
93
93
  description: 'A response with payments is expected from LND',
94
- error: [503, 'ExpectedPaymentsInListPaymentsResponse'],
94
+ error: [503, 'ExpectedFailedPaymentsInListPaymentsResponse'],
95
95
  },
96
96
  {
97
97
  args: makeArgs({
98
98
  lnd: {default: {listPayments: ({}, cbk) => cbk(null, {payments: []})}},
99
99
  }),
100
100
  description: 'A response with payments and last index is expected',
101
- error: [503, 'ExpectedLastIndexOffsetWhenRequestingPayments'],
101
+ error: [503, 'ExpectedLastIndexOffsetWhenRequestingFailed'],
102
102
  },
103
103
  {
104
104
  args: makeArgs({
@@ -106,7 +106,7 @@ const tests = [
106
106
  default: {
107
107
  listPayments: ({}, cbk) => cbk(null, {
108
108
  last_index_offset: '1',
109
- payments: [{}],
109
+ payments: [{ status: 'FAILED' }],
110
110
  }),
111
111
  },
112
112
  },
@@ -146,9 +146,9 @@ const tests = [
146
146
  tests.forEach(({args, description, error, expected}) => {
147
147
  return test(description, async ({end, rejects, strictSame}) => {
148
148
  if (!!error) {
149
- await rejects(() => getPayments(args), error, 'Got expected error');
149
+ await rejects(() => getFailedPayments(args), error, 'Got expected error');
150
150
  } else {
151
- const {payments} = await getPayments(args);
151
+ const {payments} = await getFailedPayments(args);
152
152
 
153
153
  const [payment] = payments;
154
154
 
@@ -0,0 +1,160 @@
1
+ const {test} = require('@alexbosworth/tap');
2
+
3
+ const {getPendingPayments} = require('./../../../');
4
+
5
+ const makeLnd = args => {
6
+ return {
7
+ default: {
8
+ listPayments: ({}, cbk) => cbk(null, {
9
+ first_index_offset: args.first_index_offset || '1',
10
+ payments: [{
11
+ creation_date: '1',
12
+ creation_time_ns: '1',
13
+ failure_reason: '',
14
+ fee_msat: '1000',
15
+ fee_sat: '1',
16
+ htlcs: [],
17
+ path: [Buffer.alloc(33, 2).toString('hex')],
18
+ payment_hash: Buffer.alloc(32).toString('hex'),
19
+ payment_index: '1',
20
+ payment_preimage: Buffer.alloc(32).toString('hex'),
21
+ payment_request: '',
22
+ status: 'IN_FLIGHT',
23
+ value: '1',
24
+ value_msat: '1000',
25
+ value_sat: '1',
26
+ }],
27
+ last_index_offset: args.last_index_offset || '1',
28
+ }),
29
+ },
30
+ };
31
+ };
32
+
33
+ const makeArgs = overrides => {
34
+ const args = {lnd: makeLnd({})};
35
+
36
+ Object.keys(overrides).forEach(k => args[k] = overrides[k]);
37
+
38
+ return args;
39
+ };
40
+
41
+ const makeExpectedPayment = ({}) => {
42
+ return {
43
+ destination: undefined,
44
+ attempts: [],
45
+ confirmed_at: undefined,
46
+ created_at: '1970-01-01T00:00:00.000Z',
47
+ fee: undefined,
48
+ fee_mtokens: undefined,
49
+ hops: [],
50
+ id: '0000000000000000000000000000000000000000000000000000000000000000',
51
+ index: 1,
52
+ is_confirmed: false,
53
+ is_outgoing: true,
54
+ mtokens: '1000',
55
+ request: undefined,
56
+ secret: undefined,
57
+ safe_fee: undefined,
58
+ safe_tokens: 1,
59
+ tokens: 1,
60
+ };
61
+ };
62
+
63
+ const tests = [
64
+ {
65
+ args: makeArgs({limit: 1, token: 'token'}),
66
+ description: 'A limit cannot be passed with a token',
67
+ error: [400, 'ExpectedNoLimitPagingPendingPaymentsWithToken'],
68
+ },
69
+ {
70
+ args: makeArgs({lnd: undefined}),
71
+ description: 'LND is required',
72
+ error: [400, 'ExpectedLndForGetPendingPaymentsRequest'],
73
+ },
74
+ {
75
+ args: makeArgs({token: 'token'}),
76
+ description: 'A valid token is required',
77
+ error: [400, 'ExpectedValidPagingTokenForGetPending'],
78
+ },
79
+ {
80
+ args: makeArgs({lnd: {default: {listPayments: ({}, cbk) => cbk('err')}}}),
81
+ description: 'Errors from LND are passed back',
82
+ error: [503, 'UnexpectedGetPendingPaymentsError', {err: 'err'}],
83
+ },
84
+ {
85
+ args: makeArgs({lnd: {default: {listPayments: ({}, cbk) => cbk()}}}),
86
+ description: 'A response is expected from LND',
87
+ error: [503, 'ExpectedPendingPaymentsInListPaymentsResponse'],
88
+ },
89
+ {
90
+ args: makeArgs({
91
+ lnd: {default: {listPayments: ({}, cbk) => cbk(null, {})}},
92
+ }),
93
+ description: 'A response with payments is expected from LND',
94
+ error: [503, 'ExpectedPendingPaymentsInListPaymentsResponse'],
95
+ },
96
+ {
97
+ args: makeArgs({
98
+ lnd: {default: {listPayments: ({}, cbk) => cbk(null, {payments: []})}},
99
+ }),
100
+ description: 'A response with payments and last index is expected',
101
+ error: [503, 'ExpectedLastIndexOffsetWhenRequestingPending'],
102
+ },
103
+ {
104
+ args: makeArgs({
105
+ lnd: {
106
+ default: {
107
+ listPayments: ({}, cbk) => cbk(null, {
108
+ last_index_offset: '1',
109
+ payments: [{status: 'IN_FLIGHT'}],
110
+ }),
111
+ },
112
+ },
113
+ }),
114
+ description: 'A response with valid payments is expected',
115
+ error: [503, 'ExpectedCreationDateInRpcPaymentDetails'],
116
+ },
117
+ {
118
+ args: makeArgs({}),
119
+ description: 'A payment is returned',
120
+ expected: {payment: makeExpectedPayment({})},
121
+ },
122
+ {
123
+ args: makeArgs({
124
+ lnd: {
125
+ default: {
126
+ listPayments: ({}, cbk) => cbk(null, {
127
+ last_index_offset: '1',
128
+ payments: [],
129
+ }),
130
+ },
131
+ },
132
+ }),
133
+ description: 'No payments are returned',
134
+ expected: {},
135
+ },
136
+ {
137
+ args: makeArgs({
138
+ lnd: makeLnd({first_index_offset: '2'}),
139
+ token: JSON.stringify({limit: 1, offset: 1})
140
+ }),
141
+ description: 'A payment is returned when a token is specified',
142
+ expected: {payment: makeExpectedPayment({})},
143
+ },
144
+ ];
145
+
146
+ tests.forEach(({args, description, error, expected}) => {
147
+ return test(description, async ({end, rejects, strictSame}) => {
148
+ if (!!error) {
149
+ await rejects(() => getPendingPayments(args), error, 'Got error');
150
+ } else {
151
+ const {payments} = await getPendingPayments(args);
152
+
153
+ const [payment] = payments;
154
+
155
+ strictSame(payment, expected.payment, 'Got expected payment');
156
+ }
157
+
158
+ return end();
159
+ });
160
+ });
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "overrides": [
3
- ["lightning", 3468],
3
+ ["lightning", 3470],
4
4
  ["router", 100],
5
5
  ["walletkit", 3],
6
6
  ["walletunlocker", 2]
@@ -0,0 +1,19 @@
1
+ import {expectError, expectType} from 'tsd';
2
+ import {AuthenticatedLnd} from '../../lnd_grpc';
3
+ import {
4
+ getMasterPublicKeys,
5
+ GetMasterPublicKeysResult,
6
+ } from '../../lnd_methods';
7
+
8
+ const lnd = {} as AuthenticatedLnd;
9
+
10
+ expectError(getMasterPublicKeys());
11
+ expectError(getMasterPublicKeys({}));
12
+
13
+ expectType<GetMasterPublicKeysResult>(await getMasterPublicKeys({lnd}));
14
+
15
+ expectType<void>(
16
+ getMasterPublicKeys({lnd}, (error, result) => {
17
+ expectType<GetMasterPublicKeysResult>(result);
18
+ })
19
+ );
@@ -0,0 +1,31 @@
1
+ import {expectError, expectType} from 'tsd';
2
+ import {AuthenticatedLnd} from '../../lnd_grpc';
3
+ import {getPendingPayments, GetPendingPaymentsResult} from '../../lnd_methods';
4
+
5
+ const lnd = {} as AuthenticatedLnd;
6
+ const limit = 1;
7
+ const token = 'token';
8
+
9
+ expectError(getPendingPayments());
10
+ expectError(getPendingPayments({}));
11
+ expectError(getPendingPayments({lnd, limit, token})); // ExpectedNoLimitPagingPendingPaymentsWithToken
12
+
13
+ expectType<GetPendingPaymentsResult>(await getPendingPayments({lnd}));
14
+ expectType<GetPendingPaymentsResult>(await getPendingPayments({lnd, limit}));
15
+ expectType<GetPendingPaymentsResult>(await getPendingPayments({lnd, token}));
16
+
17
+ expectType<void>(
18
+ getPendingPayments({lnd}, (error, result) => {
19
+ expectType<GetPendingPaymentsResult>(result);
20
+ })
21
+ );
22
+ expectType<void>(
23
+ getPendingPayments({lnd, limit}, (error, result) => {
24
+ expectType<GetPendingPaymentsResult>(result);
25
+ })
26
+ );
27
+ expectType<void>(
28
+ getPendingPayments({lnd, token}, (error, result) => {
29
+ expectType<GetPendingPaymentsResult>(result);
30
+ })
31
+ );