Open benschac opened 8 months ago
link to PR for reference: https://github.com/entropyxyz/entropy-client/pull/129
Going to use this a research / context note for internal teammates / outside contributors / users of entropy.js / brain dump
entropy-js
has a requirement on @polkadot/wasm-crypo-wasm
which has a requirement on a builtin node package crypto
which isn't supported in react-native / web runtimes.
\](https://github.com/entropyxyz/entropy-js/assets/2502947/4bd2ce83-ab8a-46ee-a0fc-a9cd83b177c7%22%3E)
It's particularly tricky / hacky to get crypto
nodejs package to work.
rn-nodeify --install
installs shims for core node modules, see './shims.js' (https://github.com/tradle/rn-nodeify/blob/master/shims.js) for the current mappings. It recurses downnode_modules
and modifies all thepackage.json
's in there to add/update thebrowser
andreact-native
fields. It sounds scary because it is. However, it does work.
rn-nodeify --hack
Now that you're scared, I should also mention that there are some package-specific hacks (see './pkg-hacks.js' (https://github.com/tradle/rn-nodeify/blob/master/pkg-hacks.js)), for when the React Native packager choked on something that Webpack and Browserify swallowed.If you're looking for a saner approach, check out ReactNativify (https://github.com/[philikon](https://github.com/philikon)/ReactNativify). I haven't tested it myself, but I think philikon (https://github.com/philikon) will be happy to help.
node:fs
isn't a thing.hermes
which react native uses under the hood as a runtime https://stackoverflow.com/questions/70440505/ts1343-the-import-meta-meta-property-is-only-allowed-when-the-module-opti@polkadot/wasm-crypto-wasm
and use the browserify-crypto plugin via their web app which looks like it's shared with their native app.entropyjs
I don't think devs would want to jump through all of these hoops to get sdk working on react-native.I posted this above a couple of weeks ago:
https://hackernoon.com/using-core-node-js-modules-in-react-native-apps-64acd4d07140
I'm suggesting something similar for entropy js client.
I assuming entropy-js
is working on web because: https://www.npmjs.com/package/crypto-js
Active development of CryptoJS has been discontinued. This library is no longer maintained.
Nowadays, NodeJS and modern browsers have a native Crypto module. The latest version of CryptoJS already uses the native Crypto module for random number generation, since Math.random() is not crypto-safe. Further development of CryptoJS would result in it only being a wrapper of native Crypto. Therefore, development and maintenance has been discontinued, it is time to go for the native crypto module.
https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API
I have some experience in this neighborhood. You're right it can get ugly.
Leads for later:
crypto
functions called, you can monkey patch (in a stable way!) the method calls.
entropy-js is shipping with deps that expect
crypto
from nodejs standard lib, crashing the application