Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expo 48 getRandomValues undefined #51

Open
Willie-Pretorius opened this issue Oct 30, 2023 · 0 comments
Open

Expo 48 getRandomValues undefined #51

Willie-Pretorius opened this issue Oct 30, 2023 · 0 comments

Comments

@Willie-Pretorius
Copy link

Willie-Pretorius commented Oct 30, 2023

Please Help
I am upgrading an expo application to expo-48.
"react-native": "0.71.14",
"react-native-get-random-values": "~1.9.0",
"expo-crypto": "12.2.1",
"expo": "48.0.21"

I have added some console logs to try and find out whats happening and it appears that I am getting ExpoCrypto but getRandomValues is undefined.

function getRandomValues (array) {
  if (!(array instanceof Int8Array || array instanceof Uint8Array || array instanceof Int16Array || array instanceof Uint16Array || array instanceof Int32Array || array instanceof Uint32Array || array instanceof Uint8ClampedArray)) {
    throw new TypeMismatchError('Expected an integer array')
  }

  if (array.byteLength > 65536) {
    throw new QuotaExceededError('Can only request a maximum of 65536 bytes')
  }

  // Expo SDK 48+
  if (global.expo){
    console.log("global.expo")
  }
  if (global.expo.modules){
    console.log("global.expo.modules ")
  }
  if (global.expo.modules.ExpoCrypto){
    console.log("global.expo.modules.ExpoCrypto")
  }
  if (global.expo.modules.ExpoCrypto.getRandomValues){
    console.log("global.expo.modules.ExpoCrypto.getRandomValues")
  } else console.log("global.expo.modules.ExpoCrypto.getRandomValues is " + typeof global.expo.modules.ExpoCrypto.getRandomValues)
  
   // Expo SDK 48+
   if (global.expo && global.expo.modules && global.expo.modules.ExpoCrypto && global.expo.modules.ExpoCrypto.getRandomValues) {
    // ExpoCrypto.getRandomValues doesn't return the array
    global.expo.modules.ExpoCrypto.getRandomValues(array)
    return array
  }


  // Calling getRandomBase64 in debug mode leads to the error
  // "Calling synchronous methods on native modules is not supported in Chrome".
  // So in that specific case we fall back to just using Math.random.
  if (__DEV__) {
    if (typeof global.nativeCallSyncHook === 'undefined') {
      return insecureRandomValues(array)
    }
  }

  base64Decode(getRandomBase64(array.byteLength), new Uint8Array(array.buffer, array.byteOffset, array.byteLength))

  return array
}

//Output --------------------------------------------------------------
LOG global.expo
LOG global.expo.modules
LOG global.expo.modules.ExpoCrypto
LOG global.expo.modules.ExpoCrypto.getRandomValues is undefined
LOG global.expo
LOG global.expo.modules
LOG global.expo.modules.ExpoCrypto
LOG global.expo.modules.ExpoCrypto.getRandomValues is undefined

-Update

I am just building to expo-go with metro builder. My linking is being done by "expo-modules-autolinking": "~1.1.0 || ~1.2.0",

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

No branches or pull requests

1 participant