ln-service 53.7.2 → 53.7.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.
Files changed (31) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/package.json +3 -3
  3. package/test/integration/test_add_peer.js +2 -2
  4. package/test/integration/test_get_closed_channels.js +0 -2
  5. package/test/integration/test_get_invoice.js +0 -1
  6. package/test/integration/test_get_node.js +13 -1
  7. package/test/integration/test_get_peers.js +32 -21
  8. package/test/integration/test_get_wallet_info.js +6 -4
  9. package/test/integration/test_open_channels.js +2 -2
  10. package/test/integration/test_pay.js +0 -1
  11. package/test/integration/test_pay_private_invoice.js +0 -1
  12. package/test/integration/test_remove_peer.js +13 -9
  13. package/test/integration/test_send_message_to_peer.js +39 -28
  14. package/test/integration/test_subscribe_to_channels.js +0 -1
  15. package/test/integration/test_subscribe_to_invoices.js +80 -78
  16. package/test/integration/test_subscribe_to_peer_messages.js +6 -4
  17. package/test/invoicesrpc-integration/test_get_sweep_transactions.js +0 -2
  18. package/test/invoicesrpc-integration/test_subscribe_cancel_invoice.js +0 -1
  19. package/test/macros/wait_for_channel.js +1 -1
  20. package/test/routerrpc-integration/test_delete_forwarding_reputations.js +61 -27
  21. package/test/routerrpc-integration/test_get_forwarding_reputations.js +42 -14
  22. package/test/routerrpc-integration/test_get_route_through_hops.js +24 -15
  23. package/test/routerrpc-integration/test_multipath_payment.js +0 -1
  24. package/test/routerrpc-integration/test_pay_via_payment_details.js +0 -1
  25. package/test/routerrpc-integration/test_pay_via_payment_request.js +92 -80
  26. package/test/routerrpc-integration/test_probe_for_route.js +5 -5
  27. package/test/routerrpc-integration/test_subscribe_to_forward_requests.js +0 -1
  28. package/test/routerrpc-integration/test_subscribe_to_forwards.js +11 -2
  29. package/test/routerrpc-integration/test_subscribe_to_past_payments.js +0 -3
  30. package/test/tower_clientrpc-integration/test_get_connected_watchtowers.js +0 -3
  31. package/test/walletrpc-integration/test_fund_psbt.js +110 -1
@@ -1,32 +1,55 @@
1
1
  const asyncRetry = require('async/retry');
2
2
  const {address} = require('bitcoinjs-lib');
3
+ const {createPsbt} = require('psbt');
4
+ const {crypto} = require('bitcoinjs-lib');
3
5
  const {decodePsbt} = require('psbt');
6
+ const {networks} = require('bitcoinjs-lib');
7
+ const {script} = require('bitcoinjs-lib');
4
8
  const {spawnLightningCluster} = require('ln-docker-daemons');
5
9
  const {test} = require('@alexbosworth/tap');
6
10
  const tinysecp = require('tiny-secp256k1');
11
+ const {Transaction} = require('bitcoinjs-lib');
7
12
 
13
+ const {broadcastChainTransaction} = require('./../../');
8
14
  const {createChainAddress} = require('./../../');
9
15
  const {fundPsbt} = require('./../../');
10
16
  const {getChainBalance} = require('./../../');
11
17
  const {getChainTransactions} = require('./../../');
12
18
  const {getUtxos} = require('./../../');
13
19
  const {sendToChainAddress} = require('./../../');
20
+ const {signPsbt} = require('./../../');
14
21
 
15
22
  const chainAddressRowType = 'chain_address';
23
+ const {compile} = script;
16
24
  const confirmationCount = 6;
17
25
  const count = 100;
18
26
  const description = 'description';
27
+ const extra = Buffer.alloc(32);
19
28
  const {fromBech32} = address;
29
+ const {fromHex} = Transaction;
30
+ const {fromOutputScript} = address;
31
+ const hexAsBuffer = hex => Buffer.from(hex, 'hex');
20
32
  const interval = retryCount => 10 * Math.pow(2, retryCount);
33
+ const isLowPublicKey = keyPair => keyPair.publicKey[0] === 2;
34
+ const makeTaprootKey = (k, h) => tinysecp.xOnlyPointAddTweak(k, h).xOnlyPubkey;
35
+ const nLess1 = 'fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140';
36
+ const one256BitBigEndian = '0000000000000000000000000000000000000000000000000000000000000001';
37
+ const OP_1 = 81;
38
+ const {privateAdd} = tinysecp;
39
+ const {privateSub} = tinysecp;
21
40
  const regtestBech32AddressHrp = 'bcrt';
41
+ const shortKey = keyPair => keyPair.publicKey.slice(1, 33);
42
+ const {signSchnorr} = tinysecp;
43
+ const smallTokens = 2e5;
44
+ const tapHash = k => crypto.taggedHash('TapTweak', k.publicKey.slice(1, 33));
22
45
  const times = 20;
46
+ const {toOutputScript} = address;
23
47
  const tokens = 1e6;
24
48
  const txIdHexByteLength = 64;
25
49
 
26
50
  // Funding a transaction should result in a funded PSBT
27
51
  test(`Fund PSBT`, async ({end, equal}) => {
28
52
  const ecp = (await import('ecpair')).ECPairFactory(tinysecp);
29
-
30
53
  const {kill, nodes} = await spawnLightningCluster({});
31
54
 
32
55
  const [{generate, lnd}] = nodes;
@@ -97,6 +120,92 @@ test(`Fund PSBT`, async ({end, equal}) => {
97
120
  equal(!!decodedInput.witness_utxo.script_pub, true, 'PSBT input address');
98
121
  equal(decodedInput.witness_utxo.tokens, 5000000000, 'PSBT has input tokens');
99
122
 
123
+ // A Taproot output should be funded
124
+ try {
125
+ await generate({count});
126
+
127
+ const keyPair = ecp.makeRandom({network: networks.regtest});
128
+
129
+ const outputKey = makeTaprootKey(shortKey(keyPair), tapHash(keyPair));
130
+ const tweakHash = tapHash(keyPair);
131
+
132
+ const outputScript = compile([OP_1, Buffer.from(outputKey)]);
133
+
134
+ const [utxo] = (await getUtxos({lnd})).utxos.reverse();
135
+
136
+ // Make a PSBT paying to the Taproot output
137
+ const {psbt} = createPsbt({
138
+ outputs: [{tokens, script: outputScript.toString('hex')}],
139
+ utxos: [{id: utxo.transaction_id, vout: utxo.transaction_vout}],
140
+ });
141
+
142
+ // Sign the PSBT
143
+ const signed = await signPsbt({
144
+ lnd,
145
+ psbt: (await fundPsbt({lnd, psbt})).psbt,
146
+ });
147
+
148
+ // Send the tx to the chain
149
+ await broadcastChainTransaction({lnd, transaction: signed.transaction});
150
+
151
+ // Make a new tx that will spend the output back into the wallet
152
+ const tx = new Transaction();
153
+
154
+ // The new tx spends the Taproot output
155
+ tx.addInput(
156
+ fromHex(signed.transaction).getHash(),
157
+ fromHex(signed.transaction).outs.findIndex(n => n.value === tokens)
158
+ );
159
+
160
+ // Make an output to pay back into the wallet
161
+ const chainOutput = toOutputScript(
162
+ (await createChainAddress({lnd})).address,
163
+ networks.regtest
164
+ );
165
+
166
+ // Add output to the pay back transaction
167
+ tx.addOutput(chainOutput, smallTokens);
168
+
169
+ const [hashToSign] = tx.ins.map((input, i) => {
170
+ return tx.hashForWitnessV1(
171
+ i,
172
+ [outputScript],
173
+ [tokens],
174
+ Transaction.SIGHASH_DEFAULT,
175
+ );
176
+ });
177
+
178
+ const isLow = isLowPublicKey(keyPair);
179
+ const ONE = hexAsBuffer(one256BitBigEndian);
180
+ const subtract = privateSub(hexAsBuffer(nLess1), keyPair.privateKey);
181
+
182
+ const privateKey = isLow ? keyPair.privateKey : privateAdd(subtract, ONE);
183
+
184
+ // Only low keys are allowed to save a leading byte on the public key
185
+ const lowPrivateKey = privateAdd(privateKey, tweakHash);
186
+
187
+ const signature = signSchnorr(hashToSign, lowPrivateKey, extra);
188
+
189
+ // Add the signature to the input
190
+ tx.ins.forEach((input, i) => tx.setWitness(i, [Buffer.from(signature)]));
191
+
192
+ await broadcastChainTransaction({lnd, transaction: tx.toHex()});
193
+
194
+ await asyncRetry({interval, times}, async () => {
195
+ await generate({});
196
+
197
+ const {utxos} = await getUtxos({lnd});
198
+
199
+ const utxo = utxos.find(n => n.transaction_id === tx.getId());
200
+
201
+ if (!utxo || !utxo.confirmation_count) {
202
+ throw new Error('ExpectedReceivedTaprootSpend');
203
+ }
204
+ });
205
+ } catch (err) {
206
+ equal(err, null, 'Expected no error');
207
+ }
208
+
100
209
  await kill({});
101
210
 
102
211
  return end();