js-libp2p-crypto/src/random-bytes.js
dirkmc 0b686d363c chore: add error codes (#155)
* chore: add error codes

* chore: create errors with new Error()

* fix: better error testin

* refactor: simplify random bytes error checks
2019-07-22 11:16:02 +01:00

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)
}