lightning 5.6.2 → 5.6.3

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,6 +1,6 @@
1
1
  # Versions
2
2
 
3
- ## 5.6.2
3
+ ## 5.6.3
4
4
 
5
5
  - `payViaRoutes`, `subscribeToPayViaRoutes`: Add support for relay messages
6
6
 
package/README.md CHANGED
@@ -42,8 +42,8 @@ Run `base64` on the tls.cert and admin.macaroon files to get the encoded
42
42
  authentication data to create the LND connection. You can find these files in
43
43
  the LND directory. (~/.lnd or ~/Library/Application Support/Lnd)
44
44
 
45
- base64 ~/.lnd/tls.cert | tr -d '\n'
46
- base64 ~/.lnd/data/chain/bitcoin/mainnet/admin.macaroon | tr -d '\n'
45
+ base64 -w0 ~/.lnd/tls.cert
46
+ base64 -w0 ~/.lnd/data/chain/bitcoin/mainnet/admin.macaroon
47
47
 
48
48
  You can then use these to interact with your LND node directly:
49
49
 
package/index.js CHANGED
@@ -48,6 +48,7 @@ const {getIdentity} = require('./lnd_methods');
48
48
  const {getInvoice} = require('./lnd_methods');
49
49
  const {getInvoices} = require('./lnd_methods');
50
50
  const {getLockedUtxos} = require('./lnd_methods');
51
+ const {getMasterPublicKeys} = require('./lnd_methods');
51
52
  const {getMethods} = require('./lnd_methods');
52
53
  const {getNetworkCentrality} = require('./lnd_methods');
53
54
  const {getNetworkGraph} = require('./lnd_methods');
@@ -186,6 +187,7 @@ module.exports = {
186
187
  getInvoice,
187
188
  getInvoices,
188
189
  getLockedUtxos,
190
+ getMasterPublicKeys,
189
191
  getMethods,
190
192
  getNetworkCentrality,
191
193
  getNetworkGraph,
@@ -46,6 +46,7 @@ const {getIdentity} = require('./info');
46
46
  const {getInvoice} = require('./invoices');
47
47
  const {getInvoices} = require('./invoices');
48
48
  const {getLockedUtxos} = require('./onchain');
49
+ const {getMasterPublicKeys} = require('./onchain');
49
50
  const {getMethods} = require('./info');
50
51
  const {getNetworkCentrality} = require('./info');
51
52
  const {getNetworkGraph} = require('./info');
@@ -180,6 +181,7 @@ module.exports = {
180
181
  getInvoice,
181
182
  getInvoices,
182
183
  getLockedUtxos,
184
+ getMasterPublicKeys,
183
185
  getMethods,
184
186
  getNetworkCentrality,
185
187
  getNetworkGraph,
@@ -181,6 +181,10 @@
181
181
  "method": "ListLeases",
182
182
  "type": "wallet"
183
183
  },
184
+ "getMasterPublicKeys": {
185
+ "method": "ListAccounts",
186
+ "type": "wallet"
187
+ },
184
188
  "getMethods": {
185
189
  "method": "ListPermissions",
186
190
  "type": "default"
@@ -0,0 +1,83 @@
1
+ const asyncAuto = require('async/auto');
2
+ const {returnResult} = require('asyncjs-util');
3
+
4
+ const {isLnd} = require('./../../lnd_requests');
5
+
6
+ const {isArray} = Array;
7
+ const method = 'listAccounts';
8
+ const notSupported = /unknown.*walletrpc.WalletKit/;
9
+ const type = 'wallet';
10
+
11
+ /** Get the currently tracked master public keys
12
+
13
+ Requires LND compiled with `walletrpc` build tag
14
+
15
+ Requires `onchain:read` permission
16
+
17
+ This method is not supported in LND 0.13.3 and below
18
+
19
+ {
20
+ lnd: <Authenticated API LND Object>
21
+ }
22
+
23
+ @returns via cbk or Promise
24
+ {
25
+ keys: [{
26
+ derivation_path: <Key Derivation Path String>
27
+ extended_public_key: <Base58 Encoded Master Public Key String>
28
+ external_key_count: <Used External Keys Count Number>
29
+ internal_key_count: <Used Internal Keys Count Number>
30
+ is_watch_only: <Node has Master Private Key Bool>
31
+ named: <Account Name String>
32
+ }]
33
+ }
34
+ */
35
+ module.exports = ({lnd}, cbk) => {
36
+ return new Promise((resolve, reject) => {
37
+ return asyncAuto({
38
+ // Check arguments
39
+ validate: cbk => {
40
+ if (!isLnd({lnd, method, type})) {
41
+ return cbk([400, 'ExpectedAuthenticatedLndToGetMasterPublicKeys']);
42
+ }
43
+
44
+ return cbk();
45
+ },
46
+
47
+ // Get master public keys
48
+ getKeys: ['validate', ({}, cbk) => {
49
+ return lnd[type][method]({}, (err, res) => {
50
+ if (!!err && notSupported.test(err.details)) {
51
+ return cbk([501, 'GetMasterPublicKeysMethodNotSupported']);
52
+ }
53
+
54
+ if (!!err) {
55
+ return cbk([503, 'UnexpectedErrorGettingMasterPublicKeys', {err}]);
56
+ }
57
+
58
+ if (!res) {
59
+ return cbk([503, 'ExpectedResultForMasterPublicKeyListRequest']);
60
+ }
61
+
62
+ if (!isArray(res.accounts)) {
63
+ return cbk([503, 'ExpectedArrayOfAccountsInMasterPublicKeysList']);
64
+ }
65
+
66
+ const keys = res.accounts
67
+ .filter(account => !!account.extended_public_key)
68
+ .map(account => ({
69
+ derivation_path: account.derivation_path,
70
+ extended_public_key: account.extended_public_key,
71
+ external_key_count: account.external_key_count,
72
+ internal_key_count: account.internal_key_count,
73
+ is_watch_only: account.watch_only,
74
+ named: account.name,
75
+ }));
76
+
77
+ return cbk(null, {keys});
78
+ });
79
+ }],
80
+ },
81
+ returnResult({reject, resolve, of: 'getKeys'}, cbk));
82
+ });
83
+ };
@@ -8,6 +8,7 @@ const getChainFeeEstimate = require('./get_chain_fee_estimate');
8
8
  const getChainFeeRate = require('./get_chain_fee_rate');
9
9
  const getChainTransactions = require('./get_chain_transactions');
10
10
  const getLockedUtxos = require('./get_locked_utxos');
11
+ const getMasterPublicKeys = require('./get_master_public_keys');
11
12
  const getPendingChainBalance = require('./get_pending_chain_balance');
12
13
  const getSweepTransactions = require('./get_sweep_transactions');
13
14
  const getUtxos = require('./get_utxos');
@@ -41,6 +42,7 @@ module.exports = {
41
42
  getChainFeeRate,
42
43
  getChainTransactions,
43
44
  getLockedUtxos,
45
+ getMasterPublicKeys,
44
46
  getPendingChainBalance,
45
47
  getSweepTransactions,
46
48
  getUtxos,
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "@grpc/grpc-js": "1.5.4",
11
11
  "@grpc/proto-loader": "0.6.9",
12
12
  "@types/express": "4.17.13",
13
- "@types/node": "17.0.15",
13
+ "@types/node": "17.0.16",
14
14
  "@types/request": "2.48.8",
15
15
  "@types/ws": "8.2.2",
16
16
  "async": "3.2.3",
@@ -23,7 +23,7 @@
23
23
  "cbor": "8.1.0",
24
24
  "ecpair": "2.0.1",
25
25
  "express": "4.17.2",
26
- "invoices": "2.0.3",
26
+ "invoices": "2.0.4",
27
27
  "psbt": "2.0.0",
28
28
  "tiny-secp256k1": "2.2.0",
29
29
  "type-fest": "2.11.1"
@@ -34,7 +34,7 @@
34
34
  "@alexbosworth/tap": "15.0.10",
35
35
  "tsd": "0.19.1",
36
36
  "typescript": "4.5.5",
37
- "ws": "8.4.2"
37
+ "ws": "8.5.0"
38
38
  },
39
39
  "engines": {
40
40
  "node": ">=12.20"
@@ -59,5 +59,5 @@
59
59
  "directory": "test/typescript"
60
60
  },
61
61
  "types": "index.d.ts",
62
- "version": "5.6.2"
62
+ "version": "5.6.3"
63
63
  }
@@ -0,0 +1,94 @@
1
+ const {test} = require('@alexbosworth/tap');
2
+
3
+ const {getMasterPublicKeys} = require('./../../../lnd_methods');
4
+
5
+ const makeExpected = overrides => {
6
+ const res = {
7
+ derivation_path: 'derivation_path',
8
+ extended_public_key: 'extended_public_key',
9
+ external_key_count: 0,
10
+ internal_key_count: 1,
11
+ is_watch_only: true,
12
+ named: 'name',
13
+ };
14
+
15
+ Object.keys(overrides).forEach(k => res[k] = overrides[k]);
16
+
17
+ return {keys: [res]};
18
+ };
19
+
20
+ const makeLnd = overrides => {
21
+ return {
22
+ wallet: {
23
+ listAccounts: ({}, cbk) => {
24
+ const account = {
25
+ derivation_path: 'derivation_path',
26
+ extended_public_key: 'extended_public_key',
27
+ external_key_count: 0,
28
+ internal_key_count: 1,
29
+ name: 'name',
30
+ watch_only: true,
31
+ };
32
+
33
+ Object.keys(overrides).forEach(k => account[k] = overrides[k]);
34
+
35
+ return cbk(null, {accounts: [account]});
36
+ },
37
+ },
38
+ };
39
+ };
40
+
41
+ const tests = [
42
+ {
43
+ args: {},
44
+ description: 'LND Object is required to get master public keys',
45
+ error: [400, 'ExpectedAuthenticatedLndToGetMasterPublicKeys'],
46
+ },
47
+ {
48
+ args: {
49
+ lnd: {
50
+ wallet: {
51
+ listAccounts: ({}, cbk) => cbk({
52
+ details: 'unknown walletrpc.WalletKit',
53
+ }),
54
+ },
55
+ },
56
+ },
57
+ description: 'LND unsupported errors are passed back',
58
+ error: [501, 'GetMasterPublicKeysMethodNotSupported'],
59
+ },
60
+ {
61
+ args: {lnd: {wallet: {listAccounts: ({}, cbk) => cbk('err')}}},
62
+ description: 'LND errors are passed back',
63
+ error: [503, 'UnexpectedErrorGettingMasterPublicKeys', {err: 'err'}],
64
+ },
65
+ {
66
+ args: {lnd: {wallet: {listAccounts: ({}, cbk) => cbk()}}},
67
+ description: 'A response is expected',
68
+ error: [503, 'ExpectedResultForMasterPublicKeyListRequest'],
69
+ },
70
+ {
71
+ args: {lnd: {wallet: {listAccounts: ({}, cbk) => cbk(null, {})}}},
72
+ description: 'A response with accounts is expected',
73
+ error: [503, 'ExpectedArrayOfAccountsInMasterPublicKeysList'],
74
+ },
75
+ {
76
+ args: {lnd: makeLnd({})},
77
+ description: 'Get a list of master public keys',
78
+ expected: makeExpected({}),
79
+ },
80
+ ];
81
+
82
+ tests.forEach(({args, description, error, expected}) => {
83
+ return test(description, async ({end, rejects, strictSame}) => {
84
+ if (!!error) {
85
+ await rejects(() => getMasterPublicKeys(args), error, 'Got error');
86
+ } else {
87
+ const {keys} = await getMasterPublicKeys(args);
88
+
89
+ strictSame(keys, expected.keys, 'Got keys');
90
+ }
91
+
92
+ return end();
93
+ });
94
+ });