forked from seeleteam/go-seele
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate_key.go
43 lines (34 loc) · 884 Bytes
/
validate_key.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* @file
* @copyright defined in go-seele/LICENSE
*/
package cmd
import (
"fmt"
"github.com/seeleteam/go-seele/crypto"
"github.com/spf13/cobra"
)
var (
privateKey *string
)
// validatekeyCmd represents the validatekey command
var validatekeyCmd = &cobra.Command{
Use: "validatekey",
Short: "validate the private key and generate its public key",
Long: `For example:
node.exe validatekey`,
Run: func(cmd *cobra.Command, args []string) {
key, err := crypto.LoadECDSAFromString(*privateKey)
if err != nil {
fmt.Printf("failed to load the private key: %s\n", err.Error())
return
}
addr := crypto.GetAddress(&key.PublicKey)
fmt.Printf("public key: %s\n", addr.Hex())
},
}
func init() {
rootCmd.AddCommand(validatekeyCmd)
privateKey = validatekeyCmd.Flags().StringP("key", "k", "", "private key")
validatekeyCmd.MustMarkFlagRequired("key")
}