@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth 0.34.1-fix.171 → 0.34.1-fix.182

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.
@@ -5,11 +5,11 @@ import {
5
5
  AuthorizationResponseStateStatus,
6
6
  AuthorizationResponseStateWithVerifiedData,
7
7
  decodeUriAsJson,
8
- EncodedDcqlPresentationVpToken,
9
- VerifiedAuthorizationResponse
8
+ VerifiedAuthorizationResponse,
10
9
  } from '@sphereon/did-auth-siop'
11
10
  import { getAgentResolver } from '@sphereon/ssi-sdk-ext.did-utils'
12
11
  import { shaHasher as defaultHasher } from '@sphereon/ssi-sdk.core'
12
+ import type { ImportDcqlQueryItem } from '@sphereon/ssi-sdk.pd-manager'
13
13
  import {
14
14
  AdditionalClaims,
15
15
  CredentialMapper,
@@ -22,10 +22,10 @@ import {
22
22
  MdocDeviceResponse,
23
23
  MdocOid4vpMdocVpToken,
24
24
  OriginalVerifiablePresentation,
25
- SdJwtDecodedVerifiableCredential
25
+ SdJwtDecodedVerifiableCredential,
26
26
  } from '@sphereon/ssi-types'
27
27
  import { IAgentPlugin } from '@veramo/core'
28
- import { DcqlPresentation, DcqlQuery } from 'dcql'
28
+ import { DcqlQuery } from 'dcql'
29
29
  import {
30
30
  IAuthorizationRequestPayloads,
31
31
  ICreateAuthRequestArgs,
@@ -41,7 +41,8 @@ import {
41
41
  ISiopv2RPOpts,
42
42
  IUpdateRequestStateArgs,
43
43
  IVerifyAuthResponseStateArgs,
44
- schema
44
+ schema,
45
+ VerifiedDataMode,
45
46
  } from '../index'
46
47
  import { RPInstance } from '../RPInstance'
47
48
  import { ISIOPv2RP } from '../types/ISIOPv2RP'
@@ -84,7 +85,10 @@ export class SIOPv2RP implements IAgentPlugin {
84
85
  }
85
86
 
86
87
  private async createAuthorizationRequestURI(createArgs: ICreateAuthRequestArgs, context: IRequiredContext): Promise<string> {
87
- return await this.getRPInstance({ responseRedirectURI: createArgs.responseRedirectURI, ...(createArgs.useQueryIdInstance === true && { queryId: createArgs.queryId } ) }, context)
88
+ return await this.getRPInstance(
89
+ { responseRedirectURI: createArgs.responseRedirectURI, ...(createArgs.useQueryIdInstance === true && { queryId: createArgs.queryId }) },
90
+ context,
91
+ )
88
92
  .then((rp) => rp.createAuthorizationRequestURI(createArgs, context))
89
93
  .then((URI) => URI.encodedUri)
90
94
  }
@@ -107,9 +111,7 @@ export class SIOPv2RP implements IAgentPlugin {
107
111
 
108
112
  private async siopGetRequestState(args: IGetAuthRequestStateArgs, context: IRequiredContext): Promise<AuthorizationRequestState | undefined> {
109
113
  return await this.getRPInstance({ queryId: args.queryId }, context).then((rp) =>
110
- rp.get(context).then((rp) =>
111
- rp.sessionManager.getRequestStateByCorrelationId(args.correlationId, args.errorOnNotFound)
112
- ),
114
+ rp.get(context).then((rp) => rp.sessionManager.getRequestStateByCorrelationId(args.correlationId, args.errorOnNotFound)),
113
115
  )
114
116
  }
115
117
 
@@ -126,7 +128,11 @@ export class SIOPv2RP implements IAgentPlugin {
126
128
  }
127
129
 
128
130
  const responseState = authorizationResponseState as AuthorizationResponseStateWithVerifiedData
129
- if (responseState.status === AuthorizationResponseStateStatus.VERIFIED) {
131
+ if (
132
+ responseState.status === AuthorizationResponseStateStatus.VERIFIED &&
133
+ args.includeVerifiedData &&
134
+ args.includeVerifiedData !== VerifiedDataMode.NONE
135
+ ) {
130
136
  let hasher: HasherSync | undefined
131
137
  if (
132
138
  CredentialMapper.isSdJwtEncoded(responseState.response.payload.vp_token as OriginalVerifiablePresentation) &&
@@ -134,25 +140,19 @@ export class SIOPv2RP implements IAgentPlugin {
134
140
  ) {
135
141
  hasher = defaultHasher
136
142
  }
137
-
138
-
139
- const vpToken = responseState.response.payload.vp_token && JSON.parse(responseState.response.payload.vp_token as EncodedDcqlPresentationVpToken)
140
- const xx = DcqlPresentation.parse(vpToken)
141
- console.log(`IS DCQL PRESENTATION: ${JSON.stringify(xx)}`)
142
- const claims = []
143
- for (const [key, value] of Object.entries(vpToken)) {
144
- // todo this should also include mdl-mdoc
145
- const presentationDecoded = CredentialMapper.decodeVerifiablePresentation(
146
- value as OriginalVerifiablePresentation,
147
- //todo: later we want to conditionally pass in options for mdl-mdoc here
148
- hasher,
149
- )
150
- console.log(`presentationDecoded: ${JSON.stringify(presentationDecoded)}`)
151
-
152
- const allClaims: AdditionalClaims = {}
153
- const presentationOrClaims = this.presentationOrClaimsFrom(presentationDecoded)
154
- if ('verifiableCredential' in presentationOrClaims) {
155
- for (const credential of presentationOrClaims.verifiableCredential) {
143
+ // todo this should also include mdl-mdoc
144
+ const presentationDecoded = CredentialMapper.decodeVerifiablePresentation(
145
+ responseState.response.payload.vp_token as OriginalVerifiablePresentation,
146
+ //todo: later we want to conditionally pass in options for mdl-mdoc here
147
+ hasher,
148
+ )
149
+ switch (args.includeVerifiedData) {
150
+ case VerifiedDataMode.VERIFIED_PRESENTATION:
151
+ responseState.response.payload.verifiedData = this.presentationOrClaimsFrom(presentationDecoded)
152
+ break
153
+ case VerifiedDataMode.CREDENTIAL_SUBJECT_FLATTENED: // TODO debug cs-flat for SD-JWT
154
+ const allClaims: AdditionalClaims = {}
155
+ for (const credential of this.presentationOrClaimsFrom(presentationDecoded).verifiableCredential || []) {
156
156
  const vc = credential as IVerifiableCredential
157
157
  const schemaValidationResult = await context.agent.cvVerifySchema({
158
158
  credential,
@@ -175,34 +175,11 @@ export class SIOPv2RP implements IAgentPlugin {
175
175
  allClaims[key] = value
176
176
  }
177
177
  })
178
-
179
- claims.push({
180
- id: key,
181
- type: vc.type[0],
182
- claims: allClaims
183
- })
184
178
  }
185
- } else {
186
- claims.push({
187
- id: key,
188
- type: (presentationDecoded as SdJwtDecodedVerifiableCredential).decodedPayload.vct,
189
- claims: presentationOrClaims
190
- })
191
- }
192
- }
193
-
194
- responseState.verifiedData = {
195
- ...(responseState.response.payload.vp_token && {
196
- authorization_response: {
197
- vp_token: typeof responseState.response.payload.vp_token === 'string'
198
- ? JSON.parse(responseState.response.payload.vp_token)
199
- : responseState.response.payload.vp_token
200
- }
201
- }),
202
- ...(claims.length > 0 && { credential_claims: claims })
179
+ responseState.verifiedData = allClaims
180
+ break
203
181
  }
204
182
  }
205
-
206
183
  return responseState
207
184
  }
208
185
 
@@ -212,12 +189,11 @@ export class SIOPv2RP implements IAgentPlugin {
212
189
  | IVerifiablePresentation
213
190
  | SdJwtDecodedVerifiableCredential
214
191
  | MdocOid4vpMdocVpToken
215
- | MdocDeviceResponse
216
- ): AdditionalClaims | IPresentation => {
217
- return CredentialMapper.isSdJwtDecodedCredential(presentationDecoded)
192
+ | MdocDeviceResponse,
193
+ ): AdditionalClaims | IPresentation =>
194
+ CredentialMapper.isSdJwtDecodedCredential(presentationDecoded)
218
195
  ? presentationDecoded.decodedPayload
219
196
  : CredentialMapper.toUniformPresentation(presentationDecoded as OriginalVerifiablePresentation)
220
- }
221
197
 
222
198
  private async siopUpdateRequestState(args: IUpdateRequestStateArgs, context: IRequiredContext): Promise<AuthorizationRequestState> {
223
199
  if (args.state !== 'authorization_request_created') {
@@ -254,7 +230,7 @@ export class SIOPv2RP implements IAgentPlugin {
254
230
  rp.get(context).then((rp) =>
255
231
  rp.verifyAuthorizationResponse(authResponse, {
256
232
  correlationId: args.correlationId,
257
- ...(args.dcqlQueryPayload ? { dcqlQuery: args.dcqlQueryPayload.dcqlQuery } : {}),
233
+ ...(args.dcqlQuery ? { dcqlQuery: args.dcqlQuery } : {}),
258
234
  audience: args.audience,
259
235
  }),
260
236
  ),
@@ -262,33 +238,18 @@ export class SIOPv2RP implements IAgentPlugin {
262
238
  }
263
239
 
264
240
  private async siopImportDefinitions(args: ImportDefinitionsArgs, context: IRequiredContext): Promise<void> {
265
- const { queries, tenantId, version, versionControlMode } = args
241
+ const { importItems, tenantId, version, versionControlMode } = args
266
242
  await Promise.all(
267
- queries.map(async (definitionPair) => {
268
- const definitionPayload = definitionPair.definitionPayload
269
- if (!definitionPayload && !definitionPair.dcqlPayload) {
270
- return Promise.reject(Error('Either dcqlPayload or definitionPayload must be suppplied'))
271
- }
272
-
273
- let definitionId: string
274
- if (definitionPair.dcqlPayload) {
275
- DcqlQuery.validate(definitionPair.dcqlPayload.dcqlQuery)
276
- console.log(`persisting DCQL definition ${definitionPair.dcqlPayload.queryId} with versionControlMode ${versionControlMode}`)
277
- definitionId = definitionPair.dcqlPayload.queryId
278
- }
279
- if (definitionPayload) {
280
- await context.agent.pexValidateDefinition({ definition: definitionPayload })
281
- console.log(`persisting PEX definition ${definitionPayload.id} / ${definitionPayload.name} with versionControlMode ${versionControlMode}`)
282
- definitionId = definitionPayload.id
283
- }
243
+ importItems.map(async (importItem: ImportDcqlQueryItem) => {
244
+ DcqlQuery.validate(importItem.query)
245
+ console.log(`persisting DCQL definition ${importItem.queryId} with versionControlMode ${versionControlMode}`)
284
246
 
285
247
  return context.agent.pdmPersistDefinition({
286
248
  definitionItem: {
287
- definitionId: definitionId!,
249
+ queryId: importItem.queryId!,
288
250
  tenantId: tenantId,
289
251
  version: version,
290
- definitionPayload,
291
- dcqlPayload: definitionPair.dcqlPayload,
252
+ query: importItem.query,
292
253
  },
293
254
  opts: { versionControlMode: versionControlMode },
294
255
  })
package/src/functions.ts CHANGED
@@ -28,12 +28,7 @@ import {
28
28
  } from '@sphereon/ssi-sdk-ext.identifier-resolution'
29
29
  import { JwtCompactResult } from '@sphereon/ssi-sdk-ext.jwt-service'
30
30
  import { IVerifySdJwtPresentationResult } from '@sphereon/ssi-sdk.sd-jwt'
31
- import {
32
- CredentialMapper,
33
- HasherSync,
34
- OriginalVerifiableCredential,
35
- PresentationSubmission
36
- } from '@sphereon/ssi-types'
31
+ import { CredentialMapper, HasherSync, OriginalVerifiableCredential, PresentationSubmission } from '@sphereon/ssi-types'
37
32
  import { IVerifyCallbackArgs, IVerifyCredentialResult, VerifyCallback } from '@sphereon/wellknown-dids-client'
38
33
  import { TKeyType } from '@veramo/core'
39
34
  import { JWTVerifyOptions } from 'did-jwt'
@@ -72,7 +67,7 @@ export function getPresentationVerificationCallback(
72
67
  ): Promise<PresentationVerificationResult> {
73
68
  if (CredentialMapper.isSdJwtEncoded(args)) {
74
69
  const result: IVerifySdJwtPresentationResult = await context.agent.verifySdJwtPresentation({
75
- presentation: args
70
+ presentation: args,
76
71
  })
77
72
  // fixme: investigate the correct way to handle this
78
73
  return { verified: !!result.payload }
@@ -120,7 +115,7 @@ export async function createRPBuilder(args: {
120
115
  const presentationDefinitionItems = await context.agent.pdmGetDefinitions({
121
116
  filter: [
122
117
  {
123
- definitionId: pexOpts.queryId,
118
+ queryId: pexOpts.queryId,
124
119
  version: pexOpts.version,
125
120
  tenantId: pexOpts.tenantId,
126
121
  },
@@ -202,9 +197,11 @@ export async function createRPBuilder(args: {
202
197
  builder.withEntityId(oidfOpts.identifier, PropertyTarget.REQUEST_OBJECT)
203
198
  } else {
204
199
  const resolution = await context.agent.identifierManagedGet(identifierOpts.idOpts)
205
- const clientId: string = rpOpts.clientMetadataOpts?.client_id ?? resolution.issuer ?? (isManagedIdentifierDidResult(resolution) ? resolution.did : resolution.jwkThumbprint)
206
- const clientIdPrefixed = prefixClientId(clientId)
207
- builder.withClientId(clientIdPrefixed, PropertyTarget.REQUEST_OBJECT)
200
+ const clientId: string = rpOpts.clientMetadataOpts?.client_id ??
201
+ resolution.issuer ?? (isManagedIdentifierDidResult(resolution) ? resolution.did : resolution.jwkThumbprint)
202
+ const clientIdPrefixed = prefixClientId(clientId)
203
+ builder.withClientId(clientIdPrefixed, PropertyTarget.REQUEST_OBJECT
204
+ )
208
205
  }
209
206
 
210
207
  if (hasher) {
@@ -24,13 +24,14 @@ import { ExternalIdentifierOIDFEntityIdOpts, IIdentifierResolution, ManagedIdent
24
24
  import { IJwtService } from '@sphereon/ssi-sdk-ext.jwt-service'
25
25
  import { ICredentialValidation, SchemaValidation } from '@sphereon/ssi-sdk.credential-validation'
26
26
  import { ImDLMdoc } from '@sphereon/ssi-sdk.mdl-mdoc'
27
- import { IPDManager, VersionControlMode } from '@sphereon/ssi-sdk.pd-manager'
27
+ import { ImportDcqlQueryItem, IPDManager, VersionControlMode } from '@sphereon/ssi-sdk.pd-manager'
28
28
  import { IPresentationExchange } from '@sphereon/ssi-sdk.presentation-exchange'
29
29
  import { ISDJwtPlugin } from '@sphereon/ssi-sdk.sd-jwt'
30
30
  import { AuthorizationRequestStateStatus } from '@sphereon/ssi-sdk.siopv2-oid4vp-common'
31
- import { DcqlQueryPayload, HasherSync } from '@sphereon/ssi-types'
31
+ import { HasherSync } from '@sphereon/ssi-types'
32
32
  import { VerifyCallback } from '@sphereon/wellknown-dids-client'
33
33
  import { IAgentContext, ICredentialVerifier, IDIDManager, IKeyManager, IPluginMethodMap, IResolver } from '@veramo/core'
34
+ import { DcqlQuery } from 'dcql'
34
35
 
35
36
  import { Resolvable } from 'did-resolver'
36
37
  import { EventEmitter } from 'events'
@@ -89,11 +90,11 @@ export interface IGetAuthResponseStateArgs {
89
90
  queryId?: string
90
91
  errorOnNotFound?: boolean
91
92
  progressRequestStateTo?: AuthorizationRequestStateStatus
92
- //includeVerifiedData?: VerifiedDataMode
93
+ includeVerifiedData?: VerifiedDataMode
93
94
  }
94
95
 
95
96
  export interface IUpdateRequestStateArgs {
96
- queryId?: string
97
+ queryId: string
97
98
  correlationId: string
98
99
  state: AuthorizationRequestStateStatus
99
100
  error?: string
@@ -109,16 +110,10 @@ export interface IVerifyAuthResponseStateArgs {
109
110
  queryId?: string
110
111
  correlationId: string
111
112
  audience?: string
112
- dcqlQueryPayload?: DcqlQueryPayload
113
+ dcqlQuery?: DcqlQuery
113
114
  }
114
-
115
- export interface IDefinitionPair {
116
- definitionPayload?: IPresentationDefinition
117
- dcqlPayload?: DcqlQueryPayload
118
- }
119
-
120
115
  export interface ImportDefinitionsArgs {
121
- queries: Array<IDefinitionPair>
116
+ importItems: Array<ImportDcqlQueryItem>
122
117
  tenantId?: string
123
118
  version?: string
124
119
  versionControlMode?: VersionControlMode