Blog
Request signingAuthentication

Debugging the Bytes in an Exchange Signature

Compare serialized request bytes, timestamp format, paths, and digest encoding when diagnosing exchange signatures instead of repeatedly changing credentials.

Siebly.io2 min readMarkdown

Compare Two Signing Contracts

Two JSON strings can describe the same object and produce different signatures. Whitespace, escaping, and field serialization change the bytes passed to an HMAC function. Signing one string and sending another makes the local calculation irrelevant to the request the exchange received.

A signature investigation therefore needs the exact serialization path. Changing a secret repeatedly will not repair a request body that changes after signing.

For HMAC requests, Bybit's authentication guide combines a timestamp, key, receive window, and serialized parameters. OKX authentication includes a timestamp, method, request path, and body, with a different digest representation.

The following uses synthetic values and sends no request. It illustrates why a common SHA-256 primitive does not establish a common signing contract:

signature-bytes.mjs

JavaScript
import { createHmac } from 'node:crypto';

const body = JSON.stringify({ example: 'value' });
const bybitInput = '1700000000000' + 'example-key' + '5000' + body;
const okxInput = '2023-11-14T22:13:20.000Z' + 'POST' + '/example' + body;

console.log({
  bybitHex: createHmac('sha256', 'example-secret').update(bybitInput).digest('hex'),
  okxBase64: createHmac('sha256', 'example-secret').update(okxInput).digest('base64'),
});

These are not complete authenticated API requests. Real paths, fields, credential types, and header rules come from the selected endpoint. The SDK tutorial supplies that implementation; this example isolates the input difference for debugging.

Trace Serialization Once

Start with one read-only private call. Confirm the selected API family and environment, then inspect the client configuration and any custom request or signing hooks. Check that the string signed is the same one eventually transmitted.

For a GET request, include the query exactly where the exchange's specification requires it. For a POST request, do not serialize again after signing with a different formatter. Confirm whether the digest is hexadecimal or base64 and whether the secret itself requires decoding.

A timestamp rejection is a separate failure. The clock diagnostic explains how to distinguish local clock offset from request delay.

Keep Diagnostics Out of Private Logs

Use public fixtures and synthetic secrets when recording byte-level test cases. Production logs should identify the endpoint, environment, correlation ID, and exchange error without dumping credentials, authentication headers, or sensitive account payloads.

A reproducible fixture can compare the expected serialization and signature locally. If the fixture passes while the live call fails, investigate routing, key type, permissions, and request transformations. A client initialized with the wrong API family's key cannot be repaired by a generic HMAC helper.

Related articles

Continue from here

Related Siebly resources

All articles

Subscribe on Substack

Complete the Substack form below to join our newsletter. Substack handles all subscriber data directly.