forked from gnolang/gno
-
Notifications
You must be signed in to change notification settings - Fork 0
/
secrets.go
104 lines (88 loc) · 3.18 KB
/
secrets.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
package main
import (
"errors"
"flag"
"path/filepath"
"github.com/gnolang/gno/tm2/pkg/bft/config"
"github.com/gnolang/gno/tm2/pkg/commands"
)
var (
errInvalidDataDir = errors.New("invalid data directory provided")
errInvalidSecretsKey = errors.New("invalid number of secret key arguments")
)
const (
defaultValidatorKeyName = "priv_validator_key.json"
defaultNodeKeyName = "node_key.json"
defaultValidatorStateName = "priv_validator_state.json"
)
const (
nodeIDKey = "node_id"
validatorPrivateKeyKey = "validator_key"
validatorStateKey = "validator_state"
)
// newSecretsCmd creates the secrets root command
func newSecretsCmd(io commands.IO) *commands.Command {
cmd := commands.NewCommand(
commands.Metadata{
Name: "secrets",
ShortUsage: "secrets <subcommand> [flags] [<arg>...]",
ShortHelp: "gno secrets manipulation suite",
LongHelp: "gno secrets manipulation suite, for managing the validator key, p2p key and validator state",
},
commands.NewEmptyConfig(),
commands.HelpExec,
)
cmd.AddSubCommands(
newSecretsInitCmd(io),
newSecretsVerifyCmd(io),
newSecretsGetCmd(io),
)
return cmd
}
// commonAllCfg is the common
// configuration for secrets commands
// that require a bundled secrets dir
type commonAllCfg struct {
dataDir string
}
func (c *commonAllCfg) RegisterFlags(fs *flag.FlagSet) {
fs.StringVar(
&c.dataDir,
"data-dir",
constructSecretsPath(defaultNodeDir),
"the secrets output directory",
)
}
// constructSecretsPath constructs the default secrets path, using
// the given node directory
func constructSecretsPath(nodeDir string) string {
return filepath.Join(
nodeDir,
config.DefaultSecretsDir,
)
}
type (
secrets struct {
ValidatorKeyInfo *validatorKeyInfo `json:"validator_key,omitempty" toml:"validator_key" comment:"the validator private key info"`
ValidatorStateInfo *validatorStateInfo `json:"validator_state,omitempty" toml:"validator_state" comment:"the last signed validator state info"`
NodeIDInfo *nodeIDInfo `json:"node_id,omitempty" toml:"node_id" comment:"the derived node ID info"`
}
// NOTE: keep in sync with tm2/pkg/bft/privval/file.go
validatorKeyInfo struct {
Address string `json:"address" toml:"address" comment:"the validator address"`
PubKey string `json:"pub_key" toml:"pub_key" comment:"the validator public key"`
}
// NOTE: keep in sync with tm2/pkg/bft/privval/file.go
validatorStateInfo struct {
Height int64 `json:"height" toml:"height" comment:"the height of the last sign"`
Round int `json:"round" toml:"round" comment:"the round of the last sign"`
Step int8 `json:"step" toml:"step" comment:"the step of the last sign"`
Signature []byte `json:"signature,omitempty" toml:"signature,omitempty" comment:"the signature of the last sign"`
SignBytes []byte `json:"sign_bytes,omitempty" toml:"sign_bytes,omitempty" comment:"the raw signature bytes of the last sign"`
}
// NOTE: keep in sync with tm2/pkg/p2p/key.go
nodeIDInfo struct {
ID string `json:"id" toml:"id" comment:"the node ID derived from the private key"`
P2PAddress string `json:"p2p_address" toml:"p2p_address" comment:"the node's constructed P2P address'"`
}
)