Authentification

API requests to Any.Cash are authenticated using API secret key. Any request that isn't signed with your API secret key will return an error. The signature is passed in HTTP header.

All API requests must be made over HTTPS, and plain HTTP will be refused.

Signing a request

How to get a signature:

  1. Concatenate the query string with the request body and timestamp

    1. concatenation of the string to be signed is always made like this:

      • {query_params}+{request_body}+{timestamp}

    2. if some part of the string is absent, then it is skipped (timestamp is always in place).

  2. Get the HMAC SHA512 hash from the above string using the User API Key.

  3. (optional step, if API is called by 'tenant') Get the HMAC SHA512 hash from the above hash using the Tenant API Key (it is provided by Any.Cash by separate request).

  4. Add the generated hash to the HTTP header Signature

Signature generation example

function getQueryString() {
    return request.url.split('?')[1] || '';
}

function getBodyString() {
    const payload = request.data;
    if (typeof payload === 'object') {
        if (Object.keys(payload).length) {
            return JSON.stringify(payload);
        } else {
            return '';
        }
    }
    return payload;
}

function generateSignature(
    queryString, bodyString, timestamp, userSecretKey, tenantSecretKey) {
    const str = queryString + bodyString + String(timestamp);
    const signedStr = CryptoJS.HmacSHA512(str, userSecretKey).toString();
    return tenantSecretKey
        ? CryptoJS.HmacSHA512(signedStr, tenantSecretKey).toString()
        : signedStr;
}

const queryString = getQueryString();
const bodyString = getBodyString();
const timestamp = Date.now();
const signature = generateSignature(queryString, bodyString, timestamp, userSecretKey, tenantSecretKey);

Custom headers of the requests

All requests must contain the following headers:

Header name
Description

Tenant-Api-Key

(optional, if API is called by 'tenant') Unique identifier of the calling party

Api-Key

Unique identifier of API key of a user

Signature

The signature of the request generated based on this algo

Timestamp

Timestamp of a request in milliseconds

Last updated