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

@tanakayuto/intmax402-fetch

v0.2.2

Published

Web標準の `Request`/`Response` で動く INTMAX402 認証アダプター。

Downloads

692

Readme

@tanakayuto/intmax402-fetch

Web標準の Request/Response で動く INTMAX402 認証アダプター。

Hono、Next.js、Cloudflare Workers など、すべての fetch ベースフレームワークで使える共通基盤です。

インストール

npm install @tanakayuto/intmax402-fetch

使い方

Cloudflare Workers

import { handleIntmax402 } from "@tanakayuto/intmax402-fetch"

const config = {
  secret: process.env.INTMAX402_SECRET!,
  mode: "signature" as const,
}

export default {
  async fetch(request: Request): Promise<Response> {
    const result = await handleIntmax402(request, config)
    if (result.response) {
      // 認証失敗 → エラーレスポンスを返す
      return result.response
    }
    // 認証成功 → result.context にアドレス等が入る
    const { address } = result.context
    return new Response(`Hello, ${address}!`)
  },
}

Hono

import { Hono } from "hono"
import { handleIntmax402 } from "@tanakayuto/intmax402-fetch"

const app = new Hono()

const config = {
  secret: process.env.INTMAX402_SECRET!,
  mode: "signature" as const,
}

app.use("/protected/*", async (c, next) => {
  const result = await handleIntmax402(c.req.raw, config)
  if (result.response) {
    return result.response
  }
  c.set("intmax402", result.context)
  await next()
})

app.get("/protected/resource", (c) => {
  const ctx = c.get("intmax402")
  return c.json({ message: "Access granted", address: ctx.address })
})

Next.js App Router (Middleware)

// middleware.ts
import { NextRequest, NextResponse } from "next/server"
import { handleIntmax402 } from "@tanakayuto/intmax402-fetch"

const config = {
  secret: process.env.INTMAX402_SECRET!,
  mode: "payment" as const,
  serverAddress: process.env.SERVER_ADDRESS!,
  amount: process.env.PAYMENT_AMOUNT!,
}

export async function middleware(request: NextRequest) {
  const result = await handleIntmax402(request, config)
  if (result.response) {
    return result.response
  }
  // 認証成功 → ヘッダーにアドレスを追加して続行
  const requestHeaders = new Headers(request.headers)
  requestHeaders.set("x-intmax402-address", result.context.address)
  return NextResponse.next({ request: { headers: requestHeaders } })
}

export const config = {
  matcher: "/api/protected/:path*",
}

API

handleIntmax402(request, config)

パラメータ:

  • request: Request — Web標準の Request オブジェクト
  • config: INTMAX402Config — 認証設定

戻り値:

  • 認証失敗時: { response: Response, context: null } — このレスポンスをクライアントに返す
  • 認証成功時: { response: null, context: Intmax402Context } — 次のハンドラに進む

Intmax402Context

interface Intmax402Context {
  address: string   // 認証済みウォレットアドレス
  verified: boolean // 常に true
  txHash?: string   // payment モード時のトランザクションハッシュ
}

Network / ネットワーク

intmax402-fetch は Ethereum mainnet(INTMAX ZK L2 on Scroll)をデフォルトで使用します。開発時は environment: "testnet" を指定してください。

| Environment | Network | L1 Chain ID | |---|---|---| | mainnet (default) | Ethereum + Scroll | 1 | | testnet | Sepolia + Scroll Sepolia | 11155111 |

ライセンス

MIT

⚠️ IP Binding Warning

When using bindIp: true, ensure your server is behind a trusted reverse proxy (Nginx, Cloudflare, etc.). Direct exposure allows attackers to forge X-Forwarded-For headers, bypassing IP binding. Default (bindIp: false) is recommended for AI agent use cases.