feat: add discord interactions worker

This commit is contained in:
41666 2021-08-01 15:45:15 -04:00
parent dde05c402e
commit 9354047447
36 changed files with 486 additions and 178 deletions

View file

@ -0,0 +1,25 @@
import { publicKey } from '@roleypoly/interactions/utils/config';
import nacl from 'tweetnacl';
export const verifyRequest = async (request: Request): Promise<boolean> => {
const timestamp = request.headers.get('x-signature-timestamp');
const signature = request.headers.get('x-signature-ed25519');
if (!timestamp || !signature) {
return false;
}
const body = await request.json();
if (
!nacl.sign.detached.verify(
Buffer.from(timestamp + JSON.stringify(body)),
Buffer.from(signature, 'hex'),
Buffer.from(publicKey, 'hex')
)
) {
return false;
}
return true;
};