ln-service 59.3.1 → 59.3.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Versions
2
2
 
3
- ## 59.3.1
3
+ ## 59.3.3
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"
@@ -8,29 +13,25 @@
8
13
  },
9
14
  "dependencies": {
10
15
  "bolt07": "1.9.5",
11
- "invoices": "6.1.0",
12
- "lightning": "12.2.5",
16
+ "invoices": "6.1.1",
17
+ "lightning": "12.2.7",
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.1.1",
18
- "@alexbosworth/node-fetch": "2.6.2",
22
+ "@alexbosworth/blockchain": "4.5.0",
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
33
  "psbt": "5.0.0",
31
- "rimraf": "6.1.3",
32
34
  "tiny-secp256k1": "2.2.4",
33
- "uuid": "14.0.1",
34
35
  "varuint-bitcoin": "2.0.0"
35
36
  },
36
37
  "engines": {
@@ -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.1"
64
+ "version": "59.3.3"
64
65
  }
@@ -3,20 +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
+ const {encodeBech32Address} = require('@alexbosworth/blockchain');
9
10
  const {extractTransaction} = require('psbt');
10
11
  const {finalizePsbt} = require('psbt');
12
+ const {hashForP2wpkh} = require('@alexbosworth/blockchain');
11
13
  const {idForTransaction} = require('@alexbosworth/blockchain');
12
- const {networks} = require('bitcoinjs-lib');
13
14
  const {p2msScript} = require('@alexbosworth/blockchain');
15
+ const {p2pkhOutputScript} = require('@alexbosworth/blockchain');
14
16
  const {p2wshOutputScript} = require('@alexbosworth/blockchain');
15
- const {payments} = require('bitcoinjs-lib');
16
- const {script} = require('bitcoinjs-lib');
17
+ const {sizeOfTransaction} = require('@alexbosworth/blockchain');
17
18
  const {spawnLightningCluster} = require('ln-docker-daemons');
18
19
  const tinysecp = require('tiny-secp256k1');
19
- const {Transaction} = require('bitcoinjs-lib');
20
+ const {unsignedTxFromPsbt} = require('@alexbosworth/blockchain');
20
21
  const {updatePsbt} = require('psbt');
21
22
 
22
23
  const {addPeer} = require('./../../');
@@ -36,21 +37,25 @@ const {signTransaction} = require('./../../');
36
37
  const bufferAsHex = buffer => buffer.toString('hex');
37
38
  const capacity = 1e6;
38
39
  const {ceil} = Math;
40
+ const componentsOfTx = tx => componentsOfTransaction({transaction: tx});
39
41
  const cooperativeCloseDelay = 2016;
40
42
  const family = 0;
41
43
  const feeRate = 1;
42
- const {fromHex} = Transaction;
43
44
  const fundingFee = 190; // Vsize of 2 input, 1 output tx
44
45
  const idForTx = transaction => idForTransaction({transaction}).id;
45
46
  const interval = 100;
46
47
  const keyIndex = 0;
47
48
  const network = 'regtest';
48
- const {p2pkh} = payments;
49
- const {regtest} = networks;
49
+ const p2pkh = hash => p2pkhOutputScript({hash}).script;
50
+ const p2wpkhHash = key => hashForP2wpkh({key: Buffer.from(key, 'hex')}).hash;
51
+ const prefix = 'bcrt';
50
52
  const reserveRatio = 0.01;
51
53
  const size = 2;
52
54
  const temporaryFamily = 805;
53
55
  const times = 300;
56
+ const transactionSighashAll = 1;
57
+ const unsignedTx = psbt => bufferAsHex(unsignedTxFromPsbt({psbt}).transaction);
58
+ const vsizeOfTx = transaction => sizeOfTransaction({transaction}).vsize;
54
59
 
55
60
  // Proposing a cooperative delay channel should open a cooperative delay chan
56
61
  test(`Propose a channel with a coop delay`, async () => {
@@ -103,17 +108,36 @@ test(`Propose a channel with a coop delay`, async () => {
103
108
  lnd: target.lnd,
104
109
  });
105
110
 
111
+
106
112
  // Control should fund and sign a transaction going to the control temp key
107
- const controlDerivedAddress = payments.p2wpkh({
108
- network: regtest,
109
- pubkey: Buffer.from(controlDerivedKey.public_key, 'hex'),
110
- });
113
+ const controlDerivedAddress = {
114
+ hash: p2wpkhHash(controlDerivedKey.public_key),
115
+ };
116
+
117
+ {
118
+ const {address} = encodeBech32Address({
119
+ prefix,
120
+ program: controlDerivedAddress.hash,
121
+ version: 0,
122
+ });
123
+
124
+ controlDerivedAddress.address = address;
125
+ }
111
126
 
112
127
  // Target should fund and sign a transaction going to the target temp key
113
- const targetDerivedAddress = payments.p2wpkh({
114
- network: regtest,
115
- pubkey: Buffer.from(targetDerivedKey.public_key, 'hex'),
116
- });
128
+ const targetDerivedAddress = {
129
+ hash: p2wpkhHash(targetDerivedKey.public_key),
130
+ };
131
+
132
+ {
133
+ const {address} = encodeBech32Address({
134
+ prefix,
135
+ program: targetDerivedAddress.hash,
136
+ version: 0,
137
+ });
138
+
139
+ targetDerivedAddress.address = address;
140
+ }
117
141
 
118
142
  const temporaryKeys = [controlDerivedKey, targetDerivedKey];
119
143
 
@@ -187,49 +211,31 @@ test(`Propose a channel with a coop delay`, async () => {
187
211
  ],
188
212
  });
189
213
 
190
- const controlWithoutWitnessTx = fromHex(controlSignPsbt.transaction);
191
- const targetWithoutWitnessTx = fromHex(targetSignPsbt.transaction);
192
-
193
- // Eliminate the witnesses
194
- controlWithoutWitnessTx.ins.forEach((input, index) => {
195
- return controlWithoutWitnessTx.setWitness(index, []);
196
- });
197
-
198
- targetWithoutWitnessTx.ins.forEach((input, index) => {
199
- return targetWithoutWitnessTx.setWitness(index, []);
200
- });
201
-
202
214
  // Add the spending transactions to the psbt
203
215
  const psbtWithSpending = updatePsbt({
204
216
  ecp,
205
217
  psbt: dualFundPsbt.psbt,
206
- transactions: [
207
- controlWithoutWitnessTx.toHex(),
208
- targetWithoutWitnessTx.toHex(),
209
- ],
218
+ transactions: [controlSignPsbt.transaction, targetSignPsbt.transaction],
210
219
  });
211
220
 
212
- const finalFundingPsbt = decodePsbt({ecp, psbt: dualFundPsbt.psbt});
213
-
214
- const fundingTx = fromHex(finalFundingPsbt.unsigned_transaction);
221
+ // The funding transaction is the unsigned tx of the dual funding PSBT
222
+ const fundingTransaction = unsignedTx(dualFundPsbt.psbt);
215
223
 
216
- const fundingTxId = idForTx(finalFundingPsbt.unsigned_transaction);
224
+ const fundingTx = componentsOfTx(fundingTransaction);
225
+ const fundingTxId = idForTx(fundingTransaction);
217
226
 
218
- const fundingTxVout = fundingTx.outs.findIndex(n => n.value === capacity);
219
-
220
- const controlTxHash = controlWithoutWitnessTx.getHash();
221
-
222
- const targetTxHash = targetWithoutWitnessTx.getHash();
223
-
224
- const controlVin = fundingTx.ins.findIndex(({hash}) => {
225
- return hash.equals(controlTxHash);
227
+ const fundingTxVout = fundingTx.outputs.findIndex(({tokens}) => {
228
+ return tokens === capacity;
226
229
  });
227
230
 
228
- const targetVin = fundingTx.ins.findIndex(({hash}) => {
229
- return hash.equals(targetTxHash);
230
- });
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);
231
236
 
232
- 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);
233
239
 
234
240
  // Call signTransaction on the unsigned tx that pays from temp -> multisig
235
241
  const controlSignDerivedKey = await signTransaction({
@@ -239,11 +245,11 @@ test(`Propose a channel with a coop delay`, async () => {
239
245
  key_index: controlDerivedKey.index,
240
246
  output_script: bufferAsHex(dualFundingChannelOutputScript.script),
241
247
  output_tokens: giveTokens + ceil(fundingFee / temporaryKeys.length),
242
- sighash: Transaction.SIGHASH_ALL,
248
+ sighash: transactionSighashAll,
243
249
  vin: controlVin,
244
- witness_script: p2pkh({hash: controlDerivedAddress.hash}).output,
250
+ witness_script: p2pkh(controlDerivedAddress.hash),
245
251
  }],
246
- transaction: decodePayout.unsigned_transaction,
252
+ transaction: payoutTransaction,
247
253
  });
248
254
 
249
255
  const [controlDerivedSignature] = controlSignDerivedKey.signatures;
@@ -255,9 +261,9 @@ test(`Propose a channel with a coop delay`, async () => {
255
261
  return {
256
262
  signature: Buffer.concat([
257
263
  Buffer.from(sig, 'hex'),
258
- Buffer.from([Transaction.SIGHASH_ALL]),
264
+ Buffer.from([transactionSighashAll]),
259
265
  ]).toString('hex') ,
260
- hash_type: Transaction.SIGHASH_ALL,
266
+ hash_type: transactionSighashAll,
261
267
  public_key: controlDerivedKey.public_key,
262
268
  vin: controlVin,
263
269
  };
@@ -271,15 +277,12 @@ test(`Propose a channel with a coop delay`, async () => {
271
277
  key_index: targetDerivedKey.index,
272
278
  output_script: bufferAsHex(dualFundingChannelOutputScript.script),
273
279
  output_tokens: giveTokens + ceil(fundingFee / temporaryKeys.length),
274
- sighash: Transaction.SIGHASH_ALL,
280
+ sighash: transactionSighashAll,
275
281
  vin: targetVin,
276
- witness_script: p2pkh({hash: targetDerivedAddress.hash}).output,
282
+ witness_script: p2pkh(targetDerivedAddress.hash),
277
283
  }],
278
284
  lnd: target.lnd,
279
- transaction: decodePsbt({
280
- ecp,
281
- psbt: psbtWithSpending.psbt,
282
- }).unsigned_transaction,
285
+ transaction: payoutTransaction,
283
286
  });
284
287
 
285
288
  const [targetDerivedSignature] = targetSignDerivedKey.signatures;
@@ -291,9 +294,9 @@ test(`Propose a channel with a coop delay`, async () => {
291
294
  return {
292
295
  signature: Buffer.concat([
293
296
  Buffer.from(sig, 'hex'),
294
- Buffer.from([Transaction.SIGHASH_ALL]),
297
+ Buffer.from([transactionSighashAll]),
295
298
  ]).toString('hex') ,
296
- hash_type: Transaction.SIGHASH_ALL,
299
+ hash_type: transactionSighashAll,
297
300
  public_key: targetDerivedKey.public_key,
298
301
  vin: targetVin,
299
302
  };
@@ -375,7 +378,7 @@ test(`Propose a channel with a coop delay`, async () => {
375
378
  const finalTempTx = extractTransaction({ecp, psbt: finalTempPsbt.psbt});
376
379
 
377
380
  // Calculate the size of the tx
378
- const txSize = fromHex(finalTempTx.transaction).virtualSize();
381
+ const txSize = vsizeOfTx(finalTempTx.transaction);
379
382
 
380
383
  strictEqual(txSize <= fundingFee, true, 'Transaction size is not large');
381
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,