jose 4.5.3 → 4.6.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 (62) hide show
  1. package/dist/browser/jwe/general/encrypt.js +8 -1
  2. package/dist/browser/jwks/local.js +2 -1
  3. package/dist/browser/lib/buffer_utils.js +5 -11
  4. package/dist/browser/lib/crypto_key.js +1 -1
  5. package/dist/browser/lib/decrypt_key_management.js +1 -1
  6. package/dist/browser/lib/encrypt_key_management.js +1 -1
  7. package/dist/browser/lib/jwt_claims_set.js +2 -7
  8. package/dist/browser/runtime/base64url.js +6 -3
  9. package/dist/browser/runtime/ecdhes.js +2 -5
  10. package/dist/browser/runtime/pbes2kw.js +1 -1
  11. package/dist/node/cjs/jwe/general/encrypt.js +8 -1
  12. package/dist/node/cjs/jwks/local.js +2 -1
  13. package/dist/node/cjs/lib/buffer_utils.js +5 -11
  14. package/dist/node/cjs/lib/crypto_key.js +1 -1
  15. package/dist/node/cjs/lib/decrypt_key_management.js +1 -1
  16. package/dist/node/cjs/lib/encrypt_key_management.js +1 -1
  17. package/dist/node/cjs/lib/jwt_claims_set.js +2 -7
  18. package/dist/node/cjs/runtime/ecdhes.js +2 -2
  19. package/dist/node/cjs/runtime/generate.js +3 -2
  20. package/dist/node/cjs/runtime/pbes2kw.js +1 -1
  21. package/dist/node/esm/jwe/general/encrypt.js +8 -1
  22. package/dist/node/esm/jwks/local.js +2 -1
  23. package/dist/node/esm/lib/buffer_utils.js +5 -11
  24. package/dist/node/esm/lib/crypto_key.js +1 -1
  25. package/dist/node/esm/lib/decrypt_key_management.js +1 -1
  26. package/dist/node/esm/lib/encrypt_key_management.js +1 -1
  27. package/dist/node/esm/lib/jwt_claims_set.js +2 -7
  28. package/dist/node/esm/runtime/ecdhes.js +2 -2
  29. package/dist/node/esm/runtime/generate.js +3 -2
  30. package/dist/node/esm/runtime/pbes2kw.js +1 -1
  31. package/dist/types/jwe/compact/decrypt.d.ts +26 -0
  32. package/dist/types/jwe/compact/encrypt.d.ts +56 -0
  33. package/dist/types/jwe/flattened/decrypt.d.ts +39 -0
  34. package/dist/types/jwe/flattened/encrypt.d.ts +77 -0
  35. package/dist/types/jwe/general/decrypt.d.ts +43 -0
  36. package/dist/types/jwe/general/encrypt.d.ts +63 -0
  37. package/dist/types/jwk/embedded.d.ts +20 -0
  38. package/dist/types/jwk/thumbprint.d.ts +19 -0
  39. package/dist/types/jwks/local.d.ts +42 -0
  40. package/dist/types/jwks/remote.d.ts +44 -0
  41. package/dist/types/jws/compact/sign.d.ts +30 -0
  42. package/dist/types/jws/compact/verify.d.ts +29 -0
  43. package/dist/types/jws/flattened/sign.d.ts +35 -0
  44. package/dist/types/jws/flattened/verify.d.ts +34 -0
  45. package/dist/types/jws/general/sign.d.ts +50 -0
  46. package/dist/types/jws/general/verify.d.ts +37 -0
  47. package/dist/types/jwt/decrypt.d.ts +32 -0
  48. package/dist/types/jwt/encrypt.d.ts +68 -0
  49. package/dist/types/jwt/produce.d.ts +46 -0
  50. package/dist/types/jwt/sign.d.ts +28 -0
  51. package/dist/types/jwt/unsecured.d.ts +34 -0
  52. package/dist/types/jwt/verify.d.ts +35 -0
  53. package/dist/types/key/export.d.ts +38 -0
  54. package/dist/types/key/generate_key_pair.d.ts +38 -0
  55. package/dist/types/key/generate_secret.d.ts +20 -0
  56. package/dist/types/key/import.d.ts +96 -0
  57. package/dist/types/types.d.ts +499 -2
  58. package/dist/types/util/base64url.d.ts +10 -0
  59. package/dist/types/util/decode_jwt.d.ts +14 -0
  60. package/dist/types/util/decode_protected_header.d.ts +11 -0
  61. package/dist/types/util/errors.d.ts +65 -0
  62. package/package.json +1 -1
@@ -1,5 +1,26 @@
1
1
  import type { KeyLike, FlattenedJWE, JWEHeaderParameters, JWEKeyManagementHeaderParameters, EncryptOptions } from '../../types';
2
+ /**
3
+ * @private
4
+ */
2
5
  export declare const unprotected: unique symbol;
6
+ /**
7
+ * The FlattenedEncrypt class is a utility for creating Flattened JWE
8
+ * objects.
9
+ *
10
+ * @example Usage
11
+ * ```js
12
+ * const jwe = await new jose.FlattenedEncrypt(
13
+ * new TextEncoder().encode(
14
+ * 'It’s a dangerous business, Frodo, going out your door.'
15
+ * )
16
+ * )
17
+ * .setProtectedHeader({ alg: 'RSA-OAEP-256', enc: 'A256GCM' })
18
+ * .setAdditionalAuthenticatedData(encoder.encode('The Fellowship of the Ring'))
19
+ * .encrypt(publicKey)
20
+ *
21
+ * console.log(jwe)
22
+ * ```
23
+ */
3
24
  export declare class FlattenedEncrypt {
4
25
  private _plaintext;
5
26
  private _protectedHeader;
@@ -9,13 +30,69 @@ export declare class FlattenedEncrypt {
9
30
  private _cek;
10
31
  private _iv;
11
32
  private _keyManagementParameters;
33
+ /**
34
+ * @param plaintext Binary representation of the plaintext to encrypt.
35
+ */
12
36
  constructor(plaintext: Uint8Array);
37
+ /**
38
+ * Sets the JWE Key Management parameters to be used when encrypting.
39
+ * Use of this is method is really only needed for ECDH based algorithms
40
+ * when utilizing the Agreement PartyUInfo or Agreement PartyVInfo parameters.
41
+ * Other parameters will always be randomly generated when needed and missing.
42
+ *
43
+ * @param parameters JWE Key Management parameters.
44
+ */
13
45
  setKeyManagementParameters(parameters: JWEKeyManagementHeaderParameters): this;
46
+ /**
47
+ * Sets the JWE Protected Header on the FlattenedEncrypt object.
48
+ *
49
+ * @param protectedHeader JWE Protected Header.
50
+ */
14
51
  setProtectedHeader(protectedHeader: JWEHeaderParameters): this;
52
+ /**
53
+ * Sets the JWE Shared Unprotected Header on the FlattenedEncrypt object.
54
+ *
55
+ * @param sharedUnprotectedHeader JWE Shared Unprotected Header.
56
+ */
15
57
  setSharedUnprotectedHeader(sharedUnprotectedHeader: JWEHeaderParameters): this;
58
+ /**
59
+ * Sets the JWE Per-Recipient Unprotected Header on the FlattenedEncrypt object.
60
+ *
61
+ * @param unprotectedHeader JWE Per-Recipient Unprotected Header.
62
+ */
16
63
  setUnprotectedHeader(unprotectedHeader: JWEHeaderParameters): this;
64
+ /**
65
+ * Sets the Additional Authenticated Data on the FlattenedEncrypt object.
66
+ *
67
+ * @param aad Additional Authenticated Data.
68
+ */
17
69
  setAdditionalAuthenticatedData(aad: Uint8Array): this;
70
+ /**
71
+ * Sets a content encryption key to use, by default a random suitable one
72
+ * is generated for the JWE enc" (Encryption Algorithm) Header Parameter.
73
+ *
74
+ * @param cek JWE Content Encryption Key.
75
+ *
76
+ * @deprecated You should not use this method. It is only really intended
77
+ * for test and vector validation purposes.
78
+ */
18
79
  setContentEncryptionKey(cek: Uint8Array): this;
80
+ /**
81
+ * Sets the JWE Initialization Vector to use for content encryption, by default
82
+ * a random suitable one is generated for the JWE enc" (Encryption Algorithm)
83
+ * Header Parameter.
84
+ *
85
+ * @param iv JWE Initialization Vector.
86
+ *
87
+ * @deprecated You should not use this method. It is only really intended
88
+ * for test and vector validation purposes.
89
+ */
19
90
  setInitializationVector(iv: Uint8Array): this;
91
+ /**
92
+ * Encrypts and resolves the value of the Flattened JWE object.
93
+ *
94
+ * @param key Public Key or Secret to encrypt the JWE with.
95
+ * @param options JWE Encryption options.
96
+ */
20
97
  encrypt(key: KeyLike | Uint8Array, options?: EncryptOptions): Promise<FlattenedJWE>;
21
98
  }
@@ -1,5 +1,48 @@
1
1
  import type { KeyLike, DecryptOptions, JWEHeaderParameters, GetKeyFunction, FlattenedJWE, GeneralJWE, GeneralDecryptResult, ResolvedKey } from '../../types';
2
+ /**
3
+ * Interface for General JWE Decryption dynamic key resolution.
4
+ * No token components have been verified at the time of this function call.
5
+ */
2
6
  export interface GeneralDecryptGetKey extends GetKeyFunction<JWEHeaderParameters, FlattenedJWE> {
3
7
  }
8
+ /**
9
+ * Decrypts a General JWE.
10
+ *
11
+ * @param jwe General JWE.
12
+ * @param key Private Key or Secret to decrypt the JWE with.
13
+ * @param options JWE Decryption options.
14
+ *
15
+ * @example Usage
16
+ * ```js
17
+ * const jwe = {
18
+ * ciphertext: '9EzjFISUyoG-ifC2mSihfP0DPC80yeyrxhTzKt1C_VJBkxeBG0MI4Te61Pk45RAGubUvBpU9jm4',
19
+ * iv: '8Fy7A_IuoX5VXG9s',
20
+ * tag: 'W76IYV6arGRuDSaSyWrQNg',
21
+ * aad: 'VGhlIEZlbGxvd3NoaXAgb2YgdGhlIFJpbmc',
22
+ * protected: 'eyJhbGciOiJSU0EtT0FFUC0yNTYiLCJlbmMiOiJBMjU2R0NNIn0',
23
+ * recipients: [
24
+ * {
25
+ * encrypted_key: 'Z6eD4UK_yFb5ZoKvKkGAdqywEG_m0e4IYo0x8Vf30LAMJcsc-_zSgIeiF82teZyYi2YYduHKoqImk7MRnoPZOlEs0Q5BNK1OgBmSOhCE8DFyqh9Zh48TCTP6lmBQ52naqoUJFMtHzu-0LwZH26hxos0GP3Dt19O379MJB837TdKKa87skq0zHaVLAquRHOBF77GI54Bc7O49d8aOrSu1VEFGMThlW2caspPRiTSePDMDPq7_WGk50izRhB3Asl9wmP9wEeaTrkJKRnQj5ips1SAZ1hDBsqEQKKukxP1HtdcopHV5_qgwU8Hjm5EwSLMluMQuiE6hwlkXGOujZLVizA'
26
+ * }
27
+ * ]
28
+ * }
29
+ *
30
+ * const {
31
+ * plaintext,
32
+ * protectedHeader,
33
+ * additionalAuthenticatedData
34
+ * } = await jose.generalDecrypt(jwe, privateKey)
35
+ *
36
+ * console.log(protectedHeader)
37
+ * const decoder = new TextDecoder()
38
+ * console.log(decoder.decode(plaintext))
39
+ * console.log(decoder.decode(additionalAuthenticatedData))
40
+ * ```
41
+ */
4
42
  export declare function generalDecrypt(jwe: GeneralJWE, key: KeyLike | Uint8Array, options?: DecryptOptions): Promise<GeneralDecryptResult>;
43
+ /**
44
+ * @param jwe General JWE.
45
+ * @param getKey Function resolving Private Key or Secret to decrypt the JWE with.
46
+ * @param options JWE Decryption options.
47
+ */
5
48
  export declare function generalDecrypt(jwe: GeneralJWE, getKey: GeneralDecryptGetKey, options?: DecryptOptions): Promise<GeneralDecryptResult & ResolvedKey>;
@@ -1,20 +1,83 @@
1
1
  import type { KeyLike, GeneralJWE, JWEHeaderParameters, CritOption, DeflateOption } from '../../types';
2
2
  export interface Recipient {
3
+ /**
4
+ * Sets the JWE Per-Recipient Unprotected Header on the Recipient object.
5
+ *
6
+ * @param unprotectedHeader JWE Per-Recipient Unprotected Header.
7
+ */
3
8
  setUnprotectedHeader(unprotectedHeader: JWEHeaderParameters): Recipient;
9
+ /**
10
+ * A shorthand for calling addRecipient() on the enclosing GeneralEncrypt instance
11
+ */
4
12
  addRecipient(...args: Parameters<GeneralEncrypt['addRecipient']>): Recipient;
13
+ /**
14
+ * A shorthand for calling encrypt() on the enclosing GeneralEncrypt instance
15
+ */
5
16
  encrypt(...args: Parameters<GeneralEncrypt['encrypt']>): Promise<GeneralJWE>;
17
+ /**
18
+ * Returns the enclosing GeneralEncrypt
19
+ */
6
20
  done(): GeneralEncrypt;
7
21
  }
22
+ /**
23
+ * The GeneralEncrypt class is a utility for creating General JWE objects.
24
+ *
25
+ * @example Usage
26
+ * ```js
27
+ * const jwe = await new jose.GeneralEncrypt(
28
+ * new TextEncoder().encode(
29
+ * 'It’s a dangerous business, Frodo, going out your door.'
30
+ * )
31
+ * )
32
+ * .setProtectedHeader({ enc: 'A256GCM' })
33
+ * .addRecipient(ecPublicKey)
34
+ * .setUnprotectedHeader({ alg: 'ECDH-ES+A256KW' })
35
+ * .addRecipient(rsaPublicKey)
36
+ * .setUnprotectedHeader({ alg: 'RSA-OAEP-384' })
37
+ * .encrypt()
38
+ *
39
+ * console.log(jwe)
40
+ * ```
41
+ */
8
42
  export declare class GeneralEncrypt {
9
43
  private _plaintext;
10
44
  private _recipients;
11
45
  private _protectedHeader;
12
46
  private _unprotectedHeader;
13
47
  private _aad;
48
+ /**
49
+ * @param plaintext Binary representation of the plaintext to encrypt.
50
+ */
14
51
  constructor(plaintext: Uint8Array);
52
+ /**
53
+ * Adds an additional recipient for the General JWE object.
54
+ *
55
+ * @param key Public Key or Secret to encrypt the Content Encryption Key for the recipient with.
56
+ * @param options JWE Encryption options.
57
+ */
15
58
  addRecipient(key: KeyLike | Uint8Array, options?: CritOption): Recipient;
59
+ /**
60
+ * Sets the JWE Protected Header on the GeneralEncrypt object.
61
+ *
62
+ * @param protectedHeader JWE Protected Header object.
63
+ */
16
64
  setProtectedHeader(protectedHeader: JWEHeaderParameters): this;
65
+ /**
66
+ * Sets the JWE Shared Unprotected Header on the GeneralEncrypt object.
67
+ *
68
+ * @param sharedUnprotectedHeader JWE Shared Unprotected Header object.
69
+ */
17
70
  setSharedUnprotectedHeader(sharedUnprotectedHeader: JWEHeaderParameters): this;
71
+ /**
72
+ * Sets the Additional Authenticated Data on the GeneralEncrypt object.
73
+ *
74
+ * @param aad Additional Authenticated Data.
75
+ */
18
76
  setAdditionalAuthenticatedData(aad: Uint8Array): this;
77
+ /**
78
+ * Encrypts and resolves the value of the General JWE object.
79
+ *
80
+ * @param options JWE Encryption options.
81
+ */
19
82
  encrypt(options?: DeflateOption): Promise<GeneralJWE>;
20
83
  }
@@ -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>;