You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-07-31 15:24:23 +03:00
Add new methods for verification to CryptoApi
(#3474)
* Add accessors for verification requests to CryptoApi Part of https://github.com/vector-im/crypto-internal/issues/97 * Add new methods for verification to `CryptoApi` and deprecate old method https://github.com/vector-im/crypto-internal/issues/98
This commit is contained in:
committed by
GitHub
parent
1bae10c4b2
commit
22f0b781ea
@ -19,14 +19,14 @@ import { MockResponse } from "fetch-mock";
|
|||||||
|
|
||||||
import { createClient, CryptoEvent, MatrixClient } from "../../../src";
|
import { createClient, CryptoEvent, MatrixClient } from "../../../src";
|
||||||
import {
|
import {
|
||||||
|
canAcceptVerificationRequest,
|
||||||
ShowQrCodeCallbacks,
|
ShowQrCodeCallbacks,
|
||||||
ShowSasCallbacks,
|
ShowSasCallbacks,
|
||||||
Verifier,
|
|
||||||
VerifierEvent,
|
|
||||||
VerificationPhase,
|
VerificationPhase,
|
||||||
VerificationRequest,
|
VerificationRequest,
|
||||||
VerificationRequestEvent,
|
VerificationRequestEvent,
|
||||||
canAcceptVerificationRequest,
|
Verifier,
|
||||||
|
VerifierEvent,
|
||||||
} from "../../../src/crypto-api/verification";
|
} from "../../../src/crypto-api/verification";
|
||||||
import { escapeRegExp } from "../../../src/utils";
|
import { escapeRegExp } from "../../../src/utils";
|
||||||
import { CRYPTO_BACKENDS, emitPromise, InitCrypto } from "../../test-utils/test-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
|
// have alice initiate a verification. She should send a m.key.verification.request
|
||||||
let [requestBody, request] = await Promise.all([
|
let [requestBody, request] = await Promise.all([
|
||||||
expectSendToDeviceMessage("m.key.verification.request"),
|
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;
|
const transactionId = request.transactionId;
|
||||||
expect(transactionId).toBeDefined();
|
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
|
// have alice initiate a verification. She should send a m.key.verification.request
|
||||||
const [requestBody, request] = await Promise.all([
|
const [requestBody, request] = await Promise.all([
|
||||||
expectSendToDeviceMessage("m.key.verification.request"),
|
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;
|
const transactionId = request.transactionId;
|
||||||
|
|
||||||
|
@ -2431,12 +2431,17 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
|||||||
* @param roomId - the room to use for verification
|
* @param roomId - the room to use for verification
|
||||||
*
|
*
|
||||||
* @returns the VerificationRequest that is in progress, if any
|
* @returns the VerificationRequest that is in progress, if any
|
||||||
|
* @deprecated Prefer {@link CryptoApi.findVerificationRequestDMInProgress}.
|
||||||
*/
|
*/
|
||||||
public findVerificationRequestDMInProgress(roomId: string): VerificationRequest | undefined {
|
public findVerificationRequestDMInProgress(roomId: string): VerificationRequest | undefined {
|
||||||
if (!this.cryptoBackend) {
|
if (!this.cryptoBackend) {
|
||||||
throw new Error("End-to-end encryption disabled");
|
throw new Error("End-to-end encryption disabled");
|
||||||
|
} else if (!this.crypto) {
|
||||||
|
// Hack for element-R to avoid breaking the cypress tests. We can get rid of this once the react-sdk is
|
||||||
|
// updated to use CryptoApi.findVerificationRequestDMInProgress.
|
||||||
|
return undefined;
|
||||||
}
|
}
|
||||||
return this.cryptoBackend.findVerificationRequestDMInProgress(roomId);
|
return this.crypto.findVerificationRequestDMInProgress(roomId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2445,6 +2450,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
|||||||
* @param userId - the ID of the user to query
|
* @param userId - the ID of the user to query
|
||||||
*
|
*
|
||||||
* @returns the VerificationRequests that are in progress
|
* @returns the VerificationRequests that are in progress
|
||||||
|
* @deprecated Prefer {@link CryptoApi.getVerificationRequestsToDeviceInProgress}.
|
||||||
*/
|
*/
|
||||||
public getVerificationRequestsToDeviceInProgress(userId: string): VerificationRequest[] {
|
public getVerificationRequestsToDeviceInProgress(userId: string): VerificationRequest[] {
|
||||||
if (!this.crypto) {
|
if (!this.crypto) {
|
||||||
@ -2462,6 +2468,8 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
|||||||
*
|
*
|
||||||
* @returns resolves to a VerificationRequest
|
* @returns resolves to a VerificationRequest
|
||||||
* when the request has been sent to the other party.
|
* when the request has been sent to the other party.
|
||||||
|
*
|
||||||
|
* @deprecated Prefer {@link CryptoApi#requestOwnUserVerification} or {@link CryptoApi#requestDeviceVerification}.
|
||||||
*/
|
*/
|
||||||
public requestVerification(userId: string, devices?: string[]): Promise<VerificationRequest> {
|
public requestVerification(userId: string, devices?: string[]): Promise<VerificationRequest> {
|
||||||
if (!this.crypto) {
|
if (!this.crypto) {
|
||||||
|
@ -21,7 +21,6 @@ import { CryptoApi } from "../crypto-api";
|
|||||||
import { CrossSigningInfo, UserTrustLevel } from "../crypto/CrossSigning";
|
import { CrossSigningInfo, UserTrustLevel } from "../crypto/CrossSigning";
|
||||||
import { IEncryptedEventInfo } from "../crypto/api";
|
import { IEncryptedEventInfo } from "../crypto/api";
|
||||||
import { IEventDecryptionResult } from "../@types/crypto";
|
import { IEventDecryptionResult } from "../@types/crypto";
|
||||||
import { VerificationRequest } from "../crypto/verification/request/VerificationRequest";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common interface for the crypto implementations
|
* Common interface for the crypto implementations
|
||||||
@ -79,15 +78,6 @@ export interface CryptoBackend extends SyncCryptoCallbacks, CryptoApi {
|
|||||||
*/
|
*/
|
||||||
getEventEncryptionInfo(event: MatrixEvent): IEncryptedEventInfo;
|
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.
|
* Get the cross signing information for a given user.
|
||||||
*
|
*
|
||||||
|
@ -19,6 +19,7 @@ import { Room } from "./models/room";
|
|||||||
import { DeviceMap } from "./models/device";
|
import { DeviceMap } from "./models/device";
|
||||||
import { UIAuthCallback } from "./interactive-auth";
|
import { UIAuthCallback } from "./interactive-auth";
|
||||||
import { AddSecretStorageKeyOpts } from "./secret-storage";
|
import { AddSecretStorageKeyOpts } from "./secret-storage";
|
||||||
|
import { VerificationRequest } from "./crypto-api/verification";
|
||||||
|
|
||||||
/** Types of cross-signing key */
|
/** Types of cross-signing key */
|
||||||
export enum CrossSigningKey {
|
export enum CrossSigningKey {
|
||||||
@ -227,6 +228,51 @@ export interface CryptoApi {
|
|||||||
* The private key should be disposed of after displaying to the use.
|
* The private key should be disposed of after displaying to the use.
|
||||||
*/
|
*/
|
||||||
createRecoveryKeyFromPassphrase(password?: string): Promise<GeneratedSecretStorageKey>;
|
createRecoveryKeyFromPassphrase(password?: string): Promise<GeneratedSecretStorageKey>;
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// 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<VerificationRequest>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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<VerificationRequest>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2356,6 +2356,7 @@ export class Crypto extends TypedEventEmitter<CryptoEvent, CryptoEventHandlerMap
|
|||||||
return this.requestVerificationWithChannel(userId, channel, this.inRoomVerificationRequests);
|
return this.requestVerificationWithChannel(userId, channel, this.inRoomVerificationRequests);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @deprecated Use `requestOwnUserVerificationToDevice` or `requestDeviceVerification` */
|
||||||
public requestVerification(userId: string, devices?: string[]): Promise<VerificationRequest> {
|
public requestVerification(userId: string, devices?: string[]): Promise<VerificationRequest> {
|
||||||
if (!devices) {
|
if (!devices) {
|
||||||
devices = Object.keys(this.deviceList.getRawStoredDevicesForUser(userId));
|
devices = Object.keys(this.deviceList.getRawStoredDevicesForUser(userId));
|
||||||
@ -2368,6 +2369,14 @@ export class Crypto extends TypedEventEmitter<CryptoEvent, CryptoEventHandlerMap
|
|||||||
return this.requestVerificationWithChannel(userId, channel, this.toDeviceVerificationRequests);
|
return this.requestVerificationWithChannel(userId, channel, this.toDeviceVerificationRequests);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public requestOwnUserVerification(): Promise<VerificationRequest> {
|
||||||
|
return this.requestVerification(this.userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public requestDeviceVerification(userId: string, deviceId: string): Promise<VerificationRequest> {
|
||||||
|
return this.requestVerification(userId, [deviceId]);
|
||||||
|
}
|
||||||
|
|
||||||
private async requestVerificationWithChannel(
|
private async requestVerificationWithChannel(
|
||||||
userId: string,
|
userId: string,
|
||||||
channel: IVerificationChannel,
|
channel: IVerificationChannel,
|
||||||
|
@ -32,12 +32,13 @@ import { KeyClaimManager } from "./KeyClaimManager";
|
|||||||
import { MapWithDefault } from "../utils";
|
import { MapWithDefault } from "../utils";
|
||||||
import {
|
import {
|
||||||
BootstrapCrossSigningOpts,
|
BootstrapCrossSigningOpts,
|
||||||
|
CrossSigningKey,
|
||||||
CrossSigningStatus,
|
CrossSigningStatus,
|
||||||
DeviceVerificationStatus,
|
DeviceVerificationStatus,
|
||||||
GeneratedSecretStorageKey,
|
GeneratedSecretStorageKey,
|
||||||
ImportRoomKeyProgressData,
|
ImportRoomKeyProgressData,
|
||||||
ImportRoomKeysOpts,
|
ImportRoomKeysOpts,
|
||||||
CrossSigningKey,
|
VerificationRequest,
|
||||||
} from "../crypto-api";
|
} from "../crypto-api";
|
||||||
import { deviceKeysToDeviceMap, rustDeviceToJsDevice } from "./device-converter";
|
import { deviceKeysToDeviceMap, rustDeviceToJsDevice } from "./device-converter";
|
||||||
import { IDownloadKeyResult, IQueryKeysRequest } from "../client";
|
import { IDownloadKeyResult, IQueryKeysRequest } from "../client";
|
||||||
@ -165,18 +166,6 @@ export class RustCrypto implements CryptoBackend {
|
|||||||
return new UserTrustLevel(false, false, false);
|
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.
|
* 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<VerificationRequest> {
|
||||||
|
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<VerificationRequest> {
|
||||||
|
throw new Error("not implemented");
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// SyncCryptoCallbacks implementation
|
// SyncCryptoCallbacks implementation
|
||||||
|
Reference in New Issue
Block a user