Java SDK
Installation
Maven
<dependency>
<groupId>id.crowdproof</groupId>
<artifactId>crowdproof-java</artifactId>
<version>1.0.0</version>
</dependency>
Gradle
implementation 'id.crowdproof:crowdproof-java:1.0.0'
Requires Java 17+.
Initialization
import id.crowdproof.CrowdProofClient;
CrowdProofClient client = CrowdProofClient.builder()
.apiKey("cp_live_abc123...")
.build();
Reputation Scores
// Single score
Score score = client.getScore("0x1234...", "DEFI_LENDING");
System.out.printf("Score: %.2f, Tier: %s%n", score.getScore(), score.getTier());
// All categories
AllScoresResponse all = client.getAllScores("0x1234...");
for (Score s : all.getScores()) {
System.out.printf("%s: %.2f%n", s.getCategory(), s.getScore());
}
// Batch query
BatchResponse batch = client.batchQuery(
List.of("0x1234...", "0x5678..."),
"DEFI_LENDING"
);
ZK Proofs
// Generate
Proof proof = client.generateProof(ProofRequest.builder()
.subject("0x1234...")
.proofType("ScoreAboveThreshold")
.category("DEFI_LENDING")
.threshold(700)
.build());
// Verify
VerifyResult result = client.verifyProof(proof.getProof());
System.out.println("Valid: " + result.isValid());
Identity (DID)
// Register
DID did = client.registerDID("0x1234...", 1);
// Resolve
DID resolved = client.getDID("did:ethr:0x1234...");
Error Handling
try {
Score score = client.getScore("invalid", "DEFI_LENDING");
} catch (CrowdProofException e) {
System.out.printf("Error %d: %s%n", e.getStatus(), e.getMessage());
if (e.getStatus() == 429) {
Thread.sleep(e.getRetryAfter() * 1000L);
}
}