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.

info

Node.js >= 18 is required.

const crypto = require('crypto');

const privateKeyString = '<<Your private key>>';

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

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

const message = {
jsonrpc: '2.0',
id: 'test',
method: 'getCurrencies',
};

const body = JSON.stringify(message);

const signature = crypto.sign('sha256', Buffer.from(body), privateKey);

(async () => {
const res = await fetch('https://api.changelly.com/v2', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Api-Key': crypto.createHash('sha256').update(publicKey).digest('base64'),
'X-Api-Signature': signature.toString('base64'),
},
body,
});

console.log(await res.text());
})();