aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBruno Barbieri <bruno.barbieri@consensys.net>2018-11-27 02:40:04 +0800
committerGitHub <noreply@github.com>2018-11-27 02:40:04 +0800
commit3b1e73eff8bc553877cee957a401aa502f64a1b6 (patch)
treef090ad9a93b44f0822e45356a101f574b44a919d
parent1403b8286d55db50f9f525a1bbfcffe36b34255a (diff)
parentf2066432baa5af4f63a5687800bb524959b27af3 (diff)
downloadtangerine-wallet-browser-3b1e73eff8bc553877cee957a401aa502f64a1b6.tar.gz
tangerine-wallet-browser-3b1e73eff8bc553877cee957a401aa502f64a1b6.tar.zst
tangerine-wallet-browser-3b1e73eff8bc553877cee957a401aa502f64a1b6.zip
Merge pull request #5792 from MetaMask/signed-type-data-error-hw-wallet
Consider HW Wallets for signTypedMessage
-rw-r--r--app/scripts/metamask-controller.js25
1 files changed, 16 insertions, 9 deletions
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index f3cd078b8..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')
@@ -1025,16 +1026,22 @@ module.exports = class MetamaskController extends EventEmitter {
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.includes(keyring.type)) {
+ 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()