Search code examples
hashdecodeipfs

What is multicodec and how it is related to multihash?


I don't have any background with this subject.

To try to understand them better, I read:

enter image description here

enter image description here


From what I understand, the multihash is the algorithm used to hash (one way) the value. so it means, we can't go back (we can't decode the hash to the value).

Questions

  1. I don't understand, in simple words, what is multicodec and if it's related to decoding the hash to a value (which makes no sense).
  2. what is the motivation to multicodec prefix?

Solution

    1. The multicodec is related to decoding the value the hash points to, if that makes it easier to understand. Don't worry, no magic hash decoding is happening ;). Remember we're making CIDs, and we can use CIDs to lookup content. However then we have the question of "how do we decode this data we just retrieved?", the multicodec solves that problem for us. Reading From Data to Data Structures might help clear up some confusion.

    2. The multicodec prefix allows IPFS to evolve to support new and different encodings for the data that's actually put into IPFS. This refers to IPLD, and you can actually find the answer you're looking for under Links (with information about the codecs under Codecs):

    For links we use a CID. A CID is an extension of multihash, in fact a multihash is part of a CID. We simply add a codec to a multihash that tells us what format the data is in (JSON, CBOR, Bitcoin, Ethereum, etc). This way, we can actually link between data in different formats and any link to data anyone ever gives us can be decoded so that it can become more than just a series of bytes.

    CID is a standard that anyone can implement, even people that have no other interest in IPLD beyond the need for hash links to different data types can use it.