lightning 6.2.6 → 6.3.0

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 (42) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +2 -0
  3. package/grpc/protos/lightning.proto +42 -0
  4. package/index.js +2 -0
  5. package/lnd_methods/address/create_chain_address.js +1 -1
  6. package/lnd_methods/index.js +2 -0
  7. package/lnd_methods/info/constants.json +1 -0
  8. package/lnd_methods/info/get_route_to_destination.js +1 -1
  9. package/lnd_methods/macaroon/methods.json +4 -0
  10. package/lnd_methods/offchain/get_settlement_status.js +90 -0
  11. package/lnd_methods/offchain/index.js +2 -0
  12. package/lnd_methods/offchain/is_destination_payable.js +1 -1
  13. package/lnd_methods/offchain/pay.js +1 -1
  14. package/lnd_methods/offchain/pay_via_payment_details.js +1 -1
  15. package/lnd_methods/offchain/pay_via_payment_request.js +1 -1
  16. package/lnd_methods/offchain/probe_for_route.js +1 -1
  17. package/lnd_methods/offchain/subscribe_to_pay.js +1 -1
  18. package/lnd_methods/offchain/subscribe_to_pay_via_details.js +1 -1
  19. package/lnd_methods/offchain/subscribe_to_pay_via_request.js +1 -1
  20. package/lnd_methods/offchain/subscribe_to_probe_for_route.js +1 -1
  21. package/lnd_methods/onchain/subscribe_to_chain_spend.js +1 -1
  22. package/lnd_methods/peers/add_external_socket.d.ts +1 -1
  23. package/lnd_methods/peers/add_external_socket.js +1 -1
  24. package/lnd_methods/peers/remove_external_socket.d.ts +1 -1
  25. package/lnd_methods/peers/remove_external_socket.js +1 -1
  26. package/lnd_methods/peers/update_alias.js +1 -1
  27. package/lnd_methods/peers/update_color.js +1 -1
  28. package/lnd_methods/signer/begin_group_signing_session.js +1 -1
  29. package/lnd_methods/signer/end_group_signing_session.js +1 -1
  30. package/lnd_methods/signer/sign_transaction.d.ts +1 -1
  31. package/lnd_methods/signer/sign_transaction.js +2 -2
  32. package/lnd_methods/signer/update_group_signing_session.js +1 -1
  33. package/package.json +5 -5
  34. package/test/lnd_methods/address/test_get_public_key.js +42 -0
  35. package/test/lnd_methods/info/test_get_wallet_info.js +5 -0
  36. package/test/lnd_methods/offchain/test_disconnect_watchtower.js +4 -0
  37. package/test/lnd_methods/offchain/test_get_settlement_status.js +84 -0
  38. package/test/lnd_methods/onchain/test_get_chain_fee_estimate.js +17 -0
  39. package/test/lnd_methods/onchain/test_lock_utxo.js +5 -0
  40. package/test/lnd_methods/signer/test_sign_transaction.js +11 -0
  41. package/test/lnd_methods/unauthenticated/test_create_wallet.js +20 -0
  42. package/test/lnd_methods/unauthenticated/test_subscribe_to_wallet_status.js +12 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Versions
2
2
 
3
+ ## 6.3.0
4
+
5
+ - `getSettlementStatus`: Add method to lookup received htlc settlement status
6
+
7
+ ## 6.2.7
8
+
9
+ - `getWalletInfo`: Add support for LND 0.14.5
10
+
3
11
  ## 6.2.6
4
12
 
5
13
  - `getWalletInfo`: Add support for LND 0.15.4
package/README.md CHANGED
@@ -212,6 +212,8 @@ variables set:
212
212
  Calculate a route through specified nodes.
213
213
  - [getRouteToDestination](https://github.com/alexbosworth/ln-service#getroutetodestination):
214
214
  Calculate a route through the graph to a destination.
215
+ - [getSettlementStatus](https://github.com/alexbosworth/ln-service#getsettlementstatus):
216
+ Lookup the status of a received payment output
215
217
  - [getSweepTransactions](https://github.com/alexbosworth/ln-service#getsweeptransactions): List
216
218
  transactions that are sweeping funds on-chain.
217
219
  - [getTowerServerInfo](https://github.com/alexbosworth/ln-service#gettowerserverinfo): General
@@ -577,6 +577,20 @@ service Lightning {
577
577
  zero conf).
578
578
  */
579
579
  rpc ListAliases (ListAliasesRequest) returns (ListAliasesResponse);
580
+
581
+ rpc LookupHtlc (LookupHtlcRequest) returns (LookupHtlcResponse);
582
+ }
583
+
584
+ message LookupHtlcRequest {
585
+ uint64 chan_id = 1;
586
+
587
+ uint64 htlc_index = 2;
588
+ }
589
+
590
+ message LookupHtlcResponse {
591
+ bool settled = 1;
592
+
593
+ bool offchain = 2;
580
594
  }
581
595
 
582
596
  message SubscribeCustomMessagesRequest {
@@ -2217,6 +2231,13 @@ message OpenChannelRequest {
2217
2231
  to use the default fee rate value specified in the config or 0.
2218
2232
  */
2219
2233
  bool use_fee_rate = 24;
2234
+
2235
+ /*
2236
+ The number of satoshis we require the remote peer to reserve. This value,
2237
+ if specified, must be above the dust limit and below 20% of the channel
2238
+ capacity.
2239
+ */
2240
+ uint64 remote_chan_reserve_sat = 25;
2220
2241
  }
2221
2242
  message OpenStatusUpdate {
2222
2243
  oneof update {
@@ -3047,6 +3068,9 @@ message LightningNode {
3047
3068
  repeated NodeAddress addresses = 4;
3048
3069
  string color = 5;
3049
3070
  map<uint32, Feature> features = 6;
3071
+
3072
+ // Custom node announcement tlv records.
3073
+ map<uint64, bytes> custom_records = 7;
3050
3074
  }
3051
3075
 
3052
3076
  message NodeAddress {
@@ -3062,6 +3086,9 @@ message RoutingPolicy {
3062
3086
  bool disabled = 5;
3063
3087
  uint64 max_htlc_msat = 6;
3064
3088
  uint32 last_update = 7;
3089
+
3090
+ // Custom channel update tlv records.
3091
+ map<uint64, bytes> custom_records = 8;
3065
3092
  }
3066
3093
 
3067
3094
  /*
@@ -3089,6 +3116,9 @@ message ChannelEdge {
3089
3116
 
3090
3117
  RoutingPolicy node1_policy = 7;
3091
3118
  RoutingPolicy node2_policy = 8;
3119
+
3120
+ // Custom channel announcement tlv records.
3121
+ map<uint64, bytes> custom_records = 9;
3092
3122
  }
3093
3123
 
3094
3124
  message ChannelGraphRequest {
@@ -3371,6 +3401,8 @@ message Invoice {
3371
3401
  repeated RouteHint route_hints = 14;
3372
3402
 
3373
3403
  // Whether this invoice should include routing hints for private channels.
3404
+ // Note: When enabled, if value and value_msat are zero, a large number of
3405
+ // hints with these channels can be included, which might not be desirable.
3374
3406
  bool private = 15;
3375
3407
 
3376
3408
  /*
@@ -4042,6 +4074,10 @@ message ForwardingHistoryRequest {
4042
4074
 
4043
4075
  // The max number of events to return in the response to this query.
4044
4076
  uint32 num_max_events = 4;
4077
+
4078
+ // Informs the server if the peer alias should be looked up for each
4079
+ // forwarding event.
4080
+ bool peer_alias_lookup = 5;
4045
4081
  }
4046
4082
  message ForwardingEvent {
4047
4083
  // Timestamp is the time (unix epoch offset) that this circuit was
@@ -4081,6 +4117,12 @@ message ForwardingEvent {
4081
4117
  // circuit was completed.
4082
4118
  uint64 timestamp_ns = 11;
4083
4119
 
4120
+ // The peer alias of the incoming channel.
4121
+ string peer_alias_in = 12;
4122
+
4123
+ // The peer alias of the outgoing channel.
4124
+ string peer_alias_out = 13;
4125
+
4084
4126
  // TODO(roasbeef): add settlement latency?
4085
4127
  // * use FPE on the chan id?
4086
4128
  // * also list failures?
package/index.js CHANGED
@@ -69,6 +69,7 @@ const {getPublicKey} = require('./lnd_methods');
69
69
  const {getRouteConfidence} = require('./lnd_methods');
70
70
  const {getRouteThroughHops} = require('./lnd_methods');
71
71
  const {getRouteToDestination} = require('./lnd_methods');
72
+ const {getSettlementStatus} = require('./lnd_methods');
72
73
  const {getSweepTransactions} = require('./lnd_methods');
73
74
  const {getTowerServerInfo} = require('./lnd_methods');
74
75
  const {getUtxos} = require('./lnd_methods');
@@ -218,6 +219,7 @@ module.exports = {
218
219
  getRouteConfidence,
219
220
  getRouteThroughHops,
220
221
  getRouteToDestination,
222
+ getSettlementStatus,
221
223
  getSweepTransactions,
222
224
  getTowerServerInfo,
223
225
  getUtxos,
@@ -17,7 +17,7 @@ const type = 'default';
17
17
 
18
18
  Requires `address:write` permission
19
19
 
20
- LND 0.14.3 and below do not support p2tr addresses
20
+ LND 0.14.5 and below do not support p2tr addresses
21
21
 
22
22
  {
23
23
  [format]: <Receive Address Type String> // "np2wpkh" || "p2tr" || "p2wpkh"
@@ -67,6 +67,7 @@ const {getPublicKey} = require('./address');
67
67
  const {getRouteConfidence} = require('./generic');
68
68
  const {getRouteThroughHops} = require('./offchain');
69
69
  const {getRouteToDestination} = require('./info');
70
+ const {getSettlementStatus} = require('./offchain');
70
71
  const {getSweepTransactions} = require('./onchain');
71
72
  const {getTowerServerInfo} = require('./info');
72
73
  const {getUtxos} = require('./onchain');
@@ -212,6 +213,7 @@ module.exports = {
212
213
  getRouteConfidence,
213
214
  getRouteThroughHops,
214
215
  getRouteToDestination,
216
+ getSettlementStatus,
215
217
  getSweepTransactions,
216
218
  getTowerServerInfo,
217
219
  getUtxos,
@@ -19,6 +19,7 @@
19
19
  "prefAttachType": "preferential",
20
20
  "versions": {
21
21
  "0d5b0fefa4d9082f7964836f5e58c3a6bda8e471": "0.10.2-beta",
22
+ "15c1eb13972f86a7c1e8cb084aa6d52700d685ff": "0.14.5-beta",
22
23
  "1a3194d302f33bb52823297d9d7f75cd37516053": "0.10.0-beta",
23
24
  "1e511be523eb8e97c4e2d9c89a7a263963a3929f": "0.14.2-beta",
24
25
  "3ae46d81f4a2edad06ef778b2940d9b06386d93b": "0.11.0-beta",
@@ -43,7 +43,7 @@ const trimByte = 0;
43
43
 
44
44
  Requires `info:read` permission
45
45
 
46
- Preferred `confidence` is not supported on LND 0.14.3 and below
46
+ Preferred `confidence` is not supported on LND 0.14.5 and below
47
47
 
48
48
  {
49
49
  [cltv_delta]: <Final CLTV Delta Number>
@@ -276,6 +276,10 @@
276
276
  "method": "QueryRoutes",
277
277
  "type": "default"
278
278
  },
279
+ "getSettlementStatus": {
280
+ "method": "LookupHtlc",
281
+ "type": "default"
282
+ },
279
283
  "getSweepTransactions": {
280
284
  "method": "ListSweeps",
281
285
  "type": "default"
@@ -0,0 +1,90 @@
1
+ const asyncAuto = require('async/auto');
2
+ const {chanNumber} = require('bolt07');
3
+ const {returnResult} = require('asyncjs-util');
4
+
5
+ const {isLnd} = require('./../../lnd_requests');
6
+
7
+ const errorNotFound = 'htlc unknown';
8
+ const errorUnimplemented = 'unknown method LookupHtlc for service lnrpc.Lightning';
9
+ const isBoolean = n => n === false || n === true;
10
+ const method = 'lookupHtlc';
11
+ const type = 'default';
12
+
13
+ /** Get the settlement status of a received HTLC
14
+
15
+ Note: this method is not supported in LND versions 0.15.4 and below
16
+
17
+ Requires `offchain:read` permissions
18
+
19
+ {
20
+ channel: <Standard Format Channel Id String>
21
+ payment: <Payment Id Number>
22
+ }
23
+
24
+ @returns via cbk or Promise
25
+ {
26
+ is_onchain: <Payment Went to Chain Bool>
27
+ is_settled: <Payment Is Settled Into Non-HTLC Balance Bool>
28
+ }
29
+ */
30
+ module.exports = ({channel, lnd, payment}, cbk) => {
31
+ return new Promise((resolve, reject) => {
32
+ return asyncAuto({
33
+ // Check arguments
34
+ validate: cbk => {
35
+ if (!channel) {
36
+ return cbk([400, 'ExpectedChannelIdToGetSettlementStatus']);
37
+ }
38
+
39
+ if (!isLnd({lnd, method, type})) {
40
+ return cbk([400, 'ExpectedLndToGetSettlementStatus']);
41
+ }
42
+
43
+ if (payment === undefined) {
44
+ return cbk([400, 'ExpectedHtlcIndexToGetSettlementStatus']);
45
+ }
46
+
47
+ return cbk();
48
+ },
49
+
50
+ // Get the settlement status of an HTLC
51
+ getStatus: ['validate', ({}, cbk) => {
52
+ return lnd[type][method]({
53
+ chan_id: chanNumber({channel}).number,
54
+ htlc_index: payment.toString(),
55
+ },
56
+ (err, res) => {
57
+ if (!!err && err.details === errorNotFound) {
58
+ return cbk([404, 'PaymentNotFound']);
59
+ }
60
+
61
+ if (!!err && err.details === errorUnimplemented) {
62
+ return cbk([501, 'LookupHtlcMethodUnsupported']);
63
+ }
64
+
65
+ if (!!err) {
66
+ return cbk([503, 'UnexpectedLookupHltcError', {err}]);
67
+ }
68
+
69
+ if (!res) {
70
+ return cbk([503, 'ExpectedHtlcLookupResponse']);
71
+ }
72
+
73
+ if (!isBoolean(res.offchain)) {
74
+ return cbk([503, 'ExpectedOffchainStatusInHtlcLookupResponse']);
75
+ }
76
+
77
+ if (!isBoolean(res.settled)) {
78
+ return cbk([503, 'ExpectedSettledStatusInHtlcLookupResponse']);
79
+ }
80
+
81
+ return cbk(null, {
82
+ is_onchain: !res.offchain,
83
+ is_settled: res.settled,
84
+ });
85
+ });
86
+ }],
87
+ },
88
+ returnResult({reject, resolve, of: 'getStatus'}, cbk));
89
+ });
90
+ };
@@ -27,6 +27,7 @@ const getPayments = require('./get_payments');
27
27
  const getPendingChannels = require('./get_pending_channels');
28
28
  const getPendingPayments = require('./get_pending_payments');
29
29
  const getRouteThroughHops = require('./get_route_through_hops');
30
+ const getSettlementStatus = require('./get_settlement_status');
30
31
  const isDestinationPayable = require('./is_destination_payable');
31
32
  const pay = require('./pay');
32
33
  const payViaPaymentDetails = require('./pay_via_payment_details');
@@ -85,6 +86,7 @@ module.exports = {
85
86
  getPendingChannels,
86
87
  getPendingPayments,
87
88
  getRouteThroughHops,
89
+ getSettlementStatus,
88
90
  isDestinationPayable,
89
91
  pay,
90
92
  payViaPaymentDetails,
@@ -9,7 +9,7 @@ const defaultTokens = 1;
9
9
 
10
10
  Requires `offchain:write` permission
11
11
 
12
- Preferred `confidence` is not supported on LND 0.14.3 and below
12
+ Preferred `confidence` is not supported on LND 0.14.5 and below
13
13
 
14
14
  {
15
15
  [cltv_delta]: <Final CLTV Delta Number>
@@ -17,7 +17,7 @@ const payViaRoutes = require('./pay_via_routes');
17
17
 
18
18
  `max_path_mtokens` is not supported in LND 0.12.0 or below
19
19
 
20
- Preferred `confidence` is not supported on LND 0.14.3 and below
20
+ Preferred `confidence` is not supported on LND 0.14.5 and below
21
21
 
22
22
  {
23
23
  [confidence]: <Preferred Route Confidence Number Out of One Million Number>
@@ -19,7 +19,7 @@ const type = 'router';
19
19
 
20
20
  `max_path_mtokens` is not supported in LND 0.12.0 or below
21
21
 
22
- Preferred `confidence` is not supported on LND 0.14.3 and below
22
+ Preferred `confidence` is not supported on LND 0.14.5 and below
23
23
 
24
24
  {
25
25
  [cltv_delta]: <Final CLTV Delta Number>
@@ -14,7 +14,7 @@ const type = 'router';
14
14
 
15
15
  `max_path_mtokens` is not supported in LND 0.12.0 or below
16
16
 
17
- Preferred `confidence` is not supported on LND 0.14.3 and below
17
+ Preferred `confidence` is not supported on LND 0.14.5 and below
18
18
 
19
19
  {
20
20
  [confidence]: <Preferred Route Confidence Number Out of One Million Number>
@@ -17,7 +17,7 @@ const isHex = n => !(n.length % 2) && /^[0-9A-F]*$/i.test(n);
17
17
 
18
18
  Requires `offchain:write` permission
19
19
 
20
- Preferred `confidence` is not supported on LND 0.14.3 and below
20
+ Preferred `confidence` is not supported on LND 0.14.5 and below
21
21
 
22
22
  {
23
23
  [cltv_delta]: <Final CLTV Delta Number>
@@ -44,7 +44,7 @@ const unknownServiceErr = 'unknown service verrpc.Versioner';
44
44
 
45
45
  `max_path_mtokens` is not supported in LND 0.12.0 or below
46
46
 
47
- Preferred `confidence` is not supported on LND 0.14.3 and below
47
+ Preferred `confidence` is not supported on LND 0.14.5 and below
48
48
 
49
49
  {
50
50
  [cltv_delta]: <Final CLTV Delta Number>
@@ -17,7 +17,7 @@ const type = 'router';
17
17
 
18
18
  `max_path_mtokens` is not supported in LND 0.12.0 or below
19
19
 
20
- Preferred `confidence` is not supported on LND 0.14.3 and below
20
+ Preferred `confidence` is not supported on LND 0.14.5 and below
21
21
 
22
22
  {
23
23
  [cltv_delta]: <Final CLTV Delta Number>
@@ -10,7 +10,7 @@ const type = 'router';
10
10
 
11
11
  `max_path_mtokens` is not supported in LND 0.12.0 or below
12
12
 
13
- Preferred `confidence` is not supported on LND 0.14.3 and below
13
+ Preferred `confidence` is not supported on LND 0.14.5 and below
14
14
 
15
15
  {
16
16
  [confidence]: <Preferred Route Confidence Number Out of One Million Number>
@@ -20,7 +20,7 @@ const {nextTick} = process;
20
20
 
21
21
  Requires `offchain:write` permission
22
22
 
23
- Preferred `confidence` is not supported on LND 0.14.3 and below
23
+ Preferred `confidence` is not supported on LND 0.14.5 and below
24
24
 
25
25
  {
26
26
  [cltv_delta]: <Final CLTV Delta Number>
@@ -24,7 +24,7 @@ const type = 'chain';
24
24
 
25
25
  Requires `onchain:read` permission
26
26
 
27
- Subscribing to P2TR outputs is not supported in LND 0.14.3 and below
27
+ Subscribing to P2TR outputs is not supported in LND 0.14.5 and below
28
28
 
29
29
  {
30
30
  [bech32_address]: <Bech32 P2WPKH or P2WSH Address String>
@@ -11,7 +11,7 @@ export type AddExternalSocketArgs = AuthenticatedLightningArgs<{
11
11
  /**
12
12
  * Add a new advertised p2p socket address
13
13
  *
14
- * Note: this method is not supported in LND versions 0.14.3 and below
14
+ * Note: this method is not supported in LND versions 0.14.5 and below
15
15
  *
16
16
  * Requires LND built with `peersrpc` build tag
17
17
  *
@@ -10,7 +10,7 @@ const type = 'peers';
10
10
 
11
11
  /** Add a new advertised p2p socket address
12
12
 
13
- Note: this method is not supported in LND versions 0.14.3 and below
13
+ Note: this method is not supported in LND versions 0.14.5 and below
14
14
 
15
15
  Requires LND built with `peersrpc` build tag
16
16
 
@@ -11,7 +11,7 @@ export type RemoveExternalSocketArgs = AuthenticatedLightningArgs<{
11
11
  /**
12
12
  * Remove an existing advertised p2p socket address
13
13
  *
14
- * Note: this method is not supported in LND versions 0.14.3 and below
14
+ * Note: this method is not supported in LND versions 0.14.5 and below
15
15
  *
16
16
  * Requires LND built with `peersrpc` build tag
17
17
  *
@@ -10,7 +10,7 @@ const type = 'peers';
10
10
 
11
11
  /** Remove an existing advertised p2p socket address
12
12
 
13
- Note: this method is not supported in LND versions 0.14.3 and below
13
+ Note: this method is not supported in LND versions 0.14.5 and below
14
14
 
15
15
  Requires LND built with `peersrpc` build tag
16
16
 
@@ -9,7 +9,7 @@ const type = 'peers';
9
9
 
10
10
  /** Update the node alias as advertised in the graph
11
11
 
12
- Note: this method is not supported in LND versions 0.14.3 and below
12
+ Note: this method is not supported in LND versions 0.14.5 and below
13
13
 
14
14
  Requires LND built with `peersrpc` build tag
15
15
 
@@ -9,7 +9,7 @@ const type = 'peers';
9
9
 
10
10
  /** Update the node color as advertised in the graph
11
11
 
12
- Note: this method is not supported in LND versions 0.14.3 and below
12
+ Note: this method is not supported in LND versions 0.14.5 and below
13
13
 
14
14
  Requires LND built with `peersrpc` build tag
15
15
 
@@ -21,7 +21,7 @@ const xOnlyPublicKey = hexKey => hexKey.slice(2);
21
21
 
22
22
  Requires `address:read`, `signer:generate` permissions
23
23
 
24
- This method is not supported in LND 0.14.3 and below
24
+ This method is not supported in LND 0.14.5 and below
25
25
 
26
26
  {
27
27
  lnd: <Authenticated LND API Object>
@@ -16,7 +16,7 @@ const type = 'signer';
16
16
 
17
17
  Requires `signer:generate` permission
18
18
 
19
- This method is not supported in LND 0.14.3 and below
19
+ This method is not supported in LND 0.14.5 and below
20
20
 
21
21
  {
22
22
  id: <Session Id Hex String>
@@ -44,7 +44,7 @@ export type SignTransactionResult = {
44
44
  *
45
45
  * Requires `signer:generate` permission
46
46
  *
47
- * `spending` is not supported in LND 0.14.3 and below
47
+ * `spending` is not supported in LND 0.14.5 and below
48
48
  */
49
49
  export const signTransaction: AuthenticatedLightningMethod<
50
50
  SignTransactionArgs,
@@ -21,8 +21,8 @@ const unimplementedError = '12 UNIMPLEMENTED: unknown service signrpc.Signer';
21
21
 
22
22
  Requires `signer:generate` permission
23
23
 
24
- `root_hash` is not supported in LND 0.14.3 and below
25
- `spending` is not supported in LND 0.14.3 and below
24
+ `root_hash` is not supported in LND 0.14.5 and below
25
+ `spending` is not supported in LND 0.14.5 and below
26
26
 
27
27
  {
28
28
  inputs: [{
@@ -19,7 +19,7 @@ const type = 'signer';
19
19
 
20
20
  Requires `signer:generate` permission
21
21
 
22
- This method is not supported in LND 0.14.3 and below
22
+ This method is not supported in LND 0.14.5 and below
23
23
 
24
24
  {
25
25
  hash: <Hash to Sign Hex String>
package/package.json CHANGED
@@ -23,18 +23,18 @@
23
23
  "cbor": "8.1.0",
24
24
  "ecpair": "2.1.0",
25
25
  "express": "4.18.2",
26
- "invoices": "2.2.0",
26
+ "invoices": "2.2.1",
27
27
  "psbt": "2.7.1",
28
28
  "tiny-secp256k1": "2.2.1",
29
- "type-fest": "3.1.0"
29
+ "type-fest": "3.2.0"
30
30
  },
31
31
  "description": "Lightning Network client library",
32
32
  "devDependencies": {
33
33
  "@alexbosworth/node-fetch": "2.6.2",
34
34
  "@alexbosworth/tap": "15.0.11",
35
35
  "tsd": "0.24.1",
36
- "typescript": "4.8.4",
37
- "ws": "8.10.0"
36
+ "typescript": "4.9.3",
37
+ "ws": "8.11.0"
38
38
  },
39
39
  "engines": {
40
40
  "node": ">=14"
@@ -59,5 +59,5 @@
59
59
  "directory": "test/typescript"
60
60
  },
61
61
  "types": "index.d.ts",
62
- "version": "6.2.6"
62
+ "version": "6.3.0"
63
63
  }
@@ -54,12 +54,54 @@ const tests = [
54
54
  args: {
55
55
  family: 1,
56
56
  index: 1,
57
+ lnd: {wallet: {deriveKey: ({}, cbk) => cbk(null, {
58
+ raw_key_bytes: Buffer.alloc(1),
59
+ })}},
60
+ },
61
+ description: 'Expects result key loc',
62
+ error: [503, 'ExpectedKeyLocatorInPublicKeyResponse'],
63
+ },
64
+ {
65
+ args: {
66
+ family: 1,
67
+ index: 1,
68
+ lnd: {wallet: {deriveKey: ({}, cbk) => cbk(null, {
69
+ key_loc: {},
70
+ raw_key_bytes: Buffer.alloc(1),
71
+ })}},
72
+ },
73
+ description: 'Expects result key loc index',
74
+ error: [503, 'ExpectedKeyIndexInPublicKeyResponse'],
75
+ },
76
+ {
77
+ args: {
78
+ family: 1,
79
+ index: 1,
80
+ lnd: {
81
+ wallet: {
82
+ deriveKey: ({}, cbk) => cbk(null, {
83
+ key_loc: {key_index: 0},
84
+ raw_key_bytes: Buffer.alloc(1),
85
+ }),
86
+ },
87
+ },
88
+ },
89
+ description: 'Got public key result',
90
+ expected: {public_key: '00'},
91
+ },
92
+ {
93
+ args: {
94
+ family: 1,
57
95
  lnd: {
58
96
  wallet: {
59
97
  deriveKey: ({}, cbk) => cbk(null, {
60
98
  key_loc: {key_index: 0},
61
99
  raw_key_bytes: Buffer.alloc(1),
62
100
  }),
101
+ deriveNextKey: ({}, cbk) => cbk(null, {
102
+ key_loc: {key_index: 0},
103
+ raw_key_bytes: Buffer.alloc(1),
104
+ }),
63
105
  },
64
106
  },
65
107
  },
@@ -36,6 +36,11 @@ const tests = [
36
36
  description: 'Connect fails returns error',
37
37
  error: [503, 'FailedToConnectToDaemon'],
38
38
  },
39
+ {
40
+ args: {lnd: makeLnd({err: {details: 'No connection established'}})},
41
+ description: 'Connect fails returns error',
42
+ error: [503, 'FailedToConnectToDaemon'],
43
+ },
39
44
  {
40
45
  args: {lnd: makeLnd({err: 'err'})},
41
46
  description: 'Generic failure returns back the error',
@@ -42,6 +42,10 @@ const tests = [
42
42
  description: 'Server error is returned',
43
43
  error: [503, 'UnexpectedErrDisconnectingWatchtower', {err: 'err'}],
44
44
  },
45
+ {
46
+ args: makeArgs({lnd: makeLnd({details: 'tower not found'})}),
47
+ description: 'Ignore removed already errors',
48
+ },
45
49
  {
46
50
  args: makeArgs({}),
47
51
  description: 'A tower is added',
@@ -0,0 +1,84 @@
1
+ const {test} = require('@alexbosworth/tap');
2
+
3
+ const {getSettlementStatus} = require('./../../../');
4
+
5
+ const makeLnd = ({err, res}) => {
6
+ const result = res === undefined ? {offchain: true, settled: true} : res;
7
+
8
+ return {default: {lookupHtlc: ({}, cbk) => cbk(err, result)}};
9
+ };
10
+
11
+ const makeArgs = overrides => {
12
+ const args = {channel: '0x0x0', lnd: makeLnd({}), payment: 0};
13
+
14
+ Object.keys(overrides).forEach(k => args[k] = overrides[k]);
15
+
16
+ return args;
17
+ };
18
+
19
+ const tests = [
20
+ {
21
+ args: makeArgs({channel: undefined}),
22
+ description: 'A channel id is required',
23
+ error: [400, 'ExpectedChannelIdToGetSettlementStatus'],
24
+ },
25
+ {
26
+ args: makeArgs({lnd: undefined}),
27
+ description: 'LND object is required',
28
+ error: [400, 'ExpectedLndToGetSettlementStatus'],
29
+ },
30
+ {
31
+ args: makeArgs({payment: undefined}),
32
+ description: 'A payment index is required',
33
+ error: [400, 'ExpectedHtlcIndexToGetSettlementStatus'],
34
+ },
35
+ {
36
+ args: makeArgs({lnd: makeLnd({err: {details: 'htlc unknown'}})}),
37
+ description: 'An HTLC not found error is returned',
38
+ error: [404, 'PaymentNotFound'],
39
+ },
40
+ {
41
+ args: makeArgs({lnd: makeLnd({err: {details: 'unknown method LookupHtlc for service lnrpc.Lightning'}})}),
42
+ description: 'A method not supported error is returned',
43
+ error: [501, 'LookupHtlcMethodUnsupported'],
44
+ },
45
+ {
46
+ args: makeArgs({lnd: makeLnd({err: 'err'})}),
47
+ description: 'A generic error is returned',
48
+ error: [503, 'UnexpectedLookupHltcError', {err: 'err'}],
49
+ },
50
+ {
51
+ args: makeArgs({lnd: makeLnd({res: null})}),
52
+ description: 'A response is expected',
53
+ error: [503, 'ExpectedHtlcLookupResponse'],
54
+ },
55
+ {
56
+ args: makeArgs({lnd: makeLnd({res: {}})}),
57
+ description: 'A chain status is expected',
58
+ error: [503, 'ExpectedOffchainStatusInHtlcLookupResponse'],
59
+ },
60
+ {
61
+ args: makeArgs({lnd: makeLnd({res: {offchain: true}})}),
62
+ description: 'A settlement status is expected',
63
+ error: [503, 'ExpectedSettledStatusInHtlcLookupResponse'],
64
+ },
65
+ {
66
+ args: makeArgs({}),
67
+ description: 'Settlement status is returned',
68
+ expected: {is_onchain: false, is_settled: true},
69
+ },
70
+ ];
71
+
72
+ tests.forEach(({args, description, error, expected}) => {
73
+ return test(description, async ({deepEqual, end, rejects, strictSame}) => {
74
+ if (!!error) {
75
+ await rejects(getSettlementStatus(args), error, 'Got expected error');
76
+ } else {
77
+ const res = await getSettlementStatus(args);
78
+
79
+ strictSame(res, expected, 'Got expected result');
80
+ }
81
+
82
+ return end();
83
+ });
84
+ });
@@ -94,6 +94,23 @@ const tests = [
94
94
  description: 'Passing 0 UTXO confirmations is supported',
95
95
  expected: {fee: 1, tokens_per_vbyte: 1},
96
96
  },
97
+ {
98
+ args: {
99
+ lnd: {
100
+ default: {
101
+ estimateFee: ({}, cbk) => cbk(null, {
102
+ fee_sat: '1',
103
+ feerate_sat_per_byte: '1',
104
+ sat_per_vbyte: '2',
105
+ }),
106
+ },
107
+ },
108
+ send_to: [{address: 'address', tokens: 1}],
109
+ utxo_confirmations: 0,
110
+ },
111
+ description: 'Sat per vbyte result is supported',
112
+ expected: {fee: 1, tokens_per_vbyte: 2},
113
+ },
97
114
  ];
98
115
 
99
116
  tests.forEach(({args, description, error, expected}) => {
@@ -17,6 +17,11 @@ const makeArgs = overrides => {
17
17
  };
18
18
 
19
19
  const tests = [
20
+ {
21
+ args: makeArgs({expires_at: '1970'}),
22
+ description: 'Cannot give a past expiry',
23
+ error: [400, 'ExpectedLaterDateToSetLockExpirationDateTo'],
24
+ },
20
25
  {
21
26
  args: makeArgs({lnd: undefined}),
22
27
  description: 'LND is required to lock a utxo',
@@ -84,6 +84,17 @@ const tests = [
84
84
  description: 'Buffers in raw sigs array are expected',
85
85
  expected: {signature: '00'},
86
86
  },
87
+ {
88
+ args: makeArgs({
89
+ override: {
90
+ inputs: [{
91
+ output_script: '51200000000000000000000000000000000000000000000000000000000000000000',
92
+ }],
93
+ },
94
+ }),
95
+ description: 'A taproot tx is signed',
96
+ expected: {signature: '00'},
97
+ },
87
98
  ];
88
99
 
89
100
  tests.forEach(({args, description, error, expected}) => {
@@ -18,6 +18,26 @@ const tests = [
18
18
  description: 'Seed is required',
19
19
  error: [400, 'ExpectedSeedMnemonicForWalletCreation'],
20
20
  },
21
+ {
22
+ args: {
23
+ lnd: {unlocker: {initWallet: ({}, cbk) => cbk()}},
24
+ passphrase: 'passphrase',
25
+ password: 'pass',
26
+ seed: 'seed',
27
+ },
28
+ description: 'A wallet creation is expected',
29
+ error: [503, 'ExpectedResponseForInitWallet'],
30
+ },
31
+ {
32
+ args: {
33
+ lnd: {unlocker: {initWallet: ({}, cbk) => cbk(null, {})}},
34
+ passphrase: 'passphrase',
35
+ password: 'pass',
36
+ seed: 'seed',
37
+ },
38
+ description: 'An admin macaroon is expected',
39
+ error: [503, 'ExpectedAdminMacaroonToCrateWallet'],
40
+ },
21
41
  {
22
42
  args: {
23
43
  lnd: {unlocker: {initWallet: ({}, cbk) => cbk('err')}},
@@ -86,6 +86,18 @@ const tests = [
86
86
  args: {lnd: makeLnd({state: 'RPC_ACTIVE'})},
87
87
  description: 'Active wallet state emitted',
88
88
  },
89
+ {
90
+ args: {lnd: makeLnd({state: 'SERVER_ACTIVE'})},
91
+ description: 'Active server state emitted',
92
+ },
93
+ {
94
+ args: {lnd: makeLnd({state: 'WAITING_TO_START'})},
95
+ description: 'Server waiting to start',
96
+ },
97
+ {
98
+ args: {lnd: makeLnd({state: 'undefined_state'})},
99
+ description: 'Server emitted an unknown event',
100
+ },
89
101
  {
90
102
  args: {lnd: makeLnd({state: 'UNLOCKED'})},
91
103
  description: 'Starting state emitted',