mirror of
https://github.com/fluencelabs/js-libp2p-crypto
synced 2025-03-15 21:30:59 +00:00
* chore: add error codes * chore: create errors with new Error() * fix: better error testin * refactor: simplify random bytes error checks
11 lines
325 B
JavaScript
11 lines
325 B
JavaScript
'use strict'
|
|
const randomBytes = require('iso-random-stream/src/random')
|
|
const errcode = require('err-code')
|
|
|
|
module.exports = function (length) {
|
|
if (isNaN(length) || length <= 0) {
|
|
throw errcode(new Error('random bytes length must be a Number bigger than 0'), 'ERR_INVALID_LENGTH')
|
|
}
|
|
return randomBytes(length)
|
|
}
|