backup and export working with mnemonics

This commit is contained in:
Matias Alejo Garcia 2015-08-08 09:30:50 -03:00
parent 300881a180
commit 4c155b7895
9 changed files with 271 additions and 172 deletions

View File

@ -6,101 +6,48 @@
<div class="content p20v" ng-controller="backupController as backup">
<div class="content p20v" ng-controller="wordsController as wordsC">
<div class="row">
<div class="columns" ng-show="!backup.backupWalletPlainText">
<div class="text-warning size-14 m20b" ng-show="backup.error">
<i class="fi-alert size-12"></i>
<span translate> Failed to create backup </span>
</div>
<div class="text-warning size-14 m20b" ng-show="backup.isEncrypted">
<i class="fi-alert size-12"></i>
<span translate> The private key for this wallet is encrypted. Exporting a backup will keep the private key encrypted in the backup archive.</span>
</div>
<label for="password" translate>Set up a Password for your backup</label>
<div class="input">
<input type="password" class="form-control"
placeholder="{{'Your backup password'|translate}}"
name="password" ng-model="backup.password">
</div>
<label for="password" translate>Repeat password</label>
<div class="input">
<input type="password" class="form-control"
placeholder="{{'Repeat password'|translate}}"
name="password" ng-model="backup.repeatpassword">
</div>
<div class="m10t oh" ng-init="hideAdv=true">
<a class="button outline light-gray expand tiny" ng-click="hideAdv=!hideAdv">
<div class="m10 size-14 text-gray" translate>
<span translate>
In order to restore your Copay wallet you will need these 12 backup words.
</span>
<span translate class="text-bold">
Write them down and keep them somethere safe
</span>
</div>
</div>
<div class="row">
<div class="m10t oh" ng-init="show=false">
<a class="button outline light-gray expand tiny" ng-click="show=!show">
<i class="fi-widget m3r"></i>
<span translate ng-hide="!hideAdv">Show advanced options</span>
<span translate ng-hide="hideAdv">Hide advanced options</span>
<i ng-if="hideAdv" class="icon-arrow-down4"></i>
<i ng-if="!hideAdv" class="icon-arrow-up4"></i>
<span translate ng-hide="show">Show Backup Words</span>
<span translate ng-hide="!show">Hide Backup Words</span>
<i ng-if="!show" class="icon-arrow-down4"></i>
<i ng-if="show" class="icon-arrow-up4"></i>
</a>
</div>
<div ng-hide="hideAdv" class="row">
<div class="large-12 columns">
<label for="no-sign" class="line-b oh">
<span translate>Do not include private key in backup</span>
<switch id="no-sign" name="noSign" ng-model="noSign" class="green right m5t m10b"></switch>
</label>
</div>
</div>
<div class="row" ng-show="show" ng-init="words = wordsC.getMnemonic()">
<span class="m10" ng-repeat="word in words">
{{word}}
</span>
<div class="m10 text-center">
<div class="m10 size-14 text-gray" translate>
A backup without its private key will allow the user to see the wallet balance, transactions, and create spend proposals. However, it will not be able to approve (sign) proposals.
<span translate>
Once you have wrote your backup words, it is recommended to delete them from Copay.
</span>
</div>
<button class="button outline round dark-gray tiny" translate>DELETE WORDS</button>
</div>
<button class="black round expand m0" ng-click="backup.downloadWalletBackup()"
ng-disabled="(!backup.password || backup.password != backup.repeatpassword)"
ng-style="{'background-color':index.backgroundColor}"
ng-show="!backup.isSafari && !backup.isCordova"><i class="fi-download"></i>
<span translate>Download backup</span></button>
<button class="black round expand m0" ng-click="backup.viewWalletBackup()"
ng-disabled="(!backup.password || backup.password != backup.repeatpassword)"
ng-style="{'background-color':index.backgroundColor}"
ng-show="backup.isSafari && !backup.isCordova"><i class="fi-eye"></i>
<span translate>View backup</span></button>
<div ng-show="backup.isCordova">
<h4 translate>Backup options</h4>
<button class="black round expand" ng-disabled="(!backup.password || backup.password != backup.repeatpassword)"
ng-style="{'background-color':index.backgroundColor}"
ng-click="backup.copyWalletBackup()"><i class="fi-clipboard-pencil"></i>
<span translate>Copy to clipboard</span></button>
<button class="black round expand m0" ng-disabled="(!backup.password || backup.password != backup.repeatpassword)"
ng-style="{'background-color':index.backgroundColor}"
ng-click="backup.sendWalletBackup()"><i class="fi-mail"></i>
<span translate>Send by email</span></button>
</div>
</div>
</div>
<div class="row" ng-show="backup.backupWalletPlainText">
<div class="large-12 columns">
<h3 translate>Copy backup to a safe place</h3>
<div class="input">
<textarea rows="12">{{backup.backupWalletPlainText}}</textarea>
</div>
<div class="size-12 text-gray text-right">
<i class="icon-compose"></i>
<span translate>Copy this text as it is to a safe place (notepad or email)</span>
</div>
</div>
<div class="row text-center m20t" >
<button class="button outline round dark-gray tiny" ng-click="$root.openExternalLink('https://github.com/bitpay/copay#backups')">
<span class="text-gray" translate>Learn more about Copay backups</span>
</button>
</div>
<div class="row m10t">
<div class="columns size-14 text-gray" translate>
* You can safely install your backup on another device and use your wallet from multiple devices at the same time.
</div>
</div>
</div>
<div class="extra-margin-bottom"></div>

106
public/views/export.html Normal file
View File

@ -0,0 +1,106 @@
<div
class="topbar-container"
ng-include="'views/includes/topbar.html'"
ng-init="titleSection='Export'; goBackToState = 'preferences'">
</div>
<div class="content p20v" ng-controller="backupController as backup">
<div class="row">
<div class="columns" ng-show="!backup.backupWalletPlainText">
<div class="text-warning size-14 m20b" ng-show="backup.error">
<i class="fi-alert size-12"></i>
<span translate> Failed to export </span>
</div>
<div class="text-warning size-14 m20b" ng-show="backup.isEncrypted">
<i class="fi-alert size-12"></i>
<span translate> The private key for this wallet is encrypted. Exporting keep the private key encrypted in the export archive.</span>
</div>
<label for="password" translate>Set up a Export Password </label>
<div class="input">
<input type="password" class="form-control"
placeholder="{{'Your export password'|translate}}"
name="password" ng-model="backup.password">
</div>
<label for="password" translate>Repeat password</label>
<div class="input">
<input type="password" class="form-control"
placeholder="{{'Repeat password'|translate}}"
name="password" ng-model="backup.repeatpassword">
</div>
<div class="m10t oh" ng-init="hideAdv=true">
<a class="button outline light-gray expand tiny" ng-click="hideAdv=!hideAdv">
<i class="fi-widget m3r"></i>
<span translate ng-hide="!hideAdv">Show Advanced options</span>
<span translate ng-hide="hideAdv">Hide Advanced options</span>
<i ng-if="hideAdv" class="icon-arrow-down4"></i>
<i ng-if="!hideAdv" class="icon-arrow-up4"></i>
</a>
</div>
<div ng-hide="hideAdv" class="row">
<div class="large-12 columns">
<label for="no-sign" class="line-b oh">
<span translate>Do not include private key</span>
<switch id="no-sign" name="noSign" ng-model="noSign" class="green right m5t m10b"></switch>
</label>
</div>
<div class="m10 size-14 text-gray" translate>
Not including the private key will allow the user to see the wallet balance, transactions, and create spend proposals. However, it will not be able to approve (sign) proposals.
</div>
</div>
<button class="black round expand m0" ng-click="backup.downloadWalletBackup()"
ng-disabled="(!backup.password || backup.password != backup.repeatpassword)"
ng-style="{'background-color':index.backgroundColor}"
ng-show="!backup.isSafari && !backup.isCordova"><i class="fi-download"></i>
<span translate>Download backup</span></button>
<button class="black round expand m0" ng-click="backup.viewWalletBackup()"
ng-disabled="(!backup.password || backup.password != backup.repeatpassword)"
ng-style="{'background-color':index.backgroundColor}"
ng-show="backup.isSafari && !backup.isCordova"><i class="fi-eye"></i>
<span translate>View backup</span></button>
<div ng-show="backup.isCordova">
<h4 translate>Backup options</h4>
<button class="black round expand" ng-disabled="(!backup.password || backup.password != backup.repeatpassword)"
ng-style="{'background-color':index.backgroundColor}"
ng-click="backup.copyWalletBackup()"><i class="fi-clipboard-pencil"></i>
<span translate>Copy to clipboard</span></button>
<button class="black round expand m0" ng-disabled="(!backup.password || backup.password != backup.repeatpassword)"
ng-style="{'background-color':index.backgroundColor}"
ng-click="backup.sendWalletBackup()"><i class="fi-mail"></i>
<span translate>Send by email</span></button>
</div>
</div>
</div>
<div class="row" ng-show="backup.backupWalletPlainText">
<div class="large-12 columns">
<h3 translate>Copy backup to a safe place</h3>
<div class="input">
<textarea rows="12">{{backup.backupWalletPlainText}}</textarea>
</div>
<div class="size-12 text-gray text-right">
<i class="icon-compose"></i>
<span translate>Copy this text as it is to a safe place (notepad or email)</span>
</div>
</div>
</div>
<div class="row m10t">
<div class="columns size-14 text-gray" translate>
* You can safely install your backup on another device and use your wallet from multiple devices at the same time.
</div>
</div>
</div>
<div class="extra-margin-bottom"></div>

View File

@ -37,7 +37,7 @@
<p class="text-warning size-12 columns m20t text-center" ng-show="index.askPassword.isSetup">
<i class="fi-alert"></i>
<span translate ng-show="!pass.error">Password cannot be recovered. Be sure to write it down</span>
<span translate ng-show="!pass.error"> Your wallet key will be encrypted. Password cannot be recovered. Be sure to write it down</span>
<span ng-show="pass.error">{{pass.error|translate}}</span>
</p>

View File

@ -36,8 +36,9 @@
<span ng-style="{'color':index.backgroundColor}">&block;</span>
</span>
</li>
<li class="line-b p20" ng-hide="preferences.externalIndex >= 0">
<span translate>Encrypt Private Key</span>
<li class="line-b p20" ng-hide="preferences.externalIndex >= 0">
<span translate>Request Password for Spending Funds</span>
<switch id="network-name" name="encrypt" ng-model="encrypt" class="green right"></switch>
</li>
<li class="line-b p20" ng-show="preferences.externalIndex >= 0">
@ -49,9 +50,9 @@
</li>
<h4 class="title m0">&nbsp;</h4>
<li class="line-b p20" ng-click="$root.go('backup')">
<li class="line-b p20" ng-click="$root.go('export')">
<i class="icon-arrow-right3 size-24 right text-gray"></i>
<span translate>Backup</span>
<span translate>Export</span>
</li>
<li class="line-b p20" ng-click="$root.go('preferencesAdvanced')">
<i class="icon-arrow-right3 size-24 right text-gray"></i>

View File

@ -16,7 +16,12 @@
<li class="line-b p20" ng-click="index.retryScan(); $root.go('walletHome'); ">
<span translate>Scan addresses for funds</span>
</li>
<li class="line-b p20" ng-click="$root.go('addaccess');">
<i class="icon-arrow-right3 size-24 right text-gray"></i>
<span translate>Add access (TODO)</span>
</li>
<li class="line-b p20" ng-click="$root.go('delete')">
<i class="icon-arrow-right3 size-24 right text-gray"></i>
<span translate>Delete Wallet</span>

View File

@ -1,86 +1,13 @@
'use strict';
angular.module('copayApp.controllers').controller('backupController',
function($rootScope, $scope, $timeout, backupService, profileService, isMobile, isCordova, notification, go, gettext, gettextCatalog) {
this.isSafari = isMobile.Safari();
this.isCordova = isCordova;
this.error = null;
this.success = null;
var fc = profileService.focusedClient;
this.isEncrypted = fc.isPrivKeyEncrypted();
this.downloadWalletBackup = function() {
var self = this;
var opts = {
noSign: $scope.noSign,
};
backupService.walletDownload(this.password, opts, function(err) {
if (err) {
self.error = true;
return ;
}
$rootScope.$emit('Local/BackupDone');
notification.success(gettext('Backup created'), gettext('Encrypted backup file saved'));
go.walletHome();
});
};
this.getBackup = function() {
var opts = {
noSign: $scope.noSign,
};
var ew = backupService.walletExport(this.password, opts);
if (!ew) {
this.error = true;
} else {
this.error = false;
}
return ew;
};
this.viewWalletBackup = function() {
var self = this;
$timeout(function() {
var ew = self.getBackup();
if (!ew) return;
self.backupWalletPlainText = ew;
$rootScope.$emit('Local/BackupDone');
}, 100);
};
this.copyWalletBackup = function() {
var ew = this.getBackup();
if (!ew) return;
window.cordova.plugins.clipboard.copy(ew);
window.plugins.toast.showShortCenter(gettextCatalog.getString('Copied to clipboard'));
$rootScope.$emit('Local/BackupDone');
};
this.sendWalletBackup = function() {
angular.module('copayApp.controllers').controller('wordsController',
function($rootScope, $scope, $timeout, profileService, go, gettext) {
this.getMnemonic = function() {
var fc = profileService.focusedClient;
if (isMobile.Android() || isMobile.Windows()) {
window.ignoreMobilePause = true;
}
window.plugins.toast.showShortCenter(gettextCatalog.getString('Preparing backup...'));
var name = (fc.credentials.walletName || fc.credentials.walletId);
if (fc.alias) {
name = fc.alias + ' [' + name + ']';
}
var ew = this.getBackup();
if (!ew) return;
var words = fc.getMnemonic();
console.log('[backup.js.7:words:]',words); //TODO
if (!words) return;
if( $scope.noSign)
name = name + '(No Private Key)';
var properties = {
subject: 'Copay Wallet Backup: ' + name,
body: 'Here is the encrypted backup of the wallet ' + name + ': \n\n' + ew + '\n\n To import this backup, copy all text between {...}, including the symbols {}',
isHtml: false
};
$rootScope.$emit('Local/BackupDone');
window.plugin.email.open(properties);
return words.split(' ');
};
});

View File

@ -0,0 +1,86 @@
'use strict';
angular.module('copayApp.controllers').controller('backupController',
function($rootScope, $scope, $timeout, backupService, profileService, isMobile, isCordova, notification, go, gettext, gettextCatalog) {
this.isSafari = isMobile.Safari();
this.isCordova = isCordova;
this.error = null;
this.success = null;
var fc = profileService.focusedClient;
this.isEncrypted = fc.isPrivKeyEncrypted();
this.downloadWalletBackup = function() {
var self = this;
var opts = {
noSign: $scope.noSign,
};
backupService.walletDownload(this.password, opts, function(err) {
if (err) {
self.error = true;
return ;
}
$rootScope.$emit('Local/BackupDone');
notification.success(gettext('Backup created'), gettext('Encrypted backup file saved'));
go.walletHome();
});
};
this.getBackup = function() {
var opts = {
noSign: $scope.noSign,
};
var ew = backupService.walletExport(this.password, opts);
if (!ew) {
this.error = true;
} else {
this.error = false;
}
return ew;
};
this.viewWalletBackup = function() {
var self = this;
$timeout(function() {
var ew = self.getBackup();
if (!ew) return;
self.backupWalletPlainText = ew;
$rootScope.$emit('Local/BackupDone');
}, 100);
};
this.copyWalletBackup = function() {
var ew = this.getBackup();
if (!ew) return;
window.cordova.plugins.clipboard.copy(ew);
window.plugins.toast.showShortCenter(gettextCatalog.getString('Copied to clipboard'));
$rootScope.$emit('Local/BackupDone');
};
this.sendWalletBackup = function() {
var fc = profileService.focusedClient;
if (isMobile.Android() || isMobile.Windows()) {
window.ignoreMobilePause = true;
}
window.plugins.toast.showShortCenter(gettextCatalog.getString('Preparing backup...'));
var name = (fc.credentials.walletName || fc.credentials.walletId);
if (fc.alias) {
name = fc.alias + ' [' + name + ']';
}
var ew = this.getBackup();
if (!ew) return;
if( $scope.noSign)
name = name + '(No Private Key)';
var properties = {
subject: 'Copay Wallet Backup: ' + name,
body: 'Here is the encrypted backup of the wallet ' + name + ': \n\n' + ew + '\n\n To import this backup, copy all text between {...}, including the symbols {}',
isHtml: false
};
$rootScope.$emit('Local/BackupDone');
window.plugin.email.open(properties);
};
});

View File

@ -453,6 +453,17 @@ angular
},
}
})
.state('export', {
url: '/export',
templateUrl: 'views/export.html',
walletShouldBeComplete: true,
needProfile: true,
views: {
'main': {
templateUrl: 'views/export.html'
},
}
})
.state('backup', {
url: '/backup',
templateUrl: 'views/backup.html',

View File

@ -172,6 +172,17 @@ angular.module('copayApp.services')
}
var walletClient = bwcService.getClient();
// TODO LANG...
// TODO...
walletClient.seedFromRandomWithMnemonic('livenet');
console.log('[profileService.js.200:walletClient:]',walletClient); //TODO
console.log('[profileService.js.180]'); //TODO
console.log('[profileService.js.180]'); //TODO
console.log('[profileService.js.180]'); //TODO
console.log('[profileService.js.180]'); //TODO
console.log('[profileService.js.180]'); //TODO
walletClient.createWallet('Personal Wallet', 'me', 1, 1, {
network: 'livenet'
}, function(err) {
@ -200,6 +211,11 @@ angular.module('copayApp.services')
return cb(gettext('Could not create using the specified extended public key'));
}
}
// TODO LANG...
// TODO...
walletClient.seedFromRandomWithMnemonic(opts.networkName);
console.log('[profileService.js.200:walletClient:]',walletClient); //TODO
walletClient.createWallet(opts.name, opts.myName || 'me', opts.m, opts.n, {
network: opts.networkName
}, function(err, secret) {