jose 4.5.3 → 4.6.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/dist/browser/jwe/general/encrypt.js +8 -1
- package/dist/browser/lib/crypto_key.js +1 -1
- package/dist/browser/lib/decrypt_key_management.js +1 -1
- package/dist/browser/lib/encrypt_key_management.js +1 -1
- package/dist/browser/runtime/ecdhes.js +2 -5
- package/dist/browser/runtime/pbes2kw.js +1 -1
- package/dist/node/cjs/jwe/general/encrypt.js +8 -1
- package/dist/node/cjs/lib/crypto_key.js +1 -1
- package/dist/node/cjs/lib/decrypt_key_management.js +1 -1
- package/dist/node/cjs/lib/encrypt_key_management.js +1 -1
- package/dist/node/cjs/runtime/ecdhes.js +2 -2
- package/dist/node/cjs/runtime/pbes2kw.js +1 -1
- package/dist/node/esm/jwe/general/encrypt.js +8 -1
- package/dist/node/esm/lib/crypto_key.js +1 -1
- package/dist/node/esm/lib/decrypt_key_management.js +1 -1
- package/dist/node/esm/lib/encrypt_key_management.js +1 -1
- package/dist/node/esm/runtime/ecdhes.js +2 -2
- package/dist/node/esm/runtime/pbes2kw.js +1 -1
- package/dist/types/jwe/compact/decrypt.d.ts +26 -0
- package/dist/types/jwe/compact/encrypt.d.ts +56 -0
- package/dist/types/jwe/flattened/decrypt.d.ts +39 -0
- package/dist/types/jwe/flattened/encrypt.d.ts +77 -0
- package/dist/types/jwe/general/decrypt.d.ts +43 -0
- package/dist/types/jwe/general/encrypt.d.ts +63 -0
- package/dist/types/jwk/embedded.d.ts +20 -0
- package/dist/types/jwk/thumbprint.d.ts +19 -0
- package/dist/types/jwks/local.d.ts +42 -0
- package/dist/types/jwks/remote.d.ts +44 -0
- package/dist/types/jws/compact/sign.d.ts +30 -0
- package/dist/types/jws/compact/verify.d.ts +29 -0
- package/dist/types/jws/flattened/sign.d.ts +35 -0
- package/dist/types/jws/flattened/verify.d.ts +34 -0
- package/dist/types/jws/general/sign.d.ts +50 -0
- package/dist/types/jws/general/verify.d.ts +37 -0
- package/dist/types/jwt/decrypt.d.ts +32 -0
- package/dist/types/jwt/encrypt.d.ts +68 -0
- package/dist/types/jwt/produce.d.ts +46 -0
- package/dist/types/jwt/sign.d.ts +28 -0
- package/dist/types/jwt/unsecured.d.ts +34 -0
- package/dist/types/jwt/verify.d.ts +35 -0
- package/dist/types/key/export.d.ts +38 -0
- package/dist/types/key/generate_key_pair.d.ts +38 -0
- package/dist/types/key/generate_secret.d.ts +20 -0
- package/dist/types/key/import.d.ts +96 -0
- package/dist/types/types.d.ts +499 -2
- package/dist/types/util/base64url.d.ts +10 -0
- package/dist/types/util/decode_jwt.d.ts +14 -0
- package/dist/types/util/decode_protected_header.d.ts +11 -0
- package/dist/types/util/errors.d.ts +65 -0
- package/package.json +1 -1
|
@@ -1,2 +1,22 @@
|
|
|
1
1
|
import type { FlattenedJWSInput, JWSHeaderParameters } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* EmbeddedJWK is an implementation of a GetKeyFunction intended to be used with the
|
|
4
|
+
* JWS/JWT verify operations whenever you need to opt-in to verify signatures with
|
|
5
|
+
* a public key embedded in the token's "jwk" (JSON Web Key) Header Parameter.
|
|
6
|
+
* It is recommended to combine this with the verify algorithms option to whitelist
|
|
7
|
+
* JWS algorithms to accept.
|
|
8
|
+
*
|
|
9
|
+
* @example Usage
|
|
10
|
+
* ```js
|
|
11
|
+
* const jwt = 'eyJqd2siOnsiY3J2IjoiUC0yNTYiLCJ4IjoiVU05ZzVuS25aWFlvdldBbE03NmNMejl2VG96UmpfX0NIVV9kT2wtZ09vRSIsInkiOiJkczhhZVF3MWwyY0RDQTdiQ2tPTnZ3REtwWEFidFhqdnFDbGVZSDhXc19VIiwia3R5IjoiRUMifSwiYWxnIjoiRVMyNTYifQ.eyJpc3MiOiJ1cm46ZXhhbXBsZTppc3N1ZXIiLCJhdWQiOiJ1cm46ZXhhbXBsZTphdWRpZW5jZSIsImlhdCI6MTYwNDU4MDc5NH0.60boak3_dErnW47ZPty1C0nrjeVq86EN_eK0GOq6K8w2OA0thKoBxFK4j-NuU9yZ_A9UKGxPT_G87DladBaV9g'
|
|
12
|
+
*
|
|
13
|
+
* const { payload, protectedHeader } = await jose.jwtVerify(jwt, jose.EmbeddedJWK, {
|
|
14
|
+
* issuer: 'urn:example:issuer',
|
|
15
|
+
* audience: 'urn:example:audience'
|
|
16
|
+
* })
|
|
17
|
+
*
|
|
18
|
+
* console.log(protectedHeader)
|
|
19
|
+
* console.log(payload)
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
2
22
|
export declare function EmbeddedJWK(protectedHeader: JWSHeaderParameters, token: FlattenedJWSInput): Promise<import("../types.d").KeyLike>;
|
|
@@ -1,2 +1,21 @@
|
|
|
1
1
|
import type { JWK } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Calculates a base64url-encoded JSON Web Key (JWK) Thumbprint as per
|
|
4
|
+
* [RFC7638](https://www.rfc-editor.org/rfc/rfc7638).
|
|
5
|
+
*
|
|
6
|
+
* @param jwk JSON Web Key.
|
|
7
|
+
* @param digestAlgorithm Digest Algorithm to use for calculating the thumbprint.
|
|
8
|
+
* Default is sha256. Accepted is "sha256", "sha384", "sha512".
|
|
9
|
+
*
|
|
10
|
+
* @example Usage
|
|
11
|
+
* ```js
|
|
12
|
+
* const thumbprint = await jose.calculateJwkThumbprint({
|
|
13
|
+
* kty: 'RSA',
|
|
14
|
+
* e: 'AQAB',
|
|
15
|
+
* n: '12oBZRhCiZFJLcPg59LkZZ9mdhSMTKAQZYq32k_ti5SBB6jerkh-WzOMAO664r_qyLkqHUSp3u5SbXtseZEpN3XPWGKSxjsy-1JyEFTdLSYe6f9gfrmxkUF_7DTpq0gn6rntP05g2-wFW50YO7mosfdslfrTJYWHFhJALabAeYirYD7-9kqq9ebfFMF4sRRELbv9oi36As6Q9B3Qb5_C1rAzqfao_PCsf9EPsTZsVVVkA5qoIAr47lo1ipfiBPxUCCNSdvkmDTYgvvRm6ZoMjFbvOtgyts55fXKdMWv7I9HMD5HwE9uW839PWA514qhbcIsXEYSFMPMV6fnlsiZvQQ'
|
|
16
|
+
* })
|
|
17
|
+
*
|
|
18
|
+
* console.log(thumbprint)
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
2
21
|
export declare function calculateJwkThumbprint(jwk: JWK, digestAlgorithm?: 'sha256' | 'sha384' | 'sha512'): Promise<string>;
|
|
@@ -1,9 +1,51 @@
|
|
|
1
1
|
import type { KeyLike, JWSHeaderParameters, JSONWebKeySet, FlattenedJWSInput, GetKeyFunction } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* @private
|
|
4
|
+
*/
|
|
2
5
|
export declare function isJWKSLike(jwks: unknown): jwks is JSONWebKeySet;
|
|
6
|
+
/**
|
|
7
|
+
* @private
|
|
8
|
+
*/
|
|
3
9
|
export declare class LocalJWKSet {
|
|
4
10
|
protected _jwks?: JSONWebKeySet;
|
|
5
11
|
private _cached;
|
|
6
12
|
constructor(jwks: unknown);
|
|
7
13
|
getKey(protectedHeader: JWSHeaderParameters, token: FlattenedJWSInput): Promise<KeyLike>;
|
|
8
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Returns a function that resolves to a key object from a locally
|
|
17
|
+
* stored, or otherwise available, JSON Web Key Set.
|
|
18
|
+
*
|
|
19
|
+
* Only a single public key must match the selection process.
|
|
20
|
+
*
|
|
21
|
+
* @param jwks JSON Web Key Set formatted object.
|
|
22
|
+
*
|
|
23
|
+
* @example Usage
|
|
24
|
+
* ```js
|
|
25
|
+
* const JWKS = jose.createLocalJWKSet({
|
|
26
|
+
* keys: [
|
|
27
|
+
* {
|
|
28
|
+
* kty: 'RSA',
|
|
29
|
+
* e: 'AQAB',
|
|
30
|
+
* n: '12oBZRhCiZFJLcPg59LkZZ9mdhSMTKAQZYq32k_ti5SBB6jerkh-WzOMAO664r_qyLkqHUSp3u5SbXtseZEpN3XPWGKSxjsy-1JyEFTdLSYe6f9gfrmxkUF_7DTpq0gn6rntP05g2-wFW50YO7mosfdslfrTJYWHFhJALabAeYirYD7-9kqq9ebfFMF4sRRELbv9oi36As6Q9B3Qb5_C1rAzqfao_PCsf9EPsTZsVVVkA5qoIAr47lo1ipfiBPxUCCNSdvkmDTYgvvRm6ZoMjFbvOtgyts55fXKdMWv7I9HMD5HwE9uW839PWA514qhbcIsXEYSFMPMV6fnlsiZvQQ',
|
|
31
|
+
* alg: 'PS256'
|
|
32
|
+
* },
|
|
33
|
+
* {
|
|
34
|
+
* crv: 'P-256',
|
|
35
|
+
* kty: 'EC',
|
|
36
|
+
* x: 'ySK38C1jBdLwDsNWKzzBHqKYEE5Cgv-qjWvorUXk9fw',
|
|
37
|
+
* y: '_LeQBw07cf5t57Iavn4j-BqJsAD1dpoz8gokd3sBsOo',
|
|
38
|
+
* alg: 'ES256'
|
|
39
|
+
* }
|
|
40
|
+
* ]
|
|
41
|
+
* })
|
|
42
|
+
*
|
|
43
|
+
* const { payload, protectedHeader } = await jose.jwtVerify(jwt, JWKS, {
|
|
44
|
+
* issuer: 'urn:example:issuer',
|
|
45
|
+
* audience: 'urn:example:audience'
|
|
46
|
+
* })
|
|
47
|
+
* console.log(protectedHeader)
|
|
48
|
+
* console.log(payload)
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
9
51
|
export declare function createLocalJWKSet(jwks: JSONWebKeySet): GetKeyFunction<JWSHeaderParameters, FlattenedJWSInput>;
|
|
@@ -1,11 +1,55 @@
|
|
|
1
1
|
import type { JWSHeaderParameters, FlattenedJWSInput, GetKeyFunction } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Options for the remote JSON Web Key Set.
|
|
4
|
+
*/
|
|
2
5
|
export interface RemoteJWKSetOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Timeout (in milliseconds) for the HTTP request. When reached the request will be
|
|
8
|
+
* aborted and the verification will fail. Default is 5000.
|
|
9
|
+
*/
|
|
3
10
|
timeoutDuration?: number;
|
|
11
|
+
/**
|
|
12
|
+
* Duration (in milliseconds) for which no more HTTP requests will be triggered
|
|
13
|
+
* after a previous successful fetch. Default is 30000.
|
|
14
|
+
*/
|
|
4
15
|
cooldownDuration?: number;
|
|
16
|
+
/**
|
|
17
|
+
* An instance of [http.Agent](https://nodejs.org/api/http.html#http_class_http_agent)
|
|
18
|
+
* or [https.Agent](https://nodejs.org/api/https.html#https_class_https_agent) to pass
|
|
19
|
+
* to the [http.get](https://nodejs.org/api/http.html#http_http_get_options_callback)
|
|
20
|
+
* or [https.get](https://nodejs.org/api/https.html#https_https_get_options_callback)
|
|
21
|
+
* method's options. Use when behind an http(s) proxy.
|
|
22
|
+
* This is a Node.js runtime specific option, it is ignored
|
|
23
|
+
* when used outside of Node.js runtime.
|
|
24
|
+
*/
|
|
5
25
|
agent?: any;
|
|
6
26
|
}
|
|
7
27
|
interface URL {
|
|
8
28
|
href: string;
|
|
9
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Returns a function that resolves to a key object downloaded from a
|
|
32
|
+
* remote endpoint returning a JSON Web Key Set, that is, for example,
|
|
33
|
+
* an OAuth 2.0 or OIDC jwks_uri. Only a single public key must match
|
|
34
|
+
* the selection process.
|
|
35
|
+
* The JSON Web Key Set is fetched when no key matches the selection
|
|
36
|
+
* process but only as frequently as the `cooldownDuration` option allows,
|
|
37
|
+
* to prevent abuse.
|
|
38
|
+
*
|
|
39
|
+
* @param url URL to fetch the JSON Web Key Set from.
|
|
40
|
+
* @param options Options for the remote JSON Web Key Set.
|
|
41
|
+
*
|
|
42
|
+
* @example Usage
|
|
43
|
+
* ```js
|
|
44
|
+
* const JWKS = jose.createRemoteJWKSet(new URL('https://www.googleapis.com/oauth2/v3/certs'))
|
|
45
|
+
*
|
|
46
|
+
* const { payload, protectedHeader } = await jose.jwtVerify(jwt, JWKS, {
|
|
47
|
+
* issuer: 'urn:example:issuer',
|
|
48
|
+
* audience: 'urn:example:audience'
|
|
49
|
+
* })
|
|
50
|
+
* console.log(protectedHeader)
|
|
51
|
+
* console.log(payload)
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
10
54
|
export declare function createRemoteJWKSet(url: URL, options?: RemoteJWKSetOptions): GetKeyFunction<JWSHeaderParameters, FlattenedJWSInput>;
|
|
11
55
|
export {};
|
|
@@ -1,7 +1,37 @@
|
|
|
1
1
|
import type { CompactJWSHeaderParameters, KeyLike, SignOptions } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* The CompactSign class is a utility for creating Compact JWS strings.
|
|
4
|
+
*
|
|
5
|
+
* @example Usage
|
|
6
|
+
* ```js
|
|
7
|
+
* const jws = await new jose.CompactSign(
|
|
8
|
+
* new TextEncoder().encode(
|
|
9
|
+
* 'It’s a dangerous business, Frodo, going out your door.'
|
|
10
|
+
* )
|
|
11
|
+
* )
|
|
12
|
+
* .setProtectedHeader({ alg: 'ES256' })
|
|
13
|
+
* .sign(privateKey)
|
|
14
|
+
*
|
|
15
|
+
* console.log(jws)
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
2
18
|
export declare class CompactSign {
|
|
3
19
|
private _flattened;
|
|
20
|
+
/**
|
|
21
|
+
* @param payload Binary representation of the payload to sign.
|
|
22
|
+
*/
|
|
4
23
|
constructor(payload: Uint8Array);
|
|
24
|
+
/**
|
|
25
|
+
* Sets the JWS Protected Header on the Sign object.
|
|
26
|
+
*
|
|
27
|
+
* @param protectedHeader JWS Protected Header.
|
|
28
|
+
*/
|
|
5
29
|
setProtectedHeader(protectedHeader: CompactJWSHeaderParameters): this;
|
|
30
|
+
/**
|
|
31
|
+
* Signs and resolves the value of the Compact JWS string.
|
|
32
|
+
*
|
|
33
|
+
* @param key Private Key or Secret to sign the JWS with.
|
|
34
|
+
* @param options JWS Sign options.
|
|
35
|
+
*/
|
|
6
36
|
sign(key: KeyLike | Uint8Array, options?: SignOptions): Promise<string>;
|
|
7
37
|
}
|
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
import type { CompactVerifyResult, FlattenedJWSInput, GetKeyFunction, CompactJWSHeaderParameters, KeyLike, VerifyOptions, ResolvedKey } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Interface for Compact JWS Verification dynamic key resolution.
|
|
4
|
+
* No token components have been verified at the time of this function call.
|
|
5
|
+
*
|
|
6
|
+
* See [createRemoteJWKSet](../functions/jwks_remote.createRemoteJWKSet.md#function-createremotejwkset)
|
|
7
|
+
* to verify using a remote JSON Web Key Set.
|
|
8
|
+
*/
|
|
2
9
|
export interface CompactVerifyGetKey extends GetKeyFunction<CompactJWSHeaderParameters, FlattenedJWSInput> {
|
|
3
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Verifies the signature and format of and afterwards decodes the Compact JWS.
|
|
13
|
+
*
|
|
14
|
+
* @param jws Compact JWS.
|
|
15
|
+
* @param key Key to verify the JWS with.
|
|
16
|
+
* @param options JWS Verify options.
|
|
17
|
+
*
|
|
18
|
+
* @example Usage
|
|
19
|
+
* ```js
|
|
20
|
+
* const jws = 'eyJhbGciOiJFUzI1NiJ9.SXTigJlzIGEgZGFuZ2Vyb3VzIGJ1c2luZXNzLCBGcm9kbywgZ29pbmcgb3V0IHlvdXIgZG9vci4.kkAs_gPPxWMI3rHuVlxHaTPfDWDoqdI8jSvuSmqV-8IHIWXg9mcAeC9ggV-45ZHRbiRJ3obUIFo1rHphPA5URg'
|
|
21
|
+
*
|
|
22
|
+
* const { payload, protectedHeader } = await jose.compactVerify(jws, publicKey)
|
|
23
|
+
*
|
|
24
|
+
* console.log(protectedHeader)
|
|
25
|
+
* console.log(new TextDecoder().decode(payload))
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
4
28
|
export declare function compactVerify(jws: string | Uint8Array, key: KeyLike | Uint8Array, options?: VerifyOptions): Promise<CompactVerifyResult>;
|
|
29
|
+
/**
|
|
30
|
+
* @param jws Compact JWS.
|
|
31
|
+
* @param getKey Function resolving a key to verify the JWS with.
|
|
32
|
+
* @param options JWS Verify options.
|
|
33
|
+
*/
|
|
5
34
|
export declare function compactVerify(jws: string | Uint8Array, getKey: CompactVerifyGetKey, options?: VerifyOptions): Promise<CompactVerifyResult & ResolvedKey>;
|
|
@@ -1,10 +1,45 @@
|
|
|
1
1
|
import type { KeyLike, FlattenedJWS, JWSHeaderParameters, SignOptions } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* The FlattenedSign class is a utility for creating Flattened JWS objects.
|
|
4
|
+
*
|
|
5
|
+
* @example Usage
|
|
6
|
+
* ```js
|
|
7
|
+
* const jws = await new jose.FlattenedSign(
|
|
8
|
+
* new TextEncoder().encode(
|
|
9
|
+
* 'It’s a dangerous business, Frodo, going out your door.'
|
|
10
|
+
* )
|
|
11
|
+
* )
|
|
12
|
+
* .setProtectedHeader({ alg: 'ES256' })
|
|
13
|
+
* .sign(privateKey)
|
|
14
|
+
*
|
|
15
|
+
* console.log(jws)
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
2
18
|
export declare class FlattenedSign {
|
|
3
19
|
private _payload;
|
|
4
20
|
private _protectedHeader;
|
|
5
21
|
private _unprotectedHeader;
|
|
22
|
+
/**
|
|
23
|
+
* @param payload Binary representation of the payload to sign.
|
|
24
|
+
*/
|
|
6
25
|
constructor(payload: Uint8Array);
|
|
26
|
+
/**
|
|
27
|
+
* Sets the JWS Protected Header on the FlattenedSign object.
|
|
28
|
+
*
|
|
29
|
+
* @param protectedHeader JWS Protected Header.
|
|
30
|
+
*/
|
|
7
31
|
setProtectedHeader(protectedHeader: JWSHeaderParameters): this;
|
|
32
|
+
/**
|
|
33
|
+
* Sets the JWS Unprotected Header on the FlattenedSign object.
|
|
34
|
+
*
|
|
35
|
+
* @param unprotectedHeader JWS Unprotected Header.
|
|
36
|
+
*/
|
|
8
37
|
setUnprotectedHeader(unprotectedHeader: JWSHeaderParameters): this;
|
|
38
|
+
/**
|
|
39
|
+
* Signs and resolves the value of the Flattened JWS object.
|
|
40
|
+
*
|
|
41
|
+
* @param key Private Key or Secret to sign the JWS with.
|
|
42
|
+
* @param options JWS Sign options.
|
|
43
|
+
*/
|
|
9
44
|
sign(key: KeyLike | Uint8Array, options?: SignOptions): Promise<FlattenedJWS>;
|
|
10
45
|
}
|
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
import type { FlattenedVerifyResult, KeyLike, FlattenedJWSInput, JWSHeaderParameters, VerifyOptions, GetKeyFunction, ResolvedKey } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Interface for Flattened JWS Verification dynamic key resolution.
|
|
4
|
+
* No token components have been verified at the time of this function call.
|
|
5
|
+
*
|
|
6
|
+
* See [createRemoteJWKSet](../functions/jwks_remote.createRemoteJWKSet.md#function-createremotejwkset)
|
|
7
|
+
* to verify using a remote JSON Web Key Set.
|
|
8
|
+
*/
|
|
2
9
|
export interface FlattenedVerifyGetKey extends GetKeyFunction<JWSHeaderParameters | undefined, FlattenedJWSInput> {
|
|
3
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Verifies the signature and format of and afterwards decodes the Flattened JWS.
|
|
13
|
+
*
|
|
14
|
+
* @param jws Flattened JWS.
|
|
15
|
+
* @param key Key to verify the JWS with.
|
|
16
|
+
* @param options JWS Verify options.
|
|
17
|
+
*
|
|
18
|
+
* @example Usage
|
|
19
|
+
* ```js
|
|
20
|
+
* const decoder = new TextDecoder()
|
|
21
|
+
* const jws = {
|
|
22
|
+
* signature: 'FVVOXwj6kD3DqdfD9yYqfT2W9jv-Nop4kOehp_DeDGNB5dQNSPRvntBY6xH3uxlCxE8na9d_kyhYOcanpDJ0EA',
|
|
23
|
+
* payload: 'SXTigJlzIGEgZGFuZ2Vyb3VzIGJ1c2luZXNzLCBGcm9kbywgZ29pbmcgb3V0IHlvdXIgZG9vci4',
|
|
24
|
+
* protected: 'eyJhbGciOiJFUzI1NiJ9'
|
|
25
|
+
* }
|
|
26
|
+
*
|
|
27
|
+
* const { payload, protectedHeader } = await jose.flattenedVerify(jws, publicKey)
|
|
28
|
+
*
|
|
29
|
+
* console.log(protectedHeader)
|
|
30
|
+
* console.log(decoder.decode(payload))
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
4
33
|
export declare function flattenedVerify(jws: FlattenedJWSInput, key: KeyLike | Uint8Array, options?: VerifyOptions): Promise<FlattenedVerifyResult>;
|
|
34
|
+
/**
|
|
35
|
+
* @param jws Flattened JWS.
|
|
36
|
+
* @param getKey Function resolving a key to verify the JWS with.
|
|
37
|
+
* @param options JWS Verify options.
|
|
38
|
+
*/
|
|
5
39
|
export declare function flattenedVerify(jws: FlattenedJWSInput, getKey: FlattenedVerifyGetKey, options?: VerifyOptions): Promise<FlattenedVerifyResult & ResolvedKey>;
|
|
@@ -1,15 +1,65 @@
|
|
|
1
1
|
import type { KeyLike, GeneralJWS, JWSHeaderParameters, SignOptions } from '../../types';
|
|
2
2
|
export interface Signature {
|
|
3
|
+
/**
|
|
4
|
+
* Sets the JWS Protected Header on the Signature object.
|
|
5
|
+
*
|
|
6
|
+
* @param protectedHeader JWS Protected Header.
|
|
7
|
+
*/
|
|
3
8
|
setProtectedHeader(protectedHeader: JWSHeaderParameters): Signature;
|
|
9
|
+
/**
|
|
10
|
+
* Sets the JWS Unprotected Header on the Signature object.
|
|
11
|
+
*
|
|
12
|
+
* @param unprotectedHeader JWS Unprotected Header.
|
|
13
|
+
*/
|
|
4
14
|
setUnprotectedHeader(unprotectedHeader: JWSHeaderParameters): Signature;
|
|
15
|
+
/**
|
|
16
|
+
* A shorthand for calling addSignature() on the enclosing GeneralSign instance
|
|
17
|
+
*/
|
|
5
18
|
addSignature(...args: Parameters<GeneralSign['addSignature']>): Signature;
|
|
19
|
+
/**
|
|
20
|
+
* A shorthand for calling encrypt() on the enclosing GeneralSign instance
|
|
21
|
+
*/
|
|
6
22
|
sign(...args: Parameters<GeneralSign['sign']>): Promise<GeneralJWS>;
|
|
23
|
+
/**
|
|
24
|
+
* Returns the enclosing GeneralSign
|
|
25
|
+
*/
|
|
7
26
|
done(): GeneralSign;
|
|
8
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* The GeneralSign class is a utility for creating General JWS objects.
|
|
30
|
+
*
|
|
31
|
+
* @example Usage
|
|
32
|
+
* ```js
|
|
33
|
+
* const jws = await new jose.GeneralSign(
|
|
34
|
+
* new TextEncoder().encode(
|
|
35
|
+
* 'It’s a dangerous business, Frodo, going out your door.'
|
|
36
|
+
* )
|
|
37
|
+
* )
|
|
38
|
+
* .addSignature(ecPrivateKey)
|
|
39
|
+
* .setProtectedHeader({ alg: 'ES256' })
|
|
40
|
+
* .addSignature(rsaPrivateKey)
|
|
41
|
+
* .setProtectedHeader({ alg: 'PS256' })
|
|
42
|
+
* .sign()
|
|
43
|
+
*
|
|
44
|
+
* console.log(jws)
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
9
47
|
export declare class GeneralSign {
|
|
10
48
|
private _payload;
|
|
11
49
|
private _signatures;
|
|
50
|
+
/**
|
|
51
|
+
* @param payload Binary representation of the payload to sign.
|
|
52
|
+
*/
|
|
12
53
|
constructor(payload: Uint8Array);
|
|
54
|
+
/**
|
|
55
|
+
* Adds an additional signature for the General JWS object.
|
|
56
|
+
*
|
|
57
|
+
* @param key Private Key or Secret to sign the individual JWS signature with.
|
|
58
|
+
* @param options JWS Sign options.
|
|
59
|
+
*/
|
|
13
60
|
addSignature(key: KeyLike | Uint8Array, options?: SignOptions): Signature;
|
|
61
|
+
/**
|
|
62
|
+
* Signs and resolves the value of the General JWS object.
|
|
63
|
+
*/
|
|
14
64
|
sign(): Promise<GeneralJWS>;
|
|
15
65
|
}
|
|
@@ -1,5 +1,42 @@
|
|
|
1
1
|
import type { GeneralJWSInput, GeneralVerifyResult, FlattenedJWSInput, GetKeyFunction, JWSHeaderParameters, KeyLike, VerifyOptions, ResolvedKey } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Interface for General JWS Verification dynamic key resolution.
|
|
4
|
+
* No token components have been verified at the time of this function call.
|
|
5
|
+
*
|
|
6
|
+
* See [createRemoteJWKSet](../functions/jwks_remote.createRemoteJWKSet.md#function-createremotejwkset)
|
|
7
|
+
* to verify using a remote JSON Web Key Set.
|
|
8
|
+
*/
|
|
2
9
|
export interface GeneralVerifyGetKey extends GetKeyFunction<JWSHeaderParameters, FlattenedJWSInput> {
|
|
3
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Verifies the signature and format of and afterwards decodes the General JWS.
|
|
13
|
+
*
|
|
14
|
+
* @param jws General JWS.
|
|
15
|
+
* @param key Key to verify the JWS with.
|
|
16
|
+
* @param options JWS Verify options.
|
|
17
|
+
*
|
|
18
|
+
* @example Usage
|
|
19
|
+
* ```js
|
|
20
|
+
* const jws = {
|
|
21
|
+
* payload: 'SXTigJlzIGEgZGFuZ2Vyb3VzIGJ1c2luZXNzLCBGcm9kbywgZ29pbmcgb3V0IHlvdXIgZG9vci4',
|
|
22
|
+
* signatures: [
|
|
23
|
+
* {
|
|
24
|
+
* signature: 'FVVOXwj6kD3DqdfD9yYqfT2W9jv-Nop4kOehp_DeDGNB5dQNSPRvntBY6xH3uxlCxE8na9d_kyhYOcanpDJ0EA',
|
|
25
|
+
* protected: 'eyJhbGciOiJFUzI1NiJ9'
|
|
26
|
+
* }
|
|
27
|
+
* ]
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* const { payload, protectedHeader } = await jose.generalVerify(jws, publicKey)
|
|
31
|
+
*
|
|
32
|
+
* console.log(protectedHeader)
|
|
33
|
+
* console.log(new TextDecoder().decode(payload))
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
4
36
|
export declare function generalVerify(jws: GeneralJWSInput, key: KeyLike | Uint8Array, options?: VerifyOptions): Promise<GeneralVerifyResult>;
|
|
37
|
+
/**
|
|
38
|
+
* @param jws General JWS.
|
|
39
|
+
* @param getKey Function resolving a key to verify the JWS with.
|
|
40
|
+
* @param options JWS Verify options.
|
|
41
|
+
*/
|
|
5
42
|
export declare function generalVerify(jws: GeneralJWSInput, getKey: GeneralVerifyGetKey, options?: VerifyOptions): Promise<GeneralVerifyResult & ResolvedKey>;
|
|
@@ -1,7 +1,39 @@
|
|
|
1
1
|
import type { KeyLike, DecryptOptions, JWTClaimVerificationOptions, GetKeyFunction, CompactJWEHeaderParameters, FlattenedJWE, JWTDecryptResult, ResolvedKey } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Combination of JWE Decryption options and JWT Claims Set verification options.
|
|
4
|
+
*/
|
|
2
5
|
export interface JWTDecryptOptions extends DecryptOptions, JWTClaimVerificationOptions {
|
|
3
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Interface for JWT Decryption dynamic key resolution.
|
|
9
|
+
* No token components have been verified at the time of this function call.
|
|
10
|
+
*/
|
|
4
11
|
export interface JWTDecryptGetKey extends GetKeyFunction<CompactJWEHeaderParameters, FlattenedJWE> {
|
|
5
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Verifies the JWT format (to be a JWE Compact format), decrypts the ciphertext, validates the JWT Claims Set.
|
|
15
|
+
*
|
|
16
|
+
* @param jwt JSON Web Token value (encoded as JWE).
|
|
17
|
+
* @param key Private Key or Secret to decrypt and verify the JWT with.
|
|
18
|
+
* @param options JWT Decryption and JWT Claims Set validation options.
|
|
19
|
+
*
|
|
20
|
+
* @example Usage
|
|
21
|
+
* ```js
|
|
22
|
+
* const jwt = 'eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIn0..KVcNLqK-3-8ZkYIC.xSwF4VxO0kUMUD2W-cifsNUxnr-swyBq-nADBptyt6y9n79-iNc5b0AALJpRwc0wwDkJw8hNOMjApNUTMsK9b-asToZ3DXFMvwfJ6n1aWefvd7RsoZ2LInWFfVAuttJDzoGB.uuexQoWHwrLMEYRElT8pBQ'
|
|
23
|
+
*
|
|
24
|
+
* const { payload, protectedHeader } = await jose.jwtDecrypt(jwt, secretKey, {
|
|
25
|
+
* issuer: 'urn:example:issuer',
|
|
26
|
+
* audience: 'urn:example:audience'
|
|
27
|
+
* })
|
|
28
|
+
*
|
|
29
|
+
* console.log(protectedHeader)
|
|
30
|
+
* console.log(payload)
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
6
33
|
export declare function jwtDecrypt(jwt: string | Uint8Array, key: KeyLike | Uint8Array, options?: JWTDecryptOptions): Promise<JWTDecryptResult>;
|
|
34
|
+
/**
|
|
35
|
+
* @param jwt JSON Web Token value (encoded as JWE).
|
|
36
|
+
* @param getKey Function resolving Private Key or Secret to decrypt and verify the JWT with.
|
|
37
|
+
* @param options JWT Decryption and JWT Claims Set validation options.
|
|
38
|
+
*/
|
|
7
39
|
export declare function jwtDecrypt(jwt: string | Uint8Array, getKey: JWTDecryptGetKey, options?: JWTDecryptOptions): Promise<JWTDecryptResult & ResolvedKey>;
|
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
import type { EncryptOptions, CompactJWEHeaderParameters, JWEKeyManagementHeaderParameters, KeyLike } from '../types';
|
|
2
2
|
import { ProduceJWT } from './produce';
|
|
3
|
+
/**
|
|
4
|
+
* The EncryptJWT class is a utility for creating Compact JWE formatted JWT strings.
|
|
5
|
+
*
|
|
6
|
+
* @example Usage
|
|
7
|
+
* ```js
|
|
8
|
+
* const jwt = await new jose.EncryptJWT({ 'urn:example:claim': true })
|
|
9
|
+
* .setProtectedHeader({ alg: 'dir', enc: 'A256GCM' })
|
|
10
|
+
* .setIssuedAt()
|
|
11
|
+
* .setIssuer('urn:example:issuer')
|
|
12
|
+
* .setAudience('urn:example:audience')
|
|
13
|
+
* .setExpirationTime('2h')
|
|
14
|
+
* .encrypt(secretKey)
|
|
15
|
+
*
|
|
16
|
+
* console.log(jwt)
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
3
19
|
export declare class EncryptJWT extends ProduceJWT {
|
|
4
20
|
private _cek;
|
|
5
21
|
private _iv;
|
|
@@ -8,12 +24,64 @@ export declare class EncryptJWT extends ProduceJWT {
|
|
|
8
24
|
private _replicateIssuerAsHeader;
|
|
9
25
|
private _replicateSubjectAsHeader;
|
|
10
26
|
private _replicateAudienceAsHeader;
|
|
27
|
+
/**
|
|
28
|
+
* Sets the JWE Protected Header on the EncryptJWT object.
|
|
29
|
+
*
|
|
30
|
+
* @param protectedHeader JWE Protected Header.
|
|
31
|
+
* Must contain an "alg" (JWE Algorithm) and "enc" (JWE
|
|
32
|
+
* Encryption Algorithm) properties.
|
|
33
|
+
*/
|
|
11
34
|
setProtectedHeader(protectedHeader: CompactJWEHeaderParameters): this;
|
|
35
|
+
/**
|
|
36
|
+
* Sets the JWE Key Management parameters to be used when encrypting.
|
|
37
|
+
* Use of this is method is really only needed for ECDH based algorithms
|
|
38
|
+
* when utilizing the Agreement PartyUInfo or Agreement PartyVInfo parameters.
|
|
39
|
+
* Other parameters will always be randomly generated when needed and missing.
|
|
40
|
+
*
|
|
41
|
+
* @param parameters JWE Key Management parameters.
|
|
42
|
+
*/
|
|
12
43
|
setKeyManagementParameters(parameters: JWEKeyManagementHeaderParameters): this;
|
|
44
|
+
/**
|
|
45
|
+
* Sets a content encryption key to use, by default a random suitable one
|
|
46
|
+
* is generated for the JWE enc" (Encryption Algorithm) Header Parameter.
|
|
47
|
+
*
|
|
48
|
+
* @param cek JWE Content Encryption Key.
|
|
49
|
+
*
|
|
50
|
+
* @deprecated You should not use this method. It is only really intended
|
|
51
|
+
* for test and vector validation purposes.
|
|
52
|
+
*/
|
|
13
53
|
setContentEncryptionKey(cek: Uint8Array): this;
|
|
54
|
+
/**
|
|
55
|
+
* Sets the JWE Initialization Vector to use for content encryption, by default
|
|
56
|
+
* a random suitable one is generated for the JWE enc" (Encryption Algorithm)
|
|
57
|
+
* Header Parameter.
|
|
58
|
+
*
|
|
59
|
+
* @param iv JWE Initialization Vector.
|
|
60
|
+
*
|
|
61
|
+
* @deprecated You should not use this method. It is only really intended
|
|
62
|
+
* for test and vector validation purposes.
|
|
63
|
+
*/
|
|
14
64
|
setInitializationVector(iv: Uint8Array): this;
|
|
65
|
+
/**
|
|
66
|
+
* Replicates the "iss" (Issuer) Claim as a JWE Protected Header Parameter as per
|
|
67
|
+
* [RFC7519#section-5.3](https://www.rfc-editor.org/rfc/rfc7519#section-5.3).
|
|
68
|
+
*/
|
|
15
69
|
replicateIssuerAsHeader(): this;
|
|
70
|
+
/**
|
|
71
|
+
* Replicates the "sub" (Subject) Claim as a JWE Protected Header Parameter as per
|
|
72
|
+
* [RFC7519#section-5.3](https://www.rfc-editor.org/rfc/rfc7519#section-5.3).
|
|
73
|
+
*/
|
|
16
74
|
replicateSubjectAsHeader(): this;
|
|
75
|
+
/**
|
|
76
|
+
* Replicates the "aud" (Audience) Claim as a JWE Protected Header Parameter as per
|
|
77
|
+
* [RFC7519#section-5.3](https://www.rfc-editor.org/rfc/rfc7519#section-5.3).
|
|
78
|
+
*/
|
|
17
79
|
replicateAudienceAsHeader(): this;
|
|
80
|
+
/**
|
|
81
|
+
* Encrypts and returns the JWT.
|
|
82
|
+
*
|
|
83
|
+
* @param key Public Key or Secret to encrypt the JWT with.
|
|
84
|
+
* @param options JWE Encryption options.
|
|
85
|
+
*/
|
|
18
86
|
encrypt(key: KeyLike | Uint8Array, options?: EncryptOptions): Promise<string>;
|
|
19
87
|
}
|
|
@@ -1,12 +1,58 @@
|
|
|
1
1
|
import type { JWTPayload } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Generic class for JWT producing.
|
|
4
|
+
*/
|
|
2
5
|
export declare class ProduceJWT {
|
|
3
6
|
protected _payload: JWTPayload;
|
|
7
|
+
/**
|
|
8
|
+
* @param payload The JWT Claims Set object.
|
|
9
|
+
*/
|
|
4
10
|
constructor(payload: JWTPayload);
|
|
11
|
+
/**
|
|
12
|
+
* Set "iss" (Issuer) Claim.
|
|
13
|
+
*
|
|
14
|
+
* @param issuer "Issuer" Claim value to set on the JWT Claims Set.
|
|
15
|
+
*/
|
|
5
16
|
setIssuer(issuer: string): this;
|
|
17
|
+
/**
|
|
18
|
+
* Set "sub" (Subject) Claim.
|
|
19
|
+
*
|
|
20
|
+
* @param subject "sub" (Subject) Claim value to set on the JWT Claims Set.
|
|
21
|
+
*/
|
|
6
22
|
setSubject(subject: string): this;
|
|
23
|
+
/**
|
|
24
|
+
* Set "aud" (Audience) Claim.
|
|
25
|
+
*
|
|
26
|
+
* @param audience "aud" (Audience) Claim value to set on the JWT Claims Set.
|
|
27
|
+
*/
|
|
7
28
|
setAudience(audience: string | string[]): this;
|
|
29
|
+
/**
|
|
30
|
+
* Set "jti" (JWT ID) Claim.
|
|
31
|
+
*
|
|
32
|
+
* @param jwtId "jti" (JWT ID) Claim value to set on the JWT Claims Set.
|
|
33
|
+
*/
|
|
8
34
|
setJti(jwtId: string): this;
|
|
35
|
+
/**
|
|
36
|
+
* Set "nbf" (Not Before) Claim.
|
|
37
|
+
*
|
|
38
|
+
* @param input "nbf" (Not Before) Claim value to set on the JWT Claims Set.
|
|
39
|
+
* When number is passed that is used as a value, when string is passed
|
|
40
|
+
* it is resolved to a time span and added to the current timestamp.
|
|
41
|
+
*/
|
|
9
42
|
setNotBefore(input: number | string): this;
|
|
43
|
+
/**
|
|
44
|
+
* Set "exp" (Expiration Time) Claim.
|
|
45
|
+
*
|
|
46
|
+
* @param input "exp" (Expiration Time) Claim value to set on the JWT Claims Set.
|
|
47
|
+
* When number is passed that is used as a value, when string is passed
|
|
48
|
+
* it is resolved to a time span and added to the current timestamp.
|
|
49
|
+
*/
|
|
10
50
|
setExpirationTime(input: number | string): this;
|
|
51
|
+
/**
|
|
52
|
+
* Set "iat" (Issued At) Claim.
|
|
53
|
+
*
|
|
54
|
+
* @param input "iat" (Issued At) Claim value to set on the JWT Claims Set.
|
|
55
|
+
* Default is current timestamp.
|
|
56
|
+
*/
|
|
11
57
|
setIssuedAt(input?: number): this;
|
|
12
58
|
}
|
package/dist/types/jwt/sign.d.ts
CHANGED
|
@@ -1,7 +1,35 @@
|
|
|
1
1
|
import type { JWTHeaderParameters, KeyLike, SignOptions } from '../types';
|
|
2
2
|
import { ProduceJWT } from './produce';
|
|
3
|
+
/**
|
|
4
|
+
* The SignJWT class is a utility for creating Compact JWS formatted JWT strings.
|
|
5
|
+
*
|
|
6
|
+
* @example Usage
|
|
7
|
+
* ```js
|
|
8
|
+
* const jwt = await new jose.SignJWT({ 'urn:example:claim': true })
|
|
9
|
+
* .setProtectedHeader({ alg: 'ES256' })
|
|
10
|
+
* .setIssuedAt()
|
|
11
|
+
* .setIssuer('urn:example:issuer')
|
|
12
|
+
* .setAudience('urn:example:audience')
|
|
13
|
+
* .setExpirationTime('2h')
|
|
14
|
+
* .sign(privateKey)
|
|
15
|
+
*
|
|
16
|
+
* console.log(jwt)
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
3
19
|
export declare class SignJWT extends ProduceJWT {
|
|
4
20
|
private _protectedHeader;
|
|
21
|
+
/**
|
|
22
|
+
* Sets the JWS Protected Header on the SignJWT object.
|
|
23
|
+
*
|
|
24
|
+
* @param protectedHeader JWS Protected Header.
|
|
25
|
+
* Must contain an "alg" (JWS Algorithm) property.
|
|
26
|
+
*/
|
|
5
27
|
setProtectedHeader(protectedHeader: JWTHeaderParameters): this;
|
|
28
|
+
/**
|
|
29
|
+
* Signs and returns the JWT.
|
|
30
|
+
*
|
|
31
|
+
* @param key Private Key or Secret to sign the JWT with.
|
|
32
|
+
* @param options JWT Sign options.
|
|
33
|
+
*/
|
|
6
34
|
sign(key: KeyLike | Uint8Array, options?: SignOptions): Promise<string>;
|
|
7
35
|
}
|