Skip to content

Commit

Permalink
Merge pull request #839 from bnb-chain/ar-220215-01
Browse files Browse the repository at this point in the history
Crypto-level random
  • Loading branch information
forcodedancing authored Mar 4, 2022
2 parents 1e38003 + 5665a87 commit 22e53d4
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 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,8 @@ import (

const (
flagPVPath = "pvpath"
errRandF = "failed to generate random int with error: %s"
randMax = 2147483647
)

func AddCommands(cmd *cobra.Command, cdc *wire.Codec) {
Expand Down Expand Up @@ -50,8 +52,11 @@ 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())
nonceB, err := rand.Int(rand.Reader, big.NewInt(randMax))
if err != nil {
return fmt.Errorf(errRandF, err.Error())
}
nonce := nonceB.Bytes()
sig, err := privKey.Sign([]byte(nonce))
if err != nil {
return err
Expand Down Expand Up @@ -85,8 +90,11 @@ func getModeCmd(cdc *wire.Codec) *cobra.Command {
}

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

0 comments on commit 22e53d4

Please sign in to comment.