From c65e677f2cb9f1ccc10edd4525f2b892c4a70113 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Mon, 2 Jun 2014 14:40:00 -0300 Subject: [PATCH 1/5] fix bad password error --- index.html | 2 +- js/controllers/signin.js | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index d54ed8ea8..770046bfe 100644 --- a/index.html +++ b/index.html @@ -182,7 +182,7 @@
- Authenticating and Looking for peers... + Authenticating and looking for peers...
Oops, we had an error! Looks like you are already connected to this wallet, diff --git a/js/controllers/signin.js b/js/controllers/signin.js index 057b548ba..79d8d1d3b 100644 --- a/js/controllers/signin.js +++ b/js/controllers/signin.js @@ -27,17 +27,15 @@ angular.module('copay.signin').controller('SigninController', console.log('## Obtaining passphrase...'); Passphrase.getBase64Async(password, function(passphrase){ - console.log('## Done.'); + console.log('## Passphrase obtained'); var w = walletFactory.open($scope.selectedWalletId, { passphrase: passphrase}); if (!w) { $scope.loading = $scope.failure = false; - $rootScope.$flashMessage = { message: 'Bad password or connection error', type: 'error'}; + $rootScope.$flashMessage = { message: 'Wrong password', type: 'error'}; $rootScope.$digest(); return; } - console.log('[signin.js.49]'); //TODO installStartupHandlers(w); - console.log('[signin.js.52]'); //TODO controllerUtils.startNetwork(w); }); }; From 7b2f227bccc2ee4d0f0f9769ff172f6d72052a5a Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Mon, 2 Jun 2014 15:14:28 -0300 Subject: [PATCH 2/5] work towards connection error --- js/models/core/Wallet.js | 6 ++---- js/models/network/WebRTC.js | 1 - js/services/controllerUtils.js | 10 +--------- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index cb6a49057..dab6a6303 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -63,9 +63,7 @@ Wallet.prototype.seedCopayer = function(pubKey) { Wallet.prototype.connectToAll = function() { -console.log('[Wallet.js.57]'); //TODO var all = this.publicKeyRing.getAllCopayerIds(); - console.log('[Wallet.js.58] connecting'); //TODO this.network.connectToCopayers(all); if (this.seededCopayerId) { @@ -224,8 +222,8 @@ Wallet.prototype.netStart = function() { self.log('[Wallet.js.132:openError:] GOT openError'); //TODO self.emit('openError'); }); - net.on('error', function(){ - self.emit('connectionError'); // Bubble the error + net.on('error', function() { + self.emit('connectionError'); }); net.on('close', function() { self.emit('close'); diff --git a/js/models/network/WebRTC.js b/js/models/network/WebRTC.js index 8d424af2d..912f35864 100644 --- a/js/models/network/WebRTC.js +++ b/js/models/network/WebRTC.js @@ -269,7 +269,6 @@ Network.prototype._setupPeerHandlers = function(openCallback) { self._checkAnyPeer(); }); - p.on('connection', function(dataConn) { console.log('### NEW INBOUND CONNECTION %d/%d', self.connectedPeers.length, self.maxPeers); if (self.connectedPeers.length >= self.maxPeers) { diff --git a/js/services/controllerUtils.js b/js/services/controllerUtils.js index 905110242..25f4bcb11 100644 --- a/js/services/controllerUtils.js +++ b/js/services/controllerUtils.js @@ -62,35 +62,29 @@ angular.module('copay.controllerUtils') $rootScope.wallet = w; $location.path('addresses'); video.setOwnPeer(myPeerID, w, handlePeerVideo); - console.log('# Done ready handler'); }); w.on('publicKeyRingUpdated', function(dontDigest) { - console.log('[start publicKeyRing handler]'); //TODO root.setSocketHandlers(); root.updateAddressList(); if (!dontDigest) { - console.log('[pkr digest]'); $rootScope.$digest(); - console.log('[done digest]'); } }); w.on('txProposalsUpdated', function(dontDigest) { root.updateTxs({onlyPending:true}); root.updateBalance(function(){ if (!dontDigest) { - console.log('[txp digest]'); $rootScope.$digest(); - console.log('[done digest]'); } }); }); w.on('openError', root.onErrorDigest); + w.on('connectionError', root.onErrorDigest); w.on('connect', function(peerID) { if (peerID) { video.callPeer(peerID, handlePeerVideo); } - console.log('[digest]'); $rootScope.$digest(); }); w.on('disconnect', function(peerID) { @@ -129,7 +123,6 @@ angular.module('copay.controllerUtils') $rootScope.availableBalance = safeBalance; root.updateAddressList(); $rootScope.updatingBalance = false; - console.log('Done updating balance.'); //TODO return cb?cb():null; }); }; @@ -145,7 +138,6 @@ angular.module('copay.controllerUtils') var inT = w.getTxProposals().sort(function(t1, t2) { return t1.createdTs < t2.createdTs }); var txs = []; - console.log('[START LOOP]'); //TODO inT.forEach(function(i, index){ if (opts.skip && (index < opts.skip[0] || index >= opts.skip[1])) { return txs.push(null); From 6feb2a217650981ad560ac99cbe2e328f927aa66 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Mon, 2 Jun 2014 16:41:57 -0300 Subject: [PATCH 3/5] add error on incorrect password while importing --- js/controllers/import.js | 12 +++++- js/models/core/WalletFactory.js | 15 +++---- js/models/storage/LocalEncrypted.js | 66 ++++++++++++++--------------- 3 files changed, 49 insertions(+), 44 deletions(-) diff --git a/js/controllers/import.js b/js/controllers/import.js index 612c4d8ad..8a3ad9268 100644 --- a/js/controllers/import.js +++ b/js/controllers/import.js @@ -6,7 +6,15 @@ angular.module('copay.import').controller('ImportController', var reader = new FileReader(); var _importBackup = function(encryptedObj) { Passphrase.getBase64Async($scope.password, function(passphrase){ - $rootScope.wallet = walletFactory.fromEncryptedObj(encryptedObj, passphrase); + var w = walletFactory.fromEncryptedObj(encryptedObj, passphrase); + if (!w) { + $scope.loading = false; + $rootScope.$flashMessage = { message: 'Wrong password', type: 'error'}; + $rootScope.$digest(); + return; + } + $rootScope.wallet = w; + controllerUtils.startNetwork($rootScope.wallet); }); }; @@ -23,6 +31,7 @@ angular.module('copay.import').controller('ImportController', $scope.import = function(form) { if (form.$invalid) { + $scope.loading = false; $rootScope.$flashMessage = { message: 'There is an error in the form. Please, try again', type: 'error'}; return; } @@ -32,6 +41,7 @@ angular.module('copay.import').controller('ImportController', var password = form.password.$modelValue; if (!backupFile && !backupText) { + $scope.loading = false; $rootScope.$flashMessage = { message: 'Please, select your backup file or paste the text', type: 'error'}; return; } diff --git a/js/models/core/WalletFactory.js b/js/models/core/WalletFactory.js index afd322d6f..0e63da89f 100644 --- a/js/models/core/WalletFactory.js +++ b/js/models/core/WalletFactory.js @@ -39,14 +39,11 @@ WalletFactory.prototype.log = function(){ WalletFactory.prototype._checkRead = function(walletId) { var s = this.storage; var ret = - ( s.get(walletId, 'publicKeyRing') && s.get(walletId, 'txProposals') && s.get(walletId, 'opts') && - s.get(walletId, 'privateKey') - )?true:false; - ; - return ret?true:false; + s.get(walletId, 'privateKey'); + return ret; }; WalletFactory.prototype.fromObj = function(obj) { @@ -60,14 +57,15 @@ WalletFactory.prototype.fromObj = function(obj) { WalletFactory.prototype.fromEncryptedObj = function(base64, password) { this.storage._setPassphrase(password); var walletObj = this.storage.import(base64); - var w= this.fromObj(walletObj); - w.store(); + if (!walletObj) return null; + var w = this.fromObj(walletObj); + if (!w) return null; return w; }; WalletFactory.prototype.read = function(walletId) { if (! this._checkRead(walletId)) - return false; + return null; var obj = {}; var s = this.storage; @@ -149,7 +147,6 @@ WalletFactory.prototype.open = function(walletId, opts) { var w = this.read(walletId); - if (w) { this._checkVersion(w.version); w.store(); diff --git a/js/models/storage/LocalEncrypted.js b/js/models/storage/LocalEncrypted.js index 18fc83dee..e30652adc 100644 --- a/js/models/storage/LocalEncrypted.js +++ b/js/models/storage/LocalEncrypted.js @@ -3,6 +3,7 @@ var imports = require('soop').imports(); var id = 0; + function Storage(opts) { opts = opts || {}; @@ -33,12 +34,16 @@ Storage.prototype._encryptObj = function(obj) { }; Storage.prototype._decrypt = function(base64) { - var decryptedStr=null; - var decrypted = CryptoJS.AES.decrypt(base64, this._getPassphrase()); - - if (decrypted) - decryptedStr = decrypted.toString(CryptoJS.enc.Utf8); + var decryptedStr = null; + try { + var decrypted = CryptoJS.AES.decrypt(base64, this._getPassphrase()); + if (decrypted) + decryptedStr = decrypted.toString(CryptoJS.enc.Utf8); + } catch (e) { + console.log('Error while decrypting ' + base64); + return null; + } return decryptedStr; }; @@ -49,22 +54,16 @@ Storage.prototype._decryptObj = function(base64) { Storage.prototype._read = function(k) { var ret; - try { - ret = localStorage.getItem(k); - if (ret){ - ret = this._decrypt(ret); - ret = ret.toString(CryptoJS.enc.Utf8); - ret = JSON.parse(ret); - } - } catch (e) { - console.log('Error while decrypting: '+e); - return null; - }; - + ret = localStorage.getItem(k); + if (!ret) return null; + ret = this._decrypt(ret); + if (!ret) return null; + ret = ret.toString(CryptoJS.enc.Utf8); + ret = JSON.parse(ret); return ret; }; -Storage.prototype._write = function(k,v) { +Storage.prototype._write = function(k, v) { v = JSON.stringify(v); v = this._encrypt(v); @@ -78,7 +77,7 @@ Storage.prototype.getGlobal = function(k) { }; // set value for key -Storage.prototype.setGlobal = function(k,v) { +Storage.prototype.setGlobal = function(k, v) { localStorage.setItem(k, JSON.stringify(v)); }; @@ -92,46 +91,45 @@ Storage.prototype._key = function(walletId, k) { }; // get value by key Storage.prototype.get = function(walletId, k) { - var ret = this._read(this._key(walletId,k)); - + var ret = this._read(this._key(walletId, k)); return ret; }; // set value for key -Storage.prototype.set = function(walletId, k,v) { - this._write(this._key(walletId,k), v); +Storage.prototype.set = function(walletId, k, v) { + this._write(this._key(walletId, k), v); }; // remove value for key Storage.prototype.remove = function(walletId, k) { - this.removeGlobal(this._key(walletId,k)); + this.removeGlobal(this._key(walletId, k)); }; Storage.prototype.setName = function(walletId, name) { - this.setGlobal('nameFor::'+walletId, name); + this.setGlobal('nameFor::' + walletId, name); }; Storage.prototype.getName = function(walletId) { - return this.getGlobal('nameFor::'+walletId); + return this.getGlobal('nameFor::' + walletId); }; Storage.prototype.getWalletIds = function() { var walletIds = []; var uniq = {}; for (var i = 0; i < localStorage.length; i++) { - var key = localStorage.key(i); - var split = key.split('::'); - if (split.length == 2) { + var key = localStorage.key(i); + var split = key.split('::'); + if (split.length == 2) { var walletId = split[0]; if (walletId === 'nameFor') continue; - if (typeof uniq[walletId] === 'undefined' ) { + if (typeof uniq[walletId] === 'undefined') { walletIds.push(walletId); uniq[walletId] = 1; } - } - } + } + } return walletIds; }; @@ -140,9 +138,9 @@ Storage.prototype.getWallets = function() { var uniq = {}; var ids = this.getWalletIds(); - for (var i in ids){ + for (var i in ids) { wallets.push({ - id:ids[i], + id: ids[i], name: this.getName(ids[i]), }); } From 55245650bdfadade7d04143b0ee13b9f8368ac74 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Mon, 2 Jun 2014 18:50:46 -0300 Subject: [PATCH 4/5] rename WF test --- index.html | 2 +- test/{test.Walletfactory.js => test.WalletFactory.js} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename test/{test.Walletfactory.js => test.WalletFactory.js} (100%) diff --git a/index.html b/index.html index 770046bfe..3084e5fc6 100644 --- a/index.html +++ b/index.html @@ -309,7 +309,7 @@
Your Wallet Password(doesn't need to be shared) Required
+ ng-model="walletPassword" check-strength="passwordStrength" tooltip-trigger="focus" required>
Wallet name Optional
diff --git a/test/test.Walletfactory.js b/test/test.WalletFactory.js similarity index 100% rename from test/test.Walletfactory.js rename to test/test.WalletFactory.js From 1cba837f8d2a6a29965bb4fcbe83fb736089d8a8 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Mon, 2 Jun 2014 18:59:38 -0300 Subject: [PATCH 5/5] fix test --- js/models/core/WalletFactory.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/js/models/core/WalletFactory.js b/js/models/core/WalletFactory.js index 0e63da89f..1912b655d 100644 --- a/js/models/core/WalletFactory.js +++ b/js/models/core/WalletFactory.js @@ -43,7 +43,7 @@ WalletFactory.prototype._checkRead = function(walletId) { s.get(walletId, 'txProposals') && s.get(walletId, 'opts') && s.get(walletId, 'privateKey'); - return ret; + return !!ret; }; WalletFactory.prototype.fromObj = function(obj) { @@ -57,15 +57,15 @@ WalletFactory.prototype.fromObj = function(obj) { WalletFactory.prototype.fromEncryptedObj = function(base64, password) { this.storage._setPassphrase(password); var walletObj = this.storage.import(base64); - if (!walletObj) return null; + if (!walletObj) return false; var w = this.fromObj(walletObj); - if (!w) return null; + if (!w) return false; return w; }; WalletFactory.prototype.read = function(walletId) { if (! this._checkRead(walletId)) - return null; + return false; var obj = {}; var s = this.storage;