lightning 7.0.8 → 7.1.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.
- package/.github/workflows/unit-test.yml +1 -1
- package/CHANGELOG.md +5 -0
- package/LICENSE +1 -1
- package/README.md +4 -0
- 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.d.ts +2 -0
- package/lnd_methods/onchain/index.js +4 -0
- package/lnd_methods/onchain/sign_chain_address_message.d.ts +30 -0
- package/lnd_methods/onchain/sign_chain_address_message.js +80 -0
- package/lnd_methods/onchain/verify_chain_address_message.d.ts +32 -0
- package/lnd_methods/onchain/verify_chain_address_message.js +93 -0
- package/package.json +5 -5
- 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/test/typescript/authenticated_lightning_method.test-d.ts +18 -0
- package/test/typescript/sign_chain_address_message.test-d.ts +27 -0
- package/test/typescript/verify_chain_address_message.test-d.ts +32 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Versions
|
|
2
2
|
|
|
3
|
+
## 7.1.1
|
|
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
|
## 7.0.8
|
|
4
9
|
|
|
5
10
|
- `getChainAddresses`: Add method to get the list of chain addresses
|
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/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"
|
|
@@ -24,6 +24,7 @@ export * from './request_chain_fee_increase';
|
|
|
24
24
|
export * from './send_to_chain_address';
|
|
25
25
|
export * from './send_to_chain_addresses';
|
|
26
26
|
export * from './send_to_chain_output_scripts';
|
|
27
|
+
export * from './sign_chain_address_message';
|
|
27
28
|
export * from './set_autopilot';
|
|
28
29
|
export * from './sign_psbt';
|
|
29
30
|
export * from './subscribe_to_blocks';
|
|
@@ -32,3 +33,4 @@ export * from './subscribe_to_chain_spend';
|
|
|
32
33
|
export * from './subscribe_to_transactions';
|
|
33
34
|
export * from './unlock_utxo';
|
|
34
35
|
export * from './update_chain_transaction';
|
|
36
|
+
export * from './verify_chain_address_message';
|
|
@@ -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,30 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AuthenticatedLightningArgs,
|
|
3
|
+
AuthenticatedLightningMethod,
|
|
4
|
+
} from '../../typescript';
|
|
5
|
+
|
|
6
|
+
export type SignChainAddressMessageArgs = AuthenticatedLightningArgs<{
|
|
7
|
+
/** Chain Address String */
|
|
8
|
+
address: string;
|
|
9
|
+
/** Message To Sign String */
|
|
10
|
+
message: string;
|
|
11
|
+
}>;
|
|
12
|
+
|
|
13
|
+
export type SignChainAddressMessageResult = {
|
|
14
|
+
/** Hex Encoded Signature String */
|
|
15
|
+
signature: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Sign a chain address message using ECDSA
|
|
20
|
+
*
|
|
21
|
+
* Note: this method is not supported in LND versions 0.15.5 and below
|
|
22
|
+
*
|
|
23
|
+
* Requires LND built with `walletrpc` tag
|
|
24
|
+
*
|
|
25
|
+
* `onchain:write` permission is required
|
|
26
|
+
*/
|
|
27
|
+
export const signChainAddressMessage: AuthenticatedLightningMethod<
|
|
28
|
+
SignChainAddressMessageArgs,
|
|
29
|
+
SignChainAddressMessageResult
|
|
30
|
+
>;
|
|
@@ -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,32 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AuthenticatedLightningArgs,
|
|
3
|
+
AuthenticatedLightningMethod,
|
|
4
|
+
} from '../../typescript';
|
|
5
|
+
|
|
6
|
+
export type VerifyChainAddressMessageArgs = AuthenticatedLightningArgs<{
|
|
7
|
+
/** Chain Address String */
|
|
8
|
+
address: string;
|
|
9
|
+
/** Message to Verify String */
|
|
10
|
+
message: string;
|
|
11
|
+
/** Hex Encoded Signature String */
|
|
12
|
+
signature: string;
|
|
13
|
+
}>;
|
|
14
|
+
|
|
15
|
+
export type VerifyChainAddressMessageResult = {
|
|
16
|
+
/** Public Key Hex String */
|
|
17
|
+
signed_by: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Verify a chain address message using ECDSA
|
|
22
|
+
*
|
|
23
|
+
* Note: this method is not supported in LND versions 0.15.5 and below
|
|
24
|
+
*
|
|
25
|
+
* Requires LND built with `walletrpc` tag
|
|
26
|
+
*
|
|
27
|
+
* `onchain:write` permission is required
|
|
28
|
+
*/
|
|
29
|
+
export const verifyChainAddressMessage: AuthenticatedLightningMethod<
|
|
30
|
+
VerifyChainAddressMessageArgs,
|
|
31
|
+
VerifyChainAddressMessageResult
|
|
32
|
+
>;
|
|
@@ -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,17 +7,17 @@
|
|
|
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.11",
|
|
11
11
|
"@grpc/proto-loader": "0.7.5",
|
|
12
12
|
"@types/express": "4.17.17",
|
|
13
|
-
"@types/node": "18.
|
|
13
|
+
"@types/node": "18.14.1",
|
|
14
14
|
"@types/request": "2.48.8",
|
|
15
15
|
"@types/ws": "8.5.4",
|
|
16
16
|
"async": "3.2.4",
|
|
17
17
|
"asyncjs-util": "1.2.11",
|
|
18
18
|
"bitcoinjs-lib": "6.1.0",
|
|
19
19
|
"bn.js": "5.2.1",
|
|
20
|
-
"body-parser": "1.20.
|
|
20
|
+
"body-parser": "1.20.2",
|
|
21
21
|
"bolt07": "1.8.3",
|
|
22
22
|
"bolt09": "0.2.5",
|
|
23
23
|
"cbor": "8.1.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.1"
|
|
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.
|
|
62
|
+
"version": "7.1.1"
|
|
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
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {expectError, expectType} from 'tsd';
|
|
2
|
+
import {AuthenticatedLnd} from '../../lnd_grpc';
|
|
3
|
+
import {
|
|
4
|
+
AuthenticatedLightningArgs,
|
|
5
|
+
AuthenticatedLightningMethod,
|
|
6
|
+
} from '../../typescript';
|
|
7
|
+
|
|
8
|
+
type TestArgs = AuthenticatedLightningArgs;
|
|
9
|
+
type TestResult = unknown;
|
|
10
|
+
type TestMethod = AuthenticatedLightningMethod<TestArgs, TestResult>;
|
|
11
|
+
|
|
12
|
+
const authenticatedLightningMethod: TestMethod = async () => {};
|
|
13
|
+
|
|
14
|
+
const lnd = {} as AuthenticatedLnd;
|
|
15
|
+
|
|
16
|
+
expectError(authenticatedLightningMethod());
|
|
17
|
+
expectError(authenticatedLightningMethod({}));
|
|
18
|
+
expectType(authenticatedLightningMethod({lnd}));
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {expectError, expectType} from 'tsd';
|
|
2
|
+
import {AuthenticatedLnd} from '../../lnd_grpc';
|
|
3
|
+
import {
|
|
4
|
+
signChainAddressMessage,
|
|
5
|
+
SignChainAddressMessageResult,
|
|
6
|
+
} from '../../lnd_methods';
|
|
7
|
+
|
|
8
|
+
const lnd = {} as AuthenticatedLnd;
|
|
9
|
+
const address = '';
|
|
10
|
+
const message = '';
|
|
11
|
+
|
|
12
|
+
expectError(signChainAddressMessage({lnd, address}));
|
|
13
|
+
expectError(signChainAddressMessage({lnd, message}));
|
|
14
|
+
|
|
15
|
+
expectType<SignChainAddressMessageResult>(
|
|
16
|
+
await signChainAddressMessage({
|
|
17
|
+
lnd,
|
|
18
|
+
address,
|
|
19
|
+
message,
|
|
20
|
+
}),
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
expectType<void>(
|
|
24
|
+
signChainAddressMessage({lnd, address, message}, (error, result) => {
|
|
25
|
+
expectType<SignChainAddressMessageResult>(result);
|
|
26
|
+
}),
|
|
27
|
+
);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {expectError, expectType} from 'tsd';
|
|
2
|
+
import {AuthenticatedLnd} from '../../lnd_grpc';
|
|
3
|
+
import {
|
|
4
|
+
verifyChainAddressMessage,
|
|
5
|
+
VerifyChainAddressMessageResult,
|
|
6
|
+
} from '../../lnd_methods';
|
|
7
|
+
|
|
8
|
+
const lnd = {} as AuthenticatedLnd;
|
|
9
|
+
const address = '';
|
|
10
|
+
const message = '';
|
|
11
|
+
const signature = '';
|
|
12
|
+
|
|
13
|
+
expectError(verifyChainAddressMessage({lnd, address}));
|
|
14
|
+
expectError(verifyChainAddressMessage({lnd, message}));
|
|
15
|
+
expectError(verifyChainAddressMessage({lnd, address, message}));
|
|
16
|
+
expectError(verifyChainAddressMessage({lnd, address, signature}));
|
|
17
|
+
expectError(verifyChainAddressMessage({lnd, message, signature}));
|
|
18
|
+
|
|
19
|
+
expectType<VerifyChainAddressMessageResult>(
|
|
20
|
+
await verifyChainAddressMessage({
|
|
21
|
+
lnd,
|
|
22
|
+
address,
|
|
23
|
+
message,
|
|
24
|
+
signature,
|
|
25
|
+
}),
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
expectType<void>(
|
|
29
|
+
verifyChainAddressMessage({lnd, address, message, signature}, (error, result) => {
|
|
30
|
+
expectType<VerifyChainAddressMessageResult>(result);
|
|
31
|
+
}),
|
|
32
|
+
);
|