/** * Society Protocol — Reputation System v1.0 * * Decentralized reputation tracking for agents based on: * - Task completion history * - Quality scores from reviews * - On-time delivery rates * - Community feedback * * Uses exponential decay to weight recent performance higher. */ import { EventEmitter } from 'events'; import { type Storage } from './storage.js'; export interface ReputationMetrics { tasks_completed: number; tasks_failed: number; tasks_cancelled: number; avg_quality_score: number; avg_latency_ms: number; response_rate: number; on_time_delivery: number; total_tokens_used: number; total_cost_usd: number; } export interface SpecialtyScore { specialty: string; score: number; tasks_completed: number; last_used: number; } export interface ReputationScore { did: string; display_name?: string; overall: number; metrics: ReputationMetrics; specialties: SpecialtyScore[]; trust_tier: 'unverified' | 'bronze' | 'silver' | 'gold' | 'platinum'; first_seen: number; last_updated: number; version: number; } export interface ReputationConfig { decayFactor: number; minTasksForReliability: number; weights: { quality: number; reliability: number; responsiveness: number; expertise: number; }; } export interface TaskOutcome { did: string; chain_id: string; step_id: string; status: 'completed' | 'failed' | 'cancelled' | 'partial'; quality_score?: number; latency_ms: number; lease_ms: number; accepted: boolean; tokens_used?: number; cost_usd?: number; specialties_used: string[]; timestamp: number; } /** * Lightweight reputation observation for gossip propagation. * One node's observation of another's performance — the unit of reputation gossip. */ export interface ReputationObservation { subject: string; observer: string; timestamp: number; quality?: number; delivered: boolean; onTime: boolean; specialties?: string[]; } export declare class ReputationEngine extends EventEmitter { private storage; private config; private cache; private dirtyDids; private identityVerified; constructor(storage: Storage, config?: Partial); /** * Record the outcome of a task assignment */ recordTaskOutcome(outcome: TaskOutcome): Promise; /** * Get current reputation score for a DID */ getReputation(did: string): Promise; /** * Get reputation for multiple DIDs (batch) */ getReputations(dids: string[]): Promise>; /** * Rank agents by suitability for a specific task */ rankAgentsForTask(dids: string[], requirements: { specialties?: string[]; minReputation?: number; kind?: string; }): Promise>; /** * Update reputation based on peer review */ recordPeerReview(reviewerDid: string, subjectDid: string, chainId: string, stepId: string, rating: number, // 0.0 - 1.0 feedback?: string): Promise; /** * Get reputation trend over time */ getReputationHistory(did: string, days?: number): Promise>; private calculateReputation; private calculateMetrics; private calculateSpecialtyScores; private calculateOverallScore; private calculateTaskScore; private calculateTrustTier; private applyTemporalDecay; private getDefaultReputation; private recalculateReputation; /** * Reputation observation for network propagation. * Lightweight struct carrying a single peer's observation of another. */ static serializeObservation(obs: ReputationObservation): Uint8Array; static deserializeObservation(data: Uint8Array): ReputationObservation; /** * Create a reputation observation from a task outcome. * This is the unit of gossip — a single observation, not a full score. */ createObservation(outcome: TaskOutcome, observerDid: string): ReputationObservation; /** * Ingest a reputation observation received from the network. * Validates the observation and integrates it into the local reputation store. * * Anti-gaming: observations are weighted by the observer's own reputation * to reduce the impact of Sybil nodes (low-rep observers have diminished influence). */ ingestObservation(obs: ReputationObservation): Promise; /** * Handle an incoming reputation gossip message from the network. */ handleSyncMessage(data: Uint8Array, from: string): void; /** * Record that a DID has verified identity via ZKP (Schnorr PoK). * Verified identities get a minimum trust tier of 'bronze'. */ recordIdentityVerification(did: string): void; /** * Check if a DID has a verified identity. */ hasVerifiedIdentity(did: string): boolean; private startPeriodicSync; private groupByDay; private calculateScoreFromOutcomes; } export declare function formatReputationTier(tier: ReputationScore['trust_tier']): string; export declare function isTrusted(rep: ReputationScore, minTier?: ReputationScore['trust_tier']): boolean; //# sourceMappingURL=reputation.d.ts.map