Self-describing content-addressed identifiers for distributed systems
- Motivation
- How does it work? - Protocol Description
- Design Considerations
- Human Readable CIDs
- Versions
- Implementations
- FAQ
- Maintainers
- Contribute
- License
CID is a format for referencing content in distributed information systems, like IPFS. It leverages content addressing, cryptographic hashing, and self-describing formats. It is the core identifier used by IPFS and IPLD.
You can read an in-depth discussion on why this format was needed in IPFS here: ipfs/specs#130 (first post reproduced here)
CID is a self-describing content-addressed identifier. It uses cryptographic hashes to achieve content addressing. It uses several multiformats to achieve flexible self-description, namely multihash for hashes, multicodec-packed for data content types, and multibase to encode the CID itself into strings.
Current version: CIDv1
A CIDv1 has four parts:
<cidv1> ::= <mb><version><mcp><mh>
# or, expanded:
<cidv1> ::= <multibase-prefix><cid-version><multicodec-packed-content-type><multihash-content-address>
Where
<multibase-prefix>
is a multibase code (1 or 2 bytes), to ease encoding CIDs into various bases.<cid-version>
is a varint representing the version of CID, here for upgradability purposes.<multicodec-packed-content-type>
is a multicodec-packed code representing the content type or format of the data being addressed.<multihash-content-address>
is a multihash value, representing the cryptographic hash of the content being addressed. Multihash enables CIDs to use many different cryptographic hash function, for upgradability and protocol agility purposes.
That's it!
CIDs design takes into account many difficult tradeoffs encountered while building IPFS. These are mostly coming from the multiformats project.
- Compactness: CIDs are binary in nature to ensure these are as compact as possible, as they're meant to be part of longer path identifiers or URLs.
- Transport friendliness (or "copy-pastability"): CIDs are encoded with multibase to allow choosing the best base for transporting. For example, CIDs can be encoded into base58btc to yield shorter and easily-copy-pastable hashes.
- Versatility: CIDs are meant to be able to represent values of any format with any cryptographic hash.
- Avoid Lock-in: CIDs prevent lock-in to old, potentially-outdated decisions.
- Upgradability: CIDs encode a version to ensure the CID format itself can evolve.
It is advantageous to have a human readable description of a CID, solely for the purposes of debugging and explanation. We can easily transform a CID to a "Human Readable CID" as follows:
<hr-cid> ::= <hr-mbc> "-" <hr-cid-version> "-" <hr-mcp> "-" <hr-mh>
Where each sub-component is represented with its own human-readable form:
<hr-mbc>
is a human-readable multibase code (egbase58btc
)<hr-cid-version>
is the stringcidv#
(egcidv1
orcidv2
)<hr-mcp>
is a human-readable multicodec-packed code (egcbor
)<hr-mh>
is a human-readanble multihash (egsha2-256-256-abcdef0123456789...
)
For example:
# TODO example
# example CID
# corresponding human readable CID
CIDv0 is a backwards-compatible version, where:
- the
multibase
is alwaysbase58btc
and implicit (not written) - the
multicodec
is alwaysprotobuf-mdag
and implicit (not written) - the
cid-version
is alwayscidv0
and implicit (not written) - the
multihash
is written as is.
cidv0 ::= <multihash-content-address>
See the section: How does it work? - Protocol Description
<cidv1> ::= <multibase-prefix><cid-version><multicodec-packed-content-type><multihash-content-address>
Q. I have questions on multicodec, multibase, or multihash.
Please check their repositories: multicodec, multibase, multihash.
Q. Why does CID exist?
We were using base58btc encoded multihashes in IPFS, and then we needed to switch formats to IPLD. We struggled with lots of problems of addressing data with different formats until we created CIDs. You can read the history of this format here: ipfs/specs#130
Q. Is the use of multicodec-packed similar to file extensions?
Yes, kind of! like a file extension, the multicodec-packed identifier establishes the format of the data. Unlike file extensions, these are in the middle of the identifier and not meant to be changed by users. There is also a short table of supported formats.
Q. What formats (multicodec-packed codes) does CID support?
We are figuring this out at this time. It will likely be a table of formats for secure distributed systems. So far, we want to address: IPFS's original protobuf format, the new IPLD CBOR format, git, bitcoin, and ethereum objects.
Captain: @jbenet.
Contributions welcome. Please check out the issues.
Check out our contributing document for more information on how we work, and about contributing in general. Please be aware that all interactions related to IPLD are subject to the IPFS Code of Conduct.
Small note: If editing the README, please conform to the standard-readme specification.
This repository is only for documents. These are licensed under a CC-BY 3.0 Unported License © 2016 Protocol Labs Inc.