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

Using AttributeValue for AttributeFilter fails #1033

Closed
icc-romeu opened this issue Sep 21, 2022 · 2 comments
Closed

Using AttributeValue for AttributeFilter fails #1033

icc-romeu opened this issue Sep 21, 2022 · 2 comments

Comments

@icc-romeu
Copy link

Hi, I am using version 0.2.1 on React Native and I am trying to create a Proof that checks for a string value. So I wrote this:

 async getConnectionString (restrictions:ProofRestrictions, claims: ProofClaims): Promise<string> {
    try {
      const attributes:Record<string, ProofAttributeInfo> = {}
      claims.forEach((credentialClaim, index) => {
        const key = 'attr_' + index

      // Some attributes with just credDefId as restriction
        attributes[key] = new ProofAttributeInfo({
          names: credentialClaim.attributes,
          restrictions: [
            new AttributeFilter({
              credentialDefinitionId: credentialClaim.credDefId,
            }),
          ],
        })
      })


      restrictions.forEach((restriction, index) => {
        const key = 'attrRest_' + index

       // Some attributes with credDefId as restriction AND AttributeValue
        attributes[key] = new ProofAttributeInfo({
          name: restriction.name,
          restrictions: [
            new AttributeFilter({
              credentialDefinitionId: restriction.credDefId,
            }),
            new AttributeFilter({
              attributeValue: new AttributeValue({ 
                name: restriction.name,
                value: restriction.value,
              }),
            }),
          ],
        })
      })

      const { requestMessage } = await this.agent.proofs.createOutOfBandRequest(
        {
          name: 'Access Request',
          requestedAttributes: attributes,
        },
        {
          autoAcceptProof: AutoAcceptProof.ContentApproved,
        },
      )
      return requestMessage.toJSON()
    } catch (e: any) {
      throw new CredentialsServiceError(CredentialsServiceErrorType.couldNotCreateChallenge, e)
    }
  }

This generates the following challenge:

{
  "@type": "https://didcomm.org/present-proof/1.0/request-presentation",
  "@id": "cd5edb2a-7c5d-49a0-9ed1-72855909c76b",
  "request_presentations~attach": [
    {
      "@id": "libindy-request-presentation-0",
      "mime-type": "application/json",
      "data": {
        "base64": "eyJuYW1lIjoiQWNjZXNzIFJlcXVlc3QiLCJ2ZXJzaW9uIjoiQWNjZXNzIFJlcXVlc3QiLCJub25jZSI6IjY0NzM4NjEzOTY2MzQ2ODA1Mjc0Njg5NyIsInJlcXVlc3RlZF9hdHRyaWJ1dGVzIjp7ImF0dHJfMCI6eyJuYW1lcyI6WyJmaXJzdE5hbWUiLCJsYXN0TmFtZSIsInBlcnNvbklkIl0sInJlc3RyaWN0aW9ucyI6W3siY3JlZF9kZWZfaWQiOiJKZ0hpd2JGcjZOMVlmdGh0YlFZeWhZOjM6Q0w6NDUxOmNvcmVpZGVudGl0eXJldm9jYWJsZXYzIn1dfSwiYXR0clJlc3RfMCI6eyJuYW1lIjoiYWNjZXNzRGMiLCJyZXN0cmljdGlvbnMiOlt7ImNyZWRfZGVmX2lkIjoiSmdIaXdiRnI2TjFZZnRodGJRWXloWTozOkNMOjM0MjphY2Nlc3NjcmVkZW50aWFscmV2b2NhYmxldjIifSx7ImF0dHJpYnV0ZVZhbHVlIjp7Im5hbWUiOiJhY2Nlc3NEYyIsInZhbHVlIjoiRU5BQkxFRCJ9fV19fSwicmVxdWVzdGVkX3ByZWRpY2F0ZXMiOnt9fQ=="
      }
    }
  ],
  "~service": {
    "recipientKeys": [
      "whatever"
    ],
    "routingKeys": [
      "whatever"
    ],
    "serviceEndpoint": "https://whatever"
  }
}

And the libindy presentation is:

{
  "name": "Access Request",
  "version": "Access Request",
  "nonce": "647386139663468052746897",
  "requested_attributes": {
    "attr_0": {
      "names": [
        "firstName",
        "lastName",
        "personId"
      ],
      "restrictions": [
        {
          "cred_def_id": "JgHiwbFr6N1YfthtbQYyhY:3:CL:451:coreidentityrevocablev3"
        }
      ]
    },
    "attrRest_0": {
      "name": "accessDc",
      "restrictions": [
        {
          "cred_def_id": "JgHiwbFr6N1YfthtbQYyhY:3:CL:342:accesscredentialrevocablev2"
        },
        {
          "attributeValue": {
            "name": "accessDc",
            "value": "ENABLED"
          }
        }
      ]
    }
  },
  "requested_predicates": {}
}

This fails with a CommonInvalidStructure when trying to fulfill the proof.

Reading the code at https://github.com/hyperledger/aries-framework-javascript/blob/36b9d466d400a0f87f6272bc428965601023581a/packages/core/src/modules/proofs/models/AttributeFilter.ts it seems that the attributeValue value:

 {
   "attributeValue":
      {
         "name":"accessDc",
         "value":"ENABLED"
      }
 }

Should be transformed at some point executing AttributeFilterTransformerto:

   "attr::test_prop:: accessDc": "ENABLED"

But that function is never called.

I assume this is a bug, as there is no way as far as I know to verify a string value of an attribute, and it seems this transformation is not performed.

@TimoGlastra
Copy link
Contributor

Seems to be broken indeed. The AttributeFilterTransformer is never called somehow, and it seems the implementation is also broken.

Would you be willing to open a PR for this?

@TimoGlastra
Copy link
Contributor

This is fixed in main

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

No branches or pull requests

2 participants