kore-koi / react-native-get-random-values

⚡️ A fast implementation of `crypto.getRandomValues` for React Native

Home Page:https://www.npmjs.com/package/@korekoi/react-native-get-random-values

Repository from Github https://github.comkore-koi/react-native-get-random-valuesRepository from Github https://github.comkore-koi/react-native-get-random-values

@kore-koi/react-native-get-random-values

NPM Version

Features

  • 🫳 Drop-in replacement for crypto.getRandomValues
  • ⚡ Uses JSI for faster operations between Native and JS
  • 🔒 Native C++ secure randomization using libsodium

Installation

npm install @korekoi/react-native-get-random-values

Dependencies

This library needs these dependencies to be installed in your project before you can use it:

npm install react-native-nitro-modules

Usage

import "@korekoi/react-native-get-random-values"

const array = new Uint8Array(32);
global.crypto.getRandomValues(array);

See the example app

How does it compare to other alternatives?

The most downloaded and probably the only available library to polyfill this method (until now) has been LinusU/react-native-get-random-values, but our solution has a couple improvements:

Benchmark

Percentage represents how much faster JSI is compared to B64

iOS iOS Simulator Android
iPhone 13 Benchmark Simulator Benchmark Feel free to open an issue
iPhone 13 on iOS 17 iPhone 16 Pro Simulator, iOS 18, running on an MacBook Air M1 2020 16GB ram
10k loops at 65535 bytes with Base 64 crashed the app

Notes

About

⚡️ A fast implementation of `crypto.getRandomValues` for React Native

https://www.npmjs.com/package/@korekoi/react-native-get-random-values

License:MIT License


Languages

Language:C 98.4%Language:TypeScript 1.0%Language:JavaScript 0.1%Language:Kotlin 0.1%Language:Ruby 0.1%Language:Objective-C 0.1%Language:C++ 0.1%Language:CMake 0.1%Language:Objective-C++ 0.0%Language:Java 0.0%Language:Swift 0.0%