@sphereon/ssi-sdk.siopv2-oid4vp-op-auth 0.34.1-next.29 → 0.34.1-next.299

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-next.29+2593a430",
3
+ "version": "0.34.1-next.299+9e9f5a50",
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-next.220",
30
+ "@sphereon/did-auth-siop-adapter": "0.19.1-next.220",
31
+ "@sphereon/oid4vc-common": "0.19.1-next.220",
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.29.1-next.3",
35
- "@sphereon/ssi-sdk-ext.identifier-resolution": "0.29.1-next.3",
36
- "@sphereon/ssi-sdk-ext.jwt-service": "0.29.1-next.3",
37
- "@sphereon/ssi-sdk.contact-manager": "0.34.1-next.29+2593a430",
38
- "@sphereon/ssi-sdk.core": "0.34.1-next.29+2593a430",
39
- "@sphereon/ssi-sdk.credential-store": "0.34.1-next.29+2593a430",
40
- "@sphereon/ssi-sdk.credential-validation": "0.34.1-next.29+2593a430",
41
- "@sphereon/ssi-sdk.data-store": "0.34.1-next.29+2593a430",
42
- "@sphereon/ssi-sdk.issuance-branding": "0.34.1-next.29+2593a430",
43
- "@sphereon/ssi-sdk.pd-manager": "0.34.1-next.29+2593a430",
44
- "@sphereon/ssi-sdk.presentation-exchange": "0.34.1-next.29+2593a430",
45
- "@sphereon/ssi-sdk.sd-jwt": "0.34.1-next.29+2593a430",
46
- "@sphereon/ssi-sdk.siopv2-oid4vp-common": "0.34.1-next.29+2593a430",
47
- "@sphereon/ssi-sdk.xstate-machine-persistence": "0.34.1-next.29+2593a430",
48
- "@sphereon/ssi-types": "0.34.1-next.29+2593a430",
34
+ "@sphereon/ssi-sdk-ext.did-utils": "0.34.1-next.299+9e9f5a50",
35
+ "@sphereon/ssi-sdk-ext.identifier-resolution": "0.34.1-next.299+9e9f5a50",
36
+ "@sphereon/ssi-sdk-ext.jwt-service": "0.34.1-next.299+9e9f5a50",
37
+ "@sphereon/ssi-sdk.contact-manager": "0.34.1-next.299+9e9f5a50",
38
+ "@sphereon/ssi-sdk.core": "0.34.1-next.299+9e9f5a50",
39
+ "@sphereon/ssi-sdk.credential-store": "0.34.1-next.299+9e9f5a50",
40
+ "@sphereon/ssi-sdk.credential-validation": "0.34.1-next.299+9e9f5a50",
41
+ "@sphereon/ssi-sdk.data-store-types": "0.34.1-next.299+9e9f5a50",
42
+ "@sphereon/ssi-sdk.issuance-branding": "0.34.1-next.299+9e9f5a50",
43
+ "@sphereon/ssi-sdk.pd-manager": "0.34.1-next.299+9e9f5a50",
44
+ "@sphereon/ssi-sdk.presentation-exchange": "0.34.1-next.299+9e9f5a50",
45
+ "@sphereon/ssi-sdk.sd-jwt": "0.34.1-next.299+9e9f5a50",
46
+ "@sphereon/ssi-sdk.siopv2-oid4vp-common": "0.34.1-next.299+9e9f5a50",
47
+ "@sphereon/ssi-sdk.xstate-machine-persistence": "0.34.1-next.299+9e9f5a50",
48
+ "@sphereon/ssi-types": "0.34.1-next.299+9e9f5a50",
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.29.1-next.3",
63
- "@sphereon/ssi-sdk.agent-config": "0.34.1-next.29+2593a430",
62
+ "@sphereon/ssi-sdk-ext.did-resolver-jwk": "0.34.1-next.299+9e9f5a50",
63
+ "@sphereon/ssi-sdk.agent-config": "0.34.1-next.299+9e9f5a50",
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": "2593a430ac4faca47b620a3e12b297899518f2af"
105
+ "gitHead": "9e9f5a50ead9373a078cb5291cbc4fb1e7865dc2"
106
106
  }
@@ -1,23 +1,9 @@
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'
1
+ import { decodeUriAsJson, PresentationSignCallback, VerifiedAuthorizationRequest } from '@sphereon/did-auth-siop'
2
+ import { ConnectionType, CorrelationIdentifierType, Identity, IdentityOrigin, NonPersistedIdentity, Party } from '@sphereon/ssi-sdk.data-store-types'
3
+ import { HasherSync, Loggers, CredentialRole } from '@sphereon/ssi-types'
14
4
  import { IAgentPlugin } from '@veramo/core'
15
5
  import { v4 as uuidv4 } from 'uuid'
16
-
17
6
  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
7
  import { EventEmitter } from 'events'
22
8
  import {
23
9
  DidAuthSiopOpAuthenticatorOptions,
@@ -29,14 +15,11 @@ import {
29
15
  IRemoveCustomApprovalForSiopArgs,
30
16
  IRemoveSiopSessionArgs,
31
17
  IRequiredContext,
32
- Json,
33
18
  LOGGER_NAMESPACE,
34
19
  RequiredContext,
35
20
  SelectableCredentialsMap,
36
21
  Siopv2AuthorizationResponseData,
37
- VerifiableCredentialsWithDefinition,
38
22
  } from '../types'
39
-
40
23
  import {
41
24
  AddIdentityArgs,
42
25
  CreateConfigArgs,
@@ -51,7 +34,6 @@ import {
51
34
  Siopv2Machine as Siopv2MachineId,
52
35
  Siopv2MachineInstanceOpts,
53
36
  } from '../types'
54
- import { DcqlCredential, DcqlPresentation, DcqlQuery, DcqlSdJwtVcCredential } from 'dcql'
55
37
  import { Siopv2Machine } from '../machine/Siopv2Machine'
56
38
  import { getSelectableCredentials, siopSendAuthorizationResponse, translateCorrelationIdToName } from '../services/Siopv2MachineService'
57
39
  import { schema } from '..'
@@ -104,7 +86,7 @@ export class DidAuthSiopOpAuthenticator implements IAgentPlugin {
104
86
  this.hasher = hasher
105
87
  this.onContactIdentityCreated = onContactIdentityCreated
106
88
  this.onIdentifierCreated = onIdentifierCreated
107
- this.presentationSignCallback = presentationSignCallback
89
+ this.presentationSignCallback = presentationSignCallback // TODO do we still need this?
108
90
  this.sessions = new Map<string, OpSession>()
109
91
  this.customApprovals = customApprovals
110
92
  }
@@ -232,9 +214,9 @@ export class DidAuthSiopOpAuthenticator implements IAgentPlugin {
232
214
  (args.url.includes('request_uri')
233
215
  ? decodeURIComponent(args.url.split('?request_uri=')[1].trim())
234
216
  : (verifiedAuthorizationRequest.issuer ?? verifiedAuthorizationRequest.registrationMetadataPayload?.client_id))
235
- const uri: URL | undefined = url.includes('://') ? new URL(url) : undefined
217
+ const uri: URL | undefined = url?.includes('://') ? new URL(url) : undefined
236
218
  const correlationId: string = uri?.hostname ?? (await this.determineCorrelationId(uri, verifiedAuthorizationRequest, clientName, context))
237
- const clientId: string | undefined = await verifiedAuthorizationRequest.authorizationRequest.getMergedProperty<string>('client_id')
219
+ const clientId: string | undefined = verifiedAuthorizationRequest.authorizationRequest.getMergedProperty<string>('client_id')
238
220
 
239
221
  return {
240
222
  issuer: verifiedAuthorizationRequest.issuer,
@@ -243,13 +225,6 @@ export class DidAuthSiopOpAuthenticator implements IAgentPlugin {
243
225
  uri,
244
226
  name: clientName,
245
227
  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
228
  dcqlQuery: verifiedAuthorizationRequest.dcqlQuery,
254
229
  }
255
230
  }
@@ -349,87 +324,14 @@ export class DidAuthSiopOpAuthenticator implements IAgentPlugin {
349
324
  return Promise.reject(Error('Missing authorization request data in context'))
350
325
  }
351
326
 
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
327
  const response = await siopSendAuthorizationResponse(
426
328
  ConnectionType.SIOPv2_OpenID4VP,
427
329
  {
428
330
  sessionId: didAuthConfig.sessionId,
429
331
  ...(args.idOpts && { idOpts: args.idOpts }),
430
- ...(authorizationRequestData.presentationDefinitions !== undefined && { verifiableCredentialsWithDefinition }),
431
332
  isFirstParty,
432
333
  hasher: this.hasher,
334
+ credentials: selectedCredentials,
433
335
  },
434
336
  context,
435
337
  )
@@ -449,50 +351,13 @@ export class DidAuthSiopOpAuthenticator implements IAgentPlugin {
449
351
  }
450
352
  }
451
353
 
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
354
  private async siopGetSelectableCredentials(args: GetSelectableCredentialsArgs, context: RequiredContext): Promise<SelectableCredentialsMap> {
483
355
  const { authorizationRequestData } = args
484
356
 
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'))
357
+ if (!authorizationRequestData?.dcqlQuery) {
358
+ return Promise.reject(Error('Missing required dcql query in context'))
494
359
  }
495
360
 
496
- return getSelectableCredentials(authorizationRequestData.presentationDefinitions[0].definition, context)
361
+ return getSelectableCredentials(authorizationRequestData?.dcqlQuery, context)
497
362
  }
498
363
  }
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'
@@ -1,5 +1,5 @@
1
1
  import { VerifiedAuthorizationRequest } from '@sphereon/did-auth-siop'
2
- import { DidAuthConfig, Identity, Party } from '@sphereon/ssi-sdk.data-store'
2
+ import { DidAuthConfig, Identity, Party } from '@sphereon/ssi-sdk.data-store-types'
3
3
  import { assign, createMachine, DoneInvokeEvent, interpret } from 'xstate'
4
4
  import { translate } from '../localization/Localization'
5
5
  import { ErrorDetails } from '../types'
@@ -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 => {