Skip to content

Commit

Permalink
Don't error if nonce is a number string
Browse files Browse the repository at this point in the history
  • Loading branch information
harryttd committed Oct 15, 2023
1 parent e6d1aa0 commit 60a6da6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,15 @@ const validateChallengeBody = (
) => {
if (!env.DISABLE_CHALLENGES) {
const { solution, nonce } = req.body

if (!solution || !nonce) {
return res.status(400).send({
status: "ERROR",
message: "'solution', and 'nonce', fields are required",
})
}

if (!Number.isInteger(nonce)) {
if (!Number.isInteger(Number(nonce))) {
return res.status(400).send({
status: "ERROR",
message: "'nonce' must be an integer",
Expand Down
4 changes: 2 additions & 2 deletions src/pow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ({
Expand Down

0 comments on commit 60a6da6

Please sign in to comment.