aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/scripts/background.js4
-rw-r--r--app/scripts/lib/personal-message-manager.js4
-rw-r--r--app/scripts/metamask-controller.js55
3 files changed, 42 insertions, 21 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js
index 2e5a992b9..254737dec 100644
--- a/app/scripts/background.js
+++ b/app/scripts/background.js
@@ -15,6 +15,10 @@ const firstTimeState = require('./first-time-state')
const STORAGE_KEY = 'metamask-config'
const METAMASK_DEBUG = 'GULP_METAMASK_DEBUG'
+const log = require('loglevel')
+window.log = log
+log.setDefaultLevel(METAMASK_DEBUG ? 'debug' : 'warn')
+
let popupIsOpen = false
// state persistence
diff --git a/app/scripts/lib/personal-message-manager.js b/app/scripts/lib/personal-message-manager.js
index 65ad9200a..3b8510767 100644
--- a/app/scripts/lib/personal-message-manager.js
+++ b/app/scripts/lib/personal-message-manager.js
@@ -4,7 +4,7 @@ const ethUtil = require('ethereumjs-util')
const createId = require('./random-id')
-module.exports = class MessageManager extends EventEmitter{
+module.exports = class PersonalMessageManager extends EventEmitter{
constructor (opts) {
super()
this.memStore = new ObservableStore({
@@ -82,7 +82,7 @@ module.exports = class MessageManager extends EventEmitter{
_setMsgStatus (msgId, status) {
const msg = this.getMsg(msgId)
- if (!msg) throw new Error('MessageManager - Message not found for id: "${msgId}".')
+ if (!msg) throw new Error('PersonalMessageManager - Message not found for id: "${msgId}".')
msg.status = status
this._updateMsg(msg)
this.emit(`${msgId}:${status}`, msg)
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index b109918cf..c301e2035 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -170,8 +170,7 @@ module.exports = class MetamaskController extends EventEmitter {
processMessage: this.newUnsignedMessage.bind(this),
// new style msg signing
- approvePersonalMessage: this.approvePersonalMessage.bind(this),
- signPersonalMessage: nodeify(this.signPersonalMessage).bind(this),
+ processPersonalMessage: this.newUnsignedPersonalMessage.bind(this),
personalRecoverSigner: nodeify(this.recoverPersonalMessage).bind(this),
})
return provider
@@ -283,11 +282,11 @@ module.exports = class MetamaskController extends EventEmitter {
cancelTransaction: txManager.cancelTransaction.bind(txManager),
// messageManager
- signMessage: this.signMessage.bind(this),
+ signMessage: nodeify(this.signMessage).bind(this),
cancelMessage: messageManager.rejectMsg.bind(messageManager),
// personalMessageManager
- signPersonalMessage: this.signPersonalMessage.bind(this),
+ signPersonalMessage: nodeify(this.signPersonalMessage).bind(this),
cancelPersonalMessage: personalMessageManager.rejectMsg.bind(personalMessageManager),
// notices
@@ -445,22 +444,39 @@ module.exports = class MetamaskController extends EventEmitter {
})
}
+ newUnsignedPersonalMessage (msgParams, cb) {
+ let msgId = this.personalMessageManager.addUnapprovedMessage(msgParams)
+ this.sendUpdate()
+ this.opts.showUnconfirmedMessage()
+ this.personalMessageManager.once(`${msgId}:finished`, (data) => {
+ switch (data.status) {
+ case 'signed':
+ return cb(null, data.rawSig)
+ case 'rejected':
+ return cb(new Error('MetaMask Message Signature: User denied transaction signature.'))
+ default:
+ return cb(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`))
+ }
+ })
+ }
+
signMessage (msgParams, cb) {
+ log.info('MetaMaskController - signMessage')
const msgId = msgParams.metamaskId
- promiseToCallback(
- // sets the status op the message to 'approved'
- // and removes the metamaskId for signing
- this.messageManager.approveMessage(msgParams)
- .then((cleanMsgParams) => {
- // signs the message
- return this.keyringController.signMessage(cleanMsgParams)
- })
- .then((rawSig) => {
- // tells the listener that the message has been signed
- // and can be returned to the dapp
- this.messageManager.setMsgStatusSigned(msgId, rawSig)
- })
- )(cb)
+
+ // sets the status op the message to 'approved'
+ // and removes the metamaskId for signing
+ return this.messageManager.approveMessage(msgParams)
+ .then((cleanMsgParams) => {
+ // signs the message
+ return this.keyringController.signMessage(cleanMsgParams)
+ })
+ .then((rawSig) => {
+ // tells the listener that the message has been signed
+ // and can be returned to the dapp
+ this.messageManager.setMsgStatusSigned(msgId, rawSig)
+ return this.getState()
+ })
}
// Prefixed Style Message Signing Methods:
@@ -481,6 +497,7 @@ module.exports = class MetamaskController extends EventEmitter {
}
signPersonalMessage (msgParams) {
+ log.info('MetaMaskController - signPersonalMessage')
const msgId = msgParams.metamaskId
// sets the status op the message to 'approved'
// and removes the metamaskId for signing
@@ -493,7 +510,7 @@ module.exports = class MetamaskController extends EventEmitter {
// tells the listener that the message has been signed
// and can be returned to the dapp
this.personalMessageManager.setMsgStatusSigned(msgId, rawSig)
- return rawSig
+ return this.getState()
})
}