-
Notifications
You must be signed in to change notification settings - Fork 19
/
walletinfo.go
73 lines (65 loc) · 1.88 KB
/
walletinfo.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
61
62
63
64
65
66
67
68
69
70
71
72
73
package cmd
import (
"fmt"
"os"
"github.com/0chain/gosdk/core/encryption"
"github.com/0chain/gosdk/zboxcore/client"
"github.com/0chain/zboxcli/util"
"github.com/0chain/gosdk/zboxcore/sdk"
"github.com/spf13/cobra"
)
// walletinfo used for getting the wallet info
var walletinfoCmd = &cobra.Command{
Use: "getwallet",
Short: "Get wallet information",
Long: `Get wallet information`,
Args: cobra.MinimumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
doJSON, _ := cmd.Flags().GetBool("json")
header := []string{"Public Key", "ClientID", "Encryption Public Key"}
data := make([][]string, 1)
encPubKey, err := sdk.GetClientEncryptedPublicKey()
if err != nil {
fmt.Println("Error getting the public key for encryption. ", err.Error())
return
}
data[0] = []string{client.GetClientPublicKey(), client.GetClientID(), encPubKey}
if doJSON {
j := make(map[string]string)
j["client_public_key"] = client.GetClientPublicKey()
j["client_id"] = client.GetClientID()
j["encryption_public_key"] = encPubKey
util.PrintJSON(j)
return
}
util.WriteTable(os.Stdout, header, []string{}, data)
return
},
}
var signCmd = &cobra.Command{
Use: "sign-data",
Short: "Sign given data",
Long: `Sign given data`,
Args: cobra.MinimumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
data, _ := cmd.Flags().GetString("data")
if data == "" {
data = client.GetClientID()
} else {
data = encryption.Hash(data)
}
sign, err := client.Sign(data)
if err != nil {
fmt.Println("Error generating the signature. ", err.Error())
return
}
fmt.Println("Signature : " + sign)
return
},
}
func init() {
rootCmd.AddCommand(walletinfoCmd)
walletinfoCmd.Flags().Bool("json", false, "pass this option to print response as json data")
rootCmd.AddCommand(signCmd)
signCmd.Flags().String("data", "", "give data for signing, Default will be clientID")
}