Skip to content

Commit

Permalink
Adding nonce to pow captcha (#1496)
Browse files Browse the repository at this point in the history
  • Loading branch information
forgetso authored Nov 4, 2024
2 parents 486a6e9 + 017e1ad commit a53540d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions packages/provider/src/tasks/powCaptcha/powTasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ export class PowCaptchaManager {
powDifficulty?: number,
): Promise<PoWCaptcha> {
const difficulty = powDifficulty || DEFAULT_POW_DIFFICULTY;

const requestedAtTimestamp = Date.now();

// Create nonce for the challenge
const nonce = Math.floor(Math.random() * 1000000);

// Use blockhash, userAccount and dappAccount for string for challenge
const challenge: PoWChallengeId = `${requestedAtTimestamp}___${userAccount}___${dappAccount}`;
const challenge: PoWChallengeId = `${requestedAtTimestamp}___${userAccount}___${dappAccount}___${nonce}`;
const challengeSignature = u8aToHex(this.pair.sign(stringToHex(challenge)));
return {
challenge,
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/datasets/captcha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export const PowChallengeIdSchema = custom<PoWChallengeId>((val: any) => {
const valSplit = val.split(POW_SEPARATOR);
try {
Number.parseInt(valSplit[0]);
return valSplit.length === 3;
return valSplit.length === 4;
} catch (e) {
return false;
}
Expand Down

0 comments on commit a53540d

Please sign in to comment.