antelle / argon2-browser

Argon2 library compiled for browser runtime
https://antelle.net/argon2-browser
MIT License
383 stars 81 forks source link

TypeError: arr is not iterable #77

Closed malmod closed 2 years ago

malmod commented 2 years ago

I tried to call argon2.hash with:

  const key = await argon2.hash({
    // required
    pass: pass,
    salt: salt,
    // optional
    time: 3, // the number of iterations
    mem: 1024, // used memory, in KiB
    hashLen: 32, // desired hash length
    parallelism: 3, // desired parallelism (it won't be computed in parallel, however)
    type: argon2.ArgonType.Argon2id, // Argon2d, Argon2i, Argon2id
  });

and get the following error:

 TypeError: arr is not iterable
 at allocateArrayStr (node_modules/argon2-browser/lib/argon2.js:128:56)
      at node_modules/argon2-browser/lib/argon2.js:171:25

I'm using esm modules import argon2 from "argon2-browser"; and TypeScript. Is it a packaging configuration error?

The line which seemingly causes the error is:

    function allocateArrayStr(Module, arr) {
        const nullTerminatedArray = new Uint8Array([...arr, 0]);
        return allocateArray(Module, nullTerminatedArray);
    }
antelle commented 2 years ago

Hi! What did you pass as pass and salt?

malmod commented 2 years ago

Thanks a lot @antelle, despite using TS the pass was a null Uint8Array.

The tests are now fine but I still have problems building it but that's a different issue, anyway I'll try to fix it.