Skip to content

Commit

Permalink
fix: check proof request group names do not overlap (openwallet-found…
Browse files Browse the repository at this point in the history
…ation#638)

Signed-off-by: annelein <[email protected]>
  • Loading branch information
Annelein committed Feb 28, 2022
1 parent df735ed commit f4cb998
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
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`
)
})
})

0 comments on commit f4cb998

Please sign in to comment.