这是 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 以选择工具链。