"""Webhook signature verification for Relayway API callbacks."""
import hashlib
import hmac


def verify_signature(secret: str, signature: str, timestamp: int, payload: str) -> bool:
    """Verify HMAC-SHA256 signature from worker callback."""
    message = f"{timestamp}.{payload}"
    expected = hmac.new(
        secret.encode(),
        message.encode(),
        hashlib.sha256
    ).hexdigest()
    return hmac.compare_digest(signature, expected)
