ipfs-shipyard / java-ipfs-http-client

A Java implementation of the HTTP IPFS API
MIT License
538 stars 243 forks source link

key.list() or .gen() always throw io.ipfs.cid.Cid$CidEncodingException: Invalid cid bytes #182

Closed crick77 closed 3 years ago

crick77 commented 3 years ago

Hi all,

I'm trying to use the library to manage some files into ipfs. I've ipfs desktop installed and running. I can add files from java without any problem but i need to crate new key for ipns names because some files can be updated and I need a unique esternal name to retrieve the last and most updated version. When I try to call any ipfs.key.* method I always get the exception in title. What I'm doing wrong? (could not find any solution online) Here is my code:

` IPFS ipfs = new IPFS("/ip4/127.0.0.1/tcp/5001"); NamedStreamable.ByteArrayWrapper file = new NamedStreamable.ByteArrayWrapper(userId, text.getBytes()); MerkleNode addResult = ipfs.add(file).get(0);

        List<KeyInfo> keys = ipfs.key.list(); // exception here
        System.out.println("Keys: "+keys);

        Optional<String> keyType = Optional.of("rsa");
        Optional<String> keySize = Optional.of("2048");
        KeyInfo key = ipfs.key.gen(userId, keyType, keySize); // exception here (if I comment list() call.

        Map result = ipfs.name.publish(addResult.hash, Optional.of(key.name));
        System.out.println("IPNS: "+result);
        return result.get("Name");

` Thank you for you're help.

crick77 commented 3 years ago

Just for information, trying to generate key on same name raises another exception of key existence, so the key generation seems to work but the conversion of the code attached to exception after "Invalid cid bytes" fails.

crick77 commented 3 years ago

Updating java-cid library to last pull-request seems to solve problem.