sovroute-guard
v0.1.0
Published
Deterministic pre-sign firewall, rolling-window budget lock, and EIP-7702/x402 guardrails for autonomous agents.
Maintainers
Readme
sovroute-guard
Deterministic pre-sign firewall, rolling-window budget lock, and EIP-7702 / x402 guardrails for autonomous AI agents. Zero runtime dependencies; runs in Node.js, Bun, Cloudflare Workers, and browsers.
Why?
Production agentic payment rails suffer from four recurring failure modes:
- Parallel race double-spends (
x402#4198) — two concurrent calls 20 ms apart pass client-side checks and sign separate nonces. - Multi-replica & calendar-reset budget bypasses — process-local counters reset on restart or diverge across replicas; unpriced tokens (e.g.
EURC) get logged as$0. - EIP-7702 & unlimited approval traps — blind delegation or
MAX_UINT256ERC-20 / Permit2 approvals drain wallets. - Misordered seller x402 offers — agents pick a
$1.00mainnet offer placed first instead of a policy-compliant$0.01offer.
sovroute-guard isolates LLM reasoning to the advisory layer and enforces signing rules deterministically before any private key or enclave is invoked.
3-Line Quickstart
import { createPreSignFirewall, guardSigner } from "sovroute-guard";
const firewall = createPreSignFirewall({
maxRolling24hAtomicUsd6: 150_000_000n, // $150.00 rolling 24h cap (atomic 6-dec USD)
maxPerCallAtomicUsd6: 5_000_000n, // $5.00 max per call
allowedNetworks: ["eip155:8453"], // Base mainnet only
allowedRecipients: ["0x488cbDad29E60d8Bae53FFF4c4252C9711dF9784"],
});
const safeSign = guardSigner(firewall, (intent) => wallet.signAndPay(intent));If the wrapped signer throws (e.g. RPC timeout), guardSigner automatically releases the budget hold so retries do not burn quota.
Safe x402 Offer Selection
const best = firewall.selectBestX402Offer(paymentRequired.accepts);
if (!best) throw new Error("No policy-compliant x402 payment offer");Multi-Replica Production Store
By default, InMemoryBudgetStore provides atomic single-process locking and CAIP-10 wallet normalization. For multi-replica deployments, pass a custom BudgetStore backed by Redis, Postgres, or a Cloudflare Durable Object implementing acquireHold, commitHold, and releaseHold.
License
Apache-2.0
