jose 6.0.13 → 6.1.1

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 (59) hide show
  1. package/README.md +3 -2
  2. package/dist/types/jwe/compact/encrypt.d.ts +4 -4
  3. package/dist/types/jwe/flattened/encrypt.d.ts +4 -4
  4. package/dist/types/jwe/general/encrypt.d.ts +9 -0
  5. package/dist/types/jwt/encrypt.d.ts +4 -4
  6. package/dist/types/types.d.ts +40 -11
  7. package/dist/webapi/jwe/flattened/decrypt.js +12 -12
  8. package/dist/webapi/jwe/flattened/encrypt.js +17 -13
  9. package/dist/webapi/jwe/general/decrypt.js +1 -1
  10. package/dist/webapi/jwe/general/encrypt.js +16 -16
  11. package/dist/webapi/jwk/embedded.js +1 -1
  12. package/dist/webapi/jwk/thumbprint.js +10 -5
  13. package/dist/webapi/jwks/local.js +4 -2
  14. package/dist/webapi/jwks/remote.js +2 -2
  15. package/dist/webapi/jws/flattened/sign.js +23 -17
  16. package/dist/webapi/jws/flattened/verify.js +13 -9
  17. package/dist/webapi/jws/general/verify.js +1 -1
  18. package/dist/webapi/key/export.js +1 -1
  19. package/dist/webapi/key/generate_key_pair.js +10 -3
  20. package/dist/webapi/key/import.js +13 -3
  21. package/dist/webapi/lib/aesgcmkw.js +4 -4
  22. package/dist/webapi/lib/asn1.js +9 -7
  23. package/dist/webapi/lib/buffer_utils.js +11 -0
  24. package/dist/webapi/lib/cek.js +2 -2
  25. package/dist/webapi/lib/check_cek_length.js +2 -2
  26. package/dist/webapi/lib/check_iv_length.js +2 -2
  27. package/dist/webapi/lib/check_key_length.js +2 -2
  28. package/dist/webapi/lib/check_key_type.js +13 -17
  29. package/dist/webapi/lib/crypto_key.js +9 -6
  30. package/dist/webapi/lib/decrypt.js +7 -7
  31. package/dist/webapi/lib/decrypt_key_management.js +4 -4
  32. package/dist/webapi/lib/digest.js +2 -2
  33. package/dist/webapi/lib/ecdhes.js +5 -5
  34. package/dist/webapi/lib/encrypt.js +8 -8
  35. package/dist/webapi/lib/encrypt_key_management.js +4 -4
  36. package/dist/webapi/lib/get_sign_verify_key.js +3 -3
  37. package/dist/webapi/lib/invalid_key_input.js +2 -6
  38. package/dist/webapi/lib/is_disjoint.js +2 -2
  39. package/dist/webapi/lib/is_jwk.js +6 -13
  40. package/dist/webapi/lib/is_key_like.js +3 -9
  41. package/dist/webapi/lib/is_object.js +3 -5
  42. package/dist/webapi/lib/iv.js +1 -1
  43. package/dist/webapi/lib/jwk_to_key.js +19 -4
  44. package/dist/webapi/lib/jwt_claims_set.js +59 -6
  45. package/dist/webapi/lib/key_to_jwk.js +6 -2
  46. package/dist/webapi/lib/normalize_key.js +16 -4
  47. package/dist/webapi/lib/pbes2kw.js +5 -3
  48. package/dist/webapi/lib/rsaes.js +1 -1
  49. package/dist/webapi/lib/sign.js +6 -6
  50. package/dist/webapi/lib/subtle_dsa.js +6 -2
  51. package/dist/webapi/lib/validate_algorithms.js +2 -2
  52. package/dist/webapi/lib/validate_crit.js +2 -2
  53. package/dist/webapi/lib/verify.js +6 -6
  54. package/dist/webapi/util/base64url.js +1 -1
  55. package/dist/webapi/util/decode_jwt.js +1 -1
  56. package/dist/webapi/util/decode_protected_header.js +1 -1
  57. package/package.json +4 -2
  58. package/dist/webapi/lib/epoch.js +0 -1
  59. package/dist/webapi/lib/secs.js +0 -55
@@ -16,7 +16,7 @@ export async function generateKeyPair(alg, options) {
16
16
  algorithm = {
17
17
  name: 'RSA-PSS',
18
18
  hash: `SHA-${alg.slice(-3)}`,
19
- publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
19
+ publicExponent: Uint8Array.of(0x01, 0x00, 0x01),
20
20
  modulusLength: getModulusLengthOption(options),
21
21
  };
22
22
  keyUsages = ['sign', 'verify'];
@@ -27,7 +27,7 @@ export async function generateKeyPair(alg, options) {
27
27
  algorithm = {
28
28
  name: 'RSASSA-PKCS1-v1_5',
29
29
  hash: `SHA-${alg.slice(-3)}`,
30
- publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
30
+ publicExponent: Uint8Array.of(0x01, 0x00, 0x01),
31
31
  modulusLength: getModulusLengthOption(options),
32
32
  };
33
33
  keyUsages = ['sign', 'verify'];
@@ -39,7 +39,7 @@ export async function generateKeyPair(alg, options) {
39
39
  algorithm = {
40
40
  name: 'RSA-OAEP',
41
41
  hash: `SHA-${parseInt(alg.slice(-3), 10) || 1}`,
42
- publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
42
+ publicExponent: Uint8Array.of(0x01, 0x00, 0x01),
43
43
  modulusLength: getModulusLengthOption(options),
44
44
  };
45
45
  keyUsages = ['decrypt', 'unwrapKey', 'encrypt', 'wrapKey'];
@@ -62,6 +62,13 @@ export async function generateKeyPair(alg, options) {
62
62
  algorithm = { name: 'Ed25519' };
63
63
  break;
64
64
  }
65
+ case 'ML-DSA-44':
66
+ case 'ML-DSA-65':
67
+ case 'ML-DSA-87': {
68
+ keyUsages = ['sign', 'verify'];
69
+ algorithm = { name: alg };
70
+ break;
71
+ }
65
72
  case 'ECDH-ES':
66
73
  case 'ECDH-ES+A128KW':
67
74
  case 'ECDH-ES+A192KW':
@@ -1,8 +1,8 @@
1
1
  import { decode as decodeBase64URL } from '../util/base64url.js';
2
2
  import { fromSPKI, fromPKCS8, fromX509 } from '../lib/asn1.js';
3
- import toCryptoKey from '../lib/jwk_to_key.js';
3
+ import { jwkToKey } from '../lib/jwk_to_key.js';
4
4
  import { JOSENotSupported } from '../util/errors.js';
5
- import isObject from '../lib/is_object.js';
5
+ import { isObject } from '../lib/is_object.js';
6
6
  export async function importSPKI(spki, alg, options) {
7
7
  if (typeof spki !== 'string' || spki.indexOf('-----BEGIN PUBLIC KEY-----') !== 0) {
8
8
  throw new TypeError('"spki" must be SPKI formatted string');
@@ -38,9 +38,19 @@ export async function importJWK(jwk, alg, options) {
38
38
  if ('oth' in jwk && jwk.oth !== undefined) {
39
39
  throw new JOSENotSupported('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
40
40
  }
41
+ return jwkToKey({ ...jwk, alg, ext });
42
+ case 'AKP': {
43
+ if (typeof jwk.alg !== 'string' || !jwk.alg) {
44
+ throw new TypeError('missing "alg" (Algorithm) Parameter value');
45
+ }
46
+ if (alg !== undefined && alg !== jwk.alg) {
47
+ throw new TypeError('JWK alg and alg option value mismatch');
48
+ }
49
+ return jwkToKey({ ...jwk, ext });
50
+ }
41
51
  case 'EC':
42
52
  case 'OKP':
43
- return toCryptoKey({ ...jwk, alg, ext });
53
+ return jwkToKey({ ...jwk, alg, ext });
44
54
  default:
45
55
  throw new JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
46
56
  }
@@ -1,9 +1,9 @@
1
- import encrypt from './encrypt.js';
2
- import decrypt from './decrypt.js';
1
+ import { encrypt } from './encrypt.js';
2
+ import { decrypt } from './decrypt.js';
3
3
  import { encode as b64u } from '../util/base64url.js';
4
4
  export async function wrap(alg, key, cek, iv) {
5
5
  const jweAlgorithm = alg.slice(0, 7);
6
- const wrapped = await encrypt(jweAlgorithm, cek, key, iv, new Uint8Array(0));
6
+ const wrapped = await encrypt(jweAlgorithm, cek, key, iv, new Uint8Array());
7
7
  return {
8
8
  encryptedKey: wrapped.ciphertext,
9
9
  iv: b64u(wrapped.iv),
@@ -12,5 +12,5 @@ export async function wrap(alg, key, cek, iv) {
12
12
  }
13
13
  export async function unwrap(alg, key, encryptedKey, iv, tag) {
14
14
  const jweAlgorithm = alg.slice(0, 7);
15
- return decrypt(jweAlgorithm, key, encryptedKey, iv, tag, new Uint8Array(0));
15
+ return decrypt(jweAlgorithm, key, encryptedKey, iv, tag, new Uint8Array());
16
16
  }
@@ -1,4 +1,4 @@
1
- import invalidKeyInput from './invalid_key_input.js';
1
+ import { invalidKeyInput } from './invalid_key_input.js';
2
2
  import { encodeBase64, decodeBase64 } from '../lib/base64.js';
3
3
  import { JOSENotSupported } from '../util/errors.js';
4
4
  import { isCryptoKey, isKeyObject } from './is_key_like.js';
@@ -24,12 +24,8 @@ const genericExport = async (keyType, keyFormat, key) => {
24
24
  }
25
25
  return formatPEM(encodeBase64(new Uint8Array(await crypto.subtle.exportKey(keyFormat, key))), `${keyType.toUpperCase()} KEY`);
26
26
  };
27
- export const toSPKI = (key) => {
28
- return genericExport('public', 'spki', key);
29
- };
30
- export const toPKCS8 = (key) => {
31
- return genericExport('private', 'pkcs8', key);
32
- };
27
+ export const toSPKI = (key) => genericExport('public', 'spki', key);
28
+ export const toPKCS8 = (key) => genericExport('private', 'pkcs8', key);
33
29
  const bytesEqual = (a, b) => {
34
30
  if (a.byteLength !== b.length)
35
31
  return false;
@@ -174,6 +170,12 @@ const genericImport = async (keyFormat, keyData, alg, options) => {
174
170
  algorithm = { name: 'Ed25519' };
175
171
  keyUsages = getSigUsages();
176
172
  break;
173
+ case 'ML-DSA-44':
174
+ case 'ML-DSA-65':
175
+ case 'ML-DSA-87':
176
+ algorithm = { name: alg };
177
+ keyUsages = getSigUsages();
178
+ break;
177
179
  default:
178
180
  throw new JOSENotSupported('Invalid or unsupported "alg" (Algorithm) value');
179
181
  }
@@ -30,3 +30,14 @@ export function uint32be(value) {
30
30
  writeUInt32BE(buf, value);
31
31
  return buf;
32
32
  }
33
+ export function encode(string) {
34
+ const bytes = new Uint8Array(string.length);
35
+ for (let i = 0; i < string.length; i++) {
36
+ const code = string.charCodeAt(i);
37
+ if (code > 127) {
38
+ throw new TypeError('non-ASCII string encountered in encode()');
39
+ }
40
+ bytes[i] = code;
41
+ }
42
+ return bytes;
43
+ }
@@ -1,5 +1,5 @@
1
1
  import { JOSENotSupported } from '../util/errors.js';
2
- export function bitLength(alg) {
2
+ export function cekLength(alg) {
3
3
  switch (alg) {
4
4
  case 'A128GCM':
5
5
  return 128;
@@ -16,4 +16,4 @@ export function bitLength(alg) {
16
16
  throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
17
17
  }
18
18
  }
19
- export default (alg) => crypto.getRandomValues(new Uint8Array(bitLength(alg) >> 3));
19
+ export const generateCek = (alg) => crypto.getRandomValues(new Uint8Array(cekLength(alg) >> 3));
@@ -1,7 +1,7 @@
1
1
  import { JWEInvalid } from '../util/errors.js';
2
- export default (cek, expected) => {
2
+ export function checkCekLength(cek, expected) {
3
3
  const actual = cek.byteLength << 3;
4
4
  if (actual !== expected) {
5
5
  throw new JWEInvalid(`Invalid Content Encryption Key length. Expected ${expected} bits, got ${actual} bits`);
6
6
  }
7
- };
7
+ }
@@ -1,7 +1,7 @@
1
1
  import { JWEInvalid } from '../util/errors.js';
2
2
  import { bitLength } from './iv.js';
3
- export default (enc, iv) => {
3
+ export function checkIvLength(enc, iv) {
4
4
  if (iv.length << 3 !== bitLength(enc)) {
5
5
  throw new JWEInvalid('Invalid Initialization Vector length');
6
6
  }
7
- };
7
+ }
@@ -1,8 +1,8 @@
1
- export default (alg, key) => {
1
+ export function checkKeyLength(alg, key) {
2
2
  if (alg.startsWith('RS') || alg.startsWith('PS')) {
3
3
  const { modulusLength } = key.algorithm;
4
4
  if (typeof modulusLength !== 'number' || modulusLength < 2048) {
5
5
  throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
6
6
  }
7
7
  }
8
- };
8
+ }
@@ -1,5 +1,5 @@
1
1
  import { withAlg as invalidKeyInput } from './invalid_key_input.js';
2
- import isKeyLike from './is_key_like.js';
2
+ import { isKeyLike } from './is_key_like.js';
3
3
  import * as jwk from './is_jwk.js';
4
4
  const tag = (key) => key?.[Symbol.toStringTag];
5
5
  const jwkMatchesOp = (alg, key, usage) => {
@@ -96,8 +96,6 @@ const asymmetricTypeCheck = (alg, key, usage) => {
96
96
  throw new TypeError(`${tag(key)} instances for asymmetric algorithm signing must be of type "private"`);
97
97
  case 'decrypt':
98
98
  throw new TypeError(`${tag(key)} instances for asymmetric algorithm decryption must be of type "private"`);
99
- default:
100
- break;
101
99
  }
102
100
  }
103
101
  if (key.type === 'private') {
@@ -106,21 +104,19 @@ const asymmetricTypeCheck = (alg, key, usage) => {
106
104
  throw new TypeError(`${tag(key)} instances for asymmetric algorithm verifying must be of type "public"`);
107
105
  case 'encrypt':
108
106
  throw new TypeError(`${tag(key)} instances for asymmetric algorithm encryption must be of type "public"`);
109
- default:
110
- break;
111
107
  }
112
108
  }
113
109
  };
114
- export default (alg, key, usage) => {
115
- const symmetric = alg.startsWith('HS') ||
116
- alg === 'dir' ||
117
- alg.startsWith('PBES2') ||
118
- /^A(?:128|192|256)(?:GCM)?(?:KW)?$/.test(alg) ||
119
- /^A(?:128|192|256)CBC-HS(?:256|384|512)$/.test(alg);
120
- if (symmetric) {
121
- symmetricTypeCheck(alg, key, usage);
110
+ export function checkKeyType(alg, key, usage) {
111
+ switch (alg.substring(0, 2)) {
112
+ case 'A1':
113
+ case 'A2':
114
+ case 'di':
115
+ case 'HS':
116
+ case 'PB':
117
+ symmetricTypeCheck(alg, key, usage);
118
+ break;
119
+ default:
120
+ asymmetricTypeCheck(alg, key, usage);
122
121
  }
123
- else {
124
- asymmetricTypeCheck(alg, key, usage);
125
- }
126
- };
122
+ }
@@ -1,9 +1,5 @@
1
- function unusable(name, prop = 'algorithm.name') {
2
- return new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
3
- }
4
- function isAlgorithm(algorithm, name) {
5
- return algorithm.name === name;
6
- }
1
+ const unusable = (name, prop = 'algorithm.name') => new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
2
+ const isAlgorithm = (algorithm, name) => algorithm.name === name;
7
3
  function getHashLength(hash) {
8
4
  return parseInt(hash.name.slice(4), 10);
9
5
  }
@@ -65,6 +61,13 @@ export function checkSigCryptoKey(key, alg, usage) {
65
61
  throw unusable('Ed25519');
66
62
  break;
67
63
  }
64
+ case 'ML-DSA-44':
65
+ case 'ML-DSA-65':
66
+ case 'ML-DSA-87': {
67
+ if (!isAlgorithm(key.algorithm, alg))
68
+ throw unusable(alg);
69
+ break;
70
+ }
68
71
  case 'ES256':
69
72
  case 'ES384':
70
73
  case 'ES512': {
@@ -1,9 +1,9 @@
1
1
  import { concat, uint64be } from './buffer_utils.js';
2
- import checkIvLength from './check_iv_length.js';
3
- import checkCekLength from './check_cek_length.js';
2
+ import { checkIvLength } from './check_iv_length.js';
3
+ import { checkCekLength } from './check_cek_length.js';
4
4
  import { JOSENotSupported, JWEDecryptionFailed, JWEInvalid } from '../util/errors.js';
5
5
  import { checkEncCryptoKey } from './crypto_key.js';
6
- import invalidKeyInput from './invalid_key_input.js';
6
+ import { invalidKeyInput } from './invalid_key_input.js';
7
7
  import { isCryptoKey } from './is_key_like.js';
8
8
  async function timingSafeEqual(a, b) {
9
9
  if (!(a instanceof Uint8Array)) {
@@ -46,7 +46,7 @@ async function cbcDecrypt(enc, cek, ciphertext, iv, tag, aad) {
46
46
  }
47
47
  let plaintext;
48
48
  try {
49
- plaintext = new Uint8Array(await crypto.subtle.decrypt({ iv, name: 'AES-CBC' }, encKey, ciphertext));
49
+ plaintext = new Uint8Array(await crypto.subtle.decrypt({ iv: iv, name: 'AES-CBC' }, encKey, ciphertext));
50
50
  }
51
51
  catch {
52
52
  }
@@ -67,7 +67,7 @@ async function gcmDecrypt(enc, cek, ciphertext, iv, tag, aad) {
67
67
  try {
68
68
  return new Uint8Array(await crypto.subtle.decrypt({
69
69
  additionalData: aad,
70
- iv,
70
+ iv: iv,
71
71
  name: 'AES-GCM',
72
72
  tagLength: 128,
73
73
  }, encKey, concat(ciphertext, tag)));
@@ -76,7 +76,7 @@ async function gcmDecrypt(enc, cek, ciphertext, iv, tag, aad) {
76
76
  throw new JWEDecryptionFailed();
77
77
  }
78
78
  }
79
- export default async (enc, cek, ciphertext, iv, tag, aad) => {
79
+ export async function decrypt(enc, cek, ciphertext, iv, tag, aad) {
80
80
  if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) {
81
81
  throw new TypeError(invalidKeyInput(cek, 'CryptoKey', 'KeyObject', 'Uint8Array', 'JSON Web Key'));
82
82
  }
@@ -103,4 +103,4 @@ export default async (enc, cek, ciphertext, iv, tag, aad) => {
103
103
  default:
104
104
  throw new JOSENotSupported('Unsupported JWE Content Encryption Algorithm');
105
105
  }
106
- };
106
+ }
@@ -4,12 +4,12 @@ import * as pbes2kw from './pbes2kw.js';
4
4
  import * as rsaes from './rsaes.js';
5
5
  import { decode as b64u } from '../util/base64url.js';
6
6
  import { JOSENotSupported, JWEInvalid } from '../util/errors.js';
7
- import { bitLength as cekLength } from '../lib/cek.js';
7
+ import { cekLength } from '../lib/cek.js';
8
8
  import { importJWK } from '../key/import.js';
9
- import isObject from './is_object.js';
9
+ import { isObject } from './is_object.js';
10
10
  import { unwrap as aesGcmKw } from './aesgcmkw.js';
11
11
  import { assertCryptoKey } from './is_key_like.js';
12
- export default async (alg, key, encryptedKey, joseHeader, options) => {
12
+ export async function decryptKeyManagement(alg, key, encryptedKey, joseHeader, options) {
13
13
  switch (alg) {
14
14
  case 'dir': {
15
15
  if (encryptedKey !== undefined)
@@ -124,4 +124,4 @@ export default async (alg, key, encryptedKey, joseHeader, options) => {
124
124
  throw new JOSENotSupported('Invalid or unsupported "alg" (JWE Algorithm) header value');
125
125
  }
126
126
  }
127
- };
127
+ }
@@ -1,4 +1,4 @@
1
- export default async (algorithm, data) => {
1
+ export async function digest(algorithm, data) {
2
2
  const subtleDigest = `SHA-${algorithm.slice(-3)}`;
3
3
  return new Uint8Array(await crypto.subtle.digest(subtleDigest, data));
4
- };
4
+ }
@@ -1,6 +1,6 @@
1
- import { encoder, concat, uint32be } from './buffer_utils.js';
1
+ import { encode, concat, uint32be } from './buffer_utils.js';
2
2
  import { checkEncCryptoKey } from './crypto_key.js';
3
- import digest from './digest.js';
3
+ import { digest } from './digest.js';
4
4
  function lengthAndInput(input) {
5
5
  return concat(uint32be(input.length), input);
6
6
  }
@@ -19,14 +19,14 @@ async function concatKdf(Z, L, OtherInfo) {
19
19
  }
20
20
  return dk.slice(0, dkLen);
21
21
  }
22
- export async function deriveKey(publicKey, privateKey, algorithm, keyLength, apu = new Uint8Array(0), apv = new Uint8Array(0)) {
22
+ export async function deriveKey(publicKey, privateKey, algorithm, keyLength, apu = new Uint8Array(), apv = new Uint8Array()) {
23
23
  checkEncCryptoKey(publicKey, 'ECDH');
24
24
  checkEncCryptoKey(privateKey, 'ECDH', 'deriveBits');
25
- const algorithmID = lengthAndInput(encoder.encode(algorithm));
25
+ const algorithmID = lengthAndInput(encode(algorithm));
26
26
  const partyUInfo = lengthAndInput(apu);
27
27
  const partyVInfo = lengthAndInput(apv);
28
28
  const suppPubInfo = uint32be(keyLength);
29
- const suppPrivInfo = new Uint8Array(0);
29
+ const suppPrivInfo = new Uint8Array();
30
30
  const otherInfo = concat(algorithmID, partyUInfo, partyVInfo, suppPubInfo, suppPrivInfo);
31
31
  const Z = new Uint8Array(await crypto.subtle.deriveBits({
32
32
  name: publicKey.algorithm.name,
@@ -1,9 +1,9 @@
1
1
  import { concat, uint64be } from './buffer_utils.js';
2
- import checkIvLength from './check_iv_length.js';
3
- import checkCekLength from './check_cek_length.js';
2
+ import { checkIvLength } from './check_iv_length.js';
3
+ import { checkCekLength } from './check_cek_length.js';
4
4
  import { checkEncCryptoKey } from './crypto_key.js';
5
- import invalidKeyInput from './invalid_key_input.js';
6
- import generateIv from './iv.js';
5
+ import { invalidKeyInput } from './invalid_key_input.js';
6
+ import { generateIv } from './iv.js';
7
7
  import { JOSENotSupported } from '../util/errors.js';
8
8
  import { isCryptoKey } from './is_key_like.js';
9
9
  async function cbcEncrypt(enc, plaintext, cek, iv, aad) {
@@ -17,7 +17,7 @@ async function cbcEncrypt(enc, plaintext, cek, iv, aad) {
17
17
  name: 'HMAC',
18
18
  }, false, ['sign']);
19
19
  const ciphertext = new Uint8Array(await crypto.subtle.encrypt({
20
- iv,
20
+ iv: iv,
21
21
  name: 'AES-CBC',
22
22
  }, encKey, plaintext));
23
23
  const macData = concat(aad, iv, ciphertext, uint64be(aad.length << 3));
@@ -35,7 +35,7 @@ async function gcmEncrypt(enc, plaintext, cek, iv, aad) {
35
35
  }
36
36
  const encrypted = new Uint8Array(await crypto.subtle.encrypt({
37
37
  additionalData: aad,
38
- iv,
38
+ iv: iv,
39
39
  name: 'AES-GCM',
40
40
  tagLength: 128,
41
41
  }, encKey, plaintext));
@@ -43,7 +43,7 @@ async function gcmEncrypt(enc, plaintext, cek, iv, aad) {
43
43
  const ciphertext = encrypted.slice(0, -16);
44
44
  return { ciphertext, tag, iv };
45
45
  }
46
- export default async (enc, plaintext, cek, iv, aad) => {
46
+ export async function encrypt(enc, plaintext, cek, iv, aad) {
47
47
  if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) {
48
48
  throw new TypeError(invalidKeyInput(cek, 'CryptoKey', 'KeyObject', 'Uint8Array', 'JSON Web Key'));
49
49
  }
@@ -71,4 +71,4 @@ export default async (enc, plaintext, cek, iv, aad) => {
71
71
  default:
72
72
  throw new JOSENotSupported('Unsupported JWE Content Encryption Algorithm');
73
73
  }
74
- };
74
+ }
@@ -3,13 +3,13 @@ import * as ecdhes from './ecdhes.js';
3
3
  import * as pbes2kw from './pbes2kw.js';
4
4
  import * as rsaes from './rsaes.js';
5
5
  import { encode as b64u } from '../util/base64url.js';
6
- import normalizeKey from './normalize_key.js';
7
- import generateCek, { bitLength as cekLength } from '../lib/cek.js';
6
+ import { normalizeKey } from './normalize_key.js';
7
+ import { generateCek, cekLength } from '../lib/cek.js';
8
8
  import { JOSENotSupported } from '../util/errors.js';
9
9
  import { exportJWK } from '../key/export.js';
10
10
  import { wrap as aesGcmKw } from './aesgcmkw.js';
11
11
  import { assertCryptoKey } from './is_key_like.js';
12
- export default async (alg, enc, key, providedCek, providedParameters = {}) => {
12
+ export async function encryptKeyManagement(alg, enc, key, providedCek, providedParameters = {}) {
13
13
  let encryptedKey;
14
14
  let parameters;
15
15
  let cek;
@@ -89,4 +89,4 @@ export default async (alg, enc, key, providedCek, providedParameters = {}) => {
89
89
  }
90
90
  }
91
91
  return { cek, encryptedKey, parameters };
92
- };
92
+ }
@@ -1,6 +1,6 @@
1
1
  import { checkSigCryptoKey } from './crypto_key.js';
2
- import invalidKeyInput from './invalid_key_input.js';
3
- export default async (alg, key, usage) => {
2
+ import { invalidKeyInput } from './invalid_key_input.js';
3
+ export async function getSigKey(alg, key, usage) {
4
4
  if (key instanceof Uint8Array) {
5
5
  if (!alg.startsWith('HS')) {
6
6
  throw new TypeError(invalidKeyInput(key, 'CryptoKey', 'KeyObject', 'JSON Web Key'));
@@ -9,4 +9,4 @@ export default async (alg, key, usage) => {
9
9
  }
10
10
  checkSigCryptoKey(key, alg, usage);
11
11
  return key;
12
- };
12
+ }
@@ -23,9 +23,5 @@ function message(msg, actual, ...types) {
23
23
  }
24
24
  return msg;
25
25
  }
26
- export default (actual, ...types) => {
27
- return message('Key must be ', actual, ...types);
28
- };
29
- export function withAlg(alg, actual, ...types) {
30
- return message(`Key for the ${alg} algorithm must be `, actual, ...types);
31
- }
26
+ export const invalidKeyInput = (actual, ...types) => message('Key must be ', actual, ...types);
27
+ export const withAlg = (alg, actual, ...types) => message(`Key for the ${alg} algorithm must be `, actual, ...types);
@@ -1,4 +1,4 @@
1
- export default (...headers) => {
1
+ export function isDisjoint(...headers) {
2
2
  const sources = headers.filter(Boolean);
3
3
  if (sources.length === 0 || sources.length === 1) {
4
4
  return true;
@@ -18,4 +18,4 @@ export default (...headers) => {
18
18
  }
19
19
  }
20
20
  return true;
21
- };
21
+ }
@@ -1,13 +1,6 @@
1
- import isObject from './is_object.js';
2
- export function isJWK(key) {
3
- return isObject(key) && typeof key.kty === 'string';
4
- }
5
- export function isPrivateJWK(key) {
6
- return key.kty !== 'oct' && typeof key.d === 'string';
7
- }
8
- export function isPublicJWK(key) {
9
- return key.kty !== 'oct' && typeof key.d === 'undefined';
10
- }
11
- export function isSecretJWK(key) {
12
- return key.kty === 'oct' && typeof key.k === 'string';
13
- }
1
+ import { isObject } from './is_object.js';
2
+ export const isJWK = (key) => isObject(key) && typeof key.kty === 'string';
3
+ export const isPrivateJWK = (key) => key.kty !== 'oct' &&
4
+ ((key.kty === 'AKP' && typeof key.priv === 'string') || typeof key.d === 'string');
5
+ export const isPublicJWK = (key) => key.kty !== 'oct' && key.d === undefined && key.priv === undefined;
6
+ export const isSecretJWK = (key) => key.kty === 'oct' && typeof key.k === 'string';
@@ -3,12 +3,6 @@ export function assertCryptoKey(key) {
3
3
  throw new Error('CryptoKey instance expected');
4
4
  }
5
5
  }
6
- export function isCryptoKey(key) {
7
- return key?.[Symbol.toStringTag] === 'CryptoKey';
8
- }
9
- export function isKeyObject(key) {
10
- return key?.[Symbol.toStringTag] === 'KeyObject';
11
- }
12
- export default (key) => {
13
- return isCryptoKey(key) || isKeyObject(key);
14
- };
6
+ export const isCryptoKey = (key) => key?.[Symbol.toStringTag] === 'CryptoKey';
7
+ export const isKeyObject = (key) => key?.[Symbol.toStringTag] === 'KeyObject';
8
+ export const isKeyLike = (key) => isCryptoKey(key) || isKeyObject(key);
@@ -1,7 +1,5 @@
1
- function isObjectLike(value) {
2
- return typeof value === 'object' && value !== null;
3
- }
4
- export default (input) => {
1
+ const isObjectLike = (value) => typeof value === 'object' && value !== null;
2
+ export function isObject(input) {
5
3
  if (!isObjectLike(input) || Object.prototype.toString.call(input) !== '[object Object]') {
6
4
  return false;
7
5
  }
@@ -13,4 +11,4 @@ export default (input) => {
13
11
  proto = Object.getPrototypeOf(proto);
14
12
  }
15
13
  return Object.getPrototypeOf(input) === proto;
16
- };
14
+ }
@@ -16,4 +16,4 @@ export function bitLength(alg) {
16
16
  throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
17
17
  }
18
18
  }
19
- export default (alg) => crypto.getRandomValues(new Uint8Array(bitLength(alg) >> 3));
19
+ export const generateIv = (alg) => crypto.getRandomValues(new Uint8Array(bitLength(alg) >> 3));
@@ -3,6 +3,19 @@ function subtleMapping(jwk) {
3
3
  let algorithm;
4
4
  let keyUsages;
5
5
  switch (jwk.kty) {
6
+ case 'AKP': {
7
+ switch (jwk.alg) {
8
+ case 'ML-DSA-44':
9
+ case 'ML-DSA-65':
10
+ case 'ML-DSA-87':
11
+ algorithm = { name: jwk.alg };
12
+ keyUsages = jwk.priv ? ['sign'] : ['verify'];
13
+ break;
14
+ default:
15
+ throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
16
+ }
17
+ break;
18
+ }
6
19
  case 'RSA': {
7
20
  switch (jwk.alg) {
8
21
  case 'PS256':
@@ -82,13 +95,15 @@ function subtleMapping(jwk) {
82
95
  }
83
96
  return { algorithm, keyUsages };
84
97
  }
85
- export default async (jwk) => {
98
+ export async function jwkToKey(jwk) {
86
99
  if (!jwk.alg) {
87
100
  throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
88
101
  }
89
102
  const { algorithm, keyUsages } = subtleMapping(jwk);
90
103
  const keyData = { ...jwk };
91
- delete keyData.alg;
104
+ if (keyData.kty !== 'AKP') {
105
+ delete keyData.alg;
106
+ }
92
107
  delete keyData.use;
93
- return crypto.subtle.importKey('jwk', keyData, algorithm, jwk.ext ?? (jwk.d ? false : true), jwk.key_ops ?? keyUsages);
94
- };
108
+ return crypto.subtle.importKey('jwk', keyData, algorithm, jwk.ext ?? (jwk.d || jwk.priv ? false : true), jwk.key_ops ?? keyUsages);
109
+ }