-
Notifications
You must be signed in to change notification settings - Fork 10
/
identityKeys.go
134 lines (120 loc) · 3.08 KB
/
identityKeys.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Copyright 2017 Factom Foundation
// Use of this source code is governed by the MIT
// license that can be found in the LICENSE file.
package main
import (
"flag"
"fmt"
"os"
"github.com/FactomProject/factom"
"github.com/posener/complete"
)
// newIdentityKey generates a new identity key in the wallet
var newIdentityKey = func() *fctCmd {
cmd := new(fctCmd)
cmd.helpMsg = "factom-cli newidentitykey"
cmd.description = "Generate a new identity key in the wallet"
cmd.execFunc = func(args []string) {
os.Args = args
flag.Parse()
args = flag.Args()
k, err := factom.GenerateIdentityKey()
if err != nil {
errorln(err)
return
}
fmt.Println(k.PubString())
}
help.Add("newidentitykey", cmd)
return cmd
}()
// importIdentityKeys imports identity keys from 1 or more secret keys into the wallet
var importIdentityKeys = func() *fctCmd {
cmd := new(fctCmd)
cmd.helpMsg = "factom-cli importidentitykeys SECKEY [SECKEY...]"
cmd.description = "Import one or more identity keys into the wallet from the specified idsec keys"
cmd.execFunc = func(args []string) {
os.Args = args
flag.Parse()
args = flag.Args()
if len(args) < 1 {
fmt.Println(cmd.helpMsg)
return
}
keys, err := factom.ImportIdentityKeys(args...)
if err != nil {
errorln(err)
return
}
for _, k := range keys {
fmt.Println(k)
}
}
help.Add("importidentitykeys", cmd)
return cmd
}()
// exportIdentityKeys lists the identity key pairs (public and private) stored in the wallet
var exportIdentityKeys = func() *fctCmd {
cmd := new(fctCmd)
cmd.helpMsg = "factom-cli exportidentitykeys"
cmd.description = "List the identity key pairs (public and private) stored in the wallet"
cmd.execFunc = func(args []string) {
os.Args = args
flag.Parse()
args = flag.Args()
keys, err := factom.FetchIdentityKeys()
if err != nil {
errorln(err)
return
}
for _, k := range keys {
fmt.Println(k.SecString(), k.PubString())
}
}
help.Add("exportidentitykeys", cmd)
return cmd
}()
// listIdentityKeys lists the addresses in the wallet
var listIdentityKeys = func() *fctCmd {
cmd := new(fctCmd)
cmd.helpMsg = "factom-cli listidentitykeys"
cmd.description = "List the public identity keys stored in the wallet"
cmd.execFunc = func(args []string) {
os.Args = args
flag.Parse()
args = flag.Args()
keys, err := factom.FetchIdentityKeys()
if err != nil {
errorln(err)
return
}
for _, k := range keys {
fmt.Println(k.PubString())
}
}
help.Add("listidentitykeys", cmd)
return cmd
}()
// removeIdentityKey removes an identity key pair from the wallet
var removeIdentityKey = func() *fctCmd {
cmd := new(fctCmd)
cmd.helpMsg = "factom-cli rmidentitykey PUBKEY"
cmd.description = "Removes the identity key pair from the wallet for the specified idpub key."
cmd.completion = complete.Command{
Args: predictIdentityKey,
}
cmd.execFunc = func(args []string) {
if len(args) < 2 {
fmt.Println(cmd.helpMsg)
return
}
pub := args[1]
err := factom.RemoveIdentityKey(pub)
if err != nil {
fmt.Printf("%v\n", err)
return
}
}
help.Add("rmidentitykey", cmd)
return cmd
}()