react-native-get-random-values
react-native-get-random-values copied to clipboard
v1.9.0 throws "unordered_map::at: key not found" error
When executing version v1.9.0
of the library, an exception is thrown at this line: global.expo.modules.ExpoCrypto.getRandomValues(array)
.
Here's the full error log:
ERROR Error: Exception in HostFunction: unordered_map::at: key not found, js engine: hermes
I am utilizing this package alongside randombytes.
The array
variable, which originates from randombytes
, is initialized at this location.
Additional context that might be helpful:
-
I'm running the app on an iOS simulator using the command:
npx expo start -c
. -
Buffer
support was added with:npm install buffer
.And it's being shimmed in the following manner:
import { Buffer } from "buffer"; global.Buffer = Buffer;
For further clarity, I've tracked the function call in version v1.8.0
, and it ultimately leads to global.ExpoModules.ExpoRandom.getRandomBase64String(byteLength);
, which runs without any hitches.
For now, I've reverted to using v1.8.0
. Appreciate the efforts behind this library, and I hope this information aids in resolving the issue.
Thank you for taking the time to investigate and report!
Are you able to reproduce this if you just run the following lines, without this library at all?
const array = new Uint8Array(10)
global.expo.modules.ExpoCrypto.getRandomValues(array)
and do you get the same error if you import getRandomValues
from expo-crypto
and call that directly?
Also, which version of Expo are you using? and does the same error happen even if you remove your global Buffer
polyfill?
Example to reproduce this issue: repo: https://github.com/Mastaleru/rn-learn/tree/625f9d2791442e622f85c4d46cb1e9317c2bbfee/first_project package.json
"dependencies": {
"expo": "~49.0.13",
"expo-status-bar": "~1.6.0",
"react": "18.2.0",
"react-native": "0.72.5",
"react-native-get-random-values": "^1.9.0"
},
"devDependencies": {
"@babel/core": "^7.20.0"
},
More context:
- It works on Android, fails on iOS.
- I'm using in conjunction with a browserified lib that does not have support for
crypto.getRandomValues
Same behaviour, after v1.9.0 it crashes using expo v49 with realm-js (which needs this polyfill to run safely).
This is still occurring on v1.11.0 with expo 51 and realm 12.