Skip to main content

m4a_matrix_core/
lib.rs

1//! Matrix event layer, spike stage (F3.0).
2//!
3//! What it does: builds room events of room version 11 the way a foreign Matrix server expects
4//! them: no `event_id` on the wire, a content hash, an ed25519 signature over the redacted form,
5//! and an event id that is COMPUTED (`$` + url-safe unpadded base64 of the reference hash). It
6//! checks every new event against the room's auth rules before accepting it, and wraps
7//! `ruma-state-res` for state resolution over forked state.
8//!
9//! What it is not: no HTTP, no storage, no federation transport. Keys come in through a closure,
10//! so the crate does not care which ed25519 implementation the caller uses. All ruma types stay
11//! behind this crate's own small surface.
12
13mod builder;
14pub mod dag;
15mod pdu;
16mod resolve;
17mod signer;
18
19pub use builder::{BuildError, RoomBuilder, SignedEvent};
20pub use pdu::Pdu;
21pub use resolve::{auth_chain, auth_chain_with, resolve_state, resolve_state_with, ResolveError};
22pub use signer::Signer;
23
24pub use ruma_common::IdParseError as IdError;
25pub use ruma_common::{OwnedEventId, OwnedRoomId, OwnedUserId, RoomVersionId};
26pub use ruma_state_res::StateMap;
27pub use ruma_signatures::PublicKeyMap;
28pub use ruma_common::{CanonicalJsonObject, room_version_rules::RoomVersionRules};
29
30/// The room version this spike emits.
31pub const ROOM_VERSION: RoomVersionId = RoomVersionId::V11;
32
33pub use ruma_common::{CanonicalJsonValue, EventId};
34pub use ruma_events::StateEventType;
35
36/// A signing key as ruma wants it, from standard base64 (padded or not).
37pub fn key_from_b64(b64: &str) -> Result<ruma_common::serde::Base64, String> {
38    ruma_common::serde::Base64::parse(b64).map_err(|e| e.to_string())
39}
40
41/// Standard base64 of public key bytes.
42pub fn key_to_b64(bytes: &[u8]) -> String {
43    ruma_common::serde::Base64::<ruma_common::serde::base64::Standard>::new(bytes.to_vec()).encode()
44}