I would like to import sodium-plus to use within a .js
file in a Chrome extension. The library’s documentation only shows how to include the extension from an html file with a <script>
tag. When I do that I get an error:
Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'".
I tried to import directly through a .js
file:
import SodiumPlus from "./sodium-plus.min.js";
(async function() {
if (!window.sodium) window.sodium = await SodiumPlus.auto();
// You can now use the sodium object here.
// Just some example code to ensure it's running:
let random = await sodium.randombytes_buf(32);
let hash = await sodium.crypto_generichash('hello world');
console.log({
'random': random.toString('hex'),
'hash': hash.toString('hex')
});
})();
But received an error:
Uncaught SyntaxError: The requested module './sodium-plus.min.js' does not provide an export named 'default'
Is there any way to fix that? Alternatively, is there a similar library that would be easier to import into a .js
file of a Chrome extension?