edge-currency-plugins 2.0.4 → 2.2.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/lib/common/plugin/makeCurrencyTools.js +0 -5
- package/lib/common/plugin/types.js +3 -2
- package/lib/common/upgradeMemos.js +47 -0
- package/lib/common/utxobased/db/Models/ProcessorTransaction.js +7 -4
- package/lib/common/utxobased/engine/makeUtxoEngine.js +18 -18
- package/lib/common/utxobased/engine/utils.js +0 -13
- package/lib/common/utxobased/info/badcoin.js +6 -2
- package/lib/common/utxobased/info/bitcoin.js +6 -2
- package/lib/common/utxobased/info/bitcoincash.js +8 -4
- package/lib/common/utxobased/info/bitcoincashtestnet.js +8 -4
- package/lib/common/utxobased/info/bitcoingold.js +6 -2
- package/lib/common/utxobased/info/bitcoingoldtestnet.js +6 -2
- package/lib/common/utxobased/info/bitcoinsv.js +9 -5
- package/lib/common/utxobased/info/bitcointestnet.js +6 -2
- package/lib/common/utxobased/info/commonInfo.js +16 -0
- package/lib/common/utxobased/info/dash.js +7 -2
- package/lib/common/utxobased/info/digibyte.js +6 -2
- package/lib/common/utxobased/info/dogecoin.js +6 -2
- package/lib/common/utxobased/info/eboost.js +6 -2
- package/lib/common/utxobased/info/feathercoin.js +6 -2
- package/lib/common/utxobased/info/groestlcoin.js +6 -2
- package/lib/common/utxobased/info/litecoin.js +6 -2
- package/lib/common/utxobased/info/qtum.js +6 -2
- package/lib/common/utxobased/info/ravencoin.js +6 -2
- package/lib/common/utxobased/info/smartcash.js +6 -2
- package/lib/common/utxobased/info/ufo.js +6 -2
- package/lib/common/utxobased/info/vertcoin.js +6 -2
- package/lib/common/utxobased/info/zcoin.js +6 -2
- package/lib/common/utxobased/keymanager/bitcoincashUtils/base32.js +1 -2
- package/lib/common/utxobased/keymanager/bitcoincashUtils/cashAddress.js +1 -4
- package/lib/common/utxobased/keymanager/declarations/bs58smartcheck.d.js +4 -0
- package/lib/common/utxobased/keymanager/declarations/wif-smart.d.js +24 -0
- package/lib/common/utxobased/keymanager/keymanager.js +129 -84
- package/lib/common/utxobased/keymanager/utxopicker/utils.js +1 -3
- package/lib/common/validateMemos.js +107 -0
- package/lib/src/common/plugin/types.d.ts +6 -4
- package/lib/src/common/upgradeMemos.d.ts +6 -0
- package/lib/src/common/utxobased/engine/utils.d.ts +1 -2
- package/lib/src/common/utxobased/info/commonInfo.d.ts +2 -0
- package/lib/src/common/utxobased/keymanager/keymanager.d.ts +5 -11
- package/lib/src/common/validateMemos.d.ts +6 -0
- package/lib/src/util/cleaners.d.ts +6 -0
- package/lib/util/cleaners.js +18 -0
- package/package.json +12 -4
- package/lib/common/utxobased/keymanager/declarations/base58grscheck.d.js +0 -1
- package/lib/common/utxobased/keymanager/declarations/wifgrs.d.js +0 -1
|
@@ -1,16 +1,24 @@
|
|
|
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
|
-
|
|
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');
|
|
10
19
|
var _undefinedIfEmptyString = require('../../../util/undefinedIfEmptyString');
|
|
11
20
|
|
|
12
21
|
|
|
13
|
-
var _utils = require('../engine/utils');
|
|
14
22
|
|
|
15
23
|
var _bip69 = require('./bip69');
|
|
16
24
|
|
|
@@ -21,6 +29,20 @@ var _cashAddress = require('./bitcoincashUtils/cashAddress');
|
|
|
21
29
|
var _coinmapper = require('./coinmapper');
|
|
22
30
|
var _utxopicker = require('./utxopicker'); var utxopicker = _interopRequireWildcard(_utxopicker);
|
|
23
31
|
|
|
32
|
+
let ECPair
|
|
33
|
+
|
|
34
|
+
Promise.resolve().then(() => require('@bitcoin-js/tiny-secp256k1-asmjs'))
|
|
35
|
+
.then(tinysecp => {
|
|
36
|
+
_altcoinjs.initEccLib.call(void 0, tinysecp)
|
|
37
|
+
ECPair = _ecpair.ECPairFactory.call(void 0, tinysecp)
|
|
38
|
+
})
|
|
39
|
+
.catch(error => {
|
|
40
|
+
console.error(error)
|
|
41
|
+
})
|
|
42
|
+
.finally(() => {
|
|
43
|
+
console.log('loaded ECPair!')
|
|
44
|
+
})
|
|
45
|
+
|
|
24
46
|
// in bitcoin these are bip44, bip49, bip84 xpub prefixes
|
|
25
47
|
// other coins contain different formats which still need to be gathered.
|
|
26
48
|
var BIP43PurposeTypeEnum; (function (BIP43PurposeTypeEnum) {
|
|
@@ -37,6 +59,7 @@ var AddressTypeEnum; (function (AddressTypeEnum) {
|
|
|
37
59
|
const p2sh = 'p2sh'; AddressTypeEnum["p2sh"] = p2sh;
|
|
38
60
|
const p2wpkh = 'p2wpkh'; AddressTypeEnum["p2wpkh"] = p2wpkh; // short bech32 address
|
|
39
61
|
const p2wsh = 'p2wsh'; AddressTypeEnum["p2wsh"] = p2wsh; // long bech32 address
|
|
62
|
+
const p2tr = 'p2tr'; AddressTypeEnum["p2tr"] = p2tr; // bech32m address
|
|
40
63
|
})(AddressTypeEnum || (exports.AddressTypeEnum = AddressTypeEnum = {}));
|
|
41
64
|
|
|
42
65
|
var ScriptTypeEnum; (function (ScriptTypeEnum) {
|
|
@@ -46,6 +69,7 @@ var ScriptTypeEnum; (function (ScriptTypeEnum) {
|
|
|
46
69
|
const p2pk = 'p2pk'; ScriptTypeEnum["p2pk"] = p2pk;
|
|
47
70
|
const p2pkh = 'p2pkh'; ScriptTypeEnum["p2pkh"] = p2pkh;
|
|
48
71
|
const p2sh = 'p2sh'; ScriptTypeEnum["p2sh"] = p2sh;
|
|
72
|
+
const p2tr = 'p2tr'; ScriptTypeEnum["p2tr"] = p2tr;
|
|
49
73
|
const replayProtection = 'replayprotection'; ScriptTypeEnum["replayProtection"] = replayProtection;
|
|
50
74
|
const replayProtectionP2SH = 'replayprotectionp2sh'; ScriptTypeEnum["replayProtectionP2SH"] = replayProtectionP2SH;
|
|
51
75
|
})(ScriptTypeEnum || (exports.ScriptTypeEnum = ScriptTypeEnum = {}));
|
|
@@ -224,15 +248,6 @@ var VerifyAddressEnum; (function (VerifyAddressEnum) {
|
|
|
224
248
|
|
|
225
249
|
|
|
226
250
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
251
|
|
|
237
252
|
|
|
238
253
|
|
|
@@ -392,7 +407,7 @@ const xprivToXPubInternal = (
|
|
|
392
407
|
// currently returns the derivation for an empty script template for a bitcoin cash
|
|
393
408
|
// replay protection script (without key material)
|
|
394
409
|
let hash = '0000'
|
|
395
|
-
hash =
|
|
410
|
+
hash = _altcoinjs.crypto
|
|
396
411
|
.hash160(Buffer.from(scriptTemplate(''), 'hex'))
|
|
397
412
|
.slice(0, 4)
|
|
398
413
|
.toString('hex')
|
|
@@ -482,7 +497,7 @@ const addressToScriptPubkeyInternal = (
|
|
|
482
497
|
return scriptPubkey
|
|
483
498
|
}
|
|
484
499
|
}
|
|
485
|
-
payment =
|
|
500
|
+
payment = _altcoinjs.payments.p2pkh
|
|
486
501
|
break
|
|
487
502
|
case AddressTypeEnum.p2sh:
|
|
488
503
|
if (selectedPrefixes.cashaddr != null) {
|
|
@@ -501,13 +516,16 @@ const addressToScriptPubkeyInternal = (
|
|
|
501
516
|
return scriptPubkey
|
|
502
517
|
}
|
|
503
518
|
}
|
|
504
|
-
payment =
|
|
519
|
+
payment = _altcoinjs.payments.p2sh
|
|
505
520
|
break
|
|
506
521
|
case AddressTypeEnum.p2wpkh:
|
|
507
|
-
payment =
|
|
522
|
+
payment = _altcoinjs.payments.p2wpkh
|
|
508
523
|
break
|
|
509
524
|
case AddressTypeEnum.p2wsh:
|
|
510
|
-
payment =
|
|
525
|
+
payment = _altcoinjs.payments.p2wsh
|
|
526
|
+
break
|
|
527
|
+
case AddressTypeEnum.p2tr:
|
|
528
|
+
payment = _altcoinjs.payments.p2tr
|
|
511
529
|
break
|
|
512
530
|
default:
|
|
513
531
|
throw new Error('invalid address type in address to script pubkey')
|
|
@@ -516,7 +534,7 @@ const addressToScriptPubkeyInternal = (
|
|
|
516
534
|
try {
|
|
517
535
|
scriptPubkey = payment({
|
|
518
536
|
address: args.address,
|
|
519
|
-
network
|
|
537
|
+
network,
|
|
520
538
|
bs58DecodeFunc: coin.bs58DecodeFunc,
|
|
521
539
|
bs58EncodeFunc: coin.bs58EncodeFunc
|
|
522
540
|
}).output
|
|
@@ -593,7 +611,7 @@ const addressToScriptPubkeyInternal = (
|
|
|
593
611
|
legacyPrefixes.cashaddr
|
|
594
612
|
)
|
|
595
613
|
}
|
|
596
|
-
payment =
|
|
614
|
+
payment = _altcoinjs.payments.p2pkh
|
|
597
615
|
break
|
|
598
616
|
case AddressTypeEnum.p2sh:
|
|
599
617
|
if (standardPrefixes.cashaddr != null) {
|
|
@@ -618,13 +636,16 @@ const addressToScriptPubkeyInternal = (
|
|
|
618
636
|
legacyPrefixes.cashaddr
|
|
619
637
|
)
|
|
620
638
|
}
|
|
621
|
-
payment =
|
|
639
|
+
payment = _altcoinjs.payments.p2sh
|
|
622
640
|
break
|
|
623
641
|
case AddressTypeEnum.p2wpkh:
|
|
624
|
-
payment =
|
|
642
|
+
payment = _altcoinjs.payments.p2wpkh
|
|
625
643
|
break
|
|
626
644
|
case AddressTypeEnum.p2wsh:
|
|
627
|
-
payment =
|
|
645
|
+
payment = _altcoinjs.payments.p2wsh
|
|
646
|
+
break
|
|
647
|
+
case AddressTypeEnum.p2tr:
|
|
648
|
+
payment = _altcoinjs.payments.p2tr
|
|
628
649
|
break
|
|
629
650
|
default:
|
|
630
651
|
throw new Error('invalid address type in address to script pubkey')
|
|
@@ -634,7 +655,7 @@ const addressToScriptPubkeyInternal = (
|
|
|
634
655
|
_nullishCoalesce(address, () => (
|
|
635
656
|
payment({
|
|
636
657
|
output: Buffer.from(args.scriptPubkey, 'hex'),
|
|
637
|
-
network
|
|
658
|
+
network,
|
|
638
659
|
bs58DecodeFunc: coinClass.bs58DecodeFunc,
|
|
639
660
|
bs58EncodeFunc: coinClass.bs58EncodeFunc
|
|
640
661
|
}).address))
|
|
@@ -668,13 +689,16 @@ const addressToScriptPubkeyInternal = (
|
|
|
668
689
|
let payment
|
|
669
690
|
switch (args.scriptType) {
|
|
670
691
|
case ScriptTypeEnum.p2pkh:
|
|
671
|
-
payment =
|
|
692
|
+
payment = _altcoinjs.payments.p2pkh
|
|
672
693
|
break
|
|
673
694
|
case ScriptTypeEnum.p2sh:
|
|
674
|
-
payment =
|
|
695
|
+
payment = _altcoinjs.payments.p2sh
|
|
675
696
|
break
|
|
676
697
|
case ScriptTypeEnum.p2wpkh:
|
|
677
|
-
payment =
|
|
698
|
+
payment = _altcoinjs.payments.p2wpkh
|
|
699
|
+
break
|
|
700
|
+
case ScriptTypeEnum.p2tr:
|
|
701
|
+
payment = _altcoinjs.payments.p2tr
|
|
678
702
|
break
|
|
679
703
|
default:
|
|
680
704
|
throw new Error('invalid address type in address to script pubkey')
|
|
@@ -683,7 +707,7 @@ const addressToScriptPubkeyInternal = (
|
|
|
683
707
|
try {
|
|
684
708
|
scriptHash = payment({
|
|
685
709
|
output: Buffer.from(args.scriptPubkey, 'hex'),
|
|
686
|
-
network
|
|
710
|
+
network
|
|
687
711
|
}).hash
|
|
688
712
|
} catch (error) {
|
|
689
713
|
console.trace(error)
|
|
@@ -706,15 +730,15 @@ const addressToScriptPubkeyInternal = (
|
|
|
706
730
|
prefixIndex: 0
|
|
707
731
|
})
|
|
708
732
|
}
|
|
709
|
-
const p2sh =
|
|
710
|
-
network: bip32Network,
|
|
733
|
+
const p2sh = _altcoinjs.payments.p2sh({
|
|
734
|
+
...(bip32Network != null ? { network: bip32Network } : {}),
|
|
711
735
|
redeem: {
|
|
712
736
|
output: Buffer.from(scriptPubkey, 'hex')
|
|
713
737
|
}
|
|
714
738
|
})
|
|
715
|
-
const scriptPubkeyFromLib = _optionalChain([p2sh, 'access',
|
|
716
|
-
const redeemScript = _optionalChain([p2sh, 'access',
|
|
717
|
-
const scriptHash = _optionalChain([p2sh, 'access',
|
|
739
|
+
const scriptPubkeyFromLib = _optionalChain([p2sh, 'access', _2 => _2.output, 'optionalAccess', _3 => _3.toString, 'call', _4 => _4('hex')])
|
|
740
|
+
const redeemScript = _optionalChain([p2sh, 'access', _5 => _5.redeem, 'optionalAccess', _6 => _6.output, 'optionalAccess', _7 => _7.toString, 'call', _8 => _8('hex')])
|
|
741
|
+
const scriptHash = _optionalChain([p2sh, 'access', _9 => _9.hash, 'optionalAccess', _10 => _10.toString, 'call', _11 => _11('hex')])
|
|
718
742
|
|
|
719
743
|
if (scriptPubkeyFromLib == null || redeemScript == null) {
|
|
720
744
|
throw new Error('unable to convert script to p2sh')
|
|
@@ -748,29 +772,41 @@ const addressToScriptPubkeyInternal = (
|
|
|
748
772
|
) {
|
|
749
773
|
let payment
|
|
750
774
|
switch (args.scriptType) {
|
|
751
|
-
case ScriptTypeEnum.p2pkh:
|
|
752
|
-
payment =
|
|
775
|
+
case ScriptTypeEnum.p2pkh: {
|
|
776
|
+
payment = _altcoinjs.payments.p2pkh({
|
|
753
777
|
pubkey: Buffer.from(args.pubkey, 'hex')
|
|
754
778
|
})
|
|
755
779
|
if (payment.output == null) {
|
|
756
780
|
throw new Error('failed converting pubkey to script pubkey')
|
|
757
781
|
}
|
|
758
782
|
return { scriptPubkey: payment.output.toString('hex') }
|
|
759
|
-
|
|
783
|
+
}
|
|
784
|
+
case ScriptTypeEnum.p2wpkhp2sh: {
|
|
760
785
|
return scriptPubkeyToP2SH({
|
|
761
786
|
scriptPubkey: pubkeyToScriptPubkey({
|
|
762
787
|
pubkey: args.pubkey,
|
|
763
788
|
scriptType: ScriptTypeEnum.p2wpkh
|
|
764
789
|
}).scriptPubkey
|
|
765
790
|
})
|
|
766
|
-
|
|
767
|
-
|
|
791
|
+
}
|
|
792
|
+
case ScriptTypeEnum.p2wpkh: {
|
|
793
|
+
payment = _altcoinjs.payments.p2wpkh({
|
|
794
|
+
pubkey: Buffer.from(args.pubkey, 'hex')
|
|
795
|
+
})
|
|
796
|
+
if (payment.output == null) {
|
|
797
|
+
throw new Error('failed converting pubkey to script pubkey')
|
|
798
|
+
}
|
|
799
|
+
return { scriptPubkey: payment.output.toString('hex') }
|
|
800
|
+
}
|
|
801
|
+
case ScriptTypeEnum.p2tr: {
|
|
802
|
+
payment = _altcoinjs.payments.p2tr({
|
|
768
803
|
pubkey: Buffer.from(args.pubkey, 'hex')
|
|
769
804
|
})
|
|
770
805
|
if (payment.output == null) {
|
|
771
806
|
throw new Error('failed converting pubkey to script pubkey')
|
|
772
807
|
}
|
|
773
808
|
return { scriptPubkey: payment.output.toString('hex') }
|
|
809
|
+
}
|
|
774
810
|
case ScriptTypeEnum.replayProtection: {
|
|
775
811
|
if (args.scriptTemplates == null)
|
|
776
812
|
throw new Error('Missing replayProtection script template')
|
|
@@ -809,9 +845,9 @@ const xprivToPrivateKeyInternal = (
|
|
|
809
845
|
const bip32FromBase58Func = _nullishCoalesce(coin.bip32FromBase58Func, () => ( bip32.fromBase58))
|
|
810
846
|
const node = bip32FromBase58Func(args.xpriv, network)
|
|
811
847
|
return _optionalChain([node
|
|
812
|
-
, 'access',
|
|
813
|
-
, 'access',
|
|
814
|
-
, 'access',
|
|
848
|
+
, 'access', _12 => _12.derive, 'call', _13 => _13(args.bip44ChangeIndex)
|
|
849
|
+
, 'access', _14 => _14.derive, 'call', _15 => _15(args.bip44AddressIndex)
|
|
850
|
+
, 'access', _16 => _16.privateKey, 'optionalAccess', _17 => _17.toString, 'call', _18 => _18('hex')])
|
|
815
851
|
}
|
|
816
852
|
|
|
817
853
|
const xprivToPrivateKey = (args) => {
|
|
@@ -833,7 +869,7 @@ const xprivToPrivateKeyInternal = (
|
|
|
833
869
|
prefixIndex: 0
|
|
834
870
|
})
|
|
835
871
|
const coinClass = _coinmapper.getCoinFromString.call(void 0, args.coin)
|
|
836
|
-
return
|
|
872
|
+
return ECPair.fromPrivateKey(Buffer.from(args.privateKey, 'hex'), {
|
|
837
873
|
network
|
|
838
874
|
}).toWIF(coinClass.wifEncodeFunc)
|
|
839
875
|
} exports.privateKeyToWIF = privateKeyToWIF;
|
|
@@ -848,11 +884,7 @@ const wifToPrivateKeyEncodingInternal = (
|
|
|
848
884
|
forWIF: true,
|
|
849
885
|
prefixIndex
|
|
850
886
|
})
|
|
851
|
-
const ecPair =
|
|
852
|
-
args.wifKey,
|
|
853
|
-
network,
|
|
854
|
-
coin.bs58DecodeFunc
|
|
855
|
-
)
|
|
887
|
+
const ecPair = ECPair.fromWIF(args.wifKey, network, coin.bs58DecodeFunc)
|
|
856
888
|
if (ecPair.privateKey == null) return
|
|
857
889
|
return {
|
|
858
890
|
hex: ecPair.privateKey.toString('hex'),
|
|
@@ -877,13 +909,13 @@ const wifToPrivateKeyEncodingInternal = (
|
|
|
877
909
|
privateKeyEncoding
|
|
878
910
|
) {
|
|
879
911
|
const { hex, compressed } = privateKeyEncoding
|
|
880
|
-
return
|
|
912
|
+
return ECPair.fromPrivateKey(Buffer.from(hex, 'hex'), {
|
|
881
913
|
compressed
|
|
882
914
|
}).publicKey.toString('hex')
|
|
883
915
|
} exports.privateKeyEncodingToPubkey = privateKeyEncodingToPubkey;
|
|
884
916
|
|
|
885
917
|
function signMessageBase64(message, privateKey) {
|
|
886
|
-
const keyPair =
|
|
918
|
+
const keyPair = ECPair.fromPrivateKey(Buffer.from(privateKey, 'hex'))
|
|
887
919
|
if (keyPair.privateKey == null) {
|
|
888
920
|
throw new Error('Address could not sign message')
|
|
889
921
|
}
|
|
@@ -893,14 +925,14 @@ const wifToPrivateKeyEncodingInternal = (
|
|
|
893
925
|
} exports.signMessageBase64 = signMessageBase64;
|
|
894
926
|
|
|
895
927
|
function makeTx(args) {
|
|
896
|
-
const { log, outputSort } = args
|
|
928
|
+
const { log, outputSort, memos } = args
|
|
897
929
|
let sequence = 0xffffffff
|
|
898
930
|
if (args.setRBF) {
|
|
899
931
|
sequence -= 2
|
|
900
932
|
}
|
|
901
933
|
|
|
902
934
|
// get coin specific replay protection sighhash bits
|
|
903
|
-
let sighashType =
|
|
935
|
+
let sighashType = _altcoinjs.Transaction.SIGHASH_ALL
|
|
904
936
|
const coin = _coinmapper.getCoinFromString.call(void 0, args.coin)
|
|
905
937
|
if (coin.sighash != null) {
|
|
906
938
|
sighashType = coin.sighash
|
|
@@ -983,22 +1015,19 @@ const wifToPrivateKeyEncodingInternal = (
|
|
|
983
1015
|
value: target.value
|
|
984
1016
|
})
|
|
985
1017
|
}
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
value: 0
|
|
1000
|
-
})
|
|
1001
|
-
}
|
|
1018
|
+
}
|
|
1019
|
+
for (const memo of memos) {
|
|
1020
|
+
const memoData =
|
|
1021
|
+
memo.type === 'text'
|
|
1022
|
+
? Buffer.from(memo.value, 'utf8')
|
|
1023
|
+
: Buffer.from(memo.value, 'hex')
|
|
1024
|
+
const script = _altcoinjs.script
|
|
1025
|
+
.compile([_altcoinjs.opcodes.OP_RETURN, memoData])
|
|
1026
|
+
.toString('hex')
|
|
1027
|
+
targets.push({
|
|
1028
|
+
script,
|
|
1029
|
+
value: 0
|
|
1030
|
+
})
|
|
1002
1031
|
}
|
|
1003
1032
|
|
|
1004
1033
|
const changeScript = exports.addressToScriptPubkey.call(void 0, {
|
|
@@ -1035,12 +1064,12 @@ const wifToPrivateKeyEncodingInternal = (
|
|
|
1035
1064
|
}
|
|
1036
1065
|
})()
|
|
1037
1066
|
|
|
1038
|
-
const psbt = new
|
|
1067
|
+
const psbt = new (0, _altcoinjs.Psbt)()
|
|
1039
1068
|
try {
|
|
1040
1069
|
psbt.addInputs(sortedInputs)
|
|
1041
1070
|
psbt.addOutputs(sortedOutputs)
|
|
1042
1071
|
} catch (error) {
|
|
1043
|
-
_optionalChain([log, 'optionalAccess',
|
|
1072
|
+
_optionalChain([log, 'optionalAccess', _19 => _19.error, 'call', _20 => _20(`Failed makeTx: ${String(error)}`)])
|
|
1044
1073
|
throw error
|
|
1045
1074
|
}
|
|
1046
1075
|
|
|
@@ -1050,14 +1079,20 @@ const wifToPrivateKeyEncodingInternal = (
|
|
|
1050
1079
|
changeUsed: result.changeUsed,
|
|
1051
1080
|
fee: result.fee,
|
|
1052
1081
|
psbtBase64: psbt.toBase64(),
|
|
1053
|
-
hex: _optionalChain([psbt, 'access',
|
|
1082
|
+
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
1083
|
}
|
|
1055
1084
|
} exports.makeTx = makeTx;
|
|
1056
1085
|
|
|
1057
1086
|
async function signTx(args) {
|
|
1058
|
-
const psbt =
|
|
1087
|
+
const psbt = _altcoinjs.Psbt.fromBase64(args.psbtBase64)
|
|
1059
1088
|
const coin = _coinmapper.getCoinFromString.call(void 0, args.coin)
|
|
1060
1089
|
|
|
1090
|
+
const validator = (
|
|
1091
|
+
pubkey,
|
|
1092
|
+
msghash,
|
|
1093
|
+
signature
|
|
1094
|
+
) => ECPair.fromPublicKey(pubkey).verify(msghash, signature)
|
|
1095
|
+
|
|
1061
1096
|
for (let i = 0; i < psbt.inputCount; i++) {
|
|
1062
1097
|
const privateKeyEncoding =
|
|
1063
1098
|
_nullishCoalesce(args.privateKeyEncodings[i], () => (
|
|
@@ -1065,11 +1100,11 @@ const wifToPrivateKeyEncodingInternal = (
|
|
|
1065
1100
|
const { hex, compressed } = privateKeyEncoding
|
|
1066
1101
|
psbt.signInput(
|
|
1067
1102
|
i,
|
|
1068
|
-
|
|
1069
|
-
|
|
1103
|
+
ECPair.fromPrivateKey(Buffer.from(hex, 'hex'), { compressed }),
|
|
1104
|
+
_altcoinjs.Psbt.DEFAULT_SIGHASHES,
|
|
1070
1105
|
coin.sighashFunction
|
|
1071
1106
|
)
|
|
1072
|
-
psbt.validateSignaturesOfInput(i)
|
|
1107
|
+
psbt.validateSignaturesOfInput(i, validator)
|
|
1073
1108
|
psbt.finalizeInput(i)
|
|
1074
1109
|
}
|
|
1075
1110
|
const tx = psbt.extractTransaction(true)
|
|
@@ -1225,31 +1260,38 @@ const guessAddressTypeFromAddress = (
|
|
|
1225
1260
|
}
|
|
1226
1261
|
const coinClass = _coinmapper.getCoinFromString.call(void 0, coin)
|
|
1227
1262
|
try {
|
|
1228
|
-
|
|
1263
|
+
_altcoinjs.payments.p2pkh({
|
|
1229
1264
|
address,
|
|
1230
1265
|
network,
|
|
1231
1266
|
bs58DecodeFunc: coinClass.bs58DecodeFunc,
|
|
1232
1267
|
bs58EncodeFunc: coinClass.bs58EncodeFunc
|
|
1233
1268
|
})
|
|
1234
1269
|
return AddressTypeEnum.p2pkh
|
|
1235
|
-
} catch (
|
|
1270
|
+
} catch (_) {}
|
|
1236
1271
|
try {
|
|
1237
|
-
|
|
1272
|
+
_altcoinjs.payments.p2sh({
|
|
1238
1273
|
address,
|
|
1239
1274
|
network,
|
|
1240
1275
|
bs58DecodeFunc: coinClass.bs58DecodeFunc,
|
|
1241
1276
|
bs58EncodeFunc: coinClass.bs58EncodeFunc
|
|
1242
1277
|
})
|
|
1243
1278
|
return AddressTypeEnum.p2sh
|
|
1244
|
-
} catch (
|
|
1279
|
+
} catch (_) {}
|
|
1245
1280
|
try {
|
|
1246
|
-
|
|
1281
|
+
_altcoinjs.payments.p2wsh({ address, network })
|
|
1247
1282
|
return AddressTypeEnum.p2wsh
|
|
1248
|
-
} catch (
|
|
1283
|
+
} catch (_) {}
|
|
1249
1284
|
try {
|
|
1250
|
-
|
|
1285
|
+
_altcoinjs.payments.p2wpkh({ address, network })
|
|
1251
1286
|
return AddressTypeEnum.p2wpkh
|
|
1252
|
-
} catch (
|
|
1287
|
+
} catch (_) {}
|
|
1288
|
+
try {
|
|
1289
|
+
_altcoinjs.payments.p2tr({
|
|
1290
|
+
address,
|
|
1291
|
+
network
|
|
1292
|
+
})
|
|
1293
|
+
return AddressTypeEnum.p2tr
|
|
1294
|
+
} catch (_) {}
|
|
1253
1295
|
const cashAddrPrefixes = getCashAddrPrefixes(coinClass)
|
|
1254
1296
|
if (cashAddrPrefixes.length > 0) {
|
|
1255
1297
|
try {
|
|
@@ -1295,13 +1337,16 @@ const scriptHashToScriptPubkey = (
|
|
|
1295
1337
|
let payment
|
|
1296
1338
|
switch (args.scriptType) {
|
|
1297
1339
|
case ScriptTypeEnum.p2pkh:
|
|
1298
|
-
payment =
|
|
1340
|
+
payment = _altcoinjs.payments.p2pkh
|
|
1299
1341
|
break
|
|
1300
1342
|
case ScriptTypeEnum.p2sh:
|
|
1301
|
-
payment =
|
|
1343
|
+
payment = _altcoinjs.payments.p2sh
|
|
1302
1344
|
break
|
|
1303
1345
|
case ScriptTypeEnum.p2wpkh:
|
|
1304
|
-
payment =
|
|
1346
|
+
payment = _altcoinjs.payments.p2wpkh
|
|
1347
|
+
break
|
|
1348
|
+
case ScriptTypeEnum.p2tr:
|
|
1349
|
+
payment = _altcoinjs.payments.p2tr
|
|
1305
1350
|
break
|
|
1306
1351
|
default:
|
|
1307
1352
|
throw new Error('invalid address type in address to script pubkey')
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true})
|
|
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
|
/*
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }var _biggystring = require('biggystring');
|
|
2
|
+
var _cleaners = require('cleaners');
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
var _cleaners3 = require('../util/cleaners');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Validates the memos on an spend request.
|
|
14
|
+
* Throws an error if any of the memos are wrong.
|
|
15
|
+
*/
|
|
16
|
+
function validateMemos(
|
|
17
|
+
spendInfo,
|
|
18
|
+
currencyInfo
|
|
19
|
+
) {
|
|
20
|
+
const { memos = [] } = spendInfo
|
|
21
|
+
const {
|
|
22
|
+
displayName,
|
|
23
|
+
memoMaxLength,
|
|
24
|
+
memoMaxValue,
|
|
25
|
+
memoOptions = [],
|
|
26
|
+
multipleMemos = false,
|
|
27
|
+
memoType
|
|
28
|
+
} = currencyInfo
|
|
29
|
+
|
|
30
|
+
// Not all coins keep the legacy memo type in the modern list,
|
|
31
|
+
// but we still need to validate the legacy type if present:
|
|
32
|
+
const allOptions = [...memoOptions]
|
|
33
|
+
if (memoType === 'text') {
|
|
34
|
+
allOptions.push({ type: 'text', maxLength: memoMaxLength })
|
|
35
|
+
}
|
|
36
|
+
if (memoType === 'number') {
|
|
37
|
+
allOptions.push({ type: 'number', maxValue: memoMaxValue })
|
|
38
|
+
}
|
|
39
|
+
if (memoType === 'hex') {
|
|
40
|
+
allOptions.push({
|
|
41
|
+
type: 'hex',
|
|
42
|
+
maxBytes: memoMaxLength == null ? undefined : memoMaxLength / 2
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// What we should call a "memo" in our error messages:
|
|
47
|
+
const { memoName = 'memo' } = _nullishCoalesce(memoOptions[0], () => ( {}))
|
|
48
|
+
|
|
49
|
+
// Now validate our memos:
|
|
50
|
+
for (const memo of memos) {
|
|
51
|
+
const options = allOptions.filter(option => memo.type === option.type)
|
|
52
|
+
if (options.length < 1) {
|
|
53
|
+
throw new Error(`${displayName} ${memoName}: cannot be type ${memo.type}`)
|
|
54
|
+
}
|
|
55
|
+
const problem = options
|
|
56
|
+
.map(option => getMemoError(memo, option))
|
|
57
|
+
.find(problem => problem != null)
|
|
58
|
+
if (problem != null) {
|
|
59
|
+
throw new Error(`${displayName} {memoName}: ${problem}`)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Validate the number of memos:
|
|
64
|
+
if (!multipleMemos && memos.length > 1) {
|
|
65
|
+
throw new Error(`${displayName} only supports one ${memoName}`)
|
|
66
|
+
}
|
|
67
|
+
} exports.validateMemos = validateMemos;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Checks a memo against a memo option.
|
|
71
|
+
* Returns `undefined` if valid, or an error string if invalid.
|
|
72
|
+
*/
|
|
73
|
+
function getMemoError(
|
|
74
|
+
memo,
|
|
75
|
+
option
|
|
76
|
+
) {
|
|
77
|
+
if (
|
|
78
|
+
option.type === 'text' &&
|
|
79
|
+
option.maxLength != null &&
|
|
80
|
+
memo.value.length > option.maxLength
|
|
81
|
+
) {
|
|
82
|
+
return `cannot be longer than ${option.maxLength}`
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (option.type === 'number') {
|
|
86
|
+
const value = _cleaners.asMaybe.call(void 0, (0, _cleaners3.asIntegerString))(memo.value)
|
|
87
|
+
if (value == null) {
|
|
88
|
+
return `is not a valid number`
|
|
89
|
+
}
|
|
90
|
+
if (option.maxValue != null && _biggystring.gt.call(void 0, value, option.maxValue)) {
|
|
91
|
+
return `cannot be greater than ${option.maxValue}`
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (option.type === 'hex') {
|
|
96
|
+
const value = _cleaners.asMaybe.call(void 0, (0, _cleaners3.asBase16))(memo.value)
|
|
97
|
+
if (value == null) {
|
|
98
|
+
return `is not valid hexadecimal`
|
|
99
|
+
}
|
|
100
|
+
if (option.maxBytes != null && value.length > option.maxBytes) {
|
|
101
|
+
return `cannot be longer than ${option.maxBytes} bytes`
|
|
102
|
+
}
|
|
103
|
+
if (option.minBytes != null && value.length < option.minBytes) {
|
|
104
|
+
return `cannot be shorter than ${option.minBytes} bytes`
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import {
|
|
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?:
|
|
57
|
-
bs58EncodeFunc?:
|
|
58
|
-
wifEncodeFunc?:
|
|
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;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { EdgeCurrencyInfo, EdgeSpendInfo } from 'edge-core-js/types';
|
|
2
|
+
/**
|
|
3
|
+
* Upgrades the memo fields inside an EdgeSpendTarget,
|
|
4
|
+
* since we need to be runtime-compatible with legacy core versions.
|
|
5
|
+
*/
|
|
6
|
+
export declare function upgradeMemos(spendInfo: EdgeSpendInfo, currencyInfo: EdgeCurrencyInfo): EdgeSpendInfo;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { Disklet } from 'disklet';
|
|
2
|
-
import {
|
|
2
|
+
import { EdgeParsedUri } from 'edge-core-js/types';
|
|
3
3
|
import { ChangePath, CurrencyFormat, EngineInfo } from '../../plugin/types';
|
|
4
4
|
import { IUTXO } from '../db/types';
|
|
5
5
|
import { ScriptTemplates } from '../info/scriptTemplates/types';
|
|
6
6
|
import { PrivateKey } from '../keymanager/cleaners';
|
|
7
7
|
import { AddressTypeEnum, BIP43PurposeTypeEnum, ScriptTypeEnum } from '../keymanager/keymanager';
|
|
8
8
|
export declare const getCurrencyFormatFromPurposeType: (purpose: BIP43PurposeTypeEnum) => CurrencyFormat;
|
|
9
|
-
export declare const validateMemo: (memo: string) => EdgeMemoRules;
|
|
10
9
|
export declare const getAddressTypeFromPurposeType: (purpose: BIP43PurposeTypeEnum) => AddressTypeEnum;
|
|
11
10
|
export declare const getScriptTypeFromPurposeType: (purpose: BIP43PurposeTypeEnum) => ScriptTypeEnum;
|
|
12
11
|
export declare const validScriptPubkeyFromAddress: (args: {
|