aboutsummaryrefslogtreecommitdiffhomepage
path: root/public/scripts/chat.js
diff options
context:
space:
mode:
authorMarvin Borner2019-01-26 22:16:30 +0100
committerMarvin Borner2019-01-26 22:16:30 +0100
commit150779fa6ad074f9124a495cbb79209419a1ca34 (patch)
treec8d6a01cb3e738c0e1c7f04aec8049dd51a0763a /public/scripts/chat.js
parentbe66b667d1e301751e49d87fd9282c2f6148b6f8 (diff)
Added public key verification
Diffstat (limited to 'public/scripts/chat.js')
-rw-r--r--public/scripts/chat.js13
1 files changed, 6 insertions, 7 deletions
diff --git a/public/scripts/chat.js b/public/scripts/chat.js
index 5f437d9..9845b50 100644
--- a/public/scripts/chat.js
+++ b/public/scripts/chat.js
@@ -1,12 +1,12 @@
const $ = require('jquery');
const encryption = require('./2_encryption');
const generate = require('nanoid/generate');
-const nolookalikes = require('nanoid-dictionary/nolookalikes');
+const noLookalikes = require('nanoid-dictionary/nolookalikes');
-let connectedPeers = []; // TODO: Save new peers in array
let connectedPeer;
-const peerId = generate(nolookalikes, 16);
-const host = '127.0.0.1';
+let connectedPeers = []; // TODO: Save new peers in array
+const peerId = generate(noLookalikes, 16);
+const host = 'meta.marvinborner.de';
// setup encryption
(async () => {
@@ -38,7 +38,7 @@ function chat() {
* @param id
*/
function connect(id) {
- const connectionId = generate(nolookalikes, 16);
+ const connectionId = generate(noLookalikes, 16);
console.log('[LOG] Connecting to', id);
console.log('[LOG] Your connection ID is', connectionId);
connectedPeer = peer.connect(id, {label: connectionId, reliable: true});
@@ -53,7 +53,7 @@ function chat() {
* @returns {Promise<void>}
*/
async function sendMessage(message) {
- console.log(`[LOG] Sending message ${message} to ${connectedPeer.peer}`);
+ console.log(`[LOG] Sending message '${message}' to ${connectedPeer.peer}`);
await encryption.get(connectedPeer.peer).then(async peerKey => {
await encryption.encrypt(message, peerKey).then(async encrypted => {
connectedPeer.send({type: 'text', data: encrypted});
@@ -81,7 +81,6 @@ function chat() {
$('#messages').append(`<span style="color: green">${message}</span><br>`);
} else {
if (message.type === 'text') {
- // TODO: Cleanup async method calls
await encryption.get(connectedPeer.peer).then(async peerKey => {
await encryption.getPrivate().then(async privateKey => {
await encryption.decrypt(message.data, peerKey, privateKey, 'supersecure')