Class Signatures
java.lang.Object
lv.id.jc.dicechess.runtime.Signatures
HMAC-SHA256 signing and verification for the DiceChess webhook delivery protocol.
The signed payload is timestamp + "." + body, hex-encoded. A delivery is accepted
only if its timestamp falls within REPLAY_WINDOW_SECONDS of the verifier's clock,
and the comparison is constant-time to avoid leaking the secret through timing.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longThe signature is only accepted within this many seconds of the current time, either side. -
Method Summary
-
Field Details
-
REPLAY_WINDOW_SECONDS
public static final long REPLAY_WINDOW_SECONDSThe signature is only accepted within this many seconds of the current time, either side.- See Also:
-
-
Method Details
-
sign
Computes the hex-encoded HMAC-SHA256 signature for a delivery.- Parameters:
secret- the webhook secret issued by the platformtimestampEpochSeconds- the delivery timestamp, Unix epoch secondsbody- the raw request body, exactly as transmitted- Returns:
- the lowercase hex signature
-
verify
public static boolean verify(String secret, long timestampEpochSeconds, String body, String signature, long nowEpochSeconds) Verifies a delivery's signature and freshness.- Parameters:
secret- the webhook secret issued by the platformtimestampEpochSeconds- the delivery's claimed timestamp, Unix epoch secondsbody- the raw request body, exactly as receivedsignature- the hex signature supplied with the deliverynowEpochSeconds- the verifier's current time, Unix epoch seconds- Returns:
trueif the timestamp is withinREPLAY_WINDOW_SECONDSand the signature matches
-