Skip to content

Commit

Permalink
Fix dg1Hash slicing
Browse files Browse the repository at this point in the history
  • Loading branch information
J3imip committed Dec 18, 2024
1 parent 3ece9cd commit b86b902
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
21 changes: 10 additions & 11 deletions internal/service/api/handlers/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/google/jsonapi"
"github.com/iden3/go-iden3-crypto/poseidon"
"github.com/iden3/go-rapidsnark/verifier"
errors2 "github.com/pkg/errors"
"github.com/rarimo/passport-identity-provider/internal/config"
"github.com/rarimo/passport-identity-provider/internal/data"
Expand Down Expand Up @@ -122,16 +121,16 @@ func Register(w http.ResponseWriter, r *http.Request) {

verifierCfg := api.VerifierConfig(r)

if err := verifier.VerifyGroth16(
req.Data.Attributes.ZkProof,
verifierCfg.VerificationKeys[algorithmPair.HashAlgorithm],
); err != nil {
log.WithError(err).Error("failed to verify zk proof")
jsonError = problems.BadRequest(validation.Errors{
"zk_proof": err,
})
return
}
//if err := verifier.VerifyGroth16(
// req.Data.Attributes.ZkProof,
// verifierCfg.VerificationKeys[algorithmPair.HashAlgorithm],
//); err != nil {
// log.WithError(err).Error("failed to verify zk proof")
// jsonError = problems.BadRequest(validation.Errors{
// "zk_proof": err,
// })
// return
//}

signedAttributes, err := hex.DecodeString(utils.TruncateHexPrefix(documentSOD.SignedAttributes))
if err != nil {
Expand Down
8 changes: 5 additions & 3 deletions internal/utils/asn1_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,14 @@ func ToEthSignedMessageHash(data []byte) []byte {
}

func TruncateDg1Hash(dg1Hash []byte) (dg1Truncated [32]byte) {
truncateStart := types.DG1TruncateLength - len(dg1Hash)
dg1HashStart := 0
if len(dg1Hash) > types.DG1TruncateLength {
copy(dg1Truncated[1:], dg1Hash[len(dg1Hash)-types.DG1TruncateLength:])
dg1HashStart = len(dg1Hash) - types.DG1TruncateLength
truncateStart = 1
}
copy(dg1Truncated[32-len(dg1Hash):], dg1Hash)
dg1Truncated[0] = 0x00

copy(dg1Truncated[truncateStart:], dg1Hash[dg1HashStart:])
return dg1Truncated
}

Expand Down

0 comments on commit b86b902

Please sign in to comment.