diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index b9231aa3d..df9adc248 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -345,6 +345,7 @@ module.exports = class MetamaskController extends EventEmitter { // primary HD keyring management addNewAccount: nodeify(this.addNewAccount, this), placeSeedWords: this.placeSeedWords.bind(this), + verifySeedPhrase: this.verifySeedPhrase.bind(this), clearSeedWordCache: this.clearSeedWordCache.bind(this), resetAccount: this.resetAccount.bind(this), importAccountWithStrategy: this.importAccountWithStrategy.bind(this), @@ -588,6 +589,19 @@ module.exports = class MetamaskController extends EventEmitter { // Used when creating a first vault, to allow confirmation. // Also used when revealing the seed words in the confirmation view. placeSeedWords (cb) { + + this.verifySeedPhrase((err, seedWords) => { + + if (err) { + return cb(err) + } + this.configManager.setSeedWords(seedWords) + return cb(null, seedWords) + }) + } + + verifySeedPhrase (cb) { + const primaryKeyring = this.keyringController.getKeyringsByType('HD Key Tree')[0] if (!primaryKeyring) return cb(new Error('MetamaskController - No HD Key Tree found')) primaryKeyring.serialize() @@ -602,12 +616,11 @@ module.exports = class MetamaskController extends EventEmitter { seedPhraseVerifier.verifyAccounts(accounts, seedWords) .then(() => { - this.configManager.setSeedWords(seedWords) - cb(null, seedWords) + return cb(null, seedWords) }) .catch((err) => { log.error(err) - cb(err) + return cb(err) }) }) }) diff --git a/test/unit/seed-phrase-verifier-test.js b/test/unit/seed-phrase-verifier-test.js index 3e9acfa82..654fb5994 100644 --- a/test/unit/seed-phrase-verifier-test.js +++ b/test/unit/seed-phrase-verifier-test.js @@ -9,16 +9,20 @@ describe('SeedPhraseVerifier', function () { describe('verifyAccounts', function () { - var password = 'passw0rd1' + let password = 'passw0rd1' let hdKeyTree = 'HD Key Tree' - it('should be able to verify created account with seed words', async function () { - - let keyringController = new KeyringController({ + let keyringController + beforeEach(function () { + keyringController = new KeyringController({ initState: clone(firstTimeState), encryptor: mockEncryptor, }) + assert(keyringController) + }) + + it('should be able to verify created account with seed words', async function () { let vault = await keyringController.createNewVaultAndKeychain(password) let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] @@ -35,12 +39,6 @@ describe('SeedPhraseVerifier', function () { it('should be able to verify created account (upper case) with seed words', async function () { - let keyringController = new KeyringController({ - initState: clone(firstTimeState), - encryptor: mockEncryptor, - }) - assert(keyringController) - let vault = await keyringController.createNewVaultAndKeychain(password) let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] @@ -57,12 +55,6 @@ describe('SeedPhraseVerifier', function () { it('should be able to verify created account (lower case) with seed words', async function () { - let keyringController = new KeyringController({ - initState: clone(firstTimeState), - encryptor: mockEncryptor, - }) - assert(keyringController) - let vault = await keyringController.createNewVaultAndKeychain(password) let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] @@ -79,12 +71,6 @@ describe('SeedPhraseVerifier', function () { it('should return error with good but different seed words', async function () { - let keyringController = new KeyringController({ - initState: clone(firstTimeState), - encryptor: mockEncryptor, - }) - assert(keyringController) - let vault = await keyringController.createNewVaultAndKeychain(password) let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] @@ -104,12 +90,6 @@ describe('SeedPhraseVerifier', function () { it('should return error with undefined existing accounts', async function () { - let keyringController = new KeyringController({ - initState: clone(firstTimeState), - encryptor: mockEncryptor, - }) - assert(keyringController) - let vault = await keyringController.createNewVaultAndKeychain(password) let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] @@ -129,12 +109,6 @@ describe('SeedPhraseVerifier', function () { it('should return error with empty accounts array', async function () { - let keyringController = new KeyringController({ - initState: clone(firstTimeState), - encryptor: mockEncryptor, - }) - assert(keyringController) - let vault = await keyringController.createNewVaultAndKeychain(password) let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] @@ -154,12 +128,6 @@ describe('SeedPhraseVerifier', function () { it('should be able to verify more than one created account with seed words', async function () { - let keyringController = new KeyringController({ - initState: clone(firstTimeState), - encryptor: mockEncryptor, - }) - assert(keyringController) - let vault = await keyringController.createNewVaultAndKeychain(password) let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] diff --git a/ui/app/actions.js b/ui/app/actions.js index 64d5b67e0..9606841ae 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -296,6 +296,13 @@ function tryUnlockMetamask (password) { dispatch(actions.unlockSucceeded()) dispatch(actions.transitionForward()) forceUpdateMetamaskState(dispatch) + + background.verifySeedPhrase((err) => { + if (err) { + dispatch(actions.displayWarning(err.message)) + } + }) + } }) }