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

ap2-payment-handler

v1.0.0

Published

Non-custodial crypto payment handler for the AP2 Agent Payment Protocol. Supports x402, USDC/Base, EIP-712 signing. Zero key escrow.

Readme

ap2-payment-handler

Non-custodial crypto payment handler for the AP2 Agent Payment Protocol. The first open-source, zero-escrow AP2 implementation.

npm version License: MIT

What is AP2?

AP2 (Agent Payment Protocol) is Google's emerging standard for agentic commerce — enabling AI agents to negotiate and execute payments autonomously on behalf of users. This package implements the AP2 mandate lifecycle with a non-custodial, crypto-native approach.

Installation

npm install ap2-payment-handler

Quick Start

import { AP2PaymentHandler } from 'ap2-payment-handler';

const handler = new AP2PaymentHandler({
  supportedMethods: ['usdc_base', 'x402'],
});

// Create an intent mandate (agent-initiated)
const mandate = handler.createIntentMandate({
  agentId: 'my-agent-001',
  merchantId: 'merchant-xyz',
  maxAmount: 10.0,
  currency: 'USDC',
  ttl: Date.now() + 5 * 60_000, // 5 minutes
});

// Process payment
const response = await handler.handle({
  mandate,
  preferredMethod: 'usdc_base',
});

if (response.success) {
  console.log('Payment initiated:', response.transactionId);
  console.log('Audit trail:', response.paymentMandate?.auditTrail);
}

Cart Payments

const cartMandate = handler.createCartMandate({
  agentId: 'my-agent-001',
  lineItems: [
    { name: 'API Credits', price: 5.0, qty: 2 },
    { name: 'Priority Queue', price: 3.0, qty: 1 },
  ],
  total: 13.0,
  currency: 'USDC',
});

const response = await handler.handle({
  mandate: cartMandate,
  preferredMethod: 'usdc_base',
});

HTTP 402 Payment Required (x402)

import { X402Bridge } from 'ap2-payment-handler';

const bridge = new X402Bridge();

// When your agent receives a 402 response
const paymentResponse = await bridge.handleResponse({
  status: 402,
  headers: response.headers,
});

if (paymentResponse) {
  // Build proof and retry request
  const proof = await bridge.buildPaymentProof({
    amount: '5.00',
    currency: 'USDC',
    address: '0x...',
    agentId: 'my-agent-001',
  });
}

Supported Payment Methods

| Method | Network | Description | |--------|---------|-------------| | usdc_base | Base (Coinbase L2) | USDC on Base — low fees, fast finality | | x402 | Any | HTTP 402 Payment Required flow | | usdc_arbitrum | Arbitrum | USDC on Arbitrum One | | usdc_optimism | Optimism | USDC on Optimism |

Non-Custodial Design

This package is zero-escrow by design:

  • No private keys stored — signing is delegated to your wallet/signer
  • No funds held — payment proofs reference on-chain transactions
  • Full audit trail — every mandate lifecycle step is logged
  • EIP-712 compatible — structured signing for human-readable approval

All PaymentMandate objects carry isNonCustodial: true as a type-level guarantee.

API Reference

AP2PaymentHandler

  • constructor({ supportedMethods }) — initialize with supported payment methods
  • handle(request) — process an AP2 payment request
  • createIntentMandate(params) — create an agent-initiated intent mandate
  • createCartMandate(params) — create a cart mandate from line items
  • getSupportedMethods() — list configured methods

X402Bridge

  • parsePaymentRequired(headers) — extract payment details from 402 headers
  • buildPaymentProof(params) — create a non-custodial payment proof
  • handleResponse(response) — handle HTTP responses, returns AP2PaymentResponse for 402

validateMandate(mandate)

Validates a mandate and throws AP2ValidationError on failure.

License

MIT © AI Agent Economy