Skip to content

Instantly share code, notes, and snippets.

@je-poy
Last active July 1, 2021 02:26
Show Gist options
  • Save je-poy/e7c25ed61278a58060c7bb4cef3217e4 to your computer and use it in GitHub Desktop.
Save je-poy/e7c25ed61278a58060c7bb4cef3217e4 to your computer and use it in GitHub Desktop.
Ninjavan Webhook HASH Validation
let CryptoJS = require('crypto-js')
let headers = request.headers
let data = request.body
let ninjavanHash = headers['x-ninjavan-hmac-sha256']
let jsonString = JSON.stringify(data)
let secret = "<Client_Key>"
let hmac = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, secret);
hmac.update(jsonString);
let hash = hmac.finalize();
let calculated = CryptoJS.enc.Base64.stringify(hash);
console.log(calculated)
console.log(ninjavanHash)
console.log(calculated === ninjavanHash)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment