@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth 0.34.1-feature.DIIPv4.142 → 0.34.1-feature.DIIPv4.152

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.
@@ -43,7 +43,6 @@ import {
43
43
  VerifiedDataMode,
44
44
  } from '../index'
45
45
  import { RPInstance } from '../RPInstance'
46
-
47
46
  import { ISIOPv2RP } from '../types/ISIOPv2RP'
48
47
  import { shaHasher as defaultHasher } from '@sphereon/ssi-sdk.core'
49
48
 
@@ -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,7 +224,7 @@ 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,
@@ -235,9 +236,9 @@ export class SIOPv2RP implements IAgentPlugin {
235
236
  }
236
237
 
237
238
  private async siopImportDefinitions(args: ImportDefinitionsArgs, context: IRequiredContext): Promise<void> {
238
- const { definitions, tenantId, version, versionControlMode } = args
239
+ const { queries, tenantId, version, versionControlMode } = args
239
240
  await Promise.all(
240
- definitions.map(async (definitionPair) => {
241
+ queries.map(async (definitionPair) => {
241
242
  const definitionPayload = definitionPair.definitionPayload
242
243
  if (!definitionPayload && !definitionPair.dcqlPayload) {
243
244
  return Promise.reject(Error('Either dcqlPayload or definitionPayload must be suppplied'))
@@ -270,7 +271,7 @@ export class SIOPv2RP implements IAgentPlugin {
270
271
  }
271
272
 
272
273
  private async siopGetRedirectURI(args: IGetRedirectUriArgs, context: IRequiredContext): Promise<string | undefined> {
273
- const instanceId = args.definitionId ?? SIOPv2RP._DEFAULT_OPTS_KEY
274
+ const instanceId = args.queryId ?? SIOPv2RP._DEFAULT_OPTS_KEY
274
275
  if (this.instances.has(instanceId)) {
275
276
  const rpInstance = this.instances.get(instanceId)
276
277
  if (rpInstance !== undefined) {
@@ -285,17 +286,17 @@ export class SIOPv2RP implements IAgentPlugin {
285
286
  return undefined
286
287
  }
287
288
 
288
- async getRPInstance({ definitionId, responseRedirectURI }: ISiopRPInstanceArgs, context: IRequiredContext): Promise<RPInstance> {
289
- 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
290
291
  if (!this.instances.has(instanceId)) {
291
- const instanceOpts = this.getInstanceOpts(definitionId)
292
- 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 })
293
294
  if (!rpOpts.identifierOpts.resolveOpts?.resolver || typeof rpOpts.identifierOpts.resolveOpts.resolver.resolve !== 'function') {
294
295
  if (!rpOpts.identifierOpts?.resolveOpts) {
295
296
  rpOpts.identifierOpts = { ...rpOpts.identifierOpts }
296
297
  rpOpts.identifierOpts.resolveOpts = { ...rpOpts.identifierOpts.resolveOpts }
297
298
  }
298
- 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)
299
300
  rpOpts.identifierOpts.resolveOpts.resolver = getAgentResolver(context, {
300
301
  uniresolverResolution: true,
301
302
  localResolution: true,
@@ -311,11 +312,11 @@ export class SIOPv2RP implements IAgentPlugin {
311
312
  return rpInstance
312
313
  }
313
314
 
314
- async getRPOptions(context: IRequiredContext, opts: { definitionId?: string; responseRedirectURI?: string }): Promise<IRPOptions> {
315
- const { definitionId, responseRedirectURI: responseRedirectURI } = opts
316
- 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
317
318
  if (!options) {
318
- 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}`)
319
320
  }
320
321
  if (this.opts.defaultOpts) {
321
322
  if (!options.identifierOpts) {
@@ -349,7 +350,7 @@ export class SIOPv2RP implements IAgentPlugin {
349
350
  getInstanceOpts(definitionId?: string): IPEXInstanceOptions | undefined {
350
351
  if (!this.opts.instanceOpts) return undefined
351
352
 
352
- 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
353
354
 
354
355
  return instanceOpt ?? this.getDefaultOptions(definitionId)
355
356
  }
@@ -357,11 +358,11 @@ export class SIOPv2RP implements IAgentPlugin {
357
358
  private getDefaultOptions(definitionId: string | undefined) {
358
359
  if (!this.opts.instanceOpts) return undefined
359
360
 
360
- const defaultOptions = this.opts.instanceOpts.find((i) => i.definitionId === 'default')
361
+ const defaultOptions = this.opts.instanceOpts.find((i) => i.queryId === 'default')
361
362
  if (defaultOptions) {
362
363
  const clonedOptions = { ...defaultOptions }
363
364
  if (definitionId !== undefined) {
364
- clonedOptions.definitionId = definitionId
365
+ clonedOptions.queryId = definitionId
365
366
  }
366
367
  return clonedOptions
367
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
  },
@@ -52,7 +52,6 @@ export interface ISIOPv2RP extends IPluginMethodMap {
52
52
  siopDeleteAuthState(args: IDeleteAuthStateArgs, context: IRequiredContext): Promise<boolean>
53
53
  siopVerifyAuthResponse(args: IVerifyAuthResponseStateArgs, context: IRequiredContext): Promise<VerifiedAuthorizationResponse>
54
54
  siopImportDefinitions(args: ImportDefinitionsArgs, context: IRequiredContext): Promise<void>
55
-
56
55
  siopGetRedirectURI(args: IGetRedirectUriArgs, context: IRequiredContext): Promise<string | undefined>
57
56
  }
58
57
 
@@ -64,8 +63,9 @@ export interface ISiopv2RPOpts {
64
63
  export interface IRPDefaultOpts extends IRPOptions {}
65
64
 
66
65
  export interface ICreateAuthRequestArgs {
67
- definitionId: string
66
+ queryId: string
68
67
  correlationId: string
68
+ useQueryIdInstance?: boolean
69
69
  responseURIType: ResponseURIType
70
70
  responseURI: string
71
71
  responseRedirectURI?: string
@@ -78,20 +78,20 @@ export interface ICreateAuthRequestArgs {
78
78
 
79
79
  export interface IGetAuthRequestStateArgs {
80
80
  correlationId: string
81
- definitionId: string
81
+ queryId?: string
82
82
  errorOnNotFound?: boolean
83
83
  }
84
84
 
85
85
  export interface IGetAuthResponseStateArgs {
86
86
  correlationId: string
87
- definitionId: string
87
+ queryId?: string
88
88
  errorOnNotFound?: boolean
89
89
  progressRequestStateTo?: AuthorizationRequestStateStatus
90
90
  includeVerifiedData?: VerifiedDataMode
91
91
  }
92
92
 
93
93
  export interface IUpdateRequestStateArgs {
94
- definitionId: string
94
+ queryId: string
95
95
  correlationId: string
96
96
  state: AuthorizationRequestStateStatus
97
97
  error?: string
@@ -99,12 +99,12 @@ export interface IUpdateRequestStateArgs {
99
99
 
100
100
  export interface IDeleteAuthStateArgs {
101
101
  correlationId: string
102
- definitionId: string
102
+ queryId?: string
103
103
  }
104
104
 
105
105
  export interface IVerifyAuthResponseStateArgs {
106
106
  authorizationResponse: string | AuthorizationResponsePayload
107
- definitionId?: string
107
+ queryId?: string
108
108
  correlationId: string
109
109
  audience?: string
110
110
  dcqlQueryPayload?: DcqlQueryPayload
@@ -116,7 +116,7 @@ export interface IDefinitionPair {
116
116
  }
117
117
 
118
118
  export interface ImportDefinitionsArgs {
119
- definitions: Array<IDefinitionPair>
119
+ queries: Array<IDefinitionPair>
120
120
  tenantId?: string
121
121
  version?: string
122
122
  versionControlMode?: VersionControlMode
@@ -124,7 +124,7 @@ export interface ImportDefinitionsArgs {
124
124
 
125
125
  export interface IGetRedirectUriArgs {
126
126
  correlationId: string
127
- definitionId?: string
127
+ queryId?: string
128
128
  state?: string
129
129
  }
130
130
 
@@ -140,7 +140,7 @@ export interface IPEXDefinitionPersistArgs extends IPEXInstanceOptions {
140
140
  }
141
141
 
142
142
  export interface ISiopRPInstanceArgs {
143
- definitionId?: string
143
+ queryId?: string
144
144
  responseRedirectURI?: string
145
145
  }
146
146
 
@@ -165,7 +165,7 @@ export interface IRPOptions {
165
165
  export interface IPEXOptions {
166
166
  presentationVerifyCallback?: PresentationVerificationCallback
167
167
  // definition?: IPresentationDefinition
168
- definitionId: string
168
+ queryId: string
169
169
  version?: string
170
170
  tenantId?: string
171
171
  }