Skip to content

feat(cmd): add 'ipfs cid inspect' command#11241

Merged
lidel merged 8 commits intoipfs:masterfrom
jolo18:feat/cid-inspect
Mar 20, 2026
Merged

feat(cmd): add 'ipfs cid inspect' command#11241
lidel merged 8 commits intoipfs:masterfrom
jolo18:feat/cid-inspect

Conversation

@jolo18
Copy link
Contributor

@jolo18 jolo18 commented Mar 18, 2026

Summary

  • Adds new ipfs cid inspect <cid> subcommand to display detailed CID information
  • Shows CID version, multibase encoding, multicodec, multihash (algorithm, length, digest)
  • Provides equivalent CIDv0/CIDv1 representations when applicable
  • Supports --enc=json for machine-readable output
  • Works offline (no daemon required)

Example Output

$ ipfs cid inspect bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi
CID:        bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi
Version:    1
Multibase:  base32 (b)
Multicodec: dag-pb (0x70)
Multihash:  sha2-256 (0x12)
  Length:   32 bytes
  Digest:   c3c4733ec8affd06cf9e9ff50ffc6bcd2ec85a6170004bb709669c31de94391a
CIDv0:      QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR
CIDv1:      bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi

Test Plan

  • make build succeeds
  • go test ./core/commands/... -run TestCid passes
  • go test ./test/cli/... -run TestCommandDocsWidth passes
  • Manual testing with CIDv0, CIDv1, and invalid CIDs

References

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
@jolo18 jolo18 requested a review from a team as a code owner March 18, 2026 13:17
jolo18 and others added 4 commits March 18, 2026 18:49
…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.
@lidel lidel self-assigned this Mar 19, 2026
lidel added 3 commits March 20, 2026 01:24
- 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 lidel force-pushed the feat/cid-inspect branch from f666a50 to 50836bc Compare March 20, 2026 01:07
Copy link
Member

@lidel lidel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-key CIDv1 uses base36 -- per peer-ids spec.
  • 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 -- ErrorMsg kept in struct for HTTP RPC API consumers, text encoder returns an error for CLI exit code 1.
  • Digest as bare lowercase hex -- matching sha256sum convention.
  • Unknown codec/hash -- shows unknown (0x...) instead of confusing Code(N) format.
  • Multibase prefix field -- renamed from code, type changed from rune to string to show useful value instead of number as in multibase spec.
  • Stdin support -- .EnableStdin() added, matching cid format and cid 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.

@lidel lidel mentioned this pull request Mar 20, 2026
22 tasks
@lidel lidel merged commit ae98932 into ipfs:master Mar 20, 2026
21 checks passed
@jolo18
Copy link
Contributor Author

jolo18 commented Mar 20, 2026

@lidel Apologies for making you do the extra work 😬. Anyways thank you for looking into this quickly I appreciate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CID inspect on command line

2 participants