@pagopa/io-wallet-oauth2 2.0.0-apt → 2.0.0-launchpad

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,66 +1,17 @@
1
1
  // src/access-token/create-token-request.ts
2
- import {
3
- ItWalletSpecsVersion,
4
- createVersionDispatcher
5
- } from "@pagopa/io-wallet-utils";
6
-
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;
17
-
18
- // src/access-token/create-token-request.ts
19
- var createTokenRequestV1_4 = (options) => {
20
- if (options.grantType === refreshTokenGrantIdentifier) {
21
- return {
22
- ...options.additionalRequestPayload,
23
- grant_type: refreshTokenGrantIdentifier,
24
- refresh_token: options.refreshToken,
25
- scope: options.scope
26
- };
27
- }
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) {
38
- return {
39
- ...options.additionalRequestPayload,
40
- grant_type: preAuthorizedCodeGrantIdentifier,
41
- "pre-authorized_code": options.preAuthorizedCode,
42
- tx_code: options.txCode
43
- };
44
- }
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)
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
52
8
  });
53
- function createTokenRequest(options) {
54
- return dispatchCreateTokenRequest(options);
55
- }
56
9
 
57
10
  // src/access-token/create-token-response.ts
58
11
  import {
59
12
  HashAlgorithm,
60
- ItWalletSpecsVersion as ItWalletSpecsVersion2,
61
13
  addSecondsToDate,
62
14
  calculateJwkThumbprint,
63
- createVersionDispatcher as createVersionDispatcher2,
64
15
  dateToSeconds,
65
16
  jwtHeaderFromJwtSigner,
66
17
  parseWithErrorHandling
@@ -128,82 +79,70 @@ import {
128
79
  zJwtHeader,
129
80
  zJwtPayload
130
81
  } 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
82
+ import { z } from "zod";
83
+ var zAccessTokenRequest = z.discriminatedUnion("grant_type", [
84
+ z.object({
85
+ code: z.string().nonempty(),
86
+ code_verifier: z.string().nonempty(),
87
+ grant_type: z.literal("authorization_code"),
88
+ redirect_uri: z.string().nonempty()
89
+ }),
90
+ z.object({
91
+ grant_type: z.literal("refresh_token"),
92
+ refresh_token: z.string().nonempty(),
93
+ scope: z.string().optional()
94
+ })
156
95
  ]);
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")
96
+ var zAccessTokenResponse = z.looseObject({
97
+ access_token: z.string(),
98
+ authorization_details: z.array(
99
+ z.looseObject({
100
+ credential_configuration_id: z.optional(z.string()),
101
+ credential_identifiers: z.optional(z.array(z.string())),
102
+ type: z.literal("openid_credential")
164
103
  })
165
104
  ).optional(),
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")])
105
+ expires_in: z.optional(z.number().int()),
106
+ refresh_token: z.optional(z.string()),
107
+ token_type: z.union([z.literal("Bearer"), z.literal("DPoP")])
169
108
  });
170
- var zAccessTokenProfileJwtHeader = z2.looseObject({
109
+ var zAccessTokenProfileJwtHeader = z.looseObject({
171
110
  ...zJwtHeader.shape,
172
- typ: z2.enum(["application/at+jwt", "at+jwt"])
111
+ typ: z.enum(["application/at+jwt", "at+jwt"])
173
112
  });
174
- var zAccessTokenProfileJwtPayload = z2.looseObject({
113
+ var zAccessTokenProfileJwtPayload = z.looseObject({
175
114
  ...zJwtPayload.shape,
176
- aud: z2.string(),
177
- client_id: z2.string(),
178
- cnf: z2.object({
179
- jkt: z2.string()
115
+ aud: z.string(),
116
+ client_id: z.string(),
117
+ cnf: z.object({
118
+ jkt: z.string()
180
119
  }).optional(),
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()
120
+ exp: z.number(),
121
+ iat: z.number(),
122
+ iss: z.string(),
123
+ jti: z.string().max(MAX_JTI_LENGTH),
124
+ nbf: z.number().optional(),
125
+ scope: z.string().optional(),
126
+ sub: z.string()
188
127
  });
189
- var zRefreshTokenProfileJwtHeader = z2.looseObject({
128
+ var zRefreshTokenProfileJwtHeader = z.looseObject({
190
129
  ...zJwtHeader.shape,
191
- kid: z2.string(),
192
- typ: z2.literal("rt+jwt")
130
+ kid: z.string(),
131
+ typ: z.literal("rt+jwt")
193
132
  });
194
- var zRefreshTokenProfileJwtPayload = z2.looseObject({
133
+ var zRefreshTokenProfileJwtPayload = z.looseObject({
195
134
  ...zJwtPayload.shape,
196
- aud: z2.string(),
197
- client_id: z2.string(),
198
- cnf: z2.object({
199
- jkt: z2.string()
135
+ aud: z.string(),
136
+ client_id: z.string(),
137
+ cnf: z.object({
138
+ jkt: z.string()
200
139
  }),
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()
140
+ exp: z.number().int(),
141
+ iat: z.number().int(),
142
+ iss: z.string(),
143
+ jti: z.string().max(MAX_JTI_LENGTH),
144
+ nbf: z.number().int(),
145
+ sub: z.string()
207
146
  });
208
147
 
209
148
  // src/access-token/create-token-response.ts
@@ -232,7 +171,7 @@ function resolveRefreshTokenKid(signer) {
232
171
  }
233
172
  return void 0;
234
173
  }
235
- async function createAccessTokenResponseV1_4(options) {
174
+ async function createAccessTokenResponse(options) {
236
175
  try {
237
176
  const now = options.now ?? /* @__PURE__ */ new Date();
238
177
  if (options.tokenType === "DPoP" && !options.dpop) {
@@ -338,29 +277,18 @@ async function createAccessTokenResponseV1_4(options) {
338
277
  );
339
278
  }
340
279
  }
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
- }
350
280
 
351
281
  // src/access-token/fetch-token-response.ts
352
282
  import {
353
283
  CONTENT_TYPES,
354
284
  HEADERS,
355
- ItWalletSpecsVersion as ItWalletSpecsVersion3,
356
285
  UnexpectedStatusCodeError,
357
286
  ValidationError,
358
287
  createFetcher,
359
- createVersionDispatcher as createVersionDispatcher3,
360
288
  hasStatusOrThrow,
361
289
  parseWithErrorHandling as parseWithErrorHandling2
362
290
  } from "@pagopa/io-wallet-utils";
363
- async function fetchTokenResponseV1_4(options) {
291
+ async function fetchTokenResponse(options) {
364
292
  try {
365
293
  const fetch = createFetcher(options.callbacks.fetch);
366
294
  const tokenResponse = await fetch(options.accessTokenEndpoint, {
@@ -399,43 +327,26 @@ function toURLSearchParams(data) {
399
327
  });
400
328
  return params;
401
329
  }
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
- }
417
330
 
418
331
  // src/access-token/parse-token-request.ts
419
332
  import {
420
- ItWalletSpecsVersion as ItWalletSpecsVersion5,
421
- createVersionDispatcher as createVersionDispatcher5,
422
333
  formatZodError
423
334
  } from "@pagopa/io-wallet-utils";
424
335
 
425
336
  // src/client-attestation/wallet-attestation.ts
426
337
  import {
427
- ItWalletSpecsVersion as ItWalletSpecsVersion4,
428
- createVersionDispatcher as createVersionDispatcher4,
338
+ ItWalletSpecsVersion,
339
+ createVersionDispatcher,
429
340
  zCompactJwt
430
341
  } from "@pagopa/io-wallet-utils";
431
342
 
432
343
  // src/client-attestation/types.ts
433
- import z3 from "zod";
434
- var zOauthClientAttestationHeader = z3.literal(
344
+ import z2 from "zod";
345
+ var zOauthClientAttestationHeader = z2.literal(
435
346
  "OAuth-Client-Attestation"
436
347
  );
437
348
  var oauthClientAttestationHeader = zOauthClientAttestationHeader.value;
438
- var zOauthClientAttestationPopHeader = z3.literal(
349
+ var zOauthClientAttestationPopHeader = z2.literal(
439
350
  "OAuth-Client-Attestation-PoP"
440
351
  );
441
352
  var oauthClientAttestationPopHeader = zOauthClientAttestationPopHeader.value;
@@ -472,27 +383,27 @@ import {
472
383
  zJwtPayload as zJwtPayload2,
473
384
  zTrustChain
474
385
  } from "@pagopa/io-wallet-utils";
475
- import { z as z4 } from "zod";
476
- var zWalletAttestationJwtHeaderV1_0 = z4.looseObject({
386
+ import { z as z3 } from "zod";
387
+ var zWalletAttestationJwtHeaderV1_0 = z3.looseObject({
477
388
  ...zJwtHeader2.shape,
478
389
  trust_chain: zTrustChain,
479
390
  // REQUIRED in v1.0
480
- typ: z4.literal("oauth-client-attestation+jwt")
391
+ typ: z3.literal("oauth-client-attestation+jwt")
481
392
  });
482
- var zWalletAttestationJwtPayloadV1_0 = z4.looseObject({
393
+ var zWalletAttestationJwtPayloadV1_0 = z3.looseObject({
483
394
  ...zJwtPayload2.shape,
484
- aal: z4.string(),
485
- cnf: z4.object({
395
+ aal: z3.string(),
396
+ cnf: z3.object({
486
397
  jwk: zJwk
487
398
  }),
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()
399
+ exp: z3.number(),
400
+ iat: z3.number(),
401
+ iss: z3.string(),
402
+ sub: z3.string(),
403
+ wallet_link: z3.url().optional(),
404
+ wallet_name: z3.string().optional()
494
405
  });
495
- var zWalletAttestationJwtV1_0 = z4.string().min(1);
406
+ var zWalletAttestationJwtV1_0 = z3.string().min(1);
496
407
 
497
408
  // src/client-attestation/v1.0/verify-wallet-attestation-jwt.ts
498
409
  async function verifyWalletAttestationJwt(options) {
@@ -511,37 +422,37 @@ import {
511
422
  zJwtPayload as zJwtPayload3,
512
423
  zTrustChain as zTrustChain2
513
424
  } from "@pagopa/io-wallet-utils";
514
- import { z as z5 } from "zod";
515
- var zWalletAttestationJwtHeaderV1_3 = z5.looseObject({
425
+ import { z as z4 } from "zod";
426
+ var zWalletAttestationJwtHeaderV1_3 = z4.looseObject({
516
427
  ...zJwtHeader3.shape,
517
428
  trust_chain: zTrustChain2.optional(),
518
429
  // OPTIONAL in v1.3
519
- typ: z5.literal("oauth-client-attestation+jwt"),
430
+ typ: z4.literal("oauth-client-attestation+jwt"),
520
431
  x5c: zCertificateChain
521
432
  // REQUIRED in v1.3
522
433
  });
523
- var zWalletAttestationJwtPayloadV1_3 = z5.looseObject({
434
+ var zWalletAttestationJwtPayloadV1_3 = z4.looseObject({
524
435
  ...zJwtPayload3.shape,
525
- cnf: z5.object({
436
+ cnf: z4.object({
526
437
  jwk: zJwk2
527
438
  }),
528
- exp: z5.number(),
529
- iat: z5.number(),
530
- iss: z5.string(),
531
- nbf: z5.number().optional(),
439
+ exp: z4.number(),
440
+ iat: z4.number(),
441
+ iss: z4.string(),
442
+ nbf: z4.number().optional(),
532
443
  // NEW in v1.3
533
- status: z5.object({
534
- status_list: z5.object({
535
- idx: z5.number().int(),
536
- uri: z5.string()
444
+ status: z4.object({
445
+ status_list: z4.object({
446
+ idx: z4.number().int(),
447
+ uri: z4.string()
537
448
  })
538
449
  }).optional(),
539
450
  // NEW in v1.3 - status object for revocation
540
- sub: z5.string(),
541
- wallet_link: z5.url().optional(),
542
- wallet_name: z5.string().optional()
451
+ sub: z4.string(),
452
+ wallet_link: z4.url().optional(),
453
+ wallet_name: z4.string().optional()
543
454
  });
544
- var zWalletAttestationJwtV1_3 = z5.string().min(1);
455
+ var zWalletAttestationJwtV1_3 = z4.string().min(1);
545
456
 
546
457
  // src/client-attestation/v1.3/verify-wallet-attestation-jwt.ts
547
458
  async function verifyWalletAttestationJwt2(options) {
@@ -560,28 +471,28 @@ import {
560
471
  zJwtPayload as zJwtPayload4,
561
472
  zTrustChain as zTrustChain3
562
473
  } from "@pagopa/io-wallet-utils";
563
- import { z as z6 } from "zod";
564
- var zWalletAttestationJwtHeaderV1_4 = z6.looseObject({
474
+ import { z as z5 } from "zod";
475
+ var zWalletAttestationJwtHeaderV1_4 = z5.looseObject({
565
476
  ...zJwtHeader4.shape,
566
- kid: z6.string(),
477
+ kid: z5.string(),
567
478
  trust_chain: zTrustChain3.optional(),
568
- typ: z6.literal("oauth-client-attestation+jwt"),
479
+ typ: z5.literal("oauth-client-attestation+jwt"),
569
480
  x5c: zCertificateChain2
570
481
  });
571
- var zWalletAttestationJwtPayloadV1_4 = z6.looseObject({
482
+ var zWalletAttestationJwtPayloadV1_4 = z5.looseObject({
572
483
  ...zJwtPayload4.shape,
573
- cnf: z6.object({
484
+ cnf: z5.object({
574
485
  jwk: zJwk3
575
486
  }),
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()
487
+ exp: z5.number().int(),
488
+ iat: z5.number().int(),
489
+ iss: z5.string(),
490
+ nbf: z5.number().optional(),
491
+ sub: z5.string(),
492
+ wallet_link: z5.url(),
493
+ wallet_name: z5.string()
583
494
  });
584
- var zWalletAttestationJwtV1_4 = z6.string().min(1);
495
+ var zWalletAttestationJwtV1_4 = z5.string().min(1);
585
496
 
586
497
  // src/client-attestation/v1.4/verify-wallet-attestation-jwt.ts
587
498
  async function verifyWalletAttestationJwt3(options) {
@@ -593,11 +504,10 @@ async function verifyWalletAttestationJwt3(options) {
593
504
  }
594
505
 
595
506
  // src/client-attestation/wallet-attestation.ts
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)
507
+ var dispatchVerifyWalletAttestationJwt = createVersionDispatcher({
508
+ [ItWalletSpecsVersion.V1_0]: (o) => verifyWalletAttestationJwt(o),
509
+ [ItWalletSpecsVersion.V1_3]: (o) => verifyWalletAttestationJwt2(o),
510
+ [ItWalletSpecsVersion.V1_4]: (o) => verifyWalletAttestationJwt3(o)
601
511
  });
602
512
  async function verifyWalletAttestationJwt4(options) {
603
513
  return dispatchVerifyWalletAttestationJwt(options);
@@ -651,19 +561,19 @@ import {
651
561
  zJwtHeader as zJwtHeader5,
652
562
  zJwtPayload as zJwtPayload5
653
563
  } from "@pagopa/io-wallet-utils";
654
- import z7 from "zod";
655
- var zDpopJwtPayload = z7.looseObject({
564
+ import z6 from "zod";
565
+ var zDpopJwtPayload = z6.looseObject({
656
566
  ...zJwtPayload5.shape,
657
- ath: z7.optional(z7.string()),
567
+ ath: z6.optional(z6.string()),
658
568
  htm: zHttpMethod,
659
- htu: z7.url(),
660
- iat: z7.number().int().nonnegative(),
661
- jti: z7.string().max(MAX_JTI_LENGTH2)
569
+ htu: z6.url(),
570
+ iat: z6.number().int().nonnegative(),
571
+ jti: z6.string().max(MAX_JTI_LENGTH2)
662
572
  });
663
- var zDpopJwtHeader = z7.looseObject({
573
+ var zDpopJwtHeader = z6.looseObject({
664
574
  ...zJwtHeader5.shape,
665
575
  jwk: zJwk4,
666
- typ: z7.literal("dpop+jwt")
576
+ typ: z6.literal("dpop+jwt")
667
577
  });
668
578
 
669
579
  // src/token-dpop/create-token-dpop.ts
@@ -720,8 +630,15 @@ function extractDpopJwtFromHeaders(headers) {
720
630
  return { dpopJwt, valid: true };
721
631
  }
722
632
 
633
+ // src/access-token/z-grant-type.ts
634
+ import { z as z7 } from "zod";
635
+ var zAuthorizationCodeGrantIdentifier = z7.literal("authorization_code");
636
+ var authorizationCodeGrantIdentifier = zAuthorizationCodeGrantIdentifier.value;
637
+ var zRefreshTokenGrantIdentifier = z7.literal("refresh_token");
638
+ var refreshTokenGrantIdentifier = zRefreshTokenGrantIdentifier.value;
639
+
723
640
  // src/access-token/parse-token-request.ts
724
- function parseAccessTokenRequestV1_4(options) {
641
+ function parseAccessTokenRequest(options) {
725
642
  const validationResult = zAccessTokenRequest.safeParse(
726
643
  options.accessTokenRequest
727
644
  );
@@ -742,25 +659,6 @@ ${formatZodError(validationResult.error)}`
742
659
  ...securityHeaders
743
660
  };
744
661
  }
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
- }
764
662
  function parseGrantParameters(accessTokenRequest) {
765
663
  if (accessTokenRequest.grant_type === authorizationCodeGrantIdentifier) {
766
664
  return {
@@ -778,30 +676,6 @@ function parseGrantParameters(accessTokenRequest) {
778
676
  `Unsupported grant type. Supported types are: '${authorizationCodeGrantIdentifier}', '${refreshTokenGrantIdentifier}'`
779
677
  );
780
678
  }
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
- }
805
679
  function parseSecurityHeaders(headers) {
806
680
  const extractedDpopJwt = extractDpopJwtFromHeaders(headers);
807
681
  if (!extractedDpopJwt.valid) {
@@ -836,29 +710,6 @@ function parseSecurityHeaders(headers) {
836
710
  dpop: { jwt: extractedDpopJwt.dpopJwt }
837
711
  };
838
712
  }
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";
862
713
 
863
714
  // src/client-attestation/verify-client-attestation.ts
864
715
  import {
@@ -868,7 +719,7 @@ import {
868
719
 
869
720
  // src/client-attestation/client-attestation-pop.ts
870
721
  import {
871
- ItWalletSpecsVersion as ItWalletSpecsVersion6,
722
+ ItWalletSpecsVersion as ItWalletSpecsVersion2,
872
723
  addSecondsToDate as addSecondsToDate2,
873
724
  dateToSeconds as dateToSeconds3,
874
725
  decodeJwt as decodeJwt2,
@@ -995,7 +846,7 @@ async function createClientAttestationPopJwt(options) {
995
846
  iat: dateToSeconds3(issuedAt),
996
847
  iss: sub,
997
848
  jti,
998
- ...options.config.itWalletSpecsVersion === ItWalletSpecsVersion6.V1_0 ? {
849
+ ...options.config.itWalletSpecsVersion === ItWalletSpecsVersion2.V1_0 ? {
999
850
  exp: dateToSeconds3(
1000
851
  "expiresAt" in options && options.expiresAt ? options.expiresAt : addSecondsToDate2(issuedAt, 1 * 60)
1001
852
  )
@@ -1229,7 +1080,7 @@ async function verifyTokenDPoP(options) {
1229
1080
  }
1230
1081
 
1231
1082
  // src/access-token/verify-access-token-request.ts
1232
- async function verifyAccessTokenRequestV1_4(options) {
1083
+ async function verifyAccessTokenRequest(options) {
1233
1084
  if (options.dpop.expectedNonce === "") {
1234
1085
  throw new Oauth2Error(`Invalid 'dpop.expectedNonce' provided`);
1235
1086
  }
@@ -1258,44 +1109,12 @@ async function verifyAccessTokenRequestV1_4(options) {
1258
1109
  if (options.grant.code !== options.expectedCode) {
1259
1110
  throw new Oauth2Error(`Invalid 'code' provided`);
1260
1111
  }
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`);
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
- });
1112
+ if (options.codeExpiresAt) {
1113
+ const now = options.now ?? /* @__PURE__ */ new Date();
1114
+ if (now.getTime() > options.codeExpiresAt.getTime()) {
1115
+ throw new Oauth2Error(`Expired 'code' provided`);
1116
+ }
1281
1117
  }
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);
1299
1118
  if (!header.jwk) {
1300
1119
  throw new Oauth2Error("DPoP header does not contain a JWK");
1301
1120
  }
@@ -1304,73 +1123,10 @@ async function verifyAccessTokenRequestAPTITUDE(options) {
1304
1123
  dpop: { jwk: header.jwk, jwkThumbprint }
1305
1124
  };
1306
1125
  }
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
- }
1370
1126
 
1371
1127
  // src/authorization-request/create-authorization-request.ts
1372
1128
  import {
1373
- ItWalletSpecsVersion as ItWalletSpecsVersion8,
1129
+ ItWalletSpecsVersion as ItWalletSpecsVersion3,
1374
1130
  addSecondsToDate as addSecondsToDate3,
1375
1131
  dateToSeconds as dateToSeconds4,
1376
1132
  dispatchByVersion,
@@ -1526,19 +1282,16 @@ async function createPushedAuthorizationRequest(options) {
1526
1282
  }
1527
1283
  function parseAuthorizationRequestByVersion(options, baseAuthorizationRequest) {
1528
1284
  return dispatchByVersion(options.config.itWalletSpecsVersion, {
1529
- [ItWalletSpecsVersion8.APTITUDE]: () => zAuthorizationRequestV1_3.parse(
1530
- baseAuthorizationRequest
1531
- ),
1532
- [ItWalletSpecsVersion8.V1_0]: () => zAuthorizationRequestV1_0.parse({
1285
+ [ItWalletSpecsVersion3.V1_0]: () => zAuthorizationRequestV1_0.parse({
1533
1286
  ...baseAuthorizationRequest,
1534
1287
  response_mode: options.responseMode
1535
1288
  }),
1536
- // V1_4 reuses V1_3 authorization request schema — no breaking changes between versions.
1537
- [ItWalletSpecsVersion8.V1_3]: () => zAuthorizationRequestV1_3.parse(
1289
+ [ItWalletSpecsVersion3.V1_3]: () => zAuthorizationRequestV1_3.parse(
1538
1290
  baseAuthorizationRequest
1539
1291
  ),
1292
+ // V1_4 reuses V1_3 authorization request schema — no breaking changes between versions.
1540
1293
  // Verified against compare/1.3.3...1.4.1: authorization request parameters identical.
1541
- [ItWalletSpecsVersion8.V1_4]: () => zAuthorizationRequestV1_3.parse(
1294
+ [ItWalletSpecsVersion3.V1_4]: () => zAuthorizationRequestV1_3.parse(
1542
1295
  baseAuthorizationRequest
1543
1296
  )
1544
1297
  });
@@ -1634,7 +1387,7 @@ function parseAuthorizationRequest(options) {
1634
1387
 
1635
1388
  // src/authorization-request/parse-pushed-authorization-request.ts
1636
1389
  import {
1637
- ItWalletSpecsVersion as ItWalletSpecsVersion9,
1390
+ ItWalletSpecsVersion as ItWalletSpecsVersion4,
1638
1391
  decodeJwt as decodeJwt4,
1639
1392
  dispatchByVersion as dispatchByVersion2,
1640
1393
  formatZodError as formatZodError2,
@@ -1783,12 +1536,11 @@ ${formatZodError2(parsedAuthorizationRequest.error)}`
1783
1536
  }
1784
1537
  function getAuthorizationRequestSchema(config) {
1785
1538
  return dispatchByVersion2(config.itWalletSpecsVersion, {
1786
- [ItWalletSpecsVersion9.APTITUDE]: () => zAuthorizationRequestV1_3,
1787
- [ItWalletSpecsVersion9.V1_0]: () => zAuthorizationRequestV1_0,
1539
+ [ItWalletSpecsVersion4.V1_0]: () => zAuthorizationRequestV1_0,
1540
+ [ItWalletSpecsVersion4.V1_3]: () => zAuthorizationRequestV1_3,
1788
1541
  // V1_4 reuses V1_3 PAR schema — no breaking changes between versions.
1789
- [ItWalletSpecsVersion9.V1_3]: () => zAuthorizationRequestV1_3,
1790
1542
  // Verified against compare/1.3.3...1.4.1: authorization request parameters identical.
1791
- [ItWalletSpecsVersion9.V1_4]: () => zAuthorizationRequestV1_3
1543
+ [ItWalletSpecsVersion4.V1_4]: () => zAuthorizationRequestV1_3
1792
1544
  });
1793
1545
  }
1794
1546
 
@@ -2620,8 +2372,6 @@ export {
2620
2372
  createPushedAuthorizationRequest,
2621
2373
  createTokenDPoP,
2622
2374
  createTokenRequest,
2623
- createTokenRequestAPTITUDE,
2624
- createTokenRequestV1_4,
2625
2375
  createWalletAttestationJwt as createWalletAttestationJwtV1_0,
2626
2376
  createWalletAttestationJwt2 as createWalletAttestationJwtV1_3,
2627
2377
  createWalletAttestationJwt3 as createWalletAttestationJwtV1_4,
@@ -2644,7 +2394,6 @@ export {
2644
2394
  parseJarRequest,
2645
2395
  parseMrtdChallenge,
2646
2396
  parsePushedAuthorizationRequest,
2647
- preAuthorizedCodeGrantIdentifier,
2648
2397
  refreshTokenGrantIdentifier,
2649
2398
  signedAuthorizationRequestJwtHeaderTyp,
2650
2399
  toURLSearchParams,
@@ -2665,10 +2414,8 @@ export {
2665
2414
  zAccessTokenProfileJwtHeader,
2666
2415
  zAccessTokenProfileJwtPayload,
2667
2416
  zAccessTokenRequest,
2668
- zAccessTokenRequestAPTITUDE,
2669
2417
  zAccessTokenResponse,
2670
2418
  zAuthorizationCodeGrantIdentifier,
2671
- zAuthorizationCodeTokenRequest,
2672
2419
  zAuthorizationRequestV1_0,
2673
2420
  zAuthorizationRequestV1_3,
2674
2421
  zDpopJwtHeader,
@@ -2687,8 +2434,6 @@ export {
2687
2434
  zMrtdPopVerifyResponse,
2688
2435
  zMrtdValidationJwtHeader,
2689
2436
  zMrtdValidationJwtPayload,
2690
- zPreAuthorizedCodeGrantIdentifier,
2691
- zPreAuthorizedCodeTokenRequest,
2692
2437
  zPushedAuthorizationRequestSigned,
2693
2438
  zPushedAuthorizationRequestUnsignedV1_0,
2694
2439
  zPushedAuthorizationRequestUnsignedV1_3,
@@ -2696,7 +2441,6 @@ export {
2696
2441
  zRefreshTokenGrantIdentifier,
2697
2442
  zRefreshTokenProfileJwtHeader,
2698
2443
  zRefreshTokenProfileJwtPayload,
2699
- zRefreshTokenTokenRequest,
2700
2444
  zSignedAuthorizationRequestJwtHeaderTyp,
2701
2445
  zWalletAttestationJwtHeaderV1_0,
2702
2446
  zWalletAttestationJwtHeaderV1_3,