Add encrypted captcha answer, move AES utils

This commit is contained in:
Alex Gleason
2024-10-03 19:36:44 -05:00
parent f83ad0dbce
commit 8d1b1b8abc
10 changed files with 75 additions and 60 deletions

View File

@@ -1,6 +1,9 @@
import { createCanvas, loadImage } from '@gfx/canvas-wasm';
import { encodeBase64 } from '@std/encoding/base64';
import { AppController } from '@/app.ts';
import { DittoWallet } from '@/DittoWallet.ts';
import { aesEncrypt } from '@/utils/aes.ts';
export const captchaController: AppController = async (c) => {
const { puzzle, piece, solution } = await generateCaptcha(
@@ -14,9 +17,20 @@ export const captchaController: AppController = async (c) => {
},
);
const answerData = {
solution,
created_at: new Date().toISOString(),
};
const encoded = new TextEncoder().encode(JSON.stringify(answerData));
const encrypted = await aesEncrypt(DittoWallet.captchaKey, encoded);
return c.json({
type: 'puzzle',
token: crypto.randomUUID(),
puzzle: puzzle.toDataURL(),
piece: piece.toDataURL(),
answer_data: encodeBase64(encrypted),
});
};