From 1cd039bfa5a6ddd249665bb981a5740b50270460 Mon Sep 17 00:00:00 2001 From: Aryeh Harris Date: Sat, 14 Oct 2023 22:37:42 -0400 Subject: [PATCH] Don't error if nonce is a number string (#8) --- src/middleware.ts | 3 ++- src/pow.ts | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) 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 = ({