From 85f14397044dda056526f3025d9ee4dd2705e540 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Fri, 25 Sep 2015 17:24:15 -0300 Subject: [PATCH] fix mnemonics with priv key is encrypted --- public/views/backup.html | 12 ++++++++-- src/js/controllers/backup.js | 44 +++++++++++++++++++++++++++++------- src/js/services/bwsError.js | 2 ++ 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/public/views/backup.html b/public/views/backup.html index 1abfba1a3..9ff0eaf4a 100644 --- a/public/views/backup.html +++ b/public/views/backup.html @@ -5,9 +5,17 @@ -
+ +
+ + {{wordsC.error|translate}} + +
+ + +
@@ -46,7 +54,7 @@
-
+
Wallet seed not available. You can still export it from Advanced > Export.
diff --git a/src/js/controllers/backup.js b/src/js/controllers/backup.js index ac262d0d6..f99f1a946 100644 --- a/src/js/controllers/backup.js +++ b/src/js/controllers/backup.js @@ -1,13 +1,14 @@ 'use strict'; angular.module('copayApp.controllers').controller('wordsController', - function($rootScope, $scope, $timeout, profileService, go, gettext, confirmDialog, notification) { + function($rootScope, $scope, $timeout, profileService, go, gettext, confirmDialog, notification, bwsError, $log) { var msg = gettext('Are you sure you want to delete the backup words?'); var successMsg = gettext('Backup words deleted'); - this.show = false; + var self = this; + this.toggle = function() { this.show = !this.show; @@ -32,13 +33,40 @@ angular.module('copayApp.controllers').controller('wordsController', }); }; + + $scope.$on('$destroy', function() { + profileService.lockFC(); + }); + + + function setWords(words) { + if (words) { + self.mnemonicWords = words.split(/[\u3000\s]+/); + self.mnemonicHasPassphrase = fc.mnemonicHasPassphrase(); + self.useIdeograms = words.indexOf("\u3000") >= 0; + } + }; + var fc = profileService.focusedClient; - var words = fc.getMnemonic(); + try { + setWords(fc.getMnemonic()); + } catch (e) { + if (e.message && e.message.match(/encrypted/) && fc.isPrivKeyEncrypted()) { + self.credentialsEncrypted = true; - if (words) { - this.mnemonicWords = words.split(/[\u3000\s]+/); - this.mnemonicHasPassphrase = fc.mnemonicHasPassphrase(); - this.useIdeograms = words.indexOf("\u3000") >= 0; + $timeout(function(){ + $scope.$apply(); + }, 1); + + profileService.unlockFC(function(err) { + if (err) { + self.error = bwsError.msg(err, gettext('Could not decrypt')); + $log.warn('Error decrypting credentials:',self.error); //TODO + return; + } + self.credentialsEncrypted = false; + setWords(fc.getMnemonic()); + }); + } } - }); diff --git a/src/js/services/bwsError.js b/src/js/services/bwsError.js index 6e59a8ffc..a4fde659d 100644 --- a/src/js/services/bwsError.js +++ b/src/js/services/bwsError.js @@ -103,6 +103,8 @@ angular.module('copayApp.services') body = err.message || err.code; break; } + } else if (err.message) { + body = gettextCatalog.getString(err.message); } else { body = gettextCatalog.getString(err); }