New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promised-entropy - npm Package Compare versions

Comparing version

to
0.1.0

const Promise = require('bluebird');
const entropy = Promise.promisifyAll(require('./lib/generator.js'));
const entropy = Promise.promisifyAll(require('./src/generator.js'));
exports.promisedEntropy = async (bits) => {
exports.promisedEntropy = async (bits, params) => {
if (!bits) {
throw new Error('Please specify how many bits of combined entropy you would like')
}
const generate = new entropy.Generator({})
const generate = new entropy.Generator(params || {})
// Pull requests for better solutions accepted

@@ -11,0 +12,0 @@ try {

{
"name": "promised-entropy",
"version": "0.0.9",
"version": "0.1.0",
"description": "Generate more entropy to combine with Node's crypto.rng or window.crypto",

@@ -11,3 +11,4 @@ "homepage": "https://github.com/masonicGIT/promised-entropy",

"devDependencies": {
"iced-coffee-script": "^1.7.1-c"
"iced-coffee-script": "^1.7.1-c",
"mocha": "^6.1.4"
},

@@ -22,2 +23,5 @@ "dependencies": {

"main": "index.js",
"scripts": {
"test": "node_modules/mocha/bin/mocha"
},
"licenses": [

@@ -24,0 +28,0 @@ {

@@ -39,9 +39,31 @@ promised-entropy

// create a generator, which can provide you with some entropy
const c = new m.Generator()
entropy = await m.promisedEntropy(bits)
// get an array of integers with at least 100 bits of combined entropy:
let entropy = await c.generate(100)
// get an array of integers with at least 256 bits of combined entropy:
let entropy = await m.promisedEntropy(256)
console.dir(entropy) // [-4358,543,9089,...]
```
Promised entropy can also be called with custom options
```javascript
const m = require('promised-entropy')
const params = {
'loop_delay': 10 // how many milliseconds to pause between each operation loop. A lower value will generate entropy faster, but will also be harder on the CPU
'work_min': 1 // milliseconds per loop; a higher value blocks the CPU more, so 1 is recommended
'auto_stop_bits': 4096 // the generator prepares entropy for you before you request it; if it reaches this much unclaimed entropy it will stop working
'max_bits_per_delta': 4 // a safety cap on how much entropy it can claim per value; 4 (default) is very conservative. a larger value will allow faster entropy generation
};
// create a generator, which can provide you with some entropy
entropy = await m.promisedEntropy(bits, params)
// get an array of integers with at least 256 bits of combined entropy:
let entropy = await m.promisedEntropy(256, params)
console.dir(entropy) // [-4358,543,9089,...]
```
### What it's doing

@@ -66,14 +88,1 @@

* your CPU is not shared with an attacker; a carefully timed attack on the CPU could produce entropy less than what's requested
### Options
`new m.Generator()` can be called with extra options:
```javascript
var c = new m.Generator({
'loop_delay': 10 // how many milliseconds to pause between each operation loop. A lower value will generate entropy faster, but will also be harder on the CPU
'work_min': 1 // milliseconds per loop; a higher value blocks the CPU more, so 1 is recommended
'auto_stop_bits': 4096 // the generator prepares entropy for you before you request it; if it reaches this much unclaimed entropy it will stop working
'max_bits_per_delta': 4 // a safety cap on how much entropy it can claim per value; 4 (default) is very conservative. a larger value will allow faster entropy generation
});
```