在 01 上构建。
一切皆为纯 HTTP 与 JSON。没有需要安装的专有 SDK,也没有外部运行时。 本页记录 01 保险箱与公开开发者平台所用的端点。
认证
使用两种机制:
- API Key — 发送 x-api-key: 01ak_…。在 01 保险箱 → 开发者 中创建与轮换密钥。密钥只属于一个 01 身份。
- 身份签名 — 面向用户的端点使用由身份密钥签名的质询/响应。移动应用会处理这一步;第三方应用使用 01 Connect。
每个响应都是 JSON。错误使用 HTTP 状态码与 { "error": "..." }。
快速开始
# 1. Health (no key) curl https://api.01.run/health # 2. Gateway statistics (no key) curl https://ingest.01.run/v1/stream/stats # 3. Write receipts in batches of up to 1000 items (API key from 01 Vault → Developer) curl -X POST https://ingest.01.run/v1/stream/receipts \ -H "content-type: application/json" \ -H "x-api-key: 01ak_…" \ -d '{"items":[ {"payload_hash":"2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824","tenant":"my-app","ref":"order-1042"}, {"payload_hash":"486ea46224d1bb4fb680f34f7c9ad96a8f24ec88be73ea8e5a6c65260e9cb8a7","tenant":"my-app"} ]}' # 4. Fetch one receipt and its Merkle proof curl https://ingest.01.run/v1/stream/receipts/rc_… # 5. Read the public event feed curl "https://ingest.01.run/v1/open/events?since=0&limit=50" \ -H "x-api-key: 01ak_…"
高吞吐收据网关
如果你需要证明数百万次 API 调用确实发生过——而不必把每一次调用都写进链—— 就把每次调用作为一条收据提交。网关把收据按一秒一批归组为 Merkle 批次,并把根锚定 到 01 链上。每笔收据都可以独立验证,批次也可以跨网关聚合。
| 方法 | 路径 | 用途 | 认证 |
|---|---|---|---|
| POST | /v1/stream/receipts | 单次请求最多受理 1000 条 | API Key |
| GET | /v1/stream/receipts/:id | 读取一笔收据及其 Merkle 证明 | 公开 |
| GET | /v1/stream/batches | 列出最近的 Merkle 批次 | 公开 |
| GET | /v1/stream/stats | 收据、批次与锚定计数 | 公开 |
| POST | /v1/stream/anchors | 提交子网关批次根用于聚合 | API Key |
| GET | /v1/stream/anchors | 列出聚合锚定 | 公开 |
| GET | /v1/stream/anchors/:id | 读取一个聚合锚定及其证明 | 公开 |
每条请求的收据条目上限为 1000 条。载荷是哈希与元数据;请不要发送明文个人数据。
开放平台与 Webhook
订阅公开事件(已发布作品、公告、锚定),接收带签名的 Webhook 投递。 每个订阅都有独立的签名密钥;在信任载荷之前请验证 HMAC。
| 方法 | 路径 | 用途 | 认证 |
|---|---|---|---|
| GET | /v1/open/events?since=&limit= | 公开事件的游标事件流 | API Key |
| POST | /v1/open/subscriptions | 创建 Webhook 订阅 | API Key |
| GET | /v1/open/subscriptions | 列出订阅 | API Key |
| DELETE | /v1/open/subscriptions/:id | 删除订阅 | API Key |
| POST | /v1/open/subscriptions/:id/test | 发送一次签名测试投递 | API Key |
| GET | /v1/open/deliveries | 查看投递尝试 | API Key |
验证 Webhook(Node.js)
import express from "express";
import { createHmac, timingSafeEqual } from "node:crypto";
const app = express();
// Keep the raw bytes: signatures are computed over the exact request body.
app.use(express.json({ verify: (req, _res, buf) => { req.rawBody = buf; } }));
function verify(rawBody, header, secret) {
const [scheme, signature] = String(header || "").split("=");
if (scheme !== "sha256") return false;
const expected = createHmac("sha256", secret).update(rawBody).digest();
const a = Buffer.from(signature, "hex");
return a.length === expected.length && timingSafeEqual(a, expected);
}
app.post("/01-webhook", (req, res) => {
const ok = verify(req.rawBody, req.get("x-01-signature"), process.env.ZERO1_WEBHOOK_SECRET);
if (!ok) return res.status(401).send("bad signature");
res.status(200).send("ok");
});
01 Connect
01 Connect 让第三方应用申请一项有范围、经用户批准的声明,而不是密码。 应用由 01 身份创建;授权在用户的应用中批准,并且可以逐项撤销。
| 方法 | 路径 | 用途 |
|---|---|---|
| POST | /v1/connect/apps | 创建应用(用户会话) |
| POST | /v1/connect/apps/:id/rotate-secret | 轮换客户端密钥 |
| POST | /v1/connect/requests | 创建授权请求 |
| GET | /v1/connect/lookup | 按客户端 ID 查询应用 |
| POST | /v1/connect/requests/:id/approve | 用户在设备上批准请求 |
| POST | /v1/connect/requests/:id/deny | 用户拒绝请求 |
| POST | /v1/connect/token | 用已批准的请求换取声明 |
| POST | /v1/connect/verify | 验证声明 |
| GET | /v1/me/connect/authorizations | 列出用户的授权 |
| POST | /v1/me/connect/authorizations/:id/revoke | 撤销一项授权 |
链协议
链规范、事件 Schema 与签名规则随节点源码一同发布 (chain/docs/01-chain-spec-v1.0.md)。账本只追加,存储哈希、 Merkle 根与锚定——从不存储加密数据块或明文。身份用后量子密钥签署事件; 验证者会拒绝签名无效或序列号过期的事件。
安全问题报告:security@01.run。请不要为漏洞提交公开 issue。 本文档描述 01-mainnet-1,会随网络演进扩展;创世规则本身不会改变。