commit
3323ee7662
4 changed files with 65 additions and 51 deletions
|
|
@ -62,6 +62,7 @@ var defaultConfig = {
|
||||||
|
|
||||||
EncryptedInsightStorage: {
|
EncryptedInsightStorage: {
|
||||||
url: 'https://test-insight.bitpay.com:443/api/email'
|
url: 'https://test-insight.bitpay.com:443/api/email'
|
||||||
|
// url: 'http://localhost:3001/api/email'
|
||||||
},
|
},
|
||||||
|
|
||||||
GoogleDrive: {
|
GoogleDrive: {
|
||||||
|
|
|
||||||
|
|
@ -224,13 +224,19 @@ Identity.prototype.storeWallet = function(wallet, cb) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Identity.prototype.toObj = function() {
|
Identity.prototype.toObj = function() {
|
||||||
return _.extend({walletIds: _.keys(this.wallets)},
|
return _.extend({
|
||||||
_.pick(this, 'version', 'fullName', 'password', 'email'));
|
walletIds: _.keys(this.wallets)
|
||||||
|
},
|
||||||
|
_.pick(this, 'version', 'fullName', 'password', 'email'));
|
||||||
};
|
};
|
||||||
|
|
||||||
Identity.prototype.exportWithWalletInfo = function() {
|
Identity.prototype.exportWithWalletInfo = function() {
|
||||||
return _.extend({wallets: _.map(this.wallets, function(wallet) { return wallet.toObj(); })},
|
return _.extend({
|
||||||
_.pick(this, 'version', 'fullName', 'password', 'email'));
|
wallets: _.map(this.wallets, function(wallet) {
|
||||||
|
return wallet.toObj();
|
||||||
|
})
|
||||||
|
},
|
||||||
|
_.pick(this, 'version', 'fullName', 'password', 'email'));
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -493,7 +499,7 @@ Identity.prototype.deleteWallet = function(walletId, cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
delete this.wallets[walletId];
|
delete this.wallets[walletId];
|
||||||
this.storage.deleteItem(walletId, function(err) {
|
this.storage.removeItem(Wallet.getStorageKey(walletId), function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return cb(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
|
|
@ -513,6 +519,7 @@ Identity.prototype.decodeSecret = function(secret) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Identity.prototype.getLastFocusedWallet = function() {
|
Identity.prototype.getLastFocusedWallet = function() {
|
||||||
|
if (_.keys(this.wallets).length == 0) return;
|
||||||
return _.max(this.wallets, function(wallet) {
|
return _.max(this.wallets, function(wallet) {
|
||||||
return wallet.lastTimestamp || 0;
|
return wallet.lastTimestamp || 0;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -9,13 +9,15 @@ inherits(EncryptedInsightStorage, InsightStorage);
|
||||||
|
|
||||||
EncryptedInsightStorage.prototype.getItem = function(name, callback) {
|
EncryptedInsightStorage.prototype.getItem = function(name, callback) {
|
||||||
var key = cryptoUtil.kdf(this.password, this.email);
|
var key = cryptoUtil.kdf(this.password, this.email);
|
||||||
InsightStorage.prototype.getItem.apply(this, [name, function(err, body) {
|
InsightStorage.prototype.getItem.apply(this, [name,
|
||||||
var decryptedJson = cryptoUtil.decrypt(key, body);
|
function(err, body) {
|
||||||
if (!decryptedJson) {
|
var decryptedJson = cryptoUtil.decrypt(key, body);
|
||||||
return callback('Internal Error');
|
if (!decryptedJson) {
|
||||||
|
return callback('Internal Error');
|
||||||
|
}
|
||||||
|
return callback(null, decryptedJson);
|
||||||
}
|
}
|
||||||
return callback(null, decryptedJson);
|
]);
|
||||||
}]);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
EncryptedInsightStorage.prototype.setItem = function(name, value, callback) {
|
EncryptedInsightStorage.prototype.setItem = function(name, value, callback) {
|
||||||
|
|
@ -24,4 +26,9 @@ EncryptedInsightStorage.prototype.setItem = function(name, value, callback) {
|
||||||
InsightStorage.prototype.setItem.apply(this, [name, record, callback]);
|
InsightStorage.prototype.setItem.apply(this, [name, record, callback]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
EncryptedInsightStorage.prototype.removeItem = function(name, callback) {
|
||||||
|
var key = cryptoUtil.kdf(this.password, this.email);
|
||||||
|
InsightStorage.prototype.removeItem.apply(this, [name, callback]);
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = EncryptedInsightStorage;
|
module.exports = EncryptedInsightStorage;
|
||||||
|
|
|
||||||
|
|
@ -1,48 +1,47 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.services')
|
angular.module('copayApp.services')
|
||||||
.factory('identityService', function($rootScope, $location, pluginManager, controllerUtils) {
|
.factory('identityService', function($rootScope, $location, pluginManager, controllerUtils) {
|
||||||
var root = {};
|
var root = {};
|
||||||
|
|
||||||
root.create = function (scope, form) {
|
root.create = function(scope, form) {
|
||||||
copay.Identity.create({
|
copay.Identity.create({
|
||||||
email: form.email.$modelValue,
|
email: form.email.$modelValue,
|
||||||
password: form.password.$modelValue,
|
password: form.password.$modelValue,
|
||||||
pluginManager: pluginManager,
|
pluginManager: pluginManager,
|
||||||
network: config.network,
|
network: config.network,
|
||||||
networkName: config.networkName,
|
networkName: config.networkName,
|
||||||
walletDefaults: config.wallet,
|
walletDefaults: config.wallet,
|
||||||
passphraseConfig: config.passphraseConfig,
|
passphraseConfig: config.passphraseConfig,
|
||||||
}, function(err, iden) {
|
}, function(err, iden) {
|
||||||
var firstWallet = iden.getLastFocusedWallet();
|
|
||||||
controllerUtils.bindProfile(scope, iden, firstWallet);
|
|
||||||
scope.loading = false;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
root.open = function (scope, form) {
|
|
||||||
copay.Identity.open({
|
|
||||||
email: form.email.$modelValue,
|
|
||||||
password: form.password.$modelValue,
|
|
||||||
pluginManager: pluginManager,
|
|
||||||
network: config.network,
|
|
||||||
networkName: config.networkName,
|
|
||||||
walletDefaults: config.wallet,
|
|
||||||
passphraseConfig: config.passphraseConfig,
|
|
||||||
}, function(err, iden) {
|
|
||||||
if (err && !iden) {
|
|
||||||
console.log('Error:' + err)
|
|
||||||
controllerUtils.onErrorDigest(
|
|
||||||
scope, (err.toString() || '').match('PNOTFOUND') ? 'Profile not found' : 'Unknown error');
|
|
||||||
} else {
|
|
||||||
var firstWallet = iden.getLastFocusedWallet();
|
var firstWallet = iden.getLastFocusedWallet();
|
||||||
controllerUtils.bindProfile(scope, iden, firstWallet);
|
controllerUtils.bindProfile(scope, iden, firstWallet);
|
||||||
}
|
scope.loading = false;
|
||||||
scope.loading = false;
|
});
|
||||||
});
|
};
|
||||||
}
|
|
||||||
|
|
||||||
return root;
|
|
||||||
});
|
|
||||||
|
|
||||||
|
root.open = function(scope, form) {
|
||||||
|
copay.Identity.open({
|
||||||
|
email: form.email.$modelValue,
|
||||||
|
password: form.password.$modelValue,
|
||||||
|
pluginManager: pluginManager,
|
||||||
|
network: config.network,
|
||||||
|
networkName: config.networkName,
|
||||||
|
walletDefaults: config.wallet,
|
||||||
|
passphraseConfig: config.passphraseConfig,
|
||||||
|
}, function(err, iden) {
|
||||||
|
if (err && !iden) {
|
||||||
|
console.log('Error:' + err)
|
||||||
|
controllerUtils.onErrorDigest(
|
||||||
|
scope, (err.toString() || '').match('PNOTFOUND') ? 'Profile not found' : 'Unknown error');
|
||||||
|
} else {
|
||||||
|
var firstWallet = iden.getLastFocusedWallet();
|
||||||
|
controllerUtils.bindProfile(scope, iden, firstWallet);
|
||||||
|
}
|
||||||
|
scope.loading = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return root;
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue