Skip to content

Instantly share code, notes, and snippets.

@VivekNayyar
Last active October 23, 2019 09:34
Show Gist options
  • Save VivekNayyar/475db4060e43138df92848950aff4079 to your computer and use it in GitHub Desktop.
Save VivekNayyar/475db4060e43138df92848950aff4079 to your computer and use it in GitHub Desktop.
/**
* 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