/** * Opacus Reputation System * EigenTrust-based reputation scoring with on-chain verification * * Features: * - 0-100 reputation scoring * - Transaction-based trust updates * - Sybil attack resistance * - Temporal decay * - On-chain verification */ import { ethers } from 'ethers'; /** * Reputation score (0-100) */ export interface ReputationScore { agentId: string; score: number; totalReviews: number; positiveReviews: number; negativeReviews: number; eigenTrust: number; trustLevel: TrustLevel; lastUpdated: number; history: ReputationEvent[]; } export type TrustLevel = 'Unverified' | 'New' | 'Trusted' | 'Highly Trusted' | 'Elite' | 'Blacklisted'; /** * Reputation event (on-chain) */ export interface ReputationEvent { txHash: string; from: string; to: string; rating: number; transactionId: string; comment?: string; timestamp: number; verified: boolean; } /** * Review submission */ export interface ReviewSubmission { agentId: string; transactionId: string; rating: { overall: number; accuracy: number; speed: number; support: number; }; comment: string; verified: boolean; } /** * EigenTrust parameters */ interface EigenTrustConfig { alpha: number; epsilon: number; maxIterations: number; decayFactor: number; } /** * Opacus Reputation System */ export declare class ReputationSystem { private contract; private signer; private config; private trustMatrix; constructor(contractAddress: string, signer: ethers.Signer, config?: Partial); /** * Submit a review (must be from verified transaction) */ submitReview(review: ReviewSubmission): Promise; /** * Get agent reputation score */ getAgentScore(agentId: string): Promise; /** * Get reviews for an agent */ getReviews(agentId: string, offset?: number, limit?: number): Promise; /** * Calculate EigenTrust score * Uses iterative power method to compute global trust */ private calculateEigenTrust; /** * Build normalized trust matrix from trust entries */ private buildTrustMatrix; /** * Calculate vector difference (L1 norm) */ private vectorDifference; /** * Normalize rating (1-5) to (0-1) */ private normalizeRating; /** * Get trust level from score */ private getTrustLevel; /** * Validate rating (1-5) */ private isValidRating; /** * Flag agent for suspicious activity */ flagAgent(agentId: string, reason: string): Promise; /** * Unflag agent (requires governance) */ unflagAgent(agentId: string): Promise; /** * Get leaderboard (top agents by reputation) */ getLeaderboard(limit?: number): Promise; /** * Calculate average rating from reviews */ static calculateAverageRating(reviews: ReputationEvent[]): number; /** * Get reputation trend (improving/declining) */ static getReputationTrend(history: ReputationEvent[]): 'improving' | 'stable' | 'declining'; /** * Check if agent is trustworthy for transaction */ static isTrustworthy(score: ReputationScore, minimumScore?: number): boolean; } export {}; /** * Example Usage: * * ```typescript * import { ReputationSystem } from 'opacus-sdk'; * * // Initialize reputation system * const reputation = new ReputationSystem(REPUTATION_CONTRACT, signer); * * // Submit review after transaction * await reputation.submitReview({ * agentId: 'agent-123', * transactionId: '0xabc...', * rating: { * overall: 5, * accuracy: 5, * speed: 4, * support: 5 * }, * comment: 'Excellent service!', * verified: true * }); * * // Get agent reputation * const score = await reputation.getAgentScore('agent-123'); * console.log('Score:', score.score, '/100'); * console.log('Trust Level:', score.trustLevel); * console.log('EigenTrust:', score.eigenTrust); * * // Check if trustworthy * const safe = ReputationSystem.isTrustworthy(score, 60); * ``` */ //# sourceMappingURL=reputation.d.ts.map