diff --git a/internal/config/proof_parameters.go b/internal/config/proof_parameters.go index 9a472f0..db02618 100644 --- a/internal/config/proof_parameters.go +++ b/internal/config/proof_parameters.go @@ -13,8 +13,6 @@ type ProofParametersConfiger interface { type ProofParametersConfig struct { EventID string `fig:"event_id,required"` - SelectorUnique string `fig:"selector_unique"` - SelectorNotUnique string `fig:"selector_not_unique"` TimestampLowerBound string `fig:"timestamp_lower_bound,required"` TimestampUpperBound string `fig:"timestamp_upper_bound,required"` ExpirationDateLowerBound string `fig:"expiration_date_lower_bound,required"` diff --git a/internal/config/verifier.go b/internal/config/verifier.go index 5ce0884..d24719c 100644 --- a/internal/config/verifier.go +++ b/internal/config/verifier.go @@ -22,8 +22,9 @@ type Verifiers struct { func (c *config) Verifiers() Verifiers { return c.verifier.Do(func() interface{} { var cfg struct { - AllowedAge int `fig:"allowed_age,required"` - AllowedIdentityTimestamp int64 `fig:"allowed_identity_timestamp,required"` + AllowedAge int `fig:"allowed_age,required"` + VerificationKeyPath string `fig:"verification_key_path,required"` + AllowedIdentityTimestamp int64 `fig:"allowed_identity_timestamp,required"` } err := figure. @@ -35,8 +36,8 @@ func (c *config) Verifiers() Verifiers { } pass, err := zk.NewVerifier(nil, - zk.WithProofType(zk.GeorgianPassport), - zk.WithVerificationKeyFile(passportVerificationKey), + zk.WithProofType(zk.GlobalPassport), + zk.WithVerificationKeyFile(cfg.VerificationKeyPath), zk.WithPassportRootVerifier(c.passport.ProvideVerifier()), zk.WithIdentitiesCreationTimestampLimit(cfg.AllowedIdentityTimestamp), ) diff --git a/internal/service/handlers/get_proof_parameters.go b/internal/service/handlers/get_proof_parameters.go index 72c358e..a658d29 100644 --- a/internal/service/handlers/get_proof_parameters.go +++ b/internal/service/handlers/get_proof_parameters.go @@ -36,14 +36,13 @@ func GetProofParameters(w http.ResponseWriter, r *http.Request) { Log(r).Debug(userInputs.Uniqueness) return } - proofSelector := ProofParameters(r).SelectorUnique - var IdentityCounterUpperBound int32 = 1 - TimestampUpperBound := "19000000000" - - if !userInputs.Uniqueness { - proofSelector = ProofParameters(r).SelectorNotUnique - IdentityCounterUpperBound = 0 - TimestampUpperBound = "0" + + TimestampUpperBound := "0" + var IdentityCounterUpperBound int32 = 0 + proofSelector := CalculateProofSelector(userInputs.Uniqueness) + if proofSelector&(1<<9) != 0 && proofSelector&(1<<11) != 0 { + TimestampUpperBound = ProofParameters(r).TimestampUpperBound + IdentityCounterUpperBound = 1 } userIdHash, err := StringToPoseidonHash(userInputs.UserId) @@ -64,7 +63,7 @@ func GetProofParameters(w http.ResponseWriter, r *http.Request) { proofParams := ProofParams{ host: Callback(r).Url, eventID: ProofParameters(r).EventID, - proofSelector: proofSelector, + proofSelector: strconv.Itoa(proofSelector), identityCounterUpperBound: IdentityCounterUpperBound, timestampUpperBound: TimestampUpperBound, citizenshipMask: utf8ToHex(userInputs.Nationality), @@ -142,10 +141,18 @@ func utf8ToHex(input string) string { func calculateBirthDateHex(ageLowerBound int) string { currentDate := time.Now().UTC() + birthDateLoweBound := []byte(fmt.Sprintf("%02d", (currentDate.Year()-ageLowerBound)%100) + "0101") + hexBirthDateLoweBound := hexutils.BytesToHex(birthDateLoweBound) - birthYear := (currentDate.Year() - ageLowerBound) % 1e2 - birthDateLowerBound := []byte(strconv.Itoa(birthYear) + "0101") - hexString := hexutils.BytesToHex(birthDateLowerBound) + return hexBirthDateLoweBound +} - return hexString +func CalculateProofSelector(uniqueness bool) int { + var bitLine uint32 = 0 + if uniqueness { + bitLine |= 1 << 9 + bitLine |= 1 << 11 + } + + return int(bitLine) } diff --git a/internal/service/handlers/verification_callback.go b/internal/service/handlers/verification_callback.go index 2612e0a..144a51d 100644 --- a/internal/service/handlers/verification_callback.go +++ b/internal/service/handlers/verification_callback.go @@ -48,15 +48,21 @@ func VerificationCallback(w http.ResponseWriter, r *http.Request) { } if verifiedUser == nil { Log(r).Error("user is empty") - ape.RenderErr(w, problems.InternalError()) + ape.RenderErr(w, problems.NotFound()) return } - selectorInt, err := strconv.Atoi(selector) + selectorInt, err := strconv.Atoi(proof.PubSignals[zk.Selector]) if err != nil { fmt.Println("Error during conversion") return } + identityCounterUpperBound, err := strconv.ParseInt(proof.PubSignals[zk.IdentityCounterUpperBound], 10, 64) + if err != nil { + Log(r).Error("cannot extract identityUpperBound from public signals") + ape.RenderErr(w, problems.InternalError()) + return + } if verifiedUser.Uniqueness { if proof.PubSignals[zk.TimestampUpperBound] == ProofParameters(r).TimestampUpperBound { if selectorInt&1<<9 == 0 { @@ -76,8 +82,8 @@ func VerificationCallback(w http.ResponseWriter, r *http.Request) { var verifyOpts = []zk.VerifyOption{ zk.WithCitizenships(verifiedUser.Nationality), - zk.WithProofSelectorValue(selector), - zk.WithIdentitiesCounter(1), + zk.WithProofSelectorValue(proof.PubSignals[zk.Selector]), + zk.WithIdentitiesCounter(identityCounterUpperBound), zk.WithAgeAbove(verifiedUser.AgeLowerBound), zk.WithEventID(ProofParameters(r).EventID), }