Skip to content

Commit

Permalink
fix: utf8 encode msg
Browse files Browse the repository at this point in the history
  • Loading branch information
sherpalden committed Dec 10, 2024
1 parent 7e003ae commit dc13601
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"crypto/ecdsa"
"crypto/elliptic"
"encoding/hex"
"errors"
"fmt"
"math/big"
Expand Down Expand Up @@ -158,7 +159,7 @@ func (c ClusterConfig) SignMessage(msg *relayertypes.Message) ([]byte, error) {
if c.privateKey == nil {
return nil, errors.New("private key is nil")
}
encodedData := c.rlpEncodeData(msg)
encodedData := c.uft8EncodeData(msg)
hash := sha3.NewLegacyKeccak256()
hash.Write(encodedData)
msgHash := hash.Sum(nil)
Expand All @@ -177,6 +178,17 @@ func (ClusterConfig) rlpEncodeData(msg *relayertypes.Message) []byte {
return encodedData
}

func (ClusterConfig) uft8EncodeData(msg *relayertypes.Message) []byte {
encodedBytes := []byte(msg.Src)
encodedBytes = append(encodedBytes, []byte(msg.Sn.String())...)

dataHexStr := hex.EncodeToString(msg.Data)
encodedBytes = append(encodedBytes, []byte(dataHexStr)...)
encodedBytes = append(encodedBytes, msg.Dst...)

return encodedBytes
}

func (c ClusterConfig) VerifySignature(msg, sig []byte) error {
if c.privateKey == nil {
return errors.New("private key is nil")
Expand Down

0 comments on commit dc13601

Please sign in to comment.