From d99451b8d860a4d4929275e95f5d8012b0a35574 Mon Sep 17 00:00:00 2001 From: ian Date: Thu, 28 Mar 2024 12:23:24 +0000 Subject: [PATCH] Support resolving rsa ipns mappings --- src/main/java/org/peergos/EmbeddedIpfs.java | 3 +-- src/main/java/org/peergos/IpnsPublisher.java | 2 +- src/main/java/org/peergos/net/APIHandler.java | 6 +----- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/peergos/EmbeddedIpfs.java b/src/main/java/org/peergos/EmbeddedIpfs.java index 9cd7a72e..3d22a8f9 100644 --- a/src/main/java/org/peergos/EmbeddedIpfs.java +++ b/src/main/java/org/peergos/EmbeddedIpfs.java @@ -126,8 +126,7 @@ public CompletableFuture resolveValue(PubKey pub, int minResults) { return CompletableFuture.completedFuture(records.get(records.size() - 1).value); } - public List resolveRecords(PubKey pub, int minResults) { - Multihash publisher = Multihash.deserialize(PeerId.fromPubKey(pub).getBytes()); + public List resolveRecords(Multihash publisher, int minResults) { List candidates = dht.resolveValue(publisher, minResults, node); return candidates.stream().sorted().collect(Collectors.toList()); } diff --git a/src/main/java/org/peergos/IpnsPublisher.java b/src/main/java/org/peergos/IpnsPublisher.java index 0035428b..c1741ed2 100644 --- a/src/main/java/org/peergos/IpnsPublisher.java +++ b/src/main/java/org/peergos/IpnsPublisher.java @@ -141,7 +141,7 @@ public static List resolveAndRepublish(List publishers, AtomicInteger successes = new AtomicInteger(0); List> futs = publishers.stream().map(pub -> CompletableFuture.supplyAsync(() -> { try { - List records = resolver.resolveRecords(pub.priv.publicKey(), 30); + List records = resolver.resolveRecords(pub.pub, 30); int success = records.isEmpty() ? successes.get() : successes.incrementAndGet(); int total = done.incrementAndGet(); if (total % 10 == 0) diff --git a/src/main/java/org/peergos/net/APIHandler.java b/src/main/java/org/peergos/net/APIHandler.java index b45c5d13..a1e6af40 100755 --- a/src/main/java/org/peergos/net/APIHandler.java +++ b/src/main/java/org/peergos/net/APIHandler.java @@ -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 records = ipfs.resolveRecords(pub, 1) + List records = ipfs.resolveRecords(signer, 1) .stream() .sorted() .collect(Collectors.toList());