@pagopa/io-wallet-oid4vp 1.5.7 → 2.0.0-apt

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,13 +1,13 @@
1
1
  // src/authorization-request/create-authorization-request.ts
2
2
  import {
3
3
  createJarRequest,
4
- jwtHeaderFromJwtSigner,
5
4
  signedAuthorizationRequestJwtHeaderTyp
6
5
  } from "@pagopa/io-wallet-oauth2";
7
6
  import {
8
7
  ItWalletSpecsVersion,
9
8
  ValidationError,
10
9
  createVersionDispatcher,
10
+ jwtHeaderFromJwtSigner,
11
11
  objectToQueryParams,
12
12
  parseWithErrorHandling
13
13
  } from "@pagopa/io-wallet-utils";
@@ -129,14 +129,14 @@ function getLeafCertificate(certificateChain) {
129
129
  }
130
130
 
131
131
  // src/authorization-request/z-authorization-request.ts
132
+ import { zSignedAuthorizationRequestJwtHeaderTyp } from "@pagopa/io-wallet-oauth2";
133
+ import { itWalletCredentialVerifierMetadataV1_3 } from "@pagopa/io-wallet-oid-federation";
132
134
  import {
133
135
  zAlgValueNotNone,
134
136
  zCertificateChain,
135
137
  zJwtPayload,
136
- zSignedAuthorizationRequestJwtHeaderTyp,
137
138
  zTrustChain
138
- } from "@pagopa/io-wallet-oauth2";
139
- import { itWalletCredentialVerifierMetadataV1_3 } from "@pagopa/io-wallet-oid-federation";
139
+ } from "@pagopa/io-wallet-utils";
140
140
  import { z } from "zod";
141
141
  var zOpenid4vpCredentialVerifierMetadata = itWalletCredentialVerifierMetadataV1_3.partial({
142
142
  application_type: true,
@@ -183,6 +183,10 @@ var zOpenid4vpAuthorizationRequestHeaderV1_3 = zOpenid4vpAuthorizationRequestHea
183
183
 
184
184
  // src/authorization-request/create-authorization-request.ts
185
185
  var dispatchCreateAuthorizationRequest = createVersionDispatcher({
186
+ [ItWalletSpecsVersion.APTITUDE]: async (o) => createAuthorizationRequestWithHeader(
187
+ o,
188
+ zOpenid4vpAuthorizationRequestHeaderV1_3
189
+ ),
186
190
  [ItWalletSpecsVersion.V1_0]: async (o) => createAuthorizationRequestWithHeader(
187
191
  o,
188
192
  zOpenid4vpAuthorizationRequestHeaderV1_0
@@ -272,8 +276,8 @@ function validateJarSignerForAuthorizationRequest(specsVersion, jwtSigner, paylo
272
276
  }
273
277
 
274
278
  // src/authorization-request/fetch-authorization-request.ts
275
- import { Oauth2JwtParseError } from "@openid4vc/oauth2";
276
279
  import {
280
+ JwtParseError,
277
281
  UnexpectedStatusCodeError,
278
282
  ValidationError as ValidationError2,
279
283
  createFetcher,
@@ -474,7 +478,7 @@ async function fetchAuthorizationRequest(options) {
474
478
  sendBy: parsedQrCode.request ? "value" : "reference"
475
479
  };
476
480
  } catch (error) {
477
- if (error instanceof ValidationError2 || error instanceof Oauth2JwtParseError || error instanceof Oid4vpError || error instanceof UnexpectedStatusCodeError) {
481
+ if (error instanceof ValidationError2 || error instanceof JwtParseError || error instanceof Oid4vpError || error instanceof UnexpectedStatusCodeError) {
478
482
  throw error;
479
483
  }
480
484
  throw new Oid4vpError(
@@ -484,16 +488,14 @@ async function fetchAuthorizationRequest(options) {
484
488
  }
485
489
 
486
490
  // src/authorization-request/parse-authorization-request.ts
487
- import {
488
- Oauth2JwtParseError as Oauth2JwtParseError2,
489
- verifyJwt
490
- } from "@openid4vc/oauth2";
491
- import { decodeJwt } from "@pagopa/io-wallet-oauth2";
492
491
  import {
493
492
  ItWalletSpecsVersion as ItWalletSpecsVersion2,
494
493
  ItWalletSpecsVersionError,
494
+ JwtParseError as JwtParseError2,
495
495
  ValidationError as ValidationError3,
496
- dispatchByVersion
496
+ decodeJwt,
497
+ dispatchByVersion,
498
+ verifyJwt
497
499
  } from "@pagopa/io-wallet-utils";
498
500
  function getPublicKeyForVerification(options) {
499
501
  const { header, payload } = options;
@@ -532,6 +534,7 @@ function getPublicKeyForVerification(options) {
532
534
  async function parseAuthorizeRequest(options) {
533
535
  try {
534
536
  const headerSchema = dispatchByVersion(options.config.itWalletSpecsVersion, {
537
+ [ItWalletSpecsVersion2.APTITUDE]: () => zOpenid4vpAuthorizationRequestHeaderV1_3,
535
538
  [ItWalletSpecsVersion2.V1_0]: () => zOpenid4vpAuthorizationRequestHeaderV1_0,
536
539
  [ItWalletSpecsVersion2.V1_3]: () => zOpenid4vpAuthorizationRequestHeaderV1_3,
537
540
  [ItWalletSpecsVersion2.V1_4]: () => zOpenid4vpAuthorizationRequestHeaderV1_3
@@ -587,7 +590,7 @@ async function parseAuthorizeRequest(options) {
587
590
  }
588
591
  };
589
592
  } catch (error) {
590
- if (error instanceof ItWalletSpecsVersionError || error instanceof ValidationError3 || error instanceof Oauth2JwtParseError2 || error instanceof Oid4vpError)
593
+ if (error instanceof ItWalletSpecsVersionError || error instanceof ValidationError3 || error instanceof JwtParseError2 || error instanceof Oid4vpError)
591
594
  throw error;
592
595
  throw new ParseAuthorizeRequestError(
593
596
  `Unexpected error during Request Object parsing: ${error instanceof Error ? error.message : String(error)}`
@@ -602,7 +605,9 @@ import {
602
605
  } from "@pagopa/io-wallet-utils";
603
606
 
604
607
  // src/authorization-response/build-jarm-response.ts
605
- import { encodeToBase64Url as encodeToBase64Url2 } from "@pagopa/io-wallet-utils";
608
+ import {
609
+ encodeToBase64Url as encodeToBase64Url2
610
+ } from "@pagopa/io-wallet-utils";
606
611
 
607
612
  // src/jarm/jarm-extract-jwks.ts
608
613
  function extractEncryptionJwkFromJwks(jwks, {
@@ -739,6 +744,9 @@ async function createAuthorizationResponse2(options) {
739
744
 
740
745
  // src/authorization-response/create-authorization-response.ts
741
746
  var dispatchCreateAuthorizationResponse = createVersionDispatcher2({
747
+ [ItWalletSpecsVersion3.APTITUDE]: (o) => createAuthorizationResponse2(
748
+ o
749
+ ),
742
750
  [ItWalletSpecsVersion3.V1_0]: (o) => (
743
751
  // V1_0 shares the v1.3 response logic — JWKS / enc resolution is identical.
744
752
  createAuthorizationResponse(
@@ -756,15 +764,235 @@ async function createAuthorizationResponse3(options) {
756
764
  return dispatchCreateAuthorizationResponse(options);
757
765
  }
758
766
 
767
+ // src/authorization-response/create-openid4vp-authorization-response.ts
768
+ import { Oauth2Error } from "@pagopa/io-wallet-oauth2";
769
+ import {
770
+ ContentType,
771
+ UnexpectedStatusCodeError as UnexpectedStatusCodeError2,
772
+ addSecondsToDate,
773
+ dateToSeconds,
774
+ encodeToBase64Url as encodeToBase64Url3,
775
+ hasStatusOrThrow as hasStatusOrThrow2,
776
+ jwtHeaderFromJwtSigner as jwtHeaderFromJwtSigner2,
777
+ parseWithErrorHandling as parseWithErrorHandling2,
778
+ zJwkSet
779
+ } from "@pagopa/io-wallet-utils";
780
+ var jarmResponseModes = /* @__PURE__ */ new Set([
781
+ "jwt",
782
+ "query.jwt",
783
+ "fragment.jwt",
784
+ "form_post.jwt",
785
+ "direct_post.jwt",
786
+ "dc_api.jwt"
787
+ ]);
788
+ function assertValueSupported(options) {
789
+ const { actual, errorMessage, supported } = options;
790
+ const found = supported.find((value) => value === actual);
791
+ if (!found) {
792
+ throw new Oauth2Error(errorMessage);
793
+ }
794
+ return found;
795
+ }
796
+ function assertClientJarmMetadataSupported(clientMetadata, serverMetadata) {
797
+ const {
798
+ authorization_encrypted_response_alg: encryptedAlg,
799
+ authorization_encrypted_response_enc: encryptedEnc,
800
+ authorization_signed_response_alg: signedAlg
801
+ } = clientMetadata;
802
+ if (encryptedAlg) {
803
+ assertValueSupported({
804
+ actual: encryptedAlg,
805
+ errorMessage: `Invalid authorization_encrypted_response_alg ${encryptedAlg}`,
806
+ supported: serverMetadata.authorization_encryption_alg_values_supported
807
+ });
808
+ }
809
+ if (encryptedEnc) {
810
+ assertValueSupported({
811
+ actual: encryptedEnc,
812
+ errorMessage: `Invalid authorization_encrypted_response_enc ${encryptedEnc}`,
813
+ supported: serverMetadata.authorization_encryption_enc_values_supported
814
+ });
815
+ }
816
+ if (signedAlg && serverMetadata.authorization_signed_response_alg_values_supported) {
817
+ assertValueSupported({
818
+ actual: signedAlg,
819
+ errorMessage: `Invalid authorization_signed_response_alg ${signedAlg}`,
820
+ supported: serverMetadata.authorization_signed_response_alg_values_supported
821
+ });
822
+ }
823
+ }
824
+ async function fetchJwks(jwksUrl, fetchCallback) {
825
+ if (!fetchCallback) {
826
+ throw new Oauth2Error(
827
+ `Missing fetch callback required to resolve jwks_uri '${jwksUrl}'.`
828
+ );
829
+ }
830
+ const response = await fetchCallback(jwksUrl, {
831
+ headers: {
832
+ Accept: `${ContentType.JwkSet}, ${ContentType.Json};q=0.9`
833
+ }
834
+ });
835
+ await hasStatusOrThrow2(200, UnexpectedStatusCodeError2)(response);
836
+ return parseWithErrorHandling2(
837
+ zJwkSet,
838
+ await response.json(),
839
+ `Validation of JWKs from jwks_uri '${jwksUrl}' failed`
840
+ );
841
+ }
842
+ async function createJarmAuthorizationResponse(options) {
843
+ const { callbacks, jarmAuthorizationResponse, jweEncryptor, jwtSigner } = options;
844
+ if (!jwtSigner && jweEncryptor) {
845
+ const { encryptionJwk: encryptionJwk2, jwe: jwe2 } = await callbacks.encryptJwe(
846
+ jweEncryptor,
847
+ JSON.stringify(jarmAuthorizationResponse)
848
+ );
849
+ return {
850
+ encryptionJwk: encryptionJwk2,
851
+ jarmAuthorizationResponseJwt: jwe2
852
+ };
853
+ }
854
+ if (jwtSigner && !jweEncryptor) {
855
+ const { jwt } = await callbacks.signJwt(jwtSigner, {
856
+ header: jwtHeaderFromJwtSigner2(jwtSigner),
857
+ payload: jarmAuthorizationResponse
858
+ });
859
+ return {
860
+ jarmAuthorizationResponseJwt: jwt
861
+ };
862
+ }
863
+ if (!jwtSigner || !jweEncryptor) {
864
+ throw new Oauth2Error(
865
+ "JWT signer and/or encryptor are required to create a JARM auth response."
866
+ );
867
+ }
868
+ const signed = await callbacks.signJwt(jwtSigner, {
869
+ header: jwtHeaderFromJwtSigner2(jwtSigner),
870
+ payload: jarmAuthorizationResponse
871
+ });
872
+ const { encryptionJwk, jwe } = await callbacks.encryptJwe(
873
+ jweEncryptor,
874
+ signed.jwt
875
+ );
876
+ return {
877
+ encryptionJwk,
878
+ jarmAuthorizationResponseJwt: jwe
879
+ };
880
+ }
881
+ async function createOpenid4vpAuthorizationResponse(options) {
882
+ const { authorizationRequestPayload, jarm } = options;
883
+ const authorizationResponsePayload = {
884
+ ...options.authorizationResponsePayload,
885
+ state: authorizationRequestPayload.state
886
+ };
887
+ const { prefix: clientIdPrefix } = extractClientIdPrefix(
888
+ authorizationRequestPayload.client_id
889
+ );
890
+ if (authorizationRequestPayload.response_mode && jarmResponseModes.has(authorizationRequestPayload.response_mode) && !jarm) {
891
+ throw new Oauth2Error(
892
+ `Missing jarm options for creating Jarm response with response mode '${authorizationRequestPayload.response_mode}'`
893
+ );
894
+ }
895
+ if (!jarm) {
896
+ return { authorizationResponsePayload };
897
+ }
898
+ if ((clientIdPrefix === "openid_federation" /* OPENID_FEDERATION */ || clientIdPrefix === "none" /* NONE */) && !options.clientMetadata) {
899
+ throw new Oauth2Error(
900
+ "When OpenID Federation is used as the client id prefix (https/openid_federation), passing externally fetched and verified 'clientMetadata' to 'createOpenid4vpAuthorizationResponse' is required."
901
+ );
902
+ }
903
+ const clientMetadata = options.clientMetadata ?? authorizationRequestPayload.client_metadata;
904
+ if (!clientMetadata) {
905
+ throw new Oauth2Error(
906
+ "Missing client metadata in the request params to assert Jarm metadata support."
907
+ );
908
+ }
909
+ const jwks = clientMetadata.jwks ? clientMetadata.jwks : clientMetadata.jwks_uri ? await fetchJwks(clientMetadata.jwks_uri, options.callbacks.fetch) : void 0;
910
+ if (!jwks) {
911
+ throw new Oauth2Error(
912
+ "Missing 'jwks' or 'jwks_uri' in client metadata. Cannot extract encryption JWK."
913
+ );
914
+ }
915
+ assertClientJarmMetadataSupported(clientMetadata, jarm.serverMetadata);
916
+ const encryptionJwk = jarm.encryption?.jwk ?? extractEncryptionJwkFromJwks(jwks, {
917
+ supportedAlgValues: jarm.serverMetadata.authorization_encryption_alg_values_supported ?? (clientMetadata.authorization_encrypted_response_alg ? [clientMetadata.authorization_encrypted_response_alg] : void 0)
918
+ });
919
+ if (!encryptionJwk) {
920
+ throw new Oauth2Error(
921
+ "No encryption JWK provided and could not extract encryption JWK from client metadata. Failed to create JARM response."
922
+ );
923
+ }
924
+ const enc = clientMetadata.encrypted_response_enc_values_supported ? jarm.serverMetadata.authorization_encryption_enc_values_supported.find(
925
+ (value) => clientMetadata.encrypted_response_enc_values_supported?.includes(
926
+ value
927
+ )
928
+ ) ?? clientMetadata.encrypted_response_enc_values_supported[0] ?? "A128GCM" : clientMetadata.authorization_encrypted_response_enc ?? "A128GCM";
929
+ assertValueSupported({
930
+ actual: enc,
931
+ errorMessage: `Invalid 'enc' value ${enc}. Supported values are ${jarm.serverMetadata.authorization_encryption_enc_values_supported.join(", ")}`,
932
+ supported: jarm.serverMetadata.authorization_encryption_enc_values_supported
933
+ });
934
+ const alg = encryptionJwk.alg ?? clientMetadata.authorization_encrypted_response_alg ?? "ECDH-ES";
935
+ assertValueSupported({
936
+ actual: alg,
937
+ errorMessage: `Invalid 'alg' value ${alg}. Supported values are ${jarm.serverMetadata.authorization_encryption_alg_values_supported.join(", ")}`,
938
+ supported: jarm.serverMetadata.authorization_encryption_alg_values_supported
939
+ });
940
+ if (clientMetadata.authorization_signed_response_alg && jarm.jwtSigner && clientMetadata.authorization_signed_response_alg !== jarm.jwtSigner.alg) {
941
+ throw new Oauth2Error(
942
+ `Invalid signed response alg value ${jarm.jwtSigner.alg}. Expected ${clientMetadata.authorization_signed_response_alg}.`
943
+ );
944
+ }
945
+ const additionalJwtPayload = jarm.jwtSigner ? {
946
+ aud: jarm.audience ?? (() => {
947
+ throw new Oauth2Error(
948
+ "Missing required aud in JARM configuration for creating OpenID4VP authorization response."
949
+ );
950
+ })(),
951
+ exp: jarm.expiresInSeconds ? dateToSeconds(addSecondsToDate(/* @__PURE__ */ new Date(), jarm.expiresInSeconds)) : dateToSeconds(addSecondsToDate(/* @__PURE__ */ new Date(), 600)),
952
+ iss: jarm.authorizationServer ?? (() => {
953
+ throw new Oauth2Error(
954
+ "Missing required iss in JARM configuration for creating OpenID4VP authorization response."
955
+ );
956
+ })()
957
+ } : void 0;
958
+ const jarmResponsePayload = {
959
+ ...authorizationResponsePayload,
960
+ ...additionalJwtPayload
961
+ };
962
+ const { encryptionJwk: usedEncryptionJwk, jarmAuthorizationResponseJwt } = await createJarmAuthorizationResponse({
963
+ callbacks: {
964
+ encryptJwe: options.callbacks.encryptJwe,
965
+ signJwt: options.callbacks.signJwt
966
+ },
967
+ jarmAuthorizationResponse: jarmResponsePayload,
968
+ jweEncryptor: jarm.encryption ? {
969
+ alg,
970
+ apu: jarm.encryption.nonce ? encodeToBase64Url3(jarm.encryption.nonce) : void 0,
971
+ apv: encodeToBase64Url3(authorizationRequestPayload.nonce),
972
+ enc,
973
+ method: "jwk",
974
+ publicJwk: encryptionJwk
975
+ } : void 0,
976
+ jwtSigner: jarm.jwtSigner
977
+ });
978
+ return {
979
+ authorizationResponsePayload: jarmResponsePayload,
980
+ jarm: {
981
+ encryptionJwk: usedEncryptionJwk,
982
+ responseJwt: jarmAuthorizationResponseJwt
983
+ }
984
+ };
985
+ }
986
+
759
987
  // src/authorization-response/fetch-authorization-response.ts
760
988
  import {
761
989
  CONTENT_TYPES,
762
990
  HEADERS,
763
- UnexpectedStatusCodeError as UnexpectedStatusCodeError2,
991
+ UnexpectedStatusCodeError as UnexpectedStatusCodeError3,
764
992
  ValidationError as ValidationError4,
765
993
  createFetcher as createFetcher2,
766
- hasStatusOrThrow as hasStatusOrThrow2,
767
- parseWithErrorHandling as parseWithErrorHandling2
994
+ hasStatusOrThrow as hasStatusOrThrow3,
995
+ parseWithErrorHandling as parseWithErrorHandling3
768
996
  } from "@pagopa/io-wallet-utils";
769
997
 
770
998
  // src/authorization-response/z-authorization-response.ts
@@ -814,12 +1042,12 @@ async function fetchAuthorizationResponse(options) {
814
1042
  method: "POST"
815
1043
  }
816
1044
  );
817
- await hasStatusOrThrow2(
1045
+ await hasStatusOrThrow3(
818
1046
  200,
819
- UnexpectedStatusCodeError2
1047
+ UnexpectedStatusCodeError3
820
1048
  )(authorizationResponseResult);
821
1049
  const authorizationResponseResultJson = await authorizationResponseResult.json();
822
- const parsedAuthorizationResponseResult = parseWithErrorHandling2(
1050
+ const parsedAuthorizationResponseResult = parseWithErrorHandling3(
823
1051
  zOpenid4vpAuthorizationResponseResult,
824
1052
  authorizationResponseResultJson
825
1053
  );
@@ -837,7 +1065,7 @@ async function fetchAuthorizationResponse(options) {
837
1065
  }
838
1066
  return parsedAuthorizationResponseResult;
839
1067
  } catch (error) {
840
- if (error instanceof UnexpectedStatusCodeError2 || error instanceof ValidationError4 || error instanceof FetchAuthorizationResponseError) {
1068
+ if (error instanceof UnexpectedStatusCodeError3 || error instanceof ValidationError4 || error instanceof FetchAuthorizationResponseError) {
841
1069
  throw error;
842
1070
  }
843
1071
  throw new FetchAuthorizationResponseError(
@@ -847,21 +1075,23 @@ async function fetchAuthorizationResponse(options) {
847
1075
  }
848
1076
 
849
1077
  // src/authorization-response/parse-authorization-response.ts
850
- import { parseWithErrorHandling as parseWithErrorHandling5 } from "@pagopa/io-wallet-utils";
1078
+ import {
1079
+ parseWithErrorHandling as parseWithErrorHandling6
1080
+ } from "@pagopa/io-wallet-utils";
851
1081
 
852
1082
  // src/jarm/parse-jarm-authorization-response.ts
853
1083
  import {
854
1084
  decodeJwtHeader as decodeJwtHeader2,
1085
+ parseWithErrorHandling as parseWithErrorHandling5,
855
1086
  zCompactJwe as zCompactJwe2,
856
1087
  zCompactJwt as zCompactJwt2
857
- } from "@pagopa/io-wallet-oauth2";
858
- import { parseWithErrorHandling as parseWithErrorHandling4 } from "@pagopa/io-wallet-utils";
1088
+ } from "@pagopa/io-wallet-utils";
859
1089
  import z7 from "zod";
860
1090
 
861
1091
  // src/vp-token/parse-vp-token.ts
862
- import { parseIfJson, parseWithErrorHandling as parseWithErrorHandling3 } from "@pagopa/io-wallet-utils";
1092
+ import { parseIfJson, parseWithErrorHandling as parseWithErrorHandling4 } from "@pagopa/io-wallet-utils";
863
1093
  function parseVpToken(vpToken) {
864
- return parseWithErrorHandling3(
1094
+ return parseWithErrorHandling4(
865
1095
  zVpToken,
866
1096
  parseIfJson(vpToken),
867
1097
  "Could not parse dcql vp_token. Expected an object where the values are encoded presentations"
@@ -882,20 +1112,20 @@ function validateOpenid4vpAuthorizationResponsePayload(options) {
882
1112
  }
883
1113
 
884
1114
  // src/jarm/verify-jarm-authorization-response.ts
885
- import { jwtSignerFromJwt } from "@openid4vc/oauth2";
1115
+ import { Oauth2Error as Oauth2Error2 } from "@pagopa/io-wallet-oauth2";
886
1116
  import {
887
- Oauth2Error,
888
1117
  decodeJwt as decodeJwt2,
889
1118
  decodeJwtHeader,
1119
+ jwtSignerFromJwt,
1120
+ stringToJsonWithErrorHandling,
890
1121
  zCompactJwe,
891
1122
  zCompactJwt,
892
1123
  zJwtHeader as zJwtHeader2
893
- } from "@pagopa/io-wallet-oauth2";
894
- import { stringToJsonWithErrorHandling } from "@pagopa/io-wallet-utils";
1124
+ } from "@pagopa/io-wallet-utils";
895
1125
  import z6 from "zod";
896
1126
 
897
1127
  // src/jarm/z-jarm.ts
898
- import { zJwtHeader, zJwtPayload as zJwtPayload2 } from "@pagopa/io-wallet-oauth2";
1128
+ import { zJwtHeader, zJwtPayload as zJwtPayload2 } from "@pagopa/io-wallet-utils";
899
1129
  import { z as z5 } from "zod";
900
1130
  var zJarmHeader = z5.object({
901
1131
  ...zJwtHeader.shape,
@@ -951,7 +1181,7 @@ var decryptJarmAuthorizationResponseJwt = async (options) => {
951
1181
  jwk: encryptionJwk
952
1182
  });
953
1183
  if (!result.decrypted) {
954
- throw new Oauth2Error("Failed to decrypt jarm auth response.");
1184
+ throw new Oauth2Error2("Failed to decrypt jarm auth response.");
955
1185
  }
956
1186
  return {
957
1187
  decryptionJwk: result.decryptionJwk,
@@ -976,7 +1206,7 @@ async function verifyJarmAuthorizationResponse(options) {
976
1206
  decryptedRequestData.payload
977
1207
  ).success;
978
1208
  if (!requestDataIsEncrypted && !responseIsSigned) {
979
- throw new Oauth2Error(
1209
+ throw new Oauth2Error2(
980
1210
  "Jarm Auth Response must be either encrypted, signed, or signed and encrypted."
981
1211
  );
982
1212
  }
@@ -998,27 +1228,27 @@ async function verifyJarmAuthorizationResponse(options) {
998
1228
  payload: jwsPayload
999
1229
  });
1000
1230
  if (!verificationResult.verified) {
1001
- throw new Oauth2Error("Jarm Auth Response is not valid.");
1231
+ throw new Oauth2Error2("Jarm Auth Response is not valid.");
1002
1232
  }
1003
1233
  const expectedAudience = authorizationRequestPayload.client_id;
1004
1234
  const expectedIssuer = authorizationRequestPayload.iss;
1005
1235
  if (response.aud !== expectedAudience) {
1006
- throw new Oauth2Error(
1236
+ throw new Oauth2Error2(
1007
1237
  `Jarm Auth Response contains 'aud' value '${response.aud}', but expected '${expectedAudience}'.`
1008
1238
  );
1009
1239
  }
1010
1240
  if (expectedIssuer && response.iss !== expectedIssuer) {
1011
- throw new Oauth2Error(
1241
+ throw new Oauth2Error2(
1012
1242
  `Jarm Auth Response contains 'iss' value '${response.iss}', but expected '${expectedIssuer}'.`
1013
1243
  );
1014
1244
  }
1015
1245
  const now = options.now ?? /* @__PURE__ */ new Date();
1016
1246
  const nowSeconds = Math.floor(now.getTime() / 1e3);
1017
1247
  if (response.exp < nowSeconds) {
1018
- throw new Oauth2Error("Jarm Auth Response has expired.");
1248
+ throw new Oauth2Error2("Jarm Auth Response has expired.");
1019
1249
  }
1020
1250
  if (response.nbf !== void 0 && response.nbf > nowSeconds) {
1021
- throw new Oauth2Error("Jarm Auth Response is not active yet.");
1251
+ throw new Oauth2Error2("Jarm Auth Response is not active yet.");
1022
1252
  }
1023
1253
  jarmAuthorizationResponse = response;
1024
1254
  } else {
@@ -1041,7 +1271,7 @@ async function verifyJarmAuthorizationResponse(options) {
1041
1271
  // src/jarm/parse-jarm-authorization-response.ts
1042
1272
  async function parseJarmAuthorizationResponse(options) {
1043
1273
  const { authorizationRequestPayload, callbacks, jarmResponseJwt, now } = options;
1044
- const jarmAuthorizationResponseJwt = parseWithErrorHandling4(
1274
+ const jarmAuthorizationResponseJwt = parseWithErrorHandling5(
1045
1275
  z7.union([zCompactJwt2, zCompactJwe2]),
1046
1276
  jarmResponseJwt,
1047
1277
  "Invalid jarm authorization response jwt."
@@ -1056,7 +1286,7 @@ async function parseJarmAuthorizationResponse(options) {
1056
1286
  headerSchema: zJarmHeader,
1057
1287
  jwt: jarmAuthorizationResponseJwt
1058
1288
  });
1059
- const authorizationResponsePayload = parseWithErrorHandling4(
1289
+ const authorizationResponsePayload = parseWithErrorHandling5(
1060
1290
  zOpenid4vpAuthorizationResponse,
1061
1291
  verifiedJarmResponse.jarmAuthorizationResponse,
1062
1292
  "Failed to parse openid4vp authorization response."
@@ -1088,7 +1318,7 @@ async function parseAuthorizationResponse(options) {
1088
1318
  jarmResponseJwt: authorizationResponse.response
1089
1319
  });
1090
1320
  }
1091
- const authorizationResponsePayload = parseWithErrorHandling5(
1321
+ const authorizationResponsePayload = parseWithErrorHandling6(
1092
1322
  zOpenid4vpAuthorizationResponse,
1093
1323
  authorizationResponse,
1094
1324
  "Failed to parse openid4vp authorization response."
@@ -1103,11 +1333,6 @@ async function parseAuthorizationResponse(options) {
1103
1333
  expectedNonce: authorizationRequestPayload.nonce
1104
1334
  };
1105
1335
  }
1106
-
1107
- // src/index.ts
1108
- import {
1109
- createOpenid4vpAuthorizationResponse
1110
- } from "@openid4vc/openid4vp";
1111
1336
  export {
1112
1337
  ClientIdPrefix,
1113
1338
  CreateAuthorizationResponseError,