l1fe-crypto · crate
Source declarations, signatures and documentation for crate.
Source: sigil/weave/l1feid/l1fe-crypto/src/lib.rs. SHA-256: d9f03551590ff1b9e25923df0ea5e4690408845d0e0409891dcfb623c488dcf6.
This reference follows declared source modules, retains conditional attributes, and includes public declarations and implementation methods. Private-module re-exports and trait resolution require the compiler; this is a source reference, not a claim that every listed item is a root import. Function bodies and constant values are omitted.
::CryptoError
Errors that can occur during cryptographic operations
#[derive(Error, Debug)]
pub enum CryptoError {
#[error("Invalid key length: expected {expected}, got {actual}")]
InvalidKeyLength { expected: usize, actual: usize },
#[error("Invalid signature")]
InvalidSignature,
#[error("Decryption failed")]
DecryptionFailed,
#[error("Invalid seed length: expected 32 bytes, got {actual}")]
InvalidSeedLength { actual: usize },
#[error("Initialization failed")]
InitializationFailed,
#[error("Invalid input data")]
InvalidInput,
#[error("Hash operation failed")]
HashFailed,
}Source line: 42.
::Result
Result type for crypto operations
pub type Result<T> = std::result::Result<T, CryptoError>;Source line: 66.
::KeyPair
A key pair for signing operations
#[derive(Clone, Debug)]
pub struct KeyPair {
pub public_key: [u8; 32],
pub secret_key: [u8; 64]
}Source line: 70.
::EncryptionKeyPair
A key pair for encryption operations
#[derive(Clone)]
pub struct EncryptionKeyPair {
pub public_key: [u8; 32],
pub secret_key: [u8; 32]
}Source line: 83.
::Node
Node structure for merkle tree operations
#[derive(Debug, Clone)]
pub struct Node {
pub index: u64,
pub size: u64,
pub hash: [u8; 32]
}Source line: 96.
::key_pair
Generate a new Ed25519 key pair
Arguments
seed- Optional 32-byte seed for deterministic key generation
Returns
A new KeyPair for signing operations
Errors
Returns CryptoError::InitializationFailed if cryptographic initialization fails
pub fn key_pair(seed: Option<&[u8; 32]>) -> Result<KeyPair>;Source line: 112.
::validate_key_pair
Validate that a key pair's public key matches its secret key
Arguments
key_pair- The key pair to validate
Returns
true if the keys match, false otherwise
pub fn validate_key_pair(key_pair: &KeyPair) -> bool;Source line: 141.
::sign
Sign a message with a secret key
Arguments
message- The message to signsecret_key- The 64-byte secret key (32-byte seed + 32-byte public key)
Returns
A 64-byte signature
pub fn sign(message: &[u8], secret_key: &[u8; 64]) -> [u8; 64];Source line: 158.
::verify
Verify a signature
Arguments
message- The original messagesignature- The signature to verifypublic_key- The public key to verify against
Returns
true if the signature is valid, false otherwise
pub fn verify(message: &[u8], signature: &[u8], public_key: &[u8; 32]) -> bool;Source line: 175.
::encryption_key_pair
Generate a key pair for sealed box encryption
Arguments
seed- Optional seed for deterministic generation
Returns
An EncryptionKeyPair for sealed box operations
Errors
Returns CryptoError::InitializationFailed if cryptographic initialization fails
pub fn encryption_key_pair(seed: Option<&[u8; 32]>) -> Result<EncryptionKeyPair>;Source line: 205.
::encrypt
Encrypt a message using sealed box encryption
Arguments
message- The message to encryptpublic_key- The recipient's public key
Returns
The encrypted ciphertext
Errors
Returns CryptoError::InitializationFailed if cryptographic initialization fails
pub fn encrypt(message: &[u8], public_key: &[u8; 32]) -> Result<Vec<u8>>;Source line: 231.
::decrypt
Decrypt a sealed box
Arguments
ciphertext- The encrypted messagekey_pair- The recipient's key pair
Returns
The decrypted message
Errors
Returns CryptoError::DecryptionFailed if decryption fails
Returns CryptoError::InitializationFailed if cryptographic initialization fails
pub fn decrypt(ciphertext: &[u8], key_pair: &EncryptionKeyPair) -> Result<Vec<u8>>;Source line: 250.
::data
Hash data for a leaf node
Arguments
data- The data to hash
Returns
A 32-byte hash
pub fn data(data: &[u8]) -> [u8; 32];Source line: 270.
::parent
Hash two nodes to create a parent node
Arguments
left- The left child noderight- The right child node
Returns
A 32-byte hash for the parent
pub fn parent(left: &Node, right: &Node) -> [u8; 32];Source line: 289.
::tree
Hash a set of root nodes
Arguments
roots- The root nodes to hash
Returns
A 32-byte tree hash
pub fn tree(roots: &[Node]) -> [u8; 32];Source line: 315.
::hash
Generic hash function using Blake2b
Arguments
data- Slice of byte slices to hash together
Returns
A 32-byte hash
pub fn hash(data: &[&[u8]]) -> [u8; 32];Source line: 338.
::hash_into
Generic hash function with output buffer
Arguments
data- Slice of byte slices to hash togetherout- Output buffer (must be 32 bytes)
pub fn hash_into(data: &[&[u8]], out: &mut [u8; 32]);Source line: 354.
::random_bytes
Generate random bytes
Arguments
n- Number of bytes to generate
Returns
A vector of random bytes
Errors
Returns CryptoError::InitializationFailed if cryptographic initialization fails
pub fn random_bytes(n: usize) -> Result<Vec<u8>>;Source line: 368.
::discovery_key
Generate a discovery key from a public key
Arguments
key- A 32-byte public key
Returns
A 32-byte discovery key
pub fn discovery_key(key: &[u8; 32]) -> [u8; 32];Source line: 382.
::namespace
Generate namespaced keys
Arguments
name- The namespace namecount- Number of keys to generate (or specific indices)
Returns
A vector of 32-byte keys
pub fn namespace(name: &str, count: impl NamespaceCount) -> Vec<[u8; 32]>;Source line: 400.
::free
Free secure memory (no-op in Rust as memory is automatically freed)
pub fn free(_secure_buf: &[u8]);Source line: 429.
::NamespaceCount
Trait for namespace count parameter (can be a count or specific indices)
pub trait NamespaceCount {
fn indices(&self) -> Vec<usize>;
}Source line: 435.