@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.mjs CHANGED
@@ -1,189 +1,78 @@
1
1
  // src/access-token/create-token-request.ts
2
- var createTokenRequest = async (options) => ({
3
- ...options.additionalRequestPayload,
4
- code: options.authorizationCode,
5
- code_verifier: options.pkceCodeVerifier,
6
- grant_type: "authorization_code",
7
- redirect_uri: options.redirectUri
8
- });
9
-
10
- // src/access-token/create-token-response.ts
11
- import {
12
- HashAlgorithm,
13
- calculateJwkThumbprint
14
- } from "@openid4vc/oauth2";
15
- import {
16
- addSecondsToDate,
17
- dateToSeconds,
18
- parseWithErrorHandling as parseWithErrorHandling2
19
- } from "@pagopa/io-wallet-utils";
20
-
21
- // src/common/jwt/decode-jwt-header.ts
22
- import { Oauth2JwtParseError } from "@openid4vc/oauth2";
23
2
  import {
24
- decodeBase64,
25
- encodeToUtf8String,
26
- formatError,
27
- parseWithErrorHandling,
28
- stringToJsonWithErrorHandling
3
+ ItWalletSpecsVersion,
4
+ createVersionDispatcher
29
5
  } from "@pagopa/io-wallet-utils";
30
6
 
31
- // src/common/jwt/z-jwt.ts
32
- import z3 from "zod";
33
-
34
- // src/common/jwk/z-jwk.ts
35
- import z2 from "zod";
36
-
37
- // src/common/z-common.ts
38
- import z from "zod";
39
- var zTrustChain = z.tuple([z.string()], z.string());
40
- var zCertificateChain = z.array(z.string()).nonempty();
41
- var zAlgValueNotNone = z.string().refine((alg) => alg !== "none", { message: `alg value may not be 'none'` });
42
-
43
- // src/common/jwk/z-jwk.ts
44
- var zJwk = z2.looseObject({
45
- alg: z2.optional(z2.string()),
46
- crv: z2.optional(z2.string()),
47
- d: z2.optional(z2.string()),
48
- dp: z2.optional(z2.string()),
49
- dq: z2.optional(z2.string()),
50
- e: z2.optional(z2.string()),
51
- ext: z2.optional(z2.boolean()),
52
- k: z2.optional(z2.string()),
53
- key_ops: z2.optional(z2.array(z2.string())),
54
- kid: z2.optional(z2.string()),
55
- kty: z2.string(),
56
- n: z2.optional(z2.string()),
57
- oth: z2.optional(
58
- z2.array(
59
- z2.looseObject({
60
- d: z2.optional(z2.string()),
61
- r: z2.optional(z2.string()),
62
- t: z2.optional(z2.string())
63
- })
64
- )
65
- ),
66
- p: z2.optional(z2.string()),
67
- q: z2.optional(z2.string()),
68
- qi: z2.optional(z2.string()),
69
- use: z2.optional(z2.string()),
70
- x: z2.optional(z2.string()),
71
- x5c: z2.optional(zCertificateChain),
72
- x5t: z2.optional(z2.string()),
73
- "x5t#S256": z2.optional(z2.string()),
74
- x5u: z2.optional(z2.string()),
75
- y: z2.optional(z2.string())
76
- });
77
- var zJwkSet = z2.looseObject({ keys: z2.array(zJwk) });
78
-
79
- // src/common/jwt/z-jwt.ts
80
- var MAX_JTI_LENGTH = 256;
81
- var zCompactJwt = z3.string().regex(/^([a-zA-Z0-9-_]+)\.([a-zA-Z0-9-_]+)\.([a-zA-Z0-9-_]+)$/, {
82
- message: "Not a valid compact jwt"
83
- });
84
- var zJwtConfirmationPayload = z3.looseObject({
85
- // RFC9449. jwk thumbprint of the dpop public key to which the access token is bound
86
- jkt: z3.string().optional(),
87
- jwk: zJwk.optional()
88
- });
89
- var zJwtPayload = z3.looseObject({
90
- aud: z3.string().optional(),
91
- cnf: zJwtConfirmationPayload.optional(),
92
- exp: z3.number().int().optional(),
93
- iat: z3.number().int().optional(),
94
- iss: z3.string().optional(),
95
- jti: z3.string().max(MAX_JTI_LENGTH).optional(),
96
- nbf: z3.number().int().optional(),
97
- nonce: z3.string().optional(),
98
- // Reserved for status parameters
99
- status: z3.record(z3.string(), z3.any()).optional(),
100
- // Reserved for OpenID Federation
101
- trust_chain: zTrustChain.optional()
102
- });
103
- var zJwtHeader = z3.looseObject({
104
- alg: zAlgValueNotNone,
105
- jwk: zJwk.optional(),
106
- kid: z3.string().optional(),
107
- // Reserved for OpenID Federation
108
- trust_chain: zTrustChain.optional(),
109
- typ: z3.string().optional(),
110
- x5c: zCertificateChain.optional()
111
- });
7
+ // src/access-token/z-grant-type.ts
8
+ import { z } from "zod";
9
+ var zAuthorizationCodeGrantIdentifier = z.literal("authorization_code");
10
+ var authorizationCodeGrantIdentifier = zAuthorizationCodeGrantIdentifier.value;
11
+ var zPreAuthorizedCodeGrantIdentifier = z.literal(
12
+ "urn:ietf:params:oauth:grant-type:pre-authorized_code"
13
+ );
14
+ var preAuthorizedCodeGrantIdentifier = zPreAuthorizedCodeGrantIdentifier.value;
15
+ var zRefreshTokenGrantIdentifier = z.literal("refresh_token");
16
+ var refreshTokenGrantIdentifier = zRefreshTokenGrantIdentifier.value;
112
17
 
113
- // src/common/jwt/decode-jwt-header.ts
114
- function decodeJwtHeader(options) {
115
- const jwtParts = options.jwt.split(".");
116
- if (jwtParts.length <= 2) {
117
- throw new Oauth2JwtParseError(
118
- formatError(
119
- "Unable to decode because Jwt is not a valid!",
120
- options.errorMessagePrefix
121
- )
122
- );
123
- }
124
- const [headerPart] = jwtParts;
125
- let headerJson;
126
- try {
127
- headerJson = stringToJsonWithErrorHandling(
128
- encodeToUtf8String(decodeBase64(headerPart)),
129
- formatError(
130
- "Unable to parse jwt header to JSON",
131
- options.errorMessagePrefix
132
- )
133
- );
134
- } catch (error) {
135
- throw new Oauth2JwtParseError(
136
- formatError(
137
- `Error parsing JWT. ${error instanceof Error ? error.message : ""}`,
138
- options.errorMessagePrefix
139
- )
140
- );
141
- }
142
- const header = parseWithErrorHandling(
143
- options.headerSchema ?? zJwtHeader,
144
- headerJson,
145
- formatError("Invalid JWT header", options.errorMessagePrefix)
146
- );
147
- return {
148
- header
149
- };
150
- }
151
- function jwtHeaderFromJwtSigner(signer) {
152
- if (signer.method === "did") {
153
- return {
154
- alg: signer.alg,
155
- kid: signer.didUrl
156
- };
157
- }
158
- if (signer.method === "federation") {
159
- return {
160
- alg: signer.alg,
161
- kid: signer.kid,
162
- trust_chain: signer.trustChain
163
- };
164
- }
165
- if (signer.method === "jwk") {
18
+ // src/access-token/create-token-request.ts
19
+ var createTokenRequestV1_4 = (options) => {
20
+ if (options.grantType === refreshTokenGrantIdentifier) {
166
21
  return {
167
- alg: signer.alg,
168
- jwk: signer.publicJwk
22
+ ...options.additionalRequestPayload,
23
+ grant_type: refreshTokenGrantIdentifier,
24
+ refresh_token: options.refreshToken,
25
+ scope: options.scope
169
26
  };
170
27
  }
171
- if (signer.method === "x5c") {
28
+ return {
29
+ ...options.additionalRequestPayload,
30
+ code: options.authorizationCode,
31
+ code_verifier: options.pkceCodeVerifier,
32
+ grant_type: authorizationCodeGrantIdentifier,
33
+ redirect_uri: options.redirectUri
34
+ };
35
+ };
36
+ function createTokenRequestAPTITUDE(options) {
37
+ if (options.grantType === preAuthorizedCodeGrantIdentifier) {
172
38
  return {
173
- alg: signer.alg,
174
- kid: signer.kid,
175
- trust_chain: signer.trustChain,
176
- x5c: signer.x5c
39
+ ...options.additionalRequestPayload,
40
+ grant_type: preAuthorizedCodeGrantIdentifier,
41
+ "pre-authorized_code": options.preAuthorizedCode,
42
+ tx_code: options.txCode
177
43
  };
178
44
  }
179
- return { alg: signer.alg };
45
+ return createTokenRequestV1_4(options);
46
+ }
47
+ var dispatchCreateTokenRequest = createVersionDispatcher({
48
+ [ItWalletSpecsVersion.APTITUDE]: (o) => createTokenRequestAPTITUDE(o),
49
+ [ItWalletSpecsVersion.V1_0]: (o) => createTokenRequestV1_4(o),
50
+ [ItWalletSpecsVersion.V1_3]: (o) => createTokenRequestV1_4(o),
51
+ [ItWalletSpecsVersion.V1_4]: (o) => createTokenRequestV1_4(o)
52
+ });
53
+ function createTokenRequest(options) {
54
+ return dispatchCreateTokenRequest(options);
180
55
  }
181
56
 
57
+ // src/access-token/create-token-response.ts
58
+ import {
59
+ HashAlgorithm,
60
+ ItWalletSpecsVersion as ItWalletSpecsVersion2,
61
+ addSecondsToDate,
62
+ calculateJwkThumbprint,
63
+ createVersionDispatcher as createVersionDispatcher2,
64
+ dateToSeconds,
65
+ jwtHeaderFromJwtSigner,
66
+ parseWithErrorHandling
67
+ } from "@pagopa/io-wallet-utils";
68
+
182
69
  // src/errors.ts
183
70
  var Oauth2Error = class extends Error {
184
71
  statusCode;
185
72
  constructor(message, options) {
186
- super(message, options);
73
+ const errorMessage = message ?? "Unknown error occurred.";
74
+ const causeMessage = options?.cause instanceof Error ? ` ${options.cause.message}` : options?.cause ? ` ${String(options.cause)}` : "";
75
+ super(`${errorMessage}${causeMessage}`, options);
187
76
  this.name = "Oauth2Error";
188
77
  this.statusCode = options?.statusCode;
189
78
  }
@@ -234,70 +123,87 @@ var ClientAttestationError = class extends Oauth2Error {
234
123
  };
235
124
 
236
125
  // src/access-token/z-token.ts
237
- import { z as z4 } from "zod";
238
- var zAccessTokenRequest = z4.discriminatedUnion("grant_type", [
239
- z4.object({
240
- code: z4.string().nonempty(),
241
- code_verifier: z4.string().nonempty(),
242
- grant_type: z4.literal("authorization_code"),
243
- redirect_uri: z4.string().nonempty()
244
- }),
245
- z4.object({
246
- grant_type: z4.literal("refresh_token"),
247
- refresh_token: z4.string().nonempty(),
248
- scope: z4.string().optional()
249
- })
126
+ import {
127
+ MAX_JTI_LENGTH,
128
+ zJwtHeader,
129
+ zJwtPayload
130
+ } from "@pagopa/io-wallet-utils";
131
+ import { z as z2 } from "zod";
132
+ var zPreAuthorizedCodeTokenRequest = z2.object({
133
+ grant_type: zPreAuthorizedCodeGrantIdentifier,
134
+ "pre-authorized_code": z2.string().nonempty(),
135
+ tx_code: z2.string().optional()
136
+ });
137
+ var zAuthorizationCodeTokenRequest = z2.object({
138
+ code: z2.string().nonempty(),
139
+ code_verifier: z2.string().nonempty(),
140
+ grant_type: zAuthorizationCodeGrantIdentifier,
141
+ redirect_uri: z2.string().nonempty()
142
+ });
143
+ var zRefreshTokenTokenRequest = z2.object({
144
+ grant_type: zRefreshTokenGrantIdentifier,
145
+ refresh_token: z2.string().nonempty(),
146
+ scope: z2.string().optional()
147
+ });
148
+ var zAccessTokenRequest = z2.discriminatedUnion("grant_type", [
149
+ zAuthorizationCodeTokenRequest,
150
+ zRefreshTokenTokenRequest
151
+ ]);
152
+ var zAccessTokenRequestAPTITUDE = z2.discriminatedUnion("grant_type", [
153
+ zAuthorizationCodeTokenRequest,
154
+ zRefreshTokenTokenRequest,
155
+ zPreAuthorizedCodeTokenRequest
250
156
  ]);
251
- var zAccessTokenResponse = z4.looseObject({
252
- access_token: z4.string(),
253
- authorization_details: z4.array(
254
- z4.looseObject({
255
- credential_configuration_id: z4.optional(z4.string()),
256
- credential_identifiers: z4.optional(z4.array(z4.string())),
257
- type: z4.literal("openid_credential")
157
+ var zAccessTokenResponse = z2.looseObject({
158
+ access_token: z2.string(),
159
+ authorization_details: z2.array(
160
+ z2.looseObject({
161
+ credential_configuration_id: z2.optional(z2.string()),
162
+ credential_identifiers: z2.optional(z2.array(z2.string())),
163
+ type: z2.literal("openid_credential")
258
164
  })
259
165
  ).optional(),
260
- expires_in: z4.optional(z4.number().int()),
261
- refresh_token: z4.optional(z4.string()),
262
- token_type: z4.union([z4.literal("Bearer"), z4.literal("DPoP")])
166
+ expires_in: z2.optional(z2.number().int()),
167
+ refresh_token: z2.optional(z2.string()),
168
+ token_type: z2.union([z2.literal("Bearer"), z2.literal("DPoP")])
263
169
  });
264
- var zAccessTokenProfileJwtHeader = z4.looseObject({
170
+ var zAccessTokenProfileJwtHeader = z2.looseObject({
265
171
  ...zJwtHeader.shape,
266
- typ: z4.enum(["application/at+jwt", "at+jwt"])
172
+ typ: z2.enum(["application/at+jwt", "at+jwt"])
267
173
  });
268
- var zAccessTokenProfileJwtPayload = z4.looseObject({
174
+ var zAccessTokenProfileJwtPayload = z2.looseObject({
269
175
  ...zJwtPayload.shape,
270
- aud: z4.string(),
271
- client_id: z4.string(),
272
- cnf: z4.object({
273
- jkt: z4.string()
176
+ aud: z2.string(),
177
+ client_id: z2.string(),
178
+ cnf: z2.object({
179
+ jkt: z2.string()
274
180
  }).optional(),
275
- exp: z4.number(),
276
- iat: z4.number(),
277
- iss: z4.string(),
278
- jti: z4.string().max(MAX_JTI_LENGTH),
279
- nbf: z4.number().optional(),
280
- scope: z4.string().optional(),
281
- sub: z4.string()
181
+ exp: z2.number(),
182
+ iat: z2.number(),
183
+ iss: z2.string(),
184
+ jti: z2.string().max(MAX_JTI_LENGTH),
185
+ nbf: z2.number().optional(),
186
+ scope: z2.string().optional(),
187
+ sub: z2.string()
282
188
  });
283
- var zRefreshTokenProfileJwtHeader = z4.looseObject({
189
+ var zRefreshTokenProfileJwtHeader = z2.looseObject({
284
190
  ...zJwtHeader.shape,
285
- kid: z4.string(),
286
- typ: z4.literal("rt+jwt")
191
+ kid: z2.string(),
192
+ typ: z2.literal("rt+jwt")
287
193
  });
288
- var zRefreshTokenProfileJwtPayload = z4.looseObject({
194
+ var zRefreshTokenProfileJwtPayload = z2.looseObject({
289
195
  ...zJwtPayload.shape,
290
- aud: z4.string(),
291
- client_id: z4.string(),
292
- cnf: z4.object({
293
- jkt: z4.string()
196
+ aud: z2.string(),
197
+ client_id: z2.string(),
198
+ cnf: z2.object({
199
+ jkt: z2.string()
294
200
  }),
295
- exp: z4.number().int(),
296
- iat: z4.number().int(),
297
- iss: z4.string(),
298
- jti: z4.string().max(MAX_JTI_LENGTH),
299
- nbf: z4.number().int(),
300
- sub: z4.string()
201
+ exp: z2.number().int(),
202
+ iat: z2.number().int(),
203
+ iss: z2.string(),
204
+ jti: z2.string().max(MAX_JTI_LENGTH),
205
+ nbf: z2.number().int(),
206
+ sub: z2.string()
301
207
  });
302
208
 
303
209
  // src/access-token/create-token-response.ts
@@ -326,7 +232,7 @@ function resolveRefreshTokenKid(signer) {
326
232
  }
327
233
  return void 0;
328
234
  }
329
- async function createAccessTokenResponse(options) {
235
+ async function createAccessTokenResponseV1_4(options) {
330
236
  try {
331
237
  const now = options.now ?? /* @__PURE__ */ new Date();
332
238
  if (options.tokenType === "DPoP" && !options.dpop) {
@@ -353,11 +259,11 @@ async function createAccessTokenResponse(options) {
353
259
  now,
354
260
  options.expiresInSeconds
355
261
  );
356
- const header = parseWithErrorHandling2(zAccessTokenProfileJwtHeader, {
262
+ const header = parseWithErrorHandling(zAccessTokenProfileJwtHeader, {
357
263
  ...jwtHeaderFromJwtSigner(options.signer),
358
264
  typ: "at+jwt"
359
265
  });
360
- const payload = parseWithErrorHandling2(zAccessTokenProfileJwtPayload, {
266
+ const payload = parseWithErrorHandling(zAccessTokenProfileJwtPayload, {
361
267
  ...options.additionalPayload,
362
268
  aud: options.audience,
363
269
  client_id: options.clientId,
@@ -382,7 +288,7 @@ async function createAccessTokenResponse(options) {
382
288
  "Unable to resolve a kid for the Refresh Token JOSE header. Provide signer.kid or a publicJwk.kid."
383
289
  );
384
290
  }
385
- const refreshTokenHeader = parseWithErrorHandling2(
291
+ const refreshTokenHeader = parseWithErrorHandling(
386
292
  zRefreshTokenProfileJwtHeader,
387
293
  {
388
294
  alg: options.signer.alg,
@@ -390,7 +296,7 @@ async function createAccessTokenResponse(options) {
390
296
  typ: "rt+jwt"
391
297
  }
392
298
  );
393
- const refreshTokenPayload = parseWithErrorHandling2(
299
+ const refreshTokenPayload = parseWithErrorHandling(
394
300
  zRefreshTokenProfileJwtPayload,
395
301
  {
396
302
  aud: options.authorizationServer,
@@ -415,7 +321,7 @@ async function createAccessTokenResponse(options) {
415
321
  );
416
322
  refreshToken = refreshTokenSignResult.jwt;
417
323
  }
418
- const accessTokenResponse = parseWithErrorHandling2(zAccessTokenResponse, {
324
+ const accessTokenResponse = parseWithErrorHandling(zAccessTokenResponse, {
419
325
  ...options.additionalPayload,
420
326
  access_token: jwt,
421
327
  expires_in: options.expiresInSeconds,
@@ -432,18 +338,29 @@ async function createAccessTokenResponse(options) {
432
338
  );
433
339
  }
434
340
  }
341
+ var dispatchCreateAccessTokenResponse = createVersionDispatcher2({
342
+ [ItWalletSpecsVersion2.APTITUDE]: (o) => createAccessTokenResponseV1_4(o),
343
+ [ItWalletSpecsVersion2.V1_0]: (o) => createAccessTokenResponseV1_4(o),
344
+ [ItWalletSpecsVersion2.V1_3]: (o) => createAccessTokenResponseV1_4(o),
345
+ [ItWalletSpecsVersion2.V1_4]: (o) => createAccessTokenResponseV1_4(o)
346
+ });
347
+ function createAccessTokenResponse(options) {
348
+ return dispatchCreateAccessTokenResponse(options);
349
+ }
435
350
 
436
351
  // src/access-token/fetch-token-response.ts
437
352
  import {
438
353
  CONTENT_TYPES,
439
354
  HEADERS,
355
+ ItWalletSpecsVersion as ItWalletSpecsVersion3,
440
356
  UnexpectedStatusCodeError,
441
357
  ValidationError,
442
358
  createFetcher,
359
+ createVersionDispatcher as createVersionDispatcher3,
443
360
  hasStatusOrThrow,
444
- parseWithErrorHandling as parseWithErrorHandling3
361
+ parseWithErrorHandling as parseWithErrorHandling2
445
362
  } from "@pagopa/io-wallet-utils";
446
- async function fetchTokenResponse(options) {
363
+ async function fetchTokenResponseV1_4(options) {
447
364
  try {
448
365
  const fetch = createFetcher(options.callbacks.fetch);
449
366
  const tokenResponse = await fetch(options.accessTokenEndpoint, {
@@ -457,7 +374,7 @@ async function fetchTokenResponse(options) {
457
374
  method: "POST"
458
375
  });
459
376
  await hasStatusOrThrow(200, UnexpectedStatusCodeError)(tokenResponse);
460
- return parseWithErrorHandling3(
377
+ return parseWithErrorHandling2(
461
378
  zAccessTokenResponse,
462
379
  await tokenResponse.json(),
463
380
  "Failed to parse token response"
@@ -482,105 +399,53 @@ function toURLSearchParams(data) {
482
399
  });
483
400
  return params;
484
401
  }
402
+ var dispatchFetchTokenResponse = createVersionDispatcher3({
403
+ [ItWalletSpecsVersion3.APTITUDE]: (o) => fetchTokenResponseV1_4(o),
404
+ [ItWalletSpecsVersion3.V1_0]: (o) => fetchTokenResponseV1_4(
405
+ o
406
+ ),
407
+ [ItWalletSpecsVersion3.V1_3]: (o) => fetchTokenResponseV1_4(
408
+ o
409
+ ),
410
+ [ItWalletSpecsVersion3.V1_4]: (o) => fetchTokenResponseV1_4(
411
+ o
412
+ )
413
+ });
414
+ function fetchTokenResponse(options) {
415
+ return dispatchFetchTokenResponse(options);
416
+ }
485
417
 
486
418
  // src/access-token/parse-token-request.ts
487
419
  import {
420
+ ItWalletSpecsVersion as ItWalletSpecsVersion5,
421
+ createVersionDispatcher as createVersionDispatcher5,
488
422
  formatZodError
489
423
  } from "@pagopa/io-wallet-utils";
490
424
 
491
425
  // src/client-attestation/wallet-attestation.ts
492
- import { zCompactJwt as zCompactJwt2 } from "@openid4vc/oauth2";
493
426
  import {
494
- ItWalletSpecsVersion,
495
- createVersionDispatcher
427
+ ItWalletSpecsVersion as ItWalletSpecsVersion4,
428
+ createVersionDispatcher as createVersionDispatcher4,
429
+ zCompactJwt
496
430
  } from "@pagopa/io-wallet-utils";
497
431
 
498
432
  // src/client-attestation/types.ts
499
- import z5 from "zod";
500
- var zOauthClientAttestationHeader = z5.literal(
433
+ import z3 from "zod";
434
+ var zOauthClientAttestationHeader = z3.literal(
501
435
  "OAuth-Client-Attestation"
502
436
  );
503
437
  var oauthClientAttestationHeader = zOauthClientAttestationHeader.value;
504
- var zOauthClientAttestationPopHeader = z5.literal(
438
+ var zOauthClientAttestationPopHeader = z3.literal(
505
439
  "OAuth-Client-Attestation-PoP"
506
440
  );
507
441
  var oauthClientAttestationPopHeader = zOauthClientAttestationPopHeader.value;
508
442
 
509
443
  // src/client-attestation/verify-wallet-attestation-jwt-base.ts
510
- import { jwtSignerFromJwt, verifyJwt } from "@openid4vc/oauth2";
511
-
512
- // src/common/jwt/decode-jwt.ts
513
- import { Oauth2JwtParseError as Oauth2JwtParseError2 } from "@openid4vc/oauth2";
514
444
  import {
515
- decodeBase64 as decodeBase642,
516
- encodeToUtf8String as encodeToUtf8String2,
517
- formatError as formatError2,
518
- parseWithErrorHandling as parseWithErrorHandling4,
519
- stringToJsonWithErrorHandling as stringToJsonWithErrorHandling2
445
+ decodeJwt,
446
+ jwtSignerFromJwt,
447
+ verifyJwt
520
448
  } from "@pagopa/io-wallet-utils";
521
- function decodeJwt(options) {
522
- const jwtParts = options.jwt.split(".");
523
- if (jwtParts.length !== 3) {
524
- throw new Oauth2JwtParseError2(
525
- formatError2(
526
- "Unable to decode because Jwt is not a valid!",
527
- options.errorMessagePrefix
528
- )
529
- );
530
- }
531
- let payloadJson;
532
- try {
533
- const payloadPart = jwtParts[1];
534
- if (payloadPart === void 0) {
535
- throw new Oauth2JwtParseError2(
536
- formatError2(
537
- "Unable to decode because Jwt is not a valid!",
538
- options.errorMessagePrefix
539
- )
540
- );
541
- }
542
- payloadJson = stringToJsonWithErrorHandling2(
543
- encodeToUtf8String2(decodeBase642(payloadPart)),
544
- formatError2(
545
- "Unable to parse jwt payload to JSON",
546
- options.errorMessagePrefix
547
- )
548
- );
549
- } catch (error) {
550
- throw new Oauth2JwtParseError2(
551
- formatError2(
552
- `Error parsing JWT. ${error instanceof Error ? error.message : ""}`,
553
- options.errorMessagePrefix
554
- )
555
- );
556
- }
557
- const signaturePart = jwtParts[2];
558
- if (signaturePart === void 0) {
559
- throw new Oauth2JwtParseError2(
560
- formatError2(
561
- "Unable to decode because Jwt is not a valid!",
562
- options.errorMessagePrefix
563
- )
564
- );
565
- }
566
- const { header } = decodeJwtHeader({
567
- errorMessagePrefix: options.errorMessagePrefix,
568
- headerSchema: options.headerSchema,
569
- jwt: options.jwt
570
- });
571
- const payload = parseWithErrorHandling4(
572
- options.payloadSchema ?? zJwtPayload,
573
- payloadJson,
574
- formatError2("Invalid JWT payload", options.errorMessagePrefix)
575
- );
576
- return {
577
- header,
578
- payload,
579
- signature: signaturePart
580
- };
581
- }
582
-
583
- // src/client-attestation/verify-wallet-attestation-jwt-base.ts
584
449
  async function verifyWalletAttestationBase(options, headerSchema, payloadSchema) {
585
450
  const { header, payload } = decodeJwt({
586
451
  errorMessagePrefix: "Error decoding wallet attestation JWT:",
@@ -601,27 +466,33 @@ async function verifyWalletAttestationBase(options, headerSchema, payloadSchema)
601
466
  }
602
467
 
603
468
  // src/client-attestation/v1.0/z-wallet-attestation.ts
604
- import { z as z6 } from "zod";
605
- var zWalletAttestationJwtHeaderV1_0 = z6.looseObject({
606
- ...zJwtHeader.shape,
469
+ import {
470
+ zJwk,
471
+ zJwtHeader as zJwtHeader2,
472
+ zJwtPayload as zJwtPayload2,
473
+ zTrustChain
474
+ } from "@pagopa/io-wallet-utils";
475
+ import { z as z4 } from "zod";
476
+ var zWalletAttestationJwtHeaderV1_0 = z4.looseObject({
477
+ ...zJwtHeader2.shape,
607
478
  trust_chain: zTrustChain,
608
479
  // REQUIRED in v1.0
609
- typ: z6.literal("oauth-client-attestation+jwt")
480
+ typ: z4.literal("oauth-client-attestation+jwt")
610
481
  });
611
- var zWalletAttestationJwtPayloadV1_0 = z6.looseObject({
612
- ...zJwtPayload.shape,
613
- aal: z6.string(),
614
- cnf: z6.object({
482
+ var zWalletAttestationJwtPayloadV1_0 = z4.looseObject({
483
+ ...zJwtPayload2.shape,
484
+ aal: z4.string(),
485
+ cnf: z4.object({
615
486
  jwk: zJwk
616
487
  }),
617
- exp: z6.number(),
618
- iat: z6.number(),
619
- iss: z6.string(),
620
- sub: z6.string(),
621
- wallet_link: z6.url().optional(),
622
- wallet_name: z6.string().optional()
488
+ exp: z4.number(),
489
+ iat: z4.number(),
490
+ iss: z4.string(),
491
+ sub: z4.string(),
492
+ wallet_link: z4.url().optional(),
493
+ wallet_name: z4.string().optional()
623
494
  });
624
- var zWalletAttestationJwtV1_0 = z6.string().min(1);
495
+ var zWalletAttestationJwtV1_0 = z4.string().min(1);
625
496
 
626
497
  // src/client-attestation/v1.0/verify-wallet-attestation-jwt.ts
627
498
  async function verifyWalletAttestationJwt(options) {
@@ -633,37 +504,44 @@ async function verifyWalletAttestationJwt(options) {
633
504
  }
634
505
 
635
506
  // src/client-attestation/v1.3/z-wallet-attestation.ts
636
- import { z as z7 } from "zod";
637
- var zWalletAttestationJwtHeaderV1_3 = z7.looseObject({
638
- ...zJwtHeader.shape,
639
- trust_chain: zTrustChain.optional(),
507
+ import {
508
+ zCertificateChain,
509
+ zJwk as zJwk2,
510
+ zJwtHeader as zJwtHeader3,
511
+ zJwtPayload as zJwtPayload3,
512
+ zTrustChain as zTrustChain2
513
+ } from "@pagopa/io-wallet-utils";
514
+ import { z as z5 } from "zod";
515
+ var zWalletAttestationJwtHeaderV1_3 = z5.looseObject({
516
+ ...zJwtHeader3.shape,
517
+ trust_chain: zTrustChain2.optional(),
640
518
  // OPTIONAL in v1.3
641
- typ: z7.literal("oauth-client-attestation+jwt"),
519
+ typ: z5.literal("oauth-client-attestation+jwt"),
642
520
  x5c: zCertificateChain
643
521
  // REQUIRED in v1.3
644
522
  });
645
- var zWalletAttestationJwtPayloadV1_3 = z7.looseObject({
646
- ...zJwtPayload.shape,
647
- cnf: z7.object({
648
- jwk: zJwk
523
+ var zWalletAttestationJwtPayloadV1_3 = z5.looseObject({
524
+ ...zJwtPayload3.shape,
525
+ cnf: z5.object({
526
+ jwk: zJwk2
649
527
  }),
650
- exp: z7.number(),
651
- iat: z7.number(),
652
- iss: z7.string(),
653
- nbf: z7.number().optional(),
528
+ exp: z5.number(),
529
+ iat: z5.number(),
530
+ iss: z5.string(),
531
+ nbf: z5.number().optional(),
654
532
  // NEW in v1.3
655
- status: z7.object({
656
- status_list: z7.object({
657
- idx: z7.number().int(),
658
- uri: z7.string()
533
+ status: z5.object({
534
+ status_list: z5.object({
535
+ idx: z5.number().int(),
536
+ uri: z5.string()
659
537
  })
660
538
  }).optional(),
661
539
  // NEW in v1.3 - status object for revocation
662
- sub: z7.string(),
663
- wallet_link: z7.url().optional(),
664
- wallet_name: z7.string().optional()
540
+ sub: z5.string(),
541
+ wallet_link: z5.url().optional(),
542
+ wallet_name: z5.string().optional()
665
543
  });
666
- var zWalletAttestationJwtV1_3 = z7.string().min(1);
544
+ var zWalletAttestationJwtV1_3 = z5.string().min(1);
667
545
 
668
546
  // src/client-attestation/v1.3/verify-wallet-attestation-jwt.ts
669
547
  async function verifyWalletAttestationJwt2(options) {
@@ -675,28 +553,35 @@ async function verifyWalletAttestationJwt2(options) {
675
553
  }
676
554
 
677
555
  // src/client-attestation/v1.4/z-wallet-attestation.ts
678
- import { z as z8 } from "zod";
679
- var zWalletAttestationJwtHeaderV1_4 = z8.looseObject({
680
- ...zJwtHeader.shape,
681
- kid: z8.string(),
682
- trust_chain: zTrustChain.optional(),
683
- typ: z8.literal("oauth-client-attestation+jwt"),
684
- x5c: zCertificateChain
556
+ import {
557
+ zCertificateChain as zCertificateChain2,
558
+ zJwk as zJwk3,
559
+ zJwtHeader as zJwtHeader4,
560
+ zJwtPayload as zJwtPayload4,
561
+ zTrustChain as zTrustChain3
562
+ } from "@pagopa/io-wallet-utils";
563
+ import { z as z6 } from "zod";
564
+ var zWalletAttestationJwtHeaderV1_4 = z6.looseObject({
565
+ ...zJwtHeader4.shape,
566
+ kid: z6.string(),
567
+ trust_chain: zTrustChain3.optional(),
568
+ typ: z6.literal("oauth-client-attestation+jwt"),
569
+ x5c: zCertificateChain2
685
570
  });
686
- var zWalletAttestationJwtPayloadV1_4 = z8.looseObject({
687
- ...zJwtPayload.shape,
688
- cnf: z8.object({
689
- jwk: zJwk
571
+ var zWalletAttestationJwtPayloadV1_4 = z6.looseObject({
572
+ ...zJwtPayload4.shape,
573
+ cnf: z6.object({
574
+ jwk: zJwk3
690
575
  }),
691
- exp: z8.number().int(),
692
- iat: z8.number().int(),
693
- iss: z8.string(),
694
- nbf: z8.number().optional(),
695
- sub: z8.string(),
696
- wallet_link: z8.url(),
697
- wallet_name: z8.string()
576
+ exp: z6.number().int(),
577
+ iat: z6.number().int(),
578
+ iss: z6.string(),
579
+ nbf: z6.number().optional(),
580
+ sub: z6.string(),
581
+ wallet_link: z6.url(),
582
+ wallet_name: z6.string()
698
583
  });
699
- var zWalletAttestationJwtV1_4 = z8.string().min(1);
584
+ var zWalletAttestationJwtV1_4 = z6.string().min(1);
700
585
 
701
586
  // src/client-attestation/v1.4/verify-wallet-attestation-jwt.ts
702
587
  async function verifyWalletAttestationJwt3(options) {
@@ -708,10 +593,11 @@ async function verifyWalletAttestationJwt3(options) {
708
593
  }
709
594
 
710
595
  // src/client-attestation/wallet-attestation.ts
711
- var dispatchVerifyWalletAttestationJwt = createVersionDispatcher({
712
- [ItWalletSpecsVersion.V1_0]: (o) => verifyWalletAttestationJwt(o),
713
- [ItWalletSpecsVersion.V1_3]: (o) => verifyWalletAttestationJwt2(o),
714
- [ItWalletSpecsVersion.V1_4]: (o) => verifyWalletAttestationJwt3(o)
596
+ var dispatchVerifyWalletAttestationJwt = createVersionDispatcher4({
597
+ [ItWalletSpecsVersion4.APTITUDE]: (o) => verifyWalletAttestationJwt3(o),
598
+ [ItWalletSpecsVersion4.V1_0]: (o) => verifyWalletAttestationJwt(o),
599
+ [ItWalletSpecsVersion4.V1_3]: (o) => verifyWalletAttestationJwt2(o),
600
+ [ItWalletSpecsVersion4.V1_4]: (o) => verifyWalletAttestationJwt3(o)
715
601
  });
716
602
  async function verifyWalletAttestationJwt4(options) {
717
603
  return dispatchVerifyWalletAttestationJwt(options);
@@ -727,7 +613,7 @@ function extractClientAttestationJwtsFromHeaders(headers) {
727
613
  if (!walletAttestationHeader || !clientAttestationPopHeader) {
728
614
  return { valid: false };
729
615
  }
730
- if (!zCompactJwt2.safeParse(walletAttestationHeader).success || !zCompactJwt2.safeParse(clientAttestationPopHeader).success) {
616
+ if (!zCompactJwt.safeParse(walletAttestationHeader).success || !zCompactJwt.safeParse(clientAttestationPopHeader).success) {
731
617
  return { valid: false };
732
618
  }
733
619
  return {
@@ -740,14 +626,12 @@ function extractClientAttestationJwtsFromHeaders(headers) {
740
626
  // src/token-dpop/create-token-dpop.ts
741
627
  import {
742
628
  HashAlgorithm as HashAlgorithm2,
743
- zCompactJwt as zCompactJwt3
744
- } from "@openid4vc/oauth2";
745
- import {
746
629
  ValidationError as ValidationError2,
747
630
  dateToSeconds as dateToSeconds2,
748
631
  decodeUtf8String,
749
632
  encodeToBase64Url,
750
- parseWithErrorHandling as parseWithErrorHandling5
633
+ parseWithErrorHandling as parseWithErrorHandling3,
634
+ zCompactJwt as zCompactJwt2
751
635
  } from "@pagopa/io-wallet-utils";
752
636
  import { Base64 } from "js-base64";
753
637
 
@@ -760,20 +644,26 @@ var htuFromRequestUrl = (requestUrl) => {
760
644
  };
761
645
 
762
646
  // src/token-dpop/z-dpop.ts
763
- import { zHttpMethod } from "@pagopa/io-wallet-utils";
764
- import z9 from "zod";
765
- var zDpopJwtPayload = z9.looseObject({
766
- ...zJwtPayload.shape,
767
- ath: z9.optional(z9.string()),
647
+ import {
648
+ MAX_JTI_LENGTH as MAX_JTI_LENGTH2,
649
+ zHttpMethod,
650
+ zJwk as zJwk4,
651
+ zJwtHeader as zJwtHeader5,
652
+ zJwtPayload as zJwtPayload5
653
+ } from "@pagopa/io-wallet-utils";
654
+ import z7 from "zod";
655
+ var zDpopJwtPayload = z7.looseObject({
656
+ ...zJwtPayload5.shape,
657
+ ath: z7.optional(z7.string()),
768
658
  htm: zHttpMethod,
769
- htu: z9.url(),
770
- iat: z9.number().int().nonnegative(),
771
- jti: z9.string().max(MAX_JTI_LENGTH)
659
+ htu: z7.url(),
660
+ iat: z7.number().int().nonnegative(),
661
+ jti: z7.string().max(MAX_JTI_LENGTH2)
772
662
  });
773
- var zDpopJwtHeader = z9.looseObject({
774
- ...zJwtHeader.shape,
775
- jwk: zJwk,
776
- typ: z9.literal("dpop+jwt")
663
+ var zDpopJwtHeader = z7.looseObject({
664
+ ...zJwtHeader5.shape,
665
+ jwk: zJwk4,
666
+ typ: z7.literal("dpop+jwt")
777
667
  });
778
668
 
779
669
  // src/token-dpop/create-token-dpop.ts
@@ -794,12 +684,12 @@ async function createTokenDPoP(options) {
794
684
  "Error: neither a default jti nor a generateRandom callback have been provided"
795
685
  );
796
686
  }
797
- const header = parseWithErrorHandling5(zDpopJwtHeader, {
687
+ const header = parseWithErrorHandling3(zDpopJwtHeader, {
798
688
  alg: options.signer.alg,
799
689
  jwk: options.signer.publicJwk,
800
690
  typ: "dpop+jwt"
801
691
  });
802
- const payload = parseWithErrorHandling5(zDpopJwtPayload, {
692
+ const payload = parseWithErrorHandling3(zDpopJwtPayload, {
803
693
  ath,
804
694
  htm: options.tokenRequest.method,
805
695
  htu: htuFromRequestUrl(options.tokenRequest.url),
@@ -824,21 +714,14 @@ function extractDpopJwtFromHeaders(headers) {
824
714
  if (!dpopJwt) {
825
715
  return { valid: true };
826
716
  }
827
- if (!zCompactJwt3.safeParse(dpopJwt).success) {
717
+ if (!zCompactJwt2.safeParse(dpopJwt).success) {
828
718
  return { valid: false };
829
719
  }
830
720
  return { dpopJwt, valid: true };
831
721
  }
832
722
 
833
- // src/access-token/z-grant-type.ts
834
- import { z as z10 } from "zod";
835
- var zAuthorizationCodeGrantIdentifier = z10.literal("authorization_code");
836
- var authorizationCodeGrantIdentifier = zAuthorizationCodeGrantIdentifier.value;
837
- var zRefreshTokenGrantIdentifier = z10.literal("refresh_token");
838
- var refreshTokenGrantIdentifier = zRefreshTokenGrantIdentifier.value;
839
-
840
723
  // src/access-token/parse-token-request.ts
841
- function parseAccessTokenRequest(options) {
724
+ function parseAccessTokenRequestV1_4(options) {
842
725
  const validationResult = zAccessTokenRequest.safeParse(
843
726
  options.accessTokenRequest
844
727
  );
@@ -859,6 +742,25 @@ ${formatZodError(validationResult.error)}`
859
742
  ...securityHeaders
860
743
  };
861
744
  }
745
+ function parseAccessTokenRequestAPTITUDE(options) {
746
+ const validationResult = zAccessTokenRequestAPTITUDE.safeParse(
747
+ options.accessTokenRequest
748
+ );
749
+ if (!validationResult.success) {
750
+ throw new Oauth2Error(
751
+ `Access token request validation failed:
752
+ ${formatZodError(validationResult.error)}`
753
+ );
754
+ }
755
+ const accessTokenRequest = validationResult.data;
756
+ const grant = parseGrantParametersAPTITUDE(accessTokenRequest);
757
+ const securityHeaders = parseSecurityHeaders(options.request.headers);
758
+ return {
759
+ accessTokenRequest,
760
+ grant,
761
+ ...securityHeaders
762
+ };
763
+ }
862
764
  function parseGrantParameters(accessTokenRequest) {
863
765
  if (accessTokenRequest.grant_type === authorizationCodeGrantIdentifier) {
864
766
  return {
@@ -876,6 +778,30 @@ function parseGrantParameters(accessTokenRequest) {
876
778
  `Unsupported grant type. Supported types are: '${authorizationCodeGrantIdentifier}', '${refreshTokenGrantIdentifier}'`
877
779
  );
878
780
  }
781
+ function parseGrantParametersAPTITUDE(accessTokenRequest) {
782
+ if (accessTokenRequest.grant_type === authorizationCodeGrantIdentifier) {
783
+ return {
784
+ code: accessTokenRequest.code,
785
+ grantType: authorizationCodeGrantIdentifier
786
+ };
787
+ }
788
+ if (accessTokenRequest.grant_type === refreshTokenGrantIdentifier) {
789
+ return {
790
+ grantType: refreshTokenGrantIdentifier,
791
+ refreshToken: accessTokenRequest.refresh_token
792
+ };
793
+ }
794
+ if (accessTokenRequest.grant_type === preAuthorizedCodeGrantIdentifier) {
795
+ return {
796
+ grantType: preAuthorizedCodeGrantIdentifier,
797
+ preAuthorizedCode: accessTokenRequest["pre-authorized_code"],
798
+ txCode: accessTokenRequest.tx_code
799
+ };
800
+ }
801
+ throw new Oauth2Error(
802
+ `Unsupported grant type. Supported types are: '${authorizationCodeGrantIdentifier}', '${refreshTokenGrantIdentifier}', '${preAuthorizedCodeGrantIdentifier}'`
803
+ );
804
+ }
879
805
  function parseSecurityHeaders(headers) {
880
806
  const extractedDpopJwt = extractDpopJwtFromHeaders(headers);
881
807
  if (!extractedDpopJwt.valid) {
@@ -910,47 +836,76 @@ function parseSecurityHeaders(headers) {
910
836
  dpop: { jwt: extractedDpopJwt.dpopJwt }
911
837
  };
912
838
  }
839
+ var dispatchParseTokenRequest = createVersionDispatcher5({
840
+ [ItWalletSpecsVersion5.APTITUDE]: (o) => parseAccessTokenRequestAPTITUDE(
841
+ o
842
+ ),
843
+ [ItWalletSpecsVersion5.V1_0]: (o) => parseAccessTokenRequestV1_4(
844
+ o
845
+ ),
846
+ [ItWalletSpecsVersion5.V1_3]: (o) => parseAccessTokenRequestV1_4(
847
+ o
848
+ ),
849
+ [ItWalletSpecsVersion5.V1_4]: (o) => parseAccessTokenRequestV1_4(
850
+ o
851
+ )
852
+ });
853
+ function parseAccessTokenRequest(options) {
854
+ return dispatchParseTokenRequest(options);
855
+ }
856
+
857
+ // src/access-token/verify-access-token-request.ts
858
+ import {
859
+ ItWalletSpecsVersion as ItWalletSpecsVersion7,
860
+ createVersionDispatcher as createVersionDispatcher6
861
+ } from "@pagopa/io-wallet-utils";
913
862
 
914
863
  // src/client-attestation/verify-client-attestation.ts
915
864
  import {
916
865
  HashAlgorithm as HashAlgorithm3,
917
866
  calculateJwkThumbprint as calculateJwkThumbprint2
918
- } from "@openid4vc/oauth2";
867
+ } from "@pagopa/io-wallet-utils";
919
868
 
920
869
  // src/client-attestation/client-attestation-pop.ts
921
- import { verifyJwt as verifyJwt2 } from "@openid4vc/oauth2";
922
870
  import {
923
- ItWalletSpecsVersion as ItWalletSpecsVersion2,
871
+ ItWalletSpecsVersion as ItWalletSpecsVersion6,
924
872
  addSecondsToDate as addSecondsToDate2,
925
873
  dateToSeconds as dateToSeconds3,
874
+ decodeJwt as decodeJwt2,
926
875
  encodeToBase64Url as encodeToBase64Url2,
927
- parseWithErrorHandling as parseWithErrorHandling6
876
+ parseWithErrorHandling as parseWithErrorHandling4,
877
+ verifyJwt as verifyJwt2
928
878
  } from "@pagopa/io-wallet-utils";
929
879
 
930
880
  // src/client-attestation/z-client-attestation-pop.ts
931
- import z11 from "zod";
881
+ import {
882
+ MAX_JTI_LENGTH as MAX_JTI_LENGTH3,
883
+ zJwtHeader as zJwtHeader6,
884
+ zJwtPayload as zJwtPayload6
885
+ } from "@pagopa/io-wallet-utils";
886
+ import z8 from "zod";
932
887
  var IT_WALLET_CLIENT_ATTESTATION_POP_ALLOWED_ALG_VALUES = [
933
888
  "ES256",
934
889
  "ES384",
935
890
  "ES512"
936
891
  ];
937
- var zItWalletClientAttestationPopJwtAlg = z11.enum(
892
+ var zItWalletClientAttestationPopJwtAlg = z8.enum(
938
893
  IT_WALLET_CLIENT_ATTESTATION_POP_ALLOWED_ALG_VALUES
939
894
  );
940
- var zItWalletClientAttestationPopJwtPayload = z11.looseObject({
941
- ...zJwtPayload.shape,
942
- aud: z11.string(),
943
- exp: z11.number().int().optional(),
944
- iat: z11.number().int(),
945
- iss: z11.string(),
946
- jti: z11.string().max(MAX_JTI_LENGTH),
947
- nonce: z11.string().optional()
895
+ var zItWalletClientAttestationPopJwtPayload = z8.looseObject({
896
+ ...zJwtPayload6.shape,
897
+ aud: z8.string(),
898
+ exp: z8.number().int().optional(),
899
+ iat: z8.number().int(),
900
+ iss: z8.string(),
901
+ jti: z8.string().max(MAX_JTI_LENGTH3),
902
+ nonce: z8.string().optional()
948
903
  });
949
- var zItWalletClientAttestationPopJwtTyp = z11.literal(
904
+ var zItWalletClientAttestationPopJwtTyp = z8.literal(
950
905
  "oauth-client-attestation-pop+jwt"
951
906
  );
952
- var zItWalletClientAttestationPopJwtHeader = z11.looseObject({
953
- ...zJwtHeader.shape,
907
+ var zItWalletClientAttestationPopJwtHeader = z8.looseObject({
908
+ ...zJwtHeader6.shape,
954
909
  typ: zItWalletClientAttestationPopJwtTyp
955
910
  });
956
911
 
@@ -964,7 +919,7 @@ function assertSupportedClientAttestationPopAlg(alg) {
964
919
  }
965
920
  async function verifyClientAttestationPopJwt(options) {
966
921
  try {
967
- const { header, payload } = decodeJwt({
922
+ const { header, payload } = decodeJwt2({
968
923
  errorMessagePrefix: "Error decoding client attestation PoP JWT:",
969
924
  headerSchema: zItWalletClientAttestationPopJwtHeader,
970
925
  jwt: options.clientAttestationPopJwt,
@@ -1000,7 +955,7 @@ async function verifyClientAttestationPopJwt(options) {
1000
955
  }
1001
956
  async function createClientAttestationPopJwt(options) {
1002
957
  try {
1003
- const clientAttestation = decodeJwt({
958
+ const clientAttestation = decodeJwt2({
1004
959
  errorMessagePrefix: "Error decoding client attestation JWT:",
1005
960
  jwt: options.clientAttestation
1006
961
  });
@@ -1033,14 +988,14 @@ async function createClientAttestationPopJwt(options) {
1033
988
  "Error: neither a default jti nor a generateRandom callback have been provided"
1034
989
  );
1035
990
  }
1036
- const payload = parseWithErrorHandling6(
991
+ const payload = parseWithErrorHandling4(
1037
992
  zItWalletClientAttestationPopJwtPayload,
1038
993
  {
1039
994
  aud: options.authorizationServer,
1040
995
  iat: dateToSeconds3(issuedAt),
1041
996
  iss: sub,
1042
997
  jti,
1043
- ...options.config.itWalletSpecsVersion === ItWalletSpecsVersion2.V1_0 ? {
998
+ ...options.config.itWalletSpecsVersion === ItWalletSpecsVersion6.V1_0 ? {
1044
999
  exp: dateToSeconds3(
1045
1000
  "expiresAt" in options && options.expiresAt ? options.expiresAt : addSecondsToDate2(issuedAt, 1 * 60)
1046
1001
  )
@@ -1106,9 +1061,10 @@ async function verifyClientAttestation(options) {
1106
1061
 
1107
1062
  // src/pkce.ts
1108
1063
  import {
1109
- HashAlgorithm as HashAlgorithm4
1110
- } from "@openid4vc/oauth2";
1111
- import { decodeUtf8String as decodeUtf8String2, encodeToBase64Url as encodeToBase64Url3 } from "@pagopa/io-wallet-utils";
1064
+ HashAlgorithm as HashAlgorithm4,
1065
+ decodeUtf8String as decodeUtf8String2,
1066
+ encodeToBase64Url as encodeToBase64Url3
1067
+ } from "@pagopa/io-wallet-utils";
1112
1068
  var PkceCodeChallengeMethod = {
1113
1069
  Plain: "plain",
1114
1070
  S256: "S256"
@@ -1170,15 +1126,14 @@ async function calculateCodeChallenge(options) {
1170
1126
  import {
1171
1127
  HashAlgorithm as HashAlgorithm5,
1172
1128
  calculateJwkThumbprint as calculateJwkThumbprint3,
1173
- verifyJwt as verifyJwt3
1174
- } from "@openid4vc/oauth2";
1175
- import {
1129
+ decodeJwt as decodeJwt3,
1176
1130
  decodeUtf8String as decodeUtf8String3,
1177
1131
  encodeToBase64Url as encodeToBase64Url4,
1132
+ verifyJwt as verifyJwt3,
1178
1133
  verifyJwtIatOrThrow
1179
1134
  } from "@pagopa/io-wallet-utils";
1180
1135
  async function verifyTokenDPoP(options) {
1181
- const { header, payload } = decodeJwt({
1136
+ const { header, payload } = decodeJwt3({
1182
1137
  errorMessagePrefix: "Error decoding access token DPoP JWT:",
1183
1138
  headerSchema: zDpopJwtHeader,
1184
1139
  jwt: options.dpopJwt,
@@ -1274,7 +1229,7 @@ async function verifyTokenDPoP(options) {
1274
1229
  }
1275
1230
 
1276
1231
  // src/access-token/verify-access-token-request.ts
1277
- async function verifyAccessTokenRequest(options) {
1232
+ async function verifyAccessTokenRequestV1_4(options) {
1278
1233
  if (options.dpop.expectedNonce === "") {
1279
1234
  throw new Oauth2Error(`Invalid 'dpop.expectedNonce' provided`);
1280
1235
  }
@@ -1303,12 +1258,44 @@ async function verifyAccessTokenRequest(options) {
1303
1258
  if (options.grant.code !== options.expectedCode) {
1304
1259
  throw new Oauth2Error(`Invalid 'code' provided`);
1305
1260
  }
1306
- if (options.codeExpiresAt) {
1307
- const now = options.now ?? /* @__PURE__ */ new Date();
1308
- if (now.getTime() > options.codeExpiresAt.getTime()) {
1309
- throw new Oauth2Error(`Expired 'code' provided`);
1310
- }
1261
+ verifyCodeExpiration(options.codeExpiresAt, options.now, "code");
1262
+ if (!header.jwk) {
1263
+ throw new Oauth2Error("DPoP header does not contain a JWK");
1264
+ }
1265
+ return {
1266
+ clientAttestation: clientAttestationResult,
1267
+ dpop: { jwk: header.jwk, jwkThumbprint }
1268
+ };
1269
+ }
1270
+ async function verifyAccessTokenRequestAPTITUDE(options) {
1271
+ if (options.dpop.expectedNonce === "") {
1272
+ throw new Oauth2Error(`Invalid 'dpop.expectedNonce' provided`);
1311
1273
  }
1274
+ if (!isPreAuthorizedCodeVerification(options)) {
1275
+ await verifyPkce({
1276
+ callbacks: options.callbacks,
1277
+ codeChallenge: options.pkce.codeChallenge,
1278
+ codeChallengeMethod: options.pkce.codeChallengeMethod,
1279
+ codeVerifier: options.pkce.codeVerifier
1280
+ });
1281
+ }
1282
+ const { header, jwkThumbprint } = await verifyTokenDPoP({
1283
+ allowedSigningAlgs: options.dpop.allowedSigningAlgs,
1284
+ callbacks: options.callbacks,
1285
+ dpopJwt: options.dpop.jwt,
1286
+ expectedNonce: options.dpop.expectedNonce,
1287
+ now: options.now,
1288
+ request: options.request
1289
+ });
1290
+ const clientAttestationResult = await verifyClientAttestation({
1291
+ authorizationServerMetadata: options.authorizationServerMetadata,
1292
+ callbacks: options.callbacks,
1293
+ clientAttestation: options.clientAttestation,
1294
+ config: options.config,
1295
+ dpopJwkThumbprint: jwkThumbprint,
1296
+ now: options.now
1297
+ });
1298
+ verifyGrantParameters(options);
1312
1299
  if (!header.jwk) {
1313
1300
  throw new Oauth2Error("DPoP header does not contain a JWK");
1314
1301
  }
@@ -1317,10 +1304,73 @@ async function verifyAccessTokenRequest(options) {
1317
1304
  dpop: { jwk: header.jwk, jwkThumbprint }
1318
1305
  };
1319
1306
  }
1307
+ function isPreAuthorizedCodeVerification(options) {
1308
+ return options.grant.grantType === preAuthorizedCodeGrantIdentifier;
1309
+ }
1310
+ function verifyGrantParameters(options) {
1311
+ if (isPreAuthorizedCodeVerification(options)) {
1312
+ if (options.grant.preAuthorizedCode !== options.expectedPreAuthorizedCode) {
1313
+ throw new Oauth2Error(`Invalid 'pre-authorized_code' provided`);
1314
+ }
1315
+ verifyTransactionCode(options.grant.txCode, options.expectedTxCode);
1316
+ verifyCodeExpiration(
1317
+ options.preAuthorizedCodeExpiresAt,
1318
+ options.now,
1319
+ "pre-authorized_code"
1320
+ );
1321
+ return;
1322
+ }
1323
+ if (options.grant.grantType !== authorizationCodeGrantIdentifier) {
1324
+ throw new Oauth2Error(
1325
+ "Only authorization_code and pre-authorized_code grants can be verified"
1326
+ );
1327
+ }
1328
+ if (options.grant.code !== options.expectedCode) {
1329
+ throw new Oauth2Error(`Invalid 'code' provided`);
1330
+ }
1331
+ verifyCodeExpiration(options.codeExpiresAt, options.now, "code");
1332
+ }
1333
+ function verifyTransactionCode(txCode, expectedTxCode) {
1334
+ if (txCode === expectedTxCode) return;
1335
+ if (expectedTxCode === void 0) {
1336
+ throw new Oauth2Error("Request contains 'tx_code' that was not expected");
1337
+ }
1338
+ if (txCode === void 0) {
1339
+ throw new Oauth2Error("Missing required 'tx_code' in request");
1340
+ }
1341
+ throw new Oauth2Error("Invalid 'tx_code' provided");
1342
+ }
1343
+ function verifyCodeExpiration(expiresAt, date, codeParameter) {
1344
+ if (!expiresAt) return;
1345
+ if (Number.isNaN(expiresAt.getTime())) {
1346
+ throw new Oauth2Error(`Invalid expiration date for '${codeParameter}'`);
1347
+ }
1348
+ const now = date ?? /* @__PURE__ */ new Date();
1349
+ if (now.getTime() > expiresAt.getTime()) {
1350
+ throw new Oauth2Error(`Expired '${codeParameter}' provided`);
1351
+ }
1352
+ }
1353
+ var dispatchVerifyAccessTokenRequest = createVersionDispatcher6({
1354
+ [ItWalletSpecsVersion7.APTITUDE]: (o) => verifyAccessTokenRequestAPTITUDE(
1355
+ o
1356
+ ),
1357
+ [ItWalletSpecsVersion7.V1_0]: (o) => verifyAccessTokenRequestV1_4(
1358
+ o
1359
+ ),
1360
+ [ItWalletSpecsVersion7.V1_3]: (o) => verifyAccessTokenRequestV1_4(
1361
+ o
1362
+ ),
1363
+ [ItWalletSpecsVersion7.V1_4]: (o) => verifyAccessTokenRequestV1_4(
1364
+ o
1365
+ )
1366
+ });
1367
+ function verifyAccessTokenRequest(options) {
1368
+ return dispatchVerifyAccessTokenRequest(options);
1369
+ }
1320
1370
 
1321
1371
  // src/authorization-request/create-authorization-request.ts
1322
1372
  import {
1323
- ItWalletSpecsVersion as ItWalletSpecsVersion3,
1373
+ ItWalletSpecsVersion as ItWalletSpecsVersion8,
1324
1374
  addSecondsToDate as addSecondsToDate3,
1325
1375
  dateToSeconds as dateToSeconds4,
1326
1376
  dispatchByVersion,
@@ -1328,33 +1378,34 @@ import {
1328
1378
  } from "@pagopa/io-wallet-utils";
1329
1379
 
1330
1380
  // src/authorization-request/z-authorization-request.ts
1331
- import z12 from "zod";
1332
- var zOpenidCredentialAuthorizationDetails = z12.object({
1333
- credential_configuration_id: z12.string(),
1334
- type: z12.literal("openid_credential")
1381
+ import { MAX_JTI_LENGTH as MAX_JTI_LENGTH4 } from "@pagopa/io-wallet-utils";
1382
+ import z9 from "zod";
1383
+ var zOpenidCredentialAuthorizationDetails = z9.object({
1384
+ credential_configuration_id: z9.string(),
1385
+ type: z9.literal("openid_credential")
1335
1386
  });
1336
- var zItL2DocumentProofAuthorizationDetails = z12.object({
1337
- challenge_method: z12.literal("mrtd+ias"),
1338
- challenge_redirect_uri: z12.url(),
1339
- idphinting: z12.url(),
1340
- type: z12.literal("it_l2+document_proof")
1387
+ var zItL2DocumentProofAuthorizationDetails = z9.object({
1388
+ challenge_method: z9.literal("mrtd+ias"),
1389
+ challenge_redirect_uri: z9.url(),
1390
+ idphinting: z9.url(),
1391
+ type: z9.literal("it_l2+document_proof")
1341
1392
  });
1342
- var zAuthorizationRequestBaseObject = z12.looseObject({
1343
- authorization_details: z12.array(
1344
- z12.discriminatedUnion("type", [
1393
+ var zAuthorizationRequestBaseObject = z9.looseObject({
1394
+ authorization_details: z9.array(
1395
+ z9.discriminatedUnion("type", [
1345
1396
  zOpenidCredentialAuthorizationDetails,
1346
1397
  zItL2DocumentProofAuthorizationDetails
1347
1398
  ])
1348
1399
  ).optional(),
1349
- client_id: z12.string(),
1350
- code_challenge: z12.string(),
1351
- code_challenge_method: z12.string(),
1352
- issuer_state: z12.optional(z12.string()),
1353
- jti: z12.string().max(MAX_JTI_LENGTH),
1354
- redirect_uri: z12.url(),
1355
- response_type: z12.string(),
1356
- scope: z12.string().optional(),
1357
- state: z12.string()
1400
+ client_id: z9.string(),
1401
+ code_challenge: z9.string(),
1402
+ code_challenge_method: z9.string(),
1403
+ issuer_state: z9.optional(z9.string()),
1404
+ jti: z9.string().max(MAX_JTI_LENGTH4),
1405
+ redirect_uri: z9.url(),
1406
+ response_type: z9.string(),
1407
+ scope: z9.string().optional(),
1408
+ state: z9.string()
1358
1409
  });
1359
1410
  var zAuthorizationRequestBase = zAuthorizationRequestBaseObject.refine(
1360
1411
  (data) => data.authorization_details !== void 0 || data.scope !== void 0,
@@ -1364,7 +1415,7 @@ var zAuthorizationRequestBase = zAuthorizationRequestBaseObject.refine(
1364
1415
  }
1365
1416
  );
1366
1417
  var zAuthorizationRequestV1_0 = zAuthorizationRequestBaseObject.extend({
1367
- response_mode: z12.string()
1418
+ response_mode: z9.string()
1368
1419
  }).refine(
1369
1420
  (data) => data.authorization_details !== void 0 || data.scope !== void 0,
1370
1421
  {
@@ -1373,25 +1424,25 @@ var zAuthorizationRequestV1_0 = zAuthorizationRequestBaseObject.extend({
1373
1424
  }
1374
1425
  );
1375
1426
  var zAuthorizationRequestV1_3 = zAuthorizationRequestBase;
1376
- var zPushedAuthorizationRequestSigned = z12.looseObject({
1377
- client_id: z12.string().describe(
1427
+ var zPushedAuthorizationRequestSigned = z9.looseObject({
1428
+ client_id: z9.string().describe(
1378
1429
  "MUST be set to the thumbprint of the jwk value in the cnf parameter inside the Wallet Attestation."
1379
1430
  ),
1380
- pkceCodeVerifier: z12.string().describe(
1431
+ pkceCodeVerifier: z9.string().describe(
1381
1432
  "Code verifier for PKCE. If not provided in CreatePushedAuthorizationRequestOptions, SDK will generate one."
1382
1433
  ),
1383
- request: z12.string().describe(
1434
+ request: z9.string().describe(
1384
1435
  "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."
1385
1436
  )
1386
1437
  });
1387
- var zPushedAuthorizationRequestUnsignedBase = (authorizationRequest) => z12.looseObject({
1438
+ var zPushedAuthorizationRequestUnsignedBase = (authorizationRequest) => z9.looseObject({
1388
1439
  authorizationRequest: authorizationRequest.describe(
1389
1440
  "The authorization request parameters as a plain object. Used when require_signed_request_object is false."
1390
1441
  ),
1391
- client_id: z12.string().describe(
1442
+ client_id: z9.string().describe(
1392
1443
  "Thumbprint of the jwk value in the cnf parameter inside Wallet Attestation."
1393
1444
  ),
1394
- pkceCodeVerifier: z12.string().describe(
1445
+ pkceCodeVerifier: z9.string().describe(
1395
1446
  "PKCE code verifier. Auto-generated if not provided in options."
1396
1447
  )
1397
1448
  });
@@ -1403,9 +1454,9 @@ function isPushedAuthorizationRequestSigned(par) {
1403
1454
  function isPushedAuthorizationRequestUnsigned(par) {
1404
1455
  return "authorizationRequest" in par;
1405
1456
  }
1406
- var zPushedAuthorizationResponse = z12.looseObject({
1407
- expires_in: z12.number().int(),
1408
- request_uri: z12.string()
1457
+ var zPushedAuthorizationResponse = z9.looseObject({
1458
+ expires_in: z9.number().int(),
1459
+ request_uri: z9.string()
1409
1460
  });
1410
1461
 
1411
1462
  // src/authorization-request/create-authorization-request.ts
@@ -1475,16 +1526,19 @@ async function createPushedAuthorizationRequest(options) {
1475
1526
  }
1476
1527
  function parseAuthorizationRequestByVersion(options, baseAuthorizationRequest) {
1477
1528
  return dispatchByVersion(options.config.itWalletSpecsVersion, {
1478
- [ItWalletSpecsVersion3.V1_0]: () => zAuthorizationRequestV1_0.parse({
1529
+ [ItWalletSpecsVersion8.APTITUDE]: () => zAuthorizationRequestV1_3.parse(
1530
+ baseAuthorizationRequest
1531
+ ),
1532
+ [ItWalletSpecsVersion8.V1_0]: () => zAuthorizationRequestV1_0.parse({
1479
1533
  ...baseAuthorizationRequest,
1480
1534
  response_mode: options.responseMode
1481
1535
  }),
1482
- [ItWalletSpecsVersion3.V1_3]: () => zAuthorizationRequestV1_3.parse(
1536
+ // V1_4 reuses V1_3 authorization request schema — no breaking changes between versions.
1537
+ [ItWalletSpecsVersion8.V1_3]: () => zAuthorizationRequestV1_3.parse(
1483
1538
  baseAuthorizationRequest
1484
1539
  ),
1485
- // V1_4 reuses V1_3 authorization request schema — no breaking changes between versions.
1486
1540
  // Verified against compare/1.3.3...1.4.1: authorization request parameters identical.
1487
- [ItWalletSpecsVersion3.V1_4]: () => zAuthorizationRequestV1_3.parse(
1541
+ [ItWalletSpecsVersion8.V1_4]: () => zAuthorizationRequestV1_3.parse(
1488
1542
  baseAuthorizationRequest
1489
1543
  )
1490
1544
  });
@@ -1580,12 +1634,13 @@ function parseAuthorizationRequest(options) {
1580
1634
 
1581
1635
  // src/authorization-request/parse-pushed-authorization-request.ts
1582
1636
  import {
1583
- ItWalletSpecsVersion as ItWalletSpecsVersion4,
1637
+ ItWalletSpecsVersion as ItWalletSpecsVersion9,
1638
+ decodeJwt as decodeJwt4,
1584
1639
  dispatchByVersion as dispatchByVersion2,
1585
1640
  formatZodError as formatZodError2,
1586
- parseWithErrorHandling as parseWithErrorHandling7
1641
+ parseWithErrorHandling as parseWithErrorHandling5
1587
1642
  } from "@pagopa/io-wallet-utils";
1588
- import z14 from "zod";
1643
+ import z11 from "zod";
1589
1644
 
1590
1645
  // src/jar/fetch-jar-request-object.ts
1591
1646
  import {
@@ -1651,25 +1706,26 @@ async function parseJarRequest(options) {
1651
1706
  }
1652
1707
 
1653
1708
  // src/jar/z-jar.ts
1654
- import z13 from "zod";
1655
- var zJarAuthorizationRequest = z13.looseObject({
1656
- client_id: z13.optional(z13.string()),
1657
- request: z13.optional(z13.string()),
1658
- request_uri: z13.url().optional()
1709
+ import { zJwtHeader as zJwtHeader7, zJwtPayload as zJwtPayload7 } from "@pagopa/io-wallet-utils";
1710
+ import z10 from "zod";
1711
+ var zJarAuthorizationRequest = z10.looseObject({
1712
+ client_id: z10.optional(z10.string()),
1713
+ request: z10.optional(z10.string()),
1714
+ request_uri: z10.url().optional()
1659
1715
  });
1660
- var zJarRequestObjectPayload = z13.looseObject({
1661
- ...zJwtPayload.shape,
1662
- client_id: z13.string()
1716
+ var zJarRequestObjectPayload = z10.looseObject({
1717
+ ...zJwtPayload7.shape,
1718
+ client_id: z10.string()
1663
1719
  });
1664
- var zSignedAuthorizationRequestJwtHeaderTyp = z13.literal(
1720
+ var zSignedAuthorizationRequestJwtHeaderTyp = z10.literal(
1665
1721
  "oauth-authz-req+jwt"
1666
1722
  );
1667
- var zJarRequestObjectHeader = z13.looseObject({
1668
- ...zJwtHeader.shape,
1723
+ var zJarRequestObjectHeader = z10.looseObject({
1724
+ ...zJwtHeader7.shape,
1669
1725
  typ: zSignedAuthorizationRequestJwtHeaderTyp
1670
1726
  });
1671
1727
  var signedAuthorizationRequestJwtHeaderTyp = zSignedAuthorizationRequestJwtHeaderTyp.value;
1672
- var zJwtAuthorizationRequestJwtHeaderTyp = z13.literal("jwt");
1728
+ var zJwtAuthorizationRequestJwtHeaderTyp = z10.literal("jwt");
1673
1729
  var jwtAuthorizationRequestJwtHeaderTyp = zJwtAuthorizationRequestJwtHeaderTyp.value;
1674
1730
 
1675
1731
  // src/authorization-request/parse-pushed-authorization-request.ts
@@ -1677,8 +1733,8 @@ async function parsePushedAuthorizationRequest(options) {
1677
1733
  const authorizationRequestSchema = getAuthorizationRequestSchema(
1678
1734
  options.config
1679
1735
  );
1680
- const parsed = parseWithErrorHandling7(
1681
- z14.union([authorizationRequestSchema, zJarAuthorizationRequest]),
1736
+ const parsed = parseWithErrorHandling5(
1737
+ z11.union([authorizationRequestSchema, zJarAuthorizationRequest]),
1682
1738
  options.authorizationRequest,
1683
1739
  "Invalid authorization request. Could not parse authorization request or jar."
1684
1740
  );
@@ -1689,7 +1745,7 @@ async function parsePushedAuthorizationRequest(options) {
1689
1745
  callbacks: options.callbacks,
1690
1746
  jarRequestParams: parsed
1691
1747
  });
1692
- const jwt = decodeJwt({
1748
+ const jwt = decodeJwt4({
1693
1749
  errorMessagePrefix: "Error decoding pushed authorization request JWT:",
1694
1750
  jwt: parsedJar.authorizationRequestJwt
1695
1751
  });
@@ -1727,11 +1783,12 @@ ${formatZodError2(parsedAuthorizationRequest.error)}`
1727
1783
  }
1728
1784
  function getAuthorizationRequestSchema(config) {
1729
1785
  return dispatchByVersion2(config.itWalletSpecsVersion, {
1730
- [ItWalletSpecsVersion4.V1_0]: () => zAuthorizationRequestV1_0,
1731
- [ItWalletSpecsVersion4.V1_3]: () => zAuthorizationRequestV1_3,
1786
+ [ItWalletSpecsVersion9.APTITUDE]: () => zAuthorizationRequestV1_3,
1787
+ [ItWalletSpecsVersion9.V1_0]: () => zAuthorizationRequestV1_0,
1732
1788
  // V1_4 reuses V1_3 PAR schema — no breaking changes between versions.
1789
+ [ItWalletSpecsVersion9.V1_3]: () => zAuthorizationRequestV1_3,
1733
1790
  // Verified against compare/1.3.3...1.4.1: authorization request parameters identical.
1734
- [ItWalletSpecsVersion4.V1_4]: () => zAuthorizationRequestV1_3
1791
+ [ItWalletSpecsVersion9.V1_4]: () => zAuthorizationRequestV1_3
1735
1792
  });
1736
1793
  }
1737
1794
 
@@ -1779,13 +1836,17 @@ async function verifyAuthorizationRequestDpop(options, request, callbacks, now)
1779
1836
  };
1780
1837
  }
1781
1838
 
1839
+ // src/authorization-request/verify-pushed-authorization-request.ts
1840
+ import { decodeJwt as decodeJwt6 } from "@pagopa/io-wallet-utils";
1841
+
1782
1842
  // src/jar/verify-jar-request.ts
1783
1843
  import {
1844
+ decodeJwt as decodeJwt5,
1845
+ parseWithErrorHandling as parseWithErrorHandling6,
1784
1846
  verifyJwt as verifyJwt4,
1785
1847
  zCompactJwe,
1786
- zCompactJwt as zCompactJwt4
1787
- } from "@openid4vc/oauth2";
1788
- import { parseWithErrorHandling as parseWithErrorHandling8 } from "@pagopa/io-wallet-utils";
1848
+ zCompactJwt as zCompactJwt3
1849
+ } from "@pagopa/io-wallet-utils";
1789
1850
  async function verifyJarRequest(options) {
1790
1851
  const { authorizationRequestJwt, callbacks, jarRequestParams, jwtSigner } = options;
1791
1852
  const requestObjectIsEncrypted = zCompactJwe.safeParse(
@@ -1794,7 +1855,7 @@ async function verifyJarRequest(options) {
1794
1855
  if (requestObjectIsEncrypted) {
1795
1856
  throw new Oauth2Error("Encrypted JWE request objects are not supported.");
1796
1857
  }
1797
- const requestIsSigned = zCompactJwt4.safeParse(
1858
+ const requestIsSigned = zCompactJwt3.safeParse(
1798
1859
  authorizationRequestJwt
1799
1860
  ).success;
1800
1861
  if (!requestIsSigned) {
@@ -1847,11 +1908,11 @@ async function verifyJarRequest(options) {
1847
1908
  }
1848
1909
  async function verifyJarRequestObject(options) {
1849
1910
  const { authorizationRequestJwt, callbacks, jwtSigner } = options;
1850
- const jwt = decodeJwt({
1911
+ const jwt = decodeJwt5({
1851
1912
  errorMessagePrefix: "Error decoding JAR authorization request JWT:",
1852
1913
  jwt: authorizationRequestJwt
1853
1914
  });
1854
- const authorizationRequestPayload = parseWithErrorHandling8(
1915
+ const authorizationRequestPayload = parseWithErrorHandling6(
1855
1916
  zJarRequestObjectPayload,
1856
1917
  jwt.payload
1857
1918
  );
@@ -1888,7 +1949,7 @@ async function verifyPushedAuthorizationRequest(options) {
1888
1949
  let jar;
1889
1950
  if (options.authorizationRequestJwt) {
1890
1951
  if (requireSigned) {
1891
- const decoded = decodeJwt({
1952
+ const decoded = decodeJwt6({
1892
1953
  errorMessagePrefix: "Error decoding pushed authorization request JWT:",
1893
1954
  jwt: options.authorizationRequestJwt.jwt
1894
1955
  });
@@ -1980,14 +2041,15 @@ function clientAuthenticationWalletAttestationJwt(options) {
1980
2041
  import {
1981
2042
  ValidationError as ValidationError4,
1982
2043
  addSecondsToDate as addSecondsToDate4,
1983
- dateToSeconds as dateToSeconds5
2044
+ dateToSeconds as dateToSeconds5,
2045
+ decodeJwt as decodeJwt7
1984
2046
  } from "@pagopa/io-wallet-utils";
1985
2047
 
1986
2048
  // src/client-attestation/jwk-thumbprint.ts
1987
2049
  import {
1988
2050
  HashAlgorithm as HashAlgorithm6,
1989
2051
  calculateJwkThumbprint as calculateJwkThumbprint4
1990
- } from "@openid4vc/oauth2";
2052
+ } from "@pagopa/io-wallet-utils";
1991
2053
  var SUPPORTED_KTY = ["RSA", "EC"];
1992
2054
  var calculateDpopJwkThumbprint = (options) => {
1993
2055
  if (!SUPPORTED_KTY.includes(
@@ -2031,7 +2093,7 @@ var createWalletAttestationJwt = async (options) => {
2031
2093
  header,
2032
2094
  payload
2033
2095
  });
2034
- decodeJwt({
2096
+ decodeJwt7({
2035
2097
  errorMessagePrefix: "Error decoding wallet attestation JWT:",
2036
2098
  headerSchema: zWalletAttestationJwtHeaderV1_0,
2037
2099
  jwt: result.jwt,
@@ -2052,7 +2114,8 @@ var createWalletAttestationJwt = async (options) => {
2052
2114
  import {
2053
2115
  ValidationError as ValidationError5,
2054
2116
  addSecondsToDate as addSecondsToDate5,
2055
- dateToSeconds as dateToSeconds6
2117
+ dateToSeconds as dateToSeconds6,
2118
+ decodeJwt as decodeJwt8
2056
2119
  } from "@pagopa/io-wallet-utils";
2057
2120
  var createWalletAttestationJwt2 = async (options) => {
2058
2121
  try {
@@ -2088,7 +2151,7 @@ var createWalletAttestationJwt2 = async (options) => {
2088
2151
  header,
2089
2152
  payload
2090
2153
  });
2091
- decodeJwt({
2154
+ decodeJwt8({
2092
2155
  errorMessagePrefix: "Error decoding wallet attestation JWT:",
2093
2156
  headerSchema: zWalletAttestationJwtHeaderV1_3,
2094
2157
  jwt: result.jwt,
@@ -2109,7 +2172,8 @@ var createWalletAttestationJwt2 = async (options) => {
2109
2172
  import {
2110
2173
  ValidationError as ValidationError6,
2111
2174
  addSecondsToDate as addSecondsToDate6,
2112
- dateToSeconds as dateToSeconds7
2175
+ dateToSeconds as dateToSeconds7,
2176
+ decodeJwt as decodeJwt9
2113
2177
  } from "@pagopa/io-wallet-utils";
2114
2178
  var DEFAULT_EXPIRATION_SECONDS = 3600;
2115
2179
  var MAX_EXPIRATION_SECONDS = 86400;
@@ -2151,7 +2215,7 @@ var createWalletAttestationJwt3 = async (options) => {
2151
2215
  header,
2152
2216
  payload
2153
2217
  });
2154
- decodeJwt({
2218
+ decodeJwt9({
2155
2219
  errorMessagePrefix: "Error decoding wallet attestation JWT:",
2156
2220
  headerSchema: zWalletAttestationJwtHeaderV1_4,
2157
2221
  jwt: result.jwt,
@@ -2168,17 +2232,11 @@ var createWalletAttestationJwt3 = async (options) => {
2168
2232
  }
2169
2233
  };
2170
2234
 
2171
- // src/common/jwt/z-jwe.ts
2172
- import { z as z15 } from "zod";
2173
- var zCompactJwe2 = z15.string().regex(
2174
- /^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/,
2175
- {
2176
- message: "Not a valid compact jwe"
2177
- }
2178
- );
2179
-
2180
2235
  // src/jar/create-jar-request.ts
2181
- import { addSecondsToDate as addSecondsToDate7, dateToSeconds as dateToSeconds8 } from "@pagopa/io-wallet-utils";
2236
+ import {
2237
+ addSecondsToDate as addSecondsToDate7,
2238
+ dateToSeconds as dateToSeconds8
2239
+ } from "@pagopa/io-wallet-utils";
2182
2240
  async function createJarRequest(options) {
2183
2241
  const {
2184
2242
  authorizationRequestHeader,
@@ -2225,6 +2283,7 @@ async function createJarRequest(options) {
2225
2283
  }
2226
2284
 
2227
2285
  // src/jarm-form-post-jwt.ts
2286
+ import { decodeJwt as decodeJwt10 } from "@pagopa/io-wallet-utils";
2228
2287
  var getJwtFromFormPost = async (options) => {
2229
2288
  const inputRegex = /<input[^<>]*>/gi;
2230
2289
  const nameRegex = /name="response"/gi;
@@ -2239,7 +2298,7 @@ var getJwtFromFormPost = async (options) => {
2239
2298
  const responseJwt = matchValue[1];
2240
2299
  if (responseJwt) {
2241
2300
  const jwt = responseJwt.replace(lineExpressionRegex, "");
2242
- const decodedJwt = decodeJwt({
2301
+ const decodedJwt = decodeJwt10({
2243
2302
  errorMessagePrefix: "Error decoding JARM form post JWT:",
2244
2303
  jwt,
2245
2304
  payloadSchema: options.schema
@@ -2261,73 +2320,76 @@ var getJwtFromFormPost = async (options) => {
2261
2320
  };
2262
2321
 
2263
2322
  // src/mrtd-pop/create-mrtd-validation-jwt.ts
2264
- import { dateToSeconds as dateToSeconds9, parseWithErrorHandling as parseWithErrorHandling9 } from "@pagopa/io-wallet-utils";
2323
+ import {
2324
+ dateToSeconds as dateToSeconds9,
2325
+ parseWithErrorHandling as parseWithErrorHandling7
2326
+ } from "@pagopa/io-wallet-utils";
2265
2327
 
2266
2328
  // src/mrtd-pop/z-mrtd-pop.ts
2267
- import z16 from "zod";
2268
- var zMrtdChallengeJwtHeader = z16.looseObject({
2269
- alg: z16.string(),
2270
- kid: z16.string(),
2271
- typ: z16.literal("mrtd-ias+jwt")
2329
+ import z12 from "zod";
2330
+ var zMrtdChallengeJwtHeader = z12.looseObject({
2331
+ alg: z12.string(),
2332
+ kid: z12.string(),
2333
+ typ: z12.literal("mrtd-ias+jwt")
2272
2334
  });
2273
- var zMrtdChallengeJwtPayload = z16.looseObject({
2274
- aud: z16.string(),
2275
- exp: z16.number(),
2276
- htm: z16.literal("POST"),
2277
- htu: z16.url(),
2278
- iat: z16.number(),
2279
- iss: z16.string(),
2280
- mrtd_auth_session: z16.string(),
2281
- mrtd_pop_jwt_nonce: z16.string(),
2282
- state: z16.string(),
2283
- status: z16.literal("require_interaction"),
2284
- type: z16.literal("mrtd+ias")
2335
+ var zMrtdChallengeJwtPayload = z12.looseObject({
2336
+ aud: z12.string(),
2337
+ exp: z12.number(),
2338
+ htm: z12.literal("POST"),
2339
+ htu: z12.url(),
2340
+ iat: z12.number(),
2341
+ iss: z12.string(),
2342
+ mrtd_auth_session: z12.string(),
2343
+ mrtd_pop_jwt_nonce: z12.string(),
2344
+ state: z12.string(),
2345
+ status: z12.literal("require_interaction"),
2346
+ type: z12.literal("mrtd+ias")
2285
2347
  });
2286
- var zMrtdPopInitResponseJwtHeader = z16.looseObject({
2287
- alg: z16.string(),
2288
- kid: z16.string(),
2289
- typ: z16.literal("mrtd-ias-pop+jwt")
2348
+ var zMrtdPopInitResponseJwtHeader = z12.looseObject({
2349
+ alg: z12.string(),
2350
+ kid: z12.string(),
2351
+ typ: z12.literal("mrtd-ias-pop+jwt")
2290
2352
  });
2291
- var zMrtdPopInitResponseJwtPayload = z16.looseObject({
2292
- aud: z16.string(),
2293
- challenge: z16.string(),
2294
- exp: z16.number(),
2295
- htm: z16.literal("POST"),
2296
- htu: z16.url(),
2297
- iat: z16.number(),
2298
- iss: z16.string(),
2299
- mrtd_pop_nonce: z16.string(),
2300
- mrz: z16.string().optional()
2353
+ var zMrtdPopInitResponseJwtPayload = z12.looseObject({
2354
+ aud: z12.string(),
2355
+ challenge: z12.string(),
2356
+ exp: z12.number(),
2357
+ htm: z12.literal("POST"),
2358
+ htu: z12.url(),
2359
+ iat: z12.number(),
2360
+ iss: z12.string(),
2361
+ mrtd_pop_nonce: z12.string(),
2362
+ mrz: z12.string().optional()
2301
2363
  });
2302
- var zMrtdData = z16.looseObject({
2303
- dg1: z16.string(),
2304
- dg11: z16.string(),
2305
- sod_mrtd: z16.string()
2364
+ var zMrtdData = z12.looseObject({
2365
+ dg1: z12.string(),
2366
+ dg11: z12.string(),
2367
+ sod_mrtd: z12.string()
2306
2368
  });
2307
- var zIasData = z16.looseObject({
2308
- challenge_signed: z16.string(),
2309
- ias_pk: z16.string(),
2310
- sod_ias: z16.string()
2369
+ var zIasData = z12.looseObject({
2370
+ challenge_signed: z12.string(),
2371
+ ias_pk: z12.string(),
2372
+ sod_ias: z12.string()
2311
2373
  });
2312
- var zMrtdValidationJwtHeader = z16.looseObject({
2313
- alg: z16.string(),
2314
- kid: z16.string(),
2315
- typ: z16.literal("mrtd-ias+jwt")
2374
+ var zMrtdValidationJwtHeader = z12.looseObject({
2375
+ alg: z12.string(),
2376
+ kid: z12.string(),
2377
+ typ: z12.literal("mrtd-ias+jwt")
2316
2378
  });
2317
- var zMrtdValidationJwtPayload = z16.looseObject({
2318
- aud: z16.string(),
2319
- document_type: z16.literal("cie"),
2320
- exp: z16.number(),
2379
+ var zMrtdValidationJwtPayload = z12.looseObject({
2380
+ aud: z12.string(),
2381
+ document_type: z12.literal("cie"),
2382
+ exp: z12.number(),
2321
2383
  ias: zIasData,
2322
- iat: z16.number(),
2323
- iss: z16.string(),
2384
+ iat: z12.number(),
2385
+ iss: z12.string(),
2324
2386
  mrtd: zMrtdData
2325
2387
  });
2326
- var zMrtdPopVerifyResponse = z16.looseObject({
2327
- mrtd_val_pop_nonce: z16.string(),
2328
- redirect_uri: z16.url(),
2329
- status: z16.literal("require_interaction"),
2330
- type: z16.literal("redirect_to_web")
2388
+ var zMrtdPopVerifyResponse = z12.looseObject({
2389
+ mrtd_val_pop_nonce: z12.string(),
2390
+ redirect_uri: z12.url(),
2391
+ status: z12.literal("require_interaction"),
2392
+ type: z12.literal("redirect_to_web")
2331
2393
  });
2332
2394
 
2333
2395
  // src/mrtd-pop/create-mrtd-validation-jwt.ts
@@ -2339,12 +2401,12 @@ async function createMrtdValidationJwt(options) {
2339
2401
  throw new MrtdPopError("Signer must have a publicJwk.kid property");
2340
2402
  }
2341
2403
  const iat = dateToSeconds9(options.issuedAt);
2342
- const header = parseWithErrorHandling9(zMrtdValidationJwtHeader, {
2404
+ const header = parseWithErrorHandling7(zMrtdValidationJwtHeader, {
2343
2405
  alg: options.signer.alg,
2344
2406
  kid,
2345
2407
  typ: "mrtd-ias+jwt"
2346
2408
  });
2347
- const payload = parseWithErrorHandling9(zMrtdValidationJwtPayload, {
2409
+ const payload = parseWithErrorHandling7(zMrtdValidationJwtPayload, {
2348
2410
  aud: options.audience,
2349
2411
  document_type: "cie",
2350
2412
  exp: iat + JWT_EXPIRY_SECONDS2,
@@ -2377,17 +2439,16 @@ async function createMrtdValidationJwt(options) {
2377
2439
  }
2378
2440
 
2379
2441
  // src/mrtd-pop/fetch-mrtd-pop-init.ts
2380
- import {
2381
- jwtSignerFromJwt as jwtSignerFromJwt2,
2382
- verifyJwt as verifyJwt5
2383
- } from "@openid4vc/oauth2";
2384
2442
  import {
2385
2443
  CONTENT_TYPES as CONTENT_TYPES3,
2386
2444
  HEADERS as HEADERS3,
2387
2445
  UnexpectedStatusCodeError as UnexpectedStatusCodeError4,
2388
2446
  ValidationError as ValidationError7,
2389
2447
  createFetcher as createFetcher4,
2390
- hasStatusOrThrow as hasStatusOrThrow4
2448
+ decodeJwt as decodeJwt11,
2449
+ hasStatusOrThrow as hasStatusOrThrow4,
2450
+ jwtSignerFromJwt as jwtSignerFromJwt2,
2451
+ verifyJwt as verifyJwt5
2391
2452
  } from "@pagopa/io-wallet-utils";
2392
2453
  async function fetchMrtdPopInit(options) {
2393
2454
  try {
@@ -2406,7 +2467,7 @@ async function fetchMrtdPopInit(options) {
2406
2467
  });
2407
2468
  await hasStatusOrThrow4(202, UnexpectedStatusCodeError4)(response);
2408
2469
  const responseJwt = await response.text();
2409
- const jwt = decodeJwt({
2470
+ const jwt = decodeJwt11({
2410
2471
  errorMessagePrefix: "Error decoding MRTD PoP init response JWT:",
2411
2472
  headerSchema: zMrtdPopInitResponseJwtHeader,
2412
2473
  jwt: responseJwt,
@@ -2445,7 +2506,7 @@ import {
2445
2506
  ValidationError as ValidationError8,
2446
2507
  createFetcher as createFetcher5,
2447
2508
  hasStatusOrThrow as hasStatusOrThrow5,
2448
- parseWithErrorHandling as parseWithErrorHandling10
2509
+ parseWithErrorHandling as parseWithErrorHandling8
2449
2510
  } from "@pagopa/io-wallet-utils";
2450
2511
  async function fetchMrtdPopVerify(options) {
2451
2512
  try {
@@ -2464,7 +2525,7 @@ async function fetchMrtdPopVerify(options) {
2464
2525
  method: "POST"
2465
2526
  });
2466
2527
  await hasStatusOrThrow5(202, UnexpectedStatusCodeError5)(response);
2467
- const parsed = parseWithErrorHandling10(
2528
+ const parsed = parseWithErrorHandling8(
2468
2529
  zMrtdPopVerifyResponse,
2469
2530
  await response.json(),
2470
2531
  "Failed to parse MRTD PoP verify response"
@@ -2484,7 +2545,7 @@ async function fetchMrtdPopVerify(options) {
2484
2545
  }
2485
2546
 
2486
2547
  // src/mrtd-pop/parse-mrtd-challenge.ts
2487
- import { zCompactJwt as zCompactJwt5 } from "@openid4vc/oauth2";
2548
+ import { decodeJwt as decodeJwt12, zCompactJwt as zCompactJwt4 } from "@pagopa/io-wallet-utils";
2488
2549
  function parseMrtdChallenge(options) {
2489
2550
  const url = new URL(options.redirectUrl);
2490
2551
  const challengeJwt = url.searchParams.get("challenge_info");
@@ -2493,12 +2554,12 @@ function parseMrtdChallenge(options) {
2493
2554
  "Missing 'challenge_info' query parameter in redirect URL"
2494
2555
  );
2495
2556
  }
2496
- if (!zCompactJwt5.safeParse(challengeJwt).success) {
2557
+ if (!zCompactJwt4.safeParse(challengeJwt).success) {
2497
2558
  throw new MrtdPopError(
2498
2559
  "Invalid JWT format in 'challenge_info' query parameter"
2499
2560
  );
2500
2561
  }
2501
- const { header, payload } = decodeJwt({
2562
+ const { header, payload } = decodeJwt12({
2502
2563
  errorMessagePrefix: "Error decoding MRTD challenge JWT:",
2503
2564
  headerSchema: zMrtdChallengeJwtHeader,
2504
2565
  jwt: challengeJwt,
@@ -2509,12 +2570,13 @@ function parseMrtdChallenge(options) {
2509
2570
 
2510
2571
  // src/mrtd-pop/verify-mrtd-challenge.ts
2511
2572
  import {
2573
+ decodeJwt as decodeJwt13,
2512
2574
  jwtSignerFromJwt as jwtSignerFromJwt3,
2513
2575
  verifyJwt as verifyJwt6
2514
- } from "@openid4vc/oauth2";
2576
+ } from "@pagopa/io-wallet-utils";
2515
2577
  async function verifyMrtdChallenge(options) {
2516
2578
  const { callbacks, challengeJwt, clientId } = options;
2517
- const jwt = decodeJwt({
2579
+ const jwt = decodeJwt13({
2518
2580
  errorMessagePrefix: "Error decoding MRTD challenge JWT:",
2519
2581
  headerSchema: zMrtdChallengeJwtHeader,
2520
2582
  jwt: challengeJwt,
@@ -2536,24 +2598,14 @@ async function verifyMrtdChallenge(options) {
2536
2598
  });
2537
2599
  return { header: jwt.header, payload: jwt.payload, signer };
2538
2600
  }
2539
-
2540
- // src/index.ts
2541
- import {
2542
- HashAlgorithm as HashAlgorithm7,
2543
- Oauth2JwtParseError as Oauth2JwtParseError3,
2544
- verifyJwt as verifyJwt7
2545
- } from "@openid4vc/oauth2";
2546
2601
  export {
2547
2602
  ClientAttestationError,
2548
2603
  CreateTokenDPoPError,
2549
2604
  CreateTokenResponseError,
2550
2605
  FetchTokenResponseError,
2551
- HashAlgorithm7 as HashAlgorithm,
2552
2606
  IT_WALLET_CLIENT_ATTESTATION_POP_ALLOWED_ALG_VALUES,
2553
- MAX_JTI_LENGTH,
2554
2607
  MrtdPopError,
2555
2608
  Oauth2Error,
2556
- Oauth2JwtParseError3 as Oauth2JwtParseError,
2557
2609
  PkceCodeChallengeMethod,
2558
2610
  PushedAuthorizationRequestError,
2559
2611
  SupportedClientAuthenticationMethod,
@@ -2568,11 +2620,11 @@ export {
2568
2620
  createPushedAuthorizationRequest,
2569
2621
  createTokenDPoP,
2570
2622
  createTokenRequest,
2623
+ createTokenRequestAPTITUDE,
2624
+ createTokenRequestV1_4,
2571
2625
  createWalletAttestationJwt as createWalletAttestationJwtV1_0,
2572
2626
  createWalletAttestationJwt2 as createWalletAttestationJwtV1_3,
2573
2627
  createWalletAttestationJwt3 as createWalletAttestationJwtV1_4,
2574
- decodeJwt,
2575
- decodeJwtHeader,
2576
2628
  extractClientAttestationJwtsFromHeaders,
2577
2629
  extractDpopJwtFromHeaders,
2578
2630
  fetchJarRequestObject,
@@ -2587,12 +2639,12 @@ export {
2587
2639
  isPushedAuthorizationRequestSigned,
2588
2640
  isPushedAuthorizationRequestUnsigned,
2589
2641
  jwtAuthorizationRequestJwtHeaderTyp,
2590
- jwtHeaderFromJwtSigner,
2591
2642
  parseAccessTokenRequest,
2592
2643
  parseAuthorizationRequest,
2593
2644
  parseJarRequest,
2594
2645
  parseMrtdChallenge,
2595
2646
  parsePushedAuthorizationRequest,
2647
+ preAuthorizedCodeGrantIdentifier,
2596
2648
  refreshTokenGrantIdentifier,
2597
2649
  signedAuthorizationRequestJwtHeaderTyp,
2598
2650
  toURLSearchParams,
@@ -2602,7 +2654,6 @@ export {
2602
2654
  verifyClientAttestation,
2603
2655
  verifyClientAttestationPopJwt,
2604
2656
  verifyJarRequest,
2605
- verifyJwt7 as verifyJwt,
2606
2657
  verifyMrtdChallenge,
2607
2658
  verifyPkce,
2608
2659
  verifyPushedAuthorizationRequest,
@@ -2614,14 +2665,12 @@ export {
2614
2665
  zAccessTokenProfileJwtHeader,
2615
2666
  zAccessTokenProfileJwtPayload,
2616
2667
  zAccessTokenRequest,
2668
+ zAccessTokenRequestAPTITUDE,
2617
2669
  zAccessTokenResponse,
2618
- zAlgValueNotNone,
2619
2670
  zAuthorizationCodeGrantIdentifier,
2671
+ zAuthorizationCodeTokenRequest,
2620
2672
  zAuthorizationRequestV1_0,
2621
2673
  zAuthorizationRequestV1_3,
2622
- zCertificateChain,
2623
- zCompactJwe2 as zCompactJwe,
2624
- zCompactJwt,
2625
2674
  zDpopJwtHeader,
2626
2675
  zDpopJwtPayload,
2627
2676
  zItWalletClientAttestationPopJwtAlg,
@@ -2631,11 +2680,6 @@ export {
2631
2680
  zJarAuthorizationRequest,
2632
2681
  zJarRequestObjectHeader,
2633
2682
  zJarRequestObjectPayload,
2634
- zJwk,
2635
- zJwkSet,
2636
- zJwtConfirmationPayload,
2637
- zJwtHeader,
2638
- zJwtPayload,
2639
2683
  zMrtdChallengeJwtHeader,
2640
2684
  zMrtdChallengeJwtPayload,
2641
2685
  zMrtdPopInitResponseJwtHeader,
@@ -2643,6 +2687,8 @@ export {
2643
2687
  zMrtdPopVerifyResponse,
2644
2688
  zMrtdValidationJwtHeader,
2645
2689
  zMrtdValidationJwtPayload,
2690
+ zPreAuthorizedCodeGrantIdentifier,
2691
+ zPreAuthorizedCodeTokenRequest,
2646
2692
  zPushedAuthorizationRequestSigned,
2647
2693
  zPushedAuthorizationRequestUnsignedV1_0,
2648
2694
  zPushedAuthorizationRequestUnsignedV1_3,
@@ -2650,8 +2696,8 @@ export {
2650
2696
  zRefreshTokenGrantIdentifier,
2651
2697
  zRefreshTokenProfileJwtHeader,
2652
2698
  zRefreshTokenProfileJwtPayload,
2699
+ zRefreshTokenTokenRequest,
2653
2700
  zSignedAuthorizationRequestJwtHeaderTyp,
2654
- zTrustChain,
2655
2701
  zWalletAttestationJwtHeaderV1_0,
2656
2702
  zWalletAttestationJwtHeaderV1_3,
2657
2703
  zWalletAttestationJwtHeaderV1_4,