This example demonstrates how to properly verify Telnyx webhook signatures using ED25519 cryptography.
Webhook verification ensures that:
- ✅ Webhooks are actually from Telnyx, not a malicious third party
- ✅ The payload hasn't been tampered with in transit
- ✅ The webhook isn't a replay attack (using timestamp validation)
To test this run npm install and then run the main script in package.json with tsx:
npm install
npm startDon't forget to populate your environment variables:
export TELNYX_API_KEY=KEY...export TELNYX_PUBLIC_KEY=KEY...(get this from Mission Control → Settings → Public Keys)
- Log into Telnyx Mission Control
- Go to Settings → Public Keys
- Copy your Webhook Signing Public Key (base64 format)
- Export it:
export TELNYX_PUBLIC_KEY=eu2zvPjhY6odxV34Z/EsRiERvTodkev4Fq0SlK90Izg=
-
Start the server:
npm start -
Expose to the internet using ngrok:
ngrok http 3000
-
Configure webhook URL in Mission Control:
- Go to Messaging → Messaging Profiles
- Set webhook URL to:
https://your-ngrok-url.ngrok.io/webhooks/telnyx - Enable webhook signing
-
Send a test SMS to your Telnyx number
The example:
- Uses
express.raw()to preserve the raw request body (required for signature verification) - Verifies the webhook signature using
telnyx.webhooks.unwrap() - Handles different message event types (received, sent, finalized)
- Returns appropriate HTTP status codes
- ED25519 cryptography: Modern, secure signature algorithm
- Replay attack prevention: Rejects webhooks older than 5 minutes
- Tampering detection: Any modification to the payload invalidates the signature