idStore - add createNewVault

feature/default_network_editable
kumavis 9 years ago
parent c134fd3c1f
commit 2c719db940
  1. 1
      app/scripts/background.js
  2. 31
      app/scripts/lib/idStore.js

@ -75,6 +75,7 @@ function handleInternalCommunication(remotePort){
var connection = Dnode({ var connection = Dnode({
getState: function(cb){ cb(null, getState()) }, getState: function(cb){ cb(null, getState()) },
// forward directly to idStore // forward directly to idStore
createNewVault: idStore.createNewVault.bind(idStore),
submitPassword: idStore.submitPassword.bind(idStore), submitPassword: idStore.submitPassword.bind(idStore),
setSelectedAddress: idStore.setSelectedAddress.bind(idStore), setSelectedAddress: idStore.setSelectedAddress.bind(idStore),
signTransaction: idStore.signTransaction.bind(idStore), signTransaction: idStore.signTransaction.bind(idStore),

@ -32,11 +32,24 @@ function IdentityStore(ethStore) {
// public // public
// //
IdentityStore.prototype.createNewVault = function(password, cb){
const self = this
delete self._keyStore
delete window.localStorage['lightwallet']
var keyStore = self._getKeyStore(password)
var seedWords = keyStore.getSeed(password)
self._loadIdentities()
self._didUpdate()
cb(null, seedWords)
}
IdentityStore.prototype.setStore = function(store){ IdentityStore.prototype.setStore = function(store){
const self = this const self = this
self._ethStore = store self._ethStore = store
} }
IdentityStore.prototype.getState = function(){ IdentityStore.prototype.getState = function(){
const self = this const self = this
return clone(extend(self._currentState, { return clone(extend(self._currentState, {
@ -83,7 +96,6 @@ IdentityStore.prototype.addUnconfirmedTransaction = function(txParams, cb){
IdentityStore.prototype.setLocked = function(){ IdentityStore.prototype.setLocked = function(){
const self = this const self = this
delete self._keyStore delete self._keyStore
delete window.sessionStorage['password']
} }
IdentityStore.prototype.submitPassword = function(password, cb){ IdentityStore.prototype.submitPassword = function(password, cb){
@ -93,7 +105,6 @@ IdentityStore.prototype.submitPassword = function(password, cb){
if (err) console.log('bad password:', password, err) if (err) console.log('bad password:', password, err)
if (err) return cb(err) if (err) return cb(err)
console.log('good password:', password) console.log('good password:', password)
window.sessionStorage['password'] = password
// load identities before returning... // load identities before returning...
self._loadIdentities() self._loadIdentities()
cb() cb()
@ -174,7 +185,6 @@ IdentityStore.prototype._signTransaction = function(password, txParams, cb){
gasLimit: txParams.gas, gasLimit: txParams.gas,
}) })
var password = self._getPassword()
var serializedTx = self._keyStore.signTx(tx.serialize(), password, self._currentState.selectedAddress) var serializedTx = self._keyStore.signTx(tx.serialize(), password, self._currentState.selectedAddress)
// // deserialize and dump values to confirm configuration // // deserialize and dump values to confirm configuration
@ -201,20 +211,19 @@ IdentityStore.prototype._didUpdate = function(){
IdentityStore.prototype._isUnlocked = function(){ IdentityStore.prototype._isUnlocked = function(){
const self = this const self = this
// var password = window.sessionStorage['password']
// var result = Boolean(password) // var result = Boolean(password)
var result = Boolean(self._keyStore) var result = Boolean(self._keyStore)
return result return result
} }
// load identities from keyStore // load identities from keyStoreet
IdentityStore.prototype._loadIdentities = function(){ IdentityStore.prototype._loadIdentities = function(){
const self = this const self = this
if (!self._isUnlocked()) throw new Error('not unlocked') if (!self._isUnlocked()) throw new Error('not unlocked')
// get addresses and normalize address hexString // get addresses and normalize address hexString
var addresses = self._keyStore.getAddresses().map(function(address){ return '0x'+address }) var addresses = self._keyStore.getAddresses().map(function(address){ return '0x'+address })
addresses.forEach(function(address){ addresses.forEach(function(address){
// add to ethStore // // add to ethStore
self._ethStore.addAccount(address) self._ethStore.addAccount(address)
// add to identities // add to identities
var identity = { var identity = {
@ -265,7 +274,7 @@ IdentityStore.prototype._getKeyStore = function(password){
self._saveKeystore(keyStore) self._saveKeystore(keyStore)
} }
keyStore.passwordProvider = function getPassword(cb){ keyStore.passwordProvider = function getPassword(cb){
cb(null, self._getPassword()) cb(null, password)
} }
self._keyStore = keyStore self._keyStore = keyStore
return keyStore return keyStore
@ -274,13 +283,7 @@ IdentityStore.prototype._getKeyStore = function(password){
IdentityStore.prototype._saveKeystore = function(keyStore){ IdentityStore.prototype._saveKeystore = function(keyStore){
const self = this const self = this
window.localStorage['lightwallet'] = keyStore.serialize() window.localStorage['lightwallet'] = keyStore.serialize()
} console.log('saved to localStorage')
IdentityStore.prototype._getPassword = function(){
const self = this
var password = window.sessionStorage['password']
console.warn('using password from memory:', password)
return password
} }
// util // util

Loading…
Cancel
Save