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, build_sealed_header_value, canonical_query_string,
25    canonical_string, derive_sealed_post_key, ml_dsa_sign, ml_dsa_verify, parse_header_value,
26    parse_sealed_header_value, post_canonical_string, sealed_canonical_string, sealed_token_mac,
27    sign_post, verify_post, verify_sealed_token, verify_signature, MlDsaError, ParsedSealed,
28    ParsedSignature, SealedTokenError, SignatureParseError, SignatureVerifyError,
29    EMPTY_BODY_SHA256, ML_DSA_PUBKEY_BYTES, ML_DSA_SIG_BYTES, POST_CONTEXT, SEALED_KEY_BYTES,
30    SEALED_LABEL, SEALED_SIGNATURE_VERSION, SIGNATURE_HEADER, SIGNATURE_VERSION,
31};
32
33/// Maximum allowed `|now - ts|` in seconds for signature freshness.
34pub const TIMESTAMP_WINDOW_SECS: i64 = 60;
35
36/// Minimum window for which servers must remember nonces, in seconds.
37/// Must be at least 2× TIMESTAMP_WINDOW_SECS so an edge-of-skew request
38/// cannot be replayed by walking the clock.
39pub const NONCE_RETENTION_SECS: i64 = 120;
40
41/// Maximum size of a `text` message `content` field, in UTF-8 bytes.
42pub const MAX_TEXT_CONTENT_BYTES: usize = 4096;
43
44/// Maximum size of an MLS message `content` field (base64url-encoded
45/// bytes on the wire). Generous to accommodate large group commits.
46pub const MAX_MLS_CONTENT_BYTES: usize = 1024 * 1024;
47
48/// Maximum size of an `Idempotency-Key` header value, in bytes.
49pub const MAX_IDEMPOTENCY_KEY_BYTES: usize = 128;
50
51/// Maximum size of a contact-request `intro` message, in UTF-8 bytes.
52pub const MAX_INTRO_BYTES: usize = 280;
53
54/// Maximum size of a signed public post's `content`, in UTF-8 bytes.
55pub const MAX_POST_CONTENT_BYTES: usize = 16 * 1024;
56
57/// Maximum size of a reaction token (e.g. "like"), in UTF-8 bytes.
58pub const MAX_REACTION_BYTES: usize = 32;
59
60/// Minimum window servers must retain idempotency records, in seconds.
61pub const IDEMPOTENCY_RETENTION_SECS: i64 = 24 * 60 * 60;