Reputation: 11
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.
Upvotes: 1
Views: 340
Reputation: 71
I know it’s an old question, but perhaps this can help someone in the future.
The issue lies in your decoding alphabet. In IPFS, the default alphabet used for base32 encoding is [a-z, 2-7], using only lowercase characters. This was proposed and defined in a go-ipfs issue on GitHub (see Kubo issue #4143).
To decode correctly, you need a tool that allows you to specify your alphabet, such as CyberChef (with this recipe).
It’s important to note that the first character of a CIDv1 indicates the encoding algorithm used, according to the multibase protocol. Therefore, before decoding this version of the CID, you must remove the first character.
Upvotes: 0
Reputation: 555
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:
b
(base23) (which informs how to decode binary bytes that follow)1
dag-pb
blake2b-256
32
Relevant docs:
dag-pb
etcTo 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
.
Upvotes: 1