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

@zbdpay/agent-pay

v1.0.3

Published

L402 middleware foundation with Express, Hono, and Next adapters

Readme

@zbdpay/agent-pay

Framework adapters and core logic for L402 payment-gated HTTP routes.

Supports:

  • Express middleware
  • Hono middleware
  • Next.js route wrapper (@zbdpay/agent-pay/next)

Want to run this immediately? See Examples (Fastest Way to Run).

Requirements

  • Node.js >=22
  • npm

Install

npm install @zbdpay/agent-pay

Quick Start

Express

import express from "express";
import { createExpressPaymentMiddleware } from "@zbdpay/agent-pay";

const app = express();

app.get(
  "/protected",
  createExpressPaymentMiddleware({
    amount: 21,
    apiKey: process.env.ZBD_API_KEY,
  }),
  (_req, res) => {
    res.json({ ok: true });
  },
);

Hono

import { Hono } from "hono";
import { createHonoPaymentMiddleware } from "@zbdpay/agent-pay";

const app = new Hono();

app.use(
  "/protected",
  createHonoPaymentMiddleware({
    amount: 21,
    apiKey: process.env.ZBD_API_KEY,
  }),
);

Next.js Route Handlers

import { withPaymentRequired } from "@zbdpay/agent-pay/next";

export const GET = withPaymentRequired(
  {
    amount: 21,
    apiKey: process.env.ZBD_API_KEY,
  },
  async () => Response.json({ ok: true }),
);

Config (PaymentConfig)

  • amount: number or async resolver function
  • currency: "SAT" | "USD" (default "SAT")
  • apiKey: optional, falls back to ZBD_API_KEY
  • tokenStorePath: optional, defaults to ~/.zbd-wallet/server-tokens.json

Runtime Environment

  • ZBD_API_KEY: required unless passed via config
  • ZBD_API_BASE_URL: optional, default https://api.zbdpay.com

Examples (Fastest Way to Run)

Use this local script path first to validate your environment before integrating middleware into your app.

  • examples/http-server.mjs: minimal Node HTTP server using createPaymentMiddlewareFoundation

Run locally from this repo:

npm run build
ZBD_API_KEY=<your_api_key> npm run example:http-server

Enable verbose host-side debug logs:

ZBD_PAY_DEBUG=1 ZBD_API_KEY=<your_api_key> npm run example:http-server

In a second terminal, consume the paid route with your local wallet CLI:

zbdw fetch "http://localhost:8787/protected" --max-sats 100

L402 Flow

When a request has no valid auth proof:

  1. Middleware creates a charge (/v0/charges)
  2. Returns 402 with:
    • JSON body: payment_required + challenge fields
    • WWW-Authenticate header: L402 macaroon="...", invoice="..."

When a request has auth proof:

  1. Parse Authorization (L402 or LSAT)
  2. Verify signed macaroon payload
  3. Verify resource path, amount, expiry, payment hash
  4. Confirm charge settlement via ZBD API
  5. Allow or deny request

Error Codes

error.code may be:

  • configuration_error
  • payment_required
  • invalid_credential
  • invalid_payment_proof
  • resource_mismatch
  • amount_mismatch
  • token_expired
  • pricing_error
  • invoice_creation_failed

Exports

Main package:

  • createExpressPaymentMiddleware
  • createHonoPaymentMiddleware
  • createPaymentMiddlewareFoundation
  • AgentPayError
  • createConfigurationError
  • related TS types

Subpath export:

  • @zbdpay/agent-pay/next -> withPaymentRequired

Scripts

npm run build
npm run test
npm run lint
npm run typecheck
npm run smoke:adapters
npm run example:http-server
npm run release:dry-run

Notes

  • Middleware stores verified settled tokens in a local file token store by default.
  • For production, set tokenStorePath to durable storage if required by your deployment model.