Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilb committed Sep 20, 2023
1 parent 1a18054 commit cd17a08
Show file tree
Hide file tree
Showing 19 changed files with 121 additions and 144 deletions.
1 change: 1 addition & 0 deletions libsession.worker.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require('path');

const isProd = process.env.NODE_ENV === 'production';

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion ts/node/sql_calls/config_dump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

import { compact, uniq } from 'lodash';
import { GroupPubkeyType } from 'libsession_util_nodejs';
import {
CONFIG_DUMP_TABLE,
ConfigDumpDataNode,
Expand All @@ -12,7 +13,6 @@ import {
// eslint-disable-next-line import/no-unresolved, import/extensions
import { ConfigWrapperObjectTypesMeta } from '../../webworker/workers/browser/libsession_worker_functions';
import { assertGlobalInstance } from '../sqlInstance';
import { GroupPubkeyType } from 'libsession_util_nodejs';

function parseRow(
row: Pick<ConfigDumpRow, 'data' | 'publicKey' | 'variant'>
Expand Down
6 changes: 3 additions & 3 deletions ts/receiver/configMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
ConfigWrapperUser,
getGroupPubkeyFromWrapperType,
isUserConfigWrapperType,
} from '../../ts/webworker/workers/browser/libsession_worker_functions';
} from '../webworker/workers/browser/libsession_worker_functions';
import { UserConfigKind, isUserKind } from '../types/ProtobufKind';
import {
ContactsWrapperActions,
Expand Down Expand Up @@ -115,7 +115,7 @@ async function mergeUserConfigsWithIncomingUpdates(
hash: msg.messageHash,
}));
if (window.sessionFeatureFlags.debug.debugLibsessionDumps) {
printDumpForDebug(`printDumpsForDebugging: before merge of ${variant}:`, variant);
await printDumpForDebug(`printDumpsForDebugging: before merge of ${variant}:`, variant);
}

const mergedCount = await GenericWrapperActions.merge(variant, toMerge);
Expand All @@ -129,7 +129,7 @@ async function mergeUserConfigsWithIncomingUpdates(
);

if (window.sessionFeatureFlags.debug.debugLibsessionDumps) {
printDumpForDebug(`printDumpsForDebugging: after merge of ${variant}:`, variant);
await printDumpForDebug(`printDumpsForDebugging: after merge of ${variant}:`, variant);
}
const incomingConfResult: IncomingUserResult = {
needsDump,
Expand Down
4 changes: 1 addition & 3 deletions ts/receiver/contentMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,12 @@ export async function handleSwarmContentMessage(envelope: EnvelopePlus, messageH

async function decryptForGroupV2(envelope: EnvelopePlus) {
window?.log?.info('received closed group message v2');
// try {
const groupPk = envelope.source;
if (!PubKey.isClosedGroupV2(groupPk)) {
throw new PreConditionFailed('decryptForGroupV2: not a 03 prefixed group');
}

return await MetaGroupWrapperActions.decryptMessage(groupPk, envelope.content);
// } catch (e) {}
return MetaGroupWrapperActions.decryptMessage(groupPk, envelope.content);
}

async function decryptForClosedGroup(envelope: EnvelopePlus) {
Expand Down
4 changes: 3 additions & 1 deletion ts/session/apis/snode_api/namespaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ function isGroupConfigNamespace(
assertUnreachable(namespace, `isGroupConfigNamespace case not handled: ${namespace}`);
} catch (e) {
window.log.warn(`isGroupConfigNamespace case not handled: ${namespace}: ${e.message}`);
return false;
}
}
return false;
}

/**
Expand Down Expand Up @@ -164,6 +164,7 @@ function isGroupNamespace(namespace: SnodeNamespaces): namespace is SnodeNamespa
return false;
}
}
return false;
}

function namespacePriority(namespace: SnodeNamespaces): 10 | 1 {
Expand All @@ -189,6 +190,7 @@ function namespacePriority(namespace: SnodeNamespaces): 10 | 1 {
return 1;
}
}
return 1;
}

function maxSizeMap(namespaces: Array<SnodeNamespaces>) {
Expand Down
2 changes: 1 addition & 1 deletion ts/session/apis/snode_api/retrieveRequest.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { isEmpty, isNil, omit } from 'lodash';
import { GroupPubkeyType } from 'libsession_util_nodejs';
import { Snode } from '../../../data/data';
import { updateIsOnline } from '../../../state/ducks/onion';
import { doSnodeBatchRequest } from './batchRequest';
import { GetNetworkTime } from './getNetworkTime';
import { SnodeNamespace, SnodeNamespaces } from './namespaces';

import { GroupPubkeyType } from 'libsession_util_nodejs';
import { UserGroupsWrapperActions } from '../../../webworker/workers/browser/libsession_worker_interface';
import { DURATION } from '../../constants';
import { PubKey } from '../../types';
Expand Down
1 change: 1 addition & 0 deletions ts/session/apis/snode_api/sessionRpc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import https from 'https';
// eslint-disable-next-line import/no-named-default
import { clone } from 'lodash';
// eslint-disable-next-line import/no-named-default
import { default as insecureNodeFetch } from 'node-fetch';
import pRetry from 'p-retry';

Expand Down
4 changes: 2 additions & 2 deletions ts/session/apis/snode_api/snodeSignatures.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FixedSizeUint8Array, GroupPubkeyType } from 'libsession_util_nodejs';
import { isEmpty } from 'lodash';
import { getSodiumRenderer } from '../../crypto';
import { StringUtils, UserUtils } from '../../utils';
import { fromHexToArray, fromUInt8ArrayToBase64 } from '../../utils/String';
Expand All @@ -7,7 +8,6 @@ import { SnodeNamespaces } from './namespaces';
import { PubKey } from '../../types';
import { toFixedUint8ArrayOfLength } from '../../../types/sqlSharedTypes';
import { PreConditionFailed } from '../../utils/errors';
import { isEmpty } from 'lodash';

export type SnodeSignatureResult = {
timestamp: number;
Expand Down Expand Up @@ -184,7 +184,7 @@ async function generateUpdateExpirySignature({
const signature = sodium.crypto_sign_detached(message, ed25519Privkey as Uint8Array);
const signatureBase64 = fromUInt8ArrayToBase64(signature);

if (!isEmpty(signatureBase64) || isEmpty(ed25519Pubkey)) {
if (isEmpty(signatureBase64) || isEmpty(ed25519Pubkey)) {
throw new Error('generateUpdateExpirySignature: failed to build signature');
}

Expand Down
42 changes: 20 additions & 22 deletions ts/session/apis/snode_api/swarmPolling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ export class SwarmPolling {
setTimeout(this.pollForAllKeys.bind(this), SWARM_POLLING_TIMEOUT.ACTIVE);
return;
}
window.log.warn('############################ pollForAllKeys ############################');
// we always poll as often as possible for our pubkey
const ourPubkey = UserUtils.getOurPubKeyStrFromCache();
const directPromise = this.pollOnceForKey([ourPubkey, ConversationTypeEnum.PRIVATE]);
Expand Down Expand Up @@ -318,32 +317,30 @@ export class SwarmPolling {
!allLegacyGroupsInWrapper.some(m => m.pubkeyHex === pubkey) // just check if a legacy group with that pubkey exists
) {
// not tracked anymore in the wrapper. Discard messages and stop polling
this.notPollingForGroupAsNotInWrapper(pubkey, 'not in wrapper after poll');
await this.notPollingForGroupAsNotInWrapper(pubkey, 'not in wrapper after poll');
return;
}
if (PubKey.isClosedGroupV2(pubkey) && allGroupsInWrapper.some(m => m.pubkeyHex === pubkey)) {
// not tracked anymore in the wrapper. Discard messages and stop polling
this.notPollingForGroupAsNotInWrapper(pubkey, 'not in wrapper after poll');
await this.notPollingForGroupAsNotInWrapper(pubkey, 'not in wrapper after poll');
return;
}

{
// trigger the handling of all the other messages, not shared config related
newMessages.forEach(m => {
const content = extractWebSocketContent(m.data, m.hash);
if (!content) {
return;
}
// trigger the handling of all the other messages, not shared config related
newMessages.forEach(m => {
const content = extractWebSocketContent(m.data, m.hash);
if (!content) {
return;
}

Receiver.handleRequest(
content.body,
type === ConversationTypeEnum.GROUP || type === ConversationTypeEnum.GROUPV3
? pubkey
: null,
content.messageHash
);
});
}
Receiver.handleRequest(
content.body,
type === ConversationTypeEnum.GROUP || type === ConversationTypeEnum.GROUPV3
? pubkey
: null,
content.messageHash
);
});
}

private async getHashesToBump(
Expand All @@ -364,12 +361,12 @@ export class SwarmPolling {
window.log.warn(`failed to get currentHashes for user variant ${variant}`);
}
}
window.log.debug(`configHashesToBump: ${configHashesToBump}`);
window.log.debug(`configHashesToBump private: ${configHashesToBump}`);
return configHashesToBump;
}
if (type === ConversationTypeEnum.GROUPV3 && PubKey.isClosedGroupV2(pubkey)) {
const toBump = await MetaGroupWrapperActions.currentHashes(pubkey);
window.log.debug(`configHashesToBump: ${toBump}`);
window.log.debug(`configHashesToBump group: ${toBump}`);
return toBump;
}
return [];
Expand Down Expand Up @@ -498,6 +495,7 @@ export class SwarmPolling {
return newMessages;
}

// eslint-disable-next-line consistent-return
private getNamespacesToPollFrom(type: ConversationTypeEnum): Array<SnodeNamespaces> {
if (type === ConversationTypeEnum.PRIVATE) {
return [
Expand Down Expand Up @@ -578,7 +576,7 @@ export class SwarmPolling {
}
}

function retrieveItemWithNamespace(results: RetrieveRequestResult[]) {
function retrieveItemWithNamespace(results: Array<RetrieveRequestResult>) {
return flatten(
compact(
results.map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ async function decryptSharedConfigMessages(

try {
const envelope: EnvelopePlus = SignalService.Envelope.decode(groupConfigMessage.body) as any;
// eslint-disable-next-line no-await-in-loop
const decryptedEnvelope = await decryptEnvelope(envelope);
if (!decryptedEnvelope?.byteLength) {
continue;
Expand Down
31 changes: 2 additions & 29 deletions ts/session/crypto/MessageEncrypter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ async function encryptForLegacyGroup(destination: PubKey, plainText: Uint8Array)
* @param encryptionType The type of encryption.
* @returns The envelope type and the base64 encoded cipher text
*/
// eslint-disable-next-line consistent-return
export async function encrypt(
destination: PubKey,
plainTextBuffer: Uint8Array,
Expand All @@ -64,23 +65,11 @@ export async function encrypt(

switch (encryptionType) {
case SESSION_MESSAGE: {
// if (destination.isPrivate || destination.isUS) {
const cipherText = await MessageEncrypter.encryptUsingSessionProtocol(
PubKey.cast(destination.key),
plainTextPadded
);
return { envelopeType: SESSION_MESSAGE, cipherText };
// }

// if (destination.isGroupV2 || destination.isLegacyGroup) {
// throw new PreConditionFailed(
// 'Encryption with SESSION_MESSAGE only work with destination private or us'
// );
// }
// assertUnreachable(
// destination,
// 'Encryption with SESSION_MESSAGE only work with destination private or us'
// );
}

case CLOSED_GROUP_MESSAGE: {
Expand All @@ -92,26 +81,10 @@ export async function encrypt(
};
}

// if (destination.isLegacyGroup) {
return encryptForLegacyGroup(destination, plainTextPadded); // not padding it again, it is already done by libsession
// }
// if (
// destination.isBlinded ||
// destination.isBlinded ||
// destination.isPrivate ||
// destination.isUS
// ) {
// throw new PreConditionFailed(
// 'Encryption with CLOSED_GROUP_MESSAGE only work with destination groupv2 or legacy group'
// );
// }
// assertUnreachable(
// destination,
// 'Encryption with CLOSED_GROUP_MESSAGE only work with destination groupv2 or legacy group'
// );
}
default:
assertUnreachable(encryptionType, '');
assertUnreachable(encryptionType, 'MessageEncrypter encrypt unreachable case');
}
}

Expand Down
2 changes: 1 addition & 1 deletion ts/session/group/closed-group.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _, { isNumber } from 'lodash';
import _, { isFinite, isNumber } from 'lodash';
import { v4 as uuidv4 } from 'uuid';

import { PubKey } from '../types';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { GroupPubkeyType } from 'libsession_util_nodejs';
import { SignalService } from '../../../../protobuf';
import { PubKey } from '../../../types';
import { StringUtils } from '../../../utils';
import { VisibleMessage } from './VisibleMessage';
import { ClosedGroupMessage } from '../controlMessage/group/ClosedGroupMessage';
import { DataMessage } from '../DataMessage';
import { GroupPubkeyType } from 'libsession_util_nodejs';
import { SnodeNamespaces } from '../../../apis/snode_api/namespaces';

interface ClosedGroupVisibleMessageParams {
Expand Down
4 changes: 1 addition & 3 deletions ts/session/utils/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,9 @@ export class HTTPError extends Error {
}

class BaseError extends Error {
public readonly context?: Object;
constructor(message: string, context?: Object) {
constructor(message: string) {
super(message);
this.name = this.constructor.name;
this.context = context;
}
}

Expand Down
10 changes: 8 additions & 2 deletions ts/session/utils/job_runners/jobs/GroupConfigJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
PersistedJob,
RunJobResult,
} from '../PersistedJob';
import { assertUnreachable } from '../../../../types/sqlSharedTypes';

const defaultMsBetweenRetries = 15000; // a long time between retries, to avoid running multiple jobs at the same time, when one was postponed at the same time as one already planned (5s)
const defaultMaxAttempts = 2;
Expand Down Expand Up @@ -96,8 +97,8 @@ async function buildAndSaveDumpsToDB(

for (let i = 0; i < changes.length; i++) {
const change = changes[i];

switch (change.pushed.namespace) {
const namespace = change.pushed.namespace;
switch (namespace) {
case SnodeNamespaces.ClosedGroupInfo: {
if ((change.pushed as any).seqno) {
toConfirm[1].groupInfo = [change.pushed.seqno.toNumber(), change.updatedHash];
Expand All @@ -108,6 +109,11 @@ async function buildAndSaveDumpsToDB(
toConfirm[1].groupMember = [change.pushed.seqno.toNumber(), change.updatedHash];
break;
}
case SnodeNamespaces.ClosedGroupKeys: {
break;
}
default:
assertUnreachable(namespace, 'buildAndSaveDumpsToDB assertUnreachable');
}
}

Expand Down
2 changes: 2 additions & 0 deletions ts/session/utils/libsession/libsession_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ async function pendingChangesForGroup(
return { messages: results, allOldHashes };
}

// eslint-disable-next-line consistent-return
function userKindToVariant(kind: UserConfigKind): ConfigWrapperUser {
switch (kind) {
case SignalService.SharedConfigMessage.Kind.USER_PROFILE:
Expand All @@ -323,6 +324,7 @@ function userKindToVariant(kind: UserConfigKind): ConfigWrapperUser {
}
}

// eslint-disable-next-line consistent-return
function userVariantToUserKind(variant: ConfigWrapperUser) {
switch (variant) {
case 'UserConfig':
Expand Down

0 comments on commit cd17a08

Please sign in to comment.