jose 4.13.1 → 4.13.2

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 (34) hide show
  1. package/README.md +94 -88
  2. package/dist/browser/jws/general/sign.js +1 -1
  3. package/dist/node/cjs/jws/general/sign.js +1 -1
  4. package/dist/node/esm/jws/general/sign.js +1 -1
  5. package/dist/types/jwe/compact/decrypt.d.ts +4 -14
  6. package/dist/types/jwe/compact/encrypt.d.ts +3 -13
  7. package/dist/types/jwe/flattened/decrypt.d.ts +4 -24
  8. package/dist/types/jwe/flattened/encrypt.d.ts +3 -14
  9. package/dist/types/jwe/general/decrypt.d.ts +4 -28
  10. package/dist/types/jwe/general/encrypt.d.ts +2 -16
  11. package/dist/types/jwk/embedded.d.ts +0 -14
  12. package/dist/types/jwk/thumbprint.d.ts +2 -30
  13. package/dist/types/jwks/local.d.ts +0 -59
  14. package/dist/types/jwks/remote.d.ts +5 -48
  15. package/dist/types/jws/compact/sign.d.ts +3 -13
  16. package/dist/types/jws/compact/verify.d.ts +5 -17
  17. package/dist/types/jws/flattened/sign.d.ts +3 -13
  18. package/dist/types/jws/flattened/verify.d.ts +5 -22
  19. package/dist/types/jws/general/sign.d.ts +3 -16
  20. package/dist/types/jws/general/verify.d.ts +5 -25
  21. package/dist/types/jwt/decrypt.d.ts +4 -18
  22. package/dist/types/jwt/encrypt.d.ts +12 -22
  23. package/dist/types/jwt/sign.d.ts +3 -93
  24. package/dist/types/jwt/unsecured.d.ts +0 -23
  25. package/dist/types/jwt/verify.d.ts +5 -84
  26. package/dist/types/key/export.d.ts +0 -26
  27. package/dist/types/key/generate_key_pair.d.ts +1 -9
  28. package/dist/types/key/generate_secret.d.ts +1 -8
  29. package/dist/types/key/import.d.ts +15 -80
  30. package/dist/types/types.d.ts +38 -94
  31. package/dist/types/util/decode_jwt.d.ts +0 -7
  32. package/dist/types/util/decode_protected_header.d.ts +0 -7
  33. package/dist/types/util/errors.d.ts +57 -14
  34. package/package.json +1 -1
@@ -17,11 +17,11 @@ export interface RemoteJWKSetOptions {
17
17
  */
18
18
  cacheMaxAge?: number | typeof Infinity;
19
19
  /**
20
- * An instance of [http.Agent](https://nodejs.org/api/http.html#class-httpagent) or
21
- * [https.Agent](https://nodejs.org/api/https.html#class-httpsagent) to pass to the
22
- * [http.get](https://nodejs.org/api/http.html#httpgetoptions-callback) or
23
- * [https.get](https://nodejs.org/api/https.html#httpsgetoptions-callback) method's options. Use
24
- * when behind an http(s) proxy. This is a Node.js runtime specific option, it is ignored when
20
+ * An instance of {@link https://nodejs.org/api/http.html#class-httpagent http.Agent} or
21
+ * {@link https://nodejs.org/api/https.html#class-httpsagent https.Agent} to pass to the
22
+ * {@link https://nodejs.org/api/http.html#httpgetoptions-callback http.get} or
23
+ * {@link https://nodejs.org/api/https.html#httpsgetoptions-callback https.get} method's options.
24
+ * Use when behind an http(s) proxy. This is a Node.js runtime specific option, it is ignored when
25
25
  * used outside of Node.js runtime.
26
26
  */
27
27
  agent?: any;
@@ -43,49 +43,6 @@ export interface RemoteJWKSetOptions {
43
43
  * multiple keys get matched it is possible to opt-in to iterate over the matched keys and attempt
44
44
  * verification in an iterative manner.
45
45
  *
46
- * @example Usage
47
- *
48
- * ```js
49
- * const JWKS = jose.createRemoteJWKSet(new URL('https://www.googleapis.com/oauth2/v3/certs'))
50
- *
51
- * const { payload, protectedHeader } = await jose.jwtVerify(jwt, JWKS, {
52
- * issuer: 'urn:example:issuer',
53
- * audience: 'urn:example:audience',
54
- * })
55
- * console.log(protectedHeader)
56
- * console.log(payload)
57
- * ```
58
- *
59
- * @example Opting-in to multiple JWKS matches using `createRemoteJWKSet`
60
- *
61
- * ```js
62
- * const options = {
63
- * issuer: 'urn:example:issuer',
64
- * audience: 'urn:example:audience',
65
- * }
66
- * const { payload, protectedHeader } = await jose
67
- * .jwtVerify(jwt, JWKS, options)
68
- * .catch(async (error) => {
69
- * if (error?.code === 'ERR_JWKS_MULTIPLE_MATCHING_KEYS') {
70
- * for await (const publicKey of error) {
71
- * try {
72
- * return await jose.jwtVerify(jwt, publicKey, options)
73
- * } catch (innerError) {
74
- * if (innerError?.code === 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED') {
75
- * continue
76
- * }
77
- * throw innerError
78
- * }
79
- * }
80
- * throw new jose.errors.JWSSignatureVerificationFailed()
81
- * }
82
- *
83
- * throw error
84
- * })
85
- * console.log(protectedHeader)
86
- * console.log(payload)
87
- * ```
88
- *
89
46
  * @param url URL to fetch the JSON Web Key Set from.
90
47
  * @param options Options for the remote JSON Web Key Set.
91
48
  */
@@ -1,18 +1,7 @@
1
1
  import type { CompactJWSHeaderParameters, KeyLike, SignOptions } from '../../types';
2
2
  /**
3
- * The CompactSign class is a utility for creating Compact JWS strings.
3
+ * The CompactSign class is used to build and sign Compact JWS strings.
4
4
  *
5
- * @example Usage
6
- *
7
- * ```js
8
- * const jws = await new jose.CompactSign(
9
- * new TextEncoder().encode('It’s a dangerous business, Frodo, going out your door.'),
10
- * )
11
- * .setProtectedHeader({ alg: 'ES256' })
12
- * .sign(privateKey)
13
- *
14
- * console.log(jws)
15
- * ```
16
5
  */
17
6
  export declare class CompactSign {
18
7
  private _flattened;
@@ -27,7 +16,8 @@ export declare class CompactSign {
27
16
  /**
28
17
  * Signs and resolves the value of the Compact JWS string.
29
18
  *
30
- * @param key Private Key or Secret to sign the JWS with.
19
+ * @param key Private Key or Secret to sign the JWS with. See
20
+ * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
31
21
  * @param options JWS Sign options.
32
22
  */
33
23
  sign(key: KeyLike | Uint8Array, options?: SignOptions): Promise<string>;
@@ -3,35 +3,23 @@ import type { CompactVerifyResult, FlattenedJWSInput, GetKeyFunction, CompactJWS
3
3
  * Interface for Compact JWS Verification dynamic key resolution. No token components have been
4
4
  * verified at the time of this function call.
5
5
  *
6
- * See
7
- * [createRemoteJWKSet](../functions/jwks_remote.createRemoteJWKSet.md#function-createremotejwkset)
8
- * to verify using a remote JSON Web Key Set.
6
+ * @see [createRemoteJWKSet](../functions/jwks_remote.createRemoteJWKSet.md#function-createremotejwkset) to verify using a remote JSON Web Key Set.
9
7
  */
10
8
  export interface CompactVerifyGetKey extends GetKeyFunction<CompactJWSHeaderParameters, FlattenedJWSInput> {
11
9
  }
12
10
  /**
13
11
  * Verifies the signature and format of and afterwards decodes the Compact JWS.
14
12
  *
15
- * @example Usage
16
- *
17
- * ```js
18
- * const jws =
19
- * 'eyJhbGciOiJFUzI1NiJ9.SXTigJlzIGEgZGFuZ2Vyb3VzIGJ1c2luZXNzLCBGcm9kbywgZ29pbmcgb3V0IHlvdXIgZG9vci4.kkAs_gPPxWMI3rHuVlxHaTPfDWDoqdI8jSvuSmqV-8IHIWXg9mcAeC9ggV-45ZHRbiRJ3obUIFo1rHphPA5URg'
20
- *
21
- * const { payload, protectedHeader } = await jose.compactVerify(jws, publicKey)
22
- *
23
- * console.log(protectedHeader)
24
- * console.log(new TextDecoder().decode(payload))
25
- * ```
26
- *
27
13
  * @param jws Compact JWS.
28
- * @param key Key to verify the JWS with.
14
+ * @param key Key to verify the JWS with. See
15
+ * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
29
16
  * @param options JWS Verify options.
30
17
  */
31
18
  export declare function compactVerify(jws: string | Uint8Array, key: KeyLike | Uint8Array, options?: VerifyOptions): Promise<CompactVerifyResult>;
32
19
  /**
33
20
  * @param jws Compact JWS.
34
- * @param getKey Function resolving a key to verify the JWS with.
21
+ * @param getKey Function resolving a key to verify the JWS with. See
22
+ * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
35
23
  * @param options JWS Verify options.
36
24
  */
37
25
  export declare function compactVerify<T extends KeyLike = KeyLike>(jws: string | Uint8Array, getKey: CompactVerifyGetKey, options?: VerifyOptions): Promise<CompactVerifyResult & ResolvedKey<T>>;
@@ -1,18 +1,7 @@
1
1
  import type { KeyLike, FlattenedJWS, JWSHeaderParameters, SignOptions } from '../../types';
2
2
  /**
3
- * The FlattenedSign class is a utility for creating Flattened JWS objects.
3
+ * The FlattenedSign class is used to build and sign Flattened JWS objects.
4
4
  *
5
- * @example Usage
6
- *
7
- * ```js
8
- * const jws = await new jose.FlattenedSign(
9
- * new TextEncoder().encode('It’s a dangerous business, Frodo, going out your door.'),
10
- * )
11
- * .setProtectedHeader({ alg: 'ES256' })
12
- * .sign(privateKey)
13
- *
14
- * console.log(jws)
15
- * ```
16
5
  */
17
6
  export declare class FlattenedSign {
18
7
  private _payload;
@@ -35,7 +24,8 @@ export declare class FlattenedSign {
35
24
  /**
36
25
  * Signs and resolves the value of the Flattened JWS object.
37
26
  *
38
- * @param key Private Key or Secret to sign the JWS with.
27
+ * @param key Private Key or Secret to sign the JWS with. See
28
+ * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
39
29
  * @param options JWS Sign options.
40
30
  */
41
31
  sign(key: KeyLike | Uint8Array, options?: SignOptions): Promise<FlattenedJWS>;
@@ -3,40 +3,23 @@ import type { FlattenedVerifyResult, KeyLike, FlattenedJWSInput, JWSHeaderParame
3
3
  * Interface for Flattened JWS Verification dynamic key resolution. No token components have been
4
4
  * verified at the time of this function call.
5
5
  *
6
- * See
7
- * [createRemoteJWKSet](../functions/jwks_remote.createRemoteJWKSet.md#function-createremotejwkset)
8
- * to verify using a remote JSON Web Key Set.
6
+ * @see [createRemoteJWKSet](../functions/jwks_remote.createRemoteJWKSet.md#function-createremotejwkset) to verify using a remote JSON Web Key Set.
9
7
  */
10
8
  export interface FlattenedVerifyGetKey extends GetKeyFunction<JWSHeaderParameters | undefined, FlattenedJWSInput> {
11
9
  }
12
10
  /**
13
11
  * Verifies the signature and format of and afterwards decodes the Flattened JWS.
14
12
  *
15
- * @example Usage
16
- *
17
- * ```js
18
- * const decoder = new TextDecoder()
19
- * const jws = {
20
- * signature:
21
- * 'FVVOXwj6kD3DqdfD9yYqfT2W9jv-Nop4kOehp_DeDGNB5dQNSPRvntBY6xH3uxlCxE8na9d_kyhYOcanpDJ0EA',
22
- * payload: 'SXTigJlzIGEgZGFuZ2Vyb3VzIGJ1c2luZXNzLCBGcm9kbywgZ29pbmcgb3V0IHlvdXIgZG9vci4',
23
- * protected: 'eyJhbGciOiJFUzI1NiJ9',
24
- * }
25
- *
26
- * const { payload, protectedHeader } = await jose.flattenedVerify(jws, publicKey)
27
- *
28
- * console.log(protectedHeader)
29
- * console.log(decoder.decode(payload))
30
- * ```
31
- *
32
13
  * @param jws Flattened JWS.
33
- * @param key Key to verify the JWS with.
14
+ * @param key Key to verify the JWS with. See
15
+ * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
34
16
  * @param options JWS Verify options.
35
17
  */
36
18
  export declare function flattenedVerify(jws: FlattenedJWSInput, key: KeyLike | Uint8Array, options?: VerifyOptions): Promise<FlattenedVerifyResult>;
37
19
  /**
38
20
  * @param jws Flattened JWS.
39
- * @param getKey Function resolving a key to verify the JWS with.
21
+ * @param getKey Function resolving a key to verify the JWS with. See
22
+ * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
40
23
  * @param options JWS Verify options.
41
24
  */
42
25
  export declare function flattenedVerify<T extends KeyLike = KeyLike>(jws: FlattenedJWSInput, getKey: FlattenedVerifyGetKey, options?: VerifyOptions): Promise<FlattenedVerifyResult & ResolvedKey<T>>;
@@ -20,22 +20,8 @@ export interface Signature {
20
20
  done(): GeneralSign;
21
21
  }
22
22
  /**
23
- * The GeneralSign class is a utility for creating General JWS objects.
23
+ * The GeneralSign class is used to build and sign General JWS objects.
24
24
  *
25
- * @example Usage
26
- *
27
- * ```js
28
- * const jws = await new jose.GeneralSign(
29
- * new TextEncoder().encode('It’s a dangerous business, Frodo, going out your door.'),
30
- * )
31
- * .addSignature(ecPrivateKey)
32
- * .setProtectedHeader({ alg: 'ES256' })
33
- * .addSignature(rsaPrivateKey)
34
- * .setProtectedHeader({ alg: 'PS256' })
35
- * .sign()
36
- *
37
- * console.log(jws)
38
- * ```
39
25
  */
40
26
  export declare class GeneralSign {
41
27
  private _payload;
@@ -45,7 +31,8 @@ export declare class GeneralSign {
45
31
  /**
46
32
  * Adds an additional signature for the General JWS object.
47
33
  *
48
- * @param key Private Key or Secret to sign the individual JWS signature with.
34
+ * @param key Private Key or Secret to sign the individual JWS signature with. See
35
+ * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
49
36
  * @param options JWS Sign options.
50
37
  */
51
38
  addSignature(key: KeyLike | Uint8Array, options?: SignOptions): Signature;
@@ -3,43 +3,23 @@ import type { GeneralJWSInput, GeneralVerifyResult, FlattenedJWSInput, GetKeyFun
3
3
  * Interface for General JWS Verification dynamic key resolution. No token components have been
4
4
  * verified at the time of this function call.
5
5
  *
6
- * See
7
- * [createRemoteJWKSet](../functions/jwks_remote.createRemoteJWKSet.md#function-createremotejwkset)
8
- * to verify using a remote JSON Web Key Set.
6
+ * @see [createRemoteJWKSet](../functions/jwks_remote.createRemoteJWKSet.md#function-createremotejwkset) to verify using a remote JSON Web Key Set.
9
7
  */
10
8
  export interface GeneralVerifyGetKey extends GetKeyFunction<JWSHeaderParameters, FlattenedJWSInput> {
11
9
  }
12
10
  /**
13
11
  * Verifies the signature and format of and afterwards decodes the General JWS.
14
12
  *
15
- * @example Usage
16
- *
17
- * ```js
18
- * const jws = {
19
- * payload: 'SXTigJlzIGEgZGFuZ2Vyb3VzIGJ1c2luZXNzLCBGcm9kbywgZ29pbmcgb3V0IHlvdXIgZG9vci4',
20
- * signatures: [
21
- * {
22
- * signature:
23
- * 'FVVOXwj6kD3DqdfD9yYqfT2W9jv-Nop4kOehp_DeDGNB5dQNSPRvntBY6xH3uxlCxE8na9d_kyhYOcanpDJ0EA',
24
- * protected: 'eyJhbGciOiJFUzI1NiJ9',
25
- * },
26
- * ],
27
- * }
28
- *
29
- * const { payload, protectedHeader } = await jose.generalVerify(jws, publicKey)
30
- *
31
- * console.log(protectedHeader)
32
- * console.log(new TextDecoder().decode(payload))
33
- * ```
34
- *
35
13
  * @param jws General JWS.
36
- * @param key Key to verify the JWS with.
14
+ * @param key Key to verify the JWS with. See
15
+ * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
37
16
  * @param options JWS Verify options.
38
17
  */
39
18
  export declare function generalVerify(jws: GeneralJWSInput, key: KeyLike | Uint8Array, options?: VerifyOptions): Promise<GeneralVerifyResult>;
40
19
  /**
41
20
  * @param jws General JWS.
42
- * @param getKey Function resolving a key to verify the JWS with.
21
+ * @param getKey Function resolving a key to verify the JWS with. See
22
+ * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
43
23
  * @param options JWS Verify options.
44
24
  */
45
25
  export declare function generalVerify<T extends KeyLike = KeyLike>(jws: GeneralJWSInput, getKey: GeneralVerifyGetKey, options?: VerifyOptions): Promise<GeneralVerifyResult & ResolvedKey<T>>;
@@ -12,30 +12,16 @@ export interface JWTDecryptGetKey extends GetKeyFunction<CompactJWEHeaderParamet
12
12
  * Verifies the JWT format (to be a JWE Compact format), decrypts the ciphertext, validates the JWT
13
13
  * Claims Set.
14
14
  *
15
- * @example Usage
16
- *
17
- * ```js
18
- * const secret = jose.base64url.decode('zH4NRP1HMALxxCFnRZABFA7GOJtzU_gIj02alfL1lvI')
19
- * const jwt =
20
- * 'eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0..MB66qstZBPxAXKdsjet_lA.WHbtJTl4taHp7otOHLq3hBvv0yNPsPEKHYInmCPdDDeyV1kU-f-tGEiU4FxlSqkqAT2hVs8_wMNiQFAzPU1PUgIqWCPsBrPP3TtxYsrtwagpn4SvCsUsx0Mhw9ZhliAO8CLmCBQkqr_T9AcYsz5uZw.7nX9m7BGUu_u1p1qFHzyIg'
21
- *
22
- * const { payload, protectedHeader } = await jose.jwtDecrypt(jwt, secret, {
23
- * issuer: 'urn:example:issuer',
24
- * audience: 'urn:example:audience',
25
- * })
26
- *
27
- * console.log(protectedHeader)
28
- * console.log(payload)
29
- * ```
30
- *
31
15
  * @param jwt JSON Web Token value (encoded as JWE).
32
- * @param key Private Key or Secret to decrypt and verify the JWT with.
16
+ * @param key Private Key or Secret to decrypt and verify the JWT with. See
17
+ * {@link https://github.com/panva/jose/issues/210#jwe-alg Algorithm Key Requirements}.
33
18
  * @param options JWT Decryption and JWT Claims Set validation options.
34
19
  */
35
20
  export declare function jwtDecrypt(jwt: string | Uint8Array, key: KeyLike | Uint8Array, options?: JWTDecryptOptions): Promise<JWTDecryptResult>;
36
21
  /**
37
22
  * @param jwt JSON Web Token value (encoded as JWE).
38
- * @param getKey Function resolving Private Key or Secret to decrypt and verify the JWT with.
23
+ * @param getKey Function resolving Private Key or Secret to decrypt and verify the JWT with. See
24
+ * {@link https://github.com/panva/jose/issues/210#jwe-alg Algorithm Key Requirements}.
39
25
  * @param options JWT Decryption and JWT Claims Set validation options.
40
26
  */
41
27
  export declare function jwtDecrypt<T extends KeyLike = KeyLike>(jwt: string | Uint8Array, getKey: JWTDecryptGetKey, options?: JWTDecryptOptions): Promise<JWTDecryptResult & ResolvedKey<T>>;
@@ -1,22 +1,8 @@
1
1
  import type { EncryptOptions, CompactJWEHeaderParameters, JWEKeyManagementHeaderParameters, KeyLike } from '../types';
2
2
  import { ProduceJWT } from './produce';
3
3
  /**
4
- * The EncryptJWT class is a utility for creating Compact JWE formatted JWT strings.
4
+ * The EncryptJWT class is used to build and encrypt Compact JWE formatted JSON Web Tokens.
5
5
  *
6
- * @example Usage
7
- *
8
- * ```js
9
- * const secret = jose.base64url.decode('zH4NRP1HMALxxCFnRZABFA7GOJtzU_gIj02alfL1lvI')
10
- * const jwt = await new jose.EncryptJWT({ 'urn:example:claim': true })
11
- * .setProtectedHeader({ alg: 'dir', enc: 'A128CBC-HS256' })
12
- * .setIssuedAt()
13
- * .setIssuer('urn:example:issuer')
14
- * .setAudience('urn:example:audience')
15
- * .setExpirationTime('2h')
16
- * .encrypt(secret)
17
- *
18
- * console.log(jwt)
19
- * ```
20
6
  */
21
7
  export declare class EncryptJWT extends ProduceJWT {
22
8
  private _cek;
@@ -61,24 +47,28 @@ export declare class EncryptJWT extends ProduceJWT {
61
47
  */
62
48
  setInitializationVector(iv: Uint8Array): this;
63
49
  /**
64
- * Replicates the "iss" (Issuer) Claim as a JWE Protected Header Parameter as per
65
- * [RFC7519#section-5.3](https://www.rfc-editor.org/rfc/rfc7519#section-5.3).
50
+ * Replicates the "iss" (Issuer) Claim as a JWE Protected Header Parameter.
51
+ *
52
+ * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-5.3 RFC7519#section-5.3}
66
53
  */
67
54
  replicateIssuerAsHeader(): this;
68
55
  /**
69
- * Replicates the "sub" (Subject) Claim as a JWE Protected Header Parameter as per
70
- * [RFC7519#section-5.3](https://www.rfc-editor.org/rfc/rfc7519#section-5.3).
56
+ * Replicates the "sub" (Subject) Claim as a JWE Protected Header Parameter.
57
+ *
58
+ * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-5.3 RFC7519#section-5.3}
71
59
  */
72
60
  replicateSubjectAsHeader(): this;
73
61
  /**
74
- * Replicates the "aud" (Audience) Claim as a JWE Protected Header Parameter as per
75
- * [RFC7519#section-5.3](https://www.rfc-editor.org/rfc/rfc7519#section-5.3).
62
+ * Replicates the "aud" (Audience) Claim as a JWE Protected Header Parameter.
63
+ *
64
+ * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-5.3 RFC7519#section-5.3}
76
65
  */
77
66
  replicateAudienceAsHeader(): this;
78
67
  /**
79
68
  * Encrypts and returns the JWT.
80
69
  *
81
- * @param key Public Key or Secret to encrypt the JWT with.
70
+ * @param key Public Key or Secret to encrypt the JWT with. See
71
+ * {@link https://github.com/panva/jose/issues/210#jwe-alg Algorithm Key Requirements}.
82
72
  * @param options JWE Encryption options.
83
73
  */
84
74
  encrypt(key: KeyLike | Uint8Array, options?: EncryptOptions): Promise<string>;
@@ -1,99 +1,8 @@
1
1
  import type { JWTHeaderParameters, KeyLike, SignOptions } from '../types';
2
2
  import { ProduceJWT } from './produce';
3
3
  /**
4
- * The SignJWT class is a utility for creating Compact JWS formatted JWT strings.
4
+ * The SignJWT class is used to build and sign Compact JWS formatted JSON Web Tokens.
5
5
  *
6
- * @example Usage with a symmetric secret
7
- *
8
- * ```js
9
- * const secret = new TextEncoder().encode(
10
- * 'cc7e0d44fd473002f1c42167459001140ec6389b7353f8088f4d9a95f2f596f2',
11
- * )
12
- * const alg = 'HS256'
13
- *
14
- * const jwt = await new jose.SignJWT({ 'urn:example:claim': true })
15
- * .setProtectedHeader({ alg })
16
- * .setIssuedAt()
17
- * .setIssuer('urn:example:issuer')
18
- * .setAudience('urn:example:audience')
19
- * .setExpirationTime('2h')
20
- * .sign(secret)
21
- *
22
- * console.log(jwt)
23
- * ```
24
- *
25
- * @example Usage with a private PKCS#8 encoded RSA key
26
- *
27
- * ```js
28
- * const alg = 'RS256'
29
- * const pkcs8 = `-----BEGIN PRIVATE KEY-----
30
- * MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDCFg4UrY5xtulv
31
- * /NXKmL1J4qI1SopAfTNMo3X7p+kJO7plqUYjzaztcre1qfh0m33Sm1Q8oPbO/GpP
32
- * MU1/HgcceytgJ/b4UwufVVMl9BrMDYG8moDBylbVupFQS3Ly1L9i/iFG9Z9A9xzY
33
- * Zzf799A45bnvNXL6s2glzvjiRvfQ2NDF0anTcnZLcYtC7ugq1IMM+ihAcPfw8Qw2
34
- * chN/SmP4qAM+PKaQwagmU7doqmmyN9u38AfoYZ1GCFhEs5TBBT6H6h9YdHeVtiIq
35
- * 1c+fl03biSIfLrV7dUBD39gBmXBcL/30Ya3D82mCEUC4zg/UkOfQOmkmV3Lc8YUL
36
- * QZ8EJkBLAgMBAAECggEAVuVE/KEP6323WjpbBdAIv7HGahGrgGANvbxZsIhm34ls
37
- * VOPK0XDegZkhAybMZHjRhp+gwVxX5ChC+J3cUpOBH5FNxElgW6HizD2Jcq6t6LoL
38
- * YgPSrfEHm71iHg8JsgrqfUnGYFzMJmv88C6WdCtpgG/qJV1K00/Ly1G1QKoBffEs
39
- * +v4fAMJrCbUdCz1qWto+PU+HLMEo+krfEpGgcmtZeRlDADh8cETMQlgQfQX2VWq/
40
- * aAP4a1SXmo+j0cvRU4W5Fj0RVwNesIpetX2ZFz4p/JmB5sWFEj/fC7h5z2lq+6Bm
41
- * e2T3BHtXkIxoBW0/pYVnASC8P2puO5FnVxDmWuHDYQKBgQDTuuBd3+0tSFVEX+DU
42
- * 5qpFmHm5nyGItZRJTS+71yg5pBxq1KqNCUjAtbxR0q//fwauakh+BwRVCPOrqsUG
43
- * jBSb3NYE70Srp6elqxgkE54PwQx4Mr6exJPnseM9U4K+hULllf5yjM9edreJE1nV
44
- * NVgFjeyafQhrHKwgr7PERJ/ikwKBgQDqqsT1M+EJLmI1HtCspOG6cu7q3gf/wKRh
45
- * E8tu84i3YyBnI8uJkKy92RNVI5fvpBARe3tjSdM25rr2rcrcmF/5g6Q9ImxZPGCt
46
- * 86eOgO9ErNtbc4TEgybsP319UE4O41aKeNiBTAZKoYCxv/dMqG0j4avmWzd+foHq
47
- * gSNUvR2maQKBgQCYeqOsV2B6VPY7KIVFLd0AA9/dwvEmgAYLiA/RShDI+hwQ/5jX
48
- * uxDu37KAhqeC65sHLrmIMUt4Zdr+DRyZK3aIDNEAesPMjw/X6lCXYp1ZISD2yyym
49
- * MFGH8X8CIkstI9Faf9vf6PJKSFrC1/HA7wq17VCwrUzLvrljTMW8meM/CwKBgCpo
50
- * 2leGHLFQFKeM/iF1WuYbR1pi7gcmhY6VyTowARFDdOOu8GXYI5/bz0afvCGvAMho
51
- * DJCREv7lC/zww6zCTPYG+HOj+PjXlJFba3ixjIxYwPvyEJiDK1Ge18sB7Fl8dHNq
52
- * C5ayaqCqN1voWYUdGzxU2IA1E/5kVo5O8FesJeOhAoGBAImJbZFf+D5kA32Xxhac
53
- * 59lLWBCsocvvbd1cvDMNlRywAAyhsCb1SuX4nEAK9mrSBdfmoF2Nm3eilfsOds0f
54
- * K5mX069IKG82CMqh3Mzptd7e7lyb9lsoGO0BAtjho3cWtha/UZ70vfaMzGuZ6JmQ
55
- * ak6k+8+UFd93M4z0Qo74OhXB
56
- * -----END PRIVATE KEY-----`
57
- * const privateKey = await jose.importPKCS8(pkcs8, alg)
58
- *
59
- * const jwt = await new jose.SignJWT({ 'urn:example:claim': true })
60
- * .setProtectedHeader({ alg })
61
- * .setIssuedAt()
62
- * .setIssuer('urn:example:issuer')
63
- * .setAudience('urn:example:audience')
64
- * .setExpirationTime('2h')
65
- * .sign(privateKey)
66
- *
67
- * console.log(jwt)
68
- * ```
69
- *
70
- * @example Usage with a private JWK encoded RSA key
71
- *
72
- * ```js
73
- * const alg = 'RS256'
74
- * const jwk = {
75
- * kty: 'RSA',
76
- * n: 'whYOFK2Ocbbpb_zVypi9SeKiNUqKQH0zTKN1-6fpCTu6ZalGI82s7XK3tan4dJt90ptUPKD2zvxqTzFNfx4HHHsrYCf2-FMLn1VTJfQazA2BvJqAwcpW1bqRUEty8tS_Yv4hRvWfQPcc2Gc3-_fQOOW57zVy-rNoJc744kb30NjQxdGp03J2S3GLQu7oKtSDDPooQHD38PEMNnITf0pj-KgDPjymkMGoJlO3aKppsjfbt_AH6GGdRghYRLOUwQU-h-ofWHR3lbYiKtXPn5dN24kiHy61e3VAQ9_YAZlwXC_99GGtw_NpghFAuM4P1JDn0DppJldy3PGFC0GfBCZASw',
77
- * e: 'AQAB',
78
- * d: 'VuVE_KEP6323WjpbBdAIv7HGahGrgGANvbxZsIhm34lsVOPK0XDegZkhAybMZHjRhp-gwVxX5ChC-J3cUpOBH5FNxElgW6HizD2Jcq6t6LoLYgPSrfEHm71iHg8JsgrqfUnGYFzMJmv88C6WdCtpgG_qJV1K00_Ly1G1QKoBffEs-v4fAMJrCbUdCz1qWto-PU-HLMEo-krfEpGgcmtZeRlDADh8cETMQlgQfQX2VWq_aAP4a1SXmo-j0cvRU4W5Fj0RVwNesIpetX2ZFz4p_JmB5sWFEj_fC7h5z2lq-6Bme2T3BHtXkIxoBW0_pYVnASC8P2puO5FnVxDmWuHDYQ',
79
- * p: '07rgXd_tLUhVRF_g1OaqRZh5uZ8hiLWUSU0vu9coOaQcatSqjQlIwLW8UdKv_38GrmpIfgcEVQjzq6rFBowUm9zWBO9Eq6enpasYJBOeD8EMeDK-nsST57HjPVOCvoVC5ZX-cozPXna3iRNZ1TVYBY3smn0IaxysIK-zxESf4pM',
80
- * q: '6qrE9TPhCS5iNR7QrKThunLu6t4H_8CkYRPLbvOIt2MgZyPLiZCsvdkTVSOX76QQEXt7Y0nTNua69q3K3Jhf-YOkPSJsWTxgrfOnjoDvRKzbW3OExIMm7D99fVBODuNWinjYgUwGSqGAsb_3TKhtI-Gr5ls3fn6B6oEjVL0dpmk',
81
- * dp: 'mHqjrFdgelT2OyiFRS3dAAPf3cLxJoAGC4gP0UoQyPocEP-Y17sQ7t-ygIanguubBy65iDFLeGXa_g0cmSt2iAzRAHrDzI8P1-pQl2KdWSEg9ssspjBRh_F_AiJLLSPRWn_b3-jySkhawtfxwO8Kte1QsK1My765Y0zFvJnjPws',
82
- * dq: 'KmjaV4YcsVAUp4z-IXVa5htHWmLuByaFjpXJOjABEUN0467wZdgjn9vPRp-8Ia8AyGgMkJES_uUL_PDDrMJM9gb4c6P4-NeUkVtreLGMjFjA-_IQmIMrUZ7XywHsWXx0c2oLlrJqoKo3W-hZhR0bPFTYgDUT_mRWjk7wV6wl46E',
83
- * qi: 'iYltkV_4PmQDfZfGFpzn2UtYEKyhy-9t3Vy8Mw2VHLAADKGwJvVK5ficQAr2atIF1-agXY2bd6KV-w52zR8rmZfTr0gobzYIyqHczOm13t7uXJv2WygY7QEC2OGjdxa2Fr9RnvS99ozMa5nomZBqTqT7z5QV33czjPRCjvg6FcE',
84
- * }
85
- * const privateKey = await jose.importJWK(jwk, alg)
86
- *
87
- * const jwt = await new jose.SignJWT({ 'urn:example:claim': true })
88
- * .setProtectedHeader({ alg })
89
- * .setIssuedAt()
90
- * .setIssuer('urn:example:issuer')
91
- * .setAudience('urn:example:audience')
92
- * .setExpirationTime('2h')
93
- * .sign(privateKey)
94
- *
95
- * console.log(jwt)
96
- * ```
97
6
  */
98
7
  export declare class SignJWT extends ProduceJWT {
99
8
  private _protectedHeader;
@@ -106,7 +15,8 @@ export declare class SignJWT extends ProduceJWT {
106
15
  /**
107
16
  * Signs and returns the JWT.
108
17
  *
109
- * @param key Private Key or Secret to sign the JWT with.
18
+ * @param key Private Key or Secret to sign the JWT with. See
19
+ * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
110
20
  * @param options JWT Sign options.
111
21
  */
112
22
  sign(key: KeyLike | Uint8Array, options?: SignOptions): Promise<string>;
@@ -7,29 +7,6 @@ export interface UnsecuredResult {
7
7
  /**
8
8
  * The UnsecuredJWT class is a utility for dealing with `{ "alg": "none" }` Unsecured JWTs.
9
9
  *
10
- * @example Encoding
11
- *
12
- * ```js
13
- * const unsecuredJwt = new jose.UnsecuredJWT({ 'urn:example:claim': true })
14
- * .setIssuedAt()
15
- * .setIssuer('urn:example:issuer')
16
- * .setAudience('urn:example:audience')
17
- * .setExpirationTime('2h')
18
- * .encode()
19
- *
20
- * console.log(unsecuredJwt)
21
- * ```
22
- *
23
- * @example Decoding
24
- *
25
- * ```js
26
- * const payload = jose.UnsecuredJWT.decode(jwt, {
27
- * issuer: 'urn:example:issuer',
28
- * audience: 'urn:example:audience',
29
- * })
30
- *
31
- * console.log(payload)
32
- * ```
33
10
  */
34
11
  export declare class UnsecuredJWT extends ProduceJWT {
35
12
  /** Encodes the Unsecured JWT. */
@@ -6,9 +6,7 @@ export interface JWTVerifyOptions extends VerifyOptions, JWTClaimVerificationOpt
6
6
  * Interface for JWT Verification dynamic key resolution. No token components have been verified at
7
7
  * the time of this function call.
8
8
  *
9
- * See
10
- * [createRemoteJWKSet](../functions/jwks_remote.createRemoteJWKSet.md#function-createremotejwkset)
11
- * to verify using a remote JSON Web Key Set.
9
+ * @see [createRemoteJWKSet](../functions/jwks_remote.createRemoteJWKSet.md#function-createremotejwkset) to verify using a remote JSON Web Key Set.
12
10
  */
13
11
  export interface JWTVerifyGetKey extends GetKeyFunction<JWTHeaderParameters, FlattenedJWSInput> {
14
12
  }
@@ -16,93 +14,16 @@ export interface JWTVerifyGetKey extends GetKeyFunction<JWTHeaderParameters, Fla
16
14
  * Verifies the JWT format (to be a JWS Compact format), verifies the JWS signature, validates the
17
15
  * JWT Claims Set.
18
16
  *
19
- * @example Usage with a symmetric secret
20
- *
21
- * ```js
22
- * const secret = new TextEncoder().encode(
23
- * 'cc7e0d44fd473002f1c42167459001140ec6389b7353f8088f4d9a95f2f596f2',
24
- * )
25
- * const jwt =
26
- * 'eyJhbGciOiJIUzI1NiJ9.eyJ1cm46ZXhhbXBsZTpjbGFpbSI6dHJ1ZSwiaWF0IjoxNjY5MDU2MjMxLCJpc3MiOiJ1cm46ZXhhbXBsZTppc3N1ZXIiLCJhdWQiOiJ1cm46ZXhhbXBsZTphdWRpZW5jZSJ9.C4iSlLfAUMBq--wnC6VqD9gEOhwpRZpoRarE0m7KEnI'
27
- *
28
- * const { payload, protectedHeader } = await jose.jwtVerify(jwt, secret, {
29
- * issuer: 'urn:example:issuer',
30
- * audience: 'urn:example:audience',
31
- * })
32
- *
33
- * console.log(protectedHeader)
34
- * console.log(payload)
35
- * ```
36
- *
37
- * @example Usage with a public SPKI encoded RSA key
38
- *
39
- * ```js
40
- * const alg = 'RS256'
41
- * const spki = `-----BEGIN PUBLIC KEY-----
42
- * MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwhYOFK2Ocbbpb/zVypi9
43
- * SeKiNUqKQH0zTKN1+6fpCTu6ZalGI82s7XK3tan4dJt90ptUPKD2zvxqTzFNfx4H
44
- * HHsrYCf2+FMLn1VTJfQazA2BvJqAwcpW1bqRUEty8tS/Yv4hRvWfQPcc2Gc3+/fQ
45
- * OOW57zVy+rNoJc744kb30NjQxdGp03J2S3GLQu7oKtSDDPooQHD38PEMNnITf0pj
46
- * +KgDPjymkMGoJlO3aKppsjfbt/AH6GGdRghYRLOUwQU+h+ofWHR3lbYiKtXPn5dN
47
- * 24kiHy61e3VAQ9/YAZlwXC/99GGtw/NpghFAuM4P1JDn0DppJldy3PGFC0GfBCZA
48
- * SwIDAQAB
49
- * -----END PUBLIC KEY-----`
50
- * const publicKey = await jose.importSPKI(spki, alg)
51
- * const jwt =
52
- * 'eyJhbGciOiJSUzI1NiJ9.eyJ1cm46ZXhhbXBsZTpjbGFpbSI6dHJ1ZSwiaWF0IjoxNjY5MDU2NDg4LCJpc3MiOiJ1cm46ZXhhbXBsZTppc3N1ZXIiLCJhdWQiOiJ1cm46ZXhhbXBsZTphdWRpZW5jZSJ9.gXrPZ3yM_60dMXGE69dusbpzYASNA-XIOwsb5D5xYnSxyj6_D6OR_uR_1vqhUm4AxZxcrH1_-XJAve9HCw8az_QzHcN-nETt-v6stCsYrn6Bv1YOc-mSJRZ8ll57KVqLbCIbjKwerNX5r2_Qg2TwmJzQdRs-AQDhy-s_DlJd8ql6wR4n-kDZpar-pwIvz4fFIN0Fj57SXpAbLrV6Eo4Byzl0xFD8qEYEpBwjrMMfxCZXTlAVhAq6KCoGlDTwWuExps342-0UErEtyIqDnDGcrfNWiUsoo8j-29IpKd-w9-C388u-ChCxoHz--H8WmMSZzx3zTXsZ5lXLZ9IKfanDKg'
53
- *
54
- * const { payload, protectedHeader } = await jose.jwtVerify(jwt, publicKey, {
55
- * issuer: 'urn:example:issuer',
56
- * audience: 'urn:example:audience',
57
- * })
58
- *
59
- * console.log(protectedHeader)
60
- * console.log(payload)
61
- * ```
62
- *
63
- * @example Usage with a public JWK encoded RSA key
64
- *
65
- * ```js
66
- * const alg = 'RS256'
67
- * const jwk = {
68
- * kty: 'RSA',
69
- * n: 'whYOFK2Ocbbpb_zVypi9SeKiNUqKQH0zTKN1-6fpCTu6ZalGI82s7XK3tan4dJt90ptUPKD2zvxqTzFNfx4HHHsrYCf2-FMLn1VTJfQazA2BvJqAwcpW1bqRUEty8tS_Yv4hRvWfQPcc2Gc3-_fQOOW57zVy-rNoJc744kb30NjQxdGp03J2S3GLQu7oKtSDDPooQHD38PEMNnITf0pj-KgDPjymkMGoJlO3aKppsjfbt_AH6GGdRghYRLOUwQU-h-ofWHR3lbYiKtXPn5dN24kiHy61e3VAQ9_YAZlwXC_99GGtw_NpghFAuM4P1JDn0DppJldy3PGFC0GfBCZASw',
70
- * e: 'AQAB',
71
- * }
72
- * const publicKey = await jose.importJWK(jwk, alg)
73
- * const jwt =
74
- * 'eyJhbGciOiJSUzI1NiJ9.eyJ1cm46ZXhhbXBsZTpjbGFpbSI6dHJ1ZSwiaWF0IjoxNjY5MDU2NDg4LCJpc3MiOiJ1cm46ZXhhbXBsZTppc3N1ZXIiLCJhdWQiOiJ1cm46ZXhhbXBsZTphdWRpZW5jZSJ9.gXrPZ3yM_60dMXGE69dusbpzYASNA-XIOwsb5D5xYnSxyj6_D6OR_uR_1vqhUm4AxZxcrH1_-XJAve9HCw8az_QzHcN-nETt-v6stCsYrn6Bv1YOc-mSJRZ8ll57KVqLbCIbjKwerNX5r2_Qg2TwmJzQdRs-AQDhy-s_DlJd8ql6wR4n-kDZpar-pwIvz4fFIN0Fj57SXpAbLrV6Eo4Byzl0xFD8qEYEpBwjrMMfxCZXTlAVhAq6KCoGlDTwWuExps342-0UErEtyIqDnDGcrfNWiUsoo8j-29IpKd-w9-C388u-ChCxoHz--H8WmMSZzx3zTXsZ5lXLZ9IKfanDKg'
75
- *
76
- * const { payload, protectedHeader } = await jose.jwtVerify(jwt, publicKey, {
77
- * issuer: 'urn:example:issuer',
78
- * audience: 'urn:example:audience',
79
- * })
80
- *
81
- * console.log(protectedHeader)
82
- * console.log(payload)
83
- * ```
84
- *
85
17
  * @param jwt JSON Web Token value (encoded as JWS).
86
- * @param key Key to verify the JWT with.
18
+ * @param key Key to verify the JWT with. See
19
+ * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
87
20
  * @param options JWT Decryption and JWT Claims Set validation options.
88
21
  */
89
22
  export declare function jwtVerify(jwt: string | Uint8Array, key: KeyLike | Uint8Array, options?: JWTVerifyOptions): Promise<JWTVerifyResult>;
90
23
  /**
91
- * @example Usage with a public JSON Web Key Set hosted on a remote URL
92
- *
93
- * ```js
94
- * const JWKS = jose.createRemoteJWKSet(new URL('https://www.googleapis.com/oauth2/v3/certs'))
95
- *
96
- * const { payload, protectedHeader } = await jose.jwtVerify(jwt, JWKS, {
97
- * issuer: 'urn:example:issuer',
98
- * audience: 'urn:example:audience',
99
- * })
100
- * console.log(protectedHeader)
101
- * console.log(payload)
102
- * ```
103
- *
104
24
  * @param jwt JSON Web Token value (encoded as JWS).
105
- * @param getKey Function resolving a key to verify the JWT with.
25
+ * @param getKey Function resolving a key to verify the JWT with. See
26
+ * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
106
27
  * @param options JWT Decryption and JWT Claims Set validation options.
107
28
  */
108
29
  export declare function jwtVerify<T extends KeyLike = KeyLike>(jwt: string | Uint8Array, getKey: JWTVerifyGetKey, options?: JWTVerifyOptions): Promise<JWTVerifyResult & ResolvedKey<T>>;