11import { randomBytes } from 'node:crypto'
22
3- import { EntropyByBytes , EntropyByValues , EntropyFunction , Puid , PuidConfig , PuidResult } from '../types/puid'
3+ import { EntropyFunction , Puid , PuidConfig , PuidResult } from '../types/puid'
44
55import muncher from './bits'
66import { Chars , charsName , validChars } from './chars'
@@ -12,17 +12,17 @@ const round2 = (f: number): number => round(f * 100) / 100
1212const { ceil, round } = Math
1313
1414const selectEntropyFunction = ( puidConfig : PuidConfig ) : EntropyFunction => {
15- if ( puidConfig . entropyValues ) return [ true , puidConfig . entropyValues as EntropyByValues ]
16- if ( puidConfig . entropyBytes ) return [ false , puidConfig . entropyBytes as EntropyByBytes ]
15+ if ( puidConfig . entropyValues ) return { byValues : true , source : puidConfig . entropyValues }
16+ if ( puidConfig . entropyBytes ) return { byValues : false , source : puidConfig . entropyBytes }
1717
1818 // Prefer Web Crypto in environments where it's available
1919 type CryptoLike = { getRandomValues ?: ( b : Uint8Array ) => void }
2020 const cryptoObj = ( globalThis as { crypto ?: CryptoLike } ) . crypto
2121 const gv = cryptoObj ?. getRandomValues ?. bind ( cryptoObj ) as ( ( b : Uint8Array ) => void ) | undefined
22- if ( gv ) return [ true , gv ]
22+ if ( gv ) return { byValues : true , source : gv }
2323
2424 // Fallback to Node's randomBytes
25- return [ false , randomBytes ]
25+ return { byValues : false , source : randomBytes }
2626}
2727
2828/**
0 commit comments