@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth 0.34.1-feature.SSISDK.57.uni.client.206 → 0.34.1-feature.SSISDK.58.host.nonce.endpoint.145
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 +403 -417
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +45 -729
- package/dist/index.d.ts +45 -729
- package/dist/index.js +397 -410
- package/dist/index.js.map +1 -1
- package/package.json +17 -17
- package/src/RPInstance.ts +28 -11
- package/src/agent/SIOPv2RP.ts +55 -76
- package/src/functions.ts +46 -49
- package/src/index.ts +1 -1
- package/src/types/ISIOPv2RP.ts +32 -22
package/src/agent/SIOPv2RP.ts
CHANGED
|
@@ -3,15 +3,10 @@ import {
|
|
|
3
3
|
AuthorizationResponsePayload,
|
|
4
4
|
AuthorizationResponseState,
|
|
5
5
|
AuthorizationResponseStateStatus,
|
|
6
|
-
AuthorizationResponseStateWithVerifiedData,
|
|
7
6
|
decodeUriAsJson,
|
|
8
7
|
VerifiedAuthorizationResponse,
|
|
9
8
|
} from '@sphereon/did-auth-siop'
|
|
10
9
|
import { getAgentResolver } from '@sphereon/ssi-sdk-ext.did-utils'
|
|
11
|
-
import { shaHasher as defaultHasher } from '@sphereon/ssi-sdk.core'
|
|
12
|
-
import { validate as isValidUUID } from 'uuid'
|
|
13
|
-
|
|
14
|
-
import type { ImportDcqlQueryItem } from '@sphereon/ssi-sdk.pd-manager'
|
|
15
10
|
import {
|
|
16
11
|
AdditionalClaims,
|
|
17
12
|
CredentialMapper,
|
|
@@ -29,6 +24,7 @@ import {
|
|
|
29
24
|
import { IAgentPlugin } from '@veramo/core'
|
|
30
25
|
import { DcqlQuery } from 'dcql'
|
|
31
26
|
import {
|
|
27
|
+
AuthorizationResponseStateWithVerifiedData,
|
|
32
28
|
IAuthorizationRequestPayloads,
|
|
33
29
|
ICreateAuthRequestArgs,
|
|
34
30
|
IGetAuthRequestStateArgs,
|
|
@@ -47,7 +43,9 @@ import {
|
|
|
47
43
|
VerifiedDataMode,
|
|
48
44
|
} from '../index'
|
|
49
45
|
import { RPInstance } from '../RPInstance'
|
|
46
|
+
|
|
50
47
|
import { ISIOPv2RP } from '../types/ISIOPv2RP'
|
|
48
|
+
import { shaHasher as defaultHasher } from '@sphereon/ssi-sdk.core'
|
|
51
49
|
|
|
52
50
|
export class SIOPv2RP implements IAgentPlugin {
|
|
53
51
|
private readonly opts: ISiopv2RPOpts
|
|
@@ -87,14 +85,7 @@ export class SIOPv2RP implements IAgentPlugin {
|
|
|
87
85
|
}
|
|
88
86
|
|
|
89
87
|
private async createAuthorizationRequestURI(createArgs: ICreateAuthRequestArgs, context: IRequiredContext): Promise<string> {
|
|
90
|
-
return await this.getRPInstance(
|
|
91
|
-
{
|
|
92
|
-
createWhenNotPresent: true,
|
|
93
|
-
responseRedirectURI: createArgs.responseRedirectURI,
|
|
94
|
-
...(createArgs.useQueryIdInstance === true && { queryId: createArgs.queryId }),
|
|
95
|
-
},
|
|
96
|
-
context,
|
|
97
|
-
)
|
|
88
|
+
return await this.getRPInstance({ definitionId: createArgs.definitionId, responseRedirectURI: createArgs.responseRedirectURI }, context)
|
|
98
89
|
.then((rp) => rp.createAuthorizationRequestURI(createArgs, context))
|
|
99
90
|
.then((URI) => URI.encodedUri)
|
|
100
91
|
}
|
|
@@ -103,20 +94,20 @@ export class SIOPv2RP implements IAgentPlugin {
|
|
|
103
94
|
createArgs: ICreateAuthRequestArgs,
|
|
104
95
|
context: IRequiredContext,
|
|
105
96
|
): Promise<IAuthorizationRequestPayloads> {
|
|
106
|
-
return await this.getRPInstance({
|
|
97
|
+
return await this.getRPInstance({ definitionId: createArgs.definitionId }, context)
|
|
107
98
|
.then((rp) => rp.createAuthorizationRequest(createArgs, context))
|
|
108
99
|
.then(async (request) => {
|
|
109
100
|
const authRequest: IAuthorizationRequestPayloads = {
|
|
110
101
|
authorizationRequest: request.payload,
|
|
111
102
|
requestObject: await request.requestObjectJwt(),
|
|
112
|
-
requestObjectDecoded: request.requestObject?.getPayload(),
|
|
103
|
+
requestObjectDecoded: await request.requestObject?.getPayload(),
|
|
113
104
|
}
|
|
114
105
|
return authRequest
|
|
115
106
|
})
|
|
116
107
|
}
|
|
117
108
|
|
|
118
109
|
private async siopGetRequestState(args: IGetAuthRequestStateArgs, context: IRequiredContext): Promise<AuthorizationRequestState | undefined> {
|
|
119
|
-
return await this.getRPInstance({
|
|
110
|
+
return await this.getRPInstance({ definitionId: args.definitionId }, context).then((rp) =>
|
|
120
111
|
rp.get(context).then((rp) => rp.sessionManager.getRequestStateByCorrelationId(args.correlationId, args.errorOnNotFound)),
|
|
121
112
|
)
|
|
122
113
|
}
|
|
@@ -125,7 +116,7 @@ export class SIOPv2RP implements IAgentPlugin {
|
|
|
125
116
|
args: IGetAuthResponseStateArgs,
|
|
126
117
|
context: IRequiredContext,
|
|
127
118
|
): Promise<AuthorizationResponseStateWithVerifiedData | undefined> {
|
|
128
|
-
const rpInstance: RPInstance = await this.getRPInstance({
|
|
119
|
+
const rpInstance: RPInstance = await this.getRPInstance({ definitionId: args.definitionId }, context)
|
|
129
120
|
const authorizationResponseState: AuthorizationResponseState | undefined = await rpInstance
|
|
130
121
|
.get(context)
|
|
131
122
|
.then((rp) => rp.sessionManager.getResponseStateByCorrelationId(args.correlationId, args.errorOnNotFound))
|
|
@@ -202,10 +193,10 @@ export class SIOPv2RP implements IAgentPlugin {
|
|
|
202
193
|
: CredentialMapper.toUniformPresentation(presentationDecoded as OriginalVerifiablePresentation)
|
|
203
194
|
|
|
204
195
|
private async siopUpdateRequestState(args: IUpdateRequestStateArgs, context: IRequiredContext): Promise<AuthorizationRequestState> {
|
|
205
|
-
if (args.state !== '
|
|
206
|
-
throw Error(`Only '
|
|
196
|
+
if (args.state !== 'sent') {
|
|
197
|
+
throw Error(`Only 'sent' status is supported for this method at this point`)
|
|
207
198
|
}
|
|
208
|
-
return await this.getRPInstance({
|
|
199
|
+
return await this.getRPInstance({ definitionId: args.definitionId }, context)
|
|
209
200
|
// todo: In the SIOP library we need to update the signal method to be more like this method
|
|
210
201
|
.then((rp) =>
|
|
211
202
|
rp.get(context).then(async (rp) => {
|
|
@@ -219,7 +210,7 @@ export class SIOPv2RP implements IAgentPlugin {
|
|
|
219
210
|
}
|
|
220
211
|
|
|
221
212
|
private async siopDeleteState(args: IGetAuthResponseStateArgs, context: IRequiredContext): Promise<boolean> {
|
|
222
|
-
return await this.getRPInstance({
|
|
213
|
+
return await this.getRPInstance({ definitionId: args.definitionId }, context)
|
|
223
214
|
.then((rp) => rp.get(context).then((rp) => rp.sessionManager.deleteStateForCorrelationId(args.correlationId)))
|
|
224
215
|
.then(() => true)
|
|
225
216
|
}
|
|
@@ -232,11 +223,11 @@ export class SIOPv2RP implements IAgentPlugin {
|
|
|
232
223
|
typeof args.authorizationResponse === 'string'
|
|
233
224
|
? (decodeUriAsJson(args.authorizationResponse) as AuthorizationResponsePayload)
|
|
234
225
|
: args.authorizationResponse
|
|
235
|
-
return await this.getRPInstance({
|
|
226
|
+
return await this.getRPInstance({ definitionId: args.definitionId }, context).then((rp) =>
|
|
236
227
|
rp.get(context).then((rp) =>
|
|
237
228
|
rp.verifyAuthorizationResponse(authResponse, {
|
|
238
229
|
correlationId: args.correlationId,
|
|
239
|
-
...(args.
|
|
230
|
+
...(args.dcqlQueryPayload ? { dcqlQuery: args.dcqlQueryPayload.dcqlQuery } : {}),
|
|
240
231
|
audience: args.audience,
|
|
241
232
|
}),
|
|
242
233
|
),
|
|
@@ -244,18 +235,33 @@ export class SIOPv2RP implements IAgentPlugin {
|
|
|
244
235
|
}
|
|
245
236
|
|
|
246
237
|
private async siopImportDefinitions(args: ImportDefinitionsArgs, context: IRequiredContext): Promise<void> {
|
|
247
|
-
const {
|
|
238
|
+
const { definitions, tenantId, version, versionControlMode } = args
|
|
248
239
|
await Promise.all(
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
240
|
+
definitions.map(async (definitionPair) => {
|
|
241
|
+
const definitionPayload = definitionPair.definitionPayload
|
|
242
|
+
if (!definitionPayload && !definitionPair.dcqlPayload) {
|
|
243
|
+
return Promise.reject(Error('Either dcqlPayload or definitionPayload must be suppplied'))
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
let definitionId: string
|
|
247
|
+
if (definitionPair.dcqlPayload) {
|
|
248
|
+
DcqlQuery.validate(definitionPair.dcqlPayload.dcqlQuery)
|
|
249
|
+
console.log(`persisting DCQL definition ${definitionPair.dcqlPayload.queryId} with versionControlMode ${versionControlMode}`)
|
|
250
|
+
definitionId = definitionPair.dcqlPayload.queryId
|
|
251
|
+
}
|
|
252
|
+
if (definitionPayload) {
|
|
253
|
+
await context.agent.pexValidateDefinition({ definition: definitionPayload })
|
|
254
|
+
console.log(`persisting PEX definition ${definitionPayload.id} / ${definitionPayload.name} with versionControlMode ${versionControlMode}`)
|
|
255
|
+
definitionId = definitionPayload.id
|
|
256
|
+
}
|
|
252
257
|
|
|
253
258
|
return context.agent.pdmPersistDefinition({
|
|
254
259
|
definitionItem: {
|
|
255
|
-
|
|
260
|
+
definitionId: definitionId!,
|
|
256
261
|
tenantId: tenantId,
|
|
257
262
|
version: version,
|
|
258
|
-
|
|
263
|
+
definitionPayload,
|
|
264
|
+
dcqlPayload: definitionPair.dcqlPayload,
|
|
259
265
|
},
|
|
260
266
|
opts: { versionControlMode: versionControlMode },
|
|
261
267
|
})
|
|
@@ -264,7 +270,7 @@ export class SIOPv2RP implements IAgentPlugin {
|
|
|
264
270
|
}
|
|
265
271
|
|
|
266
272
|
private async siopGetRedirectURI(args: IGetRedirectUriArgs, context: IRequiredContext): Promise<string | undefined> {
|
|
267
|
-
const instanceId = args.
|
|
273
|
+
const instanceId = args.definitionId ?? SIOPv2RP._DEFAULT_OPTS_KEY
|
|
268
274
|
if (this.instances.has(instanceId)) {
|
|
269
275
|
const rpInstance = this.instances.get(instanceId)
|
|
270
276
|
if (rpInstance !== undefined) {
|
|
@@ -279,64 +285,37 @@ export class SIOPv2RP implements IAgentPlugin {
|
|
|
279
285
|
return undefined
|
|
280
286
|
}
|
|
281
287
|
|
|
282
|
-
async getRPInstance({
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
rpInstanceId = queryId
|
|
288
|
-
rpInstance = this.instances.get(rpInstanceId)!
|
|
289
|
-
} else if (isValidUUID(queryId)) {
|
|
290
|
-
try {
|
|
291
|
-
// Check whether queryId is actually the PD item id
|
|
292
|
-
const pd = await context.agent.pdmGetDefinition({ itemId: queryId })
|
|
293
|
-
if (this.instances.has(pd.queryId)) {
|
|
294
|
-
rpInstanceId = pd.queryId
|
|
295
|
-
rpInstance = this.instances.get(rpInstanceId)!
|
|
296
|
-
}
|
|
297
|
-
} catch (ignore) {}
|
|
298
|
-
}
|
|
299
|
-
if (createWhenNotPresent) {
|
|
300
|
-
rpInstanceId = queryId
|
|
301
|
-
} else {
|
|
302
|
-
rpInstance = this.instances.get(rpInstanceId)
|
|
303
|
-
}
|
|
304
|
-
} else {
|
|
305
|
-
rpInstance = this.instances.get(rpInstanceId)
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
if (!rpInstance) {
|
|
309
|
-
if (!createWhenNotPresent) {
|
|
310
|
-
return Promise.reject(`No RP instance found for key ${rpInstanceId}`)
|
|
311
|
-
}
|
|
312
|
-
const instanceOpts = this.getInstanceOpts(queryId)
|
|
313
|
-
const rpOpts = await this.getRPOptions(context, { queryId, responseRedirectURI: responseRedirectURI })
|
|
288
|
+
async getRPInstance({ definitionId, responseRedirectURI }: ISiopRPInstanceArgs, context: IRequiredContext): Promise<RPInstance> {
|
|
289
|
+
const instanceId = definitionId ?? SIOPv2RP._DEFAULT_OPTS_KEY
|
|
290
|
+
if (!this.instances.has(instanceId)) {
|
|
291
|
+
const instanceOpts = this.getInstanceOpts(definitionId)
|
|
292
|
+
const rpOpts = await this.getRPOptions(context, { definitionId, responseRedirectURI: responseRedirectURI })
|
|
314
293
|
if (!rpOpts.identifierOpts.resolveOpts?.resolver || typeof rpOpts.identifierOpts.resolveOpts.resolver.resolve !== 'function') {
|
|
315
294
|
if (!rpOpts.identifierOpts?.resolveOpts) {
|
|
316
295
|
rpOpts.identifierOpts = { ...rpOpts.identifierOpts }
|
|
317
296
|
rpOpts.identifierOpts.resolveOpts = { ...rpOpts.identifierOpts.resolveOpts }
|
|
318
297
|
}
|
|
319
|
-
console.log('Using agent DID resolver for RP instance with definition id ' +
|
|
298
|
+
console.log('Using agent DID resolver for RP instance with definition id ' + definitionId)
|
|
320
299
|
rpOpts.identifierOpts.resolveOpts.resolver = getAgentResolver(context, {
|
|
321
300
|
uniresolverResolution: true,
|
|
322
301
|
localResolution: true,
|
|
323
302
|
resolverResolution: true,
|
|
324
303
|
})
|
|
325
304
|
}
|
|
326
|
-
|
|
327
|
-
this.instances.set(rpInstanceId, rpInstance)
|
|
305
|
+
this.instances.set(instanceId, new RPInstance({ rpOpts, pexOpts: instanceOpts }))
|
|
328
306
|
}
|
|
307
|
+
const rpInstance = this.instances.get(instanceId)!
|
|
329
308
|
if (responseRedirectURI) {
|
|
330
309
|
rpInstance.rpOptions.responseRedirectUri = responseRedirectURI
|
|
331
310
|
}
|
|
332
311
|
return rpInstance
|
|
333
312
|
}
|
|
334
313
|
|
|
335
|
-
async getRPOptions(context: IRequiredContext, opts: {
|
|
336
|
-
const {
|
|
337
|
-
const options = this.getInstanceOpts(
|
|
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
|
|
338
317
|
if (!options) {
|
|
339
|
-
throw Error(`Could not get specific nor default options for definition ${
|
|
318
|
+
throw Error(`Could not get specific nor default options for definition ${definitionId}`)
|
|
340
319
|
}
|
|
341
320
|
if (this.opts.defaultOpts) {
|
|
342
321
|
if (!options.identifierOpts) {
|
|
@@ -367,22 +346,22 @@ export class SIOPv2RP implements IAgentPlugin {
|
|
|
367
346
|
return options
|
|
368
347
|
}
|
|
369
348
|
|
|
370
|
-
getInstanceOpts(
|
|
349
|
+
getInstanceOpts(definitionId?: string): IPEXInstanceOptions | undefined {
|
|
371
350
|
if (!this.opts.instanceOpts) return undefined
|
|
372
351
|
|
|
373
|
-
const instanceOpt =
|
|
352
|
+
const instanceOpt = definitionId ? this.opts.instanceOpts.find((i) => i.definitionId === definitionId) : undefined
|
|
374
353
|
|
|
375
|
-
return instanceOpt ?? this.getDefaultOptions(
|
|
354
|
+
return instanceOpt ?? this.getDefaultOptions(definitionId)
|
|
376
355
|
}
|
|
377
356
|
|
|
378
|
-
private getDefaultOptions(
|
|
357
|
+
private getDefaultOptions(definitionId: string | undefined) {
|
|
379
358
|
if (!this.opts.instanceOpts) return undefined
|
|
380
359
|
|
|
381
|
-
const defaultOptions = this.opts.instanceOpts.find((i) => i.
|
|
360
|
+
const defaultOptions = this.opts.instanceOpts.find((i) => i.definitionId === 'default')
|
|
382
361
|
if (defaultOptions) {
|
|
383
362
|
const clonedOptions = { ...defaultOptions }
|
|
384
|
-
if (
|
|
385
|
-
clonedOptions.
|
|
363
|
+
if (definitionId !== undefined) {
|
|
364
|
+
clonedOptions.definitionId = definitionId
|
|
386
365
|
}
|
|
387
366
|
return clonedOptions
|
|
388
367
|
}
|
package/src/functions.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
ClientIdentifierPrefix,
|
|
3
2
|
ClientMetadataOpts,
|
|
4
|
-
DcqlQueryLookupCallback,
|
|
5
3
|
InMemoryRPSessionManager,
|
|
6
4
|
PassBy,
|
|
7
5
|
PresentationVerificationCallback,
|
|
@@ -29,13 +27,19 @@ import {
|
|
|
29
27
|
} from '@sphereon/ssi-sdk-ext.identifier-resolution'
|
|
30
28
|
import { JwtCompactResult } from '@sphereon/ssi-sdk-ext.jwt-service'
|
|
31
29
|
import { IVerifySdJwtPresentationResult } from '@sphereon/ssi-sdk.sd-jwt'
|
|
32
|
-
import {
|
|
30
|
+
import {
|
|
31
|
+
CredentialMapper,
|
|
32
|
+
HasherSync,
|
|
33
|
+
OriginalVerifiableCredential,
|
|
34
|
+
PresentationSubmission
|
|
35
|
+
} from '@sphereon/ssi-types'
|
|
33
36
|
import { IVerifyCallbackArgs, IVerifyCredentialResult, VerifyCallback } from '@sphereon/wellknown-dids-client'
|
|
37
|
+
// import { KeyAlgo, SuppliedSigner } from '@sphereon/ssi-sdk.core'
|
|
34
38
|
import { TKeyType } from '@veramo/core'
|
|
35
39
|
import { JWTVerifyOptions } from 'did-jwt'
|
|
36
40
|
import { Resolvable } from 'did-resolver'
|
|
37
41
|
import { EventEmitter } from 'events'
|
|
38
|
-
import { IRequiredContext, IRPOptions, ISIOPIdentifierOptions } from './types/ISIOPv2RP'
|
|
42
|
+
import { IPEXOptions, IRequiredContext, IRPOptions, ISIOPIdentifierOptions } from './types/ISIOPv2RP'
|
|
39
43
|
import { DcqlQuery } from 'dcql'
|
|
40
44
|
import { defaultHasher } from '@sphereon/ssi-sdk.core'
|
|
41
45
|
|
|
@@ -43,7 +47,7 @@ export function getRequestVersion(rpOptions: IRPOptions): SupportedVersion {
|
|
|
43
47
|
if (Array.isArray(rpOptions.supportedVersions) && rpOptions.supportedVersions.length > 0) {
|
|
44
48
|
return rpOptions.supportedVersions[0]
|
|
45
49
|
}
|
|
46
|
-
return SupportedVersion.
|
|
50
|
+
return SupportedVersion.JWT_VC_PRESENTATION_PROFILE_v1
|
|
47
51
|
}
|
|
48
52
|
|
|
49
53
|
function getWellKnownDIDVerifyCallback(siopIdentifierOpts: ISIOPIdentifierOptions, context: IRequiredContext) {
|
|
@@ -58,31 +62,6 @@ function getWellKnownDIDVerifyCallback(siopIdentifierOpts: ISIOPIdentifierOption
|
|
|
58
62
|
}
|
|
59
63
|
}
|
|
60
64
|
|
|
61
|
-
export function getDcqlQueryLookupCallback(context: IRequiredContext): DcqlQueryLookupCallback {
|
|
62
|
-
async function dcqlQueryLookup(queryId: string, version?: string, tenantId?: string): Promise<DcqlQuery> {
|
|
63
|
-
// TODO Add caching?
|
|
64
|
-
const result = await context.agent.pdmGetDefinitions({
|
|
65
|
-
filter: [
|
|
66
|
-
{
|
|
67
|
-
queryId,
|
|
68
|
-
...(tenantId && { tenantId }),
|
|
69
|
-
...(version && { version }),
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
id: queryId,
|
|
73
|
-
},
|
|
74
|
-
],
|
|
75
|
-
})
|
|
76
|
-
if (result && result.length > 0) {
|
|
77
|
-
return result[0].query
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return Promise.reject(Error(`No dcql query found for queryId ${queryId}`))
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return dcqlQueryLookup
|
|
84
|
-
}
|
|
85
|
-
|
|
86
65
|
export function getPresentationVerificationCallback(
|
|
87
66
|
idOpts: ManagedIdentifierOptsOrResult,
|
|
88
67
|
context: IRequiredContext,
|
|
@@ -93,7 +72,7 @@ export function getPresentationVerificationCallback(
|
|
|
93
72
|
): Promise<PresentationVerificationResult> {
|
|
94
73
|
if (CredentialMapper.isSdJwtEncoded(args)) {
|
|
95
74
|
const result: IVerifySdJwtPresentationResult = await context.agent.verifySdJwtPresentation({
|
|
96
|
-
presentation: args
|
|
75
|
+
presentation: args
|
|
97
76
|
})
|
|
98
77
|
// fixme: investigate the correct way to handle this
|
|
99
78
|
return { verified: !!result.payload }
|
|
@@ -127,11 +106,34 @@ export function getPresentationVerificationCallback(
|
|
|
127
106
|
|
|
128
107
|
export async function createRPBuilder(args: {
|
|
129
108
|
rpOpts: IRPOptions
|
|
109
|
+
pexOpts?: IPEXOptions | undefined
|
|
130
110
|
definition?: IPresentationDefinition
|
|
111
|
+
dcql?: DcqlQuery
|
|
131
112
|
context: IRequiredContext
|
|
132
113
|
}): Promise<RPBuilder> {
|
|
133
|
-
const { rpOpts, context } = args
|
|
114
|
+
const { rpOpts, pexOpts, context } = args
|
|
134
115
|
const { identifierOpts } = rpOpts
|
|
116
|
+
let definition: IPresentationDefinition | undefined = args.definition
|
|
117
|
+
let dcqlQuery: DcqlQuery | undefined = args.dcql
|
|
118
|
+
|
|
119
|
+
if (!definition && pexOpts && pexOpts.definitionId) {
|
|
120
|
+
const presentationDefinitionItems = await context.agent.pdmGetDefinitions({
|
|
121
|
+
filter: [
|
|
122
|
+
{
|
|
123
|
+
definitionId: pexOpts.definitionId,
|
|
124
|
+
version: pexOpts.version,
|
|
125
|
+
tenantId: pexOpts.tenantId,
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
if (presentationDefinitionItems.length > 0) {
|
|
131
|
+
const presentationDefinitionItem = presentationDefinitionItems[0]
|
|
132
|
+
if (!dcqlQuery && presentationDefinitionItem.dcqlPayload) {
|
|
133
|
+
dcqlQuery = presentationDefinitionItem.dcqlPayload.dcqlQuery as DcqlQuery // cast from DcqlQueryREST back to valibot DcqlQuery
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
135
137
|
|
|
136
138
|
const didMethods = identifierOpts.supportedDIDMethods ?? (await getAgentDIDMethods(context))
|
|
137
139
|
const eventEmitter = rpOpts.eventEmitter ?? new EventEmitter()
|
|
@@ -171,7 +173,9 @@ export async function createRPBuilder(args: {
|
|
|
171
173
|
.withResponseMode(rpOpts.responseMode ?? ResponseMode.POST)
|
|
172
174
|
.withResponseType(ResponseType.VP_TOKEN, PropertyTarget.REQUEST_OBJECT)
|
|
173
175
|
// todo: move to options fill/correct method
|
|
174
|
-
.withSupportedVersions(
|
|
176
|
+
.withSupportedVersions(
|
|
177
|
+
rpOpts.supportedVersions ?? [SupportedVersion.JWT_VC_PRESENTATION_PROFILE_v1, SupportedVersion.SIOPv2_ID1, SupportedVersion.SIOPv2_D11],
|
|
178
|
+
)
|
|
175
179
|
|
|
176
180
|
.withEventEmitter(eventEmitter)
|
|
177
181
|
.withSessionManager(rpOpts.sessionManager ?? new InMemoryRPSessionManager(eventEmitter))
|
|
@@ -190,7 +194,6 @@ export async function createRPBuilder(args: {
|
|
|
190
194
|
context,
|
|
191
195
|
),
|
|
192
196
|
)
|
|
193
|
-
.withDcqlQueryLookup(getDcqlQueryLookupCallback(context))
|
|
194
197
|
.withRevocationVerification(RevocationVerification.NEVER)
|
|
195
198
|
.withPresentationVerification(getPresentationVerificationCallback(identifierOpts.idOpts, context))
|
|
196
199
|
|
|
@@ -199,12 +202,11 @@ export async function createRPBuilder(args: {
|
|
|
199
202
|
builder.withEntityId(oidfOpts.identifier, PropertyTarget.REQUEST_OBJECT)
|
|
200
203
|
} else {
|
|
201
204
|
const resolution = await context.agent.identifierManagedGet(identifierOpts.idOpts)
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
builder.withClientId(clientIdPrefixed, PropertyTarget.REQUEST_OBJECT)
|
|
205
|
+
builder
|
|
206
|
+
.withClientId(
|
|
207
|
+
resolution.issuer ?? (isManagedIdentifierDidResult(resolution) ? resolution.did : resolution.jwkThumbprint),
|
|
208
|
+
PropertyTarget.REQUEST_OBJECT,
|
|
209
|
+
)
|
|
208
210
|
}
|
|
209
211
|
|
|
210
212
|
if (hasher) {
|
|
@@ -218,6 +220,10 @@ export async function createRPBuilder(args: {
|
|
|
218
220
|
//fixme: this has been removed in the new version of did-auth-siop
|
|
219
221
|
// builder.withWellknownDIDVerifyCallback(getWellKnownDIDVerifyCallback(didOpts, context))
|
|
220
222
|
|
|
223
|
+
if (dcqlQuery) {
|
|
224
|
+
builder.withDcqlQuery(dcqlQuery)
|
|
225
|
+
}
|
|
226
|
+
|
|
221
227
|
if (rpOpts.responseRedirectUri) {
|
|
222
228
|
builder.withResponseRedirectUri(rpOpts.responseRedirectUri)
|
|
223
229
|
}
|
|
@@ -298,12 +304,3 @@ export function getSigningAlgo(type: TKeyType): SigningAlgo {
|
|
|
298
304
|
throw Error('Key type not yet supported')
|
|
299
305
|
}
|
|
300
306
|
}
|
|
301
|
-
|
|
302
|
-
export function prefixClientId(clientId: string): string {
|
|
303
|
-
// FIXME SSISDK-60
|
|
304
|
-
if (clientId.startsWith('did:')) {
|
|
305
|
-
return `${ClientIdentifierPrefix.DECENTRALIZED_IDENTIFIER}:${clientId}`
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
return clientId
|
|
309
|
-
}
|
package/src/index.ts
CHANGED
package/src/types/ISIOPv2RP.ts
CHANGED
|
@@ -2,8 +2,7 @@ import {
|
|
|
2
2
|
AuthorizationRequestPayload,
|
|
3
3
|
AuthorizationRequestState,
|
|
4
4
|
AuthorizationResponsePayload,
|
|
5
|
-
|
|
6
|
-
CallbackOpts,
|
|
5
|
+
AuthorizationResponseState,
|
|
7
6
|
ClaimPayloadCommonOpts,
|
|
8
7
|
ClientMetadataOpts,
|
|
9
8
|
IRPSessionManager,
|
|
@@ -24,14 +23,13 @@ import { ExternalIdentifierOIDFEntityIdOpts, IIdentifierResolution, ManagedIdent
|
|
|
24
23
|
import { IJwtService } from '@sphereon/ssi-sdk-ext.jwt-service'
|
|
25
24
|
import { ICredentialValidation, SchemaValidation } from '@sphereon/ssi-sdk.credential-validation'
|
|
26
25
|
import { ImDLMdoc } from '@sphereon/ssi-sdk.mdl-mdoc'
|
|
27
|
-
import {
|
|
26
|
+
import { IPDManager, VersionControlMode } from '@sphereon/ssi-sdk.pd-manager'
|
|
28
27
|
import { IPresentationExchange } from '@sphereon/ssi-sdk.presentation-exchange'
|
|
29
28
|
import { ISDJwtPlugin } from '@sphereon/ssi-sdk.sd-jwt'
|
|
30
29
|
import { AuthorizationRequestStateStatus } from '@sphereon/ssi-sdk.siopv2-oid4vp-common'
|
|
31
|
-
import { HasherSync } from '@sphereon/ssi-types'
|
|
30
|
+
import { AdditionalClaims, DcqlQueryPayload, HasherSync } from '@sphereon/ssi-types'
|
|
32
31
|
import { VerifyCallback } from '@sphereon/wellknown-dids-client'
|
|
33
|
-
import { IAgentContext, ICredentialVerifier, IDIDManager, IKeyManager, IPluginMethodMap, IResolver } from '@veramo/core'
|
|
34
|
-
import { DcqlQuery } from 'dcql'
|
|
32
|
+
import { IAgentContext, ICredentialIssuer, ICredentialVerifier, IDIDManager, IKeyManager, IPluginMethodMap, IResolver } from '@veramo/core'
|
|
35
33
|
|
|
36
34
|
import { Resolvable } from 'did-resolver'
|
|
37
35
|
import { EventEmitter } from 'events'
|
|
@@ -54,6 +52,7 @@ export interface ISIOPv2RP extends IPluginMethodMap {
|
|
|
54
52
|
siopDeleteAuthState(args: IDeleteAuthStateArgs, context: IRequiredContext): Promise<boolean>
|
|
55
53
|
siopVerifyAuthResponse(args: IVerifyAuthResponseStateArgs, context: IRequiredContext): Promise<VerifiedAuthorizationResponse>
|
|
56
54
|
siopImportDefinitions(args: ImportDefinitionsArgs, context: IRequiredContext): Promise<void>
|
|
55
|
+
|
|
57
56
|
siopGetRedirectURI(args: IGetRedirectUriArgs, context: IRequiredContext): Promise<string | undefined>
|
|
58
57
|
}
|
|
59
58
|
|
|
@@ -65,9 +64,8 @@ export interface ISiopv2RPOpts {
|
|
|
65
64
|
export interface IRPDefaultOpts extends IRPOptions {}
|
|
66
65
|
|
|
67
66
|
export interface ICreateAuthRequestArgs {
|
|
68
|
-
|
|
67
|
+
definitionId: string
|
|
69
68
|
correlationId: string
|
|
70
|
-
useQueryIdInstance?: boolean
|
|
71
69
|
responseURIType: ResponseURIType
|
|
72
70
|
responseURI: string
|
|
73
71
|
responseRedirectURI?: string
|
|
@@ -76,25 +74,24 @@ export interface ICreateAuthRequestArgs {
|
|
|
76
74
|
nonce?: string
|
|
77
75
|
state?: string
|
|
78
76
|
claims?: ClaimPayloadCommonOpts
|
|
79
|
-
callback?: CallbackOpts
|
|
80
77
|
}
|
|
81
78
|
|
|
82
79
|
export interface IGetAuthRequestStateArgs {
|
|
83
80
|
correlationId: string
|
|
84
|
-
|
|
81
|
+
definitionId: string
|
|
85
82
|
errorOnNotFound?: boolean
|
|
86
83
|
}
|
|
87
84
|
|
|
88
85
|
export interface IGetAuthResponseStateArgs {
|
|
89
86
|
correlationId: string
|
|
90
|
-
|
|
87
|
+
definitionId: string
|
|
91
88
|
errorOnNotFound?: boolean
|
|
92
89
|
progressRequestStateTo?: AuthorizationRequestStateStatus
|
|
93
90
|
includeVerifiedData?: VerifiedDataMode
|
|
94
91
|
}
|
|
95
92
|
|
|
96
93
|
export interface IUpdateRequestStateArgs {
|
|
97
|
-
|
|
94
|
+
definitionId: string
|
|
98
95
|
correlationId: string
|
|
99
96
|
state: AuthorizationRequestStateStatus
|
|
100
97
|
error?: string
|
|
@@ -102,18 +99,24 @@ export interface IUpdateRequestStateArgs {
|
|
|
102
99
|
|
|
103
100
|
export interface IDeleteAuthStateArgs {
|
|
104
101
|
correlationId: string
|
|
105
|
-
|
|
102
|
+
definitionId: string
|
|
106
103
|
}
|
|
107
104
|
|
|
108
105
|
export interface IVerifyAuthResponseStateArgs {
|
|
109
106
|
authorizationResponse: string | AuthorizationResponsePayload
|
|
110
|
-
|
|
107
|
+
definitionId?: string
|
|
111
108
|
correlationId: string
|
|
112
109
|
audience?: string
|
|
113
|
-
|
|
110
|
+
dcqlQueryPayload?: DcqlQueryPayload
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface IDefinitionPair {
|
|
114
|
+
definitionPayload?: IPresentationDefinition
|
|
115
|
+
dcqlPayload?: DcqlQueryPayload
|
|
114
116
|
}
|
|
117
|
+
|
|
115
118
|
export interface ImportDefinitionsArgs {
|
|
116
|
-
|
|
119
|
+
definitions: Array<IDefinitionPair>
|
|
117
120
|
tenantId?: string
|
|
118
121
|
version?: string
|
|
119
122
|
versionControlMode?: VersionControlMode
|
|
@@ -121,7 +124,7 @@ export interface ImportDefinitionsArgs {
|
|
|
121
124
|
|
|
122
125
|
export interface IGetRedirectUriArgs {
|
|
123
126
|
correlationId: string
|
|
124
|
-
|
|
127
|
+
definitionId?: string
|
|
125
128
|
state?: string
|
|
126
129
|
}
|
|
127
130
|
|
|
@@ -137,12 +140,11 @@ export interface IPEXDefinitionPersistArgs extends IPEXInstanceOptions {
|
|
|
137
140
|
}
|
|
138
141
|
|
|
139
142
|
export interface ISiopRPInstanceArgs {
|
|
140
|
-
|
|
141
|
-
queryId?: string
|
|
143
|
+
definitionId?: string
|
|
142
144
|
responseRedirectURI?: string
|
|
143
145
|
}
|
|
144
146
|
|
|
145
|
-
export interface IPEXInstanceOptions extends
|
|
147
|
+
export interface IPEXInstanceOptions extends IPEXOptions {
|
|
146
148
|
rpOpts?: IRPOptions
|
|
147
149
|
}
|
|
148
150
|
|
|
@@ -160,9 +162,12 @@ export interface IRPOptions {
|
|
|
160
162
|
responseRedirectUri?: string
|
|
161
163
|
}
|
|
162
164
|
|
|
163
|
-
export interface
|
|
164
|
-
queryId: string
|
|
165
|
+
export interface IPEXOptions {
|
|
165
166
|
presentationVerifyCallback?: PresentationVerificationCallback
|
|
167
|
+
// definition?: IPresentationDefinition
|
|
168
|
+
definitionId: string
|
|
169
|
+
version?: string
|
|
170
|
+
tenantId?: string
|
|
166
171
|
}
|
|
167
172
|
|
|
168
173
|
export type VerificationPolicies = {
|
|
@@ -193,11 +198,16 @@ export type CredentialOpts = {
|
|
|
193
198
|
hasher?: HasherSync
|
|
194
199
|
}
|
|
195
200
|
|
|
201
|
+
export interface AuthorizationResponseStateWithVerifiedData extends AuthorizationResponseState {
|
|
202
|
+
verifiedData?: AdditionalClaims
|
|
203
|
+
}
|
|
204
|
+
|
|
196
205
|
export type IRequiredContext = IAgentContext<
|
|
197
206
|
IResolver &
|
|
198
207
|
IDIDManager &
|
|
199
208
|
IKeyManager &
|
|
200
209
|
IIdentifierResolution &
|
|
210
|
+
ICredentialIssuer &
|
|
201
211
|
ICredentialValidation &
|
|
202
212
|
ICredentialVerifier &
|
|
203
213
|
IPresentationExchange &
|