You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I importScripts("sodium.js") in such a blob created worker, sodium.ready inside the worker never fires.
If the web worker is created "normally" with an external js file, it works correctly.
Complete test case of issue:
<!DOCTYPE html><html><body><script>classThreadableextendsFunction{constructor(f){super("...as",`return (${f.toString()}).apply(this, as)`);}spawn(...as){varcode=`self.onmessage = m => self.postMessage((${this.toString()}).apply(self,m.data));`,blob=newBlob([code],{type: "text/javascript"}),wrkr=newWorker(window.URL.createObjectURL(blob));returnnewPromise((v,x)=>(wrkr.onmessage=m=>(v(m.data),wrkr.terminate()),wrkr.onerror=e=>(x(e.message),wrkr.terminate()),wrkr.postMessage(as)));}};constgenerateSecurityHashChunkWorker=newThreadable((salt,secret)=>{constsodiumOnload=asyncsodium=>{// Never enters hereconsole.log("Sodium ready fired");letsaltSodium=sodium.from_string(salt);saltSodium=awaitsodium.crypto_generichash(16,saltSodium,null);constsecretSodium=sodium.from_string(iterationSecret);consthash=awaitsodium.crypto_pwhash(64,secretSodium,saltSodium,sodium.crypto_pwhash_OPSLIMIT_INTERACTIVE,sodium.crypto_pwhash_MEMLIMIT_INTERACTIVE,sodium.crypto_pwhash_ALG_ARGON2ID13);console.log("sodium result",hash);postMessage(hash);};importScripts('https://fastly.jsdelivr.net/gh/jedisct1/libsodium.js@master/dist/browsers-sumo/sodium.js');sodium.ready.then(async()=>awaitsodiumOnload(sodium));console.log("sodium.ready",sodium.ready);});constgenerateSecurityHashAsync=async(salt,secret)=>{if(!salt){throw"salt cannot be empty";}if(!secret){throw"secret cannot be empty";}conststart=newDate().getTime();constworker=generateSecurityHashChunkWorker.spawn(salt,secret);consthash=awaitworker;console.log("Hash result from awaiting worker",hash);consttimeMilliseconds=newDate().getTime()-start;console.log("Security hash time (ms)",timeMilliseconds,"size",hash?.length);returnhash;};document.addEventListener("DOMContentLoaded",asyncevent=>{constsalt="Test";constpassword="Password";consthash=awaitgenerateSecurityHashAsync(salt,password);console.log(hash);});</script></body></html>
The text was updated successfully, but these errors were encountered:
Hello,
Using the technique described here:
https://stackoverflow.com/a/73621351/111830
If I
importScripts("sodium.js")
in such a blob created worker, sodium.ready inside the worker never fires.If the web worker is created "normally" with an external js file, it works correctly.
Complete test case of issue:
The text was updated successfully, but these errors were encountered: