Skip to content

๐Ÿ”’ High-performance crypto secure random bytes generator for React Native.

License

Notifications You must be signed in to change notification settings

daload/react-native-csrng

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

10 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

react-native-csrng

High-performance, cross-platform library that provides cryptographically secure random bytes for React Native applications. Uses SecRandomCopyBytes on iOS and SecureRandom on Android.

Table of Contents

Usage

The library exports 3 functions:

getRandomBytes(length: number) => ArrayBuffer

Takes a length, the number of bytes to generate, and returns an ArrayBuffer with that length of random bytes.

import { getRandomBytes } from 'react-native-csrng'

const randomArrayBuffer = getRandomBytes(12)

getRandomInt(min: number, max:number) => number

Takes a min and a max. Returns a random value between those 2 values

import { getRandomInt } from 'react-native-csrng'

const randomNumberBetween1And10 = getRandomInt(1, 10)

generateUUID() => string

Returns a random UUID

import { getRandomInt } from 'react-native-csrng'

const randomUUID = generateUUID()

Installation

// Yarn
yarn add react-native-csrng

// NPM
npm install react-native-csrng

Example

To run the example, where you can see the library in action you have to run:

  1. Install dependencies:

    // Yarn
    yarn example install
    
    //NPM
    npm run example install
    1. Install Pods for iOS (only needed for iOS):
      cd example/ios && pod install && cd ../..
  2. Start Metro Bundler:

    // Yarn
    yarn example start
    
    // NPM
    npm run example start
  3. Install the app:

    1. Android:

      // Yarn
      yarn example android
      
      // NPM
      npm run example android
    2. iOS:

      // Yarn
      yarn example ios
      
      // NPM
      npm run example ios

Contributing

Feel free to dive in! Open an issue or submit PRs.

react-native-csrng follows the Contributor Covenant Code of Conduct.

Contributors

This project exists thanks to all the people who contribute. @Daload

License

MIT ยฉ Daload