Skip to main content

logicaffeine_system/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![doc = include_str!("../README.md")]
3
4// === Always Available (Core IO) ===
5pub mod io;
6pub mod temporal;
7
8// The thin-relay wire protocol — shared by the native relay server (under
9// `networking`) and the browser relay client (wasm). Target-agnostic (serde
10// only), so it compiles into both the native binary and the wasm bundle without
11// dragging in libp2p.
12pub mod relay_proto;
13
14// Address normalization (libp2p multiaddr → ws:// URL) so the interpreter accepts
15// the same peer-address surface as the compiled path. Pure string logic, no
16// libp2p, no target gating — identical on native and wasm.
17pub mod addr;
18
19// The native WebSocket relay server + client. A LIGHT capability behind its own
20// `relay` feature (tokio-tungstenite, NO libp2p) so the interpreter can network
21// over the relay without the mesh stack. `networking` implies `relay`.
22#[cfg(all(not(target_arch = "wasm32"), feature = "relay"))]
23pub mod relay;
24
25// Browser relay client — a `web-sys` WebSocket speaking `relay_proto`, the
26// browser's door into a native node's relay. wasm-only; no libp2p.
27#[cfg(target_arch = "wasm32")]
28pub mod relay_browser;
29
30// The cross-target `Net` handle the interpreter holds — native RelayClient or
31// browser WebSocket behind one API. Available wherever a relay client is.
32#[cfg(any(all(not(target_arch = "wasm32"), feature = "relay"), target_arch = "wasm32"))]
33pub mod net;
34
35// Native-only core modules
36#[cfg(not(target_arch = "wasm32"))]
37pub mod time;
38#[cfg(not(target_arch = "wasm32"))]
39pub mod env;
40#[cfg(not(target_arch = "wasm32"))]
41pub mod random;
42#[cfg(not(target_arch = "wasm32"))]
43pub mod text;
44
45// === Feature-Gated Modules ===
46
47// Persistence feature: file operations, storage, VFS
48#[cfg(feature = "persistence")]
49pub mod file;
50#[cfg(feature = "persistence")]
51pub mod fs;
52#[cfg(feature = "persistence")]
53pub mod storage;
54
55// Networking feature: P2P networking
56#[cfg(feature = "networking")]
57pub mod network;
58
59// Concurrency feature: parallel computation
60#[cfg(feature = "concurrency")]
61pub mod concurrency;
62#[cfg(feature = "concurrency")]
63pub mod memory;
64
65// Distributed<T> requires both networking AND persistence
66#[cfg(all(feature = "networking", feature = "persistence"))]
67pub mod distributed;
68
69// CRDT sync wrapper requires networking (uses tokio + libp2p)
70#[cfg(feature = "networking")]
71pub mod crdt;
72
73// Runtime support for the Word8/16/32/64 ring types in compiled LOGOS (constructors,
74// rotations, Showable). Operators live on the newtypes themselves in logicaffeine_base.
75pub mod word_rt;
76
77// ML-KEM (Kyber) NTT runtime kernel (scalar + AVX2 i16×16) reached via the `mlkemNtt` stdlib fn.
78pub mod ntt;
79
80// Keccak-f[1600] + SHA-3 / SHAKE — the symmetric/hash layer (reached via sha3_256/shake128/… ).
81pub mod keccak;
82
83// ChaCha20-Poly1305 AEAD (RFC 8439) — the symmetric seal for the post-quantum channel.
84pub mod aead;
85
86// ML-KEM-768 (FIPS-203) keygen/encaps/decaps composed from the NTT + Keccak kernels — the
87// post-quantum key exchange for the channel handshake.
88pub mod mlkem;
89
90// ML-DSA-65 (FIPS-204) signature kernels — the post-quantum signature complement to ML-KEM.
91pub mod mldsa;
92
93// Re-export tokio for async main support (native only)
94#[cfg(not(target_arch = "wasm32"))]
95pub use tokio;
96
97// Re-export commonly used items
98pub use io::{show, read_line, println, eprintln, print, Showable};
99pub use temporal::{LogosDate, LogosMoment, LogosSpan, LogosTime};
100pub use word_rt::{
101    hsum_lanes4, int_of_word16, int_of_word32, int_of_word64, lanes16_word16, lanes4_word64,
102    lanes8_word32, montmul32, mul32x32to64, mulhi16, splat4_word64, and_not4,
103    rotl, rotr, word_and, word_or, word_not, seq_of_lanes16, seq_of_lanes4, word32_shr, word64_and, word64_shl, word64_shr,
104    seq_of_lanes8, splat16_word16, splat8_word32, word16, word32, word64, word8, Lanes16Word16,
105    Lanes4Word64, Lanes8Word32, Word16, Word32, Word64, Word8, WordRotate,
106    Lanes4Word32, lanes4_word32, lanes4_of, seq_of_lanes4w32, sha1rnds4, sha1msg1, sha1msg2, sha1nexte,
107    Lanes16Word8, lanes16_word8, seq_of_lanes16w8, splat16_word8, shuffle16, shr_bytes16,
108    interleave_lo16, interleave_hi16, byte_add16, maddubs16, packus16,
109};
110pub use ntt::{
111    mlkem_base_mul, mlkem_byte_decode, mlkem_byte_encode, mlkem_cbd2, mlkem_cbd3, mlkem_compress,
112    mlkem_decompress, mlkem_inv_ntt, mlkem_ntt, mlkem_sample_a, mlkem_sample_ntt, mlkem_to_mont,
113};
114pub use keccak::{sha3_256, sha3_512, shake128, shake256};
115
116/// Panic with a custom message (used by generated LOGOS code)
117pub fn panic_with(reason: &str) -> ! {
118    panic!("{}", reason);
119}
120
121/// Formatting utilities
122pub mod fmt {
123    pub fn format<T: std::fmt::Display>(x: T) -> String {
124        format!("{}", x)
125    }
126}