@sd-jwt/core 0.20.1-next.5 → 0.20.1-next.6

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
@@ -8,12 +8,16 @@ declare const KB_JWT_TYP = "kb+jwt";
8
8
  type SDJWTCompact = string;
9
9
  type Base64urlString = string;
10
10
  type DisclosureData<T> = [string, string, T] | [string, T];
11
+ declare const encodePathSegment: (segment: string) => string;
12
+ declare const encodePath: (segments: string[]) => string;
11
13
  declare const IANA_HASH_ALGORITHMS: readonly ["sha-256", "sha-256-128", "sha-256-120", "sha-256-96", "sha-256-64", "sha-256-32", "sha-384", "sha-512", "sha3-224", "sha3-256", "sha3-384", "sha3-512", "blake2s-256", "blake2b-256", "blake2b-512", "k12-256", "k12-512"];
12
14
  type HashAlgorithm = (typeof IANA_HASH_ALGORITHMS)[number];
15
+ declare const DEFAULT_SECURE_HASH_ALGORITHMS: readonly ["sha-256", "sha-384", "sha-512", "sha3-256", "sha3-384", "sha3-512", "blake2s-256", "blake2b-256", "blake2b-512", "k12-256", "k12-512"];
13
16
  type SDJWTConfig<T = unknown> = {
14
17
  omitTyp?: boolean;
15
18
  hasher?: Hasher;
16
19
  hashAlg?: HashAlgorithm;
20
+ allowedDisclosureHashAlgorithms?: ReadonlyArray<HashAlgorithm>;
17
21
  saltGenerator?: SaltGenerator;
18
22
  signer?: Signer;
19
23
  signAlg?: string;
@@ -268,6 +272,7 @@ type GeneralJSONSerialized = {
268
272
  disclosures?: Array<string>;
269
273
  kid?: string;
270
274
  kb_jwt?: string;
275
+ [key: string]: unknown;
271
276
  };
272
277
  protected: string;
273
278
  signature: string;
@@ -332,10 +337,31 @@ type VerifierOptions = {
332
337
  * If the payload does not contain these keys, the verification will fail.
333
338
  */
334
339
  requiredClaimKeys?: string[];
340
+ /**
341
+ * Expected audience for the processed SD-JWT payload.
342
+ */
343
+ expectedAudience?: string | string[];
344
+ /**
345
+ * Allowed JOSE algorithms for issuer-signed JWTs. `none` is always rejected.
346
+ */
347
+ allowedIssuerAlgorithms?: string[];
335
348
  /**
336
349
  * nonce used to verify the key binding jwt to prevent replay attacks.
337
350
  */
338
351
  keyBindingNonce?: string;
352
+ /**
353
+ * Expected audience for the Key Binding JWT.
354
+ */
355
+ expectedKeyBindingAudience?: string | string[];
356
+ /**
357
+ * Maximum acceptable age of the Key Binding JWT, in seconds.
358
+ */
359
+ keyBindingMaxAgeSeconds?: number;
360
+ /**
361
+ * Internal option used by SD-JWT validation to defer claim checks until after
362
+ * disclosures are processed.
363
+ */
364
+ skipJwtClaimValidation?: boolean;
339
365
  /**
340
366
  * disable the verification of the status claim in the payload.
341
367
  *
@@ -347,6 +373,7 @@ type VerifierOptions = {
347
373
  */
348
374
  [key: string]: unknown;
349
375
  };
376
+ declare const validateJwtPayload: (payload: Record<string, unknown> | undefined, options?: VerifierOptions) => void;
350
377
  declare class Jwt<Header extends Record<string, unknown> = Record<string, unknown>, Payload extends Record<string, unknown> = Record<string, unknown>> {
351
378
  header?: Header;
352
379
  payload?: Payload;
@@ -451,7 +478,7 @@ declare class SDJwt<Header extends Record<string, unknown> = Record<string, unkn
451
478
  getClaims<T>(hasher: Hasher): Promise<T>;
452
479
  }
453
480
  declare const listKeys: (obj: Record<string, unknown>, prefix?: string) => string[];
454
- declare const pack: <T extends Record<string, unknown>>(claims: T, disclosureFrame: DisclosureFrame<T> | undefined, hash: HasherAndAlg, saltGenerator: SaltGenerator) => Promise<{
481
+ declare const pack: <T extends Record<string, unknown>>(claims: T, disclosureFrame: DisclosureFrame<T> | undefined, hash: HasherAndAlg, saltGenerator: SaltGenerator, seenSalts?: Set<string>, seenDigests?: Set<string>) => Promise<{
455
482
  packedClaims: Record<string, unknown> | Array<Record<string, unknown>>;
456
483
  disclosures: Array<Disclosure>;
457
484
  }>;
@@ -476,7 +503,7 @@ declare const unpackObj: (obj: unknown, map: Record<string, Disclosure>) => {
476
503
  };
477
504
  declare const createHashMapping: (disclosures: Array<Disclosure>, hash: HasherAndAlg) => Promise<Record<string, Disclosure<unknown>>>;
478
505
  declare const createHashMappingSync: (disclosures: Array<Disclosure>, hash: HasherAndAlgSync) => Record<string, Disclosure<unknown>>;
479
- declare const getSDAlgAndPayload: (SdJwtPayload: Record<string, unknown>) => {
506
+ declare const getSDAlgAndPayload: (SdJwtPayload: Record<string, unknown>, allowedAlgorithms?: ReadonlyArray<HashAlgorithm>) => {
480
507
  _sd_alg: string;
481
508
  payload: {
482
509
  [x: string]: unknown;
@@ -516,7 +543,7 @@ declare const presentSync: <T extends Record<string, unknown>>(sdJwt: string, pr
516
543
  * @param prefix The prefix to add to the keys
517
544
  * @returns
518
545
  */
519
- declare const transformPresentationFrame: (obj: PresentationFrame<Extensible>, prefix?: string) => string[];
546
+ declare const transformPresentationFrame: (obj: PresentationFrame<Extensible>, prefix?: string[]) => string[];
520
547
  type SerializedDisclosure = {
521
548
  digest: string;
522
549
  encoded: string;
@@ -633,20 +660,20 @@ declare class SDJwtGeneralJSONInstance<ExtendedPayload extends SdJwtPayload> {
633
660
  }): Promise<GeneralJSON>;
634
661
  verify(generalJSON: GeneralJSON, options?: VerifierOptions): Promise<{
635
662
  payload: ExtendedPayload;
636
- headers: unknown[];
663
+ headers: Record<string, unknown>[];
637
664
  kb?: undefined;
638
665
  } | {
639
666
  payload: ExtendedPayload;
640
- headers: unknown[];
667
+ headers: Record<string, unknown>[];
641
668
  kb: {
642
669
  payload: kbPayload;
643
670
  header: kbHeader;
644
671
  };
645
672
  }>;
646
673
  private calculateSDHash;
647
- validate(generalJSON: GeneralJSON): Promise<{
674
+ validate(generalJSON: GeneralJSON, options?: VerifierOptions): Promise<{
648
675
  payload: ExtendedPayload;
649
- headers: unknown[];
676
+ headers: Record<string, unknown>[];
650
677
  }>;
651
678
  config(newConfig: SDJWTConfig): void;
652
679
  encode(sdJwt: GeneralJSON, index: number): SDJWTCompact;
@@ -656,4 +683,4 @@ declare class SDJwtGeneralJSONInstance<ExtendedPayload extends SdJwtPayload> {
656
683
  getClaims(generalSdjwt: GeneralJSON): Promise<unknown>;
657
684
  }
658
685
 
659
- export { type Base64urlString, type DECOY, type DecodedSDJwt, Disclosure, type DisclosureData, type DisclosureFrame, type Extensible, FlattenJSON, type FlattenJSONData, type FlattenJSONSerialized, GeneralJSON, type GeneralJSONData, type GeneralJSONSerialized, type HashAlgorithm, type Hasher, type HasherAndAlg, type HasherAndAlgSync, type HasherSync, IANA_HASH_ALGORITHMS, Jwt, type JwtData, type JwtPayload, KBJwt, type KBOptions, KB_JWT_TYP, type KbVerifier, type OrPromise, type PresentationFrame, type SD, type SDJWTCompact, type SDJWTConfig, SDJWTException, SDJwt, type SDJwtData, SDJwtGeneralJSONInstance, SDJwtInstance, SD_DECOY, SD_DIGEST, SD_LIST_KEY, SD_SEPARATOR, type SafeVerifyResult, type SaltGenerator, type SaltGeneratorSync, type SdJwtPayload, type SerializedDisclosure, type Signer, type SignerSync, type VerificationError, type VerificationErrorCode, type Verifier, type VerifierOptions, type VerifierSync, createDecoy, createHashMapping, createHashMappingForSerializedDisclosure, createHashMappingSync, decodeJwt, decodeSdJwt, decodeSdJwtSync, ensureError, getClaims, getClaimsSync, getSDAlgAndPayload, type kbHeader, type kbPayload, listKeys, pack, present, presentSync, presentableKeys, presentableKeysSync, selectDisclosures, splitSdJwt, transformPresentationFrame, unpack, unpackObj, unpackSync };
686
+ export { type Base64urlString, type DECOY, DEFAULT_SECURE_HASH_ALGORITHMS, type DecodedSDJwt, Disclosure, type DisclosureData, type DisclosureFrame, type Extensible, FlattenJSON, type FlattenJSONData, type FlattenJSONSerialized, GeneralJSON, type GeneralJSONData, type GeneralJSONSerialized, type HashAlgorithm, type Hasher, type HasherAndAlg, type HasherAndAlgSync, type HasherSync, IANA_HASH_ALGORITHMS, Jwt, type JwtData, type JwtPayload, KBJwt, type KBOptions, KB_JWT_TYP, type KbVerifier, type OrPromise, type PresentationFrame, type SD, type SDJWTCompact, type SDJWTConfig, SDJWTException, SDJwt, type SDJwtData, SDJwtGeneralJSONInstance, SDJwtInstance, SD_DECOY, SD_DIGEST, SD_LIST_KEY, SD_SEPARATOR, type SafeVerifyResult, type SaltGenerator, type SaltGeneratorSync, type SdJwtPayload, type SerializedDisclosure, type Signer, type SignerSync, type VerificationError, type VerificationErrorCode, type Verifier, type VerifierOptions, type VerifierSync, createDecoy, createHashMapping, createHashMappingForSerializedDisclosure, createHashMappingSync, decodeJwt, decodeSdJwt, decodeSdJwtSync, encodePath, encodePathSegment, ensureError, getClaims, getClaimsSync, getSDAlgAndPayload, type kbHeader, type kbPayload, listKeys, pack, present, presentSync, presentableKeys, presentableKeysSync, selectDisclosures, splitSdJwt, transformPresentationFrame, unpack, unpackObj, unpackSync, validateJwtPayload };
package/dist/index.d.ts CHANGED
@@ -8,12 +8,16 @@ declare const KB_JWT_TYP = "kb+jwt";
8
8
  type SDJWTCompact = string;
9
9
  type Base64urlString = string;
10
10
  type DisclosureData<T> = [string, string, T] | [string, T];
11
+ declare const encodePathSegment: (segment: string) => string;
12
+ declare const encodePath: (segments: string[]) => string;
11
13
  declare const IANA_HASH_ALGORITHMS: readonly ["sha-256", "sha-256-128", "sha-256-120", "sha-256-96", "sha-256-64", "sha-256-32", "sha-384", "sha-512", "sha3-224", "sha3-256", "sha3-384", "sha3-512", "blake2s-256", "blake2b-256", "blake2b-512", "k12-256", "k12-512"];
12
14
  type HashAlgorithm = (typeof IANA_HASH_ALGORITHMS)[number];
15
+ declare const DEFAULT_SECURE_HASH_ALGORITHMS: readonly ["sha-256", "sha-384", "sha-512", "sha3-256", "sha3-384", "sha3-512", "blake2s-256", "blake2b-256", "blake2b-512", "k12-256", "k12-512"];
13
16
  type SDJWTConfig<T = unknown> = {
14
17
  omitTyp?: boolean;
15
18
  hasher?: Hasher;
16
19
  hashAlg?: HashAlgorithm;
20
+ allowedDisclosureHashAlgorithms?: ReadonlyArray<HashAlgorithm>;
17
21
  saltGenerator?: SaltGenerator;
18
22
  signer?: Signer;
19
23
  signAlg?: string;
@@ -268,6 +272,7 @@ type GeneralJSONSerialized = {
268
272
  disclosures?: Array<string>;
269
273
  kid?: string;
270
274
  kb_jwt?: string;
275
+ [key: string]: unknown;
271
276
  };
272
277
  protected: string;
273
278
  signature: string;
@@ -332,10 +337,31 @@ type VerifierOptions = {
332
337
  * If the payload does not contain these keys, the verification will fail.
333
338
  */
334
339
  requiredClaimKeys?: string[];
340
+ /**
341
+ * Expected audience for the processed SD-JWT payload.
342
+ */
343
+ expectedAudience?: string | string[];
344
+ /**
345
+ * Allowed JOSE algorithms for issuer-signed JWTs. `none` is always rejected.
346
+ */
347
+ allowedIssuerAlgorithms?: string[];
335
348
  /**
336
349
  * nonce used to verify the key binding jwt to prevent replay attacks.
337
350
  */
338
351
  keyBindingNonce?: string;
352
+ /**
353
+ * Expected audience for the Key Binding JWT.
354
+ */
355
+ expectedKeyBindingAudience?: string | string[];
356
+ /**
357
+ * Maximum acceptable age of the Key Binding JWT, in seconds.
358
+ */
359
+ keyBindingMaxAgeSeconds?: number;
360
+ /**
361
+ * Internal option used by SD-JWT validation to defer claim checks until after
362
+ * disclosures are processed.
363
+ */
364
+ skipJwtClaimValidation?: boolean;
339
365
  /**
340
366
  * disable the verification of the status claim in the payload.
341
367
  *
@@ -347,6 +373,7 @@ type VerifierOptions = {
347
373
  */
348
374
  [key: string]: unknown;
349
375
  };
376
+ declare const validateJwtPayload: (payload: Record<string, unknown> | undefined, options?: VerifierOptions) => void;
350
377
  declare class Jwt<Header extends Record<string, unknown> = Record<string, unknown>, Payload extends Record<string, unknown> = Record<string, unknown>> {
351
378
  header?: Header;
352
379
  payload?: Payload;
@@ -451,7 +478,7 @@ declare class SDJwt<Header extends Record<string, unknown> = Record<string, unkn
451
478
  getClaims<T>(hasher: Hasher): Promise<T>;
452
479
  }
453
480
  declare const listKeys: (obj: Record<string, unknown>, prefix?: string) => string[];
454
- declare const pack: <T extends Record<string, unknown>>(claims: T, disclosureFrame: DisclosureFrame<T> | undefined, hash: HasherAndAlg, saltGenerator: SaltGenerator) => Promise<{
481
+ declare const pack: <T extends Record<string, unknown>>(claims: T, disclosureFrame: DisclosureFrame<T> | undefined, hash: HasherAndAlg, saltGenerator: SaltGenerator, seenSalts?: Set<string>, seenDigests?: Set<string>) => Promise<{
455
482
  packedClaims: Record<string, unknown> | Array<Record<string, unknown>>;
456
483
  disclosures: Array<Disclosure>;
457
484
  }>;
@@ -476,7 +503,7 @@ declare const unpackObj: (obj: unknown, map: Record<string, Disclosure>) => {
476
503
  };
477
504
  declare const createHashMapping: (disclosures: Array<Disclosure>, hash: HasherAndAlg) => Promise<Record<string, Disclosure<unknown>>>;
478
505
  declare const createHashMappingSync: (disclosures: Array<Disclosure>, hash: HasherAndAlgSync) => Record<string, Disclosure<unknown>>;
479
- declare const getSDAlgAndPayload: (SdJwtPayload: Record<string, unknown>) => {
506
+ declare const getSDAlgAndPayload: (SdJwtPayload: Record<string, unknown>, allowedAlgorithms?: ReadonlyArray<HashAlgorithm>) => {
480
507
  _sd_alg: string;
481
508
  payload: {
482
509
  [x: string]: unknown;
@@ -516,7 +543,7 @@ declare const presentSync: <T extends Record<string, unknown>>(sdJwt: string, pr
516
543
  * @param prefix The prefix to add to the keys
517
544
  * @returns
518
545
  */
519
- declare const transformPresentationFrame: (obj: PresentationFrame<Extensible>, prefix?: string) => string[];
546
+ declare const transformPresentationFrame: (obj: PresentationFrame<Extensible>, prefix?: string[]) => string[];
520
547
  type SerializedDisclosure = {
521
548
  digest: string;
522
549
  encoded: string;
@@ -633,20 +660,20 @@ declare class SDJwtGeneralJSONInstance<ExtendedPayload extends SdJwtPayload> {
633
660
  }): Promise<GeneralJSON>;
634
661
  verify(generalJSON: GeneralJSON, options?: VerifierOptions): Promise<{
635
662
  payload: ExtendedPayload;
636
- headers: unknown[];
663
+ headers: Record<string, unknown>[];
637
664
  kb?: undefined;
638
665
  } | {
639
666
  payload: ExtendedPayload;
640
- headers: unknown[];
667
+ headers: Record<string, unknown>[];
641
668
  kb: {
642
669
  payload: kbPayload;
643
670
  header: kbHeader;
644
671
  };
645
672
  }>;
646
673
  private calculateSDHash;
647
- validate(generalJSON: GeneralJSON): Promise<{
674
+ validate(generalJSON: GeneralJSON, options?: VerifierOptions): Promise<{
648
675
  payload: ExtendedPayload;
649
- headers: unknown[];
676
+ headers: Record<string, unknown>[];
650
677
  }>;
651
678
  config(newConfig: SDJWTConfig): void;
652
679
  encode(sdJwt: GeneralJSON, index: number): SDJWTCompact;
@@ -656,4 +683,4 @@ declare class SDJwtGeneralJSONInstance<ExtendedPayload extends SdJwtPayload> {
656
683
  getClaims(generalSdjwt: GeneralJSON): Promise<unknown>;
657
684
  }
658
685
 
659
- export { type Base64urlString, type DECOY, type DecodedSDJwt, Disclosure, type DisclosureData, type DisclosureFrame, type Extensible, FlattenJSON, type FlattenJSONData, type FlattenJSONSerialized, GeneralJSON, type GeneralJSONData, type GeneralJSONSerialized, type HashAlgorithm, type Hasher, type HasherAndAlg, type HasherAndAlgSync, type HasherSync, IANA_HASH_ALGORITHMS, Jwt, type JwtData, type JwtPayload, KBJwt, type KBOptions, KB_JWT_TYP, type KbVerifier, type OrPromise, type PresentationFrame, type SD, type SDJWTCompact, type SDJWTConfig, SDJWTException, SDJwt, type SDJwtData, SDJwtGeneralJSONInstance, SDJwtInstance, SD_DECOY, SD_DIGEST, SD_LIST_KEY, SD_SEPARATOR, type SafeVerifyResult, type SaltGenerator, type SaltGeneratorSync, type SdJwtPayload, type SerializedDisclosure, type Signer, type SignerSync, type VerificationError, type VerificationErrorCode, type Verifier, type VerifierOptions, type VerifierSync, createDecoy, createHashMapping, createHashMappingForSerializedDisclosure, createHashMappingSync, decodeJwt, decodeSdJwt, decodeSdJwtSync, ensureError, getClaims, getClaimsSync, getSDAlgAndPayload, type kbHeader, type kbPayload, listKeys, pack, present, presentSync, presentableKeys, presentableKeysSync, selectDisclosures, splitSdJwt, transformPresentationFrame, unpack, unpackObj, unpackSync };
686
+ export { type Base64urlString, type DECOY, DEFAULT_SECURE_HASH_ALGORITHMS, type DecodedSDJwt, Disclosure, type DisclosureData, type DisclosureFrame, type Extensible, FlattenJSON, type FlattenJSONData, type FlattenJSONSerialized, GeneralJSON, type GeneralJSONData, type GeneralJSONSerialized, type HashAlgorithm, type Hasher, type HasherAndAlg, type HasherAndAlgSync, type HasherSync, IANA_HASH_ALGORITHMS, Jwt, type JwtData, type JwtPayload, KBJwt, type KBOptions, KB_JWT_TYP, type KbVerifier, type OrPromise, type PresentationFrame, type SD, type SDJWTCompact, type SDJWTConfig, SDJWTException, SDJwt, type SDJwtData, SDJwtGeneralJSONInstance, SDJwtInstance, SD_DECOY, SD_DIGEST, SD_LIST_KEY, SD_SEPARATOR, type SafeVerifyResult, type SaltGenerator, type SaltGeneratorSync, type SdJwtPayload, type SerializedDisclosure, type Signer, type SignerSync, type VerificationError, type VerificationErrorCode, type Verifier, type VerifierOptions, type VerifierSync, createDecoy, createHashMapping, createHashMappingForSerializedDisclosure, createHashMappingSync, decodeJwt, decodeSdJwt, decodeSdJwtSync, encodePath, encodePathSegment, ensureError, getClaims, getClaimsSync, getSDAlgAndPayload, type kbHeader, type kbPayload, listKeys, pack, present, presentSync, presentableKeys, presentableKeysSync, selectDisclosures, splitSdJwt, transformPresentationFrame, unpack, unpackObj, unpackSync, validateJwtPayload };