jose 4.5.0 → 4.5.3

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
@@ -136,16 +136,16 @@ install size should not be a cause for concern.
136
136
 
137
137
  [documentation]: /docs/README.md
138
138
  [node-jose]: https://github.com/cisco/node-jose
139
- [spec-b64]: https://tools.ietf.org/html/rfc7797
140
- [spec-cookbook]: https://tools.ietf.org/html/rfc7520
141
- [spec-jwa]: https://tools.ietf.org/html/rfc7518
142
- [spec-jwe]: https://tools.ietf.org/html/rfc7516
143
- [spec-jwk]: https://tools.ietf.org/html/rfc7517
144
- [spec-jws]: https://tools.ietf.org/html/rfc7515
145
- [spec-jwt]: https://tools.ietf.org/html/rfc7519
146
- [spec-okp]: https://tools.ietf.org/html/rfc8037
147
- [spec-secp256k1]: https://tools.ietf.org/html/rfc8812
148
- [spec-thumbprint]: https://tools.ietf.org/html/rfc7638
139
+ [spec-b64]: https://www.rfc-editor.org/rfc/rfc7797
140
+ [spec-cookbook]: https://www.rfc-editor.org/rfc/rfc7520
141
+ [spec-jwa]: https://www.rfc-editor.org/rfc/rfc7518
142
+ [spec-jwe]: https://www.rfc-editor.org/rfc/rfc7516
143
+ [spec-jwk]: https://www.rfc-editor.org/rfc/rfc7517
144
+ [spec-jws]: https://www.rfc-editor.org/rfc/rfc7515
145
+ [spec-jwt]: https://www.rfc-editor.org/rfc/rfc7519
146
+ [spec-okp]: https://www.rfc-editor.org/rfc/rfc8037
147
+ [spec-secp256k1]: https://www.rfc-editor.org/rfc/rfc8812
148
+ [spec-thumbprint]: https://www.rfc-editor.org/rfc/rfc7638
149
149
  [support-sponsor]: https://github.com/sponsors/panva
150
150
  [conditional-exports]: https://nodejs.org/api/packages.html#packages_conditional_exports
151
151
  [webcrypto]: https://www.w3.org/TR/WebCryptoAPI/
@@ -13,7 +13,7 @@ export async function compactDecrypt(jwe, key, options) {
13
13
  throw new JWEInvalid('Invalid Compact JWE');
14
14
  }
15
15
  const decrypted = await flattenedDecrypt({
16
- ciphertext: (ciphertext || undefined),
16
+ ciphertext,
17
17
  iv: (iv || undefined),
18
18
  protected: protectedHeader || undefined,
19
19
  tag: (tag || undefined),
@@ -12,6 +12,11 @@ export async function calculateJwkThumbprint(jwk, digestAlgorithm = 'sha256') {
12
12
  if (!isObject(jwk)) {
13
13
  throw new TypeError('JWK must be an object');
14
14
  }
15
+ if (digestAlgorithm !== 'sha256' &&
16
+ digestAlgorithm !== 'sha384' &&
17
+ digestAlgorithm !== 'sha512') {
18
+ throw new TypeError('digestAlgorithm must one of "sha256", "sha384", or "sha512"');
19
+ }
15
20
  let components;
16
21
  switch (jwk.kty) {
17
22
  case 'EC':
@@ -1,3 +1,4 @@
1
+ import digest from '../runtime/digest.js';
1
2
  export const encoder = new TextEncoder();
2
3
  export const decoder = new TextDecoder();
3
4
  const MAX_INT32 = 2 ** 32;
@@ -36,7 +37,7 @@ export function uint32be(value) {
36
37
  export function lengthAndInput(input) {
37
38
  return concat(uint32be(input.length), input);
38
39
  }
39
- export async function concatKdf(digest, secret, bits, value) {
40
+ export async function concatKdf(secret, bits, value) {
40
41
  const iterations = Math.ceil((bits >> 3) / 32);
41
42
  let res;
42
43
  for (let iter = 1; iter <= iterations; iter++) {
@@ -1,7 +1,6 @@
1
1
  import { encoder, concat, uint32be, lengthAndInput, concatKdf } from '../lib/buffer_utils.js';
2
2
  import crypto, { isCryptoKey } from './webcrypto.js';
3
3
  import { checkEncCryptoKey } from '../lib/crypto_key.js';
4
- import digest from './digest.js';
5
4
  import invalidKeyInput from '../lib/invalid_key_input.js';
6
5
  import { types } from './is_key_like.js';
7
6
  export async function deriveKey(publicKey, privateKey, algorithm, keyLength, apu = new Uint8Array(0), apv = new Uint8Array(0)) {
@@ -21,7 +20,7 @@ export async function deriveKey(publicKey, privateKey, algorithm, keyLength, apu
21
20
  name: 'ECDH',
22
21
  public: publicKey,
23
22
  }, privateKey, Math.ceil(parseInt(privateKey.algorithm.namedCurve.slice(-3), 10) / 8) << 3));
24
- return concatKdf(digest, sharedSecret, keyLength, value);
23
+ return concatKdf(sharedSecret, keyLength, value);
25
24
  }
26
25
  export async function generateEpk(key) {
27
26
  if (!isCryptoKey(key)) {
@@ -1,5 +1,4 @@
1
1
  import { JOSEError, JWKSTimeout } from '../util/errors.js';
2
- import { isCloudflareWorkers } from './env.js';
3
2
  const fetchJwks = async (url, timeout) => {
4
3
  let controller;
5
4
  let id;
@@ -14,14 +13,6 @@ const fetchJwks = async (url, timeout) => {
14
13
  const response = await fetch(url.href, {
15
14
  signal: controller ? controller.signal : undefined,
16
15
  redirect: 'manual',
17
- method: 'GET',
18
- ...(!isCloudflareWorkers()
19
- ? {
20
- referrerPolicy: 'no-referrer',
21
- credentials: 'omit',
22
- mode: 'cors',
23
- }
24
- : undefined),
25
16
  }).catch((err) => {
26
17
  if (timedOut)
27
18
  throw new JWKSTimeout();
@@ -16,7 +16,7 @@ async function compactDecrypt(jwe, key, options) {
16
16
  throw new errors_js_1.JWEInvalid('Invalid Compact JWE');
17
17
  }
18
18
  const decrypted = await (0, decrypt_js_1.flattenedDecrypt)({
19
- ciphertext: (ciphertext || undefined),
19
+ ciphertext,
20
20
  iv: (iv || undefined),
21
21
  protected: protectedHeader || undefined,
22
22
  tag: (tag || undefined),
@@ -15,6 +15,11 @@ async function calculateJwkThumbprint(jwk, digestAlgorithm = 'sha256') {
15
15
  if (!(0, is_object_js_1.default)(jwk)) {
16
16
  throw new TypeError('JWK must be an object');
17
17
  }
18
+ if (digestAlgorithm !== 'sha256' &&
19
+ digestAlgorithm !== 'sha384' &&
20
+ digestAlgorithm !== 'sha512') {
21
+ throw new TypeError('digestAlgorithm must one of "sha256", "sha384", or "sha512"');
22
+ }
18
23
  let components;
19
24
  switch (jwk.kty) {
20
25
  case 'EC':
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.concatKdf = exports.lengthAndInput = exports.uint32be = exports.uint64be = exports.p2s = exports.concat = exports.decoder = exports.encoder = void 0;
4
+ const digest_js_1 = require("../runtime/digest.js");
4
5
  exports.encoder = new TextEncoder();
5
6
  exports.decoder = new TextDecoder();
6
7
  const MAX_INT32 = 2 ** 32;
@@ -44,7 +45,7 @@ function lengthAndInput(input) {
44
45
  return concat(uint32be(input.length), input);
45
46
  }
46
47
  exports.lengthAndInput = lengthAndInput;
47
- async function concatKdf(digest, secret, bits, value) {
48
+ async function concatKdf(secret, bits, value) {
48
49
  const iterations = Math.ceil((bits >> 3) / 32);
49
50
  let res;
50
51
  for (let iter = 1; iter <= iterations; iter++) {
@@ -53,10 +54,10 @@ async function concatKdf(digest, secret, bits, value) {
53
54
  buf.set(secret, 4);
54
55
  buf.set(value, 4 + secret.length);
55
56
  if (!res) {
56
- res = await digest('sha256', buf);
57
+ res = await (0, digest_js_1.default)('sha256', buf);
57
58
  }
58
59
  else {
59
- res = concat(res, await digest('sha256', buf));
60
+ res = concat(res, await (0, digest_js_1.default)('sha256', buf));
60
61
  }
61
62
  }
62
63
  res = res.slice(0, bits >> 3);
@@ -5,7 +5,6 @@ const crypto_1 = require("crypto");
5
5
  const util_1 = require("util");
6
6
  const get_named_curve_js_1 = require("./get_named_curve.js");
7
7
  const buffer_utils_js_1 = require("../lib/buffer_utils.js");
8
- const digest_js_1 = require("./digest.js");
9
8
  const errors_js_1 = require("../util/errors.js");
10
9
  const webcrypto_js_1 = require("./webcrypto.js");
11
10
  const crypto_key_js_1 = require("../lib/crypto_key.js");
@@ -38,7 +37,7 @@ async function deriveKey(publicKee, privateKee, algorithm, keyLength, apu = new
38
37
  }
39
38
  const value = (0, buffer_utils_js_1.concat)((0, buffer_utils_js_1.lengthAndInput)(buffer_utils_js_1.encoder.encode(algorithm)), (0, buffer_utils_js_1.lengthAndInput)(apu), (0, buffer_utils_js_1.lengthAndInput)(apv), (0, buffer_utils_js_1.uint32be)(keyLength));
40
39
  const sharedSecret = (0, crypto_1.diffieHellman)({ privateKey, publicKey });
41
- return (0, buffer_utils_js_1.concatKdf)(digest_js_1.default, sharedSecret, keyLength, value);
40
+ return (0, buffer_utils_js_1.concatKdf)(sharedSecret, keyLength, value);
42
41
  }
43
42
  exports.deriveKey = deriveKey;
44
43
  async function generateEpk(kee) {
@@ -13,7 +13,7 @@ export async function compactDecrypt(jwe, key, options) {
13
13
  throw new JWEInvalid('Invalid Compact JWE');
14
14
  }
15
15
  const decrypted = await flattenedDecrypt({
16
- ciphertext: (ciphertext || undefined),
16
+ ciphertext,
17
17
  iv: (iv || undefined),
18
18
  protected: protectedHeader || undefined,
19
19
  tag: (tag || undefined),
@@ -12,6 +12,11 @@ export async function calculateJwkThumbprint(jwk, digestAlgorithm = 'sha256') {
12
12
  if (!isObject(jwk)) {
13
13
  throw new TypeError('JWK must be an object');
14
14
  }
15
+ if (digestAlgorithm !== 'sha256' &&
16
+ digestAlgorithm !== 'sha384' &&
17
+ digestAlgorithm !== 'sha512') {
18
+ throw new TypeError('digestAlgorithm must one of "sha256", "sha384", or "sha512"');
19
+ }
15
20
  let components;
16
21
  switch (jwk.kty) {
17
22
  case 'EC':
@@ -1,3 +1,4 @@
1
+ import digest from '../runtime/digest.js';
1
2
  export const encoder = new TextEncoder();
2
3
  export const decoder = new TextDecoder();
3
4
  const MAX_INT32 = 2 ** 32;
@@ -36,7 +37,7 @@ export function uint32be(value) {
36
37
  export function lengthAndInput(input) {
37
38
  return concat(uint32be(input.length), input);
38
39
  }
39
- export async function concatKdf(digest, secret, bits, value) {
40
+ export async function concatKdf(secret, bits, value) {
40
41
  const iterations = Math.ceil((bits >> 3) / 32);
41
42
  let res;
42
43
  for (let iter = 1; iter <= iterations; iter++) {
@@ -2,7 +2,6 @@ import { diffieHellman, generateKeyPair as generateKeyPairCb, KeyObject } from '
2
2
  import { promisify } from 'util';
3
3
  import getNamedCurve from './get_named_curve.js';
4
4
  import { encoder, concat, uint32be, lengthAndInput, concatKdf } from '../lib/buffer_utils.js';
5
- import digest from './digest.js';
6
5
  import { JOSENotSupported } from '../util/errors.js';
7
6
  import { isCryptoKey } from './webcrypto.js';
8
7
  import { checkEncCryptoKey } from '../lib/crypto_key.js';
@@ -35,7 +34,7 @@ export async function deriveKey(publicKee, privateKee, algorithm, keyLength, apu
35
34
  }
36
35
  const value = concat(lengthAndInput(encoder.encode(algorithm)), lengthAndInput(apu), lengthAndInput(apv), uint32be(keyLength));
37
36
  const sharedSecret = diffieHellman({ privateKey, publicKey });
38
- return concatKdf(digest, sharedSecret, keyLength, value);
37
+ return concatKdf(sharedSecret, keyLength, value);
39
38
  }
40
39
  export async function generateEpk(kee) {
41
40
  let key;
@@ -118,7 +118,7 @@ export interface JWK {
118
118
  [propName: string]: unknown
119
119
  }
120
120
  export interface GetKeyFunction<T, T2> {
121
- (protectedHeader: T, token: T2): Promise<KeyLike | Uint8Array>
121
+ (protectedHeader: T, token: T2): Promise<KeyLike | Uint8Array> | KeyLike | Uint8Array
122
122
  }
123
123
  export interface FlattenedJWSInput {
124
124
  header?: JWSHeaderParameters
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jose",
3
- "version": "4.5.0",
3
+ "version": "4.5.3",
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",