mirror of https://github.com/BTCPrivate/copay.git
Merge pull request #4276 from matiu/feat/derivation-test-cache
Feat/derivation test cache
This commit is contained in:
commit
bab8a26e1e
|
@ -6,31 +6,9 @@ bwcModule.constant('MODULE_VERSION', '1.0.0');
|
|||
bwcModule.provider("bwcService", function() {
|
||||
var provider = {};
|
||||
|
||||
var config = {
|
||||
baseUrl: 'https://bws.bitpay.com/bws/api',
|
||||
verbose: null,
|
||||
transports: null
|
||||
};
|
||||
|
||||
provider.setBaseUrl = function(url) {
|
||||
config.baseUrl = url;
|
||||
};
|
||||
|
||||
provider.setVerbose = function(v) {
|
||||
config.verbose = v ? true : false;
|
||||
};
|
||||
|
||||
provider.$get = function() {
|
||||
var service = {};
|
||||
|
||||
service.setBaseUrl = function(url) {
|
||||
config.baseUrl = url;
|
||||
};
|
||||
|
||||
service.setTransports = function(transports) {
|
||||
config.transports = transports;
|
||||
};
|
||||
|
||||
service.getBitcore = function() {
|
||||
return Client.Bitcore;
|
||||
};
|
||||
|
@ -46,20 +24,21 @@ bwcModule.provider("bwcService", function() {
|
|||
service.buildTx = Client.buildTx;
|
||||
service.parseSecret = Client.parseSecret;
|
||||
service.Client = Client;
|
||||
service.config = config;
|
||||
|
||||
service.getUtils = function() {
|
||||
return Client.Utils;
|
||||
};
|
||||
|
||||
service.getClient = function(walletData) {
|
||||
service.getClient = function(walletData, opts) {
|
||||
|
||||
//note opts use `baseurl` all lowercase;
|
||||
var bwc = new Client({
|
||||
baseUrl: config.baseUrl,
|
||||
verbose: config.verbose,
|
||||
transports: config.transports
|
||||
baseUrl: opts.baseurl || 'https://bws.bitpay.com/bws/api',
|
||||
verbose: opts.verbose,
|
||||
transports: ['polling'],
|
||||
});
|
||||
if (walletData)
|
||||
bwc.import(walletData);
|
||||
bwc.import(walletData, opts);
|
||||
return bwc;
|
||||
};
|
||||
return service;
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -62,29 +62,34 @@ angular.module('copayApp.services')
|
|||
});
|
||||
};
|
||||
|
||||
root.setBaseURL = function(walletId) {
|
||||
var config = configService.getSync();
|
||||
var defaults = configService.getDefaults();
|
||||
|
||||
bwcService.setBaseUrl((config.bwsFor && config.bwsFor[walletId]) || defaults.bws.url);
|
||||
bwcService.setTransports(['polling']);
|
||||
}
|
||||
|
||||
root.setWalletClient = function(credentials) {
|
||||
if (root.walletClients[credentials.walletId] &&
|
||||
root.walletClients[credentials.walletId].started) {
|
||||
return;
|
||||
}
|
||||
|
||||
root.setBaseURL(credentials.walletId);
|
||||
|
||||
var getBaseURL = function(walletId) {
|
||||
var config = configService.getSync();
|
||||
var defaults = configService.getDefaults();
|
||||
|
||||
return ((config.bwsFor && config.bwsFor[walletId]) || defaults.bws.url);
|
||||
};
|
||||
|
||||
$log.debug('Importing wallet:' + credentials.walletId);
|
||||
var client = bwcService.getClient(JSON.stringify(credentials));
|
||||
var skipKeyValidation = root.profile.checked[credentials.walletId] == platformInfo.ua;
|
||||
var client = bwcService.getClient(JSON.stringify(credentials), {
|
||||
baseurl: 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();
|
||||
|
@ -219,10 +224,7 @@ angular.module('copayApp.services')
|
|||
|
||||
root._seedWallet = function(opts, cb) {
|
||||
opts = opts || {};
|
||||
if (opts.bwsurl)
|
||||
bwcService.setBaseUrl(opts.bwsurl);
|
||||
|
||||
var walletClient = bwcService.getClient();
|
||||
var walletClient = bwcService.getClient(null, opts);
|
||||
var network = opts.networkName || 'livenet';
|
||||
|
||||
|
||||
|
@ -331,8 +333,8 @@ angular.module('copayApp.services')
|
|||
|
||||
// check if exist
|
||||
if (lodash.find(root.profile.credentials, {
|
||||
'walletId': walletData.walletId
|
||||
})) {
|
||||
'walletId': walletData.walletId
|
||||
})) {
|
||||
return cb(gettext('Cannot join the same wallet more that once'));
|
||||
}
|
||||
} catch (ex) {
|
||||
|
@ -471,10 +473,8 @@ angular.module('copayApp.services')
|
|||
};
|
||||
|
||||
root.importWallet = function(str, opts, cb) {
|
||||
if (opts.bwsurl)
|
||||
bwcService.setBaseUrl(opts.bwsurl);
|
||||
|
||||
var walletClient = bwcService.getClient();
|
||||
var walletClient = bwcService.getClient(null, opts);
|
||||
|
||||
$log.debug('Importing Wallet:', opts);
|
||||
try {
|
||||
|
@ -501,10 +501,7 @@ angular.module('copayApp.services')
|
|||
};
|
||||
|
||||
root.importExtendedPrivateKey = function(xPrivKey, opts, cb) {
|
||||
if (opts.bwsurl)
|
||||
bwcService.setBaseUrl(opts.bwsurl);
|
||||
|
||||
var walletClient = bwcService.getClient();
|
||||
var walletClient = bwcService.getClient(null, opts);
|
||||
$log.debug('Importing Wallet xPrivKey');
|
||||
|
||||
walletClient.importFromExtendedPrivateKey(xPrivKey, opts, function(err) {
|
||||
|
@ -523,10 +520,7 @@ angular.module('copayApp.services')
|
|||
};
|
||||
|
||||
root.importMnemonic = function(words, opts, cb) {
|
||||
if (opts.bwsurl)
|
||||
bwcService.setBaseUrl(opts.bwsurl);
|
||||
|
||||
var walletClient = bwcService.getClient();
|
||||
var walletClient = bwcService.getClient(null, opts);
|
||||
|
||||
$log.debug('Importing Wallet Mnemonic');
|
||||
|
||||
|
@ -544,10 +538,7 @@ angular.module('copayApp.services')
|
|||
};
|
||||
|
||||
root.importExtendedPublicKey = function(opts, cb) {
|
||||
if (opts.bwsurl)
|
||||
bwcService.setBaseUrl(opts.bwsurl);
|
||||
|
||||
var walletClient = bwcService.getClient();
|
||||
var walletClient = bwcService.getClient(null, opts);
|
||||
$log.debug('Importing Wallet XPubKey');
|
||||
|
||||
walletClient.importFromExtendedPublicKey(opts.extendedPublicKey, opts.externalSource, opts.entropySource, {
|
||||
|
@ -572,8 +563,6 @@ angular.module('copayApp.services')
|
|||
var defaults = configService.getDefaults();
|
||||
|
||||
configService.get(function(err) {
|
||||
bwcService.setBaseUrl(defaults.bws.url);
|
||||
bwcService.setTransports(['polling']);
|
||||
root._createNewProfile(opts, function(err, p) {
|
||||
if (err) return cb(err);
|
||||
|
||||
|
@ -589,7 +578,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);
|
||||
});
|
||||
};
|
||||
|
@ -641,7 +630,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);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -118,6 +118,8 @@ angular.module('copayApp.services')
|
|||
});
|
||||
};
|
||||
|
||||
root.storeProfileThrottled = lodash.throttle(root.storeProfile, 5000);
|
||||
|
||||
root.getProfile = function(cb) {
|
||||
storage.get('profile', function(err, str) {
|
||||
if (err || !str)
|
||||
|
|
|
@ -85,21 +85,20 @@ mocks.init = function(fixtures, controllerName, opts, done) {
|
|||
module('bwcModule', function($provide) {
|
||||
$provide.decorator('bwcService', function($delegate, lodash) {
|
||||
var getClient = $delegate.getClient;
|
||||
var config = $delegate.config;
|
||||
|
||||
// Fix Encryption IVs
|
||||
var utils = $delegate.getUtils();
|
||||
utils.SJCL.iv = 'BZQVWAP6d1e4G8Fq1rQKbA==';
|
||||
|
||||
$delegate.getClient = function(walletData) {
|
||||
$delegate.getClient = function(walletData, opts) {
|
||||
|
||||
var bwc = new $delegate.Client({
|
||||
baseUrl: config.baseUrl,
|
||||
verbose: config.verbose,
|
||||
transports: config.transports
|
||||
});
|
||||
var bwc = new $delegate.Client();
|
||||
if (walletData)
|
||||
bwc.import(walletData);
|
||||
bwc.import(walletData, {
|
||||
baseUrl: opts.baseurl || 'https://bws.bitpay.com/bws/api',
|
||||
verbose: opts.verbose,
|
||||
transports: ['polling'],
|
||||
});
|
||||
|
||||
function createHash(method, url, args) {
|
||||
var headers = JSON.stringify(bwc._getHeaders(method, url, args));
|
||||
|
|
Loading…
Reference in New Issue