mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Validate signTypedData in eth-json-rpc-middleware
This commit is contained in:
parent
7852269ed1
commit
1d65687ce4
@ -11,6 +11,7 @@ function createMetamaskMiddleware ({
|
|||||||
processTransaction,
|
processTransaction,
|
||||||
processEthSignMessage,
|
processEthSignMessage,
|
||||||
processTypedMessage,
|
processTypedMessage,
|
||||||
|
processTypedMessageV3,
|
||||||
processPersonalMessage,
|
processPersonalMessage,
|
||||||
getPendingNonce,
|
getPendingNonce,
|
||||||
}) {
|
}) {
|
||||||
@ -25,6 +26,7 @@ function createMetamaskMiddleware ({
|
|||||||
processTransaction,
|
processTransaction,
|
||||||
processEthSignMessage,
|
processEthSignMessage,
|
||||||
processTypedMessage,
|
processTypedMessage,
|
||||||
|
processTypedMessageV3,
|
||||||
processPersonalMessage,
|
processPersonalMessage,
|
||||||
}),
|
}),
|
||||||
createPendingNonceMiddleware({ getPendingNonce }),
|
createPendingNonceMiddleware({ getPendingNonce }),
|
||||||
|
@ -275,6 +275,8 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
processTransaction: this.newUnapprovedTransaction.bind(this),
|
processTransaction: this.newUnapprovedTransaction.bind(this),
|
||||||
// msg signing
|
// msg signing
|
||||||
processEthSignMessage: this.newUnsignedMessage.bind(this),
|
processEthSignMessage: this.newUnsignedMessage.bind(this),
|
||||||
|
processTypedMessage: this.newUnsignedTypedMessage.bind(this),
|
||||||
|
processTypedMessageV3: this.newUnsignedTypedMessage.bind(this),
|
||||||
processPersonalMessage: this.newUnsignedPersonalMessage.bind(this),
|
processPersonalMessage: this.newUnsignedPersonalMessage.bind(this),
|
||||||
getPendingNonce: this.getPendingNonce.bind(this),
|
getPendingNonce: this.getPendingNonce.bind(this),
|
||||||
}
|
}
|
||||||
@ -978,8 +980,8 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
* @param {Object} msgParams - The params passed to eth_signTypedData.
|
* @param {Object} msgParams - The params passed to eth_signTypedData.
|
||||||
* @param {Function} cb - The callback function, called with the signature.
|
* @param {Function} cb - The callback function, called with the signature.
|
||||||
*/
|
*/
|
||||||
newUnsignedTypedMessage (msgParams, req) {
|
newUnsignedTypedMessage (msgParams, req, version) {
|
||||||
const promise = this.typedMessageManager.addUnapprovedMessageAsync(msgParams, req)
|
const promise = this.typedMessageManager.addUnapprovedMessageAsync(msgParams, req, version)
|
||||||
this.sendUpdate()
|
this.sendUpdate()
|
||||||
this.opts.showUnconfirmedMessage()
|
this.opts.showUnconfirmedMessage()
|
||||||
return promise
|
return promise
|
||||||
@ -1274,9 +1276,9 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
// watch asset
|
// watch asset
|
||||||
engine.push(this.preferencesController.requestWatchAsset.bind(this.preferencesController))
|
engine.push(this.preferencesController.requestWatchAsset.bind(this.preferencesController))
|
||||||
// sign typed data middleware
|
// sign typed data middleware
|
||||||
engine.push(this.createTypedDataMiddleware('eth_signTypedData', 'V1').bind(this))
|
// engine.push(this.createTypedDataMiddleware('eth_signTypedData', 'V1').bind(this))
|
||||||
engine.push(this.createTypedDataMiddleware('eth_signTypedData_v1', 'V1').bind(this))
|
// engine.push(this.createTypedDataMiddleware('eth_signTypedData_v1', 'V1').bind(this))
|
||||||
engine.push(this.createTypedDataMiddleware('eth_signTypedData_v3', 'V3', true).bind(this))
|
// engine.push(this.createTypedDataMiddleware('eth_signTypedData_v3', 'V3', true).bind(this))
|
||||||
// forward to metamask primary provider
|
// forward to metamask primary provider
|
||||||
engine.push(createProviderMiddleware({ provider }))
|
engine.push(createProviderMiddleware({ provider }))
|
||||||
|
|
||||||
@ -1542,27 +1544,27 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
* @param {Function} - next
|
* @param {Function} - next
|
||||||
* @param {Function} - end
|
* @param {Function} - end
|
||||||
*/
|
*/
|
||||||
createTypedDataMiddleware (methodName, version, reverse) {
|
// createTypedDataMiddleware (methodName, version, reverse) {
|
||||||
return async (req, res, next, end) => {
|
// return async (req, res, next, end) => {
|
||||||
const { method, params } = req
|
// const { method, params } = req
|
||||||
if (method === methodName) {
|
// if (method === methodName) {
|
||||||
const promise = this.typedMessageManager.addUnapprovedMessageAsync({
|
// const promise = this.typedMessageManager.addUnapprovedMessageAsync({
|
||||||
data: reverse ? params[1] : params[0],
|
// data: reverse ? params[1] : params[0],
|
||||||
from: reverse ? params[0] : params[1],
|
// from: reverse ? params[0] : params[1],
|
||||||
}, req, version)
|
// }, req, version)
|
||||||
this.sendUpdate()
|
// this.sendUpdate()
|
||||||
this.opts.showUnconfirmedMessage()
|
// this.opts.showUnconfirmedMessage()
|
||||||
try {
|
// try {
|
||||||
res.result = await promise
|
// res.result = await promise
|
||||||
end()
|
// end()
|
||||||
} catch (error) {
|
// } catch (error) {
|
||||||
end(error)
|
// end(error)
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
next()
|
// next()
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a domain to the {@link BlacklistController} whitelist
|
* Adds a domain to the {@link BlacklistController} whitelist
|
||||||
|
Loading…
x
Reference in New Issue
Block a user