CAPTCHA 证明你是人类。HATCHA 证明你不是。
HATCHA(Hyperfast Agent Test for Computational Heuristic Assessment,超快代理计算启发式评估测试)是一种反向验证码,以对 AI 代理轻而易举、对人类却十分痛苦的任务作为访问门槛——大数乘法、字符串反转、二进制解码等。
npm install @mondaycom/hatcha-react @mondaycom/hatcha-server
// 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;
// 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>
);
}
"use client";
import { useHatcha } from "@mondaycom/hatcha-react";
function AgentModeButton() {
const { requestVerification } = useHatcha();
return (
<button
onClick={() =>
requestVerification((token) => {
console.log("Agent verified!", token);
})
}
>
Enter Agent Mode
</button>
);
}
# .env.local
HATCHA_SECRET=your-random-secret-here
Client Server
│ │
│ GET /api/hatcha/challenge │
│────────────────────────────────►│
│ │ Generate challenge
│ │ Hash answer
│ │ HMAC-sign { hash, expiry }
│ { challenge (no answer), token }
│◄────────────────────────────────│
│ │
│ Agent solves the challenge │
│ │
│ POST /api/hatcha/verify │
│ { answer, token } │
│────────────────────────────────►│
│ │ Verify HMAC signature
│ │ Check expiry
│ │ Compare answer hash
│ { success, verificationToken } │
│◄────────────────────────────────│
答案永远不会到达客户端。签名令牌是不透明的,仅包含哈希后的答案和过期时间。验证是无状态的——无需数据库。
import { registerChallenge } from "@mondaycom/hatcha-server";
registerChallenge({
type: "hex",
generate() {
const n = Math.floor(Math.random() * 0xffffff);
return {
display: {
type: "hex",
icon: "0x",
title: "Hex Decode",
description: "Convert this hex number to decimal.",
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>。
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 | 挑战生成与加密验证 |
git clone https://github.com/mondaycom/HATCHA.git
cd HATCHA
pnpm install
pnpm build
cd examples/nextjs-app
pnpm dev
欢迎贡献!有关环境搭建说明和指南,请参阅 CONTRIBUTING.md。
| 类型 | 图标 | 作用 | 时间限制 |
|---|
math | × | 5 位数 × 5 位数乘法 | 30 秒 |
string | ↔ | 反转一个 60–80 字符的随机字符串 | 30 秒 |
count | # | 统计约 250 个字符中特定字符的出现次数 | 30 秒 |
sort | ⇅ | 对 15 个数字排序,返回第 k 小的数字 | 30 秒 |
binary | 01 | 将二进制八位组解码为 ASCII | 30 秒 |
@mondaycom/hatcha-react |
| React 组件、提供者和样式 |
@mondaycom/hatcha-server | Next.js 和 Express 服务端处理器 |