From a3a36291ad5cbf88750eadb67697b50b1ce15211 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Tue, 11 Jul 2023 16:29:17 +0100 Subject: [PATCH 1/4] crypto-js Fix return type of `receiveSyncChanges` https://github.com/matrix-org/matrix-rust-sdk/pull/2142 introduced an unintended change such that `receiveSyncChanges` returned an array of arrays. --- bindings/matrix-sdk-crypto-js/CHANGELOG.md | 7 +++++++ bindings/matrix-sdk-crypto-js/src/machine.rs | 15 +++++++++++---- .../matrix-sdk-crypto-js/tests/machine.test.js | 6 +++--- crates/matrix-sdk-crypto/src/machine.rs | 4 +++- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/bindings/matrix-sdk-crypto-js/CHANGELOG.md b/bindings/matrix-sdk-crypto-js/CHANGELOG.md index 0bdcb8714..4a9c638cc 100644 --- a/bindings/matrix-sdk-crypto-js/CHANGELOG.md +++ b/bindings/matrix-sdk-crypto-js/CHANGELOG.md @@ -1,5 +1,12 @@ +# v0.1.3 + +Fix bug introduced in v0.1.2 which caused an undocumented change to the results of `OlmMachine.receiveSyncChanges`. + # v0.1.2 +**WARNING**: this version had a breaking change in the result type of `OlmMachine.receiveSyncChanges`. +This is corrected in v0.1.3. + ## Changes in the Javascript bindings - Add `Qr.state()` method to inspect the current state of QR code diff --git a/bindings/matrix-sdk-crypto-js/src/machine.rs b/bindings/matrix-sdk-crypto-js/src/machine.rs index 842145f0c..5a9972063 100644 --- a/bindings/matrix-sdk-crypto-js/src/machine.rs +++ b/bindings/matrix-sdk-crypto-js/src/machine.rs @@ -216,6 +216,9 @@ impl OlmMachine { /// /// To decrypt an event from the room timeline call /// `decrypt_room_event`. + /// + /// Returns a list of JSON strings, containing the decrypted to-device + /// events. #[wasm_bindgen(js_name = "receiveSyncChanges")] pub fn receive_sync_changes( &self, @@ -255,15 +258,19 @@ impl OlmMachine { let me = self.inner.clone(); Ok(future_to_promise(async move { - Ok(serde_json::to_string( - &me.receive_sync_changes( + // we discard the list of updated room keys in the result; JS applications are + // expected to use register_room_key_updated_callback to receive updated room + // keys. + let (decrypted_to_device_events, _) = me + .receive_sync_changes( to_device_events, &changed_devices, &one_time_key_counts, unused_fallback_keys.as_deref(), ) - .await?, - )?) + .await?; + + Ok(serde_json::to_string(&decrypted_to_device_events)?) })) } diff --git a/bindings/matrix-sdk-crypto-js/tests/machine.test.js b/bindings/matrix-sdk-crypto-js/tests/machine.test.js index 6abd4bde2..220d105a8 100644 --- a/bindings/matrix-sdk-crypto-js/tests/machine.test.js +++ b/bindings/matrix-sdk-crypto-js/tests/machine.test.js @@ -217,7 +217,7 @@ describe(OlmMachine.name, () => { await m.receiveSyncChanges(toDeviceEvents, changedDevices, oneTimeKeyCounts, unusedFallbackKeys), ); - expect(receiveSyncChanges).toEqual([[], []]); + expect(receiveSyncChanges).toEqual([]); }); test("can receive sync changes with unusedFallbackKeys as undefined", async () => { @@ -230,7 +230,7 @@ describe(OlmMachine.name, () => { await m.receiveSyncChanges(toDeviceEvents, changedDevices, oneTimeKeyCounts, undefined), ); - expect(receiveSyncChanges).toEqual([[], []]); + expect(receiveSyncChanges).toEqual([]); }); test("can get the outgoing requests that need to be send out", async () => { @@ -244,7 +244,7 @@ describe(OlmMachine.name, () => { await m.receiveSyncChanges(toDeviceEvents, changedDevices, oneTimeKeyCounts, unusedFallbackKeys), ); - expect(receiveSyncChanges).toEqual([[], []]); + expect(receiveSyncChanges).toEqual([]); const outgoingRequests = await m.outgoingRequests(); diff --git a/crates/matrix-sdk-crypto/src/machine.rs b/crates/matrix-sdk-crypto/src/machine.rs index 3fd26f7cc..dfe5fce43 100644 --- a/crates/matrix-sdk-crypto/src/machine.rs +++ b/crates/matrix-sdk-crypto/src/machine.rs @@ -1105,7 +1105,9 @@ impl OlmMachine { /// /// [`decrypt_room_event`]: #method.decrypt_room_event /// - /// Returns a tuple of (pending verification events, updated room keys) + /// # Returns + /// + /// A tuple of (decrypted to-device events, updated room keys). #[instrument(skip_all)] pub async fn receive_sync_changes( &self, From fd3c4f669d585105d9bdcb4ee30222637e0b8c9c Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Tue, 11 Jul 2023 16:41:22 +0100 Subject: [PATCH 2/4] matrix-sdk-crypto-js v0.1.3 --- bindings/matrix-sdk-crypto-js/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/matrix-sdk-crypto-js/package.json b/bindings/matrix-sdk-crypto-js/package.json index b70c470ea..d924385e0 100644 --- a/bindings/matrix-sdk-crypto-js/package.json +++ b/bindings/matrix-sdk-crypto-js/package.json @@ -1,6 +1,6 @@ { "name": "@matrix-org/matrix-sdk-crypto-js", - "version": "0.1.2", + "version": "0.1.3", "homepage": "https://github.com/matrix-org/matrix-rust-sdk", "description": "Matrix encryption library, for JavaScript", "license": "Apache-2.0", From 0bd1e65b497b67d61aee2f64d9262430da523371 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Tue, 11 Jul 2023 16:41:45 +0100 Subject: [PATCH 3/4] update changelogs --- bindings/matrix-sdk-crypto-js/CHANGELOG.md | 8 +++++++- crates/matrix-sdk-crypto/CHANGELOG.md | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/bindings/matrix-sdk-crypto-js/CHANGELOG.md b/bindings/matrix-sdk-crypto-js/CHANGELOG.md index 4a9c638cc..cea68b531 100644 --- a/bindings/matrix-sdk-crypto-js/CHANGELOG.md +++ b/bindings/matrix-sdk-crypto-js/CHANGELOG.md @@ -1,6 +1,12 @@ # v0.1.3 -Fix bug introduced in v0.1.2 which caused an undocumented change to the results of `OlmMachine.receiveSyncChanges`. +## Changes in the Javascript bindings + +- Fix bug introduced in v0.1.2 which caused an undocumented change to the results of `OlmMachine.receiveSyncChanges`. + +## Changes in the underlying Rust crate + +- Fix a bug which could cause generated one-time-keys not to be persisted. # v0.1.2 diff --git a/crates/matrix-sdk-crypto/CHANGELOG.md b/crates/matrix-sdk-crypto/CHANGELOG.md index be9f8b2f2..b7b63461a 100644 --- a/crates/matrix-sdk-crypto/CHANGELOG.md +++ b/crates/matrix-sdk-crypto/CHANGELOG.md @@ -38,3 +38,5 @@ "Airplane", for consistency with the Matrix spec. - Fix handling of SAS verification start events once we have shown a QR code. + +- Fix a bug which could cause generated one-time-keys not to be persisted. From f1def2a45860caa650375258c22433956a1c1fdc Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Tue, 11 Jul 2023 17:19:58 +0100 Subject: [PATCH 4/4] fix another test --- bindings/matrix-sdk-crypto-js/tests/helper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bindings/matrix-sdk-crypto-js/tests/helper.js b/bindings/matrix-sdk-crypto-js/tests/helper.js index 5aa3e1442..eaf58d5b8 100644 --- a/bindings/matrix-sdk-crypto-js/tests/helper.js +++ b/bindings/matrix-sdk-crypto-js/tests/helper.js @@ -20,7 +20,7 @@ async function addMachineToMachine(machineToAdd, machine) { await machineToAdd.receiveSyncChanges(toDeviceEvents, changedDevices, oneTimeKeyCounts, unusedFallbackKeys), ); - expect(receiveSyncChanges).toEqual([[], []]); + expect(receiveSyncChanges).toEqual([]); const outgoingRequests = await machineToAdd.outgoingRequests();