add store/restore passphrasse methods

This commit is contained in:
Matias Alejo Garcia 2014-10-14 09:58:12 -03:00
commit f1ae8f9c33
5 changed files with 32 additions and 7 deletions

View file

@ -295,14 +295,17 @@ Identity.prototype.close = function(cb) {
* @return {Wallet}
*/
Identity.prototype.importWallet = function(base64, password, skipFields, cb) {
preconditions.checkArgument(password);
preconditions.checkArgument(cb);
this.storage.savePassphrase();
this.storage.setPassword(password);
var obj = this.storage.decrypt(base64);
if (!obj) return false;
this.storage.restorePassphrase();
if (!obj) return false;
var w = Identity._walletFromObj(obj, this.storage, this.networkOpts, this.blockchainOpts);
console.log('[Identity.js.307:Identity:]',w); //TODO
this._checkVersion(w.version);
this.addWallet(w, function(err) {
if (err) return cb(err);

View file

@ -45,8 +45,24 @@ Storage.prototype._getPassphrase = function() {
throw new Error('NOPASSPHRASE: No passphrase set');
return pps[this.__uniqueid];
}
};
Storage.prototype.savePassphrase = function() {
if (!pps[this.__uniqueid])
throw new Error('NOPASSPHRASE: No passphrase set');
this.savedPassphrase = this.savedPassphrase || {};
this.savedPassphrase[this.__uniqueid] = pps[this.__uniqueid];
};
Storage.prototype.restorePassphrase = function() {
if (!this.savedPassphrase[this.__uniqueid])
throw new Error('NOSTOREDPASSPHRASE: No stored passphrase');
pps[this.__uniqueid] = this.savedPassphrase[this.__uniqueid];
this.savedPassphrase[this.__uniqueid] = undefined;
};
Storage.prototype.hasPassphrase = function() {
return pps[this.__uniqueid] ? true : false;