WeaveDocs
Strand Id Encoding

Internals

Internals of `strand-id-encoding` — z-base-32 alphabet, entity prefix tables, and legacy hex compatibility paths.

Purpose

z-base-32 and hex strand identity encoding with entity prefixes and compatibility helpers.

This page follows the real source shape for Strand Id Encoding and explains the workflow a developer is likely to use first.

Developer workflow

Start from the smallest constructor or builder, perform one meaningful operation, inspect the returned state, then add the relevant policy, storage, or network integration. The examples below should be expanded whenever the crate API changes.

Primary types to know

  • StrandId — libs/strand-id-encoding/src/lib.rs
  • StrandIdentity — libs/strand-id-encoding/src/lib.rs
  • EntityType — libs/strand-id-encoding/src/lib.rs
  • StrandIdError — libs/strand-id-encoding/src/lib.rs

Example shape

use strand_id_encoding::{decode_id, encode_id, encode_entity_id, EntityType, StrandIdError};

fn main() {
    // The encoder uses a versioned, multibase-style prefix so future schemes
    // can coexist with current IDs without ambiguity.
    let raw: [u8; 32] = [0xAB; 32];
    let id_str = encode_id(&raw);
    let with_kind = encode_entity_id(EntityType::Agent, &raw);

    // The decoder validates the version byte and length. A truncated value
    // surfaces as StrandIdError::Length so callers can fall back gracefully.
    match decode_id("not-a-real-id") {
        Ok(_) => unreachable!(),
        Err(StrandIdError::Format(_)) => println!("rejected malformed input"),
        Err(other) => eprintln!("other error: {other}"),
    }

    println!(
        "id={} entity_qualified={} prefix_byte={:#04x}",
        id_str,
        with_kind,
        id_str.as_bytes().first().copied().unwrap_or(0),
    );
}