Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into update-is-valid
Browse files Browse the repository at this point in the history
  • Loading branch information
andresuribe87 authored Jun 7, 2023
2 parents b41f27a + 2ba63e1 commit f72785d
Show file tree
Hide file tree
Showing 14 changed files with 497 additions and 225 deletions.
2 changes: 1 addition & 1 deletion doc/docs.go

Large diffs are not rendered by default.

39 changes: 34 additions & 5 deletions doc/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1073,23 +1073,51 @@ definitions:
pkg_server_router.CreateManifestRequest:
properties:
description:
description: |-
Explains what the Manifest in question is generally offering in exchange for meeting its requirements.
Optional.
type: string
format:
$ref: '#/definitions/exchange.ClaimFormat'
allOf:
- $ref: '#/definitions/exchange.ClaimFormat'
description: |-
Formats that the issuer can support when issuing the credential. At least one needs to be set. We currently only
support `jwt_vc` for issuance. See https://identity.foundation/claim-format-registry/#registry for the definition.
TODO: support different claim formats https://github.com/TBD54566975/ssi-service/issues/96
issuerDid:
description: |-
DID that identifies who the issuer of the credential(s) will be.
Required.
type: string
issuerKid:
description: |-
The KID of the private key that will be used when signing issued credentials.
Required.
type: string
issuerName:
description: |-
Human-readable name the Issuer wishes to be recognized by.
Optional.
type: string
name:
description: |-
Summarizing title for the Manifest in question.
Optional.
type: string
outputDescriptors:
description: Array of objects as defined in https://identity.foundation/credential-manifest/#output-descriptor.
items:
$ref: '#/definitions/manifest.OutputDescriptor'
type: array
presentationDefinition:
$ref: '#/definitions/exchange.PresentationDefinition'
allOf:
- $ref: '#/definitions/exchange.PresentationDefinition'
description: value of the presentation definition to use. Must be empty if
`id` is present.
presentationDefinitionId:
description: id of the presentation definition created with PresentationDefinitionAPI.
Must be empty if `value` is present.
type: string
required:
- format
- issuerDid
Expand Down Expand Up @@ -1961,8 +1989,9 @@ paths:
get:
consumes:
- application/json
description: Checks for the presence of a query parameter and calls the associated
filtered get method. Only one parameter is allowed to be specified.
description: Checks for the presence of an optional query parameter and calls
the associated filtered get method. Only one optional parameter is allowed
to be specified.
parameters:
- description: The issuer id
example: did:key:z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp
Expand Down Expand Up @@ -2590,7 +2619,7 @@ paths:
put:
consumes:
- application/json
description: Create manifest
description: Create manifest. Most fields map to the definitions from https://identity.foundation/credential-manifest/#general-composition.
parameters:
- description: request body
in: body
Expand Down
6 changes: 6 additions & 0 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ func Spec() error {
return err
}

// We need to download deps first as a workaround to https://github.com/TBD54566975/ssi-service/issues/515
if err := sh.Run(Go, "mod", "download"); err != nil {
logrus.WithError(err).Error("failed to download dependencies")
return err
}

if err := sh.Run(swagCommand, "fmt", "-d", "pkg/server/router"); err != nil {
logrus.WithError(err).Error("failed to format swagger docs")
return err
Expand Down
33 changes: 25 additions & 8 deletions pkg/server/router/credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ type ListCredentialsResponse struct {
// ListCredentials godoc
//
// @Summary List Credentials
// @Description Checks for the presence of a query parameter and calls the associated filtered get method. Only one parameter is allowed to be specified.
// @Description Checks for the presence of an optional query parameter and calls the associated filtered get method. Only one optional parameter is allowed to be specified.
// @Tags CredentialAPI
// @Accept json
// @Produce json
Expand All @@ -413,30 +413,47 @@ func (cr CredentialRouter) ListCredentials(c *gin.Context) {
schema := framework.GetQueryValue(c, SchemaParam)
subject := framework.GetQueryValue(c, SubjectParam)

errMsg := "must use one of the following query parameters: issuer, subject, schema"
errMsg := "must use only one of the following optional query parameters: issuer, subject, schema"

// check if there are multiple parameters set, which is not allowed
if (issuer != nil && subject != nil) || (issuer != nil && schema != nil) || (subject != nil && schema != nil) {
framework.LoggingRespondErrMsg(c, errMsg, http.StatusBadRequest)
return
}

if issuer == nil && schema == nil && subject == nil {
cr.listCredentials(c)
return
}
if issuer != nil {
cr.getCredentialsByIssuer(c, *issuer)
cr.listCredentialsByIssuer(c, *issuer)
return
}
if subject != nil {
cr.getCredentialsBySubject(c, *subject)
cr.listCredentialsBySubject(c, *subject)
return
}
if schema != nil {
cr.getCredentialsBySchema(c, *schema)
cr.listCredentialsBySchema(c, *schema)
return
}

framework.LoggingRespondErrMsg(c, errMsg, http.StatusBadRequest)
}

func (cr CredentialRouter) getCredentialsByIssuer(c *gin.Context, issuer string) {
func (cr CredentialRouter) listCredentials(c *gin.Context) {
gotCredentials, err := cr.service.ListCredentials(c)
if err != nil {
errMsg := fmt.Sprintf("could not get credentials")
framework.LoggingRespondErrWithMsg(c, err, errMsg, http.StatusInternalServerError)
return
}

resp := ListCredentialsResponse{Credentials: gotCredentials.Credentials}
framework.Respond(c, resp, http.StatusOK)
}

func (cr CredentialRouter) listCredentialsByIssuer(c *gin.Context, issuer string) {
gotCredentials, err := cr.service.ListCredentialsByIssuer(c, credential.ListCredentialByIssuerRequest{Issuer: issuer})
if err != nil {
errMsg := fmt.Sprintf("could not get credentials for issuer: %s", util.SanitizeLog(issuer))
Expand All @@ -449,7 +466,7 @@ func (cr CredentialRouter) getCredentialsByIssuer(c *gin.Context, issuer string)
return
}

func (cr CredentialRouter) getCredentialsBySubject(c *gin.Context, subject string) {
func (cr CredentialRouter) listCredentialsBySubject(c *gin.Context, subject string) {
gotCredentials, err := cr.service.ListCredentialsBySubject(c, credential.ListCredentialBySubjectRequest{Subject: subject})
if err != nil {
errMsg := fmt.Sprintf("could not get credentials for subject: %s", util.SanitizeLog(subject))
Expand All @@ -461,7 +478,7 @@ func (cr CredentialRouter) getCredentialsBySubject(c *gin.Context, subject strin
framework.Respond(c, resp, http.StatusOK)
}

func (cr CredentialRouter) getCredentialsBySchema(c *gin.Context, schema string) {
func (cr CredentialRouter) listCredentialsBySchema(c *gin.Context, schema string) {
gotCredentials, err := cr.service.ListCredentialsBySchema(c, credential.ListCredentialBySchemaRequest{Schema: schema})
if err != nil {
errMsg := fmt.Sprintf("could not get credentials for schema: %s", util.SanitizeLog(schema))
Expand Down
58 changes: 41 additions & 17 deletions pkg/server/router/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,50 @@ func NewManifestRouter(s svcframework.Service) (*ManifestRouter, error) {
// CreateManifestRequest is the request body for creating a manifest, which populates all remaining fields
// and builds a well-formed manifest object.
type CreateManifestRequest struct {
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
IssuerDID string `json:"issuerDid" validate:"required"`
IssuerKID string `json:"issuerKid" validate:"required"`
IssuerName *string `json:"issuerName,omitempty"`
ClaimFormat *exchange.ClaimFormat `json:"format" validate:"required,dive"`
OutputDescriptors []manifestsdk.OutputDescriptor `json:"outputDescriptors" validate:"required,dive"`
PresentationDefinition *exchange.PresentationDefinition `json:"presentationDefinition,omitempty" validate:"omitempty,dive"`
// Summarizing title for the Manifest in question.
// Optional.
Name *string `json:"name,omitempty"`

// Explains what the Manifest in question is generally offering in exchange for meeting its requirements.
// Optional.
Description *string `json:"description,omitempty"`

// DID that identifies who the issuer of the credential(s) will be.
// Required.
IssuerDID string `json:"issuerDid" validate:"required"`

// The KID of the private key that will be used when signing issued credentials.
// Required.
IssuerKID string `json:"issuerKid" validate:"required"`

// Human-readable name the Issuer wishes to be recognized by.
// Optional.
IssuerName *string `json:"issuerName,omitempty"`

// Formats that the issuer can support when issuing the credential. At least one needs to be set. We currently only
// support `jwt_vc` for issuance. See https://identity.foundation/claim-format-registry/#registry for the definition.
// TODO: support different claim formats https://github.com/TBD54566975/ssi-service/issues/96
ClaimFormat *exchange.ClaimFormat `json:"format" validate:"required,dive"`

// Array of objects as defined in https://identity.foundation/credential-manifest/#output-descriptor.
OutputDescriptors []manifestsdk.OutputDescriptor `json:"outputDescriptors" validate:"required,dive"`

// Describes what proofs are required in order to issue this credential. When present, only `id` or `value` may be
// populated, but not both.
// Optional.
*model.PresentationDefinitionRef
}

func (c CreateManifestRequest) ToServiceRequest() model.CreateManifestRequest {
return model.CreateManifestRequest{
Name: c.Name,
Description: c.Description,
IssuerDID: c.IssuerDID,
IssuerKID: c.IssuerKID,
IssuerName: c.IssuerName,
OutputDescriptors: c.OutputDescriptors,
ClaimFormat: c.ClaimFormat,
PresentationDefinition: c.PresentationDefinition,
Name: c.Name,
Description: c.Description,
IssuerDID: c.IssuerDID,
IssuerKID: c.IssuerKID,
IssuerName: c.IssuerName,
OutputDescriptors: c.OutputDescriptors,
ClaimFormat: c.ClaimFormat,
PresentationDefinitionRef: c.PresentationDefinitionRef,
}
}

Expand All @@ -74,7 +98,7 @@ type CreateManifestResponse struct {
// CreateManifest godoc
//
// @Summary Create manifest
// @Description Create manifest
// @Description Create manifest. Most fields map to the definitions from https://identity.foundation/credential-manifest/#general-composition.
// @Tags ManifestAPI
// @Accept json
// @Produce json
Expand Down
Loading

0 comments on commit f72785d

Please sign in to comment.