@openid4vc/oauth2 0.3.0-alpha-20251017102623 → 0.3.0-alpha-20251017122507

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
@@ -158,7 +158,7 @@ const zJwk = zod.default.object({
158
158
  d: zod.default.optional(zod.default.string()),
159
159
  r: zod.default.optional(zod.default.string()),
160
160
  t: zod.default.optional(zod.default.string())
161
- }).passthrough())),
161
+ }).loose())),
162
162
  p: zod.default.optional(zod.default.string()),
163
163
  q: zod.default.optional(zod.default.string()),
164
164
  qi: zod.default.optional(zod.default.string()),
@@ -167,8 +167,8 @@ const zJwk = zod.default.object({
167
167
  x5t: zod.default.optional(zod.default.string()),
168
168
  "x5t#S256": zod.default.optional(zod.default.string()),
169
169
  x5u: zod.default.optional(zod.default.string())
170
- }).passthrough();
171
- const zJwkSet = zod.default.object({ keys: zod.default.array(zJwk) }).passthrough();
170
+ }).loose();
171
+ const zJwkSet = zod.default.object({ keys: zod.default.array(zJwk) }).loose();
172
172
 
173
173
  //#endregion
174
174
  //#region src/common/z-common.ts
@@ -180,7 +180,7 @@ const zCompactJwt = zod.default.string().regex(/^([a-zA-Z0-9-_]+)\.([a-zA-Z0-9-_
180
180
  const zJwtConfirmationPayload = zod.default.object({
181
181
  jwk: zJwk.optional(),
182
182
  jkt: zod.default.string().optional()
183
- }).passthrough();
183
+ }).loose();
184
184
  const zJwtPayload = zod.default.object({
185
185
  iss: zod.default.string().optional(),
186
186
  aud: zod.default.string().optional(),
@@ -191,16 +191,16 @@ const zJwtPayload = zod.default.object({
191
191
  jti: zod.default.string().optional(),
192
192
  cnf: zJwtConfirmationPayload.optional(),
193
193
  status: zod.default.record(zod.default.string(), zod.default.any()).optional(),
194
- trust_chain: zod.default.array(zod.default.string()).nonempty().optional()
195
- }).passthrough();
194
+ trust_chain: zod.default.tuple([zod.default.string()], zod.default.string()).optional()
195
+ }).loose();
196
196
  const zJwtHeader = zod.default.object({
197
197
  alg: zAlgValueNotNone,
198
198
  typ: zod.default.string().optional(),
199
199
  kid: zod.default.string().optional(),
200
200
  jwk: zJwk.optional(),
201
201
  x5c: zod.default.array(zod.default.string()).optional(),
202
- trust_chain: zod.default.array(zod.default.string()).nonempty().optional()
203
- }).passthrough();
202
+ trust_chain: zod.default.tuple([zod.default.string()], zod.default.string()).optional()
203
+ }).loose();
204
204
 
205
205
  //#endregion
206
206
  //#region src/common/jwt/decode-jwt-header.ts
@@ -368,60 +368,12 @@ async function verifyJwt(options) {
368
368
  } };
369
369
  }
370
370
 
371
- //#endregion
372
- //#region ../utils/src/zod-error.ts
373
- /**
374
- * Some code comes from `zod-validation-error` package (MIT License) and
375
- * was slightly simplified to fit our needs.
376
- */
377
- const constants = {
378
- identifierRegex: /[$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*/u,
379
- unionSeparator: ", or ",
380
- issueSeparator: "\n - "
381
- };
382
- function escapeQuotes(str) {
383
- return str.replace(/"/g, "\\\"");
384
- }
385
- function joinPath(path) {
386
- if (path.length === 1) return path[0].toString();
387
- return path.reduce((acc, item) => {
388
- if (typeof item === "number") return `${acc}[${item.toString()}]`;
389
- if (item.includes("\"")) return `${acc}["${escapeQuotes(item)}"]`;
390
- if (!constants.identifierRegex.test(item)) return `${acc}["${item}"]`;
391
- return acc + (acc.length === 0 ? "" : ".") + item;
392
- }, "");
393
- }
394
- function getMessageFromZodIssue(issue) {
395
- if (issue.code === zod.ZodIssueCode.invalid_union) return getMessageFromUnionErrors(issue.unionErrors);
396
- if (issue.code === zod.ZodIssueCode.invalid_arguments) return [issue.message, ...issue.argumentsError.issues.map((issue$1) => getMessageFromZodIssue(issue$1))].join(constants.issueSeparator);
397
- if (issue.code === zod.ZodIssueCode.invalid_return_type) return [issue.message, ...issue.returnTypeError.issues.map((issue$1) => getMessageFromZodIssue(issue$1))].join(constants.issueSeparator);
398
- if (issue.path.length !== 0) {
399
- if (issue.path.length === 1) {
400
- const identifier = issue.path[0];
401
- if (typeof identifier === "number") return `${issue.message} at index ${identifier}`;
402
- }
403
- return `${issue.message} at "${joinPath(issue.path)}"`;
404
- }
405
- return issue.message;
406
- }
407
- function getMessageFromUnionErrors(unionErrors) {
408
- return unionErrors.reduce((acc, zodError) => {
409
- const newIssues = zodError.issues.map((issue) => getMessageFromZodIssue(issue)).join(constants.issueSeparator);
410
- if (!acc.includes(newIssues)) acc.push(newIssues);
411
- return acc;
412
- }, []).join(constants.unionSeparator);
413
- }
414
- function formatZodError$3(error) {
415
- if (!error) return "";
416
- return `\t- ${error?.issues.map((issue) => getMessageFromZodIssue(issue)).join(constants.issueSeparator)}`;
417
- }
418
-
419
371
  //#endregion
420
372
  //#region ../utils/src/error/ValidationError.ts
421
373
  var ValidationError$1 = class extends Error {
422
374
  constructor(message, zodError) {
423
375
  super(message);
424
- this.message = `${message}\n${formatZodError$3(zodError)}`;
376
+ this.message = `${message}\n${zodError ? zod.default.prettifyError(zodError) : ""}`;
425
377
  Object.defineProperty(this, "zodError", {
426
378
  value: zodError,
427
379
  writable: false,
@@ -453,7 +405,7 @@ async function fetchJwks(jwksUrl, fetch) {
453
405
  const zAccessTokenProfileJwtHeader = zod.default.object({
454
406
  ...zJwtHeader.shape,
455
407
  typ: zod.default.enum(["application/at+jwt", "at+jwt"])
456
- }).passthrough();
408
+ }).loose();
457
409
  const zAccessTokenProfileJwtPayload = zod.default.object({
458
410
  ...zJwtPayload.shape,
459
411
  iss: zod.default.string(),
@@ -464,7 +416,7 @@ const zAccessTokenProfileJwtPayload = zod.default.object({
464
416
  client_id: zod.default.optional(zod.default.string()),
465
417
  jti: zod.default.string(),
466
418
  scope: zod.default.optional(zod.default.string())
467
- }).passthrough();
419
+ }).loose();
468
420
 
469
421
  //#endregion
470
422
  //#region src/access-token/verify-access-token.ts
@@ -560,10 +512,10 @@ let Oauth2ErrorCodes = /* @__PURE__ */ function(Oauth2ErrorCodes$1) {
560
512
  return Oauth2ErrorCodes$1;
561
513
  }({});
562
514
  const zOauth2ErrorResponse = zod.default.object({
563
- error: zod.default.union([zod.default.nativeEnum(Oauth2ErrorCodes), zod.default.string()]),
515
+ error: zod.default.union([zod.default.enum(Oauth2ErrorCodes), zod.default.string()]),
564
516
  error_description: zod.default.string().optional(),
565
517
  error_uri: zod.default.string().optional()
566
- }).passthrough();
518
+ }).loose();
567
519
 
568
520
  //#endregion
569
521
  //#region src/error/Oauth2ServerErrorResponseError.ts
@@ -584,14 +536,14 @@ const zClientAttestationJwtPayload = zod.default.object({
584
536
  iss: zod.default.string(),
585
537
  sub: zod.default.string(),
586
538
  exp: __openid4vc_utils.zInteger,
587
- cnf: zod.default.object({ jwk: zJwk }).passthrough(),
539
+ cnf: zod.default.object({ jwk: zJwk }).loose(),
588
540
  wallet_name: zod.default.string().optional(),
589
- wallet_link: zod.default.string().url().optional()
590
- }).passthrough();
541
+ wallet_link: zod.default.url().optional()
542
+ }).loose();
591
543
  const zClientAttestationJwtHeader = zod.default.object({
592
544
  ...zJwtHeader.shape,
593
545
  typ: zod.default.literal("oauth-client-attestation+jwt")
594
- }).passthrough();
546
+ }).loose();
595
547
  const zOauthClientAttestationPopHeader = zod.default.literal("OAuth-Client-Attestation-PoP");
596
548
  const oauthClientAttestationPopHeader = zOauthClientAttestationPopHeader.value;
597
549
  const zClientAttestationPopJwtPayload = zod.default.object({
@@ -601,11 +553,11 @@ const zClientAttestationPopJwtPayload = zod.default.object({
601
553
  aud: __openid4vc_utils.zHttpsUrl,
602
554
  jti: zod.default.string(),
603
555
  nonce: zod.default.optional(zod.default.string())
604
- }).passthrough();
556
+ }).loose();
605
557
  const zClientAttestationPopJwtHeader = zod.default.object({
606
558
  ...zJwtHeader.shape,
607
559
  typ: zod.default.literal("oauth-client-attestation-pop+jwt")
608
- }).passthrough();
560
+ }).loose();
609
561
 
610
562
  //#endregion
611
563
  //#region src/client-attestation/client-attestation-pop.ts
@@ -962,7 +914,7 @@ const zAuthorizationServerMetadata = zod.default.object({
962
914
  authorization_challenge_endpoint: zod.default.optional(__openid4vc_utils.zHttpsUrl),
963
915
  "pre-authorized_grant_anonymous_access_supported": zod.default.optional(zod.default.boolean()),
964
916
  client_attestation_pop_nonce_required: zod.default.boolean().optional()
965
- }).passthrough().refine(({ introspection_endpoint_auth_methods_supported: methodsSupported, introspection_endpoint_auth_signing_alg_values_supported: algValuesSupported }) => {
917
+ }).loose().refine(({ introspection_endpoint_auth_methods_supported: methodsSupported, introspection_endpoint_auth_signing_alg_values_supported: algValuesSupported }) => {
966
918
  if (!methodsSupported) return true;
967
919
  if (!methodsSupported.includes("private_key_jwt") && !methodsSupported.includes("client_secret_jwt")) return true;
968
920
  return algValuesSupported !== void 0 && algValuesSupported.length > 0;
@@ -977,26 +929,15 @@ const wellKnownOpenIdConfigurationServerSuffix = ".well-known/openid-configurati
977
929
  * a 404, the openid-configuration metadata will be fetched.
978
930
  */
979
931
  async function fetchAuthorizationServerMetadata(issuer, fetch) {
980
- const openIdConfigurationWellKnownMetadataUrl = (0, __openid4vc_utils.joinUriParts)(issuer, [wellKnownOpenIdConfigurationServerSuffix]);
981
932
  const parsedIssuerUrl = new __openid4vc_utils.URL(issuer);
933
+ const openIdConfigurationWellKnownMetadataUrl = (0, __openid4vc_utils.joinUriParts)(issuer, [wellKnownOpenIdConfigurationServerSuffix]);
982
934
  const authorizationServerWellKnownMetadataUrl = (0, __openid4vc_utils.joinUriParts)(parsedIssuerUrl.origin, [wellKnownAuthorizationServerSuffix, parsedIssuerUrl.pathname]);
983
- const authorizationServerResult = await fetchWellKnownMetadata(authorizationServerWellKnownMetadataUrl, zAuthorizationServerMetadata, fetch);
984
- if (authorizationServerResult) {
985
- if (authorizationServerResult.issuer !== issuer) throw new Oauth2Error(`The 'issuer' parameter '${authorizationServerResult.issuer}' in the well known authorization server metadata at '${authorizationServerWellKnownMetadataUrl}' does not match the provided issuer '${issuer}'.`);
986
- return authorizationServerResult;
987
- }
988
935
  const nonCompliantAuthorizationServerWellKnownMetadataUrl = (0, __openid4vc_utils.joinUriParts)(issuer, [wellKnownAuthorizationServerSuffix]);
989
- const alternativeAuthorizationServerResult = nonCompliantAuthorizationServerWellKnownMetadataUrl !== authorizationServerWellKnownMetadataUrl ? await fetchWellKnownMetadata(nonCompliantAuthorizationServerWellKnownMetadataUrl, zAuthorizationServerMetadata, fetch) : void 0;
990
- if (alternativeAuthorizationServerResult) {
991
- if (alternativeAuthorizationServerResult.issuer !== issuer) throw new Oauth2Error(`The 'issuer' parameter '${alternativeAuthorizationServerResult.issuer}' in the well known authorization server metadata at '${nonCompliantAuthorizationServerWellKnownMetadataUrl}' does not match the provided issuer '${issuer}'.`);
992
- return alternativeAuthorizationServerResult;
993
- }
994
- const openIdConfigurationResult = await fetchWellKnownMetadata(openIdConfigurationWellKnownMetadataUrl, zAuthorizationServerMetadata, fetch);
995
- if (openIdConfigurationResult) {
996
- if (openIdConfigurationResult.issuer !== issuer) throw new Oauth2Error(`The 'issuer' parameter '${openIdConfigurationResult.issuer}' in the well known openid configuration metadata at '${openIdConfigurationWellKnownMetadataUrl}' does not match the provided issuer '${issuer}'.`);
997
- return openIdConfigurationResult;
998
- }
999
- return null;
936
+ let authorizationServerResult = await fetchWellKnownMetadata(authorizationServerWellKnownMetadataUrl, zAuthorizationServerMetadata, fetch);
937
+ if (!authorizationServerResult && nonCompliantAuthorizationServerWellKnownMetadataUrl !== authorizationServerWellKnownMetadataUrl) authorizationServerResult = await fetchWellKnownMetadata(nonCompliantAuthorizationServerWellKnownMetadataUrl, zAuthorizationServerMetadata, fetch);
938
+ if (!authorizationServerResult) authorizationServerResult = await fetchWellKnownMetadata(openIdConfigurationWellKnownMetadataUrl, zAuthorizationServerMetadata, fetch);
939
+ if (authorizationServerResult && authorizationServerResult.issuer !== issuer) throw new Oauth2Error(`The 'issuer' parameter '${authorizationServerResult.issuer}' in the well known authorization server metadata at '${authorizationServerWellKnownMetadataUrl}' does not match the provided issuer '${issuer}'.`);
940
+ return authorizationServerResult;
1000
941
  }
1001
942
  function getAuthorizationServerMetadataFromList(authorizationServersMetadata, issuer) {
1002
943
  const authorizationServerMetadata = authorizationServersMetadata.find((authorizationServerMetadata$1) => authorizationServerMetadata$1.issuer === issuer);
@@ -1044,7 +985,7 @@ async function createAccessTokenJwt(options) {
1044
985
  const zAccessTokenRequest = zod.default.intersection(zod.default.object({
1045
986
  "pre-authorized_code": zod.default.optional(zod.default.string()),
1046
987
  code: zod.default.optional(zod.default.string()),
1047
- redirect_uri: zod.default.string().url().optional(),
988
+ redirect_uri: zod.default.url().optional(),
1048
989
  refresh_token: zod.default.optional(zod.default.string()),
1049
990
  resource: zod.default.optional(__openid4vc_utils.zHttpsUrl),
1050
991
  code_verifier: zod.default.optional(zod.default.string()),
@@ -1054,10 +995,10 @@ const zAccessTokenRequest = zod.default.intersection(zod.default.object({
1054
995
  zRefreshTokenGrantIdentifier,
1055
996
  zod.default.string()
1056
997
  ])
1057
- }).passthrough(), zod.default.object({
998
+ }).loose(), zod.default.object({
1058
999
  tx_code: zod.default.optional(zod.default.string()),
1059
1000
  user_pin: zod.default.optional(zod.default.string())
1060
- }).passthrough().refine(({ tx_code, user_pin }) => !tx_code || !user_pin || user_pin === tx_code, { message: `If both 'tx_code' and 'user_pin' are present they must match` }).transform(({ tx_code, user_pin,...rest }) => {
1001
+ }).loose().refine(({ tx_code, user_pin }) => !tx_code || !user_pin || user_pin === tx_code, { message: `If both 'tx_code' and 'user_pin' are present they must match` }).transform(({ tx_code, user_pin,...rest }) => {
1061
1002
  return {
1062
1003
  ...rest,
1063
1004
  ...tx_code ?? user_pin ? { tx_code: tx_code ?? user_pin } : {}
@@ -1072,8 +1013,8 @@ const zAccessTokenResponse = zod.default.object({
1072
1013
  refresh_token: zod.default.optional(zod.default.string()),
1073
1014
  c_nonce: zod.default.optional(zod.default.string()),
1074
1015
  c_nonce_expires_in: zod.default.optional(zod.default.number().int()),
1075
- authorization_details: zod.default.array(zod.default.object({}).passthrough()).optional()
1076
- }).passthrough();
1016
+ authorization_details: zod.default.array(zod.default.object({}).loose()).optional()
1017
+ }).loose();
1077
1018
  const zAccessTokenErrorResponse = zOauth2ErrorResponse;
1078
1019
 
1079
1020
  //#endregion
@@ -1099,12 +1040,12 @@ const zDpopJwtPayload = zod.default.object({
1099
1040
  htm: __openid4vc_utils.zHttpMethod,
1100
1041
  jti: zod.default.string(),
1101
1042
  ath: zod.default.optional(zod.default.string())
1102
- }).passthrough();
1043
+ }).loose();
1103
1044
  const zDpopJwtHeader = zod.default.object({
1104
1045
  ...zJwtHeader.shape,
1105
1046
  typ: zod.default.literal("dpop+jwt"),
1106
1047
  jwk: zJwk
1107
- }).passthrough();
1048
+ }).loose();
1108
1049
 
1109
1050
  //#endregion
1110
1051
  //#region src/dpop/dpop.ts
@@ -1466,21 +1407,21 @@ const zAuthorizationRequest = zod.default.object({
1466
1407
  response_type: zod.default.string(),
1467
1408
  client_id: zod.default.string(),
1468
1409
  issuer_state: zod.default.optional(zod.default.string()),
1469
- redirect_uri: zod.default.string().url().optional(),
1410
+ redirect_uri: zod.default.url().optional(),
1470
1411
  resource: zod.default.optional(__openid4vc_utils.zHttpsUrl),
1471
1412
  scope: zod.default.optional(zod.default.string()),
1472
- dpop_jkt: zod.default.optional(zod.default.string().base64url()),
1413
+ dpop_jkt: zod.default.optional(zod.default.base64url()),
1473
1414
  code_challenge: zod.default.optional(zod.default.string()),
1474
1415
  code_challenge_method: zod.default.optional(zod.default.string())
1475
- }).passthrough();
1416
+ }).loose();
1476
1417
  const zPushedAuthorizationRequest = zod.default.object({
1477
1418
  request_uri: zod.default.string(),
1478
1419
  client_id: zod.default.string()
1479
- }).passthrough();
1420
+ }).loose();
1480
1421
  const zPushedAuthorizationResponse = zod.default.object({
1481
1422
  request_uri: zod.default.string(),
1482
1423
  expires_in: zod.default.number().int()
1483
- }).passthrough();
1424
+ }).loose();
1484
1425
 
1485
1426
  //#endregion
1486
1427
  //#region src/authorization-challenge/z-authorization-challenge.ts
@@ -1492,15 +1433,15 @@ const zAuthorizationChallengeRequest = zod.default.object({
1492
1433
  client_id: zod.default.optional(zAuthorizationRequest.shape.client_id),
1493
1434
  auth_session: zod.default.optional(zod.default.string()),
1494
1435
  presentation_during_issuance_session: zod.default.optional(zod.default.string())
1495
- }).passthrough();
1496
- const zAuthorizationChallengeResponse = zod.default.object({ authorization_code: zod.default.string() }).passthrough();
1436
+ }).loose();
1437
+ const zAuthorizationChallengeResponse = zod.default.object({ authorization_code: zod.default.string() }).loose();
1497
1438
  const zAuthorizationChallengeErrorResponse = zod.default.object({
1498
1439
  ...zOauth2ErrorResponse.shape,
1499
1440
  auth_session: zod.default.optional(zod.default.string()),
1500
1441
  request_uri: zod.default.optional(zod.default.string()),
1501
1442
  expires_in: zod.default.optional(__openid4vc_utils.zInteger),
1502
1443
  presentation: zod.default.optional(zod.default.string())
1503
- }).passthrough();
1444
+ }).loose();
1504
1445
 
1505
1446
  //#endregion
1506
1447
  //#region src/authorization-challenge/create-authorization-challenge-response.ts
@@ -2396,7 +2337,7 @@ var Oauth2ResourceServer = class {
2396
2337
  const zTokenIntrospectionRequest = zod.default.object({
2397
2338
  token: zod.default.string(),
2398
2339
  token_type_hint: zod.default.optional(zod.default.string())
2399
- }).passthrough();
2340
+ }).loose();
2400
2341
  const zTokenIntrospectionResponse = zod.default.object({
2401
2342
  active: zod.default.boolean(),
2402
2343
  scope: zod.default.optional(zod.default.string()),
@@ -2411,7 +2352,7 @@ const zTokenIntrospectionResponse = zod.default.object({
2411
2352
  iss: zod.default.optional(zod.default.string()),
2412
2353
  jti: zod.default.optional(zod.default.string()),
2413
2354
  cnf: zod.default.optional(zJwtConfirmationPayload)
2414
- }).passthrough();
2355
+ }).loose();
2415
2356
 
2416
2357
  //#endregion
2417
2358
  //#region src/access-token/introspect-token.ts