ln-service 53.7.1 → 53.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.
Files changed (40) hide show
  1. package/CHANGELOG.md +9 -1
  2. package/README.md +36 -0
  3. package/index.js +2 -0
  4. package/package.json +8 -6
  5. package/test/integration/test_add_peer.js +4 -2
  6. package/test/integration/test_delete_pending_channel.js +5 -2
  7. package/test/integration/test_get_closed_channels.js +0 -2
  8. package/test/integration/test_get_invoice.js +0 -1
  9. package/test/integration/test_get_node.js +13 -1
  10. package/test/integration/test_get_peers.js +32 -21
  11. package/test/integration/test_get_wallet_info.js +32 -26
  12. package/test/integration/test_open_channels.js +22 -15
  13. package/test/integration/test_pay.js +0 -1
  14. package/test/integration/test_pay_private_invoice.js +0 -1
  15. package/test/integration/test_propose_channel.js +438 -421
  16. package/test/integration/test_remove_peer.js +13 -9
  17. package/test/integration/test_send_message_to_peer.js +39 -28
  18. package/test/integration/test_send_to_chain_address.js +4 -0
  19. package/test/integration/test_subscribe_to_channels.js +0 -1
  20. package/test/integration/test_subscribe_to_invoices.js +80 -78
  21. package/test/integration/test_subscribe_to_peer_messages.js +6 -4
  22. package/test/integration/test_subscribe_to_peers.js +23 -19
  23. package/test/invoicesrpc-integration/test_get_sweep_transactions.js +0 -2
  24. package/test/invoicesrpc-integration/test_subscribe_cancel_invoice.js +0 -1
  25. package/test/macros/wait_for_channel.js +1 -1
  26. package/test/routerrpc-integration/test_delete_forwarding_reputations.js +61 -27
  27. package/test/routerrpc-integration/test_get_forwarding_reputations.js +42 -14
  28. package/test/routerrpc-integration/test_get_route_through_hops.js +33 -22
  29. package/test/routerrpc-integration/test_multipath_payment.js +0 -1
  30. package/test/routerrpc-integration/test_pay_via_payment_details.js +118 -111
  31. package/test/routerrpc-integration/test_pay_via_payment_request.js +92 -80
  32. package/test/routerrpc-integration/test_probe_for_route.js +78 -74
  33. package/test/routerrpc-integration/test_subscribe_to_forward_requests.js +0 -1
  34. package/test/routerrpc-integration/test_subscribe_to_forwards.js +518 -505
  35. package/test/routerrpc-integration/test_subscribe_to_past_payments.js +0 -3
  36. package/test/tower_clientrpc-integration/test_get_connected_watchtowers.js +0 -3
  37. package/test/walletrpc-integration/test_fund_psbt.js +113 -1
  38. package/test/walletrpc-integration/test_get_master_public_keys.js +79 -0
  39. package/test/walletrpc-integration/test_partially_sign_psbt.js +17 -5
  40. package/test/walletrpc-integration/test_sign_psbt.js +4 -1
package/CHANGELOG.md CHANGED
@@ -1,6 +1,14 @@
1
1
  # Versions
2
2
 
3
- ## 53.7.1
3
+ ## 53.8.1
4
+
5
+ - `fundPsbt`: Fix bip32 key derivation error
6
+
7
+ ## 53.8.0
8
+
9
+ - `getMasterPublicKeys`: Add method to get bip32 master public keys
10
+
11
+ ## 53.7.3
4
12
 
5
13
  - `payViaRoutes`, `subscribeToPayViaRoutes`: Add support for relay messages
6
14
 
package/README.md CHANGED
@@ -157,6 +157,7 @@ for `unlocker` methods.
157
157
  - [getInvoice](#getinvoice) - Get a previously created invoice
158
158
  - [getInvoices](#getinvoices) - Get all previously created invoices
159
159
  - [getLockedUtxos](#getlockedutxos) - Get all previously locked UTXOs
160
+ - [getMasterPublicKeys](#getmasterpublickeys) - Get a list of master pub keys
160
161
  - [getMethods](#getmethods) - Get available methods and associated permissions
161
162
  - [getNetworkCentrality](#getnetworkcentrality) - Get centrality score for nodes
162
163
  - [getNetworkGraph](#getnetworkgraph) - Get the channels and nodes of the graph
@@ -2102,6 +2103,41 @@ const {getLockedUtxos} = require('ln-service');
2102
2103
  const numLockedUtxos = (await getLockedUtxos({lnd})).utxos.length;
2103
2104
  ```
2104
2105
 
2106
+ ### getMasterPublicKeys
2107
+
2108
+ Get the currently tracked master public keys
2109
+
2110
+ Requires LND compiled with `walletrpc` build tag
2111
+
2112
+ Requires `onchain:read` permission
2113
+
2114
+ This method is not supported in LND 0.13.3 and below
2115
+
2116
+ {
2117
+ lnd: <Authenticated API LND Object>
2118
+ }
2119
+
2120
+ @returns via cbk or Promise
2121
+ {
2122
+ keys: [{
2123
+ derivation_path: <Key Derivation Path String>
2124
+ extended_public_key: <Base58 Encoded Master Public Key String>
2125
+ external_key_count: <Used External Keys Count Number>
2126
+ internal_key_count: <Used Internal Keys Count Number>
2127
+ is_watch_only: <Node has Master Private Key Bool>
2128
+ named: <Account Name String>
2129
+ }]
2130
+ }
2131
+
2132
+ ```node
2133
+ const {getMasterPublicKeys} = require('ln-service');
2134
+
2135
+ const {keys} = await getMasterPublicKeys({lnd});
2136
+
2137
+ // Find the master public key that derives pay to witness public key hash keys
2138
+ const masterAddressesKey = keys.find(n => n.derivation_path === `m/84'/0'/0'`);
2139
+ ```
2140
+
2105
2141
  ### getMethods
2106
2142
 
2107
2143
  Get the list of all methods and their associated requisite permissions
package/index.js CHANGED
@@ -49,6 +49,7 @@ const {getIdentity} = require('lightning');
49
49
  const {getInvoice} = require('lightning');
50
50
  const {getInvoices} = require('lightning');
51
51
  const {getLockedUtxos} = require('lightning');
52
+ const {getMasterPublicKeys} = require('lightning');
52
53
  const {getMethods} = require('lightning');
53
54
  const {getNetworkCentrality} = require('lightning');
54
55
  const {getNetworkGraph} = require('lightning');
@@ -189,6 +190,7 @@ module.exports = {
189
190
  getInvoice,
190
191
  getInvoices,
191
192
  getLockedUtxos,
193
+ getMasterPublicKeys,
192
194
  getMethods,
193
195
  getNetworkCentrality,
194
196
  getNetworkGraph,
package/package.json CHANGED
@@ -10,11 +10,11 @@
10
10
  "bolt07": "1.8.0",
11
11
  "cors": "2.8.5",
12
12
  "express": "4.17.2",
13
- "invoices": "2.0.3",
14
- "lightning": "5.6.1",
13
+ "invoices": "2.0.4",
14
+ "lightning": "5.7.1",
15
15
  "macaroon": "3.0.4",
16
16
  "morgan": "1.10.0",
17
- "ws": "8.4.2"
17
+ "ws": "8.5.0"
18
18
  },
19
19
  "description": "Interaction helper for your Lightning Network daemon",
20
20
  "devDependencies": {
@@ -22,13 +22,15 @@
22
22
  "@alexbosworth/node-fetch": "2.6.2",
23
23
  "async": "3.2.3",
24
24
  "asyncjs-util": "1.2.8",
25
+ "bip32": "3.0.1",
25
26
  "bip66": "1.1.5",
26
27
  "bitcoinjs-lib": "6.0.1",
27
28
  "bn.js": "5.2.0",
29
+ "bs58check": "2.1.2",
28
30
  "ecpair": "2.0.1",
29
- "ln-docker-daemons": "2.2.3",
31
+ "ln-docker-daemons": "2.2.4",
30
32
  "portfinder": "1.0.28",
31
- "psbt": "1.1.11",
33
+ "psbt": "2.0.0",
32
34
  "rimraf": "3.0.2",
33
35
  "secp256k1": "4.0.3",
34
36
  "tiny-secp256k1": "2.2.0",
@@ -66,5 +68,5 @@
66
68
  "integration-test-0.12.0": "DOCKER_LND_VERSION=v0.12.0-beta npm run test",
67
69
  "test": "echo $DOCKER_LND_VERSION && tap -j 2 --branches=1 --functions=1 --lines=1 --statements=1 -t 200 test/autopilotrpc-integration/*.js test/chainrpc-integration/*.js test/integration/*.js test/invoicesrpc-integration/*.js test/routerrpc-integration/*.js test/signerrpc-integration/*.js test/tower_clientrpc-integration/*.js test/tower_serverrpc-integration/*.js test/walletrpc-integration/*.js"
68
70
  },
69
- "version": "53.7.1"
71
+ "version": "53.8.1"
70
72
  }
@@ -8,8 +8,8 @@ const {getPeers} = require('./../../');
8
8
 
9
9
  const interval = 100;
10
10
  const size = 2;
11
- const times = 100;
12
- const timeout = 1;
11
+ const times = 2000;
12
+ const timeout = 100;
13
13
 
14
14
  // Adding peers should result in a connected peer
15
15
  test(`Add a peer`, async ({end, equal}) => {
@@ -27,6 +27,8 @@ test(`Add a peer`, async ({end, equal}) => {
27
27
  lnd,
28
28
  timeout,
29
29
  public_key: target.id,
30
+ retry_count: 1,
31
+ retry_delay: 1,
30
32
  socket: target.socket,
31
33
  });
32
34
 
@@ -5,6 +5,7 @@ const asyncRetry = require('async/retry');
5
5
  const {extractTransaction} = require('psbt');
6
6
  const {spawnLightningCluster} = require('ln-docker-daemons');
7
7
  const {test} = require('@alexbosworth/tap');
8
+ const tinysecp = require('tiny-secp256k1');
8
9
 
9
10
  const {addPeer} = require('./../../');
10
11
  const {broadcastChainTransaction} = require('./../../');
@@ -27,11 +28,13 @@ const count = 100;
27
28
  const interval = 100;
28
29
  const race = promises => Promise.race(promises);
29
30
  const size = 3;
30
- const timeout = 1000 * 5;
31
+ const timeout = 1000 * 20;
31
32
  const times = 200;
32
33
 
33
34
  // Forfeiting a pending channel should remove the pending channel
34
35
  test(`Forfeit pending channel`, async ({end, equal, strictSame}) => {
36
+ const ecp = (await import('ecpair')).ECPairFactory(tinysecp);
37
+
35
38
  const {kill, nodes} = await spawnLightningCluster({size});
36
39
 
37
40
  const [control, target, remote] = nodes;
@@ -105,7 +108,7 @@ test(`Forfeit pending channel`, async ({end, equal, strictSame}) => {
105
108
  funding: signRemote.psbt,
106
109
  });
107
110
 
108
- const {transaction} = extractTransaction({psbt: signRemote.psbt});
111
+ const {transaction} = extractTransaction({ecp, psbt: signRemote.psbt});
109
112
 
110
113
  await broadcastChainTransaction({lnd, transaction});
111
114
 
@@ -9,9 +9,7 @@ const {createHodlInvoice} = require('./../../');
9
9
  const {delay} = require('./../macros');
10
10
  const {payViaPaymentRequest} = require('./../../');
11
11
  const {getChainTransactions} = require('./../../');
12
- const {getChannels} = require('./../../');
13
12
  const {getClosedChannels} = require('./../../');
14
- const {getHeight} = require('./../../');
15
13
  const {getPendingChannels} = require('./../../');
16
14
  const {getSweepTransactions} = require('./../../');
17
15
  const {getUtxos} = require('./../../');
@@ -2,7 +2,6 @@ const {spawnLightningCluster} = require('ln-docker-daemons');
2
2
  const {test} = require('@alexbosworth/tap');
3
3
 
4
4
  const {createInvoice} = require('./../../');
5
- const {getHeight} = require('./../../');
6
5
  const {getInvoice} = require('./../../');
7
6
  const {pay} = require('./../../');
8
7
  const {setupChannel} = require('./../macros');
@@ -1,3 +1,4 @@
1
+ const asyncRetry = require('async/retry');
1
2
  const {spawnLightningCluster} = require('ln-docker-daemons');
2
3
  const {test} = require('@alexbosworth/tap');
3
4
 
@@ -15,8 +16,10 @@ const confirmationCount = 20;
15
16
  const defaultFee = 1e3;
16
17
  const defaultAliasLength = '00000000000000000000'.length;
17
18
  const feeRate = 21;
19
+ const interval = 10;
18
20
  const mtokPerTok = BigInt(1e3);
19
21
  const size = 3;
22
+ const times = 1000;
20
23
 
21
24
  // Getting a node should return the public graph node info
22
25
  test(`Get node`, async ({end, equal, strictSame}) => {
@@ -42,7 +45,16 @@ test(`Get node`, async ({end, equal, strictSame}) => {
42
45
  transaction_vout: controlToTarget.transaction_vout,
43
46
  });
44
47
 
45
- await addPeer({lnd, public_key: remote.id, socket: remote.socket});
48
+ await asyncRetry({interval, times}, async () => {
49
+ await addPeer({
50
+ lnd,
51
+ public_key: remote.id,
52
+ retry_count: 1,
53
+ retry_delay: 1,
54
+ socket: remote.socket,
55
+ timeout: 1000,
56
+ });
57
+ });
46
58
 
47
59
  await delay(3000);
48
60
 
@@ -15,27 +15,38 @@ test('Get peers', async ({end, equal}) => {
15
15
 
16
16
  const [{lnd}, target] = nodes;
17
17
 
18
- await asyncRetry({interval, times}, async () => {
19
- await addPeer({lnd, public_key: target.id, socket: target.socket});
20
-
21
- const [peer] = (await getPeers({lnd})).peers;
22
-
23
- if (!peer || !peer.is_sync_peer) {
24
- throw new Error('ExpectedSyncPeer');
25
- }
26
-
27
- equal(peer.bytes_received !== undefined, true, 'Bytes received');
28
- equal(peer.bytes_sent !== undefined, true, 'Bytes sent');
29
- equal(peer.is_inbound, false, 'Is inbound peer');
30
- equal(peer.is_sync_peer, true, 'Is sync peer');
31
- equal(peer.ping_time, 0, 'Ping time');
32
- equal(peer.public_key, target.id, 'Public key');
33
- equal(!!peer.socket, true, 'Socket');
34
- equal(peer.tokens_received, 0, 'Tokens received');
35
- equal(peer.tokens_sent, 0, 'Tokens sent');
36
-
37
- return;
38
- });
18
+ try {
19
+ await asyncRetry({interval, times}, async () => {
20
+ await addPeer({
21
+ lnd,
22
+ public_key: target.id,
23
+ retry_count: 1,
24
+ retry_delay: 1,
25
+ socket: target.socket,
26
+ timeout: 100,
27
+ });
28
+
29
+ const [peer] = (await getPeers({lnd})).peers;
30
+
31
+ if (!peer || !peer.is_sync_peer) {
32
+ throw new Error('ExpectedSyncPeer');
33
+ }
34
+
35
+ equal(peer.bytes_received !== undefined, true, 'Bytes received');
36
+ equal(peer.bytes_sent !== undefined, true, 'Bytes sent');
37
+ equal(peer.is_inbound, false, 'Is inbound peer');
38
+ equal(peer.is_sync_peer, true, 'Is sync peer');
39
+ equal(peer.ping_time, 0, 'Ping time');
40
+ equal(peer.public_key, target.id, 'Public key');
41
+ equal(!!peer.socket, true, 'Socket');
42
+ equal(peer.tokens_received, 0, 'Tokens received');
43
+ equal(peer.tokens_sent, 0, 'Tokens sent');
44
+
45
+ return;
46
+ });
47
+ } catch (err) {
48
+ equal(err, null, 'Expected no error');
49
+ }
39
50
 
40
51
  await kill({});
41
52
 
@@ -12,34 +12,40 @@ const times = 1000;
12
12
  const walletInfoType = 'wallet';
13
13
 
14
14
  // Getting the wallet info should return info about the wallet
15
- test(`Get wallet info`, async ({end, equal, strictSame}) => {
15
+ test(`Get wallet info`, async ({end, equal, ok, strictSame}) => {
16
16
  const {kill, nodes} = await spawnLightningCluster({});
17
17
 
18
- const [{lnd}] = nodes;
19
-
20
- const result = await getWalletInfo({lnd});
21
-
22
- await asyncRetry({interval, times}, async () => {
23
- if (result.current_block_height === initHeight) {
24
- return;
25
- }
26
-
27
- throw new Error('ExpectedBlockHeightAtInitHeight');
28
- });
29
-
30
- equal(result.active_channels_count, 0, 'Expected channels count');
31
- equal(!!result.alias, true, 'Expected alias');
32
- strictSame(result.chains, [regtestChainId], 'Got chains');
33
- equal(!!result.current_block_hash, true, 'Expected best block hash');
34
- equal(result.current_block_height, initHeight, 'Expected best block height');
35
- equal(!!result.latest_block_at, true, 'Last block time');
36
- equal(result.peers_count, 0, 'Expected wallet peers count');
37
- equal(result.pending_channels_count, 0, 'Expected pending channels count');
38
- equal(result.public_key.length, pubKeyHexLength, 'Expected public key');
39
- strictSame(result.uris.length, 1, 'Expected node URI');
40
- equal(!!result.version, true, 'Expected version');
41
-
42
- await kill({});
18
+ const [{generate, lnd}] = nodes;
19
+
20
+ try {
21
+ const result = await asyncRetry({interval, times}, async () => {
22
+ await generate({});
23
+
24
+ const result = await getWalletInfo({lnd});
25
+
26
+ if (result.current_block_height >= initHeight) {
27
+ return result;
28
+ }
29
+
30
+ throw new Error('ExpectedBlockHeightAtInitHeight');
31
+ });
32
+
33
+ equal(result.active_channels_count, 0, 'Expected channels count');
34
+ equal(!!result.alias, true, 'Expected alias');
35
+ strictSame(result.chains, [regtestChainId], 'Got chains');
36
+ equal(!!result.current_block_hash, true, 'Expected best block hash');
37
+ ok(result.current_block_height >= initHeight, 'Expected block height');
38
+ equal(!!result.latest_block_at, true, 'Last block time');
39
+ equal(result.peers_count, 0, 'Expected wallet peers count');
40
+ equal(result.pending_channels_count, 0, 'Expected pending channels count');
41
+ equal(result.public_key.length, pubKeyHexLength, 'Expected public key');
42
+ strictSame(result.uris.length, 1, 'Expected node URI');
43
+ equal(!!result.version, true, 'Expected version');
44
+ } catch (err) {
45
+ equal(err, null, 'Expected no error');
46
+ } finally {
47
+ await kill({});
48
+ }
43
49
 
44
50
  return end();
45
51
  });
@@ -4,6 +4,7 @@ const {extractTransaction} = require('psbt');
4
4
  const {finalizePsbt} = require('psbt');
5
5
  const {spawnLightningCluster} = require('ln-docker-daemons');
6
6
  const {test} = require('@alexbosworth/tap');
7
+ const tinysecp = require('tiny-secp256k1');
7
8
  const {transactionAsPsbt} = require('psbt');
8
9
 
9
10
  const {addPeer} = require('./../../');
@@ -29,27 +30,29 @@ const times = 2000;
29
30
 
30
31
  // Opening channels should open up channels
31
32
  test(`Open channels`, async ({end, equal}) => {
33
+ const ecp = (await import('ecpair')).ECPairFactory(tinysecp);
34
+
32
35
  const {kill, nodes} = await spawnLightningCluster({size});
33
36
 
34
37
  const [{generate, lnd}, target, remote] = nodes;
35
38
 
36
- await generate({count: maturity});
39
+ try {
40
+ await generate({count: maturity});
37
41
 
38
- await asyncRetry({interval, times}, async () => {
39
- const lnds = [lnd, target.lnd, remote.lnd];
42
+ await asyncRetry({interval, times}, async () => {
43
+ const lnds = [lnd, target.lnd, remote.lnd];
40
44
 
41
- const heights = await asyncMap(lnds, async lnd => {
42
- return (await getHeight({lnd})).current_block_height;
43
- });
45
+ const heights = await asyncMap(lnds, async lnd => {
46
+ return (await getHeight({lnd})).current_block_height;
47
+ });
44
48
 
45
- const [controlHeight, targetHeight, remoteHeight] = heights;
49
+ const [controlHeight, targetHeight, remoteHeight] = heights;
46
50
 
47
- if (controlHeight !== targetHeight || controlHeight !== remoteHeight) {
48
- throw new Error('ExpectedSyncHeights');
49
- }
50
- });
51
+ if (controlHeight !== targetHeight || controlHeight !== remoteHeight) {
52
+ throw new Error('ExpectedSyncHeights');
53
+ }
54
+ });
51
55
 
52
- try {
53
56
  const chainTx = (await getChainTransactions({lnd})).transactions;
54
57
 
55
58
  const spending = chainTx.map(({transaction}) => transaction);
@@ -97,11 +100,15 @@ test(`Open channels`, async ({end, equal}) => {
97
100
  .map(({transaction}) => transaction)
98
101
  .find(transaction => spending.find(spend => transaction !== spend));
99
102
 
100
- const fundingPsbt = transactionAsPsbt({spending, transaction: fundTx});
103
+ const fundingPsbt = transactionAsPsbt({
104
+ ecp,
105
+ spending,
106
+ transaction: fundTx,
107
+ });
101
108
 
102
- const {psbt} = finalizePsbt({psbt: fundingPsbt.psbt});
109
+ const {psbt} = finalizePsbt({ecp, psbt: fundingPsbt.psbt});
103
110
 
104
- const reconstitutedTransaction = extractTransaction({psbt});
111
+ const reconstitutedTransaction = extractTransaction({ecp, psbt});
105
112
 
106
113
  await fundPendingChannels({
107
114
  lnd,
@@ -10,7 +10,6 @@ const {createInvoice} = require('./../../');
10
10
  const {decodePaymentRequest} = require('./../../');
11
11
  const {delay} = require('./../macros');
12
12
  const {getChannel} = require('./../../');
13
- const {getChannels} = require('./../../');
14
13
  const {getHeight} = require('./../../');
15
14
  const {getNetworkGraph} = require('./../../');
16
15
  const {getRouteToDestination} = require('./../../');
@@ -8,7 +8,6 @@ const {cancelHodlInvoice} = require('./../../');
8
8
  const {createInvoice} = require('./../../');
9
9
  const {decodePaymentRequest} = require('./../../');
10
10
  const {getChannel} = require('./../../');
11
- const {getChannels} = require('./../../');
12
11
  const {getInvoice} = require('./../../');
13
12
  const {getRouteToDestination} = require('./../../');
14
13
  const {openChannel} = require('./../../');