Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support CIDv1 #7

Open
lidel opened this issue Jan 21, 2022 · 1 comment
Open

Support CIDv1 #7

lidel opened this issue Jan 21, 2022 · 1 comment

Comments

@lidel
Copy link

lidel commented Jan 21, 2022

Summary

Heads up:

  • IPFS ecosystem will switch to CIDv1 as the default in the near future (https://github.com/ipfs/ipfs/issues/337)
  • The way CID is extracted from ipfs:// addresses in this project will break when it attempts to read a CIDv1
  • The fix is to use CID library instead of Multihash when parsing ipfs:// addresses

Problem

This code assumes every CID is CIDv0 (looks the same as Multihash, so it is parsed as Multihash here):

                    public InputStream getInputStream() throws IOException {
                        Multihash filePointer = Multihash.fromBase58(location.toString().replaceFirst("ipfs://", ""));

                        byte[] fileContents = new byte[0];
                        try {
                            fileContents = ipfs.cat(filePointer);
                        } catch (IOException e) {
                            logger.error("Failed to retrieve object", e);
                            return null;
                        }

Try parsing ipfs://bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi – it is not Base58 (it is CIDv1 in Base32), so will throw an exception.

Solution

Always assume localtion is a CID and parse it using a library that understands CIDv1.

You can use CID implementation from java-cid, you can also peek at how CIDs are used in Peergos

See:

Happy to answer any questions / guide

cc @rlebre for awareness

@rlebre
Copy link
Contributor

rlebre commented Jan 25, 2022

Thank you very much for the heads up @lidel. I'll look into this soon and definitely reach you if a technical issue arises. Thanks!

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

No branches or pull requests

2 participants