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

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