XPayLabs authenticates every API request using HMAC-SHA256 request signing. Unlike traditional Bearer token authentication, XPayLabs requires each request to include a cryptographic signature computed over the request payload. This ensures request integrity and prevents replay attacks.Documentation Index
Fetch the complete documentation index at: https://docs.xpaylabs.com/llms.txt
Use this file to discover all available pages before exploring further.
How It Works
Every API request includes aReqPayload wrapper with four fields:
| Field | Type | Description |
|---|---|---|
sign | string | HMAC-SHA256 signature of the stringified data object |
timestamp | integer | Unix timestamp (seconds) of when the request was created |
nonce | string | A unique random string, never reused |
data | object | The actual request payload |
sign field is computed using your merchant token as the HMAC secret key.
Computing the Signature
Algorithm
- Serialize the
dataobject as a JSON string (no pretty-printing, no extra whitespace). - Compute
HMAC-SHA256(data_json, merchant_token). - Convert the result to a lowercase hex string.
- Set this value as the
signfield.
Node.js
Python
Go
Timestamp and Nonce Requirements
Thetimestamp and nonce fields prevent replay attacks:
- Timestamp: Your server clock must be within 5 minutes of XPayLabs server time. Requests with timestamps older than 5 minutes are rejected.
- Nonce: Each request must use a unique nonce. XPayLabs tracks used nonces and rejects duplicates. UUIDs or cryptographically random strings work well.
Verification (Server-Side)
XPayLabs verifies every request by recomputing the HMAC-SHA256 signature using your stored merchant token. If the signatures don’t match, or if the timestamp is outside the tolerance window, the request is rejected with a401 Unauthorized response.
Keeping Your Merchant Token Secure
- Store your merchant token in an environment variable or secrets manager.
- Never hardcode the token in source code or client-side applications.
- Rotate the token periodically and update your configuration.
- The token is a shared secret between your merchant server and the XPayLabs gateway. It is not sent over the network in API requests.

