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

@hauska-sdk/payment

v0.1.0

Published

CNS Protocol Payment SDK - x402 protocol implementation

Readme

@hauska-sdk/payment

CNS Protocol Payment SDK - x402 protocol implementation for crypto and fiat payments.

Installation

npm install @hauska-sdk/payment

Quick Start

import { PaymentSDK } from "@hauska-sdk/payment";
import { MockStorageAdapter } from "@hauska-sdk/adapters-storage-mock";
import { WalletManager } from "@hauska-sdk/wallet";

// Initialize SDK
const sdk = new PaymentSDK({
  walletManager: new WalletManager(),
  blockchain: {
    chain: "base",
    token: "USDC",
    facilitatorWallet: "0xYourFacilitatorWallet",
    baseRpcUrl: "https://mainnet.base.org",
  },
  storage: new MockStorageAdapter(), // Use PostgreSQL adapter in production
});

// Generate payment request
const response = await sdk.generate402Response({
  resourceId: "invoice-123",
  amount: "450000", // $450.00 USDC (6 decimals)
  currency: "USDC",
  expiresAt: Date.now() + 3600000, // 1 hour
});

// Return 402 response to client
res.status(402).json(response.body);

Features

  • HTTP 402 Response Generation - x402 protocol support
  • Crypto Payment Verification - USDC on Base L2
  • Automatic Wallet Creation - Seamless wallet management
  • Payment Record Storage - Audit trail and duplicate prevention
  • EIP-712 Signing - Standard typed data signing

API Reference

PaymentSDK

Main SDK class that provides all payment functionality.

Constructor

new PaymentSDK(config: PaymentSDKConfig)

Methods

generate402Response(request: PaymentRequest): Promise<HTTP402Response>

Generate HTTP 402 Payment Required response.

const response = await sdk.generate402Response({
  resourceId: "invoice-123",
  amount: "450000",
  currency: "USDC",
  expiresAt: Date.now() + 3600000,
});
verifyPayment(proof: PaymentVerificationProof): Promise<PaymentVerificationResult>

Verify a crypto payment transaction.

const result = await sdk.verifyPayment({
  txHash: "0x...",
  fromAddress: "0x...",
  toAddress: "0x...",
  amount: "450000",
  chainId: 8453, // Base
});

if (result.verified) {
  // Payment verified!
}
recordPayment(record): Promise<PaymentRecord>

Record a payment in storage.

const record = await sdk.recordPayment({
  resourceId: "invoice-123",
  amount: "450000",
  currency: "USDC",
  method: "crypto",
  txHash: "0x...",
  fromAddress: "0x...",
  toAddress: "0x...",
});
processPaymentFlow(params): Promise<{response, verification, record}>

Complete payment flow: Generate 402 → Verify → Record.

const flow = await sdk.processPaymentFlow({
  request: {
    resourceId: "invoice-123",
    amount: "450000",
    currency: "USDC",
    expiresAt: Date.now() + 3600000,
  },
  verificationProof: {
    txHash: "0x...",
    fromAddress: "0x...",
    toAddress: "0x...",
    amount: "450000",
    chainId: 8453,
  },
});
createWalletIfNeeded(userId: string, password: string): Promise<string>

Create wallet automatically if user doesn't have one.

const walletAddress = await sdk.createWalletIfNeeded("user-123", "password");

Configuration

interface PaymentSDKConfig {
  walletManager?: WalletManager;
  blockchain?: {
    chain: "base" | "ethereum" | "polygon";
    token: "USDC" | "USDT";
    facilitatorWallet: string;
    baseRpcUrl?: string;
  };
  fiat?: {
    provider: "circle";
    apiKey: string;
  };
  storage?: StorageAdapter;
}

Examples

Express.js Integration

import express from "express";
import { PaymentSDK } from "@hauska-sdk/payment";

const app = express();
const sdk = new PaymentSDK({
  // ... config
});

app.post("/api/payment/request", async (req, res) => {
  const response = await sdk.generate402Response({
    resourceId: req.body.invoiceId,
    amount: req.body.amount,
    currency: "USDC",
    expiresAt: Date.now() + 3600000,
  });

  res.status(402).json(response.body);
});

app.post("/api/payment/verify", async (req, res) => {
  const result = await sdk.verifyPayment({
    txHash: req.body.txHash,
    fromAddress: req.body.fromAddress,
    toAddress: req.body.toAddress,
    amount: req.body.amount,
    chainId: 8453,
  });

  if (result.verified) {
    await sdk.markPaymentVerified(req.body.resourceId, {
      txHash: req.body.txHash,
    });
    res.json({ success: true });
  } else {
    res.status(400).json({ error: result.error });
  }
});

License

MIT