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

Uptake JSON Schema for FPWD #494

Merged
merged 12 commits into from
May 31, 2023
Merged

Uptake JSON Schema for FPWD #494

merged 12 commits into from
May 31, 2023

Conversation

decentralgabe
Copy link
Member

@decentralgabe decentralgabe commented May 26, 2023

Fixes #493

  • refactored some cred logic along the way
  • refactored some config logic to include base paths, needed for surfacing querying of schemas
  • disabled signing schemas for now; to be re-enabled in Support CredentialSchema2023 #501

@decentralgabe decentralgabe marked this pull request as ready for review May 30, 2023 20:55
@@ -129,22 +129,26 @@ func newRequestContextWithParams(w http.ResponseWriter, req *http.Request, param
return c
}

func getValidManifestRequest(issuerDID, issuerKID, schemaID string) model.CreateManifestRequest {
func getValidCreateManifestRequest(issuerDID, issuerKID, schemaID string) model.CreateManifestRequest {
return model.CreateManifestRequest{
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated this test to use real input/output descriptors for readability

if request.SchemaID != "" {
// resolve schema and save it for validation later
gotSchema, err := s.schema.GetSchema(ctx, schema.GetSchemaRequest{ID: request.SchemaID})
if err != nil {
return nil, sdkutil.LoggingErrorMsgf(err, "failed to create credential; could not get schema: %s", request.SchemaID)
}
knownSchema = &gotSchema.Schema

schemaType := schemalib.CredentialSchema2023Type
if gotSchema.CredentialSchema == nil {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for now this branch will always be true

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in other places, I think we should completely remove.

@@ -0,0 +1,97 @@
package credential
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved this to another file for readability

@codecov-commenter
Copy link

Codecov Report

Merging #494 (e5e95da) into main (47db532) will increase coverage by 0.44%.
The diff coverage is 12.21%.

❗ Current head e5e95da differs from pull request most recent head dfa57f6. Consider uploading reports for the commit dfa57f6 to get more accurate results

@@            Coverage Diff             @@
##             main     #494      +/-   ##
==========================================
+ Coverage   20.57%   21.02%   +0.44%     
==========================================
  Files          48       49       +1     
  Lines        5769     5803      +34     
==========================================
+ Hits         1187     1220      +33     
+ Misses       4373     4358      -15     
- Partials      209      225      +16     
Impacted Files Coverage Δ
integration/common.go 1.96% <ø> (ø)
pkg/server/router/did.go 4.73% <ø> (ø)
pkg/server/router/schema.go 9.63% <0.00%> (+0.84%) ⬆️
pkg/server/server.go 68.05% <0.00%> (-0.15%) ⬇️
pkg/service/credential/model.go 0.00% <ø> (ø)
pkg/service/credential/service.go 0.00% <0.00%> (ø)
pkg/service/credential/status.go 0.00% <0.00%> (ø)
pkg/service/credential/storage.go 1.68% <0.00%> (ø)
pkg/service/did/handler.go 0.00% <0.00%> (ø)
pkg/service/did/resolution/resolver.go 0.00% <0.00%> (ø)
... and 6 more

BaseServiceConfig: new(BaseServiceConfig),
}
}
services.DIDConfig.ServiceEndpoint = endpoint + "/dids"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone sets the service_endpoint for a single service and not others, seems like this will override. Is that intentional? Should defaults be applied before decoding the file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to be refactored because we don't want to enable config for setting service endpoints. I'll open a new issue

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -155,6 +165,14 @@ func TestManifestRouter(t *testing.T) {
ID: storage.StatusObjectID(createdApplicationResponseOp.ID),
Approved: true,
Reason: "ApprovalMan is here",
CredentialOverrides: map[string]model.CredentialOverride{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add this here? I.e. was there a test that was failing? Or was the test not exercising the desired behavior?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the schema the test was using did not have any required fields - so it wasn't a great test. once I added them this is necessary

Comment on lines 33 to 34
Name string `json:"name" validate:"required"`
Description string `json:"description,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind adding godocs for these two fields?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Schema schemalib.JSONSchema `json:"schema" validate:"required"`

// TODO(gabe): re-enable in https://github.com/TBD54566975/ssi-service/issues/493
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand why this change requires disabling an already existing feature. Was it broken?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a slightly different feature, since before we weren't creating credentials just JWTs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not keep the verification endpoint?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since it will be a credential and we already have a credential verification endpoint

we could add a new endpoint to see whether a cred is valid against a schema - but that's a new ticket

Reason string `json:"reason,omitempty"`
ID string `json:"id"`
Schema schema.JSONSchema `json:"schema"`
CredentialSchema *keyaccess.JWT `json:"credentialSchema,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be returned from the schema.Service.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

going to remove this and save it for the next issue

SchemaJWT *keyaccess.JWT `json:"schemaJwt,omitempty"`
ID string `json:"id"`
Schema schema.JSONSchema `json:"schema"`
CredentialSchema *keyaccess.JWT `json:"credentialSchema,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above. Suggestion is that schema.Service only stores plain schemas.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's take this in the next issue

}

// TODO(gabe) support signing credential schemas
// create schema
storedSchema := StoredSchema{ID: schemaID, Schema: jsonSchema}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two IDs within a StoredSchema: id and schema.$id. I think it's easily confused. Would it make sense to only have one?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the reason for two: when you view the schema on it's own you need a fully qualified URI to resolve it (e.g. tbd.website/schemas/01841408-1408140148

when you are talking to the service, it is awkward to request anything but 01841408-1408140148

so 01841408-1408140148 is the service identifier, whereas the $id is the fully qualified identifier

return nil, nil
}
var stored []StoredSchema
for _, schemaBytes := range gotSchemas {
var nextSchema StoredSchema
if err := json.Unmarshal(schemaBytes, &nextSchema); err == nil {
if err = json.Unmarshal(schemaBytes, &nextSchema); err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invert the order to reduce nesting:

if err != nil {
  // log here
  continue
}
stored = append(stored, nextSchema)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if request.SchemaID != "" {
// resolve schema and save it for validation later
gotSchema, err := s.schema.GetSchema(ctx, schema.GetSchemaRequest{ID: request.SchemaID})
if err != nil {
return nil, sdkutil.LoggingErrorMsgf(err, "failed to create credential; could not get schema: %s", request.SchemaID)
}
knownSchema = &gotSchema.Schema

schemaType := schemalib.CredentialSchema2023Type
if gotSchema.CredentialSchema == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in other places, I think we should completely remove.

@decentralgabe decentralgabe merged commit e76fb15 into main May 31, 2023
@decentralgabe decentralgabe deleted the update-schema-fpwd branch May 31, 2023 20:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Uptake of the FPWD of VC JSON Schema
3 participants