ln-service 59.3.2 → 59.3.4

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,6 +1,6 @@
1
1
  # Versions
2
2
 
3
- ## 59.3.2
3
+ ## 59.3.4
4
4
 
5
5
  - `parsePaymentRequest`: Add `signet` support
6
6
 
package/package.json CHANGED
@@ -1,4 +1,9 @@
1
1
  {
2
+ "allowScripts": {
3
+ "cpu-features@0.0.10": true,
4
+ "protobufjs@7.6.5": true,
5
+ "ssh2@1.17.0": true
6
+ },
2
7
  "author": {
3
8
  "name": "Alex Bosworth",
4
9
  "url": "https://twitter.com/alexbosworth"
@@ -7,30 +12,26 @@
7
12
  "url": "https://github.com/alexbosworth/ln-service/issues"
8
13
  },
9
14
  "dependencies": {
10
- "bolt07": "1.9.5",
11
- "invoices": "6.1.0",
12
- "lightning": "12.2.6",
15
+ "bolt07": "2.0.0",
16
+ "invoices": "6.1.3",
17
+ "lightning": "12.2.8",
13
18
  "macaroon": "3.0.4"
14
19
  },
15
20
  "description": "Interaction helper for your Lightning Network daemon",
16
21
  "devDependencies": {
17
- "@alexbosworth/blockchain": "4.2.0",
18
- "@alexbosworth/node-fetch": "2.6.2",
22
+ "@alexbosworth/blockchain": "4.5.1",
19
23
  "async": "3.2.6",
20
24
  "asyncjs-util": "1.2.12",
21
25
  "bip32": "5.0.1",
22
26
  "bip66": "2.0.0",
23
- "bitcoinjs-lib": "6.1.7",
24
27
  "bn.js": "5.2.5",
25
28
  "bs58check": "4.0.0",
26
29
  "ecpair": "3.0.1",
27
- "ln-docker-daemons": "8.0.2",
28
- "p2tr": "2.0.0",
30
+ "ln-docker-daemons": "8.0.3",
31
+ "p2tr": "3.0.0",
29
32
  "portfinder": "1.0.38",
30
- "psbt": "5.0.0",
31
- "rimraf": "6.1.3",
33
+ "psbt": "6.0.0",
32
34
  "tiny-secp256k1": "2.2.4",
33
- "uuid": "14.0.2",
34
35
  "varuint-bitcoin": "2.0.0"
35
36
  },
36
37
  "engines": {
@@ -48,7 +49,7 @@
48
49
  "name": "ln-service",
49
50
  "repository": {
50
51
  "type": "git",
51
- "url": "https://github.com/alexbosworth/ln-service.git"
52
+ "url": "git+https://github.com/alexbosworth/ln-service.git"
52
53
  },
53
54
  "scripts": {
54
55
  "integration-test-0.21.2": "DOCKER_LND_VERSION=v0.21.2-beta npm run test",
@@ -60,5 +61,5 @@
60
61
  "integration-test-0.20.0": "DOCKER_LND_VERSION=v0.20.0-beta npm run test",
61
62
  "test": "echo $DOCKER_LND_VERSION && node test/runner"
62
63
  },
63
- "version": "59.3.2"
64
+ "version": "59.3.4"
64
65
  }
@@ -3,22 +3,21 @@ const {strictEqual} = require('node:assert').strict;
3
3
  const test = require('node:test');
4
4
 
5
5
  const asyncRetry = require('async/retry');
6
- const {createPsbt} = require('psbt');
7
6
  const {combinePsbts} = require('psbt');
8
- const {decodePsbt} = require('psbt');
7
+ const {componentsOfTransaction} = require('@alexbosworth/blockchain');
8
+ const {createPsbt} = require('psbt');
9
9
  const {encodeBech32Address} = require('@alexbosworth/blockchain');
10
10
  const {extractTransaction} = require('psbt');
11
11
  const {finalizePsbt} = require('psbt');
12
12
  const {hashForP2wpkh} = require('@alexbosworth/blockchain');
13
13
  const {idForTransaction} = require('@alexbosworth/blockchain');
14
- const {networks} = require('bitcoinjs-lib');
15
14
  const {p2msScript} = require('@alexbosworth/blockchain');
15
+ const {p2pkhOutputScript} = require('@alexbosworth/blockchain');
16
16
  const {p2wshOutputScript} = require('@alexbosworth/blockchain');
17
- const {payments} = require('bitcoinjs-lib');
18
- const {script} = require('bitcoinjs-lib');
17
+ const {sizeOfTransaction} = require('@alexbosworth/blockchain');
19
18
  const {spawnLightningCluster} = require('ln-docker-daemons');
20
19
  const tinysecp = require('tiny-secp256k1');
21
- const {Transaction} = require('bitcoinjs-lib');
20
+ const {unsignedTxFromPsbt} = require('@alexbosworth/blockchain');
22
21
  const {updatePsbt} = require('psbt');
23
22
 
24
23
  const {addPeer} = require('./../../');
@@ -38,22 +37,25 @@ const {signTransaction} = require('./../../');
38
37
  const bufferAsHex = buffer => buffer.toString('hex');
39
38
  const capacity = 1e6;
40
39
  const {ceil} = Math;
40
+ const componentsOfTx = tx => componentsOfTransaction({transaction: tx});
41
41
  const cooperativeCloseDelay = 2016;
42
42
  const family = 0;
43
43
  const feeRate = 1;
44
- const {fromHex} = Transaction;
45
44
  const fundingFee = 190; // Vsize of 2 input, 1 output tx
46
45
  const idForTx = transaction => idForTransaction({transaction}).id;
47
46
  const interval = 100;
48
47
  const keyIndex = 0;
49
48
  const network = 'regtest';
50
- const {p2pkh} = payments;
49
+ const p2pkh = hash => p2pkhOutputScript({hash}).script;
51
50
  const p2wpkhHash = key => hashForP2wpkh({key: Buffer.from(key, 'hex')}).hash;
52
51
  const prefix = 'bcrt';
53
52
  const reserveRatio = 0.01;
54
53
  const size = 2;
55
54
  const temporaryFamily = 805;
56
55
  const times = 300;
56
+ const transactionSighashAll = 1;
57
+ const unsignedTx = psbt => bufferAsHex(unsignedTxFromPsbt({psbt}).transaction);
58
+ const vsizeOfTx = transaction => sizeOfTransaction({transaction}).vsize;
57
59
 
58
60
  // Proposing a cooperative delay channel should open a cooperative delay chan
59
61
  test(`Propose a channel with a coop delay`, async () => {
@@ -209,49 +211,31 @@ test(`Propose a channel with a coop delay`, async () => {
209
211
  ],
210
212
  });
211
213
 
212
- const controlWithoutWitnessTx = fromHex(controlSignPsbt.transaction);
213
- const targetWithoutWitnessTx = fromHex(targetSignPsbt.transaction);
214
-
215
- // Eliminate the witnesses
216
- controlWithoutWitnessTx.ins.forEach((input, index) => {
217
- return controlWithoutWitnessTx.setWitness(index, []);
218
- });
219
-
220
- targetWithoutWitnessTx.ins.forEach((input, index) => {
221
- return targetWithoutWitnessTx.setWitness(index, []);
222
- });
223
-
224
214
  // Add the spending transactions to the psbt
225
215
  const psbtWithSpending = updatePsbt({
226
216
  ecp,
227
217
  psbt: dualFundPsbt.psbt,
228
- transactions: [
229
- controlWithoutWitnessTx.toHex(),
230
- targetWithoutWitnessTx.toHex(),
231
- ],
218
+ transactions: [controlSignPsbt.transaction, targetSignPsbt.transaction],
232
219
  });
233
220
 
234
- const finalFundingPsbt = decodePsbt({ecp, psbt: dualFundPsbt.psbt});
235
-
236
- const fundingTx = fromHex(finalFundingPsbt.unsigned_transaction);
237
-
238
- const fundingTxId = idForTx(finalFundingPsbt.unsigned_transaction);
239
-
240
- const fundingTxVout = fundingTx.outs.findIndex(n => n.value === capacity);
221
+ // The funding transaction is the unsigned tx of the dual funding PSBT
222
+ const fundingTransaction = unsignedTx(dualFundPsbt.psbt);
241
223
 
242
- const controlTxHash = controlWithoutWitnessTx.getHash();
224
+ const fundingTx = componentsOfTx(fundingTransaction);
225
+ const fundingTxId = idForTx(fundingTransaction);
243
226
 
244
- const targetTxHash = targetWithoutWitnessTx.getHash();
245
-
246
- const controlVin = fundingTx.ins.findIndex(({hash}) => {
247
- return hash.equals(controlTxHash);
227
+ const fundingTxVout = fundingTx.outputs.findIndex(({tokens}) => {
228
+ return tokens === capacity;
248
229
  });
249
230
 
250
- const targetVin = fundingTx.ins.findIndex(({hash}) => {
251
- return hash.equals(targetTxHash);
252
- });
231
+ const controlTxId = idForTx(controlSignPsbt.transaction);
232
+ const targetTxId = idForTx(targetSignPsbt.transaction);
233
+
234
+ const controlVin = fundingTx.inputs.findIndex(n => n.id === controlTxId);
235
+ const targetVin = fundingTx.inputs.findIndex(n => n.id === targetTxId);
253
236
 
254
- const decodePayout = decodePsbt({ecp, psbt: psbtWithSpending.psbt});
237
+ // The temporary funds spend is the unsigned tx of the spending PSBT
238
+ const payoutTransaction = unsignedTx(psbtWithSpending.psbt);
255
239
 
256
240
  // Call signTransaction on the unsigned tx that pays from temp -> multisig
257
241
  const controlSignDerivedKey = await signTransaction({
@@ -261,11 +245,11 @@ test(`Propose a channel with a coop delay`, async () => {
261
245
  key_index: controlDerivedKey.index,
262
246
  output_script: bufferAsHex(dualFundingChannelOutputScript.script),
263
247
  output_tokens: giveTokens + ceil(fundingFee / temporaryKeys.length),
264
- sighash: Transaction.SIGHASH_ALL,
248
+ sighash: transactionSighashAll,
265
249
  vin: controlVin,
266
- witness_script: p2pkh({hash: controlDerivedAddress.hash}).output,
250
+ witness_script: p2pkh(controlDerivedAddress.hash),
267
251
  }],
268
- transaction: decodePayout.unsigned_transaction,
252
+ transaction: payoutTransaction,
269
253
  });
270
254
 
271
255
  const [controlDerivedSignature] = controlSignDerivedKey.signatures;
@@ -277,9 +261,9 @@ test(`Propose a channel with a coop delay`, async () => {
277
261
  return {
278
262
  signature: Buffer.concat([
279
263
  Buffer.from(sig, 'hex'),
280
- Buffer.from([Transaction.SIGHASH_ALL]),
264
+ Buffer.from([transactionSighashAll]),
281
265
  ]).toString('hex') ,
282
- hash_type: Transaction.SIGHASH_ALL,
266
+ hash_type: transactionSighashAll,
283
267
  public_key: controlDerivedKey.public_key,
284
268
  vin: controlVin,
285
269
  };
@@ -293,15 +277,12 @@ test(`Propose a channel with a coop delay`, async () => {
293
277
  key_index: targetDerivedKey.index,
294
278
  output_script: bufferAsHex(dualFundingChannelOutputScript.script),
295
279
  output_tokens: giveTokens + ceil(fundingFee / temporaryKeys.length),
296
- sighash: Transaction.SIGHASH_ALL,
280
+ sighash: transactionSighashAll,
297
281
  vin: targetVin,
298
- witness_script: p2pkh({hash: targetDerivedAddress.hash}).output,
282
+ witness_script: p2pkh(targetDerivedAddress.hash),
299
283
  }],
300
284
  lnd: target.lnd,
301
- transaction: decodePsbt({
302
- ecp,
303
- psbt: psbtWithSpending.psbt,
304
- }).unsigned_transaction,
285
+ transaction: payoutTransaction,
305
286
  });
306
287
 
307
288
  const [targetDerivedSignature] = targetSignDerivedKey.signatures;
@@ -313,9 +294,9 @@ test(`Propose a channel with a coop delay`, async () => {
313
294
  return {
314
295
  signature: Buffer.concat([
315
296
  Buffer.from(sig, 'hex'),
316
- Buffer.from([Transaction.SIGHASH_ALL]),
297
+ Buffer.from([transactionSighashAll]),
317
298
  ]).toString('hex') ,
318
- hash_type: Transaction.SIGHASH_ALL,
299
+ hash_type: transactionSighashAll,
319
300
  public_key: targetDerivedKey.public_key,
320
301
  vin: targetVin,
321
302
  };
@@ -397,7 +378,7 @@ test(`Propose a channel with a coop delay`, async () => {
397
378
  const finalTempTx = extractTransaction({ecp, psbt: finalTempPsbt.psbt});
398
379
 
399
380
  // Calculate the size of the tx
400
- const txSize = fromHex(finalTempTx.transaction).virtualSize();
381
+ const txSize = vsizeOfTx(finalTempTx.transaction);
401
382
 
402
383
  strictEqual(txSize <= fundingFee, true, 'Transaction size is not large');
403
384
 
@@ -1,15 +1,7 @@
1
1
  const {promisify} = require('util');
2
2
 
3
- const chainSendTransaction = require('./chain_send_transaction');
4
- const changePassword = promisify(require('./change_password'));
5
- const connectChainNode = promisify(require('./connect_chain_node'));
6
- const createCluster = promisify(require('./create_cluster'));
7
3
  const delay = promisify(setTimeout);
8
- const generateBlocks = promisify(require('./generate_blocks'));
9
- const getRawTransaction = require('./get_raw_transaction');
10
- const mineTransaction = promisify(require('./mine_transaction'));
11
4
  const setupChannel = require('./setup_channel');
12
- const spawnLnd = promisify(require('./spawn_lnd'));
13
5
  const waitForChannel = promisify(require('./wait_for_channel'));
14
6
  const waitForPendingChannel = promisify(require('./wait_for_pending_channel'));
15
7
  const waitForRoute = promisify(require('./wait_for_route'));
@@ -17,16 +9,8 @@ const waitForTermination = promisify(require('./wait_for_termination'));
17
9
  const waitForUtxo = promisify(require('./wait_for_utxo'));
18
10
 
19
11
  module.exports = {
20
- chainSendTransaction,
21
- changePassword,
22
- connectChainNode,
23
- createCluster,
24
12
  delay,
25
- generateBlocks,
26
- getRawTransaction,
27
- mineTransaction,
28
13
  setupChannel,
29
- spawnLnd,
30
14
  waitForChannel,
31
15
  waitForPendingChannel,
32
16
  waitForRoute,