npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@x402guard/core

v0.1.0

Published

TypeScript SDK for x402Guard — non-custodial safety proxy for AI agents making x402 DeFi payments. Spend limits, contract whitelists, session keys, instant revoke.

Readme

@x402guard/core

TypeScript SDK for x402Guard proxy — types, HTTP client, errors, retry.

Installation

npm install @x402guard/core

Requires Node.js 22+.

Quick Start

import {
  X402GuardClient,
  GuardrailViolationError,
  ProxyUnreachableError,
} from "@x402guard/core";

const client = new X402GuardClient({
  proxyUrl: "http://localhost:3001",
  agentId: "my-agent-uuid",
});

// Check proxy connectivity
const alive = await client.healthCheck();

// Register an agent
const agent = await client.createAgent({
  name: "trading-bot",
  owner_address: "0xYourEoaAddress",
});

// Add a guardrail rule — cap each payment at 1 USDC (6 decimals)
await client.createRule(agent.id, {
  rule_type: {
    type: "MaxSpendPerTx",
    params: { limit: 1_000_000 },
  },
});

// Route a payment through the proxy
try {
  const result = await client.proxyPayment({
    targetUrl: "https://api.example.com/service",
    x402Payment: "<signed-payment-header>",
    x402Requirements: "<requirements-header>",
    agentId: agent.id,
  });
  console.log("tx:", result.txHash);
} catch (err) {
  if (err instanceof GuardrailViolationError) {
    // ruleType, limit, actual are parsed from the proxy response
    console.error(`Blocked by ${err.ruleType}: actual=${err.actual} limit=${err.limit}`);
  } else if (err instanceof ProxyUnreachableError) {
    console.error("Proxy is down");
  }
}

API Reference

X402GuardClient

All methods are async and return typed values.

| Method | Signature | Description | |--------|-----------|-------------| | healthCheck | () => Promise<boolean> | Returns true if proxy returns 200 on GET /health | | createAgent | (req: CreateAgentRequest) => Promise<Agent> | Register a new agent | | getAgent | (id: string) => Promise<Agent> | Fetch an agent by ID | | createRule | (agentId, rule: CreateRuleRequest) => Promise<GuardrailRule> | Add a guardrail rule | | listRules | (agentId: string) => Promise<readonly GuardrailRule[]> | List rules for an agent | | createSessionKey | (agentId, req: CreateSessionKeyRequest) => Promise<SessionKey> | Issue a session key (EIP-7702) | | listSessionKeys | (agentId: string) => Promise<readonly SessionKey[]> | List session keys | | getSessionKey | (agentId, keyId: string) => Promise<SessionKey> | Fetch a single session key | | revokeSessionKey | (agentId, keyId: string) => Promise<void> | Revoke a session key | | revokeAll | (agentId, req: RevokeAllRequest) => Promise<RevokeAllResponse> | Revoke all keys and deactivate agent | | proxyPayment | (req: ProxyRequest) => Promise<ProxyResponse> | Route an EVM x402 payment | | proxySolanaPayment | (req: SolanaProxyRequest) => Promise<SolanaProxyResponse> | Route a Solana x402 payment |

Errors

| Class | HTTP status | When thrown | |-------|-------------|-------------| | X402GuardError | any | Base class for all SDK errors | | GuardrailViolationError | 403 | A guardrail rule blocked the payment. Has ruleType, limit, actual fields. | | ProxyUnreachableError | — | Network failure reaching the proxy | | RateLimitedError | 429 | Too many requests. Has retryAfter (seconds). | | SessionKeyExpiredError | 403 | The referenced session key has expired |

Types (main exports)

| Type | Description | |------|-------------| | Agent | Registered agent record | | GuardrailRule | A single guardrail rule with discriminated RuleType | | RuleType | Union: MaxSpendPerTx, MaxSpendPerDay, AllowedContracts, MaxLeverage, MaxSlippage | | SessionKey | EIP-7702 session key record | | ProxyRequest / ProxyResponse | EVM payment proxy payload | | SolanaProxyRequest / SolanaProxyResponse | Solana payment proxy payload | | X402GuardConfig | Client configuration (validated via Zod) | | ApiResponse<T> / ApiListResponse<T> | Response envelope types |

Utilities

| Export | Description | |--------|-------------| | fetchWithRetry | Fetch wrapper with exponential back-off on 429/network errors | | createLogger | Create a pino logger scoped to a component name | | x402GuardConfigSchema | Zod schema for X402GuardConfig |

Configuration

The client accepts a partial X402GuardConfig object. Missing fields fall back to environment variables:

| Option | Env var | Default | Description | |--------|---------|---------|-------------| | proxyUrl | X402GUARD_PROXY_URL | required | Base URL of the x402Guard proxy | | agentId | X402GUARD_AGENT_ID | — | Default agent ID for requests | | logLevel | — | "info" | Pino log level | | maxRetries | — | 3 | Retry attempts on 429/network errors | | retryBaseMs | — | 1000 | Base delay (ms) for exponential back-off |

// Via constructor options
const client = new X402GuardClient({ proxyUrl: "http://localhost:3001" });

// Via environment variables
// X402GUARD_PROXY_URL=http://localhost:3001
const client = new X402GuardClient();

Development

npm install
npm test          # vitest (unit tests)
npm run typecheck # tsc --noEmit
npm run build     # tsup -> dist/

License

MIT