jose 5.2.3 → 5.2.4

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.
@@ -14,7 +14,7 @@ function getKtyFromAlg(alg) {
14
14
  throw new JOSENotSupported('Unsupported "alg" value for a JSON Web Key Set');
15
15
  }
16
16
  }
17
- export function isJWKSLike(jwks) {
17
+ function isJWKSLike(jwks) {
18
18
  return (jwks &&
19
19
  typeof jwks === 'object' &&
20
20
  Array.isArray(jwks.keys) &&
@@ -1,6 +1,6 @@
1
1
  import fetchJwks from '../runtime/fetch_jwks.js';
2
- import { JWKSInvalid, JWKSNoMatchingKey } from '../util/errors.js';
3
- import { isJWKSLike, LocalJWKSet } from './local.js';
2
+ import { JWKSNoMatchingKey } from '../util/errors.js';
3
+ import { createLocalJWKSet } from './local.js';
4
4
  function isCloudflareWorkers() {
5
5
  return (typeof WebSocketPair !== 'undefined' ||
6
6
  (typeof navigator !== 'undefined' && navigator.userAgent === 'Cloudflare-Workers') ||
@@ -9,13 +9,11 @@ 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 = 'v5.2.3';
12
+ const VERSION = 'v5.2.4';
13
13
  USER_AGENT = `${NAME}/${VERSION}`;
14
14
  }
15
- class RemoteJWKSet extends LocalJWKSet {
15
+ class RemoteJWKSet {
16
16
  constructor(url, options) {
17
- super({ keys: [] });
18
- this._jwks = undefined;
19
17
  if (!(url instanceof URL)) {
20
18
  throw new TypeError('url must be an instance of URL');
21
19
  }
@@ -38,17 +36,17 @@ class RemoteJWKSet extends LocalJWKSet {
38
36
  : false;
39
37
  }
40
38
  async getKey(protectedHeader, token) {
41
- if (!this._jwks || !this.fresh()) {
39
+ if (!this._local || !this.fresh()) {
42
40
  await this.reload();
43
41
  }
44
42
  try {
45
- return await super.getKey(protectedHeader, token);
43
+ return await this._local(protectedHeader, token);
46
44
  }
47
45
  catch (err) {
48
46
  if (err instanceof JWKSNoMatchingKey) {
49
47
  if (this.coolingDown() === false) {
50
48
  await this.reload();
51
- return super.getKey(protectedHeader, token);
49
+ return this._local(protectedHeader, token);
52
50
  }
53
51
  }
54
52
  throw err;
@@ -65,10 +63,7 @@ class RemoteJWKSet extends LocalJWKSet {
65
63
  }
66
64
  this._pendingFetch || (this._pendingFetch = fetchJwks(this._url, this._timeoutDuration, this._options)
67
65
  .then((json) => {
68
- if (!isJWKSLike(json)) {
69
- throw new JWKSInvalid('JSON Web Key Set malformed');
70
- }
71
- this._jwks = { keys: json.keys };
66
+ this._local = createLocalJWKSet(json);
72
67
  this._jwksTimestamp = Date.now();
73
68
  this._pendingFetch = undefined;
74
69
  })
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createLocalJWKSet = exports.LocalJWKSet = exports.isJWKSLike = void 0;
3
+ exports.createLocalJWKSet = exports.LocalJWKSet = void 0;
4
4
  const import_js_1 = require("../key/import.js");
5
5
  const errors_js_1 = require("../util/errors.js");
6
6
  const is_object_js_1 = require("../lib/is_object.js");
@@ -23,7 +23,6 @@ function isJWKSLike(jwks) {
23
23
  Array.isArray(jwks.keys) &&
24
24
  jwks.keys.every(isJWKLike));
25
25
  }
26
- exports.isJWKSLike = isJWKSLike;
27
26
  function isJWKLike(key) {
28
27
  return (0, is_object_js_1.default)(key);
29
28
  }
@@ -12,10 +12,10 @@ function isCloudflareWorkers() {
12
12
  let USER_AGENT;
13
13
  if (typeof navigator === 'undefined' || !navigator.userAgent?.startsWith?.('Mozilla/5.0 ')) {
14
14
  const NAME = 'jose';
15
- const VERSION = 'v5.2.3';
15
+ const VERSION = 'v5.2.4';
16
16
  USER_AGENT = `${NAME}/${VERSION}`;
17
17
  }
18
- class RemoteJWKSet extends local_js_1.LocalJWKSet {
18
+ class RemoteJWKSet {
19
19
  _url;
20
20
  _timeoutDuration;
21
21
  _cooldownDuration;
@@ -23,9 +23,8 @@ class RemoteJWKSet extends local_js_1.LocalJWKSet {
23
23
  _jwksTimestamp;
24
24
  _pendingFetch;
25
25
  _options;
26
+ _local;
26
27
  constructor(url, options) {
27
- super({ keys: [] });
28
- this._jwks = undefined;
29
28
  if (!(url instanceof URL)) {
30
29
  throw new TypeError('url must be an instance of URL');
31
30
  }
@@ -48,17 +47,17 @@ class RemoteJWKSet extends local_js_1.LocalJWKSet {
48
47
  : false;
49
48
  }
50
49
  async getKey(protectedHeader, token) {
51
- if (!this._jwks || !this.fresh()) {
50
+ if (!this._local || !this.fresh()) {
52
51
  await this.reload();
53
52
  }
54
53
  try {
55
- return await super.getKey(protectedHeader, token);
54
+ return await this._local(protectedHeader, token);
56
55
  }
57
56
  catch (err) {
58
57
  if (err instanceof errors_js_1.JWKSNoMatchingKey) {
59
58
  if (this.coolingDown() === false) {
60
59
  await this.reload();
61
- return super.getKey(protectedHeader, token);
60
+ return this._local(protectedHeader, token);
62
61
  }
63
62
  }
64
63
  throw err;
@@ -75,10 +74,7 @@ class RemoteJWKSet extends local_js_1.LocalJWKSet {
75
74
  }
76
75
  this._pendingFetch ||= (0, fetch_jwks_js_1.default)(this._url, this._timeoutDuration, this._options)
77
76
  .then((json) => {
78
- if (!(0, local_js_1.isJWKSLike)(json)) {
79
- throw new errors_js_1.JWKSInvalid('JSON Web Key Set malformed');
80
- }
81
- this._jwks = { keys: json.keys };
77
+ this._local = (0, local_js_1.createLocalJWKSet)(json);
82
78
  this._jwksTimestamp = Date.now();
83
79
  this._pendingFetch = undefined;
84
80
  })
@@ -75,7 +75,7 @@ async function decryptKeyManagement(alg, key, encryptedKey, joseHeader, options)
75
75
  throw new errors_js_1.JWEInvalid('JWE Encrypted Key missing');
76
76
  if (typeof joseHeader.p2c !== 'number')
77
77
  throw new errors_js_1.JWEInvalid(`JOSE Header "p2c" (PBES2 Count) missing or invalid`);
78
- const p2cLimit = options?.maxPBES2Count || 10000;
78
+ const p2cLimit = options?.maxPBES2Count || 10_000;
79
79
  if (joseHeader.p2c > p2cLimit)
80
80
  throw new errors_js_1.JWEInvalid(`JOSE Header "p2c" (PBES2 Count) out is of acceptable bounds`);
81
81
  if (typeof joseHeader.p2s !== 'string')
@@ -14,7 +14,7 @@ function getKtyFromAlg(alg) {
14
14
  throw new JOSENotSupported('Unsupported "alg" value for a JSON Web Key Set');
15
15
  }
16
16
  }
17
- export function isJWKSLike(jwks) {
17
+ function isJWKSLike(jwks) {
18
18
  return (jwks &&
19
19
  typeof jwks === 'object' &&
20
20
  Array.isArray(jwks.keys) &&
@@ -1,6 +1,6 @@
1
1
  import fetchJwks from '../runtime/fetch_jwks.js';
2
- import { JWKSInvalid, JWKSNoMatchingKey } from '../util/errors.js';
3
- import { isJWKSLike, LocalJWKSet } from './local.js';
2
+ import { JWKSNoMatchingKey } from '../util/errors.js';
3
+ import { createLocalJWKSet } from './local.js';
4
4
  function isCloudflareWorkers() {
5
5
  return (typeof WebSocketPair !== 'undefined' ||
6
6
  (typeof navigator !== 'undefined' && navigator.userAgent === 'Cloudflare-Workers') ||
@@ -9,10 +9,10 @@ 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 = 'v5.2.3';
12
+ const VERSION = 'v5.2.4';
13
13
  USER_AGENT = `${NAME}/${VERSION}`;
14
14
  }
15
- class RemoteJWKSet extends LocalJWKSet {
15
+ class RemoteJWKSet {
16
16
  _url;
17
17
  _timeoutDuration;
18
18
  _cooldownDuration;
@@ -20,9 +20,8 @@ class RemoteJWKSet extends LocalJWKSet {
20
20
  _jwksTimestamp;
21
21
  _pendingFetch;
22
22
  _options;
23
+ _local;
23
24
  constructor(url, options) {
24
- super({ keys: [] });
25
- this._jwks = undefined;
26
25
  if (!(url instanceof URL)) {
27
26
  throw new TypeError('url must be an instance of URL');
28
27
  }
@@ -45,17 +44,17 @@ class RemoteJWKSet extends LocalJWKSet {
45
44
  : false;
46
45
  }
47
46
  async getKey(protectedHeader, token) {
48
- if (!this._jwks || !this.fresh()) {
47
+ if (!this._local || !this.fresh()) {
49
48
  await this.reload();
50
49
  }
51
50
  try {
52
- return await super.getKey(protectedHeader, token);
51
+ return await this._local(protectedHeader, token);
53
52
  }
54
53
  catch (err) {
55
54
  if (err instanceof JWKSNoMatchingKey) {
56
55
  if (this.coolingDown() === false) {
57
56
  await this.reload();
58
- return super.getKey(protectedHeader, token);
57
+ return this._local(protectedHeader, token);
59
58
  }
60
59
  }
61
60
  throw err;
@@ -72,10 +71,7 @@ class RemoteJWKSet extends LocalJWKSet {
72
71
  }
73
72
  this._pendingFetch ||= fetchJwks(this._url, this._timeoutDuration, this._options)
74
73
  .then((json) => {
75
- if (!isJWKSLike(json)) {
76
- throw new JWKSInvalid('JSON Web Key Set malformed');
77
- }
78
- this._jwks = { keys: json.keys };
74
+ this._local = createLocalJWKSet(json);
79
75
  this._jwksTimestamp = Date.now();
80
76
  this._pendingFetch = undefined;
81
77
  })
@@ -73,7 +73,7 @@ async function decryptKeyManagement(alg, key, encryptedKey, joseHeader, options)
73
73
  throw new JWEInvalid('JWE Encrypted Key missing');
74
74
  if (typeof joseHeader.p2c !== 'number')
75
75
  throw new JWEInvalid(`JOSE Header "p2c" (PBES2 Count) missing or invalid`);
76
- const p2cLimit = options?.maxPBES2Count || 10000;
76
+ const p2cLimit = options?.maxPBES2Count || 10_000;
77
77
  if (joseHeader.p2c > p2cLimit)
78
78
  throw new JWEInvalid(`JOSE Header "p2c" (PBES2 Count) out is of acceptable bounds`);
79
79
  if (typeof joseHeader.p2s !== 'string')
@@ -1,7 +1,5 @@
1
1
  import type { KeyLike, JWSHeaderParameters, JSONWebKeySet, FlattenedJWSInput } from '../types';
2
2
  /** @private */
3
- export declare function isJWKSLike(jwks: unknown): jwks is JSONWebKeySet;
4
- /** @private */
5
3
  export declare class LocalJWKSet<KeyLikeType extends KeyLike = KeyLike> {
6
4
  protected _jwks?: JSONWebKeySet;
7
5
  private _cached;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jose",
3
- "version": "5.2.3",
3
+ "version": "5.2.4",
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",
@@ -65,6 +65,7 @@
65
65
  "deno": "./dist/browser/index.js",
66
66
  "browser": "./dist/browser/index.js",
67
67
  "worker": "./dist/browser/index.js",
68
+ "workerd": "./dist/browser/index.js",
68
69
  "import": "./dist/node/esm/index.js",
69
70
  "require": "./dist/node/cjs/index.js"
70
71
  },
@@ -74,6 +75,7 @@
74
75
  "deno": "./dist/browser/util/errors.js",
75
76
  "browser": "./dist/browser/util/errors.js",
76
77
  "worker": "./dist/browser/util/errors.js",
78
+ "workerd": "./dist/browser/util/errors.js",
77
79
  "import": "./dist/node/esm/util/errors.js",
78
80
  "require": "./dist/node/cjs/util/errors.js"
79
81
  },
@@ -83,6 +85,7 @@
83
85
  "deno": "./dist/browser/util/base64url.js",
84
86
  "browser": "./dist/browser/util/base64url.js",
85
87
  "worker": "./dist/browser/util/base64url.js",
88
+ "workerd": "./dist/browser/util/base64url.js",
86
89
  "import": "./dist/node/esm/util/base64url.js",
87
90
  "require": "./dist/node/cjs/util/base64url.js"
88
91
  },