mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-06-16 17:49:09 +00:00
fix(interactions): deployment + handler
This commit is contained in:
parent
3ca37cff17
commit
61b1146774
7 changed files with 58 additions and 12 deletions
|
@ -17,12 +17,12 @@ const commands: Record<
|
|||
};
|
||||
|
||||
export const interactionHandler = async (request: Request): Promise<Response> => {
|
||||
if (!(await verifyRequest(request))) {
|
||||
const interaction = (await request.json()) as InteractionRequest;
|
||||
|
||||
if (!verifyRequest(request, interaction)) {
|
||||
return new Response('invalid request signature', { status: 401 });
|
||||
}
|
||||
|
||||
const interaction = (await request.json()) as InteractionRequest;
|
||||
|
||||
if (interaction.type === InteractionType.PING) {
|
||||
return respond({ type: 1 });
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import { uiPublicURI } from './utils/config';
|
|||
const router = new Router();
|
||||
|
||||
router.add('GET', '_healthz', healthz);
|
||||
router.add('POST', 'interaction', interactionHandler);
|
||||
router.add('POST', 'interactions', interactionHandler);
|
||||
|
||||
// Root Zen <3
|
||||
router.addFallback('root', () => {
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
import { publicKey } from '@roleypoly/interactions/utils/config';
|
||||
import { InteractionRequest } from '@roleypoly/types';
|
||||
import nacl from 'tweetnacl';
|
||||
|
||||
export const verifyRequest = async (request: Request): Promise<boolean> => {
|
||||
export const verifyRequest = (
|
||||
request: Request,
|
||||
interaction: InteractionRequest
|
||||
): boolean => {
|
||||
const timestamp = request.headers.get('x-signature-timestamp');
|
||||
const signature = request.headers.get('x-signature-ed25519');
|
||||
|
||||
|
@ -9,11 +13,9 @@ export const verifyRequest = async (request: Request): Promise<boolean> => {
|
|||
return false;
|
||||
}
|
||||
|
||||
const body = await request.json();
|
||||
|
||||
if (
|
||||
!nacl.sign.detached.verify(
|
||||
Buffer.from(timestamp + JSON.stringify(body)),
|
||||
Buffer.from(timestamp + JSON.stringify(interaction)),
|
||||
Buffer.from(signature, 'hex'),
|
||||
Buffer.from(publicKey, 'hex')
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue