-
Notifications
You must be signed in to change notification settings - Fork 295
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
fix generate now can't throw exception #160
base: master
Are you sure you want to change the base?
fix generate now can't throw exception #160
Conversation
Hi there, thanks for the PR! 🙂 Could you please give some more context and explain what you are doing here? |
randomBytes(32) is used in current implementation of .generate() for generating new wallet. But this is not 100% correct way to properly generate ECDSA point for private key. My fix allows code to be formally correct and never throw exception (even with astronomically low probability) |
src/index.ts
Outdated
} | ||
} catch (ignoreError) { | ||
// Do not crash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation.
Can we update here that only this specific error is ignored and all other errors rethrown? Otherwise all other errors will get hidden with this implementation.
Also: can you add a test case which would fail before the change and pass afterwards?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made better implementation, but it's almost impossible to mock randomBytes. Because randombytes module uses
module.exports = require('crypto').randomBytes
this implementation. So mocking crypto.randomBytes will have no effect, mocking result of require is impossible (or I don't know how to do that), and mocking whole require is kinda overkill
Based on: fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141
Probability of throw was ~1/2**499
But after fix it should never throw