Following this
I was getting error – Unhandled promise rejection (rejection id: 2): TypeError: First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object
So I changed to
var msg = JSON.stringify(req.rawBody);
var digest = crypto.createHmac('sha256', APP_SHARED_SECRET)
.update(Buffer.from(msg,'utf8'))
.digest('base64');
The signature (hmac-sha256) generated is different then what I am receiving in the request header !
Any clue or pointers will be helpful.
3
Answers
You would probably want to use JSON.parse, instead of JSON.stringify, to parse the message before performing any other actions.
I’m dealing with a similar issue, but you want to use
For anyone still looking for a solution, this is what worked for me
I was using Serverless function in Vercel, hence I used the external npm package
raw-body
to get the correct raw bodyNotes
req.body
is a parsed object andJSON.stringify
messes up the original payload.crypto.timingSafeEqual
, this function prevents leaking time information to the extent.