Skip to main content

uor_addr/ring/
pipeline.rs

1//! `ring::address` — the ring-element realization's public entry point.
2//!
3//! 1. [`RingElement::parse`] validates the Amendment 43 §2 canonical
4//!    bytes at the host boundary.
5//! 2. [`AddressModel::forward`] runs the shared ψ-tower: the handle's
6//!    canonical bytes flow in as an ADR-060 carrier and ψ₉ folds them
7//!    through `H = Sha256Hasher` to mint the κ-label.
8//! 3. [`AddressOutcome::from_grounded`] extracts the owned κ-label +
9//!    replayable TC-05 witness.
10
11pub use crate::outcome::{AddressOutcome, AddressWitness, VerifyError};
12
13/// Failure modes from [`address`].
14#[derive(Debug, Clone, Copy, PartialEq, Eq)]
15pub enum AddressFailure {
16    /// The input bytes were not valid Amendment 43 canonical bytes (a
17    /// canonical ring element is intrinsically ≤ 5 bytes — Witt level
18    /// plus its little-endian coefficient — so every malformed or
19    /// over-wide input falls here).
20    InvalidRingElement,
21    /// Defensive: foundation's catamorphism returned a shape violation.
22    PipelineFailure,
23}
24
25use crate::ring::model::{
26    AddressModel, AddressModelBlake3, AddressModelKeccak256, AddressModelSha3_256,
27    AddressModelSha512,
28};
29use crate::ring::value::RingElement;
30use prism::pipeline::PrismModel;
31
32/// **uor-addr's ring entry point** (σ-axis `Sha256Hasher`) — one
33/// ψ-pipeline content-address inference, yielding a `sha256:<64hex>`
34/// κ-label.
35///
36/// # Errors
37///
38/// - [`AddressFailure::InvalidRingElement`] — the input is not well-formed.
39/// - [`AddressFailure::PipelineFailure`] — defensive; unreachable.
40pub fn address(input_bytes: &[u8]) -> Result<AddressOutcome<71>, AddressFailure> {
41    let element =
42        RingElement::parse(input_bytes).map_err(|_| AddressFailure::InvalidRingElement)?;
43    let grounded = AddressModel::forward(element).map_err(|_| AddressFailure::PipelineFailure)?;
44    AddressOutcome::<71>::from_grounded(&grounded).map_err(|_| AddressFailure::PipelineFailure)
45}
46
47/// The ring entry point under σ-axis `Blake3Hasher` — yields a
48/// `blake3:<64hex>` κ-label. See [`address`] for the error contract.
49///
50/// # Errors
51///
52/// As [`address`].
53pub fn address_blake3(input_bytes: &[u8]) -> Result<AddressOutcome<71>, AddressFailure> {
54    let element =
55        RingElement::parse(input_bytes).map_err(|_| AddressFailure::InvalidRingElement)?;
56    let grounded =
57        AddressModelBlake3::forward(element).map_err(|_| AddressFailure::PipelineFailure)?;
58    AddressOutcome::<71>::from_grounded(&grounded).map_err(|_| AddressFailure::PipelineFailure)
59}
60
61/// The ring entry point under σ-axis `Sha3_256Hasher` — yields a
62/// `sha3-256:<64hex>` κ-label. See [`address`] for the error contract.
63///
64/// # Errors
65///
66/// As [`address`].
67pub fn address_sha3_256(input_bytes: &[u8]) -> Result<AddressOutcome<73>, AddressFailure> {
68    let element =
69        RingElement::parse(input_bytes).map_err(|_| AddressFailure::InvalidRingElement)?;
70    let grounded =
71        AddressModelSha3_256::forward(element).map_err(|_| AddressFailure::PipelineFailure)?;
72    AddressOutcome::<73>::from_grounded(&grounded).map_err(|_| AddressFailure::PipelineFailure)
73}
74
75/// The ring entry point under σ-axis `Keccak256Hasher` — yields a
76/// `keccak256:<64hex>` κ-label. See [`address`] for the error contract.
77///
78/// # Errors
79///
80/// As [`address`].
81pub fn address_keccak256(input_bytes: &[u8]) -> Result<AddressOutcome<74>, AddressFailure> {
82    let element =
83        RingElement::parse(input_bytes).map_err(|_| AddressFailure::InvalidRingElement)?;
84    let grounded =
85        AddressModelKeccak256::forward(element).map_err(|_| AddressFailure::PipelineFailure)?;
86    AddressOutcome::<74>::from_grounded(&grounded).map_err(|_| AddressFailure::PipelineFailure)
87}
88
89/// The ring entry point under σ-axis `Sha512Hasher` — yields a
90/// `sha512:<128hex>` κ-label (135 bytes, 64-byte fingerprint). See
91/// [`address`] for the error contract.
92///
93/// # Errors
94///
95/// As [`address`].
96pub fn address_sha512(input_bytes: &[u8]) -> Result<AddressOutcome<135, 64>, AddressFailure> {
97    let element =
98        RingElement::parse(input_bytes).map_err(|_| AddressFailure::InvalidRingElement)?;
99    let grounded =
100        AddressModelSha512::forward(element).map_err(|_| AddressFailure::PipelineFailure)?;
101    AddressOutcome::<135, 64>::from_grounded(&grounded).map_err(|_| AddressFailure::PipelineFailure)
102}