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

selectFrom - unknown exception occurred: Cannot read property 'value' of undefined #50

Closed
smithbk opened this issue Sep 10, 2021 · 12 comments

Comments

@smithbk
Copy link

smithbk commented Sep 10, 2021

  • I'm submitting a ...
    [ X] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary

I am getting the following exception on my call to selectFrom:
"unknown exception occurred: Cannot read property 'value' of undefined"

The error passed to my exception handler does not contain a stack trace, so I don't know where this is occurring.

The arguments that I am passing to selectFrom are as follows:

First arg

{
    "submission_requirements": [
        {
            "purpose": "We need your driver's license name",
            "name": "Name on driver's license",
            "rule": "all",
            "from": "A"
        }
    ],
    "id": "32f54163-7166-48f1-93d8-ff217bdb0654",
    "input_descriptors": [
        {
            "constraints": {
                "fields": [
                    {
                        "path": [
                            "$.credentialSubject.familyName"
                        ],
                        "purpose": "The claim must be from one of the specified issuers",
                        "id": "1f44d55f-f161-4938-a659-f8026467f126"
                    },
                    {
                        "path": [
                            "$.credentialSubject.givenName"
                        ],
                        "purpose": "The claim must be from one of the specified issuers"
                    }
                ],
                "limit_disclosure": "required",
                "is_holder": [
                    {
                        "directive": "required",
                        "field_id": [
                            "1f44d55f-f161-4938-a659-f8026467f126"
                        ]
                    }
                ]
            },
            "schema": [
                {
                    "uri": "https://www.w3.org/2018/credentials#VerifiableCredential"
                },
                {
                    "uri": "https://w3id.org/citizenship#PermanentResident"
                }
            ],
            "name": "EU Driver's License",
            "group": [
                "A"
            ],
            "id": "citizenship_input_1"
        }
    ],
    "format": {
        "ldp_vp": {
            "proof_type": [
                "Ed25519VerificationKey2018"
            ]
        }
    }
}

Second arg

[
    {
        "identifier": "83627465",
        "name": "Permanent Resident Card",
        "type": [
            "VerifiableCredential",
            "PermanentResidentCard"
        ],
        "id": "https://issuer.oidp.uscis.gov/credentials/83627465",
        "credentialSubject": {
            "birthCountry": "Bahamas",
            "id": "did:example:b34ca6cd37bbf23",
            "type": [
                "PermanentResident",
                "Person"
            ],
            "gender": "Female",
            "familyName": "SMITH",
            "givenName": "JANE",
            "residentSince": "2015-01-01",
            "lprNumber": "999-999-999",
            "birthDate": "1958-07-17",
            "commuterClassification": "C1",
            "lprCategory": "C09",
            "image": "data:image/png;base64,iVBORw0KGgokJggg=="
        },
        "expirationDate": "2029-12-03T12:19:52Z",
        "description": "Government of Example Permanent Resident Card.",
        "issuanceDate": "2019-12-03T12:19:52Z",
        "@context": [
            "https://www.w3.org/2018/credentials/v1",
            "https://w3id.org/citizenship/v1",
            "https://w3id.org/security/suites/ed25519-2020/v1"
        ],
        "issuer": "did:key:z6MkhfRoL9n7ko9d6LnB5jLB4aejd3ir2q6E2xkuzKUYESig",
        "proof": {
            "type": "Ed25519Signature2020",
            "created": "2021-09-10T15:33:39Z",
            "verificationMethod": "did:key:z6MkhfRoL9n7ko9d6LnB5jLB4aejd3ir2q6E2xkuzKUYESig#key-1",
            "proofPurpose": "assertionMethod",
            "proofValue": "z4CYETTeGFbMz67ocKtRMb2xVG5mm5VcMtUYcs5KTgCAT2LhrwPfrN3ruvXf8DFSz6VtryWYJTPSWtEjspwakmTAY"
        }
    }
]

Third arg:

FAsYneKJhWBP2n5E21ZzdY
  • Other information (e.g. detailed explanation, stack traces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)
@smithbk
Copy link
Author

smithbk commented Sep 21, 2021

I’m now getting the following errors back from my call to selectFrom which I’m scatching my head over. Could you please help me interpret the errors?

[
    {
        "tag": "UriEvaluation",
        "status": "error",
        "message": "presentation_definition URI for the schema of the candidate input MUST be equal to one of the input_descriptors object uri values exactly.: $.input_descriptors[0]: $.verifiableCredential[0]"
    },
    {
        "tag": "MarkForSubmissionEvaluation",
        "status": "error",
        "message": "The input candidate is not eligible for submission: $.input_descriptors[0]: $.verifiableCredential[0]"
    },
    {
        "tag": "IsHolderEvaluation",
        "status": "error",
        "message": "The field ids requiring the subject to be the holder: [1f44d55f-f161-4938-a659-f8026467f126]: []"
    }
]

WRT the 1st error, it appears from the code that it is searching for the string $.input_descriptors[0] in the strings $.verifiableCredential[0]. Is it possible that it is erroneously comparing the location rather than the value at these locations?

The presentation definition that I’m passing is

{
    "submission_requirements": [
        {
            "from": "A",
            "purpose": "We need your driver's license name",
            "rule": "all",
            "name": "Name on driver's license"
        }
    ],
    "id": "32f54163-7166-48f1-93d8-ff217bdb0654",
    "input_descriptors": [
        {
            "schema": [
                {
                    "uri": "https://www.w3.org/2018/credentials/v1"
                },
                {
                    "uri": "https://w3id.org/citizenship/v1"
                }
            ],
            "group": [
                "A"
            ],
            "constraints": {
                "is_holder": [
                    {
                        "field_id": [
                            "1f44d55f-f161-4938-a659-f8026467f126"
                        ],
                        "directive": "required"
                    }
                ],
                "fields": [
                    {
                        "purpose": "The claim must be from one of the specified issuers",
                        "id": "1f44d55f-f161-4938-a659-f8026467f126",
                        "path": [
                            "$.credentialSubject.familyName"
                        ]
                    },
                    {
                        "purpose": "The claim must be from one of the specified issuers",
                        "path": [
                            "$.credentialSubject.givenName"
                        ]
                    }
                ],
                "limit_disclosure": "required"
            },
            "id": "citizenship_input_1",
            "name": "EU Driver's License"
        }
    ],
    "format": {
        "ldp_vp": {
            "proof_type": [
                "Ed25519VerificationKey2018"
            ]
        }
    }
}

The credentials are:

[
    {
        "description": "Government of Example Permanent Resident Card.",
        "expirationDate": "2029-12-03T12:19:52Z",
        "issuanceDate": "2019-12-03T12:19:52Z",
        "id": "https://issuer.oidp.uscis.gov/credentials/83627465",
        "name": "Permanent Resident Card",
        "identifier": "83627465",
        "credentialSubject": {
            "birthDate": "1958-07-17",
            "lprCategory": "C09",
            "lprNumber": "999-999-999",
            "image": "data:image/png;base64,iVBORw0KGgokJggg==",
            "type": [
                "PermanentResident",
                "Person"
            ],
            "commuterClassification": "C1",
            "familyName": "SMITH",
            "id": "did:example:b34ca6cd37bbf23",
            "givenName": "JANE",
            "gender": "Female",
            "residentSince": "2015-01-01",
            "birthCountry": "Bahamas"
        },
        "type": [
            "VerifiableCredential",
            "PermanentResidentCard"
        ],
        "@context": [
            "https://www.w3.org/2018/credentials/v1",
            "https://w3id.org/security/suites/ed25519-2020/v1",
            "https://w3id.org/citizenship/v1"
        ],
        "issuer": "did:key:z6MkuDyqwjCVhFFQEZdS5utguwYD2KRig2PEb9qbfP9iqwn9",
        "proof": {
            "type": "Ed25519Signature2020",
            "created": "2021-09-21T19:18:08Z",
            "verificationMethod": "did:key:z6MkuDyqwjCVhFFQEZdS5utguwYD2KRig2PEb9qbfP9iqwn9#key-1",
            "proofPurpose": "assertionMethod",
            "proofValue": "z22TFxZwpiT3B7TEKTZNyRzYbf6GfrXo7Xv35nyJTH6xWkvQAAiRCdnjAg4tRA5qB3bA9zZ726CthFUQf8Y8f3p1R"
        }
    }
]

and the holder DID is:

5qza7Q6eEJE9vhKcqXABec

@nklomp
Copy link
Contributor

nklomp commented Sep 22, 2021

Hi Keith,

We seem to have identified the issue. My colleague gave an answer earlier today, that is removed because it was not totally correct. We need to create a fix for it first, which another colleague is looking into right now. We hope to have another version ready today or tomorrow. Sorry for the inconvenience.

@nklomp
Copy link
Contributor

nklomp commented Sep 22, 2021

We have opened a ticket with DIF for the PE spec to get some clarification, because it sparked some discussion here internally.

decentralized-identity/presentation-exchange#250

The fix we are creating will interpret the evaluation of the contexts against the schemas in the Input Descriptor as the first matching singular intersection to proceed. Which would also mean that in the new version we will be releasing your example needs to remove "https://www.w3.org/2018/credentials/v1" from the schema array in the input descriptor as otherwise almost all VCs would match the schema

@nklomp
Copy link
Contributor

nklomp commented Sep 23, 2021

Okay, we have the fix and adjusted our tests and test-vectors. Currently we will go into the review process, but we expect to have a release today, which is working for your example. The interesting outcome of the above DIF discussion is that the schema array will be removed altogether because it could be interpreted in multiple ways and the path/constraints can already be used to also restrict the outcome to one or more VC contexts.

So the next version will still support the schema array, but probably the version after that will start emitting warning if you use the schemas array. We will adjust your example to how it should look like in the future as well. I will let you know when we do the actual release.

@smithbk
Copy link
Author

smithbk commented Sep 23, 2021

Thanks Niels and team

@nklomp
Copy link
Contributor

nklomp commented Sep 23, 2021

Hi @smithbk,

We just released v0.2.3 to NPMJS. It contains the fix for your example. There are however a few remarks. As you might have noticed in the DIF discussion and as I mentioned above the concept of the schema arrays will be removed in the future PE specification, because of the ambiguity. This also means that in a future release we will start ignoring these values and emitting a warning whenever we do encounter them in the input descriptors.

In your current example you are using

"schema": [
                {
                    "uri": "https://www.w3.org/2018/credentials/v1"
                },
                {
                    "uri": "https://w3id.org/citizenship/v1"
                }
            ]

Since the first schema is the generic VC schema, it means that the end result will be that any VC you will pass in to be checked will be accepted, as the current implementation does an intersection between the input descriptor schemas and the VC contexts. The first match between those is accepted. So for v0.2.3 you might want to remove the first schema.

Once we remove the support for schemas you will see the warnings mentioned above. From that point on you will need to check for the correct context in the path of the constraint. Below you will find an example how to do that. I guess you could already add it now, so all you have to do in the future is remove the schemas from the Input Descriptor.

{
  "presentation_definition": {
    "id": "31e2f0f1-6b70-411d-b239-56aed5321884",
    "purpose": "To see Inspection details of Heavy Sour Dilbit..",
    "input_descriptors": [
      {
        "id": "867bfe7a-5b91-46b2-9ba4-70028b8d9cc8",
        "purpose": "To see Inspection details of Heavy Sour Dilbit..",
        "constraints": {
          "fields": [
            {
              "path": [
                "$.issuer.id",
                "$.vc.issuer.id",
                "$.iss.id",
                "$.issuer",
                "$.vc.issuer",
                "$.iss"
              ],
              "filter": {
                "type": "string",
                "pattern": "did:v1:test:nym:z6MkhdmzFu659ZJ4XKj31vtEDmjvsi5yDZG5L7Caz63oP39k"
              }
            },
            {
              "path": [
                "$['@context']"
              ],
              "filter": {
                "type": "string",
                "pattern": "https://www.w3.org/2018/credentials/v1"
              }
            }
          ]
        }
      }
    ]
  }
}

Please let us know if this fixes your problem. Thx

@smithbk
Copy link
Author

smithbk commented Sep 30, 2021

Hi @nklomp,

First, I agree with your comments that it would be nice to provide an easy-to-use syntax for the common use-case in which someone wants to match credentials which match ALL of a set of contexts. This will be very common. If the spec does not support that and pe-js does not support that, then I think I will extend the language and just convert it myself on behalf of users.

Next, I updated to the latest packages and the selectFrom no longer returns an error; however, it does not work as I had expected. Here is the return value from selectFrom:

{"matches":[{"rule":"all","count":2,"matches":["$.verifiableCredential[0]","$.verifiableCredential[0]"],"from":["A"],"name":"Name on driver's license"}],
"errors":[],
"warnings":[]}

There are two things I did not expect.

  1. I expect only a single match since there is only a single credential to match, but the count is 2 and the matches array contains two equal strings.
  2. I had expected the matches array to either contain a list of indices of the credentials which matched or a copy of the credentials which matched. Am I supposed to extract the index 0 from the "$.verifiableCredential[0]" in this case? Or is this some jpath type syntax or something that I'm not recognizing?

Thanks

@nklomp
Copy link
Contributor

nklomp commented Sep 30, 2021

Hi @smithbk ,

The 'easy-to-use syntax for matching ALL of a set of contexts' is not part of the DIF spec, but we agree that this is a common use case. It should be possible to explicitly select one, or ALL contexts. We will therefore also propose to keep this as part of the Spec. Additionally, if they do move forward with the removal from the spec in a next version we will make sure to have methods available to easily convey this and to convert it this so it will work using the submission requirements.

The duplicate entry is fixed and will be in the next patch release. My colleague @hrehman-sphereon is looking into it your second issue. To answer your questions it is a JSON path result string, but it could be that the container verifiableCredential is off. We will create an example for you to work with and expect that soon.

@nklomp
Copy link
Contributor

nklomp commented Oct 4, 2021

Hi @smithbk ,

We are creating some additional tests today. We expect to have the release with the fixes out today as well. I will inform you when that has happend.

Niels

@smithbk
Copy link
Author

smithbk commented Oct 15, 2021

Hi @nklomp, is there any progress on this?

@nklomp
Copy link
Contributor

nklomp commented Oct 15, 2021

I thought I updated you elsewhere if not, sorry for that.

The above was fixed in the latest release, but I suggest to wait a bit for the next release, which contains fixes for strict-mode not being enabled and introduces interfaces for VCs and VPs instead of using unknowns. We will hopefully release that today and otherwise on monday

@JorisSphereon
Copy link
Contributor

In 0.3.0 we handled this issue, worked on better test cases to make sure that it won't show up again.
If you have any questions feel free to ask

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants