diff --git a/common/components/WalletDecrypt/Trezor.jsx b/common/components/WalletDecrypt/Trezor.jsx index 4216f010770..dba45ddc015 100644 --- a/common/components/WalletDecrypt/Trezor.jsx +++ b/common/components/WalletDecrypt/Trezor.jsx @@ -65,8 +65,8 @@ export default class TrezorDecrypt extends Component { }); }; - _handleUnlock = (address: string) => { - this.props.onUnlock(new TrezorWallet(address, this.state.dPath)); + _handleUnlock = (address: string, index: number) => { + this.props.onUnlock(new TrezorWallet(address, this.state.dPath, index)); }; render() { diff --git a/common/libs/decrypt.js b/common/libs/decrypt.js index 4c86464fd67..d70106c1e24 100644 --- a/common/libs/decrypt.js +++ b/common/libs/decrypt.js @@ -3,7 +3,7 @@ import { createHash, createDecipheriv } from 'crypto'; import { validateMnemonic, mnemonicToSeed } from 'bip39'; import { fromMasterSeed } from 'hdkey'; -import { stripHex } from 'libs/values'; +import { stripHexPrefixAndLower } from 'libs/values'; import { privateToAddress } from 'ethereumjs-util'; @@ -79,7 +79,7 @@ export function decryptMnemonicToPrivKey( address: string ): Buffer { phrase = phrase.trim(); - address = stripHex(address); + address = stripHexPrefixAndLower(address); if (!validateMnemonic(phrase)) { throw new Error('Invalid mnemonic'); diff --git a/common/libs/transaction.js b/common/libs/transaction.js index ed47705f443..1d4c7b2a5d4 100644 --- a/common/libs/transaction.js +++ b/common/libs/transaction.js @@ -4,7 +4,7 @@ import translate from 'translations'; import { padToEven, addHexPrefix, toChecksumAddress } from 'ethereumjs-util'; import { isValidETHAddress } from 'libs/validators'; import ERC20 from 'libs/erc20'; -import { stripHex, valueToHex } from 'libs/values'; +import { stripHexPrefixAndLower, valueToHex } from 'libs/values'; import { Wei, Ether, toTokenUnit } from 'libs/units'; import { RPCNode } from 'libs/nodes'; import { TransactionWithoutGas } from 'libs/messages'; @@ -132,12 +132,12 @@ export async function generateCompleteTransactionFromRawTransaction( } // Taken from v3's `sanitizeHex`, ensures that the value is a %2 === 0 // prefix'd hex value. - const cleanHex = hex => addHexPrefix(padToEven(stripHex(hex))); + const cleanHex = hex => addHexPrefix(padToEven(stripHexPrefixAndLower(hex))); const cleanedRawTx = { nonce: cleanHex(nonce), gasPrice: cleanHex(gasPrice.toString(16)), gasLimit: cleanHex(gasLimit.toString(16)), - to: cleanHex(to), + to: toChecksumAddress(cleanHex(to)), value: token ? '0x00' : cleanHex(value.toString(16)), data: data ? cleanHex(data) : '', chainId: chainId || 1 diff --git a/common/libs/values.js b/common/libs/values.js index f7af6b724d4..f740e72f4f7 100644 --- a/common/libs/values.js +++ b/common/libs/values.js @@ -1,7 +1,7 @@ // @flow import { Ether } from 'libs/units'; -export function stripHex(address: string): string { +export function stripHexPrefixAndLower(address: string): string { return address.replace('0x', '').toLowerCase(); } diff --git a/common/libs/wallet/deterministic.js b/common/libs/wallet/deterministic.js index ac8ad6d0e15..d3fae175173 100644 --- a/common/libs/wallet/deterministic.js +++ b/common/libs/wallet/deterministic.js @@ -4,10 +4,12 @@ import type { IWallet } from './IWallet'; export default class DeterministicWallet implements IWallet { address: string; dPath: string; + index: number; - constructor(address: string, dPath: string) { + constructor(address: string, dPath: string, index: number) { this.address = address; this.dPath = dPath; + this.index = index; } getAddress(): Promise { @@ -15,6 +17,6 @@ export default class DeterministicWallet implements IWallet { } getPath(): string { - return this.dPath; + return `${this.dPath}/${this.index}`; } } diff --git a/common/libs/wallet/privkey.js b/common/libs/wallet/privkey.js index 152f66f9afe..78f5dcdb68d 100644 --- a/common/libs/wallet/privkey.js +++ b/common/libs/wallet/privkey.js @@ -11,7 +11,7 @@ import { signRawTxWithPrivKey, signMessageWithPrivKey } from 'libs/signing'; import { isValidPrivKey } from 'libs/validators'; import type { RawTransaction } from 'libs/transaction'; import type { UtcKeystore } from 'libs/keystore'; -import { stripHex } from 'libs/values'; +import { stripHexPrefixAndLower } from 'libs/values'; export default class PrivKeyWallet implements IWallet { privKey: Buffer; @@ -43,7 +43,7 @@ export default class PrivKeyWallet implements IWallet { getNakedAddress(): Promise { return new Promise(resolve => { this.getAddress().then(address => { - resolve(stripHex(address)); + resolve(stripHexPrefixAndLower(address)); }); }); } diff --git a/common/libs/wallet/trezor.js b/common/libs/wallet/trezor.js index dcefb1e6639..d8145912a53 100644 --- a/common/libs/wallet/trezor.js +++ b/common/libs/wallet/trezor.js @@ -4,8 +4,7 @@ import EthTx from 'ethereumjs-tx'; import Big from 'bignumber.js'; import { addHexPrefix } from 'ethereumjs-util'; import DeterministicWallet from './deterministic'; -import { stripHex } from 'libs/values'; - +import { stripHexPrefixAndLower } from 'libs/values'; import type { RawTransaction } from 'libs/transaction'; export default class TrezorWallet extends DeterministicWallet { @@ -14,12 +13,13 @@ export default class TrezorWallet extends DeterministicWallet { TrezorConnect.ethereumSignTx( // Args this.getPath(), - stripHex(tx.nonce), - stripHex(tx.gasPrice.toString()), - stripHex(tx.gasLimit.toString()), - stripHex(tx.to), - stripHex(tx.value), - stripHex(tx.data), + // stripHexPrefixAndLower identical to ethFuncs.getNakedAddress + stripHexPrefixAndLower(tx.nonce), + stripHexPrefixAndLower(tx.gasPrice.toString()), + stripHexPrefixAndLower(tx.gasLimit.toString()), + stripHexPrefixAndLower(tx.to), + stripHexPrefixAndLower(tx.value), + stripHexPrefixAndLower(tx.data), tx.chainId, // Callback result => {