import type { OlmPayload, OlmEncryptedMessageContent } from "./types"; import type { Account } from "../Account"; import type { LockMap } from "../../../utils/LockMap"; import type { Storage } from "../../storage/idb/Storage"; import type { DeviceKey } from "../common"; import type { HomeServerApi } from "../../net/HomeServerApi"; import type { ILogItem } from "../../../logging/types"; import type * as OlmNamespace from "@matrix-org/olm"; type Olm = typeof OlmNamespace; type ClaimedOTKResponse = { [userId: string]: { [deviceId: string]: { [algorithmAndOtk: string]: { key: string; signatures: { [userId: string]: { [algorithmAndDevice: string]: string; }; }; }; }; }; }; export declare class Encryption { private readonly account; private readonly pickleKey; private readonly olm; private readonly storage; private readonly now; private readonly ownUserId; private readonly olmUtil; private readonly senderKeyLock; private _batchLocks; constructor(account: Account, pickleKey: string, olm: Olm, storage: Storage, now: () => number, ownUserId: string, olmUtil: Olm.Utility, senderKeyLock: LockMap); /** A hack to prevent olm OOMing when `encrypt` is called several times concurrently, * which is the case when encrypting voip signalling message to send over to_device. * A better fix will be to extract the common bits from megolm/KeyLoader in a super class * and have some sort of olm/SessionLoader that is shared between encryption and decryption * and only keeps the olm session in wasm memory for a brief moment, like we already do for RoomKeys, * and get the benefit of an optimal cache at the same time. * */ private _takeBatchLock; encrypt(type: string, content: Record, devices: DeviceKey[], hsApi: HomeServerApi, log: ILogItem): Promise; _encryptForMaxDevices(type: string, content: Record, devices: DeviceKey[], hsApi: HomeServerApi, log: ILogItem): Promise; _findExistingSessions(devices: DeviceKey[]): Promise<{ devicesWithoutSession: DeviceKey[]; existingEncryptionTargets: EncryptionTarget[]; }>; _encryptForDevice(type: string, content: Record, target: EncryptionTarget): OlmEncryptedMessageContent; _buildPlainTextMessageForDevice(type: string, content: Record, device: DeviceKey): OlmPayload; _createNewSessions(devicesWithoutSession: DeviceKey[], hsApi: HomeServerApi, timestamp: number, log: ILogItem): Promise; _claimOneTimeKeys(hsApi: HomeServerApi, deviceIdentities: DeviceKey[], log: ILogItem): Promise; _verifyAndCreateOTKTargets(userKeyMap: ClaimedOTKResponse, devicesByUser: Map>, log: ILogItem): EncryptionTarget[]; _loadSessions(encryptionTargets: EncryptionTarget[]): Promise; _storeSessions(encryptionTargets: EncryptionTarget[], timestamp: number): Promise; } declare class EncryptionTarget { readonly device: DeviceKey; readonly oneTimeKey: string | null; readonly sessionId: string | null; session: Olm.Session | null; constructor(device: DeviceKey, oneTimeKey: string | null, sessionId: string | null); static fromOTK(device: DeviceKey, oneTimeKey: string): EncryptionTarget; static fromSessionId(device: DeviceKey, sessionId: string): EncryptionTarget; dispose(): void; } export declare class EncryptedMessage { readonly content: OlmEncryptedMessageContent; readonly device: DeviceKey; constructor(content: OlmEncryptedMessageContent, device: DeviceKey); } export {};