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…:
tis the time of this attempt, in Unix seconds. It is new on every retry.v1is a hex HMAC-SHA256 of the string<t>.<raw request body>, keyed with your secret. Use the whole secret, including itswhsec_prefix.
To verify a request:
Read the raw body bytes before any JSON parsing.
Reject the request if
tis more than 5 minutes from your clock.Compute the HMAC and compare it with each
v1value. Accept the request if any one matches. As a best practice, compare the HMAC using your language's constant-time function (crypto.timingSafeEqualin Node.js,hmac.compare_digestin 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?

