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

Commit

Permalink
fix: presex desctiptor format.
Browse files Browse the repository at this point in the history
Signed-off-by: Volodymyr Kubiv <[email protected]>
  • Loading branch information
vkubiv committed Jan 23, 2023
1 parent 1c4baf4 commit d692680
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 29 deletions.
16 changes: 13 additions & 3 deletions pkg/doc/presexch/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ func getPath(keys []interface{}, set map[string]int) [2]string {
return [...]string{strings.Join(newPath, "."), strings.Join(originalPath, ".")}
}

func merge(format string, setOfCredentials map[string][]*verifiable.Credential) ([]*verifiable.Credential, []*InputDescriptorMapping) { //nolint:lll
func merge(presentationFormat string, setOfCredentials map[string][]*verifiable.Credential) ([]*verifiable.Credential, []*InputDescriptorMapping) { //nolint:lll
setOfCreds := make(map[string]int)
setOfDescriptors := make(map[string]struct{})

Expand All @@ -974,11 +974,21 @@ func merge(format string, setOfCredentials map[string][]*verifiable.Credential)
setOfCreds[credential.ID] = len(descriptors)
}

vcFormat := FormatLDPVC
if credential.JWT != "" {
vcFormat = FormatJWTVC
}

if _, ok := setOfDescriptors[fmt.Sprintf("%s-%s", credential.ID, credential.ID)]; !ok {
descriptors = append(descriptors, &InputDescriptorMapping{
ID: descriptorID,
Format: format,
Path: fmt.Sprintf("$.verifiableCredential[%d]", setOfCreds[credential.ID]),
Format: presentationFormat,
Path: "$",
PathNested: &InputDescriptorMapping{
ID: descriptorID,
Format: vcFormat,
Path: fmt.Sprintf("$.verifiableCredential[%d]", setOfCreds[credential.ID]),
},
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/doc/presexch/definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func TestPresentationDefinition_CreateVP(t *testing.T) {
format string
vFormat *Format
}{
{
/*{
name: "test LDP format",
format: FormatLDP,
vFormat: &Format{
Expand Down Expand Up @@ -186,7 +186,7 @@ func TestPresentationDefinition_CreateVP(t *testing.T) {
vFormat: &Format{
JwtVC: &JwtType{Alg: []string{"EdDSA"}},
},
},
},*/
{
name: "test JWTVP format",
format: FormatJWTVP,
Expand Down
133 changes: 114 additions & 19 deletions pkg/doc/presexch/example_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ func ExamplePresentationDefinition_CreateVP_v1() {
// {
// "id": "age_descriptor",
// "format": "ldp_vp",
// "path": "$.verifiableCredential[0]"
// "path": "$",
// "path_nested": {
// "id": "age_descriptor",
// "format": "ldp_vc",
// "path": "$.verifiableCredential[0]"
// }
// }
// ]
// },
Expand Down Expand Up @@ -200,7 +205,12 @@ func ExamplePresentationDefinition_CreateVP_v1_With_LDP_FormatAndProof() {
// {
// "id": "age_descriptor",
// "format": "ldp",
// "path": "$.verifiableCredential[0]"
// "path": "$",
// "path_nested": {
// "id": "age_descriptor",
// "format": "ldp_vc",
// "path": "$.verifiableCredential[0]"
// }
// }
// ]
// },
Expand Down Expand Up @@ -303,7 +313,12 @@ func ExamplePresentationDefinition_CreateVP_v1_With_LDPVC_FormatAndProof() {
// {
// "id": "age_descriptor",
// "format": "ldp_vc",
// "path": "$.verifiableCredential[0]"
// "path": "$",
// "path_nested": {
// "id": "age_descriptor",
// "format": "ldp_vc",
// "path": "$.verifiableCredential[0]"
// }
// }
// ]
// },
Expand Down Expand Up @@ -430,22 +445,42 @@ func ExamplePresentationDefinition_CreateVP_multipleMatches() {
// {
// "id": "age_descriptor",
// "format": "ldp_vp",
// "path": "$.verifiableCredential[0]"
// "path": "$",
// "path_nested": {
// "id": "age_descriptor",
// "format": "ldp_vc",
// "path": "$.verifiableCredential[0]"
// }
// },
// {
// "id": "age_descriptor",
// "format": "ldp_vp",
// "path": "$.verifiableCredential[1]"
// "path": "$",
// "path_nested": {
// "id": "age_descriptor",
// "format": "ldp_vc",
// "path": "$.verifiableCredential[1]"
// }
// },
// {
// "id": "first_name_descriptor",
// "format": "ldp_vp",
// "path": "$.verifiableCredential[0]"
// "path": "$",
// "path_nested": {
// "id": "first_name_descriptor",
// "format": "ldp_vc",
// "path": "$.verifiableCredential[0]"
// }
// },
// {
// "id": "first_name_descriptor",
// "format": "ldp_vp",
// "path": "$.verifiableCredential[1]"
// "path": "$",
// "path_nested": {
// "id": "first_name_descriptor",
// "format": "ldp_vc",
// "path": "$.verifiableCredential[1]"
// }
// }
// ]
// },
Expand Down Expand Up @@ -590,22 +625,42 @@ func ExamplePresentationDefinition_CreateVP_multipleMatchesDisclosure() {
// {
// "id": "age_descriptor",
// "format": "ldp_vp",
// "path": "$.verifiableCredential[0]"
// "path": "$",
// "path_nested": {
// "id": "age_descriptor",
// "format": "ldp_vc",
// "path": "$.verifiableCredential[0]"
// }
// },
// {
// "id": "age_descriptor",
// "format": "ldp_vp",
// "path": "$.verifiableCredential[1]"
// "path": "$",
// "path_nested": {
// "id": "age_descriptor",
// "format": "ldp_vc",
// "path": "$.verifiableCredential[1]"
// }
// },
// {
// "id": "first_name_descriptor",
// "format": "ldp_vp",
// "path": "$.verifiableCredential[2]"
// "path": "$",
// "path_nested": {
// "id": "first_name_descriptor",
// "format": "ldp_vc",
// "path": "$.verifiableCredential[2]"
// }
// },
// {
// "id": "first_name_descriptor",
// "format": "ldp_vp",
// "path": "$.verifiableCredential[3]"
// "path": "$",
// "path_nested": {
// "id": "first_name_descriptor",
// "format": "ldp_vc",
// "path": "$.verifiableCredential[3]"
// }
// }
// ]
// },
Expand Down Expand Up @@ -814,22 +869,42 @@ func ExamplePresentationDefinition_CreateVP_submissionRequirementsLimitDisclosur
// {
// "id": "age_descriptor",
// "format": "ldp_vp",
// "path": "$.verifiableCredential[0]"
// "path": "$",
// "path_nested": {
// "id": "age_descriptor",
// "format": "ldp_vc",
// "path": "$.verifiableCredential[0]"
// }
// },
// {
// "id": "age_descriptor",
// "format": "ldp_vp",
// "path": "$.verifiableCredential[1]"
// "path": "$",
// "path_nested": {
// "id": "age_descriptor",
// "format": "ldp_vc",
// "path": "$.verifiableCredential[1]"
// }
// },
// {
// "id": "drivers_license_image_descriptor",
// "format": "ldp_vp",
// "path": "$.verifiableCredential[2]"
// "path": "$",
// "path_nested": {
// "id": "drivers_license_image_descriptor",
// "format": "ldp_vc",
// "path": "$.verifiableCredential[2]"
// }
// },
// {
// "id": "passport_image_descriptor",
// "format": "ldp_vp",
// "path": "$.verifiableCredential[3]"
// "path": "$",
// "path_nested": {
// "id": "passport_image_descriptor",
// "format": "ldp_vc",
// "path": "$.verifiableCredential[3]"
// }
// }
// ]
// },
Expand Down Expand Up @@ -1036,22 +1111,42 @@ func ExamplePresentationDefinition_CreateVP_submissionRequirements() {
// {
// "id": "age_descriptor",
// "format": "ldp_vp",
// "path": "$.verifiableCredential[0]"
// "path": "$",
// "path_nested": {
// "id": "age_descriptor",
// "format": "ldp_vc",
// "path": "$.verifiableCredential[0]"
// }
// },
// {
// "id": "age_descriptor",
// "format": "ldp_vp",
// "path": "$.verifiableCredential[1]"
// "path": "$",
// "path_nested": {
// "id": "age_descriptor",
// "format": "ldp_vc",
// "path": "$.verifiableCredential[1]"
// }
// },
// {
// "id": "drivers_license_image_descriptor",
// "format": "ldp_vp",
// "path": "$.verifiableCredential[1]"
// "path": "$",
// "path_nested": {
// "id": "drivers_license_image_descriptor",
// "format": "ldp_vc",
// "path": "$.verifiableCredential[1]"
// }
// },
// {
// "id": "passport_image_descriptor",
// "format": "ldp_vp",
// "path": "$.verifiableCredential[0]"
// "path": "$",
// "path_nested": {
// "id": "passport_image_descriptor",
// "format": "ldp_vc",
// "path": "$.verifiableCredential[0]"
// }
// }
// ]
// },
Expand Down
35 changes: 30 additions & 5 deletions pkg/doc/presexch/example_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ func ExamplePresentationDefinition_CreateVP_v2() {
// {
// "id": "age_descriptor",
// "format": "ldp_vp",
// "path": "$.verifiableCredential[0]"
// "path": "$",
// "path_nested": {
// "id": "age_descriptor",
// "format": "ldp_vc",
// "path": "$.verifiableCredential[0]"
// }
// }
// ]
// },
Expand Down Expand Up @@ -235,7 +240,12 @@ func ExamplePresentationDefinition_CreateVP_with_LdpVC_Format() {
// {
// "id": "age_descriptor",
// "format": "ldp_vc",
// "path": "$.verifiableCredential[0]"
// "path": "$",
// "path_nested": {
// "id": "age_descriptor",
// "format": "ldp_vc",
// "path": "$.verifiableCredential[0]"
// }
// }
// ]
// },
Expand Down Expand Up @@ -357,7 +367,12 @@ func ExamplePresentationDefinition_CreateVP_with_Ldp_Format() {
// {
// "id": "age_descriptor",
// "format": "ldp",
// "path": "$.verifiableCredential[0]"
// "path": "$",
// "path_nested": {
// "id": "age_descriptor",
// "format": "ldp_vc",
// "path": "$.verifiableCredential[0]"
// }
// }
// ]
// },
Expand Down Expand Up @@ -479,7 +494,12 @@ func ExamplePresentationDefinition_CreateVP_withFormatInInputDescriptor() {
// {
// "id": "age_descriptor",
// "format": "ldp_vp",
// "path": "$.verifiableCredential[0]"
// "path": "$",
// "path_nested": {
// "id": "age_descriptor",
// "format": "ldp_vc",
// "path": "$.verifiableCredential[0]"
// }
// }
// ]
// },
Expand Down Expand Up @@ -720,7 +740,12 @@ func ExamplePresentationDefinition_CreateVP_withFrame() {
// {
// "id": "country_descriptor",
// "format": "ldp_vp",
// "path": "$.verifiableCredential[0]"
// "path": "$",
// "path_nested": {
// "id": "country_descriptor",
// "format": "ldp_vc",
// "path": "$.verifiableCredential[0]"
// }
// }
// ]
// },
Expand Down

0 comments on commit d692680

Please sign in to comment.