-
Notifications
You must be signed in to change notification settings - Fork 54
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
feat: ensure valid random PrivateKey if no secret is given #392
base: main
Are you sure you want to change the base?
feat: ensure valid random PrivateKey if no secret is given #392
Conversation
PR Summary
|
633b449
to
f7d3d82
Compare
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.
This is a great start @charlie632, thank you for the contribution! These changes just update the backing implementation, we still need to update the public API in Asymmetric.swift
.
Additionally, we should incorporate a unit test (similar to the one discussed in the issue thread) with a high iteration rate. Maybe 100K?
Lastly, we'd want to update the examples in the README to reflect the API change.
@@ -151,16 +151,14 @@ extension secp256k1 { | |||
|
|||
/// Backing initialization that creates a random secp256k1 private key for signing | |||
@usableFromInline init(format: secp256k1.Format = .compressed) throws { |
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.
We will want to update the function signature so a try catch statement isn't needed.
@usableFromInline init(format: secp256k1.Format = .compressed) throws { | |
@usableFromInline init(format: secp256k1.Format = .compressed) { |
Hey @charlie632, just checking in, would you like any help with this PR? |
@csjones hey! Sorry, I've been extremely busy with a big deliverable for my company. I have some free time next week, so I can happily finish this PR! |
fixes: #390
This will loop for an arbitrary time (10 times) until the random private key is valid.
The PrivateKeyImplementation can throw an error if an invalid secret is provided, which can happen if it returns a value bigger than
0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141
(see https://crypto.stackexchange.com/questions/30269/are-all-possible-ec-private-keys-valid/30272#30272).This looping mechanism follows a technique used by Apple