Examples
The examples below are test-mode examples. Replace the key locally and do not commit it. The Node sample is the same HMAC construction the server uses.
Create a testnet invoicebash
curl -s https://zenvault.world/v1/invoices \
-H "Authorization: Bearer cx_test_example" \
-H "Idempotency-Key: order_12345" \
-H "Content-Type: application/json" \
-d '{"merchantReference":"order_12345","asset":"USDT","amount":"25.50","network":"BSC"}'Verify a webhookts
import { createHmac, timingSafeEqual } from "node:crypto";
export function verifyWebhook(secret: string, header: string, rawBody: string) {
const parts = new Map(header.split(",").map((piece) => {
const index = piece.indexOf("=");
return [piece.slice(0, index), piece.slice(index + 1)] as const;
}));
const timestamp = parts.get("t");
const signature = parts.get("v1");
if (!timestamp || !signature) return false;
if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) return false;
const expected = createHmac("sha256", secret).update(`${timestamp}.${rawBody}`).digest("hex");
const left = Buffer.from(expected);
const right = Buffer.from(signature);
return left.length === right.length && timingSafeEqual(left, right);
}