|
| 1 | +import type { AgentMessage } from '../../agent/AgentMessage' |
| 2 | +import type { HandlerInboundMessage } from '../../agent/Handler' |
| 3 | +import type { InboundMessageContext } from '../../agent/models/InboundMessageContext' |
| 4 | +import type { |
| 5 | + CreateRequestOptions, |
| 6 | + RequestProofOptions, |
| 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' |
| 18 | + |
| 19 | +import { ConsoleLogger, LogLevel } from '../../logger' |
| 20 | + |
| 21 | +const logger = new ConsoleLogger(LogLevel.debug) |
| 22 | + |
| 23 | +/** |
| 24 | + * - creates records & messages |
| 25 | + * - stores records |
| 26 | + * - returns records & messages |
| 27 | + */ |
| 28 | +export abstract class ProofService { |
| 29 | + abstract getVersion(): ProofProtocolVersion |
| 30 | + |
| 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 |
| 53 | + ): Promise<{ proofRecord: ProofRecord; message: AgentMessage }> |
| 54 | + |
| 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 |
| 79 | + ): Promise<{ proofRecord: ProofRecord; message: AgentMessage }> |
| 80 | + |
| 81 | + abstract processRequest(messageContext: InboundMessageContext<AgentMessage>): Promise<ProofRecord> |
| 82 | + |
| 83 | + abstract createPresentation( |
| 84 | + options: CreatePresentationOptions |
| 85 | + ): Promise<{ proofRecord: ProofRecord; message: AgentMessage }> |
| 86 | + |
| 87 | + abstract processPresentation(messageContext: InboundMessageContext<AgentMessage>): Promise<ProofRecord> |
| 88 | + |
| 89 | + abstract createAck(options: CreateAckOptions): Promise<{ proofRecord: ProofRecord; message: AgentMessage }> |
| 90 | + |
| 91 | + abstract processAck(messageContext: InboundMessageContext<AgentMessage>): Promise<ProofRecord> |
| 92 | + |
| 93 | + abstract createProblemReport( |
| 94 | + options: CreateProblemReportOptions |
| 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 | + } |
| 110 | +} |
0 commit comments