Skip to content

Commit

Permalink
Add ToEthSignedMessageHash logic
Browse files Browse the repository at this point in the history
  • Loading branch information
J3imip committed Dec 16, 2024
1 parent ac1afaf commit a9ed2ec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 1 addition & 2 deletions internal/service/api/handlers/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
Expand Down
6 changes: 6 additions & 0 deletions internal/utils/asn1_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit a9ed2ec

Please sign in to comment.