Skip to content

Commit 1b52eaa

Browse files
refac: V1ProofService
Signed-off-by: NB Prasad Katkar <[email protected]>
1 parent 1f8b369 commit 1b52eaa

File tree

4 files changed

+607
-118
lines changed

4 files changed

+607
-118
lines changed

packages/core/src/modules/proofs/ProofService.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import type { AgentMessage } from '../../agent/AgentMessage'
22
import type { InboundMessageContext } from '../../agent/models/InboundMessageContext'
3-
import type { CreateRequestAsResponseOptions } from './interface'
3+
import type { ProofFormatService } from './formats/ProofFormatService'
44
import type { ProofProtocolVersion } from './models/ProofProtocolVersion'
55
import type {
6-
CreatePresentationOptions,
76
CreateProposalAsResponseOptions,
87
CreateProposalOptions,
8+
CreateRequestAsResponseOptions,
9+
PresentationOptions,
910
RequestProofOptions,
1011
} from './models/ServiceOptions'
1112
import type { RetrievedCredentials } from './protocol/v1/models'
1213
import type { ProofRecord } from './repository'
1314
import type { PresentationRecordType } from './repository/PresentationExchangeRecord'
14-
import type { ProofFormatService } from './v2/formats/ProofFormatService'
1515

1616
import { ConsoleLogger, LogLevel } from '../../logger'
1717

@@ -78,7 +78,7 @@ export abstract class ProofService {
7878
abstract processRequest(messageContext: InboundMessageContext<AgentMessage>): Promise<ProofRecord>
7979

8080
abstract createPresentation(
81-
options: CreatePresentationOptions
81+
options: PresentationOptions
8282
): Promise<{ proofRecord: ProofRecord; message: AgentMessage }>
8383

8484
abstract processPresentation(messageContext: InboundMessageContext<AgentMessage>): Promise<ProofRecord>
Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import type { ProofAttributeInfo, ProofRequest, RequestedCredentials } from '../..'
2-
import type { CredentialRepository } from '../../../credentials'
31
import type { CreateProposalOptions } from '../../models/ServiceOptions'
42
import type {
53
CreatePresentationOptions,
64
CreateRequestOptions,
75
ProcessProposalOptions,
6+
ProcessRequestOptions,
87
ProofAttachmentFormat,
98
ProofFormatSpec,
109
} from '../ProofFormatService'
@@ -15,13 +14,6 @@ import { ProofFormatService } from '../ProofFormatService'
1514
import { ATTACHMENT_FORMAT } from '../ProofFormats'
1615

1716
export class IndyProofFormatService extends ProofFormatService {
18-
private credentialRepository: CredentialRepository
19-
20-
public constructor(credentialRepository: CredentialRepository) {
21-
super()
22-
this.credentialRepository = credentialRepository
23-
}
24-
2517
public createProposal(options: CreateProposalOptions): ProofAttachmentFormat {
2618
// Handle format in service
2719
throw new Error('Method not implemented.')
@@ -74,56 +66,4 @@ export class IndyProofFormatService extends ProofFormatService {
7466
public getFormatIdentifier(messageType: string): ProofFormatSpec {
7567
return ATTACHMENT_FORMAT[messageType].indy
7668
}
77-
78-
public async getRequestedAttachmentsForRequestedCredentials(
79-
indyProofRequest: ProofRequest,
80-
requestedCredentials: RequestedCredentials
81-
): Promise<Attachment[] | undefined> {
82-
const attachments: Attachment[] = []
83-
const credentialIds = new Set<string>()
84-
const requestedAttributesNames: (string | undefined)[] = []
85-
86-
// Get the credentialIds if it contains a hashlink
87-
for (const [referent, requestedAttribute] of Object.entries(requestedCredentials.requestedAttributes)) {
88-
// Find the requested Attributes
89-
const requestedAttributes = indyProofRequest.requestedAttributes.get(referent) as ProofAttributeInfo
90-
91-
// List the requested attributes
92-
requestedAttributesNames.push(...(requestedAttributes.names ?? [requestedAttributes.name]))
93-
94-
// Find the attributes that have a hashlink as a value
95-
for (const attribute of Object.values(requestedAttribute.credentialInfo.attributes)) {
96-
if (attribute.toLowerCase().startsWith('hl:')) {
97-
credentialIds.add(requestedAttribute.credentialId)
98-
}
99-
}
100-
}
101-
102-
// Only continues if there is an attribute value that contains a hashlink
103-
for (const credentialId of credentialIds) {
104-
// Get the credentialRecord that matches the ID
105-
106-
const credentialRecord = await this.credentialRepository.getSingleByQuery({ credentialId })
107-
108-
if (credentialRecord.linkedAttachments) {
109-
// Get the credentials that have a hashlink as value and are requested
110-
const requestedCredentials = credentialRecord.credentialAttributes?.filter(
111-
(credential) =>
112-
credential.value.toLowerCase().startsWith('hl:') && requestedAttributesNames.includes(credential.name)
113-
)
114-
115-
// Get the linked attachments that match the requestedCredentials
116-
const linkedAttachments = credentialRecord.linkedAttachments.filter((attachment) =>
117-
requestedCredentials?.map((credential) => credential.value.split(':')[1]).includes(attachment.id)
118-
)
119-
120-
if (linkedAttachments) {
121-
attachments.push(...linkedAttachments)
122-
}
123-
}
124-
}
125-
126-
return attachments.length ? attachments : undefined
127-
}
128-
12969
}

packages/core/src/modules/proofs/models/ServiceOptions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,7 @@ export interface PresentationOptions {
4343
comment?: string
4444
// TODO: add other options such as comment, etc...
4545
}
46+
47+
export interface CreateAckOptions {
48+
proofRecord: ProofRecord
49+
}

0 commit comments

Comments
 (0)