Skip to main content

AgentMessage

Struct AgentMessage 

Source
pub struct AgentMessage {
    pub message_id: String,
    pub from: AgentIdentity,
    pub to: AgentIdentity,
    pub message_type: AgentMessageType,
    pub payload: Vec<u8>,
    pub timestamp: Timestamp,
    pub signature: Option<Vec<u8>>,
    pub pq_signature: Option<Vec<u8>>,
    pub reply_to: Option<String>,
}
Expand description

A message between agents on Tenzro Network

Wave 3d hybrid signing: signed messages carry BOTH signature (Ed25519 classical) and pq_signature (ML-DSA-65). When the message is signed, both legs are Some(_). When the message is unsigned (trusted single-process tests), both legs are None. Mixing — one Some, one None — is rejected by the router.

Fields§

§message_id: String

Message ID

§from: AgentIdentity

Sender agent

§to: AgentIdentity

Recipient agent

§message_type: AgentMessageType

Message type

§payload: Vec<u8>

Message payload

§timestamp: Timestamp

Message timestamp

§signature: Option<Vec<u8>>

Classical Ed25519 message signature (None when unsigned)

§pq_signature: Option<Vec<u8>>

Post-quantum ML-DSA-65 message signature (3309 bytes when signed, None when unsigned). Must be present whenever signature is present.

§reply_to: Option<String>

Reply-to message ID (if this is a reply)

Implementations§

Source§

impl AgentMessage

Source

pub fn new( from: AgentIdentity, to: AgentIdentity, message_type: AgentMessageType, payload: Vec<u8>, ) -> Self

Creates a new agent message

Source

pub fn as_reply_to(self, message_id: String) -> Self

Sets the message as a reply to another message

Source

pub fn with_signature(self, signature: Vec<u8>) -> Self

Adds a classical-only signature to the message.

Wave 3d hybrid signing: this is the classical (Ed25519) leg only. Production agent message production should call with_hybrid_signature instead so both legs are populated; the router rejects messages with only the classical leg present.

Source

pub fn with_hybrid_signature(self, classical: Vec<u8>, pq: Vec<u8>) -> Self

Adds a full hybrid (Ed25519 + ML-DSA-65) signature to the message.

Source

pub fn signing_data(&self) -> Vec<u8>

Returns the canonical bytes that should be signed.

This deliberately excludes the signature field so that signing followed by verifying yields a stable hash. The encoding is a simple length-prefixed concatenation of the message-determining fields:

signing_data = len(message_id) || message_id
             || from.agent_id_len || from.agent_id || from.address
             || to.agent_id_len   || to.agent_id   || to.address
             || message_type_tag (u8)
             || payload_len (u64 LE) || payload
             || timestamp_millis (i64 LE)
             || reply_to_present (u8) [|| reply_to_len || reply_to]

All len() fields are encoded as little-endian u64 for deterministic, length-prefixed framing. This avoids ambiguity attacks where two different field arrangements collide into the same byte stream (e.g. concatenating two strings without a length prefix).

Source

pub fn hash(&self) -> Hash

Computes the SHA-256 hash of the message’s canonical signing data.

This is the value passed to a signer when producing the signature field, and the value verified against the public key when validating an inbound message. Because it is computed from Self::signing_data, the signature field itself is not included in the hash, so signing is idempotent.

Trait Implementations§

Source§

impl Clone for AgentMessage

Source§

fn clone(&self) -> AgentMessage

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AgentMessage

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for AgentMessage

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for AgentMessage

Source§

impl PartialEq for AgentMessage

Source§

fn eq(&self, other: &AgentMessage) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for AgentMessage

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for AgentMessage

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.