From a791641b3418420f025066eea1293167f18a9027 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 26 Jan 2022 12:10:20 +0100 Subject: [PATCH] move types to separate file --- .../e2ee/megolm/keybackup/Curve25519.ts | 2 +- src/matrix/e2ee/megolm/keybackup/KeyBackup.ts | 43 ------------- src/matrix/e2ee/megolm/keybackup/types.ts | 61 +++++++++++++++++++ 3 files changed, 62 insertions(+), 44 deletions(-) create mode 100644 src/matrix/e2ee/megolm/keybackup/types.ts diff --git a/src/matrix/e2ee/megolm/keybackup/Curve25519.ts b/src/matrix/e2ee/megolm/keybackup/Curve25519.ts index f1345bc6..8007d422 100644 --- a/src/matrix/e2ee/megolm/keybackup/Curve25519.ts +++ b/src/matrix/e2ee/megolm/keybackup/Curve25519.ts @@ -17,7 +17,7 @@ limitations under the License. import {MEGOLM_ALGORITHM} from "../../common"; import type {RoomKey} from "../decryption/RoomKey"; -import type {BaseBackupInfo, SignatureMap, SessionKeyInfo} from "./KeyBackup"; +import type {BaseBackupInfo, SignatureMap, SessionKeyInfo} from "./types"; import type * as OlmNamespace from "@matrix-org/olm"; type Olm = typeof OlmNamespace; diff --git a/src/matrix/e2ee/megolm/keybackup/KeyBackup.ts b/src/matrix/e2ee/megolm/keybackup/KeyBackup.ts index f4c7b28b..38faa5e2 100644 --- a/src/matrix/e2ee/megolm/keybackup/KeyBackup.ts +++ b/src/matrix/e2ee/megolm/keybackup/KeyBackup.ts @@ -30,49 +30,6 @@ import type {Transaction} from "../../../storage/idb/Transaction"; import type * as OlmNamespace from "@matrix-org/olm"; type Olm = typeof OlmNamespace; -export type SignatureMap = { - [userId: string]: {[deviceIdAndAlgorithm: string]: string} -} - -export type BaseBackupInfo = { - version: string, - etag: string, - count: number, -} - -type OtherBackupInfo = BaseBackupInfo & { - algorithm: "other" -}; - -type BackupInfo = Curve25519.BackupInfo | OtherBackupInfo; -type SessionData = Curve25519.SessionData; - -type SessionInfo = { - first_message_index: number, - forwarded_count: number, - is_verified: boolean, - session_data: SessionData -} - -type MegOlmSessionKeyInfo = { - algorithm: MEGOLM_ALGORITHM, - sender_key: string, - sender_claimed_keys: {[algorithm: string]: string}, - forwarding_curve25519_key_chain: string[], - session_key: string -} - -// the type that session_data decrypts from / encrypts to -export type SessionKeyInfo = MegOlmSessionKeyInfo | {algorithm: string}; - -type KeyBackupPayload = { - rooms: { - [roomId: string]: { - sessions: {[sessionId: string]: SessionInfo} - } - } -} - export class KeyBackup { constructor( private readonly backupInfo: BackupInfo, diff --git a/src/matrix/e2ee/megolm/keybackup/types.ts b/src/matrix/e2ee/megolm/keybackup/types.ts new file mode 100644 index 00000000..ce56cca7 --- /dev/null +++ b/src/matrix/e2ee/megolm/keybackup/types.ts @@ -0,0 +1,61 @@ +/* +Copyright 2022 The Matrix.org Foundation C.I.C. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import type * as Curve25519 from "./Curve25519"; +import type {MEGOLM_ALGORITHM} from "../../common"; + +export type SignatureMap = { + [userId: string]: {[deviceIdAndAlgorithm: string]: string} +} + +export type BaseBackupInfo = { + version: string, + etag: string, + count: number, +} + +export type OtherBackupInfo = BaseBackupInfo & { + algorithm: "other" +}; + +export type BackupInfo = Curve25519.BackupInfo | OtherBackupInfo; +export type SessionData = Curve25519.SessionData; + +export type SessionInfo = { + first_message_index: number, + forwarded_count: number, + is_verified: boolean, + session_data: SessionData +} + +export type MegOlmSessionKeyInfo = { + algorithm: MEGOLM_ALGORITHM, + sender_key: string, + sender_claimed_keys: {[algorithm: string]: string}, + forwarding_curve25519_key_chain: string[], + session_key: string +} + +// the type that session_data decrypts from / encrypts to +export type SessionKeyInfo = MegOlmSessionKeyInfo | {algorithm: string}; + +export type KeyBackupPayload = { + rooms: { + [roomId: string]: { + sessions: {[sessionId: string]: SessionInfo} + } + } +}