import { isMsWindow } from '@aws-crypto/ie11-detection' ; import { supportsSecureRandom } from '@aws-crypto/supports-web-crypto' ; import { locateWindow } from '@aws-sdk/util-locate-window' ; export const synchronousRandomValues = generateSynchronousRandomValues ( locateWindow ( ) ) ; export function generateSynchronousRandomValues ( globalScope ) { return function synchronousRandomValues ( byteLength ) : Uint8Array { if ( supportsSecureRandom ( globalScope ) ) { return globalScope . crypto . getRandomValues ( new Uint8Array ( byteLength ) ) ; } else if ( isMsWindow ( globalScope ) ) { const values = new Uint8Array ( byteLength ) ; globalScope . msCrypto . getRandomValues ( values ) ; return values ; } throw new Error ( `Unable to locate a secure random source.` ) ; } ; }