diff --git a/app/sign.js b/app/sign.js index 7e65e0d..f9ced33 100644 --- a/app/sign.js +++ b/app/sign.js @@ -11,45 +11,6 @@ const bip39 = require('bip39'); const bitgojs = require('bitgo'); let bitgo; -const utxoNetworks = { - btc: utxoLib.networks.bitcoin, - ltc: utxoLib.networks.litecoin, - bch: utxoLib.networks.bitcoincash, - bsv: utxoLib.networks.bitcoinsv, - zec: utxoLib.networks.zcash, - dash: utxoLib.networks.dash, - tltc: utxoLib.networks.litecoin, - tbtc: utxoLib.networks.testnet, - tbch: utxoLib.networks.bitcoincashTestnet, - tbsv: utxoLib.networks.bitcoinsvTestnet, - tzec: utxoLib.networks.zcashTest, - tdash: utxoLib.networks.dashTest, -}; - -const coinDecimals = { - btc: 8, - eth: 18, - eos: 4, - trx: 6, - xrp: 6, - bch: 8, - bsv: 8, - ltc: 8, - zec: 8, - dash: 8, - xlm: 7, - tbtc: 8, - teth: 18, - teos: 4, - ttrx: 6, - txrp: 6, - tltc: 8, - txlm: 7, - tbch: 8, - tbsv: 8, - tzec: 8, - tdash: 8, -}; const BCH_COINS = ['bch', 'tbch', 'bsv', 'tbsv']; const TEN = new BN(10); @@ -57,6 +18,10 @@ const TEN = new BN(10); const EOS_MAINNET_CHAIN_ID = 'aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906'; const EOS_TESTNET_CHAIN_ID = 'e70aaab8997e1dfce58fbfac80cbbb8fecec7b99cf982a9444273cbc64c41473'; +const getCoinConfig = function(coin, data) { + return statics.coins.get[coin].[data]; +} + const confirmRecovery = function(backupKey, outputs, customMessage, skipConfirm) { console.log('Sign Recovery Transaction'); console.log('========================='); @@ -131,8 +96,9 @@ const getBackupSigningKey = function(key, expectedXpub) { } const handleSignUtxo = function(recoveryRequest, key, skipConfirm) { - const network = utxoNetworks[recoveryRequest.coin]; - const decimals = coinDecimals[recoveryRequest.coin]; + + const network = getCoinConfig(recoveryRequest.coin, 'network'); + const decimals = getCoinConfig(recoveryRequest.coin, 'decimalPlaces'); if (!network) { throw new Error(`Unsupported coin: ${recoveryRequest.coin}`); @@ -232,7 +198,8 @@ const signEthTx = function(recoveryRequest, key, skipConfirm, isToken) { // if request is for ETH, need to correct the amount decimals. if (!isToken) { - const decimals = coinDecimals[recoveryRequest.coin]; + const decimals = getCoinConfig(recoveryRequest.coin, 'decimalPlaces'); + outputs[0].amount = outputs[0].amount.div(TEN.pow(decimals)); } @@ -305,7 +272,7 @@ const handleSignXrp = function(recoveryRequest, key, skipConfirm) { const txHex = getTransactionHexFromRequest(recoveryRequest); - const decimals = coinDecimals[recoveryRequest.coin]; + const decimals = getCoinConfig(recoveryRequest.coin, 'decimalPlaces'); const transaction = rippleParse.decode(txHex); const outputs = [{