mirror of https://github.com/BTCPrivate/copay.git
add normalization of seeds, better JA support
This commit is contained in:
parent
bef39b4b8d
commit
4f39315a46
|
@ -75,9 +75,7 @@
|
||||||
<div class="row enable_text_select" ng-show="show">
|
<div class="row enable_text_select" ng-show="show">
|
||||||
<div class="small-centered p10t p10b large-centered medium-centered large-8 medium-8 small-10 columns enable_text_select" style="border:1px solid gray; background:#eee;
|
<div class="small-centered p10t p10b large-centered medium-centered large-8 medium-8 small-10 columns enable_text_select" style="border:1px solid gray; background:#eee;
|
||||||
">
|
">
|
||||||
<span ng-repeat="word in wordsC.mnemonicWords">
|
<span ng-repeat="word in wordsC.mnemonicWords"><span style="white-space:nowrap">{{word}}</span><span ng-show="index.defaultLanguageIsoCode == 'ja'"> </span> </span>
|
||||||
{{word}}
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="box-notification large-centered medium-centered small-centered large-8 medium-8 small-10 columns m10t" ng-show="wordsC.mnemonicHasPassphrase">
|
<div class="box-notification large-centered medium-centered small-centered large-8 medium-8 small-10 columns m10t" ng-show="wordsC.mnemonicHasPassphrase">
|
||||||
|
@ -89,10 +87,6 @@
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="m10 text-center columns">
|
<div class="m10 text-center columns">
|
||||||
<div class="m10 size-14 text-gray">
|
<div class="m10 size-14 text-gray">
|
||||||
<span translate>
|
<span translate>
|
||||||
|
|
|
@ -55,12 +55,6 @@
|
||||||
<span translate>Backup</span>
|
<span translate>Backup</span>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<h4 class="title m0"> </h4>
|
|
||||||
<li class="line-b p20" ng-click="$root.go('export')" ng-hide="preferences.externalIndex >= 0">
|
|
||||||
<i class="icon-arrow-right3 size-24 right text-gray"></i>
|
|
||||||
<span translate>Export</span>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<li class="line-b p20" ng-click="$root.go('preferencesAdvanced')">
|
<li class="line-b p20" ng-click="$root.go('preferencesAdvanced')">
|
||||||
<i class="icon-arrow-right3 size-24 right text-gray"></i>
|
<i class="icon-arrow-right3 size-24 right text-gray"></i>
|
||||||
<span translate>Advanced</span>
|
<span translate>Advanced</span>
|
||||||
|
|
|
@ -27,7 +27,7 @@ angular.module('copayApp.controllers').controller('wordsController',
|
||||||
var words = fc.getMnemonic();
|
var words = fc.getMnemonic();
|
||||||
|
|
||||||
if (words)
|
if (words)
|
||||||
this.mnemonicWords = words.split(' ');
|
this.mnemonicWords = words.split(/[\u3000\s]+/);
|
||||||
|
|
||||||
this.mnemonicHasPassphrase = fc.mnemonicHasPassphrase();
|
this.mnemonicHasPassphrase = fc.mnemonicHasPassphrase();
|
||||||
});
|
});
|
||||||
|
|
|
@ -159,18 +159,14 @@ angular.module('copayApp.controllers').controller('importController',
|
||||||
|
|
||||||
if (!words) {
|
if (!words) {
|
||||||
this.error = gettext('Please enter the seed words');
|
this.error = gettext('Please enter the seed words');
|
||||||
} else if (words.indexOf(' ') == -1 && words.indexOf('prv') == 1 && words.length > 108) {
|
} else if (words.indexOf('xprv') == 0 || words.indexOf('tprv') == 0) {
|
||||||
return _importExtendedPrivateKey(words)
|
return _importExtendedPrivateKey(words)
|
||||||
} else {
|
} else {
|
||||||
var wordList = words.split(/ /).filter(function(v) {
|
var wordList = words.split(/[\u3000\s]+/);
|
||||||
return v.length > 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
// m/ allows to enter a custom derivation
|
// m/ allows to enter a custom derivation
|
||||||
if ((wordList.length % 3) != 0 && wordList[0].indexOf('m/') != 0)
|
if ((wordList.length % 3) != 0 && wordList[0].indexOf('m/') != 0)
|
||||||
this.error = gettext('Wrong number of seed words:') + wordList.length;
|
this.error = gettext('Wrong number of seed words:') + wordList.length;
|
||||||
else
|
|
||||||
words = wordList.join(' ');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.error) {
|
if (this.error) {
|
||||||
|
|
|
@ -170,15 +170,9 @@ angular.module('copayApp.services')
|
||||||
var walletClient = bwcService.getClient();
|
var walletClient = bwcService.getClient();
|
||||||
var network = opts.networkName || 'livenet';
|
var network = opts.networkName || 'livenet';
|
||||||
|
|
||||||
if (opts.mnemonic && opts.mnemonic.indexOf('m/') == 0) {
|
|
||||||
var xPrivKey = root._preDerivation(opts.mnemonic, network);
|
|
||||||
if (!xPrivKey)
|
|
||||||
return bwsError.cb('Bad derivation', gettext('Could not import'), cb);
|
|
||||||
opts.mnemonic = null;
|
|
||||||
opts.extendedPrivateKey = xPrivKey;
|
|
||||||
}
|
|
||||||
if (opts.mnemonic) {
|
if (opts.mnemonic) {
|
||||||
try {
|
try {
|
||||||
|
opts.mnemonic = root._normalizeMnemonic(opts.mnemonic);
|
||||||
walletClient.seedFromMnemonic(opts.mnemonic, opts.passphrase, network);
|
walletClient.seedFromMnemonic(opts.mnemonic, opts.passphrase, network);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
$log.info(ex);
|
$log.info(ex);
|
||||||
|
@ -327,10 +321,11 @@ angular.module('copayApp.services')
|
||||||
var walletId = walletClient.credentials.walletId;
|
var walletId = walletClient.credentials.walletId;
|
||||||
|
|
||||||
// check if exist
|
// check if exist
|
||||||
if (lodash.find(root.profile.credentials, {
|
var w = lodash.find(root.profile.credentials, {
|
||||||
'walletId': walletId
|
'walletId': walletId
|
||||||
})) {
|
});
|
||||||
return cb(gettext('Wallet already exists'));
|
if (w) {
|
||||||
|
return cb(gettext('Wallet already in Copay' + ": ") + w.walletName );
|
||||||
}
|
}
|
||||||
|
|
||||||
root.profile.credentials.push(JSON.parse(walletClient.export()));
|
root.profile.credentials.push(JSON.parse(walletClient.export()));
|
||||||
|
@ -371,31 +366,19 @@ angular.module('copayApp.services')
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
root._preDerivation = function(words, network) {
|
root._normalizeMnemonic = function(words) {
|
||||||
var wordList = words.split(/ /).filter(function(v) {
|
var isJA = words.indexOf('\u3000') > -1;
|
||||||
return v.length > 0;
|
var wordList = words.split(/[\u3000\s]+/);
|
||||||
});
|
|
||||||
var path = wordList.shift();
|
return wordList.join(isJA ? '\u3000' : ' ');
|
||||||
var walletClient = bwcService.getClient();
|
|
||||||
$log.info('preDerivation:', path);
|
|
||||||
walletClient.seedFromMnemonic(wordList.join(' '), null, network);
|
|
||||||
var k = new bitcore.HDPrivateKey(walletClient.credentials.xPrivKey);
|
|
||||||
var k2 = k.derive(path);
|
|
||||||
return k2.toString();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
root.importMnemonic = function(words, opts, cb) {
|
root.importMnemonic = function(words, opts, cb) {
|
||||||
var walletClient = bwcService.getClient();
|
var walletClient = bwcService.getClient();
|
||||||
|
|
||||||
if (words.indexOf('m/') == 0) {
|
|
||||||
var xPrivKey = root._preDerivation(words, opts.networkName);
|
|
||||||
if (!xPrivKey)
|
|
||||||
return bwsError.cb('Bad derivation', gettext('Could not import'), cb);
|
|
||||||
return root.importExtendedPrivateKey(xPrivKey, cb);
|
|
||||||
}
|
|
||||||
|
|
||||||
$log.debug('Importing Wallet Mnemonic');
|
$log.debug('Importing Wallet Mnemonic');
|
||||||
|
|
||||||
|
words = root._normalizeMnemonic(words);
|
||||||
walletClient.importFromMnemonic(words, {
|
walletClient.importFromMnemonic(words, {
|
||||||
network: opts.networkName,
|
network: opts.networkName,
|
||||||
passphrase: opts.passphrase,
|
passphrase: opts.passphrase,
|
||||||
|
|
Loading…
Reference in New Issue