From 61762a92207e929c4a0672b002ffacb27b747ffb Mon Sep 17 00:00:00 2001 From: evanvosberg Date: Wed, 12 Feb 2020 03:42:23 +0100 Subject: [PATCH] Use react-native-crypto to support react native environments. --- package.json | 3 +++ src/core.js | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/package.json b/package.json index b7686de..7ac39a2 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,9 @@ "load-grunt-config": "^0.16.0", "lodash": "^4.17.11" }, + "optionalDependencies": { + "react-native-crypto": "^2.2.0" + }, "keywords": [ "security", "crypto", diff --git a/src/core.js b/src/core.js index 8ba28ed..c4e4451 100644 --- a/src/core.js +++ b/src/core.js @@ -29,6 +29,13 @@ var CryptoJS = CryptoJS || (function (Math, undefined) { } catch (err) {} } + // React native crypto import via require (React Native) + if (!crypto && typeof require === 'function') { + try { + crypto = require('react-native-crypto'); + } catch (err) {} + } + /* * Cryptographically secure pseudorandom number generator *