Skip to content

Commit

Permalink
PEX: Validate Presentation Definitions and Submissions using JSON sch…
Browse files Browse the repository at this point in the history
…ema (#2556)
  • Loading branch information
reinkrul authored Oct 25, 2023
1 parent c5afa09 commit c8abcf3
Show file tree
Hide file tree
Showing 27 changed files with 1,627 additions and 38 deletions.
2 changes: 1 addition & 1 deletion auth/api/iam/openid4vp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestWrapper_handlePresentationRequest(t *testing.T) {
t.Run("with scope", func(t *testing.T) {
ctrl := gomock.NewController(t)
peStore := &pe.DefinitionResolver{}
_ = peStore.LoadFromFile("test/presentation_definition_mapping.json")
require.NoError(t, peStore.LoadFromFile("test/presentation_definition_mapping.json"))
mockVDR := vdr.NewMockVDR(ctrl)
mockVCR := vcr.NewMockVCR(ctrl)
mockWallet := holder.NewMockWallet(ctrl)
Expand Down
7 changes: 6 additions & 1 deletion auth/api/iam/test/presentation_definition_mapping.json
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
{"eOverdracht-overdrachtsbericht":{}}
{
"eOverdracht-overdrachtsbericht": {
"id": "eOverdracht",
"input_descriptors": []
}
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ require (
schneider.vip/problem v1.8.1
)

require github.com/santhosh-tekuri/jsonschema v1.2.4

require (
github.com/PaesslerAG/gval v1.2.2 // indirect
github.com/alexandrevicenzi/go-sse v1.6.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,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 h1:iQh3xXAumdQ+4Ufa5b25cRpC5TYKlno6hsv6Cb3pkBk=
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/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/shengdoushi/base58 v1.0.0 h1:tGe4o6TmdXFJWoI31VoSWvuaKxf0Px3gqa3sUWhAxBs=
github.com/shengdoushi/base58 v1.0.0/go.mod h1:m5uIILfzcKMw6238iWAhP4l3s5+uXyF3+bJKUNhAL9I=
Expand Down
14 changes: 3 additions & 11 deletions vcr/pe/schema/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
# generate structs from JSON schema

From this directory, run:

```shell
go run .
```

It'll generate `generated.go` within the `pe` package.
The generated code is not really useful, but it could serve as a guide for the types that are expected by the API.
The output of `generated.go` is copied to `types.go`
Schemas files were taken from:
- https://github.com/decentralized-identity/presentation-exchange/tree/main/schemas
- https://github.com/decentralized-identity/claim-format-registry/tree/main/schemas
11 changes: 11 additions & 0 deletions vcr/pe/schema/gen/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# generate structs from JSON schema

From this directory, run:

```shell
go run .
```

It'll generate `generated.go` within the `pe` package.
The generated code is not really useful, but it could serve as a guide for the types that are expected by the API.
The output of `generated.go` is copied to `types.go`
2 changes: 1 addition & 1 deletion vcr/pe/schema/go.mod → vcr/pe/schema/gen/go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/nuts-foundation/nuts-node/vcr/pe/schema
module github.com/nuts-foundation/nuts-node/vcr/pe/gen/schema

go 1.21

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion vcr/pe/schema/main.go → vcr/pe/schema/gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func main() {
os.Exit(1)
}

f, err := os.OpenFile("../generated.go", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
f, err := os.OpenFile("generated.go", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)

if err != nil {
fmt.Fprintln(os.Stderr, "Error opening output file: ", err)
Expand Down
220 changes: 220 additions & 0 deletions vcr/pe/schema/v2/input-descriptor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Input Descriptor",
"definitions": {
"status_directive": {
"type": "object",
"additionalProperties": false,
"properties": {
"directive": {
"type": "string",
"enum": [
"required",
"allowed",
"disallowed"
]
},
"type": {
"type": "array",
"minItems": 1,
"items": {
"type": "string"
}
}
}
},
"field": {
"type": "object",
"oneOf": [
{
"properties": {
"id": {
"type": "string"
},
"optional": {
"type": "boolean"
},
"path": {
"type": "array",
"items": {
"type": "string"
}
},
"purpose": {
"type": "string"
},
"intent_to_retain": {
"type": "boolean"
},
"name": {
"type": "string"
},
"filter": {
"$ref": "http://json-schema.org/draft-07/schema#"
}
},
"required": [
"path"
],
"additionalProperties": false
},
{
"properties": {
"id": {
"type": "string"
},
"optional": {
"type": "boolean"
},
"path": {
"type": "array",
"items": {
"type": "string"
}
},
"purpose": {
"type": "string"
},
"intent_to_retain": {
"type": "boolean"
},
"filter": {
"$ref": "http://json-schema.org/draft-07/schema#"
},
"name": {
"type": "string"
},
"predicate": {
"type": "string",
"enum": [
"required",
"preferred"
]
}
},
"required": [
"path",
"filter",
"predicate"
],
"additionalProperties": false
}
]
}
},
"type": "object",
"additionalProperties": false,
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"purpose": {
"type": "string"
},
"group": {
"type": "array",
"items": {
"type": "string"
}
},
"constraints": {
"type": "object",
"additionalProperties": false,
"properties": {
"limit_disclosure": {
"type": "string",
"enum": [
"required",
"preferred"
]
},
"statuses": {
"type": "object",
"additionalProperties": false,
"properties": {
"active": {
"$ref": "#/definitions/status_directive"
},
"suspended": {
"$ref": "#/definitions/status_directive"
},
"revoked": {
"$ref": "#/definitions/status_directive"
}
}
},
"fields": {
"type": "array",
"items": {
"$ref": "#/definitions/field"
}
},
"subject_is_issuer": {
"type": "string",
"enum": [
"required",
"preferred"
]
},
"is_holder": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"properties": {
"field_id": {
"type": "array",
"items": {
"type": "string"
}
},
"directive": {
"type": "string",
"enum": [
"required",
"preferred"
]
}
},
"required": [
"field_id",
"directive"
]
}
},
"same_subject": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"properties": {
"field_id": {
"type": "array",
"items": {
"type": "string"
}
},
"directive": {
"type": "string",
"enum": [
"required",
"preferred"
]
}
},
"required": [
"field_id",
"directive"
]
}
}
}
}
},
"required": [
"id"
]
}
Loading

0 comments on commit c8abcf3

Please sign in to comment.