-
Notifications
You must be signed in to change notification settings - Fork 13
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
add: signature command in iovnscli #263
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package extension | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"github.com/cosmos/cosmos-sdk/client/context" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/crypto/keys" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/pflag" | ||
"github.com/spf13/viper" | ||
"io" | ||
"os" | ||
) | ||
|
||
type SignatureSchema struct { | ||
ChanID string `json:"@chain_id"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please drop the |
||
Type string `json:"@type"` | ||
Message []byte `json:"text"` | ||
Sig string `json:"sig"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please change the tag to |
||
PubKey sdk.AccAddress `json:"address"` | ||
} | ||
|
||
type sigCommand struct { | ||
file string | ||
} | ||
|
||
func (s *sigCommand) applyFlags(flag *pflag.FlagSet) { | ||
flag.StringP("file", "f", "", "") | ||
} | ||
|
||
func (s *sigCommand) extractFlags(flag *pflag.FlagSet) (err error) { | ||
s.file, err = flag.GetString("file") | ||
if err != nil { | ||
return err | ||
} | ||
return | ||
} | ||
|
||
func SignatureCommand() *cobra.Command { | ||
req := new(sigCommand) | ||
cmd := &cobra.Command{ | ||
Use: "sign", | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
// extract flags | ||
err = req.extractFlags(cmd.Flags()) | ||
if err != nil { | ||
return | ||
} | ||
// retrieve file | ||
f, err := os.Open(req.file) | ||
if err != nil { | ||
return | ||
} | ||
defer f.Close() | ||
buf := &bytes.Buffer{} | ||
_, err = io.Copy(buf, f) | ||
if err != nil { | ||
return | ||
} | ||
cliCtx := context.NewCLIContext() | ||
kb, err := keys.NewKeyring(sdk.KeyringServiceName(), viper.GetString(flags.FlagKeyringBackend), viper.GetString(flags.FlagHome), cmd.InOrStdin()) | ||
if err != nil { | ||
return err | ||
} | ||
sig, _, err := kb.Sign(cliCtx.GetFromName(), keys.DefaultBIP39Passphrase, buf.Bytes()) | ||
if err != nil { | ||
return | ||
} | ||
messageJSON, err := json.Marshal(&SignatureSchema{ | ||
ChanID: cliCtx.ChainID, | ||
Type: "message", | ||
Sig: string(sig), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think Sig should be base64 encoded so that it looks familiar to users. |
||
Message: buf.Bytes(), | ||
PubKey: cliCtx.GetFromAddress(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be |
||
}) | ||
if err != nil { | ||
return | ||
} | ||
cmd.Println(fmt.Sprintf("%s", messageJSON)) | ||
return nil | ||
}, | ||
} | ||
req.applyFlags(cmd.Flags()) | ||
return cmd | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,6 @@ | |
|
||
set -o nounset | ||
|
||
echo -n "This script will remove all existing iovns configurations, wallets etc. Do you want to proceed? [Y/n] " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it's nice to destroy existing wallets, etc without warning. If this is blocking some CI or script then just pipe yes into it, eg |
||
read YN | ||
if ! echo $YN | grep -v -q -i "n"; then exit; fi | ||
|
||
rm -rf "$HOME/.iovnscli" | ||
rm -rf "$HOME/.iovnsd" | ||
# init config files | ||
|
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 can be
RUN sh -c 'yes | ./init.sh'
to address my comment on the deletion from init.sh.