jose 4.1.0 → 4.1.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.
@@ -1,4 +1,4 @@
1
- import { isCloudflareWorkers, isNodeJs } from '../runtime/global.js';
1
+ import { isCloudflareWorkers, isNodeJs } from '../runtime/env.js';
2
2
  function unusable(name, prop = 'algorithm.name') {
3
3
  return new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
4
4
  }
@@ -1,4 +1,4 @@
1
- import globalThis, { isCloudflareWorkers, isNodeJs } from './global.js';
1
+ import { isCloudflareWorkers, isNodeJs } from './env.js';
2
2
  import crypto, { isCryptoKey } from './webcrypto.js';
3
3
  import invalidKeyInput from '../lib/invalid_key_input.js';
4
4
  import { encodeBase64 } from './base64url.js';
@@ -54,8 +54,7 @@ const genericImport = async (replace, keyFormat, pem, alg, options) => {
54
54
  var _a;
55
55
  let algorithm;
56
56
  let keyUsages;
57
- const keyData = new Uint8Array(globalThis
58
- .atob(pem.replace(replace, ''))
57
+ const keyData = new Uint8Array(atob(pem.replace(replace, ''))
59
58
  .split('')
60
59
  .map((c) => c.charCodeAt(0)));
61
60
  const isPublic = keyFormat === 'spki';
@@ -1,5 +1,4 @@
1
1
  import { encoder, decoder } from '../lib/buffer_utils.js';
2
- import globalThis from './global.js';
3
2
  export const encodeBase64 = (input) => {
4
3
  let unencoded = input;
5
4
  if (typeof unencoded === 'string') {
@@ -10,14 +9,13 @@ export const encodeBase64 = (input) => {
10
9
  for (let i = 0; i < unencoded.length; i += CHUNK_SIZE) {
11
10
  arr.push(String.fromCharCode.apply(null, unencoded.subarray(i, i + CHUNK_SIZE)));
12
11
  }
13
- return globalThis.btoa(arr.join(''));
12
+ return btoa(arr.join(''));
14
13
  };
15
14
  export const encode = (input) => {
16
15
  return encodeBase64(input).replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
17
16
  };
18
17
  export const decodeBase64 = (encoded) => {
19
- return new Uint8Array(globalThis
20
- .atob(encoded)
18
+ return new Uint8Array(atob(encoded)
21
19
  .split('')
22
20
  .map((c) => c.charCodeAt(0)));
23
21
  };
@@ -1,11 +1,4 @@
1
1
  export default (alg, key) => {
2
- if (alg.startsWith('HS')) {
3
- const bitlen = parseInt(alg.substr(-3), 10);
4
- const { length } = key.algorithm;
5
- if (typeof length !== 'number' || length < bitlen) {
6
- throw new TypeError(`${alg} requires symmetric keys to be ${bitlen} bits or larger`);
7
- }
8
- }
9
2
  if (alg.startsWith('RS') || alg.startsWith('PS')) {
10
3
  const { modulusLength } = key.algorithm;
11
4
  if (typeof modulusLength !== 'number' || modulusLength < 2048) {
@@ -0,0 +1,11 @@
1
+ export function isCloudflareWorkers() {
2
+ return typeof WebSocketPair === 'function';
3
+ }
4
+ export function isNodeJs() {
5
+ try {
6
+ return process.versions.node !== undefined;
7
+ }
8
+ catch (_a) {
9
+ return false;
10
+ }
11
+ }
@@ -1,5 +1,5 @@
1
1
  import { JOSEError, JWKSTimeout } from '../util/errors.js';
2
- import globalThis, { isCloudflareWorkers } from './global.js';
2
+ import { isCloudflareWorkers } from './env.js';
3
3
  const fetchJwks = async (url, timeout) => {
4
4
  let controller;
5
5
  let id;
@@ -11,8 +11,7 @@ const fetchJwks = async (url, timeout) => {
11
11
  controller.abort();
12
12
  }, timeout);
13
13
  }
14
- const response = await globalThis
15
- .fetch(url.href, {
14
+ const response = await fetch(url.href, {
16
15
  signal: controller ? controller.signal : undefined,
17
16
  redirect: 'manual',
18
17
  method: 'GET',
@@ -23,8 +22,7 @@ const fetchJwks = async (url, timeout) => {
23
22
  mode: 'cors',
24
23
  }
25
24
  : undefined),
26
- })
27
- .catch((err) => {
25
+ }).catch((err) => {
28
26
  if (timedOut)
29
27
  throw new JWKSTimeout();
30
28
  throw err;
@@ -1,4 +1,4 @@
1
- import { isCloudflareWorkers, isNodeJs } from './global.js';
1
+ import { isCloudflareWorkers, isNodeJs } from './env.js';
2
2
  import crypto from './webcrypto.js';
3
3
  import { JOSENotSupported } from '../util/errors.js';
4
4
  import random from './random.js';
@@ -1,4 +1,4 @@
1
- import { isCloudflareWorkers, isNodeJs } from './global.js';
1
+ import { isCloudflareWorkers, isNodeJs } from './env.js';
2
2
  import crypto from './webcrypto.js';
3
3
  import { JOSENotSupported } from '../util/errors.js';
4
4
  import { decode as base64url } from './base64url.js';
@@ -1,4 +1,4 @@
1
- import { isCloudflareWorkers, isNodeJs } from './global.js';
1
+ import { isCloudflareWorkers, isNodeJs } from './env.js';
2
2
  import { JOSENotSupported } from '../util/errors.js';
3
3
  export default function subtleDsa(alg, namedCurve) {
4
4
  const length = parseInt(alg.substr(-3), 10);
@@ -1,8 +1,12 @@
1
- import globalThis from './global.js';
2
- export default globalThis.crypto;
1
+ export default crypto;
3
2
  export function isCryptoKey(key) {
4
- if (typeof globalThis.CryptoKey === 'undefined') {
3
+ try {
4
+ return (key != null &&
5
+ typeof key.extractable === 'boolean' &&
6
+ typeof key.algorithm.name === 'string' &&
7
+ typeof key.type === 'string');
8
+ }
9
+ catch (_a) {
5
10
  return false;
6
11
  }
7
- return key != null && key instanceof globalThis.CryptoKey;
8
12
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.checkEncCryptoKey = exports.checkSigCryptoKey = void 0;
4
- const global_js_1 = require("../runtime/global.js");
4
+ const env_js_1 = require("../runtime/env.js");
5
5
  function unusable(name, prop = 'algorithm.name') {
6
6
  return new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
7
7
  }
@@ -74,12 +74,12 @@ function checkSigCryptoKey(key, alg, ...usages) {
74
74
  throw unusable(`SHA-${expected}`, 'algorithm.hash');
75
75
  break;
76
76
  }
77
- case (0, global_js_1.isNodeJs)() && 'EdDSA': {
77
+ case (0, env_js_1.isNodeJs)() && 'EdDSA': {
78
78
  if (key.algorithm.name !== 'NODE-ED25519' && key.algorithm.name !== 'NODE-ED448')
79
79
  throw unusable('NODE-ED25519 or NODE-ED448');
80
80
  break;
81
81
  }
82
- case (0, global_js_1.isCloudflareWorkers)() && 'EdDSA': {
82
+ case (0, env_js_1.isCloudflareWorkers)() && 'EdDSA': {
83
83
  if (!isAlgorithm(key.algorithm, 'NODE-ED25519'))
84
84
  throw unusable('NODE-ED25519');
85
85
  break;
File without changes
@@ -16,10 +16,6 @@ else {
16
16
  const sign = async (alg, key, data) => {
17
17
  const keyObject = (0, get_sign_verify_key_js_1.default)(alg, key, 'sign');
18
18
  if (alg.startsWith('HS')) {
19
- const bitlen = parseInt(alg.substr(-3), 10);
20
- if (!keyObject.symmetricKeySize || keyObject.symmetricKeySize << 3 < bitlen) {
21
- throw new TypeError(`${alg} requires symmetric keys to be ${bitlen} bits or larger`);
22
- }
23
19
  const hmac = crypto.createHmac((0, hmac_digest_js_1.default)(alg), keyObject);
24
20
  hmac.update(data);
25
21
  return hmac.digest();
@@ -1,4 +1,4 @@
1
- import { isCloudflareWorkers, isNodeJs } from '../runtime/global.js';
1
+ import { isCloudflareWorkers, isNodeJs } from '../runtime/env.js';
2
2
  function unusable(name, prop = 'algorithm.name') {
3
3
  return new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
4
4
  }
File without changes
@@ -14,10 +14,6 @@ else {
14
14
  const sign = async (alg, key, data) => {
15
15
  const keyObject = getSignKey(alg, key, 'sign');
16
16
  if (alg.startsWith('HS')) {
17
- const bitlen = parseInt(alg.substr(-3), 10);
18
- if (!keyObject.symmetricKeySize || keyObject.symmetricKeySize << 3 < bitlen) {
19
- throw new TypeError(`${alg} requires symmetric keys to be ${bitlen} bits or larger`);
20
- }
21
17
  const hmac = crypto.createHmac(hmacDigest(alg), keyObject);
22
18
  hmac.update(data);
23
19
  return hmac.digest();
@@ -4,4 +4,8 @@ export interface RemoteJWKSetOptions {
4
4
  cooldownDuration?: number;
5
5
  agent?: any;
6
6
  }
7
+ interface URL {
8
+ href: string;
9
+ }
7
10
  export declare function createRemoteJWKSet(url: URL, options?: RemoteJWKSetOptions): GetKeyFunction<JWSHeaderParameters, FlattenedJWSInput>;
11
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jose",
3
- "version": "4.1.0",
3
+ "version": "4.1.4",
4
4
  "description": "'JSON Web Almost Everything' - JWA, JWS, JWE, JWT, JWK, JWKS with no dependencies using runtime's native crypto",
5
5
  "keywords": [
6
6
  "browser",
@@ -1,27 +0,0 @@
1
- function getGlobal() {
2
- if (typeof globalThis !== 'undefined')
3
- return globalThis;
4
- if (typeof self !== 'undefined')
5
- return self;
6
- if (typeof window !== 'undefined')
7
- return window;
8
- throw new Error('unable to locate global object');
9
- }
10
- export default getGlobal();
11
- export function isCloudflareWorkers() {
12
- try {
13
- return getGlobal().WebSocketPair !== undefined;
14
- }
15
- catch (_a) {
16
- return false;
17
- }
18
- }
19
- export function isNodeJs() {
20
- var _a, _b;
21
- try {
22
- return ((_b = (_a = getGlobal().process) === null || _a === void 0 ? void 0 : _a.versions) === null || _b === void 0 ? void 0 : _b.node) !== undefined;
23
- }
24
- catch (_c) {
25
- return false;
26
- }
27
- }