Skip to content

Commit

Permalink
Implement contract-related logic. Major register logic overhaul. Impr…
Browse files Browse the repository at this point in the history
…ove register handler's optimization
  • Loading branch information
J3imip committed Dec 13, 2024
1 parent 76fa5ee commit 6f031da
Show file tree
Hide file tree
Showing 16 changed files with 19,929 additions and 16,517 deletions.
9 changes: 9 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ verifier:
disableTimeChecks: false
disableNameChecks: false

addresses:
registration_contract: 8B8b14B6bD955eCc96bee1D83a3Eba21B80A0E91
verifiers:
sha1: 50f07F4E66Cc7A09186120B6e0152602768923ac
sha224: b83D5fd8A498482b123EE1837B86B82CCd33240D
sha256: 91E3d9ef73afC08E083719e8CF052c1d810aF191
sha384: Abf2Fef1aF4ca7cB7EB3F4F2169D55C502E086aD
sha512: b7609357EAEA80C8a064Aa7B9Ff1D7E7b76fDB98

log:
level: debug
disable_sentry: true
Expand Down
25 changes: 18 additions & 7 deletions docs/spec/components/schemas/Signature.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,25 @@ allOf:
attributes:
type: object
required:
- passport_hash
- public_key
- verifier
- signature
- document_hash
properties:
signature:
passport_hash:
type: string
example: 0x7768792064696420796F75206576656E206465636F6465642069743F
description: Poseidon hash of truncated signed attributes
public_key:
type: string
example: 7768792064696420796F75206576656E206465636F6465642069743F
description: ECDSA signature of the document hash
document_hash:
example: 0x7768792064696420796F75206576656E206465636F6465642069743F
description: Public key parsed from dg15. Omitted (empty string) if passport has no dg15
verifier:
type: string
format: common.Address
example: 0x7768792064696420796F75206576656E206465636F6465642069743F
description: Verifier contract address
signature:
type: string
example: 7768792064696420796F75206576656E206465636F6465642069743F
description: Poseidon hash of the document
example: 0x7768792064696420796F75206576656E206465636F6465642069743F
description: ECDSA signature of the abi encoded signed data
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ go 1.21.6
require (
github.com/Masterminds/squirrel v1.5.4
github.com/alecthomas/kingpin v2.2.6+incompatible
github.com/ethereum/go-ethereum v1.13.14
github.com/fatih/structs v1.1.0
github.com/go-chi/chi v4.1.2+incompatible
github.com/go-ozzo/ozzo-validation/v4 v4.3.0
github.com/google/jsonapi v0.0.0-20200226002910-c8283f632fb7
github.com/hashicorp/vault/api v1.15.0
github.com/iden3/go-iden3-crypto v0.0.17
github.com/iden3/go-rapidsnark/types v0.0.3
Expand Down Expand Up @@ -36,14 +38,12 @@ require (
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/ethereum/c-kzg-4844 v0.4.0 // indirect
github.com/ethereum/go-ethereum v1.13.14 // 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
github.com/go-gorp/gorp/v3 v3.1.0 // indirect
github.com/go-jose/go-jose/v4 v4.0.1 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
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/errwrap v1.1.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1543,6 +1543,8 @@ github.com/google/go-pkcs11 v0.2.1-0.20230907215043-c6f79328ddf9/go.mod h1:6eQoG
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/jsonapi v0.0.0-20200226002910-c8283f632fb7 h1:aQ4kMXDAmP9IRIZHcSKB2orXHGwGiSxH4PX1BzKHR50=
github.com/google/jsonapi v0.0.0-20200226002910-c8283f632fb7/go.mod h1:XSx4m2SziAqk9DXY9nz659easTq4q6TyrpYd9tHSm0g=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
Expand Down
59 changes: 59 additions & 0 deletions internal/config/addresses.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package config

import (
"github.com/ethereum/go-ethereum/common"
"github.com/rarimo/passport-identity-provider/internal/types"
"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 AddressesConfiger interface {
AddressesConfig() AddressesConfig
}

func NewAddressesConfiger(getter kv.Getter) AddressesConfiger {
return &Addresses{
getter: getter,
}
}

type Addresses struct {
addressesOnce comfig.Once
getter kv.Getter
}

type AddressesConfig struct {
RegistrationContract *common.Address
Verifiers map[types.HashAlgorithm]*common.Address
}

func (e *Addresses) AddressesConfig() AddressesConfig {
return e.addressesOnce.Do(func() interface{} {
newCfg := struct {
RegistrationContract *common.Address `fig:"registration_contract,required"`
Verifiers map[string]string `fig:"verifiers,required"`
}{}

err := figure.
Out(&newCfg).
With(figure.BaseHooks, figure.EthereumHooks).
From(kv.MustGetStringMap(e.getter, "addresses")).
Please()
if err != nil {
panic(errors.Wrap(err, "failed to figure out addresses config"))
}

addresses := make(map[types.HashAlgorithm]*common.Address)
for algo, address := range newCfg.Verifiers {
address := common.HexToAddress(address)
addresses[types.HashAlgorithmFromString(algo)] = &address
}

return AddressesConfig{
RegistrationContract: newCfg.RegistrationContract,
Verifiers: addresses,
}
}).(AddressesConfig)
}
17 changes: 10 additions & 7 deletions internal/config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Config interface {

VerifierConfiger
KeysConfiger
AddressesConfiger
}

type config struct {
Expand All @@ -27,16 +28,18 @@ type config struct {

VerifierConfiger
KeysConfiger
AddressesConfiger
}

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{}),
VerifierConfiger: NewVerifierConfiger(getter),
KeysConfiger: NewKeysConfiger(getter),
getter: getter,
Databaser: pgdb.NewDatabaser(getter),
Copuser: copus.NewCopuser(getter),
Listenerer: comfig.NewListenerer(getter),
Logger: comfig.NewLogger(getter, comfig.LoggerOpts{}),
VerifierConfiger: NewVerifierConfiger(getter),
KeysConfiger: NewKeysConfiger(getter),
AddressesConfiger: NewAddressesConfiger(getter),
}
}
8 changes: 6 additions & 2 deletions internal/config/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"os"

"github.com/rarimo/certificate-transparency-go/x509"
"github.com/rarimo/passport-identity-provider/internal/types"
"gitlab.com/distributed_lab/figure/v3"
"gitlab.com/distributed_lab/kit/comfig"
Expand All @@ -15,7 +16,7 @@ type VerifierConfiger interface {

type VerifierConfig struct {
VerificationKeys map[types.HashAlgorithm][]byte
MasterCerts []byte
MasterCerts *x509.CertPool
DisableTimeChecks bool
DisableNameChecks bool
}
Expand Down Expand Up @@ -64,9 +65,12 @@ func (v *verifier) VerifierConfig() *VerifierConfig {
panic(err)
}

roots := x509.NewCertPool()
roots.AppendCertsFromPEM(masterCerts)

return &VerifierConfig{
VerificationKeys: verificationKeys,
MasterCerts: masterCerts,
MasterCerts: roots,
DisableTimeChecks: newCfg.DisableTimeChecks,
DisableNameChecks: newCfg.DisableNameChecks,
}
Expand Down
11 changes: 11 additions & 0 deletions internal/service/api/ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (
verifierConfigKey
documentSODQKey
keysConfigKey
addressesConfigKey
)

func CtxLog(entry *logan.Entry) func(context.Context) context.Context {
Expand Down Expand Up @@ -57,3 +58,13 @@ func CtxKeysConfig(entry config.KeysConfig) func(context.Context) context.Contex
func KeysConfig(r *http.Request) config.KeysConfig {
return r.Context().Value(keysConfigKey).(config.KeysConfig)
}

func CtxAddressesConfig(entry config.AddressesConfig) func(context.Context) context.Context {
return func(ctx context.Context) context.Context {
return context.WithValue(ctx, addressesConfigKey, entry)
}
}

func AddressesConfig(r *http.Request) config.AddressesConfig {
return r.Context().Value(addressesConfigKey).(config.AddressesConfig)
}
Loading

0 comments on commit 6f031da

Please sign in to comment.