-
Notifications
You must be signed in to change notification settings - Fork 7
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
base: main
Are you sure you want to change the base?
Conversation
90833ef
to
e09ecc3
Compare
e09ecc3
to
5e848ab
Compare
src/device.rs
Outdated
/// they are encrypted. | ||
/// | ||
/// # Returns | ||
/// Returns a Promise for a `json` string of the encrypted event. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Returns a Promise for a `json` string of the encrypted event. | |
/// Returns a Promise for a JSON string of the encrypted event. |
There was a problem hiding this comment.
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
) ?
There was a problem hiding this comment.
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()
)
There was a problem hiding this comment.
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.]
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>
There was a problem hiding this 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}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// 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(); |
There was a problem hiding this comment.
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.
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