aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2017-02-24 06:23:45 +0800
committerDan Finlay <dan@danfinlay.com>2017-02-24 06:23:45 +0800
commit4697aca02c669b1787e72f0648b3043270867799 (patch)
treeecc07db1ce05ec6a88612a0fa7d1c86007ef6389 /app
parent7ec25526b70473247a69ab4a3a1302e50b06f12b (diff)
downloadtangerine-wallet-browser-4697aca02c669b1787e72f0648b3043270867799.tar
tangerine-wallet-browser-4697aca02c669b1787e72f0648b3043270867799.tar.gz
tangerine-wallet-browser-4697aca02c669b1787e72f0648b3043270867799.tar.bz2
tangerine-wallet-browser-4697aca02c669b1787e72f0648b3043270867799.tar.lz
tangerine-wallet-browser-4697aca02c669b1787e72f0648b3043270867799.tar.xz
tangerine-wallet-browser-4697aca02c669b1787e72f0648b3043270867799.tar.zst
tangerine-wallet-browser-4697aca02c669b1787e72f0648b3043270867799.zip
Got personal_sign working
Also fixed bug where signing would not close popup.
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()
})
}