Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PEX: Resolve values mapped by Input Descriptor constraint fields #2667

Merged
merged 4 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 6 additions & 3 deletions vcr/pe/presentation_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (presentationDefinition PresentationDefinition) Match(vcs []vc.VerifiableCr
// to the corresponding value from the Verifiable Credentials that map to the InputDescriptor.
// The credentialMap is a map with the InputDescriptor.Id as key and the VerifiableCredential as value.
// Constraints that contain no ID are ignored.
func (presentationDefinition PresentationDefinition) ResolveConstraintsFields(credentialMap map[string]vc.VerifiableCredential) map[string]interface{} {
func (presentationDefinition PresentationDefinition) ResolveConstraintsFields(credentialMap map[string]vc.VerifiableCredential) (map[string]interface{}, error) {
result := make(map[string]interface{})
for inputDescriptorID, cred := range credentialMap {
// Find the input descriptor
Expand All @@ -91,12 +91,15 @@ func (presentationDefinition PresentationDefinition) ResolveConstraintsFields(cr
if inputDescriptor.Constraints == nil {
continue
}
_, values, _ := matchConstraint(inputDescriptor.Constraints, cred)
_, values, err := matchConstraint(inputDescriptor.Constraints, cred)
if err != nil {
return nil, fmt.Errorf("failed to match constraint for input descriptor '%s' and credential '%s': %w", inputDescriptorID, cred.ID, err)
}
for key, value := range values {
result[key] = value
}
}
return result
return result, nil
}

func (presentationDefinition PresentationDefinition) matchConstraints(vcs []vc.VerifiableCredential) ([]Candidate, error) {
Expand Down
6 changes: 3 additions & 3 deletions vcr/pe/presentation_definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ func TestPresentationDefinition_ResolveConstraintsFields(t *testing.T) {
"organization_credential": jwtCredential,
}

fieldValues := definition.ResolveConstraintsFields(credentialMap)
fieldValues, _ := definition.ResolveConstraintsFields(credentialMap)

require.Len(t, fieldValues, 2)
assert.Equal(t, "IJbergen", fieldValues["credentialsubject_organization_city"])
Expand All @@ -690,7 +690,7 @@ func TestPresentationDefinition_ResolveConstraintsFields(t *testing.T) {
"organization_credential": jsonldCredential,
}

fieldValues := definition.ResolveConstraintsFields(credentialMap)
fieldValues, _ := definition.ResolveConstraintsFields(credentialMap)

require.Len(t, fieldValues, 2)
assert.Equal(t, "IJbergen", fieldValues["credentialsubject_organization_city"])
Expand All @@ -710,7 +710,7 @@ func TestPresentationDefinition_ResolveConstraintsFields(t *testing.T) {
"any_credential": jwtCredential,
}

fieldValues := definition.ResolveConstraintsFields(credentialMap)
fieldValues, _ := definition.ResolveConstraintsFields(credentialMap)
reinkrul marked this conversation as resolved.
Show resolved Hide resolved

assert.Empty(t, fieldValues)
})
Expand Down
Loading