Added generation of seed in registration.

pull/71/head
Mikunj 7 years ago
parent 89a19fd09b
commit 85298012e4

@ -1669,5 +1669,10 @@
"editDisplayName": { "editDisplayName": {
"message": "Edit display name", "message": "Edit display name",
"description": "Button action that the user can click to edit their display name" "description": "Button action that the user can click to edit their display name"
},
"copiedMnemonic": {
"message": "Copied mnemonic to clipboard",
"description": "A toast message telling the user that the mnemonic was copied"
} }
} }

@ -603,7 +603,7 @@
<div class='step-body'> <div class='step-body'>
<div class='header'>Create your Loki Messenger Account</div> <div class='header'>Create your Loki Messenger Account</div>
<input class='form-control' type='text' placeholder='Display Name (optional)' autocomplete='off' spellcheck='false' maxlength='25'> <input class='form-control' type='text' id='display-name' placeholder='Display Name (optional)' autocomplete='off' spellcheck='false' maxlength='25'>
<h4 class='section-toggle'>Register using Mnenomic</h4> <h4 class='section-toggle'>Register using Mnenomic</h4>
<div class='standalone-mnemonic section-content'> <div class='standalone-mnemonic section-content'>
@ -611,13 +611,18 @@
<input class='form-control' type='text' id='mnemonic' placeholder='Mnemonic' autocomplete='off' spellcheck='false' /> <input class='form-control' type='text' id='mnemonic' placeholder='Mnemonic' autocomplete='off' spellcheck='false' />
<select id='mnemonic-language'></select> <select id='mnemonic-language'></select>
</div> </div>
<a class='button' id='register-mnemonic'>Register using mnenomic</a> <a class='button' id='register-mnemonic'>Register</a>
<div id='error' class='collapse'></div> <div id='error' class='collapse'></div>
<div id=status></div> <div id=status></div>
</div> </div>
<h4 class='section-toggle section-toggle-visible'>Register</h4> <h4 class='section-toggle section-toggle-visible'>Register</h4>
<div class='standalone-register section-content'> <div class='standalone-register section-content'>
<a class='button' id='register' data-loading-text='Please wait...'>Register</a> <div id='mnemonic-display' />
<div class='standalone-register-buttons'>
<a class='button' id='generate-mnemonic'>Generate Mnemonic</a>
<a class='button' id='copy-mnemonic'>Copy Mnemonic</a>
<a class='button' id='register' data-loading-text='Please wait...'>Register</a>
</div>
</div> </div>
</div> </div>
</div> </div>

@ -1,4 +1,4 @@
/* global Whisper, $, getAccountManager, textsecure, storage, ConversationController */ /* global Whisper, $, getAccountManager, textsecure, i18n, storage, ConversationController */
/* eslint-disable more/no-then */ /* eslint-disable more/no-then */
@ -27,6 +27,8 @@
this.$('.standalone-mnemonic').hide(); this.$('.standalone-mnemonic').hide();
this.onGenerateMnemonic();
window.mnemonic.get_languages().forEach(language => { window.mnemonic.get_languages().forEach(language => {
this.$('#mnemonic-language').append( this.$('#mnemonic-language').append(
$('<option>', { $('<option>', {
@ -41,15 +43,17 @@
'click #request-voice': 'requestVoice', 'click #request-voice': 'requestVoice',
'click #request-sms': 'requestSMSVerification', 'click #request-sms': 'requestSMSVerification',
'change #code': 'onChangeCode', 'change #code': 'onChangeCode',
'click #register': 'register', 'click #register': 'registerWithoutMnemonic',
'click #register-mnemonic': 'registerWithMnemonic', 'click #register-mnemonic': 'registerWithMnemonic',
'change #mnemonic': 'onChangeMnemonic', 'change #mnemonic': 'onChangeMnemonic',
'click #generate-mnemonic': 'onGenerateMnemonic',
'click #copy-mnemonic': 'onCopyMnemonic',
'click .section-toggle': 'toggleSection', 'click .section-toggle': 'toggleSection',
}, },
register() { register(mnemonic) {
this.accountManager this.accountManager
.registerSingleDevice( .registerSingleDevice(
this.$('#mnemonic').val(), mnemonic,
this.$('#mnemonic-language').val(), this.$('#mnemonic-language').val(),
this.$('#display-name').val() this.$('#display-name').val()
) )
@ -58,17 +62,34 @@
}) })
.catch(this.log.bind(this)); .catch(this.log.bind(this));
}, },
registerWithoutMnemonic() {
const mnemonic = this.$('#mnemonic-display').text();
this.register(mnemonic);
},
registerWithMnemonic() { registerWithMnemonic() {
const words = this.$('#mnemonic').val(); const mnemonic = this.$('#mnemonic').val();
if (!words) { if (!mnemonic) {
this.log('Please provide a mnemonic word list'); this.log('Please provide a mnemonic word list');
} else { } else {
this.register(); this.register(mnemonic);
} }
}, },
onChangeMnemonic() { onChangeMnemonic() {
this.$('#status').html(''); this.$('#status').html('');
}, },
async onGenerateMnemonic() {
const mnemonic = await this.accountManager.generateMnemonic();
this.$('#mnemonic-display').text(mnemonic)
},
onCopyMnemonic() {
window.clipboard.writeText(this.$('#mnemonic-display').text());
const toast = new Whisper.MessageToastView({
message: i18n('copiedMnemonic'),
});
toast.$el.appendTo(this.$el);
toast.render();
},
log(s) { log(s) {
window.log.info(s); window.log.info(s);
this.$('#status').text(s); this.$('#status').text(s);

@ -2,7 +2,7 @@
window, window,
textsecure, textsecure,
libsignal, libsignal,
WebSocketResource, mnemonic,
btoa, btoa,
getString, getString,
Event, Event,
@ -446,6 +446,11 @@
); );
}); });
}, },
async generateMnemonic() {
const keys = await libsignal.KeyHelper.generateIdentityKeyPair();
const hex = StringView.arrayBufferToHex(keys.privKey);
return mnemonic.mn_encode(hex);
},
async registrationDone(number, profileName) { async registrationDone(number, profileName) {
window.log.info('registration done'); window.log.info('registration done');

@ -722,8 +722,9 @@ textarea {
color: white; color: white;
background: $blue; background: $blue;
box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5); box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
user-select: none;
font-size: 12pt; font-size: 12pt;
margin-top: 4px;
&.neutral { &.neutral {
color: black; color: black;
@ -823,7 +824,7 @@ textarea {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
align-items: center; align-items: center;
margin: 1em 12px; margin: 1em 8px;
margin-top: 0; margin-top: 0;
input { input {
@ -832,6 +833,12 @@ textarea {
margin-right: 12px; margin-right: 12px;
} }
} }
#mnemonic-display {
margin: 8px;
margin-top: 0;
font-size: 16px;
}
} }
//yellow border fix //yellow border fix

Loading…
Cancel
Save