From 3abf9ec7db99de3aa85222e7630e4e714cd08ea3 Mon Sep 17 00:00:00 2001 From: brunobar79 Date: Tue, 20 Nov 2018 12:48:43 -0500 Subject: [PATCH 1/3] consider hw wallets --- app/scripts/metamask-controller.js | 25 ++++++++++++++++--------- 1 file 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() From fb94c1bae7d4f500ef78b2f93ada44ef640d38e4 Mon Sep 17 00:00:00 2001 From: brunobar79 Date: Tue, 20 Nov 2018 12:57:58 -0500 Subject: [PATCH 2/3] remove extra semicolon --- app/scripts/metamask-controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 51114b5d2..2cffa15c2 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -1041,7 +1041,7 @@ module.exports = class MetamaskController extends EventEmitter { break } } else { - signature = await keyring.signTypedData(address, cleanMsgParams.data); + signature = await keyring.signTypedData(address, cleanMsgParams.data) } this.typedMessageManager.setMsgStatusSigned(msgId, signature) return this.getState() From f2066432baa5af4f63a5687800bb524959b27af3 Mon Sep 17 00:00:00 2001 From: Bruno Barbieri Date: Mon, 26 Nov 2018 13:27:49 -0500 Subject: [PATCH 3/3] Use Array.includes --- app/scripts/metamask-controller.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 2cffa15c2..7d6f06f92 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -50,6 +50,7 @@ const seedPhraseVerifier = require('./lib/seed-phrase-verifier') const log = require('loglevel') const TrezorKeyring = require('eth-trezor-keyring') const LedgerBridgeKeyring = require('eth-ledger-bridge-keyring') +const HW_WALLETS_KEYRINGS = [TrezorKeyring.type, LedgerBridgeKeyring.type] const EthQuery = require('eth-query') const ethUtil = require('ethereumjs-util') const sigUtil = require('eth-sig-util') @@ -1021,15 +1022,14 @@ 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) let signature - // HW Wallet keyrings don't expose private keys so - // we need to handle it separately - if (HW_WALLETS_KEYRINGS.indexOf(keyring.type) === -1) { + // HW Wallet keyrings don't expose private keys + // so we need to handle it separately + if (!HW_WALLETS_KEYRINGS.includes(keyring.type)) { const wallet = keyring._getWalletForAccount(address) const privKey = ethUtil.toBuffer(wallet.getPrivateKey()) switch (version) {