@shumai-one/shumai-agent 0.6.2 → 0.6.4
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.
- package/bin/{chunk-akj1v1zj.js → chunk-0p6vypf5.js} +1 -1
- package/bin/chunk-1g04y33t.js +2 -0
- package/bin/{chunk-3kt4k4jg.js → chunk-212mr722.js} +4 -4
- package/bin/{chunk-b767451d.js → chunk-2rha5rx0.js} +1 -1
- package/bin/{chunk-pbdctjg4.js → chunk-2z122czc.js} +1 -1
- package/bin/{chunk-7bn1mjf2.js → chunk-49hphjym.js} +2 -2
- package/bin/{chunk-7pwsjw9r.js → chunk-59ggf7fb.js} +2 -2
- package/bin/{chunk-vngxwvwv.js → chunk-5katf1md.js} +1 -1
- package/bin/{chunk-z3gbypjs.js → chunk-5q6efkg4.js} +1 -1
- package/bin/{chunk-zphx997k.js → chunk-71xpmfsv.js} +2 -2
- package/bin/{chunk-rf428t28.js → chunk-81h3f894.js} +1 -1
- package/bin/{chunk-pphsqcqt.js → chunk-88qd5fc9.js} +1 -1
- package/bin/{chunk-bsxxt20c.js → chunk-954981f3.js} +1 -1
- package/bin/{chunk-rkcsrrvy.js → chunk-96w1b3xz.js} +22 -22
- package/bin/{chunk-mnd4dn3q.js → chunk-b4nq5cev.js} +1 -1
- package/bin/{chunk-stex0y7j.js → chunk-cmz4eddb.js} +2 -2
- package/bin/{chunk-nwz9f1dy.js → chunk-f2t13wg5.js} +1 -1
- package/bin/{chunk-eh6xcwvv.js → chunk-g3dzntvc.js} +4 -4
- package/bin/{chunk-hnpr396w.js → chunk-g9trq7qh.js} +2 -2
- package/bin/{chunk-nmygzasv.js → chunk-gdtq1b84.js} +1 -1
- package/bin/{chunk-w0e5ek1r.js → chunk-hnw1kn3x.js} +1 -1
- package/bin/chunk-hq9yqnhy.js +2 -0
- package/bin/{chunk-ss91akc0.js → chunk-j64r5dpq.js} +1 -1
- package/bin/{chunk-p5nhcxwg.js → chunk-jkv2mt6v.js} +1 -1
- package/bin/{chunk-gx33h4rt.js → chunk-mqsbzv5n.js} +1 -1
- package/bin/{chunk-a5rn622e.js → chunk-mxpww8hv.js} +1 -1
- package/bin/chunk-ncgx0gs7.js +2 -0
- package/bin/{chunk-m3saxrzj.js → chunk-pn5sn30m.js} +1 -1
- package/bin/{chunk-fgabndrh.js → chunk-pqze01t7.js} +1 -1
- package/bin/{chunk-9fqyh49m.js → chunk-r3aq67n1.js} +1 -1
- package/bin/{chunk-29r6a67p.js → chunk-rgp1hb27.js} +1 -1
- package/bin/chunk-sp31yj39.js +2 -0
- package/bin/{chunk-fq1tf20c.js → chunk-t75d2xk1.js} +3 -3
- package/bin/{chunk-rx0fmt6n.js → chunk-tfs03y7v.js} +3 -3
- package/bin/chunk-tq868tzy.js +3 -0
- package/bin/{chunk-hssdv3mc.js → chunk-vj82ck6j.js} +1 -1
- package/bin/{chunk-g7v8pfhe.js → chunk-wjyvz1nr.js} +1 -1
- package/bin/chunk-wyr1ea3f.js +2 -0
- package/bin/{chunk-62n25c3m.js → chunk-y416xjpm.js} +1 -1
- package/bin/{chunk-q5w77y3e.js → chunk-yetjsdvh.js} +1 -1
- package/bin/{chunk-6pf9rgk6.js → chunk-yj9dtnxh.js} +1 -1
- package/bin/{chunk-at5qzp08.js → chunk-z9xbbnnq.js} +3 -3
- package/bin/{chunk-pqa01d4g.js → chunk-zyd62xn1.js} +1 -1
- package/bin/shumai-agent-app.js +447 -366
- package/package.json +7 -7
- package/prisma/migrations/20261102032402_add_archive_storage/migration.sql +25 -0
- package/prisma/schema.prisma +12 -6
- package/bin/chunk-023w4q1f.js +0 -2
- package/bin/chunk-3ev1fh2w.js +0 -3
- package/bin/chunk-b2n9g75s.js +0 -2
- package/bin/chunk-ee8rt9we.js +0 -2
- package/bin/chunk-g7ad4dw4.js +0 -2
- package/bin/chunk-rtqengn3.js +0 -2
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var Lr=Object.create;var{getPrototypeOf:$r,defineProperty:wt,getOwnPropertyNames:jr}=Object;var Ft=Object.prototype.hasOwnProperty;function Vr(e){return this[e]}var Gr,Xr,E=(e,t,r)=>{var n=e!=null&&typeof e==="object";if(n){var o=t?Gr??=new WeakMap:Xr??=new WeakMap,a=o.get(e);if(a)return a}r=e!=null?Lr($r(e)):{};let i=t||!e||!e.__esModule||!Ft.call(e,"default")?wt(r,"default",{value:e,enumerable:!0}):r;if(e&&typeof e==="object"||typeof e==="function"){for(let s of jr(e))if(!Ft.call(i,s))wt(i,s,{get:Vr.bind(e,s),enumerable:!0})}if(n)o.set(e,i);return i};var A=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Yr=(e)=>e;function qr(e,t){this[e]=Yr.bind(null,t)}var Ie=(e,t)=>{for(var r in t)wt(e,r,{get:t[r],enumerable:!0,configurable:!0,set:qr.bind(t,r)})};var C=import.meta.require;var wn={};Ie(wn,{JOSEAlgNotAllowed:()=>ie,JOSEError:()=>X,JOSENotSupported:()=>m,JWEDecryptionFailed:()=>Te,JWEInvalid:()=>u,JWKInvalid:()=>Oe,JWKSInvalid:()=>yt,JWKSMultipleMatchingKeys:()=>Lt,JWKSNoMatchingKey:()=>le,JWKSTimeout:()=>Et,JWSInvalid:()=>h,JWSSignatureVerificationFailed:()=>Fe,JWTClaimValidationFailed:()=>D,JWTExpired:()=>tt,JWTInvalid:()=>H});var un={};Ie(un,{decode:()=>N,encode:()=>B});var We=new TextEncoder,oe=new TextDecoder,fe=new TextDecoder("utf-8",{fatal:!0});function x(...e){let t=e.reduce((o,{length:a})=>o+a,0),r=new Uint8Array(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}function gt(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 bt(e){let t=Math.floor(e/4294967296),r=e%4294967296,n=new Uint8Array(8);return gt(n,t,0),gt(n,r,4),n}function Ve(e){let t=new Uint8Array(4);return gt(t,e),t}function b(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}var ze=(e,t="algorithm.name")=>TypeError(`CryptoKey does not support this operation, its ${t} must be ${e}`);function St(e,t){if(t&&!e.usages.includes(t))throw TypeError(`CryptoKey does not support this operation, its usages must include ${t}.`)}function Ge(e,t){let{modulusLength:r}=t.algorithm;if(typeof r!=="number"||r<2048)throw TypeError(`${e} requires key modulusLength to be 2048 bits or larger`)}function j(e,t,r){let n=e.algorithm;if(n.name!==t.name)throw ze(t.name);if(t.hash&&n.hash?.name!==t.hash)throw ze(t.hash,"algorithm.hash");if(t.namedCurve&&n.namedCurve!==t.namedCurve)throw ze(t.namedCurve,"algorithm.namedCurve");if(t.length!==void 0&&n.length!==t.length)throw ze(t.length,"algorithm.length");St(e,r)}function Xt(e,t,...r){if(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 z=(e,...t)=>Xt("Key must be ",e,...t),Pe=(e,t,...r)=>Xt(`Key for the ${e} algorithm must be `,t,...r);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 D 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 tt 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 ie extends X{static code="ERR_JOSE_ALG_NOT_ALLOWED";code="ERR_JOSE_ALG_NOT_ALLOWED"}class m extends X{static code="ERR_JOSE_NOT_SUPPORTED";code="ERR_JOSE_NOT_SUPPORTED"}class Te extends X{static code="ERR_JWE_DECRYPTION_FAILED";code="ERR_JWE_DECRYPTION_FAILED";constructor(e="decryption operation failed",t){super(e,t)}}class u 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 H extends X{static code="ERR_JWT_INVALID";code="ERR_JWT_INVALID"}class Oe extends X{static code="ERR_JWK_INVALID";code="ERR_JWK_INVALID"}class yt extends X{static code="ERR_JWKS_INVALID";code="ERR_JWKS_INVALID"}class le 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 Lt extends X{[Symbol.asyncIterator]=async function*(){};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 Et extends X{static code="ERR_JWKS_TIMEOUT";code="ERR_JWKS_TIMEOUT";constructor(e="request timed out",t){super(e,t)}}class Fe 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 Xe(e){if(!G(e))throw Error("CryptoKey instance expected")}var G=(e)=>{if(e?.[Symbol.toStringTag]==="CryptoKey")return!0;try{return e instanceof CryptoKey}catch{return!1}},xt=(e)=>e?.[Symbol.toStringTag]==="KeyObject",Ye=(e)=>G(e)||xt(e);var F=(e)=>crypto.getRandomValues(new Uint8Array(e.cekBits>>3));function Yt(e,t){let r=e.byteLength<<3;if(r!==t)throw new u(`Invalid Content Encryption Key length. Expected ${t} bits, got ${r} bits`)}var Zr=(e)=>crypto.getRandomValues(new Uint8Array(e.ivBits>>3));function qt(e,t){if(t.length<<3!==e.ivBits)throw new u("Invalid Initialization Vector length")}async function Zt(e,t,r){if(!(t instanceof Uint8Array))throw TypeError(z(t,"Uint8Array"));let n=e.cekBits>>1,o=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[o,a,n]}async function Qt(e,t,r){return new Uint8Array((await crypto.subtle.sign("HMAC",e,t)).slice(0,r>>3))}async function Qr(e,t,r,n,o){let[a,i,s]=await Zt(e,r,"encrypt"),c=new Uint8Array(await crypto.subtle.encrypt({iv:n,name:"AES-CBC"},a,t)),p=x(o,n,c,bt(o.length*8)),d=await Qt(i,p,s);return{ciphertext:c,tag:d,iv:n}}async function en(e,t){let r={name:"HMAC",hash:"SHA-256"},n=await crypto.subtle.generateKey(r,!1,["sign","verify"]),o=await crypto.subtle.sign(r,n,e);return crypto.subtle.verify(r,n,o,t)}async function tn(e,t,r,n,o,a){let[i,s,c]=await Zt(e,t,"decrypt"),p=x(a,n,r,bt(a.length*8)),d=await Qt(s,p,c);try{if(await en(o,d))return new Uint8Array(await crypto.subtle.decrypt({iv:n,name:"AES-CBC"},i,r))}catch{}throw new Te}async function rn(e,t,r,n,o){let a=r instanceof Uint8Array?await crypto.subtle.importKey("raw",r,"AES-GCM",!1,["encrypt"]):(j(r,e.subtle,"encrypt"),r),i=new Uint8Array(await crypto.subtle.encrypt({additionalData:o,iv:n,name:"AES-GCM",tagLength:128},a,t)),s=i.slice(-16);return{ciphertext:i.slice(0,-16),tag:s,iv:n}}async function nn(e,t,r,n,o,a){let i=t instanceof Uint8Array?await crypto.subtle.importKey("raw",t,"AES-GCM",!1,["decrypt"]):(j(t,e.subtle,"decrypt"),t);try{return new Uint8Array(await crypto.subtle.decrypt({additionalData:a,iv:n,name:"AES-GCM",tagLength:128},i,x(r,o)))}catch{throw new Te}}async function qe(e,t,r,n,o){if(!G(r)&&!(r instanceof Uint8Array))throw TypeError(z(r,"CryptoKey","KeyObject","Uint8Array","JSON Web Key"));if(n)qt(e,n);else n=Zr(e);if(r instanceof Uint8Array)Yt(r,e.cekBits);return e.cbc?Qr(e,t,r,n,o):rn(e,t,r,n,o)}async function Ze(e,t,r,n,o,a){if(!G(t)&&!(t instanceof Uint8Array))throw TypeError(z(t,"CryptoKey","KeyObject","Uint8Array","JSON Web Key"));if(!n)throw new u("JWE Initialization Vector missing");if(!o)throw new u("JWE Authentication Tag missing");if(!e.cbc&&o.length!==16)throw new u("Invalid Authentication Tag length");if(qt(e,n),t instanceof Uint8Array)Yt(t,e.cekBits);return e.cbc?tn(e,t,r,n,o,a):nn(e,t,r,n,o,a)}function At(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 Qe(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}var Kt="The input to be decoded is not correctly encoded.";function N(e){if(Uint8Array.fromBase64)try{return Uint8Array.fromBase64(typeof e==="string"?e:oe.decode(e),{alphabet:"base64url"})}catch(r){throw TypeError(Kt,{cause:r})}let t=e;if(t instanceof Uint8Array)t=oe.decode(t);if(t.includes("+")||t.includes("/"))throw TypeError(Kt);t=t.replace(/-/g,"+").replace(/_/g,"/");try{return Qe(t)}catch{throw TypeError(Kt)}}function B(e){let t=e;if(typeof t==="string")t=We.encode(t);if(Uint8Array.prototype.toBase64)return t.toBase64({alphabet:"base64url",omitPadding:!0});return At(t).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function ae(e,t){if(!(e instanceof Uint8Array))throw TypeError(`${t} must be an instance of Uint8Array`)}function S(e){if(typeof e!=="object"||e===null||Object.prototype.toString.call(e)!=="[object Object]")return!1;let t=Object.getPrototypeOf(e);return t===null||Object.getPrototypeOf(t)===null}function et(e){return S(e)&&Array.isArray(e.keys)&&Array.from(e.keys).every(S)}function er(...e){let t=new Set;for(let r of e){if(!r)continue;for(let n of Object.keys(r)){if(t.has(n))return!1;t.add(n)}}return!0}var tr=Symbol();function se(e,t){if(e!==void 0)throw TypeError(`${t} can only be called once`)}function v(e,t,r){try{return N(e)}catch{throw new r(`Failed to base64url decode the ${t}`)}}function Jt(e,t,r){try{return b(e)}catch{throw new r(`The ${t} is not a valid base64url string`)}}async function rt(e,t){let r=`SHA-${e.slice(-3)}`;return new Uint8Array(await crypto.subtle.digest(r,t))}function ee(e,t,r){let n;try{n=JSON.parse(fe.decode(N(e)))}catch{throw new t(r)}if(!S(n))throw new t(r);return n}async function Y(e,t){if(t.kty==="RSA"&&"oth"in t&&t.oth!==void 0)throw new m('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');if(!e.kty.includes(t.kty))throw new m('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');let r=e.resolve?.({kty:t.kty,crv:t.crv})??e.subtle,n=!!(t.d||t.priv),o={...t};if(o.kty!=="AKP")delete o.alg;return delete o.use,crypto.subtle.importKey("jwk",o,r,t.ext??!n,t.key_ops??e.usages[n?1:0])}function me(e){return{__proto__:null,...e}}function nt(e){let t=me(e);if(t.ext!==void 0&&typeof t.ext!=="boolean")throw TypeError('"ext" (Extractable) Parameter must be a boolean');if(t.key_ops!==void 0){let r=t.key_ops,n=Array.isArray(r)?[...r]:void 0;if(!n||n.some((o)=>typeof o!=="string")||new Set(n).size!==n.length)throw TypeError('"key_ops" (Key Operations) Parameter must be an array of unique strings');t.key_ops=n}return t}var vt=(e)=>e[Symbol.toStringTag],on=(e,t,r)=>{let{alg:n}=e;if(t.use!==void 0){let o=r==="sign"||r==="verify"?"sig":"enc";if(t.use!==o)throw TypeError(`Invalid key for this operation, its "use" must be "${o}" when present`)}if(t.alg!==void 0&&t.alg!==n)throw TypeError(`Invalid key for this operation, its "alg" must be "${n}" when present`);if(Array.isArray(t.key_ops)){let o=r==="encrypt"||r==="decrypt"?e.ops?.[r==="encrypt"?0:1]:r;if(o&&!t.key_ops.includes(o))throw TypeError(`Invalid key for this operation, its "key_ops" must include "${o}" when present`)}};function an(e,t,r){let{alg:n,secret:o}=e,a=r==="decrypt"||r==="sign";if(o&&t instanceof Uint8Array)return[nr,t];if(S(t)){let i=nt(t);if(typeof i.kty!=="string")throw TypeError(o?Pe(n,t,"CryptoKey","KeyObject","JSON Web Key","Uint8Array"):Pe(n,t,"CryptoKey","KeyObject","JSON Web Key"));if(!(o?i.kty==="oct"&&typeof i.k==="string":i.kty!=="oct"&&(a?i.kty==="AKP"&&typeof i.priv==="string"||typeof i.d==="string":i.d===void 0&&i.priv===void 0)))throw TypeError(o?'JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present':`JSON Web Key for this operation must be a ${a?"private":"public"} JWK`);return on(e,i,r),[ar,t,i]}if(!Ye(t))throw TypeError(o?Pe(n,t,"CryptoKey","KeyObject","JSON Web Key","Uint8Array"):Pe(n,t,"CryptoKey","KeyObject","JSON Web Key"));if(o){if(t.type!=="secret")throw TypeError(`${vt(t)} instances for symmetric algorithms must be of type "secret"`)}else{if(t.type==="secret")throw TypeError(`${vt(t)} instances for asymmetric algorithms must not be of type "secret"`);let i=a?"private":"public";if((t.type==="public"||t.type==="private")&&t.type!==i){let s=r==="sign"?"signing":r==="verify"?"verifying":`${r.slice(0,-1)}tion`;throw TypeError(`${vt(t)} instances for asymmetric algorithm ${s} must be of type "${i}"`)}}return G(t)?[or,t]:[ir,t]}var nr=0,or=1,ir=2,ar=3,Wt,sn={__proto__:null,prime256v1:"P-256",secp384r1:"P-384",secp521r1:"P-521"};function ot(e,t,r){Wt||=new WeakMap;let n=Wt.get(e);if(r)if(n)n[t]=r;else Wt.set(e,{[t]:r});return r??n?.[t]}var rr=async(e,t,r)=>ot(e,r.alg)??ot(e,r.alg,await Y(r,{...t,alg:r.alg})),cn=(e,t)=>{let r=ot(e,t.alg);if(r)return r;let n=e.type==="public",o=t.usages[n?0:1],{asymmetricKeyType:a}=e,i=sn[e.asymmetricKeyDetails?.namedCurve],s=t.resolve?.({crv:i,asymmetricKeyType:a})??t.subtle;return ot(e,t.alg,e.toCryptoKey(s,n,o))};async function R(e,t,r){let n=an(e,t,r);switch(n[0]){case nr:case or:return n[1];case ar:{let o=n[1],a=n[2];if(a.kty==="oct")return N(a.k);if(!Object.isFrozen(o)){let{key_ops:i}=o;if(Array.isArray(i))Object.freeze(i);Object.freeze(o)}return rr(o,a,e)}case ir:{let o=n[1];if(o.type==="secret")return o.export();if("toCryptoKey"in o&&typeof o.toCryptoKey==="function")return cn(o,e);return rr(o,o.export({format:"jwk"}),e)}}}function _e(e){let t={__proto__:null};for(let r in e)t[r]={...e[r],alg:r};return t}var pn=[["encrypt","wrapKey"],["decrypt","unwrapKey"]],dn=[[],["deriveBits"]],st=[[],[]];function it(e){return{kty:["RSA"],subtle:{name:"RSA-OAEP",hash:`SHA-${e}`},usages:pn,ops:["wrapKey","unwrapKey"]}}function at(){return{kty:["EC","OKP"],subtle:{name:"ECDH"},resolve:({kty:e,crv:t,asymmetricKeyType:r})=>{if(t==="X25519"||r==="x25519")return{name:"X25519"};if(e==="OKP")throw new m('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');return{name:"ECDH",namedCurve:t}},usages:dn,ops:[void 0,"deriveBits"]}}function ye(e,t=!1){return{kty:["oct"],secret:!0,subtle:{name:t?"AES-GCM":"AES-KW",length:e},usages:st,ops:t?["encrypt","decrypt"]:["wrapKey","unwrapKey"]}}function Pt(){return{kty:["oct"],secret:!0,subtle:{name:"PBKDF2"},usages:st,ops:["deriveBits","deriveBits"]}}var Tt=_e({dir:{kty:["oct"],secret:!0,subtle:{name:"AES-GCM"},usages:st,ops:["encrypt","decrypt"]},"RSA-OAEP":it(1),"RSA-OAEP-256":it(256),"RSA-OAEP-384":it(384),"RSA-OAEP-512":it(512),"ECDH-ES":at(),"ECDH-ES+A128KW":at(),"ECDH-ES+A192KW":at(),"ECDH-ES+A256KW":at(),A128KW:ye(128),A192KW:ye(192),A256KW:ye(256),A128GCMKW:ye(128,!0),A192GCMKW:ye(192,!0),A256GCMKW:ye(256,!0),"PBES2-HS256+A128KW":Pt(),"PBES2-HS384+A192KW":Pt(),"PBES2-HS512+A256KW":Pt()}),fn=["encrypt","decrypt"];function he(e,t=!1){return{kty:["oct"],secret:!0,subtle:{name:t?"AES-CBC":"AES-GCM",length:e},usages:st,ops:fn,cekBits:e,ivBits:t?128:96,cbc:t}}var ln=_e({A128GCM:he(128),A192GCM:he(192),A256GCM:he(256),"A128CBC-HS256":he(256,!0),"A192CBC-HS384":he(384,!0),"A256CBC-HS512":he(512,!0)});function sr(e,t){throw new m(`Invalid or unsupported "${e}" (JWE ${t}) header value`)}function k(e){return(typeof e==="string"?Tt[e]:void 0)??sr("alg","Algorithm")}function ce(e){return(typeof e==="string"?ln[e]:void 0)??sr("enc","Encryption Algorithm")}function cr(e,t){if(e.algorithm.name!=="ECDH"&&e.algorithm.name!=="X25519")throw TypeError("CryptoKey does not support this operation, its algorithm.name must be ECDH or X25519");St(e,t)}async function dr(e,t,r){let n=k(t).subtle,o=e instanceof Uint8Array?await crypto.subtle.importKey("raw",e,"AES-KW",!0,[r]):e;return j(o,n,r),o}async function Ot(e,t,r){let n=await dr(t,e,"wrapKey"),o=await crypto.subtle.importKey("raw",r,{hash:"SHA-256",name:"HMAC"},!0,["sign"]);return new Uint8Array(await crypto.subtle.wrapKey("raw",o,n,"AES-KW"))}async function _t(e,t,r){let n=await dr(t,e,"unwrapKey"),o=await crypto.subtle.unwrapKey("raw",r,n,"AES-KW",{hash:"SHA-256",name:"HMAC"},!0,["sign"]);return new Uint8Array(await crypto.subtle.exportKey("raw",o))}function ur(e,t,r){j(t,k(e).subtle,r),Ge(e,t)}function mn(e,t){if(e instanceof Uint8Array)return crypto.subtle.importKey("raw",e,"PBKDF2",!1,["deriveBits"]);return j(e,k(t).subtle,"deriveBits"),e}async function fr(e,t,r,n){if(!(e instanceof Uint8Array)||e.length<8)throw new u("PBES2 Salt Input must be 8 or more octets");if(!Number.isSafeInteger(r)||Math.sign(r)!==1)throw new u("PBES2 Count Input must be a positive integer");let o=x(b(t),Uint8Array.of(0),e),a=parseInt(t.slice(13,16),10),i={hash:`SHA-${t.slice(8,11)}`,iterations:r,name:"PBKDF2",salt:o},s=await mn(n,t);return new Uint8Array(await crypto.subtle.deriveBits(i,s,a))}function Dt(e){return x(Ve(e.length),e)}async function yn(e,t,r){let n=t>>3,o=32,a=Math.ceil(n/32),i=new Uint8Array(a*32);for(let s=1;s<=a;s++){let c=await rt("sha256",x(Ve(s),e,r));i.set(c,(s-1)*32)}return i.slice(0,n)}async function lr(e,t,r,n,o=new Uint8Array,a=new Uint8Array){cr(e),cr(t,"deriveBits");let i=x(Dt(b(r)),Dt(o),Dt(a),Ve(n)),s=new Uint8Array(await crypto.subtle.deriveBits({name:e.algorithm.name,public:e},t,e.algorithm.name==="X25519"?256:Math.ceil(parseInt(e.algorithm.namedCurve.slice(-3),10)/8)<<3));return yn(s,n,i)}function mr(e){Xe(e);let t=e.algorithm.namedCurve;if(t!=="P-256"&&t!=="P-384"&&t!=="P-521"&&e.algorithm.name!=="X25519")throw new m("ECDH with the provided key is not allowed or not supported by your javascript runtime")}function De(e){if(e===void 0)throw new u("JWE Encrypted Key missing")}function pr(e){if(e!==void 0)throw new u("Encountered unexpected JWE Encrypted Key")}async function hr(e,t,r,n,o,a){let i=k(e);if(e==="dir")return pr(n),r;switch(i.subtle.name){case"ECDH":{if(e==="ECDH-ES")pr(n);if(!S(o.epk))throw new u('JOSE Header "epk" (Ephemeral Public Key) missing or invalid');mr(r);let s=await Y(i,o.epk),c,p;if(o.apu!==void 0){if(typeof o.apu!=="string")throw new u('JOSE Header "apu" (Agreement PartyUInfo) invalid');c=v(o.apu,"apu",u)}if(o.apv!==void 0){if(typeof o.apv!=="string")throw new u('JOSE Header "apv" (Agreement PartyVInfo) invalid');p=v(o.apv,"apv",u)}let d=await lr(s,r,e==="ECDH-ES"?t.alg:e,e==="ECDH-ES"?t.cekBits:parseInt(e.slice(-5,-2),10),c,p);if(e==="ECDH-ES")return d;return De(n),_t(e.slice(-6),d,n)}case"RSA-OAEP":return De(n),Xe(r),ur(e,r,"decrypt"),new Uint8Array(await crypto.subtle.decrypt("RSA-OAEP",r,n));case"PBKDF2":{if(De(n),typeof o.p2c!=="number")throw new u('JOSE Header "p2c" (PBES2 Count) missing or invalid');let s=a||1e4;if(o.p2c>s)throw new u('JOSE Header "p2c" (PBES2 Count) out is of acceptable bounds');if(typeof o.p2s!=="string")throw new u('JOSE Header "p2s" (PBES2 Salt) missing or invalid');let c=v(o.p2s,"p2s",u),p=await fr(c,e,o.p2c,r);return _t(e.slice(-6),p,n)}case"AES-KW":return De(n),_t(e,r,n);case"AES-GCM":{if(De(n),typeof o.iv!=="string")throw new u('JOSE Header "iv" (Initialization Vector) missing or invalid');if(typeof o.tag!=="string")throw new u('JOSE Header "tag" (Authentication Tag) missing or invalid');let s;s=v(o.iv,"iv",u);let c;return c=v(o.tag,"tag",u),Ze(ce(e.slice(0,-2)),r,n,s,c,new Uint8Array)}}}async function wr(e,t,r,n,o={}){let a,i,s,c=k(e);if(e==="dir")return[r,void 0,void 0];switch(c.subtle.name){case"ECDH":{mr(r);let{apu:p,apv:d}=o;if(p!==void 0)ae(p,'"apu"');if(d!==void 0)ae(d,'"apv"');let f;if(o.epk!==void 0)f=await R(c,o.epk,"decrypt");else f=(await crypto.subtle.generateKey(r.algorithm,!0,["deriveBits"])).privateKey;let l=crypto.subtle,K=f;if(!K.extractable){if(typeof l.getPublicKey!=="function")throw TypeError('CryptoKey for "epk" must be extractable');K=await l.getPublicKey(f,[])}let{x:I,y:g,crv:w,kty:T}=await l.exportKey("jwk",K),y=await lr(r,f,e==="ECDH-ES"?t.alg:e,e==="ECDH-ES"?t.cekBits:parseInt(e.slice(-5,-2),10),p,d);if(i={epk:{x:I,crv:w,kty:T}},T==="EC")i.epk.y=g;if(p)i.apu=B(p);if(d)i.apv=B(d);if(e==="ECDH-ES"){s=y;break}s=n||F(t);let J=e.slice(-6);a=await Ot(J,y,s);break}case"RSA-OAEP":{s=n||F(t),Xe(r),ur(e,r,"encrypt"),a=new Uint8Array(await crypto.subtle.encrypt("RSA-OAEP",r,s));break}case"PBKDF2":{s=n||F(t);let{p2c:p=2048,p2s:d=crypto.getRandomValues(new Uint8Array(16))}=o,f=await fr(d,e,p,r);a=await Ot(e.slice(-6),f,s),i={p2c:p,p2s:B(d)};break}case"AES-KW":{s=n||F(t),a=await Ot(e,r,s);break}case"AES-GCM":{s=n||F(t);let{iv:p}=o,d=await qe(ce(e.slice(0,-2)),s,r,p,new Uint8Array);a=d.ciphertext,i={iv:B(d.iv),tag:B(d.tag)};break}}return[s,a,i]}var we={__proto__:null,b64:!0},ct={__proto__:null};function Ue(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)}function pt(e,t){let{crit:r}=t??{};if(Array.isArray(r)&&new Set(r).size!==r.length)throw new e('"crit" (Critical) Header Parameter MUST NOT contain duplicate values')}function M(e,t,r,n,o){if(o.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[];if(!Array.isArray(n.crit)||n.crit.length===0||n.crit.some((i)=>typeof i!=="string"||i.length===0))throw new e('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');let a=r===void 0?t:{__proto__:null,...r,...t};for(let i of n.crit){if(!(i in a))throw new m(`Extension Header Parameter "${i}" is not recognized`);if(!Object.hasOwn(o,i)||o[i]===void 0)throw new e(`Extension Header Parameter "${i}" is missing`);if(a[i]&&(!Object.hasOwn(n,i)||n[i]===void 0))throw new e(`Extension Header Parameter "${i}" MUST be integrity protected`)}return n.crit}function ge(e,t){if(t.includes("b64")){let r=e.b64;if(typeof r!=="boolean")throw new h('The "b64" (base64url-encode payload) Header Parameter must be a boolean');return r}return!0}function Ee(e,t){let r,n;try{r=JSON.stringify(t),n=JSON.parse(r)}catch(o){throw new e("JOSE Header is not valid JSON",{cause:o})}if(!S(n))throw new e("JOSE Header is not a JSON object");return[n,r]}function dt(e,t){if(e.zip!==void 0&&e.zip!=="DEF")throw new m('Unsupported JWE "zip" (Compression Algorithm) Header Parameter value.');if(e.zip!==void 0&&!t?.zip)throw new u('JWE "zip" (Compression Algorithm) Header Parameter MUST be in a protected header.')}function gr(e){if(typeof globalThis[e]>"u")throw new m(`JWE "zip" (Compression Algorithm) Header Parameter requires the ${e} API.`)}async function br(e){gr("CompressionStream");let t=new CompressionStream("deflate-raw"),r=t.writable.getWriter();r.write(e).catch(()=>{}),r.close().catch(()=>{});let n=[],o=t.readable.getReader();for(;;){let{value:a,done:i}=await o.read();if(i)break;n.push(a)}return x(...n)}async function Sr(e,t){gr("DecompressionStream");let r=new DecompressionStream("deflate-raw"),n=r.writable.getWriter();n.write(e).catch(()=>{}),n.close().catch(()=>{});let o=[],a=0,i=r.readable.getReader();for(;;){let{value:s,done:c}=await i.read();if(c)break;if(o.push(s),a+=s.byteLength,t!==1/0&&a>t)throw new u("Decompressed plaintext exceeded the configured limit")}return x(...o)}function xr(e){return[e&&Ue("keyManagementAlgorithms",e.keyManagementAlgorithms),e&&Ue("contentEncryptionAlgorithms",e.contentEncryptionAlgorithms),e?.crit,e?.maxPBES2Count,e?.maxDecompressedLength]}async function hn(e,t,r,n,o){let[a,i,s,c,p]=r,[d,f,l,K,I]=t,{encrypted_key:g}=e;M(u,ct,s,d,o),dt(o,d);let{alg:w,enc:T}=o;if(typeof w!=="string"||!w)throw new u("missing JWE Algorithm (alg) in JWE Header");if(typeof T!=="string"||!T)throw new u("missing JWE Encryption Algorithm (enc) in JWE Header");if(a&&!a.has(w)||!a&&w.startsWith("PBES2"))throw new ie('"alg" (Algorithm) Header Parameter value not allowed');if(i&&!i.has(T))throw new ie('"enc" (Encryption Algorithm) Header Parameter value not allowed');let y=ce(T),J;if(g!==void 0)J=v(g,"encrypted_key",u);let O=!1;if(typeof n==="function")n=await n(d,e),O=!0;let L=k(w),U=await R(w==="dir"?y:L,n,"decrypt"),_;try{if(_=await hr(w,y,U,J,o,c),g!==void 0&&_ instanceof Uint8Array&&_.byteLength<<3!==y.cekBits)_=F(y)}catch(P){if(P instanceof TypeError||P instanceof u||P instanceof m)throw P;_=F(y)}let re=await Ze(y,_,f,l,K,I);if(o.zip==="DEF"){let P=p??250000;if(P===0)throw new m('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');if(P!==1/0&&(!Number.isSafeInteger(P)||P<1))throw TypeError("maxDecompressedLength must be 0, a positive safe integer, or Infinity");re=await Sr(re,P).catch((ne)=>{if(ne instanceof u)throw ne;throw new u("Failed to decompress plaintext",{cause:ne})})}return[re,d,U,O]}async function Ar(e,t,r){if(e instanceof Uint8Array)e=oe.decode(e);if(typeof e!=="string")throw new u("Compact JWE must be a string or Uint8Array");let{0:n,1:o,2:a,3:i,4:s,length:c}=e.split(".");if(c!==5)throw new u("Invalid Compact JWE");let p={ciphertext:i,iv:a||void 0,protected:n,tag:s||void 0,encrypted_key:o||void 0},d=ee(n,u,"JWE Protected Header is invalid"),f=b(n),l=[d,v(i,"ciphertext",u),a?v(a,"iv",u):void 0,s?v(s,"tag",u):void 0,f];return hn(p,l,t,r,d)}function Kr(e,t,r){if(!er(e,t,r))throw new u("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint")}function gn(e){let[,t,r,n,o,a,i,s,c]=e;if(o!==void 0)ae(o,"JWE Additional Authenticated Data");if(a!==void 0)ae(a,"JWE Content Encryption Key");if(i!==void 0)ae(i,"JWE Initialization Vector");if(t!==void 0)t=Ee(u,t)[0],e[1]=t;if(r!==void 0)r=Ee(u,r)[0],e[2]=r;if(n!==void 0)n=Ee(u,n)[0],e[3]=n;if(s!==void 0&&!S(s))throw TypeError("JWE Key Management Parameters must be an object");Kr(t,r,n);let p={...t,...r,...n};pt(u,t),M(u,ct,c,t,p),dt(p,t);let{alg:d,enc:f}=p;if(typeof d!=="string"||!d)throw new u('JWE "alg" (Algorithm) Header Parameter missing or invalid');if(typeof f!=="string"||!f)throw new u('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');return[p,d,f,ce(f)]}async function En(e,t,r){let[n,o,,a]=t,[i,s,c,p,d,f,l,K,,I]=e,g=s,w=c;if(f&&(o==="dir"||o==="ECDH-ES"))throw TypeError(`setContentEncryptionKey cannot be called with JWE "alg" (Algorithm) Header ${o}`);let T=k(o),y=await R(o==="dir"?a:T,r,"encrypt"),[J,O,L]=await wr(o,a,y,f,K);if(L){if(I)w=w?{...w,...L}:L;else g=g?{...g,...L}:L;Kr(g,w,p)}let U,_;if(g)U=B(JSON.stringify(g)),_=b(U);else U="",_=new Uint8Array;let re,P;if(d?.byteLength)P=B(d),re=x(_,b("."),b(P));else re=_;let ne=i;if(n.zip==="DEF")ne=await br(ne).catch((Mr)=>{throw new u("Failed to compress plaintext",{cause:Mr})});let{ciphertext:Br,tag:zt,iv:Gt}=await qe(a,ne,J,l,re),Q={ciphertext:B(Br)};if(Gt)Q.iv=B(Gt);if(zt)Q.tag=B(zt);if(O)Q.encrypted_key=B(O);if(P)Q.aad=P;if(g)Q.protected=U;if(p)Q.unprotected=p;if(w)Q.header=w;return Q}async function Jr(e,t,r){if(!e[1]&&!e[2]&&!e[3])throw new u("either setProtectedHeader, setUnprotectedHeader, or sharedUnprotectedHeader must be called before #encrypt()");if(r!==void 0)e[8]=r?.crit,e[9]=r?tr in r:!1;return En(e,gn(e),t)}async function vr(e,t,r){if(t instanceof Uint8Array)return crypto.subtle.importKey("raw",t,e.subtle,!1,[r]);if(j(t,e.subtle,r),e.minRsaBits)Ge(e.alg,t);return t}async function Wr(e,t,r){let n=await vr(e,t,"sign"),o=await crypto.subtle.sign(e.signing,n,r);return new Uint8Array(o)}async function Pr(e,t,r,n){let o=await vr(e,t,"verify");try{return await crypto.subtle.verify(e.signing,o,r,n)}catch{return!1}}var Ne=[["verify"],["sign"]];function Ut(e){let t={name:"HMAC",hash:`SHA-${e}`};return{kty:["oct"],secret:!0,subtle:t,signing:t,usages:Ne}}function be(e,t){let n={name:t?"RSA-PSS":"RSASSA-PKCS1-v1_5",hash:`SHA-${e}`};return{kty:["RSA"],subtle:n,signing:t?{...n,saltLength:t}:n,usages:Ne,minRsaBits:2048}}function Nt(e,t){return{kty:["EC"],crv:e,subtle:{name:"ECDSA",namedCurve:e},signing:{name:"ECDSA",hash:`SHA-${t}`},usages:Ne}}function Tr(){let e={name:"Ed25519"};return{kty:["OKP"],crv:"Ed25519",subtle:e,signing:e,usages:Ne}}function Rt(e){let r={name:`ML-DSA-${e}`};return{kty:["AKP"],subtle:r,signing:r,usages:Ne}}var Re=_e({HS256:Ut(256),HS384:Ut(384),HS512:Ut(512),RS256:be(256),RS384:be(384),RS512:be(512),PS256:be(256,32),PS384:be(384,48),PS512:be(512,64),ES256:Nt("P-256",256),ES384:Nt("P-384",384),ES512:Nt("P-521",512),EdDSA:Tr(),Ed25519:Tr(),"ML-DSA-44":Rt(44),"ML-DSA-65":Rt(65),"ML-DSA-87":Rt(87)});function ut(e){let t=typeof e==="string"?Re[e]:void 0;if(!t)throw new m(`alg ${e} is not supported either by JOSE or your javascript runtime`);return t}function ft(e){return[e&&Ue("algorithms",e.algorithms),e?.crit]}function bn(e,t=e===void 0?{}:ee(e,h,"JWS Protected Header is invalid")){return t}function Sn(e,t,r){let n=ge(e,M(h,we,r[1],e,t)),o=t.alg;if(typeof o!=="string"||!o)throw new h('JWS "alg" (Algorithm) Header Parameter missing or invalid');if(r[0]&&!r[0].has(o))throw new ie('"alg" (Algorithm) Header Parameter value not allowed');return[n,o]}function xn(e){try{return b(e)}catch{throw new h("JWS Compact Serialization payload must use only ASCII characters")}}async function An(e,t,r,n,o,a,i){let s=!1;if(typeof r==="function")r=await r(o,e),s=!0;let c=typeof i==="string",p=ut(a),d=x(n!==void 0?b(n):new Uint8Array,b("."),c?t[2]??=Jt(i,"payload",h):i),f=v(e.signature,"signature",h),l=await R(p,r,"verify");if(!await Pr(p,l,f,d))throw new Fe;return[c?v(i,"payload",h):i,o,c,l,s]}async function lt(e,t,r){if(e instanceof Uint8Array)e=oe.decode(e);if(typeof e!=="string")throw new h("Compact JWS must be a string or Uint8Array");let{0:n,1:o,2:a,length:i}=e.split(".");if(i!==3)throw new h("Invalid Compact JWS");let s={payload:o,protected:n,signature:a},c=bn(n),[p,d]=Sn(c,c,t),f=p?o:xn(o);return An(s,t,r,n,c,d,f)}async function yr(e,t,r){let n=await lt(e,ft(r),t),o={payload:n[0],protectedHeader:n[1]};if(typeof t==="function")return{...o,key:n[3]};return o}var He=(e)=>Math.floor(e.getTime()/1000),Kn={s:1,m:60,h:3600,d:86400,w:604800,y:31557600},Jn=/^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i,xe="check_failed";function Ht(){throw TypeError("Invalid time period format")}function mt(e){if(typeof e!=="string")Ht();let t=Jn.exec(e);if(!t||t[4]&&t[1])Ht();let r=parseFloat(t[2]),n=Math.round(r*Kn[t[3][0].toLowerCase()]);if(!Number.isFinite(n))Ht();if(t[1]==="-"||t[4]==="ago")return-n;return n}function Ae(e,t){if(!Number.isFinite(t))throw TypeError(`Invalid ${e} input`);return t}function kt(e,t){if(typeof t!=="string")throw TypeError(`"${e}" claim must be a string`)}function Cn(e){if(typeof e!=="string"&&(!Array.isArray(e)||Array.from(e).some((t)=>typeof t!=="string")))throw TypeError('"aud" claim must be a string or an array of strings')}function Bt(e,t){if(typeof e==="number")return Ae(t,e);if(e instanceof Date)return Ae(t,He(e));return He(new Date)+mt(e)}var Ir=(e)=>{let t=e.toLowerCase();return e.includes("/")?t:`application/${t}`},Wn=(e,t)=>{if(typeof e==="string")return t.includes(e);if(Array.isArray(e))return t.some((r)=>e.includes(r));return!1};function Mt(e,t,r=!1){let n=e[t];if(n===void 0&&!r)return;if(typeof n!=="number")throw new D(`"${t}" claim must be a number`,e,t,"invalid");return n}function $t(e,t){throw new D(`unexpected "${t}" claim value`,e,t,xe)}function Ke(e,t,r={}){let n;try{n=JSON.parse(fe.decode(t))}catch{}if(!S(n))throw new H("JWT Claims Set must be a top-level JSON object");let{typ:o}=r;if(o!==void 0&&(typeof e.typ!=="string"||Ir(e.typ)!==Ir(o)))throw new D('unexpected "typ" JWT header value',n,"typ",xe);let{requiredClaims:a=[],issuer:i,subject:s,audience:c,maxTokenAge:p}=r,d=[...a];if(p!==void 0)d.push("iat");if(c!==void 0)d.push("aud");if(s!==void 0)d.push("sub");if(i!==void 0)d.push("iss");for(let y of new Set(d.reverse()))if(!Object.hasOwn(n,y))throw new D(`missing required "${y}" claim`,n,y,"missing");if(i!==void 0&&!(Array.isArray(i)?i:[i]).includes(n.iss))$t(n,"iss");if(s!==void 0&&n.sub!==s)$t(n,"sub");if(c!==void 0&&!Wn(n.aud,typeof c==="string"?[c]:c))$t(n,"aud");let{clockTolerance:f}=r,l=0;if(typeof f==="string")l=mt(f);else if(f!==void 0){if(typeof f!=="number")throw TypeError("Invalid clockTolerance option type");l=f}Ae("clockTolerance option",l);let{currentDate:K}=r,I=Ae("currentDate option",He(K===void 0?new Date:K)),g=Mt(n,"iat",p!==void 0),w=Mt(n,"nbf");if(w!==void 0){if(w>I+l)throw new D('"nbf" claim timestamp check failed',n,"nbf",xe)}let T=Mt(n,"exp");if(T!==void 0){if(T<=I-l)throw new tt('"exp" claim timestamp check failed',n,"exp",xe)}if(p!==void 0){let y=I-g,J=Ae("maxTokenAge option",typeof p==="number"?p:mt(p));if(y-l>J)throw new tt('"iat" claim timestamp check failed (too far in the past)',n,"iat",xe);if(y<-l)throw new D('"iat" claim timestamp check failed (it should be in the past)',n,"iat",xe)}return n}var Or;function q(e){return Or.get(e)}function Je(e){let t=q(e);for(let r of["iat","nbf","exp"]){let n=t[r];if(typeof n==="number"&&!Number.isFinite(n))throw TypeError(`"${r}" claim must be a finite number`)}return We.encode(JSON.stringify(t))}function ht(e,t){return q(e)[t]}class pe{constructor(e={}){if(!S(e))throw TypeError("JWT Claims Set MUST be an object");(Or||=new WeakMap).set(this,structuredClone(e))}setIssuer(e){return kt("iss",e),q(this).iss=e,this}setSubject(e){return kt("sub",e),q(this).sub=e,this}setAudience(e){return Cn(e),q(this).aud=e,this}setJti(e){return kt("jti",e),q(this).jti=e,this}setNotBefore(e){return q(this).nbf=Bt(e,"setNotBefore"),this}setExpirationTime(e){return q(this).exp=Bt(e,"setExpirationTime"),this}setIssuedAt(e){let t=q(this);if(e===void 0)t.iat=He(new Date);else if(typeof e==="string")t.iat=Ae("setIssuedAt",He(new Date)+mt(e));else t.iat=Bt(e,"setIssuedAt");return this}}async function V(e,t,r){let n=await lt(e,ft(r),t);if(!n[2])throw new H("JWTs MUST NOT use unencoded payload");let a={payload:Ke(n[1],n[0],r),protectedHeader:n[1]};if(typeof t==="function")return{...a,key:n[3]};return a}async function Er(e,t,r){let n=await Ar(e,xr(r),t),o=n[1],a=Ke(o,n[0],r);for(let s of["iss","sub","aud"])if(o[s]!==void 0&&(s==="aud"?JSON.stringify(o.aud)!==JSON.stringify(a.aud):o[s]!==a[s]))throw new D(`replicated "${s}" claim header parameter mismatch`,a,s,"mismatch");let i={payload:a,protectedHeader:o};if(typeof t==="function")return{...i,key:n[2]};return i}function Pn(e){if(e===void 0)return[void 0,""];let t=Ee(h,e);return[t[0],B(t[1])]}function Tn(e,t,r){return pt(h,e),ge(e,M(h,we,r,e,t))}function In(e){let t=e.alg;if(typeof t!=="string"||!t)throw new h('JWS "alg" (Algorithm) Header Parameter missing or invalid');return ut(t)}async function On(e,t,r,n){let o=x(b(e),b("."),t),a=await R(r,n,"sign");return B(await Wr(r,a,o))}async function _r(e,t,r,n,o){let[a,i]=Pn(t);if(!a)throw new h("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");if(!Tn(a,a,r))o();let c=In(a),p=B(e),d=await On(i,b(p),c,n);return`${i}.${p}.${d}`}var _n=pe;class ke extends _n{#e;setProtectedHeader(e){return se(this.#e,"setProtectedHeader"),this.#e=e,this}async sign(e,t){return _r(Je(this),this.#e,t?.crit,e,()=>{throw new H("JWTs MUST NOT use unencoded payload")})}}var Dn=pe;class Cr extends Dn{#e;#r;#n;#t;#o;#i;#a;setProtectedHeader(e){return se(this.#t,"setProtectedHeader"),this.#t=e,this}setKeyManagementParameters(e){return se(this.#n,"setKeyManagementParameters"),this.#n=e,this}setContentEncryptionKey(e){return se(this.#e,"setContentEncryptionKey"),this.#e=e,this}setInitializationVector(e){return se(this.#r,"setInitializationVector"),this.#r=e,this}replicateIssuerAsHeader(){return this.#o=!0,this}replicateSubjectAsHeader(){return this.#i=!0,this}replicateAudienceAsHeader(){return this.#a=!0,this}async encrypt(e,t){let r=Je(this);if(this.#t&&(this.#o||this.#i||this.#a))this.#t={...this.#t,iss:this.#o?ht(this,"iss"):void 0,sub:this.#i?ht(this,"sub"):void 0,aud:this.#a?ht(this,"aud"):void 0};let n=await Jr([r,this.#t,void 0,void 0,void 0,this.#e,this.#r,this.#n,void 0,!1],e,t);return[n.protected,n.encrypted_key,n.iv,n.ciphertext,n.tag].join(".")}}var ve='"alg" (Algorithm)';function Be(e='JWK "alg" (Algorithm) Parameter'){throw new m(`Invalid or unsupported ${e} value`)}function de(e,t){return(typeof e==="string"?Re[e]??Tt[e]:void 0)??Be(t)}function Ce(e){if(e!==void 0&&typeof e!=="boolean")throw TypeError('"extractable" option must be a boolean');return e}var Me=(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},Un=(e)=>({data:e,pos:0}),jt=(e)=>{let t=e.data[e.pos++];if(t===void 0)throw Error("Unexpected end of ASN.1 input");return t},Le=(e)=>{let t=jt(e);if(t&128){let r=t&127,n=0;for(let o=0;o<r;o++)n=n<<8|jt(e);return n}return t};var $e=(e,t,r)=>{if(jt(e)!==t)throw Error(r)},Dr=(e,t)=>{if(t<0||e.pos+t>e.data.length)throw Error("Unexpected end of ASN.1 input");let r=e.data.subarray(e.pos,e.pos+t);return e.pos+=t,r},Nn=(e)=>{$e(e,6,"Expected algorithm OID");let t=Le(e);return Dr(e,t)};function Hn(e,t){if($e(e,48,`Invalid ${t==="spki"?"SPKI":"PKCS#8"} structure`),Le(e),t==="pkcs8"){$e(e,2,"Expected version field");let r=Le(e);e.pos+=r}$e(e,48,"Expected algorithm identifier"),Le(e)}var kn=(e)=>{let t=Nn(e);if(Me(t,[43,101,110]))return"X25519";if(!Me(t,[42,134,72,206,61,2,1]))throw Error("Unsupported key algorithm");$e(e,6,"Expected curve OID");let r=Le(e),n=Dr(e,r);if(Me(n,[42,134,72,206,61,3,1,7]))return"P-256";if(Me(n,[43,129,4,0,34]))return"P-384";if(Me(n,[43,129,4,0,35]))return"P-521";throw Error("Unsupported named curve")},Bn=async(e,t,r,n)=>{let o=Ce(n?.extractable),a=de(r,ve);if(a.secret)Be(ve);let i=e==="spki",s;if(a.resolve)try{let c=Un(t);Hn(c,e),s=a.resolve({crv:kn(c)})}catch{throw new m("Invalid or unsupported key format")}else s=a.subtle;return crypto.subtle.importKey(e,t,s,o??i,a.usages[i?0:1])},Mn=(e,t)=>Qe(e.replace(t,"")),Ur=(e,t,r)=>{let n=Mn(e,/(?:-----(?:BEGIN|END) PRIVATE KEY-----|\s)/g);return Bn("pkcs8",n,t,r)};function Ln(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0))}async function $n(e){if(xt(e))if(e.type==="secret")e=e.export();else return e.export({format:"jwk"});if(e instanceof Uint8Array)return{kty:"oct",k:B(e)};if(!G(e))throw TypeError(z(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:o,...a}=Ln(await crypto.subtle.exportKey("jwk",e));if(a.kty==="AKP")a.alg=n;return a}function Ct(e){return $n(e)}var Z=(e,t)=>{if(typeof e!=="string"||!e)throw new Oe(`${t} missing or invalid`)};async function It(e,t){let r;if(S(e)){if(r=me(e),typeof r.kty!=="string")throw TypeError(z(e,"CryptoKey","KeyObject","JSON Web Key"))}else if(Ye(e))r=me(await Ct(e));else throw TypeError(z(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":Z(r.alg,'"alg" (Algorithm) Parameter'),Z(r.pub,'"pub" (Public key) Parameter'),n={alg:r.alg,kty:r.kty,pub:r.pub};break;case"EC":Z(r.crv,'"crv" (Curve) Parameter'),Z(r.x,'"x" (X Coordinate) Parameter'),Z(r.y,'"y" (Y Coordinate) Parameter'),n={crv:r.crv,kty:r.kty,x:r.x,y:r.y};break;case"OKP":Z(r.crv,'"crv" (Subtype of Key Pair) Parameter'),Z(r.x,'"x" (Public Key) Parameter'),n={crv:r.crv,kty:r.kty,x:r.x};break;case"RSA":Z(r.e,'"e" (Exponent) Parameter'),Z(r.n,'"n" (Modulus) Parameter'),n={e:r.e,kty:r.kty,n:r.n};break;case"oct":if(typeof r.k!=="string")throw new Oe('"k" (Key Value) Parameter missing or invalid');n={k:r.k,kty:r.kty};break;default:throw new m('"kty" (Key Type) Parameter missing or unsupported')}let o=b(JSON.stringify(n));return B(await rt(t,o))}function jn(e,t,r,n){let{kty:o,key_ops:a,ext:i,kid:s,alg:c,use:p,crv:d}=me(e),f=Array.isArray(a)?[...a]:a;return(i===void 0||typeof i==="boolean")&&(f===void 0||Array.isArray(f)&&f.every((l,K)=>typeof l==="string"&&f.indexOf(l)===K)&&f.includes("verify"))&&t.kty.includes(o)&&(n===void 0||typeof n==="string"&&n===s)&&(c===void 0?o!=="AKP":r===c)&&(p===void 0||p==="sig")&&(!t.crv||d===t.crv)}async function Nr(e,t,r){let n=e.get(t)||e.set(t,{}).get(t),{alg:o}=r;if(n[o]===void 0){let a=await Y(r,{...t,alg:o,ext:!0});if(a.type!=="public")throw new yt("JSON Web Key Set members must be public keys");n[o]=a}return n[o]}function Se(e){let t;try{t=structuredClone(e)}catch{}if(!et(t))throw new yt("JSON Web Key Set malformed");let r=new WeakMap;return Object.defineProperty(async(o,a)=>{let{alg:i,kid:s}={...o,...a?.header},c=typeof i==="string"?Re[i]:void 0;if(!c||c.secret)throw new m('Unsupported "alg" value for a JSON Web Key Set');let p=t.keys.filter((l)=>jn(l,c,i,s)),{0:d,length:f}=p;if(!f)throw new le;if(f!==1){let l=new Lt;throw l[Symbol.asyncIterator]=async function*(){for(let K of p)try{yield await Nr(r,K,c)}catch{}},l}return Nr(r,d,c)},"jwks",{value:()=>structuredClone(t)})}function Vn(){return typeof WebSocketPair<"u"||typeof navigator<"u"&&navigator.userAgent==="Cloudflare-Workers"||typeof EdgeRuntime<"u"&&EdgeRuntime==="vercel"}var Vt;if(typeof navigator>"u"||!navigator.userAgent?.startsWith?.("Mozilla/5.0 "))Vt="jose/v6.2.10";var Hr=Symbol();async function zn(e,t,r,n=fetch){let o=await n(e,{method:"GET",signal:r,redirect:"manual",headers:t}).catch((a)=>{if(a.name==="TimeoutError")throw new Et;throw a});if(o.status!==200)throw new X("Expected 200 OK from the JSON Web Key Set HTTP response");try{return await o.json()}catch{throw new X("Failed to parse the JSON Web Key Set HTTP response as JSON")}}var kr=Symbol();function je(e,t){return Number.isFinite(e)&&Date.now()<e+t}function Rr(e,t,r){if(Number.isNaN(e))throw TypeError(`"${r}" option must not be NaN`);return typeof e==="number"?e:t}function Fr(e,t){if(!(e instanceof URL))throw TypeError("url must be an instance of URL");let r=new URL(e.href).href,n=t??{},o=n.timeoutDuration;if(typeof o==="number"&&(!Number.isInteger(o)||o<0))throw TypeError('"timeoutDuration" option must be a non-negative integer');let a=typeof o==="number"?o:5000,i=Rr(n.cooldownDuration,30000,"cooldownDuration"),s=Rr(n.cacheMaxAge,600000,"cacheMaxAge"),c=new Headers(n.headers);if(Vt&&!c.has("User-Agent"))c.set("User-Agent",Vt);if(!c.has("accept"))c.set("accept","application/json, application/jwk-set+json");let p=n[Hr],d=n[kr],f,l,K=0,I=0,g;if(d&&typeof d==="object"){let{uat:y,jwks:J}=d;if(je(y,s)&&et(J))f=y,g=Se(J)}let w=async()=>{if(l&&Vn())l=void 0;if(!l){let y=++K,J=l=zn(r,c,AbortSignal.timeout(a),p).then((O)=>{let L=Se(O);if(y<=I)return;g=L;let U=Date.now();if(d)d.uat=U,d.jwks=O;f=U,I=y}).finally(()=>{if(l===J)l=void 0})}await l};return Object.defineProperties(async(y,J)=>{if(!g||!je(f,s))await w();try{return await g(y,J)}catch(O){if(O instanceof le&&!je(f,i))return await w(),g(y,J);throw O}},{coolingDown:{get:()=>je(f,i),enumerable:!0},fresh:{get:()=>je(f,s),enumerable:!0},reload:{value:w,enumerable:!0},reloading:{get:()=>!!l,enumerable:!0},jwks:{value:()=>g?.jwks(),enumerable:!0}})}var Gn=pe;class vn extends Gn{encode(){let e=B(JSON.stringify({alg:"none"})),t=B(Je(this));return`${e}.${t}.`}static decode(e,t){if(typeof e!=="string")throw new H("Unsecured JWT must be a string");let{0:r,1:n,2:o,length:a}=e.split(".");if(a!==3||o!=="")throw new H("Invalid Unsecured JWT");let i,s;try{i=ee(r,h,"JWS Protected Header is invalid");let p=M(h,we,void 0,i,i);s=ge(i,p)}catch(p){if(!(p instanceof h))throw p;throw new H("Invalid Unsecured JWT",{cause:p})}if(i.alg!=="none")throw new H("Invalid Unsecured JWT");if(!s)throw new H("JWTs MUST NOT use unencoded payload");return{payload:Ke(i,v(n,"payload",H),t),header:i}}}async function Rn(e,t,r){if(typeof e!=="string"||e.indexOf("-----BEGIN PRIVATE KEY-----")!==0)throw TypeError('"pkcs8" must be PKCS#8 formatted string');return Ur(e,t,r)}async function te(e,t,r){if(!S(e))throw TypeError("JWK must be an object");let n=nt(e),o=Ce(r?.extractable),{alg:a}=n;t??=a;let i=o??n.ext;if(n.kty!=="oct"&&!t)throw TypeError('"alg" argument is required when "jwk.alg" is not present');switch(n.kty){case"oct":if(typeof n.k!=="string")throw TypeError('missing "k" (Key Value) Parameter value');return N(n.k);case"AKP":{if(typeof a!=="string"||!a)throw TypeError('missing "alg" (Algorithm) Parameter value');if(t!==a)throw TypeError("JWK alg and alg option value mismatch");return Y(de(t),{...n,ext:i})}case"RSA":case"EC":case"OKP":return Y(de(t),{...n,alg:t,ext:i});default:throw new m('Unsupported "kty" (Key Type) Parameter value')}}function ue(e){let t;if(typeof e==="string"){let n=e.split(".");if(n.length===3||n.length===5)[t]=n}else if(typeof e==="object"&&e)if("protected"in e)t=e.protected;else throw TypeError("Token does not contain a Protected Header");let r="Invalid Token or Protected Header formatting";if(typeof t!=="string"||!t)throw TypeError(r);return ee(t,TypeError,r)}function W(e){if(typeof e!=="string")throw new H("JWTs must use Compact JWS serialization, JWT must be a string");let{1:t,length:r}=e.split(".");if(r===5)throw new H("Only JWTs using Compact JWS serialization can be decoded");if(r!==3)throw new H("Invalid JWT");if(!t)throw new H("JWTs must contain a payload");let n;try{n=N(t)}catch{throw new H("Failed to base64url decode the payload")}let o;try{o=JSON.parse(fe.decode(n))}catch{throw new H("Failed to parse the decoded payload as JSON")}if(!S(o))throw new H("Invalid JWT Claims Set");return o}function Fn(e){let t=e?.modulusLength??2048;if(typeof t!=="number"||!Number.isInteger(t)||t<2048)throw new m("Invalid or unsupported modulusLength option provided, 2048 bits or larger keys must be used");return t}async function zr(e,t){let r=Ce(t?.extractable),n=de(e,ve);if(n.secret)Be(ve);let o;if(n.resolve){let a=t?.crv??"P-256";switch(a){case"P-256":case"P-384":case"P-521":o={name:"ECDH",namedCurve:a};break;case"X25519":o={name:"X25519"};break;default:throw new m("Invalid or unsupported crv option provided, supported values are P-256, P-384, P-521, and X25519")}}else{if(n.crv!==void 0&&t?.crv!==void 0&&t.crv!==n.crv)throw new m(`Invalid or unsupported crv option provided, the only supported value for ${e} is ${n.crv}`);o=n.kty[0]==="RSA"?{...n.subtle,publicExponent:Uint8Array.of(1,0,1),modulusLength:Fn(t)}:n.subtle}return crypto.subtle.generateKey(o,r??!1,[...n.usages[1],...n.usages[0]])}export{E,A,Ie,C,X,tt,H,yt,Lt,Et,wn,B,un,yr,V,Er,ke,Cr,Ct,It,Se,Fr,vn,Rn,te,ue,W,zr};
|
|
2
|
+
var Lr=Object.create;var{getPrototypeOf:$r,defineProperty:wt,getOwnPropertyNames:jr}=Object;var Ft=Object.prototype.hasOwnProperty;function Vr(e){return this[e]}var Gr,Fr,E=(e,t,r)=>{var n=e!=null&&typeof e==="object";if(n){var o=t?Gr??=new WeakMap:Fr??=new WeakMap,a=o.get(e);if(a)return a}r=e!=null?Lr($r(e)):{};let i=t||!e||!e.__esModule||!Ft.call(e,"default")?wt(r,"default",{value:e,enumerable:!0}):r;if(e&&typeof e==="object"||typeof e==="function"){for(let s of jr(e))if(!Ft.call(i,s))wt(i,s,{get:Vr.bind(e,s),enumerable:!0})}if(n)o.set(e,i);return i};var A=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Xr=(e)=>e;function Yr(e,t){this[e]=Xr.bind(null,t)}var Ie=(e,t)=>{for(var r in t)wt(e,r,{get:t[r],enumerable:!0,configurable:!0,set:Yr.bind(t,r)})};var C=import.meta.require;var wn={};Ie(wn,{JOSEAlgNotAllowed:()=>ie,JOSEError:()=>X,JOSENotSupported:()=>m,JWEDecryptionFailed:()=>Te,JWEInvalid:()=>u,JWKInvalid:()=>Oe,JWKSInvalid:()=>yt,JWKSMultipleMatchingKeys:()=>Lt,JWKSNoMatchingKey:()=>le,JWKSTimeout:()=>Et,JWSInvalid:()=>h,JWSSignatureVerificationFailed:()=>Fe,JWTClaimValidationFailed:()=>D,JWTExpired:()=>tt,JWTInvalid:()=>H});var un={};Ie(un,{decode:()=>N,encode:()=>B});var We=new TextEncoder,oe=new TextDecoder,fe=new TextDecoder("utf-8",{fatal:!0});function x(...e){let t=e.reduce((o,{length:a})=>o+a,0),r=new Uint8Array(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}function gt(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 bt(e){let t=Math.floor(e/4294967296),r=e%4294967296,n=new Uint8Array(8);return gt(n,t,0),gt(n,r,4),n}function Ve(e){let t=new Uint8Array(4);return gt(t,e),t}function b(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}var ze=(e,t="algorithm.name")=>TypeError(`CryptoKey does not support this operation, its ${t} must be ${e}`);function St(e,t){if(t&&!e.usages.includes(t))throw TypeError(`CryptoKey does not support this operation, its usages must include ${t}.`)}function Ge(e,t){let{modulusLength:r}=t.algorithm;if(typeof r!=="number"||r<2048)throw TypeError(`${e} requires key modulusLength to be 2048 bits or larger`)}function j(e,t,r){let n=e.algorithm;if(n.name!==t.name)throw ze(t.name);if(t.hash&&n.hash?.name!==t.hash)throw ze(t.hash,"algorithm.hash");if(t.namedCurve&&n.namedCurve!==t.namedCurve)throw ze(t.namedCurve,"algorithm.namedCurve");if(t.length!==void 0&&n.length!==t.length)throw ze(t.length,"algorithm.length");St(e,r)}function Xt(e,t,...r){if(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 z=(e,...t)=>Xt("Key must be ",e,...t),Pe=(e,t,...r)=>Xt(`Key for the ${e} algorithm must be `,t,...r);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 D 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 tt 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 ie extends X{static code="ERR_JOSE_ALG_NOT_ALLOWED";code="ERR_JOSE_ALG_NOT_ALLOWED"}class m extends X{static code="ERR_JOSE_NOT_SUPPORTED";code="ERR_JOSE_NOT_SUPPORTED"}class Te extends X{static code="ERR_JWE_DECRYPTION_FAILED";code="ERR_JWE_DECRYPTION_FAILED";constructor(e="decryption operation failed",t){super(e,t)}}class u 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 H extends X{static code="ERR_JWT_INVALID";code="ERR_JWT_INVALID"}class Oe extends X{static code="ERR_JWK_INVALID";code="ERR_JWK_INVALID"}class yt extends X{static code="ERR_JWKS_INVALID";code="ERR_JWKS_INVALID"}class le 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 Lt extends X{[Symbol.asyncIterator]=async function*(){};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 Et extends X{static code="ERR_JWKS_TIMEOUT";code="ERR_JWKS_TIMEOUT";constructor(e="request timed out",t){super(e,t)}}class Fe 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 Xe(e){if(!G(e))throw Error("CryptoKey instance expected")}var G=(e)=>{if(e?.[Symbol.toStringTag]==="CryptoKey")return!0;try{return e instanceof CryptoKey}catch{return!1}},xt=(e)=>e?.[Symbol.toStringTag]==="KeyObject",Ye=(e)=>G(e)||xt(e);var F=(e)=>crypto.getRandomValues(new Uint8Array(e.cekBits>>3));function Yt(e,t){let r=e.byteLength<<3;if(r!==t)throw new u(`Invalid Content Encryption Key length. Expected ${t} bits, got ${r} bits`)}var qr=(e)=>crypto.getRandomValues(new Uint8Array(e.ivBits>>3));function qt(e,t){if(t.length<<3!==e.ivBits)throw new u("Invalid Initialization Vector length")}async function Zt(e,t,r){if(!(t instanceof Uint8Array))throw TypeError(z(t,"Uint8Array"));let n=e.cekBits>>1,o=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[o,a,n]}async function Qt(e,t,r){return new Uint8Array((await crypto.subtle.sign("HMAC",e,t)).slice(0,r>>3))}async function Zr(e,t,r,n,o){let[a,i,s]=await Zt(e,r,"encrypt"),c=new Uint8Array(await crypto.subtle.encrypt({iv:n,name:"AES-CBC"},a,t)),p=x(o,n,c,bt(o.length*8)),d=await Qt(i,p,s);return{ciphertext:c,tag:d,iv:n}}async function en(e,t){let r={name:"HMAC",hash:"SHA-256"},n=await crypto.subtle.generateKey(r,!1,["sign","verify"]),o=await crypto.subtle.sign(r,n,e);return crypto.subtle.verify(r,n,o,t)}async function tn(e,t,r,n,o,a){let[i,s,c]=await Zt(e,t,"decrypt"),p=x(a,n,r,bt(a.length*8)),d=await Qt(s,p,c);try{if(await en(o,d))return new Uint8Array(await crypto.subtle.decrypt({iv:n,name:"AES-CBC"},i,r))}catch{}throw new Te}async function rn(e,t,r,n,o){let a=r instanceof Uint8Array?await crypto.subtle.importKey("raw",r,"AES-GCM",!1,["encrypt"]):(j(r,e.subtle,"encrypt"),r),i=new Uint8Array(await crypto.subtle.encrypt({additionalData:o,iv:n,name:"AES-GCM",tagLength:128},a,t)),s=i.slice(-16);return{ciphertext:i.slice(0,-16),tag:s,iv:n}}async function nn(e,t,r,n,o,a){let i=t instanceof Uint8Array?await crypto.subtle.importKey("raw",t,"AES-GCM",!1,["decrypt"]):(j(t,e.subtle,"decrypt"),t);try{return new Uint8Array(await crypto.subtle.decrypt({additionalData:a,iv:n,name:"AES-GCM",tagLength:128},i,x(r,o)))}catch{throw new Te}}async function qe(e,t,r,n,o){if(!G(r)&&!(r instanceof Uint8Array))throw TypeError(z(r,"CryptoKey","KeyObject","Uint8Array","JSON Web Key"));if(n)qt(e,n);else n=qr(e);if(r instanceof Uint8Array)Yt(r,e.cekBits);return e.cbc?Zr(e,t,r,n,o):rn(e,t,r,n,o)}async function Ze(e,t,r,n,o,a){if(!G(t)&&!(t instanceof Uint8Array))throw TypeError(z(t,"CryptoKey","KeyObject","Uint8Array","JSON Web Key"));if(!n)throw new u("JWE Initialization Vector missing");if(!o)throw new u("JWE Authentication Tag missing");if(!e.cbc&&o.length!==16)throw new u("Invalid Authentication Tag length");if(qt(e,n),t instanceof Uint8Array)Yt(t,e.cekBits);return e.cbc?tn(e,t,r,n,o,a):nn(e,t,r,n,o,a)}function At(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 Qe(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}var Kt="The input to be decoded is not correctly encoded.";function N(e){if(Uint8Array.fromBase64)try{return Uint8Array.fromBase64(typeof e==="string"?e:oe.decode(e),{alphabet:"base64url"})}catch(r){throw TypeError(Kt,{cause:r})}let t=e;if(t instanceof Uint8Array)t=oe.decode(t);if(t.includes("+")||t.includes("/"))throw TypeError(Kt);t=t.replace(/-/g,"+").replace(/_/g,"/");try{return Qe(t)}catch{throw TypeError(Kt)}}function B(e){let t=e;if(typeof t==="string")t=We.encode(t);if(Uint8Array.prototype.toBase64)return t.toBase64({alphabet:"base64url",omitPadding:!0});return At(t).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function ae(e,t){if(!(e instanceof Uint8Array))throw TypeError(`${t} must be an instance of Uint8Array`)}function S(e){if(typeof e!=="object"||e===null||Object.prototype.toString.call(e)!=="[object Object]")return!1;let t=Object.getPrototypeOf(e);return t===null||Object.getPrototypeOf(t)===null}function et(e){return S(e)&&Array.isArray(e.keys)&&Array.from(e.keys).every(S)}function er(...e){let t=new Set;for(let r of e){if(!r)continue;for(let n of Object.keys(r)){if(t.has(n))return!1;t.add(n)}}return!0}var tr=Symbol();function se(e,t){if(e!==void 0)throw TypeError(`${t} can only be called once`)}function v(e,t,r){try{return N(e)}catch{throw new r(`Failed to base64url decode the ${t}`)}}function Jt(e,t,r){try{return b(e)}catch{throw new r(`The ${t} is not a valid base64url string`)}}async function rt(e,t){let r=`SHA-${e.slice(-3)}`;return new Uint8Array(await crypto.subtle.digest(r,t))}function ee(e,t,r){let n;try{n=JSON.parse(fe.decode(N(e)))}catch{throw new t(r)}if(!S(n))throw new t(r);return n}async function Y(e,t){if(t.kty==="RSA"&&"oth"in t&&t.oth!==void 0)throw new m('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');if(!e.kty.includes(t.kty))throw new m('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');let r=e.resolve?.({kty:t.kty,crv:t.crv})??e.subtle,n=!!(t.d||t.priv),o={...t};if(o.kty!=="AKP")delete o.alg;return delete o.use,crypto.subtle.importKey("jwk",o,r,t.ext??!n,t.key_ops??e.usages[n?1:0])}function me(e){return{__proto__:null,...e}}function nt(e){let t=me(e);if(t.ext!==void 0&&typeof t.ext!=="boolean")throw TypeError('"ext" (Extractable) Parameter must be a boolean');if(t.key_ops!==void 0){let r=t.key_ops,n=Array.isArray(r)?[...r]:void 0;if(!n||n.some((o)=>typeof o!=="string")||new Set(n).size!==n.length)throw TypeError('"key_ops" (Key Operations) Parameter must be an array of unique strings');t.key_ops=n}return t}var vt=(e)=>e[Symbol.toStringTag],on=(e,t,r)=>{let{alg:n}=e;if(t.use!==void 0){let o=r==="sign"||r==="verify"?"sig":"enc";if(t.use!==o)throw TypeError(`Invalid key for this operation, its "use" must be "${o}" when present`)}if(t.alg!==void 0&&t.alg!==n)throw TypeError(`Invalid key for this operation, its "alg" must be "${n}" when present`);if(Array.isArray(t.key_ops)){let o=r==="encrypt"||r==="decrypt"?e.ops?.[r==="encrypt"?0:1]:r;if(o&&!t.key_ops.includes(o))throw TypeError(`Invalid key for this operation, its "key_ops" must include "${o}" when present`)}};function an(e,t,r){let{alg:n,secret:o}=e,a=r==="decrypt"||r==="sign";if(o&&t instanceof Uint8Array)return[nr,t];if(S(t)){let i=nt(t);if(typeof i.kty!=="string")throw TypeError(o?Pe(n,t,"CryptoKey","KeyObject","JSON Web Key","Uint8Array"):Pe(n,t,"CryptoKey","KeyObject","JSON Web Key"));if(!(o?i.kty==="oct"&&typeof i.k==="string":i.kty!=="oct"&&(a?i.kty==="AKP"&&typeof i.priv==="string"||typeof i.d==="string":i.d===void 0&&i.priv===void 0)))throw TypeError(o?'JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present':`JSON Web Key for this operation must be a ${a?"private":"public"} JWK`);return on(e,i,r),[ar,t,i]}if(!Ye(t))throw TypeError(o?Pe(n,t,"CryptoKey","KeyObject","JSON Web Key","Uint8Array"):Pe(n,t,"CryptoKey","KeyObject","JSON Web Key"));if(o){if(t.type!=="secret")throw TypeError(`${vt(t)} instances for symmetric algorithms must be of type "secret"`)}else{if(t.type==="secret")throw TypeError(`${vt(t)} instances for asymmetric algorithms must not be of type "secret"`);let i=a?"private":"public";if((t.type==="public"||t.type==="private")&&t.type!==i){let s=r==="sign"?"signing":r==="verify"?"verifying":`${r.slice(0,-1)}tion`;throw TypeError(`${vt(t)} instances for asymmetric algorithm ${s} must be of type "${i}"`)}}return G(t)?[or,t]:[ir,t]}var nr=0,or=1,ir=2,ar=3,Wt,sn={__proto__:null,prime256v1:"P-256",secp384r1:"P-384",secp521r1:"P-521"};function ot(e,t,r){Wt||=new WeakMap;let n=Wt.get(e);if(r)if(n)n[t]=r;else Wt.set(e,{[t]:r});return r??n?.[t]}var rr=async(e,t,r)=>ot(e,r.alg)??ot(e,r.alg,await Y(r,{...t,alg:r.alg})),cn=(e,t)=>{let r=ot(e,t.alg);if(r)return r;let n=e.type==="public",o=t.usages[n?0:1],{asymmetricKeyType:a}=e,i=sn[e.asymmetricKeyDetails?.namedCurve],s=t.resolve?.({crv:i,asymmetricKeyType:a})??t.subtle;return ot(e,t.alg,e.toCryptoKey(s,n,o))};async function R(e,t,r){let n=an(e,t,r);switch(n[0]){case nr:case or:return n[1];case ar:{let o=n[1],a=n[2];if(a.kty==="oct")return N(a.k);if(!Object.isFrozen(o)){let{key_ops:i}=o;if(Array.isArray(i))Object.freeze(i);Object.freeze(o)}return rr(o,a,e)}case ir:{let o=n[1];if(o.type==="secret")return o.export();if("toCryptoKey"in o&&typeof o.toCryptoKey==="function")return cn(o,e);return rr(o,o.export({format:"jwk"}),e)}}}function _e(e){let t={__proto__:null};for(let r in e)t[r]={...e[r],alg:r};return t}var pn=[["encrypt","wrapKey"],["decrypt","unwrapKey"]],dn=[[],["deriveBits"]],st=[[],[]];function it(e){return{kty:["RSA"],subtle:{name:"RSA-OAEP",hash:`SHA-${e}`},usages:pn,ops:["wrapKey","unwrapKey"]}}function at(){return{kty:["EC","OKP"],subtle:{name:"ECDH"},resolve:({kty:e,crv:t,asymmetricKeyType:r})=>{if(t==="X25519"||r==="x25519")return{name:"X25519"};if(e==="OKP")throw new m('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');return{name:"ECDH",namedCurve:t}},usages:dn,ops:[void 0,"deriveBits"]}}function ye(e,t=!1){return{kty:["oct"],secret:!0,subtle:{name:t?"AES-GCM":"AES-KW",length:e},usages:st,ops:t?["encrypt","decrypt"]:["wrapKey","unwrapKey"]}}function Pt(){return{kty:["oct"],secret:!0,subtle:{name:"PBKDF2"},usages:st,ops:["deriveBits","deriveBits"]}}var Tt=_e({dir:{kty:["oct"],secret:!0,subtle:{name:"AES-GCM"},usages:st,ops:["encrypt","decrypt"]},"RSA-OAEP":it(1),"RSA-OAEP-256":it(256),"RSA-OAEP-384":it(384),"RSA-OAEP-512":it(512),"ECDH-ES":at(),"ECDH-ES+A128KW":at(),"ECDH-ES+A192KW":at(),"ECDH-ES+A256KW":at(),A128KW:ye(128),A192KW:ye(192),A256KW:ye(256),A128GCMKW:ye(128,!0),A192GCMKW:ye(192,!0),A256GCMKW:ye(256,!0),"PBES2-HS256+A128KW":Pt(),"PBES2-HS384+A192KW":Pt(),"PBES2-HS512+A256KW":Pt()}),fn=["encrypt","decrypt"];function he(e,t=!1){return{kty:["oct"],secret:!0,subtle:{name:t?"AES-CBC":"AES-GCM",length:e},usages:st,ops:fn,cekBits:e,ivBits:t?128:96,cbc:t}}var ln=_e({A128GCM:he(128),A192GCM:he(192),A256GCM:he(256),"A128CBC-HS256":he(256,!0),"A192CBC-HS384":he(384,!0),"A256CBC-HS512":he(512,!0)});function sr(e,t){throw new m(`Invalid or unsupported "${e}" (JWE ${t}) header value`)}function k(e){return(typeof e==="string"?Tt[e]:void 0)??sr("alg","Algorithm")}function ce(e){return(typeof e==="string"?ln[e]:void 0)??sr("enc","Encryption Algorithm")}function cr(e,t){if(e.algorithm.name!=="ECDH"&&e.algorithm.name!=="X25519")throw TypeError("CryptoKey does not support this operation, its algorithm.name must be ECDH or X25519");St(e,t)}async function dr(e,t,r){let n=k(t).subtle,o=e instanceof Uint8Array?await crypto.subtle.importKey("raw",e,"AES-KW",!0,[r]):e;return j(o,n,r),o}async function Ot(e,t,r){let n=await dr(t,e,"wrapKey"),o=await crypto.subtle.importKey("raw",r,{hash:"SHA-256",name:"HMAC"},!0,["sign"]);return new Uint8Array(await crypto.subtle.wrapKey("raw",o,n,"AES-KW"))}async function _t(e,t,r){let n=await dr(t,e,"unwrapKey"),o=await crypto.subtle.unwrapKey("raw",r,n,"AES-KW",{hash:"SHA-256",name:"HMAC"},!0,["sign"]);return new Uint8Array(await crypto.subtle.exportKey("raw",o))}function ur(e,t,r){j(t,k(e).subtle,r),Ge(e,t)}function mn(e,t){if(e instanceof Uint8Array)return crypto.subtle.importKey("raw",e,"PBKDF2",!1,["deriveBits"]);return j(e,k(t).subtle,"deriveBits"),e}async function fr(e,t,r,n){if(!(e instanceof Uint8Array)||e.length<8)throw new u("PBES2 Salt Input must be 8 or more octets");if(!Number.isSafeInteger(r)||Math.sign(r)!==1)throw new u("PBES2 Count Input must be a positive integer");let o=x(b(t),Uint8Array.of(0),e),a=parseInt(t.slice(13,16),10),i={hash:`SHA-${t.slice(8,11)}`,iterations:r,name:"PBKDF2",salt:o},s=await mn(n,t);return new Uint8Array(await crypto.subtle.deriveBits(i,s,a))}function Dt(e){return x(Ve(e.length),e)}async function yn(e,t,r){let n=t>>3,o=32,a=Math.ceil(n/32),i=new Uint8Array(a*32);for(let s=1;s<=a;s++){let c=await rt("sha256",x(Ve(s),e,r));i.set(c,(s-1)*32)}return i.slice(0,n)}async function lr(e,t,r,n,o=new Uint8Array,a=new Uint8Array){cr(e),cr(t,"deriveBits");let i=x(Dt(b(r)),Dt(o),Dt(a),Ve(n)),s=new Uint8Array(await crypto.subtle.deriveBits({name:e.algorithm.name,public:e},t,e.algorithm.name==="X25519"?256:Math.ceil(parseInt(e.algorithm.namedCurve.slice(-3),10)/8)<<3));return yn(s,n,i)}function mr(e){Xe(e);let t=e.algorithm.namedCurve;if(t!=="P-256"&&t!=="P-384"&&t!=="P-521"&&e.algorithm.name!=="X25519")throw new m("ECDH with the provided key is not allowed or not supported by your javascript runtime")}function De(e){if(e===void 0)throw new u("JWE Encrypted Key missing")}function pr(e){if(e!==void 0)throw new u("Encountered unexpected JWE Encrypted Key")}async function hr(e,t,r,n,o,a){let i=k(e);if(e==="dir")return pr(n),r;switch(i.subtle.name){case"ECDH":{if(e==="ECDH-ES")pr(n);if(!S(o.epk))throw new u('JOSE Header "epk" (Ephemeral Public Key) missing or invalid');mr(r);let s=await Y(i,o.epk),c,p;if(o.apu!==void 0){if(typeof o.apu!=="string")throw new u('JOSE Header "apu" (Agreement PartyUInfo) invalid');c=v(o.apu,"apu",u)}if(o.apv!==void 0){if(typeof o.apv!=="string")throw new u('JOSE Header "apv" (Agreement PartyVInfo) invalid');p=v(o.apv,"apv",u)}let d=await lr(s,r,e==="ECDH-ES"?t.alg:e,e==="ECDH-ES"?t.cekBits:parseInt(e.slice(-5,-2),10),c,p);if(e==="ECDH-ES")return d;return De(n),_t(e.slice(-6),d,n)}case"RSA-OAEP":return De(n),Xe(r),ur(e,r,"decrypt"),new Uint8Array(await crypto.subtle.decrypt("RSA-OAEP",r,n));case"PBKDF2":{if(De(n),typeof o.p2c!=="number")throw new u('JOSE Header "p2c" (PBES2 Count) missing or invalid');let s=a||1e4;if(o.p2c>s)throw new u('JOSE Header "p2c" (PBES2 Count) out is of acceptable bounds');if(typeof o.p2s!=="string")throw new u('JOSE Header "p2s" (PBES2 Salt) missing or invalid');let c=v(o.p2s,"p2s",u),p=await fr(c,e,o.p2c,r);return _t(e.slice(-6),p,n)}case"AES-KW":return De(n),_t(e,r,n);case"AES-GCM":{if(De(n),typeof o.iv!=="string")throw new u('JOSE Header "iv" (Initialization Vector) missing or invalid');if(typeof o.tag!=="string")throw new u('JOSE Header "tag" (Authentication Tag) missing or invalid');let s;s=v(o.iv,"iv",u);let c;return c=v(o.tag,"tag",u),Ze(ce(e.slice(0,-2)),r,n,s,c,new Uint8Array)}}}async function wr(e,t,r,n,o={}){let a,i,s,c=k(e);if(e==="dir")return[r,void 0,void 0];switch(c.subtle.name){case"ECDH":{mr(r);let{apu:p,apv:d}=o;if(p!==void 0)ae(p,'"apu"');if(d!==void 0)ae(d,'"apv"');let f;if(o.epk!==void 0)f=await R(c,o.epk,"decrypt");else f=(await crypto.subtle.generateKey(r.algorithm,!0,["deriveBits"])).privateKey;let l=crypto.subtle,K=f;if(!K.extractable){if(typeof l.getPublicKey!=="function")throw TypeError('CryptoKey for "epk" must be extractable');K=await l.getPublicKey(f,[])}let{x:I,y:g,crv:w,kty:T}=await l.exportKey("jwk",K),y=await lr(r,f,e==="ECDH-ES"?t.alg:e,e==="ECDH-ES"?t.cekBits:parseInt(e.slice(-5,-2),10),p,d);if(i={epk:{x:I,crv:w,kty:T}},T==="EC")i.epk.y=g;if(p)i.apu=B(p);if(d)i.apv=B(d);if(e==="ECDH-ES"){s=y;break}s=n||F(t);let J=e.slice(-6);a=await Ot(J,y,s);break}case"RSA-OAEP":{s=n||F(t),Xe(r),ur(e,r,"encrypt"),a=new Uint8Array(await crypto.subtle.encrypt("RSA-OAEP",r,s));break}case"PBKDF2":{s=n||F(t);let{p2c:p=2048,p2s:d=crypto.getRandomValues(new Uint8Array(16))}=o,f=await fr(d,e,p,r);a=await Ot(e.slice(-6),f,s),i={p2c:p,p2s:B(d)};break}case"AES-KW":{s=n||F(t),a=await Ot(e,r,s);break}case"AES-GCM":{s=n||F(t);let{iv:p}=o,d=await qe(ce(e.slice(0,-2)),s,r,p,new Uint8Array);a=d.ciphertext,i={iv:B(d.iv),tag:B(d.tag)};break}}return[s,a,i]}var we={__proto__:null,b64:!0},ct={__proto__:null};function Ue(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)}function pt(e,t){let{crit:r}=t??{};if(Array.isArray(r)&&new Set(r).size!==r.length)throw new e('"crit" (Critical) Header Parameter MUST NOT contain duplicate values')}function M(e,t,r,n,o){if(o.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[];if(!Array.isArray(n.crit)||n.crit.length===0||n.crit.some((i)=>typeof i!=="string"||i.length===0))throw new e('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');let a=r===void 0?t:{__proto__:null,...r,...t};for(let i of n.crit){if(!(i in a))throw new m(`Extension Header Parameter "${i}" is not recognized`);if(!Object.hasOwn(o,i)||o[i]===void 0)throw new e(`Extension Header Parameter "${i}" is missing`);if(a[i]&&(!Object.hasOwn(n,i)||n[i]===void 0))throw new e(`Extension Header Parameter "${i}" MUST be integrity protected`)}return n.crit}function ge(e,t){if(t.includes("b64")){let r=e.b64;if(typeof r!=="boolean")throw new h('The "b64" (base64url-encode payload) Header Parameter must be a boolean');return r}return!0}function Ee(e,t){let r,n;try{r=JSON.stringify(t),n=JSON.parse(r)}catch(o){throw new e("JOSE Header is not valid JSON",{cause:o})}if(!S(n))throw new e("JOSE Header is not a JSON object");return[n,r]}function dt(e,t){if(e.zip!==void 0&&e.zip!=="DEF")throw new m('Unsupported JWE "zip" (Compression Algorithm) Header Parameter value.');if(e.zip!==void 0&&!t?.zip)throw new u('JWE "zip" (Compression Algorithm) Header Parameter MUST be in a protected header.')}function gr(e){if(typeof globalThis[e]>"u")throw new m(`JWE "zip" (Compression Algorithm) Header Parameter requires the ${e} API.`)}async function br(e){gr("CompressionStream");let t=new CompressionStream("deflate-raw"),r=t.writable.getWriter();r.write(e).catch(()=>{}),r.close().catch(()=>{});let n=[],o=t.readable.getReader();for(;;){let{value:a,done:i}=await o.read();if(i)break;n.push(a)}return x(...n)}async function Sr(e,t){gr("DecompressionStream");let r=new DecompressionStream("deflate-raw"),n=r.writable.getWriter();n.write(e).catch(()=>{}),n.close().catch(()=>{});let o=[],a=0,i=r.readable.getReader();for(;;){let{value:s,done:c}=await i.read();if(c)break;if(o.push(s),a+=s.byteLength,t!==1/0&&a>t)throw new u("Decompressed plaintext exceeded the configured limit")}return x(...o)}function xr(e){return[e&&Ue("keyManagementAlgorithms",e.keyManagementAlgorithms),e&&Ue("contentEncryptionAlgorithms",e.contentEncryptionAlgorithms),e?.crit,e?.maxPBES2Count,e?.maxDecompressedLength]}async function hn(e,t,r,n,o){let[a,i,s,c,p]=r,[d,f,l,K,I]=t,{encrypted_key:g}=e;M(u,ct,s,d,o),dt(o,d);let{alg:w,enc:T}=o;if(typeof w!=="string"||!w)throw new u("missing JWE Algorithm (alg) in JWE Header");if(typeof T!=="string"||!T)throw new u("missing JWE Encryption Algorithm (enc) in JWE Header");if(a&&!a.has(w)||!a&&w.startsWith("PBES2"))throw new ie('"alg" (Algorithm) Header Parameter value not allowed');if(i&&!i.has(T))throw new ie('"enc" (Encryption Algorithm) Header Parameter value not allowed');let y=ce(T),J;if(g!==void 0)J=v(g,"encrypted_key",u);let O=!1;if(typeof n==="function")n=await n(d,e),O=!0;let L=k(w),U=await R(w==="dir"?y:L,n,"decrypt"),_;try{if(_=await hr(w,y,U,J,o,c),g!==void 0&&_ instanceof Uint8Array&&_.byteLength<<3!==y.cekBits)_=F(y)}catch(P){if(P instanceof TypeError||P instanceof u||P instanceof m)throw P;_=F(y)}let re=await Ze(y,_,f,l,K,I);if(o.zip==="DEF"){let P=p??250000;if(P===0)throw new m('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');if(P!==1/0&&(!Number.isSafeInteger(P)||P<1))throw TypeError("maxDecompressedLength must be 0, a positive safe integer, or Infinity");re=await Sr(re,P).catch((ne)=>{if(ne instanceof u)throw ne;throw new u("Failed to decompress plaintext",{cause:ne})})}return[re,d,U,O]}async function Ar(e,t,r){if(e instanceof Uint8Array)e=oe.decode(e);if(typeof e!=="string")throw new u("Compact JWE must be a string or Uint8Array");let{0:n,1:o,2:a,3:i,4:s,length:c}=e.split(".");if(c!==5)throw new u("Invalid Compact JWE");let p={ciphertext:i,iv:a||void 0,protected:n,tag:s||void 0,encrypted_key:o||void 0},d=ee(n,u,"JWE Protected Header is invalid"),f=b(n),l=[d,v(i,"ciphertext",u),a?v(a,"iv",u):void 0,s?v(s,"tag",u):void 0,f];return hn(p,l,t,r,d)}function Kr(e,t,r){if(!er(e,t,r))throw new u("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint")}function gn(e){let[,t,r,n,o,a,i,s,c]=e;if(o!==void 0)ae(o,"JWE Additional Authenticated Data");if(a!==void 0)ae(a,"JWE Content Encryption Key");if(i!==void 0)ae(i,"JWE Initialization Vector");if(t!==void 0)t=Ee(u,t)[0],e[1]=t;if(r!==void 0)r=Ee(u,r)[0],e[2]=r;if(n!==void 0)n=Ee(u,n)[0],e[3]=n;if(s!==void 0&&!S(s))throw TypeError("JWE Key Management Parameters must be an object");Kr(t,r,n);let p={...t,...r,...n};pt(u,t),M(u,ct,c,t,p),dt(p,t);let{alg:d,enc:f}=p;if(typeof d!=="string"||!d)throw new u('JWE "alg" (Algorithm) Header Parameter missing or invalid');if(typeof f!=="string"||!f)throw new u('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');return[p,d,f,ce(f)]}async function En(e,t,r){let[n,o,,a]=t,[i,s,c,p,d,f,l,K,,I]=e,g=s,w=c;if(f&&(o==="dir"||o==="ECDH-ES"))throw TypeError(`setContentEncryptionKey cannot be called with JWE "alg" (Algorithm) Header ${o}`);let T=k(o),y=await R(o==="dir"?a:T,r,"encrypt"),[J,O,L]=await wr(o,a,y,f,K);if(L){if(I)w=w?{...w,...L}:L;else g=g?{...g,...L}:L;Kr(g,w,p)}let U,_;if(g)U=B(JSON.stringify(g)),_=b(U);else U="",_=new Uint8Array;let re,P;if(d?.byteLength)P=B(d),re=x(_,b("."),b(P));else re=_;let ne=i;if(n.zip==="DEF")ne=await br(ne).catch((Mr)=>{throw new u("Failed to compress plaintext",{cause:Mr})});let{ciphertext:Br,tag:zt,iv:Gt}=await qe(a,ne,J,l,re),Q={ciphertext:B(Br)};if(Gt)Q.iv=B(Gt);if(zt)Q.tag=B(zt);if(O)Q.encrypted_key=B(O);if(P)Q.aad=P;if(g)Q.protected=U;if(p)Q.unprotected=p;if(w)Q.header=w;return Q}async function Jr(e,t,r){if(!e[1]&&!e[2]&&!e[3])throw new u("either setProtectedHeader, setUnprotectedHeader, or sharedUnprotectedHeader must be called before #encrypt()");if(r!==void 0)e[8]=r?.crit,e[9]=r?tr in r:!1;return En(e,gn(e),t)}async function vr(e,t,r){if(t instanceof Uint8Array)return crypto.subtle.importKey("raw",t,e.subtle,!1,[r]);if(j(t,e.subtle,r),e.minRsaBits)Ge(e.alg,t);return t}async function Wr(e,t,r){let n=await vr(e,t,"sign"),o=await crypto.subtle.sign(e.signing,n,r);return new Uint8Array(o)}async function Pr(e,t,r,n){let o=await vr(e,t,"verify");try{return await crypto.subtle.verify(e.signing,o,r,n)}catch{return!1}}var Ne=[["verify"],["sign"]];function Ut(e){let t={name:"HMAC",hash:`SHA-${e}`};return{kty:["oct"],secret:!0,subtle:t,signing:t,usages:Ne}}function be(e,t){let n={name:t?"RSA-PSS":"RSASSA-PKCS1-v1_5",hash:`SHA-${e}`};return{kty:["RSA"],subtle:n,signing:t?{...n,saltLength:t}:n,usages:Ne,minRsaBits:2048}}function Nt(e,t){return{kty:["EC"],crv:e,subtle:{name:"ECDSA",namedCurve:e},signing:{name:"ECDSA",hash:`SHA-${t}`},usages:Ne}}function Tr(){let e={name:"Ed25519"};return{kty:["OKP"],crv:"Ed25519",subtle:e,signing:e,usages:Ne}}function Rt(e){let r={name:`ML-DSA-${e}`};return{kty:["AKP"],subtle:r,signing:r,usages:Ne}}var Re=_e({HS256:Ut(256),HS384:Ut(384),HS512:Ut(512),RS256:be(256),RS384:be(384),RS512:be(512),PS256:be(256,32),PS384:be(384,48),PS512:be(512,64),ES256:Nt("P-256",256),ES384:Nt("P-384",384),ES512:Nt("P-521",512),EdDSA:Tr(),Ed25519:Tr(),"ML-DSA-44":Rt(44),"ML-DSA-65":Rt(65),"ML-DSA-87":Rt(87)});function ut(e){let t=typeof e==="string"?Re[e]:void 0;if(!t)throw new m(`alg ${e} is not supported either by JOSE or your javascript runtime`);return t}function ft(e){return[e&&Ue("algorithms",e.algorithms),e?.crit]}function bn(e,t=e===void 0?{}:ee(e,h,"JWS Protected Header is invalid")){return t}function Sn(e,t,r){let n=ge(e,M(h,we,r[1],e,t)),o=t.alg;if(typeof o!=="string"||!o)throw new h('JWS "alg" (Algorithm) Header Parameter missing or invalid');if(r[0]&&!r[0].has(o))throw new ie('"alg" (Algorithm) Header Parameter value not allowed');return[n,o]}function xn(e){try{return b(e)}catch{throw new h("JWS Compact Serialization payload must use only ASCII characters")}}async function An(e,t,r,n,o,a,i){let s=!1;if(typeof r==="function")r=await r(o,e),s=!0;let c=typeof i==="string",p=ut(a),d=x(n!==void 0?b(n):new Uint8Array,b("."),c?t[2]??=Jt(i,"payload",h):i),f=v(e.signature,"signature",h),l=await R(p,r,"verify");if(!await Pr(p,l,f,d))throw new Fe;return[c?v(i,"payload",h):i,o,c,l,s]}async function lt(e,t,r){if(e instanceof Uint8Array)e=oe.decode(e);if(typeof e!=="string")throw new h("Compact JWS must be a string or Uint8Array");let{0:n,1:o,2:a,length:i}=e.split(".");if(i!==3)throw new h("Invalid Compact JWS");let s={payload:o,protected:n,signature:a},c=bn(n),[p,d]=Sn(c,c,t),f=p?o:xn(o);return An(s,t,r,n,c,d,f)}async function yr(e,t,r){let n=await lt(e,ft(r),t),o={payload:n[0],protectedHeader:n[1]};if(typeof t==="function")return{...o,key:n[3]};return o}var He=(e)=>Math.floor(e.getTime()/1000),Kn={s:1,m:60,h:3600,d:86400,w:604800,y:31557600},Jn=/^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i,xe="check_failed";function Ht(){throw TypeError("Invalid time period format")}function mt(e){if(typeof e!=="string")Ht();let t=Jn.exec(e);if(!t||t[4]&&t[1])Ht();let r=parseFloat(t[2]),n=Math.round(r*Kn[t[3][0].toLowerCase()]);if(!Number.isFinite(n))Ht();if(t[1]==="-"||t[4]==="ago")return-n;return n}function Ae(e,t){if(!Number.isFinite(t))throw TypeError(`Invalid ${e} input`);return t}function kt(e,t){if(typeof t!=="string")throw TypeError(`"${e}" claim must be a string`)}function Cn(e){if(typeof e!=="string"&&(!Array.isArray(e)||Array.from(e).some((t)=>typeof t!=="string")))throw TypeError('"aud" claim must be a string or an array of strings')}function Bt(e,t){if(typeof e==="number")return Ae(t,e);if(e instanceof Date)return Ae(t,He(e));return He(new Date)+mt(e)}var Ir=(e)=>{let t=e.toLowerCase();return e.includes("/")?t:`application/${t}`},Wn=(e,t)=>{if(typeof e==="string")return t.includes(e);if(Array.isArray(e))return t.some((r)=>e.includes(r));return!1};function Mt(e,t,r=!1){let n=e[t];if(n===void 0&&!r)return;if(typeof n!=="number")throw new D(`"${t}" claim must be a number`,e,t,"invalid");return n}function $t(e,t){throw new D(`unexpected "${t}" claim value`,e,t,xe)}function Ke(e,t,r={}){let n;try{n=JSON.parse(fe.decode(t))}catch{}if(!S(n))throw new H("JWT Claims Set must be a top-level JSON object");let{typ:o}=r;if(o!==void 0&&(typeof e.typ!=="string"||Ir(e.typ)!==Ir(o)))throw new D('unexpected "typ" JWT header value',n,"typ",xe);let{requiredClaims:a=[],issuer:i,subject:s,audience:c,maxTokenAge:p}=r,d=[...a];if(p!==void 0)d.push("iat");if(c!==void 0)d.push("aud");if(s!==void 0)d.push("sub");if(i!==void 0)d.push("iss");for(let y of new Set(d.reverse()))if(!Object.hasOwn(n,y))throw new D(`missing required "${y}" claim`,n,y,"missing");if(i!==void 0&&!(Array.isArray(i)?i:[i]).includes(n.iss))$t(n,"iss");if(s!==void 0&&n.sub!==s)$t(n,"sub");if(c!==void 0&&!Wn(n.aud,typeof c==="string"?[c]:c))$t(n,"aud");let{clockTolerance:f}=r,l=0;if(typeof f==="string")l=mt(f);else if(f!==void 0){if(typeof f!=="number")throw TypeError("Invalid clockTolerance option type");l=f}Ae("clockTolerance option",l);let{currentDate:K}=r,I=Ae("currentDate option",He(K===void 0?new Date:K)),g=Mt(n,"iat",p!==void 0),w=Mt(n,"nbf");if(w!==void 0){if(w>I+l)throw new D('"nbf" claim timestamp check failed',n,"nbf",xe)}let T=Mt(n,"exp");if(T!==void 0){if(T<=I-l)throw new tt('"exp" claim timestamp check failed',n,"exp",xe)}if(p!==void 0){let y=I-g,J=Ae("maxTokenAge option",typeof p==="number"?p:mt(p));if(y-l>J)throw new tt('"iat" claim timestamp check failed (too far in the past)',n,"iat",xe);if(y<-l)throw new D('"iat" claim timestamp check failed (it should be in the past)',n,"iat",xe)}return n}var Or;function q(e){return Or.get(e)}function Je(e){let t=q(e);for(let r of["iat","nbf","exp"]){let n=t[r];if(typeof n==="number"&&!Number.isFinite(n))throw TypeError(`"${r}" claim must be a finite number`)}return We.encode(JSON.stringify(t))}function ht(e,t){return q(e)[t]}class pe{constructor(e={}){if(!S(e))throw TypeError("JWT Claims Set MUST be an object");(Or||=new WeakMap).set(this,structuredClone(e))}setIssuer(e){return kt("iss",e),q(this).iss=e,this}setSubject(e){return kt("sub",e),q(this).sub=e,this}setAudience(e){return Cn(e),q(this).aud=e,this}setJti(e){return kt("jti",e),q(this).jti=e,this}setNotBefore(e){return q(this).nbf=Bt(e,"setNotBefore"),this}setExpirationTime(e){return q(this).exp=Bt(e,"setExpirationTime"),this}setIssuedAt(e){let t=q(this);if(e===void 0)t.iat=He(new Date);else if(typeof e==="string")t.iat=Ae("setIssuedAt",He(new Date)+mt(e));else t.iat=Bt(e,"setIssuedAt");return this}}async function V(e,t,r){let n=await lt(e,ft(r),t);if(!n[2])throw new H("JWTs MUST NOT use unencoded payload");let a={payload:Ke(n[1],n[0],r),protectedHeader:n[1]};if(typeof t==="function")return{...a,key:n[3]};return a}async function Er(e,t,r){let n=await Ar(e,xr(r),t),o=n[1],a=Ke(o,n[0],r);for(let s of["iss","sub","aud"])if(o[s]!==void 0&&(s==="aud"?JSON.stringify(o.aud)!==JSON.stringify(a.aud):o[s]!==a[s]))throw new D(`replicated "${s}" claim header parameter mismatch`,a,s,"mismatch");let i={payload:a,protectedHeader:o};if(typeof t==="function")return{...i,key:n[2]};return i}function Pn(e){if(e===void 0)return[void 0,""];let t=Ee(h,e);return[t[0],B(t[1])]}function Tn(e,t,r){return pt(h,e),ge(e,M(h,we,r,e,t))}function In(e){let t=e.alg;if(typeof t!=="string"||!t)throw new h('JWS "alg" (Algorithm) Header Parameter missing or invalid');return ut(t)}async function On(e,t,r,n){let o=x(b(e),b("."),t),a=await R(r,n,"sign");return B(await Wr(r,a,o))}async function _r(e,t,r,n,o){let[a,i]=Pn(t);if(!a)throw new h("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");if(!Tn(a,a,r))o();let c=In(a),p=B(e),d=await On(i,b(p),c,n);return`${i}.${p}.${d}`}var _n=pe;class ke extends _n{#e;setProtectedHeader(e){return se(this.#e,"setProtectedHeader"),this.#e=e,this}async sign(e,t){return _r(Je(this),this.#e,t?.crit,e,()=>{throw new H("JWTs MUST NOT use unencoded payload")})}}var Dn=pe;class Cr extends Dn{#e;#r;#n;#t;#o;#i;#a;setProtectedHeader(e){return se(this.#t,"setProtectedHeader"),this.#t=e,this}setKeyManagementParameters(e){return se(this.#n,"setKeyManagementParameters"),this.#n=e,this}setContentEncryptionKey(e){return se(this.#e,"setContentEncryptionKey"),this.#e=e,this}setInitializationVector(e){return se(this.#r,"setInitializationVector"),this.#r=e,this}replicateIssuerAsHeader(){return this.#o=!0,this}replicateSubjectAsHeader(){return this.#i=!0,this}replicateAudienceAsHeader(){return this.#a=!0,this}async encrypt(e,t){let r=Je(this);if(this.#t&&(this.#o||this.#i||this.#a))this.#t={...this.#t,iss:this.#o?ht(this,"iss"):void 0,sub:this.#i?ht(this,"sub"):void 0,aud:this.#a?ht(this,"aud"):void 0};let n=await Jr([r,this.#t,void 0,void 0,void 0,this.#e,this.#r,this.#n,void 0,!1],e,t);return[n.protected,n.encrypted_key,n.iv,n.ciphertext,n.tag].join(".")}}var ve='"alg" (Algorithm)';function Be(e='JWK "alg" (Algorithm) Parameter'){throw new m(`Invalid or unsupported ${e} value`)}function de(e,t){return(typeof e==="string"?Re[e]??Tt[e]:void 0)??Be(t)}function Ce(e){if(e!==void 0&&typeof e!=="boolean")throw TypeError('"extractable" option must be a boolean');return e}var Me=(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},Un=(e)=>({data:e,pos:0}),jt=(e)=>{let t=e.data[e.pos++];if(t===void 0)throw Error("Unexpected end of ASN.1 input");return t},Le=(e)=>{let t=jt(e);if(t&128){let r=t&127,n=0;for(let o=0;o<r;o++)n=n<<8|jt(e);return n}return t};var $e=(e,t,r)=>{if(jt(e)!==t)throw Error(r)},Dr=(e,t)=>{if(t<0||e.pos+t>e.data.length)throw Error("Unexpected end of ASN.1 input");let r=e.data.subarray(e.pos,e.pos+t);return e.pos+=t,r},Nn=(e)=>{$e(e,6,"Expected algorithm OID");let t=Le(e);return Dr(e,t)};function Hn(e,t){if($e(e,48,`Invalid ${t==="spki"?"SPKI":"PKCS#8"} structure`),Le(e),t==="pkcs8"){$e(e,2,"Expected version field");let r=Le(e);e.pos+=r}$e(e,48,"Expected algorithm identifier"),Le(e)}var kn=(e)=>{let t=Nn(e);if(Me(t,[43,101,110]))return"X25519";if(!Me(t,[42,134,72,206,61,2,1]))throw Error("Unsupported key algorithm");$e(e,6,"Expected curve OID");let r=Le(e),n=Dr(e,r);if(Me(n,[42,134,72,206,61,3,1,7]))return"P-256";if(Me(n,[43,129,4,0,34]))return"P-384";if(Me(n,[43,129,4,0,35]))return"P-521";throw Error("Unsupported named curve")},Bn=async(e,t,r,n)=>{let o=Ce(n?.extractable),a=de(r,ve);if(a.secret)Be(ve);let i=e==="spki",s;if(a.resolve)try{let c=Un(t);Hn(c,e),s=a.resolve({crv:kn(c)})}catch{throw new m("Invalid or unsupported key format")}else s=a.subtle;return crypto.subtle.importKey(e,t,s,o??i,a.usages[i?0:1])},Mn=(e,t)=>Qe(e.replace(t,"")),Ur=(e,t,r)=>{let n=Mn(e,/(?:-----(?:BEGIN|END) PRIVATE KEY-----|\s)/g);return Bn("pkcs8",n,t,r)};function Ln(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0))}async function $n(e){if(xt(e))if(e.type==="secret")e=e.export();else return e.export({format:"jwk"});if(e instanceof Uint8Array)return{kty:"oct",k:B(e)};if(!G(e))throw TypeError(z(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:o,...a}=Ln(await crypto.subtle.exportKey("jwk",e));if(a.kty==="AKP")a.alg=n;return a}function Ct(e){return $n(e)}var Z=(e,t)=>{if(typeof e!=="string"||!e)throw new Oe(`${t} missing or invalid`)};async function It(e,t){let r;if(S(e)){if(r=me(e),typeof r.kty!=="string")throw TypeError(z(e,"CryptoKey","KeyObject","JSON Web Key"))}else if(Ye(e))r=me(await Ct(e));else throw TypeError(z(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":Z(r.alg,'"alg" (Algorithm) Parameter'),Z(r.pub,'"pub" (Public key) Parameter'),n={alg:r.alg,kty:r.kty,pub:r.pub};break;case"EC":Z(r.crv,'"crv" (Curve) Parameter'),Z(r.x,'"x" (X Coordinate) Parameter'),Z(r.y,'"y" (Y Coordinate) Parameter'),n={crv:r.crv,kty:r.kty,x:r.x,y:r.y};break;case"OKP":Z(r.crv,'"crv" (Subtype of Key Pair) Parameter'),Z(r.x,'"x" (Public Key) Parameter'),n={crv:r.crv,kty:r.kty,x:r.x};break;case"RSA":Z(r.e,'"e" (Exponent) Parameter'),Z(r.n,'"n" (Modulus) Parameter'),n={e:r.e,kty:r.kty,n:r.n};break;case"oct":if(typeof r.k!=="string")throw new Oe('"k" (Key Value) Parameter missing or invalid');n={k:r.k,kty:r.kty};break;default:throw new m('"kty" (Key Type) Parameter missing or unsupported')}let o=b(JSON.stringify(n));return B(await rt(t,o))}function jn(e,t,r,n){let{kty:o,key_ops:a,ext:i,kid:s,alg:c,use:p,crv:d}=me(e),f=Array.isArray(a)?[...a]:a;return(i===void 0||typeof i==="boolean")&&(f===void 0||Array.isArray(f)&&f.every((l,K)=>typeof l==="string"&&f.indexOf(l)===K)&&f.includes("verify"))&&t.kty.includes(o)&&(n===void 0||typeof n==="string"&&n===s)&&(c===void 0?o!=="AKP":r===c)&&(p===void 0||p==="sig")&&(!t.crv||d===t.crv)}async function Nr(e,t,r){let n=e.get(t)||e.set(t,{}).get(t),{alg:o}=r;if(n[o]===void 0){let a=await Y(r,{...t,alg:o,ext:!0});if(a.type!=="public")throw new yt("JSON Web Key Set members must be public keys");n[o]=a}return n[o]}function Se(e){let t;try{t=structuredClone(e)}catch{}if(!et(t))throw new yt("JSON Web Key Set malformed");let r=new WeakMap;return Object.defineProperty(async(o,a)=>{let{alg:i,kid:s}={...o,...a?.header},c=typeof i==="string"?Re[i]:void 0;if(!c||c.secret)throw new m('Unsupported "alg" value for a JSON Web Key Set');let p=t.keys.filter((l)=>jn(l,c,i,s)),{0:d,length:f}=p;if(!f)throw new le;if(f!==1){let l=new Lt;throw l[Symbol.asyncIterator]=async function*(){for(let K of p)try{yield await Nr(r,K,c)}catch{}},l}return Nr(r,d,c)},"jwks",{value:()=>structuredClone(t)})}function Vn(){return typeof WebSocketPair<"u"||typeof navigator<"u"&&navigator.userAgent==="Cloudflare-Workers"||typeof EdgeRuntime<"u"&&EdgeRuntime==="vercel"}var Vt;if(typeof navigator>"u"||!navigator.userAgent?.startsWith?.("Mozilla/5.0 "))Vt="jose/v6.2.10";var Hr=Symbol();async function zn(e,t,r,n=fetch){let o=await n(e,{method:"GET",signal:r,redirect:"manual",headers:t}).catch((a)=>{if(a.name==="TimeoutError")throw new Et;throw a});if(o.status!==200)throw new X("Expected 200 OK from the JSON Web Key Set HTTP response");try{return await o.json()}catch{throw new X("Failed to parse the JSON Web Key Set HTTP response as JSON")}}var kr=Symbol();function je(e,t){return Number.isFinite(e)&&Date.now()<e+t}function Rr(e,t,r){if(Number.isNaN(e))throw TypeError(`"${r}" option must not be NaN`);return typeof e==="number"?e:t}function Qr(e,t){if(!(e instanceof URL))throw TypeError("url must be an instance of URL");let r=new URL(e.href).href,n=t??{},o=n.timeoutDuration;if(typeof o==="number"&&(!Number.isInteger(o)||o<0))throw TypeError('"timeoutDuration" option must be a non-negative integer');let a=typeof o==="number"?o:5000,i=Rr(n.cooldownDuration,30000,"cooldownDuration"),s=Rr(n.cacheMaxAge,600000,"cacheMaxAge"),c=new Headers(n.headers);if(Vt&&!c.has("User-Agent"))c.set("User-Agent",Vt);if(!c.has("accept"))c.set("accept","application/json, application/jwk-set+json");let p=n[Hr],d=n[kr],f,l,K=0,I=0,g;if(d&&typeof d==="object"){let{uat:y,jwks:J}=d;if(je(y,s)&&et(J))f=y,g=Se(J)}let w=async()=>{if(l&&Vn())l=void 0;if(!l){let y=++K,J=l=zn(r,c,AbortSignal.timeout(a),p).then((O)=>{let L=Se(O);if(y<=I)return;g=L;let U=Date.now();if(d)d.uat=U,d.jwks=O;f=U,I=y}).finally(()=>{if(l===J)l=void 0})}await l};return Object.defineProperties(async(y,J)=>{if(!g||!je(f,s))await w();try{return await g(y,J)}catch(O){if(O instanceof le&&!je(f,i))return await w(),g(y,J);throw O}},{coolingDown:{get:()=>je(f,i),enumerable:!0},fresh:{get:()=>je(f,s),enumerable:!0},reload:{value:w,enumerable:!0},reloading:{get:()=>!!l,enumerable:!0},jwks:{value:()=>g?.jwks(),enumerable:!0}})}var Gn=pe;class vn extends Gn{encode(){let e=B(JSON.stringify({alg:"none"})),t=B(Je(this));return`${e}.${t}.`}static decode(e,t){if(typeof e!=="string")throw new H("Unsecured JWT must be a string");let{0:r,1:n,2:o,length:a}=e.split(".");if(a!==3||o!=="")throw new H("Invalid Unsecured JWT");let i,s;try{i=ee(r,h,"JWS Protected Header is invalid");let p=M(h,we,void 0,i,i);s=ge(i,p)}catch(p){if(!(p instanceof h))throw p;throw new H("Invalid Unsecured JWT",{cause:p})}if(i.alg!=="none")throw new H("Invalid Unsecured JWT");if(!s)throw new H("JWTs MUST NOT use unencoded payload");return{payload:Ke(i,v(n,"payload",H),t),header:i}}}async function Rn(e,t,r){if(typeof e!=="string"||e.indexOf("-----BEGIN PRIVATE KEY-----")!==0)throw TypeError('"pkcs8" must be PKCS#8 formatted string');return Ur(e,t,r)}async function te(e,t,r){if(!S(e))throw TypeError("JWK must be an object");let n=nt(e),o=Ce(r?.extractable),{alg:a}=n;t??=a;let i=o??n.ext;if(n.kty!=="oct"&&!t)throw TypeError('"alg" argument is required when "jwk.alg" is not present');switch(n.kty){case"oct":if(typeof n.k!=="string")throw TypeError('missing "k" (Key Value) Parameter value');return N(n.k);case"AKP":{if(typeof a!=="string"||!a)throw TypeError('missing "alg" (Algorithm) Parameter value');if(t!==a)throw TypeError("JWK alg and alg option value mismatch");return Y(de(t),{...n,ext:i})}case"RSA":case"EC":case"OKP":return Y(de(t),{...n,alg:t,ext:i});default:throw new m('Unsupported "kty" (Key Type) Parameter value')}}function ue(e){let t;if(typeof e==="string"){let n=e.split(".");if(n.length===3||n.length===5)[t]=n}else if(typeof e==="object"&&e)if("protected"in e)t=e.protected;else throw TypeError("Token does not contain a Protected Header");let r="Invalid Token or Protected Header formatting";if(typeof t!=="string"||!t)throw TypeError(r);return ee(t,TypeError,r)}function W(e){if(typeof e!=="string")throw new H("JWTs must use Compact JWS serialization, JWT must be a string");let{1:t,length:r}=e.split(".");if(r===5)throw new H("Only JWTs using Compact JWS serialization can be decoded");if(r!==3)throw new H("Invalid JWT");if(!t)throw new H("JWTs must contain a payload");let n;try{n=N(t)}catch{throw new H("Failed to base64url decode the payload")}let o;try{o=JSON.parse(fe.decode(n))}catch{throw new H("Failed to parse the decoded payload as JSON")}if(!S(o))throw new H("Invalid JWT Claims Set");return o}function Fn(e){let t=e?.modulusLength??2048;if(typeof t!=="number"||!Number.isInteger(t)||t<2048)throw new m("Invalid or unsupported modulusLength option provided, 2048 bits or larger keys must be used");return t}async function zr(e,t){let r=Ce(t?.extractable),n=de(e,ve);if(n.secret)Be(ve);let o;if(n.resolve){let a=t?.crv??"P-256";switch(a){case"P-256":case"P-384":case"P-521":o={name:"ECDH",namedCurve:a};break;case"X25519":o={name:"X25519"};break;default:throw new m("Invalid or unsupported crv option provided, supported values are P-256, P-384, P-521, and X25519")}}else{if(n.crv!==void 0&&t?.crv!==void 0&&t.crv!==n.crv)throw new m(`Invalid or unsupported crv option provided, the only supported value for ${e} is ${n.crv}`);o=n.kty[0]==="RSA"?{...n.subtle,publicExponent:Uint8Array.of(1,0,1),modulusLength:Fn(t)}:n.subtle}return crypto.subtle.generateKey(o,r??!1,[...n.usages[1],...n.usages[0]])}export{E,A,Ie,C,X,tt,H,yt,Lt,Et,wn,B,un,yr,V,Er,ke,Cr,Ct,It,Se,Qr,vn,Rn,te,ue,W,zr};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
function
|
|
3
|
-
export{
|
|
2
|
+
function Fe(i){let t=3735928559,h=1103547991;for(let e=0;e<i.length;e++){let l=i.charCodeAt(e);t=Math.imul(t^l,2654435761),h=Math.imul(h^l,1597334677)}return t=Math.imul(t^t>>>16,2246822507)^Math.imul(h^h>>>13,3266489909),h=Math.imul(h^h>>>16,2246822507)^Math.imul(t^t>>>13,3266489909),(h>>>0).toString(36)+(t>>>0).toString(36)}
|
|
3
|
+
export{Fe};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Be,Bt,pt,
|
|
2
|
+
import{Be,Bt,pt,Ft,At,Qt,zt,qt,Gt,$t}from"./chunk-g3dzntvc.js";import{Q}from"./chunk-49hphjym.js";import{ae,ce}from"./chunk-x71z4a2a.js";import{R,j}from"./chunk-z19gfsnw.js";import{lt}from"./chunk-2exf93nx.js";import{F,ie,Y}from"./chunk-96w1b3xz.js";var y="v1",E="gcp-vertex-credentials",T={THINKING_LEVEL_UNSPECIFIED:Be.THINKING_LEVEL_UNSPECIFIED,MINIMAL:Be.MINIMAL,LOW:Be.LOW,MEDIUM:Be.MEDIUM,HIGH:Be.HIGH},_=0,m=(e,t,n)=>{let o=new F;return(async()=>{let i={role:"assistant",content:[],api:"google-vertex",provider:e.provider,model:e.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:"stop",timestamp:Date.now()};try{let u=G(n),s=u?v(e,u,n?.headers):b(e,P(n),N(n),n?.headers,n?.env),h=U(e,t,n),g=await n?.onPayload?.(h,e);if(g!==void 0)h=g;let x=await s.models.generateContentStream(h);o.push({type:"start",partial:i});let r=null,I=i.content,l=()=>I.length-1;for await(let c of x){i.responseId||=c.responseId;let p=c.candidates?.[0];if(p?.content?.parts)for(let a of p.content.parts){if(a.text!==void 0){let d=Ft(a);if(!r||d&&r.type!=="thinking"||!d&&r.type!=="text"){if(r)if(r.type==="text")o.push({type:"text_end",contentIndex:I.length-1,content:r.text,partial:i});else o.push({type:"thinking_end",contentIndex:l(),content:r.thinking,partial:i});if(d)r={type:"thinking",thinking:"",thinkingSignature:void 0},i.content.push(r),o.push({type:"thinking_start",contentIndex:l(),partial:i});else r={type:"text",text:""},i.content.push(r),o.push({type:"text_start",contentIndex:l(),partial:i})}if(r.type==="thinking")r.thinking+=a.text,r.thinkingSignature=At(r.thinkingSignature,a.thoughtSignature),o.push({type:"thinking_delta",contentIndex:l(),delta:a.text,partial:i});else r.text+=a.text,r.textSignature=At(r.textSignature,a.thoughtSignature),o.push({type:"text_delta",contentIndex:l(),delta:a.text,partial:i})}if(a.functionCall){if(r){if(r.type==="text")o.push({type:"text_end",contentIndex:l(),content:r.text,partial:i});else o.push({type:"thinking_end",contentIndex:l(),content:r.thinking,partial:i});r=null}let d=a.functionCall.id,f={type:"toolCall",id:!d||i.content.some((C)=>C.type==="toolCall"&&C.id===d)?`${a.functionCall.name}_${Date.now()}_${++_}`:d,name:a.functionCall.name||"",arguments:a.functionCall.args??{},...a.thoughtSignature&&{thoughtSignature:a.thoughtSignature}};i.content.push(f),o.push({type:"toolcall_start",contentIndex:l(),partial:i}),o.push({type:"toolcall_delta",contentIndex:l(),delta:JSON.stringify(f.arguments),partial:i}),o.push({type:"toolcall_end",contentIndex:l(),toolCall:f,partial:i})}}if(p?.finishReason){if(i.stopReason=$t(p.finishReason),i.content.some((a)=>a.type==="toolCall"))i.stopReason="toolUse"}if(c.usageMetadata)i.usage={input:(c.usageMetadata.promptTokenCount||0)-(c.usageMetadata.cachedContentTokenCount||0),output:(c.usageMetadata.candidatesTokenCount||0)+(c.usageMetadata.thoughtsTokenCount||0),cacheRead:c.usageMetadata.cachedContentTokenCount||0,cacheWrite:0,reasoning:c.usageMetadata.thoughtsTokenCount||0,totalTokens:c.usageMetadata.totalTokenCount||0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},ie(e,i.usage)}if(r)if(r.type==="text")o.push({type:"text_end",contentIndex:l(),content:r.text,partial:i});else o.push({type:"thinking_end",contentIndex:l(),content:r.thinking,partial:i});if(n?.signal?.aborted)throw Error("Request was aborted");if(i.stopReason==="aborted"||i.stopReason==="error")throw Error("An unknown error occurred");o.push({type:"done",reason:i.stopReason,message:i}),o.end()}catch(u){for(let s of i.content)if("index"in s)delete s.index;i.stopReason=n?.signal?.aborted?"aborted":"error",i.errorMessage=ce(ae(u)),o.push({type:"error",reason:i.stopReason,error:i}),o.end()}})(),o},oe=(e,t,n)=>{let o=j(e,t,n,void 0);if(!n?.reasoning)return m(e,t,{...o,thinking:{enabled:!1}});let i=Y(e,n.reasoning),u=i==="off"?"high":i,s=e;if(k(s)||L(s))return m(e,t,{...o,thinking:{enabled:!0,level:H(u,s)}});return m(e,t,{...o,thinking:{enabled:!0,budgetTokens:V(s,u,n.thinkingBudgets)}})};function b(e,t,n,o,i){let u=S(i);return new pt({vertexai:!0,project:t,location:n,apiVersion:y,...u?{googleAuthOptions:u}:{},httpOptions:O(e,o)})}function v(e,t,n){return new pt({vertexai:!0,apiKey:t,apiVersion:y,httpOptions:O(e,n)})}function O(e,t){let n={},o=M(e.baseUrl);if(o){if(n.baseUrl=o,n.baseUrlResourceScope=Bt.COLLECTION,w(o))n.apiVersion=""}let i=lt({...e.headers,...t});if(i)n.headers=i;return Object.keys(n).length>0?n:void 0}function M(e){let t=e.trim();if(!t||t.includes("{location}"))return;return t}function w(e){try{return new URL(e).pathname.split("/").some((n)=>/^v\d+(?:beta\d*)?$/.test(n))}catch{return/(?:^|\/)v\d+(?:beta\d*)?(?:\/|$)/.test(e)}}function S(e){let t=Q("GOOGLE_APPLICATION_CREDENTIALS",e);return t?{keyFilename:t}:void 0}function G(e){let t=e?.apiKey?.trim();if(!t||t===E||A(t))return;return t}function A(e){return/^<[^>]+>$/.test(e)}function P(e){let t=e?.project||Q("GOOGLE_CLOUD_PROJECT",e?.env)||Q("GCLOUD_PROJECT",e?.env);if(!t)throw Error("Vertex AI requires a project ID. Set GOOGLE_CLOUD_PROJECT/GCLOUD_PROJECT or pass project in options.");return t}function N(e){let t=e?.location||Q("GOOGLE_CLOUD_LOCATION",e?.env);if(!t)throw Error("Vertex AI requires a location. Set GOOGLE_CLOUD_LOCATION or pass location in options.");return t}function U(e,t,n={}){let o=Qt(e,t),i={};if(n.temperature!==void 0)i.temperature=n.temperature;if(n.maxTokens!==void 0)i.maxOutputTokens=n.maxTokens;let u=t.tools?.length?Gt(t.tools,n.toolChoice,qt(e.id)):void 0,s={...Object.keys(i).length>0&&i,...t.systemPrompt&&{systemInstruction:R(t.systemPrompt)},...t.tools&&t.tools.length>0&&{tools:zt(t.tools)},...u!==void 0&&{toolConfig:{functionCallingConfig:{mode:u}}}};if(n.thinking?.enabled&&e.reasoning){let g={includeThoughts:!0};if(n.thinking.level!==void 0)g.thinkingLevel=T[n.thinking.level];else if(n.thinking.budgetTokens!==void 0)g.thinkingBudget=n.thinking.budgetTokens;s.thinkingConfig=g}else if(e.reasoning&&n.thinking&&!n.thinking.enabled)s.thinkingConfig=D(e);if(n.signal){if(n.signal.aborted)throw Error("Request aborted");s.abortSignal=n.signal}return{model:e.id,contents:o,config:s}}function k(e){return/gemini-3(?:\.\d+)?-pro/.test(e.id.toLowerCase())}function L(e){let t=e.id.toLowerCase();return/gemini-3(?:\.\d+)?-flash/.test(t)||t==="gemini-flash-latest"||t==="gemini-flash-lite-latest"}function D(e){let t=e;if(k(t))return{thinkingLevel:Be.LOW};if(L(t))return{thinkingLevel:Be.MINIMAL};return{thinkingBudget:0}}function H(e,t){if(k(t))switch(e){case"minimal":case"low":return"LOW";case"medium":case"high":return"HIGH"}switch(e){case"minimal":return"MINIMAL";case"low":return"LOW";case"medium":return"MEDIUM";case"high":return"HIGH"}}function V(e,t,n){if(n?.[t]!==void 0)return n[t];if(e.id.includes("2.5-pro"))return{minimal:128,low:2048,medium:8192,high:32768}[t];if(e.id.includes("2.5-flash"))return{minimal:128,low:2048,medium:8192,high:24576}[t];return-1}export{m as stream,oe as streamSimple};
|