Skip to content

Documentation: validatePrivateKey does not check typed array length #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
webmaster128 opened this issue Jun 13, 2018 · 3 comments
Closed
Labels
good first issue Good for newcomers

Comments

@webmaster128
Copy link

  • I'm submitting a ...
    [x] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary

Right now, I get positive feedback from validatePrivateKey for the input values

  • e4ade2a5232a7c6f37e7b854a774e25e6047ee7c6d63e8304ae04fa190bc17 (31 bytes)
  • e4ade2a5232a7c6f37e7b854a774e25e6047ee7c6d63e8304ae04fa190bc1732aa (33 bytes)

so it looks like in all the stack of validatePrivateKey, the input length is not checked.

  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)
@bitjson
Copy link
Member

bitjson commented Jun 15, 2018

Hey @webmaster128, thanks for opening an issue!

Thanks, I should improve the documentation on validatePrivateKey to clarify the functionality there. There's a short note here on it – basically, I want to avoid adding any runtime checks which aren't necessary for 100% of consumers.

For most applications, when a potential new key is generated, it should be 32 bytes in length, so also validating the length in validatePrivateKey would be extraneous.

Ideally, TypeScript will eventually support stronger type guarantees about the length of a typed array so our function signature can specifically require a 32-byte Uint8Array (microsoft/TypeScript#18471). This would never be an error at runtime, because the compiler should be able to catch any instance in which the programmer accidentally generated the wrong size key (or failed to validate the length of a user-provided key), and those errors should never make it to runtime.

@bitjson bitjson changed the title Check private key length in validatePrivateKey Documentation: validatePrivateKey does not check typed array length Jun 15, 2018
@bitjson bitjson added the good first issue Good for newcomers label Jun 15, 2018
@webmaster128
Copy link
Author

webmaster128 commented Jun 15, 2018

👍 makes sense, thanks. If I know that, I can easily do the check in my own code.

@bitjson
Copy link
Member

bitjson commented Jun 19, 2018

Merging into #3, which I think probably handles this best.

@bitjson bitjson closed this as completed Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants