Expo
Last updated
Last updated
This guide demonstrates how to integrate Request Network into a React Native application using Expo. Due to the differences between Node.js and React Native environments, several polyfills and configurations are necessary to make Request Network work properly. Following this guide will set up your Expo project to use Request Network, handle polyfills for missing modules, and ensure smooth integration. A full Github repository with Request Network support can be found here.
After creating a new Expo project, install the necessary dependencies:
1- Create a new file named index.js
in the root of your project
2- Add the following content to index.js
3- Create a file named cryptoPolyfill.js
in the root of your project
4- Add the following content to cryptoPolyfill.js
5- Create / Update metro.config.js
to use the custom polyfills
6- Update package.json
to set the main entry point to index.js
7- Ensure that app.json
file includes the correct entry point
We've created a custom crypto polyfill (cryptoPolyfill.js
) to provide the necessary cryptographic functions. This polyfill uses tweetnacl
and node-forge
libraries to implement various cryptographic operations.
Why tweetnacl
and node-forge
?
tweetnacl
: It's a fast, secure, and easy-to-use cryptography library. It provides a pure JavaScript implementation of the NaCl cryptography library, which is particularly useful for generating random bytes, essential for cryptographic operations.
node-forge
: It provides a comprehensive set of cryptographic tools and utilities. It implements various cryptographic algorithms and protocols that are not natively available in React Native. It's used in our polyfill for operations like hashing, cipher creation, and PBKDF2 key derivation.
Using these libraries allows us to implement a more complete set of cryptographic functions that closely mimic the Node.js crypto module, which is not available in React Native.
Ensure you're using compatible versions of React Native and Expo.
The crypto polyfill may not cover all use cases. Test thoroughly and adjust as needed.
Be cautious when handling private keys. Never expose them in your code or version control.
The example code uses environment variables for private keys. Ensure you set these up correctly and securely.