@pagopa/io-wallet-oauth2 1.5.8 → 2.0.0-apt
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.d.mts +1182 -1397
- package/dist/index.d.ts +1182 -1397
- package/dist/index.js +697 -708
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +651 -605
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -6
package/dist/index.js
CHANGED
|
@@ -34,12 +34,9 @@ __export(index_exports, {
|
|
|
34
34
|
CreateTokenDPoPError: () => CreateTokenDPoPError,
|
|
35
35
|
CreateTokenResponseError: () => CreateTokenResponseError,
|
|
36
36
|
FetchTokenResponseError: () => FetchTokenResponseError,
|
|
37
|
-
HashAlgorithm: () => import_oauth216.HashAlgorithm,
|
|
38
37
|
IT_WALLET_CLIENT_ATTESTATION_POP_ALLOWED_ALG_VALUES: () => IT_WALLET_CLIENT_ATTESTATION_POP_ALLOWED_ALG_VALUES,
|
|
39
|
-
MAX_JTI_LENGTH: () => MAX_JTI_LENGTH,
|
|
40
38
|
MrtdPopError: () => MrtdPopError,
|
|
41
39
|
Oauth2Error: () => Oauth2Error,
|
|
42
|
-
Oauth2JwtParseError: () => import_oauth216.Oauth2JwtParseError,
|
|
43
40
|
PkceCodeChallengeMethod: () => PkceCodeChallengeMethod,
|
|
44
41
|
PushedAuthorizationRequestError: () => PushedAuthorizationRequestError,
|
|
45
42
|
SupportedClientAuthenticationMethod: () => SupportedClientAuthenticationMethod,
|
|
@@ -54,11 +51,11 @@ __export(index_exports, {
|
|
|
54
51
|
createPushedAuthorizationRequest: () => createPushedAuthorizationRequest,
|
|
55
52
|
createTokenDPoP: () => createTokenDPoP,
|
|
56
53
|
createTokenRequest: () => createTokenRequest,
|
|
54
|
+
createTokenRequestAPTITUDE: () => createTokenRequestAPTITUDE,
|
|
55
|
+
createTokenRequestV1_4: () => createTokenRequestV1_4,
|
|
57
56
|
createWalletAttestationJwtV1_0: () => createWalletAttestationJwt,
|
|
58
57
|
createWalletAttestationJwtV1_3: () => createWalletAttestationJwt2,
|
|
59
58
|
createWalletAttestationJwtV1_4: () => createWalletAttestationJwt3,
|
|
60
|
-
decodeJwt: () => decodeJwt,
|
|
61
|
-
decodeJwtHeader: () => decodeJwtHeader,
|
|
62
59
|
extractClientAttestationJwtsFromHeaders: () => extractClientAttestationJwtsFromHeaders,
|
|
63
60
|
extractDpopJwtFromHeaders: () => extractDpopJwtFromHeaders,
|
|
64
61
|
fetchJarRequestObject: () => fetchJarRequestObject,
|
|
@@ -73,12 +70,12 @@ __export(index_exports, {
|
|
|
73
70
|
isPushedAuthorizationRequestSigned: () => isPushedAuthorizationRequestSigned,
|
|
74
71
|
isPushedAuthorizationRequestUnsigned: () => isPushedAuthorizationRequestUnsigned,
|
|
75
72
|
jwtAuthorizationRequestJwtHeaderTyp: () => jwtAuthorizationRequestJwtHeaderTyp,
|
|
76
|
-
jwtHeaderFromJwtSigner: () => jwtHeaderFromJwtSigner,
|
|
77
73
|
parseAccessTokenRequest: () => parseAccessTokenRequest,
|
|
78
74
|
parseAuthorizationRequest: () => parseAuthorizationRequest,
|
|
79
75
|
parseJarRequest: () => parseJarRequest,
|
|
80
76
|
parseMrtdChallenge: () => parseMrtdChallenge,
|
|
81
77
|
parsePushedAuthorizationRequest: () => parsePushedAuthorizationRequest,
|
|
78
|
+
preAuthorizedCodeGrantIdentifier: () => preAuthorizedCodeGrantIdentifier,
|
|
82
79
|
refreshTokenGrantIdentifier: () => refreshTokenGrantIdentifier,
|
|
83
80
|
signedAuthorizationRequestJwtHeaderTyp: () => signedAuthorizationRequestJwtHeaderTyp,
|
|
84
81
|
toURLSearchParams: () => toURLSearchParams,
|
|
@@ -88,7 +85,6 @@ __export(index_exports, {
|
|
|
88
85
|
verifyClientAttestation: () => verifyClientAttestation,
|
|
89
86
|
verifyClientAttestationPopJwt: () => verifyClientAttestationPopJwt,
|
|
90
87
|
verifyJarRequest: () => verifyJarRequest,
|
|
91
|
-
verifyJwt: () => import_oauth216.verifyJwt,
|
|
92
88
|
verifyMrtdChallenge: () => verifyMrtdChallenge,
|
|
93
89
|
verifyPkce: () => verifyPkce,
|
|
94
90
|
verifyPushedAuthorizationRequest: () => verifyPushedAuthorizationRequest,
|
|
@@ -100,14 +96,12 @@ __export(index_exports, {
|
|
|
100
96
|
zAccessTokenProfileJwtHeader: () => zAccessTokenProfileJwtHeader,
|
|
101
97
|
zAccessTokenProfileJwtPayload: () => zAccessTokenProfileJwtPayload,
|
|
102
98
|
zAccessTokenRequest: () => zAccessTokenRequest,
|
|
99
|
+
zAccessTokenRequestAPTITUDE: () => zAccessTokenRequestAPTITUDE,
|
|
103
100
|
zAccessTokenResponse: () => zAccessTokenResponse,
|
|
104
|
-
zAlgValueNotNone: () => zAlgValueNotNone,
|
|
105
101
|
zAuthorizationCodeGrantIdentifier: () => zAuthorizationCodeGrantIdentifier,
|
|
102
|
+
zAuthorizationCodeTokenRequest: () => zAuthorizationCodeTokenRequest,
|
|
106
103
|
zAuthorizationRequestV1_0: () => zAuthorizationRequestV1_0,
|
|
107
104
|
zAuthorizationRequestV1_3: () => zAuthorizationRequestV1_3,
|
|
108
|
-
zCertificateChain: () => zCertificateChain,
|
|
109
|
-
zCompactJwe: () => zCompactJwe2,
|
|
110
|
-
zCompactJwt: () => zCompactJwt,
|
|
111
105
|
zDpopJwtHeader: () => zDpopJwtHeader,
|
|
112
106
|
zDpopJwtPayload: () => zDpopJwtPayload,
|
|
113
107
|
zItWalletClientAttestationPopJwtAlg: () => zItWalletClientAttestationPopJwtAlg,
|
|
@@ -117,11 +111,6 @@ __export(index_exports, {
|
|
|
117
111
|
zJarAuthorizationRequest: () => zJarAuthorizationRequest,
|
|
118
112
|
zJarRequestObjectHeader: () => zJarRequestObjectHeader,
|
|
119
113
|
zJarRequestObjectPayload: () => zJarRequestObjectPayload,
|
|
120
|
-
zJwk: () => zJwk,
|
|
121
|
-
zJwkSet: () => zJwkSet,
|
|
122
|
-
zJwtConfirmationPayload: () => zJwtConfirmationPayload,
|
|
123
|
-
zJwtHeader: () => zJwtHeader,
|
|
124
|
-
zJwtPayload: () => zJwtPayload,
|
|
125
114
|
zMrtdChallengeJwtHeader: () => zMrtdChallengeJwtHeader,
|
|
126
115
|
zMrtdChallengeJwtPayload: () => zMrtdChallengeJwtPayload,
|
|
127
116
|
zMrtdPopInitResponseJwtHeader: () => zMrtdPopInitResponseJwtHeader,
|
|
@@ -129,6 +118,8 @@ __export(index_exports, {
|
|
|
129
118
|
zMrtdPopVerifyResponse: () => zMrtdPopVerifyResponse,
|
|
130
119
|
zMrtdValidationJwtHeader: () => zMrtdValidationJwtHeader,
|
|
131
120
|
zMrtdValidationJwtPayload: () => zMrtdValidationJwtPayload,
|
|
121
|
+
zPreAuthorizedCodeGrantIdentifier: () => zPreAuthorizedCodeGrantIdentifier,
|
|
122
|
+
zPreAuthorizedCodeTokenRequest: () => zPreAuthorizedCodeTokenRequest,
|
|
132
123
|
zPushedAuthorizationRequestSigned: () => zPushedAuthorizationRequestSigned,
|
|
133
124
|
zPushedAuthorizationRequestUnsignedV1_0: () => zPushedAuthorizationRequestUnsignedV1_0,
|
|
134
125
|
zPushedAuthorizationRequestUnsignedV1_3: () => zPushedAuthorizationRequestUnsignedV1_3,
|
|
@@ -136,8 +127,8 @@ __export(index_exports, {
|
|
|
136
127
|
zRefreshTokenGrantIdentifier: () => zRefreshTokenGrantIdentifier,
|
|
137
128
|
zRefreshTokenProfileJwtHeader: () => zRefreshTokenProfileJwtHeader,
|
|
138
129
|
zRefreshTokenProfileJwtPayload: () => zRefreshTokenProfileJwtPayload,
|
|
130
|
+
zRefreshTokenTokenRequest: () => zRefreshTokenTokenRequest,
|
|
139
131
|
zSignedAuthorizationRequestJwtHeaderTyp: () => zSignedAuthorizationRequestJwtHeaderTyp,
|
|
140
|
-
zTrustChain: () => zTrustChain,
|
|
141
132
|
zWalletAttestationJwtHeaderV1_0: () => zWalletAttestationJwtHeaderV1_0,
|
|
142
133
|
zWalletAttestationJwtHeaderV1_3: () => zWalletAttestationJwtHeaderV1_3,
|
|
143
134
|
zWalletAttestationJwtHeaderV1_4: () => zWalletAttestationJwtHeaderV1_4,
|
|
@@ -151,178 +142,68 @@ __export(index_exports, {
|
|
|
151
142
|
module.exports = __toCommonJS(index_exports);
|
|
152
143
|
|
|
153
144
|
// src/access-token/create-token-request.ts
|
|
154
|
-
var createTokenRequest = async (options) => ({
|
|
155
|
-
...options.additionalRequestPayload,
|
|
156
|
-
code: options.authorizationCode,
|
|
157
|
-
code_verifier: options.pkceCodeVerifier,
|
|
158
|
-
grant_type: "authorization_code",
|
|
159
|
-
redirect_uri: options.redirectUri
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
// src/access-token/create-token-response.ts
|
|
163
|
-
var import_oauth22 = require("@openid4vc/oauth2");
|
|
164
|
-
var import_io_wallet_utils2 = require("@pagopa/io-wallet-utils");
|
|
165
|
-
|
|
166
|
-
// src/common/jwt/decode-jwt-header.ts
|
|
167
|
-
var import_oauth2 = require("@openid4vc/oauth2");
|
|
168
145
|
var import_io_wallet_utils = require("@pagopa/io-wallet-utils");
|
|
169
146
|
|
|
170
|
-
// src/
|
|
171
|
-
var
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
var
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
var
|
|
178
|
-
var
|
|
179
|
-
var
|
|
180
|
-
var zAlgValueNotNone = import_zod.default.string().refine((alg) => alg !== "none", { message: `alg value may not be 'none'` });
|
|
181
|
-
|
|
182
|
-
// src/common/jwk/z-jwk.ts
|
|
183
|
-
var zJwk = import_zod2.default.looseObject({
|
|
184
|
-
alg: import_zod2.default.optional(import_zod2.default.string()),
|
|
185
|
-
crv: import_zod2.default.optional(import_zod2.default.string()),
|
|
186
|
-
d: import_zod2.default.optional(import_zod2.default.string()),
|
|
187
|
-
dp: import_zod2.default.optional(import_zod2.default.string()),
|
|
188
|
-
dq: import_zod2.default.optional(import_zod2.default.string()),
|
|
189
|
-
e: import_zod2.default.optional(import_zod2.default.string()),
|
|
190
|
-
ext: import_zod2.default.optional(import_zod2.default.boolean()),
|
|
191
|
-
k: import_zod2.default.optional(import_zod2.default.string()),
|
|
192
|
-
key_ops: import_zod2.default.optional(import_zod2.default.array(import_zod2.default.string())),
|
|
193
|
-
kid: import_zod2.default.optional(import_zod2.default.string()),
|
|
194
|
-
kty: import_zod2.default.string(),
|
|
195
|
-
n: import_zod2.default.optional(import_zod2.default.string()),
|
|
196
|
-
oth: import_zod2.default.optional(
|
|
197
|
-
import_zod2.default.array(
|
|
198
|
-
import_zod2.default.looseObject({
|
|
199
|
-
d: import_zod2.default.optional(import_zod2.default.string()),
|
|
200
|
-
r: import_zod2.default.optional(import_zod2.default.string()),
|
|
201
|
-
t: import_zod2.default.optional(import_zod2.default.string())
|
|
202
|
-
})
|
|
203
|
-
)
|
|
204
|
-
),
|
|
205
|
-
p: import_zod2.default.optional(import_zod2.default.string()),
|
|
206
|
-
q: import_zod2.default.optional(import_zod2.default.string()),
|
|
207
|
-
qi: import_zod2.default.optional(import_zod2.default.string()),
|
|
208
|
-
use: import_zod2.default.optional(import_zod2.default.string()),
|
|
209
|
-
x: import_zod2.default.optional(import_zod2.default.string()),
|
|
210
|
-
x5c: import_zod2.default.optional(zCertificateChain),
|
|
211
|
-
x5t: import_zod2.default.optional(import_zod2.default.string()),
|
|
212
|
-
"x5t#S256": import_zod2.default.optional(import_zod2.default.string()),
|
|
213
|
-
x5u: import_zod2.default.optional(import_zod2.default.string()),
|
|
214
|
-
y: import_zod2.default.optional(import_zod2.default.string())
|
|
215
|
-
});
|
|
216
|
-
var zJwkSet = import_zod2.default.looseObject({ keys: import_zod2.default.array(zJwk) });
|
|
217
|
-
|
|
218
|
-
// src/common/jwt/z-jwt.ts
|
|
219
|
-
var MAX_JTI_LENGTH = 256;
|
|
220
|
-
var zCompactJwt = import_zod3.default.string().regex(/^([a-zA-Z0-9-_]+)\.([a-zA-Z0-9-_]+)\.([a-zA-Z0-9-_]+)$/, {
|
|
221
|
-
message: "Not a valid compact jwt"
|
|
222
|
-
});
|
|
223
|
-
var zJwtConfirmationPayload = import_zod3.default.looseObject({
|
|
224
|
-
// RFC9449. jwk thumbprint of the dpop public key to which the access token is bound
|
|
225
|
-
jkt: import_zod3.default.string().optional(),
|
|
226
|
-
jwk: zJwk.optional()
|
|
227
|
-
});
|
|
228
|
-
var zJwtPayload = import_zod3.default.looseObject({
|
|
229
|
-
aud: import_zod3.default.string().optional(),
|
|
230
|
-
cnf: zJwtConfirmationPayload.optional(),
|
|
231
|
-
exp: import_zod3.default.number().int().optional(),
|
|
232
|
-
iat: import_zod3.default.number().int().optional(),
|
|
233
|
-
iss: import_zod3.default.string().optional(),
|
|
234
|
-
jti: import_zod3.default.string().max(MAX_JTI_LENGTH).optional(),
|
|
235
|
-
nbf: import_zod3.default.number().int().optional(),
|
|
236
|
-
nonce: import_zod3.default.string().optional(),
|
|
237
|
-
// Reserved for status parameters
|
|
238
|
-
status: import_zod3.default.record(import_zod3.default.string(), import_zod3.default.any()).optional(),
|
|
239
|
-
// Reserved for OpenID Federation
|
|
240
|
-
trust_chain: zTrustChain.optional()
|
|
241
|
-
});
|
|
242
|
-
var zJwtHeader = import_zod3.default.looseObject({
|
|
243
|
-
alg: zAlgValueNotNone,
|
|
244
|
-
jwk: zJwk.optional(),
|
|
245
|
-
kid: import_zod3.default.string().optional(),
|
|
246
|
-
// Reserved for OpenID Federation
|
|
247
|
-
trust_chain: zTrustChain.optional(),
|
|
248
|
-
typ: import_zod3.default.string().optional(),
|
|
249
|
-
x5c: zCertificateChain.optional()
|
|
250
|
-
});
|
|
147
|
+
// src/access-token/z-grant-type.ts
|
|
148
|
+
var import_zod = require("zod");
|
|
149
|
+
var zAuthorizationCodeGrantIdentifier = import_zod.z.literal("authorization_code");
|
|
150
|
+
var authorizationCodeGrantIdentifier = zAuthorizationCodeGrantIdentifier.value;
|
|
151
|
+
var zPreAuthorizedCodeGrantIdentifier = import_zod.z.literal(
|
|
152
|
+
"urn:ietf:params:oauth:grant-type:pre-authorized_code"
|
|
153
|
+
);
|
|
154
|
+
var preAuthorizedCodeGrantIdentifier = zPreAuthorizedCodeGrantIdentifier.value;
|
|
155
|
+
var zRefreshTokenGrantIdentifier = import_zod.z.literal("refresh_token");
|
|
156
|
+
var refreshTokenGrantIdentifier = zRefreshTokenGrantIdentifier.value;
|
|
251
157
|
|
|
252
|
-
// src/
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
if (jwtParts.length <= 2) {
|
|
256
|
-
throw new import_oauth2.Oauth2JwtParseError(
|
|
257
|
-
(0, import_io_wallet_utils.formatError)(
|
|
258
|
-
"Unable to decode because Jwt is not a valid!",
|
|
259
|
-
options.errorMessagePrefix
|
|
260
|
-
)
|
|
261
|
-
);
|
|
262
|
-
}
|
|
263
|
-
const [headerPart] = jwtParts;
|
|
264
|
-
let headerJson;
|
|
265
|
-
try {
|
|
266
|
-
headerJson = (0, import_io_wallet_utils.stringToJsonWithErrorHandling)(
|
|
267
|
-
(0, import_io_wallet_utils.encodeToUtf8String)((0, import_io_wallet_utils.decodeBase64)(headerPart)),
|
|
268
|
-
(0, import_io_wallet_utils.formatError)(
|
|
269
|
-
"Unable to parse jwt header to JSON",
|
|
270
|
-
options.errorMessagePrefix
|
|
271
|
-
)
|
|
272
|
-
);
|
|
273
|
-
} catch (error) {
|
|
274
|
-
throw new import_oauth2.Oauth2JwtParseError(
|
|
275
|
-
(0, import_io_wallet_utils.formatError)(
|
|
276
|
-
`Error parsing JWT. ${error instanceof Error ? error.message : ""}`,
|
|
277
|
-
options.errorMessagePrefix
|
|
278
|
-
)
|
|
279
|
-
);
|
|
280
|
-
}
|
|
281
|
-
const header = (0, import_io_wallet_utils.parseWithErrorHandling)(
|
|
282
|
-
options.headerSchema ?? zJwtHeader,
|
|
283
|
-
headerJson,
|
|
284
|
-
(0, import_io_wallet_utils.formatError)("Invalid JWT header", options.errorMessagePrefix)
|
|
285
|
-
);
|
|
286
|
-
return {
|
|
287
|
-
header
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
function jwtHeaderFromJwtSigner(signer) {
|
|
291
|
-
if (signer.method === "did") {
|
|
292
|
-
return {
|
|
293
|
-
alg: signer.alg,
|
|
294
|
-
kid: signer.didUrl
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
if (signer.method === "federation") {
|
|
298
|
-
return {
|
|
299
|
-
alg: signer.alg,
|
|
300
|
-
kid: signer.kid,
|
|
301
|
-
trust_chain: signer.trustChain
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
if (signer.method === "jwk") {
|
|
158
|
+
// src/access-token/create-token-request.ts
|
|
159
|
+
var createTokenRequestV1_4 = (options) => {
|
|
160
|
+
if (options.grantType === refreshTokenGrantIdentifier) {
|
|
305
161
|
return {
|
|
306
|
-
|
|
307
|
-
|
|
162
|
+
...options.additionalRequestPayload,
|
|
163
|
+
grant_type: refreshTokenGrantIdentifier,
|
|
164
|
+
refresh_token: options.refreshToken,
|
|
165
|
+
scope: options.scope
|
|
308
166
|
};
|
|
309
167
|
}
|
|
310
|
-
|
|
168
|
+
return {
|
|
169
|
+
...options.additionalRequestPayload,
|
|
170
|
+
code: options.authorizationCode,
|
|
171
|
+
code_verifier: options.pkceCodeVerifier,
|
|
172
|
+
grant_type: authorizationCodeGrantIdentifier,
|
|
173
|
+
redirect_uri: options.redirectUri
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
function createTokenRequestAPTITUDE(options) {
|
|
177
|
+
if (options.grantType === preAuthorizedCodeGrantIdentifier) {
|
|
311
178
|
return {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
179
|
+
...options.additionalRequestPayload,
|
|
180
|
+
grant_type: preAuthorizedCodeGrantIdentifier,
|
|
181
|
+
"pre-authorized_code": options.preAuthorizedCode,
|
|
182
|
+
tx_code: options.txCode
|
|
316
183
|
};
|
|
317
184
|
}
|
|
318
|
-
return
|
|
185
|
+
return createTokenRequestV1_4(options);
|
|
186
|
+
}
|
|
187
|
+
var dispatchCreateTokenRequest = (0, import_io_wallet_utils.createVersionDispatcher)({
|
|
188
|
+
[import_io_wallet_utils.ItWalletSpecsVersion.APTITUDE]: (o) => createTokenRequestAPTITUDE(o),
|
|
189
|
+
[import_io_wallet_utils.ItWalletSpecsVersion.V1_0]: (o) => createTokenRequestV1_4(o),
|
|
190
|
+
[import_io_wallet_utils.ItWalletSpecsVersion.V1_3]: (o) => createTokenRequestV1_4(o),
|
|
191
|
+
[import_io_wallet_utils.ItWalletSpecsVersion.V1_4]: (o) => createTokenRequestV1_4(o)
|
|
192
|
+
});
|
|
193
|
+
function createTokenRequest(options) {
|
|
194
|
+
return dispatchCreateTokenRequest(options);
|
|
319
195
|
}
|
|
320
196
|
|
|
197
|
+
// src/access-token/create-token-response.ts
|
|
198
|
+
var import_io_wallet_utils3 = require("@pagopa/io-wallet-utils");
|
|
199
|
+
|
|
321
200
|
// src/errors.ts
|
|
322
201
|
var Oauth2Error = class extends Error {
|
|
323
202
|
statusCode;
|
|
324
203
|
constructor(message, options) {
|
|
325
|
-
|
|
204
|
+
const errorMessage = message ?? "Unknown error occurred.";
|
|
205
|
+
const causeMessage = options?.cause instanceof Error ? ` ${options.cause.message}` : options?.cause ? ` ${String(options.cause)}` : "";
|
|
206
|
+
super(`${errorMessage}${causeMessage}`, options);
|
|
326
207
|
this.name = "Oauth2Error";
|
|
327
208
|
this.statusCode = options?.statusCode;
|
|
328
209
|
}
|
|
@@ -373,70 +254,83 @@ var ClientAttestationError = class extends Oauth2Error {
|
|
|
373
254
|
};
|
|
374
255
|
|
|
375
256
|
// src/access-token/z-token.ts
|
|
376
|
-
var
|
|
377
|
-
var
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
257
|
+
var import_io_wallet_utils2 = require("@pagopa/io-wallet-utils");
|
|
258
|
+
var import_zod2 = require("zod");
|
|
259
|
+
var zPreAuthorizedCodeTokenRequest = import_zod2.z.object({
|
|
260
|
+
grant_type: zPreAuthorizedCodeGrantIdentifier,
|
|
261
|
+
"pre-authorized_code": import_zod2.z.string().nonempty(),
|
|
262
|
+
tx_code: import_zod2.z.string().optional()
|
|
263
|
+
});
|
|
264
|
+
var zAuthorizationCodeTokenRequest = import_zod2.z.object({
|
|
265
|
+
code: import_zod2.z.string().nonempty(),
|
|
266
|
+
code_verifier: import_zod2.z.string().nonempty(),
|
|
267
|
+
grant_type: zAuthorizationCodeGrantIdentifier,
|
|
268
|
+
redirect_uri: import_zod2.z.string().nonempty()
|
|
269
|
+
});
|
|
270
|
+
var zRefreshTokenTokenRequest = import_zod2.z.object({
|
|
271
|
+
grant_type: zRefreshTokenGrantIdentifier,
|
|
272
|
+
refresh_token: import_zod2.z.string().nonempty(),
|
|
273
|
+
scope: import_zod2.z.string().optional()
|
|
274
|
+
});
|
|
275
|
+
var zAccessTokenRequest = import_zod2.z.discriminatedUnion("grant_type", [
|
|
276
|
+
zAuthorizationCodeTokenRequest,
|
|
277
|
+
zRefreshTokenTokenRequest
|
|
278
|
+
]);
|
|
279
|
+
var zAccessTokenRequestAPTITUDE = import_zod2.z.discriminatedUnion("grant_type", [
|
|
280
|
+
zAuthorizationCodeTokenRequest,
|
|
281
|
+
zRefreshTokenTokenRequest,
|
|
282
|
+
zPreAuthorizedCodeTokenRequest
|
|
389
283
|
]);
|
|
390
|
-
var zAccessTokenResponse =
|
|
391
|
-
access_token:
|
|
392
|
-
authorization_details:
|
|
393
|
-
|
|
394
|
-
credential_configuration_id:
|
|
395
|
-
credential_identifiers:
|
|
396
|
-
type:
|
|
284
|
+
var zAccessTokenResponse = import_zod2.z.looseObject({
|
|
285
|
+
access_token: import_zod2.z.string(),
|
|
286
|
+
authorization_details: import_zod2.z.array(
|
|
287
|
+
import_zod2.z.looseObject({
|
|
288
|
+
credential_configuration_id: import_zod2.z.optional(import_zod2.z.string()),
|
|
289
|
+
credential_identifiers: import_zod2.z.optional(import_zod2.z.array(import_zod2.z.string())),
|
|
290
|
+
type: import_zod2.z.literal("openid_credential")
|
|
397
291
|
})
|
|
398
292
|
).optional(),
|
|
399
|
-
expires_in:
|
|
400
|
-
refresh_token:
|
|
401
|
-
token_type:
|
|
293
|
+
expires_in: import_zod2.z.optional(import_zod2.z.number().int()),
|
|
294
|
+
refresh_token: import_zod2.z.optional(import_zod2.z.string()),
|
|
295
|
+
token_type: import_zod2.z.union([import_zod2.z.literal("Bearer"), import_zod2.z.literal("DPoP")])
|
|
402
296
|
});
|
|
403
|
-
var zAccessTokenProfileJwtHeader =
|
|
404
|
-
...zJwtHeader.shape,
|
|
405
|
-
typ:
|
|
297
|
+
var zAccessTokenProfileJwtHeader = import_zod2.z.looseObject({
|
|
298
|
+
...import_io_wallet_utils2.zJwtHeader.shape,
|
|
299
|
+
typ: import_zod2.z.enum(["application/at+jwt", "at+jwt"])
|
|
406
300
|
});
|
|
407
|
-
var zAccessTokenProfileJwtPayload =
|
|
408
|
-
...zJwtPayload.shape,
|
|
409
|
-
aud:
|
|
410
|
-
client_id:
|
|
411
|
-
cnf:
|
|
412
|
-
jkt:
|
|
301
|
+
var zAccessTokenProfileJwtPayload = import_zod2.z.looseObject({
|
|
302
|
+
...import_io_wallet_utils2.zJwtPayload.shape,
|
|
303
|
+
aud: import_zod2.z.string(),
|
|
304
|
+
client_id: import_zod2.z.string(),
|
|
305
|
+
cnf: import_zod2.z.object({
|
|
306
|
+
jkt: import_zod2.z.string()
|
|
413
307
|
}).optional(),
|
|
414
|
-
exp:
|
|
415
|
-
iat:
|
|
416
|
-
iss:
|
|
417
|
-
jti:
|
|
418
|
-
nbf:
|
|
419
|
-
scope:
|
|
420
|
-
sub:
|
|
308
|
+
exp: import_zod2.z.number(),
|
|
309
|
+
iat: import_zod2.z.number(),
|
|
310
|
+
iss: import_zod2.z.string(),
|
|
311
|
+
jti: import_zod2.z.string().max(import_io_wallet_utils2.MAX_JTI_LENGTH),
|
|
312
|
+
nbf: import_zod2.z.number().optional(),
|
|
313
|
+
scope: import_zod2.z.string().optional(),
|
|
314
|
+
sub: import_zod2.z.string()
|
|
421
315
|
});
|
|
422
|
-
var zRefreshTokenProfileJwtHeader =
|
|
423
|
-
...zJwtHeader.shape,
|
|
424
|
-
kid:
|
|
425
|
-
typ:
|
|
316
|
+
var zRefreshTokenProfileJwtHeader = import_zod2.z.looseObject({
|
|
317
|
+
...import_io_wallet_utils2.zJwtHeader.shape,
|
|
318
|
+
kid: import_zod2.z.string(),
|
|
319
|
+
typ: import_zod2.z.literal("rt+jwt")
|
|
426
320
|
});
|
|
427
|
-
var zRefreshTokenProfileJwtPayload =
|
|
428
|
-
...zJwtPayload.shape,
|
|
429
|
-
aud:
|
|
430
|
-
client_id:
|
|
431
|
-
cnf:
|
|
432
|
-
jkt:
|
|
321
|
+
var zRefreshTokenProfileJwtPayload = import_zod2.z.looseObject({
|
|
322
|
+
...import_io_wallet_utils2.zJwtPayload.shape,
|
|
323
|
+
aud: import_zod2.z.string(),
|
|
324
|
+
client_id: import_zod2.z.string(),
|
|
325
|
+
cnf: import_zod2.z.object({
|
|
326
|
+
jkt: import_zod2.z.string()
|
|
433
327
|
}),
|
|
434
|
-
exp:
|
|
435
|
-
iat:
|
|
436
|
-
iss:
|
|
437
|
-
jti:
|
|
438
|
-
nbf:
|
|
439
|
-
sub:
|
|
328
|
+
exp: import_zod2.z.number().int(),
|
|
329
|
+
iat: import_zod2.z.number().int(),
|
|
330
|
+
iss: import_zod2.z.string(),
|
|
331
|
+
jti: import_zod2.z.string().max(import_io_wallet_utils2.MAX_JTI_LENGTH),
|
|
332
|
+
nbf: import_zod2.z.number().int(),
|
|
333
|
+
sub: import_zod2.z.string()
|
|
440
334
|
});
|
|
441
335
|
|
|
442
336
|
// src/access-token/create-token-response.ts
|
|
@@ -465,7 +359,7 @@ function resolveRefreshTokenKid(signer) {
|
|
|
465
359
|
}
|
|
466
360
|
return void 0;
|
|
467
361
|
}
|
|
468
|
-
async function
|
|
362
|
+
async function createAccessTokenResponseV1_4(options) {
|
|
469
363
|
try {
|
|
470
364
|
const now = options.now ?? /* @__PURE__ */ new Date();
|
|
471
365
|
if (options.tokenType === "DPoP" && !options.dpop) {
|
|
@@ -483,26 +377,26 @@ async function createAccessTokenResponse(options) {
|
|
|
483
377
|
`refreshTokenExpiresInSeconds (${options.refreshTokenExpiresInSeconds}) must be greater than expiresInSeconds (${options.expiresInSeconds}) so the Refresh Token remains usable after the Access Token expires.`
|
|
484
378
|
);
|
|
485
379
|
}
|
|
486
|
-
const dpopJkt = options.dpop ? await (0,
|
|
487
|
-
hashAlgorithm:
|
|
380
|
+
const dpopJkt = options.dpop ? await (0, import_io_wallet_utils3.calculateJwkThumbprint)({
|
|
381
|
+
hashAlgorithm: import_io_wallet_utils3.HashAlgorithm.Sha256,
|
|
488
382
|
hashCallback: options.callbacks.hash,
|
|
489
383
|
jwk: options.dpop.jwk
|
|
490
384
|
}) : void 0;
|
|
491
|
-
const accessTokenExpiresAt = (0,
|
|
385
|
+
const accessTokenExpiresAt = (0, import_io_wallet_utils3.addSecondsToDate)(
|
|
492
386
|
now,
|
|
493
387
|
options.expiresInSeconds
|
|
494
388
|
);
|
|
495
|
-
const header = (0,
|
|
496
|
-
...jwtHeaderFromJwtSigner(options.signer),
|
|
389
|
+
const header = (0, import_io_wallet_utils3.parseWithErrorHandling)(zAccessTokenProfileJwtHeader, {
|
|
390
|
+
...(0, import_io_wallet_utils3.jwtHeaderFromJwtSigner)(options.signer),
|
|
497
391
|
typ: "at+jwt"
|
|
498
392
|
});
|
|
499
|
-
const payload = (0,
|
|
393
|
+
const payload = (0, import_io_wallet_utils3.parseWithErrorHandling)(zAccessTokenProfileJwtPayload, {
|
|
500
394
|
...options.additionalPayload,
|
|
501
395
|
aud: options.audience,
|
|
502
396
|
client_id: options.clientId,
|
|
503
397
|
cnf: dpopJkt ? { jkt: dpopJkt } : void 0,
|
|
504
|
-
exp: (0,
|
|
505
|
-
iat: (0,
|
|
398
|
+
exp: (0, import_io_wallet_utils3.dateToSeconds)(accessTokenExpiresAt),
|
|
399
|
+
iat: (0, import_io_wallet_utils3.dateToSeconds)(now),
|
|
506
400
|
iss: options.authorizationServer,
|
|
507
401
|
jti: await generateUuidV4(options.callbacks.generateRandom),
|
|
508
402
|
nbf: options.nbf,
|
|
@@ -521,7 +415,7 @@ async function createAccessTokenResponse(options) {
|
|
|
521
415
|
"Unable to resolve a kid for the Refresh Token JOSE header. Provide signer.kid or a publicJwk.kid."
|
|
522
416
|
);
|
|
523
417
|
}
|
|
524
|
-
const refreshTokenHeader = (0,
|
|
418
|
+
const refreshTokenHeader = (0, import_io_wallet_utils3.parseWithErrorHandling)(
|
|
525
419
|
zRefreshTokenProfileJwtHeader,
|
|
526
420
|
{
|
|
527
421
|
alg: options.signer.alg,
|
|
@@ -529,19 +423,19 @@ async function createAccessTokenResponse(options) {
|
|
|
529
423
|
typ: "rt+jwt"
|
|
530
424
|
}
|
|
531
425
|
);
|
|
532
|
-
const refreshTokenPayload = (0,
|
|
426
|
+
const refreshTokenPayload = (0, import_io_wallet_utils3.parseWithErrorHandling)(
|
|
533
427
|
zRefreshTokenProfileJwtPayload,
|
|
534
428
|
{
|
|
535
429
|
aud: options.authorizationServer,
|
|
536
430
|
client_id: options.clientId,
|
|
537
431
|
cnf: { jkt: dpopJkt },
|
|
538
|
-
exp: (0,
|
|
539
|
-
(0,
|
|
432
|
+
exp: (0, import_io_wallet_utils3.dateToSeconds)(
|
|
433
|
+
(0, import_io_wallet_utils3.addSecondsToDate)(now, options.refreshTokenExpiresInSeconds)
|
|
540
434
|
),
|
|
541
|
-
iat: (0,
|
|
435
|
+
iat: (0, import_io_wallet_utils3.dateToSeconds)(now),
|
|
542
436
|
iss: options.authorizationServer,
|
|
543
437
|
jti: await generateUuidV4(options.callbacks.generateRandom),
|
|
544
|
-
nbf: (0,
|
|
438
|
+
nbf: (0, import_io_wallet_utils3.dateToSeconds)(accessTokenExpiresAt),
|
|
545
439
|
sub: options.subject
|
|
546
440
|
}
|
|
547
441
|
);
|
|
@@ -554,7 +448,7 @@ async function createAccessTokenResponse(options) {
|
|
|
554
448
|
);
|
|
555
449
|
refreshToken = refreshTokenSignResult.jwt;
|
|
556
450
|
}
|
|
557
|
-
const accessTokenResponse = (0,
|
|
451
|
+
const accessTokenResponse = (0, import_io_wallet_utils3.parseWithErrorHandling)(zAccessTokenResponse, {
|
|
558
452
|
...options.additionalPayload,
|
|
559
453
|
access_token: jwt,
|
|
560
454
|
expires_in: options.expiresInSeconds,
|
|
@@ -571,30 +465,39 @@ async function createAccessTokenResponse(options) {
|
|
|
571
465
|
);
|
|
572
466
|
}
|
|
573
467
|
}
|
|
468
|
+
var dispatchCreateAccessTokenResponse = (0, import_io_wallet_utils3.createVersionDispatcher)({
|
|
469
|
+
[import_io_wallet_utils3.ItWalletSpecsVersion.APTITUDE]: (o) => createAccessTokenResponseV1_4(o),
|
|
470
|
+
[import_io_wallet_utils3.ItWalletSpecsVersion.V1_0]: (o) => createAccessTokenResponseV1_4(o),
|
|
471
|
+
[import_io_wallet_utils3.ItWalletSpecsVersion.V1_3]: (o) => createAccessTokenResponseV1_4(o),
|
|
472
|
+
[import_io_wallet_utils3.ItWalletSpecsVersion.V1_4]: (o) => createAccessTokenResponseV1_4(o)
|
|
473
|
+
});
|
|
474
|
+
function createAccessTokenResponse(options) {
|
|
475
|
+
return dispatchCreateAccessTokenResponse(options);
|
|
476
|
+
}
|
|
574
477
|
|
|
575
478
|
// src/access-token/fetch-token-response.ts
|
|
576
|
-
var
|
|
577
|
-
async function
|
|
479
|
+
var import_io_wallet_utils4 = require("@pagopa/io-wallet-utils");
|
|
480
|
+
async function fetchTokenResponseV1_4(options) {
|
|
578
481
|
try {
|
|
579
|
-
const fetch = (0,
|
|
482
|
+
const fetch = (0, import_io_wallet_utils4.createFetcher)(options.callbacks.fetch);
|
|
580
483
|
const tokenResponse = await fetch(options.accessTokenEndpoint, {
|
|
581
484
|
body: toURLSearchParams(options.accessTokenRequest),
|
|
582
485
|
headers: {
|
|
583
|
-
[
|
|
584
|
-
[
|
|
585
|
-
[
|
|
586
|
-
[
|
|
486
|
+
[import_io_wallet_utils4.HEADERS.CONTENT_TYPE]: import_io_wallet_utils4.CONTENT_TYPES.FORM_URLENCODED,
|
|
487
|
+
[import_io_wallet_utils4.HEADERS.DPOP]: options.dPoP,
|
|
488
|
+
[import_io_wallet_utils4.HEADERS.OAUTH_CLIENT_ATTESTATION]: options.walletAttestation,
|
|
489
|
+
[import_io_wallet_utils4.HEADERS.OAUTH_CLIENT_ATTESTATION_POP]: options.clientAttestationDPoP
|
|
587
490
|
},
|
|
588
491
|
method: "POST"
|
|
589
492
|
});
|
|
590
|
-
await (0,
|
|
591
|
-
return (0,
|
|
493
|
+
await (0, import_io_wallet_utils4.hasStatusOrThrow)(200, import_io_wallet_utils4.UnexpectedStatusCodeError)(tokenResponse);
|
|
494
|
+
return (0, import_io_wallet_utils4.parseWithErrorHandling)(
|
|
592
495
|
zAccessTokenResponse,
|
|
593
496
|
await tokenResponse.json(),
|
|
594
497
|
"Failed to parse token response"
|
|
595
498
|
);
|
|
596
499
|
} catch (error) {
|
|
597
|
-
if (error instanceof
|
|
500
|
+
if (error instanceof import_io_wallet_utils4.UnexpectedStatusCodeError || error instanceof import_io_wallet_utils4.ValidationError) {
|
|
598
501
|
throw error;
|
|
599
502
|
}
|
|
600
503
|
throw new FetchTokenResponseError(
|
|
@@ -613,135 +516,83 @@ function toURLSearchParams(data) {
|
|
|
613
516
|
});
|
|
614
517
|
return params;
|
|
615
518
|
}
|
|
519
|
+
var dispatchFetchTokenResponse = (0, import_io_wallet_utils4.createVersionDispatcher)({
|
|
520
|
+
[import_io_wallet_utils4.ItWalletSpecsVersion.APTITUDE]: (o) => fetchTokenResponseV1_4(o),
|
|
521
|
+
[import_io_wallet_utils4.ItWalletSpecsVersion.V1_0]: (o) => fetchTokenResponseV1_4(
|
|
522
|
+
o
|
|
523
|
+
),
|
|
524
|
+
[import_io_wallet_utils4.ItWalletSpecsVersion.V1_3]: (o) => fetchTokenResponseV1_4(
|
|
525
|
+
o
|
|
526
|
+
),
|
|
527
|
+
[import_io_wallet_utils4.ItWalletSpecsVersion.V1_4]: (o) => fetchTokenResponseV1_4(
|
|
528
|
+
o
|
|
529
|
+
)
|
|
530
|
+
});
|
|
531
|
+
function fetchTokenResponse(options) {
|
|
532
|
+
return dispatchFetchTokenResponse(options);
|
|
533
|
+
}
|
|
616
534
|
|
|
617
535
|
// src/access-token/parse-token-request.ts
|
|
618
|
-
var
|
|
536
|
+
var import_io_wallet_utils12 = require("@pagopa/io-wallet-utils");
|
|
619
537
|
|
|
620
538
|
// src/client-attestation/wallet-attestation.ts
|
|
621
|
-
var
|
|
622
|
-
var import_io_wallet_utils5 = require("@pagopa/io-wallet-utils");
|
|
539
|
+
var import_io_wallet_utils9 = require("@pagopa/io-wallet-utils");
|
|
623
540
|
|
|
624
541
|
// src/client-attestation/types.ts
|
|
625
|
-
var
|
|
626
|
-
var zOauthClientAttestationHeader =
|
|
542
|
+
var import_zod3 = __toESM(require("zod"));
|
|
543
|
+
var zOauthClientAttestationHeader = import_zod3.default.literal(
|
|
627
544
|
"OAuth-Client-Attestation"
|
|
628
545
|
);
|
|
629
546
|
var oauthClientAttestationHeader = zOauthClientAttestationHeader.value;
|
|
630
|
-
var zOauthClientAttestationPopHeader =
|
|
547
|
+
var zOauthClientAttestationPopHeader = import_zod3.default.literal(
|
|
631
548
|
"OAuth-Client-Attestation-PoP"
|
|
632
549
|
);
|
|
633
550
|
var oauthClientAttestationPopHeader = zOauthClientAttestationPopHeader.value;
|
|
634
551
|
|
|
635
552
|
// src/client-attestation/verify-wallet-attestation-jwt-base.ts
|
|
636
|
-
var
|
|
637
|
-
|
|
638
|
-
// src/common/jwt/decode-jwt.ts
|
|
639
|
-
var import_oauth23 = require("@openid4vc/oauth2");
|
|
640
|
-
var import_io_wallet_utils4 = require("@pagopa/io-wallet-utils");
|
|
641
|
-
function decodeJwt(options) {
|
|
642
|
-
const jwtParts = options.jwt.split(".");
|
|
643
|
-
if (jwtParts.length !== 3) {
|
|
644
|
-
throw new import_oauth23.Oauth2JwtParseError(
|
|
645
|
-
(0, import_io_wallet_utils4.formatError)(
|
|
646
|
-
"Unable to decode because Jwt is not a valid!",
|
|
647
|
-
options.errorMessagePrefix
|
|
648
|
-
)
|
|
649
|
-
);
|
|
650
|
-
}
|
|
651
|
-
let payloadJson;
|
|
652
|
-
try {
|
|
653
|
-
const payloadPart = jwtParts[1];
|
|
654
|
-
if (payloadPart === void 0) {
|
|
655
|
-
throw new import_oauth23.Oauth2JwtParseError(
|
|
656
|
-
(0, import_io_wallet_utils4.formatError)(
|
|
657
|
-
"Unable to decode because Jwt is not a valid!",
|
|
658
|
-
options.errorMessagePrefix
|
|
659
|
-
)
|
|
660
|
-
);
|
|
661
|
-
}
|
|
662
|
-
payloadJson = (0, import_io_wallet_utils4.stringToJsonWithErrorHandling)(
|
|
663
|
-
(0, import_io_wallet_utils4.encodeToUtf8String)((0, import_io_wallet_utils4.decodeBase64)(payloadPart)),
|
|
664
|
-
(0, import_io_wallet_utils4.formatError)(
|
|
665
|
-
"Unable to parse jwt payload to JSON",
|
|
666
|
-
options.errorMessagePrefix
|
|
667
|
-
)
|
|
668
|
-
);
|
|
669
|
-
} catch (error) {
|
|
670
|
-
throw new import_oauth23.Oauth2JwtParseError(
|
|
671
|
-
(0, import_io_wallet_utils4.formatError)(
|
|
672
|
-
`Error parsing JWT. ${error instanceof Error ? error.message : ""}`,
|
|
673
|
-
options.errorMessagePrefix
|
|
674
|
-
)
|
|
675
|
-
);
|
|
676
|
-
}
|
|
677
|
-
const signaturePart = jwtParts[2];
|
|
678
|
-
if (signaturePart === void 0) {
|
|
679
|
-
throw new import_oauth23.Oauth2JwtParseError(
|
|
680
|
-
(0, import_io_wallet_utils4.formatError)(
|
|
681
|
-
"Unable to decode because Jwt is not a valid!",
|
|
682
|
-
options.errorMessagePrefix
|
|
683
|
-
)
|
|
684
|
-
);
|
|
685
|
-
}
|
|
686
|
-
const { header } = decodeJwtHeader({
|
|
687
|
-
errorMessagePrefix: options.errorMessagePrefix,
|
|
688
|
-
headerSchema: options.headerSchema,
|
|
689
|
-
jwt: options.jwt
|
|
690
|
-
});
|
|
691
|
-
const payload = (0, import_io_wallet_utils4.parseWithErrorHandling)(
|
|
692
|
-
options.payloadSchema ?? zJwtPayload,
|
|
693
|
-
payloadJson,
|
|
694
|
-
(0, import_io_wallet_utils4.formatError)("Invalid JWT payload", options.errorMessagePrefix)
|
|
695
|
-
);
|
|
696
|
-
return {
|
|
697
|
-
header,
|
|
698
|
-
payload,
|
|
699
|
-
signature: signaturePart
|
|
700
|
-
};
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
// src/client-attestation/verify-wallet-attestation-jwt-base.ts
|
|
553
|
+
var import_io_wallet_utils5 = require("@pagopa/io-wallet-utils");
|
|
704
554
|
async function verifyWalletAttestationBase(options, headerSchema, payloadSchema) {
|
|
705
|
-
const { header, payload } = decodeJwt({
|
|
555
|
+
const { header, payload } = (0, import_io_wallet_utils5.decodeJwt)({
|
|
706
556
|
errorMessagePrefix: "Error decoding wallet attestation JWT:",
|
|
707
557
|
headerSchema,
|
|
708
558
|
jwt: options.walletAttestationJwt,
|
|
709
559
|
payloadSchema
|
|
710
560
|
});
|
|
711
|
-
const { signer } = await (0,
|
|
561
|
+
const { signer } = await (0, import_io_wallet_utils5.verifyJwt)({
|
|
712
562
|
compact: options.walletAttestationJwt,
|
|
713
563
|
errorMessage: "wallet attestation verification failed.",
|
|
714
564
|
header,
|
|
715
565
|
now: options.now,
|
|
716
566
|
payload,
|
|
717
|
-
signer: (0,
|
|
567
|
+
signer: (0, import_io_wallet_utils5.jwtSignerFromJwt)({ header, payload }),
|
|
718
568
|
verifyJwtCallback: options.callbacks.verifyJwt
|
|
719
569
|
});
|
|
720
570
|
return { header, payload, signer };
|
|
721
571
|
}
|
|
722
572
|
|
|
723
573
|
// src/client-attestation/v1.0/z-wallet-attestation.ts
|
|
724
|
-
var
|
|
725
|
-
var
|
|
726
|
-
|
|
727
|
-
|
|
574
|
+
var import_io_wallet_utils6 = require("@pagopa/io-wallet-utils");
|
|
575
|
+
var import_zod4 = require("zod");
|
|
576
|
+
var zWalletAttestationJwtHeaderV1_0 = import_zod4.z.looseObject({
|
|
577
|
+
...import_io_wallet_utils6.zJwtHeader.shape,
|
|
578
|
+
trust_chain: import_io_wallet_utils6.zTrustChain,
|
|
728
579
|
// REQUIRED in v1.0
|
|
729
|
-
typ:
|
|
580
|
+
typ: import_zod4.z.literal("oauth-client-attestation+jwt")
|
|
730
581
|
});
|
|
731
|
-
var zWalletAttestationJwtPayloadV1_0 =
|
|
732
|
-
...zJwtPayload.shape,
|
|
733
|
-
aal:
|
|
734
|
-
cnf:
|
|
735
|
-
jwk: zJwk
|
|
582
|
+
var zWalletAttestationJwtPayloadV1_0 = import_zod4.z.looseObject({
|
|
583
|
+
...import_io_wallet_utils6.zJwtPayload.shape,
|
|
584
|
+
aal: import_zod4.z.string(),
|
|
585
|
+
cnf: import_zod4.z.object({
|
|
586
|
+
jwk: import_io_wallet_utils6.zJwk
|
|
736
587
|
}),
|
|
737
|
-
exp:
|
|
738
|
-
iat:
|
|
739
|
-
iss:
|
|
740
|
-
sub:
|
|
741
|
-
wallet_link:
|
|
742
|
-
wallet_name:
|
|
588
|
+
exp: import_zod4.z.number(),
|
|
589
|
+
iat: import_zod4.z.number(),
|
|
590
|
+
iss: import_zod4.z.string(),
|
|
591
|
+
sub: import_zod4.z.string(),
|
|
592
|
+
wallet_link: import_zod4.z.url().optional(),
|
|
593
|
+
wallet_name: import_zod4.z.string().optional()
|
|
743
594
|
});
|
|
744
|
-
var zWalletAttestationJwtV1_0 =
|
|
595
|
+
var zWalletAttestationJwtV1_0 = import_zod4.z.string().min(1);
|
|
745
596
|
|
|
746
597
|
// src/client-attestation/v1.0/verify-wallet-attestation-jwt.ts
|
|
747
598
|
async function verifyWalletAttestationJwt(options) {
|
|
@@ -753,37 +604,38 @@ async function verifyWalletAttestationJwt(options) {
|
|
|
753
604
|
}
|
|
754
605
|
|
|
755
606
|
// src/client-attestation/v1.3/z-wallet-attestation.ts
|
|
756
|
-
var
|
|
757
|
-
var
|
|
758
|
-
|
|
759
|
-
|
|
607
|
+
var import_io_wallet_utils7 = require("@pagopa/io-wallet-utils");
|
|
608
|
+
var import_zod5 = require("zod");
|
|
609
|
+
var zWalletAttestationJwtHeaderV1_3 = import_zod5.z.looseObject({
|
|
610
|
+
...import_io_wallet_utils7.zJwtHeader.shape,
|
|
611
|
+
trust_chain: import_io_wallet_utils7.zTrustChain.optional(),
|
|
760
612
|
// OPTIONAL in v1.3
|
|
761
|
-
typ:
|
|
762
|
-
x5c: zCertificateChain
|
|
613
|
+
typ: import_zod5.z.literal("oauth-client-attestation+jwt"),
|
|
614
|
+
x5c: import_io_wallet_utils7.zCertificateChain
|
|
763
615
|
// REQUIRED in v1.3
|
|
764
616
|
});
|
|
765
|
-
var zWalletAttestationJwtPayloadV1_3 =
|
|
766
|
-
...zJwtPayload.shape,
|
|
767
|
-
cnf:
|
|
768
|
-
jwk: zJwk
|
|
617
|
+
var zWalletAttestationJwtPayloadV1_3 = import_zod5.z.looseObject({
|
|
618
|
+
...import_io_wallet_utils7.zJwtPayload.shape,
|
|
619
|
+
cnf: import_zod5.z.object({
|
|
620
|
+
jwk: import_io_wallet_utils7.zJwk
|
|
769
621
|
}),
|
|
770
|
-
exp:
|
|
771
|
-
iat:
|
|
772
|
-
iss:
|
|
773
|
-
nbf:
|
|
622
|
+
exp: import_zod5.z.number(),
|
|
623
|
+
iat: import_zod5.z.number(),
|
|
624
|
+
iss: import_zod5.z.string(),
|
|
625
|
+
nbf: import_zod5.z.number().optional(),
|
|
774
626
|
// NEW in v1.3
|
|
775
|
-
status:
|
|
776
|
-
status_list:
|
|
777
|
-
idx:
|
|
778
|
-
uri:
|
|
627
|
+
status: import_zod5.z.object({
|
|
628
|
+
status_list: import_zod5.z.object({
|
|
629
|
+
idx: import_zod5.z.number().int(),
|
|
630
|
+
uri: import_zod5.z.string()
|
|
779
631
|
})
|
|
780
632
|
}).optional(),
|
|
781
633
|
// NEW in v1.3 - status object for revocation
|
|
782
|
-
sub:
|
|
783
|
-
wallet_link:
|
|
784
|
-
wallet_name:
|
|
634
|
+
sub: import_zod5.z.string(),
|
|
635
|
+
wallet_link: import_zod5.z.url().optional(),
|
|
636
|
+
wallet_name: import_zod5.z.string().optional()
|
|
785
637
|
});
|
|
786
|
-
var zWalletAttestationJwtV1_3 =
|
|
638
|
+
var zWalletAttestationJwtV1_3 = import_zod5.z.string().min(1);
|
|
787
639
|
|
|
788
640
|
// src/client-attestation/v1.3/verify-wallet-attestation-jwt.ts
|
|
789
641
|
async function verifyWalletAttestationJwt2(options) {
|
|
@@ -795,28 +647,29 @@ async function verifyWalletAttestationJwt2(options) {
|
|
|
795
647
|
}
|
|
796
648
|
|
|
797
649
|
// src/client-attestation/v1.4/z-wallet-attestation.ts
|
|
798
|
-
var
|
|
799
|
-
var
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
650
|
+
var import_io_wallet_utils8 = require("@pagopa/io-wallet-utils");
|
|
651
|
+
var import_zod6 = require("zod");
|
|
652
|
+
var zWalletAttestationJwtHeaderV1_4 = import_zod6.z.looseObject({
|
|
653
|
+
...import_io_wallet_utils8.zJwtHeader.shape,
|
|
654
|
+
kid: import_zod6.z.string(),
|
|
655
|
+
trust_chain: import_io_wallet_utils8.zTrustChain.optional(),
|
|
656
|
+
typ: import_zod6.z.literal("oauth-client-attestation+jwt"),
|
|
657
|
+
x5c: import_io_wallet_utils8.zCertificateChain
|
|
805
658
|
});
|
|
806
|
-
var zWalletAttestationJwtPayloadV1_4 =
|
|
807
|
-
...zJwtPayload.shape,
|
|
808
|
-
cnf:
|
|
809
|
-
jwk: zJwk
|
|
659
|
+
var zWalletAttestationJwtPayloadV1_4 = import_zod6.z.looseObject({
|
|
660
|
+
...import_io_wallet_utils8.zJwtPayload.shape,
|
|
661
|
+
cnf: import_zod6.z.object({
|
|
662
|
+
jwk: import_io_wallet_utils8.zJwk
|
|
810
663
|
}),
|
|
811
|
-
exp:
|
|
812
|
-
iat:
|
|
813
|
-
iss:
|
|
814
|
-
nbf:
|
|
815
|
-
sub:
|
|
816
|
-
wallet_link:
|
|
817
|
-
wallet_name:
|
|
664
|
+
exp: import_zod6.z.number().int(),
|
|
665
|
+
iat: import_zod6.z.number().int(),
|
|
666
|
+
iss: import_zod6.z.string(),
|
|
667
|
+
nbf: import_zod6.z.number().optional(),
|
|
668
|
+
sub: import_zod6.z.string(),
|
|
669
|
+
wallet_link: import_zod6.z.url(),
|
|
670
|
+
wallet_name: import_zod6.z.string()
|
|
818
671
|
});
|
|
819
|
-
var zWalletAttestationJwtV1_4 =
|
|
672
|
+
var zWalletAttestationJwtV1_4 = import_zod6.z.string().min(1);
|
|
820
673
|
|
|
821
674
|
// src/client-attestation/v1.4/verify-wallet-attestation-jwt.ts
|
|
822
675
|
async function verifyWalletAttestationJwt3(options) {
|
|
@@ -828,10 +681,11 @@ async function verifyWalletAttestationJwt3(options) {
|
|
|
828
681
|
}
|
|
829
682
|
|
|
830
683
|
// src/client-attestation/wallet-attestation.ts
|
|
831
|
-
var dispatchVerifyWalletAttestationJwt = (0,
|
|
832
|
-
[
|
|
833
|
-
[
|
|
834
|
-
[
|
|
684
|
+
var dispatchVerifyWalletAttestationJwt = (0, import_io_wallet_utils9.createVersionDispatcher)({
|
|
685
|
+
[import_io_wallet_utils9.ItWalletSpecsVersion.APTITUDE]: (o) => verifyWalletAttestationJwt3(o),
|
|
686
|
+
[import_io_wallet_utils9.ItWalletSpecsVersion.V1_0]: (o) => verifyWalletAttestationJwt(o),
|
|
687
|
+
[import_io_wallet_utils9.ItWalletSpecsVersion.V1_3]: (o) => verifyWalletAttestationJwt2(o),
|
|
688
|
+
[import_io_wallet_utils9.ItWalletSpecsVersion.V1_4]: (o) => verifyWalletAttestationJwt3(o)
|
|
835
689
|
});
|
|
836
690
|
async function verifyWalletAttestationJwt4(options) {
|
|
837
691
|
return dispatchVerifyWalletAttestationJwt(options);
|
|
@@ -847,7 +701,7 @@ function extractClientAttestationJwtsFromHeaders(headers) {
|
|
|
847
701
|
if (!walletAttestationHeader || !clientAttestationPopHeader) {
|
|
848
702
|
return { valid: false };
|
|
849
703
|
}
|
|
850
|
-
if (!
|
|
704
|
+
if (!import_io_wallet_utils9.zCompactJwt.safeParse(walletAttestationHeader).success || !import_io_wallet_utils9.zCompactJwt.safeParse(clientAttestationPopHeader).success) {
|
|
851
705
|
return { valid: false };
|
|
852
706
|
}
|
|
853
707
|
return {
|
|
@@ -858,8 +712,7 @@ function extractClientAttestationJwtsFromHeaders(headers) {
|
|
|
858
712
|
}
|
|
859
713
|
|
|
860
714
|
// src/token-dpop/create-token-dpop.ts
|
|
861
|
-
var
|
|
862
|
-
var import_io_wallet_utils7 = require("@pagopa/io-wallet-utils");
|
|
715
|
+
var import_io_wallet_utils11 = require("@pagopa/io-wallet-utils");
|
|
863
716
|
var import_js_base64 = require("js-base64");
|
|
864
717
|
|
|
865
718
|
// src/token-dpop/dpop-utils.ts
|
|
@@ -871,29 +724,29 @@ var htuFromRequestUrl = (requestUrl) => {
|
|
|
871
724
|
};
|
|
872
725
|
|
|
873
726
|
// src/token-dpop/z-dpop.ts
|
|
874
|
-
var
|
|
875
|
-
var
|
|
876
|
-
var zDpopJwtPayload =
|
|
877
|
-
...zJwtPayload.shape,
|
|
878
|
-
ath:
|
|
879
|
-
htm:
|
|
880
|
-
htu:
|
|
881
|
-
iat:
|
|
882
|
-
jti:
|
|
727
|
+
var import_io_wallet_utils10 = require("@pagopa/io-wallet-utils");
|
|
728
|
+
var import_zod7 = __toESM(require("zod"));
|
|
729
|
+
var zDpopJwtPayload = import_zod7.default.looseObject({
|
|
730
|
+
...import_io_wallet_utils10.zJwtPayload.shape,
|
|
731
|
+
ath: import_zod7.default.optional(import_zod7.default.string()),
|
|
732
|
+
htm: import_io_wallet_utils10.zHttpMethod,
|
|
733
|
+
htu: import_zod7.default.url(),
|
|
734
|
+
iat: import_zod7.default.number().int().nonnegative(),
|
|
735
|
+
jti: import_zod7.default.string().max(import_io_wallet_utils10.MAX_JTI_LENGTH)
|
|
883
736
|
});
|
|
884
|
-
var zDpopJwtHeader =
|
|
885
|
-
...zJwtHeader.shape,
|
|
886
|
-
jwk: zJwk,
|
|
887
|
-
typ:
|
|
737
|
+
var zDpopJwtHeader = import_zod7.default.looseObject({
|
|
738
|
+
...import_io_wallet_utils10.zJwtHeader.shape,
|
|
739
|
+
jwk: import_io_wallet_utils10.zJwk,
|
|
740
|
+
typ: import_zod7.default.literal("dpop+jwt")
|
|
888
741
|
});
|
|
889
742
|
|
|
890
743
|
// src/token-dpop/create-token-dpop.ts
|
|
891
744
|
async function createTokenDPoP(options) {
|
|
892
745
|
try {
|
|
893
|
-
const ath = options.accessToken ? (0,
|
|
746
|
+
const ath = options.accessToken ? (0, import_io_wallet_utils11.encodeToBase64Url)(
|
|
894
747
|
await options.callbacks.hash(
|
|
895
|
-
(0,
|
|
896
|
-
|
|
748
|
+
(0, import_io_wallet_utils11.decodeUtf8String)(options.accessToken),
|
|
749
|
+
import_io_wallet_utils11.HashAlgorithm.Sha256
|
|
897
750
|
)
|
|
898
751
|
) : void 0;
|
|
899
752
|
const jti = options.jti ?? (options.callbacks.generateRandom ? import_js_base64.Base64.fromUint8Array(
|
|
@@ -905,16 +758,16 @@ async function createTokenDPoP(options) {
|
|
|
905
758
|
"Error: neither a default jti nor a generateRandom callback have been provided"
|
|
906
759
|
);
|
|
907
760
|
}
|
|
908
|
-
const header = (0,
|
|
761
|
+
const header = (0, import_io_wallet_utils11.parseWithErrorHandling)(zDpopJwtHeader, {
|
|
909
762
|
alg: options.signer.alg,
|
|
910
763
|
jwk: options.signer.publicJwk,
|
|
911
764
|
typ: "dpop+jwt"
|
|
912
765
|
});
|
|
913
|
-
const payload = (0,
|
|
766
|
+
const payload = (0, import_io_wallet_utils11.parseWithErrorHandling)(zDpopJwtPayload, {
|
|
914
767
|
ath,
|
|
915
768
|
htm: options.tokenRequest.method,
|
|
916
769
|
htu: htuFromRequestUrl(options.tokenRequest.url),
|
|
917
|
-
iat: (0,
|
|
770
|
+
iat: (0, import_io_wallet_utils11.dateToSeconds)(options.issuedAt),
|
|
918
771
|
jti
|
|
919
772
|
});
|
|
920
773
|
return options.callbacks.signJwt(options.signer, {
|
|
@@ -922,7 +775,7 @@ async function createTokenDPoP(options) {
|
|
|
922
775
|
payload
|
|
923
776
|
});
|
|
924
777
|
} catch (error) {
|
|
925
|
-
if (error instanceof CreateTokenDPoPError || error instanceof
|
|
778
|
+
if (error instanceof CreateTokenDPoPError || error instanceof import_io_wallet_utils11.ValidationError) {
|
|
926
779
|
throw error;
|
|
927
780
|
}
|
|
928
781
|
throw new CreateTokenDPoPError(
|
|
@@ -935,28 +788,21 @@ function extractDpopJwtFromHeaders(headers) {
|
|
|
935
788
|
if (!dpopJwt) {
|
|
936
789
|
return { valid: true };
|
|
937
790
|
}
|
|
938
|
-
if (!
|
|
791
|
+
if (!import_io_wallet_utils11.zCompactJwt.safeParse(dpopJwt).success) {
|
|
939
792
|
return { valid: false };
|
|
940
793
|
}
|
|
941
794
|
return { dpopJwt, valid: true };
|
|
942
795
|
}
|
|
943
796
|
|
|
944
|
-
// src/access-token/z-grant-type.ts
|
|
945
|
-
var import_zod10 = require("zod");
|
|
946
|
-
var zAuthorizationCodeGrantIdentifier = import_zod10.z.literal("authorization_code");
|
|
947
|
-
var authorizationCodeGrantIdentifier = zAuthorizationCodeGrantIdentifier.value;
|
|
948
|
-
var zRefreshTokenGrantIdentifier = import_zod10.z.literal("refresh_token");
|
|
949
|
-
var refreshTokenGrantIdentifier = zRefreshTokenGrantIdentifier.value;
|
|
950
|
-
|
|
951
797
|
// src/access-token/parse-token-request.ts
|
|
952
|
-
function
|
|
798
|
+
function parseAccessTokenRequestV1_4(options) {
|
|
953
799
|
const validationResult = zAccessTokenRequest.safeParse(
|
|
954
800
|
options.accessTokenRequest
|
|
955
801
|
);
|
|
956
802
|
if (!validationResult.success) {
|
|
957
803
|
throw new Oauth2Error(
|
|
958
804
|
`Access token request validation failed:
|
|
959
|
-
${(0,
|
|
805
|
+
${(0, import_io_wallet_utils12.formatZodError)(validationResult.error)}`
|
|
960
806
|
);
|
|
961
807
|
}
|
|
962
808
|
const accessTokenRequest = validationResult.data;
|
|
@@ -970,6 +816,25 @@ ${(0, import_io_wallet_utils8.formatZodError)(validationResult.error)}`
|
|
|
970
816
|
...securityHeaders
|
|
971
817
|
};
|
|
972
818
|
}
|
|
819
|
+
function parseAccessTokenRequestAPTITUDE(options) {
|
|
820
|
+
const validationResult = zAccessTokenRequestAPTITUDE.safeParse(
|
|
821
|
+
options.accessTokenRequest
|
|
822
|
+
);
|
|
823
|
+
if (!validationResult.success) {
|
|
824
|
+
throw new Oauth2Error(
|
|
825
|
+
`Access token request validation failed:
|
|
826
|
+
${(0, import_io_wallet_utils12.formatZodError)(validationResult.error)}`
|
|
827
|
+
);
|
|
828
|
+
}
|
|
829
|
+
const accessTokenRequest = validationResult.data;
|
|
830
|
+
const grant = parseGrantParametersAPTITUDE(accessTokenRequest);
|
|
831
|
+
const securityHeaders = parseSecurityHeaders(options.request.headers);
|
|
832
|
+
return {
|
|
833
|
+
accessTokenRequest,
|
|
834
|
+
grant,
|
|
835
|
+
...securityHeaders
|
|
836
|
+
};
|
|
837
|
+
}
|
|
973
838
|
function parseGrantParameters(accessTokenRequest) {
|
|
974
839
|
if (accessTokenRequest.grant_type === authorizationCodeGrantIdentifier) {
|
|
975
840
|
return {
|
|
@@ -987,6 +852,30 @@ function parseGrantParameters(accessTokenRequest) {
|
|
|
987
852
|
`Unsupported grant type. Supported types are: '${authorizationCodeGrantIdentifier}', '${refreshTokenGrantIdentifier}'`
|
|
988
853
|
);
|
|
989
854
|
}
|
|
855
|
+
function parseGrantParametersAPTITUDE(accessTokenRequest) {
|
|
856
|
+
if (accessTokenRequest.grant_type === authorizationCodeGrantIdentifier) {
|
|
857
|
+
return {
|
|
858
|
+
code: accessTokenRequest.code,
|
|
859
|
+
grantType: authorizationCodeGrantIdentifier
|
|
860
|
+
};
|
|
861
|
+
}
|
|
862
|
+
if (accessTokenRequest.grant_type === refreshTokenGrantIdentifier) {
|
|
863
|
+
return {
|
|
864
|
+
grantType: refreshTokenGrantIdentifier,
|
|
865
|
+
refreshToken: accessTokenRequest.refresh_token
|
|
866
|
+
};
|
|
867
|
+
}
|
|
868
|
+
if (accessTokenRequest.grant_type === preAuthorizedCodeGrantIdentifier) {
|
|
869
|
+
return {
|
|
870
|
+
grantType: preAuthorizedCodeGrantIdentifier,
|
|
871
|
+
preAuthorizedCode: accessTokenRequest["pre-authorized_code"],
|
|
872
|
+
txCode: accessTokenRequest.tx_code
|
|
873
|
+
};
|
|
874
|
+
}
|
|
875
|
+
throw new Oauth2Error(
|
|
876
|
+
`Unsupported grant type. Supported types are: '${authorizationCodeGrantIdentifier}', '${refreshTokenGrantIdentifier}', '${preAuthorizedCodeGrantIdentifier}'`
|
|
877
|
+
);
|
|
878
|
+
}
|
|
990
879
|
function parseSecurityHeaders(headers) {
|
|
991
880
|
const extractedDpopJwt = extractDpopJwtFromHeaders(headers);
|
|
992
881
|
if (!extractedDpopJwt.valid) {
|
|
@@ -1021,38 +910,58 @@ function parseSecurityHeaders(headers) {
|
|
|
1021
910
|
dpop: { jwt: extractedDpopJwt.dpopJwt }
|
|
1022
911
|
};
|
|
1023
912
|
}
|
|
913
|
+
var dispatchParseTokenRequest = (0, import_io_wallet_utils12.createVersionDispatcher)({
|
|
914
|
+
[import_io_wallet_utils12.ItWalletSpecsVersion.APTITUDE]: (o) => parseAccessTokenRequestAPTITUDE(
|
|
915
|
+
o
|
|
916
|
+
),
|
|
917
|
+
[import_io_wallet_utils12.ItWalletSpecsVersion.V1_0]: (o) => parseAccessTokenRequestV1_4(
|
|
918
|
+
o
|
|
919
|
+
),
|
|
920
|
+
[import_io_wallet_utils12.ItWalletSpecsVersion.V1_3]: (o) => parseAccessTokenRequestV1_4(
|
|
921
|
+
o
|
|
922
|
+
),
|
|
923
|
+
[import_io_wallet_utils12.ItWalletSpecsVersion.V1_4]: (o) => parseAccessTokenRequestV1_4(
|
|
924
|
+
o
|
|
925
|
+
)
|
|
926
|
+
});
|
|
927
|
+
function parseAccessTokenRequest(options) {
|
|
928
|
+
return dispatchParseTokenRequest(options);
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
// src/access-token/verify-access-token-request.ts
|
|
932
|
+
var import_io_wallet_utils18 = require("@pagopa/io-wallet-utils");
|
|
1024
933
|
|
|
1025
934
|
// src/client-attestation/verify-client-attestation.ts
|
|
1026
|
-
var
|
|
935
|
+
var import_io_wallet_utils15 = require("@pagopa/io-wallet-utils");
|
|
1027
936
|
|
|
1028
937
|
// src/client-attestation/client-attestation-pop.ts
|
|
1029
|
-
var
|
|
1030
|
-
var import_io_wallet_utils9 = require("@pagopa/io-wallet-utils");
|
|
938
|
+
var import_io_wallet_utils14 = require("@pagopa/io-wallet-utils");
|
|
1031
939
|
|
|
1032
940
|
// src/client-attestation/z-client-attestation-pop.ts
|
|
1033
|
-
var
|
|
941
|
+
var import_io_wallet_utils13 = require("@pagopa/io-wallet-utils");
|
|
942
|
+
var import_zod8 = __toESM(require("zod"));
|
|
1034
943
|
var IT_WALLET_CLIENT_ATTESTATION_POP_ALLOWED_ALG_VALUES = [
|
|
1035
944
|
"ES256",
|
|
1036
945
|
"ES384",
|
|
1037
946
|
"ES512"
|
|
1038
947
|
];
|
|
1039
|
-
var zItWalletClientAttestationPopJwtAlg =
|
|
948
|
+
var zItWalletClientAttestationPopJwtAlg = import_zod8.default.enum(
|
|
1040
949
|
IT_WALLET_CLIENT_ATTESTATION_POP_ALLOWED_ALG_VALUES
|
|
1041
950
|
);
|
|
1042
|
-
var zItWalletClientAttestationPopJwtPayload =
|
|
1043
|
-
...zJwtPayload.shape,
|
|
1044
|
-
aud:
|
|
1045
|
-
exp:
|
|
1046
|
-
iat:
|
|
1047
|
-
iss:
|
|
1048
|
-
jti:
|
|
1049
|
-
nonce:
|
|
951
|
+
var zItWalletClientAttestationPopJwtPayload = import_zod8.default.looseObject({
|
|
952
|
+
...import_io_wallet_utils13.zJwtPayload.shape,
|
|
953
|
+
aud: import_zod8.default.string(),
|
|
954
|
+
exp: import_zod8.default.number().int().optional(),
|
|
955
|
+
iat: import_zod8.default.number().int(),
|
|
956
|
+
iss: import_zod8.default.string(),
|
|
957
|
+
jti: import_zod8.default.string().max(import_io_wallet_utils13.MAX_JTI_LENGTH),
|
|
958
|
+
nonce: import_zod8.default.string().optional()
|
|
1050
959
|
});
|
|
1051
|
-
var zItWalletClientAttestationPopJwtTyp =
|
|
960
|
+
var zItWalletClientAttestationPopJwtTyp = import_zod8.default.literal(
|
|
1052
961
|
"oauth-client-attestation-pop+jwt"
|
|
1053
962
|
);
|
|
1054
|
-
var zItWalletClientAttestationPopJwtHeader =
|
|
1055
|
-
...zJwtHeader.shape,
|
|
963
|
+
var zItWalletClientAttestationPopJwtHeader = import_zod8.default.looseObject({
|
|
964
|
+
...import_io_wallet_utils13.zJwtHeader.shape,
|
|
1056
965
|
typ: zItWalletClientAttestationPopJwtTyp
|
|
1057
966
|
});
|
|
1058
967
|
|
|
@@ -1066,14 +975,14 @@ function assertSupportedClientAttestationPopAlg(alg) {
|
|
|
1066
975
|
}
|
|
1067
976
|
async function verifyClientAttestationPopJwt(options) {
|
|
1068
977
|
try {
|
|
1069
|
-
const { header, payload } = decodeJwt({
|
|
978
|
+
const { header, payload } = (0, import_io_wallet_utils14.decodeJwt)({
|
|
1070
979
|
errorMessagePrefix: "Error decoding client attestation PoP JWT:",
|
|
1071
980
|
headerSchema: zItWalletClientAttestationPopJwtHeader,
|
|
1072
981
|
jwt: options.clientAttestationPopJwt,
|
|
1073
982
|
payloadSchema: zItWalletClientAttestationPopJwtPayload
|
|
1074
983
|
});
|
|
1075
984
|
assertSupportedClientAttestationPopAlg(header.alg);
|
|
1076
|
-
const { signer } = await (0,
|
|
985
|
+
const { signer } = await (0, import_io_wallet_utils14.verifyJwt)({
|
|
1077
986
|
compact: options.clientAttestationPopJwt,
|
|
1078
987
|
errorMessage: "client attestation pop jwt verification failed",
|
|
1079
988
|
expectedAudience: options.authorizationServer,
|
|
@@ -1102,7 +1011,7 @@ async function verifyClientAttestationPopJwt(options) {
|
|
|
1102
1011
|
}
|
|
1103
1012
|
async function createClientAttestationPopJwt(options) {
|
|
1104
1013
|
try {
|
|
1105
|
-
const clientAttestation = decodeJwt({
|
|
1014
|
+
const clientAttestation = (0, import_io_wallet_utils14.decodeJwt)({
|
|
1106
1015
|
errorMessagePrefix: "Error decoding client attestation JWT:",
|
|
1107
1016
|
jwt: options.clientAttestation
|
|
1108
1017
|
});
|
|
@@ -1129,22 +1038,22 @@ async function createClientAttestationPopJwt(options) {
|
|
|
1129
1038
|
typ: zItWalletClientAttestationPopJwtTyp.value
|
|
1130
1039
|
};
|
|
1131
1040
|
const issuedAt = options.issuedAt ?? /* @__PURE__ */ new Date();
|
|
1132
|
-
const jti = options.jti ?? (options.callbacks.generateRandom ? (0,
|
|
1041
|
+
const jti = options.jti ?? (options.callbacks.generateRandom ? (0, import_io_wallet_utils14.encodeToBase64Url)(await options.callbacks.generateRandom(32)) : void 0);
|
|
1133
1042
|
if (!jti) {
|
|
1134
1043
|
throw new Oauth2Error(
|
|
1135
1044
|
"Error: neither a default jti nor a generateRandom callback have been provided"
|
|
1136
1045
|
);
|
|
1137
1046
|
}
|
|
1138
|
-
const payload = (0,
|
|
1047
|
+
const payload = (0, import_io_wallet_utils14.parseWithErrorHandling)(
|
|
1139
1048
|
zItWalletClientAttestationPopJwtPayload,
|
|
1140
1049
|
{
|
|
1141
1050
|
aud: options.authorizationServer,
|
|
1142
|
-
iat: (0,
|
|
1051
|
+
iat: (0, import_io_wallet_utils14.dateToSeconds)(issuedAt),
|
|
1143
1052
|
iss: sub,
|
|
1144
1053
|
jti,
|
|
1145
|
-
...options.config.itWalletSpecsVersion ===
|
|
1146
|
-
exp: (0,
|
|
1147
|
-
"expiresAt" in options && options.expiresAt ? options.expiresAt : (0,
|
|
1054
|
+
...options.config.itWalletSpecsVersion === import_io_wallet_utils14.ItWalletSpecsVersion.V1_0 ? {
|
|
1055
|
+
exp: (0, import_io_wallet_utils14.dateToSeconds)(
|
|
1056
|
+
"expiresAt" in options && options.expiresAt ? options.expiresAt : (0, import_io_wallet_utils14.addSecondsToDate)(issuedAt, 1 * 60)
|
|
1148
1057
|
)
|
|
1149
1058
|
} : {}
|
|
1150
1059
|
}
|
|
@@ -1189,8 +1098,8 @@ async function verifyClientAttestation(options) {
|
|
|
1189
1098
|
);
|
|
1190
1099
|
}
|
|
1191
1100
|
if (options.clientAttestation.ensureConfirmationKeyMatchesDpopKey && options.dpopJwkThumbprint) {
|
|
1192
|
-
const clientAttestationJkt = await (0,
|
|
1193
|
-
hashAlgorithm:
|
|
1101
|
+
const clientAttestationJkt = await (0, import_io_wallet_utils15.calculateJwkThumbprint)({
|
|
1102
|
+
hashAlgorithm: import_io_wallet_utils15.HashAlgorithm.Sha256,
|
|
1194
1103
|
hashCallback: options.callbacks.hash,
|
|
1195
1104
|
jwk: clientAttestation.payload.cnf.jwk
|
|
1196
1105
|
});
|
|
@@ -1207,8 +1116,7 @@ async function verifyClientAttestation(options) {
|
|
|
1207
1116
|
}
|
|
1208
1117
|
|
|
1209
1118
|
// src/pkce.ts
|
|
1210
|
-
var
|
|
1211
|
-
var import_io_wallet_utils10 = require("@pagopa/io-wallet-utils");
|
|
1119
|
+
var import_io_wallet_utils16 = require("@pagopa/io-wallet-utils");
|
|
1212
1120
|
var PkceCodeChallengeMethod = {
|
|
1213
1121
|
Plain: "plain",
|
|
1214
1122
|
S256: "S256"
|
|
@@ -1226,7 +1134,7 @@ async function createPkce(options) {
|
|
|
1226
1134
|
const codeChallengeMethod = allowedCodeChallengeMethods.includes(
|
|
1227
1135
|
PkceCodeChallengeMethod.S256
|
|
1228
1136
|
) ? PkceCodeChallengeMethod.S256 : PkceCodeChallengeMethod.Plain;
|
|
1229
|
-
const codeVerifier = options.codeVerifier ?? (0,
|
|
1137
|
+
const codeVerifier = options.codeVerifier ?? (0, import_io_wallet_utils16.encodeToBase64Url)(await options.callbacks.generateRandom(64));
|
|
1230
1138
|
return {
|
|
1231
1139
|
codeChallenge: await calculateCodeChallenge({
|
|
1232
1140
|
codeChallengeMethod,
|
|
@@ -1254,10 +1162,10 @@ async function calculateCodeChallenge(options) {
|
|
|
1254
1162
|
return options.codeVerifier;
|
|
1255
1163
|
}
|
|
1256
1164
|
if (options.codeChallengeMethod === PkceCodeChallengeMethod.S256) {
|
|
1257
|
-
return (0,
|
|
1165
|
+
return (0, import_io_wallet_utils16.encodeToBase64Url)(
|
|
1258
1166
|
await options.hashCallback(
|
|
1259
|
-
(0,
|
|
1260
|
-
|
|
1167
|
+
(0, import_io_wallet_utils16.decodeUtf8String)(options.codeVerifier),
|
|
1168
|
+
import_io_wallet_utils16.HashAlgorithm.Sha256
|
|
1261
1169
|
)
|
|
1262
1170
|
);
|
|
1263
1171
|
}
|
|
@@ -1267,10 +1175,9 @@ async function calculateCodeChallenge(options) {
|
|
|
1267
1175
|
}
|
|
1268
1176
|
|
|
1269
1177
|
// src/token-dpop/verify-token-dpop.ts
|
|
1270
|
-
var
|
|
1271
|
-
var import_io_wallet_utils11 = require("@pagopa/io-wallet-utils");
|
|
1178
|
+
var import_io_wallet_utils17 = require("@pagopa/io-wallet-utils");
|
|
1272
1179
|
async function verifyTokenDPoP(options) {
|
|
1273
|
-
const { header, payload } = decodeJwt({
|
|
1180
|
+
const { header, payload } = (0, import_io_wallet_utils17.decodeJwt)({
|
|
1274
1181
|
errorMessagePrefix: "Error decoding access token DPoP JWT:",
|
|
1275
1182
|
headerSchema: zDpopJwtHeader,
|
|
1276
1183
|
jwt: options.dpopJwt,
|
|
@@ -1308,10 +1215,10 @@ async function verifyTokenDPoP(options) {
|
|
|
1308
1215
|
);
|
|
1309
1216
|
}
|
|
1310
1217
|
if (options.accessToken) {
|
|
1311
|
-
const expectedAth = (0,
|
|
1218
|
+
const expectedAth = (0, import_io_wallet_utils17.encodeToBase64Url)(
|
|
1312
1219
|
await options.callbacks.hash(
|
|
1313
|
-
(0,
|
|
1314
|
-
|
|
1220
|
+
(0, import_io_wallet_utils17.decodeUtf8String)(options.accessToken),
|
|
1221
|
+
import_io_wallet_utils17.HashAlgorithm.Sha256
|
|
1315
1222
|
)
|
|
1316
1223
|
);
|
|
1317
1224
|
if (!payload.ath) {
|
|
@@ -1325,8 +1232,8 @@ async function verifyTokenDPoP(options) {
|
|
|
1325
1232
|
);
|
|
1326
1233
|
}
|
|
1327
1234
|
}
|
|
1328
|
-
const jwkThumbprint = await (0,
|
|
1329
|
-
hashAlgorithm:
|
|
1235
|
+
const jwkThumbprint = await (0, import_io_wallet_utils17.calculateJwkThumbprint)({
|
|
1236
|
+
hashAlgorithm: import_io_wallet_utils17.HashAlgorithm.Sha256,
|
|
1330
1237
|
hashCallback: options.callbacks.hash,
|
|
1331
1238
|
jwk: header.jwk
|
|
1332
1239
|
});
|
|
@@ -1336,7 +1243,7 @@ async function verifyTokenDPoP(options) {
|
|
|
1336
1243
|
);
|
|
1337
1244
|
}
|
|
1338
1245
|
try {
|
|
1339
|
-
(0,
|
|
1246
|
+
(0, import_io_wallet_utils17.verifyJwtIatOrThrow)({
|
|
1340
1247
|
iat: payload.iat,
|
|
1341
1248
|
now: options.now
|
|
1342
1249
|
});
|
|
@@ -1345,7 +1252,7 @@ async function verifyTokenDPoP(options) {
|
|
|
1345
1252
|
throw new Oauth2Error(`Invalid iat claim in dpop JWT: ${error.message}`);
|
|
1346
1253
|
}
|
|
1347
1254
|
}
|
|
1348
|
-
await (0,
|
|
1255
|
+
await (0, import_io_wallet_utils17.verifyJwt)({
|
|
1349
1256
|
compact: options.dpopJwt,
|
|
1350
1257
|
errorMessage: "dpop jwt verification failed",
|
|
1351
1258
|
header,
|
|
@@ -1366,7 +1273,7 @@ async function verifyTokenDPoP(options) {
|
|
|
1366
1273
|
}
|
|
1367
1274
|
|
|
1368
1275
|
// src/access-token/verify-access-token-request.ts
|
|
1369
|
-
async function
|
|
1276
|
+
async function verifyAccessTokenRequestV1_4(options) {
|
|
1370
1277
|
if (options.dpop.expectedNonce === "") {
|
|
1371
1278
|
throw new Oauth2Error(`Invalid 'dpop.expectedNonce' provided`);
|
|
1372
1279
|
}
|
|
@@ -1395,12 +1302,44 @@ async function verifyAccessTokenRequest(options) {
|
|
|
1395
1302
|
if (options.grant.code !== options.expectedCode) {
|
|
1396
1303
|
throw new Oauth2Error(`Invalid 'code' provided`);
|
|
1397
1304
|
}
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1305
|
+
verifyCodeExpiration(options.codeExpiresAt, options.now, "code");
|
|
1306
|
+
if (!header.jwk) {
|
|
1307
|
+
throw new Oauth2Error("DPoP header does not contain a JWK");
|
|
1308
|
+
}
|
|
1309
|
+
return {
|
|
1310
|
+
clientAttestation: clientAttestationResult,
|
|
1311
|
+
dpop: { jwk: header.jwk, jwkThumbprint }
|
|
1312
|
+
};
|
|
1313
|
+
}
|
|
1314
|
+
async function verifyAccessTokenRequestAPTITUDE(options) {
|
|
1315
|
+
if (options.dpop.expectedNonce === "") {
|
|
1316
|
+
throw new Oauth2Error(`Invalid 'dpop.expectedNonce' provided`);
|
|
1403
1317
|
}
|
|
1318
|
+
if (!isPreAuthorizedCodeVerification(options)) {
|
|
1319
|
+
await verifyPkce({
|
|
1320
|
+
callbacks: options.callbacks,
|
|
1321
|
+
codeChallenge: options.pkce.codeChallenge,
|
|
1322
|
+
codeChallengeMethod: options.pkce.codeChallengeMethod,
|
|
1323
|
+
codeVerifier: options.pkce.codeVerifier
|
|
1324
|
+
});
|
|
1325
|
+
}
|
|
1326
|
+
const { header, jwkThumbprint } = await verifyTokenDPoP({
|
|
1327
|
+
allowedSigningAlgs: options.dpop.allowedSigningAlgs,
|
|
1328
|
+
callbacks: options.callbacks,
|
|
1329
|
+
dpopJwt: options.dpop.jwt,
|
|
1330
|
+
expectedNonce: options.dpop.expectedNonce,
|
|
1331
|
+
now: options.now,
|
|
1332
|
+
request: options.request
|
|
1333
|
+
});
|
|
1334
|
+
const clientAttestationResult = await verifyClientAttestation({
|
|
1335
|
+
authorizationServerMetadata: options.authorizationServerMetadata,
|
|
1336
|
+
callbacks: options.callbacks,
|
|
1337
|
+
clientAttestation: options.clientAttestation,
|
|
1338
|
+
config: options.config,
|
|
1339
|
+
dpopJwkThumbprint: jwkThumbprint,
|
|
1340
|
+
now: options.now
|
|
1341
|
+
});
|
|
1342
|
+
verifyGrantParameters(options);
|
|
1404
1343
|
if (!header.jwk) {
|
|
1405
1344
|
throw new Oauth2Error("DPoP header does not contain a JWK");
|
|
1406
1345
|
}
|
|
@@ -1409,38 +1348,102 @@ async function verifyAccessTokenRequest(options) {
|
|
|
1409
1348
|
dpop: { jwk: header.jwk, jwkThumbprint }
|
|
1410
1349
|
};
|
|
1411
1350
|
}
|
|
1351
|
+
function isPreAuthorizedCodeVerification(options) {
|
|
1352
|
+
return options.grant.grantType === preAuthorizedCodeGrantIdentifier;
|
|
1353
|
+
}
|
|
1354
|
+
function verifyGrantParameters(options) {
|
|
1355
|
+
if (isPreAuthorizedCodeVerification(options)) {
|
|
1356
|
+
if (options.grant.preAuthorizedCode !== options.expectedPreAuthorizedCode) {
|
|
1357
|
+
throw new Oauth2Error(`Invalid 'pre-authorized_code' provided`);
|
|
1358
|
+
}
|
|
1359
|
+
verifyTransactionCode(options.grant.txCode, options.expectedTxCode);
|
|
1360
|
+
verifyCodeExpiration(
|
|
1361
|
+
options.preAuthorizedCodeExpiresAt,
|
|
1362
|
+
options.now,
|
|
1363
|
+
"pre-authorized_code"
|
|
1364
|
+
);
|
|
1365
|
+
return;
|
|
1366
|
+
}
|
|
1367
|
+
if (options.grant.grantType !== authorizationCodeGrantIdentifier) {
|
|
1368
|
+
throw new Oauth2Error(
|
|
1369
|
+
"Only authorization_code and pre-authorized_code grants can be verified"
|
|
1370
|
+
);
|
|
1371
|
+
}
|
|
1372
|
+
if (options.grant.code !== options.expectedCode) {
|
|
1373
|
+
throw new Oauth2Error(`Invalid 'code' provided`);
|
|
1374
|
+
}
|
|
1375
|
+
verifyCodeExpiration(options.codeExpiresAt, options.now, "code");
|
|
1376
|
+
}
|
|
1377
|
+
function verifyTransactionCode(txCode, expectedTxCode) {
|
|
1378
|
+
if (txCode === expectedTxCode) return;
|
|
1379
|
+
if (expectedTxCode === void 0) {
|
|
1380
|
+
throw new Oauth2Error("Request contains 'tx_code' that was not expected");
|
|
1381
|
+
}
|
|
1382
|
+
if (txCode === void 0) {
|
|
1383
|
+
throw new Oauth2Error("Missing required 'tx_code' in request");
|
|
1384
|
+
}
|
|
1385
|
+
throw new Oauth2Error("Invalid 'tx_code' provided");
|
|
1386
|
+
}
|
|
1387
|
+
function verifyCodeExpiration(expiresAt, date, codeParameter) {
|
|
1388
|
+
if (!expiresAt) return;
|
|
1389
|
+
if (Number.isNaN(expiresAt.getTime())) {
|
|
1390
|
+
throw new Oauth2Error(`Invalid expiration date for '${codeParameter}'`);
|
|
1391
|
+
}
|
|
1392
|
+
const now = date ?? /* @__PURE__ */ new Date();
|
|
1393
|
+
if (now.getTime() > expiresAt.getTime()) {
|
|
1394
|
+
throw new Oauth2Error(`Expired '${codeParameter}' provided`);
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
var dispatchVerifyAccessTokenRequest = (0, import_io_wallet_utils18.createVersionDispatcher)({
|
|
1398
|
+
[import_io_wallet_utils18.ItWalletSpecsVersion.APTITUDE]: (o) => verifyAccessTokenRequestAPTITUDE(
|
|
1399
|
+
o
|
|
1400
|
+
),
|
|
1401
|
+
[import_io_wallet_utils18.ItWalletSpecsVersion.V1_0]: (o) => verifyAccessTokenRequestV1_4(
|
|
1402
|
+
o
|
|
1403
|
+
),
|
|
1404
|
+
[import_io_wallet_utils18.ItWalletSpecsVersion.V1_3]: (o) => verifyAccessTokenRequestV1_4(
|
|
1405
|
+
o
|
|
1406
|
+
),
|
|
1407
|
+
[import_io_wallet_utils18.ItWalletSpecsVersion.V1_4]: (o) => verifyAccessTokenRequestV1_4(
|
|
1408
|
+
o
|
|
1409
|
+
)
|
|
1410
|
+
});
|
|
1411
|
+
function verifyAccessTokenRequest(options) {
|
|
1412
|
+
return dispatchVerifyAccessTokenRequest(options);
|
|
1413
|
+
}
|
|
1412
1414
|
|
|
1413
1415
|
// src/authorization-request/create-authorization-request.ts
|
|
1414
|
-
var
|
|
1416
|
+
var import_io_wallet_utils20 = require("@pagopa/io-wallet-utils");
|
|
1415
1417
|
|
|
1416
1418
|
// src/authorization-request/z-authorization-request.ts
|
|
1417
|
-
var
|
|
1418
|
-
var
|
|
1419
|
-
|
|
1420
|
-
|
|
1419
|
+
var import_io_wallet_utils19 = require("@pagopa/io-wallet-utils");
|
|
1420
|
+
var import_zod9 = __toESM(require("zod"));
|
|
1421
|
+
var zOpenidCredentialAuthorizationDetails = import_zod9.default.object({
|
|
1422
|
+
credential_configuration_id: import_zod9.default.string(),
|
|
1423
|
+
type: import_zod9.default.literal("openid_credential")
|
|
1421
1424
|
});
|
|
1422
|
-
var zItL2DocumentProofAuthorizationDetails =
|
|
1423
|
-
challenge_method:
|
|
1424
|
-
challenge_redirect_uri:
|
|
1425
|
-
idphinting:
|
|
1426
|
-
type:
|
|
1425
|
+
var zItL2DocumentProofAuthorizationDetails = import_zod9.default.object({
|
|
1426
|
+
challenge_method: import_zod9.default.literal("mrtd+ias"),
|
|
1427
|
+
challenge_redirect_uri: import_zod9.default.url(),
|
|
1428
|
+
idphinting: import_zod9.default.url(),
|
|
1429
|
+
type: import_zod9.default.literal("it_l2+document_proof")
|
|
1427
1430
|
});
|
|
1428
|
-
var zAuthorizationRequestBaseObject =
|
|
1429
|
-
authorization_details:
|
|
1430
|
-
|
|
1431
|
+
var zAuthorizationRequestBaseObject = import_zod9.default.looseObject({
|
|
1432
|
+
authorization_details: import_zod9.default.array(
|
|
1433
|
+
import_zod9.default.discriminatedUnion("type", [
|
|
1431
1434
|
zOpenidCredentialAuthorizationDetails,
|
|
1432
1435
|
zItL2DocumentProofAuthorizationDetails
|
|
1433
1436
|
])
|
|
1434
1437
|
).optional(),
|
|
1435
|
-
client_id:
|
|
1436
|
-
code_challenge:
|
|
1437
|
-
code_challenge_method:
|
|
1438
|
-
issuer_state:
|
|
1439
|
-
jti:
|
|
1440
|
-
redirect_uri:
|
|
1441
|
-
response_type:
|
|
1442
|
-
scope:
|
|
1443
|
-
state:
|
|
1438
|
+
client_id: import_zod9.default.string(),
|
|
1439
|
+
code_challenge: import_zod9.default.string(),
|
|
1440
|
+
code_challenge_method: import_zod9.default.string(),
|
|
1441
|
+
issuer_state: import_zod9.default.optional(import_zod9.default.string()),
|
|
1442
|
+
jti: import_zod9.default.string().max(import_io_wallet_utils19.MAX_JTI_LENGTH),
|
|
1443
|
+
redirect_uri: import_zod9.default.url(),
|
|
1444
|
+
response_type: import_zod9.default.string(),
|
|
1445
|
+
scope: import_zod9.default.string().optional(),
|
|
1446
|
+
state: import_zod9.default.string()
|
|
1444
1447
|
});
|
|
1445
1448
|
var zAuthorizationRequestBase = zAuthorizationRequestBaseObject.refine(
|
|
1446
1449
|
(data) => data.authorization_details !== void 0 || data.scope !== void 0,
|
|
@@ -1450,7 +1453,7 @@ var zAuthorizationRequestBase = zAuthorizationRequestBaseObject.refine(
|
|
|
1450
1453
|
}
|
|
1451
1454
|
);
|
|
1452
1455
|
var zAuthorizationRequestV1_0 = zAuthorizationRequestBaseObject.extend({
|
|
1453
|
-
response_mode:
|
|
1456
|
+
response_mode: import_zod9.default.string()
|
|
1454
1457
|
}).refine(
|
|
1455
1458
|
(data) => data.authorization_details !== void 0 || data.scope !== void 0,
|
|
1456
1459
|
{
|
|
@@ -1459,25 +1462,25 @@ var zAuthorizationRequestV1_0 = zAuthorizationRequestBaseObject.extend({
|
|
|
1459
1462
|
}
|
|
1460
1463
|
);
|
|
1461
1464
|
var zAuthorizationRequestV1_3 = zAuthorizationRequestBase;
|
|
1462
|
-
var zPushedAuthorizationRequestSigned =
|
|
1463
|
-
client_id:
|
|
1465
|
+
var zPushedAuthorizationRequestSigned = import_zod9.default.looseObject({
|
|
1466
|
+
client_id: import_zod9.default.string().describe(
|
|
1464
1467
|
"MUST be set to the thumbprint of the jwk value in the cnf parameter inside the Wallet Attestation."
|
|
1465
1468
|
),
|
|
1466
|
-
pkceCodeVerifier:
|
|
1469
|
+
pkceCodeVerifier: import_zod9.default.string().describe(
|
|
1467
1470
|
"Code verifier for PKCE. If not provided in CreatePushedAuthorizationRequestOptions, SDK will generate one."
|
|
1468
1471
|
),
|
|
1469
|
-
request:
|
|
1472
|
+
request: import_zod9.default.string().describe(
|
|
1470
1473
|
"It MUST be a signed JWT. The private key corresponding to the public one in the cnf parameter inside the Wallet Attestation MUST be used for signing the Request Object."
|
|
1471
1474
|
)
|
|
1472
1475
|
});
|
|
1473
|
-
var zPushedAuthorizationRequestUnsignedBase = (authorizationRequest) =>
|
|
1476
|
+
var zPushedAuthorizationRequestUnsignedBase = (authorizationRequest) => import_zod9.default.looseObject({
|
|
1474
1477
|
authorizationRequest: authorizationRequest.describe(
|
|
1475
1478
|
"The authorization request parameters as a plain object. Used when require_signed_request_object is false."
|
|
1476
1479
|
),
|
|
1477
|
-
client_id:
|
|
1480
|
+
client_id: import_zod9.default.string().describe(
|
|
1478
1481
|
"Thumbprint of the jwk value in the cnf parameter inside Wallet Attestation."
|
|
1479
1482
|
),
|
|
1480
|
-
pkceCodeVerifier:
|
|
1483
|
+
pkceCodeVerifier: import_zod9.default.string().describe(
|
|
1481
1484
|
"PKCE code verifier. Auto-generated if not provided in options."
|
|
1482
1485
|
)
|
|
1483
1486
|
});
|
|
@@ -1489,9 +1492,9 @@ function isPushedAuthorizationRequestSigned(par) {
|
|
|
1489
1492
|
function isPushedAuthorizationRequestUnsigned(par) {
|
|
1490
1493
|
return "authorizationRequest" in par;
|
|
1491
1494
|
}
|
|
1492
|
-
var zPushedAuthorizationResponse =
|
|
1493
|
-
expires_in:
|
|
1494
|
-
request_uri:
|
|
1495
|
+
var zPushedAuthorizationResponse = import_zod9.default.looseObject({
|
|
1496
|
+
expires_in: import_zod9.default.number().int(),
|
|
1497
|
+
request_uri: import_zod9.default.string()
|
|
1495
1498
|
});
|
|
1496
1499
|
|
|
1497
1500
|
// src/authorization-request/create-authorization-request.ts
|
|
@@ -1509,13 +1512,13 @@ async function createPushedAuthorizationRequest(options) {
|
|
|
1509
1512
|
code_challenge: pkce.codeChallenge,
|
|
1510
1513
|
code_challenge_method: pkce.codeChallengeMethod,
|
|
1511
1514
|
...options.issuerState !== void 0 ? { issuer_state: options.issuerState } : {},
|
|
1512
|
-
jti: options.jti ?? (0,
|
|
1515
|
+
jti: options.jti ?? (0, import_io_wallet_utils20.encodeToBase64Url)(
|
|
1513
1516
|
await options.callbacks.generateRandom(RANDOM_BYTES_SIZE)
|
|
1514
1517
|
),
|
|
1515
1518
|
redirect_uri: options.redirectUri,
|
|
1516
1519
|
response_type: "code",
|
|
1517
1520
|
scope: options.scope,
|
|
1518
|
-
state: options.state ?? (0,
|
|
1521
|
+
state: options.state ?? (0, import_io_wallet_utils20.encodeToBase64Url)(
|
|
1519
1522
|
await options.callbacks.generateRandom(RANDOM_BYTES_SIZE)
|
|
1520
1523
|
)
|
|
1521
1524
|
};
|
|
@@ -1532,7 +1535,7 @@ async function createPushedAuthorizationRequest(options) {
|
|
|
1532
1535
|
);
|
|
1533
1536
|
}
|
|
1534
1537
|
const iat = options.issuedAt ?? /* @__PURE__ */ new Date();
|
|
1535
|
-
const exp = options.expiresAt ?? (0,
|
|
1538
|
+
const exp = options.expiresAt ?? (0, import_io_wallet_utils20.addSecondsToDate)(iat, JWT_EXPIRY_SECONDS);
|
|
1536
1539
|
const requestJwt = await options.callbacks.signJwt(dpop.signer, {
|
|
1537
1540
|
header: {
|
|
1538
1541
|
alg: dpop.signer.alg,
|
|
@@ -1541,8 +1544,8 @@ async function createPushedAuthorizationRequest(options) {
|
|
|
1541
1544
|
},
|
|
1542
1545
|
payload: {
|
|
1543
1546
|
aud: options.audience,
|
|
1544
|
-
exp: (0,
|
|
1545
|
-
iat: (0,
|
|
1547
|
+
exp: (0, import_io_wallet_utils20.dateToSeconds)(exp),
|
|
1548
|
+
iat: (0, import_io_wallet_utils20.dateToSeconds)(iat),
|
|
1546
1549
|
iss: dpop.signer.publicJwk.kid,
|
|
1547
1550
|
...authorizationRequest
|
|
1548
1551
|
}
|
|
@@ -1560,27 +1563,30 @@ async function createPushedAuthorizationRequest(options) {
|
|
|
1560
1563
|
};
|
|
1561
1564
|
}
|
|
1562
1565
|
function parseAuthorizationRequestByVersion(options, baseAuthorizationRequest) {
|
|
1563
|
-
return (0,
|
|
1564
|
-
[
|
|
1566
|
+
return (0, import_io_wallet_utils20.dispatchByVersion)(options.config.itWalletSpecsVersion, {
|
|
1567
|
+
[import_io_wallet_utils20.ItWalletSpecsVersion.APTITUDE]: () => zAuthorizationRequestV1_3.parse(
|
|
1568
|
+
baseAuthorizationRequest
|
|
1569
|
+
),
|
|
1570
|
+
[import_io_wallet_utils20.ItWalletSpecsVersion.V1_0]: () => zAuthorizationRequestV1_0.parse({
|
|
1565
1571
|
...baseAuthorizationRequest,
|
|
1566
1572
|
response_mode: options.responseMode
|
|
1567
1573
|
}),
|
|
1568
|
-
|
|
1574
|
+
// V1_4 reuses V1_3 authorization request schema — no breaking changes between versions.
|
|
1575
|
+
[import_io_wallet_utils20.ItWalletSpecsVersion.V1_3]: () => zAuthorizationRequestV1_3.parse(
|
|
1569
1576
|
baseAuthorizationRequest
|
|
1570
1577
|
),
|
|
1571
|
-
// V1_4 reuses V1_3 authorization request schema — no breaking changes between versions.
|
|
1572
1578
|
// Verified against compare/1.3.3...1.4.1: authorization request parameters identical.
|
|
1573
|
-
[
|
|
1579
|
+
[import_io_wallet_utils20.ItWalletSpecsVersion.V1_4]: () => zAuthorizationRequestV1_3.parse(
|
|
1574
1580
|
baseAuthorizationRequest
|
|
1575
1581
|
)
|
|
1576
1582
|
});
|
|
1577
1583
|
}
|
|
1578
1584
|
|
|
1579
1585
|
// src/authorization-request/fetch-authorization-response.ts
|
|
1580
|
-
var
|
|
1586
|
+
var import_io_wallet_utils21 = require("@pagopa/io-wallet-utils");
|
|
1581
1587
|
async function fetchPushedAuthorizationResponse(options) {
|
|
1582
1588
|
try {
|
|
1583
|
-
const fetch = (0,
|
|
1589
|
+
const fetch = (0, import_io_wallet_utils21.createFetcher)(options.callbacks.fetch);
|
|
1584
1590
|
const body = isPushedAuthorizationRequestSigned(
|
|
1585
1591
|
options.pushedAuthorizationRequest
|
|
1586
1592
|
) ? new URLSearchParams({
|
|
@@ -1594,25 +1600,25 @@ async function fetchPushedAuthorizationResponse(options) {
|
|
|
1594
1600
|
{
|
|
1595
1601
|
body,
|
|
1596
1602
|
headers: {
|
|
1597
|
-
[
|
|
1598
|
-
[
|
|
1599
|
-
[
|
|
1603
|
+
[import_io_wallet_utils21.HEADERS.CONTENT_TYPE]: import_io_wallet_utils21.CONTENT_TYPES.FORM_URLENCODED,
|
|
1604
|
+
[import_io_wallet_utils21.HEADERS.OAUTH_CLIENT_ATTESTATION]: options.walletAttestation,
|
|
1605
|
+
[import_io_wallet_utils21.HEADERS.OAUTH_CLIENT_ATTESTATION_POP]: options.clientAttestationDPoP
|
|
1600
1606
|
},
|
|
1601
1607
|
method: "POST"
|
|
1602
1608
|
}
|
|
1603
1609
|
);
|
|
1604
|
-
await (0,
|
|
1610
|
+
await (0, import_io_wallet_utils21.hasStatusOrThrow)(201, import_io_wallet_utils21.UnexpectedStatusCodeError)(parResponse);
|
|
1605
1611
|
const parResponseJson = await parResponse.json();
|
|
1606
1612
|
const parsedParResponse = zPushedAuthorizationResponse.safeParse(parResponseJson);
|
|
1607
1613
|
if (!parsedParResponse.success) {
|
|
1608
|
-
throw new
|
|
1614
|
+
throw new import_io_wallet_utils21.ValidationError(
|
|
1609
1615
|
`Failed to parse pushed authorization response`,
|
|
1610
1616
|
parsedParResponse.error
|
|
1611
1617
|
);
|
|
1612
1618
|
}
|
|
1613
1619
|
return parsedParResponse.data;
|
|
1614
1620
|
} catch (error) {
|
|
1615
|
-
if (error instanceof
|
|
1621
|
+
if (error instanceof import_io_wallet_utils21.UnexpectedStatusCodeError || error instanceof import_io_wallet_utils21.ValidationError) {
|
|
1616
1622
|
throw error;
|
|
1617
1623
|
}
|
|
1618
1624
|
throw new PushedAuthorizationRequestError(
|
|
@@ -1658,22 +1664,22 @@ function parseAuthorizationRequest(options) {
|
|
|
1658
1664
|
}
|
|
1659
1665
|
|
|
1660
1666
|
// src/authorization-request/parse-pushed-authorization-request.ts
|
|
1661
|
-
var
|
|
1662
|
-
var
|
|
1667
|
+
var import_io_wallet_utils24 = require("@pagopa/io-wallet-utils");
|
|
1668
|
+
var import_zod11 = __toESM(require("zod"));
|
|
1663
1669
|
|
|
1664
1670
|
// src/jar/fetch-jar-request-object.ts
|
|
1665
|
-
var
|
|
1671
|
+
var import_io_wallet_utils22 = require("@pagopa/io-wallet-utils");
|
|
1666
1672
|
async function fetchJarRequestObject(options) {
|
|
1667
1673
|
const { fetch, requestUri } = options;
|
|
1668
1674
|
const JAR_ACCEPT_HEADER = [
|
|
1669
|
-
|
|
1675
|
+
import_io_wallet_utils22.ContentType.OAuthAuthorizationRequestJwt,
|
|
1670
1676
|
// Preferred: application/oauth-authz-req+jwt
|
|
1671
|
-
`${
|
|
1677
|
+
`${import_io_wallet_utils22.ContentType.Jwt};q=0.9`,
|
|
1672
1678
|
// Fallback: application/jwt
|
|
1673
1679
|
"text/plain"
|
|
1674
1680
|
// Final fallback: text/plain
|
|
1675
1681
|
].join(", ");
|
|
1676
|
-
const response = await (0,
|
|
1682
|
+
const response = await (0, import_io_wallet_utils22.createFetcher)(fetch)(requestUri, {
|
|
1677
1683
|
headers: {
|
|
1678
1684
|
Accept: JAR_ACCEPT_HEADER
|
|
1679
1685
|
},
|
|
@@ -1683,7 +1689,7 @@ async function fetchJarRequestObject(options) {
|
|
|
1683
1689
|
`Fetching request_object from request_uri '${requestUri}' failed`
|
|
1684
1690
|
);
|
|
1685
1691
|
});
|
|
1686
|
-
await (0,
|
|
1692
|
+
await (0, import_io_wallet_utils22.hasStatusOrThrow)(200, import_io_wallet_utils22.UnexpectedStatusCodeError)(response);
|
|
1687
1693
|
return await response.text();
|
|
1688
1694
|
}
|
|
1689
1695
|
|
|
@@ -1720,25 +1726,26 @@ async function parseJarRequest(options) {
|
|
|
1720
1726
|
}
|
|
1721
1727
|
|
|
1722
1728
|
// src/jar/z-jar.ts
|
|
1723
|
-
var
|
|
1724
|
-
var
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1729
|
+
var import_io_wallet_utils23 = require("@pagopa/io-wallet-utils");
|
|
1730
|
+
var import_zod10 = __toESM(require("zod"));
|
|
1731
|
+
var zJarAuthorizationRequest = import_zod10.default.looseObject({
|
|
1732
|
+
client_id: import_zod10.default.optional(import_zod10.default.string()),
|
|
1733
|
+
request: import_zod10.default.optional(import_zod10.default.string()),
|
|
1734
|
+
request_uri: import_zod10.default.url().optional()
|
|
1728
1735
|
});
|
|
1729
|
-
var zJarRequestObjectPayload =
|
|
1730
|
-
...zJwtPayload.shape,
|
|
1731
|
-
client_id:
|
|
1736
|
+
var zJarRequestObjectPayload = import_zod10.default.looseObject({
|
|
1737
|
+
...import_io_wallet_utils23.zJwtPayload.shape,
|
|
1738
|
+
client_id: import_zod10.default.string()
|
|
1732
1739
|
});
|
|
1733
|
-
var zSignedAuthorizationRequestJwtHeaderTyp =
|
|
1740
|
+
var zSignedAuthorizationRequestJwtHeaderTyp = import_zod10.default.literal(
|
|
1734
1741
|
"oauth-authz-req+jwt"
|
|
1735
1742
|
);
|
|
1736
|
-
var zJarRequestObjectHeader =
|
|
1737
|
-
...zJwtHeader.shape,
|
|
1743
|
+
var zJarRequestObjectHeader = import_zod10.default.looseObject({
|
|
1744
|
+
...import_io_wallet_utils23.zJwtHeader.shape,
|
|
1738
1745
|
typ: zSignedAuthorizationRequestJwtHeaderTyp
|
|
1739
1746
|
});
|
|
1740
1747
|
var signedAuthorizationRequestJwtHeaderTyp = zSignedAuthorizationRequestJwtHeaderTyp.value;
|
|
1741
|
-
var zJwtAuthorizationRequestJwtHeaderTyp =
|
|
1748
|
+
var zJwtAuthorizationRequestJwtHeaderTyp = import_zod10.default.literal("jwt");
|
|
1742
1749
|
var jwtAuthorizationRequestJwtHeaderTyp = zJwtAuthorizationRequestJwtHeaderTyp.value;
|
|
1743
1750
|
|
|
1744
1751
|
// src/authorization-request/parse-pushed-authorization-request.ts
|
|
@@ -1746,8 +1753,8 @@ async function parsePushedAuthorizationRequest(options) {
|
|
|
1746
1753
|
const authorizationRequestSchema = getAuthorizationRequestSchema(
|
|
1747
1754
|
options.config
|
|
1748
1755
|
);
|
|
1749
|
-
const parsed = (0,
|
|
1750
|
-
|
|
1756
|
+
const parsed = (0, import_io_wallet_utils24.parseWithErrorHandling)(
|
|
1757
|
+
import_zod11.default.union([authorizationRequestSchema, zJarAuthorizationRequest]),
|
|
1751
1758
|
options.authorizationRequest,
|
|
1752
1759
|
"Invalid authorization request. Could not parse authorization request or jar."
|
|
1753
1760
|
);
|
|
@@ -1758,7 +1765,7 @@ async function parsePushedAuthorizationRequest(options) {
|
|
|
1758
1765
|
callbacks: options.callbacks,
|
|
1759
1766
|
jarRequestParams: parsed
|
|
1760
1767
|
});
|
|
1761
|
-
const jwt = decodeJwt({
|
|
1768
|
+
const jwt = (0, import_io_wallet_utils24.decodeJwt)({
|
|
1762
1769
|
errorMessagePrefix: "Error decoding pushed authorization request JWT:",
|
|
1763
1770
|
jwt: parsedJar.authorizationRequestJwt
|
|
1764
1771
|
});
|
|
@@ -1768,7 +1775,7 @@ async function parsePushedAuthorizationRequest(options) {
|
|
|
1768
1775
|
if (!parsedAuthorizationRequest.success) {
|
|
1769
1776
|
throw new Oauth2Error(
|
|
1770
1777
|
`Invalid authorization request. Could not parse jar request payload.
|
|
1771
|
-
${(0,
|
|
1778
|
+
${(0, import_io_wallet_utils24.formatZodError)(parsedAuthorizationRequest.error)}`
|
|
1772
1779
|
);
|
|
1773
1780
|
}
|
|
1774
1781
|
authorizationRequestJwt = parsedJar.authorizationRequestJwt;
|
|
@@ -1779,7 +1786,7 @@ ${(0, import_io_wallet_utils15.formatZodError)(parsedAuthorizationRequest.error)
|
|
|
1779
1786
|
if (!parsedAuthorizationRequest.success) {
|
|
1780
1787
|
throw new Oauth2Error(
|
|
1781
1788
|
`Error occurred during validation of pushed authorization request.
|
|
1782
|
-
${(0,
|
|
1789
|
+
${(0, import_io_wallet_utils24.formatZodError)(parsedAuthorizationRequest.error)}`
|
|
1783
1790
|
);
|
|
1784
1791
|
}
|
|
1785
1792
|
}
|
|
@@ -1795,12 +1802,13 @@ ${(0, import_io_wallet_utils15.formatZodError)(parsedAuthorizationRequest.error)
|
|
|
1795
1802
|
};
|
|
1796
1803
|
}
|
|
1797
1804
|
function getAuthorizationRequestSchema(config) {
|
|
1798
|
-
return (0,
|
|
1799
|
-
[
|
|
1800
|
-
[
|
|
1805
|
+
return (0, import_io_wallet_utils24.dispatchByVersion)(config.itWalletSpecsVersion, {
|
|
1806
|
+
[import_io_wallet_utils24.ItWalletSpecsVersion.APTITUDE]: () => zAuthorizationRequestV1_3,
|
|
1807
|
+
[import_io_wallet_utils24.ItWalletSpecsVersion.V1_0]: () => zAuthorizationRequestV1_0,
|
|
1801
1808
|
// V1_4 reuses V1_3 PAR schema — no breaking changes between versions.
|
|
1809
|
+
[import_io_wallet_utils24.ItWalletSpecsVersion.V1_3]: () => zAuthorizationRequestV1_3,
|
|
1802
1810
|
// Verified against compare/1.3.3...1.4.1: authorization request parameters identical.
|
|
1803
|
-
[
|
|
1811
|
+
[import_io_wallet_utils24.ItWalletSpecsVersion.V1_4]: () => zAuthorizationRequestV1_3
|
|
1804
1812
|
});
|
|
1805
1813
|
}
|
|
1806
1814
|
|
|
@@ -1848,18 +1856,20 @@ async function verifyAuthorizationRequestDpop(options, request, callbacks, now)
|
|
|
1848
1856
|
};
|
|
1849
1857
|
}
|
|
1850
1858
|
|
|
1859
|
+
// src/authorization-request/verify-pushed-authorization-request.ts
|
|
1860
|
+
var import_io_wallet_utils26 = require("@pagopa/io-wallet-utils");
|
|
1861
|
+
|
|
1851
1862
|
// src/jar/verify-jar-request.ts
|
|
1852
|
-
var
|
|
1853
|
-
var import_io_wallet_utils16 = require("@pagopa/io-wallet-utils");
|
|
1863
|
+
var import_io_wallet_utils25 = require("@pagopa/io-wallet-utils");
|
|
1854
1864
|
async function verifyJarRequest(options) {
|
|
1855
1865
|
const { authorizationRequestJwt, callbacks, jarRequestParams, jwtSigner } = options;
|
|
1856
|
-
const requestObjectIsEncrypted =
|
|
1866
|
+
const requestObjectIsEncrypted = import_io_wallet_utils25.zCompactJwe.safeParse(
|
|
1857
1867
|
authorizationRequestJwt
|
|
1858
1868
|
).success;
|
|
1859
1869
|
if (requestObjectIsEncrypted) {
|
|
1860
1870
|
throw new Oauth2Error("Encrypted JWE request objects are not supported.");
|
|
1861
1871
|
}
|
|
1862
|
-
const requestIsSigned =
|
|
1872
|
+
const requestIsSigned = import_io_wallet_utils25.zCompactJwt.safeParse(
|
|
1863
1873
|
authorizationRequestJwt
|
|
1864
1874
|
).success;
|
|
1865
1875
|
if (!requestIsSigned) {
|
|
@@ -1912,15 +1922,15 @@ async function verifyJarRequest(options) {
|
|
|
1912
1922
|
}
|
|
1913
1923
|
async function verifyJarRequestObject(options) {
|
|
1914
1924
|
const { authorizationRequestJwt, callbacks, jwtSigner } = options;
|
|
1915
|
-
const jwt = decodeJwt({
|
|
1925
|
+
const jwt = (0, import_io_wallet_utils25.decodeJwt)({
|
|
1916
1926
|
errorMessagePrefix: "Error decoding JAR authorization request JWT:",
|
|
1917
1927
|
jwt: authorizationRequestJwt
|
|
1918
1928
|
});
|
|
1919
|
-
const authorizationRequestPayload = (0,
|
|
1929
|
+
const authorizationRequestPayload = (0, import_io_wallet_utils25.parseWithErrorHandling)(
|
|
1920
1930
|
zJarRequestObjectPayload,
|
|
1921
1931
|
jwt.payload
|
|
1922
1932
|
);
|
|
1923
|
-
const { signer } = await (0,
|
|
1933
|
+
const { signer } = await (0, import_io_wallet_utils25.verifyJwt)({
|
|
1924
1934
|
compact: authorizationRequestJwt,
|
|
1925
1935
|
header: jwt.header,
|
|
1926
1936
|
payload: authorizationRequestPayload,
|
|
@@ -1953,7 +1963,7 @@ async function verifyPushedAuthorizationRequest(options) {
|
|
|
1953
1963
|
let jar;
|
|
1954
1964
|
if (options.authorizationRequestJwt) {
|
|
1955
1965
|
if (requireSigned) {
|
|
1956
|
-
const decoded = decodeJwt({
|
|
1966
|
+
const decoded = (0, import_io_wallet_utils26.decodeJwt)({
|
|
1957
1967
|
errorMessagePrefix: "Error decoding pushed authorization request JWT:",
|
|
1958
1968
|
jwt: options.authorizationRequestJwt.jwt
|
|
1959
1969
|
});
|
|
@@ -2042,10 +2052,10 @@ function clientAuthenticationWalletAttestationJwt(options) {
|
|
|
2042
2052
|
}
|
|
2043
2053
|
|
|
2044
2054
|
// src/client-attestation/v1.0/create-wallet-attestation-jwt.ts
|
|
2045
|
-
var
|
|
2055
|
+
var import_io_wallet_utils28 = require("@pagopa/io-wallet-utils");
|
|
2046
2056
|
|
|
2047
2057
|
// src/client-attestation/jwk-thumbprint.ts
|
|
2048
|
-
var
|
|
2058
|
+
var import_io_wallet_utils27 = require("@pagopa/io-wallet-utils");
|
|
2049
2059
|
var SUPPORTED_KTY = ["RSA", "EC"];
|
|
2050
2060
|
var calculateDpopJwkThumbprint = (options) => {
|
|
2051
2061
|
if (!SUPPORTED_KTY.includes(
|
|
@@ -2055,8 +2065,8 @@ var calculateDpopJwkThumbprint = (options) => {
|
|
|
2055
2065
|
`Unsupported JWK key type "${options.dpopJwkPublic.kty}" for thumbprint computation. Supported types: ${SUPPORTED_KTY.join(", ")}.`
|
|
2056
2066
|
);
|
|
2057
2067
|
}
|
|
2058
|
-
return (0,
|
|
2059
|
-
hashAlgorithm:
|
|
2068
|
+
return (0, import_io_wallet_utils27.calculateJwkThumbprint)({
|
|
2069
|
+
hashAlgorithm: import_io_wallet_utils27.HashAlgorithm.Sha256,
|
|
2060
2070
|
hashCallback: options.callbacks.hash,
|
|
2061
2071
|
jwk: options.dpopJwkPublic
|
|
2062
2072
|
});
|
|
@@ -2067,12 +2077,12 @@ var createWalletAttestationJwt = async (options) => {
|
|
|
2067
2077
|
try {
|
|
2068
2078
|
const { signJwt } = options.callbacks;
|
|
2069
2079
|
const iat = /* @__PURE__ */ new Date();
|
|
2070
|
-
const exp = options.expiresAt ?? (0,
|
|
2080
|
+
const exp = options.expiresAt ?? (0, import_io_wallet_utils28.addSecondsToDate)(iat, 3600);
|
|
2071
2081
|
const dpopJwkThumbprint = await calculateDpopJwkThumbprint(options);
|
|
2072
2082
|
const payload = {
|
|
2073
2083
|
cnf: { jwk: options.dpopJwkPublic },
|
|
2074
|
-
exp: (0,
|
|
2075
|
-
iat: (0,
|
|
2084
|
+
exp: (0, import_io_wallet_utils28.dateToSeconds)(exp),
|
|
2085
|
+
iat: (0, import_io_wallet_utils28.dateToSeconds)(iat),
|
|
2076
2086
|
iss: options.issuer,
|
|
2077
2087
|
sub: dpopJwkThumbprint,
|
|
2078
2088
|
...options.walletLink && { wallet_link: options.walletLink },
|
|
@@ -2089,7 +2099,7 @@ var createWalletAttestationJwt = async (options) => {
|
|
|
2089
2099
|
header,
|
|
2090
2100
|
payload
|
|
2091
2101
|
});
|
|
2092
|
-
decodeJwt({
|
|
2102
|
+
(0, import_io_wallet_utils28.decodeJwt)({
|
|
2093
2103
|
errorMessagePrefix: "Error decoding wallet attestation JWT:",
|
|
2094
2104
|
headerSchema: zWalletAttestationJwtHeaderV1_0,
|
|
2095
2105
|
jwt: result.jwt,
|
|
@@ -2097,7 +2107,7 @@ var createWalletAttestationJwt = async (options) => {
|
|
|
2097
2107
|
});
|
|
2098
2108
|
return result.jwt;
|
|
2099
2109
|
} catch (error) {
|
|
2100
|
-
if (error instanceof
|
|
2110
|
+
if (error instanceof import_io_wallet_utils28.ValidationError) {
|
|
2101
2111
|
throw error;
|
|
2102
2112
|
}
|
|
2103
2113
|
throw new ClientAttestationError(
|
|
@@ -2107,23 +2117,23 @@ var createWalletAttestationJwt = async (options) => {
|
|
|
2107
2117
|
};
|
|
2108
2118
|
|
|
2109
2119
|
// src/client-attestation/v1.3/create-wallet-attestation-jwt.ts
|
|
2110
|
-
var
|
|
2120
|
+
var import_io_wallet_utils29 = require("@pagopa/io-wallet-utils");
|
|
2111
2121
|
var createWalletAttestationJwt2 = async (options) => {
|
|
2112
2122
|
try {
|
|
2113
2123
|
const { signJwt } = options.callbacks;
|
|
2114
2124
|
const iat = /* @__PURE__ */ new Date();
|
|
2115
|
-
const exp = options.expiresAt ?? (0,
|
|
2125
|
+
const exp = options.expiresAt ?? (0, import_io_wallet_utils29.addSecondsToDate)(iat, 3600);
|
|
2116
2126
|
if (options.nbf && options.nbf >= exp) {
|
|
2117
|
-
throw new
|
|
2127
|
+
throw new import_io_wallet_utils29.ValidationError("nbf must be before exp");
|
|
2118
2128
|
}
|
|
2119
2129
|
const dpopJwkThumbprint = await calculateDpopJwkThumbprint(options);
|
|
2120
2130
|
const payload = {
|
|
2121
2131
|
cnf: { jwk: options.dpopJwkPublic },
|
|
2122
|
-
exp: (0,
|
|
2123
|
-
iat: (0,
|
|
2132
|
+
exp: (0, import_io_wallet_utils29.dateToSeconds)(exp),
|
|
2133
|
+
iat: (0, import_io_wallet_utils29.dateToSeconds)(iat),
|
|
2124
2134
|
iss: options.issuer,
|
|
2125
2135
|
sub: dpopJwkThumbprint,
|
|
2126
|
-
...options.nbf && { nbf: (0,
|
|
2136
|
+
...options.nbf && { nbf: (0, import_io_wallet_utils29.dateToSeconds)(options.nbf) },
|
|
2127
2137
|
...options.status && { status: options.status },
|
|
2128
2138
|
...options.walletLink && { wallet_link: options.walletLink },
|
|
2129
2139
|
...options.walletName && { wallet_name: options.walletName }
|
|
@@ -2142,7 +2152,7 @@ var createWalletAttestationJwt2 = async (options) => {
|
|
|
2142
2152
|
header,
|
|
2143
2153
|
payload
|
|
2144
2154
|
});
|
|
2145
|
-
decodeJwt({
|
|
2155
|
+
(0, import_io_wallet_utils29.decodeJwt)({
|
|
2146
2156
|
errorMessagePrefix: "Error decoding wallet attestation JWT:",
|
|
2147
2157
|
headerSchema: zWalletAttestationJwtHeaderV1_3,
|
|
2148
2158
|
jwt: result.jwt,
|
|
@@ -2150,7 +2160,7 @@ var createWalletAttestationJwt2 = async (options) => {
|
|
|
2150
2160
|
});
|
|
2151
2161
|
return result.jwt;
|
|
2152
2162
|
} catch (error) {
|
|
2153
|
-
if (error instanceof
|
|
2163
|
+
if (error instanceof import_io_wallet_utils29.ValidationError) {
|
|
2154
2164
|
throw error;
|
|
2155
2165
|
}
|
|
2156
2166
|
throw new ClientAttestationError(
|
|
@@ -2160,33 +2170,33 @@ var createWalletAttestationJwt2 = async (options) => {
|
|
|
2160
2170
|
};
|
|
2161
2171
|
|
|
2162
2172
|
// src/client-attestation/v1.4/create-wallet-attestation-jwt.ts
|
|
2163
|
-
var
|
|
2173
|
+
var import_io_wallet_utils30 = require("@pagopa/io-wallet-utils");
|
|
2164
2174
|
var DEFAULT_EXPIRATION_SECONDS = 3600;
|
|
2165
2175
|
var MAX_EXPIRATION_SECONDS = 86400;
|
|
2166
2176
|
var createWalletAttestationJwt3 = async (options) => {
|
|
2167
2177
|
try {
|
|
2168
2178
|
const { signJwt } = options.callbacks;
|
|
2169
2179
|
const iat = /* @__PURE__ */ new Date();
|
|
2170
|
-
const exp = options.expiresAt ?? (0,
|
|
2180
|
+
const exp = options.expiresAt ?? (0, import_io_wallet_utils30.addSecondsToDate)(iat, DEFAULT_EXPIRATION_SECONDS);
|
|
2171
2181
|
if (exp <= iat) {
|
|
2172
|
-
throw new
|
|
2182
|
+
throw new import_io_wallet_utils30.ValidationError("exp must be after iat");
|
|
2173
2183
|
}
|
|
2174
|
-
if (exp > (0,
|
|
2175
|
-
throw new
|
|
2184
|
+
if (exp > (0, import_io_wallet_utils30.addSecondsToDate)(iat, MAX_EXPIRATION_SECONDS)) {
|
|
2185
|
+
throw new import_io_wallet_utils30.ValidationError("exp must not be more than 24 hours after iat");
|
|
2176
2186
|
}
|
|
2177
2187
|
if (options.nbf && options.nbf >= exp) {
|
|
2178
|
-
throw new
|
|
2188
|
+
throw new import_io_wallet_utils30.ValidationError("nbf must be before exp");
|
|
2179
2189
|
}
|
|
2180
2190
|
const dpopJwkThumbprint = await calculateDpopJwkThumbprint(options);
|
|
2181
2191
|
const payload = {
|
|
2182
2192
|
cnf: { jwk: options.dpopJwkPublic },
|
|
2183
|
-
exp: (0,
|
|
2184
|
-
iat: (0,
|
|
2193
|
+
exp: (0, import_io_wallet_utils30.dateToSeconds)(exp),
|
|
2194
|
+
iat: (0, import_io_wallet_utils30.dateToSeconds)(iat),
|
|
2185
2195
|
iss: options.issuer,
|
|
2186
2196
|
sub: dpopJwkThumbprint,
|
|
2187
2197
|
wallet_link: options.walletLink,
|
|
2188
2198
|
wallet_name: options.walletName,
|
|
2189
|
-
...options.nbf && { nbf: (0,
|
|
2199
|
+
...options.nbf && { nbf: (0, import_io_wallet_utils30.dateToSeconds)(options.nbf) }
|
|
2190
2200
|
};
|
|
2191
2201
|
const header = {
|
|
2192
2202
|
alg: options.signer.alg,
|
|
@@ -2201,7 +2211,7 @@ var createWalletAttestationJwt3 = async (options) => {
|
|
|
2201
2211
|
header,
|
|
2202
2212
|
payload
|
|
2203
2213
|
});
|
|
2204
|
-
decodeJwt({
|
|
2214
|
+
(0, import_io_wallet_utils30.decodeJwt)({
|
|
2205
2215
|
errorMessagePrefix: "Error decoding wallet attestation JWT:",
|
|
2206
2216
|
headerSchema: zWalletAttestationJwtHeaderV1_4,
|
|
2207
2217
|
jwt: result.jwt,
|
|
@@ -2209,7 +2219,7 @@ var createWalletAttestationJwt3 = async (options) => {
|
|
|
2209
2219
|
});
|
|
2210
2220
|
return result.jwt;
|
|
2211
2221
|
} catch (error) {
|
|
2212
|
-
if (error instanceof
|
|
2222
|
+
if (error instanceof import_io_wallet_utils30.ValidationError) {
|
|
2213
2223
|
throw error;
|
|
2214
2224
|
}
|
|
2215
2225
|
throw new ClientAttestationError(
|
|
@@ -2218,17 +2228,8 @@ var createWalletAttestationJwt3 = async (options) => {
|
|
|
2218
2228
|
}
|
|
2219
2229
|
};
|
|
2220
2230
|
|
|
2221
|
-
// src/common/jwt/z-jwe.ts
|
|
2222
|
-
var import_zod15 = require("zod");
|
|
2223
|
-
var zCompactJwe2 = import_zod15.z.string().regex(
|
|
2224
|
-
/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/,
|
|
2225
|
-
{
|
|
2226
|
-
message: "Not a valid compact jwe"
|
|
2227
|
-
}
|
|
2228
|
-
);
|
|
2229
|
-
|
|
2230
2231
|
// src/jar/create-jar-request.ts
|
|
2231
|
-
var
|
|
2232
|
+
var import_io_wallet_utils31 = require("@pagopa/io-wallet-utils");
|
|
2232
2233
|
async function createJarRequest(options) {
|
|
2233
2234
|
const {
|
|
2234
2235
|
authorizationRequestHeader,
|
|
@@ -2246,8 +2247,8 @@ async function createJarRequest(options) {
|
|
|
2246
2247
|
payload: {
|
|
2247
2248
|
...options.additionalJwtPayload,
|
|
2248
2249
|
...authorizationRequestPayload,
|
|
2249
|
-
exp: (0,
|
|
2250
|
-
iat: (0,
|
|
2250
|
+
exp: (0, import_io_wallet_utils31.dateToSeconds)((0, import_io_wallet_utils31.addSecondsToDate)(now, options.expiresInSeconds)),
|
|
2251
|
+
iat: (0, import_io_wallet_utils31.dateToSeconds)(now)
|
|
2251
2252
|
}
|
|
2252
2253
|
});
|
|
2253
2254
|
authorizationRequestJwt = jwt;
|
|
@@ -2275,6 +2276,7 @@ async function createJarRequest(options) {
|
|
|
2275
2276
|
}
|
|
2276
2277
|
|
|
2277
2278
|
// src/jarm-form-post-jwt.ts
|
|
2279
|
+
var import_io_wallet_utils32 = require("@pagopa/io-wallet-utils");
|
|
2278
2280
|
var getJwtFromFormPost = async (options) => {
|
|
2279
2281
|
const inputRegex = /<input[^<>]*>/gi;
|
|
2280
2282
|
const nameRegex = /name="response"/gi;
|
|
@@ -2289,7 +2291,7 @@ var getJwtFromFormPost = async (options) => {
|
|
|
2289
2291
|
const responseJwt = matchValue[1];
|
|
2290
2292
|
if (responseJwt) {
|
|
2291
2293
|
const jwt = responseJwt.replace(lineExpressionRegex, "");
|
|
2292
|
-
const decodedJwt = decodeJwt({
|
|
2294
|
+
const decodedJwt = (0, import_io_wallet_utils32.decodeJwt)({
|
|
2293
2295
|
errorMessagePrefix: "Error decoding JARM form post JWT:",
|
|
2294
2296
|
jwt,
|
|
2295
2297
|
payloadSchema: options.schema
|
|
@@ -2311,73 +2313,73 @@ var getJwtFromFormPost = async (options) => {
|
|
|
2311
2313
|
};
|
|
2312
2314
|
|
|
2313
2315
|
// src/mrtd-pop/create-mrtd-validation-jwt.ts
|
|
2314
|
-
var
|
|
2316
|
+
var import_io_wallet_utils33 = require("@pagopa/io-wallet-utils");
|
|
2315
2317
|
|
|
2316
2318
|
// src/mrtd-pop/z-mrtd-pop.ts
|
|
2317
|
-
var
|
|
2318
|
-
var zMrtdChallengeJwtHeader =
|
|
2319
|
-
alg:
|
|
2320
|
-
kid:
|
|
2321
|
-
typ:
|
|
2319
|
+
var import_zod12 = __toESM(require("zod"));
|
|
2320
|
+
var zMrtdChallengeJwtHeader = import_zod12.default.looseObject({
|
|
2321
|
+
alg: import_zod12.default.string(),
|
|
2322
|
+
kid: import_zod12.default.string(),
|
|
2323
|
+
typ: import_zod12.default.literal("mrtd-ias+jwt")
|
|
2322
2324
|
});
|
|
2323
|
-
var zMrtdChallengeJwtPayload =
|
|
2324
|
-
aud:
|
|
2325
|
-
exp:
|
|
2326
|
-
htm:
|
|
2327
|
-
htu:
|
|
2328
|
-
iat:
|
|
2329
|
-
iss:
|
|
2330
|
-
mrtd_auth_session:
|
|
2331
|
-
mrtd_pop_jwt_nonce:
|
|
2332
|
-
state:
|
|
2333
|
-
status:
|
|
2334
|
-
type:
|
|
2325
|
+
var zMrtdChallengeJwtPayload = import_zod12.default.looseObject({
|
|
2326
|
+
aud: import_zod12.default.string(),
|
|
2327
|
+
exp: import_zod12.default.number(),
|
|
2328
|
+
htm: import_zod12.default.literal("POST"),
|
|
2329
|
+
htu: import_zod12.default.url(),
|
|
2330
|
+
iat: import_zod12.default.number(),
|
|
2331
|
+
iss: import_zod12.default.string(),
|
|
2332
|
+
mrtd_auth_session: import_zod12.default.string(),
|
|
2333
|
+
mrtd_pop_jwt_nonce: import_zod12.default.string(),
|
|
2334
|
+
state: import_zod12.default.string(),
|
|
2335
|
+
status: import_zod12.default.literal("require_interaction"),
|
|
2336
|
+
type: import_zod12.default.literal("mrtd+ias")
|
|
2335
2337
|
});
|
|
2336
|
-
var zMrtdPopInitResponseJwtHeader =
|
|
2337
|
-
alg:
|
|
2338
|
-
kid:
|
|
2339
|
-
typ:
|
|
2338
|
+
var zMrtdPopInitResponseJwtHeader = import_zod12.default.looseObject({
|
|
2339
|
+
alg: import_zod12.default.string(),
|
|
2340
|
+
kid: import_zod12.default.string(),
|
|
2341
|
+
typ: import_zod12.default.literal("mrtd-ias-pop+jwt")
|
|
2340
2342
|
});
|
|
2341
|
-
var zMrtdPopInitResponseJwtPayload =
|
|
2342
|
-
aud:
|
|
2343
|
-
challenge:
|
|
2344
|
-
exp:
|
|
2345
|
-
htm:
|
|
2346
|
-
htu:
|
|
2347
|
-
iat:
|
|
2348
|
-
iss:
|
|
2349
|
-
mrtd_pop_nonce:
|
|
2350
|
-
mrz:
|
|
2343
|
+
var zMrtdPopInitResponseJwtPayload = import_zod12.default.looseObject({
|
|
2344
|
+
aud: import_zod12.default.string(),
|
|
2345
|
+
challenge: import_zod12.default.string(),
|
|
2346
|
+
exp: import_zod12.default.number(),
|
|
2347
|
+
htm: import_zod12.default.literal("POST"),
|
|
2348
|
+
htu: import_zod12.default.url(),
|
|
2349
|
+
iat: import_zod12.default.number(),
|
|
2350
|
+
iss: import_zod12.default.string(),
|
|
2351
|
+
mrtd_pop_nonce: import_zod12.default.string(),
|
|
2352
|
+
mrz: import_zod12.default.string().optional()
|
|
2351
2353
|
});
|
|
2352
|
-
var zMrtdData =
|
|
2353
|
-
dg1:
|
|
2354
|
-
dg11:
|
|
2355
|
-
sod_mrtd:
|
|
2354
|
+
var zMrtdData = import_zod12.default.looseObject({
|
|
2355
|
+
dg1: import_zod12.default.string(),
|
|
2356
|
+
dg11: import_zod12.default.string(),
|
|
2357
|
+
sod_mrtd: import_zod12.default.string()
|
|
2356
2358
|
});
|
|
2357
|
-
var zIasData =
|
|
2358
|
-
challenge_signed:
|
|
2359
|
-
ias_pk:
|
|
2360
|
-
sod_ias:
|
|
2359
|
+
var zIasData = import_zod12.default.looseObject({
|
|
2360
|
+
challenge_signed: import_zod12.default.string(),
|
|
2361
|
+
ias_pk: import_zod12.default.string(),
|
|
2362
|
+
sod_ias: import_zod12.default.string()
|
|
2361
2363
|
});
|
|
2362
|
-
var zMrtdValidationJwtHeader =
|
|
2363
|
-
alg:
|
|
2364
|
-
kid:
|
|
2365
|
-
typ:
|
|
2364
|
+
var zMrtdValidationJwtHeader = import_zod12.default.looseObject({
|
|
2365
|
+
alg: import_zod12.default.string(),
|
|
2366
|
+
kid: import_zod12.default.string(),
|
|
2367
|
+
typ: import_zod12.default.literal("mrtd-ias+jwt")
|
|
2366
2368
|
});
|
|
2367
|
-
var zMrtdValidationJwtPayload =
|
|
2368
|
-
aud:
|
|
2369
|
-
document_type:
|
|
2370
|
-
exp:
|
|
2369
|
+
var zMrtdValidationJwtPayload = import_zod12.default.looseObject({
|
|
2370
|
+
aud: import_zod12.default.string(),
|
|
2371
|
+
document_type: import_zod12.default.literal("cie"),
|
|
2372
|
+
exp: import_zod12.default.number(),
|
|
2371
2373
|
ias: zIasData,
|
|
2372
|
-
iat:
|
|
2373
|
-
iss:
|
|
2374
|
+
iat: import_zod12.default.number(),
|
|
2375
|
+
iss: import_zod12.default.string(),
|
|
2374
2376
|
mrtd: zMrtdData
|
|
2375
2377
|
});
|
|
2376
|
-
var zMrtdPopVerifyResponse =
|
|
2377
|
-
mrtd_val_pop_nonce:
|
|
2378
|
-
redirect_uri:
|
|
2379
|
-
status:
|
|
2380
|
-
type:
|
|
2378
|
+
var zMrtdPopVerifyResponse = import_zod12.default.looseObject({
|
|
2379
|
+
mrtd_val_pop_nonce: import_zod12.default.string(),
|
|
2380
|
+
redirect_uri: import_zod12.default.url(),
|
|
2381
|
+
status: import_zod12.default.literal("require_interaction"),
|
|
2382
|
+
type: import_zod12.default.literal("redirect_to_web")
|
|
2381
2383
|
});
|
|
2382
2384
|
|
|
2383
2385
|
// src/mrtd-pop/create-mrtd-validation-jwt.ts
|
|
@@ -2388,13 +2390,13 @@ async function createMrtdValidationJwt(options) {
|
|
|
2388
2390
|
if (!kid) {
|
|
2389
2391
|
throw new MrtdPopError("Signer must have a publicJwk.kid property");
|
|
2390
2392
|
}
|
|
2391
|
-
const iat = (0,
|
|
2392
|
-
const header = (0,
|
|
2393
|
+
const iat = (0, import_io_wallet_utils33.dateToSeconds)(options.issuedAt);
|
|
2394
|
+
const header = (0, import_io_wallet_utils33.parseWithErrorHandling)(zMrtdValidationJwtHeader, {
|
|
2393
2395
|
alg: options.signer.alg,
|
|
2394
2396
|
kid,
|
|
2395
2397
|
typ: "mrtd-ias+jwt"
|
|
2396
2398
|
});
|
|
2397
|
-
const payload = (0,
|
|
2399
|
+
const payload = (0, import_io_wallet_utils33.parseWithErrorHandling)(zMrtdValidationJwtPayload, {
|
|
2398
2400
|
aud: options.audience,
|
|
2399
2401
|
document_type: "cie",
|
|
2400
2402
|
exp: iat + JWT_EXPIRY_SECONDS2,
|
|
@@ -2427,37 +2429,36 @@ async function createMrtdValidationJwt(options) {
|
|
|
2427
2429
|
}
|
|
2428
2430
|
|
|
2429
2431
|
// src/mrtd-pop/fetch-mrtd-pop-init.ts
|
|
2430
|
-
var
|
|
2431
|
-
var import_io_wallet_utils22 = require("@pagopa/io-wallet-utils");
|
|
2432
|
+
var import_io_wallet_utils34 = require("@pagopa/io-wallet-utils");
|
|
2432
2433
|
async function fetchMrtdPopInit(options) {
|
|
2433
2434
|
try {
|
|
2434
|
-
const fetch = (0,
|
|
2435
|
+
const fetch = (0, import_io_wallet_utils34.createFetcher)(options.callbacks.fetch);
|
|
2435
2436
|
const response = await fetch(options.popInitEndpoint, {
|
|
2436
2437
|
body: JSON.stringify({
|
|
2437
2438
|
mrtd_auth_session: options.mrtdAuthSession,
|
|
2438
2439
|
mrtd_pop_jwt_nonce: options.mrtdPopJwtNonce
|
|
2439
2440
|
}),
|
|
2440
2441
|
headers: {
|
|
2441
|
-
[
|
|
2442
|
-
[
|
|
2443
|
-
[
|
|
2442
|
+
[import_io_wallet_utils34.HEADERS.CONTENT_TYPE]: import_io_wallet_utils34.CONTENT_TYPES.JSON,
|
|
2443
|
+
[import_io_wallet_utils34.HEADERS.OAUTH_CLIENT_ATTESTATION]: options.walletAttestation,
|
|
2444
|
+
[import_io_wallet_utils34.HEADERS.OAUTH_CLIENT_ATTESTATION_POP]: options.clientAttestationDPoP
|
|
2444
2445
|
},
|
|
2445
2446
|
method: "POST"
|
|
2446
2447
|
});
|
|
2447
|
-
await (0,
|
|
2448
|
+
await (0, import_io_wallet_utils34.hasStatusOrThrow)(202, import_io_wallet_utils34.UnexpectedStatusCodeError)(response);
|
|
2448
2449
|
const responseJwt = await response.text();
|
|
2449
|
-
const jwt = decodeJwt({
|
|
2450
|
+
const jwt = (0, import_io_wallet_utils34.decodeJwt)({
|
|
2450
2451
|
errorMessagePrefix: "Error decoding MRTD PoP init response JWT:",
|
|
2451
2452
|
headerSchema: zMrtdPopInitResponseJwtHeader,
|
|
2452
2453
|
jwt: responseJwt,
|
|
2453
2454
|
payloadSchema: zMrtdPopInitResponseJwtPayload
|
|
2454
2455
|
});
|
|
2455
|
-
const { signer } = await (0,
|
|
2456
|
+
const { signer } = await (0, import_io_wallet_utils34.verifyJwt)({
|
|
2456
2457
|
compact: responseJwt,
|
|
2457
2458
|
errorMessage: "Error verifying MRTD PoP init response JWT",
|
|
2458
2459
|
header: jwt.header,
|
|
2459
2460
|
payload: jwt.payload,
|
|
2460
|
-
signer: options.signer ?? (0,
|
|
2461
|
+
signer: options.signer ?? (0, import_io_wallet_utils34.jwtSignerFromJwt)({ header: jwt.header, payload: jwt.payload }),
|
|
2461
2462
|
verifyJwtCallback: options.callbacks.verifyJwt
|
|
2462
2463
|
});
|
|
2463
2464
|
return {
|
|
@@ -2468,7 +2469,7 @@ async function fetchMrtdPopInit(options) {
|
|
|
2468
2469
|
signer
|
|
2469
2470
|
};
|
|
2470
2471
|
} catch (error) {
|
|
2471
|
-
if (error instanceof
|
|
2472
|
+
if (error instanceof import_io_wallet_utils34.UnexpectedStatusCodeError || error instanceof import_io_wallet_utils34.ValidationError) {
|
|
2472
2473
|
throw error;
|
|
2473
2474
|
}
|
|
2474
2475
|
throw new MrtdPopError(
|
|
@@ -2478,10 +2479,10 @@ async function fetchMrtdPopInit(options) {
|
|
|
2478
2479
|
}
|
|
2479
2480
|
|
|
2480
2481
|
// src/mrtd-pop/fetch-mrtd-pop-verify.ts
|
|
2481
|
-
var
|
|
2482
|
+
var import_io_wallet_utils35 = require("@pagopa/io-wallet-utils");
|
|
2482
2483
|
async function fetchMrtdPopVerify(options) {
|
|
2483
2484
|
try {
|
|
2484
|
-
const fetch = (0,
|
|
2485
|
+
const fetch = (0, import_io_wallet_utils35.createFetcher)(options.callbacks.fetch);
|
|
2485
2486
|
const response = await fetch(options.popVerifyEndpoint, {
|
|
2486
2487
|
body: JSON.stringify({
|
|
2487
2488
|
mrtd_auth_session: options.mrtdAuthSession,
|
|
@@ -2489,14 +2490,14 @@ async function fetchMrtdPopVerify(options) {
|
|
|
2489
2490
|
mrtd_validation_jwt: options.mrtdValidationJwt
|
|
2490
2491
|
}),
|
|
2491
2492
|
headers: {
|
|
2492
|
-
[
|
|
2493
|
-
[
|
|
2494
|
-
[
|
|
2493
|
+
[import_io_wallet_utils35.HEADERS.CONTENT_TYPE]: import_io_wallet_utils35.CONTENT_TYPES.JSON,
|
|
2494
|
+
[import_io_wallet_utils35.HEADERS.OAUTH_CLIENT_ATTESTATION]: options.walletAttestation,
|
|
2495
|
+
[import_io_wallet_utils35.HEADERS.OAUTH_CLIENT_ATTESTATION_POP]: options.clientAttestationDPoP
|
|
2495
2496
|
},
|
|
2496
2497
|
method: "POST"
|
|
2497
2498
|
});
|
|
2498
|
-
await (0,
|
|
2499
|
-
const parsed = (0,
|
|
2499
|
+
await (0, import_io_wallet_utils35.hasStatusOrThrow)(202, import_io_wallet_utils35.UnexpectedStatusCodeError)(response);
|
|
2500
|
+
const parsed = (0, import_io_wallet_utils35.parseWithErrorHandling)(
|
|
2500
2501
|
zMrtdPopVerifyResponse,
|
|
2501
2502
|
await response.json(),
|
|
2502
2503
|
"Failed to parse MRTD PoP verify response"
|
|
@@ -2506,7 +2507,7 @@ async function fetchMrtdPopVerify(options) {
|
|
|
2506
2507
|
redirectUri: parsed.redirect_uri
|
|
2507
2508
|
};
|
|
2508
2509
|
} catch (error) {
|
|
2509
|
-
if (error instanceof
|
|
2510
|
+
if (error instanceof import_io_wallet_utils35.UnexpectedStatusCodeError || error instanceof import_io_wallet_utils35.ValidationError) {
|
|
2510
2511
|
throw error;
|
|
2511
2512
|
}
|
|
2512
2513
|
throw new MrtdPopError(
|
|
@@ -2516,7 +2517,7 @@ async function fetchMrtdPopVerify(options) {
|
|
|
2516
2517
|
}
|
|
2517
2518
|
|
|
2518
2519
|
// src/mrtd-pop/parse-mrtd-challenge.ts
|
|
2519
|
-
var
|
|
2520
|
+
var import_io_wallet_utils36 = require("@pagopa/io-wallet-utils");
|
|
2520
2521
|
function parseMrtdChallenge(options) {
|
|
2521
2522
|
const url = new URL(options.redirectUrl);
|
|
2522
2523
|
const challengeJwt = url.searchParams.get("challenge_info");
|
|
@@ -2525,12 +2526,12 @@ function parseMrtdChallenge(options) {
|
|
|
2525
2526
|
"Missing 'challenge_info' query parameter in redirect URL"
|
|
2526
2527
|
);
|
|
2527
2528
|
}
|
|
2528
|
-
if (!
|
|
2529
|
+
if (!import_io_wallet_utils36.zCompactJwt.safeParse(challengeJwt).success) {
|
|
2529
2530
|
throw new MrtdPopError(
|
|
2530
2531
|
"Invalid JWT format in 'challenge_info' query parameter"
|
|
2531
2532
|
);
|
|
2532
2533
|
}
|
|
2533
|
-
const { header, payload } = decodeJwt({
|
|
2534
|
+
const { header, payload } = (0, import_io_wallet_utils36.decodeJwt)({
|
|
2534
2535
|
errorMessagePrefix: "Error decoding MRTD challenge JWT:",
|
|
2535
2536
|
headerSchema: zMrtdChallengeJwtHeader,
|
|
2536
2537
|
jwt: challengeJwt,
|
|
@@ -2540,10 +2541,10 @@ function parseMrtdChallenge(options) {
|
|
|
2540
2541
|
}
|
|
2541
2542
|
|
|
2542
2543
|
// src/mrtd-pop/verify-mrtd-challenge.ts
|
|
2543
|
-
var
|
|
2544
|
+
var import_io_wallet_utils37 = require("@pagopa/io-wallet-utils");
|
|
2544
2545
|
async function verifyMrtdChallenge(options) {
|
|
2545
2546
|
const { callbacks, challengeJwt, clientId } = options;
|
|
2546
|
-
const jwt = decodeJwt({
|
|
2547
|
+
const jwt = (0, import_io_wallet_utils37.decodeJwt)({
|
|
2547
2548
|
errorMessagePrefix: "Error decoding MRTD challenge JWT:",
|
|
2548
2549
|
headerSchema: zMrtdChallengeJwtHeader,
|
|
2549
2550
|
jwt: challengeJwt,
|
|
@@ -2555,31 +2556,25 @@ async function verifyMrtdChallenge(options) {
|
|
|
2555
2556
|
);
|
|
2556
2557
|
}
|
|
2557
2558
|
const payload = jwt.payload;
|
|
2558
|
-
const { signer } = await (0,
|
|
2559
|
+
const { signer } = await (0, import_io_wallet_utils37.verifyJwt)({
|
|
2559
2560
|
compact: challengeJwt,
|
|
2560
2561
|
errorMessage: "Error verifying MRTD challenge JWT",
|
|
2561
2562
|
header: jwt.header,
|
|
2562
2563
|
payload,
|
|
2563
|
-
signer: options.signer ?? (0,
|
|
2564
|
+
signer: options.signer ?? (0, import_io_wallet_utils37.jwtSignerFromJwt)({ header: jwt.header, payload }),
|
|
2564
2565
|
verifyJwtCallback: callbacks.verifyJwt
|
|
2565
2566
|
});
|
|
2566
2567
|
return { header: jwt.header, payload: jwt.payload, signer };
|
|
2567
2568
|
}
|
|
2568
|
-
|
|
2569
|
-
// src/index.ts
|
|
2570
|
-
var import_oauth216 = require("@openid4vc/oauth2");
|
|
2571
2569
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2572
2570
|
0 && (module.exports = {
|
|
2573
2571
|
ClientAttestationError,
|
|
2574
2572
|
CreateTokenDPoPError,
|
|
2575
2573
|
CreateTokenResponseError,
|
|
2576
2574
|
FetchTokenResponseError,
|
|
2577
|
-
HashAlgorithm,
|
|
2578
2575
|
IT_WALLET_CLIENT_ATTESTATION_POP_ALLOWED_ALG_VALUES,
|
|
2579
|
-
MAX_JTI_LENGTH,
|
|
2580
2576
|
MrtdPopError,
|
|
2581
2577
|
Oauth2Error,
|
|
2582
|
-
Oauth2JwtParseError,
|
|
2583
2578
|
PkceCodeChallengeMethod,
|
|
2584
2579
|
PushedAuthorizationRequestError,
|
|
2585
2580
|
SupportedClientAuthenticationMethod,
|
|
@@ -2594,11 +2589,11 @@ var import_oauth216 = require("@openid4vc/oauth2");
|
|
|
2594
2589
|
createPushedAuthorizationRequest,
|
|
2595
2590
|
createTokenDPoP,
|
|
2596
2591
|
createTokenRequest,
|
|
2592
|
+
createTokenRequestAPTITUDE,
|
|
2593
|
+
createTokenRequestV1_4,
|
|
2597
2594
|
createWalletAttestationJwtV1_0,
|
|
2598
2595
|
createWalletAttestationJwtV1_3,
|
|
2599
2596
|
createWalletAttestationJwtV1_4,
|
|
2600
|
-
decodeJwt,
|
|
2601
|
-
decodeJwtHeader,
|
|
2602
2597
|
extractClientAttestationJwtsFromHeaders,
|
|
2603
2598
|
extractDpopJwtFromHeaders,
|
|
2604
2599
|
fetchJarRequestObject,
|
|
@@ -2613,12 +2608,12 @@ var import_oauth216 = require("@openid4vc/oauth2");
|
|
|
2613
2608
|
isPushedAuthorizationRequestSigned,
|
|
2614
2609
|
isPushedAuthorizationRequestUnsigned,
|
|
2615
2610
|
jwtAuthorizationRequestJwtHeaderTyp,
|
|
2616
|
-
jwtHeaderFromJwtSigner,
|
|
2617
2611
|
parseAccessTokenRequest,
|
|
2618
2612
|
parseAuthorizationRequest,
|
|
2619
2613
|
parseJarRequest,
|
|
2620
2614
|
parseMrtdChallenge,
|
|
2621
2615
|
parsePushedAuthorizationRequest,
|
|
2616
|
+
preAuthorizedCodeGrantIdentifier,
|
|
2622
2617
|
refreshTokenGrantIdentifier,
|
|
2623
2618
|
signedAuthorizationRequestJwtHeaderTyp,
|
|
2624
2619
|
toURLSearchParams,
|
|
@@ -2628,7 +2623,6 @@ var import_oauth216 = require("@openid4vc/oauth2");
|
|
|
2628
2623
|
verifyClientAttestation,
|
|
2629
2624
|
verifyClientAttestationPopJwt,
|
|
2630
2625
|
verifyJarRequest,
|
|
2631
|
-
verifyJwt,
|
|
2632
2626
|
verifyMrtdChallenge,
|
|
2633
2627
|
verifyPkce,
|
|
2634
2628
|
verifyPushedAuthorizationRequest,
|
|
@@ -2640,14 +2634,12 @@ var import_oauth216 = require("@openid4vc/oauth2");
|
|
|
2640
2634
|
zAccessTokenProfileJwtHeader,
|
|
2641
2635
|
zAccessTokenProfileJwtPayload,
|
|
2642
2636
|
zAccessTokenRequest,
|
|
2637
|
+
zAccessTokenRequestAPTITUDE,
|
|
2643
2638
|
zAccessTokenResponse,
|
|
2644
|
-
zAlgValueNotNone,
|
|
2645
2639
|
zAuthorizationCodeGrantIdentifier,
|
|
2640
|
+
zAuthorizationCodeTokenRequest,
|
|
2646
2641
|
zAuthorizationRequestV1_0,
|
|
2647
2642
|
zAuthorizationRequestV1_3,
|
|
2648
|
-
zCertificateChain,
|
|
2649
|
-
zCompactJwe,
|
|
2650
|
-
zCompactJwt,
|
|
2651
2643
|
zDpopJwtHeader,
|
|
2652
2644
|
zDpopJwtPayload,
|
|
2653
2645
|
zItWalletClientAttestationPopJwtAlg,
|
|
@@ -2657,11 +2649,6 @@ var import_oauth216 = require("@openid4vc/oauth2");
|
|
|
2657
2649
|
zJarAuthorizationRequest,
|
|
2658
2650
|
zJarRequestObjectHeader,
|
|
2659
2651
|
zJarRequestObjectPayload,
|
|
2660
|
-
zJwk,
|
|
2661
|
-
zJwkSet,
|
|
2662
|
-
zJwtConfirmationPayload,
|
|
2663
|
-
zJwtHeader,
|
|
2664
|
-
zJwtPayload,
|
|
2665
2652
|
zMrtdChallengeJwtHeader,
|
|
2666
2653
|
zMrtdChallengeJwtPayload,
|
|
2667
2654
|
zMrtdPopInitResponseJwtHeader,
|
|
@@ -2669,6 +2656,8 @@ var import_oauth216 = require("@openid4vc/oauth2");
|
|
|
2669
2656
|
zMrtdPopVerifyResponse,
|
|
2670
2657
|
zMrtdValidationJwtHeader,
|
|
2671
2658
|
zMrtdValidationJwtPayload,
|
|
2659
|
+
zPreAuthorizedCodeGrantIdentifier,
|
|
2660
|
+
zPreAuthorizedCodeTokenRequest,
|
|
2672
2661
|
zPushedAuthorizationRequestSigned,
|
|
2673
2662
|
zPushedAuthorizationRequestUnsignedV1_0,
|
|
2674
2663
|
zPushedAuthorizationRequestUnsignedV1_3,
|
|
@@ -2676,8 +2665,8 @@ var import_oauth216 = require("@openid4vc/oauth2");
|
|
|
2676
2665
|
zRefreshTokenGrantIdentifier,
|
|
2677
2666
|
zRefreshTokenProfileJwtHeader,
|
|
2678
2667
|
zRefreshTokenProfileJwtPayload,
|
|
2668
|
+
zRefreshTokenTokenRequest,
|
|
2679
2669
|
zSignedAuthorizationRequestJwtHeaderTyp,
|
|
2680
|
-
zTrustChain,
|
|
2681
2670
|
zWalletAttestationJwtHeaderV1_0,
|
|
2682
2671
|
zWalletAttestationJwtHeaderV1_3,
|
|
2683
2672
|
zWalletAttestationJwtHeaderV1_4,
|