Skip to content

Commit

Permalink
Merge pull request #124 from matrix-org/poljar/bump-sdk
Browse files Browse the repository at this point in the history
Update the matrix-sdk crates to 9b05d0d822
  • Loading branch information
Hywan authored Jun 13, 2024
2 parents cd9fff5 + cbd7ca9 commit b6a1de7
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 57 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# UNRELEASED

**BREAKING CHANGES**

- Update matrix-rust-sdk to `9b05d0d82`, which includes:

- `Device.requestVerification`, `UserIdentities.requestVerification`, and
`UserIdentities.verificationRequestContent` is not async anymore.
([#3513](https://github.com/matrix-org/matrix-rust-sdk/pull/3513))

- Use the server name in the `QrCodeData` instead of the homeserver URL.
([#3537](https://github.com/matrix-org/matrix-rust-sdk/pull/3537))

# matrix-sdk-crypto-wasm v5.0.0

**BREAKING CHANGES**
Expand Down
34 changes: 15 additions & 19 deletions Cargo.lock

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

30 changes: 14 additions & 16 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,24 @@ impl Device {
pub fn request_verification(
&self,
methods: Option<Vec<verification::VerificationMethod>>,
) -> Result<Promise, JsError> {
) -> Result<Array, JsError> {
let me = self.inner.clone();
let methods = methods.map(|methods| methods.iter().map(Into::into).collect());

Ok(future_to_promise(async move {
let tuple = Array::new();
let (verification_request, outgoing_verification_request) = match methods {
Some(methods) => me.request_verification_with_methods(methods).await,
None => me.request_verification().await,
};

tuple.set(0, verification::VerificationRequest::from(verification_request).into());
tuple.set(
1,
verification::OutgoingVerificationRequest::from(outgoing_verification_request)
.try_into()?,
);
let tuple = Array::new();
let (verification_request, outgoing_verification_request) = match methods {
Some(methods) => me.request_verification_with_methods(methods),
None => me.request_verification(),
};

tuple.set(0, verification::VerificationRequest::from(verification_request).into());
tuple.set(
1,
verification::OutgoingVerificationRequest::from(outgoing_verification_request)
.try_into()?,
);

Ok(tuple)
}))
Ok(tuple)
}

/// Is this device considered to be verified.
Expand Down
21 changes: 9 additions & 12 deletions src/identities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
use js_sys::{Array, Promise};
use wasm_bindgen::prelude::*;

use crate::{future::future_to_promise, identifiers, impl_from_to_inner, requests, verification};
use crate::{
future::future_to_promise,
identifiers, impl_from_to_inner, requests,
verification::{self, VerificationRequest},
};

pub(crate) struct UserIdentities {
inner: matrix_sdk_crypto::UserIdentities,
Expand Down Expand Up @@ -164,18 +168,13 @@ impl UserIdentity {
room_id: &identifiers::RoomId,
request_event_id: &identifiers::EventId,
methods: Option<Vec<verification::VerificationMethod>>,
) -> Result<Promise, JsError> {
) -> Result<VerificationRequest, JsError> {
let me = self.inner.clone();
let room_id = room_id.inner.clone();
let request_event_id = request_event_id.inner.clone();
let methods = methods.map(|methods| methods.iter().map(Into::into).collect());

Ok(future_to_promise::<_, verification::VerificationRequest>(async move {
Ok(me
.request_verification(room_id.as_ref(), request_event_id.as_ref(), methods)
.await
.into())
}))
Ok(me.request_verification(room_id.as_ref(), request_event_id.as_ref(), methods).into())
}

/// Send a verification request to the given user.
Expand All @@ -189,13 +188,11 @@ impl UserIdentity {
pub fn verification_request_content(
&self,
methods: Option<Vec<verification::VerificationMethod>>,
) -> Result<Promise, JsError> {
) -> Result<String, JsError> {
let me = self.inner.clone();
let methods = methods.map(|methods| methods.iter().map(Into::into).collect());

Ok(future_to_promise(async move {
Ok(serde_json::to_string(&me.verification_request_content(methods).await)?)
}))
Ok(serde_json::to_string(&me.verification_request_content(methods))?)
}

/// Get the master key of the identity.
Expand Down
1 change: 1 addition & 0 deletions src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ impl OlmMachine {
user_id.as_ref(),
device_id.as_ref(),
store_handle,
None,
)
.await
.map_err(JsError::from)?,
Expand Down
21 changes: 11 additions & 10 deletions src/qr_login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,26 @@ pub struct QrCodeData {
#[wasm_bindgen]
impl QrCodeData {
/// Create new [`QrCodeData`] from a given public key, a rendezvous URL and,
/// optionally, a homeserver URL.
/// optionally, a server name for the homeserver.
///
/// If a homeserver URL is given, then the [`QrCodeData`] mode will be
/// If a server name is given, then the [`QrCodeData`] mode will be
/// [`QrCodeMode::Reciprocate`], i.e. the QR code will contain data for the
/// existing device to display the QR code.
///
/// If no homeserver is given, the [`QrCodeData`] mode will be
/// If no server name is given, the [`QrCodeData`] mode will be
/// [`QrCodeMode::Login`], i.e. the QR code will contain data for the
/// new device to display the QR code.
#[wasm_bindgen(constructor)]
pub fn new(
public_key: Curve25519PublicKey,
rendezvous_url: &str,
homeserver_url: Option<String>,
server_name: Option<String>,
) -> Result<QrCodeData, JsError> {
let public_key = public_key.inner;
let rendezvous_url = Url::parse(rendezvous_url)?;

let mode_data = if let Some(homeserver_url) = homeserver_url {
qr_login::QrCodeModeData::Reciprocate { homeserver_url: Url::parse(&homeserver_url)? }
let mode_data = if let Some(server_name) = server_name {
qr_login::QrCodeModeData::Reciprocate { server_name }
} else {
qr_login::QrCodeModeData::Login
};
Expand Down Expand Up @@ -120,14 +120,15 @@ impl QrCodeData {
self.inner.rendezvous_url.as_str().to_owned()
}

/// Get the homeserver URL which the new device will be logged in to.
/// Get the server name of the homeserver which the new device will be
/// logged in to.
///
/// This will be only available if the existing device has generated the QR
/// code and the new device is the one scanning the QR code.
#[wasm_bindgen(getter)]
pub fn homeserver_url(&self) -> Option<String> {
if let qr_login::QrCodeModeData::Reciprocate { homeserver_url } = &self.inner.mode_data {
Some(homeserver_url.as_str().to_owned())
pub fn server_name(&self) -> Option<String> {
if let qr_login::QrCodeModeData::Reciprocate { server_name } = &self.inner.mode_data {
Some(server_name.to_owned())
} else {
None
}
Expand Down

0 comments on commit b6a1de7

Please sign in to comment.