1

Migrating the pure Nativescript 5.x project to Nativescript 6 Using nativescript-nodeify (0.8.0) , sjcl (1.0.8) and uuid (3.3.3)
When executed on ios or android, sjcl.random.randomWords(PBKDF2_SALT_SIZE) is throwing the error - JS ERROR NOT READY: generator isn't seeded

tried different ways to configure crypto in webpack. Still not able to solve this error! Any help in this regards will be much appreciated!!!

  • Does it happen upon launch, as soon you hit the `randomWords` method the very first time? – Manoj Dec 04 '19 at 15:37
  • yes. It happens as soon as first time randomWords is hit after launch. – Aravinda Tanneerbavi Dec 05 '19 at 05:31
  • Can you confirm the sjcl version in your package-lock file. – Manoj Dec 05 '19 at 08:57
  • "sjcl": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/sjcl/-/sjcl-1.0.8.tgz", "integrity": "sha512-LzIjEQ0S0DpIgnxMEayM1rq9aGwGRG4OnZhCdjx7glTaJtf4zRfpg87ImfjSJjoW9vKpagd82McDOwbRT5kQKQ==" }, – Aravinda Tanneerbavi Dec 05 '19 at 10:17
  • If you look at the Github repository, they have highlighted it could fail on platforms where there is no support for random numbers. I'm not entirely sure what they mean but it sounds like your issue. If you are not very particular about the package, why don't you try [Crypto JS](https://github.com/brix/crypto-js) which should serve the purpose. – Manoj Dec 05 '19 at 15:00
  • thanks for the input Manoj. The issue with Crypto-js is - if I encrypt using Crypto-js in nativescript app and want to decrypt in java app in back end, it needs sam Crypto-js library to be called in java app, which is very slow. In sjcl you have the library for java and javascript which does the same job in both java script app and java app. Any alternatives? – Aravinda Tanneerbavi Dec 09 '19 at 05:23

1 Answers1

2
Solution : https://stackoverflow.com/questions/53172766/how-to-use-ripple-lib-with-nativescript/53925032#53925032
1. Add NativeScript plugin to the project:
tns plugin add nativescript-randombytes
2. Create a file that will be a partial implementation of crypto module:
// Example path: project/app/shims/crypto.js
module.exports.randomBytes = require('nativescript-randombytes')
3. Add it to webpack.config.js in plugins configuration:
plugins: [
  ..., // other plugins
  new webpack.ProvidePlugin({
        crypto: resolve(__dirname, 'app/shims/crypto.js')
    })
]
4. Add resolve.alias for our version of crypto in webpack.config.js, so child dependencies require our crypto implementation:

alias: {
  ..., // Other aliases
  'crypto': resolve(__dirname, 'app/shims/crypto.js')
}
5. rm -rf platforms/android # or ios
   rm -rf hooks
   rm -rf node_modules
6. tns platform remove ios/android
7. tns platform add ios/android
8. tns build ios/android --bundle
9. tns run ios/android --bundle