Skip to main content

dsfb_densor_runtime/
densor.rs

1//! The `Densor` trait — a sealed, self-verifying evidence object the runtime carries between stages.
2//!
3//! "Densor" is the generic DSFB term for a sealed residual-evidence object (the chemical crate's `…V1` records are
4//! concrete densors). This trait is the minimal contract the runtime needs: a stable id, a kind, a 32-byte
5//! evidence hash, and a `verify()` that re-derives the seal. It says nothing about chemistry — it is a mechanism.
6
7use crate::errors::DensorError;
8
9/// Coarse category of a densor, for routing/inventory only (never a claim about meaning).
10#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
11pub enum DensorKind {
12    /// A residual / deviation object.
13    Residual,
14    /// An admissibility-envelope evaluation.
15    Envelope,
16    /// A grammar / classification state.
17    Grammar,
18    /// A fused / quorum object.
19    Fusion,
20    /// A physical / contextual witness.
21    Witness,
22    /// A sealed court / bundle record.
23    Court,
24    /// Anything else a downstream domain defines.
25    Other,
26}
27
28impl DensorKind {
29    pub fn tag(self) -> &'static str {
30        match self {
31            DensorKind::Residual => "residual",
32            DensorKind::Envelope => "envelope",
33            DensorKind::Grammar => "grammar",
34            DensorKind::Fusion => "fusion",
35            DensorKind::Witness => "witness",
36            DensorKind::Court => "court",
37            DensorKind::Other => "other",
38        }
39    }
40}
41
42/// A sealed, self-verifying evidence object.
43pub trait Densor {
44    /// A stable, non-empty identifier.
45    fn densor_id(&self) -> &str;
46    /// The densor's coarse kind (routing/inventory only).
47    fn densor_kind(&self) -> DensorKind;
48    /// The 32-byte evidence hash this densor seals to.
49    fn evidence_hash(&self) -> [u8; 32];
50    /// Re-derive the seal and confirm it matches (tamper-evident). Implementors must check `densor_id` is
51    /// non-empty and that a freshly computed seal equals [`Densor::evidence_hash`].
52    fn verify(&self) -> Result<(), DensorError>;
53}