Skip to content

Webhook signature verify

FREE with proof-of-workor $0.001 in USDCPOST /api/webhook-verify

Verify a webhook's HMAC signature against the correct per-provider scheme: GitHub (X-Hub-Signature-256, sha256=hex), Stripe (Stripe-Signature t/v1 over "<t>.<body>" with replay tolerance), Shopify (X-Shopify-Hmac-Sha256, base64), Slack (X-Slack-Signature, v0:<ts>:<body> with replay tolerance).

Category: Validation & parsingTags: webhook hmac signature security github stripe shopify slack

Try in playground →

Details

Constant-time comparison; the secret is never echoed. Pass the RAW request body string - signatures are over the raw bytes. Deterministic.

Parameters

NameTypeRequiredDescription
providerstringyesgithub | stripe | shopify | slack The example sends github.
payloadstringyesthe RAW request body string, byte-for-byte as received (never a re-serialized object) Also accepted as body, data, claims, message. The example sends {"hello":"world"}.
secretstringyesthe provider signing secret (never echoed back) Also accepted as key, password, passphrase. The example sends it's a secret.
signaturestringyesthe signature header value, with or without its scheme prefix (sha256= / v0= / t=...,v1=...)
timestampstringnoprovider timestamp, required for stripe + slack (stripe may be parsed from a t= element in the signature)
toleranceSecondsnumbernomax timestamp age for stripe/slack replay protection (default 300; 0 skips the age check)

Free call, no wallet

Fetch a challenge, solve its sha256 puzzle (16 leading zero bits), resend with X-Pow-Solution.

import { createHash } from "node:crypto";
const lz = (b) => { let t = 0; for (const x of b) { if (!x) { t += 8; continue; } t += Math.clz32(x) - 24; break; } return t; };
const c = await (await fetch("https://agent402.tools/api/pow/challenge?slug=webhook-verify")).json();
let n = 0;
while (lz(createHash("sha256").update(c.challenge + ":" + n).digest()) < c.difficulty) n++;
await fetch("https://agent402.tools/api/webhook-verify", { method: "POST", headers: { "X-Pow-Solution": c.token + ":" + n, "Content-Type": "application/json" }, body: JSON.stringify({"provider":"github","payload":"{\"hello\":\"world\"}","secret":"it's a secret","signature":"sha256=8d4063f0a81aa1531d9891a028a68cf2bb537ecdf0e82557674d71e168d570f9"}) });

Python:

import hashlib, json, urllib.request

def zero_bits(digest):
    n = 0
    for b in digest:
        if b:
            return n + 8 - b.bit_length()
        n += 8
    return n

c = json.load(urllib.request.urlopen("https://agent402.tools/api/pow/challenge?slug=webhook-verify"))
n = 0
while zero_bits(hashlib.sha256(f"{c['challenge']}:{n}".encode()).digest()) < c["difficulty"]:
    n += 1
req = urllib.request.Request("https://agent402.tools/api/webhook-verify", method="POST", data="{\"provider\":\"github\",\"payload\":\"{\\\"hello\\\":\\\"world\\\"}\",\"secret\":\"it's a secret\",\"signature\":\"sha256=8d4063f0a81aa1531d9891a028a68cf2bb537ecdf0e82557674d71e168d570f9\"}".encode(), headers={"X-Pow-Solution": f"{c['token']}:{n}", "Content-Type": "application/json"})
print(json.load(urllib.request.urlopen(req)))

Example request

curl -i -X POST https://agent402.tools/api/webhook-verify \
  -H "Content-Type: application/json" \
  -d '{"provider":"github","payload":"{\"hello\":\"world\"}","secret":"it'\''s a secret","signature":"sha256=8d4063f0a81aa1531d9891a028a68cf2bb537ecdf0e82557674d71e168d570f9"}'

Watch a call get paid

RequestPOST /api/webhook-verify
402$0.001 USDC
SignPAYMENT-SIGNATURE
Settleon 14 chains
Answer200 OK
ReceiptAgent402-ReceiptEd25519

Example response

{
  "valid": true,
  "provider": "github",
  "scheme": "X-Hub-Signature-256: sha256=hex(HMAC-SHA256(secret, rawBody))",
  "reason": "signature matches the recomputed HMAC for this payload and secret"
}
FieldTypeAlways presentIn the example
validbooleanyestrue
providerstringyesgithub
schemestringyesX-Hub-Signature-256: sha256=hex(HMAC-SHA256(secret, rawBody))
reasonstringyessignature matches the recomputed HMAC for this payload and secret

From an MCP client

catalog.call {
  "slug": "webhook-verify",
  "params": {
    "provider": "github",
    "payload": "{\"hello\":\"world\"}",
    "secret": "it's a secret",
    "signature": "sha256=8d4063f0a81aa1531d9891a028a68cf2bb537ecdf0e82557674d71e168d570f9"
  }
}

Hosted connector (https://agent402.tools/mcp): free, rate-limited. Stdio package: npx -y agent402-mcp@0.17.2.

Errors and behavior

Paid call (JavaScript agent)

import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";

const client = new x402Client();
client.setSpendControls?.({ maxAmountPerPayment: "$0.001" }); // refuse any quote above this tool's price
registerExactEvmScheme(client, { signer: privateKeyToAccount(process.env.AGENT_KEY) });
const payFetch = wrapFetchWithPayment(fetch, client);

const res = await payFetch("https://agent402.tools/api/webhook-verify", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    "provider": "github",
    "payload": "{\"hello\":\"world\"}",
    "secret": "it's a secret",
    "signature": "sha256=8d4063f0a81aa1531d9891a028a68cf2bb537ecdf0e82557674d71e168d570f9"
  }),
});

Get a wallet or run npx -y agent402-mcp@0.17.2 wallet new.

Part of these workflows

Related tools