2014-06-16 16:46:17 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
2014-10-28 12:01:09 -03:00
|
|
|
var BackupService = function($rootScope, notification) {
|
2014-10-28 00:31:30 -03:00
|
|
|
this.$rootScope = $rootScope;
|
2014-06-18 13:01:50 -03:00
|
|
|
this.notifications = notification;
|
2014-06-17 11:33:43 -03:00
|
|
|
};
|
2014-06-16 16:46:17 -03:00
|
|
|
|
2014-09-12 10:40:47 -03:00
|
|
|
BackupService.prototype.getCopayer = function(wallet) {
|
2014-09-12 11:10:45 -03:00
|
|
|
return wallet.totalCopayers > 1 ? wallet.getMyCopayerNickname() : '';
|
2014-09-12 10:40:47 -03:00
|
|
|
};
|
|
|
|
|
|
2014-10-16 10:18:37 -03:00
|
|
|
BackupService.prototype._download = function(ew, walletName, filename) {
|
2014-06-16 16:46:17 -03:00
|
|
|
var blob = new Blob([ew], {
|
|
|
|
|
type: 'text/plain;charset=utf-8'
|
|
|
|
|
});
|
2014-10-16 10:18:37 -03:00
|
|
|
|
|
|
|
|
this.notifications.success('Backup created', 'Encrypted backup file saved');
|
2014-07-17 16:53:38 -03:00
|
|
|
|
2014-06-16 16:46:17 -03:00
|
|
|
// otherwise lean on the browser implementation
|
|
|
|
|
saveAs(blob, filename);
|
|
|
|
|
};
|
|
|
|
|
|
2014-10-21 15:11:04 -03:00
|
|
|
BackupService.prototype.walletEncrypted = function(wallet) {
|
2014-10-28 00:31:30 -03:00
|
|
|
return wallet.exportEncrypted(this.$rootScope.iden.password);
|
2014-10-21 15:11:04 -03:00
|
|
|
}
|
2014-10-16 10:18:37 -03:00
|
|
|
|
|
|
|
|
BackupService.prototype.walletDownload = function(wallet) {
|
2014-10-28 00:31:30 -03:00
|
|
|
var ew = this.walletEncrypted(wallet);
|
2014-10-16 10:18:37 -03:00
|
|
|
var walletName = wallet.getName();
|
|
|
|
|
var copayerName = this.getCopayer(wallet);
|
|
|
|
|
var filename = (copayerName ? copayerName + '-' : '') + walletName + '-keybackup.json.aes';
|
|
|
|
|
this._download(ew, walletName, filename)
|
|
|
|
|
};
|
|
|
|
|
|
2014-10-21 15:11:04 -03:00
|
|
|
BackupService.prototype.profileEncrypted = function(iden) {
|
2014-10-28 00:31:30 -03:00
|
|
|
return iden.exportEncryptedWithWalletInfo(iden.password);
|
2014-10-21 15:11:04 -03:00
|
|
|
}
|
|
|
|
|
|
2014-10-16 10:18:37 -03:00
|
|
|
BackupService.prototype.profileDownload = function(iden) {
|
2014-10-28 00:31:30 -03:00
|
|
|
var ew = this.profileEncrypted(iden);
|
2014-11-26 12:08:26 -03:00
|
|
|
iden.setBackupDone();
|
2014-10-28 00:31:30 -03:00
|
|
|
var name = iden.fullName;
|
2014-10-16 10:18:37 -03:00
|
|
|
var filename = name + '-profile.json';
|
|
|
|
|
this._download(ew, name, filename)
|
|
|
|
|
};
|
|
|
|
|
|
2014-06-17 11:33:43 -03:00
|
|
|
angular.module('copayApp.services').service('backupService', BackupService);
|