From 18626169e4bd7ba00d2f76f1388dbf6c72358aea Mon Sep 17 00:00:00 2001 From: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Date: Tue, 27 Jun 2023 12:24:29 +0100 Subject: [PATCH] Create a new event type for verification requests (#3514) * More slow test fixes * Create a new event type for verification requests Previous PRs (https://github.com/matrix-org/matrix-js-sdk/pull/3449, etc) have pulled out an interface from the `VerificationRequest` class, but applications registering for the `CryptoEvent.VerificationRequest` event could still be expecting a fully-fledged class rather than the interface. To handle this without breaking backwards compat, add a new event type that carries the interface, not the class. --- spec/integ/crypto/verification.spec.ts | 5 ++++- src/client.ts | 1 + src/crypto/index.ts | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/spec/integ/crypto/verification.spec.ts b/spec/integ/crypto/verification.spec.ts index 041881df0..2d6800201 100644 --- a/spec/integ/crypto/verification.spec.ts +++ b/spec/integ/crypto/verification.spec.ts @@ -510,7 +510,10 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st timestamp: Date.now() - 1000, }, }); - const request: VerificationRequest = await emitPromise(aliceClient, CryptoEvent.VerificationRequest); + const request: VerificationRequest = await emitPromise( + aliceClient, + CryptoEvent.VerificationRequestReceived, + ); expect(request.transactionId).toEqual(TRANSACTION_ID); expect(request.phase).toEqual(VerificationPhase.Requested); expect(request.roomId).toBeUndefined(); diff --git a/src/client.ts b/src/client.ts index a848abba1..3004f040c 100644 --- a/src/client.ts +++ b/src/client.ts @@ -924,6 +924,7 @@ type CryptoEvents = | CryptoEvent.RoomKeyRequest | CryptoEvent.RoomKeyRequestCancellation | CryptoEvent.VerificationRequest + | CryptoEvent.VerificationRequestReceived | CryptoEvent.DeviceVerificationChanged | CryptoEvent.UserTrustStatusChanged | CryptoEvent.KeysChanged diff --git a/src/crypto/index.ts b/src/crypto/index.ts index 699561f27..ff3410dea 100644 --- a/src/crypto/index.ts +++ b/src/crypto/index.ts @@ -91,6 +91,7 @@ import { CrossSigningStatus, DeviceVerificationStatus, ImportRoomKeysOpts, + VerificationRequest as CryptoApiVerificationRequest, } from "../crypto-api"; import { Device, DeviceMap } from "../models/device"; import { deviceInfoToDevice } from "./device-converter"; @@ -218,7 +219,16 @@ export enum CryptoEvent { KeyBackupFailed = "crypto.keyBackupFailed", KeyBackupSessionsRemaining = "crypto.keyBackupSessionsRemaining", KeySignatureUploadFailure = "crypto.keySignatureUploadFailure", + /** @deprecated Use `VerificationRequestReceived`. */ VerificationRequest = "crypto.verification.request", + + /** + * Fires when a key verification request is received. + * + * The payload is a {@link Crypto.VerificationRequest}. + */ + VerificationRequestReceived = "crypto.verificationRequestReceived", + Warning = "crypto.warning", WillUpdateDevices = "crypto.willUpdateDevices", DevicesUpdated = "crypto.devicesUpdated", @@ -280,8 +290,16 @@ export type CryptoEventHandlerMap = { ) => void; /** * Fires when a key verification is requested. + * + * Deprecated: use `CryptoEvent.VerificationRequestReceived`. */ [CryptoEvent.VerificationRequest]: (request: VerificationRequest) => void; + + /** + * Fires when a key verification request is received. + */ + [CryptoEvent.VerificationRequestReceived]: (request: CryptoApiVerificationRequest) => void; + /** * Fires when the app may wish to warn the user about something related * the end-to-end crypto. @@ -3541,6 +3559,7 @@ export class Crypto extends TypedEventEmitter