mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-26 12:29:06 +01:00
Merge pull request #5792 from MetaMask/signed-type-data-error-hw-wallet
Consider HW Wallets for signTypedMessage
This commit is contained in:
commit
3b1e73eff8
@ -50,6 +50,7 @@ const seedPhraseVerifier = require('./lib/seed-phrase-verifier')
|
|||||||
const log = require('loglevel')
|
const log = require('loglevel')
|
||||||
const TrezorKeyring = require('eth-trezor-keyring')
|
const TrezorKeyring = require('eth-trezor-keyring')
|
||||||
const LedgerBridgeKeyring = require('eth-ledger-bridge-keyring')
|
const LedgerBridgeKeyring = require('eth-ledger-bridge-keyring')
|
||||||
|
const HW_WALLETS_KEYRINGS = [TrezorKeyring.type, LedgerBridgeKeyring.type]
|
||||||
const EthQuery = require('eth-query')
|
const EthQuery = require('eth-query')
|
||||||
const ethUtil = require('ethereumjs-util')
|
const ethUtil = require('ethereumjs-util')
|
||||||
const sigUtil = require('eth-sig-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 cleanMsgParams = await this.typedMessageManager.approveMessage(msgParams)
|
||||||
const address = sigUtil.normalize(cleanMsgParams.from)
|
const address = sigUtil.normalize(cleanMsgParams.from)
|
||||||
const keyring = await this.keyringController.getKeyringForAccount(address)
|
const keyring = await this.keyringController.getKeyringForAccount(address)
|
||||||
const wallet = keyring._getWalletForAccount(address)
|
|
||||||
const privKey = ethUtil.toBuffer(wallet.getPrivateKey())
|
|
||||||
let signature
|
let signature
|
||||||
switch (version) {
|
// HW Wallet keyrings don't expose private keys
|
||||||
case 'V1':
|
// so we need to handle it separately
|
||||||
signature = sigUtil.signTypedDataLegacy(privKey, { data: cleanMsgParams.data })
|
if (!HW_WALLETS_KEYRINGS.includes(keyring.type)) {
|
||||||
break
|
const wallet = keyring._getWalletForAccount(address)
|
||||||
case 'V3':
|
const privKey = ethUtil.toBuffer(wallet.getPrivateKey())
|
||||||
signature = sigUtil.signTypedData(privKey, { data: JSON.parse(cleanMsgParams.data) })
|
switch (version) {
|
||||||
break
|
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)
|
this.typedMessageManager.setMsgStatusSigned(msgId, signature)
|
||||||
return this.getState()
|
return this.getState()
|
||||||
|
Loading…
Reference in New Issue
Block a user