(base64: string, variant: 'base64' | 'base64url' = 'base64')
| 30 | * Decode a base64 string to a Uint8Array |
| 31 | */ |
| 32 | export function decodeBase64(base64: string, variant: 'base64' | 'base64url' = 'base64'): Uint8Array { |
| 33 | if (variant === 'base64url') { |
| 34 | const base64Standard = base64 |
| 35 | .replaceAll('-', '+') |
| 36 | .replaceAll('_', '/') |
| 37 | + '='.repeat((4 - base64.length % 4) % 4); |
| 38 | return new Uint8Array(Buffer.from(base64Standard, 'base64')); |
| 39 | } |
| 40 | return new Uint8Array(Buffer.from(base64, 'base64')); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Generate secure random bytes |
no outgoing calls
no test coverage detected