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

x402-verify-client-base

v1.0.0

Published

Client-side verification library for x402 payments on Base (L2 on Ethereum)

Downloads

8

Readme

x402-verify-client-base

Client-side verification SDK for x402 payment headers on Base (L2 on Ethereum). Built with TypeScript and ethers v6, compatible with Node.js and modern browsers.

Features

  • ECDSA signature verification via ethers.verifyMessage()
  • Cross-platform Base64 decoding (Browser atob() / Node Buffer)
  • EIP-55 checksum address normalization with ethers.getAddress()
  • Replay protection hooks: maxAgeMs (timestamp window) and nonceSeen (nonce reuse)
  • Strict typings with PaymentHeader and a minimal, ergonomic API

Installation

npm install x402-verify-client-base

Quick Start

import { verifyPayment } from "x402-verify-client-base";

// Base64-encoded JSON header conforming to the PaymentHeader interface
const header = "<Base64 PaymentHeader JSON>";

const verified = verifyPayment(
  header,
  "0.001", // expected amount (ETH, decimal string)
  "0xRecipientAddress",
  { maxAgeMs: 60_000, nonceSeen: () => false }
);

console.log("Verified:", verified);

API Reference

verifyPayment(paymentHeader: string, expectedAmount: string, expectedAddress: string, options?: { maxAgeMs?: number; nonceSeen?: (nonce: string) => boolean }): boolean

Verifies an x402 payment header by:

  • Decoding Base64 JSON (browser atob() or Node Buffer.from(..., "base64"))
  • Building the signed message including optional nonce and timestamp
  • Recovering the signer using ethers.verifyMessage()
  • Normalizing addresses via ethers.getAddress()
  • Comparing amounts as wei using ethers.parseUnits(amount, 18)
  • Applying replay checks with options.maxAgeMs and options.nonceSeen

Returns true only if all checks pass; otherwise false.

Types

export interface PaymentHeader {
  amount: string;       // decimal ETH string (e.g., "0.001")
  to: string;           // recipient address
  from: string;         // signer (sender) address
  signature: string;    // hex string, 65-byte ECDSA signature (130 hex chars)
  nonce?: string;       // optional, for replay protection
  timestamp?: number;   // optional, ms since epoch
}

Verification Workflow

  1. Decode: Base64 → UTF‑8 JSON using atob() (browser) or Buffer (Node).
  2. Validate: Ensure required fields exist and types are correct.
  3. Build Message: Include amount, to, from, and optionally nonce/timestamp.
  4. Recover Signer: ethers.verifyMessage(message, signature).
  5. Normalize Addresses: ethers.getAddress() for EIP‑55 checksum normalization.
  6. Compare Amounts: parseUnits(payment.amount, 18) === parseUnits(expectedAmount, 18).
  7. Replay Checks: Reject if timestamp is older than maxAgeMs, or if nonceSeen(nonce) returns true.

Cross‑Platform Notes

  • Base64 decoding: Uses atob() in browsers and Buffer.from(header, "base64").toString("utf8") in Node.
  • Address normalization: ethers.getAddress() produces checksummed addresses for consistent comparisons.
  • Amount verification: Convert decimal ETH strings to wei via ethers.parseUnits(..., 18) and compare numerically.

Testing

Run the test suite (Vitest):

npm run test

Scenarios covered: valid signature, wrong amount, wrong recipient, and invalid signature.

Requirements

  • Node.js 18+ or a modern browser runtime
  • ethers v6
  • TypeScript 5+

Contact

License

MIT — see the separate LICENSE file for details.