oidc-spa 8.1.9 → 8.1.11

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 (196) hide show
  1. package/backend.d.ts +27 -6
  2. package/backend.js +124 -139
  3. package/backend.js.map +1 -1
  4. package/core/Oidc.d.ts +28 -4
  5. package/core/createOidc.d.ts +12 -3
  6. package/core/createOidc.js +1 -1
  7. package/core/createOidc.js.map +1 -1
  8. package/core/earlyInit.d.ts +1 -0
  9. package/core/earlyInit.js +11 -4
  10. package/core/earlyInit.js.map +1 -1
  11. package/core/iframeMessageProtection.js +16 -18
  12. package/core/iframeMessageProtection.js.map +1 -1
  13. package/core/loginOrGoToAuthServer.js +8 -3
  14. package/core/loginOrGoToAuthServer.js.map +1 -1
  15. package/core/loginSilent.js +4 -0
  16. package/core/loginSilent.js.map +1 -1
  17. package/core/oidcClientTsUserToTokens.d.ts +1 -1
  18. package/core/oidcClientTsUserToTokens.js.map +1 -1
  19. package/core/requiredPostHydrationReplaceNavigationUrl.d.ts +6 -0
  20. package/core/requiredPostHydrationReplaceNavigationUrl.js +12 -0
  21. package/core/requiredPostHydrationReplaceNavigationUrl.js.map +1 -0
  22. package/entrypoint.d.ts +1 -0
  23. package/entrypoint.js +3 -1
  24. package/entrypoint.js.map +1 -1
  25. package/esm/angular.d.ts +14 -4
  26. package/esm/angular.js +155 -10
  27. package/esm/angular.js.map +1 -1
  28. package/esm/backend.d.ts +48 -0
  29. package/esm/backend.js +259 -0
  30. package/esm/backend.js.map +1 -0
  31. package/esm/core/Oidc.d.ts +28 -4
  32. package/esm/core/createOidc.d.ts +12 -3
  33. package/esm/core/createOidc.js +1 -1
  34. package/esm/core/createOidc.js.map +1 -1
  35. package/esm/core/earlyInit.d.ts +1 -0
  36. package/esm/core/earlyInit.js +11 -4
  37. package/esm/core/earlyInit.js.map +1 -1
  38. package/esm/core/iframeMessageProtection.js +16 -18
  39. package/esm/core/iframeMessageProtection.js.map +1 -1
  40. package/esm/core/loginOrGoToAuthServer.js +8 -3
  41. package/esm/core/loginOrGoToAuthServer.js.map +1 -1
  42. package/esm/core/loginSilent.js +4 -0
  43. package/esm/core/loginSilent.js.map +1 -1
  44. package/esm/core/oidcClientTsUserToTokens.d.ts +1 -1
  45. package/esm/core/oidcClientTsUserToTokens.js.map +1 -1
  46. package/esm/core/requiredPostHydrationReplaceNavigationUrl.d.ts +6 -0
  47. package/esm/core/requiredPostHydrationReplaceNavigationUrl.js +8 -0
  48. package/esm/core/requiredPostHydrationReplaceNavigationUrl.js.map +1 -0
  49. package/esm/entrypoint.d.ts +1 -0
  50. package/esm/entrypoint.js +1 -0
  51. package/esm/entrypoint.js.map +1 -1
  52. package/esm/mock/oidc.d.ts +1 -1
  53. package/esm/mock/oidc.js.map +1 -1
  54. package/esm/react/react.d.ts +1 -1
  55. package/esm/tanstack-start/react/accessTokenValidation_rfc9068.d.ts +12 -0
  56. package/esm/tanstack-start/react/accessTokenValidation_rfc9068.js +95 -0
  57. package/esm/tanstack-start/react/accessTokenValidation_rfc9068.js.map +1 -0
  58. package/esm/tanstack-start/react/apiBuilder.d.ts +27 -0
  59. package/esm/tanstack-start/react/apiBuilder.js +58 -0
  60. package/esm/tanstack-start/react/apiBuilder.js.map +1 -0
  61. package/esm/tanstack-start/react/createOidcSpaApi.d.ts +9 -0
  62. package/esm/tanstack-start/react/createOidcSpaApi.js +678 -0
  63. package/esm/tanstack-start/react/createOidcSpaApi.js.map +1 -0
  64. package/esm/tanstack-start/react/index.d.ts +3 -0
  65. package/esm/tanstack-start/react/index.js +4 -0
  66. package/esm/tanstack-start/react/index.js.map +1 -0
  67. package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/UnifiedClientRetryForSsrLoadersError.d.ts +4 -0
  68. package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/UnifiedClientRetryForSsrLoadersError.js +8 -0
  69. package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/UnifiedClientRetryForSsrLoadersError.js.map +1 -0
  70. package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/enableUnifiedClientRetryForSsrLoaders.d.ts +4 -0
  71. package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/enableUnifiedClientRetryForSsrLoaders.js +76 -0
  72. package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/enableUnifiedClientRetryForSsrLoaders.js.map +1 -0
  73. package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/entrypoint.d.ts +1 -0
  74. package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/entrypoint.js +11 -0
  75. package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/entrypoint.js.map +1 -0
  76. package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/index.d.ts +2 -0
  77. package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/index.js +3 -0
  78. package/esm/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/index.js.map +1 -0
  79. package/esm/tanstack-start/react/types.d.ts +355 -0
  80. package/esm/tanstack-start/react/types.js +2 -0
  81. package/esm/tanstack-start/react/types.js.map +1 -0
  82. package/esm/tanstack-start/react/withHandlingOidcPostLoginNavigation.d.ts +2 -0
  83. package/esm/tanstack-start/react/withHandlingOidcPostLoginNavigation.js +25 -0
  84. package/esm/tanstack-start/react/withHandlingOidcPostLoginNavigation.js.map +1 -0
  85. package/esm/tools/GetterOrDirectValue.d.ts +1 -0
  86. package/esm/tools/GetterOrDirectValue.js +2 -0
  87. package/esm/tools/GetterOrDirectValue.js.map +1 -0
  88. package/esm/tools/ZodSchemaLike.d.ts +3 -0
  89. package/esm/tools/ZodSchemaLike.js +2 -0
  90. package/esm/tools/ZodSchemaLike.js.map +1 -0
  91. package/esm/tools/inferIsViteDev.d.ts +1 -0
  92. package/esm/tools/inferIsViteDev.js +6 -0
  93. package/esm/tools/inferIsViteDev.js.map +1 -0
  94. package/esm/tools/infer_import_meta_env_BASE_URL.d.ts +1 -0
  95. package/esm/tools/infer_import_meta_env_BASE_URL.js +15 -0
  96. package/esm/tools/infer_import_meta_env_BASE_URL.js.map +1 -0
  97. package/esm/tools/tsafe/uncapitalize.d.ts +2 -0
  98. package/esm/tools/tsafe/uncapitalize.js +5 -0
  99. package/esm/tools/tsafe/uncapitalize.js.map +1 -0
  100. package/esm/vendor/backend/evt.d.ts +2 -0
  101. package/esm/vendor/backend/evt.js +3286 -0
  102. package/esm/vendor/backend/jose.d.ts +1 -0
  103. package/esm/vendor/backend/jose.js +3546 -0
  104. package/esm/vendor/backend/tsafe.d.ts +5 -0
  105. package/esm/vendor/backend/tsafe.js +68 -0
  106. package/esm/vendor/backend/zod.d.ts +1 -0
  107. package/esm/vendor/backend/zod.js +4023 -0
  108. package/esm/vendor/frontend/worker-timers.js +261 -1
  109. package/mock/oidc.d.ts +1 -1
  110. package/mock/oidc.js.map +1 -1
  111. package/package.json +40 -4
  112. package/react/react.d.ts +1 -1
  113. package/src/angular.ts +224 -9
  114. package/src/backend.ts +201 -166
  115. package/src/core/Oidc.ts +41 -11
  116. package/src/core/createOidc.ts +12 -3
  117. package/src/core/earlyInit.ts +19 -4
  118. package/src/core/iframeMessageProtection.ts +14 -15
  119. package/src/core/loginOrGoToAuthServer.ts +11 -3
  120. package/src/core/loginSilent.ts +5 -0
  121. package/src/core/oidcClientTsUserToTokens.ts +2 -2
  122. package/src/core/requiredPostHydrationReplaceNavigationUrl.ts +11 -0
  123. package/src/entrypoint.ts +1 -0
  124. package/src/mock/oidc.ts +2 -2
  125. package/src/react/react.tsx +1 -1
  126. package/src/tanstack-start/react/accessTokenValidation_rfc9068.ts +135 -0
  127. package/src/tanstack-start/react/apiBuilder.ts +151 -0
  128. package/src/tanstack-start/react/createOidcSpaApi.tsx +1009 -0
  129. package/src/tanstack-start/react/index.ts +5 -0
  130. package/src/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/UnifiedClientRetryForSsrLoadersError.ts +8 -0
  131. package/src/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/enableUnifiedClientRetryForSsrLoaders.tsx +110 -0
  132. package/src/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/entrypoint.ts +13 -0
  133. package/src/tanstack-start/react/rfcUnifiedClientRetryForSsrLoaders/index.ts +2 -0
  134. package/src/tanstack-start/react/types.tsx +415 -0
  135. package/src/tanstack-start/react/withHandlingOidcPostLoginNavigation.tsx +35 -0
  136. package/src/tools/GetterOrDirectValue.ts +1 -0
  137. package/src/tools/ZodSchemaLike.ts +3 -0
  138. package/src/tools/getThisCodebaseRootDirPath_cjs.ts +19 -0
  139. package/src/tools/inferIsViteDev.ts +6 -0
  140. package/src/tools/infer_import_meta_env_BASE_URL.ts +19 -0
  141. package/src/tools/tsafe/uncapitalize.ts +4 -0
  142. package/src/vendor/backend/jose.ts +1 -0
  143. package/src/vendor/build-runtime/babel.ts +6 -0
  144. package/src/vendor/build-runtime/magic-string.ts +3 -0
  145. package/src/vite-plugin/detectProjectType.ts +20 -0
  146. package/src/vite-plugin/excludeModuleExportFromOptimizedDeps.ts +20 -0
  147. package/src/vite-plugin/handleClientEntrypoint.ts +260 -0
  148. package/src/vite-plugin/index.ts +1 -0
  149. package/src/vite-plugin/transformCreateFileRoute.ts +240 -0
  150. package/src/vite-plugin/vite-plugin.ts +54 -0
  151. package/tools/GetterOrDirectValue.d.ts +1 -0
  152. package/tools/GetterOrDirectValue.js +3 -0
  153. package/tools/GetterOrDirectValue.js.map +1 -0
  154. package/tools/ZodSchemaLike.d.ts +3 -0
  155. package/tools/ZodSchemaLike.js +3 -0
  156. package/tools/ZodSchemaLike.js.map +1 -0
  157. package/tools/getThisCodebaseRootDirPath_cjs.d.ts +2 -0
  158. package/tools/getThisCodebaseRootDirPath_cjs.js +53 -0
  159. package/tools/getThisCodebaseRootDirPath_cjs.js.map +1 -0
  160. package/tools/tsafe/uncapitalize.d.ts +2 -0
  161. package/tools/tsafe/uncapitalize.js +8 -0
  162. package/tools/tsafe/uncapitalize.js.map +1 -0
  163. package/vendor/backend/jose.d.ts +1 -0
  164. package/vendor/backend/jose.js +3 -0
  165. package/vendor/build-runtime/babel.d.ts +6 -0
  166. package/vendor/build-runtime/babel.js +3 -0
  167. package/vendor/build-runtime/magic-string.d.ts +2 -0
  168. package/vendor/build-runtime/magic-string.js +2 -0
  169. package/vendor/frontend/oidc-client-ts.js +0 -2
  170. package/vite-plugin/detectProjectType.d.ts +10 -0
  171. package/vite-plugin/detectProjectType.js +15 -0
  172. package/vite-plugin/detectProjectType.js.map +1 -0
  173. package/vite-plugin/excludeModuleExportFromOptimizedDeps.d.ts +4 -0
  174. package/vite-plugin/excludeModuleExportFromOptimizedDeps.js +50 -0
  175. package/vite-plugin/excludeModuleExportFromOptimizedDeps.js.map +1 -0
  176. package/vite-plugin/handleClientEntrypoint.d.ts +10 -0
  177. package/vite-plugin/handleClientEntrypoint.js +211 -0
  178. package/vite-plugin/handleClientEntrypoint.js.map +1 -0
  179. package/vite-plugin/index.d.ts +1 -0
  180. package/vite-plugin/index.js +6 -0
  181. package/vite-plugin/index.js.map +1 -0
  182. package/vite-plugin/transformCreateFileRoute.d.ts +10 -0
  183. package/vite-plugin/transformCreateFileRoute.js +173 -0
  184. package/vite-plugin/transformCreateFileRoute.js.map +1 -0
  185. package/vite-plugin/vite-plugin.d.ts +5 -0
  186. package/vite-plugin/vite-plugin.js +46 -0
  187. package/vite-plugin/vite-plugin.js.map +1 -0
  188. package/src/vendor/backend/jsonwebtoken.ts +0 -1
  189. package/src/vendor/backend/node-fetch.ts +0 -2
  190. package/src/vendor/backend/node-jose.ts +0 -1
  191. package/vendor/backend/jsonwebtoken.d.ts +0 -1
  192. package/vendor/backend/jsonwebtoken.js +0 -3
  193. package/vendor/backend/node-fetch.d.ts +0 -2
  194. package/vendor/backend/node-fetch.js +0 -2
  195. package/vendor/backend/node-jose.d.ts +0 -1
  196. package/vendor/backend/node-jose.js +0 -3
@@ -0,0 +1,3546 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // node_modules/jose/dist/browser/runtime/webcrypto.js
8
+ var webcrypto_default = crypto;
9
+ var isCryptoKey = (key) => key instanceof CryptoKey;
10
+
11
+ // node_modules/jose/dist/browser/runtime/digest.js
12
+ var digest = async (algorithm, data) => {
13
+ const subtleDigest = `SHA-${algorithm.slice(-3)}`;
14
+ return new Uint8Array(await webcrypto_default.subtle.digest(subtleDigest, data));
15
+ };
16
+ var digest_default = digest;
17
+
18
+ // node_modules/jose/dist/browser/lib/buffer_utils.js
19
+ var encoder = new TextEncoder();
20
+ var decoder = new TextDecoder();
21
+ var MAX_INT32 = 2 ** 32;
22
+ function concat(...buffers) {
23
+ const size = buffers.reduce((acc, { length }) => acc + length, 0);
24
+ const buf = new Uint8Array(size);
25
+ let i = 0;
26
+ for (const buffer of buffers) {
27
+ buf.set(buffer, i);
28
+ i += buffer.length;
29
+ }
30
+ return buf;
31
+ }
32
+ function p2s(alg, p2sInput) {
33
+ return concat(encoder.encode(alg), new Uint8Array([0]), p2sInput);
34
+ }
35
+ function writeUInt32BE(buf, value, offset) {
36
+ if (value < 0 || value >= MAX_INT32) {
37
+ throw new RangeError(`value must be >= 0 and <= ${MAX_INT32 - 1}. Received ${value}`);
38
+ }
39
+ buf.set([value >>> 24, value >>> 16, value >>> 8, value & 255], offset);
40
+ }
41
+ function uint64be(value) {
42
+ const high = Math.floor(value / MAX_INT32);
43
+ const low = value % MAX_INT32;
44
+ const buf = new Uint8Array(8);
45
+ writeUInt32BE(buf, high, 0);
46
+ writeUInt32BE(buf, low, 4);
47
+ return buf;
48
+ }
49
+ function uint32be(value) {
50
+ const buf = new Uint8Array(4);
51
+ writeUInt32BE(buf, value);
52
+ return buf;
53
+ }
54
+ function lengthAndInput(input) {
55
+ return concat(uint32be(input.length), input);
56
+ }
57
+ async function concatKdf(secret, bits, value) {
58
+ const iterations = Math.ceil((bits >> 3) / 32);
59
+ const res = new Uint8Array(iterations * 32);
60
+ for (let iter = 0; iter < iterations; iter++) {
61
+ const buf = new Uint8Array(4 + secret.length + value.length);
62
+ buf.set(uint32be(iter + 1));
63
+ buf.set(secret, 4);
64
+ buf.set(value, 4 + secret.length);
65
+ res.set(await digest_default("sha256", buf), iter * 32);
66
+ }
67
+ return res.slice(0, bits >> 3);
68
+ }
69
+
70
+ // node_modules/jose/dist/browser/runtime/base64url.js
71
+ var encodeBase64 = (input) => {
72
+ let unencoded = input;
73
+ if (typeof unencoded === "string") {
74
+ unencoded = encoder.encode(unencoded);
75
+ }
76
+ const CHUNK_SIZE = 32768;
77
+ const arr = [];
78
+ for (let i = 0; i < unencoded.length; i += CHUNK_SIZE) {
79
+ arr.push(String.fromCharCode.apply(null, unencoded.subarray(i, i + CHUNK_SIZE)));
80
+ }
81
+ return btoa(arr.join(""));
82
+ };
83
+ var encode = (input) => {
84
+ return encodeBase64(input).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
85
+ };
86
+ var decodeBase64 = (encoded) => {
87
+ const binary = atob(encoded);
88
+ const bytes = new Uint8Array(binary.length);
89
+ for (let i = 0; i < binary.length; i++) {
90
+ bytes[i] = binary.charCodeAt(i);
91
+ }
92
+ return bytes;
93
+ };
94
+ var decode = (input) => {
95
+ let encoded = input;
96
+ if (encoded instanceof Uint8Array) {
97
+ encoded = decoder.decode(encoded);
98
+ }
99
+ encoded = encoded.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
100
+ try {
101
+ return decodeBase64(encoded);
102
+ } catch {
103
+ throw new TypeError("The input to be decoded is not correctly encoded.");
104
+ }
105
+ };
106
+
107
+ // node_modules/jose/dist/browser/util/errors.js
108
+ var errors_exports = {};
109
+ __export(errors_exports, {
110
+ JOSEAlgNotAllowed: () => JOSEAlgNotAllowed,
111
+ JOSEError: () => JOSEError,
112
+ JOSENotSupported: () => JOSENotSupported,
113
+ JWEDecryptionFailed: () => JWEDecryptionFailed,
114
+ JWEInvalid: () => JWEInvalid,
115
+ JWKInvalid: () => JWKInvalid,
116
+ JWKSInvalid: () => JWKSInvalid,
117
+ JWKSMultipleMatchingKeys: () => JWKSMultipleMatchingKeys,
118
+ JWKSNoMatchingKey: () => JWKSNoMatchingKey,
119
+ JWKSTimeout: () => JWKSTimeout,
120
+ JWSInvalid: () => JWSInvalid,
121
+ JWSSignatureVerificationFailed: () => JWSSignatureVerificationFailed,
122
+ JWTClaimValidationFailed: () => JWTClaimValidationFailed,
123
+ JWTExpired: () => JWTExpired,
124
+ JWTInvalid: () => JWTInvalid
125
+ });
126
+ var JOSEError = class extends Error {
127
+ constructor(message2, options) {
128
+ super(message2, options);
129
+ this.code = "ERR_JOSE_GENERIC";
130
+ this.name = this.constructor.name;
131
+ Error.captureStackTrace?.(this, this.constructor);
132
+ }
133
+ };
134
+ JOSEError.code = "ERR_JOSE_GENERIC";
135
+ var JWTClaimValidationFailed = class extends JOSEError {
136
+ constructor(message2, payload, claim = "unspecified", reason = "unspecified") {
137
+ super(message2, { cause: { claim, reason, payload } });
138
+ this.code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
139
+ this.claim = claim;
140
+ this.reason = reason;
141
+ this.payload = payload;
142
+ }
143
+ };
144
+ JWTClaimValidationFailed.code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
145
+ var JWTExpired = class extends JOSEError {
146
+ constructor(message2, payload, claim = "unspecified", reason = "unspecified") {
147
+ super(message2, { cause: { claim, reason, payload } });
148
+ this.code = "ERR_JWT_EXPIRED";
149
+ this.claim = claim;
150
+ this.reason = reason;
151
+ this.payload = payload;
152
+ }
153
+ };
154
+ JWTExpired.code = "ERR_JWT_EXPIRED";
155
+ var JOSEAlgNotAllowed = class extends JOSEError {
156
+ constructor() {
157
+ super(...arguments);
158
+ this.code = "ERR_JOSE_ALG_NOT_ALLOWED";
159
+ }
160
+ };
161
+ JOSEAlgNotAllowed.code = "ERR_JOSE_ALG_NOT_ALLOWED";
162
+ var JOSENotSupported = class extends JOSEError {
163
+ constructor() {
164
+ super(...arguments);
165
+ this.code = "ERR_JOSE_NOT_SUPPORTED";
166
+ }
167
+ };
168
+ JOSENotSupported.code = "ERR_JOSE_NOT_SUPPORTED";
169
+ var JWEDecryptionFailed = class extends JOSEError {
170
+ constructor(message2 = "decryption operation failed", options) {
171
+ super(message2, options);
172
+ this.code = "ERR_JWE_DECRYPTION_FAILED";
173
+ }
174
+ };
175
+ JWEDecryptionFailed.code = "ERR_JWE_DECRYPTION_FAILED";
176
+ var JWEInvalid = class extends JOSEError {
177
+ constructor() {
178
+ super(...arguments);
179
+ this.code = "ERR_JWE_INVALID";
180
+ }
181
+ };
182
+ JWEInvalid.code = "ERR_JWE_INVALID";
183
+ var JWSInvalid = class extends JOSEError {
184
+ constructor() {
185
+ super(...arguments);
186
+ this.code = "ERR_JWS_INVALID";
187
+ }
188
+ };
189
+ JWSInvalid.code = "ERR_JWS_INVALID";
190
+ var JWTInvalid = class extends JOSEError {
191
+ constructor() {
192
+ super(...arguments);
193
+ this.code = "ERR_JWT_INVALID";
194
+ }
195
+ };
196
+ JWTInvalid.code = "ERR_JWT_INVALID";
197
+ var JWKInvalid = class extends JOSEError {
198
+ constructor() {
199
+ super(...arguments);
200
+ this.code = "ERR_JWK_INVALID";
201
+ }
202
+ };
203
+ JWKInvalid.code = "ERR_JWK_INVALID";
204
+ var JWKSInvalid = class extends JOSEError {
205
+ constructor() {
206
+ super(...arguments);
207
+ this.code = "ERR_JWKS_INVALID";
208
+ }
209
+ };
210
+ JWKSInvalid.code = "ERR_JWKS_INVALID";
211
+ var JWKSNoMatchingKey = class extends JOSEError {
212
+ constructor(message2 = "no applicable key found in the JSON Web Key Set", options) {
213
+ super(message2, options);
214
+ this.code = "ERR_JWKS_NO_MATCHING_KEY";
215
+ }
216
+ };
217
+ JWKSNoMatchingKey.code = "ERR_JWKS_NO_MATCHING_KEY";
218
+ var JWKSMultipleMatchingKeys = class extends JOSEError {
219
+ constructor(message2 = "multiple matching keys found in the JSON Web Key Set", options) {
220
+ super(message2, options);
221
+ this.code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
222
+ }
223
+ };
224
+ JWKSMultipleMatchingKeys.code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
225
+ var JWKSTimeout = class extends JOSEError {
226
+ constructor(message2 = "request timed out", options) {
227
+ super(message2, options);
228
+ this.code = "ERR_JWKS_TIMEOUT";
229
+ }
230
+ };
231
+ JWKSTimeout.code = "ERR_JWKS_TIMEOUT";
232
+ var JWSSignatureVerificationFailed = class extends JOSEError {
233
+ constructor(message2 = "signature verification failed", options) {
234
+ super(message2, options);
235
+ this.code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
236
+ }
237
+ };
238
+ JWSSignatureVerificationFailed.code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
239
+
240
+ // node_modules/jose/dist/browser/runtime/random.js
241
+ var random_default = webcrypto_default.getRandomValues.bind(webcrypto_default);
242
+
243
+ // node_modules/jose/dist/browser/lib/iv.js
244
+ function bitLength(alg) {
245
+ switch (alg) {
246
+ case "A128GCM":
247
+ case "A128GCMKW":
248
+ case "A192GCM":
249
+ case "A192GCMKW":
250
+ case "A256GCM":
251
+ case "A256GCMKW":
252
+ return 96;
253
+ case "A128CBC-HS256":
254
+ case "A192CBC-HS384":
255
+ case "A256CBC-HS512":
256
+ return 128;
257
+ default:
258
+ throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
259
+ }
260
+ }
261
+ var iv_default = (alg) => random_default(new Uint8Array(bitLength(alg) >> 3));
262
+
263
+ // node_modules/jose/dist/browser/lib/check_iv_length.js
264
+ var checkIvLength = (enc, iv) => {
265
+ if (iv.length << 3 !== bitLength(enc)) {
266
+ throw new JWEInvalid("Invalid Initialization Vector length");
267
+ }
268
+ };
269
+ var check_iv_length_default = checkIvLength;
270
+
271
+ // node_modules/jose/dist/browser/runtime/check_cek_length.js
272
+ var checkCekLength = (cek, expected) => {
273
+ const actual = cek.byteLength << 3;
274
+ if (actual !== expected) {
275
+ throw new JWEInvalid(`Invalid Content Encryption Key length. Expected ${expected} bits, got ${actual} bits`);
276
+ }
277
+ };
278
+ var check_cek_length_default = checkCekLength;
279
+
280
+ // node_modules/jose/dist/browser/runtime/timing_safe_equal.js
281
+ var timingSafeEqual = (a, b) => {
282
+ if (!(a instanceof Uint8Array)) {
283
+ throw new TypeError("First argument must be a buffer");
284
+ }
285
+ if (!(b instanceof Uint8Array)) {
286
+ throw new TypeError("Second argument must be a buffer");
287
+ }
288
+ if (a.length !== b.length) {
289
+ throw new TypeError("Input buffers must have the same length");
290
+ }
291
+ const len = a.length;
292
+ let out = 0;
293
+ let i = -1;
294
+ while (++i < len) {
295
+ out |= a[i] ^ b[i];
296
+ }
297
+ return out === 0;
298
+ };
299
+ var timing_safe_equal_default = timingSafeEqual;
300
+
301
+ // node_modules/jose/dist/browser/lib/crypto_key.js
302
+ function unusable(name, prop = "algorithm.name") {
303
+ return new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
304
+ }
305
+ function isAlgorithm(algorithm, name) {
306
+ return algorithm.name === name;
307
+ }
308
+ function getHashLength(hash) {
309
+ return parseInt(hash.name.slice(4), 10);
310
+ }
311
+ function getNamedCurve(alg) {
312
+ switch (alg) {
313
+ case "ES256":
314
+ return "P-256";
315
+ case "ES384":
316
+ return "P-384";
317
+ case "ES512":
318
+ return "P-521";
319
+ default:
320
+ throw new Error("unreachable");
321
+ }
322
+ }
323
+ function checkUsage(key, usages) {
324
+ if (usages.length && !usages.some((expected) => key.usages.includes(expected))) {
325
+ let msg = "CryptoKey does not support this operation, its usages must include ";
326
+ if (usages.length > 2) {
327
+ const last = usages.pop();
328
+ msg += `one of ${usages.join(", ")}, or ${last}.`;
329
+ } else if (usages.length === 2) {
330
+ msg += `one of ${usages[0]} or ${usages[1]}.`;
331
+ } else {
332
+ msg += `${usages[0]}.`;
333
+ }
334
+ throw new TypeError(msg);
335
+ }
336
+ }
337
+ function checkSigCryptoKey(key, alg, ...usages) {
338
+ switch (alg) {
339
+ case "HS256":
340
+ case "HS384":
341
+ case "HS512": {
342
+ if (!isAlgorithm(key.algorithm, "HMAC"))
343
+ throw unusable("HMAC");
344
+ const expected = parseInt(alg.slice(2), 10);
345
+ const actual = getHashLength(key.algorithm.hash);
346
+ if (actual !== expected)
347
+ throw unusable(`SHA-${expected}`, "algorithm.hash");
348
+ break;
349
+ }
350
+ case "RS256":
351
+ case "RS384":
352
+ case "RS512": {
353
+ if (!isAlgorithm(key.algorithm, "RSASSA-PKCS1-v1_5"))
354
+ throw unusable("RSASSA-PKCS1-v1_5");
355
+ const expected = parseInt(alg.slice(2), 10);
356
+ const actual = getHashLength(key.algorithm.hash);
357
+ if (actual !== expected)
358
+ throw unusable(`SHA-${expected}`, "algorithm.hash");
359
+ break;
360
+ }
361
+ case "PS256":
362
+ case "PS384":
363
+ case "PS512": {
364
+ if (!isAlgorithm(key.algorithm, "RSA-PSS"))
365
+ throw unusable("RSA-PSS");
366
+ const expected = parseInt(alg.slice(2), 10);
367
+ const actual = getHashLength(key.algorithm.hash);
368
+ if (actual !== expected)
369
+ throw unusable(`SHA-${expected}`, "algorithm.hash");
370
+ break;
371
+ }
372
+ case "EdDSA": {
373
+ if (key.algorithm.name !== "Ed25519" && key.algorithm.name !== "Ed448") {
374
+ throw unusable("Ed25519 or Ed448");
375
+ }
376
+ break;
377
+ }
378
+ case "Ed25519": {
379
+ if (!isAlgorithm(key.algorithm, "Ed25519"))
380
+ throw unusable("Ed25519");
381
+ break;
382
+ }
383
+ case "ES256":
384
+ case "ES384":
385
+ case "ES512": {
386
+ if (!isAlgorithm(key.algorithm, "ECDSA"))
387
+ throw unusable("ECDSA");
388
+ const expected = getNamedCurve(alg);
389
+ const actual = key.algorithm.namedCurve;
390
+ if (actual !== expected)
391
+ throw unusable(expected, "algorithm.namedCurve");
392
+ break;
393
+ }
394
+ default:
395
+ throw new TypeError("CryptoKey does not support this operation");
396
+ }
397
+ checkUsage(key, usages);
398
+ }
399
+ function checkEncCryptoKey(key, alg, ...usages) {
400
+ switch (alg) {
401
+ case "A128GCM":
402
+ case "A192GCM":
403
+ case "A256GCM": {
404
+ if (!isAlgorithm(key.algorithm, "AES-GCM"))
405
+ throw unusable("AES-GCM");
406
+ const expected = parseInt(alg.slice(1, 4), 10);
407
+ const actual = key.algorithm.length;
408
+ if (actual !== expected)
409
+ throw unusable(expected, "algorithm.length");
410
+ break;
411
+ }
412
+ case "A128KW":
413
+ case "A192KW":
414
+ case "A256KW": {
415
+ if (!isAlgorithm(key.algorithm, "AES-KW"))
416
+ throw unusable("AES-KW");
417
+ const expected = parseInt(alg.slice(1, 4), 10);
418
+ const actual = key.algorithm.length;
419
+ if (actual !== expected)
420
+ throw unusable(expected, "algorithm.length");
421
+ break;
422
+ }
423
+ case "ECDH": {
424
+ switch (key.algorithm.name) {
425
+ case "ECDH":
426
+ case "X25519":
427
+ case "X448":
428
+ break;
429
+ default:
430
+ throw unusable("ECDH, X25519, or X448");
431
+ }
432
+ break;
433
+ }
434
+ case "PBES2-HS256+A128KW":
435
+ case "PBES2-HS384+A192KW":
436
+ case "PBES2-HS512+A256KW":
437
+ if (!isAlgorithm(key.algorithm, "PBKDF2"))
438
+ throw unusable("PBKDF2");
439
+ break;
440
+ case "RSA-OAEP":
441
+ case "RSA-OAEP-256":
442
+ case "RSA-OAEP-384":
443
+ case "RSA-OAEP-512": {
444
+ if (!isAlgorithm(key.algorithm, "RSA-OAEP"))
445
+ throw unusable("RSA-OAEP");
446
+ const expected = parseInt(alg.slice(9), 10) || 1;
447
+ const actual = getHashLength(key.algorithm.hash);
448
+ if (actual !== expected)
449
+ throw unusable(`SHA-${expected}`, "algorithm.hash");
450
+ break;
451
+ }
452
+ default:
453
+ throw new TypeError("CryptoKey does not support this operation");
454
+ }
455
+ checkUsage(key, usages);
456
+ }
457
+
458
+ // node_modules/jose/dist/browser/lib/invalid_key_input.js
459
+ function message(msg, actual, ...types2) {
460
+ types2 = types2.filter(Boolean);
461
+ if (types2.length > 2) {
462
+ const last = types2.pop();
463
+ msg += `one of type ${types2.join(", ")}, or ${last}.`;
464
+ } else if (types2.length === 2) {
465
+ msg += `one of type ${types2[0]} or ${types2[1]}.`;
466
+ } else {
467
+ msg += `of type ${types2[0]}.`;
468
+ }
469
+ if (actual == null) {
470
+ msg += ` Received ${actual}`;
471
+ } else if (typeof actual === "function" && actual.name) {
472
+ msg += ` Received function ${actual.name}`;
473
+ } else if (typeof actual === "object" && actual != null) {
474
+ if (actual.constructor?.name) {
475
+ msg += ` Received an instance of ${actual.constructor.name}`;
476
+ }
477
+ }
478
+ return msg;
479
+ }
480
+ var invalid_key_input_default = (actual, ...types2) => {
481
+ return message("Key must be ", actual, ...types2);
482
+ };
483
+ function withAlg(alg, actual, ...types2) {
484
+ return message(`Key for the ${alg} algorithm must be `, actual, ...types2);
485
+ }
486
+
487
+ // node_modules/jose/dist/browser/runtime/is_key_like.js
488
+ var is_key_like_default = (key) => {
489
+ if (isCryptoKey(key)) {
490
+ return true;
491
+ }
492
+ return key?.[Symbol.toStringTag] === "KeyObject";
493
+ };
494
+ var types = ["CryptoKey"];
495
+
496
+ // node_modules/jose/dist/browser/runtime/decrypt.js
497
+ async function cbcDecrypt(enc, cek, ciphertext, iv, tag2, aad) {
498
+ if (!(cek instanceof Uint8Array)) {
499
+ throw new TypeError(invalid_key_input_default(cek, "Uint8Array"));
500
+ }
501
+ const keySize = parseInt(enc.slice(1, 4), 10);
502
+ const encKey = await webcrypto_default.subtle.importKey("raw", cek.subarray(keySize >> 3), "AES-CBC", false, ["decrypt"]);
503
+ const macKey = await webcrypto_default.subtle.importKey("raw", cek.subarray(0, keySize >> 3), {
504
+ hash: `SHA-${keySize << 1}`,
505
+ name: "HMAC"
506
+ }, false, ["sign"]);
507
+ const macData = concat(aad, iv, ciphertext, uint64be(aad.length << 3));
508
+ const expectedTag = new Uint8Array((await webcrypto_default.subtle.sign("HMAC", macKey, macData)).slice(0, keySize >> 3));
509
+ let macCheckPassed;
510
+ try {
511
+ macCheckPassed = timing_safe_equal_default(tag2, expectedTag);
512
+ } catch {
513
+ }
514
+ if (!macCheckPassed) {
515
+ throw new JWEDecryptionFailed();
516
+ }
517
+ let plaintext;
518
+ try {
519
+ plaintext = new Uint8Array(await webcrypto_default.subtle.decrypt({ iv, name: "AES-CBC" }, encKey, ciphertext));
520
+ } catch {
521
+ }
522
+ if (!plaintext) {
523
+ throw new JWEDecryptionFailed();
524
+ }
525
+ return plaintext;
526
+ }
527
+ async function gcmDecrypt(enc, cek, ciphertext, iv, tag2, aad) {
528
+ let encKey;
529
+ if (cek instanceof Uint8Array) {
530
+ encKey = await webcrypto_default.subtle.importKey("raw", cek, "AES-GCM", false, ["decrypt"]);
531
+ } else {
532
+ checkEncCryptoKey(cek, enc, "decrypt");
533
+ encKey = cek;
534
+ }
535
+ try {
536
+ return new Uint8Array(await webcrypto_default.subtle.decrypt({
537
+ additionalData: aad,
538
+ iv,
539
+ name: "AES-GCM",
540
+ tagLength: 128
541
+ }, encKey, concat(ciphertext, tag2)));
542
+ } catch {
543
+ throw new JWEDecryptionFailed();
544
+ }
545
+ }
546
+ var decrypt = async (enc, cek, ciphertext, iv, tag2, aad) => {
547
+ if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) {
548
+ throw new TypeError(invalid_key_input_default(cek, ...types, "Uint8Array"));
549
+ }
550
+ if (!iv) {
551
+ throw new JWEInvalid("JWE Initialization Vector missing");
552
+ }
553
+ if (!tag2) {
554
+ throw new JWEInvalid("JWE Authentication Tag missing");
555
+ }
556
+ check_iv_length_default(enc, iv);
557
+ switch (enc) {
558
+ case "A128CBC-HS256":
559
+ case "A192CBC-HS384":
560
+ case "A256CBC-HS512":
561
+ if (cek instanceof Uint8Array)
562
+ check_cek_length_default(cek, parseInt(enc.slice(-3), 10));
563
+ return cbcDecrypt(enc, cek, ciphertext, iv, tag2, aad);
564
+ case "A128GCM":
565
+ case "A192GCM":
566
+ case "A256GCM":
567
+ if (cek instanceof Uint8Array)
568
+ check_cek_length_default(cek, parseInt(enc.slice(1, 4), 10));
569
+ return gcmDecrypt(enc, cek, ciphertext, iv, tag2, aad);
570
+ default:
571
+ throw new JOSENotSupported("Unsupported JWE Content Encryption Algorithm");
572
+ }
573
+ };
574
+ var decrypt_default = decrypt;
575
+
576
+ // node_modules/jose/dist/browser/lib/is_disjoint.js
577
+ var isDisjoint = (...headers) => {
578
+ const sources = headers.filter(Boolean);
579
+ if (sources.length === 0 || sources.length === 1) {
580
+ return true;
581
+ }
582
+ let acc;
583
+ for (const header of sources) {
584
+ const parameters = Object.keys(header);
585
+ if (!acc || acc.size === 0) {
586
+ acc = new Set(parameters);
587
+ continue;
588
+ }
589
+ for (const parameter of parameters) {
590
+ if (acc.has(parameter)) {
591
+ return false;
592
+ }
593
+ acc.add(parameter);
594
+ }
595
+ }
596
+ return true;
597
+ };
598
+ var is_disjoint_default = isDisjoint;
599
+
600
+ // node_modules/jose/dist/browser/lib/is_object.js
601
+ function isObjectLike(value) {
602
+ return typeof value === "object" && value !== null;
603
+ }
604
+ function isObject(input) {
605
+ if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") {
606
+ return false;
607
+ }
608
+ if (Object.getPrototypeOf(input) === null) {
609
+ return true;
610
+ }
611
+ let proto = input;
612
+ while (Object.getPrototypeOf(proto) !== null) {
613
+ proto = Object.getPrototypeOf(proto);
614
+ }
615
+ return Object.getPrototypeOf(input) === proto;
616
+ }
617
+
618
+ // node_modules/jose/dist/browser/runtime/bogus.js
619
+ var bogusWebCrypto = [
620
+ { hash: "SHA-256", name: "HMAC" },
621
+ true,
622
+ ["sign"]
623
+ ];
624
+ var bogus_default = bogusWebCrypto;
625
+
626
+ // node_modules/jose/dist/browser/runtime/aeskw.js
627
+ function checkKeySize(key, alg) {
628
+ if (key.algorithm.length !== parseInt(alg.slice(1, 4), 10)) {
629
+ throw new TypeError(`Invalid key size for alg: ${alg}`);
630
+ }
631
+ }
632
+ function getCryptoKey(key, alg, usage) {
633
+ if (isCryptoKey(key)) {
634
+ checkEncCryptoKey(key, alg, usage);
635
+ return key;
636
+ }
637
+ if (key instanceof Uint8Array) {
638
+ return webcrypto_default.subtle.importKey("raw", key, "AES-KW", true, [usage]);
639
+ }
640
+ throw new TypeError(invalid_key_input_default(key, ...types, "Uint8Array"));
641
+ }
642
+ var wrap = async (alg, key, cek) => {
643
+ const cryptoKey = await getCryptoKey(key, alg, "wrapKey");
644
+ checkKeySize(cryptoKey, alg);
645
+ const cryptoKeyCek = await webcrypto_default.subtle.importKey("raw", cek, ...bogus_default);
646
+ return new Uint8Array(await webcrypto_default.subtle.wrapKey("raw", cryptoKeyCek, cryptoKey, "AES-KW"));
647
+ };
648
+ var unwrap = async (alg, key, encryptedKey) => {
649
+ const cryptoKey = await getCryptoKey(key, alg, "unwrapKey");
650
+ checkKeySize(cryptoKey, alg);
651
+ const cryptoKeyCek = await webcrypto_default.subtle.unwrapKey("raw", encryptedKey, cryptoKey, "AES-KW", ...bogus_default);
652
+ return new Uint8Array(await webcrypto_default.subtle.exportKey("raw", cryptoKeyCek));
653
+ };
654
+
655
+ // node_modules/jose/dist/browser/runtime/ecdhes.js
656
+ async function deriveKey(publicKey, privateKey, algorithm, keyLength, apu = new Uint8Array(0), apv = new Uint8Array(0)) {
657
+ if (!isCryptoKey(publicKey)) {
658
+ throw new TypeError(invalid_key_input_default(publicKey, ...types));
659
+ }
660
+ checkEncCryptoKey(publicKey, "ECDH");
661
+ if (!isCryptoKey(privateKey)) {
662
+ throw new TypeError(invalid_key_input_default(privateKey, ...types));
663
+ }
664
+ checkEncCryptoKey(privateKey, "ECDH", "deriveBits");
665
+ const value = concat(lengthAndInput(encoder.encode(algorithm)), lengthAndInput(apu), lengthAndInput(apv), uint32be(keyLength));
666
+ let length;
667
+ if (publicKey.algorithm.name === "X25519") {
668
+ length = 256;
669
+ } else if (publicKey.algorithm.name === "X448") {
670
+ length = 448;
671
+ } else {
672
+ length = Math.ceil(parseInt(publicKey.algorithm.namedCurve.substr(-3), 10) / 8) << 3;
673
+ }
674
+ const sharedSecret = new Uint8Array(await webcrypto_default.subtle.deriveBits({
675
+ name: publicKey.algorithm.name,
676
+ public: publicKey
677
+ }, privateKey, length));
678
+ return concatKdf(sharedSecret, keyLength, value);
679
+ }
680
+ async function generateEpk(key) {
681
+ if (!isCryptoKey(key)) {
682
+ throw new TypeError(invalid_key_input_default(key, ...types));
683
+ }
684
+ return webcrypto_default.subtle.generateKey(key.algorithm, true, ["deriveBits"]);
685
+ }
686
+ function ecdhAllowed(key) {
687
+ if (!isCryptoKey(key)) {
688
+ throw new TypeError(invalid_key_input_default(key, ...types));
689
+ }
690
+ return ["P-256", "P-384", "P-521"].includes(key.algorithm.namedCurve) || key.algorithm.name === "X25519" || key.algorithm.name === "X448";
691
+ }
692
+
693
+ // node_modules/jose/dist/browser/lib/check_p2s.js
694
+ function checkP2s(p2s2) {
695
+ if (!(p2s2 instanceof Uint8Array) || p2s2.length < 8) {
696
+ throw new JWEInvalid("PBES2 Salt Input must be 8 or more octets");
697
+ }
698
+ }
699
+
700
+ // node_modules/jose/dist/browser/runtime/pbes2kw.js
701
+ function getCryptoKey2(key, alg) {
702
+ if (key instanceof Uint8Array) {
703
+ return webcrypto_default.subtle.importKey("raw", key, "PBKDF2", false, ["deriveBits"]);
704
+ }
705
+ if (isCryptoKey(key)) {
706
+ checkEncCryptoKey(key, alg, "deriveBits", "deriveKey");
707
+ return key;
708
+ }
709
+ throw new TypeError(invalid_key_input_default(key, ...types, "Uint8Array"));
710
+ }
711
+ async function deriveKey2(p2s2, alg, p2c, key) {
712
+ checkP2s(p2s2);
713
+ const salt = p2s(alg, p2s2);
714
+ const keylen = parseInt(alg.slice(13, 16), 10);
715
+ const subtleAlg = {
716
+ hash: `SHA-${alg.slice(8, 11)}`,
717
+ iterations: p2c,
718
+ name: "PBKDF2",
719
+ salt
720
+ };
721
+ const wrapAlg = {
722
+ length: keylen,
723
+ name: "AES-KW"
724
+ };
725
+ const cryptoKey = await getCryptoKey2(key, alg);
726
+ if (cryptoKey.usages.includes("deriveBits")) {
727
+ return new Uint8Array(await webcrypto_default.subtle.deriveBits(subtleAlg, cryptoKey, keylen));
728
+ }
729
+ if (cryptoKey.usages.includes("deriveKey")) {
730
+ return webcrypto_default.subtle.deriveKey(subtleAlg, cryptoKey, wrapAlg, false, ["wrapKey", "unwrapKey"]);
731
+ }
732
+ throw new TypeError('PBKDF2 key "usages" must include "deriveBits" or "deriveKey"');
733
+ }
734
+ var encrypt = async (alg, key, cek, p2c = 2048, p2s2 = random_default(new Uint8Array(16))) => {
735
+ const derived = await deriveKey2(p2s2, alg, p2c, key);
736
+ const encryptedKey = await wrap(alg.slice(-6), derived, cek);
737
+ return { encryptedKey, p2c, p2s: encode(p2s2) };
738
+ };
739
+ var decrypt2 = async (alg, key, encryptedKey, p2c, p2s2) => {
740
+ const derived = await deriveKey2(p2s2, alg, p2c, key);
741
+ return unwrap(alg.slice(-6), derived, encryptedKey);
742
+ };
743
+
744
+ // node_modules/jose/dist/browser/runtime/subtle_rsaes.js
745
+ function subtleRsaEs(alg) {
746
+ switch (alg) {
747
+ case "RSA-OAEP":
748
+ case "RSA-OAEP-256":
749
+ case "RSA-OAEP-384":
750
+ case "RSA-OAEP-512":
751
+ return "RSA-OAEP";
752
+ default:
753
+ throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
754
+ }
755
+ }
756
+
757
+ // node_modules/jose/dist/browser/runtime/check_key_length.js
758
+ var check_key_length_default = (alg, key) => {
759
+ if (alg.startsWith("RS") || alg.startsWith("PS")) {
760
+ const { modulusLength } = key.algorithm;
761
+ if (typeof modulusLength !== "number" || modulusLength < 2048) {
762
+ throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
763
+ }
764
+ }
765
+ };
766
+
767
+ // node_modules/jose/dist/browser/runtime/rsaes.js
768
+ var encrypt2 = async (alg, key, cek) => {
769
+ if (!isCryptoKey(key)) {
770
+ throw new TypeError(invalid_key_input_default(key, ...types));
771
+ }
772
+ checkEncCryptoKey(key, alg, "encrypt", "wrapKey");
773
+ check_key_length_default(alg, key);
774
+ if (key.usages.includes("encrypt")) {
775
+ return new Uint8Array(await webcrypto_default.subtle.encrypt(subtleRsaEs(alg), key, cek));
776
+ }
777
+ if (key.usages.includes("wrapKey")) {
778
+ const cryptoKeyCek = await webcrypto_default.subtle.importKey("raw", cek, ...bogus_default);
779
+ return new Uint8Array(await webcrypto_default.subtle.wrapKey("raw", cryptoKeyCek, key, subtleRsaEs(alg)));
780
+ }
781
+ throw new TypeError('RSA-OAEP key "usages" must include "encrypt" or "wrapKey" for this operation');
782
+ };
783
+ var decrypt3 = async (alg, key, encryptedKey) => {
784
+ if (!isCryptoKey(key)) {
785
+ throw new TypeError(invalid_key_input_default(key, ...types));
786
+ }
787
+ checkEncCryptoKey(key, alg, "decrypt", "unwrapKey");
788
+ check_key_length_default(alg, key);
789
+ if (key.usages.includes("decrypt")) {
790
+ return new Uint8Array(await webcrypto_default.subtle.decrypt(subtleRsaEs(alg), key, encryptedKey));
791
+ }
792
+ if (key.usages.includes("unwrapKey")) {
793
+ const cryptoKeyCek = await webcrypto_default.subtle.unwrapKey("raw", encryptedKey, key, subtleRsaEs(alg), ...bogus_default);
794
+ return new Uint8Array(await webcrypto_default.subtle.exportKey("raw", cryptoKeyCek));
795
+ }
796
+ throw new TypeError('RSA-OAEP key "usages" must include "decrypt" or "unwrapKey" for this operation');
797
+ };
798
+
799
+ // node_modules/jose/dist/browser/lib/is_jwk.js
800
+ function isJWK(key) {
801
+ return isObject(key) && typeof key.kty === "string";
802
+ }
803
+ function isPrivateJWK(key) {
804
+ return key.kty !== "oct" && typeof key.d === "string";
805
+ }
806
+ function isPublicJWK(key) {
807
+ return key.kty !== "oct" && typeof key.d === "undefined";
808
+ }
809
+ function isSecretJWK(key) {
810
+ return isJWK(key) && key.kty === "oct" && typeof key.k === "string";
811
+ }
812
+
813
+ // node_modules/jose/dist/browser/runtime/jwk_to_key.js
814
+ function subtleMapping(jwk) {
815
+ let algorithm;
816
+ let keyUsages;
817
+ switch (jwk.kty) {
818
+ case "RSA": {
819
+ switch (jwk.alg) {
820
+ case "PS256":
821
+ case "PS384":
822
+ case "PS512":
823
+ algorithm = { name: "RSA-PSS", hash: `SHA-${jwk.alg.slice(-3)}` };
824
+ keyUsages = jwk.d ? ["sign"] : ["verify"];
825
+ break;
826
+ case "RS256":
827
+ case "RS384":
828
+ case "RS512":
829
+ algorithm = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${jwk.alg.slice(-3)}` };
830
+ keyUsages = jwk.d ? ["sign"] : ["verify"];
831
+ break;
832
+ case "RSA-OAEP":
833
+ case "RSA-OAEP-256":
834
+ case "RSA-OAEP-384":
835
+ case "RSA-OAEP-512":
836
+ algorithm = {
837
+ name: "RSA-OAEP",
838
+ hash: `SHA-${parseInt(jwk.alg.slice(-3), 10) || 1}`
839
+ };
840
+ keyUsages = jwk.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
841
+ break;
842
+ default:
843
+ throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
844
+ }
845
+ break;
846
+ }
847
+ case "EC": {
848
+ switch (jwk.alg) {
849
+ case "ES256":
850
+ algorithm = { name: "ECDSA", namedCurve: "P-256" };
851
+ keyUsages = jwk.d ? ["sign"] : ["verify"];
852
+ break;
853
+ case "ES384":
854
+ algorithm = { name: "ECDSA", namedCurve: "P-384" };
855
+ keyUsages = jwk.d ? ["sign"] : ["verify"];
856
+ break;
857
+ case "ES512":
858
+ algorithm = { name: "ECDSA", namedCurve: "P-521" };
859
+ keyUsages = jwk.d ? ["sign"] : ["verify"];
860
+ break;
861
+ case "ECDH-ES":
862
+ case "ECDH-ES+A128KW":
863
+ case "ECDH-ES+A192KW":
864
+ case "ECDH-ES+A256KW":
865
+ algorithm = { name: "ECDH", namedCurve: jwk.crv };
866
+ keyUsages = jwk.d ? ["deriveBits"] : [];
867
+ break;
868
+ default:
869
+ throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
870
+ }
871
+ break;
872
+ }
873
+ case "OKP": {
874
+ switch (jwk.alg) {
875
+ case "Ed25519":
876
+ algorithm = { name: "Ed25519" };
877
+ keyUsages = jwk.d ? ["sign"] : ["verify"];
878
+ break;
879
+ case "EdDSA":
880
+ algorithm = { name: jwk.crv };
881
+ keyUsages = jwk.d ? ["sign"] : ["verify"];
882
+ break;
883
+ case "ECDH-ES":
884
+ case "ECDH-ES+A128KW":
885
+ case "ECDH-ES+A192KW":
886
+ case "ECDH-ES+A256KW":
887
+ algorithm = { name: jwk.crv };
888
+ keyUsages = jwk.d ? ["deriveBits"] : [];
889
+ break;
890
+ default:
891
+ throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
892
+ }
893
+ break;
894
+ }
895
+ default:
896
+ throw new JOSENotSupported('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
897
+ }
898
+ return { algorithm, keyUsages };
899
+ }
900
+ var parse = async (jwk) => {
901
+ if (!jwk.alg) {
902
+ throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
903
+ }
904
+ const { algorithm, keyUsages } = subtleMapping(jwk);
905
+ const rest = [
906
+ algorithm,
907
+ jwk.ext ?? false,
908
+ jwk.key_ops ?? keyUsages
909
+ ];
910
+ const keyData = { ...jwk };
911
+ delete keyData.alg;
912
+ delete keyData.use;
913
+ return webcrypto_default.subtle.importKey("jwk", keyData, ...rest);
914
+ };
915
+ var jwk_to_key_default = parse;
916
+
917
+ // node_modules/jose/dist/browser/runtime/normalize_key.js
918
+ var exportKeyValue = (k) => decode(k);
919
+ var privCache;
920
+ var pubCache;
921
+ var isKeyObject = (key) => {
922
+ return key?.[Symbol.toStringTag] === "KeyObject";
923
+ };
924
+ var importAndCache = async (cache, key, jwk, alg, freeze = false) => {
925
+ let cached = cache.get(key);
926
+ if (cached?.[alg]) {
927
+ return cached[alg];
928
+ }
929
+ const cryptoKey = await jwk_to_key_default({ ...jwk, alg });
930
+ if (freeze)
931
+ Object.freeze(key);
932
+ if (!cached) {
933
+ cache.set(key, { [alg]: cryptoKey });
934
+ } else {
935
+ cached[alg] = cryptoKey;
936
+ }
937
+ return cryptoKey;
938
+ };
939
+ var normalizePublicKey = (key, alg) => {
940
+ if (isKeyObject(key)) {
941
+ let jwk = key.export({ format: "jwk" });
942
+ delete jwk.d;
943
+ delete jwk.dp;
944
+ delete jwk.dq;
945
+ delete jwk.p;
946
+ delete jwk.q;
947
+ delete jwk.qi;
948
+ if (jwk.k) {
949
+ return exportKeyValue(jwk.k);
950
+ }
951
+ pubCache || (pubCache = /* @__PURE__ */ new WeakMap());
952
+ return importAndCache(pubCache, key, jwk, alg);
953
+ }
954
+ if (isJWK(key)) {
955
+ if (key.k)
956
+ return decode(key.k);
957
+ pubCache || (pubCache = /* @__PURE__ */ new WeakMap());
958
+ const cryptoKey = importAndCache(pubCache, key, key, alg, true);
959
+ return cryptoKey;
960
+ }
961
+ return key;
962
+ };
963
+ var normalizePrivateKey = (key, alg) => {
964
+ if (isKeyObject(key)) {
965
+ let jwk = key.export({ format: "jwk" });
966
+ if (jwk.k) {
967
+ return exportKeyValue(jwk.k);
968
+ }
969
+ privCache || (privCache = /* @__PURE__ */ new WeakMap());
970
+ return importAndCache(privCache, key, jwk, alg);
971
+ }
972
+ if (isJWK(key)) {
973
+ if (key.k)
974
+ return decode(key.k);
975
+ privCache || (privCache = /* @__PURE__ */ new WeakMap());
976
+ const cryptoKey = importAndCache(privCache, key, key, alg, true);
977
+ return cryptoKey;
978
+ }
979
+ return key;
980
+ };
981
+ var normalize_key_default = { normalizePublicKey, normalizePrivateKey };
982
+
983
+ // node_modules/jose/dist/browser/lib/cek.js
984
+ function bitLength2(alg) {
985
+ switch (alg) {
986
+ case "A128GCM":
987
+ return 128;
988
+ case "A192GCM":
989
+ return 192;
990
+ case "A256GCM":
991
+ case "A128CBC-HS256":
992
+ return 256;
993
+ case "A192CBC-HS384":
994
+ return 384;
995
+ case "A256CBC-HS512":
996
+ return 512;
997
+ default:
998
+ throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
999
+ }
1000
+ }
1001
+ var cek_default = (alg) => random_default(new Uint8Array(bitLength2(alg) >> 3));
1002
+
1003
+ // node_modules/jose/dist/browser/lib/format_pem.js
1004
+ var format_pem_default = (b64, descriptor) => {
1005
+ const newlined = (b64.match(/.{1,64}/g) || []).join("\n");
1006
+ return `-----BEGIN ${descriptor}-----
1007
+ ${newlined}
1008
+ -----END ${descriptor}-----`;
1009
+ };
1010
+
1011
+ // node_modules/jose/dist/browser/runtime/asn1.js
1012
+ var genericExport = async (keyType, keyFormat, key) => {
1013
+ if (!isCryptoKey(key)) {
1014
+ throw new TypeError(invalid_key_input_default(key, ...types));
1015
+ }
1016
+ if (!key.extractable) {
1017
+ throw new TypeError("CryptoKey is not extractable");
1018
+ }
1019
+ if (key.type !== keyType) {
1020
+ throw new TypeError(`key is not a ${keyType} key`);
1021
+ }
1022
+ return format_pem_default(encodeBase64(new Uint8Array(await webcrypto_default.subtle.exportKey(keyFormat, key))), `${keyType.toUpperCase()} KEY`);
1023
+ };
1024
+ var toSPKI = (key) => {
1025
+ return genericExport("public", "spki", key);
1026
+ };
1027
+ var toPKCS8 = (key) => {
1028
+ return genericExport("private", "pkcs8", key);
1029
+ };
1030
+ var findOid = (keyData, oid, from = 0) => {
1031
+ if (from === 0) {
1032
+ oid.unshift(oid.length);
1033
+ oid.unshift(6);
1034
+ }
1035
+ const i = keyData.indexOf(oid[0], from);
1036
+ if (i === -1)
1037
+ return false;
1038
+ const sub = keyData.subarray(i, i + oid.length);
1039
+ if (sub.length !== oid.length)
1040
+ return false;
1041
+ return sub.every((value, index) => value === oid[index]) || findOid(keyData, oid, i + 1);
1042
+ };
1043
+ var getNamedCurve2 = (keyData) => {
1044
+ switch (true) {
1045
+ case findOid(keyData, [42, 134, 72, 206, 61, 3, 1, 7]):
1046
+ return "P-256";
1047
+ case findOid(keyData, [43, 129, 4, 0, 34]):
1048
+ return "P-384";
1049
+ case findOid(keyData, [43, 129, 4, 0, 35]):
1050
+ return "P-521";
1051
+ case findOid(keyData, [43, 101, 110]):
1052
+ return "X25519";
1053
+ case findOid(keyData, [43, 101, 111]):
1054
+ return "X448";
1055
+ case findOid(keyData, [43, 101, 112]):
1056
+ return "Ed25519";
1057
+ case findOid(keyData, [43, 101, 113]):
1058
+ return "Ed448";
1059
+ default:
1060
+ throw new JOSENotSupported("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
1061
+ }
1062
+ };
1063
+ var genericImport = async (replace, keyFormat, pem, alg, options) => {
1064
+ let algorithm;
1065
+ let keyUsages;
1066
+ const keyData = new Uint8Array(atob(pem.replace(replace, "")).split("").map((c) => c.charCodeAt(0)));
1067
+ const isPublic = keyFormat === "spki";
1068
+ switch (alg) {
1069
+ case "PS256":
1070
+ case "PS384":
1071
+ case "PS512":
1072
+ algorithm = { name: "RSA-PSS", hash: `SHA-${alg.slice(-3)}` };
1073
+ keyUsages = isPublic ? ["verify"] : ["sign"];
1074
+ break;
1075
+ case "RS256":
1076
+ case "RS384":
1077
+ case "RS512":
1078
+ algorithm = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${alg.slice(-3)}` };
1079
+ keyUsages = isPublic ? ["verify"] : ["sign"];
1080
+ break;
1081
+ case "RSA-OAEP":
1082
+ case "RSA-OAEP-256":
1083
+ case "RSA-OAEP-384":
1084
+ case "RSA-OAEP-512":
1085
+ algorithm = {
1086
+ name: "RSA-OAEP",
1087
+ hash: `SHA-${parseInt(alg.slice(-3), 10) || 1}`
1088
+ };
1089
+ keyUsages = isPublic ? ["encrypt", "wrapKey"] : ["decrypt", "unwrapKey"];
1090
+ break;
1091
+ case "ES256":
1092
+ algorithm = { name: "ECDSA", namedCurve: "P-256" };
1093
+ keyUsages = isPublic ? ["verify"] : ["sign"];
1094
+ break;
1095
+ case "ES384":
1096
+ algorithm = { name: "ECDSA", namedCurve: "P-384" };
1097
+ keyUsages = isPublic ? ["verify"] : ["sign"];
1098
+ break;
1099
+ case "ES512":
1100
+ algorithm = { name: "ECDSA", namedCurve: "P-521" };
1101
+ keyUsages = isPublic ? ["verify"] : ["sign"];
1102
+ break;
1103
+ case "ECDH-ES":
1104
+ case "ECDH-ES+A128KW":
1105
+ case "ECDH-ES+A192KW":
1106
+ case "ECDH-ES+A256KW": {
1107
+ const namedCurve = getNamedCurve2(keyData);
1108
+ algorithm = namedCurve.startsWith("P-") ? { name: "ECDH", namedCurve } : { name: namedCurve };
1109
+ keyUsages = isPublic ? [] : ["deriveBits"];
1110
+ break;
1111
+ }
1112
+ case "Ed25519":
1113
+ algorithm = { name: "Ed25519" };
1114
+ keyUsages = isPublic ? ["verify"] : ["sign"];
1115
+ break;
1116
+ case "EdDSA":
1117
+ algorithm = { name: getNamedCurve2(keyData) };
1118
+ keyUsages = isPublic ? ["verify"] : ["sign"];
1119
+ break;
1120
+ default:
1121
+ throw new JOSENotSupported('Invalid or unsupported "alg" (Algorithm) value');
1122
+ }
1123
+ return webcrypto_default.subtle.importKey(keyFormat, keyData, algorithm, options?.extractable ?? false, keyUsages);
1124
+ };
1125
+ var fromPKCS8 = (pem, alg, options) => {
1126
+ return genericImport(/(?:-----(?:BEGIN|END) PRIVATE KEY-----|\s)/g, "pkcs8", pem, alg, options);
1127
+ };
1128
+ var fromSPKI = (pem, alg, options) => {
1129
+ return genericImport(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "spki", pem, alg, options);
1130
+ };
1131
+ function getElement(seq) {
1132
+ const result = [];
1133
+ let next = 0;
1134
+ while (next < seq.length) {
1135
+ const nextPart = parseElement(seq.subarray(next));
1136
+ result.push(nextPart);
1137
+ next += nextPart.byteLength;
1138
+ }
1139
+ return result;
1140
+ }
1141
+ function parseElement(bytes) {
1142
+ let position = 0;
1143
+ let tag2 = bytes[0] & 31;
1144
+ position++;
1145
+ if (tag2 === 31) {
1146
+ tag2 = 0;
1147
+ while (bytes[position] >= 128) {
1148
+ tag2 = tag2 * 128 + bytes[position] - 128;
1149
+ position++;
1150
+ }
1151
+ tag2 = tag2 * 128 + bytes[position] - 128;
1152
+ position++;
1153
+ }
1154
+ let length = 0;
1155
+ if (bytes[position] < 128) {
1156
+ length = bytes[position];
1157
+ position++;
1158
+ } else if (length === 128) {
1159
+ length = 0;
1160
+ while (bytes[position + length] !== 0 || bytes[position + length + 1] !== 0) {
1161
+ if (length > bytes.byteLength) {
1162
+ throw new TypeError("invalid indefinite form length");
1163
+ }
1164
+ length++;
1165
+ }
1166
+ const byteLength2 = position + length + 2;
1167
+ return {
1168
+ byteLength: byteLength2,
1169
+ contents: bytes.subarray(position, position + length),
1170
+ raw: bytes.subarray(0, byteLength2)
1171
+ };
1172
+ } else {
1173
+ const numberOfDigits = bytes[position] & 127;
1174
+ position++;
1175
+ length = 0;
1176
+ for (let i = 0; i < numberOfDigits; i++) {
1177
+ length = length * 256 + bytes[position];
1178
+ position++;
1179
+ }
1180
+ }
1181
+ const byteLength = position + length;
1182
+ return {
1183
+ byteLength,
1184
+ contents: bytes.subarray(position, byteLength),
1185
+ raw: bytes.subarray(0, byteLength)
1186
+ };
1187
+ }
1188
+ function spkiFromX509(buf) {
1189
+ const tbsCertificate = getElement(getElement(parseElement(buf).contents)[0].contents);
1190
+ return encodeBase64(tbsCertificate[tbsCertificate[0].raw[0] === 160 ? 6 : 5].raw);
1191
+ }
1192
+ function getSPKI(x509) {
1193
+ const pem = x509.replace(/(?:-----(?:BEGIN|END) CERTIFICATE-----|\s)/g, "");
1194
+ const raw = decodeBase64(pem);
1195
+ return format_pem_default(spkiFromX509(raw), "PUBLIC KEY");
1196
+ }
1197
+ var fromX509 = (pem, alg, options) => {
1198
+ let spki;
1199
+ try {
1200
+ spki = getSPKI(pem);
1201
+ } catch (cause) {
1202
+ throw new TypeError("Failed to parse the X.509 certificate", { cause });
1203
+ }
1204
+ return fromSPKI(spki, alg, options);
1205
+ };
1206
+
1207
+ // node_modules/jose/dist/browser/key/import.js
1208
+ async function importSPKI(spki, alg, options) {
1209
+ if (typeof spki !== "string" || spki.indexOf("-----BEGIN PUBLIC KEY-----") !== 0) {
1210
+ throw new TypeError('"spki" must be SPKI formatted string');
1211
+ }
1212
+ return fromSPKI(spki, alg, options);
1213
+ }
1214
+ async function importX509(x509, alg, options) {
1215
+ if (typeof x509 !== "string" || x509.indexOf("-----BEGIN CERTIFICATE-----") !== 0) {
1216
+ throw new TypeError('"x509" must be X.509 formatted string');
1217
+ }
1218
+ return fromX509(x509, alg, options);
1219
+ }
1220
+ async function importPKCS8(pkcs8, alg, options) {
1221
+ if (typeof pkcs8 !== "string" || pkcs8.indexOf("-----BEGIN PRIVATE KEY-----") !== 0) {
1222
+ throw new TypeError('"pkcs8" must be PKCS#8 formatted string');
1223
+ }
1224
+ return fromPKCS8(pkcs8, alg, options);
1225
+ }
1226
+ async function importJWK(jwk, alg) {
1227
+ if (!isObject(jwk)) {
1228
+ throw new TypeError("JWK must be an object");
1229
+ }
1230
+ alg || (alg = jwk.alg);
1231
+ switch (jwk.kty) {
1232
+ case "oct":
1233
+ if (typeof jwk.k !== "string" || !jwk.k) {
1234
+ throw new TypeError('missing "k" (Key Value) Parameter value');
1235
+ }
1236
+ return decode(jwk.k);
1237
+ case "RSA":
1238
+ if ("oth" in jwk && jwk.oth !== void 0) {
1239
+ throw new JOSENotSupported('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
1240
+ }
1241
+ case "EC":
1242
+ case "OKP":
1243
+ return jwk_to_key_default({ ...jwk, alg });
1244
+ default:
1245
+ throw new JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
1246
+ }
1247
+ }
1248
+
1249
+ // node_modules/jose/dist/browser/lib/check_key_type.js
1250
+ var tag = (key) => key?.[Symbol.toStringTag];
1251
+ var jwkMatchesOp = (alg, key, usage) => {
1252
+ if (key.use !== void 0 && key.use !== "sig") {
1253
+ throw new TypeError("Invalid key for this operation, when present its use must be sig");
1254
+ }
1255
+ if (key.key_ops !== void 0 && key.key_ops.includes?.(usage) !== true) {
1256
+ throw new TypeError(`Invalid key for this operation, when present its key_ops must include ${usage}`);
1257
+ }
1258
+ if (key.alg !== void 0 && key.alg !== alg) {
1259
+ throw new TypeError(`Invalid key for this operation, when present its alg must be ${alg}`);
1260
+ }
1261
+ return true;
1262
+ };
1263
+ var symmetricTypeCheck = (alg, key, usage, allowJwk) => {
1264
+ if (key instanceof Uint8Array)
1265
+ return;
1266
+ if (allowJwk && isJWK(key)) {
1267
+ if (isSecretJWK(key) && jwkMatchesOp(alg, key, usage))
1268
+ return;
1269
+ 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`);
1270
+ }
1271
+ if (!is_key_like_default(key)) {
1272
+ throw new TypeError(withAlg(alg, key, ...types, "Uint8Array", allowJwk ? "JSON Web Key" : null));
1273
+ }
1274
+ if (key.type !== "secret") {
1275
+ throw new TypeError(`${tag(key)} instances for symmetric algorithms must be of type "secret"`);
1276
+ }
1277
+ };
1278
+ var asymmetricTypeCheck = (alg, key, usage, allowJwk) => {
1279
+ if (allowJwk && isJWK(key)) {
1280
+ switch (usage) {
1281
+ case "sign":
1282
+ if (isPrivateJWK(key) && jwkMatchesOp(alg, key, usage))
1283
+ return;
1284
+ throw new TypeError(`JSON Web Key for this operation be a private JWK`);
1285
+ case "verify":
1286
+ if (isPublicJWK(key) && jwkMatchesOp(alg, key, usage))
1287
+ return;
1288
+ throw new TypeError(`JSON Web Key for this operation be a public JWK`);
1289
+ }
1290
+ }
1291
+ if (!is_key_like_default(key)) {
1292
+ throw new TypeError(withAlg(alg, key, ...types, allowJwk ? "JSON Web Key" : null));
1293
+ }
1294
+ if (key.type === "secret") {
1295
+ throw new TypeError(`${tag(key)} instances for asymmetric algorithms must not be of type "secret"`);
1296
+ }
1297
+ if (usage === "sign" && key.type === "public") {
1298
+ throw new TypeError(`${tag(key)} instances for asymmetric algorithm signing must be of type "private"`);
1299
+ }
1300
+ if (usage === "decrypt" && key.type === "public") {
1301
+ throw new TypeError(`${tag(key)} instances for asymmetric algorithm decryption must be of type "private"`);
1302
+ }
1303
+ if (key.algorithm && usage === "verify" && key.type === "private") {
1304
+ throw new TypeError(`${tag(key)} instances for asymmetric algorithm verifying must be of type "public"`);
1305
+ }
1306
+ if (key.algorithm && usage === "encrypt" && key.type === "private") {
1307
+ throw new TypeError(`${tag(key)} instances for asymmetric algorithm encryption must be of type "public"`);
1308
+ }
1309
+ };
1310
+ function checkKeyType(allowJwk, alg, key, usage) {
1311
+ const symmetric = alg.startsWith("HS") || alg === "dir" || alg.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(alg);
1312
+ if (symmetric) {
1313
+ symmetricTypeCheck(alg, key, usage, allowJwk);
1314
+ } else {
1315
+ asymmetricTypeCheck(alg, key, usage, allowJwk);
1316
+ }
1317
+ }
1318
+ var check_key_type_default = checkKeyType.bind(void 0, false);
1319
+ var checkKeyTypeWithJwk = checkKeyType.bind(void 0, true);
1320
+
1321
+ // node_modules/jose/dist/browser/runtime/encrypt.js
1322
+ async function cbcEncrypt(enc, plaintext, cek, iv, aad) {
1323
+ if (!(cek instanceof Uint8Array)) {
1324
+ throw new TypeError(invalid_key_input_default(cek, "Uint8Array"));
1325
+ }
1326
+ const keySize = parseInt(enc.slice(1, 4), 10);
1327
+ const encKey = await webcrypto_default.subtle.importKey("raw", cek.subarray(keySize >> 3), "AES-CBC", false, ["encrypt"]);
1328
+ const macKey = await webcrypto_default.subtle.importKey("raw", cek.subarray(0, keySize >> 3), {
1329
+ hash: `SHA-${keySize << 1}`,
1330
+ name: "HMAC"
1331
+ }, false, ["sign"]);
1332
+ const ciphertext = new Uint8Array(await webcrypto_default.subtle.encrypt({
1333
+ iv,
1334
+ name: "AES-CBC"
1335
+ }, encKey, plaintext));
1336
+ const macData = concat(aad, iv, ciphertext, uint64be(aad.length << 3));
1337
+ const tag2 = new Uint8Array((await webcrypto_default.subtle.sign("HMAC", macKey, macData)).slice(0, keySize >> 3));
1338
+ return { ciphertext, tag: tag2, iv };
1339
+ }
1340
+ async function gcmEncrypt(enc, plaintext, cek, iv, aad) {
1341
+ let encKey;
1342
+ if (cek instanceof Uint8Array) {
1343
+ encKey = await webcrypto_default.subtle.importKey("raw", cek, "AES-GCM", false, ["encrypt"]);
1344
+ } else {
1345
+ checkEncCryptoKey(cek, enc, "encrypt");
1346
+ encKey = cek;
1347
+ }
1348
+ const encrypted = new Uint8Array(await webcrypto_default.subtle.encrypt({
1349
+ additionalData: aad,
1350
+ iv,
1351
+ name: "AES-GCM",
1352
+ tagLength: 128
1353
+ }, encKey, plaintext));
1354
+ const tag2 = encrypted.slice(-16);
1355
+ const ciphertext = encrypted.slice(0, -16);
1356
+ return { ciphertext, tag: tag2, iv };
1357
+ }
1358
+ var encrypt3 = async (enc, plaintext, cek, iv, aad) => {
1359
+ if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) {
1360
+ throw new TypeError(invalid_key_input_default(cek, ...types, "Uint8Array"));
1361
+ }
1362
+ if (iv) {
1363
+ check_iv_length_default(enc, iv);
1364
+ } else {
1365
+ iv = iv_default(enc);
1366
+ }
1367
+ switch (enc) {
1368
+ case "A128CBC-HS256":
1369
+ case "A192CBC-HS384":
1370
+ case "A256CBC-HS512":
1371
+ if (cek instanceof Uint8Array) {
1372
+ check_cek_length_default(cek, parseInt(enc.slice(-3), 10));
1373
+ }
1374
+ return cbcEncrypt(enc, plaintext, cek, iv, aad);
1375
+ case "A128GCM":
1376
+ case "A192GCM":
1377
+ case "A256GCM":
1378
+ if (cek instanceof Uint8Array) {
1379
+ check_cek_length_default(cek, parseInt(enc.slice(1, 4), 10));
1380
+ }
1381
+ return gcmEncrypt(enc, plaintext, cek, iv, aad);
1382
+ default:
1383
+ throw new JOSENotSupported("Unsupported JWE Content Encryption Algorithm");
1384
+ }
1385
+ };
1386
+ var encrypt_default = encrypt3;
1387
+
1388
+ // node_modules/jose/dist/browser/lib/aesgcmkw.js
1389
+ async function wrap2(alg, key, cek, iv) {
1390
+ const jweAlgorithm = alg.slice(0, 7);
1391
+ const wrapped = await encrypt_default(jweAlgorithm, cek, key, iv, new Uint8Array(0));
1392
+ return {
1393
+ encryptedKey: wrapped.ciphertext,
1394
+ iv: encode(wrapped.iv),
1395
+ tag: encode(wrapped.tag)
1396
+ };
1397
+ }
1398
+ async function unwrap2(alg, key, encryptedKey, iv, tag2) {
1399
+ const jweAlgorithm = alg.slice(0, 7);
1400
+ return decrypt_default(jweAlgorithm, key, encryptedKey, iv, tag2, new Uint8Array(0));
1401
+ }
1402
+
1403
+ // node_modules/jose/dist/browser/lib/decrypt_key_management.js
1404
+ async function decryptKeyManagement(alg, key, encryptedKey, joseHeader, options) {
1405
+ check_key_type_default(alg, key, "decrypt");
1406
+ key = await normalize_key_default.normalizePrivateKey?.(key, alg) || key;
1407
+ switch (alg) {
1408
+ case "dir": {
1409
+ if (encryptedKey !== void 0)
1410
+ throw new JWEInvalid("Encountered unexpected JWE Encrypted Key");
1411
+ return key;
1412
+ }
1413
+ case "ECDH-ES":
1414
+ if (encryptedKey !== void 0)
1415
+ throw new JWEInvalid("Encountered unexpected JWE Encrypted Key");
1416
+ case "ECDH-ES+A128KW":
1417
+ case "ECDH-ES+A192KW":
1418
+ case "ECDH-ES+A256KW": {
1419
+ if (!isObject(joseHeader.epk))
1420
+ throw new JWEInvalid(`JOSE Header "epk" (Ephemeral Public Key) missing or invalid`);
1421
+ if (!ecdhAllowed(key))
1422
+ throw new JOSENotSupported("ECDH with the provided key is not allowed or not supported by your javascript runtime");
1423
+ const epk = await importJWK(joseHeader.epk, alg);
1424
+ let partyUInfo;
1425
+ let partyVInfo;
1426
+ if (joseHeader.apu !== void 0) {
1427
+ if (typeof joseHeader.apu !== "string")
1428
+ throw new JWEInvalid(`JOSE Header "apu" (Agreement PartyUInfo) invalid`);
1429
+ try {
1430
+ partyUInfo = decode(joseHeader.apu);
1431
+ } catch {
1432
+ throw new JWEInvalid("Failed to base64url decode the apu");
1433
+ }
1434
+ }
1435
+ if (joseHeader.apv !== void 0) {
1436
+ if (typeof joseHeader.apv !== "string")
1437
+ throw new JWEInvalid(`JOSE Header "apv" (Agreement PartyVInfo) invalid`);
1438
+ try {
1439
+ partyVInfo = decode(joseHeader.apv);
1440
+ } catch {
1441
+ throw new JWEInvalid("Failed to base64url decode the apv");
1442
+ }
1443
+ }
1444
+ const sharedSecret = await deriveKey(epk, key, alg === "ECDH-ES" ? joseHeader.enc : alg, alg === "ECDH-ES" ? bitLength2(joseHeader.enc) : parseInt(alg.slice(-5, -2), 10), partyUInfo, partyVInfo);
1445
+ if (alg === "ECDH-ES")
1446
+ return sharedSecret;
1447
+ if (encryptedKey === void 0)
1448
+ throw new JWEInvalid("JWE Encrypted Key missing");
1449
+ return unwrap(alg.slice(-6), sharedSecret, encryptedKey);
1450
+ }
1451
+ case "RSA1_5":
1452
+ case "RSA-OAEP":
1453
+ case "RSA-OAEP-256":
1454
+ case "RSA-OAEP-384":
1455
+ case "RSA-OAEP-512": {
1456
+ if (encryptedKey === void 0)
1457
+ throw new JWEInvalid("JWE Encrypted Key missing");
1458
+ return decrypt3(alg, key, encryptedKey);
1459
+ }
1460
+ case "PBES2-HS256+A128KW":
1461
+ case "PBES2-HS384+A192KW":
1462
+ case "PBES2-HS512+A256KW": {
1463
+ if (encryptedKey === void 0)
1464
+ throw new JWEInvalid("JWE Encrypted Key missing");
1465
+ if (typeof joseHeader.p2c !== "number")
1466
+ throw new JWEInvalid(`JOSE Header "p2c" (PBES2 Count) missing or invalid`);
1467
+ const p2cLimit = options?.maxPBES2Count || 1e4;
1468
+ if (joseHeader.p2c > p2cLimit)
1469
+ throw new JWEInvalid(`JOSE Header "p2c" (PBES2 Count) out is of acceptable bounds`);
1470
+ if (typeof joseHeader.p2s !== "string")
1471
+ throw new JWEInvalid(`JOSE Header "p2s" (PBES2 Salt) missing or invalid`);
1472
+ let p2s2;
1473
+ try {
1474
+ p2s2 = decode(joseHeader.p2s);
1475
+ } catch {
1476
+ throw new JWEInvalid("Failed to base64url decode the p2s");
1477
+ }
1478
+ return decrypt2(alg, key, encryptedKey, joseHeader.p2c, p2s2);
1479
+ }
1480
+ case "A128KW":
1481
+ case "A192KW":
1482
+ case "A256KW": {
1483
+ if (encryptedKey === void 0)
1484
+ throw new JWEInvalid("JWE Encrypted Key missing");
1485
+ return unwrap(alg, key, encryptedKey);
1486
+ }
1487
+ case "A128GCMKW":
1488
+ case "A192GCMKW":
1489
+ case "A256GCMKW": {
1490
+ if (encryptedKey === void 0)
1491
+ throw new JWEInvalid("JWE Encrypted Key missing");
1492
+ if (typeof joseHeader.iv !== "string")
1493
+ throw new JWEInvalid(`JOSE Header "iv" (Initialization Vector) missing or invalid`);
1494
+ if (typeof joseHeader.tag !== "string")
1495
+ throw new JWEInvalid(`JOSE Header "tag" (Authentication Tag) missing or invalid`);
1496
+ let iv;
1497
+ try {
1498
+ iv = decode(joseHeader.iv);
1499
+ } catch {
1500
+ throw new JWEInvalid("Failed to base64url decode the iv");
1501
+ }
1502
+ let tag2;
1503
+ try {
1504
+ tag2 = decode(joseHeader.tag);
1505
+ } catch {
1506
+ throw new JWEInvalid("Failed to base64url decode the tag");
1507
+ }
1508
+ return unwrap2(alg, key, encryptedKey, iv, tag2);
1509
+ }
1510
+ default: {
1511
+ throw new JOSENotSupported('Invalid or unsupported "alg" (JWE Algorithm) header value');
1512
+ }
1513
+ }
1514
+ }
1515
+ var decrypt_key_management_default = decryptKeyManagement;
1516
+
1517
+ // node_modules/jose/dist/browser/lib/validate_crit.js
1518
+ function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
1519
+ if (joseHeader.crit !== void 0 && protectedHeader?.crit === void 0) {
1520
+ throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
1521
+ }
1522
+ if (!protectedHeader || protectedHeader.crit === void 0) {
1523
+ return /* @__PURE__ */ new Set();
1524
+ }
1525
+ if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input !== "string" || input.length === 0)) {
1526
+ throw new Err('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
1527
+ }
1528
+ let recognized;
1529
+ if (recognizedOption !== void 0) {
1530
+ recognized = new Map([...Object.entries(recognizedOption), ...recognizedDefault.entries()]);
1531
+ } else {
1532
+ recognized = recognizedDefault;
1533
+ }
1534
+ for (const parameter of protectedHeader.crit) {
1535
+ if (!recognized.has(parameter)) {
1536
+ throw new JOSENotSupported(`Extension Header Parameter "${parameter}" is not recognized`);
1537
+ }
1538
+ if (joseHeader[parameter] === void 0) {
1539
+ throw new Err(`Extension Header Parameter "${parameter}" is missing`);
1540
+ }
1541
+ if (recognized.get(parameter) && protectedHeader[parameter] === void 0) {
1542
+ throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
1543
+ }
1544
+ }
1545
+ return new Set(protectedHeader.crit);
1546
+ }
1547
+ var validate_crit_default = validateCrit;
1548
+
1549
+ // node_modules/jose/dist/browser/lib/validate_algorithms.js
1550
+ var validateAlgorithms = (option, algorithms) => {
1551
+ if (algorithms !== void 0 && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) {
1552
+ throw new TypeError(`"${option}" option must be an array of strings`);
1553
+ }
1554
+ if (!algorithms) {
1555
+ return void 0;
1556
+ }
1557
+ return new Set(algorithms);
1558
+ };
1559
+ var validate_algorithms_default = validateAlgorithms;
1560
+
1561
+ // node_modules/jose/dist/browser/jwe/flattened/decrypt.js
1562
+ async function flattenedDecrypt(jwe, key, options) {
1563
+ if (!isObject(jwe)) {
1564
+ throw new JWEInvalid("Flattened JWE must be an object");
1565
+ }
1566
+ if (jwe.protected === void 0 && jwe.header === void 0 && jwe.unprotected === void 0) {
1567
+ throw new JWEInvalid("JOSE Header missing");
1568
+ }
1569
+ if (jwe.iv !== void 0 && typeof jwe.iv !== "string") {
1570
+ throw new JWEInvalid("JWE Initialization Vector incorrect type");
1571
+ }
1572
+ if (typeof jwe.ciphertext !== "string") {
1573
+ throw new JWEInvalid("JWE Ciphertext missing or incorrect type");
1574
+ }
1575
+ if (jwe.tag !== void 0 && typeof jwe.tag !== "string") {
1576
+ throw new JWEInvalid("JWE Authentication Tag incorrect type");
1577
+ }
1578
+ if (jwe.protected !== void 0 && typeof jwe.protected !== "string") {
1579
+ throw new JWEInvalid("JWE Protected Header incorrect type");
1580
+ }
1581
+ if (jwe.encrypted_key !== void 0 && typeof jwe.encrypted_key !== "string") {
1582
+ throw new JWEInvalid("JWE Encrypted Key incorrect type");
1583
+ }
1584
+ if (jwe.aad !== void 0 && typeof jwe.aad !== "string") {
1585
+ throw new JWEInvalid("JWE AAD incorrect type");
1586
+ }
1587
+ if (jwe.header !== void 0 && !isObject(jwe.header)) {
1588
+ throw new JWEInvalid("JWE Shared Unprotected Header incorrect type");
1589
+ }
1590
+ if (jwe.unprotected !== void 0 && !isObject(jwe.unprotected)) {
1591
+ throw new JWEInvalid("JWE Per-Recipient Unprotected Header incorrect type");
1592
+ }
1593
+ let parsedProt;
1594
+ if (jwe.protected) {
1595
+ try {
1596
+ const protectedHeader2 = decode(jwe.protected);
1597
+ parsedProt = JSON.parse(decoder.decode(protectedHeader2));
1598
+ } catch {
1599
+ throw new JWEInvalid("JWE Protected Header is invalid");
1600
+ }
1601
+ }
1602
+ if (!is_disjoint_default(parsedProt, jwe.header, jwe.unprotected)) {
1603
+ throw new JWEInvalid("JWE Protected, JWE Unprotected Header, and JWE Per-Recipient Unprotected Header Parameter names must be disjoint");
1604
+ }
1605
+ const joseHeader = {
1606
+ ...parsedProt,
1607
+ ...jwe.header,
1608
+ ...jwe.unprotected
1609
+ };
1610
+ validate_crit_default(JWEInvalid, /* @__PURE__ */ new Map(), options?.crit, parsedProt, joseHeader);
1611
+ if (joseHeader.zip !== void 0) {
1612
+ throw new JOSENotSupported('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');
1613
+ }
1614
+ const { alg, enc } = joseHeader;
1615
+ if (typeof alg !== "string" || !alg) {
1616
+ throw new JWEInvalid("missing JWE Algorithm (alg) in JWE Header");
1617
+ }
1618
+ if (typeof enc !== "string" || !enc) {
1619
+ throw new JWEInvalid("missing JWE Encryption Algorithm (enc) in JWE Header");
1620
+ }
1621
+ const keyManagementAlgorithms = options && validate_algorithms_default("keyManagementAlgorithms", options.keyManagementAlgorithms);
1622
+ const contentEncryptionAlgorithms = options && validate_algorithms_default("contentEncryptionAlgorithms", options.contentEncryptionAlgorithms);
1623
+ if (keyManagementAlgorithms && !keyManagementAlgorithms.has(alg) || !keyManagementAlgorithms && alg.startsWith("PBES2")) {
1624
+ throw new JOSEAlgNotAllowed('"alg" (Algorithm) Header Parameter value not allowed');
1625
+ }
1626
+ if (contentEncryptionAlgorithms && !contentEncryptionAlgorithms.has(enc)) {
1627
+ throw new JOSEAlgNotAllowed('"enc" (Encryption Algorithm) Header Parameter value not allowed');
1628
+ }
1629
+ let encryptedKey;
1630
+ if (jwe.encrypted_key !== void 0) {
1631
+ try {
1632
+ encryptedKey = decode(jwe.encrypted_key);
1633
+ } catch {
1634
+ throw new JWEInvalid("Failed to base64url decode the encrypted_key");
1635
+ }
1636
+ }
1637
+ let resolvedKey = false;
1638
+ if (typeof key === "function") {
1639
+ key = await key(parsedProt, jwe);
1640
+ resolvedKey = true;
1641
+ }
1642
+ let cek;
1643
+ try {
1644
+ cek = await decrypt_key_management_default(alg, key, encryptedKey, joseHeader, options);
1645
+ } catch (err) {
1646
+ if (err instanceof TypeError || err instanceof JWEInvalid || err instanceof JOSENotSupported) {
1647
+ throw err;
1648
+ }
1649
+ cek = cek_default(enc);
1650
+ }
1651
+ let iv;
1652
+ let tag2;
1653
+ if (jwe.iv !== void 0) {
1654
+ try {
1655
+ iv = decode(jwe.iv);
1656
+ } catch {
1657
+ throw new JWEInvalid("Failed to base64url decode the iv");
1658
+ }
1659
+ }
1660
+ if (jwe.tag !== void 0) {
1661
+ try {
1662
+ tag2 = decode(jwe.tag);
1663
+ } catch {
1664
+ throw new JWEInvalid("Failed to base64url decode the tag");
1665
+ }
1666
+ }
1667
+ const protectedHeader = encoder.encode(jwe.protected ?? "");
1668
+ let additionalData;
1669
+ if (jwe.aad !== void 0) {
1670
+ additionalData = concat(protectedHeader, encoder.encode("."), encoder.encode(jwe.aad));
1671
+ } else {
1672
+ additionalData = protectedHeader;
1673
+ }
1674
+ let ciphertext;
1675
+ try {
1676
+ ciphertext = decode(jwe.ciphertext);
1677
+ } catch {
1678
+ throw new JWEInvalid("Failed to base64url decode the ciphertext");
1679
+ }
1680
+ const plaintext = await decrypt_default(enc, cek, ciphertext, iv, tag2, additionalData);
1681
+ const result = { plaintext };
1682
+ if (jwe.protected !== void 0) {
1683
+ result.protectedHeader = parsedProt;
1684
+ }
1685
+ if (jwe.aad !== void 0) {
1686
+ try {
1687
+ result.additionalAuthenticatedData = decode(jwe.aad);
1688
+ } catch {
1689
+ throw new JWEInvalid("Failed to base64url decode the aad");
1690
+ }
1691
+ }
1692
+ if (jwe.unprotected !== void 0) {
1693
+ result.sharedUnprotectedHeader = jwe.unprotected;
1694
+ }
1695
+ if (jwe.header !== void 0) {
1696
+ result.unprotectedHeader = jwe.header;
1697
+ }
1698
+ if (resolvedKey) {
1699
+ return { ...result, key };
1700
+ }
1701
+ return result;
1702
+ }
1703
+
1704
+ // node_modules/jose/dist/browser/jwe/compact/decrypt.js
1705
+ async function compactDecrypt(jwe, key, options) {
1706
+ if (jwe instanceof Uint8Array) {
1707
+ jwe = decoder.decode(jwe);
1708
+ }
1709
+ if (typeof jwe !== "string") {
1710
+ throw new JWEInvalid("Compact JWE must be a string or Uint8Array");
1711
+ }
1712
+ const { 0: protectedHeader, 1: encryptedKey, 2: iv, 3: ciphertext, 4: tag2, length } = jwe.split(".");
1713
+ if (length !== 5) {
1714
+ throw new JWEInvalid("Invalid Compact JWE");
1715
+ }
1716
+ const decrypted = await flattenedDecrypt({
1717
+ ciphertext,
1718
+ iv: iv || void 0,
1719
+ protected: protectedHeader,
1720
+ tag: tag2 || void 0,
1721
+ encrypted_key: encryptedKey || void 0
1722
+ }, key, options);
1723
+ const result = { plaintext: decrypted.plaintext, protectedHeader: decrypted.protectedHeader };
1724
+ if (typeof key === "function") {
1725
+ return { ...result, key: decrypted.key };
1726
+ }
1727
+ return result;
1728
+ }
1729
+
1730
+ // node_modules/jose/dist/browser/jwe/general/decrypt.js
1731
+ async function generalDecrypt(jwe, key, options) {
1732
+ if (!isObject(jwe)) {
1733
+ throw new JWEInvalid("General JWE must be an object");
1734
+ }
1735
+ if (!Array.isArray(jwe.recipients) || !jwe.recipients.every(isObject)) {
1736
+ throw new JWEInvalid("JWE Recipients missing or incorrect type");
1737
+ }
1738
+ if (!jwe.recipients.length) {
1739
+ throw new JWEInvalid("JWE Recipients has no members");
1740
+ }
1741
+ for (const recipient of jwe.recipients) {
1742
+ try {
1743
+ return await flattenedDecrypt({
1744
+ aad: jwe.aad,
1745
+ ciphertext: jwe.ciphertext,
1746
+ encrypted_key: recipient.encrypted_key,
1747
+ header: recipient.header,
1748
+ iv: jwe.iv,
1749
+ protected: jwe.protected,
1750
+ tag: jwe.tag,
1751
+ unprotected: jwe.unprotected
1752
+ }, key, options);
1753
+ } catch {
1754
+ }
1755
+ }
1756
+ throw new JWEDecryptionFailed();
1757
+ }
1758
+
1759
+ // node_modules/jose/dist/browser/lib/private_symbols.js
1760
+ var unprotected = Symbol();
1761
+
1762
+ // node_modules/jose/dist/browser/runtime/key_to_jwk.js
1763
+ var keyToJWK = async (key) => {
1764
+ if (key instanceof Uint8Array) {
1765
+ return {
1766
+ kty: "oct",
1767
+ k: encode(key)
1768
+ };
1769
+ }
1770
+ if (!isCryptoKey(key)) {
1771
+ throw new TypeError(invalid_key_input_default(key, ...types, "Uint8Array"));
1772
+ }
1773
+ if (!key.extractable) {
1774
+ throw new TypeError("non-extractable CryptoKey cannot be exported as a JWK");
1775
+ }
1776
+ const { ext, key_ops, alg, use, ...jwk } = await webcrypto_default.subtle.exportKey("jwk", key);
1777
+ return jwk;
1778
+ };
1779
+ var key_to_jwk_default = keyToJWK;
1780
+
1781
+ // node_modules/jose/dist/browser/key/export.js
1782
+ async function exportSPKI(key) {
1783
+ return toSPKI(key);
1784
+ }
1785
+ async function exportPKCS8(key) {
1786
+ return toPKCS8(key);
1787
+ }
1788
+ async function exportJWK(key) {
1789
+ return key_to_jwk_default(key);
1790
+ }
1791
+
1792
+ // node_modules/jose/dist/browser/lib/encrypt_key_management.js
1793
+ async function encryptKeyManagement(alg, enc, key, providedCek, providedParameters = {}) {
1794
+ let encryptedKey;
1795
+ let parameters;
1796
+ let cek;
1797
+ check_key_type_default(alg, key, "encrypt");
1798
+ key = await normalize_key_default.normalizePublicKey?.(key, alg) || key;
1799
+ switch (alg) {
1800
+ case "dir": {
1801
+ cek = key;
1802
+ break;
1803
+ }
1804
+ case "ECDH-ES":
1805
+ case "ECDH-ES+A128KW":
1806
+ case "ECDH-ES+A192KW":
1807
+ case "ECDH-ES+A256KW": {
1808
+ if (!ecdhAllowed(key)) {
1809
+ throw new JOSENotSupported("ECDH with the provided key is not allowed or not supported by your javascript runtime");
1810
+ }
1811
+ const { apu, apv } = providedParameters;
1812
+ let { epk: ephemeralKey } = providedParameters;
1813
+ ephemeralKey || (ephemeralKey = (await generateEpk(key)).privateKey);
1814
+ const { x, y, crv, kty } = await exportJWK(ephemeralKey);
1815
+ const sharedSecret = await deriveKey(key, ephemeralKey, alg === "ECDH-ES" ? enc : alg, alg === "ECDH-ES" ? bitLength2(enc) : parseInt(alg.slice(-5, -2), 10), apu, apv);
1816
+ parameters = { epk: { x, crv, kty } };
1817
+ if (kty === "EC")
1818
+ parameters.epk.y = y;
1819
+ if (apu)
1820
+ parameters.apu = encode(apu);
1821
+ if (apv)
1822
+ parameters.apv = encode(apv);
1823
+ if (alg === "ECDH-ES") {
1824
+ cek = sharedSecret;
1825
+ break;
1826
+ }
1827
+ cek = providedCek || cek_default(enc);
1828
+ const kwAlg = alg.slice(-6);
1829
+ encryptedKey = await wrap(kwAlg, sharedSecret, cek);
1830
+ break;
1831
+ }
1832
+ case "RSA1_5":
1833
+ case "RSA-OAEP":
1834
+ case "RSA-OAEP-256":
1835
+ case "RSA-OAEP-384":
1836
+ case "RSA-OAEP-512": {
1837
+ cek = providedCek || cek_default(enc);
1838
+ encryptedKey = await encrypt2(alg, key, cek);
1839
+ break;
1840
+ }
1841
+ case "PBES2-HS256+A128KW":
1842
+ case "PBES2-HS384+A192KW":
1843
+ case "PBES2-HS512+A256KW": {
1844
+ cek = providedCek || cek_default(enc);
1845
+ const { p2c, p2s: p2s2 } = providedParameters;
1846
+ ({ encryptedKey, ...parameters } = await encrypt(alg, key, cek, p2c, p2s2));
1847
+ break;
1848
+ }
1849
+ case "A128KW":
1850
+ case "A192KW":
1851
+ case "A256KW": {
1852
+ cek = providedCek || cek_default(enc);
1853
+ encryptedKey = await wrap(alg, key, cek);
1854
+ break;
1855
+ }
1856
+ case "A128GCMKW":
1857
+ case "A192GCMKW":
1858
+ case "A256GCMKW": {
1859
+ cek = providedCek || cek_default(enc);
1860
+ const { iv } = providedParameters;
1861
+ ({ encryptedKey, ...parameters } = await wrap2(alg, key, cek, iv));
1862
+ break;
1863
+ }
1864
+ default: {
1865
+ throw new JOSENotSupported('Invalid or unsupported "alg" (JWE Algorithm) header value');
1866
+ }
1867
+ }
1868
+ return { cek, encryptedKey, parameters };
1869
+ }
1870
+ var encrypt_key_management_default = encryptKeyManagement;
1871
+
1872
+ // node_modules/jose/dist/browser/jwe/flattened/encrypt.js
1873
+ var FlattenedEncrypt = class {
1874
+ constructor(plaintext) {
1875
+ if (!(plaintext instanceof Uint8Array)) {
1876
+ throw new TypeError("plaintext must be an instance of Uint8Array");
1877
+ }
1878
+ this._plaintext = plaintext;
1879
+ }
1880
+ setKeyManagementParameters(parameters) {
1881
+ if (this._keyManagementParameters) {
1882
+ throw new TypeError("setKeyManagementParameters can only be called once");
1883
+ }
1884
+ this._keyManagementParameters = parameters;
1885
+ return this;
1886
+ }
1887
+ setProtectedHeader(protectedHeader) {
1888
+ if (this._protectedHeader) {
1889
+ throw new TypeError("setProtectedHeader can only be called once");
1890
+ }
1891
+ this._protectedHeader = protectedHeader;
1892
+ return this;
1893
+ }
1894
+ setSharedUnprotectedHeader(sharedUnprotectedHeader) {
1895
+ if (this._sharedUnprotectedHeader) {
1896
+ throw new TypeError("setSharedUnprotectedHeader can only be called once");
1897
+ }
1898
+ this._sharedUnprotectedHeader = sharedUnprotectedHeader;
1899
+ return this;
1900
+ }
1901
+ setUnprotectedHeader(unprotectedHeader) {
1902
+ if (this._unprotectedHeader) {
1903
+ throw new TypeError("setUnprotectedHeader can only be called once");
1904
+ }
1905
+ this._unprotectedHeader = unprotectedHeader;
1906
+ return this;
1907
+ }
1908
+ setAdditionalAuthenticatedData(aad) {
1909
+ this._aad = aad;
1910
+ return this;
1911
+ }
1912
+ setContentEncryptionKey(cek) {
1913
+ if (this._cek) {
1914
+ throw new TypeError("setContentEncryptionKey can only be called once");
1915
+ }
1916
+ this._cek = cek;
1917
+ return this;
1918
+ }
1919
+ setInitializationVector(iv) {
1920
+ if (this._iv) {
1921
+ throw new TypeError("setInitializationVector can only be called once");
1922
+ }
1923
+ this._iv = iv;
1924
+ return this;
1925
+ }
1926
+ async encrypt(key, options) {
1927
+ if (!this._protectedHeader && !this._unprotectedHeader && !this._sharedUnprotectedHeader) {
1928
+ throw new JWEInvalid("either setProtectedHeader, setUnprotectedHeader, or sharedUnprotectedHeader must be called before #encrypt()");
1929
+ }
1930
+ if (!is_disjoint_default(this._protectedHeader, this._unprotectedHeader, this._sharedUnprotectedHeader)) {
1931
+ throw new JWEInvalid("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint");
1932
+ }
1933
+ const joseHeader = {
1934
+ ...this._protectedHeader,
1935
+ ...this._unprotectedHeader,
1936
+ ...this._sharedUnprotectedHeader
1937
+ };
1938
+ validate_crit_default(JWEInvalid, /* @__PURE__ */ new Map(), options?.crit, this._protectedHeader, joseHeader);
1939
+ if (joseHeader.zip !== void 0) {
1940
+ throw new JOSENotSupported('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');
1941
+ }
1942
+ const { alg, enc } = joseHeader;
1943
+ if (typeof alg !== "string" || !alg) {
1944
+ throw new JWEInvalid('JWE "alg" (Algorithm) Header Parameter missing or invalid');
1945
+ }
1946
+ if (typeof enc !== "string" || !enc) {
1947
+ throw new JWEInvalid('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');
1948
+ }
1949
+ let encryptedKey;
1950
+ if (this._cek && (alg === "dir" || alg === "ECDH-ES")) {
1951
+ throw new TypeError(`setContentEncryptionKey cannot be called with JWE "alg" (Algorithm) Header ${alg}`);
1952
+ }
1953
+ let cek;
1954
+ {
1955
+ let parameters;
1956
+ ({ cek, encryptedKey, parameters } = await encrypt_key_management_default(alg, enc, key, this._cek, this._keyManagementParameters));
1957
+ if (parameters) {
1958
+ if (options && unprotected in options) {
1959
+ if (!this._unprotectedHeader) {
1960
+ this.setUnprotectedHeader(parameters);
1961
+ } else {
1962
+ this._unprotectedHeader = { ...this._unprotectedHeader, ...parameters };
1963
+ }
1964
+ } else if (!this._protectedHeader) {
1965
+ this.setProtectedHeader(parameters);
1966
+ } else {
1967
+ this._protectedHeader = { ...this._protectedHeader, ...parameters };
1968
+ }
1969
+ }
1970
+ }
1971
+ let additionalData;
1972
+ let protectedHeader;
1973
+ let aadMember;
1974
+ if (this._protectedHeader) {
1975
+ protectedHeader = encoder.encode(encode(JSON.stringify(this._protectedHeader)));
1976
+ } else {
1977
+ protectedHeader = encoder.encode("");
1978
+ }
1979
+ if (this._aad) {
1980
+ aadMember = encode(this._aad);
1981
+ additionalData = concat(protectedHeader, encoder.encode("."), encoder.encode(aadMember));
1982
+ } else {
1983
+ additionalData = protectedHeader;
1984
+ }
1985
+ const { ciphertext, tag: tag2, iv } = await encrypt_default(enc, this._plaintext, cek, this._iv, additionalData);
1986
+ const jwe = {
1987
+ ciphertext: encode(ciphertext)
1988
+ };
1989
+ if (iv) {
1990
+ jwe.iv = encode(iv);
1991
+ }
1992
+ if (tag2) {
1993
+ jwe.tag = encode(tag2);
1994
+ }
1995
+ if (encryptedKey) {
1996
+ jwe.encrypted_key = encode(encryptedKey);
1997
+ }
1998
+ if (aadMember) {
1999
+ jwe.aad = aadMember;
2000
+ }
2001
+ if (this._protectedHeader) {
2002
+ jwe.protected = decoder.decode(protectedHeader);
2003
+ }
2004
+ if (this._sharedUnprotectedHeader) {
2005
+ jwe.unprotected = this._sharedUnprotectedHeader;
2006
+ }
2007
+ if (this._unprotectedHeader) {
2008
+ jwe.header = this._unprotectedHeader;
2009
+ }
2010
+ return jwe;
2011
+ }
2012
+ };
2013
+
2014
+ // node_modules/jose/dist/browser/jwe/general/encrypt.js
2015
+ var IndividualRecipient = class {
2016
+ constructor(enc, key, options) {
2017
+ this.parent = enc;
2018
+ this.key = key;
2019
+ this.options = options;
2020
+ }
2021
+ setUnprotectedHeader(unprotectedHeader) {
2022
+ if (this.unprotectedHeader) {
2023
+ throw new TypeError("setUnprotectedHeader can only be called once");
2024
+ }
2025
+ this.unprotectedHeader = unprotectedHeader;
2026
+ return this;
2027
+ }
2028
+ addRecipient(...args) {
2029
+ return this.parent.addRecipient(...args);
2030
+ }
2031
+ encrypt(...args) {
2032
+ return this.parent.encrypt(...args);
2033
+ }
2034
+ done() {
2035
+ return this.parent;
2036
+ }
2037
+ };
2038
+ var GeneralEncrypt = class {
2039
+ constructor(plaintext) {
2040
+ this._recipients = [];
2041
+ this._plaintext = plaintext;
2042
+ }
2043
+ addRecipient(key, options) {
2044
+ const recipient = new IndividualRecipient(this, key, { crit: options?.crit });
2045
+ this._recipients.push(recipient);
2046
+ return recipient;
2047
+ }
2048
+ setProtectedHeader(protectedHeader) {
2049
+ if (this._protectedHeader) {
2050
+ throw new TypeError("setProtectedHeader can only be called once");
2051
+ }
2052
+ this._protectedHeader = protectedHeader;
2053
+ return this;
2054
+ }
2055
+ setSharedUnprotectedHeader(sharedUnprotectedHeader) {
2056
+ if (this._unprotectedHeader) {
2057
+ throw new TypeError("setSharedUnprotectedHeader can only be called once");
2058
+ }
2059
+ this._unprotectedHeader = sharedUnprotectedHeader;
2060
+ return this;
2061
+ }
2062
+ setAdditionalAuthenticatedData(aad) {
2063
+ this._aad = aad;
2064
+ return this;
2065
+ }
2066
+ async encrypt() {
2067
+ if (!this._recipients.length) {
2068
+ throw new JWEInvalid("at least one recipient must be added");
2069
+ }
2070
+ if (this._recipients.length === 1) {
2071
+ const [recipient] = this._recipients;
2072
+ const flattened = await new FlattenedEncrypt(this._plaintext).setAdditionalAuthenticatedData(this._aad).setProtectedHeader(this._protectedHeader).setSharedUnprotectedHeader(this._unprotectedHeader).setUnprotectedHeader(recipient.unprotectedHeader).encrypt(recipient.key, { ...recipient.options });
2073
+ const jwe2 = {
2074
+ ciphertext: flattened.ciphertext,
2075
+ iv: flattened.iv,
2076
+ recipients: [{}],
2077
+ tag: flattened.tag
2078
+ };
2079
+ if (flattened.aad)
2080
+ jwe2.aad = flattened.aad;
2081
+ if (flattened.protected)
2082
+ jwe2.protected = flattened.protected;
2083
+ if (flattened.unprotected)
2084
+ jwe2.unprotected = flattened.unprotected;
2085
+ if (flattened.encrypted_key)
2086
+ jwe2.recipients[0].encrypted_key = flattened.encrypted_key;
2087
+ if (flattened.header)
2088
+ jwe2.recipients[0].header = flattened.header;
2089
+ return jwe2;
2090
+ }
2091
+ let enc;
2092
+ for (let i = 0; i < this._recipients.length; i++) {
2093
+ const recipient = this._recipients[i];
2094
+ if (!is_disjoint_default(this._protectedHeader, this._unprotectedHeader, recipient.unprotectedHeader)) {
2095
+ throw new JWEInvalid("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint");
2096
+ }
2097
+ const joseHeader = {
2098
+ ...this._protectedHeader,
2099
+ ...this._unprotectedHeader,
2100
+ ...recipient.unprotectedHeader
2101
+ };
2102
+ const { alg } = joseHeader;
2103
+ if (typeof alg !== "string" || !alg) {
2104
+ throw new JWEInvalid('JWE "alg" (Algorithm) Header Parameter missing or invalid');
2105
+ }
2106
+ if (alg === "dir" || alg === "ECDH-ES") {
2107
+ throw new JWEInvalid('"dir" and "ECDH-ES" alg may only be used with a single recipient');
2108
+ }
2109
+ if (typeof joseHeader.enc !== "string" || !joseHeader.enc) {
2110
+ throw new JWEInvalid('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');
2111
+ }
2112
+ if (!enc) {
2113
+ enc = joseHeader.enc;
2114
+ } else if (enc !== joseHeader.enc) {
2115
+ throw new JWEInvalid('JWE "enc" (Encryption Algorithm) Header Parameter must be the same for all recipients');
2116
+ }
2117
+ validate_crit_default(JWEInvalid, /* @__PURE__ */ new Map(), recipient.options.crit, this._protectedHeader, joseHeader);
2118
+ if (joseHeader.zip !== void 0) {
2119
+ throw new JOSENotSupported('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');
2120
+ }
2121
+ }
2122
+ const cek = cek_default(enc);
2123
+ const jwe = {
2124
+ ciphertext: "",
2125
+ iv: "",
2126
+ recipients: [],
2127
+ tag: ""
2128
+ };
2129
+ for (let i = 0; i < this._recipients.length; i++) {
2130
+ const recipient = this._recipients[i];
2131
+ const target = {};
2132
+ jwe.recipients.push(target);
2133
+ const joseHeader = {
2134
+ ...this._protectedHeader,
2135
+ ...this._unprotectedHeader,
2136
+ ...recipient.unprotectedHeader
2137
+ };
2138
+ const p2c = joseHeader.alg.startsWith("PBES2") ? 2048 + i : void 0;
2139
+ if (i === 0) {
2140
+ const flattened = await new FlattenedEncrypt(this._plaintext).setAdditionalAuthenticatedData(this._aad).setContentEncryptionKey(cek).setProtectedHeader(this._protectedHeader).setSharedUnprotectedHeader(this._unprotectedHeader).setUnprotectedHeader(recipient.unprotectedHeader).setKeyManagementParameters({ p2c }).encrypt(recipient.key, {
2141
+ ...recipient.options,
2142
+ [unprotected]: true
2143
+ });
2144
+ jwe.ciphertext = flattened.ciphertext;
2145
+ jwe.iv = flattened.iv;
2146
+ jwe.tag = flattened.tag;
2147
+ if (flattened.aad)
2148
+ jwe.aad = flattened.aad;
2149
+ if (flattened.protected)
2150
+ jwe.protected = flattened.protected;
2151
+ if (flattened.unprotected)
2152
+ jwe.unprotected = flattened.unprotected;
2153
+ target.encrypted_key = flattened.encrypted_key;
2154
+ if (flattened.header)
2155
+ target.header = flattened.header;
2156
+ continue;
2157
+ }
2158
+ const { encryptedKey, parameters } = await encrypt_key_management_default(recipient.unprotectedHeader?.alg || this._protectedHeader?.alg || this._unprotectedHeader?.alg, enc, recipient.key, cek, { p2c });
2159
+ target.encrypted_key = encode(encryptedKey);
2160
+ if (recipient.unprotectedHeader || parameters)
2161
+ target.header = { ...recipient.unprotectedHeader, ...parameters };
2162
+ }
2163
+ return jwe;
2164
+ }
2165
+ };
2166
+
2167
+ // node_modules/jose/dist/browser/runtime/subtle_dsa.js
2168
+ function subtleDsa(alg, algorithm) {
2169
+ const hash = `SHA-${alg.slice(-3)}`;
2170
+ switch (alg) {
2171
+ case "HS256":
2172
+ case "HS384":
2173
+ case "HS512":
2174
+ return { hash, name: "HMAC" };
2175
+ case "PS256":
2176
+ case "PS384":
2177
+ case "PS512":
2178
+ return { hash, name: "RSA-PSS", saltLength: alg.slice(-3) >> 3 };
2179
+ case "RS256":
2180
+ case "RS384":
2181
+ case "RS512":
2182
+ return { hash, name: "RSASSA-PKCS1-v1_5" };
2183
+ case "ES256":
2184
+ case "ES384":
2185
+ case "ES512":
2186
+ return { hash, name: "ECDSA", namedCurve: algorithm.namedCurve };
2187
+ case "Ed25519":
2188
+ return { name: "Ed25519" };
2189
+ case "EdDSA":
2190
+ return { name: algorithm.name };
2191
+ default:
2192
+ throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
2193
+ }
2194
+ }
2195
+
2196
+ // node_modules/jose/dist/browser/runtime/get_sign_verify_key.js
2197
+ async function getCryptoKey3(alg, key, usage) {
2198
+ if (usage === "sign") {
2199
+ key = await normalize_key_default.normalizePrivateKey(key, alg);
2200
+ }
2201
+ if (usage === "verify") {
2202
+ key = await normalize_key_default.normalizePublicKey(key, alg);
2203
+ }
2204
+ if (isCryptoKey(key)) {
2205
+ checkSigCryptoKey(key, alg, usage);
2206
+ return key;
2207
+ }
2208
+ if (key instanceof Uint8Array) {
2209
+ if (!alg.startsWith("HS")) {
2210
+ throw new TypeError(invalid_key_input_default(key, ...types));
2211
+ }
2212
+ return webcrypto_default.subtle.importKey("raw", key, { hash: `SHA-${alg.slice(-3)}`, name: "HMAC" }, false, [usage]);
2213
+ }
2214
+ throw new TypeError(invalid_key_input_default(key, ...types, "Uint8Array", "JSON Web Key"));
2215
+ }
2216
+
2217
+ // node_modules/jose/dist/browser/runtime/verify.js
2218
+ var verify = async (alg, key, signature, data) => {
2219
+ const cryptoKey = await getCryptoKey3(alg, key, "verify");
2220
+ check_key_length_default(alg, cryptoKey);
2221
+ const algorithm = subtleDsa(alg, cryptoKey.algorithm);
2222
+ try {
2223
+ return await webcrypto_default.subtle.verify(algorithm, cryptoKey, signature, data);
2224
+ } catch {
2225
+ return false;
2226
+ }
2227
+ };
2228
+ var verify_default = verify;
2229
+
2230
+ // node_modules/jose/dist/browser/jws/flattened/verify.js
2231
+ async function flattenedVerify(jws, key, options) {
2232
+ if (!isObject(jws)) {
2233
+ throw new JWSInvalid("Flattened JWS must be an object");
2234
+ }
2235
+ if (jws.protected === void 0 && jws.header === void 0) {
2236
+ throw new JWSInvalid('Flattened JWS must have either of the "protected" or "header" members');
2237
+ }
2238
+ if (jws.protected !== void 0 && typeof jws.protected !== "string") {
2239
+ throw new JWSInvalid("JWS Protected Header incorrect type");
2240
+ }
2241
+ if (jws.payload === void 0) {
2242
+ throw new JWSInvalid("JWS Payload missing");
2243
+ }
2244
+ if (typeof jws.signature !== "string") {
2245
+ throw new JWSInvalid("JWS Signature missing or incorrect type");
2246
+ }
2247
+ if (jws.header !== void 0 && !isObject(jws.header)) {
2248
+ throw new JWSInvalid("JWS Unprotected Header incorrect type");
2249
+ }
2250
+ let parsedProt = {};
2251
+ if (jws.protected) {
2252
+ try {
2253
+ const protectedHeader = decode(jws.protected);
2254
+ parsedProt = JSON.parse(decoder.decode(protectedHeader));
2255
+ } catch {
2256
+ throw new JWSInvalid("JWS Protected Header is invalid");
2257
+ }
2258
+ }
2259
+ if (!is_disjoint_default(parsedProt, jws.header)) {
2260
+ throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
2261
+ }
2262
+ const joseHeader = {
2263
+ ...parsedProt,
2264
+ ...jws.header
2265
+ };
2266
+ const extensions = validate_crit_default(JWSInvalid, /* @__PURE__ */ new Map([["b64", true]]), options?.crit, parsedProt, joseHeader);
2267
+ let b64 = true;
2268
+ if (extensions.has("b64")) {
2269
+ b64 = parsedProt.b64;
2270
+ if (typeof b64 !== "boolean") {
2271
+ throw new JWSInvalid('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
2272
+ }
2273
+ }
2274
+ const { alg } = joseHeader;
2275
+ if (typeof alg !== "string" || !alg) {
2276
+ throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
2277
+ }
2278
+ const algorithms = options && validate_algorithms_default("algorithms", options.algorithms);
2279
+ if (algorithms && !algorithms.has(alg)) {
2280
+ throw new JOSEAlgNotAllowed('"alg" (Algorithm) Header Parameter value not allowed');
2281
+ }
2282
+ if (b64) {
2283
+ if (typeof jws.payload !== "string") {
2284
+ throw new JWSInvalid("JWS Payload must be a string");
2285
+ }
2286
+ } else if (typeof jws.payload !== "string" && !(jws.payload instanceof Uint8Array)) {
2287
+ throw new JWSInvalid("JWS Payload must be a string or an Uint8Array instance");
2288
+ }
2289
+ let resolvedKey = false;
2290
+ if (typeof key === "function") {
2291
+ key = await key(parsedProt, jws);
2292
+ resolvedKey = true;
2293
+ checkKeyTypeWithJwk(alg, key, "verify");
2294
+ if (isJWK(key)) {
2295
+ key = await importJWK(key, alg);
2296
+ }
2297
+ } else {
2298
+ checkKeyTypeWithJwk(alg, key, "verify");
2299
+ }
2300
+ const data = concat(encoder.encode(jws.protected ?? ""), encoder.encode("."), typeof jws.payload === "string" ? encoder.encode(jws.payload) : jws.payload);
2301
+ let signature;
2302
+ try {
2303
+ signature = decode(jws.signature);
2304
+ } catch {
2305
+ throw new JWSInvalid("Failed to base64url decode the signature");
2306
+ }
2307
+ const verified = await verify_default(alg, key, signature, data);
2308
+ if (!verified) {
2309
+ throw new JWSSignatureVerificationFailed();
2310
+ }
2311
+ let payload;
2312
+ if (b64) {
2313
+ try {
2314
+ payload = decode(jws.payload);
2315
+ } catch {
2316
+ throw new JWSInvalid("Failed to base64url decode the payload");
2317
+ }
2318
+ } else if (typeof jws.payload === "string") {
2319
+ payload = encoder.encode(jws.payload);
2320
+ } else {
2321
+ payload = jws.payload;
2322
+ }
2323
+ const result = { payload };
2324
+ if (jws.protected !== void 0) {
2325
+ result.protectedHeader = parsedProt;
2326
+ }
2327
+ if (jws.header !== void 0) {
2328
+ result.unprotectedHeader = jws.header;
2329
+ }
2330
+ if (resolvedKey) {
2331
+ return { ...result, key };
2332
+ }
2333
+ return result;
2334
+ }
2335
+
2336
+ // node_modules/jose/dist/browser/jws/compact/verify.js
2337
+ async function compactVerify(jws, key, options) {
2338
+ if (jws instanceof Uint8Array) {
2339
+ jws = decoder.decode(jws);
2340
+ }
2341
+ if (typeof jws !== "string") {
2342
+ throw new JWSInvalid("Compact JWS must be a string or Uint8Array");
2343
+ }
2344
+ const { 0: protectedHeader, 1: payload, 2: signature, length } = jws.split(".");
2345
+ if (length !== 3) {
2346
+ throw new JWSInvalid("Invalid Compact JWS");
2347
+ }
2348
+ const verified = await flattenedVerify({ payload, protected: protectedHeader, signature }, key, options);
2349
+ const result = { payload: verified.payload, protectedHeader: verified.protectedHeader };
2350
+ if (typeof key === "function") {
2351
+ return { ...result, key: verified.key };
2352
+ }
2353
+ return result;
2354
+ }
2355
+
2356
+ // node_modules/jose/dist/browser/jws/general/verify.js
2357
+ async function generalVerify(jws, key, options) {
2358
+ if (!isObject(jws)) {
2359
+ throw new JWSInvalid("General JWS must be an object");
2360
+ }
2361
+ if (!Array.isArray(jws.signatures) || !jws.signatures.every(isObject)) {
2362
+ throw new JWSInvalid("JWS Signatures missing or incorrect type");
2363
+ }
2364
+ for (const signature of jws.signatures) {
2365
+ try {
2366
+ return await flattenedVerify({
2367
+ header: signature.header,
2368
+ payload: jws.payload,
2369
+ protected: signature.protected,
2370
+ signature: signature.signature
2371
+ }, key, options);
2372
+ } catch {
2373
+ }
2374
+ }
2375
+ throw new JWSSignatureVerificationFailed();
2376
+ }
2377
+
2378
+ // node_modules/jose/dist/browser/lib/epoch.js
2379
+ var epoch_default = (date) => Math.floor(date.getTime() / 1e3);
2380
+
2381
+ // node_modules/jose/dist/browser/lib/secs.js
2382
+ var minute = 60;
2383
+ var hour = minute * 60;
2384
+ var day = hour * 24;
2385
+ var week = day * 7;
2386
+ var year = day * 365.25;
2387
+ var REGEX = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;
2388
+ var secs_default = (str) => {
2389
+ const matched = REGEX.exec(str);
2390
+ if (!matched || matched[4] && matched[1]) {
2391
+ throw new TypeError("Invalid time period format");
2392
+ }
2393
+ const value = parseFloat(matched[2]);
2394
+ const unit = matched[3].toLowerCase();
2395
+ let numericDate;
2396
+ switch (unit) {
2397
+ case "sec":
2398
+ case "secs":
2399
+ case "second":
2400
+ case "seconds":
2401
+ case "s":
2402
+ numericDate = Math.round(value);
2403
+ break;
2404
+ case "minute":
2405
+ case "minutes":
2406
+ case "min":
2407
+ case "mins":
2408
+ case "m":
2409
+ numericDate = Math.round(value * minute);
2410
+ break;
2411
+ case "hour":
2412
+ case "hours":
2413
+ case "hr":
2414
+ case "hrs":
2415
+ case "h":
2416
+ numericDate = Math.round(value * hour);
2417
+ break;
2418
+ case "day":
2419
+ case "days":
2420
+ case "d":
2421
+ numericDate = Math.round(value * day);
2422
+ break;
2423
+ case "week":
2424
+ case "weeks":
2425
+ case "w":
2426
+ numericDate = Math.round(value * week);
2427
+ break;
2428
+ default:
2429
+ numericDate = Math.round(value * year);
2430
+ break;
2431
+ }
2432
+ if (matched[1] === "-" || matched[4] === "ago") {
2433
+ return -numericDate;
2434
+ }
2435
+ return numericDate;
2436
+ };
2437
+
2438
+ // node_modules/jose/dist/browser/lib/jwt_claims_set.js
2439
+ var normalizeTyp = (value) => value.toLowerCase().replace(/^application\//, "");
2440
+ var checkAudiencePresence = (audPayload, audOption) => {
2441
+ if (typeof audPayload === "string") {
2442
+ return audOption.includes(audPayload);
2443
+ }
2444
+ if (Array.isArray(audPayload)) {
2445
+ return audOption.some(Set.prototype.has.bind(new Set(audPayload)));
2446
+ }
2447
+ return false;
2448
+ };
2449
+ var jwt_claims_set_default = (protectedHeader, encodedPayload, options = {}) => {
2450
+ let payload;
2451
+ try {
2452
+ payload = JSON.parse(decoder.decode(encodedPayload));
2453
+ } catch {
2454
+ }
2455
+ if (!isObject(payload)) {
2456
+ throw new JWTInvalid("JWT Claims Set must be a top-level JSON object");
2457
+ }
2458
+ const { typ } = options;
2459
+ if (typ && (typeof protectedHeader.typ !== "string" || normalizeTyp(protectedHeader.typ) !== normalizeTyp(typ))) {
2460
+ throw new JWTClaimValidationFailed('unexpected "typ" JWT header value', payload, "typ", "check_failed");
2461
+ }
2462
+ const { requiredClaims = [], issuer, subject, audience, maxTokenAge } = options;
2463
+ const presenceCheck = [...requiredClaims];
2464
+ if (maxTokenAge !== void 0)
2465
+ presenceCheck.push("iat");
2466
+ if (audience !== void 0)
2467
+ presenceCheck.push("aud");
2468
+ if (subject !== void 0)
2469
+ presenceCheck.push("sub");
2470
+ if (issuer !== void 0)
2471
+ presenceCheck.push("iss");
2472
+ for (const claim of new Set(presenceCheck.reverse())) {
2473
+ if (!(claim in payload)) {
2474
+ throw new JWTClaimValidationFailed(`missing required "${claim}" claim`, payload, claim, "missing");
2475
+ }
2476
+ }
2477
+ if (issuer && !(Array.isArray(issuer) ? issuer : [issuer]).includes(payload.iss)) {
2478
+ throw new JWTClaimValidationFailed('unexpected "iss" claim value', payload, "iss", "check_failed");
2479
+ }
2480
+ if (subject && payload.sub !== subject) {
2481
+ throw new JWTClaimValidationFailed('unexpected "sub" claim value', payload, "sub", "check_failed");
2482
+ }
2483
+ if (audience && !checkAudiencePresence(payload.aud, typeof audience === "string" ? [audience] : audience)) {
2484
+ throw new JWTClaimValidationFailed('unexpected "aud" claim value', payload, "aud", "check_failed");
2485
+ }
2486
+ let tolerance;
2487
+ switch (typeof options.clockTolerance) {
2488
+ case "string":
2489
+ tolerance = secs_default(options.clockTolerance);
2490
+ break;
2491
+ case "number":
2492
+ tolerance = options.clockTolerance;
2493
+ break;
2494
+ case "undefined":
2495
+ tolerance = 0;
2496
+ break;
2497
+ default:
2498
+ throw new TypeError("Invalid clockTolerance option type");
2499
+ }
2500
+ const { currentDate } = options;
2501
+ const now = epoch_default(currentDate || /* @__PURE__ */ new Date());
2502
+ if ((payload.iat !== void 0 || maxTokenAge) && typeof payload.iat !== "number") {
2503
+ throw new JWTClaimValidationFailed('"iat" claim must be a number', payload, "iat", "invalid");
2504
+ }
2505
+ if (payload.nbf !== void 0) {
2506
+ if (typeof payload.nbf !== "number") {
2507
+ throw new JWTClaimValidationFailed('"nbf" claim must be a number', payload, "nbf", "invalid");
2508
+ }
2509
+ if (payload.nbf > now + tolerance) {
2510
+ throw new JWTClaimValidationFailed('"nbf" claim timestamp check failed', payload, "nbf", "check_failed");
2511
+ }
2512
+ }
2513
+ if (payload.exp !== void 0) {
2514
+ if (typeof payload.exp !== "number") {
2515
+ throw new JWTClaimValidationFailed('"exp" claim must be a number', payload, "exp", "invalid");
2516
+ }
2517
+ if (payload.exp <= now - tolerance) {
2518
+ throw new JWTExpired('"exp" claim timestamp check failed', payload, "exp", "check_failed");
2519
+ }
2520
+ }
2521
+ if (maxTokenAge) {
2522
+ const age = now - payload.iat;
2523
+ const max = typeof maxTokenAge === "number" ? maxTokenAge : secs_default(maxTokenAge);
2524
+ if (age - tolerance > max) {
2525
+ throw new JWTExpired('"iat" claim timestamp check failed (too far in the past)', payload, "iat", "check_failed");
2526
+ }
2527
+ if (age < 0 - tolerance) {
2528
+ throw new JWTClaimValidationFailed('"iat" claim timestamp check failed (it should be in the past)', payload, "iat", "check_failed");
2529
+ }
2530
+ }
2531
+ return payload;
2532
+ };
2533
+
2534
+ // node_modules/jose/dist/browser/jwt/verify.js
2535
+ async function jwtVerify(jwt, key, options) {
2536
+ const verified = await compactVerify(jwt, key, options);
2537
+ if (verified.protectedHeader.crit?.includes("b64") && verified.protectedHeader.b64 === false) {
2538
+ throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
2539
+ }
2540
+ const payload = jwt_claims_set_default(verified.protectedHeader, verified.payload, options);
2541
+ const result = { payload, protectedHeader: verified.protectedHeader };
2542
+ if (typeof key === "function") {
2543
+ return { ...result, key: verified.key };
2544
+ }
2545
+ return result;
2546
+ }
2547
+
2548
+ // node_modules/jose/dist/browser/jwt/decrypt.js
2549
+ async function jwtDecrypt(jwt, key, options) {
2550
+ const decrypted = await compactDecrypt(jwt, key, options);
2551
+ const payload = jwt_claims_set_default(decrypted.protectedHeader, decrypted.plaintext, options);
2552
+ const { protectedHeader } = decrypted;
2553
+ if (protectedHeader.iss !== void 0 && protectedHeader.iss !== payload.iss) {
2554
+ throw new JWTClaimValidationFailed('replicated "iss" claim header parameter mismatch', payload, "iss", "mismatch");
2555
+ }
2556
+ if (protectedHeader.sub !== void 0 && protectedHeader.sub !== payload.sub) {
2557
+ throw new JWTClaimValidationFailed('replicated "sub" claim header parameter mismatch', payload, "sub", "mismatch");
2558
+ }
2559
+ if (protectedHeader.aud !== void 0 && JSON.stringify(protectedHeader.aud) !== JSON.stringify(payload.aud)) {
2560
+ throw new JWTClaimValidationFailed('replicated "aud" claim header parameter mismatch', payload, "aud", "mismatch");
2561
+ }
2562
+ const result = { payload, protectedHeader };
2563
+ if (typeof key === "function") {
2564
+ return { ...result, key: decrypted.key };
2565
+ }
2566
+ return result;
2567
+ }
2568
+
2569
+ // node_modules/jose/dist/browser/jwe/compact/encrypt.js
2570
+ var CompactEncrypt = class {
2571
+ constructor(plaintext) {
2572
+ this._flattened = new FlattenedEncrypt(plaintext);
2573
+ }
2574
+ setContentEncryptionKey(cek) {
2575
+ this._flattened.setContentEncryptionKey(cek);
2576
+ return this;
2577
+ }
2578
+ setInitializationVector(iv) {
2579
+ this._flattened.setInitializationVector(iv);
2580
+ return this;
2581
+ }
2582
+ setProtectedHeader(protectedHeader) {
2583
+ this._flattened.setProtectedHeader(protectedHeader);
2584
+ return this;
2585
+ }
2586
+ setKeyManagementParameters(parameters) {
2587
+ this._flattened.setKeyManagementParameters(parameters);
2588
+ return this;
2589
+ }
2590
+ async encrypt(key, options) {
2591
+ const jwe = await this._flattened.encrypt(key, options);
2592
+ return [jwe.protected, jwe.encrypted_key, jwe.iv, jwe.ciphertext, jwe.tag].join(".");
2593
+ }
2594
+ };
2595
+
2596
+ // node_modules/jose/dist/browser/runtime/sign.js
2597
+ var sign = async (alg, key, data) => {
2598
+ const cryptoKey = await getCryptoKey3(alg, key, "sign");
2599
+ check_key_length_default(alg, cryptoKey);
2600
+ const signature = await webcrypto_default.subtle.sign(subtleDsa(alg, cryptoKey.algorithm), cryptoKey, data);
2601
+ return new Uint8Array(signature);
2602
+ };
2603
+ var sign_default = sign;
2604
+
2605
+ // node_modules/jose/dist/browser/jws/flattened/sign.js
2606
+ var FlattenedSign = class {
2607
+ constructor(payload) {
2608
+ if (!(payload instanceof Uint8Array)) {
2609
+ throw new TypeError("payload must be an instance of Uint8Array");
2610
+ }
2611
+ this._payload = payload;
2612
+ }
2613
+ setProtectedHeader(protectedHeader) {
2614
+ if (this._protectedHeader) {
2615
+ throw new TypeError("setProtectedHeader can only be called once");
2616
+ }
2617
+ this._protectedHeader = protectedHeader;
2618
+ return this;
2619
+ }
2620
+ setUnprotectedHeader(unprotectedHeader) {
2621
+ if (this._unprotectedHeader) {
2622
+ throw new TypeError("setUnprotectedHeader can only be called once");
2623
+ }
2624
+ this._unprotectedHeader = unprotectedHeader;
2625
+ return this;
2626
+ }
2627
+ async sign(key, options) {
2628
+ if (!this._protectedHeader && !this._unprotectedHeader) {
2629
+ throw new JWSInvalid("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");
2630
+ }
2631
+ if (!is_disjoint_default(this._protectedHeader, this._unprotectedHeader)) {
2632
+ throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
2633
+ }
2634
+ const joseHeader = {
2635
+ ...this._protectedHeader,
2636
+ ...this._unprotectedHeader
2637
+ };
2638
+ const extensions = validate_crit_default(JWSInvalid, /* @__PURE__ */ new Map([["b64", true]]), options?.crit, this._protectedHeader, joseHeader);
2639
+ let b64 = true;
2640
+ if (extensions.has("b64")) {
2641
+ b64 = this._protectedHeader.b64;
2642
+ if (typeof b64 !== "boolean") {
2643
+ throw new JWSInvalid('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
2644
+ }
2645
+ }
2646
+ const { alg } = joseHeader;
2647
+ if (typeof alg !== "string" || !alg) {
2648
+ throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
2649
+ }
2650
+ checkKeyTypeWithJwk(alg, key, "sign");
2651
+ let payload = this._payload;
2652
+ if (b64) {
2653
+ payload = encoder.encode(encode(payload));
2654
+ }
2655
+ let protectedHeader;
2656
+ if (this._protectedHeader) {
2657
+ protectedHeader = encoder.encode(encode(JSON.stringify(this._protectedHeader)));
2658
+ } else {
2659
+ protectedHeader = encoder.encode("");
2660
+ }
2661
+ const data = concat(protectedHeader, encoder.encode("."), payload);
2662
+ const signature = await sign_default(alg, key, data);
2663
+ const jws = {
2664
+ signature: encode(signature),
2665
+ payload: ""
2666
+ };
2667
+ if (b64) {
2668
+ jws.payload = decoder.decode(payload);
2669
+ }
2670
+ if (this._unprotectedHeader) {
2671
+ jws.header = this._unprotectedHeader;
2672
+ }
2673
+ if (this._protectedHeader) {
2674
+ jws.protected = decoder.decode(protectedHeader);
2675
+ }
2676
+ return jws;
2677
+ }
2678
+ };
2679
+
2680
+ // node_modules/jose/dist/browser/jws/compact/sign.js
2681
+ var CompactSign = class {
2682
+ constructor(payload) {
2683
+ this._flattened = new FlattenedSign(payload);
2684
+ }
2685
+ setProtectedHeader(protectedHeader) {
2686
+ this._flattened.setProtectedHeader(protectedHeader);
2687
+ return this;
2688
+ }
2689
+ async sign(key, options) {
2690
+ const jws = await this._flattened.sign(key, options);
2691
+ if (jws.payload === void 0) {
2692
+ throw new TypeError("use the flattened module for creating JWS with b64: false");
2693
+ }
2694
+ return `${jws.protected}.${jws.payload}.${jws.signature}`;
2695
+ }
2696
+ };
2697
+
2698
+ // node_modules/jose/dist/browser/jws/general/sign.js
2699
+ var IndividualSignature = class {
2700
+ constructor(sig, key, options) {
2701
+ this.parent = sig;
2702
+ this.key = key;
2703
+ this.options = options;
2704
+ }
2705
+ setProtectedHeader(protectedHeader) {
2706
+ if (this.protectedHeader) {
2707
+ throw new TypeError("setProtectedHeader can only be called once");
2708
+ }
2709
+ this.protectedHeader = protectedHeader;
2710
+ return this;
2711
+ }
2712
+ setUnprotectedHeader(unprotectedHeader) {
2713
+ if (this.unprotectedHeader) {
2714
+ throw new TypeError("setUnprotectedHeader can only be called once");
2715
+ }
2716
+ this.unprotectedHeader = unprotectedHeader;
2717
+ return this;
2718
+ }
2719
+ addSignature(...args) {
2720
+ return this.parent.addSignature(...args);
2721
+ }
2722
+ sign(...args) {
2723
+ return this.parent.sign(...args);
2724
+ }
2725
+ done() {
2726
+ return this.parent;
2727
+ }
2728
+ };
2729
+ var GeneralSign = class {
2730
+ constructor(payload) {
2731
+ this._signatures = [];
2732
+ this._payload = payload;
2733
+ }
2734
+ addSignature(key, options) {
2735
+ const signature = new IndividualSignature(this, key, options);
2736
+ this._signatures.push(signature);
2737
+ return signature;
2738
+ }
2739
+ async sign() {
2740
+ if (!this._signatures.length) {
2741
+ throw new JWSInvalid("at least one signature must be added");
2742
+ }
2743
+ const jws = {
2744
+ signatures: [],
2745
+ payload: ""
2746
+ };
2747
+ for (let i = 0; i < this._signatures.length; i++) {
2748
+ const signature = this._signatures[i];
2749
+ const flattened = new FlattenedSign(this._payload);
2750
+ flattened.setProtectedHeader(signature.protectedHeader);
2751
+ flattened.setUnprotectedHeader(signature.unprotectedHeader);
2752
+ const { payload, ...rest } = await flattened.sign(signature.key, signature.options);
2753
+ if (i === 0) {
2754
+ jws.payload = payload;
2755
+ } else if (jws.payload !== payload) {
2756
+ throw new JWSInvalid("inconsistent use of JWS Unencoded Payload (RFC7797)");
2757
+ }
2758
+ jws.signatures.push(rest);
2759
+ }
2760
+ return jws;
2761
+ }
2762
+ };
2763
+
2764
+ // node_modules/jose/dist/browser/jwt/produce.js
2765
+ function validateInput(label, input) {
2766
+ if (!Number.isFinite(input)) {
2767
+ throw new TypeError(`Invalid ${label} input`);
2768
+ }
2769
+ return input;
2770
+ }
2771
+ var ProduceJWT = class {
2772
+ constructor(payload = {}) {
2773
+ if (!isObject(payload)) {
2774
+ throw new TypeError("JWT Claims Set MUST be an object");
2775
+ }
2776
+ this._payload = payload;
2777
+ }
2778
+ setIssuer(issuer) {
2779
+ this._payload = { ...this._payload, iss: issuer };
2780
+ return this;
2781
+ }
2782
+ setSubject(subject) {
2783
+ this._payload = { ...this._payload, sub: subject };
2784
+ return this;
2785
+ }
2786
+ setAudience(audience) {
2787
+ this._payload = { ...this._payload, aud: audience };
2788
+ return this;
2789
+ }
2790
+ setJti(jwtId) {
2791
+ this._payload = { ...this._payload, jti: jwtId };
2792
+ return this;
2793
+ }
2794
+ setNotBefore(input) {
2795
+ if (typeof input === "number") {
2796
+ this._payload = { ...this._payload, nbf: validateInput("setNotBefore", input) };
2797
+ } else if (input instanceof Date) {
2798
+ this._payload = { ...this._payload, nbf: validateInput("setNotBefore", epoch_default(input)) };
2799
+ } else {
2800
+ this._payload = { ...this._payload, nbf: epoch_default(/* @__PURE__ */ new Date()) + secs_default(input) };
2801
+ }
2802
+ return this;
2803
+ }
2804
+ setExpirationTime(input) {
2805
+ if (typeof input === "number") {
2806
+ this._payload = { ...this._payload, exp: validateInput("setExpirationTime", input) };
2807
+ } else if (input instanceof Date) {
2808
+ this._payload = { ...this._payload, exp: validateInput("setExpirationTime", epoch_default(input)) };
2809
+ } else {
2810
+ this._payload = { ...this._payload, exp: epoch_default(/* @__PURE__ */ new Date()) + secs_default(input) };
2811
+ }
2812
+ return this;
2813
+ }
2814
+ setIssuedAt(input) {
2815
+ if (typeof input === "undefined") {
2816
+ this._payload = { ...this._payload, iat: epoch_default(/* @__PURE__ */ new Date()) };
2817
+ } else if (input instanceof Date) {
2818
+ this._payload = { ...this._payload, iat: validateInput("setIssuedAt", epoch_default(input)) };
2819
+ } else if (typeof input === "string") {
2820
+ this._payload = {
2821
+ ...this._payload,
2822
+ iat: validateInput("setIssuedAt", epoch_default(/* @__PURE__ */ new Date()) + secs_default(input))
2823
+ };
2824
+ } else {
2825
+ this._payload = { ...this._payload, iat: validateInput("setIssuedAt", input) };
2826
+ }
2827
+ return this;
2828
+ }
2829
+ };
2830
+
2831
+ // node_modules/jose/dist/browser/jwt/sign.js
2832
+ var SignJWT = class extends ProduceJWT {
2833
+ setProtectedHeader(protectedHeader) {
2834
+ this._protectedHeader = protectedHeader;
2835
+ return this;
2836
+ }
2837
+ async sign(key, options) {
2838
+ const sig = new CompactSign(encoder.encode(JSON.stringify(this._payload)));
2839
+ sig.setProtectedHeader(this._protectedHeader);
2840
+ if (Array.isArray(this._protectedHeader?.crit) && this._protectedHeader.crit.includes("b64") && this._protectedHeader.b64 === false) {
2841
+ throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
2842
+ }
2843
+ return sig.sign(key, options);
2844
+ }
2845
+ };
2846
+
2847
+ // node_modules/jose/dist/browser/jwt/encrypt.js
2848
+ var EncryptJWT = class extends ProduceJWT {
2849
+ setProtectedHeader(protectedHeader) {
2850
+ if (this._protectedHeader) {
2851
+ throw new TypeError("setProtectedHeader can only be called once");
2852
+ }
2853
+ this._protectedHeader = protectedHeader;
2854
+ return this;
2855
+ }
2856
+ setKeyManagementParameters(parameters) {
2857
+ if (this._keyManagementParameters) {
2858
+ throw new TypeError("setKeyManagementParameters can only be called once");
2859
+ }
2860
+ this._keyManagementParameters = parameters;
2861
+ return this;
2862
+ }
2863
+ setContentEncryptionKey(cek) {
2864
+ if (this._cek) {
2865
+ throw new TypeError("setContentEncryptionKey can only be called once");
2866
+ }
2867
+ this._cek = cek;
2868
+ return this;
2869
+ }
2870
+ setInitializationVector(iv) {
2871
+ if (this._iv) {
2872
+ throw new TypeError("setInitializationVector can only be called once");
2873
+ }
2874
+ this._iv = iv;
2875
+ return this;
2876
+ }
2877
+ replicateIssuerAsHeader() {
2878
+ this._replicateIssuerAsHeader = true;
2879
+ return this;
2880
+ }
2881
+ replicateSubjectAsHeader() {
2882
+ this._replicateSubjectAsHeader = true;
2883
+ return this;
2884
+ }
2885
+ replicateAudienceAsHeader() {
2886
+ this._replicateAudienceAsHeader = true;
2887
+ return this;
2888
+ }
2889
+ async encrypt(key, options) {
2890
+ const enc = new CompactEncrypt(encoder.encode(JSON.stringify(this._payload)));
2891
+ if (this._replicateIssuerAsHeader) {
2892
+ this._protectedHeader = { ...this._protectedHeader, iss: this._payload.iss };
2893
+ }
2894
+ if (this._replicateSubjectAsHeader) {
2895
+ this._protectedHeader = { ...this._protectedHeader, sub: this._payload.sub };
2896
+ }
2897
+ if (this._replicateAudienceAsHeader) {
2898
+ this._protectedHeader = { ...this._protectedHeader, aud: this._payload.aud };
2899
+ }
2900
+ enc.setProtectedHeader(this._protectedHeader);
2901
+ if (this._iv) {
2902
+ enc.setInitializationVector(this._iv);
2903
+ }
2904
+ if (this._cek) {
2905
+ enc.setContentEncryptionKey(this._cek);
2906
+ }
2907
+ if (this._keyManagementParameters) {
2908
+ enc.setKeyManagementParameters(this._keyManagementParameters);
2909
+ }
2910
+ return enc.encrypt(key, options);
2911
+ }
2912
+ };
2913
+
2914
+ // node_modules/jose/dist/browser/jwk/thumbprint.js
2915
+ var check = (value, description) => {
2916
+ if (typeof value !== "string" || !value) {
2917
+ throw new JWKInvalid(`${description} missing or invalid`);
2918
+ }
2919
+ };
2920
+ async function calculateJwkThumbprint(jwk, digestAlgorithm) {
2921
+ if (!isObject(jwk)) {
2922
+ throw new TypeError("JWK must be an object");
2923
+ }
2924
+ digestAlgorithm ?? (digestAlgorithm = "sha256");
2925
+ if (digestAlgorithm !== "sha256" && digestAlgorithm !== "sha384" && digestAlgorithm !== "sha512") {
2926
+ throw new TypeError('digestAlgorithm must one of "sha256", "sha384", or "sha512"');
2927
+ }
2928
+ let components;
2929
+ switch (jwk.kty) {
2930
+ case "EC":
2931
+ check(jwk.crv, '"crv" (Curve) Parameter');
2932
+ check(jwk.x, '"x" (X Coordinate) Parameter');
2933
+ check(jwk.y, '"y" (Y Coordinate) Parameter');
2934
+ components = { crv: jwk.crv, kty: jwk.kty, x: jwk.x, y: jwk.y };
2935
+ break;
2936
+ case "OKP":
2937
+ check(jwk.crv, '"crv" (Subtype of Key Pair) Parameter');
2938
+ check(jwk.x, '"x" (Public Key) Parameter');
2939
+ components = { crv: jwk.crv, kty: jwk.kty, x: jwk.x };
2940
+ break;
2941
+ case "RSA":
2942
+ check(jwk.e, '"e" (Exponent) Parameter');
2943
+ check(jwk.n, '"n" (Modulus) Parameter');
2944
+ components = { e: jwk.e, kty: jwk.kty, n: jwk.n };
2945
+ break;
2946
+ case "oct":
2947
+ check(jwk.k, '"k" (Key Value) Parameter');
2948
+ components = { k: jwk.k, kty: jwk.kty };
2949
+ break;
2950
+ default:
2951
+ throw new JOSENotSupported('"kty" (Key Type) Parameter missing or unsupported');
2952
+ }
2953
+ const data = encoder.encode(JSON.stringify(components));
2954
+ return encode(await digest_default(digestAlgorithm, data));
2955
+ }
2956
+ async function calculateJwkThumbprintUri(jwk, digestAlgorithm) {
2957
+ digestAlgorithm ?? (digestAlgorithm = "sha256");
2958
+ const thumbprint = await calculateJwkThumbprint(jwk, digestAlgorithm);
2959
+ return `urn:ietf:params:oauth:jwk-thumbprint:sha-${digestAlgorithm.slice(-3)}:${thumbprint}`;
2960
+ }
2961
+
2962
+ // node_modules/jose/dist/browser/jwk/embedded.js
2963
+ async function EmbeddedJWK(protectedHeader, token) {
2964
+ const joseHeader = {
2965
+ ...protectedHeader,
2966
+ ...token?.header
2967
+ };
2968
+ if (!isObject(joseHeader.jwk)) {
2969
+ throw new JWSInvalid('"jwk" (JSON Web Key) Header Parameter must be a JSON object');
2970
+ }
2971
+ const key = await importJWK({ ...joseHeader.jwk, ext: true }, joseHeader.alg);
2972
+ if (key instanceof Uint8Array || key.type !== "public") {
2973
+ throw new JWSInvalid('"jwk" (JSON Web Key) Header Parameter must be a public key');
2974
+ }
2975
+ return key;
2976
+ }
2977
+
2978
+ // node_modules/jose/dist/browser/jwks/local.js
2979
+ function getKtyFromAlg(alg) {
2980
+ switch (typeof alg === "string" && alg.slice(0, 2)) {
2981
+ case "RS":
2982
+ case "PS":
2983
+ return "RSA";
2984
+ case "ES":
2985
+ return "EC";
2986
+ case "Ed":
2987
+ return "OKP";
2988
+ default:
2989
+ throw new JOSENotSupported('Unsupported "alg" value for a JSON Web Key Set');
2990
+ }
2991
+ }
2992
+ function isJWKSLike(jwks) {
2993
+ return jwks && typeof jwks === "object" && Array.isArray(jwks.keys) && jwks.keys.every(isJWKLike);
2994
+ }
2995
+ function isJWKLike(key) {
2996
+ return isObject(key);
2997
+ }
2998
+ function clone(obj) {
2999
+ if (typeof structuredClone === "function") {
3000
+ return structuredClone(obj);
3001
+ }
3002
+ return JSON.parse(JSON.stringify(obj));
3003
+ }
3004
+ var LocalJWKSet = class {
3005
+ constructor(jwks) {
3006
+ this._cached = /* @__PURE__ */ new WeakMap();
3007
+ if (!isJWKSLike(jwks)) {
3008
+ throw new JWKSInvalid("JSON Web Key Set malformed");
3009
+ }
3010
+ this._jwks = clone(jwks);
3011
+ }
3012
+ async getKey(protectedHeader, token) {
3013
+ const { alg, kid } = { ...protectedHeader, ...token?.header };
3014
+ const kty = getKtyFromAlg(alg);
3015
+ const candidates = this._jwks.keys.filter((jwk2) => {
3016
+ let candidate = kty === jwk2.kty;
3017
+ if (candidate && typeof kid === "string") {
3018
+ candidate = kid === jwk2.kid;
3019
+ }
3020
+ if (candidate && typeof jwk2.alg === "string") {
3021
+ candidate = alg === jwk2.alg;
3022
+ }
3023
+ if (candidate && typeof jwk2.use === "string") {
3024
+ candidate = jwk2.use === "sig";
3025
+ }
3026
+ if (candidate && Array.isArray(jwk2.key_ops)) {
3027
+ candidate = jwk2.key_ops.includes("verify");
3028
+ }
3029
+ if (candidate) {
3030
+ switch (alg) {
3031
+ case "ES256":
3032
+ candidate = jwk2.crv === "P-256";
3033
+ break;
3034
+ case "ES256K":
3035
+ candidate = jwk2.crv === "secp256k1";
3036
+ break;
3037
+ case "ES384":
3038
+ candidate = jwk2.crv === "P-384";
3039
+ break;
3040
+ case "ES512":
3041
+ candidate = jwk2.crv === "P-521";
3042
+ break;
3043
+ case "Ed25519":
3044
+ candidate = jwk2.crv === "Ed25519";
3045
+ break;
3046
+ case "EdDSA":
3047
+ candidate = jwk2.crv === "Ed25519" || jwk2.crv === "Ed448";
3048
+ break;
3049
+ }
3050
+ }
3051
+ return candidate;
3052
+ });
3053
+ const { 0: jwk, length } = candidates;
3054
+ if (length === 0) {
3055
+ throw new JWKSNoMatchingKey();
3056
+ }
3057
+ if (length !== 1) {
3058
+ const error = new JWKSMultipleMatchingKeys();
3059
+ const { _cached } = this;
3060
+ error[Symbol.asyncIterator] = async function* () {
3061
+ for (const jwk2 of candidates) {
3062
+ try {
3063
+ yield await importWithAlgCache(_cached, jwk2, alg);
3064
+ } catch {
3065
+ }
3066
+ }
3067
+ };
3068
+ throw error;
3069
+ }
3070
+ return importWithAlgCache(this._cached, jwk, alg);
3071
+ }
3072
+ };
3073
+ async function importWithAlgCache(cache, jwk, alg) {
3074
+ const cached = cache.get(jwk) || cache.set(jwk, {}).get(jwk);
3075
+ if (cached[alg] === void 0) {
3076
+ const key = await importJWK({ ...jwk, ext: true }, alg);
3077
+ if (key instanceof Uint8Array || key.type !== "public") {
3078
+ throw new JWKSInvalid("JSON Web Key Set members must be public keys");
3079
+ }
3080
+ cached[alg] = key;
3081
+ }
3082
+ return cached[alg];
3083
+ }
3084
+ function createLocalJWKSet(jwks) {
3085
+ const set = new LocalJWKSet(jwks);
3086
+ const localJWKSet = async (protectedHeader, token) => set.getKey(protectedHeader, token);
3087
+ Object.defineProperties(localJWKSet, {
3088
+ jwks: {
3089
+ value: () => clone(set._jwks),
3090
+ enumerable: true,
3091
+ configurable: false,
3092
+ writable: false
3093
+ }
3094
+ });
3095
+ return localJWKSet;
3096
+ }
3097
+
3098
+ // node_modules/jose/dist/browser/runtime/fetch_jwks.js
3099
+ var fetchJwks = async (url, timeout, options) => {
3100
+ let controller;
3101
+ let id;
3102
+ let timedOut = false;
3103
+ if (typeof AbortController === "function") {
3104
+ controller = new AbortController();
3105
+ id = setTimeout(() => {
3106
+ timedOut = true;
3107
+ controller.abort();
3108
+ }, timeout);
3109
+ }
3110
+ const response = await fetch(url.href, {
3111
+ signal: controller ? controller.signal : void 0,
3112
+ redirect: "manual",
3113
+ headers: options.headers
3114
+ }).catch((err) => {
3115
+ if (timedOut)
3116
+ throw new JWKSTimeout();
3117
+ throw err;
3118
+ });
3119
+ if (id !== void 0)
3120
+ clearTimeout(id);
3121
+ if (response.status !== 200) {
3122
+ throw new JOSEError("Expected 200 OK from the JSON Web Key Set HTTP response");
3123
+ }
3124
+ try {
3125
+ return await response.json();
3126
+ } catch {
3127
+ throw new JOSEError("Failed to parse the JSON Web Key Set HTTP response as JSON");
3128
+ }
3129
+ };
3130
+ var fetch_jwks_default = fetchJwks;
3131
+
3132
+ // node_modules/jose/dist/browser/jwks/remote.js
3133
+ function isCloudflareWorkers() {
3134
+ return typeof WebSocketPair !== "undefined" || typeof navigator !== "undefined" && navigator.userAgent === "Cloudflare-Workers" || typeof EdgeRuntime !== "undefined" && EdgeRuntime === "vercel";
3135
+ }
3136
+ var USER_AGENT;
3137
+ if (typeof navigator === "undefined" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) {
3138
+ const NAME = "jose";
3139
+ const VERSION = "v5.10.0";
3140
+ USER_AGENT = `${NAME}/${VERSION}`;
3141
+ }
3142
+ var jwksCache = Symbol();
3143
+ function isFreshJwksCache(input, cacheMaxAge) {
3144
+ if (typeof input !== "object" || input === null) {
3145
+ return false;
3146
+ }
3147
+ if (!("uat" in input) || typeof input.uat !== "number" || Date.now() - input.uat >= cacheMaxAge) {
3148
+ return false;
3149
+ }
3150
+ if (!("jwks" in input) || !isObject(input.jwks) || !Array.isArray(input.jwks.keys) || !Array.prototype.every.call(input.jwks.keys, isObject)) {
3151
+ return false;
3152
+ }
3153
+ return true;
3154
+ }
3155
+ var RemoteJWKSet = class {
3156
+ constructor(url, options) {
3157
+ if (!(url instanceof URL)) {
3158
+ throw new TypeError("url must be an instance of URL");
3159
+ }
3160
+ this._url = new URL(url.href);
3161
+ this._options = { agent: options?.agent, headers: options?.headers };
3162
+ this._timeoutDuration = typeof options?.timeoutDuration === "number" ? options?.timeoutDuration : 5e3;
3163
+ this._cooldownDuration = typeof options?.cooldownDuration === "number" ? options?.cooldownDuration : 3e4;
3164
+ this._cacheMaxAge = typeof options?.cacheMaxAge === "number" ? options?.cacheMaxAge : 6e5;
3165
+ if (options?.[jwksCache] !== void 0) {
3166
+ this._cache = options?.[jwksCache];
3167
+ if (isFreshJwksCache(options?.[jwksCache], this._cacheMaxAge)) {
3168
+ this._jwksTimestamp = this._cache.uat;
3169
+ this._local = createLocalJWKSet(this._cache.jwks);
3170
+ }
3171
+ }
3172
+ }
3173
+ coolingDown() {
3174
+ return typeof this._jwksTimestamp === "number" ? Date.now() < this._jwksTimestamp + this._cooldownDuration : false;
3175
+ }
3176
+ fresh() {
3177
+ return typeof this._jwksTimestamp === "number" ? Date.now() < this._jwksTimestamp + this._cacheMaxAge : false;
3178
+ }
3179
+ async getKey(protectedHeader, token) {
3180
+ if (!this._local || !this.fresh()) {
3181
+ await this.reload();
3182
+ }
3183
+ try {
3184
+ return await this._local(protectedHeader, token);
3185
+ } catch (err) {
3186
+ if (err instanceof JWKSNoMatchingKey) {
3187
+ if (this.coolingDown() === false) {
3188
+ await this.reload();
3189
+ return this._local(protectedHeader, token);
3190
+ }
3191
+ }
3192
+ throw err;
3193
+ }
3194
+ }
3195
+ async reload() {
3196
+ if (this._pendingFetch && isCloudflareWorkers()) {
3197
+ this._pendingFetch = void 0;
3198
+ }
3199
+ const headers = new Headers(this._options.headers);
3200
+ if (USER_AGENT && !headers.has("User-Agent")) {
3201
+ headers.set("User-Agent", USER_AGENT);
3202
+ this._options.headers = Object.fromEntries(headers.entries());
3203
+ }
3204
+ this._pendingFetch || (this._pendingFetch = fetch_jwks_default(this._url, this._timeoutDuration, this._options).then((json) => {
3205
+ this._local = createLocalJWKSet(json);
3206
+ if (this._cache) {
3207
+ this._cache.uat = Date.now();
3208
+ this._cache.jwks = json;
3209
+ }
3210
+ this._jwksTimestamp = Date.now();
3211
+ this._pendingFetch = void 0;
3212
+ }).catch((err) => {
3213
+ this._pendingFetch = void 0;
3214
+ throw err;
3215
+ }));
3216
+ await this._pendingFetch;
3217
+ }
3218
+ };
3219
+ function createRemoteJWKSet(url, options) {
3220
+ const set = new RemoteJWKSet(url, options);
3221
+ const remoteJWKSet = async (protectedHeader, token) => set.getKey(protectedHeader, token);
3222
+ Object.defineProperties(remoteJWKSet, {
3223
+ coolingDown: {
3224
+ get: () => set.coolingDown(),
3225
+ enumerable: true,
3226
+ configurable: false
3227
+ },
3228
+ fresh: {
3229
+ get: () => set.fresh(),
3230
+ enumerable: true,
3231
+ configurable: false
3232
+ },
3233
+ reload: {
3234
+ value: () => set.reload(),
3235
+ enumerable: true,
3236
+ configurable: false,
3237
+ writable: false
3238
+ },
3239
+ reloading: {
3240
+ get: () => !!set._pendingFetch,
3241
+ enumerable: true,
3242
+ configurable: false
3243
+ },
3244
+ jwks: {
3245
+ value: () => set._local?.jwks(),
3246
+ enumerable: true,
3247
+ configurable: false,
3248
+ writable: false
3249
+ }
3250
+ });
3251
+ return remoteJWKSet;
3252
+ }
3253
+ var experimental_jwksCache = jwksCache;
3254
+
3255
+ // node_modules/jose/dist/browser/jwt/unsecured.js
3256
+ var UnsecuredJWT = class extends ProduceJWT {
3257
+ encode() {
3258
+ const header = encode(JSON.stringify({ alg: "none" }));
3259
+ const payload = encode(JSON.stringify(this._payload));
3260
+ return `${header}.${payload}.`;
3261
+ }
3262
+ static decode(jwt, options) {
3263
+ if (typeof jwt !== "string") {
3264
+ throw new JWTInvalid("Unsecured JWT must be a string");
3265
+ }
3266
+ const { 0: encodedHeader, 1: encodedPayload, 2: signature, length } = jwt.split(".");
3267
+ if (length !== 3 || signature !== "") {
3268
+ throw new JWTInvalid("Invalid Unsecured JWT");
3269
+ }
3270
+ let header;
3271
+ try {
3272
+ header = JSON.parse(decoder.decode(decode(encodedHeader)));
3273
+ if (header.alg !== "none")
3274
+ throw new Error();
3275
+ } catch {
3276
+ throw new JWTInvalid("Invalid Unsecured JWT");
3277
+ }
3278
+ const payload = jwt_claims_set_default(header, decode(encodedPayload), options);
3279
+ return { payload, header };
3280
+ }
3281
+ };
3282
+
3283
+ // node_modules/jose/dist/browser/util/base64url.js
3284
+ var base64url_exports2 = {};
3285
+ __export(base64url_exports2, {
3286
+ decode: () => decode2,
3287
+ encode: () => encode2
3288
+ });
3289
+ var encode2 = encode;
3290
+ var decode2 = decode;
3291
+
3292
+ // node_modules/jose/dist/browser/util/decode_protected_header.js
3293
+ function decodeProtectedHeader(token) {
3294
+ let protectedB64u;
3295
+ if (typeof token === "string") {
3296
+ const parts = token.split(".");
3297
+ if (parts.length === 3 || parts.length === 5) {
3298
+ ;
3299
+ [protectedB64u] = parts;
3300
+ }
3301
+ } else if (typeof token === "object" && token) {
3302
+ if ("protected" in token) {
3303
+ protectedB64u = token.protected;
3304
+ } else {
3305
+ throw new TypeError("Token does not contain a Protected Header");
3306
+ }
3307
+ }
3308
+ try {
3309
+ if (typeof protectedB64u !== "string" || !protectedB64u) {
3310
+ throw new Error();
3311
+ }
3312
+ const result = JSON.parse(decoder.decode(decode2(protectedB64u)));
3313
+ if (!isObject(result)) {
3314
+ throw new Error();
3315
+ }
3316
+ return result;
3317
+ } catch {
3318
+ throw new TypeError("Invalid Token or Protected Header formatting");
3319
+ }
3320
+ }
3321
+
3322
+ // node_modules/jose/dist/browser/util/decode_jwt.js
3323
+ function decodeJwt(jwt) {
3324
+ if (typeof jwt !== "string")
3325
+ throw new JWTInvalid("JWTs must use Compact JWS serialization, JWT must be a string");
3326
+ const { 1: payload, length } = jwt.split(".");
3327
+ if (length === 5)
3328
+ throw new JWTInvalid("Only JWTs using Compact JWS serialization can be decoded");
3329
+ if (length !== 3)
3330
+ throw new JWTInvalid("Invalid JWT");
3331
+ if (!payload)
3332
+ throw new JWTInvalid("JWTs must contain a payload");
3333
+ let decoded;
3334
+ try {
3335
+ decoded = decode2(payload);
3336
+ } catch {
3337
+ throw new JWTInvalid("Failed to base64url decode the payload");
3338
+ }
3339
+ let result;
3340
+ try {
3341
+ result = JSON.parse(decoder.decode(decoded));
3342
+ } catch {
3343
+ throw new JWTInvalid("Failed to parse the decoded payload as JSON");
3344
+ }
3345
+ if (!isObject(result))
3346
+ throw new JWTInvalid("Invalid JWT Claims Set");
3347
+ return result;
3348
+ }
3349
+
3350
+ // node_modules/jose/dist/browser/runtime/generate.js
3351
+ async function generateSecret(alg, options) {
3352
+ let length;
3353
+ let algorithm;
3354
+ let keyUsages;
3355
+ switch (alg) {
3356
+ case "HS256":
3357
+ case "HS384":
3358
+ case "HS512":
3359
+ length = parseInt(alg.slice(-3), 10);
3360
+ algorithm = { name: "HMAC", hash: `SHA-${length}`, length };
3361
+ keyUsages = ["sign", "verify"];
3362
+ break;
3363
+ case "A128CBC-HS256":
3364
+ case "A192CBC-HS384":
3365
+ case "A256CBC-HS512":
3366
+ length = parseInt(alg.slice(-3), 10);
3367
+ return random_default(new Uint8Array(length >> 3));
3368
+ case "A128KW":
3369
+ case "A192KW":
3370
+ case "A256KW":
3371
+ length = parseInt(alg.slice(1, 4), 10);
3372
+ algorithm = { name: "AES-KW", length };
3373
+ keyUsages = ["wrapKey", "unwrapKey"];
3374
+ break;
3375
+ case "A128GCMKW":
3376
+ case "A192GCMKW":
3377
+ case "A256GCMKW":
3378
+ case "A128GCM":
3379
+ case "A192GCM":
3380
+ case "A256GCM":
3381
+ length = parseInt(alg.slice(1, 4), 10);
3382
+ algorithm = { name: "AES-GCM", length };
3383
+ keyUsages = ["encrypt", "decrypt"];
3384
+ break;
3385
+ default:
3386
+ throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
3387
+ }
3388
+ return webcrypto_default.subtle.generateKey(algorithm, options?.extractable ?? false, keyUsages);
3389
+ }
3390
+ function getModulusLengthOption(options) {
3391
+ const modulusLength = options?.modulusLength ?? 2048;
3392
+ if (typeof modulusLength !== "number" || modulusLength < 2048) {
3393
+ throw new JOSENotSupported("Invalid or unsupported modulusLength option provided, 2048 bits or larger keys must be used");
3394
+ }
3395
+ return modulusLength;
3396
+ }
3397
+ async function generateKeyPair(alg, options) {
3398
+ let algorithm;
3399
+ let keyUsages;
3400
+ switch (alg) {
3401
+ case "PS256":
3402
+ case "PS384":
3403
+ case "PS512":
3404
+ algorithm = {
3405
+ name: "RSA-PSS",
3406
+ hash: `SHA-${alg.slice(-3)}`,
3407
+ publicExponent: new Uint8Array([1, 0, 1]),
3408
+ modulusLength: getModulusLengthOption(options)
3409
+ };
3410
+ keyUsages = ["sign", "verify"];
3411
+ break;
3412
+ case "RS256":
3413
+ case "RS384":
3414
+ case "RS512":
3415
+ algorithm = {
3416
+ name: "RSASSA-PKCS1-v1_5",
3417
+ hash: `SHA-${alg.slice(-3)}`,
3418
+ publicExponent: new Uint8Array([1, 0, 1]),
3419
+ modulusLength: getModulusLengthOption(options)
3420
+ };
3421
+ keyUsages = ["sign", "verify"];
3422
+ break;
3423
+ case "RSA-OAEP":
3424
+ case "RSA-OAEP-256":
3425
+ case "RSA-OAEP-384":
3426
+ case "RSA-OAEP-512":
3427
+ algorithm = {
3428
+ name: "RSA-OAEP",
3429
+ hash: `SHA-${parseInt(alg.slice(-3), 10) || 1}`,
3430
+ publicExponent: new Uint8Array([1, 0, 1]),
3431
+ modulusLength: getModulusLengthOption(options)
3432
+ };
3433
+ keyUsages = ["decrypt", "unwrapKey", "encrypt", "wrapKey"];
3434
+ break;
3435
+ case "ES256":
3436
+ algorithm = { name: "ECDSA", namedCurve: "P-256" };
3437
+ keyUsages = ["sign", "verify"];
3438
+ break;
3439
+ case "ES384":
3440
+ algorithm = { name: "ECDSA", namedCurve: "P-384" };
3441
+ keyUsages = ["sign", "verify"];
3442
+ break;
3443
+ case "ES512":
3444
+ algorithm = { name: "ECDSA", namedCurve: "P-521" };
3445
+ keyUsages = ["sign", "verify"];
3446
+ break;
3447
+ case "Ed25519":
3448
+ algorithm = { name: "Ed25519" };
3449
+ keyUsages = ["sign", "verify"];
3450
+ break;
3451
+ case "EdDSA": {
3452
+ keyUsages = ["sign", "verify"];
3453
+ const crv = options?.crv ?? "Ed25519";
3454
+ switch (crv) {
3455
+ case "Ed25519":
3456
+ case "Ed448":
3457
+ algorithm = { name: crv };
3458
+ break;
3459
+ default:
3460
+ throw new JOSENotSupported("Invalid or unsupported crv option provided");
3461
+ }
3462
+ break;
3463
+ }
3464
+ case "ECDH-ES":
3465
+ case "ECDH-ES+A128KW":
3466
+ case "ECDH-ES+A192KW":
3467
+ case "ECDH-ES+A256KW": {
3468
+ keyUsages = ["deriveKey", "deriveBits"];
3469
+ const crv = options?.crv ?? "P-256";
3470
+ switch (crv) {
3471
+ case "P-256":
3472
+ case "P-384":
3473
+ case "P-521": {
3474
+ algorithm = { name: "ECDH", namedCurve: crv };
3475
+ break;
3476
+ }
3477
+ case "X25519":
3478
+ case "X448":
3479
+ algorithm = { name: crv };
3480
+ break;
3481
+ default:
3482
+ throw new JOSENotSupported("Invalid or unsupported crv option provided, supported values are P-256, P-384, P-521, X25519, and X448");
3483
+ }
3484
+ break;
3485
+ }
3486
+ default:
3487
+ throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
3488
+ }
3489
+ return webcrypto_default.subtle.generateKey(algorithm, options?.extractable ?? false, keyUsages);
3490
+ }
3491
+
3492
+ // node_modules/jose/dist/browser/key/generate_key_pair.js
3493
+ async function generateKeyPair2(alg, options) {
3494
+ return generateKeyPair(alg, options);
3495
+ }
3496
+
3497
+ // node_modules/jose/dist/browser/key/generate_secret.js
3498
+ async function generateSecret2(alg, options) {
3499
+ return generateSecret(alg, options);
3500
+ }
3501
+
3502
+ // node_modules/jose/dist/browser/runtime/runtime.js
3503
+ var runtime_default = "WebCryptoAPI";
3504
+
3505
+ // node_modules/jose/dist/browser/util/runtime.js
3506
+ var runtime_default2 = runtime_default;
3507
+ export {
3508
+ CompactEncrypt,
3509
+ CompactSign,
3510
+ EmbeddedJWK,
3511
+ EncryptJWT,
3512
+ FlattenedEncrypt,
3513
+ FlattenedSign,
3514
+ GeneralEncrypt,
3515
+ GeneralSign,
3516
+ SignJWT,
3517
+ UnsecuredJWT,
3518
+ base64url_exports2 as base64url,
3519
+ calculateJwkThumbprint,
3520
+ calculateJwkThumbprintUri,
3521
+ compactDecrypt,
3522
+ compactVerify,
3523
+ createLocalJWKSet,
3524
+ createRemoteJWKSet,
3525
+ runtime_default2 as cryptoRuntime,
3526
+ decodeJwt,
3527
+ decodeProtectedHeader,
3528
+ errors_exports as errors,
3529
+ experimental_jwksCache,
3530
+ exportJWK,
3531
+ exportPKCS8,
3532
+ exportSPKI,
3533
+ flattenedDecrypt,
3534
+ flattenedVerify,
3535
+ generalDecrypt,
3536
+ generalVerify,
3537
+ generateKeyPair2 as generateKeyPair,
3538
+ generateSecret2 as generateSecret,
3539
+ importJWK,
3540
+ importPKCS8,
3541
+ importSPKI,
3542
+ importX509,
3543
+ jwksCache,
3544
+ jwtDecrypt,
3545
+ jwtVerify
3546
+ };