1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-25 05:23:13 +03:00

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.
This commit is contained in:
Richard van der Hoff
2023-06-27 12:24:29 +01:00
committed by GitHub
parent e4a9f958a0
commit 18626169e4
3 changed files with 24 additions and 1 deletions

View File

@@ -510,7 +510,10 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st
timestamp: Date.now() - 1000, 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.transactionId).toEqual(TRANSACTION_ID);
expect(request.phase).toEqual(VerificationPhase.Requested); expect(request.phase).toEqual(VerificationPhase.Requested);
expect(request.roomId).toBeUndefined(); expect(request.roomId).toBeUndefined();

View File

@@ -924,6 +924,7 @@ type CryptoEvents =
| CryptoEvent.RoomKeyRequest | CryptoEvent.RoomKeyRequest
| CryptoEvent.RoomKeyRequestCancellation | CryptoEvent.RoomKeyRequestCancellation
| CryptoEvent.VerificationRequest | CryptoEvent.VerificationRequest
| CryptoEvent.VerificationRequestReceived
| CryptoEvent.DeviceVerificationChanged | CryptoEvent.DeviceVerificationChanged
| CryptoEvent.UserTrustStatusChanged | CryptoEvent.UserTrustStatusChanged
| CryptoEvent.KeysChanged | CryptoEvent.KeysChanged

View File

@@ -91,6 +91,7 @@ import {
CrossSigningStatus, CrossSigningStatus,
DeviceVerificationStatus, DeviceVerificationStatus,
ImportRoomKeysOpts, ImportRoomKeysOpts,
VerificationRequest as CryptoApiVerificationRequest,
} from "../crypto-api"; } from "../crypto-api";
import { Device, DeviceMap } from "../models/device"; import { Device, DeviceMap } from "../models/device";
import { deviceInfoToDevice } from "./device-converter"; import { deviceInfoToDevice } from "./device-converter";
@@ -218,7 +219,16 @@ export enum CryptoEvent {
KeyBackupFailed = "crypto.keyBackupFailed", KeyBackupFailed = "crypto.keyBackupFailed",
KeyBackupSessionsRemaining = "crypto.keyBackupSessionsRemaining", KeyBackupSessionsRemaining = "crypto.keyBackupSessionsRemaining",
KeySignatureUploadFailure = "crypto.keySignatureUploadFailure", KeySignatureUploadFailure = "crypto.keySignatureUploadFailure",
/** @deprecated Use `VerificationRequestReceived`. */
VerificationRequest = "crypto.verification.request", 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", Warning = "crypto.warning",
WillUpdateDevices = "crypto.willUpdateDevices", WillUpdateDevices = "crypto.willUpdateDevices",
DevicesUpdated = "crypto.devicesUpdated", DevicesUpdated = "crypto.devicesUpdated",
@@ -280,8 +290,16 @@ export type CryptoEventHandlerMap = {
) => void; ) => void;
/** /**
* Fires when a key verification is requested. * Fires when a key verification is requested.
*
* Deprecated: use `CryptoEvent.VerificationRequestReceived`.
*/ */
[CryptoEvent.VerificationRequest]: (request: VerificationRequest<any>) => void; [CryptoEvent.VerificationRequest]: (request: VerificationRequest<any>) => 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 * Fires when the app may wish to warn the user about something related
* the end-to-end crypto. * the end-to-end crypto.
@@ -3541,6 +3559,7 @@ export class Crypto extends TypedEventEmitter<CryptoEvent, CryptoEventHandlerMap
!request.observeOnly; !request.observeOnly;
if (shouldEmit) { if (shouldEmit) {
this.baseApis.emit(CryptoEvent.VerificationRequest, request); this.baseApis.emit(CryptoEvent.VerificationRequest, request);
this.baseApis.emit(CryptoEvent.VerificationRequestReceived, request);
} }
} }