jose 6.2.10 → 6.2.12

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 (89) hide show
  1. package/dist/types/index.d.ts +1 -2
  2. package/dist/types/jwe/compact/decrypt.d.ts +12 -25
  3. package/dist/types/jwe/compact/encrypt.d.ts +18 -32
  4. package/dist/types/jwe/flattened/decrypt.d.ts +12 -25
  5. package/dist/types/jwe/flattened/encrypt.d.ts +24 -50
  6. package/dist/types/jwe/general/decrypt.d.ts +15 -30
  7. package/dist/types/jwe/general/encrypt.d.ts +29 -52
  8. package/dist/types/jwk/embedded.d.ts +5 -8
  9. package/dist/types/jwk/thumbprint.d.ts +7 -9
  10. package/dist/types/jwks/local.d.ts +10 -13
  11. package/dist/types/jwks/remote.d.ts +29 -41
  12. package/dist/types/jws/compact/sign.d.ts +8 -13
  13. package/dist/types/jws/compact/verify.d.ts +14 -26
  14. package/dist/types/jws/flattened/sign.d.ts +10 -19
  15. package/dist/types/jws/flattened/verify.d.ts +14 -26
  16. package/dist/types/jws/general/sign.d.ts +19 -33
  17. package/dist/types/jws/general/verify.d.ts +17 -32
  18. package/dist/types/jwt/decrypt.d.ts +20 -27
  19. package/dist/types/jwt/encrypt.d.ts +30 -35
  20. package/dist/types/jwt/sign.d.ts +8 -13
  21. package/dist/types/jwt/unsecured.d.ts +10 -19
  22. package/dist/types/jwt/verify.d.ts +19 -22
  23. package/dist/types/key/export.d.ts +10 -10
  24. package/dist/types/key/generate_key_pair.d.ts +15 -22
  25. package/dist/types/key/generate_secret.d.ts +12 -19
  26. package/dist/types/key/import.d.ts +25 -31
  27. package/dist/types/types.d.ts +184 -319
  28. package/dist/types/util/base64url.d.ts +7 -7
  29. package/dist/types/util/decode_jwt.d.ts +5 -7
  30. package/dist/types/util/decode_protected_header.d.ts +6 -5
  31. package/dist/types/util/errors.d.ts +50 -88
  32. package/dist/webapi/index.js +70 -32
  33. package/dist/webapi/jwe/compact/decrypt.js +6 -8
  34. package/dist/webapi/jwe/compact/encrypt.js +25 -48
  35. package/dist/webapi/jwe/flattened/decrypt.js +14 -14
  36. package/dist/webapi/jwe/flattened/encrypt.js +34 -64
  37. package/dist/webapi/jwe/general/decrypt.js +38 -49
  38. package/dist/webapi/jwe/general/encrypt.js +100 -172
  39. package/dist/webapi/jwk/embedded.js +29 -32
  40. package/dist/webapi/jwk/thumbprint.js +51 -70
  41. package/dist/webapi/jwks/local.js +53 -64
  42. package/dist/webapi/jwks/remote.js +88 -136
  43. package/dist/webapi/jws/compact/sign.js +19 -21
  44. package/dist/webapi/jws/compact/verify.js +7 -8
  45. package/dist/webapi/jws/flattened/sign.js +22 -31
  46. package/dist/webapi/jws/flattened/verify.js +11 -24
  47. package/dist/webapi/jws/general/sign.js +55 -73
  48. package/dist/webapi/jws/general/verify.js +43 -69
  49. package/dist/webapi/jwt/decrypt.js +12 -20
  50. package/dist/webapi/jwt/encrypt.js +43 -70
  51. package/dist/webapi/jwt/sign.js +17 -16
  52. package/dist/webapi/jwt/unsecured.js +31 -40
  53. package/dist/webapi/jwt/verify.js +12 -14
  54. package/dist/webapi/key/export.js +32 -41
  55. package/dist/webapi/key/generate_key_pair.js +32 -49
  56. package/dist/webapi/key/generate_secret.js +35 -40
  57. package/dist/webapi/key/import.js +48 -56
  58. package/dist/webapi/lib/asn1.js +128 -169
  59. package/dist/webapi/lib/buffer_utils.js +72 -41
  60. package/dist/webapi/lib/content_encryption.js +75 -119
  61. package/dist/webapi/lib/deflate.js +35 -47
  62. package/dist/webapi/lib/jwe_algorithms.js +102 -93
  63. package/dist/webapi/lib/jwe_decrypt.js +178 -234
  64. package/dist/webapi/lib/jwe_encrypt.js +71 -138
  65. package/dist/webapi/lib/jws_algorithms.js +62 -61
  66. package/dist/webapi/lib/jws_sign.js +43 -82
  67. package/dist/webapi/lib/jws_verify.js +78 -131
  68. package/dist/webapi/lib/jwt_claims_set.js +123 -209
  69. package/dist/webapi/lib/key.js +147 -139
  70. package/dist/webapi/lib/key_algorithm.js +13 -8
  71. package/dist/webapi/lib/key_descriptor.js +8 -6
  72. package/dist/webapi/lib/key_management.js +169 -235
  73. package/dist/webapi/lib/validate.js +122 -0
  74. package/dist/webapi/util/base64url.js +14 -37
  75. package/dist/webapi/util/decode_jwt.js +32 -31
  76. package/dist/webapi/util/decode_protected_header.js +18 -23
  77. package/dist/webapi/util/errors.js +94 -84
  78. package/package.json +17 -81
  79. package/dist/webapi/lib/base64.js +0 -22
  80. package/dist/webapi/lib/crypto_key.js +0 -28
  81. package/dist/webapi/lib/helpers.js +0 -42
  82. package/dist/webapi/lib/invalid_key_input.js +0 -26
  83. package/dist/webapi/lib/is_key_like.js +0 -17
  84. package/dist/webapi/lib/jwk_metadata.js +0 -20
  85. package/dist/webapi/lib/jwk_to_key.js +0 -17
  86. package/dist/webapi/lib/key_options.js +0 -6
  87. package/dist/webapi/lib/options.js +0 -74
  88. package/dist/webapi/lib/signing.js +0 -26
  89. package/dist/webapi/lib/type_checks.js +0 -33
@@ -1,134 +1,90 @@
1
- import { concat, uint64be } from './buffer_utils.js';
2
- import { checkCryptoKey } from './crypto_key.js';
3
- import { invalidKeyInput } from './invalid_key_input.js';
4
- import { JWEDecryptionFailed, JWEInvalid } from '../util/errors.js';
5
- import { isCryptoKey } from './is_key_like.js';
6
- export const generateCek = (enc) => crypto.getRandomValues(new Uint8Array(enc.cekBits >> 3));
1
+ import { concat, uint64be } from "./buffer_utils.js";
2
+ import { rawKey, invalidKeyInput, isCryptoKey } from "./key.js";
3
+ import { JWEDecryptionFailed, JWEInvalid } from "../util/errors.js";
4
+ const generateCek = (enc) => crypto.getRandomValues(new Uint8Array(enc.cekBits >> 3));
7
5
  function checkCekLength(cek, expected) {
8
- const actual = cek.byteLength << 3;
9
- if (actual !== expected) {
10
- throw new JWEInvalid(`Invalid Content Encryption Key length. Expected ${expected} bits, got ${actual} bits`);
11
- }
6
+ const actual = cek.byteLength << 3;
7
+ if (actual !== expected)
8
+ throw new JWEInvalid(`Invalid Content Encryption Key length. Expected ${expected} bits, got ${actual} bits`);
12
9
  }
13
- export const generateIv = (enc) => crypto.getRandomValues(new Uint8Array(enc.ivBits >> 3));
14
- export function checkIvLength(enc, iv) {
15
- if (iv.length << 3 !== enc.ivBits) {
16
- throw new JWEInvalid('Invalid Initialization Vector length');
17
- }
10
+ const generateIv = (enc) => crypto.getRandomValues(new Uint8Array(enc.ivBits >> 3));
11
+ function checkIvLength(enc, iv) {
12
+ if (iv.length << 3 !== enc.ivBits)
13
+ throw new JWEInvalid("Invalid Initialization Vector length");
18
14
  }
19
15
  async function cbcKeySetup(enc, cek, usage) {
20
- if (!(cek instanceof Uint8Array)) {
21
- throw new TypeError(invalidKeyInput(cek, 'Uint8Array'));
22
- }
23
- const keySize = enc.cekBits >> 1;
24
- const encKey = await crypto.subtle.importKey('raw', cek.subarray(keySize >> 3), 'AES-CBC', false, [usage]);
25
- const macKey = await crypto.subtle.importKey('raw', cek.subarray(0, keySize >> 3), {
26
- hash: `SHA-${keySize << 1}`,
27
- name: 'HMAC',
28
- }, false, ['sign']);
29
- return [encKey, macKey, keySize];
16
+ if (!(cek instanceof Uint8Array))
17
+ throw new TypeError(invalidKeyInput(cek, "Uint8Array"));
18
+ const keySize = enc.cekBits >> 1, encKey = await crypto.subtle.importKey("raw", cek.subarray(keySize >> 3), "AES-CBC", !1, [usage]), macKey = await crypto.subtle.importKey("raw", cek.subarray(0, keySize >> 3), {
19
+ hash: `SHA-${keySize << 1}`,
20
+ name: "HMAC"
21
+ }, !1, ["sign"]);
22
+ return [encKey, macKey, keySize];
30
23
  }
31
24
  async function cbcHmacTag(macKey, macData, keySize) {
32
- return new Uint8Array((await crypto.subtle.sign('HMAC', macKey, macData)).slice(0, keySize >> 3));
25
+ return new Uint8Array((await crypto.subtle.sign("HMAC", macKey, macData)).slice(0, keySize >> 3));
33
26
  }
34
27
  async function cbcEncrypt(enc, plaintext, cek, iv, aad) {
35
- const [encKey, macKey, keySize] = await cbcKeySetup(enc, cek, 'encrypt');
36
- const ciphertext = new Uint8Array(await crypto.subtle.encrypt({
37
- iv: iv,
38
- name: 'AES-CBC',
39
- }, encKey, plaintext));
40
- const macData = concat(aad, iv, ciphertext, uint64be(aad.length * 8));
41
- const tag = await cbcHmacTag(macKey, macData, keySize);
42
- return { ciphertext, tag, iv };
28
+ const [encKey, macKey, keySize] = await cbcKeySetup(enc, cek, "encrypt"), ciphertext = new Uint8Array(await crypto.subtle.encrypt({
29
+ iv,
30
+ name: "AES-CBC"
31
+ }, encKey, plaintext)), macData = concat(aad, iv, ciphertext, uint64be(aad.length * 8)), tag = await cbcHmacTag(macKey, macData, keySize);
32
+ return { ciphertext, tag, iv };
43
33
  }
44
34
  async function timingSafeEqual(a, b) {
45
- const algorithm = { name: 'HMAC', hash: 'SHA-256' };
46
- const key = (await crypto.subtle.generateKey(algorithm, false, ['sign', 'verify']));
47
- const aHmac = await crypto.subtle.sign(algorithm, key, a);
48
- return crypto.subtle.verify(algorithm, key, aHmac, b);
35
+ const algorithm = { name: "HMAC", hash: "SHA-256" }, key = await crypto.subtle.generateKey(algorithm, !1, ["sign", "verify"]), aHmac = await crypto.subtle.sign(algorithm, key, a);
36
+ return crypto.subtle.verify(algorithm, key, aHmac, b);
49
37
  }
50
38
  async function cbcDecrypt(enc, cek, ciphertext, iv, tag, aad) {
51
- const [encKey, macKey, keySize] = await cbcKeySetup(enc, cek, 'decrypt');
52
- const macData = concat(aad, iv, ciphertext, uint64be(aad.length * 8));
53
- const expectedTag = await cbcHmacTag(macKey, macData, keySize);
54
- try {
55
- if (await timingSafeEqual(tag, expectedTag)) {
56
- return new Uint8Array(await crypto.subtle.decrypt({ iv: iv, name: 'AES-CBC' }, encKey, ciphertext));
57
- }
58
- }
59
- catch {
60
- }
61
- throw new JWEDecryptionFailed();
62
- }
63
- async function gcmEncrypt(enc, plaintext, cek, iv, aad) {
64
- const encKey = cek instanceof Uint8Array
65
- ? await crypto.subtle.importKey('raw', cek, 'AES-GCM', false, [
66
- 'encrypt',
67
- ])
68
- : (checkCryptoKey(cek, enc.subtle, 'encrypt'), cek);
69
- const encrypted = new Uint8Array(await crypto.subtle.encrypt({
70
- additionalData: aad,
71
- iv: iv,
72
- name: 'AES-GCM',
73
- tagLength: 128,
74
- }, encKey, plaintext));
75
- const tag = encrypted.slice(-16);
76
- const ciphertext = encrypted.slice(0, -16);
77
- return { ciphertext, tag, iv };
39
+ const [encKey, macKey, keySize] = await cbcKeySetup(enc, cek, "decrypt"), macData = concat(aad, iv, ciphertext, uint64be(aad.length * 8)), expectedTag = await cbcHmacTag(macKey, macData, keySize);
40
+ try {
41
+ if (await timingSafeEqual(tag, expectedTag))
42
+ return new Uint8Array(await crypto.subtle.decrypt({ iv, name: "AES-CBC" }, encKey, ciphertext));
43
+ } catch {
44
+ }
45
+ throw new JWEDecryptionFailed();
78
46
  }
79
- async function gcmDecrypt(enc, cek, ciphertext, iv, tag, aad) {
80
- const encKey = cek instanceof Uint8Array
81
- ? await crypto.subtle.importKey('raw', cek, 'AES-GCM', false, [
82
- 'decrypt',
83
- ])
84
- : (checkCryptoKey(cek, enc.subtle, 'decrypt'), cek);
85
- try {
86
- return new Uint8Array(await crypto.subtle.decrypt({
87
- additionalData: aad,
88
- iv: iv,
89
- name: 'AES-GCM',
90
- tagLength: 128,
91
- }, encKey, concat(ciphertext, tag)));
92
- }
93
- catch {
94
- throw new JWEDecryptionFailed();
95
- }
47
+ async function encrypt(enc, plaintext, cek, iv, aad) {
48
+ if (!isCryptoKey(cek) && !(cek instanceof Uint8Array))
49
+ throw new TypeError(invalidKeyInput(cek, "CryptoKey", "KeyObject", "Uint8Array", "JSON Web Key"));
50
+ if (iv ? checkIvLength(enc, iv) : iv = generateIv(enc), cek instanceof Uint8Array && checkCekLength(cek, enc.cekBits), enc.cbc)
51
+ return cbcEncrypt(enc, plaintext, cek, iv, aad);
52
+ const encKey = await rawKey(cek, enc.subtle, "encrypt"), encrypted = new Uint8Array(await crypto.subtle.encrypt({
53
+ additionalData: aad,
54
+ iv,
55
+ name: "AES-GCM",
56
+ tagLength: 128
57
+ }, encKey, plaintext));
58
+ return { ciphertext: encrypted.subarray(0, -16), tag: encrypted.subarray(-16), iv };
96
59
  }
97
- export async function encrypt(enc, plaintext, cek, iv, aad) {
98
- if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) {
99
- throw new TypeError(invalidKeyInput(cek, 'CryptoKey', 'KeyObject', 'Uint8Array', 'JSON Web Key'));
100
- }
101
- if (iv) {
102
- checkIvLength(enc, iv);
103
- }
104
- else {
105
- iv = generateIv(enc);
106
- }
107
- if (cek instanceof Uint8Array) {
108
- checkCekLength(cek, enc.cekBits);
109
- }
110
- return enc.cbc
111
- ? cbcEncrypt(enc, plaintext, cek, iv, aad)
112
- : gcmEncrypt(enc, plaintext, cek, iv, aad);
113
- }
114
- export async function decrypt(enc, cek, ciphertext, iv, tag, aad) {
115
- if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) {
116
- throw new TypeError(invalidKeyInput(cek, 'CryptoKey', 'KeyObject', 'Uint8Array', 'JSON Web Key'));
117
- }
118
- if (!iv) {
119
- throw new JWEInvalid('JWE Initialization Vector missing');
120
- }
121
- if (!tag) {
122
- throw new JWEInvalid('JWE Authentication Tag missing');
123
- }
124
- if (!enc.cbc && tag.length !== 16) {
125
- throw new JWEInvalid('Invalid Authentication Tag length');
126
- }
127
- checkIvLength(enc, iv);
128
- if (cek instanceof Uint8Array) {
129
- checkCekLength(cek, enc.cekBits);
130
- }
131
- return enc.cbc
132
- ? cbcDecrypt(enc, cek, ciphertext, iv, tag, aad)
133
- : gcmDecrypt(enc, cek, ciphertext, iv, tag, aad);
60
+ async function decrypt(enc, cek, ciphertext, iv, tag, aad) {
61
+ if (!isCryptoKey(cek) && !(cek instanceof Uint8Array))
62
+ throw new TypeError(invalidKeyInput(cek, "CryptoKey", "KeyObject", "Uint8Array", "JSON Web Key"));
63
+ if (!iv)
64
+ throw new JWEInvalid("JWE Initialization Vector missing");
65
+ if (!tag)
66
+ throw new JWEInvalid("JWE Authentication Tag missing");
67
+ if (!enc.cbc && tag.length !== 16)
68
+ throw new JWEInvalid("Invalid Authentication Tag length");
69
+ if (checkIvLength(enc, iv), cek instanceof Uint8Array && checkCekLength(cek, enc.cekBits), enc.cbc)
70
+ return cbcDecrypt(enc, cek, ciphertext, iv, tag, aad);
71
+ const encKey = await rawKey(cek, enc.subtle, "decrypt");
72
+ try {
73
+ return new Uint8Array(await crypto.subtle.decrypt({
74
+ additionalData: aad,
75
+ iv,
76
+ name: "AES-GCM",
77
+ tagLength: 128
78
+ }, encKey, concat(ciphertext, tag)));
79
+ } catch {
80
+ throw new JWEDecryptionFailed();
81
+ }
134
82
  }
83
+ export {
84
+ checkCekLength,
85
+ checkIvLength,
86
+ decrypt,
87
+ encrypt,
88
+ generateCek,
89
+ generateIv
90
+ };
@@ -1,52 +1,40 @@
1
- import { JOSENotSupported, JWEInvalid } from '../util/errors.js';
2
- import { concat } from './buffer_utils.js';
3
- export function validateZip(joseHeader, protectedHeader) {
4
- if (joseHeader.zip !== undefined && joseHeader.zip !== 'DEF') {
5
- throw new JOSENotSupported('Unsupported JWE "zip" (Compression Algorithm) Header Parameter value.');
6
- }
7
- if (joseHeader.zip !== undefined && !protectedHeader?.zip) {
8
- throw new JWEInvalid('JWE "zip" (Compression Algorithm) Header Parameter MUST be in a protected header.');
9
- }
1
+ import { JOSENotSupported, JWEInvalid } from "../util/errors.js";
2
+ import { concat } from "./buffer_utils.js";
3
+ function validateZip(joseHeader, protectedHeader) {
4
+ if (joseHeader.zip !== void 0 && joseHeader.zip !== "DEF")
5
+ throw new JOSENotSupported('Unsupported JWE "zip" (Compression Algorithm) Header Parameter value.');
6
+ if (joseHeader.zip !== void 0 && !protectedHeader?.zip)
7
+ throw new JWEInvalid('JWE "zip" (Compression Algorithm) Header Parameter MUST be in a protected header.');
10
8
  }
11
9
  function supported(name) {
12
- if (typeof globalThis[name] === 'undefined') {
13
- throw new JOSENotSupported(`JWE "zip" (Compression Algorithm) Header Parameter requires the ${name} API.`);
14
- }
10
+ if (typeof globalThis[name] > "u")
11
+ throw new JOSENotSupported(`JWE "zip" (Compression Algorithm) Header Parameter requires the ${name} API.`);
15
12
  }
16
- export async function compress(input) {
17
- supported('CompressionStream');
18
- const cs = new CompressionStream('deflate-raw');
19
- const writer = cs.writable.getWriter();
20
- writer.write(input).catch(() => { });
21
- writer.close().catch(() => { });
22
- const chunks = [];
23
- const reader = cs.readable.getReader();
24
- for (;;) {
25
- const { value, done } = await reader.read();
26
- if (done)
27
- break;
28
- chunks.push(value);
29
- }
30
- return concat(...chunks);
13
+ async function transform(stream, input, maxLength = 1 / 0) {
14
+ const writer = stream.writable.getWriter();
15
+ writer.write(input).catch(() => {
16
+ }), writer.close().catch(() => {
17
+ });
18
+ const chunks = [];
19
+ let length = 0;
20
+ const reader = stream.readable.getReader();
21
+ for (; ; ) {
22
+ const { value, done } = await reader.read();
23
+ if (done)
24
+ break;
25
+ if (chunks.push(value), length += value.byteLength, maxLength !== 1 / 0 && length > maxLength)
26
+ throw new JWEInvalid("Decompressed plaintext exceeded the configured limit");
27
+ }
28
+ return concat(...chunks);
31
29
  }
32
- export async function decompress(input, maxLength) {
33
- supported('DecompressionStream');
34
- const ds = new DecompressionStream('deflate-raw');
35
- const writer = ds.writable.getWriter();
36
- writer.write(input).catch(() => { });
37
- writer.close().catch(() => { });
38
- const chunks = [];
39
- let length = 0;
40
- const reader = ds.readable.getReader();
41
- for (;;) {
42
- const { value, done } = await reader.read();
43
- if (done)
44
- break;
45
- chunks.push(value);
46
- length += value.byteLength;
47
- if (maxLength !== Infinity && length > maxLength) {
48
- throw new JWEInvalid('Decompressed plaintext exceeded the configured limit');
49
- }
50
- }
51
- return concat(...chunks);
30
+ async function compress(input) {
31
+ return supported("CompressionStream"), transform(new CompressionStream("deflate-raw"), input);
52
32
  }
33
+ async function decompress(input, maxLength) {
34
+ return supported("DecompressionStream"), transform(new DecompressionStream("deflate-raw"), input, maxLength);
35
+ }
36
+ export {
37
+ compress,
38
+ decompress,
39
+ validateZip
40
+ };
@@ -1,107 +1,116 @@
1
- import { JOSENotSupported } from '../util/errors.js';
2
- import { table } from './key_descriptor.js';
1
+ import { JOSENotSupported } from "../util/errors.js";
2
+ import { table } from "./key_descriptor.js";
3
3
  const wrap = [
4
- ['encrypt', 'wrapKey'],
5
- ['decrypt', 'unwrapKey'],
6
- ];
7
- const derive = [[], ['deriveBits']];
8
- const none = [[], []];
4
+ ["encrypt", "wrapKey"],
5
+ ["decrypt", "unwrapKey"]
6
+ ], derive = [[], ["deriveBits"]], none = [[], []];
9
7
  function rsaes(bits) {
10
- return {
11
- kty: ['RSA'],
12
- subtle: { name: 'RSA-OAEP', hash: `SHA-${bits}` },
13
- usages: wrap,
14
- ops: ['wrapKey', 'unwrapKey'],
15
- };
8
+ return {
9
+ kty: ["RSA"],
10
+ mode: "key-encryption",
11
+ subtle: { name: "RSA-OAEP", hash: `SHA-${bits}` },
12
+ usages: wrap,
13
+ ops: ["wrapKey", "unwrapKey"]
14
+ };
16
15
  }
17
- function ecdh() {
18
- return {
19
- kty: ['EC', 'OKP'],
20
- subtle: { name: 'ECDH' },
21
- resolve: ({ kty, crv, asymmetricKeyType }) => {
22
- if (crv === 'X25519' || asymmetricKeyType === 'x25519') {
23
- return { name: 'X25519' };
24
- }
25
- if (kty === 'OKP') {
26
- throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
27
- }
28
- return { name: 'ECDH', namedCurve: crv };
29
- },
30
- usages: derive,
31
- ops: [undefined, 'deriveBits'],
32
- };
16
+ function ecdh(mode) {
17
+ return {
18
+ kty: ["EC", "OKP"],
19
+ mode,
20
+ subtle: { name: "ECDH" },
21
+ resolve: ({ kty, crv, asymmetricKeyType }) => {
22
+ if (crv === "X25519" || asymmetricKeyType === "x25519")
23
+ return { name: "X25519" };
24
+ if (kty === "OKP")
25
+ throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
26
+ return { name: "ECDH", namedCurve: crv };
27
+ },
28
+ usages: derive,
29
+ ops: [void 0, "deriveBits"]
30
+ };
33
31
  }
34
- function aeskw(bits, gcm = false) {
35
- return {
36
- kty: ['oct'],
37
- secret: true,
38
- subtle: { name: gcm ? 'AES-GCM' : 'AES-KW', length: bits },
39
- usages: none,
40
- ops: gcm ? ['encrypt', 'decrypt'] : ['wrapKey', 'unwrapKey'],
41
- };
32
+ function aeskw(bits, gcm = !1) {
33
+ return {
34
+ kty: ["oct"],
35
+ mode: "key-wrapping",
36
+ secret: !0,
37
+ subtle: { name: gcm ? "AES-GCM" : "AES-KW", length: bits },
38
+ usages: none,
39
+ ops: gcm ? ["encrypt", "decrypt"] : ["wrapKey", "unwrapKey"]
40
+ };
42
41
  }
43
42
  function pbes2() {
44
- return {
45
- kty: ['oct'],
46
- secret: true,
47
- subtle: { name: 'PBKDF2' },
48
- usages: none,
49
- ops: ['deriveBits', 'deriveBits'],
50
- };
43
+ return {
44
+ kty: ["oct"],
45
+ mode: "key-wrapping",
46
+ secret: !0,
47
+ subtle: { name: "PBKDF2" },
48
+ usages: none,
49
+ ops: ["deriveBits", "deriveBits"]
50
+ };
51
51
  }
52
- export const JWE = table({
53
- dir: {
54
- kty: ['oct'],
55
- secret: true,
56
- subtle: { name: 'AES-GCM' },
57
- usages: none,
58
- ops: ['encrypt', 'decrypt'],
59
- },
60
- 'RSA-OAEP': rsaes(1),
61
- 'RSA-OAEP-256': rsaes(256),
62
- 'RSA-OAEP-384': rsaes(384),
63
- 'RSA-OAEP-512': rsaes(512),
64
- 'ECDH-ES': ecdh(),
65
- 'ECDH-ES+A128KW': ecdh(),
66
- 'ECDH-ES+A192KW': ecdh(),
67
- 'ECDH-ES+A256KW': ecdh(),
68
- A128KW: aeskw(128),
69
- A192KW: aeskw(192),
70
- A256KW: aeskw(256),
71
- A128GCMKW: aeskw(128, true),
72
- A192GCMKW: aeskw(192, true),
73
- A256GCMKW: aeskw(256, true),
74
- 'PBES2-HS256+A128KW': pbes2(),
75
- 'PBES2-HS384+A192KW': pbes2(),
76
- 'PBES2-HS512+A256KW': pbes2(),
77
- });
78
- const contentOps = ['encrypt', 'decrypt'];
79
- function contentEncryption(bits, cbc = false) {
80
- return {
81
- kty: ['oct'],
82
- secret: true,
83
- subtle: { name: cbc ? 'AES-CBC' : 'AES-GCM', length: bits },
84
- usages: none,
85
- ops: contentOps,
86
- cekBits: bits,
87
- ivBits: cbc ? 128 : 96,
88
- cbc,
89
- };
52
+ const JWE = table({
53
+ dir: {
54
+ kty: ["oct"],
55
+ mode: "direct-encryption",
56
+ secret: !0,
57
+ subtle: { name: "AES-GCM" },
58
+ usages: none,
59
+ ops: ["encrypt", "decrypt"]
60
+ },
61
+ "RSA-OAEP": rsaes(1),
62
+ "RSA-OAEP-256": rsaes(256),
63
+ "RSA-OAEP-384": rsaes(384),
64
+ "RSA-OAEP-512": rsaes(512),
65
+ "ECDH-ES": ecdh("direct-key-agreement"),
66
+ "ECDH-ES+A128KW": ecdh("key-agreement-with-key-wrapping"),
67
+ "ECDH-ES+A192KW": ecdh("key-agreement-with-key-wrapping"),
68
+ "ECDH-ES+A256KW": ecdh("key-agreement-with-key-wrapping"),
69
+ A128KW: aeskw(128),
70
+ A192KW: aeskw(192),
71
+ A256KW: aeskw(256),
72
+ A128GCMKW: aeskw(128, !0),
73
+ A192GCMKW: aeskw(192, !0),
74
+ A256GCMKW: aeskw(256, !0),
75
+ "PBES2-HS256+A128KW": pbes2(),
76
+ "PBES2-HS384+A192KW": pbes2(),
77
+ "PBES2-HS512+A256KW": pbes2()
78
+ }), contentOps = ["encrypt", "decrypt"];
79
+ function contentEncryption(bits, cbc = !1) {
80
+ return {
81
+ kty: ["oct"],
82
+ secret: !0,
83
+ subtle: { name: cbc ? "AES-CBC" : "AES-GCM", length: bits },
84
+ usages: none,
85
+ ops: contentOps,
86
+ cekBits: bits,
87
+ ivBits: cbc ? 128 : 96,
88
+ cbc
89
+ };
90
90
  }
91
91
  const ENC = table({
92
- A128GCM: contentEncryption(128),
93
- A192GCM: contentEncryption(192),
94
- A256GCM: contentEncryption(256),
95
- 'A128CBC-HS256': contentEncryption(256, true),
96
- 'A192CBC-HS384': contentEncryption(384, true),
97
- 'A256CBC-HS512': contentEncryption(512, true),
92
+ A128GCM: contentEncryption(128),
93
+ A192GCM: contentEncryption(192),
94
+ A256GCM: contentEncryption(256),
95
+ "A128CBC-HS256": contentEncryption(256, !0),
96
+ "A192CBC-HS384": contentEncryption(384, !0),
97
+ "A256CBC-HS512": contentEncryption(512, !0)
98
98
  });
99
99
  function unsupported(parameter, name) {
100
- throw new JOSENotSupported(`Invalid or unsupported "${parameter}" (JWE ${name}) header value`);
100
+ throw new JOSENotSupported(`Invalid or unsupported "${parameter}" (JWE ${name}) header value`);
101
+ }
102
+ function jweAlgorithm(alg) {
103
+ return (typeof alg == "string" ? JWE[alg] : void 0) ?? unsupported("alg", "Algorithm");
101
104
  }
102
- export function jweAlgorithm(alg) {
103
- return (typeof alg === 'string' ? JWE[alg] : undefined) ?? unsupported('alg', 'Algorithm');
105
+ function isJWECEKTransport(algorithm) {
106
+ return algorithm.mode === "key-wrapping" || algorithm.mode === "key-encryption" || algorithm.mode === "key-agreement-with-key-wrapping";
104
107
  }
105
- export function jweEncryption(enc) {
106
- return ((typeof enc === 'string' ? ENC[enc] : undefined) ?? unsupported('enc', 'Encryption Algorithm'));
108
+ function jweEncryption(enc) {
109
+ return (typeof enc == "string" ? ENC[enc] : void 0) ?? unsupported("enc", "Encryption Algorithm");
107
110
  }
111
+ export {
112
+ JWE,
113
+ isJWECEKTransport,
114
+ jweAlgorithm,
115
+ jweEncryption
116
+ };