chie/
lib.rs

1//! CHIE Protocol - Decentralized, privacy-preserving file sharing with zero-knowledge proofs.
2//!
3//! This is the meta crate that re-exports all CHIE Protocol components for convenient access.
4//!
5//! # Overview
6//!
7//! CHIE (Collective Hybrid Intelligence Ecosystem) is a decentralized content distribution
8//! system with cryptographic incentive mechanisms. This crate provides a unified API to all
9//! CHIE components:
10//!
11//! - **[`shared`]**: Common types, errors, and utilities
12//! - **[`crypto`]**: Cryptographic primitives (encryption, signatures, ZK proofs)
13//! - **[`core`]**: Node implementation and content management
14//! - **[`p2p`]**: P2P networking layer using rust-libp2p
15//!
16//! # Quick Start
17//!
18//! ```ignore
19//! use chie::prelude::*;
20//! use std::path::PathBuf;
21//!
22//! #[tokio::main]
23//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
24//!     // Create a content node
25//!     let config = NodeConfig {
26//!         storage_path: PathBuf::from("./chie-data"),
27//!         max_storage_bytes: 50 * 1024 * 1024 * 1024, // 50 GB
28//!         max_bandwidth_bps: 100 * 1024 * 1024 / 8,   // 100 Mbps
29//!         coordinator_url: "https://coordinator.chie.network".to_string(),
30//!     };
31//!
32//!     let mut node = ContentNode::with_storage(config).await?;
33//!
34//!     // Generate cryptographic keys
35//!     let keypair = KeyPair::generate();
36//!     println!("Public key: {:?}", keypair.public_key());
37//!
38//!     Ok(())
39//! }
40//! ```
41//!
42//! # Features
43//!
44//! ## Cryptography
45//!
46//! ```
47//! use chie::crypto::{KeyPair, generate_key, generate_nonce, encrypt, decrypt};
48//!
49//! // Generate keys
50//! let keypair = KeyPair::generate();
51//! let encryption_key = generate_key();
52//! let nonce = generate_nonce();
53//!
54//! // Encrypt/decrypt data
55//! let plaintext = b"Hello, CHIE!";
56//! let ciphertext = encrypt(plaintext, &encryption_key, &nonce).unwrap();
57//! let decrypted = decrypt(&ciphertext, &encryption_key, &nonce).unwrap();
58//! assert_eq!(plaintext.as_slice(), decrypted.as_slice());
59//! ```
60//!
61//! ## Content Management
62//!
63//! ```ignore
64//! use chie::shared::{ContentMetadataBuilder, ContentCategory, ContentStatus};
65//! use uuid::Uuid;
66//!
67//! let metadata = ContentMetadataBuilder::new()
68//!     .cid("QmExampleCID123")
69//!     .title("My Content")
70//!     .description("A sample content item")
71//!     .category(ContentCategory::ThreeDModels)
72//!     .size_bytes(1024 * 1024)
73//!     .price(100)
74//!     .creator_id(Uuid::new_v4())
75//!     .status(ContentStatus::Active)
76//!     .build()
77//!     .expect("Failed to build metadata");
78//! ```
79//!
80//! ## P2P Networking
81//!
82//! ```
83//! use chie::p2p::{CompressionManager, CompressionAlgorithm, CompressionLevel};
84//!
85//! let manager = CompressionManager::new(CompressionAlgorithm::Lz4, CompressionLevel::Fast);
86//! let data = b"Data to compress";
87//! let compressed = manager.compress(data).unwrap();
88//! let decompressed = manager.decompress(&compressed).unwrap();
89//! assert_eq!(data.as_slice(), decompressed.as_slice());
90//! ```
91//!
92//! # Module Structure
93//!
94//! | Module | Description |
95//! |--------|-------------|
96//! | [`shared`] | Common types, constants, errors, and utilities |
97//! | [`crypto`] | Cryptographic primitives and protocols |
98//! | [`core`] | Node implementation, storage, and protocol logic |
99//! | [`p2p`] | P2P networking, discovery, and gossip |
100
101#![cfg_attr(docsrs, feature(doc_cfg))]
102
103/// Re-export of `chie-shared` - Common types, errors, and utilities.
104pub use chie_shared as shared;
105
106/// Re-export of `chie-crypto` - Cryptographic primitives and protocols.
107pub use chie_crypto as crypto;
108
109/// Re-export of `chie-core` - Core node implementation and content management.
110pub use chie_core as core;
111
112/// Re-export of `chie-p2p` - P2P networking layer.
113pub use chie_p2p as p2p;
114
115/// Prelude module for convenient imports.
116///
117/// Import everything commonly needed with:
118/// ```
119/// use chie::prelude::*;
120/// ```
121pub mod prelude {
122    // ========================================
123    // From chie-shared
124    // ========================================
125
126    // Types
127    pub use chie_shared::{
128        BandwidthProof, BandwidthProofBuilder, BatchProofSubmission, ChunkRequest, ChunkResponse,
129        ContentCategory, ContentMetadata, ContentMetadataBuilder, ContentStatus,
130    };
131
132    // Errors
133    pub use chie_shared::{ChieError, ChieResult};
134
135    // Utilities
136    pub use chie_shared::{calculate_demand_multiplier, format_bytes, format_points, now_ms};
137    pub use chie_shared::generate_nonce as shared_generate_nonce;
138
139    // Config
140    pub use chie_shared::{NetworkConfig, StorageConfig};
141
142    // Metrics
143    pub use chie_shared::{BandwidthMetrics, CacheStats, OperationStats};
144
145    // Quotas
146    pub use chie_shared::{BandwidthQuota, RateLimitQuota, StorageQuota, UserQuota};
147
148    // ========================================
149    // From chie-crypto
150    // ========================================
151
152    // Core crypto types
153    pub use chie_crypto::{KeyPair, PublicKey, SecretKey};
154
155    // Encryption
156    pub use chie_crypto::{decrypt, encrypt, generate_key, generate_nonce, EncryptionError};
157
158    // Hashing
159    pub use chie_crypto::{hash, Hash};
160
161    // Signing
162    pub use chie_crypto::signing::{verify, SignatureBytes, SigningError};
163
164    // Key exchange
165    pub use chie_crypto::{KeyExchange, SharedSecret};
166
167    // ========================================
168    // From chie-core
169    // ========================================
170
171    // Node
172    pub use chie_core::{ContentNode, NodeConfig, PinnedContent};
173
174    // Storage
175    pub use chie_core::{ChunkStorage, split_into_chunks};
176
177    // Protocol
178    pub use chie_core::{create_bandwidth_proof, create_chunk_request};
179
180    // Analytics
181    pub use chie_core::AnalyticsCollector;
182
183    // Cache
184    pub use chie_core::TieredCache;
185
186    // Health
187    pub use chie_core::{HealthChecker, HealthStatus};
188
189    // ========================================
190    // From chie-p2p
191    // ========================================
192
193    // Compression
194    pub use chie_p2p::{CompressionAlgorithm, CompressionLevel, CompressionManager};
195
196    // Priority
197    pub use chie_p2p::{Priority, PriorityQueue};
198
199    // Discovery
200    pub use chie_p2p::{BootstrapManager, ContentRouter, DiscoveryConfig};
201
202    // Gossip
203    pub use chie_p2p::{ContentAnnouncement, ContentAnnouncementGossip, GossipConfig};
204
205    // Health
206    pub use chie_p2p::HealthMonitor;
207
208    // Metrics
209    pub use chie_p2p::MetricsCollector;
210}
211
212#[cfg(test)]
213mod tests {
214    use super::*;
215
216    #[test]
217    fn test_module_access() {
218        // Verify all modules are accessible
219        let _ = shared::ContentCategory::ThreeDModels;
220        let _ = crypto::generate_key();
221    }
222
223    #[test]
224    fn test_prelude_imports() {
225        use crate::prelude::*;
226
227        // Verify prelude types are available
228        let key = generate_key();
229        assert_eq!(key.len(), 32);
230
231        let nonce = generate_nonce();
232        assert_eq!(nonce.len(), 12);
233    }
234}