Skip to content

Conversation

@rajk93
Copy link
Contributor

@rajk93 rajk93 commented Dec 2, 2025

Problem

In React Native environments, getRandomValues() was incorrectly using the browser implementation instead of native modules (RNGetRandomValues or ExpoRandom), even when these native modules were installed and available.

Ref - polkadot-js/wasm#598

Root Cause

The detection logic in src/react-native.ts checked for the presence of xglobal.crypto first. When libraries like react-native-get-random-values polyfill the global crypto object, this check would pass and use the browser implementation, never checking if native modules were available for React Native.

Solution

Inverted the priority order of checks:

Before:

  1. Check if xglobal.crypto exists -> use browser implementation
  2. Check if in RN environment -> use native modules

After:

  1. Check if native modules exist (RNGetRandomValues or ExpoRandom) -> use native implementation
  2. Fallback to xglobal.crypto if available -> use browser implementation
  3. Throw error if nothing is available

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants