Skip to content

Commit 1430d43

Browse files
committed
Create a new event type for verification requests
Previous PRs (#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.
1 parent f67a7a0 commit 1430d43

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

spec/integ/crypto/verification.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,10 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st
504504
timestamp: Date.now() - 1000,
505505
},
506506
});
507-
const request: VerificationRequest = await emitPromise(aliceClient, CryptoEvent.VerificationRequest);
507+
const request: VerificationRequest = await emitPromise(
508+
aliceClient,
509+
CryptoEvent.VerificationRequestReceived,
510+
);
508511
expect(request.transactionId).toEqual(TRANSACTION_ID);
509512
expect(request.phase).toEqual(VerificationPhase.Requested);
510513
expect(request.roomId).toBeUndefined();

src/client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,7 @@ type CryptoEvents =
923923
| CryptoEvent.RoomKeyRequest
924924
| CryptoEvent.RoomKeyRequestCancellation
925925
| CryptoEvent.VerificationRequest
926+
| CryptoEvent.VerificationRequestReceived
926927
| CryptoEvent.DeviceVerificationChanged
927928
| CryptoEvent.UserTrustStatusChanged
928929
| CryptoEvent.KeysChanged

src/crypto/index.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ import {
9191
CrossSigningStatus,
9292
DeviceVerificationStatus,
9393
ImportRoomKeysOpts,
94+
VerificationRequest as CryptoApiVerificationRequest,
9495
} from "../crypto-api";
9596
import { Device, DeviceMap } from "../models/device";
9697
import { deviceInfoToDevice } from "./device-converter";
@@ -218,7 +219,16 @@ export enum CryptoEvent {
218219
KeyBackupFailed = "crypto.keyBackupFailed",
219220
KeyBackupSessionsRemaining = "crypto.keyBackupSessionsRemaining",
220221
KeySignatureUploadFailure = "crypto.keySignatureUploadFailure",
222+
/** @deprecated Use `VerificationRequestReceived`. */
221223
VerificationRequest = "crypto.verification.request",
224+
225+
/**
226+
* Fires when a key verification request is received.
227+
*
228+
* The payload is a {@link Crypto.VerificationRequest}.
229+
*/
230+
VerificationRequestReceived = "crypto.verificationRequestReceived",
231+
222232
Warning = "crypto.warning",
223233
WillUpdateDevices = "crypto.willUpdateDevices",
224234
DevicesUpdated = "crypto.devicesUpdated",
@@ -280,8 +290,16 @@ export type CryptoEventHandlerMap = {
280290
) => void;
281291
/**
282292
* Fires when a key verification is requested.
293+
*
294+
* Deprecated: use `CryptoEvent.VerificationRequestReceived`.
283295
*/
284296
[CryptoEvent.VerificationRequest]: (request: VerificationRequest<any>) => void;
297+
298+
/**
299+
* Fires when a key verification request is received.
300+
*/
301+
[CryptoEvent.VerificationRequestReceived]: (request: CryptoApiVerificationRequest) => void;
302+
285303
/**
286304
* Fires when the app may wish to warn the user about something related
287305
* the end-to-end crypto.
@@ -3541,6 +3559,7 @@ export class Crypto extends TypedEventEmitter<CryptoEvent, CryptoEventHandlerMap
35413559
!request.observeOnly;
35423560
if (shouldEmit) {
35433561
this.baseApis.emit(CryptoEvent.VerificationRequest, request);
3562+
this.baseApis.emit(CryptoEvent.VerificationRequestReceived, request);
35443563
}
35453564
}
35463565

0 commit comments

Comments
 (0)