1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-07-30 04:23:07 +03:00

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

* bump wasm bindings version 4.0.0

* fix test compilation with initFromStore

* Fix test due to change in wasm handling of Vec<>

* review: Better doc

Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>

* review: Better doc

Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>

* review: revert userIdentity free removal

---------

Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
This commit is contained in:
Valere
2024-01-22 16:17:53 +01:00
committed by GitHub
parent 2337d5a7af
commit b10a804a03
8 changed files with 32 additions and 17 deletions

View File

@ -52,7 +52,7 @@
], ],
"dependencies": { "dependencies": {
"@babel/runtime": "^7.12.5", "@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", "another-json": "^0.2.0",
"bs58": "^5.0.0", "bs58": "^5.0.0",
"content-type": "^1.0.4", "content-type": "^1.0.4",

View File

@ -97,7 +97,10 @@ describe("KeyClaimManager", () => {
await keyClaimManager.ensureSessionsForUsers(new LogSpan(logger, "test"), [u1, u2]); await keyClaimManager.ensureSessionsForUsers(new LogSpan(logger, "test"), [u1, u2]);
// check that all the calls were made // check that all the calls were made
expect(olmMachine.getMissingSessions).toHaveBeenCalledWith([u1, u2]); // We can't use directly toHaveBeenCalledWith because the UserId are cloned in the process.
const calledWith = olmMachine.getMissingSessions.mock.calls[0][0].map((u) => u.toString());
expect(calledWith).toEqual([u1.toString(), u2.toString()]);
expect(fetchMock).toHaveFetched("https://example.com/_matrix/client/v3/keys/claim", { expect(fetchMock).toHaveFetched("https://example.com/_matrix/client/v3/keys/claim", {
method: "POST", method: "POST",
body: { k1: "v1" }, body: { k1: "v1" },
@ -135,7 +138,10 @@ describe("KeyClaimManager", () => {
// at this point, there should have been a single call to getMissingSessions, and a single fetch; and neither // at this point, there should have been a single call to getMissingSessions, and a single fetch; and neither
// call to ensureSessionsAsUsers should have completed // call to ensureSessionsAsUsers should have completed
expect(olmMachine.getMissingSessions).toHaveBeenCalledWith([u1]); // check that all the calls were made
// We can't use directly toHaveBeenCalledWith because the UserId are cloned in the process.
const calledWith = olmMachine.getMissingSessions.mock.calls[0][0].map((u) => u.toString());
expect(calledWith).toEqual([u1.toString()]);
expect(olmMachine.getMissingSessions).toHaveBeenCalledTimes(1); expect(olmMachine.getMissingSessions).toHaveBeenCalledTimes(1);
expect(fetchMock).toHaveBeenCalledTimes(1); expect(fetchMock).toHaveBeenCalledTimes(1);
expect(req1Resolved).toBe(false); expect(req1Resolved).toBe(false);
@ -147,7 +153,9 @@ describe("KeyClaimManager", () => {
resolveMarkRequestAsSentCallback = await markRequestAsSentPromise; resolveMarkRequestAsSentCallback = await markRequestAsSentPromise;
// the first request should now have completed, and we should have more calls and fetches // the first request should now have completed, and we should have more calls and fetches
expect(olmMachine.getMissingSessions).toHaveBeenCalledWith([u2]); // We can't use directly toHaveBeenCalledWith because the UserId are cloned in the process.
const calledWith2 = olmMachine.getMissingSessions.mock.calls[1][0].map((u) => u.toString());
expect(calledWith2).toEqual([u2.toString()]);
expect(olmMachine.getMissingSessions).toHaveBeenCalledTimes(2); expect(olmMachine.getMissingSessions).toHaveBeenCalledTimes(2);
expect(fetchMock).toHaveBeenCalledTimes(2); expect(fetchMock).toHaveBeenCalledTimes(2);
expect(req1Resolved).toBe(true); expect(req1Resolved).toBe(true);

View File

@ -100,7 +100,7 @@ describe("initRustCrypto", () => {
jest.spyOn(StoreHandle, "open").mockResolvedValue(mockStore); jest.spyOn(StoreHandle, "open").mockResolvedValue(mockStore);
const testOlmMachine = makeTestOlmMachine(); const testOlmMachine = makeTestOlmMachine();
jest.spyOn(OlmMachine, "init_from_store").mockResolvedValue(testOlmMachine); jest.spyOn(OlmMachine, "initFromStore").mockResolvedValue(testOlmMachine);
await initRustCrypto({ await initRustCrypto({
logger, logger,
@ -114,7 +114,7 @@ describe("initRustCrypto", () => {
}); });
expect(StoreHandle.open).toHaveBeenCalledWith("storePrefix", "storePassphrase"); 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 () => { it("suppresses the storePassphrase if storePrefix is unset", async () => {
@ -122,7 +122,7 @@ describe("initRustCrypto", () => {
jest.spyOn(StoreHandle, "open").mockResolvedValue(mockStore); jest.spyOn(StoreHandle, "open").mockResolvedValue(mockStore);
const testOlmMachine = makeTestOlmMachine(); const testOlmMachine = makeTestOlmMachine();
jest.spyOn(OlmMachine, "init_from_store").mockResolvedValue(testOlmMachine); jest.spyOn(OlmMachine, "initFromStore").mockResolvedValue(testOlmMachine);
await initRustCrypto({ await initRustCrypto({
logger, logger,
@ -136,7 +136,7 @@ describe("initRustCrypto", () => {
}); });
expect(StoreHandle.open).toHaveBeenCalledWith(undefined, undefined); 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 () => { it("Should get secrets from inbox on start", async () => {
@ -144,7 +144,7 @@ describe("initRustCrypto", () => {
jest.spyOn(StoreHandle, "open").mockResolvedValue(mockStore); jest.spyOn(StoreHandle, "open").mockResolvedValue(mockStore);
const testOlmMachine = makeTestOlmMachine(); const testOlmMachine = makeTestOlmMachine();
jest.spyOn(OlmMachine, "init_from_store").mockResolvedValue(testOlmMachine); jest.spyOn(OlmMachine, "initFromStore").mockResolvedValue(testOlmMachine);
await initRustCrypto({ await initRustCrypto({
logger, logger,
@ -189,7 +189,7 @@ describe("initRustCrypto", () => {
jest.spyOn(Migration, "migrateMegolmSessions").mockResolvedValue(undefined); jest.spyOn(Migration, "migrateMegolmSessions").mockResolvedValue(undefined);
const testOlmMachine = makeTestOlmMachine(); 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" }); fetchMock.get("path:/_matrix/client/v3/room_keys/version", { version: "45" });

View File

@ -73,7 +73,10 @@ export class KeyClaimManager {
throw new Error(`Cannot ensure Olm sessions: shutting down`); throw new Error(`Cannot ensure Olm sessions: shutting down`);
} }
logger.info("Checking for missing Olm sessions"); 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, causing
// them to be invalidated on the JS side as soon as the method is called.
// As we haven't created the `userList` let's clone the users, to not break the caller from re-using it.
const claimRequest = await this.olmMachine.getMissingSessions(userList.map((u) => u.clone()));
if (claimRequest) { if (claimRequest) {
logger.info("Making /keys/claim request"); logger.info("Making /keys/claim request");
await this.outgoingRequestProcessor.makeOutgoingRequest(claimRequest); await this.outgoingRequestProcessor.makeOutgoingRequest(claimRequest);

View File

@ -258,6 +258,7 @@ export class RoomEncryptor {
await logDuration(this.prefixedLogger, "shareRoomKey", async () => { await logDuration(this.prefixedLogger, "shareRoomKey", async () => {
const shareMessages: ToDeviceRequest[] = await this.olmMachine.shareRoomKey( const shareMessages: ToDeviceRequest[] = await this.olmMachine.shareRoomKey(
new RoomId(this.room.roomId), new RoomId(this.room.roomId),
// safe to pass without cloning, as it's not reused here (before or after)
userList, userList,
rustEncryptionSettings, rustEncryptionSettings,
); );

View File

@ -131,7 +131,7 @@ async function initOlmMachine(
): Promise<RustCrypto> { ): Promise<RustCrypto> {
logger.debug("Init OlmMachine"); logger.debug("Init OlmMachine");
const olmMachine = await RustSdkCryptoJs.OlmMachine.init_from_store( const olmMachine = await RustSdkCryptoJs.OlmMachine.initFromStore(
new RustSdkCryptoJs.UserId(userId), new RustSdkCryptoJs.UserId(userId),
new RustSdkCryptoJs.DeviceId(deviceId), new RustSdkCryptoJs.DeviceId(deviceId),
storeHandle, storeHandle,

View File

@ -359,7 +359,10 @@ 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 /* 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. * 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); await this.outgoingRequestProcessor.makeOutgoingRequest(request);
} }
const userIdentity = await this.olmMachine.getIdentity(rustTrackedUser); const userIdentity = await this.olmMachine.getIdentity(rustTrackedUser);

View File

@ -1674,10 +1674,10 @@
"@jridgewell/resolve-uri" "^3.1.0" "@jridgewell/resolve-uri" "^3.1.0"
"@jridgewell/sourcemap-codec" "^1.4.14" "@jridgewell/sourcemap-codec" "^1.4.14"
"@matrix-org/matrix-sdk-crypto-wasm@^3.6.0": "@matrix-org/matrix-sdk-crypto-wasm@^4.0.0":
version "3.6.0" version "4.0.0"
resolved "https://registry.yarnpkg.com/@matrix-org/matrix-sdk-crypto-wasm/-/matrix-sdk-crypto-wasm-3.6.0.tgz#385aa579d7b7546d85c9b20bf6ba780f799bdda3" resolved "https://registry.yarnpkg.com/@matrix-org/matrix-sdk-crypto-wasm/-/matrix-sdk-crypto-wasm-4.0.0.tgz#b33bae9c418c5516d0dbce29662c6db803003626"
integrity sha512-fvuYczcp/r/MOkOAUbK+tMaTerEe7/QHGQcRJz3W3JuEma0YN59d35zTBlts7EkN6Ichw1vLSyM+GkcbuosuyA== integrity sha512-a883HchJViPo6ukM0fEDmBgvMI6lWEujqAjMZgwaKEYNZTPgezN5PQvSNz2d+b96/R1y4QOC71zXM1yNylXA6Q==
"@matrix-org/olm@3.2.15": "@matrix-org/olm@3.2.15":
version "3.2.15" version "3.2.15"