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
- Installation
- Example
- Contributing
- License
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.
const randomArrayBuffer = getRandomBytes(12)
getRandomInt(min: number, max:number) => number
Takes a min and a max. Returns a random value between those 2 values
const randomNumberBetween1And10 = getRandomInt(1, 10)
generateUUID() => string
Returns a random UUID
const randomUUID = generateUUID()
Installation
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:
-
Install dependencies:
// Yarn
yarn example install
//NPM
npm run example install- Install Pods for iOS (only needed for iOS):
cd example/ios && pod install && cd ../..
- Install Pods for iOS (only needed for iOS):
-
Start Metro Bundler:
// Yarn
yarn example start
// NPM
npm run example start -
Install the app:
-
Android:
// Yarn
yarn example android
// NPM
npm run example android -
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 (c) Daload