XMTP React Native Example
This is a work in progress to demonstrate importing xmtp-js into a React Native app. The example currently generates a random account and sends a message to a given address. Please reference blockers for production for ongoing work and getting started to run the app.
Warning
This code should only be used experimentally as we work to remove our dependency on PeculiarVentures/webcrypto (a SubtleCrypto polyfill) as the library includes the following warning.
At this time this solution should be considered suitable for research and experimentation, further code and security review is needed before utilization in a production application.
Getting started
- Follow the React Native guide to set up CLI environment
- Clone this repo and
cd example_chat_rn
- Edit the blockchain account address in App.tsx's
sendGm()
to point to the recipient's address - Run
npx react-native start
to start Metro - Run
npx react-native run-ios
ornpx react-native run-android
to run the app - Press the
Send a gm
button once the app is running - A message will arrive in the account provided in Step 3
Blockers for production
- Remove the
SubtleCrypto
dependency fromxmtp-js
or add a Node crypto workaround as proposed in a proof of concept PR. This will allow us to remove the PeculiarVentures/webcrypto polyfill noted in the above warning. - Add authentication to the app instead of generating a random private key for a sender account in
App.tsx
. - Nice to have: Remove unnecessary local storage dependency from
xmtp-js
to remove the polyfill inApp.tsx
.
Requirements
- The JavaScript engine used in the React Native app must include
BigInt
support as it is required byxmtp-js
use of paulmillr/noble-secp256k1.BigInt
is included in the following JS environments:- Hermes v0.70 for both iOS and Android (used in this example)
- JavaScriptCore for iOS starting with iOS 14
- V8 for Android
Polyfills
- @azure/core-asynciterator-polyfill (necessary for Hermes only)
- @ethersproject/shims
- crypto-browserify
- stream-browserify
- events
- process
- react-native-get-random-values
- text-encoding
- web-streams-polyfill
- @peculiar/webcrypto (necessary for
SubtleCrypto
but need to remove) - @react-native-async-storage/async-storage (necessary for
global.localStorage
)