npm.io
0.4.0 • Published 1h ago

@curless/agentbank-protocols

Licence
MIT
Version
0.4.0
Deps
1
Size
42 kB
Vulns
0
Weekly
492

@curless/agentbank-protocols

Agent-runtime client helpers for the agent-commerce protocols agentbank supports. One package, one subpath per protocol — import only what you actually use, no forced heavy deps.

Pair with @curless/agentbank-sdk on the agent's backend (API calls) and @curless/agentbank-merchant-sdk on the merchant's backend.

Subpaths

Subpath What it does Extra dep
/x402 Sign EIP-3009 transferWithAuthorization + auto-retry 402 with X-PAYMENT. viem (peer, optional)
/ap2 (planned) Local JWS signing for AP2 mandates.
/acp (planned, if needed) Delegated-token helpers.

/x402 quick start

npm i @curless/agentbank-protocols viem
import { payWithFetch, signerFromPrivateKey } from '@curless/agentbank-protocols/x402';

// async — viem loads lazily on first signing use
const signer = await signerFromPrivateKey(process.env.AGENT_PRIVATE_KEY as `0x${string}`);

// Auto-handle 402 → sign → retry. Just replace your fetch().
const res = await payWithFetch(
  'https://shop.example/api/buy/latte',
  { method: 'POST', body: JSON.stringify({ qty: 1 }) },
  { signer },
);
const order = await res.json();

signer is any viem LocalAccount-shaped object ({ address, signTypedData }), so an agent runtime can plug in an HSM or a Curless-managed wallet later without changing call sites.

Design

  • viem is a peer-dependency, marked optional, loaded lazily. Only code paths that actually SIGN (signX402Payment / signerFromPrivateKey) touch it — importing /x402 just to encode/decode X-PAYMENT headers works without viem installed at all.
  • Edge-safe: header encode/decode uses @curless/agentbank-core's portable base64 (no raw Buffer), so it runs on Workers / Deno.
  • One subpath per protocol keeps imports and discovery clean. Adding a protocol = adding a sibling folder, not a new npm package.

Replaces

This package replaces @curless/agentbank-x402-client@0.0.1 (deprecated). The wire shapes and exported symbols are identical; only the import path changed: from '@curless/agentbank-x402-client'from '@curless/agentbank-protocols/x402'.

Keywords