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

@larkinsh/x402

v1.0.4

Published

Authorization middleware for the x402 agent payment protocol.

Readme

@larkinsh/x402

Authorization middleware for x402-paid APIs. One line of code wraps your handler; every paying wallet gets a 0-100 trust score and an Ed25519-signed receipt before your business logic runs.

Requirements

Node 18+ with ESM. This package is ESM-only — use import syntax, not require(). CJS callers can use dynamic import: const m = await import("@larkinsh/x402/next").

Install

npm i @larkinsh/x402

Next.js (App Router)

import { preflight } from "@larkinsh/x402/next";

export const GET = preflight(handler, {
  apiKey: process.env.LARKIN_API_KEY!,
  minScore: 40,
  mode: "block",
});

Hono

import { Hono } from "hono";
import { preflight } from "@larkinsh/x402/hono";

const app = new Hono();
app.use("/paid/*", preflight({ apiKey: process.env.LARKIN_API_KEY!, minScore: 40, mode: "block" }));
app.get("/paid/data", (c) => c.json({ ok: true }));

Express

import express from "express";
import { preflight } from "@larkinsh/x402/express";

const app = express();
app.use("/paid", preflight({ apiKey: process.env.LARKIN_API_KEY!, minScore: 40, mode: "block" }));
app.get("/paid/data", (_req, res) => res.json({ ok: true }));

Modes

| Mode | Behavior below minScore | |---|---| | block | Returns 403 payment_denied. Handler does not run. | | warn | Always runs the handler. Adds X-Larkin-Score, X-Larkin-Decision, X-Larkin-CheckId response headers. | | surcharge | Signals the x402 layer to multiply price (X-Larkin-Surcharge-Multiplier header) instead of denying. |

Error states

When the Larkin API returns an error rather than a decision, the SDK surfaces it as one of three outcomes (visible via the X-Larkin-Error response header in warn mode, and via a console.warn from the SDK in either mode):

| X-Larkin-Error | Meaning | |---|---| | service_unavailable | Larkin's API is unreachable (timeout, network error, 5xx). Block mode returns 503; warn mode runs the handler and adds the header. | | free_tier_exhausted | Your Larkin account has used its monthly Free-tier quota (10,000 checks). The SDK logs a console.warn containing the upgrade URL — https://larkin.sh/dashboard/billing. Block mode returns 503 (the trust gate is effectively unavailable until you upgrade); warn mode runs the handler with the header. Upgrade to keep block-mode endpoints serving. | | tier_hard_cap_exceeded | Your Pro or Scale account has hit its 2x hard cap (Pro: 1M/month, Scale: 10M/month). Pro and Scale tiers include 2x overage headroom over their stated limit before this fires. The SDK logs a console.warn with mailto:[email protected]. Block mode returns 503; warn mode runs the handler with the header. Email sales to right-size your plan. |

Options

| Option | Type | Required | Description | |---|---|---|---| | apiKey | string | yes | Your pf_live_* key from https://larkin.sh/dashboard. | | minScore | number | yes | Threshold (0-100) below which the chosen mode triggers. | | mode | "block" \| "warn" \| "surcharge" | yes | What to do when a wallet falls below minScore. | | surcharge | { below: number, multiplier: number } | only when mode === "surcharge" | Multiplier applied to the x402 price for sub-threshold wallets. | | requireERC8004 | boolean | no | If true, deny wallets without an ERC-8004 registration regardless of score. |

A note on naming

This package is @larkinsh/x402larkinsh is the npm scope (because larkin was taken at publish time), x402 because it adds authorization to x402-paid endpoints. The product is Larkin; the verb is preflight(). You'll see all three in the docs.

Why "preflight"?

The product is Larkin; the function is named preflight() because it describes the operation — a preflight check before the API responds. Stripe uses the same pattern (stripe.charges.create()).

Receipt verification

Every Larkin-issued receipt is independently verifiable forever using only the published public key. See @larkinsh/verify.

Documentation

Full docs: https://larkin.sh/docs Marketing site: https://larkin.sh Issues: https://github.com/larkin-dev/larkin/issues

License

MIT