Last active
October 23, 2019 09:34
-
-
Save VivekNayyar/475db4060e43138df92848950aff4079 to your computer and use it in GitHub Desktop.
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
/** | |
* This function will check if a particular hmac(hash) coming from the url and one generted with lead is same or not | |
* This is to make sure that the url can not be tampered with | |
* @param {String} identity This is either the lead_id or mobileNo | |
* @param {String} hash This is the generted hash in the url | |
* It will return true or false based on if the hmac's match or not | |
*/ | |
checkHash(identity, clientCode, hash) { | |
const generatedHash = crypto | |
.createHmac('sha1', hmacSalt) | |
.update(`${identity}${clientCode}`) | |
.digest('hex'); | |
return generatedHash === hash; | |
}, | |
/** | |
* This function is used to create a new hmac from identity(lead_id) and clientcode | |
* @param {String} identity lead id or mobile_no to use for generating hmac | |
* It will return a new hmac | |
*/ | |
createHmac(identity, clientCode) { | |
const generatedHash = crypto | |
.createHmac('sha1', hmacSalt) | |
.update(`${identity}${clientCode}`) | |
.digest('hex'); | |
return generatedHash; | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment