Skip to content

Commit

Permalink
Merge pull request trustbloc#1608 from bstasyszyn/trust-registry-issu…
Browse files Browse the repository at this point in the history
…er-endpoint-2

feat: Update trust-registry issuer endpoint
  • Loading branch information
fqutishat authored Feb 27, 2024
2 parents 8207c3f + 2522f25 commit eb47629
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
5 changes: 3 additions & 2 deletions pkg/service/trustregistry/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ type CredentialMetadata struct {

// IssuancePolicyEvaluationRequest is a request payload for issuance policy evaluation service.
type IssuancePolicyEvaluationRequest struct {
AttestationVC *string `json:"attestation_vc,omitempty"`
IssuerDID string `json:"issuer_did"`
CredentialTypes []string `json:"credential_types"`
AttestationVC *[]string `json:"attestation_vc,omitempty"`
IssuerDID string `json:"issuer_did"`
}

// PresentationPolicyEvaluationRequest is a request payload for presentation policy evaluation service.
Expand Down
19 changes: 16 additions & 3 deletions pkg/service/trustregistry/trustregistry_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ func (s *Service) ValidateIssuance(
}

req := &IssuancePolicyEvaluationRequest{
IssuerDID: profile.SigningDID.DID,
IssuerDID: profile.SigningDID.DID,
CredentialTypes: getCredentialTypes(profile),
}

if profile.Checks.ClientAttestationCheck.Enabled {
Expand All @@ -97,14 +98,18 @@ func (s *Service) ValidateIssuance(
return err
}

for _, vc := range attestationVCs {
attestations := make([]string, len(attestationVCs))

for i, vc := range attestationVCs {
jwtVC, convertErr := vc.ToJWTString()
if convertErr != nil {
return fmt.Errorf("convert attestation vc to jwt: %w", convertErr)
}

req.AttestationVC = lo.ToPtr(jwtVC)
attestations[i] = jwtVC
}

req.AttestationVC = lo.ToPtr(attestations)
}

payload, err := json.Marshal(req)
Expand Down Expand Up @@ -332,3 +337,11 @@ func (s *Service) requestPolicyEvaluation(

return result, nil
}

func getCredentialTypes(profile *profileapi.Issuer) []string {
return lo.Map(profile.CredentialTemplates,
func(item *profileapi.CredentialTemplate, index int) string {
return item.Type
},
)
}
5 changes: 5 additions & 0 deletions pkg/service/trustregistry/trustregistry_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,11 @@ func createIssuerProfile(t *testing.T) *profileapi.Issuer {
Enabled: true,
},
},
CredentialTemplates: []*profileapi.CredentialTemplate{
{
Type: "VerifiedDocument",
},
},
}

return profile
Expand Down
5 changes: 3 additions & 2 deletions test/bdd/trustregistry/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ package main

// IssuerIssuanceRequest is a model for issuer issuance policy evaluation.
type IssuerIssuanceRequest struct {
AttestationVC *string `json:"attestation_vc,omitempty"`
IssuerDID string `json:"issuer_did"`
AttestationVC *[]string `json:"attestation_vc,omitempty"`
CredentialTypes []string `json:"credential_types"`
IssuerDID string `json:"issuer_did"`
}

// VerifierPresentationRequest is a model for verifier presentation policy evaluation.
Expand Down
4 changes: 2 additions & 2 deletions test/bdd/trustregistry/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ func (s *server) evaluateIssuerIssuancePolicy(w http.ResponseWriter, r *http.Req
return
}

if request.AttestationVC == nil || len(*request.AttestationVC) == 0 {
if len(request.CredentialTypes) == 0 {
s.writeResponse(
w, http.StatusBadRequest, "no attestation vc supplied")
w, http.StatusBadRequest, "no credential types supplied")

return
}
Expand Down

0 comments on commit eb47629

Please sign in to comment.