argon2-browser icon indicating copy to clipboard operation
argon2-browser copied to clipboard

`argon2.verify()` documentation in `README.md` is wrong

Open enspritz opened this issue 7 months ago • 1 comments

README.md says:

argon2.verify({
    // <CODE ELIDED>
})
// result
.then(res => {
    res.hash // hash as Uint8Array
    res.hashHex // hash as hex-string
    res.encoded // encoded hash, as required by argon2
})
// or error
.catch(err => {
    err.message // error message as string, if available
    err.code // numeric error code
})

Which is desirable! I need res.hash after a successful verification. But, meanwhile, back in argon2.js:

  let result;
  if (res || err) {
    // <CODE ELIDED>
    result = { message: err, code: res };
  }
  // <CODE ELIDED>
  if (err) {
    throw result;
  } else {
    return result;
  }

.. returning undefined in the case of success. And indeed argon2_library.c indicates we can only receive a status code and not the various hash values:

  ret = argon2_verify_ctx(&ctx, (char *)desired_result, type);

SO, the res data structure containing encoded, hash, hashHex needs to be re-written out of the README.md sample .then() clause , perhaps like this:

argon2.verify({
    // <CODE ELIDED>
})
// success
then(() => console.log("success!"))
// or error
.catch(err => {
    err.message // error message as string, if available
    err.code // numeric error code
})

enspritz avatar Nov 23 '23 00:11 enspritz

See also https://github.com/antelle/argon2-browser/issues/7#issuecomment-443872030

enspritz avatar Nov 23 '23 01:11 enspritz