1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Add support for eth_signTypedData_v4 (#6930)

This commit is contained in:
Brendan Chou 2019-08-20 12:52:59 -07:00 committed by Whymarrh Whitby
parent 6e081eb17c
commit cc71b4f52b
4 changed files with 11 additions and 4 deletions

View File

@ -12,6 +12,7 @@ function createMetamaskMiddleware ({
processEthSignMessage,
processTypedMessage,
processTypedMessageV3,
processTypedMessageV4,
processPersonalMessage,
getPendingNonce,
}) {
@ -27,6 +28,7 @@ function createMetamaskMiddleware ({
processEthSignMessage,
processTypedMessage,
processTypedMessageV3,
processTypedMessageV4,
processPersonalMessage,
}),
createPendingNonceMiddleware({ getPendingNonce }),

View File

@ -141,6 +141,7 @@ module.exports = class TypedMessageManager extends EventEmitter {
}, 'Expected EIP712 typed data')
break
case 'V3':
case 'V4':
let data
assert.equal(typeof params, 'object', 'Params should be an object.')
assert.ok('data' in params, 'Params must include a data field.')

View File

@ -341,6 +341,7 @@ module.exports = class MetamaskController extends EventEmitter {
processEthSignMessage: this.newUnsignedMessage.bind(this),
processTypedMessage: this.newUnsignedTypedMessage.bind(this),
processTypedMessageV3: this.newUnsignedTypedMessage.bind(this),
processTypedMessageV4: this.newUnsignedTypedMessage.bind(this),
processPersonalMessage: this.newUnsignedPersonalMessage.bind(this),
getPendingNonce: this.getPendingNonce.bind(this),
}
@ -1141,6 +1142,9 @@ module.exports = class MetamaskController extends EventEmitter {
case 'V3':
signature = sigUtil.signTypedData(privKey, { data: JSON.parse(cleanMsgParams.data) })
break
case 'V4':
signature = sigUtil.signTypedData_v4(privKey, { data: JSON.parse(cleanMsgParams.data) })
break
}
} else {
signature = await keyring.signTypedData(address, cleanMsgParams.data)
@ -1797,4 +1801,3 @@ module.exports = class MetamaskController extends EventEmitter {
return this.keyringController.setLocked()
}
}

View File

@ -215,7 +215,7 @@ SignatureRequest.prototype.msgHexToText = function (hex) {
}
// eslint-disable-next-line react/display-name
SignatureRequest.prototype.renderTypedDataV3 = function (data) {
SignatureRequest.prototype.renderTypedData = function (data) {
const { domain, message } = JSON.parse(data)
return [
h('div.request-signature__typed-container', [
@ -267,8 +267,9 @@ SignatureRequest.prototype.renderBody = function () {
}),
}, [notice]),
h('div.request-signature__rows', type === 'eth_signTypedData' && version === 'V3' ?
this.renderTypedDataV3(data) :
h('div.request-signature__rows',
type === 'eth_signTypedData' && (version === 'V3' || version === 'V4') ?
this.renderTypedData(data) :
rows.map(({ name, value }) => {
if (typeof value === 'boolean') {
value = value.toString()