Skip to content

Commit

Permalink
Don't error if nonce is a number string (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
harryttd authored Oct 15, 2023
1 parent e6d1aa0 commit 1cd039b
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 1cd039b

Please sign in to comment.