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

fix: check groupnames #638

Merged
merged 4 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
21 changes: 21 additions & 0 deletions packages/core/src/modules/proofs/services/ProofService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ export class ProofService {
comment?: string
}
): Promise<ProofProtocolMsgReturnType<RequestPresentationMessage>> {
// Assert attribute and predicate group names do not match
this.assertAttributePredicateGroupNamesDoNotMatch(proofRequest)

// Assert
proofRecord.assertState(ProofState.ProposalReceived)

Expand Down Expand Up @@ -299,6 +302,9 @@ export class ProofService {
): Promise<ProofProtocolMsgReturnType<RequestPresentationMessage>> {
this.logger.debug(`Creating proof request`)

// Assert attribute and predicate group names do not match
this.assertAttributePredicateGroupNamesDoNotMatch(proofRequest)

// Assert
connectionRecord?.assertReady()

Expand Down Expand Up @@ -360,6 +366,9 @@ export class ProofService {
}
await validateOrReject(proofRequest)

// Assert attribute and predicate group names do not match
this.assertAttributePredicateGroupNamesDoNotMatch(proofRequest)

this.logger.debug('received proof request', proofRequest)

try {
Expand Down Expand Up @@ -1037,6 +1046,18 @@ export class ProofService {

return credentialDefinitions
}

public assertAttributePredicateGroupNamesDoNotMatch(proofRequest: ProofRequest) {
const attributes = Array.from(proofRequest.requestedAttributes.keys())
const predicates = Array.from(proofRequest.requestedPredicates.keys())
const intersection = attributes.filter((x) => predicates.includes(x))

if (intersection.length > 0) {
throw new AriesFrameworkError(
`The proof request contains an attribute group name that matches a predicate group name: ${intersection}`
)
}
}
}

export interface ProofRequestTemplate {
Expand Down
38 changes: 38 additions & 0 deletions packages/core/tests/proofs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,42 @@ describe('Present Proof', () => {
presentationMessage: expect.any(PresentationMessage),
})
})

test('an attribute group name matches with a predicate group name so an error is thrown', async () => {
// Age attribute
const attributes = {
age: new ProofAttributeInfo({
name: 'age',
restrictions: [
new AttributeFilter({
credentialDefinitionId: credDefId,
}),
],
}),
}

// Age predicate
const predicates = {
age: new ProofPredicateInfo({
name: 'age',
predicateType: PredicateType.GreaterThanOrEqualTo,
predicateValue: 50,
restrictions: [
new AttributeFilter({
credentialDefinitionId: credDefId,
}),
],
}),
}

await expect(
faberAgent.proofs.requestProof(faberConnection.id, {
name: 'test-proof-request',
requestedAttributes: attributes,
requestedPredicates: predicates,
})
).rejects.toThrowError(
`The proof request contains an attribute group name that matches a predicate group name: age`
)
})
})