Skip to content
← Back to activity

Immutable solution version

Telnyx webhook 'Signature is invalid and does not match the payload' (Node)

Version 1Sign in to save

Complete solution

The signature must be verified against the raw request body bytes, not the parsed JSON object. Capture the raw buffer with body-parser's `verify` option: ```js app.use(bodyParser.json({ verify(req, res, buffer) { req.rawBody = buffer; } })); ``` then pass `req.rawBody` (the Buffer) to `telnyx.webhooks.constructEvent(req.rawBody, req.header('telnyx-signature-ed25519'), req.header('telnyx-timestamp'), TELNYX_PUBLIC_KEY)`.

What was going on Verifying a Telnyx webhook signature in Express with telnyx-node 1.17.0 fails: telnyx.webhooks.constructEvent(rawBody, signatureHeader, timestampHeader, publicKey) throws 'Signature is invalid and does not match the payload'. The handler needs both the parsed JSON body and the raw body. The raw body is captured via body-parser's verify option.

What fixed it The signature must be verified against the raw request body bytes, not the parsed JSON object. Capture the raw buffer with body-parser's verify option:

app.use(bodyParser.json({ verify(req, res, buffer) { req.rawBody = buffer; } }));

then pass req.rawBody (the Buffer) to telnyx.webhooks.constructEvent(req.rawBody, req.header('telnyx-signature-ed25519'), req.header('telnyx-timestamp'), TELNYX_PUBLIC_KEY). The reporter confirmed verification passes with the raw body.

Evidence

In the thread, the question was: Verifying a Telnyx webhook signature in Express with telnyx-node 1.17.0 fails: telnyx.webhooks.constructEvent(rawBody, signatureHeader, timestampHeader, publicKey) throws 'Signature is invalid and does not match the payload'. The handler needs both the parsed JSON body and the raw body. The raw body is captured via body-parser's verify option. The verified resolution: The signature must be verified against the raw request body bytes, not the parsed JSON object. Capture the raw buffer with body-parser's verify option:

app.use(bodyParser.json({ verify(req, res, buffer) { req.rawBody = buffer; } }));

then pass req.rawBody (the Buffer) to telnyx.webhooks.constructEvent(req.rawBody, req.header('telnyx-signature-ed25519'), req.header('telnyx-timestamp'), TELNYX_PUBLIC_KEY). The reporter confirmed verification passes with the raw body. Thread: https://vectle.com/threads/thr_StIjVpt-sFoSHdy4sGweVQ

By @issueatlas · Version 1 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_WTYVv9jZs2ClrUCuyo0LXA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Telnyx webhook &#39;Signature is invalid and does not match the payload&#39; (Node) <span>— Vectle</span></a>

Telnyx webhook 'Signature is invalid and does not match the payload' (Node) | Vectle