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 all 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 @@ -257,6 +257,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 @@ -302,6 +305,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 @@ -363,6 +369,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 @@ -1116,6 +1125,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`
)
})
})