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

Feature/poll event #22

Merged
merged 6 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
9 changes: 6 additions & 3 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,16 @@ auth:
addr: http://rarime-auth

verifier:
verification_key_path: "./verification_key.json"
allowed_age: 18
allowed_identity_timestamp: 1715698750

root_verifier:
poseidonsmt_root_verifier:
rpc: evm_rpc_url
contract: poseidon_smt_contract_address
request_timeout: 10s

proposalsmt_root_verifier:
rpc: evm_rpc_url
contract: registration_contract_address
request_timeout: 10s

sig_verifier:
Expand Down
9 changes: 9 additions & 0 deletions docs/spec/components/schemas/EventStaticMeta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,12 @@ properties:
format: int
description: Number of uses. Only available to the administrator.
example: 1002
poll_event_id:
type: string
description: Decimal value of the Event ID
example: "123456789987654321"
poll_contract:
type: string
description: Hex voting contract address with 0x.
example: "0x123...123"
pattern: '^0x[0-9a-fA-F]{40}$'
18 changes: 18 additions & 0 deletions docs/spec/components/schemas/FulfillPollEvent.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
allOf:
- $ref: '#/components/schemas/FulfillPollEventKey'
- type: object
x-go-is-request: true
required:
- attributes
properties:
attributes:
required:
- proof
type: object
properties:
proof:
type: object
format: types.ZKProof
description: |
Proof of voting in some poll.
The poll ID must be equal to `meta.static.poll_id` from the event.
12 changes: 12 additions & 0 deletions docs/spec/components/schemas/FulfillPollEventKey.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
type: object
required:
- id
- type
properties:
id:
type: string
description: Event ID
example: "059c81dd-2a54-44a8-8142-c15ad8f88949"
type:
type: string
enum: [ fulfill_poll_event ]
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ get:
- $ref: '#/components/parameters/pageLimit'
- $ref: '#/components/parameters/pageNumber'
- $ref: '#/components/parameters/pageOrder'
- in: query
name: count
description: Count total number of users.
required: false
schema:
type: boolean
example: true
responses:
200:
description: Success
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ put:
summary: Update event type
description: |
Update an existing event type. Requires **admin** role in JWT.
**All attributes** are updated, ensure to pass every existing field too.
**All attributes** except QR code, Poll Event ID and Poll Contract are
updated, ensure to pass every existing field too.
Although this is not JSON:API compliant, it is much easier to work with
in Go, because differentiating between `{}` and `{"field": null}`
requires custom unmarshalling implementation.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
patch:
tags:
- Events
summary: Fulfill poll event
description: Fulfill event for voting in Georgian poll by sending proof of voting
operationId: fulfillPollEvent
parameters:
- in: path
name: 'id'
required: true
schema:
type: string
example: "059c81dd-2a54-44a8-8142-c15ad8f88949"
requestBody:
required: true
content:
application/vnd.api+json:
schema:
type: object
required:
- data
properties:
data:
$ref: '#/components/schemas/FulfillPollEvent'
responses:
200:
description: Success
content:
application/vnd.api+json:
schema:
type: object
required:
- data
properties:
data:
$ref: '#/components/schemas/EventClaimingState'
400:
$ref: '#/components/responses/invalidParameter'
401:
$ref: '#/components/responses/invalidAuth'
403:
description: This event type was disabled and cannot be fulfilled
content:
application/vnd.api+json:
schema:
$ref: '#/components/schemas/Errors'
404:
$ref: '#/components/responses/notFound'
500:
$ref: '#/components/responses/internalError'
6 changes: 1 addition & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ require (
github.com/go-ozzo/ozzo-validation/v4 v4.3.0
github.com/google/jsonapi v1.0.0
github.com/iden3/go-rapidsnark/types v0.0.3
github.com/labstack/gommon v0.4.0
github.com/rarimo/geo-auth-svc v1.1.0
github.com/rarimo/saver-grpc-lib v1.0.0
github.com/rarimo/zkverifier-kit v1.1.1
github.com/rarimo/zkverifier-kit v1.1.2-0.20240724050048-459caa155ec1
github.com/rubenv/sql-migrate v1.6.1
gitlab.com/distributed_lab/ape v1.7.1
gitlab.com/distributed_lab/figure/v3 v3.1.4
Expand Down Expand Up @@ -105,7 +104,6 @@ require (
github.com/lib/pq v1.10.9 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mimoo/StrobeGo v0.0.0-20210601165009-122bf33a46e0 // indirect
Expand Down Expand Up @@ -146,8 +144,6 @@ require (
github.com/tendermint/tm-db v0.6.7 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/zondax/hid v0.9.1 // indirect
github.com/zondax/ledger-go v0.14.1 // indirect
gitlab.com/distributed_lab/figure v2.1.2+incompatible // indirect
Expand Down
11 changes: 2 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1879,7 +1879,6 @@ github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+
github.com/labstack/echo/v4 v4.2.1/go.mod h1:AA49e0DZ8kk5jTOOCKNuPR6oTnBS0dYiM4FW1e6jwpg=
github.com/labstack/echo/v4 v4.10.0/go.mod h1:S/T/5fy/GigaXnHTkh0ZGe4LpkkQysvRjFMSUTkDRNQ=
github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k=
github.com/labstack/gommon v0.4.0 h1:y7cvthEAEbU0yHOf4axH8ZG2NH8knB9iNSoTO8dyIk8=
github.com/labstack/gommon v0.4.0/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM=
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 h1:SOEGU9fKiNWd/HOJuq6+3iTQz8KNCLtVX6idSoTLdUw=
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0/go.mod h1:dXGbAdH5GtBTC4WfIxhKZfyBF/HBFgRZSWwZ9g/He9o=
Expand Down Expand Up @@ -2114,16 +2113,12 @@ github.com/rarimo/broadcaster-svc v1.0.2 h1:ExQcjjWCRP5+POLDlZHrTD1ffUsBH+Dgv5FA
github.com/rarimo/broadcaster-svc v1.0.2/go.mod h1:lYIHy+X4IqQt4eBdtMN/V352H3EV0/gO8G+32SFwUWI=
github.com/rarimo/cosmos-sdk v0.46.7 h1:jU2PiWzc+19SF02cXM0O0puKPeH1C6Q6t2lzJ9s1ejc=
github.com/rarimo/cosmos-sdk v0.46.7/go.mod h1:fqKqz39U5IlEFb4nbQ72951myztsDzFKKDtffYJ63nk=
github.com/rarimo/geo-auth-svc v0.2.0 h1:yQvcIBNx+Tc1jJdtpWDfyLc0HogU+okA08HEZ55wv5U=
github.com/rarimo/geo-auth-svc v0.2.0/go.mod h1:SB4bo1xHYDAsBaQGX2+FoEgD3xxqYmcgr4XTTjy4/OM=
github.com/rarimo/geo-auth-svc v1.1.0 h1:3k1tTWAjtCBsnzlMb3aB+xgsFLEPUSmB3woME+q6tfk=
github.com/rarimo/geo-auth-svc v1.1.0/go.mod h1:JrpCGdT0xtAcWIKgPhxPHf7QCW4h845BXuh6M7NdQFw=
github.com/rarimo/saver-grpc-lib v1.0.0 h1:MGUVjYg7unmodYczVsLqlqZNkT4CIgKqdo6aQtL1qdE=
github.com/rarimo/saver-grpc-lib v1.0.0/go.mod h1:DpugWK5B7Hi0bdC3MPe/9FD2zCxaRwsyykdwxtF1Zgg=
github.com/rarimo/zkverifier-kit v1.1.0-rc.1 h1:xtmrFEl7eLAE6mi7IQYOOMKFdwXC3gbe39fYQdvKVZg=
github.com/rarimo/zkverifier-kit v1.1.0-rc.1/go.mod h1:3YDg5dTkDRr4IdfaDHGYetopd6gS/2SuwSeseYTWwNw=
github.com/rarimo/zkverifier-kit v1.1.1 h1:jy4/i52sWgWD9JJQtAKiLufOZefgTsuZ8bO7Hxdkb+s=
github.com/rarimo/zkverifier-kit v1.1.1/go.mod h1:3YDg5dTkDRr4IdfaDHGYetopd6gS/2SuwSeseYTWwNw=
github.com/rarimo/zkverifier-kit v1.1.2-0.20240724050048-459caa155ec1 h1:49sGqP0W4oGoU8kegYK1A1pb7B0deEw1bwz0qogXxvs=
github.com/rarimo/zkverifier-kit v1.1.2-0.20240724050048-459caa155ec1/go.mod h1:3YDg5dTkDRr4IdfaDHGYetopd6gS/2SuwSeseYTWwNw=
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM=
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/regen-network/cosmos-proto v0.3.1 h1:rV7iM4SSFAagvy8RiyhiACbWEGotmqzywPxOvwMdxcg=
Expand Down Expand Up @@ -2287,12 +2282,10 @@ github.com/urfave/cli/v2 v2.10.2/go.mod h1:f8iq5LtQ/bLxafbdBSLPPNsgaW0l/2fYYEHhA
github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs=
github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.40.0/go.mod h1:t/G+3rLek+CyY9bnIE+YlMRddxVAAGjhxndDB4i4C0I=
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc=
Expand Down
7 changes: 7 additions & 0 deletions internal/assets/migrations/002_poll_event_types.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- +migrate Up
ALTER TABLE event_types ADD COLUMN poll_event_id TEXT;
ALTER TABLE event_types ADD COLUMN poll_contract TEXT;

-- +migrate Down
ALTER TABLE event_types DROP COLUMN poll_event_id;
ALTER TABLE event_types DROP COLUMN poll_contract;
12 changes: 7 additions & 5 deletions internal/config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import (
"github.com/rarimo/geo-auth-svc/pkg/hmacsig"
"github.com/rarimo/geo-points-svc/internal/data/evtypes"
"github.com/rarimo/saver-grpc-lib/broadcaster"
zk "github.com/rarimo/zkverifier-kit"
"github.com/rarimo/zkverifier-kit/identity"
"github.com/rarimo/zkverifier-kit/root"
"gitlab.com/distributed_lab/kit/comfig"
"gitlab.com/distributed_lab/kit/kv"
"gitlab.com/distributed_lab/kit/pgdb"
Expand All @@ -22,7 +21,7 @@ type Config interface {
hmacsig.SigCalculatorProvider

Levels() Levels
Verifier() *zk.Verifier
Verifiers() Verifiers
}

type config struct {
Expand All @@ -31,10 +30,12 @@ type config struct {
comfig.Listenerer
auth.Auther
broadcaster.Broadcasterer
identity.VerifierProvider
evtypes.EventTypeser
hmacsig.SigCalculatorProvider

passport root.VerifierProvider
poll root.VerifierProvider

levels comfig.Once
verifier comfig.Once
getter kv.Getter
Expand All @@ -48,7 +49,8 @@ func New(getter kv.Getter) Config {
Logger: comfig.NewLogger(getter, comfig.LoggerOpts{}),
Auther: auth.NewAuther(getter), //nolint:misspell
Broadcasterer: broadcaster.New(getter),
VerifierProvider: identity.NewVerifierProvider(getter),
passport: root.NewVerifierProvider(getter, root.PoseidonSMT),
poll: root.NewVerifierProvider(getter, root.ProposalSMT),
EventTypeser: evtypes.NewConfig(getter),
SigCalculatorProvider: hmacsig.NewCalculatorProvider(getter),
}
Expand Down
51 changes: 36 additions & 15 deletions internal/config/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,31 @@ import (
"fmt"

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

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

func (c *config) Verifier() *zk.Verifier {
type Verifiers struct {
Passport *zk.Verifier
Poll *zk.Verifier
PollRoot *root.ProposalSMTVerifier
}

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

err := figure.
Expand All @@ -31,23 +39,36 @@ func (c *config) Verifier() *zk.Verifier {
panic(fmt.Errorf("failed to figure out verifier: %w", err))
}

v, err := zk.NewVerifier(nil,
zk.WithCitizenships("GEO"),
pass, err := zk.NewVerifier(nil,
zk.WithProofType(zk.GeorgianPassport),
zk.WithVerificationKeyFile(cfg.VerificationKeyPath),
zk.WithCitizenships("GEO"),
zk.WithVerificationKeyFile(passportVerificationKey),
zk.WithAgeAbove(cfg.AllowedAge),
zk.WithIdentityVerifier(c.ProvideVerifier()),
zk.WithPassportRootVerifier(c.passport.ProvideVerifier()),
zk.WithProofSelectorValue(proofSelectorValue),
zk.WithEventID(proofEventIDValue),
zk.WithIdentitiesCounter(maxIdentityCount),
zk.WithIdentitiesCreationTimestampLimit(cfg.AllowedIdentityTimestamp),
zk.WithDocumentType(documentTypeID),
)

if err != nil {
panic(fmt.Errorf("failed to initialize passport verifier: %w", err))
}

return v
}).(*zk.Verifier)
poll, err := zk.NewVerifier(nil,
zk.WithProofType(zk.PollParticipation),
zk.WithEventID(proofEventIDValue),
zk.WithVerificationKeyFile(pollVerificationKey))
if err != nil {
panic(fmt.Errorf("failed to initialize poll verifier: %w", err))
}

rv := c.poll.ProvideVerifier().(*root.ProposalSMTVerifier)

return Verifiers{
Passport: pass,
Poll: poll,
PollRoot: rv,
}
}).(Verifiers)
}
2 changes: 2 additions & 0 deletions internal/data/balances.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type BalancesQ interface {
WithoutPassportEvent() ([]WithoutPassportEventBalance, error)
WithoutReferralEvent() ([]ReferredReferrer, error)

Count() (int64, error)

FilterByNullifier(...string) BalancesQ
FilterDisabled() BalancesQ
FilterByAnonymousID(id string) BalancesQ
Expand Down
9 changes: 7 additions & 2 deletions internal/data/evtypes/models/event_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ type EventType struct {
Disabled bool `fig:"disabled" db:"disabled"`
ActionURL *string `fig:"action_url" db:"action_url"`
Logo *string `fig:"logo" db:"logo"`
QRCodeValue *string `fig:"qr_code_value" db:"qr_code_value"`
QRCodeValue *string `db:"qr_code_value"`
PollEventID *string `db:"poll_event_id"`
PollContract *string `db:"poll_contract"`
}

func ResourceToModel(r resources.EventStaticMeta) EventType {
Expand All @@ -42,6 +44,8 @@ func ResourceToModel(r resources.EventStaticMeta) EventType {
ActionURL: r.ActionUrl,
Logo: r.Logo,
QRCodeValue: r.QrCodeValue,
PollEventID: r.PollEventId,
PollContract: r.PollContract,
}
}

Expand Down Expand Up @@ -74,6 +78,8 @@ func (e EventType) Resource(locale string) resources.EventStaticMeta {
Disabled: e.Disabled,
Logo: e.Logo,
Flag: e.Flag(),
PollEventId: e.PollEventID,
PollContract: e.PollContract,
}
}

Expand All @@ -90,7 +96,6 @@ func (e EventType) ForUpdate() map[string]any {
"disabled": e.Disabled,
"action_url": e.ActionURL,
"logo": e.Logo,
"qr_code_value": e.QRCodeValue,
Zaptoss marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
Loading
Loading