jose 3.12.0 → 3.13.0

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,6 +1,6 @@
1
1
  import parseJWK from '../jwk/parse.js';
2
2
  import { JWKSInvalid, JOSENotSupported, JWKSNoMatchingKey, JWKSMultipleMatchingKeys, } from '../util/errors.js';
3
- import fetchJson from '../runtime/fetch.js';
3
+ import fetchJwks from '../runtime/fetch_jwks.js';
4
4
  import isObject from '../lib/is_object.js';
5
5
  function getKtyFromAlg(alg) {
6
6
  switch (alg.substr(0, 2)) {
@@ -103,7 +103,7 @@ class RemoteJWKSet {
103
103
  }
104
104
  async reload() {
105
105
  if (!this._pendingFetch) {
106
- this._pendingFetch = fetchJson(this._url, this._timeoutDuration, this._options)
106
+ this._pendingFetch = fetchJwks(this._url, this._timeoutDuration, this._options)
107
107
  .then((json) => {
108
108
  if (typeof json !== 'object' ||
109
109
  !json ||
@@ -1,6 +1,6 @@
1
1
  import { JOSEError } from '../util/errors.js';
2
2
  import globalThis from './global.js';
3
- const fetch = async (url, timeout) => {
3
+ const fetchJwks = async (url, timeout) => {
4
4
  let controller;
5
5
  if (typeof AbortController === 'function') {
6
6
  controller = new AbortController();
@@ -24,4 +24,4 @@ const fetch = async (url, timeout) => {
24
24
  throw new JOSEError('Failed to parse the JSON Web Key Set HTTP response as JSON');
25
25
  }
26
26
  };
27
- export default fetch;
27
+ export default fetchJwks;
@@ -1,4 +1,3 @@
1
- import { ok as assert } from 'assert';
2
1
  import { decode as base64url } from './base64url.js';
3
2
  import { decoder } from '../lib/buffer_utils.js';
4
3
  import isObject from '../lib/is_object.js';
@@ -20,9 +19,13 @@ function decodeProtectedHeader(token) {
20
19
  }
21
20
  }
22
21
  try {
23
- assert(typeof protectedB64u === 'string' && protectedB64u);
22
+ if (typeof protectedB64u !== 'string' || !protectedB64u) {
23
+ throw new Error();
24
+ }
24
25
  const result = JSON.parse(decoder.decode(base64url(protectedB64u)));
25
- assert(isObject(result));
26
+ if (!isObject(result)) {
27
+ throw new Error();
28
+ }
26
29
  return result;
27
30
  }
28
31
  catch (err) {
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createRemoteJWKSet = void 0;
4
4
  const parse_js_1 = require("../jwk/parse.js");
5
5
  const errors_js_1 = require("../util/errors.js");
6
- const fetch_js_1 = require("../runtime/fetch.js");
6
+ const fetch_jwks_js_1 = require("../runtime/fetch_jwks.js");
7
7
  const is_object_js_1 = require("../lib/is_object.js");
8
8
  function getKtyFromAlg(alg) {
9
9
  switch (alg.substr(0, 2)) {
@@ -106,7 +106,7 @@ class RemoteJWKSet {
106
106
  }
107
107
  async reload() {
108
108
  if (!this._pendingFetch) {
109
- this._pendingFetch = fetch_js_1.default(this._url, this._timeoutDuration, this._options)
109
+ this._pendingFetch = fetch_jwks_js_1.default(this._url, this._timeoutDuration, this._options)
110
110
  .then((json) => {
111
111
  if (typeof json !== 'object' ||
112
112
  !json ||
@@ -9,7 +9,7 @@ const protocols = {
9
9
  'https:': https_1.get,
10
10
  'http:': http_1.get,
11
11
  };
12
- const fetch = async (url, timeout, options) => {
12
+ const fetchJwks = async (url, timeout, options) => {
13
13
  if (protocols[url.protocol] === undefined) {
14
14
  throw new TypeError('Unsupported URL protocol.');
15
15
  }
@@ -33,4 +33,4 @@ const fetch = async (url, timeout, options) => {
33
33
  throw new errors_js_1.JOSEError('Failed to parse the JSON Web Key Set HTTP response as JSON');
34
34
  }
35
35
  };
36
- exports.default = fetch;
36
+ exports.default = fetchJwks;
@@ -21,7 +21,7 @@ const namedCurveToJOSE = (namedCurve) => {
21
21
  case 'secp256k1':
22
22
  return namedCurve;
23
23
  default:
24
- throw new errors_js_1.JOSENotSupported('unsupported curve for this operation');
24
+ throw new errors_js_1.JOSENotSupported('unsupported key curve for this operation');
25
25
  }
26
26
  };
27
27
  const getNamedCurve = (key, raw) => {
@@ -67,6 +67,9 @@ const getNamedCurve = (key, raw) => {
67
67
  else if (curveOid.equals(secp256k1)) {
68
68
  namedCurve = 'secp256k1';
69
69
  }
70
+ else {
71
+ throw new errors_js_1.JOSENotSupported('unsupported key curve for this operation');
72
+ }
70
73
  }
71
74
  if (raw)
72
75
  return namedCurve;
@@ -1,7 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const crypto_1 = require("crypto");
4
- function isKeyObject(obj) {
5
- return obj != null && obj instanceof crypto_1.KeyObject;
4
+ const util = require("util");
5
+ let impl;
6
+ if (util.types.isKeyObject) {
7
+ impl = function isKeyObject(obj) {
8
+ return util.types.isKeyObject(obj);
9
+ };
6
10
  }
7
- exports.default = isKeyObject;
11
+ else {
12
+ impl = function isKeyObject(obj) {
13
+ return obj != null && obj instanceof crypto_1.KeyObject;
14
+ };
15
+ }
16
+ exports.default = impl;
@@ -6,9 +6,12 @@ const dsa_digest_js_1 = require("./dsa_digest.js");
6
6
  const hmac_digest_js_1 = require("./hmac_digest.js");
7
7
  const node_key_js_1 = require("./node_key.js");
8
8
  const get_sign_verify_key_js_1 = require("./get_sign_verify_key.js");
9
- let oneShotSign = crypto.sign;
10
- if (oneShotSign.length > 3) {
11
- oneShotSign = util_1.promisify(oneShotSign);
9
+ let oneShotSign;
10
+ if (crypto.sign.length > 3) {
11
+ oneShotSign = util_1.promisify(crypto.sign);
12
+ }
13
+ else {
14
+ oneShotSign = crypto.sign;
12
15
  }
13
16
  const sign = async (alg, key, data) => {
14
17
  const keyObject = get_sign_verify_key_js_1.default(alg, key, 'sign');
@@ -11,9 +11,12 @@ const [major, minor] = process.version
11
11
  .split('.')
12
12
  .map((str) => parseInt(str, 10));
13
13
  const oneShotCallbackSupported = major >= 16 || (major === 15 && minor >= 13);
14
- let oneShotVerify = crypto.verify;
15
- if (oneShotVerify.length > 4 && oneShotCallbackSupported) {
16
- oneShotVerify = util_1.promisify(oneShotVerify);
14
+ let oneShotVerify;
15
+ if (crypto.verify.length > 4 && oneShotCallbackSupported) {
16
+ oneShotVerify = util_1.promisify(crypto.verify);
17
+ }
18
+ else {
19
+ oneShotVerify = crypto.verify;
17
20
  }
18
21
  const verify = async (alg, key, signature, data) => {
19
22
  if (alg.startsWith('HS')) {
@@ -30,11 +33,7 @@ const verify = async (alg, key, signature, data) => {
30
33
  const keyObject = get_sign_verify_key_js_1.default(alg, key, 'verify');
31
34
  const keyInput = node_key_js_1.default(alg, keyObject);
32
35
  try {
33
- let result = oneShotVerify(algorithm, data, keyInput, signature);
34
- if (result instanceof Promise) {
35
- result = await result;
36
- }
37
- return result;
36
+ return await oneShotVerify(algorithm, data, keyInput, signature);
38
37
  }
39
38
  catch {
40
39
  return false;
@@ -2,15 +2,24 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getKeyObject = exports.isCryptoKey = void 0;
4
4
  const crypto = require("crypto");
5
+ const util = require("util");
5
6
  const webcrypto = crypto.webcrypto;
6
7
  exports.default = webcrypto;
7
- function isCryptoKey(key) {
8
- if (webcrypto !== undefined) {
9
- return key != null && key instanceof webcrypto.CryptoKey;
10
- }
11
- return false;
8
+ let impl;
9
+ exports.isCryptoKey = impl;
10
+ if (util.types.isCryptoKey) {
11
+ exports.isCryptoKey = impl = function isCryptoKey(obj) {
12
+ return util.types.isCryptoKey(obj);
13
+ };
14
+ }
15
+ else if (webcrypto) {
16
+ exports.isCryptoKey = impl = function isCryptoKey(obj) {
17
+ return obj != null && obj instanceof webcrypto.CryptoKey;
18
+ };
19
+ }
20
+ else {
21
+ exports.isCryptoKey = impl = (obj) => false;
12
22
  }
13
- exports.isCryptoKey = isCryptoKey;
14
23
  function getHashLength(hash) {
15
24
  return parseInt(hash === null || hash === void 0 ? void 0 : hash.name.substr(4), 10);
16
25
  }
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.decodeProtectedHeader = void 0;
4
- const assert_1 = require("assert");
5
4
  const base64url_js_1 = require("./base64url.js");
6
5
  const buffer_utils_js_1 = require("../lib/buffer_utils.js");
7
6
  const is_object_js_1 = require("../lib/is_object.js");
@@ -23,9 +22,13 @@ function decodeProtectedHeader(token) {
23
22
  }
24
23
  }
25
24
  try {
26
- assert_1.ok(typeof protectedB64u === 'string' && protectedB64u);
25
+ if (typeof protectedB64u !== 'string' || !protectedB64u) {
26
+ throw new Error();
27
+ }
27
28
  const result = JSON.parse(buffer_utils_js_1.decoder.decode(base64url_js_1.decode(protectedB64u)));
28
- assert_1.ok(is_object_js_1.default(result));
29
+ if (!is_object_js_1.default(result)) {
30
+ throw new Error();
31
+ }
29
32
  return result;
30
33
  }
31
34
  catch (err) {
@@ -1,6 +1,6 @@
1
1
  import parseJWK from '../jwk/parse.js';
2
2
  import { JWKSInvalid, JOSENotSupported, JWKSNoMatchingKey, JWKSMultipleMatchingKeys, } from '../util/errors.js';
3
- import fetchJson from '../runtime/fetch.js';
3
+ import fetchJwks from '../runtime/fetch_jwks.js';
4
4
  import isObject from '../lib/is_object.js';
5
5
  function getKtyFromAlg(alg) {
6
6
  switch (alg.substr(0, 2)) {
@@ -103,7 +103,7 @@ class RemoteJWKSet {
103
103
  }
104
104
  async reload() {
105
105
  if (!this._pendingFetch) {
106
- this._pendingFetch = fetchJson(this._url, this._timeoutDuration, this._options)
106
+ this._pendingFetch = fetchJwks(this._url, this._timeoutDuration, this._options)
107
107
  .then((json) => {
108
108
  if (typeof json !== 'object' ||
109
109
  !json ||
@@ -7,7 +7,7 @@ const protocols = {
7
7
  'https:': https,
8
8
  'http:': http,
9
9
  };
10
- const fetch = async (url, timeout, options) => {
10
+ const fetchJwks = async (url, timeout, options) => {
11
11
  if (protocols[url.protocol] === undefined) {
12
12
  throw new TypeError('Unsupported URL protocol.');
13
13
  }
@@ -31,4 +31,4 @@ const fetch = async (url, timeout, options) => {
31
31
  throw new JOSEError('Failed to parse the JSON Web Key Set HTTP response as JSON');
32
32
  }
33
33
  };
34
- export default fetch;
34
+ export default fetchJwks;
@@ -18,7 +18,7 @@ const namedCurveToJOSE = (namedCurve) => {
18
18
  case 'secp256k1':
19
19
  return namedCurve;
20
20
  default:
21
- throw new JOSENotSupported('unsupported curve for this operation');
21
+ throw new JOSENotSupported('unsupported key curve for this operation');
22
22
  }
23
23
  };
24
24
  const getNamedCurve = (key, raw) => {
@@ -64,6 +64,9 @@ const getNamedCurve = (key, raw) => {
64
64
  else if (curveOid.equals(secp256k1)) {
65
65
  namedCurve = 'secp256k1';
66
66
  }
67
+ else {
68
+ throw new JOSENotSupported('unsupported key curve for this operation');
69
+ }
67
70
  }
68
71
  if (raw)
69
72
  return namedCurve;
@@ -1,4 +1,14 @@
1
1
  import { KeyObject } from 'crypto';
2
- export default function isKeyObject(obj) {
3
- return obj != null && obj instanceof KeyObject;
2
+ import * as util from 'util';
3
+ let impl;
4
+ if (util.types.isKeyObject) {
5
+ impl = function isKeyObject(obj) {
6
+ return util.types.isKeyObject(obj);
7
+ };
4
8
  }
9
+ else {
10
+ impl = function isKeyObject(obj) {
11
+ return obj != null && obj instanceof KeyObject;
12
+ };
13
+ }
14
+ export default impl;
@@ -4,9 +4,12 @@ import nodeDigest from './dsa_digest.js';
4
4
  import hmacDigest from './hmac_digest.js';
5
5
  import nodeKey from './node_key.js';
6
6
  import getSignKey from './get_sign_verify_key.js';
7
- let oneShotSign = crypto.sign;
8
- if (oneShotSign.length > 3) {
9
- oneShotSign = promisify(oneShotSign);
7
+ let oneShotSign;
8
+ if (crypto.sign.length > 3) {
9
+ oneShotSign = promisify(crypto.sign);
10
+ }
11
+ else {
12
+ oneShotSign = crypto.sign;
10
13
  }
11
14
  const sign = async (alg, key, data) => {
12
15
  const keyObject = getSignKey(alg, key, 'sign');
@@ -9,9 +9,12 @@ const [major, minor] = process.version
9
9
  .split('.')
10
10
  .map((str) => parseInt(str, 10));
11
11
  const oneShotCallbackSupported = major >= 16 || (major === 15 && minor >= 13);
12
- let oneShotVerify = crypto.verify;
13
- if (oneShotVerify.length > 4 && oneShotCallbackSupported) {
14
- oneShotVerify = promisify(oneShotVerify);
12
+ let oneShotVerify;
13
+ if (crypto.verify.length > 4 && oneShotCallbackSupported) {
14
+ oneShotVerify = promisify(crypto.verify);
15
+ }
16
+ else {
17
+ oneShotVerify = crypto.verify;
15
18
  }
16
19
  const verify = async (alg, key, signature, data) => {
17
20
  if (alg.startsWith('HS')) {
@@ -28,11 +31,7 @@ const verify = async (alg, key, signature, data) => {
28
31
  const keyObject = getVerifyKey(alg, key, 'verify');
29
32
  const keyInput = nodeKey(alg, keyObject);
30
33
  try {
31
- let result = oneShotVerify(algorithm, data, keyInput, signature);
32
- if (result instanceof Promise) {
33
- result = await result;
34
- }
35
- return result;
34
+ return await oneShotVerify(algorithm, data, keyInput, signature);
36
35
  }
37
36
  catch {
38
37
  return false;
@@ -1,12 +1,22 @@
1
1
  import * as crypto from 'crypto';
2
+ import * as util from 'util';
2
3
  const webcrypto = crypto.webcrypto;
3
4
  export default webcrypto;
4
- export function isCryptoKey(key) {
5
- if (webcrypto !== undefined) {
6
- return key != null && key instanceof webcrypto.CryptoKey;
7
- }
8
- return false;
5
+ let impl;
6
+ if (util.types.isCryptoKey) {
7
+ impl = function isCryptoKey(obj) {
8
+ return util.types.isCryptoKey(obj);
9
+ };
10
+ }
11
+ else if (webcrypto) {
12
+ impl = function isCryptoKey(obj) {
13
+ return obj != null && obj instanceof webcrypto.CryptoKey;
14
+ };
15
+ }
16
+ else {
17
+ impl = (obj) => false;
9
18
  }
19
+ export { impl as isCryptoKey };
10
20
  function getHashLength(hash) {
11
21
  return parseInt(hash === null || hash === void 0 ? void 0 : hash.name.substr(4), 10);
12
22
  }
@@ -1,4 +1,3 @@
1
- import { ok as assert } from 'assert';
2
1
  import { decode as base64url } from './base64url.js';
3
2
  import { decoder } from '../lib/buffer_utils.js';
4
3
  import isObject from '../lib/is_object.js';
@@ -20,9 +19,13 @@ function decodeProtectedHeader(token) {
20
19
  }
21
20
  }
22
21
  try {
23
- assert(typeof protectedB64u === 'string' && protectedB64u);
22
+ if (typeof protectedB64u !== 'string' || !protectedB64u) {
23
+ throw new Error();
24
+ }
24
25
  const result = JSON.parse(decoder.decode(base64url(protectedB64u)));
25
- assert(isObject(result));
26
+ if (!isObject(result)) {
27
+ throw new Error();
28
+ }
26
29
  return result;
27
30
  }
28
31
  catch (err) {
@@ -4,4 +4,4 @@ export interface CompactDecryptGetKey extends GetKeyFunction<JWEHeaderParameters
4
4
  declare function compactDecrypt(jwe: string | Uint8Array, key: KeyLike | CompactDecryptGetKey, options?: DecryptOptions): Promise<CompactDecryptResult>;
5
5
  export { compactDecrypt };
6
6
  export default compactDecrypt;
7
- export type { KeyLike, DecryptOptions };
7
+ export type { KeyLike, DecryptOptions, CompactDecryptResult };
@@ -4,4 +4,4 @@ export interface FlattenedDecryptGetKey extends GetKeyFunction<JWEHeaderParamete
4
4
  declare function flattenedDecrypt(jwe: FlattenedJWE, key: KeyLike | FlattenedDecryptGetKey, options?: DecryptOptions): Promise<FlattenedDecryptResult>;
5
5
  export { flattenedDecrypt };
6
6
  export default flattenedDecrypt;
7
- export type { KeyLike, FlattenedJWE, JWEHeaderParameters, DecryptOptions };
7
+ export type { KeyLike, FlattenedJWE, JWEHeaderParameters, DecryptOptions, FlattenedDecryptResult };
@@ -4,4 +4,4 @@ export interface GeneralDecryptGetKey extends GetKeyFunction<JWEHeaderParameters
4
4
  declare function generalDecrypt(jwe: GeneralJWE, key: KeyLike | GeneralDecryptGetKey, options?: DecryptOptions): Promise<GeneralDecryptResult>;
5
5
  export { generalDecrypt };
6
6
  export default generalDecrypt;
7
- export type { KeyLike, GeneralJWE, DecryptOptions };
7
+ export type { KeyLike, GeneralJWE, DecryptOptions, GeneralDecryptResult };
@@ -4,4 +4,4 @@ export interface CompactVerifyGetKey extends GetKeyFunction<JWSHeaderParameters,
4
4
  declare function compactVerify(jws: string | Uint8Array, key: KeyLike | CompactVerifyGetKey, options?: VerifyOptions): Promise<CompactVerifyResult>;
5
5
  export { compactVerify };
6
6
  export default compactVerify;
7
- export type { KeyLike, VerifyOptions };
7
+ export type { KeyLike, VerifyOptions, CompactVerifyResult };
@@ -4,4 +4,4 @@ export interface FlattenedVerifyGetKey extends GetKeyFunction<JWSHeaderParameter
4
4
  declare function flattenedVerify(jws: FlattenedJWSInput, key: KeyLike | FlattenedVerifyGetKey, options?: VerifyOptions): Promise<FlattenedVerifyResult>;
5
5
  export { flattenedVerify };
6
6
  export default flattenedVerify;
7
- export type { KeyLike, FlattenedJWSInput, GetKeyFunction, JWSHeaderParameters, VerifyOptions };
7
+ export type { KeyLike, FlattenedJWSInput, GetKeyFunction, JWSHeaderParameters, VerifyOptions, FlattenedVerifyResult, };
@@ -4,4 +4,4 @@ export interface GeneralVerifyGetKey extends GetKeyFunction<JWSHeaderParameters,
4
4
  declare function generalVerify(jws: GeneralJWSInput, key: KeyLike | GeneralVerifyGetKey, options?: VerifyOptions): Promise<GeneralVerifyResult>;
5
5
  export { generalVerify };
6
6
  export default generalVerify;
7
- export type { KeyLike, GeneralJWSInput, VerifyOptions };
7
+ export type { KeyLike, GeneralJWSInput, VerifyOptions, GeneralVerifyResult };
@@ -6,4 +6,4 @@ export interface JWTDecryptGetKey extends GetKeyFunction<JWEHeaderParameters, Fl
6
6
  declare function jwtDecrypt(jwt: string | Uint8Array, key: KeyLike | JWTDecryptGetKey, options?: JWTDecryptOptions): Promise<JWTDecryptResult>;
7
7
  export { jwtDecrypt };
8
8
  export default jwtDecrypt;
9
- export type { KeyLike, DecryptOptions, JWTPayload, JWTDecryptOptions };
9
+ export type { KeyLike, DecryptOptions, JWTPayload, JWTDecryptOptions, JWTDecryptResult };
@@ -1,12 +1,13 @@
1
1
  import type { JWSHeaderParameters, JWTClaimVerificationOptions, JWTPayload } from '../types.d';
2
2
  import ProduceJWT from '../lib/jwt_producer.js';
3
+ interface UnsecuredResult {
4
+ payload: JWTPayload;
5
+ header: JWSHeaderParameters;
6
+ }
3
7
  declare class UnsecuredJWT extends ProduceJWT {
4
8
  encode(): string;
5
- static decode(jwt: string, options?: JWTClaimVerificationOptions): {
6
- payload: JWTPayload;
7
- header: JWSHeaderParameters;
8
- };
9
+ static decode(jwt: string, options?: JWTClaimVerificationOptions): UnsecuredResult;
9
10
  }
10
11
  export { UnsecuredJWT };
11
12
  export default UnsecuredJWT;
12
- export type { JWSHeaderParameters, JWTPayload };
13
+ export type { JWSHeaderParameters, JWTPayload, UnsecuredResult };
@@ -6,4 +6,4 @@ export interface JWTVerifyGetKey extends GetKeyFunction<JWSHeaderParameters, Fla
6
6
  declare function jwtVerify(jwt: string | Uint8Array, key: KeyLike | JWTVerifyGetKey, options?: JWTVerifyOptions): Promise<JWTVerifyResult>;
7
7
  export { jwtVerify };
8
8
  export default jwtVerify;
9
- export type { KeyLike, JWTPayload, JWTVerifyOptions, JWSHeaderParameters, GetKeyFunction };
9
+ export type { KeyLike, JWTPayload, JWTVerifyOptions, JWSHeaderParameters, GetKeyFunction, JWTVerifyResult, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jose",
3
- "version": "3.12.0",
3
+ "version": "3.13.0",
4
4
  "description": "Universal 'JSON Web Almost Everything' - JWA, JWS, JWE, JWT, JWK with no dependencies",
5
5
  "keywords": [
6
6
  "browser",