npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jittertrng

v0.1.0

Published

Bindings for Jitterentropy Library - A Hardware RNG based on CPU timing jitter

Downloads

13

Readme

Node JitterTRNG

GitHub issues GitHub license Node version NPM version NPM downloads

This is a wrapper of jitterentropy-library, which is a hardware RNG based on CPU timing jitter, wrapped for Node.js.

For more information about this library, it is better to visit its site, www.chronox.de/jent.html.

This is my first attempt to create a native C++ module for Node.js, therefore it might be many bugs and might be just works on my machine. I have made some modification on the original source (Added a header) in order to make it compilable on Windows platform.

Usage

Please refer to documentation for exposed classes. :)

Example

const { JitterTrng } = require('jittertrng');

const rng = new JitterTrng();

async function() {
  console.log(await rng.randomAsync(100)); // Asynchronous call, get a float-point number between 0 and 100
}

console.log(rng.randomInt(1234, 5678)); // Synchronous call, gets an integer number between 1234 and 5678

const randombytes = rng.generate(100); // Gets 100 random bytes as a buffer.

rng.generateAsync(10000, (err, buffer) => {
  // Gets 10000 random bytes as a buffer.
});
// Getting large amount of random bits at once is slow, therefore asynchronous call will be safer as this does not block the javascript execution thread.
// Also, all asynchronous methods also provides old-school callback flow for use.

Or in a more convenient way:

const { RandomStream } = require('jittertrng');

(async() => {
  const rng = await RandomStream.create(1024); // Create a buffered random pool with 1024 bytes.
  // You also can use `new RandomStream(...)` constructor, but you have to be patient
  // because the pool does not immediately get ready after it constructs. (Async logic is used here)
  rng.random();
  rng.random(1, 10);
  rng.randomInt(1, 100);
  // Keep in mind that if the pool is already drain (and of cause it will starts to fill up at the background),
  // whatever you want to get, you will get undefined.
})();

Limits

As this is a true random number generator, it is not very efficient to get large amount of random numbers directly, even here I have made asynchronous direct and buffered methods to access the entropy. If you needs random values immediately at anytime and doesn't really mind the randomness, it is recommend to use other pseudo random number generators as a fallback, or you have another option to just use this as a source of seed for other pseudo random number generators.

Also, I don't make the memory secure here, this wrapper just pulls the random bytes out and pass it to the JavaScript engine, nothing is protecting them to prevent third party to access or spy on them. So if anyone wants to use this in something secure-critical is not recommend.

Installation

You can use

$ npm i jittertrng

to install this package.

As this is a native addon module, to use it you will have to prepare suitable C++ compilers (gcc for *nix systems and Visual C++ with Windows SDK for Windows systems) and node-gyp as a global dependency. Prebuilt binaries are not yet available, sorry about that :(

Contributing

Yes! If you don't mind my messy code and you want to make it better, issues and pull-requests are welcome!

License

Original jitterentropy-library is dual-licensed with BSD and GPLv2, all original notes are kept untouched in its own dependency directory. The wrapper and binding codes are licensed with MIT.