aura_effects/lib.rs
1//! # Aura Effects - Layer 3: Implementation (Stateless Effect Handlers)
2//!
3//! **Purpose**: Production-grade stateless effect handlers that delegate to OS services.
4//!
5//! This crate provides the Implementation Layer of the Aura architecture,
6//! containing context-free, single-operation effect handlers that work in ANY
7//! execution context (production, testing, simulation, choreographic).
8//!
9//! # Architecture Constraints
10//!
11//! **Layer 3 depends only on aura-core and external libraries** (foundation + libraries).
12//! - MUST implement infrastructure effect traits defined in aura-core
13//! - MUST be stateless (no shared mutable state between calls)
14//! - MUST be single-party (each handler works independently)
15//! - MUST be context-free (no assumptions about caller's context)
16//! - MUST NOT depend on other Aura crates (domain crates, aura-protocol, etc.)
17//! - MUST NOT do multi-handler coordination
18//! - MUST NOT do multi-party protocol logic
19//!
20//! ## Stateful Boundary (compile-fail example)
21//!
22//! Handlers in Layer 3 are stateless. Stateful caches belong in Layer 6 services.
23//!
24//! ```compile_fail
25//! use std::sync::RwLock;
26//!
27//! struct BadHandler {
28//! cache: RwLock<Vec<u8>>,
29//! }
30//!
31//! compile_error!("Stateful caches must live in Layer 6 handlers, not aura-effects.");
32//! ```
33//!
34//! # Required Infrastructure Effects
35//!
36//! This crate MUST provide handlers for:
37//! - CryptoEffects: Ed25519 signing, hashing, key derivation
38//! - NetworkEffects: TCP connections, message sending
39//! - StorageEffects: File I/O, chunk operations
40//! - TimeEffects: Current time, delays
41//! - RandomEffects: Cryptographically secure randomness
42//!
43//! # What Belongs Here
44//!
45//! Basic effect implementations (RealCryptoHandler, ProductionLeakageHandler)
46//! Storage backends (FilesystemStorageHandler, EncryptedStorage)
47//! Network transports (TcpTransportHandler, WebSocketTransportHandler)
48//! Time providers (RealTimeHandler), System handlers (LoggingSystemHandler)
49//!
50//! # What Does NOT Belong Here
51//!
52//! ✗ Multi-handler coordination (→ aura-protocol)
53//! ✗ Choreographic bridges (→ aura-protocol)
54//! ✗ Stateful orchestration (→ aura-protocol)
55//! ✗ Complete protocols (→ feature crates)
56//!
57//! # Usage
58//!
59//! ```rust,ignore
60//! use aura_effects::crypto::RealCryptoHandler;
61//! use aura_effects::storage::FilesystemStorageHandler;
62//! use aura_core::effects::{CryptoEffects, StorageEffects};
63//!
64//! // Use handlers directly for single operations
65//! let crypto = RealCryptoHandler::new();
66//! let signature = crypto.sign(&key, &message).await?;
67//!
68//! // Or compose into a runtime (done by aura-agent or aura-protocol)
69//! let runtime = EffectSystemBuilder::production()
70//! .with_crypto(crypto)
71//! .with_storage(storage)
72//! .build();
73//! ```
74
75#[cfg(all(feature = "transparent_onion", not(any(test, debug_assertions))))]
76compile_error!(
77 "Feature `transparent_onion` is a debug/test/simulation-only tool and must \
78 not be enabled in release production builds."
79);
80
81use cfg_if::cfg_if;
82
83pub mod biometric;
84pub mod console;
85pub mod context;
86/// Cryptographic effect handlers for signing, verification, and key derivation
87pub mod crypto;
88/// Indexed journal handler with B-tree indexes, Bloom filters, and Merkle trees
89pub mod database;
90/// Unified encrypted storage wrapper for transparent encryption at rest
91pub mod encrypted_storage;
92/// Error types for Layer 3 handler implementations.
93pub mod error;
94pub mod guard_interpreter;
95pub mod identifiers;
96pub mod leakage;
97pub mod network_monitor;
98pub mod noise;
99pub mod query;
100pub mod random;
101pub mod reactive;
102pub mod route_crypto;
103pub mod runtime_capability;
104pub mod secure;
105#[cfg(feature = "simulation")]
106pub mod simulation;
107cfg_if! {
108 if #[cfg(target_arch = "wasm32")] {
109 #[path = "storage_wasm.rs"]
110 pub mod storage;
111 } else {
112 pub mod storage;
113 }
114}
115pub mod system;
116pub mod time;
117pub mod trace;
118
119cfg_if! {
120 if #[cfg(target_arch = "wasm32")] {
121 pub mod transport;
122 } else {
123 pub mod transport;
124 pub mod udp;
125 }
126}
127
128// Re-export production handlers
129pub use crate::storage::FilesystemStorageHandler;
130pub use biometric::FallbackBiometricHandler;
131pub use console::RealConsoleHandler;
132pub use context::{EffectContext, StandardContextHandler};
133pub use crypto::RealCryptoHandler;
134pub use database::query::{AuraQuery, FactTerm, QueryError, QueryResult};
135pub use encrypted_storage::{EncryptedStorage, EncryptedStorageConfig};
136pub use error::Layer3Error;
137pub use guard_interpreter::ProductionEffectInterpreter;
138pub use identifiers::{
139 new_account_id, new_authority_id, new_context_id, new_device_id, new_event_id, new_guardian_id,
140 new_operation_id, new_session_id,
141};
142pub use leakage::ProductionLeakageHandler;
143pub use network_monitor::NetworkMonitorHandler;
144pub use noise::RealNoiseHandler;
145pub use query::{
146 format_rule, format_value, parse_arg_to_value, parse_fact_to_row, CapabilityPolicy,
147 QueryHandler,
148};
149pub use random::RealRandomHandler;
150pub use reactive::{ReactiveHandler, SignalGraph, SignalGraphStats};
151pub use route_crypto::RealRouteCryptoHandler;
152pub use runtime_capability::RuntimeCapabilityHandler;
153pub use secure::RealSecureStorageHandler;
154#[cfg(feature = "simulation")]
155pub use simulation::FallbackSimulationHandler;
156#[allow(deprecated)]
157pub use time::{
158 LogicalClockHandler, OrderClockHandler, PhysicalTimeHandler, TimeComparisonHandler,
159};
160#[cfg(not(target_arch = "wasm32"))]
161pub use udp::RealUdpEffectsHandler;
162
163// Transport effect handlers
164cfg_if! {
165 if #[cfg(target_arch = "wasm32")] {
166 pub mod transport_effects {
167 //! Transport effect implementations - Layer 3 stateless handlers.
168
169 pub use crate::transport::{
170 AddressResolver, BufferUtils, ConnectionMetrics, FramingHandler,
171 RealTransportHandler, TimeoutHelper, TransportError, UrlValidator,
172 };
173 }
174 } else {
175 pub mod transport_effects {
176 //! Transport effect implementations - Layer 3 stateless handlers
177
178 pub use crate::transport::{
179 // Utilities and helpers
180 AddressResolver,
181 BufferUtils,
182 ConnectionMetrics,
183 // Message processing
184 FramingHandler,
185
186 // Core transport handlers
187 RealTransportHandler,
188 TcpTransportHandler,
189 TimeoutHelper,
190 // Integration helpers
191 TransportError,
192 UrlValidator,
193
194 // Web transport
195 WebSocketTransportHandler,
196 };
197 }
198 }
199}
200
201// Convenience re-exports for most common handlers
202// Re-export system handlers
203pub use system::{LoggingSystemHandler, MetricsSystemHandler, MonitoringSystemHandler};
204
205// Convenience re-exports for most common transport handlers
206cfg_if! {
207 if #[cfg(target_arch = "wasm32")] {
208 pub use transport_effects::{FramingHandler, RealTransportHandler, TransportError};
209 } else {
210 pub use transport_effects::{
211 FramingHandler, RealTransportHandler, TcpTransportHandler, TransportError,
212 WebSocketTransportHandler,
213 };
214 }
215}
216
217// Re-export core effect traits for convenience
218pub use aura_core::effects::*;