dchest / tweetnacl-js

Port of TweetNaCl cryptographic library to JavaScript
https://tweetnacl.js.org
The Unlicense
1.75k stars 292 forks source link

Unclear what types arguments expect #209

Closed csuwildcat closed 3 years ago

csuwildcat commented 3 years ago

I have been struggling with errors that report TypeError: unexpected type, use Uint8Array, but I can't figure out which arguments it pertains to and the docs don't seem to provide an indication of which arguments expect which types. I have tried generating Uint8Array values for just about every method I am invoking, but haven't had any luck. The offending line of my code is this:

return nacl.sign.detached.verify(Uint8Array.from(message), Uint8Array.from(signature), publicKey);

In my code, message is a base64Url encoded hash of an image's raw buffer, and signature is a base64Url encoded version of the signature tweetnacl outputs. Any insight would be much appreciated.

dchest commented 3 years ago

All of them must be Uint8Array. Uint8Array.from does not decode base64, you need a decoder/encoder, for example @stablelib/base64 (doc)

csuwildcat commented 3 years ago

Yep, my bad, I just blanked and didn't even remember to decode the values.

Aside: might still be good to reference the type of args for calls in the MD (maybe link the text to a common statement that all are Uint8Array?)

dchest commented 3 years ago

See https://github.com/dchest/tweetnacl-js#usage

csuwildcat commented 3 years ago

If you want, I can submit a PR to link the arg names to that section, but understand if you think that's overkill. Just lmk.

dchest commented 3 years ago

Yeah, I think it would be overkill and wouldn't look nice in plaintext. Thanks anyway!