1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 19:26:13 +02:00

Merge pull request #2605 from MetaMask/i2577-SeedPhraseBug

Fix a possible seed phrase bug
This commit is contained in:
Thomas Huang 2017-11-27 13:37:42 -06:00 committed by GitHub
commit e71115735c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 68 additions and 5 deletions

View File

@ -2,6 +2,7 @@
## Current Master
- Fix bug where a user could be shown two different seed phrases.
- Detect when multiple web3 extensions are active, and provide useful error.
## 3.12.0 2017-10-25

View File

@ -31,6 +31,7 @@ const ConfigManager = require('./lib/config-manager')
const nodeify = require('./lib/nodeify')
const accountImporter = require('./account-import-strategies')
const getBuyEthUrl = require('./lib/buy-eth-url')
const Mutex = require('await-semaphore').Mutex
const version = require('../manifest.json').version
module.exports = class MetamaskController extends EventEmitter {
@ -38,6 +39,7 @@ module.exports = class MetamaskController extends EventEmitter {
constructor (opts) {
super()
this.sendUpdate = debounce(this.privateSendUpdate.bind(this), 200)
this.opts = opts
@ -49,6 +51,9 @@ module.exports = class MetamaskController extends EventEmitter {
// observable state store
this.store = new ObservableStore(initState)
// lock to ensure only one vault created at once
this.createVaultMutex = new Mutex()
// network store
this.networkController = new NetworkController(initState.NetworkController)
@ -467,15 +472,34 @@ module.exports = class MetamaskController extends EventEmitter {
// Vault Management
//
async createNewVaultAndKeychain (password, cb) {
const vault = await this.keyringController.createNewVaultAndKeychain(password)
this.selectFirstIdentity(vault)
async createNewVaultAndKeychain (password) {
const release = await this.createVaultMutex.acquire()
let vault
try {
const accounts = await this.keyringController.getAccounts()
if (accounts.length > 0) {
vault = await this.keyringController.fullUpdate()
} else {
let vault = await this.keyringController.createNewVaultAndKeychain(password)
this.selectFirstIdentity(vault)
}
release()
} catch (err) {
release()
throw err
}
return vault
}
async createNewVaultAndRestore (password, seed, cb) {
async createNewVaultAndRestore (password, seed) {
const release = await this.createVaultMutex.acquire()
const vault = await this.keyringController.createNewVaultAndRestore(password, seed)
this.selectFirstIdentity(vault)
release()
return vault
}

View File

@ -11,6 +11,15 @@ describe('MetaMaskController', function () {
unlockAccountMessage: noop,
showUnapprovedTx: noop,
platform: {},
encryptor: {
encrypt: function(password, object) {
this.object = object
return Promise.resolve()
},
decrypt: function () {
return Promise.resolve(this.object)
}
},
// initial state
initState: clone(firstTimeState),
})
@ -27,6 +36,30 @@ describe('MetaMaskController', function () {
describe('Metamask Controller', function () {
assert(metamaskController)
beforeEach(function () {
sinon.spy(metamaskController.keyringController, 'createNewVaultAndKeychain')
})
afterEach(function () {
metamaskController.keyringController.createNewVaultAndKeychain.restore()
})
describe('#createNewVaultAndKeychain', function () {
it('can only create new vault on keyringController once', async function () {
const selectStub = sinon.stub(metamaskController, 'selectFirstIdentity')
const password = 'a-fake-password'
const first = await metamaskController.createNewVaultAndKeychain(password)
const second = await metamaskController.createNewVaultAndKeychain(password)
assert(metamaskController.keyringController.createNewVaultAndKeychain.calledOnce)
selectStub.reset()
})
})
})
})

View File

@ -8,6 +8,8 @@ const actions = require('../actions')
const Tooltip = require('../components/tooltip')
const getCaretCoordinates = require('textarea-caret')
let isSubmitting = false
module.exports = connect(mapStateToProps)(InitializeMenuScreen)
inherits(InitializeMenuScreen, Component)
@ -164,7 +166,10 @@ InitializeMenuScreen.prototype.createNewVaultAndKeychain = function () {
return
}
this.props.dispatch(actions.createNewVaultAndKeychain(password))
if (!isSubmitting) {
isSubmitting = true
this.props.dispatch(actions.createNewVaultAndKeychain(password))
}
}
InitializeMenuScreen.prototype.inputChanged = function (event) {