Skip to content

Use the logger associated with MatrixClient in rust sdk #4918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions spec/unit/rust-crypto/rust-crypto.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ describe("initRustCrypto", () => {
storePassphrase: "storePassphrase",
});

expect(StoreHandle.open).toHaveBeenCalledWith("storePrefix", "storePassphrase");
expect(OlmMachine.initFromStore).toHaveBeenCalledWith(expect.anything(), expect.anything(), mockStore);
expect(StoreHandle.open).toHaveBeenCalledWith("storePrefix", "storePassphrase", logger);
expect(OlmMachine.initFromStore).toHaveBeenCalledWith(expect.anything(), expect.anything(), mockStore, logger);
});

it("passes through the store params (key)", async () => {
Expand All @@ -154,8 +154,8 @@ describe("initRustCrypto", () => {
storeKey: storeKey,
});

expect(StoreHandle.openWithKey).toHaveBeenCalledWith("storePrefix", storeKey);
expect(OlmMachine.initFromStore).toHaveBeenCalledWith(expect.anything(), expect.anything(), mockStore);
expect(StoreHandle.openWithKey).toHaveBeenCalledWith("storePrefix", storeKey, logger);
expect(OlmMachine.initFromStore).toHaveBeenCalledWith(expect.anything(), expect.anything(), mockStore, logger);
});

it("suppresses the storePassphrase and storeKey if storePrefix is unset", async () => {
Expand All @@ -178,8 +178,8 @@ describe("initRustCrypto", () => {
storePassphrase: "storePassphrase",
});

expect(StoreHandle.open).toHaveBeenCalledWith();
expect(OlmMachine.initFromStore).toHaveBeenCalledWith(expect.anything(), expect.anything(), mockStore);
expect(StoreHandle.open).toHaveBeenCalledWith(null, null, logger);
expect(OlmMachine.initFromStore).toHaveBeenCalledWith(expect.anything(), expect.anything(), mockStore, logger);
});

it("Should get secrets from inbox on start", async () => {
Expand Down Expand Up @@ -278,6 +278,7 @@ describe("initRustCrypto", () => {
expect.any(BaseMigrationData),
new Uint8Array(Buffer.from(PICKLE_KEY)),
mockStore,
logger,
);
const data = mocked(Migration.migrateBaseData).mock.calls[0][0];
expect(data.pickledAccount).toEqual("not a real account");
Expand All @@ -294,6 +295,7 @@ describe("initRustCrypto", () => {
expect.any(Array),
new Uint8Array(Buffer.from(PICKLE_KEY)),
mockStore,
logger,
);
// First call should have 50 entries; second should have 10
const sessions1: PickledSession[] = mocked(Migration.migrateOlmSessions).mock.calls[0][0];
Expand All @@ -316,6 +318,7 @@ describe("initRustCrypto", () => {
expect.any(Array),
new Uint8Array(Buffer.from(PICKLE_KEY)),
mockStore,
logger,
);
// First call should have 50 entries; second should have 10
const megolmSessions1: PickledInboundGroupSession[] = mocked(Migration.migrateMegolmSessions).mock
Expand Down Expand Up @@ -424,6 +427,7 @@ describe("initRustCrypto", () => {
expect.any(Array),
new Uint8Array(Buffer.from(PICKLE_KEY)),
mockStore,
logger,
);
const megolmSessions: PickledInboundGroupSession[] = mocked(Migration.migrateMegolmSessions).mock
.calls[0][0];
Expand Down
10 changes: 4 additions & 6 deletions src/rust-crypto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,16 @@
logger.debug("Initialising Rust crypto-sdk WASM artifact");
await RustSdkCryptoJs.initAsync();

// enable tracing in the rust-sdk
new RustSdkCryptoJs.Tracing(RustSdkCryptoJs.LoggerLevel.Debug).turnOn();

logger.debug("Opening Rust CryptoStore");
let storeHandle;
if (args.storePrefix) {
if (args.storeKey) {
storeHandle = await StoreHandle.openWithKey(args.storePrefix, args.storeKey);
storeHandle = await StoreHandle.openWithKey(args.storePrefix, args.storeKey, logger);

Check failure on line 105 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / JSDoc Checker

Expected 2 arguments, but got 3.

Check failure on line 105 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node lts/*)

Expected 2 arguments, but got 3.

Check failure on line 105 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / Analyse Dead Code

Expected 2 arguments, but got 3.

Check failure on line 105 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / ESLint

Expected 2 arguments, but got 3.

Check failure on line 105 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

Expected 2 arguments, but got 3.

Check failure on line 105 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node lts/*)

Expected 2 arguments, but got 3.

Check failure on line 105 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / Node.js example

Expected 2 arguments, but got 3.

Check failure on line 105 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / Workflow Lint

Expected 2 arguments, but got 3.

Check failure on line 105 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node 22)

Expected 2 arguments, but got 3.

Check failure on line 105 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node 22)

Expected 2 arguments, but got 3.
} else {
storeHandle = await StoreHandle.open(args.storePrefix, args.storePassphrase);
storeHandle = await StoreHandle.open(args.storePrefix, args.storePassphrase, logger);

Check failure on line 107 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / JSDoc Checker

Expected 0-2 arguments, but got 3.

Check failure on line 107 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node lts/*)

Expected 0-2 arguments, but got 3.

Check failure on line 107 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / Analyse Dead Code

Expected 0-2 arguments, but got 3.

Check failure on line 107 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / ESLint

Expected 0-2 arguments, but got 3.

Check failure on line 107 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

Expected 0-2 arguments, but got 3.

Check failure on line 107 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node lts/*)

Expected 0-2 arguments, but got 3.

Check failure on line 107 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / Node.js example

Expected 0-2 arguments, but got 3.

Check failure on line 107 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / Workflow Lint

Expected 0-2 arguments, but got 3.

Check failure on line 107 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node 22)

Expected 0-2 arguments, but got 3.

Check failure on line 107 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node 22)

Expected 0-2 arguments, but got 3.
}
} else {
storeHandle = await StoreHandle.open();
storeHandle = await StoreHandle.open(null, null, logger);

Check failure on line 110 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / JSDoc Checker

Expected 0-2 arguments, but got 3.

Check failure on line 110 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node lts/*)

Expected 0-2 arguments, but got 3.

Check failure on line 110 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / Analyse Dead Code

Expected 0-2 arguments, but got 3.

Check failure on line 110 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / ESLint

Expected 0-2 arguments, but got 3.

Check failure on line 110 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

Expected 0-2 arguments, but got 3.

Check failure on line 110 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node lts/*)

Expected 0-2 arguments, but got 3.

Check failure on line 110 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / Node.js example

Expected 0-2 arguments, but got 3.

Check failure on line 110 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / Workflow Lint

Expected 0-2 arguments, but got 3.

Check failure on line 110 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node 22)

Expected 0-2 arguments, but got 3.

Check failure on line 110 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node 22)

Expected 0-2 arguments, but got 3.
}

if (args.legacyCryptoStore) {
Expand Down Expand Up @@ -155,6 +152,7 @@
new RustSdkCryptoJs.UserId(userId),
new RustSdkCryptoJs.DeviceId(deviceId),
storeHandle,
logger,

Check failure on line 155 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / JSDoc Checker

Expected 3 arguments, but got 4.

Check failure on line 155 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node lts/*)

Expected 3 arguments, but got 4.

Check failure on line 155 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / Analyse Dead Code

Expected 3 arguments, but got 4.

Check failure on line 155 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / ESLint

Expected 3 arguments, but got 4.

Check failure on line 155 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

Expected 3 arguments, but got 4.

Check failure on line 155 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node lts/*)

Expected 3 arguments, but got 4.

Check failure on line 155 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / Node.js example

Expected 3 arguments, but got 4.

Check failure on line 155 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / Workflow Lint

Expected 3 arguments, but got 4.

Check failure on line 155 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node 22)

Expected 3 arguments, but got 4.

Check failure on line 155 in src/rust-crypto/index.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node 22)

Expected 3 arguments, but got 4.
);

// A final migration step, now that we have an OlmMachine.
Expand Down
9 changes: 3 additions & 6 deletions src/rust-crypto/libolm_migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@
// initialise the rust matrix-sdk-crypto-wasm, if it hasn't already been done
await RustSdkCryptoJs.initAsync();

// enable tracing in the rust-sdk
new RustSdkCryptoJs.Tracing(RustSdkCryptoJs.LoggerLevel.Debug).turnOn();

if (!(await legacyStore.containsData())) {
// This store was never used. Nothing to migrate.
return;
Expand Down Expand Up @@ -230,7 +227,7 @@
pickleKey,
"user_signing",
);
await RustSdkCryptoJs.Migration.migrateBaseData(migrationData, pickleKey, storeHandle);
await RustSdkCryptoJs.Migration.migrateBaseData(migrationData, pickleKey, storeHandle, logger);

Check failure on line 230 in src/rust-crypto/libolm_migration.ts

View workflow job for this annotation

GitHub Actions / JSDoc Checker

Expected 3 arguments, but got 4.

Check failure on line 230 in src/rust-crypto/libolm_migration.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node lts/*)

Expected 3 arguments, but got 4.

Check failure on line 230 in src/rust-crypto/libolm_migration.ts

View workflow job for this annotation

GitHub Actions / Analyse Dead Code

Expected 3 arguments, but got 4.

Check failure on line 230 in src/rust-crypto/libolm_migration.ts

View workflow job for this annotation

GitHub Actions / ESLint

Expected 3 arguments, but got 4.

Check failure on line 230 in src/rust-crypto/libolm_migration.ts

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

Expected 3 arguments, but got 4.

Check failure on line 230 in src/rust-crypto/libolm_migration.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node lts/*)

Expected 3 arguments, but got 4.

Check failure on line 230 in src/rust-crypto/libolm_migration.ts

View workflow job for this annotation

GitHub Actions / Node.js example

Expected 3 arguments, but got 4.

Check failure on line 230 in src/rust-crypto/libolm_migration.ts

View workflow job for this annotation

GitHub Actions / Workflow Lint

Expected 3 arguments, but got 4.

Check failure on line 230 in src/rust-crypto/libolm_migration.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node 22)

Expected 3 arguments, but got 4.

Check failure on line 230 in src/rust-crypto/libolm_migration.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node 22)

Expected 3 arguments, but got 4.
}

async function countOlmSessions(logger: Logger, legacyStore: CryptoStore): Promise<number> {
Expand Down Expand Up @@ -269,7 +266,7 @@
migrationData.push(pickledSession);
}

await RustSdkCryptoJs.Migration.migrateOlmSessions(migrationData, pickleKey, storeHandle);
await RustSdkCryptoJs.Migration.migrateOlmSessions(migrationData, pickleKey, storeHandle, logger);

Check failure on line 269 in src/rust-crypto/libolm_migration.ts

View workflow job for this annotation

GitHub Actions / JSDoc Checker

Expected 3 arguments, but got 4.

Check failure on line 269 in src/rust-crypto/libolm_migration.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node lts/*)

Expected 3 arguments, but got 4.

Check failure on line 269 in src/rust-crypto/libolm_migration.ts

View workflow job for this annotation

GitHub Actions / Analyse Dead Code

Expected 3 arguments, but got 4.

Check failure on line 269 in src/rust-crypto/libolm_migration.ts

View workflow job for this annotation

GitHub Actions / ESLint

Expected 3 arguments, but got 4.

Check failure on line 269 in src/rust-crypto/libolm_migration.ts

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

Expected 3 arguments, but got 4.

Check failure on line 269 in src/rust-crypto/libolm_migration.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node lts/*)

Expected 3 arguments, but got 4.

Check failure on line 269 in src/rust-crypto/libolm_migration.ts

View workflow job for this annotation

GitHub Actions / Node.js example

Expected 3 arguments, but got 4.

Check failure on line 269 in src/rust-crypto/libolm_migration.ts

View workflow job for this annotation

GitHub Actions / Workflow Lint

Expected 3 arguments, but got 4.

Check failure on line 269 in src/rust-crypto/libolm_migration.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node 22)

Expected 3 arguments, but got 4.

Check failure on line 269 in src/rust-crypto/libolm_migration.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node 22)

Expected 3 arguments, but got 4.
await legacyStore.deleteEndToEndSessionsBatch(batch);
onBatchDone(batch.length);
}
Expand Down Expand Up @@ -343,7 +340,7 @@
migrationData.push(pickledSession);
}

await RustSdkCryptoJs.Migration.migrateMegolmSessions(migrationData, pickleKey, storeHandle);
await RustSdkCryptoJs.Migration.migrateMegolmSessions(migrationData, pickleKey, storeHandle, logger);

Check failure on line 343 in src/rust-crypto/libolm_migration.ts

View workflow job for this annotation

GitHub Actions / JSDoc Checker

Expected 3 arguments, but got 4.

Check failure on line 343 in src/rust-crypto/libolm_migration.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node lts/*)

Expected 3 arguments, but got 4.

Check failure on line 343 in src/rust-crypto/libolm_migration.ts

View workflow job for this annotation

GitHub Actions / Analyse Dead Code

Expected 3 arguments, but got 4.

Check failure on line 343 in src/rust-crypto/libolm_migration.ts

View workflow job for this annotation

GitHub Actions / ESLint

Expected 3 arguments, but got 4.

Check failure on line 343 in src/rust-crypto/libolm_migration.ts

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

Expected 3 arguments, but got 4.

Check failure on line 343 in src/rust-crypto/libolm_migration.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node lts/*)

Expected 3 arguments, but got 4.

Check failure on line 343 in src/rust-crypto/libolm_migration.ts

View workflow job for this annotation

GitHub Actions / Node.js example

Expected 3 arguments, but got 4.

Check failure on line 343 in src/rust-crypto/libolm_migration.ts

View workflow job for this annotation

GitHub Actions / Workflow Lint

Expected 3 arguments, but got 4.

Check failure on line 343 in src/rust-crypto/libolm_migration.ts

View workflow job for this annotation

GitHub Actions / Jest [integ] (Node 22)

Expected 3 arguments, but got 4.

Check failure on line 343 in src/rust-crypto/libolm_migration.ts

View workflow job for this annotation

GitHub Actions / Jest [unit] (Node 22)

Expected 3 arguments, but got 4.
await legacyStore.deleteEndToEndInboundGroupSessionsBatch(batch);
onBatchDone(batch.length);
}
Expand Down
Loading