mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
modify verifySeedPhrase to async and call it from addNewAccount also
This commit is contained in:
parent
8fde208f0b
commit
59007a6c36
@ -345,7 +345,7 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
// primary HD keyring management
|
// primary HD keyring management
|
||||||
addNewAccount: nodeify(this.addNewAccount, this),
|
addNewAccount: nodeify(this.addNewAccount, this),
|
||||||
placeSeedWords: this.placeSeedWords.bind(this),
|
placeSeedWords: this.placeSeedWords.bind(this),
|
||||||
verifySeedPhrase: this.verifySeedPhrase.bind(this),
|
verifySeedPhrase: nodeify(this.verifySeedPhrase, this),
|
||||||
clearSeedWordCache: this.clearSeedWordCache.bind(this),
|
clearSeedWordCache: this.clearSeedWordCache.bind(this),
|
||||||
resetAccount: this.resetAccount.bind(this),
|
resetAccount: this.resetAccount.bind(this),
|
||||||
importAccountWithStrategy: this.importAccountWithStrategy.bind(this),
|
importAccountWithStrategy: this.importAccountWithStrategy.bind(this),
|
||||||
@ -567,14 +567,18 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
// Opinionated Keyring Management
|
// Opinionated Keyring Management
|
||||||
//
|
//
|
||||||
|
|
||||||
async addNewAccount (cb) {
|
async addNewAccount () {
|
||||||
const primaryKeyring = this.keyringController.getKeyringsByType('HD Key Tree')[0]
|
const primaryKeyring = this.keyringController.getKeyringsByType('HD Key Tree')[0]
|
||||||
if (!primaryKeyring) return cb(new Error('MetamaskController - No HD Key Tree found'))
|
if (!primaryKeyring) {
|
||||||
|
throw new Error('MetamaskController - No HD Key Tree found')
|
||||||
|
}
|
||||||
const keyringController = this.keyringController
|
const keyringController = this.keyringController
|
||||||
const oldAccounts = await keyringController.getAccounts()
|
const oldAccounts = await keyringController.getAccounts()
|
||||||
const keyState = await keyringController.addNewAccount(primaryKeyring)
|
const keyState = await keyringController.addNewAccount(primaryKeyring)
|
||||||
const newAccounts = await keyringController.getAccounts()
|
const newAccounts = await keyringController.getAccounts()
|
||||||
|
|
||||||
|
await this.verifySeedPhrase()
|
||||||
|
|
||||||
newAccounts.forEach((address) => {
|
newAccounts.forEach((address) => {
|
||||||
if (!oldAccounts.includes(address)) {
|
if (!oldAccounts.includes(address)) {
|
||||||
this.preferencesController.setSelectedAddress(address)
|
this.preferencesController.setSelectedAddress(address)
|
||||||
@ -590,44 +594,42 @@ module.exports = class MetamaskController extends EventEmitter {
|
|||||||
// Also used when revealing the seed words in the confirmation view.
|
// Also used when revealing the seed words in the confirmation view.
|
||||||
placeSeedWords (cb) {
|
placeSeedWords (cb) {
|
||||||
|
|
||||||
this.verifySeedPhrase((err, seedWords) => {
|
this.verifySeedPhrase()
|
||||||
|
.then((seedWords) => {
|
||||||
if (err) {
|
this.configManager.setSeedWords(seedWords)
|
||||||
|
return cb(null, seedWords)
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
return cb(err)
|
return cb(err)
|
||||||
}
|
})
|
||||||
this.configManager.setSeedWords(seedWords)
|
|
||||||
return cb(null, seedWords)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verifies the current vault's seed words if they can restore the
|
// Verifies the current vault's seed words if they can restore the
|
||||||
// accounts belonging to the current vault.
|
// accounts belonging to the current vault.
|
||||||
//
|
//
|
||||||
// Called when the first account is created and on unlocking the vault.
|
// Called when the first account is created and on unlocking the vault.
|
||||||
verifySeedPhrase (cb) {
|
async verifySeedPhrase () {
|
||||||
|
|
||||||
const primaryKeyring = this.keyringController.getKeyringsByType('HD Key Tree')[0]
|
const primaryKeyring = this.keyringController.getKeyringsByType('HD Key Tree')[0]
|
||||||
if (!primaryKeyring) return cb(new Error('MetamaskController - No HD Key Tree found'))
|
if (!primaryKeyring) {
|
||||||
primaryKeyring.serialize()
|
throw new Error('MetamaskController - No HD Key Tree found')
|
||||||
.then((serialized) => {
|
}
|
||||||
const seedWords = serialized.mnemonic
|
|
||||||
|
|
||||||
primaryKeyring.getAccounts()
|
const serialized = await primaryKeyring.serialize()
|
||||||
.then((accounts) => {
|
const seedWords = serialized.mnemonic
|
||||||
if (accounts.length < 1) {
|
|
||||||
return cb(new Error('MetamaskController - No accounts found'))
|
|
||||||
}
|
|
||||||
|
|
||||||
seedPhraseVerifier.verifyAccounts(accounts, seedWords)
|
const accounts = await primaryKeyring.getAccounts()
|
||||||
.then(() => {
|
if (accounts.length < 1) {
|
||||||
return cb(null, seedWords)
|
throw new Error('MetamaskController - No accounts found')
|
||||||
})
|
}
|
||||||
.catch((err) => {
|
|
||||||
log.error(err)
|
try {
|
||||||
return cb(err)
|
await seedPhraseVerifier.verifyAccounts(accounts, seedWords)
|
||||||
})
|
return seedWords
|
||||||
})
|
} catch (err) {
|
||||||
})
|
log.error(err.message)
|
||||||
|
throw err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClearSeedWordCache
|
// ClearSeedWordCache
|
||||||
|
Loading…
x
Reference in New Issue
Block a user