From c75c26044f290663cc6dff7913d98d8dc7affa2f Mon Sep 17 00:00:00 2001 From: Toby Date: Fri, 1 Mar 2024 20:31:24 +0100 Subject: [PATCH] remove math abs --- src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 0a10341..7268fb8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -221,10 +221,10 @@ export async function verify(token: string, secret: string | JsonWebKey | Crypto const now = Math.floor(Date.now() / 1000) - if (payload.nbf && payload.nbf > now && Math.abs(payload.nbf - now) > (options.clockTolerance ?? 0)) + if (payload.nbf && payload.nbf > now && (payload.nbf - now) > (options.clockTolerance ?? 0)) throw new Error("NOT_YET_VALID") - if (payload.exp && payload.exp <= now && Math.abs(payload.exp - now) > (options.clockTolerance ?? 0)) + if (payload.exp && payload.exp <= now && (now - payload.exp) > (options.clockTolerance ?? 0)) throw new Error("EXPIRED") const key = secret instanceof CryptoKey ? secret : await importKey(secret, algorithm, ["verify"])