diff --git a/cmd/aries-agent-mobile/go.mod b/cmd/aries-agent-mobile/go.mod index 8892e7e5d..da6ec0b95 100644 --- a/cmd/aries-agent-mobile/go.mod +++ b/cmd/aries-agent-mobile/go.mod @@ -8,8 +8,8 @@ go 1.19 require ( github.com/google/uuid v1.3.0 - github.com/hyperledger/aries-framework-go v0.1.8-0.20220322085443-50e8f9bd208b - github.com/hyperledger/aries-framework-go/component/storageutil v0.0.0-20220322085443-50e8f9bd208b + github.com/hyperledger/aries-framework-go v0.1.9-0.20221007132211-6233891ce372 + github.com/hyperledger/aries-framework-go/component/storageutil v0.1.9-0.20221007132211-6233891ce372 github.com/hyperledger/aries-framework-go/spi v0.0.0-20220606124520-53422361c38c github.com/hyperledger/aries-framework-go/test/component v0.0.0-20220428211718-66cc046674a1 github.com/piprate/json-gold v0.4.1 @@ -49,6 +49,7 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/pquerna/cachecontrol v0.1.0 // indirect github.com/rs/cors v1.7.0 // indirect + github.com/santhosh-tekuri/jsonschema v1.2.4 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/square/go-jose/v3 v3.0.0-20200630053402-0a67ce9b0693 // indirect github.com/teserakt-io/golang-ed25519 v0.0.0-20210104091850-3888c087a4c8 // indirect diff --git a/cmd/aries-agent-mobile/go.sum b/cmd/aries-agent-mobile/go.sum index aad427cd6..bcea1cc65 100644 --- a/cmd/aries-agent-mobile/go.sum +++ b/cmd/aries-agent-mobile/go.sum @@ -270,6 +270,8 @@ github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc= +github.com/santhosh-tekuri/jsonschema v1.2.4 h1:hNhW8e7t+H1vgY+1QeEQpveR6D4+OwKPXCfD2aieJis= +github.com/santhosh-tekuri/jsonschema v1.2.4/go.mod h1:TEAUOeZSmIxTTuHatJzrvARHiuO9LYd+cIxzgEHCQI4= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/square/go-jose/v3 v3.0.0-20200630053402-0a67ce9b0693 h1:wD1IWQwAhdWclCwaf6DdzgCAe9Bfz1M+4AHRd7N786Y= diff --git a/cmd/aries-agent-rest/go.mod b/cmd/aries-agent-rest/go.mod index 420796c2e..469b2af43 100644 --- a/cmd/aries-agent-rest/go.mod +++ b/cmd/aries-agent-rest/go.mod @@ -9,9 +9,9 @@ go 1.19 require ( github.com/cenkalti/backoff/v4 v4.1.2 github.com/gorilla/mux v1.7.3 - github.com/hyperledger/aries-framework-go v0.1.8-0.20220322085443-50e8f9bd208b - github.com/hyperledger/aries-framework-go/component/storage/leveldb v0.0.0-20220322085443-50e8f9bd208b - github.com/hyperledger/aries-framework-go/component/storageutil v0.0.0-20220322085443-50e8f9bd208b + github.com/hyperledger/aries-framework-go v0.1.9-0.20221007132211-6233891ce372 + github.com/hyperledger/aries-framework-go/component/storage/leveldb v0.1.9-0.20221007132211-6233891ce372 + github.com/hyperledger/aries-framework-go/component/storageutil v0.1.9-0.20221007132211-6233891ce372 github.com/hyperledger/aries-framework-go/spi v0.0.0-20220606124520-53422361c38c github.com/rs/cors v1.7.0 github.com/spf13/cobra v1.0.0 @@ -65,6 +65,7 @@ require ( github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/pquerna/cachecontrol v0.1.0 // indirect + github.com/santhosh-tekuri/jsonschema v1.2.4 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/square/go-jose/v3 v3.0.0-20200630053402-0a67ce9b0693 // indirect github.com/syndtr/goleveldb v1.0.0 // indirect diff --git a/cmd/aries-agent-rest/go.sum b/cmd/aries-agent-rest/go.sum index da042a563..617e0c870 100644 --- a/cmd/aries-agent-rest/go.sum +++ b/cmd/aries-agent-rest/go.sum @@ -632,6 +632,8 @@ github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc= github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E= +github.com/santhosh-tekuri/jsonschema v1.2.4 h1:hNhW8e7t+H1vgY+1QeEQpveR6D4+OwKPXCfD2aieJis= +github.com/santhosh-tekuri/jsonschema v1.2.4/go.mod h1:TEAUOeZSmIxTTuHatJzrvARHiuO9LYd+cIxzgEHCQI4= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/seccomp/libseccomp-golang v0.9.1/go.mod h1:GbW5+tmTXfcxTToHLXlScSlAvWlF4P2Ca7zGrPiEpWo= diff --git a/cmd/aries-js-worker/go.mod b/cmd/aries-js-worker/go.mod index 39040f471..380976004 100644 --- a/cmd/aries-js-worker/go.mod +++ b/cmd/aries-js-worker/go.mod @@ -8,8 +8,8 @@ go 1.19 require ( github.com/google/uuid v1.3.0 - github.com/hyperledger/aries-framework-go v0.1.8-0.20220322085443-50e8f9bd208b - github.com/hyperledger/aries-framework-go/component/storage/indexeddb v0.1.8-0.20220322085443-50e8f9bd208b + github.com/hyperledger/aries-framework-go v0.1.9-0.20221007132211-6233891ce372 + github.com/hyperledger/aries-framework-go/component/storage/indexeddb v0.1.9-0.20221007132211-6233891ce372 github.com/hyperledger/aries-framework-go/spi v0.0.0-20220606124520-53422361c38c github.com/mitchellh/mapstructure v1.3.0 github.com/stretchr/testify v1.7.2 @@ -48,6 +48,7 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/pquerna/cachecontrol v0.1.0 // indirect github.com/rs/cors v1.7.0 // indirect + github.com/santhosh-tekuri/jsonschema v1.2.4 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/square/go-jose/v3 v3.0.0-20200630053402-0a67ce9b0693 // indirect github.com/teserakt-io/golang-ed25519 v0.0.0-20210104091850-3888c087a4c8 // indirect diff --git a/cmd/aries-js-worker/go.sum b/cmd/aries-js-worker/go.sum index 4ca69bbb5..48b3a49a1 100644 --- a/cmd/aries-js-worker/go.sum +++ b/cmd/aries-js-worker/go.sum @@ -269,6 +269,8 @@ github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc= +github.com/santhosh-tekuri/jsonschema v1.2.4 h1:hNhW8e7t+H1vgY+1QeEQpveR6D4+OwKPXCfD2aieJis= +github.com/santhosh-tekuri/jsonschema v1.2.4/go.mod h1:TEAUOeZSmIxTTuHatJzrvARHiuO9LYd+cIxzgEHCQI4= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/square/go-jose/v3 v3.0.0-20200630053402-0a67ce9b0693 h1:wD1IWQwAhdWclCwaf6DdzgCAe9Bfz1M+4AHRd7N786Y= diff --git a/go.mod b/go.mod index 4454447ba..16bfa1d8b 100644 --- a/go.mod +++ b/go.mod @@ -30,6 +30,7 @@ require ( github.com/piprate/json-gold v0.4.1 github.com/pkg/errors v0.9.1 github.com/rs/cors v1.7.0 + github.com/santhosh-tekuri/jsonschema v1.2.4 github.com/square/go-jose/v3 v3.0.0-20200630053402-0a67ce9b0693 github.com/stretchr/testify v1.7.2 github.com/teserakt-io/golang-ed25519 v0.0.0-20210104091850-3888c087a4c8 diff --git a/go.sum b/go.sum index f125d1988..7225c4571 100644 --- a/go.sum +++ b/go.sum @@ -317,6 +317,8 @@ github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc= +github.com/santhosh-tekuri/jsonschema v1.2.4 h1:hNhW8e7t+H1vgY+1QeEQpveR6D4+OwKPXCfD2aieJis= +github.com/santhosh-tekuri/jsonschema v1.2.4/go.mod h1:TEAUOeZSmIxTTuHatJzrvARHiuO9LYd+cIxzgEHCQI4= github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/square/go-jose/v3 v3.0.0-20200630053402-0a67ce9b0693 h1:wD1IWQwAhdWclCwaf6DdzgCAe9Bfz1M+4AHRd7N786Y= diff --git a/pkg/doc/verifiable/presentation.go b/pkg/doc/verifiable/presentation.go index 3e31298e3..092612baa 100644 --- a/pkg/doc/verifiable/presentation.go +++ b/pkg/doc/verifiable/presentation.go @@ -6,12 +6,14 @@ SPDX-License-Identifier: Apache-2.0 package verifiable import ( + "bytes" "encoding/json" "errors" "fmt" + "strings" jsonld "github.com/piprate/json-gold/ld" - "github.com/xeipuuv/gojsonschema" + "github.com/santhosh-tekuri/jsonschema" "github.com/hyperledger/aries-framework-go/pkg/doc/jose" docjsonld "github.com/hyperledger/aries-framework-go/pkg/doc/jsonld" @@ -157,7 +159,12 @@ const basePresentationSchema = ` ` //nolint:gochecknoglobals -var basePresentationSchemaLoader = gojsonschema.NewStringLoader(basePresentationSchema) +var ( + schemaName = "presentationSchema" + schemaCompiler = jsonschema.NewCompiler() + _ = schemaCompiler.AddResource(schemaName, strings.NewReader(basePresentationSchema)) + presentationSchema = schemaCompiler.MustCompile(schemaName) +) // MarshalledCredential defines marshalled Verifiable Credential enclosed into Presentation. // MarshalledCredential can be passed to verifiable.ParseCredential(). @@ -568,16 +575,9 @@ func validateVPJSONLD(vpBytes []byte, opts *presentationOpts) error { } func validateVPJSONSchema(data []byte) error { - loader := gojsonschema.NewStringLoader(string(data)) - - result, err := gojsonschema.Validate(basePresentationSchemaLoader, loader) + err := presentationSchema.Validate(bytes.NewReader(data)) if err != nil { - return fmt.Errorf("validation of verifiable credential: %w", err) - } - - if !result.Valid() { - errMsg := describeSchemaValidationError(result, "verifiable presentation") - return errors.New(errMsg) + return fmt.Errorf("verifiable presentation is not valid: %w", err) } return nil diff --git a/pkg/doc/verifiable/presentation_test.go b/pkg/doc/verifiable/presentation_test.go index 17043a083..afd4050ab 100644 --- a/pkg/doc/verifiable/presentation_test.go +++ b/pkg/doc/verifiable/presentation_test.go @@ -304,7 +304,7 @@ func TestValidateVP_Context(t *testing.T) { require.NoError(t, err) vp, err := newTestPresentation(t, bytes) require.Error(t, err) - require.Contains(t, err.Error(), "@context is required") + require.Contains(t, err.Error(), "missing properties: \"@context\"") require.Nil(t, vp) }) @@ -319,7 +319,7 @@ func TestValidateVP_Context(t *testing.T) { require.NoError(t, err) vp, err := newTestPresentation(t, bytes) require.Error(t, err) - require.Contains(t, err.Error(), "does not match: \"https://www.w3.org/2018/credentials/v1\"") + require.Contains(t, err.Error(), "must be \"https://www.w3.org/2018/credentials/v1\"") require.Nil(t, vp) }) @@ -342,7 +342,7 @@ func TestValidateVP_Context(t *testing.T) { require.NoError(t, err) vp, err := newTestPresentation(t, bytes) require.Error(t, err) - require.Contains(t, err.Error(), "does not match: \"https://www.w3.org/2018/credentials/v1\"") + require.Contains(t, err.Error(), "must be \"https://www.w3.org/2018/credentials/v1\"") require.Nil(t, vp) }) } @@ -356,7 +356,7 @@ func TestValidateVP_ID(t *testing.T) { require.NoError(t, err) vp, err := newTestPresentation(t, bytes) require.Error(t, err) - require.Contains(t, err.Error(), "id: Does not match format 'uri'") + require.Contains(t, err.Error(), "\"not valid presentation ID URL\" is not valid \"uri\"") require.Nil(t, vp) }) } @@ -402,7 +402,7 @@ func TestValidateVP_Type(t *testing.T) { require.NoError(t, err) vp, err := newTestPresentation(t, bytes) require.Error(t, err) - require.Contains(t, err.Error(), "type is required") + require.Contains(t, err.Error(), "missing properties: \"type\"") require.Nil(t, vp) }) @@ -414,7 +414,7 @@ func TestValidateVP_Type(t *testing.T) { require.NoError(t, err) vp, err := newTestPresentation(t, bytes) require.Error(t, err) - require.Contains(t, err.Error(), "Does not match pattern '^VerifiablePresentation$'") + require.Contains(t, err.Error(), "does not match pattern \"^VerifiablePresentation$\"") require.Nil(t, vp) }) } @@ -428,7 +428,7 @@ func TestValidateVP_Holder(t *testing.T) { require.NoError(t, err) vp, err := newTestPresentation(t, bytes) require.Error(t, err) - require.Contains(t, err.Error(), "holder: Does not match format 'uri'") + require.Contains(t, err.Error(), "not valid presentation Holder URL\" is not valid \"uri\"") require.Nil(t, vp) }) } diff --git a/test/bdd/go.mod b/test/bdd/go.mod index 68a536b43..dc5a94f5d 100644 --- a/test/bdd/go.mod +++ b/test/bdd/go.mod @@ -13,7 +13,7 @@ require ( github.com/fsouza/go-dockerclient v1.6.6 github.com/google/uuid v1.3.0 github.com/gorilla/mux v1.8.0 - github.com/hyperledger/aries-framework-go v0.1.8-0.20220322085443-50e8f9bd208b + github.com/hyperledger/aries-framework-go v0.1.9-0.20221007132211-6233891ce372 github.com/hyperledger/aries-framework-go/component/storage/leveldb v0.0.0-20220322085443-50e8f9bd208b github.com/hyperledger/aries-framework-go/component/storageutil v0.0.0-20220322085443-50e8f9bd208b github.com/hyperledger/aries-framework-go/spi v0.0.0-20220606124520-53422361c38c @@ -72,6 +72,7 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/pquerna/cachecontrol v0.1.0 // indirect github.com/rs/cors v1.7.0 // indirect + github.com/santhosh-tekuri/jsonschema v1.2.4 // indirect github.com/sirupsen/logrus v1.7.0 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/square/go-jose/v3 v3.0.0-20200630053402-0a67ce9b0693 // indirect diff --git a/test/bdd/go.sum b/test/bdd/go.sum index 3f1b47347..c0952e279 100644 --- a/test/bdd/go.sum +++ b/test/bdd/go.sum @@ -423,6 +423,8 @@ github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc= +github.com/santhosh-tekuri/jsonschema v1.2.4 h1:hNhW8e7t+H1vgY+1QeEQpveR6D4+OwKPXCfD2aieJis= +github.com/santhosh-tekuri/jsonschema v1.2.4/go.mod h1:TEAUOeZSmIxTTuHatJzrvARHiuO9LYd+cIxzgEHCQI4= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.0.4-0.20170822132746-89742aefa4b2/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=