[ANN] cid 0.1.0 - Content Identifiers in OCaml

I’m happy to announce the initial release of cid, an OCaml library for working with Content Identifiers. These are like your usual hash-based identifiers used in content-addressable stores, but are built on multiformat libraries. See [ANN] multicodec, multibase, multihash and multihash-digestif for the initial release of the OCaml versions of these libraries.

The main takeaway is that the identifiers are self-describing helping build more permanent and interoperable content-addressed systems (e.g. they are used in the IPFS protocol).

let () =
  let s = "foo" in
  let hash =
    Multihash_digestif.of_cstruct `Sha3_256 (Cstruct.of_string s)
    |> Result.get_ok
  let cid = Cid.v ~version:`Cidv1 ~codec:`Raw ~base:`Base32 ~hash in
  Format.printf "Base encoded: %s\nHuman: %a" 
    (Cid.to_string cid) Cid.pp_human cid

Base encoded: bafkrmidw2o6edspvrd37zugvx5drr6hyjmoedmqiqjydcafz5okbhad4ae
Human: cidv1 - base32 - raw - ident(sha3-256) length(32) digest(
76 d3 bc 41 c9 f5 88 f7  fc d0 d5 bf 47 18 f8 f8
4b 1c 41 b2 08 82 70 31  00 b9 eb 94 13 80 7c 01

There’s also a small example the repository of replacing Irmin’s default hash implementation to use cid.

Happy Hacking :camel: