revert to setPassphrase

This commit is contained in:
Matias Alejo Garcia 2014-09-18 16:38:18 -03:00
commit 9bfc0dd193
7 changed files with 29 additions and 29 deletions

View file

@ -12,7 +12,7 @@ function Storage(opts) {
this.__uniqueid = ++id; this.__uniqueid = ++id;
if (opts.password) if (opts.password)
this.setPassword(opts.password); this.setPassphrase(opts.password);
try { try {
this.storage = opts.storage || localStorage; this.storage = opts.storage || localStorage;
@ -26,7 +26,7 @@ function Storage(opts) {
} }
var pps = {}; var pps = {};
Storage.prototype._getPassword = function() { Storage.prototype._getPassphrase = function() {
if (!pps[this.__uniqueid]) if (!pps[this.__uniqueid])
throw new Error('NOPASSPHRASE: No passphrase set'); throw new Error('NOPASSPHRASE: No passphrase set');
@ -34,12 +34,12 @@ Storage.prototype._getPassword = function() {
return pps[this.__uniqueid]; return pps[this.__uniqueid];
} }
Storage.prototype.setPassword = function(password) { Storage.prototype.setPassphrase = function(password) {
pps[this.__uniqueid] = password; pps[this.__uniqueid] = password;
} }
Storage.prototype._encrypt = function(string) { Storage.prototype._encrypt = function(string) {
var encrypted = CryptoJS.AES.encrypt(string, this._getPassword()); var encrypted = CryptoJS.AES.encrypt(string, this._getPassphrase());
var encryptedBase64 = encrypted.toString(); var encryptedBase64 = encrypted.toString();
return encryptedBase64; return encryptedBase64;
}; };
@ -47,7 +47,7 @@ Storage.prototype._encrypt = function(string) {
Storage.prototype._decrypt = function(base64) { Storage.prototype._decrypt = function(base64) {
var decryptedStr = null; var decryptedStr = null;
try { try {
var decrypted = CryptoJS.AES.decrypt(base64, this._getPassword()); var decrypted = CryptoJS.AES.decrypt(base64, this._getPassphrase());
if (decrypted) if (decrypted)
decryptedStr = decrypted.toString(CryptoJS.enc.Utf8); decryptedStr = decrypted.toString(CryptoJS.enc.Utf8);
} catch (e) { } catch (e) {

View file

@ -119,7 +119,7 @@ WalletFactory.prototype.fromObj = function(inObj, skipFields) {
* @return {Wallet} * @return {Wallet}
*/ */
WalletFactory.prototype.fromEncryptedObj = function(base64, password, skipFields) { WalletFactory.prototype.fromEncryptedObj = function(base64, password, skipFields) {
this.storage.setPassword(password); this.storage.setPassphrase(password);
var walletObj = this.storage.import(base64); var walletObj = this.storage.import(base64);
if (!walletObj) return false; if (!walletObj) return false;
return this.fromObj(walletObj, skipFields); return this.fromObj(walletObj, skipFields);
@ -248,7 +248,7 @@ WalletFactory.prototype.create = function(opts, cb) {
}); });
log.debug('\t### TxProposals Initialized'); log.debug('\t### TxProposals Initialized');
this.storage.setPassword(opts.passphrase); this.storage.setPassphrase(opts.passphrase);
opts.storage = this.storage; opts.storage = this.storage;
opts.network = this.networks[opts.networkName]; opts.network = this.networks[opts.networkName];
@ -300,7 +300,7 @@ WalletFactory.prototype._checkVersion = function(inVersion) {
WalletFactory.prototype.open = function(walletId, passphrase, cb) { WalletFactory.prototype.open = function(walletId, passphrase, cb) {
preconditions.checkArgument(cb); preconditions.checkArgument(cb);
var self = this; var self = this;
self.storage.setPassword(passphrase); self.storage.setPassphrase(passphrase);
self.read(walletId, null, function(err, w) { self.read(walletId, null, function(err, w) {
if (err) return cb(err); if (err) return cb(err);

View file

@ -69,7 +69,7 @@ describe('PayPro (in Wallet) model', function() {
}); });
var storage = new Storage(walletConfig.storage); var storage = new Storage(walletConfig.storage);
storage.setPassword('xxx'); storage.setPassphrase('xxx');
var network = new Network(walletConfig.network); var network = new Network(walletConfig.network);
var blockchain = new Blockchain(walletConfig.blockchain); var blockchain = new Blockchain(walletConfig.blockchain);
c.storage = storage; c.storage = storage;

View file

@ -13,7 +13,7 @@ describe('Storage model', function() {
var s; var s;
beforeEach(function() { beforeEach(function() {
s = new Storage(require('./mocks/FakeLocalStorage').storageParams); s = new Storage(require('./mocks/FakeLocalStorage').storageParams);
s.setPassword('mysupercoolpassword'); s.setPassphrase('mysupercoolpassword');
s.storage.clear(); s.storage.clear();
s.sessionStorage.clear(); s.sessionStorage.clear();
}); });
@ -251,13 +251,13 @@ describe('Storage model', function() {
describe('#import', function() { describe('#import', function() {
it('should not be able to decrypt with wrong password', function() { it('should not be able to decrypt with wrong password', function() {
s.setPassword('xxx'); s.setPassphrase('xxx');
var wo = s.import(encryptedLegacy1); var wo = s.import(encryptedLegacy1);
should.not.exist(wo); should.not.exist(wo);
}); });
it('should be able to decrypt an old backup', function() { it('should be able to decrypt an old backup', function() {
s.setPassword(legacyPassword1); s.setPassphrase(legacyPassword1);
var wo = s.import(encryptedLegacy1); var wo = s.import(encryptedLegacy1);
should.exist(wo); should.exist(wo);
wo.opts.id.should.equal('48ba2f1ffdfe9708'); wo.opts.id.should.equal('48ba2f1ffdfe9708');

View file

@ -82,7 +82,7 @@ describe('Wallet model', function() {
}); });
var storage = new Storage(walletConfig.storage); var storage = new Storage(walletConfig.storage);
storage.setPassword('xxx'); storage.setPassphrase('xxx');
var network = new Network(walletConfig.network); var network = new Network(walletConfig.network);
var blockchain = new Blockchain(walletConfig.blockchain); var blockchain = new Blockchain(walletConfig.blockchain);
c.storage = storage; c.storage = storage;
@ -344,7 +344,7 @@ describe('Wallet model', function() {
o.opts.reconnectDelay = 100; o.opts.reconnectDelay = 100;
var s = new Storage(walletConfig.storage); var s = new Storage(walletConfig.storage);
s.setPassword('xxx'); s.setPassphrase('xxx');
var w2 = Wallet.fromObj(o, var w2 = Wallet.fromObj(o,
s, s,
new Network(walletConfig.network), new Network(walletConfig.network),

View file

@ -34,7 +34,7 @@ describe('WalletFactory model', function() {
beforeEach(function() { beforeEach(function() {
wf = new WalletFactory(config, '0.0.1'); wf = new WalletFactory(config, '0.0.1');
wf.storage.setPassword = sinon.spy(); wf.storage.setPassphrase = sinon.spy();
wf.storage.getSessionId = sinon.spy(); wf.storage.getSessionId = sinon.spy();
wf.storage.setFromObj = sinon.spy(); wf.storage.setFromObj = sinon.spy();
wf.storage.setLastOpened = sinon.stub().yields(null); wf.storage.setLastOpened = sinon.stub().yields(null);
@ -151,15 +151,15 @@ describe('WalletFactory model', function() {
describe('#fromEncryptedObj', function() { describe('#fromEncryptedObj', function() {
it('should create wallet from encrypted object', function() { it('should create wallet from encrypted object', function() {
wf.storage.setPassword = sinon.spy(); wf.storage.setPassphrase = sinon.spy();
wf.storage.import = sinon.stub().withArgs('base64').returns('walletObj'); wf.storage.import = sinon.stub().withArgs('base64').returns('walletObj');
wf.fromObj = sinon.stub().withArgs('walletObj').returns('ok'); wf.fromObj = sinon.stub().withArgs('walletObj').returns('ok');
var w = wf.fromEncryptedObj("encrypted object", "123"); var w = wf.fromEncryptedObj("encrypted object", "123");
w.should.equal('ok'); w.should.equal('ok');
wf.storage.setPassword.calledOnce.should.be.true; wf.storage.setPassphrase.calledOnce.should.be.true;
wf.storage.setPassword.getCall(0).args[0].should.equal('123'); wf.storage.setPassphrase.getCall(0).args[0].should.equal('123');
wf.storage.import.calledOnce.should.be.true; wf.storage.import.calledOnce.should.be.true;
wf.fromObj.calledWith('walletObj').should.be.true; wf.fromObj.calledWith('walletObj').should.be.true;
}); });
@ -291,9 +291,9 @@ describe('WalletFactory model', function() {
'totalcopayers': 3 'totalcopayers': 3
}; };
it('should call setPassword', function(done) { it('should call setPassphrase', function(done) {
var wf = new WalletFactory(config, '0.0.1'); var wf = new WalletFactory(config, '0.0.1');
wf.storage.setPassword = sinon.spy(); wf.storage.setPassphrase = sinon.spy();
var s1 = sinon.stub(); var s1 = sinon.stub();
s1.store = sinon.stub().yields(null); s1.store = sinon.stub().yields(null);
@ -301,15 +301,15 @@ describe('WalletFactory model', function() {
wf.storage.setLastOpened = sinon.stub().yields(null); wf.storage.setLastOpened = sinon.stub().yields(null);
wf.open('dummy', 'xxx', function(err, w) { wf.open('dummy', 'xxx', function(err, w) {
wf.storage.setPassword.calledOnce.should.equal(true); wf.storage.setPassphrase.calledOnce.should.equal(true);
wf.storage.setPassword.getCall(0).args[0].should.equal('xxx'); wf.storage.setPassphrase.getCall(0).args[0].should.equal('xxx');
done(); done();
}); });
}); });
it('should call return wallet', function(done) { it('should call return wallet', function(done) {
var wf = new WalletFactory(config, '0.0.1'); var wf = new WalletFactory(config, '0.0.1');
wf.storage.setPassword = sinon.spy(); wf.storage.setPassphrase = sinon.spy();
var s1 = sinon.stub(); var s1 = sinon.stub();
s1.store = sinon.stub().yields(null); s1.store = sinon.stub().yields(null);
@ -326,7 +326,7 @@ describe('WalletFactory model', function() {
it('should call #store', function(done) { it('should call #store', function(done) {
var wf = new WalletFactory(config, '0.0.1'); var wf = new WalletFactory(config, '0.0.1');
wf.storage.setPassword = sinon.spy(); wf.storage.setPassphrase = sinon.spy();
var s1 = sinon.stub(); var s1 = sinon.stub();
s1.store = sinon.stub().yields(null); s1.store = sinon.stub().yields(null);
@ -341,7 +341,7 @@ describe('WalletFactory model', function() {
it('should call #setLastOpened', function(done) { it('should call #setLastOpened', function(done) {
var wf = new WalletFactory(config, '0.0.1'); var wf = new WalletFactory(config, '0.0.1');
wf.storage.setPassword = sinon.spy(); wf.storage.setPassphrase = sinon.spy();
var s1 = sinon.stub(); var s1 = sinon.stub();
s1.store = sinon.stub().yields(null); s1.store = sinon.stub().yields(null);
@ -510,13 +510,13 @@ describe('WalletFactory model', function() {
it('should be able to import simple 1-of-1 encrypted legacy testnet wallet', function() { it('should be able to import simple 1-of-1 encrypted legacy testnet wallet', function() {
wf.storage.import = sinon.stub(); wf.storage.import = sinon.stub();
wf.storage.setPassword = sinon.spy(); wf.storage.setPassphrase = sinon.spy();
wf.storage.import.withArgs('dummy').returns(JSON.parse(legacy1)); wf.storage.import.withArgs('dummy').returns(JSON.parse(legacy1));
var w = wf.import('dummy', 'xxx'); var w = wf.import('dummy', 'xxx');
should.exist(w); should.exist(w);
wf.storage.setPassword.calledOnce.should.equal(true); wf.storage.setPassphrase.calledOnce.should.equal(true);
wf.storage.setPassword.getCall(0).args[0].should.equal('xxx'); wf.storage.setPassphrase.getCall(0).args[0].should.equal('xxx');
w.isReady().should.equal(true); w.isReady().should.equal(true);
var wo = w.toObj(); var wo = w.toObj();

View file

@ -21,7 +21,7 @@ describe('WalletLock model', function() {
beforeEach(function() { beforeEach(function() {
storage = new Storage(require('./mocks/FakeLocalStorage').storageParams); storage = new Storage(require('./mocks/FakeLocalStorage').storageParams);
storage.setPassword('mysupercoolpassword'); storage.setPassphrase('mysupercoolpassword');
storage.storage.clear(); storage.storage.clear();
storage.sessionStorage.clear(); storage.sessionStorage.clear();
}); });