From 9bfc0dd1937682cbe560103f2fcff04ee14e1a20 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Thu, 18 Sep 2014 16:38:18 -0300 Subject: [PATCH] revert to setPassphrase --- js/models/Storage.js | 10 +++++----- js/models/core/WalletFactory.js | 6 +++--- test/test.PayPro.js | 2 +- test/test.Storage.js | 6 +++--- test/test.Wallet.js | 4 ++-- test/test.WalletFactory.js | 28 ++++++++++++++-------------- test/test.WalletLock.js | 2 +- 7 files changed, 29 insertions(+), 29 deletions(-) diff --git a/js/models/Storage.js b/js/models/Storage.js index 6c1441580..4c8c658cb 100644 --- a/js/models/Storage.js +++ b/js/models/Storage.js @@ -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) { diff --git a/js/models/core/WalletFactory.js b/js/models/core/WalletFactory.js index 192827567..b1594937c 100644 --- a/js/models/core/WalletFactory.js +++ b/js/models/core/WalletFactory.js @@ -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); diff --git a/test/test.PayPro.js b/test/test.PayPro.js index bf218d4b0..e1d3d88ea 100644 --- a/test/test.PayPro.js +++ b/test/test.PayPro.js @@ -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; diff --git a/test/test.Storage.js b/test/test.Storage.js index 120aa3de1..186a30070 100644 --- a/test/test.Storage.js +++ b/test/test.Storage.js @@ -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'); diff --git a/test/test.Wallet.js b/test/test.Wallet.js index be2e59cd5..b4f2a7347 100644 --- a/test/test.Wallet.js +++ b/test/test.Wallet.js @@ -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), diff --git a/test/test.WalletFactory.js b/test/test.WalletFactory.js index 537f69ecb..517bf44bd 100644 --- a/test/test.WalletFactory.js +++ b/test/test.WalletFactory.js @@ -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(); diff --git a/test/test.WalletLock.js b/test/test.WalletLock.js index 018d151d9..6b2cb3ee2 100644 --- a/test/test.WalletLock.js +++ b/test/test.WalletLock.js @@ -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(); });