jose 6.0.6 → 6.0.7

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.
@@ -6,7 +6,12 @@
6
6
  import type * as types from '../types.d.ts';
7
7
  /** Secret generation function options. */
8
8
  export interface GenerateSecretOptions {
9
- /** The value to use as {@link !SubtleCrypto.generateKey} `extractable` argument. Default is false. */
9
+ /**
10
+ * The value to use as {@link !SubtleCrypto.generateKey} `extractable` argument. Default is false.
11
+ *
12
+ * Note: Because A128CBC-HS256, A192CBC-HS384, and A256CBC-HS512 secrets cannot be represented as
13
+ * {@link !CryptoKey} this option has no effect for them.
14
+ */
10
15
  extractable?: boolean;
11
16
  }
12
17
  /**
@@ -14,6 +19,9 @@ export interface GenerateSecretOptions {
14
19
  *
15
20
  * Note: The secret key is generated with `extractable` set to `false` by default.
16
21
  *
22
+ * Note: Because A128CBC-HS256, A192CBC-HS384, and A256CBC-HS512 secrets cannot be represented as
23
+ * {@link !CryptoKey} this method yields a {@link !Uint8Array} for them instead.
24
+ *
17
25
  * This function is exported (as a named export) from the main `'jose'` module entry point as well
18
26
  * as from its subpath export `'jose/generate/secret'`.
19
27
  *
@@ -8,7 +8,7 @@ import type * as types from '../types.d.ts';
8
8
  export interface KeyImportOptions {
9
9
  /**
10
10
  * The value to use as {@link !SubtleCrypto.importKey} `extractable` argument. Default is false for
11
- * private and secret keys, true otherwise.
11
+ * private keys, true otherwise.
12
12
  */
13
13
  extractable?: boolean;
14
14
  }
@@ -59,11 +59,14 @@ export declare function importX509(x509: string, alg: string, options?: KeyImpor
59
59
  export declare function importPKCS8(pkcs8: string, alg: string, options?: KeyImportOptions): Promise<types.CryptoKey>;
60
60
  /**
61
61
  * Imports a JWK to a {@link !CryptoKey}. Either the JWK "alg" (Algorithm) Parameter, or the optional
62
- * "alg" argument, must be present.
62
+ * "alg" argument, must be present for asymmetric JSON Web Key imports.
63
63
  *
64
64
  * Note: The JSON Web Key parameters "use", "key_ops", and "ext" are also used in the
65
65
  * {@link !CryptoKey} import process.
66
66
  *
67
+ * Note: Symmetric JSON Web Keys (i.e. `kty: "oct"`) yield back an {@link !Uint8Array} instead of a
68
+ * {@link !CryptoKey}.
69
+ *
67
70
  * This function is exported (as a named export) from the main `'jose'` module entry point as well
68
71
  * as from its subpath export `'jose/key/import'`.
69
72
  *
@@ -9,16 +9,16 @@ function isCloudflareWorkers() {
9
9
  let USER_AGENT;
10
10
  if (typeof navigator === 'undefined' || !navigator.userAgent?.startsWith?.('Mozilla/5.0 ')) {
11
11
  const NAME = 'jose';
12
- const VERSION = 'v6.0.6';
12
+ const VERSION = 'v6.0.7';
13
13
  USER_AGENT = `${NAME}/${VERSION}`;
14
14
  }
15
15
  export const customFetch = Symbol();
16
- async function fetchJwks(url, options) {
17
- const response = await (options?.[customFetch] || fetch)(url, {
16
+ async function fetchJwks(url, headers, signal, fetchImpl = fetch) {
17
+ const response = await fetchImpl(url, {
18
18
  method: 'GET',
19
- signal: options.signal,
19
+ signal,
20
20
  redirect: 'manual',
21
- headers: options.headers,
21
+ headers,
22
22
  }).catch((err) => {
23
23
  if (err.name === 'TimeoutError') {
24
24
  throw new JWKSTimeout();
@@ -58,7 +58,8 @@ class RemoteJWKSet {
58
58
  _cacheMaxAge;
59
59
  _jwksTimestamp;
60
60
  _pendingFetch;
61
- _options;
61
+ _headers;
62
+ [customFetch];
62
63
  _local;
63
64
  _cache;
64
65
  constructor(url, options) {
@@ -66,12 +67,20 @@ class RemoteJWKSet {
66
67
  throw new TypeError('url must be an instance of URL');
67
68
  }
68
69
  this._url = new URL(url.href);
69
- this._options = { headers: options?.headers };
70
70
  this._timeoutDuration =
71
71
  typeof options?.timeoutDuration === 'number' ? options?.timeoutDuration : 5000;
72
72
  this._cooldownDuration =
73
73
  typeof options?.cooldownDuration === 'number' ? options?.cooldownDuration : 30000;
74
74
  this._cacheMaxAge = typeof options?.cacheMaxAge === 'number' ? options?.cacheMaxAge : 600000;
75
+ this._headers = new Headers(options?.headers);
76
+ if (USER_AGENT && !this._headers.has('User-Agent')) {
77
+ this._headers.set('User-Agent', USER_AGENT);
78
+ }
79
+ if (!this._headers.has('accept')) {
80
+ this._headers.set('accept', 'application/json');
81
+ this._headers.append('accept', 'application/jwk-set+json');
82
+ }
83
+ this[customFetch] = options?.[customFetch];
75
84
  if (options?.[jwksCache] !== undefined) {
76
85
  this._cache = options?.[jwksCache];
77
86
  if (isFreshJwksCache(options?.[jwksCache], this._cacheMaxAge)) {
@@ -111,19 +120,7 @@ class RemoteJWKSet {
111
120
  if (this._pendingFetch && isCloudflareWorkers()) {
112
121
  this._pendingFetch = undefined;
113
122
  }
114
- const headers = new Headers(this._options.headers);
115
- if (USER_AGENT && !headers.has('User-Agent')) {
116
- headers.set('User-Agent', USER_AGENT);
117
- this._options.headers = Object.fromEntries(headers.entries());
118
- }
119
- if (!headers.has('accept')) {
120
- headers.set('accept', 'application/json');
121
- headers.append('accept', 'application/jwk-set+json');
122
- }
123
- this._pendingFetch ||= fetchJwks(this._url.href, {
124
- headers,
125
- signal: AbortSignal.timeout(this._timeoutDuration),
126
- })
123
+ this._pendingFetch ||= fetchJwks(this._url.href, this._headers, AbortSignal.timeout(this._timeoutDuration), this[customFetch])
127
124
  .then((json) => {
128
125
  this._local = createLocalJWKSet(json);
129
126
  if (this._cache) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jose",
3
- "version": "6.0.6",
3
+ "version": "6.0.7",
4
4
  "description": "JWA, JWS, JWE, JWT, JWK, JWKS for Node.js, Browser, Cloudflare Workers, Deno, Bun, and other Web-interoperable runtimes",
5
5
  "keywords": [
6
6
  "browser",