implement cache for key derivation, using user-agent

This commit is contained in:
Matias Alejo Garcia 2016-06-01 19:56:47 -03:00
parent 02861992e6
commit d08d4e3650
No known key found for this signature in database
GPG Key ID: 02470DB551277AB3
4 changed files with 14 additions and 14 deletions

View File

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

View File

@ -16,6 +16,7 @@ Profile.create = function(opts) {
x.createdOn = Date.now();
x.credentials = opts.credentials || [];
x.disclaimerAccepted = false;
x.checked = {};
return x;
};
@ -25,6 +26,7 @@ Profile.fromObj = function(obj) {
x.createdOn = obj.createdOn;
x.credentials = obj.credentials;
x.disclaimerAccepted = obj.disclaimerAccepted;
x.checked = obj.checked || {};
if (x.credentials[0] && typeof x.credentials[0] != 'object')
throw ("credentials should be an object");

View File

@ -66,7 +66,7 @@ angular.module('copayApp.services')
var config = configService.getSync();
var defaults = configService.getDefaults();
bwcService.setBaseUrl((config.bwsFor && config.bwsFor[walletId]) || defaults.bws.url);
return ((config.bwsFor && config.bwsFor[walletId]) || defaults.bws.url);
}
root.setWalletClient = function(credentials) {
@ -75,17 +75,20 @@ angular.module('copayApp.services')
return;
}
$log.debug('Importing wallet:' + credentials.walletId);
var skipKeyValidation = root.profile.checked[credentials.walletId] == platformInfo.ua;
var client = bwcService.getClient(JSON.stringify(credentials), {
baseurl: root._getBaseURL(credentials.walletId),
skipKeyValidation: skipKeyValidation,
});
root.walletClients[credentials.walletId] = client;
if (client.incorrectDerivation) {
$log.warn('Key Derivation failed for wallet:' + credentials.walletId);
storageService.clearLastAddress(credentials.walletId, function() {});
} else if (!skipKeyValidation) {
root.profile.checked[credentials.walletId] = platformInfo.ua;
storageService.storeProfileThrottled(root.profile, function() {});
}
client.removeAllListeners();
@ -574,7 +577,7 @@ angular.module('copayApp.services')
root.setDisclaimerAccepted = function(cb) {
root.profile.disclaimerAccepted = true;
storageService.storeProfile(root.profile, function(err) {
storageService.storeProfileThrottled(root.profile, function(err) {
return cb(err);
});
};
@ -626,7 +629,7 @@ angular.module('copayApp.services')
newCredentials.push(JSON.parse(fc.export()));
root.profile.credentials = newCredentials;
storageService.storeProfile(root.profile, cb);
storageService.storeProfileThrottled(root.profile, cb);
};

View File

@ -113,11 +113,14 @@ angular.module('copayApp.services')
};
root.storeProfile = function(profile, cb) {
console.log('[storageService.js.115:storeProfile:]',profile); //TODO
encryptOnMobile(profile.toObj(), function(err, x) {
storage.set('profile', x, cb);
});
};
root.storeProfileThrottled = lodash.throttle(root.storeProfile, 5000);
root.getProfile = function(cb) {
storage.get('profile', function(err, str) {
if (err || !str)
@ -173,14 +176,6 @@ angular.module('copayApp.services')
storage.remove('backup-' + walletId, cb);
};
root.setDerivationTestFlag = function(walletId, ua, cb) {
storage.set('DerivationTest-'+walletId+ua.replace(' ', ''), true, cb);
};
root.getDerivationTestFlag = function(walletId, ua, cb) {
storage.get('DerivationTest-'+walletId+ua.replace(' ', ''), cb);
};
root.setCleanAndScanAddresses = function(walletId, cb) {
storage.set('CleanAndScanAddresses', walletId, cb);
};