generateOpenRouterCodeVerifier function
Generates a PKCE code verifier.
The output is a random URL-safe string suitable for the code_verifier
parameter. It uses a cryptographically secure random source when available
(Random.secure), falling back to a non-secure source only in test/JS
environments where Random.secure throws.
Implementation
String generateOpenRouterCodeVerifier() {
final random = _secureRandom();
final bytes = Uint8List(_verifierByteLength);
for (var i = 0; i < _verifierByteLength; i++) {
bytes[i] = random.nextInt(_verifierAlphabet.length);
}
return String.fromCharCodes(
bytes.map((b) => _verifierAlphabet.codeUnitAt(b)),
);
}