-
Notifications
You must be signed in to change notification settings - Fork 143
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(grpc): sign and verify message by ed25519 #1667
base: main
Are you sure you want to change the base?
fix(grpc): sign and verify message by ed25519 #1667
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1667 +/- ##
==========================================
+ Coverage 75.07% 76.41% +1.34%
==========================================
Files 234 241 +7
Lines 12156 18479 +6323
==========================================
+ Hits 9126 14121 +4995
- Misses 2582 3898 +1316
- Partials 448 460 +12 |
Thank you so much for this amazing PR. It’s great to see how smart you are in understanding the logic and fixing this issue. Good job! First of all, it’s great to see that you can detect the type of maybeBLSPublicKey := func(str string) bool {
return strings.Contains(strings.ToLower(str), "public1p")
}
maybeEd25519PublicKey := func(str string) bool {
return strings.Contains(strings.ToLower(str), "public1r")
}
switch {
case maybeBLSPublicKey(req.PublicKey):
/// ...
case maybeEd25519PublicKey(req.PublicKey):
/// ...
default:
return nil, status.Error(codes.InvalidArgument, "invalid public key")
} Now, we can make another improvement here. We can define a function like this: func (*utilServer) publicKeyFromString(pubStr string) (crypto.PublicKey, error) {
maybeBLSPublicKey := func(str string) bool {
return strings.Contains(strings.ToLower(str), "secret1p")
}
maybeEd25519PublicKey := func(str string) bool {
return strings.Contains(strings.ToLower(str), "secret1e")
}
switch {
case maybeBLSPublicKey(pubStr):
blsPub, err := bls.PublicKeyFromString(pubStr)
if err != nil {
return nil, status.Error(codes.InvalidArgument, "invalid private key")
}
return blsPub, nil
case maybeEd25519PublicKey(pubStr):
ed25519Pub, err := ed25519.PublicKeyFromString(pubStr)
if err != nil {
return nil, status.Error(codes.InvalidArgument, "invalid private key")
}
return ed25519Pub, nil
default:
return nil, status.Error(codes.InvalidArgument, "invalid private key")
}
} Finally we can make the same for |
@b00f Sure. Thanks for the review. I was not aware that the public key also has the same structure. Tried to find across the code but couldn't. Thanks for the suggestion on the interface as well. I just saw two different structs and missed the interface. I will implement those. |
@b00f Made the changes. Can you please check. |
Fix for the issue : Sign and verify message by ed25519