isCID checks version, codec and multihash properties are present and validates them. This proves that the passed object is an object that looks like { version, codec, multihash } and each property is valid, but doesn't actually prove that the passed object is an instance of CID.
So you could get back a true from isCID but there's a possibility that toBaseEncodedString (and the other instance methods) don't exist!
It's still possible to "fake" a CID instance, but it's much harder to do it by accident and we might even get a performance win if we make version, codec, and multihash readonly, because we can safely assume they are valid if we can determine the passed object is an instance of CID.
isCID
checksversion
,codec
andmultihash
properties are present and validates them. This proves that the passed object is an object that looks like{ version, codec, multihash }
and each property is valid, but doesn't actually prove that the passed object is an instance ofCID
.So you could get back a
true
fromisCID
but there's a possibility thattoBaseEncodedString
(and the other instance methods) don't exist!I know it's not the perfect solution, but would using https://github.com/moxystudio/js-class-is be better?
It's still possible to "fake" a CID instance, but it's much harder to do it by accident and we might even get a performance win if we make
version
,codec
, andmultihash
readonly, because we can safely assume they are valid if we can determine the passed object is an instance of CID.