@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth 0.34.1-fix.148 → 0.34.1-fix.161

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.
@@ -3,8 +3,9 @@ import {
3
3
  AuthorizationResponsePayload,
4
4
  AuthorizationResponseState,
5
5
  AuthorizationResponseStateStatus,
6
+ AuthorizationResponseStateWithVerifiedData,
6
7
  decodeUriAsJson,
7
- VerifiedAuthorizationResponse,
8
+ VerifiedAuthorizationResponse
8
9
  } from '@sphereon/did-auth-siop'
9
10
  import { getAgentResolver } from '@sphereon/ssi-sdk-ext.did-utils'
10
11
  import { shaHasher as defaultHasher } from '@sphereon/ssi-sdk.core'
@@ -25,7 +26,6 @@ import {
25
26
  import { IAgentPlugin } from '@veramo/core'
26
27
  import { DcqlQuery } from 'dcql'
27
28
  import {
28
- AuthorizationResponseStateWithVerifiedData,
29
29
  IAuthorizationRequestPayloads,
30
30
  ICreateAuthRequestArgs,
31
31
  IGetAuthRequestStateArgs,
@@ -84,7 +84,7 @@ export class SIOPv2RP implements IAgentPlugin {
84
84
  }
85
85
 
86
86
  private async createAuthorizationRequestURI(createArgs: ICreateAuthRequestArgs, context: IRequiredContext): Promise<string> {
87
- 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)
88
88
  .then((rp) => rp.createAuthorizationRequestURI(createArgs, context))
89
89
  .then((URI) => URI.encodedUri)
90
90
  }
@@ -93,7 +93,7 @@ export class SIOPv2RP implements IAgentPlugin {
93
93
  createArgs: ICreateAuthRequestArgs,
94
94
  context: IRequiredContext,
95
95
  ): Promise<IAuthorizationRequestPayloads> {
96
- return await this.getRPInstance({ definitionId: createArgs.definitionId }, context)
96
+ return await this.getRPInstance({ queryId: createArgs.queryId }, context)
97
97
  .then((rp) => rp.createAuthorizationRequest(createArgs, context))
98
98
  .then(async (request) => {
99
99
  const authRequest: IAuthorizationRequestPayloads = {
@@ -106,8 +106,10 @@ export class SIOPv2RP implements IAgentPlugin {
106
106
  }
107
107
 
108
108
  private async siopGetRequestState(args: IGetAuthRequestStateArgs, context: IRequiredContext): Promise<AuthorizationRequestState | undefined> {
109
- return await this.getRPInstance({ definitionId: args.definitionId }, context).then((rp) =>
110
- 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
+ ),
111
113
  )
112
114
  }
113
115
 
@@ -115,7 +117,7 @@ export class SIOPv2RP implements IAgentPlugin {
115
117
  args: IGetAuthResponseStateArgs,
116
118
  context: IRequiredContext,
117
119
  ): Promise<AuthorizationResponseStateWithVerifiedData | undefined> {
118
- const rpInstance: RPInstance = await this.getRPInstance({ definitionId: args.definitionId }, context)
120
+ const rpInstance: RPInstance = await this.getRPInstance({ queryId: args.queryId }, context)
119
121
  const authorizationResponseState: AuthorizationResponseState | undefined = await rpInstance
120
122
  .get(context)
121
123
  .then((rp) => rp.sessionManager.getResponseStateByCorrelationId(args.correlationId, args.errorOnNotFound))
@@ -192,10 +194,10 @@ export class SIOPv2RP implements IAgentPlugin {
192
194
  : CredentialMapper.toUniformPresentation(presentationDecoded as OriginalVerifiablePresentation)
193
195
 
194
196
  private async siopUpdateRequestState(args: IUpdateRequestStateArgs, context: IRequiredContext): Promise<AuthorizationRequestState> {
195
- if (args.state !== 'sent') {
196
- 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`)
197
199
  }
198
- return await this.getRPInstance({ definitionId: args.definitionId }, context)
200
+ return await this.getRPInstance({ queryId: args.queryId }, context)
199
201
  // todo: In the SIOP library we need to update the signal method to be more like this method
200
202
  .then((rp) =>
201
203
  rp.get(context).then(async (rp) => {
@@ -209,7 +211,7 @@ export class SIOPv2RP implements IAgentPlugin {
209
211
  }
210
212
 
211
213
  private async siopDeleteState(args: IGetAuthResponseStateArgs, context: IRequiredContext): Promise<boolean> {
212
- return await this.getRPInstance({ definitionId: args.definitionId }, context)
214
+ return await this.getRPInstance({ queryId: args.queryId }, context)
213
215
  .then((rp) => rp.get(context).then((rp) => rp.sessionManager.deleteStateForCorrelationId(args.correlationId)))
214
216
  .then(() => true)
215
217
  }
@@ -222,7 +224,7 @@ export class SIOPv2RP implements IAgentPlugin {
222
224
  typeof args.authorizationResponse === 'string'
223
225
  ? (decodeUriAsJson(args.authorizationResponse) as AuthorizationResponsePayload)
224
226
  : args.authorizationResponse
225
- return await this.getRPInstance({ definitionId: args.definitionId }, context).then((rp) =>
227
+ return await this.getRPInstance({ queryId: args.queryId }, context).then((rp) =>
226
228
  rp.get(context).then((rp) =>
227
229
  rp.verifyAuthorizationResponse(authResponse, {
228
230
  correlationId: args.correlationId,
@@ -234,9 +236,9 @@ export class SIOPv2RP implements IAgentPlugin {
234
236
  }
235
237
 
236
238
  private async siopImportDefinitions(args: ImportDefinitionsArgs, context: IRequiredContext): Promise<void> {
237
- const { definitions, tenantId, version, versionControlMode } = args
239
+ const { queries, tenantId, version, versionControlMode } = args
238
240
  await Promise.all(
239
- definitions.map(async (definitionPair) => {
241
+ queries.map(async (definitionPair) => {
240
242
  const definitionPayload = definitionPair.definitionPayload
241
243
  if (!definitionPayload && !definitionPair.dcqlPayload) {
242
244
  return Promise.reject(Error('Either dcqlPayload or definitionPayload must be suppplied'))
@@ -269,7 +271,7 @@ export class SIOPv2RP implements IAgentPlugin {
269
271
  }
270
272
 
271
273
  private async siopGetRedirectURI(args: IGetRedirectUriArgs, context: IRequiredContext): Promise<string | undefined> {
272
- const instanceId = args.definitionId ?? SIOPv2RP._DEFAULT_OPTS_KEY
274
+ const instanceId = args.queryId ?? SIOPv2RP._DEFAULT_OPTS_KEY
273
275
  if (this.instances.has(instanceId)) {
274
276
  const rpInstance = this.instances.get(instanceId)
275
277
  if (rpInstance !== undefined) {
@@ -284,17 +286,17 @@ export class SIOPv2RP implements IAgentPlugin {
284
286
  return undefined
285
287
  }
286
288
 
287
- async getRPInstance({ definitionId, responseRedirectURI }: ISiopRPInstanceArgs, context: IRequiredContext): Promise<RPInstance> {
288
- const instanceId = definitionId ?? SIOPv2RP._DEFAULT_OPTS_KEY
289
+ async getRPInstance({ queryId, responseRedirectURI }: ISiopRPInstanceArgs, context: IRequiredContext): Promise<RPInstance> {
290
+ const instanceId = queryId ?? SIOPv2RP._DEFAULT_OPTS_KEY
289
291
  if (!this.instances.has(instanceId)) {
290
- const instanceOpts = this.getInstanceOpts(definitionId)
291
- const rpOpts = await this.getRPOptions(context, { definitionId, responseRedirectURI: responseRedirectURI })
292
+ const instanceOpts = this.getInstanceOpts(queryId)
293
+ const rpOpts = await this.getRPOptions(context, { queryId, responseRedirectURI: responseRedirectURI })
292
294
  if (!rpOpts.identifierOpts.resolveOpts?.resolver || typeof rpOpts.identifierOpts.resolveOpts.resolver.resolve !== 'function') {
293
295
  if (!rpOpts.identifierOpts?.resolveOpts) {
294
296
  rpOpts.identifierOpts = { ...rpOpts.identifierOpts }
295
297
  rpOpts.identifierOpts.resolveOpts = { ...rpOpts.identifierOpts.resolveOpts }
296
298
  }
297
- console.log('Using agent DID resolver for RP instance with definition id ' + definitionId)
299
+ console.log('Using agent DID resolver for RP instance with definition id ' + queryId)
298
300
  rpOpts.identifierOpts.resolveOpts.resolver = getAgentResolver(context, {
299
301
  uniresolverResolution: true,
300
302
  localResolution: true,
@@ -310,11 +312,11 @@ export class SIOPv2RP implements IAgentPlugin {
310
312
  return rpInstance
311
313
  }
312
314
 
313
- async getRPOptions(context: IRequiredContext, opts: { definitionId?: string; responseRedirectURI?: string }): Promise<IRPOptions> {
314
- const { definitionId, responseRedirectURI: responseRedirectURI } = opts
315
- const options = this.getInstanceOpts(definitionId)?.rpOpts ?? this.opts.defaultOpts
315
+ async getRPOptions(context: IRequiredContext, opts: { queryId?: string; responseRedirectURI?: string }): Promise<IRPOptions> {
316
+ const { queryId, responseRedirectURI: responseRedirectURI } = opts
317
+ const options = this.getInstanceOpts(queryId)?.rpOpts ?? this.opts.defaultOpts
316
318
  if (!options) {
317
- throw Error(`Could not get specific nor default options for definition ${definitionId}`)
319
+ throw Error(`Could not get specific nor default options for definition ${queryId}`)
318
320
  }
319
321
  if (this.opts.defaultOpts) {
320
322
  if (!options.identifierOpts) {
@@ -348,7 +350,7 @@ export class SIOPv2RP implements IAgentPlugin {
348
350
  getInstanceOpts(definitionId?: string): IPEXInstanceOptions | undefined {
349
351
  if (!this.opts.instanceOpts) return undefined
350
352
 
351
- const instanceOpt = definitionId ? this.opts.instanceOpts.find((i) => i.definitionId === definitionId) : undefined
353
+ const instanceOpt = definitionId ? this.opts.instanceOpts.find((i) => i.queryId === definitionId) : undefined
352
354
 
353
355
  return instanceOpt ?? this.getDefaultOptions(definitionId)
354
356
  }
@@ -356,11 +358,11 @@ export class SIOPv2RP implements IAgentPlugin {
356
358
  private getDefaultOptions(definitionId: string | undefined) {
357
359
  if (!this.opts.instanceOpts) return undefined
358
360
 
359
- const defaultOptions = this.opts.instanceOpts.find((i) => i.definitionId === 'default')
361
+ const defaultOptions = this.opts.instanceOpts.find((i) => i.queryId === 'default')
360
362
  if (defaultOptions) {
361
363
  const clonedOptions = { ...defaultOptions }
362
364
  if (definitionId !== undefined) {
363
- clonedOptions.definitionId = definitionId
365
+ clonedOptions.queryId = definitionId
364
366
  }
365
367
  return clonedOptions
366
368
  }
package/src/functions.ts CHANGED
@@ -116,11 +116,11 @@ export async function createRPBuilder(args: {
116
116
  let definition: IPresentationDefinition | undefined = args.definition
117
117
  let dcqlQuery: DcqlQuery | undefined = args.dcql
118
118
 
119
- if (!definition && pexOpts && pexOpts.definitionId) {
119
+ if (!definition && pexOpts && pexOpts.queryId) {
120
120
  const presentationDefinitionItems = await context.agent.pdmGetDefinitions({
121
121
  filter: [
122
122
  {
123
- definitionId: pexOpts.definitionId,
123
+ definitionId: pexOpts.queryId,
124
124
  version: pexOpts.version,
125
125
  tenantId: pexOpts.tenantId,
126
126
  },
@@ -2,7 +2,8 @@ import {
2
2
  AuthorizationRequestPayload,
3
3
  AuthorizationRequestState,
4
4
  AuthorizationResponsePayload,
5
- AuthorizationResponseState,
5
+ AuthorizationResponseStateWithVerifiedData,
6
+ CallbackOpts,
6
7
  ClaimPayloadCommonOpts,
7
8
  ClientMetadataOpts,
8
9
  IRPSessionManager,
@@ -27,7 +28,7 @@ import { IPDManager, VersionControlMode } from '@sphereon/ssi-sdk.pd-manager'
27
28
  import { IPresentationExchange } from '@sphereon/ssi-sdk.presentation-exchange'
28
29
  import { ISDJwtPlugin } from '@sphereon/ssi-sdk.sd-jwt'
29
30
  import { AuthorizationRequestStateStatus } from '@sphereon/ssi-sdk.siopv2-oid4vp-common'
30
- import { AdditionalClaims, DcqlQueryPayload, HasherSync } from '@sphereon/ssi-types'
31
+ import { DcqlQueryPayload, HasherSync } from '@sphereon/ssi-types'
31
32
  import { VerifyCallback } from '@sphereon/wellknown-dids-client'
32
33
  import { IAgentContext, ICredentialIssuer, ICredentialVerifier, IDIDManager, IKeyManager, IPluginMethodMap, IResolver } from '@veramo/core'
33
34
 
@@ -52,7 +53,6 @@ export interface ISIOPv2RP extends IPluginMethodMap {
52
53
  siopDeleteAuthState(args: IDeleteAuthStateArgs, context: IRequiredContext): Promise<boolean>
53
54
  siopVerifyAuthResponse(args: IVerifyAuthResponseStateArgs, context: IRequiredContext): Promise<VerifiedAuthorizationResponse>
54
55
  siopImportDefinitions(args: ImportDefinitionsArgs, context: IRequiredContext): Promise<void>
55
-
56
56
  siopGetRedirectURI(args: IGetRedirectUriArgs, context: IRequiredContext): Promise<string | undefined>
57
57
  }
58
58
 
@@ -64,8 +64,9 @@ export interface ISiopv2RPOpts {
64
64
  export interface IRPDefaultOpts extends IRPOptions {}
65
65
 
66
66
  export interface ICreateAuthRequestArgs {
67
- definitionId: string
67
+ queryId: string
68
68
  correlationId: string
69
+ useQueryIdInstance?: boolean
69
70
  responseURIType: ResponseURIType
70
71
  responseURI: string
71
72
  responseRedirectURI?: string
@@ -74,24 +75,25 @@ export interface ICreateAuthRequestArgs {
74
75
  nonce?: string
75
76
  state?: string
76
77
  claims?: ClaimPayloadCommonOpts
78
+ callback?: CallbackOpts
77
79
  }
78
80
 
79
81
  export interface IGetAuthRequestStateArgs {
80
82
  correlationId: string
81
- definitionId: string
83
+ queryId?: string
82
84
  errorOnNotFound?: boolean
83
85
  }
84
86
 
85
87
  export interface IGetAuthResponseStateArgs {
86
88
  correlationId: string
87
- definitionId: string
89
+ queryId?: string
88
90
  errorOnNotFound?: boolean
89
91
  progressRequestStateTo?: AuthorizationRequestStateStatus
90
92
  includeVerifiedData?: VerifiedDataMode
91
93
  }
92
94
 
93
95
  export interface IUpdateRequestStateArgs {
94
- definitionId: string
96
+ queryId: string
95
97
  correlationId: string
96
98
  state: AuthorizationRequestStateStatus
97
99
  error?: string
@@ -99,12 +101,12 @@ export interface IUpdateRequestStateArgs {
99
101
 
100
102
  export interface IDeleteAuthStateArgs {
101
103
  correlationId: string
102
- definitionId: string
104
+ queryId?: string
103
105
  }
104
106
 
105
107
  export interface IVerifyAuthResponseStateArgs {
106
108
  authorizationResponse: string | AuthorizationResponsePayload
107
- definitionId?: string
109
+ queryId?: string
108
110
  correlationId: string
109
111
  audience?: string
110
112
  dcqlQueryPayload?: DcqlQueryPayload
@@ -116,7 +118,7 @@ export interface IDefinitionPair {
116
118
  }
117
119
 
118
120
  export interface ImportDefinitionsArgs {
119
- definitions: Array<IDefinitionPair>
121
+ queries: Array<IDefinitionPair>
120
122
  tenantId?: string
121
123
  version?: string
122
124
  versionControlMode?: VersionControlMode
@@ -124,7 +126,7 @@ export interface ImportDefinitionsArgs {
124
126
 
125
127
  export interface IGetRedirectUriArgs {
126
128
  correlationId: string
127
- definitionId?: string
129
+ queryId?: string
128
130
  state?: string
129
131
  }
130
132
 
@@ -140,7 +142,7 @@ export interface IPEXDefinitionPersistArgs extends IPEXInstanceOptions {
140
142
  }
141
143
 
142
144
  export interface ISiopRPInstanceArgs {
143
- definitionId?: string
145
+ queryId?: string
144
146
  responseRedirectURI?: string
145
147
  }
146
148
 
@@ -165,7 +167,7 @@ export interface IRPOptions {
165
167
  export interface IPEXOptions {
166
168
  presentationVerifyCallback?: PresentationVerificationCallback
167
169
  // definition?: IPresentationDefinition
168
- definitionId: string
170
+ queryId: string
169
171
  version?: string
170
172
  tenantId?: string
171
173
  }
@@ -198,10 +200,6 @@ export type CredentialOpts = {
198
200
  hasher?: HasherSync
199
201
  }
200
202
 
201
- export interface AuthorizationResponseStateWithVerifiedData extends AuthorizationResponseState {
202
- verifiedData?: AdditionalClaims
203
- }
204
-
205
203
  export type IRequiredContext = IAgentContext<
206
204
  IResolver &
207
205
  IDIDManager &