mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
consider hw wallets
This commit is contained in:
parent
a7b3750a3e
commit
3abf9ec7db
@ -1021,20 +1021,27 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
log.info('MetaMaskController - eth_signTypedData')
|
log.info('MetaMaskController - eth_signTypedData')
|
||||||
const msgId = msgParams.metamaskId
|
const msgId = msgParams.metamaskId
|
||||||
const version = msgParams.version
|
const version = msgParams.version
|
||||||
|
const HW_WALLETS_KEYRINGS = [TrezorKeyring.type, LedgerBridgeKeyring.type]
|
||||||
try {
|
try {
|
||||||
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 so
|
||||||
case 'V1':
|
// we need to handle it separately
|
||||||
signature = sigUtil.signTypedDataLegacy(privKey, { data: cleanMsgParams.data })
|
if (HW_WALLETS_KEYRINGS.indexOf(keyring.type) === -1) {
|
||||||
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