Skip to content

Commit e4236d1

Browse files
committed
docs: unify grammar tokens and tighten prose
Make the spec read consistently end to end: every grammar block now uses one vocabulary for the CID fields, and the narrative prose is trimmed for clarity. - unify binary grammar tokens across all sections - replace the inaccurate "ipld entries" note with a worked hex example - copyedit prose for concision and active voice - drop the "Variant - " heading prefix - repoint the IPIP template link to ipip-template.md
1 parent 6082d90 commit e4236d1

1 file changed

Lines changed: 22 additions & 19 deletions

File tree

src/data-formats/cid.md

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,19 @@ It leverages [content addressing](https://en.wikipedia.org/wiki/Content-addressa
4444
[cryptographic hashing](https://simple.wikipedia.org/wiki/Cryptographic_hash_function), and
4545
[self-describing formats](https://github.com/multiformats/multiformats).
4646
It is the core identifier used by [IPFS](https://ipfs.tech) and [IPLD](https://ipld.io).
47-
It uses a [multicodec](https://github.com/multiformats/multicodec) to indicate its version, making it fully self describing.
47+
It uses a [multicodec](https://github.com/multiformats/multicodec) to indicate its version, making it fully self-describing.
4848

4949
## What is it?
5050

5151
A CID is a self-describing content-addressed identifier.
52-
It uses cryptographic hashes to achieve content addressing. It uses several
53-
[multiformats](https://github.com/multiformats/multiformats) to achieve flexible self-description, namely:
52+
It uses cryptographic hashes for content addressing and several
53+
[multiformats](https://github.com/multiformats/multiformats) for flexible self-description, namely:
5454

55-
1. [multihash](https://github.com/multiformats/multihash) for content-addressed hashing, and
56-
2. [multicodec](https://github.com/multiformats/multicodec) to type that addressed content,
57-
to form a binary self-contained identifier, and optionally also
58-
3. [multibase](https://github.com/multiformats/multibase) to encode that binary CID as a string.
55+
1. [multihash](https://github.com/multiformats/multihash) for content-addressed hashing,
56+
2. [multicodec](https://github.com/multiformats/multicodec) to type that addressed content, and
57+
3. optionally, [multibase](https://github.com/multiformats/multibase) to encode the binary CID as a string.
58+
59+
The first two form a self-contained binary identifier; the third is added only when the CID is written as text.
5960

6061
Concretely, it's a *typed* content address: a tuple of `(content-type, content-address)`.
6162

@@ -67,9 +68,11 @@ CIDv1 is a **binary** format composed of [unsigned varints](https://github.com/m
6768
prefixing a hash digest to form a self-describing "content address":
6869

6970
```text
70-
<cidv1> ::= <CIDv1-multicodec><content-type-multicodec><content-multihash>
71-
# or, expanded:
72-
<cidv1> ::= <`0x01`, the code for `CIDv1`><another code from `ipld` entries in multicodec table that signals content type of data being addressed><multihash of addressed data>
71+
<cidv1> ::= <multicodec-cidv1><multicodec-content-type><multihash-content-address>
72+
73+
# example: a CIDv1 addressing the raw bytes "hello", in hex
74+
01 55 12 20 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
75+
# 01: cidv1 | 55: raw | 12 20: sha2-256, 32 bytes | 2cf2...: sha2-256 digest of "hello"
7376
```
7477

7578
Where
@@ -78,15 +81,15 @@ Where
7881
- `<multicodec-content-type>` is a [multicodec](https://github.com/multiformats/multicodec) code representing the content type or format of the data being addressed.
7982
- `<multihash-content-address>` is a [multihash](https://github.com/multiformats/multihash) value, which uses a registry of hash function abbreviations to prefix a cryptographic hash of the content being addressed, thus making it self-describing.
8083

81-
## Variant - Stringified Form
84+
## Stringified Form
8285

83-
Since CIDs have many applications outside of binary-only contexts, a given CID may need to be base-encoded for different consumers or transports.
86+
Since CIDs have many applications outside binary-only contexts, a CID may need to be base-encoded for different consumers or transports.
8487
In such applications, CIDs are expressed as a Unicode *string* with a [multibase](https://github.com/multiformats/multibase) prefix.
85-
The multibase prefix identifies the string encoding but is not part of the CID itself -- the same binary CID may be represented in different bases depending on context and needs such as string length and case-sensitivity.
88+
The multibase prefix identifies the string encoding but is not part of the CID itself; the same binary CID can appear in different bases depending on context and needs such as string length and case-sensitivity.
8689
The full string form is:
8790

8891
```text
89-
<cidv1-str> ::= <multibase-prefix><multibase-encoding(<CIDv1-multicodec><multicodec><multihash>)>
92+
<cidv1-str> ::= <multibase-prefix><multibase-encoding(<multicodec-cidv1><multicodec-content-type><multihash-content-address>)>
9093
```
9194

9295
Where
@@ -97,9 +100,9 @@ IPFS implementations SHOULD support at minimum `base58btc` (`z`), `base32` (`b`)
97100

98101
## Design Considerations
99102

100-
CIDs design takes into account many difficult tradeoffs encountered while building [IPFS](https://ipfs.tech). These are mostly coming from the multiformats project.
103+
The design of CIDs takes into account many difficult tradeoffs encountered while building [IPFS](https://ipfs.tech). Most of these come from the multiformats project.
101104

102-
- 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 URIs.
105+
- Compactness: CIDs are binary to keep them as compact as possible, since they're meant to be part of longer path identifiers or URIs.
103106
- 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.
104107
- Versatility: CIDs are meant to be able to represent values of any format with any cryptographic hash.
105108
- Avoid Lock-in: CIDs prevent lock-in to old, potentially-outdated decisions.
@@ -209,7 +212,7 @@ The history of this format is documented at: https://github.com/ipfs/specs/issue
209212
> **Q. Is the use of multicodec similar to file extensions?**
210213
211214
Yes. Like a file extension, the multicodec in a CID tells consumers how to interpret the bytes.
212-
And just like file extensions, most users will never change it, but it is technically possible to swap the codec to change how the same bytes behind a CID are parsed.
215+
And just like file extensions, most users will never change it, but you can swap the codec to change how the same bytes are parsed.
213216

214217
> **Q. What formats (multicodec codes) does CID support?**
215218
@@ -220,9 +223,9 @@ In practice, IPFS primarily uses [`dag-pb`](https://web.archive.org/web/20260305
220223
221224
CIDs are a well established standard.
222225
IPFS uses CIDs for content-addressing and IPNS.
223-
Making changes to such key protocol requires a careful review which should include feedback from implementers and stakeholders across ecosystem.
226+
Changing such a core protocol requires careful review, including feedback from implementers and stakeholders across the ecosystem.
224227

225-
Due to this, changes to CID specification MUST be submitted as an improvement proposal to [ipfs/specs](https://github.com/ipfs/specs/tree/main/IPIP) repository (PR with [IPIP document](https://github.com/ipfs/specs/blob/main/IPIP/0000-template.md)), and follow the IPIP process described there.
228+
For this reason, changes to the CID specification MUST be submitted as an improvement proposal to [ipfs/specs](https://github.com/ipfs/specs/tree/main/IPIP) repository (PR with [IPIP document](https://github.com/ipfs/specs/blob/main/ipip-template.md)), and follow the IPIP process described there.
226229

227230
## Historical Design Decisions
228231

0 commit comments

Comments
 (0)