CIDv1 base32 encoding

135 views Asked by At

Can anyone help me understand how string version is calculated for CIDv1?

Example: bafykbzacea6h5nvlblvak5jhj7m7ku5sp7u2roo3lbembab3a6tnvmuzgcqas

Is this right hex representation according to CID explorer 0170B220203C7EB6AB0AEA0575274FD9F553B27FE9A8B9DB5848C0803B07A6DAB29930A009

Using this tool, values doesn't match.

1

There are 1 answers

0
lidel On

The hex displayed by the CID explorer shows the HEX of the hash DIGEST part, not the entire CID. This enables you to extract raw blake2b-256 from the CID.

CIDv1 have a prefix which for your CID is:

  • multibase-indicator: b (base23) (which informs how to decode binary bytes that follow)
  • cid version: 1
  • multicodec-content-type: dag-pb
  • multihash, which itself has three fields
    • code of the hash function used: blake2b-256
    • length of digest: 32
    • DIGEST

Relevant docs:

To inspect CID details like prefix (things before hash digest) with ipfs cid format (from Kubo):

$ ipfs cid format -f "(%b)-(%v)-(%c)-(%h)-(%L)-DIGEST" bafykbzacea6h5nvlblvak5jhj7m7ku5sp7u2roo3lbembab3a6tnvmuzgcqas
(base32)-(cidv1)-(dag-pb)-(blake2b-256)-(32)-DIGEST

See ipfs cid format --help.