diff --git a/cjs/dist/index.js b/cjs/dist/index.js index 5040a5f..99af199 100644 --- a/cjs/dist/index.js +++ b/cjs/dist/index.js @@ -70,11 +70,8 @@ async function verifySolution(payload, hmacKey, checkExpires = true) { } } const params = extractParams(payload); - if (checkExpires) { - const expires = params.expires || params.expire; - if (!expires) { - return false; - } + const expires = params.expires || params.expire; + if (checkExpires && expires) { const date = new Date(parseInt(expires, 10) * 1000); if (Number.isNaN(date.getTime()) || date.getTime() < Date.now()) { return false; diff --git a/deno_dist/index.ts b/deno_dist/index.ts index da5c47a..1693c74 100644 --- a/deno_dist/index.ts +++ b/deno_dist/index.ts @@ -90,11 +90,8 @@ export async function verifySolution( } } const params = extractParams(payload); - if (checkExpires) { - const expires = params.expires || params.expire; - if (!expires) { - return false; - } + const expires = params.expires || params.expire; + if (checkExpires && expires) { const date = new Date(parseInt(expires, 10) * 1000); if (Number.isNaN(date.getTime()) || date.getTime() < Date.now()) { return false; diff --git a/dist/index.js b/dist/index.js index 448af8f..b37e5c8 100644 --- a/dist/index.js +++ b/dist/index.js @@ -61,11 +61,8 @@ export async function verifySolution(payload, hmacKey, checkExpires = true) { } } const params = extractParams(payload); - if (checkExpires) { - const expires = params.expires || params.expire; - if (!expires) { - return false; - } + const expires = params.expires || params.expire; + if (checkExpires && expires) { const date = new Date(parseInt(expires, 10) * 1000); if (Number.isNaN(date.getTime()) || date.getTime() < Date.now()) { return false; diff --git a/lib/index.ts b/lib/index.ts index 1498a3b..b31682a 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -90,11 +90,8 @@ export async function verifySolution( } } const params = extractParams(payload); - if (checkExpires) { - const expires = params.expires || params.expire; - if (!expires) { - return false; - } + const expires = params.expires || params.expire; + if (checkExpires && expires) { const date = new Date(parseInt(expires, 10) * 1000); if (Number.isNaN(date.getTime()) || date.getTime() < Date.now()) { return false; diff --git a/package.json b/package.json index f43147f..f535b95 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "altcha-lib", - "version": "1.0.0", + "version": "1.1.0", "description": "A library for creating and verifying ALTCHA challenges for Node.js, Bun and Deno.", "author": { "name": "Daniel Regeci", diff --git a/tests/challenge.test.ts b/tests/challenge.test.ts index c337464..54c3a67 100644 --- a/tests/challenge.test.ts +++ b/tests/challenge.test.ts @@ -150,7 +150,6 @@ describe('challenge', () => { signature: challenge.signature, }, hmacKey, - false // don't check expires ); expect(ok).toEqual(true); }); @@ -289,27 +288,6 @@ describe('challenge', () => { expect(ok).toEqual(false); }); - it('should return false if the challenge does not include expires param but should be checked', async () => { - const number = 100; - const challenge = await createChallenge({ - expires: undefined, - number, - hmacKey, - }); - const ok = await verifySolution( - { - algorithm: challenge.algorithm, - challenge: challenge.challenge, - number, - salt: challenge.salt, - signature: challenge.signature, - }, - hmacKey, - true // make sure expires is checked - ); - expect(ok).toEqual(false); - }); - it('should return false if the expires is malformated', async () => { const number = 100; const challenge = await createChallenge({