chore(crypto-js): Clean up code and make CI happy.

This commit is contained in:
Ivan Enderlin
2022-05-30 11:02:24 +02:00
parent 4db1ad350b
commit 7931c4a589
14 changed files with 89 additions and 500 deletions

View File

@@ -38,7 +38,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: tarpaulin
args: --ignore-config --exclude-files "crates/matrix-sdk/examples/*,crates/matrix-sdk-common,crates/matrix-sdk-test,crates/matrix-sdk-crypto-js,crates/matrix-sdk-crypto-nodejs" --out Xml
args: --workspace --ignore-config --exclude-files "crates/matrix-sdk/examples/*,crates/matrix-sdk-common,crates/matrix-sdk-test" --exclude matrix-sdk-crypto-js --exclude matrix-sdk-crypto-nodejs --out Xml
- name: Upload to codecov.io
uses: codecov/codecov-action@v3

View File

@@ -32,7 +32,7 @@ jobs:
RUSTDOCFLAGS: "--enable-index-page -Zunstable-options --cfg docsrs -Dwarnings"
with:
command: doc
args: --no-deps --workspace --features docsrs -Zrustdoc-map
args: --no-deps --workspace --exclude matrix-sdk-crypto-js --exclude matrix-sdk-crypto-nodejs --features docsrs -Zrustdoc-map
- name: Deploy docs
if: github.event_name == 'push' && github.ref == 'refs/heads/main'

View File

@@ -1,2 +1,2 @@
[build]
target = "wasm32-unknown-unknown"
target = "wasm32-unknown-unknown"

View File

@@ -35,4 +35,4 @@ wasm-bindgen-futures = "0.4.30"
js-sys = "0.3.49"
serde_json = "1.0.79"
http = "0.2.6"
anyhow = "1.0"
anyhow = "1.0"

View File

@@ -23,7 +23,7 @@ impl UserId {
/// Parse/validate and create a new `UserId`.
#[wasm_bindgen(constructor)]
pub fn new(id: &str) -> Result<UserId, JsError> {
Ok(Self { inner: ruma::UserId::parse(id)? })
Ok(Self::new_with(ruma::UserId::parse(id)?))
}
/// Returns the user's localpart.
@@ -76,7 +76,7 @@ impl DeviceId {
/// Create a new `DeviceId`.
#[wasm_bindgen(constructor)]
pub fn new(id: &str) -> DeviceId {
Self { inner: id.into() }
Self::new_with(id.into())
}
/// Return the device ID as a string.
@@ -107,7 +107,7 @@ impl RoomId {
/// Parse/validate and create a new `RoomId`.
#[wasm_bindgen(constructor)]
pub fn new(id: &str) -> Result<RoomId, JsError> {
Ok(Self { inner: ruma::RoomId::parse(id)? })
Ok(Self::new_with(ruma::RoomId::parse(id)?))
}
/// Returns the user's localpart.

View File

@@ -1,4 +1,4 @@
// Copyright 2020 The Matrix.org Foundation C.I.C.
// Copyright 2022 The Matrix.org Foundation C.I.C.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -16,9 +16,6 @@
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![warn(missing_docs, missing_debug_implementations)]
#[cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))]
compile_error!("This crate is designed to only be compiled to `wasm32-unknown-unknown`.");
pub mod events;
mod future;
pub mod identifiers;
@@ -26,7 +23,6 @@ pub mod machine;
pub mod requests;
pub mod responses;
pub mod sync_events;
pub mod verifications;
use js_sys::{Object, Reflect};
use wasm_bindgen::{convert::RefFromWasmAbi, prelude::*};

View File

@@ -1,13 +1,10 @@
//! The crypto specific Olm objects.
use std::{collections::BTreeMap, sync::Arc, time::Duration};
use std::{collections::BTreeMap, time::Duration};
use js_sys::{Array, Map, Promise, Set};
use ruma::{
events::{AnyMessageLikeEventContent, EventContent},
DeviceKeyAlgorithm, OwnedTransactionId, UInt,
};
use serde_json::value::RawValue as RawJsonValue;
use ruma::{DeviceKeyAlgorithm, OwnedTransactionId, UInt};
use serde_json::Value as JsonValue;
use wasm_bindgen::prelude::*;
use crate::{
@@ -16,15 +13,15 @@ use crate::{
identifiers, requests,
requests::OutgoingRequest,
responses::{self, response_from_string},
sync_events, verifications,
sync_events,
};
/// State machine implementation of the Olm/Megolm encryption protocol
/// used for Matrix end to end encryption.
#[wasm_bindgen]
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct OlmMachine {
inner: Arc<matrix_sdk_crypto::OlmMachine>,
inner: matrix_sdk_crypto::OlmMachine,
}
#[wasm_bindgen]
@@ -45,9 +42,8 @@ impl OlmMachine {
future_to_promise(async move {
Ok(OlmMachine {
inner: Arc::new(
matrix_sdk_crypto::OlmMachine::new(user_id.as_ref(), device_id.as_ref()).await,
),
inner: matrix_sdk_crypto::OlmMachine::new(user_id.as_ref(), device_id.as_ref())
.await,
})
})
}
@@ -119,7 +115,8 @@ impl OlmMachine {
}))
}
/// Handle a to-device and one-time key counts from a sync response.
/// Handle to-device events and one-time key counts from a sync
/// response.
///
/// This will decrypt and handle to-device events returning the
/// decrypted versions of them.
@@ -206,12 +203,14 @@ impl OlmMachine {
/// Mark the request with the given request ID as sent (see
/// `outgoing_requests`).
///
/// `request_id` represents the unique ID of the request that was
/// sent out. This is needed to couple the response with the now
/// sent out request. `response_type` represents the type of the
/// request that was sent out. `response` represents the response
/// that was received from the server after the outgoing request
/// was sent out. `
/// Arguments are:
///
/// * `request_id` represents the unique ID of the request that was sent
/// out. This is needed to couple the response with the now sent out
/// request.
/// * `response_type` represents the type of the request that was sent out.
/// * `response` represents the response that was received from the server
/// after the outgoing request was sent out.
#[wasm_bindgen(js_name = "markRequestAsSent")]
pub fn mark_request_as_sent(
&self,
@@ -235,11 +234,6 @@ impl OlmMachine {
/// Beware that a group session needs to be shared before this
/// method can be called using the `share_group_session` method.
///
/// Since group sessions can expire or become invalid if the room
/// membership changes, client authors should check with the
/// `should_share_group_session` method if a new group session
/// needs to be shared.
///
/// `room_id` is the ID of the room for which the message should
/// be encrypted. `event_type` is the type of the event. `content`
/// is the plaintext content of the message that should be
@@ -247,22 +241,23 @@ impl OlmMachine {
///
/// # Panics
///
/// Panics if a group session for the given room wasn't shared beforehand.
/// Panics if a group session for the given room wasn't shared
/// beforehand.
#[wasm_bindgen(js_name = "encryptRoomEvent")]
pub fn encrypt_room_event(
&self,
room_id: &identifiers::RoomId,
event_type: &str,
event_type: String,
content: &str,
) -> Result<Promise, JsError> {
let room_id = room_id.inner.clone();
let content: Box<RawJsonValue> = serde_json::from_str(content)?;
let content = AnyMessageLikeEventContent::from_parts(event_type, &content)?;
let content: JsonValue = serde_json::from_str(content)?;
let me = self.inner.clone();
Ok(future_to_promise(async move {
Ok(serde_json::to_string(&me.encrypt_room_event(&room_id, content).await?)?)
Ok(serde_json::to_string(
&me.encrypt_room_event_raw(&room_id, content, event_type.as_ref()).await?,
)?)
}))
}
@@ -362,31 +357,6 @@ impl OlmMachine {
}
}))
}
/// Get a verification object for the given user ID with the given flow ID.
///
/// Returns a list of `JsValue` to represent either (depending on
/// how the Wasm module has been compiled):
/// * `Sas` (enabled),
/// * `Qr`
#[cfg_attr(feature = "qrcode", doc = "(enabled).")]
#[cfg_attr(not(feature = "qrcode"), doc = "(disabled).")]
///
/// If a verification mode is missing, please try to compile the
/// Wasm module with different features.
#[wasm_bindgen(js_name = "getVerification")]
pub fn get_verification(
&self,
user_id: &identifiers::UserId,
flow_id: &str,
) -> Result<JsValue, JsError> {
self.inner
.get_verification(user_id.inner.as_ref(), flow_id)
.map(verifications::Verification)
.map(JsValue::try_from)
.transpose()
.map(|r| r.unwrap_or(JsValue::UNDEFINED))
}
}
/// An Ed25519 public key, used to verify digital signatures.

View File

@@ -15,9 +15,12 @@ use ruma::api::client::keys::{
};
use wasm_bindgen::prelude::*;
/// Data for a request to the `upload_keys` API endpoint.
/// Data for a request to the `/keys/upload` API endpoint
/// ([specification]).
///
/// Publishes end-to-end encryption keys for the device.
///
/// [specification]: https://spec.matrix.org/unstable/client-server-api/#post_matrixclientv3keysupload
#[derive(Debug)]
#[wasm_bindgen(getter_with_clone)]
pub struct KeysUploadRequest {
@@ -34,9 +37,12 @@ pub struct KeysUploadRequest {
pub body: JsString,
}
/// Data for a request to the `get_keys` API endpoint.
/// Data for a request to the `/keys/query` API endpoint
/// ([specification]).
///
/// Returns the current devices and identity keys for the given users.
///
/// [specification]: https://spec.matrix.org/unstable/client-server-api/#post_matrixclientv3keysquery
#[derive(Debug)]
#[wasm_bindgen(getter_with_clone)]
pub struct KeysQueryRequest {
@@ -53,9 +59,13 @@ pub struct KeysQueryRequest {
pub body: JsString,
}
/// Data for a request to the `claim_keys` API endpoint.
/// Data for a request to the `/keys/claim` API endpoint
/// ([specification]).
///
/// Claims one-time keys for use in pre-key messages.
/// Claims one-time keys that can be used to establish 1-to-1 E2EE
/// sessions.
///
/// [specification]: https://spec.matrix.org/unstable/client-server-api/#post_matrixclientv3keysclaim
#[derive(Debug)]
#[wasm_bindgen(getter_with_clone)]
pub struct KeysClaimRequest {
@@ -72,9 +82,12 @@ pub struct KeysClaimRequest {
pub body: JsString,
}
/// Data for a request to the `send_event_to_device` API endpoint.
/// Data for a request to the `/sendToDevice` API endpoint
/// ([specification]).
///
/// Send an event to a device or devices.
/// Send an event to a single device or to a group of devices.
///
/// [specification]: https://spec.matrix.org/unstable/client-server-api/#put_matrixclientv3sendtodeviceeventtypetxnid
#[derive(Debug)]
#[wasm_bindgen(getter_with_clone)]
pub struct ToDeviceRequest {
@@ -91,9 +104,12 @@ pub struct ToDeviceRequest {
pub body: JsString,
}
/// Data for a request to the `upload_signatures` API endpoint.
/// Data for a request to the `/keys/signatures/upload` API endpoint
/// ([specification]).
///
/// Publishes cross-signing signatures for the user.
///
/// [specification]: https://spec.matrix.org/unstable/client-server-api/#post_matrixclientv3keyssignaturesupload
#[derive(Debug)]
#[wasm_bindgen(getter_with_clone)]
pub struct SignatureUploadRequest {
@@ -110,7 +126,10 @@ pub struct SignatureUploadRequest {
pub body: JsString,
}
/// A customized owned request type for sending out room messages.
/// A customized owned request type for sending out room messages
/// ([specification]).
///
/// [specification]: https://spec.matrix.org/unstable/client-server-api/#put_matrixclientv3roomsroomidsendeventtypetxnid
#[derive(Debug)]
#[wasm_bindgen(getter_with_clone)]
pub struct RoomMessageRequest {
@@ -127,7 +146,10 @@ pub struct RoomMessageRequest {
pub body: JsString,
}
/// A request that will back up a batch of room keys to the server.
/// A request that will back up a batch of room keys to the server
/// ([specification]).
///
/// [specification]: https://spec.matrix.org/unstable/client-server-api/#put_matrixclientv3room_keyskeys
#[derive(Debug)]
#[wasm_bindgen(getter_with_clone)]
pub struct KeysBackupRequest {
@@ -138,7 +160,7 @@ pub struct KeysBackupRequest {
/// A JSON-encoded object of form:
///
/// ```
/// {"version": …, "rooms": …}
/// {"rooms": …}
/// ```
#[wasm_bindgen(readonly)]
pub body: JsString,
@@ -173,7 +195,7 @@ request!(KeysClaimRequest from RumaKeysClaimRequest maps fields timeout, one_tim
request!(ToDeviceRequest from RumaToDeviceRequest maps fields event_type, txn_id, messages);
request!(SignatureUploadRequest from RumaSignatureUploadRequest maps fields signed_keys);
request!(RoomMessageRequest from RumaRoomMessageRequest maps fields room_id, txn_id, content);
request!(KeysBackupRequest from RumaKeysBackupRequest maps fields version, rooms);
request!(KeysBackupRequest from RumaKeysBackupRequest maps fields rooms);
// JavaScript has no complex enums like Rust. To return structs of
// different types, we have no choice that hiding everything behind a

View File

@@ -1,394 +0,0 @@
//! Different verification types.
use js_sys::{Array, JsString};
use ruma::events::key::verification::cancel::CancelCode as RumaCancelCode;
use wasm_bindgen::prelude::*;
use crate::identifiers::{DeviceId, RoomId, UserId};
/// Short Authentification String (SAS) verification.
#[wasm_bindgen]
#[derive(Debug)]
pub struct Sas {
inner: matrix_sdk_crypto::Sas,
}
#[wasm_bindgen]
impl Sas {
/// Get our own user ID.
#[wasm_bindgen(js_name = "userId")]
pub fn user_id(&self) -> UserId {
UserId { inner: self.inner.user_id().to_owned() }
}
/// Get our own device ID.
#[wasm_bindgen(js_name = "deviceId")]
pub fn device_id(&self) -> DeviceId {
DeviceId { inner: self.inner.device_id().to_owned() }
}
/// Get the user id of the other side.
#[wasm_bindgen(js_name = "otherUserId")]
pub fn other_user_id(&self) -> UserId {
UserId { inner: self.inner.other_user_id().to_owned() }
}
/// Get the device ID of the other side.
#[wasm_bindgen(js_name = "otherDeviceId")]
pub fn other_device_id(&self) -> DeviceId {
DeviceId { inner: self.inner.other_device_id().to_owned() }
}
/*
/// Get the device of the other user.
#[wasm_bindgen(js_name = "otherDevice")]
pub fn other_device(&self) {
todo!()
}
*/
/*
/// Get the unique ID that identifies this SAS verification flow.
#[wasm_bindgen(js_name = "flowId")]
pub fn flow_id(&self) {
todo!()
}
*/
/// Get the room ID if the verification is happening inside a
/// room.
#[wasm_bindgen(js_name = "roomId")]
pub fn room_id(&self) -> Option<RoomId> {
self.inner.room_id().map(ToOwned::to_owned).map(RoomId::new_with)
}
/// Does this verification flow support displaying emoji for the
/// short authentication string.
#[wasm_bindgen(js_name = "supportsEmoji")]
pub fn supports_emoji(&self) -> bool {
self.inner.supports_emoji()
}
/// Did this verification flow start from a verification request.
#[wasm_bindgen(js_name = "startedFromRequest")]
pub fn started_from_request(&self) -> bool {
self.inner.started_from_request()
}
/// Is this a verification that is veryfying one of our own
/// devices.
#[wasm_bindgen(js_name = "isSelfVerification")]
pub fn is_self_verification(&self) -> bool {
self.inner.is_self_verification()
}
/// Have we confirmed that the short auth string matches.
#[wasm_bindgen(js_name = "haveWeConfirmed")]
pub fn have_we_confirmed(&self) -> bool {
self.inner.have_we_confirmed()
}
/// Has the verification been accepted by both parties.
#[wasm_bindgen(js_name = "hasBeenAccepted")]
pub fn has_been_accepted(&self) -> bool {
self.inner.has_been_accepted()
}
/// Get info about the cancellation if the verification flow has
/// been cancelled.
#[wasm_bindgen(js_name = "cancelInfo")]
pub fn cancel_info(&self) -> Option<CancelInfo> {
self.inner.cancel_info().map(CancelInfo::new_with)
}
/// Did we initiate the verification flow.
#[wasm_bindgen(js_name = "weStarted")]
pub fn we_started(&self) -> bool {
self.inner.we_started()
}
/*
pub fn accept(&self) {
todo!()
}
*/
/*
#[wasm_bindgen(js_name = "acceptWithSettings")]
pub fn accept_with_settings(&self) {
todo!()
}
*/
/*
pub fn confirm(&self) {
todo!()
}
*/
/*
pub fn cancel(&self) {
todo!()
}
*/
/*
#[wasm_bindgen(js_name = "cancelWithCode")]
pub fn cancel_with_code(&self) {
todo!()
}
*/
/// Has the SAS verification flow timed out.
#[wasm_bindgen(js_name = "timedOut")]
pub fn timed_out(&self) -> bool {
self.inner.timed_out()
}
/// Are we in a state where we can show the short auth string.
#[wasm_bindgen(js_name = "canBePresented")]
pub fn can_be_presented(&self) -> bool {
self.inner.can_be_presented()
}
/// Is the SAS flow done.
#[wasm_bindgen(js_name = "isDone")]
pub fn is_done(&self) -> bool {
self.inner.is_done()
}
/// Is the SAS flow canceled.
#[wasm_bindgen(js_name = "isCancelled")]
pub fn is_cancelled(&self) -> bool {
self.inner.is_cancelled()
}
/// Get the emoji version of the short auth string.
///
/// Returns `undefined` if we can't yet present the short auth string,
/// otherwise seven tuples containing the emoji and description.
pub fn emoji(&self) -> Option<Array> {
Some(
self.inner
.emoji()?
.iter()
.map(|emoji| Emoji::new_with(emoji.clone()))
.map(JsValue::from)
.collect(),
)
}
/// Get the index of the emoji representing the short auth string
///
/// Returns `undefined` if we cant yet present the short auth
/// string, otherwise seven u8 numbers in the range from 0 to 63
/// inclusive which can be converted to an emoji using [the
/// relevant specification
/// entry](https://spec.matrix.org/unstable/client-server-api/#sas-method-emoji).
#[wasm_bindgen(js_name = "emoji_index")]
pub fn emoji_index(&self) -> Option<Array> {
Some(self.inner.emoji_index()?.iter().copied().map(JsValue::from).collect())
}
/// Get the decimal version of the short auth string.
///
/// Returns None if we cant yet present the short auth string,
/// otherwise a tuple containing three 4-digit integers that
/// represent the short auth string.
pub fn decimals(&self) -> Option<Array> {
let decimals = self.inner.decimals()?;
let out = Array::new_with_length(3);
out.set(0, JsValue::from(decimals.0));
out.set(1, JsValue::from(decimals.1));
out.set(2, JsValue::from(decimals.2));
Some(out)
}
}
/// QR code based verification.
#[cfg(feature = "qrcode")]
#[wasm_bindgen]
#[derive(Debug)]
pub struct Qr {
inner: matrix_sdk_crypto::QrVerification,
}
#[cfg(feature = "qrcode")]
#[wasm_bindgen]
impl Qr {
#[wasm_bindgen(js_name = "hasBeenScanned")]
pub fn has_been_scanned(&self) -> bool {
self.inner.has_been_scanned()
}
}
pub(crate) struct Verification(pub(crate) matrix_sdk_crypto::Verification);
impl TryFrom<Verification> for JsValue {
type Error = JsError;
fn try_from(verification: Verification) -> Result<Self, Self::Error> {
use matrix_sdk_crypto::Verification::*;
Ok(match verification.0 {
SasV1(sas) => JsValue::from(Sas { inner: sas }),
#[cfg(feature = "qrcode")]
QrV1(qr) => JsValue::from(Qr { inner: qr }),
_ => {
return Err(JsError::new(
"Unknown verification type, expect `m.sas.v1` only for now",
))
}
})
}
}
/// Information about the cancellation of a verification request or
/// verification flow.
#[wasm_bindgen]
#[derive(Debug)]
pub struct CancelInfo {
inner: matrix_sdk_crypto::CancelInfo,
}
impl CancelInfo {
pub(crate) fn new_with(inner: matrix_sdk_crypto::CancelInfo) -> Self {
Self { inner }
}
}
#[wasm_bindgen]
impl CancelInfo {
/// Get the human readable reason of the cancellation.
pub fn reason(&self) -> JsString {
self.inner.reason().into()
}
/// Get the `CancelCode` that cancelled this verification.
#[wasm_bindgen(js_name = "cancelCode")]
pub fn cancel_code(&self) -> CancelCode {
self.inner.cancel_code().into()
}
/// Was the verification cancelled by us?
#[wasm_bindgen(js_name = "cancelledbyUs")]
pub fn cancelled_by_us(&self) -> bool {
self.inner.cancelled_by_us()
}
}
/// An error code for why the process/request was cancelled by the
/// user.
#[wasm_bindgen]
#[derive(Debug)]
pub enum CancelCode {
/// Unknown cancel code.
Other,
/// The user cancelled the verification.
User,
/// The verification process timed out.
///
/// Verification processes can define their own timeout
/// parameters.
Timeout,
/// The device does not know about the given transaction ID.
UnknownTransaction,
/// The device does not know how to handle the requested method.
///
/// Should be sent for `m.key.verification.start` messages and
/// messages defined by individual verification processes.
UnknownMethod,
/// The device received an unexpected message.
///
/// Typically raised when one of the parties is handling the
/// verification out of order.
UnexpectedMessage,
/// The key was not verified.
KeyMismatch,
/// The expected user did not match the user verified.
UserMismatch,
/// The message received was invalid.
InvalidMessage,
/// An `m.key.verification.request` was accepted by a different
/// device.
///
/// The device receiving this error can ignore the verification
/// request.
Accepted,
/// The device receiving this error can ignore the verification
/// request.
MismatchedCommitment,
/// The SAS did not match.
MismatchedSas,
}
impl From<&RumaCancelCode> for CancelCode {
fn from(code: &RumaCancelCode) -> Self {
use RumaCancelCode::*;
match code {
User => Self::User,
Timeout => Self::Timeout,
UnknownTransaction => Self::UnknownTransaction,
UnknownMethod => Self::UnknownMethod,
UnexpectedMessage => Self::UnexpectedMessage,
KeyMismatch => Self::KeyMismatch,
UserMismatch => Self::UserMismatch,
InvalidMessage => Self::InvalidMessage,
Accepted => Self::Accepted,
MismatchedCommitment => Self::MismatchedCommitment,
MismatchedSas => Self::MismatchedSas,
_ => Self::Other,
}
}
}
/// An emoji that is used for interactive verification using a short
/// auth string.
///
/// This will contain a single emoji and description from the list of
/// emojis from [the specification].
///
/// [the specification]: https://spec.matrix.org/unstable/client-server-api/#sas-method-emoji
#[wasm_bindgen]
#[derive(Debug)]
pub struct Emoji {
inner: matrix_sdk_crypto::Emoji,
}
impl Emoji {
pub(crate) fn new_with(inner: matrix_sdk_crypto::Emoji) -> Self {
Self { inner }
}
}
#[wasm_bindgen]
impl Emoji {
/// The emoji symbol that represents a part of the short auth
/// string, for example: 🐶
#[wasm_bindgen(getter)]
pub fn symbol(&self) -> JsString {
self.inner.symbol.into()
}
/// The description of the emoji, for example Dog.
#[wasm_bindgen(getter)]
pub fn description(&self) -> JsString {
self.inner.description.into()
}
}

View File

@@ -11,8 +11,8 @@ where
}
}
impl Into<napi::Error> for Error {
fn into(self) -> napi::Error {
self.0
impl From<Error> for napi::Error {
fn from(value: Error) -> Self {
value.0
}
}

View File

@@ -2,6 +2,7 @@
use napi::bindgen_prelude::ToNapiValue;
use napi_derive::*;
use ruma::events::room::history_visibility::HistoryVisibility as RumaHistoryVisibility;
/// Who can see a room's history.
#[napi]
@@ -33,7 +34,7 @@ pub enum HistoryVisibility {
WorldReadable,
}
impl From<HistoryVisibility> for ruma::events::room::history_visibility::HistoryVisibility {
impl From<HistoryVisibility> for RumaHistoryVisibility {
fn from(value: HistoryVisibility) -> Self {
use HistoryVisibility::*;
@@ -46,15 +47,15 @@ impl From<HistoryVisibility> for ruma::events::room::history_visibility::History
}
}
impl Into<HistoryVisibility> for ruma::events::room::history_visibility::HistoryVisibility {
fn into(self) -> HistoryVisibility {
use HistoryVisibility::*;
impl From<RumaHistoryVisibility> for HistoryVisibility {
fn from(value: RumaHistoryVisibility) -> Self {
use RumaHistoryVisibility::*;
match self {
Self::Invited => Invited,
Self::Joined => Joined,
Self::Shared => Shared,
Self::WorldReadable => WorldReadable,
match value {
Invited => Self::Invited,
Joined => Self::Joined,
Shared => Self::Shared,
WorldReadable => Self::WorldReadable,
_ => unreachable!("Unknown variant"),
}
}

View File

@@ -50,6 +50,7 @@ impl UserId {
/// Return the user ID as a string.
#[napi(js_name = "toString")]
#[allow(clippy::inherent_to_string)]
pub fn to_string(&self) -> String {
self.inner.as_str().to_owned()
}
@@ -75,6 +76,7 @@ impl DeviceId {
/// Return the device ID as a string.
#[napi(js_name = "toString")]
#[allow(clippy::inherent_to_string)]
pub fn to_string(&self) -> String {
self.inner.as_str().to_owned()
}
@@ -115,6 +117,7 @@ impl RoomId {
/// Return the room ID as a string.
#[napi(js_name = "toString")]
#[allow(clippy::inherent_to_string)]
pub fn to_string(&self) -> String {
self.inner.as_str().to_owned()
}

View File

@@ -1,4 +1,4 @@
// Copyright 2020 The Matrix.org Foundation C.I.C.
// Copyright 2022 The Matrix.org Foundation C.I.C.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.

View File

@@ -48,22 +48,13 @@ thiserror = "1.0.30"
tracing = "0.1.34"
zeroize = { version = "1.3.0", features = ["zeroize_derive"] }
[target.'cfg(target_arch = "wasm32")'.dependencies.ruma]
version = "0.6.1"
features = ["client-api-c", "js", "rand", "signatures", "unstable-msc2676", "unstable-msc2677"]
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
ruma = { version = "0.6.2", features = ["client-api-c", "rand", "signatures", "unstable-msc2676", "unstable-msc2677"] }
vodozemac = { git = "https://github.com/matrix-org/vodozemac/", rev = "d0e744287a14319c2a9148fef3747548c740fc36" }
[target.'cfg(target_arch = "wasm32")'.dependencies.vodozemac]
git = "https://github.com/matrix-org/vodozemac/"
rev = "d0e744287a14319c2a9148fef3747548c740fc36"
features = ["js"]
[target.'cfg(not(target_arch = "wasm32"))'.dependencies.ruma]
version = "0.6.1"
features = ["client-api-c", "rand", "signatures", "unstable-msc2676", "unstable-msc2677"]
[target.'cfg(not(target_arch = "wasm32"))'.dependencies.vodozemac]
git = "https://github.com/matrix-org/vodozemac/"
rev = "d0e744287a14319c2a9148fef3747548c740fc36"
[target.'cfg(target_arch = "wasm32")'.dependencies]
ruma = { version = "0.6.2", features = ["client-api-c", "js", "rand", "signatures", "unstable-msc2676", "unstable-msc2677"] }
vodozemac = { git = "https://github.com/matrix-org/vodozemac/", rev = "d0e744287a14319c2a9148fef3747548c740fc36", features = ["js"] }
[dev-dependencies]
futures = { version = "0.3.21", default-features = false, features = ["executor"] }