TypeScript SDK
Installation
npm install @crowdproof/sdk
# or
yarn add @crowdproof/sdk
# or
pnpm add @crowdproof/sdk
Initialization
import { CrowdProof } from '@crowdproof/sdk';
const client = new CrowdProof({
apiKey: 'cp_live_abc123...',
baseUrl: 'https://crowdproof-api.azurewebsites.net', // optional
});
Reputation Scores
// Single score
const score = await client.getScore('0x1234...', 'DEFI_LENDING');
console.log(score.score, score.tier, score.confidence);
// All categories
const all = await client.getAllScores('0x1234...');
all.scores.forEach(s => console.log(s.category, s.score));
// Batch query
const batch = await client.batchQuery(
['0x1234...', '0x5678...', '0x9abc...'],
'DEFI_LENDING'
);
ZK Proofs
// Generate proof that score ≥ 700
const proof = await client.generateProof({
subject: '0x1234...',
proofType: 'ScoreAboveThreshold',
category: 'DEFI_LENDING',
threshold: 700,
});
// Verify proof
const { valid } = await client.verifyProof(proof.proof);
Identity (DID)
// Register DID
const did = await client.registerDID('0x1234...', 1);
// Resolve DID
const resolved = await client.getDID('did:ethr:0x1234...');
// Issue credential
const credential = await client.issueCredential('did:ethr:0x1234...', {
credentialType: 'KYCVerification',
subject: '{"level": "enhanced"}',
});
Webhooks
// Register webhook
const webhook = await client.createWebhook({
url: 'https://your-app.com/webhook',
walletAddress: '0x1234...', // optional filter
});
// List webhooks
const list = await client.listWebhooks();
// Delete webhook
await client.deleteWebhook(webhook.id);
Error Handling
import { CrowdProofError } from '@crowdproof/sdk';
try {
await client.getScore('invalid-address', 'DEFI_LENDING');
} catch (err) {
if (err instanceof CrowdProofError) {
console.error(`${err.status}: ${err.message}`);
// err.status — HTTP status code
// err.message — Error description
// err.details — Additional context
}
}
TypeScript Types
interface Score {
category: string;
score: number;
confidence: number;
tier: 'Excellent' | 'Good' | 'Fair' | 'Poor' | 'Very Poor';
calculatedAt: string;
modelVersion: string;
}
interface Proof {
proof: string;
proofType: string;
}
interface DID {
id: string;
did: string;
walletAddress: string;
didDocument: string;
chainId: number;
isActive: boolean;
}