diff --git a/config.yaml b/config.yaml index 3526d9a..61b234e 100644 --- a/config.yaml +++ b/config.yaml @@ -24,7 +24,7 @@ verifier: event_id: "event_id" signature_verification: - pub_key: "public_key" + pub_key: "04e29323ad356ab524fa5dbe3e490244e741b4d445ac7d2ee5f321556b3fda616bb9d2f2216fc27e099ab3019103cca872679e130629b2b90ea16cedb2b2136371" poseidonsmt_root_verifier: rpc: rpc_url diff --git a/docs/spec/components/schemas/User.yaml b/docs/spec/components/schemas/User.yaml index fee1239..372c06e 100644 --- a/docs/spec/components/schemas/User.yaml +++ b/docs/spec/components/schemas/User.yaml @@ -19,6 +19,10 @@ allOf: type: string example: "UKR" description: "User nationality" + nationality_check: + type: boolean + example: true + description: "You can use this instead of 'nationality' params, it will check nationality bit in selector" event_id: type: string example: "2234556494903931186902189494613533900917417361106374681011849132651019822199" diff --git a/internal/assets/migrations/004_nationalityEnable.sql b/internal/assets/migrations/004_nationalityEnable.sql new file mode 100644 index 0000000..c3f54f0 --- /dev/null +++ b/internal/assets/migrations/004_nationalityEnable.sql @@ -0,0 +1,4 @@ +-- +migrate Up +ALTER TABLE verify_users ADD COLUMN nationality_enable BOOLEAN NOT NULL DEFAULT FALSE; +-- +migrate Down +ALTER TABLE verify_users DROP COLUMN nationality_enable; \ No newline at end of file diff --git a/internal/data/pg/verify_users.go b/internal/data/pg/verify_users.go index 3080fad..0c42979 100644 --- a/internal/data/pg/verify_users.go +++ b/internal/data/pg/verify_users.go @@ -69,16 +69,17 @@ func (q *VerifyUsersQ) Insert(VerifyUsers *data.VerifyUsers) error { } stmt := sq.Insert(verifyUsersTableName).SetMap(map[string]interface{}{ - "user_id": VerifyUsers.UserID, - "user_id_hash": VerifyUsers.UserIDHash, - "age_lower_bound": VerifyUsers.AgeLowerBound, - "nationality": VerifyUsers.Nationality, - "uniqueness": VerifyUsers.Uniqueness, - "event_id": VerifyUsers.EventId, - "status": VerifyUsers.Status, - "proof": proofJSON, - "sex": VerifyUsers.Sex, - "sex_enable": VerifyUsers.SexEnable, + "user_id": VerifyUsers.UserID, + "user_id_hash": VerifyUsers.UserIDHash, + "age_lower_bound": VerifyUsers.AgeLowerBound, + "nationality": VerifyUsers.Nationality, + "uniqueness": VerifyUsers.Uniqueness, + "event_id": VerifyUsers.EventId, + "status": VerifyUsers.Status, + "proof": proofJSON, + "sex": VerifyUsers.Sex, + "sex_enable": VerifyUsers.SexEnable, + "nationality_enable": VerifyUsers.NationalityEnable, }) if err = q.db.Exec(stmt); err != nil { diff --git a/internal/data/verify_users.go b/internal/data/verify_users.go index 788a1b9..984325f 100644 --- a/internal/data/verify_users.go +++ b/internal/data/verify_users.go @@ -5,17 +5,18 @@ import ( ) type VerifyUsers struct { - UserID string `db:"user_id"` - UserIDHash string `db:"user_id_hash"` - AgeLowerBound int `db:"age_lower_bound"` - Nationality string `db:"nationality"` - CreatedAt time.Time `db:"created_at"` - Uniqueness bool `db:"uniqueness"` - EventId string `db:"event_id"` - Status string `db:"status"` - Proof []byte `db:"proof"` - Sex string `db:"sex"` - SexEnable bool `db:"sex_enable"` + UserID string `db:"user_id"` + UserIDHash string `db:"user_id_hash"` + AgeLowerBound int `db:"age_lower_bound"` + Nationality string `db:"nationality"` + CreatedAt time.Time `db:"created_at"` + Uniqueness bool `db:"uniqueness"` + EventId string `db:"event_id"` + Status string `db:"status"` + Proof []byte `db:"proof"` + Sex string `db:"sex"` + SexEnable bool `db:"sex_enable"` + NationalityEnable bool `db:"nationality_enable"` } type VerifyUsersQ interface { diff --git a/internal/service/handlers/get_proof_parameters.go b/internal/service/handlers/get_proof_parameters.go index be9d05e..46b75f1 100644 --- a/internal/service/handlers/get_proof_parameters.go +++ b/internal/service/handlers/get_proof_parameters.go @@ -25,7 +25,7 @@ func GetProofParameters(w http.ResponseWriter, r *http.Request) { IdentityCounterUpperBound int32 TimestampUpperBound = "0" eventID = Verifiers(r).EventID - proofSelector = helpers.CalculateProofSelector(userInputs.Uniqueness, userInputs.AgeLowerBound, userInputs.Nationality, true) + proofSelector = helpers.CalculateProofSelector(userInputs.Uniqueness, userInputs.AgeLowerBound, userInputs.Nationality, true, true) ) if userInputs.EventID != "" { diff --git a/internal/service/handlers/helpers/proof_params.go b/internal/service/handlers/helpers/proof_params.go index 13ca972..959046b 100644 --- a/internal/service/handlers/helpers/proof_params.go +++ b/internal/service/handlers/helpers/proof_params.go @@ -93,10 +93,10 @@ func ExtractEventData(getter zk.PubSignalGetter) (string, error) { return fmt.Sprintf("0x%s", hex.EncodeToString(userIDHash[:])), nil } -func CalculateProofSelector(uniqueness bool, ageLowerBound int, nationality string, sexEnable bool) int { +func CalculateProofSelector(uniqueness bool, ageLowerBound int, nationality string, sexEnable bool, nationalityEnable bool) int { var bitLine uint32 bitLine |= 1 << NullifierBit - if nationality != "" { + if nationality != "" || nationalityEnable { bitLine |= 1 << CitizenshipBit } if sexEnable { diff --git a/internal/service/handlers/proof_params.go b/internal/service/handlers/proof_params.go index 85fd212..bfde766 100644 --- a/internal/service/handlers/proof_params.go +++ b/internal/service/handlers/proof_params.go @@ -36,7 +36,7 @@ func GetProofParamsById(w http.ResponseWriter, r *http.Request) { TimestampUpperBound = "0" eventID = Verifiers(r).EventID birthDateUpperBound = helpers.CalculateBirthDateHex(existingUser.AgeLowerBound) - proofSelector = helpers.CalculateProofSelector(existingUser.Uniqueness, existingUser.AgeLowerBound, existingUser.Nationality, existingUser.SexEnable) + proofSelector = helpers.CalculateProofSelector(existingUser.Uniqueness, existingUser.AgeLowerBound, existingUser.Nationality, existingUser.SexEnable, existingUser.NationalityEnable) callbackURL = fmt.Sprintf("%s/integrations/verificator-svc/public/callback/%s", Callback(r).URL, userIDHash) ) diff --git a/internal/service/handlers/proof_params_light.go b/internal/service/handlers/proof_params_light.go index 40f77bf..85b25ca 100644 --- a/internal/service/handlers/proof_params_light.go +++ b/internal/service/handlers/proof_params_light.go @@ -36,7 +36,7 @@ func GetProofParamsLightById(w http.ResponseWriter, r *http.Request) { TimestampUpperBound = "0" eventID = Verifiers(r).EventID birthDateUpperBound = helpers.CalculateBirthDateHex(existingUser.AgeLowerBound) - proofSelector = helpers.CalculateProofSelector(existingUser.Uniqueness, existingUser.AgeLowerBound, existingUser.Nationality, existingUser.SexEnable) + proofSelector = helpers.CalculateProofSelector(existingUser.Uniqueness, existingUser.AgeLowerBound, existingUser.Nationality, existingUser.SexEnable, existingUser.NationalityEnable) callbackURL = fmt.Sprintf("%s/integrations/verificator-svc/light/public/callback-sign/%s", Callback(r).URL, userIDHash) ) diff --git a/internal/service/handlers/verification_callback.go b/internal/service/handlers/verification_callback.go index 4223fdc..1c90696 100644 --- a/internal/service/handlers/verification_callback.go +++ b/internal/service/handlers/verification_callback.go @@ -56,6 +56,13 @@ func VerificationCallback(w http.ResponseWriter, r *http.Request) { return } + userNationality, err := helpers.DecimalToHexToUtf8(getter.Get(zk.Citizenship)) + if err != nil { + Log(r).WithError(err).Errorf("failed to convert decimal(nationality) to utf8") + ape.RenderErr(w, problems.BadRequest(err)...) + return + } + userIDHash, err := helpers.ExtractEventData(getter) if err != nil { Log(r).WithError(err).Errorf("failed to extract user hash from event data") @@ -88,6 +95,8 @@ func VerificationCallback(w http.ResponseWriter, r *http.Request) { } if verifiedUser.Nationality != "" { verifyOpts = append(verifyOpts, zk.WithCitizenships(verifiedUser.Nationality)) + } else { + verifiedUser.Nationality = userNationality } err = Verifiers(r).Passport.VerifyProof(proof, verifyOpts...) diff --git a/internal/service/handlers/verification_link.go b/internal/service/handlers/verification_link.go index a614153..eca5bd3 100644 --- a/internal/service/handlers/verification_link.go +++ b/internal/service/handlers/verification_link.go @@ -54,6 +54,10 @@ func VerificationLink(w http.ResponseWriter, r *http.Request) { user.SexEnable = *req.Data.Attributes.Sex } + if req.Data.Attributes.NationalityCheck != nil { + user.NationalityEnable = *req.Data.Attributes.NationalityCheck + } + existingUser, err := VerifyUsersQ(r).WhereHashID(user.UserIDHash).Get() if err != nil { Log(r).WithError(err).Errorf("failed to query user with userID [%s]", userIdHash) diff --git a/resources/model_user_attributes.go b/resources/model_user_attributes.go index 2433dbc..d21c2ea 100644 --- a/resources/model_user_attributes.go +++ b/resources/model_user_attributes.go @@ -11,6 +11,8 @@ type UserAttributes struct { EventId *string `json:"event_id,omitempty"` // User nationality Nationality *string `json:"nationality,omitempty"` + // You can use this instead of 'nationality' params, it will check nationality bit in selector + NationalityCheck *bool `json:"nationality_check,omitempty"` // Enable verification of sex param Sex *bool `json:"sex,omitempty"` // Parameters for checking user uniqueness