@arianee/arianee-access-token
Advanced tools
Comparing version 0.3.0 to 0.3.1
{ | ||
"name": "@arianee/arianee-access-token", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"dependencies": { | ||
@@ -5,0 +5,0 @@ "ethers": "6.3.0" |
@@ -16,4 +16,4 @@ import { Core } from '@arianee/core'; | ||
createActionArianeeAccessTokenLink(url: string, certificateId: number, network: string): Promise<string>; | ||
static isArianeeAccessTokenValid(arianeeAccessToken: string): boolean; | ||
static decodeJwt(arianeeAccessToken: string): { | ||
static isArianeeAccessTokenValid(arianeeAccessToken: string, ignoreExpiration?: boolean): boolean; | ||
static decodeJwt(arianeeAccessToken: string, ignoreExpiration?: boolean): { | ||
header: JwtHeaderInterface; | ||
@@ -20,0 +20,0 @@ payload: ArianeeAccessTokenPayload; |
@@ -34,3 +34,3 @@ "use strict"; | ||
} | ||
static isArianeeAccessTokenValid(arianeeAccessToken) { | ||
static isArianeeAccessTokenValid(arianeeAccessToken, ignoreExpiration = false) { | ||
const recover = (message, signature) => ethers_1.ethers.verifyMessage(message, signature); | ||
@@ -40,6 +40,6 @@ const jwtGenerator = new jwtGeneric_1.JWTGeneric({ recover }); | ||
const iss = jwt.decode().payload.iss; | ||
return jwt.verify(iss); | ||
return jwt.verify(iss, ignoreExpiration); | ||
} | ||
static decodeJwt(arianeeAccessToken) { | ||
const isAatValid = ArianeeAccessToken.isArianeeAccessTokenValid(arianeeAccessToken); | ||
static decodeJwt(arianeeAccessToken, ignoreExpiration = false) { | ||
const isAatValid = ArianeeAccessToken.isArianeeAccessTokenValid(arianeeAccessToken, ignoreExpiration); | ||
if (!isAatValid) { | ||
@@ -46,0 +46,0 @@ throw new Error('ArianeeAccessToken is not valid'); |
@@ -32,3 +32,3 @@ import { ArianeeAccessTokenPayload } from '../types/arianeeAccessTokenPayload'; | ||
}; | ||
verify: (pubKey: string) => boolean; | ||
verify: (pubKey: string, ignoreExpiration?: boolean) => boolean; | ||
}; | ||
@@ -35,0 +35,0 @@ private static base64Stringified; |
@@ -25,4 +25,4 @@ "use strict"; | ||
}); | ||
this.arePropertiesValid = (payload) => { | ||
if (payload.exp) { | ||
this.arePropertiesValid = (payload, ignoreExpiration = false) => { | ||
if (payload.exp && !ignoreExpiration) { | ||
const isExpired = new Date(payload.exp).getTime() < Date.now(); | ||
@@ -75,3 +75,3 @@ if (isExpired) { | ||
*/ | ||
verify(pubKey) { | ||
verify(pubKey, ignoreExpiration = false) { | ||
if (!this.params.recover) { | ||
@@ -85,3 +85,3 @@ throw new Error('You should provide a decoder to verify your token'); | ||
const decode = this.params.recover(joinedHeaderPayload, signature); | ||
const arePropertyValid = this.arePropertiesValid(payload); | ||
const arePropertyValid = this.arePropertiesValid(payload, ignoreExpiration); | ||
if (!arePropertyValid) { | ||
@@ -88,0 +88,0 @@ return false; |
@@ -6,3 +6,3 @@ "use strict"; | ||
function isExpInLessThan(aat, timeBeforeExpInSec) { | ||
const decoded = arianee_access_token_1.ArianeeAccessToken.decodeJwt(aat); | ||
const decoded = arianee_access_token_1.ArianeeAccessToken.decodeJwt(aat, true); | ||
const now = new Date().getTime(); | ||
@@ -9,0 +9,0 @@ return decoded.payload.exp - now < timeBeforeExpInSec * 1000; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
19782