Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new accessor OlmMachine.deviceCreationTimeMs #112

Merged
merged 2 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
66 changes: 33 additions & 33 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
Loading