(key: CryptoKey, data: T)
| 30 | await crypto.subtle.importKey('raw', textToData(key), { name: 'HMAC', hash: 'SHA-256' }, false, ['sign', 'verify']); |
| 31 | |
| 32 | async 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 | |
| 41 | export async function verifyAuthJwt<T = JwtData>(key: CryptoKey, jwt: string): Promise<T> { |
| 42 | const jwtParts = jwt.split('.'); |
nothing calls this directly
no test coverage detected