Skip to content

Commit 0ebea8b

Browse files
committed
Pass HttpApi into RustCrypto
... so that we can make outbound requests.
1 parent 6168ced commit 0ebea8b

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

spec/unit/rust-crypto.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { IDBFactory } from "fake-indexeddb";
1919

2020
import { RustCrypto } from "../../src/rust-crypto/rust-crypto";
2121
import { initRustCrypto } from "../../src/rust-crypto";
22+
import { IHttpOpts, MatrixHttpApi } from "../../src";
2223

2324
afterEach(() => {
2425
// reset fake-indexeddb after each test, to make sure we don't leak connections
@@ -34,7 +35,8 @@ describe("RustCrypto", () => {
3435
let rustCrypto: RustCrypto;
3536

3637
beforeEach(async () => {
37-
rustCrypto = (await initRustCrypto(TEST_USER, TEST_DEVICE_ID)) as RustCrypto;
38+
const mockHttpApi = {} as MatrixHttpApi<IHttpOpts>;
39+
rustCrypto = (await initRustCrypto(mockHttpApi, TEST_USER, TEST_DEVICE_ID)) as RustCrypto;
3840
});
3941

4042
describe(".exportRoomKeys", () => {

src/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2148,7 +2148,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
21482148
// importing rust-crypto will download the webassembly, so we delay it until we know it will be
21492149
// needed.
21502150
const RustCrypto = await import("./rust-crypto");
2151-
this.cryptoBackend = await RustCrypto.initRustCrypto(userId, deviceId);
2151+
this.cryptoBackend = await RustCrypto.initRustCrypto(this.http, userId, deviceId);
21522152
}
21532153

21542154
/**

src/rust-crypto/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,13 @@ import { RustCrypto } from "./rust-crypto";
2020
import { logger } from "../logger";
2121
import { CryptoBackend } from "../common-crypto/CryptoBackend";
2222
import { RUST_SDK_STORE_PREFIX } from "./constants";
23+
import { IHttpOpts, MatrixHttpApi } from "../http-api";
2324

24-
export async function initRustCrypto(userId: string, deviceId: string): Promise<CryptoBackend> {
25+
export async function initRustCrypto(
26+
http: MatrixHttpApi<IHttpOpts>,
27+
userId: string,
28+
deviceId: string,
29+
): Promise<CryptoBackend> {
2530
// initialise the rust matrix-sdk-crypto-js, if it hasn't already been done
2631
await RustSdkCryptoJs.initAsync();
2732

@@ -34,7 +39,7 @@ export async function initRustCrypto(userId: string, deviceId: string): Promise<
3439

3540
// TODO: use the pickle key for the passphrase
3641
const olmMachine = await RustSdkCryptoJs.OlmMachine.initialize(u, d, RUST_SDK_STORE_PREFIX, "test pass");
37-
const rustCrypto = new RustCrypto(olmMachine, userId, deviceId);
42+
const rustCrypto = new RustCrypto(olmMachine, http, userId, deviceId);
3843

3944
logger.info("Completed rust crypto-sdk setup");
4045
return rustCrypto;

src/rust-crypto/rust-crypto.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import * as RustSdkCryptoJs from "@matrix-org/matrix-sdk-crypto-js";
1919
import type { IEventDecryptionResult, IMegolmSessionData } from "../@types/crypto";
2020
import { MatrixEvent } from "../models/event";
2121
import { CryptoBackend, OnSyncCompletedData } from "../common-crypto/CryptoBackend";
22+
import { IHttpOpts, MatrixHttpApi } from "../http-api";
2223

2324
// import { logger } from "../logger";
2425

@@ -32,7 +33,12 @@ export class RustCrypto implements CryptoBackend {
3233
/** whether stop() has been called */
3334
private stopped = false;
3435

35-
public constructor(private readonly olmMachine: RustSdkCryptoJs.OlmMachine, _userId: string, _deviceId: string) {}
36+
public constructor(
37+
private readonly olmMachine: RustSdkCryptoJs.OlmMachine,
38+
private readonly http: MatrixHttpApi<IHttpOpts>,
39+
_userId: string,
40+
_deviceId: string,
41+
) {}
3642

3743
public stop(): void {
3844
// stop() may be called multiple times, but attempting to close() the OlmMachine twice

0 commit comments

Comments
 (0)