Skip to content

Commit 8f3d371

Browse files
Merge pull request #39 from rarimo/fix/callback-get-user
Add support of v2 verification with custom event_data in callback end…
2 parents 5491767 + 8cc11bf commit 8f3d371

4 files changed

Lines changed: 33 additions & 11 deletions

File tree

Dockerfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
FROM golang:1.22.0-alpine as buildbase
1+
FROM golang:1.23.0-alpine as buildbase
22

33
ARG CI_JOB_TOKEN
44

55
RUN apk add git build-base ca-certificates
66

77
WORKDIR /go/src/github.com/rarimo/verificator-svc
8-
COPY . .
8+
COPY go.mod .
9+
COPY go.sum .
10+
RUN go mod download
911

1012
RUN git config --global url."https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com".insteadOf https://gitlab.com
1113
RUN git config --global url."https://${CI_JOB_TOKEN}@github.com/".insteadOf https://github.com/
@@ -24,4 +26,4 @@ COPY --from=buildbase /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
2426
COPY --from=buildbase /go/src/github.com/rarimo/verificator-svc/proof_keys/passport.json /proof_keys/passport.json
2527

2628

27-
ENTRYPOINT ["verificator-svc"]
29+
ENTRYPOINT ["verificator-svc"]

internal/data/pg/verify_users.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,12 @@ func (q *VerifyUsersQ) FilterByNullifier(nullifier string) data.VerifyUsersQ {
175175
q.sel = q.sel.Where(sq.Eq{"nullifier": nullifier})
176176
return q
177177
}
178+
179+
func (q *VerifyUsersQ) FilterByEventData(eventData string) data.VerifyUsersQ {
180+
q.sel = q.sel.Where(sq.And{
181+
sq.Eq{"event_data": eventData},
182+
sq.NotEq{"event_data": ""},
183+
sq.Expr("event_data IS NOT NULL"),
184+
})
185+
return q
186+
}

internal/data/verify_users.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,5 @@ type VerifyUsersQ interface {
4949
WhereCreatedAtLt(createdAt time.Time) VerifyUsersQ
5050
FilterByInternalAID(aid string) VerifyUsersQ
5151
FilterByNullifier(nullifier string) VerifyUsersQ
52+
FilterByEventData(eventData string) VerifyUsersQ
5253
}

internal/service/handlers/verification_callback.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,27 +78,37 @@ func VerificationCallback(w http.ResponseWriter, r *http.Request) {
7878
nullifier.FillBytes(nullifierBytes[:])
7979
nullifierHex := hex.EncodeToString(nullifierBytes[:])
8080

81-
userIDHash, err := helpers.ExtractEventData(getter)
81+
eventDataFromProof, err := helpers.ExtractEventData(getter)
8282
if err != nil {
83-
ctx.Log(r).WithError(err).Errorf("failed to extract user hash from event data")
83+
ctx.Log(r).WithError(err).Errorf("failed to extract event data")
8484
ape.RenderErr(w, problems.BadRequest(validation.Errors{
8585
"pub_signals/event_data": err,
8686
})...)
8787
return
8888
}
8989

90-
verifiedUser, err := ctx.VerifyUsersQ(r).WhereHashID(userIDHash).Get()
90+
verifiedUser, err := ctx.VerifyUsersQ(r).FilterByEventData(eventDataFromProof).Get()
9191
if err != nil {
92-
ctx.Log(r).WithError(err).Errorf("failed to get user with userHashID [%s]", userIDHash)
93-
ape.RenderErr(w, problems.BadRequest(err)...)
92+
ctx.Log(r).WithError(err).Error("failed to get user with event_data")
93+
ape.RenderErr(w, problems.InternalError())
9494
return
9595
}
96+
97+
if verifiedUser == nil {
98+
verifiedUser, err = ctx.VerifyUsersQ(r).WhereHashID(eventDataFromProof).Get()
99+
if err != nil {
100+
ctx.Log(r).WithError(err).Error("failed to get user with user_id_hash")
101+
ape.RenderErr(w, problems.InternalError())
102+
return
103+
}
104+
}
105+
96106
if verifiedUser == nil {
97107
ctx.Log(r).WithFields(logan.F{
98108
"event_data": getter.Get(zk.EventData),
99-
"user_id_hash": userIDHash,
109+
"user_id_hash": eventDataFromProof,
100110
"id": req.Data.ID,
101-
}).Error("user not found or eventData != userHashID")
111+
}).Error("user not found")
102112
ape.RenderErr(w, problems.NotFound())
103113
return
104114
}
@@ -169,7 +179,7 @@ func VerificationCallback(w http.ResponseWriter, r *http.Request) {
169179
"service_timestamp": ctx.Verifiers(r).ServiceStartTimestamp,
170180
"identity_timestamp_upper_bound": identityTimestampUpperBound,
171181
"identity_counter_upper_bound": identityCounterUpperBound,
172-
"user_id_hash": userIDHash,
182+
"user_id_hash": eventDataFromProof,
173183
}).Errorf("failed to check uniqueness")
174184
verifiedUser.Status = "uniqueness_check_failed"
175185
}

0 commit comments

Comments
 (0)