/** * On-Chain Agent Discovery * * Reads the AgentRegistry contract on the Sequence0 chain to discover * active agent nodes. Fully decentralized — no centralized gateway needed. * * @example * ```typescript * const discovery = new AgentDiscovery({ * rpcUrl: 'https://mainnet-rpc.sequence0.network', * registryAddress: '0x...', * }); * const agents = await discovery.discoverAgents(); * const agent = await discovery.selectAgent(); * ``` */ export interface AgentInfo { /** libp2p peer ID (e.g. 12D3KooW...) */ peerId: string; /** Full multiaddr (e.g. /ip4/1.2.3.4/tcp/9000/p2p/12D3KooW...) */ multiaddr: string; /** * Operator-controlled REST API URL the SDK actually dials. * * Resolution order: * 1. The operator's on-chain `httpsEndpoints[peerId]` if non-empty (the * DNS-fronted URL the operator self-published via * `AgentRegistryV2.setHttpsEndpoint`). * 2. Otherwise, the multiaddr-derived fallback * (`http(s)://:`). * * On testnet, agents without a self-published endpoint still resolve via * the multiaddr fallback so the legacy 24-agent fleet keeps working * during the transition. */ apiUrl: string; /** Agent's payment address */ paymentAddress: string; /** * The DNS-fronted HTTPS REST URL the operator published on chain via * `AgentRegistryV2.setHttpsEndpoint`. Empty string when the operator has * not (yet) published one. When non-empty this is the URL the SDK uses * as `apiUrl` — no `sequence0.network` proxy in the path. */ httpsEndpoint?: string; } export interface DiscoveryOptions { /** Sequence0 chain RPC URL */ rpcUrl: string; /** AgentRegistry contract address */ registryAddress: string; /** Cache TTL in ms (default: 60000) */ cacheTtl?: number; /** API port offset from P2P port (default: -920, i.e. 9000 → 8080) */ apiPortOffset?: number; /** Use HTTPS for discovered agent API URLs (default: false) */ useHttps?: boolean; /** * Require HTTPS for all agent connections (default: false). * When true, agents that only have HTTP endpoints are excluded from discovery. * SECURITY: Should be true on mainnet to prevent MITM on signing requests. */ requireHttps?: boolean; } export declare class AgentDiscovery { private rpcUrl; private registryAddress; private cacheTtl; private apiPortOffset; private useHttps; private requireHttps; private cache; constructor(options: DiscoveryOptions); /** * Discover active agents from the on-chain registry (single page, max 100). * Convenience wrapper around discoverAllAgents() — suitable when the * network has fewer than 100 registered agents. */ discoverAgents(): Promise; /** * Discover ALL active agents from the on-chain registry using pagination. * Loops through pages of 100 agents until a batch returns fewer than 100, * then combines all results and caches them with the configured TTL. */ discoverAllAgents(): Promise; /** * Read the operator-published HTTPS REST endpoint for one peerId from * `AgentRegistryV2.httpsEndpoints(string)`. Returns the empty string * if the operator has not published one. * * This is the on-chain entrypoint backing the decentralized * per-operator HTTPS ingress — every client (browser wallet, SDK, CLI) * resolves the operator's URL from chain and talks to it DIRECTLY, * rather than through any shared founder-run proxy. */ fetchHttpsEndpoint(peerId: string): Promise; /** * Fetch a single page of agents from the registry contract. * @param offset - Starting index * @param limit - Maximum agents to return (up to 100) */ private fetchAgentPage; /** * Select a random healthy agent from the registry * @returns API URL of a healthy agent * @throws if no healthy agents found */ selectAgent(): Promise; /** * Get agents that respond to health checks */ getHealthyAgents(): Promise; /** * Get the on-chain reputation score for a single agent. * Score = heartbeatCount + (signaturesParticipated * 10) + blockAge * Returns 0 if agent is not active. */ getAgentReputation(peerId: string): Promise; /** * Get reputation scores for multiple agents in parallel. */ getAgentReputations(peerIds: string[]): Promise>; /** * Invalidate the agent cache */ clearCache(): void; private ethCall; /** * Decode ABI response from getActiveAgents() * Returns: (string[] peerIds, string[] multiaddrs) * ABI encoding: offset_peerIds, offset_multiaddrs, peerIds_data, multiaddrs_data */ private decodeAgentResponse; /** * Decode a dynamic string[] from ABI-encoded data */ private decodeStringArray; /** * Convert a libp2p multiaddr to an HTTP API URL * e.g. /ip4/52.14.62.162/tcp/9000/p2p/12D3KooW... → http://52.14.62.162:8080 * * Convention: API port = P2P port + apiPortOffset (default: 9000 → 8080) */ private multiaddrToApiUrl; } //# sourceMappingURL=discovery.d.ts.map