ln-service 53.9.2 → 53.9.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/README.md +2 -0
- package/package.json +3 -3
- package/test/walletrpc-integration/test_fund_psbt.js +203 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -5433,6 +5433,8 @@ const {secret} = await once(sub, 'confirmed');
|
|
|
5433
5433
|
|
|
5434
5434
|
Subscribe to successful outgoing payments
|
|
5435
5435
|
|
|
5436
|
+
Payments may be omitted if LND does not finalize the payment record
|
|
5437
|
+
|
|
5436
5438
|
Requires `offchain:read` permission
|
|
5437
5439
|
|
|
5438
5440
|
Note: Method not supported on LND 0.13.4 and below
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"cors": "2.8.5",
|
|
12
12
|
"express": "4.17.3",
|
|
13
13
|
"invoices": "2.0.4",
|
|
14
|
-
"lightning": "5.8.
|
|
14
|
+
"lightning": "5.8.2",
|
|
15
15
|
"macaroon": "3.0.4",
|
|
16
16
|
"morgan": "1.10.0",
|
|
17
17
|
"ws": "8.5.0"
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"bs58check": "2.1.2",
|
|
30
30
|
"ecpair": "2.0.1",
|
|
31
31
|
"ln-docker-daemons": "2.2.4",
|
|
32
|
-
"p2tr": "1.
|
|
32
|
+
"p2tr": "1.3.0",
|
|
33
33
|
"portfinder": "1.0.28",
|
|
34
34
|
"psbt": "2.0.0",
|
|
35
35
|
"rimraf": "3.0.2",
|
|
@@ -69,5 +69,5 @@
|
|
|
69
69
|
"integration-test-0.12.0": "DOCKER_LND_VERSION=v0.12.0-beta npm run test",
|
|
70
70
|
"test": "echo $DOCKER_LND_VERSION && tap -j 2 --branches=1 --functions=1 --lines=1 --statements=1 -t 200 test/autopilotrpc-integration/*.js test/chainrpc-integration/*.js test/integration/*.js test/invoicesrpc-integration/*.js test/routerrpc-integration/*.js test/signerrpc-integration/*.js test/tower_clientrpc-integration/*.js test/tower_serverrpc-integration/*.js test/walletrpc-integration/*.js"
|
|
71
71
|
},
|
|
72
|
-
"version": "53.9.
|
|
72
|
+
"version": "53.9.3"
|
|
73
73
|
}
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
const asyncRetry = require('async/retry');
|
|
2
2
|
const {address} = require('bitcoinjs-lib');
|
|
3
|
+
const {controlBlock} = require('p2tr');
|
|
3
4
|
const {createPsbt} = require('psbt');
|
|
4
5
|
const {decodePsbt} = require('psbt');
|
|
6
|
+
const {hashForTree} = require('p2tr');
|
|
7
|
+
const {leafHash} = require('p2tr');
|
|
5
8
|
const {networks} = require('bitcoinjs-lib');
|
|
9
|
+
const {pointAdd} = require('tiny-secp256k1');
|
|
10
|
+
const {privateAdd} = require('tiny-secp256k1');
|
|
11
|
+
const {script} = require('bitcoinjs-lib');
|
|
6
12
|
const {signHash} = require('p2tr');
|
|
13
|
+
const {signSchnorr} = require('tiny-secp256k1');
|
|
7
14
|
const {spawnLightningCluster} = require('ln-docker-daemons');
|
|
8
15
|
const {test} = require('@alexbosworth/tap');
|
|
9
16
|
const tinysecp = require('tiny-secp256k1');
|
|
@@ -20,14 +27,18 @@ const {sendToChainAddress} = require('./../../');
|
|
|
20
27
|
const {signPsbt} = require('./../../');
|
|
21
28
|
|
|
22
29
|
const chainAddressRowType = 'chain_address';
|
|
30
|
+
const {compile} = script;
|
|
23
31
|
const confirmationCount = 6;
|
|
24
32
|
const count = 100;
|
|
33
|
+
const defaultInternalKey = '0350929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0';
|
|
25
34
|
const description = 'description';
|
|
35
|
+
const {from} = Buffer;
|
|
26
36
|
const {fromBech32} = address;
|
|
27
37
|
const {fromHex} = Transaction;
|
|
28
38
|
const {fromOutputScript} = address;
|
|
29
39
|
const hexAsBuffer = hex => Buffer.from(hex, 'hex');
|
|
30
40
|
const interval = retryCount => 10 * Math.pow(2, retryCount);
|
|
41
|
+
const OP_CHECKSIG = 172;
|
|
31
42
|
const regtestBech32AddressHrp = 'bcrt';
|
|
32
43
|
const smallTokens = 2e5;
|
|
33
44
|
const times = 20;
|
|
@@ -108,7 +119,198 @@ test(`Fund PSBT`, async ({end, equal}) => {
|
|
|
108
119
|
equal(!!decodedInput.witness_utxo.script_pub, true, 'PSBT input address');
|
|
109
120
|
equal(decodedInput.witness_utxo.tokens, 5000000000, 'PSBT has input tokens');
|
|
110
121
|
|
|
111
|
-
// A Taproot
|
|
122
|
+
// A Taproot script can be funded and spent with internal key + script hash
|
|
123
|
+
try {
|
|
124
|
+
await generate({count});
|
|
125
|
+
|
|
126
|
+
const keyPair1 = ecp.makeRandom({network: networks.regtest});
|
|
127
|
+
const keyPair2 = ecp.makeRandom({network: networks.regtest});
|
|
128
|
+
const unusedKey = ecp.makeRandom({network: networks.regtest});
|
|
129
|
+
|
|
130
|
+
const witnessScript = compile([unusedKey.publicKey.slice(1), OP_CHECKSIG]);
|
|
131
|
+
|
|
132
|
+
const branches = [{script: witnessScript.toString('hex')}];
|
|
133
|
+
|
|
134
|
+
const {hash} = hashForTree({branches});
|
|
135
|
+
|
|
136
|
+
// Create a combined key using public key material
|
|
137
|
+
const combinedPoint = pointAdd(keyPair1.publicKey, keyPair2.publicKey);
|
|
138
|
+
|
|
139
|
+
const output = v1OutputScript({
|
|
140
|
+
hash,
|
|
141
|
+
internal_key: Buffer.from(combinedPoint).toString('hex'),
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const [utxo] = (await getUtxos({lnd})).utxos.reverse();
|
|
145
|
+
|
|
146
|
+
// Make a PSBT paying to the Taproot output
|
|
147
|
+
const {psbt} = createPsbt({
|
|
148
|
+
outputs: [{tokens, script: output.script}],
|
|
149
|
+
utxos: [{id: utxo.transaction_id, vout: utxo.transaction_vout}],
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
// Sign the PSBT
|
|
153
|
+
const signed = await signPsbt({
|
|
154
|
+
lnd,
|
|
155
|
+
psbt: (await fundPsbt({lnd, psbt})).psbt,
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
// Send the tx to the chain
|
|
159
|
+
await broadcastChainTransaction({lnd, transaction: signed.transaction});
|
|
160
|
+
|
|
161
|
+
// Make a new tx that will spend the output back into the wallet
|
|
162
|
+
const tx = new Transaction();
|
|
163
|
+
|
|
164
|
+
// The new tx spends the Taproot output
|
|
165
|
+
tx.addInput(
|
|
166
|
+
fromHex(signed.transaction).getHash(),
|
|
167
|
+
fromHex(signed.transaction).outs.findIndex(n => n.value === tokens)
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
// Make an output to pay back into the wallet
|
|
171
|
+
const chainOutput = toOutputScript(
|
|
172
|
+
(await createChainAddress({lnd})).address,
|
|
173
|
+
networks.regtest
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
// Add output to the pay back transaction
|
|
177
|
+
tx.addOutput(chainOutput, smallTokens);
|
|
178
|
+
|
|
179
|
+
const [hashToSign] = tx.ins.map((input, i) => {
|
|
180
|
+
return tx.hashForWitnessV1(
|
|
181
|
+
i,
|
|
182
|
+
[hexAsBuffer(output.script)],
|
|
183
|
+
[tokens],
|
|
184
|
+
Transaction.SIGHASH_DEFAULT,
|
|
185
|
+
);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// Ready for private key combining
|
|
189
|
+
const combinedKey = privateAdd(keyPair1.privateKey, keyPair2.privateKey);
|
|
190
|
+
|
|
191
|
+
const signedInput = signHash({
|
|
192
|
+
hash,
|
|
193
|
+
private_key: Buffer.from(combinedKey).toString('hex'),
|
|
194
|
+
public_key: Buffer.from(combinedPoint).toString('hex'),
|
|
195
|
+
sign_hash: hashToSign.toString('hex'),
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
const signature = hexAsBuffer(signedInput.signature);
|
|
199
|
+
|
|
200
|
+
// Add the signature to the input
|
|
201
|
+
tx.ins.forEach((input, i) => tx.setWitness(i, [signature]));
|
|
202
|
+
|
|
203
|
+
await broadcastChainTransaction({lnd, transaction: tx.toHex()});
|
|
204
|
+
|
|
205
|
+
await asyncRetry({interval, times}, async () => {
|
|
206
|
+
await generate({});
|
|
207
|
+
|
|
208
|
+
const {utxos} = await getUtxos({lnd});
|
|
209
|
+
|
|
210
|
+
const utxo = utxos.find(n => n.transaction_id === tx.getId());
|
|
211
|
+
|
|
212
|
+
if (!utxo || !utxo.confirmation_count) {
|
|
213
|
+
throw new Error('ExpectedReceivedTaprootSpend');
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
} catch (err) {
|
|
217
|
+
equal(err, null, 'Expected no error');
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// A Taproot script output should be funded and spent with script
|
|
221
|
+
try {
|
|
222
|
+
await generate({count});
|
|
223
|
+
|
|
224
|
+
const keyPair = ecp.makeRandom({network: networks.regtest});
|
|
225
|
+
|
|
226
|
+
const witnessScript = compile([keyPair.publicKey.slice(1), OP_CHECKSIG]);
|
|
227
|
+
|
|
228
|
+
const branches = [{script: witnessScript.toString('hex')}];
|
|
229
|
+
|
|
230
|
+
const {hash} = hashForTree({branches});
|
|
231
|
+
|
|
232
|
+
const output = v1OutputScript({hash, internal_key: defaultInternalKey});
|
|
233
|
+
|
|
234
|
+
const [utxo] = (await getUtxos({lnd})).utxos.reverse();
|
|
235
|
+
|
|
236
|
+
// Make a PSBT paying to the Taproot output
|
|
237
|
+
const {psbt} = createPsbt({
|
|
238
|
+
outputs: [{tokens, script: output.script}],
|
|
239
|
+
utxos: [{id: utxo.transaction_id, vout: utxo.transaction_vout}],
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
// Sign the PSBT
|
|
243
|
+
const signed = await signPsbt({
|
|
244
|
+
lnd,
|
|
245
|
+
psbt: (await fundPsbt({lnd, psbt})).psbt,
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
// Send the tx to the chain
|
|
249
|
+
await broadcastChainTransaction({lnd, transaction: signed.transaction});
|
|
250
|
+
|
|
251
|
+
// Make a new tx that will spend the output back into the wallet
|
|
252
|
+
const tx = new Transaction();
|
|
253
|
+
|
|
254
|
+
// The new tx spends the Taproot output
|
|
255
|
+
tx.addInput(
|
|
256
|
+
fromHex(signed.transaction).getHash(),
|
|
257
|
+
fromHex(signed.transaction).outs.findIndex(n => n.value === tokens)
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
// Make an output to pay back into the wallet
|
|
261
|
+
const chainOutput = toOutputScript(
|
|
262
|
+
(await createChainAddress({lnd})).address,
|
|
263
|
+
networks.regtest
|
|
264
|
+
);
|
|
265
|
+
|
|
266
|
+
// Add output to the pay back transaction
|
|
267
|
+
tx.addOutput(chainOutput, smallTokens);
|
|
268
|
+
|
|
269
|
+
const [hashToSign] = tx.ins.map((input, i) => {
|
|
270
|
+
return tx.hashForWitnessV1(
|
|
271
|
+
i,
|
|
272
|
+
[hexAsBuffer(output.script)],
|
|
273
|
+
[tokens],
|
|
274
|
+
Transaction.SIGHASH_DEFAULT,
|
|
275
|
+
hexAsBuffer(leafHash({script: witnessScript.toString('hex')}).hash),
|
|
276
|
+
);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
const signature = from(signSchnorr(hashToSign, keyPair.privateKey));
|
|
280
|
+
|
|
281
|
+
const {block} = controlBlock({
|
|
282
|
+
external_key: output.external_key,
|
|
283
|
+
leaf_script: witnessScript.toString('hex'),
|
|
284
|
+
script_branches: branches,
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
// Add the signature to the input
|
|
288
|
+
tx.ins.forEach((input, i) => {
|
|
289
|
+
return tx.setWitness(i, [
|
|
290
|
+
signature,
|
|
291
|
+
witnessScript,
|
|
292
|
+
hexAsBuffer(block),
|
|
293
|
+
]);
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
await broadcastChainTransaction({lnd, transaction: tx.toHex()});
|
|
297
|
+
|
|
298
|
+
await asyncRetry({interval, times}, async () => {
|
|
299
|
+
await generate({});
|
|
300
|
+
|
|
301
|
+
const {utxos} = await getUtxos({lnd});
|
|
302
|
+
|
|
303
|
+
const utxo = utxos.find(n => n.transaction_id === tx.getId());
|
|
304
|
+
|
|
305
|
+
if (!utxo || !utxo.confirmation_count) {
|
|
306
|
+
throw new Error('ExpectedReceivedTaprootSpend');
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
} catch (err) {
|
|
310
|
+
equal(err, null, 'Expected no error');
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// A Taproot output should be funded for a regular key spend
|
|
112
314
|
try {
|
|
113
315
|
await generate({count});
|
|
114
316
|
|