agent-rooms 0.1.0

Rust port of the parley protocol core (@p-vbordei/agent-rooms): canonical encoding, Ed25519 signing, message validation
Documentation
//! Parley protocol errors. Mirrors `parley/errors.py`.
//!
//! Each variant maps to one of the HTTP error codes in SPEC §9. The library
//! does not produce HTTP responses; consumers translate these to their own
//! transport.

use thiserror::Error;

#[derive(Debug, Error, Clone, PartialEq, Eq)]
pub enum Error {
    /// HTTP 400 — header pubkey malformed or not 32 bytes.
    #[error("invalid pubkey")]
    InvalidPubkey,

    /// HTTP 400 — `created_at` outside the +/- 60 s window.
    #[error("created_at outside acceptable window")]
    StaleTimestamp,

    /// HTTP 401 — Ed25519 verification failed, or sig not 64 bytes of hex.
    #[error("invalid signature")]
    BadSignature,

    /// HTTP 403 — caller's pubkey not in the room, or not authorized for close.
    #[error("not a participant of this room")]
    NotAParticipant,

    /// HTTP 403 — caller is a participant but not the current `turn_owner`.
    #[error("not your turn")]
    NotTurnOwner,

    /// HTTP 404 — room UUID does not resolve.
    #[error("room not found")]
    RoomNotFound,

    /// HTTP 409 — room is `closed` or past `ttl_until`.
    #[error("room is closed or expired")]
    RoomClosed,

    /// HTTP 409 — `turn_n != room.turn_n + 1`.
    #[error("turn_n conflict: expected {expected}, got {got}")]
    TurnConflict { expected: i64, got: i64 },

    /// HTTP 409 — duplicate `create_room` signed payload within the window.
    #[error("duplicate signed payload within freshness window")]
    ReplayDetected,

    /// HTTP 413 — message body byte-length > 16 384.
    #[error("message body too large")]
    BodyTooLarge,

    /// Malformed JSON input passed into a library helper.
    #[error("invalid json: {0}")]
    InvalidJson(String),

    /// Hex decoding failure on a pubkey / signature.
    #[error("invalid hex: {0}")]
    InvalidHex(String),
}