-
Notifications
You must be signed in to change notification settings - Fork 320
/
accountexportpublic.go
60 lines (54 loc) · 1.84 KB
/
accountexportpublic.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright (c) 2019 IoTeX Foundation
// This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability
// or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed.
// This source code is governed by Apache License 2.0 that can be found in the LICENSE file.
package account
import (
"github.com/spf13/cobra"
"github.com/iotexproject/iotex-core/ioctl/config"
"github.com/iotexproject/iotex-core/ioctl/output"
"github.com/iotexproject/iotex-core/ioctl/util"
)
// Multi-language support
var (
_exportPublicCmdShorts = map[config.Language]string{
config.English: "Export IoTeX public key from wallet",
config.Chinese: "从钱包导出IoTeX的公钥",
}
_exportPublicCmdUses = map[config.Language]string{
config.English: "exportpublic (ALIAS|ADDRESS)",
config.Chinese: "exportpublic (别名|地址)",
}
)
// _accountExportPublicCmd represents the account export public key command
var _accountExportPublicCmd = &cobra.Command{
Use: config.TranslateInLang(_exportPublicCmdUses, config.UILanguage),
Short: config.TranslateInLang(_exportPublicCmdShorts, config.UILanguage),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true
err := exportPublic(args[0])
return output.PrintError(err)
},
}
func exportPublic(arg string) error {
var (
addr string
err error
)
if util.AliasIsHdwalletKey(arg) {
addr = arg
} else {
addr, err = util.Address(arg)
if err != nil {
return output.NewError(output.AddressError, "failed to get address", err)
}
}
prvKey, err := PrivateKeyFromSigner(addr, "")
if err != nil {
return output.NewError(output.KeystoreError, "failed to get private key from keystore", err)
}
output.PrintResult(prvKey.PublicKey().HexString())
prvKey.Zero()
return nil
}