-
Notifications
You must be signed in to change notification settings - Fork 31
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
Falling back to Math.random()
even if polyfill is used
#35
Comments
The problem is in a js file, any imported lib will execute before any code written in this file, the polyfill work should be imported from another lib or file before importing CryptoES, not written by code in the file: https://stackoverflow.com/questions/65656104/how-to-run-several-code-before-import-syntax-in-javascript There is a mature solution in RN: brix/crypto-js#259 (comment) Assigning crypto every time in random function is not a good idea, CryptoJS doesn't do like it either. |
In my actual project i'm importing the polyfill from a file in If you only concern is with the assignment of crypto it can also be moved to the outside scope and only be tried to reassign if it wasn't set yet.
|
How about try this polifill: https://github.com/zloirock/core-js#ecmascript-globalthis |
I've first encountered this when using expo (react-native) where I have to polyfill the
globalThis.crypto
with the following code right at the very beginning of myApp.js
:Even though the polyfill is applied you still end up getting the
Because there is no global crypto property in this context, cryptographically unsafe Math.random() is used
message in the logs. I think the reason for this is that therandomWordArray
function is declared in such a way that it will only evaluated once during the initialization, but I wasn't able to find a order of operations during which the polyfill is already applied before this.It's probably a bit less efficient, but you could get around this issue if you would define
randomWordArray
incore.js
instead in the following way:Is this anything you would consider changing?
The text was updated successfully, but these errors were encountered: