@openid4vc/oauth2 0.3.0-alpha-20251021082313 → 0.3.0-alpha-20251029091020

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.d.mts CHANGED
@@ -1427,6 +1427,7 @@ declare const zAuthorizationChallengeRequest: z$1.ZodObject<{
1427
1427
  scope: z$1.ZodOptional<z$1.ZodString>;
1428
1428
  redirect_uri: z$1.ZodOptional<z$1.ZodURL>;
1429
1429
  resource: z$1.ZodOptional<z$1.ZodString>;
1430
+ state: z$1.ZodOptional<z$1.ZodString>;
1430
1431
  issuer_state: z$1.ZodOptional<z$1.ZodString>;
1431
1432
  dpop_jkt: z$1.ZodOptional<z$1.ZodBase64URL>;
1432
1433
  code_challenge: z$1.ZodOptional<z$1.ZodString>;
@@ -1565,6 +1566,10 @@ interface CreateAuthorizationRequestUrlOptions {
1565
1566
  * Scope to request for the authorization request
1566
1567
  */
1567
1568
  scope?: string;
1569
+ /**
1570
+ * State for the authorization request
1571
+ */
1572
+ state?: string;
1568
1573
  /**
1569
1574
  * The resource to which access is being requested. This can help the authorization
1570
1575
  * server in determining the resource server to handle the authorization request for
@@ -1629,6 +1634,7 @@ declare const zAuthorizationRequest: z$1.ZodObject<{
1629
1634
  redirect_uri: z$1.ZodOptional<z$1.ZodURL>;
1630
1635
  resource: z$1.ZodOptional<z$1.ZodString>;
1631
1636
  scope: z$1.ZodOptional<z$1.ZodString>;
1637
+ state: z$1.ZodOptional<z$1.ZodString>;
1632
1638
  dpop_jkt: z$1.ZodOptional<z$1.ZodBase64URL>;
1633
1639
  code_challenge: z$1.ZodOptional<z$1.ZodString>;
1634
1640
  code_challenge_method: z$1.ZodOptional<z$1.ZodString>;
@@ -2304,7 +2310,7 @@ declare class Oauth2AuthorizationServer {
2304
2310
  [x: string]: unknown;
2305
2311
  iat: number;
2306
2312
  htu: string;
2307
- htm: "POST" | "GET" | "PUT" | "DELETE" | "HEAD" | "OPTIONS" | "TRACE" | "CONNECT" | "PATCH";
2313
+ htm: "GET" | "POST" | "PUT" | "DELETE" | "HEAD" | "OPTIONS" | "TRACE" | "CONNECT" | "PATCH";
2308
2314
  jti: string;
2309
2315
  ath?: string | undefined;
2310
2316
  iss?: string | undefined;
@@ -2608,7 +2614,7 @@ interface SendAuthorizationChallengeRequestOptions {
2608
2614
  */
2609
2615
  resource?: string;
2610
2616
  /**
2611
- * Presentation during issuance sessios if credentials were presented
2617
+ * Presentation during issuance session if credentials were presented
2612
2618
  * as part of an issuance session
2613
2619
  */
2614
2620
  presentationDuringIssuanceSession?: string;
package/dist/index.d.ts CHANGED
@@ -1427,6 +1427,7 @@ declare const zAuthorizationChallengeRequest: z$1.ZodObject<{
1427
1427
  scope: z$1.ZodOptional<z$1.ZodString>;
1428
1428
  redirect_uri: z$1.ZodOptional<z$1.ZodURL>;
1429
1429
  resource: z$1.ZodOptional<z$1.ZodString>;
1430
+ state: z$1.ZodOptional<z$1.ZodString>;
1430
1431
  issuer_state: z$1.ZodOptional<z$1.ZodString>;
1431
1432
  dpop_jkt: z$1.ZodOptional<z$1.ZodBase64URL>;
1432
1433
  code_challenge: z$1.ZodOptional<z$1.ZodString>;
@@ -1565,6 +1566,10 @@ interface CreateAuthorizationRequestUrlOptions {
1565
1566
  * Scope to request for the authorization request
1566
1567
  */
1567
1568
  scope?: string;
1569
+ /**
1570
+ * State for the authorization request
1571
+ */
1572
+ state?: string;
1568
1573
  /**
1569
1574
  * The resource to which access is being requested. This can help the authorization
1570
1575
  * server in determining the resource server to handle the authorization request for
@@ -1629,6 +1634,7 @@ declare const zAuthorizationRequest: z$1.ZodObject<{
1629
1634
  redirect_uri: z$1.ZodOptional<z$1.ZodURL>;
1630
1635
  resource: z$1.ZodOptional<z$1.ZodString>;
1631
1636
  scope: z$1.ZodOptional<z$1.ZodString>;
1637
+ state: z$1.ZodOptional<z$1.ZodString>;
1632
1638
  dpop_jkt: z$1.ZodOptional<z$1.ZodBase64URL>;
1633
1639
  code_challenge: z$1.ZodOptional<z$1.ZodString>;
1634
1640
  code_challenge_method: z$1.ZodOptional<z$1.ZodString>;
@@ -2304,7 +2310,7 @@ declare class Oauth2AuthorizationServer {
2304
2310
  [x: string]: unknown;
2305
2311
  iat: number;
2306
2312
  htu: string;
2307
- htm: "POST" | "GET" | "PUT" | "DELETE" | "HEAD" | "OPTIONS" | "TRACE" | "CONNECT" | "PATCH";
2313
+ htm: "GET" | "POST" | "PUT" | "DELETE" | "HEAD" | "OPTIONS" | "TRACE" | "CONNECT" | "PATCH";
2308
2314
  jti: string;
2309
2315
  ath?: string | undefined;
2310
2316
  iss?: string | undefined;
@@ -2608,7 +2614,7 @@ interface SendAuthorizationChallengeRequestOptions {
2608
2614
  */
2609
2615
  resource?: string;
2610
2616
  /**
2611
- * Presentation during issuance sessios if credentials were presented
2617
+ * Presentation during issuance session if credentials were presented
2612
2618
  * as part of an issuance session
2613
2619
  */
2614
2620
  presentationDuringIssuanceSession?: string;
package/dist/index.js CHANGED
@@ -43,7 +43,7 @@ let HashAlgorithm = /* @__PURE__ */ function(HashAlgorithm$1) {
43
43
  //#region src/error/Oauth2Error.ts
44
44
  var Oauth2Error = class extends Error {
45
45
  constructor(message, options) {
46
- const errorMessage = message ?? "Unknown error occured.";
46
+ const errorMessage = message ?? "Unknown error occurred.";
47
47
  const causeMessage = options?.cause instanceof Error ? ` ${options.cause.message}` : options?.cause ? ` ${options?.cause}` : "";
48
48
  super(`${errorMessage}${causeMessage}`);
49
49
  this.cause = options?.cause;
@@ -288,7 +288,7 @@ function jwtSignerFromJwt({ header, payload, allowedSignerMethods }) {
288
288
  if (header.kid?.startsWith("did:") || payload.iss?.startsWith("did:")) if (payload.iss && header.kid?.startsWith("did:") && !header.kid.startsWith(payload.iss)) found.push({
289
289
  method: "did",
290
290
  valid: false,
291
- error: `kid in header starst with did that is different from did value in 'iss'`
291
+ error: `kid in header starts with did that is different from did value in 'iss'`
292
292
  });
293
293
  else if (!header.kid?.startsWith("did:") && !header.kid?.startsWith("#")) found.push({
294
294
  method: "did",
@@ -1411,6 +1411,7 @@ const zAuthorizationRequest = zod.default.object({
1411
1411
  redirect_uri: zod.default.url().optional(),
1412
1412
  resource: zod.default.optional(__openid4vc_utils.zHttpsUrl),
1413
1413
  scope: zod.default.optional(zod.default.string()),
1414
+ state: zod.default.optional(zod.default.string()),
1414
1415
  dpop_jkt: zod.default.optional(zod.default.base64url()),
1415
1416
  code_challenge: zod.default.optional(zod.default.string()),
1416
1417
  code_challenge_method: zod.default.optional(zod.default.string())
@@ -1449,7 +1450,7 @@ const zAuthorizationChallengeErrorResponse = zod.default.object({
1449
1450
  /**
1450
1451
  * Create an authorization challenge response
1451
1452
  *
1452
- * @throws {ValidationError} if an error occured during verification of the {@link AuthorizationChallengeResponse}
1453
+ * @throws {ValidationError} if an error occurred during verification of the {@link AuthorizationChallengeResponse}
1453
1454
  */
1454
1455
  function createAuthorizationChallengeResponse(options) {
1455
1456
  return { authorizationChallengeResponse: (0, __openid4vc_utils.parseWithErrorHandling)(zAuthorizationChallengeResponse, {
@@ -1460,7 +1461,7 @@ function createAuthorizationChallengeResponse(options) {
1460
1461
  /**
1461
1462
  * Create an authorization challenge error response
1462
1463
  *
1463
- * @throws {ValidationError} if an error occured during validation of the {@link AuthorizationChallengeErrorResponse}
1464
+ * @throws {ValidationError} if an error occurred during validation of the {@link AuthorizationChallengeErrorResponse}
1464
1465
  */
1465
1466
  function createAuthorizationChallengeErrorResponse(options) {
1466
1467
  return (0, __openid4vc_utils.parseWithErrorHandling)(zAuthorizationChallengeErrorResponse, {
@@ -1616,7 +1617,7 @@ async function verifyAuthorizationChallengeRequest(options) {
1616
1617
  /**
1617
1618
  * Create an pushed authorization response
1618
1619
  *
1619
- * @throws {ValidationError} if an error occured during verification of the {@link PushedAuthorizationResponse}
1620
+ * @throws {ValidationError} if an error occurred during verification of the {@link PushedAuthorizationResponse}
1620
1621
  */
1621
1622
  function createPushedAuthorizationResponse(options) {
1622
1623
  return { pushedAuthorizationResponse: (0, __openid4vc_utils.parseWithErrorHandling)(zPushedAuthorizationResponse, {
@@ -1628,7 +1629,7 @@ function createPushedAuthorizationResponse(options) {
1628
1629
  /**
1629
1630
  * Create a pushed authorization error response
1630
1631
  *
1631
- * @throws {ValidationError} if an error occured during validation of the {@link PushedAuthorizationErrorResponse}
1632
+ * @throws {ValidationError} if an error occurred during validation of the {@link PushedAuthorizationErrorResponse}
1632
1633
  */
1633
1634
  function createPushedAuthorizationErrorResponse(options) {
1634
1635
  return (0, __openid4vc_utils.parseWithErrorHandling)(zAccessTokenErrorResponse, {
@@ -1649,7 +1650,7 @@ function parsePushedAuthorizationRequest(options) {
1649
1650
  const parsedAuthorizationRequest = zAuthorizationRequest.safeParse(options.authorizationRequest);
1650
1651
  if (!parsedAuthorizationRequest.success) throw new Oauth2ServerErrorResponseError({
1651
1652
  error: Oauth2ErrorCodes.InvalidRequest,
1652
- error_description: `Error occured during validation of pushed authorization request.\n${(0, __openid4vc_utils.formatZodError)(parsedAuthorizationRequest.error)}`
1653
+ error_description: `Error occurred during validation of pushed authorization request.\n${(0, __openid4vc_utils.formatZodError)(parsedAuthorizationRequest.error)}`
1653
1654
  });
1654
1655
  const authorizationRequest = parsedAuthorizationRequest.data;
1655
1656
  const { clientAttestation, dpop } = parseAuthorizationRequest({
@@ -1960,13 +1961,13 @@ async function retrieveAccessToken(options) {
1960
1961
  *
1961
1962
  * @throws {Oauth2ClientAuthorizationChallengeError} if the request failed and a {@link AuthorizationChallengeErrorResponse} is returned
1962
1963
  * @throws {InvalidFetchResponseError} if the request failed but no error response could be parsed
1963
- * @throws {ValidationError} if a successful response was received but an error occured during verification of the {@link AuthorizationChallengeResponse}
1964
+ * @throws {ValidationError} if a successful response was received but an error occurred during verification of the {@link AuthorizationChallengeResponse}
1964
1965
  */
1965
1966
  async function sendAuthorizationChallengeRequest(options) {
1966
1967
  const fetchWithZod = (0, __openid4vc_utils.createZodFetcher)(options.callbacks.fetch);
1967
1968
  const authorizationServerMetadata = options.authorizationServerMetadata;
1968
1969
  const authorizationChallengeEndpoint = authorizationServerMetadata.authorization_challenge_endpoint;
1969
- if (!authorizationChallengeEndpoint) throw new Oauth2Error(`Unable to send authorization challange. Authorization server '${authorizationServerMetadata.issuer}' has no 'authorization_challenge_endpoint'`);
1970
+ if (!authorizationChallengeEndpoint) throw new Oauth2Error(`Unable to send authorization challenge. Authorization server '${authorizationServerMetadata.issuer}' has no 'authorization_challenge_endpoint'`);
1970
1971
  const pkce = authorizationServerMetadata.code_challenge_methods_supported && !options.authSession ? await createPkce({
1971
1972
  allowedCodeChallengeMethods: authorizationServerMetadata.code_challenge_methods_supported,
1972
1973
  callbacks: options.callbacks,
@@ -2053,6 +2054,7 @@ async function createAuthorizationRequestUrl(options) {
2053
2054
  redirect_uri: options.redirectUri,
2054
2055
  resource: options.resource,
2055
2056
  scope: options.scope,
2057
+ state: options.state,
2056
2058
  code_challenge: pkce?.codeChallenge,
2057
2059
  code_challenge_method: pkce?.codeChallengeMethod
2058
2060
  };
@@ -2102,7 +2104,7 @@ async function createAuthorizationRequestUrl(options) {
2102
2104
  }
2103
2105
  async function pushAuthorizationRequest(options) {
2104
2106
  const fetchWithZod = (0, __openid4vc_utils.createZodFetcher)(options.callbacks.fetch);
2105
- if (options.authorizationRequest.request_uri) throw new Oauth2Error(`Authorization request contains 'request_uri' parameter. This is not allowed for pushed authorization reuqests.`);
2107
+ if (options.authorizationRequest.request_uri) throw new Oauth2Error(`Authorization request contains 'request_uri' parameter. This is not allowed for pushed authorization requests.`);
2106
2108
  const headers = new __openid4vc_utils.Headers({
2107
2109
  ...options.headers,
2108
2110
  "Content-Type": __openid4vc_utils.ContentType.XWwwFormUrlencoded
@@ -2456,7 +2458,7 @@ async function verifyResourceRequest(options) {
2456
2458
  })).header.jwk;
2457
2459
  } catch (error) {
2458
2460
  const errorMessage = error instanceof Oauth2Error ? error.message : "Error verifying DPoP jwt";
2459
- throw new Oauth2ResourceUnauthorizedError(`Error occured during verification of jwt profile access token: ${error instanceof Error ? error.message : error}`, {
2461
+ throw new Oauth2ResourceUnauthorizedError(`Error occurred during verification of jwt profile access token: ${error instanceof Error ? error.message : error}`, {
2460
2462
  scheme,
2461
2463
  error: Oauth2ErrorCodes.InvalidDpopProof,
2462
2464
  error_description: errorMessage