@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth 0.34.1-feature.SSISDK.50.type.refactor.148 → 0.34.1-feature.SSISDK.57.uni.client.167
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 +323 -329
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +716 -25
- package/dist/index.d.ts +716 -25
- package/dist/index.js +315 -322
- package/dist/index.js.map +1 -1
- package/package.json +17 -17
- package/src/RPInstance.ts +6 -4
- package/src/agent/SIOPv2RP.ts +27 -25
- package/src/functions.ts +4 -4
- package/src/index.ts +1 -1
- package/src/types/ISIOPv2RP.ts +15 -17
package/src/agent/SIOPv2RP.ts
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
AuthorizationResponsePayload,
|
|
4
4
|
AuthorizationResponseState,
|
|
5
5
|
AuthorizationResponseStateStatus,
|
|
6
|
+
AuthorizationResponseStateWithVerifiedData,
|
|
6
7
|
decodeUriAsJson,
|
|
7
8
|
VerifiedAuthorizationResponse,
|
|
8
9
|
} from '@sphereon/did-auth-siop'
|
|
@@ -27,7 +28,6 @@ import {
|
|
|
27
28
|
import { IAgentPlugin } from '@veramo/core'
|
|
28
29
|
import { DcqlQuery } from 'dcql'
|
|
29
30
|
import {
|
|
30
|
-
AuthorizationResponseStateWithVerifiedData,
|
|
31
31
|
IAuthorizationRequestPayloads,
|
|
32
32
|
ICreateAuthRequestArgs,
|
|
33
33
|
IGetAuthRequestStateArgs,
|
|
@@ -46,7 +46,6 @@ import {
|
|
|
46
46
|
VerifiedDataMode,
|
|
47
47
|
} from '../index'
|
|
48
48
|
import { RPInstance } from '../RPInstance'
|
|
49
|
-
|
|
50
49
|
import { ISIOPv2RP } from '../types/ISIOPv2RP'
|
|
51
50
|
|
|
52
51
|
export class SIOPv2RP implements IAgentPlugin {
|
|
@@ -87,7 +86,10 @@ export class SIOPv2RP implements IAgentPlugin {
|
|
|
87
86
|
}
|
|
88
87
|
|
|
89
88
|
private async createAuthorizationRequestURI(createArgs: ICreateAuthRequestArgs, context: IRequiredContext): Promise<string> {
|
|
90
|
-
return await this.getRPInstance(
|
|
89
|
+
return await this.getRPInstance(
|
|
90
|
+
{ responseRedirectURI: createArgs.responseRedirectURI, ...(createArgs.useQueryIdInstance === true && { queryId: createArgs.queryId }) },
|
|
91
|
+
context,
|
|
92
|
+
)
|
|
91
93
|
.then((rp) => rp.createAuthorizationRequestURI(createArgs, context))
|
|
92
94
|
.then((URI) => URI.encodedUri)
|
|
93
95
|
}
|
|
@@ -96,20 +98,20 @@ export class SIOPv2RP implements IAgentPlugin {
|
|
|
96
98
|
createArgs: ICreateAuthRequestArgs,
|
|
97
99
|
context: IRequiredContext,
|
|
98
100
|
): Promise<IAuthorizationRequestPayloads> {
|
|
99
|
-
return await this.getRPInstance({
|
|
101
|
+
return await this.getRPInstance({ queryId: createArgs.queryId }, context)
|
|
100
102
|
.then((rp) => rp.createAuthorizationRequest(createArgs, context))
|
|
101
103
|
.then(async (request) => {
|
|
102
104
|
const authRequest: IAuthorizationRequestPayloads = {
|
|
103
105
|
authorizationRequest: request.payload,
|
|
104
106
|
requestObject: await request.requestObjectJwt(),
|
|
105
|
-
requestObjectDecoded:
|
|
107
|
+
requestObjectDecoded: request.requestObject?.getPayload(),
|
|
106
108
|
}
|
|
107
109
|
return authRequest
|
|
108
110
|
})
|
|
109
111
|
}
|
|
110
112
|
|
|
111
113
|
private async siopGetRequestState(args: IGetAuthRequestStateArgs, context: IRequiredContext): Promise<AuthorizationRequestState | undefined> {
|
|
112
|
-
return await this.getRPInstance({
|
|
114
|
+
return await this.getRPInstance({ queryId: args.queryId }, context).then((rp) =>
|
|
113
115
|
rp.get(context).then((rp) => rp.sessionManager.getRequestStateByCorrelationId(args.correlationId, args.errorOnNotFound)),
|
|
114
116
|
)
|
|
115
117
|
}
|
|
@@ -118,7 +120,7 @@ export class SIOPv2RP implements IAgentPlugin {
|
|
|
118
120
|
args: IGetAuthResponseStateArgs,
|
|
119
121
|
context: IRequiredContext,
|
|
120
122
|
): Promise<AuthorizationResponseStateWithVerifiedData | undefined> {
|
|
121
|
-
const rpInstance: RPInstance = await this.getRPInstance({
|
|
123
|
+
const rpInstance: RPInstance = await this.getRPInstance({ queryId: args.queryId }, context)
|
|
122
124
|
const authorizationResponseState: AuthorizationResponseState | undefined = await rpInstance
|
|
123
125
|
.get(context)
|
|
124
126
|
.then((rp) => rp.sessionManager.getResponseStateByCorrelationId(args.correlationId, args.errorOnNotFound))
|
|
@@ -195,10 +197,10 @@ export class SIOPv2RP implements IAgentPlugin {
|
|
|
195
197
|
: CredentialMapper.toUniformPresentation(presentationDecoded as OriginalVerifiablePresentation)
|
|
196
198
|
|
|
197
199
|
private async siopUpdateRequestState(args: IUpdateRequestStateArgs, context: IRequiredContext): Promise<AuthorizationRequestState> {
|
|
198
|
-
if (args.state !== '
|
|
199
|
-
throw Error(`Only '
|
|
200
|
+
if (args.state !== 'authorization_request_created') {
|
|
201
|
+
throw Error(`Only 'authorization_request_created' status is supported for this method at this point`)
|
|
200
202
|
}
|
|
201
|
-
return await this.getRPInstance({
|
|
203
|
+
return await this.getRPInstance({ queryId: args.queryId }, context)
|
|
202
204
|
// todo: In the SIOP library we need to update the signal method to be more like this method
|
|
203
205
|
.then((rp) =>
|
|
204
206
|
rp.get(context).then(async (rp) => {
|
|
@@ -212,7 +214,7 @@ export class SIOPv2RP implements IAgentPlugin {
|
|
|
212
214
|
}
|
|
213
215
|
|
|
214
216
|
private async siopDeleteState(args: IGetAuthResponseStateArgs, context: IRequiredContext): Promise<boolean> {
|
|
215
|
-
return await this.getRPInstance({
|
|
217
|
+
return await this.getRPInstance({ queryId: args.queryId }, context)
|
|
216
218
|
.then((rp) => rp.get(context).then((rp) => rp.sessionManager.deleteStateForCorrelationId(args.correlationId)))
|
|
217
219
|
.then(() => true)
|
|
218
220
|
}
|
|
@@ -225,7 +227,7 @@ export class SIOPv2RP implements IAgentPlugin {
|
|
|
225
227
|
typeof args.authorizationResponse === 'string'
|
|
226
228
|
? (decodeUriAsJson(args.authorizationResponse) as AuthorizationResponsePayload)
|
|
227
229
|
: args.authorizationResponse
|
|
228
|
-
return await this.getRPInstance({
|
|
230
|
+
return await this.getRPInstance({ queryId: args.queryId }, context).then((rp) =>
|
|
229
231
|
rp.get(context).then((rp) =>
|
|
230
232
|
rp.verifyAuthorizationResponse(authResponse, {
|
|
231
233
|
correlationId: args.correlationId,
|
|
@@ -257,7 +259,7 @@ export class SIOPv2RP implements IAgentPlugin {
|
|
|
257
259
|
}
|
|
258
260
|
|
|
259
261
|
private async siopGetRedirectURI(args: IGetRedirectUriArgs, context: IRequiredContext): Promise<string | undefined> {
|
|
260
|
-
const instanceId = args.
|
|
262
|
+
const instanceId = args.queryId ?? SIOPv2RP._DEFAULT_OPTS_KEY
|
|
261
263
|
if (this.instances.has(instanceId)) {
|
|
262
264
|
const rpInstance = this.instances.get(instanceId)
|
|
263
265
|
if (rpInstance !== undefined) {
|
|
@@ -272,17 +274,17 @@ export class SIOPv2RP implements IAgentPlugin {
|
|
|
272
274
|
return undefined
|
|
273
275
|
}
|
|
274
276
|
|
|
275
|
-
async getRPInstance({
|
|
276
|
-
const instanceId =
|
|
277
|
+
async getRPInstance({ queryId, responseRedirectURI }: ISiopRPInstanceArgs, context: IRequiredContext): Promise<RPInstance> {
|
|
278
|
+
const instanceId = queryId ?? SIOPv2RP._DEFAULT_OPTS_KEY
|
|
277
279
|
if (!this.instances.has(instanceId)) {
|
|
278
|
-
const instanceOpts = this.getInstanceOpts(
|
|
279
|
-
const rpOpts = await this.getRPOptions(context, {
|
|
280
|
+
const instanceOpts = this.getInstanceOpts(queryId)
|
|
281
|
+
const rpOpts = await this.getRPOptions(context, { queryId, responseRedirectURI: responseRedirectURI })
|
|
280
282
|
if (!rpOpts.identifierOpts.resolveOpts?.resolver || typeof rpOpts.identifierOpts.resolveOpts.resolver.resolve !== 'function') {
|
|
281
283
|
if (!rpOpts.identifierOpts?.resolveOpts) {
|
|
282
284
|
rpOpts.identifierOpts = { ...rpOpts.identifierOpts }
|
|
283
285
|
rpOpts.identifierOpts.resolveOpts = { ...rpOpts.identifierOpts.resolveOpts }
|
|
284
286
|
}
|
|
285
|
-
console.log('Using agent DID resolver for RP instance with definition id ' +
|
|
287
|
+
console.log('Using agent DID resolver for RP instance with definition id ' + queryId)
|
|
286
288
|
rpOpts.identifierOpts.resolveOpts.resolver = getAgentResolver(context, {
|
|
287
289
|
uniresolverResolution: true,
|
|
288
290
|
localResolution: true,
|
|
@@ -298,11 +300,11 @@ export class SIOPv2RP implements IAgentPlugin {
|
|
|
298
300
|
return rpInstance
|
|
299
301
|
}
|
|
300
302
|
|
|
301
|
-
async getRPOptions(context: IRequiredContext, opts: {
|
|
302
|
-
const {
|
|
303
|
-
const options = this.getInstanceOpts(
|
|
303
|
+
async getRPOptions(context: IRequiredContext, opts: { queryId?: string; responseRedirectURI?: string }): Promise<IRPOptions> {
|
|
304
|
+
const { queryId, responseRedirectURI: responseRedirectURI } = opts
|
|
305
|
+
const options = this.getInstanceOpts(queryId)?.rpOpts ?? this.opts.defaultOpts
|
|
304
306
|
if (!options) {
|
|
305
|
-
throw Error(`Could not get specific nor default options for definition ${
|
|
307
|
+
throw Error(`Could not get specific nor default options for definition ${queryId}`)
|
|
306
308
|
}
|
|
307
309
|
if (this.opts.defaultOpts) {
|
|
308
310
|
if (!options.identifierOpts) {
|
|
@@ -336,7 +338,7 @@ export class SIOPv2RP implements IAgentPlugin {
|
|
|
336
338
|
getInstanceOpts(definitionId?: string): IPEXInstanceOptions | undefined {
|
|
337
339
|
if (!this.opts.instanceOpts) return undefined
|
|
338
340
|
|
|
339
|
-
const instanceOpt = definitionId ? this.opts.instanceOpts.find((i) => i.
|
|
341
|
+
const instanceOpt = definitionId ? this.opts.instanceOpts.find((i) => i.queryId === definitionId) : undefined
|
|
340
342
|
|
|
341
343
|
return instanceOpt ?? this.getDefaultOptions(definitionId)
|
|
342
344
|
}
|
|
@@ -344,11 +346,11 @@ export class SIOPv2RP implements IAgentPlugin {
|
|
|
344
346
|
private getDefaultOptions(definitionId: string | undefined) {
|
|
345
347
|
if (!this.opts.instanceOpts) return undefined
|
|
346
348
|
|
|
347
|
-
const defaultOptions = this.opts.instanceOpts.find((i) => i.
|
|
349
|
+
const defaultOptions = this.opts.instanceOpts.find((i) => i.queryId === 'default')
|
|
348
350
|
if (defaultOptions) {
|
|
349
351
|
const clonedOptions = { ...defaultOptions }
|
|
350
352
|
if (definitionId !== undefined) {
|
|
351
|
-
clonedOptions.
|
|
353
|
+
clonedOptions.queryId = definitionId
|
|
352
354
|
}
|
|
353
355
|
return clonedOptions
|
|
354
356
|
}
|
package/src/functions.ts
CHANGED
|
@@ -111,11 +111,11 @@ export async function createRPBuilder(args: {
|
|
|
111
111
|
let definition: IPresentationDefinition | undefined = args.definition
|
|
112
112
|
let dcqlQuery: DcqlQuery | undefined = args.dcql
|
|
113
113
|
|
|
114
|
-
if (!definition && pexOpts && pexOpts.
|
|
114
|
+
if (!definition && pexOpts && pexOpts.queryId) {
|
|
115
115
|
const presentationDefinitionItems = await context.agent.pdmGetDefinitions({
|
|
116
116
|
filter: [
|
|
117
117
|
{
|
|
118
|
-
queryId: pexOpts.
|
|
118
|
+
queryId: pexOpts.queryId,
|
|
119
119
|
version: pexOpts.version,
|
|
120
120
|
tenantId: pexOpts.tenantId,
|
|
121
121
|
},
|
|
@@ -124,8 +124,8 @@ export async function createRPBuilder(args: {
|
|
|
124
124
|
|
|
125
125
|
if (presentationDefinitionItems.length > 0) {
|
|
126
126
|
const presentationDefinitionItem = presentationDefinitionItems[0]
|
|
127
|
-
if (!dcqlQuery
|
|
128
|
-
dcqlQuery = presentationDefinitionItem.
|
|
127
|
+
if (!dcqlQuery) {
|
|
128
|
+
dcqlQuery = presentationDefinitionItem.dcqlQuery
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
}
|
package/src/index.ts
CHANGED
package/src/types/ISIOPv2RP.ts
CHANGED
|
@@ -2,7 +2,8 @@ import {
|
|
|
2
2
|
AuthorizationRequestPayload,
|
|
3
3
|
AuthorizationRequestState,
|
|
4
4
|
AuthorizationResponsePayload,
|
|
5
|
-
|
|
5
|
+
AuthorizationResponseStateWithVerifiedData,
|
|
6
|
+
CallbackOpts,
|
|
6
7
|
ClaimPayloadCommonOpts,
|
|
7
8
|
ClientMetadataOpts,
|
|
8
9
|
IRPSessionManager,
|
|
@@ -23,11 +24,11 @@ import { ExternalIdentifierOIDFEntityIdOpts, IIdentifierResolution, ManagedIdent
|
|
|
23
24
|
import { IJwtService } from '@sphereon/ssi-sdk-ext.jwt-service'
|
|
24
25
|
import { ICredentialValidation, SchemaValidation } from '@sphereon/ssi-sdk.credential-validation'
|
|
25
26
|
import { ImDLMdoc } from '@sphereon/ssi-sdk.mdl-mdoc'
|
|
26
|
-
import { IPDManager, VersionControlMode
|
|
27
|
+
import { ImportDcqlQueryItem, 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 {
|
|
31
|
+
import { 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
|
import { DcqlQuery } from 'dcql'
|
|
@@ -53,7 +54,6 @@ export interface ISIOPv2RP extends IPluginMethodMap {
|
|
|
53
54
|
siopDeleteAuthState(args: IDeleteAuthStateArgs, context: IRequiredContext): Promise<boolean>
|
|
54
55
|
siopVerifyAuthResponse(args: IVerifyAuthResponseStateArgs, context: IRequiredContext): Promise<VerifiedAuthorizationResponse>
|
|
55
56
|
siopImportDefinitions(args: ImportDefinitionsArgs, context: IRequiredContext): Promise<void>
|
|
56
|
-
|
|
57
57
|
siopGetRedirectURI(args: IGetRedirectUriArgs, context: IRequiredContext): Promise<string | undefined>
|
|
58
58
|
}
|
|
59
59
|
|
|
@@ -65,8 +65,9 @@ export interface ISiopv2RPOpts {
|
|
|
65
65
|
export interface IRPDefaultOpts extends IRPOptions {}
|
|
66
66
|
|
|
67
67
|
export interface ICreateAuthRequestArgs {
|
|
68
|
-
|
|
68
|
+
queryId: string
|
|
69
69
|
correlationId: string
|
|
70
|
+
useQueryIdInstance?: boolean
|
|
70
71
|
responseURIType: ResponseURIType
|
|
71
72
|
responseURI: string
|
|
72
73
|
responseRedirectURI?: string
|
|
@@ -75,24 +76,25 @@ export interface ICreateAuthRequestArgs {
|
|
|
75
76
|
nonce?: string
|
|
76
77
|
state?: string
|
|
77
78
|
claims?: ClaimPayloadCommonOpts
|
|
79
|
+
callback?: CallbackOpts
|
|
78
80
|
}
|
|
79
81
|
|
|
80
82
|
export interface IGetAuthRequestStateArgs {
|
|
81
83
|
correlationId: string
|
|
82
|
-
|
|
84
|
+
queryId?: string
|
|
83
85
|
errorOnNotFound?: boolean
|
|
84
86
|
}
|
|
85
87
|
|
|
86
88
|
export interface IGetAuthResponseStateArgs {
|
|
87
89
|
correlationId: string
|
|
88
|
-
|
|
90
|
+
queryId?: string
|
|
89
91
|
errorOnNotFound?: boolean
|
|
90
92
|
progressRequestStateTo?: AuthorizationRequestStateStatus
|
|
91
93
|
includeVerifiedData?: VerifiedDataMode
|
|
92
94
|
}
|
|
93
95
|
|
|
94
96
|
export interface IUpdateRequestStateArgs {
|
|
95
|
-
|
|
97
|
+
queryId: string
|
|
96
98
|
correlationId: string
|
|
97
99
|
state: AuthorizationRequestStateStatus
|
|
98
100
|
error?: string
|
|
@@ -100,12 +102,12 @@ export interface IUpdateRequestStateArgs {
|
|
|
100
102
|
|
|
101
103
|
export interface IDeleteAuthStateArgs {
|
|
102
104
|
correlationId: string
|
|
103
|
-
|
|
105
|
+
queryId?: string
|
|
104
106
|
}
|
|
105
107
|
|
|
106
108
|
export interface IVerifyAuthResponseStateArgs {
|
|
107
109
|
authorizationResponse: string | AuthorizationResponsePayload
|
|
108
|
-
|
|
110
|
+
queryId?: string
|
|
109
111
|
correlationId: string
|
|
110
112
|
audience?: string
|
|
111
113
|
dcqlQuery?: DcqlQuery
|
|
@@ -119,7 +121,7 @@ export interface ImportDefinitionsArgs {
|
|
|
119
121
|
|
|
120
122
|
export interface IGetRedirectUriArgs {
|
|
121
123
|
correlationId: string
|
|
122
|
-
|
|
124
|
+
queryId?: string
|
|
123
125
|
state?: string
|
|
124
126
|
}
|
|
125
127
|
|
|
@@ -135,7 +137,7 @@ export interface IPEXDefinitionPersistArgs extends IPEXInstanceOptions {
|
|
|
135
137
|
}
|
|
136
138
|
|
|
137
139
|
export interface ISiopRPInstanceArgs {
|
|
138
|
-
|
|
140
|
+
queryId?: string
|
|
139
141
|
responseRedirectURI?: string
|
|
140
142
|
}
|
|
141
143
|
|
|
@@ -160,7 +162,7 @@ export interface IRPOptions {
|
|
|
160
162
|
export interface IPEXOptions {
|
|
161
163
|
presentationVerifyCallback?: PresentationVerificationCallback
|
|
162
164
|
// definition?: IPresentationDefinition
|
|
163
|
-
|
|
165
|
+
queryId: string
|
|
164
166
|
version?: string
|
|
165
167
|
tenantId?: string
|
|
166
168
|
}
|
|
@@ -193,10 +195,6 @@ export type CredentialOpts = {
|
|
|
193
195
|
hasher?: HasherSync
|
|
194
196
|
}
|
|
195
197
|
|
|
196
|
-
export interface AuthorizationResponseStateWithVerifiedData extends AuthorizationResponseState {
|
|
197
|
-
verifiedData?: AdditionalClaims
|
|
198
|
-
}
|
|
199
|
-
|
|
200
198
|
export type IRequiredContext = IAgentContext<
|
|
201
199
|
IResolver &
|
|
202
200
|
IDIDManager &
|