Skip to content

Commit

Permalink
feat: Unify responses in get credential and get credentials (#801)
Browse files Browse the repository at this point in the history
* feat: Changes in getCredential Response

* feat: Changes in getCredentials Response

* feat: GetConnection and GetConnections use same Credential Entity

* feat: Rename CredentialW3C to Credential and remove old API credential entities
  • Loading branch information
x1m3 authored Sep 30, 2024
1 parent b27c991 commit 4ab6052
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 323 deletions.
122 changes: 17 additions & 105 deletions api/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/GetCredentialResponse'
$ref: '#/components/schemas/Credential'
'400':
$ref: '#/components/responses/400'
'401':
Expand Down Expand Up @@ -1803,71 +1803,6 @@ components:
type: string
x-omitempty: false

Credential:
type: object
required:
- id
- proofTypes
- createdAt
- expired
- schemaHash
- schemaType
- schemaUrl
- revNonce
- credentialSubject
- revoked
- userID
properties:
id:
type: string
x-go-type: uuid.UUID
x-go-type-import:
name: uuid
path: github.com/google/uuid
example: 8edd8112-c415-11ed-b036-debe37e1cbd6
proofTypes:
type: array
items:
type: string
example: [ "BJJSignature2021" ]
createdAt:
$ref: '#/components/schemas/TimeUTC'
expiresAt:
$ref: '#/components/schemas/TimeUTC'
expired:
type: boolean
example: true
schemaHash:
type: string
example: "c9b2370371b7fa8b3dab2a5ba81b6838"
schemaType:
type: string
example: "KYCAgeCredential"
schemaUrl:
type: string
example: "https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json/KYCAgeCredential-v3.json"
revoked:
type: boolean
example: false
revNonce:
type: integer
format: uint64
example: 2136005230
credentialSubject:
type: object
x-omitempty: false
example:
birthday: 19960424
documentType: 2
id: "did:polygonid:polygon:amoy:2qDDDKmo436EZGCBAvkqZjADYoNRJszkG7UymZeCHQ"
userID:
type: string
example: did:polygonid:polygon:amoy:2qFpPHotk6oyaX1fcrpQFT4BMnmg8YszUwxYtaoGoe
refreshService:
$ref: '#/components/schemas/RefreshService'
displayMethod:
$ref: '#/components/schemas/DisplayMethod'

AuthenticationConnection:
type: object
required:
Expand Down Expand Up @@ -1896,58 +1831,35 @@ components:
connection:
$ref: '#/components/schemas/AuthenticationConnection'

GetCredentialResponse:
Credential:
type: object
required:
- id
- "@context"
- type
- credentialSubject
- credentialStatus
- issuer
- credentialSchema
- proof
- proofTypes
- revoked
- schemaHash
- vc
properties:
id:
type: string
x-omitempty: false
"@context":
type: array
x-omitempty: false
items:
type: string
type:
type: array
x-omitempty: false
items:
type: string
expirationDate:
$ref: '#/components/schemas/TimeUTC'
issuanceDate:
$ref: '#/components/schemas/TimeUTC'
credentialSubject:
type: object
x-omitempty: false
credentialStatus:
type: null
issuer:
type: string
x-omitempty: false
credentialSchema:
$ref: '#/components/schemas/CredentialSchema'
x-omitempty: false
proofTypes:
type: array
items:
type: string
example: [ "BJJSignature2021" ]
proof:
type: null
displayMethod:
$ref: '#/components/schemas/DisplayMethod'
refreshService:
$ref: '#/components/schemas/RefreshService'
revoked:
type: boolean
example: false
schemaHash:
type: string
example: "c9b2370371b7fa8b3dab2a5ba81b6838"
vc:
type: object
x-go-type: verifiable.W3CCredential
x-go-type-import:
name: verifiable
path: "github.com/iden3/go-schema-processor/v2/verifiable"

QrCodeLinkShortResponse:
type: object
Expand Down
45 changes: 7 additions & 38 deletions internal/api/api.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions internal/api/connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/polygonid/sh-id-platform/internal/core/services"
"github.com/polygonid/sh-id-platform/internal/log"
"github.com/polygonid/sh-id-platform/internal/sqltools"
"github.com/polygonid/sh-id-platform/pkg/schema"
)

// GetConnections returns the list of connections of a determined issuer
Expand Down Expand Up @@ -163,13 +162,13 @@ func (s *Server) GetConnection(ctx context.Context, request GetConnectionRequest
return GetConnection500JSONResponse{N500JSONResponse{"There was an error retrieving the connection"}}, nil
}

w3credentials, err := schema.FromClaimsModelToW3CCredential(credentials)
resp, err := connectionResponse(conn, credentials)
if err != nil {
log.Debug(ctx, "get connection internal server error converting credentials to w3c", "err", err, "req", request)
log.Error(ctx, "get connection internal server error converting credentials to w3c", "err", err)
return GetConnection500JSONResponse{N500JSONResponse{"There was an error parsing the credential of the given connection"}}, nil
}

return GetConnection200JSONResponse(connectionResponse(conn, w3credentials, credentials)), nil
return GetConnection200JSONResponse(resp), nil
}

// DeleteConnectionCredentials deletes all the credentials of the given connection
Expand Down
51 changes: 8 additions & 43 deletions internal/api/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func (s *Server) GetCredentials(ctx context.Context, request GetCredentialsReque
log.Error(ctx, "creating credentials response", "err", err, "req", request)
return GetCredentials500JSONResponse{N500JSONResponse{"Invalid claim format"}}, nil
}
response[i] = credentialResponse(w3c, credential)
response[i] = toGetCredential200Response(w3c, credential)
}

resp := GetCredentials200JSONResponse{
Expand Down Expand Up @@ -363,48 +363,13 @@ func toVerifiableDisplayMethod(s *DisplayMethod) *verifiable.DisplayMethod {
}
}

func toGetCredential200Response(w3cCredential *verifiable.W3CCredential, cred *domain.Claim) GetCredentialResponse {
var claimExpiration, claimIssuanceDate *TimeUTC
if w3cCredential.Expiration != nil {
claimExpiration = common.ToPointer(TimeUTC(*w3cCredential.Expiration))
}
if w3cCredential.IssuanceDate != nil {
claimIssuanceDate = common.ToPointer(TimeUTC(*w3cCredential.IssuanceDate))
}

var refreshService *RefreshService
if w3cCredential.RefreshService != nil {
refreshService = &RefreshService{
Id: w3cCredential.RefreshService.ID,
Type: RefreshServiceType(w3cCredential.RefreshService.Type),
}
}

var displayMethod *DisplayMethod
if w3cCredential.DisplayMethod != nil {
displayMethod = &DisplayMethod{
Id: w3cCredential.DisplayMethod.ID,
Type: DisplayMethodType(w3cCredential.DisplayMethod.Type),
}
}

return GetCredentialResponse{
Context: w3cCredential.Context,
CredentialSchema: CredentialSchema{
w3cCredential.CredentialSchema.ID,
w3cCredential.CredentialSchema.Type,
},
CredentialStatus: w3cCredential.CredentialStatus,
CredentialSubject: w3cCredential.CredentialSubject,
ExpirationDate: claimExpiration,
Id: w3cCredential.ID,
IssuanceDate: claimIssuanceDate,
Issuer: w3cCredential.Issuer,
Proof: w3cCredential.Proof,
ProofTypes: getProofs(cred),
Type: w3cCredential.Type,
RefreshService: refreshService,
DisplayMethod: displayMethod,
func toGetCredential200Response(w3cCredential *verifiable.W3CCredential, cred *domain.Claim) Credential {
return Credential{
Vc: *w3cCredential,
Id: cred.ID.String(),
Revoked: cred.Revoked,
SchemaHash: cred.SchemaHash,
ProofTypes: getProofs(cred),
}
}

Expand Down
Loading

0 comments on commit 4ab6052

Please sign in to comment.