RelayrtcDocs
Get started
Documentation
Node SDK

verifyWebhookRequest

Verify the original body and signed headers before processing a webhook.

On this page

Import

TypeScript
import { verifyWebhookRequest } from '@relayrtc/node'

Signature

TypeScript
import type { WebhookHeaders, WebhookVerificationOptions } from '@relayrtc/node'
 
type VerifySignature = (
  secret: string,
  rawBody: string | Uint8Array,
  headers: WebhookHeaders,
  options?: WebhookVerificationOptions,
) => boolean
 
const verify: VerifySignature = verifyWebhookRequest

Parameters

OptionTypeDefault / requirementPurpose
secretstringRequiredFull whsec_ signing secret returned by endpoint creation or rotation.
rawBodystring or Uint8ArrayRequiredUnmodified body bytes. A Node Buffer is accepted.
headersHeaders or readonly header recordRequiredIncoming request headers.
options.nowDateCurrent timeClock override, useful for controlled verification.
options.toleranceSecondsinteger300Allowed clock difference, 1–300 seconds.

Example

TypeScript
export async function verifyIncomingRequest(request: Request, secret: string) {
  const rawRequestBody = new Uint8Array(await request.arrayBuffer())
  const valid = verifyWebhookRequest(secret, rawRequestBody, request.headers)
  if (!valid) throw new Error('Invalid webhook signature')
  return rawRequestBody
}

rawRequestBody must be captured before a JSON parser rewrites the body. See the receiver example.

Returns

A boolean. Invalid secret format, missing/duplicate headers, malformed signature, stale timestamp or mismatched digest returns false.

Headers

HeaderPurpose
x-relayrtc-signatureSignature string with timestamp.
x-relayrtc-delivery-idDelivery ID included in the signed content.
x-relayrtc-replay-countReplay count included in the signed content.
x-relayrtc-signing-key-versionInformational secret version; not part of the verifier’s signed input.

Signature format is t=TIMESTAMP,v1=HEX_DIGEST.

The HMAC-SHA256 input is the ASCII prefix TIMESTAMP.DELIVERY_ID.REPLAY_COUNT. followed by the original body bytes. The HMAC key is the complete signing secret string, including whsec_; do not decode its suffix as a separate key.

Processing events

Signature verification authenticates a delivery. It does not prevent duplicate processing. Store each event ID atomically with its side effects and processing result.