File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -124,7 +124,18 @@ const generateJoinServerOnlyConfig = config => {
124124 * @param {number } length - The length of the resulting hex value.
125125 * @returns {string } - Pseudorandom hex value of length `length`.
126126 */
127- const generateHexValue = length => crypto . randomBytes ( Math . floor ( length / 2 ) ) . toString ( 'hex' )
127+ const generateHexValue = ( length ) => {
128+ const byteLen = Math . ceil ( length / 2 )
129+ const bytes = new Uint8Array ( byteLen )
130+ if ( globalThis . crypto ?. getRandomValues ) {
131+ globalThis . crypto . getRandomValues ( bytes )
132+ } else {
133+ for ( let i = 0 ; i < byteLen ; i ++ ) bytes [ i ] = Math . floor ( Math . random ( ) * 256 )
134+ }
135+ let hex = ''
136+ for ( let i = 0 ; i < byteLen ; i ++ ) hex += bytes [ i ] . toString ( 16 ) . padStart ( 2 , '0' )
137+ return hex . slice ( 0 , length )
138+ }
128139
129140const generateCollaborator = ( entity , type ) => {
130141 const collabUserId = 'test-collab-user'
You can’t perform that action at this time.
0 commit comments