1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 01:39:44 +01:00

verify seedwords on log in

This commit is contained in:
Csaba Solya 2018-03-03 22:08:10 +01:00
parent 3e05b693db
commit 2b86d65d0c
3 changed files with 31 additions and 43 deletions

View File

@ -345,6 +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),
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),
@ -588,6 +589,19 @@ module.exports = class MetamaskController extends EventEmitter {
// Used when creating a first vault, to allow confirmation. // Used when creating a first vault, to allow confirmation.
// 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) => {
if (err) {
return cb(err)
}
this.configManager.setSeedWords(seedWords)
return cb(null, seedWords)
})
}
verifySeedPhrase (cb) {
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) return cb(new Error('MetamaskController - No HD Key Tree found'))
primaryKeyring.serialize() primaryKeyring.serialize()
@ -602,12 +616,11 @@ module.exports = class MetamaskController extends EventEmitter {
seedPhraseVerifier.verifyAccounts(accounts, seedWords) seedPhraseVerifier.verifyAccounts(accounts, seedWords)
.then(() => { .then(() => {
this.configManager.setSeedWords(seedWords) return cb(null, seedWords)
cb(null, seedWords)
}) })
.catch((err) => { .catch((err) => {
log.error(err) log.error(err)
cb(err) return cb(err)
}) })
}) })
}) })

View File

@ -9,16 +9,20 @@ describe('SeedPhraseVerifier', function () {
describe('verifyAccounts', function () { describe('verifyAccounts', function () {
var password = 'passw0rd1' let password = 'passw0rd1'
let hdKeyTree = 'HD Key Tree' let hdKeyTree = 'HD Key Tree'
it('should be able to verify created account with seed words', async function () { let keyringController
beforeEach(function () {
let keyringController = new KeyringController({ keyringController = new KeyringController({
initState: clone(firstTimeState), initState: clone(firstTimeState),
encryptor: mockEncryptor, encryptor: mockEncryptor,
}) })
assert(keyringController) assert(keyringController)
})
it('should be able to verify created account with seed words', async function () {
let vault = await keyringController.createNewVaultAndKeychain(password) let vault = await keyringController.createNewVaultAndKeychain(password)
let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] 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 () { 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 vault = await keyringController.createNewVaultAndKeychain(password)
let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] 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 () { 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 vault = await keyringController.createNewVaultAndKeychain(password)
let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] 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 () { 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 vault = await keyringController.createNewVaultAndKeychain(password)
let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0]
@ -104,12 +90,6 @@ describe('SeedPhraseVerifier', function () {
it('should return error with undefined existing accounts', async 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 vault = await keyringController.createNewVaultAndKeychain(password)
let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0]
@ -129,12 +109,6 @@ describe('SeedPhraseVerifier', function () {
it('should return error with empty accounts array', async 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 vault = await keyringController.createNewVaultAndKeychain(password)
let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] 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 () { 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 vault = await keyringController.createNewVaultAndKeychain(password)
let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0] let primaryKeyring = keyringController.getKeyringsByType(hdKeyTree)[0]

View File

@ -296,6 +296,13 @@ function tryUnlockMetamask (password) {
dispatch(actions.unlockSucceeded()) dispatch(actions.unlockSucceeded())
dispatch(actions.transitionForward()) dispatch(actions.transitionForward())
forceUpdateMetamaskState(dispatch) forceUpdateMetamaskState(dispatch)
background.verifySeedPhrase((err) => {
if (err) {
dispatch(actions.displayWarning(err.message))
}
})
} }
}) })
} }