Skip to content

Commit

Permalink
Merge pull request #592 from 0xPolygonID/PID-1649-credential-included…
Browse files Browse the repository at this point in the history
…-in-state-of-issuer-even-if-only-sig-proof-is-selected

Pid 1649 credential included in state of issuer even if only sig proof is selected
  • Loading branch information
martinsaporiti authored Jan 17, 2024
2 parents eed0901 + 6bcd4a9 commit a4ac499
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions internal/api_ui/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,11 @@ func (s *Server) PublishState(ctx context.Context, request PublishStateRequestOb
publishedState, err := s.publisherGateway.PublishState(ctx, &s.cfg.APIUI.IssuerDID)
if err != nil {
log.Error(ctx, "error publishing the state", "err", err)

if errors.Is(err, services.ErrNoClaimsFoundToProcess) {
return PublishState400JSONResponse{N400JSONResponse{Message: err.Error()}}, nil
}

if errors.Is(err, gateways.ErrStateIsBeingProcessed) || errors.Is(err, gateways.ErrNoStatesToProcess) {
return PublishState400JSONResponse{N400JSONResponse{Message: err.Error()}}, nil
}
Expand Down
6 changes: 6 additions & 0 deletions internal/core/services/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ var (
ErrWrongDIDMetada = errors.New("wrong DID Metadata")
// ErrAssigningMTPProof - represents an error in the identity metadata
ErrAssigningMTPProof = errors.New("error assigning the MTP Proof from Auth Claim. If this identity has keyType=ETH you must to publish the state first")
// ErrNoClaimsFoundToProcess - means that there are no claims to process
ErrNoClaimsFoundToProcess = errors.New("no MTP claims found to process")
)

type identity struct {
Expand Down Expand Up @@ -331,6 +333,10 @@ func (i *identity) UpdateState(ctx context.Context, did w3c.DID) (*domain.Identi
return fmt.Errorf("error getting the states: %w", err)
}

if len(lc) == 0 {
return ErrNoClaimsFoundToProcess
}

for i := range lc {
err = iTrees.AddClaim(ctx, &lc[i])
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/core/services/tests/identity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func Test_identity_UpdateState(t *testing.T) {
{
name: "should get a new state for identity without claim",
did: did2,
shouldReturnErr: false,
shouldReturnErr: true,
},
{
name: "should return an error",
Expand Down
4 changes: 2 additions & 2 deletions internal/repositories/claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ func (c *claims) GetAllByState(ctx context.Context, conn db.Querier, did *w3c.DI
credential_status,
core_claim
FROM claims
WHERE issuer = $1 AND identity_state IS NULL AND identifier = issuer
WHERE issuer = $1 AND identity_state IS NULL AND identifier = issuer AND mtp = true
`, did.String())
} else {
rows, err = conn.Query(ctx, `
Expand All @@ -555,7 +555,7 @@ func (c *claims) GetAllByState(ctx context.Context, conn db.Querier, did *w3c.DI
core_claim
FROM claims
LEFT OUTER JOIN identity_states ON claims.identity_state = identity_states.state
WHERE issuer = $1 AND identity_state = $2 AND claims.identifier = issuer
WHERE issuer = $1 AND identity_state = $2 AND claims.identifier = issuer AND mtp = true
`, did.String(), state.Hex())
}

Expand Down

0 comments on commit a4ac499

Please sign in to comment.