diff --git a/src/client.ts b/src/client.ts index 5e1459338..3192e1449 100644 --- a/src/client.ts +++ b/src/client.ts @@ -83,7 +83,6 @@ import { ICryptoCallbacks, IRoomKeyRequestBody, isCryptoAvailable, - VerificationMethod, } from "./crypto"; import { DeviceInfo } from "./crypto/deviceinfo"; import { decodeRecoveryKey } from "./crypto/recoverykey"; @@ -378,8 +377,10 @@ export interface ICreateClientOpts { * Verification methods we should offer to the other side when performing an interactive verification. * If unset, we will offer all known methods. Currently these are: showing a QR code, scanning a QR code, and SAS * (aka "emojis"). + * + * See {@link types.VerificationMethod} for a set of useful constants for this parameter. */ - verificationMethods?: Array; + verificationMethods?: Array; /** * Whether relaying calls through a TURN server should be forced. Default false. @@ -1271,7 +1272,7 @@ export class MatrixClient extends TypedEventEmitter; errorTs?: number } } = {}; protected notifTimelineSet: EventTimelineSet | null = null; protected cryptoStore?: CryptoStore; - protected verificationMethods?: VerificationMethod[]; + protected verificationMethods?: string[]; protected fallbackICEServerAllowed = false; protected syncApi?: SlidingSyncSdk | SyncApi; public roomNameGenerator?: ICreateClientOpts["roomNameGenerator"]; @@ -2777,11 +2778,7 @@ export class MatrixClient extends TypedEventEmitter { + public legacyDeviceVerification(userId: string, deviceId: string, method: string): Promise { if (!this.crypto) { throw new Error("End-to-end encryption disabled"); } diff --git a/src/crypto/verification/QRCode.ts b/src/crypto/verification/QRCode.ts index b4e43252e..e0c7816eb 100644 --- a/src/crypto/verification/QRCode.ts +++ b/src/crypto/verification/QRCode.ts @@ -28,9 +28,10 @@ import { MatrixClient } from "../../client"; import { IVerificationChannel } from "./request/Channel"; import { MatrixEvent } from "../../models/event"; import { ShowQrCodeCallbacks, VerifierEvent } from "../../crypto-api/verification"; +import { VerificationMethod } from "../../types"; -export const SHOW_QR_CODE_METHOD = "m.qr_code.show.v1"; -export const SCAN_QR_CODE_METHOD = "m.qr_code.scan.v1"; +export const SHOW_QR_CODE_METHOD = VerificationMethod.ShowQrCode; +export const SCAN_QR_CODE_METHOD = VerificationMethod.ScanQrCode; /** @deprecated use VerifierEvent */ export type QrCodeEvent = VerifierEvent; diff --git a/src/crypto/verification/SAS.ts b/src/crypto/verification/SAS.ts index ba92d2348..7a21d615b 100644 --- a/src/crypto/verification/SAS.ts +++ b/src/crypto/verification/SAS.ts @@ -34,6 +34,7 @@ import { IContent, MatrixEvent } from "../../models/event"; import { generateDecimalSas } from "./SASDecimal"; import { EventType } from "../../@types/event"; import { EmojiMapping, GeneratedSas, ShowSasCallbacks, VerifierEvent } from "../../crypto-api/verification"; +import { VerificationMethod } from "../../types"; // backwards-compatibility exports export type { @@ -233,7 +234,7 @@ export class SAS extends Base { // eslint-disable-next-line @typescript-eslint/naming-convention public static get NAME(): string { - return "m.sas.v1"; + return VerificationMethod.Sas; } public get events(): string[] { diff --git a/src/rust-crypto/rust-crypto.ts b/src/rust-crypto/rust-crypto.ts index 99f70190a..2bec6fe28 100644 --- a/src/rust-crypto/rust-crypto.ts +++ b/src/rust-crypto/rust-crypto.ts @@ -73,8 +73,14 @@ import { ISignatures } from "../@types/signed"; import { encodeBase64 } from "../base64"; import { OutgoingRequestsManager } from "./OutgoingRequestsManager"; import { PerSessionKeyBackupDownloader } from "./PerSessionKeyBackupDownloader"; +import { VerificationMethod } from "../types"; -const ALL_VERIFICATION_METHODS = ["m.sas.v1", "m.qr_code.scan.v1", "m.qr_code.show.v1", "m.reciprocate.v1"]; +const ALL_VERIFICATION_METHODS = [ + VerificationMethod.Sas, + VerificationMethod.ScanQrCode, + VerificationMethod.ShowQrCode, + VerificationMethod.Reciprocate, +]; interface ISignableObject { signatures?: ISignatures; diff --git a/src/rust-crypto/verification.ts b/src/rust-crypto/verification.ts index dde54fd58..6d164adee 100644 --- a/src/rust-crypto/verification.ts +++ b/src/rust-crypto/verification.ts @@ -35,6 +35,7 @@ import { TypedReEmitter } from "../ReEmitter"; import { MatrixEvent } from "../models/event"; import { EventType, MsgType } from "../@types/event"; import { defer, IDeferred } from "../utils"; +import { VerificationMethod } from "../types"; /** * An incoming, or outgoing, request to verify a user or a device via cross-signing. @@ -230,9 +231,9 @@ export class RustVerificationRequest const verification: RustSdkCryptoJs.Qr | RustSdkCryptoJs.Sas | undefined = this.inner.getVerification(); if (verification instanceof RustSdkCryptoJs.Sas) { - return "m.sas.v1"; + return VerificationMethod.Sas; } else if (verification instanceof RustSdkCryptoJs.Qr) { - return "m.reciprocate.v1"; + return VerificationMethod.Reciprocate; } else { return null; } @@ -336,7 +337,7 @@ export class RustVerificationRequest * @param method - the name of the verification method to use. */ public async startVerification(method: string): Promise { - if (method !== "m.sas.v1") { + if (method !== VerificationMethod.Sas) { throw new Error(`Unsupported verification method ${method}`); } @@ -756,10 +757,10 @@ export class RustSASVerifier extends BaseRustVerifer implem /** For each specced verification method, the rust-side `VerificationMethod` corresponding to it */ const verificationMethodsByIdentifier: Record = { - "m.sas.v1": RustSdkCryptoJs.VerificationMethod.SasV1, - "m.qr_code.scan.v1": RustSdkCryptoJs.VerificationMethod.QrCodeScanV1, - "m.qr_code.show.v1": RustSdkCryptoJs.VerificationMethod.QrCodeShowV1, - "m.reciprocate.v1": RustSdkCryptoJs.VerificationMethod.ReciprocateV1, + [VerificationMethod.Sas]: RustSdkCryptoJs.VerificationMethod.SasV1, + [VerificationMethod.ScanQrCode]: RustSdkCryptoJs.VerificationMethod.QrCodeScanV1, + [VerificationMethod.ShowQrCode]: RustSdkCryptoJs.VerificationMethod.QrCodeShowV1, + [VerificationMethod.Reciprocate]: RustSdkCryptoJs.VerificationMethod.ReciprocateV1, }; /** diff --git a/src/types.ts b/src/types.ts index 97a89002c..adfd4e5b3 100644 --- a/src/types.ts +++ b/src/types.ts @@ -25,3 +25,33 @@ export type * from "./@types/media"; export * from "./@types/membership"; export type * from "./@types/event"; export type * from "./@types/state_events"; + +/** The different methods for device and user verification */ +export enum VerificationMethod { + /** Short authentication string (emoji or decimals). + * + * @see https://spec.matrix.org/v1.9/client-server-api/#short-authentication-string-sas-verification + */ + Sas = "m.sas.v1", + + /** + * Verification by showing a QR code which is scanned by the other device. + * + * @see https://spec.matrix.org/v1.9/client-server-api/#qr-codes + */ + ShowQrCode = "m.qr_code.show.v1", + + /** + * Verification by scanning a QR code that is shown by the other device. + * + * @see https://spec.matrix.org/v1.9/client-server-api/#qr-codes + */ + ScanQrCode = "m.qr_code.scan.v1", + + /** + * Verification by confirming that we have scanned a QR code. + * + * @see https://spec.matrix.org/v1.9/client-server-api/#qr-codes + */ + Reciprocate = "m.reciprocate.v1", +}