diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2019-04-30 14:53:26 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-04-30 14:53:26 +0800 |
commit | 814f1f36c491c01e85aaa92f492ab8f972d6e690 (patch) | |
tree | 64c2b6578d9203aa864455d3cca16c10079f2195 /cmd/nodekey | |
parent | 90ce80a741cdc296d4f3badf665d0fe7bacb0ecb (diff) | |
download | dexon-814f1f36c491c01e85aaa92f492ab8f972d6e690.tar dexon-814f1f36c491c01e85aaa92f492ab8f972d6e690.tar.gz dexon-814f1f36c491c01e85aaa92f492ab8f972d6e690.tar.bz2 dexon-814f1f36c491c01e85aaa92f492ab8f972d6e690.tar.lz dexon-814f1f36c491c01e85aaa92f492ab8f972d6e690.tar.xz dexon-814f1f36c491c01e85aaa92f492ab8f972d6e690.tar.zst dexon-814f1f36c491c01e85aaa92f492ab8f972d6e690.zip |
cmd: nodekey: add pk2addr (#400)
Diffstat (limited to 'cmd/nodekey')
-rw-r--r-- | cmd/nodekey/main.go | 27 |
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) |