@pagopa/io-wallet-utils 1.5.8 → 2.0.0-apt

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.ts CHANGED
@@ -1,11 +1,10 @@
1
- import z$1, { ZodError, z } from 'zod';
2
- export { CallbackContext, HashAlgorithm, HashCallback, JwtSignerJwk, calculateJwkThumbprint, decodeJwt } from '@openid4vc/oauth2';
3
- export { ContentType, Fetch, JsonParseError, addSecondsToDate, createFetcher, dateToSeconds, decodeBase64, decodeUtf8String, encodeToBase64Url, encodeToUtf8String, objectToQueryParams, parseIfJson, setGlobalConfig, stringToJsonWithErrorHandling } from '@openid4vc/utils';
1
+ import z, { z as z$1, ZodError } from 'zod';
4
2
 
5
3
  /**
6
4
  * Supported versions of the Italian Wallet technical specifications
7
5
  */
8
6
  declare enum ItWalletSpecsVersion {
7
+ APTITUDE = "APTITUDE",
9
8
  V1_0 = "V1_0",
10
9
  V1_3 = "V1_3",
11
10
  V1_4 = "V1_4"
@@ -93,6 +92,608 @@ declare const HEADERS: {
93
92
  declare const MAX_IAT_AGE_SECONDS: number;
94
93
  declare const CLOCK_SKEW_TOLERANCE_SECONDS = 60;
95
94
 
95
+ declare enum ContentType {
96
+ Html = "text/html",
97
+ Json = "application/json",
98
+ JwkSet = "application/jwk-set+json",
99
+ Jwt = "application/jwt",
100
+ OAuthAuthorizationRequestJwt = "application/oauth-authz-req+jwt",
101
+ XWwwFormUrlencoded = "application/x-www-form-urlencoded"
102
+ }
103
+
104
+ /**
105
+ * For the moment, these are all the supported algorithms in both
106
+ * {@link https://italia.github.io/eid-wallet-it-docs/releases/1.3.3/en/algorithms.html#cryptographic-algorithms|v1.3.3} and
107
+ * {@link https://italia.github.io/eid-wallet-it-docs/releases/1.0.2/en/algorithms.html#cryptographic-algorithms|v1.0.2},
108
+ * and in both specifications the `alg` field MUST be one of those values.
109
+ */
110
+ declare const zItwSupportedSignatureAlg: z.ZodEnum<{
111
+ ES256: "ES256";
112
+ ES384: "ES384";
113
+ ES512: "ES512";
114
+ PS256: "PS256";
115
+ PS384: "PS384";
116
+ PS512: "PS512";
117
+ }>;
118
+ type ItwSupportedSignatureAlg = z.infer<typeof zItwSupportedSignatureAlg>;
119
+ declare const zHttpMethod: z.ZodEnum<{
120
+ GET: "GET";
121
+ POST: "POST";
122
+ PUT: "PUT";
123
+ DELETE: "DELETE";
124
+ HEAD: "HEAD";
125
+ OPTIONS: "OPTIONS";
126
+ TRACE: "TRACE";
127
+ CONNECT: "CONNECT";
128
+ PATCH: "PATCH";
129
+ }>;
130
+ type HttpMethod = z.infer<typeof zHttpMethod>;
131
+
132
+ type Fetch = typeof fetch;
133
+ type FetchHeaders = globalThis.Headers;
134
+ interface RequestLike {
135
+ headers: FetchHeaders;
136
+ method: HttpMethod;
137
+ url: string;
138
+ }
139
+
140
+ type OrPromise$1<T> = Promise<T> | T;
141
+ declare enum HashAlgorithm {
142
+ Sha256 = "sha-256",
143
+ Sha384 = "sha-384",
144
+ Sha512 = "sha-512"
145
+ }
146
+ type HashCallback = (data: Uint8Array, alg: HashAlgorithm) => OrPromise$1<Uint8Array>;
147
+
148
+ declare const zJwk: z.ZodObject<{
149
+ alg: z.ZodOptional<z.ZodString>;
150
+ crv: z.ZodOptional<z.ZodString>;
151
+ d: z.ZodOptional<z.ZodString>;
152
+ dp: z.ZodOptional<z.ZodString>;
153
+ dq: z.ZodOptional<z.ZodString>;
154
+ e: z.ZodOptional<z.ZodString>;
155
+ ext: z.ZodOptional<z.ZodBoolean>;
156
+ k: z.ZodOptional<z.ZodString>;
157
+ key_ops: z.ZodOptional<z.ZodArray<z.ZodString>>;
158
+ kid: z.ZodOptional<z.ZodString>;
159
+ kty: z.ZodString;
160
+ n: z.ZodOptional<z.ZodString>;
161
+ oth: z.ZodOptional<z.ZodArray<z.ZodObject<{
162
+ d: z.ZodOptional<z.ZodString>;
163
+ r: z.ZodOptional<z.ZodString>;
164
+ t: z.ZodOptional<z.ZodString>;
165
+ }, z.core.$loose>>>;
166
+ p: z.ZodOptional<z.ZodString>;
167
+ q: z.ZodOptional<z.ZodString>;
168
+ qi: z.ZodOptional<z.ZodString>;
169
+ use: z.ZodOptional<z.ZodString>;
170
+ x: z.ZodOptional<z.ZodString>;
171
+ x5c: z.ZodOptional<z.ZodArray<z.ZodString>>;
172
+ x5t: z.ZodOptional<z.ZodString>;
173
+ "x5t#S256": z.ZodOptional<z.ZodString>;
174
+ x5u: z.ZodOptional<z.ZodString>;
175
+ y: z.ZodOptional<z.ZodString>;
176
+ }, z.core.$loose>;
177
+ type Jwk = z.infer<typeof zJwk>;
178
+ declare const zJwkSet: z.ZodObject<{
179
+ keys: z.ZodArray<z.ZodObject<{
180
+ alg: z.ZodOptional<z.ZodString>;
181
+ crv: z.ZodOptional<z.ZodString>;
182
+ d: z.ZodOptional<z.ZodString>;
183
+ dp: z.ZodOptional<z.ZodString>;
184
+ dq: z.ZodOptional<z.ZodString>;
185
+ e: z.ZodOptional<z.ZodString>;
186
+ ext: z.ZodOptional<z.ZodBoolean>;
187
+ k: z.ZodOptional<z.ZodString>;
188
+ key_ops: z.ZodOptional<z.ZodArray<z.ZodString>>;
189
+ kid: z.ZodOptional<z.ZodString>;
190
+ kty: z.ZodString;
191
+ n: z.ZodOptional<z.ZodString>;
192
+ oth: z.ZodOptional<z.ZodArray<z.ZodObject<{
193
+ d: z.ZodOptional<z.ZodString>;
194
+ r: z.ZodOptional<z.ZodString>;
195
+ t: z.ZodOptional<z.ZodString>;
196
+ }, z.core.$loose>>>;
197
+ p: z.ZodOptional<z.ZodString>;
198
+ q: z.ZodOptional<z.ZodString>;
199
+ qi: z.ZodOptional<z.ZodString>;
200
+ use: z.ZodOptional<z.ZodString>;
201
+ x: z.ZodOptional<z.ZodString>;
202
+ x5c: z.ZodOptional<z.ZodArray<z.ZodString>>;
203
+ x5t: z.ZodOptional<z.ZodString>;
204
+ "x5t#S256": z.ZodOptional<z.ZodString>;
205
+ x5u: z.ZodOptional<z.ZodString>;
206
+ y: z.ZodOptional<z.ZodString>;
207
+ }, z.core.$loose>>;
208
+ }, z.core.$loose>;
209
+ type JwkSet = z.infer<typeof zJwkSet>;
210
+
211
+ declare const zTrustChain: z.ZodTuple<[z.ZodString], z.ZodString>;
212
+ type TrustChain = z.infer<typeof zTrustChain>;
213
+ declare const zCertificateChain: z.ZodArray<z.ZodString>;
214
+ type CertificateChain = z.infer<typeof zCertificateChain>;
215
+ declare const zAlgValueNotNone: z.ZodString;
216
+
217
+ declare const MAX_JTI_LENGTH = 256;
218
+ interface JwtSignerDid {
219
+ alg: string;
220
+ didUrl: string;
221
+ /**
222
+ * The key id that should be used for signing. You need to make sure the kid actually matches
223
+ * with the key associated with the didUrl.
224
+ */
225
+ kid?: string;
226
+ method: "did";
227
+ }
228
+ interface JwtSignerJwk {
229
+ alg: string;
230
+ /**
231
+ * The key id that should be used for signing. You need to make sure the kid actually matches
232
+ * with the key associated with the jwk.
233
+ *
234
+ * If not provided the kid can also be extracted from the `publicJwk`. Providing it here means the `kid` won't
235
+ * be included in the JWT header.
236
+ */
237
+ kid?: string;
238
+ method: "jwk";
239
+ publicJwk: Jwk;
240
+ }
241
+ interface JwtSignerX5c {
242
+ alg: string;
243
+ /**
244
+ * The key id that should be used for signing. You need to make sure the kid actually matches
245
+ * with the key associated with the leaf certificate.
246
+ */
247
+ kid?: string;
248
+ method: "x5c";
249
+ trustChain?: TrustChain;
250
+ x5c: string[];
251
+ }
252
+ interface JwtSignerFederation {
253
+ alg: string;
254
+ /**
255
+ * The key id that should be used for signing. You need to make sure the kid actually matches
256
+ * with a key present in the federation.
257
+ */
258
+ kid: string;
259
+ method: "federation";
260
+ trustChain?: TrustChain;
261
+ }
262
+ interface JwtSignerCustom {
263
+ alg: string;
264
+ /**
265
+ * The key id that should be used for signing.
266
+ */
267
+ kid?: string;
268
+ method: "custom";
269
+ }
270
+ type JwtSigner = JwtSignerCustom | JwtSignerDid | JwtSignerFederation | JwtSignerJwk | JwtSignerX5c;
271
+ type JwtSignerWithJwk = {
272
+ publicJwk: Jwk;
273
+ } & JwtSigner;
274
+ type JweEncryptor = {
275
+ /**
276
+ * base64-url encoded apu
277
+ */
278
+ apu?: string;
279
+ /**
280
+ * base64-url encoded apv
281
+ */
282
+ apv?: string;
283
+ enc: string;
284
+ } & JwtSignerJwk;
285
+ declare const zCompactJwt: z.ZodString;
286
+ declare const zJwtConfirmationPayload: z.ZodObject<{
287
+ jkt: z.ZodOptional<z.ZodString>;
288
+ jwk: z.ZodOptional<z.ZodObject<{
289
+ alg: z.ZodOptional<z.ZodString>;
290
+ crv: z.ZodOptional<z.ZodString>;
291
+ d: z.ZodOptional<z.ZodString>;
292
+ dp: z.ZodOptional<z.ZodString>;
293
+ dq: z.ZodOptional<z.ZodString>;
294
+ e: z.ZodOptional<z.ZodString>;
295
+ ext: z.ZodOptional<z.ZodBoolean>;
296
+ k: z.ZodOptional<z.ZodString>;
297
+ key_ops: z.ZodOptional<z.ZodArray<z.ZodString>>;
298
+ kid: z.ZodOptional<z.ZodString>;
299
+ kty: z.ZodString;
300
+ n: z.ZodOptional<z.ZodString>;
301
+ oth: z.ZodOptional<z.ZodArray<z.ZodObject<{
302
+ d: z.ZodOptional<z.ZodString>;
303
+ r: z.ZodOptional<z.ZodString>;
304
+ t: z.ZodOptional<z.ZodString>;
305
+ }, z.core.$loose>>>;
306
+ p: z.ZodOptional<z.ZodString>;
307
+ q: z.ZodOptional<z.ZodString>;
308
+ qi: z.ZodOptional<z.ZodString>;
309
+ use: z.ZodOptional<z.ZodString>;
310
+ x: z.ZodOptional<z.ZodString>;
311
+ x5c: z.ZodOptional<z.ZodArray<z.ZodString>>;
312
+ x5t: z.ZodOptional<z.ZodString>;
313
+ "x5t#S256": z.ZodOptional<z.ZodString>;
314
+ x5u: z.ZodOptional<z.ZodString>;
315
+ y: z.ZodOptional<z.ZodString>;
316
+ }, z.core.$loose>>;
317
+ }, z.core.$loose>;
318
+ declare const zJwtPayload: z.ZodObject<{
319
+ aud: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString>]>>;
320
+ cnf: z.ZodOptional<z.ZodObject<{
321
+ jkt: z.ZodOptional<z.ZodString>;
322
+ jwk: z.ZodOptional<z.ZodObject<{
323
+ alg: z.ZodOptional<z.ZodString>;
324
+ crv: z.ZodOptional<z.ZodString>;
325
+ d: z.ZodOptional<z.ZodString>;
326
+ dp: z.ZodOptional<z.ZodString>;
327
+ dq: z.ZodOptional<z.ZodString>;
328
+ e: z.ZodOptional<z.ZodString>;
329
+ ext: z.ZodOptional<z.ZodBoolean>;
330
+ k: z.ZodOptional<z.ZodString>;
331
+ key_ops: z.ZodOptional<z.ZodArray<z.ZodString>>;
332
+ kid: z.ZodOptional<z.ZodString>;
333
+ kty: z.ZodString;
334
+ n: z.ZodOptional<z.ZodString>;
335
+ oth: z.ZodOptional<z.ZodArray<z.ZodObject<{
336
+ d: z.ZodOptional<z.ZodString>;
337
+ r: z.ZodOptional<z.ZodString>;
338
+ t: z.ZodOptional<z.ZodString>;
339
+ }, z.core.$loose>>>;
340
+ p: z.ZodOptional<z.ZodString>;
341
+ q: z.ZodOptional<z.ZodString>;
342
+ qi: z.ZodOptional<z.ZodString>;
343
+ use: z.ZodOptional<z.ZodString>;
344
+ x: z.ZodOptional<z.ZodString>;
345
+ x5c: z.ZodOptional<z.ZodArray<z.ZodString>>;
346
+ x5t: z.ZodOptional<z.ZodString>;
347
+ "x5t#S256": z.ZodOptional<z.ZodString>;
348
+ x5u: z.ZodOptional<z.ZodString>;
349
+ y: z.ZodOptional<z.ZodString>;
350
+ }, z.core.$loose>>;
351
+ }, z.core.$loose>>;
352
+ exp: z.ZodOptional<z.ZodNumber>;
353
+ iat: z.ZodOptional<z.ZodNumber>;
354
+ iss: z.ZodOptional<z.ZodString>;
355
+ jti: z.ZodOptional<z.ZodString>;
356
+ nbf: z.ZodOptional<z.ZodNumber>;
357
+ nonce: z.ZodOptional<z.ZodString>;
358
+ status: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
359
+ sub: z.ZodOptional<z.ZodString>;
360
+ trust_chain: z.ZodOptional<z.ZodTuple<[z.ZodString], z.ZodString>>;
361
+ }, z.core.$loose>;
362
+ type JwtPayload = z.infer<typeof zJwtPayload>;
363
+ declare const zJwtHeader: z.ZodObject<{
364
+ alg: z.ZodString;
365
+ jwk: z.ZodOptional<z.ZodObject<{
366
+ alg: z.ZodOptional<z.ZodString>;
367
+ crv: z.ZodOptional<z.ZodString>;
368
+ d: z.ZodOptional<z.ZodString>;
369
+ dp: z.ZodOptional<z.ZodString>;
370
+ dq: z.ZodOptional<z.ZodString>;
371
+ e: z.ZodOptional<z.ZodString>;
372
+ ext: z.ZodOptional<z.ZodBoolean>;
373
+ k: z.ZodOptional<z.ZodString>;
374
+ key_ops: z.ZodOptional<z.ZodArray<z.ZodString>>;
375
+ kid: z.ZodOptional<z.ZodString>;
376
+ kty: z.ZodString;
377
+ n: z.ZodOptional<z.ZodString>;
378
+ oth: z.ZodOptional<z.ZodArray<z.ZodObject<{
379
+ d: z.ZodOptional<z.ZodString>;
380
+ r: z.ZodOptional<z.ZodString>;
381
+ t: z.ZodOptional<z.ZodString>;
382
+ }, z.core.$loose>>>;
383
+ p: z.ZodOptional<z.ZodString>;
384
+ q: z.ZodOptional<z.ZodString>;
385
+ qi: z.ZodOptional<z.ZodString>;
386
+ use: z.ZodOptional<z.ZodString>;
387
+ x: z.ZodOptional<z.ZodString>;
388
+ x5c: z.ZodOptional<z.ZodArray<z.ZodString>>;
389
+ x5t: z.ZodOptional<z.ZodString>;
390
+ "x5t#S256": z.ZodOptional<z.ZodString>;
391
+ x5u: z.ZodOptional<z.ZodString>;
392
+ y: z.ZodOptional<z.ZodString>;
393
+ }, z.core.$loose>>;
394
+ kid: z.ZodOptional<z.ZodString>;
395
+ trust_chain: z.ZodOptional<z.ZodTuple<[z.ZodString], z.ZodString>>;
396
+ typ: z.ZodOptional<z.ZodString>;
397
+ x5c: z.ZodOptional<z.ZodArray<z.ZodString>>;
398
+ }, z.core.$loose>;
399
+ type JwtHeader = z.infer<typeof zJwtHeader>;
400
+
401
+ type OrPromise<T> = Promise<T> | T;
402
+ type GenerateRandomCallback = (byteLength: number) => OrPromise<Uint8Array>;
403
+ type SignJwtCallback = (jwtSigner: JwtSigner, jwt: {
404
+ header: JwtHeader;
405
+ payload: JwtPayload;
406
+ }) => OrPromise<{
407
+ jwt: string;
408
+ signerJwk: Jwk;
409
+ }>;
410
+ type VerifyJwtCallback = (jwtSigner: JwtSigner, jwt: {
411
+ compact: string;
412
+ header: JwtHeader;
413
+ payload: JwtPayload;
414
+ }) => OrPromise<{
415
+ signerJwk: Jwk;
416
+ verified: true;
417
+ } | {
418
+ signerJwk?: Jwk;
419
+ verified: false;
420
+ }>;
421
+ type DecryptJweCallback = (jwe: string, options?: {
422
+ jwk?: Jwk;
423
+ }) => OrPromise<{
424
+ decrypted: false;
425
+ decryptionJwk?: Jwk;
426
+ payload?: string;
427
+ } | {
428
+ decrypted: true;
429
+ decryptionJwk: Jwk;
430
+ payload: string;
431
+ }>;
432
+ type EncryptJweCallback = (jweEncryptor: JweEncryptor, data: string) => OrPromise<{
433
+ encryptionJwk: Jwk;
434
+ jwe: string;
435
+ }>;
436
+ interface ClientAuthenticationCallbackOptionsBase<AuthorizationServerMetadata = unknown> {
437
+ authorizationServerMetadata: AuthorizationServerMetadata;
438
+ body: Record<string, unknown>;
439
+ contentType: ContentType;
440
+ headers: FetchHeaders;
441
+ method: HttpMethod;
442
+ url: string;
443
+ }
444
+ type ClientAuthenticationCallbackOptions<AuthorizationServerMetadata = unknown, ExtraOptions extends object = object> = ClientAuthenticationCallbackOptionsBase<AuthorizationServerMetadata> & ExtraOptions;
445
+ type ClientAuthenticationCallback<Options extends ClientAuthenticationCallbackOptions = ClientAuthenticationCallbackOptions> = (options: Options) => OrPromise<void>;
446
+ interface CallbackContext {
447
+ clientAuthentication: ClientAuthenticationCallback;
448
+ decryptJwe: DecryptJweCallback;
449
+ encryptJwe: EncryptJweCallback;
450
+ fetch?: Fetch;
451
+ generateRandom: GenerateRandomCallback;
452
+ getX509CertificateMetadata?: (certificate: string) => {
453
+ sanDnsNames: string[];
454
+ sanUriNames: string[];
455
+ };
456
+ hash: HashCallback;
457
+ signJwt: SignJwtCallback;
458
+ verifyJwt: VerifyJwtCallback;
459
+ }
460
+ interface RequestDpopOptions {
461
+ nonce?: string;
462
+ signer: JwtSignerJwk;
463
+ }
464
+
465
+ declare function calculateJwkThumbprint(options: {
466
+ hashAlgorithm: HashAlgorithm;
467
+ hashCallback: HashCallback;
468
+ jwk: Jwk;
469
+ }): Promise<string>;
470
+
471
+ type BaseSchema = z$1.ZodTypeAny;
472
+ /**
473
+ * Parses a JSON string and throws the SDK `JsonParseError` on failure.
474
+ *
475
+ * @param value - JSON string to parse.
476
+ * @param errorMessage - Optional error message used when parsing fails.
477
+ * @returns Parsed JSON object.
478
+ * @throws {JsonParseError} If the value is not valid JSON.
479
+ */
480
+ declare function stringToJsonWithErrorHandling(value: string, errorMessage?: string): Record<string, unknown>;
481
+ declare function parseIfJson<T>(data: T): Record<string, unknown> | T;
482
+ declare function parseWithErrorHandling<Schema extends BaseSchema>(schema: Schema, data: unknown, customErrorMessage?: string): z$1.infer<Schema>;
483
+ /**
484
+ * Prefixes an error message with optional contextual text.
485
+ *
486
+ * @param message - Base error message.
487
+ * @param prefix - Optional prefix to prepend.
488
+ * @returns Formatted error message.
489
+ */
490
+ declare function formatError(message: string, prefix?: string): string;
491
+
492
+ interface DecodeJwtOptions<HeaderSchema extends BaseSchema | undefined, PayloadSchema extends BaseSchema | undefined> {
493
+ /**
494
+ * Optional prefix for error messages thrown during decoding, to provide more context on where the error occurred
495
+ */
496
+ errorMessagePrefix?: string;
497
+ /**
498
+ * Schema to use for validating the header. If not provided the
499
+ * default `zJwtHeader` schema will be used
500
+ */
501
+ headerSchema?: HeaderSchema;
502
+ /**
503
+ * The compact encoded jwt
504
+ */
505
+ jwt: string;
506
+ /**
507
+ * Schema to use for validating the payload. If not provided the
508
+ * default `zJwtPayload` schema will be used
509
+ */
510
+ payloadSchema?: PayloadSchema;
511
+ }
512
+ interface DecodeJwtResult<HeaderSchema extends BaseSchema | undefined = undefined, PayloadSchema extends BaseSchema | undefined = undefined> {
513
+ compact: string;
514
+ header: InferSchemaOrDefaultOutput<HeaderSchema, typeof zJwtHeader>;
515
+ payload: InferSchemaOrDefaultOutput<PayloadSchema, typeof zJwtPayload>;
516
+ signature: string;
517
+ }
518
+ /**
519
+ * Decodes a compact JWT and validates its header and payload with Zod schemas.
520
+ *
521
+ * This helper does not verify the JWT signature.
522
+ *
523
+ * @param options - Decode options.
524
+ * @param options.errorMessagePrefix - Optional context prefix for thrown parse/validation errors.
525
+ * @param options.headerSchema - Optional schema for the JWT header; defaults to `zJwtHeader`.
526
+ * @param options.jwt - Compact JWT to decode.
527
+ * @param options.payloadSchema - Optional schema for the JWT payload; defaults to `zJwtPayload`.
528
+ * @returns Decoded and schema-validated JWT header, payload, and signature segment.
529
+ * @throws {JwtParseError} If the JWT shape or base64url JSON segments are invalid.
530
+ * @throws {ValidationError} If header or payload schema validation fails.
531
+ */
532
+ declare function decodeJwt<HeaderSchema extends BaseSchema | undefined = undefined, PayloadSchema extends BaseSchema | undefined = undefined>(options: DecodeJwtOptions<HeaderSchema, PayloadSchema>): DecodeJwtResult<HeaderSchema, PayloadSchema>;
533
+ type IsSchemaProvided<T> = T extends undefined ? false : true;
534
+ type InferSchemaOrDefaultOutput<ProvidedSchema extends BaseSchema | undefined, DefaultSchema extends BaseSchema> = IsSchemaProvided<ProvidedSchema> extends true ? ProvidedSchema extends BaseSchema ? z.infer<ProvidedSchema> : never : z.infer<DefaultSchema>;
535
+
536
+ interface DecodeJwtHeaderOptions<HeaderSchema extends BaseSchema | undefined> {
537
+ /**
538
+ * Optional prefix for error messages thrown during decoding, to provide more context on where the error occurred
539
+ */
540
+ errorMessagePrefix?: string;
541
+ /**
542
+ * Schema to use for validating the header. If not provided the
543
+ * default `zJwtHeader` schema will be used
544
+ */
545
+ headerSchema?: HeaderSchema;
546
+ /**
547
+ * The compact encoded jwt
548
+ */
549
+ jwt: string;
550
+ }
551
+ interface DecodeJwtHeaderResult<HeaderSchema extends BaseSchema | undefined = undefined> {
552
+ header: InferSchemaOrDefaultOutput<HeaderSchema, typeof zJwtHeader>;
553
+ }
554
+ /**
555
+ * Decodes and validates the header of a compact JWT.
556
+ *
557
+ * This helper does not verify the JWT signature or parse the payload.
558
+ *
559
+ * @param options - Header decode options.
560
+ * @param options.errorMessagePrefix - Optional context prefix for thrown parse/validation errors.
561
+ * @param options.headerSchema - Optional schema for the JWT header; defaults to `zJwtHeader`.
562
+ * @param options.jwt - Compact JWT to decode.
563
+ * @returns Decoded and schema-validated JWT header.
564
+ * @throws {JwtParseError} If the JWT shape or header JSON is invalid.
565
+ * @throws {ValidationError} If header schema validation fails.
566
+ */
567
+ declare function decodeJwtHeader<HeaderSchema extends BaseSchema | undefined = undefined>(options: DecodeJwtHeaderOptions<HeaderSchema>): DecodeJwtHeaderResult<HeaderSchema>;
568
+ /**
569
+ * Builds a JWT header from an SDK signer descriptor.
570
+ *
571
+ * @param signer - Signer descriptor used by SDK signing callbacks.
572
+ * @returns Header fields required by the signer method.
573
+ */
574
+ declare function jwtHeaderFromJwtSigner(signer: JwtSigner): {
575
+ alg: string;
576
+ kid: string;
577
+ trust_chain?: undefined;
578
+ jwk?: undefined;
579
+ x5c?: undefined;
580
+ } | {
581
+ alg: string;
582
+ kid: string;
583
+ trust_chain: [string, ...string[]] | undefined;
584
+ jwk?: undefined;
585
+ x5c?: undefined;
586
+ } | {
587
+ alg: string;
588
+ jwk: {
589
+ [x: string]: unknown;
590
+ kty: string;
591
+ alg?: string | undefined;
592
+ crv?: string | undefined;
593
+ d?: string | undefined;
594
+ dp?: string | undefined;
595
+ dq?: string | undefined;
596
+ e?: string | undefined;
597
+ ext?: boolean | undefined;
598
+ k?: string | undefined;
599
+ key_ops?: string[] | undefined;
600
+ kid?: string | undefined;
601
+ n?: string | undefined;
602
+ oth?: {
603
+ [x: string]: unknown;
604
+ d?: string | undefined;
605
+ r?: string | undefined;
606
+ t?: string | undefined;
607
+ }[] | undefined;
608
+ p?: string | undefined;
609
+ q?: string | undefined;
610
+ qi?: string | undefined;
611
+ use?: string | undefined;
612
+ x?: string | undefined;
613
+ x5c?: string[] | undefined;
614
+ x5t?: string | undefined;
615
+ "x5t#S256"?: string | undefined;
616
+ x5u?: string | undefined;
617
+ y?: string | undefined;
618
+ };
619
+ kid?: undefined;
620
+ trust_chain?: undefined;
621
+ x5c?: undefined;
622
+ } | {
623
+ alg: string;
624
+ kid: string | undefined;
625
+ trust_chain: [string, ...string[]] | undefined;
626
+ x5c: string[];
627
+ jwk?: undefined;
628
+ } | {
629
+ alg: string;
630
+ kid?: undefined;
631
+ trust_chain?: undefined;
632
+ jwk?: undefined;
633
+ x5c?: undefined;
634
+ };
635
+ /**
636
+ * Derives the SDK signer descriptor from a decoded JWT header and payload.
637
+ *
638
+ * @param options.allowedSignerMethods - Signer methods accepted by the caller; all are allowed when omitted.
639
+ * @param options.header - Decoded JWT header.
640
+ * @param options.payload - Decoded JWT payload.
641
+ * @returns The first valid, allowed signer found in the JWT.
642
+ * @throws {JwtParseError} If no allowed signer can be extracted from the JWT.
643
+ */
644
+ declare function jwtSignerFromJwt(options: {
645
+ allowedSignerMethods?: JwtSigner["method"][];
646
+ header: Pick<JwtHeader, "alg" | "jwk" | "kid" | "trust_chain" | "x5c">;
647
+ payload: Pick<JwtPayload, "iss">;
648
+ }): JwtSigner;
649
+
650
+ interface VerifyJwtOptions {
651
+ allowedSkewInSeconds?: number;
652
+ compact: string;
653
+ errorMessage?: string;
654
+ expectedAudience?: string;
655
+ expectedIssuer?: string;
656
+ expectedNonce?: string;
657
+ expectedSubject?: string;
658
+ header: JwtHeader;
659
+ now?: Date;
660
+ payload: JwtPayload;
661
+ requiredClaims?: (keyof JwtPayload)[];
662
+ signer: JwtSigner;
663
+ skipTimeBasedValidation?: boolean;
664
+ verifyJwtCallback: VerifyJwtCallback;
665
+ }
666
+ interface VerifyJwtReturn {
667
+ signer: JwtSignerWithJwk;
668
+ }
669
+ declare function verifyJwt(options: VerifyJwtOptions): Promise<VerifyJwtReturn>;
670
+
671
+ declare const zCompactJwe: z$1.ZodString;
672
+
673
+ /**
674
+ * Get the time in seconds since epoch for a date.
675
+ * If date is not provided the current time will be used.
676
+ */
677
+ declare function dateToSeconds(date?: Date): number;
678
+ declare function addSecondsToDate(date: Date, seconds: number): Date;
679
+
680
+ declare function decodeUtf8String(value: string): Uint8Array;
681
+ declare function encodeToUtf8String(data: Uint8Array): string;
682
+ /**
683
+ * Also supports base64 url encoded input.
684
+ */
685
+ declare function decodeBase64(base64: string): Uint8Array;
686
+ declare function encodeToBase64Url(data: Uint8Array | string): string;
687
+
688
+ declare class JsonParseError extends Error {
689
+ constructor(message: string, jsonString: string);
690
+ }
691
+ declare class JwtParseError extends Error {
692
+ constructor(message?: string);
693
+ }
694
+ declare class JwtVerificationError extends Error {
695
+ constructor(message?: string, options?: ErrorOptions);
696
+ }
96
697
  type GenericErrorReason = Record<string, unknown> | string;
97
698
  /**
98
699
  * utility to format a set of attributes into an error message string
@@ -146,7 +747,7 @@ declare class ItWalletSpecsVersionError extends Error {
146
747
  */
147
748
  declare class ValidationError extends Error {
148
749
  zodError: ZodError | undefined;
149
- constructor(message: string, zodError?: z.ZodError);
750
+ constructor(message: string, zodError?: z$1.ZodError);
150
751
  }
151
752
 
152
753
  /**
@@ -155,8 +756,9 @@ declare class ValidationError extends Error {
155
756
  * @param error - Optional Zod error to format.
156
757
  * @returns Empty string when no error is provided, otherwise a formatted issue list.
157
758
  */
158
- declare function formatZodError(error?: z$1.ZodError): string;
759
+ declare function formatZodError(error?: z.ZodError): string;
159
760
 
761
+ declare function createFetcher(fetcher?: Fetch): Fetch;
160
762
  /**
161
763
  * Check if a response is in the expected status, otherwise throw an error
162
764
  * @param status - The expected status
@@ -171,62 +773,9 @@ declare const hasStatusOrThrow: (status: number | number[], customError?: typeof
171
773
  * @param response - Raw HTTP response to parse.
172
774
  * @returns Parsed JSON for JSON responses, otherwise response text.
173
775
  */
174
- declare const parseRawHttpResponse: <T extends Record<string, unknown>>(response: Response) => Promise<T> | Promise<string>;
776
+ declare const parseRawHttpResponse: <T extends Record<string, unknown>>(response: Response) => Promise<string> | Promise<T>;
175
777
 
176
- /**
177
- * For the moment, these are all the supported algorithms in both
178
- * {@link https://italia.github.io/eid-wallet-it-docs/releases/1.3.3/en/algorithms.html#cryptographic-algorithms|v1.3.3} and
179
- * {@link https://italia.github.io/eid-wallet-it-docs/releases/1.0.2/en/algorithms.html#cryptographic-algorithms|v1.0.2},
180
- * and in both specifications the `alg` field MUST be one of those values.
181
- */
182
- declare const zItwSupportedSignatureAlg: z$1.ZodEnum<{
183
- ES256: "ES256";
184
- ES384: "ES384";
185
- ES512: "ES512";
186
- PS256: "PS256";
187
- PS384: "PS384";
188
- PS512: "PS512";
189
- }>;
190
- type ItwSupportedSignatureAlg = z$1.infer<typeof zItwSupportedSignatureAlg>;
191
- declare const zHttpMethod: z$1.ZodEnum<{
192
- GET: "GET";
193
- POST: "POST";
194
- PUT: "PUT";
195
- DELETE: "DELETE";
196
- HEAD: "HEAD";
197
- OPTIONS: "OPTIONS";
198
- TRACE: "TRACE";
199
- CONNECT: "CONNECT";
200
- PATCH: "PATCH";
201
- }>;
202
- type HttpMethod = z$1.infer<typeof zHttpMethod>;
203
-
204
- type FetchHeaders = globalThis.Headers;
205
- interface RequestLike {
206
- headers: FetchHeaders;
207
- method: HttpMethod;
208
- url: string;
209
- }
210
-
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
- */
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
- */
229
- declare function formatError(message: string, prefix?: string): string;
778
+ declare function objectToQueryParams(object: Record<string, unknown>): URLSearchParams;
230
779
 
231
780
  /**
232
781
  * Validates a JWT `iat` claim against SDK age and clock-skew limits.
@@ -271,4 +820,4 @@ declare function createVersionDispatcher<TOptions extends VersionedOptions, TRes
271
820
  */
272
821
  declare function dispatchByVersion<TResult>(version: ItWalletSpecsVersion, handlers: Required<Record<ItWalletSpecsVersion, () => TResult>>): TResult;
273
822
 
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 };
823
+ export { type BaseSchema, CLOCK_SKEW_TOLERANCE_SECONDS, CONTENT_TYPES, type CallbackContext, type CertificateChain, type ClientAuthenticationCallback, type ClientAuthenticationCallbackOptions, type ClientAuthenticationCallbackOptionsBase, ContentType, type DecodeJwtHeaderOptions, type DecodeJwtHeaderResult, type DecodeJwtOptions, type DecodeJwtResult, type DecryptJweCallback, type EncryptJweCallback, type Fetch, type FetchHeaders, type GenerateRandomCallback, HEADERS, HashAlgorithm, type HashCallback, type HttpMethod, type InferSchemaOrDefaultOutput, IoWalletSdkConfig, type IoWalletSdkConfigOptions, ItWalletSpecsVersion, ItWalletSpecsVersionError, type ItwSupportedSignatureAlg, JsonParseError, type JweEncryptor, type Jwk, type JwkSet, type JwtHeader, JwtParseError, type JwtPayload, type JwtSigner, type JwtSignerCustom, type JwtSignerDid, type JwtSignerFederation, type JwtSignerJwk, type JwtSignerWithJwk, type JwtSignerX5c, JwtVerificationError, MAX_IAT_AGE_SECONDS, MAX_JTI_LENGTH, type RequestDpopOptions, type RequestLike, type SignJwtCallback, type TrustChain, UnexpectedStatusCodeError, ValidationError, type VerifyJwtCallback, type VerifyJwtOptions, type VerifyJwtReturn, type VersionedOptions, addSecondsToDate, calculateJwkThumbprint, createFetcher, createVersionDispatcher, dateToSeconds, decodeBase64, decodeJwt, decodeJwtHeader, decodeUtf8String, dispatchByVersion, encodeToBase64Url, encodeToUtf8String, formatError, formatZodError, hasConfigVersion, hasStatusOrThrow, jwtHeaderFromJwtSigner, jwtSignerFromJwt, objectToQueryParams, parseIfJson, parseRawHttpResponse, parseWithErrorHandling, serializeAttrs, stringToJsonWithErrorHandling, verifyJwt, verifyJwtIatOrThrow, zAlgValueNotNone, zCertificateChain, zCompactJwe, zCompactJwt, zHttpMethod, zItwSupportedSignatureAlg, zJwk, zJwkSet, zJwtConfirmationPayload, zJwtHeader, zJwtPayload, zTrustChain };