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

feat: present proof v2 #666

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
136 commits
Select commit Hold shift + click to select a range
8690411
refactor: initial proof module directory for v1 and v2
NB-PrasadKatkar Dec 14, 2021
a25c14a
feat(PresentProofV2): implemented presentation proposal
NB-PrasadKatkar Jan 6, 2022
ccb0329
feat: present proof v2(work in progress)
NB-PrasadKatkar Jan 13, 2022
1634262
feat: Present Proof v2 (WIP Accept Proposal)
NB-PrasadKatkar Jan 15, 2022
d654752
refactor(proofs): reworked directory structure
NB-KarimStekelenburg Jan 18, 2022
9866b56
Merge branch 'feat/present-proof-v2' of https://github.com/hyperledge…
NB-PrasadKatkar Jan 19, 2022
c2d0c45
Merge branch 'hyperledger-feat/present-proof-v2' into feat/present-pr…
NB-PrasadKatkar Jan 19, 2022
9d7a58a
IndyProofFormatService(Request and Presentation)
NB-PrasadKatkar Jan 23, 2022
4de4303
fix: IndyProofFormatService, V1ProofService
NB-PrasadKatkar Jan 24, 2022
1f8b369
refac: IndyProofFormatService, V1ProofService
NB-PrasadKatkar Jan 25, 2022
20a8da6
feat(proofs): add v2 message types
NB-KarimStekelenburg Jan 25, 2022
1b52eaa
refac: V1ProofService
NB-PrasadKatkar Jan 27, 2022
7a021da
feat(proofs): add v2 message types
NB-KarimStekelenburg Jan 25, 2022
bf824d4
fix(proofs): add missing goal_code to options
NB-KarimStekelenburg Jan 26, 2022
84a2f47
feat(proofs): add getter methods to ProofService
NB-KarimStekelenburg Jan 27, 2022
4a201c1
Merge branch 'feat/present-proof-v2' of https://github.com/hyperledge…
NB-KarimStekelenburg Jan 27, 2022
7e03954
refac: V1ProofService
NB-PrasadKatkar Jan 28, 2022
8c9db7d
feat(proofs): add v2 message types
NB-KarimStekelenburg Jan 25, 2022
c5d0ec6
fix(proofs): add missing goal_code to options
NB-KarimStekelenburg Jan 26, 2022
73d9f5e
feat(proofs): add getter methods to ProofService
NB-KarimStekelenburg Jan 27, 2022
9d8791a
Merge pull request #3 from hyperledger/feat/present-proof-v2
NB-PrasadKatkar Jan 28, 2022
66c146e
Merge branch 'feat/present-proof-v2' of https://github.com/hyperledge…
NB-KarimStekelenburg Jan 29, 2022
c55c4d6
Merge branch 'main' into feat/present-proof-v2
NB-KarimStekelenburg Jan 29, 2022
50481a4
refac: ProofsModule
NB-PrasadKatkar Jan 31, 2022
7eccd99
Merge pull request #4 from hyperledger/feat/present-proof-v2
NB-PrasadKatkar Jan 31, 2022
68afa1b
refac: ProofsModule
NB-PrasadKatkar Jan 31, 2022
ade451b
feat(didcomm-msg): add find method repositoty
NB-KarimStekelenburg Jan 31, 2022
e1c56da
feat(proofs): update V1 service w/ DidCommMessages
NB-KarimStekelenburg Jan 31, 2022
ae3665e
refactor(proofs): clean V1Service imports
NB-KarimStekelenburg Jan 31, 2022
cfe6025
refactor(proofs): clean V1Service imports
NB-KarimStekelenburg Jan 31, 2022
5129009
feat(proofs): add request methods to V2Service
NB-KarimStekelenburg Jan 31, 2022
e635497
Merge pull request #5 from hyperledger/feat/present-proof-v2
NB-PrasadKatkar Feb 2, 2022
6b4e767
refactor(proofs): updated ProofsModule request payload
NB-PrasadKatkar Feb 2, 2022
e135c83
Merge branch 'feat/present-proof-v2' of https://github.com/NB-PrasadK…
NB-PrasadKatkar Feb 2, 2022
db40c41
feat(proofs): added script for Proposal
NB-PrasadKatkar Feb 2, 2022
fb04808
feat(proofs): V2ProofService implementation done
NB-KarimStekelenburg Feb 7, 2022
77c1c13
Merge branch 'main' into feat/present-proof-v2
NB-KarimStekelenburg Feb 7, 2022
a2e1035
Merge remote-tracking branch 'prasad/feat/present-proof-v2' into feat…
NB-KarimStekelenburg Feb 7, 2022
56a2bad
Merge pull request #6 from hyperledger/feat/present-proof-v2
NB-PrasadKatkar Feb 7, 2022
94fa88c
feat(proofs): adding test case
NB-PrasadKatkar Feb 7, 2022
ac23660
Merge branch 'feat/present-proof-v2' of https://github.com/NB-PrasadK…
NB-PrasadKatkar Feb 7, 2022
d735cae
feat(proofs): updated packages in test case
NB-PrasadKatkar Feb 7, 2022
b930fde
refactor(proofs): renamed v1 handlers
NB-KarimStekelenburg Feb 7, 2022
b0b002d
feat(proofs): add auto accept logic
NB-KarimStekelenburg Feb 8, 2022
8ba7652
feat(proofs): add V2 service to ProofsModule
NB-KarimStekelenburg Feb 10, 2022
53461a9
fix(proofs): add V2 handler
NB-KarimStekelenburg Feb 14, 2022
aaf830c
fix(proofs): add final V2 handlers
NB-KarimStekelenburg Feb 14, 2022
b30f5ff
fix(proofs): register V2 handlers
NB-KarimStekelenburg Feb 16, 2022
7251fcf
Merge pull request #7 from hyperledger/feat/present-proof-v2
NB-PrasadKatkar Feb 17, 2022
f8f231a
test: added tests for v1 and v2 proof presentation proposal
NB-PrasadKatkar Feb 22, 2022
3eebaf8
fix: create proof request from proposal
NB-PrasadKatkar Feb 28, 2022
91c5adb
fix: process presentation if no proof proposal was created
NB-PrasadKatkar Mar 1, 2022
f4f06b1
test: working on V2 present proofs
NB-PrasadKatkar Mar 2, 2022
3de00b5
refac: renamed the proofs test files
NB-PrasadKatkar Mar 2, 2022
c9fa068
feat(present-proof v2): added createProofRequestFromProposal method t…
NB-PrasadKatkar Mar 8, 2022
eba2bfe
test(present-proof v2): proposal based scenario
NB-PrasadKatkar Mar 9, 2022
3905fe0
tests(present-proof v2): e2e proof request based scenario
NB-PrasadKatkar Mar 10, 2022
e5d1023
Merge branch 'main' of https://github.com/NB-PrasadKatkar/aries-frame…
NB-PrasadKatkar Mar 10, 2022
65aacfa
Merge branch 'main' of https://github.com/NB-PrasadKatkar/aries-frame…
NB-PrasadKatkar Mar 10, 2022
405fb0d
fix: connectionless-proofs and some tests
NB-PrasadKatkar Mar 12, 2022
88cb5f7
fix: auto accept proof test
NB-PrasadKatkar Mar 12, 2022
dfbd338
fix: demo files with new proof payloads and AckDecorator test
NB-PrasadKatkar Mar 12, 2022
51a7a0e
Merge branch 'main' of https://github.com/NB-PrasadKatkar/aries-frame…
NB-PrasadKatkar Mar 21, 2022
6a5ff87
test: v2 connectionless proofs and auto accept tests
NB-PrasadKatkar Mar 22, 2022
ddc9d8c
Merge branch 'main' of https://github.com/NB-PrasadKatkar/aries-frame…
NB-PrasadKatkar Mar 22, 2022
143280d
fix: check didCommMessages in proof tests
NB-PrasadKatkar Mar 24, 2022
a1bc56b
refac: renamed varibales
NB-PrasadKatkar Mar 25, 2022
30e5142
refac: few comments received on PR
NB-PrasadKatkar Mar 28, 2022
210a131
Merge branch 'main' of https://github.com/NB-PrasadKatkar/aries-frame…
NB-PrasadKatkar Mar 28, 2022
0254ccd
refac: removed commented lines, updates '.', '../' imports, empty err…
NB-PrasadKatkar Mar 28, 2022
d84c8a6
Merge branch 'main' of https://github.com/NB-PrasadKatkar/aries-frame…
NB-PrasadKatkar Mar 28, 2022
39be7e2
refac: proof response coordinator (auto-accept) check
NB-PrasadKatkar Mar 28, 2022
50dc835
Merge branch 'main' of https://github.com/NB-PrasadKatkar/aries-frame…
NB-PrasadKatkar Mar 28, 2022
b65bd48
refac: moved presentation preview in v1
NB-PrasadKatkar Mar 29, 2022
1b135c6
fix: import order
NB-PrasadKatkar Mar 29, 2022
a2ad211
refac: replaced inline interfaces
NB-PrasadKatkar Mar 30, 2022
247ba0a
Merge branch 'main' of https://github.com/NB-PrasadKatkar/aries-frame…
NB-PrasadKatkar Mar 30, 2022
533a02b
fix: lint issues
NB-PrasadKatkar Mar 30, 2022
2a3dd27
Merge branch 'main' of https://github.com/NB-PrasadKatkar/aries-frame…
NB-PrasadKatkar Apr 5, 2022
578fb5a
fix: import path fix after merge conflict issues
NB-PrasadKatkar Apr 5, 2022
4502fb8
fix: V2 proof proposal attachment
NB-PrasadKatkar Apr 8, 2022
22ee18b
refac: proposal interface removed proofPreview
NB-PrasadKatkar Apr 13, 2022
2465290
refac: renamed PresentationPreview to V1PresentationPreview
NB-PrasadKatkar Apr 13, 2022
a853fd7
refac: removed commented lines and renamed interfaces
NB-PrasadKatkar Apr 13, 2022
7e0f055
Merge branch 'main' of https://github.com/NB-PrasadKatkar/aries-frame…
NB-PrasadKatkar Apr 13, 2022
a97ea63
fix: merge conflicts
NB-PrasadKatkar Apr 13, 2022
25d028b
refac: accept proposal removed some not required properties from inte…
NB-PrasadKatkar Apr 14, 2022
2fcbc9a
refac: renamed protocol version enum
NB-PrasadKatkar Apr 14, 2022
2c45f1f
refac: removed version from accept methods
NB-PrasadKatkar Apr 14, 2022
42b1ca7
refac: merged getRequestedCredentialsForProofRequest and autoSelectCr…
NB-PrasadKatkar Apr 15, 2022
9f7be41
Merge branch 'main' of https://github.com/NB-PrasadKatkar/aries-frame…
NB-PrasadKatkar Apr 15, 2022
a47e3ae
refac: async createXXX and processXXX methods in the proof format ser…
NB-PrasadKatkar Apr 15, 2022
30d6933
Merge branch 'main' of https://github.com/NB-PrasadKatkar/aries-frame…
NB-PrasadKatkar Apr 15, 2022
cc31e87
refac: renamed propoerty in RequestProofOptions interface
NB-PrasadKatkar Apr 15, 2022
07d79cd
refac: created constants for proof formats
NB-PrasadKatkar Apr 15, 2022
d46e55b
refac: decline proof handled in module itself
NB-PrasadKatkar Apr 18, 2022
965225a
refac: Presentation Problem report structure changed
NB-PrasadKatkar Apr 18, 2022
fed9e68
refac: removed nonce from module
NB-PrasadKatkar Apr 18, 2022
4c89292
fix: lint issue
NB-PrasadKatkar Apr 18, 2022
9c552c7
refac: few feedback comments resolved
NB-PrasadKatkar Apr 19, 2022
0c0c983
refac: proof module document updated
NB-PrasadKatkar Apr 19, 2022
be00ec1
refac: proof format enums
NB-PrasadKatkar Apr 19, 2022
e2cc0ff
refac: proof format constants
NB-PrasadKatkar Apr 20, 2022
20a9741
Merge branch 'main' of https://github.com/NB-PrasadKatkar/aries-frame…
NB-PrasadKatkar Apr 20, 2022
3a49595
Merge branch 'main' of https://github.com/NB-PrasadKatkar/aries-frame…
NB-PrasadKatkar Apr 20, 2022
9d152be
Merge branch 'main' of https://github.com/NB-PrasadKatkar/aries-frame…
NB-PrasadKatkar Apr 23, 2022
fb398f6
Merge branch 'main' of https://github.com/NB-PrasadKatkar/aries-frame…
NB-PrasadKatkar May 2, 2022
04c15a8
fix: few review comments fixed
NB-PrasadKatkar May 2, 2022
11566c2
refac: find request payload updated
NB-PrasadKatkar May 2, 2022
0b2ea5f
fix: eslint fixes
NB-PrasadKatkar May 2, 2022
6c68720
Merge branch 'main' of https://github.com/NB-PrasadKatkar/aries-frame…
NB-PrasadKatkar May 3, 2022
7c51e2e
test: added test for Problem report from Module.
NB-PrasadKatkar May 4, 2022
a61811f
Merge branch 'main' of https://github.com/NB-PrasadKatkar/aries-frame…
NB-PrasadKatkar May 4, 2022
14a98fa
refac: removed TBD comment
NB-PrasadKatkar May 4, 2022
9d301af
fix: service name updation comments resolved
NB-PrasadKatkar May 5, 2022
cfb8dca
fix: service name updation comments resolved
NB-PrasadKatkar May 5, 2022
7cb29de
fix: eslint fixes
NB-PrasadKatkar May 5, 2022
0c0feed
fix: some review comments on based on protocol version
NB-PrasadKatkar May 5, 2022
6ba43f2
fix: few comments related to tests
NB-PrasadKatkar May 6, 2022
f43f8c8
fix: created single file for problem report reason and renamed attchI…
NB-PrasadKatkar May 6, 2022
39514ba
Merge branch 'main' of https://github.com/NB-PrasadKatkar/aries-frame…
NB-PrasadKatkar May 7, 2022
b6cc5d1
fix: removed duplicate referent method
NB-PrasadKatkar May 8, 2022
b7f0548
fix: remove uuid and used indy wallet for nonce generation
NB-PrasadKatkar May 8, 2022
d04598e
Update packages/core/src/modules/proofs/ProofService.ts
TimoGlastra May 9, 2022
7a6fb59
Update packages/core/src/modules/proofs/__tests__/V1ProofService.test.ts
TimoGlastra May 9, 2022
8bba6dd
Merge branch 'main' of https://github.com/NB-PrasadKatkar/aries-frame…
NB-PrasadKatkar May 10, 2022
cad0d1f
Merge branch 'feat/present-proof-v2' of https://github.com/NB-PrasadK…
NB-PrasadKatkar May 10, 2022
6e40192
Merge branch 'main' of https://github.com/NB-PrasadKatkar/aries-frame…
NB-PrasadKatkar May 10, 2022
c59d670
Merge branch 'main' of https://github.com/NB-PrasadKatkar/aries-frame…
NB-PrasadKatkar May 10, 2022
cf500e9
Merge branch 'main' of https://github.com/NB-PrasadKatkar/aries-frame…
NB-PrasadKatkar May 12, 2022
9b116a9
Merge branch 'main' of https://github.com/NB-PrasadKatkar/aries-frame…
NB-PrasadKatkar May 18, 2022
c8617e4
fix: eslint fixes
NB-PrasadKatkar May 18, 2022
cfde215
Merge branch 'main' of https://github.com/NB-PrasadKatkar/aries-frame…
NB-PrasadKatkar May 18, 2022
de30117
refac: validate attachment before processing the messages.
NB-PrasadKatkar May 19, 2022
61797ff
Merge branch 'main' of https://github.com/NB-PrasadKatkar/aries-frame…
NB-PrasadKatkar May 19, 2022
0166af3
tests: presentation exchange unit test
NB-PrasadKatkar May 19, 2022
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
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) {
NB-PrasadKatkar marked this conversation as resolved.
Show resolved Hide resolved
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