Skip to main content

React Native Module

The @credo-ts/react-native package provides React Native-specific dependencies and utilities for running Credo agents in React Native applications.

Installation

npm install @credo-ts/react-native react-native-fs react-native-get-random-values
Requires React Native version 0.71.4 or higher.

Peer Dependencies

The following peer dependencies are required:
  • react-native (version 0.71.4 or higher)
  • react-native-fs (version 2.20.0)
  • react-native-get-random-values (version 1.11.0 to 2.x)
Optional:
  • @animo-id/expo-secure-environment (^0.1.1) - For Expo secure storage
  • expo-crypto (^15.0.7) - For Expo crypto operations

Setup

Import the polyfill at the top of your entry file:
import 'react-native-get-random-values'
import { Agent } from '@credo-ts/core'
import { agentDependencies } from '@credo-ts/react-native'
import { AskarModule } from '@credo-ts/askar'
import { ariesAskar } from '@hyperledger/askar-react-native'

const agent = new Agent({
  config: {
    label: 'My React Native Agent',
    walletConfig: {
      id: 'wallet-id',
      key: 'wallet-key',
    },
  },
  dependencies: agentDependencies,
  modules: {
    askar: new AskarModule({ ariesAskar }),
  },
})

await agent.initialize()

What It Provides

The React Native module exports:
  • agentDependencies - Platform-specific dependencies for React Native
  • ReactNativeFileSystem - File system implementation using react-native-fs

Platform Considerations

Storage

React Native requires the @hyperledger/askar-react-native package instead of the Node.js version:
import { ariesAskar } from '@hyperledger/askar-react-native'

Networking

For DIDComm connections, configure appropriate transports for mobile environments:
import { DidCommHttpOutboundTransport } from '@credo-ts/core'

// Only outbound transport needed for mobile wallets
agent.registerOutboundTransport(new DidCommHttpOutboundTransport())

Secure Storage

For production apps, consider using secure storage:
import { ExpoSecureEnvironmentModule } from '@animo-id/expo-secure-environment'

const agent = new Agent({
  // ... other config
  modules: {
    secureEnvironment: new ExpoSecureEnvironmentModule(),
    // ... other modules
  },
})

See Also

Build docs developers (and LLMs) love