jose 4.0.4 → 4.1.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.
Files changed (62) hide show
  1. package/dist/browser/{runtime → lib}/aesgcmkw.js +8 -8
  2. package/dist/browser/lib/check_key_type.js +1 -1
  3. package/dist/browser/lib/crypto_key.js +46 -56
  4. package/dist/browser/lib/decrypt_key_management.js +1 -1
  5. package/dist/browser/lib/encrypt_key_management.js +1 -1
  6. package/dist/browser/{runtime → lib}/invalid_key_input.js +0 -0
  7. package/dist/browser/runtime/aeskw.js +1 -1
  8. package/dist/browser/runtime/asn1.js +6 -7
  9. package/dist/browser/runtime/base64url.js +2 -4
  10. package/dist/browser/runtime/bogus.js +1 -1
  11. package/dist/browser/runtime/decrypt.js +2 -2
  12. package/dist/browser/runtime/ecdhes.js +1 -1
  13. package/dist/browser/runtime/encrypt.js +2 -2
  14. package/dist/browser/runtime/env.js +11 -0
  15. package/dist/browser/runtime/fetch_jwks.js +3 -5
  16. package/dist/browser/runtime/generate.js +5 -5
  17. package/dist/browser/runtime/get_sign_verify_key.js +2 -2
  18. package/dist/browser/runtime/jwk_to_key.js +5 -5
  19. package/dist/browser/runtime/key_to_jwk.js +1 -1
  20. package/dist/browser/runtime/pbes2kw.js +11 -34
  21. package/dist/browser/runtime/rsaes.js +1 -1
  22. package/dist/browser/runtime/subtle_dsa.js +8 -27
  23. package/dist/browser/runtime/webcrypto.js +8 -4
  24. package/dist/node/cjs/{runtime → lib}/aesgcmkw.js +8 -8
  25. package/dist/node/cjs/lib/check_key_type.js +1 -1
  26. package/dist/node/cjs/lib/crypto_key.js +48 -58
  27. package/dist/node/cjs/lib/decrypt_key_management.js +1 -1
  28. package/dist/node/cjs/lib/encrypt_key_management.js +1 -1
  29. package/dist/node/cjs/{runtime → lib}/invalid_key_input.js +0 -11
  30. package/dist/node/cjs/runtime/aeskw.js +1 -1
  31. package/dist/node/cjs/runtime/asn1.js +1 -1
  32. package/dist/node/cjs/runtime/decrypt.js +1 -1
  33. package/dist/node/cjs/runtime/ecdhes.js +1 -1
  34. package/dist/node/cjs/runtime/encrypt.js +1 -1
  35. package/dist/node/cjs/runtime/{global.js → env.js} +0 -0
  36. package/dist/node/cjs/runtime/get_named_curve.js +1 -1
  37. package/dist/node/cjs/runtime/get_sign_verify_key.js +1 -1
  38. package/dist/node/cjs/runtime/key_to_jwk.js +1 -1
  39. package/dist/node/cjs/runtime/node_key.js +6 -10
  40. package/dist/node/cjs/runtime/pbes2kw.js +1 -1
  41. package/dist/node/cjs/runtime/rsaes.js +1 -1
  42. package/dist/node/esm/{runtime → lib}/aesgcmkw.js +8 -8
  43. package/dist/node/esm/lib/check_key_type.js +1 -1
  44. package/dist/node/esm/lib/crypto_key.js +46 -56
  45. package/dist/node/esm/lib/decrypt_key_management.js +1 -1
  46. package/dist/node/esm/lib/encrypt_key_management.js +1 -1
  47. package/dist/node/esm/{runtime → lib}/invalid_key_input.js +0 -11
  48. package/dist/node/esm/runtime/aeskw.js +1 -1
  49. package/dist/node/esm/runtime/asn1.js +1 -1
  50. package/dist/node/esm/runtime/decrypt.js +1 -1
  51. package/dist/node/esm/runtime/ecdhes.js +1 -1
  52. package/dist/node/esm/runtime/encrypt.js +1 -1
  53. package/dist/node/esm/runtime/{global.js → env.js} +0 -0
  54. package/dist/node/esm/runtime/get_named_curve.js +1 -1
  55. package/dist/node/esm/runtime/get_sign_verify_key.js +1 -1
  56. package/dist/node/esm/runtime/key_to_jwk.js +1 -1
  57. package/dist/node/esm/runtime/node_key.js +6 -10
  58. package/dist/node/esm/runtime/pbes2kw.js +1 -1
  59. package/dist/node/esm/runtime/rsaes.js +1 -1
  60. package/dist/types/jwks/remote.d.ts +4 -0
  61. package/package.json +4 -1
  62. package/dist/browser/runtime/global.js +0 -27
@@ -1,45 +1,26 @@
1
- import { isCloudflareWorkers, isNodeJs } from './global.js';
1
+ import { isCloudflareWorkers, isNodeJs } from './env.js';
2
2
  import { JOSENotSupported } from '../util/errors.js';
3
- export default function subtleDsa(alg, crv) {
3
+ export default function subtleDsa(alg, namedCurve) {
4
+ const length = parseInt(alg.substr(-3), 10);
4
5
  switch (alg) {
5
6
  case 'HS256':
6
- return { hash: { name: 'SHA-256' }, name: 'HMAC' };
7
7
  case 'HS384':
8
- return { hash: { name: 'SHA-384' }, name: 'HMAC' };
9
8
  case 'HS512':
10
- return { hash: { name: 'SHA-512' }, name: 'HMAC' };
9
+ return { hash: `SHA-${length}`, name: 'HMAC' };
11
10
  case 'PS256':
12
- return {
13
- hash: { name: 'SHA-256' },
14
- name: 'RSA-PSS',
15
- saltLength: 256 >> 3,
16
- };
17
11
  case 'PS384':
18
- return {
19
- hash: { name: 'SHA-384' },
20
- name: 'RSA-PSS',
21
- saltLength: 384 >> 3,
22
- };
23
12
  case 'PS512':
24
- return {
25
- hash: { name: 'SHA-512' },
26
- name: 'RSA-PSS',
27
- saltLength: 512 >> 3,
28
- };
13
+ return { hash: `SHA-${length}`, name: 'RSA-PSS', saltLength: length >> 3 };
29
14
  case 'RS256':
30
- return { hash: { name: 'SHA-256' }, name: 'RSASSA-PKCS1-v1_5' };
31
15
  case 'RS384':
32
- return { hash: { name: 'SHA-384' }, name: 'RSASSA-PKCS1-v1_5' };
33
16
  case 'RS512':
34
- return { hash: { name: 'SHA-512' }, name: 'RSASSA-PKCS1-v1_5' };
17
+ return { hash: `SHA-${length}`, name: 'RSASSA-PKCS1-v1_5' };
35
18
  case 'ES256':
36
- return { hash: { name: 'SHA-256' }, name: 'ECDSA', namedCurve: 'P-256' };
37
19
  case 'ES384':
38
- return { hash: { name: 'SHA-384' }, name: 'ECDSA', namedCurve: 'P-384' };
39
20
  case 'ES512':
40
- return { hash: { name: 'SHA-512' }, name: 'ECDSA', namedCurve: 'P-521' };
21
+ return { hash: `SHA-${length}`, name: 'ECDSA', namedCurve };
41
22
  case (isCloudflareWorkers() || isNodeJs()) && 'EdDSA':
42
- return { name: crv, namedCurve: crv };
23
+ return { name: namedCurve, namedCurve };
43
24
  default:
44
25
  throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
45
26
  }
@@ -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,19 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.unwrap = exports.wrap = void 0;
4
- const encrypt_js_1 = require("./encrypt.js");
5
- const decrypt_js_1 = require("./decrypt.js");
6
- const iv_js_1 = require("../lib/iv.js");
7
- const base64url_js_1 = require("./base64url.js");
8
- const wrap = async (alg, key, cek, iv) => {
4
+ const encrypt_js_1 = require("../runtime/encrypt.js");
5
+ const decrypt_js_1 = require("../runtime/decrypt.js");
6
+ const iv_js_1 = require("./iv.js");
7
+ const base64url_js_1 = require("../runtime/base64url.js");
8
+ async function wrap(alg, key, cek, iv) {
9
9
  const jweAlgorithm = alg.substr(0, 7);
10
10
  iv || (iv = (0, iv_js_1.default)(jweAlgorithm));
11
11
  const { ciphertext: encryptedKey, tag } = await (0, encrypt_js_1.default)(jweAlgorithm, cek, key, iv, new Uint8Array(0));
12
12
  return { encryptedKey, iv: (0, base64url_js_1.encode)(iv), tag: (0, base64url_js_1.encode)(tag) };
13
- };
13
+ }
14
14
  exports.wrap = wrap;
15
- const unwrap = async (alg, key, encryptedKey, iv, tag) => {
15
+ async function unwrap(alg, key, encryptedKey, iv, tag) {
16
16
  const jweAlgorithm = alg.substr(0, 7);
17
17
  return (0, decrypt_js_1.default)(jweAlgorithm, key, encryptedKey, iv, tag, new Uint8Array(0));
18
- };
18
+ }
19
19
  exports.unwrap = unwrap;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const invalid_key_input_js_1 = require("../runtime/invalid_key_input.js");
3
+ const invalid_key_input_js_1 = require("./invalid_key_input.js");
4
4
  const is_key_like_js_1 = require("../runtime/is_key_like.js");
5
5
  const symmetricTypeCheck = (key) => {
6
6
  if (key instanceof Uint8Array)
@@ -1,9 +1,15 @@
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
+ function unusable(name, prop = 'algorithm.name') {
6
+ return new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
7
+ }
8
+ function isAlgorithm(algorithm, name) {
9
+ return algorithm.name === name;
10
+ }
5
11
  function getHashLength(hash) {
6
- return parseInt(hash === null || hash === void 0 ? void 0 : hash.name.substr(4), 10);
12
+ return parseInt(hash.name.substr(4), 10);
7
13
  }
8
14
  function getNamedCurve(alg) {
9
15
  switch (alg) {
@@ -13,6 +19,8 @@ function getNamedCurve(alg) {
13
19
  return 'P-384';
14
20
  case 'ES512':
15
21
  return 'P-521';
22
+ default:
23
+ throw new Error('unreachable');
16
24
  }
17
25
  }
18
26
  function checkUsage(key, usages) {
@@ -36,65 +44,55 @@ function checkSigCryptoKey(key, alg, ...usages) {
36
44
  case 'HS256':
37
45
  case 'HS384':
38
46
  case 'HS512': {
39
- if (key.algorithm.name !== 'HMAC') {
40
- throw new TypeError(`CryptoKey does not support this operation, its algorithm.name must be HMAC.`);
41
- }
47
+ if (!isAlgorithm(key.algorithm, 'HMAC'))
48
+ throw unusable('HMAC');
42
49
  const expected = parseInt(alg.substr(2), 10);
43
50
  const actual = getHashLength(key.algorithm.hash);
44
- if (actual !== expected) {
45
- throw new TypeError(`CryptoKey does not support this operation, its algorithm.hash must be SHA-${expected}.`);
46
- }
51
+ if (actual !== expected)
52
+ throw unusable(`SHA-${expected}`, 'algorithm.hash');
47
53
  break;
48
54
  }
49
55
  case 'RS256':
50
56
  case 'RS384':
51
57
  case 'RS512': {
52
- if (key.algorithm.name !== 'RSASSA-PKCS1-v1_5') {
53
- throw new TypeError(`CryptoKey does not support this operation, its algorithm.name must be RSASSA-PKCS1-v1_5.`);
54
- }
58
+ if (!isAlgorithm(key.algorithm, 'RSASSA-PKCS1-v1_5'))
59
+ throw unusable('RSASSA-PKCS1-v1_5');
55
60
  const expected = parseInt(alg.substr(2), 10);
56
61
  const actual = getHashLength(key.algorithm.hash);
57
- if (actual !== expected) {
58
- throw new TypeError(`CryptoKey does not support this operation, its algorithm.hash must be SHA-${expected}.`);
59
- }
62
+ if (actual !== expected)
63
+ throw unusable(`SHA-${expected}`, 'algorithm.hash');
60
64
  break;
61
65
  }
62
66
  case 'PS256':
63
67
  case 'PS384':
64
68
  case 'PS512': {
65
- if (key.algorithm.name !== 'RSA-PSS') {
66
- throw new TypeError(`CryptoKey does not support this operation, its algorithm.name must be RSA-PSS.`);
67
- }
69
+ if (!isAlgorithm(key.algorithm, 'RSA-PSS'))
70
+ throw unusable('RSA-PSS');
68
71
  const expected = parseInt(alg.substr(2), 10);
69
72
  const actual = getHashLength(key.algorithm.hash);
70
- if (actual !== expected) {
71
- throw new TypeError(`CryptoKey does not support this operation, its algorithm.hash must be SHA-${expected}.`);
72
- }
73
+ if (actual !== expected)
74
+ throw unusable(`SHA-${expected}`, 'algorithm.hash');
73
75
  break;
74
76
  }
75
- case (0, global_js_1.isNodeJs)() && 'EdDSA': {
76
- if (key.algorithm.name !== 'NODE-ED25519' && key.algorithm.name !== 'NODE-ED448') {
77
- throw new TypeError(`CryptoKey does not support this operation, its algorithm.name must be NODE-ED25519 or NODE-ED448.`);
78
- }
77
+ case (0, env_js_1.isNodeJs)() && 'EdDSA': {
78
+ if (key.algorithm.name !== 'NODE-ED25519' && key.algorithm.name !== 'NODE-ED448')
79
+ throw unusable('NODE-ED25519 or NODE-ED448');
79
80
  break;
80
81
  }
81
- case (0, global_js_1.isCloudflareWorkers)() && 'EdDSA': {
82
- if (key.algorithm.name !== 'NODE-ED25519') {
83
- throw new TypeError(`CryptoKey does not support this operation, its algorithm.name must be NODE-ED25519.`);
84
- }
82
+ case (0, env_js_1.isCloudflareWorkers)() && 'EdDSA': {
83
+ if (!isAlgorithm(key.algorithm, 'NODE-ED25519'))
84
+ throw unusable('NODE-ED25519');
85
85
  break;
86
86
  }
87
87
  case 'ES256':
88
88
  case 'ES384':
89
89
  case 'ES512': {
90
- if (key.algorithm.name !== 'ECDSA') {
91
- throw new TypeError(`CryptoKey does not support this operation, its algorithm.name must be ECDSA.`);
92
- }
90
+ if (!isAlgorithm(key.algorithm, 'ECDSA'))
91
+ throw unusable('ECDSA');
93
92
  const expected = getNamedCurve(alg);
94
93
  const actual = key.algorithm.namedCurve;
95
- if (actual !== expected) {
96
- throw new TypeError(`CryptoKey does not support this operation, its algorithm.namedCurve must be ${expected}.`);
97
- }
94
+ if (actual !== expected)
95
+ throw unusable(expected, 'algorithm.namedCurve');
98
96
  break;
99
97
  }
100
98
  default:
@@ -108,53 +106,45 @@ function checkEncCryptoKey(key, alg, ...usages) {
108
106
  case 'A128GCM':
109
107
  case 'A192GCM':
110
108
  case 'A256GCM': {
111
- if (key.algorithm.name !== 'AES-GCM') {
112
- throw new TypeError(`CryptoKey does not support this operation, its algorithm.name must be AES-GCM.`);
113
- }
109
+ if (!isAlgorithm(key.algorithm, 'AES-GCM'))
110
+ throw unusable('AES-GCM');
114
111
  const expected = parseInt(alg.substr(1, 3), 10);
115
112
  const actual = key.algorithm.length;
116
- if (actual !== expected) {
117
- throw new TypeError(`CryptoKey does not support this operation, its algorithm.length must be ${expected}.`);
118
- }
113
+ if (actual !== expected)
114
+ throw unusable(expected, 'algorithm.length');
119
115
  break;
120
116
  }
121
117
  case 'A128KW':
122
118
  case 'A192KW':
123
119
  case 'A256KW': {
124
- if (key.algorithm.name !== 'AES-KW') {
125
- throw new TypeError(`CryptoKey does not support this operation, its algorithm.name must be AES-KW.`);
126
- }
120
+ if (!isAlgorithm(key.algorithm, 'AES-KW'))
121
+ throw unusable('AES-KW');
127
122
  const expected = parseInt(alg.substr(1, 3), 10);
128
123
  const actual = key.algorithm.length;
129
- if (actual !== expected) {
130
- throw new TypeError(`CryptoKey does not support this operation, its algorithm.length must be ${expected}.`);
131
- }
124
+ if (actual !== expected)
125
+ throw unusable(expected, 'algorithm.length');
132
126
  break;
133
127
  }
134
128
  case 'ECDH-ES':
135
- if (key.algorithm.name !== 'ECDH') {
136
- throw new TypeError(`CryptoKey does not support this operation, its algorithm.name must be ECDH.`);
137
- }
129
+ if (!isAlgorithm(key.algorithm, 'ECDH'))
130
+ throw unusable('ECDH');
138
131
  break;
139
132
  case 'PBES2-HS256+A128KW':
140
133
  case 'PBES2-HS384+A192KW':
141
134
  case 'PBES2-HS512+A256KW':
142
- if (key.algorithm.name !== 'PBKDF2') {
143
- throw new TypeError(`CryptoKey does not support this operation, its algorithm.name must be PBKDF2.`);
144
- }
135
+ if (!isAlgorithm(key.algorithm, 'PBKDF2'))
136
+ throw unusable('PBKDF2');
145
137
  break;
146
138
  case 'RSA-OAEP':
147
139
  case 'RSA-OAEP-256':
148
140
  case 'RSA-OAEP-384':
149
141
  case 'RSA-OAEP-512': {
150
- if (key.algorithm.name !== 'RSA-OAEP') {
151
- throw new TypeError(`CryptoKey does not support this operation, its algorithm.name must be RSA-OAEP.`);
152
- }
142
+ if (!isAlgorithm(key.algorithm, 'RSA-OAEP'))
143
+ throw unusable('RSA-OAEP');
153
144
  const expected = parseInt(alg.substr(9), 10) || 1;
154
145
  const actual = getHashLength(key.algorithm.hash);
155
- if (actual !== expected) {
156
- throw new TypeError(`CryptoKey does not support this operation, its algorithm.hash must be SHA-${expected}.`);
157
- }
146
+ if (actual !== expected)
147
+ throw unusable(`SHA-${expected}`, 'algorithm.hash');
158
148
  break;
159
149
  }
160
150
  default:
@@ -4,13 +4,13 @@ const aeskw_js_1 = require("../runtime/aeskw.js");
4
4
  const ECDH = require("../runtime/ecdhes.js");
5
5
  const pbes2kw_js_1 = require("../runtime/pbes2kw.js");
6
6
  const rsaes_js_1 = require("../runtime/rsaes.js");
7
- const aesgcmkw_js_1 = require("../runtime/aesgcmkw.js");
8
7
  const base64url_js_1 = require("../runtime/base64url.js");
9
8
  const errors_js_1 = require("../util/errors.js");
10
9
  const cek_js_1 = require("../lib/cek.js");
11
10
  const import_js_1 = require("../key/import.js");
12
11
  const check_key_type_js_1 = require("./check_key_type.js");
13
12
  const is_object_js_1 = require("./is_object.js");
13
+ const aesgcmkw_js_1 = require("./aesgcmkw.js");
14
14
  async function decryptKeyManagement(alg, key, encryptedKey, joseHeader) {
15
15
  (0, check_key_type_js_1.default)(alg, key, 'decrypt');
16
16
  switch (alg) {
@@ -4,12 +4,12 @@ const aeskw_js_1 = require("../runtime/aeskw.js");
4
4
  const ECDH = require("../runtime/ecdhes.js");
5
5
  const pbes2kw_js_1 = require("../runtime/pbes2kw.js");
6
6
  const rsaes_js_1 = require("../runtime/rsaes.js");
7
- const aesgcmkw_js_1 = require("../runtime/aesgcmkw.js");
8
7
  const base64url_js_1 = require("../runtime/base64url.js");
9
8
  const cek_js_1 = require("../lib/cek.js");
10
9
  const errors_js_1 = require("../util/errors.js");
11
10
  const export_js_1 = require("../key/export.js");
12
11
  const check_key_type_js_1 = require("./check_key_type.js");
12
+ const aesgcmkw_js_1 = require("./aesgcmkw.js");
13
13
  async function encryptKeyManagement(alg, enc, key, providedCek, providedParameters = {}) {
14
14
  let encryptedKey;
15
15
  let parameters;
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const util_1 = require("util");
4
3
  exports.default = (actual, ...types) => {
5
4
  let msg = 'Key must be ';
6
5
  if (types.length > 2) {
@@ -23,16 +22,6 @@ exports.default = (actual, ...types) => {
23
22
  if (actual.constructor && actual.constructor.name) {
24
23
  msg += ` Received an instance of ${actual.constructor.name}`;
25
24
  }
26
- else {
27
- const inspected = (0, util_1.inspect)(actual, { depth: -1 });
28
- msg += ` Received ${inspected}`;
29
- }
30
- }
31
- else {
32
- let inspected = (0, util_1.inspect)(actual, { colors: false });
33
- if (inspected.length > 25)
34
- inspected = `${inspected.slice(0, 25)}...`;
35
- msg += ` Received type ${typeof actual} (${inspected})`;
36
25
  }
37
26
  return msg;
38
27
  };
@@ -9,7 +9,7 @@ const secret_key_js_1 = require("./secret_key.js");
9
9
  const webcrypto_js_1 = require("./webcrypto.js");
10
10
  const crypto_key_js_1 = require("../lib/crypto_key.js");
11
11
  const is_key_object_js_1 = require("./is_key_object.js");
12
- const invalid_key_input_js_1 = require("./invalid_key_input.js");
12
+ const invalid_key_input_js_1 = require("../lib/invalid_key_input.js");
13
13
  const ciphers_js_1 = require("./ciphers.js");
14
14
  function checkKeySize(key, alg) {
15
15
  if (key.symmetricKeySize << 3 !== parseInt(alg.substr(1, 3), 10)) {
@@ -5,7 +5,7 @@ const crypto_1 = require("crypto");
5
5
  const buffer_1 = require("buffer");
6
6
  const webcrypto_js_1 = require("./webcrypto.js");
7
7
  const is_key_object_js_1 = require("./is_key_object.js");
8
- const invalid_key_input_js_1 = require("./invalid_key_input.js");
8
+ const invalid_key_input_js_1 = require("../lib/invalid_key_input.js");
9
9
  const genericExport = (keyType, keyFormat, key) => {
10
10
  let keyObject;
11
11
  if ((0, webcrypto_js_1.isCryptoKey)(key)) {
@@ -10,7 +10,7 @@ const cbc_tag_js_1 = require("./cbc_tag.js");
10
10
  const webcrypto_js_1 = require("./webcrypto.js");
11
11
  const crypto_key_js_1 = require("../lib/crypto_key.js");
12
12
  const is_key_object_js_1 = require("./is_key_object.js");
13
- const invalid_key_input_js_1 = require("./invalid_key_input.js");
13
+ const invalid_key_input_js_1 = require("../lib/invalid_key_input.js");
14
14
  const ciphers_js_1 = require("./ciphers.js");
15
15
  async function cbcDecrypt(enc, cek, ciphertext, iv, tag, aad) {
16
16
  const keySize = parseInt(enc.substr(1, 3), 10);
@@ -10,7 +10,7 @@ const errors_js_1 = require("../util/errors.js");
10
10
  const webcrypto_js_1 = require("./webcrypto.js");
11
11
  const crypto_key_js_1 = require("../lib/crypto_key.js");
12
12
  const is_key_object_js_1 = require("./is_key_object.js");
13
- const invalid_key_input_js_1 = require("./invalid_key_input.js");
13
+ const invalid_key_input_js_1 = require("../lib/invalid_key_input.js");
14
14
  const generateKeyPair = (0, util_1.promisify)(crypto_1.generateKeyPair);
15
15
  const deriveKey = async (publicKee, privateKee, algorithm, keyLength, apu = new Uint8Array(0), apv = new Uint8Array(0)) => {
16
16
  let publicKey;
@@ -8,7 +8,7 @@ const cbc_tag_js_1 = require("./cbc_tag.js");
8
8
  const webcrypto_js_1 = require("./webcrypto.js");
9
9
  const crypto_key_js_1 = require("../lib/crypto_key.js");
10
10
  const is_key_object_js_1 = require("./is_key_object.js");
11
- const invalid_key_input_js_1 = require("./invalid_key_input.js");
11
+ const invalid_key_input_js_1 = require("../lib/invalid_key_input.js");
12
12
  const errors_js_1 = require("../util/errors.js");
13
13
  const ciphers_js_1 = require("./ciphers.js");
14
14
  async function cbcEncrypt(enc, plaintext, cek, iv, aad) {
File without changes
@@ -6,7 +6,7 @@ const crypto_1 = require("crypto");
6
6
  const errors_js_1 = require("../util/errors.js");
7
7
  const webcrypto_js_1 = require("./webcrypto.js");
8
8
  const is_key_object_js_1 = require("./is_key_object.js");
9
- const invalid_key_input_js_1 = require("./invalid_key_input.js");
9
+ const invalid_key_input_js_1 = require("../lib/invalid_key_input.js");
10
10
  const p256 = buffer_1.Buffer.from([42, 134, 72, 206, 61, 3, 1, 7]);
11
11
  const p384 = buffer_1.Buffer.from([43, 129, 4, 0, 34]);
12
12
  const p521 = buffer_1.Buffer.from([43, 129, 4, 0, 35]);
@@ -4,7 +4,7 @@ const crypto_1 = require("crypto");
4
4
  const webcrypto_js_1 = require("./webcrypto.js");
5
5
  const crypto_key_js_1 = require("../lib/crypto_key.js");
6
6
  const secret_key_js_1 = require("./secret_key.js");
7
- const invalid_key_input_js_1 = require("./invalid_key_input.js");
7
+ const invalid_key_input_js_1 = require("../lib/invalid_key_input.js");
8
8
  function getSignVerifyKey(alg, key, usage) {
9
9
  if (key instanceof Uint8Array) {
10
10
  if (!alg.startsWith('HS')) {
@@ -7,7 +7,7 @@ const errors_js_1 = require("../util/errors.js");
7
7
  const get_named_curve_js_1 = require("./get_named_curve.js");
8
8
  const webcrypto_js_1 = require("./webcrypto.js");
9
9
  const is_key_object_js_1 = require("./is_key_object.js");
10
- const invalid_key_input_js_1 = require("./invalid_key_input.js");
10
+ const invalid_key_input_js_1 = require("../lib/invalid_key_input.js");
11
11
  const [major, minor] = process.version
12
12
  .substr(1)
13
13
  .split('.')
@@ -9,6 +9,10 @@ const [major, minor] = process.version
9
9
  .split('.')
10
10
  .map((str) => parseInt(str, 10));
11
11
  const rsaPssParams = major >= 17 || (major === 16 && minor >= 9);
12
+ const PSS = {
13
+ padding: crypto_1.constants.RSA_PKCS1_PSS_PADDING,
14
+ saltLength: crypto_1.constants.RSA_PSS_SALTLEN_DIGEST,
15
+ };
12
16
  const ecCurveAlgMap = new Map([
13
17
  ['ES256', 'P-256'],
14
18
  ['ES256K', 'secp256k1'],
@@ -48,11 +52,7 @@ function keyForCrypto(alg, key) {
48
52
  throw new TypeError('Invalid key for this operation, its asymmetricKeyType must be rsa or rsa-pss');
49
53
  }
50
54
  (0, check_modulus_length_js_1.default)(key, alg);
51
- return {
52
- key,
53
- padding: crypto_1.constants.RSA_PKCS1_PSS_PADDING,
54
- saltLength: crypto_1.constants.RSA_PSS_SALTLEN_DIGEST,
55
- };
55
+ return { key, ...PSS };
56
56
  case !rsaPssParams && 'PS256':
57
57
  case !rsaPssParams && 'PS384':
58
58
  case !rsaPssParams && 'PS512':
@@ -60,11 +60,7 @@ function keyForCrypto(alg, key) {
60
60
  throw new TypeError('Invalid key for this operation, its asymmetricKeyType must be rsa');
61
61
  }
62
62
  (0, check_modulus_length_js_1.default)(key, alg);
63
- return {
64
- key,
65
- padding: crypto_1.constants.RSA_PKCS1_PSS_PADDING,
66
- saltLength: crypto_1.constants.RSA_PSS_SALTLEN_DIGEST,
67
- };
63
+ return { key, ...PSS };
68
64
  case 'ES256':
69
65
  case 'ES256K':
70
66
  case 'ES384':
@@ -11,7 +11,7 @@ const check_p2s_js_1 = require("../lib/check_p2s.js");
11
11
  const webcrypto_js_1 = require("./webcrypto.js");
12
12
  const crypto_key_js_1 = require("../lib/crypto_key.js");
13
13
  const is_key_object_js_1 = require("./is_key_object.js");
14
- const invalid_key_input_js_1 = require("./invalid_key_input.js");
14
+ const invalid_key_input_js_1 = require("../lib/invalid_key_input.js");
15
15
  const pbkdf2 = (0, util_1.promisify)(crypto_1.pbkdf2);
16
16
  function getPassword(key, alg) {
17
17
  if ((0, is_key_object_js_1.default)(key)) {
@@ -6,7 +6,7 @@ const check_modulus_length_js_1 = require("./check_modulus_length.js");
6
6
  const webcrypto_js_1 = require("./webcrypto.js");
7
7
  const crypto_key_js_1 = require("../lib/crypto_key.js");
8
8
  const is_key_object_js_1 = require("./is_key_object.js");
9
- const invalid_key_input_js_1 = require("./invalid_key_input.js");
9
+ const invalid_key_input_js_1 = require("../lib/invalid_key_input.js");
10
10
  const checkKey = (key, alg) => {
11
11
  if (key.asymmetricKeyType !== 'rsa') {
12
12
  throw new TypeError('Invalid key for this operation, its asymmetricKeyType must be rsa');
@@ -1,14 +1,14 @@
1
- import encrypt from './encrypt.js';
2
- import decrypt from './decrypt.js';
3
- import generateIv from '../lib/iv.js';
4
- import { encode as base64url } from './base64url.js';
5
- export const wrap = async (alg, key, cek, iv) => {
1
+ import encrypt from '../runtime/encrypt.js';
2
+ import decrypt from '../runtime/decrypt.js';
3
+ import generateIv from './iv.js';
4
+ import { encode as base64url } from '../runtime/base64url.js';
5
+ export async function wrap(alg, key, cek, iv) {
6
6
  const jweAlgorithm = alg.substr(0, 7);
7
7
  iv || (iv = generateIv(jweAlgorithm));
8
8
  const { ciphertext: encryptedKey, tag } = await encrypt(jweAlgorithm, cek, key, iv, new Uint8Array(0));
9
9
  return { encryptedKey, iv: base64url(iv), tag: base64url(tag) };
10
- };
11
- export const unwrap = async (alg, key, encryptedKey, iv, tag) => {
10
+ }
11
+ export async function unwrap(alg, key, encryptedKey, iv, tag) {
12
12
  const jweAlgorithm = alg.substr(0, 7);
13
13
  return decrypt(jweAlgorithm, key, encryptedKey, iv, tag, new Uint8Array(0));
14
- };
14
+ }
@@ -1,4 +1,4 @@
1
- import invalidKeyInput from '../runtime/invalid_key_input.js';
1
+ import invalidKeyInput from './invalid_key_input.js';
2
2
  import isKeyLike, { types } from '../runtime/is_key_like.js';
3
3
  const symmetricTypeCheck = (key) => {
4
4
  if (key instanceof Uint8Array)