jose 4.13.0 → 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 (37) hide show
  1. package/README.md +94 -88
  2. package/dist/browser/jwks/remote.js +14 -26
  3. package/dist/browser/jws/general/sign.js +1 -1
  4. package/dist/node/cjs/jwks/remote.js +14 -26
  5. package/dist/node/cjs/jws/general/sign.js +1 -1
  6. package/dist/node/esm/jwks/remote.js +14 -26
  7. package/dist/node/esm/jws/general/sign.js +1 -1
  8. package/dist/types/jwe/compact/decrypt.d.ts +4 -14
  9. package/dist/types/jwe/compact/encrypt.d.ts +3 -13
  10. package/dist/types/jwe/flattened/decrypt.d.ts +4 -24
  11. package/dist/types/jwe/flattened/encrypt.d.ts +3 -14
  12. package/dist/types/jwe/general/decrypt.d.ts +4 -28
  13. package/dist/types/jwe/general/encrypt.d.ts +2 -16
  14. package/dist/types/jwk/embedded.d.ts +0 -14
  15. package/dist/types/jwk/thumbprint.d.ts +2 -30
  16. package/dist/types/jwks/local.d.ts +0 -59
  17. package/dist/types/jwks/remote.d.ts +5 -48
  18. package/dist/types/jws/compact/sign.d.ts +3 -13
  19. package/dist/types/jws/compact/verify.d.ts +5 -17
  20. package/dist/types/jws/flattened/sign.d.ts +3 -13
  21. package/dist/types/jws/flattened/verify.d.ts +5 -22
  22. package/dist/types/jws/general/sign.d.ts +3 -16
  23. package/dist/types/jws/general/verify.d.ts +5 -25
  24. package/dist/types/jwt/decrypt.d.ts +4 -18
  25. package/dist/types/jwt/encrypt.d.ts +12 -22
  26. package/dist/types/jwt/sign.d.ts +3 -93
  27. package/dist/types/jwt/unsecured.d.ts +0 -23
  28. package/dist/types/jwt/verify.d.ts +5 -84
  29. package/dist/types/key/export.d.ts +0 -26
  30. package/dist/types/key/generate_key_pair.d.ts +1 -9
  31. package/dist/types/key/generate_secret.d.ts +1 -8
  32. package/dist/types/key/import.d.ts +15 -80
  33. package/dist/types/types.d.ts +38 -94
  34. package/dist/types/util/decode_jwt.d.ts +0 -7
  35. package/dist/types/util/decode_protected_header.d.ts +0 -7
  36. package/dist/types/util/errors.d.ts +57 -14
  37. package/package.json +1 -1
@@ -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>>;
@@ -3,14 +3,6 @@ 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
- * @example Usage
7
- *
8
- * ```js
9
- * const spkiPem = await jose.exportSPKI(publicKey)
10
- *
11
- * console.log(spkiPem)
12
- * ```
13
- *
14
6
  * @param key Key representation to transform to a PEM-encoded SPKI string format.
15
7
  */
16
8
  export declare function exportSPKI(key: KeyLike): Promise<string>;
@@ -18,30 +10,12 @@ export declare function exportSPKI(key: KeyLike): Promise<string>;
18
10
  * Exports a runtime-specific private key representation (KeyObject or CryptoKey) to a PEM-encoded
19
11
  * PKCS8 string format.
20
12
  *
21
- * @example Usage
22
- *
23
- * ```js
24
- * const pkcs8Pem = await jose.exportPKCS8(privateKey)
25
- *
26
- * console.log(pkcs8Pem)
27
- * ```
28
- *
29
13
  * @param key Key representation to transform to a PEM-encoded PKCS8 string format.
30
14
  */
31
15
  export declare function exportPKCS8(key: KeyLike): Promise<string>;
32
16
  /**
33
17
  * Exports a runtime-specific key representation (KeyLike) to a JWK.
34
18
  *
35
- * @example Usage
36
- *
37
- * ```js
38
- * const privateJwk = await jose.exportJWK(privateKey)
39
- * const publicJwk = await jose.exportJWK(publicKey)
40
- *
41
- * console.log(privateJwk)
42
- * console.log(publicJwk)
43
- * ```
44
- *
45
19
  * @param key Key representation to export as JWK.
46
20
  */
47
21
  export declare function exportJWK(key: KeyLike | Uint8Array): Promise<JWK>;
@@ -18,7 +18,7 @@ export interface GenerateKeyPairOptions {
18
18
  modulusLength?: number;
19
19
  /**
20
20
  * (Only effective in Web Crypto API runtimes) The value to use as
21
- * [SubtleCrypto.generateKey()](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey)
21
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey SubtleCrypto.generateKey()}
22
22
  * `extractable` argument. Default is false.
23
23
  */
24
24
  extractable?: boolean;
@@ -30,14 +30,6 @@ export interface GenerateKeyPairOptions {
30
30
  * Note: Under Web Crypto API runtime the `privateKey` is generated with `extractable` set to
31
31
  * `false` by default.
32
32
  *
33
- * @example Usage
34
- *
35
- * ```js
36
- * const { publicKey, privateKey } = await jose.generateKeyPair('PS256')
37
- * console.log(publicKey)
38
- * console.log(privateKey)
39
- * ```
40
- *
41
33
  * @param alg JWA Algorithm Identifier to be used with the generated key pair.
42
34
  * @param options Additional options passed down to the key pair generation.
43
35
  */
@@ -2,7 +2,7 @@ import type { KeyLike } from '../types';
2
2
  export interface GenerateSecretOptions {
3
3
  /**
4
4
  * (Only effective in Web Crypto API runtimes) The value to use as
5
- * [SubtleCrypto.generateKey()](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey)
5
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey SubtleCrypto.generateKey()}
6
6
  * `extractable` argument. Default is false.
7
7
  */
8
8
  extractable?: boolean;
@@ -13,13 +13,6 @@ 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
- * @example Usage
17
- *
18
- * ```js
19
- * const secret = await jose.generateSecret('HS256')
20
- * console.log(secret)
21
- * ```
22
- *
23
16
  * @param alg JWA Algorithm Identifier to be used with the generated secret.
24
17
  * @param options Additional options passed down to the secret generation.
25
18
  */
@@ -2,117 +2,52 @@ import type { JWK, KeyLike } from '../types';
2
2
  export interface PEMImportOptions {
3
3
  /**
4
4
  * (Only effective in Web Crypto API runtimes) The value to use as
5
- * [SubtleCrypto.importKey()](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey)
5
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey SubtleCrypto.importKey()}
6
6
  * `extractable` argument. Default is false.
7
7
  */
8
8
  extractable?: boolean;
9
9
  }
10
10
  /**
11
11
  * Imports a PEM-encoded SPKI string as a runtime-specific public key representation (KeyObject or
12
- * CryptoKey). See [Algorithm Key Requirements](https://github.com/panva/jose/issues/210) to learn
13
- * about key to algorithm requirements and mapping.
14
- *
15
- * @example Usage
16
- *
17
- * ```js
18
- * const algorithm = 'ES256'
19
- * const spki = `-----BEGIN PUBLIC KEY-----
20
- * MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEFlHHWfLk0gLBbsLTcuCrbCqoHqmM
21
- * YJepMC+Q+Dd6RBmBiA41evUsNMwLeN+PNFqib+xwi9JkJ8qhZkq8Y/IzGg==
22
- * -----END PUBLIC KEY-----`
23
- * const ecPublicKey = await jose.importSPKI(spki, algorithm)
24
- * ```
12
+ * CryptoKey).
25
13
  *
26
14
  * @param pem PEM-encoded SPKI string
27
15
  * @param alg (Only effective in Web Crypto API runtimes) JSON Web Algorithm identifier to be used
28
- * with the imported key, its presence is only enforced in Web Crypto API runtimes.
16
+ * with the imported key, its presence is only enforced in Web Crypto API runtimes. See
17
+ * {@link https://github.com/panva/jose/issues/210 Algorithm Key Requirements}.
29
18
  */
30
19
  export declare function importSPKI<T extends KeyLike = KeyLike>(spki: string, alg: string, options?: PEMImportOptions): Promise<T>;
31
20
  /**
32
21
  * Imports the SPKI from an X.509 string certificate as a runtime-specific public key representation
33
- * (KeyObject or CryptoKey). See [Algorithm Key
34
- * Requirements](https://github.com/panva/jose/issues/210) to learn about key to algorithm
35
- * requirements and mapping.
36
- *
37
- * @example Usage
38
- *
39
- * ```js
40
- * const algorithm = 'ES256'
41
- * const x509 = `-----BEGIN CERTIFICATE-----
42
- * MIIBXjCCAQSgAwIBAgIGAXvykuMKMAoGCCqGSM49BAMCMDYxNDAyBgNVBAMMK3Np
43
- * QXBNOXpBdk1VaXhXVWVGaGtjZXg1NjJRRzFyQUhXaV96UlFQTVpQaG8wHhcNMjEw
44
- * OTE3MDcwNTE3WhcNMjIwNzE0MDcwNTE3WjA2MTQwMgYDVQQDDCtzaUFwTTl6QXZN
45
- * VWl4V1VlRmhrY2V4NTYyUUcxckFIV2lfelJRUE1aUGhvMFkwEwYHKoZIzj0CAQYI
46
- * KoZIzj0DAQcDQgAE8PbPvCv5D5xBFHEZlBp/q5OEUymq7RIgWIi7tkl9aGSpYE35
47
- * UH+kBKDnphJO3odpPZ5gvgKs2nwRWcrDnUjYLDAKBggqhkjOPQQDAgNIADBFAiEA
48
- * 1yyMTRe66MhEXID9+uVub7woMkNYd0LhSHwKSPMUUTkCIFQGsfm1ecXOpeGOufAh
49
- * v+A1QWZMuTWqYt+uh/YSRNDn
50
- * -----END CERTIFICATE-----`
51
- * const ecPublicKey = await jose.importX509(x509, algorithm)
52
- * ```
22
+ * (KeyObject or CryptoKey).
53
23
  *
54
24
  * @param pem X.509 certificate string
55
25
  * @param alg (Only effective in Web Crypto API runtimes) JSON Web Algorithm identifier to be used
56
- * with the imported key, its presence is only enforced in Web Crypto API runtimes.
26
+ * with the imported key, its presence is only enforced in Web Crypto API runtimes. See
27
+ * {@link https://github.com/panva/jose/issues/210 Algorithm Key Requirements}.
57
28
  */
58
29
  export declare function importX509<T extends KeyLike = KeyLike>(x509: string, alg: string, options?: PEMImportOptions): Promise<T>;
59
30
  /**
60
31
  * Imports a PEM-encoded PKCS#8 string as a runtime-specific private key representation (KeyObject
61
- * or CryptoKey). See [Algorithm Key Requirements](https://github.com/panva/jose/issues/210) to
62
- * learn about key to algorithm requirements and mapping. Encrypted keys are not supported.
63
- *
64
- * @example Usage
65
- *
66
- * ```js
67
- * const algorithm = 'ES256'
68
- * const pkcs8 = `-----BEGIN PRIVATE KEY-----
69
- * MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgiyvo0X+VQ0yIrOaN
70
- * nlrnUclopnvuuMfoc8HHly3505OhRANCAAQWUcdZ8uTSAsFuwtNy4KtsKqgeqYxg
71
- * l6kwL5D4N3pEGYGIDjV69Sw0zAt43480WqJv7HCL0mQnyqFmSrxj8jMa
72
- * -----END PRIVATE KEY-----`
73
- * const ecPrivateKey = await jose.importPKCS8(pkcs8, algorithm)
74
- * ```
32
+ * or CryptoKey).
75
33
  *
76
34
  * @param pem PEM-encoded PKCS#8 string
77
35
  * @param alg (Only effective in Web Crypto API runtimes) JSON Web Algorithm identifier to be used
78
- * with the imported key, its presence is only enforced in Web Crypto API runtimes.
36
+ * with the imported key, its presence is only enforced in Web Crypto API runtimes. See
37
+ * {@link https://github.com/panva/jose/issues/210 Algorithm Key Requirements}.
79
38
  */
80
39
  export declare function importPKCS8<T extends KeyLike = KeyLike>(pkcs8: string, alg: string, options?: PEMImportOptions): Promise<T>;
81
40
  /**
82
41
  * Imports a JWK to a runtime-specific key representation (KeyLike). Either JWK "alg" (Algorithm)
83
- * Parameter must be present or the optional "alg" argument. When running on a runtime using [Web
84
- * Cryptography API](https://www.w3.org/TR/WebCryptoAPI/) the jwk parameters "use", "key_ops", and
85
- * "ext" are also used in the resulting `CryptoKey`. See [Algorithm Key
86
- * Requirements](https://github.com/panva/jose/issues/210) to learn about key to algorithm
87
- * requirements and mapping.
88
- *
89
- * @example Usage
90
- *
91
- * ```js
92
- * const ecPublicKey = await jose.importJWK(
93
- * {
94
- * crv: 'P-256',
95
- * kty: 'EC',
96
- * x: 'ySK38C1jBdLwDsNWKzzBHqKYEE5Cgv-qjWvorUXk9fw',
97
- * y: '_LeQBw07cf5t57Iavn4j-BqJsAD1dpoz8gokd3sBsOo',
98
- * },
99
- * 'ES256',
100
- * )
101
- *
102
- * const rsaPublicKey = await jose.importJWK(
103
- * {
104
- * kty: 'RSA',
105
- * e: 'AQAB',
106
- * n: '12oBZRhCiZFJLcPg59LkZZ9mdhSMTKAQZYq32k_ti5SBB6jerkh-WzOMAO664r_qyLkqHUSp3u5SbXtseZEpN3XPWGKSxjsy-1JyEFTdLSYe6f9gfrmxkUF_7DTpq0gn6rntP05g2-wFW50YO7mosfdslfrTJYWHFhJALabAeYirYD7-9kqq9ebfFMF4sRRELbv9oi36As6Q9B3Qb5_C1rAzqfao_PCsf9EPsTZsVVVkA5qoIAr47lo1ipfiBPxUCCNSdvkmDTYgvvRm6ZoMjFbvOtgyts55fXKdMWv7I9HMD5HwE9uW839PWA514qhbcIsXEYSFMPMV6fnlsiZvQQ',
107
- * },
108
- * 'PS256',
109
- * )
110
- * ```
42
+ * Parameter must be present or the optional "alg" argument. When running on a runtime using
43
+ * {@link https://www.w3.org/TR/WebCryptoAPI/ Web Cryptography API} the jwk parameters "use",
44
+ * "key_ops", and "ext" are also used in the resulting `CryptoKey`.
111
45
  *
112
46
  * @param jwk JSON Web Key.
113
47
  * @param alg (Only effective in Web Crypto API runtimes) JSON Web Algorithm identifier to be used
114
48
  * with the imported key. Default is the "alg" property on the JWK, its presence is only enforced
115
- * in Web Crypto API runtimes.
49
+ * in Web Crypto API runtimes. See
50
+ * {@link https://github.com/panva/jose/issues/210 Algorithm Key Requirements}.
116
51
  * @param octAsKeyObject Forces a symmetric key to be imported to a KeyObject or CryptoKey. Default
117
52
  * is true unless JWK "ext" (Extractable) is true.
118
53
  */
@@ -1,98 +1,37 @@
1
1
  /**
2
2
  * KeyLike are runtime-specific classes representing asymmetric keys or symmetric secrets. These are
3
- * instances of [CryptoKey](https://developer.mozilla.org/en-US/docs/Web/API/CryptoKey) and
4
- * additionally [KeyObject](https://nodejs.org/api/crypto.html#class-keyobject) in Node.js runtime.
5
- * [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array)
3
+ * instances of {@link https://developer.mozilla.org/en-US/docs/Web/API/CryptoKey CryptoKey} and
4
+ * additionally {@link https://nodejs.org/api/crypto.html#class-keyobject KeyObject} in Node.js
5
+ * runtime.
6
+ * {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array Uint8Array}
6
7
  * instances are also accepted as symmetric secret representation only.
7
8
  *
8
- * [Key Import Functions](../modules/key_import.md#readme) can be used to import PEM, or JWK
9
- * formatted asymmetric keys and certificates to these runtime-specific representations.
9
+ * [Key Import Functions](../modules/key_import.md) can be used to import PEM, or JWK formatted
10
+ * asymmetric keys and certificates to these runtime-specific representations.
10
11
  *
11
- * In Node.js the [Buffer](https://nodejs.org/api/buffer.html#buffer) class is a subclass of
12
+ * In Node.js the {@link https://nodejs.org/api/buffer.html#buffer Buffer} class is a subclass of
12
13
  * Uint8Array and so Buffer can be provided for symmetric secrets as well.
13
14
  *
14
- * [KeyObject](https://nodejs.org/api/crypto.html#class-keyobject) is a representation of a
15
+ * {@link https://nodejs.org/api/crypto.html#class-keyobject KeyObject} is a representation of a
15
16
  * key/secret available in the Node.js runtime. In addition to the import functions of this library
16
17
  * you may use the runtime APIs
17
- * [crypto.createPublicKey](https://nodejs.org/api/crypto.html#cryptocreatepublickeykey),
18
- * [crypto.createPrivateKey](https://nodejs.org/api/crypto.html#cryptocreateprivatekeykey), and
19
- * [crypto.createSecretKey](https://nodejs.org/api/crypto.html#cryptocreatesecretkeykey-encoding) to
20
- * obtain a KeyObject from your existing key material.
18
+ * {@link https://nodejs.org/api/crypto.html#cryptocreatepublickeykey crypto.createPublicKey},
19
+ * {@link https://nodejs.org/api/crypto.html#cryptocreateprivatekeykey crypto.createPrivateKey}, and
20
+ * {@link https://nodejs.org/api/crypto.html#cryptocreatesecretkeykey-encoding crypto.createSecretKey}
21
+ * to obtain a `KeyObject` from your existing key material.
21
22
  *
22
- * [CryptoKey](https://developer.mozilla.org/en-US/docs/Web/API/CryptoKey) is a representation of a
23
- * key/secret available in the Browser and Web-interoperable runtimes. In addition to the import
24
- * functions of this library you may use the
25
- * [SubtleCrypto.importKey](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey)
23
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/CryptoKey CryptoKey} is a representation
24
+ * of a key/secret available in the Browser and Web-interoperable runtimes. In addition to the
25
+ * import functions of this library you may use the
26
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey SubtleCrypto.importKey}
26
27
  * API to obtain a CryptoKey from your existing key material.
27
28
  *
28
- * @example Import a PEM-encoded SPKI Public Key
29
- *
30
- * ```js
31
- * const algorithm = 'ES256'
32
- * const spki = `-----BEGIN PUBLIC KEY-----
33
- * MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEFlHHWfLk0gLBbsLTcuCrbCqoHqmM
34
- * YJepMC+Q+Dd6RBmBiA41evUsNMwLeN+PNFqib+xwi9JkJ8qhZkq8Y/IzGg==
35
- * -----END PUBLIC KEY-----`
36
- * const ecPublicKey = await jose.importSPKI(spki, algorithm)
37
- * ```
38
- *
39
- * @example Import SPKI from an X.509 Certificate
40
- *
41
- * ```js
42
- * const algorithm = 'ES256'
43
- * const x509 = `-----BEGIN CERTIFICATE-----
44
- * MIIBXjCCAQSgAwIBAgIGAXvykuMKMAoGCCqGSM49BAMCMDYxNDAyBgNVBAMMK3Np
45
- * QXBNOXpBdk1VaXhXVWVGaGtjZXg1NjJRRzFyQUhXaV96UlFQTVpQaG8wHhcNMjEw
46
- * OTE3MDcwNTE3WhcNMjIwNzE0MDcwNTE3WjA2MTQwMgYDVQQDDCtzaUFwTTl6QXZN
47
- * VWl4V1VlRmhrY2V4NTYyUUcxckFIV2lfelJRUE1aUGhvMFkwEwYHKoZIzj0CAQYI
48
- * KoZIzj0DAQcDQgAE8PbPvCv5D5xBFHEZlBp/q5OEUymq7RIgWIi7tkl9aGSpYE35
49
- * UH+kBKDnphJO3odpPZ5gvgKs2nwRWcrDnUjYLDAKBggqhkjOPQQDAgNIADBFAiEA
50
- * 1yyMTRe66MhEXID9+uVub7woMkNYd0LhSHwKSPMUUTkCIFQGsfm1ecXOpeGOufAh
51
- * v+A1QWZMuTWqYt+uh/YSRNDn
52
- * -----END CERTIFICATE-----`
53
- * const ecPublicKey = await jose.importX509(x509, algorithm)
54
- * ```
55
- *
56
- * @example Import a PEM-encoded PKCS8 Private Key
57
- *
58
- * ```js
59
- * const algorithm = 'ES256'
60
- * const pkcs8 = `-----BEGIN PRIVATE KEY-----
61
- * MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgiyvo0X+VQ0yIrOaN
62
- * nlrnUclopnvuuMfoc8HHly3505OhRANCAAQWUcdZ8uTSAsFuwtNy4KtsKqgeqYxg
63
- * l6kwL5D4N3pEGYGIDjV69Sw0zAt43480WqJv7HCL0mQnyqFmSrxj8jMa
64
- * -----END PRIVATE KEY-----`
65
- * const ecPrivateKey = await jose.importPKCS8(pkcs8, algorithm)
66
- * ```
67
- *
68
- * @example Import a JSON Web Key (JWK)
69
- *
70
- * ```js
71
- * const ecPublicKey = await jose.importJWK(
72
- * {
73
- * crv: 'P-256',
74
- * kty: 'EC',
75
- * x: 'ySK38C1jBdLwDsNWKzzBHqKYEE5Cgv-qjWvorUXk9fw',
76
- * y: '_LeQBw07cf5t57Iavn4j-BqJsAD1dpoz8gokd3sBsOo',
77
- * },
78
- * 'ES256',
79
- * )
80
- *
81
- * const rsaPublicKey = await jose.importJWK(
82
- * {
83
- * kty: 'RSA',
84
- * e: 'AQAB',
85
- * n: '12oBZRhCiZFJLcPg59LkZZ9mdhSMTKAQZYq32k_ti5SBB6jerkh-WzOMAO664r_qyLkqHUSp3u5SbXtseZEpN3XPWGKSxjsy-1JyEFTdLSYe6f9gfrmxkUF_7DTpq0gn6rntP05g2-wFW50YO7mosfdslfrTJYWHFhJALabAeYirYD7-9kqq9ebfFMF4sRRELbv9oi36As6Q9B3Qb5_C1rAzqfao_PCsf9EPsTZsVVVkA5qoIAr47lo1ipfiBPxUCCNSdvkmDTYgvvRm6ZoMjFbvOtgyts55fXKdMWv7I9HMD5HwE9uW839PWA514qhbcIsXEYSFMPMV6fnlsiZvQQ',
86
- * },
87
- * 'PS256',
88
- * )
89
- * ```
90
29
  */
91
30
  export type KeyLike = { type: string }
92
31
 
93
32
  /**
94
- * JSON Web Key ([JWK](https://www.rfc-editor.org/rfc/rfc7517)). "RSA", "EC", "OKP", and "oct" key
95
- * types are supported.
33
+ * JSON Web Key ({@link https://www.rfc-editor.org/rfc/rfc7517 JWK}). "RSA", "EC", "OKP", and "oct"
34
+ * key types are supported.
96
35
  */
97
36
  export interface JWK {
98
37
  /** JWK "alg" (Algorithm) Parameter. */
@@ -185,8 +124,9 @@ export interface FlattenedJWSInput {
185
124
  */
186
125
  export interface GeneralJWSInput {
187
126
  /**
188
- * The "payload" member MUST be present and contain the value BASE64URL(JWS Payload). When RFC7797
189
- * "b64": false is used the value passed may also be a Uint8Array.
127
+ * The "payload" member MUST be present and contain the value BASE64URL(JWS Payload). When when
128
+ * JWS Unencoded Payload ({@link https://www.rfc-editor.org/rfc/rfc7797 RFC7797}) "b64": false is
129
+ * used the value passed may also be a Uint8Array.
190
130
  */
191
131
  payload: string | Uint8Array
192
132
 
@@ -199,7 +139,7 @@ export interface GeneralJWSInput {
199
139
 
200
140
  /**
201
141
  * Flattened JWS definition. Payload is returned as an empty string when JWS Unencoded Payload
202
- * Option [RFC7797](https://www.rfc-editor.org/rfc/rfc7797) is used.
142
+ * ({@link https://www.rfc-editor.org/rfc/rfc7797 RFC7797}) is used.
203
143
  */
204
144
  export interface FlattenedJWS extends Partial<FlattenedJWSInput> {
205
145
  payload: string
@@ -207,8 +147,8 @@ export interface FlattenedJWS extends Partial<FlattenedJWSInput> {
207
147
  }
208
148
 
209
149
  /**
210
- * General JWS definition. Payload is returned as an empty string when JWS Unencoded Payload Option
211
- * [RFC7797](https://www.rfc-editor.org/rfc/rfc7797) is used.
150
+ * General JWS definition. Payload is returned as an empty string when JWS Unencoded Payload
151
+ * ({@link https://www.rfc-editor.org/rfc/rfc7797 RFC7797}) is used.
212
152
  */
213
153
  export interface GeneralJWS {
214
154
  payload: string
@@ -248,7 +188,7 @@ export interface JWSHeaderParameters extends JoseHeaderParameters {
248
188
 
249
189
  /**
250
190
  * This JWS Extension Header Parameter modifies the JWS Payload representation and the JWS Signing
251
- * Input computation as per [RFC7797](https://www.rfc-editor.org/rfc/rfc7797).
191
+ * Input computation as per {@link https://www.rfc-editor.org/rfc/rfc7797 RFC7797}.
252
192
  */
253
193
  b64?: boolean
254
194
 
@@ -475,45 +415,49 @@ export interface JWTPayload {
475
415
  /**
476
416
  * JWT Issuer
477
417
  *
478
- * @see [RFC7519#section-4.1.1](https://www.rfc-editor.org/rfc/rfc7519#section-4.1.1)
418
+ * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.1 RFC7519#section-4.1.1}
479
419
  */
480
420
  iss?: string
481
421
 
482
422
  /**
483
423
  * JWT Subject
484
424
  *
485
- * @see [RFC7519#section-4.1.2](https://www.rfc-editor.org/rfc/rfc7519#section-4.1.2)
425
+ * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.2 RFC7519#section-4.1.2}
486
426
  */
487
427
  sub?: string
488
428
 
489
- /** JWT Audience [RFC7519#section-4.1.3](https://www.rfc-editor.org/rfc/rfc7519#section-4.1.3). */
429
+ /**
430
+ * JWT Audience
431
+ *
432
+ * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.3 RFC7519#section-4.1.3}
433
+ */
490
434
  aud?: string | string[]
491
435
 
492
436
  /**
493
437
  * JWT ID
494
438
  *
495
- * @see [RFC7519#section-4.1.7](https://www.rfc-editor.org/rfc/rfc7519#section-4.1.7)
439
+ * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.7 RFC7519#section-4.1.7}
496
440
  */
497
441
  jti?: string
498
442
 
499
443
  /**
500
444
  * JWT Not Before
501
445
  *
502
- * @see [RFC7519#section-4.1.5](https://www.rfc-editor.org/rfc/rfc7519#section-4.1.5)
446
+ * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.5 RFC7519#section-4.1.5}
503
447
  */
504
448
  nbf?: number
505
449
 
506
450
  /**
507
451
  * JWT Expiration Time
508
452
  *
509
- * @see [RFC7519#section-4.1.4](https://www.rfc-editor.org/rfc/rfc7519#section-4.1.4)
453
+ * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.4 RFC7519#section-4.1.4}
510
454
  */
511
455
  exp?: number
512
456
 
513
457
  /**
514
458
  * JWT Issued At
515
459
  *
516
- * @see [RFC7519#section-4.1.6](https://www.rfc-editor.org/rfc/rfc7519#section-4.1.6)
460
+ * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.6 RFC7519#section-4.1.6}
517
461
  */
518
462
  iat?: number
519
463
 
@@ -523,7 +467,7 @@ export interface JWTPayload {
523
467
 
524
468
  /**
525
469
  * Deflate Raw implementation, e.g. promisified
526
- * [zlib.deflateRaw](https://nodejs.org/api/zlib.html#zlibdeflaterawbuffer-options-callback).
470
+ * {@link https://nodejs.org/api/zlib.html#zlibdeflaterawbuffer-options-callback zlib.deflateRaw}.
527
471
  */
528
472
  export interface DeflateFunction {
529
473
  (input: Uint8Array): Promise<Uint8Array>
@@ -531,7 +475,7 @@ export interface DeflateFunction {
531
475
 
532
476
  /**
533
477
  * Inflate Raw implementation, e.g. promisified
534
- * [zlib.inflateRaw](https://nodejs.org/api/zlib.html#zlibinflaterawbuffer-options-callback).
478
+ * {@link https://nodejs.org/api/zlib.html#zlibinflaterawbuffer-options-callback zlib.inflateRaw}.
535
479
  */
536
480
  export interface InflateFunction {
537
481
  (input: Uint8Array): Promise<Uint8Array>
@@ -5,13 +5,6 @@ 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
- * @example Usage
9
- *
10
- * ```js
11
- * const claims = jose.decodeJwt(token)
12
- * console.log(claims)
13
- * ```
14
- *
15
8
  * @param jwt JWT token in compact JWS serialization.
16
9
  */
17
10
  export declare function decodeJwt(jwt: string): JWTPayload;
@@ -3,13 +3,6 @@ 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
- * @example Usage
7
- *
8
- * ```js
9
- * const protectedHeader = jose.decodeProtectedHeader(token)
10
- * console.log(protectedHeader)
11
- * ```
12
- *
13
6
  * @param token JWE/JWS/JWT token in any JOSE serialization.
14
7
  */
15
8
  export declare function decodeProtectedHeader(token: string | object): ProtectedHeaderParameters;