Skip to content
Jennifer Programming Language

webhook API reference

Sign and verify HMAC-signed webhooks - the GitHub-style X-Hub-Signature-256 convention. A sender computes sha256=<hex>, the hex HMAC-SHA256 of the exact request body keyed by a shared secret, and sends it in a header; a receiver recomputes it and compares, confirming the delivery is authentic and untampered. Every function is pure, and the module imports no network module, so it runs on both binaries. To deliver a webhook, POST the body with the signedHeaders map through http (default binary).

Import with import "webhook.j" as webhook;. See the webhook guide for prose and examples.

Contents

NameWhat it is
signSign a payload: sha256= followed by the hex HMAC-SHA256 of the payload keyed by the shared secret - the v...
signedHeadersThe headers that sign a webhook delivery: X-Hub-Signature-256 set to sign(payload, secret).
slackSignSign a payload the Slack way: the signed base string is "v0:" + <timestamp> + ":" + <body>, HMAC-SHA256, ...
slackVerifyVerify a Slack v0=... signature against a body, secret, and the request timestamp (from...
stripeSignSign a payload the Stripe way: the signed base string is <timestamp> + "." + <body>, HMAC-SHA256, hex-enc...
stripeVerifyVerify a Stripe t=...,v1=... signature header against a body and secret.
timestampedSignGeneric timestamped HMAC signature: sign <timestamp> + "." + <body> with a caller-chosen digest and text ...
timestampedVerifyVerify a generic timestamped HMAC signature (see timestampedSign) with a constant-time compare and a repl...
verifyVerify a signature against a payload and secret, with a constant-time compare.

Functions

sign

jennifer
webhook.sign(payload as string, secret as string)

Sign a payload: sha256= followed by the hex HMAC-SHA256 of the payload keyed by the shared secret - the value a receiver checks in X-Hub-Signature-256.

payload
the exact request body
secret
the shared secret
Returns string
the signature, e.g. "sha256=757107ea..."

signedHeaders

jennifer
webhook.signedHeaders(payload as string, secret as string)

The headers that sign a webhook delivery: X-Hub-Signature-256 set to sign(payload, secret). Pass them to http.post with the same payload (the common content type is application/json); the HTTP request itself needs the default binary.

payload
the exact request body to send
secret
the shared secret
Returns map of string to string
the header map to send with the body
jennifer
def r as http.Response init http.post($url, "application/json", $body,
    webhook.signedHeaders($body, $secret));

slackSign

jennifer
webhook.slackSign(secret as string, body as string, timestamp as int)

Sign a payload the Slack way: the signed base string is "v0:" + <timestamp> + ":" + <body>, HMAC-SHA256, hex-encoded, and the returned value is v0=<hexsig> (the X-Slack-Signature shape). The timestamp travels separately in X-Slack-Request-Timestamp.

secret
the Slack signing secret
body
the exact request body
timestamp
the unix timestamp (seconds), the request timestamp
Returns string
the signature, e.g. "v0=a2114d57..."

slackVerify

jennifer
webhook.slackVerify(
    secret as string,
    body as string,
    timestamp as int,
    signature as string,
    toleranceSeconds as int,
    now as int)

Verify a Slack v0=... signature against a body, secret, and the request timestamp (from X-Slack-Request-Timestamp). Recomputes the HMAC-SHA256 over "v0:" + <timestamp> + ":" + <body> and constant-time compares. Returns true only if the signature matches AND the timestamp is within toleranceSeconds of now (replay protection, e.g. 300s).

secret
the Slack signing secret
body
the exact request body received
timestamp
the request timestamp (seconds) from the header
signature
the received v0=... header value
toleranceSeconds
the freshness window in seconds (e.g. 300)
now
the current unix time (seconds)
Returns bool
true if the signature is valid and the timestamp is fresh

stripeSign

jennifer
webhook.stripeSign(secret as string, body as string, timestamp as int)

Sign a payload the Stripe way: the signed base string is <timestamp> + "." + <body>, HMAC-SHA256, hex-encoded, and the returned header value is t=<timestamp>,v1=<hexsig> (the Stripe-Signature shape).

secret
the endpoint signing secret
body
the exact request body
timestamp
the unix timestamp (seconds) to stamp and sign
Returns string
the header value, e.g. "t=1492774800,v1=5257a8..."

stripeVerify

jennifer
webhook.stripeVerify(
    secret as string,
    body as string,
    header as string,
    toleranceSeconds as int,
    now as int)

Verify a Stripe t=...,v1=... signature header against a body and secret. Parses the timestamp and the (possibly several) v1= signatures, recomputes the HMAC-SHA256 over <t>.<body>, and constant-time compares. Returns true only if a signature matches AND the timestamp is within toleranceSeconds of now (replay protection).

secret
the endpoint signing secret
body
the exact request body received
header
the received t=...,v1=... header value
toleranceSeconds
the freshness window in seconds (e.g. 300)
now
the current unix time (seconds)
Returns bool
true if a signature is valid and the timestamp is fresh

timestampedSign

jennifer
webhook.timestampedSign(
    algo as string,
    encoding as string,
    secret as string,
    body as string,
    timestamp as int)

Generic timestamped HMAC signature: sign <timestamp> + "." + <body> with a caller-chosen digest and text encoding. Covers GitHub-style sha1/sha256 and hex/base64 schemes from one composable primitive.

algo
the HMAC digest: "sha1" or "sha256"
encoding
the text encoding: "hex" or "base64"
secret
the shared secret
body
the exact request body
timestamp
the unix timestamp (seconds) to stamp and sign
Returns string
the encoded signature (no scheme prefix)

timestampedVerify

jennifer
webhook.timestampedVerify(
    algo as string,
    encoding as string,
    secret as string,
    body as string,
    timestamp as int,
    signature as string,
    toleranceSeconds as int,
    now as int)

Verify a generic timestamped HMAC signature (see timestampedSign) with a constant-time compare and a replay-protecting freshness check. Returns true only if the signature matches AND the timestamp is within toleranceSeconds of now.

algo
the HMAC digest: "sha1" or "sha256"
encoding
the text encoding: "hex" or "base64"
secret
the shared secret
body
the exact request body received
timestamp
the request timestamp (seconds)
signature
the received signature (encoded, no prefix)
toleranceSeconds
the freshness window in seconds
now
the current unix time (seconds)
Returns bool
true if the signature is valid and the timestamp is fresh

verify

jennifer
webhook.verify(payload as string, signature as string, secret as string)

Verify a signature against a payload and secret, with a constant-time compare.

payload
the exact request body received
signature
the received signature, e.g. "sha256=..."
secret
the shared secret
Returns bool
true if the signature is valid