1
- import type { ProofAttributeInfo , ProofRequest , RequestedCredentials } from '../..'
2
- import type { CredentialRepository } from '../../../credentials'
3
1
import type { CreateProposalOptions } from '../../models/ServiceOptions'
4
2
import type {
5
3
CreatePresentationOptions ,
6
4
CreateRequestOptions ,
7
5
ProcessProposalOptions ,
6
+ ProcessRequestOptions ,
8
7
ProofAttachmentFormat ,
9
8
ProofFormatSpec ,
10
9
} from '../ProofFormatService'
@@ -15,13 +14,6 @@ import { ProofFormatService } from '../ProofFormatService'
15
14
import { ATTACHMENT_FORMAT } from '../ProofFormats'
16
15
17
16
export class IndyProofFormatService extends ProofFormatService {
18
- private credentialRepository : CredentialRepository
19
-
20
- public constructor ( credentialRepository : CredentialRepository ) {
21
- super ( )
22
- this . credentialRepository = credentialRepository
23
- }
24
-
25
17
public createProposal ( options : CreateProposalOptions ) : ProofAttachmentFormat {
26
18
// Handle format in service
27
19
throw new Error ( 'Method not implemented.' )
@@ -74,56 +66,4 @@ export class IndyProofFormatService extends ProofFormatService {
74
66
public getFormatIdentifier ( messageType : string ) : ProofFormatSpec {
75
67
return ATTACHMENT_FORMAT [ messageType ] . indy
76
68
}
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
-
129
69
}
0 commit comments