@sphereon/ssi-sdk.siopv2-oid4vp-rp-rest-api 0.34.1-feature.SSISDK.57.uni.client.206 → 0.34.1-feature.SSISDK.58.host.nonce.endpoint.194
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 +75 -50
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +59 -7
- package/dist/index.d.ts +59 -7
- package/dist/index.js +72 -47
- package/dist/index.js.map +1 -1
- package/package.json +17 -19
- package/src/schemas/index.ts +36 -0
- package/src/siop-api-functions.ts +15 -26
- package/src/types/types.ts +18 -9
- package/src/universal-oid4vp-api-functions.ts +24 -40
- package/src/webapp-api-functions.ts +27 -25
package/src/types/types.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IAgentContext, ICredentialVerifier } from '@veramo/core'
|
|
2
2
|
import { GenericAuthArgs, ISingleEndpointOpts } from '@sphereon/ssi-express-support'
|
|
3
|
-
import { IPDManager } from '@sphereon/ssi-sdk.pd-manager'
|
|
4
|
-
import { AuthorizationRequestStateStatus, AuthorizationResponseStateStatus } from '@sphereon/ssi-sdk.siopv2-oid4vp-common'
|
|
5
3
|
import { ISIOPv2RP } from '@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth'
|
|
4
|
+
import { IPDManager } from '@sphereon/ssi-sdk.pd-manager'
|
|
6
5
|
import { AdditionalClaims } from '@sphereon/ssi-types'
|
|
7
|
-
import {
|
|
6
|
+
import { AuthorizationRequestStateStatus, AuthorizationResponseStateStatus } from '@sphereon/ssi-sdk.siopv2-oid4vp-common'
|
|
8
7
|
import { Request, Response } from 'express'
|
|
8
|
+
import { z } from 'zod'
|
|
9
|
+
import { CreateAuthorizationRequestBodySchema, CreateAuthorizationResponseSchema } from '../schemas'
|
|
9
10
|
import { QRCodeOpts } from './QRCode.types'
|
|
10
11
|
|
|
11
12
|
export type SiopFeatures = 'rp-status' | 'siop'
|
|
@@ -35,20 +36,24 @@ export interface ICreateAuthRequestWebappEndpointOpts extends ISingleEndpointOpt
|
|
|
35
36
|
export type IRequiredPlugins = ICredentialVerifier & ISIOPv2RP & IPDManager
|
|
36
37
|
export type IRequiredContext = IAgentContext<IRequiredPlugins>
|
|
37
38
|
|
|
38
|
-
export type
|
|
39
|
+
export type CreateAuthorizationRequest = Request<Record<string, never>, any, CreateAuthorizationRequestBody, Record<string, never>>
|
|
40
|
+
|
|
41
|
+
export type CreateAuthorizationRequestBody = z.infer<typeof CreateAuthorizationRequestBodySchema>;
|
|
42
|
+
|
|
43
|
+
export type CreateAuthorizationResponse = Response<CreateAuthorizationRequestResponse>
|
|
39
44
|
|
|
40
|
-
export type
|
|
45
|
+
export type CreateAuthorizationRequestResponse = z.infer<typeof CreateAuthorizationResponseSchema>;
|
|
41
46
|
|
|
42
47
|
export type DeleteAuthorizationRequest = Request<DeleteAuthorizationRequestPathParameters, any, Record<string, any>, Record<string, any>>
|
|
43
48
|
|
|
44
49
|
export type DeleteAuthorizationRequestPathParameters = {
|
|
45
|
-
correlationId: string
|
|
50
|
+
correlationId: string;
|
|
46
51
|
}
|
|
47
52
|
|
|
48
53
|
export type GetAuthorizationRequestStatus = Request<GetAuthorizationRequestStatusPathParameters, any, Record<string, any>, Record<string, any>>
|
|
49
54
|
|
|
50
55
|
export type GetAuthorizationRequestStatusPathParameters = {
|
|
51
|
-
correlationId: string
|
|
56
|
+
correlationId: string;
|
|
52
57
|
}
|
|
53
58
|
|
|
54
59
|
export type RequestError = {
|
|
@@ -86,4 +91,8 @@ export type MultipleVpTokenDCQL = {
|
|
|
86
91
|
[key: string]: MultipleVpTokens
|
|
87
92
|
}
|
|
88
93
|
|
|
89
|
-
export type VpToken =
|
|
94
|
+
export type VpToken =
|
|
95
|
+
| SingleObjectVpTokenPE
|
|
96
|
+
| SingleStringVpTokenPE
|
|
97
|
+
| MultipleVpTokens
|
|
98
|
+
| MultipleVpTokenDCQL
|
|
@@ -1,26 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AuthorizationRequestStateStatus,
|
|
3
|
-
AuthorizationResponseStateStatus,
|
|
4
|
-
CreateAuthorizationRequest,
|
|
5
|
-
createAuthorizationRequestFromPayload,
|
|
6
|
-
CreateAuthorizationRequestPayloadSchema,
|
|
7
|
-
CreateAuthorizationResponsePayload,
|
|
8
|
-
} from '@sphereon/did-auth-siop'
|
|
1
|
+
import { AuthorizationResponseStateStatus } from '@sphereon/did-auth-siop'
|
|
9
2
|
import { checkAuth, ISingleEndpointOpts, sendErrorResponse } from '@sphereon/ssi-express-support'
|
|
10
3
|
import { uriWithBase } from '@sphereon/ssi-sdk.siopv2-oid4vp-common'
|
|
11
|
-
import { VerifiedDataMode } from '@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth'
|
|
12
4
|
import { Request, Response, Router } from 'express'
|
|
13
5
|
import uuid from 'short-uuid'
|
|
14
6
|
import { validateData } from './middleware/validationMiddleware'
|
|
7
|
+
import { CreateAuthorizationRequestBodySchema } from './schemas'
|
|
15
8
|
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
CreateAuthorizationRequest,
|
|
10
|
+
CreateAuthorizationRequestResponse,
|
|
11
|
+
CreateAuthorizationResponse,
|
|
19
12
|
DeleteAuthorizationRequest,
|
|
20
13
|
GetAuthorizationRequestStatus,
|
|
14
|
+
AuthStatusResponse,
|
|
21
15
|
ICreateAuthRequestWebappEndpointOpts,
|
|
22
16
|
IRequiredContext,
|
|
23
|
-
QRCodeOpts,
|
|
24
17
|
} from './types'
|
|
25
18
|
|
|
26
19
|
export function createAuthRequestUniversalOID4VPEndpoint(router: Router, context: IRequiredContext, opts?: ICreateAuthRequestWebappEndpointOpts) {
|
|
@@ -33,29 +26,26 @@ export function createAuthRequestUniversalOID4VPEndpoint(router: Router, context
|
|
|
33
26
|
router.post(
|
|
34
27
|
path,
|
|
35
28
|
checkAuth(opts?.endpoint),
|
|
36
|
-
validateData(
|
|
37
|
-
async (request:
|
|
29
|
+
validateData(CreateAuthorizationRequestBodySchema),
|
|
30
|
+
async (request: CreateAuthorizationRequest, response: CreateAuthorizationResponse) => {
|
|
38
31
|
try {
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
{ queryId },
|
|
48
|
-
],
|
|
49
|
-
})
|
|
32
|
+
const correlationId = request.body.correlation_id ?? uuid.uuid()
|
|
33
|
+
const qrCodeOpts = request.body.qr_code ?? opts?.qrCodeOpts
|
|
34
|
+
const queryId = request.body.query_id
|
|
35
|
+
const directPostResponseRedirectUri = request.body.direct_post_response_redirect_uri // TODO Uri not URI
|
|
36
|
+
const requestUriBase = request.body.request_uri_base
|
|
37
|
+
const callback = request.body.callback
|
|
38
|
+
|
|
39
|
+
const definitionItems = await context.agent.pdmGetDefinitions({ filter: [{ queryId }] })
|
|
50
40
|
if (definitionItems.length === 0) {
|
|
51
41
|
console.log(`No query could be found for the given id. Query id: ${queryId}`)
|
|
52
42
|
return sendErrorResponse(response, 404, { status: 404, message: 'No query could be found' })
|
|
53
43
|
}
|
|
54
44
|
|
|
55
|
-
const requestByReferenceURI = uriWithBase(`/siop/
|
|
56
|
-
baseURI:
|
|
45
|
+
const requestByReferenceURI = uriWithBase(`/siop/definitions/${queryId}/auth-requests/${correlationId}`, {
|
|
46
|
+
baseURI: requestUriBase ?? opts?.siopBaseURI,
|
|
57
47
|
})
|
|
58
|
-
const responseURI = uriWithBase(`/siop/
|
|
48
|
+
const responseURI = uriWithBase(`/siop/definitions/${queryId}/auth-responses/${correlationId}`, { baseURI: opts?.siopBaseURI })
|
|
59
49
|
|
|
60
50
|
const authRequestURI = await context.agent.siopCreateAuthRequestURI({
|
|
61
51
|
queryId,
|
|
@@ -64,8 +54,8 @@ export function createAuthRequestUniversalOID4VPEndpoint(router: Router, context
|
|
|
64
54
|
requestByReferenceURI,
|
|
65
55
|
responseURIType: 'response_uri',
|
|
66
56
|
responseURI,
|
|
67
|
-
...(
|
|
68
|
-
|
|
57
|
+
...(directPostResponseRedirectUri && { responseRedirectURI: directPostResponseRedirectUri }),
|
|
58
|
+
callback,
|
|
69
59
|
})
|
|
70
60
|
|
|
71
61
|
let qrCodeDataUri: string | undefined
|
|
@@ -73,8 +63,6 @@ export function createAuthRequestUniversalOID4VPEndpoint(router: Router, context
|
|
|
73
63
|
const { AwesomeQR } = await import('awesome-qr')
|
|
74
64
|
const qrCode = new AwesomeQR({ ...qrCodeOpts, text: authRequestURI })
|
|
75
65
|
qrCodeDataUri = `data:image/png;base64,${(await qrCode.draw())!.toString('base64')}`
|
|
76
|
-
} else {
|
|
77
|
-
qrCodeDataUri = authRequestURI
|
|
78
66
|
}
|
|
79
67
|
|
|
80
68
|
const authRequestBody = {
|
|
@@ -83,7 +71,7 @@ export function createAuthRequestUniversalOID4VPEndpoint(router: Router, context
|
|
|
83
71
|
request_uri: authRequestURI,
|
|
84
72
|
status_uri: `${uriWithBase(opts?.webappAuthStatusPath ?? `/backend/auth/status/${correlationId}`, { baseURI: opts?.webappBaseURI })}`,
|
|
85
73
|
...(qrCodeDataUri && { qr_uri: qrCodeDataUri }),
|
|
86
|
-
} satisfies
|
|
74
|
+
} satisfies CreateAuthorizationRequestResponse
|
|
87
75
|
console.log(`Auth Request URI data to send back: ${JSON.stringify(authRequestBody)}`)
|
|
88
76
|
|
|
89
77
|
return response.status(201).json(authRequestBody)
|
|
@@ -146,12 +134,8 @@ export function authStatusUniversalOID4VPEndpoint(router: Router, context: IRequ
|
|
|
146
134
|
}
|
|
147
135
|
|
|
148
136
|
let responseState
|
|
149
|
-
if (requestState.status ===
|
|
150
|
-
responseState = await context.agent.siopGetAuthResponseState({
|
|
151
|
-
correlationId,
|
|
152
|
-
errorOnNotFound: false,
|
|
153
|
-
includeVerifiedData: VerifiedDataMode.VERIFIED_PRESENTATION,
|
|
154
|
-
})
|
|
137
|
+
if (requestState.status === 'authorization_request_created') {
|
|
138
|
+
responseState = await context.agent.siopGetAuthResponseState({ correlationId, errorOnNotFound: false })
|
|
155
139
|
}
|
|
156
140
|
const overallState = responseState ?? requestState
|
|
157
141
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { AuthorizationRequestState, AuthorizationResponseStateStatus
|
|
1
|
+
import { AuthorizationRequestState, AuthorizationResponseStateStatus } from '@sphereon/did-auth-siop'
|
|
2
2
|
import { checkAuth, ISingleEndpointOpts, sendErrorResponse } from '@sphereon/ssi-express-support'
|
|
3
3
|
import { AuthStatusResponse, GenerateAuthRequestURIResponse, uriWithBase } from '@sphereon/ssi-sdk.siopv2-oid4vp-common'
|
|
4
|
-
import { VerifiedDataMode } from '@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth'
|
|
4
|
+
import { AuthorizationResponseStateWithVerifiedData, VerifiedDataMode } from '@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth'
|
|
5
5
|
import { shaHasher as defaultHasher } from '@sphereon/ssi-sdk.core'
|
|
6
6
|
import { Request, Response, Router } from 'express'
|
|
7
7
|
import uuid from 'short-uuid'
|
|
@@ -12,29 +12,29 @@ export function createAuthRequestWebappEndpoint(router: Router, context: IRequir
|
|
|
12
12
|
console.log(`createAuthRequest Webapp endpoint is disabled`)
|
|
13
13
|
return
|
|
14
14
|
}
|
|
15
|
-
const path = opts?.path ?? '/webapp/
|
|
15
|
+
const path = opts?.path ?? '/webapp/definitions/:definitionId/auth-requests'
|
|
16
16
|
router.post(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
17
17
|
try {
|
|
18
18
|
// if (!request.agent) throw Error('No agent configured')
|
|
19
|
-
const
|
|
20
|
-
if (!
|
|
21
|
-
return sendErrorResponse(response, 400, 'No
|
|
19
|
+
const definitionId = request.params.definitionId
|
|
20
|
+
if (!definitionId) {
|
|
21
|
+
return sendErrorResponse(response, 400, 'No definitionId query parameter provided')
|
|
22
22
|
}
|
|
23
23
|
const state: string = request.body.state ?? uuid.uuid()
|
|
24
24
|
const correlationId = request.body.correlationId ?? state
|
|
25
25
|
const qrCodeOpts = request.body.qrCodeOpts ?? opts?.qrCodeOpts
|
|
26
26
|
|
|
27
|
-
const requestByReferenceURI = uriWithBase(`/siop/
|
|
27
|
+
const requestByReferenceURI = uriWithBase(`/siop/definitions/${definitionId}/auth-requests/${state}`, {
|
|
28
28
|
baseURI: opts?.siopBaseURI,
|
|
29
29
|
})
|
|
30
|
-
const responseURI = uriWithBase(`/siop/
|
|
30
|
+
const responseURI = uriWithBase(`/siop/definitions/${definitionId}/auth-responses/${state}`, { baseURI: opts?.siopBaseURI })
|
|
31
31
|
// first version is for backwards compat
|
|
32
32
|
const responseRedirectURI =
|
|
33
33
|
('response_redirect_uri' in request.body && (request.body.response_redirect_uri as string | undefined)) ??
|
|
34
34
|
('responseRedirectURI' in request.body && (request.body.responseRedirectURI as string | undefined))
|
|
35
35
|
|
|
36
36
|
const authRequestURI = await context.agent.siopCreateAuthRequestURI({
|
|
37
|
-
|
|
37
|
+
definitionId,
|
|
38
38
|
correlationId,
|
|
39
39
|
state,
|
|
40
40
|
nonce: uuid.uuid(),
|
|
@@ -53,7 +53,7 @@ export function createAuthRequestWebappEndpoint(router: Router, context: IRequir
|
|
|
53
53
|
const authRequestBody: GenerateAuthRequestURIResponse = {
|
|
54
54
|
correlationId,
|
|
55
55
|
state,
|
|
56
|
-
|
|
56
|
+
definitionId,
|
|
57
57
|
authRequestURI,
|
|
58
58
|
authStatusURI: `${uriWithBase(opts?.webappAuthStatusPath ?? '/webapp/auth-status', { baseURI: opts?.webappBaseURI })}`,
|
|
59
59
|
...(qrCodeDataUri && { qrCodeDataUri }),
|
|
@@ -76,24 +76,26 @@ export function authStatusWebappEndpoint(router: Router, context: IRequiredConte
|
|
|
76
76
|
try {
|
|
77
77
|
console.log('Received auth-status request...')
|
|
78
78
|
const correlationId: string = request.body.correlationId as string
|
|
79
|
-
const
|
|
79
|
+
const definitionId: string = request.body.definitionId as string
|
|
80
80
|
|
|
81
81
|
const requestState =
|
|
82
|
-
correlationId &&
|
|
82
|
+
correlationId && definitionId
|
|
83
83
|
? await context.agent.siopGetAuthRequestState({
|
|
84
84
|
correlationId,
|
|
85
|
-
|
|
85
|
+
definitionId,
|
|
86
86
|
errorOnNotFound: false,
|
|
87
87
|
})
|
|
88
88
|
: undefined
|
|
89
|
-
if (!requestState || !
|
|
90
|
-
console.log(
|
|
89
|
+
if (!requestState || !definitionId || !correlationId) {
|
|
90
|
+
console.log(
|
|
91
|
+
`No authentication request mapping could be found for the given URL. correlation: ${correlationId}, definitionId: ${definitionId}`,
|
|
92
|
+
)
|
|
91
93
|
response.statusCode = 404
|
|
92
94
|
const statusBody: AuthStatusResponse = {
|
|
93
95
|
status: requestState ? requestState.status : 'error',
|
|
94
96
|
error: 'No authentication request mapping could be found for the given URL.',
|
|
95
97
|
correlationId,
|
|
96
|
-
|
|
98
|
+
definitionId,
|
|
97
99
|
lastUpdated: requestState ? requestState.lastUpdated : Date.now(),
|
|
98
100
|
}
|
|
99
101
|
return response.json(statusBody)
|
|
@@ -105,10 +107,10 @@ export function authStatusWebappEndpoint(router: Router, context: IRequiredConte
|
|
|
105
107
|
}
|
|
106
108
|
|
|
107
109
|
let responseState
|
|
108
|
-
if (requestState.status === '
|
|
110
|
+
if (requestState.status === 'sent') {
|
|
109
111
|
responseState = (await context.agent.siopGetAuthResponseState({
|
|
110
112
|
correlationId,
|
|
111
|
-
|
|
113
|
+
definitionId,
|
|
112
114
|
includeVerifiedData: includeVerifiedData,
|
|
113
115
|
errorOnNotFound: false,
|
|
114
116
|
})) as AuthorizationResponseStateWithVerifiedData
|
|
@@ -119,7 +121,7 @@ export function authStatusWebappEndpoint(router: Router, context: IRequiredConte
|
|
|
119
121
|
status: overallState.status,
|
|
120
122
|
...(overallState.error ? { error: overallState.error?.message } : {}),
|
|
121
123
|
correlationId,
|
|
122
|
-
|
|
124
|
+
definitionId,
|
|
123
125
|
lastUpdated: overallState.lastUpdated,
|
|
124
126
|
...(responseState && responseState.status === AuthorizationResponseStateStatus.VERIFIED
|
|
125
127
|
? {
|
|
@@ -146,17 +148,17 @@ export function removeAuthRequestStateWebappEndpoint(router: Router, context: IR
|
|
|
146
148
|
console.log(`removeAuthStatus Webapp endpoint is disabled`)
|
|
147
149
|
return
|
|
148
150
|
}
|
|
149
|
-
const path = opts?.path ?? '/webapp/
|
|
151
|
+
const path = opts?.path ?? '/webapp/definitions/:definitionId/auth-requests/:correlationId'
|
|
150
152
|
router.delete(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
151
153
|
try {
|
|
152
154
|
const correlationId: string = request.params.correlationId
|
|
153
|
-
const
|
|
154
|
-
if (!correlationId || !
|
|
155
|
-
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId},
|
|
155
|
+
const definitionId: string = request.params.definitionId
|
|
156
|
+
if (!correlationId || !definitionId) {
|
|
157
|
+
console.log(`No authorization request could be found for the given url. correlationId: ${correlationId}, definitionId: ${definitionId}`)
|
|
156
158
|
return sendErrorResponse(response, 404, 'No authorization request could be found')
|
|
157
159
|
}
|
|
158
160
|
response.statusCode = 200
|
|
159
|
-
return response.json(await context.agent.siopDeleteAuthState({
|
|
161
|
+
return response.json(await context.agent.siopDeleteAuthState({ definitionId, correlationId }))
|
|
160
162
|
} catch (error) {
|
|
161
163
|
return sendErrorResponse(response, 500, error.message, error)
|
|
162
164
|
}
|
|
@@ -168,7 +170,7 @@ export function getDefinitionsEndpoint(router: Router, context: IRequiredContext
|
|
|
168
170
|
console.log(`getDefinitions Webapp endpoint is disabled`)
|
|
169
171
|
return
|
|
170
172
|
}
|
|
171
|
-
const path = opts?.path ?? '/webapp/
|
|
173
|
+
const path = opts?.path ?? '/webapp/definitions'
|
|
172
174
|
router.get(path, checkAuth(opts?.endpoint), async (request: Request, response: Response) => {
|
|
173
175
|
try {
|
|
174
176
|
const definitions = await context.agent.pdmGetDefinitions()
|