Skip to content

Commit

Permalink
Merge pull request #1 from rarimo/feature/claims-revocation
Browse files Browse the repository at this point in the history
Claims revocation
  • Loading branch information
ivanlele authored Feb 14, 2024
2 parents fe8583d + 8b44c1d commit bb9e5a7
Show file tree
Hide file tree
Showing 16 changed files with 385 additions and 61 deletions.
1 change: 1 addition & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ verifier:

issuer:
base_url: "http://localhost:3002/v1"
did: ""
auth_username: ""
auth_password: ""
claim_type: "VotingCredential"
Expand Down
3 changes: 3 additions & 0 deletions docs/spec/components/schemas/Claim.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ allOf:
type: object
required:
- claim_id
- issuer_did
properties:
claim_id:
type: string
issuer_did:
type: string
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/alecthomas/kingpin v2.2.6+incompatible
github.com/fatih/structs v1.1.0
github.com/go-chi/chi v4.1.2+incompatible
github.com/google/uuid v1.3.0
github.com/iden3/go-iden3-crypto v0.0.15
github.com/iden3/go-rapidsnark/types v0.0.3
github.com/iden3/go-rapidsnark/verifier v0.0.5
Expand Down
13 changes: 13 additions & 0 deletions internal/assets/migrations/002_claims.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- +migrate Up
alter table proofs add column claim_id uuid;

create table claims(
id uuid primary key,
user_did text not null,
issuer_did text not null,
document text not null unique
);

-- +migrate Down
alter table proofs drop column claim_id;
drop table claims;
1 change: 1 addition & 0 deletions internal/config/issuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type IssuerConfig struct {
BaseUrl string `fig:"base_url,required"`
AuthUsername string `fig:"auth_username,required"`
AuthPassword string `fig:"auth_password,required"`
DID string `fig:"did,required"`
ClaimType string `fig:"claim_type,required"`
CredentialSchema string `fig:"credential_schema,required"`
}
Expand Down
20 changes: 20 additions & 0 deletions internal/data/claims.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package data

import "github.com/google/uuid"

type ClaimQ interface {
New() ClaimQ
Insert(value Claim) error
FilterBy(column string, value any) ClaimQ
Get() (*Claim, error)
DeleteByID(id uuid.UUID) error
ForUpdate() ClaimQ
ResetFilter() ClaimQ
}

type Claim struct {
ID uuid.UUID `db:"id" structs:"id"`
UserDID string `db:"user_did" structs:"user_did"`
IssuerDID string `db:"issuer_did" structs:"issuer_did"`
Document string `db:"document" structs:"document"`
}
10 changes: 10 additions & 0 deletions internal/data/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package data

type MasterQ interface {
New() MasterQ

Proof() ProofQ
Claim() ClaimQ

Transaction(fn func(db MasterQ) error) error
}
74 changes: 74 additions & 0 deletions internal/data/pg/claims.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package pg

import (
"database/sql"
sq "github.com/Masterminds/squirrel"
"github.com/fatih/structs"
"github.com/google/uuid"
"github.com/rarimo/passport-identity-provider/internal/data"
"gitlab.com/distributed_lab/kit/pgdb"
)

const claimsTableName = "claims"

var (
claimsSelector = sq.Select("*").From(claimsTableName)
claimsUpdate = sq.Update(claimsTableName)
)

func NewClaimsQ(db *pgdb.DB) data.ClaimQ {
return &claimsQ{
db: db,
sql: claimsSelector,
upd: claimsUpdate,
}
}

type claimsQ struct {
db *pgdb.DB
sql sq.SelectBuilder
upd sq.UpdateBuilder
}

func (q *claimsQ) New() data.ClaimQ {
return NewClaimsQ(q.db.Clone())
}

func (q *claimsQ) Insert(value data.Claim) error {
clauses := structs.Map(value)
stmt := sq.Insert(claimsTableName).SetMap(clauses)
err := q.db.Exec(stmt)
return err
}

func (q *claimsQ) FilterBy(column string, value any) data.ClaimQ {
q.sql = q.sql.Where(sq.Eq{column: value})
return q
}

func (q *claimsQ) Get() (*data.Claim, error) {
var result data.Claim
err := q.db.Get(&result, q.sql)
if err == sql.ErrNoRows {
return nil, nil
}
return &result, err
}

func (q *claimsQ) DeleteByID(id uuid.UUID) error {
if err := q.db.Exec(sq.Delete(claimsTableName).Where(sq.Eq{"id": id})); err != nil {
return err
}
return nil
}

func (q *claimsQ) ForUpdate() data.ClaimQ {
q.sql = q.sql.Suffix("FOR UPDATE")
return q
}

func (q *claimsQ) ResetFilter() data.ClaimQ {
q.sql = sq.Select("*").From(claimsTableName)
q.upd = sq.Update(claimsTableName)
return q
}
34 changes: 34 additions & 0 deletions internal/data/pg/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package pg

import (
"github.com/rarimo/passport-identity-provider/internal/data"
"gitlab.com/distributed_lab/kit/pgdb"
)

func NewMasterQ(db *pgdb.DB) data.MasterQ {
return &masterQ{
db: db.Clone(),
}
}

type masterQ struct {
db *pgdb.DB
}

func (m *masterQ) New() data.MasterQ {
return NewMasterQ(m.db)
}

func (m *masterQ) Transaction(fn func(q data.MasterQ) error) error {
return m.db.Transaction(func() error {
return fn(m)
})
}

func (m *masterQ) Proof() data.ProofQ {
return NewProofsQ(m.db)
}

func (m *masterQ) Claim() data.ClaimQ {
return NewClaimsQ(m.db)
}
6 changes: 5 additions & 1 deletion internal/data/proofs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package data

import "encoding/json"
import (
"encoding/json"
"github.com/google/uuid"
)

type ProofQ interface {
New() ProofQ
Expand All @@ -10,6 +13,7 @@ type ProofQ interface {
type Proof struct {
ID int64 `db:"id" structs:"-"`
DID string `db:"did" structs:"did"`
ClaimID uuid.UUID `db:"claim_id" structs:"claim_id"`
Data json.RawMessage `db:"data" structs:"data"`
PubSignals json.RawMessage `db:"pub_signals" structs:"pub_signals"`
DocumentSOD json.RawMessage `db:"document_sod" structs:"document_sod"`
Expand Down
Loading

0 comments on commit bb9e5a7

Please sign in to comment.