diff --git a/src/middleware.ts b/src/middleware.ts index 4bca5a6..110098d 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -79,6 +79,7 @@ const validateChallengeBody = ( ) => { if (!env.DISABLE_CHALLENGES) { const { solution, nonce } = req.body + if (!solution || !nonce) { return res.status(400).send({ status: "ERROR", @@ -86,7 +87,7 @@ const validateChallengeBody = ( }) } - if (!Number.isInteger(nonce)) { + if (!Number.isInteger(Number(nonce))) { return res.status(400).send({ status: "ERROR", message: "'nonce' must be an integer", diff --git a/src/pow.ts b/src/pow.ts index 5e24d8a..58d5f33 100644 --- a/src/pow.ts +++ b/src/pow.ts @@ -112,13 +112,13 @@ export const getChallenge = async ( } satisfies ChallengeState as ChallengeState } -const getSolution = (challenge: string, nonce: number) => +const getSolution = (challenge: string, nonce: number | string) => createHash("sha256").update(`${challenge}:${nonce}`).digest("hex") interface VerifySolutionArgs { challenge: string difficulty: number - nonce: number + nonce: number | string solution: string } export const verifySolution = ({