Function Signature
Description
Validates a payload from Discord against its signature and key using the Ed25519 cryptographic signature algorithm. This function is used internally by the middleware functions but can also be used directly for custom verification implementations.Parameters
The raw payload data received from Discord. This should be the unmodified request body.
The signature from the
X-Signature-Ed25519 header sent by Discord.The timestamp from the
X-Signature-Timestamp header sent by Discord.The public key from the Discord developer dashboard. Can be provided as a hex-encoded string or as a
CryptoKey object.Returns
Returns
true if the signature is valid and the payload is authentic, false otherwise. The function will also return false if any error occurs during verification.Usage Example
Implementation Details
The function:- Converts the timestamp and body to
Uint8Arrayformat - Concatenates the timestamp and body data
- Imports the public key if provided as a string (hex-encoded)
- Verifies the signature using the Ed25519 algorithm via the Web Crypto API
- Returns
trueif verification succeeds,falseif it fails or any error occurs
See Also
- verifyKeyMiddleware - Express middleware for interaction verification
- verifyWebhookEventMiddleware - Express middleware for webhook event verification