@@ -6,18 +6,20 @@ class Extensions{
66 this . ext = { } ;
77 }
88 #extensionID( ) {
9- var dt = new Date ( ) . getTime ( ) ,
10- // Replace the placeholders in the UUID template with random hexadecimal characters.
11- uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' . replace ( / [ x y ] / g, function ( c ) {
12- // Generate a random hexadecimal digit.
13- const r = ( dt + Math . random ( ) * 16 ) % 16 | 0 ;
14- // Update dt to simulate passage of time for the next random character.
15- dt = Math . floor ( dt / 16 ) ;
16- // Replace 'x' with a random digit and 'y' with a specific digit (4 for UUID version 4).
17- return ( c == 'x' ? r :( r & 0x3 | 0x8 ) ) . toString ( 16 ) ;
18- } ) ;
19- // Return the generated UUID.
20- return uuid ;
9+ // Create a buffer to hold random bytes
10+ const randomBytes = new Uint8Array ( 16 ) ;
11+ // Fill the buffer with cryptographically secure random values
12+ window . crypto . getRandomValues ( randomBytes ) ;
13+
14+ // Replace the placeholders in the UUID template with random hexadecimal characters
15+ const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' . replace ( / [ x y ] / g, function ( c ) {
16+ // Use random bytes to generate hexadecimal digits
17+ const r = randomBytes [ Math . floor ( Math . random ( ) * randomBytes . length ) ] ;
18+ // Replace 'x' with a random digit and 'y' with a specific digit (4 for UUID version 4)
19+ return ( c === 'x' ? ( r & 0x0f ) : ( r & 0x3 | 0x8 ) ) . toString ( 16 ) ;
20+ } ) ;
21+
22+ return uuid ;
2123 }
2224 /**
2325 * Gets file content
@@ -242,4 +244,4 @@ class Extensions{
242244 throw new Error ( '[WebServerAI] - "' + name + '" is no longer supported!' ) ;
243245 }
244246}
245- export default Extensions ;
247+ export default Extensions ;
0 commit comments