-1

I have an issue, I don't understand how to "install" sodium-plus for using on my website.

I installed :

<script src="https://cdn.jsdelivr.net/npm/sodium-plus@0.9.0/index.min.js"></script>

<script type="text/javascript" src="/require.js"></script>

and I want to test this script :

<script>
(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")
    });
})();
</script>

But I have two errors :

Uncaught ReferenceError: module is not defined Uncaught (in promise)

TypeError: Cannot read properties of undefined (reading 'auto')

DoMiSol
  • 9
  • 4
  • Follow the [_"in the browser"_ instructions](https://github.com/paragonie/sodium-plus/blob/master/docs/getting-started.md#sodium-plus-in-the-browser) - exactly, not just partially. – Andreas Feb 12 '22 at 17:16
  • If you think about the require, if I did this, It doesn't work and I have an issue with require : Uncaught Error: Module name has not been loaded yet for context: _. Use require([]) http://requirejs.org/docs/errors.html#notloaded – DoMiSol Feb 12 '22 at 17:19
  • You are using the wrong file, try: `src="https://cdn.jsdelivr.net/npm/sodium-plus@0.9.0/dist/sodium-plus.min.js"`, s. online on jsfiddle: https://jsfiddle.net/oad1egxw/ – Topaco Feb 12 '22 at 19:07
  • @Topaco oh my god, it works with your link and without require and without `let { SodiumPlus } = "sodium-plus"; require(["sodium-plus"], function(result){ SodiumPlus = result; }); let sodium;` Thank you – DoMiSol Feb 12 '22 at 20:25
  • @DoMiSol We don't do "RESOLVED" or "SOLVED" in the titles here. If you found your own answer, you can post and accept it, or delete the question – j08691 Feb 12 '22 at 21:30
  • @j08691 I understand, but it's ridiculous, I can "accept" my answer in two days ! And I wrote an answer but the bot adds a comment, ridiculous ahahaha – DoMiSol Feb 12 '22 at 21:38

1 Answers1

0

It works with this link :

src="https://cdn.jsdelivr.net/npm/sodium-plus@0.9.0/dist/sodium-plus.min.js"

and I delete the code :

let { SodiumPlus } = "sodium-plus";
require(["sodium-plus"], function(result){
    SodiumPlus = result;
});

But I keep the requirejs script from this website (at the bottom of my scripts because there is sometimes an issue with jQuery) :

https://cdnjs.com/libraries/require.js

And after, to avoid an issue about requirejs script, I do this :

define(function (require) {
    const { SodiumPlus } = require("sodium-plus");
});
let sodium;

Not this :

const { SodiumPlus } = require('sodium-plus');
let sodium;
Topaco
  • 40,594
  • 4
  • 35
  • 62
DoMiSol
  • 9
  • 4
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 12 '22 at 21:09
  • As it is written in the _"in the browser"_ section in the _"Getting started"_ guide... – Andreas Feb 13 '22 at 10:51
  • @Andreas you’re so cute, next time try to help me with good information. It was difficult to find a correct link from a CDN because there is no information in the doc. I code all of my scripts with native JS, maybe it’s easy for you, but I’m not you ! Also, codes from documentation are not good for the require script, you have to write it on a define function for calling sodium-plus. Maybe documentation is not updated. Thanks ! – DoMiSol Feb 13 '22 at 19:51
  • CDN or not is not relevant for this question. You also don't need `require()`. Use it as described in the documentation. – Andreas Feb 13 '22 at 20:33
  • You're wrong ! Yeah because with a bad link, it doesn't work. You need the requirejs (I've just try it without now and it doesn't work), I've just edit my post ;) You're so funny, so don't mess with me please. – DoMiSol Feb 13 '22 at 20:36
  • https://jsfiddle.net/qv9mtrx7/ – Andreas Feb 14 '22 at 07:37
  • yes, but apart from this, it doesn't work – DoMiSol Feb 19 '22 at 01:46