You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-23 17:02:25 +03:00
Add new enum for verification methods. (#4129)
* Define constants for the verification methods. * Remove some confusing references to the *old* `VerificationMethod`
This commit is contained in:
committed by
GitHub
parent
d1259b241c
commit
d5a35f8a99
@@ -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<VerificationMethod>;
|
||||
verificationMethods?: Array<string>;
|
||||
|
||||
/**
|
||||
* Whether relaying calls through a TURN server should be forced. Default false.
|
||||
@@ -1271,7 +1272,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
|
||||
protected ongoingScrollbacks: { [roomId: string]: { promise?: Promise<Room>; 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<EmittedEvents, ClientEventHa
|
||||
}
|
||||
|
||||
// deprecated: use requestVerification instead
|
||||
public legacyDeviceVerification(
|
||||
userId: string,
|
||||
deviceId: string,
|
||||
method: VerificationMethod,
|
||||
): Promise<VerificationRequest> {
|
||||
public legacyDeviceVerification(userId: string, deviceId: string, method: string): Promise<VerificationRequest> {
|
||||
if (!this.crypto) {
|
||||
throw new Error("End-to-end encryption disabled");
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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[] {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<Verifier> {
|
||||
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<RustSdkCryptoJs.Sas> implem
|
||||
|
||||
/** For each specced verification method, the rust-side `VerificationMethod` corresponding to it */
|
||||
const verificationMethodsByIdentifier: Record<string, RustSdkCryptoJs.VerificationMethod> = {
|
||||
"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,
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
30
src/types.ts
30
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",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user