lightning 5.17.0 → 5.18.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
|
+
## 5.18.0
|
|
4
|
+
|
|
5
|
+
- `signBytes`: Add `type` and support for specifying `schnorr` type signing
|
|
6
|
+
- `verifyBytesSignature`: Add support for verifying Schnorr signatures
|
|
7
|
+
|
|
3
8
|
## 5.17.0
|
|
4
9
|
|
|
5
10
|
- `getChannels`: Add support for `is_trusted_funding` and `other_ids`
|
|
@@ -4,23 +4,31 @@ const {returnResult} = require('asyncjs-util');
|
|
|
4
4
|
const {isLnd} = require('./../../lnd_requests');
|
|
5
5
|
|
|
6
6
|
const bufferAsHex = buffer => buffer.toString('hex');
|
|
7
|
+
const defaultType = 'ecdsa';
|
|
7
8
|
const hexAsBuffer = hex => Buffer.from(hex, 'hex');
|
|
8
9
|
const isHex = n => !!n && !(n.length % 2) && /^[0-9A-F]*$/i.test(n);
|
|
10
|
+
const isSchnorrSig = signature => signature.length === 64;
|
|
9
11
|
const method = 'signMessage';
|
|
10
12
|
const type = 'signer';
|
|
13
|
+
const types = {ecdsa: 'ecdsa', schnorr: 'schnorr'};
|
|
11
14
|
const unimplementedError = '12 UNIMPLEMENTED: unknown service signrpc.Signer';
|
|
12
15
|
|
|
13
16
|
/** Sign a sha256 hash of arbitrary bytes
|
|
14
17
|
|
|
18
|
+
Supported signature types: `ecdsa`, `schnorr`
|
|
19
|
+
|
|
15
20
|
Requires LND built with `signrpc` build tag
|
|
16
21
|
|
|
17
22
|
Requires `signer:generate` permission
|
|
18
23
|
|
|
24
|
+
`schnorr` signature type is not supported on LND 0.15.0 and below
|
|
25
|
+
|
|
19
26
|
{
|
|
20
27
|
key_family: <Key Family Number>
|
|
21
28
|
key_index: <Key Index Number>
|
|
22
29
|
lnd: <Authenticated LND API Object>
|
|
23
30
|
preimage: <Bytes To Hash and Sign Hex Encoded String>
|
|
31
|
+
[type]: <Signature Type String>
|
|
24
32
|
}
|
|
25
33
|
|
|
26
34
|
@returns via cbk or Promise
|
|
@@ -49,6 +57,10 @@ module.exports = (args, cbk) => {
|
|
|
49
57
|
return cbk([400, 'ExpectedHexDataToSignBytes']);
|
|
50
58
|
}
|
|
51
59
|
|
|
60
|
+
if (!!args.type && !types[args.type]) {
|
|
61
|
+
return cbk([400, 'ExpectedKnownSignatureTypeToSignBytes']);
|
|
62
|
+
}
|
|
63
|
+
|
|
52
64
|
return cbk();
|
|
53
65
|
},
|
|
54
66
|
|
|
@@ -57,6 +69,7 @@ module.exports = (args, cbk) => {
|
|
|
57
69
|
return args.lnd[type][method]({
|
|
58
70
|
key_loc: {key_family: args.key_family, key_index: args.key_index},
|
|
59
71
|
msg: hexAsBuffer(args.preimage),
|
|
72
|
+
schnorr_sig: args.type === types.schnorr || undefined,
|
|
60
73
|
},
|
|
61
74
|
(err, res) => {
|
|
62
75
|
if (!!err && err.message === unimplementedError) {
|
|
@@ -79,6 +92,10 @@ module.exports = (args, cbk) => {
|
|
|
79
92
|
return cbk([503, 'ExpectedSignatureInSignBytesResponse']);
|
|
80
93
|
}
|
|
81
94
|
|
|
95
|
+
if (args.type === types.schnorr && !isSchnorrSig(res.signature)) {
|
|
96
|
+
return cbk([503, 'UnexpectedSignatureLengthInSignBytesResponse']);
|
|
97
|
+
}
|
|
98
|
+
|
|
82
99
|
return cbk(null, {signature: bufferAsHex(res.signature)});
|
|
83
100
|
});
|
|
84
101
|
}],
|
|
@@ -4,14 +4,19 @@ const {returnResult} = require('asyncjs-util');
|
|
|
4
4
|
const {isLnd} = require('./../../lnd_requests');
|
|
5
5
|
|
|
6
6
|
const isHex = n => !(n.length % 2) && /^[0-9A-F]*$/i.test(n);
|
|
7
|
+
const isSchnorrSignatureLength = signature => signature.length === 128;
|
|
7
8
|
const unimplementedError = '12 UNIMPLEMENTED: unknown service signrpc.Signer';
|
|
8
9
|
|
|
9
10
|
/** Verify signature of arbitrary bytes
|
|
10
11
|
|
|
12
|
+
When passing a schnorr signature, a BIP-340 x-only public key should be given
|
|
13
|
+
|
|
11
14
|
Requires LND built with `signrpc` build tag
|
|
12
15
|
|
|
13
16
|
Requires `signer:read` permission
|
|
14
17
|
|
|
18
|
+
Validating `schnorr` signatures is unsupported in LND 0.15.0 and below
|
|
19
|
+
|
|
15
20
|
{
|
|
16
21
|
lnd: <Authenticated LND API Object>
|
|
17
22
|
preimage: <Message Preimage Bytes Hex Encoded String>
|
|
@@ -51,6 +56,7 @@ module.exports = (args, cbk) => {
|
|
|
51
56
|
// Verify signature
|
|
52
57
|
verify: ['validate', ({}, cbk) => {
|
|
53
58
|
return args.lnd.signer.verifyMessage({
|
|
59
|
+
is_schnorr_sig: isSchnorrSignatureLength(args.signature),
|
|
54
60
|
msg: Buffer.from(args.preimage, 'hex'),
|
|
55
61
|
pubkey: Buffer.from(args.public_key, 'hex'),
|
|
56
62
|
signature: Buffer.from(args.signature, 'hex'),
|
package/package.json
CHANGED
|
@@ -6,12 +6,13 @@ const makeLnd = (err, res) => {
|
|
|
6
6
|
return {signer: {signMessage: ({}, cbk) => cbk(err, res)}};
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
const makeArgs = ({override}) => {
|
|
9
|
+
const makeArgs = ({override, signature}) => {
|
|
10
10
|
const args = {
|
|
11
11
|
key_family: 0,
|
|
12
12
|
key_index: 0,
|
|
13
|
-
lnd: makeLnd(null, {signature: '00'}),
|
|
13
|
+
lnd: makeLnd(null, {signature: Buffer.from(signature || '00', 'hex')}),
|
|
14
14
|
preimage: '00',
|
|
15
|
+
type: 'ecdsa',
|
|
15
16
|
};
|
|
16
17
|
|
|
17
18
|
Object.keys(override || {}).forEach(key => args[key] = override[key]);
|
|
@@ -40,6 +41,11 @@ const tests = [
|
|
|
40
41
|
description: 'A preimage to hash and sign is required',
|
|
41
42
|
error: [400, 'ExpectedHexDataToSignBytes'],
|
|
42
43
|
},
|
|
44
|
+
{
|
|
45
|
+
args: makeArgs({override: {type: 'type'}}),
|
|
46
|
+
description: 'A known signature type is required',
|
|
47
|
+
error: [400, 'ExpectedKnownSignatureTypeToSignBytes'],
|
|
48
|
+
},
|
|
43
49
|
{
|
|
44
50
|
args: makeArgs({
|
|
45
51
|
override: {
|
|
@@ -71,11 +77,23 @@ const tests = [
|
|
|
71
77
|
description: 'A non empty signature is expected',
|
|
72
78
|
error: [503, 'ExpectedSignatureInSignBytesResponse'],
|
|
73
79
|
},
|
|
80
|
+
{
|
|
81
|
+
args: makeArgs({override: {type: 'schnorr'}}),
|
|
82
|
+
description: 'Schnorr signature is expected to be schnorr sized',
|
|
83
|
+
error: [503, 'UnexpectedSignatureLengthInSignBytesResponse'],
|
|
84
|
+
},
|
|
74
85
|
{
|
|
75
86
|
args: makeArgs({}),
|
|
76
87
|
description: 'Signature is returned for preimage',
|
|
77
88
|
expected: {signature: '00'},
|
|
78
89
|
},
|
|
90
|
+
{
|
|
91
|
+
args: makeArgs({
|
|
92
|
+
override: {type: 'schnorr'}, signature: Buffer.alloc(64).toString('hex'),
|
|
93
|
+
}),
|
|
94
|
+
description: 'Schnorr signature is supported',
|
|
95
|
+
expected: {signature: Buffer.alloc(64).toString('hex')},
|
|
96
|
+
},
|
|
79
97
|
];
|
|
80
98
|
|
|
81
99
|
tests.forEach(({args, description, error, expected}) => {
|