X Enterprises
fastify-x-signwell

xsignwell.webhooks.verifySignature

Verify the HMAC-SHA256 signature on an incoming SignWell webhook request using timing-safe comparison.

xsignwell.webhooks.verifySignature

Verify that an incoming webhook request genuinely originated from SignWell by checking its HMAC-SHA256 signature. Uses timingSafeEqual to prevent timing attacks. Always call this before processing any webhook payload.

Signature

fastify.xsignwell.webhooks.verifySignature(
  payload: string,
  signature: string,
  secret: string
): boolean

Params

NameTypeRequiredDescription
payloadstringYesRaw request body string (not parsed JSON).
signaturestringYesValue from the SignWell signature header.
secretstringYesWebhook secret from SignWell dashboard.

Returns

booleantrue if the signature is valid, false otherwise. Uses timingSafeEqual to prevent timing attacks.

Throws

  • [xSignwell] webhooks.verifySignature: payload (string) is required
  • [xSignwell] webhooks.verifySignature: signature (string) is required
  • [xSignwell] webhooks.verifySignature: secret (string) is required

Examples

Verify before processing

const isValid = fastify.xsignwell.webhooks.verifySignature(
  rawBody,
  request.headers["x-signwell-signature"],
  process.env.SIGNWELL_WEBHOOK_SECRET
);

if (!isValid) {
  return reply.code(401).send({ error: "Invalid signature" });
}

Realistic — secure webhook handler

fastify.post("/webhooks/signwell", {
  config: { rawBody: true }, // requires rawBody plugin or equivalent
}, async (request, reply) => {
  const signature = request.headers["x-signwell-signature"];
  const rawBody = request.rawBody;

  const isValid = fastify.xsignwell.webhooks.verifySignature(
    rawBody,
    signature,
    process.env.SIGNWELL_WEBHOOK_SECRET
  );

  if (!isValid) {
    return reply.code(401).send({ error: "Invalid signature" });
  }

  const event = fastify.xsignwell.webhooks.parseEvent(request.body);

  // handle event...

  return reply.send({ received: true });
});

See also


AI Context

package: "@xenterprises/fastify-xsignwell"
method: fastify.xsignwell.webhooks.verifySignature(payload, signature, secret)
use-when: Verify HMAC-SHA256 signature on an incoming SignWell webhook request before processing the payload
params: payload (raw body string), signature (from x-signwell-signature header), secret (from SignWell dashboard)
returns: boolean — true if valid, false otherwise; uses timingSafeEqual to prevent timing attacks
Copyright © 2026