mirror of https://github.com/BTCPrivate/copay.git
implement cache for key derivation, using user-agent
This commit is contained in:
parent
02861992e6
commit
d08d4e3650
|
@ -42,7 +42,7 @@
|
||||||
"url": "https://github.com/bitpay/copay/issues"
|
"url": "https://github.com/bitpay/copay/issues"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bitcore-wallet-client": "https://github.com/bitpay/bitcore-wallet-client#baf7b8e50f53d3a62d0f5804919f0f0218872daf",
|
"bitcore-wallet-client": "2.5.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",
|
||||||
|
|
|
@ -16,6 +16,7 @@ Profile.create = function(opts) {
|
||||||
x.createdOn = Date.now();
|
x.createdOn = Date.now();
|
||||||
x.credentials = opts.credentials || [];
|
x.credentials = opts.credentials || [];
|
||||||
x.disclaimerAccepted = false;
|
x.disclaimerAccepted = false;
|
||||||
|
x.checked = {};
|
||||||
return x;
|
return x;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -25,6 +26,7 @@ Profile.fromObj = function(obj) {
|
||||||
x.createdOn = obj.createdOn;
|
x.createdOn = obj.createdOn;
|
||||||
x.credentials = obj.credentials;
|
x.credentials = obj.credentials;
|
||||||
x.disclaimerAccepted = obj.disclaimerAccepted;
|
x.disclaimerAccepted = obj.disclaimerAccepted;
|
||||||
|
x.checked = obj.checked || {};
|
||||||
|
|
||||||
if (x.credentials[0] && typeof x.credentials[0] != 'object')
|
if (x.credentials[0] && typeof x.credentials[0] != 'object')
|
||||||
throw ("credentials should be an object");
|
throw ("credentials should be an object");
|
||||||
|
|
|
@ -66,7 +66,7 @@ angular.module('copayApp.services')
|
||||||
var config = configService.getSync();
|
var config = configService.getSync();
|
||||||
var defaults = configService.getDefaults();
|
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) {
|
root.setWalletClient = function(credentials) {
|
||||||
|
@ -75,17 +75,20 @@ angular.module('copayApp.services')
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$log.debug('Importing wallet:' + credentials.walletId);
|
$log.debug('Importing wallet:' + credentials.walletId);
|
||||||
|
var skipKeyValidation = root.profile.checked[credentials.walletId] == platformInfo.ua;
|
||||||
var client = bwcService.getClient(JSON.stringify(credentials), {
|
var client = bwcService.getClient(JSON.stringify(credentials), {
|
||||||
baseurl: root._getBaseURL(credentials.walletId),
|
baseurl: root._getBaseURL(credentials.walletId),
|
||||||
|
skipKeyValidation: skipKeyValidation,
|
||||||
});
|
});
|
||||||
root.walletClients[credentials.walletId] = client;
|
root.walletClients[credentials.walletId] = client;
|
||||||
|
|
||||||
if (client.incorrectDerivation) {
|
if (client.incorrectDerivation) {
|
||||||
$log.warn('Key Derivation failed for wallet:' + credentials.walletId);
|
$log.warn('Key Derivation failed for wallet:' + credentials.walletId);
|
||||||
storageService.clearLastAddress(credentials.walletId, function() {});
|
storageService.clearLastAddress(credentials.walletId, function() {});
|
||||||
|
} else if (!skipKeyValidation) {
|
||||||
|
root.profile.checked[credentials.walletId] = platformInfo.ua;
|
||||||
|
storageService.storeProfileThrottled(root.profile, function() {});
|
||||||
}
|
}
|
||||||
|
|
||||||
client.removeAllListeners();
|
client.removeAllListeners();
|
||||||
|
@ -574,7 +577,7 @@ angular.module('copayApp.services')
|
||||||
|
|
||||||
root.setDisclaimerAccepted = function(cb) {
|
root.setDisclaimerAccepted = function(cb) {
|
||||||
root.profile.disclaimerAccepted = true;
|
root.profile.disclaimerAccepted = true;
|
||||||
storageService.storeProfile(root.profile, function(err) {
|
storageService.storeProfileThrottled(root.profile, function(err) {
|
||||||
return cb(err);
|
return cb(err);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -626,7 +629,7 @@ angular.module('copayApp.services')
|
||||||
newCredentials.push(JSON.parse(fc.export()));
|
newCredentials.push(JSON.parse(fc.export()));
|
||||||
root.profile.credentials = newCredentials;
|
root.profile.credentials = newCredentials;
|
||||||
|
|
||||||
storageService.storeProfile(root.profile, cb);
|
storageService.storeProfileThrottled(root.profile, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -113,11 +113,14 @@ angular.module('copayApp.services')
|
||||||
};
|
};
|
||||||
|
|
||||||
root.storeProfile = function(profile, cb) {
|
root.storeProfile = function(profile, cb) {
|
||||||
|
console.log('[storageService.js.115:storeProfile:]',profile); //TODO
|
||||||
encryptOnMobile(profile.toObj(), function(err, x) {
|
encryptOnMobile(profile.toObj(), function(err, x) {
|
||||||
storage.set('profile', x, cb);
|
storage.set('profile', x, cb);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
root.storeProfileThrottled = lodash.throttle(root.storeProfile, 5000);
|
||||||
|
|
||||||
root.getProfile = function(cb) {
|
root.getProfile = function(cb) {
|
||||||
storage.get('profile', function(err, str) {
|
storage.get('profile', function(err, str) {
|
||||||
if (err || !str)
|
if (err || !str)
|
||||||
|
@ -173,14 +176,6 @@ angular.module('copayApp.services')
|
||||||
storage.remove('backup-' + walletId, cb);
|
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) {
|
root.setCleanAndScanAddresses = function(walletId, cb) {
|
||||||
storage.set('CleanAndScanAddresses', walletId, cb);
|
storage.set('CleanAndScanAddresses', walletId, cb);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue