File tree Expand file tree Collapse file tree 1 file changed +14
-12
lines changed Expand file tree Collapse file tree 1 file changed +14
-12
lines changed Original file line number Diff line number Diff line change @@ -10,19 +10,21 @@ function normalizedFunctionString(fn) {
1010 return fn . toString ( ) . replace ( 'function(' , 'function (' ) ;
1111}
1212
13- let randomBytes ;
14- if ( typeof window !== 'undefined' ) {
15- if ( window . crypto && window . crypto . getRandomValues ) {
16- randomBytes = size => window . crypto . getRandomValues ( new Uint8Array ( size ) ) ;
17- } else {
18- randomBytes = size => {
19- const result = new Uint8Array ( size ) ;
20- for ( let i = 0 ; i < size ; ++ i ) result [ i ] = Math . floor ( Math . random ( ) * 256 ) ;
21- return result ;
22- } ;
23- }
13+ function insecureRandomBytes ( size ) {
14+ const result = new Uint8Array ( size ) ;
15+ for ( let i = 0 ; i < size ; ++ i ) result [ i ] = Math . floor ( Math . random ( ) * 256 ) ;
16+ return result ;
17+ }
18+
19+ let randomBytes = insecureRandomBytes ;
20+ if ( typeof window !== 'undefined' && window . crypto && window . crypto . getRandomValues ) {
21+ randomBytes = size => window . crypto . getRandomValues ( new Uint8Array ( size ) ) ;
2422} else {
25- randomBytes = require ( 'crypto' ) . randomBytes ;
23+ try {
24+ randomBytes = require ( 'crypto' ) . randomBytes ;
25+ } catch ( e ) {
26+ // keep the fallback
27+ }
2628}
2729
2830module . exports = {
You can’t perform that action at this time.
0 commit comments