Skip to content

Improve types and docs of {import,export}SecretsBundle #123

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

Merged
merged 2 commits into from
Jun 4, 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
Expand Up @@ -18,6 +18,9 @@
keys that had been imported from key backup to be backed up again, when
using the in-memory datastore.

- Improve the return types of `OlmMachine.{import,export}exportSecretsBundle()`.
([#123](https://github.com/matrix-org/matrix-rust-sdk-crypto-wasm/pull/123))

# matrix-sdk-crypto-wasm v4.10.0

- Expose new constructor function `OlmMachine.openWithKey()`.
Expand Down
31 changes: 13 additions & 18 deletions src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,8 @@ impl OlmMachine {
})
}

/// Export all the secrets we have in the store into a [`SecretsBundle`].
/// Export all the secrets we have in the store into a {@link
/// SecretsBundle}.
Comment on lines +537 to +538
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this documentation is used by typedoc, we have to use link formats that it understands.

(Note that currently the documentation at https://matrix-org.github.io/matrix-rust-sdk-crypto-wasm/classes/OlmMachine.html#importSecretsBundle doesn't link correctly).

///
/// This method will export all the private cross-signing keys and, if
/// available, the private part of a backup key and its accompanying
Expand All @@ -546,35 +547,29 @@ impl OlmMachine {
/// **Warning**: Only export this and share it with a trusted recipient,
/// i.e. if an existing device is sharing this with a new device.
#[wasm_bindgen(js_name = "exportSecretsBundle")]
pub fn export_secrets_bundle(&self) -> Promise {
let me = self.inner.clone();

future_to_promise(async move {
Ok(me.store().export_secrets_bundle().await.map(store::SecretsBundle::from)?)
})
pub async fn export_secrets_bundle(&self) -> Result<store::SecretsBundle, JsError> {
Ok(self.inner.store().export_secrets_bundle().await?.into())
}

/// Import and persists secrets from a [`SecretsBundle`].
/// Import and persists secrets from a {@link SecretsBundle}.
///
/// This method will import all the private cross-signing keys and, if
/// available, the private part of a backup key and its accompanying
/// version into the store.
///
/// **Warning**: Only import this from a trusted source, i.e. if an existing
/// device is sharing this with a new device. The imported cross-signing
/// keys will create a [`OwnUserIdentity`] and mark it as verified.
/// keys will create a {@link OwnUserIdentity} and mark it as verified.
///
/// The backup key will be persisted in the store and can be enabled using
/// the [`BackupMachine`].
/// the {@link BackupMachine}.
///
/// The provided `SecretsBundle` is freed by this method; be careful not to
/// use it once this method has been called.
Comment on lines +567 to +568
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invalidating an argument is a very non-JS thing to do, so let's call it out explicitly.

#[wasm_bindgen(js_name = "importSecretsBundle")]
pub fn import_secrets_bundle(&self, bundle: store::SecretsBundle) -> Promise {
let me = self.inner.clone();

future_to_promise(async move {
me.store().import_secrets_bundle(&bundle.inner).await?;

Ok(JsValue::null())
})
pub async fn import_secrets_bundle(&self, bundle: store::SecretsBundle) -> Result<(), JsError> {
self.inner.store().import_secrets_bundle(&bundle.inner).await?;
Ok(())
}

/// Export all the private cross signing keys we have.
Expand Down
Loading