diff --git a/RFC/0001-text-peerid-cid.md b/RFC/0001-text-peerid-cid.md index 40d6906..0bcaef6 100644 --- a/RFC/0001-text-peerid-cid.md +++ b/RFC/0001-text-peerid-cid.md @@ -41,6 +41,12 @@ from Multihash to CIDv1 in Base32 and to support encoding/decoding text Peer Ids [rfc4648]: https://tools.ietf.org/html/rfc4648 +### Upgrade path + +1. Release support for reading Peer Id represented with CIDv1 +2. Wait three months or until the next release (whichever comes first) +3. Switch the default Peer Id output format to CIDv1 in Base32 + ### Backward compatibility The old text representation (Multihash encoded as [`base58btc`][base58btc]) diff --git a/peer-ids/peer-ids.md b/peer-ids/peer-ids.md index e14a601..13d4e96 100644 --- a/peer-ids/peer-ids.md +++ b/peer-ids/peer-ids.md @@ -131,7 +131,7 @@ behavior. ### String representation -Peer Ids are [multihashes][multihash] represented with [CIDs](https://github.com/ipld/cid) when encoded into strings. +Peer Ids are [multihashes][multihash] canonically represented with [CIDs](https://github.com/ipld/cid) when encoded into strings. CID is a multihash with a prefix that specifies things like base encoding, cid version and the type of data behind it: @@ -139,7 +139,7 @@ CID is a multihash with a prefix that specifies things like base encoding, cid v ::= ``` -Encoding and decoding of string representation must follow [CID spec][cid-decoding]. +Encoding and decoding of string representation must follow [CID spec][cid-decoding]. #### libp2p-key CID @@ -153,6 +153,14 @@ with `base32` [multibase][multibase] ([RFC4648](https://tools.ietf.org/html/rfc4 - `libp2p-key` multicodec is mandatory when serializing to text (ensures Peer Id is self-describing) - `base32` is the default multibase encoding: projects are free to use a different one if it is more suited to their needs +##### Decoding string representation + +To decode a CID, follow the following algorithm: + +- If it is 46 characters long and starts with `Qm...`, it's a CIDv0. Decode it as base58btc multihash. +- Otherwise, decode it according to the multibase and [CID spec][cid-decoding]. + + Examples: - SHA256 Peer Id encoded as canonical [CIDv1][cid-versions]: