@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth 0.34.1-feature.DIIPv4.144 → 0.34.1-feature.DIIPv4.156

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 {
@@ -24,7 +25,6 @@ import {
24
25
  import { IAgentPlugin } from '@veramo/core'
25
26
  import { DcqlQuery } from 'dcql'
26
27
  import {
27
- AuthorizationResponseStateWithVerifiedData,
28
28
  IAuthorizationRequestPayloads,
29
29
  ICreateAuthRequestArgs,
30
30
  IGetAuthRequestStateArgs,
@@ -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
  },
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 { SIOPv2RP } from './agent/SIOPv2RP'
7
7
  export * from './types/ISIOPv2RP'
@@ -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 &