mirror of https://github.com/BTCPrivate/copay.git
Merge pull request #255 from colkito/feature/encrypted-web-backup
Feature/encrypted web backup
This commit is contained in:
commit
4e09b6b503
|
@ -187,7 +187,12 @@
|
|||
<div ng-controller="ImportController">
|
||||
<h3>{{title}}</h3>
|
||||
<div class="large-6 columns">
|
||||
<input type="file" class="form-control" placeholder="Select a backup file" ng-model="backupFile" autofocus="" ng-file-select>
|
||||
<input type="password" class="form-control" placeholder="Your wallet password" ng-model="password" autofocus required>
|
||||
<h6>Select a backup file</h6>
|
||||
<input type="file" class="form-control" placeholder="Select a backup file" ng-model="backupFile" ng-file-select>
|
||||
<h6>Or just paste the backup text here</h6>
|
||||
<textarea class="form-control" ng-model="backupText"></textarea>
|
||||
<button class="button primary expand radius" ng-click="import()">Import backup</button>
|
||||
</div>
|
||||
</div>
|
||||
</script>
|
||||
|
|
|
@ -8,7 +8,7 @@ angular.module('copay.backup').controller('BackupController',
|
|||
|
||||
// TODO: get the real encrypted wallet.
|
||||
var _getEncryptedWallet = function() {
|
||||
var wallet = JSON.stringify($rootScope.wallet.toObj());
|
||||
var wallet = $rootScope.wallet.toEncryptedObj();
|
||||
return wallet;
|
||||
};
|
||||
|
||||
|
@ -40,11 +40,10 @@ angular.module('copay.backup').controller('BackupController',
|
|||
} else {
|
||||
if (email && email !== '') {
|
||||
var body = _getEncryptedWallet();
|
||||
console.log(body);
|
||||
var subject = 'Copay Backup';
|
||||
var href = 'mailto:' + email + '?'
|
||||
+ 'subject=' + subject + '&'
|
||||
+ 'body=' + 'body'; // TODO: Uncomment this when get the real encrypted wallet.
|
||||
+ 'body=' + body;
|
||||
|
||||
var newWin = $window.open(href, '_blank', 'scrollbars=yes,resizable=yes,width=10,height=10');
|
||||
|
||||
|
|
|
@ -1,22 +1,33 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copay.import').controller('ImportController',
|
||||
function($scope, $rootScope, walletFactory, controllerUtils) {
|
||||
function($scope, $rootScope, walletFactory, controllerUtils, Passphrase) {
|
||||
$scope.title = 'Import a backup';
|
||||
|
||||
$scope.getFile = function() {
|
||||
var reader = new FileReader();
|
||||
var _importBackup = function(encryptedObj) {
|
||||
var passphrase = Passphrase.getBase64($scope.password);
|
||||
$rootScope.wallet = walletFactory.fromEncryptedObj(encryptedObj, passphrase);
|
||||
controllerUtils.startNetwork($rootScope.wallet);
|
||||
};
|
||||
|
||||
$scope.getFile = function() {
|
||||
// If we use onloadend, we need to check the readyState.
|
||||
reader.onloadend = function(evt) {
|
||||
if (evt.target.readyState == FileReader.DONE) { // DONE == 2
|
||||
var obj = JSON.parse(evt.target.result);
|
||||
$rootScope.wallet = walletFactory.fromObj(obj);
|
||||
|
||||
controllerUtils.startNetwork($rootScope.wallet);
|
||||
var encryptedObj = evt.target.result;
|
||||
_importBackup(encryptedObj);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
$scope.import = function() {
|
||||
if ($scope.password) {
|
||||
if ($scope.backupText) {
|
||||
_importBackup($scope.backupText);
|
||||
} else {
|
||||
reader.readAsBinaryString($scope.file);
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
|
|
@ -268,6 +268,11 @@ Wallet.fromObj = function(o, storage, network, blockchain) {
|
|||
return w;
|
||||
};
|
||||
|
||||
Wallet.prototype.toEncryptedObj = function() {
|
||||
var walletObj = this.toObj();
|
||||
return this.storage.export(walletObj);
|
||||
};
|
||||
|
||||
Wallet.prototype.sendTxProposals = function(recipients) {
|
||||
this.log('### SENDING txProposals TO:', recipients || 'All', this.txProposals);
|
||||
|
||||
|
|
|
@ -68,6 +68,12 @@ WalletFactory.prototype.fromObj = function(obj) {
|
|||
return w;
|
||||
};
|
||||
|
||||
WalletFactory.prototype.fromEncryptedObj = function(base64, password) {
|
||||
this.storage._setPassphrase(password);
|
||||
var walletObj = this.storage.import(base64);
|
||||
return this.fromObj(walletObj);
|
||||
};
|
||||
|
||||
WalletFactory.prototype.read = function(walletId) {
|
||||
if (! this._checkRead(walletId))
|
||||
return false;
|
||||
|
|
|
@ -157,4 +157,14 @@ Storage.prototype.clearAll = function() {
|
|||
localStorage.clear();
|
||||
};
|
||||
|
||||
Storage.prototype.export = function(obj) {
|
||||
var encryptedObj = this._encryptObj(obj);
|
||||
return encryptedObj;
|
||||
};
|
||||
|
||||
Storage.prototype.import = function(base64) {
|
||||
var decryptedObj = this._decryptObj(base64);
|
||||
return decryptedObj;
|
||||
};
|
||||
|
||||
module.exports = require('soop')(Storage);
|
||||
|
|
Loading…
Reference in New Issue