From 79c98a3432367497a04e2a86820fee07f74d3716 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Wed, 6 Mar 2024 20:07:40 +0000 Subject: [PATCH 1/2] Remove references to internal js-sdk type `CryptoBackend` --- .eslintrc.js | 2 -- test/components/views/rooms/EventTile-test.tsx | 6 +++--- test/test-utils/test-utils.ts | 6 +++--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 342dbde484a..0d877a7bbbd 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -125,8 +125,6 @@ module.exports = { "!matrix-js-sdk/src/crypto/verification/QRCode", "!matrix-js-sdk/src/crypto/verification/request", "!matrix-js-sdk/src/crypto/verification/request/VerificationRequest", - "!matrix-js-sdk/src/common-crypto", - "!matrix-js-sdk/src/common-crypto/CryptoBackend", "!matrix-js-sdk/src/oidc", "!matrix-js-sdk/src/oidc/discovery", "!matrix-js-sdk/src/oidc/authorize", diff --git a/test/components/views/rooms/EventTile-test.tsx b/test/components/views/rooms/EventTile-test.tsx index b46eef44b85..16fa0ba1edb 100644 --- a/test/components/views/rooms/EventTile-test.tsx +++ b/test/components/views/rooms/EventTile-test.tsx @@ -29,7 +29,6 @@ import { TweakName, } from "matrix-js-sdk/src/matrix"; import { EventEncryptionInfo, EventShieldColour, EventShieldReason } from "matrix-js-sdk/src/crypto-api"; -import { CryptoBackend } from "matrix-js-sdk/src/common-crypto/CryptoBackend"; import { TooltipProvider } from "@vector-im/compound-web"; import EventTile, { EventTileProps } from "../../../../src/components/views/rooms/EventTile"; @@ -317,11 +316,12 @@ describe("EventTile", () => { }); const mockCrypto = { - decryptEvent: async (_ev): Promise => { + decryptEvent: async (_ev: MatrixEvent): Promise => { throw new Error("can't decrypt"); }, - } as CryptoBackend; + }; + // @ts-ignore `mockCrypto` is not a `CryptoBackend`, which is an internal type in the js-sdk await mxEvent.attemptDecryption(mockCrypto); const { container } = getComponent(); diff --git a/test/test-utils/test-utils.ts b/test/test-utils/test-utils.ts index a79a7ce5f03..c946d7a46b4 100644 --- a/test/test-utils/test-utils.ts +++ b/test/test-utils/test-utils.ts @@ -43,7 +43,6 @@ import { normalize } from "matrix-js-sdk/src/utils"; import { ReEmitter } from "matrix-js-sdk/src/ReEmitter"; import { MediaHandler } from "matrix-js-sdk/src/webrtc/mediaHandler"; import { Feature, ServerSupport } from "matrix-js-sdk/src/feature"; -import { CryptoBackend } from "matrix-js-sdk/src/common-crypto/CryptoBackend"; import { MapperOpts } from "matrix-js-sdk/src/event-mapper"; // eslint-disable-next-line no-restricted-imports import { MatrixRTCSessionManager } from "matrix-js-sdk/src/matrixrtc/MatrixRTCSessionManager"; @@ -441,9 +440,10 @@ export async function mkEncryptedEvent(opts: { }; const mockCrypto = { - decryptEvent: async (_ev): Promise => decryptionResult, - } as CryptoBackend; + decryptEvent: async (_ev: MatrixEvent): Promise => decryptionResult, + }; + // @ts-ignore `mockCrypto` is not a `CryptoBackend`, which is an internal type in the js-sdk await mxEvent.attemptDecryption(mockCrypto); return mxEvent; } From 094be3c4480960453d002582c1b9530f7651c52d Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Wed, 6 Mar 2024 20:55:22 +0000 Subject: [PATCH 2/2] Use `Paramteters` to avoid `ts-ignore` --- test/components/views/rooms/EventTile-test.tsx | 6 ++---- test/test-utils/test-utils.ts | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/test/components/views/rooms/EventTile-test.tsx b/test/components/views/rooms/EventTile-test.tsx index 16fa0ba1edb..ce89a9fe8fe 100644 --- a/test/components/views/rooms/EventTile-test.tsx +++ b/test/components/views/rooms/EventTile-test.tsx @@ -316,12 +316,10 @@ describe("EventTile", () => { }); const mockCrypto = { - decryptEvent: async (_ev: MatrixEvent): Promise => { + decryptEvent: async (_ev): Promise => { throw new Error("can't decrypt"); }, - }; - - // @ts-ignore `mockCrypto` is not a `CryptoBackend`, which is an internal type in the js-sdk + } as Parameters[0]; await mxEvent.attemptDecryption(mockCrypto); const { container } = getComponent(); diff --git a/test/test-utils/test-utils.ts b/test/test-utils/test-utils.ts index c946d7a46b4..fd4a83e2082 100644 --- a/test/test-utils/test-utils.ts +++ b/test/test-utils/test-utils.ts @@ -440,10 +440,8 @@ export async function mkEncryptedEvent(opts: { }; const mockCrypto = { - decryptEvent: async (_ev: MatrixEvent): Promise => decryptionResult, - }; - - // @ts-ignore `mockCrypto` is not a `CryptoBackend`, which is an internal type in the js-sdk + decryptEvent: async (_ev): Promise => decryptionResult, + } as Parameters[0]; await mxEvent.attemptDecryption(mockCrypto); return mxEvent; }