File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { BYTE_LENGTH } from './utils' ;
22
33export default function generateRandomBytes ( ) : string {
4- if ( typeof window ! == 'undefined' ) {
5- const buffer = window . crypto . getRandomValues ( new Uint8Array ( BYTE_LENGTH ) ) ;
6- const bytes = btoa ( String . fromCharCode ( ... new Uint8Array ( buffer ) ) ) ;
4+ if ( typeof window = == 'undefined' ) {
5+ const buffer = require ( ' crypto' ) . randomBytes ( BYTE_LENGTH ) ;
6+ const bytes = buffer . toString ( 'base64' ) ;
77
88 return bytes ;
99 }
1010
11- const buffer = require ( ' crypto' ) . randomBytes ( BYTE_LENGTH ) ;
12- const bytes = buffer . toString ( 'base64' ) ;
11+ const buffer = window . crypto . getRandomValues ( new Uint8Array ( BYTE_LENGTH ) ) ;
12+ const bytes = btoa ( String . fromCharCode ( ... new Uint8Array ( buffer ) ) ) ;
1313
1414 return bytes ;
1515}
Original file line number Diff line number Diff line change 1+ import { BYTE_LENGTH } from './utils' ;
2+
3+ export default function generateRandomBytes ( ) : string {
4+ const buffer = window . crypto . getRandomValues ( new Uint8Array ( BYTE_LENGTH ) ) ;
5+ const bytes = btoa ( String . fromCharCode ( ...new Uint8Array ( buffer ) ) ) ;
6+
7+ return bytes ;
8+ }
You can’t perform that action at this time.
0 commit comments