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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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