Content Identifier (CID) handling for Exosphere.ATProto.
CIDs are self-describing content-addressed identifiers used throughout Exosphere.ATProto for referencing data objects (DAG-CBOR) and blobs (raw bytes).
Exosphere.ATProto CID Requirements
Exosphere.ATProto uses a specific "blessed" CID format:
- CIDv1
- Multibase:
base32for string encoding, binary for DAG-CBOR - Multicodec:
dag-cbor(0x71) for data objects,raw(0x55) for blobs - Multihash:
sha-256(0x12) with 256 bits
Examples
# Create a CID from data
iex> {:ok, cid} = Exosphere.ATProto.CID.create(%{"hello" => "world"})
iex> to_string(cid)
"bafyreidykglsfhoixmivffc5uwhcgshx4j465xwqntbmu43nb2dzqwfvae"
# Parse a CID string
iex> {:ok, cid} = Exosphere.ATProto.CID.decode("bafyreidykglsfhoixmivffc5uwhcgshx4j465xwqntbmu43nb2dzqwfvae")
iex> cid.codec
:dag_cbor
# Create a CID for a blob
iex> {:ok, cid} = Exosphere.ATProto.CID.create_raw(<<binary_data>>)
iex> cid.codec
:raw
Summary
Functions
Create a CID for a DAG-CBOR encoded term.
Create a CID for a DAG-CBOR term, raising on error.
Create a CID for raw binary data (blobs).
Create a CID for raw binary data, raising on error.
Check if a CID uses the dag-cbor codec.
Decode a CID from its string representation.
Decode a CID string, raising on error.
Encode a CID to its string representation using base32.
Create a CID from raw bytes (without multibase prefix).
Create a CID from raw bytes, raising on error.
Check if a CID uses the raw codec.
Convert a CID to its raw byte representation (without multibase prefix).
Types
@type t() :: %Exosphere.ATProto.CID{ codec: :dag_cbor | :raw, hash: binary(), version: 1 }
Functions
Create a CID for a DAG-CBOR encoded term.
The term is encoded with Exosphere.ATProto.CBOR.encode/1 and hashed with SHA-256.
Examples
iex> {:ok, cid} = Exosphere.ATProto.CID.create(%{"foo" => "bar"})
iex> cid.codec
:dag_cbor
Create a CID for a DAG-CBOR term, raising on error.
Create a CID for raw binary data (blobs).
Examples
iex> {:ok, cid} = Exosphere.ATProto.CID.create_raw(<<1, 2, 3>>)
iex> cid.codec
:raw
Create a CID for raw binary data, raising on error.
Check if a CID uses the dag-cbor codec.
Decode a CID from its string representation.
Supports base32-encoded CIDv1 strings (prefix 'b').
Examples
iex> Exosphere.ATProto.CID.decode("bafyreidykglsfhoixmivffc5uwhcgshx4j465xwqntbmu43nb2dzqwfvae")
{:ok, %Exosphere.ATProto.CID{...}}
Decode a CID string, raising on error.
Encode a CID to its string representation using base32.
Create a CID from raw bytes (without multibase prefix).
Examples
iex> Exosphere.ATProto.CID.from_bytes(<<0x01, 0x71, 0x12, 0x20, hash::binary-32>>)
{:ok, %Exosphere.ATProto.CID{...}}
Create a CID from raw bytes, raising on error.
Check if a CID uses the raw codec.
Convert a CID to its raw byte representation (without multibase prefix).