edge-currency-plugins 2.0.4 → 2.1.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.
@@ -1,4 +1,5 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }
2
+
2
3
  var _cleaners = require('cleaners');
3
4
 
4
5
 
@@ -17,6 +18,7 @@ var _cleaners = require('cleaners');
17
18
 
18
19
 
19
20
 
21
+
20
22
  const asCurrencyFormat = _cleaners.asValue.call(void 0, 'bip32', 'bip44', 'bip49', 'bip84'); exports.asCurrencyFormat = asCurrencyFormat
21
23
 
22
24
  // Path up to changeIndex
@@ -133,7 +135,6 @@ var _cleaners = require('cleaners');
133
135
 
134
136
 
135
137
 
136
-
137
138
 
138
139
 
139
140
  const asFeeRates = _cleaners.asObject.call(void 0, {
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }var _altcoinjs = require('altcoin-js'); var bitcoin = _interopRequireWildcard(_altcoinjs);
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _altcoinjs = require('altcoin-js');
2
2
  var _cleaners = require('cleaners');
3
3
 
4
4
 
@@ -76,7 +76,7 @@ const engineInfo = {
76
76
  const coinInfo = {
77
77
  name: 'bitcoincash',
78
78
  segwit: false,
79
- sighash: bitcoin.Psbt.BCH_SIGHASH_ALL,
79
+ sighash: _altcoinjs.Psbt.BCH_SIGHASH_ALL,
80
80
  coinType: 145,
81
81
 
82
82
  prefixes: {
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }var _altcoinjs = require('altcoin-js'); var bitcoin = _interopRequireWildcard(_altcoinjs);
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _altcoinjs = require('altcoin-js');
2
2
 
3
3
 
4
4
  var _constants = require('../../constants');
@@ -55,7 +55,7 @@ const engineInfo = {
55
55
  const coinInfo = {
56
56
  name: 'bitcoincashtestnet',
57
57
  segwit: false,
58
- sighash: bitcoin.Psbt.BCH_SIGHASH_ALL,
58
+ sighash: _altcoinjs.Psbt.BCH_SIGHASH_ALL,
59
59
  coinType: 1,
60
60
 
61
61
  prefixes: {
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }var _altcoinjs = require('altcoin-js'); var bitcoin = _interopRequireWildcard(_altcoinjs);
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _altcoinjs = require('altcoin-js');
2
2
  var _cleaners = require('cleaners');
3
3
 
4
4
 
@@ -94,7 +94,7 @@ const engineInfo = {
94
94
  const coinInfo = {
95
95
  name: 'bitcoinsv',
96
96
  segwit: false,
97
- sighash: bitcoin.Psbt.BCH_SIGHASH_ALL,
97
+ sighash: _altcoinjs.Psbt.BCH_SIGHASH_ALL,
98
98
  coinType: 236,
99
99
 
100
100
  prefixes: {
@@ -1,5 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// @flow
2
- /***
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});/***
3
2
  * https://github.com/bitcoincashjs/cashaddr
4
3
  * Copyright (c) 2018 Matias Alejo Garcia
5
4
  * Copyright (c) 2017 Emilio Almansi
@@ -1,7 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// @flow
2
-
3
- // import bcoin from 'bcoin'
4
- var _buffer = require('buffer');
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _buffer = require('buffer');
5
2
 
6
3
  var _base32 = require('./base32');
7
4
  var _bn = require('./bn'); var _bn2 = _interopRequireDefault(_bn);
@@ -1,9 +1,18 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }/* eslint-disable camelcase */
2
- var _altcoinjs = require('altcoin-js'); var bitcoin = _interopRequireWildcard(_altcoinjs);
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+ var _altcoinjs = require('altcoin-js');
3
11
  var _biggystring = require('biggystring');
4
12
  var _bip32 = require('bip32'); var bip32 = _interopRequireWildcard(_bip32);
5
13
  var _bip39 = require('bip39'); var bip39 = _interopRequireWildcard(_bip39);
6
14
  var _bitcoinjsmessage = require('bitcoinjs-message'); var _bitcoinjsmessage2 = _interopRequireDefault(_bitcoinjsmessage);
15
+ var _ecpair = require('ecpair');
7
16
  var _types = require('edge-core-js/types');
8
17
 
9
18
  var _indexAtProtected = require('../../../util/indexAtProtected');
@@ -21,6 +30,20 @@ var _cashAddress = require('./bitcoincashUtils/cashAddress');
21
30
  var _coinmapper = require('./coinmapper');
22
31
  var _utxopicker = require('./utxopicker'); var utxopicker = _interopRequireWildcard(_utxopicker);
23
32
 
33
+ let ECPair
34
+
35
+ Promise.resolve().then(() => require('@bitcoin-js/tiny-secp256k1-asmjs'))
36
+ .then(tinysecp => {
37
+ _altcoinjs.initEccLib.call(void 0, tinysecp)
38
+ ECPair = _ecpair.ECPairFactory.call(void 0, tinysecp)
39
+ })
40
+ .catch(error => {
41
+ console.error(error)
42
+ })
43
+ .finally(() => {
44
+ console.log('loaded ECPair!')
45
+ })
46
+
24
47
  // in bitcoin these are bip44, bip49, bip84 xpub prefixes
25
48
  // other coins contain different formats which still need to be gathered.
26
49
  var BIP43PurposeTypeEnum; (function (BIP43PurposeTypeEnum) {
@@ -37,6 +60,7 @@ var AddressTypeEnum; (function (AddressTypeEnum) {
37
60
  const p2sh = 'p2sh'; AddressTypeEnum["p2sh"] = p2sh;
38
61
  const p2wpkh = 'p2wpkh'; AddressTypeEnum["p2wpkh"] = p2wpkh; // short bech32 address
39
62
  const p2wsh = 'p2wsh'; AddressTypeEnum["p2wsh"] = p2wsh; // long bech32 address
63
+ const p2tr = 'p2tr'; AddressTypeEnum["p2tr"] = p2tr; // bech32m address
40
64
  })(AddressTypeEnum || (exports.AddressTypeEnum = AddressTypeEnum = {}));
41
65
 
42
66
  var ScriptTypeEnum; (function (ScriptTypeEnum) {
@@ -46,6 +70,7 @@ var ScriptTypeEnum; (function (ScriptTypeEnum) {
46
70
  const p2pk = 'p2pk'; ScriptTypeEnum["p2pk"] = p2pk;
47
71
  const p2pkh = 'p2pkh'; ScriptTypeEnum["p2pkh"] = p2pkh;
48
72
  const p2sh = 'p2sh'; ScriptTypeEnum["p2sh"] = p2sh;
73
+ const p2tr = 'p2tr'; ScriptTypeEnum["p2tr"] = p2tr;
49
74
  const replayProtection = 'replayprotection'; ScriptTypeEnum["replayProtection"] = replayProtection;
50
75
  const replayProtectionP2SH = 'replayprotectionp2sh'; ScriptTypeEnum["replayProtectionP2SH"] = replayProtectionP2SH;
51
76
  })(ScriptTypeEnum || (exports.ScriptTypeEnum = ScriptTypeEnum = {}));
@@ -224,15 +249,6 @@ var VerifyAddressEnum; (function (VerifyAddressEnum) {
224
249
 
225
250
 
226
251
 
227
-
228
-
229
-
230
-
231
-
232
-
233
-
234
-
235
-
236
252
 
237
253
 
238
254
 
@@ -392,7 +408,7 @@ const xprivToXPubInternal = (
392
408
  // currently returns the derivation for an empty script template for a bitcoin cash
393
409
  // replay protection script (without key material)
394
410
  let hash = '0000'
395
- hash = bitcoin.crypto
411
+ hash = _altcoinjs.crypto
396
412
  .hash160(Buffer.from(scriptTemplate(''), 'hex'))
397
413
  .slice(0, 4)
398
414
  .toString('hex')
@@ -482,7 +498,7 @@ const addressToScriptPubkeyInternal = (
482
498
  return scriptPubkey
483
499
  }
484
500
  }
485
- payment = bitcoin.payments.p2pkh
501
+ payment = _altcoinjs.payments.p2pkh
486
502
  break
487
503
  case AddressTypeEnum.p2sh:
488
504
  if (selectedPrefixes.cashaddr != null) {
@@ -501,13 +517,16 @@ const addressToScriptPubkeyInternal = (
501
517
  return scriptPubkey
502
518
  }
503
519
  }
504
- payment = bitcoin.payments.p2sh
520
+ payment = _altcoinjs.payments.p2sh
505
521
  break
506
522
  case AddressTypeEnum.p2wpkh:
507
- payment = bitcoin.payments.p2wpkh
523
+ payment = _altcoinjs.payments.p2wpkh
508
524
  break
509
525
  case AddressTypeEnum.p2wsh:
510
- payment = bitcoin.payments.p2wsh
526
+ payment = _altcoinjs.payments.p2wsh
527
+ break
528
+ case AddressTypeEnum.p2tr:
529
+ payment = _altcoinjs.payments.p2tr
511
530
  break
512
531
  default:
513
532
  throw new Error('invalid address type in address to script pubkey')
@@ -516,7 +535,7 @@ const addressToScriptPubkeyInternal = (
516
535
  try {
517
536
  scriptPubkey = payment({
518
537
  address: args.address,
519
- network: network,
538
+ network,
520
539
  bs58DecodeFunc: coin.bs58DecodeFunc,
521
540
  bs58EncodeFunc: coin.bs58EncodeFunc
522
541
  }).output
@@ -593,7 +612,7 @@ const addressToScriptPubkeyInternal = (
593
612
  legacyPrefixes.cashaddr
594
613
  )
595
614
  }
596
- payment = bitcoin.payments.p2pkh
615
+ payment = _altcoinjs.payments.p2pkh
597
616
  break
598
617
  case AddressTypeEnum.p2sh:
599
618
  if (standardPrefixes.cashaddr != null) {
@@ -618,13 +637,16 @@ const addressToScriptPubkeyInternal = (
618
637
  legacyPrefixes.cashaddr
619
638
  )
620
639
  }
621
- payment = bitcoin.payments.p2sh
640
+ payment = _altcoinjs.payments.p2sh
622
641
  break
623
642
  case AddressTypeEnum.p2wpkh:
624
- payment = bitcoin.payments.p2wpkh
643
+ payment = _altcoinjs.payments.p2wpkh
625
644
  break
626
645
  case AddressTypeEnum.p2wsh:
627
- payment = bitcoin.payments.p2wsh
646
+ payment = _altcoinjs.payments.p2wsh
647
+ break
648
+ case AddressTypeEnum.p2tr:
649
+ payment = _altcoinjs.payments.p2tr
628
650
  break
629
651
  default:
630
652
  throw new Error('invalid address type in address to script pubkey')
@@ -634,7 +656,7 @@ const addressToScriptPubkeyInternal = (
634
656
  _nullishCoalesce(address, () => (
635
657
  payment({
636
658
  output: Buffer.from(args.scriptPubkey, 'hex'),
637
- network: network,
659
+ network,
638
660
  bs58DecodeFunc: coinClass.bs58DecodeFunc,
639
661
  bs58EncodeFunc: coinClass.bs58EncodeFunc
640
662
  }).address))
@@ -668,13 +690,16 @@ const addressToScriptPubkeyInternal = (
668
690
  let payment
669
691
  switch (args.scriptType) {
670
692
  case ScriptTypeEnum.p2pkh:
671
- payment = bitcoin.payments.p2pkh
693
+ payment = _altcoinjs.payments.p2pkh
672
694
  break
673
695
  case ScriptTypeEnum.p2sh:
674
- payment = bitcoin.payments.p2sh
696
+ payment = _altcoinjs.payments.p2sh
675
697
  break
676
698
  case ScriptTypeEnum.p2wpkh:
677
- payment = bitcoin.payments.p2wpkh
699
+ payment = _altcoinjs.payments.p2wpkh
700
+ break
701
+ case ScriptTypeEnum.p2tr:
702
+ payment = _altcoinjs.payments.p2tr
678
703
  break
679
704
  default:
680
705
  throw new Error('invalid address type in address to script pubkey')
@@ -683,7 +708,7 @@ const addressToScriptPubkeyInternal = (
683
708
  try {
684
709
  scriptHash = payment({
685
710
  output: Buffer.from(args.scriptPubkey, 'hex'),
686
- network: network
711
+ network
687
712
  }).hash
688
713
  } catch (error) {
689
714
  console.trace(error)
@@ -706,15 +731,15 @@ const addressToScriptPubkeyInternal = (
706
731
  prefixIndex: 0
707
732
  })
708
733
  }
709
- const p2sh = bitcoin.payments.p2sh({
710
- network: bip32Network,
734
+ const p2sh = _altcoinjs.payments.p2sh({
735
+ ...(bip32Network != null ? { network: bip32Network } : {}),
711
736
  redeem: {
712
737
  output: Buffer.from(scriptPubkey, 'hex')
713
738
  }
714
739
  })
715
- const scriptPubkeyFromLib = _optionalChain([p2sh, 'access', _ => _.output, 'optionalAccess', _2 => _2.toString, 'call', _3 => _3('hex')])
716
- const redeemScript = _optionalChain([p2sh, 'access', _4 => _4.redeem, 'optionalAccess', _5 => _5.output, 'optionalAccess', _6 => _6.toString, 'call', _7 => _7('hex')])
717
- const scriptHash = _optionalChain([p2sh, 'access', _8 => _8.hash, 'optionalAccess', _9 => _9.toString, 'call', _10 => _10('hex')])
740
+ const scriptPubkeyFromLib = _optionalChain([p2sh, 'access', _2 => _2.output, 'optionalAccess', _3 => _3.toString, 'call', _4 => _4('hex')])
741
+ const redeemScript = _optionalChain([p2sh, 'access', _5 => _5.redeem, 'optionalAccess', _6 => _6.output, 'optionalAccess', _7 => _7.toString, 'call', _8 => _8('hex')])
742
+ const scriptHash = _optionalChain([p2sh, 'access', _9 => _9.hash, 'optionalAccess', _10 => _10.toString, 'call', _11 => _11('hex')])
718
743
 
719
744
  if (scriptPubkeyFromLib == null || redeemScript == null) {
720
745
  throw new Error('unable to convert script to p2sh')
@@ -748,29 +773,41 @@ const addressToScriptPubkeyInternal = (
748
773
  ) {
749
774
  let payment
750
775
  switch (args.scriptType) {
751
- case ScriptTypeEnum.p2pkh:
752
- payment = bitcoin.payments.p2pkh({
776
+ case ScriptTypeEnum.p2pkh: {
777
+ payment = _altcoinjs.payments.p2pkh({
753
778
  pubkey: Buffer.from(args.pubkey, 'hex')
754
779
  })
755
780
  if (payment.output == null) {
756
781
  throw new Error('failed converting pubkey to script pubkey')
757
782
  }
758
783
  return { scriptPubkey: payment.output.toString('hex') }
759
- case ScriptTypeEnum.p2wpkhp2sh:
784
+ }
785
+ case ScriptTypeEnum.p2wpkhp2sh: {
760
786
  return scriptPubkeyToP2SH({
761
787
  scriptPubkey: pubkeyToScriptPubkey({
762
788
  pubkey: args.pubkey,
763
789
  scriptType: ScriptTypeEnum.p2wpkh
764
790
  }).scriptPubkey
765
791
  })
766
- case ScriptTypeEnum.p2wpkh:
767
- payment = bitcoin.payments.p2wpkh({
792
+ }
793
+ case ScriptTypeEnum.p2wpkh: {
794
+ payment = _altcoinjs.payments.p2wpkh({
768
795
  pubkey: Buffer.from(args.pubkey, 'hex')
769
796
  })
770
797
  if (payment.output == null) {
771
798
  throw new Error('failed converting pubkey to script pubkey')
772
799
  }
773
800
  return { scriptPubkey: payment.output.toString('hex') }
801
+ }
802
+ case ScriptTypeEnum.p2tr: {
803
+ payment = _altcoinjs.payments.p2tr({
804
+ pubkey: Buffer.from(args.pubkey, 'hex')
805
+ })
806
+ if (payment.output == null) {
807
+ throw new Error('failed converting pubkey to script pubkey')
808
+ }
809
+ return { scriptPubkey: payment.output.toString('hex') }
810
+ }
774
811
  case ScriptTypeEnum.replayProtection: {
775
812
  if (args.scriptTemplates == null)
776
813
  throw new Error('Missing replayProtection script template')
@@ -809,9 +846,9 @@ const xprivToPrivateKeyInternal = (
809
846
  const bip32FromBase58Func = _nullishCoalesce(coin.bip32FromBase58Func, () => ( bip32.fromBase58))
810
847
  const node = bip32FromBase58Func(args.xpriv, network)
811
848
  return _optionalChain([node
812
- , 'access', _11 => _11.derive, 'call', _12 => _12(args.bip44ChangeIndex)
813
- , 'access', _13 => _13.derive, 'call', _14 => _14(args.bip44AddressIndex)
814
- , 'access', _15 => _15.privateKey, 'optionalAccess', _16 => _16.toString, 'call', _17 => _17('hex')])
849
+ , 'access', _12 => _12.derive, 'call', _13 => _13(args.bip44ChangeIndex)
850
+ , 'access', _14 => _14.derive, 'call', _15 => _15(args.bip44AddressIndex)
851
+ , 'access', _16 => _16.privateKey, 'optionalAccess', _17 => _17.toString, 'call', _18 => _18('hex')])
815
852
  }
816
853
 
817
854
  const xprivToPrivateKey = (args) => {
@@ -833,7 +870,7 @@ const xprivToPrivateKeyInternal = (
833
870
  prefixIndex: 0
834
871
  })
835
872
  const coinClass = _coinmapper.getCoinFromString.call(void 0, args.coin)
836
- return bitcoin.ECPair.fromPrivateKey(Buffer.from(args.privateKey, 'hex'), {
873
+ return ECPair.fromPrivateKey(Buffer.from(args.privateKey, 'hex'), {
837
874
  network
838
875
  }).toWIF(coinClass.wifEncodeFunc)
839
876
  } exports.privateKeyToWIF = privateKeyToWIF;
@@ -848,11 +885,7 @@ const wifToPrivateKeyEncodingInternal = (
848
885
  forWIF: true,
849
886
  prefixIndex
850
887
  })
851
- const ecPair = bitcoin.ECPair.fromWIF(
852
- args.wifKey,
853
- network,
854
- coin.bs58DecodeFunc
855
- )
888
+ const ecPair = ECPair.fromWIF(args.wifKey, network, coin.bs58DecodeFunc)
856
889
  if (ecPair.privateKey == null) return
857
890
  return {
858
891
  hex: ecPair.privateKey.toString('hex'),
@@ -877,13 +910,13 @@ const wifToPrivateKeyEncodingInternal = (
877
910
  privateKeyEncoding
878
911
  ) {
879
912
  const { hex, compressed } = privateKeyEncoding
880
- return bitcoin.ECPair.fromPrivateKey(Buffer.from(hex, 'hex'), {
913
+ return ECPair.fromPrivateKey(Buffer.from(hex, 'hex'), {
881
914
  compressed
882
915
  }).publicKey.toString('hex')
883
916
  } exports.privateKeyEncodingToPubkey = privateKeyEncodingToPubkey;
884
917
 
885
918
  function signMessageBase64(message, privateKey) {
886
- const keyPair = bitcoin.ECPair.fromPrivateKey(Buffer.from(privateKey, 'hex'))
919
+ const keyPair = ECPair.fromPrivateKey(Buffer.from(privateKey, 'hex'))
887
920
  if (keyPair.privateKey == null) {
888
921
  throw new Error('Address could not sign message')
889
922
  }
@@ -900,7 +933,7 @@ const wifToPrivateKeyEncodingInternal = (
900
933
  }
901
934
 
902
935
  // get coin specific replay protection sighhash bits
903
- let sighashType = bitcoin.Transaction.SIGHASH_ALL
936
+ let sighashType = _altcoinjs.Transaction.SIGHASH_ALL
904
937
  const coin = _coinmapper.getCoinFromString.call(void 0, args.coin)
905
938
  if (coin.sighash != null) {
906
939
  sighashType = coin.sighash
@@ -991,8 +1024,8 @@ const wifToPrivateKeyEncodingInternal = (
991
1024
  if (!validatedMemo.passed) {
992
1025
  throw new Error('Memo size exceeds 80 bytes')
993
1026
  }
994
- const script = bitcoin.script
995
- .compile([bitcoin.opcodes.OP_RETURN, Buffer.from(target.memo, 'utf8')])
1027
+ const script = _altcoinjs.script
1028
+ .compile([_altcoinjs.opcodes.OP_RETURN, Buffer.from(target.memo, 'utf8')])
996
1029
  .toString('hex')
997
1030
  targets.push({
998
1031
  script,
@@ -1035,12 +1068,12 @@ const wifToPrivateKeyEncodingInternal = (
1035
1068
  }
1036
1069
  })()
1037
1070
 
1038
- const psbt = new bitcoin.Psbt()
1071
+ const psbt = new (0, _altcoinjs.Psbt)()
1039
1072
  try {
1040
1073
  psbt.addInputs(sortedInputs)
1041
1074
  psbt.addOutputs(sortedOutputs)
1042
1075
  } catch (error) {
1043
- _optionalChain([log, 'optionalAccess', _18 => _18.error, 'call', _19 => _19(`Failed makeTx: ${String(error)}`)])
1076
+ _optionalChain([log, 'optionalAccess', _19 => _19.error, 'call', _20 => _20(`Failed makeTx: ${String(error)}`)])
1044
1077
  throw error
1045
1078
  }
1046
1079
 
@@ -1050,14 +1083,20 @@ const wifToPrivateKeyEncodingInternal = (
1050
1083
  changeUsed: result.changeUsed,
1051
1084
  fee: result.fee,
1052
1085
  psbtBase64: psbt.toBase64(),
1053
- hex: _optionalChain([psbt, 'access', _20 => _20.data, 'optionalAccess', _21 => _21.globalMap, 'optionalAccess', _22 => _22.unsignedTx, 'optionalAccess', _23 => _23.toBuffer, 'call', _24 => _24(), 'optionalAccess', _25 => _25.toString, 'call', _26 => _26('hex')])
1086
+ hex: _optionalChain([psbt, 'access', _21 => _21.data, 'optionalAccess', _22 => _22.globalMap, 'optionalAccess', _23 => _23.unsignedTx, 'optionalAccess', _24 => _24.toBuffer, 'call', _25 => _25(), 'optionalAccess', _26 => _26.toString, 'call', _27 => _27('hex')])
1054
1087
  }
1055
1088
  } exports.makeTx = makeTx;
1056
1089
 
1057
1090
  async function signTx(args) {
1058
- const psbt = bitcoin.Psbt.fromBase64(args.psbtBase64)
1091
+ const psbt = _altcoinjs.Psbt.fromBase64(args.psbtBase64)
1059
1092
  const coin = _coinmapper.getCoinFromString.call(void 0, args.coin)
1060
1093
 
1094
+ const validator = (
1095
+ pubkey,
1096
+ msghash,
1097
+ signature
1098
+ ) => ECPair.fromPublicKey(pubkey).verify(msghash, signature)
1099
+
1061
1100
  for (let i = 0; i < psbt.inputCount; i++) {
1062
1101
  const privateKeyEncoding =
1063
1102
  _nullishCoalesce(args.privateKeyEncodings[i], () => (
@@ -1065,11 +1104,11 @@ const wifToPrivateKeyEncodingInternal = (
1065
1104
  const { hex, compressed } = privateKeyEncoding
1066
1105
  psbt.signInput(
1067
1106
  i,
1068
- bitcoin.ECPair.fromPrivateKey(Buffer.from(hex, 'hex'), { compressed }),
1069
- bitcoin.Psbt.DEFAULT_SIGHASHES,
1107
+ ECPair.fromPrivateKey(Buffer.from(hex, 'hex'), { compressed }),
1108
+ _altcoinjs.Psbt.DEFAULT_SIGHASHES,
1070
1109
  coin.sighashFunction
1071
1110
  )
1072
- psbt.validateSignaturesOfInput(i)
1111
+ psbt.validateSignaturesOfInput(i, validator)
1073
1112
  psbt.finalizeInput(i)
1074
1113
  }
1075
1114
  const tx = psbt.extractTransaction(true)
@@ -1225,31 +1264,38 @@ const guessAddressTypeFromAddress = (
1225
1264
  }
1226
1265
  const coinClass = _coinmapper.getCoinFromString.call(void 0, coin)
1227
1266
  try {
1228
- bitcoin.payments.p2pkh({
1267
+ _altcoinjs.payments.p2pkh({
1229
1268
  address,
1230
1269
  network,
1231
1270
  bs58DecodeFunc: coinClass.bs58DecodeFunc,
1232
1271
  bs58EncodeFunc: coinClass.bs58EncodeFunc
1233
1272
  })
1234
1273
  return AddressTypeEnum.p2pkh
1235
- } catch (e) {}
1274
+ } catch (_) {}
1236
1275
  try {
1237
- bitcoin.payments.p2sh({
1276
+ _altcoinjs.payments.p2sh({
1238
1277
  address,
1239
1278
  network,
1240
1279
  bs58DecodeFunc: coinClass.bs58DecodeFunc,
1241
1280
  bs58EncodeFunc: coinClass.bs58EncodeFunc
1242
1281
  })
1243
1282
  return AddressTypeEnum.p2sh
1244
- } catch (e) {}
1283
+ } catch (_) {}
1245
1284
  try {
1246
- bitcoin.payments.p2wsh({ address, network })
1285
+ _altcoinjs.payments.p2wsh({ address, network })
1247
1286
  return AddressTypeEnum.p2wsh
1248
- } catch (e) {}
1287
+ } catch (_) {}
1249
1288
  try {
1250
- bitcoin.payments.p2wpkh({ address, network })
1289
+ _altcoinjs.payments.p2wpkh({ address, network })
1251
1290
  return AddressTypeEnum.p2wpkh
1252
- } catch (e) {}
1291
+ } catch (_) {}
1292
+ try {
1293
+ _altcoinjs.payments.p2tr({
1294
+ address,
1295
+ network
1296
+ })
1297
+ return AddressTypeEnum.p2tr
1298
+ } catch (_) {}
1253
1299
  const cashAddrPrefixes = getCashAddrPrefixes(coinClass)
1254
1300
  if (cashAddrPrefixes.length > 0) {
1255
1301
  try {
@@ -1295,13 +1341,16 @@ const scriptHashToScriptPubkey = (
1295
1341
  let payment
1296
1342
  switch (args.scriptType) {
1297
1343
  case ScriptTypeEnum.p2pkh:
1298
- payment = bitcoin.payments.p2pkh
1344
+ payment = _altcoinjs.payments.p2pkh
1299
1345
  break
1300
1346
  case ScriptTypeEnum.p2sh:
1301
- payment = bitcoin.payments.p2sh
1347
+ payment = _altcoinjs.payments.p2sh
1302
1348
  break
1303
1349
  case ScriptTypeEnum.p2wpkh:
1304
- payment = bitcoin.payments.p2wpkh
1350
+ payment = _altcoinjs.payments.p2wpkh
1351
+ break
1352
+ case ScriptTypeEnum.p2tr:
1353
+ payment = _altcoinjs.payments.p2tr
1305
1354
  break
1306
1355
  default:
1307
1356
  throw new Error('invalid address type in address to script pubkey')
@@ -1,6 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});/* eslint-disable no-fallthrough */
2
- /* eslint-disable no-duplicate-case */
3
- var _keymanager = require('../keymanager');
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _keymanager = require('../keymanager');
4
2
 
5
3
 
6
4
  /*
@@ -1,8 +1,10 @@
1
1
  /// <reference types="node" />
2
- import { bip32 } from 'altcoin-js';
2
+ import { BaseConverter } from 'base-x';
3
+ import * as bip32 from 'bip32';
3
4
  import { Cleaner } from 'cleaners';
4
5
  import { Disklet } from 'disklet';
5
6
  import { EdgeCurrencyEngineOptions, EdgeCurrencyInfo, EdgeCurrencyTools, EdgeIo, EdgeParsedUri, EdgeWalletInfo } from 'edge-core-js/types';
7
+ import * as wif from 'wif';
6
8
  import { IProcessorTransaction, IUTXO } from '../utxobased/db/types';
7
9
  import { ScriptTemplates } from '../utxobased/info/scriptTemplates/types';
8
10
  import { UtxoPicker } from '../utxobased/keymanager/utxopicker';
@@ -53,9 +55,9 @@ export interface CoinInfo {
53
55
  sighash?: number;
54
56
  sighashFunction?: (Hash: Buffer) => Buffer;
55
57
  txHashFunction?: (Hash: Buffer) => Buffer;
56
- bs58DecodeFunc?: (payload: string | undefined) => Buffer;
57
- bs58EncodeFunc?: (payload: any) => string;
58
- wifEncodeFunc?: (prefix: unknown, key: unknown, compressed: unknown) => string;
58
+ bs58DecodeFunc?: BaseConverter['decode'];
59
+ bs58EncodeFunc?: BaseConverter['encode'];
60
+ wifEncodeFunc?: typeof wif.encode;
59
61
  bip32FromBase58Func?: (xKey: string, network: BitcoinJSNetwork) => bip32.BIP32Interface;
60
62
  bip32FromSeedFunc?: (seed: Buffer) => bip32.BIP32Interface;
61
63
  utxoPicker?: UtxoPicker;
@@ -14,7 +14,8 @@ export declare enum AddressTypeEnum {
14
14
  p2pkh = "p2pkh",
15
15
  p2sh = "p2sh",
16
16
  p2wpkh = "p2wpkh",
17
- p2wsh = "p2wsh"
17
+ p2wsh = "p2wsh",
18
+ p2tr = "p2tr"
18
19
  }
19
20
  export declare enum ScriptTypeEnum {
20
21
  p2wpkh = "p2wpkh",
@@ -23,6 +24,7 @@ export declare enum ScriptTypeEnum {
23
24
  p2pk = "p2pk",
24
25
  p2pkh = "p2pkh",
25
26
  p2sh = "p2sh",
27
+ p2tr = "p2tr",
26
28
  replayProtection = "replayprotection",
27
29
  replayProtectionP2SH = "replayprotectionp2sh"
28
30
  }
@@ -159,14 +161,6 @@ interface SignTxReturn {
159
161
  id: string;
160
162
  hex: string;
161
163
  }
162
- export interface BitcoinJSNetwork {
163
- wif: number;
164
- bip32: Bip32;
165
- messagePrefix: string;
166
- bech32: string;
167
- pubKeyHash: number;
168
- scriptHash: number;
169
- }
170
164
  export interface Bip32 {
171
165
  public: number;
172
166
  private: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "edge-currency-plugins",
3
- "version": "2.0.4",
3
+ "version": "2.1.0",
4
4
  "description": "Edge currency plugins to fetch and process wallet accounts, balances and transactions.",
5
5
  "repository": "https://github.com/EdgeApp/edge-currency-plugins",
6
6
  "license": "MIT",
@@ -33,7 +33,8 @@
33
33
  "*.{js,ts,json}": "eslint"
34
34
  },
35
35
  "dependencies": {
36
- "altcoin-js": "https://github.com/EdgeApp/altcoin-js.git#master",
36
+ "@bitcoin-js/tiny-secp256k1-asmjs": "^2.2.3",
37
+ "altcoin-js": "^1.0.0",
37
38
  "async-mutex": "^0.2.6",
38
39
  "baselet": "^0.2.4",
39
40
  "biggystring": "^4.0.0",
@@ -48,6 +49,7 @@
48
49
  "bs58smartcheck": "^2.0.4",
49
50
  "cleaners": "^0.3.12",
50
51
  "disklet": "^0.4.5",
52
+ "ecpair": "https://github.com/EdgeApp/ecpair.git#b193eb8ea2ec0c93b528f4b0223a605407ff43e4",
51
53
  "edge-sync-client": "^0.2.7",
52
54
  "memlet": "^0.1.7",
53
55
  "uri-js": "^4.4.0",
@@ -57,8 +59,10 @@
57
59
  "ws": "^7.4.6"
58
60
  },
59
61
  "devDependencies": {
62
+ "@types/base-x": "^3.0.6",
60
63
  "@types/bn.js": "^5.1.0",
61
64
  "@types/bs58": "^4.0.1",
65
+ "@types/bs58grscheck": "^2.1.0",
62
66
  "@types/chai": "^4.2.9",
63
67
  "@types/chai-as-promised": "^7.1.3",
64
68
  "@types/jsonfile": "^6.0.1",
@@ -67,9 +71,12 @@
67
71
  "@types/node-fetch": "2.x",
68
72
  "@types/request": "^2.48.7",
69
73
  "@types/url-parse": "^1.4.3",
74
+ "@types/wif": "^2.0.2",
75
+ "@types/wifgrs": "^2.0.0",
70
76
  "@types/ws": "^7.2.6",
71
77
  "@typescript-eslint/eslint-plugin": "^4.8.2",
72
78
  "@typescript-eslint/parser": "^4.8.2",
79
+ "base-x": "^4.0.0",
73
80
  "chai": "^4.2.0",
74
81
  "chai-as-promised": "^7.1.1",
75
82
  "edge-core-js": "^0.19.48",
@@ -97,6 +104,7 @@
97
104
  "request": "^2.88.2",
98
105
  "rimraf": "^3.0.2",
99
106
  "sucrase": "^3.12.1",
100
- "typescript": "^4.1.2"
107
+ "typescript": "^4.1.2",
108
+ "wif": "^2.0.6"
101
109
  }
102
110
  }
@@ -1 +0,0 @@
1
- "use strict";