import root from 'window-or-global' ; import './base64' ; import SafeBuffer from './SafeBuffer' ; const isocrypto = require ( 'isomorphic-webcrypto' ) ; export const crypto = isocrypto . default || isocrypto ; export const Buffer = SafeBuffer ; const api = { Buffer , TextDecoder : root && root . TextDecoder , TextEncoder : root && root . TextEncoder } ; api . random = ( len ) => api . Buffer . from ( crypto . getRandomValues ( new Uint8Array ( api . Buffer . alloc ( len ) ) ) ) ; if ( ! api . TextEncoder ) { const { TextEncoder , TextDecoder } = eval ( 'require' ) ( 'text-encoding' ) ; api . TextEncoder = TextEncoder ; api . TextDecoder = TextDecoder ; } export const TextEncoder = api . TextEncoder ; export const TextDecoder = api . TextDecoder ; export const random = api . random ;