//! Platform-agnostic core for the Ping messaging SDK.
//!
//! This crate owns OpenMLS state machines and exposes a transport-/storage-agnostic API.
//! Native and WASM bindings are thin wrappers around [`MessagingClient`].

#![deny(unsafe_code)]
#![warn(rust_2018_idioms, missing_debug_implementations)]

pub mod clock;
pub mod codec;
pub mod conversation;
pub mod device;
pub mod error;
pub mod identity;
pub mod log_filter;
pub mod message;
pub mod storage;
pub mod storage_blob;
pub mod sync;
pub mod transport;

mod client;

pub use client::{AdmitChatOutcome, AdmitChatStatus, ClientConfig, MessagingClient};
pub use clock::Hlc;
pub use conversation::{Conversation, ConversationId, ConversationMeta, MemberInfo};
pub use device::{
    CatchupAppEventEntry, CatchupConversationEntry, CatchupSnapshot, DeviceId, DeviceInfo,
    GroupSnapshotEntry, GroupStateSnapshot, LinkingTicket, CATCHUP_SNAPSHOT_HARD_CAP,
    CATCHUP_SNAPSHOT_SOFT_CAP, CATCHUP_SNAPSHOT_VERSION, GROUP_SNAPSHOT_HARD_CAP,
    GROUP_SNAPSHOT_SOFT_CAP, GROUP_SNAPSHOT_VERSION,
};
pub use error::{Error, Result};
pub use identity::{Identity, UserId};
pub use message::{IncomingMessage, MessageEnvelope, MessageKind, OutgoingMessage};
/// [CR-4] re-export so hosts can build `ClientConfig { storage_backend: … }` without
/// pulling `ping_mls_store` in directly. `AsyncBlobStore` is the async
/// single-blob trait WASM hosts implement to back `StorageBackend::IndexedDb`;
/// `BlobFuture` is the matching future-type helper.
pub use ping_mls_store::{AsyncBlobStore, BlobFuture, StorageBackend};
pub use storage::Storage;
/// [CR-4] Wrap an `Arc<dyn Storage>` as the single-blob backend the
/// persistent provider needs. Hosts pass the result as
/// `StorageBackend::AsyncBlob { blob_store }` to opt their existing
/// Storage trait into MLS-state persistence with no extra wiring.
pub use storage_blob::storage_as_blob_store;
pub use sync::SyncCursor;
pub use transport::{Transport, TransportSubscription};

/// Wire-format version. Bumped only on incompatible envelope changes.
///
/// **v=2** ([CR-6](../ping-prime-architecture.md#cr-6)): for `MessageKind::Application`,
/// `content_hash` is computed over the **plaintext** instead of the ciphertext payload.
/// Handshake kinds (`Commit` / `Welcome` / `Proposal` / `KeyPackage`) keep the v=1 semantics
/// — `content_hash = SHA-256(kind || payload)`. See `MessageEnvelope::new_application` for
/// the production constructor.
///
/// Receivers run a 90-day dual-accept window per Q-ARCH-02: any envelope with `v ∈ {1, 2}`
/// is structurally accepted; the validate layer routes hash-check semantics by version.
/// Clients SHOULD refuse v=1 once the window expires.
pub const WIRE_VERSION: u8 = 2;

/// The lowest envelope version that receivers will accept during the CR-6 dual-accept
/// transition. Bumped to `2` after the window closes; until then it stays at `1` so we
/// keep accepting messages produced by un-updated senders.
pub const WIRE_VERSION_MIN_ACCEPTED: u8 = 1;
