Skip to main content

prism_crypto/
lib.rs

1//! Prism standard-library cryptography sub-crate.
2//!
3//! `prism-crypto` realizes the cryptography Layer-3 of the standard
4//! library named in [Wiki ADR-031][09-adr-031]: it declares the
5//! cryptographic axis traits (`HashAxis`, `CurveAxis`, `SignatureAxis`,
6//! `CommitmentAxis`) through the [`axis!`][09-adr-030] SDK macro and
7//! supplies canonical impls plus matching `ConstrainedTypeShape`
8//! carriers per the wiki's ADR-031 roster.
9//!
10//! ## Scope
11//!
12//! - **`HashAxis`** — content-addressing function. Canonical impls:
13//!   [`Sha256Hasher`], [`Sha512Hasher`], [`Sha3_256Hasher`],
14//!   [`Blake3Hasher`], [`Keccak256Hasher`]. Each impl is
15//!   conformance-tested against the relevant standard's published
16//!   vectors (FIPS-180-4 for SHA-2, FIPS-202 for SHA-3, BLAKE3 spec
17//!   for BLAKE3) — see `tests/conformance.rs`.
18//! - **`CommitmentAxis`** — composes any `HashAxis` impl into a
19//!   Merkle-root commitment via [`MerkleRoot<H, LEAF_BYTES>`]. The
20//!   default alias [`MerkleRootCommitment`] is SHA-256. Per ADR-031
21//!   this is the canonical example of standard-library
22//!   cross-sub-crate composition.
23//! - **`CurveAxis`**, **`SignatureAxis`** — declared per ADR-031's
24//!   standard-library roster; concrete reference impls are scoped per
25//!   axis maintenance policy (ADR-031's "operational policy"
26//!   carve-out).
27//!
28//! ## ConstrainedTypeShape declarations
29//!
30//! Per ADR-031's shape-declaration commitment, the canonical
31//! cryptographic value-carriers are parametric over byte-width:
32//!
33//! - **[`Digest<N>`]** — hash output. `Digest<32>` for SHA-256 /
34//!   SHA3-256 / Keccak-256 / BLAKE3; `Digest<48>` for SHA-384;
35//!   `Digest<64>` for SHA-512.
36//! - **[`PublicKey<N>`]** — public-key bytes.
37//! - **[`Signature<N>`]** — signature bytes.
38//! - **[`MerkleProofShape<MAX_DEPTH, LEAF_BYTES>`]** — Merkle-inclusion
39//!   proof.
40//!
41//! Each shape is `GroundedShape + IntoBindingValue`-bound for use as
42//! the `Output` of a `prism_model!`-declared application.
43//!
44//! ## Closure under uor-foundation (ADR-013)
45//!
46//! Every axis trait declared here has `::uor_foundation::pipeline::AxisExtension`
47//! as a supertrait — the `axis!` macro enforces this. Concrete impls
48//! that take no type parameters use the companion-macro lane; the
49//! parametric `MerkleRoot<H, LEAF_BYTES>` hand-writes its
50//! `AxisExtension` impl since the companion macro takes `:ident`.
51//!
52//! ## See also
53//!
54//! - [Wiki: 09 Architecture Decisions § ADR-030 — `axis!` SDK macro][09-adr-030]
55//! - [Wiki: 09 Architecture Decisions § ADR-031 — `prism` is the standard library][09-adr-031]
56//! - [Wiki: 09 Architecture Decisions § ADR-024 — Three-layer algebraic closure][09-adr-024]
57//! - [Wiki: 12 Glossary § Crypto][12-glossary]
58//!
59//! [09-adr-024]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
60//! [09-adr-030]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
61//! [09-adr-031]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
62//! [12-glossary]: https://github.com/UOR-Foundation/UOR-Framework/wiki/12-Glossary
63
64#![no_std]
65#![cfg_attr(docsrs, feature(doc_cfg))]
66
67pub mod commitment;
68pub mod curve;
69pub mod hash;
70pub mod shapes;
71pub mod signature;
72pub mod verbs;
73
74pub use commitment::{
75    CommitmentAxis, MerkleProofShape, MerkleRoot, MerkleRootCommitment, MAX_MERKLE_LEAVES,
76};
77pub use curve::CurveAxis;
78pub use hash::{
79    Blake3Hasher, HashAxis, Keccak256Hasher, Sha256Hasher, Sha3_256Hasher, Sha512Hasher,
80};
81pub use shapes::{Digest, PublicKey, Signature};
82pub use signature::SignatureAxis;
83
84/// Wiki ADR-031 standard-library version banner. Each prism standard-
85/// library sub-crate exposes this so application authors can introspect
86/// the canonical-reference version of the axes it declares.
87pub const STANDARD_LIBRARY_VERSION: &str = env!("CARGO_PKG_VERSION");