For the complete documentation index, see llms.txt. This page is also available as Markdown.

Examples

Node.js HMAC authentication snippets. For a full integration sample with viem (self-submit tx, ERC-20 approve, One Click signTypedData), see guides/demo-code.md.

HMAC helper

import crypto from "node:crypto";

function canonicalUri(path, query = {}) {
  const pairs = [];
  for (const key of Object.keys(query).sort()) {
    const value = query[key];
    if (Array.isArray(value)) {
      for (const item of value) pairs.push(`${key}=${item}`);
    } else if (value !== undefined && value !== null) {
      pairs.push(`${key}=${value}`);
    }
  }
  return pairs.length === 0 ? path : `${path}?${pairs.join("&")}`;
}

function signTradingApi({ method, path, query, timestamp, nonce, rawBody, apiSecret }) {
  const uri = canonicalUri(path, query);
  const payload = [
    method.toUpperCase(),
    uri,
    String(timestamp),
    nonce,
    rawBody ?? ""
  ].join("\n");

  return crypto
    .createHmac("sha256", apiSecret)
    .update(payload, "utf8")
    .digest("hex");
}

Signed POST example

cURL with HMAC

See also signature.md for Python and HMAC authentication details, and guides/demo-code.md for viem integration.

Last updated