From 52a20334e122d0e670c73a9b2c92cf7cb9ca8f33 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Tue, 14 Jun 2016 12:28:21 -0300 Subject: [PATCH 1/3] new key test, upgrades to bwc 2.7.0 --- package.json | 2 +- src/js/controllers/index.js | 23 +++++++++----- src/js/models/profile.js | 6 ++++ src/js/services/profileService.js | 50 ++++++++++++++++++++----------- 4 files changed, 55 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index 5429ce936..243be9a41 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "url": "https://github.com/bitpay/copay/issues" }, "dependencies": { - "bitcore-wallet-client": "2.6.0", + "bitcore-wallet-client": "2.7.0", "express": "^4.11.2", "fs": "0.0.2", "grunt": "^0.4.5", diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index cce4b547f..bc1daeaa4 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -135,7 +135,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r self.isPrivKeyEncrypted = fc.isPrivKeyEncrypted(); self.externalSource = fc.getPrivKeyExternalSourceName(); self.account = fc.credentials.account; - self.incorrectDerivation = fc.incorrectDerivation; + self.incorrectDerivation = fc.keyDerivationOk === false; if (self.externalSource == 'trezor') self.account++; @@ -1388,6 +1388,11 @@ angular.module('copayApp.controllers').controller('indexController', function($r }); }; + self.isInFocus = function(walletId) { + var fc = profileService.focusedClient; + return fc && fc.credentials.walletId == walletId; + }; + self.setAddressbook = function(ab) { if (ab) { self.addressbook = ab; @@ -1408,12 +1413,17 @@ angular.module('copayApp.controllers').controller('indexController', function($r self.tab = 'walletHome'; }); - $rootScope.$on('Local/ValidatingWallet', function() { - ongoingProcess.set('validatingWallet', true); + $rootScope.$on('Local/ValidatingWallet', function(ev, walletId) { + if (self.isInFocus(walletId)) { + ongoingProcess.set('validatingWallet', true); + } }); - $rootScope.$on('Local/ProfileBound', function() { - ongoingProcess.set('validatingWallet', false); + $rootScope.$on('Local/ValidatingWalletEnded', function(ev, walletId, isOK) { + if (self.isInFocus(walletId)) { + ongoingProcess.set('validatingWallet', false); + self.incorrectDerivation = isOK === false; + } }); $rootScope.$on('Local/ClearHistory', function(event) { @@ -1475,8 +1485,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r }); $rootScope.$on('Local/WalletCompleted', function(event, walletId) { - var fc = profileService.focusedClient; - if (fc && fc.credentials.walletId == walletId) { + if (self.isInFocus(walletId)) { // reset main wallet variables self.setFocusedWallet(); go.walletHome(); diff --git a/src/js/models/profile.js b/src/js/models/profile.js index aaa5f4a4c..aea506864 100644 --- a/src/js/models/profile.js +++ b/src/js/models/profile.js @@ -57,6 +57,12 @@ Profile.prototype.isChecked = function(ua, walletId) { return !!(this.checkedUA == ua && this.checked[walletId]); }; + +Profile.prototype.isDeviceChecked = function(ua) { + return this.checkedUA == ua; +}; + + Profile.prototype.setChecked = function(ua, walletId) { if (this.checkedUA != ua) { this.checkedUA = ua; diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 6daf48900..25f4a42cd 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -75,11 +75,6 @@ angular.module('copayApp.services') root.walletClients[walletId].started = true; root.walletClients[walletId].doNotVerifyPayPro = isChromeApp; - if (client.incorrectDerivation) { - $log.warn('Key Derivation failed for wallet:' + walletId); - storageService.clearLastAddress(walletId, function() {}); - } - client.removeAllListeners(); client.on('report', function(n) { $log.info('BWC Report:' + n); @@ -121,6 +116,29 @@ angular.module('copayApp.services') return true; }; + root.runValidation = function(client) { + var skipDeviceValidation = root.profile.isDeviceChecked(platformInfo.ua); + var walletId = client.credentials.walletId; + + $timeout(function() { + + $log.debug('ValidatingWallet: ' + walletId + ' device validation:' + skipDeviceValidation); + $rootScope.$emit('Local/ValidatingWallet', walletId); + + client.validateKeyDerivation({ + skipDeviceValidation: skipDeviceValidation, + }, function(err, isOK) { + $rootScope.$emit('Local/ValidatingWalletEnded', walletId, isOK); + + if (isOK) { + root.profile.setChecked(platformInfo.ua, walletId); + } else { + $log.warn('Key Derivation failed for wallet:' + walletId); + storageService.clearLastAddress(walletId, function() {}); + } + }); + }, 10); + }; // Used when reading wallets from the profile root.bindWallet = function(credentials, cb) { @@ -135,22 +153,18 @@ angular.module('copayApp.services') return ((config.bwsFor && config.bwsFor[walletId]) || defaults.bws.url); }; + + var client = bwcService.getClient(JSON.stringify(credentials), { + bwsurl: getBWSURL(credentials.walletId), + }); + var skipKeyValidation = root.profile.isChecked(platformInfo.ua, credentials.walletId); - if (!skipKeyValidation) { - $rootScope.$emit('Local/ValidatingWallet'); - } - $timeout(function() { - $log.info('Binding wallet:' + credentials.walletId + ' Validating?:' + !skipKeyValidation); - var client = bwcService.getClient(JSON.stringify(credentials), { - bwsurl: getBWSURL(credentials.walletId), - skipKeyValidation: skipKeyValidation, - }); - if (!skipKeyValidation && !client.incorrectDerivation) - root.profile.setChecked(platformInfo.ua, credentials.walletId); + if (!skipKeyValidation) + root.runValidation(client); - return cb(null, root.bindWalletClient(client)); - }, skipKeyValidation ? 50 : 0); + $log.info('Binding wallet:' + credentials.walletId + ' Validating?:' + !skipKeyValidation); + return cb(null, root.bindWalletClient(client)); }; root.bindProfile = function(profile, cb) { From 57aecf7e1b4df5ad348607bd5ce193557f232ae2 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Tue, 14 Jun 2016 14:05:25 -0300 Subject: [PATCH 2/3] fix skip Validation. Replaces scanning with updating --- src/js/controllers/index.js | 6 +++--- src/js/services/profileService.js | 14 ++++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index bc1daeaa4..1b5fb175e 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -286,7 +286,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r } else { self.isSingleAddress = !!ret.wallet.singleAddress; if (!opts.quiet) - ongoingProcess.set('scanning', ret.wallet.scanStatus == 'running'); + self.updating = ret.wallet.scanStatus == 'running'; } return cb(err, ret); }); @@ -1015,13 +1015,13 @@ angular.module('copayApp.controllers').controller('indexController', function($r if (!c.isComplete()) return; if (self.walletId == walletId) - ongoingProcess.set('scanning', true); + self.updating = true; c.startScan({ includeCopayerBranches: true, }, function(err) { if (err && self.walletId == walletId) { - ongoingProcess.set('scanning', false); + self.updating = false; self.handleError(err); $rootScope.$apply(); } diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 25f4a42cd..fc893dff2 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -122,12 +122,13 @@ angular.module('copayApp.services') $timeout(function() { - $log.debug('ValidatingWallet: ' + walletId + ' device validation:' + skipDeviceValidation); + $log.debug('ValidatingWallet: ' + walletId + ' skip Device:' + skipDeviceValidation); $rootScope.$emit('Local/ValidatingWallet', walletId); client.validateKeyDerivation({ skipDeviceValidation: skipDeviceValidation, }, function(err, isOK) { + $log.debug('ValidatingWallet End: ' + walletId + ' isOK:' + isOK); $rootScope.$emit('Local/ValidatingWalletEnded', walletId, isOK); if (isOK) { @@ -137,7 +138,7 @@ angular.module('copayApp.services') storageService.clearLastAddress(walletId, function() {}); } }); - }, 10); + }, 3000); }; // Used when reading wallets from the profile @@ -159,7 +160,6 @@ angular.module('copayApp.services') }); var skipKeyValidation = root.profile.isChecked(platformInfo.ua, credentials.walletId); - if (!skipKeyValidation) root.runValidation(client); @@ -477,6 +477,11 @@ angular.module('copayApp.services') if (!root.profile.addWallet(JSON.parse(client.export()))) return cb(gettext('Wallet already in Copay')); + + var skipKeyValidation = root.profile.isChecked(platformInfo.ua, walletId); + if (!skipKeyValidation) + root.runValidation(client); + root.bindWalletClient(client); $rootScope.$emit('Local/WalletListUpdated', client); @@ -557,9 +562,6 @@ angular.module('copayApp.services') var addressBook = str.addressBook || {}; var historyCache = str.historyCache ||  []; - if (!walletClient.incorrectDerivation) - root.profile.setChecked(platformInfo.ua, walletClient.credentials.walletId); - root.addAndBindWalletClient(walletClient, { bwsurl: opts.bwsurl, isImport: true From 6f8210c17b32f9b0eed3a6476aad731f91edaf2e Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Tue, 14 Jun 2016 14:15:33 -0300 Subject: [PATCH 3/3] fix validation; --- src/js/services/profileService.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index fc893dff2..a484d2c67 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -138,7 +138,7 @@ angular.module('copayApp.services') storageService.clearLastAddress(walletId, function() {}); } }); - }, 3000); + }, 5000); }; // Used when reading wallets from the profile