lightning 5.4.2 → 5.6.2
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 +8 -0
- package/README.md +4 -2
- package/lnd_methods/info/constants.json +1 -0
- package/lnd_methods/offchain/pay_via_routes.d.ts +6 -0
- package/lnd_methods/offchain/pay_via_routes.js +4 -0
- package/lnd_methods/offchain/subscribe_to_pay_via_routes.js +4 -0
- package/lnd_methods/onchain/fund_psbt.js +6 -2
- package/lnd_methods/onchain/index.d.ts +1 -0
- package/lnd_methods/onchain/partially_sign_psbt.d.ts +28 -0
- package/lnd_methods/onchain/partially_sign_psbt.js +1 -1
- package/lnd_methods/unauthenticated/create_wallet.d.ts +9 -1
- package/lnd_requests/rpc_hop_from_hop.js +25 -1
- package/lnd_requests/rpc_route_from_route.js +7 -2
- package/package.json +7 -5
- package/test/lnd_requests/test_rpc_hop_from_hop.js +26 -0
- package/test/typescript/create_wallet.test-d.ts +11 -5
- package/test/typescript/partially_sign_psbt.test-d.ts +18 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Versions
|
|
2
2
|
|
|
3
|
+
## 5.6.2
|
|
4
|
+
|
|
5
|
+
- `payViaRoutes`, `subscribeToPayViaRoutes`: Add support for relay messages
|
|
6
|
+
|
|
7
|
+
## 5.5.0
|
|
8
|
+
|
|
9
|
+
- `partiallySignPsbt`: Add method to partially sign a PSBT
|
|
10
|
+
|
|
3
11
|
## 5.4.2
|
|
4
12
|
|
|
5
13
|
- `deletePendingChannel`: Add method to delete a stuck pending channel
|
package/README.md
CHANGED
|
@@ -206,8 +206,10 @@ To access unauthenticated methods like the wallet unlocker, use
|
|
|
206
206
|
chosen to be spent.
|
|
207
207
|
- [openChannel](https://github.com/alexbosworth/ln-service#openchannel): Create a new channel
|
|
208
208
|
to another node.
|
|
209
|
-
- [openChannels](https://github.com/alexbosworth/ln-service#openchannels): Open
|
|
210
|
-
|
|
209
|
+
- [openChannels](https://github.com/alexbosworth/ln-service#openchannels): Open
|
|
210
|
+
multiple channels in a single on-chain transaction batch.
|
|
211
|
+
- [partiallySignPsbt](https://github.com/alexbosworth/ln-service#partiallysignpsbt):
|
|
212
|
+
Add a partial signature to a PSBT
|
|
211
213
|
- [pay](https://github.com/alexbosworth/ln-service#pay): Make an off-chain payment.
|
|
212
214
|
- [payViaPaymentDetails](https://github.com/alexbosworth/ln-service#payviapaymentdetails): Pay
|
|
213
215
|
off-chain using details about a destination invoice.
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"versions": {
|
|
21
21
|
"0d5b0fefa4d9082f7964836f5e58c3a6bda8e471": "0.10.2-beta",
|
|
22
22
|
"1a3194d302f33bb52823297d9d7f75cd37516053": "0.10.0-beta",
|
|
23
|
+
"1e511be523eb8e97c4e2d9c89a7a263963a3929f": "0.14.2-beta",
|
|
23
24
|
"3ae46d81f4a2edad06ef778b2940d9b06386d93b": "0.11.0-beta",
|
|
24
25
|
"4f567577db9d85b6f392f960b3aabddcad3cd02c": "0.13.3-beta",
|
|
25
26
|
"52bb3f33707b81972c67937c7a89addcdf00991c": "0.10.1-beta",
|
|
@@ -27,6 +27,12 @@ export type PayViaRoutesArgs = AuthenticatedLightningArgs<{
|
|
|
27
27
|
forward: number;
|
|
28
28
|
/** Forward Millitokens */
|
|
29
29
|
forward_mtokens: string;
|
|
30
|
+
messages?: {
|
|
31
|
+
/** Message Type number */
|
|
32
|
+
type: string;
|
|
33
|
+
/** Message Raw Value Hex Encoded */
|
|
34
|
+
value: string;
|
|
35
|
+
}[];
|
|
30
36
|
/** Public Key Hex */
|
|
31
37
|
public_key?: string;
|
|
32
38
|
/** Timeout Block Height */
|
|
@@ -29,6 +29,10 @@ const notFound = -1;
|
|
|
29
29
|
fee_mtokens: <Fee Millitokens String>
|
|
30
30
|
forward: <Forward Tokens Number>
|
|
31
31
|
forward_mtokens: <Forward Millitokens String>
|
|
32
|
+
[messages]: [{
|
|
33
|
+
type: <Message Type Number String>
|
|
34
|
+
value: <Message Raw Value Hex Encoded String>
|
|
35
|
+
}]
|
|
32
36
|
[public_key]: <Public Key Hex String>
|
|
33
37
|
timeout: <Timeout Block Height Number>
|
|
34
38
|
}]
|
|
@@ -43,6 +43,10 @@ const unknownWireError = 'unknown wire error';
|
|
|
43
43
|
fee_mtokens: <Fee Millitokens String>
|
|
44
44
|
forward: <Forward Tokens Number>
|
|
45
45
|
forward_mtokens: <Forward Millitokens String>
|
|
46
|
+
[messages]: [{
|
|
47
|
+
type: <Message Type Number String>
|
|
48
|
+
value: <Message Raw Value Hex Encoded String>
|
|
49
|
+
}]
|
|
46
50
|
public_key: <Public Key Hex String>
|
|
47
51
|
timeout: <Timeout Block Height Number>
|
|
48
52
|
}]
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const asyncAuto = require('async/auto');
|
|
2
2
|
const {decodePsbt} = require('psbt');
|
|
3
3
|
const {returnResult} = require('asyncjs-util');
|
|
4
|
+
const tinysecp = require('tiny-secp256k1');
|
|
4
5
|
const {Transaction} = require('bitcoinjs-lib');
|
|
5
6
|
|
|
6
7
|
const {isLnd} = require('./../../lnd_requests');
|
|
@@ -67,6 +68,9 @@ const txIdFromHash = hash => hash.reverse().toString('hex');
|
|
|
67
68
|
module.exports = (args, cbk) => {
|
|
68
69
|
return new Promise((resolve, reject) => {
|
|
69
70
|
return asyncAuto({
|
|
71
|
+
// Import ECPair library
|
|
72
|
+
ecp: async () => (await import('ecpair')).ECPairFactory(tinysecp),
|
|
73
|
+
|
|
70
74
|
// Check arguments
|
|
71
75
|
validate: cbk => {
|
|
72
76
|
if (!isLnd({method, type, lnd: args.lnd})) {
|
|
@@ -201,11 +205,11 @@ module.exports = (args, cbk) => {
|
|
|
201
205
|
}],
|
|
202
206
|
|
|
203
207
|
// Derive the raw transaction from the funded PSBT
|
|
204
|
-
tx: ['fund', ({fund}, cbk) => {
|
|
208
|
+
tx: ['fund', ({ecp, fund}, cbk) => {
|
|
205
209
|
const {psbt} = fund;
|
|
206
210
|
|
|
207
211
|
try {
|
|
208
|
-
const tx = fromHex(decodePsbt({psbt}).unsigned_transaction);
|
|
212
|
+
const tx = fromHex(decodePsbt({ecp, psbt}).unsigned_transaction);
|
|
209
213
|
|
|
210
214
|
return cbk(null, tx);
|
|
211
215
|
} catch (err) {
|
|
@@ -14,6 +14,7 @@ export * from './get_utxos';
|
|
|
14
14
|
export * from './lock_utxo';
|
|
15
15
|
export * from './open_channel';
|
|
16
16
|
export * from './open_channels';
|
|
17
|
+
export * from './partially_sign_psbt';
|
|
17
18
|
export * from './prepare_for_channel_proposal';
|
|
18
19
|
export * from './propose_channel';
|
|
19
20
|
export * from './request_chain_fee_increase';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AuthenticatedLightningArgs,
|
|
3
|
+
AuthenticatedLightningMethod,
|
|
4
|
+
} from '../../typescript';
|
|
5
|
+
|
|
6
|
+
export type PartiallySignPsbtArgs = AuthenticatedLightningArgs<{
|
|
7
|
+
/** Funded PSBT Hex String */
|
|
8
|
+
psbt: string;
|
|
9
|
+
}>;
|
|
10
|
+
|
|
11
|
+
export type PartiallySignPsbtResult = {
|
|
12
|
+
/** Partially Signed PSBT Hex String */
|
|
13
|
+
psbt: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Sign a PSBT to produce a partially signed PSBT
|
|
18
|
+
*
|
|
19
|
+
* Requires `onchain:write` permission
|
|
20
|
+
*
|
|
21
|
+
* Requires LND built with `walletrpc` tag
|
|
22
|
+
*
|
|
23
|
+
* This method is not supported in LND 0.14.2 and below
|
|
24
|
+
*/
|
|
25
|
+
export const partiallySignPsbt: AuthenticatedLightningMethod<
|
|
26
|
+
PartiallySignPsbtArgs,
|
|
27
|
+
PartiallySignPsbtResult
|
|
28
|
+
>;
|
|
@@ -12,9 +12,17 @@ export type CreateWalletArgs = UnauthenticatedLightningArgs<{
|
|
|
12
12
|
seed: string;
|
|
13
13
|
}>;
|
|
14
14
|
|
|
15
|
+
export type CreateWalletResult = {
|
|
16
|
+
/** Base64 Encoded Admin Macaroon String */
|
|
17
|
+
macaroon: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
15
20
|
/**
|
|
16
21
|
* Create a wallet
|
|
17
22
|
*
|
|
18
23
|
* Requires unlocked lnd and unauthenticated LND
|
|
19
24
|
*/
|
|
20
|
-
export const createWallet: UnauthenticatedLightningMethod<
|
|
25
|
+
export const createWallet: UnauthenticatedLightningMethod<
|
|
26
|
+
CreateWalletArgs,
|
|
27
|
+
CreateWalletResult
|
|
28
|
+
>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const {chanNumber} = require('bolt07');
|
|
2
2
|
|
|
3
|
+
const hexAsBuffer = hex => Buffer.from(hex, 'hex');
|
|
3
4
|
const isNumber = n => !isNaN(n);
|
|
4
5
|
const millitokensAsTokens = n => Number(BigInt(n) / BigInt(1e3));
|
|
5
6
|
|
|
@@ -12,6 +13,10 @@ const millitokensAsTokens = n => Number(BigInt(n) / BigInt(1e3));
|
|
|
12
13
|
fee_mtokens: <Fee Millitokens String>
|
|
13
14
|
forward: <Forward Tokens Number>
|
|
14
15
|
forward_mtokens: <Forward Millitokens String>
|
|
16
|
+
[messages]: [{
|
|
17
|
+
type: <Message Type Number String>
|
|
18
|
+
value: <Message Raw Value Hex Encoded String>
|
|
19
|
+
}]
|
|
15
20
|
[public_key]: <Forward Edge Public Key Hex String>
|
|
16
21
|
timeout: <Timeout Block Height Number>
|
|
17
22
|
}
|
|
@@ -25,10 +30,12 @@ const millitokensAsTokens = n => Number(BigInt(n) / BigInt(1e3));
|
|
|
25
30
|
amt_to_forward_msat: <Millitokens to Forward String>
|
|
26
31
|
chan_id: <Numeric Format Channel Id String>
|
|
27
32
|
chan_capacity: <Channel Capacity Number>
|
|
33
|
+
[custom_records]: {<TLV Type Number String>: <TLV Value Buffer Object>}
|
|
28
34
|
expiry: <Timeout Chain Height Number>
|
|
29
35
|
fee: <Fee in Tokens Number>
|
|
30
36
|
fee_msat: <Fee in Millitokens String>
|
|
31
37
|
[pub_key]: <Next Hop Public Key Hex String>
|
|
38
|
+
[tlv_payload]: <Has Extra TLV Data Bool>
|
|
32
39
|
}
|
|
33
40
|
*/
|
|
34
41
|
module.exports = args => {
|
|
@@ -44,7 +51,7 @@ module.exports = args => {
|
|
|
44
51
|
throw new Error('ExpectedFeeMillitokensToMapRpcHopFromHop');
|
|
45
52
|
}
|
|
46
53
|
|
|
47
|
-
|
|
54
|
+
const hop = {
|
|
48
55
|
amt_to_forward: millitokensAsTokens(args.forward_mtokens).toString(),
|
|
49
56
|
amt_to_forward_msat: args.forward_mtokens,
|
|
50
57
|
chan_id: chanNumber({channel: args.channel}).number,
|
|
@@ -54,4 +61,21 @@ module.exports = args => {
|
|
|
54
61
|
fee_msat: args.fee_mtokens,
|
|
55
62
|
pub_key: args.public_key,
|
|
56
63
|
};
|
|
64
|
+
|
|
65
|
+
// Exit early when there are no messages to encode in this hop
|
|
66
|
+
if (!args.messages || !args.messages.length) {
|
|
67
|
+
return hop;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Set custom TLV payload records for this hop
|
|
71
|
+
hop.tlv_payload = true;
|
|
72
|
+
|
|
73
|
+
hop.custom_records = args.messages.reduce((tlv, n) => {
|
|
74
|
+
tlv[n.type] = hexAsBuffer(n.value);
|
|
75
|
+
|
|
76
|
+
return tlv;
|
|
77
|
+
},
|
|
78
|
+
{});
|
|
79
|
+
|
|
80
|
+
return hop;
|
|
57
81
|
};
|
|
@@ -14,6 +14,10 @@ const isNumber = n => !isNaN(n);
|
|
|
14
14
|
fee_mtokens: <Fee Millitokens String>
|
|
15
15
|
forward: <Forward Tokens Number>
|
|
16
16
|
forward_mtokens: <Forward Millitokens String>
|
|
17
|
+
[messages]: [{
|
|
18
|
+
type: <Message Type Number String>
|
|
19
|
+
value: <Message Raw Value Hex Encoded String>
|
|
20
|
+
}]
|
|
17
21
|
[public_key]: <Forward Edge Public Key Hex String>
|
|
18
22
|
timeout: <Timeout Block Height Number>
|
|
19
23
|
}]
|
|
@@ -38,6 +42,7 @@ const isNumber = n => !isNaN(n);
|
|
|
38
42
|
amt_to_forward_msat: <Millitokens to Forward String>
|
|
39
43
|
chan_id: <Numeric Format Channel Id String>
|
|
40
44
|
chan_capacity: <Channel Capacity Number>
|
|
45
|
+
[custom_records]: {<TLV Type Number String>: <TLV Value Buffer Object>}
|
|
41
46
|
expiry: <Timeout Chain Height Number>
|
|
42
47
|
fee: <Fee in Tokens Number>
|
|
43
48
|
fee_msat: <Fee in Millitokens Number>
|
|
@@ -79,7 +84,7 @@ module.exports = args => {
|
|
|
79
84
|
};
|
|
80
85
|
}
|
|
81
86
|
|
|
82
|
-
// Set custom TLV payload records
|
|
87
|
+
// Set custom TLV payload records on the final hop
|
|
83
88
|
if (!!args.messages && !!args.messages.length) {
|
|
84
89
|
hops[finalHopIndex].tlv_payload = true;
|
|
85
90
|
|
|
@@ -88,7 +93,7 @@ module.exports = args => {
|
|
|
88
93
|
|
|
89
94
|
return tlv;
|
|
90
95
|
},
|
|
91
|
-
{});
|
|
96
|
+
hops[finalHopIndex].custom_records || {});
|
|
92
97
|
}
|
|
93
98
|
|
|
94
99
|
return {
|
package/package.json
CHANGED
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
"url": "https://github.com/alexbosworth/lightning/issues"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@grpc/grpc-js": "1.5.
|
|
10
|
+
"@grpc/grpc-js": "1.5.4",
|
|
11
11
|
"@grpc/proto-loader": "0.6.9",
|
|
12
12
|
"@types/express": "4.17.13",
|
|
13
|
-
"@types/node": "17.0.
|
|
13
|
+
"@types/node": "17.0.15",
|
|
14
14
|
"@types/request": "2.48.8",
|
|
15
15
|
"@types/ws": "8.2.2",
|
|
16
16
|
"async": "3.2.3",
|
|
@@ -21,10 +21,12 @@
|
|
|
21
21
|
"bolt07": "1.8.0",
|
|
22
22
|
"bolt09": "0.2.1",
|
|
23
23
|
"cbor": "8.1.0",
|
|
24
|
+
"ecpair": "2.0.1",
|
|
24
25
|
"express": "4.17.2",
|
|
25
26
|
"invoices": "2.0.3",
|
|
26
|
-
"psbt": "
|
|
27
|
-
"
|
|
27
|
+
"psbt": "2.0.0",
|
|
28
|
+
"tiny-secp256k1": "2.2.0",
|
|
29
|
+
"type-fest": "2.11.1"
|
|
28
30
|
},
|
|
29
31
|
"description": "Lightning Network client library",
|
|
30
32
|
"devDependencies": {
|
|
@@ -57,5 +59,5 @@
|
|
|
57
59
|
"directory": "test/typescript"
|
|
58
60
|
},
|
|
59
61
|
"types": "index.d.ts",
|
|
60
|
-
"version": "5.
|
|
62
|
+
"version": "5.6.2"
|
|
61
63
|
}
|
|
@@ -41,6 +41,32 @@ const tests = [
|
|
|
41
41
|
pub_key: 'public_key',
|
|
42
42
|
},
|
|
43
43
|
},
|
|
44
|
+
{
|
|
45
|
+
args: {
|
|
46
|
+
channel: '0x0x1',
|
|
47
|
+
channel_capacity: 1,
|
|
48
|
+
fee: 1,
|
|
49
|
+
fee_mtokens: '1000',
|
|
50
|
+
forward: '1',
|
|
51
|
+
forward_mtokens: '1000',
|
|
52
|
+
messages: [{type: '12', value: '34'}],
|
|
53
|
+
public_key: 'public_key',
|
|
54
|
+
timeout: 1,
|
|
55
|
+
},
|
|
56
|
+
description: 'Hop is mapped to RPC hop',
|
|
57
|
+
expected: {
|
|
58
|
+
amt_to_forward: '1',
|
|
59
|
+
amt_to_forward_msat: '1000',
|
|
60
|
+
chan_id: '1',
|
|
61
|
+
chan_capacity: '1',
|
|
62
|
+
custom_records: {'12': Buffer.from('34', 'hex')},
|
|
63
|
+
expiry: 1,
|
|
64
|
+
fee: '1',
|
|
65
|
+
fee_msat: '1000',
|
|
66
|
+
pub_key: 'public_key',
|
|
67
|
+
tlv_payload: true,
|
|
68
|
+
},
|
|
69
|
+
},
|
|
44
70
|
];
|
|
45
71
|
|
|
46
72
|
tests.forEach(({args, description, error, expected}) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {expectError, expectType} from 'tsd';
|
|
2
2
|
import {UnauthenticatedLnd} from '../../lnd_grpc';
|
|
3
|
-
import {createWallet} from '../../lnd_methods';
|
|
3
|
+
import {createWallet, CreateWalletResult} from '../../lnd_methods';
|
|
4
4
|
|
|
5
5
|
const lnd = {} as UnauthenticatedLnd;
|
|
6
6
|
|
|
@@ -20,8 +20,14 @@ expectError(createWallet({lnd, seed}));
|
|
|
20
20
|
expectError(createWallet({lnd, passphrase, password}));
|
|
21
21
|
expectError(createWallet({lnd, passphrase, seed}));
|
|
22
22
|
|
|
23
|
-
expectType<
|
|
24
|
-
expectType<
|
|
23
|
+
expectType<CreateWalletResult>(await createWallet({lnd, password, seed}));
|
|
24
|
+
expectType<CreateWalletResult>(
|
|
25
|
+
await createWallet({lnd, passphrase, password, seed})
|
|
26
|
+
);
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
expectType<
|
|
28
|
+
createWallet({lnd, password, seed}, (err, res) => {
|
|
29
|
+
expectType<CreateWalletResult>(res);
|
|
30
|
+
});
|
|
31
|
+
createWallet({lnd, passphrase, password, seed}, (err, res) => {
|
|
32
|
+
expectType<CreateWalletResult>(res);
|
|
33
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {expectError, expectType} from 'tsd';
|
|
2
|
+
import {AuthenticatedLnd} from '../../lnd_grpc';
|
|
3
|
+
import {partiallySignPsbt, PartiallySignPsbtResult} from '../../lnd_methods';
|
|
4
|
+
|
|
5
|
+
const lnd = {} as AuthenticatedLnd;
|
|
6
|
+
const psbt = 'psbt';
|
|
7
|
+
|
|
8
|
+
expectError(partiallySignPsbt());
|
|
9
|
+
expectError(partiallySignPsbt({}));
|
|
10
|
+
expectError(partiallySignPsbt({lnd}));
|
|
11
|
+
|
|
12
|
+
expectType<PartiallySignPsbtResult>(await partiallySignPsbt({lnd, psbt}));
|
|
13
|
+
|
|
14
|
+
expectType<void>(
|
|
15
|
+
partiallySignPsbt({lnd, psbt}, (error, result) => {
|
|
16
|
+
expectType<PartiallySignPsbtResult>(result);
|
|
17
|
+
})
|
|
18
|
+
);
|