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

Add signTypedData input validations

This commit is contained in:
Dan Finlay 2017-10-05 14:39:35 -07:00
parent 176d03b2e8
commit 9bc80d998e
2 changed files with 20 additions and 4 deletions

View File

@ -1,6 +1,7 @@
const EventEmitter = require('events')
const ObservableStore = require('obs-store')
const createId = require('./random-id')
const assert = require('assert')
module.exports = class TypedMessageManager extends EventEmitter {
@ -23,6 +24,8 @@ module.exports = class TypedMessageManager extends EventEmitter {
}
addUnapprovedMessage (msgParams) {
this.validateParams(msgParams)
log.debug(`TypedMessageManager addUnapprovedMessage: ${JSON.stringify(msgParams)}`)
// create txData obj with parameters and meta data
var time = (new Date()).getTime()
@ -41,6 +44,14 @@ module.exports = class TypedMessageManager extends EventEmitter {
return msgId
}
validateParams (params) {
assert.equal(typeof params, 'object', 'Params should ben an object.')
assert.ok('data' in params, 'Params must include a data field.')
assert.ok('from' in params, 'Params must include a from field.')
assert.ok(Array.isArray(params.data), 'Data should be an array.')
assert.equal(typeof params.from, 'string', 'From field must be a string.')
}
addMsg (msg) {
this.messages.push(msg)
this._saveMsgList()

View File

@ -566,11 +566,16 @@ module.exports = class MetamaskController extends EventEmitter {
}
newUnsignedTypedMessage (msgParams, cb) {
const msgId = this.typedMessageManager.addUnapprovedMessage(msgParams)
this.sendUpdate()
this.opts.showUnconfirmedMessage()
let msgId
try {
msgId = this.typedMessageManager.addUnapprovedMessage(msgParams)
this.sendUpdate()
this.opts.showUnconfirmedMessage()
} catch (e) {
return cb(e)
}
this.typedMessageManager.once(`${msgId}:finished`, (data) => {
console.log(data)
switch (data.status) {
case 'signed':
return cb(null, data.rawSig)