Skip to content

Commit

Permalink
Merge pull request #600 from 0xPolygonID/PID-1234-issuer-node-revocat…
Browse files Browse the repository at this point in the history
…ion-status-iden-3-comm-revocation-status-v-1-0

feat: adding Iden3commRevocationStatusV1
  • Loading branch information
martinsaporiti authored May 30, 2024
2 parents e17968f + 3a5e44e commit 11392d6
Show file tree
Hide file tree
Showing 26 changed files with 152 additions and 1,385 deletions.
5 changes: 2 additions & 3 deletions cmd/issuer_initializer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/ethereum/go-ethereum/ethclient"
vault "github.com/hashicorp/vault/api"
core "github.com/iden3/go-iden3-core/v2"
"github.com/iden3/go-schema-processor/v2/verifiable"

"github.com/polygonid/sh-id-platform/internal/buildinfo"
"github.com/polygonid/sh-id-platform/internal/config"
Expand Down Expand Up @@ -144,7 +143,7 @@ func main() {
}, keyStore)

// this is needed to create the did with the correct auth core claim revocation status URL
cfg.CredentialStatus.DirectStatus.URL = cfg.APIUI.ServerURL
cfg.CredentialStatus.Iden3CommAgentStatus.URL = cfg.APIUI.ServerURL
rhsFactory := reverse_hash.NewFactory(cfg.CredentialStatus.RHS.GetURL(), ethConn, common.HexToAddress(cfg.CredentialStatus.OnchainTreeStore.SupportedTreeStoreContract), reverse_hash.DefaultRHSTimeOut)
revocationStatusResolver := revocation_status.NewRevocationStatusResolver(cfg.CredentialStatus)
cfg.CredentialStatus.SingleIssuer = true
Expand All @@ -155,7 +154,7 @@ func main() {
Network: core.NetworkID(cfg.APIUI.IdentityNetwork),
Blockchain: core.Blockchain(cfg.APIUI.IdentityBlockchain),
KeyType: kms.KeyType(cfg.APIUI.KeyType),
AuthBJJCredentialStatus: verifiable.CredentialStatusType(cfg.CredentialStatus.CredentialStatusType),
AuthBJJCredentialStatus: cfg.CredentialStatus.CredentialStatusType,
}

identity, err := identityService.Create(ctx, cfg.APIUI.ServerURL, didCreationOptions)
Expand Down
17 changes: 1 addition & 16 deletions cmd/platform/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"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/blockchain/eth"
"github.com/polygonid/sh-id-platform/pkg/cache"
"github.com/polygonid/sh-id-platform/pkg/credentials/revocation_status"
circuitLoaders "github.com/polygonid/sh-id-platform/pkg/loaders"
Expand Down Expand Up @@ -147,20 +146,6 @@ func main() {
claimsService := services.NewClaim(claimsRepository, identityService, qrService, mtService, identityStateRepository, schemaLoader, storage, cfg.ServerUrl, ps, cfg.IPFS.GatewayURL, revocationStatusResolver)
proofService := gateways.NewProver(ctx, cfg, circuitsLoaderService)

stateService, err := eth.NewStateService(eth.StateServiceConfig{
EthClient: ethConn,
StateAddress: common.HexToAddress(cfg.Ethereum.ContractAddress),
ResponseTimeout: cfg.Ethereum.RPCResponseTimeout,
})
if err != nil {
log.Error(ctx, "failed init state service", "err", err)
return
}

onChainCredentialStatusResolverService := gateways.NewOnChainCredStatusResolverService(ethConn, cfg.Ethereum.RPCResponseTimeout)
revocationService := services.NewRevocationService(common.HexToAddress(cfg.Ethereum.ContractAddress), stateService, onChainCredentialStatusResolverService)

zkProofService := services.NewProofService(claimsService, revocationService, identityService, mtService, claimsRepository, keyStore, storage, stateService, schemaLoader)
transactionService, err := gateways.NewTransaction(ethereumClient, cfg.Ethereum.ConfirmationBlockCount)
if err != nil {
log.Error(ctx, "error creating transaction service", "err", err)
Expand All @@ -175,7 +160,7 @@ func main() {

publisher := gateways.NewPublisher(storage, identityService, claimsService, mtService, keyStore, transactionService, proofService, publisherGateway, cfg.Ethereum.ConfirmationTimeout, ps)

packageManager, err := protocol.InitPackageManager(ctx, stateContract, zkProofService, cfg.Circuit.Path)
packageManager, err := protocol.InitPackageManager(stateContract, cfg.Circuit.Path)
if err != nil {
log.Error(ctx, "failed init package protocol", "err", err)
return
Expand Down
16 changes: 1 addition & 15 deletions cmd/platform_ui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
"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/blockchain/eth"
"github.com/polygonid/sh-id-platform/pkg/cache"
"github.com/polygonid/sh-id-platform/pkg/credentials/revocation_status"
circuitLoaders "github.com/polygonid/sh-id-platform/pkg/loaders"
Expand Down Expand Up @@ -181,19 +180,6 @@ func main() {
connectionsService := services.NewConnection(connectionsRepository, claimsRepository, storage)
linkService := services.NewLinkService(storage, claimsService, qrService, claimsRepository, linkRepository, schemaRepository, schemaLoader, sessionRepository, ps, cfg.IPFS.GatewayURL)

stateService, err := eth.NewStateService(eth.StateServiceConfig{
EthClient: ethConn,
StateAddress: common.HexToAddress(cfg.Ethereum.ContractAddress),
ResponseTimeout: cfg.Ethereum.RPCResponseTimeout,
})
if err != nil {
log.Error(ctx, "failed init state service", "err", err)
return
}

onChainCredentialStatusResolverService := gateways.NewOnChainCredStatusResolverService(ethConn, cfg.Ethereum.RPCResponseTimeout)
revocationService := services.NewRevocationService(common.HexToAddress(cfg.Ethereum.ContractAddress), stateService, onChainCredentialStatusResolverService)
zkProofService := services.NewProofService(claimsService, revocationService, identityService, mtService, claimsRepository, keyStore, storage, stateService, schemaLoader)
transactionService, err := gateways.NewTransaction(ethereumClient, cfg.Ethereum.ConfirmationBlockCount)
if err != nil {
log.Error(ctx, "error creating transaction service", "err", err)
Expand All @@ -208,7 +194,7 @@ func main() {

publisher := gateways.NewPublisher(storage, identityService, claimsService, mtService, keyStore, transactionService, proofService, publisherGateway, cfg.Ethereum.ConfirmationTimeout, ps)

packageManager, err := protocol.InitPackageManager(ctx, stateContract, zkProofService, cfg.Circuit.Path)
packageManager, err := protocol.InitPackageManager(stateContract, cfg.Circuit.Path)
if err != nil {
log.Error(ctx, "failed init package protocol", "err", err)
return
Expand Down
2 changes: 1 addition & 1 deletion internal/api/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func TestMain(m *testing.M) {

cfg.CredentialStatus = config.CredentialStatus{
RHSMode: "None",
DirectStatus: config.DirectStatus{
Iden3CommAgentStatus: config.Iden3CommAgentStatus{
URL: "http://localhost:3001",
},
}
Expand Down
7 changes: 4 additions & 3 deletions internal/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (s *Server) CreateIdentity(ctx context.Context, request CreateIdentityReque
Network: core.NetworkID(network),
Blockchain: core.Blockchain(blockchain),
KeyType: kms.KeyType(keyType),
AuthBJJCredentialStatus: verifiable.CredentialStatusType(s.cfg.CredentialStatus.CredentialStatusType),
AuthBJJCredentialStatus: s.cfg.CredentialStatus.CredentialStatusType,
})
if err != nil {
if errors.Is(err, services.ErrWrongDIDMetada) {
Expand Down Expand Up @@ -160,7 +160,7 @@ func (s *Server) CreateClaim(ctx context.Context, request CreateClaimRequestObje
expiration = common.ToPointer(time.Unix(*request.Body.Expiration, 0))
}

req := ports.NewCreateClaimRequest(did, request.Body.CredentialSchema, request.Body.CredentialSubject, expiration, request.Body.Type, request.Body.Version, request.Body.SubjectPosition, request.Body.MerklizedRootPosition, common.ToPointer(true), common.ToPointer(true), nil, false, verifiable.CredentialStatusType(s.cfg.CredentialStatus.CredentialStatusType), toVerifiableRefreshService(request.Body.RefreshService), request.Body.RevNonce,
req := ports.NewCreateClaimRequest(did, request.Body.CredentialSchema, request.Body.CredentialSubject, expiration, request.Body.Type, request.Body.Version, request.Body.SubjectPosition, request.Body.MerklizedRootPosition, common.ToPointer(true), common.ToPointer(true), nil, false, s.cfg.CredentialStatus.CredentialStatusType, toVerifiableRefreshService(request.Body.RefreshService), request.Body.RevNonce,
toVerifiableDisplayMethod(request.Body.DisplayMethod))

resp, err := s.claimService.Save(ctx, req)
Expand Down Expand Up @@ -407,7 +407,8 @@ func (s *Server) Agent(ctx context.Context, request AgentRequestObject) (AgentRe
log.Debug(ctx, "agent empty request")
return Agent400JSONResponse{N400JSONResponse{"cannot proceed with an empty request"}}, nil
}
basicMessage, err := s.packageManager.UnpackWithType(packers.MediaTypeZKPMessage, []byte(*request.Body))

basicMessage, _, err := s.packageManager.Unpack([]byte(*request.Body))
if err != nil {
log.Debug(ctx, "agent bad request", "err", err, "body", *request.Body)
return Agent400JSONResponse{N400JSONResponse{"cannot proceed with the given request"}}, nil
Expand Down
18 changes: 9 additions & 9 deletions internal/api/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ 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)

claimsService := services.NewClaim(claimsRepo, identityService, nil, mtService, identityStateRepo, schemaLoader, storage, cfg.CredentialStatus.DirectStatus.GetURL(), pubsub.NewMock(), ipfsGatewayURL, revocationStatusResolver)
claimsService := services.NewClaim(claimsRepo, identityService, nil, mtService, identityStateRepo, schemaLoader, storage, cfg.CredentialStatus.Iden3CommAgentStatus.GetURL(), pubsub.NewMock(), ipfsGatewayURL, revocationStatusResolver)
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 +251,7 @@ 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)

claimsService := services.NewClaim(claimsRepo, identityService, nil, mtService, identityStateRepo, schemaLoader, storage, cfg.CredentialStatus.DirectStatus.GetURL(), pubsub.NewMock(), ipfsGatewayURL, revocationStatusResolver)
claimsService := services.NewClaim(claimsRepo, identityService, nil, mtService, identityStateRepo, schemaLoader, storage, cfg.CredentialStatus.Iden3CommAgentStatus.GetURL(), pubsub.NewMock(), ipfsGatewayURL, revocationStatusResolver)
accountService := services.NewAccountService(cfg.Ethereum, keyStore)
server := NewServer(&cfg, identityService, accountService, claimsService, nil, NewPublisherMock(), NewPackageManagerMock(), nil)

Expand Down Expand Up @@ -402,7 +402,7 @@ func TestServer_CreateClaim(t *testing.T) {
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)
pubSub := pubsub.NewMock()
claimsService := services.NewClaim(claimsRepo, identityService, nil, mtService, identityStateRepo, schemaLoader, storage, cfg.CredentialStatus.DirectStatus.GetURL(), pubSub, ipfsGatewayURL, revocationStatusResolver)
claimsService := services.NewClaim(claimsRepo, identityService, nil, mtService, identityStateRepo, schemaLoader, storage, cfg.CredentialStatus.Iden3CommAgentStatus.GetURL(), pubSub, ipfsGatewayURL, revocationStatusResolver)
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 +580,7 @@ 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)

claimsService := services.NewClaim(claimsRepo, identityService, nil, mtService, identityStateRepo, schemaLoader, storage, cfg.CredentialStatus.DirectStatus.GetURL(), pubsub.NewMock(), ipfsGatewayURL, revocationStatusResolver)
claimsService := services.NewClaim(claimsRepo, identityService, nil, mtService, identityStateRepo, schemaLoader, storage, cfg.CredentialStatus.Iden3CommAgentStatus.GetURL(), pubsub.NewMock(), ipfsGatewayURL, revocationStatusResolver)
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 +655,7 @@ 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.DirectStatus.GetURL(), pubsub.NewMock(), ipfsGatewayURL, revocationStatusResolver)
claimsService := services.NewClaim(claimsRepo, identityService, nil, mtService, identityStateRepo, schemaLoader, storage, cfg.CredentialStatus.Iden3CommAgentStatus.GetURL(), pubsub.NewMock(), ipfsGatewayURL, revocationStatusResolver)

identity := &domain.Identity{
Identifier: idStr,
Expand Down Expand Up @@ -795,7 +795,7 @@ 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)
claimsService := services.NewClaim(claimsRepo, identityService, nil, mtService, identityStateRepo, schemaLoader, storage, cfg.CredentialStatus.DirectStatus.GetURL(), pubsub.NewMock(), ipfsGatewayURL, revocationStatusResolver)
claimsService := services.NewClaim(claimsRepo, identityService, nil, mtService, identityStateRepo, schemaLoader, storage, cfg.CredentialStatus.Iden3CommAgentStatus.GetURL(), pubsub.NewMock(), ipfsGatewayURL, revocationStatusResolver)

accountService := services.NewAccountService(cfg.Ethereum, keyStore)
server := NewServer(&cfg, identityService, accountService, claimsService, nil, NewPublisherMock(), NewPackageManagerMock(), nil)
Expand Down Expand Up @@ -969,7 +969,7 @@ 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)
claimsService := services.NewClaim(claimsRepo, identityService, nil, mtService, identityStateRepo, schemaLoader, storage, cfg.CredentialStatus.DirectStatus.GetURL(), pubsub.NewMock(), ipfsGatewayURL, revocationStatusResolver)
claimsService := services.NewClaim(claimsRepo, identityService, nil, mtService, identityStateRepo, schemaLoader, storage, cfg.CredentialStatus.Iden3CommAgentStatus.GetURL(), pubsub.NewMock(), ipfsGatewayURL, revocationStatusResolver)

fixture := tests.NewFixture(storage)

Expand Down Expand Up @@ -1318,7 +1318,7 @@ 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.DirectStatus.GetURL(), pubsub.NewMock(), ipfsGatewayURL, revocationStatusResolver)
claimsService := services.NewClaim(claimsRepo, identityService, nil, mtService, identityStateRepo, schemaLoader, storage, cfg.CredentialStatus.Iden3CommAgentStatus.GetURL(), pubsub.NewMock(), ipfsGatewayURL, revocationStatusResolver)
accountService := services.NewAccountService(cfg.Ethereum, keyStore)
server := NewServer(&cfg, identityService, accountService, claimsService, nil, NewPublisherMock(), NewPackageManagerMock(), nil)
handler := getHandler(context.Background(), server)
Expand All @@ -1333,7 +1333,7 @@ func TestServer_GetRevocationStatus(t *testing.T) {
typeC := "KYCAgeCredential"

merklizedRootPosition := "value"
claim, err := claimsService.Save(ctx, ports.NewCreateClaimRequest(did, schema, credentialSubject, common.ToPointer(time.Now()), typeC, nil, nil, &merklizedRootPosition, common.ToPointer(true), common.ToPointer(true), nil, false, verifiable.SparseMerkleTreeProof, nil, nil, nil))
claim, err := claimsService.Save(ctx, ports.NewCreateClaimRequest(did, schema, credentialSubject, common.ToPointer(time.Now()), typeC, nil, nil, &merklizedRootPosition, common.ToPointer(true), common.ToPointer(true), nil, false, verifiable.Iden3commRevocationStatusV1, nil, nil, nil))
assert.NoError(t, err)

type expected struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/api_ui/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestMain(m *testing.M) {
cfg.ServerUrl = "https://testing.env/"
cfg.CredentialStatus = config.CredentialStatus{
RHSMode: "None",
DirectStatus: config.DirectStatus{
Iden3CommAgentStatus: config.Iden3CommAgentStatus{
URL: "http://localhost:3001",
},
}
Expand Down
Loading

0 comments on commit 11392d6

Please sign in to comment.