UNPKG

lotus-sdk

Version:

Central repository for several classes of tools for integrating with, and building for, the Lotusia ecosystem

143 lines 4.51 kB
import type { PeerInfo } from '../types.js'; export interface DiscoveryCriteria { protocol: string; capabilities?: string[]; minReputation?: number; location?: { latitude: number; longitude: number; radiusKm: number; }; customCriteria?: Record<string, unknown>; maxResults?: number; timeout?: number; } export interface DiscoveryAdvertisement { id: string; protocol: string; peerInfo: PeerInfo; capabilities: string[]; signature?: Buffer; createdAt: number; expiresAt: number; reputation: number; metadata?: Record<string, unknown>; customCriteria?: Record<string, unknown>; location?: { latitude: number; longitude: number; }; } export interface DiscoveryOptions { ttl?: number; replicas?: number; autoRefresh?: boolean; refreshInterval?: number; enableCache?: boolean; cacheTTL?: number; maxRetries?: number; retryDelay?: number; enableRateLimit?: boolean; rateLimitWindow?: number; maxOperationsPerWindow?: number; } export interface DiscoverySubscription { id: string; criteria: DiscoveryCriteria; callback: (advertisement: DiscoveryAdvertisement) => void; active: boolean; createdAt: number; lastActivity: number; topic: string; } export interface SubscriptionOptions { fetchExisting?: boolean; fetchTimeout?: number; deduplicate?: boolean; } export interface IDiscoveryAdvertiser { advertise(advertisement: DiscoveryAdvertisement, options?: DiscoveryOptions): Promise<string>; withdraw(advertisementId: string): Promise<void>; refresh(advertisementId: string, options?: DiscoveryOptions): Promise<void>; getActiveAdvertisements(): string[]; isAdvertisementActive(advertisementId: string): boolean; start(): Promise<void>; stop(): Promise<void>; } export interface IDiscoveryDiscoverer { discover(criteria: DiscoveryCriteria, options?: DiscoveryOptions): Promise<DiscoveryAdvertisement[]>; subscribe(criteria: DiscoveryCriteria, callback: (advertisement: DiscoveryAdvertisement) => void, options?: SubscriptionOptions): Promise<DiscoverySubscription>; unsubscribe(subscriptionId: string): Promise<void>; getActiveSubscriptions(): string[]; clearCache(protocol?: string): void; getCacheStats(): { size: number; hits: number; misses: number; hitRate: number; }; start(): Promise<void>; stop(): Promise<void>; } export interface SecurityValidationResult { valid: boolean; error?: string; securityScore: number; details: { signatureValid: boolean; notExpired: boolean; reputationAcceptable: boolean; criteriaMatch: boolean; customValidation: boolean; }; } export interface ReputationData { peerId: string; score: number; successes: number; failures: number; lastInteraction: number; history: Array<{ timestamp: number; success: boolean; weight: number; reason?: string; }>; } export interface SecurityPolicy { minReputation: number; maxAdvertisementAge: number; enableSignatureVerification: boolean; enableReplayPrevention: boolean; enableRateLimiting: boolean; rateLimits: { maxAdvertisementsPerPeer: number; maxDiscoveryQueriesPerPeer: number; windowSizeMs: number; }; customValidators: Array<{ name: string; validator: (advertisement: DiscoveryAdvertisement) => boolean; }>; } export declare enum DiscoveryErrorType { INVALID_ADVERTISEMENT = "INVALID_ADVERTISEMENT", ADVERTISEMENT_EXPIRED = "ADVERTISEMENT_EXPIRED", SECURITY_VALIDATION_FAILED = "SECURITY_VALIDATION_FAILED", DHT_OPERATION_FAILED = "DHT_OPERATION_FAILED", NETWORK_TIMEOUT = "NETWORK_TIMEOUT", RATE_LIMIT_EXCEEDED = "RATE_LIMIT_EXCEEDED", INVALID_CRITERIA = "INVALID_CRITERIA", SUBSCRIPTION_ERROR = "SUBSCRIPTION_ERROR", CACHE_ERROR = "CACHE_ERROR", CONFIGURATION_ERROR = "CONFIGURATION_ERROR", SIGNATURE_ERROR = "SIGNATURE_ERROR" } export declare class DiscoveryError extends Error { readonly type: DiscoveryErrorType; readonly cause?: Error; constructor(type: DiscoveryErrorType, message: string, cause?: Error); } export declare const DEFAULT_DISCOVERY_OPTIONS: Required<DiscoveryOptions>; export declare const DEFAULT_SECURITY_POLICY: SecurityPolicy; //# sourceMappingURL=types.d.ts.map