EVENTS & DELIVERY
Keep your system in sync
Signed events, at-least-once delivery and retries. Your system owns the receiving endpoint.
Save the secret returned once when creating an endpoint. Every delivery is a POST with X-UCard-Event-Id and X-UCard-Signature: t=<unix seconds>,v1=<hex>, where v1 is HMAC-SHA256(secret, t + "." + rawBody). Verify against the raw body and allow ±300 seconds. Deduplicate by event.id and return 2xx on success. Failures retry with a widening backoff from one minute to one day, up to eight attempts, then the delivery is dead. Ordering is not guaranteed.
{
"id": "evt_…",
"type": "deposit.credited",
"data": {
"deposit_id": "dep_…",
"amount_cents": 99000
}
}Events include deposit.credited, card.created, card.updated, card.challenge_created, card.challenge_answered, transaction.*, budget.updated, withdrawal.requested, withdrawal.approved, withdrawal.rejected and withdrawal.completed (data.id is the withdrawal ID and data.address_suffix the last four characters of the address; the other data fields match Withdrawal). An endpoint URL must be HTTPS on a hostname an operator has allowlisted; anything else returns 422 webhook_url_not_allowed. Mock also accepts mock://local, a sink that records every delivery as HTTP 200 without sending anything.
import { createHmac, timingSafeEqual } from 'node:crypto';
// header = X-UCard-Signature, rawBody = the request body bytes, unparsed
const match = /^t=(\d+),v1=([a-f0-9]{64})$/.exec(header || '');
if (!match) throw Error('Invalid signature');
const [, timestamp, signatureHex] = match;
if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300)
throw Error('Expired event');
const expected = createHmac('sha256', secret)
.update(timestamp + '.').update(rawBody).digest();
const received = Buffer.from(signatureHex, 'hex');
if (received.length !== expected.length ||
!timingSafeEqual(received, expected)) throw Error('Invalid signature');GET /v1/webhook-deliveries lists delivery records with the fields id, endpoint, attempts, status (pending, retry, delivered, dead, cancelled), next_at (Unix milliseconds) and last_code (HTTP status of the last attempt, 0 when unreachable). A record holds neither the signature nor the event body; verify those on your receiver. POST /v1/webhook-deliveries/{id}/retry requeues a dead delivery; any other status returns 404 not_found. In Mock, POST /v1/mock/webhooks/deliver runs one delivery pass.