Skip to content

Commit

Permalink
fix: Adding prooftypes array to credential response
Browse files Browse the repository at this point in the history
  • Loading branch information
x1m3 committed Sep 6, 2024
1 parent 907f4fd commit 9cf0e20
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 21 deletions.
6 changes: 6 additions & 0 deletions api/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1898,6 +1898,7 @@ components:
- issuer
- credentialSchema
- proof
- proofTypes
properties:
id:
type: string
Expand Down Expand Up @@ -1927,6 +1928,11 @@ components:
credentialSchema:
$ref: '#/components/schemas/CredentialSchema'
x-omitempty: false
proofTypes:
type: array
items:
type: string
example: [ "BJJSignature2021" ]
proof:
type: null
displayMethod:
Expand Down
1 change: 1 addition & 0 deletions internal/api/api.gen.go

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

44 changes: 23 additions & 21 deletions internal/api/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/iden3/go-schema-processor/v2/verifiable"

"github.com/polygonid/sh-id-platform/internal/common"
"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/core/services"
"github.com/polygonid/sh-id-platform/internal/log"
Expand Down Expand Up @@ -288,7 +289,7 @@ func (s *Server) GetCredential(ctx context.Context, request GetCredentialRequest
return GetCredential500JSONResponse{N500JSONResponse{"invalid claim format"}}, nil
}

return GetCredential200JSONResponse(toGetCredential200Response(w3c)), nil
return GetCredential200JSONResponse(toGetCredential200Response(w3c, claim)), nil
}

// GetCredentialQrCode returns a GetCredentialQrCodeResponseObject universalLink, raw or deeplink type based on query parameter `type`
Expand Down Expand Up @@ -361,45 +362,46 @@ func toVerifiableDisplayMethod(s *DisplayMethod) *verifiable.DisplayMethod {
}
}

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

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

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

return GetCredentialResponse{
Context: claim.Context,
Context: w3cCredential.Context,
CredentialSchema: CredentialSchema{
claim.CredentialSchema.ID,
claim.CredentialSchema.Type,
w3cCredential.CredentialSchema.ID,
w3cCredential.CredentialSchema.Type,
},
CredentialStatus: claim.CredentialStatus,
CredentialSubject: claim.CredentialSubject,
CredentialStatus: w3cCredential.CredentialStatus,
CredentialSubject: w3cCredential.CredentialSubject,
ExpirationDate: claimExpiration,
Id: claim.ID,
Id: w3cCredential.ID,
IssuanceDate: claimIssuanceDate,
Issuer: claim.Issuer,
Proof: claim.Proof,
Type: claim.Type,
Issuer: w3cCredential.Issuer,
Proof: w3cCredential.Proof,
ProofTypes: getProofs(cred),
Type: w3cCredential.Type,
RefreshService: refreshService,
DisplayMethod: displayMethod,
}
Expand Down
3 changes: 3 additions & 0 deletions internal/api/credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,7 @@ func TestServer_GetCredential(t *testing.T) {
fixture.CreateIdentity(t, identity)

claim := fixture.NewClaim(t, identity.Identifier)
claim.MtProof = true
fixture.CreateClaim(t, claim)

query := repositories.ExecQueryParams{
Expand Down Expand Up @@ -820,6 +821,7 @@ func TestServer_GetCredential(t *testing.T) {
Id: "https://refresh-service.xyz",
Type: RefreshServiceType(verifiable.Iden3RefreshService2023),
},
ProofTypes: []string{"SparseMerkleTreeProof"},
},
},
},
Expand Down Expand Up @@ -1548,6 +1550,7 @@ func validateCredential(t *testing.T, resp, tc GetCredentialResponse) {
assert.NoError(t, mapstructure.Decode(tc.CredentialSubject, &tcCredentialSubject))
assert.EqualValues(t, responseCredentialSubject, tcCredentialSubject)
}
assert.Equal(t, resp.ProofTypes, tc.ProofTypes)

assert.NoError(t, mapstructure.Decode(resp.CredentialStatus, &responseCredentialStatus))
responseCredentialStatus.ID = strings.Replace(responseCredentialStatus.ID, "%3A", ":", -1)
Expand Down

0 comments on commit 9cf0e20

Please sign in to comment.