Skip to content

Commit cd9fff5

Browse files
authored
Improve types and docs of {import,export}SecretsBundle (#123)
* Improve return types of `{import,export}SecretsBundle` * Improve documentation too
1 parent ca8f2fb commit cd9fff5

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
keys that had been imported from key backup to be backed up again, when
1919
using the in-memory datastore.
2020

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

2326
- Expose new constructor function `OlmMachine.openWithKey()`.

src/machine.rs

+13-18
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,8 @@ impl OlmMachine {
534534
})
535535
}
536536

537-
/// Export all the secrets we have in the store into a [`SecretsBundle`].
537+
/// Export all the secrets we have in the store into a {@link
538+
/// SecretsBundle}.
538539
///
539540
/// This method will export all the private cross-signing keys and, if
540541
/// available, the private part of a backup key and its accompanying
@@ -546,35 +547,29 @@ impl OlmMachine {
546547
/// **Warning**: Only export this and share it with a trusted recipient,
547548
/// i.e. if an existing device is sharing this with a new device.
548549
#[wasm_bindgen(js_name = "exportSecretsBundle")]
549-
pub fn export_secrets_bundle(&self) -> Promise {
550-
let me = self.inner.clone();
551-
552-
future_to_promise(async move {
553-
Ok(me.store().export_secrets_bundle().await.map(store::SecretsBundle::from)?)
554-
})
550+
pub async fn export_secrets_bundle(&self) -> Result<store::SecretsBundle, JsError> {
551+
Ok(self.inner.store().export_secrets_bundle().await?.into())
555552
}
556553

557-
/// Import and persists secrets from a [`SecretsBundle`].
554+
/// Import and persists secrets from a {@link SecretsBundle}.
558555
///
559556
/// This method will import all the private cross-signing keys and, if
560557
/// available, the private part of a backup key and its accompanying
561558
/// version into the store.
562559
///
563560
/// **Warning**: Only import this from a trusted source, i.e. if an existing
564561
/// device is sharing this with a new device. The imported cross-signing
565-
/// keys will create a [`OwnUserIdentity`] and mark it as verified.
562+
/// keys will create a {@link OwnUserIdentity} and mark it as verified.
566563
///
567564
/// The backup key will be persisted in the store and can be enabled using
568-
/// the [`BackupMachine`].
565+
/// the {@link BackupMachine}.
566+
///
567+
/// The provided `SecretsBundle` is freed by this method; be careful not to
568+
/// use it once this method has been called.
569569
#[wasm_bindgen(js_name = "importSecretsBundle")]
570-
pub fn import_secrets_bundle(&self, bundle: store::SecretsBundle) -> Promise {
571-
let me = self.inner.clone();
572-
573-
future_to_promise(async move {
574-
me.store().import_secrets_bundle(&bundle.inner).await?;
575-
576-
Ok(JsValue::null())
577-
})
570+
pub async fn import_secrets_bundle(&self, bundle: store::SecretsBundle) -> Result<(), JsError> {
571+
self.inner.store().import_secrets_bundle(&bundle.inner).await?;
572+
Ok(())
578573
}
579574

580575
/// Export all the private cross signing keys we have.

0 commit comments

Comments
 (0)