Last active
July 1, 2021 02:26
-
-
Save je-poy/e7c25ed61278a58060c7bb4cef3217e4 to your computer and use it in GitHub Desktop.
Ninjavan Webhook HASH Validation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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