import { fail } from './debug' ; let nodeCrypto ; try { nodeCrypto = require ( 'crypto' ) ; if ( ! nodeCrypto ?. randomBytes ) { nodeCrypto = undefined ; } } catch { } interface Crypto { getRandomValues < T extends Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array | DataView | null > ( array ) : T ; } declare const crypto ; function arrayToHex ( arr ) { return [ ... arr ] . map ( ( x ) => x . toString ( 16 ) . padStart ( 2 , '0' ) ) . join ( '' ) ; } export function randomBytesHex ( size ) { if ( nodeCrypto ) { return nodeCrypto . randomBytes ( size ) . toString ( 'hex' ) ; } if ( crypto ) { const buf = crypto . getRandomValues ( new Uint8Array ( size ) ) ; return arrayToHex ( buf ) ; } fail ( 'crypto library not found' ) ; }