Persona webhooks: Persona-Signature verification, event parsing,
and webhook endpoint management.
Persona signs each delivery with HMAC-SHA256 over ${t}.${raw_body}
and sends Persona-Signature: t=<unix>,v1=<hex>. While a secret is
being rotated the header holds one space-separated t=...,v1=... set
per active secret; any matching set verifies. The timestamp is signed,
so verify-request also rejects deliveries older (or newer) than a
replay window, 300 seconds by default.
Deliveries can repeat and arrive out of order: dedupe on the event id
and order by created-at. Persona retries failed deliveries (non-2xx
or slower than 5 s) up to 7 times over about 2 days.
See https://docs.withpersona.com/webhooks-best-practices.
Values
DEFAULT_TOLERANCE_SECONDS
DEFAULT_TOLERANCE_SECONDS: Int 300
Functions
archive-webhook
fn (webhook-id: Str): Map
fn (webhook-id: Str, options: Map): Map
POST /webhooks/{id}/archive - Archive a webhook endpoint.
Example
::persona::webhooks/archive-webhook("wbh_123")
construct-event
fn (request: Map): Map
fn (request: Map, secret: Str): Map
fn (request: Map, secret: Str, tolerance-seconds: Int): Map
Verify a webhook request (see verify-request) and return the parsed
event (see parse-event), or an Err when the signature is invalid or
stale.
Example
persona-webhook
meta {webhook: {service: "persona", path: "/persona/webhook"}, secret-headers: ["persona-signature"]}
fn (request) {
event ::persona::webhooks/construct-event(request)
cond {
is-err(event) => { ::hot::http/HttpResponse({status: 401, body: "invalid signature"}) }
=> {
// Dedupe on event.id, then hand the inquiry to the reviewer agent
::hot::http/HttpResponse({status: 200, body: {received: true}})
}
}
}
persona.webhook.secret
create-webhook
fn (name: Str, url: Str, enabled-events: Vec<Str>): Map
fn (name: Str, url: Str, enabled-events: Vec<Str>, opts: Map): Map
fn (name: Str, url: Str, enabled-events: Vec<Str>, opts: Map, options: Map): Map
POST /webhooks - Register a webhook endpoint. enabled-events lists
event names (["*"] for all). opts: description, api-version
(default ::persona/API_VERSION), api-key-inflection,
included-allowlist, relationship-allowlist,
file-access-token-expires-in, custom-http-headers. Persona's create
example returns status: "disabled", so call enable-webhook. The response's
attributes.secrets holds the signing secret; store it as
persona.webhook.secret.
Example
hook ::persona::webhooks/create-webhook("kyc-agent", "https://myapp.hot.dev/persona/webhook",
["inquiry.completed", "inquiry.approved", "inquiry.declined", "inquiry.marked-for-review"])
::persona::webhooks/enable-webhook(hook.data.id)
disable-webhook
fn (webhook-id: Str): Map
fn (webhook-id: Str, options: Map): Map
POST /webhooks/{id}/disable - Pause deliveries.
Example
::persona::webhooks/disable-webhook("wbh_123")
enable-webhook
fn (webhook-id: Str): Map
fn (webhook-id: Str, options: Map): Map
POST /webhooks/{id}/enable - Start deliveries.
Example
::persona::webhooks/enable-webhook("wbh_123")
event-document
fn (event: Map): Map
The event's object as a JSON:API document {data, included}, so the
::persona::decisions and ::persona::api helpers that take a document
work on it directly.
Example
event {object: {id: "inq_1", type: "inquiry", attributes: {status: "approved"}}, included: []}
doc ::persona::webhooks/event-document(event)
::persona::decisions/inquiry-decision(doc).decision // "approved"
get-webhook
fn (webhook-id: Str): Map
fn (webhook-id: Str, options: Map): Map
GET /webhooks/{id} - Retrieve a webhook endpoint.
Example
hook ::persona::webhooks/get-webhook("wbh_123")
::persona::api/attr(hook, "status")
list-webhooks
fn (): Map
fn (opts: Map): Map
fn (opts: Map, options: Map): Map
GET /webhooks - One page of webhook endpoints. opts takes page-size,
after, before.
Example
page ::persona::webhooks/list-webhooks({page-size: 25})
map(page.data, %.id)
mark-signing-secrets
fn (response: Result): Any
Mask the signing secrets in a webhook response's attributes.secrets in
call records and return the response unchanged. An Err passes through.
Exposed for testing.
Example
response ::persona::api/send("GET", "/webhooks/wbh_123", {}, null, {})
::persona::webhooks/mark-signing-secrets(response)
parse-event
fn (body: Any): Map
Flatten a webhook body (or an event from ::persona::events) into
{id, name, created-at, object-type, object-id, object, included}:
name is e.g. "inquiry.approved" or "report/watchlist.ready",
object is the resource the event is about (payload.data) and
included its related objects (empty unless the webhook's included
allowlist adds them). Works with any key inflection.
Example
e ::persona::webhooks/parse-event(::persona::events/get-event("evt_..."))
e.name // "inquiry.completed"
e.object-id // "inq_..."
parse-signature-header
fn (header: Str): Vec
Parse a Persona-Signature header into its signature sets:
[{t: Str, v1: Vec<Str>}]. Sets are separated by whitespace (one per
active secret during rotation); unknown schemes are ignored.
Example
::persona::webhooks/parse-signature-header("t=1700000000,v1=aa t=1700000000,v1=bb")
// => [{t: "1700000000", v1: ["aa"]}, {t: "1700000000", v1: ["bb"]}]
rotate-secret
fn (webhook-id: Str, expires-in-seconds: Int): Map
fn (webhook-id: Str, expires-in-seconds: Int, options: Map): Map
POST /webhooks/{id}/rotate-secret - Issue a new signing secret. The old
one keeps signing for expires-in-seconds (0, the default, expires it
now), so deliveries carry one signature set per secret meanwhile. The
new secret is in attributes.secrets; update persona.webhook.secret.
Example
// Keep the old secret signing for an hour while you update persona.webhook.secret
rotated ::persona::webhooks/rotate-secret("wbh_123", 3600)
// The new signing secret. Store it, never log it.
::persona::api/attr(rotated, "secrets")
update-webhook
fn (webhook-id: Str, attributes: Map): Map
fn (webhook-id: Str, attributes: Map, options: Map): Map
PATCH /webhooks/{id} - Update a webhook endpoint's attributes (url,
enabled-events, name, ...).
Example
::persona::webhooks/update-webhook("wbh_123", {enabled-events: ["inquiry.approved", "inquiry.declined"]})
verify-request
fn (request: Map): Bool
fn (request: Map, secret: Str): Bool
fn (request: Map, secret: Str, tolerance-seconds: Int): Bool
Verify an inbound Persona webhook: HMAC-SHA256 over
${t}.${raw_body} (::hot::http/raw-body), constant-time compared
against every v1 in every signature set, with the signed timestamp
within tolerance-seconds of now (default 300; 0 skips the check).
Uses persona.webhook.secret by default and fails when it is unset;
an empty explicit secret never verifies.
Example
persona-webhook
meta {webhook: {service: "persona", path: "/persona/webhook"}, secret-headers: ["persona-signature"]}
fn (request) {
if(not(::persona::webhooks/verify-request(request)),
::hot::http/HttpResponse({status: 401, body: "invalid signature"}),
::hot::http/HttpResponse({status: 200, body: {received: true}}))
}
persona.webhook.secret
verify-signature
fn (header: Str, raw-body: Str | Bytes, secret: Str, tolerance-seconds: Int): Bool
Verify a Persona-Signature header value against a raw body and secret,
with a replay window in seconds (0 skips the timestamp check). Fails
closed on an empty secret or header. The secret is masked in call
records. Exposed for testing; verify-request reads the header and body
from the request.
Example
persona-webhook
meta {webhook: {service: "persona", path: "/persona/webhook"}, secret-headers: ["persona-signature"]}
fn (request) {
secret ::hot::ctx/get("persona.webhook.secret")
header get(request.headers, "persona-signature")
if(::persona::webhooks/verify-signature(header, ::hot::http/raw-body(request), secret, 300), "accepted", "rejected")
}