Implement algorithm switching

This commit implements every algorithm I have played with so far. It also allows for you to switch which algorithm you want to use at runtime.
This commit is contained in:
Zoe
2025-11-25 18:09:17 +00:00
parent 570531fe32
commit e16383e9b9
20 changed files with 1262 additions and 476 deletions

View File

@@ -4,13 +4,13 @@ import * as z from 'zod';
import { outstandingChallenges } from '~~/server/utils/pow';
const challengeSchema = z.object({
challenge: z.string().startsWith("s."),
solution: z.string().startsWith("s.")
salt: z.string(),
// either a string if the algorithm is kCTF, or a number if the algorithm is Argon2id or SHA256
solution: z.string().or(z.number()),
})
// post handler that takes in the challenge, and the nonce
export default defineEventHandler(async (event) => {
console.log(await readBody(event));
const body = await readValidatedBody(event, challengeSchema.safeParse);
if (!body.success) {
@@ -20,9 +20,9 @@ export default defineEventHandler(async (event) => {
})
}
let { challenge, solution } = body.data;
let { salt, solution } = body.data;
const outstanding_challenge = outstandingChallenges.get(challenge);
const outstanding_challenge = outstandingChallenges.get(salt);
if (outstanding_challenge === undefined) {
throw createError({
statusCode: 400,
@@ -37,8 +37,8 @@ export default defineEventHandler(async (event) => {
if (challenge_valid) {
// clear the challenge
clearTimeout(outstandingChallenges.get(challenge)!.timeout);
outstandingChallenges.delete(challenge);
clearTimeout(outstandingChallenges.get(salt)!.timeout);
outstandingChallenges.delete(salt);
return {
message: 'Challenge solved'