Sigil documentation
ReferenceRust referencesigil-czac

sigil-czac · channel

Source declarations, signatures and documentation for channel.

Source: sigil/node/sigil-czac/src/channel.rs. SHA-256: b8a5b579ba269b40c30c72bdf9f5ba9c1d307832106c0402ba892689d03f89be.

This reference follows declared source modules, retains conditional attributes, and includes public declarations and implementation methods. Private-module re-exports and trait resolution require the compiler; this is a source reference, not a claim that every listed item is a root import. Function bodies and constant values are omitted.

channel::ChannelType

Channel type determines the lifecycle and behavior of the channel.

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum ChannelType {
    /// Short-lived channel that auto-closes after inactivity.
    Ephemeral {
        /// Seconds of inactivity before auto-close (default: 300).
        auto_close_secs: u64,
    },
    /// Long-lived channel with periodic heartbeats.
    Persistent {
        /// Seconds between heartbeats.
        heartbeat_interval: u64,
    },
    /// Pub/sub channel for one-to-many messaging.
    Broadcast {
        /// Maximum number of subscribers.
        max_subscribers: u32,
    },
    /// Payment channel with escrow for economic transactions.
    Payment {
        /// Escrow amount in micro-MINT.
        escrow_amount: u64,
    },
}

Source line: 43.

channel::ChannelState

Channel state machine states.

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum ChannelState {
    /// Initial state — channel created, handshake not started.
    Init,
    /// Challenge issued by the responder; awaiting signed response.
    ChallengeIssued {
        /// The 32-byte random challenge.
        challenge: [u8; 32],
    },
    /// Initiator has responded with an Ed25519 signature over the transcript.
    ///
    /// The 64-byte signature is stored (as bytes) so the responder can include
    /// it in audit logs and so future verification paths can re-check the proof.
    ChallengeResponded {
        /// The 64-byte Ed25519 signature from the initiator, serialized as bytes.
        signature: Vec<u8>,
    },
    /// Handshake confirmed by both parties.
    Confirmed,
    /// Channel is open and ready for message exchange.
    Open {
        /// Unix timestamp when the channel was opened.
        opened_at: u64,
    },
    /// Channel close has been requested.
    Closing {
        /// Unix timestamp when close was requested.
        close_requested_at: u64,
    },
    /// Channel is closed and no longer usable.
    Closed,
}

Source line: 68.

channel::Channel

A cross-zone communication channel.

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Channel {
/// Unique channel identifier (UUID v4).

pub channel_id: String,
/// The channel type and its parameters.

pub channel_type: ChannelType,
/// OAS DID of the channel initiator.

pub initiator_did: String,
/// OAS DID of the channel responder.

pub responder_did: String,
/// Source organization zone.

pub source_zone: String,
/// Target organization zone.

pub target_zone: String,
/// Current channel state.

pub state: ChannelState,
/// Unix timestamp when the channel was created.

pub created_at: u64,
/// Unix timestamp of the last activity on this channel.

pub last_activity: u64,
/// Number of messages sent on this channel.

pub messages_sent: u64,
/// Number of messages received on this channel.

pub messages_received: u64
}

Source line: 117.

channel::HandshakeMessage

Handshake messages exchanged during channel establishment.

The 5-step handshake:

  1. Initiator sends Request
  2. Responder sends Challenge
  3. Initiator sends Response (Ed25519 signature over domain-separated transcript)
  4. Responder sends Confirm
  5. Either party sends Open
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum HandshakeMessage {
    /// Step 1: Channel open request from the initiator.
    Request {
        /// Requested channel type.
        channel_type: ChannelType,
        /// OAS DID of the initiator.
        initiator_did: String,
        /// Source zone of the initiator.
        source_zone: String,
    },
    /// Step 2: Challenge from the responder.
    Challenge {
        /// 32-byte cryptographic random challenge.
        challenge: [u8; 32],
    },
    /// Step 3: Challenge response from the initiator.
    Response {
        /// 64-byte Ed25519 signature over the domain-separated transcript.
        ///
        /// Signed by the initiator's long-term Ed25519 key (resolved via DID).
        /// The responder verifies this against the initiator's published key.
        /// Serialized as bytes (Vec<u8>) because serde only derives [u8; N] for N <= 32.
        challenge_response: Vec<u8>,
        /// Key material for session key derivation.
        session_key_material: Vec<u8>,
    },
    /// Step 4: Confirmation from the responder.
    Confirm {
        /// Key material for session key derivation.
        session_key_material: Vec<u8>,
    },
    /// Step 5: Channel is now open.
    Open,
}

Source line: 151.

channel::ChannelManager

Manages all active channels and their state transitions.

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ChannelManager {

}

Source line: 188.

channel::ChannelManager::new

Create a new, empty channel manager.

pub fn new() -> Self;

Source line: 197.

channel::ChannelManager::initiate

Initiate a new channel handshake.

Creates a channel in Init state and returns the channel ID and the first handshake message (Request) to send to the responder.

pub fn initiate(
        &mut self,
        channel_type: ChannelType,
        initiator_did: String,
        responder_did: String,
        source_zone: String,
        target_zone: String,
    ) -> Result<(String, HandshakeMessage), CzacError>;

Source line: 208.

channel::ChannelManager::handle_handshake

Process a handshake message for a given channel.

Returns Ok(Some(reply)) if a reply handshake message should be sent, or Ok(None) if the handshake step was terminal (e.g., Open).

Signature-based challenge verification (steps 2 → 3)

When the responder processes a Response message, it verifies the Ed25519 signature using [verify_handshake_signature]. Verification failure causes an immediate HandshakeError — the channel is NOT advanced to Confirmed.

In the test-only path (via [handle_handshake_with_key]) the caller supplies the verifying key directly. In the production path the key would be resolved via DID; the signature API is identical.

pub fn handle_handshake(
        &mut self,
        channel_id: &str,
        message: HandshakeMessage,
    ) -> Result<Option<HandshakeMessage>, CzacError>;

Source line: 287.

channel::ChannelManager::handle_handshake_with_signing_key

Process a step-2→3 Challenge message using a caller-supplied signing key.

This is the production entry point for the initiator side of the handshake: the caller resolves the signing key from the DID store and passes it here. The signature is created over the full domain-separated transcript so the responder can verify it against the published verifying key.

Errors

Returns [CzacError::HandshakeError] if the channel is not in ChallengeIssued state or if the challenge does not match.

pub fn handle_handshake_with_signing_key(
        &mut self,
        channel_id: &str,
        received_challenge: [u8; 32],
        signing_key: &SigningKey,
    ) -> Result<HandshakeMessage, CzacError>;

Source line: 411.

channel::ChannelManager::handle_handshake_with_verifying_key

Process a step-3→4 Response message and verify the Ed25519 signature.

This is the production entry point for the responder side: the caller resolves the initiator's verifying key from its DID document and passes it here. The signature is verified against the full domain-separated transcript reconstructed from the channel's stored state.

Errors

Returns [CzacError::HandshakeError] immediately on signature failure — the channel state is not advanced.

pub fn handle_handshake_with_verifying_key(
        &mut self,
        channel_id: &str,
        challenge: [u8; 32],
        challenge_response: Vec<u8>,
        verifying_key_bytes: &[u8; 32],
        session_key_material: Vec<u8>,
    ) -> Result<HandshakeMessage, CzacError>;

Source line: 469.

channel::ChannelManager::close

Close a channel.

Transitions the channel to Closing if open, or directly to Closed if it was in a handshake state.

pub fn close(&mut self, channel_id: &str) -> Result<(), CzacError>;

Source line: 506.

channel::ChannelManager::get

Get a reference to a channel by its ID.

pub fn get(&self, channel_id: &str) -> Option<&Channel>;

Source line: 538.

channel::ChannelManager::get_mut

Get a mutable reference to a channel by its ID.

pub fn get_mut(&mut self, channel_id: &str) -> Option<&mut Channel>;

Source line: 543.

channel::ChannelManager::channels_for_zone_pair

Find all channels between a source and target zone.

pub fn channels_for_zone_pair(&self, source: &str, target: &str) -> Vec<&Channel>;

Source line: 548.

channel::ChannelManager::cleanup_expired

Remove expired ephemeral channels. Returns the IDs of removed channels.

pub fn cleanup_expired(&mut self, now: u64) -> Vec<String>;

Source line: 556.

channel::ChannelManager::len

Returns the total number of channels (all states).

pub fn len(&self) -> usize;

Source line: 595.

channel::ChannelManager::is_empty

Returns true if there are no channels.

pub fn is_empty(&self) -> bool;

Source line: 600.

channel::build_handshake_transcript

Build the domain-separated transcript that the initiator signs during step 3.

transcript = DOMAIN_TAG
             || channel_id || "\n"
             || source_zone || "\n"
             || target_zone || "\n"
             || challenge (32 bytes, raw)

Each text field is separated by a newline byte so the encoding is unambiguous regardless of field content.

pub fn build_handshake_transcript(
    channel_id: &str,
    source_zone: &str,
    target_zone: &str,
    challenge: &[u8; 32],
) -> Vec<u8>;

Source line: 627.

channel::verify_handshake_signature

Verify an Ed25519 handshake signature.

Returns Ok(()) if the signature is valid. Returns [CzacError::HandshakeError] on any failure — including invalid key bytes, invalid signature bytes, or verification mismatch. The error message does not reveal whether the failure was due to a key parse error or a signature mismatch to avoid oracle attacks.

pub fn verify_handshake_signature(
    verifying_key_bytes: &[u8; 32],
    transcript: &[u8],
    signature_bytes: &[u8],
) -> Result<(), CzacError>;

Source line: 661.

On this page