Cap: A Lightweight Open-Source CAPTCHA Alternative Using Proof-of-Work

Introduction: The Evolution and Challenges of CAPTCHAs

In today’s digital landscape, CAPTCHAs (Completely Automated Public Turing tests to tell Computers and Humans Apart) face three critical challenges: user experience fluidity, privacy compliance, and effectiveness against AI. Traditional solutions like reCAPTCHA or hCaptcha, while widely adopted, face criticism due to their large size (300-400KB average), reliance on user tracking, and complex image recognition requirements.

Enter Cap—an open-source verification system using SHA-256 Proof-of-Work (PoW). At just 12KB minified (250x smaller than hCaptcha), with zero data tracking and elegant cryptographic verification, it redefines human-bot authentication.

Core Innovation: Replacing behavioral analysis with computational complexity, forcing machines to expend real processing power while maintaining seamless human interaction.


Technical Architecture: How Cap Works

Core Principles

Cap’s verification leverages cryptography:

  1. Challenge Generation: Server creates random string + difficulty parameter
  2. Proof-of-Work: Client finds Nonce satisfying SHA-256(string+Nonce) difficulty requirement
  3. Submission: Client submits Nonce (not raw data)
  4. Server Validation: Millisecond-level Nonce verification
graph LR
A[Client Request] --> B[Server Generates Challenge]
B --> C[Client Computes Nonce]
C --> D[Submit Nonce]
D --> E{Valid?}
E -->|Yes| F[Proceed]
E -->|No| G[Block Request]

Modular Design

Cap adopts a micro-kernel architecture:

Module Function Use Case
@cap.js/widget Frontend component (3KB core) Web forms
@cap.js/server Zero-dependency validation (Node/Bun/Deno) Backend APIs
@cap.js/solver Server-side solver Machine-to-machine
@cap.js/cli Command-line tool JS-free testing
Standalone Mode Docker REST API Non-JS environments

Six Core Advantages

1. Extreme Lightweight & Performance


  • 12KB compressed (with Brotli)

  • Web Worker parallelization: No main thread blocking

  • WASM acceleration: Rust-level performance via @cap.js/wasm

2. Privacy-First Architecture


  • Zero data collection: No behavioral profiling

  • No third-party requests: All computations local

  • GDPR/CCPA compliant: No PII processing

3. Flexible Deployment

# Frontend (CDN)
<script src="https://unpkg.com/@cap.js/widget/dist/cap.umd.js"></script>

# Node.js Server
npm install @cap.js/server

# Docker Standalone
docker run -p 3000:3000 capjs/standalone

4. Multiple Interaction Modes


  • Floating Mode: Non-intrusive sidebar

  • Invisible Mode: Background computation

  • Checkpoint Middleware: Cloudflare-like intercept experience

    // Express Middleware
    app.use(require('@cap.js/checkpoint-express')())
    

5. Enterprise Customization


  • CSS Variable Control:

    :root {
      --cap-primary: #2563eb;
      --cap-border-radius: 8px;
    }
    

  • Self-hosted servers: Full logic control

  • Dynamic difficulty: Auto-adjusts based on traffic

6. Bot Mitigation


  • Economic deterrence: Forces real computational cost

  • Dynamic salts: Unique challenge per request

  • Time constraints: 5-minute expiry prevents replay attacks

Technical Comparison: Cap vs. Alternatives

Dimension Cap Cloudflare Turnstile reCAPTCHA hCaptcha
License Apache 2.0 Proprietary Proprietary Proprietary
Frontend Size 12KB ~35KB ~400KB ~300KB
Verification Delay 300-800ms 1-3s 2-5s 3-8s
Privacy Impact None Limited tracking Behavioral profiling Behavioral profiling
Deployment Self-host/CDN CDN-only CDN-only CDN-only
Customization Full-stack UI tweaks only None None

Real-world case: E-commerce payment abandonment dropped from 18% to 3.2% after Cap implementation.


Four Implementation Scenarios

Scenario 1: API Bot Protection

// Hono Middleware
app.post('/api', async (c) => {
  const { nonce, challenge } = await c.req.json()
  const isValid = await verifyChallenge(challenge, nonce)
  
  if (!isValid) return c.text('Invalid CAPTCHA', 403)
  // Proceed with business logic
})

Scenario 2: Registration Abuse Prevention


  • Dynamic difficulty: Adjusts based on IP reputation

  • Background solving: Completes during password entry

Scenario 3: Free Tier Protection


  • Combine with token buckets: Trigger CAPTCHA every 10 API calls

  • Reduces false positives vs. rate limiting

Scenario 4: Cloudflare Challenge Replacement


  • Checkpoint middleware:

    npm install @cap.js/middleware-elysia
    

  • Custom intercept pages & audit logs

Implementation Guide: 3-Step Integration

Step 1: Frontend Integration

<div id="cap-container"></div>

<script>
  Cap.init({
    container: '#cap-container',
    mode: 'floating',
    onSolved: (nonce) => {
      document.querySelector('#captcha-input').value = nonce
    }
  })
</script>

Step 2: Server Validation

// Challenge Generation
app.get('/challenge', (req, res) => {
  const challenge = createChallenge({ difficulty: 18 })
  res.json(challenge)
})

// Submission Handling
app.post('/submit', async (req, res) => {
  const isValid = await verifyChallenge(req.body.challenge, req.body.nonce)
  isValid ? proceed() : res.status(403).send()
})

Step 3: Security Tuning

Parameter Recommended Security Impact Performance Impact
difficulty 16-20 Difficulty doubles per +1 Exponential time increase
timeout 300000ms Prevents replays None
whitelist Trusted IPs Reduces user friction Lowers server load

Troubleshooting Guide

Q: Mobile devices fail verification due to low processing power?
A: Implement dynamic difficulty:

const difficulty = isMobile ? 16 : 18

Q: How to counter specialized cracking tools?
A: Enable layered defenses:

  1. IP reputation checks
  2. Critical action re-verification
  3. Regular salt algorithm updates

Q: How to verify without JavaScript?
A: Use CLI:

npx @cap.js/cli solve --challenge=xxxxx

Future Roadmap

Cap’s development focuses on:

  1. Quantum-Resistant Algorithms: Experimental post-quantum signatures
  2. Distributed Verification: Blockchain-based challenge consensus
  3. Hardware Acceleration: WebGPU computation support

Contribute via RFC:
https://github.com/tiagorangel1/cap/discussions/categories/rfc


Conclusion: Reimagining Verification

Cap achieves an elegant balance through cryptography:
Verification becomes computational cost analysis, interaction remains frictionless for humans.

Unlike traditional CAPTCHAs’ endless “cat-and-mouse” upgrades (distorted text to traffic light identification), Cap solves the problem mathematically—its name reflecting both protection (“Cap”) and elegant encapsulation (Cryptographic Automation Proof).

# Get Started
npm create cap@latest

Resources:

OpenSSF Best Practices
Based on Cap v0.8.2 documentation (Apache 2.0 Licensed)