WeaveDocs
L1fe Crypto

Internals

Internal layout of `l1fe-crypto`: Merkle nodes, namespaces, discovery keys, and keypair derivation under HKDF-SHA256.

Purpose

L1FE crypto compatibility crate for keypairs, signatures, encryption, Merkle nodes, namespaces, and discovery keys.

This page follows the real source shape for L1fe 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 — l1feid/l1fe-crypto/src/lib.rs
  • KeyPair — l1feid/l1fe-crypto/src/lib.rs
  • Node — l1feid/l1fe-crypto/src/lib.rs
  • CryptoError — l1feid/l1fe-crypto/src/lib.rs
  • NamespaceCount — l1feid/l1fe-crypto/src/lib.rs

Example shape

use l1fe_crypto::{
    derive_nonce, hash, hkdf_sha256, namespace, NamespaceCount, EncryptionKeyPair, Node,
};

fn main() {
    // Internals: l1fe-crypto bundles hashing, HKDF expansion, nonce derivation,
    // and a typed Node for Merkle layers. Each primitive is exposed as a free
    // function so callers can compose them without instantiating heavy objects.

    // 1. Blake3 hash over multiple buffers.
    let digest = hash(&[b"weave/".as_slice(), b"identity/", b"v1"]);

    // 2. Derive a per-session nonce from a label + seed.
    let nonce = derive_nonce("session/inbox", &digest);

    // 3. Expand the digest into a longer keystream via HKDF-SHA256.
    let okm = hkdf_sha256(&digest, b"salt", b"info", 64);

    // 4. Mint N deterministic namespace tags for sub-feeds.
    let tags = namespace("weave.identity", 3usize);

    // 5. Merkle Node and asymmetric encryption keypair surfaces.
    let _node = Node { index: 0, size: 1, hash: digest };
    let _enc_kp = EncryptionKeyPair::default();

    println!(
        "digest={} nonce_len={} okm_len={} ns_tags={}",
        hex::encode(digest),
        nonce.len(),
        okm.len(),
        tags.len(),
    );
}