Skip to main content

parley_core/
lib.rs

1//! Parley core domain types.
2//!
3//! This crate defines the wire types and identifiers for the Parley protocol
4//! as specified in `spec/v0.1.md` (with auth refactored per `spec/v0.4.md` §2).
5//! Types are deliberately thin: this crate contains no business logic, no I/O,
6//! no traits. It is depended on by every other crate in the workspace.
7
8#![allow(clippy::module_name_repetitions)]
9
10mod error;
11mod ids;
12pub mod keys;
13mod message;
14pub mod pow;
15mod signing;
16
17pub use error::CoreError;
18pub use ids::{AgentPubkey, BlobId, ChannelId, MessageId, NetworkId, Nonce, Seq};
19pub use keys::{
20    derive_auth_mldsa, derive_identity_ed25519, AuthKeyPair, MLDSA65SigningKey, SEED_BYTES,
21};
22pub use message::{Channel, ChannelKind, Message, MessageType};
23pub use signing::{
24    body_sha256_b64url, build_header_value, canonical_query_string, canonical_string, ml_dsa_sign,
25    ml_dsa_verify, parse_header_value, verify_signature, MlDsaError, ParsedSignature,
26    SignatureParseError, SignatureVerifyError, EMPTY_BODY_SHA256, ML_DSA_PUBKEY_BYTES,
27    ML_DSA_SIG_BYTES, SIGNATURE_HEADER, SIGNATURE_VERSION,
28};
29
30/// Maximum allowed `|now - ts|` in seconds for signature freshness.
31pub const TIMESTAMP_WINDOW_SECS: i64 = 60;
32
33/// Minimum window for which servers must remember nonces, in seconds.
34/// Must be at least 2× TIMESTAMP_WINDOW_SECS so an edge-of-skew request
35/// cannot be replayed by walking the clock.
36pub const NONCE_RETENTION_SECS: i64 = 120;
37
38/// Maximum size of a `text` message `content` field, in UTF-8 bytes.
39pub const MAX_TEXT_CONTENT_BYTES: usize = 4096;
40
41/// Maximum size of an MLS message `content` field (base64url-encoded
42/// bytes on the wire). Generous to accommodate large group commits.
43pub const MAX_MLS_CONTENT_BYTES: usize = 1024 * 1024;
44
45/// Maximum size of an `Idempotency-Key` header value, in bytes.
46pub const MAX_IDEMPOTENCY_KEY_BYTES: usize = 128;
47
48/// Minimum window servers must retain idempotency records, in seconds.
49pub const IDEMPOTENCY_RETENTION_SECS: i64 = 24 * 60 * 60;