From 6140fef1f7ebe52b4cf7cee14b3a0ad816821163 Mon Sep 17 00:00:00 2001 From: Beaudan Date: Mon, 5 Aug 2019 14:03:12 +1000 Subject: [PATCH] Fix some bugs --- js/modules/loki_message_api.js | 28 ++++++++++++++++++++++++---- js/modules/loki_snode_api.js | 5 ++++- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/js/modules/loki_message_api.js b/js/modules/loki_message_api.js index c2f83fe3a..a5b3c4102 100644 --- a/js/modules/loki_message_api.js +++ b/js/modules/loki_message_api.js @@ -96,7 +96,9 @@ class LokiMessageAPI { const timestamp = Date.now(); const nonce = await calcNonce( messageEventData, - pubKey, + window.getEnvironment() === 'production' + ? pubKey + : pubKey.substring(0, pubKey.length - 2), data64, timestamp, ttl @@ -112,7 +114,7 @@ class LokiMessageAPI { } const params = { - pubKey: window.getEnvironment() === 'production' ? pubKey : pubKey.substring(0, pubKey.length - 2), + pubKey, ttl: ttl.toString(), nonce, timestamp: timestamp.toString(), @@ -214,8 +216,22 @@ class LokiMessageAPI { let successiveFailures = 0; while (successiveFailures < MAX_ACCEPTABLE_FAILURES) { await sleepFor(successiveFailures * 500); + let result; try { - const result = await rpc(`https://${address}`, port, 'store', params); + if (window.getEnvironment() === 'production') { + result = await rpc(`https://${address}`, port, 'store', params); + } else { + const testnetParams = { + ...params, + pubKey: params.pubKey.substring(0, params.pubKey.length - 2), + }; + result = await rpc( + `https://${address}`, + port, + 'store', + testnetParams + ); + } // Make sure we aren't doing too much PoW const currentDifficulty = window.storage.get('PoWDifficulty', null); @@ -323,8 +339,12 @@ class LokiMessageAPI { } async retrieveNextMessages(nodeUrl, nodeData) { + let { ourKey } = this; + if (window.getEnvironment() !== 'production') { + ourKey = ourKey.substring(0, ourKey.length - 2); + } const params = { - pubKey: this.ourKey, + pubKey: ourKey, lastHash: nodeData.lastHash || '', }; const options = { diff --git a/js/modules/loki_snode_api.js b/js/modules/loki_snode_api.js index 49e00c773..08cf90df7 100644 --- a/js/modules/loki_snode_api.js +++ b/js/modules/loki_snode_api.js @@ -190,7 +190,10 @@ class LokiSnodeAPI { const { ip, port } = await this.getRandomSnodeAddress(); try { const result = await rpc(`https://${ip}`, port, 'get_snodes_for_pubkey', { - pubKey, + pubKey: + window.getEnvironment() === 'production' + ? pubKey + : pubKey.substring(0, pubKey.length - 2), }); const snodes = result.snodes.filter(snode => snode.ip !== '0.0.0.0'); return snodes;