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

refactor: change xeipuuv/gojsonschema to santhosh-tekuri/jsonschema package #3395

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
5 changes: 3 additions & 2 deletions cmd/aries-agent-mobile/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

is xeipuuv/gojsonschema package still referenced somewhere? I see indirect references at lines 60-62 below.

It would be good to remove all references to xeipuuv packages

Copy link
Contributor

Choose a reason for hiding this comment

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

@Baha-sk - @Abdulbois wanted to show one example of the change to gather feedback. Once there is some feedback, all instances will be changed.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am for this change. A couple of days ago the old package was failing bbs signature post signing when validating the json map where an embedded json struct was being wrongly resolving to an empty RDF entry. Hopefully, this package does a better job at mapping jsonld docs.

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
Expand Down
2 changes: 2 additions & 0 deletions cmd/aries-agent-mobile/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
7 changes: 4 additions & 3 deletions cmd/aries-agent-rest/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions cmd/aries-agent-rest/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
5 changes: 3 additions & 2 deletions cmd/aries-js-worker/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions cmd/aries-js-worker/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
22 changes: 11 additions & 11 deletions pkg/doc/verifiable/presentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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().
Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions pkg/doc/verifiable/presentation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

Expand All @@ -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)
})

Expand All @@ -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)
})
}
Expand All @@ -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)
})
}
Expand Down Expand Up @@ -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)
})

Expand All @@ -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)
})
}
Expand All @@ -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)
})
}
Expand Down
3 changes: 2 additions & 1 deletion test/bdd/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

same here... lines 86-88 below

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
Expand Down
2 changes: 2 additions & 0 deletions test/bdd/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down