1

I am using Bold Commerce Webhooks to subscribe to subscription events in my store. They give documentation about how their request signatures are generated in PHP:

$now = time(); // current unix timestamp $json = json_encode($payload, JSON_FORCE_OBJECT); $signature = hash_hmac('sha256', $now.'.'.$json, $signingKey); 

I'm trying to recreate the hash on my side in node.js. From my research I've figured out the following so far, which I believe is pretty close, but doesn't match yet:

const hash = request.header("X-Bold-Signature")!; const SECRET = "my-secret-api-key"; const body = request.body; const time = request.header("timestamp")!; const mySignature = crypto.createHmac('sha256', SECRET).update(time + '.' + body).digest("hex"); if (mySignature !== request.header("X-Bold-Signature")!) { //... } 

I've also tried using JSON.stringify(body) which changes the hash but still doesn't match.

1 Answer 1

2

It matched with this code.

const hash = crypto .createHmac('sha256', secretKey) .update(timestamp + '.' + JSON.stringify(body)) .digest('hex'); 

Note that unlike shopify, do not use rawbody.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.