跳到正文
PQWERAI 加入测试网
简体中文

GhostDeploy · 管理 API

一个 API 适用于所有主机。 绝不是节点 RPC。

GhostDeploy 通用节点托管 API 1.0.0(OpenAPI 3.1.0)。每台主机一个守护进程,使用独立端口、固定证书的 HTTPS 和限定权限的令牌。它管理实例与 Smartnode 密钥;从不返回私钥,也从不代理节点 JSON-RPC。

端点SDK下载 openapi.yaml

生成自 GhostDeploy 参考仓库中以下提交的 spec/api/openapi.yaml 7d80dca (2026-11-28)。GhostDeploy 是一个 标准草案(GDS-1 0.1.0-draft) 面向公共测试网络 20778:格式仍可能变化,且该仓库尚未公开。

每台主机一个 API 守护进程(ghostdeploy api serve),使用独立端口(默认 8790),通过 HTTPS 和自签名证书提供服务,客户端固定其 SHA-256 指纹。此 API 不是节点 JSON-RPC,也从不代理它。Bearer 令牌 gd_<id>_<secret> 带有作用域(read、operate、deploy、smartnode、admin)和可选的实例列表。主机只存储 sha256(secret)。会修改状态的调用会写入审计日志(记录令牌 ID,绝不记录密钥)。任何端点都不会返回私钥。

连接

服务器
https://{host}:8790 (默认端口 8790,默认主机 127.0.0.1)
TLS
TLS 1.3,自签名证书;客户端固定其 SHA-256 指纹,该指纹由以下命令打印: ghostdeploy api serve
认证
HTTP bearer,格式 gd_<id>_<secret>;主机仅存储机密的哈希
作用域
read · operate · deploy · smartnode · admin,可选择限制为所列实例并设置到期时间
长时间操作
202 Accepted 并返回操作 ID;轮询 /v1/operations/{id}
错误
unauthorized, forbidden, not_found, bad_request, conflict, safety_refused, internal

状态

已实机验证

在真实主机上提供服务;一致性检查 GD-API-01/02 通过(无令牌或令牌无效返回 401,使用 read 令牌返回 200,API 端口 ≠ RPC,RPC 仅限回环)。SDK 已针对真实服务器测试:Python 24/24,TypeScript 21/21。

来自 docs/STATUS.md。规范许可证:Apache-2.0。

端点

方法路径用途授权
GET/v1/capabilities能力发现无令牌
GET/v1/openapi.yaml本规范无令牌
GET/v1/benchmark最新的已签名硬件基准(作用域 read)read
GET/v1/profiles部署配置(权限范围 read)read
GET/v1/instances列出该令牌可见的实例(作用域 read)read
POST/v1/instances部署实例(权限范围 deploy)deploy
GET/v1/instances/{name}实例记录(作用域 read)read
DELETE/v1/instances/{name}移除服务;保留数据和签名器状态(作用域 deploy)deploy
GET/v1/instances/{name}/status健康、同步、对等节点、最终确定性、验证者状态(权限范围 read)read
GET/v1/instances/{name}/events实例事件日志,最新的在最后(作用域 read)read
POST/v1/instances/{name}/actions/{action}生命周期操作(作用域 operate)。start-signers 会先运行所有验证者安全检查。operate
POST/v1/instances/{name}/smartnode/keygen在主机创建投票密钥(权限范围 smartnode)。仅返回公开数据。smartnode
POST/v1/instances/{name}/smartnode/pop所有权证明 + 用于所有者钱包的 calldata(作用域 smartnode)smartnode
GET/v1/operations/{id}长时间运行操作的状态(作用域 read)read
GET/v1/offers由该主机运营者发布的已签名托管报价(无需认证;按设计公开)无令牌

GET /v1/capabilities

能力发现。授权: 无令牌.

允许无令牌访问,以便客户端配对前发现主机;不泄露任何实例数据。

状态含义正文
200OKapplication/json 能力

GET /v1/openapi.yaml

本规范。授权: 无令牌.

状态含义正文
200OKapplication/yaml

GET /v1/benchmark

最新的已签名硬件基准(作用域 read)。授权: read.

状态含义正文
200OKapplication/json 基准测试
401错误application/json 错误

GET /v1/profiles

部署配置(权限范围 read)。授权: read.

状态含义正文
200OKapplication/json object 数组

GET /v1/instances

列出该令牌可见的实例(作用域 read)。授权: read.

状态含义正文
200OKapplication/json 数组,元素为 Instance

POST /v1/instances

部署实例(权限范围 deploy)。授权: deploy.

请求体 (必填): application/json DeployRequest

状态含义正文
202已接受application/json Operation
400错误application/json 错误
403错误application/json 错误

GET /v1/instances/{name}

实例记录(作用域 read)。授权: read.

参数位置必填类型详情
namepath是string模式 ^[a-z][a-z0-9-]{1,30}$
状态含义正文
200OKapplication/json Instance
404错误application/json 错误

DELETE /v1/instances/{name}

移除服务;保留数据和签名器状态(作用域 deploy)。授权: deploy.

参数位置必填类型详情
namepath是string模式 ^[a-z][a-z0-9-]{1,30}$
状态含义正文
202已接受application/json Operation

GET /v1/instances/{name}/status

健康、同步、对等节点、最终确定性、验证者状态(权限范围 read)。授权: read.

参数位置必填类型详情
namepath是string模式 ^[a-z][a-z0-9-]{1,30}$
状态含义正文
200OKapplication/json 状态

GET /v1/instances/{name}/events

实例事件日志,最新的在最后(作用域 read)。授权: read.

参数位置必填类型详情
namepath是string模式 ^[a-z][a-z0-9-]{1,30}$
limitquery否integer默认值 100;最多 1000
状态含义正文
200OKapplication/json 数组,元素为 事件

POST /v1/instances/{name}/actions/{action}

生命周期操作(作用域 operate)。start-signers 会先运行所有验证者安全检查。授权: operate.

参数位置必填类型详情
namepath是string模式 ^[a-z][a-z0-9-]{1,30}$
actionpath是string以下之一 start, stop, restart, start-signers, backup
状态含义正文
202已接受application/json Operation
409错误application/json 错误

POST /v1/instances/{name}/smartnode/keygen

在主机创建投票密钥(权限范围 smartnode)。仅返回公开数据。授权: smartnode.

参数位置必填类型详情
namepath是string模式 ^[a-z][a-z0-9-]{1,30}$

请求体: application/json object {validator: string}

状态含义正文
200OKapplication/json KeygenResult

POST /v1/instances/{name}/smartnode/pop

所有权证明 + 用于所有者钱包的 calldata(作用域 smartnode)。授权: smartnode.

参数位置必填类型详情
namepath是string模式 ^[a-z][a-z0-9-]{1,30}$

请求体 (必填): application/json PopRequest

状态含义正文
200OKapplication/json PopResult

GET /v1/operations/{id}

长时间运行操作的状态(作用域 read)。授权: read.

参数位置必填类型详情
idpath是string
状态含义正文
200OKapplication/json Operation
404错误application/json 错误

GET /v1/offers

由该主机运营者发布的已签名托管报价(无需认证;按设计公开)。授权: 无令牌.

状态含义正文
200OKapplication/json object 数组

模式

Error

字段类型必填详情
errorstring是
codestring以下之一 unauthorized, forbidden, not_found, bad_request, conflict, safety_refused, internal

Capabilities

字段类型必填详情
gdsstring是e.g. 0.1.0-draft
apistring是始终 gds.api/1
ghostdeploy_versionstring
host_idstring是
hostHostFacts是
profilesobject {name: string, status: string} 数组是
targetsstring 数组是
networksobject {chain_id: integer, network: string, sequence: integer} 数组是
instancesinteger

HostFacts

字段类型必填详情
osstring
archstring
cpusinteger
memory_mbinteger
disk_free_gbinteger
hostnamestring
kernelstring

Benchmark

自行报告,由主机密钥签名(GDS-1 §11.3)。客户端必须将其视为未经验证。

字段类型必填详情
schemastring是始终 gds.benchmark/1
host_idstring是
measured_atstring(date-time)是
hostHostFacts是
resultsnumber 映射是
signerstring是ed25519 公钥(十六进制)
signaturestring是

Instance

字段类型必填详情
namestring是
profilestring是
targetstring是以下之一 compose, systemd, coolify
networkstring
chain_idinteger是
genesis_hashstring是
core_revstring
slotinteger是
portsobject {p2p: integer, rpc: integer, metrics: integer}是
signersstring 数组
limitsobject
createdstring(date-time)

DeployRequest

字段类型必填详情
namestring是模式 ^[a-z][a-z0-9-]{1,30}$
profilestring是
chain_idinteger是其清单已嵌入或已在主机上被接受的网络。
targetstring以下之一 compose, systemd, coolify;默认 compose
public_ipstring
etherbasestring挖矿配置使用的外部收款地址。
memory_mbinteger
cpusnumber
artifact_urlstring

Status

字段类型必填详情
instancestring是
healthstring是以下之一 healthy, degraded, down
servicesstring 映射
chain_id_okboolean
genesis_okboolean
headinteger
peersinteger
finalized_heightinteger
finalityboolean
signersobject {validator: string, validator_id: string, registered: boolean, status: string, last_seen_epoch: integer, fence_ok: boolean} 数组
problemsstring 数组

Operation

字段类型必填详情
idstring是
kindstring是
instancestring
statestring是以下之一 running, succeeded, failed
startedstring(date-time)
finishedstring(date-time)
errorstring
result任意

KeygenResult

字段类型必填详情
instancestring
validatorstring
vote_pubkeystring
validator_idstring

PopRequest

字段类型必填详情
validatorstring是
ownerstring是所有者 EOA 地址。所有者密钥绝不会发送到主机。
rotate_validator_idstring

PopResult

用于所有者钱包的公开注册包(gds.smartnode-pop/1)。

字段类型必填详情
schemastring
actionstring以下之一 register, rotate
chain_idinteger
genesis_hashstring
ownerstring
vote_pubkeystring
validator_idstring
popstring
tostring
calldatastring
value_hintstring

Event

字段类型必填详情
timestring
kindstring
messagestring
dataobject

SDK

两个参考客户端:如果主机证书与固定指纹不符,二者都会拒绝与其通信,并在所有者签名前验证 Smartnode 注册包。 二者均尚未发布到 PyPI 或 npm:就绪后即可使用下方安装命令。

客户端软件包版本运行时
Pythonghostdeploy-client0.1.0Python 3.10+,仅使用标准库
TypeScript@ghostdeploy/client0.1.0Node 18+,无运行时依赖
Python 客户端:安全模型、用法、测试

这是 GhostDeploy 通用节点托管 API 的参考客户端, gds.api/1 (GDS-1 §10, spec/api/openapi.yaml)。仅使用标准库,需要 Python 3.10+。

安全模型

  • 仅 HTTPS,使用固定证书。 主机证书为自签名。您固定其 DER 字节的 SHA-256,该值由 ghostdeploy api serve 在启动时打印。
  • 客户端在 TLS 握手后、发送任何内容(包括持有者令牌)之前,以恒定时间比较指纹。
  • 不匹配时会抛出 FingerprintMismatch.
  • 没有指纹就无法创建客户端。该检查无法关闭,也不存在回退到未验证 TLS 的方式。环境代理会被忽略。
  • Bearer 令牌。 令牌格式为 gd_<id>_<secret>。它们仅发送至 Authorization 请求头,且绝不会出现在 repr().
  • 错误。 每个服务器错误都会引发一个 APIError 子类,携带 .status 和 .code。代码为 unauthorized, forbidden, not_found, bad_request, conflict, safety_refused, internal,以及参考服务器的 rate_limited。子类为 Unauthorized, Forbidden, NotFound, BadRequest, Conflict, SafetyRefused, RateLimited 和 InternalError. A 429 响应会以退避方式重试几次。
  • 不涉及任何机密材料。 没有任何方法发送或接收私钥材料。Keygen 只返回公开数据,PoP 请求只携带所有者 地址.

用法

from ghostdeploy_client import Client, verify_pop

c = Client("https://203.0.113.10:8790", fingerprint="57dc07ba...dd3", token="gd_<id>_<secret>")
c.capabilities()                      # works without a token
c.list_instances(); c.get_instance("alice"); c.status("alice"); c.events("alice", limit=50)
c.profiles(); c.benchmark(); c.offers(); c.openapi()

op = c.stop("alice")                  # also start / restart / start_signers / backup, or c.action(name, action)
c.wait_operation(op, timeout=300)     # raises OperationFailed / OperationTimeout

c.deploy("carol", "cold-smartnode", 20778, target="compose")
c.delete_instance("carol")

kg = c.smartnode_keygen("alice", "v1")
pkg = c.smartnode_pop("alice", "v1", owner="0xYourOwnerAddress")
verify_pop(pkg, expected_owner="0xYourOwnerAddress", expected_chain_id=20778)  # do this BEFORE signing

verify_pop(pop_result)

verify_pop 首先运行纯 Python 检查(verify_pop_calldata)。以下检查始终运行:

  • calldata 恰好为 0x01 || RLP([vote_pubkey(32), pop(64)])。对于轮换,它是 0x06 || RLP([rotated_id, vote_pubkey, pop]).
  • validator_id == sha256(vote_pubkey).
  • to 即登记册 0xe52c49c93523b0bc4d53de22a0631994fbcb70e9.
  • 可选的预期所有者、链和创世信息一致。

然后验证以下内容上的 ed25519 签名: sha256("PQAI-G4-POP-V1" || chainID[32 BE] || genesis[32] || owner[20] || vote_pubkey[32])。此步骤需要可选的 cryptography 包(pip install ghostdeploy-client[pop])。没有该软件包时, verify_pop 抛出 NotImplementedError,且仅在 calldata 检查通过后执行。随后可验证 verify_pop_calldata(pkg)["message"] 使用任何其他 ed25519 库。

测试

cd sdk/python
python -m unittest discover -s tests -t . -v
  • tests/test_unit.py 可离线运行。它根据从已发布版本中捕获的向量覆盖 RLP 和 PoP pqwerai-cli (internal/smartnode/testdata),以及客户端输入检查。
  • tests/test_integration.py 构建 sdk/testserver 使用 go build 并运行 真实的 internal/api 服务器(127.0.0.1),使用一次性根目录和内嵌的 20778 清单。它不访问网络,也不运行系统命令。缺少 Go 时会跳过。设置 GHOSTDEPLOY_GO 以选择工具链。
TypeScript 客户端:安全模型、用法、测试

这是 GhostDeploy 通用节点托管 API 的参考客户端, gds.api/1 (GDS-1 §10, spec/api/openapi.yaml)。在 Node 18+ 上运行,并具有 无运行时依赖。它仅使用 node:tls, node:http 和 node:crypto.

安全模型

  • 仅 HTTPS,使用固定证书。 客户端不使用 https.request 也不信任任何 CA。
  • 它自行打开 TLS 连接,使用 tls.connect.
  • 在 secureConnect 时,以恒定时间将对端 DER 证书的 SHA-256 与固定指纹进行比较。
  • 只有在指纹匹配后,才会将套接字交给 node:http (createConnection).
  • 在此之前不会写入任何请求字节,包括持有者令牌。
  • 不匹配时会抛出 FingerprintMismatchError。指纹为必填项,且检查无法禁用。
  • 无代理,无共享 agent。 每个请求均使用独立的新建固定指纹连接。
  • 错误。 服务器错误抛出 APIError 使用 .status 和 .code,这是 gds.api/1 的代码。一个 429 响应会以退避方式重试。
  • PoP 验证。 verifyPop() 始终运行所有检查,包括 ed25519 签名。Node 内置的加密模块提供 ed25519。

用法

import { Client, verifyPop } from "@ghostdeploy/client";

const c = new Client({ baseUrl: "https://203.0.113.10:8790", fingerprint: "57dc07ba...dd3", token: "gd_<id>_<secret>" });
await c.capabilities();                       // works without a token
await c.listInstances(); await c.getInstance("alice"); await c.status("alice"); await c.events("alice", 50);
await c.profiles(); await c.benchmark(); await c.offers(); await c.openapi();

const op = await c.stop("alice");             // start / restart / startSigners / backup / action(name, action)
await c.waitOperation(op, { timeoutMs: 300_000 });

await c.deploy({ name: "carol", profile: "cold-smartnode", chain_id: 20778 });
await c.deleteInstance("carol");

await c.smartnodeKeygen("alice", "v1");
const pkg = await c.smartnodePop("alice", "v1", "0xYourOwnerAddress");
verifyPop(pkg, { expectedOwner: "0xYourOwnerAddress", expectedChainId: 20778 }); // BEFORE signing

verifyPop 检查以下内容:

  • calldata 恰好为 0x01 || RLP([vote_pubkey, pop])。对于轮换,它是 0x06 || RLP([rotated_id, vote_pubkey, pop]).
  • validator_id == sha256(vote_pubkey).
  • to 是 Smartnode 登记册。
  • 可选的所有者、链和创世预期一致。
  • 以下内容上的 ed25519 签名: sha256("PQAI-G4-POP-V1" || chainID[32] || genesis[32] || owner[20] || key[32]) 有效。

构建与测试

cd sdk/typescript
npm install          # dev only: typescript + @types/node
npm test             # tsc, then node --test on dist/test/*.test.js
npm run test:src     # Node 22.18+/23.6+: run the .ts sources directly (type stripping), no build step

源代码只使用可擦除的 TypeScript 语法,并以 .ts 扩展名导入。 rewriteRelativeImportExtensions 将这些导入转换为 .js 于 dist/.

test/integration.test.ts 构建 sdk/testserver 使用 go build 并运行 真实的 internal/api 服务器(127.0.0.1),使用一次性根目录和内嵌的 20778 清单。它不访问网络,也不运行系统命令。缺少 Go 时会跳过。设置 GHOSTDEPLOY_GO 以选择工具链。