Verify webhook signatures

Every webhook has a QwikiPay-Signature header:

QwikiPay-Signature: t=1764843300,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd
  • t is the Unix time we sent it.
  • v1 is an HMAC-SHA256, in hex, of t + . + the raw request body, keyed with that business's signing secret (on its page under Businesses → Webhook).

To verify:

  1. Compute the HMAC yourself from the raw body — not a re-encoded copy of the parsed JSON.
  2. Compare it to v1 with a constant-time comparison.
  3. Reject the request if t is more than 5 minutes old, so a captured webhook can't be replayed later.

Python

import hashlib
import hmac
import time


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

PHP

function verify_qwikipay(string $rawBody, string $header, string $secret, int $tolerance = 300): bool
{
    $parts = [];
    foreach (explode(',', $header) as $pair) {
        [$key, $value] = array_pad(explode('=', $pair, 2), 2, null);
        $parts[$key] = $value;
    }
    if (!isset($parts['t'], $parts['v1']) || abs(time() - (int) $parts['t']) > $tolerance) {
        return false;
    }
    $expected = hash_hmac('sha256', $parts['t'] . '.' . $rawBody, $secret);
    return hash_equals($expected, $parts['v1']);
}

// $rawBody = file_get_contents('php://input');

Node.js

import crypto from 'node:crypto'

export function verifyQwikipay(rawBody, header, secret, tolerance = 300) {
  const parts = Object.fromEntries(header.split(',').map((p) => [p.slice(0, p.indexOf('=')), p.slice(p.indexOf('=') + 1)]))
  if (!parts.t || !parts.v1) return false
  if (Math.abs(Date.now() / 1000 - Number(parts.t)) > tolerance) return false
  const expected = crypto.createHmac('sha256', secret).update(`${parts.t}.${rawBody}`).digest('hex')
  return expected.length === parts.v1.length && crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(parts.v1))
}

// Express: use express.raw({ type: 'application/json' }) on this route so rawBody is the exact bytes.