- A particular form of Content Addressing for the Decentralized Web.
- It was developed for IPFS, but has broad implications.
- It contains Cryptographic Hash and a Codec.
- Codecs encode and decode data in certain formats.
- Git, Bitcoin and Ethereum all use content addressing.
- CID creates an universal identifier for any of these systems.
+-------+------------------------------+
| Codec | Multihash |
+-------+------------------------------+- Multihash or the self-describing hash, contains Hash Type and Hash Value.
+------------------------------+
| Codec |
+------------------------------+
| |
| Multihash |
| +----------+---------------+ |
| |Hash Type | Hash Value | |
| +----------+---------------+ |
| |
+------------------------------+- We generate fingerprint by using a cryptogrphic algorithm that maps input of arbitrary size (data or a file) to output of fixed size.
- We call the output cryptographic hash digest or simply hash.
The cryptographic algorithm used must generate hashes that have the following characteristics:
- Deterministic: The same input should always produce the same hash.
- Uncorrelated: A small change in the input should generate a completely different hash.
- One-way: It should be infeasible to reconstruct the data from the hash.
- Unique: Only one file can produce one specific hash.
IPFS uses sha2-256 by default, though a CID supports any strong cryptographic hash algorithm.
- Hashing algorithms may prove to be insecure through time, so multihash adds the ability to know which algorithms was used to generate the hash, thus making the CID generalized.
- For this reason it is called the self-describing hash.
- Multihash follow the
TLVpattern (type-length-value).
-
type: identifier of the cryptographic algorithm used to generate the hash (e.g. the identifier ofsha2-256would be18-0x12in hexadecimal) - see the multicodec table for all the identifiers -
length: the actual length of the hash (usingsha2-256it would be256bits, which equates to32bytes) -
value: the actual hash value -
To display
0and1of the output to string, IPFS usesbase58btcencoding. This version was known asCID0. -
The initials
Qm...is thus common in IPFS.
Problems with CID0
- How do we know what method was used to encode the data?
- How do we know what method was used to create the string representation of the CID? Will we always be using
base58btc?
These problems were addressed in CID1, which is the current version of CID.
- This new version adds a new prefix known as Multicodec Prefix which tells which encoding was used on the data.
- It could tell whether it is encoded with CBOR, Protobuf, plain JSON, etc.
- Here's the complete table.
- The
dag-pbis one of many different types of IPLD (InterPlanetary Linked Data) codecs. - This multicodec is not only limited to IPFS and IPLD but is a part of the Multformats project.
- Multiformats project has implications in wide variety of projects including the CID.


