react-native-pkce-challenge
Version:
Proof Key for Code Exchange (PKCE) challenge generator for React Native
16 lines (11 loc) • 433 B
text/typescript
import { BYTE_LENGTH } from './utils';
export default function generateRandomBytes(): string {
if (typeof window === 'undefined') {
const buffer = require('crypto').randomBytes(BYTE_LENGTH);
const bytes = buffer.toString('base64');
return bytes;
}
const buffer = window.crypto.getRandomValues(new Uint8Array(BYTE_LENGTH));
const bytes = btoa(String.fromCharCode(...new Uint8Array(buffer)));
return bytes;
}