Skip to content

Commit

Permalink
chore: Update iden3 libraries to v2 (#494)
Browse files Browse the repository at this point in the history
* chore: Upgrade project dependencies and some small tweaks needed by changes in dependencies

* chore: Iden3 libraries upgraded to v2

* chore: go mod tidy
  • Loading branch information
x1m3 authored Oct 4, 2023
1 parent 14b3e3b commit 16ccdd6
Show file tree
Hide file tree
Showing 101 changed files with 1,281 additions and 1,221 deletions.
14 changes: 6 additions & 8 deletions cmd/notifications/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"syscall"

"github.com/hashicorp/vault/api"
"github.com/iden3/go-schema-processor/v2/loaders"
shell "github.com/ipfs/go-ipfs-api"

"github.com/polygonid/sh-id-platform/internal/buildinfo"
"github.com/polygonid/sh-id-platform/internal/config"
Expand All @@ -17,7 +19,6 @@ import (
"github.com/polygonid/sh-id-platform/internal/db"
"github.com/polygonid/sh-id-platform/internal/gateways"
"github.com/polygonid/sh-id-platform/internal/kms"
"github.com/polygonid/sh-id-platform/internal/loader"
"github.com/polygonid/sh-id-platform/internal/log"
"github.com/polygonid/sh-id-platform/internal/providers"
"github.com/polygonid/sh-id-platform/internal/redis"
Expand Down Expand Up @@ -121,12 +122,9 @@ func newCredentialsService(cfg *config.Configuration, storage *db.Storage, cache
}

rhsp := reverse_hash.NewRhsPublisher(nil, false)
var schemaLoader loader.Factory
if cfg.SchemaCache == nil || !*cfg.SchemaCache {
schemaLoader = loader.HTTPFactory
} else {
schemaLoader = loader.CachedFactory(loader.HTTPFactory, cachex)
}

// TODO: Cache only if cfg.APIUI.SchemaCache == true
schemaLoader := loaders.NewDocumentLoader(shell.NewShell(cfg.IPFS.GatewayURL), cfg.IPFS.GatewayURL)

mtService := services.NewIdentityMerkleTrees(mtRepository)
qrService := services.NewQrStoreService(cachex)
Expand All @@ -135,7 +133,7 @@ func newCredentialsService(cfg *config.Configuration, storage *db.Storage, cache
RHSEnabled: cfg.ReverseHashService.Enabled,
RHSUrl: cfg.ReverseHashService.URL,
Host: cfg.ServerUrl,
}, ps, cfg.IFPS.GatewayURL)
}, ps, cfg.IPFS.GatewayURL)

return claimsService, nil
}
18 changes: 8 additions & 10 deletions cmd/pending_publisher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/iden3/go-schema-processor/v2/loaders"
shell "github.com/ipfs/go-ipfs-api"

"github.com/polygonid/sh-id-platform/internal/buildinfo"
"github.com/polygonid/sh-id-platform/internal/config"
Expand All @@ -18,14 +20,13 @@ import (
"github.com/polygonid/sh-id-platform/internal/db"
"github.com/polygonid/sh-id-platform/internal/gateways"
"github.com/polygonid/sh-id-platform/internal/kms"
"github.com/polygonid/sh-id-platform/internal/loader"
"github.com/polygonid/sh-id-platform/internal/log"
"github.com/polygonid/sh-id-platform/internal/providers"
"github.com/polygonid/sh-id-platform/internal/redis"
"github.com/polygonid/sh-id-platform/internal/repositories"
"github.com/polygonid/sh-id-platform/pkg/blockchain/eth"
"github.com/polygonid/sh-id-platform/pkg/cache"
"github.com/polygonid/sh-id-platform/pkg/loaders"
circuitLoaders "github.com/polygonid/sh-id-platform/pkg/loaders"
"github.com/polygonid/sh-id-platform/pkg/pubsub"
"github.com/polygonid/sh-id-platform/pkg/reverse_hash"
)
Expand Down Expand Up @@ -72,11 +73,8 @@ func main() {
}
}(storage)

var schemaLoader loader.Factory
schemaLoader = loader.MultiProtocolFactory(cfg.IFPS.GatewayURL)
if cfg.APIUI.SchemaCache != nil && *cfg.APIUI.SchemaCache {
schemaLoader = loader.CachedFactory(schemaLoader, cachex)
}
// TODO: Cache only if cfg.APIUI.SchemaCache == true
schemaLoader := loaders.NewDocumentLoader(shell.NewShell(cfg.IPFS.GatewayURL), cfg.IPFS.GatewayURL)

vaultCli, err := providers.VaultClient(ctx, providers.Config{
UserPassAuthEnabled: cfg.VaultUserPassAuthEnabled,
Expand Down Expand Up @@ -135,7 +133,7 @@ func main() {
RHSEnabled: cfg.ReverseHashService.Enabled,
RHSUrl: cfg.ReverseHashService.URL,
Host: cfg.ServerUrl,
}, ps, cfg.IFPS.GatewayURL)
}, ps, cfg.IPFS.GatewayURL)

commonClient, err := ethclient.Dial(cfg.Ethereum.URL)
if err != nil {
Expand All @@ -154,7 +152,7 @@ func main() {
WaitBlockCycleTime: cfg.Ethereum.WaitBlockCycleTime,
})

circuitsLoaderService := loaders.NewCircuits(cfg.Circuit.Path)
circuitsLoaderService := circuitLoaders.NewCircuits(cfg.Circuit.Path)
proofService := initProofService(ctx, cfg, circuitsLoaderService)

transactionService, err := gateways.NewTransaction(cl, cfg.Ethereum.ConfirmationBlockCount)
Expand Down Expand Up @@ -190,7 +188,7 @@ func main() {
log.Info(ctx, "Finished")
}

func initProofService(ctx context.Context, config *config.Configuration, circuitLoaderService *loaders.Circuits) ports.ZKGenerator {
func initProofService(ctx context.Context, config *config.Configuration, circuitLoaderService *circuitLoaders.Circuits) ports.ZKGenerator {
log.Info(ctx, "native prover enabled", "enabled", config.NativeProofGenerationEnabled)
if config.NativeProofGenerationEnabled {
proverConfig := &services.NativeProverConfig{
Expand Down
17 changes: 8 additions & 9 deletions cmd/platform/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import (
chiMiddleware "github.com/go-chi/chi/v5/middleware"
"github.com/go-chi/cors"
redis2 "github.com/go-redis/redis/v8"
"github.com/iden3/go-schema-processor/v2/loaders"
proof "github.com/iden3/merkletree-proof"
shell "github.com/ipfs/go-ipfs-api"

"github.com/polygonid/sh-id-platform/internal/api"
"github.com/polygonid/sh-id-platform/internal/buildinfo"
Expand All @@ -24,14 +26,13 @@ import (
"github.com/polygonid/sh-id-platform/internal/gateways"
"github.com/polygonid/sh-id-platform/internal/health"
"github.com/polygonid/sh-id-platform/internal/kms"
"github.com/polygonid/sh-id-platform/internal/loader"
"github.com/polygonid/sh-id-platform/internal/log"
"github.com/polygonid/sh-id-platform/internal/providers"
"github.com/polygonid/sh-id-platform/internal/providers/blockchain"
"github.com/polygonid/sh-id-platform/internal/redis"
"github.com/polygonid/sh-id-platform/internal/repositories"
"github.com/polygonid/sh-id-platform/pkg/cache"
"github.com/polygonid/sh-id-platform/pkg/loaders"
circuitLoaders "github.com/polygonid/sh-id-platform/pkg/loaders"
"github.com/polygonid/sh-id-platform/pkg/protocol"
"github.com/polygonid/sh-id-platform/pkg/pubsub"
"github.com/polygonid/sh-id-platform/pkg/reverse_hash"
Expand Down Expand Up @@ -71,11 +72,9 @@ func main() {
ps := pubsub.NewRedis(rdb)
ps.WithLogger(log.Error)
cachex := cache.NewRedisCache(rdb)
var schemaLoader loader.Factory
schemaLoader = loader.MultiProtocolFactory(cfg.IFPS.GatewayURL)
if cfg.APIUI.SchemaCache != nil && *cfg.APIUI.SchemaCache {
schemaLoader = loader.CachedFactory(schemaLoader, cachex)
}

// TODO: Cache only if cfg.APIUI.SchemaCache == true
schemaLoader := loaders.NewDocumentLoader(shell.NewShell(cfg.IPFS.GatewayURL), cfg.IPFS.GatewayURL)

vaultCli, err := providers.VaultClient(ctx, providers.Config{
UserPassAuthEnabled: cfg.VaultUserPassAuthEnabled,
Expand Down Expand Up @@ -112,7 +111,7 @@ func main() {
return
}

circuitsLoaderService := loaders.NewCircuits(cfg.Circuit.Path)
circuitsLoaderService := circuitLoaders.NewCircuits(cfg.Circuit.Path)

rhsp := reverse_hash.NewRhsPublisher(nil, false)
if cfg.ReverseHashService.Enabled {
Expand All @@ -137,7 +136,7 @@ func main() {
RHSEnabled: cfg.ReverseHashService.Enabled,
RHSUrl: cfg.ReverseHashService.URL,
Host: cfg.ServerUrl,
}, ps, cfg.IFPS.GatewayURL)
}, ps, cfg.IPFS.GatewayURL)
proofService := gateways.NewProver(ctx, cfg, circuitsLoaderService)
revocationService := services.NewRevocationService(ethConn, common.HexToAddress(cfg.Ethereum.ContractAddress))
zkProofService := services.NewProofService(claimsService, revocationService, identityService, mtService, claimsRepository, keyStore, storage, stateContract, schemaLoader)
Expand Down
35 changes: 17 additions & 18 deletions cmd/platform_ui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import (
chiMiddleware "github.com/go-chi/chi/v5/middleware"
"github.com/go-chi/cors"
redis2 "github.com/go-redis/redis/v8"
auth "github.com/iden3/go-iden3-auth"
authLoaders "github.com/iden3/go-iden3-auth/loaders"
"github.com/iden3/go-iden3-auth/pubsignals"
"github.com/iden3/go-iden3-auth/state"
core "github.com/iden3/go-iden3-core"
auth "github.com/iden3/go-iden3-auth/v2"
authLoaders "github.com/iden3/go-iden3-auth/v2/loaders"
"github.com/iden3/go-iden3-auth/v2/pubsignals"
"github.com/iden3/go-iden3-auth/v2/state"
"github.com/iden3/go-iden3-core/v2/w3c"
"github.com/iden3/go-schema-processor/v2/loaders"
proof "github.com/iden3/merkletree-proof"
shell "github.com/ipfs/go-ipfs-api"

"github.com/polygonid/sh-id-platform/internal/api_ui"
"github.com/polygonid/sh-id-platform/internal/buildinfo"
Expand All @@ -31,14 +33,13 @@ import (
"github.com/polygonid/sh-id-platform/internal/gateways"
"github.com/polygonid/sh-id-platform/internal/health"
"github.com/polygonid/sh-id-platform/internal/kms"
"github.com/polygonid/sh-id-platform/internal/loader"
"github.com/polygonid/sh-id-platform/internal/log"
"github.com/polygonid/sh-id-platform/internal/providers"
"github.com/polygonid/sh-id-platform/internal/providers/blockchain"
"github.com/polygonid/sh-id-platform/internal/redis"
"github.com/polygonid/sh-id-platform/internal/repositories"
"github.com/polygonid/sh-id-platform/pkg/cache"
"github.com/polygonid/sh-id-platform/pkg/loaders"
circuitLoaders "github.com/polygonid/sh-id-platform/pkg/loaders"
"github.com/polygonid/sh-id-platform/pkg/protocol"
"github.com/polygonid/sh-id-platform/pkg/pubsub"
"github.com/polygonid/sh-id-platform/pkg/reverse_hash"
Expand Down Expand Up @@ -79,11 +80,8 @@ func main() {
ps.WithLogger(log.Error)
cachex := cache.NewRedisCache(rdb)

var schemaLoader loader.Factory
schemaLoader = loader.MultiProtocolFactory(cfg.IFPS.GatewayURL)
if cfg.APIUI.SchemaCache != nil && *cfg.APIUI.SchemaCache {
schemaLoader = loader.CachedFactory(schemaLoader, cachex)
}
// TODO: Cache only if cfg.APIUI.SchemaCache == true
schemaLoader := loaders.NewDocumentLoader(shell.NewShell(cfg.IPFS.GatewayURL), cfg.IPFS.GatewayURL)

vaultCli, err := providers.VaultClient(ctx, providers.Config{
UserPassAuthEnabled: cfg.VaultUserPassAuthEnabled,
Expand Down Expand Up @@ -134,13 +132,14 @@ func main() {
},
}

verifier, err := auth.NewVerifierWithExplicitError(verificationKeyLoader, authLoaders.DefaultSchemaLoader{IpfsURL: cfg.IFPS.GatewayURL}, resolvers)
verifier, err := auth.NewVerifier(verificationKeyLoader, resolvers)
if err != nil {
log.Error(ctx, "failed init verifier", "err", err)
return
}

circuitsLoaderService := loaders.NewCircuits(cfg.Circuit.Path)
circuitsLoaderService := circuitLoaders.NewCircuits(cfg.Circuit.Path)
proofService := gateways.NewProver(ctx, cfg, circuitsLoaderService)

rhsp := reverse_hash.NewRhsPublisher(nil, false)
if cfg.ReverseHashService.Enabled {
Expand Down Expand Up @@ -170,10 +169,10 @@ func main() {
RHSEnabled: cfg.ReverseHashService.Enabled,
RHSUrl: cfg.ReverseHashService.URL,
Host: cfg.APIUI.ServerURL,
}, ps, cfg.IFPS.GatewayURL)
}, ps, cfg.IPFS.GatewayURL)
connectionsService := services.NewConnection(connectionsRepository, storage)
linkService := services.NewLinkService(storage, claimsService, qrService, claimsRepository, linkRepository, schemaRepository, schemaLoader, sessionRepository, ps, cfg.IFPS.GatewayURL)
proofService := gateways.NewProver(ctx, cfg, circuitsLoaderService)
linkService := services.NewLinkService(storage, claimsService, qrService, claimsRepository, linkRepository, schemaRepository, schemaLoader, sessionRepository, ps, cfg.IPFS.GatewayURL)

revocationService := services.NewRevocationService(ethConn, common.HexToAddress(cfg.Ethereum.ContractAddress))
zkProofService := services.NewProofService(claimsService, revocationService, identityService, mtService, claimsRepository, keyStore, storage, stateContract, schemaLoader)
transactionService, err := gateways.NewTransaction(ethereumClient, cfg.Ethereum.ConfirmationBlockCount)
Expand Down Expand Up @@ -250,7 +249,7 @@ func main() {
log.Info(ctx, "Shutting down")
}

func identifierExists(ctx context.Context, did *core.DID, service ports.IdentityService) bool {
func identifierExists(ctx context.Context, did *w3c.DID, service ports.IdentityService) bool {
_, err := service.GetByDID(ctx, *did)
return err == nil
}
Expand Down
Loading

0 comments on commit 16ccdd6

Please sign in to comment.