OnLink
Get started

Authentication

Four headers and an HMAC-SHA256 signature over five newline-joined fields. A worked example with a signature you can check your own code against.

Every request carries four headers. There is no bearer token, no session and no OAuth flow — a client built around one will not work.

The four headers

HeaderValue
X-OnLink-KeyYour key id: pk_ followed by 24 hex characters.
X-OnLink-TimestampCurrent unix time in milliseconds, as a string.
X-OnLink-NonceUnique per request. At most 64 characters, and it may not contain :.
X-OnLink-Signaturev1= followed by the lowercase hex HMAC-SHA256 described below.

The string to sign

Five fields, joined with \n, in this exact order, with no trailing newline:

<METHOD>
<path including query string>
<unix milliseconds>
<nonce>
<lowercase hex sha256 of the raw request body>

The signature is HMAC-SHA256(your secret, that string), lowercase hex, sent as X-OnLink-Signature: v1=<hex>.

Four rules decide whether your signature matches:

  1. The method is upper-cased. POST, not post.
  2. The path includes the query string. /v1/orders/abc?expand=payment signs exactly that, not /v1/orders/abc. This is the single most common mistake.
  3. The timestamp is milliseconds, and it must be within 5 minutes of our clock in either direction.
  4. An empty body still hashes. A GET signs sha256("") = e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 — never an empty field, never an omitted line.

Every auth failure is the same 401

A bad signature, an expired timestamp, a replayed nonce and an unknown key all return 401 {"error":"unauthorized"} with no reason given. That is deliberate — a specific reason tells an attacker which half of a guess was right — but it means you cannot debug this from the response. Check your signing string against the worked example below instead. The one exception is a multipart upload whose X-Body-SHA256 header is missing, malformed or does not match the body: each says so, because it describes your own request. See Signing a multipart upload.

A multipart upload signs the digest of its bytes

The two calls that take multipart/form-data, POST /v1/customers/{id}/kyc and POST /v1/customers/{id}/kyb/documents, sign the sha256 of the multipart bytes you send as their body hash, and send that same digest in an X-Body-SHA256 header. The signature then covers every field and every file. Every other call signs the exact JSON body it sends. See Signing a multipart upload.

Nonces and replay

Each nonce is claimed for 11 minutes. Reusing one inside that window is rejected as a replay, so generate a fresh value per request — a UUID is fine. The window is twice the timestamp tolerance plus a minute, so a request that is still within the clock window cannot outlive its own replay guard.

Worked example

These inputs produce exactly the signature below. Run your implementation against them: if you get the same 64 hex characters, your signer is correct.

secret     sk_sandbox_EXAMPLE_0123456789abcdef0123456789abcdef
method     POST
path       /v1/quotes
timestamp  1767225600000
nonce      9f8c1d4e-2b7a-4c31-8e55-6a0f2d1b3c47
body       {"side":"sell","usdtAmount":"250.000000"}

The intermediate body hash:

2ce693efd7392574c914f1c87fb6602fec408082a85e857bc61c2e0352d493f5

The string that gets signed, with real newlines between the five fields:

POST
/v1/quotes
1767225600000
9f8c1d4e-2b7a-4c31-8e55-6a0f2d1b3c47
2ce693efd7392574c914f1c87fb6602fec408082a85e857bc61c2e0352d493f5

And the signature:

v1=14bce29a5c8181adbff7d874d99c974f710d388098e4345c4eedbe28adb7e711
const crypto = require('node:crypto');

function signOnLinkRequest({ secret, method, path, body = '' }) {
  const timestamp = String(Date.now());
  const nonce = crypto.randomUUID();
  const bodySha256Hex = crypto.createHash('sha256').update(body).digest('hex');

  // Five fields, newline-joined, in this order. The method is upper-cased and
  // the path carries its query string; both are inside the signature so a
  // captured one cannot be replayed against another route.
  const signingString = [
    method.toUpperCase(),
    path,
    timestamp,
    nonce,
    bodySha256Hex,
  ].join('\n');

  const signature = crypto
    .createHmac('sha256', secret)
    .update(signingString)
    .digest('hex');

  return {
    'X-OnLink-Key': process.env.ONLINK_KEY_ID,
    'X-OnLink-Timestamp': timestamp,
    'X-OnLink-Nonce': nonce,
    'X-OnLink-Signature': `v1=${signature}`,
    'Content-Type': 'application/json',
  };
}

Sign the bytes you send

Hash the exact body string you put on the wire. If you build the signature from one object and then re-serialise it for the request, a difference in key order or spacing changes the hash and the signature will not match.

Signing a multipart upload

POST /v1/customers/{id}/kyc takes multipart/form-data: a customer's details as form fields and three images as file parts. POST /v1/customers/{id}/kyb/documents takes it too: the document type as a form field and the file as one part. Both are signed like every other request, with one difference in where the fifth field comes from, and one extra header.

HeaderValue
X-Body-SHA256The lowercase hex sha256 of the exact multipart bytes you send: 64 characters. The same string you put on the fifth line of the string to sign.
  1. The body hash is the sha256 of the raw multipart bytes, boundary lines and all, exactly as they go on the wire. It is the fifth field of the string to sign, in the same place as for a JSON body.
  2. Send that digest in X-Body-SHA256. It must be 64 lowercase hex characters, and it must be the same string you signed. We check the signature with it, then hash the body we actually received and compare: a field or an image changed after you signed is refused before anything is read or saved.
  3. Serialise the form once, then hash and send those bytes. Your HTTP library picks the multipart boundary when it encodes the form, so hashing a form object and letting the library encode it afterwards produces a different body and a digest that does not match. The samples serialise first, then send the resulting bytes with the Content-Type that came with them.
const crypto = require('node:crypto');

async function signOnLinkMultipart({ secret, path, form }) {
  // Serialise the form ONCE. These exact bytes are what you hash and what you send.
  const encoded = new Response(form);
  const contentType = encoded.headers.get('content-type');
  const body = Buffer.from(await encoded.arrayBuffer());

  const timestamp = String(Date.now());
  const nonce = crypto.randomUUID();
  const bodySha256Hex = crypto.createHash('sha256').update(body).digest('hex');

  // The same five fields in the same order. Only the last one is new: it is the
  // digest of the multipart bytes rather than of a JSON string.
  const signingString = ['POST', path, timestamp, nonce, bodySha256Hex].join(
    '\n',
  );
  const signature = crypto
    .createHmac('sha256', secret)
    .update(signingString)
    .digest('hex');

  return {
    body,
    headers: {
      'X-OnLink-Key': process.env.ONLINK_KEY_ID,
      'X-OnLink-Timestamp': timestamp,
      'X-OnLink-Nonce': nonce,
      'X-OnLink-Signature': `v1=${signature}`,
      // The digest you signed, so we can check it against the bytes we receive.
      'X-Body-SHA256': bodySha256Hex,
      // Carries the boundary of the bytes above. Do not set your own.
      'Content-Type': contentType,
    },
  };
}

async function sendOnLinkMultipart({ baseUrl, secret, path, form }) {
  const { body, headers } = await signOnLinkMultipart({ secret, path, form });
  // Send the exact bytes that were hashed, with the headers returned beside them.
  // Passing the FormData itself here would encode it again, with a new boundary.
  const response = await fetch(baseUrl + path, {
    method: 'POST',
    headers,
    body,
  });
  return response;
}

An upload that goes wrong in these ways says which, in message as well as errorCode, because the reason describes your own request:

StatusmessageCauseWhat to do
401body_digest_missingThere is no X-Body-SHA256 header on the multipart request.Send the header, with the digest you signed.
401body_digest_malformedX-Body-SHA256 is there but is not 64 lowercase hex characters: upper case, a sha256: prefix, base64, padding or an empty value.Send the plain lowercase hex digest, exactly as you signed it.
401body_digest_mismatchThe body we received does not hash to the X-Body-SHA256 you signed: it changed between hashing and sending, or the library re-encoded it.Serialise once and send those bytes. The nonce is spent, so sign again with a fresh nonce.

Every other failure on this call is the uniform 401 {"error":"unauthorized"} described above. A digest that matches the body but was not the one signed is one of those: it fails as an ordinary signature mismatch, so check that the fifth line of your string to sign and the header are the same string.

Only these two calls are different

Every JSON call, and every GET, signs exactly the body it sends, as in the worked example above, and takes no X-Body-SHA256 header.

If you get a 401

In order of likelihood:

  • the query string was omitted from the signed path;
  • the timestamp was in seconds, not milliseconds;
  • the body was re-serialised between hashing and sending;
  • an empty body was signed as an empty field rather than sha256("");
  • for a multipart upload, X-Body-SHA256 was left off or is not lowercase hex, or the form was encoded twice, with a different boundary each time (see the section above);
  • the nonce was reused;
  • the key id and secret are from different pairs.

Verify against the worked example above before you look anywhere else — it isolates your signer from your HTTP client entirely.

Next: make your first call.

On this page