Skip to content

Commit

Permalink
chore: change from pk to random bytes (#1001)
Browse files Browse the repository at this point in the history
  • Loading branch information
shrimalmadhur authored Dec 14, 2024
1 parent df2a330 commit 2d7a94e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
9 changes: 7 additions & 2 deletions node/churner_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package node

import (
"context"
"crypto/rand"
"crypto/tls"
"errors"
"time"
Expand Down Expand Up @@ -45,8 +46,12 @@ func (c *churnerClient) Churn(ctx context.Context, operatorAddress string, keyPa
return nil, errors.New("quorumIDs cannot be empty")
}
// generate salt
privateKeyBytes := []byte(keyPair.PrivKey.String())
salt := crypto.Keccak256([]byte("churn"), []byte(time.Now().String()), quorumIDs[:], privateKeyBytes)
bytes := make([]byte, 32)
_, err := rand.Read(bytes)
if err != nil {
return nil, err
}
salt := crypto.Keccak256([]byte("churn"), []byte(time.Now().String()), quorumIDs[:], bytes)

churnRequest := &churner.ChurnRequest{
OperatorAddress: gethcommon.HexToAddress(operatorAddress),
Expand Down
10 changes: 7 additions & 3 deletions node/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package node
import (
"context"
"crypto/ecdsa"
"crypto/rand"
"errors"
"fmt"
"math/big"
Expand Down Expand Up @@ -70,10 +71,13 @@ func RegisterOperator(ctx context.Context, operator *Operator, transactor core.W
logger.Info("Should call churner", "shouldCallChurner", shouldCallChurner)

// Generate salt and expiry

privateKeyBytes := []byte(operator.KeyPair.PrivKey.String())
bytes := make([]byte, 32)
_, err = rand.Read(bytes)
if err != nil {
return err
}
salt := [32]byte{}
copy(salt[:], crypto.Keccak256([]byte("churn"), []byte(time.Now().String()), quorumsToRegister, privateKeyBytes))
copy(salt[:], crypto.Keccak256([]byte("churn"), []byte(time.Now().String()), quorumsToRegister, bytes))

// Get the current block number
expiry := big.NewInt((time.Now().Add(10 * time.Minute)).Unix())
Expand Down

0 comments on commit 2d7a94e

Please sign in to comment.