support xPrivKey seeds

This commit is contained in:
Matias Alejo Garcia 2015-09-05 00:11:14 -03:00
parent b712874c17
commit f1f4e5cfaf
6 changed files with 81 additions and 26 deletions

View File

@ -47,8 +47,8 @@
</div>
<div class="row m20t" ng-show="!wordsC.mnemonicWords">
<div class="columns size-14 text-gray" translate>
The wallet seed not available on this device. You can still export the wallet to backup it.
<div class="columns size-14 text-gray text-center" translate>
Wallet seed not available. You can still export it from Advanced &gt; Export .
</div>
</div>

View File

@ -6,7 +6,7 @@ angular.module('copayApp.controllers').controller('createController',
var self = this;
var defaults = configService.getDefaults();
this.isWindowsPhoneApp = isMobile.Windows() && isCordova;
/* For compressed keys, m*73 + n*34 <= 496 */
var COPAYER_PAIR_LIMITS = {
1: 1,
@ -35,7 +35,7 @@ angular.module('copayApp.controllers').controller('createController',
$scope.requiredCopayers = Math.min(parseInt(n / 2 + 1), maxReq);
};
this.externalIndexValues = lodash.range(0,ledger.MAX_SLOT);
this.externalIndexValues = lodash.range(0, ledger.MAX_SLOT);
$scope.externalIndex = 0;
this.TCValues = lodash.range(2, defaults.limits.totalCopayers + 1);
$scope.totalCopayers = defaults.wallet.totalCopayers;
@ -61,18 +61,23 @@ angular.module('copayApp.controllers').controller('createController',
networkName: form.isTestnet.$modelValue ? 'testnet' : 'livenet',
};
var setSeed = form.setSeed.$modelValue;
if (setSeed) {
opts.mnemonic = form.privateKey.$modelValue;
if (setSeed) {
var words = form.privateKey.$modelValue;
if (words.indexOf(' ') == -1 && words.indexOf('prv') == 1 && words.length > 108) {
opts.extendedPrivateKey = words;
} else {
opts.mnemonic = words;
}
opts.passphrase = form.passphrase.$modelValue;
} else {
opts.passphrase = form.createPassphrase.$modelValue;
}
if (setSeed && !opts.mnemonic) {
if (setSeed && !opts.mnemonic && !opts.extendedPrivateKey) {
this.error = gettext('Please enter the wallet seed');
return;
}
if (form.hwLedger.$modelValue) {
self.ledger = true;
ledger.getInfoForNewWallet($scope.externalIndex, function(err, lopts) {
@ -90,7 +95,7 @@ angular.module('copayApp.controllers').controller('createController',
}
};
this._create = function (opts) {
this._create = function(opts) {
self.loading = true;
$timeout(function() {
profileService.createWallet(opts, function(err, secret, walletId) {
@ -104,9 +109,8 @@ angular.module('copayApp.controllers').controller('createController',
$timeout(function() {
$rootScope.$apply();
});
}
else {
if ( ( opts.mnemonic && opts.n==1) || opts.externalSource ) {
} else {
if (opts.n == 1 && (opts.mnemonic || opts.externalSource || opts.extendedPrivateKey)) {
$rootScope.$emit('Local/WalletImported', walletId);
} else {
go.walletHome();
@ -115,18 +119,16 @@ angular.module('copayApp.controllers').controller('createController',
});
}, 100);
}
this.formFocus = function(what) {
if (!this.isWindowsPhoneApp) return
if (what && what == 'my-name') {
this.hideWalletName = true;
this.hideTabs = true;
}
else if (what && what == 'wallet-name'){
} else if (what && what == 'wallet-name') {
this.hideTabs = true;
}
else {
} else {
this.hideWalletName = false;
this.hideTabs = false;
}

View File

@ -63,11 +63,32 @@ angular.module('copayApp.controllers').controller('importController',
};
var _importExtendedPrivateKey = function(xPrivKey) {
self.loading = true;
$timeout(function() {
profileService.importExtendedPrivateKey(xPrivKey, function(err, walletId) {
self.loading = false;
if (err) {
self.error = err;
return $timeout(function() {
$scope.$apply();
});
}
$rootScope.$emit('Local/WalletImported', walletId);
notification.success(gettext('Success'), gettext('Your wallet has been imported correctly'));
go.walletHome();
});
}, 100);
};
var _importMnemonic = function(words, opts) {
self.loading = true;
$timeout(function() {
profileService.importWalletMnemonic(words, opts, function(err, walletId) {
profileService.importMnemonic(words, opts, function(err, walletId) {
self.loading = false;
if (err) {
self.error = err;
@ -140,7 +161,11 @@ angular.module('copayApp.controllers').controller('importController',
if (!words) {
this.error = gettext('Please enter the seed words');
} else if (words.indexOf(' ') == -1 && words.indexOf('prv') == 1 && words.length > 108) {
return _importExtendedPrivateKey(words)
} else {
console.log('[import.js.167]', words.indexOf(' '), words.indexOf('prv')); //TODO
var wordList = words.split(/ /).filter(function(v) {
return v.length > 0;
});

View File

@ -660,7 +660,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
skip = skip || 0;
fc.getTxHistory({
skip: skip,
limit: step,
limit: step,
}, function(err, txs) {
if (err) return cb(err);
if (txs && txs.length > 0) {
@ -737,7 +737,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
});
};
self.showErrorPopup = function (msg, cb) {
self.showErrorPopup = function(msg, cb) {
$log.warn('Showing err popup:' + msg);
self.showAlert = {
msg: msg,
@ -1015,7 +1015,9 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.needsBackup = false;
storageService.setBackupFlag(walletId, function() {
addressService.expireAddress(walletId, function(err) {
self.startScan(walletId);
$timeout(function() {
self.startScan(walletId);
}, 500);
});
});
});
@ -1108,7 +1110,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
});
$rootScope.$on('Local/ShowAlert', function(event, msg, cb) {
self.showErrorPopup(msg,cb);
self.showErrorPopup(msg, cb);
});
$rootScope.$on('Local/NeedsPassword', function(event, isSetup, cb) {

View File

@ -158,13 +158,18 @@ angular.module('copayApp.controllers').controller('joinController',
var setSeed = form.setSeed.$modelValue;
if (setSeed) {
opts.mnemonic = form.privateKey.$modelValue;
var words = form.privateKey.$modelValue;
if (words.indexOf(' ') == -1 && words.indexOf('prv') == 1 && words.length > 108) {
opts.extendedPrivateKey = words;
} else {
opts.mnemonic = words;
}
opts.passphrase = form.passphrase.$modelValue;
} else {
opts.passphrase = form.createPassphrase.$modelValue;
}
if (setSeed && !opts.mnemonic) {
if (setSeed && !opts.mnemonic && !opts.extendedPrivateKey) {
this.error = gettext('Please enter the wallet seed');
return;
}
@ -197,7 +202,7 @@ angular.module('copayApp.controllers').controller('joinController',
}
$timeout(function() {
var fc = profileService.focusedClient;
if ( ( opts.mnemonic || opts.externalSource ) && fc.isComplete()) {
if ( fc.isComplete() && (opts.mnemonic || opts.externalSource || opts.extendedPrivateKey)) {
$rootScope.$emit('Local/WalletImported', fc.credentials.walletId);
} else {
go.walletHome();

View File

@ -177,6 +177,13 @@ angular.module('copayApp.services')
$log.info(ex);
return cb(gettext('Could not create: Invalid wallet seed'));
}
} else if (opts.extendedPrivateKey) {
try {
walletClient.seedFromExtendedPrivateKey(opts.extendedPrivateKey);
} catch (ex) {
$log.warn(ex);
return cb(gettext('Could not create using the specified extended private key'));
}
} else if (opts.extendedPublicKey) {
try {
walletClient.seedFromExtendedPublicKey(opts.extendedPublicKey, opts.externalSource, opts.externalIndex, opts.entropySource);
@ -344,7 +351,21 @@ angular.module('copayApp.services')
root._addWalletClient(walletClient, cb);
};
root.importWalletMnemonic = function(words, opts, cb) {
root.importExtendedPrivateKey = function(xPrivKey, cb) {
var walletClient = bwcService.getClient();
$log.debug('Importing Wallet xPrivKey');
walletClient.importFromExtendedPrivateKey(xPrivKey, function(err) {
if (err)
return bwsError.cb(err, gettext('Could not import'), cb);
root._addWalletClient(walletClient, cb);
});
};
root.importMnemonic = function(words, opts, cb) {
var walletClient = bwcService.getClient();
$log.debug('Importing Wallet Mnemonic');