Implement strength for whole library

This commit is contained in:
2024-09-12 01:31:45 +02:00
parent 524e9026b8
commit 76cf4632e4
14 changed files with 97 additions and 66 deletions
+6 -5
View File
@@ -1,16 +1,17 @@
import * as jose from 'jose'
import logger from 'log'
import {generateSecret, jwtVerify, type KeyLike, SignJWT} from 'jose'
import {JWT_ALGORITHM} from './const'
const log = logger('crypto:jwt')
export type Key = jose.KeyLike | Uint8Array
export type Key = KeyLike | Uint8Array
export class JWTcontext {
private constructor(private readonly key: Key) {}
public static async gen_key(): Promise<Key> {
log.trace('generate key')
return await jose.generateSecret('HS512')
return await generateSecret(JWT_ALGORITHM())
}
public static new(key: Key): JWTcontext {
return new JWTcontext(key)
@@ -34,7 +35,7 @@ export class JWTcontext {
issuer
})
let jwt = new jose.SignJWT({message}).setProtectedHeader({alg: 'HS512'})
let jwt = new SignJWT({message}).setProtectedHeader({alg: JWT_ALGORITHM()})
if (set_issued) jwt = jwt.setIssuedAt()
if (issuer !== undefined) jwt = jwt.setIssuer(issuer)
@@ -50,7 +51,7 @@ export class JWTcontext {
log.trace('Audience :', audience)
try {
let payload = await jose.jwtVerify(jwt, this.key, {audience, issuer})
let payload = await jwtVerify(jwt, this.key, {audience, issuer})
return payload.payload.message as T
} catch (e) {
log.warn('JWT verification failed')