Skip to main content

dsfb_densor_runtime/
authority.rs

1//! Authority hashes — the frozen digests a stage was built against.
2//!
3//! An `AuthorityHash` names a piece of frozen authority (e.g. a detector atlas, an envelope policy, a dataset
4//! corpus) by `(name, 32-byte digest)`. A stage must declare the authorities it consulted; the runtime checks
5//! those against the manifest's frozen set before admitting the stage's output. This is the substrate analogue of
6//! the chemical crate's `atlas_hash_v1` / `corpus_hash_v1` pinning: an execution is only meaningful relative to a
7//! named, frozen authority.
8
9use crate::seal::to_hex;
10use serde::{Deserialize, Serialize};
11
12/// A named, frozen authority digest a stage was built/validated against.
13#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
14pub struct AuthorityHash {
15    pub name: String,
16    /// 32-byte SHA-256 of the frozen authority's canonical bytes.
17    pub hash: [u8; 32],
18}
19
20impl AuthorityHash {
21    pub fn new(name: impl Into<String>, hash: [u8; 32]) -> Self {
22        AuthorityHash {
23            name: name.into(),
24            hash,
25        }
26    }
27
28    /// Lowercase hex of the digest, for display / receipts.
29    pub fn hex(&self) -> String {
30        to_hex(&self.hash)
31    }
32}