@shumai-one/shumai 0.4.2 → 0.4.3

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 (250) hide show
  1. package/bin/{chunk-adekdctx.css → chunk-0ccg9ddn.css} +1 -1
  2. package/bin/chunk-0e4wawpq.js +2 -0
  3. package/bin/chunk-185qefn1.js +2 -0
  4. package/bin/chunk-1kw2mbqb.js +1 -0
  5. package/bin/chunk-1wm6ptdx.js +1 -0
  6. package/bin/chunk-1yacmegc.js +2 -0
  7. package/bin/chunk-2291ehh5.js +3 -0
  8. package/bin/chunk-2520aq8j.js +2 -0
  9. package/bin/chunk-29zdp63z.js +3 -0
  10. package/bin/chunk-2yxj593j.js +2 -0
  11. package/bin/chunk-32pcmaqm.js +3 -0
  12. package/bin/chunk-3a13dcs1.js +1 -0
  13. package/bin/chunk-3cyrcgm5.js +13 -0
  14. package/bin/chunk-3swpwb9v.js +1 -0
  15. package/bin/chunk-3wmcx2bv.js +2 -0
  16. package/bin/chunk-4r81ghg8.js +2 -0
  17. package/bin/chunk-4v5n0ayb.js +2 -0
  18. package/bin/chunk-5a8nt4me.js +1 -0
  19. package/bin/chunk-66hsjnw6.js +2 -0
  20. package/bin/chunk-6bhn1p8v.js +211 -0
  21. package/bin/chunk-6gg1ymer.js +2 -0
  22. package/bin/chunk-70c3xrgd.js +2 -0
  23. package/bin/chunk-7esm0hqb.js +2 -0
  24. package/bin/chunk-7fst8kdw.js +12 -0
  25. package/bin/chunk-83e12sjg.js +3 -0
  26. package/bin/chunk-87zxtf66.js +3 -0
  27. package/bin/chunk-8fmy5jtp.js +2 -0
  28. package/bin/chunk-8zqgaxvv.js +1 -0
  29. package/bin/chunk-9t1ne8xr.js +2 -0
  30. package/bin/chunk-a32vreya.js +2 -0
  31. package/bin/chunk-a3dmtt2j.js +1 -0
  32. package/bin/chunk-abt0azmv.js +2 -0
  33. package/bin/chunk-ag6p3mbf.js +2 -0
  34. package/bin/chunk-aqbrzx9z.js +1 -0
  35. package/bin/chunk-av1a8fqp.js +3 -0
  36. package/bin/chunk-awfwk64v.js +2 -0
  37. package/bin/chunk-b235azv4.js +45 -0
  38. package/bin/chunk-b9yrw9et.js +10 -0
  39. package/bin/chunk-bay038pj.js +2 -0
  40. package/bin/chunk-c007p0t8.js +299 -0
  41. package/bin/chunk-cak32x57.js +2 -0
  42. package/bin/chunk-ce8m4zeg.js +3 -0
  43. package/bin/chunk-ck8azecb.js +12 -0
  44. package/bin/chunk-cnxwmycy.js +6 -0
  45. package/bin/chunk-cqb415s6.js +5 -0
  46. package/bin/chunk-e2mvmq2m.js +1 -0
  47. package/bin/chunk-e7mqtkzn.js +2 -0
  48. package/bin/chunk-e99dv20z.js +3 -0
  49. package/bin/chunk-ea79xnn3.js +2 -0
  50. package/bin/chunk-ehc9adfz.js +2 -0
  51. package/bin/chunk-ejbvfj4r.js +1 -0
  52. package/bin/chunk-ekfem7kf.js +1 -0
  53. package/bin/chunk-etwkk0xh.js +1 -0
  54. package/bin/chunk-evrdd32b.js +2 -0
  55. package/bin/chunk-f15qyp41.js +1 -0
  56. package/bin/chunk-f3ehv01n.js +54 -0
  57. package/bin/chunk-fm6p03ad.js +2 -0
  58. package/bin/chunk-fxswt9hc.js +3 -0
  59. package/bin/chunk-fyha3r13.js +2 -0
  60. package/bin/chunk-g0vs7k2x.js +1 -0
  61. package/bin/chunk-g84z2w7v.js +16 -0
  62. package/bin/chunk-gk3eqd50.js +2 -0
  63. package/bin/chunk-h3tbf521.js +2 -0
  64. package/bin/chunk-h837fyed.js +2 -0
  65. package/bin/chunk-hfh0c082.js +2 -0
  66. package/bin/chunk-j20e0qsw.js +7 -0
  67. package/bin/chunk-j8fxp8ej.js +2 -0
  68. package/bin/chunk-jje8nj8h.js +3 -0
  69. package/bin/chunk-jy006gcv.js +7 -0
  70. package/bin/chunk-k7hss0bd.js +4 -0
  71. package/bin/chunk-m7m9d4fb.js +2 -0
  72. package/bin/chunk-n1jwdb0a.js +1 -0
  73. package/bin/chunk-p5gf1zdm.js +4 -0
  74. package/bin/chunk-pb1zf0vb.js +2 -0
  75. package/bin/chunk-pfgxggaj.js +11 -0
  76. package/bin/chunk-q16490pv.js +2 -0
  77. package/bin/chunk-q2bvyv39.js +8 -0
  78. package/bin/chunk-qf24e71w.js +2 -0
  79. package/bin/chunk-qh81zhg1.js +1 -0
  80. package/bin/chunk-qwp3kwbz.js +2 -0
  81. package/bin/chunk-qwqvt9v6.js +2 -0
  82. package/bin/chunk-qydeqgyj.js +5 -0
  83. package/bin/chunk-r7dty1tg.js +2 -0
  84. package/bin/chunk-rbj4fad9.js +32 -0
  85. package/bin/chunk-rhdxwebf.js +2 -0
  86. package/bin/chunk-rhh716z0.js +42 -0
  87. package/bin/chunk-rpywcvg1.js +3 -0
  88. package/bin/chunk-rza4ae5z.js +3 -0
  89. package/bin/chunk-sfx2588q.js +3 -0
  90. package/bin/chunk-sk4e6rb1.js +1 -0
  91. package/bin/chunk-t2n1dbgx.js +4 -0
  92. package/bin/chunk-tf28796q.js +2 -0
  93. package/bin/chunk-twdxayky.js +3 -0
  94. package/bin/chunk-v9b3w8q5.js +3 -0
  95. package/bin/chunk-v9w25rp2.js +2 -0
  96. package/bin/chunk-vgn5zcpv.js +3 -0
  97. package/bin/chunk-wfzqnpc1.js +3 -0
  98. package/bin/chunk-wry2hvrq.js +24 -0
  99. package/bin/chunk-x8f4defx.js +3 -0
  100. package/bin/chunk-xp59apdb.js +2 -0
  101. package/bin/chunk-xtf3c29c.css +1 -0
  102. package/bin/chunk-z3gkt8w1.js +3 -0
  103. package/bin/chunk-zehyn6vd.js +2 -0
  104. package/bin/chunk-zh6fqq44.js +1 -0
  105. package/bin/chunk-zmv8cg4s.js +8 -0
  106. package/bin/chunk-zqv0zhfb.js +3 -0
  107. package/bin/{pdf.worker.min-szxdj13d.mjs → pdf.worker.min-vf48er29.mjs} +14423 -13889
  108. package/bin/shumai-app.html +1 -1
  109. package/bin/shumai-app.js +626 -460
  110. package/package.json +18 -18
  111. package/prisma/migrations/20260904022457_add_agent_id_to_assets_and_audit_logs/migration.sql +17 -0
  112. package/prisma/migrations/20260906081230_default_denied_tools_delete_asset/migration.sql +15 -0
  113. package/prisma/schema.prisma +9 -0
  114. package/bin/chunk-07h4b77v.js +0 -2
  115. package/bin/chunk-0t4n4d5w.js +0 -4
  116. package/bin/chunk-1611z9jg.js +0 -2
  117. package/bin/chunk-1phqxp6z.js +0 -3
  118. package/bin/chunk-23hckrrz.js +0 -2
  119. package/bin/chunk-30z44j1g.js +0 -2
  120. package/bin/chunk-3j463k1g.js +0 -1
  121. package/bin/chunk-4181tdds.js +0 -14
  122. package/bin/chunk-480jtqng.js +0 -4
  123. package/bin/chunk-4c3g146q.js +0 -2
  124. package/bin/chunk-4ca0zt5e.js +0 -1
  125. package/bin/chunk-4d9bgmf2.js +0 -2
  126. package/bin/chunk-4ev56fss.js +0 -9
  127. package/bin/chunk-4gk52tjq.js +0 -45
  128. package/bin/chunk-4mdqkj4d.js +0 -1
  129. package/bin/chunk-4r91fggc.js +0 -2
  130. package/bin/chunk-50fb1x3w.js +0 -1
  131. package/bin/chunk-59gj1njz.js +0 -1
  132. package/bin/chunk-5pr0t7fb.js +0 -2
  133. package/bin/chunk-5vewxmz7.js +0 -3
  134. package/bin/chunk-62zx96pe.js +0 -2
  135. package/bin/chunk-63y0eb07.js +0 -2
  136. package/bin/chunk-6d5xrgfx.js +0 -2
  137. package/bin/chunk-6gbtz5bf.js +0 -67
  138. package/bin/chunk-6gjg5egq.js +0 -3
  139. package/bin/chunk-6m4jz9s1.js +0 -44
  140. package/bin/chunk-6s4x525w.js +0 -2
  141. package/bin/chunk-6w2wmvqs.js +0 -3
  142. package/bin/chunk-77d23vcn.js +0 -2
  143. package/bin/chunk-77m5p188.js +0 -2
  144. package/bin/chunk-7bvx087f.js +0 -1
  145. package/bin/chunk-7pfjfrjg.js +0 -5
  146. package/bin/chunk-7q10s127.js +0 -4
  147. package/bin/chunk-7thx8ctx.js +0 -3
  148. package/bin/chunk-8t4s91gh.js +0 -2
  149. package/bin/chunk-98ey5p2e.js +0 -3
  150. package/bin/chunk-9amndcyh.js +0 -6
  151. package/bin/chunk-9bk23g9x.js +0 -1
  152. package/bin/chunk-9mkcfy43.js +0 -1
  153. package/bin/chunk-9t3nsq5n.js +0 -2
  154. package/bin/chunk-9tjq99ds.js +0 -2
  155. package/bin/chunk-9wm9rwh1.js +0 -2
  156. package/bin/chunk-ab16fyg4.js +0 -4
  157. package/bin/chunk-arv0g2av.js +0 -1
  158. package/bin/chunk-aytj4zxg.js +0 -3
  159. package/bin/chunk-b1ypjqgp.js +0 -2
  160. package/bin/chunk-bdjv0ykq.js +0 -2
  161. package/bin/chunk-c1k86mfa.js +0 -10
  162. package/bin/chunk-caa96dgd.js +0 -2
  163. package/bin/chunk-ce4v2yjy.js +0 -1
  164. package/bin/chunk-cqh60y54.js +0 -3
  165. package/bin/chunk-cvq7zgw7.js +0 -1
  166. package/bin/chunk-d9mjbtp2.js +0 -2
  167. package/bin/chunk-dn7sbjws.js +0 -3
  168. package/bin/chunk-dxyq9h8n.js +0 -3
  169. package/bin/chunk-e3cabksx.js +0 -3
  170. package/bin/chunk-egcrbj94.js +0 -2
  171. package/bin/chunk-ev17v1mv.js +0 -2
  172. package/bin/chunk-evtpwg71.js +0 -2
  173. package/bin/chunk-f3e0nsv2.js +0 -2
  174. package/bin/chunk-f40gjqpq.js +0 -2
  175. package/bin/chunk-fe7822ak.js +0 -299
  176. package/bin/chunk-g8tkhw9j.js +0 -2
  177. package/bin/chunk-g9r0p4t8.js +0 -2
  178. package/bin/chunk-gbjyh9ms.js +0 -1
  179. package/bin/chunk-gtbsb39v.js +0 -3
  180. package/bin/chunk-gytz1q13.js +0 -13
  181. package/bin/chunk-h0fxysxs.js +0 -7
  182. package/bin/chunk-h8bdvsqt.js +0 -2
  183. package/bin/chunk-hag024w8.js +0 -2
  184. package/bin/chunk-hc6w5nw4.js +0 -7
  185. package/bin/chunk-j69dqc48.js +0 -2
  186. package/bin/chunk-jbtw1zym.js +0 -8
  187. package/bin/chunk-jc1vb7rj.js +0 -5
  188. package/bin/chunk-jdv78w9r.js +0 -2
  189. package/bin/chunk-jjs70y9v.js +0 -3
  190. package/bin/chunk-jmdar2gz.js +0 -2
  191. package/bin/chunk-jvwz10n4.js +0 -2
  192. package/bin/chunk-k47md1g4.js +0 -2
  193. package/bin/chunk-k4v0brcb.js +0 -2
  194. package/bin/chunk-k6n7c07e.js +0 -1
  195. package/bin/chunk-kk2cstsg.js +0 -2
  196. package/bin/chunk-knz4h56q.js +0 -12
  197. package/bin/chunk-kqqtt6bd.js +0 -3
  198. package/bin/chunk-kvyp1t4j.js +0 -7
  199. package/bin/chunk-kxskpgsq.js +0 -5
  200. package/bin/chunk-m6srbjcs.js +0 -2
  201. package/bin/chunk-mcc1scxs.js +0 -12
  202. package/bin/chunk-mq83a0kk.js +0 -2
  203. package/bin/chunk-mxm8g4q0.js +0 -1
  204. package/bin/chunk-nhpgdqq5.js +0 -2
  205. package/bin/chunk-nne496aa.js +0 -2
  206. package/bin/chunk-nqpb0r9h.js +0 -11
  207. package/bin/chunk-ns0zww9g.js +0 -2
  208. package/bin/chunk-ps4xfp23.js +0 -2
  209. package/bin/chunk-pz2ec6xt.js +0 -2
  210. package/bin/chunk-q163k309.js +0 -2
  211. package/bin/chunk-q1da61ps.js +0 -1
  212. package/bin/chunk-qrf0ady6.js +0 -68
  213. package/bin/chunk-qy28f25e.js +0 -2
  214. package/bin/chunk-r7s4ypw1.js +0 -2
  215. package/bin/chunk-ran23vm9.js +0 -1
  216. package/bin/chunk-rfvdc4n0.js +0 -2
  217. package/bin/chunk-rgthkvgx.js +0 -3
  218. package/bin/chunk-s39n3yw3.js +0 -2
  219. package/bin/chunk-s7wdd0g7.js +0 -8
  220. package/bin/chunk-s88ha5kx.js +0 -3
  221. package/bin/chunk-sf91bt9m.js +0 -2
  222. package/bin/chunk-sjwbjf9j.js +0 -2
  223. package/bin/chunk-t62076pv.js +0 -1
  224. package/bin/chunk-tbbwss3v.js +0 -3
  225. package/bin/chunk-tjcc7a6y.js +0 -24
  226. package/bin/chunk-tp6ab26e.js +0 -2
  227. package/bin/chunk-v2wxk9p5.js +0 -4
  228. package/bin/chunk-vbk6y4hk.js +0 -2
  229. package/bin/chunk-vfgfg5fk.js +0 -2
  230. package/bin/chunk-vm6c3xx9.js +0 -2
  231. package/bin/chunk-vsx96mt6.js +0 -3
  232. package/bin/chunk-wbyw1shz.js +0 -6
  233. package/bin/chunk-whh2vh50.css +0 -1
  234. package/bin/chunk-wjkcq65s.js +0 -2
  235. package/bin/chunk-wkefwkfp.js +0 -41
  236. package/bin/chunk-x7bsnk1e.js +0 -2
  237. package/bin/chunk-xbhw6bpz.js +0 -3
  238. package/bin/chunk-xg5yrcj5.js +0 -2
  239. package/bin/chunk-xg9xscqz.js +0 -1
  240. package/bin/chunk-xw2gpcsh.js +0 -3
  241. package/bin/chunk-ycq8ank7.js +0 -2
  242. package/bin/chunk-yp9hvkc5.js +0 -73
  243. package/bin/chunk-ytypyfkc.js +0 -65
  244. package/bin/chunk-z1kjmf60.js +0 -2
  245. package/bin/chunk-z36bx86r.js +0 -2
  246. package/bin/chunk-z7hdnecp.js +0 -3
  247. package/bin/chunk-zeby1cq7.js +0 -2
  248. package/bin/chunk-zs5e8z1w.js +0 -1
  249. package/bin/chunk-zxnyefg5.js +0 -2
  250. /package/bin/{chunk-24ke0th1.css → chunk-kegybs91.css} +0 -0
@@ -1,6 +0,0 @@
1
- // @bun
2
- import{un as pt}from"./chunk-dxyq9h8n.js";var Fe={};pt(Fe,{encode:()=>y,decode:()=>W});var X=new TextEncoder,C=new TextDecoder;function g(...e){let t=e.reduce((i,{length:a})=>i+a,0),r=new Uint8Array(t),n=0;for(let i of e)r.set(i,n),n+=i.length;return r}function Ge(e,t,r){if(t<0||t>=4294967296)throw RangeError(`value must be >= 0 and <= 4294967295. Received ${t}`);e.set([t>>>24,t>>>16,t>>>8,t&255],r)}function Ve(e){let t=Math.floor(e/4294967296),r=e%4294967296,n=new Uint8Array(8);return Ge(n,t,0),Ge(n,r,4),n}function Ce(e){let t=new Uint8Array(4);return Ge(t,e),t}function w(e){let t=new Uint8Array(e.length);for(let r=0;r<e.length;r++){let n=e.charCodeAt(r);if(n>127)throw TypeError("non-ASCII string encountered in encode()");t[r]=n}return t}function de(e){if(Uint8Array.prototype.toBase64)return e.toBase64();let t=32768,r=[];for(let n=0;n<e.length;n+=t)r.push(String.fromCharCode.apply(null,e.subarray(n,n+t)));return btoa(r.join(""))}function xe(e){if(Uint8Array.fromBase64)return Uint8Array.fromBase64(e);let t=atob(e),r=new Uint8Array(t.length);for(let n=0;n<t.length;n++)r[n]=t.charCodeAt(n);return r}function W(e){if(Uint8Array.fromBase64)return Uint8Array.fromBase64(typeof e==="string"?e:C.decode(e),{alphabet:"base64url"});let t=e;if(t instanceof Uint8Array)t=C.decode(t);t=t.replace(/-/g,"+").replace(/_/g,"/");try{return xe(t)}catch{throw TypeError("The input to be decoded is not correctly encoded.")}}function y(e){let t=e;if(typeof t==="string")t=X.encode(t);if(Uint8Array.prototype.toBase64)return t.toBase64({alphabet:"base64url",omitPadding:!0});return de(t).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}var v=(e,t="algorithm.name")=>TypeError(`CryptoKey does not support this operation, its ${t} must be ${e}`),N=(e,t)=>e.name===t;function mr(e){return parseInt(e.name.slice(4),10)}function Pe(e,t){if(mr(e.hash)!==t)throw v(`SHA-${t}`,"algorithm.hash")}function yr(e){switch(e){case"ES256":return"P-256";case"ES384":return"P-384";case"ES512":return"P-521";default:throw Error("unreachable")}}function ut(e,t){if(t&&!e.usages.includes(t))throw TypeError(`CryptoKey does not support this operation, its usages must include ${t}.`)}function dt(e,t,r){switch(t){case"HS256":case"HS384":case"HS512":{if(!N(e.algorithm,"HMAC"))throw v("HMAC");Pe(e.algorithm,parseInt(t.slice(2),10));break}case"RS256":case"RS384":case"RS512":{if(!N(e.algorithm,"RSASSA-PKCS1-v1_5"))throw v("RSASSA-PKCS1-v1_5");Pe(e.algorithm,parseInt(t.slice(2),10));break}case"PS256":case"PS384":case"PS512":{if(!N(e.algorithm,"RSA-PSS"))throw v("RSA-PSS");Pe(e.algorithm,parseInt(t.slice(2),10));break}case"Ed25519":case"EdDSA":{if(!N(e.algorithm,"Ed25519"))throw v("Ed25519");break}case"ML-DSA-44":case"ML-DSA-65":case"ML-DSA-87":{if(!N(e.algorithm,t))throw v(t);break}case"ES256":case"ES384":case"ES512":{if(!N(e.algorithm,"ECDSA"))throw v("ECDSA");let n=yr(t);if(e.algorithm.namedCurve!==n)throw v(n,"algorithm.namedCurve");break}default:throw TypeError("CryptoKey does not support this operation")}ut(e,r)}function J(e,t,r){switch(t){case"A128GCM":case"A192GCM":case"A256GCM":{if(!N(e.algorithm,"AES-GCM"))throw v("AES-GCM");let n=parseInt(t.slice(1,4),10);if(e.algorithm.length!==n)throw v(n,"algorithm.length");break}case"A128KW":case"A192KW":case"A256KW":{if(!N(e.algorithm,"AES-KW"))throw v("AES-KW");let n=parseInt(t.slice(1,4),10);if(e.algorithm.length!==n)throw v(n,"algorithm.length");break}case"ECDH":{switch(e.algorithm.name){case"ECDH":case"X25519":break;default:throw v("ECDH or X25519")}break}case"PBES2-HS256+A128KW":case"PBES2-HS384+A192KW":case"PBES2-HS512+A256KW":if(!N(e.algorithm,"PBKDF2"))throw v("PBKDF2");break;case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":{if(!N(e.algorithm,"RSA-OAEP"))throw v("RSA-OAEP");Pe(e.algorithm,parseInt(t.slice(9),10)||1);break}default:throw TypeError("CryptoKey does not support this operation")}ut(e,r)}function ft(e,t,...r){if(r=r.filter(Boolean),r.length>2){let n=r.pop();e+=`one of type ${r.join(", ")}, or ${n}.`}else if(r.length===2)e+=`one of type ${r[0]} or ${r[1]}.`;else e+=`of type ${r[0]}.`;if(t==null)e+=` Received ${t}`;else if(typeof t==="function"&&t.name)e+=` Received function ${t.name}`;else if(typeof t==="object"&&t!=null){if(t.constructor?.name)e+=` Received an instance of ${t.constructor.name}`}return e}var D=(e,...t)=>ft("Key must be ",e,...t),ze=(e,t,...r)=>ft(`Key for the ${e} algorithm must be `,t,...r);var ht={};pt(ht,{JWTInvalid:()=>K,JWTExpired:()=>fe,JWTClaimValidationFailed:()=>H,JWSSignatureVerificationFailed:()=>ne,JWSInvalid:()=>h,JWKSTimeout:()=>Te,JWKSNoMatchingKey:()=>re,JWKSMultipleMatchingKeys:()=>He,JWKSInvalid:()=>he,JWKInvalid:()=>We,JWEInvalid:()=>c,JWEDecryptionFailed:()=>V,JOSENotSupported:()=>d,JOSEError:()=>x,JOSEAlgNotAllowed:()=>Y});class x extends Error{static code="ERR_JOSE_GENERIC";code="ERR_JOSE_GENERIC";constructor(e,t){super(e,t);this.name=this.constructor.name,Error.captureStackTrace?.(this,this.constructor)}}class H extends x{static code="ERR_JWT_CLAIM_VALIDATION_FAILED";code="ERR_JWT_CLAIM_VALIDATION_FAILED";claim;reason;payload;constructor(e,t,r="unspecified",n="unspecified"){super(e,{cause:{claim:r,reason:n,payload:t}});this.claim=r,this.reason=n,this.payload=t}}class fe extends x{static code="ERR_JWT_EXPIRED";code="ERR_JWT_EXPIRED";claim;reason;payload;constructor(e,t,r="unspecified",n="unspecified"){super(e,{cause:{claim:r,reason:n,payload:t}});this.claim=r,this.reason=n,this.payload=t}}class Y extends x{static code="ERR_JOSE_ALG_NOT_ALLOWED";code="ERR_JOSE_ALG_NOT_ALLOWED"}class d extends x{static code="ERR_JOSE_NOT_SUPPORTED";code="ERR_JOSE_NOT_SUPPORTED"}class V extends x{static code="ERR_JWE_DECRYPTION_FAILED";code="ERR_JWE_DECRYPTION_FAILED";constructor(e="decryption operation failed",t){super(e,t)}}class c extends x{static code="ERR_JWE_INVALID";code="ERR_JWE_INVALID"}class h extends x{static code="ERR_JWS_INVALID";code="ERR_JWS_INVALID"}class K extends x{static code="ERR_JWT_INVALID";code="ERR_JWT_INVALID"}class We extends x{static code="ERR_JWK_INVALID";code="ERR_JWK_INVALID"}class he extends x{static code="ERR_JWKS_INVALID";code="ERR_JWKS_INVALID"}class re extends x{static code="ERR_JWKS_NO_MATCHING_KEY";code="ERR_JWKS_NO_MATCHING_KEY";constructor(e="no applicable key found in the JSON Web Key Set",t){super(e,t)}}class He extends x{[Symbol.asyncIterator];static code="ERR_JWKS_MULTIPLE_MATCHING_KEYS";code="ERR_JWKS_MULTIPLE_MATCHING_KEYS";constructor(e="multiple matching keys found in the JSON Web Key Set",t){super(e,t)}}class Te extends x{static code="ERR_JWKS_TIMEOUT";code="ERR_JWKS_TIMEOUT";constructor(e="request timed out",t){super(e,t)}}class ne extends x{static code="ERR_JWS_SIGNATURE_VERIFICATION_FAILED";code="ERR_JWS_SIGNATURE_VERIFICATION_FAILED";constructor(e="signature verification failed",t){super(e,t)}}function ie(e){if(!M(e))throw Error("CryptoKey instance expected")}var M=(e)=>{if(e?.[Symbol.toStringTag]==="CryptoKey")return!0;try{return e instanceof CryptoKey}catch{return!1}},q=(e)=>e?.[Symbol.toStringTag]==="KeyObject",me=(e)=>M(e)||q(e);function Ie(e){switch(e){case"A128GCM":return 128;case"A192GCM":return 192;case"A256GCM":case"A128CBC-HS256":return 256;case"A192CBC-HS384":return 384;case"A256CBC-HS512":return 512;default:throw new d(`Unsupported JWE Algorithm: ${e}`)}}var _=(e)=>crypto.getRandomValues(new Uint8Array(Ie(e)>>3));function ve(e,t){let r=e.byteLength<<3;if(r!==t)throw new c(`Invalid Content Encryption Key length. Expected ${t} bits, got ${r} bits`)}function mt(e){switch(e){case"A128GCM":case"A128GCMKW":case"A192GCM":case"A192GCMKW":case"A256GCM":case"A256GCMKW":return 96;case"A128CBC-HS256":case"A192CBC-HS384":case"A256CBC-HS512":return 128;default:throw new d(`Unsupported JWE Algorithm: ${e}`)}}var lr=(e)=>crypto.getRandomValues(new Uint8Array(mt(e)>>3));function yt(e,t){if(t.length<<3!==mt(e))throw new c("Invalid Initialization Vector length")}async function lt(e,t,r){if(!(t instanceof Uint8Array))throw TypeError(D(t,"Uint8Array"));let n=parseInt(e.slice(1,4),10),i=await crypto.subtle.importKey("raw",t.subarray(n>>3),"AES-CBC",!1,[r]),a=await crypto.subtle.importKey("raw",t.subarray(0,n>>3),{hash:`SHA-${n<<1}`,name:"HMAC"},!1,["sign"]);return{encKey:i,macKey:a,keySize:n}}async function St(e,t,r){return new Uint8Array((await crypto.subtle.sign("HMAC",e,t)).slice(0,r>>3))}async function Sr(e,t,r,n,i){let{encKey:a,macKey:s,keySize:o}=await lt(e,r,"encrypt"),p=new Uint8Array(await crypto.subtle.encrypt({iv:n,name:"AES-CBC"},a,t)),u=g(i,n,p,Ve(i.length<<3)),f=await St(s,u,o);return{ciphertext:p,tag:f,iv:n}}async function wr(e,t){if(!(e instanceof Uint8Array))throw TypeError("First argument must be a buffer");if(!(t instanceof Uint8Array))throw TypeError("Second argument must be a buffer");let r={name:"HMAC",hash:"SHA-256"},n=await crypto.subtle.generateKey(r,!1,["sign"]),i=new Uint8Array(await crypto.subtle.sign(r,n,e)),a=new Uint8Array(await crypto.subtle.sign(r,n,t)),s=0,o=-1;while(++o<32)s|=i[o]^a[o];return s===0}async function Ar(e,t,r,n,i,a){let{encKey:s,macKey:o,keySize:p}=await lt(e,t,"decrypt"),u=g(a,n,r,Ve(a.length<<3)),f=await St(o,u,p),l;try{l=await wr(i,f)}catch{}if(!l)throw new V;let E;try{E=new Uint8Array(await crypto.subtle.decrypt({iv:n,name:"AES-CBC"},s,r))}catch{}if(!E)throw new V;return E}async function Er(e,t,r,n,i){let a;if(r instanceof Uint8Array)a=await crypto.subtle.importKey("raw",r,"AES-GCM",!1,["encrypt"]);else J(r,e,"encrypt"),a=r;let s=new Uint8Array(await crypto.subtle.encrypt({additionalData:i,iv:n,name:"AES-GCM",tagLength:128},a,t)),o=s.slice(-16);return{ciphertext:s.slice(0,-16),tag:o,iv:n}}async function br(e,t,r,n,i,a){let s;if(t instanceof Uint8Array)s=await crypto.subtle.importKey("raw",t,"AES-GCM",!1,["decrypt"]);else J(t,e,"decrypt"),s=t;try{return new Uint8Array(await crypto.subtle.decrypt({additionalData:a,iv:n,name:"AES-GCM",tagLength:128},s,g(r,i)))}catch{throw new V}}var wt="Unsupported JWE Content Encryption Algorithm";async function Je(e,t,r,n,i){if(!M(r)&&!(r instanceof Uint8Array))throw TypeError(D(r,"CryptoKey","KeyObject","Uint8Array","JSON Web Key"));if(n)yt(e,n);else n=lr(e);switch(e){case"A128CBC-HS256":case"A192CBC-HS384":case"A256CBC-HS512":if(r instanceof Uint8Array)ve(r,parseInt(e.slice(-3),10));return Sr(e,t,r,n,i);case"A128GCM":case"A192GCM":case"A256GCM":if(r instanceof Uint8Array)ve(r,parseInt(e.slice(1,4),10));return Er(e,t,r,n,i);default:throw new d(wt)}}async function Re(e,t,r,n,i,a){if(!M(t)&&!(t instanceof Uint8Array))throw TypeError(D(t,"CryptoKey","KeyObject","Uint8Array","JSON Web Key"));if(!n)throw new c("JWE Initialization Vector missing");if(!i)throw new c("JWE Authentication Tag missing");switch(yt(e,n),e){case"A128CBC-HS256":case"A192CBC-HS384":case"A256CBC-HS512":if(t instanceof Uint8Array)ve(t,parseInt(e.slice(-3),10));return Ar(e,t,r,n,i,a);case"A128GCM":case"A192GCM":case"A256GCM":if(t instanceof Uint8Array)ve(t,parseInt(e.slice(1,4),10));return br(e,t,r,n,i,a);default:throw new d(wt)}}var De=Symbol();function S(e,t){if(e)throw TypeError(`${t} can only be called once`)}function I(e,t,r){try{return W(e)}catch{throw new r(`Failed to base64url decode the ${t}`)}}async function Ue(e,t){let r=`SHA-${e.slice(-3)}`;return new Uint8Array(await crypto.subtle.digest(r,t))}var gr=(e)=>typeof e==="object"&&e!==null;function m(e){if(!gr(e)||Object.prototype.toString.call(e)!=="[object Object]")return!1;if(Object.getPrototypeOf(e)===null)return!0;let t=e;while(Object.getPrototypeOf(t)!==null)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t}function L(...e){let t=e.filter(Boolean);if(t.length===0||t.length===1)return!0;let r;for(let n of t){let i=Object.keys(n);if(!r||r.size===0){r=new Set(i);continue}for(let a of i){if(r.has(a))return!1;r.add(a)}}return!0}var Q=(e)=>m(e)&&typeof e.kty==="string",At=(e)=>e.kty!=="oct"&&(e.kty==="AKP"&&typeof e.priv==="string"||typeof e.d==="string"),Et=(e)=>e.kty!=="oct"&&e.d===void 0&&e.priv===void 0,bt=(e)=>e.kty==="oct"&&typeof e.k==="string";function gt(e,t){if(e.algorithm.length!==parseInt(t.slice(1,4),10))throw TypeError(`Invalid key size for alg: ${t}`)}function Kt(e,t,r){if(e instanceof Uint8Array)return crypto.subtle.importKey("raw",e,"AES-KW",!0,[r]);return J(e,t,r),e}async function ye(e,t,r){let n=await Kt(t,e,"wrapKey");gt(n,e);let i=await crypto.subtle.importKey("raw",r,{hash:"SHA-256",name:"HMAC"},!0,["sign"]);return new Uint8Array(await crypto.subtle.wrapKey("raw",i,n,"AES-KW"))}async function le(e,t,r){let n=await Kt(t,e,"unwrapKey");gt(n,e);let i=await crypto.subtle.unwrapKey("raw",r,n,"AES-KW",{hash:"SHA-256",name:"HMAC"},!0,["sign"]);return new Uint8Array(await crypto.subtle.exportKey("raw",i))}function Xe(e){return g(Ce(e.length),e)}async function Cr(e,t,r){let n=t>>3,i=32,a=Math.ceil(n/32),s=new Uint8Array(a*32);for(let o=1;o<=a;o++){let p=new Uint8Array(4+e.length+r.length);p.set(Ce(o),0),p.set(e,4),p.set(r,4+e.length);let u=await Ue("sha256",p);s.set(u,(o-1)*32)}return s.slice(0,n)}async function Ye(e,t,r,n,i=new Uint8Array,a=new Uint8Array){J(e,"ECDH"),J(t,"ECDH","deriveBits");let s=Xe(w(r)),o=Xe(i),p=Xe(a),u=Ce(n),f=new Uint8Array,l=g(s,o,p,u,f),E=new Uint8Array(await crypto.subtle.deriveBits({name:e.algorithm.name,public:e},t,xr(e)));return Cr(E,n,l)}function xr(e){if(e.algorithm.name==="X25519")return 256;return Math.ceil(parseInt(e.algorithm.namedCurve.slice(-3),10)/8)<<3}function qe(e){switch(e.algorithm.namedCurve){case"P-256":case"P-384":case"P-521":return!0;default:return e.algorithm.name==="X25519"}}function Wr(e,t){if(e instanceof Uint8Array)return crypto.subtle.importKey("raw",e,"PBKDF2",!1,["deriveBits"]);return J(e,t,"deriveBits"),e}var Hr=(e,t)=>g(w(e),Uint8Array.of(0),t);async function xt(e,t,r,n){if(!(e instanceof Uint8Array)||e.length<8)throw new c("PBES2 Salt Input must be 8 or more octets");if(!Number.isSafeInteger(r)||Math.sign(r)!==1)throw new c("PBES2 Count Input must be a positive integer");let i=Hr(t,e),a=parseInt(t.slice(13,16),10),s={hash:`SHA-${t.slice(8,11)}`,iterations:r,name:"PBKDF2",salt:i},o=await Wr(n,t);return new Uint8Array(await crypto.subtle.deriveBits(s,o,a))}async function Pt(e,t,r,n=2048,i=crypto.getRandomValues(new Uint8Array(16))){let a=await xt(i,e,n,t);return{encryptedKey:await ye(e.slice(-6),a,r),p2c:n,p2s:y(i)}}async function Wt(e,t,r,n,i){let a=await xt(i,e,n,t);return le(e.slice(-6),a,r)}function Se(e,t){if(e.startsWith("RS")||e.startsWith("PS")){let{modulusLength:r}=t.algorithm;if(typeof r!=="number"||r<2048)throw TypeError(`${e} requires key modulusLength to be 2048 bits or larger`)}}function Ht(e,t){let r=`SHA-${e.slice(-3)}`;switch(e){case"HS256":case"HS384":case"HS512":return{hash:r,name:"HMAC"};case"PS256":case"PS384":case"PS512":return{hash:r,name:"RSA-PSS",saltLength:parseInt(e.slice(-3),10)>>3};case"RS256":case"RS384":case"RS512":return{hash:r,name:"RSASSA-PKCS1-v1_5"};case"ES256":case"ES384":case"ES512":return{hash:r,name:"ECDSA",namedCurve:t.namedCurve};case"Ed25519":case"EdDSA":return{name:"Ed25519"};case"ML-DSA-44":case"ML-DSA-65":case"ML-DSA-87":return{name:e};default:throw new d(`alg ${e} is not supported either by JOSE or your javascript runtime`)}}async function Tt(e,t,r){if(t instanceof Uint8Array){if(!e.startsWith("HS"))throw TypeError(D(t,"CryptoKey","KeyObject","JSON Web Key"));return crypto.subtle.importKey("raw",t,{hash:`SHA-${e.slice(-3)}`,name:"HMAC"},!1,[r])}return dt(t,e,r),t}async function vt(e,t,r){let n=await Tt(e,t,"sign");Se(e,n);let i=await crypto.subtle.sign(Ht(e,n.algorithm),n,r);return new Uint8Array(i)}async function It(e,t,r,n){let i=await Tt(e,t,"verify");Se(e,i);let a=Ht(e,i.algorithm);try{return await crypto.subtle.verify(a,i,r,n)}catch{return!1}}var Jt=(e)=>{switch(e){case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":return"RSA-OAEP";default:throw new d(`alg ${e} is not supported either by JOSE or your javascript runtime`)}};async function Rt(e,t,r){return J(t,e,"encrypt"),Se(e,t),new Uint8Array(await crypto.subtle.encrypt(Jt(e),t,r))}async function Dt(e,t,r){return J(t,e,"decrypt"),Se(e,t),new Uint8Array(await crypto.subtle.decrypt(Jt(e),t,r))}var Me='Invalid or unsupported JWK "alg" (Algorithm) Parameter value';function Ir(e){let t,r;switch(e.kty){case"AKP":{switch(e.alg){case"ML-DSA-44":case"ML-DSA-65":case"ML-DSA-87":t={name:e.alg},r=e.priv?["sign"]:["verify"];break;default:throw new d(Me)}break}case"RSA":{switch(e.alg){case"PS256":case"PS384":case"PS512":t={name:"RSA-PSS",hash:`SHA-${e.alg.slice(-3)}`},r=e.d?["sign"]:["verify"];break;case"RS256":case"RS384":case"RS512":t={name:"RSASSA-PKCS1-v1_5",hash:`SHA-${e.alg.slice(-3)}`},r=e.d?["sign"]:["verify"];break;case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":t={name:"RSA-OAEP",hash:`SHA-${parseInt(e.alg.slice(-3),10)||1}`},r=e.d?["decrypt","unwrapKey"]:["encrypt","wrapKey"];break;default:throw new d(Me)}break}case"EC":{switch(e.alg){case"ES256":case"ES384":case"ES512":t={name:"ECDSA",namedCurve:{ES256:"P-256",ES384:"P-384",ES512:"P-521"}[e.alg]},r=e.d?["sign"]:["verify"];break;case"ECDH-ES":case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":t={name:"ECDH",namedCurve:e.crv},r=e.d?["deriveBits"]:[];break;default:throw new d(Me)}break}case"OKP":{switch(e.alg){case"Ed25519":case"EdDSA":t={name:"Ed25519"},r=e.d?["sign"]:["verify"];break;case"ECDH-ES":case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":t={name:e.crv},r=e.d?["deriveBits"]:[];break;default:throw new d(Me)}break}default:throw new d('Invalid or unsupported JWK "kty" (Key Type) Parameter value')}return{algorithm:t,keyUsages:r}}async function ae(e){if(!e.alg)throw TypeError('"alg" argument is required when "jwk.alg" is not present');let{algorithm:t,keyUsages:r}=Ir(e),n={...e};if(n.kty!=="AKP")delete n.alg;return delete n.use,crypto.subtle.importKey("jwk",n,t,e.ext??(e.d||e.priv?!1:!0),e.key_ops??r)}var se="given KeyObject instance cannot be used for this algorithm",oe,Ut=async(e,t,r,n=!1)=>{oe||=new WeakMap;let i=oe.get(e);if(i?.[r])return i[r];let a=await ae({...t,alg:r});if(n)Object.freeze(e);if(!i)oe.set(e,{[r]:a});else i[r]=a;return a},Jr=(e,t)=>{oe||=new WeakMap;let r=oe.get(e);if(r?.[t])return r[t];let n=e.type==="public",i=n?!0:!1,a;if(e.asymmetricKeyType==="x25519"){switch(t){case"ECDH-ES":case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":break;default:throw TypeError(se)}a=e.toCryptoKey(e.asymmetricKeyType,i,n?[]:["deriveBits"])}if(e.asymmetricKeyType==="ed25519"){if(t!=="EdDSA"&&t!=="Ed25519")throw TypeError(se);a=e.toCryptoKey(e.asymmetricKeyType,i,[n?"verify":"sign"])}switch(e.asymmetricKeyType){case"ml-dsa-44":case"ml-dsa-65":case"ml-dsa-87":{if(t!==e.asymmetricKeyType.toUpperCase())throw TypeError(se);a=e.toCryptoKey(e.asymmetricKeyType,i,[n?"verify":"sign"])}}if(e.asymmetricKeyType==="rsa"){let s;switch(t){case"RSA-OAEP":s="SHA-1";break;case"RS256":case"PS256":case"RSA-OAEP-256":s="SHA-256";break;case"RS384":case"PS384":case"RSA-OAEP-384":s="SHA-384";break;case"RS512":case"PS512":case"RSA-OAEP-512":s="SHA-512";break;default:throw TypeError(se)}if(t.startsWith("RSA-OAEP"))return e.toCryptoKey({name:"RSA-OAEP",hash:s},i,n?["encrypt"]:["decrypt"]);a=e.toCryptoKey({name:t.startsWith("PS")?"RSA-PSS":"RSASSA-PKCS1-v1_5",hash:s},i,[n?"verify":"sign"])}if(e.asymmetricKeyType==="ec"){let o=new Map([["prime256v1","P-256"],["secp384r1","P-384"],["secp521r1","P-521"]]).get(e.asymmetricKeyDetails?.namedCurve);if(!o)throw TypeError(se);let p={ES256:"P-256",ES384:"P-384",ES512:"P-521"};if(p[t]&&o===p[t])a=e.toCryptoKey({name:"ECDSA",namedCurve:o},i,[n?"verify":"sign"]);if(t.startsWith("ECDH-ES"))a=e.toCryptoKey({name:"ECDH",namedCurve:o},i,n?[]:["deriveBits"])}if(!a)throw TypeError(se);if(!r)oe.set(e,{[t]:a});else r[t]=a;return a};async function U(e,t){if(e instanceof Uint8Array)return e;if(M(e))return e;if(q(e)){if(e.type==="secret")return e.export();if("toCryptoKey"in e&&typeof e.toCryptoKey==="function")try{return Jr(e,t)}catch(n){if(n instanceof TypeError)throw n}let r=e.export({format:"jwk"});return Ut(e,r,t)}if(Q(e)){if(e.k)return W(e.k);return Ut(e,e,t,!0)}throw Error("unreachable")}var Mt=(e,t)=>{let r=(e.match(/.{1,64}/g)||[]).join(`
3
- `);return`-----BEGIN ${t}-----
4
- ${r}
5
- -----END ${t}-----`},Ot=async(e,t,r)=>{if(q(r)){if(r.type!==e)throw TypeError(`key is not a ${e} key`);return r.export({format:"pem",type:t})}if(!M(r))throw TypeError(D(r,"CryptoKey","KeyObject"));if(!r.extractable)throw TypeError("CryptoKey is not extractable");if(r.type!==e)throw TypeError(`key is not a ${e} key`);return Mt(de(new Uint8Array(await crypto.subtle.exportKey(t,r))),`${e.toUpperCase()} KEY`)},Nt=(e)=>Ot("public","spki",e),_t=(e)=>Ot("private","pkcs8",e),Qe=(e,t)=>{if(e.byteLength!==t.length)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0},je=(e)=>({data:e,pos:0}),O=(e)=>{let t=e.data[e.pos++];if(t&128){let r=t&127,n=0;for(let i=0;i<r;i++)n=n<<8|e.data[e.pos++];return n}return t},Ze=(e,t=1)=>{if(t<=0)return;e.pos++;let r=O(e);if(e.pos+=r,t>1)Ze(e,t-1)},B=(e,t,r)=>{if(e.data[e.pos++]!==t)throw Error(r)},Lt=(e,t)=>{let r=e.data.subarray(e.pos,e.pos+t);return e.pos+=t,r},Rr=(e)=>{B(e,6,"Expected algorithm OID");let t=O(e);return Lt(e,t)};function Dr(e){B(e,48,"Invalid PKCS#8 structure"),O(e),B(e,2,"Expected version field");let t=O(e);e.pos+=t,B(e,48,"Expected algorithm identifier");let r=O(e);return{algIdStart:e.pos,algIdLength:r}}function Ur(e){B(e,48,"Invalid SPKI structure"),O(e),B(e,48,"Expected algorithm identifier");let t=O(e);return{algIdStart:e.pos,algIdLength:t}}var Bt=(e)=>{let t=Rr(e);if(Qe(t,[43,101,110]))return"X25519";if(!Qe(t,[42,134,72,206,61,2,1]))throw Error("Unsupported key algorithm");B(e,6,"Expected curve OID");let r=O(e),n=Lt(e,r);for(let{name:i,oid:a}of[{name:"P-256",oid:[42,134,72,206,61,3,1,7]},{name:"P-384",oid:[43,129,4,0,34]},{name:"P-521",oid:[43,129,4,0,35]}])if(Qe(n,a))return i;throw Error("Unsupported named curve")},kt=async(e,t,r,n)=>{let i,a,s=e==="spki",o=()=>s?["verify"]:["sign"],p=()=>s?["encrypt","wrapKey"]:["decrypt","unwrapKey"];switch(r){case"PS256":case"PS384":case"PS512":i={name:"RSA-PSS",hash:`SHA-${r.slice(-3)}`},a=o();break;case"RS256":case"RS384":case"RS512":i={name:"RSASSA-PKCS1-v1_5",hash:`SHA-${r.slice(-3)}`},a=o();break;case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":i={name:"RSA-OAEP",hash:`SHA-${parseInt(r.slice(-3),10)||1}`},a=p();break;case"ES256":case"ES384":case"ES512":{i={name:"ECDSA",namedCurve:{ES256:"P-256",ES384:"P-384",ES512:"P-521"}[r]},a=o();break}case"ECDH-ES":case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":{try{let u=n.getNamedCurve(t);i=u==="X25519"?{name:"X25519"}:{name:"ECDH",namedCurve:u}}catch(u){throw new d("Invalid or unsupported key format")}a=s?[]:["deriveBits"];break}case"Ed25519":case"EdDSA":i={name:"Ed25519"},a=o();break;case"ML-DSA-44":case"ML-DSA-65":case"ML-DSA-87":i={name:r},a=o();break;default:throw new d('Invalid or unsupported "alg" (Algorithm) value')}return crypto.subtle.importKey(e,t,i,n?.extractable??(s?!0:!1),a)},et=(e,t)=>{return xe(e.replace(t,""))},$t=(e,t,r)=>{let n=et(e,/(?:-----(?:BEGIN|END) PRIVATE KEY-----|\s)/g),i=r;if(t?.startsWith?.("ECDH-ES"))i||={},i.getNamedCurve=(a)=>{let s=je(a);return Dr(s),Bt(s)};return kt("pkcs8",n,t,i)},tt=(e,t,r)=>{let n=et(e,/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g),i=r;if(t?.startsWith?.("ECDH-ES"))i||={},i.getNamedCurve=(a)=>{let s=je(a);return Ur(s),Bt(s)};return kt("spki",n,t,i)};function Mr(e){let t=je(e);if(B(t,48,"Invalid certificate structure"),O(t),B(t,48,"Invalid tbsCertificate structure"),O(t),e[t.pos]===160)Ze(t,6);else Ze(t,5);let r=t.pos;B(t,48,"Invalid SPKI structure");let n=O(t);return e.subarray(r,r+n+(t.pos-r))}function Or(e){let t=et(e,/(?:-----(?:BEGIN|END) CERTIFICATE-----|\s)/g);return Mr(t)}var Gt=(e,t,r)=>{let n;try{n=Or(e)}catch(i){throw TypeError("Failed to parse the X.509 certificate",{cause:i})}return tt(Mt(de(n),"PUBLIC KEY"),t,r)};async function Nr(e,t,r){if(typeof e!=="string"||e.indexOf("-----BEGIN PUBLIC KEY-----")!==0)throw TypeError('"spki" must be SPKI formatted string');return tt(e,t,r)}async function _r(e,t,r){if(typeof e!=="string"||e.indexOf("-----BEGIN CERTIFICATE-----")!==0)throw TypeError('"x509" must be X.509 formatted string');return Gt(e,t,r)}async function Lr(e,t,r){if(typeof e!=="string"||e.indexOf("-----BEGIN PRIVATE KEY-----")!==0)throw TypeError('"pkcs8" must be PKCS#8 formatted string');return $t(e,t,r)}async function Z(e,t,r){if(!m(e))throw TypeError("JWK must be an object");let n;switch(t??=e.alg,n??=r?.extractable??e.ext,e.kty){case"oct":if(typeof e.k!=="string"||!e.k)throw TypeError('missing "k" (Key Value) Parameter value');return W(e.k);case"RSA":if("oth"in e&&e.oth!==void 0)throw new d('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');return ae({...e,alg:t,ext:n});case"AKP":{if(typeof e.alg!=="string"||!e.alg)throw TypeError('missing "alg" (Algorithm) Parameter value');if(t!==void 0&&t!==e.alg)throw TypeError("JWK alg and alg option value mismatch");return ae({...e,ext:n})}case"EC":case"OKP":return ae({...e,alg:t,ext:n});default:throw new d('Unsupported "kty" (Key Type) Parameter value')}}async function Vt(e){if(q(e))if(e.type==="secret")e=e.export();else return e.export({format:"jwk"});if(e instanceof Uint8Array)return{kty:"oct",k:y(e)};if(!M(e))throw TypeError(D(e,"CryptoKey","KeyObject","Uint8Array"));if(!e.extractable)throw TypeError("non-extractable CryptoKey cannot be exported as a JWK");let{ext:t,key_ops:r,alg:n,use:i,...a}=await crypto.subtle.exportKey("jwk",e);if(a.kty==="AKP")a.alg=n;return a}async function Br(e){return Nt(e)}async function kr(e){return _t(e)}async function we(e){return Vt(e)}async function Ft(e,t,r,n){let i=e.slice(0,7),a=await Je(i,r,t,n,new Uint8Array);return{encryptedKey:a.ciphertext,iv:y(a.iv),tag:y(a.tag)}}async function zt(e,t,r,n,i){let a=e.slice(0,7);return Re(a,t,r,n,i,new Uint8Array)}var Xt='Invalid or unsupported "alg" (JWE Algorithm) header value';function Ae(e){if(e===void 0)throw new c("JWE Encrypted Key missing")}async function Yt(e,t,r,n,i){switch(e){case"dir":{if(r!==void 0)throw new c("Encountered unexpected JWE Encrypted Key");return t}case"ECDH-ES":if(r!==void 0)throw new c("Encountered unexpected JWE Encrypted Key");case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":{if(!m(n.epk))throw new c('JOSE Header "epk" (Ephemeral Public Key) missing or invalid');if(ie(t),!qe(t))throw new d("ECDH with the provided key is not allowed or not supported by your javascript runtime");let a=await Z(n.epk,e);ie(a);let s,o;if(n.apu!==void 0){if(typeof n.apu!=="string")throw new c('JOSE Header "apu" (Agreement PartyUInfo) invalid');s=I(n.apu,"apu",c)}if(n.apv!==void 0){if(typeof n.apv!=="string")throw new c('JOSE Header "apv" (Agreement PartyVInfo) invalid');o=I(n.apv,"apv",c)}let p=await Ye(a,t,e==="ECDH-ES"?n.enc:e,e==="ECDH-ES"?Ie(n.enc):parseInt(e.slice(-5,-2),10),s,o);if(e==="ECDH-ES")return p;return Ae(r),le(e.slice(-6),p,r)}case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":return Ae(r),ie(t),Dt(e,t,r);case"PBES2-HS256+A128KW":case"PBES2-HS384+A192KW":case"PBES2-HS512+A256KW":{if(Ae(r),typeof n.p2c!=="number")throw new c('JOSE Header "p2c" (PBES2 Count) missing or invalid');let a=i?.maxPBES2Count||1e4;if(n.p2c>a)throw new c('JOSE Header "p2c" (PBES2 Count) out is of acceptable bounds');if(typeof n.p2s!=="string")throw new c('JOSE Header "p2s" (PBES2 Salt) missing or invalid');let s;return s=I(n.p2s,"p2s",c),Wt(e,t,r,n.p2c,s)}case"A128KW":case"A192KW":case"A256KW":return Ae(r),le(e,t,r);case"A128GCMKW":case"A192GCMKW":case"A256GCMKW":{if(Ae(r),typeof n.iv!=="string")throw new c('JOSE Header "iv" (Initialization Vector) missing or invalid');if(typeof n.tag!=="string")throw new c('JOSE Header "tag" (Authentication Tag) missing or invalid');let a;a=I(n.iv,"iv",c);let s;return s=I(n.tag,"tag",c),zt(e,t,r,a,s)}default:throw new d(Xt)}}async function Oe(e,t,r,n,i={}){let a,s,o;switch(e){case"dir":{o=r;break}case"ECDH-ES":case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":{if(ie(r),!qe(r))throw new d("ECDH with the provided key is not allowed or not supported by your javascript runtime");let{apu:p,apv:u}=i,f;if(i.epk)f=await U(i.epk,e);else f=(await crypto.subtle.generateKey(r.algorithm,!0,["deriveBits"])).privateKey;let{x:l,y:E,crv:T,kty:b}=await we(f),A=await Ye(r,f,e==="ECDH-ES"?t:e,e==="ECDH-ES"?Ie(t):parseInt(e.slice(-5,-2),10),p,u);if(s={epk:{x:l,crv:T,kty:b}},b==="EC")s.epk.y=E;if(p)s.apu=y(p);if(u)s.apv=y(u);if(e==="ECDH-ES"){o=A;break}o=n||_(t);let P=e.slice(-6);a=await ye(P,A,o);break}case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":{o=n||_(t),ie(r),a=await Rt(e,r,o);break}case"PBES2-HS256+A128KW":case"PBES2-HS384+A192KW":case"PBES2-HS512+A256KW":{o=n||_(t);let{p2c:p,p2s:u}=i;({encryptedKey:a,...s}=await Pt(e,r,o,p,u));break}case"A128KW":case"A192KW":case"A256KW":{o=n||_(t),a=await ye(e,r,o);break}case"A128GCMKW":case"A192GCMKW":case"A256GCMKW":{o=n||_(t);let{iv:p}=i;({encryptedKey:a,...s}=await Ft(e,r,o,p));break}default:throw new d(Xt)}return{cek:o,encryptedKey:a,parameters:s}}function k(e,t,r,n,i){if(i.crit!==void 0&&n?.crit===void 0)throw new e('"crit" (Critical) Header Parameter MUST be integrity protected');if(!n||n.crit===void 0)return new Set;if(!Array.isArray(n.crit)||n.crit.length===0||n.crit.some((s)=>typeof s!=="string"||s.length===0))throw new e('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');let a;if(r!==void 0)a=new Map([...Object.entries(r),...t.entries()]);else a=t;for(let s of n.crit){if(!a.has(s))throw new d(`Extension Header Parameter "${s}" is not recognized`);if(i[s]===void 0)throw new e(`Extension Header Parameter "${s}" is missing`);if(a.get(s)&&n[s]===void 0)throw new e(`Extension Header Parameter "${s}" MUST be integrity protected`)}return new Set(n.crit)}function Ee(e,t){if(t!==void 0&&(!Array.isArray(t)||t.some((r)=>typeof r!=="string")))throw TypeError(`"${e}" option must be an array of strings`);if(!t)return;return new Set(t)}var ce=(e)=>e?.[Symbol.toStringTag],rt=(e,t,r)=>{if(t.use!==void 0){let n;switch(r){case"sign":case"verify":n="sig";break;case"encrypt":case"decrypt":n="enc";break}if(t.use!==n)throw TypeError(`Invalid key for this operation, its "use" must be "${n}" when present`)}if(t.alg!==void 0&&t.alg!==e)throw TypeError(`Invalid key for this operation, its "alg" must be "${e}" when present`);if(Array.isArray(t.key_ops)){let n;switch(!0){case(r==="sign"||r==="verify"):case e==="dir":case e.includes("CBC-HS"):n=r;break;case e.startsWith("PBES2"):n="deriveBits";break;case/^A\d{3}(?:GCM)?(?:KW)?$/.test(e):if(!e.includes("GCM")&&e.endsWith("KW"))n=r==="encrypt"?"wrapKey":"unwrapKey";else n=r;break;case(r==="encrypt"&&e.startsWith("RSA")):n="wrapKey";break;case r==="decrypt":n=e.startsWith("RSA")?"unwrapKey":"deriveBits";break}if(n&&t.key_ops?.includes?.(n)===!1)throw TypeError(`Invalid key for this operation, its "key_ops" must include "${n}" when present`)}return!0},$r=(e,t,r)=>{if(t instanceof Uint8Array)return;if(Q(t)){if(bt(t)&&rt(e,t,r))return;throw TypeError('JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present')}if(!me(t))throw TypeError(ze(e,t,"CryptoKey","KeyObject","JSON Web Key","Uint8Array"));if(t.type!=="secret")throw TypeError(`${ce(t)} instances for symmetric algorithms must be of type "secret"`)},Gr=(e,t,r)=>{if(Q(t))switch(r){case"decrypt":case"sign":if(At(t)&&rt(e,t,r))return;throw TypeError("JSON Web Key for this operation must be a private JWK");case"encrypt":case"verify":if(Et(t)&&rt(e,t,r))return;throw TypeError("JSON Web Key for this operation must be a public JWK")}if(!me(t))throw TypeError(ze(e,t,"CryptoKey","KeyObject","JSON Web Key"));if(t.type==="secret")throw TypeError(`${ce(t)} instances for asymmetric algorithms must not be of type "secret"`);if(t.type==="public")switch(r){case"sign":throw TypeError(`${ce(t)} instances for asymmetric algorithm signing must be of type "private"`);case"decrypt":throw TypeError(`${ce(t)} instances for asymmetric algorithm decryption must be of type "private"`)}if(t.type==="private")switch(r){case"verify":throw TypeError(`${ce(t)} instances for asymmetric algorithm verifying must be of type "public"`);case"encrypt":throw TypeError(`${ce(t)} instances for asymmetric algorithm encryption must be of type "public"`)}};function $(e,t,r){switch(e.substring(0,2)){case"A1":case"A2":case"di":case"HS":case"PB":$r(e,t,r);break;default:Gr(e,t,r)}}function qt(e){if(typeof globalThis[e]>"u")throw new d(`JWE "zip" (Compression Algorithm) Header Parameter requires the ${e} API.`)}async function Qt(e){qt("CompressionStream");let t=new CompressionStream("deflate-raw"),r=t.writable.getWriter();r.write(e).catch(()=>{}),r.close().catch(()=>{});let n=[],i=t.readable.getReader();for(;;){let{value:a,done:s}=await i.read();if(s)break;n.push(a)}return g(...n)}async function Zt(e,t){qt("DecompressionStream");let r=new DecompressionStream("deflate-raw"),n=r.writable.getWriter();n.write(e).catch(()=>{}),n.close().catch(()=>{});let i=[],a=0,s=r.readable.getReader();for(;;){let{value:o,done:p}=await s.read();if(p)break;if(i.push(o),a+=o.byteLength,t!==1/0&&a>t)throw new c("Decompressed plaintext exceeded the configured limit")}return g(...i)}async function be(e,t,r){if(!m(e))throw new c("Flattened JWE must be an object");if(e.protected===void 0&&e.header===void 0&&e.unprotected===void 0)throw new c("JOSE Header missing");if(e.iv!==void 0&&typeof e.iv!=="string")throw new c("JWE Initialization Vector incorrect type");if(typeof e.ciphertext!=="string")throw new c("JWE Ciphertext missing or incorrect type");if(e.tag!==void 0&&typeof e.tag!=="string")throw new c("JWE Authentication Tag incorrect type");if(e.protected!==void 0&&typeof e.protected!=="string")throw new c("JWE Protected Header incorrect type");if(e.encrypted_key!==void 0&&typeof e.encrypted_key!=="string")throw new c("JWE Encrypted Key incorrect type");if(e.aad!==void 0&&typeof e.aad!=="string")throw new c("JWE AAD incorrect type");if(e.header!==void 0&&!m(e.header))throw new c("JWE Shared Unprotected Header incorrect type");if(e.unprotected!==void 0&&!m(e.unprotected))throw new c("JWE Per-Recipient Unprotected Header incorrect type");let n;if(e.protected)try{let R=W(e.protected);n=JSON.parse(C.decode(R))}catch{throw new c("JWE Protected Header is invalid")}if(!L(n,e.header,e.unprotected))throw new c("JWE Protected, JWE Unprotected Header, and JWE Per-Recipient Unprotected Header Parameter names must be disjoint");let i={...n,...e.header,...e.unprotected};if(k(c,new Map,r?.crit,n,i),i.zip!==void 0&&i.zip!=="DEF")throw new d('Unsupported JWE "zip" (Compression Algorithm) Header Parameter value.');if(i.zip!==void 0&&!n?.zip)throw new c('JWE "zip" (Compression Algorithm) Header Parameter MUST be in a protected header.');let{alg:a,enc:s}=i;if(typeof a!=="string"||!a)throw new c("missing JWE Algorithm (alg) in JWE Header");if(typeof s!=="string"||!s)throw new c("missing JWE Encryption Algorithm (enc) in JWE Header");let o=r&&Ee("keyManagementAlgorithms",r.keyManagementAlgorithms),p=r&&Ee("contentEncryptionAlgorithms",r.contentEncryptionAlgorithms);if(o&&!o.has(a)||!o&&a.startsWith("PBES2"))throw new Y('"alg" (Algorithm) Header Parameter value not allowed');if(p&&!p.has(s))throw new Y('"enc" (Encryption Algorithm) Header Parameter value not allowed');let u;if(e.encrypted_key!==void 0)u=I(e.encrypted_key,"encrypted_key",c);let f=!1;if(typeof t==="function")t=await t(n,e),f=!0;$(a==="dir"?s:a,t,"decrypt");let l=await U(t,a),E;try{E=await Yt(a,l,u,i,r)}catch(R){if(R instanceof TypeError||R instanceof c||R instanceof d)throw R;E=_(s)}let T,b;if(e.iv!==void 0)T=I(e.iv,"iv",c);if(e.tag!==void 0)b=I(e.tag,"tag",c);let A=e.protected!==void 0?w(e.protected):new Uint8Array,P;if(e.aad!==void 0)P=g(A,w("."),w(e.aad));else P=A;let ke=I(e.ciphertext,"ciphertext",c),ct=await Re(s,E,ke,T,b,P),z={plaintext:ct};if(i.zip==="DEF"){let R=r?.maxDecompressedLength??250000;if(R===0)throw new d('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');if(R!==1/0&&(!Number.isSafeInteger(R)||R<1))throw TypeError("maxDecompressedLength must be 0, a positive safe integer, or Infinity");z.plaintext=await Zt(ct,R).catch(($e)=>{if($e instanceof c)throw $e;throw new c("Failed to decompress plaintext",{cause:$e})})}if(e.protected!==void 0)z.protectedHeader=n;if(e.aad!==void 0)z.additionalAuthenticatedData=I(e.aad,"aad",c);if(e.unprotected!==void 0)z.sharedUnprotectedHeader=e.unprotected;if(e.header!==void 0)z.unprotectedHeader=e.header;if(f)return{...z,key:l};return z}async function nt(e,t,r){if(e instanceof Uint8Array)e=C.decode(e);if(typeof e!=="string")throw new c("Compact JWE must be a string or Uint8Array");let{0:n,1:i,2:a,3:s,4:o,length:p}=e.split(".");if(p!==5)throw new c("Invalid Compact JWE");let u=await be({ciphertext:s,iv:a||void 0,protected:n,tag:o||void 0,encrypted_key:i||void 0},t,r),f={plaintext:u.plaintext,protectedHeader:u.protectedHeader};if(typeof t==="function")return{...f,key:u.key};return f}async function Vr(e,t,r){if(!m(e))throw new c("General JWE must be an object");if(!Array.isArray(e.recipients)||!e.recipients.every(m))throw new c("JWE Recipients missing or incorrect type");if(!e.recipients.length)throw new c("JWE Recipients has no members");for(let n of e.recipients)try{return await be({aad:e.aad,ciphertext:e.ciphertext,encrypted_key:n.encrypted_key,header:n.header,iv:e.iv,protected:e.protected,tag:e.tag,unprotected:e.unprotected},t,r)}catch{}throw new V}class j{#e;#t;#r;#n;#a;#s;#o;#i;constructor(e){if(!(e instanceof Uint8Array))throw TypeError("plaintext must be an instance of Uint8Array");this.#e=e}setKeyManagementParameters(e){return S(this.#i,"setKeyManagementParameters"),this.#i=e,this}setProtectedHeader(e){return S(this.#t,"setProtectedHeader"),this.#t=e,this}setSharedUnprotectedHeader(e){return S(this.#r,"setSharedUnprotectedHeader"),this.#r=e,this}setUnprotectedHeader(e){return S(this.#n,"setUnprotectedHeader"),this.#n=e,this}setAdditionalAuthenticatedData(e){return this.#a=e,this}setContentEncryptionKey(e){return S(this.#s,"setContentEncryptionKey"),this.#s=e,this}setInitializationVector(e){return S(this.#o,"setInitializationVector"),this.#o=e,this}async encrypt(e,t){if(!this.#t&&!this.#n&&!this.#r)throw new c("either setProtectedHeader, setUnprotectedHeader, or sharedUnprotectedHeader must be called before #encrypt()");if(!L(this.#t,this.#n,this.#r))throw new c("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint");let r={...this.#t,...this.#n,...this.#r};if(k(c,new Map,t?.crit,this.#t,r),r.zip!==void 0&&r.zip!=="DEF")throw new d('Unsupported JWE "zip" (Compression Algorithm) Header Parameter value.');if(r.zip!==void 0&&!this.#t?.zip)throw new c('JWE "zip" (Compression Algorithm) Header Parameter MUST be in a protected header.');let{alg:n,enc:i}=r;if(typeof n!=="string"||!n)throw new c('JWE "alg" (Algorithm) Header Parameter missing or invalid');if(typeof i!=="string"||!i)throw new c('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');let a;if(this.#s&&(n==="dir"||n==="ECDH-ES"))throw TypeError(`setContentEncryptionKey cannot be called with JWE "alg" (Algorithm) Header ${n}`);$(n==="dir"?i:n,e,"encrypt");let s;{let P,ke=await U(e,n);if({cek:s,encryptedKey:a,parameters:P}=await Oe(n,i,ke,this.#s,this.#i),P)if(t&&De in t)if(!this.#n)this.setUnprotectedHeader(P);else this.#n={...this.#n,...P};else if(!this.#t)this.setProtectedHeader(P);else this.#t={...this.#t,...P}}let o,p,u,f;if(this.#t)p=y(JSON.stringify(this.#t)),u=w(p);else p="",u=new Uint8Array;if(this.#a){f=y(this.#a);let P=w(f);o=g(u,w("."),P)}else o=u;let l=this.#e;if(r.zip==="DEF")l=await Qt(l).catch((P)=>{throw new c("Failed to compress plaintext",{cause:P})});let{ciphertext:E,tag:T,iv:b}=await Je(i,l,s,this.#o,o),A={ciphertext:y(E)};if(b)A.iv=y(b);if(T)A.tag=y(T);if(a)A.encrypted_key=y(a);if(f)A.aad=f;if(this.#t)A.protected=p;if(this.#r)A.unprotected=this.#r;if(this.#n)A.header=this.#n;return A}}class jt{#e;unprotectedHeader;keyManagementParameters;key;options;constructor(e,t,r){this.#e=e,this.key=t,this.options=r}setUnprotectedHeader(e){return S(this.unprotectedHeader,"setUnprotectedHeader"),this.unprotectedHeader=e,this}setKeyManagementParameters(e){return S(this.keyManagementParameters,"setKeyManagementParameters"),this.keyManagementParameters=e,this}addRecipient(...e){return this.#e.addRecipient(...e)}encrypt(...e){return this.#e.encrypt(...e)}done(){return this.#e}}class er{#e;#t=[];#r;#n;#a;constructor(e){this.#e=e}addRecipient(e,t){let r=new jt(this,e,{crit:t?.crit});return this.#t.push(r),r}setProtectedHeader(e){return S(this.#r,"setProtectedHeader"),this.#r=e,this}setSharedUnprotectedHeader(e){return S(this.#n,"setSharedUnprotectedHeader"),this.#n=e,this}setAdditionalAuthenticatedData(e){return this.#a=e,this}async encrypt(){if(!this.#t.length)throw new c("at least one recipient must be added");if(this.#t.length===1){let[n]=this.#t,i=await new j(this.#e).setAdditionalAuthenticatedData(this.#a).setProtectedHeader(this.#r).setSharedUnprotectedHeader(this.#n).setUnprotectedHeader(n.unprotectedHeader).encrypt(n.key,{...n.options}),a={ciphertext:i.ciphertext,iv:i.iv,recipients:[{}],tag:i.tag};if(i.aad)a.aad=i.aad;if(i.protected)a.protected=i.protected;if(i.unprotected)a.unprotected=i.unprotected;if(i.encrypted_key)a.recipients[0].encrypted_key=i.encrypted_key;if(i.header)a.recipients[0].header=i.header;return a}let e;for(let n=0;n<this.#t.length;n++){let i=this.#t[n];if(!L(this.#r,this.#n,i.unprotectedHeader))throw new c("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint");let a={...this.#r,...this.#n,...i.unprotectedHeader},{alg:s}=a;if(typeof s!=="string"||!s)throw new c('JWE "alg" (Algorithm) Header Parameter missing or invalid');if(s==="dir"||s==="ECDH-ES")throw new c('"dir" and "ECDH-ES" alg may only be used with a single recipient');if(typeof a.enc!=="string"||!a.enc)throw new c('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');if(!e)e=a.enc;else if(e!==a.enc)throw new c('JWE "enc" (Encryption Algorithm) Header Parameter must be the same for all recipients');if(k(c,new Map,i.options.crit,this.#r,a),a.zip!==void 0&&a.zip!=="DEF")throw new d('Unsupported JWE "zip" (Compression Algorithm) Header Parameter value.');if(a.zip!==void 0&&!this.#r?.zip)throw new c('JWE "zip" (Compression Algorithm) Header Parameter MUST be in a protected header.')}let t=_(e),r={ciphertext:"",recipients:[]};for(let n=0;n<this.#t.length;n++){let i=this.#t[n],a={};if(r.recipients.push(a),n===0){let f=await new j(this.#e).setAdditionalAuthenticatedData(this.#a).setContentEncryptionKey(t).setProtectedHeader(this.#r).setSharedUnprotectedHeader(this.#n).setUnprotectedHeader(i.unprotectedHeader).setKeyManagementParameters(i.keyManagementParameters).encrypt(i.key,{...i.options,[De]:!0});if(r.ciphertext=f.ciphertext,r.iv=f.iv,r.tag=f.tag,f.aad)r.aad=f.aad;if(f.protected)r.protected=f.protected;if(f.unprotected)r.unprotected=f.unprotected;if(a.encrypted_key=f.encrypted_key,f.header)a.header=f.header;continue}let s=i.unprotectedHeader?.alg||this.#r?.alg||this.#n?.alg;$(s==="dir"?e:s,i.key,"encrypt");let o=await U(i.key,s),{encryptedKey:p,parameters:u}=await Oe(s,e,o,t,i.keyManagementParameters);if(a.encrypted_key=y(p),i.unprotectedHeader||u)a.header={...i.unprotectedHeader,...u}}return r}}async function ge(e,t,r){if(!m(e))throw new h("Flattened JWS must be an object");if(e.protected===void 0&&e.header===void 0)throw new h('Flattened JWS must have either of the "protected" or "header" members');if(e.protected!==void 0&&typeof e.protected!=="string")throw new h("JWS Protected Header incorrect type");if(e.payload===void 0)throw new h("JWS Payload missing");if(typeof e.signature!=="string")throw new h("JWS Signature missing or incorrect type");if(e.header!==void 0&&!m(e.header))throw new h("JWS Unprotected Header incorrect type");let n={};if(e.protected)try{let P=W(e.protected);n=JSON.parse(C.decode(P))}catch{throw new h("JWS Protected Header is invalid")}if(!L(n,e.header))throw new h("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");let i={...n,...e.header},a=k(h,new Map([["b64",!0]]),r?.crit,n,i),s=!0;if(a.has("b64")){if(s=n.b64,typeof s!=="boolean")throw new h('The "b64" (base64url-encode payload) Header Parameter must be a boolean')}let{alg:o}=i;if(typeof o!=="string"||!o)throw new h('JWS "alg" (Algorithm) Header Parameter missing or invalid');let p=r&&Ee("algorithms",r.algorithms);if(p&&!p.has(o))throw new Y('"alg" (Algorithm) Header Parameter value not allowed');if(s){if(typeof e.payload!=="string")throw new h("JWS Payload must be a string")}else if(typeof e.payload!=="string"&&!(e.payload instanceof Uint8Array))throw new h("JWS Payload must be a string or an Uint8Array instance");let u=!1;if(typeof t==="function")t=await t(n,e),u=!0;$(o,t,"verify");let f=g(e.protected!==void 0?w(e.protected):new Uint8Array,w("."),typeof e.payload==="string"?s?w(e.payload):X.encode(e.payload):e.payload),l=I(e.signature,"signature",h),E=await U(t,o);if(!await It(o,E,l,f))throw new ne;let b;if(s)b=I(e.payload,"payload",h);else if(typeof e.payload==="string")b=X.encode(e.payload);else b=e.payload;let A={payload:b};if(e.protected!==void 0)A.protectedHeader=n;if(e.header!==void 0)A.unprotectedHeader=e.header;if(u)return{...A,key:E};return A}async function it(e,t,r){if(e instanceof Uint8Array)e=C.decode(e);if(typeof e!=="string")throw new h("Compact JWS must be a string or Uint8Array");let{0:n,1:i,2:a,length:s}=e.split(".");if(s!==3)throw new h("Invalid Compact JWS");let o=await ge({payload:i,protected:n,signature:a},t,r),p={payload:o.payload,protectedHeader:o.protectedHeader};if(typeof t==="function")return{...p,key:o.key};return p}async function Fr(e,t,r){if(!m(e))throw new h("General JWS must be an object");if(!Array.isArray(e.signatures)||!e.signatures.every(m))throw new h("JWS Signatures missing or incorrect type");for(let n of e.signatures)try{return await ge({header:n.header,payload:e.payload,protected:n.protected,signature:n.signature},t,r)}catch{}throw new ne}var F=(e)=>Math.floor(e.getTime()/1000),rr=60,nr=rr*60,at=nr*24,zr=at*7,Xr=at*365.25,Yr=/^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;function Ke(e){let t=Yr.exec(e);if(!t||t[4]&&t[1])throw TypeError("Invalid time period format");let r=parseFloat(t[2]),n=t[3].toLowerCase(),i;switch(n){case"sec":case"secs":case"second":case"seconds":case"s":i=Math.round(r);break;case"minute":case"minutes":case"min":case"mins":case"m":i=Math.round(r*rr);break;case"hour":case"hours":case"hr":case"hrs":case"h":i=Math.round(r*nr);break;case"day":case"days":case"d":i=Math.round(r*at);break;case"week":case"weeks":case"w":i=Math.round(r*zr);break;default:i=Math.round(r*Xr);break}if(t[1]==="-"||t[4]==="ago")return-i;return i}function ee(e,t){if(!Number.isFinite(t))throw TypeError(`Invalid ${e} input`);return t}var tr=(e)=>{if(e.includes("/"))return e.toLowerCase();return`application/${e.toLowerCase()}`},qr=(e,t)=>{if(typeof e==="string")return t.includes(e);if(Array.isArray(e))return t.some(Set.prototype.has.bind(new Set(e)));return!1};function pe(e,t,r={}){let n;try{n=JSON.parse(C.decode(t))}catch{}if(!m(n))throw new K("JWT Claims Set must be a top-level JSON object");let{typ:i}=r;if(i&&(typeof e.typ!=="string"||tr(e.typ)!==tr(i)))throw new H('unexpected "typ" JWT header value',n,"typ","check_failed");let{requiredClaims:a=[],issuer:s,subject:o,audience:p,maxTokenAge:u}=r,f=[...a];if(u!==void 0)f.push("iat");if(p!==void 0)f.push("aud");if(o!==void 0)f.push("sub");if(s!==void 0)f.push("iss");for(let b of new Set(f.reverse()))if(!(b in n))throw new H(`missing required "${b}" claim`,n,b,"missing");if(s&&!(Array.isArray(s)?s:[s]).includes(n.iss))throw new H('unexpected "iss" claim value',n,"iss","check_failed");if(o&&n.sub!==o)throw new H('unexpected "sub" claim value',n,"sub","check_failed");if(p&&!qr(n.aud,typeof p==="string"?[p]:p))throw new H('unexpected "aud" claim value',n,"aud","check_failed");let l;switch(typeof r.clockTolerance){case"string":l=Ke(r.clockTolerance);break;case"number":l=r.clockTolerance;break;case"undefined":l=0;break;default:throw TypeError("Invalid clockTolerance option type")}let{currentDate:E}=r,T=F(E||new Date);if((n.iat!==void 0||u)&&typeof n.iat!=="number")throw new H('"iat" claim must be a number',n,"iat","invalid");if(n.nbf!==void 0){if(typeof n.nbf!=="number")throw new H('"nbf" claim must be a number',n,"nbf","invalid");if(n.nbf>T+l)throw new H('"nbf" claim timestamp check failed',n,"nbf","check_failed")}if(n.exp!==void 0){if(typeof n.exp!=="number")throw new H('"exp" claim must be a number',n,"exp","invalid");if(n.exp<=T-l)throw new fe('"exp" claim timestamp check failed',n,"exp","check_failed")}if(u){let b=T-n.iat,A=typeof u==="number"?u:Ke(u);if(b-l>A)throw new fe('"iat" claim timestamp check failed (too far in the past)',n,"iat","check_failed");if(b<0-l)throw new H('"iat" claim timestamp check failed (it should be in the past)',n,"iat","check_failed")}return n}class te{#e;constructor(e){if(!m(e))throw TypeError("JWT Claims Set MUST be an object");this.#e=structuredClone(e)}data(){return X.encode(JSON.stringify(this.#e))}get iss(){return this.#e.iss}set iss(e){this.#e.iss=e}get sub(){return this.#e.sub}set sub(e){this.#e.sub=e}get aud(){return this.#e.aud}set aud(e){this.#e.aud=e}set jti(e){this.#e.jti=e}set nbf(e){if(typeof e==="number")this.#e.nbf=ee("setNotBefore",e);else if(e instanceof Date)this.#e.nbf=ee("setNotBefore",F(e));else this.#e.nbf=F(new Date)+Ke(e)}set exp(e){if(typeof e==="number")this.#e.exp=ee("setExpirationTime",e);else if(e instanceof Date)this.#e.exp=ee("setExpirationTime",F(e));else this.#e.exp=F(new Date)+Ke(e)}set iat(e){if(e===void 0)this.#e.iat=F(new Date);else if(e instanceof Date)this.#e.iat=ee("setIssuedAt",F(e));else if(typeof e==="string")this.#e.iat=ee("setIssuedAt",F(new Date)+Ke(e));else this.#e.iat=ee("setIssuedAt",e)}}async function Qr(e,t,r){let n=await it(e,t,r);if(n.protectedHeader.crit?.includes("b64")&&n.protectedHeader.b64===!1)throw new K("JWTs MUST NOT use unencoded payload");let a={payload:pe(n.protectedHeader,n.payload,r),protectedHeader:n.protectedHeader};if(typeof t==="function")return{...a,key:n.key};return a}async function Zr(e,t,r){let n=await nt(e,t,r),i=pe(n.protectedHeader,n.plaintext,r),{protectedHeader:a}=n;if(a.iss!==void 0&&a.iss!==i.iss)throw new H('replicated "iss" claim header parameter mismatch',i,"iss","mismatch");if(a.sub!==void 0&&a.sub!==i.sub)throw new H('replicated "sub" claim header parameter mismatch',i,"sub","mismatch");if(a.aud!==void 0&&JSON.stringify(a.aud)!==JSON.stringify(i.aud))throw new H('replicated "aud" claim header parameter mismatch',i,"aud","mismatch");let s={payload:i,protectedHeader:a};if(typeof t==="function")return{...s,key:n.key};return s}class Ne{#e;constructor(e){this.#e=new j(e)}setContentEncryptionKey(e){return this.#e.setContentEncryptionKey(e),this}setInitializationVector(e){return this.#e.setInitializationVector(e),this}setProtectedHeader(e){return this.#e.setProtectedHeader(e),this}setKeyManagementParameters(e){return this.#e.setKeyManagementParameters(e),this}async encrypt(e,t){let r=await this.#e.encrypt(e,t);return[r.protected,r.encrypted_key,r.iv,r.ciphertext,r.tag].join(".")}}class ue{#e;#t;#r;constructor(e){if(!(e instanceof Uint8Array))throw TypeError("payload must be an instance of Uint8Array");this.#e=e}setProtectedHeader(e){return S(this.#t,"setProtectedHeader"),this.#t=e,this}setUnprotectedHeader(e){return S(this.#r,"setUnprotectedHeader"),this.#r=e,this}async sign(e,t){if(!this.#t&&!this.#r)throw new h("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");if(!L(this.#t,this.#r))throw new h("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");let r={...this.#t,...this.#r},n=k(h,new Map([["b64",!0]]),t?.crit,this.#t,r),i=!0;if(n.has("b64")){if(i=this.#t.b64,typeof i!=="boolean")throw new h('The "b64" (base64url-encode payload) Header Parameter must be a boolean')}let{alg:a}=r;if(typeof a!=="string"||!a)throw new h('JWS "alg" (Algorithm) Header Parameter missing or invalid');$(a,e,"sign");let s,o;if(i)s=y(this.#e),o=w(s);else o=this.#e,s="";let p,u;if(this.#t)p=y(JSON.stringify(this.#t)),u=w(p);else p="",u=new Uint8Array;let f=g(u,w("."),o),l=await U(e,a),E=await vt(a,l,f),T={signature:y(E),payload:s};if(this.#r)T.header=this.#r;if(this.#t)T.protected=p;return T}}class _e{#e;constructor(e){this.#e=new ue(e)}setProtectedHeader(e){return this.#e.setProtectedHeader(e),this}async sign(e,t){let r=await this.#e.sign(e,t);if(r.payload===void 0)throw TypeError("use the flattened module for creating JWS with b64: false");return`${r.protected}.${r.payload}.${r.signature}`}}class ir{#e;protectedHeader;unprotectedHeader;options;key;constructor(e,t,r){this.#e=e,this.key=t,this.options=r}setProtectedHeader(e){return S(this.protectedHeader,"setProtectedHeader"),this.protectedHeader=e,this}setUnprotectedHeader(e){return S(this.unprotectedHeader,"setUnprotectedHeader"),this.unprotectedHeader=e,this}addSignature(...e){return this.#e.addSignature(...e)}sign(...e){return this.#e.sign(...e)}done(){return this.#e}}class ar{#e;#t=[];constructor(e){this.#e=e}addSignature(e,t){let r=new ir(this,e,t);return this.#t.push(r),r}async sign(){if(!this.#t.length)throw new h("at least one signature must be added");let e={signatures:[],payload:""};for(let t=0;t<this.#t.length;t++){let r=this.#t[t],n=new ue(this.#e);n.setProtectedHeader(r.protectedHeader),n.setUnprotectedHeader(r.unprotectedHeader);let{payload:i,...a}=await n.sign(r.key,r.options);if(t===0)e.payload=i;else if(e.payload!==i)throw new h("inconsistent use of JWS Unencoded Payload (RFC7797)");e.signatures.push(a)}return e}}class sr{#e;#t;constructor(e={}){this.#t=new te(e)}setIssuer(e){return this.#t.iss=e,this}setSubject(e){return this.#t.sub=e,this}setAudience(e){return this.#t.aud=e,this}setJti(e){return this.#t.jti=e,this}setNotBefore(e){return this.#t.nbf=e,this}setExpirationTime(e){return this.#t.exp=e,this}setIssuedAt(e){return this.#t.iat=e,this}setProtectedHeader(e){return this.#e=e,this}async sign(e,t){let r=new _e(this.#t.data());if(r.setProtectedHeader(this.#e),Array.isArray(this.#e?.crit)&&this.#e.crit.includes("b64")&&this.#e.b64===!1)throw new K("JWTs MUST NOT use unencoded payload");return r.sign(e,t)}}class or{#e;#t;#r;#n;#a;#s;#o;#i;constructor(e={}){this.#i=new te(e)}setIssuer(e){return this.#i.iss=e,this}setSubject(e){return this.#i.sub=e,this}setAudience(e){return this.#i.aud=e,this}setJti(e){return this.#i.jti=e,this}setNotBefore(e){return this.#i.nbf=e,this}setExpirationTime(e){return this.#i.exp=e,this}setIssuedAt(e){return this.#i.iat=e,this}setProtectedHeader(e){return S(this.#n,"setProtectedHeader"),this.#n=e,this}setKeyManagementParameters(e){return S(this.#r,"setKeyManagementParameters"),this.#r=e,this}setContentEncryptionKey(e){return S(this.#e,"setContentEncryptionKey"),this.#e=e,this}setInitializationVector(e){return S(this.#t,"setInitializationVector"),this.#t=e,this}replicateIssuerAsHeader(){return this.#a=!0,this}replicateSubjectAsHeader(){return this.#s=!0,this}replicateAudienceAsHeader(){return this.#o=!0,this}async encrypt(e,t){let r=new Ne(this.#i.data());if(this.#n&&(this.#a||this.#s||this.#o))this.#n={...this.#n,iss:this.#a?this.#i.iss:void 0,sub:this.#s?this.#i.sub:void 0,aud:this.#o?this.#i.aud:void 0};if(r.setProtectedHeader(this.#n),this.#t)r.setInitializationVector(this.#t);if(this.#e)r.setContentEncryptionKey(this.#e);if(this.#r)r.setKeyManagementParameters(this.#r);return r.encrypt(e,t)}}var G=(e,t)=>{if(typeof e!=="string"||!e)throw new We(`${t} missing or invalid`)};async function cr(e,t){let r;if(Q(e))r=e;else if(me(e))r=await we(e);else throw TypeError(D(e,"CryptoKey","KeyObject","JSON Web Key"));if(t??="sha256",t!=="sha256"&&t!=="sha384"&&t!=="sha512")throw TypeError('digestAlgorithm must one of "sha256", "sha384", or "sha512"');let n;switch(r.kty){case"AKP":G(r.alg,'"alg" (Algorithm) Parameter'),G(r.pub,'"pub" (Public key) Parameter'),n={alg:r.alg,kty:r.kty,pub:r.pub};break;case"EC":G(r.crv,'"crv" (Curve) Parameter'),G(r.x,'"x" (X Coordinate) Parameter'),G(r.y,'"y" (Y Coordinate) Parameter'),n={crv:r.crv,kty:r.kty,x:r.x,y:r.y};break;case"OKP":G(r.crv,'"crv" (Subtype of Key Pair) Parameter'),G(r.x,'"x" (Public Key) Parameter'),n={crv:r.crv,kty:r.kty,x:r.x};break;case"RSA":G(r.e,'"e" (Exponent) Parameter'),G(r.n,'"n" (Modulus) Parameter'),n={e:r.e,kty:r.kty,n:r.n};break;case"oct":G(r.k,'"k" (Key Value) Parameter'),n={k:r.k,kty:r.kty};break;default:throw new d('"kty" (Key Type) Parameter missing or unsupported')}let i=w(JSON.stringify(n));return y(await Ue(t,i))}async function jr(e,t){t??="sha256";let r=await cr(e,t);return`urn:ietf:params:oauth:jwk-thumbprint:sha-${t.slice(-3)}:${r}`}async function en(e,t){let r={...e,...t?.header};if(!m(r.jwk))throw new h('"jwk" (JSON Web Key) Header Parameter must be a JSON object');let n=await Z({...r.jwk,ext:!0},r.alg);if(n instanceof Uint8Array||n.type!=="public")throw new h('"jwk" (JSON Web Key) Header Parameter must be a public key');return n}function tn(e){switch(typeof e==="string"&&e.slice(0,2)){case"RS":case"PS":return"RSA";case"ES":return"EC";case"Ed":return"OKP";case"ML":return"AKP";default:throw new d('Unsupported "alg" value for a JSON Web Key Set')}}function rn(e){return e&&typeof e==="object"&&Array.isArray(e.keys)&&e.keys.every(nn)}function nn(e){return m(e)}class ur{#e;#t=new WeakMap;constructor(e){if(!rn(e))throw new he("JSON Web Key Set malformed");this.#e=structuredClone(e)}jwks(){return this.#e}async getKey(e,t){let{alg:r,kid:n}={...e,...t?.header},i=tn(r),a=this.#e.keys.filter((p)=>{let u=i===p.kty;if(u&&typeof n==="string")u=n===p.kid;if(u&&(typeof p.alg==="string"||i==="AKP"))u=r===p.alg;if(u&&typeof p.use==="string")u=p.use==="sig";if(u&&Array.isArray(p.key_ops))u=p.key_ops.includes("verify");if(u)switch(r){case"ES256":u=p.crv==="P-256";break;case"ES384":u=p.crv==="P-384";break;case"ES512":u=p.crv==="P-521";break;case"Ed25519":case"EdDSA":u=p.crv==="Ed25519";break}return u}),{0:s,length:o}=a;if(o===0)throw new re;if(o!==1){let p=new He,u=this.#t;throw p[Symbol.asyncIterator]=async function*(){for(let f of a)try{yield await pr(u,f,r)}catch{}},p}return pr(this.#t,s,r)}}async function pr(e,t,r){let n=e.get(t)||e.set(t,{}).get(t);if(n[r]===void 0){let i=await Z({...t,ext:!0},r);if(i instanceof Uint8Array||i.type!=="public")throw new he("JSON Web Key Set members must be public keys");n[r]=i}return n[r]}function Le(e){let t=new ur(e),r=async(n,i)=>t.getKey(n,i);return Object.defineProperties(r,{jwks:{value:()=>structuredClone(t.jwks()),enumerable:!1,configurable:!1,writable:!1}}),r}function an(){return typeof WebSocketPair<"u"||typeof navigator<"u"&&navigator.userAgent==="Cloudflare-Workers"||typeof EdgeRuntime<"u"&&EdgeRuntime==="vercel"}var st;if(typeof navigator>"u"||!navigator.userAgent?.startsWith?.("Mozilla/5.0 "))st="jose/v6.2.3";var dr=Symbol();async function sn(e,t,r,n=fetch){let i=await n(e,{method:"GET",signal:r,redirect:"manual",headers:t}).catch((a)=>{if(a.name==="TimeoutError")throw new Te;throw a});if(i.status!==200)throw new x("Expected 200 OK from the JSON Web Key Set HTTP response");try{return await i.json()}catch{throw new x("Failed to parse the JSON Web Key Set HTTP response as JSON")}}var Be=Symbol();function on(e,t){if(typeof e!=="object"||e===null)return!1;if(!("uat"in e)||typeof e.uat!=="number"||Date.now()-e.uat>=t)return!1;if(!("jwks"in e)||!m(e.jwks)||!Array.isArray(e.jwks.keys)||!Array.prototype.every.call(e.jwks.keys,m))return!1;return!0}class fr{#e;#t;#r;#n;#a;#s;#o;#i;#c;#p;constructor(e,t){if(!(e instanceof URL))throw TypeError("url must be an instance of URL");if(this.#e=new URL(e.href),this.#t=typeof t?.timeoutDuration==="number"?t?.timeoutDuration:5000,this.#r=typeof t?.cooldownDuration==="number"?t?.cooldownDuration:30000,this.#n=typeof t?.cacheMaxAge==="number"?t?.cacheMaxAge:600000,this.#o=new Headers(t?.headers),st&&!this.#o.has("User-Agent"))this.#o.set("User-Agent",st);if(!this.#o.has("accept"))this.#o.set("accept","application/json"),this.#o.append("accept","application/jwk-set+json");if(this.#i=t?.[dr],t?.[Be]!==void 0){if(this.#p=t?.[Be],on(t?.[Be],this.#n))this.#a=this.#p.uat,this.#c=Le(this.#p.jwks)}}pendingFetch(){return!!this.#s}coolingDown(){return typeof this.#a==="number"?Date.now()<this.#a+this.#r:!1}fresh(){return typeof this.#a==="number"?Date.now()<this.#a+this.#n:!1}jwks(){return this.#c?.jwks()}async getKey(e,t){if(!this.#c||!this.fresh())await this.reload();try{return await this.#c(e,t)}catch(r){if(r instanceof re){if(this.coolingDown()===!1)return await this.reload(),this.#c(e,t)}throw r}}async reload(){if(this.#s&&an())this.#s=void 0;this.#s||=sn(this.#e.href,this.#o,AbortSignal.timeout(this.#t),this.#i).then((e)=>{if(this.#c=Le(e),this.#p)this.#p.uat=Date.now(),this.#p.jwks=e;this.#a=Date.now(),this.#s=void 0}).catch((e)=>{throw this.#s=void 0,e}),await this.#s}}function cn(e,t){let r=new fr(e,t),n=async(i,a)=>r.getKey(i,a);return Object.defineProperties(n,{coolingDown:{get:()=>r.coolingDown(),enumerable:!0,configurable:!1},fresh:{get:()=>r.fresh(),enumerable:!0,configurable:!1},reload:{value:()=>r.reload(),enumerable:!0,configurable:!1,writable:!1},reloading:{get:()=>r.pendingFetch(),enumerable:!0,configurable:!1},jwks:{value:()=>r.jwks(),enumerable:!0,configurable:!1,writable:!1}}),n}class hr{#e;constructor(e={}){this.#e=new te(e)}encode(){let e=y(JSON.stringify({alg:"none"})),t=y(this.#e.data());return`${e}.${t}.`}setIssuer(e){return this.#e.iss=e,this}setSubject(e){return this.#e.sub=e,this}setAudience(e){return this.#e.aud=e,this}setJti(e){return this.#e.jti=e,this}setNotBefore(e){return this.#e.nbf=e,this}setExpirationTime(e){return this.#e.exp=e,this}setIssuedAt(e){return this.#e.iat=e,this}static decode(e,t){if(typeof e!=="string")throw new K("Unsecured JWT must be a string");let{0:r,1:n,2:i,length:a}=e.split(".");if(a!==3||i!=="")throw new K("Invalid Unsecured JWT");let s;try{if(s=JSON.parse(C.decode(W(r))),s.alg!=="none")throw Error()}catch{throw new K("Invalid Unsecured JWT")}return{payload:pe(s,W(n),t),header:s}}}function pn(e){let t;if(typeof e==="string"){let r=e.split(".");if(r.length===3||r.length===5)[t]=r}else if(typeof e==="object"&&e)if("protected"in e)t=e.protected;else throw TypeError("Token does not contain a Protected Header");try{if(typeof t!=="string"||!t)throw Error();let r=JSON.parse(C.decode(W(t)));if(!m(r))throw Error();return r}catch{throw TypeError("Invalid Token or Protected Header formatting")}}function un(e){if(typeof e!=="string")throw new K("JWTs must use Compact JWS serialization, JWT must be a string");let{1:t,length:r}=e.split(".");if(r===5)throw new K("Only JWTs using Compact JWS serialization can be decoded");if(r!==3)throw new K("Invalid JWT");if(!t)throw new K("JWTs must contain a payload");let n;try{n=W(t)}catch{throw new K("Failed to base64url decode the payload")}let i;try{i=JSON.parse(C.decode(n))}catch{throw new K("Failed to parse the decoded payload as JSON")}if(!m(i))throw new K("Invalid JWT Claims Set");return i}function ot(e){let t=e?.modulusLength??2048;if(typeof t!=="number"||t<2048)throw new d("Invalid or unsupported modulusLength option provided, 2048 bits or larger keys must be used");return t}async function dn(e,t){let r,n;switch(e){case"PS256":case"PS384":case"PS512":r={name:"RSA-PSS",hash:`SHA-${e.slice(-3)}`,publicExponent:Uint8Array.of(1,0,1),modulusLength:ot(t)},n=["sign","verify"];break;case"RS256":case"RS384":case"RS512":r={name:"RSASSA-PKCS1-v1_5",hash:`SHA-${e.slice(-3)}`,publicExponent:Uint8Array.of(1,0,1),modulusLength:ot(t)},n=["sign","verify"];break;case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":r={name:"RSA-OAEP",hash:`SHA-${parseInt(e.slice(-3),10)||1}`,publicExponent:Uint8Array.of(1,0,1),modulusLength:ot(t)},n=["decrypt","unwrapKey","encrypt","wrapKey"];break;case"ES256":r={name:"ECDSA",namedCurve:"P-256"},n=["sign","verify"];break;case"ES384":r={name:"ECDSA",namedCurve:"P-384"},n=["sign","verify"];break;case"ES512":r={name:"ECDSA",namedCurve:"P-521"},n=["sign","verify"];break;case"Ed25519":case"EdDSA":{n=["sign","verify"],r={name:"Ed25519"};break}case"ML-DSA-44":case"ML-DSA-65":case"ML-DSA-87":{n=["sign","verify"],r={name:e};break}case"ECDH-ES":case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":{n=["deriveBits"];let i=t?.crv??"P-256";switch(i){case"P-256":case"P-384":case"P-521":{r={name:"ECDH",namedCurve:i};break}case"X25519":r={name:"X25519"};break;default:throw new d("Invalid or unsupported crv option provided, supported values are P-256, P-384, P-521, and X25519")}break}default:throw new d('Invalid or unsupported JWK "alg" (Algorithm) Parameter value')}return crypto.subtle.generateKey(r,t?.extractable??!1,n)}async function fn(e,t){let r,n,i;switch(e){case"HS256":case"HS384":case"HS512":r=parseInt(e.slice(-3),10),n={name:"HMAC",hash:`SHA-${r}`,length:r},i=["sign","verify"];break;case"A128CBC-HS256":case"A192CBC-HS384":case"A256CBC-HS512":return r=parseInt(e.slice(-3),10),crypto.getRandomValues(new Uint8Array(r>>3));case"A128KW":case"A192KW":case"A256KW":r=parseInt(e.slice(1,4),10),n={name:"AES-KW",length:r},i=["wrapKey","unwrapKey"];break;case"A128GCMKW":case"A192GCMKW":case"A256GCMKW":case"A128GCM":case"A192GCM":case"A256GCM":r=parseInt(e.slice(1,4),10),n={name:"AES-GCM",length:r},i=["encrypt","decrypt"];break;default:throw new d('Invalid or unsupported JWK "alg" (Algorithm) Parameter value')}return crypto.subtle.generateKey(n,t?.extractable??!1,i)}var wo="WebCryptoAPI";
6
- export{Fe as yd,fe as zd,ht as Ad,Nr as Bd,_r as Cd,Lr as Dd,Z as Ed,Br as Fd,kr as Gd,we as Hd,be as Id,nt as Jd,Vr as Kd,j as Ld,er as Md,ge as Nd,it as Od,Fr as Pd,Qr as Qd,Zr as Rd,Ne as Sd,ue as Td,_e as Ud,ar as Vd,sr as Wd,or as Xd,cr as Yd,jr as Zd,en as _d,Le as $d,dr as ae,Be as be,cn as ce,hr as de,pn as ee,un as fe,dn as ge,fn as he,wo as ie};