import { HistoryVisibility, DeviceKey } from "./common"; import { KeyUsage } from "../verification/CrossSigning"; import { MemberChange } from "../room/members/RoomMember"; import type { CrossSigningKey } from "../verification/CrossSigning"; import type { HomeServerApi } from "../net/HomeServerApi"; import type { Room } from "../room/Room"; import type { ILogItem } from "../../logging/types"; import type { Storage } from "../storage/idb/Storage"; import type { Transaction } from "../storage/idb/Transaction"; export declare enum KeysTrackingStatus { Outdated = 0, UpToDate = 1 } export type UserIdentity = { userId: string; roomIds: string[]; keysTrackingStatus: KeysTrackingStatus; }; export declare class DeviceTracker { private readonly _storage; private readonly _getSyncToken; private readonly _olmUtil; private readonly _ownUserId; private readonly _ownDeviceId; constructor(options: { storage: Storage; getSyncToken: () => string; olmUtil: Olm.Utility; ownUserId: string; ownDeviceId: string; }); writeDeviceChanges(changedUserIds: ReadonlyArray, txn: Transaction, log: ILogItem): Promise; /** @return Promise<{added: string[], removed: string[]}> the user ids for who the room was added or removed to the userIdentity, * and with who a key should be now be shared **/ writeMemberChanges(room: Room, memberChanges: Map, historyVisibility: HistoryVisibility, txn: Transaction): Promise<{ added: string[]; removed: string[]; }>; trackRoom(room: Room, historyVisibility: HistoryVisibility, log: ILogItem): Promise; invalidateUserKeys(userId: string): Promise; getCrossSigningKeyForUser(userId: string, usage: KeyUsage, hsApi: HomeServerApi | undefined, log: ILogItem): Promise; writeHistoryVisibility(room: Room, historyVisibility: HistoryVisibility, syncTxn: Transaction, log: ILogItem): Promise<{ added: string[]; removed: string[]; }>; _addRoomToUserIdentity(roomId: string, userId: string, txn: Transaction): Promise; _removeRoomFromUserIdentity(roomId: string, userId: string, txn: Transaction): Promise; _queryKeys(userIds: string[], hsApi: HomeServerApi, log: ILogItem): Promise<{ deviceKeys: Map; masterKeys: Map; selfSigningKeys: Map; userSigningKeys: Map; }>; _storeQueriedDevicesForUserId(userId: string, deviceKeys: DeviceKey[], txn: Transaction): Promise; _filterVerifiedCrossSigningKeys(crossSigningKeysResponse: { [userId: string]: CrossSigningKey; }, usage: KeyUsage, log: ILogItem): Map; _validateCrossSigningKey(userId: string, keyInfo: CrossSigningKey, usage: KeyUsage, log: ILogItem): boolean; /** * @return {Array<{userId, verifiedKeys: Array>} */ _filterVerifiedDeviceKeys(keyQueryDeviceKeysResponse: { [userId: string]: { [deviceId: string]: DeviceKey; }; }, parentLog: ILogItem): Map; _validateDeviceKey(userIdFromServer: string, deviceIdFromServer: string, deviceKey: DeviceKey, log: ILogItem): boolean; /** * Gives all the device identities for a room that is already tracked. * Can be used to decide which users to share keys with. * Assumes room is already tracked. Call `trackRoom` first if unsure. * @param {String} roomId [description] * @return {[type]} [description] */ devicesForTrackedRoom(roomId: string, hsApi: HomeServerApi, log: ILogItem): Promise; /** * Can be used to decide which users to share keys with. * Assumes room is already tracked. Call `trackRoom` first if unsure. * This will not return the device key for our own user, as we don't need to share keys with ourselves. */ devicesForRoomMembers(roomId: string, userIds: string[], hsApi: HomeServerApi, log: ILogItem): Promise; /** * Cannot be used to decide which users to share keys with. * Does not assume membership to any room or whether any room is tracked. * This will return device keys for our own user, including our own device. */ devicesForUsers(userIds: string[], hsApi: HomeServerApi, log: ILogItem): Promise; /** Gets a single device */ deviceForId(userId: string, deviceId: string, hsApi: HomeServerApi, log: ILogItem): Promise; /** * Gets all the device identities with which keys should be shared for a set of users in a tracked room. * If any userIdentities are outdated, it will fetch them from the homeserver. * @param {string} roomId the id of the tracked room to filter users by. * @param {Array} userIds a set of user ids to try and find the identity for. * @param {Transaction} userIdentityTxn to read the user identities * @param {HomeServerApi} hsApi * @return {Array} all devices identities for the given users we should share keys with. */ _devicesForUserIdsInTrackedRoom(roomId: string, userIds: string[], userIdentityTxn: Transaction, hsApi: HomeServerApi, log: ILogItem): Promise; /** Gets the device identites for a set of user identities that * are known to be up to date, and a set of userIds that are known * to be absent from our store our outdated. The outdated user ids * will have their keys fetched from the homeserver. */ _devicesForUserIdentities(upToDateIdentities: UserIdentity[], outdatedUserIds: string[], hsApi: HomeServerApi, log: ILogItem): Promise; getDeviceByCurve25519Key(curve25519Key: any, txn: Transaction): Promise; } export declare function tests(): { "trackRoom only writes joined members with history visibility of joined": (assert: any) => Promise; "getting devices for tracked room yields correct keys": (assert: any) => Promise; "device with changed key is ignored": (assert: any) => Promise; "change history visibility from joined to invited adds invitees": (assert: any) => Promise; "change history visibility from invited to joined removes invitees": (assert: any) => Promise; "adding invitee with history visibility of invited adds room to userIdentities": (assert: any) => Promise; "adding invitee with history visibility of joined doesn't add room": (assert: any) => Promise; "getting all devices after changing history visibility now includes invitees": (assert: any) => Promise; "rejecting invite with history visibility of invited removes room from user identity": (assert: any) => Promise; "remove room from user identity sharing multiple rooms with us preserves other room": (assert: any) => Promise; "add room to user identity sharing multiple rooms with us preserves other room": (assert: any) => Promise; "devicesForUsers fetches users even though they aren't in any tracked room": (assert: any) => Promise; "devicesForUsers doesn't add any roomId when creating userIdentity": (assert: any) => Promise; };