Skip to content

Commit

Permalink
Merge branch 'main' into specify-block-height-exit
Browse files Browse the repository at this point in the history
  • Loading branch information
geoff-vball authored Jan 17, 2024
2 parents bceed45 + 212d235 commit f9b5001
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
23 changes: 6 additions & 17 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ package config
import (
"crypto/ecdsa"
"encoding/hex"
"errors"
"fmt"
"math/big"
"net/url"
"os"

Expand All @@ -28,10 +26,6 @@ const (
cChainIdentifierString = "C"
)

var (
ErrInvalidPrivateKey = errors.New("failed to set private key string")
)

type MessageProtocolConfig struct {
MessageFormat string `mapstructure:"message-format" json:"message-format"`
Settings map[string]interface{} `mapstructure:"settings" json:"settings"`
Expand Down Expand Up @@ -399,17 +393,12 @@ func (s *SourceSubnet) GetNodeWSEndpoint() string {

// Get the private key and derive the wallet address from a relayer's configured private key for a given destination subnet.
func (s *DestinationSubnet) GetRelayerAccountInfo() (*ecdsa.PrivateKey, common.Address, error) {
var ok bool
pk := new(ecdsa.PrivateKey)
pk.D, ok = new(big.Int).SetString(s.AccountPrivateKey, 16)
if !ok {
return nil, common.Address{}, ErrInvalidPrivateKey
}
pk.PublicKey.Curve = crypto.S256()
pk.PublicKey.X, pk.PublicKey.Y = pk.PublicKey.Curve.ScalarBaseMult(pk.D.Bytes())
pkBytes := pk.PublicKey.X.Bytes()
pkBytes = append(pkBytes, pk.PublicKey.Y.Bytes()...)
return pk, common.BytesToAddress(crypto.Keccak256(pkBytes)), nil
pk, err := crypto.HexToECDSA(s.AccountPrivateKey)
if err != nil {
return nil, common.Address{}, err
}

return pk, crypto.PubkeyToAddress(pk.PublicKey), nil
}

//
Expand Down
5 changes: 3 additions & 2 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package config
import (
"crypto/ecdsa"
"encoding/json"
"errors"
"fmt"
"math/big"
"os"
Expand Down Expand Up @@ -245,7 +246,7 @@ func TestGetRelayerAccountInfo(t *testing.T) {
D: big.NewInt(-5567472993773453273),
},
addr: common.HexToAddress("0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC"),
err: ErrInvalidPrivateKey,
err: errors.New("invalid hex character 'x' in private key"),
},
},
{
Expand All @@ -258,7 +259,7 @@ func TestGetRelayerAccountInfo(t *testing.T) {
D: big.NewInt(-5567472993773453273),
},
addr: common.HexToAddress("0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC"),
err: ErrInvalidPrivateKey,
err: errors.New("invalid hex character 'i' in private key"),
},
},
}
Expand Down

0 comments on commit f9b5001

Please sign in to comment.