• GuideBreaking change in 2.0.0: the tax ID is required
  • GuideAccess
  • GuideKey scopes
  • GuideLocking a key to your network addresses
  • GuideErrors
  • GuideRate limits
  • GuideSafe retries (Idempotency-Key)
  • GuidePages
  • GuideWebhooks
  • GuideCheck the signature
  • GuideA receiver to start from
  • GuideSandbox
  • RecipeYour first call in 5 minutesMake a sandbox key and list your merchants.
  • RecipeStart a review and wait for review.readyStart a website review, get told when it is done, read the findings and download the report.
  • RecipeVerify webhook signaturesProve a delivery came from Kvali, answer fast and handle retries once.
  • RecipeSend a merchant's documentsUpload a registration certificate or bank letter in two steps.
  • RecipeMonitoring: checks, changes, alerts, violationsLearn what monitoring found about your live merchants, without missing or repeating a row.
  • RecipeRetries, idempotency, pages and rate limitsA small client that retries safely, pages through lists and stays under the limit.
  • RecipeLock a key to your network addressesMake a stolen key useless outside your own network.
  • RecipeFrom sandbox to liveThe checks to pass in the sandbox, then the switch to production keys.

↑ ↓ to move · Enter to open · Esc to close

Verify webhook signatures

Prove a delivery came from Kvali, answer fast and handle retries once.

20 minAny key

What you get

  • A receiver that refuses anything not signed by Kvali, or older than 5 minutes.
  • Retries handled once, by the delivery id.
  • A way to test it before you have a key.
  1. Add your endpoint

    In Settings → API → Webhooks, add your public https:// address and choose the events. Copy the signing secret (whsec_…): it is shown once. Keep it in an environment variable.

    Code
    export KVALI_WEBHOOK_SECRET="whsec_…"
  2. Check the signature on the raw body

    Each delivery carries Kvali-Signature: t=<unix seconds>,v1=<hex>. Compute HMAC-SHA256 of <t>.<raw body> with your secret and compare it with v1 in constant time. Use the body exactly as it arrived: parsing and re-serialising the JSON changes the bytes and breaks the check. Refuse a t more than 5 minutes from your clock.

    Code
    import { createHmac, timingSafeEqual } from "node:crypto";
    
    // rawBody: the request body exactly as received (before JSON parsing).
    function isFromKvali(rawBody, header, secret, nowSeconds = Date.now() / 1000) {
      const parts = Object.fromEntries(String(header ?? "").split(",").map((p) => p.split("=")));
      const t = Number(parts.t);
      if (!Number.isFinite(t) || !parts.v1 || Math.abs(nowSeconds - t) > 300) return false; // missing, or older than 5 minutes
      const expected = createHmac("sha256", secret).update(`${parts.t}.${rawBody}`).digest();
      const given = Buffer.from(parts.v1, "hex");
      return given.length === expected.length && timingSafeEqual(given, expected);
    }
  3. Answer at once, then work

    Answer any 2xx within 10 seconds and do the real work afterwards. Anything else is retried after 1 min, 5 min, 30 min, 2 h, 6 h, 12 h, then marked failed. A retry carries the same id (also in the Kvali-Delivery header): keep the ids you handled, with a unique index, and skip a repeat.

    Code
    import { createServer } from "node:http";
    
    const secret = process.env.KVALI_WEBHOOK_SECRET;
    const handled = new Set(); // in production: a table with a unique index on the delivery id
    
    createServer((req, res) => {
      const chunks = [];
      req.on("data", (c) => chunks.push(c));
      req.on("end", () => {
        const raw = Buffer.concat(chunks).toString("utf8");
        if (!isFromKvali(raw, req.headers["kvali-signature"], secret)) return res.writeHead(401).end();
        const delivery = JSON.parse(raw);
        res.writeHead(200).end(); // answer first
        if (handled.has(delivery.id)) return; // a retry you already handled
        handled.add(delivery.id);
        setImmediate(() => handle(delivery)); // e.g. on review.ready: GET /reviews/{id}
      });
    }).listen(8080);
  4. Test before you have a key

    GET /webhook-examples.json (no key) returns a signed sample of every event with its exact raw_body, its headers and the test secret it was signed with. Check each with your clock set to the sample's t, then change one byte and make sure your check refuses it. The full receiver is in the reference under "A receiver to start from".

    Code
    curl "https://aikvali.com/api/v1/webhook-examples.json"
  5. See what was sent, and send one again

    GET /webhooks/deliveries lists what Kvali sent and how your receiver answered (status=failed for the ones that gave up). After fixing your receiver, POST /webhooks/deliveries/{id}/replay sends one again with the same id and body.

    Code
    curl "https://aikvali.com/api/v1/webhooks/deliveries?status=failed&limit=25" \
      -H "Authorization: Bearer $KVALI_KEY"