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

@x402-iota/core

v0.1.1

Published

Core types and utilities for x402-iota SDK

Readme

@x402-iota/core

Core types, utilities, and services for the x402 payment gateway SDK on IOTA blockchain.

Overview

This package provides the foundation for the x402 protocol implementation, including:

  • Types & Interfaces: Complete TypeScript definitions for x402 protocol
  • EIP-712 Utilities: Sign gasless transfers with EIP-712
  • EIP-3009 Support: Implement transferWithAuthorization
  • IOTA Network Helpers: RPC URLs, chain IDs, utilities
  • Payment Services: PaymentVerifier and PaymentSettler
  • Route Matching: Path pattern matching for protected routes

Installation

npm install @x402-iota/core
# or
pnpm add @x402-iota/core
# or
bun add @x402-iota/core

Quick Start

1. Import Types

import {
  PaymentRequirements,
  PaymentPayload,
  Network,
  ExactPayloadEVM,
} from "@x402-iota/core";

// Define payment requirements
const requirement: PaymentRequirements = {
  scheme: "exact",
  network: "iota-evm-testnet",
  maxAmountRequired: "1000000", // 1 USDC (6 decimals)
  resource: "/api/protected",
  description: "Access protected API",
  mimeType: "application/json",
  payTo: "0x1234567890123456789012345678901234567890",
  maxTimeoutSeconds: 3600,
  asset: "0xFbDa5F676cB37624f28265A144A48B0d6e87d3b6", // USDC on IOTA
  extra: {
    name: "USD Coin",
    version: "2",
  },
};

2. Use EIP-712 Signing

import { ethers } from "ethers";
import {
  signTransferAuthorization,
  createEIP712Domain,
  generateNonce,
} from "@x402-iota/core";

const wallet = new ethers.Wallet(privateKey, provider);
const domain = createEIP712Domain(requirement, 8822); // IOTA EVM chain ID

const authorization = {
  from: await wallet.getAddress(),
  to: requirement.payTo,
  value: requirement.maxAmountRequired,
  validAfter: Math.floor(Date.now() / 1000) - 60,
  validBefore: Math.floor(Date.now() / 1000) + 3600,
  nonce: generateNonce(),
};

const signature = await signTransferAuthorization(
  wallet,
  domain,
  authorization
);

// signature: { v: number; r: string; s: string }

3. Verify Payment

import { PaymentVerifier } from "@x402-iota/core";

const verifier = new PaymentVerifier({
  facilitatorUrl: "http://localhost:3001",
  onChainVerification: false, // Use facilitator
});

const isValid = await verifier.verifyPayment(paymentHeader, requirement);
console.log("Payment valid:", isValid);

API Reference

Types

Network

type Network =
  | "iota-mainnet" // L1 Move chain
  | "iota-testnet" // L1 testnet
  | "iota-evm-mainnet" // L2 EVM (Chain ID: 8822)
  | "iota-evm-testnet"; // L2 testnet (Chain ID: 1075)

PaymentRequirements

interface PaymentRequirements {
  scheme: "exact" | "upto";
  network: Network;
  maxAmountRequired: string; // uint256 as string
  resource: string; // API endpoint
  description: string; // Human-readable
  mimeType: string; // Content type
  payTo: string; // Recipient address
  maxTimeoutSeconds: number; // Payment timeout
  asset: string; // Token contract address
  extra?: {
    name?: string; // EIP-712 token name
    version?: string; // EIP-712 version
  };
}

Functions

generateNonce(): string

Generate cryptographically secure random nonce (32 bytes).

const nonce = generateNonce();
// '0x0f3e4c9a8b2d7f1e6a3c5b9d2f4e8a1c3b7f0d2e5a8c1f4b9e2a5c8f1d4e7a'

getChainId(network: Network): number

Get IOTA chain ID for network.

const chainId = getChainId("iota-evm-testnet");
// 1075

getRpcUrl(network: Network): string

Get RPC URL for network.

const rpcUrl = getRpcUrl("iota-evm-mainnet");
// 'https://json-rpc.evm.iotaledger.net'

matchRoute(path: string, routes: Record<string, RouteConfig>): RouteConfig | null

Match request path against route patterns.

const routes = {
  "/api/protected": { amount: "1000000" },
  "/api/premium/*": { amount: "5000000" },
};

const config = matchRoute("/api/premium/data", routes);
// { amount: '5000000' }

Services

PaymentVerifier

const verifier = new PaymentVerifier({
  facilitatorUrl: "http://localhost:3001",
  onChainVerification: false,
});

const isValid = await verifier.verifyPayment(paymentHeader, requirement);

PaymentSettler

const settler = new PaymentSettler({
  facilitatorUrl: "http://localhost:3001",
});

const result = await settler.settlePayment(paymentHeader, requirement);
// { success: boolean; error?: string; txHash?: string }

Related Packages

License

MIT