diff options
author | brunobar79 <brunobar79@gmail.com> | 2018-11-21 01:48:43 +0800 |
---|---|---|
committer | brunobar79 <brunobar79@gmail.com> | 2018-11-21 01:48:43 +0800 |
commit | 3abf9ec7db99de3aa85222e7630e4e714cd08ea3 (patch) | |
tree | 9809f028198cd6fa7136e1507add80010ecdc346 | |
parent | a7b3750a3efd4dd521baf2aae4dab4c630aba418 (diff) | |
download | tangerine-wallet-browser-3abf9ec7db99de3aa85222e7630e4e714cd08ea3.tar tangerine-wallet-browser-3abf9ec7db99de3aa85222e7630e4e714cd08ea3.tar.gz tangerine-wallet-browser-3abf9ec7db99de3aa85222e7630e4e714cd08ea3.tar.bz2 tangerine-wallet-browser-3abf9ec7db99de3aa85222e7630e4e714cd08ea3.tar.lz tangerine-wallet-browser-3abf9ec7db99de3aa85222e7630e4e714cd08ea3.tar.xz tangerine-wallet-browser-3abf9ec7db99de3aa85222e7630e4e714cd08ea3.tar.zst tangerine-wallet-browser-3abf9ec7db99de3aa85222e7630e4e714cd08ea3.zip |
consider hw wallets
-rw-r--r-- | app/scripts/metamask-controller.js | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index f3cd078b8..51114b5d2 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -1021,20 +1021,27 @@ module.exports = class MetamaskController extends EventEmitter { log.info('MetaMaskController - eth_signTypedData') const msgId = msgParams.metamaskId const version = msgParams.version + const HW_WALLETS_KEYRINGS = [TrezorKeyring.type, LedgerBridgeKeyring.type] try { const cleanMsgParams = await this.typedMessageManager.approveMessage(msgParams) const address = sigUtil.normalize(cleanMsgParams.from) const keyring = await this.keyringController.getKeyringForAccount(address) - const wallet = keyring._getWalletForAccount(address) - const privKey = ethUtil.toBuffer(wallet.getPrivateKey()) let signature - switch (version) { - case 'V1': - signature = sigUtil.signTypedDataLegacy(privKey, { data: cleanMsgParams.data }) - break - case 'V3': - signature = sigUtil.signTypedData(privKey, { data: JSON.parse(cleanMsgParams.data) }) - break + // HW Wallet keyrings don't expose private keys so + // we need to handle it separately + if (HW_WALLETS_KEYRINGS.indexOf(keyring.type) === -1) { + const wallet = keyring._getWalletForAccount(address) + const privKey = ethUtil.toBuffer(wallet.getPrivateKey()) + switch (version) { + case 'V1': + signature = sigUtil.signTypedDataLegacy(privKey, { data: cleanMsgParams.data }) + break + case 'V3': + signature = sigUtil.signTypedData(privKey, { data: JSON.parse(cleanMsgParams.data) }) + break + } + } else { + signature = await keyring.signTypedData(address, cleanMsgParams.data); } this.typedMessageManager.setMsgStatusSigned(msgId, signature) return this.getState() |