Skip to content

Commit

Permalink
Create a new event type for verification requests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
richvdh committed Jun 26, 2023
1 parent a9a8c0a commit 9a25afb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion spec/integ/crypto/verification.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,7 @@ type CryptoEvents =
| CryptoEvent.RoomKeyRequest
| CryptoEvent.RoomKeyRequestCancellation
| CryptoEvent.VerificationRequest
| CryptoEvent.VerificationRequestReceived
| CryptoEvent.DeviceVerificationChanged
| CryptoEvent.UserTrustStatusChanged
| CryptoEvent.KeysChanged
Expand Down
19 changes: 19 additions & 0 deletions src/crypto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -280,8 +290,16 @@ export type CryptoEventHandlerMap = {
) => void;
/**
* Fires when a key verification is requested.
*
* Deprecated: use `CryptoEvent.VerificationRequestReceived`.
*/
[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
* the end-to-end crypto.
Expand Down Expand Up @@ -3541,6 +3559,7 @@ export class Crypto extends TypedEventEmitter<CryptoEvent, CryptoEventHandlerMap
!request.observeOnly;
if (shouldEmit) {
this.baseApis.emit(CryptoEvent.VerificationRequest, request);
this.baseApis.emit(CryptoEvent.VerificationRequestReceived, request);
}
}

Expand Down

0 comments on commit 9a25afb

Please sign in to comment.