验证码证明你是人类。HATCHA证明你不是
CAPTCHA证明你是人类。HATCHA证明你不是。HATCHA(超快代理测试用于计算启发式评估)是一种反向验证码,通过对人工智能代理简单但对人类痛苦的挑战来限制访问——大数乘法、字符串反转、二进制解码等等。服务器端验证——答案永远不会到达客户端。使用HMAC签名的令牌,无状态,无需数据库。5种内置挑战类型——数学、字符串反转、字符计数、排序、二进制解码。可扩展——在运行时注册自定义挑战生成器。可主题化——通过CSS自定义属性设置黑暗、光明或自动模式。框架适配器——开箱即用的Next.js应用路由和Express中间件。快速入门(Next.js)1. 安装npm install @mondaycom/hatcha-react @mondaycom/hatcha-server 2. 添加API路由 // app/api/hatcha/[...hatcha]/route.ts import { createHatchaHandler } from "@mondaycom/hatcha-server/nextjs"; const handler = createHatchaHandler({ secret: process.env.HATCHA_SECRET!, }); export const GET = handler; export const POST = handler; 3. 包裹你的布局 // app/layout.tsx import { HatchaProvider } from "@mondaycom/hatcha-react"; import "@mondaycom/hatcha-react/styles.css"; export default function RootLayout({ children }) { return ( <html lang="en"> <body> <HatchaProvider> {children} </HatchaProvider> </body> </html> ); } 4. 触发验证 "use client"; import { useHatcha } from "@mondaycom/hatcha-react"; function AgentModeButton() { const { requestVerification } = useHatcha(); return ( <button onClick={() => requestVerification((token) => { console.log("代理已验证!", token); })}>进入代理模式</button> ); } 5. 设置你的密钥 # .env.local HATCHA_SECRET=your-random-secret-here 它是如何工作的 客户端 服务器 │ │ │ GET /api/hatcha/challenge │ │────────────────────────────────►│ │ │ 生成挑战 │ │ 哈希答案 │ │ HMAC-sign { hash, expiry } │ { challenge (no answer), token } │◄────────────────────────────────│ │ │ │ 代理解决挑战 │ │ │ │ POST /api/hatcha/verify │ │ { answer, token } │ │────────────────────────────────►│ │ │ 验证HMAC签名 │ │ 检查到期 │ │ 比较答案哈希 │ { success, verificationToken } │ │◄────────────────────────────────│ 答案永远不会到达客户端。签名的令牌是模糊的,仅包含一个哈希答案+到期时间。验证是无状态的——无需数据库。挑战类型 类型 图标 功能 时间限制 数学 × 5位 × 5位乘法 30秒 字符串 ↔ 反转一个60–80字符的随机字符串 30秒 计数 # 统计约250个字符中特定字符的数量 30秒 排序 ⇅ 排序15个数字,返回第k个最小值 30秒 二进制 01 将二进制八位字节解码为ASCII 30秒 自定义挑战 import { registerChallenge } from "@mondaycom/hatcha-server"; registerChallenge({ type: "hex", generate() { const n = Math.floor(Math.random() * 0xffffff); return { display: { type: "hex", icon: "0x", title: "十六进制解码", description: "将这个十六进制数字转换为十进制。", prompt: `0x ${n.toString(16).toUpperCase()}`, timeLimit: 30, answer: String(n), }, answer: String(n), }; }, }); 主题设置 HATCHA使用范围定义在--hatcha-*下的CSS自定义属性。可以在任何父元素上重写它们: [data-hatcha-theme] { --hatcha-accent: #3b82f6; --hatcha-accent-light: #60a5fa; --hatcha-bg: #060b18; --hatcha-fg: #e4eaf6; --hatcha-success: #22c55e; --hatcha-danger: #ef4444; } 传递theme="dark", theme="light",或者theme="auto"给<HatchaProvider>或者<Hatcha>。 Express import express from "express"; import { hatchaRouter } from "@mondaycom/hatcha-server/express"; const app = express(); app.use(express.json()); app.use("/api/hatcha", hatchaRouter({ secret: process.env.HATCHA_SECRET! })); app.listen(3000); 包含 包含描述 @mondaycom/hatcha-core 挑战生成和加密验证 @mondaycom/hatcha-react React组件、提供者和样式 @mondaycom/hatcha-server Next.js和Express服务器处理程序 开发 git clone https://github.com/mondaycom/HATCHA.git cd HATCHA pnpm install pnpm build cd examples/nextjs-app pnpm dev 贡献 欢迎贡献!请参阅CONTRIBUTING.md以获取设置说明和准则。 许可证 MIT
本站免费、广告极少。如果觉得有帮助,可以请我们喝杯咖啡 —— 任何金额都对持续运营有实际帮助。
☕请我喝杯咖啡