Skip to content
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(gnokey): update gnokey verify and tests #2333

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tm2/pkg/crypto/keys/client/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"context"
"encoding/hex"
"flag"
"fmt"
"os"
Expand Down Expand Up @@ -200,6 +201,8 @@ func signTx(
keyOpts.decryptPass,
signBytes,
)
// Currently expose this field for verify process
fmt.Printf("**NOTICE**\nRemember this following phrase for verifying: %v\n", hex.EncodeToString(sig))
if err != nil {
return fmt.Errorf("unable to sign transaction bytes, %w", err)
}
Expand Down
42 changes: 40 additions & 2 deletions tm2/pkg/crypto/keys/client/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@
"flag"
"os"

"github.com/gnolang/gno/tm2/pkg/amino"
"github.com/gnolang/gno/tm2/pkg/commands"
"github.com/gnolang/gno/tm2/pkg/crypto/keys"
"github.com/gnolang/gno/tm2/pkg/std"
)

type VerifyCfg struct {
RootCfg *BaseCfg

DocPath string
DocPath string
ChainID string
AccountNumber uint64
Sequence uint64
}

func NewVerifyCmd(rootCfg *BaseCfg, io commands.IO) *commands.Command {
Expand Down Expand Up @@ -41,6 +46,28 @@
"",
"path of document file to verify",
)

// info to reconstruct the message
fs.StringVar(
&c.ChainID,
"chainid",
"dev",
"the ID of the chain",
)

fs.Uint64Var(
&c.AccountNumber,
"account-number",
0,
"account number to verify with",
)

fs.Uint64Var(
&c.Sequence,
"account-sequence",
0,
"account sequence to verify with",
)
}

func execVerify(cfg *VerifyCfg, args []string, io commands.IO) error {
Expand Down Expand Up @@ -84,8 +111,19 @@
// validate document to sign.
// XXX

// reconstruct the message hash
stdTx := std.Tx{}
err = amino.UnmarshalJSON(msg, &stdTx)
if err != nil {
io.Println("error in validate document")

Check warning on line 118 in tm2/pkg/crypto/keys/client/verify.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/crypto/keys/client/verify.go#L118

Added line #L118 was not covered by tests
}
origMessageHash, err := stdTx.GetSignBytes(cfg.ChainID, cfg.AccountNumber, cfg.Sequence)
if err != nil {
io.Println("error in reconstruct message hash")

Check warning on line 122 in tm2/pkg/crypto/keys/client/verify.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/crypto/keys/client/verify.go#L122

Added line #L122 was not covered by tests
}

// verify signature.
err = kb.Verify(name, msg, sig)
err = kb.Verify(name, origMessageHash, sig)
if err == nil {
io.Println("Valid signature!")
}
Expand Down
Loading
Loading