Weave Crypto
Hashing and Merkle
Hashing primitives in Weave Crypto — BLAKE3 hashing, Merkle node construction, and content-addressed identifiers.
Purpose
Ed25519, X25519, Merkle hashing, HKDF, random bytes, discovery keys, and namespaces.
This page follows the real source shape for Weave Crypto 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
EncryptionKeyPair— libs/weave-crypto/src/lib.rsKeyPair— libs/weave-crypto/src/lib.rsNode— libs/weave-crypto/src/lib.rsCryptoError— libs/weave-crypto/src/lib.rsNamespaceCount— libs/weave-crypto/src/lib.rs
Example shape
use weave_crypto::{data, hash, hash_into, parent, tree, Node};
fn main() {
// `data` produces a blake3 hash over a single buffer; `hash` accepts a slice
// of buffers and hashes them concatenated. Both return [u8; 32].
let leaf = data(b"block-0");
let multi = hash(&[b"block-0".as_slice(), b"|", b"block-1"]);
// hash_into avoids allocation for hot loops.
let mut out = [0u8; 32];
hash_into(&[b"hot path"], &mut out);
// Build merkle nodes and combine them with `parent` / `tree` to derive a root.
let l = Node { index: 0, size: 1, hash: data(b"left") };
let r = Node { index: 2, size: 1, hash: data(b"right") };
let parent_hash = parent(&l, &r);
let root = tree(&[l]);
println!(
"leaf={} parent={} root={}",
hex::encode(leaf),
hex::encode(parent_hash),
hex::encode(root),
);
let _ = multi;
}