-
Notifications
You must be signed in to change notification settings - Fork 95
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
fix: Check Null for RNRandomBytes #53
Conversation
if (RNRandomBytes) { | ||
if (RNRandomBytes.seed) { | ||
let seedBuffer = toBuffer(RNRandomBytes.seed) | ||
addEntropy(seedBuffer) | ||
} else { | ||
seedSJCL() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be more like this?
if (RNRandomBytes) { | |
if (RNRandomBytes.seed) { | |
let seedBuffer = toBuffer(RNRandomBytes.seed) | |
addEntropy(seedBuffer) | |
} else { | |
seedSJCL() | |
} | |
} | |
if (RNRandomBytes && RNRandomBytes.seed) { | |
let seedBuffer = toBuffer(RNRandomBytes.seed) | |
addEntropy(seedBuffer) | |
} else { | |
seedSJCL() | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to make the code look clear, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not about clarity, but about the fact that if RNRandomBytes
evaluates to false
then nothing gets called and in the original code, there's a call to seedSJCL()
on the else
branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am quite sure that seedSJCL()
will continue to have the lssues #40 , so it is necessary to use the way I used it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're probably right.. I haven't spent time through the library code, I just landed on this PR as a fix to my current blocker.
We have solved the problem by patch-package. This is a truly helpful dependency. |
the root question is why I think whichever the lib that depends on this lib, they need to put this lib into their |
lssues: #40
Expo projects that use the
react-native-crypto
library have problems withreact-native-randombytes
.Uncaught Error:
means that the RNrandomBytes value is uninitialized. So make sure this value is initialized properly first.
Check Null for RNRandomBytes:
I used if to check if RandomBytes is initialized. This solves the problem with Expo react-native mentioned in issue #40
Testing:
Have been tested on Android simulator, iOS simulator, and Android devices, iOS devices.
_react-native: 0.64
Expo: 44
react-native-crypto: 2.2