Created
May 28, 2020 09:32
-
-
Save stpe/5f3fffcebf3ecfd931dc5d1e4fec7166 to your computer and use it in GitHub Desktop.
How to calculate Clearbit API webhook X-Request-Signature in Node.js / JavaScript / TypeScript
This file contains hidden or 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
import * as crypto from 'crypto'; | |
export class ClearbitSignatureValidation { | |
static getSignature(raw_body: string, signature: string): string { | |
const signature_without_prefix = signature.replace(/^(sk\_)/, ''); | |
return ( | |
'sha1=' + | |
crypto | |
.createHmac('sha1', signature_without_prefix) | |
.update(raw_body) | |
.digest('hex') | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment