envelope

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 12, 2026 License: MIT Imports: 5 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Envelope

type Envelope struct {
	ID           string            `json:"id"`
	Source       string            `json:"source"`
	Destination  string            `json:"destination"`
	Protocol     protocol.Protocol `json:"protocol"`
	MessageType  MessageType       `json:"message_type"`
	ContentType  string            `json:"content_type"`
	Payload      []byte            `json:"payload"`
	Metadata     map[string]string `json:"metadata,omitempty"`
	Timestamp    time.Time         `json:"timestamp"`
	TTL          int               `json:"ttl,omitempty"`
	TraceID      string            `json:"trace_id,omitempty"`
	SessionID    string            `json:"session_id,omitempty"`
	Signature    string            `json:"signature,omitempty"`
	Nonce        string            `json:"nonce,omitempty"`
	Encrypted    bool              `json:"encrypted,omitempty"`
	SenderX25519 string            `json:"sender_x25519,omitempty"`
}

Envelope is the universal message wrapper that bridges different AI agent protocols. Every message flowing through PeerClaw is wrapped in an Envelope regardless of the originating protocol.

func New

func New(source, destination string, proto protocol.Protocol, payload []byte) *Envelope

New creates a new Envelope with a generated ID and timestamp.

func NewResponse added in v0.3.0

func NewResponse(req *Envelope, payload []byte) *Envelope

NewResponse creates a response envelope from a request envelope. It generates a new ID, copies TraceID and SessionID from the request, swaps Source and Destination, and sets MessageType to response.

func (*Envelope) GetSignature added in v0.4.0

func (e *Envelope) GetSignature() string

GetSignature returns the envelope's signature field.

func (*Envelope) SetSignature added in v0.4.0

func (e *Envelope) SetSignature(sig string)

SetSignature sets the envelope's signature field.

func (*Envelope) SigningPayload added in v0.4.0

func (e *Envelope) SigningPayload() []byte

SigningPayload returns a canonical byte representation of the envelope's security-critical fields for signing. This covers Source, Destination, Protocol, MessageType, Nonce, Timestamp, and Payload — preventing an attacker from modifying routing or replay-protection fields without invalidating the signature.

This implements the identity.SignableEnvelope interface.

func (*Envelope) WithMetadata

func (e *Envelope) WithMetadata(key, value string) *Envelope

WithMetadata adds a metadata key-value pair and returns the envelope for chaining.

func (*Envelope) WithSessionID added in v0.2.0

func (e *Envelope) WithSessionID(sessionID string) *Envelope

WithSessionID sets the session ID for multi-turn conversations and returns the envelope for chaining.

type MessageType

type MessageType string

MessageType categorizes the purpose of a message.

const (
	MessageTypeRequest  MessageType = "request"
	MessageTypeResponse MessageType = "response"
	MessageTypeEvent    MessageType = "event"
	MessageTypeError    MessageType = "error"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL