paid-services 10.3.0 → 10.3.2

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
- ## Version 10.3.0
3
+ ## Version 10.3.2
4
4
 
5
5
  - `getOfferInvoice`: Add support for offer paths that start at the payer
6
6
  - `serviceSupportOffer`: Add support for reply paths that start at the node
package/package.json CHANGED
@@ -16,21 +16,21 @@
16
16
  "@alexbosworth/fiat": "2.0.0",
17
17
  "async": "3.2.6",
18
18
  "asyncjs-util": "1.2.12",
19
+ "bitcoinjs-lib": "6.1.7",
19
20
  "bolt01": "4.0.1",
20
21
  "bolt04": "1.3.0",
21
22
  "bolt07": "2.0.0",
22
- "ecpair": "2.1.0",
23
- "goldengate": "16.0.8",
23
+ "goldengate": "16.0.9",
24
24
  "invoices": "6.3.0",
25
- "ln-service": "60.1.4",
26
- "ln-sync": "8.0.7",
25
+ "ln-service": "60.1.6",
26
+ "ln-sync": "8.0.8",
27
27
  "psbt": "7.0.0",
28
28
  "p2tr": "3.0.0",
29
29
  "tiny-secp256k1": "2.2.4"
30
30
  },
31
31
  "description": "Lightning Paid Services library",
32
32
  "devDependencies": {
33
- "ln-docker-daemons": "8.1.1",
33
+ "ln-docker-daemons": "8.1.2",
34
34
  "mock-lnd": "4.0.0"
35
35
  },
36
36
  "engines": {
@@ -73,5 +73,5 @@
73
73
  "integration-tests": "node test/integration",
74
74
  "test": "node --experimental-test-coverage --test test/actions/*.js test/balanced/*.js test/client/*.js test/config/*.js test/network/*.js test/offers/*.js test/p2p/*.js test/records/*.js test/respond/*.js test/server/*.js test/service_records/*.js test/swaps/*.js test/services/*.js test/support/*.js test/trades/*.js"
75
75
  },
76
- "version": "10.3.0"
76
+ "version": "10.3.2"
77
77
  }
@@ -32,6 +32,7 @@ const {parsePaymentRequest} = require('ln-service');
32
32
  const {pay} = require('ln-service');
33
33
  const {payViaPaymentDetails} = require('ln-service');
34
34
  const {pointAdd} = require('tiny-secp256k1');
35
+ const {pointFromScalar} = require('tiny-secp256k1');
35
36
  const {privateAdd} = require('tiny-secp256k1');
36
37
  const {releaseSwapOutSecret} = require('goldengate');
37
38
  const {returnResult} = require('asyncjs-util');
@@ -43,7 +44,6 @@ const {subscribeToSpend} = require('goldengate');
43
44
  const {swapScriptBranches} = require('goldengate');
44
45
  const {taprootClaimTransaction} = require('goldengate');
45
46
  const {taprootCoopTransaction} = require('goldengate');
46
- const tinysecp = require('tiny-secp256k1');
47
47
  const {Transaction} = require('bitcoinjs-lib');
48
48
  const {v1OutputScript} = require('p2tr');
49
49
 
@@ -72,6 +72,7 @@ const fuzzTimelock = 1;
72
72
  const getLoopCoopSignedTransaction = asyncTimeout(getCoopSignedTx, 1000 * 30);
73
73
  const hexAsBuffer = hex => Buffer.from(hex, 'hex');
74
74
  const {isArray} = Array;
75
+ const isCompressed = true;
75
76
  const maxClaimMultiple = (r, t) => Math.min(1000, ((1000 + t) / 150) / r);
76
77
  const maxCoopMultiple = (r, t) => Math.min(1000, ((1000 + t) / 100) / r);
77
78
  const messageRejected = 'PaymentRejectedByDestination';
@@ -82,6 +83,7 @@ const pollInterval = {btcregtest: 100};
82
83
  const ppmRate = (fee, total) => fee * 1e6 / total;
83
84
  const preimageByteLength = 32;
84
85
  const pubKeyAsInternalKey = key => Buffer.from(key).slice(1).toString('hex');
86
+ const publicKeyFor = key => Buffer.from(pointFromScalar(key, isCompressed));
85
87
  const pushSecret = asyncTimeout(releaseSwapOutSecret, 1000 * 30);
86
88
  const sha256 = preimage => createHash('sha256').update(preimage).digest('hex');
87
89
  const sighash = Transaction.SIGHASH_DEFAULT;
@@ -116,9 +118,6 @@ const witnessVersionTaproot = 1;
116
118
  module.exports = (args, cbk) => {
117
119
  return new Promise((resolve, reject) => {
118
120
  return asyncAuto({
119
- // Import the ECPair library
120
- ecp: async () => (await import('ecpair')).ECPairFactory(tinysecp),
121
-
122
121
  // Check arguments
123
122
  validate: cbk => {
124
123
  if (!args.emitter) {
@@ -340,12 +339,12 @@ module.exports = (args, cbk) => {
340
339
  }],
341
340
 
342
341
  // Get the claim public key
343
- getClaimKey: ['ecp', 'requestDetails', ({ecp, requestDetails}, cbk) => {
342
+ getClaimKey: ['requestDetails', ({requestDetails}, cbk) => {
344
343
  // Exit early when a private key is defined
345
344
  if (!!requestDetails.solo_private_key) {
346
345
  const privateKey = hexAsBuffer(requestDetails.solo_private_key);
347
346
 
348
- const {publicKey} = ecp.fromPrivateKey(privateKey);
347
+ const publicKey = publicKeyFor(privateKey);
349
348
 
350
349
  return cbk(null, {public_key: bufferAsHex(publicKey)});
351
350
  }
@@ -453,14 +452,12 @@ module.exports = (args, cbk) => {
453
452
 
454
453
  // Derive the swap script branches
455
454
  branches: [
456
- 'ecp',
457
455
  'getClaimKey',
458
456
  'requestDetails',
459
457
  'responseDetails',
460
- ({ecp, getClaimKey, requestDetails, responseDetails}, cbk) =>
458
+ ({getClaimKey, requestDetails, responseDetails}, cbk) =>
461
459
  {
462
460
  const swapScript = swapScriptBranches({
463
- ecp,
464
461
  claim_public_key: getClaimKey.public_key,
465
462
  hash: sha256(hexAsBuffer(requestDetails.secret)),
466
463
  refund_public_key: responseDetails.refund_public_key,
@@ -477,12 +474,11 @@ module.exports = (args, cbk) => {
477
474
 
478
475
  // Derive the output script
479
476
  joined: [
480
- 'ecp',
481
477
  'branches',
482
478
  'getClaimKey',
483
479
  'requestDetails',
484
480
  'responseDetails',
485
- ({ecp, branches, getClaimKey, requestDetails, responseDetails}, cbk) =>
481
+ ({branches, getClaimKey, requestDetails, responseDetails}, cbk) =>
486
482
  {
487
483
  // Exit early when using MuSig2 with Lightning Loop
488
484
  if (!!args.is_loop_service) {
@@ -502,7 +498,7 @@ module.exports = (args, cbk) => {
502
498
  const privateKey = requestDetails.coop_private_key;
503
499
 
504
500
  const jointPublicKey = pointAdd(
505
- ecp.fromPrivateKey(hexAsBuffer(privateKey)).publicKey,
501
+ publicKeyFor(hexAsBuffer(privateKey)),
506
502
  hexAsBuffer(responseDetails.coop_public_key)
507
503
  );
508
504
 
@@ -551,7 +547,6 @@ module.exports = (args, cbk) => {
551
547
  payToDeposit: [
552
548
  'checkSwapId',
553
549
  'deadline',
554
- 'ecp',
555
550
  'getDepositPayment',
556
551
  'getNetwork',
557
552
  'requestDetails',
@@ -560,7 +555,6 @@ module.exports = (args, cbk) => {
560
555
  'swap',
561
556
  ({
562
557
  deadline,
563
- ecp,
564
558
  getNetwork,
565
559
  getDepositPayment,
566
560
  requestDetails,
@@ -651,7 +645,7 @@ module.exports = (args, cbk) => {
651
645
  max_fee: args.max_fee_deposit,
652
646
  messages: [{
653
647
  type: typePayMetadata,
654
- value: bufferAsHex(ecp.fromPrivateKey(privateKey).publicKey),
648
+ value: bufferAsHex(publicKeyFor(privateKey)),
655
649
  }],
656
650
  mtokens: responseDetails.deposit_mtokens,
657
651
  payment: responseDetails.deposit_payment,
@@ -762,7 +756,6 @@ module.exports = (args, cbk) => {
762
756
  'checkOutput',
763
757
  'createAddress',
764
758
  'deadline',
765
- 'ecp',
766
759
  'findOutput',
767
760
  'getFeeRate',
768
761
  'getNetwork',
@@ -771,7 +764,6 @@ module.exports = (args, cbk) => {
771
764
  ({
772
765
  createAddress,
773
766
  deadline,
774
- ecp,
775
767
  findOutput,
776
768
  getFeeRate,
777
769
  getNetwork,
@@ -801,7 +793,6 @@ module.exports = (args, cbk) => {
801
793
 
802
794
  const claims = feeRates.map(({rate, height}) => {
803
795
  const {transaction} = taprootClaimTransaction({
804
- ecp,
805
796
  block_height: height - fuzzTimelock,
806
797
  claim_script: swap.claim_script,
807
798
  external_key: swap.external_key,
@@ -895,14 +886,12 @@ module.exports = (args, cbk) => {
895
886
 
896
887
  // Push the preimage to allow for a cooperative swap
897
888
  pushPreimage: [
898
- 'ecp',
899
889
  'findOutput',
900
890
  'loopService',
901
891
  'requestDetails',
902
892
  'responseDetails',
903
893
  'signClaims',
904
894
  asyncReflect(({
905
- ecp,
906
895
  loopService,
907
896
  requestDetails,
908
897
  responseDetails,
@@ -941,7 +930,7 @@ module.exports = (args, cbk) => {
941
930
  const privateKey = requestDetails.coop_private_key;
942
931
  const to = parsePaymentRequest({request: responseDetails.request});
943
932
 
944
- const pubKey = ecp.fromPrivateKey(hexAsBuffer(privateKey)).publicKey;
933
+ const pubKey = publicKeyFor(hexAsBuffer(privateKey));
945
934
 
946
935
  const id = sha256(pubKey);
947
936
 
@@ -1024,7 +1013,6 @@ module.exports = (args, cbk) => {
1024
1013
  'branches',
1025
1014
  'createAddress',
1026
1015
  'deadline',
1027
- 'ecp',
1028
1016
  'findCoopKey',
1029
1017
  'findOutput',
1030
1018
  'getClaimKey',
@@ -1039,7 +1027,6 @@ module.exports = (args, cbk) => {
1039
1027
  branches,
1040
1028
  createAddress,
1041
1029
  deadline,
1042
- ecp,
1043
1030
  findCoopKey,
1044
1031
  findOutput,
1045
1032
  getClaimKey,
@@ -1139,24 +1126,23 @@ module.exports = (args, cbk) => {
1139
1126
 
1140
1127
  const privateKeys = privateKeysHex.map(hexAsBuffer);
1141
1128
 
1142
- const coopKey = ecp.fromPrivateKey(from(privateAdd(...privateKeys)));
1129
+ const coopKey = publicKeyFor(from(privateAdd(...privateKeys)));
1143
1130
 
1144
1131
  const coopPrivateKey = hexAsBuffer(requestDetails.coop_private_key);
1145
1132
 
1146
1133
  const jointPublicKey = pointAdd(
1147
- ecp.fromPrivateKey(coopPrivateKey).publicKey,
1134
+ publicKeyFor(coopPrivateKey),
1148
1135
  hexAsBuffer(responseDetails.coop_public_key)
1149
1136
  );
1150
1137
 
1151
1138
  // The public key from the private keys should be the combined pubkeys
1152
- if (!coopKey.publicKey.equals(jointPublicKey)) {
1139
+ if (!coopKey.equals(from(jointPublicKey))) {
1153
1140
  return cbk([503, 'ReceivedIncorrectPrivateCoopKey']);
1154
1141
  }
1155
1142
 
1156
1143
  // Derive sweep transactions at different fee rates
1157
1144
  const coop = feeRates.map(({height, rate}) => {
1158
1145
  const {transaction} = taprootCoopTransaction({
1159
- ecp,
1160
1146
  fee_tokens_per_vbyte: rate,
1161
1147
  network: getNetwork.network,
1162
1148
  output_script: swap.output_script,
@@ -22,6 +22,7 @@ const {getNetwork} = require('ln-sync');
22
22
  const {getPublicKey} = require('ln-service');
23
23
  const {hashForTree} = require('p2tr');
24
24
  const {pointAdd} = require('tiny-secp256k1');
25
+ const {pointFromScalar} = require('tiny-secp256k1');
25
26
  const {returnResult} = require('asyncjs-util');
26
27
  const {sendToChainOutputScripts} = require('ln-service');
27
28
  const {settleHodlInvoice} = require('ln-service');
@@ -32,7 +33,6 @@ const {subscribeToInvoice} = require('ln-service');
32
33
  const {subscribeToSpend} = require('goldengate');
33
34
  const {swapScriptBranches} = require('goldengate');
34
35
  const {taprootRefundTransaction} = require('goldengate');
35
- const tinysecp = require('tiny-secp256k1');
36
36
  const {Transaction} = require('bitcoinjs-lib');
37
37
  const {v1OutputScript} = require('p2tr');
38
38
 
@@ -54,12 +54,14 @@ const hexAsBase64 = hex => Buffer.from(hex, 'hex').toString('base64');
54
54
  const hexAsBuffer = hex => Buffer.from(hex, 'hex');
55
55
  const historicBlocksRange = 144 * 30;
56
56
  const isAnnex = element => element[0] === 0x50;
57
+ const isCompressed = true;
57
58
  const maxRefundMultiple = (r, t) => Math.min(100, ((1000 + t) / 150) / r);
58
59
  const {min} = Math;
59
60
  const minBlocks = 50;
60
61
  const pollInterval = {btcregtest: 100};
61
62
  const pubKeyAsInternalKey = key => Buffer.from(key).slice(1).toString('hex');
62
63
  const pubKeyAsSecret = hexPublicKey => hexPublicKey.slice(2);
64
+ const publicKeyFor = key => Buffer.from(pointFromScalar(key, isCompressed));
63
65
  const removeAnnex = stack => stack.slice(0, -1);
64
66
  const sha256 = preimage => createHash('sha256').update(preimage).digest('hex');
65
67
  const sighash = Transaction.SIGHASH_DEFAULT;
@@ -86,9 +88,6 @@ const witnessLengthTimeoutSweep = 3;
86
88
  module.exports = (args, cbk) => {
87
89
  return new Promise((resolve, reject) => {
88
90
  return asyncAuto({
89
- // Import the ECPair library
90
- ecp: async () => (await import('ecpair')).ECPairFactory(tinysecp),
91
-
92
91
  // Check arguments
93
92
  validate: cbk => {
94
93
  if (!args.emitter) {
@@ -190,16 +189,12 @@ module.exports = (args, cbk) => {
190
189
  }],
191
190
 
192
191
  // Get the refund key
193
- getRefundKey: [
194
- 'ecp',
195
- 'recoveryDetails',
196
- ({ecp, recoveryDetails}, cbk) =>
197
- {
192
+ getRefundKey: ['recoveryDetails', ({recoveryDetails}, cbk) => {
198
193
  // Exit early when a unilateral private key is defined
199
194
  if (!!recoveryDetails.solo_private_key) {
200
195
  const privateKey = hexAsBuffer(recoveryDetails.solo_private_key);
201
196
 
202
- const {publicKey} = ecp.fromPrivateKey(privateKey);
197
+ const publicKey = publicKeyFor(privateKey);
203
198
 
204
199
  return cbk(null, {public_key: bufferAsHex(publicKey)});
205
200
  }
@@ -296,21 +291,19 @@ module.exports = (args, cbk) => {
296
291
 
297
292
  // Derive swap details
298
293
  swap: [
299
- 'ecp',
300
294
  'getRefundKey',
301
295
  'recoveryDetails',
302
296
  'waitForDepositHold',
303
- ({ecp, getRefundKey, recoveryDetails, waitForDepositHold}, cbk) =>
297
+ ({getRefundKey, recoveryDetails, waitForDepositHold}, cbk) =>
304
298
  {
305
299
  const privateKey = recoveryDetails.refund_coop_private_key;
306
300
 
307
301
  const jointPublicKey = pointAdd(
308
- ecp.fromPrivateKey(hexAsBuffer(privateKey)).publicKey,
302
+ publicKeyFor(hexAsBuffer(privateKey)),
309
303
  hexAsBuffer(waitForDepositHold.claim_coop_public_key)
310
304
  );
311
305
 
312
306
  const swapScript = swapScriptBranches({
313
- ecp,
314
307
  claim_public_key: recoveryDetails.claim_solo_public_key,
315
308
  hash: recoveryDetails.hash,
316
309
  refund_public_key: getRefundKey.public_key,
@@ -335,7 +328,6 @@ module.exports = (args, cbk) => {
335
328
 
336
329
  // Generate the refund transactions against the inbound HTLC deadline
337
330
  refunds: [
338
- 'ecp',
339
331
  'getChainFee',
340
332
  'getNetwork',
341
333
  'getRefundKey',
@@ -345,7 +337,6 @@ module.exports = (args, cbk) => {
345
337
  'swap',
346
338
  'waitForFundHold',
347
339
  ({
348
- ecp,
349
340
  getChainFee,
350
341
  getNetwork,
351
342
  getRefundKey,
@@ -378,7 +369,6 @@ module.exports = (args, cbk) => {
378
369
  }
379
370
 
380
371
  return taprootRefundTransaction({
381
- ecp,
382
372
  block_height: height,
383
373
  external_key: swap.external_key,
384
374
  fee_tokens_per_vbyte: rate,
@@ -0,0 +1,26 @@
1
+ const {randomBytes} = require('crypto');
2
+
3
+ const {isPrivate} = require('tiny-secp256k1');
4
+
5
+ const bufferAsHex = buffer => buffer.toString('hex');
6
+ const privateKeyByteLength = 32;
7
+
8
+ /** Make a random private key
9
+
10
+ {}
11
+
12
+ @returns
13
+ {
14
+ private_key: <Private Key Hex String>
15
+ }
16
+ */
17
+ module.exports = ({}) => {
18
+ const key = {};
19
+
20
+ // Random bytes have a negligible chance of being outside the key range
21
+ do {
22
+ key.bytes = randomBytes(privateKeyByteLength);
23
+ } while (!isPrivate(key.bytes));
24
+
25
+ return {private_key: bufferAsHex(key.bytes)};
26
+ };
@@ -17,7 +17,6 @@ const {parsePaymentRequest} = require('ln-service');
17
17
  const {pay} = require('ln-service');
18
18
  const {returnResult} = require('asyncjs-util');
19
19
  const {swapScriptBranches} = require('goldengate');
20
- const tinysecp = require('tiny-secp256k1');
21
20
 
22
21
  const decodeLoopResponse = require('./decode_loop_response');
23
22
  const decodeOffToOnRecovery = require('./decode_off_to_on_recovery');
@@ -47,9 +46,6 @@ const timeoutHeight = current => 400 + current - 3;
47
46
  module.exports = ({before, lnd, recovery}, cbk) => {
48
47
  return new Promise((resolve, reject) => {
49
48
  return asyncAuto({
50
- // Import ECPair library
51
- ecp: async () => (await import('ecpair')).ECPairFactory(tinysecp),
52
-
53
49
  // Check arguments
54
50
  validate: cbk => {
55
51
  if (!lnd) {
@@ -197,15 +193,13 @@ module.exports = ({before, lnd, recovery}, cbk) => {
197
193
  // Derive swap script branches
198
194
  script: [
199
195
  'create',
200
- 'ecp',
201
196
  'getKey',
202
197
  'requestDetails',
203
198
  'startHeight',
204
- ({create, ecp, getKey, requestDetails, startHeight}, cbk) =>
199
+ ({create, getKey, requestDetails, startHeight}, cbk) =>
205
200
  {
206
201
  try {
207
202
  const swap = swapScriptBranches({
208
- ecp,
209
203
  claim_public_key: getKey.public_key,
210
204
  hash: requestDetails.hash,
211
205
  refund_public_key: create.service_public_key,
@@ -7,15 +7,18 @@ const {getIdentity} = require('ln-service');
7
7
  const {getNetwork} = require('ln-sync');
8
8
  const {getPublicKey} = require('ln-service');
9
9
  const {networks} = require('bitcoinjs-lib');
10
+ const {pointFromScalar} = require('tiny-secp256k1');
10
11
  const {returnResult} = require('asyncjs-util');
11
- const tinysecp = require('tiny-secp256k1');
12
12
 
13
13
  const encodeOffToOnRequest = require('./encode_off_to_on_request');
14
+ const makePrivateKey = require('./make_private_key');
14
15
 
15
16
  const bufferAsHex = buffer => buffer.toString('hex');
16
17
  const family = 805;
17
18
  const hexAsBuffer = hex => Buffer.from(hex, 'hex');
19
+ const isCompressed = true;
18
20
  const makeSecret = () => randomBytes(32);
21
+ const publicKeyFor = key => Buffer.from(pointFromScalar(key, isCompressed));
19
22
  const sha256 = preimage => createHash('sha256').update(preimage).digest('hex');
20
23
 
21
24
  /** Initialize the claim details of a swap
@@ -35,9 +38,6 @@ const sha256 = preimage => createHash('sha256').update(preimage).digest('hex');
35
38
  module.exports = (args, cbk) => {
36
39
  return new Promise((resolve, reject) => {
37
40
  return asyncAuto({
38
- // Import the ECPair library
39
- ecp: async () => (await import('ecpair')).ECPairFactory(tinysecp),
40
-
41
41
  // Check arguments
42
42
  validate: cbk => {
43
43
  if (!args.lnd) {
@@ -89,8 +89,9 @@ module.exports = (args, cbk) => {
89
89
  }],
90
90
 
91
91
  // Generate the claim coop key
92
- generateCoopKey: ['ecp', 'network', ({ecp, network}, cbk) => {
93
- const {privateKey, publicKey} = ecp.makeRandom({network});
92
+ generateCoopKey: ['network', ({}, cbk) => {
93
+ const privateKey = hexAsBuffer(makePrivateKey({}).private_key);
94
+ const publicKey = publicKeyFor(privateKey);
94
95
 
95
96
  return cbk(null, {
96
97
  hash: sha256(publicKey),
@@ -99,13 +100,14 @@ module.exports = (args, cbk) => {
99
100
  }],
100
101
 
101
102
  // Generate the claim solo key
102
- generateSoloKey: ['ecp', 'network', ({ecp, network}, cbk) => {
103
+ generateSoloKey: ['network', ({}, cbk) => {
103
104
  // Exit early when the solo key is derived from the internal seed
104
105
  if (!args.is_external_solo_key) {
105
106
  return cbk(null, {});
106
107
  }
107
108
 
108
- const {publicKey, privateKey} = ecp.makeRandom({network});
109
+ const privateKey = hexAsBuffer(makePrivateKey({}).private_key);
110
+ const publicKey = publicKeyFor(privateKey);
109
111
 
110
112
  return cbk(null, {
111
113
  pub: bufferAsHex(publicKey),
@@ -7,20 +7,24 @@ const {getHeight} = require('ln-service');
7
7
  const {getIdentity} = require('ln-service');
8
8
  const {getNetwork} = require('ln-sync');
9
9
  const {getPublicKey} = require('ln-service');
10
- const {parsePaymentRequest} = require('ln-service');
11
10
  const {networks} = require('bitcoinjs-lib');
11
+ const {parsePaymentRequest} = require('ln-service');
12
+ const {pointFromScalar} = require('tiny-secp256k1');
12
13
  const {returnResult} = require('asyncjs-util');
13
- const tinysecp = require('tiny-secp256k1');
14
14
 
15
15
  const decodeOffToOnRequest = require('./decode_off_to_on_request');
16
16
  const encodeOffToOnResponse = require('./encode_off_to_on_response');
17
+ const makePrivateKey = require('./make_private_key');
17
18
 
18
19
  const bufferAsHex = buffer => buffer.toString('hex');
19
20
  const defaultSwapExpiryMs = 1000 * 60 * 30;
20
21
  const family = 805;
22
+ const hexAsBuffer = hex => Buffer.from(hex, 'hex');
23
+ const isCompressed = true;
21
24
  const maxSwapDelta = 144 * 30;
22
25
  const minSwapDelta = 80;
23
26
  const {now} = Date;
27
+ const publicKeyFor = key => Buffer.from(pointFromScalar(key, isCompressed));
24
28
  const refundDelta = 144;
25
29
  const sha256 = preimage => createHash('sha256').update(preimage).digest('hex');
26
30
 
@@ -45,9 +49,6 @@ const sha256 = preimage => createHash('sha256').update(preimage).digest('hex');
45
49
  module.exports = (args, cbk) => {
46
50
  return new Promise((resolve, reject) => {
47
51
  return asyncAuto({
48
- // Import the ECPair library
49
- ecp: async () => (await import('ecpair')).ECPairFactory(tinysecp),
50
-
51
52
  // Check arguments
52
53
  validate: cbk => {
53
54
  if (!args.delta) {
@@ -118,8 +119,9 @@ module.exports = (args, cbk) => {
118
119
  }],
119
120
 
120
121
  // Generate the refund coop key
121
- generateCoopKey: ['ecp', 'network', ({ecp, network}, cbk) => {
122
- const {privateKey, publicKey} = ecp.makeRandom({network});
122
+ generateCoopKey: ['network', ({}, cbk) => {
123
+ const privateKey = hexAsBuffer(makePrivateKey({}).private_key);
124
+ const publicKey = publicKeyFor(privateKey);
123
125
 
124
126
  return cbk(null, {
125
127
  hash: sha256(privateKey),
@@ -129,12 +131,13 @@ module.exports = (args, cbk) => {
129
131
  }],
130
132
 
131
133
  // Generate the refund solo key
132
- generateSoloKey: ['ecp', 'network', ({ecp, network}, cbk) => {
134
+ generateSoloKey: ['network', ({}, cbk) => {
133
135
  if (!args.is_external_solo_key) {
134
136
  return cbk(null, {});
135
137
  }
136
138
 
137
- const {privateKey, publicKey} = ecp.makeRandom({network});
139
+ const privateKey = hexAsBuffer(makePrivateKey({}).private_key);
140
+ const publicKey = publicKeyFor(privateKey);
138
141
 
139
142
  return cbk(null, {
140
143
  private: bufferAsHex(privateKey),