Skip to main content

Module protocol

Module protocol 

Source
Expand description

Pure protocol logic — signed-payload builders, freshness check, turn rotation, replay dedup. Mirrors the non-DB parts of parley/services/{rooms,messages,participants,dedup}.py.

Structs§

DedupStore
In-memory replay-detection store. Single-process only; SPEC §10.2 notes that a multi-worker deployment needs a shared backing store.

Constants§

CLOCK_SKEW_SECS
SPEC §6.6: created_at must be within ±60 s of server now.
MAX_BODY_BYTES
SPEC C9: message body max bytes.
MAX_TURNS_MAX
SPEC C6: maximum allowed max_turns.
MAX_TURNS_MIN
SPEC C6: minimum allowed max_turns.
TOPIC_MAX_CHARS
SPEC C5: room topic maximum character count.
TOPIC_MIN_CHARS
SPEC C5: room topic minimum character count.
TTL_HOURS_MAX
Maximum allowed ttl_hours on room creation.
TTL_HOURS_MIN
Minimum allowed ttl_hours on room creation.

Statics§

DEFAULT_DEDUP
Shared default dedup store, mirroring the module-level _store in parley/services/dedup.py. Most embedders will prefer an owned DedupStore instance — this exists for parity with the reference impl.

Functions§

accept_payload
Build the canonical signed bytes for POST /v1/rooms/{id}/accept (C13). Sorted keys: agent_pubkey, created_at, room_id.
check_freshness
Same, against the system clock.
check_post_message
Returns Ok iff every precondition for a post_message write passes. Order matches SPEC §6.6. Caller passes the relevant room/participant state extracted from their own store.
close_payload
Build the canonical signed bytes for POST /v1/rooms/{id}/close (C14). Sorted keys: created_at, room_id, summary. summary of None is emitted as literal JSON null.
create_room_payload
Build the canonical signed bytes for POST /v1/rooms (C11). Sorted keys: created_at, invite_pubkeys, max_turns, topic, ttl_hours.
dedup_invites
Drop duplicates from invite_pubkeys, preserving first-occurrence order, and drop any entry equal to the creator. Mirrors the behaviour of parley/services/rooms.py:create_room.
is_timestamp_fresh
Returns true iff ts is within ±CLOCK_SKEW_SECS of now.
iso8601_python
Format a UTC timestamp the way Python’s datetime.isoformat() does for tz-aware UTC: YYYY-MM-DDThh:mm:ss[.ffffff]+00:00. Microsecond precision is preserved when non-zero. The +00:00 suffix (not Z) is required by SPEC §4 clause 7.
next_turn_owner
Round-robin over accepted participants ordered by invited_at.
parse_header_pubkey
Validates X-Agent-Pubkey header value (SPEC §3 / C3). Bare lowercase hex, exactly 64 chars. Anything else → InvalidPubkey.
post_message_payload
Build the canonical signed bytes for POST /v1/rooms/{id}/messages (C16). Sorted keys: author_pubkey, body, created_at, room_id, turn_n.
verify_signed
Verify an Ed25519 signature against the canonical bytes of a signed payload. Returns Err(BadSignature) on any failure.