Skip to content
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

Element R: Bump matrix-rust-sdk-crypto-wasm to version 4.0.0 #4021

Merged
merged 7 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
],
"dependencies": {
"@babel/runtime": "^7.12.5",
"@matrix-org/matrix-sdk-crypto-wasm": "^3.6.0",
"@matrix-org/matrix-sdk-crypto-wasm": "^4.0.0",
"another-json": "^0.2.0",
"bs58": "^5.0.0",
"content-type": "^1.0.4",
Expand Down
12 changes: 6 additions & 6 deletions spec/unit/rust-crypto/rust-crypto.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe("initRustCrypto", () => {
jest.spyOn(StoreHandle, "open").mockResolvedValue(mockStore);

const testOlmMachine = makeTestOlmMachine();
jest.spyOn(OlmMachine, "init_from_store").mockResolvedValue(testOlmMachine);
jest.spyOn(OlmMachine, "initFromStore").mockResolvedValue(testOlmMachine);

await initRustCrypto({
logger,
Expand All @@ -114,15 +114,15 @@ describe("initRustCrypto", () => {
});

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

it("suppresses the storePassphrase if storePrefix is unset", async () => {
const mockStore = { free: jest.fn() } as unknown as StoreHandle;
jest.spyOn(StoreHandle, "open").mockResolvedValue(mockStore);

const testOlmMachine = makeTestOlmMachine();
jest.spyOn(OlmMachine, "init_from_store").mockResolvedValue(testOlmMachine);
jest.spyOn(OlmMachine, "initFromStore").mockResolvedValue(testOlmMachine);

await initRustCrypto({
logger,
Expand All @@ -136,15 +136,15 @@ describe("initRustCrypto", () => {
});

expect(StoreHandle.open).toHaveBeenCalledWith(undefined, undefined);
expect(OlmMachine.init_from_store).toHaveBeenCalledWith(expect.anything(), expect.anything(), mockStore);
expect(OlmMachine.initFromStore).toHaveBeenCalledWith(expect.anything(), expect.anything(), mockStore);
});

it("Should get secrets from inbox on start", async () => {
const mockStore = { free: jest.fn() } as unknown as StoreHandle;
jest.spyOn(StoreHandle, "open").mockResolvedValue(mockStore);

const testOlmMachine = makeTestOlmMachine();
jest.spyOn(OlmMachine, "init_from_store").mockResolvedValue(testOlmMachine);
jest.spyOn(OlmMachine, "initFromStore").mockResolvedValue(testOlmMachine);

await initRustCrypto({
logger,
Expand Down Expand Up @@ -189,7 +189,7 @@ describe("initRustCrypto", () => {
jest.spyOn(Migration, "migrateMegolmSessions").mockResolvedValue(undefined);

const testOlmMachine = makeTestOlmMachine();
jest.spyOn(OlmMachine, "init_from_store").mockResolvedValue(testOlmMachine);
jest.spyOn(OlmMachine, "initFromStore").mockResolvedValue(testOlmMachine);

fetchMock.get("path:/_matrix/client/v3/room_keys/version", { version: "45" });

Expand Down
5 changes: 4 additions & 1 deletion src/rust-crypto/KeyClaimManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ export class KeyClaimManager {
throw new Error(`Cannot ensure Olm sessions: shutting down`);
}
logger.info("Checking for missing Olm sessions");
const claimRequest = await this.olmMachine.getMissingSessions(userList);
// By passing the userId array to rust we transfer ownership of the items to rust, this
// will drop them on the JS side as soon as the method is called.
BillCarsonFr marked this conversation as resolved.
Show resolved Hide resolved
// As we haven't created the `userList` let's clone it to not break the caller from re-using it.
BillCarsonFr marked this conversation as resolved.
Show resolved Hide resolved
const claimRequest = await this.olmMachine.getMissingSessions(userList.map((u) => u.clone()));
if (claimRequest) {
logger.info("Making /keys/claim request");
await this.outgoingRequestProcessor.makeOutgoingRequest(claimRequest);
Expand Down
1 change: 1 addition & 0 deletions src/rust-crypto/RoomEncryptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ export class RoomEncryptor {
await logDuration(this.prefixedLogger, "shareRoomKey", async () => {
const shareMessages: ToDeviceRequest[] = await this.olmMachine.shareRoomKey(
new RoomId(this.room.roomId),
// safe to pass without cloning, as it's not reused here (before or after)
userList,
rustEncryptionSettings,
);
Expand Down
2 changes: 1 addition & 1 deletion src/rust-crypto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ async function initOlmMachine(
): Promise<RustCrypto> {
logger.debug("Init OlmMachine");

const olmMachine = await RustSdkCryptoJs.OlmMachine.init_from_store(
const olmMachine = await RustSdkCryptoJs.OlmMachine.initFromStore(
new RustSdkCryptoJs.UserId(userId),
new RustSdkCryptoJs.DeviceId(deviceId),
storeHandle,
Expand Down
7 changes: 5 additions & 2 deletions src/rust-crypto/rust-crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,14 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, RustCryptoEv
/* make sure we have an *up-to-date* idea of the user's cross-signing keys. This is important, because if we
* return "false" here, we will end up generating new cross-signing keys and replacing the existing ones.
*/
const request = this.olmMachine.queryKeysForUsers([rustTrackedUser]);
const request = this.olmMachine.queryKeysForUsers(
// clone as rust layer will take ownership and it's reused later
[rustTrackedUser.clone()],
);
await this.outgoingRequestProcessor.makeOutgoingRequest(request);
}
// rust layer will take ownership of rustTrackedUser and drops it from the JS side.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this is helpful?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

const userIdentity = await this.olmMachine.getIdentity(rustTrackedUser);
userIdentity?.free();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still required, I think

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added back

return userIdentity !== undefined;
} else if (downloadUncached) {
// Download the cross signing keys and check if the master key is available
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1674,10 +1674,10 @@
"@jridgewell/resolve-uri" "^3.1.0"
"@jridgewell/sourcemap-codec" "^1.4.14"

"@matrix-org/matrix-sdk-crypto-wasm@^3.6.0":
version "3.6.0"
resolved "https://registry.yarnpkg.com/@matrix-org/matrix-sdk-crypto-wasm/-/matrix-sdk-crypto-wasm-3.6.0.tgz#385aa579d7b7546d85c9b20bf6ba780f799bdda3"
integrity sha512-fvuYczcp/r/MOkOAUbK+tMaTerEe7/QHGQcRJz3W3JuEma0YN59d35zTBlts7EkN6Ichw1vLSyM+GkcbuosuyA==
"@matrix-org/matrix-sdk-crypto-wasm@^4.0.0":
version "4.0.0"
resolved "https://registry.yarnpkg.com/@matrix-org/matrix-sdk-crypto-wasm/-/matrix-sdk-crypto-wasm-4.0.0.tgz#b33bae9c418c5516d0dbce29662c6db803003626"
integrity sha512-a883HchJViPo6ukM0fEDmBgvMI6lWEujqAjMZgwaKEYNZTPgezN5PQvSNz2d+b96/R1y4QOC71zXM1yNylXA6Q==

"@matrix-org/[email protected]":
version "3.2.15"
Expand Down
Loading