jose 4.14.2 → 4.14.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.
package/README.md CHANGED
@@ -129,4 +129,4 @@ Please note that certain algorithms may not be available depending on the runtim
129
129
  | Version | Security Fixes 🔑 | Other Bug Fixes 🐞 | New Features ⭐ |
130
130
  | ------- | --------- | -------- | -------- |
131
131
  | [v4.x](https://github.com/panva/jose/tree/v4.x) | ✅ | ✅ | ✅ |
132
- | [v3.x](https://github.com/panva/jose/tree/v3.x), [v2.x](https://github.com/panva/jose/tree/v2.x), [v1.x](https://github.com/panva/jose/tree/v1.x) | ✅ | ❌ | ❌ |
132
+ | [v2.x](https://github.com/panva/jose/tree/v2.x) | ✅ | ❌ | ❌ |
@@ -1,7 +1,11 @@
1
1
  import fetchJwks from '../runtime/fetch_jwks.js';
2
- import { isCloudflareWorkers } from '../runtime/env.js';
3
2
  import { JWKSInvalid, JWKSNoMatchingKey } from '../util/errors.js';
4
3
  import { isJWKSLike, LocalJWKSet } from './local.js';
4
+ function isCloudflareWorkers() {
5
+ return (typeof WebSocketPair !== 'undefined' ||
6
+ (typeof navigator !== 'undefined' && navigator.userAgent === 'Cloudflare-Workers') ||
7
+ (typeof EdgeRuntime !== 'undefined' && EdgeRuntime === 'vercel'));
8
+ }
5
9
  class RemoteJWKSet extends LocalJWKSet {
6
10
  constructor(url, options) {
7
11
  super({ keys: [] });
@@ -1,4 +1,3 @@
1
- import { isCloudflareWorkers } from '../runtime/env.js';
2
1
  function unusable(name, prop = 'algorithm.name') {
3
2
  return new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
4
3
  }
@@ -73,11 +72,6 @@ export function checkSigCryptoKey(key, alg, ...usages) {
73
72
  }
74
73
  case 'EdDSA': {
75
74
  if (key.algorithm.name !== 'Ed25519' && key.algorithm.name !== 'Ed448') {
76
- if (isCloudflareWorkers()) {
77
- if (isAlgorithm(key.algorithm, 'NODE-ED25519'))
78
- break;
79
- throw unusable('Ed25519, Ed448, or NODE-ED25519');
80
- }
81
75
  throw unusable('Ed25519 or Ed448');
82
76
  }
83
77
  break;
@@ -1,4 +1,3 @@
1
- import { isCloudflareWorkers } from './env.js';
2
1
  import crypto, { isCryptoKey } from './webcrypto.js';
3
2
  import invalidKeyInput from '../lib/invalid_key_input.js';
4
3
  import { encodeBase64, decodeBase64 } from './base64url.js';
@@ -57,7 +56,7 @@ const getNamedCurve = (keyData) => {
57
56
  }
58
57
  };
59
58
  const genericImport = async (replace, keyFormat, pem, alg, options) => {
60
- var _a, _b;
59
+ var _a;
61
60
  let algorithm;
62
61
  let keyUsages;
63
62
  const keyData = new Uint8Array(atob(pem.replace(replace, ''))
@@ -115,18 +114,7 @@ const genericImport = async (replace, keyFormat, pem, alg, options) => {
115
114
  default:
116
115
  throw new JOSENotSupported('Invalid or unsupported "alg" (Algorithm) value');
117
116
  }
118
- try {
119
- return await crypto.subtle.importKey(keyFormat, keyData, algorithm, (_a = options === null || options === void 0 ? void 0 : options.extractable) !== null && _a !== void 0 ? _a : false, keyUsages);
120
- }
121
- catch (err) {
122
- if (algorithm.name === 'Ed25519' &&
123
- (err === null || err === void 0 ? void 0 : err.name) === 'NotSupportedError' &&
124
- isCloudflareWorkers()) {
125
- algorithm = { name: 'NODE-ED25519', namedCurve: 'NODE-ED25519' };
126
- return await crypto.subtle.importKey(keyFormat, keyData, algorithm, (_b = options === null || options === void 0 ? void 0 : options.extractable) !== null && _b !== void 0 ? _b : false, keyUsages);
127
- }
128
- throw err;
129
- }
117
+ return crypto.subtle.importKey(keyFormat, keyData, algorithm, (_a = options === null || options === void 0 ? void 0 : options.extractable) !== null && _a !== void 0 ? _a : false, keyUsages);
130
118
  };
131
119
  export const fromPKCS8 = (pem, alg, options) => {
132
120
  return genericImport(/(?:-----(?:BEGIN|END) PRIVATE KEY-----|\s)/g, 'pkcs8', pem, alg, options);
@@ -1,4 +1,3 @@
1
- import { isCloudflareWorkers } from './env.js';
2
1
  import crypto from './webcrypto.js';
3
2
  import { JOSENotSupported } from '../util/errors.js';
4
3
  import random from './random.js';
@@ -51,7 +50,7 @@ function getModulusLengthOption(options) {
51
50
  return modulusLength;
52
51
  }
53
52
  export async function generateKeyPair(alg, options) {
54
- var _a, _b, _c, _d;
53
+ var _a, _b, _c;
55
54
  let algorithm;
56
55
  let keyUsages;
57
56
  switch (alg) {
@@ -138,16 +137,5 @@ export async function generateKeyPair(alg, options) {
138
137
  default:
139
138
  throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
140
139
  }
141
- try {
142
- return (await crypto.subtle.generateKey(algorithm, (_c = options === null || options === void 0 ? void 0 : options.extractable) !== null && _c !== void 0 ? _c : false, keyUsages));
143
- }
144
- catch (err) {
145
- if (algorithm.name === 'Ed25519' &&
146
- (err === null || err === void 0 ? void 0 : err.name) === 'NotSupportedError' &&
147
- isCloudflareWorkers()) {
148
- algorithm = { name: 'NODE-ED25519', namedCurve: 'NODE-ED25519' };
149
- return (await crypto.subtle.generateKey(algorithm, (_d = options === null || options === void 0 ? void 0 : options.extractable) !== null && _d !== void 0 ? _d : false, keyUsages));
150
- }
151
- throw err;
152
- }
140
+ return (crypto.subtle.generateKey(algorithm, (_c = options === null || options === void 0 ? void 0 : options.extractable) !== null && _c !== void 0 ? _c : false, keyUsages));
153
141
  }
@@ -1,4 +1,3 @@
1
- import { isCloudflareWorkers } from './env.js';
2
1
  import crypto from './webcrypto.js';
3
2
  import { JOSENotSupported } from '../util/errors.js';
4
3
  import { decode as base64url } from './base64url.js';
@@ -139,17 +138,6 @@ const parse = async (jwk) => {
139
138
  const keyData = { ...jwk };
140
139
  delete keyData.alg;
141
140
  delete keyData.use;
142
- try {
143
- return await crypto.subtle.importKey('jwk', keyData, ...rest);
144
- }
145
- catch (err) {
146
- if (algorithm.name === 'Ed25519' &&
147
- (err === null || err === void 0 ? void 0 : err.name) === 'NotSupportedError' &&
148
- isCloudflareWorkers()) {
149
- rest[0] = { name: 'NODE-ED25519', namedCurve: 'NODE-ED25519' };
150
- return await crypto.subtle.importKey('jwk', keyData, ...rest);
151
- }
152
- throw err;
153
- }
141
+ return crypto.subtle.importKey('jwk', keyData, ...rest);
154
142
  };
155
143
  export default parse;
@@ -1,4 +1,3 @@
1
- import { isCloudflareWorkers } from './env.js';
2
1
  import { JOSENotSupported } from '../util/errors.js';
3
2
  export default function subtleDsa(alg, algorithm) {
4
3
  const hash = `SHA-${alg.slice(-3)}`;
@@ -20,9 +19,6 @@ export default function subtleDsa(alg, algorithm) {
20
19
  case 'ES512':
21
20
  return { hash, name: 'ECDSA', namedCurve: algorithm.namedCurve };
22
21
  case 'EdDSA':
23
- if (isCloudflareWorkers() && algorithm.name === 'NODE-ED25519') {
24
- return { name: 'NODE-ED25519', namedCurve: 'NODE-ED25519' };
25
- }
26
22
  return { name: algorithm.name };
27
23
  default:
28
24
  throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
@@ -2,9 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createRemoteJWKSet = void 0;
4
4
  const fetch_jwks_js_1 = require("../runtime/fetch_jwks.js");
5
- const env_js_1 = require("../runtime/env.js");
6
5
  const errors_js_1 = require("../util/errors.js");
7
6
  const local_js_1 = require("./local.js");
7
+ function isCloudflareWorkers() {
8
+ return (typeof WebSocketPair !== 'undefined' ||
9
+ (typeof navigator !== 'undefined' && navigator.userAgent === 'Cloudflare-Workers') ||
10
+ (typeof EdgeRuntime !== 'undefined' && EdgeRuntime === 'vercel'));
11
+ }
8
12
  class RemoteJWKSet extends local_js_1.LocalJWKSet {
9
13
  constructor(url, options) {
10
14
  super({ keys: [] });
@@ -48,7 +52,7 @@ class RemoteJWKSet extends local_js_1.LocalJWKSet {
48
52
  }
49
53
  }
50
54
  async reload() {
51
- if (this._pendingFetch && (0, env_js_1.isCloudflareWorkers)()) {
55
+ if (this._pendingFetch && isCloudflareWorkers()) {
52
56
  this._pendingFetch = undefined;
53
57
  }
54
58
  this._pendingFetch || (this._pendingFetch = (0, fetch_jwks_js_1.default)(this._url, this._timeoutDuration, this._options)
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.checkEncCryptoKey = exports.checkSigCryptoKey = void 0;
4
- const env_js_1 = require("../runtime/env.js");
5
4
  function unusable(name, prop = 'algorithm.name') {
6
5
  return new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
7
6
  }
@@ -76,11 +75,6 @@ function checkSigCryptoKey(key, alg, ...usages) {
76
75
  }
77
76
  case 'EdDSA': {
78
77
  if (key.algorithm.name !== 'Ed25519' && key.algorithm.name !== 'Ed448') {
79
- if ((0, env_js_1.isCloudflareWorkers)()) {
80
- if (isAlgorithm(key.algorithm, 'NODE-ED25519'))
81
- break;
82
- throw unusable('Ed25519, Ed448, or NODE-ED25519');
83
- }
84
78
  throw unusable('Ed25519 or Ed448');
85
79
  }
86
80
  break;
@@ -1,7 +1,11 @@
1
1
  import fetchJwks from '../runtime/fetch_jwks.js';
2
- import { isCloudflareWorkers } from '../runtime/env.js';
3
2
  import { JWKSInvalid, JWKSNoMatchingKey } from '../util/errors.js';
4
3
  import { isJWKSLike, LocalJWKSet } from './local.js';
4
+ function isCloudflareWorkers() {
5
+ return (typeof WebSocketPair !== 'undefined' ||
6
+ (typeof navigator !== 'undefined' && navigator.userAgent === 'Cloudflare-Workers') ||
7
+ (typeof EdgeRuntime !== 'undefined' && EdgeRuntime === 'vercel'));
8
+ }
5
9
  class RemoteJWKSet extends LocalJWKSet {
6
10
  constructor(url, options) {
7
11
  super({ keys: [] });
@@ -1,4 +1,3 @@
1
- import { isCloudflareWorkers } from '../runtime/env.js';
2
1
  function unusable(name, prop = 'algorithm.name') {
3
2
  return new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
4
3
  }
@@ -73,11 +72,6 @@ export function checkSigCryptoKey(key, alg, ...usages) {
73
72
  }
74
73
  case 'EdDSA': {
75
74
  if (key.algorithm.name !== 'Ed25519' && key.algorithm.name !== 'Ed448') {
76
- if (isCloudflareWorkers()) {
77
- if (isAlgorithm(key.algorithm, 'NODE-ED25519'))
78
- break;
79
- throw unusable('Ed25519, Ed448, or NODE-ED25519');
80
- }
81
75
  throw unusable('Ed25519 or Ed448');
82
76
  }
83
77
  break;
@@ -29,11 +29,6 @@
29
29
  */
30
30
  export type KeyLike = { type: string }
31
31
 
32
- type JsonObject = { [Key in string]?: JsonValue }
33
- type JsonArray = JsonValue[]
34
- type JsonPrimitive = string | number | boolean | null
35
- type JsonValue = JsonPrimitive | JsonObject | JsonArray
36
-
37
32
  /**
38
33
  * JSON Web Key ({@link https://www.rfc-editor.org/rfc/rfc7517 JWK}). "RSA", "EC", "OKP", and "oct"
39
34
  * key types are supported.
@@ -77,7 +72,7 @@ export interface JWK {
77
72
  /** JWK "x5u" (X.509 URL) Parameter. */
78
73
  x5u?: string
79
74
 
80
- [propName: string]: JsonValue | undefined
75
+ [propName: string]: unknown
81
76
  }
82
77
 
83
78
  /**
@@ -201,7 +196,7 @@ export interface JWSHeaderParameters extends JoseHeaderParameters {
201
196
  crit?: string[]
202
197
 
203
198
  /** Any other JWS Header member. */
204
- [propName: string]: JsonValue | undefined
199
+ [propName: string]: unknown
205
200
  }
206
201
 
207
202
  /** Recognized JWE Key Management-related Header Parameters. */
@@ -309,7 +304,7 @@ export interface JWEHeaderParameters extends JoseHeaderParameters {
309
304
  zip?: string
310
305
 
311
306
  /** Any other JWE Header member. */
312
- [propName: string]: JsonValue | undefined
307
+ [propName: string]: unknown
313
308
  }
314
309
 
315
310
  /** Shared Interface with a "crit" property for all sign, verify, encrypt and decrypt operations. */
@@ -483,7 +478,7 @@ export interface JWTPayload {
483
478
  iat?: number
484
479
 
485
480
  /** Any other JWT Claim Set member. */
486
- [propName: string]: JsonValue | undefined
481
+ [propName: string]: unknown
487
482
  }
488
483
 
489
484
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jose",
3
- "version": "4.14.2",
3
+ "version": "4.14.4",
4
4
  "description": "'JSON Web Almost Everything' - 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",
@@ -20,7 +20,6 @@
20
20
  "encrypt",
21
21
  "flattened",
22
22
  "general",
23
- "isomorphic",
24
23
  "jose",
25
24
  "json web token",
26
25
  "jsonwebtoken",
@@ -43,11 +42,11 @@
43
42
  "sign",
44
43
  "signature",
45
44
  "spki",
46
- "universal",
47
45
  "validate",
48
46
  "vercel",
49
47
  "verify",
50
48
  "webcrypto",
49
+ "workerd",
51
50
  "workers",
52
51
  "x509"
53
52
  ],
@@ -1,5 +0,0 @@
1
- export function isCloudflareWorkers() {
2
- return (typeof WebSocketPair !== 'undefined' ||
3
- (typeof navigator !== 'undefined' && navigator.userAgent === 'Cloudflare-Workers') ||
4
- (typeof EdgeRuntime !== 'undefined' && EdgeRuntime === 'vercel'));
5
- }
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isCloudflareWorkers = void 0;
4
- function isCloudflareWorkers() {
5
- return false;
6
- }
7
- exports.isCloudflareWorkers = isCloudflareWorkers;
@@ -1,3 +0,0 @@
1
- export function isCloudflareWorkers() {
2
- return false;
3
- }