-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: vote verification adjustments for KERI.
- Loading branch information
Mateusz Czeladka
committed
Sep 9, 2024
1 parent
cff6711
commit 6435671
Showing
14 changed files
with
328 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...cation-app/src/main/java/org/cardano/foundation/voting/client/KeriVerificationClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package org.cardano.foundation.voting.client; | ||
|
||
import io.vavr.control.Either; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import lombok.val; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.client.HttpClientErrorException; | ||
import org.springframework.web.client.RestTemplate; | ||
import org.zalando.problem.Problem; | ||
import org.zalando.problem.spring.common.HttpStatusAdapter; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.springframework.http.HttpMethod.POST; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
@Slf4j | ||
public class KeriVerificationClient { | ||
|
||
private final RestTemplate restTemplate; | ||
|
||
@Value("${keri.ballot.verifier.base.url}") | ||
private String keriVerifierBaseUrl; | ||
|
||
public Either<Problem, Boolean> verifySignature(String aid, | ||
String signature, | ||
String payload) { | ||
val url = String.format("%s/verify", keriVerifierBaseUrl); | ||
|
||
val headers = new HttpHeaders(); | ||
headers.add("Content-Type", "application/json"); | ||
|
||
val requestBody = new HashMap<String, String>(); | ||
requestBody.put("pre", aid); | ||
requestBody.put("signature", signature); | ||
requestBody.put("payload", payload); | ||
|
||
val entity = new HttpEntity<Map<String, String>>(requestBody, headers); | ||
|
||
try { | ||
val response = restTemplate.exchange(url, POST, entity, String.class); | ||
|
||
if (response.getStatusCode().is2xxSuccessful()) { | ||
return Either.right(true); | ||
} | ||
|
||
return Either.left(Problem.builder() | ||
.withTitle("KERI_VERIFICATION_FAILED") | ||
.withDetail("The Keri-specific condition was not met.") | ||
.withStatus(new HttpStatusAdapter(response.getStatusCode())) | ||
.build()); | ||
} catch (HttpClientErrorException e) { | ||
log.error("Unable to verify signature, reason: {}", e.getMessage()); | ||
|
||
return Either.left(Problem.builder() | ||
.withTitle("KERI_VERIFICATION_ERROR") | ||
.withDetail("Unable to verify signature, reason: " + e.getMessage()) | ||
.withStatus(new HttpStatusAdapter(e.getStatusCode())) | ||
.build()); | ||
} | ||
} | ||
|
||
} |
6 changes: 3 additions & 3 deletions
6
...undation/voting/config/CardanoConfig.java → ...undation/voting/config/NetworkConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 0 additions & 19 deletions
19
...-verification-app/src/main/java/org/cardano/foundation/voting/domain/CoseWrappedVote.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...oting-verification-app/src/main/java/org/cardano/foundation/voting/domain/WalletType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.cardano.foundation.voting.domain; | ||
|
||
public enum WalletType { | ||
|
||
KERI, CARDANO | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
...ting-verification-app/src/main/java/org/cardano/foundation/voting/domain/WrappedVote.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.cardano.foundation.voting.domain; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
import java.util.Optional; | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
public class WrappedVote { | ||
|
||
private String walletId; | ||
|
||
private WalletType walletType; | ||
|
||
@Builder.Default | ||
private Optional<String> payload = Optional.empty(); | ||
|
||
private String signature; | ||
|
||
@Builder.Default | ||
private Optional<String> publicKey = Optional.empty(); | ||
|
||
public static WrappedVote createCardanoVote(String walletId, | ||
String signature, | ||
Optional<String> publicKey) { | ||
return WrappedVote.builder() | ||
.walletId(walletId) | ||
.walletType(WalletType.CARDANO) | ||
.signature(signature) | ||
.payload(Optional.empty()) | ||
.publicKey(publicKey) | ||
.build(); | ||
} | ||
|
||
public static WrappedVote createKERIVote(String walletId, | ||
String signature, | ||
String payload) { | ||
return WrappedVote.builder() | ||
.walletId(walletId) | ||
.walletType(WalletType.KERI) | ||
.signature(signature) | ||
.payload(Optional.of(payload)) | ||
.publicKey(Optional.empty()) | ||
.build(); | ||
} | ||
|
||
} |
Oops, something went wrong.