jose 3.19.0 → 3.20.3

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 (87) hide show
  1. package/dist/browser/jwe/flattened/decrypt.js +5 -9
  2. package/dist/browser/jwe/flattened/encrypt.js +2 -5
  3. package/dist/browser/jwk/embedded.js +2 -2
  4. package/dist/browser/jwks/remote.js +7 -10
  5. package/dist/browser/jws/flattened/sign.js +1 -2
  6. package/dist/browser/jws/flattened/verify.js +2 -4
  7. package/dist/browser/jwt/encrypt.js +1 -1
  8. package/dist/browser/{lib/jwt_producer.js → jwt/produce.js} +4 -4
  9. package/dist/browser/jwt/sign.js +1 -1
  10. package/dist/browser/jwt/unsecured.js +1 -1
  11. package/dist/browser/lib/cek.js +3 -2
  12. package/dist/browser/lib/check_key_type.js +33 -16
  13. package/dist/browser/lib/decrypt_key_management.js +35 -35
  14. package/dist/browser/lib/encrypt_key_management.js +3 -5
  15. package/dist/browser/lib/iv.js +3 -2
  16. package/dist/browser/runtime/aesgcmkw.js +1 -3
  17. package/dist/browser/runtime/fetch_jwks.js +16 -3
  18. package/dist/browser/runtime/is_key_like.js +5 -0
  19. package/dist/browser/runtime/random.js +1 -2
  20. package/dist/browser/util/errors.js +73 -34
  21. package/dist/node/cjs/jwe/flattened/decrypt.js +5 -9
  22. package/dist/node/cjs/jwe/flattened/encrypt.js +2 -5
  23. package/dist/node/cjs/jwk/embedded.js +2 -2
  24. package/dist/node/cjs/jwks/remote.js +7 -10
  25. package/dist/node/cjs/jws/flattened/sign.js +1 -2
  26. package/dist/node/cjs/jws/flattened/verify.js +2 -4
  27. package/dist/node/cjs/jwt/encrypt.js +2 -2
  28. package/dist/node/cjs/{lib/jwt_producer.js → jwt/produce.js} +5 -4
  29. package/dist/node/cjs/jwt/sign.js +2 -2
  30. package/dist/node/cjs/jwt/unsecured.js +2 -2
  31. package/dist/node/cjs/lib/cek.js +4 -3
  32. package/dist/node/cjs/lib/check_key_type.js +33 -16
  33. package/dist/node/cjs/lib/decrypt_key_management.js +35 -35
  34. package/dist/node/cjs/lib/encrypt_key_management.js +7 -9
  35. package/dist/node/cjs/lib/iv.js +4 -3
  36. package/dist/node/cjs/runtime/aesgcmkw.js +1 -3
  37. package/dist/node/cjs/runtime/fetch_jwks.js +5 -1
  38. package/dist/node/cjs/runtime/is_key_like.js +11 -0
  39. package/dist/node/cjs/runtime/random.js +3 -2
  40. package/dist/node/cjs/util/errors.js +77 -37
  41. package/dist/node/esm/jwe/flattened/decrypt.js +5 -9
  42. package/dist/node/esm/jwe/flattened/encrypt.js +2 -5
  43. package/dist/node/esm/jwk/embedded.js +2 -2
  44. package/dist/node/esm/jwks/remote.js +7 -10
  45. package/dist/node/esm/jws/flattened/sign.js +1 -2
  46. package/dist/node/esm/jws/flattened/verify.js +2 -4
  47. package/dist/node/esm/jwt/encrypt.js +1 -1
  48. package/dist/node/esm/{lib/jwt_producer.js → jwt/produce.js} +4 -4
  49. package/dist/node/esm/jwt/sign.js +1 -1
  50. package/dist/node/esm/jwt/unsecured.js +1 -1
  51. package/dist/node/esm/lib/cek.js +3 -2
  52. package/dist/node/esm/lib/check_key_type.js +33 -16
  53. package/dist/node/esm/lib/decrypt_key_management.js +35 -35
  54. package/dist/node/esm/lib/encrypt_key_management.js +3 -5
  55. package/dist/node/esm/lib/iv.js +3 -2
  56. package/dist/node/esm/runtime/aesgcmkw.js +1 -3
  57. package/dist/node/esm/runtime/fetch_jwks.js +6 -2
  58. package/dist/node/esm/runtime/is_key_like.js +8 -0
  59. package/dist/node/esm/runtime/random.js +1 -2
  60. package/dist/node/esm/util/errors.js +73 -34
  61. package/dist/types/jwe/compact/decrypt.d.ts +1 -1
  62. package/dist/types/jwe/compact/encrypt.d.ts +1 -1
  63. package/dist/types/jwe/flattened/decrypt.d.ts +1 -1
  64. package/dist/types/jwe/flattened/encrypt.d.ts +1 -1
  65. package/dist/types/jwe/general/decrypt.d.ts +1 -1
  66. package/dist/types/jwk/embedded.d.ts +2 -3
  67. package/dist/types/jwk/from_key_like.d.ts +1 -1
  68. package/dist/types/jwk/parse.d.ts +1 -1
  69. package/dist/types/jws/compact/sign.d.ts +1 -1
  70. package/dist/types/jws/compact/verify.d.ts +1 -1
  71. package/dist/types/jws/flattened/sign.d.ts +1 -1
  72. package/dist/types/jws/flattened/verify.d.ts +1 -1
  73. package/dist/types/jws/general/sign.d.ts +1 -1
  74. package/dist/types/jws/general/verify.d.ts +1 -1
  75. package/dist/types/jwt/decrypt.d.ts +1 -1
  76. package/dist/types/jwt/encrypt.d.ts +2 -2
  77. package/dist/types/{lib/jwt_producer.d.ts → jwt/produce.d.ts} +1 -1
  78. package/dist/types/jwt/sign.d.ts +2 -2
  79. package/dist/types/jwt/unsecured.d.ts +1 -1
  80. package/dist/types/jwt/verify.d.ts +1 -1
  81. package/dist/types/key/export.d.ts +3 -3
  82. package/dist/types/key/import.d.ts +4 -4
  83. package/dist/types/types.d.ts +99 -6
  84. package/dist/types/util/errors.d.ts +24 -16
  85. package/dist/types/util/generate_key_pair.d.ts +2 -2
  86. package/dist/types/util/generate_secret.d.ts +1 -1
  87. package/package.json +3 -4
@@ -1,7 +1,100 @@
1
- /// <reference lib="dom"/>
2
- import type { KeyObject } from 'crypto'
3
- export type { KeyObject }
4
- export type KeyLike = KeyObject | CryptoKey | Uint8Array
1
+ /**
2
+ * KeyLike are runtime-specific classes representing asymmetric keys or symmetric secrets.
3
+ * These are instances of
4
+ * [CryptoKey](https://developer.mozilla.org/en-US/docs/Web/API/CryptoKey) and additionally
5
+ * [KeyObject](https://nodejs.org/api/crypto.html#crypto_class_keyobject)
6
+ * in Node.js runtime.
7
+ * [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array)
8
+ * instances are also accepted as symmetric secret representation only.
9
+ *
10
+ * [jose/key/import](../modules/key_import.md#readme) functions can be used to import PEM,
11
+ * or JWK formatted asymmetric keys and certificates to these runtime-specific representations.
12
+ *
13
+ * In Node.js the
14
+ * [Buffer](https://nodejs.org/api/buffer.html#buffer_buffer) class is a subclass of Uint8Array
15
+ * and so Buffer can be provided for symmetric secrets as well.
16
+ *
17
+ * ---
18
+ *
19
+ * [KeyObject](https://nodejs.org/api/crypto.html#crypto_class_keyobject) is a representation of a
20
+ * key/secret available in the Node.js runtime.
21
+ * In addition to the import functions of this library you may use the
22
+ * runtime APIs
23
+ * [crypto.createPublicKey](https://nodejs.org/api/crypto.html#crypto_crypto_createpublickey_key),
24
+ * [crypto.createPrivateKey](https://nodejs.org/api/crypto.html#crypto_crypto_createprivatekey_key), and
25
+ * [crypto.createSecretKey](https://nodejs.org/api/crypto.html#crypto_crypto_createsecretkey_key_encoding)
26
+ * to obtain a KeyObject from your existing key material.
27
+ *
28
+ * [CryptoKey](https://developer.mozilla.org/en-US/docs/Web/API/CryptoKey) is a representation of a
29
+ * key/secret available in the Browser and Deno runtimes.
30
+ * In addition to the import functions of this library you may use the
31
+ * [SubtleCrypto.importKey](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/importKey) API
32
+ * to obtain a CryptoKey from your existing key material.
33
+ *
34
+ * ---
35
+ *
36
+ * @example Import a PEM-encoded SPKI Public Key
37
+ * ```js
38
+ * import { importSPKI } from 'jose/key/import'
39
+ *
40
+ * const algorithm = 'ES256'
41
+ * const spki = `-----BEGIN PUBLIC KEY-----
42
+ * MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEFlHHWfLk0gLBbsLTcuCrbCqoHqmM
43
+ * YJepMC+Q+Dd6RBmBiA41evUsNMwLeN+PNFqib+xwi9JkJ8qhZkq8Y/IzGg==
44
+ * -----END PUBLIC KEY-----`
45
+ * const ecPublicKey = await importSPKI(spki, algorithm)
46
+ * ```
47
+ *
48
+ * @example Import a X.509 Certificate
49
+ * ```js
50
+ * import { importX509 } from 'jose/key/import'
51
+ *
52
+ * const algorithm = 'ES256'
53
+ * const x509 = `-----BEGIN CERTIFICATE-----
54
+ * MIIBXjCCAQSgAwIBAgIGAXvykuMKMAoGCCqGSM49BAMCMDYxNDAyBgNVBAMMK3Np
55
+ * QXBNOXpBdk1VaXhXVWVGaGtjZXg1NjJRRzFyQUhXaV96UlFQTVpQaG8wHhcNMjEw
56
+ * OTE3MDcwNTE3WhcNMjIwNzE0MDcwNTE3WjA2MTQwMgYDVQQDDCtzaUFwTTl6QXZN
57
+ * VWl4V1VlRmhrY2V4NTYyUUcxckFIV2lfelJRUE1aUGhvMFkwEwYHKoZIzj0CAQYI
58
+ * KoZIzj0DAQcDQgAE8PbPvCv5D5xBFHEZlBp/q5OEUymq7RIgWIi7tkl9aGSpYE35
59
+ * UH+kBKDnphJO3odpPZ5gvgKs2nwRWcrDnUjYLDAKBggqhkjOPQQDAgNIADBFAiEA
60
+ * 1yyMTRe66MhEXID9+uVub7woMkNYd0LhSHwKSPMUUTkCIFQGsfm1ecXOpeGOufAh
61
+ * v+A1QWZMuTWqYt+uh/YSRNDn
62
+ * -----END CERTIFICATE-----`
63
+ * const ecPublicKey = await importX509(x509, algorithm)
64
+ * ```
65
+ *
66
+ * @example Import a PEM-encoded PKCS8 Private Key
67
+ * ```js
68
+ * import { importPKCS8 } from 'jose/key/import'
69
+ *
70
+ * const algorithm = 'ES256'
71
+ * const pkcs8 = `-----BEGIN PRIVATE KEY-----
72
+ * MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgiyvo0X+VQ0yIrOaN
73
+ * nlrnUclopnvuuMfoc8HHly3505OhRANCAAQWUcdZ8uTSAsFuwtNy4KtsKqgeqYxg
74
+ * l6kwL5D4N3pEGYGIDjV69Sw0zAt43480WqJv7HCL0mQnyqFmSrxj8jMa
75
+ * -----END PRIVATE KEY-----`
76
+ * const ecPrivateKey = await importPKCS8(pkcs8, algorithm)
77
+ * ```
78
+ *
79
+ * @example Import a JSON Web Key (JWK)
80
+ * ```js
81
+ * import { importJWK } from 'jose/key/import'
82
+ *
83
+ * const ecPublicKey = await importJWK({
84
+ * crv: 'P-256',
85
+ * kty: 'EC',
86
+ * x: 'ySK38C1jBdLwDsNWKzzBHqKYEE5Cgv-qjWvorUXk9fw',
87
+ * y: '_LeQBw07cf5t57Iavn4j-BqJsAD1dpoz8gokd3sBsOo'
88
+ * }, 'ES256')
89
+ *
90
+ * const rsaPublicKey = await importJWK({
91
+ * kty: 'RSA',
92
+ * e: 'AQAB',
93
+ * n: '12oBZRhCiZFJLcPg59LkZZ9mdhSMTKAQZYq32k_ti5SBB6jerkh-WzOMAO664r_qyLkqHUSp3u5SbXtseZEpN3XPWGKSxjsy-1JyEFTdLSYe6f9gfrmxkUF_7DTpq0gn6rntP05g2-wFW50YO7mosfdslfrTJYWHFhJALabAeYirYD7-9kqq9ebfFMF4sRRELbv9oi36As6Q9B3Qb5_C1rAzqfao_PCsf9EPsTZsVVVkA5qoIAr47lo1ipfiBPxUCCNSdvkmDTYgvvRm6ZoMjFbvOtgyts55fXKdMWv7I9HMD5HwE9uW839PWA514qhbcIsXEYSFMPMV6fnlsiZvQQ'
94
+ * }, 'PS256')
95
+ * ```
96
+ */
97
+ export type KeyLike = { type: string }
5
98
  export interface JWK {
6
99
  alg?: string
7
100
  crv?: string
@@ -33,7 +126,7 @@ export interface JWK {
33
126
  [propName: string]: unknown
34
127
  }
35
128
  export interface GetKeyFunction<T, T2> {
36
- (protectedHeader: T, token: T2): Promise<KeyLike>
129
+ (protectedHeader: T, token: T2): Promise<KeyLike | Uint8Array>
37
130
  }
38
131
  export interface FlattenedJWSInput {
39
132
  header?: JWSHeaderParameters
@@ -170,5 +263,5 @@ export interface JWTDecryptResult {
170
263
  protectedHeader: JWEHeaderParameters
171
264
  }
172
265
  export interface ResolvedKey {
173
- key: KeyLike
266
+ key: KeyLike | Uint8Array
174
267
  }
@@ -1,64 +1,72 @@
1
1
  export declare class JOSEError extends Error {
2
- static code: string;
2
+ static get code(): string;
3
3
  code: string;
4
4
  constructor(message?: string);
5
5
  }
6
6
  export declare class JWTClaimValidationFailed extends JOSEError {
7
- static code: string;
7
+ static get code(): 'ERR_JWT_CLAIM_VALIDATION_FAILED';
8
+ code: string;
9
+ claim: string;
10
+ reason: string;
11
+ constructor(message: string, claim?: string, reason?: string);
12
+ }
13
+ export declare class JWTExpired extends JOSEError implements JWTClaimValidationFailed {
14
+ static get code(): 'ERR_JWT_EXPIRED';
8
15
  code: string;
9
16
  claim: string;
10
17
  reason: string;
11
18
  constructor(message: string, claim?: string, reason?: string);
12
19
  }
13
20
  export declare class JOSEAlgNotAllowed extends JOSEError {
14
- static code: string;
21
+ static get code(): 'ERR_JOSE_ALG_NOT_ALLOWED';
15
22
  code: string;
16
23
  }
17
24
  export declare class JOSENotSupported extends JOSEError {
18
- static code: string;
25
+ static get code(): 'ERR_JOSE_NOT_SUPPORTED';
19
26
  code: string;
20
27
  }
21
28
  export declare class JWEDecryptionFailed extends JOSEError {
22
- static code: string;
29
+ static get code(): 'ERR_JWE_DECRYPTION_FAILED';
23
30
  code: string;
24
31
  message: string;
25
32
  }
26
33
  export declare class JWEInvalid extends JOSEError {
27
- static code: string;
34
+ static get code(): 'ERR_JWE_INVALID';
28
35
  code: string;
29
36
  }
30
37
  export declare class JWSInvalid extends JOSEError {
31
- static code: string;
38
+ static get code(): 'ERR_JWS_INVALID';
32
39
  code: string;
33
40
  }
34
41
  export declare class JWTInvalid extends JOSEError {
35
- static code: string;
42
+ static get code(): 'ERR_JWT_INVALID';
36
43
  code: string;
37
44
  }
38
45
  export declare class JWKInvalid extends JOSEError {
39
- static code: string;
46
+ static get code(): 'ERR_JWK_INVALID';
40
47
  code: string;
41
48
  }
42
49
  export declare class JWKSInvalid extends JOSEError {
43
- static code: string;
50
+ static get code(): 'ERR_JWKS_INVALID';
44
51
  code: string;
45
52
  }
46
53
  export declare class JWKSNoMatchingKey extends JOSEError {
47
- static code: string;
54
+ static get code(): 'ERR_JWKS_NO_MATCHING_KEY';
48
55
  code: string;
49
56
  message: string;
50
57
  }
51
58
  export declare class JWKSMultipleMatchingKeys extends JOSEError {
52
- static code: string;
59
+ static get code(): 'ERR_JWKS_MULTIPLE_MATCHING_KEYS';
53
60
  code: string;
54
61
  message: string;
55
62
  }
56
- export declare class JWSSignatureVerificationFailed extends JOSEError {
57
- static code: string;
63
+ export declare class JWKSTimeout extends JOSEError {
64
+ static get code(): 'ERR_JWKS_TIMEOUT';
58
65
  code: string;
59
66
  message: string;
60
67
  }
61
- export declare class JWTExpired extends JWTClaimValidationFailed {
62
- static code: string;
68
+ export declare class JWSSignatureVerificationFailed extends JOSEError {
69
+ static get code(): 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED';
63
70
  code: string;
71
+ message: string;
64
72
  }
@@ -1,7 +1,7 @@
1
1
  import type { KeyLike } from '../types';
2
2
  export interface GenerateKeyPairResult {
3
- privateKey: Exclude<KeyLike, Uint8Array>;
4
- publicKey: Exclude<KeyLike, Uint8Array>;
3
+ privateKey: KeyLike;
4
+ publicKey: KeyLike;
5
5
  }
6
6
  export interface GenerateKeyPairOptions {
7
7
  crv?: string;
@@ -2,6 +2,6 @@ import type { KeyLike } from '../types';
2
2
  export interface GenerateSecretOptions {
3
3
  extractable?: boolean;
4
4
  }
5
- declare function generateSecret(alg: string, options?: GenerateSecretOptions): Promise<KeyLike>;
5
+ declare function generateSecret(alg: string, options?: GenerateSecretOptions): Promise<KeyLike | Uint8Array>;
6
6
  export { generateSecret };
7
7
  export default generateSecret;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jose",
3
- "version": "3.19.0",
3
+ "version": "3.20.3",
4
4
  "description": "Universal 'JSON Web Almost Everything' - JWA, JWS, JWE, JWT, JWK with no dependencies",
5
5
  "keywords": [
6
6
  "browser",
@@ -52,6 +52,7 @@
52
52
  },
53
53
  "license": "MIT",
54
54
  "author": "Filip Skokan <panva.ip@gmail.com>",
55
+ "sideEffects": false,
55
56
  "exports": {
56
57
  "./package.json": "./package.json",
57
58
  "./jwe/compact/decrypt": {
@@ -212,9 +213,7 @@
212
213
  "dist/**/*.js",
213
214
  "dist/types/**/*.d.ts",
214
215
  "!dist/node/webcrypto/**/*",
215
- "!dist/types/**/*.i.d.ts",
216
216
  "!dist/types/runtime/*",
217
- "!dist/types/lib/*",
218
- "dist/types/lib/jwt_producer.d.ts"
217
+ "!dist/types/lib/*"
219
218
  ]
220
219
  }