mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Fix account unlocking
SubmitPassword was not creating a new id-management This is because I broke up the old "createIdmgmt" method to not perform as much conditional logic. Now the pieces are reusable and do what they should do.
This commit is contained in:
parent
fcc9ca812e
commit
363c2a0939
@ -1,3 +1,11 @@
|
|||||||
|
/* ID Management
|
||||||
|
*
|
||||||
|
* This module exists to hold the decrypted credentials for the current session.
|
||||||
|
* It therefore exposes sign methods, because it is able to perform these
|
||||||
|
* with noa dditional authentication, because its very instantiation
|
||||||
|
* means the vault is unlocked.
|
||||||
|
*/
|
||||||
|
|
||||||
const ethUtil = require('ethereumjs-util')
|
const ethUtil = require('ethereumjs-util')
|
||||||
const Transaction = require('ethereumjs-tx')
|
const Transaction = require('ethereumjs-tx')
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ IdentityStore.prototype.createNewVault = function (password, entropy, cb) {
|
|||||||
this.configManager.setData({})
|
this.configManager.setData({})
|
||||||
}
|
}
|
||||||
|
|
||||||
this._createIdmgmt(password, null, entropy, (err) => {
|
this._createVault(password, null, entropy, (err) => {
|
||||||
if (err) return cb(err)
|
if (err) return cb(err)
|
||||||
|
|
||||||
this._autoFaucet()
|
this._autoFaucet()
|
||||||
@ -72,7 +72,7 @@ IdentityStore.prototype.recoverSeed = function (cb) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
IdentityStore.prototype.recoverFromSeed = function (password, seed, cb) {
|
IdentityStore.prototype.recoverFromSeed = function (password, seed, cb) {
|
||||||
this._createIdmgmt(password, seed, null, (err) => {
|
this._createVault(password, seed, null, (err) => {
|
||||||
if (err) return cb(err)
|
if (err) return cb(err)
|
||||||
|
|
||||||
this._loadIdentities()
|
this._loadIdentities()
|
||||||
@ -449,11 +449,12 @@ IdentityStore.prototype.tryPassword = function (password, cb) {
|
|||||||
const isCorrect = keyStore.isDerivedKeyCorrect(pwDerivedKey)
|
const isCorrect = keyStore.isDerivedKeyCorrect(pwDerivedKey)
|
||||||
if (!isCorrect) return cb(new Error('Lightwallet - password incorrect'))
|
if (!isCorrect) return cb(new Error('Lightwallet - password incorrect'))
|
||||||
|
|
||||||
|
this._createIdMgmt(derivedKey)
|
||||||
cb()
|
cb()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
IdentityStore.prototype._createIdmgmt = function (password, seedPhrase, entropy, cb) {
|
IdentityStore.prototype._createVault = function (password, seedPhrase, entropy, cb) {
|
||||||
const opts = {
|
const opts = {
|
||||||
password,
|
password,
|
||||||
hdPathString: this.hdPathString,
|
hdPathString: this.hdPathString,
|
||||||
@ -476,13 +477,7 @@ IdentityStore.prototype._createIdmgmt = function (password, seedPhrase, entropy,
|
|||||||
keyStore.addHdDerivationPath(this.hdPathString, derivedKey, {curve: 'secp256k1', purpose: 'sign'})
|
keyStore.addHdDerivationPath(this.hdPathString, derivedKey, {curve: 'secp256k1', purpose: 'sign'})
|
||||||
|
|
||||||
this._createFirstWallet(derivedKey)
|
this._createFirstWallet(derivedKey)
|
||||||
|
this._createIdMgmt(derivedKey)
|
||||||
this._idmgmt = new IdManagement({
|
|
||||||
keyStore: keyStore,
|
|
||||||
derivedKey: derivedKey,
|
|
||||||
configManager: this.configManager,
|
|
||||||
})
|
|
||||||
|
|
||||||
this.setSelectedAddressSync()
|
this.setSelectedAddressSync()
|
||||||
|
|
||||||
cb()
|
cb()
|
||||||
@ -490,6 +485,14 @@ IdentityStore.prototype._createIdmgmt = function (password, seedPhrase, entropy,
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IdentityStore.prototype._createIdMgmt = function (derivedKey) {
|
||||||
|
this._idmgmt = new IdManagement({
|
||||||
|
keyStore: this.keyStore,
|
||||||
|
derivedKey: derivedKey,
|
||||||
|
configManager: this.configManager,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
IdentityStore.prototype.purgeCache = function () {
|
IdentityStore.prototype.purgeCache = function () {
|
||||||
this._getAddresses().forEach((address) => {
|
this._getAddresses().forEach((address) => {
|
||||||
this._ethStore.del(address)
|
this._ethStore.del(address)
|
||||||
|
@ -109,6 +109,7 @@ describe('IdentityStore', function() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should enforce seed compliance with TestRPC', function (done) {
|
it('should enforce seed compliance with TestRPC', function (done) {
|
||||||
|
this.timeout(5000)
|
||||||
const tests = assertions.map((assertion) => {
|
const tests = assertions.map((assertion) => {
|
||||||
return function (cb) {
|
return function (cb) {
|
||||||
accounts = []
|
accounts = []
|
||||||
@ -118,7 +119,17 @@ describe('IdentityStore', function() {
|
|||||||
var received = accounts[0].toLowerCase()
|
var received = accounts[0].toLowerCase()
|
||||||
var expected = assertion.account.toLowerCase()
|
var expected = assertion.account.toLowerCase()
|
||||||
assert.equal(received, expected)
|
assert.equal(received, expected)
|
||||||
cb()
|
|
||||||
|
idStore.tryPassword(password, function (err) {
|
||||||
|
|
||||||
|
assert.ok(idStore.isUnlocked(), 'should unlock the id store')
|
||||||
|
|
||||||
|
idStore.submitPassword(password, function(err, account) {
|
||||||
|
assert.ifError(err)
|
||||||
|
assert.equal(account, expected)
|
||||||
|
cb()
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -128,23 +139,5 @@ describe('IdentityStore', function() {
|
|||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should allow restoring and unlocking again', function (done) {
|
|
||||||
const assertion = assertions[0]
|
|
||||||
idStore.recoverFromSeed(password, assertion.seed, (err) => {
|
|
||||||
assert.ifError(err)
|
|
||||||
|
|
||||||
var received = accounts[0].toLowerCase()
|
|
||||||
var expected = assertion.account.toLowerCase()
|
|
||||||
assert.equal(received, expected)
|
|
||||||
|
|
||||||
|
|
||||||
idStore.submitPassword(password, function(err, account) {
|
|
||||||
assert.ifError(err)
|
|
||||||
assert.equal(account, expected)
|
|
||||||
done()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user