@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.
- package/dist/index.cjs +32 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -14
- package/dist/index.d.ts +15 -14
- package/dist/index.js +32 -29
- package/dist/index.js.map +1 -1
- package/package.json +17 -17
- package/src/RPInstance.ts +5 -4
- package/src/agent/SIOPv2RP.ts +28 -27
- package/src/functions.ts +2 -2
- package/src/types/ISIOPv2RP.ts +11 -11
package/src/agent/SIOPv2RP.ts
CHANGED
|
@@ -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({
|
|
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({
|
|
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:
|
|
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({
|
|
111
|
-
rp.get(context).then((rp) =>
|
|
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({
|
|
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 !== '
|
|
197
|
-
throw Error(`Only '
|
|
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({
|
|
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({
|
|
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({
|
|
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 {
|
|
239
|
+
const { queries, tenantId, version, versionControlMode } = args
|
|
239
240
|
await Promise.all(
|
|
240
|
-
|
|
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.
|
|
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({
|
|
289
|
-
const instanceId =
|
|
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(
|
|
292
|
-
const rpOpts = await this.getRPOptions(context, {
|
|
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 ' +
|
|
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: {
|
|
315
|
-
const {
|
|
316
|
-
const options = this.getInstanceOpts(
|
|
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 ${
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
119
|
+
if (!definition && pexOpts && pexOpts.queryId) {
|
|
120
120
|
const presentationDefinitionItems = await context.agent.pdmGetDefinitions({
|
|
121
121
|
filter: [
|
|
122
122
|
{
|
|
123
|
-
definitionId: pexOpts.
|
|
123
|
+
definitionId: pexOpts.queryId,
|
|
124
124
|
version: pexOpts.version,
|
|
125
125
|
tenantId: pexOpts.tenantId,
|
|
126
126
|
},
|
package/src/types/ISIOPv2RP.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
81
|
+
queryId?: string
|
|
82
82
|
errorOnNotFound?: boolean
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
export interface IGetAuthResponseStateArgs {
|
|
86
86
|
correlationId: string
|
|
87
|
-
|
|
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
|
-
|
|
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
|
-
|
|
102
|
+
queryId?: string
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
export interface IVerifyAuthResponseStateArgs {
|
|
106
106
|
authorizationResponse: string | AuthorizationResponsePayload
|
|
107
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
168
|
+
queryId: string
|
|
169
169
|
version?: string
|
|
170
170
|
tenantId?: string
|
|
171
171
|
}
|