lightning 7.0.7 → 7.1.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 +6 -1
- package/LICENSE +1 -1
- package/README.md +4 -0
- package/grpc/protos/router.proto +92 -14
- package/index.js +4 -0
- package/lnd_methods/index.js +4 -0
- package/lnd_methods/macaroon/methods.json +8 -0
- package/lnd_methods/onchain/index.js +4 -0
- package/lnd_methods/onchain/sign_chain_address_message.js +80 -0
- package/lnd_methods/onchain/verify_chain_address_message.js +93 -0
- package/package.json +3 -3
- package/test/lnd_methods/onchain/test_sign_chain_address_message.js +86 -0
- package/test/lnd_methods/onchain/test_verify_chain_address_message.js +110 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
# Versions
|
|
2
2
|
|
|
3
|
-
## 7.0
|
|
3
|
+
## 7.1.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
|
+
|
|
8
|
+
## 7.0.8
|
|
4
9
|
|
|
5
10
|
- `getChainAddresses`: Add method to get the list of chain addresses
|
|
6
11
|
|
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -281,6 +281,8 @@ variables set:
|
|
|
281
281
|
off-chain funds when an invoice has held funds from an incoming payment.
|
|
282
282
|
- [signBytes](https://github.com/alexbosworth/ln-service#signbytes): Use node keys to sign over an
|
|
283
283
|
arbitrary set of bytes.
|
|
284
|
+
- [signChainAddressMessage](https://github.com/alexbosworth/ln-service#signchainaddressmessage):
|
|
285
|
+
Sign a message using the public key behind a chain address with ECDSA
|
|
284
286
|
- [signMessage](https://github.com/alexbosworth/ln-service#signmessage): Use the node identity
|
|
285
287
|
key to generate a signed message that represents the public graph node identity.
|
|
286
288
|
- [signPsbt](https://github.com/alexbosworth/ln-service#signpsbt): Sign inputs and finalize a
|
|
@@ -363,5 +365,7 @@ variables set:
|
|
|
363
365
|
channel fund recovery backups are valid.
|
|
364
366
|
- [verifyBytesSignature](https://github.com/alexbosworth/ln-service#verifybytessignature): Check
|
|
365
367
|
that a signature over arbitrary bytes is valid.
|
|
368
|
+
- [verifyChainAddressMessage](https://github.com/alexbosworth/ln-service#verifychainaddressmessage):
|
|
369
|
+
Verify that a chain address message has a valid ECDSA signature
|
|
366
370
|
- [verifyMessage](https://github.com/alexbosworth/ln-service#verifymessage): Check that a
|
|
367
371
|
message from a node in the graph has a valid signature.
|
package/grpc/protos/router.proto
CHANGED
|
@@ -95,7 +95,9 @@ service Router {
|
|
|
95
95
|
|
|
96
96
|
/*
|
|
97
97
|
Deprecated. QueryProbability returns the current success probability
|
|
98
|
-
estimate for a given node pair and amount.
|
|
98
|
+
estimate for a given node pair and amount. The call returns a zero success
|
|
99
|
+
probability if no channel is available or if the amount violates min/max
|
|
100
|
+
HTLC constraints.
|
|
99
101
|
*/
|
|
100
102
|
rpc QueryProbability (QueryProbabilityRequest)
|
|
101
103
|
returns (QueryProbabilityResponse);
|
|
@@ -465,6 +467,93 @@ message SetMissionControlConfigResponse {
|
|
|
465
467
|
}
|
|
466
468
|
|
|
467
469
|
message MissionControlConfig {
|
|
470
|
+
/*
|
|
471
|
+
Deprecated, use AprioriParameters. The amount of time mission control will
|
|
472
|
+
take to restore a penalized node or channel back to 50% success probability,
|
|
473
|
+
expressed in seconds. Setting this value to a higher value will penalize
|
|
474
|
+
failures for longer, making mission control less likely to route through
|
|
475
|
+
nodes and channels that we have previously recorded failures for.
|
|
476
|
+
*/
|
|
477
|
+
uint64 half_life_seconds = 1 [deprecated = true];
|
|
478
|
+
|
|
479
|
+
/*
|
|
480
|
+
Deprecated, use AprioriParameters. The probability of success mission
|
|
481
|
+
control should assign to hop in a route where it has no other information
|
|
482
|
+
available. Higher values will make mission control more willing to try hops
|
|
483
|
+
that we have no information about, lower values will discourage trying these
|
|
484
|
+
hops.
|
|
485
|
+
*/
|
|
486
|
+
float hop_probability = 2 [deprecated = true];
|
|
487
|
+
|
|
488
|
+
/*
|
|
489
|
+
Deprecated, use AprioriParameters. The importance that mission control
|
|
490
|
+
should place on historical results, expressed as a value in [0;1]. Setting
|
|
491
|
+
this value to 1 will ignore all historical payments and just use the hop
|
|
492
|
+
probability to assess the probability of success for each hop. A zero value
|
|
493
|
+
ignores hop probability completely and relies entirely on historical
|
|
494
|
+
results, unless none are available.
|
|
495
|
+
*/
|
|
496
|
+
float weight = 3 [deprecated = true];
|
|
497
|
+
|
|
498
|
+
/*
|
|
499
|
+
The maximum number of payment results that mission control will store.
|
|
500
|
+
*/
|
|
501
|
+
uint32 maximum_payment_results = 4;
|
|
502
|
+
|
|
503
|
+
/*
|
|
504
|
+
The minimum time that must have passed since the previously recorded failure
|
|
505
|
+
before we raise the failure amount.
|
|
506
|
+
*/
|
|
507
|
+
uint64 minimum_failure_relax_interval = 5;
|
|
508
|
+
|
|
509
|
+
enum ProbabilityModel {
|
|
510
|
+
APRIORI = 0;
|
|
511
|
+
BIMODAL = 1;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/*
|
|
515
|
+
ProbabilityModel defines which probability estimator should be used in
|
|
516
|
+
pathfinding.
|
|
517
|
+
*/
|
|
518
|
+
ProbabilityModel Model = 6;
|
|
519
|
+
|
|
520
|
+
/*
|
|
521
|
+
EstimatorConfig is populated dependent on the estimator type.
|
|
522
|
+
*/
|
|
523
|
+
oneof EstimatorConfig {
|
|
524
|
+
AprioriParameters apriori = 7;
|
|
525
|
+
BimodalParameters bimodal = 8;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
message BimodalParameters {
|
|
530
|
+
/*
|
|
531
|
+
NodeWeight defines how strongly other previous forwardings on channels of a
|
|
532
|
+
router should be taken into account when computing a channel's probability
|
|
533
|
+
to route. The allowed values are in the range [0, 1], where a value of 0
|
|
534
|
+
means that only direct information about a channel is taken into account.
|
|
535
|
+
*/
|
|
536
|
+
double node_weight = 1;
|
|
537
|
+
|
|
538
|
+
/*
|
|
539
|
+
ScaleMsat describes the scale over which channels statistically have some
|
|
540
|
+
liquidity left. The value determines how quickly the bimodal distribution
|
|
541
|
+
drops off from the edges of a channel. A larger value (compared to typical
|
|
542
|
+
channel capacities) means that the drop off is slow and that channel
|
|
543
|
+
balances are distributed more uniformly. A small value leads to the
|
|
544
|
+
assumption of very unbalanced channels.
|
|
545
|
+
*/
|
|
546
|
+
uint64 scale_msat = 2;
|
|
547
|
+
|
|
548
|
+
/*
|
|
549
|
+
DecayTime describes the information decay of knowledge about previous
|
|
550
|
+
successes and failures in channels. The smaller the decay time, the quicker
|
|
551
|
+
we forget about past forwardings.
|
|
552
|
+
*/
|
|
553
|
+
uint64 decay_time = 3;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
message AprioriParameters {
|
|
468
557
|
/*
|
|
469
558
|
The amount of time mission control will take to restore a penalized node
|
|
470
559
|
or channel back to 50% success probability, expressed in seconds. Setting
|
|
@@ -480,7 +569,7 @@ message MissionControlConfig {
|
|
|
480
569
|
control more willing to try hops that we have no information about, lower
|
|
481
570
|
values will discourage trying these hops.
|
|
482
571
|
*/
|
|
483
|
-
|
|
572
|
+
double hop_probability = 2;
|
|
484
573
|
|
|
485
574
|
/*
|
|
486
575
|
The importance that mission control should place on historical results,
|
|
@@ -490,18 +579,7 @@ message MissionControlConfig {
|
|
|
490
579
|
completely and relies entirely on historical results, unless none are
|
|
491
580
|
available.
|
|
492
581
|
*/
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
/*
|
|
496
|
-
The maximum number of payment results that mission control will store.
|
|
497
|
-
*/
|
|
498
|
-
uint32 maximum_payment_results = 4;
|
|
499
|
-
|
|
500
|
-
/*
|
|
501
|
-
The minimum time that must have passed since the previously recorded failure
|
|
502
|
-
before we raise the failure amount.
|
|
503
|
-
*/
|
|
504
|
-
uint64 minimum_failure_relax_interval = 5;
|
|
582
|
+
double weight = 3;
|
|
505
583
|
}
|
|
506
584
|
|
|
507
585
|
message QueryProbabilityRequest {
|
package/index.js
CHANGED
|
@@ -106,6 +106,7 @@ const {sendToChainOutputScripts} = require('./lnd_methods');
|
|
|
106
106
|
const {setAutopilot} = require('./lnd_methods');
|
|
107
107
|
const {settleHodlInvoice} = require('./lnd_methods');
|
|
108
108
|
const {signBytes} = require('./lnd_methods');
|
|
109
|
+
const {signChainAddressMessage} = require('./lnd_methods');
|
|
109
110
|
const {signMessage} = require('./lnd_methods');
|
|
110
111
|
const {signPsbt} = require('./lnd_methods');
|
|
111
112
|
const {signTransaction} = require('./lnd_methods');
|
|
@@ -147,6 +148,7 @@ const {verifyAccess} = require('./lnd_methods');
|
|
|
147
148
|
const {verifyBackup} = require('./lnd_methods');
|
|
148
149
|
const {verifyBackups} = require('./lnd_methods');
|
|
149
150
|
const {verifyBytesSignature} = require('./lnd_methods');
|
|
151
|
+
const {verifyChainAddressMessage} = require('./lnd_methods');
|
|
150
152
|
const {verifyMessage} = require('./lnd_methods');
|
|
151
153
|
|
|
152
154
|
module.exports = {
|
|
@@ -258,6 +260,7 @@ module.exports = {
|
|
|
258
260
|
setAutopilot,
|
|
259
261
|
settleHodlInvoice,
|
|
260
262
|
signBytes,
|
|
263
|
+
signChainAddressMessage,
|
|
261
264
|
signMessage,
|
|
262
265
|
signPsbt,
|
|
263
266
|
signTransaction,
|
|
@@ -299,5 +302,6 @@ module.exports = {
|
|
|
299
302
|
verifyBackup,
|
|
300
303
|
verifyBackups,
|
|
301
304
|
verifyBytesSignature,
|
|
305
|
+
verifyChainAddressMessage,
|
|
302
306
|
verifyMessage,
|
|
303
307
|
};
|
package/lnd_methods/index.js
CHANGED
|
@@ -103,6 +103,7 @@ const {sendToChainOutputScripts} = require('./onchain');
|
|
|
103
103
|
const {setAutopilot} = require('./onchain');
|
|
104
104
|
const {settleHodlInvoice} = require('./invoices');
|
|
105
105
|
const {signBytes} = require('./signer');
|
|
106
|
+
const {signChainAddressMessage} = require('./onchain');
|
|
106
107
|
const {signMessage} = require('./message');
|
|
107
108
|
const {signPsbt} = require('./onchain');
|
|
108
109
|
const {signTransaction} = require('./signer');
|
|
@@ -143,6 +144,7 @@ const {verifyAccess} = require('./macaroon');
|
|
|
143
144
|
const {verifyBackup} = require('./offchain');
|
|
144
145
|
const {verifyBackups} = require('./offchain');
|
|
145
146
|
const {verifyBytesSignature} = require('./signer');
|
|
147
|
+
const {verifyChainAddressMessage} = require('./onchain');
|
|
146
148
|
const {verifyMessage} = require('./message');
|
|
147
149
|
|
|
148
150
|
module.exports = {
|
|
@@ -251,6 +253,7 @@ module.exports = {
|
|
|
251
253
|
setAutopilot,
|
|
252
254
|
settleHodlInvoice,
|
|
253
255
|
signBytes,
|
|
256
|
+
signChainAddressMessage,
|
|
254
257
|
signMessage,
|
|
255
258
|
signPsbt,
|
|
256
259
|
signTransaction,
|
|
@@ -291,5 +294,6 @@ module.exports = {
|
|
|
291
294
|
verifyBackup,
|
|
292
295
|
verifyBackups,
|
|
293
296
|
verifyBytesSignature,
|
|
297
|
+
verifyChainAddressMessage,
|
|
294
298
|
verifyMessage,
|
|
295
299
|
};
|
|
@@ -413,6 +413,10 @@
|
|
|
413
413
|
"method": "SignMessage",
|
|
414
414
|
"type": "signer"
|
|
415
415
|
},
|
|
416
|
+
"signChainAddressMessage": {
|
|
417
|
+
"method": "SignMessageWithAddr",
|
|
418
|
+
"type": "wallet"
|
|
419
|
+
},
|
|
416
420
|
"signMessage": {
|
|
417
421
|
"method": "SignMessage",
|
|
418
422
|
"type": "default"
|
|
@@ -572,6 +576,10 @@
|
|
|
572
576
|
"method": "VerifyMessage",
|
|
573
577
|
"type": "signer"
|
|
574
578
|
},
|
|
579
|
+
"verifyChainAddressMessage": {
|
|
580
|
+
"method": "VerifyMessageWithAddr",
|
|
581
|
+
"type": "wallet"
|
|
582
|
+
},
|
|
575
583
|
"verifyMessage": {
|
|
576
584
|
"method": "VerifyMessage",
|
|
577
585
|
"type": "default"
|
|
@@ -25,6 +25,7 @@ const sendToChainAddress = require('./send_to_chain_address');
|
|
|
25
25
|
const sendToChainAddresses = require('./send_to_chain_addresses');
|
|
26
26
|
const sendToChainOutputScripts = require('./send_to_chain_output_scripts');
|
|
27
27
|
const setAutopilot = require('./set_autopilot');
|
|
28
|
+
const signChainAddressMessage = require('./sign_chain_address_message');
|
|
28
29
|
const signPsbt = require('./sign_psbt');
|
|
29
30
|
const subscribeToBlocks = require('./subscribe_to_blocks');
|
|
30
31
|
const subscribeToChainAddress = require('./subscribe_to_chain_address');
|
|
@@ -32,6 +33,7 @@ const subscribeToChainSpend = require('./subscribe_to_chain_spend');
|
|
|
32
33
|
const subscribeToTransactions = require('./subscribe_to_transactions');
|
|
33
34
|
const unlockUtxo = require('./unlock_utxo');
|
|
34
35
|
const updateChainTransaction = require('./update_chain_transaction');
|
|
36
|
+
const verifyChainAddressMessage = require('./verify_chain_address_message');
|
|
35
37
|
|
|
36
38
|
module.exports = {
|
|
37
39
|
broadcastChainTransaction,
|
|
@@ -61,6 +63,7 @@ module.exports = {
|
|
|
61
63
|
sendToChainAddresses,
|
|
62
64
|
sendToChainOutputScripts,
|
|
63
65
|
setAutopilot,
|
|
66
|
+
signChainAddressMessage,
|
|
64
67
|
signPsbt,
|
|
65
68
|
subscribeToBlocks,
|
|
66
69
|
subscribeToChainAddress,
|
|
@@ -68,4 +71,5 @@ module.exports = {
|
|
|
68
71
|
subscribeToTransactions,
|
|
69
72
|
unlockUtxo,
|
|
70
73
|
updateChainTransaction,
|
|
74
|
+
verifyChainAddressMessage,
|
|
71
75
|
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
const asyncAuto = require('async/auto');
|
|
2
|
+
const {returnResult} = require('asyncjs-util');
|
|
3
|
+
|
|
4
|
+
const {isLnd} = require('./../../lnd_requests');
|
|
5
|
+
|
|
6
|
+
const base64AsHex = base64 => Buffer.from(base64, 'base64').toString('hex');
|
|
7
|
+
const notSupportedError = 'unknown method SignMessageWithAddr for service walletrpc.WalletKit';
|
|
8
|
+
const method = 'signMessageWithAddr';
|
|
9
|
+
const utf8AsBuffer = utf8 => Buffer.from(utf8, 'utf8');
|
|
10
|
+
const type = 'wallet';
|
|
11
|
+
|
|
12
|
+
/** Sign a chain address message using ECDSA
|
|
13
|
+
|
|
14
|
+
Note: this method is not supported in LND versions 0.15.5 and below
|
|
15
|
+
|
|
16
|
+
Requires LND built with `walletrpc` tag
|
|
17
|
+
|
|
18
|
+
`onchain:write` permission is required
|
|
19
|
+
|
|
20
|
+
{
|
|
21
|
+
address: <Chain Address String>
|
|
22
|
+
lnd: <Authenticated LND API Object>
|
|
23
|
+
message: <Message To Sign String>
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@returns via cbk or Promise
|
|
27
|
+
{
|
|
28
|
+
signature: <Hex Encoded Signature String>
|
|
29
|
+
}
|
|
30
|
+
*/
|
|
31
|
+
module.exports = ({address, lnd, message}, cbk) => {
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
return asyncAuto({
|
|
34
|
+
// Check arguments
|
|
35
|
+
validate: cbk => {
|
|
36
|
+
if (!address) {
|
|
37
|
+
return cbk([400, 'ExpectedChainAddressToSignChainAddressMessage']);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!isLnd({lnd, method, type})) {
|
|
41
|
+
return cbk([400, 'ExpectedLndToSignChainAddressMessage']);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!message) {
|
|
45
|
+
return cbk([400, 'ExpectedMessageToSignChainAddressMessage']);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return cbk();
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
// Sign message
|
|
52
|
+
sign: ['validate', ({}, cbk) => {
|
|
53
|
+
return lnd[type][method]({
|
|
54
|
+
addr: address,
|
|
55
|
+
msg: utf8AsBuffer(message),
|
|
56
|
+
},
|
|
57
|
+
(err, res) => {
|
|
58
|
+
if (!!err && err.details === notSupportedError) {
|
|
59
|
+
return cbk([501, 'BackingLndDoesNotSupportSigningChainMessages']);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (!!err) {
|
|
63
|
+
return cbk([503, 'UnexpectedSignChainAddressMessageError', {err}]);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (!res) {
|
|
67
|
+
return cbk([503, 'ExpectedResponseToSignChainAddrMessageRequest']);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (!res.signature) {
|
|
71
|
+
return cbk([503, 'ExpectedSignatureForChainMessageSignRequest']);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return cbk(null, {signature: base64AsHex(res.signature)});
|
|
75
|
+
});
|
|
76
|
+
}],
|
|
77
|
+
},
|
|
78
|
+
returnResult({reject, resolve, of: 'sign'}, cbk));
|
|
79
|
+
});
|
|
80
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
const asyncAuto = require('async/auto');
|
|
2
|
+
const {returnResult} = require('asyncjs-util');
|
|
3
|
+
|
|
4
|
+
const {isLnd} = require('./../../lnd_requests');
|
|
5
|
+
|
|
6
|
+
const bufferAsHex = buffer => buffer.toString('hex');
|
|
7
|
+
const hexAsBase64 = hex => Buffer.from(hex, 'hex').toString('base64');
|
|
8
|
+
const {isBuffer} = Buffer;
|
|
9
|
+
const isHex = n => !!n && !(n.length % 2) && /^[0-9A-F]*$/i.test(n);
|
|
10
|
+
const method = 'verifyMessageWithAddr';
|
|
11
|
+
const notSupportedError = 'unknown method VerifyMessageWithAddr for service walletrpc.WalletKit';
|
|
12
|
+
const utf8StringAsBuffer = str => Buffer.from(str, 'utf8');
|
|
13
|
+
const type = 'wallet';
|
|
14
|
+
|
|
15
|
+
/** Verify a chain address message using ECDSA
|
|
16
|
+
|
|
17
|
+
Note: this method is not supported in LND versions 0.15.5 and below
|
|
18
|
+
|
|
19
|
+
Requires LND built with `walletrpc` tag
|
|
20
|
+
|
|
21
|
+
`onchain:write` permission is required
|
|
22
|
+
|
|
23
|
+
{
|
|
24
|
+
address: <Chain Address String>
|
|
25
|
+
lnd: <Authenticated LND API Object>
|
|
26
|
+
message: <Message to Verify String>
|
|
27
|
+
signature: <Hex Encoded Signature String>
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@returns via cbk or Promise
|
|
31
|
+
{
|
|
32
|
+
signed_by: <Public Key Hex String>
|
|
33
|
+
}
|
|
34
|
+
*/
|
|
35
|
+
module.exports = ({address, lnd, message, signature}, cbk) => {
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
return asyncAuto({
|
|
38
|
+
// Check arguments
|
|
39
|
+
validate: cbk => {
|
|
40
|
+
if (!address) {
|
|
41
|
+
return cbk([400, 'ExpectedChainAddressToVerifyChainAddressMessage']);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!isLnd({lnd, method, type})) {
|
|
45
|
+
return cbk([400, 'ExpectedLndToVerifyChainAddressMessage']);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (!message) {
|
|
49
|
+
return cbk([400, 'ExpectedChainAddressMessageToVerify']);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (!isHex(signature)) {
|
|
53
|
+
return cbk([400, 'ExpectedHexSignatureToVerifyChainAddressMessage']);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return cbk();
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
// Check chain address message signature
|
|
60
|
+
verify: ['validate', ({}, cbk) => {
|
|
61
|
+
return lnd[type][method]({
|
|
62
|
+
addr: address,
|
|
63
|
+
msg: utf8StringAsBuffer(message),
|
|
64
|
+
signature: hexAsBase64(signature),
|
|
65
|
+
},
|
|
66
|
+
(err, res) => {
|
|
67
|
+
if (!!err && err.details === notSupportedError) {
|
|
68
|
+
return cbk([501, 'BackingLndDoesNotSupportVerifyingAddrMessages']);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (!!err) {
|
|
72
|
+
return cbk([503, 'UnexpectedVerifyChainAddrMessageError', {err}]);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!res) {
|
|
76
|
+
return cbk([503, 'ExpectedResultForVerifyChainMessageRequest']);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (res.valid !== true) {
|
|
80
|
+
return cbk([400, 'InvalidSignatureReceivedForChainAddress']);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (!isBuffer(res.pubkey)) {
|
|
84
|
+
return cbk([503, 'ExpectedPublicKeyInVerifyChainMessageResponse']);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return cbk(null, {signed_by: bufferAsHex(res.pubkey)});
|
|
88
|
+
});
|
|
89
|
+
}],
|
|
90
|
+
},
|
|
91
|
+
returnResult({reject, resolve, of: 'verify'}, cbk));
|
|
92
|
+
});
|
|
93
|
+
};
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"url": "https://github.com/alexbosworth/lightning/issues"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@grpc/grpc-js": "1.8.
|
|
10
|
+
"@grpc/grpc-js": "1.8.9",
|
|
11
11
|
"@grpc/proto-loader": "0.7.5",
|
|
12
12
|
"@types/express": "4.17.17",
|
|
13
13
|
"@types/node": "18.13.0",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"invoices": "2.2.3",
|
|
27
27
|
"psbt": "2.7.2",
|
|
28
28
|
"tiny-secp256k1": "2.2.1",
|
|
29
|
-
"type-fest": "3.
|
|
29
|
+
"type-fest": "3.6.0"
|
|
30
30
|
},
|
|
31
31
|
"description": "Lightning Network client library",
|
|
32
32
|
"devDependencies": {
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"directory": "test/typescript"
|
|
60
60
|
},
|
|
61
61
|
"types": "index.d.ts",
|
|
62
|
-
"version": "7.0
|
|
62
|
+
"version": "7.1.0"
|
|
63
63
|
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
const {test} = require('@alexbosworth/tap');
|
|
2
|
+
|
|
3
|
+
const {signChainAddressMessage} = require('./../../../');
|
|
4
|
+
|
|
5
|
+
const makeArgs = override => {
|
|
6
|
+
const args = {
|
|
7
|
+
address: 'address',
|
|
8
|
+
lnd: {
|
|
9
|
+
wallet: {
|
|
10
|
+
signMessageWithAddr: ({}, cbk) => cbk(null, {signature: '12345'}),
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
message: 'message',
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
Object.keys(override).forEach(attr => args[attr] = override[attr]);
|
|
17
|
+
|
|
18
|
+
return args;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const tests = [
|
|
22
|
+
{
|
|
23
|
+
args: makeArgs({address: undefined}),
|
|
24
|
+
description: 'A chain address is required to sign a message',
|
|
25
|
+
error: [400, 'ExpectedChainAddressToSignChainAddressMessage'],
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
args: makeArgs({lnd: undefined}),
|
|
29
|
+
description: 'LND is required to sign a message',
|
|
30
|
+
error: [400, 'ExpectedLndToSignChainAddressMessage'],
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
args: makeArgs({message: undefined}),
|
|
34
|
+
description: 'A message is required to sign a message',
|
|
35
|
+
error: [400, 'ExpectedMessageToSignChainAddressMessage'],
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
args: makeArgs({
|
|
39
|
+
lnd: {
|
|
40
|
+
wallet: {
|
|
41
|
+
signMessageWithAddr: ({}, cbk) => cbk({
|
|
42
|
+
details: 'unknown method SignMessageWithAddr for service walletrpc.WalletKit',
|
|
43
|
+
}),
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
}),
|
|
47
|
+
description: 'Unsupported error is returned',
|
|
48
|
+
error: [501, 'BackingLndDoesNotSupportSigningChainMessages'],
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
args: makeArgs({
|
|
52
|
+
lnd: {wallet: {signMessageWithAddr: ({}, cbk) => cbk('err')}},
|
|
53
|
+
}),
|
|
54
|
+
description: 'Unexpected error is returned',
|
|
55
|
+
error: [503, 'UnexpectedSignChainAddressMessageError', {err: 'err'}],
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
args: makeArgs({lnd: {wallet: {signMessageWithAddr: ({}, cbk) => cbk()}}}),
|
|
59
|
+
description: 'A response is expected',
|
|
60
|
+
error: [503, 'ExpectedResponseToSignChainAddrMessageRequest'],
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
args: makeArgs({
|
|
64
|
+
lnd: {wallet: {signMessageWithAddr: ({}, cbk) => cbk(null, {})}},
|
|
65
|
+
}),
|
|
66
|
+
description: 'A signature is expected',
|
|
67
|
+
error: [503, 'ExpectedSignatureForChainMessageSignRequest'],
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
args: makeArgs({}),
|
|
71
|
+
description: 'Signature produced',
|
|
72
|
+
expected: {signature: 'd76df8'},
|
|
73
|
+
},
|
|
74
|
+
];
|
|
75
|
+
|
|
76
|
+
tests.forEach(({args, description, error, expected}) => {
|
|
77
|
+
return test(description, async ({end, rejects, strictSame}) => {
|
|
78
|
+
if (!!error) {
|
|
79
|
+
await rejects(() => signChainAddressMessage(args), error, 'Got error');
|
|
80
|
+
} else {
|
|
81
|
+
strictSame(await signChainAddressMessage(args), expected, 'Got result');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return end();
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
const {test} = require('@alexbosworth/tap');
|
|
2
|
+
|
|
3
|
+
const {verifyChainAddressMessage} = require('./../../../');
|
|
4
|
+
|
|
5
|
+
const makeArgs = override => {
|
|
6
|
+
const args = {
|
|
7
|
+
address: 'address',
|
|
8
|
+
lnd: {
|
|
9
|
+
wallet: {
|
|
10
|
+
verifyMessageWithAddr: ({}, cbk) => cbk(null, {
|
|
11
|
+
pubkey: Buffer.alloc(1),
|
|
12
|
+
valid: true,
|
|
13
|
+
}),
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
message: 'message',
|
|
17
|
+
signature: '00',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
Object.keys(override).forEach(attr => args[attr] = override[attr]);
|
|
21
|
+
|
|
22
|
+
return args;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const tests = [
|
|
26
|
+
{
|
|
27
|
+
args: makeArgs({address: undefined}),
|
|
28
|
+
description: 'A chain address is required to verify a message',
|
|
29
|
+
error: [400, 'ExpectedChainAddressToVerifyChainAddressMessage'],
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
args: makeArgs({lnd: undefined}),
|
|
33
|
+
description: 'LND is required to verify a message',
|
|
34
|
+
error: [400, 'ExpectedLndToVerifyChainAddressMessage'],
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
args: makeArgs({message: undefined}),
|
|
38
|
+
description: 'A message is required to verify a message',
|
|
39
|
+
error: [400, 'ExpectedChainAddressMessageToVerify'],
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
args: makeArgs({signature: undefined}),
|
|
43
|
+
description: 'A signature required to verify a message',
|
|
44
|
+
error: [400, 'ExpectedHexSignatureToVerifyChainAddressMessage'],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
args: makeArgs({
|
|
48
|
+
lnd: {
|
|
49
|
+
wallet: {
|
|
50
|
+
verifyMessageWithAddr: ({}, cbk) => cbk({
|
|
51
|
+
details: 'unknown method VerifyMessageWithAddr for service walletrpc.WalletKit',
|
|
52
|
+
}),
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
}),
|
|
56
|
+
description: 'Unsupported error is returned',
|
|
57
|
+
error: [501, 'BackingLndDoesNotSupportVerifyingAddrMessages'],
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
args: makeArgs({
|
|
61
|
+
lnd: {wallet: {verifyMessageWithAddr: ({}, cbk) => cbk('err')}},
|
|
62
|
+
}),
|
|
63
|
+
description: 'Unsupported error is returned',
|
|
64
|
+
error: [503, 'UnexpectedVerifyChainAddrMessageError', {err: 'err'}],
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
args: makeArgs({
|
|
68
|
+
lnd: {wallet: {verifyMessageWithAddr: ({}, cbk) => cbk()}},
|
|
69
|
+
}),
|
|
70
|
+
description: 'A response is expected',
|
|
71
|
+
error: [503, 'ExpectedResultForVerifyChainMessageRequest'],
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
args: makeArgs({
|
|
75
|
+
lnd: {
|
|
76
|
+
wallet: {
|
|
77
|
+
verifyMessageWithAddr: ({}, cbk) => cbk(null, {valid: false}),
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
}),
|
|
81
|
+
description: 'A valid result is expected',
|
|
82
|
+
error: [400, 'InvalidSignatureReceivedForChainAddress'],
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
args: makeArgs({
|
|
86
|
+
lnd: {
|
|
87
|
+
wallet: {verifyMessageWithAddr: ({}, cbk) => cbk(null, {valid: true})},
|
|
88
|
+
},
|
|
89
|
+
}),
|
|
90
|
+
description: 'A public key result is expected',
|
|
91
|
+
error: [503, 'ExpectedPublicKeyInVerifyChainMessageResponse'],
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
args: makeArgs({}),
|
|
95
|
+
description: 'Signature validated',
|
|
96
|
+
expected: {signed_by: '00'},
|
|
97
|
+
},
|
|
98
|
+
];
|
|
99
|
+
|
|
100
|
+
tests.forEach(({args, description, error, expected}) => {
|
|
101
|
+
return test(description, async ({end, rejects, strictSame}) => {
|
|
102
|
+
if (!!error) {
|
|
103
|
+
await rejects(() => verifyChainAddressMessage(args), error, 'Got error');
|
|
104
|
+
} else {
|
|
105
|
+
strictSame(await verifyChainAddressMessage(args), expected, 'Got res');
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return end();
|
|
109
|
+
});
|
|
110
|
+
});
|