Skip to content

Commit 9de63d6

Browse files
committed
Add key gen and publishing with non default keys
1 parent cf5a152 commit 9de63d6

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/main/java/io/ipfs/api/IPFS.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public enum PinType {all, direct, indirect, recursive}
1919
public final String host;
2020
public final int port;
2121
private final String version;
22+
public final Key key = new Key();
2223
public final Pin pin = new Pin();
2324
public final Repo repo = new Repo();
2425
public final IPFSObject object = new IPFSObject();
@@ -181,6 +182,14 @@ public List<MultiAddress> update(Multihash existing, Multihash modified, boolean
181182
}
182183
}
183184

185+
/* 'ipfs repo' is a plumbing command used to manipulate the repo.
186+
*/
187+
public class Key {
188+
public Object gen(String name, Optional<String> type, Optional<String> size) throws IOException {
189+
return retrieveAndParse("key/gen?arg=" + name + type.map(t -> "&type=" + t).orElse("") + size.map(s -> "&size=" + s).orElse(""));
190+
}
191+
}
192+
184193
/* 'ipfs repo' is a plumbing command used to manipulate the repo.
185194
*/
186195
public class Repo {
@@ -299,11 +308,11 @@ public MerkleNode patch(Multihash base, String command, Optional<byte[]> data, O
299308

300309
public class Name {
301310
public Map publish(Multihash hash) throws IOException {
302-
return publish(Optional.empty(), hash);
311+
return publish(hash, Optional.empty());
303312
}
304313

305-
public Map publish(Optional<String> id, Multihash hash) throws IOException {
306-
return retrieveMap("name/publish?arg=" + (id.isPresent() ? id+"&arg=" : "") + "/ipfs/"+hash);
314+
public Map publish(Multihash hash, Optional<String> id) throws IOException {
315+
return retrieveMap("name/publish?arg=/ipfs/" + hash + id.map(name -> "&key=" + name).orElse(""));
307316
}
308317

309318
public String resolve(Multihash hash) throws IOException {

src/test/java/io/ipfs/api/APITest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,9 @@ public void nameTest() {
578578
try {
579579
MerkleNode pointer = new MerkleNode("QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB");
580580
Map pub = ipfs.name.publish(pointer.hash);
581+
String name = "key" + System.nanoTime();
582+
Object gen = ipfs.key.gen(name, Optional.of("rsa"), Optional.of("2048"));
583+
Map mykey = ipfs.name.publish(pointer.hash, Optional.of(name));
581584
String resolved = ipfs.name.resolve(Multihash.fromBase58((String) pub.get("Name")));
582585
} catch (IOException e) {
583586
throw new RuntimeException(e);

0 commit comments

Comments
 (0)