diff --git a/.cargo/config b/.cargo/config index f4e8c002f..ae1dfdd95 100644 --- a/.cargo/config +++ b/.cargo/config @@ -1,2 +1,9 @@ +[patch.'https://github.com/matrix-org/matrix-rust-sdk'] +matrix-sdk-base = { path = "../matrix-rust-sdk/crates/matrix-sdk-base" } +matrix-sdk-common = { path = "../matrix-rust-sdk/crates/matrix-sdk-common" } +matrix-sdk-crypto = { path = "../matrix-rust-sdk/crates/matrix-sdk-crypto" } +matrix-sdk-indexeddb = { path = "../matrix-rust-sdk/crates/matrix-sdk-indexeddb" } +matrix-sdk-qrcode = { path = "../matrix-rust-sdk/crates/matrix-sdk-qrcode" } + [build] target = "wasm32-unknown-unknown" diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fc49ff5d..878ba9fd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# UNRELEASED + +- Add new properties `roomKeyRequestsEnabled` and `roomKeyForwardingEnabled` + to OlmMachine. + ([#60](https://github.com/matrix-org/matrix-rust-sdk-crypto-wasm/pull/60), + ([matrix-rust-sdk#2902](https://github.com/matrix-org/matrix-rust-sdk/pull/2902)) + # matrix-sdk-crypto-wasm v3.2.0 - Add `timeout_secs` parameters to `OlmMachine.get_user_devices` and diff --git a/Cargo.lock b/Cargo.lock index 92a7a5ffb..744d79f70 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -875,7 +875,7 @@ dependencies = [ [[package]] name = "matrix-sdk-base" version = "0.6.1" -source = "git+https://github.com/matrix-org/matrix-rust-sdk#94c4e685fc47ccecb565c755fb9a72bb104ddcaa" +source = "git+https://github.com/matrix-org/matrix-rust-sdk#a6c206118de0db6471e586beeaa5eca3449eacd4" dependencies = [ "as_variant", "async-trait", @@ -897,7 +897,7 @@ dependencies = [ [[package]] name = "matrix-sdk-common" version = "0.6.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk#94c4e685fc47ccecb565c755fb9a72bb104ddcaa" +source = "git+https://github.com/matrix-org/matrix-rust-sdk#a6c206118de0db6471e586beeaa5eca3449eacd4" dependencies = [ "async-trait", "futures-core", @@ -919,7 +919,7 @@ dependencies = [ [[package]] name = "matrix-sdk-crypto" version = "0.6.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk#94c4e685fc47ccecb565c755fb9a72bb104ddcaa" +source = "git+https://github.com/matrix-org/matrix-rust-sdk#a6c206118de0db6471e586beeaa5eca3449eacd4" dependencies = [ "aes", "as_variant", @@ -980,7 +980,7 @@ dependencies = [ [[package]] name = "matrix-sdk-indexeddb" version = "0.2.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk#94c4e685fc47ccecb565c755fb9a72bb104ddcaa" +source = "git+https://github.com/matrix-org/matrix-rust-sdk#a6c206118de0db6471e586beeaa5eca3449eacd4" dependencies = [ "anyhow", "async-trait", @@ -1006,7 +1006,7 @@ dependencies = [ [[package]] name = "matrix-sdk-qrcode" version = "0.4.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk#94c4e685fc47ccecb565c755fb9a72bb104ddcaa" +source = "git+https://github.com/matrix-org/matrix-rust-sdk#a6c206118de0db6471e586beeaa5eca3449eacd4" dependencies = [ "byteorder", "qrcode", @@ -1018,7 +1018,7 @@ dependencies = [ [[package]] name = "matrix-sdk-store-encryption" version = "0.2.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk#94c4e685fc47ccecb565c755fb9a72bb104ddcaa" +source = "git+https://github.com/matrix-org/matrix-rust-sdk#a6c206118de0db6471e586beeaa5eca3449eacd4" dependencies = [ "blake3", "chacha20poly1305", diff --git a/src/machine.rs b/src/machine.rs index b58075747..9ea307bae 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -172,6 +172,38 @@ impl OlmMachine { future_to_promise(async move { Ok(me.display_name().await?) }) } + /// Whether automatic transmission of room key requests is enabled. + /// + /// Room key requests allow the device to request room keys that it might + /// have missed in the original share using `m.room_key_request` + /// events. + #[wasm_bindgen(getter, js_name = "roomKeyRequestsEnabled")] + pub fn are_room_key_requests_enabled(&self) -> bool { + self.inner.are_room_key_requests_enabled() + } + + /// Enable or disable automatic transmission of room key requests. + #[wasm_bindgen(setter, js_name = "roomKeyRequestsEnabled")] + pub fn toggle_room_key_requests(&self, enabled: bool) { + self.inner.toggle_room_key_requests(enabled) + } + + /// Whether room key forwarding is enabled. + /// + /// If room key forwarding is enabled, we will automatically reply to + /// incoming `m.room_key_request` messages from verified devices by + /// forwarding the requested key (if we have it). + #[wasm_bindgen(getter, js_name = "roomKeyForwardingEnabled")] + pub fn is_room_key_forwarding_enabled(&self) -> bool { + self.inner.is_room_key_forwarding_enabled() + } + + /// Enable or disable room key forwarding. + #[wasm_bindgen(setter, js_name = "roomKeyForwardingEnabled")] + pub fn toggle_room_key_forwarding(&self, enabled: bool) { + self.inner.toggle_room_key_forwarding(enabled) + } + /// Get the list of users whose devices we are currently tracking. /// /// A user can be marked for tracking using the diff --git a/tests/machine.test.js b/tests/machine.test.js index b3407e53f..805af478c 100644 --- a/tests/machine.test.js +++ b/tests/machine.test.js @@ -201,6 +201,20 @@ describe(OlmMachine.name, () => { expect(await machine().displayName).toBeUndefined(); }); + test("can toggle room key requests", async () => { + const m = await machine(); + expect(m.roomKeyRequestsEnabled).toBeTruthy(); + m.roomKeyRequestsEnabled = false; + expect(m.roomKeyRequestsEnabled).toBeFalsy(); + }); + + test("can toggle room key forwarding", async () => { + const m = await machine(); + expect(m.roomKeyForwardingEnabled).toBeTruthy(); + m.roomKeyForwardingEnabled = false; + expect(m.roomKeyForwardingEnabled).toBeFalsy(); + }); + test("can read tracked users", async () => { const m = await machine(); const trackedUsers = await m.trackedUsers();