Skip to content
This repository was archived by the owner on Jun 2, 2020. It is now read-only.

Commit 2c96150

Browse files
authored
Merge pull request #104 from rjharmon/patch-2
Improve CID concept doc (fixes #95). - Explain format and components of a CID - Explain how CIDs relate to label/address content - Add more relevant links to specs and concept docs
2 parents dbbee50 + 4eb95db commit 2c96150

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

content/guides/concepts/cid.md

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,36 @@ menu:
55
parent: concepts
66
---
77

8-
A *content identifier* is a value that addresses a single piece of content in IPFS. It is mainly a cryptographic hash of the content, but is encoded as a [multihash](https://github.com/multiformats/multihash) and [multicodec](https://github.com/multiformats/multicodec). (Note: older CIDs have a different design — see [version 0](#version-0) below.)
8+
A *content identifier*, or CID, is a label used to point to material in IPFS. It doesn't indicate _where_ the content is stored, but it forms a kind of address based on the content itself. CIDs are short, regardless of the size of their underlying content.
99

10-
<!-- TODO: explain more of the details of how CID v1 is composed here. -->
10+
CIDs are based on the content’s [cryptographic hash]({{< relref "./hashes.md" >}}). That means:
1111

12-
You can read up on the details in the [CID spec](https://github.com/ipld/cid). You might also want to check out the [CID inspector](http://cid-utils.ipfs.team/#zb2rhiVd5G2DSpnbYtty8NhYHeDvNkPxjSqA7YbDPuhdihj9L) for an interactive breakdown of CIDs.
12+
* Any difference in content will produce a different CID and
13+
* The same piece of content added to two different IPFS nodes using the same settings will produce _exactly the same CID_.
1314

14-
## Version 1
15+
## CID formats
1516

16-
Version 1 is the latest version of CID. It is used by default for `files` ([MFS](/concepts/mfs)) and `object` operations.
17+
CIDs can take a few different forms with different encoding bases or CID versions. Many of the existing IPFS tools still generate v0 CIDs, although the `files` ([MFS]({{< relref "./mfs.md" >}})) and `object` operations now use CIDv1 by default.
18+
19+
### Version 0
20+
21+
When IPFS was first designed, we used base 58-encoded multihashes as the content identifiers (This is simpler, but much less flexible than newer CIDs). CIDv0 is still used by default for many IPFS operations, so you should generally try to support v0.
22+
23+
If a CID is 46 characters starting with "Qm", it's a CIDv0 (for more details, check the [decoding algorithm](https://github.com/ipld/cid/blob/ef1b2002394b15b1e6c26c30545fd485f2c4c138/README.md#decoding-algorithm) in the CID specification).
24+
25+
### Version 1
26+
27+
CID v1 contains some leading identifiers that clarify exactly which representation is used, along with the content-hash itself. These include:
28+
29+
* A [multibase](https://github.com/multiformats/multibase) prefix, specifying the encoding used for the remainder of the CID
30+
* A CID version identifer, which indicates which version of CID this is
31+
* A [multicodec](https://github.com/multiformats/multicodec) identifier, indicating the format of the target content — it helps people and software to know how to interpret that content after the content is fetched
32+
33+
These leading identifiers also provide forward-compatibility, supporting different formats to be used in future versions of CID.
34+
35+
You can use the first few bytes of the CID to interpret the remainder of the content address and know how to decode the content after it's fetched from IPFS. For more details, check out the [CID specification](https://github.com/ipld/cid). It includes a [decoding algorithm](https://github.com/ipld/cid/blob/ef1b2002394b15b1e6c26c30545fd485f2c4c138/README.md#decoding-algorithm) and links to existing software implementations for decoding CIDs.
36+
37+
You might also want to check out the [CID inspector](http://cid-utils.ipfs.team/#zb2rhiVd5G2DSpnbYtty8NhYHeDvNkPxjSqA7YbDPuhdihj9L) for an interactive breakdown of differently-formatted CIDs.
1738

18-
## Version 0
1939

20-
When IPFS was first designed, we used base 58-encoded multihashes as the content identifiers. (This is simpler, but much less flexible than newer CIDs.) It is still used by default when adding files and blocks to IPFS, so you should generally try to support them.
2140

22-
The CID specification includes a [decoding algorithm](https://github.com/ipld/cid/blob/ef1b2002394b15b1e6c26c30545fd485f2c4c138/README.md#decoding-algorithm) you can use to distinguish CID v0 from newer versions.

0 commit comments

Comments
 (0)