ln-service 56.3.1 → 56.5.0

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,5 +1,17 @@
1
1
  # Versions
2
2
 
3
+ ## 56.5.0
4
+
5
+ - `getWalletInfo`: Add support for LND 0.16.3
6
+
7
+ ## 56.4.0
8
+
9
+ - `getChannels`: Add `description` to show the channel description
10
+ - `openChannel`, `openChannels`, `proposeChannel`: Add `description` to set
11
+ the channel description
12
+ - `subscribeToChannels`: Add `description` to `channel_opened`
13
+ - `subscribeToRpcRequests`: Add `description` to `open_channel_request`
14
+
3
15
  ## 56.3.1
4
16
 
5
17
  - `subscribeToPastPayment`, `subscribeToPayViaDetails`,
package/README.md CHANGED
@@ -9,7 +9,7 @@ through npm.
9
9
 
10
10
  Supported LND versions:
11
11
 
12
- - v0.16.0-beta to v0.16.2-beta
12
+ - v0.16.0-beta to v0.16.3-beta
13
13
  - v0.15.2-beta to v0.15.5-beta
14
14
  - v0.14.4-beta to v0.14.5-beta
15
15
 
@@ -1684,6 +1684,8 @@ Requires `offchain:read` permission
1684
1684
 
1685
1685
  `is_trusted_funding` is not supported on LND 0.15.0 and below
1686
1686
 
1687
+ `description` is not supported on LND 0.16.3 and below
1688
+
1687
1689
  {
1688
1690
  [is_active]: <Limit Results To Only Active Channels Bool> // false
1689
1691
  [is_offline]: <Limit Results To Only Offline Channels Bool> // false
@@ -1701,6 +1703,7 @@ Requires `offchain:read` permission
1701
1703
  commit_transaction_weight: <Commit Transaction Weight Number>
1702
1704
  [cooperative_close_address]: <Coop Close Restricted to Address String>
1703
1705
  [cooperative_close_delay_height]: <Prevent Coop Close Until Height Number>
1706
+ [description]: <Channel Description String>
1704
1707
  id: <Standard Format Channel Id String>
1705
1708
  is_active: <Channel Active Bool>
1706
1709
  is_closing: <Channel Is Closing Bool>
@@ -3698,12 +3701,15 @@ Requires `offchain:write`, `onchain:write`, `peers:write` permissions
3698
3701
  `base_fee_mtokens` is not supported on LND 0.15.5 and below
3699
3702
  `fee_rate` is not supported on LND 0.15.5 and below
3700
3703
 
3701
- `is_max_funding` is not supported on LND 0.16.0 and below
3704
+ `is_max_funding` is not supported on LND 0.16.3 and below
3705
+
3706
+ `description` is not supported on LND 0.16.3 and below
3702
3707
 
3703
3708
  {
3704
3709
  [base_fee_mtokens]: <Routing Base Fee Millitokens Charged String>
3705
3710
  [chain_fee_tokens_per_vbyte]: <Chain Fee Tokens Per VByte Number>
3706
3711
  [cooperative_close_address]: <Restrict Cooperative Close To Address String>
3712
+ [description]: <Immutable Channel Description String>
3707
3713
  [fee_rate]: <Routing Fee Rate In Millitokens Per Million Number>
3708
3714
  [give_tokens]: <Tokens to Gift To Partner Number> // Defaults to zero
3709
3715
  [is_max_funding]: <Use Maximal Chain Funds For Local Funding Bool>
@@ -3754,11 +3760,14 @@ as well as a channel open request listener to accept the trusted funding.
3754
3760
  `base_fee_mtokens` is not supported on LND 0.15.5 and below
3755
3761
  `fee_rate` is not supported on LND 0.15.5 and below
3756
3762
 
3763
+ `description` is not supported on LND 0.16.3 and below
3764
+
3757
3765
  {
3758
3766
  channels: [{
3759
3767
  [base_fee_mtokens]: <Routing Base Fee Millitokens Charged String>
3760
3768
  capacity: <Channel Capacity Tokens Number>
3761
3769
  [cooperative_close_address]: <Restrict Coop Close To Address String>
3770
+ [description]: <Immutable Channel Description String>
3762
3771
  [fee_rate]: <Routing Fee Rate In Millitokens Per Million Number>
3763
3772
  [give_tokens]: <Tokens to Gift To Partner Number> // Defaults to zero
3764
3773
  [is_private]: <Channel is Private Bool> // Defaults to false
@@ -4384,10 +4393,13 @@ Requires `address:read`, `offchain:write`, `onchain:write` permissions
4384
4393
 
4385
4394
  Requires LND compiled with `walletrpc` build tag
4386
4395
 
4396
+ `description` is not supported on LND 0.16.3 and below
4397
+
4387
4398
  {
4388
4399
  capacity: <Channel Capacity Tokens Number>
4389
4400
  [cooperative_close_address]: <Restrict Cooperative Close To Address String>
4390
4401
  [cooperative_close_delay]: <Cooperative Close Relative Delay Number>
4402
+ [description]: <Immutable Channel Description String>
4391
4403
  [give_tokens]: <Tokens to Gift To Partner Number> // Defaults to zero
4392
4404
  id: <Pending Channel Id Hex String>
4393
4405
  [is_private]: <Channel is Private Bool> // Defaults to false
@@ -5251,6 +5263,8 @@ Requires `offchain:read` permission
5251
5263
 
5252
5264
  `is_trusted_funding`, `other_ids` are not supported on LND 0.15.0 and below
5253
5265
 
5266
+ `description` is not supported on LND 0.16.3 and below
5267
+
5254
5268
  {
5255
5269
  lnd: <Authenticated LND API Object>
5256
5270
  }
@@ -5308,6 +5322,7 @@ Requires `offchain:read` permission
5308
5322
  commit_transaction_weight: <Commit Transaction Weight Number>
5309
5323
  [cooperative_close_address]: <Coop Close Restricted to Address String>
5310
5324
  [cooperative_close_delay_height]: <Prevent Coop Close Until Height Number>
5325
+ [description]: <Channel Description String>
5311
5326
  id: <Standard Format Channel Id String>
5312
5327
  is_active: <Channel Active Bool>
5313
5328
  is_closing: <Channel Is Closing Bool>
@@ -6790,6 +6805,8 @@ LND must be running with "RPC middleware" enabled: `rpcmiddleware.enable=1`
6790
6805
 
6791
6806
  This method is not supported in LND 0.13.4 and below
6792
6807
 
6808
+ `description` is not supported on LND 0.16.3 and below
6809
+
6793
6810
  {
6794
6811
  [id]: <RPC Middleware Interception Name String>
6795
6812
  [is_intercepting_close_channel_requests]: <Intercept Channel Closes Bool>
@@ -6833,6 +6850,7 @@ This method is not supported in LND 0.13.4 and below
6833
6850
  [base_fee_mtokens]: <Routing Base Fee Millitokens Charged String>
6834
6851
  [chain_fee_tokens_per_vbyte]: <Chain Fee Tokens Per VByte Number>
6835
6852
  [cooperative_close_address]: <Prefer Cooperative Close To Address String>
6853
+ [description]: <Immutable Channel Description String>
6836
6854
  [fee_rate]: <Routing Fee Rate In Millitokens Per Million Number>
6837
6855
  [give_tokens]: <Tokens to Gift To Partner Number>
6838
6856
  [is_private]: <Channel is Private Bool>
package/package.json CHANGED
@@ -11,30 +11,31 @@
11
11
  "cors": "2.8.5",
12
12
  "express": "4.18.2",
13
13
  "invoices": "2.2.3",
14
- "lightning": "9.3.1",
14
+ "lightning": "9.5.0",
15
15
  "macaroon": "3.0.4",
16
16
  "morgan": "1.10.0",
17
17
  "ws": "8.13.0"
18
18
  },
19
19
  "description": "Interaction helper for your Lightning Network daemon",
20
20
  "devDependencies": {
21
+ "@alexbosworth/blockchain": "1.4.0",
21
22
  "@alexbosworth/tap": "15.0.12",
22
23
  "@alexbosworth/node-fetch": "2.6.2",
23
24
  "async": "3.2.4",
24
25
  "asyncjs-util": "1.2.11",
25
26
  "bip32": "4.0.0",
26
27
  "bip66": "1.1.5",
27
- "bitcoinjs-lib": "6.1.0",
28
+ "bitcoinjs-lib": "6.1.2",
28
29
  "bn.js": "5.2.1",
29
30
  "bs58check": "3.0.1",
30
31
  "ecpair": "2.1.0",
31
- "ln-docker-daemons": "5.0.3",
32
+ "ln-docker-daemons": "5.0.5",
32
33
  "p2tr": "1.3.3",
33
34
  "portfinder": "1.0.32",
34
35
  "psbt": "2.7.2",
35
- "rimraf": "5.0.0",
36
+ "rimraf": "5.0.1",
36
37
  "secp256k1": "5.0.0",
37
- "tiny-secp256k1": "2.2.1",
38
+ "tiny-secp256k1": "2.2.2",
38
39
  "uuid": "9.0.0",
39
40
  "varuint-bitcoin": "1.1.2"
40
41
  },
@@ -56,6 +57,7 @@
56
57
  "url": "https://github.com/alexbosworth/ln-service.git"
57
58
  },
58
59
  "scripts": {
60
+ "integration-test-0.16.3": "DOCKER_LND_VERSION=v0.16.3-beta npm run test",
59
61
  "integration-test-0.16.2": "DOCKER_LND_VERSION=v0.16.2-beta npm run test",
60
62
  "integration-test-0.16.1": "DOCKER_LND_VERSION=v0.16.1-beta npm run test",
61
63
  "integration-test-0.16.0": "DOCKER_LND_VERSION=v0.16.0-beta npm run test",
@@ -67,5 +69,5 @@
67
69
  "integration-test-0.14.4": "DOCKER_LND_VERSION=v0.14.4-beta npm run test",
68
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/peersrpc-integration/*.js test/routerrpc-integration/*.js test/signerrpc-integration/*.js test/tower_clientrpc-integration/*.js test/tower_serverrpc-integration/*.js test/walletrpc-integration/*.js"
69
71
  },
70
- "version": "56.3.1"
72
+ "version": "56.5.0"
71
73
  }
@@ -1,15 +1,10 @@
1
- const asyncRetry = require('async/retry');
2
- const {Block} = require('bitcoinjs-lib');
1
+ const {idForBlock} = require('@alexbosworth/blockchain');
3
2
  const {spawnLightningCluster} = require('ln-docker-daemons');
4
3
  const {test} = require('@alexbosworth/tap');
5
4
 
6
5
  const {getBlock} = require('./../../');
7
6
  const {getHeight} = require('./../../');
8
7
 
9
- const confirmationCount = 6;
10
- const {fromHex} = Block;
11
- const times = 100;
12
-
13
8
  // Get height should return height
14
9
  test(`Get height`, async ({end, equal, fail}) => {
15
10
  const {nodes} = await spawnLightningCluster({});
@@ -25,7 +20,7 @@ test(`Get height`, async ({end, equal, fail}) => {
25
20
  try {
26
21
  const {block} = await getBlock({lnd, id: blockchain.current_block_hash});
27
22
 
28
- equal(fromHex(block).getId(), hash, 'Got block');
23
+ equal(idForBlock({block}).id, hash, 'Got block');
29
24
  } catch (err) {
30
25
  const [code, message] = err;
31
26
 
@@ -40,8 +35,7 @@ test(`Get height`, async ({end, equal, fail}) => {
40
35
  // Try getting a block by the height
41
36
  try {
42
37
  const {block} = await getBlock({height, lnd});
43
-
44
- equal(fromHex(block).getId(), hash, 'Got block for height');
38
+ equal(idForBlock({block}).id, hash, 'Got block for height');
45
39
  } catch (err) {
46
40
  equal(err, null, 'Expected no error');
47
41
  }
@@ -50,7 +44,7 @@ test(`Get height`, async ({end, equal, fail}) => {
50
44
  try {
51
45
  const {block} = await getBlock({lnd});
52
46
 
53
- equal(fromHex(block).getId(), hash, 'Got chain tip block');
47
+ equal(idForBlock({block}).id, hash, 'Got chain tip block');
54
48
  } catch (err) {
55
49
  equal(err, null, 'Expected no error');
56
50
  }
@@ -2,6 +2,7 @@ const {once} = require('events');
2
2
 
3
3
  const asyncEach = require('async/each');
4
4
  const asyncRetry = require('async/retry');
5
+ const asyncTimeout = require('async/timeout');
5
6
  const {extractTransaction} = require('psbt');
6
7
  const {spawnLightningCluster} = require('ln-docker-daemons');
7
8
  const {test} = require('@alexbosworth/tap');
@@ -63,11 +64,13 @@ test(`Forfeit pending channel`, async ({end, equal, strictSame}) => {
63
64
  const channels = [{capacity, partner_public_key: target.id}];
64
65
 
65
66
  // Propose a channel to target
66
- const proposeToTarget = await asyncRetry({interval, times}, async () => {
67
- return await race([
68
- delay(timeout),
69
- openChannels({channels, lnd, is_avoiding_broadcast: true}),
70
- ]);
67
+ const proposeToTarget = await asyncRetry({interval, times}, cbk => {
68
+ return asyncTimeout(openChannels, 1000 * 10)({
69
+ channels,
70
+ lnd,
71
+ is_avoiding_broadcast: true,
72
+ },
73
+ cbk);
71
74
  });
72
75
 
73
76
  // Setup funding for the target
@@ -93,14 +96,13 @@ test(`Forfeit pending channel`, async ({end, equal, strictSame}) => {
93
96
  });
94
97
 
95
98
  // Propose a channel to remote
96
- const proposeToRemote = await asyncRetry({interval, times}, async () => {
97
- return await race([
98
- delay(timeout),
99
- openChannels({lnd,
100
- channels: [{capacity, partner_public_key: remote.id}],
101
- is_avoiding_broadcast: true,
102
- }),
103
- ]);
99
+ const proposeToRemote = await asyncRetry({interval, times}, cbk => {
100
+ return asyncTimeout(openChannels, 1000 * 10)({
101
+ lnd,
102
+ channels: [{capacity, partner_public_key: remote.id}],
103
+ is_avoiding_broadcast: true,
104
+ },
105
+ cbk);
104
106
  });
105
107
 
106
108
  // Setup funding for the remote, using the same inputs
@@ -15,6 +15,7 @@ const count = 100;
15
15
  const defaultBaseFee = '1000';
16
16
  const defaultFee = 1e3;
17
17
  const defaultVout = 0;
18
+ const description = 'description';
18
19
  const feeRate = 420;
19
20
  const giftTokens = 1000;
20
21
  const interval = 250;
@@ -36,6 +37,7 @@ test(`Open channel`, async ({end, equal}) => {
36
37
  await addPeer({lnd, public_key: target.id, socket: target.socket});
37
38
 
38
39
  return await openChannel({
40
+ description,
39
41
  lnd,
40
42
  base_fee_mtokens: baseFee,
41
43
  chain_fee_tokens_per_vbyte: defaultFee,
@@ -62,6 +64,10 @@ test(`Open channel`, async ({end, equal}) => {
62
64
  throw new Error('ExpectedChannelOpened');
63
65
  }
64
66
 
67
+ if (!!channel.description) {
68
+ equal(channel.description, description, 'Description set');
69
+ }
70
+
65
71
  const {policies} = await getChannel({lnd, id: channel.id});
66
72
 
67
73
  const policy = policies.find(n => n.public_key === id);
@@ -1,5 +1,4 @@
1
1
  const asyncRetry = require('async/retry');
2
- const {address} = require('bitcoinjs-lib');
3
2
  const {spawnLightningCluster} = require('ln-docker-daemons');
4
3
  const {test} = require('@alexbosworth/tap');
5
4
 
@@ -12,6 +12,7 @@ const {subscribeToChannels} = require('./../../');
12
12
 
13
13
  const channelCapacityTokens = 1e6;
14
14
  const defaultFee = 1e3;
15
+ const description = 'description';
15
16
  const giveTokens = 1e5;
16
17
  const interval = 100;
17
18
  const size = 2;
@@ -56,6 +57,7 @@ test('Subscribe to channels', async ({end, equal, fail}) => {
56
57
 
57
58
  // Create a channel from the control to the target node
58
59
  return await openChannel({
60
+ description,
59
61
  lnd,
60
62
  socket,
61
63
  chain_fee_tokens_per_vbyte: defaultFee,
@@ -105,6 +107,11 @@ test('Subscribe to channels', async ({end, equal, fail}) => {
105
107
  equal(openEvent.local_balance, 890950, 'Channel local balance returned');
106
108
  }
107
109
 
110
+ // LND 0.16.3 and below do not support channel descriptions
111
+ if (!!openEvent.description) {
112
+ equal(openEvent.description, description, 'Got channel open description');
113
+ }
114
+
108
115
  equal(openEvent.capacity, channelCapacityTokens, 'Channel open capacity');
109
116
  equal(!!openEvent.id, true, 'Channel id is returned');
110
117
  equal(openEvent.is_active, true, 'Channel is active');
@@ -1,5 +1,4 @@
1
1
  const asyncRetry = require('async/retry');
2
- const {Transaction} = require('bitcoinjs-lib');
3
2
 
4
3
  const {getUtxos} = require('./../../');
5
4
 
@@ -10,9 +9,8 @@ const times = 10;
10
9
 
11
10
  {
12
11
  [confirmations]: <Confirmations Count Number>
13
- [id]: <Transaction Id Hex String>
12
+ id: <Transaction Id Hex String>
14
13
  lnd: <Authenticated LND gRPC API Object>
15
- [transaction]: <Raw Transaction Hex String>
16
14
  }
17
15
 
18
16
  @returns via cbk
@@ -26,24 +24,22 @@ const times = 10;
26
24
  transaction_vout: <Transaction Output Index Number>
27
25
  }
28
26
  */
29
- module.exports = ({confirmations, id, lnd, transaction}, cbk) => {
27
+ module.exports = ({confirmations, id, lnd}, cbk) => {
30
28
  if (!lnd || !lnd.default) {
31
29
  return cbk([400, 'ExpectedAuthenticatedLndToWaitForUtxo']);
32
30
  }
33
31
 
34
- if (!transaction && !id) {
32
+ if (!id) {
35
33
  return cbk([400, 'ExpectedTransactionOrIdToWaitForUtxo']);
36
34
  }
37
35
 
38
- const txId = id || Transaction.fromHex(transaction).getId();
39
-
40
36
  return asyncRetry({interval, times}, cbk => {
41
37
  return getUtxos({lnd}, (err, res) => {
42
38
  if (!!err) {
43
39
  return cbk(err);
44
40
  }
45
41
 
46
- const utxo = res.utxos.find(n => n.transaction_id === txId);
42
+ const utxo = res.utxos.find(n => n.transaction_id === id);
47
43
 
48
44
  if (!utxo) {
49
45
  return cbk([503, 'ExpectedToFindUtxoButUtxoNotFound']);
@@ -5,7 +5,7 @@ const {createPsbt} = require('psbt');
5
5
  const {hashForTree} = require('p2tr');
6
6
  const {leafHash} = require('p2tr');
7
7
  const {networks} = require('bitcoinjs-lib');
8
- const {script} = require('bitcoinjs-lib');
8
+ const {scriptElementsAsScript} = require('@alexbosworth/blockchain');
9
9
  const {spawnLightningCluster} = require('ln-docker-daemons');
10
10
  const {test} = require('@alexbosworth/tap');
11
11
  const {Transaction} = require('bitcoinjs-lib');
@@ -21,7 +21,7 @@ const {getUtxos} = require('./../../');
21
21
  const {signPsbt} = require('./../../');
22
22
  const {updateGroupSigningSession} = require('./../../');
23
23
 
24
- const {compile} = script;
24
+ const compile = elements => scriptElementsAsScript({elements}).script;
25
25
  const count = 100;
26
26
  const defaultInternalKey = '0350929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0';
27
27
  const {from} = Buffer;
@@ -189,7 +189,7 @@ test(`Begin group signing session`, async ({end, equal}) => {
189
189
 
190
190
  const witnessScript = compile([xOnlyUnused, OP_CHECKSIG]);
191
191
 
192
- const branches = [{script: witnessScript.toString('hex')}];
192
+ const branches = [{script: witnessScript}];
193
193
 
194
194
  const {hash} = hashForTree({branches});
195
195
 
@@ -329,7 +329,7 @@ test(`Begin group signing session`, async ({end, equal}) => {
329
329
 
330
330
  const witnessScript = compile([scriptKey, OP_CHECKSIG]);
331
331
 
332
- const branches = [{script: witnessScript.toString('hex')}];
332
+ const branches = [{script: witnessScript}];
333
333
 
334
334
  const {hash} = hashForTree({branches});
335
335
 
@@ -376,7 +376,7 @@ test(`Begin group signing session`, async ({end, equal}) => {
376
376
  [hexAsBuffer(output.script)],
377
377
  [tokens],
378
378
  Transaction.SIGHASH_DEFAULT,
379
- hexAsBuffer(leafHash({script: witnessScript.toString('hex')}).hash),
379
+ hexAsBuffer(leafHash({script: witnessScript}).hash),
380
380
  );
381
381
  });
382
382
 
@@ -404,7 +404,7 @@ test(`Begin group signing session`, async ({end, equal}) => {
404
404
 
405
405
  const {block} = controlBlock({
406
406
  external_key: output.external_key,
407
- leaf_script: witnessScript.toString('hex'),
407
+ leaf_script: witnessScript,
408
408
  script_branches: branches,
409
409
  });
410
410
 
@@ -412,7 +412,7 @@ test(`Begin group signing session`, async ({end, equal}) => {
412
412
  tx.ins.forEach((input, i) => {
413
413
  return tx.setWitness(i, [
414
414
  hexAsBuffer(signature),
415
- witnessScript,
415
+ hexAsBuffer(witnessScript),
416
416
  hexAsBuffer(block),
417
417
  ]);
418
418
  });
@@ -5,6 +5,7 @@ const {createPsbt} = require('psbt');
5
5
  const {hashForTree} = require('p2tr');
6
6
  const {networks} = require('bitcoinjs-lib');
7
7
  const {script} = require('bitcoinjs-lib');
8
+ const {scriptElementsAsScript} = require('@alexbosworth/blockchain');
8
9
  const {spawnLightningCluster} = require('ln-docker-daemons');
9
10
  const {test} = require('@alexbosworth/tap');
10
11
  const tinysecp = require('tiny-secp256k1');
@@ -20,7 +21,7 @@ const {getUtxos} = require('./../../');
20
21
  const {signPsbt} = require('./../../');
21
22
  const {signTransaction} = require('./../../');
22
23
 
23
- const {compile} = script;
24
+ const compile = elements => scriptElementsAsScript({elements}).script;
24
25
  const count = 100;
25
26
  const defaultInternalKey = '0350929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0';
26
27
  const {fromHex} = Transaction;
@@ -93,7 +94,7 @@ test(`Sign a taproot transaction`, async ({end, equal}) => {
93
94
 
94
95
  const witnessScript = compile([publicKey.slice(1), OP_CHECKSIG]);
95
96
 
96
- const branches = [{script: witnessScript.toString('hex')}];
97
+ const branches = [{script: witnessScript}];
97
98
 
98
99
  const {hash} = hashForTree({branches});
99
100
 
@@ -144,7 +145,7 @@ test(`Sign a taproot transaction`, async ({end, equal}) => {
144
145
  root_hash: hash,
145
146
  sighash: Transaction.SIGHASH_DEFAULT,
146
147
  vin: 0,
147
- witness_script: witnessScript.toString('hex'),
148
+ witness_script: witnessScript,
148
149
  }],
149
150
  transaction: tx.toHex(),
150
151
  });
@@ -153,7 +154,7 @@ test(`Sign a taproot transaction`, async ({end, equal}) => {
153
154
 
154
155
  const {block} = controlBlock({
155
156
  external_key: output.external_key,
156
- leaf_script: witnessScript.toString('hex'),
157
+ leaf_script: witnessScript,
157
158
  script_branches: branches,
158
159
  });
159
160
 
@@ -161,7 +162,7 @@ test(`Sign a taproot transaction`, async ({end, equal}) => {
161
162
  tx.ins.forEach((input, i) => {
162
163
  return tx.setWitness(i, [
163
164
  signature,
164
- witnessScript,
165
+ hexAsBuffer(witnessScript),
165
166
  hexAsBuffer(block),
166
167
  ]);
167
168
  });
@@ -193,7 +194,7 @@ test(`Sign a taproot transaction`, async ({end, equal}) => {
193
194
 
194
195
  const witnessScript = compile([unusedKey.publicKey.slice(1), OP_CHECKSIG]);
195
196
 
196
- const branches = [{script: witnessScript.toString('hex')}];
197
+ const branches = [{script: witnessScript}];
197
198
 
198
199
  const {hash} = hashForTree({branches});
199
200
 
@@ -8,7 +8,7 @@ const {leafHash} = require('p2tr');
8
8
  const {networks} = require('bitcoinjs-lib');
9
9
  const {pointAdd} = require('tiny-secp256k1');
10
10
  const {privateAdd} = require('tiny-secp256k1');
11
- const {script} = require('bitcoinjs-lib');
11
+ const {scriptElementsAsScript} = require('@alexbosworth/blockchain');
12
12
  const {signHash} = require('p2tr');
13
13
  const {signSchnorr} = require('tiny-secp256k1');
14
14
  const {spawnLightningCluster} = require('ln-docker-daemons');
@@ -27,7 +27,7 @@ const {sendToChainAddress} = require('./../../');
27
27
  const {signPsbt} = require('./../../');
28
28
 
29
29
  const chainAddressRowType = 'chain_address';
30
- const {compile} = script;
30
+ const compile = elements => scriptElementsAsScript({elements}).script;
31
31
  const confirmationCount = 6;
32
32
  const count = 100;
33
33
  const defaultInternalKey = '0350929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0';
@@ -135,7 +135,7 @@ test(`Fund PSBT`, async ({end, equal}) => {
135
135
 
136
136
  const witnessScript = compile([unusedKey.publicKey.slice(1), OP_CHECKSIG]);
137
137
 
138
- const branches = [{script: witnessScript.toString('hex')}];
138
+ const branches = [{script: witnessScript}];
139
139
 
140
140
  const {hash} = hashForTree({branches});
141
141
 
@@ -231,7 +231,7 @@ test(`Fund PSBT`, async ({end, equal}) => {
231
231
 
232
232
  const witnessScript = compile([keyPair.publicKey.slice(1), OP_CHECKSIG]);
233
233
 
234
- const branches = [{script: witnessScript.toString('hex')}];
234
+ const branches = [{script: witnessScript}];
235
235
 
236
236
  const {hash} = hashForTree({branches});
237
237
 
@@ -278,7 +278,7 @@ test(`Fund PSBT`, async ({end, equal}) => {
278
278
  [hexAsBuffer(output.script)],
279
279
  [tokens],
280
280
  Transaction.SIGHASH_DEFAULT,
281
- hexAsBuffer(leafHash({script: witnessScript.toString('hex')}).hash),
281
+ hexAsBuffer(leafHash({script: witnessScript}).hash),
282
282
  );
283
283
  });
284
284
 
@@ -286,7 +286,7 @@ test(`Fund PSBT`, async ({end, equal}) => {
286
286
 
287
287
  const {block} = controlBlock({
288
288
  external_key: output.external_key,
289
- leaf_script: witnessScript.toString('hex'),
289
+ leaf_script: witnessScript,
290
290
  script_branches: branches,
291
291
  });
292
292
 
@@ -294,7 +294,7 @@ test(`Fund PSBT`, async ({end, equal}) => {
294
294
  tx.ins.forEach((input, i) => {
295
295
  return tx.setWitness(i, [
296
296
  signature,
297
- witnessScript,
297
+ hexAsBuffer(witnessScript),
298
298
  hexAsBuffer(block),
299
299
  ]);
300
300
  });
@@ -1,18 +1,16 @@
1
1
  const asyncRetry = require('async/retry');
2
- const {script} = require('bitcoinjs-lib');
2
+ const {componentsOfTransaction} = require('@alexbosworth/blockchain');
3
+ const {scriptElementsAsScript} = require('@alexbosworth/blockchain');
3
4
  const {spawnLightningCluster} = require('ln-docker-daemons');
4
5
  const {test} = require('@alexbosworth/tap');
5
- const {Transaction} = require('bitcoinjs-lib');
6
6
 
7
7
  const {getChainTransactions} = require('./../../');
8
8
  const {sendToChainOutputScripts} = require('./../../');
9
9
 
10
10
  const asBuf = hex => Buffer.from(hex, 'hex');
11
11
  const asHex = buffer => buffer.toString('hex');
12
- const {compile} = script;
13
12
  const confirmationCount = 6;
14
13
  const count = 100;
15
- const {fromHex} = Transaction;
16
14
  const interval = 10;
17
15
  const OP_RETURN = 0x6a;
18
16
  const size = 2;
@@ -27,15 +25,16 @@ test(`Send to chain output scripts`, async ({end, equal, strictSame}) => {
27
25
 
28
26
  await generate({count});
29
27
 
30
- const script = [].concat(OP_RETURN).concat(asBuf(target.id));
28
+ const elements = [].concat(OP_RETURN).concat(asBuf(target.id));
31
29
 
32
- const sendTo = [{tokens, script: asHex(compile(script))}];
30
+ const {script} = scriptElementsAsScript({elements});
31
+
32
+ const sendTo = [{script, tokens}];
33
33
 
34
34
  const sent = await sendToChainOutputScripts({lnd, send_to: sendTo});
35
35
 
36
- const outs = fromHex(sent.transaction).outs
37
- .filter(n => n.value === tokens)
38
- .map(({script, value}) => ({script: asHex(script), tokens: value}));
36
+ const outs = componentsOfTransaction({transaction: sent.transaction}).outputs
37
+ .filter(n => n.tokens === tokens);
39
38
 
40
39
  // The OP_RETURN is present in the output
41
40
  strictSame(outs, sendTo, 'Got expected outputs');
@@ -1,10 +1,9 @@
1
1
  const asyncRetry = require('async/retry');
2
- const {address} = require('bitcoinjs-lib');
2
+ const {componentsOfTransaction} = require('@alexbosworth/blockchain');
3
3
  const {decodePsbt} = require('psbt');
4
4
  const {spawnLightningCluster} = require('ln-docker-daemons');
5
5
  const {test} = require('@alexbosworth/tap');
6
6
  const tinysecp = require('tiny-secp256k1');
7
- const {Transaction} = require('bitcoinjs-lib');
8
7
 
9
8
  const {broadcastChainTransaction} = require('./../../');
10
9
  const {createChainAddress} = require('./../../');
@@ -19,7 +18,6 @@ const confirmationCount = 6;
19
18
  const count = 100;
20
19
  const description = 'description';
21
20
  const format = 'p2wpkh';
22
- const {fromBech32} = address;
23
21
  const interval = 10;
24
22
  const regtestBech32AddressHrp = 'bcrt';
25
23
  const size = 2;
@@ -72,7 +70,7 @@ test(`Sign PSBT`, async ({end, equal}) => {
72
70
 
73
71
  const finalized = await signPsbt({lnd: control.lnd, psbt: funded.psbt});
74
72
 
75
- const tx = Transaction.fromHex(finalized.transaction);
73
+ const tx = componentsOfTransaction({transaction: finalized.transaction});
76
74
 
77
75
  const decoded = decodePsbt({ecp, psbt: finalized.psbt});
78
76