jose 4.15.4 → 5.0.1

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.
Files changed (155) hide show
  1. package/README.md +2 -1
  2. package/dist/browser/index.js +2 -4
  3. package/dist/browser/jwe/flattened/decrypt.js +13 -22
  4. package/dist/browser/jwe/flattened/encrypt.js +3 -18
  5. package/dist/browser/jwe/general/decrypt.js +1 -1
  6. package/dist/browser/jwe/general/encrypt.js +8 -13
  7. package/dist/browser/jwk/embedded.js +2 -2
  8. package/dist/browser/jwk/thumbprint.js +2 -2
  9. package/dist/browser/jwks/local.js +2 -2
  10. package/dist/browser/jwks/remote.js +4 -4
  11. package/dist/browser/jws/flattened/sign.js +1 -1
  12. package/dist/browser/jws/flattened/verify.js +6 -7
  13. package/dist/browser/jws/general/verify.js +1 -1
  14. package/dist/browser/jwt/produce.js +19 -4
  15. package/dist/browser/jwt/sign.js +1 -2
  16. package/dist/browser/jwt/unsecured.js +1 -1
  17. package/dist/browser/jwt/verify.js +1 -2
  18. package/dist/browser/key/import.js +1 -6
  19. package/dist/browser/lib/decrypt_key_management.js +6 -6
  20. package/dist/browser/lib/jwt_claims_set.js +1 -1
  21. package/dist/browser/runtime/asn1.js +1 -2
  22. package/dist/browser/runtime/base64url.js +1 -1
  23. package/dist/browser/runtime/decrypt.js +3 -3
  24. package/dist/browser/runtime/fetch_jwks.js +1 -1
  25. package/dist/browser/runtime/generate.js +5 -8
  26. package/dist/browser/runtime/jwk_to_key.js +2 -45
  27. package/dist/browser/runtime/verify.js +1 -1
  28. package/dist/browser/util/decode_jwt.js +2 -2
  29. package/dist/browser/util/decode_protected_header.js +1 -1
  30. package/dist/browser/util/errors.js +1 -2
  31. package/dist/node/cjs/jwe/compact/encrypt.js +1 -0
  32. package/dist/node/cjs/jwe/flattened/decrypt.js +7 -16
  33. package/dist/node/cjs/jwe/flattened/encrypt.js +12 -19
  34. package/dist/node/cjs/jwe/general/encrypt.js +16 -13
  35. package/dist/node/cjs/jwk/embedded.js +2 -2
  36. package/dist/node/cjs/jwk/thumbprint.js +2 -2
  37. package/dist/node/cjs/jwks/local.js +3 -2
  38. package/dist/node/cjs/jwks/remote.js +13 -6
  39. package/dist/node/cjs/jws/compact/sign.js +1 -0
  40. package/dist/node/cjs/jws/flattened/sign.js +4 -1
  41. package/dist/node/cjs/jws/flattened/verify.js +3 -4
  42. package/dist/node/cjs/jws/general/sign.js +7 -1
  43. package/dist/node/cjs/jwt/encrypt.js +7 -0
  44. package/dist/node/cjs/jwt/produce.js +20 -4
  45. package/dist/node/cjs/jwt/sign.js +2 -2
  46. package/dist/node/cjs/jwt/verify.js +1 -2
  47. package/dist/node/cjs/key/import.js +2 -7
  48. package/dist/node/cjs/lib/aesgcmkw.js +1 -1
  49. package/dist/node/cjs/lib/decrypt_key_management.js +1 -1
  50. package/dist/node/cjs/lib/encrypt_key_management.js +1 -1
  51. package/dist/node/cjs/runtime/aeskw.js +6 -6
  52. package/dist/node/cjs/runtime/asn1.js +8 -8
  53. package/dist/node/cjs/runtime/base64url.js +6 -11
  54. package/dist/node/cjs/runtime/cbc_tag.js +2 -2
  55. package/dist/node/cjs/runtime/check_key_length.js +8 -0
  56. package/dist/node/cjs/runtime/ciphers.js +2 -2
  57. package/dist/node/cjs/runtime/decrypt.js +4 -4
  58. package/dist/node/cjs/runtime/digest.js +2 -2
  59. package/dist/node/cjs/runtime/ecdhes.js +7 -7
  60. package/dist/node/cjs/runtime/encrypt.js +4 -4
  61. package/dist/node/cjs/runtime/fetch_jwks.js +4 -4
  62. package/dist/node/cjs/runtime/generate.js +7 -11
  63. package/dist/node/cjs/runtime/get_named_curve.js +7 -45
  64. package/dist/node/cjs/runtime/get_sign_verify_key.js +4 -4
  65. package/dist/node/cjs/runtime/is_key_like.js +1 -1
  66. package/dist/node/cjs/runtime/is_key_object.js +2 -5
  67. package/dist/node/cjs/runtime/jwk_to_key.js +2 -113
  68. package/dist/node/cjs/runtime/key_to_jwk.js +6 -130
  69. package/dist/node/cjs/runtime/node_key.js +9 -18
  70. package/dist/node/cjs/runtime/pbes2kw.js +4 -4
  71. package/dist/node/cjs/runtime/random.js +2 -2
  72. package/dist/node/cjs/runtime/rsaes.js +8 -8
  73. package/dist/node/cjs/runtime/sign.js +3 -9
  74. package/dist/node/cjs/runtime/timing_safe_equal.js +2 -2
  75. package/dist/node/cjs/runtime/verify.js +3 -10
  76. package/dist/node/cjs/runtime/webcrypto.js +4 -6
  77. package/dist/node/cjs/util/errors.js +26 -59
  78. package/dist/node/esm/jwe/compact/encrypt.js +1 -0
  79. package/dist/node/esm/jwe/flattened/decrypt.js +7 -16
  80. package/dist/node/esm/jwe/flattened/encrypt.js +12 -19
  81. package/dist/node/esm/jwe/general/encrypt.js +17 -14
  82. package/dist/node/esm/jwk/embedded.js +2 -2
  83. package/dist/node/esm/jwk/thumbprint.js +2 -2
  84. package/dist/node/esm/jwks/local.js +3 -2
  85. package/dist/node/esm/jwks/remote.js +13 -6
  86. package/dist/node/esm/jws/compact/sign.js +1 -0
  87. package/dist/node/esm/jws/flattened/sign.js +4 -1
  88. package/dist/node/esm/jws/flattened/verify.js +3 -4
  89. package/dist/node/esm/jws/general/sign.js +7 -1
  90. package/dist/node/esm/jwt/encrypt.js +7 -0
  91. package/dist/node/esm/jwt/produce.js +20 -4
  92. package/dist/node/esm/jwt/sign.js +2 -2
  93. package/dist/node/esm/jwt/verify.js +1 -2
  94. package/dist/node/esm/key/import.js +2 -7
  95. package/dist/node/esm/lib/aesgcmkw.js +1 -1
  96. package/dist/node/esm/lib/decrypt_key_management.js +1 -1
  97. package/dist/node/esm/lib/encrypt_key_management.js +1 -1
  98. package/dist/node/esm/runtime/aeskw.js +2 -2
  99. package/dist/node/esm/runtime/asn1.js +2 -2
  100. package/dist/node/esm/runtime/base64url.js +4 -10
  101. package/dist/node/esm/runtime/cbc_tag.js +1 -1
  102. package/dist/node/esm/runtime/check_key_length.js +6 -0
  103. package/dist/node/esm/runtime/ciphers.js +2 -2
  104. package/dist/node/esm/runtime/decrypt.js +1 -1
  105. package/dist/node/esm/runtime/digest.js +1 -1
  106. package/dist/node/esm/runtime/ecdhes.js +2 -2
  107. package/dist/node/esm/runtime/encrypt.js +1 -1
  108. package/dist/node/esm/runtime/fetch_jwks.js +3 -3
  109. package/dist/node/esm/runtime/generate.js +5 -9
  110. package/dist/node/esm/runtime/get_named_curve.js +5 -42
  111. package/dist/node/esm/runtime/get_sign_verify_key.js +1 -1
  112. package/dist/node/esm/runtime/is_key_like.js +1 -1
  113. package/dist/node/esm/runtime/is_key_object.js +2 -5
  114. package/dist/node/esm/runtime/jwk_to_key.js +2 -113
  115. package/dist/node/esm/runtime/key_to_jwk.js +5 -129
  116. package/dist/node/esm/runtime/node_key.js +7 -16
  117. package/dist/node/esm/runtime/pbes2kw.js +2 -2
  118. package/dist/node/esm/runtime/random.js +1 -1
  119. package/dist/node/esm/runtime/rsaes.js +3 -3
  120. package/dist/node/esm/runtime/sign.js +3 -9
  121. package/dist/node/esm/runtime/timing_safe_equal.js +1 -1
  122. package/dist/node/esm/runtime/verify.js +3 -10
  123. package/dist/node/esm/runtime/webcrypto.js +3 -6
  124. package/dist/node/esm/util/errors.js +26 -59
  125. package/dist/types/index.d.ts +1 -1
  126. package/dist/types/jwe/compact/decrypt.d.ts +1 -1
  127. package/dist/types/jwe/flattened/decrypt.d.ts +1 -1
  128. package/dist/types/jwe/general/decrypt.d.ts +1 -1
  129. package/dist/types/jwe/general/encrypt.d.ts +3 -7
  130. package/dist/types/jwk/embedded.d.ts +1 -1
  131. package/dist/types/jwks/local.d.ts +3 -3
  132. package/dist/types/jwks/remote.d.ts +1 -1
  133. package/dist/types/jws/compact/verify.d.ts +1 -1
  134. package/dist/types/jws/flattened/verify.d.ts +1 -1
  135. package/dist/types/jws/general/verify.d.ts +1 -1
  136. package/dist/types/jwt/decrypt.d.ts +3 -3
  137. package/dist/types/jwt/produce.d.ts +12 -12
  138. package/dist/types/jwt/unsecured.d.ts +3 -3
  139. package/dist/types/jwt/verify.d.ts +3 -3
  140. package/dist/types/key/generate_key_pair.d.ts +7 -5
  141. package/dist/types/key/generate_secret.d.ts +1 -1
  142. package/dist/types/key/import.d.ts +4 -6
  143. package/dist/types/types.d.ts +13 -50
  144. package/package.json +1 -1
  145. package/dist/browser/runtime/zlib.js +0 -7
  146. package/dist/node/cjs/runtime/asn1_sequence_decoder.js +0 -47
  147. package/dist/node/cjs/runtime/asn1_sequence_encoder.js +0 -91
  148. package/dist/node/cjs/runtime/check_modulus_length.js +0 -52
  149. package/dist/node/cjs/runtime/flags.js +0 -8
  150. package/dist/node/cjs/runtime/zlib.js +0 -11
  151. package/dist/node/esm/runtime/asn1_sequence_decoder.js +0 -44
  152. package/dist/node/esm/runtime/asn1_sequence_encoder.js +0 -88
  153. package/dist/node/esm/runtime/check_modulus_length.js +0 -48
  154. package/dist/node/esm/runtime/flags.js +0 -5
  155. package/dist/node/esm/runtime/zlib.js +0 -6
@@ -2,53 +2,53 @@ import type { JWTPayload } from '../types';
2
2
  /** Generic class for JWT producing. */
3
3
  export declare class ProduceJWT {
4
4
  protected _payload: JWTPayload;
5
- /** @param payload The JWT Claims Set object. */
6
- constructor(payload: JWTPayload);
5
+ /** @param payload The JWT Claims Set object. Defaults to an empty object. */
6
+ constructor(payload?: JWTPayload);
7
7
  /**
8
- * Set "iss" (Issuer) Claim.
8
+ * Set the "iss" (Issuer) Claim.
9
9
  *
10
10
  * @param issuer "Issuer" Claim value to set on the JWT Claims Set.
11
11
  */
12
12
  setIssuer(issuer: string): this;
13
13
  /**
14
- * Set "sub" (Subject) Claim.
14
+ * Set the "sub" (Subject) Claim.
15
15
  *
16
16
  * @param subject "sub" (Subject) Claim value to set on the JWT Claims Set.
17
17
  */
18
18
  setSubject(subject: string): this;
19
19
  /**
20
- * Set "aud" (Audience) Claim.
20
+ * Set the "aud" (Audience) Claim.
21
21
  *
22
22
  * @param audience "aud" (Audience) Claim value to set on the JWT Claims Set.
23
23
  */
24
24
  setAudience(audience: string | string[]): this;
25
25
  /**
26
- * Set "jti" (JWT ID) Claim.
26
+ * Set the "jti" (JWT ID) Claim.
27
27
  *
28
28
  * @param jwtId "jti" (JWT ID) Claim value to set on the JWT Claims Set.
29
29
  */
30
30
  setJti(jwtId: string): this;
31
31
  /**
32
- * Set "nbf" (Not Before) Claim.
32
+ * Set the "nbf" (Not Before) Claim.
33
33
  *
34
34
  * @param input "nbf" (Not Before) Claim value to set on the JWT Claims Set. When number is passed
35
35
  * that is used as a value, when string is passed it is resolved to a time span and added to the
36
36
  * current timestamp.
37
37
  */
38
- setNotBefore(input: number | string): this;
38
+ setNotBefore(input: number | string | Date): this;
39
39
  /**
40
- * Set "exp" (Expiration Time) Claim.
40
+ * Set the "exp" (Expiration Time) Claim.
41
41
  *
42
42
  * @param input "exp" (Expiration Time) Claim value to set on the JWT Claims Set. When number is
43
43
  * passed that is used as a value, when string is passed it is resolved to a time span and added
44
44
  * to the current timestamp.
45
45
  */
46
- setExpirationTime(input: number | string): this;
46
+ setExpirationTime(input: number | string | Date): this;
47
47
  /**
48
- * Set "iat" (Issued At) Claim.
48
+ * Set the "iat" (Issued At) Claim.
49
49
  *
50
50
  * @param input "iat" (Issued At) Claim value to set on the JWT Claims Set. Default is current
51
51
  * timestamp.
52
52
  */
53
- setIssuedAt(input?: number): this;
53
+ setIssuedAt(input?: number | Date): this;
54
54
  }
@@ -1,7 +1,7 @@
1
1
  import type { JWSHeaderParameters, JWTClaimVerificationOptions, JWTPayload } from '../types';
2
2
  import { ProduceJWT } from './produce';
3
- export interface UnsecuredResult {
4
- payload: JWTPayload;
3
+ export interface UnsecuredResult<PayloadType = JWTPayload> {
4
+ payload: PayloadType & JWTPayload;
5
5
  header: JWSHeaderParameters;
6
6
  }
7
7
  /**
@@ -17,5 +17,5 @@ export declare class UnsecuredJWT extends ProduceJWT {
17
17
  * @param jwt Unsecured JWT to decode the payload of.
18
18
  * @param options JWT Claims Set validation options.
19
19
  */
20
- static decode(jwt: string, options?: JWTClaimVerificationOptions): UnsecuredResult;
20
+ static decode<PayloadType = JWTPayload>(jwt: string, options?: JWTClaimVerificationOptions): UnsecuredResult<PayloadType>;
21
21
  }
@@ -1,4 +1,4 @@
1
- import type { KeyLike, VerifyOptions, JWTClaimVerificationOptions, JWTHeaderParameters, GetKeyFunction, FlattenedJWSInput, JWTVerifyResult, ResolvedKey } from '../types';
1
+ import type { JWTPayload, KeyLike, VerifyOptions, JWTClaimVerificationOptions, JWTHeaderParameters, GetKeyFunction, FlattenedJWSInput, JWTVerifyResult, ResolvedKey } from '../types';
2
2
  /** Combination of JWS Verification options and JWT Claims Set verification options. */
3
3
  export interface JWTVerifyOptions extends VerifyOptions, JWTClaimVerificationOptions {
4
4
  }
@@ -19,11 +19,11 @@ export interface JWTVerifyGetKey extends GetKeyFunction<JWTHeaderParameters, Fla
19
19
  * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
20
20
  * @param options JWT Decryption and JWT Claims Set validation options.
21
21
  */
22
- export declare function jwtVerify(jwt: string | Uint8Array, key: KeyLike | Uint8Array, options?: JWTVerifyOptions): Promise<JWTVerifyResult>;
22
+ export declare function jwtVerify<PayloadType = JWTPayload>(jwt: string | Uint8Array, key: KeyLike | Uint8Array, options?: JWTVerifyOptions): Promise<JWTVerifyResult<PayloadType>>;
23
23
  /**
24
24
  * @param jwt JSON Web Token value (encoded as JWS).
25
25
  * @param getKey Function resolving a key to verify the JWT with. See
26
26
  * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
27
27
  * @param options JWT Decryption and JWT Claims Set validation options.
28
28
  */
29
- export declare function jwtVerify<T extends KeyLike = KeyLike>(jwt: string | Uint8Array, getKey: JWTVerifyGetKey, options?: JWTVerifyOptions): Promise<JWTVerifyResult & ResolvedKey<T>>;
29
+ export declare function jwtVerify<PayloadType = JWTPayload, KeyLikeType extends KeyLike = KeyLike>(jwt: string | Uint8Array, getKey: JWTVerifyGetKey, options?: JWTVerifyOptions): Promise<JWTVerifyResult<PayloadType> & ResolvedKey<KeyLikeType>>;
@@ -1,9 +1,9 @@
1
1
  import type { KeyLike } from '../types';
2
- export interface GenerateKeyPairResult<T extends KeyLike = KeyLike> {
2
+ export interface GenerateKeyPairResult<KeyLikeType extends KeyLike = KeyLike> {
3
3
  /** The generated Private Key. */
4
- privateKey: T;
4
+ privateKey: KeyLikeType;
5
5
  /** Public Key corresponding to the generated Private Key. */
6
- publicKey: T;
6
+ publicKey: KeyLikeType;
7
7
  }
8
8
  export interface GenerateKeyPairOptions {
9
9
  /**
@@ -20,6 +20,7 @@ export interface GenerateKeyPairOptions {
20
20
  * (Only effective in Web Crypto API runtimes) The value to use as
21
21
  * {@link https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey SubtleCrypto.generateKey()}
22
22
  * `extractable` argument. Default is false.
23
+ *
23
24
  */
24
25
  extractable?: boolean;
25
26
  }
@@ -28,9 +29,10 @@ export interface GenerateKeyPairOptions {
28
29
  * asymmetric key pairs. For symmetric secrets use the `generateSecret` function.
29
30
  *
30
31
  * Note: Under Web Crypto API runtime the `privateKey` is generated with `extractable` set to
31
- * `false` by default.
32
+ * `false` by default. See {@link GenerateKeyPairOptions.extractable} to generate an extractable
33
+ * `privateKey`.
32
34
  *
33
35
  * @param alg JWA Algorithm Identifier to be used with the generated key pair.
34
36
  * @param options Additional options passed down to the key pair generation.
35
37
  */
36
- export declare function generateKeyPair<T extends KeyLike = KeyLike>(alg: string, options?: GenerateKeyPairOptions): Promise<GenerateKeyPairResult<T>>;
38
+ export declare function generateKeyPair<KeyLikeType extends KeyLike = KeyLike>(alg: string, options?: GenerateKeyPairOptions): Promise<GenerateKeyPairResult<KeyLikeType>>;
@@ -16,4 +16,4 @@ export interface GenerateSecretOptions {
16
16
  * @param alg JWA Algorithm Identifier to be used with the generated secret.
17
17
  * @param options Additional options passed down to the secret generation.
18
18
  */
19
- export declare function generateSecret<T extends KeyLike = KeyLike>(alg: string, options?: GenerateSecretOptions): Promise<T | Uint8Array>;
19
+ export declare function generateSecret<KeyLikeType extends KeyLike = KeyLike>(alg: string, options?: GenerateSecretOptions): Promise<KeyLikeType | Uint8Array>;
@@ -16,7 +16,7 @@ export interface PEMImportOptions {
16
16
  * with the imported key, its presence is only enforced in Web Crypto API runtimes. See
17
17
  * {@link https://github.com/panva/jose/issues/210 Algorithm Key Requirements}.
18
18
  */
19
- export declare function importSPKI<T extends KeyLike = KeyLike>(spki: string, alg: string, options?: PEMImportOptions): Promise<T>;
19
+ export declare function importSPKI<KeyLikeType extends KeyLike = KeyLike>(spki: string, alg: string, options?: PEMImportOptions): Promise<KeyLikeType>;
20
20
  /**
21
21
  * Imports the SPKI from an X.509 string certificate as a runtime-specific public key representation
22
22
  * (KeyObject or CryptoKey).
@@ -26,7 +26,7 @@ export declare function importSPKI<T extends KeyLike = KeyLike>(spki: string, al
26
26
  * with the imported key, its presence is only enforced in Web Crypto API runtimes. See
27
27
  * {@link https://github.com/panva/jose/issues/210 Algorithm Key Requirements}.
28
28
  */
29
- export declare function importX509<T extends KeyLike = KeyLike>(x509: string, alg: string, options?: PEMImportOptions): Promise<T>;
29
+ export declare function importX509<KeyLikeType extends KeyLike = KeyLike>(x509: string, alg: string, options?: PEMImportOptions): Promise<KeyLikeType>;
30
30
  /**
31
31
  * Imports a PEM-encoded PKCS#8 string as a runtime-specific private key representation (KeyObject
32
32
  * or CryptoKey).
@@ -36,7 +36,7 @@ export declare function importX509<T extends KeyLike = KeyLike>(x509: string, al
36
36
  * with the imported key, its presence is only enforced in Web Crypto API runtimes. See
37
37
  * {@link https://github.com/panva/jose/issues/210 Algorithm Key Requirements}.
38
38
  */
39
- export declare function importPKCS8<T extends KeyLike = KeyLike>(pkcs8: string, alg: string, options?: PEMImportOptions): Promise<T>;
39
+ export declare function importPKCS8<KeyLikeType extends KeyLike = KeyLike>(pkcs8: string, alg: string, options?: PEMImportOptions): Promise<KeyLikeType>;
40
40
  /**
41
41
  * Imports a JWK to a runtime-specific key representation (KeyLike). Either JWK "alg" (Algorithm)
42
42
  * Parameter must be present or the optional "alg" argument. When running on a runtime using
@@ -48,7 +48,5 @@ export declare function importPKCS8<T extends KeyLike = KeyLike>(pkcs8: string,
48
48
  * with the imported key. Default is the "alg" property on the JWK, its presence is only enforced
49
49
  * in Web Crypto API runtimes. See
50
50
  * {@link https://github.com/panva/jose/issues/210 Algorithm Key Requirements}.
51
- * @param octAsKeyObject Forces a symmetric key to be imported to a KeyObject or CryptoKey. Default
52
- * is true unless JWK "ext" (Extractable) is true.
53
51
  */
54
- export declare function importJWK<T extends KeyLike = KeyLike>(jwk: JWK, alg?: string, octAsKeyObject?: boolean): Promise<T | Uint8Array>;
52
+ export declare function importJWK<KeyLikeType extends KeyLike = KeyLike>(jwk: JWK, alg?: string): Promise<KeyLikeType | Uint8Array>;
@@ -304,7 +304,7 @@ export interface JWEHeaderParameters extends JoseHeaderParameters {
304
304
  crit?: string[]
305
305
 
306
306
  /**
307
- * JWE "zip" (Compression Algorithm) Header Parameter.
307
+ * JWE "zip" (Compression Algorithm) Header Parameter. This parameter is not supported anymore.
308
308
  *
309
309
  * @deprecated Compression of data SHOULD NOT be done before encryption, because such compressed
310
310
  * data often reveals information about the plaintext.
@@ -344,7 +344,11 @@ export interface CritOption {
344
344
 
345
345
  /** JWE Decryption options. */
346
346
  export interface DecryptOptions extends CritOption {
347
- /** A list of accepted JWE "alg" (Algorithm) Header Parameter values. */
347
+ /**
348
+ * A list of accepted JWE "alg" (Algorithm) Header Parameter values. By default all "alg"
349
+ * (Algorithm) Header Parameter values applicable for the used key/secret are allowed except for
350
+ * all PBES2 Key Management Algorithms, these need to be explicitly allowed using this option.
351
+ */
348
352
  keyManagementAlgorithms?: string[]
349
353
 
350
354
  /**
@@ -353,12 +357,6 @@ export interface DecryptOptions extends CritOption {
353
357
  */
354
358
  contentEncryptionAlgorithms?: string[]
355
359
 
356
- /**
357
- * In a browser runtime you have to provide an implementation for Inflate Raw when you expect JWEs
358
- * with compressed plaintext.
359
- */
360
- inflateRaw?: InflateFunction
361
-
362
360
  /**
363
361
  * (PBES2 Key Management Algorithms only) Maximum allowed "p2c" (PBES2 Count) Header Parameter
364
362
  * value. The PBKDF2 iteration count defines the algorithm's computational expense. By default
@@ -367,17 +365,8 @@ export interface DecryptOptions extends CritOption {
367
365
  maxPBES2Count?: number
368
366
  }
369
367
 
370
- /** JWE Deflate option. */
371
- export interface DeflateOption {
372
- /**
373
- * In a browser runtime you have to provide an implementation for Deflate Raw when you will be
374
- * producing JWEs with compressed plaintext.
375
- */
376
- deflateRaw?: DeflateFunction
377
- }
378
-
379
368
  /** JWE Encryption options. */
380
- export interface EncryptOptions extends CritOption, DeflateOption {}
369
+ export interface EncryptOptions extends CritOption {}
381
370
 
382
371
  /** JWT Claims Set verification options. */
383
372
  export interface JWTClaimVerificationOptions {
@@ -491,32 +480,6 @@ export interface JWTPayload {
491
480
  [propName: string]: unknown
492
481
  }
493
482
 
494
- /**
495
- * Deflate Raw implementation, e.g. promisified
496
- * {@link https://nodejs.org/api/zlib.html#zlibdeflaterawbuffer-options-callback zlib.deflateRaw}.
497
- *
498
- * @deprecated Compression of data SHOULD NOT be done before encryption, because such compressed
499
- * data often reveals information about the plaintext.
500
- *
501
- * @see {@link https://www.rfc-editor.org/rfc/rfc8725#name-avoid-compression-of-encryp Avoid Compression of Encryption Inputs}
502
- */
503
- export interface DeflateFunction {
504
- (input: Uint8Array): Promise<Uint8Array>
505
- }
506
-
507
- /**
508
- * Inflate Raw implementation, e.g. promisified
509
- * {@link https://nodejs.org/api/zlib.html#zlibinflaterawbuffer-options-callback zlib.inflateRaw}.
510
- *
511
- * @deprecated Compression of data SHOULD NOT be done before encryption, because such compressed
512
- * data often reveals information about the plaintext.
513
- *
514
- * @see {@link https://www.rfc-editor.org/rfc/rfc8725#name-avoid-compression-of-encryp Avoid Compression of Encryption Inputs}
515
- */
516
- export interface InflateFunction {
517
- (input: Uint8Array): Promise<Uint8Array>
518
- }
519
-
520
483
  export interface FlattenedDecryptResult {
521
484
  /** JWE AAD. */
522
485
  additionalAuthenticatedData?: Uint8Array
@@ -565,25 +528,25 @@ export interface CompactVerifyResult {
565
528
  protectedHeader: CompactJWSHeaderParameters
566
529
  }
567
530
 
568
- export interface JWTVerifyResult {
531
+ export interface JWTVerifyResult<PayloadType = JWTPayload> {
569
532
  /** JWT Claims Set. */
570
- payload: JWTPayload
533
+ payload: PayloadType & JWTPayload
571
534
 
572
535
  /** JWS Protected Header. */
573
536
  protectedHeader: JWTHeaderParameters
574
537
  }
575
538
 
576
- export interface JWTDecryptResult {
539
+ export interface JWTDecryptResult<PayloadType = JWTPayload> {
577
540
  /** JWT Claims Set. */
578
- payload: JWTPayload
541
+ payload: PayloadType & JWTPayload
579
542
 
580
543
  /** JWE Protected Header. */
581
544
  protectedHeader: CompactJWEHeaderParameters
582
545
  }
583
546
 
584
- export interface ResolvedKey<T extends KeyLike = KeyLike> {
547
+ export interface ResolvedKey<KeyLikeType extends KeyLike = KeyLike> {
585
548
  /** Key resolved from the key resolver function. */
586
- key: T | Uint8Array
549
+ key: KeyLikeType | Uint8Array
587
550
  }
588
551
 
589
552
  /** Recognized Compact JWS Header Parameters, any other Header Members may also be present. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jose",
3
- "version": "4.15.4",
3
+ "version": "5.0.1",
4
4
  "description": "'JSON Web Almost Everything' - JWA, JWS, JWE, JWT, JWK, JWKS for Node.js, Browser, Cloudflare Workers, Deno, Bun, and other Web-interoperable runtimes",
5
5
  "keywords": [
6
6
  "browser",
@@ -1,7 +0,0 @@
1
- import { JOSENotSupported } from '../util/errors.js';
2
- export const inflate = async () => {
3
- throw new JOSENotSupported('JWE "zip" (Compression Algorithm) Header Parameter is not supported by your javascript runtime. You need to use the `inflateRaw` decrypt option to provide Inflate Raw implementation.');
4
- };
5
- export const deflate = async () => {
6
- throw new JOSENotSupported('JWE "zip" (Compression Algorithm) Header Parameter is not supported by your javascript runtime. You need to use the `deflateRaw` encrypt option to provide Deflate Raw implementation.');
7
- };
@@ -1,47 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tagInteger = 0x02;
4
- const tagSequence = 0x30;
5
- class Asn1SequenceDecoder {
6
- constructor(buffer) {
7
- if (buffer[0] !== tagSequence) {
8
- throw new TypeError();
9
- }
10
- this.buffer = buffer;
11
- this.offset = 1;
12
- const len = this.decodeLength();
13
- if (len !== buffer.length - this.offset) {
14
- throw new TypeError();
15
- }
16
- }
17
- decodeLength() {
18
- let length = this.buffer[this.offset++];
19
- if (length & 0x80) {
20
- const nBytes = length & ~0x80;
21
- length = 0;
22
- for (let i = 0; i < nBytes; i++)
23
- length = (length << 8) | this.buffer[this.offset + i];
24
- this.offset += nBytes;
25
- }
26
- return length;
27
- }
28
- unsignedInteger() {
29
- if (this.buffer[this.offset++] !== tagInteger) {
30
- throw new TypeError();
31
- }
32
- let length = this.decodeLength();
33
- if (this.buffer[this.offset] === 0) {
34
- this.offset++;
35
- length--;
36
- }
37
- const result = this.buffer.slice(this.offset, this.offset + length);
38
- this.offset += length;
39
- return result;
40
- }
41
- end() {
42
- if (this.offset !== this.buffer.length) {
43
- throw new TypeError();
44
- }
45
- }
46
- }
47
- exports.default = Asn1SequenceDecoder;
@@ -1,91 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const buffer_1 = require("buffer");
4
- const errors_js_1 = require("../util/errors.js");
5
- const tagInteger = 0x02;
6
- const tagBitStr = 0x03;
7
- const tagOctStr = 0x04;
8
- const tagSequence = 0x30;
9
- const bZero = buffer_1.Buffer.from([0x00]);
10
- const bTagInteger = buffer_1.Buffer.from([tagInteger]);
11
- const bTagBitStr = buffer_1.Buffer.from([tagBitStr]);
12
- const bTagSequence = buffer_1.Buffer.from([tagSequence]);
13
- const bTagOctStr = buffer_1.Buffer.from([tagOctStr]);
14
- const encodeLength = (len) => {
15
- if (len < 128)
16
- return buffer_1.Buffer.from([len]);
17
- const buffer = buffer_1.Buffer.alloc(5);
18
- buffer.writeUInt32BE(len, 1);
19
- let offset = 1;
20
- while (buffer[offset] === 0)
21
- offset++;
22
- buffer[offset - 1] = 0x80 | (5 - offset);
23
- return buffer.slice(offset - 1);
24
- };
25
- const oids = new Map([
26
- ['P-256', buffer_1.Buffer.from('06 08 2A 86 48 CE 3D 03 01 07'.replace(/ /g, ''), 'hex')],
27
- ['secp256k1', buffer_1.Buffer.from('06 05 2B 81 04 00 0A'.replace(/ /g, ''), 'hex')],
28
- ['P-384', buffer_1.Buffer.from('06 05 2B 81 04 00 22'.replace(/ /g, ''), 'hex')],
29
- ['P-521', buffer_1.Buffer.from('06 05 2B 81 04 00 23'.replace(/ /g, ''), 'hex')],
30
- ['ecPublicKey', buffer_1.Buffer.from('06 07 2A 86 48 CE 3D 02 01'.replace(/ /g, ''), 'hex')],
31
- ['X25519', buffer_1.Buffer.from('06 03 2B 65 6E'.replace(/ /g, ''), 'hex')],
32
- ['X448', buffer_1.Buffer.from('06 03 2B 65 6F'.replace(/ /g, ''), 'hex')],
33
- ['Ed25519', buffer_1.Buffer.from('06 03 2B 65 70'.replace(/ /g, ''), 'hex')],
34
- ['Ed448', buffer_1.Buffer.from('06 03 2B 65 71'.replace(/ /g, ''), 'hex')],
35
- ]);
36
- class DumbAsn1Encoder {
37
- constructor() {
38
- this.length = 0;
39
- this.elements = [];
40
- }
41
- oidFor(oid) {
42
- const bOid = oids.get(oid);
43
- if (!bOid) {
44
- throw new errors_js_1.JOSENotSupported('Invalid or unsupported OID');
45
- }
46
- this.elements.push(bOid);
47
- this.length += bOid.length;
48
- }
49
- zero() {
50
- this.elements.push(bTagInteger, buffer_1.Buffer.from([0x01]), bZero);
51
- this.length += 3;
52
- }
53
- one() {
54
- this.elements.push(bTagInteger, buffer_1.Buffer.from([0x01]), buffer_1.Buffer.from([0x01]));
55
- this.length += 3;
56
- }
57
- unsignedInteger(integer) {
58
- if (integer[0] & 0x80) {
59
- const len = encodeLength(integer.length + 1);
60
- this.elements.push(bTagInteger, len, bZero, integer);
61
- this.length += 2 + len.length + integer.length;
62
- }
63
- else {
64
- let i = 0;
65
- while (integer[i] === 0 && (integer[i + 1] & 0x80) === 0)
66
- i++;
67
- const len = encodeLength(integer.length - i);
68
- this.elements.push(bTagInteger, encodeLength(integer.length - i), integer.slice(i));
69
- this.length += 1 + len.length + integer.length - i;
70
- }
71
- }
72
- octStr(octStr) {
73
- const len = encodeLength(octStr.length);
74
- this.elements.push(bTagOctStr, encodeLength(octStr.length), octStr);
75
- this.length += 1 + len.length + octStr.length;
76
- }
77
- bitStr(bitS) {
78
- const len = encodeLength(bitS.length + 1);
79
- this.elements.push(bTagBitStr, encodeLength(bitS.length + 1), bZero, bitS);
80
- this.length += 1 + len.length + bitS.length + 1;
81
- }
82
- add(seq) {
83
- this.elements.push(seq);
84
- this.length += seq.length;
85
- }
86
- end(tag = bTagSequence) {
87
- const len = encodeLength(this.length);
88
- return buffer_1.Buffer.concat([tag, len, ...this.elements], 1 + len.length + this.length);
89
- }
90
- }
91
- exports.default = DumbAsn1Encoder;
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setModulusLength = exports.weakMap = void 0;
4
- exports.weakMap = new WeakMap();
5
- const getLength = (buf, index) => {
6
- let len = buf.readUInt8(1);
7
- if ((len & 0x80) === 0) {
8
- if (index === 0) {
9
- return len;
10
- }
11
- return getLength(buf.subarray(2 + len), index - 1);
12
- }
13
- const num = len & 0x7f;
14
- len = 0;
15
- for (let i = 0; i < num; i++) {
16
- len <<= 8;
17
- const j = buf.readUInt8(2 + i);
18
- len |= j;
19
- }
20
- if (index === 0) {
21
- return len;
22
- }
23
- return getLength(buf.subarray(2 + len), index - 1);
24
- };
25
- const getLengthOfSeqIndex = (sequence, index) => {
26
- const len = sequence.readUInt8(1);
27
- if ((len & 0x80) === 0) {
28
- return getLength(sequence.subarray(2), index);
29
- }
30
- const num = len & 0x7f;
31
- return getLength(sequence.subarray(2 + num), index);
32
- };
33
- const getModulusLength = (key) => {
34
- var _a, _b;
35
- if (exports.weakMap.has(key)) {
36
- return exports.weakMap.get(key);
37
- }
38
- const modulusLength = (_b = (_a = key.asymmetricKeyDetails) === null || _a === void 0 ? void 0 : _a.modulusLength) !== null && _b !== void 0 ? _b : (getLengthOfSeqIndex(key.export({ format: 'der', type: 'pkcs1' }), key.type === 'private' ? 1 : 0) -
39
- 1) <<
40
- 3;
41
- exports.weakMap.set(key, modulusLength);
42
- return modulusLength;
43
- };
44
- const setModulusLength = (keyObject, modulusLength) => {
45
- exports.weakMap.set(keyObject, modulusLength);
46
- };
47
- exports.setModulusLength = setModulusLength;
48
- exports.default = (key, alg) => {
49
- if (getModulusLength(key) < 2048) {
50
- throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
51
- }
52
- };
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.jwkImport = exports.jwkExport = exports.rsaPssParams = exports.oneShotCallback = void 0;
4
- const [major, minor] = process.versions.node.split('.').map((str) => parseInt(str, 10));
5
- exports.oneShotCallback = major >= 16 || (major === 15 && minor >= 13);
6
- exports.rsaPssParams = !('electron' in process.versions) && (major >= 17 || (major === 16 && minor >= 9));
7
- exports.jwkExport = major >= 16 || (major === 15 && minor >= 9);
8
- exports.jwkImport = major >= 16 || (major === 15 && minor >= 12);
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.deflate = exports.inflate = void 0;
4
- const util_1 = require("util");
5
- const zlib_1 = require("zlib");
6
- const inflateRaw = (0, util_1.promisify)(zlib_1.inflateRaw);
7
- const deflateRaw = (0, util_1.promisify)(zlib_1.deflateRaw);
8
- const inflate = (input) => inflateRaw(input);
9
- exports.inflate = inflate;
10
- const deflate = (input) => deflateRaw(input);
11
- exports.deflate = deflate;
@@ -1,44 +0,0 @@
1
- const tagInteger = 0x02;
2
- const tagSequence = 0x30;
3
- export default class Asn1SequenceDecoder {
4
- constructor(buffer) {
5
- if (buffer[0] !== tagSequence) {
6
- throw new TypeError();
7
- }
8
- this.buffer = buffer;
9
- this.offset = 1;
10
- const len = this.decodeLength();
11
- if (len !== buffer.length - this.offset) {
12
- throw new TypeError();
13
- }
14
- }
15
- decodeLength() {
16
- let length = this.buffer[this.offset++];
17
- if (length & 0x80) {
18
- const nBytes = length & ~0x80;
19
- length = 0;
20
- for (let i = 0; i < nBytes; i++)
21
- length = (length << 8) | this.buffer[this.offset + i];
22
- this.offset += nBytes;
23
- }
24
- return length;
25
- }
26
- unsignedInteger() {
27
- if (this.buffer[this.offset++] !== tagInteger) {
28
- throw new TypeError();
29
- }
30
- let length = this.decodeLength();
31
- if (this.buffer[this.offset] === 0) {
32
- this.offset++;
33
- length--;
34
- }
35
- const result = this.buffer.slice(this.offset, this.offset + length);
36
- this.offset += length;
37
- return result;
38
- }
39
- end() {
40
- if (this.offset !== this.buffer.length) {
41
- throw new TypeError();
42
- }
43
- }
44
- }
@@ -1,88 +0,0 @@
1
- import { Buffer } from 'buffer';
2
- import { JOSENotSupported } from '../util/errors.js';
3
- const tagInteger = 0x02;
4
- const tagBitStr = 0x03;
5
- const tagOctStr = 0x04;
6
- const tagSequence = 0x30;
7
- const bZero = Buffer.from([0x00]);
8
- const bTagInteger = Buffer.from([tagInteger]);
9
- const bTagBitStr = Buffer.from([tagBitStr]);
10
- const bTagSequence = Buffer.from([tagSequence]);
11
- const bTagOctStr = Buffer.from([tagOctStr]);
12
- const encodeLength = (len) => {
13
- if (len < 128)
14
- return Buffer.from([len]);
15
- const buffer = Buffer.alloc(5);
16
- buffer.writeUInt32BE(len, 1);
17
- let offset = 1;
18
- while (buffer[offset] === 0)
19
- offset++;
20
- buffer[offset - 1] = 0x80 | (5 - offset);
21
- return buffer.slice(offset - 1);
22
- };
23
- const oids = new Map([
24
- ['P-256', Buffer.from('06 08 2A 86 48 CE 3D 03 01 07'.replace(/ /g, ''), 'hex')],
25
- ['secp256k1', Buffer.from('06 05 2B 81 04 00 0A'.replace(/ /g, ''), 'hex')],
26
- ['P-384', Buffer.from('06 05 2B 81 04 00 22'.replace(/ /g, ''), 'hex')],
27
- ['P-521', Buffer.from('06 05 2B 81 04 00 23'.replace(/ /g, ''), 'hex')],
28
- ['ecPublicKey', Buffer.from('06 07 2A 86 48 CE 3D 02 01'.replace(/ /g, ''), 'hex')],
29
- ['X25519', Buffer.from('06 03 2B 65 6E'.replace(/ /g, ''), 'hex')],
30
- ['X448', Buffer.from('06 03 2B 65 6F'.replace(/ /g, ''), 'hex')],
31
- ['Ed25519', Buffer.from('06 03 2B 65 70'.replace(/ /g, ''), 'hex')],
32
- ['Ed448', Buffer.from('06 03 2B 65 71'.replace(/ /g, ''), 'hex')],
33
- ]);
34
- export default class DumbAsn1Encoder {
35
- constructor() {
36
- this.length = 0;
37
- this.elements = [];
38
- }
39
- oidFor(oid) {
40
- const bOid = oids.get(oid);
41
- if (!bOid) {
42
- throw new JOSENotSupported('Invalid or unsupported OID');
43
- }
44
- this.elements.push(bOid);
45
- this.length += bOid.length;
46
- }
47
- zero() {
48
- this.elements.push(bTagInteger, Buffer.from([0x01]), bZero);
49
- this.length += 3;
50
- }
51
- one() {
52
- this.elements.push(bTagInteger, Buffer.from([0x01]), Buffer.from([0x01]));
53
- this.length += 3;
54
- }
55
- unsignedInteger(integer) {
56
- if (integer[0] & 0x80) {
57
- const len = encodeLength(integer.length + 1);
58
- this.elements.push(bTagInteger, len, bZero, integer);
59
- this.length += 2 + len.length + integer.length;
60
- }
61
- else {
62
- let i = 0;
63
- while (integer[i] === 0 && (integer[i + 1] & 0x80) === 0)
64
- i++;
65
- const len = encodeLength(integer.length - i);
66
- this.elements.push(bTagInteger, encodeLength(integer.length - i), integer.slice(i));
67
- this.length += 1 + len.length + integer.length - i;
68
- }
69
- }
70
- octStr(octStr) {
71
- const len = encodeLength(octStr.length);
72
- this.elements.push(bTagOctStr, encodeLength(octStr.length), octStr);
73
- this.length += 1 + len.length + octStr.length;
74
- }
75
- bitStr(bitS) {
76
- const len = encodeLength(bitS.length + 1);
77
- this.elements.push(bTagBitStr, encodeLength(bitS.length + 1), bZero, bitS);
78
- this.length += 1 + len.length + bitS.length + 1;
79
- }
80
- add(seq) {
81
- this.elements.push(seq);
82
- this.length += seq.length;
83
- }
84
- end(tag = bTagSequence) {
85
- const len = encodeLength(this.length);
86
- return Buffer.concat([tag, len, ...this.elements], 1 + len.length + this.length);
87
- }
88
- }