Cookies, your call.

A few keep Rey running. The rest show us how the site is used, and stay off until you say yes. Cookie policy

Skip to content
All articlesengineering

Signed webhooks, done right.

HMAC over the raw body, a timestamp against replays, seven attempts over a day, and handlers built for duplicates. How Rey's webhooks are designed, and how to receive them.

By Rey team3 min read

Small glowing packets of light travel along a curved path through a ring-shaped glass gate.

Why payments need webhooks

A payment does not end when the API call returns. A live provider accepts a payout and confirms it later. A settled bank transfer can come back days afterwards as a return. A person finishes identity verification whenever they get round to it. Webhooks are how Rey tells your system that something changed, without you polling for it.

They are also an open door into your system. Anyone who knows the URL can POST to it, so the design has to answer two questions. Did this really come from Rey? And what happens when delivery fails?

Proving it came from Rey

Every endpoint gets its own signing secret (whsec_…, shown once). Every delivery carries a Rey-Signature header with a timestamp and a signature:

header
Rey-Signature: t=1764072000,v1=5f2b…c9e1

v1 is the hex HMAC-SHA256 of "<t>.<raw body>", keyed with the endpoint secret. Three details make the difference between a check that works and one that only looks like it does:

  1. Sign the raw bytes. Verify against the request body exactly as it arrived, before JSON parsing. Re-serialising a parsed object changes whitespace and key order, and the signature stops matching.
  2. Compare in constant time. Use timingSafeEqual or your language's equivalent. An ordinary string comparison can leak, through timing, how many leading characters matched.
  3. Check the timestamp. The timestamp is inside the signed string, so it cannot be altered. Reject anything older than five minutes and a captured request cannot be replayed later.
node.js
import { createHmac, timingSafeEqual } from "node:crypto";

export function verifyReySignature(secret, rawBody, header, toleranceSeconds = 300) {
  const parts = Object.fromEntries(
    header.split(",").map((part) => {
      const [key, ...rest] = part.split("=");
      return [key.trim(), rest.join("=")];
    }),
  );
  const timestamp = Number(parts.t);
  if (!Number.isFinite(timestamp) || !parts.v1) return false;
  if (Math.abs(Date.now() / 1000 - timestamp) > toleranceSeconds) return false;

  const expected = createHmac("sha256", secret).update(`${timestamp}.${rawBody}`).digest();
  const received = Buffer.from(parts.v1, "hex");
  return received.length === expected.length && timingSafeEqual(received, expected);
}

When delivery fails

Endpoints go down. Deploys restart servers. Rey treats a delivery as done only when your endpoint answers with a 2xx within ten seconds. Network errors, timeouts, 429 and 5xx are retried on a schedule that front-loads the quick wins and then backs off:

Webhook delivery attempts
AttemptWhen
1Immediately
22 seconds later
38 seconds after that
410 minutes later
51 hour later
66 hours later
724 hours later

The first three run straight after the event, which covers most blips: a cold start, a dropped connection. The later four are scheduled in the database and sent by a background job, so they survive restarts and deploys on our side. Each attempt is signed afresh with a new timestamp, so a retry a day later still passes the five-minute window.

Any other non-2xx answer, such as a 400 or 401, is treated as a deliberate rejection and not retried. Redirects are not followed. Every attempt and its response status is logged in the console under Developers, so you can see exactly what Rey sent and what came back.

Receiving well

  • Expect duplicates. Retries mean the same event can arrive after you already handled it. Store processed event ids and skip repeats. This is the same idea as idempotency keys, pointed the other way.
  • Acknowledge fast, work later. Verify, record the event and return 204. Do the slow work in a queue, well inside the ten seconds.
  • Do not trust order. A retried payment.succeeded can land after a newer event. Act on the state in data, or re-read the payment.
  • Reconcile. If you ever suspect a gap, GET /payments/:id and GET /identities/:id are the source of truth.
  • Rotate secrets by adding a second endpoint with a new secret, switching over, then deleting the old one.

The events you will see

payment.processing
A live provider accepted the payout; the result follows.
payment.succeeded
The payment paid out.
payment.failed
Every attempt failed, or the rail rejected an accepted payout.
payment.returned
A settled payout came back from the beneficiary's bank.
payment.canceled
Canceled before the provider sent it; the full amount is back in your balance.
identity.*
created, approved, declined and revoked, covered in Verify once.

The full payload shapes are in the webhooks reference.

Keep reading

  • private beta, onboarding partners
  • one API across web2 and web3 rails
  • on-chain travel rule, planned

Rey

Enabling builders to move money at the speed of light.

KYC / KYB, EDD, travel rule: planned

2026 Rey, all rights reserved

built for every corridor