new key test, upgrades to bwc 2.7.0

This commit is contained in:
Matias Alejo Garcia 2016-06-14 12:28:21 -03:00
commit 52a20334e1
No known key found for this signature in database
GPG key ID: 02470DB551277AB3
4 changed files with 55 additions and 26 deletions

View file

@ -42,7 +42,7 @@
"url": "https://github.com/bitpay/copay/issues" "url": "https://github.com/bitpay/copay/issues"
}, },
"dependencies": { "dependencies": {
"bitcore-wallet-client": "2.6.0", "bitcore-wallet-client": "2.7.0",
"express": "^4.11.2", "express": "^4.11.2",
"fs": "0.0.2", "fs": "0.0.2",
"grunt": "^0.4.5", "grunt": "^0.4.5",

View file

@ -135,7 +135,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.isPrivKeyEncrypted = fc.isPrivKeyEncrypted(); self.isPrivKeyEncrypted = fc.isPrivKeyEncrypted();
self.externalSource = fc.getPrivKeyExternalSourceName(); self.externalSource = fc.getPrivKeyExternalSourceName();
self.account = fc.credentials.account; self.account = fc.credentials.account;
self.incorrectDerivation = fc.incorrectDerivation; self.incorrectDerivation = fc.keyDerivationOk === false;
if (self.externalSource == 'trezor') if (self.externalSource == 'trezor')
self.account++; 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) { self.setAddressbook = function(ab) {
if (ab) { if (ab) {
self.addressbook = ab; self.addressbook = ab;
@ -1408,12 +1413,17 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.tab = 'walletHome'; self.tab = 'walletHome';
}); });
$rootScope.$on('Local/ValidatingWallet', function() { $rootScope.$on('Local/ValidatingWallet', function(ev, walletId) {
ongoingProcess.set('validatingWallet', true); if (self.isInFocus(walletId)) {
ongoingProcess.set('validatingWallet', true);
}
}); });
$rootScope.$on('Local/ProfileBound', function() { $rootScope.$on('Local/ValidatingWalletEnded', function(ev, walletId, isOK) {
ongoingProcess.set('validatingWallet', false); if (self.isInFocus(walletId)) {
ongoingProcess.set('validatingWallet', false);
self.incorrectDerivation = isOK === false;
}
}); });
$rootScope.$on('Local/ClearHistory', function(event) { $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) { $rootScope.$on('Local/WalletCompleted', function(event, walletId) {
var fc = profileService.focusedClient; if (self.isInFocus(walletId)) {
if (fc && fc.credentials.walletId == walletId) {
// reset main wallet variables // reset main wallet variables
self.setFocusedWallet(); self.setFocusedWallet();
go.walletHome(); go.walletHome();

View file

@ -57,6 +57,12 @@ Profile.prototype.isChecked = function(ua, walletId) {
return !!(this.checkedUA == ua && this.checked[walletId]); return !!(this.checkedUA == ua && this.checked[walletId]);
}; };
Profile.prototype.isDeviceChecked = function(ua) {
return this.checkedUA == ua;
};
Profile.prototype.setChecked = function(ua, walletId) { Profile.prototype.setChecked = function(ua, walletId) {
if (this.checkedUA != ua) { if (this.checkedUA != ua) {
this.checkedUA = ua; this.checkedUA = ua;

View file

@ -75,11 +75,6 @@ angular.module('copayApp.services')
root.walletClients[walletId].started = true; root.walletClients[walletId].started = true;
root.walletClients[walletId].doNotVerifyPayPro = isChromeApp; root.walletClients[walletId].doNotVerifyPayPro = isChromeApp;
if (client.incorrectDerivation) {
$log.warn('Key Derivation failed for wallet:' + walletId);
storageService.clearLastAddress(walletId, function() {});
}
client.removeAllListeners(); client.removeAllListeners();
client.on('report', function(n) { client.on('report', function(n) {
$log.info('BWC Report:' + n); $log.info('BWC Report:' + n);
@ -121,6 +116,29 @@ angular.module('copayApp.services')
return true; 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 // Used when reading wallets from the profile
root.bindWallet = function(credentials, cb) { root.bindWallet = function(credentials, cb) {
@ -135,22 +153,18 @@ angular.module('copayApp.services')
return ((config.bwsFor && config.bwsFor[walletId]) || defaults.bws.url); 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); 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) if (!skipKeyValidation)
root.profile.setChecked(platformInfo.ua, credentials.walletId); root.runValidation(client);
return cb(null, root.bindWalletClient(client)); $log.info('Binding wallet:' + credentials.walletId + ' Validating?:' + !skipKeyValidation);
}, skipKeyValidation ? 50 : 0); return cb(null, root.bindWalletClient(client));
}; };
root.bindProfile = function(profile, cb) { root.bindProfile = function(profile, cb) {