* Gets the last 4 characters of an encrypted API key by decrypting it first * @param encryptedKey - The encrypted API key from the database * @returns Promise - The last 4 characters
(encryptedKey: string)
| 142 | * @returns Promise<string> - The last 4 characters |
| 143 | */ |
| 144 | async function getEncryptedApiKeyLast4(encryptedKey: string): Promise<string> { |
| 145 | try { |
| 146 | if (isEncryptedKey(encryptedKey)) { |
| 147 | const decryptedKey = await decryptApiKeyFromStorage(encryptedKey) |
| 148 | return getApiKeyLast4(decryptedKey) |
| 149 | } |
| 150 | // For plain text keys (legacy), return last 4 directly |
| 151 | return getApiKeyLast4(encryptedKey) |
| 152 | } catch (error) { |
| 153 | logger.error('Failed to get last 4 characters of API key:', { error }) |
| 154 | return '****' |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Validates API key format (basic validation) |
nothing calls this directly
no test coverage detected