@pagopa/io-wallet-utils 1.4.0 → 1.4.1-alpha-20260518131456

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
@@ -55,6 +55,12 @@ declare function hasConfigVersion<T extends WithConfig, V extends ItWalletSpecsV
55
55
  */
56
56
  declare class IoWalletSdkConfig<V extends ItWalletSpecsVersion = ItWalletSpecsVersion> {
57
57
  readonly itWalletSpecsVersion: V;
58
+ /**
59
+ * Creates an SDK configuration for a specific IT-Wallet specification version.
60
+ *
61
+ * @param options - Configuration options.
62
+ * @param options.itWalletSpecsVersion - IT-Wallet specification version to use.
63
+ */
58
64
  constructor(options: IoWalletSdkConfigOptions<V>);
59
65
  /**
60
66
  * Type guard for version checking
@@ -135,11 +141,20 @@ declare class ItWalletSpecsVersionError extends Error {
135
141
  readonly code = "IT_WALLET_SPECS_VERSION_ERROR";
136
142
  constructor(feature: string, requestedVersion: string, supportedVersions: readonly string[]);
137
143
  }
144
+ /**
145
+ * Error thrown when runtime validation fails.
146
+ */
138
147
  declare class ValidationError extends Error {
139
148
  zodError: ZodError | undefined;
140
149
  constructor(message: string, zodError?: z.ZodError);
141
150
  }
142
151
 
152
+ /**
153
+ * Formats a Zod error into a readable multi-line message.
154
+ *
155
+ * @param error - Optional Zod error to format.
156
+ * @returns Empty string when no error is provided, otherwise a formatted issue list.
157
+ */
143
158
  declare function formatZodError(error?: z$1.ZodError): string;
144
159
 
145
160
  /**
@@ -152,6 +167,9 @@ declare function formatZodError(error?: z$1.ZodError): string;
152
167
  declare const hasStatusOrThrow: (status: number | number[], customError?: typeof UnexpectedStatusCodeError) => (res: Response) => Promise<Response>;
153
168
  /**
154
169
  * Utility function to parse a raw HTTP response as JSON if supported, otherwise as text.
170
+ *
171
+ * @param response - Raw HTTP response to parse.
172
+ * @returns Parsed JSON for JSON responses, otherwise response text.
155
173
  */
156
174
  declare const parseRawHttpResponse: <T extends Record<string, unknown>>(response: Response) => Promise<T> | Promise<string>;
157
175
 
@@ -191,12 +209,66 @@ interface RequestLike {
191
209
  }
192
210
 
193
211
  type BaseSchema = z.ZodTypeAny;
212
+ /**
213
+ * Parses data with a Zod schema and throws the SDK `ValidationError` on failure.
214
+ *
215
+ * @param schema - Zod schema used for validation.
216
+ * @param data - Unknown value to parse.
217
+ * @param customErrorMessage - Optional error message used when validation fails.
218
+ * @returns Parsed schema output.
219
+ * @throws {ValidationError} If the value does not satisfy the provided schema.
220
+ */
194
221
  declare function parseWithErrorHandling<Schema extends BaseSchema>(schema: Schema, data: unknown, customErrorMessage?: string): z.infer<Schema>;
222
+ /**
223
+ * Prefixes an error message with optional contextual text.
224
+ *
225
+ * @param message - Base error message.
226
+ * @param prefix - Optional prefix to prepend.
227
+ * @returns Formatted error message.
228
+ */
195
229
  declare function formatError(message: string, prefix?: string): string;
196
230
 
231
+ /**
232
+ * Validates a JWT `iat` claim against SDK age and clock-skew limits.
233
+ *
234
+ * @param options - Validation options.
235
+ * @param options.iat - Issued-at timestamp in seconds.
236
+ * @param options.now - Optional current date, defaults to the current time.
237
+ * @throws {Error} If `iat` is too old or too far in the future.
238
+ */
197
239
  declare function verifyJwtIatOrThrow(options: {
198
240
  iat: number;
199
241
  now?: Date;
200
242
  }): void;
201
243
 
202
- export { type BaseSchema, CLOCK_SKEW_TOLERANCE_SECONDS, CONTENT_TYPES, type FetchHeaders, HEADERS, type HttpMethod, IoWalletSdkConfig, type IoWalletSdkConfigOptions, ItWalletSpecsVersion, ItWalletSpecsVersionError, type ItwSupportedSignatureAlg, MAX_IAT_AGE_SECONDS, type RequestLike, UnexpectedStatusCodeError, ValidationError, formatError, formatZodError, hasConfigVersion, hasStatusOrThrow, parseRawHttpResponse, parseWithErrorHandling, serializeAttrs, verifyJwtIatOrThrow, zHttpMethod, zItwSupportedSignatureAlg };
244
+ interface VersionedOptions {
245
+ config: {
246
+ itWalletSpecsVersion: ItWalletSpecsVersion;
247
+ };
248
+ }
249
+ /**
250
+ * Creates a version-aware dispatcher that routes a function call
251
+ * based on options.config.itWalletSpecsVersion.
252
+ *
253
+ * All versions declared in `ItWalletSpecsVersion` must be provided
254
+ * (`Required` contract). Adding a new spec version therefore requires
255
+ * updating every `createVersionDispatcher` call site. This is an
256
+ * intentional trade-off: compile-time exhaustiveness is preferred over
257
+ * sparse-map flexibility.
258
+ *
259
+ * @param handlers - Map of version → handler function
260
+ * @returns Dispatcher function that invokes the handler for `options.config.itWalletSpecsVersion`.
261
+ * @throws {ItWalletSpecsVersionError} If no handler is registered for the configured version.
262
+ */
263
+ declare function createVersionDispatcher<TOptions extends VersionedOptions, TResult>(handlers: Required<Record<ItWalletSpecsVersion, (options: TOptions) => TResult>>): (options: TOptions) => TResult;
264
+ /**
265
+ * Dispatches by a bare version value (no options object needed).
266
+ *
267
+ * @param version - The version to dispatch on
268
+ * @param handlers - Map of version → zero-argument handler function
269
+ * @returns Result returned by the selected version handler.
270
+ * @throws {ItWalletSpecsVersionError} If no handler is registered for the version.
271
+ */
272
+ declare function dispatchByVersion<TResult>(version: ItWalletSpecsVersion, handlers: Required<Record<ItWalletSpecsVersion, () => TResult>>): TResult;
273
+
274
+ export { type BaseSchema, CLOCK_SKEW_TOLERANCE_SECONDS, CONTENT_TYPES, type FetchHeaders, HEADERS, type HttpMethod, IoWalletSdkConfig, type IoWalletSdkConfigOptions, ItWalletSpecsVersion, ItWalletSpecsVersionError, type ItwSupportedSignatureAlg, MAX_IAT_AGE_SECONDS, type RequestLike, UnexpectedStatusCodeError, ValidationError, type VersionedOptions, createVersionDispatcher, dispatchByVersion, formatError, formatZodError, hasConfigVersion, hasStatusOrThrow, parseRawHttpResponse, parseWithErrorHandling, serializeAttrs, verifyJwtIatOrThrow, zHttpMethod, zItwSupportedSignatureAlg };
package/dist/index.d.ts CHANGED
@@ -55,6 +55,12 @@ declare function hasConfigVersion<T extends WithConfig, V extends ItWalletSpecsV
55
55
  */
56
56
  declare class IoWalletSdkConfig<V extends ItWalletSpecsVersion = ItWalletSpecsVersion> {
57
57
  readonly itWalletSpecsVersion: V;
58
+ /**
59
+ * Creates an SDK configuration for a specific IT-Wallet specification version.
60
+ *
61
+ * @param options - Configuration options.
62
+ * @param options.itWalletSpecsVersion - IT-Wallet specification version to use.
63
+ */
58
64
  constructor(options: IoWalletSdkConfigOptions<V>);
59
65
  /**
60
66
  * Type guard for version checking
@@ -135,11 +141,20 @@ declare class ItWalletSpecsVersionError extends Error {
135
141
  readonly code = "IT_WALLET_SPECS_VERSION_ERROR";
136
142
  constructor(feature: string, requestedVersion: string, supportedVersions: readonly string[]);
137
143
  }
144
+ /**
145
+ * Error thrown when runtime validation fails.
146
+ */
138
147
  declare class ValidationError extends Error {
139
148
  zodError: ZodError | undefined;
140
149
  constructor(message: string, zodError?: z.ZodError);
141
150
  }
142
151
 
152
+ /**
153
+ * Formats a Zod error into a readable multi-line message.
154
+ *
155
+ * @param error - Optional Zod error to format.
156
+ * @returns Empty string when no error is provided, otherwise a formatted issue list.
157
+ */
143
158
  declare function formatZodError(error?: z$1.ZodError): string;
144
159
 
145
160
  /**
@@ -152,6 +167,9 @@ declare function formatZodError(error?: z$1.ZodError): string;
152
167
  declare const hasStatusOrThrow: (status: number | number[], customError?: typeof UnexpectedStatusCodeError) => (res: Response) => Promise<Response>;
153
168
  /**
154
169
  * Utility function to parse a raw HTTP response as JSON if supported, otherwise as text.
170
+ *
171
+ * @param response - Raw HTTP response to parse.
172
+ * @returns Parsed JSON for JSON responses, otherwise response text.
155
173
  */
156
174
  declare const parseRawHttpResponse: <T extends Record<string, unknown>>(response: Response) => Promise<T> | Promise<string>;
157
175
 
@@ -191,12 +209,66 @@ interface RequestLike {
191
209
  }
192
210
 
193
211
  type BaseSchema = z.ZodTypeAny;
212
+ /**
213
+ * Parses data with a Zod schema and throws the SDK `ValidationError` on failure.
214
+ *
215
+ * @param schema - Zod schema used for validation.
216
+ * @param data - Unknown value to parse.
217
+ * @param customErrorMessage - Optional error message used when validation fails.
218
+ * @returns Parsed schema output.
219
+ * @throws {ValidationError} If the value does not satisfy the provided schema.
220
+ */
194
221
  declare function parseWithErrorHandling<Schema extends BaseSchema>(schema: Schema, data: unknown, customErrorMessage?: string): z.infer<Schema>;
222
+ /**
223
+ * Prefixes an error message with optional contextual text.
224
+ *
225
+ * @param message - Base error message.
226
+ * @param prefix - Optional prefix to prepend.
227
+ * @returns Formatted error message.
228
+ */
195
229
  declare function formatError(message: string, prefix?: string): string;
196
230
 
231
+ /**
232
+ * Validates a JWT `iat` claim against SDK age and clock-skew limits.
233
+ *
234
+ * @param options - Validation options.
235
+ * @param options.iat - Issued-at timestamp in seconds.
236
+ * @param options.now - Optional current date, defaults to the current time.
237
+ * @throws {Error} If `iat` is too old or too far in the future.
238
+ */
197
239
  declare function verifyJwtIatOrThrow(options: {
198
240
  iat: number;
199
241
  now?: Date;
200
242
  }): void;
201
243
 
202
- export { type BaseSchema, CLOCK_SKEW_TOLERANCE_SECONDS, CONTENT_TYPES, type FetchHeaders, HEADERS, type HttpMethod, IoWalletSdkConfig, type IoWalletSdkConfigOptions, ItWalletSpecsVersion, ItWalletSpecsVersionError, type ItwSupportedSignatureAlg, MAX_IAT_AGE_SECONDS, type RequestLike, UnexpectedStatusCodeError, ValidationError, formatError, formatZodError, hasConfigVersion, hasStatusOrThrow, parseRawHttpResponse, parseWithErrorHandling, serializeAttrs, verifyJwtIatOrThrow, zHttpMethod, zItwSupportedSignatureAlg };
244
+ interface VersionedOptions {
245
+ config: {
246
+ itWalletSpecsVersion: ItWalletSpecsVersion;
247
+ };
248
+ }
249
+ /**
250
+ * Creates a version-aware dispatcher that routes a function call
251
+ * based on options.config.itWalletSpecsVersion.
252
+ *
253
+ * All versions declared in `ItWalletSpecsVersion` must be provided
254
+ * (`Required` contract). Adding a new spec version therefore requires
255
+ * updating every `createVersionDispatcher` call site. This is an
256
+ * intentional trade-off: compile-time exhaustiveness is preferred over
257
+ * sparse-map flexibility.
258
+ *
259
+ * @param handlers - Map of version → handler function
260
+ * @returns Dispatcher function that invokes the handler for `options.config.itWalletSpecsVersion`.
261
+ * @throws {ItWalletSpecsVersionError} If no handler is registered for the configured version.
262
+ */
263
+ declare function createVersionDispatcher<TOptions extends VersionedOptions, TResult>(handlers: Required<Record<ItWalletSpecsVersion, (options: TOptions) => TResult>>): (options: TOptions) => TResult;
264
+ /**
265
+ * Dispatches by a bare version value (no options object needed).
266
+ *
267
+ * @param version - The version to dispatch on
268
+ * @param handlers - Map of version → zero-argument handler function
269
+ * @returns Result returned by the selected version handler.
270
+ * @throws {ItWalletSpecsVersionError} If no handler is registered for the version.
271
+ */
272
+ declare function dispatchByVersion<TResult>(version: ItWalletSpecsVersion, handlers: Required<Record<ItWalletSpecsVersion, () => TResult>>): TResult;
273
+
274
+ export { type BaseSchema, CLOCK_SKEW_TOLERANCE_SECONDS, CONTENT_TYPES, type FetchHeaders, HEADERS, type HttpMethod, IoWalletSdkConfig, type IoWalletSdkConfigOptions, ItWalletSpecsVersion, ItWalletSpecsVersionError, type ItwSupportedSignatureAlg, MAX_IAT_AGE_SECONDS, type RequestLike, UnexpectedStatusCodeError, ValidationError, type VersionedOptions, createVersionDispatcher, dispatchByVersion, formatError, formatZodError, hasConfigVersion, hasStatusOrThrow, parseRawHttpResponse, parseWithErrorHandling, serializeAttrs, verifyJwtIatOrThrow, zHttpMethod, zItwSupportedSignatureAlg };
package/dist/index.js CHANGED
@@ -45,10 +45,12 @@ __export(index_exports, {
45
45
  addSecondsToDate: () => import_utils.addSecondsToDate,
46
46
  calculateJwkThumbprint: () => import_oauth2.calculateJwkThumbprint,
47
47
  createFetcher: () => import_utils.createFetcher,
48
+ createVersionDispatcher: () => createVersionDispatcher,
48
49
  dateToSeconds: () => import_utils.dateToSeconds,
49
50
  decodeBase64: () => import_utils.decodeBase64,
50
51
  decodeJwt: () => import_oauth2.decodeJwt,
51
52
  decodeUtf8String: () => import_utils.decodeUtf8String,
53
+ dispatchByVersion: () => dispatchByVersion,
52
54
  encodeToBase64Url: () => import_utils.encodeToBase64Url,
53
55
  encodeToUtf8String: () => import_utils.encodeToUtf8String,
54
56
  formatError: () => formatError,
@@ -80,6 +82,12 @@ function hasConfigVersion(options, version) {
80
82
  }
81
83
  var IoWalletSdkConfig = class {
82
84
  itWalletSpecsVersion;
85
+ /**
86
+ * Creates an SDK configuration for a specific IT-Wallet specification version.
87
+ *
88
+ * @param options - Configuration options.
89
+ * @param options.itWalletSpecsVersion - IT-Wallet specification version to use.
90
+ */
83
91
  constructor(options) {
84
92
  this.itWalletSpecsVersion = options.itWalletSpecsVersion;
85
93
  }
@@ -303,6 +311,33 @@ function verifyJwtIatOrThrow(options) {
303
311
  }
304
312
  }
305
313
 
314
+ // src/version-dispatcher.ts
315
+ function createVersionDispatcher(handlers) {
316
+ return (options) => {
317
+ const version = options.config.itWalletSpecsVersion;
318
+ const handler = handlers[version];
319
+ if (typeof handler !== "function") {
320
+ throw new ItWalletSpecsVersionError(
321
+ "version-dispatcher",
322
+ version,
323
+ Object.keys(handlers)
324
+ );
325
+ }
326
+ return handler(options);
327
+ };
328
+ }
329
+ function dispatchByVersion(version, handlers) {
330
+ const handler = handlers[version];
331
+ if (typeof handler !== "function") {
332
+ throw new ItWalletSpecsVersionError(
333
+ "version-dispatcher",
334
+ version,
335
+ Object.keys(handlers)
336
+ );
337
+ }
338
+ return handler();
339
+ }
340
+
306
341
  // src/index.ts
307
342
  var import_oauth2 = require("@openid4vc/oauth2");
308
343
  var import_utils = require("@openid4vc/utils");
@@ -323,10 +358,12 @@ var import_utils = require("@openid4vc/utils");
323
358
  addSecondsToDate,
324
359
  calculateJwkThumbprint,
325
360
  createFetcher,
361
+ createVersionDispatcher,
326
362
  dateToSeconds,
327
363
  decodeBase64,
328
364
  decodeJwt,
329
365
  decodeUtf8String,
366
+ dispatchByVersion,
330
367
  encodeToBase64Url,
331
368
  encodeToUtf8String,
332
369
  formatError,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/config.ts","../src/constants.ts","../src/errors/parse.ts","../src/errors/errors.ts","../src/fetcher.ts","../src/parse.ts","../src/validation.ts","../src/verify.ts"],"sourcesContent":["export * from \"./config\";\nexport * from \"./constants\";\nexport * from \"./errors/errors\";\nexport * from \"./errors/parse\";\nexport * from \"./fetcher\";\nexport type * from \"./globals\";\nexport * from \"./parse\";\nexport * from \"./validation\";\nexport * from \"./verify\";\n\nexport {\n type CallbackContext,\n HashAlgorithm,\n type HashCallback,\n type JwtSignerJwk,\n calculateJwkThumbprint,\n decodeJwt,\n} from \"@openid4vc/oauth2\";\n\nexport {\n ContentType,\n type Fetch,\n JsonParseError,\n addSecondsToDate,\n createFetcher,\n dateToSeconds,\n decodeBase64,\n decodeUtf8String,\n encodeToBase64Url,\n encodeToUtf8String,\n objectToQueryParams,\n parseIfJson,\n setGlobalConfig,\n stringToJsonWithErrorHandling,\n} from \"@openid4vc/utils\";\n","/**\n * Supported versions of the Italian Wallet technical specifications\n */\nexport enum ItWalletSpecsVersion {\n V1_0 = \"V1_0\",\n V1_3 = \"V1_3\",\n V1_4 = \"V1_4\",\n}\n\n/**\n * Configuration options for the IO Wallet SDK\n */\nexport interface IoWalletSdkConfigOptions<\n V extends ItWalletSpecsVersion = ItWalletSpecsVersion,\n> {\n /**\n * The version of the Italian Wallet specification to use.\n * REQUIRED - must be explicitly set by the user.\n *\n * @example\n * const config = new IoWalletSdkConfig({ itWalletSpecsVersion: ItWalletSpecsVersion.V1_3 });\n */\n itWalletSpecsVersion: V;\n}\n\ninterface WithConfig {\n config: IoWalletSdkConfig;\n}\n\ntype WithConfigVersion<\n T extends WithConfig,\n V extends ItWalletSpecsVersion,\n> = T extends { config: IoWalletSdkConfig<V> } ? T : never;\n\n/**\n * Type guard to check if the provided options have a specific config version\n *\n * @param options - The options object containing the config to check\n * @param version - The version to check against\n * @returns True if the options' config version matches the provided version\n */\nexport function hasConfigVersion<\n T extends WithConfig,\n V extends ItWalletSpecsVersion,\n>(options: T, version: V): options is WithConfigVersion<T, V> {\n return options.config.itWalletSpecsVersion === version;\n}\n\n/**\n * Configuration class for the IO Wallet SDK\n *\n * This class manages the version of the Italian Wallet technical specifications\n * to use throughout the SDK. The version determines the format of credential\n * requests and responses.\n *\n * @example Basic usage\n * const config = new IoWalletSdkConfig({ itWalletSpecsVersion: ItWalletSpecsVersion.V1_0 });\n * console.log(config.itWalletSpecsVersion); // ItWalletSpecsVersion.V1_0\n *\n * @example Type guard usage\n * if (config.isVersion(ItWalletSpecsVersion.V1_3)) {\n * // TypeScript narrows config.itWalletSpecsVersion to ItWalletSpecsVersion.V1_3\n * }\n */\nexport class IoWalletSdkConfig<\n V extends ItWalletSpecsVersion = ItWalletSpecsVersion,\n> {\n public readonly itWalletSpecsVersion: V;\n\n constructor(options: IoWalletSdkConfigOptions<V>) {\n this.itWalletSpecsVersion = options.itWalletSpecsVersion;\n }\n\n /**\n * Type guard for version checking\n *\n * @param version - The version to check against\n * @returns True if the config's version matches the provided version\n *\n * @internal\n */\n isVersion<W extends ItWalletSpecsVersion>(\n version: W,\n ): this is IoWalletSdkConfig<W> {\n const currentVersion: ItWalletSpecsVersion = this.itWalletSpecsVersion;\n return currentVersion === version;\n }\n}\n","/**\n * HTTP Content-Type constants for OAuth2 requests\n */\nexport const CONTENT_TYPES = {\n FORM_URLENCODED: \"application/x-www-form-urlencoded\",\n JSON: \"application/json\",\n} as const;\n\n/**\n * HTTP Header constants\n */\nexport const HEADERS = {\n AUTHORIZATION: \"Authorization\",\n CONTENT_TYPE: \"Content-Type\",\n DPOP: \"DPoP\",\n OAUTH_CLIENT_ATTESTATION: \"OAuth-Client-Attestation\",\n OAUTH_CLIENT_ATTESTATION_POP: \"OAuth-Client-Attestation-PoP\",\n} as const;\n\nexport const MAX_IAT_AGE_SECONDS = 5 * 60;\nexport const CLOCK_SKEW_TOLERANCE_SECONDS = 60;\n","import type z from \"zod\";\n\n/**\n * Some code comes from `zod-validation-error` package (MIT License) and\n * was slightly simplified to fit our needs.\n */\nconst constants = {\n identifierRegex: /[$_\\p{ID_Start}][$\\u200c\\u200d\\p{ID_Continue}]*/u,\n issueSeparator: \"\\n\\t- \",\n unionSeparator: \", or \",\n};\n\nfunction escapeQuotes(str: string): string {\n return str.replace(/\\\\/g, \"\\\\\\\\\").replace(/\"/g, '\\\\\"');\n}\n\ntype ZodIssue = z.ZodError[\"issues\"][number];\n\nfunction joinPath(path: PropertyKey[]): string {\n if (path.length === 1 && path[0] !== undefined) {\n return String(path[0]);\n }\n\n return path.reduce<string>((acc, item) => {\n // handle numeric indices\n if (typeof item === \"number\") {\n return `${acc}[${item.toString()}]`;\n }\n\n if (typeof item === \"symbol\") {\n return `${acc}[${JSON.stringify(String(item))}]`;\n }\n\n // handle quoted values\n if (item.includes('\"')) {\n return `${acc}[\"${escapeQuotes(item)}\"]`;\n }\n\n // handle special characters\n if (!constants.identifierRegex.test(item)) {\n return `${acc}[\"${item}\"]`;\n }\n\n // handle normal values\n const separator = acc.length === 0 ? \"\" : \".\";\n return acc + separator + item;\n }, \"\");\n}\nfunction getMessageFromZodIssue(issue: ZodIssue): string {\n if (issue.code === \"invalid_union\") {\n return getMessageFromUnionErrors(issue.errors);\n }\n\n if (issue.path.length !== 0) {\n // handle array indices\n if (issue.path.length === 1) {\n const identifier = issue.path[0];\n\n if (typeof identifier === \"number\") {\n return `${issue.message} at index ${identifier}`;\n }\n }\n\n return `${issue.message} at \"${joinPath(issue.path)}\"`;\n }\n\n return issue.message;\n}\n\nfunction getMessageFromUnionErrors(unionErrors: ZodIssue[][]): string {\n return unionErrors\n .reduce<string[]>((acc, issues) => {\n const newIssues = issues\n .map((issue) => getMessageFromZodIssue(issue))\n .join(constants.issueSeparator);\n\n if (!acc.includes(newIssues)) acc.push(newIssues);\n\n return acc;\n }, [])\n .join(constants.unionSeparator);\n}\n\nexport function formatZodError(error?: z.ZodError): string {\n if (!error) return \"\";\n\n return `\\t- ${error?.issues.map((issue) => getMessageFromZodIssue(issue)).join(constants.issueSeparator)}`;\n}\n","import type { ZodError, z } from \"zod\";\n\nimport { formatZodError } from \"./parse\";\n\n// An error reason that supports both a string and a generic JSON object\ntype GenericErrorReason = Record<string, unknown> | string;\n\n/**\n * utility to format a set of attributes into an error message string\n *\n * @example\n * // returns \"foo=value bar=(list, item)\"\n * serializeAttrs({ foo: \"value\", bar: [\"list\", \"item\"] })\n *\n * @param attrs A key value record set\n * @returns a human-readable serialization of the set\n */\nexport const serializeAttrs = (\n attrs: Record<string, GenericErrorReason | number | string[] | undefined>,\n): string =>\n Object.entries(attrs)\n .filter(([, v]) => v !== undefined)\n .map(([k, v]) => {\n if (Array.isArray(v)) return [k, `(${v.join(\", \")})`];\n if (typeof v !== \"string\") return [k, JSON.stringify(v)];\n return [k, v];\n })\n .map((_) => _.join(\"=\"))\n .join(\" \");\n\n/**\n * An error subclass thrown when an HTTP request has a status code different from the one expected.\n */\nexport class UnexpectedStatusCodeError extends Error {\n code = \"ERR_UNEXPECTED_STATUS_CODE\";\n reason: GenericErrorReason;\n statusCode: number;\n\n constructor({\n message,\n reason,\n statusCode,\n }: {\n message: string;\n reason: GenericErrorReason;\n statusCode: number;\n }) {\n super(serializeAttrs({ message, reason, statusCode }));\n this.reason = reason;\n this.statusCode = statusCode;\n }\n}\n\n/**\n * An error subclass thrown when an unsupported Italian Wallet specification version is requested.\n *\n * This error is thrown when:\n * - A feature or method is called with a version that it doesn't support\n * - An invalid version identifier is provided\n *\n * @example\n * throw new ItWalletSpecsVersionError(\n * 'createCredentialRequest',\n * '2.0.0',\n * [ItWalletSpecsVersion.V1_0, ItWalletSpecsVersion.V1_3]\n * );\n * // Error: Feature \"createCredentialRequest\" does not support version 2.0.0.\n * // Supported versions: V1_0, V1_3\n */\nexport class ItWalletSpecsVersionError extends Error {\n public readonly code = \"IT_WALLET_SPECS_VERSION_ERROR\";\n\n constructor(\n public readonly feature: string,\n public readonly requestedVersion: string,\n public readonly supportedVersions: readonly string[],\n ) {\n super(\n `Feature \"${feature}\" does not support version ${requestedVersion}.\\n` +\n `Supported versions: ${supportedVersions.join(\", \")}`,\n );\n this.name = \"ItWalletSpecsVersionError\";\n\n // Maintain proper stack trace for V8 engines (Node.js, Chrome)\n const ErrorConstructor = Error as {\n captureStackTrace?: (target: object, constructor: unknown) => void;\n };\n if (typeof ErrorConstructor.captureStackTrace === \"function\") {\n ErrorConstructor.captureStackTrace(this, ItWalletSpecsVersionError);\n }\n }\n}\n\nexport class ValidationError extends Error {\n public zodError: ZodError | undefined;\n\n constructor(message: string, zodError?: z.ZodError) {\n super(message);\n\n const formattedError = formatZodError(zodError);\n this.message = `${message}\\n${formattedError}`;\n\n Object.defineProperty(this, \"zodError\", {\n enumerable: false,\n value: zodError,\n writable: false,\n });\n }\n}\n","import { UnexpectedStatusCodeError } from \"./errors/errors\";\n\n/**\n * Check if a response is in the expected status, otherwise throw an error\n * @param status - The expected status\n * @param customError - A custom error compatible with {@link UnexpectedStatusCodeError}\n * @throws UnexpectedStatusCodeError if the status is different from the one expected\n * @returns The given response object\n */\nexport const hasStatusOrThrow =\n (status: number | number[], customError?: typeof UnexpectedStatusCodeError) =>\n async (res: Response): Promise<Response> => {\n if (\n Array.isArray(status)\n ? !status.includes(res.status)\n : res.status !== status\n ) {\n const ErrorClass = customError ?? UnexpectedStatusCodeError;\n throw new ErrorClass({\n message: `Http request failed. Expected ${status}, got ${res.status}, url: ${res.url}`,\n reason: await parseRawHttpResponse(res), // Pass the response body as reason so the original error can surface\n statusCode: res.status,\n });\n }\n return res;\n };\n\n/**\n * Utility function to parse a raw HTTP response as JSON if supported, otherwise as text.\n */\nexport const parseRawHttpResponse = <T extends Record<string, unknown>>(\n response: Response,\n) =>\n response.headers.get(\"content-type\")?.includes(\"application/json\")\n ? (response.json() as Promise<T>)\n : response.text();\n","import { z } from \"zod\";\n\nimport { ValidationError } from \"./errors/errors\";\n\nexport type BaseSchema = z.ZodTypeAny;\n\nconst SAFE_STRINGIFY_MAX_LENGTH = 200;\n\nfunction safeStringify(value: unknown): string {\n try {\n const result = JSON.stringify(value, (_key, val) =>\n typeof val === \"bigint\" ? `[BigInt: ${val}]` : val,\n );\n if (result === undefined) {\n return String(value);\n }\n return result.length > SAFE_STRINGIFY_MAX_LENGTH\n ? `${result.slice(0, SAFE_STRINGIFY_MAX_LENGTH)}…`\n : result;\n } catch {\n return \"[unserializable]\";\n }\n}\n\nexport function parseWithErrorHandling<Schema extends BaseSchema>(\n schema: Schema,\n data: unknown,\n customErrorMessage?: string,\n): z.infer<Schema> {\n const parseResult = schema.safeParse(data);\n\n if (!parseResult.success) {\n throw new ValidationError(\n customErrorMessage ??\n `Error validating schema with data ${safeStringify(data)}`,\n parseResult.error,\n );\n }\n\n return parseResult.data;\n}\n\nexport function formatError(message: string, prefix?: string): string {\n return prefix ? `${prefix} ${message}` : message;\n}\n","import z from \"zod\";\n\n/**\n * For the moment, these are all the supported algorithms in both\n * {@link https://italia.github.io/eid-wallet-it-docs/releases/1.3.3/en/algorithms.html#cryptographic-algorithms|v1.3.3} and\n * {@link https://italia.github.io/eid-wallet-it-docs/releases/1.0.2/en/algorithms.html#cryptographic-algorithms|v1.0.2},\n * and in both specifications the `alg` field MUST be one of those values.\n */\nexport const zItwSupportedSignatureAlg = z.enum([\n \"ES256\",\n \"ES384\",\n \"ES512\",\n \"PS256\",\n \"PS384\",\n \"PS512\",\n]);\nexport type ItwSupportedSignatureAlg = z.infer<\n typeof zItwSupportedSignatureAlg\n>;\n\nexport const zHttpMethod = z.enum([\n \"GET\",\n \"POST\",\n \"PUT\",\n \"DELETE\",\n \"HEAD\",\n \"OPTIONS\",\n \"TRACE\",\n \"CONNECT\",\n \"PATCH\",\n]);\nexport type HttpMethod = z.infer<typeof zHttpMethod>;\n","import { CLOCK_SKEW_TOLERANCE_SECONDS, MAX_IAT_AGE_SECONDS } from \"./constants\";\n\nexport function verifyJwtIatOrThrow(options: { iat: number; now?: Date }) {\n const now = options.now ?? new Date();\n const nowSeconds = Math.floor(now.getTime() / 1000);\n\n if (nowSeconds - options.iat > MAX_IAT_AGE_SECONDS) {\n throw new Error(\"iat claim in JWT is too old (must be within 5 minutes)\");\n }\n\n if (options.iat - nowSeconds > CLOCK_SKEW_TOLERANCE_SECONDS) {\n throw new Error(\"iat claim in JWT is too far in the future\");\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,IAAK,uBAAL,kBAAKA,0BAAL;AACL,EAAAA,sBAAA,UAAO;AACP,EAAAA,sBAAA,UAAO;AACP,EAAAA,sBAAA,UAAO;AAHG,SAAAA;AAAA,GAAA;AAsCL,SAAS,iBAGd,SAAY,SAAgD;AAC5D,SAAO,QAAQ,OAAO,yBAAyB;AACjD;AAkBO,IAAM,oBAAN,MAEL;AAAA,EACgB;AAAA,EAEhB,YAAY,SAAsC;AAChD,SAAK,uBAAuB,QAAQ;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,UACE,SAC8B;AAC9B,UAAM,iBAAuC,KAAK;AAClD,WAAO,mBAAmB;AAAA,EAC5B;AACF;;;ACpFO,IAAM,gBAAgB;AAAA,EAC3B,iBAAiB;AAAA,EACjB,MAAM;AACR;AAKO,IAAM,UAAU;AAAA,EACrB,eAAe;AAAA,EACf,cAAc;AAAA,EACd,MAAM;AAAA,EACN,0BAA0B;AAAA,EAC1B,8BAA8B;AAChC;AAEO,IAAM,sBAAsB,IAAI;AAChC,IAAM,+BAA+B;;;ACd5C,IAAM,YAAY;AAAA,EAChB,iBAAiB;AAAA,EACjB,gBAAgB;AAAA,EAChB,gBAAgB;AAClB;AAEA,SAAS,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ACrB;AACA,WAAO,OAAO,SAAS,4BACnB,GAAG,OAAO,MAAM,GAAG,yBAAyB,CAAC,WAC7C;AAAA,EACN,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEO,SAAS,uBACd,QACA,MACA,oBACiB;AACjB,QAAM,cAAc,OAAO,UAAU,IAAI;AAEzC,MAAI,CAAC,YAAY,SAAS;AACxB,UAAM,IAAI;AAAA,MACR,sBACE,qCAAqC,cAAc,IAAI,CAAC;AAAA,MAC1D,YAAY;AAAA,IACd;AAAA,EACF;AAEA,SAAO,YAAY;AACrB;AAEO,SAAS,YAAY,SAAiB,QAAyB;AACpE,SAAO,SAAS,GAAG,MAAM,IAAI,OAAO,KAAK;AAC3C;;;AC5CA,iBAAc;AAQP,IAAM,4BAA4B,WAAAC,QAAE,KAAK;AAAA,EAC9C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAKM,IAAM,cAAc,WAAAA,QAAE,KAAK;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;;;AC5BM,SAAS,oBAAoB,SAAsC;AACxE,QAAM,MAAM,QAAQ,OAAO,oBAAI,KAAK;AACpC,QAAM,aAAa,KAAK,MAAM,IAAI,QAAQ,IAAI,GAAI;AAElD,MAAI,aAAa,QAAQ,MAAM,qBAAqB;AAClD,UAAM,IAAI,MAAM,wDAAwD;AAAA,EAC1E;AAEA,MAAI,QAAQ,MAAM,aAAa,8BAA8B;AAC3D,UAAM,IAAI,MAAM,2CAA2C;AAAA,EAC7D;AACF;;;ARHA,oBAOO;AAEP,mBAeO;","names":["ItWalletSpecsVersion","z"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/config.ts","../src/constants.ts","../src/errors/parse.ts","../src/errors/errors.ts","../src/fetcher.ts","../src/parse.ts","../src/validation.ts","../src/verify.ts","../src/version-dispatcher.ts"],"sourcesContent":["export * from \"./config\";\nexport * from \"./constants\";\nexport * from \"./errors/errors\";\nexport * from \"./errors/parse\";\nexport * from \"./fetcher\";\nexport type * from \"./globals\";\nexport * from \"./parse\";\nexport * from \"./validation\";\nexport * from \"./verify\";\nexport * from \"./version-dispatcher\";\n\nexport {\n type CallbackContext,\n HashAlgorithm,\n type HashCallback,\n type JwtSignerJwk,\n calculateJwkThumbprint,\n decodeJwt,\n} from \"@openid4vc/oauth2\";\n\nexport {\n ContentType,\n type Fetch,\n JsonParseError,\n addSecondsToDate,\n createFetcher,\n dateToSeconds,\n decodeBase64,\n decodeUtf8String,\n encodeToBase64Url,\n encodeToUtf8String,\n objectToQueryParams,\n parseIfJson,\n setGlobalConfig,\n stringToJsonWithErrorHandling,\n} from \"@openid4vc/utils\";\n","/**\n * Supported versions of the Italian Wallet technical specifications\n */\nexport enum ItWalletSpecsVersion {\n V1_0 = \"V1_0\",\n V1_3 = \"V1_3\",\n V1_4 = \"V1_4\",\n}\n\n/**\n * Configuration options for the IO Wallet SDK\n */\nexport interface IoWalletSdkConfigOptions<\n V extends ItWalletSpecsVersion = ItWalletSpecsVersion,\n> {\n /**\n * The version of the Italian Wallet specification to use.\n * REQUIRED - must be explicitly set by the user.\n *\n * @example\n * const config = new IoWalletSdkConfig({ itWalletSpecsVersion: ItWalletSpecsVersion.V1_3 });\n */\n itWalletSpecsVersion: V;\n}\n\ninterface WithConfig {\n config: IoWalletSdkConfig;\n}\n\ntype WithConfigVersion<\n T extends WithConfig,\n V extends ItWalletSpecsVersion,\n> = T extends { config: IoWalletSdkConfig<V> } ? T : never;\n\n/**\n * Type guard to check if the provided options have a specific config version\n *\n * @param options - The options object containing the config to check\n * @param version - The version to check against\n * @returns True if the options' config version matches the provided version\n */\nexport function hasConfigVersion<\n T extends WithConfig,\n V extends ItWalletSpecsVersion,\n>(options: T, version: V): options is WithConfigVersion<T, V> {\n return options.config.itWalletSpecsVersion === version;\n}\n\n/**\n * Configuration class for the IO Wallet SDK\n *\n * This class manages the version of the Italian Wallet technical specifications\n * to use throughout the SDK. The version determines the format of credential\n * requests and responses.\n *\n * @example Basic usage\n * const config = new IoWalletSdkConfig({ itWalletSpecsVersion: ItWalletSpecsVersion.V1_0 });\n * console.log(config.itWalletSpecsVersion); // ItWalletSpecsVersion.V1_0\n *\n * @example Type guard usage\n * if (config.isVersion(ItWalletSpecsVersion.V1_3)) {\n * // TypeScript narrows config.itWalletSpecsVersion to ItWalletSpecsVersion.V1_3\n * }\n */\nexport class IoWalletSdkConfig<\n V extends ItWalletSpecsVersion = ItWalletSpecsVersion,\n> {\n public readonly itWalletSpecsVersion: V;\n\n /**\n * Creates an SDK configuration for a specific IT-Wallet specification version.\n *\n * @param options - Configuration options.\n * @param options.itWalletSpecsVersion - IT-Wallet specification version to use.\n */\n constructor(options: IoWalletSdkConfigOptions<V>) {\n this.itWalletSpecsVersion = options.itWalletSpecsVersion;\n }\n\n /**\n * Type guard for version checking\n *\n * @param version - The version to check against\n * @returns True if the config's version matches the provided version\n *\n * @internal\n */\n isVersion<W extends ItWalletSpecsVersion>(\n version: W,\n ): this is IoWalletSdkConfig<W> {\n const currentVersion: ItWalletSpecsVersion = this.itWalletSpecsVersion;\n return currentVersion === version;\n }\n}\n","/**\n * HTTP Content-Type constants for OAuth2 requests\n */\nexport const CONTENT_TYPES = {\n FORM_URLENCODED: \"application/x-www-form-urlencoded\",\n JSON: \"application/json\",\n} as const;\n\n/**\n * HTTP Header constants\n */\nexport const HEADERS = {\n AUTHORIZATION: \"Authorization\",\n CONTENT_TYPE: \"Content-Type\",\n DPOP: \"DPoP\",\n OAUTH_CLIENT_ATTESTATION: \"OAuth-Client-Attestation\",\n OAUTH_CLIENT_ATTESTATION_POP: \"OAuth-Client-Attestation-PoP\",\n} as const;\n\nexport const MAX_IAT_AGE_SECONDS = 5 * 60;\nexport const CLOCK_SKEW_TOLERANCE_SECONDS = 60;\n","import type z from \"zod\";\n\n/**\n * Some code comes from `zod-validation-error` package (MIT License) and\n * was slightly simplified to fit our needs.\n */\nconst constants = {\n identifierRegex: /[$_\\p{ID_Start}][$\\u200c\\u200d\\p{ID_Continue}]*/u,\n issueSeparator: \"\\n\\t- \",\n unionSeparator: \", or \",\n};\n\nfunction escapeQuotes(str: string): string {\n return str.replace(/\\\\/g, \"\\\\\\\\\").replace(/\"/g, '\\\\\"');\n}\n\ntype ZodIssue = z.ZodError[\"issues\"][number];\n\nfunction joinPath(path: PropertyKey[]): string {\n if (path.length === 1 && path[0] !== undefined) {\n return String(path[0]);\n }\n\n return path.reduce<string>((acc, item) => {\n // handle numeric indices\n if (typeof item === \"number\") {\n return `${acc}[${item.toString()}]`;\n }\n\n if (typeof item === \"symbol\") {\n return `${acc}[${JSON.stringify(String(item))}]`;\n }\n\n // handle quoted values\n if (item.includes('\"')) {\n return `${acc}[\"${escapeQuotes(item)}\"]`;\n }\n\n // handle special characters\n if (!constants.identifierRegex.test(item)) {\n return `${acc}[\"${item}\"]`;\n }\n\n // handle normal values\n const separator = acc.length === 0 ? \"\" : \".\";\n return acc + separator + item;\n }, \"\");\n}\nfunction getMessageFromZodIssue(issue: ZodIssue): string {\n if (issue.code === \"invalid_union\") {\n return getMessageFromUnionErrors(issue.errors);\n }\n\n if (issue.path.length !== 0) {\n // handle array indices\n if (issue.path.length === 1) {\n const identifier = issue.path[0];\n\n if (typeof identifier === \"number\") {\n return `${issue.message} at index ${identifier}`;\n }\n }\n\n return `${issue.message} at \"${joinPath(issue.path)}\"`;\n }\n\n return issue.message;\n}\n\nfunction getMessageFromUnionErrors(unionErrors: ZodIssue[][]): string {\n return unionErrors\n .reduce<string[]>((acc, issues) => {\n const newIssues = issues\n .map((issue) => getMessageFromZodIssue(issue))\n .join(constants.issueSeparator);\n\n if (!acc.includes(newIssues)) acc.push(newIssues);\n\n return acc;\n }, [])\n .join(constants.unionSeparator);\n}\n\n/**\n * Formats a Zod error into a readable multi-line message.\n *\n * @param error - Optional Zod error to format.\n * @returns Empty string when no error is provided, otherwise a formatted issue list.\n */\nexport function formatZodError(error?: z.ZodError): string {\n if (!error) return \"\";\n\n return `\\t- ${error?.issues.map((issue) => getMessageFromZodIssue(issue)).join(constants.issueSeparator)}`;\n}\n","import type { ZodError, z } from \"zod\";\n\nimport { formatZodError } from \"./parse\";\n\n// An error reason that supports both a string and a generic JSON object\ntype GenericErrorReason = Record<string, unknown> | string;\n\n/**\n * utility to format a set of attributes into an error message string\n *\n * @example\n * // returns \"foo=value bar=(list, item)\"\n * serializeAttrs({ foo: \"value\", bar: [\"list\", \"item\"] })\n *\n * @param attrs A key value record set\n * @returns a human-readable serialization of the set\n */\nexport const serializeAttrs = (\n attrs: Record<string, GenericErrorReason | number | string[] | undefined>,\n): string =>\n Object.entries(attrs)\n .filter(([, v]) => v !== undefined)\n .map(([k, v]) => {\n if (Array.isArray(v)) return [k, `(${v.join(\", \")})`];\n if (typeof v !== \"string\") return [k, JSON.stringify(v)];\n return [k, v];\n })\n .map((_) => _.join(\"=\"))\n .join(\" \");\n\n/**\n * An error subclass thrown when an HTTP request has a status code different from the one expected.\n */\nexport class UnexpectedStatusCodeError extends Error {\n code = \"ERR_UNEXPECTED_STATUS_CODE\";\n reason: GenericErrorReason;\n statusCode: number;\n\n constructor({\n message,\n reason,\n statusCode,\n }: {\n message: string;\n reason: GenericErrorReason;\n statusCode: number;\n }) {\n super(serializeAttrs({ message, reason, statusCode }));\n this.reason = reason;\n this.statusCode = statusCode;\n }\n}\n\n/**\n * An error subclass thrown when an unsupported Italian Wallet specification version is requested.\n *\n * This error is thrown when:\n * - A feature or method is called with a version that it doesn't support\n * - An invalid version identifier is provided\n *\n * @example\n * throw new ItWalletSpecsVersionError(\n * 'createCredentialRequest',\n * '2.0.0',\n * [ItWalletSpecsVersion.V1_0, ItWalletSpecsVersion.V1_3]\n * );\n * // Error: Feature \"createCredentialRequest\" does not support version 2.0.0.\n * // Supported versions: V1_0, V1_3\n */\nexport class ItWalletSpecsVersionError extends Error {\n public readonly code = \"IT_WALLET_SPECS_VERSION_ERROR\";\n\n constructor(\n public readonly feature: string,\n public readonly requestedVersion: string,\n public readonly supportedVersions: readonly string[],\n ) {\n super(\n `Feature \"${feature}\" does not support version ${requestedVersion}.\\n` +\n `Supported versions: ${supportedVersions.join(\", \")}`,\n );\n this.name = \"ItWalletSpecsVersionError\";\n\n // Maintain proper stack trace for V8 engines (Node.js, Chrome)\n const ErrorConstructor = Error as {\n captureStackTrace?: (target: object, constructor: unknown) => void;\n };\n if (typeof ErrorConstructor.captureStackTrace === \"function\") {\n ErrorConstructor.captureStackTrace(this, ItWalletSpecsVersionError);\n }\n }\n}\n\n/**\n * Error thrown when runtime validation fails.\n */\nexport class ValidationError extends Error {\n public zodError: ZodError | undefined;\n\n constructor(message: string, zodError?: z.ZodError) {\n super(message);\n\n const formattedError = formatZodError(zodError);\n this.message = `${message}\\n${formattedError}`;\n\n Object.defineProperty(this, \"zodError\", {\n enumerable: false,\n value: zodError,\n writable: false,\n });\n }\n}\n","import { UnexpectedStatusCodeError } from \"./errors/errors\";\n\n/**\n * Check if a response is in the expected status, otherwise throw an error\n * @param status - The expected status\n * @param customError - A custom error compatible with {@link UnexpectedStatusCodeError}\n * @throws UnexpectedStatusCodeError if the status is different from the one expected\n * @returns The given response object\n */\nexport const hasStatusOrThrow =\n (status: number | number[], customError?: typeof UnexpectedStatusCodeError) =>\n async (res: Response): Promise<Response> => {\n if (\n Array.isArray(status)\n ? !status.includes(res.status)\n : res.status !== status\n ) {\n const ErrorClass = customError ?? UnexpectedStatusCodeError;\n throw new ErrorClass({\n message: `Http request failed. Expected ${status}, got ${res.status}, url: ${res.url}`,\n reason: await parseRawHttpResponse(res), // Pass the response body as reason so the original error can surface\n statusCode: res.status,\n });\n }\n return res;\n };\n\n/**\n * Utility function to parse a raw HTTP response as JSON if supported, otherwise as text.\n *\n * @param response - Raw HTTP response to parse.\n * @returns Parsed JSON for JSON responses, otherwise response text.\n */\nexport const parseRawHttpResponse = <T extends Record<string, unknown>>(\n response: Response,\n) =>\n response.headers.get(\"content-type\")?.includes(\"application/json\")\n ? (response.json() as Promise<T>)\n : response.text();\n","import { z } from \"zod\";\n\nimport { ValidationError } from \"./errors/errors\";\n\nexport type BaseSchema = z.ZodTypeAny;\n\nconst SAFE_STRINGIFY_MAX_LENGTH = 200;\n\nfunction safeStringify(value: unknown): string {\n try {\n const result = JSON.stringify(value, (_key, val) =>\n typeof val === \"bigint\" ? `[BigInt: ${val}]` : val,\n );\n if (result === undefined) {\n return String(value);\n }\n return result.length > SAFE_STRINGIFY_MAX_LENGTH\n ? `${result.slice(0, SAFE_STRINGIFY_MAX_LENGTH)}…`\n : result;\n } catch {\n return \"[unserializable]\";\n }\n}\n\n/**\n * Parses data with a Zod schema and throws the SDK `ValidationError` on failure.\n *\n * @param schema - Zod schema used for validation.\n * @param data - Unknown value to parse.\n * @param customErrorMessage - Optional error message used when validation fails.\n * @returns Parsed schema output.\n * @throws {ValidationError} If the value does not satisfy the provided schema.\n */\nexport function parseWithErrorHandling<Schema extends BaseSchema>(\n schema: Schema,\n data: unknown,\n customErrorMessage?: string,\n): z.infer<Schema> {\n const parseResult = schema.safeParse(data);\n\n if (!parseResult.success) {\n throw new ValidationError(\n customErrorMessage ??\n `Error validating schema with data ${safeStringify(data)}`,\n parseResult.error,\n );\n }\n\n return parseResult.data;\n}\n\n/**\n * Prefixes an error message with optional contextual text.\n *\n * @param message - Base error message.\n * @param prefix - Optional prefix to prepend.\n * @returns Formatted error message.\n */\nexport function formatError(message: string, prefix?: string): string {\n return prefix ? `${prefix} ${message}` : message;\n}\n","import z from \"zod\";\n\n/**\n * For the moment, these are all the supported algorithms in both\n * {@link https://italia.github.io/eid-wallet-it-docs/releases/1.3.3/en/algorithms.html#cryptographic-algorithms|v1.3.3} and\n * {@link https://italia.github.io/eid-wallet-it-docs/releases/1.0.2/en/algorithms.html#cryptographic-algorithms|v1.0.2},\n * and in both specifications the `alg` field MUST be one of those values.\n */\nexport const zItwSupportedSignatureAlg = z.enum([\n \"ES256\",\n \"ES384\",\n \"ES512\",\n \"PS256\",\n \"PS384\",\n \"PS512\",\n]);\nexport type ItwSupportedSignatureAlg = z.infer<\n typeof zItwSupportedSignatureAlg\n>;\n\nexport const zHttpMethod = z.enum([\n \"GET\",\n \"POST\",\n \"PUT\",\n \"DELETE\",\n \"HEAD\",\n \"OPTIONS\",\n \"TRACE\",\n \"CONNECT\",\n \"PATCH\",\n]);\nexport type HttpMethod = z.infer<typeof zHttpMethod>;\n","import { CLOCK_SKEW_TOLERANCE_SECONDS, MAX_IAT_AGE_SECONDS } from \"./constants\";\n\n/**\n * Validates a JWT `iat` claim against SDK age and clock-skew limits.\n *\n * @param options - Validation options.\n * @param options.iat - Issued-at timestamp in seconds.\n * @param options.now - Optional current date, defaults to the current time.\n * @throws {Error} If `iat` is too old or too far in the future.\n */\nexport function verifyJwtIatOrThrow(options: { iat: number; now?: Date }) {\n const now = options.now ?? new Date();\n const nowSeconds = Math.floor(now.getTime() / 1000);\n\n if (nowSeconds - options.iat > MAX_IAT_AGE_SECONDS) {\n throw new Error(\"iat claim in JWT is too old (must be within 5 minutes)\");\n }\n\n if (options.iat - nowSeconds > CLOCK_SKEW_TOLERANCE_SECONDS) {\n throw new Error(\"iat claim in JWT is too far in the future\");\n }\n}\n","import { ItWalletSpecsVersion } from \"./config\";\nimport { ItWalletSpecsVersionError } from \"./errors/errors\";\n\nexport interface VersionedOptions {\n config: { itWalletSpecsVersion: ItWalletSpecsVersion };\n}\n\n/**\n * Creates a version-aware dispatcher that routes a function call\n * based on options.config.itWalletSpecsVersion.\n *\n * All versions declared in `ItWalletSpecsVersion` must be provided\n * (`Required` contract). Adding a new spec version therefore requires\n * updating every `createVersionDispatcher` call site. This is an\n * intentional trade-off: compile-time exhaustiveness is preferred over\n * sparse-map flexibility.\n *\n * @param handlers - Map of version → handler function\n * @returns Dispatcher function that invokes the handler for `options.config.itWalletSpecsVersion`.\n * @throws {ItWalletSpecsVersionError} If no handler is registered for the configured version.\n */\nexport function createVersionDispatcher<\n TOptions extends VersionedOptions,\n TResult,\n>(\n handlers: Required<\n Record<ItWalletSpecsVersion, (options: TOptions) => TResult>\n >,\n): (options: TOptions) => TResult {\n return (options: TOptions): TResult => {\n const version = options.config.itWalletSpecsVersion;\n const handler = handlers[version];\n if (typeof handler !== \"function\") {\n throw new ItWalletSpecsVersionError(\n \"version-dispatcher\",\n version,\n Object.keys(handlers),\n );\n }\n return handler(options);\n };\n}\n\n/**\n * Dispatches by a bare version value (no options object needed).\n *\n * @param version - The version to dispatch on\n * @param handlers - Map of version → zero-argument handler function\n * @returns Result returned by the selected version handler.\n * @throws {ItWalletSpecsVersionError} If no handler is registered for the version.\n */\nexport function dispatchByVersion<TResult>(\n version: ItWalletSpecsVersion,\n handlers: Required<Record<ItWalletSpecsVersion, () => TResult>>,\n): TResult {\n const handler = handlers[version];\n if (typeof handler !== \"function\") {\n throw new ItWalletSpecsVersionError(\n \"version-dispatcher\",\n version,\n Object.keys(handlers),\n );\n }\n return handler();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,IAAK,uBAAL,kBAAKA,0BAAL;AACL,EAAAA,sBAAA,UAAO;AACP,EAAAA,sBAAA,UAAO;AACP,EAAAA,sBAAA,UAAO;AAHG,SAAAA;AAAA,GAAA;AAsCL,SAAS,iBAGd,SAAY,SAAgD;AAC5D,SAAO,QAAQ,OAAO,yBAAyB;AACjD;AAkBO,IAAM,oBAAN,MAEL;AAAA,EACgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQhB,YAAY,SAAsC;AAChD,SAAK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AAS,oBAAoB,SAAsC;AACxE,QAAM,MAAM,QAAQ,OAAO,oBAAI,KAAK;AACpC,QAAM,aAAa,KAAK,MAAM,IAAI,QAAQ,IAAI,GAAI;AAElD,MAAI,aAAa,QAAQ,MAAM,qBAAqB;AAClD,UAAM,IAAI,MAAM,wDAAwD;AAAA,EAC1E;AAEA,MAAI,QAAQ,MAAM,aAAa,8BAA8B;AAC3D,UAAM,IAAI,MAAM,2CAA2C;AAAA,EAC7D;AACF;;;ACAO,SAAS,wBAId,UAGgC;AAChC,SAAO,CAAC,YAA+B;AACrC,UAAM,UAAU,QAAQ,OAAO;AAC/B,UAAM,UAAU,SAAS,OAAO;AAChC,QAAI,OAAO,YAAY,YAAY;AACjC,YAAM,IAAI;AAAA,QACR;AAAA,QACA;AAAA,QACA,OAAO,KAAK,QAAQ;AAAA,MACtB;AAAA,IACF;AACA,WAAO,QAAQ,OAAO;AAAA,EACxB;AACF;AAUO,SAAS,kBACd,SACA,UACS;AACT,QAAM,UAAU,SAAS,OAAO;AAChC,MAAI,OAAO,YAAY,YAAY;AACjC,UAAM,IAAI;AAAA,MACR;AAAA,MACA;AAAA,MACA,OAAO,KAAK,QAAQ;AAAA,IACtB;AAAA,EACF;AACA,SAAO,QAAQ;AACjB;;;ATrDA,oBAOO;AAEP,mBAeO;","names":["ItWalletSpecsVersion","z"]}
package/dist/index.mjs CHANGED
@@ -10,6 +10,12 @@ function hasConfigVersion(options, version) {
10
10
  }
11
11
  var IoWalletSdkConfig = class {
12
12
  itWalletSpecsVersion;
13
+ /**
14
+ * Creates an SDK configuration for a specific IT-Wallet specification version.
15
+ *
16
+ * @param options - Configuration options.
17
+ * @param options.itWalletSpecsVersion - IT-Wallet specification version to use.
18
+ */
13
19
  constructor(options) {
14
20
  this.itWalletSpecsVersion = options.itWalletSpecsVersion;
15
21
  }
@@ -233,6 +239,33 @@ function verifyJwtIatOrThrow(options) {
233
239
  }
234
240
  }
235
241
 
242
+ // src/version-dispatcher.ts
243
+ function createVersionDispatcher(handlers) {
244
+ return (options) => {
245
+ const version = options.config.itWalletSpecsVersion;
246
+ const handler = handlers[version];
247
+ if (typeof handler !== "function") {
248
+ throw new ItWalletSpecsVersionError(
249
+ "version-dispatcher",
250
+ version,
251
+ Object.keys(handlers)
252
+ );
253
+ }
254
+ return handler(options);
255
+ };
256
+ }
257
+ function dispatchByVersion(version, handlers) {
258
+ const handler = handlers[version];
259
+ if (typeof handler !== "function") {
260
+ throw new ItWalletSpecsVersionError(
261
+ "version-dispatcher",
262
+ version,
263
+ Object.keys(handlers)
264
+ );
265
+ }
266
+ return handler();
267
+ }
268
+
236
269
  // src/index.ts
237
270
  import {
238
271
  HashAlgorithm,
@@ -270,10 +303,12 @@ export {
270
303
  addSecondsToDate,
271
304
  calculateJwkThumbprint,
272
305
  createFetcher,
306
+ createVersionDispatcher,
273
307
  dateToSeconds,
274
308
  decodeBase64,
275
309
  decodeJwt,
276
310
  decodeUtf8String,
311
+ dispatchByVersion,
277
312
  encodeToBase64Url,
278
313
  encodeToUtf8String,
279
314
  formatError,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/config.ts","../src/constants.ts","../src/errors/parse.ts","../src/errors/errors.ts","../src/fetcher.ts","../src/parse.ts","../src/validation.ts","../src/verify.ts","../src/index.ts"],"sourcesContent":["/**\n * Supported versions of the Italian Wallet technical specifications\n */\nexport enum ItWalletSpecsVersion {\n V1_0 = \"V1_0\",\n V1_3 = \"V1_3\",\n V1_4 = \"V1_4\",\n}\n\n/**\n * Configuration options for the IO Wallet SDK\n */\nexport interface IoWalletSdkConfigOptions<\n V extends ItWalletSpecsVersion = ItWalletSpecsVersion,\n> {\n /**\n * The version of the Italian Wallet specification to use.\n * REQUIRED - must be explicitly set by the user.\n *\n * @example\n * const config = new IoWalletSdkConfig({ itWalletSpecsVersion: ItWalletSpecsVersion.V1_3 });\n */\n itWalletSpecsVersion: V;\n}\n\ninterface WithConfig {\n config: IoWalletSdkConfig;\n}\n\ntype WithConfigVersion<\n T extends WithConfig,\n V extends ItWalletSpecsVersion,\n> = T extends { config: IoWalletSdkConfig<V> } ? T : never;\n\n/**\n * Type guard to check if the provided options have a specific config version\n *\n * @param options - The options object containing the config to check\n * @param version - The version to check against\n * @returns True if the options' config version matches the provided version\n */\nexport function hasConfigVersion<\n T extends WithConfig,\n V extends ItWalletSpecsVersion,\n>(options: T, version: V): options is WithConfigVersion<T, V> {\n return options.config.itWalletSpecsVersion === version;\n}\n\n/**\n * Configuration class for the IO Wallet SDK\n *\n * This class manages the version of the Italian Wallet technical specifications\n * to use throughout the SDK. The version determines the format of credential\n * requests and responses.\n *\n * @example Basic usage\n * const config = new IoWalletSdkConfig({ itWalletSpecsVersion: ItWalletSpecsVersion.V1_0 });\n * console.log(config.itWalletSpecsVersion); // ItWalletSpecsVersion.V1_0\n *\n * @example Type guard usage\n * if (config.isVersion(ItWalletSpecsVersion.V1_3)) {\n * // TypeScript narrows config.itWalletSpecsVersion to ItWalletSpecsVersion.V1_3\n * }\n */\nexport class IoWalletSdkConfig<\n V extends ItWalletSpecsVersion = ItWalletSpecsVersion,\n> {\n public readonly itWalletSpecsVersion: V;\n\n constructor(options: IoWalletSdkConfigOptions<V>) {\n this.itWalletSpecsVersion = options.itWalletSpecsVersion;\n }\n\n /**\n * Type guard for version checking\n *\n * @param version - The version to check against\n * @returns True if the config's version matches the provided version\n *\n * @internal\n */\n isVersion<W extends ItWalletSpecsVersion>(\n version: W,\n ): this is IoWalletSdkConfig<W> {\n const currentVersion: ItWalletSpecsVersion = this.itWalletSpecsVersion;\n return currentVersion === version;\n }\n}\n","/**\n * HTTP Content-Type constants for OAuth2 requests\n */\nexport const CONTENT_TYPES = {\n FORM_URLENCODED: \"application/x-www-form-urlencoded\",\n JSON: \"application/json\",\n} as const;\n\n/**\n * HTTP Header constants\n */\nexport const HEADERS = {\n AUTHORIZATION: \"Authorization\",\n CONTENT_TYPE: \"Content-Type\",\n DPOP: \"DPoP\",\n OAUTH_CLIENT_ATTESTATION: \"OAuth-Client-Attestation\",\n OAUTH_CLIENT_ATTESTATION_POP: \"OAuth-Client-Attestation-PoP\",\n} as const;\n\nexport const MAX_IAT_AGE_SECONDS = 5 * 60;\nexport const CLOCK_SKEW_TOLERANCE_SECONDS = 60;\n","import type z from \"zod\";\n\n/**\n * Some code comes from `zod-validation-error` package (MIT License) and\n * was slightly simplified to fit our needs.\n */\nconst constants = {\n identifierRegex: /[$_\\p{ID_Start}][$\\u200c\\u200d\\p{ID_Continue}]*/u,\n issueSeparator: \"\\n\\t- \",\n unionSeparator: \", or \",\n};\n\nfunction escapeQuotes(str: string): string {\n return str.replace(/\\\\/g, \"\\\\\\\\\").replace(/\"/g, '\\\\\"');\n}\n\ntype ZodIssue = z.ZodError[\"issues\"][number];\n\nfunction joinPath(path: PropertyKey[]): string {\n if (path.length === 1 && path[0] !== undefined) {\n return String(path[0]);\n }\n\n return path.reduce<string>((acc, item) => {\n // handle numeric indices\n if (typeof item === \"number\") {\n return `${acc}[${item.toString()}]`;\n }\n\n if (typeof item === \"symbol\") {\n return `${acc}[${JSON.stringify(String(item))}]`;\n }\n\n // handle quoted values\n if (item.includes('\"')) {\n return `${acc}[\"${escapeQuotes(item)}\"]`;\n }\n\n // handle special characters\n if (!constants.identifierRegex.test(item)) {\n return `${acc}[\"${item}\"]`;\n }\n\n // handle normal values\n const separator = acc.length === 0 ? \"\" : \".\";\n return acc + separator + item;\n }, \"\");\n}\nfunction getMessageFromZodIssue(issue: ZodIssue): string {\n if (issue.code === \"invalid_union\") {\n return getMessageFromUnionErrors(issue.errors);\n }\n\n if (issue.path.length !== 0) {\n // handle array indices\n if (issue.path.length === 1) {\n const identifier = issue.path[0];\n\n if (typeof identifier === \"number\") {\n return `${issue.message} at index ${identifier}`;\n }\n }\n\n return `${issue.message} at \"${joinPath(issue.path)}\"`;\n }\n\n return issue.message;\n}\n\nfunction getMessageFromUnionErrors(unionErrors: ZodIssue[][]): string {\n return unionErrors\n .reduce<string[]>((acc, issues) => {\n const newIssues = issues\n .map((issue) => getMessageFromZodIssue(issue))\n .join(constants.issueSeparator);\n\n if (!acc.includes(newIssues)) acc.push(newIssues);\n\n return acc;\n }, [])\n .join(constants.unionSeparator);\n}\n\nexport function formatZodError(error?: z.ZodError): string {\n if (!error) return \"\";\n\n return `\\t- ${error?.issues.map((issue) => getMessageFromZodIssue(issue)).join(constants.issueSeparator)}`;\n}\n","import type { ZodError, z } from \"zod\";\n\nimport { formatZodError } from \"./parse\";\n\n// An error reason that supports both a string and a generic JSON object\ntype GenericErrorReason = Record<string, unknown> | string;\n\n/**\n * utility to format a set of attributes into an error message string\n *\n * @example\n * // returns \"foo=value bar=(list, item)\"\n * serializeAttrs({ foo: \"value\", bar: [\"list\", \"item\"] })\n *\n * @param attrs A key value record set\n * @returns a human-readable serialization of the set\n */\nexport const serializeAttrs = (\n attrs: Record<string, GenericErrorReason | number | string[] | undefined>,\n): string =>\n Object.entries(attrs)\n .filter(([, v]) => v !== undefined)\n .map(([k, v]) => {\n if (Array.isArray(v)) return [k, `(${v.join(\", \")})`];\n if (typeof v !== \"string\") return [k, JSON.stringify(v)];\n return [k, v];\n })\n .map((_) => _.join(\"=\"))\n .join(\" \");\n\n/**\n * An error subclass thrown when an HTTP request has a status code different from the one expected.\n */\nexport class UnexpectedStatusCodeError extends Error {\n code = \"ERR_UNEXPECTED_STATUS_CODE\";\n reason: GenericErrorReason;\n statusCode: number;\n\n constructor({\n message,\n reason,\n statusCode,\n }: {\n message: string;\n reason: GenericErrorReason;\n statusCode: number;\n }) {\n super(serializeAttrs({ message, reason, statusCode }));\n this.reason = reason;\n this.statusCode = statusCode;\n }\n}\n\n/**\n * An error subclass thrown when an unsupported Italian Wallet specification version is requested.\n *\n * This error is thrown when:\n * - A feature or method is called with a version that it doesn't support\n * - An invalid version identifier is provided\n *\n * @example\n * throw new ItWalletSpecsVersionError(\n * 'createCredentialRequest',\n * '2.0.0',\n * [ItWalletSpecsVersion.V1_0, ItWalletSpecsVersion.V1_3]\n * );\n * // Error: Feature \"createCredentialRequest\" does not support version 2.0.0.\n * // Supported versions: V1_0, V1_3\n */\nexport class ItWalletSpecsVersionError extends Error {\n public readonly code = \"IT_WALLET_SPECS_VERSION_ERROR\";\n\n constructor(\n public readonly feature: string,\n public readonly requestedVersion: string,\n public readonly supportedVersions: readonly string[],\n ) {\n super(\n `Feature \"${feature}\" does not support version ${requestedVersion}.\\n` +\n `Supported versions: ${supportedVersions.join(\", \")}`,\n );\n this.name = \"ItWalletSpecsVersionError\";\n\n // Maintain proper stack trace for V8 engines (Node.js, Chrome)\n const ErrorConstructor = Error as {\n captureStackTrace?: (target: object, constructor: unknown) => void;\n };\n if (typeof ErrorConstructor.captureStackTrace === \"function\") {\n ErrorConstructor.captureStackTrace(this, ItWalletSpecsVersionError);\n }\n }\n}\n\nexport class ValidationError extends Error {\n public zodError: ZodError | undefined;\n\n constructor(message: string, zodError?: z.ZodError) {\n super(message);\n\n const formattedError = formatZodError(zodError);\n this.message = `${message}\\n${formattedError}`;\n\n Object.defineProperty(this, \"zodError\", {\n enumerable: false,\n value: zodError,\n writable: false,\n });\n }\n}\n","import { UnexpectedStatusCodeError } from \"./errors/errors\";\n\n/**\n * Check if a response is in the expected status, otherwise throw an error\n * @param status - The expected status\n * @param customError - A custom error compatible with {@link UnexpectedStatusCodeError}\n * @throws UnexpectedStatusCodeError if the status is different from the one expected\n * @returns The given response object\n */\nexport const hasStatusOrThrow =\n (status: number | number[], customError?: typeof UnexpectedStatusCodeError) =>\n async (res: Response): Promise<Response> => {\n if (\n Array.isArray(status)\n ? !status.includes(res.status)\n : res.status !== status\n ) {\n const ErrorClass = customError ?? UnexpectedStatusCodeError;\n throw new ErrorClass({\n message: `Http request failed. Expected ${status}, got ${res.status}, url: ${res.url}`,\n reason: await parseRawHttpResponse(res), // Pass the response body as reason so the original error can surface\n statusCode: res.status,\n });\n }\n return res;\n };\n\n/**\n * Utility function to parse a raw HTTP response as JSON if supported, otherwise as text.\n */\nexport const parseRawHttpResponse = <T extends Record<string, unknown>>(\n response: Response,\n) =>\n response.headers.get(\"content-type\")?.includes(\"application/json\")\n ? (response.json() as Promise<T>)\n : response.text();\n","import { z } from \"zod\";\n\nimport { ValidationError } from \"./errors/errors\";\n\nexport type BaseSchema = z.ZodTypeAny;\n\nconst SAFE_STRINGIFY_MAX_LENGTH = 200;\n\nfunction safeStringify(value: unknown): string {\n try {\n const result = JSON.stringify(value, (_key, val) =>\n typeof val === \"bigint\" ? `[BigInt: ${val}]` : val,\n );\n if (result === undefined) {\n return String(value);\n }\n return result.length > SAFE_STRINGIFY_MAX_LENGTH\n ? `${result.slice(0, SAFE_STRINGIFY_MAX_LENGTH)}…`\n : result;\n } catch {\n return \"[unserializable]\";\n }\n}\n\nexport function parseWithErrorHandling<Schema extends BaseSchema>(\n schema: Schema,\n data: unknown,\n customErrorMessage?: string,\n): z.infer<Schema> {\n const parseResult = schema.safeParse(data);\n\n if (!parseResult.success) {\n throw new ValidationError(\n customErrorMessage ??\n `Error validating schema with data ${safeStringify(data)}`,\n parseResult.error,\n );\n }\n\n return parseResult.data;\n}\n\nexport function formatError(message: string, prefix?: string): string {\n return prefix ? `${prefix} ${message}` : message;\n}\n","import z from \"zod\";\n\n/**\n * For the moment, these are all the supported algorithms in both\n * {@link https://italia.github.io/eid-wallet-it-docs/releases/1.3.3/en/algorithms.html#cryptographic-algorithms|v1.3.3} and\n * {@link https://italia.github.io/eid-wallet-it-docs/releases/1.0.2/en/algorithms.html#cryptographic-algorithms|v1.0.2},\n * and in both specifications the `alg` field MUST be one of those values.\n */\nexport const zItwSupportedSignatureAlg = z.enum([\n \"ES256\",\n \"ES384\",\n \"ES512\",\n \"PS256\",\n \"PS384\",\n \"PS512\",\n]);\nexport type ItwSupportedSignatureAlg = z.infer<\n typeof zItwSupportedSignatureAlg\n>;\n\nexport const zHttpMethod = z.enum([\n \"GET\",\n \"POST\",\n \"PUT\",\n \"DELETE\",\n \"HEAD\",\n \"OPTIONS\",\n \"TRACE\",\n \"CONNECT\",\n \"PATCH\",\n]);\nexport type HttpMethod = z.infer<typeof zHttpMethod>;\n","import { CLOCK_SKEW_TOLERANCE_SECONDS, MAX_IAT_AGE_SECONDS } from \"./constants\";\n\nexport function verifyJwtIatOrThrow(options: { iat: number; now?: Date }) {\n const now = options.now ?? new Date();\n const nowSeconds = Math.floor(now.getTime() / 1000);\n\n if (nowSeconds - options.iat > MAX_IAT_AGE_SECONDS) {\n throw new Error(\"iat claim in JWT is too old (must be within 5 minutes)\");\n }\n\n if (options.iat - nowSeconds > CLOCK_SKEW_TOLERANCE_SECONDS) {\n throw new Error(\"iat claim in JWT is too far in the future\");\n }\n}\n","export * from \"./config\";\nexport * from \"./constants\";\nexport * from \"./errors/errors\";\nexport * from \"./errors/parse\";\nexport * from \"./fetcher\";\nexport type * from \"./globals\";\nexport * from \"./parse\";\nexport * from \"./validation\";\nexport * from \"./verify\";\n\nexport {\n type CallbackContext,\n HashAlgorithm,\n type HashCallback,\n type JwtSignerJwk,\n calculateJwkThumbprint,\n decodeJwt,\n} from \"@openid4vc/oauth2\";\n\nexport {\n ContentType,\n type Fetch,\n JsonParseError,\n addSecondsToDate,\n createFetcher,\n dateToSeconds,\n decodeBase64,\n decodeUtf8String,\n encodeToBase64Url,\n encodeToUtf8String,\n objectToQueryParams,\n parseIfJson,\n setGlobalConfig,\n stringToJsonWithErrorHandling,\n} from \"@openid4vc/utils\";\n"],"mappings":";AAGO,IAAK,uBAAL,kBAAKA,0BAAL;AACL,EAAAA,sBAAA,UAAO;AACP,EAAAA,sBAAA,UAAO;AACP,EAAAA,sBAAA,UAAO;AAHG,SAAAA;AAAA,GAAA;AAsCL,SAAS,iBAGd,SAAY,SAAgD;AAC5D,SAAO,QAAQ,OAAO,yBAAyB;AACjD;AAkBO,IAAM,oBAAN,MAEL;AAAA,EACgB;AAAA,EAEhB,YAAY,SAAsC;AAChD,SAAK,uBAAuB,QAAQ;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A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Aa,KAAK,MAAM,IAAI,QAAQ,IAAI,GAAI;AAElD,MAAI,aAAa,QAAQ,MAAM,qBAAqB;AAClD,UAAM,IAAI,MAAM,wDAAwD;AAAA,EAC1E;AAEA,MAAI,QAAQ,MAAM,aAAa,8BAA8B;AAC3D,UAAM,IAAI,MAAM,2CAA2C;AAAA,EAC7D;AACF;;;ACHA;AAAA,EAEE;AAAA,EAGA;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":["ItWalletSpecsVersion"]}
1
+ {"version":3,"sources":["../src/config.ts","../src/constants.ts","../src/errors/parse.ts","../src/errors/errors.ts","../src/fetcher.ts","../src/parse.ts","../src/validation.ts","../src/verify.ts","../src/version-dispatcher.ts","../src/index.ts"],"sourcesContent":["/**\n * Supported versions of the Italian Wallet technical specifications\n */\nexport enum ItWalletSpecsVersion {\n V1_0 = \"V1_0\",\n V1_3 = \"V1_3\",\n V1_4 = \"V1_4\",\n}\n\n/**\n * Configuration options for the IO Wallet SDK\n */\nexport interface IoWalletSdkConfigOptions<\n V extends ItWalletSpecsVersion = ItWalletSpecsVersion,\n> {\n /**\n * The version of the Italian Wallet specification to use.\n * REQUIRED - must be explicitly set by the user.\n *\n * @example\n * const config = new IoWalletSdkConfig({ itWalletSpecsVersion: ItWalletSpecsVersion.V1_3 });\n */\n itWalletSpecsVersion: V;\n}\n\ninterface WithConfig {\n config: IoWalletSdkConfig;\n}\n\ntype WithConfigVersion<\n T extends WithConfig,\n V extends ItWalletSpecsVersion,\n> = T extends { config: IoWalletSdkConfig<V> } ? T : never;\n\n/**\n * Type guard to check if the provided options have a specific config version\n *\n * @param options - The options object containing the config to check\n * @param version - The version to check against\n * @returns True if the options' config version matches the provided version\n */\nexport function hasConfigVersion<\n T extends WithConfig,\n V extends ItWalletSpecsVersion,\n>(options: T, version: V): options is WithConfigVersion<T, V> {\n return options.config.itWalletSpecsVersion === version;\n}\n\n/**\n * Configuration class for the IO Wallet SDK\n *\n * This class manages the version of the Italian Wallet technical specifications\n * to use throughout the SDK. The version determines the format of credential\n * requests and responses.\n *\n * @example Basic usage\n * const config = new IoWalletSdkConfig({ itWalletSpecsVersion: ItWalletSpecsVersion.V1_0 });\n * console.log(config.itWalletSpecsVersion); // ItWalletSpecsVersion.V1_0\n *\n * @example Type guard usage\n * if (config.isVersion(ItWalletSpecsVersion.V1_3)) {\n * // TypeScript narrows config.itWalletSpecsVersion to ItWalletSpecsVersion.V1_3\n * }\n */\nexport class IoWalletSdkConfig<\n V extends ItWalletSpecsVersion = ItWalletSpecsVersion,\n> {\n public readonly itWalletSpecsVersion: V;\n\n /**\n * Creates an SDK configuration for a specific IT-Wallet specification version.\n *\n * @param options - Configuration options.\n * @param options.itWalletSpecsVersion - IT-Wallet specification version to use.\n */\n constructor(options: IoWalletSdkConfigOptions<V>) {\n this.itWalletSpecsVersion = options.itWalletSpecsVersion;\n }\n\n /**\n * Type guard for version checking\n *\n * @param version - The version to check against\n * @returns True if the config's version matches the provided version\n *\n * @internal\n */\n isVersion<W extends ItWalletSpecsVersion>(\n version: W,\n ): this is IoWalletSdkConfig<W> {\n const currentVersion: ItWalletSpecsVersion = this.itWalletSpecsVersion;\n return currentVersion === version;\n }\n}\n","/**\n * HTTP Content-Type constants for OAuth2 requests\n */\nexport const CONTENT_TYPES = {\n FORM_URLENCODED: \"application/x-www-form-urlencoded\",\n JSON: \"application/json\",\n} as const;\n\n/**\n * HTTP Header constants\n */\nexport const HEADERS = {\n AUTHORIZATION: \"Authorization\",\n CONTENT_TYPE: \"Content-Type\",\n DPOP: \"DPoP\",\n OAUTH_CLIENT_ATTESTATION: \"OAuth-Client-Attestation\",\n OAUTH_CLIENT_ATTESTATION_POP: \"OAuth-Client-Attestation-PoP\",\n} as const;\n\nexport const MAX_IAT_AGE_SECONDS = 5 * 60;\nexport const CLOCK_SKEW_TOLERANCE_SECONDS = 60;\n","import type z from \"zod\";\n\n/**\n * Some code comes from `zod-validation-error` package (MIT License) and\n * was slightly simplified to fit our needs.\n */\nconst constants = {\n identifierRegex: /[$_\\p{ID_Start}][$\\u200c\\u200d\\p{ID_Continue}]*/u,\n issueSeparator: \"\\n\\t- \",\n unionSeparator: \", or \",\n};\n\nfunction escapeQuotes(str: string): string {\n return str.replace(/\\\\/g, \"\\\\\\\\\").replace(/\"/g, '\\\\\"');\n}\n\ntype ZodIssue = z.ZodError[\"issues\"][number];\n\nfunction joinPath(path: PropertyKey[]): string {\n if (path.length === 1 && path[0] !== undefined) {\n return String(path[0]);\n }\n\n return path.reduce<string>((acc, item) => {\n // handle numeric indices\n if (typeof item === \"number\") {\n return `${acc}[${item.toString()}]`;\n }\n\n if (typeof item === \"symbol\") {\n return `${acc}[${JSON.stringify(String(item))}]`;\n }\n\n // handle quoted values\n if (item.includes('\"')) {\n return `${acc}[\"${escapeQuotes(item)}\"]`;\n }\n\n // handle special characters\n if (!constants.identifierRegex.test(item)) {\n return `${acc}[\"${item}\"]`;\n }\n\n // handle normal values\n const separator = acc.length === 0 ? \"\" : \".\";\n return acc + separator + item;\n }, \"\");\n}\nfunction getMessageFromZodIssue(issue: ZodIssue): string {\n if (issue.code === \"invalid_union\") {\n return getMessageFromUnionErrors(issue.errors);\n }\n\n if (issue.path.length !== 0) {\n // handle array indices\n if (issue.path.length === 1) {\n const identifier = issue.path[0];\n\n if (typeof identifier === \"number\") {\n return `${issue.message} at index ${identifier}`;\n }\n }\n\n return `${issue.message} at \"${joinPath(issue.path)}\"`;\n }\n\n return issue.message;\n}\n\nfunction getMessageFromUnionErrors(unionErrors: ZodIssue[][]): string {\n return unionErrors\n .reduce<string[]>((acc, issues) => {\n const newIssues = issues\n .map((issue) => getMessageFromZodIssue(issue))\n .join(constants.issueSeparator);\n\n if (!acc.includes(newIssues)) acc.push(newIssues);\n\n return acc;\n }, [])\n .join(constants.unionSeparator);\n}\n\n/**\n * Formats a Zod error into a readable multi-line message.\n *\n * @param error - Optional Zod error to format.\n * @returns Empty string when no error is provided, otherwise a formatted issue list.\n */\nexport function formatZodError(error?: z.ZodError): string {\n if (!error) return \"\";\n\n return `\\t- ${error?.issues.map((issue) => getMessageFromZodIssue(issue)).join(constants.issueSeparator)}`;\n}\n","import type { ZodError, z } from \"zod\";\n\nimport { formatZodError } from \"./parse\";\n\n// An error reason that supports both a string and a generic JSON object\ntype GenericErrorReason = Record<string, unknown> | string;\n\n/**\n * utility to format a set of attributes into an error message string\n *\n * @example\n * // returns \"foo=value bar=(list, item)\"\n * serializeAttrs({ foo: \"value\", bar: [\"list\", \"item\"] })\n *\n * @param attrs A key value record set\n * @returns a human-readable serialization of the set\n */\nexport const serializeAttrs = (\n attrs: Record<string, GenericErrorReason | number | string[] | undefined>,\n): string =>\n Object.entries(attrs)\n .filter(([, v]) => v !== undefined)\n .map(([k, v]) => {\n if (Array.isArray(v)) return [k, `(${v.join(\", \")})`];\n if (typeof v !== \"string\") return [k, JSON.stringify(v)];\n return [k, v];\n })\n .map((_) => _.join(\"=\"))\n .join(\" \");\n\n/**\n * An error subclass thrown when an HTTP request has a status code different from the one expected.\n */\nexport class UnexpectedStatusCodeError extends Error {\n code = \"ERR_UNEXPECTED_STATUS_CODE\";\n reason: GenericErrorReason;\n statusCode: number;\n\n constructor({\n message,\n reason,\n statusCode,\n }: {\n message: string;\n reason: GenericErrorReason;\n statusCode: number;\n }) {\n super(serializeAttrs({ message, reason, statusCode }));\n this.reason = reason;\n this.statusCode = statusCode;\n }\n}\n\n/**\n * An error subclass thrown when an unsupported Italian Wallet specification version is requested.\n *\n * This error is thrown when:\n * - A feature or method is called with a version that it doesn't support\n * - An invalid version identifier is provided\n *\n * @example\n * throw new ItWalletSpecsVersionError(\n * 'createCredentialRequest',\n * '2.0.0',\n * [ItWalletSpecsVersion.V1_0, ItWalletSpecsVersion.V1_3]\n * );\n * // Error: Feature \"createCredentialRequest\" does not support version 2.0.0.\n * // Supported versions: V1_0, V1_3\n */\nexport class ItWalletSpecsVersionError extends Error {\n public readonly code = \"IT_WALLET_SPECS_VERSION_ERROR\";\n\n constructor(\n public readonly feature: string,\n public readonly requestedVersion: string,\n public readonly supportedVersions: readonly string[],\n ) {\n super(\n `Feature \"${feature}\" does not support version ${requestedVersion}.\\n` +\n `Supported versions: ${supportedVersions.join(\", \")}`,\n );\n this.name = \"ItWalletSpecsVersionError\";\n\n // Maintain proper stack trace for V8 engines (Node.js, Chrome)\n const ErrorConstructor = Error as {\n captureStackTrace?: (target: object, constructor: unknown) => void;\n };\n if (typeof ErrorConstructor.captureStackTrace === \"function\") {\n ErrorConstructor.captureStackTrace(this, ItWalletSpecsVersionError);\n }\n }\n}\n\n/**\n * Error thrown when runtime validation fails.\n */\nexport class ValidationError extends Error {\n public zodError: ZodError | undefined;\n\n constructor(message: string, zodError?: z.ZodError) {\n super(message);\n\n const formattedError = formatZodError(zodError);\n this.message = `${message}\\n${formattedError}`;\n\n Object.defineProperty(this, \"zodError\", {\n enumerable: false,\n value: zodError,\n writable: false,\n });\n }\n}\n","import { UnexpectedStatusCodeError } from \"./errors/errors\";\n\n/**\n * Check if a response is in the expected status, otherwise throw an error\n * @param status - The expected status\n * @param customError - A custom error compatible with {@link UnexpectedStatusCodeError}\n * @throws UnexpectedStatusCodeError if the status is different from the one expected\n * @returns The given response object\n */\nexport const hasStatusOrThrow =\n (status: number | number[], customError?: typeof UnexpectedStatusCodeError) =>\n async (res: Response): Promise<Response> => {\n if (\n Array.isArray(status)\n ? !status.includes(res.status)\n : res.status !== status\n ) {\n const ErrorClass = customError ?? UnexpectedStatusCodeError;\n throw new ErrorClass({\n message: `Http request failed. Expected ${status}, got ${res.status}, url: ${res.url}`,\n reason: await parseRawHttpResponse(res), // Pass the response body as reason so the original error can surface\n statusCode: res.status,\n });\n }\n return res;\n };\n\n/**\n * Utility function to parse a raw HTTP response as JSON if supported, otherwise as text.\n *\n * @param response - Raw HTTP response to parse.\n * @returns Parsed JSON for JSON responses, otherwise response text.\n */\nexport const parseRawHttpResponse = <T extends Record<string, unknown>>(\n response: Response,\n) =>\n response.headers.get(\"content-type\")?.includes(\"application/json\")\n ? (response.json() as Promise<T>)\n : response.text();\n","import { z } from \"zod\";\n\nimport { ValidationError } from \"./errors/errors\";\n\nexport type BaseSchema = z.ZodTypeAny;\n\nconst SAFE_STRINGIFY_MAX_LENGTH = 200;\n\nfunction safeStringify(value: unknown): string {\n try {\n const result = JSON.stringify(value, (_key, val) =>\n typeof val === \"bigint\" ? `[BigInt: ${val}]` : val,\n );\n if (result === undefined) {\n return String(value);\n }\n return result.length > SAFE_STRINGIFY_MAX_LENGTH\n ? `${result.slice(0, SAFE_STRINGIFY_MAX_LENGTH)}…`\n : result;\n } catch {\n return \"[unserializable]\";\n }\n}\n\n/**\n * Parses data with a Zod schema and throws the SDK `ValidationError` on failure.\n *\n * @param schema - Zod schema used for validation.\n * @param data - Unknown value to parse.\n * @param customErrorMessage - Optional error message used when validation fails.\n * @returns Parsed schema output.\n * @throws {ValidationError} If the value does not satisfy the provided schema.\n */\nexport function parseWithErrorHandling<Schema extends BaseSchema>(\n schema: Schema,\n data: unknown,\n customErrorMessage?: string,\n): z.infer<Schema> {\n const parseResult = schema.safeParse(data);\n\n if (!parseResult.success) {\n throw new ValidationError(\n customErrorMessage ??\n `Error validating schema with data ${safeStringify(data)}`,\n parseResult.error,\n );\n }\n\n return parseResult.data;\n}\n\n/**\n * Prefixes an error message with optional contextual text.\n *\n * @param message - Base error message.\n * @param prefix - Optional prefix to prepend.\n * @returns Formatted error message.\n */\nexport function formatError(message: string, prefix?: string): string {\n return prefix ? `${prefix} ${message}` : message;\n}\n","import z from \"zod\";\n\n/**\n * For the moment, these are all the supported algorithms in both\n * {@link https://italia.github.io/eid-wallet-it-docs/releases/1.3.3/en/algorithms.html#cryptographic-algorithms|v1.3.3} and\n * {@link https://italia.github.io/eid-wallet-it-docs/releases/1.0.2/en/algorithms.html#cryptographic-algorithms|v1.0.2},\n * and in both specifications the `alg` field MUST be one of those values.\n */\nexport const zItwSupportedSignatureAlg = z.enum([\n \"ES256\",\n \"ES384\",\n \"ES512\",\n \"PS256\",\n \"PS384\",\n \"PS512\",\n]);\nexport type ItwSupportedSignatureAlg = z.infer<\n typeof zItwSupportedSignatureAlg\n>;\n\nexport const zHttpMethod = z.enum([\n \"GET\",\n \"POST\",\n \"PUT\",\n \"DELETE\",\n \"HEAD\",\n \"OPTIONS\",\n \"TRACE\",\n \"CONNECT\",\n \"PATCH\",\n]);\nexport type HttpMethod = z.infer<typeof zHttpMethod>;\n","import { CLOCK_SKEW_TOLERANCE_SECONDS, MAX_IAT_AGE_SECONDS } from \"./constants\";\n\n/**\n * Validates a JWT `iat` claim against SDK age and clock-skew limits.\n *\n * @param options - Validation options.\n * @param options.iat - Issued-at timestamp in seconds.\n * @param options.now - Optional current date, defaults to the current time.\n * @throws {Error} If `iat` is too old or too far in the future.\n */\nexport function verifyJwtIatOrThrow(options: { iat: number; now?: Date }) {\n const now = options.now ?? new Date();\n const nowSeconds = Math.floor(now.getTime() / 1000);\n\n if (nowSeconds - options.iat > MAX_IAT_AGE_SECONDS) {\n throw new Error(\"iat claim in JWT is too old (must be within 5 minutes)\");\n }\n\n if (options.iat - nowSeconds > CLOCK_SKEW_TOLERANCE_SECONDS) {\n throw new Error(\"iat claim in JWT is too far in the future\");\n }\n}\n","import { ItWalletSpecsVersion } from \"./config\";\nimport { ItWalletSpecsVersionError } from \"./errors/errors\";\n\nexport interface VersionedOptions {\n config: { itWalletSpecsVersion: ItWalletSpecsVersion };\n}\n\n/**\n * Creates a version-aware dispatcher that routes a function call\n * based on options.config.itWalletSpecsVersion.\n *\n * All versions declared in `ItWalletSpecsVersion` must be provided\n * (`Required` contract). Adding a new spec version therefore requires\n * updating every `createVersionDispatcher` call site. This is an\n * intentional trade-off: compile-time exhaustiveness is preferred over\n * sparse-map flexibility.\n *\n * @param handlers - Map of version → handler function\n * @returns Dispatcher function that invokes the handler for `options.config.itWalletSpecsVersion`.\n * @throws {ItWalletSpecsVersionError} If no handler is registered for the configured version.\n */\nexport function createVersionDispatcher<\n TOptions extends VersionedOptions,\n TResult,\n>(\n handlers: Required<\n Record<ItWalletSpecsVersion, (options: TOptions) => TResult>\n >,\n): (options: TOptions) => TResult {\n return (options: TOptions): TResult => {\n const version = options.config.itWalletSpecsVersion;\n const handler = handlers[version];\n if (typeof handler !== \"function\") {\n throw new ItWalletSpecsVersionError(\n \"version-dispatcher\",\n version,\n Object.keys(handlers),\n );\n }\n return handler(options);\n };\n}\n\n/**\n * Dispatches by a bare version value (no options object needed).\n *\n * @param version - The version to dispatch on\n * @param handlers - Map of version → zero-argument handler function\n * @returns Result returned by the selected version handler.\n * @throws {ItWalletSpecsVersionError} If no handler is registered for the version.\n */\nexport function dispatchByVersion<TResult>(\n version: ItWalletSpecsVersion,\n handlers: Required<Record<ItWalletSpecsVersion, () => TResult>>,\n): TResult {\n const handler = handlers[version];\n if (typeof handler !== \"function\") {\n throw new ItWalletSpecsVersionError(\n \"version-dispatcher\",\n version,\n Object.keys(handlers),\n );\n }\n return handler();\n}\n","export * from \"./config\";\nexport * from \"./constants\";\nexport * from \"./errors/errors\";\nexport * from \"./errors/parse\";\nexport * from \"./fetcher\";\nexport type * from \"./globals\";\nexport * from \"./parse\";\nexport * from \"./validation\";\nexport * from \"./verify\";\nexport * from \"./version-dispatcher\";\n\nexport {\n type CallbackContext,\n HashAlgorithm,\n type HashCallback,\n type JwtSignerJwk,\n calculateJwkThumbprint,\n decodeJwt,\n} from \"@openid4vc/oauth2\";\n\nexport {\n ContentType,\n type Fetch,\n JsonParseError,\n addSecondsToDate,\n createFetcher,\n dateToSeconds,\n decodeBase64,\n decodeUtf8String,\n encodeToBase64Url,\n encodeToUtf8String,\n objectToQueryParams,\n parseIfJson,\n setGlobalConfig,\n stringToJsonWithErrorHandling,\n} from \"@openid4vc/utils\";\n"],"mappings":";AAGO,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ACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":["ItWalletSpecsVersion"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pagopa/io-wallet-utils",
3
- "version": "1.4.0",
3
+ "version": "1.4.1-alpha-20260518131456",
4
4
  "files": [
5
5
  "dist"
6
6
  ],