aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2019-04-30 14:53:26 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-09-17 16:57:29 +0800
commit67d565f3f0e398e99bef96827f729e3e4b0edf31 (patch)
treec3a3d4ff2f41659bec1cdc72259e7749f8df5ecb /cmd
parent1d5c2166ba4e733343faf0afd83a3c81fb6f4a40 (diff)
downloadgo-tangerine-67d565f3f0e398e99bef96827f729e3e4b0edf31.tar
go-tangerine-67d565f3f0e398e99bef96827f729e3e4b0edf31.tar.gz
go-tangerine-67d565f3f0e398e99bef96827f729e3e4b0edf31.tar.bz2
go-tangerine-67d565f3f0e398e99bef96827f729e3e4b0edf31.tar.lz
go-tangerine-67d565f3f0e398e99bef96827f729e3e4b0edf31.tar.xz
go-tangerine-67d565f3f0e398e99bef96827f729e3e4b0edf31.tar.zst
go-tangerine-67d565f3f0e398e99bef96827f729e3e4b0edf31.zip
cmd: nodekey: add pk2addr (#400)
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)