/
key.go
50 lines (43 loc) · 992 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package create
import (
"github.com/iost-official/go-iost/crypto"
"github.com/iost-official/go-iost/itest"
"github.com/urfave/cli"
)
var keyCommand = cli.Command{
Name: "key",
Usage: "create key pair for test",
Flags: keyFlags,
Action: keyAction,
}
var keyFlags = []cli.Flag{
cli.IntFlag{
Name: "number, n",
Value: 100,
Usage: "number of key pair",
},
cli.StringFlag{
Name: "algorithm, a",
Value: "ed25519",
Usage: "the algorithm for creating key pair, ed25519 or secp256k1",
},
cli.StringFlag{
Name: "output, o",
Value: "keys.json",
Usage: "the output file name for creating key pair",
},
}
var keyAction = func(c *cli.Context) error {
num := c.Int("number")
algo := crypto.NewAlgorithm(c.String("algorithm"))
ofile := c.String("output")
keys := make([]*itest.Key, 0)
for i := 0; i < num; i++ {
key := itest.NewKey(nil, algo)
keys = append(keys, key)
}
if err := itest.DumpKeys(keys, ofile); err != nil {
return err
}
return nil
}