Conversation
🚀 Build Preview on IPFS ready
|
vmx
reviewed
Mar 12, 2026
Co-authored-by: Volker Mische <volker.mische@gmail.com>
rvagg
reviewed
Mar 13, 2026
Comment on lines
+149
to
+153
| * 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. | ||
| * Otherwise, let `N` be the first varint in `cid`. This is the CID's version. |
Member
There was a problem hiding this comment.
Using byte length anywhere in the binary decoding path isn't ideal and not how we do it in practice so I wouldn't want encourage this.
What we actually do, for both binary paths, is read the first bytes as a varint, which tells us what to do next: if the value is 0x12 then that's sha2-256 and this is a CIDv0 cause we've discovered the multihash and we proceed accordingly, if the value is 0x01 then it's a CIDv1 and we proceed accordingly.
One minor edge is that the JS decoder will also read the value 0x00 and decode the rest as a CIDv0 but that's probably not a good idea.
rvagg
reviewed
Mar 13, 2026
| * 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 == 0x02` (CIDv2), or `N == 0x03` (CIDv3), the CID version is reserved. |
Member
There was a problem hiding this comment.
does this need to be said? if version isn't 0x01 then it's malformed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.