PUBLIC SIGNING EXAMPLES
构建可核验的签名请求。
下列代码展示签名调用结构,密钥参数为占位变量。仓库 examples/signing 提供完整 Go/TypeScript 离线验证程序,使用公开合成数据和历史时间戳,不发送请求。
TypeScript
使用仓库的 apps/web/src/lib/openapi-signing.ts。签名器负责 Query 排序、RFC3986 编码、body 摘要和 base64url 密钥解码。
const result = await signRequest(
secretKeyFromSecureStorage,
{
method: "GET",
path: "/openapi/v1/domains",
raw_query: "limit=20",
body: "",
timestamp: "1700000000",
nonce: "000102030405060708090a0b0c0d0e0f",
},
);
// result.canonical 与 result.signature 只用于本地核对。Go
仓库内通过 internal/credentials 的既有签名器构建同一份请求;完整源文件位于 examples/signing/main.go。
input := credentials.SigningInput{
Method: "GET",
Path: "/openapi/v1/domains",
RawQuery: "limit=20",
Body: []byte{},
Timestamp: "1700000000",
Nonce: "000102030405060708090a0b0c0d0e0f",
}
signature, err := credentials.Sign(secretKeyBytesFromSecureStorage, input)
// 检查 err;示例不发送请求。从示例到真实调用
在服务端受控环境取得有效凭证,用实际发送的 body 字节计算签名。每次请求使用新的时间戳和至少 16 字节的随机 nonce;同一业务操作的幂等键按接口约定保留。不要将 SK、完整鉴权请求头或私钥写入日志。
完整签名规范 →幂等与未知结果 →