@zuplo/cli 6.73.27 → 6.73.29

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 (103) hide show
  1. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/README.md +13 -13
  2. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/index.d.ts +6 -5
  3. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwe/compact/decrypt.d.ts +17 -11
  4. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwe/compact/encrypt.d.ts +7 -19
  5. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwe/flattened/decrypt.d.ts +17 -11
  6. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwe/flattened/encrypt.d.ts +7 -19
  7. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwe/general/decrypt.d.ts +18 -13
  8. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwe/general/encrypt.d.ts +20 -21
  9. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwk/embedded.d.ts +8 -12
  10. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwk/thumbprint.d.ts +0 -15
  11. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwks/local.d.ts +12 -21
  12. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwks/remote.d.ts +34 -165
  13. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jws/compact/sign.d.ts +2 -13
  14. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jws/compact/verify.d.ts +17 -13
  15. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jws/flattened/sign.d.ts +2 -13
  16. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jws/flattened/verify.d.ts +17 -13
  17. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jws/general/sign.d.ts +16 -17
  18. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jws/general/verify.d.ts +18 -15
  19. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwt/decrypt.d.ts +17 -11
  20. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwt/encrypt.d.ts +10 -34
  21. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwt/sign.d.ts +2 -13
  22. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwt/unsecured.d.ts +4 -13
  23. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/jwt/verify.d.ts +14 -13
  24. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/key/export.d.ts +0 -14
  25. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/key/generate_key_pair.d.ts +7 -14
  26. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/key/generate_secret.d.ts +16 -14
  27. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/key/import.d.ts +18 -28
  28. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/types.d.ts +242 -223
  29. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/util/base64url.d.ts +11 -4
  30. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/util/decode_jwt.d.ts +1 -9
  31. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/util/decode_protected_header.d.ts +0 -8
  32. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/types/util/errors.d.ts +128 -121
  33. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwe/compact/decrypt.js +3 -21
  34. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwe/flattened/decrypt.js +5 -153
  35. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwe/flattened/encrypt.js +16 -111
  36. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwe/general/decrypt.js +15 -3
  37. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwe/general/encrypt.js +33 -48
  38. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwk/embedded.js +5 -3
  39. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwks/local.js +27 -47
  40. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwks/remote.js +3 -3
  41. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jws/compact/sign.js +5 -2
  42. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jws/compact/verify.js +3 -15
  43. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jws/flattened/sign.js +7 -57
  44. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jws/flattened/verify.js +3 -89
  45. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jws/general/sign.js +18 -5
  46. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jws/general/verify.js +21 -3
  47. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwt/decrypt.js +4 -4
  48. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwt/sign.js +2 -3
  49. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwt/unsecured.js +4 -3
  50. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/jwt/verify.js +5 -5
  51. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/key/export.js +34 -1
  52. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/key/generate_key_pair.js +32 -82
  53. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/key/import.js +8 -8
  54. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/asn1.js +29 -65
  55. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/buffer_utils.js +1 -0
  56. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/content_encryption.js +20 -77
  57. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/crypto_key.js +13 -127
  58. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/helpers.js +23 -0
  59. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jwe_algorithms.js +143 -0
  60. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jwe_decrypt.js +181 -0
  61. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jwe_encrypt.js +109 -0
  62. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jwk_to_key.js +11 -96
  63. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jws_algorithms.js +74 -0
  64. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jws_sign.js +68 -0
  65. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jws_verify.js +108 -0
  66. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/jwt_claims_set.js +9 -8
  67. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/key.js +170 -0
  68. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/key_algorithm.js +16 -0
  69. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/key_descriptor.js +7 -0
  70. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/key_management.js +186 -29
  71. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/{validate_crit.js → options.js} +18 -0
  72. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/signing.js +20 -52
  73. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/util/base64url.js +11 -3
  74. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/util/decode_jwt.js +2 -2
  75. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/util/decode_protected_header.js +5 -15
  76. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/util/errors.js +1 -1
  77. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/package.json +2 -4
  78. package/node_modules/@zuplo/core/customer.cli.minified.js +1 -1
  79. package/node_modules/@zuplo/core/index.minified.js +1 -1
  80. package/node_modules/@zuplo/core/package.json +1 -1
  81. package/node_modules/@zuplo/graphql/package.json +1 -1
  82. package/node_modules/@zuplo/openapi-tools/package.json +1 -1
  83. package/node_modules/@zuplo/otel/package.json +1 -1
  84. package/node_modules/@zuplo/runtime/out/esm/chunk-KO2ULO4I.js +405 -0
  85. package/node_modules/@zuplo/runtime/out/esm/chunk-KO2ULO4I.js.map +1 -0
  86. package/node_modules/@zuplo/runtime/out/esm/index.js +1 -1
  87. package/node_modules/@zuplo/runtime/out/esm/index.js.map +1 -1
  88. package/node_modules/@zuplo/runtime/out/esm/mcp-gateway/index.js +1 -1
  89. package/node_modules/@zuplo/runtime/out/types/index.d.ts +144 -1
  90. package/node_modules/@zuplo/runtime/package.json +1 -1
  91. package/package.json +6 -6
  92. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/aesgcmkw.js +0 -15
  93. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/aeskw.js +0 -25
  94. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/check_key_type.js +0 -122
  95. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/ecdhes.js +0 -52
  96. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/key_to_jwk.js +0 -34
  97. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/normalize_key.js +0 -166
  98. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/pbes2kw.js +0 -42
  99. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/rsaes.js +0 -24
  100. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/validate_algorithms.js +0 -10
  101. package/node_modules/@zuplo/runtime/out/esm/chunk-GWEFPK3R.js +0 -405
  102. package/node_modules/@zuplo/runtime/out/esm/chunk-GWEFPK3R.js.map +0 -1
  103. /package/node_modules/@zuplo/runtime/out/esm/{chunk-GWEFPK3R.js.LEGAL.txt → chunk-KO2ULO4I.js.LEGAL.txt} +0 -0
@@ -0,0 +1,170 @@
1
+ import { withAlg as invalidKeyInput } from './invalid_key_input.js';
2
+ import { isKeyLike, isCryptoKey } from './is_key_like.js';
3
+ import * as jwk from './type_checks.js';
4
+ import { decode } from '../util/base64url.js';
5
+ import { jwkToKey } from './jwk_to_key.js';
6
+ const tag = (key) => key[Symbol.toStringTag];
7
+ const jwkMatchesOp = (entry, key, usage) => {
8
+ const { alg } = entry;
9
+ if (key.use !== undefined) {
10
+ let expected;
11
+ switch (usage) {
12
+ case 'sign':
13
+ case 'verify':
14
+ expected = 'sig';
15
+ break;
16
+ case 'encrypt':
17
+ case 'decrypt':
18
+ expected = 'enc';
19
+ break;
20
+ }
21
+ if (key.use !== expected) {
22
+ throw new TypeError(`Invalid key for this operation, its "use" must be "${expected}" when present`);
23
+ }
24
+ }
25
+ if (key.alg !== undefined && key.alg !== alg) {
26
+ throw new TypeError(`Invalid key for this operation, its "alg" must be "${alg}" when present`);
27
+ }
28
+ if (Array.isArray(key.key_ops)) {
29
+ const expectedKeyOp = usage === 'encrypt' || usage === 'decrypt' ? entry.keyOps?.[usage] : usage;
30
+ if (expectedKeyOp && key.key_ops?.includes?.(expectedKeyOp) === false) {
31
+ throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${expectedKeyOp}" when present`);
32
+ }
33
+ }
34
+ return true;
35
+ };
36
+ const symmetricTypeCheck = (entry, key, usage) => {
37
+ const { alg } = entry;
38
+ if (key instanceof Uint8Array)
39
+ return { kind: BYTES, key };
40
+ if (jwk.isJWK(key)) {
41
+ if (jwk.isSecretJWK(key) && jwkMatchesOp(entry, key, usage))
42
+ return { kind: JWK, key };
43
+ throw new TypeError(`JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present`);
44
+ }
45
+ if (!isKeyLike(key)) {
46
+ throw new TypeError(invalidKeyInput(alg, key, 'CryptoKey', 'KeyObject', 'JSON Web Key', 'Uint8Array'));
47
+ }
48
+ if (key.type !== 'secret') {
49
+ throw new TypeError(`${tag(key)} instances for symmetric algorithms must be of type "secret"`);
50
+ }
51
+ return isCryptoKey(key) ? { kind: CRYPTO, key } : { kind: KEYOBJECT, key };
52
+ };
53
+ const asymmetricTypeCheck = (entry, key, usage) => {
54
+ const { alg } = entry;
55
+ if (jwk.isJWK(key)) {
56
+ switch (usage) {
57
+ case 'decrypt':
58
+ case 'sign':
59
+ if (jwk.isPrivateJWK(key) && jwkMatchesOp(entry, key, usage))
60
+ return { kind: JWK, key };
61
+ throw new TypeError(`JSON Web Key for this operation must be a private JWK`);
62
+ case 'encrypt':
63
+ case 'verify':
64
+ if (jwk.isPublicJWK(key) && jwkMatchesOp(entry, key, usage))
65
+ return { kind: JWK, key };
66
+ throw new TypeError(`JSON Web Key for this operation must be a public JWK`);
67
+ }
68
+ }
69
+ if (!isKeyLike(key)) {
70
+ throw new TypeError(invalidKeyInput(alg, key, 'CryptoKey', 'KeyObject', 'JSON Web Key'));
71
+ }
72
+ if (key.type === 'secret') {
73
+ throw new TypeError(`${tag(key)} instances for asymmetric algorithms must not be of type "secret"`);
74
+ }
75
+ if (key.type === 'public') {
76
+ switch (usage) {
77
+ case 'sign':
78
+ throw new TypeError(`${tag(key)} instances for asymmetric algorithm signing must be of type "private"`);
79
+ case 'decrypt':
80
+ throw new TypeError(`${tag(key)} instances for asymmetric algorithm decryption must be of type "private"`);
81
+ }
82
+ }
83
+ if (key.type === 'private') {
84
+ switch (usage) {
85
+ case 'verify':
86
+ throw new TypeError(`${tag(key)} instances for asymmetric algorithm verifying must be of type "public"`);
87
+ case 'encrypt':
88
+ throw new TypeError(`${tag(key)} instances for asymmetric algorithm encryption must be of type "public"`);
89
+ }
90
+ }
91
+ return isCryptoKey(key) ? { kind: CRYPTO, key } : { kind: KEYOBJECT, key };
92
+ };
93
+ const BYTES = Symbol();
94
+ const CRYPTO = Symbol();
95
+ const KEYOBJECT = Symbol();
96
+ const JWK = Symbol();
97
+ export function checkKeyType(entry, key, usage) {
98
+ return entry.symmetric
99
+ ? symmetricTypeCheck(entry, key, usage)
100
+ : asymmetricTypeCheck(entry, key, usage);
101
+ }
102
+ let cache;
103
+ const nist = {
104
+ __proto__: null,
105
+ prime256v1: 'P-256',
106
+ secp384r1: 'P-384',
107
+ secp521r1: 'P-521',
108
+ };
109
+ function cached(key, alg) {
110
+ cache ||= new WeakMap();
111
+ return cache.get(key)?.[alg];
112
+ }
113
+ function store(key, alg, cryptoKey) {
114
+ const entry = cache.get(key);
115
+ if (entry) {
116
+ entry[alg] = cryptoKey;
117
+ }
118
+ else {
119
+ cache.set(key, { [alg]: cryptoKey });
120
+ }
121
+ return cryptoKey;
122
+ }
123
+ const handleJWK = async (key, jwk, entry) => {
124
+ const hit = cached(key, entry.alg);
125
+ if (hit)
126
+ return hit;
127
+ const cryptoKey = await jwkToKey(entry, { ...jwk, alg: entry.alg });
128
+ return store(key, entry.alg, cryptoKey);
129
+ };
130
+ const handleKeyObject = (keyObject, entry) => {
131
+ const hit = cached(keyObject, entry.alg);
132
+ if (hit)
133
+ return hit;
134
+ const isPublic = keyObject.type === 'public';
135
+ const usages = isPublic ? entry.usages.public : entry.usages.private;
136
+ const { asymmetricKeyType } = keyObject;
137
+ const crv = nist[keyObject.asymmetricKeyDetails?.namedCurve];
138
+ const params = entry.subtleFor?.({ crv, asymmetricKeyType }) ?? entry.subtle;
139
+ return store(keyObject, entry.alg, keyObject.toCryptoKey(params, isPublic, usages));
140
+ };
141
+ export async function prepareKey(entry, key, usage) {
142
+ const tagged = checkKeyType(entry, key, usage);
143
+ switch (tagged.kind) {
144
+ case BYTES:
145
+ case CRYPTO:
146
+ return tagged.key;
147
+ case JWK: {
148
+ if (tagged.key.k) {
149
+ return decode(tagged.key.k);
150
+ }
151
+ if (!Object.isFrozen(tagged.key)) {
152
+ const { key_ops } = tagged.key;
153
+ if (Array.isArray(key_ops))
154
+ Object.freeze(key_ops);
155
+ Object.freeze(tagged.key);
156
+ }
157
+ return handleJWK(tagged.key, tagged.key, entry);
158
+ }
159
+ case KEYOBJECT: {
160
+ const keyObject = tagged.key;
161
+ if (keyObject.type === 'secret') {
162
+ return keyObject.export();
163
+ }
164
+ if ('toCryptoKey' in keyObject && typeof keyObject.toCryptoKey === 'function') {
165
+ return handleKeyObject(keyObject, entry);
166
+ }
167
+ return handleJWK(keyObject, keyObject.export({ format: 'jwk' }), entry);
168
+ }
169
+ }
170
+ }
@@ -0,0 +1,16 @@
1
+ import { JOSENotSupported } from '../util/errors.js';
2
+ import { maybeJWSAlgorithm } from './jws_algorithms.js';
3
+ import { maybeJWEAlgorithm } from './jwe_algorithms.js';
4
+ function unsupportedAlgorithm() {
5
+ return new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
6
+ }
7
+ export function keyAlgorithm(alg) {
8
+ if (typeof alg !== 'string') {
9
+ throw unsupportedAlgorithm();
10
+ }
11
+ const entry = maybeJWSAlgorithm(alg) ?? maybeJWEAlgorithm(alg);
12
+ if (!entry) {
13
+ throw unsupportedAlgorithm();
14
+ }
15
+ return entry;
16
+ }
@@ -0,0 +1,7 @@
1
+ export function table(entries) {
2
+ const out = { __proto__: null };
3
+ for (const alg of Object.keys(entries)) {
4
+ out[alg] = { ...entries[alg], alg };
5
+ }
6
+ return out;
7
+ }
@@ -1,23 +1,173 @@
1
- import * as aeskw from './aeskw.js';
2
- import * as ecdhes from './ecdhes.js';
3
- import * as pbes2kw from './pbes2kw.js';
4
- import * as rsaes from './rsaes.js';
5
1
  import { encode as b64u } from '../util/base64url.js';
6
- import { normalizeKey } from './normalize_key.js';
2
+ import { prepareKey } from './key.js';
3
+ import { jwkToKey } from './jwk_to_key.js';
4
+ import { jweAlgorithm, jweEncryption } from './jwe_algorithms.js';
7
5
  import { JOSENotSupported, JWEInvalid } from '../util/errors.js';
8
- import { decodeBase64url } from './helpers.js';
9
- import { generateCek, cekLength } from './content_encryption.js';
10
- import { importJWK } from '../key/import.js';
11
- import { exportJWK } from '../key/export.js';
6
+ import { decodeBase64url, digest } from './helpers.js';
7
+ import { generateCek, encrypt, decrypt } from './content_encryption.js';
12
8
  import { isObject } from './type_checks.js';
13
- import { wrap as aesGcmKwWrap, unwrap as aesGcmKwUnwrap } from './aesgcmkw.js';
9
+ import { checkCryptoKey, checkUsage } from './crypto_key.js';
10
+ import { checkModulusLength } from './signing.js';
11
+ import { concat, encode, uint32be } from './buffer_utils.js';
14
12
  import { assertCryptoKey } from './is_key_like.js';
13
+ function checkEcdhCryptoKey(key, usage) {
14
+ switch (key.algorithm.name) {
15
+ case 'ECDH':
16
+ case 'X25519':
17
+ break;
18
+ default:
19
+ throw new TypeError('CryptoKey does not support this operation, its algorithm.name must be ECDH or X25519');
20
+ }
21
+ checkUsage(key, usage);
22
+ }
23
+ function checkKeySize(key, alg) {
24
+ if (key.algorithm.length !== parseInt(alg.slice(1, 4), 10)) {
25
+ throw new TypeError(`Invalid key size for alg: ${alg}`);
26
+ }
27
+ }
28
+ function aeskwCryptoKey(key, alg, usage) {
29
+ if (key instanceof Uint8Array) {
30
+ return crypto.subtle.importKey('raw', key, 'AES-KW', true, [usage]);
31
+ }
32
+ checkCryptoKey(key, jweAlgorithm(alg).subtle, usage);
33
+ return key;
34
+ }
35
+ async function aeskwWrap(alg, key, cek) {
36
+ const cryptoKey = await aeskwCryptoKey(key, alg, 'wrapKey');
37
+ checkKeySize(cryptoKey, alg);
38
+ const cryptoKeyCek = await crypto.subtle.importKey('raw', cek, { hash: 'SHA-256', name: 'HMAC' }, true, ['sign']);
39
+ return new Uint8Array(await crypto.subtle.wrapKey('raw', cryptoKeyCek, cryptoKey, 'AES-KW'));
40
+ }
41
+ async function aeskwUnwrap(alg, key, encryptedKey) {
42
+ const cryptoKey = await aeskwCryptoKey(key, alg, 'unwrapKey');
43
+ checkKeySize(cryptoKey, alg);
44
+ const cryptoKeyCek = await crypto.subtle.unwrapKey('raw', encryptedKey, cryptoKey, 'AES-KW', { hash: 'SHA-256', name: 'HMAC' }, true, ['sign']);
45
+ return new Uint8Array(await crypto.subtle.exportKey('raw', cryptoKeyCek));
46
+ }
47
+ async function aesGcmKwWrap(gcm, key, cek, iv) {
48
+ const wrapped = await encrypt(gcm, cek, key, iv, new Uint8Array());
49
+ return {
50
+ encryptedKey: wrapped.ciphertext,
51
+ iv: b64u(wrapped.iv),
52
+ tag: b64u(wrapped.tag),
53
+ };
54
+ }
55
+ async function aesGcmKwUnwrap(gcm, key, encryptedKey, iv, tag) {
56
+ return decrypt(gcm, key, encryptedKey, iv, tag, new Uint8Array());
57
+ }
58
+ const subtleAlgorithm = (alg) => {
59
+ switch (alg) {
60
+ case 'RSA-OAEP':
61
+ case 'RSA-OAEP-256':
62
+ case 'RSA-OAEP-384':
63
+ case 'RSA-OAEP-512':
64
+ return 'RSA-OAEP';
65
+ default:
66
+ throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
67
+ }
68
+ };
69
+ async function rsaesEncrypt(alg, key, cek) {
70
+ checkCryptoKey(key, jweAlgorithm(alg).subtle, 'encrypt');
71
+ checkModulusLength(alg, key);
72
+ return new Uint8Array(await crypto.subtle.encrypt(subtleAlgorithm(alg), key, cek));
73
+ }
74
+ async function rsaesDecrypt(alg, key, encryptedKey) {
75
+ checkCryptoKey(key, jweAlgorithm(alg).subtle, 'decrypt');
76
+ checkModulusLength(alg, key);
77
+ return new Uint8Array(await crypto.subtle.decrypt(subtleAlgorithm(alg), key, encryptedKey));
78
+ }
79
+ function pbes2CryptoKey(key, alg) {
80
+ if (key instanceof Uint8Array) {
81
+ return crypto.subtle.importKey('raw', key, 'PBKDF2', false, [
82
+ 'deriveBits',
83
+ ]);
84
+ }
85
+ checkCryptoKey(key, jweAlgorithm(alg).subtle, 'deriveBits');
86
+ return key;
87
+ }
88
+ const concatSalt = (alg, p2sInput) => concat(encode(alg), Uint8Array.of(0x00), p2sInput);
89
+ async function deriveKey(p2s, alg, p2c, key) {
90
+ if (!(p2s instanceof Uint8Array) || p2s.length < 8) {
91
+ throw new JWEInvalid('PBES2 Salt Input must be 8 or more octets');
92
+ }
93
+ if (!Number.isSafeInteger(p2c) || Math.sign(p2c) !== 1) {
94
+ throw new JWEInvalid('PBES2 Count Input must be a positive integer');
95
+ }
96
+ const salt = concatSalt(alg, p2s);
97
+ const keylen = parseInt(alg.slice(13, 16), 10);
98
+ const subtleAlg = {
99
+ hash: `SHA-${alg.slice(8, 11)}`,
100
+ iterations: p2c,
101
+ name: 'PBKDF2',
102
+ salt,
103
+ };
104
+ const cryptoKey = await pbes2CryptoKey(key, alg);
105
+ return new Uint8Array(await crypto.subtle.deriveBits(subtleAlg, cryptoKey, keylen));
106
+ }
107
+ async function pbes2kwWrap(alg, key, cek, p2c = 2048, p2s = crypto.getRandomValues(new Uint8Array(16))) {
108
+ const derived = await deriveKey(p2s, alg, p2c, key);
109
+ const encryptedKey = await aeskwWrap(alg.slice(-6), derived, cek);
110
+ return { encryptedKey, p2c, p2s: b64u(p2s) };
111
+ }
112
+ async function pbes2kwUnwrap(alg, key, encryptedKey, p2c, p2s) {
113
+ const derived = await deriveKey(p2s, alg, p2c, key);
114
+ return aeskwUnwrap(alg.slice(-6), derived, encryptedKey);
115
+ }
116
+ function lengthAndInput(input) {
117
+ return concat(uint32be(input.length), input);
118
+ }
119
+ async function concatKdf(Z, L, OtherInfo) {
120
+ const dkLen = L >> 3;
121
+ const hashLen = 32;
122
+ const reps = Math.ceil(dkLen / hashLen);
123
+ const dk = new Uint8Array(reps * hashLen);
124
+ for (let i = 1; i <= reps; i++) {
125
+ const hashInput = new Uint8Array(4 + Z.length + OtherInfo.length);
126
+ hashInput.set(uint32be(i), 0);
127
+ hashInput.set(Z, 4);
128
+ hashInput.set(OtherInfo, 4 + Z.length);
129
+ const hashResult = await digest('sha256', hashInput);
130
+ dk.set(hashResult, (i - 1) * hashLen);
131
+ }
132
+ return dk.slice(0, dkLen);
133
+ }
134
+ async function ecdhesDeriveKey(publicKey, privateKey, algorithm, keyLength, apu = new Uint8Array(), apv = new Uint8Array()) {
135
+ checkEcdhCryptoKey(publicKey);
136
+ checkEcdhCryptoKey(privateKey, 'deriveBits');
137
+ const algorithmID = lengthAndInput(encode(algorithm));
138
+ const partyUInfo = lengthAndInput(apu);
139
+ const partyVInfo = lengthAndInput(apv);
140
+ const suppPubInfo = uint32be(keyLength);
141
+ const suppPrivInfo = new Uint8Array();
142
+ const otherInfo = concat(algorithmID, partyUInfo, partyVInfo, suppPubInfo, suppPrivInfo);
143
+ const Z = new Uint8Array(await crypto.subtle.deriveBits({
144
+ name: publicKey.algorithm.name,
145
+ public: publicKey,
146
+ }, privateKey, getEcdhBitLength(publicKey)));
147
+ return concatKdf(Z, keyLength, otherInfo);
148
+ }
149
+ function getEcdhBitLength(publicKey) {
150
+ if (publicKey.algorithm.name === 'X25519') {
151
+ return 256;
152
+ }
153
+ return (Math.ceil(parseInt(publicKey.algorithm.namedCurve.slice(-3), 10) / 8) << 3);
154
+ }
155
+ function ecdhesAllowed(key) {
156
+ switch (key.algorithm.namedCurve) {
157
+ case 'P-256':
158
+ case 'P-384':
159
+ case 'P-521':
160
+ return true;
161
+ default:
162
+ return key.algorithm.name === 'X25519';
163
+ }
164
+ }
15
165
  const unsupportedAlgHeader = 'Invalid or unsupported "alg" (JWE Algorithm) header value';
16
166
  function assertEncryptedKey(encryptedKey) {
17
167
  if (encryptedKey === undefined)
18
168
  throw new JWEInvalid('JWE Encrypted Key missing');
19
169
  }
20
- export async function decryptKeyManagement(alg, key, encryptedKey, joseHeader, options) {
170
+ export async function decryptKeyManagement(alg, enc, key, encryptedKey, joseHeader, options) {
21
171
  switch (alg) {
22
172
  case 'dir': {
23
173
  if (encryptedKey !== undefined)
@@ -33,10 +183,9 @@ export async function decryptKeyManagement(alg, key, encryptedKey, joseHeader, o
33
183
  if (!isObject(joseHeader.epk))
34
184
  throw new JWEInvalid(`JOSE Header "epk" (Ephemeral Public Key) missing or invalid`);
35
185
  assertCryptoKey(key);
36
- if (!ecdhes.allowed(key))
186
+ if (!ecdhesAllowed(key))
37
187
  throw new JOSENotSupported('ECDH with the provided key is not allowed or not supported by your javascript runtime');
38
- const epk = await importJWK(joseHeader.epk, alg);
39
- assertCryptoKey(epk);
188
+ const epk = await jwkToKey(jweAlgorithm(alg), joseHeader.epk);
40
189
  let partyUInfo;
41
190
  let partyVInfo;
42
191
  if (joseHeader.apu !== undefined) {
@@ -49,11 +198,11 @@ export async function decryptKeyManagement(alg, key, encryptedKey, joseHeader, o
49
198
  throw new JWEInvalid(`JOSE Header "apv" (Agreement PartyVInfo) invalid`);
50
199
  partyVInfo = decodeBase64url(joseHeader.apv, 'apv', JWEInvalid);
51
200
  }
52
- const sharedSecret = await ecdhes.deriveKey(epk, key, alg === 'ECDH-ES' ? joseHeader.enc : alg, alg === 'ECDH-ES' ? cekLength(joseHeader.enc) : parseInt(alg.slice(-5, -2), 10), partyUInfo, partyVInfo);
201
+ const sharedSecret = await ecdhesDeriveKey(epk, key, alg === 'ECDH-ES' ? enc.alg : alg, alg === 'ECDH-ES' ? enc.cekBits : parseInt(alg.slice(-5, -2), 10), partyUInfo, partyVInfo);
53
202
  if (alg === 'ECDH-ES')
54
203
  return sharedSecret;
55
204
  assertEncryptedKey(encryptedKey);
56
- return aeskw.unwrap(alg.slice(-6), sharedSecret, encryptedKey);
205
+ return aeskwUnwrap(alg.slice(-6), sharedSecret, encryptedKey);
57
206
  }
58
207
  case 'RSA-OAEP':
59
208
  case 'RSA-OAEP-256':
@@ -61,7 +210,7 @@ export async function decryptKeyManagement(alg, key, encryptedKey, joseHeader, o
61
210
  case 'RSA-OAEP-512': {
62
211
  assertEncryptedKey(encryptedKey);
63
212
  assertCryptoKey(key);
64
- return rsaes.decrypt(alg, key, encryptedKey);
213
+ return rsaesDecrypt(alg, key, encryptedKey);
65
214
  }
66
215
  case 'PBES2-HS256+A128KW':
67
216
  case 'PBES2-HS384+A192KW':
@@ -76,13 +225,13 @@ export async function decryptKeyManagement(alg, key, encryptedKey, joseHeader, o
76
225
  throw new JWEInvalid(`JOSE Header "p2s" (PBES2 Salt) missing or invalid`);
77
226
  let p2s;
78
227
  p2s = decodeBase64url(joseHeader.p2s, 'p2s', JWEInvalid);
79
- return pbes2kw.unwrap(alg, key, encryptedKey, joseHeader.p2c, p2s);
228
+ return pbes2kwUnwrap(alg, key, encryptedKey, joseHeader.p2c, p2s);
80
229
  }
81
230
  case 'A128KW':
82
231
  case 'A192KW':
83
232
  case 'A256KW': {
84
233
  assertEncryptedKey(encryptedKey);
85
- return aeskw.unwrap(alg, key, encryptedKey);
234
+ return aeskwUnwrap(alg, key, encryptedKey);
86
235
  }
87
236
  case 'A128GCMKW':
88
237
  case 'A192GCMKW':
@@ -96,7 +245,7 @@ export async function decryptKeyManagement(alg, key, encryptedKey, joseHeader, o
96
245
  iv = decodeBase64url(joseHeader.iv, 'iv', JWEInvalid);
97
246
  let tag;
98
247
  tag = decodeBase64url(joseHeader.tag, 'tag', JWEInvalid);
99
- return aesGcmKwUnwrap(alg, key, encryptedKey, iv, tag);
248
+ return aesGcmKwUnwrap(jweEncryption(jweAlgorithm(alg).gcmkw), key, encryptedKey, iv, tag);
100
249
  }
101
250
  default: {
102
251
  throw new JOSENotSupported(unsupportedAlgHeader);
@@ -117,19 +266,27 @@ export async function encryptKeyManagement(alg, enc, key, providedCek, providedP
117
266
  case 'ECDH-ES+A192KW':
118
267
  case 'ECDH-ES+A256KW': {
119
268
  assertCryptoKey(key);
120
- if (!ecdhes.allowed(key)) {
269
+ if (!ecdhesAllowed(key)) {
121
270
  throw new JOSENotSupported('ECDH with the provided key is not allowed or not supported by your javascript runtime');
122
271
  }
123
272
  const { apu, apv } = providedParameters;
124
273
  let ephemeralKey;
125
274
  if (providedParameters.epk) {
126
- ephemeralKey = (await normalizeKey(providedParameters.epk, alg));
275
+ ephemeralKey = (await prepareKey(jweAlgorithm(alg), providedParameters.epk, 'decrypt'));
127
276
  }
128
277
  else {
129
278
  ephemeralKey = (await crypto.subtle.generateKey(key.algorithm, true, ['deriveBits'])).privateKey;
130
279
  }
131
- const { x, y, crv, kty } = await exportJWK(ephemeralKey);
132
- const sharedSecret = await ecdhes.deriveKey(key, ephemeralKey, alg === 'ECDH-ES' ? enc : alg, alg === 'ECDH-ES' ? cekLength(enc) : parseInt(alg.slice(-5, -2), 10), apu, apv);
280
+ const subtle = crypto.subtle;
281
+ let exportableEpk = ephemeralKey;
282
+ if (!exportableEpk.extractable) {
283
+ if (typeof subtle.getPublicKey !== 'function') {
284
+ throw new TypeError('CryptoKey for "epk" must be extractable');
285
+ }
286
+ exportableEpk = await subtle.getPublicKey(ephemeralKey, []);
287
+ }
288
+ const { x, y, crv, kty } = (await subtle.exportKey('jwk', exportableEpk));
289
+ const sharedSecret = await ecdhesDeriveKey(key, ephemeralKey, alg === 'ECDH-ES' ? enc.alg : alg, alg === 'ECDH-ES' ? enc.cekBits : parseInt(alg.slice(-5, -2), 10), apu, apv);
133
290
  parameters = { epk: { x, crv, kty } };
134
291
  if (kty === 'EC')
135
292
  parameters.epk.y = y;
@@ -143,7 +300,7 @@ export async function encryptKeyManagement(alg, enc, key, providedCek, providedP
143
300
  }
144
301
  cek = providedCek || generateCek(enc);
145
302
  const kwAlg = alg.slice(-6);
146
- encryptedKey = await aeskw.wrap(kwAlg, sharedSecret, cek);
303
+ encryptedKey = await aeskwWrap(kwAlg, sharedSecret, cek);
147
304
  break;
148
305
  }
149
306
  case 'RSA-OAEP':
@@ -152,7 +309,7 @@ export async function encryptKeyManagement(alg, enc, key, providedCek, providedP
152
309
  case 'RSA-OAEP-512': {
153
310
  cek = providedCek || generateCek(enc);
154
311
  assertCryptoKey(key);
155
- encryptedKey = await rsaes.encrypt(alg, key, cek);
312
+ encryptedKey = await rsaesEncrypt(alg, key, cek);
156
313
  break;
157
314
  }
158
315
  case 'PBES2-HS256+A128KW':
@@ -160,14 +317,14 @@ export async function encryptKeyManagement(alg, enc, key, providedCek, providedP
160
317
  case 'PBES2-HS512+A256KW': {
161
318
  cek = providedCek || generateCek(enc);
162
319
  const { p2c, p2s } = providedParameters;
163
- ({ encryptedKey, ...parameters } = await pbes2kw.wrap(alg, key, cek, p2c, p2s));
320
+ ({ encryptedKey, ...parameters } = await pbes2kwWrap(alg, key, cek, p2c, p2s));
164
321
  break;
165
322
  }
166
323
  case 'A128KW':
167
324
  case 'A192KW':
168
325
  case 'A256KW': {
169
326
  cek = providedCek || generateCek(enc);
170
- encryptedKey = await aeskw.wrap(alg, key, cek);
327
+ encryptedKey = await aeskwWrap(alg, key, cek);
171
328
  break;
172
329
  }
173
330
  case 'A128GCMKW':
@@ -175,7 +332,7 @@ export async function encryptKeyManagement(alg, enc, key, providedCek, providedP
175
332
  case 'A256GCMKW': {
176
333
  cek = providedCek || generateCek(enc);
177
334
  const { iv } = providedParameters;
178
- ({ encryptedKey, ...parameters } = await aesGcmKwWrap(alg, key, cek, iv));
335
+ ({ encryptedKey, ...parameters } = await aesGcmKwWrap(jweEncryption(jweAlgorithm(alg).gcmkw), key, cek, iv));
179
336
  break;
180
337
  }
181
338
  default: {
@@ -1,4 +1,22 @@
1
1
  import { JOSENotSupported, JWEInvalid, JWSInvalid } from '../util/errors.js';
2
+ export const JWS_RECOGNIZED = new Map([['b64', true]]);
3
+ export const JWE_RECOGNIZED = new Map();
4
+ export function validateAlgorithms(option, algorithms) {
5
+ if (algorithms !== undefined &&
6
+ (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== 'string'))) {
7
+ throw new TypeError(`"${option}" option must be an array of strings`);
8
+ }
9
+ if (!algorithms) {
10
+ return undefined;
11
+ }
12
+ return new Set(algorithms);
13
+ }
14
+ export function validateCritDuplicates(Err, protectedHeader) {
15
+ const { crit } = protectedHeader ?? {};
16
+ if (Array.isArray(crit) && new Set(crit).size !== crit.length) {
17
+ throw new Err('"crit" (Critical) Header Parameter MUST NOT contain duplicate values');
18
+ }
19
+ }
2
20
  export function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
3
21
  if (joseHeader.crit !== undefined && protectedHeader?.crit === undefined) {
4
22
  throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
@@ -1,66 +1,34 @@
1
- import { JOSENotSupported } from '../util/errors.js';
2
- import { checkSigCryptoKey } from './crypto_key.js';
3
- import { invalidKeyInput } from './invalid_key_input.js';
4
- export function checkKeyLength(alg, key) {
5
- if (alg.startsWith('RS') || alg.startsWith('PS')) {
6
- const { modulusLength } = key.algorithm;
7
- if (typeof modulusLength !== 'number' || modulusLength < 2048) {
8
- throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
9
- }
1
+ import { checkCryptoKey } from './crypto_key.js';
2
+ export function checkModulusLength(alg, key) {
3
+ const { modulusLength } = key.algorithm;
4
+ if (typeof modulusLength !== 'number' || modulusLength < 2048) {
5
+ throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
10
6
  }
11
7
  }
12
- function subtleAlgorithm(alg, algorithm) {
13
- const hash = `SHA-${alg.slice(-3)}`;
14
- switch (alg) {
15
- case 'HS256':
16
- case 'HS384':
17
- case 'HS512':
18
- return { hash, name: 'HMAC' };
19
- case 'PS256':
20
- case 'PS384':
21
- case 'PS512':
22
- return { hash, name: 'RSA-PSS', saltLength: parseInt(alg.slice(-3), 10) >> 3 };
23
- case 'RS256':
24
- case 'RS384':
25
- case 'RS512':
26
- return { hash, name: 'RSASSA-PKCS1-v1_5' };
27
- case 'ES256':
28
- case 'ES384':
29
- case 'ES512':
30
- return { hash, name: 'ECDSA', namedCurve: algorithm.namedCurve };
31
- case 'Ed25519':
32
- case 'EdDSA':
33
- return { name: 'Ed25519' };
34
- case 'ML-DSA-44':
35
- case 'ML-DSA-65':
36
- case 'ML-DSA-87':
37
- return { name: alg };
38
- default:
39
- throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
8
+ function checkSigCryptoKey(entry, key, usage) {
9
+ checkCryptoKey(key, entry.subtle, usage);
10
+ if (entry.minModulusLength) {
11
+ checkModulusLength(entry.alg, key);
40
12
  }
41
13
  }
42
- async function getSigKey(alg, key, usage) {
14
+ async function getSigKey(entry, key, usage) {
43
15
  if (key instanceof Uint8Array) {
44
- if (!alg.startsWith('HS')) {
45
- throw new TypeError(invalidKeyInput(key, 'CryptoKey', 'KeyObject', 'JSON Web Key'));
46
- }
47
- return crypto.subtle.importKey('raw', key, { hash: `SHA-${alg.slice(-3)}`, name: 'HMAC' }, false, [usage]);
16
+ return crypto.subtle.importKey('raw', key, entry.subtle, false, [
17
+ usage,
18
+ ]);
48
19
  }
49
- checkSigCryptoKey(key, alg, usage);
20
+ checkSigCryptoKey(entry, key, usage);
50
21
  return key;
51
22
  }
52
- export async function sign(alg, key, data) {
53
- const cryptoKey = await getSigKey(alg, key, 'sign');
54
- checkKeyLength(alg, cryptoKey);
55
- const signature = await crypto.subtle.sign(subtleAlgorithm(alg, cryptoKey.algorithm), cryptoKey, data);
23
+ export async function sign(entry, key, data) {
24
+ const cryptoKey = await getSigKey(entry, key, 'sign');
25
+ const signature = await crypto.subtle.sign(entry.operation, cryptoKey, data);
56
26
  return new Uint8Array(signature);
57
27
  }
58
- export async function verify(alg, key, signature, data) {
59
- const cryptoKey = await getSigKey(alg, key, 'verify');
60
- checkKeyLength(alg, cryptoKey);
61
- const algorithm = subtleAlgorithm(alg, cryptoKey.algorithm);
28
+ export async function verify(entry, key, signature, data) {
29
+ const cryptoKey = await getSigKey(entry, key, 'verify');
62
30
  try {
63
- return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
31
+ return await crypto.subtle.verify(entry.operation, cryptoKey, signature, data);
64
32
  }
65
33
  catch {
66
34
  return false;
@@ -2,14 +2,22 @@ import { encoder, decoder } from '../lib/buffer_utils.js';
2
2
  import { encodeBase64, decodeBase64 } from '../lib/base64.js';
3
3
  export function decode(input) {
4
4
  if (Uint8Array.fromBase64) {
5
- return Uint8Array.fromBase64(typeof input === 'string' ? input : decoder.decode(input), {
6
- alphabet: 'base64url',
7
- });
5
+ try {
6
+ return Uint8Array.fromBase64(typeof input === 'string' ? input : decoder.decode(input), {
7
+ alphabet: 'base64url',
8
+ });
9
+ }
10
+ catch (cause) {
11
+ throw new TypeError('The input to be decoded is not correctly encoded.', { cause });
12
+ }
8
13
  }
9
14
  let encoded = input;
10
15
  if (encoded instanceof Uint8Array) {
11
16
  encoded = decoder.decode(encoded);
12
17
  }
18
+ if (encoded.includes('+') || encoded.includes('/')) {
19
+ throw new TypeError('The input to be decoded is not correctly encoded.');
20
+ }
13
21
  encoded = encoded.replace(/-/g, '+').replace(/_/g, '/');
14
22
  try {
15
23
  return decodeBase64(encoded);
@@ -1,5 +1,5 @@
1
1
  import { decode as b64u } from './base64url.js';
2
- import { decoder } from '../lib/buffer_utils.js';
2
+ import { strictDecoder } from '../lib/buffer_utils.js';
3
3
  import { isObject } from '../lib/type_checks.js';
4
4
  import { JWTInvalid } from './errors.js';
5
5
  export function decodeJwt(jwt) {
@@ -21,7 +21,7 @@ export function decodeJwt(jwt) {
21
21
  }
22
22
  let result;
23
23
  try {
24
- result = JSON.parse(decoder.decode(decoded));
24
+ result = JSON.parse(strictDecoder.decode(decoded));
25
25
  }
26
26
  catch {
27
27
  throw new JWTInvalid('Failed to parse the decoded payload as JSON');