multiformats / js-cid

CID implementation in JavaScript
MIT License
97 stars 39 forks source link

A way to compare CIDs for equality #24

Closed mitar closed 7 years ago

mitar commented 7 years ago

Is there a way to compare two CIDs for equality of the hash itself? I am guessing that because I have a different versions of it, base encoding is different? Or is this not possible?

mitar commented 7 years ago

So I have this object:

./ipfs object get QmYe6tCaRi5M2b64uTU4ikugBQvAq2jBrwBT1rqppvNFpi
{"Links":[{"Name":"payload","Hash":"QmUxD5gZfKzm8UN4WaguAMAZjw2TzZ2ZUmcqm2qXPtais7","Size":819}],"Data":"{\"Luck\":0.4,\"Proof\":\"\u003cTEE signature\u003e\"}"}

And when I pass the same object through dagCBOR.util.cid, I get zdpuB1gw1yXZ2cHYruevpr6GwSKPxoyfF6nsKridoYZD8LJaf. It could be that I am doing something wrong, but it is unclear to me. Having equals function would remove any ambiguity to me.

mitar commented 7 years ago

And I cannot do toV0().toBaseEncodedString() because I get Cannot convert a non dag-pb CID to CIDv0.

mitar commented 7 years ago

Oh, I found it: https://github.com/ipld/js-cid/blob/master/src/index.js#L125

But it is not documented. And it also does not compare across versions?

daviddias commented 7 years ago

It considers it to be equal if they also share the version. Are you just trying to compare the multihash?

mitar commented 7 years ago

I think after I learned more this is not really reasonable. :-) Let me just close it.