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:
@@ -1,34 +1,52 @@
|
||||
import { readFileSync } from 'fs';
|
||||
import { load } from 'js-toml';
|
||||
import z from 'zod';
|
||||
import { ChallengeStrategy } from "@impost/lib";
|
||||
import { ChallengeAlgorithm, ChallengeStrategy } from "@impost/lib";
|
||||
|
||||
// const LeadingZeroesSchema = z.object({
|
||||
// strategy: z.literal(ChallengeStrategy.LeadingZeroes),
|
||||
// leading_zeroes: z.object({
|
||||
// difficulty: z.number().int().min(1).max(64),
|
||||
// }),
|
||||
// });
|
||||
const SHA256Schema = z.discriminatedUnion("strategy", [
|
||||
z.object({
|
||||
algorithm: z.literal(ChallengeAlgorithm.SHA256),
|
||||
strategy: z.literal(ChallengeStrategy.LeadingZeroes),
|
||||
leading_zeroes: z.object({
|
||||
difficulty: z.number().int().min(1).max(64),
|
||||
}),
|
||||
}),
|
||||
z.object({
|
||||
algorithm: z.literal(ChallengeAlgorithm.SHA256),
|
||||
strategy: z.literal(ChallengeStrategy.TargetNumber),
|
||||
target_number: z.object({
|
||||
max_number: z.number().int().min(1).max(100_000),
|
||||
}),
|
||||
}),
|
||||
]);
|
||||
|
||||
// const TargetNumberSchema = z.object({
|
||||
// strategy: z.literal(ChallengeStrategy.TargetNumber),
|
||||
// target_number: z.object({
|
||||
// max_number: z.number().int().min(1).max(100_000),
|
||||
// }),
|
||||
// });
|
||||
const Argon2idSchema = z.discriminatedUnion("strategy", [
|
||||
z.object({
|
||||
algorithm: z.literal(ChallengeAlgorithm.Argon2id),
|
||||
strategy: z.literal(ChallengeStrategy.LeadingZeroes),
|
||||
leading_zeroes: z.object({
|
||||
difficulty: z.number().int().min(1).max(64),
|
||||
}),
|
||||
}),
|
||||
z.object({
|
||||
algorithm: z.literal(ChallengeAlgorithm.Argon2id),
|
||||
strategy: z.literal(ChallengeStrategy.TargetNumber),
|
||||
target_number: z.object({
|
||||
max_number: z.number().int().min(1).max(100_000),
|
||||
}),
|
||||
}),
|
||||
]);
|
||||
|
||||
const kCTFSchema = z.object({
|
||||
strategy: z.literal(ChallengeStrategy.kCTF),
|
||||
const KCTFSchema = z.object({
|
||||
algorithm: z.literal(ChallengeAlgorithm.kCTF),
|
||||
kctf: z.object({
|
||||
difficulty: z.number().int().min(1),
|
||||
}),
|
||||
});
|
||||
|
||||
export type Config = z.infer<typeof Config>;
|
||||
export const Config = z.union([SHA256Schema, Argon2idSchema, KCTFSchema]);
|
||||
|
||||
export const Config = z.discriminatedUnion('strategy', [
|
||||
kCTFSchema,
|
||||
]);
|
||||
export type Config = z.infer<typeof Config>;
|
||||
|
||||
export let config: Config;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user