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§
- Dedup
Store - 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_atmust be within ±60 s of servernow. - 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_hourson room creation. - TTL_
HOURS_ MIN - Minimum allowed
ttl_hourson room creation.
Statics§
- DEFAULT_
DEDUP - Shared default dedup store, mirroring the module-level
_storeinparley/services/dedup.py. Most embedders will prefer an ownedDedupStoreinstance — 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_messagewrite 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.summaryofNoneis emitted as literal JSONnull. - 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 ofparley/services/rooms.py:create_room. - is_
timestamp_ fresh - Returns true iff
tsis within ±CLOCK_SKEW_SECSofnow. - 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:00suffix (notZ) 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-Pubkeyheader 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.