(token: string)
| 19 | * token is malformed or the payload is not valid JSON. |
| 20 | */ |
| 21 | export function decodeJwtPayload(token: string): unknown | null { |
| 22 | const jwt = token.startsWith('sk-ant-si-') |
| 23 | ? token.slice('sk-ant-si-'.length) |
| 24 | : token |
| 25 | const parts = jwt.split('.') |
| 26 | if (parts.length !== 3 || !parts[1]) return null |
| 27 | try { |
| 28 | return jsonParse(Buffer.from(parts[1], 'base64url').toString('utf8')) |
| 29 | } catch { |
| 30 | return null |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Decode the `exp` (expiry) claim from a JWT without verifying the signature. |
no test coverage detected