import { JWS } from "node-jose" ; import { decodeJWSPayload } from "./decodeJWSPayload" ; import { Handler } from "./index" ; export const createExpVerifier = ( tolerance = 0 ) : Handler => { const expOkay = ( exp ) => exp - new Date ( ) . getTime ( ) / 1000 > - tolerance ; return { complete : ( jws ) => new Promise ( ( resolve , reject ) => { const { exp : expClaim } = decodeJWSPayload ( jws ) ; if ( expOkay ( expClaim ) ) { resolve ( ) ; return ; } reject ( ) ; } ) , } ; } ;