| Crates.io | chie-shared |
| lib.rs | chie-shared |
| version | 0.1.0 |
| created_at | 2026-01-18 13:48:09.771495+00 |
| updated_at | 2026-01-18 13:48:09.771495+00 |
| description | Shared types, errors, and utilities for CHIE Protocol |
| homepage | |
| repository | https://github.com/cool-japan/chie |
| max_upload_size | |
| id | 2052355 |
| size | 714,544 |
Shared types, errors, and utilities for the CHIE Protocol.
This crate provides common types and utilities used across all CHIE Protocol components including the coordinator server, P2P nodes, desktop client, and web applications.
schema feature)Add this to your Cargo.toml:
[dependencies]
chie-shared = { path = "../chie-shared" }
Enable JSON schema generation:
[dependencies]
chie-shared = { path = "../chie-shared", features = ["schema"] }
use chie_shared::{ContentMetadataBuilder, ContentCategory, ContentStatus};
use uuid::Uuid;
let creator_id = Uuid::new_v4();
let metadata = ContentMetadataBuilder::new()
.cid("QmExampleCID123")
.title("My 3D Model")
.description("A high-quality 3D model")
.category(ContentCategory::ThreeDModels)
.add_tag("blender")
.add_tag("game-ready")
.size_bytes(5 * 1024 * 1024) // 5 MB
.price(1000)
.creator_id(creator_id)
.status(ContentStatus::Active)
.build()
.expect("Failed to build metadata");
assert!(metadata.is_valid());
assert_eq!(metadata.size_mb(), 5.0);
use chie_shared::BandwidthProofBuilder;
let proof = BandwidthProofBuilder::new()
.content_cid("QmTest123")
.chunk_index(0)
.bytes_transferred(262144) // 256 KB
.provider_peer_id("12D3KooProvider")
.requester_peer_id("12D3KooRequester")
.provider_public_key(vec![1u8; 32])
.requester_public_key(vec![2u8; 32])
.provider_signature(vec![3u8; 64])
.requester_signature(vec![4u8; 64])
.challenge_nonce(vec![5u8; 32])
.chunk_hash(vec![6u8; 32])
.timestamps(1000, 1250) // 250ms latency
.build()
.expect("Failed to build proof");
assert!(proof.is_valid());
assert!(proof.meets_quality_threshold());
use chie_shared::{format_bytes, format_points, calculate_demand_multiplier};
// Format bytes for display
assert_eq!(format_bytes(1_048_576), "1.00 MB");
// Format points with thousands separator
assert_eq!(format_points(1_234_567), "1,234,567");
// Calculate reward multiplier based on demand/supply
let multiplier = calculate_demand_multiplier(100, 50);
assert_eq!(multiplier, 3.0); // High demand = 3x multiplier
Run tests:
cargo test
Run property-based tests:
cargo test --test proptests
Run benchmarks:
cargo bench
All core types are optimized for fast serialization/deserialization, minimal allocations, and efficient validation. See benches/ for detailed performance metrics.
See LICENSE file in the project root.