How to use expo-random - 1 common examples

To help you get started, we’ve selected a few expo-random examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kevlened / isomorphic-webcrypto / src / react-native.js View on Github external
let generateSecureRandom;
if (require.getModules) {
  const NativeModules = require('react-native').NativeModules;
  const RNSecureRandom = NativeModules.RNSecureRandom;
  const NativeUnimoduleProxy = NativeModules.NativeUnimoduleProxy;
  if (RNSecureRandom && RNSecureRandom.generateSecureRandomAsBase64) {
    generateSecureRandom = require('react-native-securerandom').generateSecureRandom;
  } else if (NativeUnimoduleProxy && NativeUnimoduleProxy.exportedMethods.ExpoRandom) {
    generateSecureRandom = require('expo-random').getRandomBytesAsync;
  }
}

if (!generateSecureRandom) {
  console.log(`
    isomorphic-webcrypto cannot ensure the security of some operations!
    Install and configure react-native-securerandom or expo-random
    If managed by Expo, run 'expo install expo-random'
  `);
  generateSecureRandom = function(length) {
    const uint8Array = new Uint8Array(length);
    while (length && length--) {
      uint8Array[length] = Math.floor(Math.random() * 256);
    }
    return Promise.resolve(uint8Array);
  }

expo-random

Expo universal module for random bytes

MIT
Latest version published 6 months ago

Package Health Score

89 / 100
Full package analysis

Popular expo-random functions