From a0b52826e93797199ae1318ee314ff0071101f19 Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Wed, 18 Sep 2019 21:42:42 -0700 Subject: [PATCH 01/12] sign and only show verified messages --- js/modules/loki_public_chat_api.js | 112 ++++++++++++++++++++++++++++- 1 file changed, 110 insertions(+), 2 deletions(-) diff --git a/js/modules/loki_public_chat_api.js b/js/modules/loki_public_chat_api.js index 4823b0c1d..f81df9731 100644 --- a/js/modules/loki_public_chat_api.js +++ b/js/modules/loki_public_chat_api.js @@ -1,5 +1,5 @@ /* global log, textsecure, libloki, Signal, Whisper, Headers, ConversationController, -clearTimeout, MessageController */ +clearTimeout, MessageController, libsignal, StringView */ const EventEmitter = require('events'); const nodeFetch = require('node-fetch'); const { URL, URLSearchParams } = require('url'); @@ -16,6 +16,15 @@ class LokiPublicChatAPI extends EventEmitter { super(); this.ourKey = ourKey; this.servers = []; + this.myPrivateKey = false; + } + + async getPrivateKey() { + if (!this.myPrivateKey) { + const myKeyPair = await textsecure.storage.protocol.getIdentityKeyPair(); + this.myPrivateKey = myKeyPair.privKey; + } + return this.myPrivateKey; } // server getter/factory @@ -213,6 +222,7 @@ class LokiPublicChannelAPI { this.deleteLastId = 1; this.timers = {}; this.running = true; + this.logMop = {}; // end properties log.info(`registered LokiPublicChannel ${channelId}`); @@ -358,6 +368,22 @@ class LokiPublicChannelAPI { // update profile name as needed if (tokenRes.response.data.user.name !== profileName) { if (profileName) { + // will need this when we add an annotation + /* + const privKey = await this.serverAPI.chatAPI.getPrivateKey(); + // we might need an annotation that sets the homeserver for media + // better to include this with each attachment... + const ObjToSign = { + name: profileName, + version: 1, + annotations: [], + }; + const sig = await libsignal.Curve.async.calculateSignature( + privKey, + JSON.stringify(ObjToSign) + ); + */ + await this.serverRequest('users/me', { method: 'PATCH', objBody: { @@ -537,10 +563,11 @@ class LokiPublicChannelAPI { if (!res.err && res.response) { let receivedAt = new Date().getTime(); - res.response.data.reverse().forEach(adnMessage => { + res.response.data.reverse().forEach(async adnMessage => { let timestamp = new Date(adnMessage.created_at).getTime(); // pubKey lives in the username field let from = adnMessage.user.name; + let sigValid; let quote = null; if (adnMessage.is_deleted) { return; @@ -561,6 +588,71 @@ class LokiPublicChannelAPI { if (!from) { ({ from } = noteValue); } + + if (noteValue.sig) { + // try to verify signature + const { sig, sigver } = noteValue; + const annoCopy = JSON.parse(JSON.stringify(adnMessage.annotations)); + delete annoCopy[0].value.sig; + delete annoCopy[0].value.sigver; + const verifyObj = { + text: adnMessage.text, + version: sigver, + annotations: annoCopy, + }; + if (adnMessage.reply_to) { + verifyObj.reply_to = adnMessage.reply_to; + } + const pubKeyBin = StringView.hexToArrayBuffer( + adnMessage.user.username + ); + const sigBin = StringView.hexToArrayBuffer(sig); + try { + await libsignal.Curve.async.verifySignature( + pubKeyBin, + JSON.stringify(verifyObj), + sigBin + ); + sigValid = true; + } catch (e) { + if (e.message === 'Invalid signature') { + sigValid = false; + } + } + } + } + + // we now only accept valid messages into the public chat + if (sigValid !== true) { + let sig; + let sigver; + if ( + Array.isArray(adnMessage.annotations) && + adnMessage.annotations.length !== 0 + ) { + if (adnMessage.annotations[0].value.sig) { + ({ sig, sigver } = adnMessage.annotations[0].value); + } + } + // keep noise out of the logs, once per start up is enough + if (this.logMop[adnMessage.id] === undefined) { + log.warn( + 'Invalid or missing signature on ', + this.serverAPI.baseServerUrl, + this.channelId, + adnMessage.id, + 'says', + adnMessage.text, + 'from', + adnMessage.user.username, + 'signature', + sig, + 'signature version', + sigver + ); + this.logMop[adnMessage.id] = true; + } + return; // Invalid signature } if ( @@ -576,6 +668,7 @@ class LokiPublicChannelAPI { const messageData = { serverId: adnMessage.id, + clientVerified: sigValid, friendRequest: false, source: adnMessage.user.username, sourceDevice: 1, @@ -658,6 +751,21 @@ class LokiPublicChannelAPI { } } } + const privKey = await this.serverAPI.chatAPI.getPrivateKey(); + const ObjToSign = { + version: 1, + text, + annotations: payload.annotations, + }; + if (payload.reply_to) { + ObjToSign.reply_to = payload.reply_to; + } + const sig = await libsignal.Curve.async.calculateSignature( + privKey, + JSON.stringify(ObjToSign) + ); + payload.annotations[0].value.sig = StringView.arrayBufferToHex(sig); + payload.annotations[0].value.sigver = 1; const res = await this.serverRequest(`${this.baseChannelUrl}/messages`, { method: 'POST', objBody: payload, From a97788c7d99b9c3b8fd723d8bca21e97ce1a9ef1 Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Wed, 18 Sep 2019 21:52:12 -0700 Subject: [PATCH 02/12] modernize annotations since we're making a backward-incomp change --- js/modules/loki_public_chat_api.js | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/js/modules/loki_public_chat_api.js b/js/modules/loki_public_chat_api.js index f81df9731..955d1a0b0 100644 --- a/js/modules/loki_public_chat_api.js +++ b/js/modules/loki_public_chat_api.js @@ -577,16 +577,13 @@ class LokiPublicChannelAPI { adnMessage.annotations.length !== 0 ) { const noteValue = adnMessage.annotations[0].value; - ({ timestamp, quote } = noteValue); + ({ timestamp } = noteValue); - if (quote) { - quote.attachments = []; - } - - // if user doesn't have a name set, fallback to annotation - // pubkeys are already there in v1 (first release) - if (!from) { - ({ from } = noteValue); + if (noteValue.quote) { + ({ quote } = noteValue); + if (quote) { + quote.attachments = []; + } } if (noteValue.sig) { @@ -723,16 +720,13 @@ class LokiPublicChannelAPI { type: 'network.loki.messenger.publicChat', value: { timestamp: messageTimeStamp, - // will deprecated - from: displayName, - // will deprecated - source: pubKey, - quote, }, }, ], }; if (quote && quote.id) { + payload.annoations[0].value.quote = quote; + // copied from model/message.js copyFromQuotedMessage const collection = await Signal.Data.getMessagesBySentAt(quote.id, { MessageCollection: Whisper.MessageCollection, From 68186afba22656c07a3ebaef3bcf6cc18c70a5db Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Thu, 19 Sep 2019 19:48:04 -0700 Subject: [PATCH 03/12] lint and remove unneeded params --- js/modules/loki_message_api.js | 9 +-------- js/modules/loki_public_chat_api.js | 4 ++-- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/js/modules/loki_message_api.js b/js/modules/loki_message_api.js index f9c3610d6..bfe591fbf 100644 --- a/js/modules/loki_message_api.js +++ b/js/modules/loki_message_api.js @@ -88,17 +88,10 @@ class LokiMessageAPI { }; if (isPublic) { - const { profile } = data; - let displayName = 'Anonymous'; - if (profile && profile.displayName) { - ({ displayName } = profile); - } const res = await publicSendData.sendMessage( data.body, data.quote, - messageTimeStamp, - displayName, - this.ourKey + messageTimeStamp ); if (res === false) { throw new window.textsecure.PublicChatError( diff --git a/js/modules/loki_public_chat_api.js b/js/modules/loki_public_chat_api.js index 955d1a0b0..45fe69a0a 100644 --- a/js/modules/loki_public_chat_api.js +++ b/js/modules/loki_public_chat_api.js @@ -566,7 +566,7 @@ class LokiPublicChannelAPI { res.response.data.reverse().forEach(async adnMessage => { let timestamp = new Date(adnMessage.created_at).getTime(); // pubKey lives in the username field - let from = adnMessage.user.name; + const from = adnMessage.user.name; let sigValid; let quote = null; if (adnMessage.is_deleted) { @@ -712,7 +712,7 @@ class LokiPublicChannelAPI { } // create a message in the channel - async sendMessage(text, quote, messageTimeStamp, displayName, pubKey) { + async sendMessage(text, quote, messageTimeStamp) { const payload = { text, annotations: [ From d85cd980c2d6625138b1d2eff523d808e197ceba Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Tue, 24 Sep 2019 17:18:31 -0700 Subject: [PATCH 04/12] Update js/modules/loki_public_chat_api.js oof Co-Authored-By: sachaaaaa <40749766+sachaaaaa@users.noreply.github.com> --- js/modules/loki_public_chat_api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/modules/loki_public_chat_api.js b/js/modules/loki_public_chat_api.js index 25e081e3a..b2f0eb0d2 100644 --- a/js/modules/loki_public_chat_api.js +++ b/js/modules/loki_public_chat_api.js @@ -758,7 +758,7 @@ class LokiPublicChannelAPI { ], }; if (quote && quote.id) { - payload.annoations[0].value.quote = quote; + payload.annotations[0].value.quote = quote; // copied from model/message.js copyFromQuotedMessage const collection = await Signal.Data.getMessagesBySentAt(quote.id, { From c8cf05558f3fdaf2f314dcdeb2a3ed22cf5b949f Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Tue, 24 Sep 2019 17:33:32 -0700 Subject: [PATCH 05/12] pollOnceForMessages() move lastGot up, address Sacha's review --- js/modules/loki_public_chat_api.js | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/js/modules/loki_public_chat_api.js b/js/modules/loki_public_chat_api.js index b2f0eb0d2..b4b45db9f 100644 --- a/js/modules/loki_public_chat_api.js +++ b/js/modules/loki_public_chat_api.js @@ -223,6 +223,7 @@ class LokiPublicChannelAPI { this.deleteLastId = 1; this.timers = {}; this.running = true; + // can escalated to SQL if it start uses too much memory this.logMop = {}; // Cache for duplicate checking @@ -572,8 +573,16 @@ class LokiPublicChannelAPI { let timestamp = new Date(adnMessage.created_at).getTime(); // pubKey lives in the username field const from = adnMessage.user.name; - let sigValid; + let sigValid = false; + let sig = false; + let sigvar = false; let quote = null; + + // still update our last received if deleted, not signed or not valid + this.lastGot = !this.lastGot + ? adnMessage.id + : Math.max(this.lastGot, adnMessage.id); + if (adnMessage.is_deleted) { return; } @@ -593,8 +602,8 @@ class LokiPublicChannelAPI { if (noteValue.sig) { // try to verify signature - const { sig, sigver } = noteValue; - const annoCopy = JSON.parse(JSON.stringify(adnMessage.annotations)); + { sig, sigver } = noteValue; + const annoCopy = { ...adnMessage.annotations }; delete annoCopy[0].value.sig; delete annoCopy[0].value.sigver; const verifyObj = { @@ -623,19 +632,9 @@ class LokiPublicChannelAPI { } } } - + // we now only accept valid messages into the public chat if (sigValid !== true) { - let sig; - let sigver; - if ( - Array.isArray(adnMessage.annotations) && - adnMessage.annotations.length !== 0 - ) { - if (adnMessage.annotations[0].value.sig) { - ({ sig, sigver } = adnMessage.annotations[0].value); - } - } // keep noise out of the logs, once per start up is enough if (this.logMop[adnMessage.id] === undefined) { log.warn( @@ -736,9 +735,6 @@ class LokiPublicChannelAPI { // now process any user meta data updates // - update their conversation with a potentially new avatar - this.lastGot = !this.lastGot - ? adnMessage.id - : Math.max(this.lastGot, adnMessage.id); }); this.conversation.setLastRetrievedMessage(this.lastGot); } From 968ad9227c97190757c2ab8d1ad85d6d4a579609 Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Tue, 24 Sep 2019 18:03:46 -0700 Subject: [PATCH 06/12] refactor pls forgive, using github editor for expedience, untested changes --- js/modules/loki_public_chat_api.js | 191 +++++++++++++++-------------- 1 file changed, 100 insertions(+), 91 deletions(-) diff --git a/js/modules/loki_public_chat_api.js b/js/modules/loki_public_chat_api.js index b4b45db9f..ad712505d 100644 --- a/js/modules/loki_public_chat_api.js +++ b/js/modules/loki_public_chat_api.js @@ -379,14 +379,14 @@ class LokiPublicChannelAPI { const privKey = await this.serverAPI.chatAPI.getPrivateKey(); // we might need an annotation that sets the homeserver for media // better to include this with each attachment... - const ObjToSign = { + const objToSign = { name: profileName, version: 1, annotations: [], }; const sig = await libsignal.Curve.async.calculateSignature( privKey, - JSON.stringify(ObjToSign) + JSON.stringify(objToSign) ); */ @@ -534,6 +534,81 @@ class LokiPublicChannelAPI { more = res.response.meta.more && res.response.data.length >= params.count; } } + + async getMessengerData(adnMessage) { + if (!Array.isArray(adnMessage.annotations) || adnMessage.annotations.length === 0) return false; + const noteValue = adnMessage.annotations[0].value; + + // signatures now required + if (!noteValue.sig!) { + return false; + } + + let timetstamp = 0; + let quote = null; + + // timestamp is the only required field we've had since the first deployed version + ({ timestamp } = noteValue); + + if (noteValue.quote) { + ({ quote } = noteValue); + if (quote) { + quote.attachments = []; + } + } + + // try to verify signature + let { sig, sigver } = noteValue; + const annoCopy = _.omit(adnMessage.annotations, ['value.sig', 'value.sigver']); + const verifyObj = { + text: adnMessage.text, + version: sigver, + annotations: annoCopy, + }; + if (adnMessage.reply_to) { + verifyObj.reply_to = adnMessage.reply_to; + } + + const pubKeyBin = StringView.hexToArrayBuffer( + adnMessage.user.username + ); + const sigBin = StringView.hexToArrayBuffer(sig); + try { + await libsignal.Curve.async.verifySignature( + pubKeyBin, + JSON.stringify(verifyObj), + sigBin + ); + } catch (e) { + if (e.message === 'Invalid signature') { + // keep noise out of the logs, once per start up is enough + if (this.logMop[adnMessage.id] === undefined) { + log.warn( + 'Invalid or missing signature on ', + this.serverAPI.baseServerUrl, + this.channelId, + adnMessage.id, + 'says', + adnMessage.text, + 'from', + adnMessage.user.username, + 'signature', + sig, + 'signature version', + sigver + ); + this.logMop[adnMessage.id] = true; + } + // we now only accept valid messages into the public chat + return false; + } + } + + return { + timestamp, + quote + } + } // get channel messages async pollForMessages() { @@ -570,103 +645,33 @@ class LokiPublicChannelAPI { if (!res.err && res.response) { let receivedAt = new Date().getTime(); res.response.data.reverse().forEach(async adnMessage => { - let timestamp = new Date(adnMessage.created_at).getTime(); - // pubKey lives in the username field - const from = adnMessage.user.name; - let sigValid = false; - let sig = false; - let sigvar = false; - let quote = null; // still update our last received if deleted, not signed or not valid this.lastGot = !this.lastGot ? adnMessage.id : Math.max(this.lastGot, adnMessage.id); - - if (adnMessage.is_deleted) { - return; - } - if ( - Array.isArray(adnMessage.annotations) && - adnMessage.annotations.length !== 0 - ) { - const noteValue = adnMessage.annotations[0].value; - ({ timestamp } = noteValue); - - if (noteValue.quote) { - ({ quote } = noteValue); - if (quote) { - quote.attachments = []; - } - } - - if (noteValue.sig) { - // try to verify signature - { sig, sigver } = noteValue; - const annoCopy = { ...adnMessage.annotations }; - delete annoCopy[0].value.sig; - delete annoCopy[0].value.sigver; - const verifyObj = { - text: adnMessage.text, - version: sigver, - annotations: annoCopy, - }; - if (adnMessage.reply_to) { - verifyObj.reply_to = adnMessage.reply_to; - } - const pubKeyBin = StringView.hexToArrayBuffer( - adnMessage.user.username - ); - const sigBin = StringView.hexToArrayBuffer(sig); - try { - await libsignal.Curve.async.verifySignature( - pubKeyBin, - JSON.stringify(verifyObj), - sigBin - ); - sigValid = true; - } catch (e) { - if (e.message === 'Invalid signature') { - sigValid = false; - } - } - } - } - - // we now only accept valid messages into the public chat - if (sigValid !== true) { - // keep noise out of the logs, once per start up is enough - if (this.logMop[adnMessage.id] === undefined) { - log.warn( - 'Invalid or missing signature on ', - this.serverAPI.baseServerUrl, - this.channelId, - adnMessage.id, - 'says', - adnMessage.text, - 'from', - adnMessage.user.username, - 'signature', - sig, - 'signature version', - sigver - ); - this.logMop[adnMessage.id] = true; - } - return; // Invalid signature - } if ( - !from || - !timestamp || !adnMessage.id || !adnMessage.user || - !adnMessage.user.username || - !adnMessage.text + !adnMessage.user.username || // pubKey lives in the username field + !adnMessage.user.name || // profileName lives in the name field + !adnMessage.text || + adnMessage.is_deleted ) { - return; // Invalid message + return; // Invalid or delete message + } + + const messengerData = this.getMessengerData(adnMessage); + if (messengerData === false) { + return; } + const timestamp = messengerData.timestamp; + if (!timestamp) { + return; // Invalid message + } + // Duplicate check const isDuplicate = message => { // The username in this case is the users pubKey @@ -694,7 +699,11 @@ class LokiPublicChannelAPI { timestamp, }, ].splice(-5); - + + + const quote = messengerData.quote; + const from = adnMessage.user.name; // profileName + const messageData = { serverId: adnMessage.id, clientVerified: sigValid, @@ -775,17 +784,17 @@ class LokiPublicChannelAPI { } } const privKey = await this.serverAPI.chatAPI.getPrivateKey(); - const ObjToSign = { + const objToSign = { version: 1, text, annotations: payload.annotations, }; if (payload.reply_to) { - ObjToSign.reply_to = payload.reply_to; + objToSign.reply_to = payload.reply_to; } const sig = await libsignal.Curve.async.calculateSignature( privKey, - JSON.stringify(ObjToSign) + JSON.stringify(objToSign) ); payload.annotations[0].value.sig = StringView.arrayBufferToHex(sig); payload.annotations[0].value.sigver = 1; From b62801bc2a031f78890f4136ca14f85db358e6de Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Tue, 24 Sep 2019 18:18:38 -0700 Subject: [PATCH 07/12] fix typo CI found --- js/modules/loki_public_chat_api.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/modules/loki_public_chat_api.js b/js/modules/loki_public_chat_api.js index ad712505d..f99320fe0 100644 --- a/js/modules/loki_public_chat_api.js +++ b/js/modules/loki_public_chat_api.js @@ -540,7 +540,7 @@ class LokiPublicChannelAPI { const noteValue = adnMessage.annotations[0].value; // signatures now required - if (!noteValue.sig!) { + if (!noteValue.sig) { return false; } @@ -558,7 +558,7 @@ class LokiPublicChannelAPI { } // try to verify signature - let { sig, sigver } = noteValue; + const { sig, sigver } = noteValue; const annoCopy = _.omit(adnMessage.annotations, ['value.sig', 'value.sigver']); const verifyObj = { text: adnMessage.text, From a976388315f9d865e6300ab6543da39f7ef713ca Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Tue, 24 Sep 2019 18:36:25 -0700 Subject: [PATCH 08/12] Handle annotations omit correctly --- js/modules/loki_public_chat_api.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/js/modules/loki_public_chat_api.js b/js/modules/loki_public_chat_api.js index f99320fe0..0da4cac2a 100644 --- a/js/modules/loki_public_chat_api.js +++ b/js/modules/loki_public_chat_api.js @@ -559,7 +559,9 @@ class LokiPublicChannelAPI { // try to verify signature const { sig, sigver } = noteValue; - const annoCopy = _.omit(adnMessage.annotations, ['value.sig', 'value.sigver']); + const annoCopy = [ ...adnMessage.annotations ]; + delete annoCopy[0].value.sig; + delete annoCopy[0].value.sigver; const verifyObj = { text: adnMessage.text, version: sigver, @@ -602,6 +604,9 @@ class LokiPublicChannelAPI { // we now only accept valid messages into the public chat return false; } + // any error should cause problem + log.error(`Unhandled message signature validation error ${e.message}`); + return false; } return { From ab440a699fa2c3d0b3382465d75bc039ef210f78 Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Tue, 24 Sep 2019 18:37:31 -0700 Subject: [PATCH 09/12] Update js/modules/loki_public_chat_api.js Co-Authored-By: sachaaaaa <40749766+sachaaaaa@users.noreply.github.com> --- js/modules/loki_public_chat_api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/modules/loki_public_chat_api.js b/js/modules/loki_public_chat_api.js index 0da4cac2a..da1dc525e 100644 --- a/js/modules/loki_public_chat_api.js +++ b/js/modules/loki_public_chat_api.js @@ -667,7 +667,7 @@ class LokiPublicChannelAPI { return; // Invalid or delete message } - const messengerData = this.getMessengerData(adnMessage); + const messengerData = await this.getMessengerData(adnMessage); if (messengerData === false) { return; } From 6ac6d656a4c9486eae67deabb7fd98e300e1e00b Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Tue, 24 Sep 2019 18:41:26 -0700 Subject: [PATCH 10/12] make sure versioning on write can't get out of sync --- js/modules/loki_public_chat_api.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/js/modules/loki_public_chat_api.js b/js/modules/loki_public_chat_api.js index da1dc525e..8175843fc 100644 --- a/js/modules/loki_public_chat_api.js +++ b/js/modules/loki_public_chat_api.js @@ -560,8 +560,8 @@ class LokiPublicChannelAPI { // try to verify signature const { sig, sigver } = noteValue; const annoCopy = [ ...adnMessage.annotations ]; - delete annoCopy[0].value.sig; - delete annoCopy[0].value.sigver; + // strip out sig and sigver + annoCopy[0] = _.omit(annoCopy[0], ['value.sig', 'value.sigver']); const verifyObj = { text: adnMessage.text, version: sigver, @@ -802,7 +802,7 @@ class LokiPublicChannelAPI { JSON.stringify(objToSign) ); payload.annotations[0].value.sig = StringView.arrayBufferToHex(sig); - payload.annotations[0].value.sigver = 1; + payload.annotations[0].value.sigver = objToSign.version; const res = await this.serverRequest(`${this.baseChannelUrl}/messages`, { method: 'POST', objBody: payload, From 8bfb7f297dcb96e6e31ddca1144bbc06c1c143dd Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Tue, 24 Sep 2019 19:08:03 -0700 Subject: [PATCH 11/12] lint pass 1 --- js/modules/loki_public_chat_api.js | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/js/modules/loki_public_chat_api.js b/js/modules/loki_public_chat_api.js index 8175843fc..0e04b99b5 100644 --- a/js/modules/loki_public_chat_api.js +++ b/js/modules/loki_public_chat_api.js @@ -536,7 +536,9 @@ class LokiPublicChannelAPI { } async getMessengerData(adnMessage) { - if (!Array.isArray(adnMessage.annotations) || adnMessage.annotations.length === 0) return false; + if (!Array.isArray(adnMessage.annotations) || adnMessage.annotations.length === 0) { + return false; + } const noteValue = adnMessage.annotations[0].value; // signatures now required @@ -544,17 +546,11 @@ class LokiPublicChannelAPI { return false; } - let timetstamp = 0; - let quote = null; - // timestamp is the only required field we've had since the first deployed version - ({ timestamp } = noteValue); + let { timestamp, quote } = noteValue; - if (noteValue.quote) { - ({ quote } = noteValue); - if (quote) { - quote.attachments = []; - } + if (quote) { + quote.attachments = []; } // try to verify signature @@ -611,7 +607,7 @@ class LokiPublicChannelAPI { return { timestamp, - quote + quote, } } @@ -672,7 +668,7 @@ class LokiPublicChannelAPI { return; } - const timestamp = messengerData.timestamp; + const { timestamp, quote } = messengerData; if (!timestamp) { return; // Invalid message } @@ -704,14 +700,12 @@ class LokiPublicChannelAPI { timestamp, }, ].splice(-5); - - - const quote = messengerData.quote; + const from = adnMessage.user.name; // profileName const messageData = { serverId: adnMessage.id, - clientVerified: sigValid, + clientVerified: true, friendRequest: false, source: adnMessage.user.username, sourceDevice: 1, From 34b7117ff725972e4d67cd7bf9fc68f868f1b389 Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Tue, 24 Sep 2019 19:16:07 -0700 Subject: [PATCH 12/12] lint pass 2 --- js/modules/loki_public_chat_api.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/modules/loki_public_chat_api.js b/js/modules/loki_public_chat_api.js index 0e04b99b5..48d0f26bd 100644 --- a/js/modules/loki_public_chat_api.js +++ b/js/modules/loki_public_chat_api.js @@ -1,5 +1,5 @@ /* global log, textsecure, libloki, Signal, Whisper, Headers, ConversationController, -clearTimeout, MessageController, libsignal, StringView, window */ +clearTimeout, MessageController, libsignal, StringView, window, _ */ const EventEmitter = require('events'); const nodeFetch = require('node-fetch'); const { URL, URLSearchParams } = require('url'); @@ -547,7 +547,7 @@ class LokiPublicChannelAPI { } // timestamp is the only required field we've had since the first deployed version - let { timestamp, quote } = noteValue; + const { timestamp, quote } = noteValue; if (quote) { quote.attachments = [];