From e12af96e5d8e1a0df1a4f3c411602115ab02dbfc Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Fri, 29 Sep 2023 17:04:54 +0100 Subject: [PATCH] Element-R: emit `VerificationRequestReceived` on incoming request --- spec/integ/crypto/verification.spec.ts | 16 +++++++++++---- src/rust-crypto/rust-crypto.ts | 27 +++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/spec/integ/crypto/verification.spec.ts b/spec/integ/crypto/verification.spec.ts index f477db48b78..c05a7caa6ac 100644 --- a/spec/integ/crypto/verification.spec.ts +++ b/spec/integ/crypto/verification.spec.ts @@ -984,8 +984,11 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st // Add verification request from Bob to Alice in the DM between them returnRoomMessageFromSync(TEST_ROOM_ID, createVerificationRequestEvent()); - // Wait for the sync response to be processed - await syncPromise(aliceClient); + // Wait for the request to be received + const request1 = await emitPromise(aliceClient, CryptoEvent.VerificationRequestReceived); + expect(request1.roomId).toBe(TEST_ROOM_ID); + expect(request1.isSelfVerification).toBe(false); + expect(request1.otherUserId).toBe("@bob:xyz"); const request = aliceClient.getCrypto()!.findVerificationRequestDMInProgress(TEST_ROOM_ID, "@bob:xyz"); // Expect to find the verification request received during the sync @@ -1021,14 +1024,19 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("verification (%s)", (backend: st await awaitDecryption(matrixEvent); expect(matrixEvent.getContent().msgtype).toEqual("m.bad.encrypted"); + const requestEventPromise = emitPromise(aliceClient, CryptoEvent.VerificationRequestReceived); + // Send Bob the room keys returnToDeviceMessageFromSync(toDeviceEvent); // advance the clock, because the devicelist likes to sleep for 5ms during key downloads await jest.advanceTimersByTimeAsync(10); - // Wait for the message to be decrypted - await awaitDecryption(matrixEvent, { waitOnDecryptionFailure: true }); + // Wait for the request to be decrypted + const request1 = await requestEventPromise; + expect(request1.roomId).toBe(TEST_ROOM_ID); + expect(request1.isSelfVerification).toBe(false); + expect(request1.otherUserId).toBe("@bob:xyz"); const request = aliceClient.getCrypto()!.findVerificationRequestDMInProgress(TEST_ROOM_ID, "@bob:xyz"); // Expect to find the verification request received during the sync diff --git a/src/rust-crypto/rust-crypto.ts b/src/rust-crypto/rust-crypto.ts index 852993b763b..e07c71f8972 100644 --- a/src/rust-crypto/rust-crypto.ts +++ b/src/rust-crypto/rust-crypto.ts @@ -62,7 +62,7 @@ import { keyFromPassphrase } from "../crypto/key_passphrase"; import { encodeRecoveryKey } from "../crypto/recoverykey"; import { crypto } from "../crypto/crypto"; import { isVerificationEvent, RustVerificationRequest, verificationMethodIdentifierToMethod } from "./verification"; -import { EventType } from "../@types/event"; +import { EventType, MsgType } from "../@types/event"; import { CryptoEvent } from "../crypto"; import { TypedEventEmitter } from "../models/typed-event-emitter"; import { RustBackupCryptoEventMap, RustBackupCryptoEvents, RustBackupDecryptor, RustBackupManager } from "./backup"; @@ -1407,6 +1407,31 @@ export class RustCrypto extends TypedEventEmitter