Skip to main content

Authentication

All requests must contain the following headers:

HeaderDescription
X-Api-KeyYour API key (SHA256 from public key).
X-Api-SignatureThe query's serialized body signed by your private key according to the RSA-SHA256 method.

Authenticate and send signed requests

The following code samples illustrate how to authenticate and send signed requests.

note

Node.js >= 15 is required.

const crypto = require("crypto");
const privateKeyString = "<<Your private key>>";

const privateKey = crypto.createPrivateKey({
key: privateKeyString,
format: 'der',
type: 'pkcs8',
encoding: 'hex'
});

const publicKey = crypto.createPublicKey(privateKey).export({
type: 'pkcs1',
format: 'der'
});

const message = {
"jsonrpc": "2.0",
"id": "test",
"method": "getStatus",
"params": {
"id": "psj42e728a572mtkz"
}
};

const signature = crypto.sign('sha256', Buffer.from(JSON.stringify(message)), {
key: privateKey,
type: 'pkcs8',
format: 'der'
});

// ----------------------------------

const request = require('request');
const options = {
'method': 'POST',
'url': 'https://api.changelly.com/v2',
'headers': {
'Content-Type': 'application/json',
'X-Api-Key': crypto.createHash('sha256').update(publicKey).digest('base64'),
'X-Api-Signature': signature.toString('base64')
},
body: JSON.stringify(message)
};

request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});