fix spending passwor in export

This commit is contained in:
Matias Alejo Garcia 2016-08-29 16:13:18 -03:00
commit f534b0bc2d
No known key found for this signature in database
GPG key ID: 02470DB551277AB3
3 changed files with 27 additions and 46 deletions

View file

@ -8,7 +8,7 @@ angular.module('copayApp.controllers').controller('backupController',
$scope.walletName = wallet.credentials.walletName; $scope.walletName = wallet.credentials.walletName;
$scope.n = wallet.n; $scope.n = wallet.n;
$scope.credentialsEncrypted = wallet.isPrivKeyEncrypted; $scope.credentialsEncrypted = wallet.isPrivKeyEncrypted();
var isDeletedSeed = function() { var isDeletedSeed = function() {
if (lodash.isEmpty(wallet.credentials.mnemonic) && lodash.isEmpty(wallet.credentials.mnemonicEncrypted)) if (lodash.isEmpty(wallet.credentials.mnemonic) && lodash.isEmpty(wallet.credentials.mnemonicEncrypted))
@ -20,13 +20,13 @@ angular.module('copayApp.controllers').controller('backupController',
$scope.deleted = isDeletedSeed(); $scope.deleted = isDeletedSeed();
if ($scope.deleted) return; if ($scope.deleted) return;
walletService.getKey(wallet, function(err, mnemonics, xpriv) { walletService.getKeys(wallet, function(err, keys) {
if (err) { if (err) {
$state.go('preferences'); $state.go('preferences');
return; return;
} }
$scope.credentialsEncrypted = false; $scope.credentialsEncrypted = false;
$scope.initFlow(mnemonics, xpriv); $scope.initFlow(keys);
}); });
}; };
@ -41,9 +41,9 @@ angular.module('copayApp.controllers').controller('backupController',
}); });
}; };
$scope.initFlow = function() { $scope.initFlow = function(keys) {
var words = wallet.getMnemonic(); var words = keys.mnemonic;
xPriv6 = wallet.credentials.xPrivKey.substr(wallet.credentials.xPrivKey.length - 6); xPriv6 = keys.xPrivKey.substr(wallet.credentials.xPrivKey.length - 6);
$scope.mnemonicWords = words.split(/[\u3000\s]+/); $scope.mnemonicWords = words.split(/[\u3000\s]+/);
$scope.shuffledMnemonicWords = shuffledWords($scope.mnemonicWords); $scope.shuffledMnemonicWords = shuffledWords($scope.mnemonicWords);
@ -128,7 +128,7 @@ angular.module('copayApp.controllers').controller('backupController',
} }
if (walletClient.credentials.xPrivKey.substr(walletClient.credentials.xPrivKey-6) != xPriv6) { if (walletClient.credentials.xPrivKey.substr(walletClient.credentials.xPrivKey-6) != xPriv6) {
walletClient.credentials.xPrivKey = lodash.repeat('x', 64); delete walletClient.credentials;
return cb('Private key mismatch'); return cb('Private key mismatch');
} }
} }
@ -141,7 +141,6 @@ angular.module('copayApp.controllers').controller('backupController',
var finalStep = function() { var finalStep = function() {
ongoingProcess.set('validatingWords', true); ongoingProcess.set('validatingWords', true);
confirm(function(err) { confirm(function(err) {
xPriv6 = lodash.repeat('x', 6);
ongoingProcess.set('validatingWords', false); ongoingProcess.set('validatingWords', false);
if (err) { if (err) {
backupError(err); backupError(err);
@ -192,9 +191,4 @@ angular.module('copayApp.controllers').controller('backupController',
$scope.selectComplete = false; $scope.selectComplete = false;
}; };
$scope.$on('$destroy', function() {
walletService.lock(wallet);
});
}); });

View file

@ -1,7 +1,7 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('exportController', angular.module('copayApp.controllers').controller('exportController',
function($rootScope, $scope, $timeout, $log, lodash, backupService, walletService, storageService, profileService, platformInfo, notification, gettext, gettextCatalog, $state, $stateParams) { function($rootScope, $scope, $timeout, $log, lodash, backupService, walletService, storageService, profileService, platformInfo, gettext, gettextCatalog, $state, $stateParams) {
var prevState; var prevState;
var isWP = platformInfo.isWP; var isWP = platformInfo.isWP;
var isAndroid = platformInfo.isAndroid; var isAndroid = platformInfo.isAndroid;
@ -21,7 +21,7 @@ angular.module('copayApp.controllers').controller('exportController',
$scope.canSign = wallet.canSign(); $scope.canSign = wallet.canSign();
walletService.getEncodedWalletInfo(wallet, function(err, code) { walletService.getEncodedWalletInfo(wallet, function(err, code) {
if (err) { if (err || !code) {
$log.warn(err); $log.warn(err);
return $state.go('wallet.preferencesAdvanced') return $state.go('wallet.preferencesAdvanced')
} }
@ -48,10 +48,6 @@ angular.module('copayApp.controllers').controller('exportController',
}; };
*/ */
$scope.$on('$destroy', function() {
walletService.lock(wallet);
});
$scope.downloadWalletBackup = function() { $scope.downloadWalletBackup = function() {
$scope.getAddressbook(function(err, localAddressBook) { $scope.getAddressbook(function(err, localAddressBook) {
if (err) { if (err) {
@ -68,7 +64,6 @@ angular.module('copayApp.controllers').controller('exportController',
$scope.error = true; $scope.error = true;
return; return;
} }
notification.success(gettext('Success'), gettext('Encrypted export file saved'));
$state.go('tabs.home'); $state.go('tabs.home');
}); });
}); });

View file

@ -1028,42 +1028,34 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
root.getEncodedWalletInfo = function(wallet, cb) { root.getEncodedWalletInfo = function(wallet, cb) {
var getCode = function() { var derivationPath = wallet.credentials.getBaseAddressDerivationPath();
var derivationPath = wallet.credentials.getBaseAddressDerivationPath(); var encodingType = {
var encodingType = { mnemonic: 1,
mnemonic: 1, xpriv: 2,
xpriv: 2, xpub: 3
xpub: 3 };
}; var info;
var info;
// not supported yet // not supported yet
if (wallet.credentials.derivationStrategy != 'BIP44' || !wallet.canSign()) if (wallet.credentials.derivationStrategy != 'BIP44' || !wallet.canSign())
return null; return null;
if (wallet.credentials.mnemonic) { root.getKeys(wallet, function(err, keys){
if (err || !keys) return cb(err);
if (keys.mnemonic) {
info = { info = {
type: encodingType.mnemonic, type: encodingType.mnemonic,
data: wallet.credentials.mnemonic, data: keys.mnemonic,
} }
} else { } else {
info = { info = {
type: encodingType.xpriv, type: encodingType.xpriv,
data: wallet.credentials.xPrivKey data: keys.xPrivKey
} }
} }
return info.type + '|' + info.data + '|' + wallet.credentials.network.toLowerCase() + '|' + derivationPath + '|' + (wallet.credentials.mnemonicHasPassphrase); return cb(null, info.type + '|' + info.data + '|' + wallet.credentials.network.toLowerCase() + '|' + derivationPath + '|' + (wallet.credentials.mnemonicHasPassphrase));
};
fingerprintService.check(wallet, function(err) {
if (err) return cb(err);
root.handleEncryptedWallet(wallet, function(err) {
if (err) return cb(err);
var code = getCode();
return cb(null, code);
});
}); });
}; };
@ -1135,7 +1127,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
}); });
}; };
root.getKey = function(wallet, cb) { root.getKeys = function(wallet, cb) {
root.prepare(wallet, function(err, password) { root.prepare(wallet, function(err, password) {
if (err) return cb(err); if (err) return cb(err);
var keys; var keys;