Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set proof verifications params in handler, add callaback and proof-pa… #2

Merged
merged 8 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.19.7-alpine as buildbase
FROM golang:1.22-alpine as buildbase

RUN apk add git build-base ca-certificates

Expand All @@ -15,5 +15,7 @@ COPY --from=alpine:3.9 /lib /lib

COPY --from=buildbase /usr/local/bin/geo-forms-svc /usr/local/bin/verificator-svc
COPY --from=buildbase /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=buildbase /go/src/github.com/rarimo/verificator-svc/proof_keys/passport.json /proof_keys/passport.json


ENTRYPOINT ["verificator-svc"]
9 changes: 8 additions & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,15 @@ cop:
service_name: verificator-svc
service_port: 80

callback:
url: "http://localhost:8000"

proof_parameters:
event_id: "event_id"
timestamp_upper_bound: "19000000000"

verifier:
allowed_age: 18
verification_key_path: "./proof_keys/passport.json"
allowed_identity_timestamp: 1715698750

poseidonsmt_root_verifier:
Expand Down
24 changes: 7 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
module github.com/rarimo/verificator-svc

go 1.22

toolchain go1.22.6
go 1.22.0

require (
github.com/Masterminds/squirrel v1.5.4
github.com/alecthomas/kingpin v2.2.6+incompatible
github.com/fatih/structs v1.1.0
github.com/ethereum/go-ethereum v1.10.25
github.com/go-chi/chi v4.1.2+incompatible
github.com/go-ozzo/ozzo-validation/v4 v4.3.0
github.com/iden3/go-iden3-crypto v0.0.15
github.com/iden3/go-rapidsnark/types v0.0.3
github.com/pkg/errors v0.9.1
github.com/rarimo/zkverifier-kit v1.2.1
github.com/rubenv/sql-migrate v1.7.0
github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4
gitlab.com/distributed_lab/ape v1.7.1
gitlab.com/distributed_lab/figure/v3 v3.1.4
gitlab.com/distributed_lab/kit v1.11.3
gitlab.com/distributed_lab/logan v3.8.1+incompatible
gitlab.com/distributed_lab/urlval/v4 v4.0.3
)

require (
Expand All @@ -25,11 +28,8 @@ require (
github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/certifi/gocertifi v0.0.0-20200211180108-c7c1fbc02894 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/deckarep/golang-set v1.8.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/ethereum/go-ethereum v1.10.25 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/getsentry/raven-go v0.2.0 // indirect
github.com/getsentry/sentry-go v0.27.0 // indirect
Expand All @@ -39,23 +39,17 @@ require (
github.com/google/jsonapi v0.0.0-20200226002910-c8283f632fb7 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/iden3/go-iden3-crypto v0.0.15 // indirect
github.com/iden3/go-rapidsnark/verifier v0.0.5 // indirect
github.com/jmoiron/sqlx v1.3.5 // indirect
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/rarimo/zkverifier-kit v1.2.0 // indirect
github.com/rjeczalik/notify v0.9.1 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/rs/cors v1.8.3 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
Expand All @@ -65,16 +59,12 @@ require (
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.18.2 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
github.com/tklauser/go-sysconf v0.3.11 // indirect
github.com/tklauser/numcpus v0.6.0 // indirect
gitlab.com/distributed_lab/figure v2.1.2+incompatible // indirect
gitlab.com/distributed_lab/figure/v3 v3.1.4 // indirect
gitlab.com/distributed_lab/lorem v0.2.0 // indirect
gitlab.com/distributed_lab/running v1.6.0 // indirect
gitlab.com/distributed_lab/urlval/v4 v4.0.3 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 // indirect
Expand Down
7 changes: 6 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,9 @@ github.com/census-instrumentation/opencensus-proto v0.3.0/go.mod h1:f6KPmirojxKA
github.com/census-instrumentation/opencensus-proto v0.4.1/go.mod h1:4T9NM4+4Vw91VeyqjLS6ao50K5bOcLKN6Q42XnYaRYw=
github.com/certifi/gocertifi v0.0.0-20200211180108-c7c1fbc02894 h1:JLaf/iINcLyjwbtTsCJjc6rtlASgHeIJPrB6QmwURnA=
github.com/certifi/gocertifi v0.0.0-20200211180108-c7c1fbc02894/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA=
github.com/cespare/cp v0.1.0 h1:SE+dxFebS7Iik5LK0tsi1k9ZCxEaFX4AjQmoyA+1dJk=
github.com/cespare/cp v0.1.0/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s=
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
Expand Down Expand Up @@ -1263,6 +1265,7 @@ github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8Nz
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
Expand Down Expand Up @@ -1333,7 +1336,6 @@ github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/fatih/color v1.14.1/go.mod h1:2oHN61fhTpgcxD3TSWCgKDiH1+x4OiDVVGH8WlgGZGg=
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/fjl/gencodec v0.0.0-20220412091415-8bb9e558978c/go.mod h1:AzA8Lj6YtixmJWL+wkKoBGsLWy9gFrAzi4g+5bCKwpY=
github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 h1:FtmdgXiUlNeRsoNMFlKLDt+S+6hbjVMEW6RGQ7aUf7c=
Expand Down Expand Up @@ -1709,6 +1711,7 @@ github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 h1:SOEGU9fKiNWd/HOJuq
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0/go.mod h1:dXGbAdH5GtBTC4WfIxhKZfyBF/HBFgRZSWwZ9g/He9o=
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 h1:P6pPBnrTSX3DEVR4fDembhRWSsG5rVo6hYhAB/ADZrk=
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0/go.mod h1:vmVJ0l/dxyfGW6FmdpVm2joNMFikkuWg0EoCKLGUMNw=
github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c=
github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8=
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
Expand Down Expand Up @@ -1902,6 +1905,8 @@ github.com/prometheus/tsdb v0.7.1 h1:YZcsG11NqnK4czYLrWd9mpEuAJIHVQLwdrleYfszMAA
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/rarimo/zkverifier-kit v1.2.0 h1:Qsdcq+jMBEkdTlbqGT7InQhNI39lZyCX9PXgqzb1ozM=
github.com/rarimo/zkverifier-kit v1.2.0/go.mod h1:3YDg5dTkDRr4IdfaDHGYetopd6gS/2SuwSeseYTWwNw=
github.com/rarimo/zkverifier-kit v1.2.1 h1:sO6qgm6OBm+sBD53g3/xxo9WSvQoz1RiXsH+/jRw/X8=
github.com/rarimo/zkverifier-kit v1.2.1/go.mod h1:3YDg5dTkDRr4IdfaDHGYetopd6gS/2SuwSeseYTWwNw=
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/retailnext/hllpp v1.0.1-0.20180308014038-101a6d2f8b52/go.mod h1:RDpi1RftBQPUCDRw6SmxeaREsAaRKnOclghuzp/WRzc=
Expand Down
11 changes: 7 additions & 4 deletions internal/assets/migrations/001_initial.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

CREATE TABLE verify_users
(
user_id TEXT PRIMARY KEY NOT NULL,
user_id_hash TEXT NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT (NOW() AT TIME ZONE 'utc'),
status BOOLEAN NOT NULL
user_id TEXT PRIMARY KEY NOT NULL,
user_id_hash TEXT NOT NULL,
age_lower_bound INT NOT NULL,
nationality TEXT NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT (NOW() AT TIME ZONE 'utc'),
uniqueness BOOLEAN NOT NULL,
status TEXT NOT NULL
);

-- +migrate Down
Expand Down
43 changes: 43 additions & 0 deletions internal/config/callback.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package config

import (
"gitlab.com/distributed_lab/figure/v3"
"gitlab.com/distributed_lab/kit/comfig"
"gitlab.com/distributed_lab/kit/kv"
"gitlab.com/distributed_lab/logan/v3/errors"
)

type CallbackConfiger interface {
CallbackConfig() CallbackConfig
}

type CallbackConfig struct {
URL string `fig:"url,required"`
}

type Callback struct {
once comfig.Once
getter kv.Getter
}

func NewCallbackConfiger(getter kv.Getter) CallbackConfiger {
return &Callback{
getter: getter,
}
}

func (p *Callback) CallbackConfig() CallbackConfig {
return p.once.Do(func() interface{} {
var cfg CallbackConfig
err := figure.
Out(&cfg).
With(figure.BaseHooks).
From(kv.MustGetStringMap(p.getter, "callback")).
Please()

if err != nil {
panic(errors.Wrap(err, "failed to figure out callback"))
}
return cfg
}).(CallbackConfig)
}
21 changes: 14 additions & 7 deletions internal/config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ type Config interface {
pgdb.Databaser
types.Copuser
comfig.Listenerer
CallbackConfiger
ProofParametersConfiger
Verifiers() Verifiers
}

Expand All @@ -22,18 +24,23 @@ type config struct {
pgdb.Databaser
types.Copuser
comfig.Listenerer
getter kv.Getter
getter kv.Getter
CallbackConfiger
ProofParametersConfiger

verifier comfig.Once
passport root.VerifierProvider
}

func New(getter kv.Getter) Config {
return &config{
getter: getter,
Databaser: pgdb.NewDatabaser(getter),
Copuser: copus.NewCopuser(getter),
Listenerer: comfig.NewListenerer(getter),
Logger: comfig.NewLogger(getter, comfig.LoggerOpts{}),
passport: root.NewVerifierProvider(getter, root.PoseidonSMT),
getter: getter,
Databaser: pgdb.NewDatabaser(getter),
Copuser: copus.NewCopuser(getter),
Listenerer: comfig.NewListenerer(getter),
Logger: comfig.NewLogger(getter, comfig.LoggerOpts{}),
CallbackConfiger: NewCallbackConfiger(getter),
passport: root.NewVerifierProvider(getter, root.PoseidonSMT),
ProofParametersConfiger: NewProofParametersConfiger(getter),
}
}
44 changes: 44 additions & 0 deletions internal/config/proof_parameters.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package config

import (
"gitlab.com/distributed_lab/figure/v3"
"gitlab.com/distributed_lab/kit/comfig"
"gitlab.com/distributed_lab/kit/kv"
"gitlab.com/distributed_lab/logan/v3/errors"
)

type ProofParametersConfiger interface {
ProofParametersConfig() ProofParametersConfig
}

type ProofParametersConfig struct {
EventID string `fig:"event_id,required"`
TimestampUpperBound string `fig:"timestamp_upper_bound,required"`
}

type ProofParameters struct {
once comfig.Once
getter kv.Getter
}

func NewProofParametersConfiger(getter kv.Getter) ProofParametersConfiger {
return &ProofParameters{
getter: getter,
}
}

func (p *ProofParameters) ProofParametersConfig() ProofParametersConfig {
return p.once.Do(func() interface{} {
var cfg ProofParametersConfig
err := figure.
Out(&cfg).
With(figure.BaseHooks).
From(kv.MustGetStringMap(p.getter, "proof_parameters")).
Please()

if err != nil {
panic(errors.Wrap(err, "failed to figure out proof_parameters"))
}
return cfg
}).(ProofParametersConfig)
}
24 changes: 6 additions & 18 deletions internal/config/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,21 @@ package config

import (
"fmt"

zk "github.com/rarimo/zkverifier-kit"
"gitlab.com/distributed_lab/figure/v3"
"gitlab.com/distributed_lab/kit/kv"
)

const (
proofEventIDValue = "111186066134341633902189494613533900917417361106374681011849132651019822199"
proofSelectorValue = "236065"
maxIdentityCount = 1
documentTypeID = "ID"
passportVerificationKey = "./proof_keys/passport.json"
)

type Verifiers struct {
Passport *zk.Verifier
}

func (c *config) Verifiers() Verifiers {
return c.verifier.Do(func() interface{} {
var cfg struct {
AllowedAge int `fig:"allowed_age,required"`
AllowedIdentityTimestamp int64 `fig:"allowed_identity_timestamp,required"`
VerificationKeyPath string `fig:"verification_key_path,required"`
AllowedIdentityTimestamp int64 `fig:"allowed_identity_timestamp,required"`
}

err := figure.
Expand All @@ -35,16 +28,11 @@ func (c *config) Verifiers() Verifiers {
}

pass, err := zk.NewVerifier(nil,
zk.WithProofType(zk.GeorgianPassport),
zk.WithCitizenships("GEO"),
zk.WithVerificationKeyFile(passportVerificationKey),
zk.WithAgeAbove(cfg.AllowedAge),
zk.WithProofType(zk.GlobalPassport),
zk.WithVerificationKeyFile(cfg.VerificationKeyPath),
zk.WithPassportRootVerifier(c.passport.ProvideVerifier()),
zk.WithProofSelectorValue(proofSelectorValue),
zk.WithEventID(proofEventIDValue),
zk.WithIdentitiesCounter(maxIdentityCount),
zk.WithIdentitiesCreationTimestampLimit(cfg.AllowedIdentityTimestamp),
zk.WithDocumentType(documentTypeID),
zk.WithEventID(c.ProofParametersConfig().EventID),
)
if err != nil {
panic(fmt.Errorf("failed to initialize passport verifier: %w", err))
Expand Down
9 changes: 6 additions & 3 deletions internal/data/pg/verify_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,12 @@ func (q *VerifyUsersQ) Get() (*data.VerifyUsers, error) {

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,
"status": VerifyUsers.Status,
"user_id": VerifyUsers.UserID,
"user_id_hash": VerifyUsers.UserIDHash,
"age_lower_bound": VerifyUsers.AgeLowerBound,
"nationality": VerifyUsers.Nationality,
"uniqueness": VerifyUsers.Uniqueness,
"status": VerifyUsers.Status,
})

if err := q.db.Exec(stmt); err != nil {
Expand Down
11 changes: 7 additions & 4 deletions internal/data/verify_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import (
)

type VerifyUsers struct {
UserID string `db:"user_id"`
UserIdHash string `db:"user_id_hash"`
CreatedAt time.Time `db:"created_at"`
Status string `db:"status"`
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"`
Status string `db:"status"`
}

type VerifyUsersQ interface {
Expand Down
Loading
Loading