add store/restore passphrasse methods
This commit is contained in:
parent
d9cd2e95d4
commit
f1ae8f9c33
5 changed files with 32 additions and 7 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue