Skip to content

Commit

Permalink
[Gateway] Use personal_sign signatures everywhere (EIP-191) (#10201)
Browse files Browse the repository at this point in the history
Co-authored-by: Morgan Kuphal <87319522+KuphJr@users.noreply.github.com>
  • Loading branch information
bolekk and KuphJr committed Aug 15, 2023
1 parent 67b1f2d commit af5e478
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions core/services/gateway/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"crypto/ecdsa"
"encoding/binary"

"github.com/ethereum/go-ethereum/crypto"
"golang.org/x/exp/slices"

"github.com/smartcontractkit/chainlink/v2/core/utils"
)

func Uint32ToBytes(val uint32) []byte {
Expand All @@ -30,16 +31,22 @@ func AlignedBytesToString(data []byte) string {
return string(data[:idx])
}

func flatten(data ...[]byte) []byte {
var result []byte
for _, d := range data {
result = append(result, d...)
}
return result
}

func SignData(privateKey *ecdsa.PrivateKey, data ...[]byte) ([]byte, error) {
hash := crypto.Keccak256Hash(data...)
return crypto.Sign(hash.Bytes(), privateKey)
return utils.GenerateEthSignature(privateKey, flatten(data...))
}

func ExtractSigner(signature []byte, data ...[]byte) (signerAddress []byte, err error) {
hash := crypto.Keccak256Hash(data...)
ecdsaPubKey, err := crypto.SigToPub(hash.Bytes(), signature)
addr, err := utils.GetSignersEthAddress(flatten(data...), signature)
if err != nil {
return nil, err
}
return crypto.PubkeyToAddress(*ecdsaPubKey).Bytes(), nil
return addr.Bytes(), nil
}

0 comments on commit af5e478

Please sign in to comment.