Skip to content

Commit

Permalink
chore: ethereum identities (#505)
Browse files Browse the repository at this point in the history
* chore: add eth identities

* chore: remove topup endpoint

* chore: improvements

* chore: improve api spec

* chore: update tests
  • Loading branch information
martinsaporiti authored Oct 17, 2023
1 parent 54c52c1 commit 150c5c6
Show file tree
Hide file tree
Showing 49 changed files with 2,244 additions and 757 deletions.
1 change: 1 addition & 0 deletions .env-api.sample
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ ISSUER_API_UI_SCHEMA_CACHE=false
ISSUER_API_IDENTITY_METHOD=polygonid
ISSUER_API_IDENTITY_BLOCKCHAIN=polygon
ISSUER_API_IDENTITY_NETWORK=mumbai
ISSUER_API_KEY_TYPE=BJJ
ISSUER_API_ENVIRONMENT=local
4 changes: 3 additions & 1 deletion .env-issuer.sample
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ ISSUER_ETHEREUM_RPC_RESPONSE_TIMEOUT=5s
ISSUER_ETHEREUM_WAIT_RECEIPT_CYCLE_TIME=30s
ISSUER_ETHEREUM_WAIT_BLOCK_CYCLE_TIME=30s
ISSUER_ETHEREUM_RESOLVER_PREFIX=polygon:mumbai
ISSUER_ETHEREUM_INTERNAL_TRANSFER_AMOUNT_WEI=1000000000000000000
ISSUER_ETHEREUM_TRANSFER_ACCOUNT_KEY_PATH=pbkey

ISSUER_PROVER_SERVER_URL=http://localhost:8002
ISSUER_PROVER_TIMEOUT=600s
ISSUER_CIRCUIT_PATH=./pkg/credentials/circuits
Expand All @@ -35,4 +38,3 @@ ISSUER_SCHEMA_CACHE=false

ISSUER_VAULT_USERPASS_AUTH_ENABLED=false
ISSUER_VAULT_USERPASS_AUTH_PASSWORD=password

2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ linters-settings:
gofumpt:
lang-version: "1.18"
gocognit:
min-complexity: 38
min-complexity: 40
gocyclo:
min-complexity: 35
revive:
Expand Down
50 changes: 50 additions & 0 deletions api/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,30 @@ paths:
'500':
$ref: '#/components/responses/500'

/v1/identities/{identifier}/details:
get:
summary: Identity Detail
operationId: GetIdentityDetails
description: Endpoint to get an identity details
tags:
- Identity
security:
- basicAuth: [ ]
parameters:
- $ref: '#/components/parameters/pathIdentifier'
responses:
'200':
description: Identity top up successfully
content:
application/json:
schema:
$ref: '#/components/schemas/GetIdentityDetailsResponse'
'400':
$ref: '#/components/responses/400'
'401':
$ref: '#/components/responses/401'
'500':
$ref: '#/components/responses/500'

/v1/{identifier}/state/retry:
post:
Expand Down Expand Up @@ -480,6 +504,7 @@ components:
- method
- blockchain
- network
- type
properties:
method:
type: string
Expand All @@ -493,6 +518,12 @@ components:
type: string
x-omitempty: false
example: "mumbai"
type:
type: string
x-omitempty: false
example: "BJJ"
enum: [BJJ, ETH]


CreateIdentityResponse:
type: object
Expand All @@ -504,6 +535,25 @@ components:
type: string
state:
$ref: '#/components/schemas/IdentityState'
address:
type: string
x-omitempty: false

GetIdentityDetailsResponse:
type: object
required:
- identity
- status
properties:
identifier:
type: string
state:
$ref: '#/components/schemas/IdentityState'
address:
type: string
balance:
type: string


IdentityState:
type: object
Expand Down
21 changes: 19 additions & 2 deletions cmd/issuer_initializer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import (
"time"

vault "github.com/hashicorp/vault/api"
core "github.com/iden3/go-iden3-core/v2"

"github.com/polygonid/sh-id-platform/internal/buildinfo"
"github.com/polygonid/sh-id-platform/internal/config"
"github.com/polygonid/sh-id-platform/internal/core/ports"
"github.com/polygonid/sh-id-platform/internal/core/services"
"github.com/polygonid/sh-id-platform/internal/db"
"github.com/polygonid/sh-id-platform/internal/kms"
Expand Down Expand Up @@ -99,9 +101,24 @@ func main() {

// services initialization
mtService := services.NewIdentityMerkleTrees(mtRepository)
identityService := services.NewIdentity(keyStore, identityRepository, mtRepository, identityStateRepository, mtService, nil, claimsRepository, nil, nil, storage, nil, nil, nil, pubsub.NewMock())

identity, err := identityService.Create(ctx, cfg.APIUI.IdentityMethod, cfg.APIUI.IdentityBlockchain, cfg.APIUI.IdentityNetwork, cfg.ServerUrl)
revocationSettings := services.CredentialRevocationSettings{
RHSEnabled: cfg.ReverseHashService.Enabled,
RHSUrl: cfg.ReverseHashService.URL,
Host: cfg.ServerUrl,
AgentIden3Enabled: false,
}

identityService := services.NewIdentity(keyStore, identityRepository, mtRepository, identityStateRepository, mtService, nil, claimsRepository, nil, nil, storage, nil, nil, nil, pubsub.NewMock(), revocationSettings)

didCreationOptions := &ports.DIDCreationOptions{
Method: core.DIDMethod(cfg.APIUI.IdentityMethod),
Network: core.NetworkID(cfg.APIUI.IdentityNetwork),
Blockchain: core.Blockchain(cfg.APIUI.IdentityBlockchain),
KeyType: kms.KeyType(cfg.APIUI.KeyType),
}

identity, err := identityService.Create(ctx, cfg.ServerUrl, didCreationOptions)
if err != nil {
log.Error(ctx, "error creating identifier", err)
return
Expand Down
12 changes: 10 additions & 2 deletions cmd/notifications/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,16 @@ func newCredentialsService(cfg *config.Configuration, storage *db.Storage, cache

mtService := services.NewIdentityMerkleTrees(mtRepository)
qrService := services.NewQrStoreService(cachex)
identityService := services.NewIdentity(keyStore, identityRepository, mtRepository, identityStateRepository, mtService, qrService, claimsRepository, revocationRepository, nil, storage, rhsp, nil, nil, ps)
claimsService := services.NewClaim(claimsRepository, identityService, qrService, mtService, identityStateRepository, schemaLoader, storage, services.ClaimCfg{

revocationSettings := services.CredentialRevocationSettings{
RHSEnabled: cfg.ReverseHashService.Enabled,
RHSUrl: cfg.ReverseHashService.URL,
Host: cfg.ServerUrl,
AgentIden3Enabled: false,
}

identityService := services.NewIdentity(keyStore, identityRepository, mtRepository, identityStateRepository, mtService, qrService, claimsRepository, revocationRepository, nil, storage, rhsp, nil, nil, ps, revocationSettings)
claimsService := services.NewClaim(claimsRepository, identityService, qrService, mtService, identityStateRepository, schemaLoader, storage, services.CredentialRevocationSettings{
RHSEnabled: cfg.ReverseHashService.Enabled,
RHSUrl: cfg.ReverseHashService.URL,
Host: cfg.ServerUrl,
Expand Down
16 changes: 13 additions & 3 deletions cmd/pending_publisher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,18 @@ func main() {

rhsp := reverse_hash.NewRhsPublisher(nil, false)
connectionsRepository := repositories.NewConnections()
identityService := services.NewIdentity(keyStore, identityRepo, mtRepo, identityStateRepo, mtService, qrService, claimsRepo, revocationRepository, connectionsRepository, storage, rhsp, nil, nil, pubsub.NewMock())
claimsService := services.NewClaim(claimsRepo, identityService, qrService, mtService, identityStateRepo, schemaLoader, storage, services.ClaimCfg{

// TODO: Review this
revocationSettings := services.CredentialRevocationSettings{
RHSEnabled: cfg.ReverseHashService.Enabled,
RHSUrl: cfg.ReverseHashService.URL,
Host: cfg.ServerUrl,
AgentIden3Enabled: false,
AgentIden3URL: "",
}

identityService := services.NewIdentity(keyStore, identityRepo, mtRepo, identityStateRepo, mtService, qrService, claimsRepo, revocationRepository, connectionsRepository, storage, rhsp, nil, nil, pubsub.NewMock(), revocationSettings)
claimsService := services.NewClaim(claimsRepo, identityService, qrService, mtService, identityStateRepo, schemaLoader, storage, services.CredentialRevocationSettings{
RHSEnabled: cfg.ReverseHashService.Enabled,
RHSUrl: cfg.ReverseHashService.URL,
Host: cfg.ServerUrl,
Expand All @@ -158,7 +168,7 @@ func main() {
RPCResponseTimeout: cfg.Ethereum.RPCResponseTimeout,
WaitReceiptCycleTime: cfg.Ethereum.WaitReceiptCycleTime,
WaitBlockCycleTime: cfg.Ethereum.WaitBlockCycleTime,
})
}, keyStore)

circuitsLoaderService := circuitLoaders.NewCircuits(cfg.Circuit.Path)
proofService := initProofService(ctx, cfg, circuitsLoaderService)
Expand Down
20 changes: 15 additions & 5 deletions cmd/platform/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func main() {
return
}

ethereumClient, err := blockchain.Open(cfg)
ethereumClient, err := blockchain.Open(cfg, keyStore)
if err != nil {
log.Error(ctx, "error dialing with ethereum client", "err", err)
return
Expand All @@ -113,7 +113,7 @@ func main() {
return
}

ethConn, err := blockchain.InitEthConnect(cfg.Ethereum)
ethConn, err := blockchain.InitEthConnect(cfg.Ethereum, keyStore)
if err != nil {
log.Error(ctx, "failed init ethereum connect", "err", err)
return
Expand All @@ -139,8 +139,17 @@ func main() {
// services initialization
mtService := services.NewIdentityMerkleTrees(mtRepository)
qrService := services.NewQrStoreService(cachex)
identityService := services.NewIdentity(keyStore, identityRepository, mtRepository, identityStateRepository, mtService, qrService, claimsRepository, revocationRepository, nil, storage, rhsp, nil, nil, ps)
claimsService := services.NewClaim(claimsRepository, identityService, qrService, mtService, identityStateRepository, schemaLoader, storage, services.ClaimCfg{

revocationSettings := services.CredentialRevocationSettings{
RHSEnabled: cfg.ReverseHashService.Enabled,
RHSUrl: cfg.ReverseHashService.URL,
Host: cfg.ServerUrl,
AgentIden3Enabled: false,
}

identityService := services.NewIdentity(keyStore, identityRepository, mtRepository, identityStateRepository, mtService, qrService, claimsRepository, revocationRepository, nil, storage, rhsp, nil, nil, ps, revocationSettings)

claimsService := services.NewClaim(claimsRepository, identityService, qrService, mtService, identityStateRepository, schemaLoader, storage, services.CredentialRevocationSettings{
RHSEnabled: cfg.ReverseHashService.Enabled,
RHSUrl: cfg.ReverseHashService.URL,
Host: cfg.ServerUrl,
Expand Down Expand Up @@ -168,6 +177,7 @@ func main() {
return
}

accountService := services.NewAccountService(cfg.Ethereum, keyStore)
serverHealth := health.New(health.Monitors{
"postgres": storage.Ping,
"redis": func(rdb *redis2.Client) health.Pinger {
Expand All @@ -186,7 +196,7 @@ func main() {
)
api.HandlerFromMux(
api.NewStrictHandlerWithOptions(
api.NewServer(cfg, identityService, claimsService, qrService, publisher, packageManager, serverHealth),
api.NewServer(cfg, identityService, accountService, claimsService, qrService, publisher, packageManager, serverHealth),
middlewares(ctx, cfg.HTTPBasicAuth),
api.StrictHTTPServerOptions{
RequestErrorHandlerFunc: errors.RequestErrorHandlerFunc,
Expand Down
16 changes: 12 additions & 4 deletions cmd/platform_ui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func main() {
return
}

ethereumClient, err := blockchain.Open(cfg)
ethereumClient, err := blockchain.Open(cfg, keyStore)
if err != nil {
log.Error(ctx, "error dialing with ethereum client", "err", err)
return
Expand All @@ -126,7 +126,7 @@ func main() {
return
}

ethConn, err := blockchain.InitEthConnect(cfg.Ethereum)
ethConn, err := blockchain.InitEthConnect(cfg.Ethereum, keyStore)
if err != nil {
log.Error(ctx, "failed init ethereum connect", "err", err)
return
Expand Down Expand Up @@ -171,9 +171,17 @@ func main() {
// services initialization
mtService := services.NewIdentityMerkleTrees(mtRepository)
qrService := services.NewQrStoreService(cachex)
identityService := services.NewIdentity(keyStore, identityRepository, mtRepository, identityStateRepository, mtService, qrService, claimsRepository, revocationRepository, connectionsRepository, storage, rhsp, verifier, sessionRepository, ps)

revocationSettings := services.CredentialRevocationSettings{
RHSEnabled: cfg.ReverseHashService.Enabled,
RHSUrl: cfg.ReverseHashService.URL,
Host: cfg.APIUI.ServerURL,
AgentIden3Enabled: false,
}

identityService := services.NewIdentity(keyStore, identityRepository, mtRepository, identityStateRepository, mtService, qrService, claimsRepository, revocationRepository, connectionsRepository, storage, rhsp, verifier, sessionRepository, ps, revocationSettings)
schemaService := services.NewSchema(schemaRepository, schemaLoader)
claimsService := services.NewClaim(claimsRepository, identityService, qrService, mtService, identityStateRepository, schemaLoader, storage, services.ClaimCfg{
claimsService := services.NewClaim(claimsRepository, identityService, qrService, mtService, identityStateRepository, schemaLoader, storage, services.CredentialRevocationSettings{
RHSEnabled: cfg.ReverseHashService.Enabled,
RHSUrl: cfg.ReverseHashService.URL,
Host: cfg.APIUI.ServerURL,
Expand Down
Loading

0 comments on commit 150c5c6

Please sign in to comment.