Weave documentation
Rust referenceweave-strand

weave-strand · crate

Source declarations, signatures and documentation for crate.

Source: sigil/weave/models/strand/src/lib.rs. SHA-256: f09f7bcde22336051417cbcc71553f88c632f22b6e4ac63ebc86f2252ea2ee73.

This reference follows declared source modules, retains conditional attributes, and includes public declarations and implementation methods. Private-module re-exports and trait resolution require the compiler; this is a source reference, not a claim that every listed item is a root import. Function bodies and constant values are omitted.

pub use bitfield::Bitfield;

pub use bitfield::Bitfield;

Source line: 62.

pub use merkle_tree::{MerkleTree, Node, Proof as MerkleProof};

pub use merkle_tree::{MerkleTree, Node, Proof as MerkleProof};

Source line: 63.

pub use storage::{FileStorage, MemoryStorage, Storage};

pub use storage::{FileStorage, MemoryStorage, Storage};

Source line: 64.

::Config

Type alias for compatibility

pub type Config = StrandConfig;

Source line: 69.

::StrandError

Error types for strand operations

#[derive(Debug, Error)]
pub enum StrandError {
    /// Storage backend error
    #[error("Storage error: {0}")]
    Storage(#[from] storage::StorageError),

    /// Invalid configuration
    #[error("Configuration error: {0}")]
    Configuration(String),

    /// Cryptographic verification failed
    #[error("Verification failed: {0}")]
    VerificationFailed(String),

    /// Block not found
    #[error("Block not found: {0}")]
    BlockNotFound(u64),

    /// Invalid merkle proof
    #[error("Invalid proof")]
    InvalidProof,

    /// Invalid block sequence
    #[error("Invalid sequence: expected {expected}, got {actual}")]
    InvalidSequence {
        /// Expected sequence number
        expected: u64,
        /// Actual sequence number received
        actual: u64,
    },

    /// Sparse mode error
    #[error("Sparse mode error: {0}")]
    SparseError(String),

    /// Corrupted data
    #[error("Data corruption detected: {0}")]
    CorruptedData(String),

    /// I/O error
    #[error("I/O error: {0}")]
    Io(#[from] std::io::Error),

    /// Serialization error
    #[error("Serialization error: {0}")]
    Serialization(#[from] serde_json::Error),

    // Network and identity errors are handled at higher layers
    /// Not implemented yet (used only for cross-crate sequencing gates)
    #[error("Not implemented: {0}")]
    NotImplemented(&'static str),
}

Source line: 73.

::Result

Result type for strand operations

pub type Result<T> = std::result::Result<T, StrandError>;

Source line: 126.

::recover_remote_writer_public_key

Recover and verify the immutable writer key for a legacy read-only on-disk replica that predates the SDK's remote_public_key sidecar.

A local writer store (one with a persisted secret key) returns Ok(None). A keyless store must contain at least one complete, consistently signed block; empty or conflicting keyless stores fail closed instead of being reopened under a newly generated writable identity.

pub fn recover_remote_writer_public_key(path: impl AsRef<Path>) -> Result<Option<[u8; 32]>>;

Source line: 135.

::StrandConfig

Configuration for a strand log

#[derive(Clone, Serialize, Deserialize, Default)]
pub struct StrandConfig {
/// Optional storage path for persistence

pub storage_path: Option<PathBuf>,
/// Encryption settings

pub encrypted: bool,
/// Sparse mode (download blocks on demand)

pub sparse: bool,
/// Value encoding (e.g., "binary", "utf-8", "json")

pub value_encoding: String,
/// Optional keypair for the writer (raw Ed25519 keys)

#[serde(skip)]
pub keypair: Option<zer0_crypto::KeyPair>,
/// Optional public key for read-only strands

#[serde(skip)]
pub public_key: Option<[u8; 32]>
}

Source line: 168.

::StrandConfig::new

Create a new config with default settings

pub fn new() -> Self;

Source line: 203.

::StrandConfig::with_storage

Set the storage path

pub fn with_storage(mut self, path: impl AsRef<Path>) -> Self;

Source line: 215.

::StrandConfig::with_encryption

Enable encryption

pub fn with_encryption(mut self) -> Self;

Source line: 221.

::StrandConfig::with_sparse

Set sparse mode

pub fn with_sparse(mut self) -> Self;

Source line: 227.

::StrandConfig::with_keypair

Set the keypair

pub fn with_keypair(mut self, keypair: zer0_crypto::KeyPair) -> Self;

Source line: 233.

::StrandConfig::with_public_key

Set the public key for read-only strands

pub fn with_public_key(mut self, public_key: [u8; 32]) -> Self;

Source line: 239.

Header information for each block

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Header {
/// Protocol version

pub version: u8,
/// Block sequence number

pub seq: u64,
/// Length of the data

pub length: u64,
/// Byte offset in the data file

#[serde(rename = "byteOffset")]
pub byte_offset: u64,
/// Hash of the previous signed block header and payload.

#[serde(default)]
pub prev_hash: [u8; 32],
/// Writer public key

pub writer_public_key: [u8; 32],
/// Timestamp when block was created

pub timestamp: u64,
/// Signature of the block

pub signature: Vec<u8>
}

Source line: 247.

::Stats

Replication statistics

#[derive(Debug, Clone, Default)]
pub struct Stats {
/// Number of blocks uploaded

pub uploaded: u64,
/// Number of blocks downloaded

pub downloaded: u64,
/// Number of bytes uploaded

pub uploaded_bytes: u64,
/// Number of bytes downloaded

pub downloaded_bytes: u64,
/// Number of peers connected

pub peers: usize,
/// Number of blocks verified

pub verified: u64,
/// Number of blocks rejected (invalid signature, etc.)

pub rejected: u64
}

Source line: 277.

::ReplicationStream

Replication stream for strand data

pub struct ReplicationStream {

}

Source line: 295.

::ReplicationStream::new

Create a new replication stream

pub fn new(strand: Arc<Strand>) -> Self;

Source line: 303.

::ReplicationStream::handshake

Prepare the stream for range iteration.

Network transport handshake lives in weave-sdk. This local API only succeeds when a [ReplicationClient] is installed (sparse/network mode) or the strand already has local blocks to iterate. It never reports fake network success.

pub async fn handshake(&mut self) -> Result<()>;

Source line: 317.

::ReplicationStream::stats

Get current replication statistics

pub fn stats(&self) -> &Stats;

Source line: 327.

::ReplicationStream::download_range

Begin downloading a range from the remote peer via the installed client.

pub async fn download_range(&mut self, start: u64, end: u64, linear: bool) -> Result<()>;

Source line: 332.

::ReplicationStream::cancel_range

Cancel a previously scheduled range (best-effort local marker).

pub async fn cancel_range(&mut self, _start: u64, _end: u64) -> Result<()>;

Source line: 345.

::ReplicationStream::next

Get the next block in the stream

pub async fn next(&mut self) -> Option<(u64, Vec<u8>)>;

Source line: 350.

::Strand

Single-writer append-only log with cryptographic integrity

pub struct Strand {

}

Source line: 366.

::Strand::new

Create a new strand log

pub async fn new(config: StrandConfig) -> Result<Self>;

Source line: 538.

::Strand::public_key

Get the public key

pub fn public_key(&self) -> &[u8];

Source line: 632.

::Strand::can_sign_provider_delegation

Whether this handle owns the immutable writer key and can issue a public provider delegation. Read-only replicas return false.

pub fn can_sign_provider_delegation(&self) -> bool;

Source line: 638.

::Strand::sign_provider_delegation

Sign a public discovery-provider delegation with this Strand's writer key. Read-only replicas cannot issue provider delegations; public DHT advertisements are therefore anchored in the immutable resource writer identity rather than a provider's self-asserted DID.

pub fn sign_provider_delegation(&self, payload: &[u8]) -> Result<Vec<u8>>;

Source line: 646.

::Strand::discovery_key

Get the discovery key

pub fn discovery_key(&self) -> &[u8; 32];

Source line: 659.

::Strand::len

Get the current length

pub fn len(&self) -> u64;

Source line: 664.

::Strand::is_empty

Check if the log is empty

pub fn is_empty(&self) -> bool;

Source line: 673.

::Strand::set_history_ceiling

Install or clear a higher-layer signed history ceiling.

A ceiling is the number of admissible blocks: a ceiling of N permits sequence numbers 0..N and rejects N or later. Lowering a ceiling is allowed; raising or clearing it must be authorized by the caller's own signed control plane.

pub fn set_history_ceiling(&self, ceiling: Option<u64>);

Source line: 683.

::Strand::history_ceiling

Return the currently enforced exclusive history ceiling.

pub fn history_ceiling(&self) -> Option<u64>;

Source line: 691.

::Strand::history_checkpoint

Return the complete higher-layer checkpoint currently enforced by this handle. Replication handles must copy this pair atomically rather than reopening the same storage with an unconstrained default.

pub fn history_checkpoint(&self) -> (Option<u64>, Option<[u8; 32]>);

Source line: 698.

::Strand::set_history_checkpoint

Install a complete signed terminal checkpoint. A nonzero terminal length requires the exact terminal block-link hash.

pub fn set_history_checkpoint(
        &self,
        ceiling: u64,
        terminal_hash: Option<[u8; 32]>,
    ) -> Result<()>;

Source line: 704.

::Strand::terminal_checkpoint

Verify the complete locally stored chain and return its immutable terminal length and terminal block-link hash.

pub fn terminal_checkpoint(&self) -> Result<(u64, Option<[u8; 32]>)>;

Source line: 748.

::Strand::refresh_from_storage

Refresh in-memory metadata from the backing store.

This lets one handle observe blocks appended or replicated through a second handle that shares the same storage path.

pub fn refresh_from_storage(&self) -> Result<()>;

Source line: 779.

::Strand::config

Access the configuration

pub fn config(&self) -> &StrandConfig;

Source line: 795.

::Strand::append_sync

Append data to the log (synchronous)

pub fn append_sync(&mut self, data: &[u8]) -> Result<u64>;

Source line: 800.

::Strand::append

Append data to the log (async wrapper)

pub async fn append(&mut self, data: &[u8]) -> Result<u64>;

Source line: 898.

::Strand::get

Get data at a specific sequence number.

In sparse mode, a missing local block is fetched through the installed [ReplicationClient]. Without a client, sparse misses fail closed instead of pretending the block exists.

pub async fn get(&self, seq: u64) -> Result<Vec<u8>>;

Source line: 911.

::Strand::get_local

Read a block that is already local without invoking the sparse client. Used by network hooks to avoid recursive fetch loops.

pub async fn get_local(&self, seq: u64) -> Result<Vec<u8>>;

Source line: 976.

::Strand::fork

Fork the log (shallow copy of storage path if filesystem-backed)

pub async fn fork(&self, new_path: Option<&std::path::Path>) -> Result<Strand>;

Source line: 989.

::Strand::user_get

Read a value from user metadata KV

pub fn user_get(&self, key: &str) -> Option<Vec<u8>>;

Source line: 998.

::Strand::user_get_fresh

Read metadata from the authoritative backing store and refresh the process-local projection.

pub fn user_get_fresh(&self, key: &str) -> Result<Option<Vec<u8>>>;

Source line: 1004.

::Strand::user_set

Set a value in user metadata KV and persist

pub fn user_set(&self, key: String, value: Vec<u8>) -> Result<()>;

Source line: 1013.

::Strand::user_compare_and_set

Compare and replace one metadata value under the cross-process storage lease. A stale expected value returns Ok(false) and refreshes the local metadata projection without publishing the candidate.

pub fn user_compare_and_set(
        &self,
        key: String,
        expected: Option<&[u8]>,
        value: Vec<u8>,
    ) -> Result<bool>;

Source line: 1025.

::Strand::telemetry

Telemetry counters

pub fn telemetry(&self) -> (u64, u64);

Source line: 1044.

::Strand::replication

Create a replication handle for scheduling range downloads (no network deps)

pub async fn replication(&self, opts: ReplicationOptions) -> ReplicationHandle;

Source line: 1049.

::Strand::get_header

Get header at a specific sequence number

pub async fn get_header(&self, seq: u64) -> Result<Header>;

Source line: 1054.

::Strand::proof

Create a proof for a specific block

pub async fn proof(&self, seq: u64) -> Result<MerkleProof>;

Source line: 1077.

::Strand::verify_proof

Verify a proof

pub async fn verify_proof(&self, proof: &MerkleProof, data: &[u8]) -> Result<bool>;

Source line: 1087.

::Strand::set_replication_client

Install (or replace) the sparse/network download hook.

pub fn set_replication_client(&self, client: replication_client::SharedReplicationClient);

Source line: 1094.

::Strand::clear_replication_client

Remove any installed download hook.

pub fn clear_replication_client(&self);

Source line: 1099.

::Strand::has_replication_client

Whether a download hook is currently installed.

pub fn has_replication_client(&self) -> bool;

Source line: 1104.

::Strand::replication_client

Clone the installed download hook, if any.

pub fn replication_client(&self) -> Option<replication_client::SharedReplicationClient>;

Source line: 1109.

::Strand::is_sparse

Whether sparse mode is enabled on this handle.

pub fn is_sparse(&self) -> bool;

Source line: 1114.

::Strand::has_block

Whether block seq is present in the local bitfield.

pub fn has_block(&self, seq: u64) -> bool;

Source line: 1119.

::Strand::clear_cache

Clear cached data

pub fn clear_cache(&mut self);

Source line: 1124.

::Strand::ingest_remote_block

Ingest a verified remote block sequentially into local storage

pub async fn ingest_remote_block(&self, seq: u64, header: &Header, data: &[u8]) -> Result<()>;

Source line: 1223.

::replicate

Create a replication stream for this log

pub fn replicate(strand: Arc<Strand>) -> ReplicationStream;

Source line: 1359.

pub use policy::{set_strand_policy, AllowAllPolicy, StrandPolicy};

#[cfg(feature = "policy-hooks")]
pub use policy::{set_strand_policy, AllowAllPolicy, StrandPolicy};

Source line: 1364.

pub use replication_api::{RangeHandle, RangeSpec, ReplicationHandle, ReplicationOptions};

pub use replication_api::{RangeHandle, RangeSpec, ReplicationHandle, ReplicationOptions};

Source line: 1366.

pub use replication_client::{

ReplicationClient, SharedReplicationClient, UnsupportedReplicationClient, };

pub use replication_client::{
    ReplicationClient, SharedReplicationClient, UnsupportedReplicationClient,
};

Source line: 1367.

On this page

pub use bitfield::Bitfield;pub use merkle_tree::{MerkleTree, Node, Proof as MerkleProof};pub use storage::{FileStorage, MemoryStorage, Storage};::Config::StrandError::Result::recover_remote_writer_public_key::StrandConfig::StrandConfig::new::StrandConfig::with_storage::StrandConfig::with_encryption::StrandConfig::with_sparse::StrandConfig::with_keypair::StrandConfig::with_public_key::Header::Stats::ReplicationStream::ReplicationStream::new::ReplicationStream::handshake::ReplicationStream::stats::ReplicationStream::download_range::ReplicationStream::cancel_range::ReplicationStream::next::Strand::Strand::new::Strand::public_key::Strand::can_sign_provider_delegation::Strand::sign_provider_delegation::Strand::discovery_key::Strand::len::Strand::is_empty::Strand::set_history_ceiling::Strand::history_ceiling::Strand::history_checkpoint::Strand::set_history_checkpoint::Strand::terminal_checkpoint::Strand::refresh_from_storage::Strand::config::Strand::append_sync::Strand::append::Strand::get::Strand::get_local::Strand::fork::Strand::user_get::Strand::user_get_fresh::Strand::user_set::Strand::user_compare_and_set::Strand::telemetry::Strand::replication::Strand::get_header::Strand::proof::Strand::verify_proof::Strand::set_replication_client::Strand::clear_replication_client::Strand::has_replication_client::Strand::replication_client::Strand::is_sparse::Strand::has_block::Strand::clear_cache::Strand::ingest_remote_block::replicatepub use policy::{set_strand_policy, AllowAllPolicy, StrandPolicy};pub use replication_api::{RangeHandle, RangeSpec, ReplicationHandle, ReplicationOptions};pub use replication_client::{