Skip to content

Commit

Permalink
Support resolving rsa ipns mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
ianopolous committed Mar 28, 2024
1 parent 79b9f2a commit d99451b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/main/java/org/peergos/EmbeddedIpfs.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ public CompletableFuture<byte[]> resolveValue(PubKey pub, int minResults) {
return CompletableFuture.completedFuture(records.get(records.size() - 1).value);
}

public List<IpnsRecord> resolveRecords(PubKey pub, int minResults) {
Multihash publisher = Multihash.deserialize(PeerId.fromPubKey(pub).getBytes());
public List<IpnsRecord> resolveRecords(Multihash publisher, int minResults) {
List<IpnsRecord> candidates = dht.resolveValue(publisher, minResults, node);
return candidates.stream().sorted().collect(Collectors.toList());
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/peergos/IpnsPublisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public static List<Integer> resolveAndRepublish(List<PublishResult> publishers,
AtomicInteger successes = new AtomicInteger(0);
List<CompletableFuture<Integer>> futs = publishers.stream().map(pub -> CompletableFuture.supplyAsync(() -> {
try {
List<IpnsRecord> records = resolver.resolveRecords(pub.priv.publicKey(), 30);
List<IpnsRecord> records = resolver.resolveRecords(pub.pub, 30);
int success = records.isEmpty() ? successes.get() : successes.incrementAndGet();
int total = done.incrementAndGet();
if (total % 10 == 0)
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/org/peergos/net/APIHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,7 @@ public void handleCallToAPI(HttpExchange httpExchange) {
throw new APIException("argument \"signer\" is required");
}
Multihash signer = Multihash.fromBase58(args.get(0));
if (signer.getType() != Multihash.Type.id)
throw new IllegalStateException("Can only resolve Ed25519 ipns mappings");
byte[] pubKeymaterial = Arrays.copyOfRange(signer.getHash(), 4, 36);
io.libp2p.core.crypto.PubKey pub = new Ed25519PublicKey(new org.bouncycastle.crypto.params.Ed25519PublicKeyParameters(pubKeymaterial, 0));
List<IpnsRecord> records = ipfs.resolveRecords(pub, 1)
List<IpnsRecord> records = ipfs.resolveRecords(signer, 1)
.stream()
.sorted()
.collect(Collectors.toList());
Expand Down

0 comments on commit d99451b

Please sign in to comment.