diff --git a/internal/service/api/handlers/register.go b/internal/service/api/handlers/register.go index 549fd00..59543e7 100644 --- a/internal/service/api/handlers/register.go +++ b/internal/service/api/handlers/register.go @@ -13,7 +13,6 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/crypto" "github.com/google/jsonapi" - "github.com/iden3/go-iden3-crypto/keccak256" "github.com/iden3/go-iden3-crypto/poseidon" "github.com/iden3/go-rapidsnark/verifier" errors2 "github.com/pkg/errors" @@ -280,7 +279,7 @@ func Register(w http.ResponseWriter, r *http.Request) { return } - signature, err := crypto.Sign(keccak256.Hash(signedData), api.KeysConfig(r).SignatureKey) + signature, err := crypto.Sign(utils.ToEthSignedMessageHash(signedData), api.KeysConfig(r).SignatureKey) if err != nil { log.WithError(err).Error("failed to sign messageHash") jsonError = append(jsonError, problems.InternalError()) diff --git a/internal/utils/asn1_operations.go b/internal/utils/asn1_operations.go index 269db16..4fc18e0 100644 --- a/internal/utils/asn1_operations.go +++ b/internal/utils/asn1_operations.go @@ -10,6 +10,7 @@ import ( "math/big" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" "github.com/iden3/go-iden3-crypto/poseidon" "github.com/rarimo/passport-identity-provider/internal/types" "gitlab.com/distributed_lab/logan/v3/errors" @@ -128,6 +129,11 @@ func ExtractPublicKey(dg15 []byte) (interface{}, [32]byte, error) { } } +func ToEthSignedMessageHash(data []byte) []byte { + prefix := []byte("\x19Ethereum Signed Message:\n32") + return crypto.Keccak256(append(prefix, data...)) +} + func generalPublicKeyExtraction(dg15 []byte) (any, error) { var rawDg15 asn1.RawValue if _, err := asn1.Unmarshal(dg15, &rawDg15); err != nil {