@sphereon/ssi-sdk.siopv2-oid4vp-op-auth 0.34.1-feature.SSISDK.26.55 → 0.34.1-feature.SSISDK.26.75

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.26.55+07308f0a",
3
+ "version": "0.34.1-feature.SSISDK.26.75+414583f1",
4
4
  "source": "src/index.ts",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -26,31 +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-feature.SSISDK.13.34",
30
- "@sphereon/did-auth-siop-adapter": "0.19.1-feature.SSISDK.13.34",
31
- "@sphereon/oid4vc-common": "0.19.1-feature.SSISDK.13.34",
29
+ "@sphereon/did-auth-siop": "0.19.1-feature.DIIPv4.86",
30
+ "@sphereon/did-auth-siop-adapter": "0.19.1-feature.DIIPv4.86",
31
+ "@sphereon/oid4vc-common": "0.19.1-feature.DIIPv4.86",
32
32
  "@sphereon/pex": "5.0.0-unstable.28",
33
33
  "@sphereon/pex-models": "^2.3.2",
34
- "@sphereon/ssi-sdk-ext.did-utils": "0.34.1-feature.SSISDK.26.55+07308f0a",
35
- "@sphereon/ssi-sdk-ext.identifier-resolution": "0.34.1-feature.SSISDK.26.55+07308f0a",
36
- "@sphereon/ssi-sdk-ext.jwt-service": "0.34.1-feature.SSISDK.26.55+07308f0a",
37
- "@sphereon/ssi-sdk.contact-manager": "0.34.1-feature.SSISDK.26.55+07308f0a",
38
- "@sphereon/ssi-sdk.core": "0.34.1-feature.SSISDK.26.55+07308f0a",
39
- "@sphereon/ssi-sdk.credential-store": "0.34.1-feature.SSISDK.26.55+07308f0a",
40
- "@sphereon/ssi-sdk.credential-validation": "0.34.1-feature.SSISDK.26.55+07308f0a",
41
- "@sphereon/ssi-sdk.data-store": "0.34.1-feature.SSISDK.26.55+07308f0a",
42
- "@sphereon/ssi-sdk.issuance-branding": "0.34.1-feature.SSISDK.26.55+07308f0a",
43
- "@sphereon/ssi-sdk.pd-manager": "0.34.1-feature.SSISDK.26.55+07308f0a",
44
- "@sphereon/ssi-sdk.presentation-exchange": "0.34.1-feature.SSISDK.26.55+07308f0a",
45
- "@sphereon/ssi-sdk.sd-jwt": "0.34.1-feature.SSISDK.26.55+07308f0a",
46
- "@sphereon/ssi-sdk.siopv2-oid4vp-common": "0.34.1-feature.SSISDK.26.55+07308f0a",
47
- "@sphereon/ssi-sdk.xstate-machine-persistence": "0.34.1-feature.SSISDK.26.55+07308f0a",
48
- "@sphereon/ssi-types": "0.34.1-feature.SSISDK.26.55+07308f0a",
34
+ "@sphereon/ssi-sdk-ext.did-utils": "0.34.1-feature.SSISDK.26.75+414583f1",
35
+ "@sphereon/ssi-sdk-ext.identifier-resolution": "0.34.1-feature.SSISDK.26.75+414583f1",
36
+ "@sphereon/ssi-sdk-ext.jwt-service": "0.34.1-feature.SSISDK.26.75+414583f1",
37
+ "@sphereon/ssi-sdk.contact-manager": "0.34.1-feature.SSISDK.26.75+414583f1",
38
+ "@sphereon/ssi-sdk.core": "0.34.1-feature.SSISDK.26.75+414583f1",
39
+ "@sphereon/ssi-sdk.credential-store": "0.34.1-feature.SSISDK.26.75+414583f1",
40
+ "@sphereon/ssi-sdk.credential-validation": "0.34.1-feature.SSISDK.26.75+414583f1",
41
+ "@sphereon/ssi-sdk.data-store": "0.34.1-feature.SSISDK.26.75+414583f1",
42
+ "@sphereon/ssi-sdk.issuance-branding": "0.34.1-feature.SSISDK.26.75+414583f1",
43
+ "@sphereon/ssi-sdk.pd-manager": "0.34.1-feature.SSISDK.26.75+414583f1",
44
+ "@sphereon/ssi-sdk.presentation-exchange": "0.34.1-feature.SSISDK.26.75+414583f1",
45
+ "@sphereon/ssi-sdk.sd-jwt": "0.34.1-feature.SSISDK.26.75+414583f1",
46
+ "@sphereon/ssi-sdk.siopv2-oid4vp-common": "0.34.1-feature.SSISDK.26.75+414583f1",
47
+ "@sphereon/ssi-sdk.xstate-machine-persistence": "0.34.1-feature.SSISDK.26.75+414583f1",
48
+ "@sphereon/ssi-types": "0.34.1-feature.SSISDK.26.75+414583f1",
49
49
  "@sphereon/wellknown-dids-client": "^0.1.3",
50
50
  "@veramo/core": "4.2.0",
51
51
  "@veramo/credential-w3c": "4.2.0",
52
52
  "cross-fetch": "^4.1.0",
53
- "dcql": "0.2.19",
53
+ "dcql": "1.0.1",
54
54
  "did-jwt-vc": "3.1.3",
55
55
  "i18n-js": "^3.9.2",
56
56
  "lodash.memoize": "^4.1.2",
@@ -59,8 +59,8 @@
59
59
  },
60
60
  "devDependencies": {
61
61
  "@sphereon/did-uni-client": "^0.6.3",
62
- "@sphereon/ssi-sdk-ext.did-resolver-jwk": "0.34.1-feature.SSISDK.26.55+07308f0a",
63
- "@sphereon/ssi-sdk.agent-config": "0.34.1-feature.SSISDK.26.55+07308f0a",
62
+ "@sphereon/ssi-sdk-ext.did-resolver-jwk": "0.34.1-feature.SSISDK.26.75+414583f1",
63
+ "@sphereon/ssi-sdk.agent-config": "0.34.1-feature.SSISDK.26.75+414583f1",
64
64
  "@types/i18n-js": "^3.8.9",
65
65
  "@types/lodash.memoize": "^4.1.9",
66
66
  "@types/sha.js": "^2.4.4",
@@ -102,5 +102,5 @@
102
102
  "OpenID Connect",
103
103
  "Authenticator"
104
104
  ],
105
- "gitHead": "07308f0a0f6e8d5b9f116e7cc8bb21a680207ff3"
105
+ "gitHead": "414583f1b1ed3f44a7b125c6a4f816c573aefacd"
106
106
  }
@@ -1,27 +1,29 @@
1
- import { decodeUriAsJson, PresentationSignCallback, SupportedVersion, VerifiedAuthorizationRequest } from '@sphereon/did-auth-siop'
1
+ import { decodeUriAsJson, PresentationSignCallback, VerifiedAuthorizationRequest } from '@sphereon/did-auth-siop'
2
2
  import {
3
3
  ConnectionType,
4
4
  CorrelationIdentifierType,
5
- CredentialDocumentFormat,
6
5
  CredentialRole,
7
- DocumentType,
8
6
  Identity,
9
7
  IdentityOrigin,
10
8
  NonPersistedIdentity,
11
9
  Party,
12
10
  } from '@sphereon/ssi-sdk.data-store'
13
- import { HasherSync, Loggers, SdJwtDecodedVerifiableCredential } from '@sphereon/ssi-types'
11
+ import { HasherSync, Loggers } from '@sphereon/ssi-types'
14
12
  import { IAgentPlugin } from '@veramo/core'
13
+ import { EventEmitter } from 'events'
15
14
  import { v4 as uuidv4 } from 'uuid'
15
+ import { schema } from '..'
16
+ import { Siopv2Machine } from '../machine/Siopv2Machine'
17
+ import { getSelectableCredentials, siopSendAuthorizationResponse, translateCorrelationIdToName } from '../services/Siopv2MachineService'
16
18
 
17
19
  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'
21
- import { EventEmitter } from 'events'
22
20
  import {
21
+ AddIdentityArgs,
22
+ CreateConfigArgs,
23
+ CreateConfigResult,
23
24
  DidAuthSiopOpAuthenticatorOptions,
24
25
  GetSelectableCredentialsArgs,
26
+ GetSiopRequestArgs,
25
27
  IDidAuthSiopOpAuthenticator,
26
28
  IGetSiopSessionArgs,
27
29
  IOpSessionArgs,
@@ -29,32 +31,19 @@ import {
29
31
  IRemoveCustomApprovalForSiopArgs,
30
32
  IRemoveSiopSessionArgs,
31
33
  IRequiredContext,
32
- Json,
33
34
  LOGGER_NAMESPACE,
34
- RequiredContext,
35
- SelectableCredentialsMap,
36
- Siopv2AuthorizationResponseData,
37
- VerifiableCredentialsWithDefinition,
38
- } from '../types'
39
-
40
- import {
41
- AddIdentityArgs,
42
- CreateConfigArgs,
43
- CreateConfigResult,
44
- GetSiopRequestArgs,
45
35
  OnContactIdentityCreatedArgs,
46
36
  OnIdentifierCreatedArgs,
37
+ RequiredContext,
47
38
  RetrieveContactArgs,
39
+ SelectableCredentialsMap,
48
40
  SendResponseArgs,
49
41
  Siopv2AuthorizationRequestData,
42
+ Siopv2AuthorizationResponseData,
50
43
  Siopv2HolderEvent,
51
44
  Siopv2Machine as Siopv2MachineId,
52
45
  Siopv2MachineInstanceOpts,
53
46
  } from '../types'
54
- import { DcqlCredential, DcqlPresentation, DcqlQuery, DcqlSdJwtVcCredential } from 'dcql'
55
- import { Siopv2Machine } from '../machine/Siopv2Machine'
56
- import { getSelectableCredentials, siopSendAuthorizationResponse, translateCorrelationIdToName } from '../services/Siopv2MachineService'
57
- import { schema } from '..'
58
47
 
59
48
  const logger = Loggers.DEFAULT.options(LOGGER_NAMESPACE, {}).get(LOGGER_NAMESPACE)
60
49
 
@@ -104,7 +93,7 @@ export class DidAuthSiopOpAuthenticator implements IAgentPlugin {
104
93
  this.hasher = hasher
105
94
  this.onContactIdentityCreated = onContactIdentityCreated
106
95
  this.onIdentifierCreated = onIdentifierCreated
107
- this.presentationSignCallback = presentationSignCallback
96
+ this.presentationSignCallback = presentationSignCallback // TODO do we still need this?
108
97
  this.sessions = new Map<string, OpSession>()
109
98
  this.customApprovals = customApprovals
110
99
  }
@@ -234,7 +223,7 @@ export class DidAuthSiopOpAuthenticator implements IAgentPlugin {
234
223
  : (verifiedAuthorizationRequest.issuer ?? verifiedAuthorizationRequest.registrationMetadataPayload?.client_id))
235
224
  const uri: URL | undefined = url.includes('://') ? new URL(url) : undefined
236
225
  const correlationId: string = uri?.hostname ?? (await this.determineCorrelationId(uri, verifiedAuthorizationRequest, clientName, context))
237
- const clientId: string | undefined = await verifiedAuthorizationRequest.authorizationRequest.getMergedProperty<string>('client_id')
226
+ const clientId: string | undefined = verifiedAuthorizationRequest.authorizationRequest.getMergedProperty<string>('client_id')
238
227
 
239
228
  return {
240
229
  issuer: verifiedAuthorizationRequest.issuer,
@@ -243,13 +232,6 @@ export class DidAuthSiopOpAuthenticator implements IAgentPlugin {
243
232
  uri,
244
233
  name: clientName,
245
234
  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,
253
235
  dcqlQuery: verifiedAuthorizationRequest.dcqlQuery,
254
236
  }
255
237
  }
@@ -349,87 +331,14 @@ export class DidAuthSiopOpAuthenticator implements IAgentPlugin {
349
331
  return Promise.reject(Error('Missing authorization request data in context'))
350
332
  }
351
333
 
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: 'dc+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
-
425
334
  const response = await siopSendAuthorizationResponse(
426
335
  ConnectionType.SIOPv2_OpenID4VP,
427
336
  {
428
337
  sessionId: didAuthConfig.sessionId,
429
338
  ...(args.idOpts && { idOpts: args.idOpts }),
430
- ...(authorizationRequestData.presentationDefinitions !== undefined && { verifiableCredentialsWithDefinition }),
431
339
  isFirstParty,
432
340
  hasher: this.hasher,
341
+ credentials: selectedCredentials,
433
342
  },
434
343
  context,
435
344
  )
@@ -449,50 +358,13 @@ export class DidAuthSiopOpAuthenticator implements IAgentPlugin {
449
358
  }
450
359
  }
451
360
 
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
-
482
361
  private async siopGetSelectableCredentials(args: GetSelectableCredentialsArgs, context: RequiredContext): Promise<SelectableCredentialsMap> {
483
362
  const { authorizationRequestData } = args
484
363
 
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'))
364
+ if (!authorizationRequestData?.dcqlQuery) {
365
+ return Promise.reject(Error('Missing required dcql query in context'))
494
366
  }
495
367
 
496
- return getSelectableCredentials(authorizationRequestData.presentationDefinitions[0].definition, context)
368
+ return getSelectableCredentials(authorizationRequestData?.dcqlQuery, context)
497
369
  }
498
370
  }
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @public
3
3
  */
4
- const schema = require('../plugin.schema.json')
4
+ import schema from '../plugin.schema.json'
5
5
  export { schema }
6
6
  export { DidAuthSiopOpAuthenticator, didAuthSiopOpAuthenticatorMethods } from './agent/DidAuthSiopOpAuthenticator'
7
7
  export { Siopv2Machine } from './machine/Siopv2Machine'
@@ -9,3 +9,4 @@ 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.presentationDefinitions !== undefined
54
+ return authorizationRequestData.dcqlQuery !== 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.presentationDefinitions === undefined || authorizationRequestData.presentationDefinitions.length === 0) {
70
+ if (authorizationRequestData.dcqlQuery === undefined) {
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.presentationDefinitions === undefined
90
+ return authorizationRequestData.dcqlQuery === 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.presentationDefinitions !== undefined
104
+ return authorizationRequestData.dcqlQuery !== undefined
105
105
  }
106
106
 
107
107
  const createSiopv2Machine = (opts: CreateSiopv2MachineOpts): Siopv2StateMachine => {