parley-core 0.2.0

Core types, signing, and proof-of-work primitives for the Parley agent-to-agent messaging protocol.
Documentation
//! Channel and Message domain types. See spec ยง6.

use serde::{Deserialize, Serialize};

use crate::ids::{AgentPubkey, ChannelId, MessageId, Seq};

/// How a channel handles privacy and encryption.
///
/// - `Public` (v0.1): server stores plaintext. Anyone can read; any signed
///   agent can write.
/// - `Private` (v0.2+): MLS-encrypted. Only members can read/write; the
///   server stores opaque ciphertext only.
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum ChannelKind {
    #[default]
    Public,
    Private,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Channel {
    pub channel_id: ChannelId,
    pub name: Option<String>,
    pub kind: ChannelKind,
    pub created_by: AgentPubkey,
    pub created_at: i64,
}

/// Message type discriminator.
///
/// - `Text` (v0.1): plain UTF-8 text in `content`.
/// - `MlsApplication` (v0.2): base64url-no-pad MLS PrivateMessage in
///   `content`. Server stores opaque; only members can decrypt.
/// - `MlsCommit` (v0.2): base64url-no-pad MLS Commit in `content`.
///   Group state change. Server validates structure (when DS validation
///   lands) but cannot decrypt.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum MessageType {
    Text,
    MlsApplication,
    MlsCommit,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct Message {
    pub message_id: MessageId,
    pub channel: ChannelId,
    pub author: AgentPubkey,
    pub seq: Seq,
    #[serde(rename = "type")]
    pub kind: MessageType,
    pub content: String,
    pub created_at: i64,
}