@sphereon/ssi-sdk.siopv2-oid4vp-op-auth 0.33.1-next.73 → 0.34.1-feat.SSISDK.35.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,322 +1,331 @@
1
- import { PresentationDefinitionWithLocation, PresentationExchange } from '@sphereon/did-auth-siop'
2
- import { SelectResults, Status, SubmissionRequirementMatch } from '@sphereon/pex'
3
- import { Format } from '@sphereon/pex-models'
1
+ // import { PresentationDefinitionWithLocation, PresentationExchange } from '@sphereon/did-auth-siop'
2
+ // import { SelectResults, Status, SubmissionRequirementMatch } from '@sphereon/pex'
3
+ //import { Format } from '@sphereon/pex-models'
4
+ // import {
5
+ // //isManagedIdentifierDidResult,
6
+ // isOID4VCIssuerIdentifier,
7
+ // ManagedIdentifierOptsOrResult,
8
+ // ManagedIdentifierResult,
9
+ // } from '@sphereon/ssi-sdk-ext.identifier-resolution'
10
+ // import { defaultHasher,
11
+ // // ProofOptions
12
+ // } from '@sphereon/ssi-sdk.core'
13
+ //import { UniqueDigitalCredential, verifiableCredentialForRoleFilter } from '@sphereon/ssi-sdk.credential-store'
14
+ //import { CredentialRole, FindDigitalCredentialArgs } from '@sphereon/ssi-sdk.data-store'
4
15
  import {
5
- isManagedIdentifierDidResult,
6
- isOID4VCIssuerIdentifier,
7
- ManagedIdentifierOptsOrResult,
8
- ManagedIdentifierResult,
9
- } from '@sphereon/ssi-sdk-ext.identifier-resolution'
10
- import { defaultHasher, ProofOptions } from '@sphereon/ssi-sdk.core'
11
- import { UniqueDigitalCredential, verifiableCredentialForRoleFilter } from '@sphereon/ssi-sdk.credential-store'
12
- import { CredentialRole, FindDigitalCredentialArgs } from '@sphereon/ssi-sdk.data-store'
13
- import { CompactJWT, HasherSync, IProof, OriginalVerifiableCredential } from '@sphereon/ssi-types'
16
+ //CompactJWT,
17
+ HasherSync,
18
+ //IProof, OriginalVerifiableCredential
19
+ } from '@sphereon/ssi-types'
14
20
  import {
15
- DEFAULT_JWT_PROOF_TYPE,
16
- IGetPresentationExchangeArgs,
21
+ //DEFAULT_JWT_PROOF_TYPE,
22
+ //IGetPresentationExchangeArgs,
17
23
  IOID4VPArgs,
18
- VerifiableCredentialsWithDefinition,
19
- VerifiablePresentationWithDefinition,
24
+ //VerifiableCredentialsWithDefinition,
25
+ //VerifiablePresentationWithDefinition,
20
26
  } from '../types'
21
- import { createOID4VPPresentationSignCallback } from './functions'
27
+ //import { createOID4VPPresentationSignCallback } from './functions'
22
28
  import { OpSession } from './OpSession'
23
29
 
24
30
  export class OID4VP {
25
- private readonly session: OpSession
26
- private readonly allIdentifiers: string[]
27
- private readonly hasher?: HasherSync
31
+ //private readonly session: OpSession
32
+ // private readonly allIdentifiers: string[]
33
+ // private readonly hasher?: HasherSync
28
34
 
29
35
  private constructor(args: IOID4VPArgs) {
30
- const { session, allIdentifiers, hasher = defaultHasher } = args
36
+ // const { session,
37
+ // // allIdentifiers, hasher = defaultHasher
38
+ // } = args
31
39
 
32
- this.session = session
33
- this.allIdentifiers = allIdentifiers ?? []
34
- this.hasher = hasher
40
+ //this.session = session
41
+ // this.allIdentifiers = allIdentifiers ?? []
42
+ // this.hasher = hasher
35
43
  }
36
44
 
37
45
  public static async init(session: OpSession, allIdentifiers: string[], hasher?: HasherSync): Promise<OID4VP> {
38
46
  return new OID4VP({ session, allIdentifiers: allIdentifiers ?? (await session.getSupportedDIDs()), hasher })
39
47
  }
40
48
 
41
- public async getPresentationDefinitions(): Promise<PresentationDefinitionWithLocation[] | undefined> {
42
- const definitions = await this.session.getPresentationDefinitions()
43
- if (definitions) {
44
- PresentationExchange.assertValidPresentationDefinitionWithLocations(definitions)
45
- }
46
- return definitions
47
- }
48
-
49
- private getPresentationExchange(args: IGetPresentationExchangeArgs): PresentationExchange {
50
- const { verifiableCredentials, allIdentifiers, hasher } = args
51
-
52
- return new PresentationExchange({
53
- allDIDs: allIdentifiers ?? this.allIdentifiers,
54
- allVerifiableCredentials: verifiableCredentials,
55
- hasher: hasher ?? this.hasher,
56
- })
57
- }
58
-
59
- public async createVerifiablePresentations(
60
- credentialRole: CredentialRole,
61
- credentialsWithDefinitions: VerifiableCredentialsWithDefinition[],
62
- opts?: {
63
- forceNoCredentialsInVP?: boolean // Allow to create a VP without credentials, like EBSI is using it. Defaults to false
64
- restrictToFormats?: Format
65
- restrictToDIDMethods?: string[]
66
- proofOpts?: ProofOptions
67
- idOpts?: ManagedIdentifierOptsOrResult
68
- skipDidResolution?: boolean
69
- holderDID?: string
70
- subjectIsHolder?: boolean
71
- hasher?: HasherSync
72
- applyFilter?: boolean
73
- },
74
- ): Promise<VerifiablePresentationWithDefinition[]> {
75
- return await Promise.all(credentialsWithDefinitions.map((cred) => this.createVerifiablePresentation(credentialRole, cred, opts)))
76
- }
77
-
78
- public async createVerifiablePresentation(
79
- credentialRole: CredentialRole,
80
- selectedVerifiableCredentials: VerifiableCredentialsWithDefinition,
81
- opts?: {
82
- forceNoCredentialsInVP?: boolean // Allow to create a VP without credentials, like EBSI is using it. Defaults to false
83
- restrictToFormats?: Format
84
- restrictToDIDMethods?: string[]
85
- proofOpts?: ProofOptions
86
- idOpts?: ManagedIdentifierOptsOrResult
87
- skipDidResolution?: boolean
88
- holder?: string
89
- subjectIsHolder?: boolean
90
- applyFilter?: boolean
91
- hasher?: HasherSync
92
- },
93
- ): Promise<VerifiablePresentationWithDefinition> {
94
- const { subjectIsHolder, holder, forceNoCredentialsInVP = false } = { ...opts }
95
- if (subjectIsHolder && holder) {
96
- throw Error('Cannot both have subject is holder and a holderDID value at the same time (programming error)')
97
- }
98
- if (forceNoCredentialsInVP) {
99
- selectedVerifiableCredentials.credentials = []
100
- } else if (!selectedVerifiableCredentials?.credentials || selectedVerifiableCredentials.credentials.length === 0) {
101
- throw Error('No verifiable verifiableCredentials provided for presentation definition')
102
- }
103
-
104
- const proofOptions: ProofOptions = {
105
- ...opts?.proofOpts,
106
- challenge: opts?.proofOpts?.nonce ?? opts?.proofOpts?.challenge ?? this.session.nonce,
107
- domain: opts?.proofOpts?.domain ?? (await this.session.getRedirectUri()),
108
- }
109
-
110
- let idOpts = opts?.idOpts
111
- if (!idOpts) {
112
- if (opts?.subjectIsHolder) {
113
- if (forceNoCredentialsInVP) {
114
- return Promise.reject(
115
- Error(
116
- `Cannot have subject is holder, when force no credentials is being used, as we could never determine the holder then. Please provide holderDID`,
117
- ),
118
- )
119
- }
120
- const firstUniqueDC = selectedVerifiableCredentials.credentials[0]
121
- // const firstVC = firstUniqueDC.uniformVerifiableCredential!
122
- if (typeof firstUniqueDC !== 'object' || !('digitalCredential' in firstUniqueDC)) {
123
- return Promise.reject(Error('If no opts provided, credentials should be of type UniqueDigitalCredential'))
124
- }
125
-
126
- idOpts = isOID4VCIssuerIdentifier(firstUniqueDC.digitalCredential.kmsKeyRef)
127
- ? await this.session.context.agent.identifierManagedGetByIssuer({
128
- identifier: firstUniqueDC.digitalCredential.kmsKeyRef,
129
- })
130
- : await this.session.context.agent.identifierManagedGetByKid({
131
- identifier: firstUniqueDC.digitalCredential.kmsKeyRef,
132
- kmsKeyRef: firstUniqueDC.digitalCredential.kmsKeyRef,
133
- })
134
-
135
- /*
136
- const holder = CredentialMapper.isSdJwtDecodedCredential(firstVC)
137
- ? firstVC.decodedPayload.cnf?.jwk
138
- ? //TODO SDK-19: convert the JWK to hex and search for the appropriate key and associated DID
139
- //doesn't apply to did:jwk only, as you can represent any DID key as a JWK. So whenever you encounter a JWK it doesn't mean it had to come from a did:jwk in the system. It just can always be represented as a did:jwk
140
- `did:jwk:${encodeJoseBlob(firstVC.decodedPayload.cnf?.jwk)}#0`
141
- : firstVC.decodedPayload.sub
142
- : Array.isArray(firstVC.credentialSubject)
143
- ? firstVC.credentialSubject[0].id
144
- : firstVC.credentialSubject.id
145
- if (holder) {
146
- idOpts = { identifier: holder }
147
- }
148
- */
149
- } else if (opts?.holder) {
150
- idOpts = { identifier: opts.holder }
151
- }
152
- }
49
+ // public async getPresentationDefinitions(): Promise<PresentationDefinitionWithLocation[] | undefined> {
50
+ // const definitions = await this.session.getPresentationDefinitions()
51
+ // if (definitions) {
52
+ // PresentationExchange.assertValidPresentationDefinitionWithLocations(definitions)
53
+ // }
54
+ // return definitions
55
+ // }
153
56
 
154
- // We are making sure to filter, in case the user submitted all verifiableCredentials in the wallet/agent. We also make sure to get original formats back
155
- const vcs = forceNoCredentialsInVP
156
- ? selectedVerifiableCredentials
157
- : opts?.applyFilter
158
- ? await this.filterCredentials(credentialRole, selectedVerifiableCredentials.definition, {
159
- restrictToFormats: opts?.restrictToFormats,
160
- restrictToDIDMethods: opts?.restrictToDIDMethods,
161
- filterOpts: {
162
- verifiableCredentials: selectedVerifiableCredentials.credentials,
163
- },
164
- })
165
- : {
166
- definition: selectedVerifiableCredentials.definition,
167
- credentials: selectedVerifiableCredentials.credentials,
168
- }
57
+ // private getPresentationExchange(args: IGetPresentationExchangeArgs): PresentationExchange {
58
+ // const { verifiableCredentials, allIdentifiers, hasher } = args
59
+ //
60
+ // return new PresentationExchange({
61
+ // allDIDs: allIdentifiers ?? this.allIdentifiers,
62
+ // allVerifiableCredentials: verifiableCredentials,
63
+ // hasher: hasher ?? this.hasher,
64
+ // })
65
+ // }
169
66
 
170
- if (!idOpts) {
171
- return Promise.reject(Error(`No identifier options present at this point`))
172
- }
67
+ // public async createVerifiablePresentations(
68
+ // credentialRole: CredentialRole,
69
+ // credentialsWithDefinitions: VerifiableCredentialsWithDefinition[],
70
+ // opts?: {
71
+ // forceNoCredentialsInVP?: boolean // Allow to create a VP without credentials, like EBSI is using it. Defaults to false
72
+ // restrictToFormats?: Format
73
+ // restrictToDIDMethods?: string[]
74
+ // proofOpts?: ProofOptions
75
+ // idOpts?: ManagedIdentifierOptsOrResult
76
+ // skipDidResolution?: boolean
77
+ // holderDID?: string
78
+ // subjectIsHolder?: boolean
79
+ // hasher?: HasherSync
80
+ // applyFilter?: boolean
81
+ // },
82
+ // ): Promise<VerifiablePresentationWithDefinition[]> {
83
+ // return await Promise.all(credentialsWithDefinitions.map((cred) => this.createVerifiablePresentation(credentialRole, cred, opts)))
84
+ // }
173
85
 
174
- const signCallback = await createOID4VPPresentationSignCallback({
175
- presentationSignCallback: this.session.options.presentationSignCallback,
176
- idOpts,
177
- context: this.session.context,
178
- domain: proofOptions.domain,
179
- challenge: proofOptions.challenge,
180
- format: opts?.restrictToFormats ?? selectedVerifiableCredentials.definition.definition.format,
181
- skipDidResolution: opts?.skipDidResolution ?? false,
182
- })
183
- const identifier: ManagedIdentifierResult = await this.session.context.agent.identifierManagedGet(idOpts)
184
- const verifiableCredentials = vcs.credentials.map((credential) =>
185
- typeof credential === 'object' && 'digitalCredential' in credential ? credential.originalVerifiableCredential! : credential,
186
- )
187
- const presentationResult = await this.getPresentationExchange({
188
- verifiableCredentials: verifiableCredentials,
189
- allIdentifiers: this.allIdentifiers,
190
- hasher: opts?.hasher,
191
- }).createVerifiablePresentation(vcs.definition.definition, verifiableCredentials, signCallback, {
192
- proofOptions,
193
- // fixme: Update to newer siop-vp to not require dids here. But when Veramo is creating the VP it's still looking at this field to pass into didManagerGet
194
- ...(identifier && isManagedIdentifierDidResult(identifier) && { holderDID: identifier.did }),
195
- })
86
+ // public async createVerifiablePresentation(
87
+ // credentialRole: CredentialRole,
88
+ // selectedVerifiableCredentials: VerifiableCredentialsWithDefinition,
89
+ // opts?: {
90
+ // forceNoCredentialsInVP?: boolean // Allow to create a VP without credentials, like EBSI is using it. Defaults to false
91
+ // restrictToFormats?: Format
92
+ // restrictToDIDMethods?: string[]
93
+ // proofOpts?: ProofOptions
94
+ // idOpts?: ManagedIdentifierOptsOrResult
95
+ // skipDidResolution?: boolean
96
+ // holder?: string
97
+ // subjectIsHolder?: boolean
98
+ // applyFilter?: boolean
99
+ // hasher?: HasherSync
100
+ // },
101
+ // ): Promise<VerifiablePresentationWithDefinition> {
102
+ // const { subjectIsHolder, holder, forceNoCredentialsInVP = false } = { ...opts }
103
+ // if (subjectIsHolder && holder) {
104
+ // throw Error('Cannot both have subject is holder and a holderDID value at the same time (programming error)')
105
+ // }
106
+ // if (forceNoCredentialsInVP) {
107
+ // selectedVerifiableCredentials.credentials = []
108
+ // } else if (!selectedVerifiableCredentials?.credentials || selectedVerifiableCredentials.credentials.length === 0) {
109
+ // throw Error('No verifiable verifiableCredentials provided for presentation definition')
110
+ // }
111
+ //
112
+ // // const proofOptions: ProofOptions = {
113
+ // // ...opts?.proofOpts,
114
+ // // challenge: opts?.proofOpts?.nonce ?? opts?.proofOpts?.challenge ?? this.session.nonce,
115
+ // // domain: opts?.proofOpts?.domain ?? (await this.session.getRedirectUri()),
116
+ // // }
117
+ //
118
+ // let idOpts = opts?.idOpts
119
+ // if (!idOpts) {
120
+ // if (opts?.subjectIsHolder) {
121
+ // if (forceNoCredentialsInVP) {
122
+ // return Promise.reject(
123
+ // Error(
124
+ // `Cannot have subject is holder, when force no credentials is being used, as we could never determine the holder then. Please provide holderDID`,
125
+ // ),
126
+ // )
127
+ // }
128
+ // const firstUniqueDC = selectedVerifiableCredentials.credentials[0]
129
+ // // const firstVC = firstUniqueDC.uniformVerifiableCredential!
130
+ // if (typeof firstUniqueDC !== 'object' || !('digitalCredential' in firstUniqueDC)) {
131
+ // return Promise.reject(Error('If no opts provided, credentials should be of type UniqueDigitalCredential'))
132
+ // }
133
+ //
134
+ // idOpts = isOID4VCIssuerIdentifier(firstUniqueDC.digitalCredential.kmsKeyRef)
135
+ // ? await this.session.context.agent.identifierManagedGetByIssuer({
136
+ // identifier: firstUniqueDC.digitalCredential.kmsKeyRef,
137
+ // })
138
+ // : await this.session.context.agent.identifierManagedGetByKid({
139
+ // identifier: firstUniqueDC.digitalCredential.kmsKeyRef,
140
+ // kmsKeyRef: firstUniqueDC.digitalCredential.kmsKeyRef,
141
+ // })
142
+ //
143
+ // /*
144
+ // const holder = CredentialMapper.isSdJwtDecodedCredential(firstVC)
145
+ // ? firstVC.decodedPayload.cnf?.jwk
146
+ // ? //TODO SDK-19: convert the JWK to hex and search for the appropriate key and associated DID
147
+ // //doesn't apply to did:jwk only, as you can represent any DID key as a JWK. So whenever you encounter a JWK it doesn't mean it had to come from a did:jwk in the system. It just can always be represented as a did:jwk
148
+ // `did:jwk:${encodeJoseBlob(firstVC.decodedPayload.cnf?.jwk)}#0`
149
+ // : firstVC.decodedPayload.sub
150
+ // : Array.isArray(firstVC.credentialSubject)
151
+ // ? firstVC.credentialSubject[0].id
152
+ // : firstVC.credentialSubject.id
153
+ // if (holder) {
154
+ // idOpts = { identifier: holder }
155
+ // }
156
+ // */
157
+ // } else if (opts?.holder) {
158
+ // idOpts = { identifier: opts.holder }
159
+ // }
160
+ // }
161
+ //
162
+ // // We are making sure to filter, in case the user submitted all verifiableCredentials in the wallet/agent. We also make sure to get original formats back
163
+ // const vcs = forceNoCredentialsInVP
164
+ // ? selectedVerifiableCredentials
165
+ // : opts?.applyFilter
166
+ // ? await this.filterCredentials(credentialRole, selectedVerifiableCredentials.dcqlQuery, {
167
+ // restrictToFormats: opts?.restrictToFormats,
168
+ // restrictToDIDMethods: opts?.restrictToDIDMethods,
169
+ // filterOpts: {
170
+ // verifiableCredentials: selectedVerifiableCredentials.credentials,
171
+ // },
172
+ // })
173
+ // : {
174
+ // definition: selectedVerifiableCredentials.dcqlQuery,
175
+ // credentials: selectedVerifiableCredentials.credentials,
176
+ // }
177
+ //
178
+ // if (!idOpts) {
179
+ // return Promise.reject(Error(`No identifier options present at this point`))
180
+ // }
181
+ //
182
+ // // const signCallback = await createOID4VPPresentationSignCallback({
183
+ // // presentationSignCallback: this.session.options.presentationSignCallback,
184
+ // // idOpts,
185
+ // // context: this.session.context,
186
+ // // domain: proofOptions.domain,
187
+ // // challenge: proofOptions.challenge,
188
+ // // format: opts?.restrictToFormats ?? selectedVerifiableCredentials.dcqlQuery.dcqlQuery.format,
189
+ // // skipDidResolution: opts?.skipDidResolution ?? false,
190
+ // // })
191
+ // const identifier: ManagedIdentifierResult = await this.session.context.agent.identifierManagedGet(idOpts)
192
+ // const verifiableCredentials = vcs.credentials.map((credential) =>
193
+ // typeof credential === 'object' && 'digitalCredential' in credential ? credential.originalVerifiableCredential! : credential,
194
+ // )
195
+ // // const presentationResult = await this.getPresentationExchange({
196
+ // // verifiableCredentials: verifiableCredentials,
197
+ // // allIdentifiers: this.allIdentifiers,
198
+ // // hasher: opts?.hasher,
199
+ // // }).createVerifiablePresentation(vcs.dcqlQuery.dcqlQuery, verifiableCredentials, signCallback, {
200
+ // // proofOptions,
201
+ // // // fixme: Update to newer siop-vp to not require dids here. But when Veramo is creating the VP it's still looking at this field to pass into didManagerGet
202
+ // // ...(identifier && isManagedIdentifierDidResult(identifier) && { holderDID: identifier.did }),
203
+ // // })
204
+ //
205
+ // const verifiablePresentations = presentationResult.verifiablePresentations.map((verifiablePresentation) =>
206
+ // typeof verifiablePresentation !== 'string' &&
207
+ // 'proof' in verifiablePresentation &&
208
+ // 'jwt' in verifiablePresentation.proof &&
209
+ // verifiablePresentation.proof.jwt
210
+ // ? verifiablePresentation.proof.jwt
211
+ // : verifiablePresentation,
212
+ // )
213
+ //
214
+ // return {
215
+ // ...presentationResult,
216
+ // verifiablePresentations,
217
+ // verifiableCredentials: verifiableCredentials,
218
+ // dcqlQuery: selectedVerifiableCredentials.dcqlQuery,
219
+ // idOpts,
220
+ // }
221
+ // }
196
222
 
197
- const verifiablePresentations = presentationResult.verifiablePresentations.map((verifiablePresentation) =>
198
- typeof verifiablePresentation !== 'string' &&
199
- 'proof' in verifiablePresentation &&
200
- 'jwt' in verifiablePresentation.proof &&
201
- verifiablePresentation.proof.jwt
202
- ? verifiablePresentation.proof.jwt
203
- : verifiablePresentation,
204
- )
223
+ // public async filterCredentialsAgainstAllDefinitions(
224
+ // credentialRole: CredentialRole,
225
+ // opts?: {
226
+ // filterOpts?: {
227
+ // verifiableCredentials?: UniqueDigitalCredential[]
228
+ // filter?: FindDigitalCredentialArgs
229
+ // }
230
+ // holderDIDs?: string[]
231
+ // restrictToFormats?: Format
232
+ // restrictToDIDMethods?: string[]
233
+ // },
234
+ // ): Promise<VerifiableCredentialsWithDefinition[]> {
235
+ // const defs = await this.getPresentationDefinitions()
236
+ // const result: VerifiableCredentialsWithDefinition[] = []
237
+ // if (defs) {
238
+ // for (const definition of defs) {
239
+ // result.push(await this.filterCredentials(credentialRole, definition, opts))
240
+ // }
241
+ // }
242
+ // return result
243
+ // }
205
244
 
206
- return {
207
- ...presentationResult,
208
- verifiablePresentations,
209
- verifiableCredentials: verifiableCredentials,
210
- definition: selectedVerifiableCredentials.definition,
211
- idOpts,
212
- }
213
- }
214
-
215
- public async filterCredentialsAgainstAllDefinitions(
216
- credentialRole: CredentialRole,
217
- opts?: {
218
- filterOpts?: {
219
- verifiableCredentials?: UniqueDigitalCredential[]
220
- filter?: FindDigitalCredentialArgs
221
- }
222
- holderDIDs?: string[]
223
- restrictToFormats?: Format
224
- restrictToDIDMethods?: string[]
225
- },
226
- ): Promise<VerifiableCredentialsWithDefinition[]> {
227
- const defs = await this.getPresentationDefinitions()
228
- const result: VerifiableCredentialsWithDefinition[] = []
229
- if (defs) {
230
- for (const definition of defs) {
231
- result.push(await this.filterCredentials(credentialRole, definition, opts))
232
- }
233
- }
234
- return result
235
- }
236
-
237
- public async filterCredentials(
238
- credentialRole: CredentialRole,
239
- presentationDefinition: PresentationDefinitionWithLocation,
240
- opts?: {
241
- filterOpts?: { verifiableCredentials?: (UniqueDigitalCredential | OriginalVerifiableCredential)[]; filter?: FindDigitalCredentialArgs }
242
- holderDIDs?: string[]
243
- restrictToFormats?: Format
244
- restrictToDIDMethods?: string[]
245
- },
246
- ): Promise<VerifiableCredentialsWithDefinition> {
247
- const udcMap = new Map<OriginalVerifiableCredential, UniqueDigitalCredential | OriginalVerifiableCredential>()
248
- opts?.filterOpts?.verifiableCredentials?.forEach((credential) => {
249
- if (typeof credential === 'object' && 'digitalCredential' in credential) {
250
- udcMap.set(credential.originalVerifiableCredential!, credential)
251
- } else {
252
- udcMap.set(credential, credential)
253
- }
254
- })
255
-
256
- const credentials = (
257
- await this.filterCredentialsWithSelectionStatus(credentialRole, presentationDefinition, {
258
- ...opts,
259
- filterOpts: {
260
- verifiableCredentials: opts?.filterOpts?.verifiableCredentials?.map((credential) => {
261
- if (typeof credential === 'object' && 'digitalCredential' in credential) {
262
- return credential.originalVerifiableCredential!
263
- } else {
264
- return credential
265
- }
266
- }),
267
- },
268
- })
269
- ).verifiableCredential
270
- return {
271
- definition: presentationDefinition,
272
- credentials: credentials?.map((vc) => udcMap.get(vc)!) ?? [],
273
- }
274
- }
245
+ // public async filterCredentials(
246
+ // credentialRole: CredentialRole,
247
+ // presentationDefinition: PresentationDefinitionWithLocation,
248
+ // opts?: {
249
+ // filterOpts?: { verifiableCredentials?: (UniqueDigitalCredential | OriginalVerifiableCredential)[]; filter?: FindDigitalCredentialArgs }
250
+ // holderDIDs?: string[]
251
+ // restrictToFormats?: Format
252
+ // restrictToDIDMethods?: string[]
253
+ // },
254
+ // ): Promise<VerifiableCredentialsWithDefinition> {
255
+ // const udcMap = new Map<OriginalVerifiableCredential, UniqueDigitalCredential | OriginalVerifiableCredential>()
256
+ // opts?.filterOpts?.verifiableCredentials?.forEach((credential) => {
257
+ // if (typeof credential === 'object' && 'digitalCredential' in credential) {
258
+ // udcMap.set(credential.originalVerifiableCredential!, credential)
259
+ // } else {
260
+ // udcMap.set(credential, credential)
261
+ // }
262
+ // })
263
+ //
264
+ // const credentials = (
265
+ // await this.filterCredentialsWithSelectionStatus(credentialRole, presentationDefinition, {
266
+ // ...opts,
267
+ // filterOpts: {
268
+ // verifiableCredentials: opts?.filterOpts?.verifiableCredentials?.map((credential) => {
269
+ // if (typeof credential === 'object' && 'digitalCredential' in credential) {
270
+ // return credential.originalVerifiableCredential!
271
+ // } else {
272
+ // return credential
273
+ // }
274
+ // }),
275
+ // },
276
+ // })
277
+ // ).verifiableCredential
278
+ //
279
+ // return {
280
+ // dcqlQuery: presentationDefinition,
281
+ // credentials: credentials?.map((vc) => udcMap.get(vc)!) ?? [],
282
+ // }
283
+ // }
275
284
 
276
- public async filterCredentialsWithSelectionStatus(
277
- credentialRole: CredentialRole,
278
- presentationDefinition: PresentationDefinitionWithLocation,
279
- opts?: {
280
- filterOpts?: { verifiableCredentials?: OriginalVerifiableCredential[]; filter?: FindDigitalCredentialArgs }
281
- holderDIDs?: string[]
282
- restrictToFormats?: Format
283
- restrictToDIDMethods?: string[]
284
- },
285
- ): Promise<SelectResults> {
286
- const selectionResults: SelectResults = await this.getPresentationExchange({
287
- verifiableCredentials: await this.getCredentials(credentialRole, opts?.filterOpts),
288
- }).selectVerifiableCredentialsForSubmission(presentationDefinition.definition, opts)
289
- if (selectionResults.errors && selectionResults.errors.length > 0) {
290
- throw Error(JSON.stringify(selectionResults.errors))
291
- } else if (selectionResults.areRequiredCredentialsPresent === Status.ERROR) {
292
- throw Error(`Not all required credentials are available to satisfy the relying party's request`)
293
- }
294
-
295
- const matches: SubmissionRequirementMatch[] | undefined = selectionResults.matches
296
- if (!matches || matches.length === 0 || !selectionResults.verifiableCredential || selectionResults.verifiableCredential.length === 0) {
297
- throw Error(JSON.stringify(selectionResults.errors))
298
- }
299
- return selectionResults
300
- }
301
-
302
- private async getCredentials(
303
- credentialRole: CredentialRole,
304
- filterOpts?: {
305
- verifiableCredentials?: OriginalVerifiableCredential[]
306
- filter?: FindDigitalCredentialArgs
307
- },
308
- ): Promise<OriginalVerifiableCredential[]> {
309
- if (filterOpts?.verifiableCredentials && filterOpts.verifiableCredentials.length > 0) {
310
- return filterOpts.verifiableCredentials
311
- }
312
-
313
- const filter = verifiableCredentialForRoleFilter(credentialRole, filterOpts?.filter)
314
- const uniqueCredentials = await this.session.context.agent.crsGetUniqueCredentials({ filter })
315
- return uniqueCredentials.map((uniqueVC: UniqueDigitalCredential) => {
316
- const vc = uniqueVC.uniformVerifiableCredential!
317
- const proof = Array.isArray(vc.proof) ? vc.proof : [vc.proof]
318
- const jwtProof = proof.find((p: IProof) => p?.type === DEFAULT_JWT_PROOF_TYPE)
319
- return jwtProof ? (jwtProof.jwt as CompactJWT) : vc
320
- })
321
- }
285
+ // public async filterCredentialsWithSelectionStatus(
286
+ // credentialRole: CredentialRole,
287
+ // presentationDefinition: PresentationDefinitionWithLocation,
288
+ // opts?: {
289
+ // filterOpts?: { verifiableCredentials?: OriginalVerifiableCredential[]; filter?: FindDigitalCredentialArgs }
290
+ // holderDIDs?: string[]
291
+ // restrictToFormats?: Format
292
+ // restrictToDIDMethods?: string[]
293
+ // },
294
+ // ): Promise<SelectResults> {
295
+ // const selectionResults: SelectResults = await this.getPresentationExchange({
296
+ // verifiableCredentials: await this.getCredentials(credentialRole, opts?.filterOpts),
297
+ // }).selectVerifiableCredentialsForSubmission(presentationDefinition.definition, opts)
298
+ // if (selectionResults.errors && selectionResults.errors.length > 0) {
299
+ // throw Error(JSON.stringify(selectionResults.errors))
300
+ // } else if (selectionResults.areRequiredCredentialsPresent === Status.ERROR) {
301
+ // throw Error(`Not all required credentials are available to satisfy the relying party's request`)
302
+ // }
303
+ //
304
+ // const matches: SubmissionRequirementMatch[] | undefined = selectionResults.matches
305
+ // if (!matches || matches.length === 0 || !selectionResults.verifiableCredential || selectionResults.verifiableCredential.length === 0) {
306
+ // throw Error(JSON.stringify(selectionResults.errors))
307
+ // }
308
+ // return selectionResults
309
+ // }
310
+ //
311
+ // private async getCredentials(
312
+ // credentialRole: CredentialRole,
313
+ // filterOpts?: {
314
+ // verifiableCredentials?: OriginalVerifiableCredential[]
315
+ // filter?: FindDigitalCredentialArgs
316
+ // },
317
+ // ): Promise<OriginalVerifiableCredential[]> {
318
+ // if (filterOpts?.verifiableCredentials && filterOpts.verifiableCredentials.length > 0) {
319
+ // return filterOpts.verifiableCredentials
320
+ // }
321
+ //
322
+ // const filter = verifiableCredentialForRoleFilter(credentialRole, filterOpts?.filter)
323
+ // const uniqueCredentials = await this.session.context.agent.crsGetUniqueCredentials({ filter })
324
+ // return uniqueCredentials.map((uniqueVC: UniqueDigitalCredential) => {
325
+ // const vc = uniqueVC.uniformVerifiableCredential!
326
+ // const proof = Array.isArray(vc.proof) ? vc.proof : [vc.proof]
327
+ // const jwtProof = proof.find((p: IProof) => p?.type === DEFAULT_JWT_PROOF_TYPE)
328
+ // return jwtProof ? (jwtProof.jwt as CompactJWT) : vc
329
+ // })
330
+ // }
322
331
  }