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

ID of credentials can now be dereferenced. #507

Merged
merged 9 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/docs.go

Large diffs are not rendered by default.

31 changes: 27 additions & 4 deletions doc/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,9 @@ definitions:
proof signed by `issuerKid`.
type: string
id:
description: Credential ID
description: |-
Credential ID. This is the same value as the id within the secured credential. It is typically a URL that can be
dereferenced. For example, `https://ssi-service.com/v1/credentials/48958871-6a6d-4a25-889f-88c9c6835780`.
type: string
issuerKid:
description: The KID of the private key used to sign `credentialJwt`.
Expand Down Expand Up @@ -1014,7 +1016,9 @@ definitions:
proof signed by `issuerKid`.
type: string
id:
description: Credential ID
description: |-
Credential ID. This is the same value as the id within the secured credential. It is typically a URL that can be
dereferenced. For example, `https://ssi-service.com/v1/credentials/48958871-6a6d-4a25-889f-88c9c6835780`.
type: string
issuerKid:
description: The KID of the private key used to sign `credentialJwt`.
Expand Down Expand Up @@ -1331,11 +1335,30 @@ definitions:
pkg_server_router.GetCredentialResponse:
properties:
credential:
$ref: '#/definitions/credential.VerifiableCredential'
allOf:
- $ref: '#/definitions/credential.VerifiableCredential'
description: |-
Verifiable Credential in the `application/vc+ld+json` format. The credential is secured with an external proof
using JWS. In other words, the `proof` field is not present. See `credentialJwt` for the secured Verifiable
Credential.
credentialJwt:
description: JWT representation of `credential`, secured with an external
proof signed by `issuerKid`.
type: string
id:
description: |-
Credential ID. This is the same value as the id within the secured credential. It is typically a URL that can be
dereferenced. For example, `https://ssi-service.com/v1/credentials/48958871-6a6d-4a25-889f-88c9c6835780`.
type: string
issuerKid:
description: The KID of the private key used to sign `credentialJwt`.
type: string
revoked:
description: Whether this credential is currently revoked.
type: boolean
suspended:
description: Whether this credential is currently suspended.
type: boolean
type: object
pkg_server_router.GetCredentialStatusListResponse:
properties:
Expand Down Expand Up @@ -2089,7 +2112,7 @@ paths:
- application/json
description: Get credential by id
parameters:
- description: ID
- description: ID of the credential within SSI-Service. Must be a UUID.
in: path
name: id
required: true
Expand Down
19 changes: 14 additions & 5 deletions integration/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,14 +389,14 @@ func get(url string) (string, error) {
return "", fmt.Errorf("status code not in the 200s. body: %s", string(body))
}

logrus.Infof("Received: %s", string(body))
logrus.Infof("Received: %s", prettyJSON(body))
return string(body), err
}

func put(url string, json string) (string, error) {
logrus.Printf("\nPerforming PUT request to: %s \n\nwith data: \n%s\n", url, json)
func put(url string, jsonData string) (string, error) {
logrus.Printf("\nPerforming PUT request to: %s \n\nwith data: \n%s\n", url, jsonData)

req, err := http.NewRequest(http.MethodPut, url, bytes.NewBuffer([]byte(json)))
req, err := http.NewRequest(http.MethodPut, url, bytes.NewBuffer([]byte(jsonData)))
if err != nil {
return "", errors.Wrap(err, "building http req")
}
Expand All @@ -419,11 +419,20 @@ func put(url string, json string) (string, error) {
}

logrus.Println("\nOutput:")
logrus.Println(bodyStr)
indentedBodyStr := prettyJSON(body)
logrus.Println(indentedBodyStr)

return bodyStr, err
}

func prettyJSON(body []byte) string {
var d any
_ = json.Unmarshal(body, &d)
indentedBody, _ := json.MarshalIndent(d, "", " ")
indentedBodyStr := string(indentedBody)
return indentedBodyStr
}

func getJSONFromFile(fileName string) string {
b, _ := testVectors.ReadFile("testdata/" + fileName)
return string(b)
Expand Down
3 changes: 2 additions & 1 deletion internal/credential/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import (
// Container acts as an abstraction over both possible credential representations
// JWT representations are parsed upon container creation, while the original JWT is maintained
type Container struct {
// Credential ID
// Credential ID. This is the same value as the id within the secured credential. It is typically a URL that can be
// dereferenced. For example, `https://ssi-service.com/v1/credentials/48958871-6a6d-4a25-889f-88c9c6835780`.
ID string `json:"id,omitempty"`

// The KID of the private key used to sign `credentialJwt`.
Expand Down
13 changes: 6 additions & 7 deletions pkg/server/router/credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ func (cr CredentialRouter) CreateCredential(c *gin.Context) {
}

type GetCredentialResponse struct {
ID string `json:"id"`
Credential *credsdk.VerifiableCredential `json:"credential,omitempty"`
CredentialJWT *keyaccess.JWT `json:"credentialJwt,omitempty"`
// The `id` of this credential within SSI-Service. Same as the `id` passed in the query parameter.
ID string `json:"id"`
credmodel.Container
}

// GetCredential godoc
Expand All @@ -137,7 +137,7 @@ type GetCredentialResponse struct {
// @Tags CredentialAPI
// @Accept json
// @Produce json
// @Param id path string true "ID"
// @Param id path string true "ID of the credential within SSI-Service. Must be a UUID."
// @Success 200 {object} GetCredentialResponse
// @Failure 400 {string} string "Bad request"
// @Failure 500 {string} string "Internal server error"
Expand All @@ -158,9 +158,8 @@ func (cr CredentialRouter) GetCredential(c *gin.Context) {
}

resp := GetCredentialResponse{
ID: gotCredential.ID,
Credential: gotCredential.Credential,
CredentialJWT: gotCredential.CredentialJWT,
ID: *id,
Container: gotCredential.Container,
}
framework.Respond(c, resp, http.StatusOK)
}
Expand Down
Loading