From 8c21d4bb683536acf07163a82eda9ae332fbaf8f Mon Sep 17 00:00:00 2001 From: chabanyknikita <92546152+chabanyknikita@users.noreply.github.com> Date: Tue, 17 Sep 2024 12:06:49 +0300 Subject: [PATCH] add sex verification (#9) * add sex verification * fix migrations and delete callback-url from links * fix migrations and delete callback-url from links --- docs/package-lock.json | 37 +++++++++++-------- docs/spec/components/parameters/pathID.yaml | 1 + docs/spec/components/schemas/GetProofKey.yaml | 1 + docs/spec/components/schemas/Links.yaml | 6 +-- docs/spec/components/schemas/LinksKey.yaml | 1 + .../components/schemas/ParametersKey.yaml | 1 + docs/spec/components/schemas/ProofKey.yaml | 1 + .../components/schemas/ProofParamsKey.yaml | 1 + docs/spec/components/schemas/StatusKey.yaml | 1 + docs/spec/components/schemas/User.yaml | 10 ++++- docs/spec/components/schemas/UserKey.yaml | 1 + ...ficator-svc@private@verification-link.yaml | 2 +- ...vc@public@proof-params@{user_id_hash}.yaml | 2 +- internal/assets/migrations/002_sex.sql | 4 ++ internal/data/pg/verify_users.go | 1 + internal/data/verify_users.go | 1 + .../service/handlers/get_proof_parameters.go | 2 +- .../service/handlers/helpers/proof_params.go | 6 ++- internal/service/handlers/proof_params.go | 2 +- .../service/handlers/verification_link.go | 4 ++ resources/model_links_attributes.go | 4 +- resources/model_user_attributes.go | 14 +++++-- 22 files changed, 72 insertions(+), 31 deletions(-) create mode 100644 internal/assets/migrations/002_sex.sql diff --git a/docs/package-lock.json b/docs/package-lock.json index 25fac2d..a4a0ded 100644 --- a/docs/package-lock.json +++ b/docs/package-lock.json @@ -734,6 +734,13 @@ "ajv": "4.11.8 - 6" } }, + "node_modules/better-ajv-errors/node_modules/core-js": { + "version": "2.6.12", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.12.tgz", + "integrity": "sha512-Kb2wC0fvsWfQrgk8HU5lW6U/Lcs8+9aaYcy4ZFc6DDlo4nZ7n70dEgE5rtR0oG6ufKDUnrwfWL1mXR5ljDatrQ==", + "deprecated": "core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.", + "hasInstallScript": true + }, "node_modules/binary-extensions": { "version": "1.13.0", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-1.13.0.tgz", @@ -1316,10 +1323,14 @@ } }, "node_modules/core-js": { - "version": "2.6.5", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.5.tgz", - "integrity": "sha512-klh/kDpwX8hryYL14M9w/xei6vrv6sE8gTHDG7/T/+SEovB/G4ejwcfE/CBzO6Edsu+OETZMZ3wcX/EjUkrl5A==", - "deprecated": "core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js." + "version": "3.38.1", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.38.1.tgz", + "integrity": "sha512-OP35aUorbU3Zvlx7pjsFdu1rGNnD4pgw/CWoYzRY3t2EzoVT7shKHY1dlAy3f41cGIO7ZDPQimhGFTlEYkG/Hw==", + "hasInstallScript": true, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/core-js" + } }, "node_modules/core-util-is": { "version": "1.0.2", @@ -6245,17 +6256,6 @@ "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" }, - "node_modules/swagger2openapi/node_modules/core-js": { - "version": "3.9.0", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.9.0.tgz", - "integrity": "sha512-PyFBJaLq93FlyYdsndE5VaueA9K5cNB7CGzeCj191YYLhkQM0gdZR2SKihM70oF0wdqKSKClv/tEBOpoRmdOVQ==", - "deprecated": "core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.", - "hasInstallScript": true, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/core-js" - } - }, "node_modules/swagger2openapi/node_modules/get-caller-file": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", @@ -6958,6 +6958,13 @@ "optionalDependencies": { "commander": "^2.7.1" } + }, + "node_modules/z-schema/node_modules/core-js": { + "version": "2.6.12", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-2.6.12.tgz", + "integrity": "sha512-Kb2wC0fvsWfQrgk8HU5lW6U/Lcs8+9aaYcy4ZFc6DDlo4nZ7n70dEgE5rtR0oG6ufKDUnrwfWL1mXR5ljDatrQ==", + "deprecated": "core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.", + "hasInstallScript": true } } } diff --git a/docs/spec/components/parameters/pathID.yaml b/docs/spec/components/parameters/pathID.yaml index 3e592a3..ecd6976 100644 --- a/docs/spec/components/parameters/pathID.yaml +++ b/docs/spec/components/parameters/pathID.yaml @@ -1,6 +1,7 @@ in: path name: 'user_id' required: true +description: "User identifier (e.g., email, address)." example: "user@example.com" schema: type: string diff --git a/docs/spec/components/schemas/GetProofKey.yaml b/docs/spec/components/schemas/GetProofKey.yaml index 4a220de..c9dc920 100644 --- a/docs/spec/components/schemas/GetProofKey.yaml +++ b/docs/spec/components/schemas/GetProofKey.yaml @@ -6,6 +6,7 @@ properties: id: type: string example: "18493889724322d9aba2d93238ae60c2638946737bbe8eaecd6e5efdc0b6f4ff" + description: "User hash identifier" type: type: string enum: diff --git a/docs/spec/components/schemas/Links.yaml b/docs/spec/components/schemas/Links.yaml index 78c9e07..a2610ba 100644 --- a/docs/spec/components/schemas/Links.yaml +++ b/docs/spec/components/schemas/Links.yaml @@ -9,9 +9,7 @@ allOf: required: - get_proof_params properties: - callback_url: - type: string - example: "https://example.com/integrations/verificator-svc/public/callback/c15ad8f88949" get_proof_params: type: string - example: "https://example.com/integrations/verificator-svc/public/proof-params/c15ad8f88949" \ No newline at end of file + example: "https://example.com/integrations/verificator-svc/public/proof-params/c15ad8f88949" + description: "Returns proof-parameters and callback_url" \ No newline at end of file diff --git a/docs/spec/components/schemas/LinksKey.yaml b/docs/spec/components/schemas/LinksKey.yaml index dcaaa9e..ea8fe0f 100644 --- a/docs/spec/components/schemas/LinksKey.yaml +++ b/docs/spec/components/schemas/LinksKey.yaml @@ -6,6 +6,7 @@ properties: id: type: string example: "18493889724322d9aba2d93238ae60c2638946737bbe8eaecd6e5efdc0b6f4ff" + description: "User hash identifier" type: type: string enum: diff --git a/docs/spec/components/schemas/ParametersKey.yaml b/docs/spec/components/schemas/ParametersKey.yaml index 4160763..a8601aa 100644 --- a/docs/spec/components/schemas/ParametersKey.yaml +++ b/docs/spec/components/schemas/ParametersKey.yaml @@ -6,6 +6,7 @@ properties: id: type: string example: "user@example.com" + description: "User identifier (e.g., email, address)." type: type: string enum: diff --git a/docs/spec/components/schemas/ProofKey.yaml b/docs/spec/components/schemas/ProofKey.yaml index b87e95a..1d769d7 100644 --- a/docs/spec/components/schemas/ProofKey.yaml +++ b/docs/spec/components/schemas/ProofKey.yaml @@ -6,6 +6,7 @@ properties: id: type: string example: "18493889724322d9aba2d93238ae60c2638946737bbe8eaecd6e5efdc0b6f4ff" + description: "User hash identifier" type: type: string enum: diff --git a/docs/spec/components/schemas/ProofParamsKey.yaml b/docs/spec/components/schemas/ProofParamsKey.yaml index 3a369d0..53f9990 100644 --- a/docs/spec/components/schemas/ProofParamsKey.yaml +++ b/docs/spec/components/schemas/ProofParamsKey.yaml @@ -6,6 +6,7 @@ properties: id: type: string example: "user@example.com" + description: "User identifier (e.g., email, address)." type: type: string enum: diff --git a/docs/spec/components/schemas/StatusKey.yaml b/docs/spec/components/schemas/StatusKey.yaml index 0dabbc1..8499a6a 100644 --- a/docs/spec/components/schemas/StatusKey.yaml +++ b/docs/spec/components/schemas/StatusKey.yaml @@ -6,6 +6,7 @@ properties: id: type: string example: "user@example.com" + description: "User identifier (e.g., email, address)." type: type: string enum: diff --git a/docs/spec/components/schemas/User.yaml b/docs/spec/components/schemas/User.yaml index 656a4a5..fee1239 100644 --- a/docs/spec/components/schemas/User.yaml +++ b/docs/spec/components/schemas/User.yaml @@ -10,12 +10,20 @@ allOf: age_lower_bound: type: integer example: 18 + description: "Lower user age limit" uniqueness: type: boolean example: true + description: "Parameters for checking user uniqueness" nationality: type: string example: "UKR" + description: "User nationality" event_id: type: string - example: "2234556494903931186902189494613533900917417361106374681011849132651019822199" \ No newline at end of file + example: "2234556494903931186902189494613533900917417361106374681011849132651019822199" + description: "Event ID of event" + sex: + type: boolean + example: true + description: "Enable verification of sex param" \ No newline at end of file diff --git a/docs/spec/components/schemas/UserKey.yaml b/docs/spec/components/schemas/UserKey.yaml index 44f326b..51b9a6d 100644 --- a/docs/spec/components/schemas/UserKey.yaml +++ b/docs/spec/components/schemas/UserKey.yaml @@ -6,6 +6,7 @@ properties: id: type: string example: "example@example.com" + description: "User identifier (e.g., email, address)." type: type: string enum: diff --git a/docs/spec/paths/integrations@verificator-svc@private@verification-link.yaml b/docs/spec/paths/integrations@verificator-svc@private@verification-link.yaml index 18a7dcc..5c5e70a 100644 --- a/docs/spec/paths/integrations@verificator-svc@private@verification-link.yaml +++ b/docs/spec/paths/integrations@verificator-svc@private@verification-link.yaml @@ -3,7 +3,7 @@ post: - User verification summary: Request verification links for qr-code generation description: | - Requests verification links for user to generate qr-code, returns: callback_url and get_proof_params. + Requests verification links for user to generate qr-code, returns: get_proof_params. operationId: getVerificationLink requestBody: required: true diff --git a/docs/spec/paths/integrations@verificator-svc@public@proof-params@{user_id_hash}.yaml b/docs/spec/paths/integrations@verificator-svc@public@proof-params@{user_id_hash}.yaml index 46fc715..bb864be 100644 --- a/docs/spec/paths/integrations@verificator-svc@public@proof-params@{user_id_hash}.yaml +++ b/docs/spec/paths/integrations@verificator-svc@public@proof-params@{user_id_hash}.yaml @@ -3,7 +3,7 @@ get: - Proof summary: Get Proof Parameters(mobile) description: | - Get proof parameters by userIDHash. + Get proof parameters by userIDHash, returns: proof-params and callback_url. operationId: getProofParameters parameters: - $ref: '#/components/parameters/pathIDHash' diff --git a/internal/assets/migrations/002_sex.sql b/internal/assets/migrations/002_sex.sql new file mode 100644 index 0000000..e0cf3c9 --- /dev/null +++ b/internal/assets/migrations/002_sex.sql @@ -0,0 +1,4 @@ +-- +migrate Up +ALTER TABLE verify_users ADD COLUMN sex BOOLEAN NOT NULL DEFAULT FALSE; +-- +migrate Down +ALTER TABLE verify_users DROP COLUMN sex; \ No newline at end of file diff --git a/internal/data/pg/verify_users.go b/internal/data/pg/verify_users.go index 63ad119..d988c72 100644 --- a/internal/data/pg/verify_users.go +++ b/internal/data/pg/verify_users.go @@ -77,6 +77,7 @@ func (q *VerifyUsersQ) Insert(VerifyUsers *data.VerifyUsers) error { "event_id": VerifyUsers.EventId, "status": VerifyUsers.Status, "proof": proofJSON, + "sex": VerifyUsers.Sex, }) if err = q.db.Exec(stmt); err != nil { diff --git a/internal/data/verify_users.go b/internal/data/verify_users.go index 85809f5..525fe2b 100644 --- a/internal/data/verify_users.go +++ b/internal/data/verify_users.go @@ -14,6 +14,7 @@ type VerifyUsers struct { EventId string `db:"event_id"` Status string `db:"status"` Proof []byte `db:"proof"` + Sex bool `db:"sex"` } type VerifyUsersQ interface { diff --git a/internal/service/handlers/get_proof_parameters.go b/internal/service/handlers/get_proof_parameters.go index 1dbe6a8..be9d05e 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) + proofSelector = helpers.CalculateProofSelector(userInputs.Uniqueness, userInputs.AgeLowerBound, userInputs.Nationality, true) ) if userInputs.EventID != "" { diff --git a/internal/service/handlers/helpers/proof_params.go b/internal/service/handlers/helpers/proof_params.go index 6f6ad27..9c818bc 100644 --- a/internal/service/handlers/helpers/proof_params.go +++ b/internal/service/handlers/helpers/proof_params.go @@ -13,6 +13,7 @@ import ( const ( NullifierBit = 0 CitizenshipBit = 5 + SexBit = 6 TimestampUpperBoundBit = 9 IdentityCounterUpperBoundBit = 11 ExpirationDateLowerboundBit = 12 @@ -58,12 +59,15 @@ func ExtractEventData(getter zk.PubSignalGetter) (string, error) { return fmt.Sprintf("0x%s", hex.EncodeToString(userIDHash[:])), nil } -func CalculateProofSelector(uniqueness bool, ageLowerBound int, nationality string) int { +func CalculateProofSelector(uniqueness bool, ageLowerBound int, nationality string, sexEnable bool) int { var bitLine uint32 bitLine |= 1 << NullifierBit if nationality != "" { bitLine |= 1 << CitizenshipBit } + if sexEnable { + bitLine |= 1 << SexBit + } if ageLowerBound != -1 { bitLine |= 1 << BirthDateUpperboundBit } diff --git a/internal/service/handlers/proof_params.go b/internal/service/handlers/proof_params.go index 4f5e3d5..87dc9fd 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) + proofSelector = helpers.CalculateProofSelector(existingUser.Uniqueness, existingUser.AgeLowerBound, existingUser.Nationality, existingUser.Sex) callbackURL = fmt.Sprintf("%s/integrations/verificator-svc/public/callback/%s", Callback(r).URL, userIDHash) ) diff --git a/internal/service/handlers/verification_link.go b/internal/service/handlers/verification_link.go index 61df0ed..54d3233 100644 --- a/internal/service/handlers/verification_link.go +++ b/internal/service/handlers/verification_link.go @@ -50,6 +50,10 @@ func VerificationLink(w http.ResponseWriter, r *http.Request) { user.Uniqueness = *req.Data.Attributes.Uniqueness } + if req.Data.Attributes.Sex != nil { + user.Sex = *req.Data.Attributes.Sex + } + 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_links_attributes.go b/resources/model_links_attributes.go index c3553a0..3842d09 100644 --- a/resources/model_links_attributes.go +++ b/resources/model_links_attributes.go @@ -5,6 +5,6 @@ package resources type LinksAttributes struct { - CallbackUrl *string `json:"callback_url,omitempty"` - GetProofParams string `json:"get_proof_params"` + // Returns proof-parameters and callback_url + GetProofParams string `json:"get_proof_params"` } diff --git a/resources/model_user_attributes.go b/resources/model_user_attributes.go index 62121a8..2433dbc 100644 --- a/resources/model_user_attributes.go +++ b/resources/model_user_attributes.go @@ -5,8 +5,14 @@ package resources type UserAttributes struct { - AgeLowerBound *int32 `json:"age_lower_bound,omitempty"` - EventId *string `json:"event_id,omitempty"` - Nationality *string `json:"nationality,omitempty"` - Uniqueness *bool `json:"uniqueness,omitempty"` + // Lower user age limit + AgeLowerBound *int32 `json:"age_lower_bound,omitempty"` + // Event ID of event + EventId *string `json:"event_id,omitempty"` + // User nationality + Nationality *string `json:"nationality,omitempty"` + // Enable verification of sex param + Sex *bool `json:"sex,omitempty"` + // Parameters for checking user uniqueness + Uniqueness *bool `json:"uniqueness,omitempty"` }