-
Notifications
You must be signed in to change notification settings - Fork 23
/
walletinfo.go
97 lines (85 loc) · 2.54 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package cmd
import (
"fmt"
"os"
"github.com/0chain/gosdk/core/encryption"
"github.com/0chain/gosdk/zboxcore/client"
"github.com/0chain/gosdk/zcncore"
"github.com/0chain/zboxcli/util"
"github.com/0chain/gosdk/zboxcore/sdk"
"github.com/spf13/cobra"
)
var walletDecryptCmd = &cobra.Command{
Use: "decrypt",
Short: "Decrypt text with passphrase",
Long: `Decrypt text with passphrase`,
Args: cobra.MinimumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
passphrase, _ := cmd.Flags().GetString("passphrase")
text, _ := cmd.Flags().GetString("text")
decrypted, err := zcncore.Decrypt(passphrase, text)
if err != nil {
fmt.Println(err)
}
fmt.Println(decrypted)
return
},
}
// 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")
rootCmd.AddCommand(walletDecryptCmd)
walletDecryptCmd.Flags().String("passphrase", "", "Passphrase to decrypt text")
walletDecryptCmd.Flags().String("text", "", "Encrypted text")
}