verifyAndDecode

fun verifyAndDecode(rawBody: String, headers: Map<String, String>, secret: String): ResendWebhookMsg

Verifies a Resend webhook request's Svix signature with the Resend SDK's Webhooks.verify, then decodes rawBody with decode.

The signature is an HMAC-SHA256 over the svix-id and svix-timestamp headers and rawBody, keyed by the webhook's signing secret. It is compared in constant time, and a timestamp more than five minutes from this host's clock is rejected. Within those five minutes the same signed delivery verifies again, and Resend resends a failed delivery with the same svix-id, so record the ids already handled and skip a repeat.

Header names are matched case-insensitively. Pass the request body exactly as received, decoded from UTF-8, which is what Ktor's call.receiveText() returns for Resend's application/json requests: a body that was parsed and re-serialized no longer matches the signature.

Return

the decoded message, once its signature has been verified

Parameters

rawBody

the request body, exactly as received

headers

the request headers; only svix-id, svix-timestamp and svix-signature are read

secret

the webhook's signing secret (whsec_...) from the Resend dashboard

Throws

ResendException

if the signature does not verify: a header is missing, the timestamp is outside the tolerance, the signature does not match, rawBody is empty, or secret is blank or not a signing secret. Nothing is decoded then.

SerializationException

if the signature verifies but rawBody is not an email.* payload; see decode


fun verifyAndDecode(rawBody: String, headers: Headers, secret: String): ResendWebhookMsg

Verifies a Resend webhook request's Svix signature, then decodes rawBody; the overload for Ktor's request Headers, for example verifyAndDecode(call.receiveText(), call.request.headers, secret).

Behaves exactly like the Map overload.

Return

the decoded message, once its signature has been verified

Parameters

rawBody

the request body, exactly as received

headers

the request headers; only svix-id, svix-timestamp and svix-signature are read

secret

the webhook's signing secret (whsec_...) from the Resend dashboard

Throws

ResendException

if the signature does not verify; nothing is decoded then

SerializationException

if the signature verifies but rawBody is not an email.* payload