/** * Opacus Golden Path SDK * * Single entry point for agent developers. * Wraps the V1 REST API with a typed, promise-based interface. * * Usage: * import { Opacus } from "opacus-sdk"; * const opacus = new Opacus({ apiKey: process.env.OPACUS_KEY }); * await opacus.bootstrap(); * * // On-chain escrow (Base mainnet) * const lock = await opacus.escrow.lock({ amount: 5, counterparty: '0x…' }); * await opacus.escrow.release(lock.escrowId, 'release'); * * // ZK proof anchored on 0G DA mainnet * const proof = await opacus.zk.prove({ kind: 'reputation-threshold', payload: { did, score: 92, minScore: 80 } }); * const v = await opacus.zk.verify(proof); * * // TEE attestation anchored on 0G DA mainnet * const att = await opacus.tee.attest({ runtimeId: 'my-agent-v1' }); * const tv = await opacus.tee.verify(att); * * // Data Market — browse and purchase IoT datasets * const listings = await opacus.dataMarket.list({ category: 'iot-energy' }); * const purchase = await opacus.dataMarket.purchase(listings.listings[0].id); * * // Nitro — get optimal CEX-co-located routing node * const route = await opacus.nitro.route({ exchange: 'gemini' }); * const ping = await opacus.nitro.ping(); * * // Hermes — trigger a Hermes AI agent task * const task = await opacus.hermes.run({ intent: 'analyze BTC/USDC trend', chain: 'base' }); */ import { OpacusEscrowClient } from './escrow/api-client.js'; import { OpacusZKClient } from './zk/client.js'; import { OpacusTEEClient } from './tee/client.js'; export type { EscrowLockOptions, EscrowLockResult, EscrowReleaseResult, EscrowRecord, } from './escrow/api-client.js'; export type { ZKProveOptions, ZKProveResult, ZKVerifyOptions, ZKVerifyResult, ZKProofKind, } from './zk/client.js'; export type { TEEAttestOptions, TEEAttestResult, TEEVerifyOptions, TEEVerifyResult, } from './tee/client.js'; export interface OpacusOptions { /** API key from Agentboard → API Keys */ apiKey: string; /** Base URL (default: https://opacus.xyz) */ baseUrl?: string; /** Default chain for operations (default: "base") */ chain?: string; /** Optional SDK telemetry (disabled by default). */ telemetry?: { enabled?: boolean; endpoint?: string; anonymousId?: string; appId?: string; sdkVersion?: string; sampleRate?: number; meta?: Record; }; } export interface BootstrapResult { did: string; h3Cell: string; chains: string[]; token: string; } export interface PaymentRailInfo { id: string; enabled: boolean; providers: string[]; chains?: string; settlement?: string; } export interface PaymentRailsResult { ok: boolean; computeBalance: { balance: number; currency: string; }; paymentRails: { provider: string; model: string; khalani?: { enabled: boolean; layer?: string; breakdownUrl?: string; }; rails: PaymentRailInfo[]; }; } export interface ProductAnalyticsResult { ok: boolean; generatedAt: string; summary: { totalUsers: number; didAssignedUsers: number; h3DefinedUsers: number; totalDidAgents: number; totalH3Agents: number; }; moduleStats: Array<{ module: string; totalEvents: number; uniqueUsers: number; }>; sdkTelemetry: { totalEvents: number; last24h: number; byModule: Record; byStatus: Record; }; userBreakdown?: Array<{ user: string; didAssigned: boolean; h3Defined: boolean; didCount: number; h3Count: number; modules: Record; totalEvents: number; plan: string; }>; } export interface RouteResult { selected: { did: string; latency_ms: number; region: string; score: number; }; candidates: Array<{ did: string; latency_ms: number; region: string; score: number; }>; chain: string; mode: string; } export interface DataMarketListing { id: string; title: string; description: string; category: string; priceUsdc: number; sellerDid?: string; walletAddress?: string; location?: { city?: string; country?: string; }; deviceType?: string; dataInterval?: string; ogDaHash?: string; manifestHash?: string; reportCount?: number; status?: 'active' | 'delisted'; /** Attestation metadata (signature details). dataHash is NOT returned in public listing views). */ attestation?: { wallet: string; nonce: string; chainId: number; expiresAt: number; domain: string; }; createdAt?: string; } export interface DataMarketListOptions { category?: string; location?: string; search?: string; limit?: number; offset?: number; } export interface DataMarketListResult { listings: DataMarketListing[]; total: number; } export interface DataMarketPurchaseResult { success: boolean; purchaseId: string; listingId: string; escrowId: string; /** How escrow was handled for this purchase */ mode: 'immediate' | 'optimistic' | 'locked'; escrowStatus: 'locked' | 'released' | 'optimistic_locked'; /** Only present for released/optimistic_locked modes */ dataHash?: string; accessUrl?: string; /** ISO timestamp after which the dispute window closes (optimistic mode only) */ disputeDeadline?: string; /** Whether buyer can still open a dispute on this purchase */ canDispute?: boolean; message?: string; } export interface DataMarketDisputeResult { ok: boolean; escrowId: string; status: 'disputed'; disputedAt: number; message?: string; } export interface DataMarketReportResult { ok: boolean; listingId: string; reportCount: number; /** True if the listing was automatically delisted after exceeding report threshold */ autoDelisted: boolean; reportsToAutoDelistRemaining?: number; message?: string; } export interface DataMarketDeliverOptions { /** SHA-256 hex hash of the delivered data (must match listing.manifestHash if set) */ proofHash: string; dataUrl?: string; } export interface DataMarketDeliverResult { ok: boolean; escrowId: string; manifestVerified?: boolean; releasedAt?: number; } export interface DataMarketPublishOptions { title: string; description: string; category: string; priceUsdc: number; /** * SHA-256 hex hash of the dataset or manifest. Required for paid 0G DA listings. * This is stored server-side and is never returned in public listing views. */ dataHash?: string; location?: { city?: string; country?: string; }; deviceType?: string; dataInterval?: string; /** * Attestation signature proving you are licensed to sell this data. * Sign the canonical message: `opacus-data-market-v1\n\n\n\n\n\n\nI attest I am licensed to sell this data.` * Using eth_sign / personal_sign. */ attestationSignature?: string; /** Alias for attestationSignature (backward compat) */ ownerSignature?: string; /** Nonce for replay protection (random hex string) */ sigNonce?: string; /** Unix seconds expiry of the attestation signature */ sigExpiry?: number; /** Chain ID the signature was made on (e.g. 8453 for Base, 16661 for 0G) */ sigChainId?: number; /** SHA-256 hex hash of the content manifest (used for delivery verification) */ manifestHash?: string; } export interface DataMarketPublishResult { id: string; title: string; status: string; } export interface NitroPingResult { ok: boolean; rttMs: number; blockNumber: string; winner: string; pool: Array<{ url: string; latencyMs: number; healthy: boolean; }>; } export interface NitroRouteOptions { /** Exchange slug: gemini | binance | coinbase | okx | bybit | kraken | uniswap | aerodrome | 0g */ exchange?: string; /** Agent latitude for proximity-based routing */ lat?: number; lng?: number; } export interface NitroRouteResult { ok: boolean; exchange?: { label: string; apiHost: string; awsRegion: string; nitroId: string; }; nitro_node: { label: string; endpoint: string; }; quic_endpoint: string; latency_comparison: { tcp_p50_ms: number; tcp_p95_ms: number; quic_p50_ms: number; quic_p95_ms: number; speedup_p50: string; speedup_p95: string; }; storage_savings?: { vs_s3_percent: number; }; } export interface HermesRunOptions { /** Natural-language intent describing the task */ intent: string; /** Target chain: "base" | "0g" (default: "base") */ chain?: string; /** If true, route through Nitro for low latency */ nitro?: boolean; /** 0G DA hash of a Data Market signal to feed into the task */ signal?: string; /** Archive decision + result to 0G DA */ log_to_0g?: boolean; /** Optional exchange for CEX leg (e.g. "gemini") */ exchange?: string; } export interface HermesRunResult { taskId: string; status: 'pending' | 'running' | 'executed' | 'failed'; nitroNode?: string; cexOrderId?: string; dexTxHash?: string; ogDaLogHash?: string; latencyMs?: number; result?: unknown; sig?: string; agentPubKey?: string; } export interface HermesTaskStatus { taskId: string; status: 'pending' | 'running' | 'executed' | 'failed'; result?: unknown; createdAt: string; updatedAt: string; } export interface ComputeRunOptions { prompt: string; model?: string; providerAddress?: string; } export interface ComputeRunResult { ok: boolean; provider: string; providerAddress?: string; jobId?: string; model: string; request?: unknown; output: unknown; attestation?: unknown; status?: string; } export interface ComputeModelInfo { id: string; label: string; provider: string; default?: boolean; } export interface ComputeModelsResult { ok: boolean; defaultModel: string; models: ComputeModelInfo[]; } export interface DAUploadOptions { data: string | Uint8Array | Record; metadata?: Record; } export interface DAUploadResult { ok: boolean; rootHash: string; size: number; timestamp: number; url: string; } export interface DADownloadResult { ok: boolean; data: string | Record; size: number; timestamp: number; } export interface DAProveOptions { rootHash: string; leafIndex?: number; metadata?: Record; } export interface DAProveResult { ok: boolean; proof: string; commitment: string; timestamp: number; } export interface StorageUploadOptions { file: string | Uint8Array | Record; name?: string; metadata?: Record; replicas?: number; ttlDays?: number; } export interface StorageUploadResult { ok: boolean; fileId: string; rootHash: string; size: number; daRootHash?: string; replicas: number; ttlDays: number; url: string; } export interface StorageDownloadResult { ok: boolean; file: string | Record; fileId: string; size: number; replicas: number; } export interface StorageListResult { ok: boolean; files: Array<{ fileId: string; name?: string; size: number; rootHash: string; replicas: number; createdAt: number; ttlDays: number; }>; } export declare class Opacus { private apiKey; private baseUrl; private chain; private sessionToken?; private did?; private telemetryEnabled; private telemetryEndpoint; private telemetryAnonymousId?; private telemetryAppId?; private telemetrySdkVersion; private telemetrySampleRate; private telemetryMeta?; routing: OpacusRouting; h3: OpacusH3; ogStorage: OpacusStorage; discovery: OpacusDiscovery; /** On-chain USDC escrow (Base mainnet — contract 0xA104758F06549c2691A94c9AF0B0473463F502C2) */ escrow: OpacusEscrowClient; /** ZK commitment proofs anchored on 0G DA mainnet */ zk: OpacusZKClient; /** TEE attestation reports anchored on 0G DA mainnet */ tee: OpacusTEEClient; /** IoT + real-world Data Market on 0G DA */ dataMarket: OpacusDataMarket; /** Nitro speed layer — CEX co-location + QUIC routing */ nitro: OpacusNitro; /** Hermes AI agent task execution */ hermes: OpacusHermes; /** 0G compute inference */ compute: OpacusCompute; /** 0G Data Availability (DA) — ephemeral, immutable, light proofs */ da: OpacusDataAvailability; /** 0G Storage — persistent, replicated, with TTL */ storage: OpacusStorageAdvanced; constructor(options: OpacusOptions); /** Internal fetch with auth headers */ _fetch(path: string, options?: RequestInit): Promise; private _moduleFromPath; private _telemetryTrackPath; /** Internal helper to call a Kinetic MCP method through the hosted endpoint. */ private _callKineticMcp; /** * Bootstrap: register agent on H3 grid, receive DID + H3 cell. * Uses kineti_citadel_register under the hood — idempotent and free. */ bootstrap(): Promise; /** * Get payment rails and unified compute balance. * First tries REST billing endpoint; falls back to MCP tool when needed. */ getPaymentRails(): Promise; /** Force retrieval via MCP tool path. */ getPaymentRailsViaMcp(): Promise; /** Product-level analytics: module adoption, DID/H3 counts, telemetry summary. */ getProductAnalytics(params?: { includeUsers?: boolean; limit?: number; period?: '24h' | '7d' | '30d' | '90d' | 'all'; adminToken?: string; }): Promise; /** Get the DID assigned after bootstrap */ getDid(): string | undefined; } declare class OpacusRouting { private sdk; constructor(sdk: Opacus); /** Find the best execution path for an intent */ optimize(params: { intent: string; chain?: string; mode?: 'fast' | 'balanced' | 'cheap' | 'safe'; }): Promise; } declare class OpacusH3 { private sdk; constructor(sdk: Opacus); /** Get the H3 cell for the current agent or a given lat/lng */ locate(params?: { lat?: number; lng?: number; resolution?: number; }): Promise<{ h3Cell: string; resolution: number; lat: number; lng: number; }>; } declare class OpacusDiscovery { private sdk; constructor(sdk: Opacus); /** Discover agents by capability, within optional radius */ agents(params: { capability?: string; radius_km?: number; h3Cell?: string; }): Promise; } declare class OpacusStorage { private sdk; constructor(sdk: Opacus); /** Upload data to 0G decentralized storage */ store(data: string | Uint8Array | Record): Promise; } declare class OpacusDataMarket { private sdk; constructor(sdk: Opacus); /** * List available Data Market listings. * Filter by category (e.g. 'iot-energy', 'iot-gps'), location, or search term. */ list(options?: DataMarketListOptions): Promise; /** Get a single listing by ID (private fields like dataHash are stripped) */ get(listingId: string): Promise<{ ok: boolean; listing: DataMarketListing; }>; /** * Purchase a listing. * - `immediate`: free listing → data granted right away * - `optimistic`: 0G DA listing → data granted immediately with a 20-minute dispute window * - `locked`: paid non-0G listing → seller must call deliver() to release */ purchase(listingId: string): Promise; /** List your previous purchases (dataHash only shown for released/optimistic_locked escrows) */ myPurchases(): Promise<{ purchases: DataMarketPurchaseResult[]; }>; /** List listings you have published */ myListings(): Promise<{ listings: DataMarketListing[]; }>; /** * Publish a new dataset to the Data Market. * For paid 0G DA listings, include `dataHash`, `attestationSignature`, * `sigNonce`, `sigExpiry`, and `sigChainId` to prove you are licensed to sell. * Optionally include `manifestHash` (SHA-256 of content manifest) for delivery verification. * Rate limit: 5 listings per 24 hours per account. */ publish(options: DataMarketPublishOptions): Promise; /** * Open a dispute on an optimistic_locked purchase. * Must be called within 20 minutes of purchase (before disputeDeadline). * Freezes the escrow to 'disputed' state, preventing seller from collecting payment. */ dispute(escrowId: string, reason: string): Promise; /** * Report a listing for fraud, plagiarism, or bad content. * A listing is automatically delisted after 3 unique reports. * Cannot report your own listing. */ report(listingId: string, reason: string): Promise; /** * (Seller) Deliver data for a locked escrow. * If the listing has a `manifestHash`, `proofHash` must match exactly. * On success, escrow is released and buyer gains access. */ deliver(escrowId: string, options: DataMarketDeliverOptions): Promise; /** * (Seller) Remove / delist your own listing. */ remove(listingId: string): Promise<{ ok: boolean; message?: string; }>; } declare class OpacusNitro { private sdk; constructor(sdk: Opacus); /** * Live latency ping to all Nitro nodes. * No authentication required — useful for health checks. */ ping(): Promise; /** * Get the optimal Nitro node for a given exchange or agent location. * Exchange anchors: gemini | binance | binanceus | coinbase | kraken | okx | bybit | uniswap | aerodrome | 0g */ route(options?: NitroRouteOptions): Promise; } declare class OpacusHermes { private sdk; constructor(sdk: Opacus); /** * Run a task via the Hermes AI agent. * Supports CEX leg (via Nitro exchange anchor), DEX leg (on-chain), * IoT data signal (Data Market dataHash), and 0G DA logging. * * @example * // CEX + DEX trading pipeline with IoT signal * const task = await opacus.hermes.run({ * intent: 'trade', * chain: 'base', * exchange: 'gemini', * nitro: true, * signal: purchase.dataHash, * log_to_0g: true, * }); */ run(options: HermesRunOptions): Promise; /** Check the status of a previously submitted Hermes task */ status(taskId: string): Promise; /** List recent Hermes task history */ history(limit?: number): Promise<{ tasks: HermesTaskStatus[]; }>; } declare class OpacusCompute { private sdk; constructor(sdk: Opacus); /** * Run a 0G compute inference job through the kernel. * Fees paid automatically from sponsor wallet (opacus-managed). * * @example * const result = await opacus.compute.run({ * prompt: 'Analyze this market data', * model: 'llama-7b', * providerAddress: '0x...' // optional, defaults to sponsor * }); */ run(options: ComputeRunOptions): Promise; /** List available 0G compute models exposed by the kernel. */ models(): Promise; /** * Get current compute credits balance for this user. * Shows how many compute calls remain in sponsor quota for today. */ credits(): Promise<{ ok: boolean; creditsRemaining: number; dailyLimit: number; userPlan: string; }>; } declare class OpacusDataAvailability { private sdk; constructor(sdk: Opacus); /** * Upload data to 0G DA layer (immutable, replicated, light commitments). * Perfect for ZK proofs, audit logs, transaction history. * * @example * const da = await opacus.da.upload({ * data: { proof: '0x...', timestamp: Date.now() }, * metadata: { kind: 'zk-reputation', user: did }, * }); */ upload(options: DAUploadOptions): Promise; /** * Download data from 0G DA by root hash. */ download(rootHash: string): Promise; /** * Generate a zero-knowledge proof of inclusion for DA data. * Used internally for ZK verification and light commitments. */ prove(options: DAProveOptions): Promise; /** * Verify a DA commitment on-chain or off-chain. */ verify(proof: string, commitment: string): Promise<{ ok: boolean; valid: boolean; }>; } declare class OpacusStorageAdvanced { private sdk; constructor(sdk: Opacus); /** * Upload a file to 0G Storage with optional replication and TTL. * Suitable for agent models, large datasets, or long-term archival. * * @example * const storage = await opacus.storage.upload({ * file: modelBytes, * name: 'agent-v1-model', * replicas: 3, * ttlDays: 365, * }); */ upload(options: StorageUploadOptions): Promise; /** * Download a file from 0G Storage by file ID. */ download(fileId: string): Promise; /** * List all files you have stored. */ list(): Promise; /** * Delete a stored file (if you are the owner). */ delete(fileId: string): Promise<{ ok: boolean; message?: string; }>; /** * Extend TTL for a stored file. */ extendTtl(fileId: string, additionalDays: number): Promise<{ ok: boolean; newTtlDays: number; }>; } export interface DiscoverResult { agents: Array<{ did: string; h3Cell: string; capabilities: string[]; latency_ms: number; trustLevel: string; }>; total: number; } export interface StorageResult { rootHash: string; size: number; url: string; } export declare class OpacusError extends Error { status: number; body: string; path: string; constructor(status: number, body: string, path: string); } //# sourceMappingURL=opacus.d.ts.map