-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.go
52 lines (48 loc) · 1.18 KB
/
generate.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
package main
import (
"fmt"
"encoding/hex"
"github.com/taiyuechain/taiyuechain/cmd/utils"
"github.com/taiyuechain/taiyuechain/crypto"
"gopkg.in/urfave/cli.v1"
)
var commandGenerate = cli.Command{
Name: "generate",
Usage: "generate new key item",
ArgsUsage: "",
Description: `
Generate a new key item.
`,
Flags: []cli.Flag{
cli.IntFlag{
Name: "sum",
Usage: "key info count",
Value: 1,
},
cli.IntFlag{
Name: "type",
Usage: "crypto type[1,2,3],default:2",
Value: 2,
},
},
Action: func(ctx *cli.Context) error {
ct := ctx.GlobalInt("type")
count := ctx.GlobalInt("sum")
if count <= 0 || count > 100 {
count = 100
}
crypto.SetCrtptoType(uint8(ct))
for i:=0;i<count;i++ {
if priv, err := crypto.GenerateKey(); err != nil {
utils.Fatalf("Error GenerateKey: %v", err)
} else {
fmt.Println("privkey:",hex.EncodeToString(crypto.FromECDSA(priv)))
fmt.Println("pubkey:",hex.EncodeToString(crypto.FromECDSAPub(&priv.PublicKey)))
addr := crypto.PubkeyToAddress(priv.PublicKey)
fmt.Println("address:",crypto.AddressToHex(addr))
fmt.Println("-------------------------------------------------------")
}
}
return nil
},
}