Initial commit

Once again a weird place to commit, I have already done a lot of work, but I am just bad at using git, okay.
This commit is contained in:
Zoe
2025-11-17 16:12:26 +00:00
commit cfab3d0b8f
58 changed files with 18689 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
import { defineEventHandler } from 'h3'
import { validate_challenge } from '@impost/lib/validator';
import * as z from 'zod';
import { outstandingChallenges } from '~~/server/utils/pow';
const challengeSchema = z.object({
challenge: z.string(),
nonce: z.string()
})
// post handler that takes in the challenge, and the nonce
export default defineEventHandler(async (event) => {
const body = await readValidatedBody(event, challengeSchema.safeParse);
if (!body.success) {
throw createError({
statusCode: 400,
statusMessage: 'Validation failed'
})
}
let target = body.data.challenge;
let nonce = body.data.nonce;
// check if the challenge is valid
let challenge_valid = await validate_challenge(outstandingChallenges.get(target)!.challenge, {
challenge: target,
nonce: nonce
});
if (challenge_valid) {
// clear the challenge
clearTimeout(outstandingChallenges.get(target)!.timeout);
outstandingChallenges.delete(target);
return {
message: 'Challenge solved'
};
}
throw createError({
statusCode: 400,
statusMessage: 'Challenge is not valid'
})
})