Closed aratz-lasa closed 4 years ago
We may need to improve the documentation a bit here...
The TL;DR is, CIDs in DagCBOR are encoded as \0-<binary-cid-minus-the-multibase>
(where \0
is NULL or the 0 byte). To decode, strip the leading 0, then decode as a binary CID.
Using the "identity multibase" prefix in DagCBOR is mostly an historical mistake. I call it a mistake because we prepend the "identity multibase" to CIDv0 CIDs as well, while CIDv0 doesn't use multibase.
Thank you @Stebalien for the explanation.
Just to confirm. Then, DagCBOR CID encoding/decoding should be done "manually" (adding/removing the 0 byte, and later using the CID decoder), instead of directly using the CID library right?
If that is the case, it means CID libraries, such as py-cid (which actually cannot decode "identity multibase CIDv1) are not expected to be able to decode "identity multibase" encoded CIDv1?
Just to confirm. Then, DagCBOR CID encoding/decoding should be done "manually" (adding/removing the 0 byte, and later using the CID decoder), instead of directly using the CID library right?
Yes. To encode, prepend the "0" byte to a binary CID. To decode, remove it.
If that is the case, it means CID libraries, such as py-cid (which actually cannot decode "identity multibase CIDv1) are not expected to be able to decode "identity multibase" encoded CIDv1?
You should call from_bytes
and cid.buffer()
.
You should call
from_bytes
andcid.buffer()
.
Okay, now it is everything clear. I will need to do a PR to change it, because right now it does not decode it. Thanks for your help! (and sorry for the late response)
Given a binary CID
cid
, whereN
is the first varint incid
. IfN == 0
, could not be a CIDv1 encoded asidentity
multibase? I ask it because, in dag-cbor is specified that CIDv1 should be encoded asidentity
multibase. However, following the Decoding Algorithm, it would raise an error instead of decoding it.So, should the decoding algorithm be modified, or CID does not natively support to encode/decode CIDv1 using the raw-binary identity Multibase?