validateRequest

View as MarkdownOpen in Claude

Verify a SignalWire webhook signature, accepting either a raw body string or pre-parsed form params. This is the drop-in replacement for the legacy @signalwire/compatibility-api validateRequest. For new code that has access to the raw body, prefer validateWebhookSignature().

1validateRequest(signingKey: string, signature: string, url: string, paramsOrRawBody: string | Record<string, unknown> | Array<[string, unknown]> | null | undefined): boolean

Parameters

signingKey
stringRequired

Your SignalWire Signing Key. An empty or non-string value throws an Error.

signature
stringRequired

The signature header value. A missing or empty value returns false.

url
stringRequired

The full URL SignalWire POSTed to.

paramsOrRawBody
string | Record<string, unknown> | Array<[string, unknown]> | null | undefinedRequired

Either the raw body string, or pre-parsed form params as a record, a Map, or an array of [key, value] tuples.

Returns

booleantrue when the signature matches; false otherwise. The comparison is constant-time.

Example

1import { validateRequest } from '@signalwire/sdk';
2
3// Pre-parsed form params (compat surface)
4const params = { From: '+15551234567', To: '+15559876543' };
5
6const ok = validateRequest(
7 process.env.SIGNALWIRE_SIGNING_KEY!,
8 signature,
9 'https://example.com/webhook',
10 params,
11);