Skip to content

Commit

Permalink
1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ovx committed Sep 11, 2024
1 parent a0994fc commit 811afbf
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 43 deletions.
7 changes: 2 additions & 5 deletions cjs/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 2 additions & 5 deletions deno_dist/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 2 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 2 additions & 5 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
22 changes: 0 additions & 22 deletions tests/challenge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ describe('challenge', () => {
signature: challenge.signature,
},
hmacKey,
false // don't check expires
);
expect(ok).toEqual(true);
});
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 811afbf

Please sign in to comment.