MCPcopy Create free account
hub / github.com/bewcloud/bewcloud / signAuthJwt

Function signAuthJwt

lib/auth.ts:32–39  ·  view source on GitHub ↗
(key: CryptoKey, data: T)

Source from the content-addressed store, hash-verified

30 await crypto.subtle.importKey('raw', textToData(key), { name: 'HMAC', hash: 'SHA-256' }, false, ['sign', 'verify']);
31
32async function signAuthJwt<T = JwtData>(key: CryptoKey, data: T): Promise<string> {
33 const payload = encodeBase64Url(textToData(JSON.stringify({ alg: 'HS256', typ: 'JWT' }))) + '.' +
34 encodeBase64Url(textToData(JSON.stringify(data) || ''));
35 const signature = encodeBase64Url(
36 new Uint8Array(await crypto.subtle.sign({ name: 'HMAC' }, key, textToData(payload))),
37 );
38 return `${payload}.${signature}`;
39}
40
41export async function verifyAuthJwt<T = JwtData>(key: CryptoKey, jwt: string): Promise<T> {
42 const jwtParts = jwt.split('.');

Callers

nothing calls this directly

Calls 1

textToDataFunction · 0.85

Tested by

no test coverage detected