# HookSink Webhook Inbox & Signature Verifier API (v1.0.0)

> Provision instant public webhook URLs, verify Stripe/Shopify/GitHub/Slack HMAC signatures, and replay captured events at the edge.

Ephemeral Cloudflare Durable Object webhook capture inboxes, constant-time multi-provider HMAC-SHA256 signature verification (Stripe, GitHub, Shopify, Slack, Linear), and SSRF-guarded webhook replay for autonomous agents.

## Why Agents Use This API Instead of DIY
Eliminates spinning up ngrok tunnels, public servers, or error-prone raw-body HMAC/timestamp parsers when agents test integrations or receive async callbacks.

## Connection & Payment (x402 Default + Optional Bearer API Key)
- **MCP Server (Streamable HTTP):** `https://hook-sink.apikeg.com/mcp` (Registry ID: `com.apikeg/hook-sink` — `initialize`, `tools/list`, `resources/*`, and `prompts/*` are free)
- **OpenAPI 3.1 Spec:** [openapi.json](https://hook-sink.apikeg.com/openapi.json)
- **Full Schema & Examples:** [llms-full.txt](https://hook-sink.apikeg.com/llms-full.txt)
- **RFC 9727 API Catalog:** [.well-known/api-catalog](https://hook-sink.apikeg.com/.well-known/api-catalog)
- **x402 Bazaar Manifest:** [.well-known/x402.json](https://hook-sink.apikeg.com/.well-known/x402.json)
- **MCP Discovery Manifest:** [.well-known/mcp.json](https://hook-sink.apikeg.com/.well-known/mcp.json)
- **A2A Agent Card:** [.well-known/agent-card.json](https://hook-sink.apikeg.com/.well-known/agent-card.json)
- **Primary Payment (Zero Signup):** Cloudflare Monetization Gateway (`HTTP 402` / `x402` v2 with USDC on Base).
- **Optional Monthly API Key:** Pass `Authorization: Bearer ak_live_...` ($5 / $20 / $50 monthly per-product Stripe plans at [apikeg.com/account](https://apikeg.com/account)).
- **Free Preflight:** Append `?dry_run=true` (or header `X-Dry-Run: true`) to validate any request payload at `$0.00` cost.

## Tools & REST Endpoints
- [`create_inbox`](https://hook-sink.apikeg.com/tools/create-inbox.md) (`POST https://hook-sink.apikeg.com/v1/create-inbox`) — Free ($0.00): Provisions a fresh public webhook capture URL (/in/:inboxId) backed by an isolated Durable Object ring buffer (up to 100 events, 128 KiB each) with optional automatic HMAC signature verification.
- [`inspect_inbox_events`](https://hook-sink.apikeg.com/tools/inspect-inbox-events.md) (`POST https://hook-sink.apikeg.com/v1/inspect-inbox-events`) — $0.002 USD per inbox inspection query (x402 instant micropayment): Retrieves captured webhook deliveries from an inbox (headers, raw body, SHA-256 digest, parsed JSON, and cryptographic signature verification), supporting cursor pagination via sinceEventId and retroactive ad-hoc signature checks.
- [`verify_webhook_signature`](https://hook-sink.apikeg.com/tools/verify-webhook-signature.md) (`POST https://hook-sink.apikeg.com/v1/verify-webhook-signature`) — $0.001 USD per stateless signature verification (x402 instant micropayment): Statelessly verifies webhook HMAC-SHA256 signatures and replay timestamps across Stripe, GitHub, Shopify, Slack, Linear, or custom headers using constant-time Web Crypto comparison.
- [`replay_event`](https://hook-sink.apikeg.com/tools/replay-event.md) (`POST https://hook-sink.apikeg.com/v1/replay-event`) — $0.003 USD per SSRF-guarded webhook replay (x402 instant micropayment): Replays a captured webhook event (exact raw body, HTTP method, and signature headers) from an inbox to a public HTTP/HTTPS target URL protected by strict SSRF filtering, returning target status, latency, and response snippet.

## Instant MCP Configuration
```json
{
  "mcpServers": {
    "hook-sink": {
      "type": "streamable-http",
      "url": "https://hook-sink.apikeg.com/mcp"
    }
  }
}
```

## Common Agent Use Cases
- ephemeral webhook inbox API for AI agents
- receive Stripe Shopify GitHub Slack webhooks without ngrok
- verify Stripe-Signature X-Shopify-Hmac-Sha256 X-Slack-Signature MCP tool
- capture and replay webhook payloads API

---

## Detailed Tool Specifications

### `create_inbox` — Create Ephemeral Webhook Inbox
- **REST Endpoint:** `POST https://hook-sink.apikeg.com/v1/create-inbox`
- **Tool Doc Page:** https://hook-sink.apikeg.com/tools/create-inbox
- **MCP Tool Name:** `create_inbox`
- **Pricing:** Free ($0.00)
- **Side Effects:** readOnly=false, idempotent=false, destructive=false
- **Build vs. Buy ROI:** Replaces running ngrok/cloudflared tunnels, deploying temporary webhook servers, and managing TTL cleanup cron jobs.

#### Input JSON Schema
```json
{
  "type": "object",
  "properties": {
    "provider": {
      "type": "string",
      "enum": [
        "auto",
        "stripe",
        "github",
        "shopify",
        "slack",
        "linear",
        "generic_sha256"
      ],
      "description": "Optional webhook provider preset for automatic HMAC verification on capture (auto, stripe, github, shopify, slack, linear, generic_sha256)."
    },
    "signingSecret": {
      "type": "string",
      "minLength": 1,
      "maxLength": 512,
      "description": "Optional webhook signing secret used to verify inbound webhook signatures automatically as events arrive."
    },
    "signatureHeader": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128,
      "description": "Optional custom HTTP header name containing the HMAC signature when using generic_sha256 or linear."
    },
    "ttlSeconds": {
      "type": "integer",
      "minimum": 60,
      "maximum": 86400,
      "default": 3600,
      "description": "Ephemeral inbox retention TTL in seconds (60 to 86400, default 3600)."
    }
  },
  "additionalProperties": false
}
```

#### Examples
**Create a Stripe webhook inbox with 1-hour TTL**
```bash
curl -X POST "https://hook-sink.apikeg.com/v1/create-inbox" \
  -H "Content-Type: application/json" \
  -d '{"provider":"stripe","ttlSeconds":3600}'
```
Expected result: Returns inboxId, secret readToken, and public webhookUrl ready to paste into Stripe/GitHub/Shopify.

### `inspect_inbox_events` — Inspect Captured Webhook Events
- **REST Endpoint:** `POST https://hook-sink.apikeg.com/v1/inspect-inbox-events`
- **Tool Doc Page:** https://hook-sink.apikeg.com/tools/inspect-inbox-events
- **MCP Tool Name:** `inspect_inbox_events`
- **Pricing:** $0.002 USD per inbox inspection query (x402 instant micropayment)
- **Side Effects:** readOnly=true, idempotent=true, destructive=false
- **Build vs. Buy ROI:** Provides structured raw-body + parsed-JSON payloads with constant-time HMAC verification in a single call.

#### Input JSON Schema
```json
{
  "type": "object",
  "properties": {
    "inboxId": {
      "type": "string",
      "minLength": 4,
      "maxLength": 128,
      "pattern": "^[A-Za-z0-9_-]+$",
      "description": "Ephemeral inbox identifier returned by create_inbox."
    },
    "readToken": {
      "type": "string",
      "minLength": 8,
      "maxLength": 256,
      "description": "Secret read token returned by create_inbox."
    },
    "limit": {
      "type": "integer",
      "minimum": 1,
      "maximum": 100,
      "default": 50,
      "description": "Maximum number of captured webhook events to return (1–100, default 50)."
    },
    "sinceEventId": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128,
      "description": "Cursor pagination: return only events captured strictly after this eventId."
    },
    "signingSecret": {
      "type": "string",
      "minLength": 1,
      "maxLength": 512,
      "description": "Optional ad-hoc HMAC signing secret to retroactively verify captured webhook events."
    },
    "provider": {
      "type": "string",
      "enum": [
        "auto",
        "stripe",
        "github",
        "shopify",
        "slack",
        "linear",
        "generic_sha256"
      ],
      "description": "Optional provider preset override for retroactive signature verification (auto, stripe, github, shopify, slack, linear, generic_sha256)."
    },
    "signatureHeader": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128,
      "description": "Optional custom header name for retroactive generic_sha256 verification."
    },
    "toleranceSeconds": {
      "type": "integer",
      "minimum": 0,
      "maximum": 86400,
      "description": "Optional timestamp tolerance window in seconds (evaluated against each event's receivedAt timestamp)."
    }
  },
  "required": [
    "inboxId",
    "readToken"
  ],
  "additionalProperties": false
}
```

#### Examples
**Inspect latest webhook deliveries**
```bash
curl -X POST "https://hook-sink.apikeg.com/v1/inspect-inbox-events" \
  -H "Content-Type: application/json" \
  -d '{"inboxId":"inb_0123456789abcdef01234567","readToken":"hsk_0123456789abcdef0123456789abcdef0123456789abcdef","limit":20}'
```

### `verify_webhook_signature` — Verify Webhook HMAC Signature
- **REST Endpoint:** `POST https://hook-sink.apikeg.com/v1/verify-webhook-signature`
- **Tool Doc Page:** https://hook-sink.apikeg.com/tools/verify-webhook-signature
- **MCP Tool Name:** `verify_webhook_signature`
- **Pricing:** $0.001 USD per stateless signature verification (x402 instant micropayment)
- **Side Effects:** readOnly=true, idempotent=true, destructive=false
- **Build vs. Buy ROI:** Prevents subtle raw-body serialization bugs, hex vs. base64 mismatches, timing side channels, and Stripe/Slack timestamp replay vulnerabilities.

#### Input JSON Schema
```json
{
  "type": "object",
  "properties": {
    "provider": {
      "type": "string",
      "enum": [
        "auto",
        "stripe",
        "github",
        "shopify",
        "slack",
        "linear",
        "generic_sha256"
      ],
      "default": "auto",
      "description": "Webhook signature provider preset (auto, stripe, github, shopify, slack, linear, generic_sha256)."
    },
    "rawBody": {
      "type": "string",
      "maxLength": 262144,
      "description": "Exact raw UTF-8 HTTP request body string as delivered by the webhook sender."
    },
    "headers": {
      "type": "object",
      "additionalProperties": {
        "type": "string"
      },
      "description": "HTTP request headers map containing the webhook signature header(s)."
    },
    "secret": {
      "type": "string",
      "minLength": 1,
      "maxLength": 512,
      "description": "Webhook HMAC signing secret (e.g., whsec_... for Stripe)."
    },
    "toleranceSeconds": {
      "type": "integer",
      "minimum": 0,
      "maximum": 86400,
      "default": 300,
      "description": "Timestamp replay-window tolerance in seconds for Stripe and Slack (default 300)."
    },
    "signatureHeader": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128,
      "description": "Optional custom signature header name when provider is generic_sha256 or linear."
    },
    "nowSeconds": {
      "type": "integer",
      "minimum": 0,
      "description": "Optional Unix epoch timestamp (seconds) override for deterministic replay checks."
    }
  },
  "required": [
    "rawBody",
    "headers",
    "secret"
  ],
  "additionalProperties": false
}
```

#### Examples
**Verify a Stripe webhook signature**
```bash
curl -X POST "https://hook-sink.apikeg.com/v1/verify-webhook-signature" \
  -H "Content-Type: application/json" \
  -d '{"provider":"stripe","rawBody":"{\"id\":\"evt_123\",\"type\":\"checkout.session.completed\"}","headers":{"Stripe-Signature":"t=1700000000,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd"},"secret":"whsec_test_secret","toleranceSeconds":300}'
```

### `replay_event` — Replay Captured Webhook Event
- **REST Endpoint:** `POST https://hook-sink.apikeg.com/v1/replay-event`
- **Tool Doc Page:** https://hook-sink.apikeg.com/tools/replay-event
- **MCP Tool Name:** `replay_event`
- **Pricing:** $0.003 USD per SSRF-guarded webhook replay (x402 instant micropayment)
- **Side Effects:** readOnly=false, idempotent=false, destructive=false
- **Build vs. Buy ROI:** Safely redelivers exact byte-for-byte webhook payloads with original signatures intact without risking SSRF against internal networks.

#### Input JSON Schema
```json
{
  "type": "object",
  "properties": {
    "inboxId": {
      "type": "string",
      "minLength": 4,
      "maxLength": 128,
      "pattern": "^[A-Za-z0-9_-]+$",
      "description": "Inbox identifier containing the captured event."
    },
    "readToken": {
      "type": "string",
      "minLength": 8,
      "maxLength": 256,
      "description": "Secret read token returned by create_inbox."
    },
    "eventId": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128,
      "description": "Identifier of the captured webhook event to replay."
    },
    "targetUrl": {
      "type": "string",
      "minLength": 8,
      "maxLength": 2048,
      "description": "Publicly routable http:// or https:// URL to receive the replayed webhook."
    },
    "overrideHeaders": {
      "type": "object",
      "additionalProperties": {
        "type": "string"
      },
      "description": "Optional additional or overridden HTTP headers to send on replay."
    },
    "timeoutMs": {
      "type": "integer",
      "minimum": 500,
      "maximum": 15000,
      "default": 10000,
      "description": "Outbound replay request timeout in milliseconds (500–15000, default 10000)."
    }
  },
  "required": [
    "inboxId",
    "readToken",
    "eventId",
    "targetUrl"
  ],
  "additionalProperties": false
}
```

#### Examples
**Replay captured event to staging endpoint**
```bash
curl -X POST "https://hook-sink.apikeg.com/v1/replay-event" \
  -H "Content-Type: application/json" \
  -d '{"inboxId":"inb_0123456789abcdef01234567","readToken":"hsk_0123456789abcdef0123456789abcdef0123456789abcdef","eventId":"evt_000001_a1b2c3d4e5f6","targetUrl":"https://staging.example.com/webhooks/stripe","timeoutMs":10000}'
```
