Skip to content

Commit

Permalink
Merge branch 'main' of github.com:matrix-org/matrix-rust-sdk into jon…
Browse files Browse the repository at this point in the history
…ny/timeline-reactions
  • Loading branch information
jonnyandrew committed Jun 22, 2023
2 parents af266d9 + 7fd5068 commit d52869f
Show file tree
Hide file tree
Showing 117 changed files with 7,242 additions and 2,863 deletions.
45 changes: 37 additions & 8 deletions Cargo.lock

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

9 changes: 3 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ futures-core = "0.3.28"
futures-executor = "0.3.21"
futures-util = { version = "0.3.26", default-features = false, features = ["alloc"] }
http = "0.2.6"
ruma = { git = "https://github.com/ruma/ruma", rev = "beded100acb7cde34d5f2e67f194a25b35410f99", features = ["client-api-c", "compat-user-id"] }
ruma-common = { git = "https://github.com/ruma/ruma", rev = "beded100acb7cde34d5f2e67f194a25b35410f99" }
itertools = "0.10.5"
ruma = { git = "https://github.com/ruma/ruma", rev = "cf32036df4c9daca736dcd7f0d9d65debcf9897f", features = ["client-api-c", "compat-user-id"] }
ruma-common = { git = "https://github.com/ruma/ruma", rev = "cf32036df4c9daca736dcd7f0d9d65debcf9897f" }
once_cell = "1.16.0"
serde = "1.0.151"
serde_html_form = "0.2.0"
Expand Down Expand Up @@ -75,10 +76,6 @@ debug = 2
# `--profile reldbg` to select
[profile.reldbg]
inherits = "dev"
incremental = false

# Compile all non-workspace crate in the dependency tree with optimizations
[profile.reldbg.package."*"]
opt-level = 3

[patch.crates-io]
Expand Down
17 changes: 11 additions & 6 deletions benchmarks/benches/store_bench.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use criterion::*;
use matrix_sdk::{config::StoreConfig, Client, RoomInfo, RoomState, Session, StateChanges};
use matrix_sdk_base::{store::MemoryStore, StateStore as _};
use matrix_sdk::{
config::StoreConfig,
matrix_auth::{Session, SessionTokens},
Client, RoomInfo, RoomState, StateChanges,
};
use matrix_sdk_base::{store::MemoryStore, SessionMeta, StateStore as _};
use matrix_sdk_sqlite::SqliteStateStore;
use ruma::{device_id, user_id, RoomId};
use tokio::runtime::Builder;
Expand Down Expand Up @@ -41,10 +45,11 @@ pub fn restore_session(c: &mut Criterion) {
}

let session = Session {
access_token: "OHEY".to_owned(),
refresh_token: None,
user_id: user_id!("@somebody:example.com").to_owned(),
device_id: device_id!("DEVICE_ID").to_owned(),
meta: SessionMeta {
user_id: user_id!("@somebody:example.com").to_owned(),
device_id: device_id!("DEVICE_ID").to_owned(),
},
tokens: SessionTokens { access_token: "OHEY".to_owned(), refresh_token: None },
};

// Start the benchmark.
Expand Down
4 changes: 4 additions & 0 deletions bindings/matrix-sdk-crypto-ffi/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ pub struct Device {
/// Is our cross signing identity trusted and does the identity trust the
/// device.
pub cross_signing_trusted: bool,
/// The first time this device was seen in local timestamp, seconds since
/// epoch.
pub first_time_seen_ts: u64,
}

impl From<InnerDevice> for Device {
Expand All @@ -38,6 +41,7 @@ impl From<InnerDevice> for Device {
is_blocked: d.is_blacklisted(),
locally_trusted: d.is_locally_trusted(),
cross_signing_trusted: d.is_cross_signing_trusted(),
first_time_seen_ts: d.first_time_seen_ts().0.into(),
}
}
}
16 changes: 12 additions & 4 deletions bindings/matrix-sdk-crypto-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ pub use responses::{
};
use ruma::{
events::room::history_visibility::HistoryVisibility as RustHistoryVisibility,
DeviceKeyAlgorithm, OwnedDeviceId, OwnedUserId, RoomId, SecondsSinceUnixEpoch, UserId,
DeviceKeyAlgorithm, MilliSecondsSinceUnixEpoch, OwnedDeviceId, OwnedUserId, RoomId,
SecondsSinceUnixEpoch, UserId,
};
use serde::{Deserialize, Serialize};
use tokio::runtime::Runtime;
Expand Down Expand Up @@ -244,6 +245,7 @@ async fn migrate_data(
pickle,
shared: data.account.shared,
uploaded_signed_key_count: data.account.uploaded_signed_key_count as u64,
creation_local_time: MilliSecondsSinceUnixEpoch(UInt::default()),
};
let account = matrix_sdk_crypto::olm::ReadOnlyAccount::from_pickle(pickled_account)?;

Expand Down Expand Up @@ -284,8 +286,8 @@ async fn migrate_data(
let tracked_users: Vec<_> = data
.tracked_users
.into_iter()
.map(|u| Ok(((parse_user_id(&u)?), true)))
.collect::<anyhow::Result<_>>()?;
.filter_map(|s| parse_user_id(&s).ok().map(|u| (u, true)))
.collect();

let tracked_users: Vec<_> = tracked_users.iter().map(|(u, d)| (&**u, *d)).collect();
store.save_tracked_users(tracked_users.as_slice()).await?;
Expand Down Expand Up @@ -965,7 +967,8 @@ mod test {
"@ganfra146:matrix.org",
"@this-is-me:matrix.org",
"@Amandine:matrix.org",
"@ganfra:matrix.org"
"@ganfra:matrix.org",
"NotAUser%ID"
],
"room_settings": {
"!AZkqtjvtwPAuyNOXEt:matrix.org": {
Expand Down Expand Up @@ -1034,6 +1037,11 @@ mod test {
let settings3 = machine.get_room_settings("!XYZ:matrix.org".into())?;
assert!(settings3.is_none());

assert!(machine.is_user_tracked("@ganfra146:matrix.org".into()).unwrap());
assert!(machine.is_user_tracked("@Amandine:matrix.org".into()).unwrap());
assert!(machine.is_user_tracked("@this-is-me:matrix.org".into()).unwrap());
assert!(machine.is_user_tracked("@ganfra:matrix.org".into()).unwrap());

Ok(())
}
}
10 changes: 10 additions & 0 deletions bindings/matrix-sdk-crypto-js/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
# v0.1.0-alpha.11

## Changes in the Javascript bindings

- Simplify the response type of `Sas.confirm()`.
- Add `VerificationRequest.registerChangesCallback()`,
`Sas.registerChangesCallback()`, and `Qr.registerChangesCallback()`.
- Add `VerificationRequest.phase()` and `VerificationRequest.getVerification()`.

## Changes in the underlying Rust crate

- Add support for the `hkdf-hmac-sha256.v2` SAS message authentication code.

- Ensure that the correct short authentication strings are used when accepting a
SAS verification with the `Sas::accept()` method.

# v0.1.0-alpha.10

- Add `masterKey`, `userSigningKey`, `selfSigningKey` to `UserIdentity` and `OwnUserIdentity`
Expand Down
2 changes: 1 addition & 1 deletion bindings/matrix-sdk-crypto-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@matrix-org/matrix-sdk-crypto-js",
"version": "0.1.0-alpha.10",
"version": "0.1.0-alpha.11",
"homepage": "https://github.com/matrix-org/matrix-rust-sdk",
"description": "Matrix encryption library, for JavaScript",
"license": "Apache-2.0",
Expand Down
7 changes: 7 additions & 0 deletions bindings/matrix-sdk-crypto-js/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ impl Device {
pub fn is_deleted(&self) -> bool {
self.inner.is_deleted()
}

/// Timestamp representing the first time this device has been seen (in
/// milliseconds).
#[wasm_bindgen(js_name = "firstTimeSeen")]
pub fn first_time_seen(&self) -> u64 {
self.inner.first_time_seen_ts().0.into()
}
}

/// The local trust state of a device.
Expand Down
24 changes: 11 additions & 13 deletions bindings/matrix-sdk-crypto-js/src/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,9 @@ impl Sas {
/// This confirms that the short auth strings match on both sides.
///
/// Does nothing if we’re not in a state where we can confirm the
/// short auth string, otherwise returns a `MacEventContent` that
/// needs to be sent to the server.
/// short auth string.
///
/// Returns a `Promise` for an array of `OutgoingRequest`s.
pub fn confirm(&self) -> Promise {
let me = self.inner.clone();

Expand All @@ -262,17 +263,14 @@ impl Sas {
.map(JsValue::try_from)
.collect::<Result<Array, _>>()?;

let tuple = Array::new();
tuple.set(0, outgoing_verification_requests.into());
tuple.set(
1,
signature_upload_request
.map(|request| requests::SignatureUploadRequest::try_from(&request))
.transpose()?
.into(),
);

Ok(tuple)
// if a signature upload request was returned, push it onto the end of the array
// of OutgoingRequests we just built.
if let Some(sig_rq) = signature_upload_request {
outgoing_verification_requests
.push(&requests::SignatureUploadRequest::try_from(&sig_rq)?.into());
}

Ok(outgoing_verification_requests)
})
}

Expand Down
Loading

0 comments on commit d52869f

Please sign in to comment.