From 96e484a3feba476d6d248630dbf7e748f5d0aeb0 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Date: Mon, 26 Jun 2023 14:31:35 +0100 Subject: [PATCH] Element-R: implement `CryptoApi.getVerificationRequestsToDeviceInProgress` (#3497) * Element-R: Implement `CryptoApi.getVerificationRequestsToDeviceInProgress` * Element-R: Implement `requestOwnUserVerification` (#3503) * Revert "Element-R: Implement `requestOwnUserVerification` (#3503)" This reverts commit 8da756503c3d72b8ecbf50b4c2cf807ac36229aa. oops, merged too soon --- spec/integ/crypto/verification.spec.ts | 13 +++++++++++++ src/rust-crypto/rust-crypto.ts | 8 ++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/spec/integ/crypto/verification.spec.ts b/spec/integ/crypto/verification.spec.ts index 1e71fdcd1..0750a66af 100644 --- a/spec/integ/crypto/verification.spec.ts +++ b/spec/integ/crypto/verification.spec.ts @@ -156,6 +156,12 @@ function runTests(backend: string, initCrypto: InitCrypto, methods: string[] | u it("can verify another device via SAS", async () => { await waitForDeviceList(); + // initially there should be no verifications in progress + { + const requests = aliceClient.getCrypto()!.getVerificationRequestsToDeviceInProgress(TEST_USER_ID); + expect(requests.length).toEqual(0); + } + // have alice initiate a verification. She should send a m.key.verification.request let [requestBody, request] = await Promise.all([ expectSendToDeviceMessage("m.key.verification.request"), @@ -171,6 +177,13 @@ function runTests(backend: string, initCrypto: InitCrypto, methods: string[] | u expect(request.initiatedByMe).toBe(true); expect(request.otherUserId).toEqual(TEST_USER_ID); + // and now the request should be visible via `getVerificationRequestsToDeviceInProgress` + { + const requests = aliceClient.getCrypto()!.getVerificationRequestsToDeviceInProgress(TEST_USER_ID); + expect(requests.length).toEqual(1); + expect(requests[0].transactionId).toEqual(transactionId); + } + let toDeviceMessage = requestBody.messages[TEST_USER_ID][TEST_DEVICE_ID]; expect(toDeviceMessage.from_device).toEqual(aliceClient.deviceId); expect(toDeviceMessage.transaction_id).toEqual(transactionId); diff --git a/src/rust-crypto/rust-crypto.ts b/src/rust-crypto/rust-crypto.ts index 4057c75db..2807b782c 100644 --- a/src/rust-crypto/rust-crypto.ts +++ b/src/rust-crypto/rust-crypto.ts @@ -544,8 +544,12 @@ export class RustCrypto implements CryptoBackend { * @returns the VerificationRequests that are in progress */ public getVerificationRequestsToDeviceInProgress(userId: string): VerificationRequest[] { - // TODO - return []; + const requests: RustSdkCryptoJs.VerificationRequest[] = this.olmMachine.getVerificationRequests( + new RustSdkCryptoJs.UserId(this.userId), + ); + return requests + .filter((request) => request.roomId === undefined) + .map((request) => new RustVerificationRequest(request, this.outgoingRequestProcessor)); } /**