lightning 5.16.0 → 5.16.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 +1 -1
- package/lnd_methods/address/create_chain_address.js +37 -1
- package/lnd_methods/macaroon/methods.json +1 -0
- package/lnd_methods/offchain/pay_via_routes.js +4 -0
- package/lnd_methods/signer/sign_transaction.d.ts +3 -1
- package/lnd_methods/signer/sign_transaction.js +1 -0
- package/package.json +11 -11
- package/test/lnd_methods/address/test_create_chain_address.js +87 -0
- package/test/lnd_methods/offchain/test_pay_via_routes.js +22 -0
- package/test/typescript/sign_transaction.test-d.ts +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,7 +6,11 @@ const {isLnd} = require('./../../lnd_requests');
|
|
|
6
6
|
|
|
7
7
|
const connectFailMessage = '14 UNAVAILABLE: Connect Failed';
|
|
8
8
|
const defaultAddressFormat = 'p2wpkh';
|
|
9
|
+
const {isArray} = Array;
|
|
10
|
+
const isNeedingDerivationsCheck = format => format === 'p2tr';
|
|
11
|
+
const isTrSupported = n => !!n.find(n => n.address_type === 'TAPROOT_PUBKEY');
|
|
9
12
|
const method = 'newAddress';
|
|
13
|
+
const notSupported = /unknown.*walletrpc.WalletKit/;
|
|
10
14
|
const type = 'default';
|
|
11
15
|
|
|
12
16
|
/** Create a new receive address.
|
|
@@ -42,6 +46,38 @@ module.exports = (args, cbk) => {
|
|
|
42
46
|
return cbk();
|
|
43
47
|
},
|
|
44
48
|
|
|
49
|
+
// Get account derivations to confirm P2TR support
|
|
50
|
+
checkFormat: ['validate', ({}, cbk) => {
|
|
51
|
+
// Exit early when there is no need to check the derivations
|
|
52
|
+
if (!isNeedingDerivationsCheck(args.format)) {
|
|
53
|
+
return cbk();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return args.lnd.wallet.listAccounts({}, (err, res) => {
|
|
57
|
+
if (!!err && notSupported.test(err.details)) {
|
|
58
|
+
return cbk([501, 'CreationOfTaprootAddressesUnsupported']);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!!err) {
|
|
62
|
+
return cbk([503, 'UnexpectedErrorCheckingTaprootSupport', {err}]);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (!res) {
|
|
66
|
+
return cbk([503, 'ExpectedResultForDerivationPathsRequest']);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!isArray(res.accounts)) {
|
|
70
|
+
return cbk([503, 'ExpectedAccountsInDerivationPathsResult']);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (!isTrSupported(res.accounts)) {
|
|
74
|
+
return cbk([501, 'ExpectedTaprootSupportingLndToCreateAddress']);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return cbk();
|
|
78
|
+
});
|
|
79
|
+
}],
|
|
80
|
+
|
|
45
81
|
// Type
|
|
46
82
|
type: ['validate', ({}, cbk) => {
|
|
47
83
|
const format = args.format || defaultAddressFormat;
|
|
@@ -54,7 +90,7 @@ module.exports = (args, cbk) => {
|
|
|
54
90
|
}],
|
|
55
91
|
|
|
56
92
|
// Get the address
|
|
57
|
-
createAddress: ['type', ({type}, cbk) => {
|
|
93
|
+
createAddress: ['checkFormat', 'type', ({type}, cbk) => {
|
|
58
94
|
return args.lnd.default.newAddress({type}, (err, res) => {
|
|
59
95
|
if (!!err && err.message === connectFailMessage) {
|
|
60
96
|
return cbk([503, 'FailedToConnectToDaemonToCreateChainAddress']);
|
|
@@ -105,6 +105,10 @@ module.exports = (args, cbk) => {
|
|
|
105
105
|
return cbk([400, 'ExpectedArrayOfRoutesToPayViaRoutes']);
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
+
if (!!args.routes.filter(n => !n).length) {
|
|
109
|
+
return cbk([400, 'ExpectedArrayOfRoutesToAttemptPayingOver']);
|
|
110
|
+
}
|
|
111
|
+
|
|
108
112
|
if (args.routes.findIndex(n => !isArray(n.hops)) !== notFound) {
|
|
109
113
|
return cbk([400, 'ExpectedArrayOfHopsForPayViaRoute']);
|
|
110
114
|
}
|
|
@@ -13,12 +13,14 @@ export type SignTransactionArgs = AuthenticatedLightningArgs<{
|
|
|
13
13
|
output_script: string;
|
|
14
14
|
/** Output Tokens */
|
|
15
15
|
output_tokens: number;
|
|
16
|
+
/** Taproot Root Hash Hex String */
|
|
17
|
+
root_hash?: string;
|
|
16
18
|
/** Sighash Type */
|
|
17
19
|
sighash: number;
|
|
18
20
|
/** Input Index To Sign */
|
|
19
21
|
vin: number;
|
|
20
22
|
/** Witness Script Hex String */
|
|
21
|
-
witness_script
|
|
23
|
+
witness_script?: string;
|
|
22
24
|
}[];
|
|
23
25
|
spending?: {
|
|
24
26
|
/** Non-Internal Spend Output Script Hex String */
|
package/package.json
CHANGED
|
@@ -8,33 +8,33 @@
|
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@grpc/grpc-js": "1.6.7",
|
|
11
|
-
"@grpc/proto-loader": "0.6.
|
|
11
|
+
"@grpc/proto-loader": "0.6.13",
|
|
12
12
|
"@types/express": "4.17.13",
|
|
13
|
-
"@types/node": "17.0.
|
|
13
|
+
"@types/node": "17.0.41",
|
|
14
14
|
"@types/request": "2.48.8",
|
|
15
15
|
"@types/ws": "8.5.3",
|
|
16
|
-
"async": "3.2.
|
|
16
|
+
"async": "3.2.4",
|
|
17
17
|
"asyncjs-util": "1.2.9",
|
|
18
18
|
"bitcoinjs-lib": "6.0.1",
|
|
19
|
-
"bn.js": "5.2.
|
|
19
|
+
"bn.js": "5.2.1",
|
|
20
20
|
"body-parser": "1.20.0",
|
|
21
|
-
"bolt07": "1.8.
|
|
21
|
+
"bolt07": "1.8.2",
|
|
22
22
|
"bolt09": "0.2.3",
|
|
23
23
|
"cbor": "8.1.0",
|
|
24
24
|
"ecpair": "2.0.1",
|
|
25
25
|
"express": "4.18.1",
|
|
26
|
-
"invoices": "2.0.
|
|
27
|
-
"psbt": "2.0
|
|
26
|
+
"invoices": "2.0.7",
|
|
27
|
+
"psbt": "2.6.0",
|
|
28
28
|
"tiny-secp256k1": "2.2.1",
|
|
29
|
-
"type-fest": "2.
|
|
29
|
+
"type-fest": "2.13.0"
|
|
30
30
|
},
|
|
31
31
|
"description": "Lightning Network client library",
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@alexbosworth/node-fetch": "2.6.2",
|
|
34
34
|
"@alexbosworth/tap": "15.0.11",
|
|
35
35
|
"tsd": "0.20.0",
|
|
36
|
-
"typescript": "4.
|
|
37
|
-
"ws": "8.
|
|
36
|
+
"typescript": "4.7.3",
|
|
37
|
+
"ws": "8.7.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.16.
|
|
62
|
+
"version": "5.16.3"
|
|
63
63
|
}
|
|
@@ -66,6 +66,93 @@ const tests = [
|
|
|
66
66
|
description: 'An address is required',
|
|
67
67
|
expected: {address: 'addr'},
|
|
68
68
|
},
|
|
69
|
+
{
|
|
70
|
+
args: {
|
|
71
|
+
lnd: {default: {newAddress: ({}, cbk) => cbk(null, {address: 'addr'})}},
|
|
72
|
+
},
|
|
73
|
+
description: 'The default address is p2wpkh',
|
|
74
|
+
expected: {address: 'addr'},
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
args: {
|
|
78
|
+
format: 'p2tr',
|
|
79
|
+
lnd: {
|
|
80
|
+
default: {
|
|
81
|
+
newAddress: ({}, cbk) => cbk(null, {address: 'addr'}),
|
|
82
|
+
},
|
|
83
|
+
wallet: {
|
|
84
|
+
listAccounts: ({}, cbk) => cbk({
|
|
85
|
+
details: 'unknown.service.walletrpc.WalletKit',
|
|
86
|
+
}),
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
description: 'Taproot requires TR account',
|
|
91
|
+
error: [501, 'CreationOfTaprootAddressesUnsupported'],
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
args: {
|
|
95
|
+
format: 'p2tr',
|
|
96
|
+
lnd: {
|
|
97
|
+
default: {newAddress: ({}, cbk) => cbk(null, {address: 'addr'})},
|
|
98
|
+
wallet: {listAccounts: ({}, cbk) => cbk('err')},
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
description: 'Taproot check errors are passed back',
|
|
102
|
+
error: [503, 'UnexpectedErrorCheckingTaprootSupport'],
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
args: {
|
|
106
|
+
format: 'p2tr',
|
|
107
|
+
lnd: {
|
|
108
|
+
default: {newAddress: ({}, cbk) => cbk(null, {address: 'addr'})},
|
|
109
|
+
wallet: {listAccounts: ({}, cbk) => cbk()},
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
description: 'Taproot requires account result',
|
|
113
|
+
error: [503, 'ExpectedResultForDerivationPathsRequest'],
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
args: {
|
|
117
|
+
format: 'p2tr',
|
|
118
|
+
lnd: {
|
|
119
|
+
default: {newAddress: ({}, cbk) => cbk(null, {address: 'addr'})},
|
|
120
|
+
wallet: {listAccounts: ({}, cbk) => cbk(null, {})},
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
description: 'Taproot accounts are expected',
|
|
124
|
+
error: [503, 'ExpectedAccountsInDerivationPathsResult'],
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
args: {
|
|
128
|
+
format: 'p2tr',
|
|
129
|
+
lnd: {
|
|
130
|
+
default: {newAddress: ({}, cbk) => cbk(null, {address: 'addr'})},
|
|
131
|
+
wallet: {listAccounts: ({}, cbk) => cbk(null, {accounts: []})},
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
description: 'Taproot supporting account is expected',
|
|
135
|
+
error: [501, 'ExpectedTaprootSupportingLndToCreateAddress'],
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
args: {
|
|
139
|
+
format: 'p2tr',
|
|
140
|
+
lnd: {
|
|
141
|
+
default: {
|
|
142
|
+
newAddress: ({}, cbk) => cbk(null, {
|
|
143
|
+
address: 'taproot_address',
|
|
144
|
+
}),
|
|
145
|
+
},
|
|
146
|
+
wallet: {
|
|
147
|
+
listAccounts: ({}, cbk) => cbk(null, {
|
|
148
|
+
accounts: [{address_type: 'TAPROOT_PUBKEY'}],
|
|
149
|
+
}),
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
description: 'Taproot supporting account',
|
|
154
|
+
expected: {address: 'taproot_address'},
|
|
155
|
+
},
|
|
69
156
|
{
|
|
70
157
|
args: {
|
|
71
158
|
format: 'p2wpkh',
|
|
@@ -57,6 +57,28 @@ const tests = [
|
|
|
57
57
|
description: 'A non-empty array of routes is expected',
|
|
58
58
|
error: [400, 'ExpectedArrayOfRoutesToPayViaRoutes'],
|
|
59
59
|
},
|
|
60
|
+
{
|
|
61
|
+
args: {
|
|
62
|
+
lnd: {
|
|
63
|
+
default: {deletePayment, getInfo},
|
|
64
|
+
router: {sendToRouteV2: ({}, cbk) => cbk(null, {})},
|
|
65
|
+
},
|
|
66
|
+
routes: [null],
|
|
67
|
+
},
|
|
68
|
+
description: 'An array of non-empty routes is expected',
|
|
69
|
+
error: [400, 'ExpectedArrayOfRoutesToAttemptPayingOver'],
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
args: {
|
|
73
|
+
lnd: {
|
|
74
|
+
default: {deletePayment, getInfo},
|
|
75
|
+
router: {sendToRouteV2: ({}, cbk) => cbk(null, {})},
|
|
76
|
+
},
|
|
77
|
+
routes: [{}],
|
|
78
|
+
},
|
|
79
|
+
description: 'Routes are expected to have hops',
|
|
80
|
+
error: [400, 'ExpectedArrayOfHopsForPayViaRoute'],
|
|
81
|
+
},
|
|
60
82
|
{
|
|
61
83
|
args: {
|
|
62
84
|
lnd: {
|