🚀. Socket Launch Week Day 3:Socket Firewall Now Blocks Malicious VS Code and Open VSX Extensions.Learn more
Sign In

@powforge/ratelimit

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@powforge/ratelimit

Proof-of-work rate limiting middleware for Express/Fastify. No API keys, no third-party services. Clients prove computational work to access your API.

latest
Source
npmnpm
Version
0.3.0
Version published
Weekly downloads
13
85.71%
Maintainers
1
Weekly downloads
 
Created
Source

@powforge/ratelimit

Proof-of-work rate limiting for Express APIs. No API keys, no accounts, no third-party services.

Clients solve a SHA-256 puzzle to prove computational work before accessing your API. Solved proofs grant time-limited tokens for subsequent requests.

Install

npm install @powforge/ratelimit

Quick Start

const express = require('express');
const { powRateLimit } = require('@powforge/ratelimit');

const app = express();

// Protect your API with PoW rate limiting
app.use('/api', powRateLimit({ difficulty: 14 }));

app.get('/api/data', (req, res) => {
  res.json({ message: 'You proved computational work to get here' });
});

app.listen(3000);

How It Works

  • Client requests /api/data without proof
  • Server responds 429 with a SHA-256 challenge
  • Client finds nonce where SHA256(salt + nonce) has N leading zero bits
  • Client retries with X-PoW-Proof: salt:nonce:signature header
  • Server verifies and issues X-PoW-Token for subsequent requests (5 min TTL)

Client Integration

async function fetchWithPoW(url) {
  let res = await fetch(url);
  
  if (res.status === 429) {
    const { challenge } = await res.json();
    const nonce = await solveChallenge(challenge);
    const proof = `${challenge.salt}:${nonce}:${challenge.signature}`;
    res = await fetch(url, {
      headers: { 'X-PoW-Proof': proof }
    });
  }
  
  return res;
}

async function solveChallenge({ salt, difficulty }) {
  for (let nonce = 0; ; nonce++) {
    const hash = await sha256(salt + nonce);
    const bits = parseInt(hash.substring(0, 8), 16);
    if (bits < Math.pow(2, 32 - difficulty)) return nonce;
  }
}

Options

OptionDefaultDescription
difficulty14Leading zero bits (14 = ~16k hashes, <1s)
tokenTTL300Token validity in seconds
challengeTTL120Challenge validity in seconds
secretautoHMAC signing secret
skipIfnull(req) => boolean to bypass PoW

Difficulty Guide

DifficultyExpected HashesBrowser TimeUse Case
101,024~25msLight protection
1416,384~350msStandard API protection
18262,144~12sHigh-value endpoints
201,048,576~23sRate-limit heavy consumers

Data from empirical experiments on AMD EPYC 7443P. Browser times ~5x slower than server.

Why PoW Instead of API Keys?

  • No accounts needed: Clients prove work, not identity
  • No rate limit state: Server is stateless (tokens are self-contained HMACs)
  • Bot deterrence: Automated scrapers must spend real CPU time per request
  • Privacy-first: No tracking, no IP logging, no third-party calls
  • Softwar thesis: Access costs energy, not credentials

Part of the PowForge Project

Built as part of the Softwar thesis research, testing proof-of-work as a universal access control mechanism.

License

MIT

Keywords

rate-limiting

FAQs

Package last updated on 15 Apr 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts