Skip to content

Commit

Permalink
add sex verification (#9)
Browse files Browse the repository at this point in the history
* add sex verification

* fix migrations and delete callback-url from links

* fix migrations and delete callback-url from links
  • Loading branch information
chabanyknikita authored Sep 17, 2024
1 parent d27e74f commit 8c21d4b
Show file tree
Hide file tree
Showing 22 changed files with 72 additions and 31 deletions.
37 changes: 22 additions & 15 deletions docs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/spec/components/parameters/pathID.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
in: path
name: 'user_id'
required: true
description: "User identifier (e.g., email, address)."
example: "[email protected]"
schema:
type: string
Expand Down
1 change: 1 addition & 0 deletions docs/spec/components/schemas/GetProofKey.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ properties:
id:
type: string
example: "18493889724322d9aba2d93238ae60c2638946737bbe8eaecd6e5efdc0b6f4ff"
description: "User hash identifier"
type:
type: string
enum:
Expand Down
6 changes: 2 additions & 4 deletions docs/spec/components/schemas/Links.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
example: "https://example.com/integrations/verificator-svc/public/proof-params/c15ad8f88949"
description: "Returns proof-parameters and callback_url"
1 change: 1 addition & 0 deletions docs/spec/components/schemas/LinksKey.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ properties:
id:
type: string
example: "18493889724322d9aba2d93238ae60c2638946737bbe8eaecd6e5efdc0b6f4ff"
description: "User hash identifier"
type:
type: string
enum:
Expand Down
1 change: 1 addition & 0 deletions docs/spec/components/schemas/ParametersKey.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ properties:
id:
type: string
example: "[email protected]"
description: "User identifier (e.g., email, address)."
type:
type: string
enum:
Expand Down
1 change: 1 addition & 0 deletions docs/spec/components/schemas/ProofKey.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ properties:
id:
type: string
example: "18493889724322d9aba2d93238ae60c2638946737bbe8eaecd6e5efdc0b6f4ff"
description: "User hash identifier"
type:
type: string
enum:
Expand Down
1 change: 1 addition & 0 deletions docs/spec/components/schemas/ProofParamsKey.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ properties:
id:
type: string
example: "[email protected]"
description: "User identifier (e.g., email, address)."
type:
type: string
enum:
Expand Down
1 change: 1 addition & 0 deletions docs/spec/components/schemas/StatusKey.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ properties:
id:
type: string
example: "[email protected]"
description: "User identifier (e.g., email, address)."
type:
type: string
enum:
Expand Down
10 changes: 9 additions & 1 deletion docs/spec/components/schemas/User.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
example: "2234556494903931186902189494613533900917417361106374681011849132651019822199"
description: "Event ID of event"
sex:
type: boolean
example: true
description: "Enable verification of sex param"
1 change: 1 addition & 0 deletions docs/spec/components/schemas/UserKey.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ properties:
id:
type: string
example: "[email protected]"
description: "User identifier (e.g., email, address)."
type:
type: string
enum:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 4 additions & 0 deletions internal/assets/migrations/002_sex.sql
Original file line number Diff line number Diff line change
@@ -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;
1 change: 1 addition & 0 deletions internal/data/pg/verify_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions internal/data/verify_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/service/handlers/get_proof_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down
6 changes: 5 additions & 1 deletion internal/service/handlers/helpers/proof_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
const (
NullifierBit = 0
CitizenshipBit = 5
SexBit = 6
TimestampUpperBoundBit = 9
IdentityCounterUpperBoundBit = 11
ExpirationDateLowerboundBit = 12
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion internal/service/handlers/proof_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)

Expand Down
4 changes: 4 additions & 0 deletions internal/service/handlers/verification_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions resources/model_links_attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
14 changes: 10 additions & 4 deletions resources/model_user_attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

0 comments on commit 8c21d4b

Please sign in to comment.