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

@consento/sync-randombytes

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@consento/sync-randombytes

Synchronous randombytes function that works in node, the browser & react-native!

  • 1.0.5
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
2.9K
increased by18.84%
Maintainers
2
Weekly downloads
 
Created
Source

sync-randombytes

Build Status JavaScript Style Guide

sync-randombytes is a polyfill for crypto.randomBytes that works in node, browsers, react-native (with support for versions < 0.60) and expo.

npm i sync-randombytes --save

Usage

You can use it like an other randomBytes function by calling:

const randomBytes = require('sync-randombytes')
const randomUint8Array = randomBytes(new Uint8Array(16))

Why?

  • React-native < 0.60 does not support crypto.randomBytes and you need a custom solution to implement a sync random method
  • Metro bundlers complain when you try to use react-native-randombytes as it's dependencies try to require('crypto') - which is not available in react-native.

How it works?

  • It uses window.crypto.getRandomBytes if available.
  • If 'crypto' can be "required" it will use
    • from node > 6.13: crypo.randomFill - or a polyfill that implements it using crypto.randomBytes for node < 6.13
  • .. else it will use seedrandom
    • with a randomseed from the native environment.
    • if not available: with a custom random-seed if expo is available. Random quality degraded
    • else the default random-seed if. Random quality degraded

License

MIT

with some source code adopted from react-native-randombytes

Keywords

FAQs

Package last updated on 07 May 2020

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