Package africa.sendbyte.webhooks
Class WebhookSignature
java.lang.Object
africa.sendbyte.webhooks.WebhookSignature
Verifies the signature on inbound SendByte webhook requests.
Every delivery carries a "sendbyte-signature" header shaped like
t=<unix_seconds>,v1=<hex_hmac_sha256>. The signature is an HMAC-SHA256,
keyed with your endpoint's whsec_... secret, over the string
"<t>.<raw body>". The timestamp guards against replay attacks.
Always verify against the raw request body bytes, before any JSON parsing — re-serializing decoded JSON can change the bytes and break the check.
boolean ok = WebhookSignature.verify(
secret,
request.getHeader(WebhookSignature.SIGNATURE_HEADER),
rawBodyBytes);
if (!ok) { response.setStatus(401); return; }
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic StringCompute the "sendbyte-signature" header value for a body.static booleanVerify a raw byte body using thedefault tolerance.static booleanVerify a raw byte body against the signature header.static booleanVerify a string body using thedefault tolerance.
-
Field Details
-
SIGNATURE_HEADER
The header carrying the signature on every webhook delivery.- See Also:
-
DEFAULT_TOLERANCE
Default replay tolerance: reject deliveries whose timestamp is older than this.
-
-
Method Details
-
verify
Verify a string body using thedefault tolerance. -
verify
Verify a raw byte body using thedefault tolerance. -
verify
public static boolean verify(String secret, String signatureHeader, byte[] body, Duration tolerance) Verify a raw byte body against the signature header.- Parameters:
secret- the endpoint'swhsec_...signing secretsignatureHeader- the "sendbyte-signature" header valuebody- the raw request body bytes, before any parsingtolerance- maximum age of the signature timestamp; passDuration.ZEROor a negative value to skip the age check- Returns:
trueonly if the signature matches and the timestamp is within tolerance
-
sign
Compute the "sendbyte-signature" header value for a body. Useful for testing and for services that need to emit SendByte-compatible signatures.
-