pure-randombytes

1.0.1 • Public • Published

randombytes

Get secure cryptographic random bytes from of any TypedArray, ArrayBuffer or size without importing node:crypto or node:buffer to browsers.

import randomBytes from 'pure-randombytes'

randomBytes() // return Uint8(20) - default to 20 (same as sha1 length)
randomBytes(16) // return Uint8(16)
randomBytes("10") // return Uint8(16) - Anything that isn't TypedArray is casted to Number(x)

Still want to get a randomized node:buffer back or have something pre allocated? Stuff it in as the first argument, and get the same instance back

randomBytes(uint8) === uint8 // works with pre allocated buffer
randomBytes(bigInt64_or_dataView) // ...and any kind of ArrayBufferView
randomBytes(new ArrayBuffer(33)) instanceof ArrayBuffer // ...ArrayBuffer
randomBytes(Buffer.allocUnsafe(20)) instanceof Buffer // ...and yes, Buffer as well

Package Sidebar

Install

npm i pure-randombytes

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

6.17 kB

Total Files

6

Last publish

Collaborators

  • endless