diff options
-rw-r--r-- | app/scripts/background.js | 1 | ||||
-rw-r--r-- | app/scripts/lib/idStore.js | 25 |
2 files changed, 21 insertions, 5 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js index a724a87e8..aa06f27f1 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -115,6 +115,7 @@ function linkDnode(stream){ setRpcTarget: setRpcTarget, // forward directly to idStore createNewVault: idStore.createNewVault.bind(idStore), + recoverFromSeed: idStore.recoverFromSeed.bind(idStore), submitPassword: idStore.submitPassword.bind(idStore), setSelectedAddress: idStore.setSelectedAddress.bind(idStore), approveTransaction: idStore.approveTransaction.bind(idStore), diff --git a/app/scripts/lib/idStore.js b/app/scripts/lib/idStore.js index 148947cd7..173a1672f 100644 --- a/app/scripts/lib/idStore.js +++ b/app/scripts/lib/idStore.js @@ -41,7 +41,7 @@ IdentityStore.prototype.createNewVault = function(password, cb){ const self = this delete self._keyStore delete window.localStorage['lightwallet'] - var keyStore = self._createIdmgmt(password, function(err){ + var keyStore = self._createIdmgmt(password, null, function(err){ if (err) return cb(err) var seedWords = self._idmgmt.getSeed() self._loadIdentities() @@ -50,6 +50,15 @@ IdentityStore.prototype.createNewVault = function(password, cb){ }) } +IdentityStore.prototype.recoverFromSeed = function(password, seed, cb){ + const self = this + self._createIdmgmt(password, seed, function(err){ + if (err) return cb(err) + self._loadIdentities() + self._didUpdate() + cb() + }) +} IdentityStore.prototype.setStore = function(store){ const self = this @@ -202,17 +211,23 @@ IdentityStore.prototype._loadIdentities = function(){ IdentityStore.prototype._tryPassword = function(password, cb){ const self = this - self._createIdmgmt(password, cb) + self._createIdmgmt(password, null, cb) } -IdentityStore.prototype._createIdmgmt = function(password, cb){ +IdentityStore.prototype._createIdmgmt = function(password, seed, cb){ const self = this var keyStore = null LightwalletKeyStore.deriveKeyFromPassword(password, function(err, derrivedKey){ if (err) return cb(err) var serializedKeystore = window.localStorage['lightwallet'] - // returning user - if (serializedKeystore) { + // recovering from seed + if (seed) { + keyStore = new LightwalletKeyStore(seed, derrivedKey) + keyStore.generateNewAddress(derrivedKey, 3) + window.localStorage['lightwallet'] = keyStore.serialize() + console.log('saved to keystore localStorage') + // returning user, recovering from localStorage + } else if (serializedKeystore) { keyStore = LightwalletKeyStore.deserialize(serializedKeystore) var isCorrect = keyStore.isDerivedKeyCorrect(derrivedKey) if (!isCorrect) return cb(new Error('Lightwallet - password incorrect')) |