diff --git a/crates/matrix-sdk-crypto/CHANGELOG.md b/crates/matrix-sdk-crypto/CHANGELOG.md index c51e85b2100..14ff187ecd8 100644 --- a/crates/matrix-sdk-crypto/CHANGELOG.md +++ b/crates/matrix-sdk-crypto/CHANGELOG.md @@ -19,6 +19,9 @@ Breaking changes: Additions: +- Expose new method `OlmMachine::device_creation_time`. + ([#3275](https://github.com/matrix-org/matrix-rust-sdk/pull/3275)) + - Log more details about the Olm session after encryption and decryption. ([#3242](https://github.com/matrix-org/matrix-rust-sdk/pull/3242)) diff --git a/crates/matrix-sdk-crypto/src/machine.rs b/crates/matrix-sdk-crypto/src/machine.rs index 7ea6d4e296d..bede64636fe 100644 --- a/crates/matrix-sdk-crypto/src/machine.rs +++ b/crates/matrix-sdk-crypto/src/machine.rs @@ -40,8 +40,8 @@ use ruma::{ AnyToDeviceEvent, MessageLikeEventContent, }, serde::Raw, - DeviceId, DeviceKeyAlgorithm, OwnedDeviceId, OwnedDeviceKeyId, OwnedTransactionId, OwnedUserId, - RoomId, TransactionId, UInt, UserId, + DeviceId, DeviceKeyAlgorithm, MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedDeviceKeyId, + OwnedTransactionId, OwnedUserId, RoomId, TransactionId, UInt, UserId, }; use serde_json::value::to_raw_value; use tokio::sync::Mutex; @@ -346,6 +346,16 @@ impl OlmMachine { &self.inner.device_id } + /// The time at which the `Account` backing this `OlmMachine` was created. + /// + /// An [`Account`] is created when an `OlmMachine` is first instantiated + /// against a given [`Store`], at which point it creates identity keys etc. + /// This method returns the timestamp, according to the local clock, at + /// which that happened. + pub fn device_creation_time(&self) -> MilliSecondsSinceUnixEpoch { + self.inner.store.static_account().creation_local_time() + } + /// Get the public parts of our Olm identity keys. pub fn identity_keys(&self) -> IdentityKeys { let account = self.inner.store.static_account(); @@ -2410,8 +2420,13 @@ pub(crate) mod tests { #[async_test] async fn test_create_olm_machine() { + let test_start_ts = MilliSecondsSinceUnixEpoch::now(); let machine = OlmMachine::new(user_id(), alice_device_id()).await; + let device_creation_time = machine.device_creation_time(); + assert!(device_creation_time <= MilliSecondsSinceUnixEpoch::now()); + assert!(device_creation_time >= test_start_ts); + let cache = machine.store().cache().await.unwrap(); let account = cache.account().await.unwrap(); assert!(!account.shared());