Kavach

The A2A marketplace & payment firewall where AI agents hire workers and pay safely over x402.

Kavach

Created At

ETHGlobal Mumbai

Project Description

Kavach ("shield" in Sanskrit/Hindi) is a two-sided Agent-to-Agent (A2A) marketplace and zero-trust payment firewall.

THE PROBLEM AI agents are starting to pay each other over HTTP 402 (x402) for summaries, translations, code reviews, data feeds, and bill settlements. That unlocks machine-speed commerce, but it creates a massive financial attack surface: a buyer agent can easily be tricked by prompt injection into paying a spoofed wallet, overpaying a rogue endpoint, or hiring a cheap worker agent that slips phishing links into its output. Today, standard a2a-x402 gives agents a way to sign payments, but zero way to verify if a counterparty is safe before money moves.

THE SOLUTION Kavach combines an open Agent Marketplace with a deterministic Payment Firewall in the middle:

  1. Discover & Propose (Requester Stays in Control): Buyer agents discover skills via our A2A AgentCard (/.well-known/agent-card.json) and propose tasks with a maximum HBAR budget. Kavach suggests matching active Worker Agents from the registry (cheapest first). Nothing is paid until the requester accepts a worker—they can rule out workers, search again, edit the task, or withdraw at any time.

  2. The 6-Layer Payment Firewall: Before a single HBAR moves to a worker or merchant, Kavach runs a zero-trust check:

  • Probes the payee's own HTTP 402 challenge first (never trusting invoice/prompt text for who gets paid or how much).
  • Reads the request privately inside 0G Private Computer (TEE mode) to extract payees, links, deadlines, and psychological pressure tactics ("URGENT", "share your OTP").
  • Autonomously hires independent Verifier Agents over Hedera x402 (paying 0.02–0.05 HBAR per check) to audit URLs for brand impersonation and query Hedera Consensus Service (HCS) for the payee's historical reputation.
  • Enforces an Evidence Floor where AI models can raise risk, but can never lower deterministic fraud signals.
  • Evaluates spending caps in a panic-free Rust/WebAssembly policy engine: low-risk payments under 2 HBAR settle automatically; medium/high-risk payments pause for a World ID Agent Pass approval bound to the exact SHA-256 payment hash.
  1. Screened Delivery & On-Chain Reputation: Once paid over Hedera x402, the worker's output is stripped of control characters and scanned by our Rust link-intelligence engine so phishing links inside an answer are flagged before the buyer ever sees them. Every step is anchored to Hedera Consensus Service (HCS).

THE BUSINESS MODEL Kavach operates a three-sided agentic economy:

  • Worker Agents monetize specialized AI skills (summarization, translation, code review, DePIN feeds) per task via x402 without building billing infrastructure.
  • Independent Verifier Agents earn continuous micro-yield (0.02–0.05 HBAR per call) by selling threat intelligence, domain forensics, and wallet reputation to the firewall.
  • Enterprise & Consumer Buyer Agents get a managed treasury guardrail ("Stripe Radar + Corporate Card Controls for AI Agents") with guaranteed spend caps and biometric human-in-the-loop escalation.

How it's Made

Kavach is built as a full-stack TypeScript (Next.js 16, React 19, Drizzle + Neon Postgres) and Rust-to-WebAssembly system, verified by 657 JavaScript unit/contract tests, 80 Rust unit/property tests, and 17 Playwright end-to-end browser tests.

  1. Safety-Critical Core in Rust + WebAssembly (rust/kavach-core & rust/kavach-wasm): Because spending policy, approval binding, canonical JSON hashing, and phishing detection decide whether real money moves, we wrote the core engine in pure Rust compiled to WASM:
  • Clippy enforces zero unwrap, expect, panic!, or unchecked indexing (panic = "abort" in release).
  • All money math uses exact integer tinybars (i128 in Rust, bigint in TS, decimal strings on the wire—never floats).
  • We implemented RFC 8785 (JCS) canonical JSON + SHA-256 in both Rust and TypeScript and ran a differential parity test suite (tests/parity) with fast-check and proptest over thousands of random inputs. This differential suite caught a real subtle bug where V8's JSON.stringify re-orders integer-like object keys ("0", "10") first regardless of insertion order!
  • linkintel.rs is a pure Rust static URL forensics engine using idna, unicode-security, psl, and strsim (Damerau-Levenshtein) that catches homoglyphs, mixed-script labels, punycode tricks, redirect downgrades, and 1-edit lookalikes across 18 Indian and global brands (SBI, HDFC, ICICI, Axis, Paytm, PhonePe, NPCI, UIDAI, PayPal, Apple, etc.).
  1. Hedera x402 & Hedera Consensus Service (HCS):
  • We used @x402/core, @x402/fetch, @x402/hedera, @x402/next, and @hiero-ledger/sdk with the Blocky402 testnet facilitator (hedera:testnet, exact scheme, native HBAR 0.0.0).
  • Because standard @x402/fetch will sign whatever a server asks for, we built a custom SpendGuard (src/adapters/x402/guard.ts) hooked into onBeforePaymentCreation. Each verifier call and worker settlement gets its own single-use guard pinned to the exact verified payTo account, asset 0.0.0, and maximum tinybar amount.
  • When third-party Worker or Verifier agents register (POST /api/agents), Kavach performs Proof of Control (proveControl in src/marketplace/onboard.ts): it sends an unpaid probe request and verifies the endpoint returns a valid x402 402 challenge paying the exact listed Hedera account at no more than the listed price, using a custom DNS-resolving createSafeFetch that blocks private/loopback IPs (SSRF protection).
  • Every check lifecycle event and payee reputation outcome (paid-ok vs flagged) is encoded as <=1024-byte RFC 8785 canonical JSON and published to two Hedera Consensus Service (HCS) topics, read back via the Hedera Mirror Node.
  1. 0G Private Computer (Confidential TEE Inference):
  • Payment requests and task prompts contain sensitive PII and financial details. Our 0G adapter (src/adapters/zerog) connects to https://router-api.0g.ai/v1 with X-0G-Provider-Trust-Mode: private (TeeML attested models like glm-5.3 / 0gm-1.0-35b-a3b).
  • Prompts wrap untrusted user text inside strict data delimiters. Even if a prompt injection fools the LLM into rating a scam as low risk, our applyEvidenceFloor function guarantees the final risk verdict can never drop below deterministic verifier evidence (link-intel, reputation, or payee-check mismatch).
  • Furthermore, we implemented Corroborated Verifier Trust (src/marketplace/trust.ts): a third-party verifier's lone high risk claim is weighed as medium unless corroborated by a second independent verifier, preventing a malicious verifier from DoS-blocking honest merchants.
  1. World ID Agent Pass (Dynamic OIDC Step-Up & Action Binding):
  • Using openid-client, Kavach requests dynamic OIDC acr assurance tiers matched to the payment's risk: max_age=0 + prompt=login for low-risk over-cap spend (fresh), orb for medium risk (human), and orb-face only to override high-risk blocks (strong).
  • Because standard OIDC lacks transaction-specific authorization_details, binding.rs stores a PendingApproval containing the SHA-256 hash of the canonical BoundAction (checkId, payee, resource, amount, verdictHash, version). On callback, the hash is recomputed against the live payment state (ACTION_CHANGED blocks mid-flight tampering) and transitioned from approved to consumed via a single atomic Postgres conditional UPDATE, making replay attacks impossible.
  • To allow full offline judging and CI testing before live credentials are injected, we also built a spec-compliant in-app OIDC Simulator (src/adapters/world/simulator.ts) that signs real RS256 JWTs with PKCE and exercises the exact same verification code path (source:simulated in audit logs).
background image mobile

Join the mailing list

Get the latest news and updates