feat(cmd): add 'ipfs cid inspect' command#11241
Merged
lidel merged 8 commits intoipfs:masterfrom Mar 20, 2026
Merged
Conversation
Adds a new subcommand to inspect and display detailed CID information
including version, multibase encoding, multicodec, and multihash
components. Also shows equivalent CIDv0/CIDv1 representations.
Example output:
CID: bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi
Version: 1
Multibase: base32 (b)
Multicodec: dag-pb (0x70)
Multihash: sha2-256 (0x12)
Length: 32 bytes
Digest: c3c4733ec8affd06cf9e9ff50ffc6bcd2ec85a6170004bb709669c31de94391a
CIDv0: QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR
CIDv1: bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi
Supports --enc=json for machine-readable output.
Fixes ipfs#11205
…o tests This commit refines the CidInspectRes struct for better readability and consistency. Additionally, it includes the '/cid/inspect' route in the command tests to ensure comprehensive coverage of the new CID inspection functionality.
…mmand Added a section highlighting the new `ipfs cid inspect <cid>` command, detailing its functionality to display comprehensive CID information, including version, encoding, and hash details. The command supports machine-readable output and operates offline.
- multibase: always shown (implicit for CIDv0), prefix as string - multicodec/multihash: annotated (implicit) for CIDv0 - digest: uppercase hex with 0x prefix - cidV0: empty in JSON when not possible, text encoder explains why - cidV1: base36 for libp2p-key codec, base32 otherwise - errors: ErrorMsg kept for HTTP RPC API, text encoder returns non-zero exit - PeerID fallback: helpful hint with equivalent CID on invalid input - unknown codec/hash: graceful "unknown" label - stdin support via .EnableStdin() - inspect listed first in subcommands, cid format points to inspect - cli tests for all cases including JSON, PeerID, unknown codec
- digest: bare lowercase hex (no 0x prefix), matching sha256sum
lidel
approved these changes
Mar 20, 2026
Member
There was a problem hiding this comment.
Thanks for putting this together, @jolo18!
I pushed some refinements:
- Multibase always shown -- CIDv0 displays
base58btc (implicit). Multicodec and multihash also annotated(implicit)for CIDv0, per the CID spec. - PeerID detection -- this is quality of life thing we have on https://cid.ipfs.tech: passing a PeerID string instead of a CID returns an error with the equivalent CID to inspect.
- Kinda related:
libp2p-keyCIDv1 uses base36 -- per peer-ids spec.
- Kinda related:
- CIDv0 text explanation -- when CIDv0 is not possible, text output explains why (e.g. wrong codec or hash). JSON omits the field instead.
- Non-zero exit on error --
ErrorMsgkept in struct for HTTP RPC API consumers, text encoder returns an error for CLI exit code 1. - Digest as bare lowercase hex -- matching
sha256sumconvention. - Unknown codec/hash -- shows
unknown (0x...)instead of confusingCode(N)format. - Multibase
prefixfield -- renamed fromcode, type changed fromrunetostringto show useful value instead of number as in multibase spec. - Stdin support --
.EnableStdin()added, matchingcid formatandcid base32. - CLI tests -- CIDv0, CIDv1 (base32/base36/raw), identity multihash, unknown codec, PeerID input, JSON output.
Test coverage looks good, let's wait for CI and if green I will merge so we can include it in v0.41.
Contributor
Author
|
@lidel Apologies for making you do the extra work 😬. Anyways thank you for looking into this quickly I appreciate it. |
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.
Summary
ipfs cid inspect <cid>subcommand to display detailed CID information--enc=jsonfor machine-readable outputExample Output
Test Plan
make buildsucceedsgo test ./core/commands/... -run TestCidpassesgo test ./test/cli/... -run TestCommandDocsWidthpassesReferences