This guide will walk you through setting up Veramo on React Native. You should have a good understanding of React Native and have your environment set up correctly to build iOS and Android apps. Check out the React Native docs to learn more.
Let's setup Veramo to run locally on the device and use sqlite to store data, identities, and keys. Our identity provider will be ethr-did. Initially, we will set up the agent in the most basic config and add more plugins for additional functionality as we go. Right now we just want to create an identifer.
Install a TextEncoder polyfill and this will also trigger the postinstall script to install additional dependencies based on the rn-nodeify command to your app.
// If using the crypto shim, uncomment the following line to ensure
// crypto is loaded first, so it can populate global.crypto
require('crypto')
Install all of the pods in your project that came with the new dependencies.
npx pod-install
Close the react native packager, clean the project, and rerun your app. If everything is okay, you should see the default React Native screen as before.
We bootstrap Veramo by creating a setup file and initializing the agent. Create a setup file in src/veramo/setup.ts and import the following dependencies:
Now that the agent has been created and configured with plugins, we can create some identifiers. For this, we will need some basic UI.
note
Veramo does not impose decisions on how you manage state in your app and will work alongside any existing architecture like Redux or Mobx etc. For brevity, we use useState in this example, but you can treat Veramo like you would any async data source.
Open App.tsx and delete all the contents and add the following code:
So now we can create identifiers, store them in a database, and query for them. Next, we will use an identifier to create some Verifiable Credentials, save them to the database, and query for them too.