diff --git a/spec/integ/crypto/verification.spec.ts b/spec/integ/crypto/verification.spec.ts index fdcc4bf1a4c..f4690294515 100644 --- a/spec/integ/crypto/verification.spec.ts +++ b/spec/integ/crypto/verification.spec.ts @@ -170,6 +170,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st // there should now be a verifier const verifier: VerificationBase = request.verifier!; expect(verifier).toBeDefined(); + expect(verifier.getShowSasCallbacks()).toBeNull(); // start off the verification process: alice will send an `accept` const verificationPromise = verifier.verify(); @@ -205,6 +206,10 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st verifier.once(VerifierEvent.ShowSas, resolve); }); + // `getShowSasCallbacks` is an alternative way to get the callbacks + expect(verifier.getShowSasCallbacks()).toBe(showSas); + expect(verifier.getReciprocateQrCodeCallbacks()).toBeNull(); + // user confirms that the emoji match, and alice sends a 'mac' [requestBody] = await Promise.all([expectSendToDeviceMessage("m.key.verification.mac"), showSas.confirm()]); toDeviceMessage = requestBody.messages[TEST_USER_ID][TEST_DEVICE_ID]; @@ -320,6 +325,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st // there should now be a verifier const verifier: VerificationBase = request.verifier!; expect(verifier).toBeDefined(); + expect(verifier.getReciprocateQrCodeCallbacks()).toBeNull(); // ... which we call .verify on, which emits a ShowReciprocateQr event const verificationPromise = verifier.verify(); @@ -327,6 +333,10 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st verifier.once(VerifierEvent.ShowReciprocateQr, resolve); }); + // getReciprocateQrCodeCallbacks() is an alternative way to get the callbacks + expect(verifier.getReciprocateQrCodeCallbacks()).toBe(reciprocateQRCodeCallbacks); + expect(verifier.getShowSasCallbacks()).toBeNull(); + // Alice confirms she is happy reciprocateQRCodeCallbacks.confirm(); diff --git a/src/crypto/verification/Base.ts b/src/crypto/verification/Base.ts index 89bead3aa3e..de6a0f836b0 100644 --- a/src/crypto/verification/Base.ts +++ b/src/crypto/verification/Base.ts @@ -29,7 +29,12 @@ import { IVerificationChannel } from "./request/Channel"; import { MatrixClient } from "../../client"; import { VerificationRequest } from "./request/VerificationRequest"; import { TypedEventEmitter } from "../../models/typed-event-emitter"; -import { VerifierEvent, VerifierEventHandlerMap } from "../../crypto-api/verification"; +import { + ShowQrCodeCallbacks, + ShowSasCallbacks, + VerifierEvent, + VerifierEventHandlerMap, +} from "../../crypto-api/verification"; const timeoutException = new Error("Verification timed out"); @@ -373,4 +378,24 @@ export class VerificationBase< public get events(): string[] | undefined { return undefined; } + + /** + * Get the details for an SAS verification, if one is in progress + * + * Returns `null`, unless this verifier is for a SAS-based verification and we are waiting for the user to confirm + * the SAS matches. + */ + public getShowSasCallbacks(): ShowSasCallbacks | null { + return null; + } + + /** + * Get the details for reciprocating QR code verification, if one is in progress + * + * Returns `null`, unless this verifier is for reciprocating a QR-code-based verification (ie, the other user has + * already scanned our QR code), and we are waiting for the user to confirm. + */ + public getReciprocateQrCodeCallbacks(): ShowQrCodeCallbacks | null { + return null; + } } diff --git a/src/crypto/verification/QRCode.ts b/src/crypto/verification/QRCode.ts index 38feade12db..a51db2e34e6 100644 --- a/src/crypto/verification/QRCode.ts +++ b/src/crypto/verification/QRCode.ts @@ -119,6 +119,10 @@ export class ReciprocateQRCode extends Base { } }); }; + + public getReciprocateQrCodeCallbacks(): ShowQrCodeCallbacks | null { + return this.reciprocateQREvent ?? null; + } } const CODE_VERSION = 0x02; // the version of binary QR codes we support diff --git a/src/crypto/verification/SAS.ts b/src/crypto/verification/SAS.ts index 61f096ca452..f15adf585f0 100644 --- a/src/crypto/verification/SAS.ts +++ b/src/crypto/verification/SAS.ts @@ -480,4 +480,8 @@ export class SAS extends Base { } }); } + + public getShowSasCallbacks(): ShowSasCallbacks | null { + return this.sasEvent ?? null; + } }