@libp2p/crypto
Version:
Crypto primitives for libp2p
13 lines (11 loc) • 425 B
text/typescript
import { InvalidParametersError } from '@libp2p/interface'
import { randomBytes as randB } from '@noble/hashes/utils'
/**
* Generates a Uint8Array with length `number` populated by random bytes
*/
export default function randomBytes (length: number): Uint8Array {
if (isNaN(length) || length <= 0) {
throw new InvalidParametersError('random bytes length must be a Number bigger than 0')
}
return randB(length)
}