|
1 | 1 | import type { AgentMessage } from '../../agent/AgentMessage'
|
2 | 2 | import type { HandlerInboundMessage } from '../../agent/Handler'
|
3 |
| -import type { PresentationRecordType } from './PresentationExchangeRecord' |
4 |
| -import type { PresentationPreview } from './PresentationPreview' |
5 |
| -import type { ProofProtocolVersion } from './ProofProtocolVersion' |
6 |
| -import type { ProofRecord } from './repository' |
7 |
| -import type { ProofRequest, RetrievedCredentials } from './v1/models' |
8 |
| -import type { ProofFormatService } from './v2/formats/ProofFormatService' |
9 |
| -import type { V2ProposePresentationHandler } from './v2/handlers/V2ProposePresentationHandler' |
| 3 | +import type { InboundMessageContext } from '../../agent/models/InboundMessageContext' |
10 | 4 | import type {
|
11 | 5 | CreateRequestOptions,
|
12 |
| - ProofRequestAsResponse, |
13 |
| - ProofRequestsOptions, |
14 |
| - ProposeProofOptions, |
15 | 6 | RequestProofOptions,
|
16 |
| -} from './v2/interface' |
| 7 | + CreateProposalOptions, |
| 8 | + CreateProposalAsResponseOptions, |
| 9 | + CreateRequestAsResponseOptions, |
| 10 | +} from './interface' |
| 11 | +import type { ProofProtocolVersion } from './models/ProofProtocolVersion' |
| 12 | +import type { ProofRequest, RetrievedCredentials } from './protocol/v1/models' |
| 13 | +import type { PresentationPreview } from './protocol/v1/models/PresentationPreview' |
| 14 | +import type { ProofRecord } from './repository' |
| 15 | +import type { PresentationRecordType } from './repository/PresentationExchangeRecord' |
| 16 | +import type { ProofFormatService } from './v2/formats/ProofFormatService' |
| 17 | +import type { V2ProposePresentationHandler } from './v2/handlers/V2ProposePresentationHandler' |
17 | 18 |
|
18 | 19 | import { ConsoleLogger, LogLevel } from '../../logger'
|
19 | 20 |
|
20 | 21 | const logger = new ConsoleLogger(LogLevel.debug)
|
21 | 22 |
|
| 23 | +/** |
| 24 | + * - creates records & messages |
| 25 | + * - stores records |
| 26 | + * - returns records & messages |
| 27 | + */ |
22 | 28 | export abstract class ProofService {
|
23 | 29 | abstract getVersion(): ProofProtocolVersion
|
24 |
| - abstract createProposal(proposal: ProposeProofOptions): Promise<{ proofRecord: ProofRecord; message: AgentMessage }> |
25 | 30 |
|
26 |
| - abstract requestProof( |
27 |
| - requestProofOptions: RequestProofOptions |
| 31 | + /** |
| 32 | + * 1. Assert (connection ready, record state) |
| 33 | + * 1. Create proposal message |
| 34 | + * 2. loop through all formats from ProposeProofOptions and call format service |
| 35 | + * 3. Create and store proof record |
| 36 | + * 4. Store proposal message |
| 37 | + * 5. Return proposal message + proof record |
| 38 | + */ |
| 39 | + abstract createProposal(options: CreateProposalOptions): Promise<{ proofRecord: ProofRecord; message: AgentMessage }> |
| 40 | + |
| 41 | + /** |
| 42 | + * Create a proposal message in response to a received proof request message |
| 43 | + * |
| 44 | + * 1. assert record state |
| 45 | + * 1. Create proposal message |
| 46 | + * 2. loop through all formats from ProposeProofOptions and call format service |
| 47 | + * 3. Update proof record |
| 48 | + * 4. Create or update proposal message |
| 49 | + * 5. Return proposal message + proof record |
| 50 | + */ |
| 51 | + abstract createProposalAsResponse( |
| 52 | + options: CreateProposalAsResponseOptions |
28 | 53 | ): Promise<{ proofRecord: ProofRecord; message: AgentMessage }>
|
29 | 54 |
|
30 |
| - abstract createRequest( |
31 |
| - createRequestOptions: CreateRequestOptions |
| 55 | + /** |
| 56 | + * Process a received proposal message (does not accept yet) |
| 57 | + * |
| 58 | + * 1. Find proof record by thread and connection id |
| 59 | + * |
| 60 | + * Two flows possible: |
| 61 | + * - Proof record already exist |
| 62 | + * 2. Assert state |
| 63 | + * 3. Save or update proposal message in storage (didcomm message record) |
| 64 | + * 4. Loop through all format services to process proposal message |
| 65 | + * 5. Update & return record |
| 66 | + * |
| 67 | + * - Proof record does not exist yet |
| 68 | + * 2. Create record |
| 69 | + * 3. Save proposal message |
| 70 | + * 4. Loop through all format services to process proposal message |
| 71 | + * 5. Save & return record |
| 72 | + */ |
| 73 | + abstract processProposal(messageContext: InboundMessageContext<AgentMessage>): Promise<ProofRecord> |
| 74 | + |
| 75 | + abstract createRequest(options: CreateRequestOptions): Promise<{ proofRecord: ProofRecord; message: AgentMessage }> |
| 76 | + |
| 77 | + abstract createRequestAsResponse( |
| 78 | + options: CreateRequestAsResponseOptions |
32 | 79 | ): Promise<{ proofRecord: ProofRecord; message: AgentMessage }>
|
33 | 80 |
|
34 |
| - public getFormatService(presentationRecordType: PresentationRecordType): ProofFormatService { |
35 |
| - logger.debug(presentationRecordType.toString()) |
36 |
| - throw Error('Not Implemented') |
37 |
| - } |
| 81 | + abstract processRequest(messageContext: InboundMessageContext<AgentMessage>): Promise<ProofRecord> |
38 | 82 |
|
39 |
| - abstract processProposal(messageContext: HandlerInboundMessage<V2ProposePresentationHandler>): Promise<ProofRecord> |
| 83 | + abstract createPresentation( |
| 84 | + options: CreatePresentationOptions |
| 85 | + ): Promise<{ proofRecord: ProofRecord; message: AgentMessage }> |
40 | 86 |
|
41 |
| - abstract getById(proofRecordId: string): Promise<ProofRecord> |
| 87 | + abstract processPresentation(messageContext: InboundMessageContext<AgentMessage>): Promise<ProofRecord> |
42 | 88 |
|
43 |
| - abstract getRequestedCredentialsForProofRequest( |
44 |
| - proofRequest: ProofRequest, |
45 |
| - presentationProposal?: PresentationPreview |
46 |
| - ): Promise<RetrievedCredentials> |
| 89 | + abstract createAck(options: CreateAckOptions): Promise<{ proofRecord: ProofRecord; message: AgentMessage }> |
47 | 90 |
|
48 |
| - abstract createProofRequestFromProposal( |
49 |
| - presentationProposal: PresentationPreview, |
50 |
| - proofRequestOptions: ProofRequestsOptions |
51 |
| - ): Promise<ProofRequest> |
| 91 | + abstract processAck(messageContext: InboundMessageContext<AgentMessage>): Promise<ProofRecord> |
52 | 92 |
|
53 |
| - abstract createRequestAsResponse( |
54 |
| - proofRequestAsResponse: ProofRequestAsResponse |
| 93 | + abstract createProblemReport( |
| 94 | + options: CreateProblemReportOptions |
55 | 95 | ): Promise<{ proofRecord: ProofRecord; message: AgentMessage }>
|
| 96 | + abstract processProblemReport(messageContext: InboundMessageContext<AgentMessage>): Promise<ProofRecord> |
| 97 | + |
| 98 | + abstract getRequestedCredentialsForProofRequest(options: { |
| 99 | + proofRecord: ProofRecord |
| 100 | + }): Promise<{ indy?: RetrievedCredentials; w3c?: never }> |
| 101 | + |
| 102 | + public getFormatService(presentationRecordType: PresentationRecordType): ProofFormatService { |
| 103 | + logger.debug(presentationRecordType.toString()) |
| 104 | + throw Error('Not Implemented') |
| 105 | + } |
| 106 | + |
| 107 | + public getById(proofRecordId: string): Promise<ProofRecord> { |
| 108 | + return this.proofRepository.getById(proofRecordId) |
| 109 | + } |
56 | 110 | }
|
0 commit comments