Skip to content

Commit 931edc6

Browse files
Fix migration and remove params for check
1 parent 78ee971 commit 931edc6

9 files changed

Lines changed: 30 additions & 59 deletions

File tree

docs/spec/components/schemas/AdvancedVerification.yaml

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,18 @@ allOf:
1515
example: "12345678900987654321"
1616
description: "Event ID"
1717
selector:
18-
type: string
18+
type: integer
1919
example: "35425"
2020
description: "Selector value"
2121
# Optional
2222
age_lower_bound:
2323
type: integer
2424
example: 18
2525
description: "Lower user age limit"
26-
uniqueness:
27-
type: boolean
28-
example: true
29-
description: "Parameters for checking user uniqueness"
30-
nationality:
26+
citizenship_mask:
3127
type: string
3228
example: "UKR"
33-
description: "User nationality"
34-
nationality_check:
35-
type: boolean
36-
example: true
37-
description: "Enable nationality verification"
38-
sex:
39-
type: boolean
40-
example: true
41-
description: "Enable verification of sex param"
29+
description: "User citezenship mask"
4230
expiration_lower_bound:
4331
type: boolean
4432
example: true
@@ -76,10 +64,12 @@ allOf:
7664
example: "0x303030303030"
7765
description: "Expiration date upper bound in hex format"
7866
timestamp_lower_bound:
79-
type: string
67+
type: integer
68+
format: int64
8069
example: "0"
8170
description: "Timestamp lower bound"
8271
timestamp_upper_bound:
83-
type: string
72+
type: integer
73+
format: int64
8474
example: "1726059494"
8575
description: "Timestamp upper bound"

internal/assets/migrations/007_proof_v2.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ ALTER TABLE verify_users
77
ADD COLUMN identity_counter INTEGER DEFAULT 0,
88
ADD COLUMN identity_counter_lower_bound INTEGER DEFAULT 0,
99
ADD COLUMN identity_counter_upper_bound INTEGER DEFAULT 0,
10-
ADD COLUMN selector TEXT NOT NULL DEFAULT '',
11-
ADD COLUMN timestamp_lower_bound TEXT,
12-
ADD COLUMN timestamp_upper_bound TEXT;
10+
ADD COLUMN selector INTEGER NOT NULL DEFAULT 0,
11+
ADD COLUMN timestamp_lower_bound TIMESTAMP,
12+
ADD COLUMN timestamp_upper_bound TIMESTAMP;
1313

1414
-- +migrate Down
1515
ALTER TABLE verify_users

internal/data/verify_users.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ type VerifyUsers struct {
2929
IdentityCounter int32 `db:"identity_counter"`
3030
IdentityCounterLowerBound int32 `db:"identity_counter_lower_bound"`
3131
IdentityCounterUpperBound int32 `db:"identity_counter_upper_bound"`
32-
Selector string `db:"selector"`
33-
TimestampLowerBound sql.NullString `db:"timestamp_lower_bound"`
34-
TimestampUpperBound sql.NullString `db:"timestamp_upper_bound"`
32+
Selector int32 `db:"selector"`
33+
TimestampLowerBound sql.NullTime `db:"timestamp_lower_bound"`
34+
TimestampUpperBound sql.NullTime `db:"timestamp_upper_bound"`
3535
}
3636

3737
type VerifyUsersQ interface {

internal/service/handlers/helpers/proof_params_v2.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package helpers
22

33
import (
4+
"strconv"
5+
46
"github.com/rarimo/verificator-svc/internal/data"
57
"github.com/rarimo/verificator-svc/resources"
68
)
@@ -28,12 +30,12 @@ func BuildV2ProofParams(user *data.VerifyUsers, callbackURL string) resources.Pr
2830

2931
timestampLowerBound := "0"
3032
if user.TimestampLowerBound.Valid {
31-
timestampLowerBound = user.TimestampLowerBound.String
33+
timestampLowerBound = strconv.FormatInt(user.TimestampLowerBound.Time.Unix(), 10)
3234
}
3335

3436
timestampUpperBound := "0"
3537
if user.TimestampUpperBound.Valid {
36-
timestampUpperBound = user.TimestampUpperBound.String
38+
timestampUpperBound = strconv.FormatInt(user.TimestampUpperBound.Time.Unix(), 10)
3739
}
3840

3941
return resources.ProofParamsAttributes{
@@ -47,7 +49,7 @@ func BuildV2ProofParams(user *data.VerifyUsers, callbackURL string) resources.Pr
4749
IdentityCounter: user.IdentityCounter,
4850
IdentityCounterLowerBound: user.IdentityCounterLowerBound,
4951
IdentityCounterUpperBound: user.IdentityCounterUpperBound,
50-
Selector: user.Selector,
52+
Selector: strconv.FormatInt(int64(user.Selector), 10),
5153
TimestampLowerBound: timestampLowerBound,
5254
TimestampUpperBound: timestampUpperBound,
5355
CallbackUrl: &callbackURL,

internal/service/handlers/proof_params.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func GetProofParamsById(w http.ResponseWriter, r *http.Request) {
3636
callbackURL := fmt.Sprintf("%s/integrations/verificator-svc/public/callback/%s", ctx.Callback(r).URL, userIDHash)
3737

3838
// check if selector is not empty to use v2 params
39-
if existingUser.Selector != "" {
39+
if existingUser.Selector > 0 {
4040
proofParameters := helpers.BuildV2ProofParams(existingUser, callbackURL)
4141
ape.Render(w, responses.NewProofParamsByIdResponse(*existingUser, proofParameters))
4242
return

internal/service/handlers/proof_params_light.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func GetProofParamsLightById(w http.ResponseWriter, r *http.Request) {
3636
callbackURL := fmt.Sprintf("%s/integrations/verificator-svc/light/public/callback-sign/%s", ctx.Callback(r).URL, userIDHash)
3737

3838
// check if selector is not empty - use v2 params
39-
if existingUser.Selector != "" {
39+
if existingUser.Selector > 0 {
4040
proofParameters := helpers.BuildV2ProofParams(existingUser, callbackURL)
4141
ape.Render(w, responses.NewProofParamsByIdResponse(*existingUser, proofParameters))
4242
return

internal/service/handlers/verification_link_v2.go

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,26 +52,14 @@ func VerificationLinkV2(w http.ResponseWriter, r *http.Request) {
5252
}
5353

5454
// base v1
55-
if req.Data.Attributes.Nationality != nil {
56-
user.Nationality = *req.Data.Attributes.Nationality
55+
if req.Data.Attributes.CitizenshipMask != nil {
56+
user.Nationality = *req.Data.Attributes.CitizenshipMask
5757
}
5858

5959
if req.Data.Attributes.AgeLowerBound != nil {
6060
user.AgeLowerBound = int(*req.Data.Attributes.AgeLowerBound)
6161
}
6262

63-
if req.Data.Attributes.Uniqueness != nil {
64-
user.Uniqueness = *req.Data.Attributes.Uniqueness
65-
}
66-
67-
if req.Data.Attributes.Sex != nil {
68-
user.SexEnable = *req.Data.Attributes.Sex
69-
}
70-
71-
if req.Data.Attributes.NationalityCheck != nil {
72-
user.NationalityEnable = *req.Data.Attributes.NationalityCheck
73-
}
74-
7563
if req.Data.Attributes.ExpirationLowerBound != nil {
7664
user.ExpirationLowerBound = helpers.GetExpirationLowerBound(*req.Data.Attributes.ExpirationLowerBound)
7765
}
@@ -107,11 +95,11 @@ func VerificationLinkV2(w http.ResponseWriter, r *http.Request) {
10795
}
10896

10997
if req.Data.Attributes.TimestampLowerBound != nil {
110-
user.TimestampLowerBound = sql.NullString{String: *req.Data.Attributes.TimestampLowerBound, Valid: true}
98+
user.TimestampLowerBound = sql.NullTime{Time: time.Unix(*req.Data.Attributes.TimestampLowerBound, 0), Valid: true}
11199
}
112100

113101
if req.Data.Attributes.TimestampUpperBound != nil {
114-
user.TimestampUpperBound = sql.NullString{String: *req.Data.Attributes.TimestampUpperBound, Valid: true}
102+
user.TimestampUpperBound = sql.NullTime{Time: time.Unix(*req.Data.Attributes.TimestampUpperBound, 0), Valid: true}
115103
}
116104

117105
dbUser, err := ctx.VerifyUsersQ(r).Upsert(user)

internal/service/requests/verification_link_v2.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ func VerificationLinkV2(r *http.Request) (req resources.AdvancedVerificationRequ
2727
"data/attributes/selector": val.Validate(req.Data.Attributes.Selector, val.Required),
2828
// base v1
2929
"data/attributes/age_lower_bound": val.Validate(req.Data.Attributes.AgeLowerBound, val.NilOrNotEmpty),
30-
"data/attributes/uniqueness": val.Validate(req.Data.Attributes.Uniqueness, val.NilOrNotEmpty),
31-
"data/attributes/nationality": val.Validate(req.Data.Attributes.Nationality, val.NilOrNotEmpty),
32-
"data/attributes/nationality_check": val.Validate(req.Data.Attributes.NationalityCheck, val.NilOrNotEmpty),
33-
"data/attributes/sex": val.Validate(req.Data.Attributes.Sex, val.NilOrNotEmpty),
30+
"data/attributes/citezenship_mask": val.Validate(req.Data.Attributes.CitizenshipMask, val.NilOrNotEmpty),
3431
"data/attributes/expiration_lower_bound": val.Validate(req.Data.Attributes.ExpirationLowerBound, val.NilOrNotEmpty),
3532
// advanced v2
3633
"data/attributes/identity_counter": val.Validate(req.Data.Attributes.IdentityCounter, val.NilOrNotEmpty, val.Min(0)),

resources/model_advanced_verification_attributes.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ type AdvancedVerificationAttributes struct {
1111
BirthDateLowerBound *string `json:"birth_date_lower_bound,omitempty"`
1212
// Birth date upper bound in hex format
1313
BirthDateUpperBound *string `json:"birth_date_upper_bound,omitempty"`
14+
// User citezenship mask
15+
CitizenshipMask *string `json:"citizenship_mask,omitempty"`
1416
// Event data in hex format
1517
EventData *string `json:"event_data,omitempty"`
1618
// Event ID
@@ -27,18 +29,10 @@ type AdvancedVerificationAttributes struct {
2729
IdentityCounterLowerBound *int32 `json:"identity_counter_lower_bound,omitempty"`
2830
// Identity counter upper bound
2931
IdentityCounterUpperBound *int32 `json:"identity_counter_upper_bound,omitempty"`
30-
// User nationality
31-
Nationality *string `json:"nationality,omitempty"`
32-
// Enable nationality verification
33-
NationalityCheck *bool `json:"nationality_check,omitempty"`
3432
// Selector value
35-
Selector string `json:"selector"`
36-
// Enable verification of sex param
37-
Sex *bool `json:"sex,omitempty"`
33+
Selector int32 `json:"selector"`
3834
// Timestamp lower bound
39-
TimestampLowerBound *string `json:"timestamp_lower_bound,omitempty"`
35+
TimestampLowerBound *int64 `json:"timestamp_lower_bound,omitempty"`
4036
// Timestamp upper bound
41-
TimestampUpperBound *string `json:"timestamp_upper_bound,omitempty"`
42-
// Parameters for checking user uniqueness
43-
Uniqueness *bool `json:"uniqueness,omitempty"`
37+
TimestampUpperBound *int64 `json:"timestamp_upper_bound,omitempty"`
4438
}

0 commit comments

Comments
 (0)