aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/nodekey/main.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/cmd/nodekey/main.go b/cmd/nodekey/main.go
index 1ba417704..81aef039f 100644
--- a/cmd/nodekey/main.go
+++ b/cmd/nodekey/main.go
@@ -25,6 +25,7 @@ func init() {
app.Commands = []cli.Command{
commandGenerate,
commandInspect,
+ commandPK2Addr,
}
}
@@ -85,6 +86,32 @@ var commandInspect = cli.Command{
},
}
+var commandPK2Addr = cli.Command{
+ Name: "pk2addr",
+ Usage: "public key to address",
+ ArgsUsage: "publickey",
+ Description: `Convert public key to address`,
+ Action: func(ctx *cli.Context) error {
+ pk := ctx.Args().First()
+ if pk[1] == 'x' {
+ pk = pk[2:]
+ }
+ pkhex, err := hex.DecodeString(pk)
+ if err != nil {
+ panic(err)
+ }
+ key, err := crypto.UnmarshalPubkey(pkhex)
+ if err != nil {
+ panic(err)
+ }
+
+ address := crypto.PubkeyToAddress(*key)
+
+ fmt.Printf("Node Address: %s\n", address.String())
+ return nil
+ },
+}
+
func main() {
if err := app.Run(os.Args); err != nil {
fmt.Fprintln(os.Stderr, err)