ln-service 53.7.3 → 53.8.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Versions
2
2
 
3
+ ## 53.8.0
4
+
5
+ - `getMasterPublicKeys`: Add method to get bip32 master public keys
6
+
3
7
  ## 53.7.3
4
8
 
5
9
  - `payViaRoutes`, `subscribeToPayViaRoutes`: Add support for relay messages
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.2",
13
+ "invoices": "2.0.4",
14
+ "lightning": "5.6.3",
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,9 +22,11 @@
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
31
  "ln-docker-daemons": "2.2.4",
30
32
  "portfinder": "1.0.28",
@@ -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.3"
71
+ "version": "53.8.0"
70
72
  }
@@ -78,6 +78,10 @@ test(`Send to chain address`, async ({end, equal}) => {
78
78
  lnd: control.lnd,
79
79
  });
80
80
 
81
+ if (!!(await getChainBalance({lnd: control.lnd})).chain_balance) {
82
+ throw new Error('ExpectedChainBalanceOnControlEmptiedOut');
83
+ }
84
+
81
85
  return;
82
86
  });
83
87
 
@@ -0,0 +1,79 @@
1
+ const bip32 = require('bip32');
2
+ const bs58check = require('bs58check');
3
+ const ecc = require('tiny-secp256k1')
4
+ const {spawnLightningCluster} = require('ln-docker-daemons');
5
+ const {test} = require('@alexbosworth/tap');
6
+
7
+ const {createChainAddress} = require('./../../');
8
+ const {getMasterPublicKeys} = require('./../../');
9
+
10
+ const asHex = n => n.toString('hex');
11
+ const BIP32Factory = bip32.default;
12
+ const chainCodeFromMasterPublicKey = n => n.slice(13, 45);
13
+ const firstKeyPath = 'm/0/0';
14
+ const identityKeyName = 'act:6';
15
+ const p2wpkhPath = `m/84'/0'/0'`;
16
+ const publicKeyFromMasterPublicKey = n => n.slice(45, 78);
17
+
18
+ // Getting master public keys should return a list of master public keys
19
+ test(`Get master public keys`, async ({end, equal, strictSame}) => {
20
+ const [{id, kill, lnd}] = (await spawnLightningCluster({})).nodes;
21
+
22
+ const {fromPublicKey} = await BIP32Factory(ecc);
23
+
24
+ // This method is not supported on LND 0.13.3 and below
25
+ try {
26
+ const {keys} = await getMasterPublicKeys({lnd});
27
+
28
+ const [,, key] = keys;
29
+
30
+ // Check if extended keys are available
31
+ if (!key) {
32
+ await kill({});
33
+
34
+ return end();
35
+ }
36
+ } catch (err) {
37
+ strictSame(err, [501, 'GetMasterPublicKeysMethodNotSupported'], 'Got err');
38
+
39
+ await kill({});
40
+
41
+ return end();
42
+ }
43
+
44
+ try {
45
+ // Make a new address
46
+ const {address} = await createChainAddress({lnd});
47
+
48
+ // Get the list of accounts
49
+ const {keys} = await getMasterPublicKeys({lnd});
50
+
51
+ const masterP2wpkhKey = keys.find(n => n.derivation_path === p2wpkhPath);
52
+
53
+ // The address creation is reflected in the accounts metadata
54
+ equal(masterP2wpkhKey.external_key_count, [address].length, 'Key is used');
55
+
56
+ // Find the identity key master public key
57
+ const masterIdentityKey = keys.find(n => n.named === identityKeyName);
58
+
59
+ // Convert the key from base58 into its raw form
60
+ const rawKey = bs58check.decode(masterIdentityKey.extended_public_key);
61
+
62
+ const chainCode = chainCodeFromMasterPublicKey(rawKey);
63
+ const publicKey = publicKeyFromMasterPublicKey(rawKey);
64
+
65
+ // Make a bip32 object to derive from
66
+ const masterKey = fromPublicKey(publicKey, chainCode);
67
+
68
+ // Pull out the first key from the identity master public key
69
+ const identityKey = masterKey.derivePath(firstKeyPath);
70
+
71
+ equal(asHex(identityKey.publicKey), id, 'Got identity master public key');
72
+ } catch (err) {
73
+ equal(err, null, 'Expected no error');
74
+ }
75
+
76
+ await kill({});
77
+
78
+ return end();
79
+ });
@@ -158,6 +158,11 @@ test(`Partially sign PSBT`, async ({end, equal, strictSame}) => {
158
158
 
159
159
  const bip32Derivations = flatten(allDerivations);
160
160
 
161
+ // Exit early when derivations are not supported
162
+ if (!!bip32Derivations.filter(n => !n).length) {
163
+ await partiallySignPsbt({lnd: control.lnd, psbt: base.psbt});
164
+ }
165
+
161
166
  // Update the PSBT so that it has the consolidated details
162
167
  const updated = updatePsbt({
163
168
  ecp,