@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth 0.34.1-feature.SSISDK.45.94 → 0.34.1-feature.SSISDK.46.41

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.
@@ -42,7 +42,6 @@ import {
42
42
  VerifiedDataMode,
43
43
  } from '../index'
44
44
  import { RPInstance } from '../RPInstance'
45
-
46
45
  import { ISIOPv2RP } from '../types/ISIOPv2RP'
47
46
  import { shaHasher as defaultHasher } from '@sphereon/ssi-sdk.core'
48
47
  import { DcqlQuery } from 'dcql'
@@ -85,7 +84,7 @@ export class SIOPv2RP implements IAgentPlugin {
85
84
  }
86
85
 
87
86
  private async createAuthorizationRequestURI(createArgs: ICreateAuthRequestArgs, context: IRequiredContext): Promise<string> {
88
- return await this.getRPInstance({ definitionId: createArgs.definitionId, responseRedirectURI: createArgs.responseRedirectURI }, context)
87
+ return await this.getRPInstance({ responseRedirectURI: createArgs.responseRedirectURI, ...(createArgs.useQueryIdInstance === true && { queryId: createArgs.queryId } ) }, context)
89
88
  .then((rp) => rp.createAuthorizationRequestURI(createArgs, context))
90
89
  .then((URI) => URI.encodedUri)
91
90
  }
@@ -94,21 +93,23 @@ export class SIOPv2RP implements IAgentPlugin {
94
93
  createArgs: ICreateAuthRequestArgs,
95
94
  context: IRequiredContext,
96
95
  ): Promise<IAuthorizationRequestPayloads> {
97
- return await this.getRPInstance({ definitionId: createArgs.definitionId }, context)
96
+ return await this.getRPInstance({ queryId: createArgs.queryId }, context)
98
97
  .then((rp) => rp.createAuthorizationRequest(createArgs, context))
99
98
  .then(async (request) => {
100
99
  const authRequest: IAuthorizationRequestPayloads = {
101
100
  authorizationRequest: request.payload,
102
101
  requestObject: await request.requestObjectJwt(),
103
- requestObjectDecoded: await request.requestObject?.getPayload(),
102
+ requestObjectDecoded: request.requestObject?.getPayload(),
104
103
  }
105
104
  return authRequest
106
105
  })
107
106
  }
108
107
 
109
108
  private async siopGetRequestState(args: IGetAuthRequestStateArgs, context: IRequiredContext): Promise<AuthorizationRequestState | undefined> {
110
- return await this.getRPInstance({ definitionId: args.definitionId }, context).then((rp) =>
111
- rp.get(context).then((rp) => rp.sessionManager.getRequestStateByCorrelationId(args.correlationId, args.errorOnNotFound)),
109
+ 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
+ ),
112
113
  )
113
114
  }
114
115
 
@@ -116,7 +117,7 @@ export class SIOPv2RP implements IAgentPlugin {
116
117
  args: IGetAuthResponseStateArgs,
117
118
  context: IRequiredContext,
118
119
  ): Promise<AuthorizationResponseStateWithVerifiedData | undefined> {
119
- const rpInstance: RPInstance = await this.getRPInstance({ definitionId: args.definitionId }, context)
120
+ const rpInstance: RPInstance = await this.getRPInstance({ queryId: args.queryId }, context)
120
121
  const authorizationResponseState: AuthorizationResponseState | undefined = await rpInstance
121
122
  .get(context)
122
123
  .then((rp) => rp.sessionManager.getResponseStateByCorrelationId(args.correlationId, args.errorOnNotFound))
@@ -193,10 +194,10 @@ export class SIOPv2RP implements IAgentPlugin {
193
194
  : CredentialMapper.toUniformPresentation(presentationDecoded as OriginalVerifiablePresentation)
194
195
 
195
196
  private async siopUpdateRequestState(args: IUpdateRequestStateArgs, context: IRequiredContext): Promise<AuthorizationRequestState> {
196
- if (args.state !== 'sent') {
197
- throw Error(`Only 'sent' status is supported for this method at this point`)
197
+ if (args.state !== 'authorization_request_created') {
198
+ throw Error(`Only 'authorization_request_created' status is supported for this method at this point`)
198
199
  }
199
- return await this.getRPInstance({ definitionId: args.definitionId }, context)
200
+ return await this.getRPInstance({ queryId: args.queryId }, context)
200
201
  // todo: In the SIOP library we need to update the signal method to be more like this method
201
202
  .then((rp) =>
202
203
  rp.get(context).then(async (rp) => {
@@ -210,7 +211,7 @@ export class SIOPv2RP implements IAgentPlugin {
210
211
  }
211
212
 
212
213
  private async siopDeleteState(args: IGetAuthResponseStateArgs, context: IRequiredContext): Promise<boolean> {
213
- return await this.getRPInstance({ definitionId: args.definitionId }, context)
214
+ return await this.getRPInstance({ queryId: args.queryId }, context)
214
215
  .then((rp) => rp.get(context).then((rp) => rp.sessionManager.deleteStateForCorrelationId(args.correlationId)))
215
216
  .then(() => true)
216
217
  }
@@ -223,10 +224,11 @@ export class SIOPv2RP implements IAgentPlugin {
223
224
  typeof args.authorizationResponse === 'string'
224
225
  ? (decodeUriAsJson(args.authorizationResponse) as AuthorizationResponsePayload)
225
226
  : args.authorizationResponse
226
- return await this.getRPInstance({ definitionId: args.definitionId }, context).then((rp) =>
227
+ return await this.getRPInstance({ queryId: args.queryId }, context).then((rp) =>
227
228
  rp.get(context).then((rp) =>
228
229
  rp.verifyAuthorizationResponse(authResponse, {
229
230
  correlationId: args.correlationId,
231
+ ...(args.presentationDefinitions && !args.dcqlQuery ? { presentationDefinitions: args.presentationDefinitions } : {}),
230
232
  ...(args.dcqlQuery ? { dcqlQuery: args.dcqlQuery as DcqlQuery } : {}), // TODO BEFORE PR, check compatibility and whether we can remove local type
231
233
  audience: args.audience,
232
234
  }),
@@ -235,9 +237,9 @@ export class SIOPv2RP implements IAgentPlugin {
235
237
  }
236
238
 
237
239
  private async siopImportDefinitions(args: ImportDefinitionsArgs, context: IRequiredContext): Promise<void> {
238
- const { definitions, tenantId, version, versionControlMode } = args
240
+ const { queries, tenantId, version, versionControlMode } = args
239
241
  await Promise.all(
240
- definitions.map(async (definitionPair) => {
242
+ queries.map(async (definitionPair) => {
241
243
  const definitionPayload = definitionPair.definitionPayload
242
244
  await context.agent.pexValidateDefinition({ definition: definitionPayload })
243
245
 
@@ -256,7 +258,7 @@ export class SIOPv2RP implements IAgentPlugin {
256
258
  }
257
259
 
258
260
  private async siopGetRedirectURI(args: IGetRedirectUriArgs, context: IRequiredContext): Promise<string | undefined> {
259
- const instanceId = args.definitionId ?? SIOPv2RP._DEFAULT_OPTS_KEY
261
+ const instanceId = args.queryId ?? SIOPv2RP._DEFAULT_OPTS_KEY
260
262
  if (this.instances.has(instanceId)) {
261
263
  const rpInstance = this.instances.get(instanceId)
262
264
  if (rpInstance !== undefined) {
@@ -271,17 +273,17 @@ export class SIOPv2RP implements IAgentPlugin {
271
273
  return undefined
272
274
  }
273
275
 
274
- async getRPInstance({ definitionId, responseRedirectURI }: ISiopRPInstanceArgs, context: IRequiredContext): Promise<RPInstance> {
275
- const instanceId = definitionId ?? SIOPv2RP._DEFAULT_OPTS_KEY
276
+ async getRPInstance({ queryId, responseRedirectURI }: ISiopRPInstanceArgs, context: IRequiredContext): Promise<RPInstance> {
277
+ const instanceId = queryId ?? SIOPv2RP._DEFAULT_OPTS_KEY
276
278
  if (!this.instances.has(instanceId)) {
277
- const instanceOpts = this.getInstanceOpts(definitionId)
278
- const rpOpts = await this.getRPOptions(context, { definitionId, responseRedirectURI: responseRedirectURI })
279
+ const instanceOpts = this.getInstanceOpts(queryId)
280
+ const rpOpts = await this.getRPOptions(context, { queryId, responseRedirectURI: responseRedirectURI })
279
281
  if (!rpOpts.identifierOpts.resolveOpts?.resolver || typeof rpOpts.identifierOpts.resolveOpts.resolver.resolve !== 'function') {
280
282
  if (!rpOpts.identifierOpts?.resolveOpts) {
281
283
  rpOpts.identifierOpts = { ...rpOpts.identifierOpts }
282
284
  rpOpts.identifierOpts.resolveOpts = { ...rpOpts.identifierOpts.resolveOpts }
283
285
  }
284
- console.log('Using agent DID resolver for RP instance with definition id ' + definitionId)
286
+ console.log('Using agent DID resolver for RP instance with definition id ' + queryId)
285
287
  rpOpts.identifierOpts.resolveOpts.resolver = getAgentResolver(context, {
286
288
  uniresolverResolution: true,
287
289
  localResolution: true,
@@ -297,11 +299,11 @@ export class SIOPv2RP implements IAgentPlugin {
297
299
  return rpInstance
298
300
  }
299
301
 
300
- async getRPOptions(context: IRequiredContext, opts: { definitionId?: string; responseRedirectURI?: string }): Promise<IRPOptions> {
301
- const { definitionId, responseRedirectURI: responseRedirectURI } = opts
302
- const options = this.getInstanceOpts(definitionId)?.rpOpts ?? this.opts.defaultOpts
302
+ async getRPOptions(context: IRequiredContext, opts: { queryId?: string; responseRedirectURI?: string }): Promise<IRPOptions> {
303
+ const { queryId, responseRedirectURI: responseRedirectURI } = opts
304
+ const options = this.getInstanceOpts(queryId)?.rpOpts ?? this.opts.defaultOpts
303
305
  if (!options) {
304
- throw Error(`Could not get specific nor default options for definition ${definitionId}`)
306
+ throw Error(`Could not get specific nor default options for definition ${queryId}`)
305
307
  }
306
308
  if (this.opts.defaultOpts) {
307
309
  if (!options.identifierOpts) {
@@ -335,7 +337,7 @@ export class SIOPv2RP implements IAgentPlugin {
335
337
  getInstanceOpts(definitionId?: string): IPEXInstanceOptions | undefined {
336
338
  if (!this.opts.instanceOpts) return undefined
337
339
 
338
- const instanceOpt = definitionId ? this.opts.instanceOpts.find((i) => i.definitionId === definitionId) : undefined
340
+ const instanceOpt = definitionId ? this.opts.instanceOpts.find((i) => i.queryId === definitionId) : undefined
339
341
 
340
342
  return instanceOpt ?? this.getDefaultOptions(definitionId)
341
343
  }
@@ -343,11 +345,11 @@ export class SIOPv2RP implements IAgentPlugin {
343
345
  private getDefaultOptions(definitionId: string | undefined) {
344
346
  if (!this.opts.instanceOpts) return undefined
345
347
 
346
- const defaultOptions = this.opts.instanceOpts.find((i) => i.definitionId === 'default')
348
+ const defaultOptions = this.opts.instanceOpts.find((i) => i.queryId === 'default')
347
349
  if (defaultOptions) {
348
350
  const clonedOptions = { ...defaultOptions }
349
351
  if (definitionId !== undefined) {
350
- clonedOptions.definitionId = definitionId
352
+ clonedOptions.queryId = definitionId
351
353
  }
352
354
  return clonedOptions
353
355
  }
package/src/functions.ts CHANGED
@@ -113,11 +113,11 @@ export async function createRPBuilder(args: {
113
113
  let definition: IPresentationDefinition | undefined = args.definition
114
114
  let dcqlQuery: DcqlQuery | undefined = args.dcql
115
115
 
116
- if (!definition && pexOpts && pexOpts.definitionId) {
116
+ if (!definition && pexOpts && pexOpts.queryId) {
117
117
  const presentationDefinitionItems = await context.agent.pdmGetDefinitions({
118
118
  filter: [
119
119
  {
120
- definitionId: pexOpts.definitionId,
120
+ definitionId: pexOpts.queryId,
121
121
  version: pexOpts.version,
122
122
  tenantId: pexOpts.tenantId,
123
123
  },
@@ -6,33 +6,35 @@ import {
6
6
  ClaimPayloadCommonOpts,
7
7
  ClientMetadataOpts,
8
8
  IRPSessionManager,
9
+ PresentationDefinitionWithLocation,
9
10
  PresentationVerificationCallback,
10
11
  RequestObjectPayload,
11
12
  ResponseMode,
12
13
  ResponseURIType,
13
14
  SupportedVersion,
15
+ VerifiablePresentationTypeFormat,
14
16
  VerifiedAuthorizationResponse,
15
17
  VerifyJwtCallback,
18
+ VPTokenLocation,
16
19
  } from '@sphereon/did-auth-siop'
17
- import { CheckLinkedDomain } from '@sphereon/did-auth-siop-adapter'
20
+ import { ExternalIdentifierOIDFEntityIdOpts, IIdentifierResolution, ManagedIdentifierOptsOrResult } from '@sphereon/ssi-sdk-ext.identifier-resolution'
21
+ import { IAgentContext, ICredentialIssuer, ICredentialVerifier, IDIDManager, IKeyManager, IPluginMethodMap, IResolver } from '@veramo/core'
22
+ import { AdditionalClaims, DcqlQueryREST, HasherSync, W3CVerifiablePresentation } from '@sphereon/ssi-types'
23
+ import { Resolvable } from 'did-resolver'
18
24
  import { DIDDocument } from '@sphereon/did-uni-client'
19
- import { JwtIssuer } from '@sphereon/oid4vc-common'
25
+ import { EventEmitter } from 'events'
20
26
  import { IPresentationDefinition } from '@sphereon/pex'
21
27
  import { IDIDOptions } from '@sphereon/ssi-sdk-ext.did-utils'
22
- import { ExternalIdentifierOIDFEntityIdOpts, IIdentifierResolution, ManagedIdentifierOptsOrResult } from '@sphereon/ssi-sdk-ext.identifier-resolution'
23
- import { IJwtService } from '@sphereon/ssi-sdk-ext.jwt-service'
24
- import { ICredentialValidation, SchemaValidation } from '@sphereon/ssi-sdk.credential-validation'
25
- import { ImDLMdoc } from '@sphereon/ssi-sdk.mdl-mdoc'
26
- import { IPDManager, VersionControlMode } from '@sphereon/ssi-sdk.pd-manager'
27
28
  import { IPresentationExchange } from '@sphereon/ssi-sdk.presentation-exchange'
28
- import { ISDJwtPlugin } from '@sphereon/ssi-sdk.sd-jwt'
29
- import { AuthorizationRequestStateStatus } from '@sphereon/ssi-sdk.siopv2-oid4vp-common'
30
- import { AdditionalClaims, DcqlQueryREST, HasherSync } from '@sphereon/ssi-types'
31
29
  import { VerifyCallback } from '@sphereon/wellknown-dids-client'
32
- import { IAgentContext, ICredentialIssuer, ICredentialVerifier, IDIDManager, IKeyManager, IPluginMethodMap, IResolver } from '@veramo/core'
33
-
34
- import { Resolvable } from 'did-resolver'
35
- import { EventEmitter } from 'events'
30
+ import { AuthorizationRequestStateStatus } from '@sphereon/ssi-sdk.siopv2-oid4vp-common'
31
+ import { IPDManager, VersionControlMode } from '@sphereon/ssi-sdk.pd-manager'
32
+ import { CheckLinkedDomain } from '@sphereon/did-auth-siop-adapter'
33
+ import { ISDJwtPlugin } from '@sphereon/ssi-sdk.sd-jwt'
34
+ import { IJwtService } from '@sphereon/ssi-sdk-ext.jwt-service'
35
+ import { JwtIssuer } from '@sphereon/oid4vc-common'
36
+ import { ImDLMdoc } from '@sphereon/ssi-sdk.mdl-mdoc'
37
+ import { ICredentialValidation, SchemaValidation } from '@sphereon/ssi-sdk.credential-validation'
36
38
 
37
39
  export enum VerifiedDataMode {
38
40
  NONE = 'none',
@@ -64,8 +66,9 @@ export interface ISiopv2RPOpts {
64
66
  export interface IRPDefaultOpts extends IRPOptions {}
65
67
 
66
68
  export interface ICreateAuthRequestArgs {
67
- definitionId: string
69
+ queryId: string //definitionId
68
70
  correlationId: string
71
+ useQueryIdInstance?: boolean
69
72
  responseURIType: ResponseURIType
70
73
  responseURI: string
71
74
  responseRedirectURI?: string
@@ -74,24 +77,25 @@ export interface ICreateAuthRequestArgs {
74
77
  nonce?: string
75
78
  state?: string
76
79
  claims?: ClaimPayloadCommonOpts
80
+
77
81
  }
78
82
 
79
83
  export interface IGetAuthRequestStateArgs {
80
84
  correlationId: string
81
- definitionId: string
85
+ queryId?: string
82
86
  errorOnNotFound?: boolean
83
87
  }
84
88
 
85
89
  export interface IGetAuthResponseStateArgs {
86
90
  correlationId: string
87
- definitionId: string
91
+ queryId?: string
88
92
  errorOnNotFound?: boolean
89
93
  progressRequestStateTo?: AuthorizationRequestStateStatus
90
94
  includeVerifiedData?: VerifiedDataMode
91
95
  }
92
96
 
93
97
  export interface IUpdateRequestStateArgs {
94
- definitionId: string
98
+ queryId: string
95
99
  correlationId: string
96
100
  state: AuthorizationRequestStateStatus
97
101
  error?: string
@@ -99,14 +103,15 @@ export interface IUpdateRequestStateArgs {
99
103
 
100
104
  export interface IDeleteAuthStateArgs {
101
105
  correlationId: string
102
- definitionId: string
106
+ queryId?: string
103
107
  }
104
108
 
105
109
  export interface IVerifyAuthResponseStateArgs {
106
110
  authorizationResponse: string | AuthorizationResponsePayload
107
- definitionId?: string
111
+ queryId?: string
108
112
  correlationId: string
109
113
  audience?: string
114
+ presentationDefinitions?: PresentationDefinitionWithLocation | PresentationDefinitionWithLocation[]
110
115
  dcqlQuery?: DcqlQueryREST
111
116
  }
112
117
 
@@ -116,7 +121,7 @@ export interface IDefinitionPair {
116
121
  }
117
122
 
118
123
  export interface ImportDefinitionsArgs {
119
- definitions: Array<IDefinitionPair>
124
+ queries: Array<IDefinitionPair>
120
125
  tenantId?: string
121
126
  version?: string
122
127
  versionControlMode?: VersionControlMode
@@ -124,7 +129,7 @@ export interface ImportDefinitionsArgs {
124
129
 
125
130
  export interface IGetRedirectUriArgs {
126
131
  correlationId: string
127
- definitionId?: string
132
+ queryId?: string
128
133
  state?: string
129
134
  }
130
135
 
@@ -140,7 +145,7 @@ export interface IPEXDefinitionPersistArgs extends IPEXInstanceOptions {
140
145
  }
141
146
 
142
147
  export interface ISiopRPInstanceArgs {
143
- definitionId?: string
148
+ queryId?: string
144
149
  responseRedirectURI?: string
145
150
  }
146
151
 
@@ -165,7 +170,7 @@ export interface IRPOptions {
165
170
  export interface IPEXOptions {
166
171
  presentationVerifyCallback?: PresentationVerificationCallback
167
172
  // definition?: IPresentationDefinition
168
- definitionId: string
173
+ queryId: string
169
174
  version?: string
170
175
  tenantId?: string
171
176
  }
@@ -182,9 +187,17 @@ export interface PerDidResolver {
182
187
  export interface IAuthRequestDetails {
183
188
  rpDIDDocument?: DIDDocument
184
189
  id: string
190
+ verifiablePresentationMatches: IPresentationWithDefinition[]
185
191
  alsoKnownAs?: string[]
186
192
  }
187
193
 
194
+ export interface IPresentationWithDefinition {
195
+ location: VPTokenLocation
196
+ definition: PresentationDefinitionWithLocation
197
+ format: VerifiablePresentationTypeFormat
198
+ presentation: W3CVerifiablePresentation
199
+ }
200
+
188
201
  export interface ISIOPIdentifierOptions extends Omit<IDIDOptions, 'idOpts'> {
189
202
  // we replace the legacy idOpts with the Managed Identifier opts from the identifier resolution module
190
203
  idOpts: ManagedIdentifierOptsOrResult