/** * Device Discovery and Intent Exchange Protocol for TOSS * * Implements Section 11-12 of the TOSS Technical Paper: * - Device discovery and peer identification * - Intent exchange protocol * - Trust establishment between offline peers * - Conflict resolution for multi-device scenarios */ import type { SolanaIntent } from './intent'; import type { TossUser } from './types/tossUser'; /** * Peer device information discovered via transport */ export interface PeerDevice { id: string; user?: TossUser; lastSeen: number; transport: 'ble' | 'nfc' | 'qr' | 'mesh'; signalStrength?: number; trustScore?: number; } /** * Encrypted intent exchange session */ export interface NoiseSession { peerId: string; sessionKey: Uint8Array; encryptionCipher: any; createdAt: number; } /** * Intent exchange request/response */ export interface IntentExchangeRequest { requestId: string; timestamp: number; intent: SolanaIntent; requesterId: string; requesterUser?: TossUser; expiresAt: number; encrypted?: boolean; ciphertext?: Uint8Array; } export interface IntentExchangeResponse { requestId: string; timestamp: number; status: 'accepted' | 'rejected' | 'deferred'; responderId: string; reason?: string; acknowledgedIntentIds?: string[]; } /** * Device discovery service */ export declare class DeviceDiscoveryService { private discoveredPeers; private readonly PEER_TIMEOUT; private readonly MAX_PEERS; /** * Register a discovered peer device */ registerPeer(peer: PeerDevice): void; /** * Get all active peers (not timed out) */ getActivePeers(): PeerDevice[]; /** * Get a specific peer by ID */ getPeer(peerId: string): PeerDevice | undefined; /** * Update trust score for a peer based on interaction */ updateTrustScore(peerId: string, delta: number, maxScore?: number): void; /** * Clear all discovered peers */ clearPeers(): void; } /** * Intent exchange protocol handler with Noise encryption support */ export declare class IntentExchangeProtocol { private pendingRequests; private noiseSessions; private requestTimeouts; private sessionTimeouts; private deviceStaticKey; private readonly REQUEST_TIMEOUT; private readonly SESSION_TIMEOUT; constructor(); /** * Establish a secure Noise session with a peer */ establishSecureSession(peerId: string): NoiseSession; /** * Get an active Noise session with a peer */ getSecureSession(peerId: string): NoiseSession | undefined; /** * Encrypt request payload using Noise session */ private encryptRequestPayload; /** * Decrypt request payload using Noise session */ private decryptRequestPayload; /** * Create a new intent exchange request with optional Noise encryption */ createRequest(intent: SolanaIntent, requesterId: string, requesterUser?: TossUser, expiresIn?: number, // 5 minutes default useEncryption?: boolean, // Enable Noise encryption peerId?: string): IntentExchangeRequest; /** * Respond to an intent exchange request */ createResponse(requestId: string, responderId: string, status: 'accepted' | 'rejected' | 'deferred', reason?: string, acknowledgedIntentIds?: string[]): IntentExchangeResponse; /** * Get a pending request, decrypting if necessary */ getRequest(requestId: string, peerId?: string): IntentExchangeRequest | undefined; /** * Get the static key for this device (for peer verification) */ getDeviceStaticKey(): Uint8Array; /** * Clear all pending requests and their timers */ clearRequests(): void; /** * Clear all Noise sessions and their timers */ clearSessions(): void; /** * Dispose of the protocol, clearing internal state and timers */ dispose(): void; } /** * Device and intent routing service for multi-hop scenarios */ export declare class IntentRoutingService { private routingTable; private readonly MAX_HOPS; /** * Register a routing path to a device */ registerRoute(targetDeviceId: string, viaPeers: string[]): void; /** * Get the best route to a device */ getRoute(targetDeviceId: string): string[] | undefined; /** * Find all reachable devices */ getReachableDevices(): string[]; /** * Validate a route is still viable */ validateRoute(targetDeviceId: string, activePeers: PeerDevice[]): boolean; /** * Clear all routes */ clearRoutes(): void; } /** * Multi-device conflict resolver * * When multiple devices are offline and both create intents for the same * action, this detects and resolves the conflict per TOSS principles. */ export declare class MultiDeviceConflictResolver { /** * Detect conflicting intents from different devices */ static detectConflicts(intents: SolanaIntent[]): SolanaIntent[][]; /** * Resolve conflicts using deterministic rules per TOSS spec * * Rules (in order): * 1. Earliest nonce wins (replay protection) * 2. Earliest timestamp wins (FIFO fairness) * 3. Lexicographically first signature wins (deterministic tiebreak) */ static resolveConflicts(conflictingIntents: SolanaIntent[]): { winner: SolanaIntent; losers: SolanaIntent[]; }; } export declare const deviceDiscovery: DeviceDiscoveryService; export declare const intentExchange: IntentExchangeProtocol; export declare const intentRouting: IntentRoutingService; //# sourceMappingURL=discovery.d.ts.map