@sphereon/ssi-sdk.siopv2-oid4vp-op-auth 0.34.1-feature.SSISDK.45.94 → 0.34.1-feature.SSISDK.46.40

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sphereon/ssi-sdk.siopv2-oid4vp-op-auth",
3
- "version": "0.34.1-feature.SSISDK.45.94+24a0078a",
3
+ "version": "0.34.1-feature.SSISDK.46.40+f6339611",
4
4
  "source": "src/index.ts",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -26,30 +26,31 @@
26
26
  "build": "tsup --config ../../tsup.config.ts --tsconfig ../../tsconfig.tsup.json"
27
27
  },
28
28
  "dependencies": {
29
- "@sphereon/did-auth-siop": "0.19.1-feat.SSISDK.34.74",
30
- "@sphereon/did-auth-siop-adapter": "0.19.1-feat.SSISDK.34.74",
31
- "@sphereon/oid4vc-common": "0.19.1-feat.SSISDK.34.74",
29
+ "@sphereon/did-auth-siop": "0.19.1-next.2",
30
+ "@sphereon/did-auth-siop-adapter": "0.19.1-next.2",
31
+ "@sphereon/oid4vc-common": "0.19.1-next.2",
32
+ "@sphereon/pex": "5.0.0-unstable.28",
32
33
  "@sphereon/pex-models": "^2.3.2",
33
- "@sphereon/ssi-sdk-ext.did-utils": "0.34.1-feature.SSISDK.45.94+24a0078a",
34
- "@sphereon/ssi-sdk-ext.identifier-resolution": "0.34.1-feature.SSISDK.45.94+24a0078a",
35
- "@sphereon/ssi-sdk-ext.jwt-service": "0.34.1-feature.SSISDK.45.94+24a0078a",
36
- "@sphereon/ssi-sdk.contact-manager": "0.34.1-feature.SSISDK.45.94+24a0078a",
37
- "@sphereon/ssi-sdk.core": "0.34.1-feature.SSISDK.45.94+24a0078a",
38
- "@sphereon/ssi-sdk.credential-store": "0.34.1-feature.SSISDK.45.94+24a0078a",
39
- "@sphereon/ssi-sdk.credential-validation": "0.34.1-feature.SSISDK.45.94+24a0078a",
40
- "@sphereon/ssi-sdk.data-store": "0.34.1-feature.SSISDK.45.94+24a0078a",
41
- "@sphereon/ssi-sdk.issuance-branding": "0.34.1-feature.SSISDK.45.94+24a0078a",
42
- "@sphereon/ssi-sdk.pd-manager": "0.34.1-feature.SSISDK.45.94+24a0078a",
43
- "@sphereon/ssi-sdk.presentation-exchange": "0.34.1-feature.SSISDK.45.94+24a0078a",
44
- "@sphereon/ssi-sdk.sd-jwt": "0.34.1-feature.SSISDK.45.94+24a0078a",
45
- "@sphereon/ssi-sdk.siopv2-oid4vp-common": "0.34.1-feature.SSISDK.45.94+24a0078a",
46
- "@sphereon/ssi-sdk.xstate-machine-persistence": "0.34.1-feature.SSISDK.45.94+24a0078a",
47
- "@sphereon/ssi-types": "0.34.1-feature.SSISDK.45.94+24a0078a",
34
+ "@sphereon/ssi-sdk-ext.did-utils": "0.34.1-feature.SSISDK.46.40+f6339611",
35
+ "@sphereon/ssi-sdk-ext.identifier-resolution": "0.34.1-feature.SSISDK.46.40+f6339611",
36
+ "@sphereon/ssi-sdk-ext.jwt-service": "0.34.1-feature.SSISDK.46.40+f6339611",
37
+ "@sphereon/ssi-sdk.contact-manager": "0.34.1-feature.SSISDK.46.40+f6339611",
38
+ "@sphereon/ssi-sdk.core": "0.34.1-feature.SSISDK.46.40+f6339611",
39
+ "@sphereon/ssi-sdk.credential-store": "0.34.1-feature.SSISDK.46.40+f6339611",
40
+ "@sphereon/ssi-sdk.credential-validation": "0.34.1-feature.SSISDK.46.40+f6339611",
41
+ "@sphereon/ssi-sdk.data-store": "0.34.1-feature.SSISDK.46.40+f6339611",
42
+ "@sphereon/ssi-sdk.issuance-branding": "0.34.1-feature.SSISDK.46.40+f6339611",
43
+ "@sphereon/ssi-sdk.pd-manager": "0.34.1-feature.SSISDK.46.40+f6339611",
44
+ "@sphereon/ssi-sdk.presentation-exchange": "0.34.1-feature.SSISDK.46.40+f6339611",
45
+ "@sphereon/ssi-sdk.sd-jwt": "0.34.1-feature.SSISDK.46.40+f6339611",
46
+ "@sphereon/ssi-sdk.siopv2-oid4vp-common": "0.34.1-feature.SSISDK.46.40+f6339611",
47
+ "@sphereon/ssi-sdk.xstate-machine-persistence": "0.34.1-feature.SSISDK.46.40+f6339611",
48
+ "@sphereon/ssi-types": "0.34.1-feature.SSISDK.46.40+f6339611",
48
49
  "@sphereon/wellknown-dids-client": "^0.1.3",
49
50
  "@veramo/core": "4.2.0",
50
51
  "@veramo/credential-w3c": "4.2.0",
51
- "cross-fetch": "^4.1.0",
52
- "dcql": "1.0.1",
52
+ "cross-fetch": "^3.1.8",
53
+ "dcql": "0.2.19",
53
54
  "did-jwt-vc": "3.1.3",
54
55
  "i18n-js": "^3.9.2",
55
56
  "lodash.memoize": "^4.1.2",
@@ -58,8 +59,8 @@
58
59
  },
59
60
  "devDependencies": {
60
61
  "@sphereon/did-uni-client": "^0.6.3",
61
- "@sphereon/ssi-sdk-ext.did-resolver-jwk": "0.34.1-feature.SSISDK.45.94+24a0078a",
62
- "@sphereon/ssi-sdk.agent-config": "0.34.1-feature.SSISDK.45.94+24a0078a",
62
+ "@sphereon/ssi-sdk-ext.did-resolver-jwk": "0.34.1-feature.SSISDK.46.40+f6339611",
63
+ "@sphereon/ssi-sdk.agent-config": "0.34.1-feature.SSISDK.46.40+f6339611",
63
64
  "@types/i18n-js": "^3.8.9",
64
65
  "@types/lodash.memoize": "^4.1.9",
65
66
  "@types/sha.js": "^2.4.4",
@@ -101,5 +102,5 @@
101
102
  "OpenID Connect",
102
103
  "Authenticator"
103
104
  ],
104
- "gitHead": "24a0078a739502cd84e93cc2d4c3938c8854087a"
105
+ "gitHead": "f633961166543652ec09e4e194ed2bacbcb92602"
105
106
  }
@@ -1,9 +1,23 @@
1
- import { decodeUriAsJson, PresentationSignCallback, VerifiedAuthorizationRequest } from '@sphereon/did-auth-siop'
2
- import { ConnectionType, CorrelationIdentifierType, Identity, IdentityOrigin, NonPersistedIdentity, Party } from '@sphereon/ssi-sdk.data-store'
3
- import { HasherSync, Loggers, CredentialRole } from '@sphereon/ssi-types'
1
+ import { decodeUriAsJson, PresentationSignCallback, SupportedVersion, VerifiedAuthorizationRequest } from '@sphereon/did-auth-siop'
2
+ import {
3
+ ConnectionType,
4
+ CorrelationIdentifierType,
5
+ CredentialDocumentFormat,
6
+ CredentialRole,
7
+ DocumentType,
8
+ Identity,
9
+ IdentityOrigin,
10
+ NonPersistedIdentity,
11
+ Party,
12
+ } from '@sphereon/ssi-sdk.data-store'
13
+ import { HasherSync, Loggers, SdJwtDecodedVerifiableCredential } from '@sphereon/ssi-types'
4
14
  import { IAgentPlugin } from '@veramo/core'
5
15
  import { v4 as uuidv4 } from 'uuid'
16
+
6
17
  import { OpSession } from '../session'
18
+ import { PEX, Status } from '@sphereon/pex'
19
+ import { computeEntryHash } from '@veramo/utils'
20
+ import { UniqueDigitalCredential } from '@sphereon/ssi-sdk.credential-store'
7
21
  import { EventEmitter } from 'events'
8
22
  import {
9
23
  DidAuthSiopOpAuthenticatorOptions,
@@ -15,11 +29,14 @@ import {
15
29
  IRemoveCustomApprovalForSiopArgs,
16
30
  IRemoveSiopSessionArgs,
17
31
  IRequiredContext,
32
+ Json,
18
33
  LOGGER_NAMESPACE,
19
34
  RequiredContext,
20
35
  SelectableCredentialsMap,
21
36
  Siopv2AuthorizationResponseData,
37
+ VerifiableCredentialsWithDefinition,
22
38
  } from '../types'
39
+
23
40
  import {
24
41
  AddIdentityArgs,
25
42
  CreateConfigArgs,
@@ -34,6 +51,7 @@ import {
34
51
  Siopv2Machine as Siopv2MachineId,
35
52
  Siopv2MachineInstanceOpts,
36
53
  } from '../types'
54
+ import { DcqlCredential, DcqlPresentation, DcqlQuery, DcqlSdJwtVcCredential } from 'dcql'
37
55
  import { Siopv2Machine } from '../machine/Siopv2Machine'
38
56
  import { getSelectableCredentials, siopSendAuthorizationResponse, translateCorrelationIdToName } from '../services/Siopv2MachineService'
39
57
  import { schema } from '..'
@@ -86,7 +104,7 @@ export class DidAuthSiopOpAuthenticator implements IAgentPlugin {
86
104
  this.hasher = hasher
87
105
  this.onContactIdentityCreated = onContactIdentityCreated
88
106
  this.onIdentifierCreated = onIdentifierCreated
89
- this.presentationSignCallback = presentationSignCallback // TODO do we still need this?
107
+ this.presentationSignCallback = presentationSignCallback
90
108
  this.sessions = new Map<string, OpSession>()
91
109
  this.customApprovals = customApprovals
92
110
  }
@@ -216,7 +234,7 @@ export class DidAuthSiopOpAuthenticator implements IAgentPlugin {
216
234
  : (verifiedAuthorizationRequest.issuer ?? verifiedAuthorizationRequest.registrationMetadataPayload?.client_id))
217
235
  const uri: URL | undefined = url.includes('://') ? new URL(url) : undefined
218
236
  const correlationId: string = uri?.hostname ?? (await this.determineCorrelationId(uri, verifiedAuthorizationRequest, clientName, context))
219
- const clientId: string | undefined = verifiedAuthorizationRequest.authorizationRequest.getMergedProperty<string>('client_id')
237
+ const clientId: string | undefined = await verifiedAuthorizationRequest.authorizationRequest.getMergedProperty<string>('client_id')
220
238
 
221
239
  return {
222
240
  issuer: verifiedAuthorizationRequest.issuer,
@@ -225,6 +243,13 @@ export class DidAuthSiopOpAuthenticator implements IAgentPlugin {
225
243
  uri,
226
244
  name: clientName,
227
245
  clientId,
246
+ presentationDefinitions:
247
+ (await verifiedAuthorizationRequest.authorizationRequest.containsResponseType('vp_token')) ||
248
+ (verifiedAuthorizationRequest.versions.every((version) => version <= SupportedVersion.JWT_VC_PRESENTATION_PROFILE_v1) &&
249
+ verifiedAuthorizationRequest.presentationDefinitions &&
250
+ verifiedAuthorizationRequest.presentationDefinitions.length > 0)
251
+ ? verifiedAuthorizationRequest.presentationDefinitions
252
+ : undefined,
228
253
  dcqlQuery: verifiedAuthorizationRequest.dcqlQuery,
229
254
  }
230
255
  }
@@ -324,14 +349,87 @@ export class DidAuthSiopOpAuthenticator implements IAgentPlugin {
324
349
  return Promise.reject(Error('Missing authorization request data in context'))
325
350
  }
326
351
 
352
+ const pex = new PEX({ hasher: this.hasher })
353
+ const verifiableCredentialsWithDefinition: Array<VerifiableCredentialsWithDefinition> = []
354
+ const dcqlCredentialsWithCredentials: Map<DcqlCredential, UniqueDigitalCredential> = new Map()
355
+
356
+ if (Array.isArray(authorizationRequestData.presentationDefinitions) && authorizationRequestData?.presentationDefinitions.length > 0) {
357
+ try {
358
+ authorizationRequestData.presentationDefinitions?.forEach((presentationDefinition) => {
359
+ const { areRequiredCredentialsPresent, verifiableCredential: verifiableCredentials } = pex.selectFrom(
360
+ presentationDefinition.definition,
361
+ selectedCredentials.map((udc) => udc.originalVerifiableCredential!),
362
+ )
363
+
364
+ if (areRequiredCredentialsPresent !== Status.ERROR && verifiableCredentials) {
365
+ let uniqueDigitalCredentials: UniqueDigitalCredential[] = []
366
+ uniqueDigitalCredentials = verifiableCredentials.map((vc) => {
367
+ // @ts-ignore FIXME Funke
368
+ const hash = typeof vc === 'string' ? computeEntryHash(vc.split('~'[0])) : computeEntryHash(vc)
369
+ const udc = selectedCredentials.find((udc) => udc.hash == hash || udc.originalVerifiableCredential == vc)
370
+
371
+ if (!udc) {
372
+ throw Error(
373
+ `UniqueDigitalCredential could not be found in store. Either the credential is not present in the store or the hash is not correct.`,
374
+ )
375
+ }
376
+ return udc
377
+ })
378
+ verifiableCredentialsWithDefinition.push({
379
+ definition: presentationDefinition,
380
+ credentials: uniqueDigitalCredentials,
381
+ })
382
+ }
383
+ })
384
+ } catch (e) {
385
+ return Promise.reject(e)
386
+ }
387
+
388
+ if (verifiableCredentialsWithDefinition.length === 0) {
389
+ return Promise.reject(Error('None of the selected credentials match any of the presentation definitions.'))
390
+ }
391
+ } else if (authorizationRequestData.dcqlQuery) {
392
+ //TODO Only SD-JWT and MSO MDOC are supported at the moment
393
+ if (this.hasMDocCredentials(selectedCredentials) || this.hasSdJwtCredentials(selectedCredentials)) {
394
+ try {
395
+ selectedCredentials.forEach((vc) => {
396
+ if (this.isSdJwtCredential(vc)) {
397
+ const payload = (vc.originalVerifiableCredential as SdJwtDecodedVerifiableCredential).decodedPayload
398
+ const result: DcqlSdJwtVcCredential = {
399
+ claims: payload as { [x: string]: Json },
400
+ vct: payload.vct,
401
+ credential_format: 'vc+sd-jwt',
402
+ }
403
+ dcqlCredentialsWithCredentials.set(result, vc)
404
+ //FIXME MDoc namespaces are incompatible: array of strings vs complex object - https://sphereon.atlassian.net/browse/SPRIND-143
405
+ } else {
406
+ throw Error(`Invalid credential format: ${vc.digitalCredential.documentFormat}`)
407
+ }
408
+ })
409
+ } catch (e) {
410
+ return Promise.reject(e)
411
+ }
412
+
413
+ const dcqlPresentationRecord: DcqlPresentation.Output = {}
414
+ const queryResult = DcqlQuery.query(authorizationRequestData.dcqlQuery, Array.from(dcqlCredentialsWithCredentials.keys()))
415
+ for (const [key, value] of Object.entries(queryResult.credential_matches)) {
416
+ if (value.success) {
417
+ dcqlPresentationRecord[key] = this.retrieveEncodedCredential(dcqlCredentialsWithCredentials.get(value.output)!) as
418
+ | string
419
+ | { [x: string]: Json }
420
+ }
421
+ }
422
+ }
423
+ }
424
+
327
425
  const response = await siopSendAuthorizationResponse(
328
426
  ConnectionType.SIOPv2_OpenID4VP,
329
427
  {
330
428
  sessionId: didAuthConfig.sessionId,
331
429
  ...(args.idOpts && { idOpts: args.idOpts }),
430
+ ...(authorizationRequestData.presentationDefinitions !== undefined && { verifiableCredentialsWithDefinition }),
332
431
  isFirstParty,
333
432
  hasher: this.hasher,
334
- credentials: selectedCredentials,
335
433
  },
336
434
  context,
337
435
  )
@@ -351,13 +449,50 @@ export class DidAuthSiopOpAuthenticator implements IAgentPlugin {
351
449
  }
352
450
  }
353
451
 
452
+ private hasMDocCredentials = (credentials: UniqueDigitalCredential[]): boolean => {
453
+ return credentials.some(this.isMDocCredential)
454
+ }
455
+
456
+ private isMDocCredential = (credential: UniqueDigitalCredential) => {
457
+ return (
458
+ credential.digitalCredential.documentFormat === CredentialDocumentFormat.MSO_MDOC &&
459
+ credential.digitalCredential.documentType === DocumentType.VC
460
+ )
461
+ }
462
+
463
+ private hasSdJwtCredentials = (credentials: UniqueDigitalCredential[]): boolean => {
464
+ return credentials.some(this.isSdJwtCredential)
465
+ }
466
+
467
+ private isSdJwtCredential = (credential: UniqueDigitalCredential) => {
468
+ return (
469
+ credential.digitalCredential.documentFormat === CredentialDocumentFormat.SD_JWT && credential.digitalCredential.documentType === DocumentType.VC
470
+ )
471
+ }
472
+
473
+ private retrieveEncodedCredential = (credential: UniqueDigitalCredential) => {
474
+ return credential.originalVerifiableCredential !== undefined &&
475
+ credential.originalVerifiableCredential !== null &&
476
+ (credential?.originalVerifiableCredential as SdJwtDecodedVerifiableCredential)?.compactSdJwtVc !== undefined &&
477
+ (credential?.originalVerifiableCredential as SdJwtDecodedVerifiableCredential)?.compactSdJwtVc !== null
478
+ ? (credential.originalVerifiableCredential as SdJwtDecodedVerifiableCredential).compactSdJwtVc
479
+ : credential.originalVerifiableCredential
480
+ }
481
+
354
482
  private async siopGetSelectableCredentials(args: GetSelectableCredentialsArgs, context: RequiredContext): Promise<SelectableCredentialsMap> {
355
483
  const { authorizationRequestData } = args
356
484
 
357
- if (!authorizationRequestData?.dcqlQuery) {
358
- return Promise.reject(Error('Missing required dcql query in context'))
485
+ if (
486
+ !authorizationRequestData ||
487
+ !authorizationRequestData.presentationDefinitions ||
488
+ authorizationRequestData.presentationDefinitions.length === 0
489
+ ) {
490
+ return Promise.reject(Error('Missing required fields in arguments or context'))
491
+ }
492
+ if (authorizationRequestData.presentationDefinitions.length > 1) {
493
+ return Promise.reject(Error('Multiple presentation definitions present'))
359
494
  }
360
495
 
361
- return getSelectableCredentials(authorizationRequestData?.dcqlQuery, context)
496
+ return getSelectableCredentials(authorizationRequestData.presentationDefinitions[0].definition, context)
362
497
  }
363
498
  }
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @public
3
3
  */
4
- import schema from '../plugin.schema.json'
4
+ const schema = require('../plugin.schema.json')
5
5
  export { schema }
6
6
  export { DidAuthSiopOpAuthenticator, didAuthSiopOpAuthenticatorMethods } from './agent/DidAuthSiopOpAuthenticator'
7
7
  export { Siopv2Machine } from './machine/Siopv2Machine'
@@ -9,4 +9,3 @@ export * from './machine/CallbackStateListener'
9
9
  export * from './session'
10
10
  export * from './types'
11
11
  export * from './link-handler'
12
- export * from './utils/dcql'
@@ -51,7 +51,7 @@ const Siopv2HasSelectableCredentialsAndContactGuard = (_ctx: Siopv2MachineContex
51
51
  throw new Error('Missing contact request data in context')
52
52
  }
53
53
 
54
- return authorizationRequestData.dcqlQuery !== undefined
54
+ return authorizationRequestData.presentationDefinitions !== undefined
55
55
  }
56
56
 
57
57
  const Siopv2CreateContactGuard = (_ctx: Siopv2MachineContext, _event: Siopv2MachineEventTypes): boolean => {
@@ -67,7 +67,7 @@ const Siopv2HasSelectedRequiredCredentialsGuard = (_ctx: Siopv2MachineContext, _
67
67
  throw new Error('Missing authorization request data in context')
68
68
  }
69
69
 
70
- if (authorizationRequestData.dcqlQuery === undefined) {
70
+ if (authorizationRequestData.presentationDefinitions === undefined || authorizationRequestData.presentationDefinitions.length === 0) {
71
71
  throw Error('No presentation definitions present')
72
72
  }
73
73
 
@@ -87,7 +87,7 @@ const Siopv2IsSiopOnlyGuard = (_ctx: Siopv2MachineContext, _event: Siopv2Machine
87
87
  throw new Error('Missing authorization request data in context')
88
88
  }
89
89
 
90
- return authorizationRequestData.dcqlQuery === undefined
90
+ return authorizationRequestData.presentationDefinitions === undefined
91
91
  }
92
92
 
93
93
  const Siopv2IsSiopWithOID4VPGuard = (_ctx: Siopv2MachineContext, _event: Siopv2MachineEventTypes): boolean => {
@@ -101,7 +101,7 @@ const Siopv2IsSiopWithOID4VPGuard = (_ctx: Siopv2MachineContext, _event: Siopv2M
101
101
  throw new Error('Missing selectableCredentialsMap in context')
102
102
  }
103
103
 
104
- return authorizationRequestData.dcqlQuery !== undefined
104
+ return authorizationRequestData.presentationDefinitions !== undefined
105
105
  }
106
106
 
107
107
  const createSiopv2Machine = (opts: CreateSiopv2MachineOpts): Siopv2StateMachine => {