Skip to content

WebhookSigner

Namespace AgentPrism · Assembly AgentPrism.Core.dll

Produces and verifies the HMAC-SHA256 signature of webhook requests.

public static class WebhookSigner

objectWebhookSigner

object.GetType(), object.MemberwiseClone(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

The signature is computed from the string: {timestamp}.{body}. The timestamp is included in the signature; otherwise a captured request could be replayed forever.

When verifying the signature, the recipient must also check that the timestamp is within its own tolerance. AgentPrism cannot enforce this; it is documented in the README.

The header that carries the delivery identity. Used to distinguish duplicate deliveries.

public const string DeliveryHeader = "X-AgentPrism-Delivery"

string

The header that carries the event name.

public const string EventHeader = "X-AgentPrism-Event"

string

The header that carries the signature.

public const string SignatureHeader = "X-AgentPrism-Signature"

string

The header that carries the timestamp, in Unix seconds.

public const string TimestampHeader = "X-AgentPrism-Timestamp"

string

Reports whether a header name is one AgentPrism sets itself.

public static bool IsReservedHeader(string? name)

name string?

The header name to check.

bool

true if the name is reserved.

A subscription’s extra headers are administrator input. Letting one of them carry a reserved name would append a second value to a header the recipient verifies, which the recipient cannot resolve.

Produces a signature for a body and timestamp.

public static string Sign(string body, DateTimeOffset timestamp, string secret)

body string

The JSON body to send.

timestamp DateTimeOffset

The request’s timestamp.

secret string

The signing secret.

string

The signature, in the form sha256=<hex>.

ArgumentException

secret is empty.

Verify(string, DateTimeOffset, string, string?)

Section titled “ Verify(string, DateTimeOffset, string, string?)”

Verifies a signature.

public static bool Verify(string body, DateTimeOffset timestamp, string secret, string? signature)

body string

The received body.

timestamp DateTimeOffset

The timestamp in the request.

secret string

The signing secret.

signature string?

The signature in the request.

bool

true if the signature is valid.

The comparison is constant-time, using CryptographicOperations.FixedTimeEquals: an ordinary string comparison would let the signature be guessed byte by byte from the time taken until the first differing byte.