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

@usewayn/checkpoint

v0.0.2

Published

PoW captcha middlewares for Wayn applications

Readme

Wayn Checkpoint

npm version License: AGPL-3.0

DDOS protection middleware for Express.js and React applications using Proof-of-Work (PoW) challenges. Similar to Cloudflare's "Checking your browser" page, Wayn Checkpoint protects your applications from automated attacks and spam.

Features

  • 🛡️ DDOS Protection: Proof-of-Work challenges that are expensive for bots but easy for humans
  • 🚀 Easy Integration: Works with Express.js and React applications
  • Customizable: Configurable difficulty, duration, and appearance
  • 🔒 Secure: JWT-based verification with configurable expiration
  • 📱 Universal: Works in all modern browsers
  • 🎨 Customizable UI: Override the default checkpoint page template
  • 🔧 Rate Limiting: Built-in rate limiting for additional protection

Installation

npm install @usewayn/checkpoint

Quick Start

Express.js

const express = require('express');
const { createCheckpoint } = require('@usewayn/checkpoint');

const app = express();

// Protect all routes with checkpoint
app.use(createCheckpoint({
  secret: 'your-secret-key-here',
  questionCount: 5,
  questionHardness: 5,
  jwtTtlHours: 24
}));

app.get('/', (req, res) => {
  res.send('Hello, verified human!');
});

app.listen(3000);

React

import React from 'react';
import { CheckpointProvider } from '@usewayn/checkpoint';

function App() {
  return (
    <CheckpointProvider
      config={{
        questionCount: 5,
        questionHardness: 5,
        jwtTtlHours: 24,
        apiEndpoint: '/__wayn_checkpoint'
      }}
    >
      <div>
        <h1>Protected App</h1>
        <p>Only verified users can see this content.</p>
      </div>
    </CheckpointProvider>
  );
}

export default App;

How It Works

  1. Request Interception: When a user visits your protected application, the middleware intercepts the request
  2. Token Check: Checks for a valid verification token (JWT cookie)
  3. Challenge Page: If no valid token exists, serves a PoW challenge page
  4. Proof-of-Work: User's browser automatically solves computational puzzles
  5. Verification: Solution is verified server-side and a JWT token is issued
  6. Access Granted: User is redirected to the original destination with the verification token

Configuration Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | secret | string | Required | JWT secret key for signing tokens | | questionCount | number | 5 | Number of PoW challenges to solve | | questionHardness | number | 5 | Difficulty level (higher = more computation) | | jwtTtlHours | number | 24 | JWT token validity in hours | | apiEndpoint | string | /__wayn_checkpoint | API endpoint for challenges | | cookieName | string | __wayn-clarification | Name of the verification cookie | | excludePaths | string[] | [] | Paths to exclude from protection | | customTemplate | string | undefined | Custom HTML template for checkpoint page | | debug | boolean | false | Enable debug logging | | rateLimit | object | See below | Rate limiting configuration |

Rate Limiting Options

rateLimit: {
  windowMs: 15 * 60 * 1000,  // Time window in milliseconds
  maxAttempts: 5             // Max attempts per window
}

API Reference

Express Middleware

createCheckpoint(config: CheckpointConfig)

Creates an Express middleware function that protects routes with PoW challenges.

import { createCheckpoint } from '@usewayn/checkpoint';

const middleware = createCheckpoint({
  secret: 'your-secret-key',
  questionCount: 5,
  questionHardness: 5
});

app.use(middleware);

WaynCheckpoint Class

For more advanced usage, you can use the WaynCheckpoint class directly:

import { WaynCheckpoint } from '@usewayn/checkpoint';

const checkpoint = new WaynCheckpoint({
  secret: 'your-secret-key',
  questionCount: 5,
  questionHardness: 5
});

app.use(checkpoint.middleware());

React Components

CheckpointProvider

React context provider that protects child components:

import { CheckpointProvider } from '@usewayn/checkpoint';

<CheckpointProvider config={config}>
  <App />
</CheckpointProvider>

withCheckpoint(Component, config)

Higher-order component that wraps a component with checkpoint protection:

import { withCheckpoint } from '@usewayn/checkpoint';

const ProtectedApp = withCheckpoint(App, { config });

useCheckpoint(config)

React hook for checkpoint verification status:

import { useCheckpoint } from '@usewayn/checkpoint';

function MyComponent() {
  const { isVerified, isLoading, error } = useCheckpoint(config);
  
  if (isLoading) return <div>Checking...</div>;
  if (!isVerified) return <div>Verification required</div>;
  
  return <div>Protected content</div>;
}

Security Considerations

  1. Secret Key: Use a strong, random secret key and keep it secure
  2. HTTPS: Always use HTTPS in production to protect tokens in transit
  3. Rate Limiting: Configure appropriate rate limits for your use case
  4. Difficulty Tuning: Balance security vs. user experience when setting difficulty
  5. Token Expiration: Set appropriate JWT expiration times

Examples

See examples.md for more detailed usage examples.

Architecture

Wayn Checkpoint consists of:

  • Server Component (@usewayn/server): Generates and verifies PoW challenges
  • Widget Component (@usewayn/widget): Browser-side PoW solver
  • Checkpoint Middleware: Express middleware and React components

Performance

  • Client Impact: Minimal - challenges are solved using Web Workers
  • Server Impact: Low - stateless verification with JWT tokens
  • Network: Small overhead - only challenge data and solutions transmitted

Browser Support

  • Chrome 60+
  • Firefox 55+
  • Safari 11+
  • Edge 79+

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the AGPL-3.0 License - see the LICENSE file for details.

Related Projects

Support

For support, please open an issue on GitHub or contact the maintainers.