Skip to content

Commit

Permalink
perf(admin):change math/rand to crypto/rand
Browse files Browse the repository at this point in the history
  • Loading branch information
qinglin89 committed Mar 2, 2022
1 parent db72b99 commit 35bad47
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions admin/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package admin

import (
"fmt"
"math/rand"
"strconv"
"time"
"math/big"

"crypto/rand"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/context"
Expand All @@ -17,6 +17,7 @@ import (

const (
flagPVPath = "pvpath"
randMax = 2147483647
)

func AddCommands(cmd *cobra.Command, cdc *wire.Codec) {
Expand Down Expand Up @@ -50,8 +51,8 @@ func setModeCmd(cdc *wire.Codec) *cobra.Command {
mode := args[0]
if mode == "0" || mode == "1" || mode == "2" {
cliCtx := context.NewCLIContext().WithCodec(cdc)
rand.Seed(time.Now().UnixNano())
nonce := strconv.Itoa(rand.Int())
nTmp, _ := rand.Int(rand.Reader, big.NewInt(randMax))
nonce := nTmp.Bytes()
sig, err := privKey.Sign([]byte(nonce))
if err != nil {
return err
Expand Down Expand Up @@ -85,8 +86,8 @@ func getModeCmd(cdc *wire.Codec) *cobra.Command {
}

cliCtx := context.NewCLIContext().WithCodec(cdc)
rand.Seed(time.Now().UnixNano())
nonce := strconv.Itoa(rand.Int())
nTmp, _ := rand.Int(rand.Reader, big.NewInt(randMax))
nonce := nTmp.Bytes()
sig, err := privKey.Sign([]byte(nonce))
if err != nil {
return err
Expand Down

0 comments on commit 35bad47

Please sign in to comment.