Skip to content

Commit

Permalink
Merge pull request #666 from NB-PrasadKatkar/feat/present-proof-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
TimoGlastra authored May 19, 2022
2 parents 0c3cc49 + 0166af3 commit f0e02eb
Show file tree
Hide file tree
Showing 114 changed files with 7,963 additions and 2,296 deletions.
14 changes: 10 additions & 4 deletions demo/src/Alice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,17 @@ export class Alice extends BaseAgent {
}

public async acceptProofRequest(proofRecord: ProofRecord) {
const retrievedCredentials = await this.agent.proofs.getRequestedCredentialsForProofRequest(proofRecord.id, {
filterByPresentationPreview: true,
const requestedCredentials = await this.agent.proofs.autoSelectCredentialsForProofRequest({
proofRecordId: proofRecord.id,
config: {
filterByPresentationPreview: true,
},
})

await this.agent.proofs.acceptRequest({
proofRecordId: proofRecord.id,
proofFormats: { indy: requestedCredentials.indy },
})
const requestedCredentials = this.agent.proofs.autoSelectCredentialsForProofRequest(retrievedCredentials)
await this.agent.proofs.acceptRequest(proofRecord.id, requestedCredentials)
console.log(greenText('\nProof request accepted!\n'))
}

Expand Down
15 changes: 13 additions & 2 deletions demo/src/Faber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
AttributeFilter,
ProofAttributeInfo,
utils,
ProofProtocolVersion,
} from '@aries-framework/core'
import { ui } from 'inquirer'

Expand Down Expand Up @@ -143,8 +144,18 @@ export class Faber extends BaseAgent {
const connectionRecord = await this.getConnectionRecord()
const proofAttribute = await this.newProofAttribute()
await this.printProofFlow(greenText('\nRequesting proof...\n', false))
await this.agent.proofs.requestProof(connectionRecord.id, {
requestedAttributes: proofAttribute,

await this.agent.proofs.requestProof({
protocolVersion: ProofProtocolVersion.V1,
connectionId: connectionRecord.id,
proofFormats: {
indy: {
name: 'proof-request',
version: '1.0',
nonce: '1298236324864',
requestedAttributes: proofAttribute,
},
},
})
this.ui.updateBottomBar(
`\nProof request sent!\n\nGo to the Alice agent to accept the proof request\n\n${Color.Reset}`
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/agent/AgentConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { DID_COMM_TRANSPORT_QUEUE } from '../constants'
import { AriesFrameworkError } from '../error'
import { ConsoleLogger, LogLevel } from '../logger'
import { AutoAcceptCredential } from '../modules/credentials/CredentialAutoAcceptType'
import { AutoAcceptProof } from '../modules/proofs/ProofAutoAcceptType'
import { AutoAcceptProof } from '../modules/proofs/models/ProofAutoAcceptType'
import { DidCommMimeType } from '../types'

export class AgentConfig {
Expand Down
10 changes: 7 additions & 3 deletions packages/core/src/agent/__tests__/Agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import { CredentialRepository } from '../../modules/credentials'
import { CredentialsModule } from '../../modules/credentials/CredentialsModule'
import { IndyLedgerService } from '../../modules/ledger'
import { LedgerModule } from '../../modules/ledger/LedgerModule'
import { ProofRepository, ProofService } from '../../modules/proofs'
import { ProofRepository } from '../../modules/proofs'
import { ProofsModule } from '../../modules/proofs/ProofsModule'
import { V1ProofService } from '../../modules/proofs/protocol/v1'
import { V2ProofService } from '../../modules/proofs/protocol/v2'
import {
MediatorModule,
RecipientModule,
Expand Down Expand Up @@ -119,7 +121,8 @@ describe('Agent', () => {
expect(container.resolve(TrustPingService)).toBeInstanceOf(TrustPingService)

expect(container.resolve(ProofsModule)).toBeInstanceOf(ProofsModule)
expect(container.resolve(ProofService)).toBeInstanceOf(ProofService)
expect(container.resolve(V1ProofService)).toBeInstanceOf(V1ProofService)
expect(container.resolve(V2ProofService)).toBeInstanceOf(V2ProofService)
expect(container.resolve(ProofRepository)).toBeInstanceOf(ProofRepository)

expect(container.resolve(CredentialsModule)).toBeInstanceOf(CredentialsModule)
Expand Down Expand Up @@ -162,7 +165,8 @@ describe('Agent', () => {
expect(container.resolve(TrustPingService)).toBe(container.resolve(TrustPingService))

expect(container.resolve(ProofsModule)).toBe(container.resolve(ProofsModule))
expect(container.resolve(ProofService)).toBe(container.resolve(ProofService))
expect(container.resolve(V1ProofService)).toBe(container.resolve(V1ProofService))
expect(container.resolve(V2ProofService)).toBe(container.resolve(V2ProofService))
expect(container.resolve(ProofRepository)).toBe(container.resolve(ProofRepository))

expect(container.resolve(CredentialsModule)).toBe(container.resolve(CredentialsModule))
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/decorators/ack/AckDecorator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { BaseMessage } from '../../agent/BaseMessage'
import { JsonTransformer } from '../../utils/JsonTransformer'
import { Compose } from '../../utils/mixins'

import { AckValues } from './AckDecorator'
import { AckDecorated } from './AckDecoratorExtension'

describe('Decorators | AckDecoratorExtension', () => {
Expand All @@ -13,7 +14,7 @@ describe('Decorators | AckDecoratorExtension', () => {

test('transforms AckDecorator class to JSON', () => {
const message = new TestMessage()
message.setPleaseAck()
message.setPleaseAck([AckValues.Receipt])
expect(message.toJSON()).toEqual({
'@id': undefined,
'@type': undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { InboundMessageContext } from '../../../agent/models/InboundMessage
import type { Logger } from '../../../logger'
import type { DidCommMessageRepository } from '../../../storage'
import type { MediationRecipientService } from '../../routing'
import type { CredentialExchangeRecord } from '../repository/CredentialExchangeRecord'
import type { CredentialStateChangedEvent } from './../CredentialEvents'
import type { CredentialProtocolVersion } from './../CredentialProtocolVersion'
import type {
Expand Down Expand Up @@ -37,7 +38,7 @@ import type { V2IssueCredentialMessage } from './../protocol/v2/messages/V2Issue
import type { V2OfferCredentialMessage } from './../protocol/v2/messages/V2OfferCredentialMessage'
import type { V2ProposeCredentialMessage } from './../protocol/v2/messages/V2ProposeCredentialMessage'
import type { V2RequestCredentialMessage } from './../protocol/v2/messages/V2RequestCredentialMessage'
import type { CredentialExchangeRecord, CredentialRepository } from './../repository'
import type { CredentialRepository } from './../repository'
import type { RevocationService } from './RevocationService'

import { CredentialEventTypes } from './../CredentialEvents'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Logger } from '../../../logger'
import type { RequestedCredentials } from '../../proofs'
import type { RequestedCredentials } from '../../proofs/formats/indy/models/RequestedCredentials'
import type * as Indy from 'indy-sdk'

import { Lifecycle, scoped } from 'tsyringe'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Logger } from '../../../logger'
import type { FileSystem } from '../../../storage/FileSystem'
import type { RevocationInterval } from '../../credentials'
import type { RequestedCredentials } from '../../proofs'
import type { RevocationInterval } from '../../credentials/protocol/v1/models/RevocationInterval'
import type { RequestedCredentials } from '../../proofs/formats/indy/models/RequestedCredentials'
import type { default as Indy } from 'indy-sdk'

import { scoped, Lifecycle } from 'tsyringe'
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/modules/proofs/ProofEvents.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { BaseEvent } from '../../agent/Events'
import type { ProofState } from './ProofState'
import type { ProofState } from './models/ProofState'
import type { ProofRecord } from './repository'

export enum ProofEventTypes {
Expand Down
65 changes: 32 additions & 33 deletions packages/core/src/modules/proofs/ProofResponseCoordinator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { scoped, Lifecycle } from 'tsyringe'

import { AgentConfig } from '../../agent/AgentConfig'

import { AutoAcceptProof } from './ProofAutoAcceptType'
import { ProofService } from './ProofService'
import { AutoAcceptProof } from './models/ProofAutoAcceptType'

/**
* This class handles all the automation with all the messages in the present proof protocol
Expand All @@ -13,9 +14,11 @@ import { AutoAcceptProof } from './ProofAutoAcceptType'
@scoped(Lifecycle.ContainerScoped)
export class ProofResponseCoordinator {
private agentConfig: AgentConfig
private proofService: ProofService

public constructor(agentConfig: AgentConfig) {
public constructor(agentConfig: AgentConfig, proofService: ProofService) {
this.agentConfig = agentConfig
this.proofService = proofService
}

/**
Expand All @@ -35,52 +38,48 @@ export class ProofResponseCoordinator {
* Checks whether it should automatically respond to a proposal
*/
public shouldAutoRespondToProposal(proofRecord: ProofRecord) {
const autoAccept = ProofResponseCoordinator.composeAutoAccept(
proofRecord.autoAcceptProof,
this.agentConfig.autoAcceptProofs
)

if (autoAccept === AutoAcceptProof.Always) {
return true
}
return false
return this.isAutoAcceptProofAlways(proofRecord)
}

/**
* Checks whether it should automatically respond to a request
*/
public shouldAutoRespondToRequest(proofRecord: ProofRecord) {
const autoAccept = ProofResponseCoordinator.composeAutoAccept(
proofRecord.autoAcceptProof,
this.agentConfig.autoAcceptProofs
)

if (
autoAccept === AutoAcceptProof.Always ||
(autoAccept === AutoAcceptProof.ContentApproved && proofRecord.proposalMessage)
) {
return true
}

return false
return this.isAutoAcceptProofAlways(proofRecord)
? this.isAutoAcceptProofAlways(proofRecord)
: this.isAutoAcceptProofContentApproved(proofRecord)
}

/**
* Checks whether it should automatically respond to a presentation of proof
*/
public shouldAutoRespondToPresentation(proofRecord: ProofRecord) {
const autoAccept = ProofResponseCoordinator.composeAutoAccept(
proofRecord.autoAcceptProof,
this.agentConfig.autoAcceptProofs
)

if (
autoAccept === AutoAcceptProof.Always ||
(autoAccept === AutoAcceptProof.ContentApproved && proofRecord.requestMessage)
) {
return this.isAutoAcceptProofAlways(proofRecord)
? this.isAutoAcceptProofAlways(proofRecord)
: this.isAutoAcceptProofContentApproved(proofRecord)
}

private checkAutoRespond(proofRecord: ProofRecord) {
return ProofResponseCoordinator.composeAutoAccept(proofRecord.autoAcceptProof, this.agentConfig.autoAcceptProofs)
}

private isAutoAcceptProofAlways(proofRecord: ProofRecord) {
const autoAccept = this.checkAutoRespond(proofRecord)

if (autoAccept === AutoAcceptProof.Always) {
return true
}

return false
}

private isAutoAcceptProofContentApproved(proofRecord: ProofRecord) {
const autoAccept = this.checkAutoRespond(proofRecord)

if (autoAccept === AutoAcceptProof.ContentApproved) {
return this.proofService.shouldAutoRespondToRequest(proofRecord)
}

return false
}
}
Loading

0 comments on commit f0e02eb

Please sign in to comment.