Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

Improve isCID? #53

Closed
alanshaw opened this issue Aug 23, 2018 · 1 comment · Fixed by #58
Closed

Improve isCID? #53

alanshaw opened this issue Aug 23, 2018 · 1 comment · Fixed by #58

Comments

@alanshaw
Copy link
Member

alanshaw commented Aug 23, 2018

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!

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, and multihash readonly, because we can safely assume they are valid if we can determine the passed object is an instance of CID.

@mikeal
Copy link
Contributor

mikeal commented Sep 13, 2018

I actually assumed this was already the case because I'd seen is-class used in other related modules. Big +1.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants