Skip to content

Commit

Permalink
Add OlmMachine.deviceCreationTimeMs
Browse files Browse the repository at this point in the history
  • Loading branch information
richvdh committed Mar 26, 2024
1 parent 7b3bc28 commit 033c842
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions tests/machine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 033c842

Please sign in to comment.