jose 3.17.0 → 3.20.1

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 (103) hide show
  1. package/README.md +10 -3
  2. package/dist/browser/jwe/compact/decrypt.js +5 -1
  3. package/dist/browser/jwe/flattened/decrypt.js +5 -0
  4. package/dist/browser/jwk/embedded.js +3 -3
  5. package/dist/browser/jwk/from_key_like.js +2 -2
  6. package/dist/browser/jwk/parse.js +2 -31
  7. package/dist/browser/jwks/remote.js +7 -10
  8. package/dist/browser/jws/compact/verify.js +5 -1
  9. package/dist/browser/jws/flattened/verify.js +5 -0
  10. package/dist/browser/jwt/decrypt.js +5 -1
  11. package/dist/browser/jwt/encrypt.js +1 -1
  12. package/dist/browser/{lib/jwt_producer.js → jwt/produce.js} +4 -4
  13. package/dist/browser/jwt/sign.js +1 -1
  14. package/dist/browser/jwt/unsecured.js +1 -1
  15. package/dist/browser/jwt/verify.js +5 -1
  16. package/dist/browser/key/export.js +12 -0
  17. package/dist/browser/key/import.js +119 -0
  18. package/dist/browser/lib/check_key_type.js +33 -16
  19. package/dist/browser/lib/decrypt_key_management.js +37 -37
  20. package/dist/browser/lib/encrypt_key_management.js +2 -2
  21. package/dist/browser/lib/format_pem.js +4 -0
  22. package/dist/browser/runtime/asn1.js +119 -0
  23. package/dist/browser/runtime/base64url.js +12 -7
  24. package/dist/browser/runtime/fetch_jwks.js +18 -5
  25. package/dist/browser/runtime/is_key_like.js +5 -0
  26. package/dist/browser/util/errors.js +10 -3
  27. package/dist/node/cjs/jwe/compact/decrypt.js +5 -1
  28. package/dist/node/cjs/jwe/flattened/decrypt.js +5 -0
  29. package/dist/node/cjs/jwk/embedded.js +3 -3
  30. package/dist/node/cjs/jwk/from_key_like.js +2 -2
  31. package/dist/node/cjs/jwk/parse.js +2 -31
  32. package/dist/node/cjs/jwks/remote.js +7 -10
  33. package/dist/node/cjs/jws/compact/verify.js +5 -1
  34. package/dist/node/cjs/jws/flattened/verify.js +5 -0
  35. package/dist/node/cjs/jwt/decrypt.js +5 -1
  36. package/dist/node/cjs/jwt/encrypt.js +2 -2
  37. package/dist/node/cjs/{lib/jwt_producer.js → jwt/produce.js} +5 -4
  38. package/dist/node/cjs/jwt/sign.js +2 -2
  39. package/dist/node/cjs/jwt/unsecured.js +2 -2
  40. package/dist/node/cjs/jwt/verify.js +5 -1
  41. package/dist/node/cjs/key/export.js +18 -0
  42. package/dist/node/cjs/key/import.js +126 -0
  43. package/dist/node/cjs/lib/check_key_type.js +33 -16
  44. package/dist/node/cjs/lib/decrypt_key_management.js +37 -37
  45. package/dist/node/cjs/lib/encrypt_key_management.js +2 -2
  46. package/dist/node/cjs/lib/format_pem.js +6 -0
  47. package/dist/node/cjs/runtime/asn1.js +46 -0
  48. package/dist/node/cjs/runtime/base64url.js +5 -1
  49. package/dist/node/cjs/runtime/fetch_jwks.js +5 -1
  50. package/dist/node/cjs/runtime/is_key_like.js +11 -0
  51. package/dist/node/cjs/util/errors.js +12 -4
  52. package/dist/node/esm/jwe/compact/decrypt.js +5 -1
  53. package/dist/node/esm/jwe/flattened/decrypt.js +5 -0
  54. package/dist/node/esm/jwk/embedded.js +3 -3
  55. package/dist/node/esm/jwk/from_key_like.js +2 -2
  56. package/dist/node/esm/jwk/parse.js +2 -31
  57. package/dist/node/esm/jwks/remote.js +7 -10
  58. package/dist/node/esm/jws/compact/verify.js +5 -1
  59. package/dist/node/esm/jws/flattened/verify.js +5 -0
  60. package/dist/node/esm/jwt/decrypt.js +5 -1
  61. package/dist/node/esm/jwt/encrypt.js +1 -1
  62. package/dist/node/esm/{lib/jwt_producer.js → jwt/produce.js} +4 -4
  63. package/dist/node/esm/jwt/sign.js +1 -1
  64. package/dist/node/esm/jwt/unsecured.js +1 -1
  65. package/dist/node/esm/jwt/verify.js +5 -1
  66. package/dist/node/esm/key/export.js +12 -0
  67. package/dist/node/esm/key/import.js +119 -0
  68. package/dist/node/esm/lib/check_key_type.js +33 -16
  69. package/dist/node/esm/lib/decrypt_key_management.js +37 -37
  70. package/dist/node/esm/lib/encrypt_key_management.js +2 -2
  71. package/dist/node/esm/lib/format_pem.js +4 -0
  72. package/dist/node/esm/runtime/asn1.js +39 -0
  73. package/dist/node/esm/runtime/base64url.js +2 -0
  74. package/dist/node/esm/runtime/fetch_jwks.js +6 -2
  75. package/dist/node/esm/runtime/is_key_like.js +8 -0
  76. package/dist/node/esm/util/errors.js +10 -3
  77. package/dist/types/jwe/compact/decrypt.d.ts +3 -2
  78. package/dist/types/jwe/compact/encrypt.d.ts +1 -1
  79. package/dist/types/jwe/flattened/decrypt.d.ts +3 -2
  80. package/dist/types/jwe/flattened/encrypt.d.ts +1 -1
  81. package/dist/types/jwe/general/decrypt.d.ts +3 -2
  82. package/dist/types/jwk/embedded.d.ts +2 -3
  83. package/dist/types/jwk/from_key_like.d.ts +1 -1
  84. package/dist/types/jwk/parse.d.ts +1 -1
  85. package/dist/types/jws/compact/sign.d.ts +1 -1
  86. package/dist/types/jws/compact/verify.d.ts +3 -2
  87. package/dist/types/jws/flattened/sign.d.ts +1 -1
  88. package/dist/types/jws/flattened/verify.d.ts +3 -2
  89. package/dist/types/jws/general/sign.d.ts +1 -1
  90. package/dist/types/jws/general/verify.d.ts +3 -2
  91. package/dist/types/jwt/decrypt.d.ts +3 -2
  92. package/dist/types/jwt/encrypt.d.ts +2 -2
  93. package/dist/types/{lib/jwt_producer.d.ts → jwt/produce.d.ts} +1 -1
  94. package/dist/types/jwt/sign.d.ts +2 -2
  95. package/dist/types/jwt/unsecured.d.ts +1 -1
  96. package/dist/types/jwt/verify.d.ts +3 -2
  97. package/dist/types/key/export.d.ts +5 -0
  98. package/dist/types/key/import.d.ts +9 -0
  99. package/dist/types/types.d.ts +101 -5
  100. package/dist/types/util/errors.d.ts +5 -0
  101. package/dist/types/util/generate_key_pair.d.ts +2 -2
  102. package/dist/types/util/generate_secret.d.ts +1 -1
  103. package/package.json +20 -8
@@ -1,9 +1,9 @@
1
1
  import type { JWSHeaderParameters, JWTPayload, KeyLike, SignOptions } from '../types';
2
- import ProduceJWT from '../lib/jwt_producer';
2
+ import { ProduceJWT } from './produce';
3
3
  declare class SignJWT extends ProduceJWT {
4
4
  private _protectedHeader;
5
5
  setProtectedHeader(protectedHeader: JWSHeaderParameters): this;
6
- sign(key: KeyLike, options?: SignOptions): Promise<string>;
6
+ sign(key: KeyLike | Uint8Array, options?: SignOptions): Promise<string>;
7
7
  }
8
8
  export { SignJWT };
9
9
  export default SignJWT;
@@ -1,5 +1,5 @@
1
1
  import type { JWSHeaderParameters, JWTClaimVerificationOptions, JWTPayload } from '../types';
2
- import ProduceJWT from '../lib/jwt_producer';
2
+ import { ProduceJWT } from './produce';
3
3
  interface UnsecuredResult {
4
4
  payload: JWTPayload;
5
5
  header: JWSHeaderParameters;
@@ -1,9 +1,10 @@
1
- import type { KeyLike, VerifyOptions, JWTPayload, JWTClaimVerificationOptions, JWSHeaderParameters, GetKeyFunction, FlattenedJWSInput, JWTVerifyResult } from '../types';
1
+ import type { KeyLike, VerifyOptions, JWTPayload, JWTClaimVerificationOptions, JWSHeaderParameters, GetKeyFunction, FlattenedJWSInput, JWTVerifyResult, ResolvedKey } from '../types';
2
2
  interface JWTVerifyOptions extends VerifyOptions, JWTClaimVerificationOptions {
3
3
  }
4
4
  export interface JWTVerifyGetKey extends GetKeyFunction<JWSHeaderParameters, FlattenedJWSInput> {
5
5
  }
6
- declare function jwtVerify(jwt: string | Uint8Array, key: KeyLike | JWTVerifyGetKey, options?: JWTVerifyOptions): Promise<JWTVerifyResult>;
6
+ declare function jwtVerify(jwt: string | Uint8Array, key: KeyLike | Uint8Array, options?: JWTVerifyOptions): Promise<JWTVerifyResult>;
7
+ declare function jwtVerify(jwt: string | Uint8Array, getKey: JWTVerifyGetKey, options?: JWTVerifyOptions): Promise<JWTVerifyResult & ResolvedKey>;
7
8
  export { jwtVerify };
8
9
  export default jwtVerify;
9
10
  export type { KeyLike, JWTPayload, JWTVerifyOptions, JWSHeaderParameters, GetKeyFunction, JWTVerifyResult, };
@@ -0,0 +1,5 @@
1
+ import type { JWK, KeyLike } from '../types';
2
+ export declare function exportSPKI(key: KeyLike): Promise<string>;
3
+ export declare function exportPKCS8(key: KeyLike): Promise<string>;
4
+ export declare function exportJWK(key: KeyLike | Uint8Array): Promise<JWK>;
5
+ export type { KeyLike, JWK };
@@ -0,0 +1,9 @@
1
+ import type { JWK, KeyLike } from '../types';
2
+ export interface PEMImportOptions {
3
+ extractable?: boolean;
4
+ }
5
+ export declare function importSPKI(spki: string, alg: string, options?: PEMImportOptions): Promise<KeyLike>;
6
+ export declare function importX509(x509: string, alg: string, options?: PEMImportOptions): Promise<KeyLike>;
7
+ export declare function importPKCS8(pkcs8: string, alg: string, options?: PEMImportOptions): Promise<KeyLike>;
8
+ export declare function importJWK(jwk: JWK, alg?: string, octAsKeyObject?: boolean): Promise<KeyLike | Uint8Array>;
9
+ export type { KeyLike, JWK };
@@ -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
@@ -169,3 +262,6 @@ export interface JWTDecryptResult {
169
262
  payload: JWTPayload
170
263
  protectedHeader: JWEHeaderParameters
171
264
  }
265
+ export interface ResolvedKey {
266
+ key: KeyLike | Uint8Array
267
+ }
@@ -53,6 +53,11 @@ export declare class JWKSMultipleMatchingKeys extends JOSEError {
53
53
  code: string;
54
54
  message: string;
55
55
  }
56
+ export declare class JWKSTimeout extends JOSEError {
57
+ static code: string;
58
+ code: string;
59
+ message: string;
60
+ }
56
61
  export declare class JWSSignatureVerificationFailed extends JOSEError {
57
62
  static code: string;
58
63
  code: string;
@@ -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,16 +1,15 @@
1
1
  {
2
2
  "name": "jose",
3
- "version": "3.17.0",
3
+ "version": "3.20.1",
4
4
  "description": "Universal 'JSON Web Almost Everything' - JWA, JWS, JWE, JWT, JWK with no dependencies",
5
5
  "keywords": [
6
6
  "browser",
7
+ "cloudflare",
7
8
  "compact",
8
9
  "decode",
9
10
  "decrypt",
10
- "detached",
11
11
  "deno",
12
- "cloudflare",
13
- "workers",
12
+ "detached",
14
13
  "ec",
15
14
  "ecdsa",
16
15
  "eddsa",
@@ -32,14 +31,19 @@
32
31
  "oct",
33
32
  "okp",
34
33
  "payload",
34
+ "pem",
35
+ "pkcs8",
35
36
  "rsa",
36
37
  "secp256k1",
37
38
  "sign",
38
39
  "signature",
40
+ "spki",
39
41
  "universal",
40
42
  "validate",
41
43
  "verify",
42
- "webcrypto"
44
+ "webcrypto",
45
+ "workers",
46
+ "x509"
43
47
  ],
44
48
  "homepage": "https://github.com/panva/jose",
45
49
  "repository": "panva/jose",
@@ -155,6 +159,16 @@
155
159
  "import": "./dist/node/esm/jwt/verify.js",
156
160
  "require": "./dist/node/cjs/jwt/verify.js"
157
161
  },
162
+ "./key/export": {
163
+ "browser": "./dist/browser/key/export.js",
164
+ "import": "./dist/node/esm/key/export.js",
165
+ "require": "./dist/node/cjs/key/export.js"
166
+ },
167
+ "./key/import": {
168
+ "browser": "./dist/browser/key/import.js",
169
+ "import": "./dist/node/esm/key/import.js",
170
+ "require": "./dist/node/cjs/key/import.js"
171
+ },
158
172
  "./util/base64url": {
159
173
  "browser": "./dist/browser/util/base64url.js",
160
174
  "import": "./dist/node/esm/util/base64url.js",
@@ -198,9 +212,7 @@
198
212
  "dist/**/*.js",
199
213
  "dist/types/**/*.d.ts",
200
214
  "!dist/node/webcrypto/**/*",
201
- "!dist/types/**/*.i.d.ts",
202
215
  "!dist/types/runtime/*",
203
- "!dist/types/lib/*",
204
- "dist/types/lib/jwt_producer.d.ts"
216
+ "!dist/types/lib/*"
205
217
  ]
206
218
  }