Open TimoGlastra opened 2 years ago
the bbs-signatures library from mattrglobal uses it for the randomness of the seed.
@stablelib/random
detects platform and sets randomnesssource here: https://github.com/StableLib/stablelib/blob/d8b909d49245c040e5e4a59ff8c9b269fc1781ee/packages/random/source/system.ts#L8
I am not sure how react-native-get-random-values
polyfills, but if its injected here we could make it work. Otherwise opening a PR adding React Native support would be trivial with react-native-get-random-values
.
react-native-get-random-values polyfill the browser crypto object, so it should just work. The only thing where it could fail is if stablelib/random fails to detect the RN envrionment as a browser environment. I'll quickly test it/
It doesn't work :(
Error: System random byte generator is not available., js engine: hermes
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:95:4 in reportException
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:141:19 in handleException
at node_modules/react-native/Libraries/Core/setUpErrorHandling.js:24:6 in handleError
at node_modules/@react-native/polyfills/error-guard.js:49:36 in ErrorUtils.reportFatalError
at node_modules/metro-runtime/src/polyfills/require.js:203:6 in guardedLoadModule
at node_modules/metro-runtime/src/polyfills/require.js:127:23 in metroRequire
at http://10.254.0.138:8081/index.bundle?platform=ios&dev=true&hot=false&strict=false&minify=false:312426:3 in global
Okay thats sad. I am not sure if @stablelib
is big on RN support but we could add it.
Yeah we don't even need to add a dependency, just extend the browser check to also work in the case of RN
I think the issue is that is checks for self.crypto
, and we need to check for just the crypto
global
I think the issue is that is checks for
self.crypto
, and we need to check for just thecrypto
global
Yeah that seems very likely. Could you test that in your test app? just patch the node module.
It does work 🎉, I just imported the react-native-get-random-values library at the wrong place so @stablelib/random got imported before. Adding it as the first thing in index.js fixed it and it seems to work out of the box.
So we can just make a PR and start using that as the seed generator
We could use
@stablelib/random
for this right? https://github.com/StableLib/stablelib/blob/d8b909d49245c040e5e4a59ff8c9b269fc1781ee/packages/random/random.ts#L52_Originally posted by @blu3beri in https://github.com/hyperledger/aries-framework-javascript/pull/953#discussion_r925283552_
We need to check whether @stablelib/random works in react native through react-native-get-random-values