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

AnonCreds: support queries by credential attribute presence and value #1287

Closed
genaris opened this issue Feb 10, 2023 · 3 comments · Fixed by #1369
Closed

AnonCreds: support queries by credential attribute presence and value #1287

genaris opened this issue Feb 10, 2023 · 3 comments · Fixed by #1369
Assignees
Milestone

Comments

@genaris
Copy link
Contributor

genaris commented Feb 10, 2023

AnonCreds spec defines a number of properties that can be set as restrictions in proof requests. Most of them are already supported in @aries-framework/anoncreds-rs module but we are missing two:

  • attr::<attribute-name>::marker
  • attr::<attribute-name>::<attribute-value>

For that purpose, AnonCredsRsHolderCredentialService must be updated to properly query the wallet according to them, and apply the corresponding tags when storing the credentials.

@Vickysomtee
Copy link
Contributor

I will pick this!

@TimoGlastra
Copy link
Contributor

Example:

// Verifier
const proofRequest = {
    request_attributes: {
        userDetails: {
            names: ['name'],
            restrictions: [{
                cred_def_id: '123',
                // 'attr::name::value': 'Victor',
                // 'attr::age::marker': '1'
            }]
        }
    }
}

// send to holder over DIDComm

// Holder has 100000
const credentials = [{
 attributes: {
    name: 'Timo',
    age: 20
 },
 cred_def_id: '123'
}, {
    attributes: {
        name: 'Victor',
     },
     cred_def_id: '456'
}, {
    attributes: {
        age: '25',
     },
     cred_def_id: '123'
}]


// Filter based on request
const filteredCredentials = [{
    name: 'Timo',
    age: 20
 }, {
    age: '25',
 }]

@TimoGlastra
Copy link
Contributor

When a record is stored, and the getTags method is called on the AnonCredsCredentialRecord we want to calculate the attribute value and marker tags.

This code is currnetly here: https://github.com/hyperledger/aries-framework-javascript/blob/main/packages/anoncreds/src/repository/AnonCredsCredentialRecord.ts#LL73C55-L73C55 and just sets the following tag for attributes:

Curent format:

{
  // ... other tags ...
  attributes: ['name', 'age']
}

Desired format:

{
  // ... other tags ...
  
  // should exist for every attribute in the credential
  'attr::${attributeName}::marker': true,
  'attr::${attributeName}::value': attributeValue
}

Then when querying credentials for a proof request, we need to query by these tags in the AnonCredsCredentialRecord.

This method transforms proof request restrictions into a storage query, which would need to be extended to include the attribute value and marker restrictions: https://github.com/hyperledger/aries-framework-javascript/blob/main/packages/anoncreds-rs/src/services/AnonCredsRsHolderService.ts#L336

In here: https://github.com/hyperledger/aries-framework-javascript/blob/main/packages/anoncreds-rs/src/services/AnonCredsRsHolderService.ts#L369 add checks:

  • if this is a attribute value restirction
  • if this is a attribute marker restriction

If one is found, we need to add the restriction to the query that algns with the tag structure in the AnonCredsCredentialRecord

How to check if this is a attribute value restriction or a attribute marker restriction you can look here: https://github.com/hyperledger/aries-framework-javascript/blob/main/packages/anoncreds/src/models/AnonCredsRestriction.ts#L135-L143

@TimoGlastra TimoGlastra moved this from Todo to In Progress in Ledger Agnostic AnonCreds Mar 6, 2023
@TimoGlastra TimoGlastra moved this from In Progress to In Review in Ledger Agnostic AnonCreds Mar 7, 2023
@github-project-automation github-project-automation bot moved this from In Review to Done in Ledger Agnostic AnonCreds Mar 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants