multiformats / js-multiformats

Multiformats interface (multihash, multicodec, multibase and CID)
Other
229 stars 52 forks source link

Removing version from CID constructor #3

Open vmx opened 4 years ago

vmx commented 4 years ago

I suggest that the version is removed from the constructor and that it is always v1 automatically. There could be a dedicated v0 constructor, or we just allow constructing it by multihash (which is probably most of its uses).

mikeal commented 4 years ago

I worry that the rules for detecting whether or not a binary value is a CID or a multihash (CIDv0) are problematic, which is why I cut that behavior from the re-write and require explicit version setting for CIDv0. That could be replaced with a CIDv0 constructor but it would be a little odd to have a CIDv0 constructor and also support string encoded CIDv0 in the normal constructor (which we really need to do in order to keep the interface usable).

I’m fine having to jump through extra hoops to instantiate a CIDv0 from a binary value because you really need to be doing some detection on your own for that case, but there’s lots of places where we accept string encoded CID’s and need easy backwards compatibility. We also have a more reliable detection mechanism (starts with “Q”) for strings.