File tree 1 file changed +14
-12
lines changed
1 file changed +14
-12
lines changed Original file line number Diff line number Diff line change @@ -10,19 +10,21 @@ function normalizedFunctionString(fn) {
10
10
return fn . toString ( ) . replace ( 'function(' , 'function (' ) ;
11
11
}
12
12
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 ) ) ;
24
22
} else {
25
- randomBytes = require ( 'crypto' ) . randomBytes ;
23
+ try {
24
+ randomBytes = require ( 'crypto' ) . randomBytes ;
25
+ } catch ( e ) {
26
+ // keep the fallback
27
+ }
26
28
}
27
29
28
30
module . exports = {
You can’t perform that action at this time.
0 commit comments