diff --git a/spec/integ/crypto/verification.spec.ts b/spec/integ/crypto/verification.spec.ts index 0ceac47246d..b5f500f5887 100644 --- a/spec/integ/crypto/verification.spec.ts +++ b/spec/integ/crypto/verification.spec.ts @@ -19,14 +19,14 @@ import { MockResponse } from "fetch-mock"; import { createClient, CryptoEvent, MatrixClient } from "../../../src"; import { + canAcceptVerificationRequest, ShowQrCodeCallbacks, ShowSasCallbacks, - Verifier, - VerifierEvent, VerificationPhase, VerificationRequest, VerificationRequestEvent, - canAcceptVerificationRequest, + Verifier, + VerifierEvent, } from "../../../src/crypto-api/verification"; import { escapeRegExp } from "../../../src/utils"; import { CRYPTO_BACKENDS, emitPromise, InitCrypto } from "../../test-utils/test-utils"; @@ -130,7 +130,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st // have alice initiate a verification. She should send a m.key.verification.request let [requestBody, request] = await Promise.all([ expectSendToDeviceMessage("m.key.verification.request"), - aliceClient.requestVerification(TEST_USER_ID, [TEST_DEVICE_ID]), + aliceClient.getCrypto()!.requestDeviceVerification(TEST_USER_ID, TEST_DEVICE_ID), ]); const transactionId = request.transactionId; expect(transactionId).toBeDefined(); @@ -273,7 +273,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st // have alice initiate a verification. She should send a m.key.verification.request const [requestBody, request] = await Promise.all([ expectSendToDeviceMessage("m.key.verification.request"), - aliceClient.requestVerification(TEST_USER_ID, [TEST_DEVICE_ID]), + aliceClient.getCrypto()!.requestDeviceVerification(TEST_USER_ID, TEST_DEVICE_ID), ]); const transactionId = request.transactionId; diff --git a/src/client.ts b/src/client.ts index bf7b5adfcc5..d0d71266206 100644 --- a/src/client.ts +++ b/src/client.ts @@ -2431,12 +2431,17 @@ export class MatrixClient extends TypedEventEmitter { if (!this.crypto) { diff --git a/src/common-crypto/CryptoBackend.ts b/src/common-crypto/CryptoBackend.ts index 6049cb76585..fef3950775b 100644 --- a/src/common-crypto/CryptoBackend.ts +++ b/src/common-crypto/CryptoBackend.ts @@ -21,7 +21,6 @@ import { CryptoApi } from "../crypto-api"; import { CrossSigningInfo, UserTrustLevel } from "../crypto/CrossSigning"; import { IEncryptedEventInfo } from "../crypto/api"; import { IEventDecryptionResult } from "../@types/crypto"; -import { VerificationRequest } from "../crypto/verification/request/VerificationRequest"; /** * Common interface for the crypto implementations @@ -79,15 +78,6 @@ export interface CryptoBackend extends SyncCryptoCallbacks, CryptoApi { */ getEventEncryptionInfo(event: MatrixEvent): IEncryptedEventInfo; - /** - * Finds a DM verification request that is already in progress for the given room id - * - * @param roomId - the room to use for verification - * - * @returns the VerificationRequest that is in progress, if any - */ - findVerificationRequestDMInProgress(roomId: string): VerificationRequest | undefined; - /** * Get the cross signing information for a given user. * diff --git a/src/crypto-api.ts b/src/crypto-api.ts index 7f438307b1e..b91dde6bf1d 100644 --- a/src/crypto-api.ts +++ b/src/crypto-api.ts @@ -19,6 +19,7 @@ import { Room } from "./models/room"; import { DeviceMap } from "./models/device"; import { UIAuthCallback } from "./interactive-auth"; import { AddSecretStorageKeyOpts } from "./secret-storage"; +import { VerificationRequest } from "./crypto-api/verification"; /** Types of cross-signing key */ export enum CrossSigningKey { @@ -227,6 +228,51 @@ export interface CryptoApi { * The private key should be disposed of after displaying to the use. */ createRecoveryKeyFromPassphrase(password?: string): Promise; + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // + // Device/User verification + // + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + /** + * Returns to-device verification requests that are already in progress for the given user id. + * + * @param userId - the ID of the user to query + * + * @returns the VerificationRequests that are in progress + */ + getVerificationRequestsToDeviceInProgress(userId: string): VerificationRequest[]; + + /** + * Finds a DM verification request that is already in progress for the given room id + * + * @param roomId - the room to use for verification + * + * @returns the VerificationRequest that is in progress, if any + */ + findVerificationRequestDMInProgress(roomId: string): VerificationRequest | undefined; + + /** + * Send a verification request to our other devices. + * + * If a verification is already in flight, returns it. Otherwise, initiates a new one. + * + * @returns a VerificationRequest when the request has been sent to the other party. + */ + requestOwnUserVerification(): Promise; + + /** + * Request an interactive verification with the given device. + * + * If a verification is already in flight, returns it. Otherwise, initiates a new one. + * + * @param userId - ID of the owner of the device to verify + * @param deviceId - ID of the device to verify + * + * @returns a VerificationRequest when the request has been sent to the other party. + */ + requestDeviceVerification(userId: string, deviceId: string): Promise; } /** diff --git a/src/crypto/index.ts b/src/crypto/index.ts index 16462d74445..d9ebd74a9ae 100644 --- a/src/crypto/index.ts +++ b/src/crypto/index.ts @@ -2356,6 +2356,7 @@ export class Crypto extends TypedEventEmitter { if (!devices) { devices = Object.keys(this.deviceList.getRawStoredDevicesForUser(userId)); @@ -2368,6 +2369,14 @@ export class Crypto extends TypedEventEmitter { + return this.requestVerification(this.userId); + } + + public requestDeviceVerification(userId: string, deviceId: string): Promise { + return this.requestVerification(userId, [deviceId]); + } + private async requestVerificationWithChannel( userId: string, channel: IVerificationChannel, diff --git a/src/rust-crypto/rust-crypto.ts b/src/rust-crypto/rust-crypto.ts index 598c4b00073..84a21c548d3 100644 --- a/src/rust-crypto/rust-crypto.ts +++ b/src/rust-crypto/rust-crypto.ts @@ -32,12 +32,13 @@ import { KeyClaimManager } from "./KeyClaimManager"; import { MapWithDefault } from "../utils"; import { BootstrapCrossSigningOpts, + CrossSigningKey, CrossSigningStatus, DeviceVerificationStatus, GeneratedSecretStorageKey, ImportRoomKeyProgressData, ImportRoomKeysOpts, - CrossSigningKey, + VerificationRequest, } from "../crypto-api"; import { deviceKeysToDeviceMap, rustDeviceToJsDevice } from "./device-converter"; import { IDownloadKeyResult, IQueryKeysRequest } from "../client"; @@ -165,18 +166,6 @@ export class RustCrypto implements CryptoBackend { return new UserTrustLevel(false, false, false); } - /** - * Finds a DM verification request that is already in progress for the given room id - * - * @param roomId - the room to use for verification - * - * @returns the VerificationRequest that is in progress, if any - */ - public findVerificationRequestDMInProgress(roomId: string): undefined { - // TODO - return; - } - /** * Get the cross signing information for a given user. * @@ -439,6 +428,64 @@ export class RustCrypto implements CryptoBackend { }; } + /** + * Returns to-device verification requests that are already in progress for the given user id. + * + * Implementation of {@link CryptoApi#getVerificationRequestsToDeviceInProgress} + * + * @param userId - the ID of the user to query + * + * @returns the VerificationRequests that are in progress + */ + public getVerificationRequestsToDeviceInProgress(userId: string): VerificationRequest[] { + // TODO + return []; + } + + /** + * Finds a DM verification request that is already in progress for the given room id + * + * Implementation of {@link CryptoApi#findVerificationRequestDMInProgress} + * + * @param roomId - the room to use for verification + * + * @returns the VerificationRequest that is in progress, if any + * + */ + public findVerificationRequestDMInProgress(roomId: string): undefined { + // TODO + return; + } + + /** + * Send a verification request to our other devices. + * + * If a verification is already in flight, returns it. Otherwise, initiates a new one. + * + * Implementation of {@link CryptoApi#requestOwnUserVerification}. + * + * @returns a VerificationRequest when the request has been sent to the other party. + */ + public requestOwnUserVerification(): Promise { + throw new Error("not implemented"); + } + + /** + * Request an interactive verification with the given device. + * + * If a verification is already in flight, returns it. Otherwise, initiates a new one. + * + * Implementation of {@link CryptoApi#requestDeviceVerification }. + * + * @param userId - ID of the owner of the device to verify + * @param deviceId - ID of the device to verify + * + * @returns a VerificationRequest when the request has been sent to the other party. + */ + public requestDeviceVerification(userId: string, deviceId: string): Promise { + throw new Error("not implemented"); + } + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // SyncCryptoCallbacks implementation