Added test suite
All checks were successful
Build / Build NPM Project (push) Successful in 1m16s
Build / Tag Version (push) Successful in 14s
Build / Publish Documentation (push) Successful in 53s

This commit is contained in:
2025-05-14 16:30:42 -04:00
parent cf122ef9e8
commit fec373ca4c
32 changed files with 1719 additions and 310 deletions

View File

@ -1,7 +1,23 @@
import {JSONAttemptParse} from './objects.ts';
/**
* Decode a JWT payload, this will not check for tampering so be careful
* Creates a JSON Web Token (JWT) using the provided payload.
*
* @param {object} payload The payload to include in the JWT.
* @param signature Add a JWT signature
* @return {string} The generated JWT string.
*/
export function createJwt(payload: object, signature = 'unsigned'): string {
const header = Buffer.from(JSON.stringify({ alg: "HS256", typ: "JWT" }))
.toString('base64url');
const body = Buffer.from(JSON.stringify(payload))
.toString('base64url');
// Signature is irrelevant for decodeJwt
return `${header}.${body}.${signature}`;
}
/**
* Decode a JSON Web Token (JWT) payload, this will not check for tampering so be careful
*
* @param {string} token JWT to decode
* @return {unknown} JWT payload