开发文档

HTTP 接口文档

无需密钥的公开只读接口,基于 X Layer 快照返回 JSON 结果,并提供实时徽章 SVG 与卖家签名接口。

基础地址https://usezhen.xyz/api/v1
鉴权只读接口免密钥
签名限流10 req/min / IP
01

GET /api/v1/check

返回包含 checkedAtBlock、verdictHash、level 与公开 findings 的 JSON 对象,支持四种查询模式:

# 1. By TapeOut dot-name (circuit, processor.circuit, or task.processor.circuit)
curl "https://usezhen.xyz/api/v1/check?name=1961.2.323"

# 2. By processor address + circuit ID
curl "https://usezhen.xyz/api/v1/check?processor=0x87bfca3494aa228ff589ab9b642143a5e8c8f9a6&id=1961"

# 3. By processor address alone
curl "https://usezhen.xyz/api/v1/check?processor=0x87bfca3494aa228ff589ab9b642143a5e8c8f9a6"

# 4. By untaped netlist hash (plus optional behaviour fingerprint & PoD cost)
curl "https://usezhen.xyz/api/v1/check?netlistId=<32-byte-hash>&fpHash=<hash>&cost=351"

对于未流片的设计,建议先在 /check 本地计算哈希与指纹,避免上传原始字节。

02

GET /api/v1/badge/svg

从 X Layer 实时读取 ZhenRegistry.isVerified 状态,返回适用于交易市场、文档与 README 嵌入的 image/svg+xml 徽章。

curl "https://usezhen.xyz/api/v1/badge/svg?processor=0x87bfca3494aa228ff589ab9b642143a5e8c8f9a6&id=1961"

# Markdown embed
[![Zhen status](https://usezhen.xyz/api/v1/badge/svg?processor=0x87bfca3494aa228ff589ab9b642143a5e8c8f9a6&id=1961)](https://usezhen.xyz/c/0x87bfca3494aa228ff589ab9b642143a5e8c8f9a6/1961)
03

POST /api/v1/badge/sign

签发有效期 15 分钟的 EIP-712 签名,绑定调用者钱包地址(seller)、subject、verdictHash、checkedAtBlock 与 256 位随机数。高危结果、重复设计、常见模板与未公开检出项将被拒绝签发。

curl -X POST "https://usezhen.xyz/api/v1/badge/sign" \
  -H "content-type: application/json" \
  -d '{
    "kind": "circuit",
    "processor": "0x87bfca3494aa228ff589ab9b642143a5e8c8f9a6",
    "id": "80",
    "seller": "0xYourWalletAddress"
  }'
04

AI 代理发现、RSS 订阅与嵌入组件

所有只读接口均返回 Access-Control-Allow-Origin: * 与 OPTIONS 预检响应头,支持机器人、交易市场与 X Layer DeWEB 前端直接跨域调用。

超出每日 100 次免费额度后,代理可通过 OKX x402 在 /api/v1/check($0.005 USD₮0)或 /api/v1/deep-check($0.02 USD₮0,附带签名回执)自动付费:

import { wrapFetchWithPayment, x402Client } from '@okxweb3/x402-fetch'
import { ExactEvmScheme } from '@okxweb3/x402-evm/exact/client'

const client = new x402Client().register('eip155:196', new ExactEvmScheme(evmSigner))
const fetchWithPay = wrapFetchWithPayment(fetch, client)
const res = await fetchWithPay('https://usezhen.xyz/api/v1/deep-check?name=1056.2.323')
  • /openapi.json — OpenAPI 3.1.0 接口规范
  • /llms.txt — 大模型与 AI 代理接入指南
  • /.well-known/agent.json — AI 代理能力清单 (eip155:196)
  • GET /api/v1/watch?targets=80.2.323,1056.2.323,task:100&format=rss — 实时 JSON / RSS 2.0 关注提醒订阅(免注册)
  • POST /api/v1/webhooks — 每个地址最多注册 3 个 EIP-712 签名 Webhook
  • <script src="https://usezhen.xyz/embed.js" data-zhen="1056.2.323" async></script> — 即插即用的链上溯源卡片组件
// Register & verify signed Zhen alert webhooks (EIP-712 ZhenAlertWebhook/1/196)
import { keccak256, toBytes, verifyTypedData } from 'viem'

const bodyHash = keccak256(toBytes(rawBody))
const ok = await verifyTypedData({
  address: headers['x-zhen-signer'],
  domain: { name: 'ZhenAlertWebhook', version: '1', chainId: 196 },
  types: {
    AlertEvent: [
      { name: 'eventId', type: 'string' },
      { name: 'webhookId', type: 'string' },
      { name: 'kind', type: 'string' },
      { name: 'severity', type: 'string' },
      { name: 'target', type: 'string' },
      { name: 'block', type: 'uint64' },
      { name: 'timestamp', type: 'uint64' },
      { name: 'bodyHash', type: 'bytes32' },
    ],
  },
  primaryType: 'AlertEvent',
  message: {
    eventId: headers['x-zhen-event-id'],
    webhookId: headers['x-zhen-webhook-id'],
    kind: payload.event.kind,
    severity: payload.event.severity,
    target: payload.event.target,
    block: BigInt(payload.event.block),
    timestamp: BigInt(headers['x-zhen-timestamp']),
    bodyHash,
  },
  signature: headers['x-zhen-signature'],
})
05

自行验证检查结果(Merkle 锚定)

每个索引快照都有一个 Merkle 根,覆盖每个电路与处理器的公开检查结果。该根会发布到 X Layer 上的 ZhenAnchor 合约,因此无需信任 Zhen 的服务器,也能对照链上数据检查结果。每个结果页都有“自行验证”面板,在浏览器中完成检查。

  • 合约: 0xb29e3974d4819aa0907205077475449363a8c006 (eip155:196, 区块浏览器)
  • 读取: rootAt(uint64 snapshotBlock), latestRoot(), latestBlock(), anchorCount()
  • 接口: 对快照树中的结果,/api/v1/check 会附带 proof 与 anchor。若该快照的根尚未发布,anchor.anchored 为 false。
部分定义(zhen-merkle-v1)
subjectIdkeccak256(abi.encode(uint8 1, address processor, uint256 id)) (电路);处理器则为左补零至 32 字节的地址
verdictHashkeccak256 作用于以下规范 JSON: {v:1, subject, level, checkedAtBlock, findings:[{code, severity, data}]} (键已排序)
leafkeccak256(0x00 ‖ subjectId ‖ verdictHash)
nodekeccak256(0x01 ‖ min(a, b) ‖ max(a, b)) 因此证明只含兄弟哈希;叶子按 subjectId 排序,落单节点原样上移
# 1. Get a verdict with its proof
curl "https://usezhen.xyz/api/v1/check?name=1056.2.323"

# 2. Recompute verdictHash from the verdict, build the leaf, fold proof.proof with the node rule,
#    and compare with the root the contract holds for proof.snapshotBlock:
cast call 0xb29e3974d4819aa0907205077475449363a8c006 "rootAt(uint64)(bytes32)" <snapshotBlock> --rpc-url https://rpc.xlayer.tech

# Or run the independent checker. Download it from this site (it needs only @noble/hashes):
curl -O https://usezhen.xyz/verify.mjs && npm install @noble/hashes
node verify.mjs 1056.2.323 --anchor 0xb29e3974d4819aa0907205077475449363a8c006 --rpc https://rpc.xlayer.tech

快照的根发布后即可检查;更新的快照在发布之前显示 anchored: false。已发布的根会一直保留在链上,因此从已锚定快照保存的证明,之后仍可对照 rootAt(snapshotBlock) 验证。