@openid4vc/openid4vp 0.3.0-alpha-20251107130226 → 0.3.0-alpha-20251110114129

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.cjs CHANGED
@@ -26,57 +26,6 @@ let __openid4vc_utils = require("@openid4vc/utils");
26
26
  let zod = require("zod");
27
27
  zod = __toESM(zod);
28
28
 
29
- //#region src/jar/create-jar-authorization-request.ts
30
- /**
31
- * Creates a JAR (JWT Authorization Request) request object.
32
- *
33
- * @param options - The input parameters
34
- * @param options.authorizationRequestPayload - The authorization request parameters
35
- * @param options.jwtSigner - The JWT signer
36
- * @param options.jweEncryptor - The JWE encryptor (optional) if provided, the request object will be encrypted
37
- * @param options.requestUri - The request URI (optional) if provided, the request object needs to be fetched from the URI
38
- * @param options.callbacks - The callback context
39
- * @returns the requestParams, signerJwk, encryptionJwk, and requestObjectJwt
40
- */
41
- async function createJarAuthorizationRequest(options) {
42
- const { jwtSigner, jweEncryptor, authorizationRequestPayload, requestUri, callbacks } = options;
43
- let authorizationRequestJwt;
44
- let encryptionJwk;
45
- const now = options.now ?? /* @__PURE__ */ new Date();
46
- const { jwt, signerJwk } = await callbacks.signJwt(jwtSigner, {
47
- header: {
48
- ...(0, __openid4vc_oauth2.jwtHeaderFromJwtSigner)(jwtSigner),
49
- typ: "oauth-authz-req+jwt"
50
- },
51
- payload: {
52
- iat: (0, __openid4vc_utils.dateToSeconds)(now),
53
- exp: (0, __openid4vc_utils.dateToSeconds)((0, __openid4vc_utils.addSecondsToDate)(now, options.expiresInSeconds)),
54
- ...options.additionalJwtPayload,
55
- ...authorizationRequestPayload
56
- }
57
- });
58
- authorizationRequestJwt = jwt;
59
- if (jweEncryptor) {
60
- const encryptionResult = await callbacks.encryptJwe(jweEncryptor, authorizationRequestJwt);
61
- authorizationRequestJwt = encryptionResult.jwe;
62
- encryptionJwk = encryptionResult.encryptionJwk;
63
- }
64
- const client_id = authorizationRequestPayload.client_id;
65
- return {
66
- jarAuthorizationRequest: requestUri ? {
67
- client_id,
68
- request_uri: requestUri
69
- } : {
70
- client_id,
71
- request: authorizationRequestJwt
72
- },
73
- signerJwk,
74
- encryptionJwk,
75
- authorizationRequestJwt
76
- };
77
- }
78
-
79
- //#endregion
80
29
  //#region src/authorization-request/validate-authorization-request.ts
81
30
  /**
82
31
  * Validate the OpenId4Vp Authorization Request parameters
@@ -373,7 +322,7 @@ async function createOpenid4vpAuthorizationRequest(options) {
373
322
  ...jar.additionalJwtPayload,
374
323
  aud: jar.requestUri
375
324
  };
376
- const jarResult = await createJarAuthorizationRequest({
325
+ const jarResult = await (0, __openid4vc_oauth2.createJarAuthorizationRequest)({
377
326
  ...jar,
378
327
  authorizationRequestPayload,
379
328
  additionalJwtPayload,
@@ -407,24 +356,7 @@ async function createOpenid4vpAuthorizationRequest(options) {
407
356
 
408
357
  //#endregion
409
358
  //#region src/jar/z-jar-authorization-request.ts
410
- const zJarAuthorizationRequest = zod.z.object({
411
- request: zod.z.optional(zod.z.string()),
412
- request_uri: zod.z.optional(__openid4vc_utils.zHttpsUrl),
413
- request_uri_method: zod.z.optional(zod.z.string()),
414
- client_id: zod.z.optional(zod.z.string())
415
- }).loose();
416
- function validateJarRequestParams(options) {
417
- const { jarRequestParams } = options;
418
- if (jarRequestParams.request && jarRequestParams.request_uri) throw new __openid4vc_oauth2.Oauth2ServerErrorResponseError({
419
- error: "invalid_request_object",
420
- error_description: "request and request_uri cannot both be present in a JAR request"
421
- });
422
- if (!jarRequestParams.request && !jarRequestParams.request_uri) throw new __openid4vc_oauth2.Oauth2ServerErrorResponseError({
423
- error: "invalid_request_object",
424
- error_description: "request or request_uri must be present"
425
- });
426
- return jarRequestParams;
427
- }
359
+ const zOpenid4vpJarAuthorizationRequest = __openid4vc_oauth2.zJarAuthorizationRequest.extend({ request_uri_method: zod.z.optional(zod.z.string()) });
428
360
  function isJarAuthorizationRequest(request) {
429
361
  return "request" in request || "request_uri" in request;
430
362
  }
@@ -445,7 +377,7 @@ function parseOpenid4vpAuthorizationRequest(options) {
445
377
  else params = authorizationRequest;
446
378
  const parsedRequest = (0, __openid4vc_utils.parseWithErrorHandling)(zod.default.union([
447
379
  zOpenid4vpAuthorizationRequest,
448
- zJarAuthorizationRequest,
380
+ zOpenid4vpJarAuthorizationRequest,
449
381
  zOpenid4vpAuthorizationRequestDcApi
450
382
  ]), params);
451
383
  if (isJarAuthorizationRequest(parsedRequest)) return {
@@ -876,17 +808,8 @@ async function fetchJarRequestObject(options) {
876
808
  return await response.text();
877
809
  }
878
810
 
879
- //#endregion
880
- //#region src/jar/jar-request-object/z-jar-request-object.ts
881
- const zJarRequestObjectPayload = zod.z.object({
882
- ...__openid4vc_oauth2.zJwtPayload.shape,
883
- client_id: zod.z.string()
884
- }).loose();
885
-
886
811
  //#endregion
887
812
  //#region src/jar/handle-jar-request/verify-jar-request.ts
888
- const zSignedAuthorizationRequestJwtHeaderTyp = zod.default.literal("oauth-authz-req+jwt");
889
- const signedAuthorizationRequestJwtHeaderTyp = zSignedAuthorizationRequestJwtHeaderTyp.value;
890
813
  /**
891
814
  * Verifies a JAR (JWT Secured Authorization Request) request by validating, decrypting, and verifying signatures.
892
815
  *
@@ -897,7 +820,10 @@ const signedAuthorizationRequestJwtHeaderTyp = zSignedAuthorizationRequestJwtHea
897
820
  */
898
821
  async function verifyJarRequest(options) {
899
822
  const { callbacks, wallet = {} } = options;
900
- const jarRequestParams = validateJarRequestParams(options);
823
+ const jarRequestParams = {
824
+ ...(0, __openid4vc_oauth2.validateJarRequestParams)(options),
825
+ ...options.jarRequestParams
826
+ };
901
827
  const sendBy = jarRequestParams.request ? "value" : "reference";
902
828
  const clientIdPrefix = jarRequestParams.client_id ? zClientIdPrefix.safeParse(jarRequestParams.client_id.split(":")[0]).data : "origin";
903
829
  const method = jarRequestParams.request_uri_method ?? "get";
@@ -956,7 +882,7 @@ async function decryptJarRequest(options) {
956
882
  });
957
883
  const decryptionResult = await callbacks.decryptJwe(jwe);
958
884
  if (!decryptionResult.decrypted) throw new __openid4vc_oauth2.Oauth2ServerErrorResponseError({
959
- error: "invalid_request_object",
885
+ error: __openid4vc_oauth2.Oauth2ErrorCodes.InvalidRequestObject,
960
886
  error_description: "Failed to decrypt jar request object."
961
887
  });
962
888
  return decryptionResult;
@@ -965,7 +891,7 @@ async function verifyJarRequestObject(options) {
965
891
  const { decryptedRequestObject, callbacks } = options;
966
892
  const jwt = (0, __openid4vc_oauth2.decodeJwt)({
967
893
  jwt: decryptedRequestObject,
968
- payloadSchema: zJarRequestObjectPayload
894
+ payloadSchema: __openid4vc_oauth2.zJarRequestObjectPayload
969
895
  });
970
896
  let jwtSigner;
971
897
  const { clientIdPrefix } = getOpenid4vpClientId({
@@ -1014,7 +940,7 @@ async function verifyJarRequestObject(options) {
1014
940
  signer: jwtSigner
1015
941
  });
1016
942
  const version = parseAuthorizationRequestVersion(jwt.payload);
1017
- if (jwt.header.typ !== "oauth-authz-req+jwt" && version >= 24) throw new __openid4vc_oauth2.Oauth2ServerErrorResponseError({
943
+ if (jwt.header.typ !== __openid4vc_oauth2.signedAuthorizationRequestJwtHeaderTyp && version >= 24) throw new __openid4vc_oauth2.Oauth2ServerErrorResponseError({
1018
944
  error: __openid4vc_oauth2.Oauth2ErrorCodes.InvalidRequestObject,
1019
945
  error_description: `Invalid Jar Request Object typ header. Expected "oauth-authz-req+jwt", received "${jwt.header.typ}".`
1020
946
  });
@@ -1059,7 +985,7 @@ async function resolveOpenid4vpAuthorizationRequest(options) {
1059
985
  const parsed = (0, __openid4vc_utils.parseWithErrorHandling)(zod.default.union([
1060
986
  zOpenid4vpAuthorizationRequestDcApi,
1061
987
  zOpenid4vpAuthorizationRequest,
1062
- zJarAuthorizationRequest
988
+ zOpenid4vpJarAuthorizationRequest
1063
989
  ]), options.authorizationRequestPayload, "Invalid authorization request. Could not parse openid4vp authorization request as openid4vp or jar auth request.");
1064
990
  let jar;
1065
991
  if (isJarAuthorizationRequest(parsed)) {