sigil-czac · payment
Source declarations, signatures and documentation for payment.
Source: sigil/node/sigil-czac/src/payment.rs. SHA-256: 4034bf3daff47fd3728e90dc3e7a9e60817915ad7ad3288744e8082f3870d46c.
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.
payment::DEFAULT_DISPUTE_WINDOW
Default dispute window in blocks.
pub const DEFAULT_DISPUTE_WINDOW: u64;Source line: 21.
payment::BALANCE_UPDATE_DOMAIN_TAG
Domain separator for signed CZAC payment-channel balance updates.
The signed transcript is:
BALANCE_UPDATE_DOMAIN_TAG
|| u32-le:len(channel_id) || channel_id
|| u64-le:sequence
|| u64-le:balance_a
|| u64-le:balance_b
|| u64-le:escrow_amountescrow_amount is included to bind the update to the funded channel size.
pub const BALANCE_UPDATE_DOMAIN_TAG: &[u8];Source line: 37.
payment::PaymentChannelState
Payment channel state.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum PaymentChannelState {
/// Channel has been funded and is ready for use.
Funded,
/// Channel is actively exchanging balance updates.
Active,
/// Both parties agreed to close cooperatively.
CooperativeClose,
/// One party initiated a unilateral close.
UnilateralClose {
/// DID of the party who initiated the close.
closer_did: String,
/// Block height at which the close was initiated.
close_height: u64,
},
/// A dispute has been filed against a unilateral close.
Disputed {
/// DID of the party who filed the dispute.
disputer_did: String,
/// Block height at which the dispute was filed.
dispute_height: u64,
},
/// Channel has been settled on-chain.
Settled,
}Source line: 41.
payment::BalanceUpdate
A signed balance update exchanged between channel parties.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct BalanceUpdate {
/// Channel this update belongs to.
pub channel_id: String,
/// Monotonically increasing sequence number.
pub sequence: u64,
/// Party A's balance after this update.
pub balance_a: u64,
/// Party B's balance after this update.
pub balance_b: u64,
/// Party A's signature over (channel_id, sequence, balance_a, balance_b).
pub signature_a: Vec<u8>,
/// Party B's signature over (channel_id, sequence, balance_a, balance_b).
pub signature_b: Vec<u8>
}Source line: 68.
payment::PaymentChannel
A payment channel between two parties.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct PaymentChannel {
/// Unique channel identifier.
pub channel_id: String,
/// OAS DID of party A (typically the initiator).
pub party_a_did: String,
/// OAS DID of party B (typically the responder).
pub party_b_did: String,
/// Total escrow amount locked in the channel.
pub escrow_amount: u64,
/// Party A's current balance.
pub balance_a: u64,
/// Party B's current balance.
pub balance_b: u64,
/// Current state update sequence number.
pub sequence: u64,
/// Current channel state.
pub state: PaymentChannelState,
/// Dispute window in blocks.
pub dispute_window: u64
}Source line: 85.
payment::PaymentChannel::new
Create a new payment channel in the Funded state.
Initially, all funds belong to party A.
pub fn new(channel_id: String, party_a: String, party_b: String, escrow: u64) -> Self;Source line: 110.
payment::PaymentChannel::update_balance
Apply a balance update to the channel.
The update must:
- Reference this channel.
- Have a sequence > current sequence.
- Preserve the balance invariant (a + b == escrow).
- Have non-empty signatures from both parties.
pub fn update_balance(&mut self, update: BalanceUpdate) -> Result<(), CzacError>;Source line: 131.
payment::PaymentChannel::update_balance_with_keys
Apply a balance update after verifying both party signatures.
The verifying keys must be resolved from the channel participants by the caller. They are deliberately not stored in the update payload, so an update cannot authorize itself with attacker-chosen keys.
pub fn update_balance_with_keys(
&mut self,
update: BalanceUpdate,
party_a_verifying_key_bytes: &[u8; 32],
party_b_verifying_key_bytes: &[u8; 32],
) -> Result<(), CzacError>;Source line: 195.
payment::PaymentChannel::cooperative_close
Close the channel cooperatively.
Returns the final balances (balance_a, balance_b).
pub fn cooperative_close(&mut self) -> Result<(u64, u64), CzacError>;Source line: 245.
payment::PaymentChannel::unilateral_close
Initiate a unilateral close.
The closer publishes their latest known state. The other party has
dispute_window blocks to dispute with a newer state.
pub fn unilateral_close(
&mut self,
closer_did: &str,
current_height: u64,
) -> Result<(), CzacError>;Source line: 263.
payment::PaymentChannel::dispute
Dispute a unilateral close by providing a newer balance update.
The disputer must provide a state with a higher sequence number than the current state, and must file during the dispute window.
pub fn dispute(
&mut self,
disputer_did: &str,
newer_update: BalanceUpdate,
current_height: u64,
) -> Result<(), CzacError>;Source line: 295.
payment::PaymentChannel::can_settle
Check whether the channel can be settled on-chain.
For unilateral closes: the dispute window must have elapsed. For cooperative closes: always true. For disputes: the dispute window from the dispute height must have elapsed.
pub fn can_settle(&self, current_height: u64) -> bool;Source line: 361.
payment::PaymentChannel::settle
Settle the channel, returning the final balances.
SECURITY: Enforces can_settle(current_height) to prevent premature
settlement. Without this check, a party could publish a stale state
via unilateral close and settle before the counterparty has time to
dispute, effectively stealing funds.
pub fn settle(&mut self, current_height: u64) -> Result<(u64, u64), CzacError>;Source line: 380.
payment::create_signed_balance_update
Create a balance update signed by both channel parties.
pub fn create_signed_balance_update(
channel_id: String,
sequence: u64,
balance_a: u64,
balance_b: u64,
escrow_amount: u64,
signing_key_a: &SigningKey,
signing_key_b: &SigningKey,
) -> Result<BalanceUpdate, CzacError>;Source line: 418.
payment::verify_balance_update_signatures
Verify both signatures on a balance update.
pub fn verify_balance_update_signatures(
update: &BalanceUpdate,
escrow_amount: u64,
party_a_verifying_key_bytes: &[u8; 32],
party_b_verifying_key_bytes: &[u8; 32],
) -> Result<(), CzacError>;Source line: 445.
payment::balance_update_digest
Compute the canonical digest signed by channel parties for balance updates.
pub fn balance_update_digest(update: &BalanceUpdate, escrow_amount: u64) -> [u8; 32];Source line: 468.