diff --git a/ts/receiver/cache.ts b/ts/receiver/cache.ts index 0114960cb..65d9cd92f 100644 --- a/ts/receiver/cache.ts +++ b/ts/receiver/cache.ts @@ -1,6 +1,6 @@ import { EnvelopePlus } from './types'; import { StringUtils } from '../session/utils'; -import { toNumber } from 'lodash'; +import _ from 'lodash'; export async function removeFromCache(envelope: EnvelopePlus) { const { id } = envelope; @@ -33,7 +33,7 @@ export async function addToCache( export async function getAllFromCache() { window.log.info('getAllFromCache'); - const { textsecure, Lodash: _ } = window; + const { textsecure } = window; const count = await textsecure.storage.unprocessed.getCount(); @@ -50,7 +50,7 @@ export async function getAllFromCache() { return Promise.all( _.map(items, async (item: any) => { - const attempts = toNumber(item.attempts || 0) + 1; + const attempts = _.toNumber(item.attempts || 0) + 1; try { if (attempts >= 3) { diff --git a/ts/receiver/contentMessage.ts b/ts/receiver/contentMessage.ts index c17aebddc..6444119c3 100644 --- a/ts/receiver/contentMessage.ts +++ b/ts/receiver/contentMessage.ts @@ -17,6 +17,7 @@ import { PubKey } from '../session/types'; import { handleSyncMessage } from './syncMessages'; import { onError } from './errors'; +import ByteBuffer from 'bytebuffer'; export async function handleContentMessage(envelope: EnvelopePlus) { const plaintext = await decrypt(envelope, envelope.content); @@ -113,7 +114,7 @@ async function decryptPreKeyWhisperMessage( if (e.message === 'Unknown identity key') { // create an error that the UI will pick up and ask the // user if they want to re-negotiate - const buffer = window.dcodeIO.ByteBuffer.wrap(ciphertext); + const buffer = ByteBuffer.wrap(ciphertext); throw new window.textsecure.IncomingIdentityKeyError( address.toString(), buffer.toArrayBuffer(), @@ -312,7 +313,7 @@ async function decrypt( if (error && error.message === 'Unknown identity key') { // create an error that the UI will pick up and ask the // user if they want to re-negotiate - const buffer = window.dcodeIO.ByteBuffer.wrap(ciphertext); + const buffer = ByteBuffer.wrap(ciphertext); errorToThrow = new textsecure.IncomingIdentityKeyError( address.toString(), buffer.toArrayBuffer(), diff --git a/ts/receiver/mediumGroups.ts b/ts/receiver/mediumGroups.ts index 857c16671..edee1157a 100644 --- a/ts/receiver/mediumGroups.ts +++ b/ts/receiver/mediumGroups.ts @@ -4,6 +4,7 @@ import { EnvelopePlus } from './types'; import { MediumGroupResponseKeysMessage } from '../session/messages/outgoing'; import { getMessageQueue } from '../session'; import { PubKey } from '../session/types'; +import _ from 'lodash'; async function handleSenderKeyRequest( envelope: EnvelopePlus, @@ -59,14 +60,7 @@ async function handleSenderKey(envelope: EnvelopePlus, groupUpdate: any) { } async function handleNewGroup(envelope: EnvelopePlus, groupUpdate: any) { - const { - SenderKeyAPI, - StringView, - Whisper, - log, - textsecure, - Lodash: _, - } = window; + const { SenderKeyAPI, StringView, Whisper, log, textsecure } = window; const senderIdentity = envelope.source; diff --git a/ts/receiver/multidevice.ts b/ts/receiver/multidevice.ts index 7039b6b1b..881ff42bf 100644 --- a/ts/receiver/multidevice.ts +++ b/ts/receiver/multidevice.ts @@ -11,6 +11,8 @@ import { StringUtils } from '../session/utils'; import { MultiDeviceProtocol, SessionProtocol } from '../session/protocols'; import { PubKey } from '../session/types'; +import ByteBuffer from 'bytebuffer'; + async function unpairingRequestIsLegit(source: string, ourPubKey: string) { const { textsecure, storage, lokiFileServerAPI } = window; @@ -204,7 +206,7 @@ async function handleAuthorisationForSelf( } function parseContacts(arrbuf: ArrayBuffer): Array { - const buffer = new window.dcodeIO.ByteBuffer(); + const buffer = new ByteBuffer(); buffer.append(arrbuf); buffer.offset = 0; buffer.limit = arrbuf.byteLength; @@ -270,9 +272,14 @@ export async function handleContacts( window.log.info('contact sync'); // const { blob } = contacts; + if (!contacts.data) { + window.log.error('Contacts without data'); + return; + } + const attachmentPointer = { contacts, - data: window.dcodeIO.ByteBuffer.wrap(contacts.data).toArrayBuffer(), // ByteBuffer to ArrayBuffer + data: ByteBuffer.wrap(contacts.data).toArrayBuffer(), // ByteBuffer to ArrayBuffer }; const contactDetails = parseContacts(attachmentPointer.data); diff --git a/ts/receiver/syncMessages.ts b/ts/receiver/syncMessages.ts index 2fc42c90f..34e3b291a 100644 --- a/ts/receiver/syncMessages.ts +++ b/ts/receiver/syncMessages.ts @@ -3,6 +3,7 @@ import { SignalService } from '../protobuf'; import { removeFromCache } from './cache'; import { getEnvelopeId } from './common'; import _ from 'lodash'; +import ByteBuffer from 'bytebuffer'; import { handleEndSession } from './sessionHandling'; import { handleMediumGroupUpdate } from './mediumGroups'; @@ -131,7 +132,7 @@ async function handleSentMessage( function handleAttachment(attachment: any) { return { ...attachment, - data: window.dcodeIO.ByteBuffer.wrap(attachment.data).toArrayBuffer(), // ByteBuffer to ArrayBuffer + data: ByteBuffer.wrap(attachment.data).toArrayBuffer(), // ByteBuffer to ArrayBuffer }; } diff --git a/ts/session/snode_api/onions.ts b/ts/session/snode_api/onions.ts index cc1d68bd8..cfe7ca7ac 100644 --- a/ts/session/snode_api/onions.ts +++ b/ts/session/snode_api/onions.ts @@ -2,6 +2,8 @@ import fetch from 'node-fetch'; import https from 'https'; import { Snode } from './snodePool'; +import ByteBuffer from 'bytebuffer'; +import { StringUtils } from '../utils'; const BAD_PATH = 'bad_path'; @@ -43,7 +45,7 @@ async function encryptForRelay( const reqObj = { ...destination, - ciphertext: dcodeIO.ByteBuffer.wrap(payload).toString('base64'), + ciphertext: ByteBuffer.wrap(payload).toString('base64'), ephemeral_key: StringView.arrayBufferToHex(ctx.ephemeralKey), }; @@ -51,13 +53,11 @@ async function encryptForRelay( } async function makeGuardPayload(guardCtx: any) { - const ciphertextBase64 = window.dcodeIO.ByteBuffer.wrap( - guardCtx.ciphertext - ).toString('base64'); + const ciphertextBase64 = StringUtils.decode(guardCtx.ciphertext, 'base64'); const guardPayloadObj = { ciphertext: ciphertextBase64, - ephemeral_key: window.StringView.arrayBufferToHex(guardCtx.ephemeralKey), + ephemeral_key: StringUtils.decode(guardCtx.ephemeralKey, 'hex'), }; return guardPayloadObj; } diff --git a/ts/session/snode_api/snodePool.ts b/ts/session/snode_api/snodePool.ts index 459f9e61e..923aa57d7 100644 --- a/ts/session/snode_api/snodePool.ts +++ b/ts/session/snode_api/snodePool.ts @@ -10,6 +10,7 @@ import { } from './serviceNodeAPI'; import semver from 'semver'; +import _ from 'lodash'; export type SnodeEdKey = string; @@ -34,7 +35,7 @@ const nodesForPubkey: { [key: string]: Array } = {}; async function tryGetSnodeListFromLokidSeednode( seedNodes = window.seedNodeList ): Promise> { - const { log, Lodash: _ } = window; + const { log } = window; if (!seedNodes.length) { log.info( @@ -130,7 +131,7 @@ export async function markUnreachableForPubkey( } export function markNodeUnreachable(snode: Snode): void { - const { Lodash: _, log } = window; + const { log } = window; randomSnodePool = _.without(randomSnodePool, snode); log.warn( @@ -139,8 +140,6 @@ export function markNodeUnreachable(snode: Snode): void { } export async function getRandomSnodeAddress(): Promise { - const { Lodash: _ } = window; - // resolve random snode if (randomSnodePool.length === 0) { // allow exceptions to pass through upwards without the unhandled promise rejection @@ -154,7 +153,8 @@ export async function getRandomSnodeAddress(): Promise { } } - return _.sample(randomSnodePool); + // We know the pool can't be empty at this point + return _.sample(randomSnodePool) as Snode; } function compareSnodes(lhs: any, rhs: any): boolean { @@ -284,7 +284,7 @@ async function getSnodeListFromLokidSeednode( } async function refreshRandomPoolDetail(seedNodes: Array): Promise { - const { log, Lodash: _ } = window; + const { log } = window; // are we running any _getAllVerionsForRandomSnodePool if (stopGetAllVersionPromiseControl !== false) { @@ -303,6 +303,7 @@ async function refreshRandomPoolDetail(seedNodes: Array): Promise { port: snode.storage_port, pubkey_x25519: snode.pubkey_x25519, pubkey_ed25519: snode.pubkey_ed25519, + version: '', })); log.info( 'LokiSnodeAPI::refreshRandomPool - Refreshed random snode pool with', diff --git a/ts/session/snode_api/swarmPolling.ts b/ts/session/snode_api/swarmPolling.ts index 24631d52c..1af47b01f 100644 --- a/ts/session/snode_api/swarmPolling.ts +++ b/ts/session/snode_api/swarmPolling.ts @@ -62,9 +62,9 @@ export class SwarmPolling { public removePubkey(pubkey: PubKey) { if (this.pubkeys.indexOf(pubkey) !== -1) { - window.Lodash.remove(this.pubkeys, pubkey); + _.remove(this.pubkeys, pubkey); } else if (this.groupPubkeys.indexOf(pubkey) !== -1) { - window.Lodash.remove(this.groupPubkeys, pubkey); + _.remove(this.groupPubkeys, pubkey); } }