Skip to main content

Crate nectar_primitives

Crate nectar_primitives 

Source
Expand description

Core primitives for a decentralized storage system

This crate provides the fundamental types and operations used in a decentralized storage system, including chunk types, address calculations, and binary merkle trees.

§Key Components

  • Chunks: Content-addressed and signed data chunks (ContentChunk, SingleOwnerChunk)
  • Binary Merkle Tree: Efficient content addressing and proof generation (bmt::Hasher)
  • SwarmAddress: 256-bit identifiers for network addressing

§Usage Examples

use nectar_primitives::{Chunk, DefaultContentChunk, DefaultSingleOwnerChunk};
use alloy_signer_local::LocalSigner;
use alloy_primitives::FixedBytes;

// Creating content chunks
let chunk = DefaultContentChunk::new(b"Hello, world!".as_slice()).unwrap();
let address = chunk.address();

// Creating content chunks with pre-computed address (e.g., from storage)
let address_copy = *address;
let chunk2 = DefaultContentChunk::with_address(b"Hello, world!".as_slice(), address_copy).unwrap();

// Creating signed chunks
let wallet = LocalSigner::random();
let id = FixedBytes::random();
let owner_chunk = DefaultSingleOwnerChunk::new(id, b"Signed data".as_slice(), &wallet).unwrap();

Re-exports§

pub use bmt::DEFAULT_BODY_SIZE;
pub use chunk::encryption::EncryptedChunkRef;
pub use chunk::encryption::EncryptionKey;
pub use chunk::ChunkEncrypt;
pub use chunk::EncryptedContentChunk;
pub use address::EXTENDED_PO;
pub use address::MAX_PO;
pub use address::SwarmAddress;
pub use bin::Bin;
pub use bin::BinError;
pub use error::PrimitivesError;
pub use error::Result;
pub use neighborhood_depth::recompute_neighborhood_depth;
pub use network_id::NetworkId;
pub use nonce::Nonce;
pub use overlay::compute_overlay;
pub use proximity_order::ProximityOrder;
pub use proximity_order::ProximityOrderError;
pub use spec::MAINNET;
pub use spec::StaticSpec;
pub use spec::SwarmSpec;
pub use spec::TESTNET;
pub use timestamp::Timestamp;
pub use timestamp::TimestampError;
pub use bmt::Hasher;
pub use bmt::HasherFactory;
pub use bmt::Proof;
pub use bmt::Prover;
pub use chunk::AnyChunk;
pub use chunk::BmtChunk;
pub use chunk::Chunk;
pub use chunk::ChunkAddress;
pub use chunk::ChunkSerialization;
pub use chunk::ChunkType;
pub use chunk::ChunkTypeId;
pub use chunk::ChunkTypeSet;
pub use chunk::ContentChunk;
pub use chunk::ContentOnlyChunkSet;
pub use chunk::SingleOwnerChunk;
pub use chunk::StandardChunkSet;
pub use store::ChunkGet;
pub use store::ChunkHas;
pub use store::ChunkPut;
pub use store::ChunkStoreError;
pub use store::MemoryStore;
pub use store::SyncChunkGet;
pub use store::SyncChunkHas;
pub use store::SyncChunkPut;
pub use file::EncryptedJoiner;
pub use file::JoinerReader;
pub use file::ChunkGetExt;
pub use file::ChunkRange;
pub use file::EntryRef;
pub use file::FileError;
pub use file::GenericJoiner;
pub use file::JoinRef;
pub use file::Joiner;
pub use file::TreeParams;
pub use file::join;
pub use file::EncryptedSyncJoiner;
pub use file::EncryptedSyncParallelSplitter;
pub use file::EncryptedSyncSplitter;
pub use file::sync_split_encrypted;
pub use file::GenericSyncJoiner;
pub use file::SyncChunkGetExt;
pub use file::SyncChunkPutExt;
pub use file::SyncJoiner;
pub use file::SyncParallelSplitter;
pub use file::SyncReadAt;
pub use file::SyncSplitter;
pub use file::sync_join;
pub use file::sync_split;
pub use bytes;

Modules§

address
Swarm address implementation
bin
Typed Kademlia bin index in the range 0..=MAX_PO.
bmt
Binary Merkle Tree (BMT) implementation
chunk
Chunk types and operations
error
Error types for the nectar-primitives crate
file
File splitting and joining for arbitrary-size data.
neighborhood_depth
Canonical neighborhood-depth recomputation.
network_id
Typed Swarm network identifier.
nonce
Typed nonce used in overlay address derivation.
overlay
Canonical overlay address derivation.
proximity_order
Typed Kademlia proximity order (PO) in the range 0..=MAX_PO.
signing
BzzAddress sign-data byte layout (Swarm handshake / hive shared spec).
spec
Canonical Swarm network spec - network_id, kademlia tuning, defaults.
store
Chunk storage traits and implementations.
timestamp
Typed unix-seconds timestamp used in BzzAddress sign-data.

Type Aliases§

DefaultAnyChunk
Default polymorphic chunk.
DefaultContentChunk
Default content-addressed chunk.
DefaultEncryptedSyncJoiner
Default encrypted sync file joiner.
DefaultHasher
Default BMT hasher.
DefaultJoiner
Default async file joiner.
DefaultMemoryStore
Default in-memory chunk store.
DefaultSingleOwnerChunk
Default single-owner chunk.
DefaultSyncJoiner
Default sync file joiner.
DefaultSyncSplitter
Default sync file splitter.