Skip to content

Commit

Permalink
feat: handle same credential type with same descriptor id
Browse files Browse the repository at this point in the history
  • Loading branch information
skynet2 committed Mar 25, 2024
1 parent ceef2a0 commit 8f9c59d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
23 changes: 16 additions & 7 deletions presexch/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type InputDescriptorMapping struct {
type MatchValue struct {
PresentationID string
Credential *verifiable.Credential
DescriptorID string
}

// MatchOptions is a holder of options that can set when matching a submission against definitions.
Expand Down Expand Up @@ -111,7 +112,7 @@ func WithMergedSubmissionMap(submissionMap map[string]interface{}) MatchOption {

// Match returns the credentials matched against the InputDescriptors ids.
func (pd *PresentationDefinition) Match(vpList []*verifiable.Presentation,
contextLoader ld.DocumentLoader, options ...MatchOption) (map[string]MatchValue, error) {
contextLoader ld.DocumentLoader, options ...MatchOption) ([]*MatchValue, error) {
opts := &MatchOptions{}

for i := range options {
Expand All @@ -136,8 +137,8 @@ func getMatchedCreds( //nolint:gocyclo,funlen
vpList []*verifiable.Presentation,
contextLoader ld.DocumentLoader,
opts *MatchOptions,
) (map[string]MatchValue, error) {
result := make(map[string]MatchValue)
) ([]*MatchValue, error) {
var result []*MatchValue

descriptorIDs := descriptorIDs(pd.InputDescriptors)

Expand Down Expand Up @@ -236,10 +237,11 @@ func getMatchedCreds( //nolint:gocyclo,funlen

// TODO add support for constraints: https://github.com/hyperledger/aries-framework-go/issues/2108

result[mapping.ID] = MatchValue{
result = append(result, &MatchValue{
PresentationID: vp.ID,
Credential: vc,
}
DescriptorID: mapping.ID,
})
}
}

Expand Down Expand Up @@ -284,12 +286,19 @@ func selectVC(typelessVerifiable interface{},
}

// Ensures the matched credentials meet the submission requirements.
func (pd *PresentationDefinition) evalSubmissionRequirements(matched map[string]MatchValue) error {
func (pd *PresentationDefinition) evalSubmissionRequirements(matched []*MatchValue) error {
// TODO support submission requirement rules: https://github.com/hyperledger/aries-framework-go/issues/2109
descriptorIDs := descriptorIDs(pd.InputDescriptors)

for i := range descriptorIDs {
_, found := matched[i]
found := false
for _, m := range matched {

Check failure on line 295 in presexch/api.go

View workflow job for this annotation

GitHub Actions / Checks

ranges should only be cuddled with assignments used in the iteration (wsl)
if m.DescriptorID == i {
found = true
break
}
}

if !found {
return fmt.Errorf("no credential provided for input descriptor %s", i)
}
Expand Down
11 changes: 7 additions & 4 deletions presexch/example_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1682,10 +1682,13 @@ func ExamplePresentationDefinition_Match() {
}

for _, descriptor := range verifierDefinitions.InputDescriptors {
receivedCred := matched[descriptor.ID]
fmt.Printf(
"verifier received the '%s' credential for the input descriptor id '%s'\n",
receivedCred.Credential.Contents().Context[1], descriptor.ID)
for _, match := range matched {
if match.DescriptorID == descriptor.ID {
fmt.Printf(
"verifier received the '%s' credential for the input descriptor id '%s'\n",
match.Credential.Contents().Context[1], descriptor.ID)
}
}
}

// Output:
Expand Down

0 comments on commit 8f9c59d

Please sign in to comment.