Most webhook bugs we've run into in payment and swap integrations have nothing to do with the signature math. HMAC-SHA256 is one line in every language. The trouble starts around it: the body gets parsed before it's checked, the same event gets processed twice, or the handler does slow work before it answers.
Below is a small Express receiver and the four rules we follow when we build one. The examples assume a generic X-Signature header that carries a hex HMAC-SHA256 of the request body. Your provider may use a different header name or encoding, so check their docs before you copy anything.
1. Verify the raw body, not the parsed JSON
The provider signs the exact bytes it sends. If your framework parses the JSON first and you rebuild it with JSON.stringify , the key order, whitespace or unicode escaping can change. The HMAC stops matching, and the fix people tend to reach for at 2 a.m.…