diff --git a/spec/unit/rust-crypto.spec.ts b/spec/unit/rust-crypto.spec.ts index 81128d9d025..fe98dedbb8a 100644 --- a/spec/unit/rust-crypto.spec.ts +++ b/spec/unit/rust-crypto.spec.ts @@ -19,6 +19,7 @@ import { IDBFactory } from "fake-indexeddb"; import { RustCrypto } from "../../src/rust-crypto/rust-crypto"; import { initRustCrypto } from "../../src/rust-crypto"; +import { IHttpOpts, MatrixHttpApi } from "../../src"; afterEach(() => { // reset fake-indexeddb after each test, to make sure we don't leak connections @@ -34,7 +35,8 @@ describe("RustCrypto", () => { let rustCrypto: RustCrypto; beforeEach(async () => { - rustCrypto = (await initRustCrypto(TEST_USER, TEST_DEVICE_ID)) as RustCrypto; + const mockHttpApi = {} as MatrixHttpApi; + rustCrypto = (await initRustCrypto(mockHttpApi, TEST_USER, TEST_DEVICE_ID)) as RustCrypto; }); describe(".exportRoomKeys", () => { diff --git a/src/client.ts b/src/client.ts index 3430c008eb2..ae42103f26e 100644 --- a/src/client.ts +++ b/src/client.ts @@ -2148,7 +2148,7 @@ export class MatrixClient extends TypedEventEmitter { +export async function initRustCrypto( + http: MatrixHttpApi, + userId: string, + deviceId: string, +): Promise { // initialise the rust matrix-sdk-crypto-js, if it hasn't already been done await RustSdkCryptoJs.initAsync(); @@ -34,7 +39,7 @@ export async function initRustCrypto(userId: string, deviceId: string): Promise< // TODO: use the pickle key for the passphrase const olmMachine = await RustSdkCryptoJs.OlmMachine.initialize(u, d, RUST_SDK_STORE_PREFIX, "test pass"); - const rustCrypto = new RustCrypto(olmMachine, userId, deviceId); + const rustCrypto = new RustCrypto(olmMachine, http, userId, deviceId); logger.info("Completed rust crypto-sdk setup"); return rustCrypto; diff --git a/src/rust-crypto/rust-crypto.ts b/src/rust-crypto/rust-crypto.ts index b28b8b858c8..48b5e795108 100644 --- a/src/rust-crypto/rust-crypto.ts +++ b/src/rust-crypto/rust-crypto.ts @@ -19,6 +19,7 @@ import * as RustSdkCryptoJs from "@matrix-org/matrix-sdk-crypto-js"; import type { IEventDecryptionResult, IMegolmSessionData } from "../@types/crypto"; import { MatrixEvent } from "../models/event"; import { CryptoBackend, OnSyncCompletedData } from "../common-crypto/CryptoBackend"; +import { IHttpOpts, MatrixHttpApi } from "../http-api"; // import { logger } from "../logger"; @@ -32,7 +33,12 @@ export class RustCrypto implements CryptoBackend { /** whether stop() has been called */ private stopped = false; - public constructor(private readonly olmMachine: RustSdkCryptoJs.OlmMachine, _userId: string, _deviceId: string) {} + public constructor( + private readonly olmMachine: RustSdkCryptoJs.OlmMachine, + private readonly http: MatrixHttpApi, + _userId: string, + _deviceId: string, + ) {} public stop(): void { // stop() may be called multiple times, but attempting to close() the OlmMachine twice