diff --git a/CHANGELOG.md b/CHANGELOG.md index 71492554f..8ff58b48d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # UNRELEASED +- Add `OlmMachine.deviceCreationTimeMs`. + ([#112](https://github.com/matrix-org/matrix-rust-sdk-crypto-wasm/pull/112)) + # matrix-sdk-crypto-wasm v4.8.0 - Add `OlmMachine.dehydratedDevices()` and `DehydratedDevices` class to diff --git a/Cargo.lock b/Cargo.lock index 31c3924f0..9087ccd5e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -52,9 +52,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] @@ -94,9 +94,9 @@ checksum = "5f093eed78becd229346bf859eec0aa4dd7ddde0757287b2b4107a1f09c80002" [[package]] name = "async-trait" -version = "0.1.77" +version = "0.1.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" +checksum = "a507401cad91ec6a857ed5513a2073c82a9b9048762b885bb98655b306964681" dependencies = [ "proc-macro2", "quote", @@ -105,15 +105,15 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" [[package]] name = "backtrace" -version = "0.3.69" +version = "0.3.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" dependencies = [ "addr2line", "cc", @@ -175,9 +175,9 @@ dependencies = [ [[package]] name = "bs58" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5353f36341f7451062466f0b755b96ac3a9547e4d7f6b70d603fc721a7d7896" +checksum = "bf88ba1141d185c399bee5288d850d63b8369520c1eafc32a0430b5b6c287bf4" dependencies = [ "tinyvec", ] @@ -196,9 +196,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.5.0" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" [[package]] name = "cbc" @@ -471,9 +471,9 @@ dependencies = [ [[package]] name = "fiat-crypto" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1676f435fc1dadde4d03e43f5d62b259e1ce5f40bd4ffb21db2b42ebe59c1382" +checksum = "c007b1ae3abe1cb6f85a16305acd418b7ca6343b953633fee2b76d8f108b830f" [[package]] name = "flagset" @@ -667,9 +667,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.2.5" +version = "2.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b0b929d511467233429c45a44ac1dcaa21ba0f5ba11e4879e6ed28ddb4f9df4" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", "hashbrown", @@ -718,9 +718,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "js-sys" @@ -866,7 +866,7 @@ dependencies = [ [[package]] name = "matrix-sdk-common" version = "0.7.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk#6aee1f62bd25dcbc128b2dd0e7727f1cead19192" +source = "git+https://github.com/matrix-org/matrix-rust-sdk#ab9e4f73b1b43e0779080b714e0916496a052cc3" dependencies = [ "async-trait", "futures-core", @@ -888,7 +888,7 @@ dependencies = [ [[package]] name = "matrix-sdk-crypto" version = "0.7.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk#6aee1f62bd25dcbc128b2dd0e7727f1cead19192" +source = "git+https://github.com/matrix-org/matrix-rust-sdk#ab9e4f73b1b43e0779080b714e0916496a052cc3" dependencies = [ "aes", "as_variant", @@ -953,7 +953,7 @@ dependencies = [ [[package]] name = "matrix-sdk-indexeddb" version = "0.7.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk#6aee1f62bd25dcbc128b2dd0e7727f1cead19192" +source = "git+https://github.com/matrix-org/matrix-rust-sdk#ab9e4f73b1b43e0779080b714e0916496a052cc3" dependencies = [ "anyhow", "async-trait", @@ -978,7 +978,7 @@ dependencies = [ [[package]] name = "matrix-sdk-qrcode" version = "0.7.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk#6aee1f62bd25dcbc128b2dd0e7727f1cead19192" +source = "git+https://github.com/matrix-org/matrix-rust-sdk#ab9e4f73b1b43e0779080b714e0916496a052cc3" dependencies = [ "byteorder", "qrcode", @@ -990,7 +990,7 @@ dependencies = [ [[package]] name = "matrix-sdk-store-encryption" version = "0.7.0" -source = "git+https://github.com/matrix-org/matrix-rust-sdk#6aee1f62bd25dcbc128b2dd0e7727f1cead19192" +source = "git+https://github.com/matrix-org/matrix-rust-sdk#ab9e4f73b1b43e0779080b714e0916496a052cc3" dependencies = [ "base64 0.21.7", "blake3", @@ -1285,9 +1285,9 @@ checksum = "d7b323e7196daa571c8584de958be19e92941c41f845776fe06babfe8fa280a2" [[package]] name = "regex" -version = "1.10.3" +version = "1.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" dependencies = [ "aho-corasick", "memchr", @@ -1549,9 +1549,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.114" +version = "1.0.115" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" +checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" dependencies = [ "itoa", "ryu", @@ -1623,9 +1623,9 @@ checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" [[package]] name = "syn" -version = "2.0.52" +version = "2.0.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b699d15b36d1f02c3e7c69f8ffef53de37aefae075d8488d4ba1a7788d574a07" +checksum = "002a1b3dbf967edfafc32655d0f377ab0bb7b994aa1d32c8cc7e9b8bf3ebb8f0" dependencies = [ "proc-macro2", "quote", @@ -1722,9 +1722,9 @@ dependencies = [ [[package]] name = "tokio-stream" -version = "0.1.14" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "397c988d37662c7dda6d2208364a706264bf3d6138b11d436cbac0ad38832842" +checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af" dependencies = [ "futures-core", "pin-project-lite", @@ -2071,9 +2071,9 @@ dependencies = [ [[package]] name = "wildmatch" -version = "2.3.1" +version = "2.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "017f0a8ed8331210d91b7a4c30d4edef8f21a65c02f2540496e2e79725f6d8a8" +checksum = "939e59c1bc731542357fdaad98b209ef78c8743d652bb61439d16b16a79eb025" [[package]] name = "winapi" diff --git a/src/machine.rs b/src/machine.rs index 1881aa1d0..6b2db51d5 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -150,6 +150,18 @@ impl OlmMachine { identifiers::DeviceId::from(self.inner.device_id().to_owned()) } + /// The time, in milliseconds since the unix epoch, 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. + #[wasm_bindgen(getter, js_name = "deviceCreationTimeMs")] + pub fn device_creation_time_ms(&self) -> f64 { + self.inner.device_creation_time().get().into() + } + /// Get the public parts of our Olm identity keys. #[wasm_bindgen(getter, js_name = "identityKeys")] pub fn identity_keys(&self) -> vodozemac::IdentityKeys { diff --git a/tests/machine.test.ts b/tests/machine.test.ts index 777778f60..1e5964a78 100644 --- a/tests/machine.test.ts +++ b/tests/machine.test.ts @@ -214,6 +214,13 @@ describe(OlmMachine.name, () => { expect((await machine()).deviceId.toString()).toStrictEqual(device.toString()); }); + test("can read creation time", async () => { + const startTime = Date.now(); + const creationTime = (await machine()).deviceCreationTimeMs; + expect(creationTime).toBeLessThanOrEqual(Date.now()); + expect(creationTime).toBeGreaterThanOrEqual(startTime); + }); + test("can read identity keys", async () => { const identityKeys = (await machine()).identityKeys;