This commit is contained in:
Matias Alejo Garcia 2014-12-31 13:27:35 -03:00
commit e736e52034
9 changed files with 500 additions and 111 deletions

View file

@ -5,6 +5,7 @@ angular.module('copayApp.controllers').controller('HomeWalletController', functi
$rootScope.title = 'Home';
var w = $rootScope.wallet;
$scope.isShared = w.isShared();
$scope.requiresMultipleSignatures = w.requiresMultipleSignatures();
if ($scope.isShared)
$scope.copayers = w.getRegisteredPeerIds();
};

View file

@ -52,9 +52,9 @@ angular.module('copayApp.controllers').controller('ProfileController', function(
return;
}
$location.path('/');
setTimeout(function() {
$timeout(function() {
notification.error('Success', 'Profile successfully deleted');
}, 1);
});
});
};
@ -73,10 +73,10 @@ angular.module('copayApp.controllers').controller('ProfileController', function(
identityService.deleteWallet($scope.item, function(err) {
if (err) {
$scope.loading = null;
$scope.error = err.message;
$scope.error = err.message || err;
copay.logger.warn(err);
}
else {
$timeout(function () { $scope.$digest(); });
} else {
$modalInstance.close($scope.item.name || $scope.item.id);
}
});

View file

@ -76,6 +76,10 @@ Identity.getKeyForEmail = function(email) {
return Identity.getStoragePrefix() + bitcore.util.sha256ripe160(email).toString('hex');
};
Identity.prototype.getChecksumForStorage = function() {
return JSON.stringify(_.sortBy(this.walletIds));
};
Identity.prototype.getId = function() {
return Identity.getKeyForEmail(this.email);
};
@ -105,7 +109,7 @@ Identity.create = function(opts, cb) {
});
};
Identity.prototype.resendVerificationEmail = function (cb) {
Identity.prototype.resendVerificationEmail = function(cb) {
var self = this;
preconditions.checkArgument(_.isFunction(cb));
@ -148,6 +152,22 @@ Identity.open = function(opts, cb) {
});
};
Identity.prototype.verifyChecksum = function(cb) {
var self = this;
self.storage.getItem(Identity.getKeyForEmail(self.email), function(err, data, headers) {
var iden;
if (err) return cb(err);
try {
iden = JSON.parse(data);
} catch (e) {
return cb(e);
}
return cb(null, self.getChecksumForStorage() == self.getChecksumForStorage.call(iden));
});
};
/**
* @param {string} walletId
* @returns {Wallet}
@ -182,22 +202,25 @@ Identity.prototype.addWallet = function(w) {
*/
Identity.prototype.deleteWallet = function(walletId, cb) {
preconditions.checkArgument(_.isString(walletId));
var self = this;
var w = this.getWalletById(walletId);
w.close();
delete this.wallets[walletId];
delete this.focusedTimestamps[walletId];
this.walletIds = _.without(this.walletIds, walletId);
this.storage.removeItem(Wallet.getStorageKey(walletId), function(err) {
self.verifyChecksum(function(err, match) {
if (err) return cb(err);
self.emitAndKeepAlive('walletDeleted', walletId);
self.store(null, cb);
if (!match) return cb('The profile is out of sync. Please re-login to get the latest changes.');
var w = self.getWalletById(walletId);
w.close();
delete self.wallets[walletId];
delete self.focusedTimestamps[walletId];
self.walletIds = _.without(self.walletIds, walletId);
self.storage.removeItem(Wallet.getStorageKey(walletId), function(err) {
if (err) return cb(err);
self.emitAndKeepAlive('walletDeleted', walletId);
self.store(null, cb);
});
});
};
@ -346,18 +369,19 @@ Identity.prototype.exportEncryptedWithWalletInfo = function(opts) {
return crypto.encrypt(this.password, this.exportWithWalletInfo(opts));
};
Identity.prototype.setBackupNeeded = function() {
this.backupNeeded = true;
this.store({
noWallets: true
}, function() {});
}
Identity.prototype.setBackupNeeded = function(backupNeeded) {
var self = this;
Identity.prototype.setBackupDone = function() {
this.backupNeeded = false;
this.store({
noWallets: true
}, function() {});
self.backupNeeded = !!backupNeeded;
self.verifyChecksum(function(err, match) {
if (err) return cb(err);
if (!match) return cb('The profile is out of sync. Please re-login to get the latest changes.');
self.store({
noWallets: true
}, function() {});
});
}
Identity.prototype.exportWithWalletInfo = function(opts) {
@ -424,8 +448,11 @@ Identity.prototype.remove = function(opts, cb) {
};
Identity.prototype._cleanUp = function() {
var self = this;
_.each(this.getWallets(), function(w) {
w.close();
delete self.wallets[w.getId()];
});
};
@ -433,7 +460,6 @@ Identity.prototype._cleanUp = function() {
* @desc Closes the wallet and disconnects all services
*/
Identity.prototype.close = function() {
this._cleanUp();
this.emitAndKeepAlive('closed');
};
@ -599,70 +625,76 @@ Identity.prototype.bindWallet = function(w) {
Identity.prototype.createWallet = function(opts, cb) {
preconditions.checkArgument(cb);
opts = opts || {};
opts.networkName = opts.networkName || 'testnet';
log.debug('### CREATING NEW WALLET.' + (opts.id ? ' USING ID: ' + opts.id : ' NEW ID') + (opts.privateKey ? ' USING PrivateKey: ' + opts.privateKey.getId() : ' NEW PrivateKey'));
var privOpts = {
networkName: opts.networkName,
};
if (opts.privateKeyHex && opts.privateKeyHex.length > 1) {
privOpts.extendedPrivateKeyString = opts.privateKeyHex;
}
opts.privateKey = opts.privateKey || new PrivateKey(privOpts);
var requiredCopayers = opts.requiredCopayers || this.walletDefaults.requiredCopayers;
var totalCopayers = opts.totalCopayers || this.walletDefaults.totalCopayers;
opts.lockTimeoutMin = this.walletDefaults.idleDurationMin;
opts.publicKeyRing = opts.publicKeyRing || new PublicKeyRing({
networkName: opts.networkName,
requiredCopayers: requiredCopayers,
totalCopayers: totalCopayers,
});
opts.publicKeyRing.addCopayer(
opts.privateKey.deriveBIP45Branch().extendedPublicKeyString(),
opts.nickname || this.getName()
);
log.debug('\t### PublicKeyRing Initialized');
opts.txProposals = opts.txProposals || new TxProposals({
networkName: opts.networkName,
});
var walletClass = opts.walletClass || Wallet;
log.debug('\t### TxProposals Initialized');
opts.networkOpts = this.networkOpts;
opts.blockchainOpts = this.blockchainOpts;
opts.spendUnconfirmed = opts.spendUnconfirmed || this.walletDefaults.spendUnconfirmed;
opts.reconnectDelay = opts.reconnectDelay || this.walletDefaults.reconnectDelay;
opts.requiredCopayers = requiredCopayers;
opts.totalCopayers = totalCopayers;
opts.version = opts.version || this.version;
var self = this;
var w = new walletClass(opts);
if (self.getWalletById(w.getId())) {
return cb('walletAlreadyExists');
}
self.addWallet(w);
self.updateFocusedTimestamp(w.getId());
self.bindWallet(w);
self.storeWallet(w, function(err) {
self.verifyChecksum(function(err, match) {
if (err) return cb(err);
if (!match) return cb('The profile is out of sync. Please re-login to get the latest changes.');
self.backupNeeded = true;
self.store({
noWallets: true,
}, function(err) {
return cb(err, w);
opts = opts || {};
opts.networkName = opts.networkName || 'testnet';
log.debug('### CREATING NEW WALLET.' + (opts.id ? ' USING ID: ' + opts.id : ' NEW ID') + (opts.privateKey ? ' USING PrivateKey: ' + opts.privateKey.getId() : ' NEW PrivateKey'));
var privOpts = {
networkName: opts.networkName,
};
if (opts.privateKeyHex && opts.privateKeyHex.length > 1) {
privOpts.extendedPrivateKeyString = opts.privateKeyHex;
}
opts.privateKey = opts.privateKey || new PrivateKey(privOpts);
var requiredCopayers = opts.requiredCopayers || self.walletDefaults.requiredCopayers;
var totalCopayers = opts.totalCopayers || self.walletDefaults.totalCopayers;
opts.lockTimeoutMin = self.walletDefaults.idleDurationMin;
opts.publicKeyRing = opts.publicKeyRing || new PublicKeyRing({
networkName: opts.networkName,
requiredCopayers: requiredCopayers,
totalCopayers: totalCopayers,
});
opts.publicKeyRing.addCopayer(
opts.privateKey.deriveBIP45Branch().extendedPublicKeyString(),
opts.nickname || self.getName()
);
log.debug('\t### PublicKeyRing Initialized');
opts.txProposals = opts.txProposals || new TxProposals({
networkName: opts.networkName,
});
var walletClass = opts.walletClass || Wallet;
log.debug('\t### TxProposals Initialized');
opts.networkOpts = self.networkOpts;
opts.blockchainOpts = self.blockchainOpts;
opts.spendUnconfirmed = opts.spendUnconfirmed || self.walletDefaults.spendUnconfirmed;
opts.reconnectDelay = opts.reconnectDelay || self.walletDefaults.reconnectDelay;
opts.requiredCopayers = requiredCopayers;
opts.totalCopayers = totalCopayers;
opts.version = opts.version || self.version;
var w = new walletClass(opts);
if (self.getWalletById(w.getId())) {
return cb('walletAlreadyExists');
}
self.addWallet(w);
self.updateFocusedTimestamp(w.getId());
self.bindWallet(w);
self.storeWallet(w, function(err) {
if (err) return cb(err);
self.backupNeeded = true;
self.store({
noWallets: true,
}, function(err) {
return cb(err, w);
});
});
});
};

View file

@ -12,7 +12,7 @@ if (!ls || ls.length < 1)
if (window && window.navigator) {
var rxaosp = window.navigator.userAgent.match(/Android.*AppleWebKit\/([\d.]+)/);
var isaosp = (rxaosp && rxaosp[1] < 537);
if (isaosp)
if (!window.cordova && isaosp)
unsupported = true;
}

View file

@ -72,7 +72,7 @@ BackupService.prototype.walletDownload = function(wallet) {
};
BackupService.prototype.profileEncrypted = function(iden) {
iden.setBackupDone();
iden.setBackupNeeded(false);
return iden.exportEncryptedWithWalletInfo(iden.password);
}