- 🫳 Drop-in replacement for
crypto.getRandomValues
- ⚡ Uses JSI for faster operations between Native and JS
- 🔒 Native C++ secure randomization using libsodium
npm install @korekoi/react-native-get-random-values
This library needs these dependencies to be installed in your project before you can use it:
npm install react-native-nitro-modules
import "@korekoi/react-native-get-random-values"
const array = new Uint8Array(32);
global.crypto.getRandomValues(array);
See the example app
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:
- JSI, Native and JavaScript communicate through a memory reference and not by serializing data in Base64 back-and-forth, which results in faster operations
- Randomization is made using libsodium for both iOS and Android
- instead of Java SecureRandom for Android and Objective-C SecRandomCopyBytes or Swift SecRandomCopyBytes for iOS
Percentage represents how much faster JSI is compared to B64