@zuplo/cli 6.73.26 → 6.73.28

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 (139) 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/@posthog/types/dist/capture.d.ts +4 -0
  79. package/node_modules/@posthog/types/dist/capture.d.ts.map +1 -1
  80. package/node_modules/@posthog/types/dist/index.d.ts +1 -1
  81. package/node_modules/@posthog/types/dist/index.d.ts.map +1 -1
  82. package/node_modules/@posthog/types/dist/posthog-config.d.ts +50 -2
  83. package/node_modules/@posthog/types/dist/posthog-config.d.ts.map +1 -1
  84. package/node_modules/@posthog/types/dist/session-recording.d.ts +10 -0
  85. package/node_modules/@posthog/types/dist/session-recording.d.ts.map +1 -1
  86. package/node_modules/@posthog/types/package.json +1 -1
  87. package/node_modules/@posthog/types/src/capture.ts +4 -0
  88. package/node_modules/@posthog/types/src/index.ts +1 -0
  89. package/node_modules/@posthog/types/src/posthog-config.ts +56 -2
  90. package/node_modules/@posthog/types/src/session-recording.ts +11 -0
  91. package/node_modules/@zuplo/core/package.json +1 -1
  92. package/node_modules/@zuplo/graphql/package.json +1 -1
  93. package/node_modules/@zuplo/openapi-tools/package.json +1 -1
  94. package/node_modules/@zuplo/otel/package.json +1 -1
  95. package/node_modules/@zuplo/runtime/out/esm/{chunk-SL6SOWIV.js → chunk-6SNZ4DOC.js} +2 -2
  96. package/node_modules/@zuplo/runtime/out/esm/{chunk-PEUB7LX7.js → chunk-A3QGJZO7.js} +2 -2
  97. package/node_modules/@zuplo/runtime/out/esm/chunk-GWEFPK3R.js +405 -0
  98. package/node_modules/@zuplo/runtime/out/esm/chunk-GWEFPK3R.js.LEGAL.txt +16 -0
  99. package/node_modules/@zuplo/runtime/out/esm/chunk-GWEFPK3R.js.map +1 -0
  100. package/node_modules/@zuplo/runtime/out/esm/{chunk-RB2LCXBX.js → chunk-QGAJTUPE.js} +2 -2
  101. package/node_modules/@zuplo/runtime/out/esm/{chunk-V4X24KCQ.js → chunk-QVZD2XRK.js} +2 -2
  102. package/node_modules/@zuplo/runtime/out/esm/{chunk-7WS4HIGR.js → chunk-SH74D236.js} +2 -2
  103. package/node_modules/@zuplo/runtime/out/esm/{chunk-2WLR6ZDZ.js → chunk-TYV53J3B.js} +2 -2
  104. package/node_modules/@zuplo/runtime/out/esm/{chunk-TRBIM47E.js → chunk-UKQQD2JN.js} +2 -2
  105. package/node_modules/@zuplo/runtime/out/esm/{chunk-A3425Z75.js → chunk-VHRZC4UF.js} +2 -2
  106. package/node_modules/@zuplo/runtime/out/esm/{chunk-VCMIY3WJ.js → chunk-YIT72S45.js} +3 -3
  107. package/node_modules/@zuplo/runtime/out/esm/index.js +1 -1
  108. package/node_modules/@zuplo/runtime/out/esm/index.js.map +1 -1
  109. package/node_modules/@zuplo/runtime/out/esm/internal/index.js +1 -1
  110. package/node_modules/@zuplo/runtime/out/esm/mcp/messages/index.js +1 -1
  111. package/node_modules/@zuplo/runtime/out/esm/mcp-gateway/index.js +13 -13
  112. package/node_modules/@zuplo/runtime/out/esm/mcp-gateway/index.js.map +1 -1
  113. package/node_modules/@zuplo/runtime/out/esm/mocks/index.js +1 -1
  114. package/node_modules/@zuplo/runtime/out/esm/sdks/aws/index.js +1 -1
  115. package/node_modules/@zuplo/runtime/out/types/index.d.ts +86 -3
  116. package/node_modules/@zuplo/runtime/package.json +1 -1
  117. package/package.json +6 -6
  118. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/aesgcmkw.js +0 -15
  119. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/aeskw.js +0 -25
  120. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/check_key_type.js +0 -122
  121. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/ecdhes.js +0 -52
  122. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/key_to_jwk.js +0 -34
  123. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/normalize_key.js +0 -166
  124. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/pbes2kw.js +0 -42
  125. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/rsaes.js +0 -24
  126. package/node_modules/@modelcontextprotocol/sdk/node_modules/jose/dist/webapi/lib/validate_algorithms.js +0 -10
  127. package/node_modules/@zuplo/runtime/out/esm/chunk-WK5G5RKI.js +0 -385
  128. package/node_modules/@zuplo/runtime/out/esm/chunk-WK5G5RKI.js.LEGAL.txt +0 -7
  129. package/node_modules/@zuplo/runtime/out/esm/chunk-WK5G5RKI.js.map +0 -1
  130. /package/node_modules/@zuplo/runtime/out/esm/{chunk-SL6SOWIV.js.map → chunk-6SNZ4DOC.js.map} +0 -0
  131. /package/node_modules/@zuplo/runtime/out/esm/{chunk-PEUB7LX7.js.map → chunk-A3QGJZO7.js.map} +0 -0
  132. /package/node_modules/@zuplo/runtime/out/esm/{chunk-RB2LCXBX.js.map → chunk-QGAJTUPE.js.map} +0 -0
  133. /package/node_modules/@zuplo/runtime/out/esm/{chunk-V4X24KCQ.js.map → chunk-QVZD2XRK.js.map} +0 -0
  134. /package/node_modules/@zuplo/runtime/out/esm/{chunk-7WS4HIGR.js.map → chunk-SH74D236.js.map} +0 -0
  135. /package/node_modules/@zuplo/runtime/out/esm/{chunk-2WLR6ZDZ.js.map → chunk-TYV53J3B.js.map} +0 -0
  136. /package/node_modules/@zuplo/runtime/out/esm/{chunk-TRBIM47E.js.map → chunk-UKQQD2JN.js.map} +0 -0
  137. /package/node_modules/@zuplo/runtime/out/esm/{chunk-A3425Z75.js.map → chunk-VHRZC4UF.js.map} +0 -0
  138. /package/node_modules/@zuplo/runtime/out/esm/{chunk-VCMIY3WJ.js.LEGAL.txt → chunk-YIT72S45.js.LEGAL.txt} +0 -0
  139. /package/node_modules/@zuplo/runtime/out/esm/{chunk-VCMIY3WJ.js.map → chunk-YIT72S45.js.map} +0 -0
@@ -1,14 +1,7 @@
1
- import { encode as b64u } from '../../util/base64url.js';
2
1
  import { unprotected, assertNotSet } from '../../lib/helpers.js';
3
- import { encrypt } from '../../lib/content_encryption.js';
4
- import { encryptKeyManagement } from '../../lib/key_management.js';
5
- import { JOSENotSupported, JWEInvalid } from '../../util/errors.js';
6
- import { isDisjoint } from '../../lib/type_checks.js';
7
- import { concat, encode } from '../../lib/buffer_utils.js';
8
- import { validateCrit } from '../../lib/validate_crit.js';
9
- import { normalizeKey } from '../../lib/normalize_key.js';
10
- import { checkKeyType } from '../../lib/check_key_type.js';
11
- import { compress } from '../../lib/deflate.js';
2
+ import { JWEInvalid } from '../../util/errors.js';
3
+ import { createJWE } from '../../lib/jwe_encrypt.js';
4
+ import { validateCritDuplicates } from '../../lib/options.js';
12
5
  export class FlattenedEncrypt {
13
6
  #plaintext;
14
7
  #protectedHeader;
@@ -62,106 +55,18 @@ export class FlattenedEncrypt {
62
55
  if (!this.#protectedHeader && !this.#unprotectedHeader && !this.#sharedUnprotectedHeader) {
63
56
  throw new JWEInvalid('either setProtectedHeader, setUnprotectedHeader, or sharedUnprotectedHeader must be called before #encrypt()');
64
57
  }
65
- if (!isDisjoint(this.#protectedHeader, this.#unprotectedHeader, this.#sharedUnprotectedHeader)) {
66
- throw new JWEInvalid('JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint');
67
- }
68
- const joseHeader = {
69
- ...this.#protectedHeader,
70
- ...this.#unprotectedHeader,
71
- ...this.#sharedUnprotectedHeader,
72
- };
73
- validateCrit(JWEInvalid, new Map(), options?.crit, this.#protectedHeader, joseHeader);
74
- if (joseHeader.zip !== undefined && joseHeader.zip !== 'DEF') {
75
- throw new JOSENotSupported('Unsupported JWE "zip" (Compression Algorithm) Header Parameter value.');
76
- }
77
- if (joseHeader.zip !== undefined && !this.#protectedHeader?.zip) {
78
- throw new JWEInvalid('JWE "zip" (Compression Algorithm) Header Parameter MUST be in a protected header.');
79
- }
80
- const { alg, enc } = joseHeader;
81
- if (typeof alg !== 'string' || !alg) {
82
- throw new JWEInvalid('JWE "alg" (Algorithm) Header Parameter missing or invalid');
83
- }
84
- if (typeof enc !== 'string' || !enc) {
85
- throw new JWEInvalid('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');
86
- }
87
- let encryptedKey;
88
- if (this.#cek && (alg === 'dir' || alg === 'ECDH-ES')) {
89
- throw new TypeError(`setContentEncryptionKey cannot be called with JWE "alg" (Algorithm) Header ${alg}`);
90
- }
91
- checkKeyType(alg === 'dir' ? enc : alg, key, 'encrypt');
92
- let cek;
93
- {
94
- let parameters;
95
- const k = await normalizeKey(key, alg);
96
- ({ cek, encryptedKey, parameters } = await encryptKeyManagement(alg, enc, k, this.#cek, this.#keyManagementParameters));
97
- if (parameters) {
98
- if (options && unprotected in options) {
99
- if (!this.#unprotectedHeader) {
100
- this.setUnprotectedHeader(parameters);
101
- }
102
- else {
103
- this.#unprotectedHeader = { ...this.#unprotectedHeader, ...parameters };
104
- }
105
- }
106
- else if (!this.#protectedHeader) {
107
- this.setProtectedHeader(parameters);
108
- }
109
- else {
110
- this.#protectedHeader = { ...this.#protectedHeader, ...parameters };
111
- }
112
- }
113
- }
114
- let additionalData;
115
- let protectedHeaderS;
116
- let protectedHeaderB;
117
- let aadMember;
118
- if (this.#protectedHeader) {
119
- protectedHeaderS = b64u(JSON.stringify(this.#protectedHeader));
120
- protectedHeaderB = encode(protectedHeaderS);
121
- }
122
- else {
123
- protectedHeaderS = '';
124
- protectedHeaderB = new Uint8Array();
125
- }
126
- if (this.#aad) {
127
- aadMember = b64u(this.#aad);
128
- const aadMemberBytes = encode(aadMember);
129
- additionalData = concat(protectedHeaderB, encode('.'), aadMemberBytes);
130
- }
131
- else {
132
- additionalData = protectedHeaderB;
133
- }
134
- let plaintext = this.#plaintext;
135
- if (joseHeader.zip === 'DEF') {
136
- plaintext = await compress(plaintext).catch((cause) => {
137
- throw new JWEInvalid('Failed to compress plaintext', { cause });
138
- });
139
- }
140
- const { ciphertext, tag, iv } = await encrypt(enc, plaintext, cek, this.#iv, additionalData);
141
- const jwe = {
142
- ciphertext: b64u(ciphertext),
143
- };
144
- if (iv) {
145
- jwe.iv = b64u(iv);
146
- }
147
- if (tag) {
148
- jwe.tag = b64u(tag);
149
- }
150
- if (encryptedKey) {
151
- jwe.encrypted_key = b64u(encryptedKey);
152
- }
153
- if (aadMember) {
154
- jwe.aad = aadMember;
155
- }
156
- if (this.#protectedHeader) {
157
- jwe.protected = protectedHeaderS;
158
- }
159
- if (this.#sharedUnprotectedHeader) {
160
- jwe.unprotected = this.#sharedUnprotectedHeader;
161
- }
162
- if (this.#unprotectedHeader) {
163
- jwe.header = this.#unprotectedHeader;
164
- }
165
- return jwe;
58
+ validateCritDuplicates(JWEInvalid, this.#protectedHeader);
59
+ return createJWE({
60
+ plaintext: this.#plaintext,
61
+ protectedHeader: this.#protectedHeader,
62
+ unprotectedHeader: this.#unprotectedHeader,
63
+ sharedUnprotectedHeader: this.#sharedUnprotectedHeader,
64
+ aad: this.#aad,
65
+ cek: this.#cek,
66
+ iv: this.#iv,
67
+ keyManagementParameters: this.#keyManagementParameters,
68
+ crit: options?.crit,
69
+ unprotectedParameters: options ? unprotected in options : false,
70
+ }, key);
166
71
  }
167
72
  }
@@ -1,4 +1,4 @@
1
- import { flattenedDecrypt } from '../flattened/decrypt.js';
1
+ import { prepareDecrypt, shareJWE, decryptRecipient, decryptResult, checkShared, checkRecipient, } from '../../lib/jwe_decrypt.js';
2
2
  import { JWEDecryptionFailed, JWEInvalid } from '../../util/errors.js';
3
3
  import { isObject } from '../../lib/type_checks.js';
4
4
  export async function generalDecrypt(jwe, key, options) {
@@ -11,9 +11,19 @@ export async function generalDecrypt(jwe, key, options) {
11
11
  if (!jwe.recipients.length) {
12
12
  throw new JWEInvalid('JWE Recipients has no members');
13
13
  }
14
+ let shared;
15
+ let token;
16
+ try {
17
+ checkShared(jwe);
18
+ shared = prepareDecrypt(options);
19
+ token = shareJWE(jwe);
20
+ }
21
+ catch {
22
+ throw new JWEDecryptionFailed();
23
+ }
14
24
  for (const recipient of jwe.recipients) {
15
25
  try {
16
- return await flattenedDecrypt({
26
+ const flattened = {
17
27
  aad: jwe.aad,
18
28
  ciphertext: jwe.ciphertext,
19
29
  encrypted_key: recipient.encrypted_key,
@@ -22,7 +32,9 @@ export async function generalDecrypt(jwe, key, options) {
22
32
  protected: jwe.protected,
23
33
  tag: jwe.tag,
24
34
  unprotected: jwe.unprotected,
25
- }, key, options);
35
+ };
36
+ checkRecipient(flattened);
37
+ return decryptResult(flattened, await decryptRecipient(flattened, token, shared, key));
26
38
  }
27
39
  catch {
28
40
  }
@@ -1,13 +1,13 @@
1
1
  import { FlattenedEncrypt } from '../flattened/encrypt.js';
2
- import { unprotected, assertNotSet } from '../../lib/helpers.js';
3
- import { JOSENotSupported, JWEInvalid } from '../../util/errors.js';
2
+ import { assertNotSet } from '../../lib/helpers.js';
3
+ import { JWEInvalid } from '../../util/errors.js';
4
4
  import { generateCek } from '../../lib/content_encryption.js';
5
- import { isDisjoint } from '../../lib/type_checks.js';
6
5
  import { encryptKeyManagement } from '../../lib/key_management.js';
7
6
  import { encode as b64u } from '../../util/base64url.js';
8
- import { validateCrit } from '../../lib/validate_crit.js';
9
- import { normalizeKey } from '../../lib/normalize_key.js';
10
- import { checkKeyType } from '../../lib/check_key_type.js';
7
+ import { validateCritDuplicates } from '../../lib/options.js';
8
+ import { checkEncryptHeaders, encryptJWE } from '../../lib/jwe_encrypt.js';
9
+ import { prepareKey } from '../../lib/key.js';
10
+ import { jweAlgorithm } from '../../lib/jwe_algorithms.js';
11
11
  class IndividualRecipient {
12
12
  #parent;
13
13
  unprotectedHeader;
@@ -71,6 +71,9 @@ export class GeneralEncrypt {
71
71
  if (!this.#recipients.length) {
72
72
  throw new JWEInvalid('at least one recipient must be added');
73
73
  }
74
+ if (!(this.#plaintext instanceof Uint8Array)) {
75
+ throw new TypeError('plaintext must be an instance of Uint8Array');
76
+ }
74
77
  if (this.#recipients.length === 1) {
75
78
  const [recipient] = this.#recipients;
76
79
  const flattened = await new FlattenedEncrypt(this.#plaintext)
@@ -78,6 +81,7 @@ export class GeneralEncrypt {
78
81
  .setProtectedHeader(this.#protectedHeader)
79
82
  .setSharedUnprotectedHeader(this.#unprotectedHeader)
80
83
  .setUnprotectedHeader(recipient.unprotectedHeader)
84
+ .setKeyManagementParameters(recipient.keyManagementParameters)
81
85
  .encrypt(recipient.key, { ...recipient.options });
82
86
  const jwe = {
83
87
  ciphertext: flattened.ciphertext,
@@ -97,42 +101,36 @@ export class GeneralEncrypt {
97
101
  jwe.recipients[0].header = flattened.header;
98
102
  return jwe;
99
103
  }
104
+ validateCritDuplicates(JWEInvalid, this.#protectedHeader);
100
105
  let enc;
106
+ const inputs = [];
107
+ const checked = [];
101
108
  for (let i = 0; i < this.#recipients.length; i++) {
102
109
  const recipient = this.#recipients[i];
103
- if (!isDisjoint(this.#protectedHeader, this.#unprotectedHeader, recipient.unprotectedHeader)) {
104
- throw new JWEInvalid('JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint');
105
- }
106
- const joseHeader = {
107
- ...this.#protectedHeader,
108
- ...this.#unprotectedHeader,
109
- ...recipient.unprotectedHeader,
110
+ const input = {
111
+ plaintext: this.#plaintext,
112
+ protectedHeader: this.#protectedHeader,
113
+ unprotectedHeader: recipient.unprotectedHeader,
114
+ sharedUnprotectedHeader: this.#unprotectedHeader,
115
+ aad: this.#aad,
116
+ keyManagementParameters: recipient.keyManagementParameters,
117
+ crit: recipient.options.crit,
118
+ unprotectedParameters: true,
110
119
  };
111
- const { alg } = joseHeader;
112
- if (typeof alg !== 'string' || !alg) {
113
- throw new JWEInvalid('JWE "alg" (Algorithm) Header Parameter missing or invalid');
114
- }
115
- if (alg === 'dir' || alg === 'ECDH-ES') {
120
+ const headers = checkEncryptHeaders(input);
121
+ inputs.push(input);
122
+ checked.push(headers);
123
+ if (headers.alg === 'dir' || headers.alg === 'ECDH-ES') {
116
124
  throw new JWEInvalid('"dir" and "ECDH-ES" alg may only be used with a single recipient');
117
125
  }
118
- if (typeof joseHeader.enc !== 'string' || !joseHeader.enc) {
119
- throw new JWEInvalid('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');
120
- }
121
126
  if (!enc) {
122
- enc = joseHeader.enc;
127
+ enc = headers.enc;
123
128
  }
124
- else if (enc !== joseHeader.enc) {
129
+ else if (enc !== headers.enc) {
125
130
  throw new JWEInvalid('JWE "enc" (Encryption Algorithm) Header Parameter must be the same for all recipients');
126
131
  }
127
- validateCrit(JWEInvalid, new Map(), recipient.options.crit, this.#protectedHeader, joseHeader);
128
- if (joseHeader.zip !== undefined && joseHeader.zip !== 'DEF') {
129
- throw new JOSENotSupported('Unsupported JWE "zip" (Compression Algorithm) Header Parameter value.');
130
- }
131
- if (joseHeader.zip !== undefined && !this.#protectedHeader?.zip) {
132
- throw new JWEInvalid('JWE "zip" (Compression Algorithm) Header Parameter MUST be in a protected header.');
133
- }
134
132
  }
135
- const cek = generateCek(enc);
133
+ const cek = generateCek(checked[0].encEntry);
136
134
  const jwe = {
137
135
  ciphertext: '',
138
136
  recipients: [],
@@ -142,17 +140,7 @@ export class GeneralEncrypt {
142
140
  const target = {};
143
141
  jwe.recipients.push(target);
144
142
  if (i === 0) {
145
- const flattened = await new FlattenedEncrypt(this.#plaintext)
146
- .setAdditionalAuthenticatedData(this.#aad)
147
- .setContentEncryptionKey(cek)
148
- .setProtectedHeader(this.#protectedHeader)
149
- .setSharedUnprotectedHeader(this.#unprotectedHeader)
150
- .setUnprotectedHeader(recipient.unprotectedHeader)
151
- .setKeyManagementParameters(recipient.keyManagementParameters)
152
- .encrypt(recipient.key, {
153
- ...recipient.options,
154
- [unprotected]: true,
155
- });
143
+ const flattened = await encryptJWE({ ...inputs[0], cek }, checked[0], recipient.key);
156
144
  jwe.ciphertext = flattened.ciphertext;
157
145
  jwe.iv = flattened.iv;
158
146
  jwe.tag = flattened.tag;
@@ -167,12 +155,9 @@ export class GeneralEncrypt {
167
155
  target.header = flattened.header;
168
156
  continue;
169
157
  }
170
- const alg = recipient.unprotectedHeader?.alg ||
171
- this.#protectedHeader?.alg ||
172
- this.#unprotectedHeader?.alg;
173
- checkKeyType(alg === 'dir' ? enc : alg, recipient.key, 'encrypt');
174
- const k = await normalizeKey(recipient.key, alg);
175
- const { encryptedKey, parameters } = await encryptKeyManagement(alg, enc, k, cek, recipient.keyManagementParameters);
158
+ const { alg } = checked[i];
159
+ const k = await prepareKey(jweAlgorithm(alg), recipient.key, 'encrypt');
160
+ const { encryptedKey, parameters } = await encryptKeyManagement(alg, checked[i].encEntry, k, cek, recipient.keyManagementParameters);
176
161
  target.encrypted_key = b64u(encryptedKey);
177
162
  if (recipient.unprotectedHeader || parameters)
178
163
  target.header = { ...recipient.unprotectedHeader, ...parameters };
@@ -1,4 +1,5 @@
1
- import { importJWK } from '../key/import.js';
1
+ import { jwkToKey } from '../lib/jwk_to_key.js';
2
+ import { jwsAlgorithm } from '../lib/jws_algorithms.js';
2
3
  import { isObject } from '../lib/type_checks.js';
3
4
  import { JWSInvalid } from '../util/errors.js';
4
5
  export async function EmbeddedJWK(protectedHeader, token) {
@@ -9,8 +10,9 @@ export async function EmbeddedJWK(protectedHeader, token) {
9
10
  if (!isObject(joseHeader.jwk)) {
10
11
  throw new JWSInvalid('"jwk" (JSON Web Key) Header Parameter must be a JSON object');
11
12
  }
12
- const key = await importJWK({ ...joseHeader.jwk, ext: true }, joseHeader.alg);
13
- if (key instanceof Uint8Array || key.type !== 'public') {
13
+ const entry = jwsAlgorithm(joseHeader.alg);
14
+ const key = await jwkToKey(entry, { ...joseHeader.jwk, ext: true });
15
+ if (key.type !== 'public') {
14
16
  throw new JWSInvalid('"jwk" (JSON Web Key) Header Parameter must be a public key');
15
17
  }
16
18
  return key;
@@ -1,31 +1,25 @@
1
- import { importJWK } from '../key/import.js';
1
+ import { jwkToKey } from '../lib/jwk_to_key.js';
2
+ import { maybeJWSAlgorithm } from '../lib/jws_algorithms.js';
2
3
  import { JWKSInvalid, JOSENotSupported, JWKSNoMatchingKey, JWKSMultipleMatchingKeys, } from '../util/errors.js';
3
4
  import { isObject } from '../lib/type_checks.js';
4
- function getKtyFromAlg(alg) {
5
- switch (typeof alg === 'string' && alg.slice(0, 2)) {
6
- case 'RS':
7
- case 'PS':
8
- return 'RSA';
9
- case 'ES':
10
- return 'EC';
11
- case 'Ed':
12
- return 'OKP';
13
- case 'ML':
14
- return 'AKP';
15
- default:
16
- throw new JOSENotSupported('Unsupported "alg" value for a JSON Web Key Set');
5
+ function signatureAlgorithm(alg) {
6
+ const entry = typeof alg === 'string' ? maybeJWSAlgorithm(alg) : undefined;
7
+ if (!entry || entry.symmetric) {
8
+ throw new JOSENotSupported('Unsupported "alg" value for a JSON Web Key Set');
17
9
  }
10
+ return entry;
18
11
  }
19
12
  function isJWKSLike(jwks) {
20
- return (jwks &&
21
- typeof jwks === 'object' &&
22
- Array.isArray(jwks.keys) &&
23
- jwks.keys.every(isJWKLike));
13
+ if (!jwks || typeof jwks !== 'object') {
14
+ return false;
15
+ }
16
+ const { keys } = jwks;
17
+ return Array.isArray(keys) && keys.every(isJWKLike);
24
18
  }
25
19
  function isJWKLike(key) {
26
20
  return isObject(key);
27
21
  }
28
- class LocalJWKSet {
22
+ class LocalJWKSetImpl {
29
23
  #jwks;
30
24
  #cached = new WeakMap();
31
25
  constructor(jwks) {
@@ -39,13 +33,13 @@ class LocalJWKSet {
39
33
  }
40
34
  async getKey(protectedHeader, token) {
41
35
  const { alg, kid } = { ...protectedHeader, ...token?.header };
42
- const kty = getKtyFromAlg(alg);
36
+ const entry = signatureAlgorithm(alg);
43
37
  const candidates = this.#jwks.keys.filter((jwk) => {
44
- let candidate = kty === jwk.kty;
38
+ let candidate = entry.kty.includes(jwk.kty);
45
39
  if (candidate && typeof kid === 'string') {
46
40
  candidate = kid === jwk.kid;
47
41
  }
48
- if (candidate && (typeof jwk.alg === 'string' || kty === 'AKP')) {
42
+ if (candidate && (typeof jwk.alg === 'string' || jwk.kty === 'AKP')) {
49
43
  candidate = alg === jwk.alg;
50
44
  }
51
45
  if (candidate && typeof jwk.use === 'string') {
@@ -54,22 +48,8 @@ class LocalJWKSet {
54
48
  if (candidate && Array.isArray(jwk.key_ops)) {
55
49
  candidate = jwk.key_ops.includes('verify');
56
50
  }
57
- if (candidate) {
58
- switch (alg) {
59
- case 'ES256':
60
- candidate = jwk.crv === 'P-256';
61
- break;
62
- case 'ES384':
63
- candidate = jwk.crv === 'P-384';
64
- break;
65
- case 'ES512':
66
- candidate = jwk.crv === 'P-521';
67
- break;
68
- case 'Ed25519':
69
- case 'EdDSA':
70
- candidate = jwk.crv === 'Ed25519';
71
- break;
72
- }
51
+ if (candidate && entry.crv) {
52
+ candidate = jwk.crv === entry.crv;
73
53
  }
74
54
  return candidate;
75
55
  });
@@ -83,29 +63,29 @@ class LocalJWKSet {
83
63
  error[Symbol.asyncIterator] = async function* () {
84
64
  for (const jwk of candidates) {
85
65
  try {
86
- yield await importWithAlgCache(_cached, jwk, alg);
66
+ yield await importWithAlgCache(_cached, jwk, entry);
87
67
  }
88
68
  catch { }
89
69
  }
90
70
  };
91
71
  throw error;
92
72
  }
93
- return importWithAlgCache(this.#cached, jwk, alg);
73
+ return importWithAlgCache(this.#cached, jwk, entry);
94
74
  }
95
75
  }
96
- async function importWithAlgCache(cache, jwk, alg) {
76
+ async function importWithAlgCache(cache, jwk, entry) {
97
77
  const cached = cache.get(jwk) || cache.set(jwk, {}).get(jwk);
98
- if (cached[alg] === undefined) {
99
- const key = await importJWK({ ...jwk, ext: true }, alg);
100
- if (key instanceof Uint8Array || key.type !== 'public') {
78
+ if (cached[entry.alg] === undefined) {
79
+ const key = await jwkToKey(entry, { ...jwk, alg: entry.alg, ext: true });
80
+ if (key.type !== 'public') {
101
81
  throw new JWKSInvalid('JSON Web Key Set members must be public keys');
102
82
  }
103
- cached[alg] = key;
83
+ cached[entry.alg] = key;
104
84
  }
105
- return cached[alg];
85
+ return cached[entry.alg];
106
86
  }
107
87
  export function createLocalJWKSet(jwks) {
108
- const set = new LocalJWKSet(jwks);
88
+ const set = new LocalJWKSetImpl(jwks);
109
89
  const localJWKSet = async (protectedHeader, token) => set.getKey(protectedHeader, token);
110
90
  Object.defineProperties(localJWKSet, {
111
91
  jwks: {
@@ -9,7 +9,7 @@ function isCloudflareWorkers() {
9
9
  let USER_AGENT;
10
10
  if (typeof navigator === 'undefined' || !navigator.userAgent?.startsWith?.('Mozilla/5.0 ')) {
11
11
  const NAME = 'jose';
12
- const VERSION = 'v6.2.4';
12
+ const VERSION = 'v6.2.5';
13
13
  USER_AGENT = `${NAME}/${VERSION}`;
14
14
  }
15
15
  export const customFetch = Symbol();
@@ -51,7 +51,7 @@ function isFreshJwksCache(input, cacheMaxAge) {
51
51
  }
52
52
  return true;
53
53
  }
54
- class RemoteJWKSet {
54
+ class RemoteJWKSetImpl {
55
55
  #url;
56
56
  #timeoutDuration;
57
57
  #cooldownDuration;
@@ -144,7 +144,7 @@ class RemoteJWKSet {
144
144
  }
145
145
  }
146
146
  export function createRemoteJWKSet(url, options) {
147
- const set = new RemoteJWKSet(url, options);
147
+ const set = new RemoteJWKSetImpl(url, options);
148
148
  const remoteJWKSet = async (protectedHeader, token) => set.getKey(protectedHeader, token);
149
149
  Object.defineProperties(remoteJWKSet, {
150
150
  coolingDown: {
@@ -1,18 +1,21 @@
1
1
  import { FlattenedSign } from '../flattened/sign.js';
2
+ import { unencodedPayload } from '../../lib/jws_sign.js';
2
3
  export class CompactSign {
3
4
  #flattened;
5
+ #protectedHeader;
4
6
  constructor(payload) {
5
7
  this.#flattened = new FlattenedSign(payload);
6
8
  }
7
9
  setProtectedHeader(protectedHeader) {
8
10
  this.#flattened.setProtectedHeader(protectedHeader);
11
+ this.#protectedHeader = protectedHeader;
9
12
  return this;
10
13
  }
11
14
  async sign(key, options) {
12
- const jws = await this.#flattened.sign(key, options);
13
- if (jws.payload === undefined) {
15
+ if (unencodedPayload(this.#protectedHeader)) {
14
16
  throw new TypeError('use the flattened module for creating JWS with b64: false');
15
17
  }
18
+ const jws = await this.#flattened.sign(key, options);
16
19
  return `${jws.protected}.${jws.payload}.${jws.signature}`;
17
20
  }
18
21
  }
@@ -1,19 +1,7 @@
1
- import { flattenedVerify } from '../flattened/verify.js';
2
- import { JWSInvalid } from '../../util/errors.js';
3
- import { decoder } from '../../lib/buffer_utils.js';
1
+ import { prepareVerify, verifyCompact } from '../../lib/jws_verify.js';
4
2
  export async function compactVerify(jws, key, options) {
5
- if (jws instanceof Uint8Array) {
6
- jws = decoder.decode(jws);
7
- }
8
- if (typeof jws !== 'string') {
9
- throw new JWSInvalid('Compact JWS must be a string or Uint8Array');
10
- }
11
- const { 0: protectedHeader, 1: payload, 2: signature, length } = jws.split('.');
12
- if (length !== 3) {
13
- throw new JWSInvalid('Invalid Compact JWS');
14
- }
15
- const verified = await flattenedVerify({ payload, protected: protectedHeader, signature }, key, options);
16
- const result = { payload: verified.payload, protectedHeader: verified.protectedHeader };
3
+ const verified = await verifyCompact(jws, prepareVerify(options), key);
4
+ const result = { payload: verified.payload, protectedHeader: verified.parsedProt };
17
5
  if (typeof key === 'function') {
18
6
  return { ...result, key: verified.key };
19
7
  }
@@ -1,11 +1,5 @@
1
- import { encode as b64u } from '../../util/base64url.js';
2
- import { sign } from '../../lib/signing.js';
3
- import { isDisjoint } from '../../lib/type_checks.js';
4
1
  import { JWSInvalid } from '../../util/errors.js';
5
- import { concat, encode } from '../../lib/buffer_utils.js';
6
- import { checkKeyType } from '../../lib/check_key_type.js';
7
- import { validateCrit } from '../../lib/validate_crit.js';
8
- import { normalizeKey } from '../../lib/normalize_key.js';
2
+ import { createSignature } from '../../lib/jws_sign.js';
9
3
  import { assertNotSet } from '../../lib/helpers.js';
10
4
  export class FlattenedSign {
11
5
  #payload;
@@ -31,59 +25,15 @@ export class FlattenedSign {
31
25
  if (!this.#protectedHeader && !this.#unprotectedHeader) {
32
26
  throw new JWSInvalid('either setProtectedHeader or setUnprotectedHeader must be called before #sign()');
33
27
  }
34
- if (!isDisjoint(this.#protectedHeader, this.#unprotectedHeader)) {
35
- throw new JWSInvalid('JWS Protected and JWS Unprotected Header Parameter names must be disjoint');
36
- }
37
- const joseHeader = {
38
- ...this.#protectedHeader,
39
- ...this.#unprotectedHeader,
40
- };
41
- const extensions = validateCrit(JWSInvalid, new Map([['b64', true]]), options?.crit, this.#protectedHeader, joseHeader);
42
- let b64 = true;
43
- if (extensions.has('b64')) {
44
- b64 = this.#protectedHeader.b64;
45
- if (typeof b64 !== 'boolean') {
46
- throw new JWSInvalid('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
47
- }
48
- }
49
- const { alg } = joseHeader;
50
- if (typeof alg !== 'string' || !alg) {
51
- throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
52
- }
53
- checkKeyType(alg, key, 'sign');
54
- let payloadS;
55
- let payloadB;
56
- if (b64) {
57
- payloadS = b64u(this.#payload);
58
- payloadB = encode(payloadS);
59
- }
60
- else {
61
- payloadB = this.#payload;
62
- payloadS = '';
63
- }
64
- let protectedHeaderString;
65
- let protectedHeaderBytes;
66
- if (this.#protectedHeader) {
67
- protectedHeaderString = b64u(JSON.stringify(this.#protectedHeader));
68
- protectedHeaderBytes = encode(protectedHeaderString);
69
- }
70
- else {
71
- protectedHeaderString = '';
72
- protectedHeaderBytes = new Uint8Array();
73
- }
74
- const data = concat(protectedHeaderBytes, encode('.'), payloadB);
75
- const k = await normalizeKey(key, alg);
76
- const signature = await sign(alg, k, data);
77
- const jws = {
78
- signature: b64u(signature),
79
- payload: payloadS,
80
- };
28
+ const jws = await createSignature({
29
+ payload: this.#payload,
30
+ protectedHeader: this.#protectedHeader,
31
+ unprotectedHeader: this.#unprotectedHeader,
32
+ crit: options?.crit,
33
+ }, key);
81
34
  if (this.#unprotectedHeader) {
82
35
  jws.header = this.#unprotectedHeader;
83
36
  }
84
- if (this.#protectedHeader) {
85
- jws.protected = protectedHeaderString;
86
- }
87
37
  return jws;
88
38
  }
89
39
  }