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

@openkitx403/server

v0.1.6

Published

TypeScript server SDK for OpenKitx403 wallet authentication

Readme

@openkitx403/server

Express & Fastify middleware for OpenKitx403 wallet authentication. Easily protect your API routes with Solana wallet-based signatures.


🚀 Installation

npm install @openkitx403/server

⚙️ Quick Usage (Express)

import express from 'express';
import { createOpenKit403, inMemoryLRU } from '@openkitx403/server';

const app = express();

// Create OpenKitx403 instance
const openkit = createOpenKit403({
  issuer: 'my-api',
  audience: 'https://api.example.com',
  replayStore: inMemoryLRU(), // Prevent replay attacks
});

// Apply middleware
app.use(openkit.middleware());

// Protected route
app.get('/protected', (req, res) => {
  const user = (req as any).openkitx403User;
  res.json({ message: '✅ Authenticated', wallet: user.address });
});

app.listen(3000, () => {
  console.log('🚀 Server running at http://localhost:3000');
});

⚡ Fastify Integration

import Fastify from 'fastify';
import { createOpenKit403, inMemoryLRU } from '@openkitx403/server';

const fastify = Fastify();

const openkit = createOpenKit403({
  issuer: 'my-api',
  audience: 'https://api.example.com',
  replayStore: inMemoryLRU(),
});

// Add authentication hook
fastify.addHook('onRequest', openkit.fastifyHook());

// Protected endpoint
fastify.get('/protected', async (req, reply) => {
  const user = (req as any).openkitx403User;
  return { message: '✅ Authenticated', wallet: user.address };
});

fastify.listen({ port: 3000 });

🔧 Configuration Options

| Option | Type | Default | Description | |--------------------|------------------------------------------------------|---------|----------------------------------------------------------| | issuer | string | required| Identifier for your API (e.g. "my-api") | | audience | string | required| Expected audience or domain of your API | | ttlSeconds | number | 60 | Challenge time-to-live in seconds | | clockSkewSeconds | number | 120 | Allowed clock drift for timestamp validation | | bindMethodPath | boolean | false | Require binding to HTTP method + path | | originBinding | boolean | false | Require origin header validation | | uaBinding | boolean | false | Require user-agent header validation | | replayStore | ReplayStore | null | Used to detect and block replayed requests | | tokenGate | (address: string) => Promise<boolean> | null | Async check for wallet-based access (e.g. NFT ownership)|


🔄 Replay Protection

In-Memory Store (Development)

import { inMemoryLRU } from '@openkitx403/server';

const openkit = createOpenKit403({
  issuer: 'my-api',
  audience: 'https://api.example.com',
  replayStore: inMemoryLRU(10000) // Optional: max cache size (default 10000)
});

Custom Replay Store (Production - Redis)

For distributed systems, implement a custom replay store:

import { ReplayStore } from '@openkitx403/server';
import Redis from 'ioredis';

class RedisReplayStore implements ReplayStore {
  private redis: Redis;

  constructor(redisClient: Redis) {
    this.redis = redisClient;
  }

  async check(key: string, ttlSeconds: number): Promise<boolean> {
    const exists = await this.redis.exists(key);
    return exists === 1;
  }

  async store(key: string, ttlSeconds: number): Promise<void> {
    await this.redis.setex(key, ttlSeconds, '1');
  }
}

// Usage
const redis = new Redis('redis://localhost:6379');
const openkit = createOpenKit403({
  issuer: 'my-api',
  audience: 'https://api.example.com',
  replayStore: new RedisReplayStore(redis)
});

🎫 Token Gating Example

Require users to hold specific NFTs or tokens:

import { Connection, PublicKey } from '@solana/web3.js';

const connection = new Connection('https://api.mainnet-beta.solana.com');

const openkit = createOpenKit403({
  issuer: 'my-api',
  audience: 'https://api.example.com',
  replayStore: inMemoryLRU(),
  tokenGate: async (address: string) => {
    try {
      const pubkey = new PublicKey(address);
      // Check if wallet holds specific NFT collection
      const nftAccounts = await connection.getTokenAccountsByOwner(
        pubkey,
        { mint: new PublicKey('YOUR_NFT_MINT_ADDRESS') }
      );
      return nftAccounts.value.length > 0;
    } catch (error) {
      console.error('Token gate check failed:', error);
      return false;
    }
  }});

🧩 Type Definitions

interface OpenKit403Config {
  issuer: string;
  audience: string;
  ttlSeconds?: number;
  clockSkewSeconds?: number;
  bindMethodPath?: boolean;
  originBinding?: boolean;
  uaBinding?: boolean;
  replayStore?: ReplayStore;
  tokenGate?: (address: string) => Promise<boolean>;
}

interface OpenKit403User {
  address: string; // Solana wallet address (base58)
  challenge: Challenge; // Challenge payload
}

interface ReplayStore {
  check(key: string, ttlSeconds: number): Promise<boolean>;
  store(key: string, ttlSeconds: number): Promise<void>;
}```


---

## 📚 Documentation

* [OpenKitx403 Protocol Specification](https://github.com/openkitx403/openkitx403)
* [Client SDK Documentation](https://github.com/openkitx403/openkitx403/tree/main/packages/client)
* [Security Best Practices](https://github.com/openkitx403/openkitx403/blob/main/SECURITY.md)

---

## 🧠 Best Practices

* Always use **HTTPS** in production
* Enable **`replayStore`** for replay protection (required for production)
* Use **Redis-backed replay store** for multi-server deployments
* Use **`bindMethodPath: true`** for method-level signing security
* Apply **token gating** for NFT/token-gated endpoints
* Keep **TTL ≤ 60 seconds** for challenges
* Set **`clockSkewSeconds`** appropriately for your infrastructure (default 120s)

---

## 🪪 License

[MIT](../../LICENSE)