sams_industrial_ecosystem/lib.rs
1/*!
2# SAMS Industrial Ecosystem
3
4**Master wrapper for OMWEI 32BSA Trust Hierarchy.** The unified entry point for Silicon Sincerity protocol, providing high-level orchestration of all SAMS components with hardware-enforced trust determination.
5
6## Mission
7
8The SAMS Industrial Ecosystem serves as the L0+ layer that orchestrates all OMWEI 32BSA compliant components through a unified `SincereStack` architecture. This ensures mathematical certainty and zero-latency trust determination across the entire stack.
9
10## Architecture
11
12```text
13SAMS INDUSTRIAL ECOSYSTEM
14+-----------------------------------------------------------+
15| SincereStack (Master Wrapper) |
16| +--------------+--------------+--------------+ |
17| | GhostNode | Blackbox | LogicGate | |
18| | (PQC Store) | (Logger) | (Validator) | |
19| +--------------+--------------+--------------+ |
20| | |
21| Hardware Trust Hierarchy |
22| (omwei-atom v0.1.2) |
23+-----------------------------------------------------------+
24```
25
26## Quick Start
27
28```rust
29use sams_industrial_ecosystem::SincereStack;
30use omwei_atom::{Atom, TrustLevel};
31
32#[tokio::main]
33async fn main() -> anyhow::Result<()> {
34 // Initialize the complete SAMS stack
35 let mut stack = SincereStack::new().await?;
36
37 // Process incoming atom through unified trust hierarchy
38 let atom = Atom::new(0x12345678, [0x42; 28]);
39 let result = stack.process_atom(atom).await?;
40
41 match result.trust_level {
42 TrustLevel::Managed => {
43 println!("✅ Sincere data: {}", result.status);
44 }
45 TrustLevel::Community => {
46 println!("⚠️ Community data: {}", result.status);
47 }
48 }
49
50 Ok(())
51}
52```
53
54## Features
55
56- **Unified Trust Hierarchy:** Single entry point for all trust determination
57- **Hardware Acceleration:** Direct integration with Silicon Catalyst
58- **Component Orchestration:** Automatic initialization of GhostNode, Blackbox, LogicGate
59- **Zero-Cost Abstractions:** Compile-time optimization to single instructions
60- **Post-Quantum Ready:** Built-in PQC signature verification framework
61
62## Sincerity Compliance
63
64This crate ensures 100% compliance with OMWEI 32BSA v0.1.2 standard:
65- **Managed Space:** Bit 31 = 0, PQC signature required
66- **Community Space:** Bit 31 = 1, local verification only
67- **Zero Latency:** Single bit-mask operation (`id & 0x80000000`)
68- **Hardware Efficiency:** Stack-only execution, no allocation
69
70## Components
71
72- [`GhostNode`] - PQC signature storage and verification
73- [`Blackbox`] - Logging and telemetry with trust-based tagging
74- [`LogicGate`] - Hardware-level validation and filtering
75- [`SincereStack`] - Master orchestrator for all components
76
77## Configuration
78
79### Feature Flags
80- `std`: Standard library support (default)
81- `pqc`: Post-quantum cryptography primitives
82
83### Environment Variables
84- `SAMS_LOG_LEVEL`: Logging level (trace, debug, info, warn, error)
85- `SAMS_PQC_KEY_PATH`: Path to PQC private key for Managed Space
86- `SAMS_TRUST_POLICY`: Default trust policy (strict, permissive)
87
88*/
89
90#![cfg_attr(not(feature = "std"), no_std)]
91#![cfg_attr(docsrs, feature(doc_cfg))]
92
93#[cfg(all(not(feature = "std"), feature = "serde"))]
94extern crate alloc;
95
96#[cfg(all(not(feature = "std"), feature = "serde"))]
97use alloc::{string::String, vec::Vec};
98
99#[cfg(feature = "serde")]
100use serde::{Deserialize, Serialize};
101
102// Re-export OMWEI 32BSA core types
103pub use omwei_atom::trust_hierarchy::{get_trust_level, validate_atom, Atom, TrustLevel, ValidationResult};
104
105pub mod blackbox;
106pub mod ghost_node;
107pub mod logic_gate;
108
109use anyhow::Result;
110use chrono::{DateTime, Utc};
111use log::{error, info, warn};
112use uuid::Uuid;
113
114/// Processing result from SAMS stack
115#[derive(Debug, Clone)]
116#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
117pub struct SincereResult {
118 /// Trust level determined by hardware hierarchy
119 pub trust_level: TrustLevel,
120 /// Processing status and metadata
121 pub status: String,
122 /// Processing timestamp
123 pub timestamp: DateTime<Utc>,
124 /// Unique processing ID
125 pub process_id: Uuid,
126}
127
128/// Master wrapper for SAMS Industrial Ecosystem
129///
130/// This struct orchestrates all OMWEI 32BSA compliant components
131/// through a unified trust hierarchy with hardware acceleration.
132#[derive(Debug)]
133pub struct SincereStack {
134 /// GhostNode instance for PQC operations
135 ghost_node: ghost_node::GhostNode,
136 /// Blackbox instance for logging and telemetry
137 blackbox: blackbox::Blackbox,
138 /// LogicGate instance for validation
139 logic_gate: logic_gate::LogicGate,
140 /// Unique instance identifier
141 instance_id: Uuid,
142}
143
144impl SincereStack {
145 /// Create new SincereStack with all components initialized
146 ///
147 /// # Arguments
148 /// * `config` - Optional configuration for components
149 ///
150 /// # Returns
151 /// Initialized SincereStack ready for processing
152 ///
153 /// # Examples
154 /// ```
155 /// use sams_industrial_ecosystem::SincereStack;
156 ///
157 /// #[tokio::main]
158 /// async fn main() -> anyhow::Result<()> {
159 /// let stack = SincereStack::new().await?;
160 /// Ok(())
161 /// }
162 /// ```
163 pub async fn new() -> Result<Self> {
164 let instance_id = Uuid::new_v4();
165
166 info!("Initializing SAMS Industrial Ecosystem v0.2.0");
167 info!("Instance ID: {}", instance_id);
168
169 // Initialize all components
170 let ghost_node = ghost_node::GhostNode::new().await?;
171 let blackbox = blackbox::Blackbox::new(instance_id)?;
172 let logic_gate = logic_gate::LogicGate::new(None).await?;
173
174 info!("✅ SincereStack initialized successfully");
175
176 Ok(Self {
177 ghost_node,
178 blackbox,
179 logic_gate,
180 instance_id,
181 })
182 }
183
184 /// Process an atom through the complete trust hierarchy
185 ///
186 /// This method orchestrates validation, logging, and storage
187 /// according to OMWEI 32BSA standards.
188 ///
189 /// # Arguments
190 /// * `atom` - The atom to process
191 ///
192 /// # Returns
193 /// Processing result with trust level and status
194 ///
195 /// # Examples
196 /// ```ignore
197 /// use sams_industrial_ecosystem::{SincereStack, SincereResult};
198 /// use omwei_atom::Atom;
199 ///
200 /// #[tokio::main]
201 /// async fn main() -> anyhow::Result<()> {
202 /// let mut stack = SincereStack::new().await?;
203 /// let atom = Atom::new(0x12345678, [0x42; 28]);
204 /// let result = stack.process_atom(atom).await?;
205 /// println!("Processed: {:?}", result);
206 /// Ok(())
207 /// }
208 /// ```
209 pub async fn process_atom(&mut self, atom: Atom) -> Result<SincereResult> {
210 let process_id = Uuid::new_v4();
211 let timestamp = Utc::now();
212
213 info!(
214 "Processing atom {} with ID 0x{:08X}",
215 process_id, atom.global_id
216 );
217
218 // Step 1: Hardware trust determination (zero latency)
219 let trust_level = get_trust_level(atom.global_id);
220
221 // Step 2: Logic Gate validation
222 let validation_metadata = self.logic_gate.validate(&atom).await?;
223
224 // Convert ValidationMetadata to ValidationResult for blackbox
225 let validation_result = if validation_metadata.is_valid {
226 ValidationResult::Trusted
227 } else {
228 ValidationResult::InvalidSignature
229 };
230
231 // Step 3: Blackbox logging with trust-based tagging
232 self.blackbox
233 .log(&atom, &trust_level, &validation_result, process_id)
234 .await?;
235
236 // Step 4: GhostNode PQC operations (Managed Space only)
237 let status = match trust_level {
238 TrustLevel::Managed => {
239 // PQC signature verification for Managed Space
240 match self.ghost_node.verify_and_store(&atom).await {
241 Ok(verified) => {
242 if verified {
243 format!("✅ Sincere - PQC verified, stored in GhostNode")
244 } else {
245 format!("⚠️ Sincere - GhostNode unavailable")
246 }
247 }
248 Err(e) => {
249 warn!("GhostNode verification failed: {}", e);
250 format!("❌ Sincere - GhostNode error")
251 }
252 }
253 }
254 TrustLevel::Community => {
255 format!("⚠️ Community - Local verification only")
256 }
257 };
258
259 let status_clone = status.clone();
260
261 let result = SincereResult {
262 trust_level,
263 status,
264 timestamp: Utc::now(),
265 process_id,
266 };
267
268 info!("✅ Atom processed successfully: {}", status_clone);
269 Ok(result)
270 }
271
272 /// Get stack instance information
273 pub fn info(&self) -> &str {
274 "SAMS Industrial Ecosystem v0.2.0 - OMWEI 32BSA Compliant"
275 }
276}
277
278#[cfg(test)]
279mod tests {
280 use super::*;
281
282 #[tokio::test]
283 async fn test_sincere_stack_creation() {
284 let stack = SincereStack::new().await;
285 assert!(stack.is_ok());
286
287 let stack = stack.unwrap();
288 assert_eq!(
289 stack.info(),
290 "SAMS Industrial Ecosystem v0.2.0 - OMWEI 32BSA Compliant"
291 );
292 }
293
294 #[tokio::test]
295 async fn test_managed_atom_processing() {
296 let stack = SincereStack::new().await.unwrap();
297 let atom = Atom::new(0x12345678, [0x42; 28]); // Managed Space
298
299 let result = stack.process_atom(atom).await.unwrap();
300 assert_eq!(result.trust_level, TrustLevel::Managed);
301 assert!(result.status.contains("Sincere"));
302 }
303
304 #[tokio::test]
305 async fn test_community_atom_processing() {
306 let stack = SincereStack::new().await.unwrap();
307 let atom = Atom::new(0x80000001, [0x24; 28]); // Community Space
308
309 let result = stack.process_atom(atom).await.unwrap();
310 assert_eq!(result.trust_level, TrustLevel::Community);
311 assert!(result.status.contains("Community"));
312 }
313}