further benchmarking stuff
This commit is contained in:
43
example-app/server/api/pow/algorithm.put.ts
Normal file
43
example-app/server/api/pow/algorithm.put.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { defineEventHandler } from 'h3'
|
||||
import { ChallengeAlgorithm } from '@impost/lib';
|
||||
import * as z from 'zod';
|
||||
|
||||
const algorithmSchema = z.object({
|
||||
algorithm: z.enum(ChallengeAlgorithm),
|
||||
});
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const body = await readValidatedBody(event, algorithmSchema.safeParse);
|
||||
|
||||
if (!body.success) {
|
||||
throw createError({
|
||||
statusCode: 400,
|
||||
statusMessage: 'Validation failed'
|
||||
})
|
||||
}
|
||||
|
||||
switch (body.data.algorithm) {
|
||||
case 'sha256':
|
||||
case 'argon2':
|
||||
config.algorithm = body.data.algorithm;
|
||||
config.strategy = config.strategy || 'leading_zeroes';
|
||||
switch (config.strategy) {
|
||||
case 'leading_zeroes':
|
||||
config.leading_zeroes.difficulty = config.leading_zeroes.difficulty || 4;
|
||||
break;
|
||||
case 'target_number':
|
||||
config.target_number.max_number = config.target_number.max_number || 10_000;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'kctf':
|
||||
config.algorithm = body.data.algorithm;
|
||||
config.kctf = config.kctf || {};
|
||||
config.kctf.difficulty = config.kctf.difficulty || 100;
|
||||
break;
|
||||
}
|
||||
|
||||
return {
|
||||
message: `Algorithm set to ${config.algorithm}`
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user