prism_crypto/shapes.rs
1//! Parametric `ConstrainedTypeShape` carriers per [Wiki ADR-031][09-adr-031]:
2//! `Digest<N>`, `PublicKey<N>`, `Signature<N>`.
3//!
4//! Each shape is a phantom `N`-byte carrier. Per ADR-017's closure rule
5//! identity flows through `(SITE_COUNT, CONSTRAINTS)`, so distinct
6//! shape types with the same byte count content-address identically —
7//! the Rust name is for the developer, the content-address is for the
8//! ecosystem.
9//!
10//! [09-adr-031]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
11
12use uor_foundation::enforcement::GroundedShape;
13use uor_foundation::pipeline::{ConstrainedTypeShape, ConstraintRef, IntoBindingValue, TermValue};
14
15macro_rules! parametric_byte_shape {
16 ($(#[$attr:meta])* $name:ident) => {
17 $(#[$attr])*
18 #[derive(Debug, Clone, Copy)]
19 pub struct $name<const BYTES: usize>;
20
21 impl<const BYTES: usize> Default for $name<BYTES> {
22 fn default() -> Self {
23 Self
24 }
25 }
26
27 impl<const BYTES: usize> ConstrainedTypeShape for $name<BYTES> {
28 const IRI: &'static str = "https://uor.foundation/type/ConstrainedType";
29 const SITE_COUNT: usize = BYTES;
30 const CONSTRAINTS: &'static [ConstraintRef] = &[];
31 #[allow(clippy::cast_possible_truncation)]
32 const CYCLE_SIZE: u64 = 256u64.saturating_pow(BYTES as u32);
33 }
34
35 impl<const BYTES: usize> uor_foundation::pipeline::__sdk_seal::Sealed
36 for $name<BYTES>
37 {
38 }
39 impl<const BYTES: usize> GroundedShape for $name<BYTES> {}
40 impl<'a, const BYTES: usize> IntoBindingValue<'a> for $name<BYTES> {
41 fn as_binding_value<const INLINE_BYTES: usize>(&self) -> TermValue<'a, INLINE_BYTES> {
42 TermValue::empty()
43 }
44 }
45 };
46}
47
48parametric_byte_shape! {
49 /// Hash-digest shape: `N` bytes carrying a hash output.
50 ///
51 /// Per ADR-031's `Digest<32>` / `Digest<64>` shape commitment.
52 /// Common widths: `Digest<32>` (SHA-256, SHA3-256, Keccak-256,
53 /// BLAKE3), `Digest<64>` (SHA-512), `Digest<48>` (SHA-384).
54 Digest
55}
56
57parametric_byte_shape! {
58 /// Public-key shape: `N` bytes carrying an elliptic-curve public
59 /// key (compressed or raw, application-defined). Per ADR-031's
60 /// `PublicKey<32>` shape commitment.
61 PublicKey
62}
63
64parametric_byte_shape! {
65 /// Signature shape: `N` bytes carrying a signature. Per ADR-031's
66 /// `Signature<64>` shape commitment.
67 ///
68 /// Common widths: `Signature<64>` (Ed25519, secp256k1 raw r||s),
69 /// `Signature<96>` (BLS12-381 G1 compressed).
70 Signature
71}