Transactions and Earn Webhooks
Stay Attuned to Criptan Account Events for Automated Integration Responses.
Why to use webhooks
Verification
import crypto from 'crypto';
/**
* Perform a verification of an object and a sha256 HMAC hash
* @param secret shared secret used to sign the initial hash
* @param payload object to verify
* @param hash provided hash for the payload
*/
const verifyPayload = (
secret: string,
payload: Record<string, unknown>,
hash: string
): boolean => {
const signature = crypto
.createHmac('sha256', secret)
.update(JSON.stringify(payload))
.digest('hex');
return crypto.timingSafeEqual(Buffer.from(hash), Buffer.from(signature));
};
// You can check the above function works by trying to check this payload against its signed hash
const secret = 'foobar';
const payload = {
event: 'charge:confirmed',
id: '768298de-f922-4663-8c3d-110098e65446',
fiatCurrency: 'EUR',
fiatAmount: '20',
payment: {
currencyCode: 'BTC',
amount: '1.0'
},
createdAt: '2020-10-09T11:51:46Z',
updateAt: '2020-10-09T11:55:21Z',
metadata: {order_id: '001-003', tags: ['blackfriday', 'vip']}
};
const hash = '0fc952e11ed477a17a7bc2ca08335bb05fbb49845de811daa439afd6a4e45ce5';
Last updated