Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support disable flag for mediatype validator #675

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion cmd/notifications/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
vault "github.com/hashicorp/vault/api"
"github.com/iden3/iden3comm/v2"
"github.com/iden3/iden3comm/v2/packers"
"github.com/iden3/iden3comm/v2/protocol"

"github.com/polygonid/sh-id-platform/internal/buildinfo"
"github.com/polygonid/sh-id-platform/internal/config"
Expand Down Expand Up @@ -179,8 +182,16 @@ func newCredentialsService(ctx context.Context, cfg *config.Configuration, stora
mtService := services.NewIdentityMerkleTrees(mtRepository)
qrService := services.NewQrStoreService(cachex)

mediaTypeManager := services.NewMediaTypeManager(
map[iden3comm.ProtocolMessage][]string{
protocol.CredentialFetchRequestMessageType: {string(packers.MediaTypeZKPMessage)},
protocol.RevocationStatusRequestMessageType: {"*"},
},
*cfg.MediaTypeManager.Enabled,
)

identityService := services.NewIdentity(keyStore, identityRepository, mtRepository, identityStateRepository, mtService, qrService, claimsRepository, revocationRepository, nil, storage, nil, nil, ps, cfg.CredentialStatus, rhsFactory, revocationStatusResolver, *cfg.AutoPublishingToOnChainRHS)
claimsService := services.NewClaim(claimsRepository, identityService, qrService, mtService, identityStateRepository, schemaLoader, storage, cfg.APIUI.ServerURL, ps, cfg.IPFS.GatewayURL, revocationStatusResolver, &services.DefaultMediaTypeManager)
claimsService := services.NewClaim(claimsRepository, identityService, qrService, mtService, identityStateRepository, schemaLoader, storage, cfg.APIUI.ServerURL, ps, cfg.IPFS.GatewayURL, revocationStatusResolver, mediaTypeManager)

return claimsService, nil
}
13 changes: 12 additions & 1 deletion cmd/pending_publisher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
vault "github.com/hashicorp/vault/api"
"github.com/iden3/iden3comm/v2"
"github.com/iden3/iden3comm/v2/packers"
"github.com/iden3/iden3comm/v2/protocol"

"github.com/polygonid/sh-id-platform/internal/buildinfo"
"github.com/polygonid/sh-id-platform/internal/config"
Expand Down Expand Up @@ -160,8 +163,16 @@ func main() {
rhsFactory := reverse_hash.NewFactory(cfg.CredentialStatus.RHS.GetURL(), cl, common.HexToAddress(cfg.CredentialStatus.OnchainTreeStore.SupportedTreeStoreContract), reverse_hash.DefaultRHSTimeOut)
revocationStatusResolver := revocation_status.NewRevocationStatusResolver(cfg.CredentialStatus)

mediaTypeManager := services.NewMediaTypeManager(
map[iden3comm.ProtocolMessage][]string{
protocol.CredentialFetchRequestMessageType: {string(packers.MediaTypeZKPMessage)},
protocol.RevocationStatusRequestMessageType: {"*"},
},
*cfg.MediaTypeManager.Enabled,
)

identityService := services.NewIdentity(keyStore, identityRepo, mtRepo, identityStateRepo, mtService, qrService, claimsRepo, revocationRepository, connectionsRepository, storage, nil, nil, pubsub.NewMock(), cfg.CredentialStatus, rhsFactory, revocationStatusResolver, *cfg.AutoPublishingToOnChainRHS)
claimsService := services.NewClaim(claimsRepo, identityService, qrService, mtService, identityStateRepo, schemaLoader, storage, cfg.APIUI.ServerURL, ps, cfg.IPFS.GatewayURL, revocationStatusResolver, &services.DefaultMediaTypeManager)
claimsService := services.NewClaim(claimsRepo, identityService, qrService, mtService, identityStateRepo, schemaLoader, storage, cfg.APIUI.ServerURL, ps, cfg.IPFS.GatewayURL, revocationStatusResolver, mediaTypeManager)

circuitsLoaderService := circuitLoaders.NewCircuits(cfg.Circuit.Path)
proofService := initProofService(ctx, cfg, circuitsLoaderService)
Expand Down
14 changes: 13 additions & 1 deletion cmd/platform/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import (
"github.com/go-chi/cors"
redis2 "github.com/go-redis/redis/v8"
vault "github.com/hashicorp/vault/api"
"github.com/iden3/iden3comm/v2"
"github.com/iden3/iden3comm/v2/packers"
iden3commProtocol "github.com/iden3/iden3comm/v2/protocol"

"github.com/polygonid/sh-id-platform/internal/api"
"github.com/polygonid/sh-id-platform/internal/buildinfo"
Expand Down Expand Up @@ -141,9 +144,18 @@ func main() {
qrService := services.NewQrStoreService(cachex)

cfg.CredentialStatus.SingleIssuer = false

mediaTypeManager := services.NewMediaTypeManager(
map[iden3comm.ProtocolMessage][]string{
iden3commProtocol.CredentialFetchRequestMessageType: {string(packers.MediaTypeZKPMessage)},
iden3commProtocol.RevocationStatusRequestMessageType: {"*"},
},
*cfg.MediaTypeManager.Enabled,
)

revocationStatusResolver := revocation_status.NewRevocationStatusResolver(cfg.CredentialStatus)
identityService := services.NewIdentity(keyStore, identityRepository, mtRepository, identityStateRepository, mtService, qrService, claimsRepository, revocationRepository, nil, storage, nil, nil, ps, cfg.CredentialStatus, rhsFactory, revocationStatusResolver, *cfg.AutoPublishingToOnChainRHS)
claimsService := services.NewClaim(claimsRepository, identityService, qrService, mtService, identityStateRepository, schemaLoader, storage, cfg.ServerUrl, ps, cfg.IPFS.GatewayURL, revocationStatusResolver, &services.DefaultMediaTypeManager)
claimsService := services.NewClaim(claimsRepository, identityService, qrService, mtService, identityStateRepository, schemaLoader, storage, cfg.ServerUrl, ps, cfg.IPFS.GatewayURL, revocationStatusResolver, mediaTypeManager)
proofService := gateways.NewProver(ctx, cfg, circuitsLoaderService)

transactionService, err := gateways.NewTransaction(ethereumClient, cfg.Ethereum.ConfirmationBlockCount)
Expand Down
14 changes: 13 additions & 1 deletion cmd/platform_ui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import (
"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/iden3comm/v2"
"github.com/iden3/iden3comm/v2/packers"
iden3commProtocol "github.com/iden3/iden3comm/v2/protocol"

"github.com/polygonid/sh-id-platform/internal/api_ui"
"github.com/polygonid/sh-id-platform/internal/buildinfo"
Expand Down Expand Up @@ -173,10 +176,19 @@ func main() {
qrService := services.NewQrStoreService(cachex)

cfg.CredentialStatus.SingleIssuer = true

mediaTypeManager := services.NewMediaTypeManager(
map[iden3comm.ProtocolMessage][]string{
iden3commProtocol.CredentialFetchRequestMessageType: {string(packers.MediaTypeZKPMessage)},
iden3commProtocol.RevocationStatusRequestMessageType: {"*"},
},
*cfg.MediaTypeManager.Enabled,
)

revocationStatusResolver := revocation_status.NewRevocationStatusResolver(cfg.CredentialStatus)
identityService := services.NewIdentity(keyStore, identityRepository, mtRepository, identityStateRepository, mtService, qrService, claimsRepository, revocationRepository, connectionsRepository, storage, verifier, sessionRepository, ps, cfg.CredentialStatus, rhsFactory, revocationStatusResolver, *cfg.AutoPublishingToOnChainRHS)
schemaService := services.NewSchema(schemaRepository, schemaLoader)
claimsService := services.NewClaim(claimsRepository, identityService, qrService, mtService, identityStateRepository, schemaLoader, storage, cfg.APIUI.ServerURL, ps, cfg.IPFS.GatewayURL, revocationStatusResolver, &services.DefaultMediaTypeManager)
claimsService := services.NewClaim(claimsRepository, identityService, qrService, mtService, identityStateRepository, schemaLoader, storage, cfg.APIUI.ServerURL, ps, cfg.IPFS.GatewayURL, revocationStatusResolver, mediaTypeManager)
connectionsService := services.NewConnection(connectionsRepository, claimsRepository, storage)
linkService := services.NewLinkService(storage, claimsService, qrService, claimsRepository, linkRepository, schemaRepository, schemaLoader, sessionRepository, ps, cfg.IPFS.GatewayURL)

Expand Down
83 changes: 75 additions & 8 deletions internal/api/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
core "github.com/iden3/go-iden3-core/v2"
"github.com/iden3/go-iden3-core/v2/w3c"
"github.com/iden3/go-schema-processor/v2/verifiable"
"github.com/iden3/iden3comm/v2"
"github.com/iden3/iden3comm/v2/packers"
"github.com/iden3/iden3comm/v2/protocol"
"github.com/mitchellh/mapstructure"
Expand Down Expand Up @@ -54,7 +55,14 @@ func TestServer_CreateIdentity(t *testing.T) {
revocationStatusResolver := revocation_status.NewRevocationStatusResolver(cfg.CredentialStatus)
identityService := services.NewIdentity(keyStore, identityRepo, mtRepo, identityStateRepo, mtService, nil, claimsRepo, revocationRepository, connectionsRepository, storage, nil, nil, pubsub.NewMock(), cfg.CredentialStatus, rhsFactory, revocationStatusResolver, *cfg.AutoPublishingToOnChainRHS)

claimsService := services.NewClaim(claimsRepo, identityService, nil, mtService, identityStateRepo, schemaLoader, storage, cfg.CredentialStatus.Iden3CommAgentStatus.GetURL(), pubsub.NewMock(), ipfsGatewayURL, revocationStatusResolver, &services.DefaultMediaTypeManager)
mediaTypeManager := services.NewMediaTypeManager(
map[iden3comm.ProtocolMessage][]string{
protocol.CredentialFetchRequestMessageType: {string(packers.MediaTypeZKPMessage)},
protocol.RevocationStatusRequestMessageType: {"*"},
},
true,
)
claimsService := services.NewClaim(claimsRepo, identityService, nil, mtService, identityStateRepo, schemaLoader, storage, cfg.CredentialStatus.Iden3CommAgentStatus.GetURL(), pubsub.NewMock(), ipfsGatewayURL, revocationStatusResolver, mediaTypeManager)
accountService := services.NewAccountService(cfg.Ethereum, keyStore)
server := NewServer(&cfg, identityService, accountService, claimsService, nil, NewPublisherMock(), NewPackageManagerMock(), nil)
handler := getHandler(context.Background(), server)
Expand Down Expand Up @@ -251,7 +259,14 @@ func TestServer_RevokeClaim(t *testing.T) {
rhsFactory := reverse_hash.NewFactory(cfg.CredentialStatus.RHS.GetURL(), nil, commonEth.HexToAddress(cfg.CredentialStatus.OnchainTreeStore.SupportedTreeStoreContract), reverse_hash.DefaultRHSTimeOut)
identityService := services.NewIdentity(&KMSMock{}, identityRepo, mtRepo, identityStateRepo, mtService, nil, claimsRepo, revocationRepository, connectionsRepository, storage, nil, nil, pubsub.NewMock(), cfg.CredentialStatus, rhsFactory, revocationStatusResolver, *cfg.AutoPublishingToOnChainRHS)

claimsService := services.NewClaim(claimsRepo, identityService, nil, mtService, identityStateRepo, schemaLoader, storage, cfg.CredentialStatus.Iden3CommAgentStatus.GetURL(), pubsub.NewMock(), ipfsGatewayURL, revocationStatusResolver, &services.DefaultMediaTypeManager)
mediaTypeManager := services.NewMediaTypeManager(
map[iden3comm.ProtocolMessage][]string{
protocol.CredentialFetchRequestMessageType: {string(packers.MediaTypeZKPMessage)},
protocol.RevocationStatusRequestMessageType: {"*"},
},
true,
)
claimsService := services.NewClaim(claimsRepo, identityService, nil, mtService, identityStateRepo, schemaLoader, storage, cfg.CredentialStatus.Iden3CommAgentStatus.GetURL(), pubsub.NewMock(), ipfsGatewayURL, revocationStatusResolver, mediaTypeManager)
accountService := services.NewAccountService(cfg.Ethereum, keyStore)
server := NewServer(&cfg, identityService, accountService, claimsService, nil, NewPublisherMock(), NewPackageManagerMock(), nil)

Expand Down Expand Up @@ -398,11 +413,19 @@ func TestServer_CreateClaim(t *testing.T) {
revocationRepository := repositories.NewRevocation()
connectionsRepository := repositories.NewConnections()

mediaTypeManager := services.NewMediaTypeManager(
map[iden3comm.ProtocolMessage][]string{
protocol.CredentialFetchRequestMessageType: {string(packers.MediaTypeZKPMessage)},
protocol.RevocationStatusRequestMessageType: {"*"},
},
true,
)

rhsFactory := reverse_hash.NewFactory(cfg.CredentialStatus.RHS.GetURL(), nil, commonEth.HexToAddress(cfg.CredentialStatus.OnchainTreeStore.SupportedTreeStoreContract), reverse_hash.DefaultRHSTimeOut)
revocationStatusResolver := revocation_status.NewRevocationStatusResolver(cfg.CredentialStatus)
identityService := services.NewIdentity(keyStore, identityRepo, mtRepo, identityStateRepo, mtService, qrService, claimsRepo, revocationRepository, connectionsRepository, storage, nil, nil, pubsub.NewMock(), cfg.CredentialStatus, rhsFactory, revocationStatusResolver, *cfg.AutoPublishingToOnChainRHS)
pubSub := pubsub.NewMock()
claimsService := services.NewClaim(claimsRepo, identityService, nil, mtService, identityStateRepo, schemaLoader, storage, cfg.CredentialStatus.Iden3CommAgentStatus.GetURL(), pubSub, ipfsGatewayURL, revocationStatusResolver, &services.DefaultMediaTypeManager)
claimsService := services.NewClaim(claimsRepo, identityService, nil, mtService, identityStateRepo, schemaLoader, storage, cfg.CredentialStatus.Iden3CommAgentStatus.GetURL(), pubSub, ipfsGatewayURL, revocationStatusResolver, mediaTypeManager)
accountService := services.NewAccountService(cfg.Ethereum, keyStore)
server := NewServer(&cfg, identityService, accountService, claimsService, nil, NewPublisherMock(), NewPackageManagerMock(), nil)
handler := getHandler(ctx, server)
Expand Down Expand Up @@ -580,7 +603,15 @@ func TestServer_GetIdentities(t *testing.T) {
revocationStatusResolver := revocation_status.NewRevocationStatusResolver(cfg.CredentialStatus)
identityService := services.NewIdentity(&KMSMock{}, identityRepo, mtRepo, identityStateRepo, mtService, nil, claimsRepo, revocationRepository, connectionsRepository, storage, nil, nil, pubsub.NewMock(), cfg.CredentialStatus, rhsFactory, revocationStatusResolver, *cfg.AutoPublishingToOnChainRHS)

claimsService := services.NewClaim(claimsRepo, identityService, nil, mtService, identityStateRepo, schemaLoader, storage, cfg.CredentialStatus.Iden3CommAgentStatus.GetURL(), pubsub.NewMock(), ipfsGatewayURL, revocationStatusResolver, &services.DefaultMediaTypeManager)
mediaTypeManager := services.NewMediaTypeManager(
map[iden3comm.ProtocolMessage][]string{
protocol.CredentialFetchRequestMessageType: {string(packers.MediaTypeZKPMessage)},
protocol.RevocationStatusRequestMessageType: {"*"},
},
true,
)

claimsService := services.NewClaim(claimsRepo, identityService, nil, mtService, identityStateRepo, schemaLoader, storage, cfg.CredentialStatus.Iden3CommAgentStatus.GetURL(), pubsub.NewMock(), ipfsGatewayURL, revocationStatusResolver, mediaTypeManager)
accountService := services.NewAccountService(cfg.Ethereum, keyStore)
server := NewServer(&cfg, identityService, accountService, claimsService, nil, NewPublisherMock(), NewPackageManagerMock(), nil)
handler := getHandler(context.Background(), server)
Expand Down Expand Up @@ -655,7 +686,16 @@ func TestServer_GetClaimQrCode(t *testing.T) {
idStr := "did:polygonid:polygon:mumbai:2qPrv5Yx8s1qAmEnPym68LfT7gTbASGampiGU7TseL"
idNoClaims := "did:polygonid:polygon:mumbai:2qGjTUuxZKqKS4Q8UmxHUPw55g15QgEVGnj6Wkq8Vk"
accountService := services.NewAccountService(cfg.Ethereum, keyStore)
claimsService := services.NewClaim(claimsRepo, identityService, nil, mtService, identityStateRepo, schemaLoader, storage, cfg.CredentialStatus.Iden3CommAgentStatus.GetURL(), pubsub.NewMock(), ipfsGatewayURL, revocationStatusResolver, &services.DefaultMediaTypeManager)

mediaTypeManager := services.NewMediaTypeManager(
map[iden3comm.ProtocolMessage][]string{
protocol.CredentialFetchRequestMessageType: {string(packers.MediaTypeZKPMessage)},
protocol.RevocationStatusRequestMessageType: {"*"},
},
true,
)

claimsService := services.NewClaim(claimsRepo, identityService, nil, mtService, identityStateRepo, schemaLoader, storage, cfg.CredentialStatus.Iden3CommAgentStatus.GetURL(), pubsub.NewMock(), ipfsGatewayURL, revocationStatusResolver, mediaTypeManager)

identity := &domain.Identity{
Identifier: idStr,
Expand Down Expand Up @@ -795,7 +835,16 @@ func TestServer_GetClaim(t *testing.T) {
revocationStatusResolver := revocation_status.NewRevocationStatusResolver(cfg.CredentialStatus)
rhsFactory := reverse_hash.NewFactory(cfg.CredentialStatus.RHS.GetURL(), nil, commonEth.HexToAddress(cfg.CredentialStatus.OnchainTreeStore.SupportedTreeStoreContract), reverse_hash.DefaultRHSTimeOut)
identityService := services.NewIdentity(&KMSMock{}, identityRepo, mtRepo, identityStateRepo, mtService, nil, claimsRepo, revocationRepository, connectionsRepository, storage, nil, nil, pubsub.NewMock(), cfg.CredentialStatus, rhsFactory, revocationStatusResolver, *cfg.AutoPublishingToOnChainRHS)
claimsService := services.NewClaim(claimsRepo, identityService, nil, mtService, identityStateRepo, schemaLoader, storage, cfg.CredentialStatus.Iden3CommAgentStatus.GetURL(), pubsub.NewMock(), ipfsGatewayURL, revocationStatusResolver, &services.DefaultMediaTypeManager)

mediaTypeManager := services.NewMediaTypeManager(
map[iden3comm.ProtocolMessage][]string{
protocol.CredentialFetchRequestMessageType: {string(packers.MediaTypeZKPMessage)},
protocol.RevocationStatusRequestMessageType: {"*"},
},
true,
)

claimsService := services.NewClaim(claimsRepo, identityService, nil, mtService, identityStateRepo, schemaLoader, storage, cfg.CredentialStatus.Iden3CommAgentStatus.GetURL(), pubsub.NewMock(), ipfsGatewayURL, revocationStatusResolver, mediaTypeManager)

accountService := services.NewAccountService(cfg.Ethereum, keyStore)
server := NewServer(&cfg, identityService, accountService, claimsService, nil, NewPublisherMock(), NewPackageManagerMock(), nil)
Expand Down Expand Up @@ -969,7 +1018,16 @@ func TestServer_GetClaims(t *testing.T) {
revocationStatusResolver := revocation_status.NewRevocationStatusResolver(cfg.CredentialStatus)
rhsFactory := reverse_hash.NewFactory(cfg.CredentialStatus.RHS.GetURL(), nil, commonEth.HexToAddress(cfg.CredentialStatus.OnchainTreeStore.SupportedTreeStoreContract), reverse_hash.DefaultRHSTimeOut)
identityService := services.NewIdentity(keyStore, identityRepo, mtRepo, identityStateRepo, mtService, nil, claimsRepo, revocationRepository, connectionsRepository, storage, nil, nil, pubsub.NewMock(), cfg.CredentialStatus, rhsFactory, revocationStatusResolver, *cfg.AutoPublishingToOnChainRHS)
claimsService := services.NewClaim(claimsRepo, identityService, nil, mtService, identityStateRepo, schemaLoader, storage, cfg.CredentialStatus.Iden3CommAgentStatus.GetURL(), pubsub.NewMock(), ipfsGatewayURL, revocationStatusResolver, &services.DefaultMediaTypeManager)

mediaTypeManager := services.NewMediaTypeManager(
map[iden3comm.ProtocolMessage][]string{
protocol.CredentialFetchRequestMessageType: {string(packers.MediaTypeZKPMessage)},
protocol.RevocationStatusRequestMessageType: {"*"},
},
true,
)

claimsService := services.NewClaim(claimsRepo, identityService, nil, mtService, identityStateRepo, schemaLoader, storage, cfg.CredentialStatus.Iden3CommAgentStatus.GetURL(), pubsub.NewMock(), ipfsGatewayURL, revocationStatusResolver, mediaTypeManager)

fixture := tests.NewFixture(storage)

Expand Down Expand Up @@ -1318,7 +1376,16 @@ func TestServer_GetRevocationStatus(t *testing.T) {

identity, err := identityService.Create(ctx, "http://localhost:3001", &ports.DIDCreationOptions{Method: method, Blockchain: blockchain, Network: network, KeyType: BJJ})
assert.NoError(t, err)
claimsService := services.NewClaim(claimsRepo, identityService, nil, mtService, identityStateRepo, schemaLoader, storage, cfg.CredentialStatus.Iden3CommAgentStatus.GetURL(), pubsub.NewMock(), ipfsGatewayURL, revocationStatusResolver, &services.DefaultMediaTypeManager)

mediaTypeManager := services.NewMediaTypeManager(
map[iden3comm.ProtocolMessage][]string{
protocol.CredentialFetchRequestMessageType: {string(packers.MediaTypeZKPMessage)},
protocol.RevocationStatusRequestMessageType: {"*"},
},
true,
)

claimsService := services.NewClaim(claimsRepo, identityService, nil, mtService, identityStateRepo, schemaLoader, storage, cfg.CredentialStatus.Iden3CommAgentStatus.GetURL(), pubsub.NewMock(), ipfsGatewayURL, revocationStatusResolver, mediaTypeManager)
accountService := services.NewAccountService(cfg.Ethereum, keyStore)
server := NewServer(&cfg, identityService, accountService, claimsService, nil, NewPublisherMock(), NewPackageManagerMock(), nil)
handler := getHandler(context.Background(), server)
Expand Down
Loading
Loading