discord-interactions
Advanced tools
Comparing version 1.0.0 to 1.0.2
@@ -50,2 +50,5 @@ "use strict"; | ||
}); | ||
var InteractionResponseFlags = Object.freeze({ | ||
EPHEMERAL: 1 << 6, | ||
}); | ||
function verifyKey(rawBody, signature, timestamp, clientPublicKey) { | ||
@@ -114,2 +117,3 @@ return __awaiter(this, void 0, void 0, function () { | ||
InteractionResponseType: InteractionResponseType, | ||
InteractionResponseFlags: InteractionResponseFlags, | ||
verifyKey: verifyKey, | ||
@@ -116,0 +120,0 @@ verifyKeyMiddleware: verifyKeyMiddleware, |
{ | ||
"name": "discord-interactions", | ||
"version": "1.0.0", | ||
"version": "1.0.2", | ||
"description": "Helpers for discord interactions", | ||
@@ -18,3 +18,3 @@ "main": "dist/index.js", | ||
"build:watch": "tsc --watch", | ||
"format": "prettier --write \"src/**/*.ts\"", | ||
"format": "prettier --write \"(src|examples)/**/*.[tj]s\"", | ||
"lint": "tslint -p tsconfig.json" | ||
@@ -21,0 +21,0 @@ }, |
@@ -18,2 +18,13 @@ discord-interactions | ||
``` | ||
const signature = req.get('X-Signature-Ed25519'); | ||
const timestamp = req.get('X-Signature-Timestamp'); | ||
const isValidRequest = await verifyKey(req.rawBody, signature, timestamp, 'MY_CLIENT_PUBLIC_KEY'); | ||
if (!isValidRequest) { | ||
return res.status(403).end('Bad request signature'); | ||
} | ||
``` | ||
Note that `req.rawBody` must be populated by a middleware (it is also set by some cloud function providers). | ||
If you're using an express-like API, you can simplify things by using the `verifyKeyMiddleware`. For example: | ||
@@ -49,2 +60,6 @@ | ||
### InteractionResponseFlags | ||
An enum of flags you can set on your response data. | ||
### verifyKey(rawBody: Buffer, signature: string, timestamp: string, clientPublicKey: string): Promise<boolean> | ||
@@ -51,0 +66,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10636
120
70