Skip to content
This repository has been archived by the owner on Jun 7, 2019. It is now read-only.

Not able to use library inside html5 web worker #7

Closed
karmacoma opened this issue Dec 21, 2016 · 3 comments
Closed

Not able to use library inside html5 web worker #7

karmacoma opened this issue Dec 21, 2016 · 3 comments

Comments

@karmacoma
Copy link
Contributor

karmacoma commented Dec 21, 2016

Lisk JS does not work when required inside of a html5 web worker, affecting any 3rd party integration which rely on them.

@toschdev
Copy link
Contributor

toschdev commented Feb 2, 2017

This is still affected. Error:

No secure random number generator found app.js:25281

Which is related to

try {
  var crypto = require("crypto"),
  randomValueNodeJS = (function() {
    var buf = crypto.randomBytes(4);
      return (buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3]) >>> 0
   });
   randomValueNodeJS();
   Module.getRandomValue = randomValueNodeJS
} catch (e) {
   throw "No secure random number generator found"
}

I am looking into this

@toschdev
Copy link
Contributor

toschdev commented Feb 3, 2017

This is not only a problem for us. The web worker does not have access to the window.crypto

Problem description:
jedisct1/libsodium.js#46
http://stackoverflow.com/questions/13004375/running-window-crypto-getrandomvalues-from-inside-a-web-worker
bitwiseshiftleft/sjcl#91
https://lists.w3.org/Archives/Public/public-webcrypto-comments/2013Jul/0012.html

possible solutions:
https://github.com/snowblindroan/sjcl-webworker-instructive
https://github.com/ekodo/libsodium-worker-test

@toschdev
Copy link
Contributor

The problem is that webworkers do not have access to the dom, where window.crypto is accessible. lisk-js uses the cryptographic functions from the window.crypto.getRandomValues function. There is currently no way to use window.crypto within a webworker or pass it to the webworker. As discussed here:

http://stackoverflow.com/questions/13004375/running-window-crypto-getrandomvalues-from-inside-a-web-worker
https://wpdev.uservoice.com/forums/257854-microsoft-edge-developer/suggestions/13904769-support-web-crypto-api-inside-a-web-worker
https://lists.w3.org/Archives/Public/public-webcrypto-comments/2013Jul/0011.html

The solution I could think of is using the lisk-js functions before the webworker, then pass in the necessary information to the webworker and let it do its job. Note that only cryptographic functions are not available in the webworker, but it makes whole lisk-js fail at this point.
We hope that webworker get an equivalent window.crypto soon (edited)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants