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:
parent
6e081eb17c
commit
cc71b4f52b
@ -12,6 +12,7 @@ function createMetamaskMiddleware ({
|
|||||||
processEthSignMessage,
|
processEthSignMessage,
|
||||||
processTypedMessage,
|
processTypedMessage,
|
||||||
processTypedMessageV3,
|
processTypedMessageV3,
|
||||||
|
processTypedMessageV4,
|
||||||
processPersonalMessage,
|
processPersonalMessage,
|
||||||
getPendingNonce,
|
getPendingNonce,
|
||||||
}) {
|
}) {
|
||||||
@ -27,6 +28,7 @@ function createMetamaskMiddleware ({
|
|||||||
processEthSignMessage,
|
processEthSignMessage,
|
||||||
processTypedMessage,
|
processTypedMessage,
|
||||||
processTypedMessageV3,
|
processTypedMessageV3,
|
||||||
|
processTypedMessageV4,
|
||||||
processPersonalMessage,
|
processPersonalMessage,
|
||||||
}),
|
}),
|
||||||
createPendingNonceMiddleware({ getPendingNonce }),
|
createPendingNonceMiddleware({ getPendingNonce }),
|
||||||
|
@ -141,6 +141,7 @@ module.exports = class TypedMessageManager extends EventEmitter {
|
|||||||
}, 'Expected EIP712 typed data')
|
}, 'Expected EIP712 typed data')
|
||||||
break
|
break
|
||||||
case 'V3':
|
case 'V3':
|
||||||
|
case 'V4':
|
||||||
let data
|
let data
|
||||||
assert.equal(typeof params, 'object', 'Params should be an object.')
|
assert.equal(typeof params, 'object', 'Params should be an object.')
|
||||||
assert.ok('data' in params, 'Params must include a data field.')
|
assert.ok('data' in params, 'Params must include a data field.')
|
||||||
|
@ -341,6 +341,7 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
processEthSignMessage: this.newUnsignedMessage.bind(this),
|
processEthSignMessage: this.newUnsignedMessage.bind(this),
|
||||||
processTypedMessage: this.newUnsignedTypedMessage.bind(this),
|
processTypedMessage: this.newUnsignedTypedMessage.bind(this),
|
||||||
processTypedMessageV3: this.newUnsignedTypedMessage.bind(this),
|
processTypedMessageV3: this.newUnsignedTypedMessage.bind(this),
|
||||||
|
processTypedMessageV4: this.newUnsignedTypedMessage.bind(this),
|
||||||
processPersonalMessage: this.newUnsignedPersonalMessage.bind(this),
|
processPersonalMessage: this.newUnsignedPersonalMessage.bind(this),
|
||||||
getPendingNonce: this.getPendingNonce.bind(this),
|
getPendingNonce: this.getPendingNonce.bind(this),
|
||||||
}
|
}
|
||||||
@ -1141,6 +1142,9 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
case 'V3':
|
case 'V3':
|
||||||
signature = sigUtil.signTypedData(privKey, { data: JSON.parse(cleanMsgParams.data) })
|
signature = sigUtil.signTypedData(privKey, { data: JSON.parse(cleanMsgParams.data) })
|
||||||
break
|
break
|
||||||
|
case 'V4':
|
||||||
|
signature = sigUtil.signTypedData_v4(privKey, { data: JSON.parse(cleanMsgParams.data) })
|
||||||
|
break
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
signature = await keyring.signTypedData(address, cleanMsgParams.data)
|
signature = await keyring.signTypedData(address, cleanMsgParams.data)
|
||||||
@ -1797,4 +1801,3 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
return this.keyringController.setLocked()
|
return this.keyringController.setLocked()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,7 +215,7 @@ SignatureRequest.prototype.msgHexToText = function (hex) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line react/display-name
|
// eslint-disable-next-line react/display-name
|
||||||
SignatureRequest.prototype.renderTypedDataV3 = function (data) {
|
SignatureRequest.prototype.renderTypedData = function (data) {
|
||||||
const { domain, message } = JSON.parse(data)
|
const { domain, message } = JSON.parse(data)
|
||||||
return [
|
return [
|
||||||
h('div.request-signature__typed-container', [
|
h('div.request-signature__typed-container', [
|
||||||
@ -267,8 +267,9 @@ SignatureRequest.prototype.renderBody = function () {
|
|||||||
}),
|
}),
|
||||||
}, [notice]),
|
}, [notice]),
|
||||||
|
|
||||||
h('div.request-signature__rows', type === 'eth_signTypedData' && version === 'V3' ?
|
h('div.request-signature__rows',
|
||||||
this.renderTypedDataV3(data) :
|
type === 'eth_signTypedData' && (version === 'V3' || version === 'V4') ?
|
||||||
|
this.renderTypedData(data) :
|
||||||
rows.map(({ name, value }) => {
|
rows.map(({ name, value }) => {
|
||||||
if (typeof value === 'boolean') {
|
if (typeof value === 'boolean') {
|
||||||
value = value.toString()
|
value = value.toString()
|
||||||
|
Loading…
Reference in New Issue
Block a user