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

@foruai/gatekeeper-server

v0.2.0

Published

Server-side HMAC-SHA256 token signer for the ForU Gatekeeper AI API

Downloads

201

Readme

@foruai/gatekeeper-server

Server-side HMAC-SHA256 token signer for the ForU Gatekeeper AI API. Generate short-lived, one-time-use authentication tokens that your frontend can safely use to call the API directly.

Installation

npm install @foruai/gatekeeper-server
# or
pnpm add @foruai/gatekeeper-server
# or
bun add @foruai/gatekeeper-server

How It Works

The Gatekeeper API supports HMAC-SHA256 authentication so you never expose your secret key to the browser:

1. Frontend requests a signed token from YOUR backend
2. Your backend generates: nonce + timestamp + HMAC-SHA256(nonce:timestamp, SECRET)
3. Frontend sends the signed token to the Gatekeeper API
4. Gatekeeper verifies signature, checks expiry (5 min) + nonce uniqueness
5. Nonce is consumed (one-time use, replay-safe)
Browser  →  Your Backend (holds HMAC_SECRET)  →  returns signed token
Browser  →  Gatekeeper API (verifies HMAC)    →  returns response

Quick Start

Generate a token (server-side)

import { GatekeeperSigner } from '@foruai/gatekeeper-server'

const signer = new GatekeeperSigner({
  secret: process.env.HMAC_SECRET!, // your shared secret
})

// Option 1: Get a token object (pass to frontend)
const token = await signer.createToken()
// => { nonce: "a1b2c3...", timestamp: 1708000000000, signature: "deadbeef..." }

// Option 2: Get a ready-to-use Authorization header
const header = await signer.createAuthHeader()
// => "HMAC a1b2c3...:1708000000000:deadbeef..."

Example: Express/Hono endpoint

import express from 'express'
import { GatekeeperSigner } from '@foruai/gatekeeper-server'

const app = express()
const signer = new GatekeeperSigner({ secret: process.env.HMAC_SECRET! })

// Frontend calls this to get a signed token
app.get('/api/gatekeeper-token', async (req, res) => {
  const token = await signer.createToken()
  res.json(token)
})

Example: Next.js API Route

// app/api/gatekeeper-token/route.ts
import { GatekeeperSigner } from '@foruai/gatekeeper-server'

const signer = new GatekeeperSigner({ secret: process.env.HMAC_SECRET! })

export async function GET() {
  const token = await signer.createToken()
  return Response.json(token)
}

Using the token from the frontend

// Frontend: get token from your backend, then call Gatekeeper
const tokenRes = await fetch('/api/gatekeeper-token')
const token = await tokenRes.json()

const res = await fetch('https://gatekeeper.foruai.io/v1/chat', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    Authorization: `HMAC ${token.nonce}:${token.timestamp}:${token.signature}`,
  },
  body: JSON.stringify({ message: 'check badges for 0x123...' }),
})

Or use @foruai/gatekeeper-client which handles this automatically:

import { GatekeeperClient } from '@foruai/gatekeeper-client'

const client = new GatekeeperClient({
  baseUrl: 'https://gatekeeper.foruai.io',
})

const reply = await client.chat('check badges for 0x123...', { token })

API Reference

new GatekeeperSigner(options)

| Option | Type | Required | Description | |--------|------|----------|-------------| | secret | string | Yes | Your HMAC shared secret |

signer.createToken(): Promise<HmacToken>

Returns an HmacToken object:

interface HmacToken {
  nonce: string     // 32-char hex random nonce
  timestamp: number // Unix timestamp in milliseconds
  signature: string // HMAC-SHA256 hex digest of "nonce:timestamp"
}

Tokens expire after 5 minutes and are single-use (replay protection).

signer.createAuthHeader(): Promise<string>

Returns a ready-to-use Authorization header value:

HMAC <nonce>:<timestamp>:<signature>

Runtime Compatibility

Works in all JavaScript runtimes:

| Runtime | Crypto Backend | |---------|---------------| | Node.js 18+ | crypto.createHmac() | | Bun | Web Crypto API | | Deno | Web Crypto API | | Browsers | Web Crypto API (crypto.subtle) | | Edge (Cloudflare Workers, Vercel Edge) | Web Crypto API |

Companion Packages

License

MIT