add vault recovery

feature/default_network_editable
kumavis 9 years ago
parent 231d7ab1de
commit 2197750510
  1. 1
      app/scripts/background.js
  2. 25
      app/scripts/lib/idStore.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),

@ -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'))

Loading…
Cancel
Save