react-native-get-random-values for the New Architecture
    
When working with cryptographic operations in JavaScript, especially in libraries like @aws-amplify/react-native, access to a secure random number generator is essential. In browsers, the crypto.getRandomValues() method is typically used for this purpose. On React Native, we have been using react-native-get-random-values, but this is no longer compatible with the new architecture.
New Architecture Replacement
A good replacement is react-native-get-random-values, this one requires react-native-nitro-modules.
This library is great but it’s not compatible with React Native 0.76 or newer. Here is a fork to address this:
https://github.com/cristiangu/react-native-get-random-values
Use the old library name
This new library has a different name and libs like AWS Amplify will break if the old name is not present. Take a look here.
You should add it into your package.json like this:
 "react-native-get-random-values": "https://github.com/cristiangu/react-native-get-random-values.git",
How to use it
The polyfill needs to be applied at import time, you can import it in index.js and before importing the AWS Amplify lib.
// index.js
// Enables native support for crypto.getRandomValues()
import 'react-native-get-random-values';
Final thoughts
If you’re upgrading to React Native 0.76+, want to use the New Architecture and rely on AWS Amplify or similar libraries, be sure to update your implementation of react-native-get-random-values.
Feel free to write your question in the comments section bellow and let’s connect on LinkedIn.
        
 
                    
                
            
 
                    
                
            
 
                    
                
            
Comments