lightning 9.2.1 → 9.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Versions
2
2
 
3
+ ## 9.3.1
4
+
5
+ - `subscribeToPastPayment`, `subscribeToPayViaDetails`,
6
+ `subscribeToPayViaRequest`, `subscribeToPayments`: Add `id` for `failed`
7
+ payment hash
8
+
3
9
  ## 9.2.1
4
10
 
5
11
  - `getChannels`: Add support for `type` to show channel type
@@ -56,6 +56,8 @@ export type SubscribeToPastPaymentConfirmedEvent = {
56
56
  };
57
57
 
58
58
  export type SubscribeToPastPaymentFailedEvent = {
59
+ /** Payment Hash Hex */
60
+ id: string;
59
61
  /** Failed Due To Lack of Balance */
60
62
  is_insufficient_balance: boolean;
61
63
  /** Failed Due to Payment Rejected At Destination */
@@ -77,6 +77,7 @@ const unknownServiceErr = 'unknown service verrpc.Versioner';
77
77
 
78
78
  @event 'failed'
79
79
  {
80
+ id: <Payment Hash Hex String>
80
81
  is_insufficient_balance: <Failed Due To Lack of Balance Bool>
81
82
  is_invalid_payment: <Failed Due to Payment Rejected At Destination Bool>
82
83
  is_pathfinding_timeout: <Failed Due to Pathfinding Timeout Bool>
@@ -138,6 +138,8 @@ export type SubscribeToPayConfirmedEvent = {
138
138
  };
139
139
 
140
140
  export type SubscribeToPayFailedEvent = {
141
+ /** Payment Hash Hex */
142
+ id: string;
141
143
  /** Failed Due To Lack of Balance Bool> */
142
144
  is_insufficient_balance: boolean;
143
145
  /** Failed Due to Invalid Payment Bool> */
@@ -125,6 +125,7 @@ const unknownServiceErr = 'unknown service verrpc.Versioner';
125
125
 
126
126
  @event 'failed'
127
127
  {
128
+ id: <Payment Hash Hex String>
128
129
  is_insufficient_balance: <Failed Due To Lack of Balance Bool>
129
130
  is_invalid_payment: <Failed Due to Invalid Payment Bool>
130
131
  is_pathfinding_timeout: <Failed Due to Pathfinding Timeout Bool>
@@ -97,6 +97,7 @@ const type = 'router';
97
97
 
98
98
  @event 'failed'
99
99
  {
100
+ id: <Payment Hash Hex String>
100
101
  is_insufficient_balance: <Failed Due To Lack of Balance Bool>
101
102
  is_invalid_payment: <Failed Due to Invalid Payment Bool>
102
103
  is_pathfinding_timeout: <Failed Due to Pathfinding Timeout Bool>
@@ -77,6 +77,7 @@ const type = 'router';
77
77
 
78
78
  @event 'failed'
79
79
  {
80
+ id: <Payment Hash Hex String>
80
81
  is_insufficient_balance: <Failed Due To Lack of Balance Bool>
81
82
  is_invalid_payment: <Failed Due to Invalid Payment Bool>
82
83
  is_pathfinding_timeout: <Failed Due to Pathfinding Timeout Bool>
@@ -63,6 +63,7 @@ const type = 'router';
63
63
 
64
64
  @event 'failed'
65
65
  {
66
+ id: <Payment Hash Hex String>
66
67
  is_insufficient_balance: <Failed Due To Lack of Balance Bool>
67
68
  is_invalid_payment: <Failed Due to Payment Rejected At Destination Bool>
68
69
  is_pathfinding_timeout: <Failed Due to Pathfinding Timeout Bool>
@@ -6,6 +6,7 @@ const {isLnd} = require('./../../lnd_requests');
6
6
  const defaultConfirmations = 6;
7
7
  const isHash = n => /^[0-9A-F]{64}$/i.test(n);
8
8
  const isNumber = n => !isNaN(n);
9
+ const messageExternalUtxo = 'the passed output does not belong to the wallet';
9
10
  const method = 'bumpFee';
10
11
  const type = 'wallet';
11
12
 
@@ -76,6 +77,10 @@ module.exports = (args, cbk) => {
76
77
  target_conf: feeRate.target_conf,
77
78
  },
78
79
  (err, res) => {
80
+ if (!!err && err.details === messageExternalUtxo) {
81
+ return cbk([404, 'SpecifiedOutpointNotFoundInWalletUtxos']);
82
+ }
83
+
79
84
  if (!!err) {
80
85
  return cbk([500, 'UnexpectedErrorRequestingChainFeeBump', {err}]);
81
86
  }
@@ -1,10 +1,13 @@
1
1
  import {FailureReason} from '../typescript';
2
2
 
3
3
  export type FailureFromPaymentArgs = {
4
+ payment_hash: string;
4
5
  failure_reason: FailureReason;
5
6
  };
6
7
 
7
8
  export type FailureFromPaymentResult = {
9
+ /** Payment Hash Hex String */
10
+ id: string;
8
11
  /** Payment Failed Due to Insufficient Balance Bool */
9
12
  is_insufficient_balance: boolean;
10
13
  /** Payment Failed Due to Invalid Details Rejection Bool */
@@ -16,32 +19,40 @@ export type FailureFromPaymentResult = {
16
19
  };
17
20
 
18
21
  export function failureFromPayment(payment: {
22
+ payment_hash: string,
19
23
  failure_reason: 'FAILURE_REASON_INSUFFICIENT_BALANCE';
20
24
  }): {
25
+ id: string,
21
26
  is_insufficient_balance: true;
22
27
  is_invalid_payment: false;
23
28
  is_pathfinding_timeout: false;
24
29
  is_route_not_found: false;
25
30
  };
26
31
  export function failureFromPayment(payment: {
32
+ payment_hash: string,
27
33
  failure_reason: 'FAILURE_REASON_INCORRECT_PAYMENT_DETAILS';
28
34
  }): {
35
+ id: string,
29
36
  is_insufficient_balance: false;
30
37
  is_invalid_payment: true;
31
38
  is_pathfinding_timeout: false;
32
39
  is_route_not_found: false;
33
40
  };
34
41
  export function failureFromPayment(payment: {
42
+ payment_hash: string,
35
43
  failure_reason: 'FAILURE_REASON_TIMEOUT';
36
44
  }): {
45
+ id: string,
37
46
  is_insufficient_balance: false;
38
47
  is_invalid_payment: false;
39
48
  is_pathfinding_timeout: true;
40
49
  is_route_not_found: false;
41
50
  };
42
51
  export function failureFromPayment(payment: {
52
+ payment_hash: string,
43
53
  failure_reason: 'FAILURE_REASON_NO_ROUTE';
44
54
  }): {
55
+ id: string,
45
56
  is_insufficient_balance: false;
46
57
  is_invalid_payment: false;
47
58
  is_pathfinding_timeout: false;
@@ -1,13 +1,20 @@
1
1
  const {failureReason} = require('./constants');
2
2
 
3
+ const is256Hex = n => !!n && /^[0-9A-F]{64}$/i.test(n);
4
+
3
5
  /** Derive failure status from payment
4
6
 
5
7
  {
6
8
  failure_reason: <Payment Failure Reason String>
9
+ payment_hash: <Payment SHA256 Hash Hex String>
7
10
  }
8
11
 
12
+ @throws
13
+ <Error>
14
+
9
15
  @returns
10
16
  {
17
+ id: <Payment Hash Hex String>
11
18
  is_insufficient_balance: <Payment Failed Due to Insufficient Balance Bool>
12
19
  is_invalid_payment: <Payment Failed Due to Invalid Details Rejection Bool>
13
20
  is_pathfinding_timeout: <Failure Due To Pathfinding Timeout Failure Bool>
@@ -17,7 +24,12 @@ const {failureReason} = require('./constants');
17
24
  module.exports = payment => {
18
25
  const state = payment.failure_reason;
19
26
 
27
+ if (!is256Hex(payment.payment_hash)) {
28
+ throw new Error('ExpectedPaymentHashForPaymentAsFailedPayment');
29
+ }
30
+
20
31
  return {
32
+ id: payment.payment_hash,
21
33
  is_insufficient_balance: state === failureReason.insufficient_balance,
22
34
  is_invalid_payment: state === failureReason.invalid_payment,
23
35
  is_pathfinding_timeout: state === failureReason.pathfinding_timeout_failed,
package/package.json CHANGED
@@ -8,9 +8,9 @@
8
8
  },
9
9
  "dependencies": {
10
10
  "@grpc/grpc-js": "1.8.14",
11
- "@grpc/proto-loader": "0.7.6",
11
+ "@grpc/proto-loader": "0.7.7",
12
12
  "@types/express": "4.17.17",
13
- "@types/node": "18.16.2",
13
+ "@types/node": "20.1.2",
14
14
  "@types/request": "2.48.8",
15
15
  "@types/ws": "8.5.4",
16
16
  "async": "3.2.4",
@@ -26,7 +26,7 @@
26
26
  "invoices": "2.2.3",
27
27
  "psbt": "2.7.2",
28
28
  "tiny-secp256k1": "2.2.1",
29
- "type-fest": "3.9.0"
29
+ "type-fest": "3.10.0"
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": "9.2.1"
62
+ "version": "9.3.1"
63
63
  }
@@ -43,6 +43,19 @@ const tests = [
43
43
  description: 'A tx output index is required',
44
44
  error: [400, 'ExpectedTransactionOutputIndexToRequestFeeBump'],
45
45
  },
46
+ {
47
+ args: makeArgs({
48
+ lnd: {
49
+ wallet: {
50
+ bumpFee: ({}, cbk) => cbk({
51
+ details: 'the passed output does not belong to the wallet',
52
+ }),
53
+ },
54
+ },
55
+ }),
56
+ description: 'Unknown UTXO error is passed back',
57
+ error: [404, 'SpecifiedOutpointNotFoundInWalletUtxos'],
58
+ },
46
59
  {
47
60
  args: makeArgs({lnd: {wallet: {bumpFee: ({}, cbk) => cbk('err')}}}),
48
61
  description: 'Errors are passed back',
@@ -2,8 +2,11 @@ const {test} = require('@alexbosworth/tap');
2
2
 
3
3
  const {failureFromPayment} = require('./../../lnd_responses');
4
4
 
5
+ const id = Buffer.alloc(32).toString('hex')
6
+
5
7
  const makeExpected = overrides => {
6
8
  const expected = {
9
+ id,
7
10
  is_insufficient_balance: false,
8
11
  is_invalid_payment: false,
9
12
  is_pathfinding_timeout: false,
@@ -17,25 +20,42 @@ const makeExpected = overrides => {
17
20
 
18
21
  const tests = [
19
22
  {
20
- args: {failure_reason: 'FAILURE_REASON_INSUFFICIENT_BALANCE'},
23
+ args: {
24
+ failure_reason: 'FAILURE_REASON_INSUFFICIENT_BALANCE',
25
+ payment_hash: id,
26
+ },
21
27
  description: 'Insufficient balance mapped',
22
28
  expected: makeExpected({is_insufficient_balance: true}),
23
29
  },
24
30
  {
25
- args: {failure_reason: 'FAILURE_REASON_INCORRECT_PAYMENT_DETAILS'},
31
+ args: {
32
+ failure_reason: 'FAILURE_REASON_INCORRECT_PAYMENT_DETAILS',
33
+ payment_hash: id,
34
+ },
26
35
  description: 'Invalid payment is mapped',
27
36
  expected: makeExpected({is_invalid_payment: true}),
28
37
  },
29
38
  {
30
- args: {failure_reason: 'FAILURE_REASON_NO_ROUTE'},
39
+ args: {
40
+ failure_reason: 'FAILURE_REASON_NO_ROUTE',
41
+ payment_hash: id,
42
+ },
31
43
  description: 'No route is mapped',
32
44
  expected: makeExpected({is_route_not_found: true}),
33
45
  },
34
46
  {
35
- args: {failure_reason: 'FAILURE_REASON_TIMEOUT'},
47
+ args: {
48
+ failure_reason: 'FAILURE_REASON_TIMEOUT',
49
+ payment_hash: id,
50
+ },
36
51
  description: 'Timeout is mapped',
37
52
  expected: makeExpected({is_pathfinding_timeout: true}),
38
53
  },
54
+ {
55
+ args: {payment_hash: undefined},
56
+ description: 'A payment hash is expected',
57
+ error: 'ExpectedPaymentHashForPaymentAsFailedPayment',
58
+ },
39
59
  ];
40
60
 
41
61
  tests.forEach(({args, description, error, expected}) => {
@@ -1,41 +1,49 @@
1
1
  import {expectError, expectType} from 'tsd';
2
2
  import {failureFromPayment} from '../../lnd_responses/failure_from_payment';
3
3
 
4
+ const payment_hash = Buffer.alloc(32).toString('hex')
5
+
4
6
  expectError(failureFromPayment());
5
7
  expectError(failureFromPayment({}));
6
- expectError(failureFromPayment({failure_reason: 'invalid failure reason'}));
8
+ expectError(failureFromPayment({payment_hash, failure_reason: 'invalid failure reason'}));
7
9
 
8
10
  expectType<{
11
+ id: string;
9
12
  is_insufficient_balance: boolean;
10
13
  is_invalid_payment: boolean;
11
14
  is_pathfinding_timeout: boolean;
12
15
  is_route_not_found: boolean;
13
- }>(failureFromPayment({failure_reason: 'FAILURE_REASON_NONE'}));
16
+ }>(failureFromPayment({payment_hash, failure_reason: 'FAILURE_REASON_NONE'}));
14
17
  expectType<{
18
+ id: string;
15
19
  is_insufficient_balance: true;
16
20
  is_invalid_payment: false;
17
21
  is_pathfinding_timeout: false;
18
22
  is_route_not_found: false;
19
- }>(failureFromPayment({failure_reason: 'FAILURE_REASON_INSUFFICIENT_BALANCE'}));
23
+ }>(failureFromPayment({payment_hash, failure_reason: 'FAILURE_REASON_INSUFFICIENT_BALANCE'}));
20
24
  expectType<{
25
+ id: string;
21
26
  is_insufficient_balance: false;
22
27
  is_invalid_payment: true;
23
28
  is_pathfinding_timeout: false;
24
29
  is_route_not_found: false;
25
30
  }>(
26
31
  failureFromPayment({
32
+ payment_hash,
27
33
  failure_reason: 'FAILURE_REASON_INCORRECT_PAYMENT_DETAILS',
28
34
  })
29
35
  );
30
36
  expectType<{
37
+ id: string;
31
38
  is_insufficient_balance: false;
32
39
  is_invalid_payment: false;
33
40
  is_pathfinding_timeout: true;
34
41
  is_route_not_found: false;
35
- }>(failureFromPayment({failure_reason: 'FAILURE_REASON_TIMEOUT'}));
42
+ }>(failureFromPayment({payment_hash, failure_reason: 'FAILURE_REASON_TIMEOUT'}));
36
43
  expectType<{
44
+ id: string;
37
45
  is_insufficient_balance: false;
38
46
  is_invalid_payment: false;
39
47
  is_pathfinding_timeout: false;
40
48
  is_route_not_found: true;
41
- }>(failureFromPayment({failure_reason: 'FAILURE_REASON_NO_ROUTE'}));
49
+ }>(failureFromPayment({payment_hash, failure_reason: 'FAILURE_REASON_NO_ROUTE'}));