diff options
author | Marvin Borner | 2019-01-26 23:28:49 +0100 |
---|---|---|
committer | Marvin Borner | 2019-01-26 23:28:49 +0100 |
commit | 8d03a0f5e668260a0d94de69d15fa3ddb064bc9d (patch) | |
tree | a99be6683f2b92c27b56b9cbb5c0fd9663d235f6 /public/scripts/chat.js | |
parent | 150779fa6ad074f9124a495cbb79209419a1ca34 (diff) |
Added mnemonic id generation
Diffstat (limited to 'public/scripts/chat.js')
-rw-r--r-- | public/scripts/chat.js | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/public/scripts/chat.js b/public/scripts/chat.js index 9845b50..5e577f2 100644 --- a/public/scripts/chat.js +++ b/public/scripts/chat.js @@ -1,15 +1,19 @@ const $ = require('jquery'); const encryption = require('./2_encryption'); -const generate = require('nanoid/generate'); -const noLookalikes = require('nanoid-dictionary/nolookalikes'); +const wordList = require('./3_wordlist'); +const xkcdPassword = require('xkcd-password'); +let peerId; let connectedPeer; let connectedPeers = []; // TODO: Save new peers in array -const peerId = generate(noLookalikes, 16); const host = 'meta.marvinborner.de'; +const generator = new xkcdPassword(); +generator.initWithWordList(wordList); + // setup encryption (async () => { + peerId = await generator.generate().then(words => words.join('-')); encryption.setup(); if (localStorage.getItem('database') === 'success' && await encryption.check()) { // TODO: Ask for passphrase @@ -36,9 +40,10 @@ function chat() { /** * Connects to a peer via his id * @param id + * @returns {Promise<void>} */ - function connect(id) { - const connectionId = generate(noLookalikes, 16); + async function connect(id) { + const connectionId = await generator.generate().then(words => words.join('-')); console.log('[LOG] Connecting to', id); console.log('[LOG] Your connection ID is', connectionId); connectedPeer = peer.connect(id, {label: connectionId, reliable: true}); @@ -97,7 +102,7 @@ function chat() { * Events after load */ $(document).ready(() => { - $('#add_peer_id').on('click', () => connect($('#peer_id').val())); + $('#add_peer_id').on('click', async () => await connect($('#peer_id').val())); $('#send_message').on('click', async () => await sendMessage($('#message').val())); $('[toggle-contact-modal]').on('click', () => $('#add_contact_modal').toggleClass('is-active')) |