credo-ts
credo-ts copied to clipboard
Using AttributeValue for AttributeFilter fails
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.
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?
This is fixed in main