aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/metamask-controller.js
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/scripts/metamask-controller.js
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/scripts/metamask-controller.js')
-rw-r--r--app/scripts/metamask-controller.js55
1 files changed, 36 insertions, 19 deletions
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()
})
}