hush_core/lib.rs
1#![cfg_attr(test, allow(clippy::expect_used, clippy::unwrap_used))]
2
3//! # hush-core
4//!
5//! Cryptographic primitives for the clawdstrike attestation system.
6//!
7//! This crate provides:
8//! - Ed25519 signing and verification
9//! - SHA-256 and Keccak-256 hashing
10//! - Merkle tree construction and proof verification
11//! - Canonical JSON (RFC 8785)
12//! - Receipt types and signing
13//!
14//! ## Quick Start
15//!
16//! ```rust
17//! use hush_core::{sha256, keccak256, Keypair};
18//!
19//! // Hash some data
20//! let hash = sha256(b"hello world");
21//! assert_eq!(hash.as_bytes().len(), 32);
22//!
23//! // Keccak-256 (Ethereum-compatible)
24//! let eth_hash = keccak256(b"hello world");
25//! assert_eq!(eth_hash.as_bytes().len(), 32);
26//!
27//! // Sign and verify
28//! let keypair = Keypair::generate();
29//! let message = b"important message";
30//! let signature = keypair.sign(message);
31//! assert!(keypair.public_key().verify(message, &signature));
32//! ```
33//!
34//! ## Merkle Trees
35//!
36//! ```rust
37//! use hush_core::MerkleTree;
38//!
39//! let leaves = vec![b"leaf1".to_vec(), b"leaf2".to_vec(), b"leaf3".to_vec()];
40//! let tree = MerkleTree::from_leaves(&leaves).unwrap();
41//!
42//! // Generate and verify inclusion proof
43//! let proof = tree.inclusion_proof(1).unwrap();
44//! assert!(proof.verify(&leaves[1], &tree.root()));
45//! ```
46
47pub mod canonical;
48pub mod duration;
49pub mod error;
50pub mod hashing;
51pub mod merkle;
52pub mod receipt;
53pub mod signing;
54#[cfg(not(target_arch = "wasm32"))]
55pub mod tpm;
56
57pub use canonical::canonicalize as canonicalize_json;
58pub use duration::parse_human_duration;
59pub use error::{Error, Result};
60pub use hashing::{keccak256, keccak256_hex, sha256, sha256_hex, Hash};
61pub use merkle::{MerkleProof, MerkleTree};
62pub use receipt::{Provenance, Receipt, SignedReceipt, Verdict};
63pub use signing::{Keypair, PublicKey, Signature, Signer};
64#[cfg(not(target_arch = "wasm32"))]
65pub use tpm::{TpmSealedBlob, TpmSealedSeedSigner};
66
67/// Commonly used types
68pub mod prelude {
69 pub use crate::{
70 keccak256, sha256, Error, Hash, Keypair, MerkleProof, MerkleTree, PublicKey, Receipt,
71 Result, Signature, SignedReceipt, Signer,
72 };
73
74 #[cfg(not(target_arch = "wasm32"))]
75 pub use crate::{TpmSealedBlob, TpmSealedSeedSigner};
76}