Skip to content

Commit

Permalink
Merge branch 'develop-v2' into feature/PID-2297-migrate-ui-on-core-api
Browse files Browse the repository at this point in the history
  • Loading branch information
amonsosanz committed Oct 9, 2024
2 parents d30eb68 + 290b08b commit 81eee46
Show file tree
Hide file tree
Showing 24 changed files with 249 additions and 351 deletions.
124 changes: 19 additions & 105 deletions api/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ paths:
$ref: '#/components/responses/401'
'403':
$ref: '#/components/responses/403'
'409':
$ref: '#/components/responses/409'
'500':
$ref: '#/components/responses/500'
get:
Expand Down Expand Up @@ -753,7 +755,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 +1805,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 +1833,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
3 changes: 1 addition & 2 deletions cmd/notifications/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ func newCredentialsService(ctx context.Context, cfg *config.Configuration, stora

rhsFactory := reverse_hash.NewFactory(*networkResolver, reverse_hash.DefaultRHSTimeOut)
revocationStatusResolver := revocation_status.NewRevocationStatusResolver(*networkResolver)
// TODO: Cache only if cfg.APIUI.SchemaCache == true
schemaLoader := loader.NewDocumentLoader(cfg.IPFS.GatewayURL)
schemaLoader := loader.NewDocumentLoader(cfg.IPFS.GatewayURL, cfg.SchemaCache)

mtService := services.NewIdentityMerkleTrees(mtRepository)
qrService := services.NewQrStoreService(cachex)
Expand Down
2 changes: 1 addition & 1 deletion cmd/pending_publisher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func main() {
}(storage)

// TODO: Cache only if cfg.APIUI.SchemaCache == true
schemaLoader := loader.NewDocumentLoader(cfg.IPFS.GatewayURL)
schemaLoader := loader.NewDocumentLoader(cfg.IPFS.GatewayURL, cfg.SchemaCache)

vaultCfg := providers.Config{
UserPassAuthEnabled: cfg.KeyStore.VaultUserPassAuthEnabled,
Expand Down
2 changes: 1 addition & 1 deletion cmd/platform/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func main() {
}

// TODO: Cache only if cfg.APIUI.SchemaCache == true
schemaLoader := loader.NewDocumentLoader(cfg.IPFS.GatewayURL)
schemaLoader := loader.NewDocumentLoader(cfg.IPFS.GatewayURL, cfg.SchemaCache)

vaultCfg := providers.Config{
UserPassAuthEnabled: cfg.KeyStore.VaultUserPassAuthEnabled,
Expand Down
54 changes: 16 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 81eee46

Please sign in to comment.