Skip to content

LinusU/react-native-get-random-values

Folders and files

NameName
Last commit message
Last commit date

Latest commit

d2a10c1 Β· Mar 10, 2020

History

15 Commits
Mar 10, 2020
Aug 20, 2018
Aug 20, 2018
Aug 20, 2018
Feb 26, 2020
Aug 20, 2018
Feb 26, 2020
Mar 10, 2020
Mar 10, 2020
Mar 2, 2020

Repository files navigation

getRandomValues for React Native

A small implementation of getRandomValues for React Native.

Installation

npm install --save react-native-get-random-values
cd ios && pod install && cd ..

Usage

This library works as a polyfill for the global crypto.getRandomValues.

// Add this line to your `index.js`
import 'react-native-get-random-values'

API

crypto.getRandomValues(typedArray)

The crypto.getRandomValues() method lets you get cryptographically strong random values. The array given as the parameter is filled with random numbers (random in its cryptographic meaning).

To guarantee enough performance, implementations are not using a truly random number generator, but they are using a pseudo-random number generator seeded with a value with enough entropy. The PRNG used differs from one implementation to the other but is suitable for cryptographic usages. Implementations are also required to use a seed with enough entropy, like a system-level entropy source.

  • typedArray - Is an integer-based TypedArray, that is an Int8Array, a Uint8Array, an Int16Array, a Uint16Array, an Int32Array, or a Uint32Array. All elements in the array are going to be overridden with random numbers.

Returns the typed array that was passed in.