For the complete documentation index, see llms.txt. This page is also available as Markdown.

Verify signatures

Confirm each request came from Violet and was not changed on the way.

Every request is signed with the webhook's signing secret, so you can confirm it came from Violet and was not changed on the way.

The Violet-Signature header looks like t=1792951514,v1=5f2b…:

  • t is the time of this attempt, in Unix seconds. It is new on every retry.

  • v1 is a hex HMAC-SHA256 of the string <t>.<raw request body>, keyed with your secret. Use the whole secret, including its whsec_ prefix.

To verify a request:

  1. Read the raw body bytes before any JSON parsing.

  2. Reject the request if t is more than 5 minutes from your clock.

  3. Compute the HMAC and compare it with each v1 value. Accept the request if any one matches. As a best practice, compare the HMAC using your language's constant-time function (crypto.timingSafeEqual in Node.js, hmac.compare_digest in Python) rather than ==, so response times can't hint at how close a forged signature is.

import { createHmac, timingSafeEqual } from 'node:crypto';

export function verify(rawBody, header, secret, toleranceSeconds = 300) {
  const parts = header.split(',').map((p) => p.split('='));
  const t = Number(parts.find(([k]) => k === 't')?.[1]);
  if (!t || Math.abs(Date.now() / 1000 - t) > toleranceSeconds) return false;
  const expected = createHmac('sha256', secret).update(`${t}.${rawBody}`).digest();
  return parts
    .filter(([k]) => k === 'v1')
    .some(([, sig]) => {
      const given = Buffer.from(sig, 'hex');
      return given.length === expected.length && timingSafeEqual(given, expected);
    });
}
import hashlib, hmac, time

def verify(raw_body: bytes, header: str, secret: str, tolerance_seconds: int = 300) -> bool:
    parts = [p.split("=", 1) for p in header.split(",")]
    t = next((v for k, v in parts if k == "t"), None)
    if not t or abs(time.time() - int(t)) > tolerance_seconds:
        return False
    expected = hmac.new(secret.encode(), t.encode() + b"." + raw_body, hashlib.sha256).hexdigest()
    return any(hmac.compare_digest(v, expected) for k, v in parts if k == "v1")

Rotating the secret

The secret is shown once, when you create the webhook or rotate its secret. For 24 hours after a rotation, requests carry two v1 values: one signed with the new secret and one with the old. Switch your receiver to the new secret within that window.

Only the latest rotation keeps the old secret signing. If you rotate twice within 24 hours, the first old secret stops working at once, so switch to the newest secret before rotating again.

Custom headers are not part of the signature; the signature covers the body only.

Was this helpful?