-
Notifications
You must be signed in to change notification settings - Fork 24
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: add bls verification #239
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8885e18
feat: add bls signature verification
j75689 9380a65
chore: fix testcase
j75689 2d03e3a
choer: fix testcase
j75689 f35a783
chore: fix testcase
j75689 f29ef1c
chore: fix e2e test
j75689 fa67a3f
chore: fix comments
j75689 c32d1f6
chore: revert ethsepc256k1 changes
j75689 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package keys | ||
|
||
import ( | ||
"encoding/hex" | ||
"errors" | ||
|
||
"github.com/cometbft/cometbft/crypto/tmhash" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
) | ||
|
||
// SignMsgKeysCmd returns the Cobra Command for signing messages with the private key of a given name. | ||
func SignMsgKeysCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "sign [message]", | ||
Short: "Sign message", | ||
Long: `Return a signature from their associated name and address private key. | ||
!!!NOTE!!! | ||
This is not a secure way to sign messages. | ||
This command is allowed to sign any message from your private key. | ||
Please *DO NOT* use this command unless you know what you are doing. | ||
|
||
Example For Signing BLS PoP Message: | ||
$ gnfd keys add bls --keyring-backend test --algo eth_bls | ||
$ BLS=$(./build/bin/gnfd keys show bls --keyring-backend test --output json | jq -r .pubkey_hex) | ||
$ gnfd keys sign $BLS --from bls | ||
|
||
`, | ||
RunE: runSignMsgCmd, | ||
} | ||
|
||
cmd.Flags().String(flags.FlagFrom, "", "Name or address of private key with which to sign") | ||
return cmd | ||
} | ||
|
||
func runSignMsgCmd(cmd *cobra.Command, args []string) error { | ||
if len(args) != 1 { | ||
return errors.New("invalid number of arguments") | ||
} | ||
|
||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, name, _, err := client.GetFromFields(clientCtx, clientCtx.Keyring, clientCtx.From) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
msg, err := hex.DecodeString(args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
sig, _, err := clientCtx.Keyring.Sign(name, tmhash.Sum(msg)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cmd.Println(hex.EncodeToString(sig)) | ||
return nil | ||
} | ||
|
||
// VerifySignatureCmd returns the Cobra Command for verifying signatures with a given public key and message. | ||
func VerifySignatureCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "verify [message] [signature]", | ||
Short: "Verify signature", | ||
Long: "Verify signature with public key and message", | ||
RunE: runVerifySignatureCmd, | ||
} | ||
|
||
cmd.Flags().String(flags.FlagFrom, "", "Name or address of private key with which to sign") | ||
return cmd | ||
} | ||
|
||
func runVerifySignatureCmd(cmd *cobra.Command, args []string) error { | ||
if len(args) != 2 { | ||
return errors.New("invalid number of arguments") | ||
} | ||
|
||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, name, _, err := client.GetFromFields(clientCtx, clientCtx.Keyring, clientCtx.From) | ||
if err != nil { | ||
return err | ||
} | ||
record, err := clientCtx.Keyring.Key(name) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
priv, err := record.ExtractPrivKey() | ||
if err != nil { | ||
return nil | ||
} | ||
|
||
msg, err := hex.DecodeString(args[0]) | ||
if err != nil { | ||
return nil | ||
} | ||
signature, err := hex.DecodeString(args[1]) | ||
if err != nil { | ||
return nil | ||
} | ||
if priv.PubKey().VerifySignature(tmhash.Sum(msg), signature) { | ||
cmd.Println("Signature verify successfully") | ||
} else { | ||
cmd.Println("Signature verify failed") | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 dangerous action, please note user to take care.
And give an example, it can be used to do
possesion of proof
..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.
fixed