implementing passphrase to wallet Open/Create methods

This commit is contained in:
Mario Colque 2014-05-01 10:03:58 -03:00
commit 8d4a6ded71

View file

@ -68,12 +68,13 @@ WalletFactory.prototype.fromObj = function(obj) {
return w;
};
WalletFactory.prototype.read = function(walletId) {
WalletFactory.prototype.read = function(walletId, passphrase) {
if (! this._checkRead(walletId))
return false;
var obj = {};
var s = this.storage;
s._setPassphrase(passphrase);
obj.id = walletId;
obj.opts = s.get(walletId, 'opts');
@ -86,7 +87,6 @@ WalletFactory.prototype.read = function(walletId) {
};
WalletFactory.prototype.create = function(opts) {
var s = WalletFactory.storage;
opts = opts || {};
this.log('### CREATING NEW WALLET.' +
(opts.id ? ' USING ID: ' + opts.id : ' NEW ID') +
@ -112,6 +112,8 @@ WalletFactory.prototype.create = function(opts) {
});
this.log('\t### TxProposals Initialized');
this.storage._setPassphrase(opts.passphrase);
opts.storage = this.storage;
opts.network = this.network;
opts.blockchain = this.blockchain;
@ -130,7 +132,7 @@ WalletFactory.prototype.open = function(walletId, opts) {
opts = opts || {};
opts.id = walletId;
opts.verbose = this.verbose;
var w = this.read(walletId) || this.create(opts);
var w = this.read(walletId, opts.passphrase) || this.create(opts);
w.store();
return w;
};