Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

secure-random

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

secure-random

Normalize the creation of cryptographically strong random values.

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
50K
decreased by-51.07%
Maintainers
1
Weekly downloads
 
Created
Source

secure-random

build status

browser support

A simple JavaScript component to normalize the creation of cryptographically strong random values.

Why?

Context switching between the browser and Node.js and creating cryptographically secure random numbers is annoying. This normalizes the behavior. Used by CryptoCoinJS and BitcoinJS.

Install

Node.js/Browserify

npm install --save secure-random

Component

component install jprichardson/secure-random

Bower

bower install secure-random

Script

<script src="/path/to/secure-random.js"></script>

Usage

secureRandom(byteCount, options)

  • byteCount: is the number of bytes to return.
  • options: options to pass. Only valid value at this time type. type can be either Array, Uint8Array, or Buffer. Buffer is only valid in Node.js or Browserify environments - it will throw an error otherwise.

return an Array:

var bytes = secureRandom(10) //return an Array of 10 bytes
console.log(bytes.length) //10

or:

var bytes = secureRandom(10, {type: 'Array'}) //return an Array of 10 bytes
console.log(bytes.length) //10

return a Buffer:

var bytes = secureRandom(10, {type: 'Buffer'}) //return a Buffer of 10 bytes
console.log(bytes.length) //10

return a Uint8Array:

var bytes = secureRandom(10, {type: 'Uint8Array'}) //return a Uint8Array of 10 bytes
console.log(bytes.length) //10

randomArray(byteLength)

Sugar for secureRandom(byteLength, {type: 'Array'}).

var secureRandom = require('secure-random')
var data = secureRandom.randomArray(10)

randomUint8Array(byteLength)

Sugar for secureRandom(byteLength, {type: 'Uint8Array'}).

var secureRandom = require('secure-random')
var data = secureRandom.randomUint8Array(10)

randomBuffer(byteLength)

Sugar for secureRandom(byteLength, {type: 'Buffer'}).

var secureRandom = require('secure-random')
var data = secureRandom.randomBuffer(10)

References

License

(MIT License)

Copyright 2013-2014, JP Richardson

Keywords

FAQs

Package last updated on 03 Jun 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc