Trying to use libsodium with web worker error TypeError: sodium.crypto_pwhash is not a function
Trying to use libsodium with web worker error TypeError: sodium.crypto_pwhash is not a function
我使用 importScripts 导入了 sodium.js,但是当 web worker 运行时它给出错误 TypeError: sodium.crypto_pwhash is not a function。 Console.log sodium.js in worker 但是打印钠对象。我错过了什么?
如 this issue, you need to load the browser-sumo version 中所述,因此它包括 crypto_pwhash
。
const worker_script = `
self.sodium = {
onload: function (sodium) {
postMessage( sodium.crypto_pwhash.toString() );
}
};
importScripts('https://cdn.jsdelivr.net/gh/jedisct1/libsodium.js@master/dist/browsers-sumo/sodium.js');
`;
const worker = new Worker( URL.createObjectURL( new Blob( [ worker_script ], { type: "text/javascript" } ) ) );
worker.onmessage = ({data}) => console.log( data );
我使用 importScripts 导入了 sodium.js,但是当 web worker 运行时它给出错误 TypeError: sodium.crypto_pwhash is not a function。 Console.log sodium.js in worker 但是打印钠对象。我错过了什么?
如 this issue, you need to load the browser-sumo version 中所述,因此它包括 crypto_pwhash
。
const worker_script = `
self.sodium = {
onload: function (sodium) {
postMessage( sodium.crypto_pwhash.toString() );
}
};
importScripts('https://cdn.jsdelivr.net/gh/jedisct1/libsodium.js@master/dist/browsers-sumo/sodium.js');
`;
const worker = new Worker( URL.createObjectURL( new Blob( [ worker_script ], { type: "text/javascript" } ) ) );
worker.onmessage = ({data}) => console.log( data );