csv_adapter_core/traits.rs
1//! Core AnchorLayer trait
2//!
3//! This trait defines the interface that all chain-specific adapters must implement.
4
5use crate::dag::DAGSegment;
6use crate::error::Result;
7use crate::hash::Hash;
8use crate::proof::ProofBundle;
9use crate::signature::SignatureScheme;
10
11/// The AnchorLayer trait defines the interface for chain-specific adapters.
12///
13/// Implementors must provide:
14/// - Seal creation and management
15/// - Commitment publication
16/// - Inclusion proof extraction
17/// - Finality verification
18/// - Seal enforcement (anti-replay)
19pub trait AnchorLayer {
20 /// Chain-specific seal reference type
21 type SealRef;
22
23 /// Chain-specific anchor reference type
24 type AnchorRef;
25
26 /// Chain-specific inclusion proof type
27 type InclusionProof;
28
29 /// Chain-specific finality proof type
30 type FinalityProof;
31
32 /// Publish a commitment under a single-use seal.
33 ///
34 /// Returns a reference that can be used for inclusion/finality proofs.
35 ///
36 /// # Arguments
37 /// * `commitment` - The commitment hash to publish
38 /// * `seal` - The seal reference authorizing this commitment
39 fn publish(&self, commitment: Hash, seal: Self::SealRef) -> Result<Self::AnchorRef>;
40
41 /// Extract inclusion proof from the base layer.
42 ///
43 /// # Arguments
44 /// * `anchor` - The anchor reference to verify
45 fn verify_inclusion(&self, anchor: Self::AnchorRef) -> Result<Self::InclusionProof>;
46
47 /// Verify finality according to base-layer rules.
48 ///
49 /// # Arguments
50 /// * `anchor` - The anchor reference to verify finality for
51 fn verify_finality(&self, anchor: Self::AnchorRef) -> Result<Self::FinalityProof>;
52
53 /// Enforce that the seal is single-use and non-replayable.
54 ///
55 /// # Arguments
56 /// * `seal` - The seal reference to enforce
57 fn enforce_seal(&self, seal: Self::SealRef) -> Result<()>;
58
59 /// Create a new seal for authorizing state transitions.
60 ///
61 /// # Arguments
62 /// * `value` - Optional value/funding for the seal (chain-specific units)
63 fn create_seal(&self, value: Option<u64>) -> Result<Self::SealRef>;
64
65 /// Compute a commitment hash from components.
66 ///
67 /// # Arguments
68 /// * `contract_id` - Unique contract identifier
69 /// * `previous_commitment` - Previous commitment hash
70 /// * `transition_payload_hash` - Hash of the transition payload
71 /// * `seal_ref` - Seal reference
72 fn hash_commitment(
73 &self,
74 contract_id: Hash,
75 previous_commitment: Hash,
76 transition_payload_hash: Hash,
77 seal_ref: &Self::SealRef,
78 ) -> Hash;
79
80 /// Build a complete proof bundle for peer-to-peer verification.
81 ///
82 /// # Arguments
83 /// * `anchor` - The anchor reference
84 /// * `transition_dag` - The state transition DAG segment
85 fn build_proof_bundle(
86 &self,
87 anchor: Self::AnchorRef,
88 transition_dag: DAGSegment,
89 ) -> Result<ProofBundle>;
90
91 /// Handle rollback of an anchor due to chain reorg.
92 ///
93 /// # Arguments
94 /// * `anchor` - The anchor reference to invalidate
95 fn rollback(&self, anchor: Self::AnchorRef) -> Result<()>;
96
97 /// Get the domain separator for this adapter.
98 fn domain_separator(&self) -> [u8; 32];
99
100 /// Get the signature scheme used by this chain.
101 ///
102 /// This is used by the proof verification pipeline to select
103 /// the appropriate cryptographic verification algorithm.
104 fn signature_scheme(&self) -> SignatureScheme;
105}