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 support for sending encrypted to_device #101

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

BillCarsonFr
Copy link
Member

Depends on matrix-org/matrix-rust-sdk#3091

Add bindings to support sending custom encrypted to device event.
see matrix-org/matrix-js-sdk#3304

@BillCarsonFr BillCarsonFr force-pushed the valere/send_encrypted_to_device_support branch from e09ecc3 to 5e848ab Compare February 26, 2024 10:59
@BillCarsonFr BillCarsonFr marked this pull request as ready for review February 26, 2024 11:00
@BillCarsonFr BillCarsonFr requested a review from a team as a code owner February 26, 2024 11:00
CHANGELOG.md Outdated Show resolved Hide resolved
src/device.rs Outdated Show resolved Hide resolved
src/device.rs Outdated Show resolved Hide resolved
src/device.rs Outdated Show resolved Hide resolved
src/device.rs Outdated
/// they are encrypted.
///
/// # Returns
/// Returns a Promise for a `json` string of the encrypted event.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// Returns a Promise for a `json` string of the encrypted event.
/// Returns a Promise for a JSON string of the encrypted event.

Copy link
Member

Choose a reason for hiding this comment

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

Is JSON-encoding the response useful? Won't the application immediately have to JSON-decode it? Wouldn't it be better to return a JS object (with serde_wasm_bindgen::to_value) ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Finally found the way to do it (needed to use Serializer::json_compatible())

Copy link
Member

@richvdh richvdh Mar 6, 2024

Choose a reason for hiding this comment

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

OH! Sorry. When I asked this, I hadn't realised that encrypt_event_raw returns JSON. I don't think it's correct that we then deserialize that object back into a rust-side ToDeviceEncryptedEventContent, and then re-serialize that back to a js object.

Since we have JSON, let's just return it and deal with it on the JS side. Sorry!

[Alternatively, we could call js_sys::JSON::parse to convert straight from the JSON to a JS object, but I'm not sure there's much benefit to that.]

tests/device.test.js Outdated Show resolved Hide resolved
tests/device.test.js Outdated Show resolved Hide resolved
tests/device.test.js Outdated Show resolved Hide resolved
tests/device.test.js Outdated Show resolved Hide resolved
tests/device.test.js Outdated Show resolved Hide resolved
BillCarsonFr and others added 11 commits March 4, 2024 17:30
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

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

Looks good except for the complicated serialization stuff :/

use wasm_bindgen::prelude::*;

use crate::{
encryption::EncryptionAlgorithm,
future::future_to_promise,
identifiers::{self, DeviceId, UserId},
impl_from_to_inner, requests, types, verification, vodozemac,
impl_from_to_inner,
requests::{self},
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
requests::{self},
requests,

/// Encrypt a to-device message to be sent to this device, using Olm
/// encryption.
///
/// Prior to calling this method you must ensure that an olm session is
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// Prior to calling this method you must ensure that an olm session is
/// Prior to calling this method you must ensure that an Olm session is

/// the same order as they are encrypted.
///
/// # Returns
/// Returns a Promise for a js object of the encrypted event.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// Returns a Promise for a js object of the encrypted event.
/// Returns a Promise for a JS object of the encrypted event.

) -> Result<Promise, JsError> {
let me = self.inner.clone();
let content: Value = serde_wasm_bindgen::from_value(content)?;
let event_type = event_type.clone();
Copy link
Member

Choose a reason for hiding this comment

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

This line can be removed. No need to clone the event type here, you already own it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants