@pagopa/io-wallet-oauth2 1.2.0 → 1.3.0

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.js CHANGED
@@ -35,14 +35,13 @@ __export(index_exports, {
35
35
  CreateTokenResponseError: () => CreateTokenResponseError,
36
36
  FetchTokenResponseError: () => FetchTokenResponseError,
37
37
  HashAlgorithm: () => import_oauth215.HashAlgorithm,
38
+ MAX_JTI_LENGTH: () => MAX_JTI_LENGTH,
38
39
  MrtdPopError: () => MrtdPopError,
39
40
  Oauth2Error: () => Oauth2Error,
40
41
  Oauth2JwtParseError: () => import_oauth215.Oauth2JwtParseError,
41
42
  PkceCodeChallengeMethod: () => PkceCodeChallengeMethod,
42
43
  PushedAuthorizationRequestError: () => PushedAuthorizationRequestError,
43
44
  SupportedClientAuthenticationMethod: () => SupportedClientAuthenticationMethod,
44
- V1_0: () => v1_exports,
45
- V1_3: () => v1_exports2,
46
45
  authorizationCodeGrantIdentifier: () => authorizationCodeGrantIdentifier,
47
46
  clientAuthenticationAnonymous: () => clientAuthenticationAnonymous,
48
47
  clientAuthenticationWalletAttestationJwt: () => clientAuthenticationWalletAttestationJwt,
@@ -54,6 +53,9 @@ __export(index_exports, {
54
53
  createPushedAuthorizationRequest: () => createPushedAuthorizationRequest,
55
54
  createTokenDPoP: () => createTokenDPoP,
56
55
  createTokenRequest: () => createTokenRequest,
56
+ createWalletAttestationJwtV1_0: () => createWalletAttestationJwt,
57
+ createWalletAttestationJwtV1_3: () => createWalletAttestationJwt2,
58
+ createWalletAttestationJwtV1_4: () => createWalletAttestationJwt3,
57
59
  decodeJwt: () => decodeJwt,
58
60
  decodeJwtHeader: () => decodeJwtHeader,
59
61
  extractClientAttestationJwtsFromHeaders: () => extractClientAttestationJwtsFromHeaders,
@@ -90,7 +92,10 @@ __export(index_exports, {
90
92
  verifyPkce: () => verifyPkce,
91
93
  verifyPushedAuthorizationRequest: () => verifyPushedAuthorizationRequest,
92
94
  verifyTokenDPoP: () => verifyTokenDPoP,
93
- verifyWalletAttestationJwt: () => verifyWalletAttestationJwt3,
95
+ verifyWalletAttestationJwt: () => verifyWalletAttestationJwt4,
96
+ verifyWalletAttestationJwtV1_0: () => verifyWalletAttestationJwt,
97
+ verifyWalletAttestationJwtV1_3: () => verifyWalletAttestationJwt2,
98
+ verifyWalletAttestationJwtV1_4: () => verifyWalletAttestationJwt3,
94
99
  zAccessTokenProfileJwtHeader: () => zAccessTokenProfileJwtHeader,
95
100
  zAccessTokenProfileJwtPayload: () => zAccessTokenProfileJwtPayload,
96
101
  zAccessTokenRequest: () => zAccessTokenRequest,
@@ -123,17 +128,26 @@ __export(index_exports, {
123
128
  zPushedAuthorizationResponse: () => zPushedAuthorizationResponse,
124
129
  zRefreshTokenGrantIdentifier: () => zRefreshTokenGrantIdentifier,
125
130
  zSignedAuthorizationRequestJwtHeaderTyp: () => zSignedAuthorizationRequestJwtHeaderTyp,
126
- zTrustChain: () => zTrustChain
131
+ zTrustChain: () => zTrustChain,
132
+ zWalletAttestationJwtHeaderV1_0: () => zWalletAttestationJwtHeaderV1_0,
133
+ zWalletAttestationJwtHeaderV1_3: () => zWalletAttestationJwtHeaderV1_3,
134
+ zWalletAttestationJwtHeaderV1_4: () => zWalletAttestationJwtHeaderV1_4,
135
+ zWalletAttestationJwtPayloadV1_0: () => zWalletAttestationJwtPayloadV1_0,
136
+ zWalletAttestationJwtPayloadV1_3: () => zWalletAttestationJwtPayloadV1_3,
137
+ zWalletAttestationJwtPayloadV1_4: () => zWalletAttestationJwtPayloadV1_4,
138
+ zWalletAttestationJwtV1_0: () => zWalletAttestationJwtV1_0,
139
+ zWalletAttestationJwtV1_3: () => zWalletAttestationJwtV1_3,
140
+ zWalletAttestationJwtV1_4: () => zWalletAttestationJwtV1_4
127
141
  });
128
142
  module.exports = __toCommonJS(index_exports);
129
143
 
130
144
  // src/access-token/create-token-request.ts
131
145
  var createTokenRequest = async (options) => ({
146
+ ...options.additionalRequestPayload,
132
147
  code: options.authorizationCode,
133
148
  code_verifier: options.pkceCodeVerifier,
134
149
  grant_type: "authorization_code",
135
- redirect_uri: options.redirectUri,
136
- ...options.additionalRequestPayload
150
+ redirect_uri: options.redirectUri
137
151
  });
138
152
 
139
153
  // src/access-token/create-token-response.ts
@@ -193,6 +207,7 @@ var zJwk = import_zod2.default.looseObject({
193
207
  var zJwkSet = import_zod2.default.looseObject({ keys: import_zod2.default.array(zJwk) });
194
208
 
195
209
  // src/common/jwt/z-jwt.ts
210
+ var MAX_JTI_LENGTH = 256;
196
211
  var zCompactJwt = import_zod3.default.string().regex(/^([a-zA-Z0-9-_]+)\.([a-zA-Z0-9-_]+)\.([a-zA-Z0-9-_]+)$/, {
197
212
  message: "Not a valid compact jwt"
198
213
  });
@@ -207,7 +222,7 @@ var zJwtPayload = import_zod3.default.looseObject({
207
222
  exp: import_zod3.default.number().int().optional(),
208
223
  iat: import_zod3.default.number().int().optional(),
209
224
  iss: import_zod3.default.string().optional(),
210
- jti: import_zod3.default.string().optional(),
225
+ jti: import_zod3.default.string().max(MAX_JTI_LENGTH).optional(),
211
226
  nbf: import_zod3.default.number().int().optional(),
212
227
  nonce: import_zod3.default.string().optional(),
213
228
  // Reserved for status parameters
@@ -229,23 +244,35 @@ var zJwtHeader = import_zod3.default.looseObject({
229
244
  function decodeJwtHeader(options) {
230
245
  const jwtParts = options.jwt.split(".");
231
246
  if (jwtParts.length <= 2) {
232
- throw new import_oauth2.Oauth2JwtParseError("Jwt is not a valid jwt, unable to decode");
247
+ throw new import_oauth2.Oauth2JwtParseError(
248
+ (0, import_io_wallet_utils.formatError)(
249
+ "Unable to decode because Jwt is not a valid!",
250
+ options.errorMessagePrefix
251
+ )
252
+ );
233
253
  }
234
254
  const [headerPart] = jwtParts;
235
255
  let headerJson;
236
256
  try {
237
257
  headerJson = (0, import_io_wallet_utils.stringToJsonWithErrorHandling)(
238
258
  (0, import_io_wallet_utils.encodeToUtf8String)((0, import_io_wallet_utils.decodeBase64)(headerPart)),
239
- "Unable to parse jwt header to JSON"
259
+ (0, import_io_wallet_utils.formatError)(
260
+ "Unable to parse jwt header to JSON",
261
+ options.errorMessagePrefix
262
+ )
240
263
  );
241
264
  } catch (error) {
242
265
  throw new import_oauth2.Oauth2JwtParseError(
243
- `Error parsing JWT. ${error instanceof Error ? error.message : ""}`
266
+ (0, import_io_wallet_utils.formatError)(
267
+ `Error parsing JWT. ${error instanceof Error ? error.message : ""}`,
268
+ options.errorMessagePrefix
269
+ )
244
270
  );
245
271
  }
246
272
  const header = (0, import_io_wallet_utils.parseWithErrorHandling)(
247
273
  options.headerSchema ?? zJwtHeader,
248
- headerJson
274
+ headerJson,
275
+ (0, import_io_wallet_utils.formatError)("Invalid JWT header", options.errorMessagePrefix)
249
276
  );
250
277
  return {
251
278
  header
@@ -284,51 +311,55 @@ function jwtHeaderFromJwtSigner(signer) {
284
311
 
285
312
  // src/errors.ts
286
313
  var Oauth2Error = class extends Error {
287
- constructor(message, statusCode) {
288
- super(message);
289
- this.statusCode = statusCode;
314
+ statusCode;
315
+ constructor(message, options) {
316
+ super(message, options);
290
317
  this.name = "Oauth2Error";
318
+ this.statusCode = options?.statusCode;
291
319
  }
292
320
  };
293
321
  var PushedAuthorizationRequestError = class extends Oauth2Error {
294
- constructor(message, statusCode) {
295
- super(message);
296
- this.statusCode = statusCode;
322
+ statusCode;
323
+ constructor(message, options) {
324
+ super(message, options);
297
325
  this.name = "PushedAuthorizationRequestError";
326
+ this.statusCode = options?.statusCode;
298
327
  }
299
328
  };
300
329
  var CreateTokenDPoPError = class extends Oauth2Error {
301
- constructor(message) {
302
- super(message);
330
+ constructor(message, options) {
331
+ super(message, options);
303
332
  this.name = "CreateTokenDPoPError";
304
333
  }
305
334
  };
306
335
  var MrtdPopError = class extends Oauth2Error {
307
- constructor(message, statusCode) {
308
- super(message);
309
- this.statusCode = statusCode;
336
+ statusCode;
337
+ constructor(message, options) {
338
+ super(message, options);
310
339
  this.name = "MrtdPopError";
340
+ this.statusCode = options?.statusCode;
311
341
  }
312
342
  };
313
343
  var FetchTokenResponseError = class extends Oauth2Error {
314
- constructor(message, statusCode) {
315
- super(message);
316
- this.statusCode = statusCode;
317
- this.name = "fetchTokenResponseError";
344
+ statusCode;
345
+ constructor(message, options) {
346
+ super(message, options);
347
+ this.name = "FetchTokenResponseError";
348
+ this.statusCode = options?.statusCode;
318
349
  }
319
350
  };
320
351
  var CreateTokenResponseError = class extends Oauth2Error {
321
- constructor(message, statusCode) {
322
- super(message);
323
- this.statusCode = statusCode;
352
+ statusCode;
353
+ constructor(message, options) {
354
+ super(message, options);
324
355
  this.name = "CreateTokenResponseError";
356
+ this.statusCode = options?.statusCode;
325
357
  }
326
358
  };
327
359
  var ClientAttestationError = class extends Oauth2Error {
328
- constructor(message, cause) {
329
- super(message);
360
+ constructor(message, options) {
361
+ super(message, options);
330
362
  this.name = "ClientAttestationError";
331
- this.cause = cause;
332
363
  }
333
364
  };
334
365
 
@@ -374,7 +405,7 @@ var zAccessTokenProfileJwtPayload = import_zod4.z.looseObject({
374
405
  exp: import_zod4.z.number(),
375
406
  iat: import_zod4.z.number(),
376
407
  iss: import_zod4.z.string(),
377
- jti: import_zod4.z.string(),
408
+ jti: import_zod4.z.string().max(MAX_JTI_LENGTH),
378
409
  nbf: import_zod4.z.number().optional(),
379
410
  scope: import_zod4.z.string().optional(),
380
411
  sub: import_zod4.z.string()
@@ -394,6 +425,7 @@ async function createAccessTokenResponse(options) {
394
425
  typ: "at+jwt"
395
426
  });
396
427
  const payload = (0, import_io_wallet_utils2.parseWithErrorHandling)(zAccessTokenProfileJwtPayload, {
428
+ ...options.additionalPayload,
397
429
  aud: options.audience,
398
430
  client_id: options.clientId,
399
431
  cnf: options.dpop ? {
@@ -409,19 +441,18 @@ async function createAccessTokenResponse(options) {
409
441
  jti: (0, import_io_wallet_utils2.encodeToBase64Url)(await options.callbacks.generateRandom(32)),
410
442
  nbf: options.nbf,
411
443
  scope: options.scope,
412
- sub: options.subject,
413
- ...options.additionalPayload
444
+ sub: options.subject
414
445
  });
415
446
  const { jwt } = await options.callbacks.signJwt(options.signer, {
416
447
  header,
417
448
  payload
418
449
  });
419
450
  const accessTokenResponse = (0, import_io_wallet_utils2.parseWithErrorHandling)(zAccessTokenResponse, {
451
+ ...options.additionalPayload,
420
452
  access_token: jwt,
421
453
  expires_in: options.expiresInSeconds,
422
454
  refresh_token: options.refreshToken,
423
- token_type: options.tokenType,
424
- ...options.additionalPayload
455
+ token_type: options.tokenType
425
456
  });
426
457
  return accessTokenResponse;
427
458
  } catch (error) {
@@ -477,46 +508,83 @@ function toURLSearchParams(data) {
477
508
  }
478
509
 
479
510
  // src/access-token/parse-token-request.ts
480
- var import_io_wallet_utils12 = require("@pagopa/io-wallet-utils");
511
+ var import_io_wallet_utils8 = require("@pagopa/io-wallet-utils");
481
512
 
482
- // src/client-attestation/client-attestation-pop.ts
483
- var import_oauth24 = require("@openid4vc/oauth2");
513
+ // src/client-attestation/wallet-attestation.ts
514
+ var import_oauth25 = require("@openid4vc/oauth2");
484
515
  var import_io_wallet_utils5 = require("@pagopa/io-wallet-utils");
485
516
 
517
+ // src/client-attestation/types.ts
518
+ var import_zod5 = __toESM(require("zod"));
519
+ var zOauthClientAttestationHeader = import_zod5.default.literal(
520
+ "OAuth-Client-Attestation"
521
+ );
522
+ var oauthClientAttestationHeader = zOauthClientAttestationHeader.value;
523
+ var zOauthClientAttestationPopHeader = import_zod5.default.literal(
524
+ "OAuth-Client-Attestation-PoP"
525
+ );
526
+ var oauthClientAttestationPopHeader = zOauthClientAttestationPopHeader.value;
527
+
528
+ // src/client-attestation/verify-wallet-attestation-jwt-base.ts
529
+ var import_oauth24 = require("@openid4vc/oauth2");
530
+
486
531
  // src/common/jwt/decode-jwt.ts
487
532
  var import_oauth23 = require("@openid4vc/oauth2");
488
533
  var import_io_wallet_utils4 = require("@pagopa/io-wallet-utils");
489
534
  function decodeJwt(options) {
490
535
  const jwtParts = options.jwt.split(".");
491
536
  if (jwtParts.length !== 3) {
492
- throw new import_oauth23.Oauth2JwtParseError("Jwt is not a valid jwt, unable to decode");
537
+ throw new import_oauth23.Oauth2JwtParseError(
538
+ (0, import_io_wallet_utils4.formatError)(
539
+ "Unable to decode because Jwt is not a valid!",
540
+ options.errorMessagePrefix
541
+ )
542
+ );
493
543
  }
494
544
  let payloadJson;
495
545
  try {
496
546
  const payloadPart = jwtParts[1];
497
547
  if (payloadPart === void 0) {
498
- throw new import_oauth23.Oauth2JwtParseError("Jwt is not a valid jwt, unable to decode");
548
+ throw new import_oauth23.Oauth2JwtParseError(
549
+ (0, import_io_wallet_utils4.formatError)(
550
+ "Unable to decode because Jwt is not a valid!",
551
+ options.errorMessagePrefix
552
+ )
553
+ );
499
554
  }
500
555
  payloadJson = (0, import_io_wallet_utils4.stringToJsonWithErrorHandling)(
501
556
  (0, import_io_wallet_utils4.encodeToUtf8String)((0, import_io_wallet_utils4.decodeBase64)(payloadPart)),
502
- "Unable to parse jwt payload to JSON"
557
+ (0, import_io_wallet_utils4.formatError)(
558
+ "Unable to parse jwt payload to JSON",
559
+ options.errorMessagePrefix
560
+ )
503
561
  );
504
562
  } catch (error) {
505
563
  throw new import_oauth23.Oauth2JwtParseError(
506
- `Error parsing JWT. ${error instanceof Error ? error.message : ""}`
564
+ (0, import_io_wallet_utils4.formatError)(
565
+ `Error parsing JWT. ${error instanceof Error ? error.message : ""}`,
566
+ options.errorMessagePrefix
567
+ )
507
568
  );
508
569
  }
509
570
  const signaturePart = jwtParts[2];
510
571
  if (signaturePart === void 0) {
511
- throw new import_oauth23.Oauth2JwtParseError("Jwt is not a valid jwt, unable to decode");
572
+ throw new import_oauth23.Oauth2JwtParseError(
573
+ (0, import_io_wallet_utils4.formatError)(
574
+ "Unable to decode because Jwt is not a valid!",
575
+ options.errorMessagePrefix
576
+ )
577
+ );
512
578
  }
513
579
  const { header } = decodeJwtHeader({
580
+ errorMessagePrefix: options.errorMessagePrefix,
514
581
  headerSchema: options.headerSchema,
515
582
  jwt: options.jwt
516
583
  });
517
584
  const payload = (0, import_io_wallet_utils4.parseWithErrorHandling)(
518
585
  options.payloadSchema ?? zJwtPayload,
519
- payloadJson
586
+ payloadJson,
587
+ (0, import_io_wallet_utils4.formatError)("Invalid JWT payload", options.errorMessagePrefix)
520
588
  );
521
589
  return {
522
590
  header,
@@ -525,156 +593,26 @@ function decodeJwt(options) {
525
593
  };
526
594
  }
527
595
 
528
- // src/client-attestation/client-attestation-pop.ts
529
- async function verifyClientAttestationPopJwt(options) {
530
- try {
531
- const { header, payload } = decodeJwt({
532
- jwt: options.clientAttestationPopJwt
533
- });
534
- if (payload.aud !== options.authorizationServer) {
535
- throw new Oauth2Error(
536
- `Client Attestation Pop jwt contains 'aud' value '${payload.aud}', but expected authorization server identifier '${options.authorizationServer}'`
537
- );
538
- }
539
- const { signer } = await (0, import_oauth24.verifyJwt)({
540
- compact: options.clientAttestationPopJwt,
541
- errorMessage: "client attestation pop jwt verification failed",
542
- expectedNonce: options.expectedNonce,
543
- header,
544
- now: options.now,
545
- payload,
546
- signer: {
547
- alg: header.alg,
548
- method: "jwk",
549
- publicJwk: options.clientAttestationPublicJwk
550
- },
551
- verifyJwtCallback: options.callbacks.verifyJwt
552
- });
553
- return {
554
- header,
555
- payload,
556
- signer
557
- };
558
- } catch (error) {
559
- if (error instanceof Oauth2Error) throw error;
560
- throw new Oauth2Error(
561
- `Error creating client attestation pop jwt : ${error instanceof Error ? error.message : String(error)}`
562
- );
563
- }
564
- }
565
- async function createClientAttestationPopJwt(options) {
566
- try {
567
- const clientAttestation = decodeJwt({
568
- jwt: options.clientAttestation
569
- });
570
- const jwk = clientAttestation.payload.cnf?.jwk;
571
- if (!jwk) {
572
- throw new Oauth2Error(
573
- "Client attestation does not contain 'cnf.jwk', cannot create client attestation pop jwt"
574
- );
575
- }
576
- const sub = clientAttestation.payload.sub;
577
- if (!sub || typeof sub !== "string") {
578
- throw new Oauth2Error(
579
- "Client attestation does not contain 'sub', cannot create client attestation pop jwt"
580
- );
581
- }
582
- const signer = options.signer ?? {
583
- alg: clientAttestation.header.alg,
584
- method: "jwk",
585
- publicJwk: jwk
586
- };
587
- const header = {
588
- alg: signer.alg,
589
- typ: "oauth-client-attestation-pop+jwt"
590
- };
591
- const issuedAt = options.issuedAt ?? /* @__PURE__ */ new Date();
592
- const expiresAt = options.expiresAt ?? (0, import_io_wallet_utils5.addSecondsToDate)(issuedAt, 1 * 60);
593
- const jti = options.jti ?? (options.callbacks.generateRandom ? (0, import_io_wallet_utils5.encodeToBase64Url)(await options.callbacks.generateRandom(32)) : void 0);
594
- if (!jti) {
595
- throw new Oauth2Error(
596
- "Error: neither a default jti nor a generateRandom callback have been provided"
597
- );
598
- }
599
- const payload = {
600
- aud: options.authorizationServer,
601
- exp: (0, import_io_wallet_utils5.dateToSeconds)(expiresAt),
602
- iat: (0, import_io_wallet_utils5.dateToSeconds)(issuedAt),
603
- iss: sub,
604
- jti
605
- };
606
- const { jwt } = await options.callbacks.signJwt(signer, {
607
- header,
608
- payload
609
- });
610
- return jwt;
611
- } catch (error) {
612
- if (error instanceof Oauth2Error) throw error;
613
- throw new Oauth2Error(
614
- `Error creating client attestation pop jwt : ${error instanceof Error ? error.message : String(error)}`
615
- );
616
- }
617
- }
618
-
619
- // src/client-attestation/types.ts
620
- var import_zod5 = __toESM(require("zod"));
621
- var zOauthClientAttestationHeader = import_zod5.default.literal(
622
- "OAuth-Client-Attestation"
623
- );
624
- var oauthClientAttestationHeader = zOauthClientAttestationHeader.value;
625
- var zOauthClientAttestationPopHeader = import_zod5.default.literal(
626
- "OAuth-Client-Attestation-PoP"
627
- );
628
- var oauthClientAttestationPopHeader = zOauthClientAttestationPopHeader.value;
629
-
630
- // src/client-attestation/client-authentication.ts
631
- var SupportedClientAuthenticationMethod = {
632
- ClientSecretBasic: "client_secret_basic",
633
- ClientSecretPost: "client_secret_post",
634
- None: "none",
635
- WalletAttestationJwt: "attest_jwt_client_auth"
636
- };
637
- function isClientAttestationSupported(options) {
638
- if (!options.authorizationServerMetadata.token_endpoint_auth_methods_supported || !options.authorizationServerMetadata.token_endpoint_auth_methods_supported.includes(
639
- SupportedClientAuthenticationMethod.WalletAttestationJwt
640
- )) {
641
- return {
642
- supported: false
643
- };
644
- }
645
- return {
646
- supported: true
647
- };
648
- }
649
- function clientAuthenticationAnonymous() {
650
- return () => {
651
- };
652
- }
653
- function clientAuthenticationWalletAttestationJwt(options) {
654
- return async ({ authorizationServerMetadata, headers }) => {
655
- const clientAttestationPop = await createClientAttestationPopJwt({
656
- authorizationServer: authorizationServerMetadata.issuer,
657
- callbacks: options.callbacks,
658
- clientAttestation: options.walletAttestationJwt
659
- });
660
- headers.set(oauthClientAttestationHeader, options.walletAttestationJwt);
661
- headers.set(oauthClientAttestationPopHeader, clientAttestationPop);
662
- };
596
+ // src/client-attestation/verify-wallet-attestation-jwt-base.ts
597
+ async function verifyWalletAttestationBase(options, headerSchema, payloadSchema) {
598
+ const { header, payload } = decodeJwt({
599
+ errorMessagePrefix: "Error decoding wallet attestation JWT:",
600
+ headerSchema,
601
+ jwt: options.walletAttestationJwt,
602
+ payloadSchema
603
+ });
604
+ const { signer } = await (0, import_oauth24.verifyJwt)({
605
+ compact: options.walletAttestationJwt,
606
+ errorMessage: "wallet attestation verification failed.",
607
+ header,
608
+ now: options.now,
609
+ payload,
610
+ signer: (0, import_oauth24.jwtSignerFromJwt)({ header, payload }),
611
+ verifyJwtCallback: options.callbacks.verifyJwt
612
+ });
613
+ return { header, payload, signer };
663
614
  }
664
615
 
665
- // src/client-attestation/v1.0/index.ts
666
- var v1_exports = {};
667
- __export(v1_exports, {
668
- createWalletAttestationJwt: () => createWalletAttestationJwt,
669
- verifyWalletAttestationJwt: () => verifyWalletAttestationJwt,
670
- zWalletAttestationJwtHeaderV1_0: () => zWalletAttestationJwtHeaderV1_0,
671
- zWalletAttestationJwtPayloadV1_0: () => zWalletAttestationJwtPayloadV1_0,
672
- zWalletAttestationJwtV1_0: () => zWalletAttestationJwtV1_0
673
- });
674
-
675
- // src/client-attestation/v1.0/create-wallet-attestation-jwt.ts
676
- var import_io_wallet_utils6 = require("@pagopa/io-wallet-utils");
677
-
678
616
  // src/client-attestation/v1.0/z-wallet-attestation.ts
679
617
  var import_zod6 = require("zod");
680
618
  var zWalletAttestationJwtHeaderV1_0 = import_zod6.z.looseObject({
@@ -698,67 +636,6 @@ var zWalletAttestationJwtPayloadV1_0 = import_zod6.z.looseObject({
698
636
  });
699
637
  var zWalletAttestationJwtV1_0 = import_zod6.z.string().min(1);
700
638
 
701
- // src/client-attestation/v1.0/create-wallet-attestation-jwt.ts
702
- var createWalletAttestationJwt = async (options) => {
703
- try {
704
- const { signJwt } = options.callbacks;
705
- const exp = options.expiresAt ?? (0, import_io_wallet_utils6.addSecondsToDate)(/* @__PURE__ */ new Date(), 3600 * 24 * 60);
706
- const payload = {
707
- cnf: { jwk: options.dpopJwkPublic },
708
- exp: (0, import_io_wallet_utils6.dateToSeconds)(exp),
709
- iat: (0, import_io_wallet_utils6.dateToSeconds)(/* @__PURE__ */ new Date()),
710
- iss: options.issuer,
711
- sub: options.dpopJwkPublic.kid,
712
- ...options.walletLink && { wallet_link: options.walletLink },
713
- ...options.walletName && { wallet_name: options.walletName },
714
- aal: options.authenticatorAssuranceLevel
715
- };
716
- const header = {
717
- alg: options.signer.alg,
718
- kid: options.signer.kid,
719
- trust_chain: options.signer.trustChain,
720
- typ: "oauth-client-attestation+jwt"
721
- };
722
- const result = await signJwt(options.signer, {
723
- header,
724
- payload
725
- });
726
- decodeJwt({
727
- headerSchema: zWalletAttestationJwtHeaderV1_0,
728
- jwt: result.jwt,
729
- payloadSchema: zWalletAttestationJwtPayloadV1_0
730
- });
731
- return result.jwt;
732
- } catch (error) {
733
- if (error instanceof import_io_wallet_utils6.ValidationError) {
734
- throw error;
735
- }
736
- throw new ClientAttestationError(
737
- `Unexpected error during wallet attestation creation: ${error instanceof Error ? error.message : String(error)}`
738
- );
739
- }
740
- };
741
-
742
- // src/client-attestation/verify-wallet-attestation-jwt-base.ts
743
- var import_oauth25 = require("@openid4vc/oauth2");
744
- async function verifyWalletAttestationBase(options, headerSchema, payloadSchema) {
745
- const { header, payload } = decodeJwt({
746
- headerSchema,
747
- jwt: options.walletAttestationJwt,
748
- payloadSchema
749
- });
750
- const { signer } = await (0, import_oauth25.verifyJwt)({
751
- compact: options.walletAttestationJwt,
752
- errorMessage: "wallet attestation verification failed.",
753
- header,
754
- now: options.now,
755
- payload,
756
- signer: (0, import_oauth25.jwtSignerFromJwt)({ header, payload }),
757
- verifyJwtCallback: options.callbacks.verifyJwt
758
- });
759
- return { header, payload, signer };
760
- }
761
-
762
639
  // src/client-attestation/v1.0/verify-wallet-attestation-jwt.ts
763
640
  async function verifyWalletAttestationJwt(options) {
764
641
  return verifyWalletAttestationBase(
@@ -768,19 +645,6 @@ async function verifyWalletAttestationJwt(options) {
768
645
  );
769
646
  }
770
647
 
771
- // src/client-attestation/v1.3/index.ts
772
- var v1_exports2 = {};
773
- __export(v1_exports2, {
774
- createWalletAttestationJwt: () => createWalletAttestationJwt2,
775
- verifyWalletAttestationJwt: () => verifyWalletAttestationJwt2,
776
- zWalletAttestationJwtHeaderV1_3: () => zWalletAttestationJwtHeaderV1_3,
777
- zWalletAttestationJwtPayloadV1_3: () => zWalletAttestationJwtPayloadV1_3,
778
- zWalletAttestationJwtV1_3: () => zWalletAttestationJwtV1_3
779
- });
780
-
781
- // src/client-attestation/v1.3/create-wallet-attestation-jwt.ts
782
- var import_io_wallet_utils7 = require("@pagopa/io-wallet-utils");
783
-
784
648
  // src/client-attestation/v1.3/z-wallet-attestation.ts
785
649
  var import_zod7 = require("zod");
786
650
  var zWalletAttestationJwtHeaderV1_3 = import_zod7.z.looseObject({
@@ -814,55 +678,6 @@ var zWalletAttestationJwtPayloadV1_3 = import_zod7.z.looseObject({
814
678
  });
815
679
  var zWalletAttestationJwtV1_3 = import_zod7.z.string().min(1);
816
680
 
817
- // src/client-attestation/v1.3/create-wallet-attestation-jwt.ts
818
- var createWalletAttestationJwt2 = async (options) => {
819
- try {
820
- const { signJwt } = options.callbacks;
821
- const exp = options.expiresAt ?? (0, import_io_wallet_utils7.addSecondsToDate)(/* @__PURE__ */ new Date(), 3600 * 24 * 60);
822
- if (options.nbf && options.nbf >= exp) {
823
- throw new import_io_wallet_utils7.ValidationError("nbf must be before exp");
824
- }
825
- const payload = {
826
- cnf: { jwk: options.dpopJwkPublic },
827
- exp: (0, import_io_wallet_utils7.dateToSeconds)(exp),
828
- iat: (0, import_io_wallet_utils7.dateToSeconds)(/* @__PURE__ */ new Date()),
829
- iss: options.issuer,
830
- sub: options.dpopJwkPublic.kid,
831
- ...options.nbf && { nbf: (0, import_io_wallet_utils7.dateToSeconds)(options.nbf) },
832
- ...options.status && { status: options.status },
833
- ...options.walletLink && { wallet_link: options.walletLink },
834
- ...options.walletName && { wallet_name: options.walletName }
835
- };
836
- const header = {
837
- alg: options.signer.alg,
838
- kid: options.signer.kid,
839
- typ: "oauth-client-attestation+jwt",
840
- x5c: options.signer.x5c,
841
- // REQUIRED
842
- ...options.signer.trustChain && {
843
- trust_chain: options.signer.trustChain
844
- }
845
- };
846
- const result = await signJwt(options.signer, {
847
- header,
848
- payload
849
- });
850
- decodeJwt({
851
- headerSchema: zWalletAttestationJwtHeaderV1_3,
852
- jwt: result.jwt,
853
- payloadSchema: zWalletAttestationJwtPayloadV1_3
854
- });
855
- return result.jwt;
856
- } catch (error) {
857
- if (error instanceof import_io_wallet_utils7.ValidationError) {
858
- throw error;
859
- }
860
- throw new ClientAttestationError(
861
- `Unexpected error during wallet attestation creation: ${error instanceof Error ? error.message : String(error)}`
862
- );
863
- }
864
- };
865
-
866
681
  // src/client-attestation/v1.3/verify-wallet-attestation-jwt.ts
867
682
  async function verifyWalletAttestationJwt2(options) {
868
683
  return verifyWalletAttestationBase(
@@ -872,19 +687,65 @@ async function verifyWalletAttestationJwt2(options) {
872
687
  );
873
688
  }
874
689
 
875
- // src/client-attestation/verify-client-attestation.ts
876
- var import_oauth27 = require("@openid4vc/oauth2");
690
+ // src/client-attestation/v1.4/z-wallet-attestation.ts
691
+ var import_zod8 = require("zod");
692
+ var zWalletAttestationStatusV1_4 = import_zod8.z.object({
693
+ status_list: import_zod8.z.object({
694
+ idx: import_zod8.z.number().int(),
695
+ uri: import_zod8.z.string()
696
+ })
697
+ });
698
+ var zEudiWalletInfoV1_4 = import_zod8.z.object({
699
+ general_info: import_zod8.z.object({
700
+ wallet_provider_name: import_zod8.z.string(),
701
+ wallet_solution_certification_information: import_zod8.z.url(),
702
+ wallet_solution_id: import_zod8.z.string(),
703
+ wallet_solution_version: import_zod8.z.string()
704
+ })
705
+ });
706
+ var zWalletAttestationJwtHeaderV1_4 = import_zod8.z.looseObject({
707
+ ...zJwtHeader.shape,
708
+ trust_chain: zTrustChain.optional(),
709
+ typ: import_zod8.z.literal("oauth-client-attestation+jwt"),
710
+ x5c: zCertificateChain
711
+ });
712
+ var zWalletAttestationJwtPayloadV1_4 = import_zod8.z.looseObject({
713
+ ...zJwtPayload.shape,
714
+ cnf: import_zod8.z.object({
715
+ jwk: zJwk
716
+ }),
717
+ eudi_wallet_info: zEudiWalletInfoV1_4.optional(),
718
+ exp: import_zod8.z.number().int(),
719
+ iat: import_zod8.z.number().int(),
720
+ iss: import_zod8.z.string(),
721
+ nbf: import_zod8.z.number().optional(),
722
+ status: zWalletAttestationStatusV1_4,
723
+ sub: import_zod8.z.string(),
724
+ wallet_link: import_zod8.z.url(),
725
+ wallet_name: import_zod8.z.string()
726
+ });
727
+ var zWalletAttestationJwtV1_4 = import_zod8.z.string().min(1);
728
+
729
+ // src/client-attestation/v1.4/verify-wallet-attestation-jwt.ts
730
+ async function verifyWalletAttestationJwt3(options) {
731
+ return verifyWalletAttestationBase(
732
+ options,
733
+ zWalletAttestationJwtHeaderV1_4,
734
+ zWalletAttestationJwtPayloadV1_4
735
+ );
736
+ }
877
737
 
878
738
  // src/client-attestation/wallet-attestation.ts
879
- var import_oauth26 = require("@openid4vc/oauth2");
880
- var import_io_wallet_utils8 = require("@pagopa/io-wallet-utils");
881
739
  function isV1_0Options(options) {
882
- return options.config.itWalletSpecsVersion === import_io_wallet_utils8.ItWalletSpecsVersion.V1_0;
740
+ return options.config.itWalletSpecsVersion === import_io_wallet_utils5.ItWalletSpecsVersion.V1_0;
883
741
  }
884
742
  function isV1_3Options(options) {
885
- return options.config.itWalletSpecsVersion === import_io_wallet_utils8.ItWalletSpecsVersion.V1_3;
743
+ return options.config.itWalletSpecsVersion === import_io_wallet_utils5.ItWalletSpecsVersion.V1_3;
886
744
  }
887
- async function verifyWalletAttestationJwt3(options) {
745
+ function isV1_4Options(options) {
746
+ return options.config.itWalletSpecsVersion === import_io_wallet_utils5.ItWalletSpecsVersion.V1_4;
747
+ }
748
+ async function verifyWalletAttestationJwt4(options) {
888
749
  const version = options.config.itWalletSpecsVersion;
889
750
  if (isV1_0Options(options)) {
890
751
  return verifyWalletAttestationJwt(options);
@@ -892,10 +753,14 @@ async function verifyWalletAttestationJwt3(options) {
892
753
  if (isV1_3Options(options)) {
893
754
  return verifyWalletAttestationJwt2(options);
894
755
  }
895
- throw new import_io_wallet_utils8.ItWalletSpecsVersionError("verifyWalletAttestationJwt", version, [
896
- import_io_wallet_utils8.ItWalletSpecsVersion.V1_0,
897
- import_io_wallet_utils8.ItWalletSpecsVersion.V1_3
898
- ]);
756
+ if (isV1_4Options(options)) {
757
+ return verifyWalletAttestationJwt3(options);
758
+ }
759
+ throw new import_io_wallet_utils5.ItWalletSpecsVersionError(
760
+ "verifyWalletAttestationJwt",
761
+ version,
762
+ Object.values(import_io_wallet_utils5.ItWalletSpecsVersion)
763
+ );
899
764
  }
900
765
  function extractClientAttestationJwtsFromHeaders(headers) {
901
766
  const walletAttestationHeader = headers.get(oauthClientAttestationHeader);
@@ -908,7 +773,7 @@ function extractClientAttestationJwtsFromHeaders(headers) {
908
773
  if (!walletAttestationHeader || !clientAttestationPopHeader) {
909
774
  return { valid: false };
910
775
  }
911
- if (!import_oauth26.zCompactJwt.safeParse(walletAttestationHeader).success || !import_oauth26.zCompactJwt.safeParse(clientAttestationPopHeader).success) {
776
+ if (!import_oauth25.zCompactJwt.safeParse(walletAttestationHeader).success || !import_oauth25.zCompactJwt.safeParse(clientAttestationPopHeader).success) {
912
777
  return { valid: false };
913
778
  }
914
779
  return {
@@ -918,53 +783,9 @@ function extractClientAttestationJwtsFromHeaders(headers) {
918
783
  };
919
784
  }
920
785
 
921
- // src/client-attestation/verify-client-attestation.ts
922
- async function verifyClientAttestation(options) {
923
- if (!options.clientAttestation.walletAttestationJwt || !options.clientAttestation.clientAttestationPopJwt) {
924
- throw new Oauth2Error(
925
- `Missing required client attestation parameters in the request. Make sure to provide the '${oauthClientAttestationHeader}' and '${oauthClientAttestationPopHeader}' header values.`
926
- );
927
- }
928
- const clientAttestation = await verifyWalletAttestationJwt3({
929
- callbacks: options.callbacks,
930
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
931
- config: options.config,
932
- now: options.now,
933
- walletAttestationJwt: options.clientAttestation.walletAttestationJwt
934
- });
935
- const clientAttestationPop = await verifyClientAttestationPopJwt({
936
- authorizationServer: options.authorizationServerMetadata.issuer,
937
- callbacks: options.callbacks,
938
- clientAttestationPopJwt: options.clientAttestation.clientAttestationPopJwt,
939
- clientAttestationPublicJwk: clientAttestation.payload.cnf.jwk,
940
- now: options.now
941
- });
942
- if (options.requestClientId && options.requestClientId !== clientAttestation.payload.sub) {
943
- throw new Oauth2Error(
944
- `The client_id '${options.requestClientId}' in the request does not match the client id '${clientAttestation.payload.sub}' in the client attestation`
945
- );
946
- }
947
- if (options.clientAttestation.ensureConfirmationKeyMatchesDpopKey && options.dpopJwkThumbprint) {
948
- const clientAttestationJkt = await (0, import_oauth27.calculateJwkThumbprint)({
949
- hashAlgorithm: import_oauth27.HashAlgorithm.Sha256,
950
- hashCallback: options.callbacks.hash,
951
- jwk: clientAttestation.payload.cnf.jwk
952
- });
953
- if (clientAttestationJkt !== options.dpopJwkThumbprint) {
954
- throw new Oauth2Error(
955
- "Expected the DPoP JWK thumbprint value to match the JWK thumbprint of the client attestation confirmation JWK. Ensure both DPoP and client attestation use the same key."
956
- );
957
- }
958
- }
959
- return {
960
- clientAttestation,
961
- clientAttestationPop
962
- };
963
- }
964
-
965
786
  // src/token-dpop/create-token-dpop.ts
966
- var import_oauth28 = require("@openid4vc/oauth2");
967
- var import_io_wallet_utils10 = require("@pagopa/io-wallet-utils");
787
+ var import_oauth26 = require("@openid4vc/oauth2");
788
+ var import_io_wallet_utils7 = require("@pagopa/io-wallet-utils");
968
789
  var import_js_base64 = require("js-base64");
969
790
 
970
791
  // src/token-dpop/dpop-utils.ts
@@ -976,29 +797,29 @@ var htuFromRequestUrl = (requestUrl) => {
976
797
  };
977
798
 
978
799
  // src/token-dpop/z-dpop.ts
979
- var import_io_wallet_utils9 = require("@pagopa/io-wallet-utils");
980
- var import_zod8 = __toESM(require("zod"));
981
- var zDpopJwtPayload = import_zod8.default.looseObject({
800
+ var import_io_wallet_utils6 = require("@pagopa/io-wallet-utils");
801
+ var import_zod9 = __toESM(require("zod"));
802
+ var zDpopJwtPayload = import_zod9.default.looseObject({
982
803
  ...zJwtPayload.shape,
983
- ath: import_zod8.default.optional(import_zod8.default.string()),
984
- htm: import_io_wallet_utils9.zHttpMethod,
985
- htu: import_zod8.default.url(),
986
- iat: import_zod8.default.number().int().nonnegative(),
987
- jti: import_zod8.default.string()
804
+ ath: import_zod9.default.optional(import_zod9.default.string()),
805
+ htm: import_io_wallet_utils6.zHttpMethod,
806
+ htu: import_zod9.default.url(),
807
+ iat: import_zod9.default.number().int().nonnegative(),
808
+ jti: import_zod9.default.string().max(MAX_JTI_LENGTH)
988
809
  });
989
- var zDpopJwtHeader = import_zod8.default.looseObject({
810
+ var zDpopJwtHeader = import_zod9.default.looseObject({
990
811
  ...zJwtHeader.shape,
991
812
  jwk: zJwk,
992
- typ: import_zod8.default.literal("dpop+jwt")
813
+ typ: import_zod9.default.literal("dpop+jwt")
993
814
  });
994
815
 
995
816
  // src/token-dpop/create-token-dpop.ts
996
817
  async function createTokenDPoP(options) {
997
818
  try {
998
- const ath = options.accessToken ? (0, import_io_wallet_utils10.encodeToBase64Url)(
819
+ const ath = options.accessToken ? (0, import_io_wallet_utils7.encodeToBase64Url)(
999
820
  await options.callbacks.hash(
1000
- (0, import_io_wallet_utils10.decodeUtf8String)(options.accessToken),
1001
- import_oauth28.HashAlgorithm.Sha256
821
+ (0, import_io_wallet_utils7.decodeUtf8String)(options.accessToken),
822
+ import_oauth26.HashAlgorithm.Sha256
1002
823
  )
1003
824
  ) : void 0;
1004
825
  const jti = options.jti ?? (options.callbacks.generateRandom ? import_js_base64.Base64.fromUint8Array(
@@ -1010,16 +831,16 @@ async function createTokenDPoP(options) {
1010
831
  "Error: neither a default jti nor a generateRandom callback have been provided"
1011
832
  );
1012
833
  }
1013
- const header = (0, import_io_wallet_utils10.parseWithErrorHandling)(zDpopJwtHeader, {
834
+ const header = (0, import_io_wallet_utils7.parseWithErrorHandling)(zDpopJwtHeader, {
1014
835
  alg: options.signer.alg,
1015
836
  jwk: options.signer.publicJwk,
1016
837
  typ: "dpop+jwt"
1017
838
  });
1018
- const payload = (0, import_io_wallet_utils10.parseWithErrorHandling)(zDpopJwtPayload, {
839
+ const payload = (0, import_io_wallet_utils7.parseWithErrorHandling)(zDpopJwtPayload, {
1019
840
  ath,
1020
841
  htm: options.tokenRequest.method,
1021
842
  htu: htuFromRequestUrl(options.tokenRequest.url),
1022
- iat: (0, import_io_wallet_utils10.dateToSeconds)(options.issuedAt),
843
+ iat: (0, import_io_wallet_utils7.dateToSeconds)(options.issuedAt),
1023
844
  jti
1024
845
  });
1025
846
  return options.callbacks.signJwt(options.signer, {
@@ -1027,7 +848,7 @@ async function createTokenDPoP(options) {
1027
848
  payload
1028
849
  });
1029
850
  } catch (error) {
1030
- if (error instanceof CreateTokenDPoPError || error instanceof import_io_wallet_utils10.ValidationError) {
851
+ if (error instanceof CreateTokenDPoPError || error instanceof import_io_wallet_utils7.ValidationError) {
1031
852
  throw error;
1032
853
  }
1033
854
  throw new CreateTokenDPoPError(
@@ -1040,112 +861,17 @@ function extractDpopJwtFromHeaders(headers) {
1040
861
  if (!dpopJwt) {
1041
862
  return { valid: true };
1042
863
  }
1043
- if (!import_oauth28.zCompactJwt.safeParse(dpopJwt).success) {
864
+ if (!import_oauth26.zCompactJwt.safeParse(dpopJwt).success) {
1044
865
  return { valid: false };
1045
866
  }
1046
867
  return { dpopJwt, valid: true };
1047
868
  }
1048
869
 
1049
- // src/token-dpop/verify-token-dpop.ts
1050
- var import_oauth29 = require("@openid4vc/oauth2");
1051
- var import_io_wallet_utils11 = require("@pagopa/io-wallet-utils");
1052
- async function verifyTokenDPoP(options) {
1053
- const { header, payload } = decodeJwt({
1054
- headerSchema: zDpopJwtHeader,
1055
- jwt: options.dpopJwt,
1056
- payloadSchema: zDpopJwtPayload
1057
- });
1058
- if (options.allowedSigningAlgs && !options.allowedSigningAlgs.includes(header.alg)) {
1059
- throw new Oauth2Error(
1060
- `dpop jwt uses alg value '${header.alg}' but allowed dpop signing alg values are ${options.allowedSigningAlgs.join(", ")}.`
1061
- );
1062
- }
1063
- if (options.expectedNonce) {
1064
- if (!payload.nonce) {
1065
- throw new Oauth2Error(
1066
- `Dpop jwt does not have a nonce value, but expected nonce value '${options.expectedNonce}'`
1067
- );
1068
- }
1069
- if (payload.nonce !== options.expectedNonce) {
1070
- throw new Oauth2Error(
1071
- `Dpop jwt contains nonce value '${payload.nonce}', but expected nonce value '${options.expectedNonce}'`
1072
- );
1073
- }
1074
- }
1075
- if (options.request.method !== payload.htm) {
1076
- throw new Oauth2Error(
1077
- `Dpop jwt contains htm value '${payload.htm}', but expected htm value '${options.request.method}'`
1078
- );
1079
- }
1080
- const expectedHtu = htuFromRequestUrl(options.request.url);
1081
- if (expectedHtu !== payload.htu) {
1082
- throw new Oauth2Error(
1083
- `Dpop jwt contains htu value '${payload.htu}', but expected htu value '${expectedHtu}'.`
1084
- );
1085
- }
1086
- if (options.accessToken) {
1087
- const expectedAth = (0, import_io_wallet_utils11.encodeToBase64Url)(
1088
- await options.callbacks.hash(
1089
- (0, import_io_wallet_utils11.decodeUtf8String)(options.accessToken),
1090
- import_oauth29.HashAlgorithm.Sha256
1091
- )
1092
- );
1093
- if (!payload.ath) {
1094
- throw new Oauth2Error(
1095
- `Dpop jwt does not have a ath value, but expected ath value '${expectedAth}'.`
1096
- );
1097
- }
1098
- if (payload.ath !== expectedAth) {
1099
- throw new Oauth2Error(
1100
- `Dpop jwt contains ath value '${payload.ath}', but expected ath value '${expectedAth}'.`
1101
- );
1102
- }
1103
- }
1104
- const jwkThumbprint = await (0, import_oauth29.calculateJwkThumbprint)({
1105
- hashAlgorithm: import_oauth29.HashAlgorithm.Sha256,
1106
- hashCallback: options.callbacks.hash,
1107
- jwk: header.jwk
1108
- });
1109
- if (options.expectedJwkThumbprint && options.expectedJwkThumbprint !== jwkThumbprint) {
1110
- throw new Oauth2Error(
1111
- `Dpop is signed with jwk with thumbprint value '${jwkThumbprint}', but expect jwk thumbprint value '${options.expectedJwkThumbprint}'`
1112
- );
1113
- }
1114
- try {
1115
- (0, import_io_wallet_utils11.verifyJwtIatOrThrow)({
1116
- iat: payload.iat,
1117
- now: options.now
1118
- });
1119
- } catch (error) {
1120
- if (error instanceof Error) {
1121
- throw new Oauth2Error(`Invalid iat claim in dpop JWT: ${error.message}`);
1122
- }
1123
- }
1124
- await (0, import_oauth29.verifyJwt)({
1125
- compact: options.dpopJwt,
1126
- errorMessage: "dpop jwt verification failed",
1127
- header,
1128
- now: options.now,
1129
- payload,
1130
- signer: {
1131
- alg: header.alg,
1132
- method: "jwk",
1133
- publicJwk: header.jwk
1134
- },
1135
- verifyJwtCallback: options.callbacks.verifyJwt
1136
- });
1137
- return {
1138
- header,
1139
- jwkThumbprint,
1140
- payload
1141
- };
1142
- }
1143
-
1144
870
  // src/access-token/z-grant-type.ts
1145
- var import_zod9 = require("zod");
1146
- var zAuthorizationCodeGrantIdentifier = import_zod9.z.literal("authorization_code");
871
+ var import_zod10 = require("zod");
872
+ var zAuthorizationCodeGrantIdentifier = import_zod10.z.literal("authorization_code");
1147
873
  var authorizationCodeGrantIdentifier = zAuthorizationCodeGrantIdentifier.value;
1148
- var zRefreshTokenGrantIdentifier = import_zod9.z.literal("refresh_token");
874
+ var zRefreshTokenGrantIdentifier = import_zod10.z.literal("refresh_token");
1149
875
  var refreshTokenGrantIdentifier = zRefreshTokenGrantIdentifier.value;
1150
876
 
1151
877
  // src/access-token/parse-token-request.ts
@@ -1156,7 +882,7 @@ function parseAccessTokenRequest(options) {
1156
882
  if (!validationResult.success) {
1157
883
  throw new Oauth2Error(
1158
884
  `Access token request validation failed:
1159
- ${(0, import_io_wallet_utils12.formatZodError)(validationResult.error)}`
885
+ ${(0, import_io_wallet_utils8.formatZodError)(validationResult.error)}`
1160
886
  );
1161
887
  }
1162
888
  const accessTokenRequest = validationResult.data;
@@ -1222,9 +948,151 @@ function parseSecurityHeaders(headers) {
1222
948
  };
1223
949
  }
1224
950
 
951
+ // src/client-attestation/verify-client-attestation.ts
952
+ var import_oauth28 = require("@openid4vc/oauth2");
953
+
954
+ // src/client-attestation/client-attestation-pop.ts
955
+ var import_oauth27 = require("@openid4vc/oauth2");
956
+ var import_io_wallet_utils9 = require("@pagopa/io-wallet-utils");
957
+ async function verifyClientAttestationPopJwt(options) {
958
+ try {
959
+ const { header, payload } = decodeJwt({
960
+ errorMessagePrefix: "Error decoding client attestation PoP JWT:",
961
+ jwt: options.clientAttestationPopJwt
962
+ });
963
+ if (payload.aud !== options.authorizationServer) {
964
+ throw new Oauth2Error(
965
+ `Client Attestation Pop jwt contains 'aud' value '${payload.aud}', but expected authorization server identifier '${options.authorizationServer}'`
966
+ );
967
+ }
968
+ const { signer } = await (0, import_oauth27.verifyJwt)({
969
+ compact: options.clientAttestationPopJwt,
970
+ errorMessage: "client attestation pop jwt verification failed",
971
+ expectedNonce: options.expectedNonce,
972
+ header,
973
+ now: options.now,
974
+ payload,
975
+ signer: {
976
+ alg: header.alg,
977
+ method: "jwk",
978
+ publicJwk: options.clientAttestationPublicJwk
979
+ },
980
+ verifyJwtCallback: options.callbacks.verifyJwt
981
+ });
982
+ return {
983
+ header,
984
+ payload,
985
+ signer
986
+ };
987
+ } catch (error) {
988
+ if (error instanceof Oauth2Error) throw error;
989
+ throw new Oauth2Error(
990
+ `Error creating client attestation pop jwt : ${error instanceof Error ? error.message : String(error)}`
991
+ );
992
+ }
993
+ }
994
+ async function createClientAttestationPopJwt(options) {
995
+ try {
996
+ const clientAttestation = decodeJwt({
997
+ errorMessagePrefix: "Error decoding client attestation JWT:",
998
+ jwt: options.clientAttestation
999
+ });
1000
+ const jwk = clientAttestation.payload.cnf?.jwk;
1001
+ if (!jwk) {
1002
+ throw new Oauth2Error(
1003
+ "Client attestation does not contain 'cnf.jwk', cannot create client attestation pop jwt"
1004
+ );
1005
+ }
1006
+ const sub = clientAttestation.payload.sub;
1007
+ if (!sub || typeof sub !== "string") {
1008
+ throw new Oauth2Error(
1009
+ "Client attestation does not contain 'sub', cannot create client attestation pop jwt"
1010
+ );
1011
+ }
1012
+ const signer = options.signer ?? {
1013
+ alg: clientAttestation.header.alg,
1014
+ method: "jwk",
1015
+ publicJwk: jwk
1016
+ };
1017
+ const header = {
1018
+ alg: signer.alg,
1019
+ typ: "oauth-client-attestation-pop+jwt"
1020
+ };
1021
+ const issuedAt = options.issuedAt ?? /* @__PURE__ */ new Date();
1022
+ const expiresAt = options.expiresAt ?? (0, import_io_wallet_utils9.addSecondsToDate)(issuedAt, 1 * 60);
1023
+ const jti = options.jti ?? (options.callbacks.generateRandom ? (0, import_io_wallet_utils9.encodeToBase64Url)(await options.callbacks.generateRandom(32)) : void 0);
1024
+ if (!jti) {
1025
+ throw new Oauth2Error(
1026
+ "Error: neither a default jti nor a generateRandom callback have been provided"
1027
+ );
1028
+ }
1029
+ const payload = {
1030
+ aud: options.authorizationServer,
1031
+ exp: (0, import_io_wallet_utils9.dateToSeconds)(expiresAt),
1032
+ iat: (0, import_io_wallet_utils9.dateToSeconds)(issuedAt),
1033
+ iss: sub,
1034
+ jti
1035
+ };
1036
+ const { jwt } = await options.callbacks.signJwt(signer, {
1037
+ header,
1038
+ payload
1039
+ });
1040
+ return jwt;
1041
+ } catch (error) {
1042
+ if (error instanceof Oauth2Error) throw error;
1043
+ throw new Oauth2Error(
1044
+ `Error creating client attestation pop jwt : ${error instanceof Error ? error.message : String(error)}`
1045
+ );
1046
+ }
1047
+ }
1048
+
1049
+ // src/client-attestation/verify-client-attestation.ts
1050
+ async function verifyClientAttestation(options) {
1051
+ if (!options.clientAttestation.walletAttestationJwt || !options.clientAttestation.clientAttestationPopJwt) {
1052
+ throw new Oauth2Error(
1053
+ `Missing required client attestation parameters in the request. Make sure to provide the '${oauthClientAttestationHeader}' and '${oauthClientAttestationPopHeader}' header values.`
1054
+ );
1055
+ }
1056
+ const clientAttestation = await verifyWalletAttestationJwt4({
1057
+ callbacks: options.callbacks,
1058
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1059
+ config: options.config,
1060
+ now: options.now,
1061
+ walletAttestationJwt: options.clientAttestation.walletAttestationJwt
1062
+ });
1063
+ const clientAttestationPop = await verifyClientAttestationPopJwt({
1064
+ authorizationServer: options.authorizationServerMetadata.issuer,
1065
+ callbacks: options.callbacks,
1066
+ clientAttestationPopJwt: options.clientAttestation.clientAttestationPopJwt,
1067
+ clientAttestationPublicJwk: clientAttestation.payload.cnf.jwk,
1068
+ now: options.now
1069
+ });
1070
+ if (options.requestClientId && options.requestClientId !== clientAttestation.payload.sub) {
1071
+ throw new Oauth2Error(
1072
+ `The client_id '${options.requestClientId}' in the request does not match the client id '${clientAttestation.payload.sub}' in the client attestation`
1073
+ );
1074
+ }
1075
+ if (options.clientAttestation.ensureConfirmationKeyMatchesDpopKey && options.dpopJwkThumbprint) {
1076
+ const clientAttestationJkt = await (0, import_oauth28.calculateJwkThumbprint)({
1077
+ hashAlgorithm: import_oauth28.HashAlgorithm.Sha256,
1078
+ hashCallback: options.callbacks.hash,
1079
+ jwk: clientAttestation.payload.cnf.jwk
1080
+ });
1081
+ if (clientAttestationJkt !== options.dpopJwkThumbprint) {
1082
+ throw new Oauth2Error(
1083
+ "Expected the DPoP JWK thumbprint value to match the JWK thumbprint of the client attestation confirmation JWK. Ensure both DPoP and client attestation use the same key."
1084
+ );
1085
+ }
1086
+ }
1087
+ return {
1088
+ clientAttestation,
1089
+ clientAttestationPop
1090
+ };
1091
+ }
1092
+
1225
1093
  // src/pkce.ts
1226
- var import_oauth210 = require("@openid4vc/oauth2");
1227
- var import_io_wallet_utils13 = require("@pagopa/io-wallet-utils");
1094
+ var import_oauth29 = require("@openid4vc/oauth2");
1095
+ var import_io_wallet_utils10 = require("@pagopa/io-wallet-utils");
1228
1096
  var PkceCodeChallengeMethod = {
1229
1097
  Plain: "plain",
1230
1098
  S256: "S256"
@@ -1242,7 +1110,7 @@ async function createPkce(options) {
1242
1110
  const codeChallengeMethod = allowedCodeChallengeMethods.includes(
1243
1111
  PkceCodeChallengeMethod.S256
1244
1112
  ) ? PkceCodeChallengeMethod.S256 : PkceCodeChallengeMethod.Plain;
1245
- const codeVerifier = options.codeVerifier ?? (0, import_io_wallet_utils13.encodeToBase64Url)(await options.callbacks.generateRandom(64));
1113
+ const codeVerifier = options.codeVerifier ?? (0, import_io_wallet_utils10.encodeToBase64Url)(await options.callbacks.generateRandom(64));
1246
1114
  return {
1247
1115
  codeChallenge: await calculateCodeChallenge({
1248
1116
  codeChallengeMethod,
@@ -1261,7 +1129,7 @@ async function verifyPkce(options) {
1261
1129
  });
1262
1130
  if (options.codeChallenge !== calculatedCodeChallenge) {
1263
1131
  throw new Oauth2Error(
1264
- `Derived code challenge '${calculatedCodeChallenge}' from code_verifier '${options.codeVerifier}' using code challenge method '${options.codeChallengeMethod}' does not match the expected code challenge.`
1132
+ `PKCE verification failed: code_verifier does not match the stored code_challenge`
1265
1133
  );
1266
1134
  }
1267
1135
  }
@@ -1270,20 +1138,122 @@ async function calculateCodeChallenge(options) {
1270
1138
  return options.codeVerifier;
1271
1139
  }
1272
1140
  if (options.codeChallengeMethod === PkceCodeChallengeMethod.S256) {
1273
- return (0, import_io_wallet_utils13.encodeToBase64Url)(
1141
+ return (0, import_io_wallet_utils10.encodeToBase64Url)(
1274
1142
  await options.hashCallback(
1275
- (0, import_io_wallet_utils13.decodeUtf8String)(options.codeVerifier),
1143
+ (0, import_io_wallet_utils10.decodeUtf8String)(options.codeVerifier),
1144
+ import_oauth29.HashAlgorithm.Sha256
1145
+ )
1146
+ );
1147
+ }
1148
+ throw new Oauth2Error(
1149
+ `Unsupported code challenge method ${options.codeChallengeMethod}`
1150
+ );
1151
+ }
1152
+
1153
+ // src/token-dpop/verify-token-dpop.ts
1154
+ var import_oauth210 = require("@openid4vc/oauth2");
1155
+ var import_io_wallet_utils11 = require("@pagopa/io-wallet-utils");
1156
+ async function verifyTokenDPoP(options) {
1157
+ const { header, payload } = decodeJwt({
1158
+ errorMessagePrefix: "Error decoding access token DPoP JWT:",
1159
+ headerSchema: zDpopJwtHeader,
1160
+ jwt: options.dpopJwt,
1161
+ payloadSchema: zDpopJwtPayload
1162
+ });
1163
+ if (options.allowedSigningAlgs && !options.allowedSigningAlgs.includes(header.alg)) {
1164
+ throw new Oauth2Error(
1165
+ `dpop jwt uses alg value '${header.alg}' but allowed dpop signing alg values are ${options.allowedSigningAlgs.join(", ")}.`
1166
+ );
1167
+ }
1168
+ if (options.expectedNonce !== void 0) {
1169
+ if (options.expectedNonce === "") {
1170
+ throw new Oauth2Error(`Invalid 'expectedNonce' provided`);
1171
+ }
1172
+ if (!payload.nonce) {
1173
+ throw new Oauth2Error(
1174
+ `Dpop jwt does not have a nonce value, but expected nonce value '${options.expectedNonce}'`
1175
+ );
1176
+ }
1177
+ if (payload.nonce !== options.expectedNonce) {
1178
+ throw new Oauth2Error(
1179
+ `Dpop jwt contains nonce value '${payload.nonce}', but expected nonce value '${options.expectedNonce}'`
1180
+ );
1181
+ }
1182
+ }
1183
+ if (options.request.method !== payload.htm) {
1184
+ throw new Oauth2Error(
1185
+ `Dpop jwt contains htm value '${payload.htm}', but expected htm value '${options.request.method}'`
1186
+ );
1187
+ }
1188
+ const expectedHtu = htuFromRequestUrl(options.request.url);
1189
+ if (expectedHtu !== payload.htu) {
1190
+ throw new Oauth2Error(
1191
+ `Dpop jwt contains htu value '${payload.htu}', but expected htu value '${expectedHtu}'.`
1192
+ );
1193
+ }
1194
+ if (options.accessToken) {
1195
+ const expectedAth = (0, import_io_wallet_utils11.encodeToBase64Url)(
1196
+ await options.callbacks.hash(
1197
+ (0, import_io_wallet_utils11.decodeUtf8String)(options.accessToken),
1276
1198
  import_oauth210.HashAlgorithm.Sha256
1277
1199
  )
1278
1200
  );
1201
+ if (!payload.ath) {
1202
+ throw new Oauth2Error(
1203
+ `Dpop jwt does not have a ath value, but expected ath value '${expectedAth}'.`
1204
+ );
1205
+ }
1206
+ if (payload.ath !== expectedAth) {
1207
+ throw new Oauth2Error(
1208
+ `Dpop jwt contains ath value '${payload.ath}', but expected ath value '${expectedAth}'.`
1209
+ );
1210
+ }
1211
+ }
1212
+ const jwkThumbprint = await (0, import_oauth210.calculateJwkThumbprint)({
1213
+ hashAlgorithm: import_oauth210.HashAlgorithm.Sha256,
1214
+ hashCallback: options.callbacks.hash,
1215
+ jwk: header.jwk
1216
+ });
1217
+ if (options.expectedJwkThumbprint && options.expectedJwkThumbprint !== jwkThumbprint) {
1218
+ throw new Oauth2Error(
1219
+ `Dpop is signed with jwk with thumbprint value '${jwkThumbprint}', but expect jwk thumbprint value '${options.expectedJwkThumbprint}'`
1220
+ );
1279
1221
  }
1280
- throw new Oauth2Error(
1281
- `Unsupported code challenge method ${options.codeChallengeMethod}`
1282
- );
1222
+ try {
1223
+ (0, import_io_wallet_utils11.verifyJwtIatOrThrow)({
1224
+ iat: payload.iat,
1225
+ now: options.now
1226
+ });
1227
+ } catch (error) {
1228
+ if (error instanceof Error) {
1229
+ throw new Oauth2Error(`Invalid iat claim in dpop JWT: ${error.message}`);
1230
+ }
1231
+ }
1232
+ await (0, import_oauth210.verifyJwt)({
1233
+ compact: options.dpopJwt,
1234
+ errorMessage: "dpop jwt verification failed",
1235
+ header,
1236
+ now: options.now,
1237
+ payload,
1238
+ signer: {
1239
+ alg: header.alg,
1240
+ method: "jwk",
1241
+ publicJwk: header.jwk
1242
+ },
1243
+ verifyJwtCallback: options.callbacks.verifyJwt
1244
+ });
1245
+ return {
1246
+ header,
1247
+ jwkThumbprint,
1248
+ payload
1249
+ };
1283
1250
  }
1284
1251
 
1285
1252
  // src/access-token/verify-access-token-request.ts
1286
1253
  async function verifyAccessTokenRequest(options) {
1254
+ if (options.dpop.expectedNonce === "") {
1255
+ throw new Oauth2Error(`Invalid 'dpop.expectedNonce' provided`);
1256
+ }
1287
1257
  await verifyPkce({
1288
1258
  callbacks: options.callbacks,
1289
1259
  codeChallenge: options.pkce.codeChallenge,
@@ -1294,6 +1264,7 @@ async function verifyAccessTokenRequest(options) {
1294
1264
  allowedSigningAlgs: options.dpop.allowedSigningAlgs,
1295
1265
  callbacks: options.callbacks,
1296
1266
  dpopJwt: options.dpop.jwt,
1267
+ expectedNonce: options.dpop.expectedNonce,
1297
1268
  now: options.now,
1298
1269
  request: options.request
1299
1270
  });
@@ -1324,37 +1295,37 @@ async function verifyAccessTokenRequest(options) {
1324
1295
  }
1325
1296
 
1326
1297
  // src/authorization-request/create-authorization-request.ts
1327
- var import_io_wallet_utils14 = require("@pagopa/io-wallet-utils");
1298
+ var import_io_wallet_utils12 = require("@pagopa/io-wallet-utils");
1328
1299
 
1329
1300
  // src/authorization-request/z-authorization-request.ts
1330
- var import_zod10 = __toESM(require("zod"));
1331
- var zOpenidCredentialAuthorizationDetails = import_zod10.default.object({
1332
- credential_configuration_id: import_zod10.default.string(),
1333
- type: import_zod10.default.literal("openid_credential")
1301
+ var import_zod11 = __toESM(require("zod"));
1302
+ var zOpenidCredentialAuthorizationDetails = import_zod11.default.object({
1303
+ credential_configuration_id: import_zod11.default.string(),
1304
+ type: import_zod11.default.literal("openid_credential")
1334
1305
  });
1335
- var zItL2DocumentProofAuthorizationDetails = import_zod10.default.object({
1336
- challenge_method: import_zod10.default.literal("mrtd+ias"),
1337
- challenge_redirect_uri: import_zod10.default.url(),
1338
- idphinting: import_zod10.default.url(),
1339
- type: import_zod10.default.literal("it_l2+document_proof")
1306
+ var zItL2DocumentProofAuthorizationDetails = import_zod11.default.object({
1307
+ challenge_method: import_zod11.default.literal("mrtd+ias"),
1308
+ challenge_redirect_uri: import_zod11.default.url(),
1309
+ idphinting: import_zod11.default.url(),
1310
+ type: import_zod11.default.literal("it_l2+document_proof")
1340
1311
  });
1341
- var zAuthorizationRequest = import_zod10.default.looseObject({
1342
- authorization_details: import_zod10.default.array(
1343
- import_zod10.default.discriminatedUnion("type", [
1312
+ var zAuthorizationRequest = import_zod11.default.looseObject({
1313
+ authorization_details: import_zod11.default.array(
1314
+ import_zod11.default.discriminatedUnion("type", [
1344
1315
  zOpenidCredentialAuthorizationDetails,
1345
1316
  zItL2DocumentProofAuthorizationDetails
1346
1317
  ])
1347
1318
  ).optional(),
1348
- client_id: import_zod10.default.string(),
1349
- code_challenge: import_zod10.default.string(),
1350
- code_challenge_method: import_zod10.default.string(),
1351
- issuer_state: import_zod10.default.optional(import_zod10.default.string()),
1352
- jti: import_zod10.default.string(),
1353
- redirect_uri: import_zod10.default.url(),
1354
- response_mode: import_zod10.default.string(),
1355
- response_type: import_zod10.default.string(),
1356
- scope: import_zod10.default.string().optional(),
1357
- state: import_zod10.default.string()
1319
+ client_id: import_zod11.default.string(),
1320
+ code_challenge: import_zod11.default.string(),
1321
+ code_challenge_method: import_zod11.default.string(),
1322
+ issuer_state: import_zod11.default.optional(import_zod11.default.string()),
1323
+ jti: import_zod11.default.string().max(MAX_JTI_LENGTH),
1324
+ redirect_uri: import_zod11.default.url(),
1325
+ response_mode: import_zod11.default.string(),
1326
+ response_type: import_zod11.default.string(),
1327
+ scope: import_zod11.default.string().optional(),
1328
+ state: import_zod11.default.string()
1358
1329
  }).refine(
1359
1330
  (data) => data.authorization_details !== void 0 || data.scope !== void 0,
1360
1331
  {
@@ -1362,25 +1333,25 @@ var zAuthorizationRequest = import_zod10.default.looseObject({
1362
1333
  path: ["authorization_details"]
1363
1334
  }
1364
1335
  );
1365
- var zPushedAuthorizationRequestSigned = import_zod10.default.looseObject({
1366
- client_id: import_zod10.default.string().describe(
1336
+ var zPushedAuthorizationRequestSigned = import_zod11.default.looseObject({
1337
+ client_id: import_zod11.default.string().describe(
1367
1338
  "MUST be set to the thumbprint of the jwk value in the cnf parameter inside the Wallet Attestation."
1368
1339
  ),
1369
- pkceCodeVerifier: import_zod10.default.string().describe(
1340
+ pkceCodeVerifier: import_zod11.default.string().describe(
1370
1341
  "Code verifier for PKCE. If not provided in CreatePushedAuthorizationRequestOptions, SDK will generate one."
1371
1342
  ),
1372
- request: import_zod10.default.string().describe(
1343
+ request: import_zod11.default.string().describe(
1373
1344
  "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."
1374
1345
  )
1375
1346
  });
1376
- var zPushedAuthorizationRequestUnsigned = import_zod10.default.looseObject({
1347
+ var zPushedAuthorizationRequestUnsigned = import_zod11.default.looseObject({
1377
1348
  authorizationRequest: zAuthorizationRequest.describe(
1378
1349
  "The authorization request parameters as a plain object. Used when require_signed_request_object is false."
1379
1350
  ),
1380
- client_id: import_zod10.default.string().describe(
1351
+ client_id: import_zod11.default.string().describe(
1381
1352
  "Thumbprint of the jwk value in the cnf parameter inside Wallet Attestation."
1382
1353
  ),
1383
- pkceCodeVerifier: import_zod10.default.string().describe("PKCE code verifier. Auto-generated if not provided in options.")
1354
+ pkceCodeVerifier: import_zod11.default.string().describe("PKCE code verifier. Auto-generated if not provided in options.")
1384
1355
  });
1385
1356
  function isPushedAuthorizationRequestSigned(par) {
1386
1357
  return "request" in par && typeof par.request === "string";
@@ -1388,9 +1359,9 @@ function isPushedAuthorizationRequestSigned(par) {
1388
1359
  function isPushedAuthorizationRequestUnsigned(par) {
1389
1360
  return "authorizationRequest" in par;
1390
1361
  }
1391
- var zPushedAuthorizationResponse = import_zod10.default.looseObject({
1392
- expires_in: import_zod10.default.number().int(),
1393
- request_uri: import_zod10.default.string()
1362
+ var zPushedAuthorizationResponse = import_zod11.default.looseObject({
1363
+ expires_in: import_zod11.default.number().int(),
1364
+ request_uri: import_zod11.default.string()
1394
1365
  });
1395
1366
 
1396
1367
  // src/authorization-request/create-authorization-request.ts
@@ -1407,14 +1378,14 @@ async function createPushedAuthorizationRequest(options) {
1407
1378
  client_id: options.clientId,
1408
1379
  code_challenge: pkce.codeChallenge,
1409
1380
  code_challenge_method: pkce.codeChallengeMethod,
1410
- jti: options.jti ?? (0, import_io_wallet_utils14.encodeToBase64Url)(
1381
+ jti: options.jti ?? (0, import_io_wallet_utils12.encodeToBase64Url)(
1411
1382
  await options.callbacks.generateRandom(RANDOM_BYTES_SIZE)
1412
1383
  ),
1413
1384
  redirect_uri: options.redirectUri,
1414
1385
  response_mode: options.responseMode,
1415
1386
  response_type: "code",
1416
1387
  scope: options.scope,
1417
- state: options.state ?? (0, import_io_wallet_utils14.encodeToBase64Url)(
1388
+ state: options.state ?? (0, import_io_wallet_utils12.encodeToBase64Url)(
1418
1389
  await options.callbacks.generateRandom(RANDOM_BYTES_SIZE)
1419
1390
  )
1420
1391
  });
@@ -1427,7 +1398,7 @@ async function createPushedAuthorizationRequest(options) {
1427
1398
  );
1428
1399
  }
1429
1400
  const iat = options.issuedAt ?? /* @__PURE__ */ new Date();
1430
- const exp = options.expiresAt ?? (0, import_io_wallet_utils14.addSecondsToDate)(iat, JWT_EXPIRY_SECONDS);
1401
+ const exp = options.expiresAt ?? (0, import_io_wallet_utils12.addSecondsToDate)(iat, JWT_EXPIRY_SECONDS);
1431
1402
  const requestJwt = await options.callbacks.signJwt(dpop.signer, {
1432
1403
  header: {
1433
1404
  alg: dpop.signer.alg,
@@ -1436,8 +1407,8 @@ async function createPushedAuthorizationRequest(options) {
1436
1407
  },
1437
1408
  payload: {
1438
1409
  aud: options.audience,
1439
- exp: (0, import_io_wallet_utils14.dateToSeconds)(exp),
1440
- iat: (0, import_io_wallet_utils14.dateToSeconds)(iat),
1410
+ exp: (0, import_io_wallet_utils12.dateToSeconds)(exp),
1411
+ iat: (0, import_io_wallet_utils12.dateToSeconds)(iat),
1441
1412
  iss: dpop.signer.publicJwk.kid,
1442
1413
  ...authorizationRequest
1443
1414
  }
@@ -1457,10 +1428,10 @@ async function createPushedAuthorizationRequest(options) {
1457
1428
  }
1458
1429
 
1459
1430
  // src/authorization-request/fetch-authorization-response.ts
1460
- var import_io_wallet_utils15 = require("@pagopa/io-wallet-utils");
1431
+ var import_io_wallet_utils13 = require("@pagopa/io-wallet-utils");
1461
1432
  async function fetchPushedAuthorizationResponse(options) {
1462
1433
  try {
1463
- const fetch = (0, import_io_wallet_utils15.createFetcher)(options.callbacks.fetch);
1434
+ const fetch = (0, import_io_wallet_utils13.createFetcher)(options.callbacks.fetch);
1464
1435
  const body = isPushedAuthorizationRequestSigned(
1465
1436
  options.pushedAuthorizationRequest
1466
1437
  ) ? new URLSearchParams({
@@ -1474,25 +1445,25 @@ async function fetchPushedAuthorizationResponse(options) {
1474
1445
  {
1475
1446
  body,
1476
1447
  headers: {
1477
- [import_io_wallet_utils15.HEADERS.CONTENT_TYPE]: import_io_wallet_utils15.CONTENT_TYPES.FORM_URLENCODED,
1478
- [import_io_wallet_utils15.HEADERS.OAUTH_CLIENT_ATTESTATION]: options.walletAttestation,
1479
- [import_io_wallet_utils15.HEADERS.OAUTH_CLIENT_ATTESTATION_POP]: options.clientAttestationDPoP
1448
+ [import_io_wallet_utils13.HEADERS.CONTENT_TYPE]: import_io_wallet_utils13.CONTENT_TYPES.FORM_URLENCODED,
1449
+ [import_io_wallet_utils13.HEADERS.OAUTH_CLIENT_ATTESTATION]: options.walletAttestation,
1450
+ [import_io_wallet_utils13.HEADERS.OAUTH_CLIENT_ATTESTATION_POP]: options.clientAttestationDPoP
1480
1451
  },
1481
1452
  method: "POST"
1482
1453
  }
1483
1454
  );
1484
- await (0, import_io_wallet_utils15.hasStatusOrThrow)(201, import_io_wallet_utils15.UnexpectedStatusCodeError)(parResponse);
1455
+ await (0, import_io_wallet_utils13.hasStatusOrThrow)(201, import_io_wallet_utils13.UnexpectedStatusCodeError)(parResponse);
1485
1456
  const parResponseJson = await parResponse.json();
1486
1457
  const parsedParResponse = zPushedAuthorizationResponse.safeParse(parResponseJson);
1487
1458
  if (!parsedParResponse.success) {
1488
- throw new import_io_wallet_utils15.ValidationError(
1459
+ throw new import_io_wallet_utils13.ValidationError(
1489
1460
  `Failed to parse pushed authorization response`,
1490
1461
  parsedParResponse.error
1491
1462
  );
1492
1463
  }
1493
1464
  return parsedParResponse.data;
1494
1465
  } catch (error) {
1495
- if (error instanceof import_io_wallet_utils15.UnexpectedStatusCodeError || error instanceof import_io_wallet_utils15.ValidationError) {
1466
+ if (error instanceof import_io_wallet_utils13.UnexpectedStatusCodeError || error instanceof import_io_wallet_utils13.ValidationError) {
1496
1467
  throw error;
1497
1468
  }
1498
1469
  throw new PushedAuthorizationRequestError(
@@ -1538,69 +1509,22 @@ function parseAuthorizationRequest(options) {
1538
1509
  }
1539
1510
 
1540
1511
  // src/authorization-request/parse-pushed-authorization-request.ts
1541
- var import_io_wallet_utils19 = require("@pagopa/io-wallet-utils");
1542
- var import_zod12 = __toESM(require("zod"));
1543
-
1544
- // src/jar/create-jar-request.ts
1545
- var import_io_wallet_utils16 = require("@pagopa/io-wallet-utils");
1546
- async function createJarRequest(options) {
1547
- const {
1548
- authorizationRequestHeader,
1549
- authorizationRequestPayload,
1550
- callbacks,
1551
- jweEncryptor,
1552
- jwtSigner,
1553
- requestUri
1554
- } = options;
1555
- let authorizationRequestJwt;
1556
- let encryptionJwk;
1557
- const now = options.now ?? /* @__PURE__ */ new Date();
1558
- const { jwt, signerJwk } = await callbacks.signJwt(jwtSigner, {
1559
- header: authorizationRequestHeader,
1560
- payload: {
1561
- ...options.additionalJwtPayload,
1562
- ...authorizationRequestPayload,
1563
- exp: (0, import_io_wallet_utils16.dateToSeconds)((0, import_io_wallet_utils16.addSecondsToDate)(now, options.expiresInSeconds)),
1564
- iat: (0, import_io_wallet_utils16.dateToSeconds)(now)
1565
- }
1566
- });
1567
- authorizationRequestJwt = jwt;
1568
- if (jweEncryptor) {
1569
- if (!callbacks.encryptJwe) {
1570
- throw new Oauth2Error(
1571
- "callbacks.encryptJwe is required when jweEncryptor is provided"
1572
- );
1573
- }
1574
- const encryptionResult = await callbacks.encryptJwe(
1575
- jweEncryptor,
1576
- authorizationRequestJwt
1577
- );
1578
- authorizationRequestJwt = encryptionResult.jwe;
1579
- encryptionJwk = encryptionResult.encryptionJwk;
1580
- }
1581
- const client_id = authorizationRequestPayload.client_id;
1582
- const jarAuthorizationRequest = requestUri ? { client_id, request_uri: requestUri } : { client_id, request: authorizationRequestJwt };
1583
- return {
1584
- authorizationRequestJwt,
1585
- encryptionJwk,
1586
- jarAuthorizationRequest,
1587
- signerJwk
1588
- };
1589
- }
1512
+ var import_io_wallet_utils15 = require("@pagopa/io-wallet-utils");
1513
+ var import_zod13 = __toESM(require("zod"));
1590
1514
 
1591
1515
  // src/jar/fetch-jar-request-object.ts
1592
- var import_io_wallet_utils17 = require("@pagopa/io-wallet-utils");
1516
+ var import_io_wallet_utils14 = require("@pagopa/io-wallet-utils");
1593
1517
  async function fetchJarRequestObject(options) {
1594
1518
  const { fetch, requestUri } = options;
1595
1519
  const JAR_ACCEPT_HEADER = [
1596
- import_io_wallet_utils17.ContentType.OAuthAuthorizationRequestJwt,
1520
+ import_io_wallet_utils14.ContentType.OAuthAuthorizationRequestJwt,
1597
1521
  // Preferred: application/oauth-authz-req+jwt
1598
- `${import_io_wallet_utils17.ContentType.Jwt};q=0.9`,
1522
+ `${import_io_wallet_utils14.ContentType.Jwt};q=0.9`,
1599
1523
  // Fallback: application/jwt
1600
1524
  "text/plain"
1601
1525
  // Final fallback: text/plain
1602
1526
  ].join(", ");
1603
- const response = await (0, import_io_wallet_utils17.createFetcher)(fetch)(requestUri, {
1527
+ const response = await (0, import_io_wallet_utils14.createFetcher)(fetch)(requestUri, {
1604
1528
  headers: {
1605
1529
  Accept: JAR_ACCEPT_HEADER
1606
1530
  },
@@ -1610,7 +1534,7 @@ async function fetchJarRequestObject(options) {
1610
1534
  `Fetching request_object from request_uri '${requestUri}' failed`
1611
1535
  );
1612
1536
  });
1613
- await (0, import_io_wallet_utils17.hasStatusOrThrow)(200, import_io_wallet_utils17.UnexpectedStatusCodeError)(response);
1537
+ await (0, import_io_wallet_utils14.hasStatusOrThrow)(200, import_io_wallet_utils14.UnexpectedStatusCodeError)(response);
1614
1538
  return await response.text();
1615
1539
  }
1616
1540
 
@@ -1646,125 +1570,32 @@ async function parseJarRequest(options) {
1646
1570
  return { authorizationRequestJwt, sendBy };
1647
1571
  }
1648
1572
 
1649
- // src/jar/verify-jar-request.ts
1650
- var import_oauth211 = require("@openid4vc/oauth2");
1651
- var import_io_wallet_utils18 = require("@pagopa/io-wallet-utils");
1652
-
1653
1573
  // src/jar/z-jar.ts
1654
- var import_zod11 = __toESM(require("zod"));
1655
- var zJarAuthorizationRequest = import_zod11.default.looseObject({
1656
- client_id: import_zod11.default.optional(import_zod11.default.string()),
1657
- request: import_zod11.default.optional(import_zod11.default.string()),
1658
- request_uri: import_zod11.default.url().optional()
1574
+ var import_zod12 = __toESM(require("zod"));
1575
+ var zJarAuthorizationRequest = import_zod12.default.looseObject({
1576
+ client_id: import_zod12.default.optional(import_zod12.default.string()),
1577
+ request: import_zod12.default.optional(import_zod12.default.string()),
1578
+ request_uri: import_zod12.default.url().optional()
1659
1579
  });
1660
- var zJarRequestObjectPayload = import_zod11.default.looseObject({
1580
+ var zJarRequestObjectPayload = import_zod12.default.looseObject({
1661
1581
  ...zJwtPayload.shape,
1662
- client_id: import_zod11.default.string()
1582
+ client_id: import_zod12.default.string()
1663
1583
  });
1664
- var zSignedAuthorizationRequestJwtHeaderTyp = import_zod11.default.literal(
1584
+ var zSignedAuthorizationRequestJwtHeaderTyp = import_zod12.default.literal(
1665
1585
  "oauth-authz-req+jwt"
1666
1586
  );
1667
- var zJarRequestObjectHeader = import_zod11.default.looseObject({
1587
+ var zJarRequestObjectHeader = import_zod12.default.looseObject({
1668
1588
  ...zJwtHeader.shape,
1669
1589
  typ: zSignedAuthorizationRequestJwtHeaderTyp
1670
1590
  });
1671
1591
  var signedAuthorizationRequestJwtHeaderTyp = zSignedAuthorizationRequestJwtHeaderTyp.value;
1672
- var zJwtAuthorizationRequestJwtHeaderTyp = import_zod11.default.literal("jwt");
1592
+ var zJwtAuthorizationRequestJwtHeaderTyp = import_zod12.default.literal("jwt");
1673
1593
  var jwtAuthorizationRequestJwtHeaderTyp = zJwtAuthorizationRequestJwtHeaderTyp.value;
1674
1594
 
1675
- // src/jar/verify-jar-request.ts
1676
- async function verifyJarRequest(options) {
1677
- const { authorizationRequestJwt, callbacks, jarRequestParams, jwtSigner } = options;
1678
- const requestObjectIsEncrypted = import_oauth211.zCompactJwe.safeParse(
1679
- authorizationRequestJwt
1680
- ).success;
1681
- if (requestObjectIsEncrypted) {
1682
- throw new Oauth2Error("Encrypted JWE request objects are not supported.");
1683
- }
1684
- const requestIsSigned = import_oauth211.zCompactJwt.safeParse(
1685
- authorizationRequestJwt
1686
- ).success;
1687
- if (!requestIsSigned) {
1688
- throw new Oauth2Error("JAR request object is not a valid JWT.");
1689
- }
1690
- const { authorizationRequestPayload, jwt, signer } = await verifyJarRequestObject({
1691
- authorizationRequestJwt,
1692
- callbacks,
1693
- jwtSigner
1694
- });
1695
- if (!authorizationRequestPayload.client_id) {
1696
- throw new Oauth2Error(
1697
- 'Jar Request Object is missing the required "client_id" field.'
1698
- );
1699
- }
1700
- if (jarRequestParams.client_id !== authorizationRequestPayload.client_id) {
1701
- throw new Oauth2Error(
1702
- "client_id does not match the request object client_id."
1703
- );
1704
- }
1705
- if (jwt.payload.iss !== authorizationRequestPayload.client_id) {
1706
- throw new Oauth2Error("iss claim in request JWT does not match client_id");
1707
- }
1708
- if (jwt.payload.exp === void 0) {
1709
- throw new Oauth2Error("exp claim in request JWT is missing");
1710
- }
1711
- const now = options.now ?? /* @__PURE__ */ new Date();
1712
- const nowSeconds = Math.floor(now.getTime() / 1e3);
1713
- if (nowSeconds > jwt.payload.exp) {
1714
- throw new Oauth2Error("exp claim in request JWT is expired");
1715
- }
1716
- if (jwt.payload.iat === void 0) {
1717
- throw new Oauth2Error("iat claim in request JWT is missing");
1718
- }
1719
- const MAX_IAT_AGE_SECONDS = 5 * 60;
1720
- if (nowSeconds - jwt.payload.iat > MAX_IAT_AGE_SECONDS) {
1721
- throw new Oauth2Error(
1722
- "iat claim in request JWT is too old (must be within 5 minutes)"
1723
- );
1724
- }
1725
- const CLOCK_SKEW_TOLERANCE_SECONDS = 60;
1726
- if (jwt.payload.iat - nowSeconds > CLOCK_SKEW_TOLERANCE_SECONDS) {
1727
- throw new Oauth2Error("iat claim in request JWT is too far in the future");
1728
- }
1729
- return {
1730
- authorizationRequestPayload,
1731
- jwt,
1732
- signer
1733
- };
1734
- }
1735
- async function verifyJarRequestObject(options) {
1736
- const { authorizationRequestJwt, callbacks, jwtSigner } = options;
1737
- const jwt = (0, import_oauth211.decodeJwt)({ jwt: authorizationRequestJwt });
1738
- const authorizationRequestPayload = (0, import_io_wallet_utils18.parseWithErrorHandling)(
1739
- zJarRequestObjectPayload,
1740
- jwt.payload
1741
- );
1742
- const { signer } = await (0, import_oauth211.verifyJwt)({
1743
- compact: authorizationRequestJwt,
1744
- header: jwt.header,
1745
- payload: authorizationRequestPayload,
1746
- signer: jwtSigner,
1747
- verifyJwtCallback: callbacks.verifyJwt
1748
- });
1749
- if (jwt.header.typ !== signedAuthorizationRequestJwtHeaderTyp && jwt.header.typ !== jwtAuthorizationRequestJwtHeaderTyp) {
1750
- throw new Oauth2Error(
1751
- `Invalid Jar Request Object typ header. Expected "oauth-authz-req+jwt" or "jwt", received "${jwt.header.typ}".`
1752
- );
1753
- }
1754
- return {
1755
- authorizationRequestPayload,
1756
- jwt: {
1757
- ...jwt,
1758
- payload: authorizationRequestPayload
1759
- },
1760
- signer
1761
- };
1762
- }
1763
-
1764
1595
  // src/authorization-request/parse-pushed-authorization-request.ts
1765
1596
  async function parsePushedAuthorizationRequest(options) {
1766
- const parsed = (0, import_io_wallet_utils19.parseWithErrorHandling)(
1767
- import_zod12.default.union([zAuthorizationRequest, zJarAuthorizationRequest]),
1597
+ const parsed = (0, import_io_wallet_utils15.parseWithErrorHandling)(
1598
+ import_zod13.default.union([zAuthorizationRequest, zJarAuthorizationRequest]),
1768
1599
  options.authorizationRequest,
1769
1600
  "Invalid authorization request. Could not parse authorization request or jar."
1770
1601
  );
@@ -1775,12 +1606,15 @@ async function parsePushedAuthorizationRequest(options) {
1775
1606
  callbacks: options.callbacks,
1776
1607
  jarRequestParams: parsed
1777
1608
  });
1778
- const jwt = decodeJwt({ jwt: parsedJar.authorizationRequestJwt });
1609
+ const jwt = decodeJwt({
1610
+ errorMessagePrefix: "Error decoding pushed authorization request JWT:",
1611
+ jwt: parsedJar.authorizationRequestJwt
1612
+ });
1779
1613
  parsedAuthorizationRequest = zAuthorizationRequest.safeParse(jwt.payload);
1780
1614
  if (!parsedAuthorizationRequest.success) {
1781
1615
  throw new Oauth2Error(
1782
1616
  `Invalid authorization request. Could not parse jar request payload.
1783
- ${(0, import_io_wallet_utils19.formatZodError)(parsedAuthorizationRequest.error)}`
1617
+ ${(0, import_io_wallet_utils15.formatZodError)(parsedAuthorizationRequest.error)}`
1784
1618
  );
1785
1619
  }
1786
1620
  authorizationRequestJwt = parsedJar.authorizationRequestJwt;
@@ -1791,7 +1625,7 @@ ${(0, import_io_wallet_utils19.formatZodError)(parsedAuthorizationRequest.error)
1791
1625
  if (!parsedAuthorizationRequest.success) {
1792
1626
  throw new Oauth2Error(
1793
1627
  `Error occurred during validation of pushed authorization request.
1794
- ${(0, import_io_wallet_utils19.formatZodError)(parsedAuthorizationRequest.error)}`
1628
+ ${(0, import_io_wallet_utils15.formatZodError)(parsedAuthorizationRequest.error)}`
1795
1629
  );
1796
1630
  }
1797
1631
  }
@@ -1832,22 +1666,116 @@ async function verifyAuthorizationRequest(options) {
1832
1666
  } : void 0
1833
1667
  };
1834
1668
  }
1835
- async function verifyAuthorizationRequestDpop(options, request, callbacks, now) {
1836
- if (options.required && !options.jwt) {
1669
+ async function verifyAuthorizationRequestDpop(options, request, callbacks, now) {
1670
+ if (options.required && !options.jwt) {
1671
+ throw new Oauth2Error(
1672
+ `Missing required DPoP parameters in authorization request. DPoP header is required.`
1673
+ );
1674
+ }
1675
+ const verifyDpopResult = options.jwt ? await verifyTokenDPoP({
1676
+ allowedSigningAlgs: options.allowedSigningAlgs,
1677
+ callbacks,
1678
+ dpopJwt: options.jwt,
1679
+ now,
1680
+ request
1681
+ }) : void 0;
1682
+ return {
1683
+ jwk: verifyDpopResult?.header.jwk,
1684
+ jwkThumbprint: verifyDpopResult?.jwkThumbprint
1685
+ };
1686
+ }
1687
+
1688
+ // src/jar/verify-jar-request.ts
1689
+ var import_oauth211 = require("@openid4vc/oauth2");
1690
+ var import_io_wallet_utils16 = require("@pagopa/io-wallet-utils");
1691
+ async function verifyJarRequest(options) {
1692
+ const { authorizationRequestJwt, callbacks, jarRequestParams, jwtSigner } = options;
1693
+ const requestObjectIsEncrypted = import_oauth211.zCompactJwe.safeParse(
1694
+ authorizationRequestJwt
1695
+ ).success;
1696
+ if (requestObjectIsEncrypted) {
1697
+ throw new Oauth2Error("Encrypted JWE request objects are not supported.");
1698
+ }
1699
+ const requestIsSigned = import_oauth211.zCompactJwt.safeParse(
1700
+ authorizationRequestJwt
1701
+ ).success;
1702
+ if (!requestIsSigned) {
1703
+ throw new Oauth2Error("JAR request object is not a valid JWT.");
1704
+ }
1705
+ const { authorizationRequestPayload, jwt, signer } = await verifyJarRequestObject({
1706
+ authorizationRequestJwt,
1707
+ callbacks,
1708
+ jwtSigner
1709
+ });
1710
+ if (!authorizationRequestPayload.client_id) {
1711
+ throw new Oauth2Error(
1712
+ 'Jar Request Object is missing the required "client_id" field.'
1713
+ );
1714
+ }
1715
+ if (jarRequestParams.client_id !== authorizationRequestPayload.client_id) {
1716
+ throw new Oauth2Error(
1717
+ "client_id does not match the request object client_id."
1718
+ );
1719
+ }
1720
+ if (jwt.payload.iss !== authorizationRequestPayload.client_id) {
1721
+ throw new Oauth2Error("iss claim in request JWT does not match client_id");
1722
+ }
1723
+ if (jwt.payload.exp === void 0) {
1724
+ throw new Oauth2Error("exp claim in request JWT is missing");
1725
+ }
1726
+ const now = options.now ?? /* @__PURE__ */ new Date();
1727
+ const nowSeconds = Math.floor(now.getTime() / 1e3);
1728
+ if (nowSeconds > jwt.payload.exp) {
1729
+ throw new Oauth2Error("exp claim in request JWT is expired");
1730
+ }
1731
+ if (jwt.payload.iat === void 0) {
1732
+ throw new Oauth2Error("iat claim in request JWT is missing");
1733
+ }
1734
+ const MAX_IAT_AGE_SECONDS = 5 * 60;
1735
+ if (nowSeconds - jwt.payload.iat > MAX_IAT_AGE_SECONDS) {
1736
+ throw new Oauth2Error(
1737
+ "iat claim in request JWT is too old (must be within 5 minutes)"
1738
+ );
1739
+ }
1740
+ const CLOCK_SKEW_TOLERANCE_SECONDS = 60;
1741
+ if (jwt.payload.iat - nowSeconds > CLOCK_SKEW_TOLERANCE_SECONDS) {
1742
+ throw new Oauth2Error("iat claim in request JWT is too far in the future");
1743
+ }
1744
+ return {
1745
+ authorizationRequestPayload,
1746
+ jwt,
1747
+ signer
1748
+ };
1749
+ }
1750
+ async function verifyJarRequestObject(options) {
1751
+ const { authorizationRequestJwt, callbacks, jwtSigner } = options;
1752
+ const jwt = decodeJwt({
1753
+ errorMessagePrefix: "Error decoding JAR authorization request JWT:",
1754
+ jwt: authorizationRequestJwt
1755
+ });
1756
+ const authorizationRequestPayload = (0, import_io_wallet_utils16.parseWithErrorHandling)(
1757
+ zJarRequestObjectPayload,
1758
+ jwt.payload
1759
+ );
1760
+ const { signer } = await (0, import_oauth211.verifyJwt)({
1761
+ compact: authorizationRequestJwt,
1762
+ header: jwt.header,
1763
+ payload: authorizationRequestPayload,
1764
+ signer: jwtSigner,
1765
+ verifyJwtCallback: callbacks.verifyJwt
1766
+ });
1767
+ if (jwt.header.typ !== signedAuthorizationRequestJwtHeaderTyp && jwt.header.typ !== jwtAuthorizationRequestJwtHeaderTyp) {
1837
1768
  throw new Oauth2Error(
1838
- `Missing required DPoP parameters in authorization request. DPoP header is required.`
1769
+ `Invalid Jar Request Object typ header. Expected "oauth-authz-req+jwt" or "jwt", received "${jwt.header.typ}".`
1839
1770
  );
1840
1771
  }
1841
- const verifyDpopResult = options.jwt ? await verifyTokenDPoP({
1842
- allowedSigningAlgs: options.allowedSigningAlgs,
1843
- callbacks,
1844
- dpopJwt: options.jwt,
1845
- now,
1846
- request
1847
- }) : void 0;
1848
1772
  return {
1849
- jwk: verifyDpopResult?.header.jwk,
1850
- jwkThumbprint: verifyDpopResult?.jwkThumbprint
1773
+ authorizationRequestPayload,
1774
+ jwt: {
1775
+ ...jwt,
1776
+ payload: authorizationRequestPayload
1777
+ },
1778
+ signer
1851
1779
  };
1852
1780
  }
1853
1781
 
@@ -1862,7 +1790,10 @@ async function verifyPushedAuthorizationRequest(options) {
1862
1790
  let jar;
1863
1791
  if (options.authorizationRequestJwt) {
1864
1792
  if (requireSigned) {
1865
- const decoded = decodeJwt({ jwt: options.authorizationRequestJwt.jwt });
1793
+ const decoded = decodeJwt({
1794
+ errorMessagePrefix: "Error decoding pushed authorization request JWT:",
1795
+ jwt: options.authorizationRequestJwt.jwt
1796
+ });
1866
1797
  if (decoded.header.alg === "none") {
1867
1798
  throw new PushedAuthorizationRequestError(
1868
1799
  'Authorization Server requires signed request objects, but JAR has algorithm "none"'
@@ -1911,15 +1842,247 @@ async function verifyPushedAuthorizationRequest(options) {
1911
1842
  };
1912
1843
  }
1913
1844
 
1845
+ // src/client-attestation/client-authentication.ts
1846
+ var SupportedClientAuthenticationMethod = {
1847
+ ClientSecretBasic: "client_secret_basic",
1848
+ ClientSecretPost: "client_secret_post",
1849
+ None: "none",
1850
+ WalletAttestationJwt: "attest_jwt_client_auth"
1851
+ };
1852
+ function isClientAttestationSupported(options) {
1853
+ if (!options.authorizationServerMetadata.token_endpoint_auth_methods_supported || !options.authorizationServerMetadata.token_endpoint_auth_methods_supported.includes(
1854
+ SupportedClientAuthenticationMethod.WalletAttestationJwt
1855
+ )) {
1856
+ return {
1857
+ supported: false
1858
+ };
1859
+ }
1860
+ return {
1861
+ supported: true
1862
+ };
1863
+ }
1864
+ function clientAuthenticationAnonymous() {
1865
+ return () => {
1866
+ };
1867
+ }
1868
+ function clientAuthenticationWalletAttestationJwt(options) {
1869
+ return async ({ authorizationServerMetadata, headers }) => {
1870
+ const clientAttestationPop = await createClientAttestationPopJwt({
1871
+ authorizationServer: authorizationServerMetadata.issuer,
1872
+ callbacks: options.callbacks,
1873
+ clientAttestation: options.walletAttestationJwt
1874
+ });
1875
+ headers.set(oauthClientAttestationHeader, options.walletAttestationJwt);
1876
+ headers.set(oauthClientAttestationPopHeader, clientAttestationPop);
1877
+ };
1878
+ }
1879
+
1880
+ // src/client-attestation/v1.0/create-wallet-attestation-jwt.ts
1881
+ var import_io_wallet_utils17 = require("@pagopa/io-wallet-utils");
1882
+ var createWalletAttestationJwt = async (options) => {
1883
+ try {
1884
+ const { signJwt } = options.callbacks;
1885
+ const iat = /* @__PURE__ */ new Date();
1886
+ const exp = options.expiresAt ?? (0, import_io_wallet_utils17.addSecondsToDate)(iat, 3600);
1887
+ const payload = {
1888
+ cnf: { jwk: options.dpopJwkPublic },
1889
+ exp: (0, import_io_wallet_utils17.dateToSeconds)(exp),
1890
+ iat: (0, import_io_wallet_utils17.dateToSeconds)(iat),
1891
+ iss: options.issuer,
1892
+ sub: options.dpopJwkPublic.kid,
1893
+ ...options.walletLink && { wallet_link: options.walletLink },
1894
+ ...options.walletName && { wallet_name: options.walletName },
1895
+ aal: options.authenticatorAssuranceLevel
1896
+ };
1897
+ const header = {
1898
+ alg: options.signer.alg,
1899
+ kid: options.signer.kid,
1900
+ trust_chain: options.signer.trustChain,
1901
+ typ: "oauth-client-attestation+jwt"
1902
+ };
1903
+ const result = await signJwt(options.signer, {
1904
+ header,
1905
+ payload
1906
+ });
1907
+ decodeJwt({
1908
+ errorMessagePrefix: "Error decoding wallet attestation JWT:",
1909
+ headerSchema: zWalletAttestationJwtHeaderV1_0,
1910
+ jwt: result.jwt,
1911
+ payloadSchema: zWalletAttestationJwtPayloadV1_0
1912
+ });
1913
+ return result.jwt;
1914
+ } catch (error) {
1915
+ if (error instanceof import_io_wallet_utils17.ValidationError) {
1916
+ throw error;
1917
+ }
1918
+ throw new ClientAttestationError(
1919
+ `Unexpected error during wallet attestation creation: ${error instanceof Error ? error.message : String(error)}`
1920
+ );
1921
+ }
1922
+ };
1923
+
1924
+ // src/client-attestation/v1.3/create-wallet-attestation-jwt.ts
1925
+ var import_io_wallet_utils18 = require("@pagopa/io-wallet-utils");
1926
+ var createWalletAttestationJwt2 = async (options) => {
1927
+ try {
1928
+ const { signJwt } = options.callbacks;
1929
+ const iat = /* @__PURE__ */ new Date();
1930
+ const exp = options.expiresAt ?? (0, import_io_wallet_utils18.addSecondsToDate)(iat, 3600);
1931
+ if (options.nbf && options.nbf >= exp) {
1932
+ throw new import_io_wallet_utils18.ValidationError("nbf must be before exp");
1933
+ }
1934
+ const payload = {
1935
+ cnf: { jwk: options.dpopJwkPublic },
1936
+ exp: (0, import_io_wallet_utils18.dateToSeconds)(exp),
1937
+ iat: (0, import_io_wallet_utils18.dateToSeconds)(iat),
1938
+ iss: options.issuer,
1939
+ sub: options.dpopJwkPublic.kid,
1940
+ ...options.nbf && { nbf: (0, import_io_wallet_utils18.dateToSeconds)(options.nbf) },
1941
+ ...options.status && { status: options.status },
1942
+ ...options.walletLink && { wallet_link: options.walletLink },
1943
+ ...options.walletName && { wallet_name: options.walletName }
1944
+ };
1945
+ const header = {
1946
+ alg: options.signer.alg,
1947
+ kid: options.signer.kid,
1948
+ typ: "oauth-client-attestation+jwt",
1949
+ x5c: options.signer.x5c,
1950
+ // REQUIRED
1951
+ ...options.signer.trustChain && {
1952
+ trust_chain: options.signer.trustChain
1953
+ }
1954
+ };
1955
+ const result = await signJwt(options.signer, {
1956
+ header,
1957
+ payload
1958
+ });
1959
+ decodeJwt({
1960
+ errorMessagePrefix: "Error decoding wallet attestation JWT:",
1961
+ headerSchema: zWalletAttestationJwtHeaderV1_3,
1962
+ jwt: result.jwt,
1963
+ payloadSchema: zWalletAttestationJwtPayloadV1_3
1964
+ });
1965
+ return result.jwt;
1966
+ } catch (error) {
1967
+ if (error instanceof import_io_wallet_utils18.ValidationError) {
1968
+ throw error;
1969
+ }
1970
+ throw new ClientAttestationError(
1971
+ `Unexpected error during wallet attestation creation: ${error instanceof Error ? error.message : String(error)}`
1972
+ );
1973
+ }
1974
+ };
1975
+
1976
+ // src/client-attestation/v1.4/create-wallet-attestation-jwt.ts
1977
+ var import_io_wallet_utils19 = require("@pagopa/io-wallet-utils");
1978
+ var createWalletAttestationJwt3 = async (options) => {
1979
+ try {
1980
+ const { signJwt } = options.callbacks;
1981
+ const iat = /* @__PURE__ */ new Date();
1982
+ const exp = options.expiresAt ?? (0, import_io_wallet_utils19.addSecondsToDate)(iat, 3600);
1983
+ if (options.nbf && options.nbf >= exp) {
1984
+ throw new import_io_wallet_utils19.ValidationError("nbf must be before exp");
1985
+ }
1986
+ const payload = {
1987
+ cnf: { jwk: options.dpopJwkPublic },
1988
+ exp: (0, import_io_wallet_utils19.dateToSeconds)(exp),
1989
+ iat: (0, import_io_wallet_utils19.dateToSeconds)(iat),
1990
+ iss: options.issuer,
1991
+ status: options.status,
1992
+ sub: options.dpopJwkPublic.kid,
1993
+ wallet_link: options.walletLink,
1994
+ wallet_name: options.walletName,
1995
+ ...options.nbf && { nbf: (0, import_io_wallet_utils19.dateToSeconds)(options.nbf) },
1996
+ ...options.eudiWalletInfo && {
1997
+ eudi_wallet_info: options.eudiWalletInfo
1998
+ }
1999
+ };
2000
+ const header = {
2001
+ alg: options.signer.alg,
2002
+ kid: options.signer.kid,
2003
+ typ: "oauth-client-attestation+jwt",
2004
+ x5c: options.signer.x5c,
2005
+ ...options.signer.trustChain && {
2006
+ trust_chain: options.signer.trustChain
2007
+ }
2008
+ };
2009
+ const result = await signJwt(options.signer, {
2010
+ header,
2011
+ payload
2012
+ });
2013
+ decodeJwt({
2014
+ errorMessagePrefix: "Error decoding wallet attestation JWT:",
2015
+ headerSchema: zWalletAttestationJwtHeaderV1_4,
2016
+ jwt: result.jwt,
2017
+ payloadSchema: zWalletAttestationJwtPayloadV1_4
2018
+ });
2019
+ return result.jwt;
2020
+ } catch (error) {
2021
+ if (error instanceof import_io_wallet_utils19.ValidationError) {
2022
+ throw error;
2023
+ }
2024
+ throw new ClientAttestationError(
2025
+ `Unexpected error during wallet attestation creation: ${error instanceof Error ? error.message : String(error)}`
2026
+ );
2027
+ }
2028
+ };
2029
+
1914
2030
  // src/common/jwt/z-jwe.ts
1915
- var import_zod13 = require("zod");
1916
- var zCompactJwe2 = import_zod13.z.string().regex(
2031
+ var import_zod14 = require("zod");
2032
+ var zCompactJwe2 = import_zod14.z.string().regex(
1917
2033
  /^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/,
1918
2034
  {
1919
2035
  message: "Not a valid compact jwe"
1920
2036
  }
1921
2037
  );
1922
2038
 
2039
+ // src/jar/create-jar-request.ts
2040
+ var import_io_wallet_utils20 = require("@pagopa/io-wallet-utils");
2041
+ async function createJarRequest(options) {
2042
+ const {
2043
+ authorizationRequestHeader,
2044
+ authorizationRequestPayload,
2045
+ callbacks,
2046
+ jweEncryptor,
2047
+ jwtSigner,
2048
+ requestUri
2049
+ } = options;
2050
+ let authorizationRequestJwt;
2051
+ let encryptionJwk;
2052
+ const now = options.now ?? /* @__PURE__ */ new Date();
2053
+ const { jwt, signerJwk } = await callbacks.signJwt(jwtSigner, {
2054
+ header: authorizationRequestHeader,
2055
+ payload: {
2056
+ ...options.additionalJwtPayload,
2057
+ ...authorizationRequestPayload,
2058
+ exp: (0, import_io_wallet_utils20.dateToSeconds)((0, import_io_wallet_utils20.addSecondsToDate)(now, options.expiresInSeconds)),
2059
+ iat: (0, import_io_wallet_utils20.dateToSeconds)(now)
2060
+ }
2061
+ });
2062
+ authorizationRequestJwt = jwt;
2063
+ if (jweEncryptor) {
2064
+ if (!callbacks.encryptJwe) {
2065
+ throw new Oauth2Error(
2066
+ "callbacks.encryptJwe is required when jweEncryptor is provided"
2067
+ );
2068
+ }
2069
+ const encryptionResult = await callbacks.encryptJwe(
2070
+ jweEncryptor,
2071
+ authorizationRequestJwt
2072
+ );
2073
+ authorizationRequestJwt = encryptionResult.jwe;
2074
+ encryptionJwk = encryptionResult.encryptionJwk;
2075
+ }
2076
+ const client_id = authorizationRequestPayload.client_id;
2077
+ const jarAuthorizationRequest = requestUri ? { client_id, request_uri: requestUri } : { client_id, request: authorizationRequestJwt };
2078
+ return {
2079
+ authorizationRequestJwt,
2080
+ encryptionJwk,
2081
+ jarAuthorizationRequest,
2082
+ signerJwk
2083
+ };
2084
+ }
2085
+
1923
2086
  // src/jarm-form-post-jwt.ts
1924
2087
  var getJwtFromFormPost = async (options) => {
1925
2088
  const inputRegex = /<input[^<>]*>/gi;
@@ -1936,6 +2099,7 @@ var getJwtFromFormPost = async (options) => {
1936
2099
  if (responseJwt) {
1937
2100
  const jwt = responseJwt.replace(lineExpressionRegex, "");
1938
2101
  const decodedJwt = decodeJwt({
2102
+ errorMessagePrefix: "Error decoding JARM form post JWT:",
1939
2103
  jwt,
1940
2104
  payloadSchema: options.schema
1941
2105
  });
@@ -1956,73 +2120,73 @@ var getJwtFromFormPost = async (options) => {
1956
2120
  };
1957
2121
 
1958
2122
  // src/mrtd-pop/create-mrtd-validation-jwt.ts
1959
- var import_io_wallet_utils20 = require("@pagopa/io-wallet-utils");
2123
+ var import_io_wallet_utils21 = require("@pagopa/io-wallet-utils");
1960
2124
 
1961
2125
  // src/mrtd-pop/z-mrtd-pop.ts
1962
- var import_zod14 = __toESM(require("zod"));
1963
- var zMrtdChallengeJwtHeader = import_zod14.default.looseObject({
1964
- alg: import_zod14.default.string(),
1965
- kid: import_zod14.default.string(),
1966
- typ: import_zod14.default.literal("mrtd-ias+jwt")
2126
+ var import_zod15 = __toESM(require("zod"));
2127
+ var zMrtdChallengeJwtHeader = import_zod15.default.looseObject({
2128
+ alg: import_zod15.default.string(),
2129
+ kid: import_zod15.default.string(),
2130
+ typ: import_zod15.default.literal("mrtd-ias+jwt")
1967
2131
  });
1968
- var zMrtdChallengeJwtPayload = import_zod14.default.looseObject({
1969
- aud: import_zod14.default.string(),
1970
- exp: import_zod14.default.number(),
1971
- htm: import_zod14.default.literal("POST"),
1972
- htu: import_zod14.default.url(),
1973
- iat: import_zod14.default.number(),
1974
- iss: import_zod14.default.string(),
1975
- mrtd_auth_session: import_zod14.default.string(),
1976
- mrtd_pop_jwt_nonce: import_zod14.default.string(),
1977
- state: import_zod14.default.string(),
1978
- status: import_zod14.default.literal("require_interaction"),
1979
- type: import_zod14.default.literal("mrtd+ias")
2132
+ var zMrtdChallengeJwtPayload = import_zod15.default.looseObject({
2133
+ aud: import_zod15.default.string(),
2134
+ exp: import_zod15.default.number(),
2135
+ htm: import_zod15.default.literal("POST"),
2136
+ htu: import_zod15.default.url(),
2137
+ iat: import_zod15.default.number(),
2138
+ iss: import_zod15.default.string(),
2139
+ mrtd_auth_session: import_zod15.default.string(),
2140
+ mrtd_pop_jwt_nonce: import_zod15.default.string(),
2141
+ state: import_zod15.default.string(),
2142
+ status: import_zod15.default.literal("require_interaction"),
2143
+ type: import_zod15.default.literal("mrtd+ias")
1980
2144
  });
1981
- var zMrtdPopInitResponseJwtHeader = import_zod14.default.looseObject({
1982
- alg: import_zod14.default.string(),
1983
- kid: import_zod14.default.string(),
1984
- typ: import_zod14.default.literal("mrtd-ias-pop+jwt")
2145
+ var zMrtdPopInitResponseJwtHeader = import_zod15.default.looseObject({
2146
+ alg: import_zod15.default.string(),
2147
+ kid: import_zod15.default.string(),
2148
+ typ: import_zod15.default.literal("mrtd-ias-pop+jwt")
1985
2149
  });
1986
- var zMrtdPopInitResponseJwtPayload = import_zod14.default.looseObject({
1987
- aud: import_zod14.default.string(),
1988
- challenge: import_zod14.default.string(),
1989
- exp: import_zod14.default.number(),
1990
- htm: import_zod14.default.literal("POST"),
1991
- htu: import_zod14.default.url(),
1992
- iat: import_zod14.default.number(),
1993
- iss: import_zod14.default.string(),
1994
- mrtd_pop_nonce: import_zod14.default.string(),
1995
- mrz: import_zod14.default.string().optional()
2150
+ var zMrtdPopInitResponseJwtPayload = import_zod15.default.looseObject({
2151
+ aud: import_zod15.default.string(),
2152
+ challenge: import_zod15.default.string(),
2153
+ exp: import_zod15.default.number(),
2154
+ htm: import_zod15.default.literal("POST"),
2155
+ htu: import_zod15.default.url(),
2156
+ iat: import_zod15.default.number(),
2157
+ iss: import_zod15.default.string(),
2158
+ mrtd_pop_nonce: import_zod15.default.string(),
2159
+ mrz: import_zod15.default.string().optional()
1996
2160
  });
1997
- var zMrtdData = import_zod14.default.looseObject({
1998
- dg1: import_zod14.default.string(),
1999
- dg11: import_zod14.default.string(),
2000
- sod_mrtd: import_zod14.default.string()
2161
+ var zMrtdData = import_zod15.default.looseObject({
2162
+ dg1: import_zod15.default.string(),
2163
+ dg11: import_zod15.default.string(),
2164
+ sod_mrtd: import_zod15.default.string()
2001
2165
  });
2002
- var zIasData = import_zod14.default.looseObject({
2003
- challenge_signed: import_zod14.default.string(),
2004
- ias_pk: import_zod14.default.string(),
2005
- sod_ias: import_zod14.default.string()
2166
+ var zIasData = import_zod15.default.looseObject({
2167
+ challenge_signed: import_zod15.default.string(),
2168
+ ias_pk: import_zod15.default.string(),
2169
+ sod_ias: import_zod15.default.string()
2006
2170
  });
2007
- var zMrtdValidationJwtHeader = import_zod14.default.looseObject({
2008
- alg: import_zod14.default.string(),
2009
- kid: import_zod14.default.string(),
2010
- typ: import_zod14.default.literal("mrtd-ias+jwt")
2171
+ var zMrtdValidationJwtHeader = import_zod15.default.looseObject({
2172
+ alg: import_zod15.default.string(),
2173
+ kid: import_zod15.default.string(),
2174
+ typ: import_zod15.default.literal("mrtd-ias+jwt")
2011
2175
  });
2012
- var zMrtdValidationJwtPayload = import_zod14.default.looseObject({
2013
- aud: import_zod14.default.string(),
2014
- document_type: import_zod14.default.literal("cie"),
2015
- exp: import_zod14.default.number(),
2176
+ var zMrtdValidationJwtPayload = import_zod15.default.looseObject({
2177
+ aud: import_zod15.default.string(),
2178
+ document_type: import_zod15.default.literal("cie"),
2179
+ exp: import_zod15.default.number(),
2016
2180
  ias: zIasData,
2017
- iat: import_zod14.default.number(),
2018
- iss: import_zod14.default.string(),
2181
+ iat: import_zod15.default.number(),
2182
+ iss: import_zod15.default.string(),
2019
2183
  mrtd: zMrtdData
2020
2184
  });
2021
- var zMrtdPopVerifyResponse = import_zod14.default.looseObject({
2022
- mrtd_val_pop_nonce: import_zod14.default.string(),
2023
- redirect_uri: import_zod14.default.url(),
2024
- status: import_zod14.default.literal("require_interaction"),
2025
- type: import_zod14.default.literal("redirect_to_web")
2185
+ var zMrtdPopVerifyResponse = import_zod15.default.looseObject({
2186
+ mrtd_val_pop_nonce: import_zod15.default.string(),
2187
+ redirect_uri: import_zod15.default.url(),
2188
+ status: import_zod15.default.literal("require_interaction"),
2189
+ type: import_zod15.default.literal("redirect_to_web")
2026
2190
  });
2027
2191
 
2028
2192
  // src/mrtd-pop/create-mrtd-validation-jwt.ts
@@ -2033,13 +2197,13 @@ async function createMrtdValidationJwt(options) {
2033
2197
  if (!kid) {
2034
2198
  throw new MrtdPopError("Signer must have a publicJwk.kid property");
2035
2199
  }
2036
- const iat = (0, import_io_wallet_utils20.dateToSeconds)(options.issuedAt);
2037
- const header = (0, import_io_wallet_utils20.parseWithErrorHandling)(zMrtdValidationJwtHeader, {
2200
+ const iat = (0, import_io_wallet_utils21.dateToSeconds)(options.issuedAt);
2201
+ const header = (0, import_io_wallet_utils21.parseWithErrorHandling)(zMrtdValidationJwtHeader, {
2038
2202
  alg: options.signer.alg,
2039
2203
  kid,
2040
2204
  typ: "mrtd-ias+jwt"
2041
2205
  });
2042
- const payload = (0, import_io_wallet_utils20.parseWithErrorHandling)(zMrtdValidationJwtPayload, {
2206
+ const payload = (0, import_io_wallet_utils21.parseWithErrorHandling)(zMrtdValidationJwtPayload, {
2043
2207
  aud: options.audience,
2044
2208
  document_type: "cie",
2045
2209
  exp: iat + JWT_EXPIRY_SECONDS2,
@@ -2073,25 +2237,26 @@ async function createMrtdValidationJwt(options) {
2073
2237
 
2074
2238
  // src/mrtd-pop/fetch-mrtd-pop-init.ts
2075
2239
  var import_oauth212 = require("@openid4vc/oauth2");
2076
- var import_io_wallet_utils21 = require("@pagopa/io-wallet-utils");
2240
+ var import_io_wallet_utils22 = require("@pagopa/io-wallet-utils");
2077
2241
  async function fetchMrtdPopInit(options) {
2078
2242
  try {
2079
- const fetch = (0, import_io_wallet_utils21.createFetcher)(options.callbacks.fetch);
2243
+ const fetch = (0, import_io_wallet_utils22.createFetcher)(options.callbacks.fetch);
2080
2244
  const response = await fetch(options.popInitEndpoint, {
2081
2245
  body: JSON.stringify({
2082
2246
  mrtd_auth_session: options.mrtdAuthSession,
2083
2247
  mrtd_pop_jwt_nonce: options.mrtdPopJwtNonce
2084
2248
  }),
2085
2249
  headers: {
2086
- [import_io_wallet_utils21.HEADERS.CONTENT_TYPE]: import_io_wallet_utils21.CONTENT_TYPES.JSON,
2087
- [import_io_wallet_utils21.HEADERS.OAUTH_CLIENT_ATTESTATION]: options.walletAttestation,
2088
- [import_io_wallet_utils21.HEADERS.OAUTH_CLIENT_ATTESTATION_POP]: options.clientAttestationDPoP
2250
+ [import_io_wallet_utils22.HEADERS.CONTENT_TYPE]: import_io_wallet_utils22.CONTENT_TYPES.JSON,
2251
+ [import_io_wallet_utils22.HEADERS.OAUTH_CLIENT_ATTESTATION]: options.walletAttestation,
2252
+ [import_io_wallet_utils22.HEADERS.OAUTH_CLIENT_ATTESTATION_POP]: options.clientAttestationDPoP
2089
2253
  },
2090
2254
  method: "POST"
2091
2255
  });
2092
- await (0, import_io_wallet_utils21.hasStatusOrThrow)(202, import_io_wallet_utils21.UnexpectedStatusCodeError)(response);
2256
+ await (0, import_io_wallet_utils22.hasStatusOrThrow)(202, import_io_wallet_utils22.UnexpectedStatusCodeError)(response);
2093
2257
  const responseJwt = await response.text();
2094
2258
  const jwt = decodeJwt({
2259
+ errorMessagePrefix: "Error decoding MRTD PoP init response JWT:",
2095
2260
  headerSchema: zMrtdPopInitResponseJwtHeader,
2096
2261
  jwt: responseJwt,
2097
2262
  payloadSchema: zMrtdPopInitResponseJwtPayload
@@ -2112,7 +2277,7 @@ async function fetchMrtdPopInit(options) {
2112
2277
  signer
2113
2278
  };
2114
2279
  } catch (error) {
2115
- if (error instanceof import_io_wallet_utils21.UnexpectedStatusCodeError || error instanceof import_io_wallet_utils21.ValidationError) {
2280
+ if (error instanceof import_io_wallet_utils22.UnexpectedStatusCodeError || error instanceof import_io_wallet_utils22.ValidationError) {
2116
2281
  throw error;
2117
2282
  }
2118
2283
  throw new MrtdPopError(
@@ -2122,10 +2287,10 @@ async function fetchMrtdPopInit(options) {
2122
2287
  }
2123
2288
 
2124
2289
  // src/mrtd-pop/fetch-mrtd-pop-verify.ts
2125
- var import_io_wallet_utils22 = require("@pagopa/io-wallet-utils");
2290
+ var import_io_wallet_utils23 = require("@pagopa/io-wallet-utils");
2126
2291
  async function fetchMrtdPopVerify(options) {
2127
2292
  try {
2128
- const fetch = (0, import_io_wallet_utils22.createFetcher)(options.callbacks.fetch);
2293
+ const fetch = (0, import_io_wallet_utils23.createFetcher)(options.callbacks.fetch);
2129
2294
  const response = await fetch(options.popVerifyEndpoint, {
2130
2295
  body: JSON.stringify({
2131
2296
  mrtd_auth_session: options.mrtdAuthSession,
@@ -2133,14 +2298,14 @@ async function fetchMrtdPopVerify(options) {
2133
2298
  mrtd_validation_jwt: options.mrtdValidationJwt
2134
2299
  }),
2135
2300
  headers: {
2136
- [import_io_wallet_utils22.HEADERS.CONTENT_TYPE]: import_io_wallet_utils22.CONTENT_TYPES.JSON,
2137
- [import_io_wallet_utils22.HEADERS.OAUTH_CLIENT_ATTESTATION]: options.walletAttestation,
2138
- [import_io_wallet_utils22.HEADERS.OAUTH_CLIENT_ATTESTATION_POP]: options.clientAttestationDPoP
2301
+ [import_io_wallet_utils23.HEADERS.CONTENT_TYPE]: import_io_wallet_utils23.CONTENT_TYPES.JSON,
2302
+ [import_io_wallet_utils23.HEADERS.OAUTH_CLIENT_ATTESTATION]: options.walletAttestation,
2303
+ [import_io_wallet_utils23.HEADERS.OAUTH_CLIENT_ATTESTATION_POP]: options.clientAttestationDPoP
2139
2304
  },
2140
2305
  method: "POST"
2141
2306
  });
2142
- await (0, import_io_wallet_utils22.hasStatusOrThrow)(202, import_io_wallet_utils22.UnexpectedStatusCodeError)(response);
2143
- const parsed = (0, import_io_wallet_utils22.parseWithErrorHandling)(
2307
+ await (0, import_io_wallet_utils23.hasStatusOrThrow)(202, import_io_wallet_utils23.UnexpectedStatusCodeError)(response);
2308
+ const parsed = (0, import_io_wallet_utils23.parseWithErrorHandling)(
2144
2309
  zMrtdPopVerifyResponse,
2145
2310
  await response.json(),
2146
2311
  "Failed to parse MRTD PoP verify response"
@@ -2150,7 +2315,7 @@ async function fetchMrtdPopVerify(options) {
2150
2315
  redirectUri: parsed.redirect_uri
2151
2316
  };
2152
2317
  } catch (error) {
2153
- if (error instanceof import_io_wallet_utils22.UnexpectedStatusCodeError || error instanceof import_io_wallet_utils22.ValidationError) {
2318
+ if (error instanceof import_io_wallet_utils23.UnexpectedStatusCodeError || error instanceof import_io_wallet_utils23.ValidationError) {
2154
2319
  throw error;
2155
2320
  }
2156
2321
  throw new MrtdPopError(
@@ -2175,6 +2340,7 @@ function parseMrtdChallenge(options) {
2175
2340
  );
2176
2341
  }
2177
2342
  const { header, payload } = decodeJwt({
2343
+ errorMessagePrefix: "Error decoding MRTD challenge JWT:",
2178
2344
  headerSchema: zMrtdChallengeJwtHeader,
2179
2345
  jwt: challengeJwt,
2180
2346
  payloadSchema: zMrtdChallengeJwtPayload
@@ -2187,6 +2353,7 @@ var import_oauth214 = require("@openid4vc/oauth2");
2187
2353
  async function verifyMrtdChallenge(options) {
2188
2354
  const { callbacks, challengeJwt, clientId } = options;
2189
2355
  const jwt = decodeJwt({
2356
+ errorMessagePrefix: "Error decoding MRTD challenge JWT:",
2190
2357
  headerSchema: zMrtdChallengeJwtHeader,
2191
2358
  jwt: challengeJwt,
2192
2359
  payloadSchema: zMrtdChallengeJwtPayload
@@ -2217,14 +2384,13 @@ var import_oauth215 = require("@openid4vc/oauth2");
2217
2384
  CreateTokenResponseError,
2218
2385
  FetchTokenResponseError,
2219
2386
  HashAlgorithm,
2387
+ MAX_JTI_LENGTH,
2220
2388
  MrtdPopError,
2221
2389
  Oauth2Error,
2222
2390
  Oauth2JwtParseError,
2223
2391
  PkceCodeChallengeMethod,
2224
2392
  PushedAuthorizationRequestError,
2225
2393
  SupportedClientAuthenticationMethod,
2226
- V1_0,
2227
- V1_3,
2228
2394
  authorizationCodeGrantIdentifier,
2229
2395
  clientAuthenticationAnonymous,
2230
2396
  clientAuthenticationWalletAttestationJwt,
@@ -2236,6 +2402,9 @@ var import_oauth215 = require("@openid4vc/oauth2");
2236
2402
  createPushedAuthorizationRequest,
2237
2403
  createTokenDPoP,
2238
2404
  createTokenRequest,
2405
+ createWalletAttestationJwtV1_0,
2406
+ createWalletAttestationJwtV1_3,
2407
+ createWalletAttestationJwtV1_4,
2239
2408
  decodeJwt,
2240
2409
  decodeJwtHeader,
2241
2410
  extractClientAttestationJwtsFromHeaders,
@@ -2273,6 +2442,9 @@ var import_oauth215 = require("@openid4vc/oauth2");
2273
2442
  verifyPushedAuthorizationRequest,
2274
2443
  verifyTokenDPoP,
2275
2444
  verifyWalletAttestationJwt,
2445
+ verifyWalletAttestationJwtV1_0,
2446
+ verifyWalletAttestationJwtV1_3,
2447
+ verifyWalletAttestationJwtV1_4,
2276
2448
  zAccessTokenProfileJwtHeader,
2277
2449
  zAccessTokenProfileJwtPayload,
2278
2450
  zAccessTokenRequest,
@@ -2305,6 +2477,15 @@ var import_oauth215 = require("@openid4vc/oauth2");
2305
2477
  zPushedAuthorizationResponse,
2306
2478
  zRefreshTokenGrantIdentifier,
2307
2479
  zSignedAuthorizationRequestJwtHeaderTyp,
2308
- zTrustChain
2480
+ zTrustChain,
2481
+ zWalletAttestationJwtHeaderV1_0,
2482
+ zWalletAttestationJwtHeaderV1_3,
2483
+ zWalletAttestationJwtHeaderV1_4,
2484
+ zWalletAttestationJwtPayloadV1_0,
2485
+ zWalletAttestationJwtPayloadV1_3,
2486
+ zWalletAttestationJwtPayloadV1_4,
2487
+ zWalletAttestationJwtV1_0,
2488
+ zWalletAttestationJwtV1_3,
2489
+ zWalletAttestationJwtV1_4
2309
2490
  });
2310
2491
  //# sourceMappingURL=index.js.map