-
Notifications
You must be signed in to change notification settings - Fork 4
/
key.go
34 lines (29 loc) · 838 Bytes
/
key.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
package cmds
import (
"fmt"
"github.com/spikeekips/mitum/base/key"
)
type KeyCommand struct {
New GenerateKeyCommand `cmd:"" help:"new keypair"`
Verify VerifyKeyCommand `cmd:"" help:"verify key"`
Address KeyAddressCommand `cmd:"" help:"generate address from key"`
Sign SignKeyCommand `cmd:"" help:"signature signing"`
}
func NewKeyCommand() KeyCommand {
return KeyCommand{
New: NewGenerateKeyCommand(),
Verify: NewVerifyKeyCommand(),
Address: NewKeyAddressCommand(),
Sign: NewSignKeyCommand(),
}
}
func GenerateKey(seed string) (key.Privatekey, error) {
switch l := len(seed); {
case l < 1:
return key.NewBasePrivatekey(), nil
case l < key.MinSeedSize:
return nil, fmt.Errorf("seed should be over %d < %d", l, key.MinSeedSize)
default:
return key.NewBasePrivatekeyFromSeed(seed)
}
}