()
| 58 | const RECOVERY_ALPHABET = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789'; |
| 59 | |
| 60 | function randomRecoveryCode(): string { |
| 61 | const bytes = new Uint8Array(10); |
| 62 | crypto.getRandomValues(bytes); |
| 63 | let out = ''; |
| 64 | for (let i = 0; i < bytes.length; i++) { |
| 65 | out += RECOVERY_ALPHABET[bytes[i]! % RECOVERY_ALPHABET.length]; |
| 66 | if (i === 4) { |
| 67 | out += '-'; |
| 68 | } |
| 69 | } |
| 70 | return out; |
| 71 | } |
| 72 | |
| 73 | export function generateRecoveryCodes(count = 10): string[] { |
| 74 | return Array.from({ length: count }, randomRecoveryCode); |
nothing calls this directly
no outgoing calls
no test coverage detected