Every delivery is signed so you can prove it came from HoneyBook and was not changed on the way. HoneyBook follows the [Standard Webhooks](https://www.standardwebhooks.com) headers and signed content, with asymmetric signatures.

### What is signed

Three headers accompany each delivery:

| Header              | Value                                               |
| ------------------- | --------------------------------------------------- |
| `webhook-id`        | The event id.                                       |
| `webhook-timestamp` | Unix seconds when this attempt was signed.          |
| `webhook-signature` | One or more signatures, separated by single spaces. |

The signed content is the three values joined with dots, with the body exactly as received:

```
{webhook-id}.{webhook-timestamp}.{body}
```

Verify against the raw bytes of the body. Parsing the JSON and serializing it again changes the bytes and breaks the signature.

### Signature versions

Each entry in `webhook-signature` is `<version>,<base64 signature>`. HoneyBook signs with **`v1a`**, which is **ed25519**. The key to verify with is the `signing_public_key` returned when you created the webhook, in `whpk_` form: `whpk_` followed by the standard base64 of the raw 32-byte public key.

The header may carry **several space-delimited signatures**. Check the versions you know and ignore the rest. A verifier written that way keeps working when another version is added.

**The stock `standardwebhooks` JavaScript library verifies `v1` (HMAC) only**, so it cannot verify these deliveries. Use one of the snippets below, which implement the same checks: required headers present, timestamp within five minutes of now, and at least one `v1a` signature that verifies.

Reject a delivery that fails. Return `2xx` only for a verified delivery you have accepted.

### Verification code

The same checks in four languages. Pick yours; the choice is remembered for the rest of the page.

-   **Node.js** uses only `node:crypto`.
-   **Python** needs the `cryptography` package.
-   **Ruby** uses only the standard library (`openssl` 3.0 or newer).
-   **Go** uses only the standard library (Go 1.20 or newer).

**Node.js**

```javascript
const crypto = require('node:crypto');

const TOLERANCE_SECONDS = 5 * 60;
// An ed25519 public key in SPKI DER form is this fixed prefix plus the raw key.
const SPKI_PREFIX = Buffer.from('302a300506032b6570032100', 'hex');

// headers: lower-case header names. rawBody: the body exactly as received.
// publicKey: the webhook's signing_public_key ("whpk_...").
function verifyWebhook(
    headers,
    rawBody,
    publicKey,
    nowSeconds = Date.now() / 1000
) {
    const id = headers['webhook-id'];
    const timestamp = headers['webhook-timestamp'];
    const signatures = headers['webhook-signature'];
    if (!id || !timestamp || !signatures) return false;

    const sentAt = Number(timestamp);
    if (!Number.isFinite(sentAt)) return false;
    if (Math.abs(nowSeconds - sentAt) > TOLERANCE_SECONDS) return false;

    const rawKey = Buffer.from(publicKey.replace(/^whpk_/, ''), 'base64');
    if (rawKey.length !== 32) return false;
    const key = crypto.createPublicKey({
        key: Buffer.concat([SPKI_PREFIX, rawKey]),
        format: 'der',
        type: 'spki'
    });

    const signed = Buffer.concat([
        Buffer.from(`${id}.${timestamp}.`),
        Buffer.from(rawBody)
    ]);

    return signatures
        .split(' ')
        .filter(entry => entry.startsWith('v1a,'))
        .some(entry =>
            crypto.verify(
                null,
                signed,
                key,
                Buffer.from(entry.slice('v1a,'.length), 'base64')
            )
        );
}

module.exports = { verifyWebhook };
```

**Python**

```python
import base64
import time

from cryptography.exceptions import InvalidSignature
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PublicKey

TOLERANCE_SECONDS = 5 * 60


def verify_webhook(headers, raw_body, public_key, now=None):
    """headers: lower-case header names. raw_body: the body as received, bytes.
    public_key: the webhook's signing_public_key ("whpk_...")."""
    webhook_id = headers.get("webhook-id")
    timestamp = headers.get("webhook-timestamp")
    signatures = headers.get("webhook-signature")
    if not webhook_id or not timestamp or not signatures:
        return False

    try:
        sent_at = int(timestamp)
    except ValueError:
        return False
    now = time.time() if now is None else now
    if abs(now - sent_at) > TOLERANCE_SECONDS:
        return False

    try:
        raw_key = base64.b64decode(public_key.removeprefix("whpk_"), validate=True)
        key = Ed25519PublicKey.from_public_bytes(raw_key)
    except ValueError:
        return False

    signed = f"{webhook_id}.{timestamp}.".encode() + raw_body
    for entry in signatures.split(" "):
        if not entry.startswith("v1a,"):
            continue
        try:
            key.verify(base64.b64decode(entry[len("v1a,"):], validate=True), signed)
            return True
        except (InvalidSignature, ValueError):
            continue
    return False
```

**Ruby**

```ruby
require 'openssl'

TOLERANCE_SECONDS = 5 * 60

# headers: lower-case header names. raw_body: the body exactly as received.
# public_key: the webhook's signing_public_key ("whpk_...").
def verify_webhook(headers, raw_body, public_key, now = Time.now.to_i)
  id = headers['webhook-id']
  timestamp = headers['webhook-timestamp']
  signatures = headers['webhook-signature']
  return false if id.nil? || timestamp.nil? || signatures.nil?
  return false unless timestamp.match?(/\A\d+\z/)
  return false if (now - timestamp.to_i).abs > TOLERANCE_SECONDS

  key = OpenSSL::PKey.new_raw_public_key(
    'ED25519', public_key.delete_prefix('whpk_').unpack1('m0')
  )
  signed = "#{id}.#{timestamp}.#{raw_body}"

  signatures.split(' ').any? do |entry|
    next false unless entry.start_with?('v1a,')

    begin
      key.verify(nil, entry.delete_prefix('v1a,').unpack1('m0'), signed)
    rescue ArgumentError, OpenSSL::PKey::PKeyError
      false
    end
  end
rescue ArgumentError, OpenSSL::PKey::PKeyError
  false
end
```

**Go**

```go
package webhooks

import (
	"crypto/ed25519"
	"encoding/base64"
	"net/http"
	"strconv"
	"strings"
	"time"
)

const toleranceSeconds = 5 * 60

// VerifyWebhook reports whether a delivery is authentic. rawBody is the body
// exactly as received; publicKey is the webhook's signing_public_key
// ("whpk_...").
func VerifyWebhook(h http.Header, rawBody []byte, publicKey string, now time.Time) bool {
	id := h.Get("webhook-id")
	timestamp := h.Get("webhook-timestamp")
	signatures := h.Get("webhook-signature")
	if id == "" || timestamp == "" || signatures == "" {
		return false
	}

	sentAt, err := strconv.ParseInt(timestamp, 10, 64)
	if err != nil {
		return false
	}
	skew := now.Unix() - sentAt
	if skew > toleranceSeconds || skew < -toleranceSeconds {
		return false
	}

	rawKey, err := base64.StdEncoding.DecodeString(strings.TrimPrefix(publicKey, "whpk_"))
	if err != nil || len(rawKey) != ed25519.PublicKeySize {
		return false
	}
	key := ed25519.PublicKey(rawKey)

	signed := append([]byte(id+"."+timestamp+"."), rawBody...)
	for _, entry := range strings.Split(signatures, " ") {
		encoded, ok := strings.CutPrefix(entry, "v1a,")
		if !ok {
			continue
		}
		signature, err := base64.StdEncoding.DecodeString(encoded)
		if err != nil {
			continue
		}
		if ed25519.Verify(key, signed, signature) {
			return true
		}
	}
	return false
}
```
