Allow choosing language for mnemonic seed

pull/22/head
sachaaaaa 7 years ago
parent bbabeb34b8
commit 7b1fbe362e

@ -574,6 +574,8 @@
<input class='form-control' type='text' id='mnemonic' placeholder='Mnemonic' autocomplete='off' spellcheck='false'>
<select id='mnemonic-language'></select>
<div class='clearfix'>
<a class='button' id='register-mnemonic'>Register using mnenomic</a>
</div>

@ -24,6 +24,14 @@
el: this.$('#phone-number-input'),
});
this.$('#error').hide();
window.mnemonic.get_languages().forEach(language => {
this.$('#mnemonic-language').append($('<option>', {
value: language,
text: language.charAt(0).toUpperCase() + language.slice(1),
}));
});
},
events: {
'validation input.number': 'onValidation',
@ -36,7 +44,7 @@
},
register() {
this.accountManager
.registerSingleDevice(this.$('#mnemonic').val())
.registerSingleDevice(this.$('#mnemonic').val(), this.$('#mnemonic-language').val())
.then(() => {
this.$el.trigger('openInbox');
})

@ -5,6 +5,7 @@ module.exports = {
mn_encode,
mn_decode,
sc_reduce32,
get_languages,
};
class MnemonicError extends Error {}
@ -127,14 +128,14 @@ function mn_decode(str, wordset_name) {
}
var mn_words = {
'electrum': {
prefix_len: 0,
words: require('../mnemonic_languages/electrum'),
},
'english': {
prefix_len: 3,
words: require('../mnemonic_languages/english'),
},
'electrum': {
prefix_len: 0,
words: require('../mnemonic_languages/electrum'),
},
'spanish': {
prefix_len: 4,
words: require('../mnemonic_languages/spanish'),
@ -149,6 +150,10 @@ var mn_words = {
}
};
function get_languages() {
return Object.keys(mn_words);
}
for (var i in mn_words) {
if (mn_words.hasOwnProperty(i)) {
if (mn_words[i].prefix_len === 0) {

@ -44,7 +44,7 @@
requestSMSVerification(number) {
return this.server.requestVerificationSMS(number);
},
registerSingleDevice(mnemonic) {
registerSingleDevice(mnemonic, mnemonicLanguage) {
const createAccount = this.createAccount.bind(this);
const clearSessionsAndPreKeys = this.clearSessionsAndPreKeys.bind(this);
const generateKeys = this.generateKeys.bind(this, 0);
@ -53,7 +53,7 @@
let generateKeypair;
if (mnemonic) {
generateKeypair = () => {
const seedHex = window.mnemonic.mn_decode(mnemonic);
const seedHex = window.mnemonic.mn_decode(mnemonic, mnemonicLanguage);
const privKeyHex = window.mnemonic.sc_reduce32(seedHex);
const privKey = dcodeIO.ByteBuffer.wrap(privKeyHex, 'hex').toArrayBuffer();
return libsignal.Curve.async.createKeyPair(privKey);

Loading…
Cancel
Save