Export crypto object
aeirola opened this issue · 2 comments
Hi, thanks for the really handy polyfill! I'm planning on using this library to provide compatibility with crypto-js version 4 which broke support for react-native in favour of guaranteed cryptographically secure random number generators.
Currently the react-native-get-random-values library doesn't export anything, making it a bit tedious to work with for replacing the crypto library in the crypto-js usecase. I'll need to add some boilerplate file crypto-polyfill.js
like
import 'react-native-get-random-values';
module.exports = global.crypto;
which I then point to in metro.config.js
as an alias for crypto
module.exports = {
resolver: {
extraNodeModules: {
crypto: './crypto-polyfill.js,
},
},
};
If react-native-get-random-values would export the partially polyfilled crypto object, we could skip the boilerplate file and directly point to react-native-get-random-values as the crypto module alias.
Hmm, I'm not sure I understand exactly what you want to accomplish. In the browser environments getRandomValues
is only available via a global, and the crypto
package in Node.js doesn't have a getRandomValues
(they have randomBytes
) so I'm not sure exactly how you intend to use the extraNodeModules
config 🤔
I'm not opposed to the idea of exporting something, but would love to get some more info here.
I think that it would make more sense to export only the getRandomValues
function from this module, instead of the crypto
object probably 🤔
Ah, yes. You are completely right. I got my RNG functions mixed up. I was too eager in finding a drop in quick solution for the crypto-js compatibility issues that I failed to overlook the big picture. Sorry about that.
So, as the library name does specify react-native-get-random-values can only be used as a partial polyfill of web Crypto, not node Crypto. Thus, as you pointed out, it would probably just be even more confusing to export as if it was a node crypto polyfill.
For now I don't see any need to add exports to the library. I'll rather just keep some small boilerplate in my application code until crypto-js library provides some better compatibility with react-native runtimes.
Thanks for the help nonetheless.