diff --git a/bindings/matrix-sdk-crypto-js/src/lib.rs b/bindings/matrix-sdk-crypto-js/src/lib.rs index 7d7ee45d6..96cb8715d 100644 --- a/bindings/matrix-sdk-crypto-js/src/lib.rs +++ b/bindings/matrix-sdk-crypto-js/src/lib.rs @@ -26,6 +26,7 @@ pub mod olm; pub mod requests; pub mod responses; pub mod sync_events; +pub mod vodozemac; mod tracing; use js_sys::{Object, Reflect}; diff --git a/bindings/matrix-sdk-crypto-js/src/machine.rs b/bindings/matrix-sdk-crypto-js/src/machine.rs index c9f1ac7d4..5116d8f18 100644 --- a/bindings/matrix-sdk-crypto-js/src/machine.rs +++ b/bindings/matrix-sdk-crypto-js/src/machine.rs @@ -10,9 +10,10 @@ use wasm_bindgen::prelude::*; use crate::{ downcast, encryption, future::future_to_promise, - olm, identifiers, requests, + olm, requests::OutgoingRequest, + vodozemac, responses::{self, response_from_string}, sync_events, }; @@ -63,7 +64,7 @@ impl OlmMachine { /// Get the public parts of our Olm identity keys. #[wasm_bindgen(getter, js_name = "identityKeys")] - pub fn identity_keys(&self) -> IdentityKeys { + pub fn identity_keys(&self) -> vodozemac::IdentityKeys { self.inner.identity_keys().into() } @@ -389,69 +390,3 @@ impl OlmMachine { })) } } - -/// An Ed25519 public key, used to verify digital signatures. -#[wasm_bindgen] -#[derive(Debug, Clone)] -pub struct Ed25519PublicKey { - inner: vodozemac::Ed25519PublicKey, -} - -#[wasm_bindgen] -impl Ed25519PublicKey { - /// The number of bytes an Ed25519 public key has. - #[wasm_bindgen(getter)] - pub fn length(&self) -> usize { - vodozemac::Ed25519PublicKey::LENGTH - } - - /// Serialize an Ed25519 public key to an unpadded base64 - /// representation. - #[wasm_bindgen(js_name = "toBase64")] - pub fn to_base64(&self) -> String { - self.inner.to_base64() - } -} - -/// A Curve25519 public key. -#[wasm_bindgen] -#[derive(Debug, Clone)] -pub struct Curve25519PublicKey { - inner: vodozemac::Curve25519PublicKey, -} - -#[wasm_bindgen] -impl Curve25519PublicKey { - /// The number of bytes a Curve25519 public key has. - #[wasm_bindgen(getter)] - pub fn length(&self) -> usize { - vodozemac::Curve25519PublicKey::LENGTH - } - - /// Serialize an Curve25519 public key to an unpadded base64 - /// representation. - #[wasm_bindgen(js_name = "toBase64")] - pub fn to_base64(&self) -> String { - self.inner.to_base64() - } -} - -/// Struct holding the two public identity keys of an account. -#[wasm_bindgen(getter_with_clone)] -#[derive(Debug)] -pub struct IdentityKeys { - /// The Ed25519 public key, used for signing. - pub ed25519: Ed25519PublicKey, - - /// The Curve25519 public key, used for establish shared secrets. - pub curve25519: Curve25519PublicKey, -} - -impl From for IdentityKeys { - fn from(value: matrix_sdk_crypto::olm::IdentityKeys) -> Self { - Self { - ed25519: Ed25519PublicKey { inner: value.ed25519 }, - curve25519: Curve25519PublicKey { inner: value.curve25519 }, - } - } -} diff --git a/bindings/matrix-sdk-crypto-js/src/vodozemac.rs b/bindings/matrix-sdk-crypto-js/src/vodozemac.rs new file mode 100644 index 000000000..e8ac54d90 --- /dev/null +++ b/bindings/matrix-sdk-crypto-js/src/vodozemac.rs @@ -0,0 +1,69 @@ +//! Vodozemac types. + +use wasm_bindgen::prelude::*; + +/// An Ed25519 public key, used to verify digital signatures. +#[wasm_bindgen] +#[derive(Debug, Clone)] +pub struct Ed25519PublicKey { + inner: vodozemac::Ed25519PublicKey, +} + +#[wasm_bindgen] +impl Ed25519PublicKey { + /// The number of bytes an Ed25519 public key has. + #[wasm_bindgen(getter)] + pub fn length(&self) -> usize { + vodozemac::Ed25519PublicKey::LENGTH + } + + /// Serialize an Ed25519 public key to an unpadded base64 + /// representation. + #[wasm_bindgen(js_name = "toBase64")] + pub fn to_base64(&self) -> String { + self.inner.to_base64() + } +} + +/// A Curve25519 public key. +#[wasm_bindgen] +#[derive(Debug, Clone)] +pub struct Curve25519PublicKey { + inner: vodozemac::Curve25519PublicKey, +} + +#[wasm_bindgen] +impl Curve25519PublicKey { + /// The number of bytes a Curve25519 public key has. + #[wasm_bindgen(getter)] + pub fn length(&self) -> usize { + vodozemac::Curve25519PublicKey::LENGTH + } + + /// Serialize an Curve25519 public key to an unpadded base64 + /// representation. + #[wasm_bindgen(js_name = "toBase64")] + pub fn to_base64(&self) -> String { + self.inner.to_base64() + } +} + +/// Struct holding the two public identity keys of an account. +#[wasm_bindgen(getter_with_clone)] +#[derive(Debug)] +pub struct IdentityKeys { + /// The Ed25519 public key, used for signing. + pub ed25519: Ed25519PublicKey, + + /// The Curve25519 public key, used for establish shared secrets. + pub curve25519: Curve25519PublicKey, +} + +impl From for IdentityKeys { + fn from(value: matrix_sdk_crypto::olm::IdentityKeys) -> Self { + Self { + ed25519: Ed25519PublicKey { inner: value.ed25519 }, + curve25519: Curve25519PublicKey { inner: value.curve25519 }, + } + } +}