@notary402/x402
v0.1.0
Published
Audit & compliance wrapper for x402 payments. Budget enforcement, audit logging, and spike detection for AI agent micropayments.
Downloads
30
Maintainers
Readme
@notary402/x402
Audit & compliance wrapper for x402 payments. Budget enforcement, audit logging, and spike detection for AI agent micropayments.
Install
npm install @notary402/x402Quick Start
import { wrapWithNotary, standardPolicy } from "@notary402/x402";
const fetch = wrapWithNotary(x402Fetch, {
agentId: "researcher-01",
budget: standardPolicy(),
});
// Every payment is now tracked, budget-enforced, and audit-logged
const res = await fetch("https://api.example.com/data");Budget Policies
import { standardPolicy, conservativePolicy, permissivePolicy } from "@notary402/x402";
// Standard: $1/call, $25/hr, $100/day, $1000 total
standardPolicy()
// Conservative: $0.10/call, $5/hr, $20/day, $200 total
conservativePolicy()
// Permissive: $10/call, $100/hr, $500/day, $10000 total
permissivePolicy()
// Custom
standardPolicy({
perCall: 0.5,
hourly: 10,
allowlist: ["https://api.example.com/*"],
})Stateful Client
import { NotaryClient, standardPolicy } from "@notary402/x402";
const notary = new NotaryClient({
agentId: "researcher-01",
budget: standardPolicy(),
onAuditEvent: (event) => console.log(event),
});
const fetch = notary.wrap(x402Fetch);
await fetch("https://api.example.com/data");
// Check stats
console.log(notary.stats());
// { totalPayments: 1, totalSpent: 0.002, ... }
// Export audit log
const csv = notary.exportCSV();Webhook Integration
const fetch = wrapWithNotary(x402Fetch, {
agentId: "researcher-01",
budget: standardPolicy(),
webhookUrl: "https://hooks.slack.com/services/...",
});Error Handling
import { BudgetExceededError, EndpointBlockedError } from "@notary402/x402";
try {
await fetch("https://api.example.com/data");
} catch (err) {
if (err instanceof BudgetExceededError) {
console.log(`Budget exceeded: ${err.policy} limit $${err.limit}`);
}
if (err instanceof EndpointBlockedError) {
console.log(`Endpoint blocked: ${err.url}`);
}
}License
MIT
