Sumsub webhook verification and event parsing.

Sumsub signs each delivery with X-Payload-Digest, the hex HMAC of the raw body keyed with the webhook's own secret key (set in the dashboard's Webhook manager; it is not the App Token secret), and names the algorithm in X-Payload-Digest-Alg: HMAC_SHA256_HEX (default for new webhooks), HMAC_SHA512_HEX, or the legacy HMAC_SHA1_HEX.

Sumsub signs no timestamp, so there is no replay window to enforce. Deliveries are retried (up to five times over about a day) and can repeat: make handlers idempotent, keyed on dedupe-key(event). Webhook payloads carry ids and review results, not personal data; fetch the applicant when you need more.

Context Vars

Optional
  • sumsub.webhook.secret

Values

ALGORITHMS

ALGORITHMS: Map {
  HMAC_SHA256_HEX: "sha256",
  HMAC_SHA512_HEX: "sha512",
  HMAC_SHA1_HEX: "sha1"
}

APPLICANT_EVENTS

APPLICANT_EVENTS: Vec [
  "applicantCreated",
  "applicantPending",
  "applicantReviewed",
  "applicantOnHold",
  "applicantPrechecked",
  "applicantAwaitingService",
  "applicantAwaitingUser",
  "applicantActionPending",
  "applicantActionReviewed",
  "applicantActionOnHold",
  "applicantActionLevelChanged",
  "applicantPersonalInfoChanged",
  "applicantTagsChanged",
  "applicantActivated",
  "applicantDeactivated",
  "applicantDeleted",
  "applicantReset",
  "applicantLevelChanged",
  "applicantRiskLevelChanged",
  "applicantStepsReset",
  "applicantPersonalDataDeleted",
  "companyStructureChanged",
  "applicantWorkflowCompleted",
  "applicantWorkflowFailed",
  "videoIdentStatusChanged",
  "videoIdentCompositionCompleted",
  "applicantVerificationLinkOpened",
  "verificationLinkSdkEvent",
  "applicantShareTokenConsumed",
  "applicantShareTokenFailed"
]

KYT_EVENTS

KYT_EVENTS: Vec [
  "applicantKytTxnCreated",
  "applicantKytTxnApproved",
  "applicantKytTxnRejected",
  "applicantKytTxnReviewed",
  "applicantKytTxnDeleted",
  "applicantKytOnHold",
  "applicantKytTxnAwaitingUser",
  "applicantKytTxnDataChanged",
  "amlCaseApproved",
  "amlCaseRejected",
  "amlCaseOnHold"
]

Functions

dedupe-key

fn (event: Map): Str

A stable key for one delivery, for idempotent handling of Sumsub's retries: the event type, applicant or transaction id, correlationId and createdAtMs, joined with |. Pure.

Example

::sumsub::webhooks/dedupe-key({type: "applicantReviewed", applicant-id: "abc", correlation-id: "c1", created-at-ms: 1700000000000})
// "applicantReviewed|abc|c1|1700000000000"

digest-algorithm

fn (alg-header: Any): Str?

The HMAC ("sha256", "sha512", "sha1") named by an X-Payload-Digest-Alg value, or null for a missing or unknown value. Exposed for testing.

Example

::sumsub::webhooks/digest-algorithm("HMAC_SHA256_HEX")  // "sha256"
::sumsub::webhooks/digest-algorithm("MD5")  // null

is-final-review

fn (event: Map): Bool

True when the event reports a completed review: applicantReviewed (or an action/transaction reviewed event) with reviewStatus completed. Map it with ::sumsub::decisions/review-outcome.

Example

::sumsub::webhooks/is-final-review({review-status: "completed", review-answer: "GREEN"})  // true
::sumsub::webhooks/is-final-review({review-status: "pending"})  // false

is-kyt-event

fn (event: Map): Bool

True for transaction-monitoring and AML case events (KYT_EVENTS).

Example

::sumsub::webhooks/is-kyt-event({type: "applicantKytTxnApproved"})  // true
::sumsub::webhooks/is-kyt-event({type: "applicantReviewed"})  // false

parse-event

fn (source: Any): Map

Normalize a webhook into a flat Map: type, applicant-id, applicant-type, external-user-id, level-name, correlation-id, review-status, review-answer (GREEN/RED), reject-type (FINAL/RETRY), reject-labels, button-ids, moderation-comment (may be shown to the applicant), client-comment (internal only), sandbox, test, created-at-ms, the transaction fields kyt-txn-id, kyt-data-txn-id, kyt-txn-type, travel-rule-status, the action fields applicant-action-id, external-action-id, and payload (the decoded body). Accepts the request, its body Map, or the raw JSON. Verify the request first.

Example

event ::sumsub::webhooks/parse-event({
  type: "applicantReviewed",
  applicantId: "abc",
  reviewStatus: "completed",
  reviewResult: {reviewAnswer: "GREEN"}
})
event.type  // "applicantReviewed"
event.applicant-id  // "abc"
event.review-answer  // "GREEN"

payload-of

fn (source: Any): Map

The decoded payload of a webhook: from a request's parsed body (or its raw body when not parsed), a Map, or a JSON Str. {} for anything that isn't a JSON object. Exposed for testing.

Example

::sumsub::webhooks/payload-of("{\"type\":\"applicantCreated\"}")  // {type: "applicantCreated"}
::sumsub::webhooks/payload-of("not json")  // {}

verify-digest

fn (secret: Str, body: Str | Bytes, digest: Str?, alg-header: Str?, allowed: Vec): Bool

Check a hex digest over the raw body in constant time. False for an empty secret, a missing digest, an unknown or missing algorithm, or an algorithm not in allowed (a Vec of X-Payload-Digest-Alg values). The secret is masked in call records. Exposed for testing; verify-request uses it.

Example

secret ::hot::ctx/get("sumsub.webhook.secret")
body "{\"type\":\"applicantReviewed\"}"
digest ::hot::hmac/hmac-sha256(secret, body)
::sumsub::webhooks/verify-digest(secret, body, digest, "HMAC_SHA256_HEX", ["HMAC_SHA256_HEX"])

verify-request

fn (request: Map): Bool
fn (request: Map, secret: Str): Bool
fn (request: Map, secret: Str, options: Map): Bool

Verify a Sumsub webhook request: X-Payload-Digest must be the hex HMAC of ::hot::http/raw-body(request) with the algorithm in X-Payload-Digest-Alg, compared in constant time. Uses the sumsub.webhook.secret context variable by default (halting when it is unset), or an explicit secret; an empty explicit secret never verifies. A request with no algorithm header fails. options.algorithms restricts the accepted algorithms (default: all three, e.g. pass ["HMAC_SHA256_HEX", "HMAC_SHA512_HEX"] to refuse legacy SHA-1).

Example

sumsub-webhook
meta {webhook: {service: "sumsub", path: "/sumsub/webhook"}}
fn (request) {
  cond {
    not(::sumsub::webhooks/verify-request(request)) => {
      ::hot::http/HttpResponse({status: 401, body: "invalid digest"})
    }
    => {
      event ::sumsub::webhooks/parse-event(request)
      ::hot::http/HttpResponse({status: 200, body: event.type})
    }
  }
}
Context Vars: sumsub.webhook.secret