Skip to content

Commit

Permalink
Add support for eth_signTypedData_v4 (#6930)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brendan Chou authored and whymarrh committed Aug 20, 2019
1 parent 6e081eb commit cc71b4f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions app/scripts/controllers/network/createMetamaskMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function createMetamaskMiddleware ({
processEthSignMessage,
processTypedMessage,
processTypedMessageV3,
processTypedMessageV4,
processPersonalMessage,
getPendingNonce,
}) {
Expand All @@ -27,6 +28,7 @@ function createMetamaskMiddleware ({
processEthSignMessage,
processTypedMessage,
processTypedMessageV3,
processTypedMessageV4,
processPersonalMessage,
}),
createPendingNonceMiddleware({ getPendingNonce }),
Expand Down
1 change: 1 addition & 0 deletions app/scripts/lib/typed-message-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand Down
5 changes: 4 additions & 1 deletion app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1797,4 +1801,3 @@ module.exports = class MetamaskController extends EventEmitter {
return this.keyringController.setLocked()
}
}

7 changes: 4 additions & 3 deletions ui/app/components/app/signature-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', [
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit cc71b4f

Please sign in to comment.