content-addressable
Data carries its own proof of integrity, intrinsically.
A foundational Rust crate for content addressing. A content address is not a name assigned to data by an authority — it is derived from the data itself. Give someone the bytes and the address, and they can recompute the address and know, with no trusted third party, that the bytes are exactly what the address names. The proof travels with the data.
This crate is deliberately small and honest: it is the instrument, not the sky.
IPLD-native
This crate does not roll its own identifier format or canonicalization. It speaks the multiformats / IPLD stack, so its artifacts interoperate with the wider content-addressed world (IPFS, IPLD, libp2p, and friends):
ContentIdis a newtype over a real IPLDCid(CID v1), from thecidcrate re-exported byipld-core.- Identities are BLAKE3 multihashes (multihash code
0x1e), via themultihashcrate. - The codec is canonical dag-cbor (
0x71), viaserde_ipld_dagcbor. dag-cbor is the canonical form: strict map key ordering, definite-length arrays/maps, and tag-42 links are enforced by the codec — so determinism is a property of the encoder, not of caller discipline.
The CID is built explicitly: BLAKE3(bytes) → Multihash::wrap(0x1e, digest)
→ Cid::new_v1(0x71, mh).
Usage
Implement ContentAddressable by providing canonical_form; you get
content_id and verify for free:
use ;
use Serialize;
use BTreeMap;
let r = Record ;
let id = r.content_id.unwrap; // a CIDv1 (dag-cbor + BLAKE3)
assert!; // self-certifying
println!; // base32-lower multibase string
Alpha status — bytes are NOT frozen
This is 0.1.0-alpha.1, an explicitly non-frozen alpha. The exact
bytes this crate emits are not a stability contract yet. There is an open
byte/wire "must-fix gate" with 10 items to settle before 0.1.0,
including (non-exhaustive):
- The frozen serde representation of
ContentId(currently a dag-cbor tag-42 link via the innerCid's serde). - The default multibase used by
Display/FromStr. - Whether the hash function (BLAKE3) and codec (dag-cbor) are fixed forever or selectable.
- Multihash digest length policy.
- CID version policy (v1 only?).
- Behavior on non-canonical input passed to
from_canonical_bytes. - Error variant stability (
ContentErroris#[non_exhaustive]). - Whether
verifymismatch should ever be anErrvsOk(false). - The public re-export surface from the crate root.
- MSRV floor and edition policy.
Until 0.1.0, do not treat alpha output as a durable on-disk format.
Not compatible with the pre-alpha Python sibling
This crate is not byte-compatible with the earlier pre-alpha Python
content-addressable sibling, which used SHA3-256 + pickle. That design
is abandoned here in favor of the IPLD-native stack (BLAKE3 + CIDv1 +
canonical dag-cbor). Addresses produced by the two are unrelated.
Development
Or directly:
The pre-push hook (.githooks/pre-push) mirrors .github/workflows/ci.yml.
Do not bypass it with --no-verify.
License
Apache-2.0. See LICENSE.