Skip to content

Commit 513df9d

Browse files
author
Yutong Pei
authored
make addrgen tool generate only keypair (iotexproject#116)
1 parent 47cbac5 commit 513df9d

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

tools/addrgen/internal/cmd/createconfig.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
"github.com/spf13/cobra"
1414

15-
"github.com/iotexproject/iotex-core/iotxaddress"
15+
"github.com/iotexproject/iotex-core/crypto"
1616
"github.com/iotexproject/iotex-core/logger"
1717
)
1818

@@ -22,17 +22,17 @@ var createConfigCmd = &cobra.Command{
2222
Short: "Creates a yaml config using generated pub/pri key pair.",
2323
Long: `Creates a yaml config using generated pub/pri key pair.`,
2424
Run: func(cmd *cobra.Command, args []string) {
25-
addr, err := iotxaddress.NewAddress(iotxaddress.IsTestnet, iotxaddress.ChainID)
25+
public, private, err := crypto.EC283.NewKeyPair()
2626
if err != nil {
27-
logger.Fatal().Err(err).Msg("failed to create address")
27+
logger.Fatal().Err(err).Msg("failed to create key pair")
2828
}
2929
cfgStr := fmt.Sprintf(
3030
`chain:
3131
producerPrivKey: "%x"
3232
producerPubKey: "%x"
3333
`,
34-
addr.PrivateKey,
35-
addr.PublicKey,
34+
private,
35+
public,
3636
)
3737
if err := ioutil.WriteFile(_outputFile, []byte(cfgStr), 0666); err != nil {
3838
logger.Fatal().Err(err).Msgf("failed to write file")

tools/addrgen/internal/cmd/generate.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
"github.com/spf13/cobra"
1414

15-
"github.com/iotexproject/iotex-core/iotxaddress"
15+
"github.com/iotexproject/iotex-core/crypto"
1616
"github.com/iotexproject/iotex-core/logger"
1717
)
1818

@@ -31,15 +31,14 @@ var _addrNum int
3131
func generate(args []string) string {
3232
items := make([]string, _addrNum)
3333
for i := 0; i < _addrNum; i++ {
34-
addr, err := iotxaddress.NewAddress(iotxaddress.IsTestnet, iotxaddress.ChainID)
34+
public, private, err := crypto.EC283.NewKeyPair()
3535
if err != nil {
36-
logger.Fatal().Err(err).Msg("failed to create address")
36+
logger.Fatal().Err(err).Msg("failed to create key pair")
3737
}
3838
items[i] = fmt.Sprintf(
39-
"{\"PublicKey\": \"%x\", \"PrivateKey\": \"%x\", \"RawAddress\": \"%s\"}",
40-
addr.PublicKey,
41-
addr.PrivateKey,
42-
addr.RawAddress,
39+
"{\"PublicKey\": \"%x\", \"PrivateKey\": \"%x\"}",
40+
private,
41+
public,
4342
)
4443
}
4544
return "[" + strings.Join(items, ",") + "]"

0 commit comments

Comments
 (0)