@pagopa/io-wallet-oid4vp 0.5.0 → 0.6.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.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { CallbackContext, RequestDpopOptions, JwtSigner } from '@openid4vc/oauth2';
2
- import { z } from 'zod';
2
+ import z$1, { z } from 'zod';
3
3
  import * as _openid4vc_openid4vp from '@openid4vc/openid4vp';
4
4
  import { VpToken } from '@openid4vc/openid4vp';
5
5
  export { CreateOpenid4vpAuthorizationResponseOptions, CreateOpenid4vpAuthorizationResponseResult, VpToken, createOpenid4vpAuthorizationResponse } from '@openid4vc/openid4vp';
@@ -1148,6 +1148,45 @@ interface CreateAuthorizationResponseOptions {
1148
1148
  */
1149
1149
  declare function createAuthorizationResponse(options: CreateAuthorizationResponseOptions): Promise<_openid4vc_openid4vp.CreateOpenid4vpAuthorizationResponseResult>;
1150
1150
 
1151
+ declare const zOid4vpAuthorizationResponseResult: z$1.ZodObject<{
1152
+ redirect_uri: z$1.ZodString;
1153
+ }, "strip", z$1.ZodTypeAny, {
1154
+ redirect_uri: string;
1155
+ }, {
1156
+ redirect_uri: string;
1157
+ }>;
1158
+ type Oid4vpAuthorizationResponseResult = z$1.infer<typeof zOid4vpAuthorizationResponseResult>;
1159
+
1160
+ /**
1161
+ * Configuration options for fetching OID4VP Presentation Result
1162
+ */
1163
+ interface FetchAuthorizationResponseOptions {
1164
+ /**
1165
+ * The signed and encrypted {@link Openid4vpAuthorizationResponse} in base64 format
1166
+ */
1167
+ authorizationResponseJarm: string;
1168
+ /**
1169
+ * Callback functions for making HTTP requests
1170
+ * Allows for custom fetch implementations
1171
+ */
1172
+ callbacks: Pick<CallbackContext, "fetch">;
1173
+ /**
1174
+ * The response_uri field contained in the {@link AuthorizationRequestObject}
1175
+ */
1176
+ presentationResponseUri: string;
1177
+ }
1178
+ /**
1179
+ * Sends the {@link Openid4vpAuthorizationResponse} to the response uri provided by the session's
1180
+ * {@link AuthorizationRequestObject} and returns the {@link Oid4vpAuthorizationResponseResult} object
1181
+ * containing the redirect_uri at which to continue the presentation
1182
+ *
1183
+ * @param options {@link FetchAuthorizationResponseOptions}
1184
+ * @returns Promise that resolves to the parsed {@link Oid4vpAuthorizationResponseResult}
1185
+ * @throws {UnexpectedStatusCodeError} When the server returns a non-200 status code
1186
+ * @throws {ValidationError} When the response cannot be parsed or is invalid
1187
+ */
1188
+ declare function fetchAuthorizationResponse(options: FetchAuthorizationResponseOptions): Promise<Oid4vpAuthorizationResponseResult>;
1189
+
1151
1190
  /**
1152
1191
  * Generic error thrown during Oid4vp operations
1153
1192
  */
@@ -1164,6 +1203,13 @@ declare class ParseAuthorizeRequestError extends Oid4vpError {
1164
1203
  readonly statusCode?: number | undefined;
1165
1204
  constructor(message: string, statusCode?: number | undefined);
1166
1205
  }
1206
+ /**
1207
+ * Error thrown by {@link fetchAuthorizationResponse}
1208
+ */
1209
+ declare class FetchAuthorizationResponseError extends Oid4vpError {
1210
+ readonly statusCode?: number | undefined;
1211
+ constructor(message: string, statusCode?: number | undefined);
1212
+ }
1167
1213
  /**
1168
1214
  * Error thrown by {@link createAuthorizationResponse} in case there
1169
1215
  * are unexpected errors.
@@ -1173,4 +1219,4 @@ declare class CreateAuthorizationResponseError extends Oid4vpError {
1173
1219
  constructor(message: string, statusCode?: number | undefined);
1174
1220
  }
1175
1221
 
1176
- export { type AuthorizationRequestObject, CreateAuthorizationResponseError, type CreateAuthorizationResponseOptions, Oid4vpError, ParseAuthorizeRequestError, type ParseAuthorizeRequestOptions, createAuthorizationResponse, parseAuthorizeRequest, zOpenid4vpAuthorizationRequest };
1222
+ export { type AuthorizationRequestObject, CreateAuthorizationResponseError, type CreateAuthorizationResponseOptions, FetchAuthorizationResponseError, type FetchAuthorizationResponseOptions, type Oid4vpAuthorizationResponseResult, Oid4vpError, ParseAuthorizeRequestError, type ParseAuthorizeRequestOptions, createAuthorizationResponse, fetchAuthorizationResponse, parseAuthorizeRequest, zOid4vpAuthorizationResponseResult, zOpenid4vpAuthorizationRequest };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { CallbackContext, RequestDpopOptions, JwtSigner } from '@openid4vc/oauth2';
2
- import { z } from 'zod';
2
+ import z$1, { z } from 'zod';
3
3
  import * as _openid4vc_openid4vp from '@openid4vc/openid4vp';
4
4
  import { VpToken } from '@openid4vc/openid4vp';
5
5
  export { CreateOpenid4vpAuthorizationResponseOptions, CreateOpenid4vpAuthorizationResponseResult, VpToken, createOpenid4vpAuthorizationResponse } from '@openid4vc/openid4vp';
@@ -1148,6 +1148,45 @@ interface CreateAuthorizationResponseOptions {
1148
1148
  */
1149
1149
  declare function createAuthorizationResponse(options: CreateAuthorizationResponseOptions): Promise<_openid4vc_openid4vp.CreateOpenid4vpAuthorizationResponseResult>;
1150
1150
 
1151
+ declare const zOid4vpAuthorizationResponseResult: z$1.ZodObject<{
1152
+ redirect_uri: z$1.ZodString;
1153
+ }, "strip", z$1.ZodTypeAny, {
1154
+ redirect_uri: string;
1155
+ }, {
1156
+ redirect_uri: string;
1157
+ }>;
1158
+ type Oid4vpAuthorizationResponseResult = z$1.infer<typeof zOid4vpAuthorizationResponseResult>;
1159
+
1160
+ /**
1161
+ * Configuration options for fetching OID4VP Presentation Result
1162
+ */
1163
+ interface FetchAuthorizationResponseOptions {
1164
+ /**
1165
+ * The signed and encrypted {@link Openid4vpAuthorizationResponse} in base64 format
1166
+ */
1167
+ authorizationResponseJarm: string;
1168
+ /**
1169
+ * Callback functions for making HTTP requests
1170
+ * Allows for custom fetch implementations
1171
+ */
1172
+ callbacks: Pick<CallbackContext, "fetch">;
1173
+ /**
1174
+ * The response_uri field contained in the {@link AuthorizationRequestObject}
1175
+ */
1176
+ presentationResponseUri: string;
1177
+ }
1178
+ /**
1179
+ * Sends the {@link Openid4vpAuthorizationResponse} to the response uri provided by the session's
1180
+ * {@link AuthorizationRequestObject} and returns the {@link Oid4vpAuthorizationResponseResult} object
1181
+ * containing the redirect_uri at which to continue the presentation
1182
+ *
1183
+ * @param options {@link FetchAuthorizationResponseOptions}
1184
+ * @returns Promise that resolves to the parsed {@link Oid4vpAuthorizationResponseResult}
1185
+ * @throws {UnexpectedStatusCodeError} When the server returns a non-200 status code
1186
+ * @throws {ValidationError} When the response cannot be parsed or is invalid
1187
+ */
1188
+ declare function fetchAuthorizationResponse(options: FetchAuthorizationResponseOptions): Promise<Oid4vpAuthorizationResponseResult>;
1189
+
1151
1190
  /**
1152
1191
  * Generic error thrown during Oid4vp operations
1153
1192
  */
@@ -1164,6 +1203,13 @@ declare class ParseAuthorizeRequestError extends Oid4vpError {
1164
1203
  readonly statusCode?: number | undefined;
1165
1204
  constructor(message: string, statusCode?: number | undefined);
1166
1205
  }
1206
+ /**
1207
+ * Error thrown by {@link fetchAuthorizationResponse}
1208
+ */
1209
+ declare class FetchAuthorizationResponseError extends Oid4vpError {
1210
+ readonly statusCode?: number | undefined;
1211
+ constructor(message: string, statusCode?: number | undefined);
1212
+ }
1167
1213
  /**
1168
1214
  * Error thrown by {@link createAuthorizationResponse} in case there
1169
1215
  * are unexpected errors.
@@ -1173,4 +1219,4 @@ declare class CreateAuthorizationResponseError extends Oid4vpError {
1173
1219
  constructor(message: string, statusCode?: number | undefined);
1174
1220
  }
1175
1221
 
1176
- export { type AuthorizationRequestObject, CreateAuthorizationResponseError, type CreateAuthorizationResponseOptions, Oid4vpError, ParseAuthorizeRequestError, type ParseAuthorizeRequestOptions, createAuthorizationResponse, parseAuthorizeRequest, zOpenid4vpAuthorizationRequest };
1222
+ export { type AuthorizationRequestObject, CreateAuthorizationResponseError, type CreateAuthorizationResponseOptions, FetchAuthorizationResponseError, type FetchAuthorizationResponseOptions, type Oid4vpAuthorizationResponseResult, Oid4vpError, ParseAuthorizeRequestError, type ParseAuthorizeRequestOptions, createAuthorizationResponse, fetchAuthorizationResponse, parseAuthorizeRequest, zOid4vpAuthorizationResponseResult, zOpenid4vpAuthorizationRequest };
package/dist/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,17 +17,28 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/index.ts
21
31
  var index_exports = {};
22
32
  __export(index_exports, {
23
33
  CreateAuthorizationResponseError: () => CreateAuthorizationResponseError,
34
+ FetchAuthorizationResponseError: () => FetchAuthorizationResponseError,
24
35
  Oid4vpError: () => Oid4vpError,
25
36
  ParseAuthorizeRequestError: () => ParseAuthorizeRequestError,
26
37
  createAuthorizationResponse: () => createAuthorizationResponse,
27
38
  createOpenid4vpAuthorizationResponse: () => import_openid4vp2.createOpenid4vpAuthorizationResponse,
39
+ fetchAuthorizationResponse: () => fetchAuthorizationResponse,
28
40
  parseAuthorizeRequest: () => parseAuthorizeRequest,
41
+ zOid4vpAuthorizationResponseResult: () => zOid4vpAuthorizationResponseResult,
29
42
  zOpenid4vpAuthorizationRequest: () => zOpenid4vpAuthorizationRequest
30
43
  });
31
44
  module.exports = __toCommonJS(index_exports);
@@ -49,6 +62,13 @@ var ParseAuthorizeRequestError = class extends Oid4vpError {
49
62
  this.name = "ParseAuthorizeRequestError";
50
63
  }
51
64
  };
65
+ var FetchAuthorizationResponseError = class extends Oid4vpError {
66
+ constructor(message, statusCode) {
67
+ super(message);
68
+ this.statusCode = statusCode;
69
+ this.name = "FetchAuthorizationResponseError";
70
+ }
71
+ };
52
72
  var CreateAuthorizationResponseError = class extends Oid4vpError {
53
73
  constructor(message, statusCode) {
54
74
  super(message);
@@ -148,16 +168,64 @@ async function createAuthorizationResponse(options) {
148
168
  }
149
169
  }
150
170
 
171
+ // src/authorization-response/fetch-authorization-response.ts
172
+ var import_utils3 = require("@openid4vc/utils");
173
+ var import_io_wallet_utils = require("@pagopa/io-wallet-utils");
174
+
175
+ // src/authorization-response/z-authorization-response.ts
176
+ var import_zod2 = __toESM(require("zod"));
177
+ var zOid4vpAuthorizationResponseResult = import_zod2.default.object({
178
+ redirect_uri: import_zod2.default.string()
179
+ });
180
+
181
+ // src/authorization-response/fetch-authorization-response.ts
182
+ async function fetchAuthorizationResponse(options) {
183
+ try {
184
+ const fetch = (0, import_utils3.createFetcher)(options.callbacks.fetch);
185
+ const authorizationResponseResult = await fetch(
186
+ options.presentationResponseUri,
187
+ {
188
+ body: new URLSearchParams({
189
+ response: options.authorizationResponseJarm
190
+ }),
191
+ headers: {
192
+ [import_io_wallet_utils.HEADERS.CONTENT_TYPE]: import_io_wallet_utils.CONTENT_TYPES.FORM_URLENCODED
193
+ },
194
+ method: "POST"
195
+ }
196
+ );
197
+ await (0, import_io_wallet_utils.hasStatusOrThrow)(
198
+ 200,
199
+ import_io_wallet_utils.UnexpectedStatusCodeError
200
+ )(authorizationResponseResult);
201
+ const authorizationResponseResultJson = await authorizationResponseResult.json();
202
+ return (0, import_utils3.parseWithErrorHandling)(
203
+ zOid4vpAuthorizationResponseResult,
204
+ authorizationResponseResultJson
205
+ );
206
+ } catch (error) {
207
+ if (error instanceof import_io_wallet_utils.UnexpectedStatusCodeError || error instanceof import_utils3.ValidationError) {
208
+ throw error;
209
+ }
210
+ throw new FetchAuthorizationResponseError(
211
+ `Unexpected error sending authorization response: ${error instanceof Error ? error.message : String(error)}`
212
+ );
213
+ }
214
+ }
215
+
151
216
  // src/index.ts
152
217
  var import_openid4vp2 = require("@openid4vc/openid4vp");
153
218
  // Annotate the CommonJS export names for ESM import in node:
154
219
  0 && (module.exports = {
155
220
  CreateAuthorizationResponseError,
221
+ FetchAuthorizationResponseError,
156
222
  Oid4vpError,
157
223
  ParseAuthorizeRequestError,
158
224
  createAuthorizationResponse,
159
225
  createOpenid4vpAuthorizationResponse,
226
+ fetchAuthorizationResponse,
160
227
  parseAuthorizeRequest,
228
+ zOid4vpAuthorizationResponseResult,
161
229
  zOpenid4vpAuthorizationRequest
162
230
  });
163
231
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/authorization-request/parse-authorization-request.ts","../src/errors.ts","../src/authorization-request/z-request-object.ts","../src/authorization-response/create-authorization-response.ts"],"sourcesContent":["export * from \"./authorization-request\";\nexport * from \"./authorization-response\";\nexport * from \"./errors\";\n\nexport {\n type CreateOpenid4vpAuthorizationResponseOptions,\n type CreateOpenid4vpAuthorizationResponseResult,\n type VpToken,\n createOpenid4vpAuthorizationResponse,\n} from \"@openid4vc/openid4vp\";\n","import {\n CallbackContext,\n Oauth2JwtParseError,\n RequestDpopOptions,\n decodeJwt,\n} from \"@openid4vc/oauth2\";\nimport { ValidationError } from \"@openid4vc/utils\";\n\nimport { ParseAuthorizeRequestError } from \"../errors\";\nimport {\n AuthorizationRequestObject,\n zOpenid4vpAuthorizationRequest,\n} from \"./z-request-object\";\n\nexport interface ParseAuthorizeRequestOptions {\n /**\n * Callback context for signature verification.\n */\n callbacks: Pick<CallbackContext, \"verifyJwt\">;\n\n /**\n * DPoP options\n */\n dpop: RequestDpopOptions;\n\n /**\n * The Authorization Request Object JWT.\n */\n requestObjectJwt: string;\n}\n\n/**\n * This method verifies a JWT containing a Request Object and returns its\n * decoded value for further processing\n * @param options {@link ParseAuthorizeRequestOptions}\n * @returns An {@link AuthorizationRequestObject} containing the RP required\n * credentials\n * @throws {@link ValidationError} in case there are errors validating the Request Object structure\n * @throws {@link Oauth2JwtParseError} in case the request object jwt is malformed (e.g missing header, bad encoding)\n * @throws {@link ParseAuthorizeRequestError} in case the JWT signature is invalid or there are unexpected errors\n */\nexport async function parseAuthorizeRequest(\n options: ParseAuthorizeRequestOptions,\n): Promise<AuthorizationRequestObject> {\n try {\n const decoded = decodeJwt({\n jwt: options.requestObjectJwt,\n payloadSchema: zOpenid4vpAuthorizationRequest,\n });\n const verificationResult = await options.callbacks.verifyJwt(\n options.dpop.signer,\n {\n compact: options.requestObjectJwt,\n header: decoded.header,\n payload: decoded.payload,\n },\n );\n\n if (!verificationResult.verified)\n throw new ParseAuthorizeRequestError(\n \"Error verifying Request Object signature\",\n );\n\n return decoded.payload;\n } catch (error) {\n if (\n error instanceof ValidationError ||\n error instanceof Oauth2JwtParseError\n )\n throw error;\n throw new ParseAuthorizeRequestError(\n `Unexpected error during Request Object parsing: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n}\n","/**\n * Generic error thrown during Oid4vp operations\n */\nexport class Oid4vpError extends Error {\n constructor(\n message: string,\n public readonly statusCode?: number,\n ) {\n super(message);\n this.name = \"Oid4vpError\";\n }\n}\n\n/**\n * Error thrown by {@link parseAuthorizeRequest} when the passed\n * request object has an invalid signature or unexpected errors\n * are thrown\n */\nexport class ParseAuthorizeRequestError extends Oid4vpError {\n constructor(\n message: string,\n public readonly statusCode?: number,\n ) {\n super(message);\n this.name = \"ParseAuthorizeRequestError\";\n }\n}\n\n/**\n * Error thrown by {@link createAuthorizationResponse} in case there\n * are unexpected errors.\n */\nexport class CreateAuthorizationResponseError extends Oid4vpError {\n constructor(\n message: string,\n public readonly statusCode?: number,\n ) {\n super(message);\n this.name = \"CreateAuthorizationResponseError\";\n }\n}\n","import { zJwtPayload } from \"@openid4vc/oauth2\";\nimport { z } from \"zod\";\n\n/**\n * Zod parser that describes a JWT payload\n * containing an OID4VP Request Object\n */\nexport const zOpenid4vpAuthorizationRequest = z\n .object({\n client_id: z.string(),\n dcql_query: z.record(z.string(), z.any()).optional(),\n nonce: z.string(),\n request_uri: z.string().url().optional(),\n request_uri_method: z.optional(z.string()),\n response_mode: z.literal(\"direct_post.jwt\"),\n response_type: z.literal(\"vp_token\"),\n response_uri: z.string().url().optional(),\n scope: z.string().optional(),\n state: z.string(),\n wallet_nonce: z.string().optional(),\n })\n .passthrough()\n .and(zJwtPayload);\n\nexport type AuthorizationRequestObject = z.infer<\n typeof zOpenid4vpAuthorizationRequest\n>;\n","import { CallbackContext, JwtSigner } from \"@openid4vc/oauth2\";\nimport {\n CreateOpenid4vpAuthorizationResponseOptions,\n VpToken,\n createOpenid4vpAuthorizationResponse,\n} from \"@openid4vc/openid4vp\";\nimport { addSecondsToDate, dateToSeconds } from \"@openid4vc/utils\";\nimport { ItWalletCredentialVerifierMetadata } from \"@pagopa/io-wallet-oid-federation\";\n\nimport { AuthorizationRequestObject } from \"../authorization-request\";\nimport { CreateAuthorizationResponseError } from \"../errors\";\n\ntype JarmServerMetadata = NonNullable<\n CreateOpenid4vpAuthorizationResponseOptions[\"jarm\"]\n>[\"serverMetadata\"];\n\nexport interface CreateAuthorizationResponseOptions {\n /**\n * Callbacks for authorization response generation\n */\n callbacks: Pick<\n CallbackContext,\n \"encryptJwe\" | \"fetch\" | \"generateRandom\" | \"signJwt\"\n >;\n\n /**\n * Thumbprint of the JWK in the cnf Wallet Attestation\n */\n client_id: string;\n\n /**\n * Optional expiration of the Authorization Response JWT, defaults to 10 minutes\n */\n exp?: number;\n\n /**\n * Presentation's Request Object\n */\n requestObject: AuthorizationRequestObject;\n\n /**\n * OpenID Federation Relying Party metadata\n */\n rpMetadata: ItWalletCredentialVerifierMetadata;\n\n /**\n * Signer created from the Wallet Instance's private key\n */\n signer: JwtSigner;\n\n /**\n * Array containing the vp_tokens of the credentials\n * to present\n */\n vp_token: VpToken;\n}\n\n/**\n * This method receives the RequestObject, its resolved VP Tokens and other necessary cryptographic and configuration data\n * and returns a signed and encrypted Presentation Response\n * @param options {@link CreateAuthorizationResponseOptions}\n * @returns An {@link CreateOpenid4vpAuthorizationResponseResult} representing\n * the encrypted and signed Presentation Response to the corresponding {@link AuthorizationRequestObject}\n * @throws An {@link CreateAuthorizationResponseError} in case of unexpected errors during response generation,\n * encryption, or signing\n */\nexport async function createAuthorizationResponse(\n options: CreateAuthorizationResponseOptions,\n) {\n try {\n const openid_credential_verifier = options.rpMetadata;\n\n const serverMetadata: JarmServerMetadata = {\n authorization_encryption_alg_values_supported: [\n openid_credential_verifier.authorization_encrypted_response_alg,\n ],\n authorization_encryption_enc_values_supported: [\n openid_credential_verifier.authorization_encrypted_response_enc,\n ],\n authorization_signing_alg_values_supported: [\n openid_credential_verifier.authorization_signed_response_alg,\n ],\n };\n\n // NOTE: This method sets the state in the Authorization Response\n // using the corresponding value in the Request Object\n return await createOpenid4vpAuthorizationResponse({\n authorizationRequestPayload: options.requestObject,\n authorizationResponsePayload: {\n vp_token: options.vp_token,\n },\n callbacks: options.callbacks,\n clientMetadata: openid_credential_verifier,\n jarm: {\n audience: options.requestObject.client_id,\n authorizationServer: options.client_id,\n encryption: {\n nonce: new TextDecoder().decode(\n await options.callbacks.generateRandom(32),\n ),\n },\n expiresInSeconds:\n options.exp ?? dateToSeconds(addSecondsToDate(new Date(), 60 * 10)), // default: 10 minutes\n jwtSigner: options.signer,\n serverMetadata,\n },\n });\n } catch (error) {\n throw new CreateAuthorizationResponseError(\n `Unexpected error during Request Object parsing: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,iBAKO;AACP,mBAAgC;;;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ACF;;;AJ5GA,IAAAC,oBAKO;","names":["import_oauth2","import_utils","import_openid4vp"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/authorization-request/parse-authorization-request.ts","../src/errors.ts","../src/authorization-request/z-request-object.ts","../src/authorization-response/create-authorization-response.ts","../src/authorization-response/fetch-authorization-response.ts","../src/authorization-response/z-authorization-response.ts"],"sourcesContent":["export * from \"./authorization-request\";\nexport * from \"./authorization-response\";\nexport * from \"./errors\";\n\nexport {\n type CreateOpenid4vpAuthorizationResponseOptions,\n type CreateOpenid4vpAuthorizationResponseResult,\n type VpToken,\n createOpenid4vpAuthorizationResponse,\n} from \"@openid4vc/openid4vp\";\n","import {\n CallbackContext,\n Oauth2JwtParseError,\n RequestDpopOptions,\n decodeJwt,\n} from \"@openid4vc/oauth2\";\nimport { ValidationError } from \"@openid4vc/utils\";\n\nimport { ParseAuthorizeRequestError } from \"../errors\";\nimport {\n AuthorizationRequestObject,\n zOpenid4vpAuthorizationRequest,\n} from \"./z-request-object\";\n\nexport interface ParseAuthorizeRequestOptions {\n /**\n * Callback context for signature verification.\n */\n callbacks: Pick<CallbackContext, \"verifyJwt\">;\n\n /**\n * DPoP options\n */\n dpop: RequestDpopOptions;\n\n /**\n * The Authorization Request Object JWT.\n */\n requestObjectJwt: string;\n}\n\n/**\n * This method verifies a JWT containing a Request Object and returns its\n * decoded value for further processing\n * @param options {@link ParseAuthorizeRequestOptions}\n * @returns An {@link AuthorizationRequestObject} containing the RP required\n * credentials\n * @throws {@link ValidationError} in case there are errors validating the Request Object structure\n * @throws {@link Oauth2JwtParseError} in case the request object jwt is malformed (e.g missing header, bad encoding)\n * @throws {@link ParseAuthorizeRequestError} in case the JWT signature is invalid or there are unexpected errors\n */\nexport async function parseAuthorizeRequest(\n options: ParseAuthorizeRequestOptions,\n): Promise<AuthorizationRequestObject> {\n try {\n const decoded = decodeJwt({\n jwt: options.requestObjectJwt,\n payloadSchema: zOpenid4vpAuthorizationRequest,\n });\n const verificationResult = await options.callbacks.verifyJwt(\n options.dpop.signer,\n {\n compact: options.requestObjectJwt,\n header: decoded.header,\n payload: decoded.payload,\n },\n );\n\n if (!verificationResult.verified)\n throw new ParseAuthorizeRequestError(\n \"Error verifying Request Object signature\",\n );\n\n return decoded.payload;\n } catch (error) {\n if (\n error instanceof ValidationError ||\n error instanceof Oauth2JwtParseError\n )\n throw error;\n throw new ParseAuthorizeRequestError(\n `Unexpected error during Request Object parsing: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n}\n","/**\n * Generic error thrown during Oid4vp operations\n */\nexport class Oid4vpError extends Error {\n constructor(\n message: string,\n public readonly statusCode?: number,\n ) {\n super(message);\n this.name = \"Oid4vpError\";\n }\n}\n\n/**\n * Error thrown by {@link parseAuthorizeRequest} when the passed\n * request object has an invalid signature or unexpected errors\n * are thrown\n */\nexport class ParseAuthorizeRequestError extends Oid4vpError {\n constructor(\n message: string,\n public readonly statusCode?: number,\n ) {\n super(message);\n this.name = \"ParseAuthorizeRequestError\";\n }\n}\n\n/**\n * Error thrown by {@link fetchAuthorizationResponse}\n */\nexport class FetchAuthorizationResponseError extends Oid4vpError {\n constructor(\n message: string,\n public readonly statusCode?: number,\n ) {\n super(message);\n this.name = \"FetchAuthorizationResponseError\";\n }\n}\n\n/**\n * Error thrown by {@link createAuthorizationResponse} in case there\n * are unexpected errors.\n */\nexport class CreateAuthorizationResponseError extends Oid4vpError {\n constructor(\n message: string,\n public readonly statusCode?: number,\n ) {\n super(message);\n this.name = \"CreateAuthorizationResponseError\";\n }\n}\n","import { zJwtPayload } from \"@openid4vc/oauth2\";\nimport { z } from \"zod\";\n\n/**\n * Zod parser that describes a JWT payload\n * containing an OID4VP Request Object\n */\nexport const zOpenid4vpAuthorizationRequest = z\n .object({\n client_id: z.string(),\n dcql_query: z.record(z.string(), z.any()).optional(),\n nonce: z.string(),\n request_uri: z.string().url().optional(),\n request_uri_method: z.optional(z.string()),\n response_mode: z.literal(\"direct_post.jwt\"),\n response_type: z.literal(\"vp_token\"),\n response_uri: z.string().url().optional(),\n scope: z.string().optional(),\n state: z.string(),\n wallet_nonce: z.string().optional(),\n })\n .passthrough()\n .and(zJwtPayload);\n\nexport type AuthorizationRequestObject = z.infer<\n typeof zOpenid4vpAuthorizationRequest\n>;\n","import { CallbackContext, JwtSigner } from \"@openid4vc/oauth2\";\nimport {\n CreateOpenid4vpAuthorizationResponseOptions,\n VpToken,\n createOpenid4vpAuthorizationResponse,\n} from \"@openid4vc/openid4vp\";\nimport { addSecondsToDate, dateToSeconds } from \"@openid4vc/utils\";\nimport { ItWalletCredentialVerifierMetadata } from \"@pagopa/io-wallet-oid-federation\";\n\nimport { AuthorizationRequestObject } from \"../authorization-request\";\nimport { CreateAuthorizationResponseError } from \"../errors\";\n\ntype JarmServerMetadata = NonNullable<\n CreateOpenid4vpAuthorizationResponseOptions[\"jarm\"]\n>[\"serverMetadata\"];\n\nexport interface CreateAuthorizationResponseOptions {\n /**\n * Callbacks for authorization response generation\n */\n callbacks: Pick<\n CallbackContext,\n \"encryptJwe\" | \"fetch\" | \"generateRandom\" | \"signJwt\"\n >;\n\n /**\n * Thumbprint of the JWK in the cnf Wallet Attestation\n */\n client_id: string;\n\n /**\n * Optional expiration of the Authorization Response JWT, defaults to 10 minutes\n */\n exp?: number;\n\n /**\n * Presentation's Request Object\n */\n requestObject: AuthorizationRequestObject;\n\n /**\n * OpenID Federation Relying Party metadata\n */\n rpMetadata: ItWalletCredentialVerifierMetadata;\n\n /**\n * Signer created from the Wallet Instance's private key\n */\n signer: JwtSigner;\n\n /**\n * Array containing the vp_tokens of the credentials\n * to present\n */\n vp_token: VpToken;\n}\n\n/**\n * This method receives the RequestObject, its resolved VP Tokens and other necessary cryptographic and configuration data\n * and returns a signed and encrypted Presentation Response\n * @param options {@link CreateAuthorizationResponseOptions}\n * @returns An {@link CreateOpenid4vpAuthorizationResponseResult} representing\n * the encrypted and signed Presentation Response to the corresponding {@link AuthorizationRequestObject}\n * @throws An {@link CreateAuthorizationResponseError} in case of unexpected errors during response generation,\n * encryption, or signing\n */\nexport async function createAuthorizationResponse(\n options: CreateAuthorizationResponseOptions,\n) {\n try {\n const openid_credential_verifier = options.rpMetadata;\n\n const serverMetadata: JarmServerMetadata = {\n authorization_encryption_alg_values_supported: [\n openid_credential_verifier.authorization_encrypted_response_alg,\n ],\n authorization_encryption_enc_values_supported: [\n openid_credential_verifier.authorization_encrypted_response_enc,\n ],\n authorization_signing_alg_values_supported: [\n openid_credential_verifier.authorization_signed_response_alg,\n ],\n };\n\n // NOTE: This method sets the state in the Authorization Response\n // using the corresponding value in the Request Object\n return await createOpenid4vpAuthorizationResponse({\n authorizationRequestPayload: options.requestObject,\n authorizationResponsePayload: {\n vp_token: options.vp_token,\n },\n callbacks: options.callbacks,\n clientMetadata: openid_credential_verifier,\n jarm: {\n audience: options.requestObject.client_id,\n authorizationServer: options.client_id,\n encryption: {\n nonce: new TextDecoder().decode(\n await options.callbacks.generateRandom(32),\n ),\n },\n expiresInSeconds:\n options.exp ?? dateToSeconds(addSecondsToDate(new Date(), 60 * 10)), // default: 10 minutes\n jwtSigner: options.signer,\n serverMetadata,\n },\n });\n } catch (error) {\n throw new CreateAuthorizationResponseError(\n `Unexpected error during Request Object parsing: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n}\n","import { CallbackContext } from \"@openid4vc/oauth2\";\nimport {\n ValidationError,\n createFetcher,\n parseWithErrorHandling,\n} from \"@openid4vc/utils\";\nimport {\n CONTENT_TYPES,\n HEADERS,\n UnexpectedStatusCodeError,\n hasStatusOrThrow,\n} from \"@pagopa/io-wallet-utils\";\n\nimport { FetchAuthorizationResponseError } from \"../errors\";\nimport {\n Oid4vpAuthorizationResponseResult,\n zOid4vpAuthorizationResponseResult,\n} from \"./z-authorization-response\";\n\n/**\n * Configuration options for fetching OID4VP Presentation Result\n */\nexport interface FetchAuthorizationResponseOptions {\n /**\n * The signed and encrypted {@link Openid4vpAuthorizationResponse} in base64 format\n */\n authorizationResponseJarm: string;\n\n /**\n * Callback functions for making HTTP requests\n * Allows for custom fetch implementations\n */\n callbacks: Pick<CallbackContext, \"fetch\">;\n\n /**\n * The response_uri field contained in the {@link AuthorizationRequestObject}\n */\n presentationResponseUri: string;\n}\n\n/**\n * Sends the {@link Openid4vpAuthorizationResponse} to the response uri provided by the session's\n * {@link AuthorizationRequestObject} and returns the {@link Oid4vpAuthorizationResponseResult} object\n * containing the redirect_uri at which to continue the presentation\n *\n * @param options {@link FetchAuthorizationResponseOptions}\n * @returns Promise that resolves to the parsed {@link Oid4vpAuthorizationResponseResult}\n * @throws {UnexpectedStatusCodeError} When the server returns a non-200 status code\n * @throws {ValidationError} When the response cannot be parsed or is invalid\n */\nexport async function fetchAuthorizationResponse(\n options: FetchAuthorizationResponseOptions,\n): Promise<Oid4vpAuthorizationResponseResult> {\n try {\n const fetch = createFetcher(options.callbacks.fetch);\n const authorizationResponseResult = await fetch(\n options.presentationResponseUri,\n {\n body: new URLSearchParams({\n response: options.authorizationResponseJarm,\n }),\n headers: {\n [HEADERS.CONTENT_TYPE]: CONTENT_TYPES.FORM_URLENCODED,\n },\n method: \"POST\",\n },\n );\n\n await hasStatusOrThrow(\n 200,\n UnexpectedStatusCodeError,\n )(authorizationResponseResult);\n\n const authorizationResponseResultJson =\n await authorizationResponseResult.json();\n\n //Response could be anything, so it's returned as is for further processing\n return parseWithErrorHandling(\n zOid4vpAuthorizationResponseResult,\n authorizationResponseResultJson,\n );\n } catch (error) {\n if (\n error instanceof UnexpectedStatusCodeError ||\n error instanceof ValidationError\n ) {\n throw error;\n }\n throw new FetchAuthorizationResponseError(\n `Unexpected error sending authorization response: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n}\n","import z from \"zod\";\n\nexport const zOid4vpAuthorizationResponseResult = z.object({\n redirect_uri: z.string(),\n});\n\nexport type Oid4vpAuthorizationResponseResult = z.infer<\n typeof zOid4vpAuthorizationResponseResult\n>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;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BAAI,KAAK,GAAG,KAAK,EAAE,CAAC;AAAA;AAAA,QACpE,WAAW,QAAQ;AAAA,QACnB;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH,SAAS,OAAO;AACd,UAAM,IAAI;AAAA,MACR,mDAAmD,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AAAA,IAC3G;AAAA,EACF;AACF;;;AC/GA,IAAAC,gBAIO;AACP,6BAKO;;;ACXP,IAAAC,cAAc;AAEP,IAAM,qCAAqC,YAAAC,QAAE,OAAO;AAAA,EACzD,cAAc,YAAAA,QAAE,OAAO;AACzB,CAAC;;;AD8CD,eAAsB,2BACpB,SAC4C;AAC5C,MAAI;AACF,UAAM,YAAQ,6BAAc,QAAQ,UAAU,KAAK;AACnD,UAAM,8BAA8B,MAAM;AAAA,MACxC,QAAQ;AAAA,MACR;AAAA,QACE,MAAM,IAAI,gBAAgB;AAAA,UACxB,UAAU,QAAQ;AAAA,QACpB,CAAC;AAAA,QACD,SAAS;AAAA,UACP,CAAC,+BAAQ,YAAY,GAAG,qCAAc;AAAA,QACxC;AAAA,QACA,QAAQ;AAAA,MACV;AAAA,IACF;AAEA,cAAM;AAAA,MACJ;AAAA,MACA;AAAA,IACF,EAAE,2BAA2B;AAE7B,UAAM,kCACJ,MAAM,4BAA4B,KAAK;AAGzC,eAAO;AAAA,MACL;AAAA,MACA;AAAA,IACF;AAAA,EACF,SAAS,OAAO;AACd,QACE,iBAAiB,oDACjB,iBAAiB,+BACjB;AACA,YAAM;AAAA,IACR;AACA,UAAM,IAAI;AAAA,MACR,oDAAoD,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AAAA,IAC5G;AAAA,EACF;AACF;;;ALxFA,IAAAC,oBAKO;","names":["import_oauth2","import_utils","import_utils","import_zod","z","import_openid4vp"]}
package/dist/index.mjs CHANGED
@@ -20,6 +20,13 @@ var ParseAuthorizeRequestError = class extends Oid4vpError {
20
20
  this.name = "ParseAuthorizeRequestError";
21
21
  }
22
22
  };
23
+ var FetchAuthorizationResponseError = class extends Oid4vpError {
24
+ constructor(message, statusCode) {
25
+ super(message);
26
+ this.statusCode = statusCode;
27
+ this.name = "FetchAuthorizationResponseError";
28
+ }
29
+ };
23
30
  var CreateAuthorizationResponseError = class extends Oid4vpError {
24
31
  constructor(message, statusCode) {
25
32
  super(message);
@@ -121,17 +128,74 @@ async function createAuthorizationResponse(options) {
121
128
  }
122
129
  }
123
130
 
131
+ // src/authorization-response/fetch-authorization-response.ts
132
+ import {
133
+ ValidationError as ValidationError2,
134
+ createFetcher,
135
+ parseWithErrorHandling
136
+ } from "@openid4vc/utils";
137
+ import {
138
+ CONTENT_TYPES,
139
+ HEADERS,
140
+ UnexpectedStatusCodeError,
141
+ hasStatusOrThrow
142
+ } from "@pagopa/io-wallet-utils";
143
+
144
+ // src/authorization-response/z-authorization-response.ts
145
+ import z2 from "zod";
146
+ var zOid4vpAuthorizationResponseResult = z2.object({
147
+ redirect_uri: z2.string()
148
+ });
149
+
150
+ // src/authorization-response/fetch-authorization-response.ts
151
+ async function fetchAuthorizationResponse(options) {
152
+ try {
153
+ const fetch = createFetcher(options.callbacks.fetch);
154
+ const authorizationResponseResult = await fetch(
155
+ options.presentationResponseUri,
156
+ {
157
+ body: new URLSearchParams({
158
+ response: options.authorizationResponseJarm
159
+ }),
160
+ headers: {
161
+ [HEADERS.CONTENT_TYPE]: CONTENT_TYPES.FORM_URLENCODED
162
+ },
163
+ method: "POST"
164
+ }
165
+ );
166
+ await hasStatusOrThrow(
167
+ 200,
168
+ UnexpectedStatusCodeError
169
+ )(authorizationResponseResult);
170
+ const authorizationResponseResultJson = await authorizationResponseResult.json();
171
+ return parseWithErrorHandling(
172
+ zOid4vpAuthorizationResponseResult,
173
+ authorizationResponseResultJson
174
+ );
175
+ } catch (error) {
176
+ if (error instanceof UnexpectedStatusCodeError || error instanceof ValidationError2) {
177
+ throw error;
178
+ }
179
+ throw new FetchAuthorizationResponseError(
180
+ `Unexpected error sending authorization response: ${error instanceof Error ? error.message : String(error)}`
181
+ );
182
+ }
183
+ }
184
+
124
185
  // src/index.ts
125
186
  import {
126
187
  createOpenid4vpAuthorizationResponse as createOpenid4vpAuthorizationResponse2
127
188
  } from "@openid4vc/openid4vp";
128
189
  export {
129
190
  CreateAuthorizationResponseError,
191
+ FetchAuthorizationResponseError,
130
192
  Oid4vpError,
131
193
  ParseAuthorizeRequestError,
132
194
  createAuthorizationResponse,
133
195
  createOpenid4vpAuthorizationResponse2 as createOpenid4vpAuthorizationResponse,
196
+ fetchAuthorizationResponse,
134
197
  parseAuthorizeRequest,
198
+ zOid4vpAuthorizationResponseResult,
135
199
  zOpenid4vpAuthorizationRequest
136
200
  };
137
201
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/authorization-request/parse-authorization-request.ts","../src/errors.ts","../src/authorization-request/z-request-object.ts","../src/authorization-response/create-authorization-response.ts","../src/index.ts"],"sourcesContent":["import {\n CallbackContext,\n Oauth2JwtParseError,\n RequestDpopOptions,\n decodeJwt,\n} from \"@openid4vc/oauth2\";\nimport { ValidationError } from \"@openid4vc/utils\";\n\nimport { ParseAuthorizeRequestError } from \"../errors\";\nimport {\n AuthorizationRequestObject,\n zOpenid4vpAuthorizationRequest,\n} from \"./z-request-object\";\n\nexport interface ParseAuthorizeRequestOptions {\n /**\n * Callback context for signature verification.\n */\n callbacks: Pick<CallbackContext, \"verifyJwt\">;\n\n /**\n * DPoP options\n */\n dpop: RequestDpopOptions;\n\n /**\n * The Authorization Request Object JWT.\n */\n requestObjectJwt: string;\n}\n\n/**\n * This method verifies a JWT containing a Request Object and returns its\n * decoded value for further processing\n * @param options {@link ParseAuthorizeRequestOptions}\n * @returns An {@link AuthorizationRequestObject} containing the RP required\n * credentials\n * @throws {@link ValidationError} in case there are errors validating the Request Object structure\n * @throws {@link Oauth2JwtParseError} in case the request object jwt is malformed (e.g missing header, bad encoding)\n * @throws {@link ParseAuthorizeRequestError} in case the JWT signature is invalid or there are unexpected errors\n */\nexport async function parseAuthorizeRequest(\n options: ParseAuthorizeRequestOptions,\n): Promise<AuthorizationRequestObject> {\n try {\n const decoded = decodeJwt({\n jwt: options.requestObjectJwt,\n payloadSchema: zOpenid4vpAuthorizationRequest,\n });\n const verificationResult = await options.callbacks.verifyJwt(\n options.dpop.signer,\n {\n compact: options.requestObjectJwt,\n header: decoded.header,\n payload: decoded.payload,\n },\n );\n\n if (!verificationResult.verified)\n throw new ParseAuthorizeRequestError(\n \"Error verifying Request Object signature\",\n );\n\n return decoded.payload;\n } catch (error) {\n if (\n error instanceof ValidationError ||\n error instanceof Oauth2JwtParseError\n )\n throw error;\n throw new ParseAuthorizeRequestError(\n `Unexpected error during Request Object parsing: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n}\n","/**\n * Generic error thrown during Oid4vp operations\n */\nexport class Oid4vpError extends Error {\n constructor(\n message: string,\n public readonly statusCode?: number,\n ) {\n super(message);\n this.name = \"Oid4vpError\";\n }\n}\n\n/**\n * Error thrown by {@link parseAuthorizeRequest} when the passed\n * request object has an invalid signature or unexpected errors\n * are thrown\n */\nexport class ParseAuthorizeRequestError extends Oid4vpError {\n constructor(\n message: string,\n public readonly statusCode?: number,\n ) {\n super(message);\n this.name = \"ParseAuthorizeRequestError\";\n }\n}\n\n/**\n * Error thrown by {@link createAuthorizationResponse} in case there\n * are unexpected errors.\n */\nexport class CreateAuthorizationResponseError extends Oid4vpError {\n constructor(\n message: string,\n public readonly statusCode?: number,\n ) {\n super(message);\n this.name = \"CreateAuthorizationResponseError\";\n }\n}\n","import { zJwtPayload } from \"@openid4vc/oauth2\";\nimport { z } from \"zod\";\n\n/**\n * Zod parser that describes a JWT payload\n * containing an OID4VP Request Object\n */\nexport const zOpenid4vpAuthorizationRequest = z\n .object({\n client_id: z.string(),\n dcql_query: z.record(z.string(), z.any()).optional(),\n nonce: z.string(),\n request_uri: z.string().url().optional(),\n request_uri_method: z.optional(z.string()),\n response_mode: z.literal(\"direct_post.jwt\"),\n response_type: z.literal(\"vp_token\"),\n response_uri: z.string().url().optional(),\n scope: z.string().optional(),\n state: z.string(),\n wallet_nonce: z.string().optional(),\n })\n .passthrough()\n .and(zJwtPayload);\n\nexport type AuthorizationRequestObject = z.infer<\n typeof zOpenid4vpAuthorizationRequest\n>;\n","import { CallbackContext, JwtSigner } from \"@openid4vc/oauth2\";\nimport {\n CreateOpenid4vpAuthorizationResponseOptions,\n VpToken,\n createOpenid4vpAuthorizationResponse,\n} from \"@openid4vc/openid4vp\";\nimport { addSecondsToDate, dateToSeconds } from \"@openid4vc/utils\";\nimport { ItWalletCredentialVerifierMetadata } from \"@pagopa/io-wallet-oid-federation\";\n\nimport { AuthorizationRequestObject } from \"../authorization-request\";\nimport { CreateAuthorizationResponseError } from \"../errors\";\n\ntype JarmServerMetadata = NonNullable<\n CreateOpenid4vpAuthorizationResponseOptions[\"jarm\"]\n>[\"serverMetadata\"];\n\nexport interface CreateAuthorizationResponseOptions {\n /**\n * Callbacks for authorization response generation\n */\n callbacks: Pick<\n CallbackContext,\n \"encryptJwe\" | \"fetch\" | \"generateRandom\" | \"signJwt\"\n >;\n\n /**\n * Thumbprint of the JWK in the cnf Wallet Attestation\n */\n client_id: string;\n\n /**\n * Optional expiration of the Authorization Response JWT, defaults to 10 minutes\n */\n exp?: number;\n\n /**\n * Presentation's Request Object\n */\n requestObject: AuthorizationRequestObject;\n\n /**\n * OpenID Federation Relying Party metadata\n */\n rpMetadata: ItWalletCredentialVerifierMetadata;\n\n /**\n * Signer created from the Wallet Instance's private key\n */\n signer: JwtSigner;\n\n /**\n * Array containing the vp_tokens of the credentials\n * to present\n */\n vp_token: VpToken;\n}\n\n/**\n * This method receives the RequestObject, its resolved VP Tokens and other necessary cryptographic and configuration data\n * and returns a signed and encrypted Presentation Response\n * @param options {@link CreateAuthorizationResponseOptions}\n * @returns An {@link CreateOpenid4vpAuthorizationResponseResult} representing\n * the encrypted and signed Presentation Response to the corresponding {@link AuthorizationRequestObject}\n * @throws An {@link CreateAuthorizationResponseError} in case of unexpected errors during response generation,\n * encryption, or signing\n */\nexport async function createAuthorizationResponse(\n options: CreateAuthorizationResponseOptions,\n) {\n try {\n const openid_credential_verifier = options.rpMetadata;\n\n const serverMetadata: JarmServerMetadata = {\n authorization_encryption_alg_values_supported: [\n openid_credential_verifier.authorization_encrypted_response_alg,\n ],\n authorization_encryption_enc_values_supported: [\n openid_credential_verifier.authorization_encrypted_response_enc,\n ],\n authorization_signing_alg_values_supported: [\n openid_credential_verifier.authorization_signed_response_alg,\n ],\n };\n\n // NOTE: This method sets the state in the Authorization Response\n // using the corresponding value in the Request Object\n return await createOpenid4vpAuthorizationResponse({\n authorizationRequestPayload: options.requestObject,\n authorizationResponsePayload: {\n vp_token: options.vp_token,\n },\n callbacks: options.callbacks,\n clientMetadata: openid_credential_verifier,\n jarm: {\n audience: options.requestObject.client_id,\n authorizationServer: options.client_id,\n encryption: {\n nonce: new TextDecoder().decode(\n await options.callbacks.generateRandom(32),\n ),\n },\n expiresInSeconds:\n options.exp ?? dateToSeconds(addSecondsToDate(new Date(), 60 * 10)), // default: 10 minutes\n jwtSigner: options.signer,\n serverMetadata,\n },\n });\n } catch (error) {\n throw new CreateAuthorizationResponseError(\n `Unexpected error during Request Object parsing: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n}\n","export * from \"./authorization-request\";\nexport * from \"./authorization-response\";\nexport * from \"./errors\";\n\nexport {\n type CreateOpenid4vpAuthorizationResponseOptions,\n type CreateOpenid4vpAuthorizationResponseResult,\n type VpToken,\n createOpenid4vpAuthorizationResponse,\n} from \"@openid4vc/openid4vp\";\n"],"mappings":";AAAA;AAAA,EAEE;AAAA,EAEA;AAAA,OACK;AACP,SAAS,uBAAuB;;;ACHzB,IAAM,cAAN,cAA0B,MAAM;AAAA,EACrC,YACE,SACgB,YAChB;AACA,UAAM,OAAO;AAFG;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;AAOO,IAAM,6BAAN,c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-request.ts","../src/errors.ts","../src/authorization-request/z-request-object.ts","../src/authorization-response/create-authorization-response.ts","../src/authorization-response/fetch-authorization-response.ts","../src/authorization-response/z-authorization-response.ts","../src/index.ts"],"sourcesContent":["import {\n CallbackContext,\n Oauth2JwtParseError,\n RequestDpopOptions,\n decodeJwt,\n} from \"@openid4vc/oauth2\";\nimport { ValidationError } from \"@openid4vc/utils\";\n\nimport { ParseAuthorizeRequestError } from \"../errors\";\nimport {\n AuthorizationRequestObject,\n zOpenid4vpAuthorizationRequest,\n} from \"./z-request-object\";\n\nexport interface ParseAuthorizeRequestOptions {\n /**\n * Callback context for signature verification.\n */\n callbacks: Pick<CallbackContext, \"verifyJwt\">;\n\n /**\n * DPoP options\n */\n dpop: RequestDpopOptions;\n\n /**\n * The Authorization Request Object JWT.\n */\n requestObjectJwt: string;\n}\n\n/**\n * This method verifies a JWT containing a Request Object and returns its\n * decoded value for further processing\n * @param options {@link ParseAuthorizeRequestOptions}\n * @returns An {@link AuthorizationRequestObject} containing the RP required\n * credentials\n * @throws {@link ValidationError} in case there are errors validating the Request Object structure\n * @throws {@link Oauth2JwtParseError} in case the request object jwt is malformed (e.g missing header, bad encoding)\n * @throws {@link ParseAuthorizeRequestError} in case the JWT signature is invalid or there are unexpected errors\n */\nexport async function parseAuthorizeRequest(\n options: ParseAuthorizeRequestOptions,\n): Promise<AuthorizationRequestObject> {\n try {\n const decoded = decodeJwt({\n jwt: options.requestObjectJwt,\n payloadSchema: zOpenid4vpAuthorizationRequest,\n });\n const verificationResult = await options.callbacks.verifyJwt(\n options.dpop.signer,\n {\n compact: options.requestObjectJwt,\n header: decoded.header,\n payload: decoded.payload,\n },\n );\n\n if (!verificationResult.verified)\n throw new ParseAuthorizeRequestError(\n \"Error verifying Request Object signature\",\n );\n\n return decoded.payload;\n } catch (error) {\n if (\n error instanceof ValidationError ||\n error instanceof Oauth2JwtParseError\n )\n throw error;\n throw new ParseAuthorizeRequestError(\n `Unexpected error during Request Object parsing: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n}\n","/**\n * Generic error thrown during Oid4vp operations\n */\nexport class Oid4vpError extends Error {\n constructor(\n message: string,\n public readonly statusCode?: number,\n ) {\n super(message);\n this.name = \"Oid4vpError\";\n }\n}\n\n/**\n * Error thrown by {@link parseAuthorizeRequest} when the passed\n * request object has an invalid signature or unexpected errors\n * are thrown\n */\nexport class ParseAuthorizeRequestError extends Oid4vpError {\n constructor(\n message: string,\n public readonly statusCode?: number,\n ) {\n super(message);\n this.name = \"ParseAuthorizeRequestError\";\n }\n}\n\n/**\n * Error thrown by {@link fetchAuthorizationResponse}\n */\nexport class FetchAuthorizationResponseError extends Oid4vpError {\n constructor(\n message: string,\n public readonly statusCode?: number,\n ) {\n super(message);\n this.name = \"FetchAuthorizationResponseError\";\n }\n}\n\n/**\n * Error thrown by {@link createAuthorizationResponse} in case there\n * are unexpected errors.\n */\nexport class CreateAuthorizationResponseError extends Oid4vpError {\n constructor(\n message: string,\n public readonly statusCode?: number,\n ) {\n super(message);\n this.name = \"CreateAuthorizationResponseError\";\n }\n}\n","import { zJwtPayload } from \"@openid4vc/oauth2\";\nimport { z } from \"zod\";\n\n/**\n * Zod parser that describes a JWT payload\n * containing an OID4VP Request Object\n */\nexport const zOpenid4vpAuthorizationRequest = z\n .object({\n client_id: z.string(),\n dcql_query: z.record(z.string(), z.any()).optional(),\n nonce: z.string(),\n request_uri: z.string().url().optional(),\n request_uri_method: z.optional(z.string()),\n response_mode: z.literal(\"direct_post.jwt\"),\n response_type: z.literal(\"vp_token\"),\n response_uri: z.string().url().optional(),\n scope: z.string().optional(),\n state: z.string(),\n wallet_nonce: z.string().optional(),\n })\n .passthrough()\n .and(zJwtPayload);\n\nexport type AuthorizationRequestObject = z.infer<\n typeof zOpenid4vpAuthorizationRequest\n>;\n","import { CallbackContext, JwtSigner } from \"@openid4vc/oauth2\";\nimport {\n CreateOpenid4vpAuthorizationResponseOptions,\n VpToken,\n createOpenid4vpAuthorizationResponse,\n} from \"@openid4vc/openid4vp\";\nimport { addSecondsToDate, dateToSeconds } from \"@openid4vc/utils\";\nimport { ItWalletCredentialVerifierMetadata } from \"@pagopa/io-wallet-oid-federation\";\n\nimport { AuthorizationRequestObject } from \"../authorization-request\";\nimport { CreateAuthorizationResponseError } from \"../errors\";\n\ntype JarmServerMetadata = NonNullable<\n CreateOpenid4vpAuthorizationResponseOptions[\"jarm\"]\n>[\"serverMetadata\"];\n\nexport interface CreateAuthorizationResponseOptions {\n /**\n * Callbacks for authorization response generation\n */\n callbacks: Pick<\n CallbackContext,\n \"encryptJwe\" | \"fetch\" | \"generateRandom\" | \"signJwt\"\n >;\n\n /**\n * Thumbprint of the JWK in the cnf Wallet Attestation\n */\n client_id: string;\n\n /**\n * Optional expiration of the Authorization Response JWT, defaults to 10 minutes\n */\n exp?: number;\n\n /**\n * Presentation's Request Object\n */\n requestObject: AuthorizationRequestObject;\n\n /**\n * OpenID Federation Relying Party metadata\n */\n rpMetadata: ItWalletCredentialVerifierMetadata;\n\n /**\n * Signer created from the Wallet Instance's private key\n */\n signer: JwtSigner;\n\n /**\n * Array containing the vp_tokens of the credentials\n * to present\n */\n vp_token: VpToken;\n}\n\n/**\n * This method receives the RequestObject, its resolved VP Tokens and other necessary cryptographic and configuration data\n * and returns a signed and encrypted Presentation Response\n * @param options {@link CreateAuthorizationResponseOptions}\n * @returns An {@link CreateOpenid4vpAuthorizationResponseResult} representing\n * the encrypted and signed Presentation Response to the corresponding {@link AuthorizationRequestObject}\n * @throws An {@link CreateAuthorizationResponseError} in case of unexpected errors during response generation,\n * encryption, or signing\n */\nexport async function createAuthorizationResponse(\n options: CreateAuthorizationResponseOptions,\n) {\n try {\n const openid_credential_verifier = options.rpMetadata;\n\n const serverMetadata: JarmServerMetadata = {\n authorization_encryption_alg_values_supported: [\n openid_credential_verifier.authorization_encrypted_response_alg,\n ],\n authorization_encryption_enc_values_supported: [\n openid_credential_verifier.authorization_encrypted_response_enc,\n ],\n authorization_signing_alg_values_supported: [\n openid_credential_verifier.authorization_signed_response_alg,\n ],\n };\n\n // NOTE: This method sets the state in the Authorization Response\n // using the corresponding value in the Request Object\n return await createOpenid4vpAuthorizationResponse({\n authorizationRequestPayload: options.requestObject,\n authorizationResponsePayload: {\n vp_token: options.vp_token,\n },\n callbacks: options.callbacks,\n clientMetadata: openid_credential_verifier,\n jarm: {\n audience: options.requestObject.client_id,\n authorizationServer: options.client_id,\n encryption: {\n nonce: new TextDecoder().decode(\n await options.callbacks.generateRandom(32),\n ),\n },\n expiresInSeconds:\n options.exp ?? dateToSeconds(addSecondsToDate(new Date(), 60 * 10)), // default: 10 minutes\n jwtSigner: options.signer,\n serverMetadata,\n },\n });\n } catch (error) {\n throw new CreateAuthorizationResponseError(\n `Unexpected error during Request Object parsing: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n}\n","import { CallbackContext } from \"@openid4vc/oauth2\";\nimport {\n ValidationError,\n createFetcher,\n parseWithErrorHandling,\n} from \"@openid4vc/utils\";\nimport {\n CONTENT_TYPES,\n HEADERS,\n UnexpectedStatusCodeError,\n hasStatusOrThrow,\n} from \"@pagopa/io-wallet-utils\";\n\nimport { FetchAuthorizationResponseError } from \"../errors\";\nimport {\n Oid4vpAuthorizationResponseResult,\n zOid4vpAuthorizationResponseResult,\n} from \"./z-authorization-response\";\n\n/**\n * Configuration options for fetching OID4VP Presentation Result\n */\nexport interface FetchAuthorizationResponseOptions {\n /**\n * The signed and encrypted {@link Openid4vpAuthorizationResponse} in base64 format\n */\n authorizationResponseJarm: string;\n\n /**\n * Callback functions for making HTTP requests\n * Allows for custom fetch implementations\n */\n callbacks: Pick<CallbackContext, \"fetch\">;\n\n /**\n * The response_uri field contained in the {@link AuthorizationRequestObject}\n */\n presentationResponseUri: string;\n}\n\n/**\n * Sends the {@link Openid4vpAuthorizationResponse} to the response uri provided by the session's\n * {@link AuthorizationRequestObject} and returns the {@link Oid4vpAuthorizationResponseResult} object\n * containing the redirect_uri at which to continue the presentation\n *\n * @param options {@link FetchAuthorizationResponseOptions}\n * @returns Promise that resolves to the parsed {@link Oid4vpAuthorizationResponseResult}\n * @throws {UnexpectedStatusCodeError} When the server returns a non-200 status code\n * @throws {ValidationError} When the response cannot be parsed or is invalid\n */\nexport async function fetchAuthorizationResponse(\n options: FetchAuthorizationResponseOptions,\n): Promise<Oid4vpAuthorizationResponseResult> {\n try {\n const fetch = createFetcher(options.callbacks.fetch);\n const authorizationResponseResult = await fetch(\n options.presentationResponseUri,\n {\n body: new URLSearchParams({\n response: options.authorizationResponseJarm,\n }),\n headers: {\n [HEADERS.CONTENT_TYPE]: CONTENT_TYPES.FORM_URLENCODED,\n },\n method: \"POST\",\n },\n );\n\n await hasStatusOrThrow(\n 200,\n UnexpectedStatusCodeError,\n )(authorizationResponseResult);\n\n const authorizationResponseResultJson =\n await authorizationResponseResult.json();\n\n //Response could be anything, so it's returned as is for further processing\n return parseWithErrorHandling(\n zOid4vpAuthorizationResponseResult,\n authorizationResponseResultJson,\n );\n } catch (error) {\n if (\n error instanceof UnexpectedStatusCodeError ||\n error instanceof ValidationError\n ) {\n throw error;\n }\n throw new FetchAuthorizationResponseError(\n `Unexpected error sending authorization response: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n}\n","import z from \"zod\";\n\nexport const zOid4vpAuthorizationResponseResult = z.object({\n redirect_uri: z.string(),\n});\n\nexport type Oid4vpAuthorizationResponseResult = z.infer<\n typeof zOid4vpAuthorizationResponseResult\n>;\n","export * from \"./authorization-request\";\nexport * from \"./authorization-response\";\nexport * from \"./errors\";\n\nexport {\n type CreateOpenid4vpAuthorizationResponseOptions,\n type CreateOpenid4vpAuthorizationResponseResult,\n type VpToken,\n createOpenid4vpAuthorizationResponse,\n} from \"@openid4vc/openid4vp\";\n"],"mappings":";AAAA;AAAA,EAEE;AAAA,EAEA;AAAA,OACK;AACP,SAAS,uBAAuB;;;ACHzB,IAAM,cAAN,cAA0B,MAAM;AAAA,EACrC,YACE,SACgB,YAChB;AACA,UAAM,OAA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D,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AAAA,IAC3G;AAAA,EACF;AACF;;;AC/GA;AAAA,EACE,mBAAAA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACXP,OAAOC,QAAO;AAEP,IAAM,qCAAqCA,GAAE,OAAO;AAAA,EACzD,cAAcA,GAAE,OAAO;AACzB,CAAC;;;AD8CD,eAAsB,2BACpB,SAC4C;AAC5C,MAAI;AACF,UAAM,QAAQ,cAAc,QAAQ,UAAU,KAAK;AACnD,UAAM,8BAA8B,MAAM;AAAA,MACxC,QAAQ;AAAA,MACR;AAAA,QACE,MAAM,IAAI,gBAAgB;AAAA,UACxB,UAAU,QAAQ;AAAA,QACpB,CAAC;AAAA,QACD,SAAS;AAAA,UACP,CAAC,QAAQ,YAAY,GAAG,cAAc;AAAA,QACxC;AAAA,QACA,QAAQ;AAAA,MACV;AAAA,IACF;AAEA,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,IACF,EAAE,2BAA2B;AAE7B,UAAM,kCACJ,MAAM,4BAA4B,KAAK;AAGzC,WAAO;AAAA,MACL;AAAA,MACA;AAAA,IACF;AAAA,EACF,SAAS,OAAO;AACd,QACE,iBAAiB,6BACjB,iBAAiBC,kBACjB;AACA,YAAM;AAAA,IACR;AACA,UAAM,IAAI;AAAA,MACR,oDAAoD,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AAAA,IAC5G;AAAA,EACF;AACF;;;AExFA;AAAA,EAIE,wCAAAC;AAAA,OACK;","names":["ValidationError","z","ValidationError","createOpenid4vpAuthorizationResponse"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pagopa/io-wallet-oid4vp",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "files": [
5
5
  "dist"
6
6
  ],
@@ -30,6 +30,7 @@
30
30
  "@openid4vc/utils": "0.3.0-alpha-20250714110838",
31
31
  "@openid4vc/openid4vp": "0.3.0-alpha-20250714110838",
32
32
  "zod": "^3.24.2",
33
+ "@pagopa/io-wallet-utils": "",
33
34
  "@pagopa/io-wallet-oid-federation": ""
34
35
  },
35
36
  "devDependencies": {