402Revnuvo/ developersGitHub

@revnuvo/x402

v0.1.4

A client-side TypeScript SDK for the x402 payment protocol. Signs EIP-3009 TransferWithAuthorization payloads and builds the exact X-Payment header Revnuvo's gateway expects — without touching raw signatures.

Installation

npm install @revnuvo/x402

Quick start

Request a resource, get a 402 challenge, sign it, and retry — end to end:

index.ts
import { buildXPaymentHeader } from "@revnuvo/x402";

const RESOURCE = "https://assess.revnuvo.site/assess/domain";
const privateKey = process.env.PRIVATE_KEY as `0x${string}`;

// 1. Request the resource — no payment yet
const quoteRes = await fetch(RESOURCE, {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ domain: "example.com" }),
});

// 2. Get the 402 challenge, sign it
const challenge = await quoteRes.json();
const xPaymentHeader = await buildXPaymentHeader({ challenge, privateKey });

// 3. Retry with the signed payment
const paidRes = await fetch(RESOURCE, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "X-Payment": xPaymentHeader,
  },
  body: JSON.stringify({ domain: "example.com" }),
});

const data = await paidRes.json();
console.log(data.trust_score);

Lower-level: sign a payment directly

If you need the raw signed authorization instead of a ready-to-send header:

sign.ts
import { signPayment } from "@revnuvo/x402";

const { domain, message, signature } = await signPayment({
  privateKey: process.env.PRIVATE_KEY as `0x${string}`,
  chainId: 8453,
  usdc: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
  payTo: "0x2aaD494F3f2f3f30E464cB84442924d764f19CE7",
  amount: 50000n, // atomic units — 0.05 USDC at 6 decimals
});

Class-based API

X402Client wraps the same flow if you prefer a stateful client over calling functions directly:

client.ts
import { X402Client } from "@revnuvo/x402";

const client = new X402Client({ privateKey: process.env.PRIVATE_KEY as `0x${string}` });
const data = await client.pay("https://assess.revnuvo.site/assess/domain", {
  domain: "example.com",
});

Release notes

v0.1.4

Corrects buildXPaymentHeader and X402Client to sign with TransferWithAuthorization, matching the gateway's on-chain settlement call. v0.1.3 fixed this only for signPayment — the other two export paths still signed with the wrong type and would fail at settlement. If you installed 0.1.3, upgrade to 0.1.4.

v0.1.3

Partial fix — corrected signPayment only.