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

refactor: disabled JSON-LD checks for VPs with JWT VCs by default #3540

Merged
merged 1 commit into from
Feb 28, 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
25 changes: 19 additions & 6 deletions pkg/doc/verifiable/presentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,13 @@ func (rp *rawPresentation) UnmarshalJSON(data []byte) error {

// presentationOpts holds options for the Verifiable Presentation decoding.
type presentationOpts struct {
publicKeyFetcher PublicKeyFetcher
disabledProofCheck bool
ldpSuites []verifier.SignatureSuite
strictValidation bool
requireVC bool
requireProof bool
publicKeyFetcher PublicKeyFetcher
disabledProofCheck bool
ldpSuites []verifier.SignatureSuite
strictValidation bool
requireVC bool
requireProof bool
disableJSONLDChecks bool

jsonldCredentialOpts
}
Expand Down Expand Up @@ -402,6 +403,14 @@ func WithPresJSONLDDocumentLoader(documentLoader jsonld.DocumentLoader) Presenta
}
}

// WithDisabledJSONLDChecks disables JSON-LD checks for VP parsing.
// By default, JSON-LD checks are enabled.
func WithDisabledJSONLDChecks() PresentationOpt {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please specify in comments atleast, what you mean by JSON LD checks, is it JSON LD Schema Validation?

return func(opts *presentationOpts) {
opts.disableJSONLDChecks = true
}
}

// ParsePresentation creates an instance of Verifiable Presentation by reading a JSON document from bytes.
// It also applies miscellaneous options like custom decoders or settings of schema validation.
func ParsePresentation(vpData []byte, opts ...PresentationOpt) (*Presentation, error) {
Expand Down Expand Up @@ -548,6 +557,10 @@ func validateVP(data []byte, opts *presentationOpts) error {
return err
}

if opts.disableJSONLDChecks {
return nil
}

return validateVPJSONLD(data, opts)
}

Expand Down
22 changes: 22 additions & 0 deletions pkg/doc/verifiable/presentation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ const validPresentationWithCustomFields = `
}
`

//go:embed testdata/validPresentationWithJWTVC.jsonld
var validPresentationWithJWTVC []byte //nolint:gochecknoglobals

//go:embed testdata/context/presentation_submission_v1.jsonld
var presentationSubmissionV1 []byte //nolint:gochecknoglobals

Expand Down Expand Up @@ -293,6 +296,25 @@ func TestParsePresentation(t *testing.T) {
require.EqualError(t, err, "JSON-LD doc has different structure after compaction")
require.Nil(t, vp)
})

t.Run("parsing VP with a JWT VC succeeds", func(t *testing.T) {
loader := createTestDocumentLoader(t, ldcontext.Document{
URL: "https://trustbloc.github.io/context/vc/presentation-exchange-submission-v1.jsonld",
Content: presentationSubmissionV1,
})

vp, err := ParsePresentation(validPresentationWithJWTVC, WithPresDisabledProofCheck(),
WithPresJSONLDDocumentLoader(loader))
require.NoError(t, err)
require.NotNil(t, vp)
})

t.Run("parsing VP with a JWT VC with required JSON-LD checks succeeds", func(t *testing.T) {
vp, err := ParsePresentation(validPresentationWithJWTVC, WithPresDisabledProofCheck(),
WithDisabledJSONLDChecks())
require.NoError(t, err)
require.NotNil(t, vp)
})
}

func TestValidateVP_Context(t *testing.T) {
Expand Down
29 changes: 29 additions & 0 deletions pkg/doc/verifiable/testdata/validPresentationWithJWTVC.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"@context":[
"https://www.w3.org/2018/credentials/v1",
"https://identity.foundation/presentation-exchange/submission/v1"
],
"presentation_submission":{
"id":"0137f0ec-6676-4123-a374-4cc3a4262458",
"definition_id":"32f54163-7166-48f1-93d8-ff217bdb0153",
"descriptor_map":[
{
"id":"VerifiedEmployee",
"format":"jwt_vp",
"path":"$",
"path_nested":{
"id":"VerifiedEmployee",
"format":"jwt_vc",
"path":"$.verifiableCredential[0]"
}
}
]
},
"type":[
"VerifiablePresentation",
"PresentationSubmission"
],
"verifiableCredential":[
"eyJhbGciOiJFUzI1NksiLCJraWQiOiJkaWQ6b3JiOnVBQUE6RWlEVHhIVz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