UNPKG

ara-identity

Version:

Create and resolve decentralized identity based Ara identifiers.

20 lines (15 loc) 485 B
const randombytes = require('randombytes') const { toHex } = require('../util') const kDefaultEntropySize = 32 const kMinEntropySize = 16 async function entropy(size) { let entropySize = size if (null == entropySize) { entropySize = kDefaultEntropySize } if (!entropySize || entropySize < kMinEntropySize) { throw new TypeError(`Invalid entropy size. Must be larger than ${kMinEntropySize}.`) } return toHex(randombytes(entropySize)) } module.exports = { entropy }