Created
September 8, 2023 03:09
-
-
Save rickithadi/a646ce4bf232edd8dbd472221373ad5a to your computer and use it in GitHub Desktop.
dpay webhook signature verification
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
try { | |
let hmac = crypto | |
.createHmac( | |
"sha256", | |
process.env.NODE_ENV === "production" | |
? process.env.LIVE_DPAY_KEY | |
: process.env.STAGING_DPAY_KEY | |
) | |
.update(`${data.id}|${data.amount_str}`) | |
.digest("hex"); | |
const signatureOk = data.signature === hmac; | |
if (!signatureOk) { | |
console.log("signatures dont tally \n", data.signature, "\n", hmac); | |
return res.send("Error, signature verification failed").status(420); | |
} | |
} catch (e) { | |
console.log("cannot get signature", e); | |
return res.send("Error, signature verification failed").status(420); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment