身份验证
私密密钥、可公开密钥,以及测试与正式之间的界线。
尚未上线 —— api.baynoy.com 无法解析,下面的示例目前无法运行。它们描述的是我们正在实现的接口约定,本页的结构仍可能调整。
Secret keys, server-side only
A secret key (bk_test_ or bk_live_) authenticates your server and can do only what its scopes allow — and never more than the role of the person who created it. There are no publishable keys yet: the customer pays on Baynoy's hosted page, so nothing secret ever needs to reach a browser. If a secret key can reach a browser, it is already compromised.
# server-to-server: secret key, never in a browser or an app bundle
Authorization: Bearer bk_live_...Test and live are separate universes
bk_test_ keys operate on simulated money and never touch live data; bk_live_ keys move real money. There is no flag that turns one into the other, which is deliberate — the environments cannot be mixed by accident.
Scopes, signing and rolling
Each key carries the scopes you chose when you made it. Requests that move money (payouts, refunds, card actions, crypto withdrawals) are also signed with the key's signing secret in a Baynoy-Signature header, so a leaked bearer token alone cannot move money. Revoke a key whenever someone leaves or it might have been logged, and make a new one.
import { createHash, createHmac, randomUUID } from "node:crypto";
// The canonical string, line by line — exactly what the API rebuilds.
function sign({ keyId, secret, method, path, query = "", body = "" }) {
const ts = Math.floor(Date.now() / 1000);
const nonce = randomUUID();
const canonical = [
"BAYNOY-HMAC-SHA256",
method.toUpperCase(),
path, // e.g. /v1/payouts
query, // sorted k=v&k=v, or ""
createHash("sha256").update(body).digest("hex"),
String(ts),
nonce,
].join("\n");
const v1 = createHmac("sha256", secret).update(canonical).digest("hex");
return `kid=${keyId},ts=${ts},nonce=${nonce},v1=${v1}`;
}