Go SDK
Installation
go get github.com/crowdproof/crowdproof-go
Requires Go 1.21+.
Initialization
package main
import (
"context"
"fmt"
crowdproof "github.com/crowdproof/crowdproof-go"
)
func main() {
client := crowdproof.NewClient("cp_live_abc123...")
}
Reputation Scores
ctx := context.Background()
// Single score
score, err := client.GetScore(ctx, "0x1234...", "DEFI_LENDING")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Score: %.2f, Tier: %s\n", score.Score, score.Tier)
// All categories
all, err := client.GetAllScores(ctx, "0x1234...")
// Batch query
batch, err := client.BatchQuery(ctx, crowdproof.BatchRequest{
Addresses: []string{"0x1234...", "0x5678..."},
Category: "DEFI_LENDING",
})
ZK Proofs
// Generate
proof, err := client.GenerateProof(ctx, crowdproof.ProofRequest{
Subject: "0x1234...",
ProofType: "ScoreAboveThreshold",
Category: "DEFI_LENDING",
Threshold: 700,
})
// Verify
result, err := client.VerifyProof(ctx, proof.Proof)
fmt.Printf("Valid: %v\n", result.Valid)
Identity (DID)
// Register
did, err := client.RegisterDID(ctx, "0x1234...", 1)
// Resolve
resolved, err := client.GetDID(ctx, "did:ethr:0x1234...")
Error Handling
score, err := client.GetScore(ctx, "0x1234...", "DEFI_LENDING")
if err != nil {
var apiErr *crowdproof.APIError
if errors.As(err, &apiErr) {
fmt.Printf("API error %d: %s\n", apiErr.Status, apiErr.Message)
if apiErr.Status == 429 {
time.Sleep(time.Duration(apiErr.RetryAfter) * time.Second)
}
}
}
Types
type Score struct {
Category string `json:"category"`
Score float64 `json:"score"`
Confidence float64 `json:"confidence"`
Tier string `json:"tier"`
CalculatedAt time.Time `json:"calculatedAt"`
ModelVersion string `json:"modelVersion"`
}
type Proof struct {
Proof string `json:"proof"`
ProofType string `json:"proofType"`
}