diff --git a/keyserver/src/keyserver.js b/keyserver/src/keyserver.js --- a/keyserver/src/keyserver.js +++ b/keyserver/src/keyserver.js @@ -7,7 +7,7 @@ import cors from 'cors'; import crypto from 'crypto'; import express from 'express'; -import type { $Request, $Response } from 'express'; +import type { $Request, $Response, Router } from 'express'; import expressWs from 'express-ws'; import os from 'os'; import qrcode from 'qrcode'; @@ -145,7 +145,7 @@ server.use(express.json({ limit: '250mb' })); server.use(cookieParser()); - const setupAppRouter = router => { + const setupAppRouter = (router: Router<>) => { if (areEndpointMetricsEnabled) { router.use(logEndpointMetrics); } diff --git a/keyserver/src/push/crypto.js b/keyserver/src/push/crypto.js --- a/keyserver/src/push/crypto.js +++ b/keyserver/src/push/crypto.js @@ -1,5 +1,6 @@ // @flow +import type { EncryptResult } from '@commapp/olm'; import apn from '@parse/node-apn'; import invariant from 'invariant'; import _cloneDeep from 'lodash/fp/cloneDeep.js'; @@ -49,7 +50,11 @@ let dbPersistCondition; if (notificationSizeValidator) { - dbPersistCondition = ({ serializedPayload }) => { + dbPersistCondition = ({ + serializedPayload, + }: { + +[string]: EncryptResult, + }) => { const notifCopy = _cloneDeep(encryptedNotification); notifCopy.payload.encryptedPayload = serializedPayload.body; return notificationSizeValidator(notifCopy); @@ -128,8 +133,11 @@ let dbPersistCondition; if (payloadSizeValidator) { - dbPersistCondition = ({ serializedPayload }) => - payloadSizeValidator({ encryptedPayload: serializedPayload.body }); + dbPersistCondition = ({ + serializedPayload, + }: { + +[string]: EncryptResult, + }) => payloadSizeValidator({ encryptedPayload: serializedPayload.body }); } const { diff --git a/keyserver/src/push/send.js b/keyserver/src/push/send.js --- a/keyserver/src/push/send.js +++ b/keyserver/src/push/send.js @@ -52,6 +52,7 @@ NotificationTargetDevice, TargetedAPNsNotification, TargetedAndroidNotification, + AndroidNotification, } from './types.js'; import { apnPush, @@ -840,7 +841,7 @@ messageInfos, }; - const notificationSizeValidator = notif => + const notificationSizeValidator = (notif: apn.Notification) => notif.length() <= apnMaxNotificationPayloadByteSize; if (!shouldBeEncrypted) { @@ -999,7 +1000,7 @@ })); } - const notificationsSizeValidator = notif => { + const notificationsSizeValidator = (notif: AndroidNotification) => { const serializedNotif = JSON.stringify(notif); return ( !serializedNotif || diff --git a/keyserver/src/scripts/generate-converter-from-validator.js b/keyserver/src/scripts/generate-converter-from-validator.js --- a/keyserver/src/scripts/generate-converter-from-validator.js +++ b/keyserver/src/scripts/generate-converter-from-validator.js @@ -216,7 +216,7 @@ const validator = rawThreadInfoValidator; const typeName = 'RawThreadInfo'; const validatorToBeConverted = tID; -const conversionExpressionString = inputName => +const conversionExpressionString = (inputName: string) => `'${ashoatKeyserverID}|' + ${inputName}`; main([ async () => { diff --git a/keyserver/src/socket/socket.js b/keyserver/src/socket/socket.js --- a/keyserver/src/socket/socket.js +++ b/keyserver/src/socket/socket.js @@ -193,7 +193,7 @@ onMessage = async ( messageString: string | Buffer | ArrayBuffer | Array, - ) => { + ): Promise => { invariant(typeof messageString === 'string', 'message should be string'); let clientSocketMessage: ?ClientSocketMessage; try { @@ -824,12 +824,12 @@ // The Socket will timeout by calling this.ws.terminate() // serverRequestSocketTimeout milliseconds after the last // time resetTimeout is called - resetTimeout = _debounce( + resetTimeout: { +cancel: () => void } & (() => void) = _debounce( () => this.ws.terminate(), serverRequestSocketTimeout, ); - debouncedAfterActivity = _debounce( + debouncedAfterActivity: { +cancel: () => void } & (() => void) = _debounce( () => this.setStateCheckConditions({ activityRecentlyOccurred: false }), stateCheckInactivityActivationInterval, ); @@ -858,7 +858,7 @@ this.handleStateCheckConditionsUpdate(); } - get stateCheckCanStart() { + get stateCheckCanStart(): boolean { return Object.values(this.stateCheckConditions).every(cond => !cond); } diff --git a/keyserver/src/utils/depth-queue.js b/keyserver/src/utils/depth-queue.js --- a/keyserver/src/utils/depth-queue.js +++ b/keyserver/src/utils/depth-queue.js @@ -18,7 +18,7 @@ this.mergeFunction = mergeFunction; } - addInfo(info: T) { + addInfo(info: T): void { const depth = this.getDepth(info); if (depth <= this.maxDequeuedDepth) { throw new Error( diff --git a/keyserver/src/utils/olm-utils.test.js b/keyserver/src/utils/olm-utils.test.js --- a/keyserver/src/utils/olm-utils.test.js +++ b/keyserver/src/utils/olm-utils.test.js @@ -8,13 +8,13 @@ const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 '; - const randomString = length => + const randomString = (length: number) => Array.from( { length }, () => alphabet[Math.floor(Math.random() * alphabet.length)], ).join(''); - const initAccount = (mark_prekey_published = true) => { + const initAccount = (mark_prekey_published: boolean = true) => { const account = new olm.Account(); account.create(); account.generate_prekey(); @@ -26,12 +26,12 @@ }; const createSession = ( - aliceSession, - aliceAccount, - bobAccount, - regen = false, - forget = false, - invalid_sign = false, + aliceSession: olm.Session, + aliceAccount: olm.Account, + bobAccount: olm.Account, + regen: boolean = false, + forget: boolean = false, + invalid_sign: boolean = false, ) => { const bobOneTimeKeys = JSON.parse(bobAccount.one_time_keys()).curve25519; bobAccount.mark_keys_as_published(); @@ -86,7 +86,12 @@ return aliceSession; }; - const testRatchet = (aliceSession, bobSession, bobAccount, num_msg = 1) => { + const testRatchet = ( + aliceSession: olm.Session, + bobSession: olm.Session, + bobAccount: olm.Account, + num_msg: number = 1, + ) => { let test_text = randomString(40); let encrypted = aliceSession.encrypt(test_text); expect(encrypted.type).toEqual(0);