@zuplo/cli 6.73.27 → 6.73.28

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 (92) hide show
  1. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/README.md +13 -13
  2. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/index.d.ts +6 -5
  3. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwe/compact/decrypt.d.ts +17 -11
  4. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwe/compact/encrypt.d.ts +7 -19
  5. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwe/flattened/decrypt.d.ts +17 -11
  6. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwe/flattened/encrypt.d.ts +7 -19
  7. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwe/general/decrypt.d.ts +18 -13
  8. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwe/general/encrypt.d.ts +20 -21
  9. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwk/embedded.d.ts +8 -12
  10. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwk/thumbprint.d.ts +0 -15
  11. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwks/local.d.ts +12 -21
  12. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwks/remote.d.ts +34 -165
  13. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jws/compact/sign.d.ts +2 -13
  14. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jws/compact/verify.d.ts +17 -13
  15. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jws/flattened/sign.d.ts +2 -13
  16. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jws/flattened/verify.d.ts +17 -13
  17. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jws/general/sign.d.ts +16 -17
  18. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jws/general/verify.d.ts +18 -15
  19. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwt/decrypt.d.ts +17 -11
  20. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwt/encrypt.d.ts +10 -34
  21. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwt/sign.d.ts +2 -13
  22. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwt/unsecured.d.ts +4 -13
  23. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwt/verify.d.ts +14 -13
  24. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/key/export.d.ts +0 -14
  25. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/key/generate_key_pair.d.ts +7 -14
  26. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/key/generate_secret.d.ts +16 -14
  27. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/key/import.d.ts +18 -28
  28. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/types.d.ts +242 -223
  29. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/util/base64url.d.ts +11 -4
  30. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/util/decode_jwt.d.ts +1 -9
  31. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/util/decode_protected_header.d.ts +0 -8
  32. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/util/errors.d.ts +128 -121
  33. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwe/compact/decrypt.js +3 -21
  34. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwe/flattened/decrypt.js +5 -153
  35. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwe/flattened/encrypt.js +16 -111
  36. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwe/general/decrypt.js +15 -3
  37. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwe/general/encrypt.js +33 -48
  38. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwk/embedded.js +5 -3
  39. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwks/local.js +27 -47
  40. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwks/remote.js +3 -3
  41. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jws/compact/sign.js +5 -2
  42. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jws/compact/verify.js +3 -15
  43. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jws/flattened/sign.js +7 -57
  44. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jws/flattened/verify.js +3 -89
  45. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jws/general/sign.js +18 -5
  46. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jws/general/verify.js +21 -3
  47. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwt/decrypt.js +4 -4
  48. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwt/sign.js +2 -3
  49. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwt/unsecured.js +4 -3
  50. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwt/verify.js +5 -5
  51. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/key/export.js +34 -1
  52. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/key/generate_key_pair.js +32 -82
  53. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/key/import.js +8 -8
  54. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/asn1.js +29 -65
  55. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/buffer_utils.js +1 -0
  56. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/content_encryption.js +20 -77
  57. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/crypto_key.js +13 -127
  58. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/helpers.js +23 -0
  59. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jwe_algorithms.js +143 -0
  60. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jwe_decrypt.js +181 -0
  61. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jwe_encrypt.js +109 -0
  62. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jwk_to_key.js +11 -96
  63. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jws_algorithms.js +74 -0
  64. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jws_sign.js +68 -0
  65. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jws_verify.js +108 -0
  66. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jwt_claims_set.js +9 -8
  67. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/key.js +170 -0
  68. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/key_algorithm.js +16 -0
  69. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/key_descriptor.js +7 -0
  70. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/key_management.js +186 -29
  71. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/{validate_crit.js → options.js} +18 -0
  72. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/signing.js +20 -52
  73. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/util/base64url.js +11 -3
  74. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/util/decode_jwt.js +2 -2
  75. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/util/decode_protected_header.js +5 -15
  76. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/util/errors.js +1 -1
  77. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/package.json +2 -4
  78. package/node_modules/@zuplo/core/package.json +1 -1
  79. package/node_modules/@zuplo/graphql/package.json +1 -1
  80. package/node_modules/@zuplo/openapi-tools/package.json +1 -1
  81. package/node_modules/@zuplo/otel/package.json +1 -1
  82. package/node_modules/@zuplo/runtime/package.json +1 -1
  83. package/package.json +6 -6
  84. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/aesgcmkw.js +0 -15
  85. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/aeskw.js +0 -25
  86. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/check_key_type.js +0 -122
  87. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/ecdhes.js +0 -52
  88. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/key_to_jwk.js +0 -34
  89. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/normalize_key.js +0 -166
  90. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/pbes2kw.js +0 -42
  91. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/rsaes.js +0 -24
  92. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/validate_algorithms.js +0 -10
@@ -1,9 +1,16 @@
1
1
  /**
2
- * Base64URL encoding and decoding utilities
2
+ * Decodes a Base64URL encoded input.
3
3
  *
4
- * @module
4
+ * @param input Base64URL encoded input, as a string or its UTF-8 bytes.
5
+ * @returns The decoded bytes.
6
+ * @throws {!TypeError} When the input is not correctly Base64URL encoded. Standard Base64 input
7
+ * (i.e. containing `+` or `/`) is rejected.
5
8
  */
6
- /** Decodes a Base64URL encoded input. */
7
9
  export declare function decode(input: Uint8Array | string): Uint8Array;
8
- /** Encodes an input using Base64URL with no padding. */
10
+ /**
11
+ * Encodes an input using Base64URL with no padding.
12
+ *
13
+ * @param input Input to encode, as a string or as bytes. Strings are encoded as UTF-8 first.
14
+ * @returns The Base64URL encoded, unpadded, representation of the input.
15
+ */
9
16
  export declare function encode(input: Uint8Array | string): string;
@@ -1,8 +1,3 @@
1
- /**
2
- * JSON Web Token (JWT) Claims Set Decoding (no validation, no signature checking)
3
- *
4
- * @module
5
- */
6
1
  import type * as types from '../types.d.ts';
7
2
  /**
8
3
  * Decodes a signed JSON Web Token payload. This does not validate the JWT Claims Set types or
@@ -10,9 +5,6 @@ import type * as types from '../types.d.ts';
10
5
  * and JWS signature verification use `jose.jwtVerify()`. For an encrypted JWT Claims Set validation
11
6
  * and JWE decryption use `jose.jwtDecrypt()`.
12
7
  *
13
- * This function is exported (as a named export) from the main `'jose'` module entry point as well
14
- * as from its subpath export `'jose/jwt/decode'`.
15
- *
16
8
  * @param jwt JWT token in compact JWS serialization.
17
9
  */
18
- export declare function decodeJwt<PayloadType = types.JWTPayload>(jwt: string): PayloadType & types.JWTPayload;
10
+ export declare function decodeJwt<PayloadType = types.JWTPayload>(jwt: string): PayloadType & types.JWTPayload & ([PayloadType] extends [object] ? unknown : unknown extends PayloadType ? unknown : never);
@@ -1,17 +1,9 @@
1
- /**
2
- * JOSE Protected Header Decoding (JWE, JWS, all serialization syntaxes)
3
- *
4
- * @module
5
- */
6
1
  import type * as types from '../types.d.ts';
7
2
  /** JWE and JWS Header Parameters */
8
3
  export type ProtectedHeaderParameters = types.JWSHeaderParameters & types.JWEHeaderParameters;
9
4
  /**
10
5
  * Decodes the Protected Header of a JWE/JWS/JWT token utilizing any JOSE serialization.
11
6
  *
12
- * This function is exported (as a named export) from the main `'jose'` module entry point as well
13
- * as from its subpath export `'jose/decode/protected_header'`.
14
- *
15
7
  * @param token JWE/JWS/JWT token in any JOSE serialization.
16
8
  */
17
9
  export declare function decodeProtectedHeader(token: string | object): ProtectedHeaderParameters;
@@ -1,40 +1,50 @@
1
+ import type * as types from '../types.d.ts';
1
2
  /**
2
- * JOSE module errors and error codes
3
- *
4
- * @module
3
+ * Every stable error code used by this module. {@link AnyJOSEError} pairs each subclass with the one
4
+ * it is thrown with, making that union a discriminated one.
5
5
  */
6
- import type * as types from '../types.d.ts';
6
+ export type JOSEErrorCode = 'ERR_JOSE_ALG_NOT_ALLOWED' | 'ERR_JOSE_GENERIC' | 'ERR_JOSE_NOT_SUPPORTED' | 'ERR_JWE_DECRYPTION_FAILED' | 'ERR_JWE_INVALID' | 'ERR_JWK_INVALID' | 'ERR_JWKS_INVALID' | 'ERR_JWKS_MULTIPLE_MATCHING_KEYS' | 'ERR_JWKS_NO_MATCHING_KEY' | 'ERR_JWKS_TIMEOUT' | 'ERR_JWS_INVALID' | 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED' | 'ERR_JWT_CLAIM_VALIDATION_FAILED' | 'ERR_JWT_EXPIRED' | 'ERR_JWT_INVALID';
7
7
  /**
8
- * A generic Error that all other JOSE specific Error subclasses extend.
8
+ * The shape shared by the two errors thrown during JWT Claims Set validation.
9
9
  *
10
+ * > Note: {@link JWTExpired} does not extend {@link JWTClaimValidationFailed}, so `instanceof
11
+ * > JWTClaimValidationFailed` is `false` for an expired JWT. Use {@link JWTClaimValidationError} or
12
+ * > the {@link JOSEError.code code} discriminant to handle both.
10
13
  */
14
+ export interface JWTClaimValidationFailure {
15
+ /** The Claim for which the validation failed. */
16
+ claim: string;
17
+ /** Reason code for the validation failure. */
18
+ reason: JWTClaimValidationReason;
19
+ /** The parsed JWT Claims Set (aka payload). */
20
+ payload: types.JWTPayload;
21
+ }
22
+ /** Reason codes produced by JWT Claims Set validation. */
23
+ export type JWTClaimValidationReason = 'check_failed' | 'invalid' | 'mismatch' | 'missing' | 'unspecified' | (string & {});
24
+ /** A generic Error that all other JOSE specific Error subclasses extend. */
11
25
  export declare class JOSEError extends Error {
26
+ /** A unique error code for the particular error subclass. */
27
+ static code: JOSEErrorCode | (string & {});
12
28
  /**
13
- * A unique error code for the particular error subclass.
14
- *
15
- * @ignore
29
+ * A unique error code for {@link JOSEError}. Each subclass sets its own; see {@link AnyJOSEError}
30
+ * to switch over them as a discriminated union.
16
31
  */
17
- static code: string;
18
- /** A unique error code for {@link JOSEError}. */
19
- code: string;
20
- /** @ignore */
32
+ code: JOSEErrorCode | (string & {});
21
33
  constructor(message?: string, options?: {
22
34
  cause?: unknown;
23
35
  });
24
36
  }
25
- /**
26
- * An error subclass thrown when a JWT Claim Set member validation fails.
27
- *
28
- */
29
- export declare class JWTClaimValidationFailed extends JOSEError {
30
- /** @ignore */
31
- static code: string;
37
+ /** An error subclass thrown when a JWT Claim Set member validation fails. */
38
+ export declare class JWTClaimValidationFailed extends JOSEError implements JWTClaimValidationFailure {
39
+ static code: JOSEErrorCode | (string & {});
32
40
  /** A unique error code for {@link JWTClaimValidationFailed}. */
33
- code: string;
41
+ code: JOSEErrorCode | (string & {});
42
+ /** The {@link JWTClaimValidationFailure} carried by every instance of this error. */
43
+ cause: JWTClaimValidationFailure;
34
44
  /** The Claim for which the validation failed. */
35
45
  claim: string;
36
46
  /** Reason code for the validation failure. */
37
- reason: string;
47
+ reason: JWTClaimValidationReason;
38
48
  /**
39
49
  * The parsed JWT Claims Set (aka payload). Other JWT claims may or may not have been verified at
40
50
  * this point. The JSON Web Signature (JWS) or a JSON Web Encryption (JWE) structures' integrity
@@ -42,22 +52,19 @@ export declare class JWTClaimValidationFailed extends JOSEError {
42
52
  * Decryption processes.
43
53
  */
44
54
  payload: types.JWTPayload;
45
- /** @ignore */
46
- constructor(message: string, payload: types.JWTPayload, claim?: string, reason?: string);
55
+ constructor(message: string, payload: types.JWTPayload, claim?: string, reason?: JWTClaimValidationReason);
47
56
  }
48
- /**
49
- * An error subclass thrown when a JWT is expired.
50
- *
51
- */
52
- export declare class JWTExpired extends JOSEError implements JWTClaimValidationFailed {
53
- /** @ignore */
54
- static code: string;
57
+ /** An error subclass thrown when a JWT is expired. */
58
+ export declare class JWTExpired extends JOSEError implements JWTClaimValidationFailure {
59
+ static code: JOSEErrorCode | (string & {});
55
60
  /** A unique error code for {@link JWTExpired}. */
56
- code: string;
61
+ code: JOSEErrorCode | (string & {});
62
+ /** The {@link JWTClaimValidationFailure} carried by every instance of this error. */
63
+ cause: JWTClaimValidationFailure;
57
64
  /** The Claim for which the validation failed. */
58
65
  claim: string;
59
66
  /** Reason code for the validation failure. */
60
- reason: string;
67
+ reason: JWTClaimValidationReason;
61
68
  /**
62
69
  * The parsed JWT Claims Set (aka payload). Other JWT claims may or may not have been verified at
63
70
  * this point. The JSON Web Signature (JWS) or a JSON Web Encryption (JWE) structures' integrity
@@ -65,149 +72,149 @@ export declare class JWTExpired extends JOSEError implements JWTClaimValidationF
65
72
  * Decryption processes.
66
73
  */
67
74
  payload: types.JWTPayload;
68
- /** @ignore */
69
- constructor(message: string, payload: types.JWTPayload, claim?: string, reason?: string);
75
+ constructor(message: string, payload: types.JWTPayload, claim?: string, reason?: JWTClaimValidationReason);
70
76
  }
71
- /**
72
- * An error subclass thrown when a JOSE Algorithm is not allowed per developer preference.
73
- *
74
- */
77
+ /** An error subclass thrown when a JOSE Algorithm is not allowed per developer preference. */
75
78
  export declare class JOSEAlgNotAllowed extends JOSEError {
76
- /** @ignore */
77
- static code: string;
79
+ static code: JOSEErrorCode | (string & {});
78
80
  /** A unique error code for {@link JOSEAlgNotAllowed}. */
79
- code: string;
81
+ code: JOSEErrorCode | (string & {});
80
82
  }
81
83
  /**
82
84
  * An error subclass thrown when a particular feature or algorithm is not supported by this
83
85
  * implementation or JOSE in general.
84
- *
85
86
  */
86
87
  export declare class JOSENotSupported extends JOSEError {
87
- /** @ignore */
88
- static code: string;
88
+ static code: JOSEErrorCode | (string & {});
89
89
  /** A unique error code for {@link JOSENotSupported}. */
90
- code: string;
90
+ code: JOSEErrorCode | (string & {});
91
91
  }
92
- /**
93
- * An error subclass thrown when a JWE ciphertext decryption fails.
94
- *
95
- */
92
+ /** An error subclass thrown when a JWE ciphertext decryption fails. */
96
93
  export declare class JWEDecryptionFailed extends JOSEError {
97
- /** @ignore */
98
- static code: string;
94
+ static code: JOSEErrorCode | (string & {});
99
95
  /** A unique error code for {@link JWEDecryptionFailed}. */
100
- code: string;
101
- /** @ignore */
96
+ code: JOSEErrorCode | (string & {});
102
97
  constructor(message?: string, options?: {
103
98
  cause?: unknown;
104
99
  });
105
100
  }
106
- /**
107
- * An error subclass thrown when a JWE is invalid.
108
- *
109
- */
101
+ /** An error subclass thrown when a JWE is invalid. */
110
102
  export declare class JWEInvalid extends JOSEError {
111
- /** @ignore */
112
- static code: string;
103
+ static code: JOSEErrorCode | (string & {});
113
104
  /** A unique error code for {@link JWEInvalid}. */
114
- code: string;
105
+ code: JOSEErrorCode | (string & {});
115
106
  }
116
- /**
117
- * An error subclass thrown when a JWS is invalid.
118
- *
119
- */
107
+ /** An error subclass thrown when a JWS is invalid. */
120
108
  export declare class JWSInvalid extends JOSEError {
121
- /** @ignore */
122
- static code: string;
109
+ static code: JOSEErrorCode | (string & {});
123
110
  /** A unique error code for {@link JWSInvalid}. */
124
- code: string;
111
+ code: JOSEErrorCode | (string & {});
125
112
  }
126
- /**
127
- * An error subclass thrown when a JWT is invalid.
128
- *
129
- */
113
+ /** An error subclass thrown when a JWT is invalid. */
130
114
  export declare class JWTInvalid extends JOSEError {
131
- /** @ignore */
132
- static code: string;
115
+ static code: JOSEErrorCode | (string & {});
133
116
  /** A unique error code for {@link JWTInvalid}. */
134
- code: string;
117
+ code: JOSEErrorCode | (string & {});
135
118
  }
136
- /**
137
- * An error subclass thrown when a JWK is invalid.
138
- *
139
- */
119
+ /** An error subclass thrown when a JWK is invalid. */
140
120
  export declare class JWKInvalid extends JOSEError {
141
- /** @ignore */
142
- static code: string;
121
+ static code: JOSEErrorCode | (string & {});
143
122
  /** A unique error code for {@link JWKInvalid}. */
144
- code: string;
123
+ code: JOSEErrorCode | (string & {});
145
124
  }
146
- /**
147
- * An error subclass thrown when a JWKS is invalid.
148
- *
149
- */
125
+ /** An error subclass thrown when a JWKS is invalid. */
150
126
  export declare class JWKSInvalid extends JOSEError {
151
- /** @ignore */
152
- static code: string;
127
+ static code: JOSEErrorCode | (string & {});
153
128
  /** A unique error code for {@link JWKSInvalid}. */
154
- code: string;
129
+ code: JOSEErrorCode | (string & {});
155
130
  }
156
- /**
157
- * An error subclass thrown when no keys match from a JWKS.
158
- *
159
- */
131
+ /** An error subclass thrown when no keys match from a JWKS. */
160
132
  export declare class JWKSNoMatchingKey extends JOSEError {
161
- /** @ignore */
162
- static code: string;
133
+ static code: JOSEErrorCode | (string & {});
163
134
  /** A unique error code for {@link JWKSNoMatchingKey}. */
164
- code: string;
165
- /** @ignore */
135
+ code: JOSEErrorCode | (string & {});
166
136
  constructor(message?: string, options?: {
167
137
  cause?: unknown;
168
138
  });
169
139
  }
170
- /**
171
- * An error subclass thrown when multiple keys match from a JWKS.
172
- *
173
- */
140
+ /** An error subclass thrown when multiple keys match from a JWKS. */
174
141
  export declare class JWKSMultipleMatchingKeys extends JOSEError {
175
- /** @ignore */
142
+ /**
143
+ * Iterates the public keys that matched the JWS JOSE Header, so that verification can be
144
+ * attempted with each in turn. See the {@link jwks/remote.createRemoteJWKSet createRemoteJWKSet}
145
+ * and {@link jwks/local.createLocalJWKSet createLocalJWKSet} examples. Instances thrown by this
146
+ * module always iterate the matched keys; an instance constructed by other code iterates
147
+ * nothing.
148
+ */
176
149
  [Symbol.asyncIterator]: () => AsyncIterableIterator<types.CryptoKey>;
177
- /** @ignore */
178
- static code: string;
150
+ static code: JOSEErrorCode | (string & {});
179
151
  /** A unique error code for {@link JWKSMultipleMatchingKeys}. */
180
- code: string;
181
- /** @ignore */
152
+ code: JOSEErrorCode | (string & {});
182
153
  constructor(message?: string, options?: {
183
154
  cause?: unknown;
184
155
  });
185
156
  }
186
- /**
187
- * Timeout was reached when retrieving the JWKS response.
188
- *
189
- */
157
+ /** Timeout was reached when retrieving the JWKS response. */
190
158
  export declare class JWKSTimeout extends JOSEError {
191
- /** @ignore */
192
- static code: string;
159
+ static code: JOSEErrorCode | (string & {});
193
160
  /** A unique error code for {@link JWKSTimeout}. */
194
- code: string;
195
- /** @ignore */
161
+ code: JOSEErrorCode | (string & {});
196
162
  constructor(message?: string, options?: {
197
163
  cause?: unknown;
198
164
  });
199
165
  }
200
- /**
201
- * An error subclass thrown when JWS signature verification fails.
202
- *
203
- */
166
+ /** An error subclass thrown when JWS signature verification fails. */
204
167
  export declare class JWSSignatureVerificationFailed extends JOSEError {
205
- /** @ignore */
206
- static code: string;
168
+ static code: JOSEErrorCode | (string & {});
207
169
  /** A unique error code for {@link JWSSignatureVerificationFailed}. */
208
- code: string;
209
- /** @ignore */
170
+ code: JOSEErrorCode | (string & {});
210
171
  constructor(message?: string, options?: {
211
172
  cause?: unknown;
212
173
  });
213
174
  }
175
+ /**
176
+ * Union of the errors thrown during JWT Claims Set validation. {@link JWTExpired} does not extend
177
+ * {@link JWTClaimValidationFailed}, so a single `instanceof` check cannot cover both. Use this type
178
+ * — together with the {@link JOSEError.code code} discriminant — when handling either.
179
+ */
180
+ export type JWTClaimValidationError = JWTClaimValidationFailed | JWTExpired;
181
+ /**
182
+ * Union of every {@link JOSEError} subclass this module throws, each paired with the single
183
+ * {@link JOSEErrorCode} it is thrown with. That pairing lives here rather than on the classes, so
184
+ * that `code` stays assignable, writable, and overridable on them exactly as before, while a value
185
+ * of this type can still be switched over as a discriminated union.
186
+ *
187
+ * > Note: The base {@link JOSEError} is deliberately not a member — its `code` spans every value, which
188
+ * > would defeat the discriminant. A small number of JSON Web Key Set HTTP failures are thrown as the
189
+ * > base class itself, so `instanceof JOSEError` remains the catch-all; this union is for handling a
190
+ * > value already known to be one of the specific errors.
191
+ */
192
+ export type AnyJOSEError = (JOSEAlgNotAllowed & {
193
+ code: 'ERR_JOSE_ALG_NOT_ALLOWED';
194
+ }) | (JOSENotSupported & {
195
+ code: 'ERR_JOSE_NOT_SUPPORTED';
196
+ }) | (JWEDecryptionFailed & {
197
+ code: 'ERR_JWE_DECRYPTION_FAILED';
198
+ }) | (JWEInvalid & {
199
+ code: 'ERR_JWE_INVALID';
200
+ }) | (JWKInvalid & {
201
+ code: 'ERR_JWK_INVALID';
202
+ }) | (JWKSInvalid & {
203
+ code: 'ERR_JWKS_INVALID';
204
+ }) | (JWKSMultipleMatchingKeys & {
205
+ code: 'ERR_JWKS_MULTIPLE_MATCHING_KEYS';
206
+ }) | (JWKSNoMatchingKey & {
207
+ code: 'ERR_JWKS_NO_MATCHING_KEY';
208
+ }) | (JWKSTimeout & {
209
+ code: 'ERR_JWKS_TIMEOUT';
210
+ }) | (JWSInvalid & {
211
+ code: 'ERR_JWS_INVALID';
212
+ }) | (JWSSignatureVerificationFailed & {
213
+ code: 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED';
214
+ }) | (JWTClaimValidationFailed & {
215
+ code: 'ERR_JWT_CLAIM_VALIDATION_FAILED';
216
+ }) | (JWTExpired & {
217
+ code: 'ERR_JWT_EXPIRED';
218
+ }) | (JWTInvalid & {
219
+ code: 'ERR_JWT_INVALID';
220
+ });
@@ -1,25 +1,7 @@
1
- import { flattenedDecrypt } from '../flattened/decrypt.js';
2
- import { JWEInvalid } from '../../util/errors.js';
3
- import { decoder } from '../../lib/buffer_utils.js';
1
+ import { prepareDecrypt, decryptCompact } from '../../lib/jwe_decrypt.js';
4
2
  export async function compactDecrypt(jwe, key, options) {
5
- if (jwe instanceof Uint8Array) {
6
- jwe = decoder.decode(jwe);
7
- }
8
- if (typeof jwe !== 'string') {
9
- throw new JWEInvalid('Compact JWE must be a string or Uint8Array');
10
- }
11
- const { 0: protectedHeader, 1: encryptedKey, 2: iv, 3: ciphertext, 4: tag, length, } = jwe.split('.');
12
- if (length !== 5) {
13
- throw new JWEInvalid('Invalid Compact JWE');
14
- }
15
- const decrypted = await flattenedDecrypt({
16
- ciphertext,
17
- iv: iv || undefined,
18
- protected: protectedHeader,
19
- tag: tag || undefined,
20
- encrypted_key: encryptedKey || undefined,
21
- }, key, options);
22
- const result = { plaintext: decrypted.plaintext, protectedHeader: decrypted.protectedHeader };
3
+ const decrypted = await decryptCompact(jwe, prepareDecrypt(options), key);
4
+ const result = { plaintext: decrypted.plaintext, protectedHeader: decrypted.parsedProt };
23
5
  if (typeof key === 'function') {
24
6
  return { ...result, key: decrypted.key };
25
7
  }
@@ -1,159 +1,11 @@
1
- import { decode as b64u } from '../../util/base64url.js';
2
- import { decrypt } from '../../lib/content_encryption.js';
3
- import { decodeBase64url } from '../../lib/helpers.js';
4
- import { JOSEAlgNotAllowed, JOSENotSupported, JWEInvalid } from '../../util/errors.js';
5
- import { isDisjoint } from '../../lib/type_checks.js';
1
+ import { JWEInvalid } from '../../util/errors.js';
6
2
  import { isObject } from '../../lib/type_checks.js';
7
- import { decryptKeyManagement } from '../../lib/key_management.js';
8
- import { decoder, concat, encode } from '../../lib/buffer_utils.js';
9
- import { generateCek } from '../../lib/content_encryption.js';
10
- import { validateCrit } from '../../lib/validate_crit.js';
11
- import { validateAlgorithms } from '../../lib/validate_algorithms.js';
12
- import { normalizeKey } from '../../lib/normalize_key.js';
13
- import { checkKeyType } from '../../lib/check_key_type.js';
14
- import { decompress } from '../../lib/deflate.js';
3
+ import { prepareDecrypt, decryptJWE, decryptResult, checkShared, checkRecipient, } from '../../lib/jwe_decrypt.js';
15
4
  export async function flattenedDecrypt(jwe, key, options) {
16
5
  if (!isObject(jwe)) {
17
6
  throw new JWEInvalid('Flattened JWE must be an object');
18
7
  }
19
- if (jwe.protected === undefined && jwe.header === undefined && jwe.unprotected === undefined) {
20
- throw new JWEInvalid('JOSE Header missing');
21
- }
22
- if (jwe.iv !== undefined && typeof jwe.iv !== 'string') {
23
- throw new JWEInvalid('JWE Initialization Vector incorrect type');
24
- }
25
- if (typeof jwe.ciphertext !== 'string') {
26
- throw new JWEInvalid('JWE Ciphertext missing or incorrect type');
27
- }
28
- if (jwe.tag !== undefined && typeof jwe.tag !== 'string') {
29
- throw new JWEInvalid('JWE Authentication Tag incorrect type');
30
- }
31
- if (jwe.protected !== undefined && typeof jwe.protected !== 'string') {
32
- throw new JWEInvalid('JWE Protected Header incorrect type');
33
- }
34
- if (jwe.encrypted_key !== undefined && typeof jwe.encrypted_key !== 'string') {
35
- throw new JWEInvalid('JWE Encrypted Key incorrect type');
36
- }
37
- if (jwe.aad !== undefined && typeof jwe.aad !== 'string') {
38
- throw new JWEInvalid('JWE AAD incorrect type');
39
- }
40
- if (jwe.header !== undefined && !isObject(jwe.header)) {
41
- throw new JWEInvalid('JWE Shared Unprotected Header incorrect type');
42
- }
43
- if (jwe.unprotected !== undefined && !isObject(jwe.unprotected)) {
44
- throw new JWEInvalid('JWE Per-Recipient Unprotected Header incorrect type');
45
- }
46
- let parsedProt;
47
- if (jwe.protected) {
48
- try {
49
- const protectedHeader = b64u(jwe.protected);
50
- parsedProt = JSON.parse(decoder.decode(protectedHeader));
51
- }
52
- catch {
53
- throw new JWEInvalid('JWE Protected Header is invalid');
54
- }
55
- }
56
- if (!isDisjoint(parsedProt, jwe.header, jwe.unprotected)) {
57
- throw new JWEInvalid('JWE Protected, JWE Unprotected Header, and JWE Per-Recipient Unprotected Header Parameter names must be disjoint');
58
- }
59
- const joseHeader = {
60
- ...parsedProt,
61
- ...jwe.header,
62
- ...jwe.unprotected,
63
- };
64
- validateCrit(JWEInvalid, new Map(), options?.crit, parsedProt, joseHeader);
65
- if (joseHeader.zip !== undefined && joseHeader.zip !== 'DEF') {
66
- throw new JOSENotSupported('Unsupported JWE "zip" (Compression Algorithm) Header Parameter value.');
67
- }
68
- if (joseHeader.zip !== undefined && !parsedProt?.zip) {
69
- throw new JWEInvalid('JWE "zip" (Compression Algorithm) Header Parameter MUST be in a protected header.');
70
- }
71
- const { alg, enc } = joseHeader;
72
- if (typeof alg !== 'string' || !alg) {
73
- throw new JWEInvalid('missing JWE Algorithm (alg) in JWE Header');
74
- }
75
- if (typeof enc !== 'string' || !enc) {
76
- throw new JWEInvalid('missing JWE Encryption Algorithm (enc) in JWE Header');
77
- }
78
- const keyManagementAlgorithms = options && validateAlgorithms('keyManagementAlgorithms', options.keyManagementAlgorithms);
79
- const contentEncryptionAlgorithms = options &&
80
- validateAlgorithms('contentEncryptionAlgorithms', options.contentEncryptionAlgorithms);
81
- if ((keyManagementAlgorithms && !keyManagementAlgorithms.has(alg)) ||
82
- (!keyManagementAlgorithms && alg.startsWith('PBES2'))) {
83
- throw new JOSEAlgNotAllowed('"alg" (Algorithm) Header Parameter value not allowed');
84
- }
85
- if (contentEncryptionAlgorithms && !contentEncryptionAlgorithms.has(enc)) {
86
- throw new JOSEAlgNotAllowed('"enc" (Encryption Algorithm) Header Parameter value not allowed');
87
- }
88
- let encryptedKey;
89
- if (jwe.encrypted_key !== undefined) {
90
- encryptedKey = decodeBase64url(jwe.encrypted_key, 'encrypted_key', JWEInvalid);
91
- }
92
- let resolvedKey = false;
93
- if (typeof key === 'function') {
94
- key = await key(parsedProt, jwe);
95
- resolvedKey = true;
96
- }
97
- checkKeyType(alg === 'dir' ? enc : alg, key, 'decrypt');
98
- const k = await normalizeKey(key, alg);
99
- let cek;
100
- try {
101
- cek = await decryptKeyManagement(alg, k, encryptedKey, joseHeader, options);
102
- }
103
- catch (err) {
104
- if (err instanceof TypeError || err instanceof JWEInvalid || err instanceof JOSENotSupported) {
105
- throw err;
106
- }
107
- cek = generateCek(enc);
108
- }
109
- let iv;
110
- let tag;
111
- if (jwe.iv !== undefined) {
112
- iv = decodeBase64url(jwe.iv, 'iv', JWEInvalid);
113
- }
114
- if (jwe.tag !== undefined) {
115
- tag = decodeBase64url(jwe.tag, 'tag', JWEInvalid);
116
- }
117
- const protectedHeader = jwe.protected !== undefined ? encode(jwe.protected) : new Uint8Array();
118
- let additionalData;
119
- if (jwe.aad !== undefined) {
120
- additionalData = concat(protectedHeader, encode('.'), encode(jwe.aad));
121
- }
122
- else {
123
- additionalData = protectedHeader;
124
- }
125
- const ciphertext = decodeBase64url(jwe.ciphertext, 'ciphertext', JWEInvalid);
126
- const plaintext = await decrypt(enc, cek, ciphertext, iv, tag, additionalData);
127
- const result = { plaintext };
128
- if (joseHeader.zip === 'DEF') {
129
- const maxDecompressedLength = options?.maxDecompressedLength ?? 250_000;
130
- if (maxDecompressedLength === 0) {
131
- throw new JOSENotSupported('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');
132
- }
133
- if (maxDecompressedLength !== Infinity &&
134
- (!Number.isSafeInteger(maxDecompressedLength) || maxDecompressedLength < 1)) {
135
- throw new TypeError('maxDecompressedLength must be 0, a positive safe integer, or Infinity');
136
- }
137
- result.plaintext = await decompress(plaintext, maxDecompressedLength).catch((cause) => {
138
- if (cause instanceof JWEInvalid)
139
- throw cause;
140
- throw new JWEInvalid('Failed to decompress plaintext', { cause });
141
- });
142
- }
143
- if (jwe.protected !== undefined) {
144
- result.protectedHeader = parsedProt;
145
- }
146
- if (jwe.aad !== undefined) {
147
- result.additionalAuthenticatedData = decodeBase64url(jwe.aad, 'aad', JWEInvalid);
148
- }
149
- if (jwe.unprotected !== undefined) {
150
- result.sharedUnprotectedHeader = jwe.unprotected;
151
- }
152
- if (jwe.header !== undefined) {
153
- result.unprotectedHeader = jwe.header;
154
- }
155
- if (resolvedKey) {
156
- return { ...result, key: k };
157
- }
158
- return result;
8
+ checkShared(jwe);
9
+ checkRecipient(jwe);
10
+ return decryptResult(jwe, await decryptJWE(jwe, prepareDecrypt(options), key));
159
11
  }