jose 5.7.0 → 5.9.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.
Files changed (76) hide show
  1. package/README.md +21 -17
  2. package/dist/browser/jwe/flattened/encrypt.js +1 -1
  3. package/dist/browser/jwe/general/encrypt.js +2 -1
  4. package/dist/browser/jwks/local.js +1 -1
  5. package/dist/browser/jwks/remote.js +1 -1
  6. package/dist/browser/jws/flattened/sign.js +2 -2
  7. package/dist/browser/jws/flattened/verify.js +10 -2
  8. package/dist/browser/lib/check_key_type.js +40 -9
  9. package/dist/browser/lib/invalid_key_input.js +1 -0
  10. package/dist/browser/lib/is_jwk.js +13 -0
  11. package/dist/browser/lib/private_symbols.js +1 -0
  12. package/dist/browser/runtime/get_sign_verify_key.js +1 -1
  13. package/dist/browser/runtime/normalize_key.js +21 -4
  14. package/dist/node/cjs/jwe/flattened/encrypt.js +3 -3
  15. package/dist/node/cjs/jwe/general/encrypt.js +2 -1
  16. package/dist/node/cjs/jwks/local.js +1 -2
  17. package/dist/node/cjs/jwks/remote.js +1 -1
  18. package/dist/node/cjs/jws/flattened/sign.js +1 -1
  19. package/dist/node/cjs/jws/flattened/verify.js +9 -1
  20. package/dist/node/cjs/lib/check_key_type.js +41 -9
  21. package/dist/node/cjs/lib/invalid_key_input.js +1 -0
  22. package/dist/node/cjs/lib/is_jwk.js +20 -0
  23. package/dist/node/cjs/lib/private_symbols.js +4 -0
  24. package/dist/node/cjs/runtime/base64url.js +1 -1
  25. package/dist/node/cjs/runtime/check_key_length.js +11 -1
  26. package/dist/node/cjs/runtime/get_named_curve.js +4 -0
  27. package/dist/node/cjs/runtime/get_sign_verify_key.js +8 -1
  28. package/dist/node/cjs/runtime/node_key.js +51 -14
  29. package/dist/node/cjs/runtime/sign.js +3 -3
  30. package/dist/node/cjs/runtime/verify.js +3 -3
  31. package/dist/node/esm/jwe/flattened/encrypt.js +1 -1
  32. package/dist/node/esm/jwe/general/encrypt.js +2 -1
  33. package/dist/node/esm/jwks/local.js +1 -1
  34. package/dist/node/esm/jwks/remote.js +1 -1
  35. package/dist/node/esm/jws/flattened/sign.js +2 -2
  36. package/dist/node/esm/jws/flattened/verify.js +10 -2
  37. package/dist/node/esm/lib/check_key_type.js +40 -9
  38. package/dist/node/esm/lib/invalid_key_input.js +1 -0
  39. package/dist/node/esm/lib/is_jwk.js +13 -0
  40. package/dist/node/esm/lib/private_symbols.js +1 -0
  41. package/dist/node/esm/runtime/base64url.js +1 -1
  42. package/dist/node/esm/runtime/check_key_length.js +11 -1
  43. package/dist/node/esm/runtime/get_named_curve.js +4 -0
  44. package/dist/node/esm/runtime/get_sign_verify_key.js +8 -1
  45. package/dist/node/esm/runtime/node_key.js +52 -15
  46. package/dist/node/esm/runtime/sign.js +3 -3
  47. package/dist/node/esm/runtime/verify.js +3 -3
  48. package/dist/types/jwe/compact/decrypt.d.ts +3 -0
  49. package/dist/types/jwe/compact/encrypt.d.ts +3 -0
  50. package/dist/types/jwe/flattened/decrypt.d.ts +3 -0
  51. package/dist/types/jwe/flattened/encrypt.d.ts +3 -2
  52. package/dist/types/jwe/general/decrypt.d.ts +3 -0
  53. package/dist/types/jwe/general/encrypt.d.ts +3 -0
  54. package/dist/types/jwk/embedded.d.ts +3 -0
  55. package/dist/types/jwk/thumbprint.d.ts +6 -0
  56. package/dist/types/jwks/local.d.ts +3 -7
  57. package/dist/types/jwks/remote.d.ts +3 -0
  58. package/dist/types/jws/compact/sign.d.ts +5 -2
  59. package/dist/types/jws/compact/verify.d.ts +6 -3
  60. package/dist/types/jws/flattened/sign.d.ts +5 -2
  61. package/dist/types/jws/flattened/verify.d.ts +6 -3
  62. package/dist/types/jws/general/sign.d.ts +5 -2
  63. package/dist/types/jws/general/verify.d.ts +6 -3
  64. package/dist/types/jwt/decrypt.d.ts +3 -0
  65. package/dist/types/jwt/encrypt.d.ts +3 -0
  66. package/dist/types/jwt/sign.d.ts +5 -2
  67. package/dist/types/jwt/unsecured.d.ts +3 -0
  68. package/dist/types/jwt/verify.d.ts +6 -3
  69. package/dist/types/key/export.d.ts +9 -0
  70. package/dist/types/key/generate_key_pair.d.ts +3 -0
  71. package/dist/types/key/generate_secret.d.ts +3 -0
  72. package/dist/types/key/import.d.ts +12 -0
  73. package/dist/types/types.d.ts +129 -29
  74. package/dist/types/util/decode_jwt.d.ts +3 -0
  75. package/dist/types/util/decode_protected_header.d.ts +3 -0
  76. package/package.json +271 -1
@@ -2,6 +2,9 @@ import type { JWK } from '../types';
2
2
  /**
3
3
  * Calculates a base64url-encoded JSON Web Key (JWK) Thumbprint
4
4
  *
5
+ * This function is exported (as a named export) from the main `'jose'` module entry point as well
6
+ * as from its subpath export `'jose/jwk/thumbprint'`.
7
+ *
5
8
  * @param jwk JSON Web Key.
6
9
  * @param digestAlgorithm Digest Algorithm to use for calculating the thumbprint. Default is
7
10
  * "sha256".
@@ -12,6 +15,9 @@ export declare function calculateJwkThumbprint(jwk: JWK, digestAlgorithm?: 'sha2
12
15
  /**
13
16
  * Calculates a JSON Web Key (JWK) Thumbprint URI
14
17
  *
18
+ * This function is exported (as a named export) from the main `'jose'` module entry point as well
19
+ * as from its subpath export `'jose/jwk/thumbprint'`.
20
+ *
15
21
  * @param jwk JSON Web Key.
16
22
  * @param digestAlgorithm Digest Algorithm to use for calculating the thumbprint. Default is
17
23
  * "sha256".
@@ -1,11 +1,4 @@
1
1
  import type { KeyLike, JWSHeaderParameters, JSONWebKeySet, FlattenedJWSInput } from '../types';
2
- /** @private */
3
- export declare class LocalJWKSet<KeyLikeType extends KeyLike = KeyLike> {
4
- private _jwks?;
5
- private _cached;
6
- constructor(jwks: unknown);
7
- getKey(protectedHeader?: JWSHeaderParameters, token?: FlattenedJWSInput): Promise<KeyLikeType>;
8
- }
9
2
  /**
10
3
  * Returns a function that resolves a JWS JOSE Header to a public key object from a locally stored,
11
4
  * or otherwise available, JSON Web Key Set.
@@ -22,6 +15,9 @@ export declare class LocalJWKSet<KeyLikeType extends KeyLike = KeyLike> {
22
15
  * Note: The function's purpose is to resolve public keys used for verifying signatures and will not
23
16
  * work for public encryption keys.
24
17
  *
18
+ * This function is exported (as a named export) from the main `'jose'` module entry point as well
19
+ * as from its subpath export `'jose/jwks/local'`.
20
+ *
25
21
  * @param jwks JSON Web Key Set formatted object.
26
22
  */
27
23
  export declare function createLocalJWKSet<KeyLikeType extends KeyLike = KeyLike>(jwks: JSONWebKeySet): (protectedHeader?: JWSHeaderParameters, token?: FlattenedJWSInput) => Promise<KeyLikeType>;
@@ -108,6 +108,9 @@ export type JWKSCacheInput = ExportedJWKSCache | Record<string, never>;
108
108
  * Note: The function's purpose is to resolve public keys used for verifying signatures and will not
109
109
  * work for public encryption keys.
110
110
  *
111
+ * This function is exported (as a named export) from the main `'jose'` module entry point as well
112
+ * as from its subpath export `'jose/jwks/remote'`.
113
+ *
111
114
  * @param url URL to fetch the JSON Web Key Set from.
112
115
  * @param options Options for the remote JSON Web Key Set.
113
116
  */
@@ -1,7 +1,10 @@
1
- import type { CompactJWSHeaderParameters, KeyLike, SignOptions } from '../../types';
1
+ import type { JWK, CompactJWSHeaderParameters, KeyLike, SignOptions } from '../../types';
2
2
  /**
3
3
  * The CompactSign class is used to build and sign Compact JWS strings.
4
4
  *
5
+ * This class is exported (as a named export) from the main `'jose'` module entry point as well as
6
+ * from its subpath export `'jose/jws/compact/sign'`.
7
+ *
5
8
  */
6
9
  export declare class CompactSign {
7
10
  private _flattened;
@@ -20,5 +23,5 @@ export declare class CompactSign {
20
23
  * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
21
24
  * @param options JWS Sign options.
22
25
  */
23
- sign(key: KeyLike | Uint8Array, options?: SignOptions): Promise<string>;
26
+ sign(key: KeyLike | Uint8Array | JWK, options?: SignOptions): Promise<string>;
24
27
  }
@@ -1,21 +1,24 @@
1
- import type { CompactVerifyResult, FlattenedJWSInput, GetKeyFunction, CompactJWSHeaderParameters, KeyLike, VerifyOptions, ResolvedKey } from '../../types';
1
+ import type { JWK, CompactVerifyResult, FlattenedJWSInput, GenericGetKeyFunction, CompactJWSHeaderParameters, KeyLike, VerifyOptions, ResolvedKey } from '../../types';
2
2
  /**
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
6
  * @see [createRemoteJWKSet](../functions/jwks_remote.createRemoteJWKSet.md#function-createremotejwkset) to verify using a remote JSON Web Key Set.
7
7
  */
8
- export interface CompactVerifyGetKey extends GetKeyFunction<CompactJWSHeaderParameters, FlattenedJWSInput> {
8
+ export interface CompactVerifyGetKey extends GenericGetKeyFunction<CompactJWSHeaderParameters, FlattenedJWSInput, KeyLike | JWK | Uint8Array> {
9
9
  }
10
10
  /**
11
11
  * Verifies the signature and format of and afterwards decodes the Compact JWS.
12
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/jws/compact/verify'`.
15
+ *
13
16
  * @param jws Compact JWS.
14
17
  * @param key Key to verify the JWS with. See
15
18
  * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
16
19
  * @param options JWS Verify options.
17
20
  */
18
- export declare function compactVerify(jws: string | Uint8Array, key: KeyLike | Uint8Array, options?: VerifyOptions): Promise<CompactVerifyResult>;
21
+ export declare function compactVerify(jws: string | Uint8Array, key: KeyLike | Uint8Array | JWK, options?: VerifyOptions): Promise<CompactVerifyResult>;
19
22
  /**
20
23
  * @param jws Compact JWS.
21
24
  * @param getKey Function resolving a key to verify the JWS with. See
@@ -1,7 +1,10 @@
1
- import type { KeyLike, FlattenedJWS, JWSHeaderParameters, SignOptions } from '../../types';
1
+ import type { JWK, KeyLike, FlattenedJWS, JWSHeaderParameters, SignOptions } from '../../types';
2
2
  /**
3
3
  * The FlattenedSign class is used to build and sign Flattened JWS objects.
4
4
  *
5
+ * This class is exported (as a named export) from the main `'jose'` module entry point as well as
6
+ * from its subpath export `'jose/jws/flattened/sign'`.
7
+ *
5
8
  */
6
9
  export declare class FlattenedSign {
7
10
  private _payload;
@@ -28,5 +31,5 @@ export declare class FlattenedSign {
28
31
  * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
29
32
  * @param options JWS Sign options.
30
33
  */
31
- sign(key: KeyLike | Uint8Array, options?: SignOptions): Promise<FlattenedJWS>;
34
+ sign(key: KeyLike | Uint8Array | JWK, options?: SignOptions): Promise<FlattenedJWS>;
32
35
  }
@@ -1,21 +1,24 @@
1
- import type { FlattenedVerifyResult, KeyLike, FlattenedJWSInput, JWSHeaderParameters, VerifyOptions, GetKeyFunction, ResolvedKey } from '../../types';
1
+ import type { JWK, FlattenedVerifyResult, KeyLike, FlattenedJWSInput, JWSHeaderParameters, VerifyOptions, GenericGetKeyFunction, ResolvedKey } from '../../types';
2
2
  /**
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
6
  * @see [createRemoteJWKSet](../functions/jwks_remote.createRemoteJWKSet.md#function-createremotejwkset) to verify using a remote JSON Web Key Set.
7
7
  */
8
- export interface FlattenedVerifyGetKey extends GetKeyFunction<JWSHeaderParameters | undefined, FlattenedJWSInput> {
8
+ export interface FlattenedVerifyGetKey extends GenericGetKeyFunction<JWSHeaderParameters | undefined, FlattenedJWSInput, KeyLike | JWK | Uint8Array> {
9
9
  }
10
10
  /**
11
11
  * Verifies the signature and format of and afterwards decodes the Flattened JWS.
12
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/jws/flattened/verify'`.
15
+ *
13
16
  * @param jws Flattened JWS.
14
17
  * @param key Key to verify the JWS with. See
15
18
  * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
16
19
  * @param options JWS Verify options.
17
20
  */
18
- export declare function flattenedVerify(jws: FlattenedJWSInput, key: KeyLike | Uint8Array, options?: VerifyOptions): Promise<FlattenedVerifyResult>;
21
+ export declare function flattenedVerify(jws: FlattenedJWSInput, key: KeyLike | Uint8Array | JWK, options?: VerifyOptions): Promise<FlattenedVerifyResult>;
19
22
  /**
20
23
  * @param jws Flattened JWS.
21
24
  * @param getKey Function resolving a key to verify the JWS with. See
@@ -1,4 +1,4 @@
1
- import type { KeyLike, GeneralJWS, JWSHeaderParameters, SignOptions } from '../../types';
1
+ import type { JWK, KeyLike, GeneralJWS, JWSHeaderParameters, SignOptions } from '../../types';
2
2
  export interface Signature {
3
3
  /**
4
4
  * Sets the JWS Protected Header on the Signature object.
@@ -22,6 +22,9 @@ export interface Signature {
22
22
  /**
23
23
  * The GeneralSign class is used to build and sign General JWS objects.
24
24
  *
25
+ * This class is exported (as a named export) from the main `'jose'` module entry point as well as
26
+ * from its subpath export `'jose/jws/general/sign'`.
27
+ *
25
28
  */
26
29
  export declare class GeneralSign {
27
30
  private _payload;
@@ -35,7 +38,7 @@ export declare class GeneralSign {
35
38
  * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
36
39
  * @param options JWS Sign options.
37
40
  */
38
- addSignature(key: KeyLike | Uint8Array, options?: SignOptions): Signature;
41
+ addSignature(key: KeyLike | Uint8Array | JWK, options?: SignOptions): Signature;
39
42
  /** Signs and resolves the value of the General JWS object. */
40
43
  sign(): Promise<GeneralJWS>;
41
44
  }
@@ -1,21 +1,24 @@
1
- import type { GeneralJWSInput, GeneralVerifyResult, FlattenedJWSInput, GetKeyFunction, JWSHeaderParameters, KeyLike, VerifyOptions, ResolvedKey } from '../../types';
1
+ import type { JWK, GeneralJWSInput, GeneralVerifyResult, FlattenedJWSInput, GenericGetKeyFunction, JWSHeaderParameters, KeyLike, VerifyOptions, ResolvedKey } from '../../types';
2
2
  /**
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
6
  * @see [createRemoteJWKSet](../functions/jwks_remote.createRemoteJWKSet.md#function-createremotejwkset) to verify using a remote JSON Web Key Set.
7
7
  */
8
- export interface GeneralVerifyGetKey extends GetKeyFunction<JWSHeaderParameters, FlattenedJWSInput> {
8
+ export interface GeneralVerifyGetKey extends GenericGetKeyFunction<JWSHeaderParameters, FlattenedJWSInput, KeyLike | JWK | Uint8Array> {
9
9
  }
10
10
  /**
11
11
  * Verifies the signature and format of and afterwards decodes the General JWS.
12
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/jws/general/verify'`.
15
+ *
13
16
  * @param jws General JWS.
14
17
  * @param key Key to verify the JWS with. See
15
18
  * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
16
19
  * @param options JWS Verify options.
17
20
  */
18
- export declare function generalVerify(jws: GeneralJWSInput, key: KeyLike | Uint8Array, options?: VerifyOptions): Promise<GeneralVerifyResult>;
21
+ export declare function generalVerify(jws: GeneralJWSInput, key: KeyLike | Uint8Array | JWK, options?: VerifyOptions): Promise<GeneralVerifyResult>;
19
22
  /**
20
23
  * @param jws General JWS.
21
24
  * @param getKey Function resolving a key to verify the JWS with. See
@@ -12,6 +12,9 @@ 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
+ * This function is exported (as a named export) from the main `'jose'` module entry point as well
16
+ * as from its subpath export `'jose/jwt/decrypt'`.
17
+ *
15
18
  * @param jwt JSON Web Token value (encoded as JWE).
16
19
  * @param key Private Key or Secret to decrypt and verify the JWT with. See
17
20
  * {@link https://github.com/panva/jose/issues/210#jwe-alg Algorithm Key Requirements}.
@@ -3,6 +3,9 @@ import { ProduceJWT } from './produce';
3
3
  /**
4
4
  * The EncryptJWT class is used to build and encrypt Compact JWE formatted JSON Web Tokens.
5
5
  *
6
+ * This class is exported (as a named export) from the main `'jose'` module entry point as well as
7
+ * from its subpath export `'jose/jwt/encrypt'`.
8
+ *
6
9
  */
7
10
  export declare class EncryptJWT extends ProduceJWT {
8
11
  private _cek;
@@ -1,8 +1,11 @@
1
- import type { JWTHeaderParameters, KeyLike, SignOptions } from '../types';
1
+ import type { JWK, JWTHeaderParameters, KeyLike, SignOptions } from '../types';
2
2
  import { ProduceJWT } from './produce';
3
3
  /**
4
4
  * The SignJWT class is used to build and sign Compact JWS formatted JSON Web Tokens.
5
5
  *
6
+ * This class is exported (as a named export) from the main `'jose'` module entry point as well as
7
+ * from its subpath export `'jose/jwt/sign'`.
8
+ *
6
9
  */
7
10
  export declare class SignJWT extends ProduceJWT {
8
11
  private _protectedHeader;
@@ -19,5 +22,5 @@ export declare class SignJWT extends ProduceJWT {
19
22
  * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
20
23
  * @param options JWT Sign options.
21
24
  */
22
- sign(key: KeyLike | Uint8Array, options?: SignOptions): Promise<string>;
25
+ sign(key: KeyLike | Uint8Array | JWK, options?: SignOptions): Promise<string>;
23
26
  }
@@ -7,6 +7,9 @@ export interface UnsecuredResult<PayloadType = JWTPayload> {
7
7
  /**
8
8
  * The UnsecuredJWT class is a utility for dealing with `{ "alg": "none" }` Unsecured JWTs.
9
9
  *
10
+ * This class is exported (as a named export) from the main `'jose'` module entry point as well as
11
+ * from its subpath export `'jose/jwt/unsecured'`.
12
+ *
10
13
  */
11
14
  export declare class UnsecuredJWT extends ProduceJWT {
12
15
  /** Encodes the Unsecured JWT. */
@@ -1,4 +1,4 @@
1
- import type { JWTPayload, KeyLike, VerifyOptions, JWTClaimVerificationOptions, JWTHeaderParameters, GetKeyFunction, FlattenedJWSInput, JWTVerifyResult, ResolvedKey } from '../types';
1
+ import type { JWK, JWTPayload, KeyLike, VerifyOptions, JWTClaimVerificationOptions, JWTHeaderParameters, GenericGetKeyFunction, FlattenedJWSInput, JWTVerifyResult, ResolvedKey } from '../types';
2
2
  /** Combination of JWS Verification options and JWT Claims Set verification options. */
3
3
  export interface JWTVerifyOptions extends VerifyOptions, JWTClaimVerificationOptions {
4
4
  }
@@ -8,18 +8,21 @@ export interface JWTVerifyOptions extends VerifyOptions, JWTClaimVerificationOpt
8
8
  *
9
9
  * @see [createRemoteJWKSet](../functions/jwks_remote.createRemoteJWKSet.md#function-createremotejwkset) to verify using a remote JSON Web Key Set.
10
10
  */
11
- export interface JWTVerifyGetKey extends GetKeyFunction<JWTHeaderParameters, FlattenedJWSInput> {
11
+ export interface JWTVerifyGetKey extends GenericGetKeyFunction<JWTHeaderParameters, FlattenedJWSInput, KeyLike | JWK | Uint8Array> {
12
12
  }
13
13
  /**
14
14
  * Verifies the JWT format (to be a JWS Compact format), verifies the JWS signature, validates the
15
15
  * JWT Claims Set.
16
16
  *
17
+ * This function is exported (as a named export) from the main `'jose'` module entry point as well
18
+ * as from its subpath export `'jose/jwt/verify'`.
19
+ *
17
20
  * @param jwt JSON Web Token value (encoded as JWS).
18
21
  * @param key Key to verify the JWT with. See
19
22
  * {@link https://github.com/panva/jose/issues/210#jws-alg Algorithm Key Requirements}.
20
23
  * @param options JWT Decryption and JWT Claims Set validation options.
21
24
  */
22
- export declare function jwtVerify<PayloadType = JWTPayload>(jwt: string | Uint8Array, key: KeyLike | Uint8Array, options?: JWTVerifyOptions): Promise<JWTVerifyResult<PayloadType>>;
25
+ export declare function jwtVerify<PayloadType = JWTPayload>(jwt: string | Uint8Array, key: KeyLike | Uint8Array | JWK, options?: JWTVerifyOptions): Promise<JWTVerifyResult<PayloadType>>;
23
26
  /**
24
27
  * @param jwt JSON Web Token value (encoded as JWS).
25
28
  * @param getKey Function resolving a key to verify the JWT with. See
@@ -3,6 +3,9 @@ import type { JWK, KeyLike } from '../types';
3
3
  * Exports a runtime-specific public key representation (KeyObject or CryptoKey) to a PEM-encoded
4
4
  * SPKI string format.
5
5
  *
6
+ * This function is exported (as a named export) from the main `'jose'` module entry point as well
7
+ * as from its subpath export `'jose/key/export'`.
8
+ *
6
9
  * @param key Key representation to transform to a PEM-encoded SPKI string format.
7
10
  */
8
11
  export declare function exportSPKI(key: KeyLike): Promise<string>;
@@ -10,12 +13,18 @@ export declare function exportSPKI(key: KeyLike): Promise<string>;
10
13
  * Exports a runtime-specific private key representation (KeyObject or CryptoKey) to a PEM-encoded
11
14
  * PKCS8 string format.
12
15
  *
16
+ * This function is exported (as a named export) from the main `'jose'` module entry point as well
17
+ * as from its subpath export `'jose/key/export'`.
18
+ *
13
19
  * @param key Key representation to transform to a PEM-encoded PKCS8 string format.
14
20
  */
15
21
  export declare function exportPKCS8(key: KeyLike): Promise<string>;
16
22
  /**
17
23
  * Exports a runtime-specific key representation (KeyLike) to a JWK.
18
24
  *
25
+ * This function is exported (as a named export) from the main `'jose'` module entry point as well
26
+ * as from its subpath export `'jose/key/export'`.
27
+ *
19
28
  * @param key Key representation to export as JWK.
20
29
  */
21
30
  export declare function exportJWK(key: KeyLike | Uint8Array): Promise<JWK>;
@@ -32,6 +32,9 @@ export interface GenerateKeyPairOptions {
32
32
  * `false` by default. See {@link GenerateKeyPairOptions.extractable} to generate an extractable
33
33
  * `privateKey`.
34
34
  *
35
+ * This function is exported (as a named export) from the main `'jose'` module entry point as well
36
+ * as from its subpath export `'jose/generate/keypair'`.
37
+ *
35
38
  * @param alg JWA Algorithm Identifier to be used with the generated key pair.
36
39
  * @param options Additional options passed down to the key pair generation.
37
40
  */
@@ -13,6 +13,9 @@ export interface GenerateSecretOptions {
13
13
  * Note: Under Web Crypto API runtime the secret key is generated with `extractable` set to `false`
14
14
  * by default.
15
15
  *
16
+ * This function is exported (as a named export) from the main `'jose'` module entry point as well
17
+ * as from its subpath export `'jose/generate/secret'`.
18
+ *
16
19
  * @param alg JWA Algorithm Identifier to be used with the generated secret.
17
20
  * @param options Additional options passed down to the secret generation.
18
21
  */
@@ -15,6 +15,9 @@ export interface PEMImportOptions {
15
15
  * {@link https://w3c.github.io/webcrypto/ Web Cryptography API}, use the OID rsaEncryption
16
16
  * (1.2.840.113549.1.1.1) instead for all RSA algorithms.
17
17
  *
18
+ * This function is exported (as a named export) from the main `'jose'` module entry point as well
19
+ * as from its subpath export `'jose/key/import'`.
20
+ *
18
21
  * @param spki PEM-encoded SPKI string
19
22
  * @param alg (Only effective in Web Crypto API runtimes) JSON Web Algorithm identifier to be used
20
23
  * with the imported key, its presence is only enforced in Web Crypto API runtimes. See
@@ -29,6 +32,9 @@ export declare function importSPKI<KeyLikeType extends KeyLike = KeyLike>(spki:
29
32
  * {@link https://w3c.github.io/webcrypto/ Web Cryptography API}, use the OID rsaEncryption
30
33
  * (1.2.840.113549.1.1.1) instead for all RSA algorithms.
31
34
  *
35
+ * This function is exported (as a named export) from the main `'jose'` module entry point as well
36
+ * as from its subpath export `'jose/key/import'`.
37
+ *
32
38
  * @param x509 X.509 certificate string
33
39
  * @param alg (Only effective in Web Crypto API runtimes) JSON Web Algorithm identifier to be used
34
40
  * with the imported key, its presence is only enforced in Web Crypto API runtimes. See
@@ -43,6 +49,9 @@ export declare function importX509<KeyLikeType extends KeyLike = KeyLike>(x509:
43
49
  * {@link https://w3c.github.io/webcrypto/ Web Cryptography API}, use the OID rsaEncryption
44
50
  * (1.2.840.113549.1.1.1) instead for all RSA algorithms.
45
51
  *
52
+ * This function is exported (as a named export) from the main `'jose'` module entry point as well
53
+ * as from its subpath export `'jose/key/import'`.
54
+ *
46
55
  * @param pkcs8 PEM-encoded PKCS#8 string
47
56
  * @param alg (Only effective in Web Crypto API runtimes) JSON Web Algorithm identifier to be used
48
57
  * with the imported key, its presence is only enforced in Web Crypto API runtimes. See
@@ -56,6 +65,9 @@ export declare function importPKCS8<KeyLikeType extends KeyLike = KeyLike>(pkcs8
56
65
  * Note: When the runtime is using {@link https://w3c.github.io/webcrypto/ Web Cryptography API} the
57
66
  * jwk parameters "use", "key_ops", and "ext" are also used in the resulting `CryptoKey`.
58
67
  *
68
+ * This function is exported (as a named export) from the main `'jose'` module entry point as well
69
+ * as from its subpath export `'jose/key/import'`.
70
+ *
59
71
  * @param jwk JSON Web Key.
60
72
  * @param alg (Only effective in Web Crypto API runtimes) JSON Web Algorithm identifier to be used
61
73
  * with the imported key. Default is the "alg" property on the JWK, its presence is only enforced
@@ -29,59 +29,153 @@
29
29
  */
30
30
  export type KeyLike = { type: string }
31
31
 
32
+ /** Generic JSON Web Key Parameters. */
33
+ export interface JWKParameters {
34
+ /** JWK "kty" (Key Type) Parameter. */
35
+ kty: string
36
+ /** JWK "alg" (Algorithm) Parameter. */
37
+ alg?: string
38
+ /** JWK "key_ops" (Key Operations) Parameter. */
39
+ key_ops?: string[]
40
+ /** JWK "ext" (Extractable) Parameter. */
41
+ ext?: boolean
42
+ /** JWK "use" (Public Key Use) Parameter. */
43
+ use?: string
44
+ /** JWK "x5c" (X.509 Certificate Chain) Parameter. */
45
+ x5c?: string[]
46
+ /** JWK "x5t" (X.509 Certificate SHA-1 Thumbprint) Parameter. */
47
+ x5t?: string
48
+ /** "x5t#S256" (X.509 Certificate SHA-256 Thumbprint) Parameter. */
49
+ 'x5t#S256'?: string
50
+ /** JWK "x5u" (X.509 URL) Parameter. */
51
+ x5u?: string
52
+ /** JWK "kid" (Key ID) Parameter. */
53
+ kid?: string
54
+ }
55
+
56
+ /** Convenience interface for Public OKP JSON Web Keys */
57
+ export interface JWK_OKP_Public extends JWKParameters {
58
+ /** The Subtype of Key Pair */
59
+ crv: string
60
+ /** The public key */
61
+ x: string
62
+ }
63
+
64
+ /** Convenience interface for Private OKP JSON Web Keys */
65
+ export interface JWK_OKP_Private extends JWK_OKP_Public, JWKParameters {
66
+ /** The Private Key */
67
+ d: string
68
+ }
69
+
70
+ /** Convenience interface for Public EC JSON Web Keys */
71
+ export interface JWK_EC_Public extends JWKParameters {
72
+ /** Curve */
73
+ crv: string
74
+ /** X Coordinate */
75
+ x: string
76
+ /** Y Coordinate */
77
+ y: string
78
+ }
79
+
80
+ /** Convenience interface for Private EC JSON Web Keys */
81
+ export interface JWK_EC_Private extends JWK_EC_Public, JWKParameters {
82
+ /** ECC Private Key */
83
+ d: string
84
+ }
85
+
86
+ /** Convenience interface for Public RSA JSON Web Keys */
87
+ export interface JWK_RSA_Public extends JWKParameters {
88
+ /** Exponent */
89
+ e: string
90
+ /** Modulus */
91
+ n: string
92
+ }
93
+
94
+ /** Convenience interface for Private RSA JSON Web Keys */
95
+ export interface JWK_RSA_Private extends JWK_RSA_Public, JWKParameters {
96
+ /** Private Exponent */
97
+ d: string
98
+ /** First Factor CRT Exponent */
99
+ dp: string
100
+ /** Second Factor CRT Exponent */
101
+ dq: string
102
+ /** Other Primes Info. This parameter is not supported. */
103
+ oth?: Array<{
104
+ d?: string
105
+ r?: string
106
+ t?: string
107
+ }>
108
+ /** First Prime Factor */
109
+ p: string
110
+ /** Second Prime Factor */
111
+ q: string
112
+ /** First CRT Coefficient */
113
+ qi: string
114
+ }
115
+
116
+ /**
117
+ * Convenience interface for oct JSON Web Keys
118
+ */
119
+ export interface JWK_oct extends JWKParameters {
120
+ /** Key Value */
121
+ k: string
122
+ }
123
+
32
124
  /**
33
125
  * JSON Web Key ({@link https://www.rfc-editor.org/rfc/rfc7517 JWK}). "RSA", "EC", "OKP", and "oct"
34
126
  * key types are supported.
35
127
  */
36
- export interface JWK {
37
- /** JWK "alg" (Algorithm) Parameter. */
38
- alg?: string
128
+ export interface JWK extends JWKParameters {
129
+ /**
130
+ * - (EC) Curve
131
+ * - (OKP) The Subtype of Key Pair
132
+ */
39
133
  crv?: string
134
+ /**
135
+ * - (Private RSA) Private Exponent
136
+ * - (Private EC) ECC Private Key
137
+ * - (Private OKP) The Private Key
138
+ */
40
139
  d?: string
140
+ /** (Private RSA) First Factor CRT Exponent */
41
141
  dp?: string
142
+ /** (Private RSA) Second Factor CRT Exponent */
42
143
  dq?: string
144
+ /** (RSA) Exponent */
43
145
  e?: string
44
- /** JWK "ext" (Extractable) Parameter. */
45
- ext?: boolean
146
+ /** (oct) Key Value */
46
147
  k?: string
47
- /** JWK "key_ops" (Key Operations) Parameter. */
48
- key_ops?: string[]
49
- /** JWK "kid" (Key ID) Parameter. */
50
- kid?: string
51
- /** JWK "kty" (Key Type) Parameter. */
52
- kty?: string
148
+ /** (RSA) Modulus */
53
149
  n?: string
150
+ /** (Private RSA) Other Primes Info. This parameter is not supported. */
54
151
  oth?: Array<{
55
152
  d?: string
56
153
  r?: string
57
154
  t?: string
58
155
  }>
156
+ /** (Private RSA) First Prime Factor */
59
157
  p?: string
158
+ /** (Private RSA) Second Prime Factor */
60
159
  q?: string
160
+ /** (Private RSA) First CRT Coefficient */
61
161
  qi?: string
62
- /** JWK "use" (Public Key Use) Parameter. */
63
- use?: string
162
+ /**
163
+ * - (EC) X Coordinate
164
+ * - (OKP) The public key
165
+ */
64
166
  x?: string
167
+ /** (EC) Y Coordinate */
65
168
  y?: string
66
- /** JWK "x5c" (X.509 Certificate Chain) Parameter. */
67
- x5c?: string[]
68
- /** JWK "x5t" (X.509 Certificate SHA-1 Thumbprint) Parameter. */
69
- x5t?: string
70
- /** "x5t#S256" (X.509 Certificate SHA-256 Thumbprint) Parameter. */
71
- 'x5t#S256'?: string
72
- /** JWK "x5u" (X.509 URL) Parameter. */
73
- x5u?: string
74
169
 
75
170
  [propName: string]: unknown
76
171
  }
77
172
 
78
173
  /**
79
- * Generic Interface for consuming operations dynamic key resolution.
174
+ * @private
80
175
  *
81
- * @param IProtectedHeader Type definition of the JWE or JWS Protected Header.
82
- * @param IToken Type definition of the consumed JWE or JWS token.
176
+ * @internal
83
177
  */
84
- export interface GetKeyFunction<IProtectedHeader, IToken> {
178
+ export interface GenericGetKeyFunction<IProtectedHeader, IToken, ReturnKeyTypes> {
85
179
  /**
86
180
  * Dynamic key resolution function. No token components have been verified at the time of this
87
181
  * function call.
@@ -91,12 +185,18 @@ export interface GetKeyFunction<IProtectedHeader, IToken> {
91
185
  * @param protectedHeader JWE or JWS Protected Header.
92
186
  * @param token The consumed JWE or JWS token.
93
187
  */
94
- (
95
- protectedHeader: IProtectedHeader,
96
- token: IToken,
97
- ): Promise<KeyLike | Uint8Array> | KeyLike | Uint8Array
188
+ (protectedHeader: IProtectedHeader, token: IToken): Promise<ReturnKeyTypes> | ReturnKeyTypes
98
189
  }
99
190
 
191
+ /**
192
+ * Generic Interface for consuming operations dynamic key resolution.
193
+ *
194
+ * @param IProtectedHeader Type definition of the JWE or JWS Protected Header.
195
+ * @param IToken Type definition of the consumed JWE or JWS token.
196
+ */
197
+ export interface GetKeyFunction<IProtectedHeader, IToken>
198
+ extends GenericGetKeyFunction<IProtectedHeader, IToken, KeyLike | Uint8Array> {}
199
+
100
200
  /**
101
201
  * Flattened JWS definition for verify function inputs, allows payload as Uint8Array for detached
102
202
  * signature validation.
@@ -5,6 +5,9 @@ import type { JWTPayload } from '../types';
5
5
  * and JWS signature verification use `jose.jwtVerify()`. For an encrypted JWT Claims Set validation
6
6
  * and JWE decryption use `jose.jwtDecrypt()`.
7
7
  *
8
+ * This function is exported (as a named export) from the main `'jose'` module entry point as well
9
+ * as from its subpath export `'jose/jwt/decode'`.
10
+ *
8
11
  * @param jwt JWT token in compact JWS serialization.
9
12
  */
10
13
  export declare function decodeJwt<PayloadType = JWTPayload>(jwt: string): PayloadType & JWTPayload;
@@ -3,6 +3,9 @@ export type ProtectedHeaderParameters = JWSHeaderParameters & JWEHeaderParameter
3
3
  /**
4
4
  * Decodes the Protected Header of a JWE/JWS/JWT token utilizing any JOSE serialization.
5
5
  *
6
+ * This function is exported (as a named export) from the main `'jose'` module entry point as well
7
+ * as from its subpath export `'jose/decode/protected_header'`.
8
+ *
6
9
  * @param token JWE/JWS/JWT token in any JOSE serialization.
7
10
  */
8
11
  export declare function decodeProtectedHeader(token: string | object): ProtectedHeaderParameters;