diff options
Diffstat (limited to 'app/scripts/keyring-controller.js')
-rw-r--r-- | app/scripts/keyring-controller.js | 107 |
1 files changed, 21 insertions, 86 deletions
diff --git a/app/scripts/keyring-controller.js b/app/scripts/keyring-controller.js index be54ab00b..12e3d2844 100644 --- a/app/scripts/keyring-controller.js +++ b/app/scripts/keyring-controller.js @@ -5,11 +5,7 @@ const EventEmitter = require('events').EventEmitter const ObservableStore = require('obs-store') const filter = require('promise-filter') const encryptor = require('browser-passworder') -const createId = require('./lib/random-id') const normalizeAddress = require('./lib/sig-util').normalize -const messageManager = require('./lib/message-manager') -function noop () {} - // Keyrings: const SimpleKeyring = require('./keyrings/simple') const HdKeyring = require('./keyrings/hd') @@ -18,7 +14,6 @@ const keyringTypes = [ HdKeyring, ] - class KeyringController extends EventEmitter { // PUBLIC METHODS @@ -42,9 +37,7 @@ class KeyringController extends EventEmitter { this.ethStore = opts.ethStore this.encryptor = encryptor this.keyrings = [] - - this._unconfMsgCbs = {} - + this.identities = {} // Essentially a name hash this.getNetwork = opts.getNetwork } @@ -78,6 +71,7 @@ class KeyringController extends EventEmitter { // in this class, but will need to be Promisified when we move our // persistence to an async model. getState () { + // old wallet const memState = this.memStore.getState() const result = { @@ -87,9 +81,6 @@ class KeyringController extends EventEmitter { keyringTypes: memState.keyringTypes, identities: memState.identities, keyrings: memState.keyrings, - // messageManager - unconfMsgs: messageManager.unconfirmedMsgs(), - messages: messageManager.getMsgList(), // configManager seedWords: this.configManager.getSeedWords(), isDisclaimerConfirmed: this.configManager.getConfirmedDisclaimer(), @@ -153,6 +144,17 @@ class KeyringController extends EventEmitter { .then(this.fullUpdate.bind(this)) } + // ClearSeedWordCache + // + // returns Promise( @string currentSelectedAccount ) + // + // Removes the current vault's seed words from the UI's state tree, + // ensuring they are only ever available in the background process. + clearSeedWordCache () { + this.configManager.setSeedWords(null) + return Promise.resolve(this.configManager.getSelectedAccount()) + } + // Set Locked // returns Promise( @object state ) // @@ -204,8 +206,8 @@ class KeyringController extends EventEmitter { this.keyrings.push(keyring) return this.setupAccounts(accounts) }) - .then(() => this.persistAllKeyrings()) - .then(() => this.fullUpdate()) + .then(() => { return this.password }) + .then(this.persistAllKeyrings.bind(this)) .then(() => { return keyring }) @@ -284,86 +286,19 @@ class KeyringController extends EventEmitter { return keyring.signTransaction(fromAddress, ethTx) }) } - // Add Unconfirmed Message - // @object msgParams - // @function cb - // - // Does not call back, only emits an `update` event. - // - // Adds the given `msgParams` and `cb` to a local cache, - // for displaying to a user for approval before signing or canceling. - addUnconfirmedMessage (msgParams, cb) { - // create txData obj with parameters and meta data - var time = (new Date()).getTime() - var msgId = createId() - var msgData = { - id: msgId, - msgParams: msgParams, - time: time, - status: 'unconfirmed', - } - messageManager.addMsg(msgData) - console.log('addUnconfirmedMessage:', msgData) - - // keep the cb around for after approval (requires user interaction) - // This cb fires completion to the Dapp's write operation. - this._unconfMsgCbs[msgId] = cb - - // signal update - this.emit('update') - return msgId - } - - // Cancel Message - // @string msgId - // @function cb (optional) - // - // Calls back to cached `unconfMsgCb`. - // Calls back to `cb` if provided. - // - // Forgets any messages matching `msgId`. - cancelMessage (msgId, cb) { - var approvalCb = this._unconfMsgCbs[msgId] || noop - - // reject tx - approvalCb(null, false) - // clean up - messageManager.rejectMsg(msgId) - delete this._unconfTxCbs[msgId] - - if (cb && typeof cb === 'function') { - cb() - } - } // Sign Message // @object msgParams - // @function cb // // returns Promise(@buffer rawSig) - // calls back @function cb with @buffer rawSig - // calls back cached Dapp's @function unconfMsgCb. // // Attempts to sign the provided @object msgParams. - signMessage (msgParams, cb) { - try { - const msgId = msgParams.metamaskId - delete msgParams.metamaskId - const approvalCb = this._unconfMsgCbs[msgId] || noop - - const address = normalizeAddress(msgParams.from) - return this.getKeyringForAccount(address) - .then((keyring) => { - return keyring.signMessage(address, msgParams.data) - }).then((rawSig) => { - cb(null, rawSig) - approvalCb(null, true) - messageManager.confirmMsg(msgId) - return rawSig - }) - } catch (e) { - cb(e) - } + signMessage (msgParams) { + const address = normalizeAddress(msgParams.from) + return this.getKeyringForAccount(address) + .then((keyring) => { + return keyring.signMessage(address, msgParams.data) + }) } // PRIVATE METHODS |