Versions in this module Expand all Collapse all v1 v1.0.0 Aug 26, 2026 Changes in this version + const IdempotencyHeader + const SignatureHeader + var ErrBodyRead = errors.New("webhook body read failed") + var ErrBodyTooLarge = errors.New("webhook body too large") + var ErrDeliveryEncoding = errors.New("invalid webhook delivery encoding") + var ErrDeliveryFailed = errors.New("webhook delivery failed") + var ErrEndpointRejected = errors.New("webhook endpoint rejected") + var ErrFanOutLimit = errors.New("webhook fan-out limit exceeded") + var ErrInvalidConfiguration = errors.New("invalid webhook configuration") + var ErrInvalidEnvelope = errors.New("invalid webhook envelope") + var ErrInvalidSignature = errors.New("invalid webhook signature") + var ErrInvalidTimestamp = errors.New("invalid webhook timestamp") + var ErrMalformedSignatureHeader = errors.New("malformed webhook signature header") + var ErrMalformedSignedHeader = errors.New("malformed webhook signed header") + var ErrMissingEventID = errors.New("webhook event ID is required") + var ErrNoActiveKey = errors.New("no active webhook signing key") + var ErrNonceGeneration = errors.New("webhook nonce generation failed") + var ErrReplay = errors.New("webhook replay detected") + var ErrReplayStore = errors.New("webhook replay store unavailable") + var ErrResponseTooLarge = errors.New("webhook response too large") + var ErrSignatureHeadersTooLarge = errors.New("webhook signature headers too large") + func Canonicalize(message Message, keyID string, algorithm Algorithm) ([]byte, error) + func CaptureBody(request *http.Request, maxBytes int64) ([]byte, error) + func MarshalDeliveryRequest(delivery DeliveryRequest, maxBytes int) ([]byte, error) + func NewSecureHTTPClient(policy *SSRFPolicy, timeout time.Duration) (*http.Client, error) + func SetSignatureHeaders(header http.Header, signatures []Signature) error + func VerifiedBodyFromContext(ctx context.Context) ([]byte, bool) + type Algorithm string + const SHA256 + const SHA512 + type DeadLetterFunc func(ctx context.Context, result DeliveryResult) error + type Deliverer struct + func NewDeliverer(config DeliveryConfig) (*Deliverer, error) + func (d *Deliverer) Deliver(ctx context.Context, delivery DeliveryRequest) (DeliveryResult, error) + func (d *Deliverer) DeliverOnce(ctx context.Context, delivery DeliveryRequest) (DeliveryResult, error) + func (d *Deliverer) FanOut(ctx context.Context, deliveries []DeliveryRequest, workers int) ([]FanOutResult, error) + func (d *Deliverer) Replay(ctx context.Context, originalDeliveryID string, delivery DeliveryRequest) (DeliveryResult, error) + type DeliveryAttempt struct + Classification FailureClassification + CompletedAt time.Time + Diagnostic string + ID string + Number int + RetryAfter time.Duration + StartedAt time.Time + StatusCode int + type DeliveryConfig struct + Client HTTPDoer + Clock func() time.Time + DeadLetter DeadLetterFunc + EndpointPolicy EndpointPolicy + HeaderLimits HeaderLimits + IDGenerator func() (string, error) + MaxFanOut int + MaxRequestBytes int64 + MaxResponseBytes int64 + Observer Observer + ReplayHook ReplayHook + Retry RetryPolicy + Signer *Signer + Sleep SleepFunc + type DeliveryRequest struct + Body []byte + Endpoint *url.URL + EventID string + Headers http.Header + IdempotencyKey string + Metadata map[string]string + func UnmarshalDeliveryRequest(encoded []byte, maxBytes int) (DeliveryRequest, error) + type DeliveryResult struct + Attempts []DeliveryAttempt + EventID string + ID string + ResponseBody []byte + type EndpointPolicy interface + Validate func(ctx context.Context, endpoint *url.URL) error + type EndpointPolicyFunc func(ctx context.Context, endpoint *url.URL) error + func (f EndpointPolicyFunc) Validate(ctx context.Context, endpoint *url.URL) error + type Envelope struct + Data json.RawMessage + ID string + Metadata map[string]string + Source string + Subject string + Time time.Time + Type string + func (e Envelope) MarshalJSON() ([]byte, error) + type ErrorHook func(ctx context.Context, err error) + type EventIDExtractor func(request *http.Request, body []byte) (string, error) + func HeaderEventID(name string, maxBytes int) EventIDExtractor + type FailureClassification string + const FailureExhausted + const FailureNone + const FailureRetryable + const FailureTerminal + type FanOutResult struct + Err error + Result DeliveryResult + type HTTPDoer interface + Do func(request *http.Request) (*http.Response, error) + type HeaderLimits struct + MaxBytes int + MaxSignatures int + type Message struct + Body []byte + ContentType string + Host string + IdempotencyKey string + Metadata map[string]string + Method string + Nonce string + Path string + RawQuery string + Timestamp time.Time + type MiddlewareConfig struct + FailureStatus int + OnError ErrorHook + Request RequestOptions + type NetIPResolver interface + LookupNetIP func(ctx context.Context, network, host string) ([]netip.Addr, error) + type NonceGenerator func() (string, error) + type Observation struct + Algorithm Algorithm + Attempt int + Classification FailureClassification + Duration time.Duration + Operation Operation + Outcome Outcome + Reason Reason + StatusCode int + type Observer interface + Observe func(ctx context.Context, observation Observation) + type ObserverFunc func(ctx context.Context, observation Observation) + func (f ObserverFunc) Observe(ctx context.Context, observation Observation) + type Operation string + const OperationDeliveryAttempt + const OperationReplay + const OperationVerification + type Outcome string + const OutcomeFailure + const OutcomeRejected + const OutcomeRetry + const OutcomeSuccess + type Reason string + const ReasonCanceled + const ReasonInternal + const ReasonLimit + const ReasonNone + const ReasonPolicy + const ReasonReplay + const ReasonSignature + const ReasonStatus + const ReasonStore + const ReasonTimestamp + const ReasonTransport + type ReplayHook func(ctx context.Context, originalDeliveryID, eventID string) error + type ReplayStore interface + CheckAndRecord func(ctx context.Context, key string, expiresAt time.Time) (recorded bool, err error) + type RequestOptions struct + EventID EventIDExtractor + HeaderLimits HeaderLimits + MaxBodyBytes int64 + Metadata map[string]string + type RetryPolicy struct + BaseDelay time.Duration + MaxAttempts int + MaxDelay time.Duration + func (p RetryPolicy) Delay(attempt int, now time.Time, retryAfter string) time.Duration + type SSRFPolicy struct + func NewSSRFPolicy(config SSRFPolicyConfig) (*SSRFPolicy, error) + func (p *SSRFPolicy) Validate(ctx context.Context, endpoint *url.URL) error + type SSRFPolicyConfig struct + AllowHTTP bool + AllowedPrefixes []netip.Prefix + DeniedPrefixes []netip.Prefix + MaxAddresses int + Resolver NetIPResolver + type Signature struct + Algorithm Algorithm + KeyID string + Nonce string + Timestamp time.Time + Value string + Version string + func ParseSignatureHeaders(header http.Header, limits HeaderLimits) ([]Signature, error) + type Signer struct + func NewSigner(config SignerConfig) (*Signer, error) + func (s *Signer) Sign(message Message) ([]Signature, error) + func (s *Signer) SignRequest(request *http.Request, options RequestOptions) ([]Signature, []byte, error) + type SignerConfig struct + Algorithm Algorithm + Clock func() time.Time + Keys []SigningKey + NonceGenerator NonceGenerator + type SigningKey struct + ID string + NotAfter time.Time + NotBefore time.Time + Revoked bool + Secret []byte + type SleepFunc func(ctx context.Context, duration time.Duration) error + type Verification struct + Algorithm Algorithm + KeyID string + Nonce string + Timestamp time.Time + func VerificationFromContext(ctx context.Context) (Verification, bool) + type VerificationError struct + Diagnostic string + Kind error + func (e *VerificationError) Error() string + func (e *VerificationError) SafeMessage() string + func (e *VerificationError) Unwrap() error + type VerificationKey struct + ID string + NotAfter time.Time + NotBefore time.Time + Revoked bool + Secret []byte + type Verifier struct + func NewVerifier(config VerifierConfig) (*Verifier, error) + func (v *Verifier) Middleware(config MiddlewareConfig, next http.Handler) (http.Handler, error) + func (v *Verifier) Verify(message Message, signatures []Signature) (Verification, error) + func (v *Verifier) VerifyAndRecord(ctx context.Context, message Message, signatures []Signature, eventID string) (Verification, error) + func (v *Verifier) VerifyRequest(ctx context.Context, request *http.Request, options RequestOptions) (verification Verification, body []byte, err error) + type VerifierConfig struct + Algorithm Algorithm + Clock func() time.Time + Keys []VerificationKey + Observer Observer + ReplayNamespace string + ReplayStore ReplayStore + ReplayTTL time.Duration + Tolerance time.Duration