ln-service 54.9.2 → 54.10.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,10 @@
1
1
  # Versions
2
2
 
3
+ ## 54.10.0
4
+
5
+ - `signChainAddressMessage`: Add method to sign a message given a chain address
6
+ - `verifyChainAddressMessage`: Add method to verify a chain address message
7
+
3
8
  ## 54.9.2
4
9
 
5
10
  - `getChainAddresses`: Add method to get the list of chain addresses
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2017-2021 Alex Bosworth
3
+ Copyright (c) 2017-2023 Alex Bosworth
4
4
  Copyright (c) 2017 BitcoinJS
5
5
 
6
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
package/README.md CHANGED
@@ -220,6 +220,7 @@ for `unlocker` methods.
220
220
  - [setAutopilot](#setautopilot) - Turn autopilot on and set autopilot scores
221
221
  - [settleHodlInvoice](#settlehodlinvoice) - Accept a HODL HTLC invoice
222
222
  - [signBytes](#signbytes) - Sign over arbitrary bytes with node keys
223
+ - [signChainAddressMessage](#signchainaddressmessage) - Sign with chain address
223
224
  - [signMessage](#signmessage) - Sign a message with the node identity key
224
225
  - [signPsbt](#signpsbt) - Sign and finalize an unsigned PSBT using internal keys
225
226
  - [signTransaction](#signtransaction) - Sign an on-chain transaction
@@ -268,6 +269,7 @@ for `unlocker` methods.
268
269
  - [verifyBackup](#verifybackup) - Verify a channel backup
269
270
  - [verifyBackups](#verifybackups) - Verify a set of channel backups
270
271
  - [verifyBytesSignature](#verifybytessignature) - Verify a signature over bytes
272
+ - [verifyChainAddressMessage](#verifychainaddressmessage) - Check chain message
271
273
  - [verifyMessage](#verifymessage) - Verify a message signed by a node identity
272
274
 
273
275
  ## Additional Libraries
@@ -4918,6 +4920,40 @@ const {signature} = await signBytes({
4918
4920
  });
4919
4921
  ```
4920
4922
 
4923
+ ### signChainAddressMessage
4924
+
4925
+ Sign a chain address message using ECDSA
4926
+
4927
+ Note: this method is not supported in LND versions 0.15.5 and below
4928
+
4929
+ Requires LND built with `walletrpc` tag
4930
+
4931
+ `onchain:write` permission is required
4932
+
4933
+ {
4934
+ address: <Chain Address String>
4935
+ lnd: <Authenticated LND API Object>
4936
+ message: <Message To Sign String>
4937
+ }
4938
+
4939
+ @returns via cbk or Promise
4940
+ {
4941
+ signature: <Hex Encoded Signature String>
4942
+ }
4943
+
4944
+ ```node
4945
+ const {createChainAddress} = require('ln-service');
4946
+ const {signChainAddressMessage} = require('ln-service');
4947
+
4948
+ const {address} = await createChainAddress({lnd});
4949
+
4950
+ const {signature} = await signChainAddressMessage({
4951
+ address,
4952
+ lnd,
4953
+ message: 'hello world',
4954
+ });
4955
+ ```
4956
+
4921
4957
  ### signMessage
4922
4958
 
4923
4959
  Sign a message
@@ -7401,6 +7437,45 @@ const validity = await verifyBytesSignature({
7401
7437
  });
7402
7438
  ```
7403
7439
 
7440
+ ### verifyChainAddressMessage
7441
+
7442
+ Verify a chain address message using ECDSA
7443
+
7444
+ Note: this method is not supported in LND versions 0.15.5 and below
7445
+
7446
+ Requires LND built with `walletrpc` tag
7447
+
7448
+ `onchain:write` permission is required
7449
+
7450
+ {
7451
+ address: <Chain Address String>
7452
+ lnd: <Authenticated LND API Object>
7453
+ message: <Message to Verify String>
7454
+ signature: <Hex Encoded Signature String>
7455
+ }
7456
+
7457
+ @returns via cbk or Promise
7458
+ {
7459
+ signed_by: <Public Key Hex String>
7460
+ }
7461
+
7462
+ ```node
7463
+ const {createChainAddress} = require('ln-service');
7464
+ const {signChainAddressMessage} = require('ln-service');
7465
+
7466
+ const {address} = await createChainAddress({lnd});
7467
+
7468
+ const message = 'hello world';
7469
+
7470
+ const {signature} = await signChainAddressMessage({address, lnd, message});
7471
+
7472
+ try {
7473
+ await verifyChainAddressMessage({address, lnd, message, signature});
7474
+ } catch (err) {
7475
+ // Signature failed to vaildate
7476
+ }
7477
+ ```
7478
+
7404
7479
  ### verifyMessage
7405
7480
 
7406
7481
  Verify a message was signed by a known pubkey
package/index.js CHANGED
@@ -108,6 +108,7 @@ const {sendToChainOutputScripts} = require('lightning');
108
108
  const {setAutopilot} = require('lightning');
109
109
  const {settleHodlInvoice} = require('lightning');
110
110
  const {signBytes} = require('lightning');
111
+ const {signChainAddressMessage} = require('lightning');
111
112
  const {signMessage} = require('lightning');
112
113
  const {signPsbt} = require('lightning');
113
114
  const {signTransaction} = require('lightning');
@@ -149,6 +150,7 @@ const {verifyAccess} = require('lightning');
149
150
  const {verifyBackup} = require('lightning');
150
151
  const {verifyBackups} = require('lightning');
151
152
  const {verifyBytesSignature} = require('lightning');
153
+ const {verifyChainAddressMessage} = require('lightning');
152
154
  const {verifyMessage} = require('lightning');
153
155
 
154
156
  module.exports = {
@@ -262,6 +264,7 @@ module.exports = {
262
264
  setAutopilot,
263
265
  settleHodlInvoice,
264
266
  signBytes,
267
+ signChainAddressMessage,
265
268
  signMessage,
266
269
  signPsbt,
267
270
  signTransaction,
@@ -303,5 +306,6 @@ module.exports = {
303
306
  verifyBackup,
304
307
  verifyBackups,
305
308
  verifyBytesSignature,
309
+ verifyChainAddressMessage,
306
310
  verifyMessage,
307
311
  };
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "cors": "2.8.5",
12
12
  "express": "4.18.2",
13
13
  "invoices": "2.2.3",
14
- "lightning": "7.0.8",
14
+ "lightning": "7.1.0",
15
15
  "macaroon": "3.0.4",
16
16
  "morgan": "1.10.0",
17
17
  "ws": "8.12.1"
@@ -64,5 +64,5 @@
64
64
  "integration-test-0.14.4": "DOCKER_LND_VERSION=v0.14.4-beta npm run test",
65
65
  "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/peersrpc-integration/*.js test/routerrpc-integration/*.js test/signerrpc-integration/*.js test/tower_clientrpc-integration/*.js test/tower_serverrpc-integration/*.js test/walletrpc-integration/*.js"
66
66
  },
67
- "version": "54.9.2"
67
+ "version": "54.10.0"
68
68
  }
@@ -164,6 +164,17 @@ test(`Open unconfirmed channels`, async ({end, equal, match, strictSame}) => {
164
164
 
165
165
  match(otherId, /16000000x0/, 'Got ephemeral id');
166
166
 
167
+ // Make sure the channel is really active
168
+ await asyncRetry({interval, times}, async () => {
169
+ const {channels} = await getChannels({lnd});
170
+
171
+ const [channel] = channels;
172
+
173
+ if (!channel.time_online) {
174
+ throw new Error('ExpectedChannelOnline');
175
+ }
176
+ });
177
+
167
178
  await asyncRetry({interval, times}, async () => {
168
179
  await closeChannel({lnd, id: confirmed.id});
169
180
  });
@@ -0,0 +1,32 @@
1
+ const {spawnLightningCluster} = require('ln-docker-daemons');
2
+ const {test} = require('@alexbosworth/tap');
3
+
4
+ const {createChainAddress} = require('./../../');
5
+ const {signChainAddressMessage} = require('./../../');
6
+
7
+ const message = 'message';
8
+
9
+ // Signing a chain address message should result in a signature
10
+ test(`Sign chain address message`, async ({end, equal}) => {
11
+ const {kill, nodes} = await spawnLightningCluster({});
12
+
13
+ const [control] = nodes;
14
+
15
+ const {lnd} = control;
16
+
17
+ const {address} = await createChainAddress({lnd});
18
+
19
+ try {
20
+ const {signature} = await signChainAddressMessage({address, lnd, message});
21
+
22
+ equal(!!signature, true, 'Got a signature for a chain address');
23
+ } catch (err) {
24
+ const [code, message] = err;
25
+
26
+ equal(message, 'BackingLndDoesNotSupportSigningChainMessages', 'missing');
27
+ }
28
+
29
+ await kill({});
30
+
31
+ return end();
32
+ });
@@ -0,0 +1,58 @@
1
+ const {spawnLightningCluster} = require('ln-docker-daemons');
2
+ const {test} = require('@alexbosworth/tap');
3
+
4
+ const {createChainAddress} = require('./../../');
5
+ const {signChainAddressMessage} = require('./../../');
6
+ const {verifyChainAddressMessage} = require('./../../');
7
+
8
+ const message = 'message';
9
+
10
+ // Verifying a chain address message signature should result in verification
11
+ test(`Verify chain address message`, async ({end, equal}) => {
12
+ const {kill, nodes} = await spawnLightningCluster({});
13
+
14
+ const [control] = nodes;
15
+
16
+ const {lnd} = control;
17
+
18
+ const {address} = await createChainAddress({lnd});
19
+
20
+ try {
21
+ const {signature} = await signChainAddressMessage({address, lnd, message});
22
+
23
+ const verify = await verifyChainAddressMessage({
24
+ address,
25
+ lnd,
26
+ message,
27
+ signature,
28
+ });
29
+
30
+ equal(verify.signed_by.length, 66, 'Got public key');
31
+ } catch (err) {
32
+ const [code, message] = err;
33
+
34
+ equal(message, 'BackingLndDoesNotSupportSigningChainMessages', 'missing');
35
+
36
+ await kill({});
37
+
38
+ return end();
39
+ }
40
+
41
+ try {
42
+ const verify = await verifyChainAddressMessage({
43
+ address,
44
+ lnd,
45
+ message,
46
+ signature: '1f54fe4a1332633d3c625cf8de41004f3ce3978f7e6e9845dea944e46fab878ec5676e08d44b505ede70fa2e693192405e16baf3e18de44987db6d9e82d4f14907',
47
+ });
48
+ } catch (err) {
49
+ const [code, message] = err;
50
+
51
+ equal(code, 400, 'Invalid signature code');
52
+ equal(message, 'InvalidSignatureReceivedForChainAddress', 'invalid sig');
53
+ }
54
+
55
+ await kill({});
56
+
57
+ return end();
58
+ });