@sphereon/ssi-sdk.siopv2-oid4vp-op-auth 0.34.1-feature.merge.crypto.extensions.modules.37 → 0.34.1-fix.103

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.merge.crypto.extensions.modules.37+86254fab",
3
+ "version": "0.34.1-fix.103+693d8f0b",
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-next.2",
30
- "@sphereon/did-auth-siop-adapter": "0.19.1-next.2",
31
- "@sphereon/oid4vc-common": "0.19.1-next.2",
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.merge.crypto.extensions.modules.37+86254fab",
35
- "@sphereon/ssi-sdk-ext.identifier-resolution": "0.34.1-feature.merge.crypto.extensions.modules.37+86254fab",
36
- "@sphereon/ssi-sdk-ext.jwt-service": "0.34.1-feature.merge.crypto.extensions.modules.37+86254fab",
37
- "@sphereon/ssi-sdk.contact-manager": "0.34.1-feature.merge.crypto.extensions.modules.37+86254fab",
38
- "@sphereon/ssi-sdk.core": "0.34.1-feature.merge.crypto.extensions.modules.37+86254fab",
39
- "@sphereon/ssi-sdk.credential-store": "0.34.1-feature.merge.crypto.extensions.modules.37+86254fab",
40
- "@sphereon/ssi-sdk.credential-validation": "0.34.1-feature.merge.crypto.extensions.modules.37+86254fab",
41
- "@sphereon/ssi-sdk.data-store": "0.34.1-feature.merge.crypto.extensions.modules.37+86254fab",
42
- "@sphereon/ssi-sdk.issuance-branding": "0.34.1-feature.merge.crypto.extensions.modules.37+86254fab",
43
- "@sphereon/ssi-sdk.pd-manager": "0.34.1-feature.merge.crypto.extensions.modules.37+86254fab",
44
- "@sphereon/ssi-sdk.presentation-exchange": "0.34.1-feature.merge.crypto.extensions.modules.37+86254fab",
45
- "@sphereon/ssi-sdk.sd-jwt": "0.34.1-feature.merge.crypto.extensions.modules.37+86254fab",
46
- "@sphereon/ssi-sdk.siopv2-oid4vp-common": "0.34.1-feature.merge.crypto.extensions.modules.37+86254fab",
47
- "@sphereon/ssi-sdk.xstate-machine-persistence": "0.34.1-feature.merge.crypto.extensions.modules.37+86254fab",
48
- "@sphereon/ssi-types": "0.34.1-feature.merge.crypto.extensions.modules.37+86254fab",
34
+ "@sphereon/ssi-sdk-ext.did-utils": "0.34.1-fix.103+693d8f0b",
35
+ "@sphereon/ssi-sdk-ext.identifier-resolution": "0.34.1-fix.103+693d8f0b",
36
+ "@sphereon/ssi-sdk-ext.jwt-service": "0.34.1-fix.103+693d8f0b",
37
+ "@sphereon/ssi-sdk.contact-manager": "0.34.1-fix.103+693d8f0b",
38
+ "@sphereon/ssi-sdk.core": "0.34.1-fix.103+693d8f0b",
39
+ "@sphereon/ssi-sdk.credential-store": "0.34.1-fix.103+693d8f0b",
40
+ "@sphereon/ssi-sdk.credential-validation": "0.34.1-fix.103+693d8f0b",
41
+ "@sphereon/ssi-sdk.data-store": "0.34.1-fix.103+693d8f0b",
42
+ "@sphereon/ssi-sdk.issuance-branding": "0.34.1-fix.103+693d8f0b",
43
+ "@sphereon/ssi-sdk.pd-manager": "0.34.1-fix.103+693d8f0b",
44
+ "@sphereon/ssi-sdk.presentation-exchange": "0.34.1-fix.103+693d8f0b",
45
+ "@sphereon/ssi-sdk.sd-jwt": "0.34.1-fix.103+693d8f0b",
46
+ "@sphereon/ssi-sdk.siopv2-oid4vp-common": "0.34.1-fix.103+693d8f0b",
47
+ "@sphereon/ssi-sdk.xstate-machine-persistence": "0.34.1-fix.103+693d8f0b",
48
+ "@sphereon/ssi-types": "0.34.1-fix.103+693d8f0b",
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
- "cross-fetch": "^3.1.8",
53
- "dcql": "0.2.19",
52
+ "cross-fetch": "^4.1.0",
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.merge.crypto.extensions.modules.37+86254fab",
63
- "@sphereon/ssi-sdk.agent-config": "0.34.1-feature.merge.crypto.extensions.modules.37+86254fab",
62
+ "@sphereon/ssi-sdk-ext.did-resolver-jwk": "0.34.1-fix.103+693d8f0b",
63
+ "@sphereon/ssi-sdk.agent-config": "0.34.1-fix.103+693d8f0b",
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": "86254fab96a7ca6c162ee7ced2657fa58f385efb"
105
+ "gitHead": "693d8f0b0c6566650a31647fda630a0715f960c7"
106
106
  }
@@ -1,23 +1,20 @@
1
- import { decodeUriAsJson, PresentationSignCallback, SupportedVersion, VerifiedAuthorizationRequest } from '@sphereon/did-auth-siop'
1
+ import {
2
+ decodeUriAsJson,
3
+ PresentationSignCallback,
4
+ VerifiedAuthorizationRequest } from '@sphereon/did-auth-siop'
2
5
  import {
3
6
  ConnectionType,
4
7
  CorrelationIdentifierType,
5
- CredentialDocumentFormat,
6
8
  CredentialRole,
7
- DocumentType,
8
9
  Identity,
9
10
  IdentityOrigin,
10
11
  NonPersistedIdentity,
11
12
  Party,
12
13
  } from '@sphereon/ssi-sdk.data-store'
13
- import { HasherSync, Loggers, SdJwtDecodedVerifiableCredential } from '@sphereon/ssi-types'
14
+ import { HasherSync, Loggers } from '@sphereon/ssi-types'
14
15
  import { IAgentPlugin } from '@veramo/core'
15
16
  import { v4 as uuidv4 } from 'uuid'
16
-
17
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'
21
18
  import { EventEmitter } from 'events'
22
19
  import {
23
20
  DidAuthSiopOpAuthenticatorOptions,
@@ -29,14 +26,11 @@ import {
29
26
  IRemoveCustomApprovalForSiopArgs,
30
27
  IRemoveSiopSessionArgs,
31
28
  IRequiredContext,
32
- Json,
33
29
  LOGGER_NAMESPACE,
34
30
  RequiredContext,
35
31
  SelectableCredentialsMap,
36
32
  Siopv2AuthorizationResponseData,
37
- VerifiableCredentialsWithDefinition,
38
33
  } from '../types'
39
-
40
34
  import {
41
35
  AddIdentityArgs,
42
36
  CreateConfigArgs,
@@ -51,7 +45,6 @@ import {
51
45
  Siopv2Machine as Siopv2MachineId,
52
46
  Siopv2MachineInstanceOpts,
53
47
  } from '../types'
54
- import { DcqlCredential, DcqlPresentation, DcqlQuery, DcqlSdJwtVcCredential } from 'dcql'
55
48
  import { Siopv2Machine } from '../machine/Siopv2Machine'
56
49
  import { getSelectableCredentials, siopSendAuthorizationResponse, translateCorrelationIdToName } from '../services/Siopv2MachineService'
57
50
  import { schema } from '..'
@@ -99,12 +92,18 @@ export class DidAuthSiopOpAuthenticator implements IAgentPlugin {
99
92
  private readonly hasher?: HasherSync
100
93
 
101
94
  constructor(options?: DidAuthSiopOpAuthenticatorOptions) {
102
- const { onContactIdentityCreated, onIdentifierCreated, hasher, customApprovals = {}, presentationSignCallback } = { ...options }
95
+ const {
96
+ onContactIdentityCreated,
97
+ onIdentifierCreated,
98
+ hasher,
99
+ customApprovals = {},
100
+ presentationSignCallback
101
+ } = { ...options }
103
102
 
104
103
  this.hasher = hasher
105
104
  this.onContactIdentityCreated = onContactIdentityCreated
106
105
  this.onIdentifierCreated = onIdentifierCreated
107
- this.presentationSignCallback = presentationSignCallback
106
+ this.presentationSignCallback = presentationSignCallback // TODO do we still need this?
108
107
  this.sessions = new Map<string, OpSession>()
109
108
  this.customApprovals = customApprovals
110
109
  }
@@ -234,7 +233,7 @@ export class DidAuthSiopOpAuthenticator implements IAgentPlugin {
234
233
  : (verifiedAuthorizationRequest.issuer ?? verifiedAuthorizationRequest.registrationMetadataPayload?.client_id))
235
234
  const uri: URL | undefined = url.includes('://') ? new URL(url) : undefined
236
235
  const correlationId: string = uri?.hostname ?? (await this.determineCorrelationId(uri, verifiedAuthorizationRequest, clientName, context))
237
- const clientId: string | undefined = await verifiedAuthorizationRequest.authorizationRequest.getMergedProperty<string>('client_id')
236
+ const clientId: string | undefined = verifiedAuthorizationRequest.authorizationRequest.getMergedProperty<string>('client_id')
238
237
 
239
238
  return {
240
239
  issuer: verifiedAuthorizationRequest.issuer,
@@ -243,13 +242,6 @@ export class DidAuthSiopOpAuthenticator implements IAgentPlugin {
243
242
  uri,
244
243
  name: clientName,
245
244
  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
245
  dcqlQuery: verifiedAuthorizationRequest.dcqlQuery,
254
246
  }
255
247
  }
@@ -349,87 +341,14 @@ export class DidAuthSiopOpAuthenticator implements IAgentPlugin {
349
341
  return Promise.reject(Error('Missing authorization request data in context'))
350
342
  }
351
343
 
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
-
425
344
  const response = await siopSendAuthorizationResponse(
426
345
  ConnectionType.SIOPv2_OpenID4VP,
427
346
  {
428
347
  sessionId: didAuthConfig.sessionId,
429
348
  ...(args.idOpts && { idOpts: args.idOpts }),
430
- ...(authorizationRequestData.presentationDefinitions !== undefined && { verifiableCredentialsWithDefinition }),
431
349
  isFirstParty,
432
350
  hasher: this.hasher,
351
+ credentials: selectedCredentials,
433
352
  },
434
353
  context,
435
354
  )
@@ -449,50 +368,13 @@ export class DidAuthSiopOpAuthenticator implements IAgentPlugin {
449
368
  }
450
369
  }
451
370
 
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
371
  private async siopGetSelectableCredentials(args: GetSelectableCredentialsArgs, context: RequiredContext): Promise<SelectableCredentialsMap> {
483
372
  const { authorizationRequestData } = args
484
373
 
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'))
374
+ if (!authorizationRequestData?.dcqlQuery) {
375
+ return Promise.reject(Error('Missing required dcql query in context'))
494
376
  }
495
377
 
496
- return getSelectableCredentials(authorizationRequestData.presentationDefinitions[0].definition, context)
378
+ return getSelectableCredentials(authorizationRequestData?.dcqlQuery, context)
497
379
  }
498
380
  }
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 => {