Skip to content

Commit

Permalink
remove redundant domain.Agent struct
Browse files Browse the repository at this point in the history
  • Loading branch information
volodymyr-basiuk committed Jan 29, 2025
1 parent ffd350e commit 3d67cf9
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 44 deletions.
22 changes: 11 additions & 11 deletions internal/api/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package api
import (
"context"

"github.com/iden3/iden3comm/v2"
"github.com/iden3/iden3comm/v2/protocol"

"github.com/polygonid/sh-id-platform/internal/core/domain"
"github.com/polygonid/sh-id-platform/internal/core/ports"
"github.com/polygonid/sh-id-platform/internal/log"
)
Expand All @@ -23,7 +23,7 @@ func (s *Server) Agent(ctx context.Context, request AgentRequestObject) (AgentRe
return Agent400JSONResponse{N400JSONResponse{"cannot proceed with the given request"}}, nil
}

var agent *domain.Agent
var response *iden3comm.BasicMessage

if basicMessage.Type == protocol.DiscoverFeatureQueriesMessageType {
req, err := ports.NewDiscoveryAgentRequest(basicMessage)
Expand All @@ -32,7 +32,7 @@ func (s *Server) Agent(ctx context.Context, request AgentRequestObject) (AgentRe
return Agent400JSONResponse{N400JSONResponse{err.Error()}}, nil
}

agent, err = s.discoveryService.Agent(ctx, req)
response, err = s.discoveryService.Agent(ctx, req)
if err != nil {
log.Error(ctx, "agent error", "err", err)
return Agent400JSONResponse{N400JSONResponse{err.Error()}}, nil
Expand All @@ -45,21 +45,21 @@ func (s *Server) Agent(ctx context.Context, request AgentRequestObject) (AgentRe
return Agent400JSONResponse{N400JSONResponse{err.Error()}}, nil
}

agent, err = s.claimService.Agent(ctx, req, mediatype)
response, err = s.claimService.Agent(ctx, req, mediatype)
if err != nil {
log.Error(ctx, "agent error", "err", err)
return Agent400JSONResponse{N400JSONResponse{err.Error()}}, nil
}
}

return Agent200JSONResponse{
Body: agent.Body,
From: agent.From,
Id: agent.ID,
ThreadID: agent.ThreadID,
To: agent.To,
Typ: string(agent.Typ),
Type: string(agent.Type),
Body: response.Body,
From: response.From,
Id: response.ID,
ThreadID: response.ThreadID,
To: response.To,
Typ: string(response.Typ),
Type: string(response.Type),
}, nil
}

Expand Down
14 changes: 0 additions & 14 deletions internal/core/domain/agent.go

This file was deleted.

2 changes: 1 addition & 1 deletion internal/core/ports/claim_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ type ClaimService interface {
GetRevocationStatus(ctx context.Context, issuerDID w3c.DID, nonce uint64) (*verifiable.RevocationStatus, error)
GetByID(ctx context.Context, issID *w3c.DID, id uuid.UUID) (*domain.Claim, error)
GetCredentialQrCode(ctx context.Context, issID *w3c.DID, id uuid.UUID, hostURL string) (*GetCredentialQrCodeResponse, error)
Agent(ctx context.Context, req *AgentRequest, mediatype iden3comm.MediaType) (*domain.Agent, error)
Agent(ctx context.Context, req *AgentRequest, mediatype iden3comm.MediaType) (*iden3comm.BasicMessage, error)
GetAuthClaim(ctx context.Context, did *w3c.DID) (*domain.Claim, error)
GetFirstNonRevokedAuthClaim(ctx context.Context, did *w3c.DID) (*domain.Claim, error)
GetAuthClaimForPublishing(ctx context.Context, did *w3c.DID, state string) (*domain.Claim, error)
Expand Down
5 changes: 2 additions & 3 deletions internal/core/ports/discovery_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import (
"fmt"

"github.com/iden3/go-iden3-core/v2/w3c"
"github.com/iden3/iden3comm/v2"
comm "github.com/iden3/iden3comm/v2"
"github.com/iden3/iden3comm/v2/protocol"

"github.com/polygonid/sh-id-platform/internal/core/domain"
)

// DiscoveryService is the interface implemented by the discovery service
type DiscoveryService interface {
Agent(ctx context.Context, req *AgentRequest) (*domain.Agent, error)
Agent(ctx context.Context, req *AgentRequest) (*iden3comm.BasicMessage, error)
}

// NewDiscoveryAgentRequest validates the inputs and returns a new AgentRequest
Expand Down
25 changes: 18 additions & 7 deletions internal/core/services/claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ func (c *claim) GetCredentialQrCode(ctx context.Context, issID *w3c.DID, id uuid
}, nil
}

func (c *claim) Agent(ctx context.Context, req *ports.AgentRequest, mediatype iden3comm.MediaType) (*domain.Agent, error) {
func (c *claim) Agent(ctx context.Context, req *ports.AgentRequest, mediatype iden3comm.MediaType) (*iden3comm.BasicMessage, error) {
if !c.mediatypeManager.AllowMediaType(req.Type, mediatype) {
err := fmt.Errorf("unsupported media type '%s' for message type '%s'", mediatype, req.Type)
log.Error(ctx, "agent: unsupported media type", "err", err)
Expand Down Expand Up @@ -756,7 +756,7 @@ func (c *claim) canRevokeNonce(ctx context.Context, did *w3c.DID, querier db.Que
return canBeRevoked, nil
}

func (c *claim) getRevocationStatus(ctx context.Context, basicMessage *ports.AgentRequest) (*domain.Agent, error) {
func (c *claim) getRevocationStatus(ctx context.Context, basicMessage *ports.AgentRequest) (*iden3comm.BasicMessage, error) {
revData := &protocol.RevocationStatusRequestMessageBody{}
err := json.Unmarshal(basicMessage.Body, revData)
if err != nil {
Expand All @@ -769,18 +769,24 @@ func (c *claim) getRevocationStatus(ctx context.Context, basicMessage *ports.Age
return nil, fmt.Errorf("failed get revocation status: %w", err)
}

return &domain.Agent{
body, err := json.Marshal(protocol.RevocationStatusResponseMessageBody{RevocationStatus: *revStatus})
if err != nil {
log.Error(ctx, "marshaling body", "err", err)
return nil, err
}

return &iden3comm.BasicMessage{
ID: uuid.NewString(),
Type: protocol.RevocationStatusResponseMessageType,
ThreadID: basicMessage.ThreadID,
Body: protocol.RevocationStatusResponseMessageBody{RevocationStatus: *revStatus},
Body: body,
From: basicMessage.IssuerDID.String(),
To: basicMessage.UserDID.String(),
Typ: packers.MediaTypePlainMessage,
}, nil
}

func (c *claim) getAgentCredential(ctx context.Context, basicMessage *ports.AgentRequest) (*domain.Agent, error) {
func (c *claim) getAgentCredential(ctx context.Context, basicMessage *ports.AgentRequest) (*iden3comm.BasicMessage, error) {
fetchRequestBody := &protocol.CredentialFetchRequestMessageBody{}
err := json.Unmarshal(basicMessage.Body, fetchRequestBody)
if err != nil {
Expand Down Expand Up @@ -815,12 +821,17 @@ func (c *claim) getAgentCredential(ctx context.Context, basicMessage *ports.Agen
return nil, fmt.Errorf("failed to convert claim to w3cCredential: %w", err)
}

return &domain.Agent{
body, err := json.Marshal(protocol.IssuanceMessageBody{Credential: *vc})
if err != nil {
log.Error(ctx, "marshaling body", "err", err)
return nil, err
}
return &iden3comm.BasicMessage{
ID: uuid.NewString(),
Typ: packers.MediaTypePlainMessage,
Type: protocol.CredentialIssuanceResponseMessageType,
ThreadID: basicMessage.ThreadID,
Body: protocol.IssuanceMessageBody{Credential: *vc},
Body: body,
From: basicMessage.IssuerDID.String(),
To: basicMessage.UserDID.String(),
}, err
Expand Down
21 changes: 13 additions & 8 deletions internal/core/services/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/iden3/iden3comm/v2/packers"
"github.com/iden3/iden3comm/v2/protocol"

"github.com/polygonid/sh-id-platform/internal/core/domain"
"github.com/polygonid/sh-id-platform/internal/core/ports"
"github.com/polygonid/sh-id-platform/internal/log"
)
Expand All @@ -33,7 +32,7 @@ func NewDiscovery(mediatypeManager *MediaTypeManager, packerManager *iden3comm.P
return d
}

func (c *discovery) Agent(ctx context.Context, req *ports.AgentRequest) (*domain.Agent, error) {
func (c *discovery) Agent(ctx context.Context, req *ports.AgentRequest) (*iden3comm.BasicMessage, error) {
if !c.mediatypeManager.AllowMediaType(req.Type, req.Typ) {
err := fmt.Errorf("unsupported media type '%s' for message type '%s'", req.Typ, req.Type)
log.Error(ctx, "agent: unsupported media type", "err", err)
Expand Down Expand Up @@ -80,16 +79,22 @@ func (c *discovery) Agent(ctx context.Context, req *ports.AgentRequest) (*domain
to = req.UserDID.String()
}

return &domain.Agent{
body, err := json.Marshal(protocol.DiscoverFeatureDiscloseMessageBody{
Disclosures: disclosures,
})
if err != nil {
log.Error(ctx, "marshaling body", "err", err)
return nil, err
}

return &iden3comm.BasicMessage{
ID: uuid.NewString(),
Typ: packers.MediaTypePlainMessage,
Type: protocol.DiscoverFeatureDiscloseMessageType,
ThreadID: req.ThreadID,
Body: protocol.DiscoverFeatureDiscloseMessageBody{
Disclosures: disclosures,
},
From: from,
To: to,
Body: body,
From: from,
To: to,
}, nil
}

Expand Down

0 comments on commit 3d67cf9

Please sign in to comment.