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 🙏

© 2025 – Pkg Stats / Ryan Hefner

x402s

v0.1.0

Published

HTTP 402 payment protocol integration for Shelby Protocol on Aptos - Built on x402a infrastructure

Readme

x402s

HTTP 402 Payment Required integration for Shelby Protocol on Aptos blockchain.

Built on top of x402a, x402s bridges Aptos micropayments with Shelby's session-based storage and compute access system.

Features

  • ✅ Accept x402a payments and convert to Shelby sessions
  • ✅ Session management with automatic chunkset tracking
  • ✅ React hooks for client-side integration
  • ✅ Next.js middleware (coming in x402s-next)
  • ✅ Full TypeScript support
  • ✅ Built on Aptos blockchain

Installation

npm install x402s x402a @shelby-protocol/sdk @aptos-labs/ts-sdk

Quick Start

Server-side (Gateway)

import { X402Facilitator } from 'x402a/server';
import { ShelbyNodeClient, Network } from '@shelby-protocol/sdk/node';
import { ShelbyGateway } from 'x402s/server';

const gateway = new ShelbyGateway({
  facilitator: new X402Facilitator({
    privateKey: process.env.FACILITATOR_PRIVATE_KEY!,
    contractAddress: process.env.CONTRACT_ADDRESS!,
  }),
  shelbyClient: new ShelbyNodeClient({
    network: Network.SHELBYNET,
    apiKey: process.env.SHELBY_API_KEY!,
  }),
  pricing: {
    octasPerChunkset: "100000", // 0.001 APT per chunkset
    minPaymentOctas: "1000000", // 0.01 APT minimum
    maxChunksetsPerSession: 1000,
  }
});

// Accept payment and create session
const result = await gateway.createSessionFromPayment({
  userAddress: "0x123...",
  authenticator: signedAuthenticator,
  nonce: "...",
  validUntil: 1234567890,
  chainId: 2, // testnet
  transaction: "0x...",
});

console.log(`Session created: ${result.session?.sessionId}`);
console.log(`Chunksets: ${result.session?.chunksetsRemaining}`);

Client-side (React)

import { useShelbySession } from 'x402s/client';
import { useWallet } from '@aptos-labs/wallet-adapter-react';

function MyComponent() {
  const { signTransaction } = useWallet();

  const {
    session,
    createSession,
    needsRefill,
    isCreating
  } = useShelbySession({
    createSessionEndpoint: '/api/shelby/sessions',
    getSessionEndpoint: '/api/shelby/sessions',
    onLowChunksets: (remaining) => {
      alert(`Only ${remaining} chunksets remaining!`);
    }
  });

  const handlePayment = async () => {
    // 1. Get transaction from facilitator
    const txResponse = await fetch('/api/facilitator/build', {
      method: 'POST',
      body: JSON.stringify({
        from: userAddress,
        to: recipientAddress,
        amount: "10000000", // 0.1 APT
      })
    });
    const { transactionPayload } = await txResponse.json();

    // 2. Sign with wallet
    const authenticator = await signTransaction(transactionPayload);

    // 3. Create session
    await createSession({
      userAddress,
      authenticator,
      ...transactionPayload
    });
  };

  return (
    <div>
      {needsRefill ? (
        <button onClick={handlePayment} disabled={isCreating}>
          {isCreating ? 'Processing...' : 'Pay to Access'}
        </button>
      ) : (
        <div>
          <p>Active session</p>
          <p>Chunksets remaining: {session?.chunksetsRemaining}</p>
        </div>
      )}
    </div>
  );
}

Architecture

┌─────────────┐
│   Client    │  useShelbySession hook
│  (Browser)  │
└──────┬──────┘
       │ x402a payment
       ▼
┌─────────────────┐
│  ShelbyGateway  │  Verifies payment + creates session
│  (Next.js API)  │
└────────┬────────┘
         │
         ├─────────► x402a Facilitator (Aptos blockchain)
         │           └─ Submit transaction
         │           └─ Pay gas fees
         │
         └─────────► Shelby API
                     └─ Create session
                     └─ Track chunksets

Payment Flow

  1. Client requests access to protected resource
  2. Server returns 402 with payment requirements
  3. Client pays via x402a (signs transaction, facilitator submits)
  4. Gateway verifies payment on Aptos blockchain
  5. Gateway creates Shelby session with purchased chunksets
  6. Client uses session to access Shelby storage/compute
  7. Session auto-refreshes to track chunkset consumption

Pricing

You configure the conversion rate between APT and Shelby chunksets:

pricing: {
  octasPerChunkset: "100000",     // 0.001 APT = 1 chunkset
  minPaymentOctas: "1000000",     // 0.01 APT minimum payment
  maxChunksetsPerSession: 1000,   // Cap per session
}

Example: 0.1 APT payment = 100 chunksets

Status

Status: Experimental (v0.1.0) Network: Testnet only Production: Not recommended for production use with real funds

Packages

  • x402s - Core SDK (this package)
  • x402s-next - Next.js middleware (coming soon)

License

MIT

Links