mirror of
https://github.com/oxen-io/session-desktop.git
synced 2023-12-14 02:12:57 +01:00
Move pubkey truncation to loki_rpc and add window function
This commit is contained in:
parent
0a231ea2ae
commit
492bb3723a
4 changed files with 16 additions and 28 deletions
|
@ -96,9 +96,7 @@ class LokiMessageAPI {
|
|||
const timestamp = Date.now();
|
||||
const nonce = await calcNonce(
|
||||
messageEventData,
|
||||
window.getEnvironment() === 'production'
|
||||
? pubKey
|
||||
: pubKey.substring(0, pubKey.length - 2),
|
||||
window.getStoragePubKey(pubKey),
|
||||
data64,
|
||||
timestamp,
|
||||
ttl
|
||||
|
@ -216,22 +214,8 @@ class LokiMessageAPI {
|
|||
let successiveFailures = 0;
|
||||
while (successiveFailures < MAX_ACCEPTABLE_FAILURES) {
|
||||
await sleepFor(successiveFailures * 500);
|
||||
let result;
|
||||
try {
|
||||
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
|
||||
);
|
||||
}
|
||||
const result = await rpc(`https://${address}`, port, 'store', params);
|
||||
|
||||
// Make sure we aren't doing too much PoW
|
||||
const currentDifficulty = window.storage.get('PoWDifficulty', null);
|
||||
|
@ -339,12 +323,8 @@ class LokiMessageAPI {
|
|||
}
|
||||
|
||||
async retrieveNextMessages(nodeUrl, nodeData) {
|
||||
let { ourKey } = this;
|
||||
if (window.getEnvironment() !== 'production') {
|
||||
ourKey = ourKey.substring(0, ourKey.length - 2);
|
||||
}
|
||||
const params = {
|
||||
pubKey: ourKey,
|
||||
pubKey: this.ourKey,
|
||||
lastHash: nodeData.lastHash || '',
|
||||
};
|
||||
const options = {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* global log, libloki, textsecure */
|
||||
/* global log, libloki, textsecure, getStoragePubKey */
|
||||
|
||||
const nodeFetch = require('node-fetch');
|
||||
const { parse } = require('url');
|
||||
|
@ -113,6 +113,14 @@ const rpc = (
|
|||
const portString = port ? `:${port}` : '';
|
||||
const url = `${address}${portString}${endpoint}`;
|
||||
// TODO: The jsonrpc and body field will be ignored on storage server
|
||||
if (params.pubKey) {
|
||||
// Ensure we always take a copy
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
params = {
|
||||
...params,
|
||||
pubKey: getStoragePubKey(params.pubKey),
|
||||
};
|
||||
}
|
||||
const body = {
|
||||
jsonrpc: '2.0',
|
||||
id: '0',
|
||||
|
|
|
@ -190,10 +190,7 @@ class LokiSnodeAPI {
|
|||
const { ip, port } = await this.getRandomSnodeAddress();
|
||||
try {
|
||||
const result = await rpc(`https://${ip}`, port, 'get_snodes_for_pubkey', {
|
||||
pubKey:
|
||||
window.getEnvironment() === 'production'
|
||||
? pubKey
|
||||
: pubKey.substring(0, pubKey.length - 2),
|
||||
pubKey,
|
||||
});
|
||||
const snodes = result.snodes.filter(snode => snode.ip !== '0.0.0.0');
|
||||
return snodes;
|
||||
|
|
|
@ -26,6 +26,7 @@ window.platform = process.platform;
|
|||
window.getDefaultPoWDifficulty = () => config.defaultPoWDifficulty;
|
||||
window.getTitle = () => title;
|
||||
window.getEnvironment = () => config.environment;
|
||||
window.isDev = () => config.environment === 'development';
|
||||
window.getAppInstance = () => config.appInstance;
|
||||
window.getVersion = () => config.version;
|
||||
window.isImportMode = () => config.importMode;
|
||||
|
@ -36,6 +37,8 @@ window.getHostName = () => config.hostname;
|
|||
window.getServerTrustRoot = () => config.serverTrustRoot;
|
||||
window.isBehindProxy = () => Boolean(config.proxyUrl);
|
||||
window.JobQueue = JobQueue;
|
||||
window.getStoragePubKey = key =>
|
||||
window.isDev() ? key.substring(0, key.length - 2) : key;
|
||||
|
||||
window.isBeforeVersion = (toCheck, baseVersion) => {
|
||||
try {
|
||||
|
|
Loading…
Reference in a new issue