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: ldp_vp submission with 1 VC should not index credential property #2624

Merged
merged 2 commits into from
Dec 6, 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
10 changes: 10 additions & 0 deletions vcr/pe/presentation_submission.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@ func (b *PresentationSubmissionBuilder) Build(format string) (PresentationSubmis
}
}

// the verifiableCredential property in Verifiable Presentations can be a single VC or an array of VCs when represented in JSON.
// go-did always marshals a single VC as a single VC for JSON-LD VPs. So we might need to fix the mapping paths.
if format == vc.JSONLDPresentationProofFormat {
for _, signInstruction := range nonEmptySignInstructions {
if len(signInstruction.Mappings) == 1 {
signInstruction.Mappings[0].Path = "$.verifiableCredential"
}
}
}

index := 0
// last we create the descriptor map for the presentation submission
// If there's only one sign instruction the Path will be $.
Expand Down
37 changes: 34 additions & 3 deletions vcr/pe/presentation_submission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,38 @@ func TestPresentationSubmissionBuilder_Build(t *testing.T) {
vc2 := credentialToJSONLD(vc.VerifiableCredential{ID: &id2})
vc3 := credentialToJSONLD(vc.VerifiableCredential{ID: &id3})

t.Run("1 presentation", func(t *testing.T) {
t.Run("1 presentation with 1 credential", func(t *testing.T) {
expectedJSON := `
{
"id": "for-test",
"definition_id": "",
"descriptor_map": [
{
"format": "ldp_vc",
"id": "Match ID=1",
"path": "$.verifiableCredential"
}
]
}`
presentationDefinition := PresentationDefinition{}
_ = json.Unmarshal([]byte(test.PickOne), &presentationDefinition)
builder := presentationDefinition.PresentationSubmissionBuilder()
builder.AddWallet(holder1, []vc.VerifiableCredential{vc1, vc2})

submission, signInstructions, err := builder.Build("ldp_vp")

require.NoError(t, err)
require.NotNil(t, signInstructions)
assert.Len(t, signInstructions, 1)
require.Len(t, submission.DescriptorMap, 1)
assert.Equal(t, "$.verifiableCredential", submission.DescriptorMap[0].Path)

submission.Id = "for-test" // easier assertion
actualJSON, _ := json.MarshalIndent(submission, "", " ")
println(string(actualJSON))
reinkrul marked this conversation as resolved.
Show resolved Hide resolved
assert.JSONEq(t, expectedJSON, string(actualJSON))
})
t.Run("1 presentation with 2 credentials", func(t *testing.T) {
expectedJSON := `
{
"id": "for-test",
Expand Down Expand Up @@ -101,7 +132,7 @@ func TestPresentationSubmissionBuilder_Build(t *testing.T) {
"path_nested": {
"format": "ldp_vc",
"id": "Match ID=1",
"path": "$.verifiableCredential[0]"
"path": "$.verifiableCredential"
}
},
{
Expand All @@ -111,7 +142,7 @@ func TestPresentationSubmissionBuilder_Build(t *testing.T) {
"path_nested": {
"format": "ldp_vc",
"id": "Match ID=2",
"path": "$.verifiableCredential[0]"
"path": "$.verifiableCredential"
}
}
]
Expand Down
2 changes: 2 additions & 0 deletions vcr/pe/test/test_definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const PickOne = `
],
"input_descriptors": [
{
"id": "Match ID=1",
"name": "Pick 1",
"group": ["A"],
"constraints": {
Expand All @@ -47,6 +48,7 @@ const PickOne = `
}
},
{
"id": "Match ID=2",
"name": "Pick 2",
"group": ["A"],
"constraints": {
Expand Down
Loading