|
|
@ -25,6 +25,7 @@ const InfuraController = require('./controllers/infura') |
|
|
|
const BlacklistController = require('./controllers/blacklist') |
|
|
|
const BlacklistController = require('./controllers/blacklist') |
|
|
|
const MessageManager = require('./lib/message-manager') |
|
|
|
const MessageManager = require('./lib/message-manager') |
|
|
|
const PersonalMessageManager = require('./lib/personal-message-manager') |
|
|
|
const PersonalMessageManager = require('./lib/personal-message-manager') |
|
|
|
|
|
|
|
const TypedMessageManager = require('./lib/typed-message-manager') |
|
|
|
const TransactionController = require('./controllers/transactions') |
|
|
|
const TransactionController = require('./controllers/transactions') |
|
|
|
const BalancesController = require('./controllers/computed-balances') |
|
|
|
const BalancesController = require('./controllers/computed-balances') |
|
|
|
const ConfigManager = require('./lib/config-manager') |
|
|
|
const ConfigManager = require('./lib/config-manager') |
|
|
@ -161,6 +162,7 @@ module.exports = class MetamaskController extends EventEmitter { |
|
|
|
this.networkController.lookupNetwork() |
|
|
|
this.networkController.lookupNetwork() |
|
|
|
this.messageManager = new MessageManager() |
|
|
|
this.messageManager = new MessageManager() |
|
|
|
this.personalMessageManager = new PersonalMessageManager() |
|
|
|
this.personalMessageManager = new PersonalMessageManager() |
|
|
|
|
|
|
|
this.typedMessageManager = new TypedMessageManager() |
|
|
|
this.publicConfigStore = this.initPublicConfigStore() |
|
|
|
this.publicConfigStore = this.initPublicConfigStore() |
|
|
|
|
|
|
|
|
|
|
|
// manual disk state subscriptions
|
|
|
|
// manual disk state subscriptions
|
|
|
@ -202,6 +204,7 @@ module.exports = class MetamaskController extends EventEmitter { |
|
|
|
this.balancesController.store.subscribe(this.sendUpdate.bind(this)) |
|
|
|
this.balancesController.store.subscribe(this.sendUpdate.bind(this)) |
|
|
|
this.messageManager.memStore.subscribe(this.sendUpdate.bind(this)) |
|
|
|
this.messageManager.memStore.subscribe(this.sendUpdate.bind(this)) |
|
|
|
this.personalMessageManager.memStore.subscribe(this.sendUpdate.bind(this)) |
|
|
|
this.personalMessageManager.memStore.subscribe(this.sendUpdate.bind(this)) |
|
|
|
|
|
|
|
this.typedMessageManager.memStore.subscribe(this.sendUpdate.bind(this)) |
|
|
|
this.keyringController.memStore.subscribe(this.sendUpdate.bind(this)) |
|
|
|
this.keyringController.memStore.subscribe(this.sendUpdate.bind(this)) |
|
|
|
this.preferencesController.store.subscribe(this.sendUpdate.bind(this)) |
|
|
|
this.preferencesController.store.subscribe(this.sendUpdate.bind(this)) |
|
|
|
this.addressBookController.store.subscribe(this.sendUpdate.bind(this)) |
|
|
|
this.addressBookController.store.subscribe(this.sendUpdate.bind(this)) |
|
|
@ -239,6 +242,7 @@ module.exports = class MetamaskController extends EventEmitter { |
|
|
|
processMessage: this.newUnsignedMessage.bind(this), |
|
|
|
processMessage: this.newUnsignedMessage.bind(this), |
|
|
|
// personal_sign msg signing
|
|
|
|
// personal_sign msg signing
|
|
|
|
processPersonalMessage: this.newUnsignedPersonalMessage.bind(this), |
|
|
|
processPersonalMessage: this.newUnsignedPersonalMessage.bind(this), |
|
|
|
|
|
|
|
processTypedMessage: this.newUnsignedTypedMessage.bind(this), |
|
|
|
} |
|
|
|
} |
|
|
|
const providerProxy = this.networkController.initializeProvider(providerOpts) |
|
|
|
const providerProxy = this.networkController.initializeProvider(providerOpts) |
|
|
|
return providerProxy |
|
|
|
return providerProxy |
|
|
@ -283,6 +287,7 @@ module.exports = class MetamaskController extends EventEmitter { |
|
|
|
this.txController.memStore.getState(), |
|
|
|
this.txController.memStore.getState(), |
|
|
|
this.messageManager.memStore.getState(), |
|
|
|
this.messageManager.memStore.getState(), |
|
|
|
this.personalMessageManager.memStore.getState(), |
|
|
|
this.personalMessageManager.memStore.getState(), |
|
|
|
|
|
|
|
this.typedMessageManager.memStore.getState(), |
|
|
|
this.keyringController.memStore.getState(), |
|
|
|
this.keyringController.memStore.getState(), |
|
|
|
this.balancesController.store.getState(), |
|
|
|
this.balancesController.store.getState(), |
|
|
|
this.preferencesController.store.getState(), |
|
|
|
this.preferencesController.store.getState(), |
|
|
@ -364,6 +369,10 @@ module.exports = class MetamaskController extends EventEmitter { |
|
|
|
signPersonalMessage: nodeify(this.signPersonalMessage, this), |
|
|
|
signPersonalMessage: nodeify(this.signPersonalMessage, this), |
|
|
|
cancelPersonalMessage: this.cancelPersonalMessage.bind(this), |
|
|
|
cancelPersonalMessage: this.cancelPersonalMessage.bind(this), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// personalMessageManager
|
|
|
|
|
|
|
|
signTypedMessage: nodeify(this.signTypedMessage, this), |
|
|
|
|
|
|
|
cancelTypedMessage: this.cancelTypedMessage.bind(this), |
|
|
|
|
|
|
|
|
|
|
|
// notices
|
|
|
|
// notices
|
|
|
|
checkNotices: noticeController.updateNoticesList.bind(noticeController), |
|
|
|
checkNotices: noticeController.updateNoticesList.bind(noticeController), |
|
|
|
markNoticeRead: noticeController.markNoticeRead.bind(noticeController), |
|
|
|
markNoticeRead: noticeController.markNoticeRead.bind(noticeController), |
|
|
@ -556,6 +565,28 @@ module.exports = class MetamaskController extends EventEmitter { |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
newUnsignedTypedMessage (msgParams, cb) { |
|
|
|
|
|
|
|
let msgId |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
msgId = this.typedMessageManager.addUnapprovedMessage(msgParams) |
|
|
|
|
|
|
|
this.sendUpdate() |
|
|
|
|
|
|
|
this.opts.showUnconfirmedMessage() |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
return cb(e) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.typedMessageManager.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 message signature.')) |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
return cb(new Error(`MetaMask Message Signature: Unknown problem: ${JSON.stringify(msgParams)}`)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
signMessage (msgParams, cb) { |
|
|
|
signMessage (msgParams, cb) { |
|
|
|
log.info('MetaMaskController - signMessage') |
|
|
|
log.info('MetaMaskController - signMessage') |
|
|
|
const msgId = msgParams.metamaskId |
|
|
|
const msgId = msgParams.metamaskId |
|
|
@ -618,6 +649,24 @@ module.exports = class MetamaskController extends EventEmitter { |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
signTypedMessage (msgParams) { |
|
|
|
|
|
|
|
log.info('MetaMaskController - signTypedMessage') |
|
|
|
|
|
|
|
const msgId = msgParams.metamaskId |
|
|
|
|
|
|
|
// sets the status op the message to 'approved'
|
|
|
|
|
|
|
|
// and removes the metamaskId for signing
|
|
|
|
|
|
|
|
return this.typedMessageManager.approveMessage(msgParams) |
|
|
|
|
|
|
|
.then((cleanMsgParams) => { |
|
|
|
|
|
|
|
// signs the message
|
|
|
|
|
|
|
|
return this.keyringController.signTypedMessage(cleanMsgParams) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.then((rawSig) => { |
|
|
|
|
|
|
|
// tells the listener that the message has been signed
|
|
|
|
|
|
|
|
// and can be returned to the dapp
|
|
|
|
|
|
|
|
this.typedMessageManager.setMsgStatusSigned(msgId, rawSig) |
|
|
|
|
|
|
|
return this.getState() |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
cancelPersonalMessage (msgId, cb) { |
|
|
|
cancelPersonalMessage (msgId, cb) { |
|
|
|
const messageManager = this.personalMessageManager |
|
|
|
const messageManager = this.personalMessageManager |
|
|
|
messageManager.rejectMsg(msgId) |
|
|
|
messageManager.rejectMsg(msgId) |
|
|
@ -626,6 +675,14 @@ module.exports = class MetamaskController extends EventEmitter { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cancelTypedMessage (msgId, cb) { |
|
|
|
|
|
|
|
const messageManager = this.typedMessageManager |
|
|
|
|
|
|
|
messageManager.rejectMsg(msgId) |
|
|
|
|
|
|
|
if (cb && typeof cb === 'function') { |
|
|
|
|
|
|
|
cb(null, this.getState()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
markAccountsFound (cb) { |
|
|
|
markAccountsFound (cb) { |
|
|
|
this.configManager.setLostAccounts([]) |
|
|
|
this.configManager.setLostAccounts([]) |
|
|
|
this.sendUpdate() |
|
|
|
this.sendUpdate() |
|
|
|