@oari/jose 0.0.0
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/LICENSE.md +21 -0
- package/README.md +150 -0
- package/dist/types/index.d.ts +55 -0
- package/dist/types/jwe/compact/decrypt.d.ts +43 -0
- package/dist/types/jwe/compact/encrypt.d.ts +76 -0
- package/dist/types/jwe/flattened/decrypt.d.ts +53 -0
- package/dist/types/jwe/flattened/encrypt.d.ts +95 -0
- package/dist/types/jwe/general/decrypt.d.ts +64 -0
- package/dist/types/jwe/general/encrypt.d.ts +89 -0
- package/dist/types/jwk/embedded.d.ts +31 -0
- package/dist/types/jwk/thumbprint.d.ts +60 -0
- package/dist/types/jwks/local.d.ts +90 -0
- package/dist/types/jwks/remote.d.ts +306 -0
- package/dist/types/jws/compact/sign.d.ts +47 -0
- package/dist/types/jws/compact/verify.d.ts +45 -0
- package/dist/types/jws/flattened/sign.d.ts +53 -0
- package/dist/types/jws/flattened/verify.d.ts +50 -0
- package/dist/types/jws/general/sign.d.ts +67 -0
- package/dist/types/jws/general/verify.d.ts +61 -0
- package/dist/types/jwt/decrypt.d.ts +51 -0
- package/dist/types/jwt/encrypt.d.ts +105 -0
- package/dist/types/jwt/sign.d.ts +140 -0
- package/dist/types/jwt/unsecured.d.ts +70 -0
- package/dist/types/jwt/verify.d.ts +124 -0
- package/dist/types/key/export.d.ts +59 -0
- package/dist/types/key/generate_key_pair.d.ts +64 -0
- package/dist/types/key/generate_secret.d.ts +42 -0
- package/dist/types/key/import.d.ts +146 -0
- package/dist/types/types.d.ts +869 -0
- package/dist/types/util/base64url.d.ts +9 -0
- package/dist/types/util/decode_jwt.d.ts +25 -0
- package/dist/types/util/decode_protected_header.d.ts +24 -0
- package/dist/types/util/errors.d.ts +488 -0
- package/dist/webapi/index.js +32 -0
- package/dist/webapi/jwe/compact/decrypt.js +27 -0
- package/dist/webapi/jwe/compact/encrypt.js +27 -0
- package/dist/webapi/jwe/flattened/decrypt.js +159 -0
- package/dist/webapi/jwe/flattened/encrypt.js +167 -0
- package/dist/webapi/jwe/general/decrypt.js +31 -0
- package/dist/webapi/jwe/general/encrypt.js +182 -0
- package/dist/webapi/jwk/embedded.js +17 -0
- package/dist/webapi/jwk/thumbprint.js +68 -0
- package/dist/webapi/jwks/local.js +119 -0
- package/dist/webapi/jwks/remote.js +179 -0
- package/dist/webapi/jws/compact/sign.js +18 -0
- package/dist/webapi/jws/compact/verify.js +21 -0
- package/dist/webapi/jws/flattened/sign.js +87 -0
- package/dist/webapi/jws/flattened/verify.js +110 -0
- package/dist/webapi/jws/general/sign.js +70 -0
- package/dist/webapi/jws/general/verify.js +24 -0
- package/dist/webapi/jwt/decrypt.js +23 -0
- package/dist/webapi/jwt/encrypt.js +101 -0
- package/dist/webapi/jwt/sign.js +52 -0
- package/dist/webapi/jwt/unsecured.js +63 -0
- package/dist/webapi/jwt/verify.js +15 -0
- package/dist/webapi/key/export.js +11 -0
- package/dist/webapi/key/generate_key_pair.js +97 -0
- package/dist/webapi/key/generate_secret.js +40 -0
- package/dist/webapi/key/import.js +57 -0
- package/dist/webapi/lib/aesgcmkw.js +15 -0
- package/dist/webapi/lib/aeskw.js +25 -0
- package/dist/webapi/lib/asn1.js +243 -0
- package/dist/webapi/lib/base64.js +22 -0
- package/dist/webapi/lib/buffer_utils.js +43 -0
- package/dist/webapi/lib/check_key_type.js +127 -0
- package/dist/webapi/lib/content_encryption.js +217 -0
- package/dist/webapi/lib/crypto_key.js +136 -0
- package/dist/webapi/lib/deflate.js +44 -0
- package/dist/webapi/lib/ecdhes.js +52 -0
- package/dist/webapi/lib/helpers.js +19 -0
- package/dist/webapi/lib/invalid_key_input.js +27 -0
- package/dist/webapi/lib/is_key_like.js +17 -0
- package/dist/webapi/lib/jwk_to_key.js +107 -0
- package/dist/webapi/lib/jwt_claims_set.js +238 -0
- package/dist/webapi/lib/key_management.js +186 -0
- package/dist/webapi/lib/key_to_jwk.js +31 -0
- package/dist/webapi/lib/normalize_key.js +166 -0
- package/dist/webapi/lib/pbes2kw.js +42 -0
- package/dist/webapi/lib/rsaes.js +24 -0
- package/dist/webapi/lib/signing.js +74 -0
- package/dist/webapi/lib/type_checks.js +41 -0
- package/dist/webapi/lib/validate_algorithms.js +10 -0
- package/dist/webapi/lib/validate_crit.js +33 -0
- package/dist/webapi/util/base64url.js +30 -0
- package/dist/webapi/util/decode_jwt.js +32 -0
- package/dist/webapi/util/decode_protected_header.js +34 -0
- package/dist/webapi/util/errors.js +99 -0
- package/package.json +195 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base64URL encoding and decoding utilities
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/** Decodes a Base64URL encoded input. */
|
|
7
|
+
export declare function decode(input: Uint8Array | string): Uint8Array;
|
|
8
|
+
/** Encodes an input using Base64URL with no padding. */
|
|
9
|
+
export declare function encode(input: Uint8Array | string): string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON Web Token (JWT) Claims Set Decoding (no validation, no signature checking)
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type * as types from '../types.d.ts';
|
|
7
|
+
/**
|
|
8
|
+
* Decodes a signed JSON Web Token payload. This does not validate the JWT Claims Set types or
|
|
9
|
+
* values. This does not validate the JWS Signature. For a proper Signed JWT Claims Set validation
|
|
10
|
+
* and JWS signature verification use `jose.jwtVerify()`. For an encrypted JWT Claims Set validation
|
|
11
|
+
* and JWE decryption use `jose.jwtDecrypt()`.
|
|
12
|
+
*
|
|
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
|
+
* @example
|
|
17
|
+
*
|
|
18
|
+
* ```js
|
|
19
|
+
* const claims = jose.decodeJwt(token)
|
|
20
|
+
* console.log(claims)
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @param jwt JWT token in compact JWS serialization.
|
|
24
|
+
*/
|
|
25
|
+
export declare function decodeJwt<PayloadType = types.JWTPayload>(jwt: string): PayloadType & types.JWTPayload;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JOSE Protected Header Decoding (JWE, JWS, all serialization syntaxes)
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type * as types from '../types.d.ts';
|
|
7
|
+
/** JWE and JWS Header Parameters */
|
|
8
|
+
export type ProtectedHeaderParameters = types.JWSHeaderParameters & types.JWEHeaderParameters;
|
|
9
|
+
/**
|
|
10
|
+
* Decodes the Protected Header of a JWE/JWS/JWT token utilizing any JOSE serialization.
|
|
11
|
+
*
|
|
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
|
+
* @example
|
|
16
|
+
*
|
|
17
|
+
* ```js
|
|
18
|
+
* const protectedHeader = jose.decodeProtectedHeader(token)
|
|
19
|
+
* console.log(protectedHeader)
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @param token JWE/JWS/JWT token in any JOSE serialization.
|
|
23
|
+
*/
|
|
24
|
+
export declare function decodeProtectedHeader(token: string | object): ProtectedHeaderParameters;
|
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JOSE module errors and error codes
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type * as types from '../types.d.ts';
|
|
7
|
+
/**
|
|
8
|
+
* A generic Error that all other JOSE specific Error subclasses extend.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
*
|
|
12
|
+
* Checking thrown error is a JOSE one
|
|
13
|
+
*
|
|
14
|
+
* ```js
|
|
15
|
+
* if (err instanceof jose.errors.JOSEError) {
|
|
16
|
+
* // ...
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare class JOSEError extends Error {
|
|
21
|
+
/**
|
|
22
|
+
* A unique error code for the particular error subclass.
|
|
23
|
+
*
|
|
24
|
+
* @ignore
|
|
25
|
+
*/
|
|
26
|
+
static code: string;
|
|
27
|
+
/** A unique error code for {@link JOSEError}. */
|
|
28
|
+
code: string;
|
|
29
|
+
/** @ignore */
|
|
30
|
+
constructor(message?: string, options?: {
|
|
31
|
+
cause?: unknown;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* An error subclass thrown when a JWT Claim Set member validation fails.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
*
|
|
39
|
+
* Checking thrown error is this one using a stable error code
|
|
40
|
+
*
|
|
41
|
+
* ```js
|
|
42
|
+
* if (err.code === 'ERR_JWT_CLAIM_VALIDATION_FAILED') {
|
|
43
|
+
* // ...
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
*
|
|
49
|
+
* Checking thrown error is this one using `instanceof`
|
|
50
|
+
*
|
|
51
|
+
* ```js
|
|
52
|
+
* if (err instanceof jose.errors.JWTClaimValidationFailed) {
|
|
53
|
+
* // ...
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare class JWTClaimValidationFailed extends JOSEError {
|
|
58
|
+
/** @ignore */
|
|
59
|
+
static code: string;
|
|
60
|
+
/** A unique error code for {@link JWTClaimValidationFailed}. */
|
|
61
|
+
code: string;
|
|
62
|
+
/** The Claim for which the validation failed. */
|
|
63
|
+
claim: string;
|
|
64
|
+
/** Reason code for the validation failure. */
|
|
65
|
+
reason: string;
|
|
66
|
+
/**
|
|
67
|
+
* The parsed JWT Claims Set (aka payload). Other JWT claims may or may not have been verified at
|
|
68
|
+
* this point. The JSON Web Signature (JWS) or a JSON Web Encryption (JWE) structures' integrity
|
|
69
|
+
* has however been verified. Claims Set verification happens after the JWS Signature or JWE
|
|
70
|
+
* Decryption processes.
|
|
71
|
+
*/
|
|
72
|
+
payload: types.JWTPayload;
|
|
73
|
+
/** @ignore */
|
|
74
|
+
constructor(message: string, payload: types.JWTPayload, claim?: string, reason?: string);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* An error subclass thrown when a JWT is expired.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
*
|
|
81
|
+
* Checking thrown error is this one using a stable error code
|
|
82
|
+
*
|
|
83
|
+
* ```js
|
|
84
|
+
* if (err.code === 'ERR_JWT_EXPIRED') {
|
|
85
|
+
* // ...
|
|
86
|
+
* }
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
*
|
|
91
|
+
* Checking thrown error is this one using `instanceof`
|
|
92
|
+
*
|
|
93
|
+
* ```js
|
|
94
|
+
* if (err instanceof jose.errors.JWTExpired) {
|
|
95
|
+
* // ...
|
|
96
|
+
* }
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export declare class JWTExpired extends JOSEError implements JWTClaimValidationFailed {
|
|
100
|
+
/** @ignore */
|
|
101
|
+
static code: string;
|
|
102
|
+
/** A unique error code for {@link JWTExpired}. */
|
|
103
|
+
code: string;
|
|
104
|
+
/** The Claim for which the validation failed. */
|
|
105
|
+
claim: string;
|
|
106
|
+
/** Reason code for the validation failure. */
|
|
107
|
+
reason: string;
|
|
108
|
+
/**
|
|
109
|
+
* The parsed JWT Claims Set (aka payload). Other JWT claims may or may not have been verified at
|
|
110
|
+
* this point. The JSON Web Signature (JWS) or a JSON Web Encryption (JWE) structures' integrity
|
|
111
|
+
* has however been verified. Claims Set verification happens after the JWS Signature or JWE
|
|
112
|
+
* Decryption processes.
|
|
113
|
+
*/
|
|
114
|
+
payload: types.JWTPayload;
|
|
115
|
+
/** @ignore */
|
|
116
|
+
constructor(message: string, payload: types.JWTPayload, claim?: string, reason?: string);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* An error subclass thrown when a JOSE Algorithm is not allowed per developer preference.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
*
|
|
123
|
+
* Checking thrown error is this one using a stable error code
|
|
124
|
+
*
|
|
125
|
+
* ```js
|
|
126
|
+
* if (err.code === 'ERR_JOSE_ALG_NOT_ALLOWED') {
|
|
127
|
+
* // ...
|
|
128
|
+
* }
|
|
129
|
+
* ```
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
*
|
|
133
|
+
* Checking thrown error is this one using `instanceof`
|
|
134
|
+
*
|
|
135
|
+
* ```js
|
|
136
|
+
* if (err instanceof jose.errors.JOSEAlgNotAllowed) {
|
|
137
|
+
* // ...
|
|
138
|
+
* }
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
export declare class JOSEAlgNotAllowed extends JOSEError {
|
|
142
|
+
/** @ignore */
|
|
143
|
+
static code: string;
|
|
144
|
+
/** A unique error code for {@link JOSEAlgNotAllowed}. */
|
|
145
|
+
code: string;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* An error subclass thrown when a particular feature or algorithm is not supported by this
|
|
149
|
+
* implementation or JOSE in general.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
*
|
|
153
|
+
* Checking thrown error is this one using a stable error code
|
|
154
|
+
*
|
|
155
|
+
* ```js
|
|
156
|
+
* if (err.code === 'ERR_JOSE_NOT_SUPPORTED') {
|
|
157
|
+
* // ...
|
|
158
|
+
* }
|
|
159
|
+
* ```
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
*
|
|
163
|
+
* Checking thrown error is this one using `instanceof`
|
|
164
|
+
*
|
|
165
|
+
* ```js
|
|
166
|
+
* if (err instanceof jose.errors.JOSENotSupported) {
|
|
167
|
+
* // ...
|
|
168
|
+
* }
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
export declare class JOSENotSupported extends JOSEError {
|
|
172
|
+
/** @ignore */
|
|
173
|
+
static code: string;
|
|
174
|
+
/** A unique error code for {@link JOSENotSupported}. */
|
|
175
|
+
code: string;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* An error subclass thrown when a JWE ciphertext decryption fails.
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
*
|
|
182
|
+
* Checking thrown error is this one using a stable error code
|
|
183
|
+
*
|
|
184
|
+
* ```js
|
|
185
|
+
* if (err.code === 'ERR_JWE_DECRYPTION_FAILED') {
|
|
186
|
+
* // ...
|
|
187
|
+
* }
|
|
188
|
+
* ```
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
*
|
|
192
|
+
* Checking thrown error is this one using `instanceof`
|
|
193
|
+
*
|
|
194
|
+
* ```js
|
|
195
|
+
* if (err instanceof jose.errors.JWEDecryptionFailed) {
|
|
196
|
+
* // ...
|
|
197
|
+
* }
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
export declare class JWEDecryptionFailed extends JOSEError {
|
|
201
|
+
/** @ignore */
|
|
202
|
+
static code: string;
|
|
203
|
+
/** A unique error code for {@link JWEDecryptionFailed}. */
|
|
204
|
+
code: string;
|
|
205
|
+
/** @ignore */
|
|
206
|
+
constructor(message?: string, options?: {
|
|
207
|
+
cause?: unknown;
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* An error subclass thrown when a JWE is invalid.
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
*
|
|
215
|
+
* Checking thrown error is this one using a stable error code
|
|
216
|
+
*
|
|
217
|
+
* ```js
|
|
218
|
+
* if (err.code === 'ERR_JWE_INVALID') {
|
|
219
|
+
* // ...
|
|
220
|
+
* }
|
|
221
|
+
* ```
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
*
|
|
225
|
+
* Checking thrown error is this one using `instanceof`
|
|
226
|
+
*
|
|
227
|
+
* ```js
|
|
228
|
+
* if (err instanceof jose.errors.JWEInvalid) {
|
|
229
|
+
* // ...
|
|
230
|
+
* }
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
export declare class JWEInvalid extends JOSEError {
|
|
234
|
+
/** @ignore */
|
|
235
|
+
static code: string;
|
|
236
|
+
/** A unique error code for {@link JWEInvalid}. */
|
|
237
|
+
code: string;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* An error subclass thrown when a JWS is invalid.
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
*
|
|
244
|
+
* Checking thrown error is this one using a stable error code
|
|
245
|
+
*
|
|
246
|
+
* ```js
|
|
247
|
+
* if (err.code === 'ERR_JWS_INVALID') {
|
|
248
|
+
* // ...
|
|
249
|
+
* }
|
|
250
|
+
* ```
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
*
|
|
254
|
+
* Checking thrown error is this one using `instanceof`
|
|
255
|
+
*
|
|
256
|
+
* ```js
|
|
257
|
+
* if (err instanceof jose.errors.JWSInvalid) {
|
|
258
|
+
* // ...
|
|
259
|
+
* }
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
export declare class JWSInvalid extends JOSEError {
|
|
263
|
+
/** @ignore */
|
|
264
|
+
static code: string;
|
|
265
|
+
/** A unique error code for {@link JWSInvalid}. */
|
|
266
|
+
code: string;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* An error subclass thrown when a JWT is invalid.
|
|
270
|
+
*
|
|
271
|
+
* @example
|
|
272
|
+
*
|
|
273
|
+
* Checking thrown error is this one using a stable error code
|
|
274
|
+
*
|
|
275
|
+
* ```js
|
|
276
|
+
* if (err.code === 'ERR_JWT_INVALID') {
|
|
277
|
+
* // ...
|
|
278
|
+
* }
|
|
279
|
+
* ```
|
|
280
|
+
*
|
|
281
|
+
* @example
|
|
282
|
+
*
|
|
283
|
+
* Checking thrown error is this one using `instanceof`
|
|
284
|
+
*
|
|
285
|
+
* ```js
|
|
286
|
+
* if (err instanceof jose.errors.JWTInvalid) {
|
|
287
|
+
* // ...
|
|
288
|
+
* }
|
|
289
|
+
* ```
|
|
290
|
+
*/
|
|
291
|
+
export declare class JWTInvalid extends JOSEError {
|
|
292
|
+
/** @ignore */
|
|
293
|
+
static code: string;
|
|
294
|
+
/** A unique error code for {@link JWTInvalid}. */
|
|
295
|
+
code: string;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* An error subclass thrown when a JWK is invalid.
|
|
299
|
+
*
|
|
300
|
+
* @example
|
|
301
|
+
*
|
|
302
|
+
* Checking thrown error is this one using a stable error code
|
|
303
|
+
*
|
|
304
|
+
* ```js
|
|
305
|
+
* if (err.code === 'ERR_JWK_INVALID') {
|
|
306
|
+
* // ...
|
|
307
|
+
* }
|
|
308
|
+
* ```
|
|
309
|
+
*
|
|
310
|
+
* @example
|
|
311
|
+
*
|
|
312
|
+
* Checking thrown error is this one using `instanceof`
|
|
313
|
+
*
|
|
314
|
+
* ```js
|
|
315
|
+
* if (err instanceof jose.errors.JWKInvalid) {
|
|
316
|
+
* // ...
|
|
317
|
+
* }
|
|
318
|
+
* ```
|
|
319
|
+
*/
|
|
320
|
+
export declare class JWKInvalid extends JOSEError {
|
|
321
|
+
/** @ignore */
|
|
322
|
+
static code: string;
|
|
323
|
+
/** A unique error code for {@link JWKInvalid}. */
|
|
324
|
+
code: string;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* An error subclass thrown when a JWKS is invalid.
|
|
328
|
+
*
|
|
329
|
+
* @example
|
|
330
|
+
*
|
|
331
|
+
* Checking thrown error is this one using a stable error code
|
|
332
|
+
*
|
|
333
|
+
* ```js
|
|
334
|
+
* if (err.code === 'ERR_JWKS_INVALID') {
|
|
335
|
+
* // ...
|
|
336
|
+
* }
|
|
337
|
+
* ```
|
|
338
|
+
*
|
|
339
|
+
* @example
|
|
340
|
+
*
|
|
341
|
+
* Checking thrown error is this one using `instanceof`
|
|
342
|
+
*
|
|
343
|
+
* ```js
|
|
344
|
+
* if (err instanceof jose.errors.JWKSInvalid) {
|
|
345
|
+
* // ...
|
|
346
|
+
* }
|
|
347
|
+
* ```
|
|
348
|
+
*/
|
|
349
|
+
export declare class JWKSInvalid extends JOSEError {
|
|
350
|
+
/** @ignore */
|
|
351
|
+
static code: string;
|
|
352
|
+
/** A unique error code for {@link JWKSInvalid}. */
|
|
353
|
+
code: string;
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* An error subclass thrown when no keys match from a JWKS.
|
|
357
|
+
*
|
|
358
|
+
* @example
|
|
359
|
+
*
|
|
360
|
+
* Checking thrown error is this one using a stable error code
|
|
361
|
+
*
|
|
362
|
+
* ```js
|
|
363
|
+
* if (err.code === 'ERR_JWKS_NO_MATCHING_KEY') {
|
|
364
|
+
* // ...
|
|
365
|
+
* }
|
|
366
|
+
* ```
|
|
367
|
+
*
|
|
368
|
+
* @example
|
|
369
|
+
*
|
|
370
|
+
* Checking thrown error is this one using `instanceof`
|
|
371
|
+
*
|
|
372
|
+
* ```js
|
|
373
|
+
* if (err instanceof jose.errors.JWKSNoMatchingKey) {
|
|
374
|
+
* // ...
|
|
375
|
+
* }
|
|
376
|
+
* ```
|
|
377
|
+
*/
|
|
378
|
+
export declare class JWKSNoMatchingKey extends JOSEError {
|
|
379
|
+
/** @ignore */
|
|
380
|
+
static code: string;
|
|
381
|
+
/** A unique error code for {@link JWKSNoMatchingKey}. */
|
|
382
|
+
code: string;
|
|
383
|
+
/** @ignore */
|
|
384
|
+
constructor(message?: string, options?: {
|
|
385
|
+
cause?: unknown;
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* An error subclass thrown when multiple keys match from a JWKS.
|
|
390
|
+
*
|
|
391
|
+
* @example
|
|
392
|
+
*
|
|
393
|
+
* Checking thrown error is this one using a stable error code
|
|
394
|
+
*
|
|
395
|
+
* ```js
|
|
396
|
+
* if (err.code === 'ERR_JWKS_MULTIPLE_MATCHING_KEYS') {
|
|
397
|
+
* // ...
|
|
398
|
+
* }
|
|
399
|
+
* ```
|
|
400
|
+
*
|
|
401
|
+
* @example
|
|
402
|
+
*
|
|
403
|
+
* Checking thrown error is this one using `instanceof`
|
|
404
|
+
*
|
|
405
|
+
* ```js
|
|
406
|
+
* if (err instanceof jose.errors.JWKSMultipleMatchingKeys) {
|
|
407
|
+
* // ...
|
|
408
|
+
* }
|
|
409
|
+
* ```
|
|
410
|
+
*/
|
|
411
|
+
export declare class JWKSMultipleMatchingKeys extends JOSEError {
|
|
412
|
+
/** @ignore */
|
|
413
|
+
[Symbol.asyncIterator]: () => AsyncIterableIterator<types.CryptoKey>;
|
|
414
|
+
/** @ignore */
|
|
415
|
+
static code: string;
|
|
416
|
+
/** A unique error code for {@link JWKSMultipleMatchingKeys}. */
|
|
417
|
+
code: string;
|
|
418
|
+
/** @ignore */
|
|
419
|
+
constructor(message?: string, options?: {
|
|
420
|
+
cause?: unknown;
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Timeout was reached when retrieving the JWKS response.
|
|
425
|
+
*
|
|
426
|
+
* @example
|
|
427
|
+
*
|
|
428
|
+
* Checking thrown error is this one using a stable error code
|
|
429
|
+
*
|
|
430
|
+
* ```js
|
|
431
|
+
* if (err.code === 'ERR_JWKS_TIMEOUT') {
|
|
432
|
+
* // ...
|
|
433
|
+
* }
|
|
434
|
+
* ```
|
|
435
|
+
*
|
|
436
|
+
* @example
|
|
437
|
+
*
|
|
438
|
+
* Checking thrown error is this one using `instanceof`
|
|
439
|
+
*
|
|
440
|
+
* ```js
|
|
441
|
+
* if (err instanceof jose.errors.JWKSTimeout) {
|
|
442
|
+
* // ...
|
|
443
|
+
* }
|
|
444
|
+
* ```
|
|
445
|
+
*/
|
|
446
|
+
export declare class JWKSTimeout extends JOSEError {
|
|
447
|
+
/** @ignore */
|
|
448
|
+
static code: string;
|
|
449
|
+
/** A unique error code for {@link JWKSTimeout}. */
|
|
450
|
+
code: string;
|
|
451
|
+
/** @ignore */
|
|
452
|
+
constructor(message?: string, options?: {
|
|
453
|
+
cause?: unknown;
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* An error subclass thrown when JWS signature verification fails.
|
|
458
|
+
*
|
|
459
|
+
* @example
|
|
460
|
+
*
|
|
461
|
+
* Checking thrown error is this one using a stable error code
|
|
462
|
+
*
|
|
463
|
+
* ```js
|
|
464
|
+
* if (err.code === 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED') {
|
|
465
|
+
* // ...
|
|
466
|
+
* }
|
|
467
|
+
* ```
|
|
468
|
+
*
|
|
469
|
+
* @example
|
|
470
|
+
*
|
|
471
|
+
* Checking thrown error is this one using `instanceof`
|
|
472
|
+
*
|
|
473
|
+
* ```js
|
|
474
|
+
* if (err instanceof jose.errors.JWSSignatureVerificationFailed) {
|
|
475
|
+
* // ...
|
|
476
|
+
* }
|
|
477
|
+
* ```
|
|
478
|
+
*/
|
|
479
|
+
export declare class JWSSignatureVerificationFailed extends JOSEError {
|
|
480
|
+
/** @ignore */
|
|
481
|
+
static code: string;
|
|
482
|
+
/** A unique error code for {@link JWSSignatureVerificationFailed}. */
|
|
483
|
+
code: string;
|
|
484
|
+
/** @ignore */
|
|
485
|
+
constructor(message?: string, options?: {
|
|
486
|
+
cause?: unknown;
|
|
487
|
+
});
|
|
488
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export { compactDecrypt } from './jwe/compact/decrypt.js';
|
|
2
|
+
export { flattenedDecrypt } from './jwe/flattened/decrypt.js';
|
|
3
|
+
export { generalDecrypt } from './jwe/general/decrypt.js';
|
|
4
|
+
export { GeneralEncrypt } from './jwe/general/encrypt.js';
|
|
5
|
+
export { compactVerify } from './jws/compact/verify.js';
|
|
6
|
+
export { flattenedVerify } from './jws/flattened/verify.js';
|
|
7
|
+
export { generalVerify } from './jws/general/verify.js';
|
|
8
|
+
export { jwtVerify } from './jwt/verify.js';
|
|
9
|
+
export { jwtDecrypt } from './jwt/decrypt.js';
|
|
10
|
+
export { CompactEncrypt } from './jwe/compact/encrypt.js';
|
|
11
|
+
export { FlattenedEncrypt } from './jwe/flattened/encrypt.js';
|
|
12
|
+
export { CompactSign } from './jws/compact/sign.js';
|
|
13
|
+
export { FlattenedSign } from './jws/flattened/sign.js';
|
|
14
|
+
export { GeneralSign } from './jws/general/sign.js';
|
|
15
|
+
export { SignJWT } from './jwt/sign.js';
|
|
16
|
+
export { EncryptJWT } from './jwt/encrypt.js';
|
|
17
|
+
export { calculateJwkThumbprint, calculateJwkThumbprintUri } from './jwk/thumbprint.js';
|
|
18
|
+
export { EmbeddedJWK } from './jwk/embedded.js';
|
|
19
|
+
export { createLocalJWKSet } from './jwks/local.js';
|
|
20
|
+
export { createRemoteJWKSet, jwksCache, customFetch } from './jwks/remote.js';
|
|
21
|
+
export { UnsecuredJWT } from './jwt/unsecured.js';
|
|
22
|
+
export { exportPKCS8, exportSPKI, exportJWK } from './key/export.js';
|
|
23
|
+
export { importSPKI, importPKCS8, importX509, importJWK } from './key/import.js';
|
|
24
|
+
export { decodeProtectedHeader } from './util/decode_protected_header.js';
|
|
25
|
+
export { decodeJwt } from './util/decode_jwt.js';
|
|
26
|
+
import * as errors from './util/errors.js';
|
|
27
|
+
export { errors };
|
|
28
|
+
export { generateKeyPair } from './key/generate_key_pair.js';
|
|
29
|
+
export { generateSecret } from './key/generate_secret.js';
|
|
30
|
+
import * as base64url from './util/base64url.js';
|
|
31
|
+
export { base64url };
|
|
32
|
+
export const cryptoRuntime = 'WebCryptoAPI';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { flattenedDecrypt } from '../flattened/decrypt.js';
|
|
2
|
+
import { JWEInvalid } from '../../util/errors.js';
|
|
3
|
+
import { decoder } from '../../lib/buffer_utils.js';
|
|
4
|
+
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 };
|
|
23
|
+
if (typeof key === 'function') {
|
|
24
|
+
return { ...result, key: decrypted.key };
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { FlattenedEncrypt } from '../flattened/encrypt.js';
|
|
2
|
+
export class CompactEncrypt {
|
|
3
|
+
#flattened;
|
|
4
|
+
constructor(plaintext) {
|
|
5
|
+
this.#flattened = new FlattenedEncrypt(plaintext);
|
|
6
|
+
}
|
|
7
|
+
setContentEncryptionKey(cek) {
|
|
8
|
+
this.#flattened.setContentEncryptionKey(cek);
|
|
9
|
+
return this;
|
|
10
|
+
}
|
|
11
|
+
setInitializationVector(iv) {
|
|
12
|
+
this.#flattened.setInitializationVector(iv);
|
|
13
|
+
return this;
|
|
14
|
+
}
|
|
15
|
+
setProtectedHeader(protectedHeader) {
|
|
16
|
+
this.#flattened.setProtectedHeader(protectedHeader);
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
setKeyManagementParameters(parameters) {
|
|
20
|
+
this.#flattened.setKeyManagementParameters(parameters);
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
async encrypt(key, options) {
|
|
24
|
+
const jwe = await this.#flattened.encrypt(key, options);
|
|
25
|
+
return [jwe.protected, jwe.encrypted_key, jwe.iv, jwe.ciphertext, jwe.tag].join('.');
|
|
26
|
+
}
|
|
27
|
+
}
|