Skip to main content

Module manifest

Module manifest 

Source
Expand description

Fixed-size chunking, Merkle-root computation, and manifest construction for content larger than one storage block. Ported from macula’s own macula_manifest (SDK) — see plans/PLAN_WIRE_PROTOCOL.md §12.2.

Mirrors the reference byte-for-byte: same MCID format, same default chunk size (256 KiB), same Merkle fold (including the odd-leaf-count rule — pair the last hash with itself), same canonical-CBOR MCID derivation. Verified against real macula_manifest:create/2 / chunk_mcid/3 / verify/2 output (even and odd chunk counts, to exercise both branches of the Merkle fold) — see this module’s tests.

Two different wire representations of name, both verified separately, not confused with each other: compute_mcid’s canonical hash input wraps name as CBOR text (a deliberate, narrow special case in the reference, just for that hash computation), while to_wire — the actual manifest map as sent in a _content.put_manifest CALL payload — encodes name as a raw byte string, matching its binary() type. Confirmed directly by encoding a real manifest through the general deterministic-CBOR codec and inspecting the bytes, not inferred from the type spec alone — see the CALL/PUBLISH procedure/topic lesson in src/frame.rs for why that inference alone wasn’t trusted here.

Structs§

ChunkInfo
CreateOptions
Manifest

Enums§

Algorithm
FromWireError
VerifyError

Constants§

DEFAULT_CHUNK_SIZE
256 KiB — matches macula_manifest:default_chunk_size/0.

Functions§

block_mcid
The MCID a whole blob is stored/fetched under when it’s small enough to be a single block (no manifest at all). Matches macula_content_transfer:put_single_block/3 exactly: always BLAKE3, regardless of any algorithm preference — single-block content has no algorithm choice, only chunked/manifest content does.
chunk_mcid
The MCID a chunk at index is stored/fetched under — the station derives this same value independently when serving the chunk, so both sides agree on its address without exchanging it.
create
Split data into fixed-size chunks and build its manifest. Returns the manifest and the chunk bytes in order (index 0 first) — a caller uploads each chunk (_content.put_block) then the manifest itself (_content.put_manifest), per §12.2.
from_wire
Parse a manifest as received from a _content.get_manifest RESULT.
mcid_is_chunked
Whether mcid addresses a manifest (chunked content) rather than a single raw block — determined from its own codec byte, no network round trip needed. Matches macula_content_transfer:is_chunked/2’s get-side check.
to_wire
Encode manifest as it’s actually sent in a _content.put_manifest CALL payload — name as bytes (its real binary() type), NOT the text-wrapped form compute_mcid uses internally. See this module’s doc comment.
verify
Verify reassembled data against manifest: size, then a fresh Merkle root over data re-chunked the same way.

Type Aliases§

Mcid
<<Version:8, Codec:8, Hash:32/binary>> — 34 bytes.