Signing requests
Request Authentication
How to get the signature of the request?
timestamp = CurrentTimestamp();
stringToSign = timestamp + ":" + endpoint;
signature = Base64 ( HMAC-SHA256 ( Base64-Decode ( clientSecret ), UTF8 ( concatenatedString ) ) );Request examples
import crypto from 'crypto';
const BASE_URL = 'https://api.fonbnk.com';
const ENDPOINT = '/api/v2/order-limits;
const CLIENT_ID = '';
const CLIENT_SECRET = '';
const generateSignature = ({
clientSecret,
timestamp,
endpoint,
}: {
clientSecret: string;
timestamp: string;
endpoint: string;
}) => {
let hmac = crypto.createHmac('sha256', Buffer.from(clientSecret, 'base64'));
let stringToSign = `${timestamp}:${endpoint}`;
hmac.update(stringToSign);
return hmac.digest('base64');
};
const main = async () => {
const timestamp = new Date().getTime();
const queryParams = new URLSearchParams({
depositPaymentChannel: 'bank',
depositCurrencyType: 'fiat',
depositCurrencyCode: 'NGN',
depositCountryIsoCode: 'NG',
payoutPaymentChannel: 'crypto',
payoutCurrencyType: 'crypto',
payoutCurrencyCode: 'CELO_USDT',
});
const endpoint = `${ENDPOINT}?${queryParams.toString()}`;
const signature = generateSignature({
clientSecret: CLIENT_SECRET,
timestamp: timestamp.toString(),
endpoint,
});
const headers = {
'Content-Type': 'application/json',
'x-client-id': CLIENT_ID,
'x-timestamp': timestamp.toString(),
'x-signature': signature,
};
const response = await fetch(`${BASE_URL}${endpoint}`, {
method: 'GET',
headers,
});
const data = await response.json();
console.log(JSON.stringify(data, null, 2));
};
main().catch(console.error);
Last updated

