All blocks

Documentation Technical

Sequential technical quickstart guide featuring breadcrumb navigation, an AI setup prompt card, prerequisites and troubleshooting callouts, synced package-manager and runtime code switchers, checkable step completion progress, onward reading cards, and a responsive sticky table-of-contents rail.

QuickstartKestrel CLI v2.812 min · 5 stepsUpdated Nov 28, 2026

Deploying Signed Edge Webhooks with Kestrel CLI

Provision a workspace HMAC-SHA256 signing secret, verify raw webhook payloads in edge middleware, replay signed test events locally, and promote your endpoint to production in five steps.

Walkthrough progress1 of 5 steps completed
AI AssistanceSetup prompt

Help me deploy signed edge webhooks with Kestrel CLI. Based on my repository: 1. Install @kestrel/cli and @kestrel/webhooks. 2. Add a webhook endpoint at /api/webhooks/kestrel that reads raw request bytes and verifies the x-kestrel-signature header with HMAC-SHA256 and a 300-second replay tolerance. 3. Wire KESTREL_WEBHOOK_SECRET from environment variables and add a local test script using `kestrel webhooks listen`.

Prerequisites

Before you begin
Confirm your local environment meets these requirements so signature verification and local tunnel replay work out of the box.
  • Node.js 20+ or Bun 1.2+ with Web Crypto (crypto.subtle) enabled
  • A Kestrel workspace with Edge Runtime access and a scoped API token
  • Local port 8787 free for the authenticated webhook tunnel listener

Install CLI & Authenticate

Install @kestrel/cli globally and add @kestrel/webhooks to your service. Switching package managers below updates all CLI commands in this guide automatically.

Synced across steps 1–2
terminal · bun
# Install the Kestrel CLI and verification helper
bun add -g @kestrel/cli
bun add @kestrel/webhooks

# Authenticate with scoped webhook permissions
kestrel login --scope webhooks:write
kestrel whoami
Authenticated as acme-edge · scopes: webhooks:write · expires in 14d

Initialize Signing Secret

Register your webhook route and generate a 256-bit signing secret. Kestrel signs every outgoing delivery with HMAC-SHA256 over ${timestamp}.${rawBody} and attaches the digest in x-kestrel-signature.

terminal · bun
# Provision a workspace signing secret and write it to .env.local
bunx kestrel webhooks init \
  --endpoint /api/webhooks/kestrel \
  --events invoice.paid,subscription.updated \
  --env .env.local
.env.local (generated)
KESTREL_WEBHOOK_ENDPOINT="/api/webhooks/kestrel"
KESTREL_WEBHOOK_SECRET="whsec_dev_7f9a3e2c41b8d60e9c1b54a72e81f0c4"
KESTREL_TOLERANCE_SECONDS="300"

Verify Signatures in Middleware

Validate the raw request payload in constant time before deserializing JSON. Choose the runtime implementation that matches your deployment target:

src/routes/webhooks/kestrel.ts
import { verifyWebhookSignature, WebhookError } from "@kestrel/webhooks";

export async function POST(request: Request, env: Env): Promise<Response> {
  // Always read the exact raw bytes before parsing JSON
  const rawBody = await request.text();
  const signature = request.headers.get("x-kestrel-signature");

  try {
    const event = await verifyWebhookSignature({
      payload: rawBody,
      signatureHeader: signature,
      secret: env.KESTREL_WEBHOOK_SECRET,
      toleranceSeconds: 300,
    });

    if (event.type === "invoice.paid") {
      await markInvoiceSettled(event.data.invoiceId, event.id);
    }

    return Response.json({ received: true, eventId: event.id });
  } catch (err) {
    if (err instanceof WebhookError) {
      return new Response(err.message, { status: 401 });
    }
    throw err;
  }
}

Replay Events Locally

Stream signed payloads straight to your local handler using kestrel webhooks listen, then emit a synthetic invoice.paid event from a second terminal to confirm end-to-end HMAC verification.

terminal · local tunnel
# Terminal 1 — open an authenticated local tunnel to your dev server
kestrel webhooks listen --forward http://localhost:8787/api/webhooks/kestrel

# Terminal 2 — emit a signed test event with a deterministic idempotency key
kestrel webhooks trigger invoice.paid \
  --idempotency-key evt_test_01 \
  --data '{"invoiceId":"inv_01j9x7","amountCents":4900}'
POST /api/webhooks/kestrel → 200 OK · verified in 1.4 ms · sig=v1 · evt_test_01

Promote to Production

Store a dedicated production signing secret in the edge vault, publish your handler across every PoP, and run a live delivery probe before switching customer traffic.

terminal · production deploy
# Store the production signing key in the encrypted edge vault
kestrel secret set KESTREL_WEBHOOK_SECRET --stage prod

# Deploy the verified handler and switch the live endpoint pointer
kestrel deploy --stage prod --verify-webhooks

# Confirm live edge delivery health and p99 verification latency
kestrel webhooks status --stage prod

Troubleshooting

Receiving 401 Invalid Signature in staging or production?
Most signature mismatches come from subtle body mutations or clock skew between edge PoPs and your origin:
  • Ensure no upstream JSON body parser runs before request.text() or express.raw() — re-serializing JSON alters key spacing and invalidates the HMAC digest.
  • Check host NTP synchronization if errors report ERR_TIMESTAMP_OUTSIDE_TOLERANCE (default window is 300 seconds).
  • Verify that your production vault uses a whsec_live_* secret rather than a local whsec_dev_* key.
terminal · diagnostics
# Inspect raw-body handling, clock skew, and active secret versions
kestrel webhooks doctor --stage prod --trace-last 5

Next steps

Continue hardening your webhook pipeline with dual-key rotation, replay queues, and real-time delivery observability.

    Install

    Source

    components/blocks/ui-sdk/documentation-technical.tsx

    Inspired by the Documentation Technical template from Astryx (MIT License · Copyright (c) 2026 Meta Platforms, Inc.).