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

nexuspay-mpp-adapter

v1.0.0

Published

One-liner MPP paywall wrapper for Next.js — powered by NexusPay USDC

Readme

nexuspay-mpp-adapter

One-liner MPP paywall wrapper for Next.js — powered by NexusPay USDC.

npm version License: MIT

Add a machine-payable paywall to any Next.js API route in one line. AI agents pay in USDC via the Machine Payments Protocol (MPP) and receive immediate access. No accounts, no API keys for them — just USDC on Base.


How it works

Agent hits your endpoint
    ↓
Adapter returns 402 + WWW-Authenticate: Payment challenge
    ↓
Agent calls NexusPay POST /api/mpp/pay  (or nexuspay_mpp_pay MCP tool)
    ↓
NexusPay deducts USDC from agent wallet, returns Authorization: Payment credential
    ↓
Agent retries your endpoint with the credential
    ↓
Adapter verifies transaction via NexusPay API → returns 200 + Payment-Receipt

Installation

npm install nexuspay-mpp-adapter

Quick Start

App Router (Next.js 13+)

// app/api/inference/route.ts
import { withMpp } from "nexuspay-mpp-adapter";

async function handler(req: Request) {
  const body = await req.json();
  return Response.json({ result: `Processed: ${body.prompt}` });
}

// Wrap with 10-cent paywall
export const POST = withMpp(handler, { price: 0.10 });

// Different prices per method
export const GET  = withMpp(handler, { price: 0.05 });

Pages Router (Next.js 12 and below)

// pages/api/inference.ts
import { withMppPages } from "nexuspay-mpp-adapter";

export default withMppPages(
  async (req, res) => {
    res.json({ result: "premium data" });
  },
  { price: 0.10 }
);

Environment Variables

Add these to your .env.local:

# HMAC key for signing challenges — must be secret and random
# Generate: openssl rand -hex 32
NEXUSPAY_MPP_SECRET=your-32-char-hex-secret

# Your NexusPay instance URL
NEXUSPAY_URL=https://nexuspay.finance

# API key from NexusPay dashboard (needs transactions:read scope)
NEXUSPAY_API_KEY=npk_live_...

# Optional: realm shown in the challenge header (defaults to your app URL hostname)
NEXUSPAY_MPP_REALM=yourdomain.com

Configuration Options

withMpp(handler, {
  price: 0.10,           // Required: price in USDC

  realm: "api.myapp.com",         // Optional: realm in the challenge header
  challengeTtlMs: 300_000,        // Optional: challenge TTL (default: 5 min)
  maxPrice: 10.00,                // Optional: throws at startup if price > maxPrice (safety)

  nexuspayUrl: "https://...",     // Optional: override NEXUSPAY_URL env var
  apiKey: "npk_live_...",         // Optional: override NEXUSPAY_API_KEY env var

  replayStore: myRedisStore,      // Optional: custom replay store (see below)
});

Agent Usage

Agents using the NexusPay MCP server get this for free:

User: Fetch the premium inference data from https://api.myapp.com/api/inference
Claude: (calls nexuspay_mpp_pay with the URL and agent wallet)
        → pays the 402 automatically
        → returns the response body

Agents using the NexusPay SDK directly:

import { mppPay } from "nexuspay-sdk";

const result = await mppPay({
  agentId: "my-agent",
  url: "https://api.myapp.com/api/inference",
  method: "POST",
  body: JSON.stringify({ prompt: "hello" }),
  maxAmount: 1.00,
});

Multi-Instance Deployments

By default, replay protection is in-process (single server). For multiple instances or serverless, provide a Redis-backed replay store:

import { withMpp, type ReplayStore } from "nexuspay-mpp-adapter";
import { createClient } from "redis";

const redis = createClient({ url: process.env.REDIS_URL });
await redis.connect();

const redisReplayStore: ReplayStore = {
  async has(id: string) {
    return (await redis.exists(`mpp:used:${id}`)) === 1;
  },
  async add(id: string, ttlMs: number) {
    await redis.set(`mpp:used:${id}`, "1", { PX: ttlMs });
  },
};

export const POST = withMpp(handler, {
  price: 0.10,
  replayStore: redisReplayStore,
});

Response Headers

On success, your handler's response is augmented with:

Payment-Receipt: <base64url-encoded receipt JSON>

The receipt contains:

{
  "method": "nexuspay",
  "reference": "<transactionId>",
  "timestamp": "2025-01-01T00:00:00.000Z",
  "agentId": "agent-researcher",
  "amountUsdc": 0.10
}

Error Responses

All errors follow RFC 9457 Problem Details format.

| Status | type | Cause | |--------|------|-------| | 402 | payment-required | No Authorization header — agent must pay | | 402 | payment-insufficient | Payment amount < required price | | 401 | malformed-credential | Can't parse Authorization header | | 401 | verification-failed | Transaction not found, not CONFIRMED, or already used |


License

MIT — NexusPay