ipld/cid

Name: cid

Owner: IPLD

Description: Self-describing content-addressed identifiers for distributed systems

Created: 2016-09-09 16:04:53.0

Updated: 2018-05-21 16:58:04.0

Pushed: 2018-05-12 12:33:44.0

Homepage:

Size: 30

Language: null

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

CID (Content IDentifier)

Self-describing content-addressed identifiers for distributed systems

Table of Contents
Motivation

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: https://github.com/ipfs/specs/issues/130 (first post reproduced here)

How does it work? - Protocol Description

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 for data content types, and multibase to encode the CID itself into strings.

Current version: CIDv1

A CIDv1 has four parts:

v1> ::= <mb><version><mc><mh>
, expanded:
v1> ::= <multibase-prefix><cid-version><multicodec-content-type><multihash-content-address>

Where

That's it!

Design Considerations

CIDs design takes into account many difficult tradeoffs encountered while building IPFS. These are mostly coming from the multiformats project.

Human Readable CIDs

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:

cid> ::= <hr-mbc> "-" <hr-cid-version> "-" <hr-mc> "-" <hr-mh>

Where each sub-component is represented with its own human-readable form:

For example:

ample CID
he5P4gXftAwvA4eXQ5HJwsER2owDyS9sKaQRRVQPn93bA
rresponding human readable CID
58btc - cidv1 - raw - sha2-256-256-6e6ff7950a36187a801613426e858dce686cd7d7e3c0fc42ee0330072d245c95

See: http://cid-utils.ipfs.team/#zb2rhe5P4gXftAwvA4eXQ5HJwsER2owDyS9sKaQRRVQPn93bA

Versions
CIDv0

CIDv0 is a backwards-compatible version, where:

0 ::= <multihash-content-address>
CIDv1

See the section: How does it work? - Protocol Description

v1> ::= <multibase-prefix><cid-version><multicodec-content-type><multihash-content-address>
Decoding Algorithm

To decode a CID, follow the following algorithm:

  1. If it's a string (ASCII/UTF-8):
  2. If it is 46 characters long and starts with Qm..., it's a CIDv0. Decode it as base58btc and continue to step 2.
  3. Otherwise, decode it according to the multibase spec and:
    • If the first decoded byte is 0x12, return an error. CIDv0 CIDs may not be multibase encoded and there will be no CIDv18 (0x12 = 18) to prevent ambiguity with decoded CIDv0s.
    • Otherwise, you now have a binary CID. Continue to step 2.
  4. Given a (binary) CID (cid):
  5. If it's 34 bytes long with the leading bytes [0x12, 0x20, ...], it's a CIDv0.
    • The CID's multihash is cid.
    • The CID's multicodec is DagProtobuf
    • The CID's version is 0.
  6. Otherwise, let N be the first varint in cid. This is the CID's version.
    • If N == 1 (CIDv1):
    • The CID's multicodec is the second varint in cid
    • The CID's multihash is the rest of the cid (after the second varint).
    • The CID's version is 1.
    • If N <= 0, the CID is malformed.
    • If N > 1, the CID version is reserved.
Implementations
FAQ

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: https://github.com/ipfs/specs/issues/130

Q. Is the use of multicodec similar to file extensions?

Yes, kind of! like a file extension, the multicodec 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 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.

Maintainers

Captain: @jbenet.

Contribute

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.

License

This repository is only for documents. These are licensed under a CC-BY 3.0 Unported License © 2016 Protocol Labs Inc.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.