Module for verifing Coinpaymets Instant Payment notifications.
npm install coinpayments-ipn
/**
*
* @param {String} hmac
* @param {String} ipnSecret
* @param {Object} payload
* @returns {Boolean}
* @throws {CoinpaymentsIPNError}
*/
const { verify } = require('coinpayments-ipn');
const CoinpaymentsIPNError = require('coinpayments-ipn/lib/error');
let isValid, error;
try {
isValid = verify(hmac, ipnSecret, payload);
} catch (e) {
error = e;
}
if (error) {
if (error instanceof CoinpaymentsIPNError) {
// handle invalid payload
}
// make bug report
}
if (isValid) {
// valid
} else {
// invalid
}
A simple docker image can be found here.