Skip to content

Commit

Permalink
Add required (#245)
Browse files Browse the repository at this point in the history
* fix postal address

* change name

* adding required

* fix merge

* Update credential/exchange/builder_test.go

Co-authored-by: Gabe <gcohen@squareup.com>

* AdditionalProperties

* Update credential/exchange/builder_test.go

* merge fix

Co-authored-by: Gabe <gcohen@squareup.com>
  • Loading branch information
nitro-neal and decentralgabe committed Oct 27, 2022
1 parent 50f3596 commit 39fefd7
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 15 deletions.
55 changes: 55 additions & 0 deletions credential/exchange/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,63 @@ func TestInputDescriptorBuilderProperties(t *testing.T) {

assert.NoError(t, err)
definition, err := builder.Build()
assert.NotEmpty(t, definition)
assert.NoError(t, err)
}

func TestInputDescriptorBuilderRequired(t *testing.T) {
builder := NewPresentationDefinitionBuilder()

b := []byte(
`{
"addressCountry":{
"type":"string"
},
"addressLocality":{
"type":"string"
},
"addressRegion":{
"type":"string"
},
"postalCode":{
"type":"string"
},
"streetAddress":{
"type":"string"
}
}`)

var props interface{}
err := json.Unmarshal(b, &props)
assert.NoError(t, err)

err = builder.SetInputDescriptors([]InputDescriptor{
{
ID: uuid.NewString(),
Name: "children-info",
Constraints: &Constraints{
Fields: []Field{
{
Path: []string{"$.vc.credentialSubject.children[*].firstName", "$.credentialSubject.children[*].firstName"},
ID: "children-info-first-name",
Filter: &Filter{
Type: "string",
MinLength: 1,
Properties: props,
Required: []string{"postalCode, streetAddress"},
AdditionalProperties: true,
},
},
},
},
},
})

assert.NoError(t, err)
definition, err := builder.Build()
assert.NotEmpty(t, definition)
assert.NoError(t, err)

}

func TestInputDescriptorBuilder(t *testing.T) {
Expand Down
32 changes: 17 additions & 15 deletions credential/exchange/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,21 +285,23 @@ type RelationalConstraint struct {
}

type Filter struct {
Type string `json:"type,omitempty"`
Format string `json:"format,omitempty"`
Properties interface{} `json:"properties,omitempty"`
Pattern string `json:"pattern,omitempty"`
Minimum interface{} `json:"minimum,omitempty"`
Maximum interface{} `json:"maximum,omitempty"`
MinLength int `json:"minLength,omitempty"`
MaxLength int `json:"maxLength,omitempty"`
ExclusiveMinimum interface{} `json:"exclusiveMinimum,omitempty"`
ExclusiveMaximum interface{} `json:"exclusiveMaximum,omitempty"`
Const interface{} `json:"const,omitempty"`
Enum []interface{} `json:"enum,omitempty"`
Not interface{} `json:"not,omitempty"`
AllOf interface{} `json:"allOf,omitempty"`
OneOf interface{} `json:"oneOf,omitempty"`
Type string `json:"type,omitempty"`
Format string `json:"format,omitempty"`
Properties interface{} `json:"properties,omitempty"`
Required []string `json:"required,omitempty"`
AdditionalProperties bool `json:"additionalProperties,omitempty"`
Pattern string `json:"pattern,omitempty"`
Minimum interface{} `json:"minimum,omitempty"`
Maximum interface{} `json:"maximum,omitempty"`
MinLength int `json:"minLength,omitempty"`
MaxLength int `json:"maxLength,omitempty"`
ExclusiveMinimum interface{} `json:"exclusiveMinimum,omitempty"`
ExclusiveMaximum interface{} `json:"exclusiveMaximum,omitempty"`
Const interface{} `json:"const,omitempty"`
Enum []interface{} `json:"enum,omitempty"`
Not interface{} `json:"not,omitempty"`
AllOf interface{} `json:"allOf,omitempty"`
OneOf interface{} `json:"oneOf,omitempty"`
}

// CredentialStatus https://identity.foundation/presentation-exchange/#credential-status-constraint-feature
Expand Down

0 comments on commit 39fefd7

Please sign in to comment.