惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
云风的 BLOG
云风的 BLOG
Microsoft Security Blog
Microsoft Security Blog
WordPress大学
WordPress大学
GbyAI
GbyAI
C
Check Point Blog
M
MIT News - Artificial intelligence
T
The Blog of Author Tim Ferriss
Jina AI
Jina AI
博客园 - 【当耐特】
U
Unit 42
月光博客
月光博客
腾讯CDC
Y
Y Combinator Blog
小众软件
小众软件
博客园_首页
Last Week in AI
Last Week in AI
酷 壳 – CoolShell
酷 壳 – CoolShell
The GitHub Blog
The GitHub Blog
博客园 - 聂微东
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
MongoDB | Blog
MongoDB | Blog
博客园 - Franky
T
Tailwind CSS Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
I built ZKP auth so passwords never touch your server
Abhik Mondal · 2026-05-18 · via DEV Community

Every time you hear about a major breach, the headline is the same: "Millions of passwords exposed." Attackers get in, dump the database, and walk away with your users' bcrypt hashes. Given enough time and a GPU farm, weak passwords crack. Even strong ones end up in breach databases. The root cause is always the same: the password reached your server. It lived in a request body, got hashed, got stored, and now it's someone else's problem. What if the password never traveled at all?


What is Zero-Knowledge Proof auth?

Zero-Knowledge Proofs sound academic, but the core idea is surprisingly simple: you can prove you know a secret without revealing what the secret is.

Here's a real-world analogy. Imagine you want to prove to a bouncer that you know the secret password to a club, but you don't want to say it out loud where others can hear. Instead, the bouncer gives you a random challenge token and asks you to sign it in a way that only someone who knows the password could. You hand back the signed token. The bouncer checks the signature. You're in — and you never said the password.

That's exactly what ZKP auth does at a cryptographic level. Your browser derives a keypair from your password (the password stays in memory, never leaves), uses the private key to sign a server-issued challenge, and the server checks the signature against a stored public key. The server never sees the password. It doesn't even see a hash of the password. It sees a 32-byte public key and a one-time proof.

No password database means no password database to breach.


How the library works

ZKP Auth is a TypeScript monorepo with four focused packages:

Package What it does
@zkp-auth/core Schnorr proof primitives (Ed25519)
@zkp-auth/server Express middleware — register, challenge, verify
@zkp-auth/client Browser client — key derivation + proof generation
@zkp-auth/react useZKPAuth() hook for React apps

Install

# Server
npm install @zkp-auth/server

# Browser (vanilla)
npm install @zkp-auth/client

# Browser (React)
npm install @zkp-auth/client @zkp-auth/react

Enter fullscreen mode Exit fullscreen mode

Server — three middleware functions, that's it

// server.ts
import express from 'express';
import cookieParser from 'cookie-parser';
import {
  zkpRegister,
  zkpChallenge,
  zkpVerify,
  InMemoryChallengeStore,
} from '@zkp-auth/server';

const app = express();
app.use(express.json());
app.use(cookieParser());

// Swap InMemoryChallengeStore for Redis/Postgres in production
const store = new InMemoryChallengeStore();

// Your user store — replace with real DB calls
const users = new Map<string, Uint8Array>();

// Route 1 — register: receives and stores the user's public key
app.post(
  '/auth/register',
  zkpRegister({
    savePublicKey: async (userId, publicKey) => {
      users.set(userId, publicKey);
    },
  }),
  (_req, res) => res.json({ ok: true }),
);

// Route 2 — challenge: issues a fresh one-time nonce
app.post(
  '/auth/challenge',
  zkpChallenge({ store }),
  (_req, res) => res.json({ challengeHex: res.locals.zkpChallengeHex }),
);

// Route 3 — verify: checks the proof and issues a JWT cookie
app.post(
  '/auth/verify',
  zkpVerify({
    getPublicKey: async (userId) => users.get(userId) ?? null,
    store,
    jwtSecret: process.env.JWT_SECRET!,
  }),
  (_req, res) => {
    res.cookie('auth', res.locals.zkpToken, {
      httpOnly: true,
      sameSite: 'strict',
      secure: process.env.NODE_ENV === 'production',
    });
    res.json({ ok: true });
  },
);

Enter fullscreen mode Exit fullscreen mode

Client — React hook

// LoginForm.tsx
import { useZKPAuth } from '@zkp-auth/react';

export function LoginForm() {
  const { register, login, logout, isAuthenticated, loading, error, user } =
    useZKPAuth();

  if (isAuthenticated) {
    return (
      <div>
        <p>Welcome, {user?.userId}!</p>
        <button onClick={logout}>Log out</button>
      </div>
    );
  }

  return (
    <>
      {error && <p style={{ color: 'red' }}>{error.message}</p>}

      <form onSubmit={async (e) => {
        e.preventDefault();
        const f = new FormData(e.currentTarget);
        await register(f.get('username') as string, f.get('password') as string);
      }}>
        <h2>Register</h2>
        <input name="username" placeholder="Username" required />
        <input name="password" type="password" placeholder="Password" />
        <button type="submit" disabled={loading}>Register</button>
      </form>

      <form onSubmit={async (e) => {
        e.preventDefault();
        const f = new FormData(e.currentTarget);
        await login(f.get('username') as string, f.get('password') as string);
      }}>
        <h2>Log in</h2>
        <input name="username" placeholder="Username" required />
        <input name="password" type="password" placeholder="Password" />
        <button type="submit" disabled={loading}>
          {loading ? 'Authenticating…' : 'Log in'}
        </button>
      </form>
    </>
  );
}

Enter fullscreen mode Exit fullscreen mode

That's the entire auth surface. No password ever leaves the browser.


How it works under the hood

The protocol is a Schnorr Proof of Knowledge over Ed25519 with the Fiat–Shamir transform. Here's the flow in plain English:

BROWSER                              SERVER
──────────────────────────────────────────────────────
1. Derive keypair from password
   (PBKDF2 + SHA-512 — stays in memory)

2. POST /auth/challenge  ──────────►  Issue challenge c (random nonce)
                         ◄──────────  Return c

3. Generate commitment R = r·G
   Compute s = r + c·privKey        (private scalar stays local)
   POST /auth/verify (R, s, userId)

                         ──────────►  Fetch stored pubKey for userId
                                      Verify: s·G == R + c·pubKey
                                      ✓  Issue JWT cookie

Enter fullscreen mode Exit fullscreen mode

The server only ever stores the 32-byte public key — mathematically useless without the private scalar, which only the browser can derive (from the password, which never travels).

Replay attacks are impossible: every challenge c is a fresh one-time nonce that expires server-side after a single use.

The crypto is built on @noble/curves — an audited, zero-dependency library. No custom crypto primitives.

For the full mathematical derivation and threat model, see the Security Model docs.


Get started

npm install @zkp-auth/server        # server
npm install @zkp-auth/client        # browser / vanilla JS
npm install @zkp-auth/client @zkp-auth/react  # React

Enter fullscreen mode Exit fullscreen mode

Pre-1.0 notice: This library has not yet undergone a formal third-party audit. Review the security model before deploying to production.

Stars, issues, and PRs are all welcome. If you're building something with it, I'd love to hear about it in the comments.