Skip to content

Commit

Permalink
Merge pull request #37 from rarimo/feature/join-program-protection
Browse files Browse the repository at this point in the history
Feature: join program protection
  • Loading branch information
violog authored Jun 21, 2024
2 parents 2bc16ab + 20c9432 commit 1970264
Show file tree
Hide file tree
Showing 19 changed files with 224 additions and 178 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,15 @@ func AuthMiddleware(auth *auth.Client, log *logan.Entry) func(http.Handler) http
```
and in handlers/verify_passport:
```go
// never panics because of request validation
// proof.PubSignals[zk.Nullifier] = mustHexToInt(nullifier)
// err = Verifier(r).VerifyProof(*proof)
// if err != nil {
// return nil, problems.BadRequest(err)
// }
// err = Verifier(r).VerifyProof(*proof)
// if err != nil {
// if errors.Is(err, identity.ErrContractCall) {
// Log(r).WithError(err).Error("Failed to verify proof")
// return nil, append(errs, problems.InternalError())
// }
// return nil, problems.BadRequest(err)
// }
```
and in handlers/withdraw(lines 49-58):
```go
Expand Down
1 change: 1 addition & 0 deletions config-testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ levels:
withdrawal_allowed: true

countries:
verification_key: "37bc75afc97f8bdcd21cda85ae7b2885b5f1205ae3d79942e56457230f1636a037cc7ebfe42998d66a3dd3446b9d29366271b4f2bd8e0d307db1d320b38fc02f"
countries:
- code: "UKR"
reserve_limit: 100000
Expand Down
16 changes: 14 additions & 2 deletions docs/spec/components/schemas/VerifyPassport.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,22 @@ allOf:
properties:
attributes:
required:
- proof
- anonymous_id
- country
type: object
properties:
anonymous_id:
type: string
description: Unique identifier of the passport.
example: "2bd3a2532096fee10a45a40e444a11b4d00a707f3459376087747de05996fbf5"
country:
type: string
description: |
ISO 3166-1 alpha-3 country code, must match the one provided in `proof`.
example: "UKR"
proof:
type: object
format: types.ZKProof
description: Iden3 ZK passport verification proof.
description: |
Query ZK passport verification proof.
Required for endpoint `/v2/balances/{nullifier}/verifypassport`.
2 changes: 1 addition & 1 deletion docs/spec/components/schemas/Withdraw.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ allOf:
proof:
type: object
format: types.ZKProof
description: Iden3 ZK passport verification proof.
description: Query ZK passport verification proof.
2 changes: 1 addition & 1 deletion docs/spec/openapi.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
openapi: 3.0.0
info:
version: 1.0.0
version: 1.2.0
title: rarime-points-svc
description: ''
servers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ post:
operationId: joinRewardsProgram
parameters:
- $ref: '#/components/parameters/pathNullifier'
- in: header
name: Signature
description: Signature of the request
required: true
schema:
type: string
pattern: '^[a-f0-9]{64}$'
requestBody:
required: true
content:
Expand All @@ -16,7 +23,7 @@ post:
- data
properties:
data:
$ref: '#/components/schemas/JoinProgram'
$ref: '#/components/schemas/VerifyPassport'
responses:
200:
description: Success
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@ post:
- Points balance
summary: Verify passport
description: |
Fulfill verify passport event if it is open
Verify passport with ZKP, fulfilling the event.
One passport can't be verified twice.
operationId: verifyPassport
parameters:
- $ref: '#/components/parameters/pathNullifier'
- in: header
name: Signature
description: Signature of the request
required: true
schema:
type: string
pattern: '^[a-f0-9]{64}$'
requestBody:
required: true
content:
Expand Down
5 changes: 5 additions & 0 deletions internal/assets/migrations/004_anonymous_id.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- +migrate Up
ALTER TABLE balances ADD COLUMN anonymous_id text UNIQUE;

-- +migrate Down
ALTER TABLE balances DROP COLUMN anonymous_id;
11 changes: 7 additions & 4 deletions internal/data/balances.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
)

const (
ColAmount = "amount"
ColLevel = "level"
ColCountry = "country"
ColIsPassport = "is_passport_proven"
ColAmount = "amount"
ColLevel = "level"
ColCountry = "country"
ColIsPassport = "is_passport_proven"
ColAnonymousID = "anonymous_id"
)

type Balance struct {
Expand All @@ -23,6 +24,7 @@ type Balance struct {
Level int `db:"level"`
Country *string `db:"country"`
IsPassportProven bool `db:"is_passport_proven"`
AnonymousID *string `db:"anonymous_id"`
}

type BalancesQ interface {
Expand All @@ -45,6 +47,7 @@ type BalancesQ interface {

FilterByNullifier(...string) BalancesQ
FilterDisabled() BalancesQ
FilterByAnonymousID(id string) BalancesQ
}

type WithoutPassportEventBalance struct {
Expand Down
4 changes: 4 additions & 0 deletions internal/data/pg/balances.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ func (q *balances) FilterDisabled() data.BalancesQ {
return q.applyCondition(squirrel.NotEq{"referred_by": nil})
}

func (q *balances) FilterByAnonymousID(id string) data.BalancesQ {
return q.applyCondition(squirrel.Eq{"anonymous_id": id})
}

func (q *balances) applyCondition(cond squirrel.Sqlizer) data.BalancesQ {
q.selector = q.selector.Where(cond)
q.updater = q.updater.Where(cond)
Expand Down
77 changes: 0 additions & 77 deletions internal/service/handlers/join_program.go

This file was deleted.

Loading

0 comments on commit 1970264

Please sign in to comment.