mqtt-plus 1.4.0 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/AGENTS.md +55 -44
  2. package/CHANGELOG.md +14 -0
  3. package/README.md +4 -3
  4. package/doc/mqtt-plus-api.md +693 -680
  5. package/doc/mqtt-plus-architecture.d2 +139 -0
  6. package/doc/mqtt-plus-architecture.md +10 -0
  7. package/doc/mqtt-plus-architecture.svg +95 -0
  8. package/doc/mqtt-plus-broker-setup.md +9 -3
  9. package/doc/mqtt-plus-comm.md +73 -0
  10. package/doc/mqtt-plus-internals.md +3 -3
  11. package/dst-stage1/mqtt-plus-base.d.ts +3 -2
  12. package/dst-stage1/mqtt-plus-base.js +53 -22
  13. package/dst-stage1/mqtt-plus-event.d.ts +0 -2
  14. package/dst-stage1/mqtt-plus-event.js +6 -26
  15. package/dst-stage1/mqtt-plus-meta.d.ts +2 -2
  16. package/dst-stage1/mqtt-plus-meta.js +2 -2
  17. package/dst-stage1/mqtt-plus-msg.d.ts +2 -0
  18. package/dst-stage1/mqtt-plus-msg.js +17 -0
  19. package/dst-stage1/mqtt-plus-service.d.ts +0 -5
  20. package/dst-stage1/mqtt-plus-service.js +12 -48
  21. package/dst-stage1/mqtt-plus-sink.d.ts +0 -10
  22. package/dst-stage1/mqtt-plus-sink.js +25 -92
  23. package/dst-stage1/mqtt-plus-source.d.ts +0 -10
  24. package/dst-stage1/mqtt-plus-source.js +23 -88
  25. package/dst-stage1/mqtt-plus-subscription.d.ts +20 -0
  26. package/dst-stage1/mqtt-plus-subscription.js +126 -0
  27. package/dst-stage1/mqtt-plus-timer.d.ts +8 -0
  28. package/dst-stage1/mqtt-plus-timer.js +57 -0
  29. package/dst-stage1/mqtt-plus-topic.d.ts +20 -0
  30. package/dst-stage1/mqtt-plus-topic.js +112 -0
  31. package/dst-stage1/mqtt-plus-trace.js +2 -0
  32. package/dst-stage1/mqtt-plus-util.d.ts +0 -13
  33. package/dst-stage1/mqtt-plus-util.js +1 -77
  34. package/dst-stage1/mqtt-plus-version.d.ts +0 -1
  35. package/dst-stage1/mqtt-plus-version.js +0 -6
  36. package/dst-stage1/tsc.tsbuildinfo +1 -1
  37. package/dst-stage2/mqtt-plus.cjs.js +242 -292
  38. package/dst-stage2/mqtt-plus.esm.js +240 -290
  39. package/dst-stage2/mqtt-plus.umd.js +12 -12
  40. package/etc/knip.jsonc +1 -1
  41. package/etc/stx.conf +6 -4
  42. package/package.json +1 -1
  43. package/src/mqtt-plus-base.ts +56 -26
  44. package/src/mqtt-plus-event.ts +8 -24
  45. package/src/mqtt-plus-meta.ts +3 -3
  46. package/src/mqtt-plus-msg.ts +28 -0
  47. package/src/mqtt-plus-service.ts +12 -50
  48. package/src/mqtt-plus-sink.ts +32 -105
  49. package/src/mqtt-plus-source.ts +29 -99
  50. package/src/mqtt-plus-subscription.ts +141 -0
  51. package/src/mqtt-plus-timer.ts +61 -0
  52. package/src/mqtt-plus-trace.ts +4 -0
  53. package/src/mqtt-plus-util.ts +1 -81
  54. package/src/mqtt-plus-version.ts +0 -7
  55. package/tst/mqtt-plus-0-fixture.ts +2 -2
  56. package/tst/mqtt-plus-0-mosquitto.ts +5 -0
  57. package/tst/mqtt-plus-1-api.spec.ts +1 -1
  58. package/tst/mqtt-plus-2-event.spec.ts +0 -6
  59. package/tst/mqtt-plus-3-service.spec.ts +3 -7
  60. package/tst/mqtt-plus-4-sink.spec.ts +14 -9
  61. package/tst/mqtt-plus-5-source.spec.ts +11 -5
  62. package/tst/mqtt-plus-6-misc.spec.ts +23 -23
  63. package/tst/tsc.json +1 -1
  64. package/doc/mqtt-plus-communication.md +0 -68
  65. /package/doc/{mqtt-plus-1-event-emission.d2 → mqtt-plus-comm-event-emission.d2} +0 -0
  66. /package/doc/{mqtt-plus-1-event-emission.svg → mqtt-plus-comm-event-emission.svg} +0 -0
  67. /package/doc/{mqtt-plus-2-service-call.d2 → mqtt-plus-comm-service-call.d2} +0 -0
  68. /package/doc/{mqtt-plus-2-service-call.svg → mqtt-plus-comm-service-call.svg} +0 -0
  69. /package/doc/{mqtt-plus-3-sink-push.d2 → mqtt-plus-comm-sink-push.d2} +0 -0
  70. /package/doc/{mqtt-plus-3-sink-push.svg → mqtt-plus-comm-sink-push.svg} +0 -0
  71. /package/doc/{mqtt-plus-4-source-fetch.d2 → mqtt-plus-comm-source-fetch.d2} +0 -0
  72. /package/doc/{mqtt-plus-4-source-fetch.svg → mqtt-plus-comm-source-fetch.svg} +0 -0
  73. /package/{doc/theme.d2 → etc/d2.theme.d2} +0 -0
@@ -1,14 +1,14 @@
1
- (function(Ze,Qt){typeof exports=="object"&&typeof module<"u"?module.exports=Qt():typeof define=="function"&&define.amd?define(Qt):(Ze=typeof globalThis<"u"?globalThis:Ze||self,Ze.MQTTp=Qt())})(this,(function(){"use strict";var Ze=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Qt(t){if(Object.prototype.hasOwnProperty.call(t,"__esModule"))return t;var e=t.default;if(typeof e=="function"){var r=function n(){var s=!1;try{s=this instanceof n}catch{}return s?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};r.prototype=e.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(t).forEach(function(n){var s=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(r,n,s.get?s:{enumerable:!0,get:function(){return t[n]}})}),r}var dr={exports:{}},On;function pr(){if(On)return dr.exports;On=1;var t=typeof Reflect=="object"?Reflect:null,e=t&&typeof t.apply=="function"?t.apply:function(T,M,C){return Function.prototype.apply.call(T,M,C)},r;t&&typeof t.ownKeys=="function"?r=t.ownKeys:Object.getOwnPropertySymbols?r=function(T){return Object.getOwnPropertyNames(T).concat(Object.getOwnPropertySymbols(T))}:r=function(T){return Object.getOwnPropertyNames(T)};function n(S){console&&console.warn&&console.warn(S)}var s=Number.isNaN||function(T){return T!==T};function i(){i.init.call(this)}dr.exports=i,dr.exports.once=_,i.EventEmitter=i,i.prototype._events=void 0,i.prototype._eventsCount=0,i.prototype._maxListeners=void 0;var c=10;function l(S){if(typeof S!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof S)}Object.defineProperty(i,"defaultMaxListeners",{enumerable:!0,get:function(){return c},set:function(S){if(typeof S!="number"||S<0||s(S))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+S+".");c=S}}),i.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},i.prototype.setMaxListeners=function(T){if(typeof T!="number"||T<0||s(T))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+T+".");return this._maxListeners=T,this};function h(S){return S._maxListeners===void 0?i.defaultMaxListeners:S._maxListeners}i.prototype.getMaxListeners=function(){return h(this)},i.prototype.emit=function(T){for(var M=[],C=1;C<arguments.length;C++)M.push(arguments[C]);var U=T==="error",W=this._events;if(W!==void 0)U=U&&W.error===void 0;else if(!U)return!1;if(U){var J;if(M.length>0&&(J=M[0]),J instanceof Error)throw J;var Q=new Error("Unhandled error."+(J?" ("+J.message+")":""));throw Q.context=J,Q}var k=W[T];if(k===void 0)return!1;if(typeof k=="function")e(k,this,M);else for(var Y=k.length,se=F(k,Y),C=0;C<Y;++C)e(se[C],this,M);return!0};function w(S,T,M,C){var U,W,J;if(l(M),W=S._events,W===void 0?(W=S._events=Object.create(null),S._eventsCount=0):(W.newListener!==void 0&&(S.emit("newListener",T,M.listener?M.listener:M),W=S._events),J=W[T]),J===void 0)J=W[T]=M,++S._eventsCount;else if(typeof J=="function"?J=W[T]=C?[M,J]:[J,M]:C?J.unshift(M):J.push(M),U=h(S),U>0&&J.length>U&&!J.warned){J.warned=!0;var Q=new Error("Possible EventEmitter memory leak detected. "+J.length+" "+String(T)+" listeners added. Use emitter.setMaxListeners() to increase limit");Q.name="MaxListenersExceededWarning",Q.emitter=S,Q.type=T,Q.count=J.length,n(Q)}return S}i.prototype.addListener=function(T,M){return w(this,T,M,!1)},i.prototype.on=i.prototype.addListener,i.prototype.prependListener=function(T,M){return w(this,T,M,!0)};function d(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function I(S,T,M){var C={fired:!1,wrapFn:void 0,target:S,type:T,listener:M},U=d.bind(C);return U.listener=M,C.wrapFn=U,U}i.prototype.once=function(T,M){return l(M),this.on(T,I(this,T,M)),this},i.prototype.prependOnceListener=function(T,M){return l(M),this.prependListener(T,I(this,T,M)),this},i.prototype.removeListener=function(T,M){var C,U,W,J,Q;if(l(M),U=this._events,U===void 0)return this;if(C=U[T],C===void 0)return this;if(C===M||C.listener===M)--this._eventsCount===0?this._events=Object.create(null):(delete U[T],U.removeListener&&this.emit("removeListener",T,C.listener||M));else if(typeof C!="function"){for(W=-1,J=C.length-1;J>=0;J--)if(C[J]===M||C[J].listener===M){Q=C[J].listener,W=J;break}if(W<0)return this;W===0?C.shift():$(C,W),C.length===1&&(U[T]=C[0]),U.removeListener!==void 0&&this.emit("removeListener",T,Q||M)}return this},i.prototype.off=i.prototype.removeListener,i.prototype.removeAllListeners=function(T){var M,C,U;if(C=this._events,C===void 0)return this;if(C.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):C[T]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete C[T]),this;if(arguments.length===0){var W=Object.keys(C),J;for(U=0;U<W.length;++U)J=W[U],J!=="removeListener"&&this.removeAllListeners(J);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(M=C[T],typeof M=="function")this.removeListener(T,M);else if(M!==void 0)for(U=M.length-1;U>=0;U--)this.removeListener(T,M[U]);return this};function v(S,T,M){var C=S._events;if(C===void 0)return[];var U=C[T];return U===void 0?[]:typeof U=="function"?M?[U.listener||U]:[U]:M?j(U):F(U,U.length)}i.prototype.listeners=function(T){return v(this,T,!0)},i.prototype.rawListeners=function(T){return v(this,T,!1)},i.listenerCount=function(S,T){return typeof S.listenerCount=="function"?S.listenerCount(T):N.call(S,T)},i.prototype.listenerCount=N;function N(S){var T=this._events;if(T!==void 0){var M=T[S];if(typeof M=="function")return 1;if(M!==void 0)return M.length}return 0}i.prototype.eventNames=function(){return this._eventsCount>0?r(this._events):[]};function F(S,T){for(var M=new Array(T),C=0;C<T;++C)M[C]=S[C];return M}function $(S,T){for(;T+1<S.length;T++)S[T]=S[T+1];S.pop()}function j(S){for(var T=new Array(S.length),M=0;M<T.length;++M)T[M]=S[M].listener||S[M];return T}function _(S,T){return new Promise(function(M,C){function U(J){S.removeListener(T,W),C(J)}function W(){typeof S.removeListener=="function"&&S.removeListener("error",U),M([].slice.call(arguments))}R(S,T,W,{once:!0}),T!=="error"&&A(S,U,{once:!0})})}function A(S,T,M){typeof S.on=="function"&&R(S,"error",T,M)}function R(S,T,M,C){if(typeof S.on=="function")C.once?S.once(T,M):S.on(T,M);else if(typeof S.addEventListener=="function")S.addEventListener(T,function U(W){C.once&&S.removeEventListener(T,U),M(W)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof S)}return dr.exports}var yr={exports:{}},$n;function Lt(){return $n||($n=1,typeof Object.create=="function"?yr.exports=function(e,r){r&&(e.super_=r,e.prototype=Object.create(r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}))}:yr.exports=function(e,r){if(r){e.super_=r;var n=function(){};n.prototype=r.prototype,e.prototype=new n,e.prototype.constructor=e}}),yr.exports}function Ws(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var jn={exports:{}},Ae=jn.exports={},et,tt;function jr(){throw new Error("setTimeout has not been defined")}function qr(){throw new Error("clearTimeout has not been defined")}(function(){try{typeof setTimeout=="function"?et=setTimeout:et=jr}catch{et=jr}try{typeof clearTimeout=="function"?tt=clearTimeout:tt=qr}catch{tt=qr}})();function qn(t){if(et===setTimeout)return setTimeout(t,0);if((et===jr||!et)&&setTimeout)return et=setTimeout,setTimeout(t,0);try{return et(t,0)}catch{try{return et.call(null,t,0)}catch{return et.call(this,t,0)}}}function Hs(t){if(tt===clearTimeout)return clearTimeout(t);if((tt===qr||!tt)&&clearTimeout)return tt=clearTimeout,clearTimeout(t);try{return tt(t)}catch{try{return tt.call(null,t)}catch{return tt.call(this,t)}}}var lt=[],Ct=!1,Rt,wr=-1;function Gs(){!Ct||!Rt||(Ct=!1,Rt.length?lt=Rt.concat(lt):wr=-1,lt.length&&Kn())}function Kn(){if(!Ct){var t=qn(Gs);Ct=!0;for(var e=lt.length;e;){for(Rt=lt,lt=[];++wr<e;)Rt&&Rt[wr].run();wr=-1,e=lt.length}Rt=null,Ct=!1,Hs(t)}}Ae.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)e[r-1]=arguments[r];lt.push(new Wn(t,e)),lt.length===1&&!Ct&&qn(Kn)};function Wn(t,e){this.fun=t,this.array=e}Wn.prototype.run=function(){this.fun.apply(null,this.array)},Ae.title="browser",Ae.browser=!0,Ae.env={},Ae.argv=[],Ae.version="",Ae.versions={};function ht(){}Ae.on=ht,Ae.addListener=ht,Ae.once=ht,Ae.off=ht,Ae.removeListener=ht,Ae.removeAllListeners=ht,Ae.emit=ht,Ae.prependListener=ht,Ae.prependOnceListener=ht,Ae.listeners=function(t){return[]},Ae.binding=function(t){throw new Error("process.binding is not supported")},Ae.cwd=function(){return"/"},Ae.chdir=function(t){throw new Error("process.chdir is not supported")},Ae.umask=function(){return 0};var Js=jn.exports;const he=Ws(Js);var Kr,Hn;function Gn(){return Hn||(Hn=1,Kr=pr().EventEmitter),Kr}var Wr={},Jn;function gr(){return Jn||(Jn=1,(function(t){Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var e={},r={};r.byteLength=d,r.toByteArray=v,r.fromByteArray=$;for(var n=[],s=[],i=typeof Uint8Array<"u"?Uint8Array:Array,c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",l=0,h=c.length;l<h;++l)n[l]=c[l],s[c.charCodeAt(l)]=l;s[45]=62,s[95]=63;function w(A){var R=A.length;if(R%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var S=A.indexOf("=");S===-1&&(S=R);var T=S===R?0:4-S%4;return[S,T]}function d(A){var R=w(A),S=R[0],T=R[1];return(S+T)*3/4-T}function I(A,R,S){return(R+S)*3/4-S}function v(A){var R,S=w(A),T=S[0],M=S[1],C=new i(I(A,T,M)),U=0,W=M>0?T-4:T,J;for(J=0;J<W;J+=4)R=s[A.charCodeAt(J)]<<18|s[A.charCodeAt(J+1)]<<12|s[A.charCodeAt(J+2)]<<6|s[A.charCodeAt(J+3)],C[U++]=R>>16&255,C[U++]=R>>8&255,C[U++]=R&255;return M===2&&(R=s[A.charCodeAt(J)]<<2|s[A.charCodeAt(J+1)]>>4,C[U++]=R&255),M===1&&(R=s[A.charCodeAt(J)]<<10|s[A.charCodeAt(J+1)]<<4|s[A.charCodeAt(J+2)]>>2,C[U++]=R>>8&255,C[U++]=R&255),C}function N(A){return n[A>>18&63]+n[A>>12&63]+n[A>>6&63]+n[A&63]}function F(A,R,S){for(var T,M=[],C=R;C<S;C+=3)T=(A[C]<<16&16711680)+(A[C+1]<<8&65280)+(A[C+2]&255),M.push(N(T));return M.join("")}function $(A){for(var R,S=A.length,T=S%3,M=[],C=16383,U=0,W=S-T;U<W;U+=C)M.push(F(A,U,U+C>W?W:U+C));return T===1?(R=A[S-1],M.push(n[R>>2]+n[R<<4&63]+"==")):T===2&&(R=(A[S-2]<<8)+A[S-1],M.push(n[R>>10]+n[R>>4&63]+n[R<<2&63]+"=")),M.join("")}var j={};j.read=function(A,R,S,T,M){var C,U,W=M*8-T-1,J=(1<<W)-1,Q=J>>1,k=-7,Y=S?M-1:0,se=S?-1:1,fe=A[R+Y];for(Y+=se,C=fe&(1<<-k)-1,fe>>=-k,k+=W;k>0;C=C*256+A[R+Y],Y+=se,k-=8);for(U=C&(1<<-k)-1,C>>=-k,k+=T;k>0;U=U*256+A[R+Y],Y+=se,k-=8);if(C===0)C=1-Q;else{if(C===J)return U?NaN:(fe?-1:1)*(1/0);U=U+Math.pow(2,T),C=C-Q}return(fe?-1:1)*U*Math.pow(2,C-T)},j.write=function(A,R,S,T,M,C){var U,W,J,Q=C*8-M-1,k=(1<<Q)-1,Y=k>>1,se=M===23?Math.pow(2,-24)-Math.pow(2,-77):0,fe=T?0:C-1,Re=T?1:-1,Te=R<0||R===0&&1/R<0?1:0;for(R=Math.abs(R),isNaN(R)||R===1/0?(W=isNaN(R)?1:0,U=k):(U=Math.floor(Math.log(R)/Math.LN2),R*(J=Math.pow(2,-U))<1&&(U--,J*=2),U+Y>=1?R+=se/J:R+=se*Math.pow(2,1-Y),R*J>=2&&(U++,J/=2),U+Y>=k?(W=0,U=k):U+Y>=1?(W=(R*J-1)*Math.pow(2,M),U=U+Y):(W=R*Math.pow(2,Y-1)*Math.pow(2,M),U=0));M>=8;A[S+fe]=W&255,fe+=Re,W/=256,M-=8);for(U=U<<M|W,Q+=M;Q>0;A[S+fe]=U&255,fe+=Re,U/=256,Q-=8);A[S+fe-Re]|=Te*128};(function(A){const R=r,S=j,T=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;A.Buffer=k,A.SlowBuffer=Ye,A.INSPECT_MAX_BYTES=50;const M=2147483647;A.kMaxLength=M;const{Uint8Array:C,ArrayBuffer:U,SharedArrayBuffer:W}=globalThis;k.TYPED_ARRAY_SUPPORT=J(),!k.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function J(){try{const y=new C(1),a={foo:function(){return 42}};return Object.setPrototypeOf(a,C.prototype),Object.setPrototypeOf(y,a),y.foo()===42}catch{return!1}}Object.defineProperty(k.prototype,"parent",{enumerable:!0,get:function(){if(k.isBuffer(this))return this.buffer}}),Object.defineProperty(k.prototype,"offset",{enumerable:!0,get:function(){if(k.isBuffer(this))return this.byteOffset}});function Q(y){if(y>M)throw new RangeError('The value "'+y+'" is invalid for option "size"');const a=new C(y);return Object.setPrototypeOf(a,k.prototype),a}function k(y,a,f){if(typeof y=="number"){if(typeof a=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return Re(y)}return Y(y,a,f)}k.poolSize=8192;function Y(y,a,f){if(typeof y=="string")return Te(y,a);if(U.isView(y))return He(y);if(y==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof y);if(ft(y,U)||y&&ft(y.buffer,U)||typeof W<"u"&&(ft(y,W)||y&&ft(y.buffer,W)))return at(y,a,f);if(typeof y=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const m=y.valueOf&&y.valueOf();if(m!=null&&m!==y)return k.from(m,a,f);const B=Ut(y);if(B)return B;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof y[Symbol.toPrimitive]=="function")return k.from(y[Symbol.toPrimitive]("string"),a,f);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof y)}k.from=function(y,a,f){return Y(y,a,f)},Object.setPrototypeOf(k.prototype,C.prototype),Object.setPrototypeOf(k,C);function se(y){if(typeof y!="number")throw new TypeError('"size" argument must be of type number');if(y<0)throw new RangeError('The value "'+y+'" is invalid for option "size"')}function fe(y,a,f){return se(y),y<=0?Q(y):a!==void 0?typeof f=="string"?Q(y).fill(a,f):Q(y).fill(a):Q(y)}k.alloc=function(y,a,f){return fe(y,a,f)};function Re(y){return se(y),Q(y<0?0:ct(y)|0)}k.allocUnsafe=function(y){return Re(y)},k.allocUnsafeSlow=function(y){return Re(y)};function Te(y,a){if((typeof a!="string"||a==="")&&(a="utf8"),!k.isEncoding(a))throw new TypeError("Unknown encoding: "+a);const f=we(y,a)|0;let m=Q(f);const B=m.write(y,a);return B!==f&&(m=m.slice(0,B)),m}function Ce(y){const a=y.length<0?0:ct(y.length)|0,f=Q(a);for(let m=0;m<a;m+=1)f[m]=y[m]&255;return f}function He(y){if(ft(y,C)){const a=new C(y);return at(a.buffer,a.byteOffset,a.byteLength)}return Ce(y)}function at(y,a,f){if(a<0||y.byteLength<a)throw new RangeError('"offset" is outside of buffer bounds');if(y.byteLength<a+(f||0))throw new RangeError('"length" is outside of buffer bounds');let m;return a===void 0&&f===void 0?m=new C(y):f===void 0?m=new C(y,a):m=new C(y,a,f),Object.setPrototypeOf(m,k.prototype),m}function Ut(y){if(k.isBuffer(y)){const a=ct(y.length)|0,f=Q(a);return f.length===0||y.copy(f,0,0,a),f}if(y.length!==void 0)return typeof y.length!="number"||Dn(y.length)?Q(0):Ce(y);if(y.type==="Buffer"&&Array.isArray(y.data))return Ce(y.data)}function ct(y){if(y>=M)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+M.toString(16)+" bytes");return y|0}function Ye(y){return+y!=y&&(y=0),k.alloc(+y)}k.isBuffer=function(a){return a!=null&&a._isBuffer===!0&&a!==k.prototype},k.compare=function(a,f){if(ft(a,C)&&(a=k.from(a,a.offset,a.byteLength)),ft(f,C)&&(f=k.from(f,f.offset,f.byteLength)),!k.isBuffer(a)||!k.isBuffer(f))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(a===f)return 0;let m=a.length,B=f.length;for(let O=0,K=Math.min(m,B);O<K;++O)if(a[O]!==f[O]){m=a[O],B=f[O];break}return m<B?-1:B<m?1:0},k.isEncoding=function(a){switch(String(a).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},k.concat=function(a,f){if(!Array.isArray(a))throw new TypeError('"list" argument must be an Array of Buffers');if(a.length===0)return k.alloc(0);let m;if(f===void 0)for(f=0,m=0;m<a.length;++m)f+=a[m].length;const B=k.allocUnsafe(f);let O=0;for(m=0;m<a.length;++m){let K=a[m];if(ft(K,C))O+K.length>B.length?(k.isBuffer(K)||(K=k.from(K)),K.copy(B,O)):C.prototype.set.call(B,K,O);else if(k.isBuffer(K))K.copy(B,O);else throw new TypeError('"list" argument must be an Array of Buffers');O+=K.length}return B};function we(y,a){if(k.isBuffer(y))return y.length;if(U.isView(y)||ft(y,U))return y.byteLength;if(typeof y!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof y);const f=y.length,m=arguments.length>2&&arguments[2]===!0;if(!m&&f===0)return 0;let B=!1;for(;;)switch(a){case"ascii":case"latin1":case"binary":return f;case"utf8":case"utf-8":return pe(y).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return f*2;case"hex":return f>>>1;case"base64":return ue(y).length;default:if(B)return m?-1:pe(y).length;a=(""+a).toLowerCase(),B=!0}}k.byteLength=we;function Be(y,a,f){let m=!1;if((a===void 0||a<0)&&(a=0),a>this.length||((f===void 0||f>this.length)&&(f=this.length),f<=0)||(f>>>=0,a>>>=0,f<=a))return"";for(y||(y="utf8");;)switch(y){case"hex":return vt(this,a,f);case"utf8":case"utf-8":return le(this,a,f);case"ascii":return ut(this,a,f);case"latin1":case"binary":return Tt(this,a,f);case"base64":return V(this,a,f);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return hr(this,a,f);default:if(m)throw new TypeError("Unknown encoding: "+y);y=(y+"").toLowerCase(),m=!0}}k.prototype._isBuffer=!0;function P(y,a,f){const m=y[a];y[a]=y[f],y[f]=m}k.prototype.swap16=function(){const a=this.length;if(a%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let f=0;f<a;f+=2)P(this,f,f+1);return this},k.prototype.swap32=function(){const a=this.length;if(a%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let f=0;f<a;f+=4)P(this,f,f+3),P(this,f+1,f+2);return this},k.prototype.swap64=function(){const a=this.length;if(a%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let f=0;f<a;f+=8)P(this,f,f+7),P(this,f+1,f+6),P(this,f+2,f+5),P(this,f+3,f+4);return this},k.prototype.toString=function(){const a=this.length;return a===0?"":arguments.length===0?le(this,0,a):Be.apply(this,arguments)},k.prototype.toLocaleString=k.prototype.toString,k.prototype.equals=function(a){if(!k.isBuffer(a))throw new TypeError("Argument must be a Buffer");return this===a?!0:k.compare(this,a)===0},k.prototype.inspect=function(){let a="";const f=A.INSPECT_MAX_BYTES;return a=this.toString("hex",0,f).replace(/(.{2})/g,"$1 ").trim(),this.length>f&&(a+=" ... "),"<Buffer "+a+">"},T&&(k.prototype[T]=k.prototype.inspect),k.prototype.compare=function(a,f,m,B,O){if(ft(a,C)&&(a=k.from(a,a.offset,a.byteLength)),!k.isBuffer(a))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof a);if(f===void 0&&(f=0),m===void 0&&(m=a?a.length:0),B===void 0&&(B=0),O===void 0&&(O=this.length),f<0||m>a.length||B<0||O>this.length)throw new RangeError("out of range index");if(B>=O&&f>=m)return 0;if(B>=O)return-1;if(f>=m)return 1;if(f>>>=0,m>>>=0,B>>>=0,O>>>=0,this===a)return 0;let K=O-B,ie=m-f;const ve=Math.min(K,ie),me=this.slice(B,O),xe=a.slice(f,m);for(let de=0;de<ve;++de)if(me[de]!==xe[de]){K=me[de],ie=xe[de];break}return K<ie?-1:ie<K?1:0};function L(y,a,f,m,B){if(y.length===0)return-1;if(typeof f=="string"?(m=f,f=0):f>2147483647?f=2147483647:f<-2147483648&&(f=-2147483648),f=+f,Dn(f)&&(f=B?0:y.length-1),f<0&&(f=y.length+f),f>=y.length){if(B)return-1;f=y.length-1}else if(f<0)if(B)f=0;else return-1;if(typeof a=="string"&&(a=k.from(a,m)),k.isBuffer(a))return a.length===0?-1:G(y,a,f,m,B);if(typeof a=="number")return a=a&255,typeof C.prototype.indexOf=="function"?B?C.prototype.indexOf.call(y,a,f):C.prototype.lastIndexOf.call(y,a,f):G(y,[a],f,m,B);throw new TypeError("val must be string, number or Buffer")}function G(y,a,f,m,B){let O=1,K=y.length,ie=a.length;if(m!==void 0&&(m=String(m).toLowerCase(),m==="ucs2"||m==="ucs-2"||m==="utf16le"||m==="utf-16le")){if(y.length<2||a.length<2)return-1;O=2,K/=2,ie/=2,f/=2}function ve(xe,de){return O===1?xe[de]:xe.readUInt16BE(de*O)}let me;if(B){let xe=-1;for(me=f;me<K;me++)if(ve(y,me)===ve(a,xe===-1?0:me-xe)){if(xe===-1&&(xe=me),me-xe+1===ie)return xe*O}else xe!==-1&&(me-=me-xe),xe=-1}else for(f+ie>K&&(f=K-ie),me=f;me>=0;me--){let xe=!0;for(let de=0;de<ie;de++)if(ve(y,me+de)!==ve(a,de)){xe=!1;break}if(xe)return me}return-1}k.prototype.includes=function(a,f,m){return this.indexOf(a,f,m)!==-1},k.prototype.indexOf=function(a,f,m){return L(this,a,f,m,!0)},k.prototype.lastIndexOf=function(a,f,m){return L(this,a,f,m,!1)};function X(y,a,f,m){f=Number(f)||0;const B=y.length-f;m?(m=Number(m),m>B&&(m=B)):m=B;const O=a.length;m>O/2&&(m=O/2);let K;for(K=0;K<m;++K){const ie=parseInt(a.substr(K*2,2),16);if(Dn(ie))return K;y[f+K]=ie}return K}function re(y,a,f,m){return Or(pe(a,y.length-f),y,f,m)}function b(y,a,f,m){return Or(ye(a),y,f,m)}function E(y,a,f,m){return Or(ue(a),y,f,m)}function H(y,a,f,m){return Or(ge(a,y.length-f),y,f,m)}k.prototype.write=function(a,f,m,B){if(f===void 0)B="utf8",m=this.length,f=0;else if(m===void 0&&typeof f=="string")B=f,m=this.length,f=0;else if(isFinite(f))f=f>>>0,isFinite(m)?(m=m>>>0,B===void 0&&(B="utf8")):(B=m,m=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const O=this.length-f;if((m===void 0||m>O)&&(m=O),a.length>0&&(m<0||f<0)||f>this.length)throw new RangeError("Attempt to write outside buffer bounds");B||(B="utf8");let K=!1;for(;;)switch(B){case"hex":return X(this,a,f,m);case"utf8":case"utf-8":return re(this,a,f,m);case"ascii":case"latin1":case"binary":return b(this,a,f,m);case"base64":return E(this,a,f,m);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return H(this,a,f,m);default:if(K)throw new TypeError("Unknown encoding: "+B);B=(""+B).toLowerCase(),K=!0}},k.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function V(y,a,f){return a===0&&f===y.length?R.fromByteArray(y):R.fromByteArray(y.slice(a,f))}function le(y,a,f){f=Math.min(y.length,f);const m=[];let B=a;for(;B<f;){const O=y[B];let K=null,ie=O>239?4:O>223?3:O>191?2:1;if(B+ie<=f){let ve,me,xe,de;switch(ie){case 1:O<128&&(K=O);break;case 2:ve=y[B+1],(ve&192)===128&&(de=(O&31)<<6|ve&63,de>127&&(K=de));break;case 3:ve=y[B+1],me=y[B+2],(ve&192)===128&&(me&192)===128&&(de=(O&15)<<12|(ve&63)<<6|me&63,de>2047&&(de<55296||de>57343)&&(K=de));break;case 4:ve=y[B+1],me=y[B+2],xe=y[B+3],(ve&192)===128&&(me&192)===128&&(xe&192)===128&&(de=(O&15)<<18|(ve&63)<<12|(me&63)<<6|xe&63,de>65535&&de<1114112&&(K=de))}}K===null?(K=65533,ie=1):K>65535&&(K-=65536,m.push(K>>>10&1023|55296),K=56320|K&1023),m.push(K),B+=ie}return ae(m)}const Z=4096;function ae(y){const a=y.length;if(a<=Z)return String.fromCharCode.apply(String,y);let f="",m=0;for(;m<a;)f+=String.fromCharCode.apply(String,y.slice(m,m+=Z));return f}function ut(y,a,f){let m="";f=Math.min(y.length,f);for(let B=a;B<f;++B)m+=String.fromCharCode(y[B]&127);return m}function Tt(y,a,f){let m="";f=Math.min(y.length,f);for(let B=a;B<f;++B)m+=String.fromCharCode(y[B]);return m}function vt(y,a,f){const m=y.length;(!a||a<0)&&(a=0),(!f||f<0||f>m)&&(f=m);let B="";for(let O=a;O<f;++O)B+=Rc[y[O]];return B}function hr(y,a,f){const m=y.slice(a,f);let B="";for(let O=0;O<m.length-1;O+=2)B+=String.fromCharCode(m[O]+m[O+1]*256);return B}k.prototype.slice=function(a,f){const m=this.length;a=~~a,f=f===void 0?m:~~f,a<0?(a+=m,a<0&&(a=0)):a>m&&(a=m),f<0?(f+=m,f<0&&(f=0)):f>m&&(f=m),f<a&&(f=a);const B=this.subarray(a,f);return Object.setPrototypeOf(B,k.prototype),B};function Ee(y,a,f){if(y%1!==0||y<0)throw new RangeError("offset is not uint");if(y+a>f)throw new RangeError("Trying to access beyond buffer length")}k.prototype.readUintLE=k.prototype.readUIntLE=function(a,f,m){a=a>>>0,f=f>>>0,m||Ee(a,f,this.length);let B=this[a],O=1,K=0;for(;++K<f&&(O*=256);)B+=this[a+K]*O;return B},k.prototype.readUintBE=k.prototype.readUIntBE=function(a,f,m){a=a>>>0,f=f>>>0,m||Ee(a,f,this.length);let B=this[a+--f],O=1;for(;f>0&&(O*=256);)B+=this[a+--f]*O;return B},k.prototype.readUint8=k.prototype.readUInt8=function(a,f){return a=a>>>0,f||Ee(a,1,this.length),this[a]},k.prototype.readUint16LE=k.prototype.readUInt16LE=function(a,f){return a=a>>>0,f||Ee(a,2,this.length),this[a]|this[a+1]<<8},k.prototype.readUint16BE=k.prototype.readUInt16BE=function(a,f){return a=a>>>0,f||Ee(a,2,this.length),this[a]<<8|this[a+1]},k.prototype.readUint32LE=k.prototype.readUInt32LE=function(a,f){return a=a>>>0,f||Ee(a,4,this.length),(this[a]|this[a+1]<<8|this[a+2]<<16)+this[a+3]*16777216},k.prototype.readUint32BE=k.prototype.readUInt32BE=function(a,f){return a=a>>>0,f||Ee(a,4,this.length),this[a]*16777216+(this[a+1]<<16|this[a+2]<<8|this[a+3])},k.prototype.readBigUInt64LE=At(function(a){a=a>>>0,x(a,"offset");const f=this[a],m=this[a+7];(f===void 0||m===void 0)&&D(a,this.length-8);const B=f+this[++a]*2**8+this[++a]*2**16+this[++a]*2**24,O=this[++a]+this[++a]*2**8+this[++a]*2**16+m*2**24;return BigInt(B)+(BigInt(O)<<BigInt(32))}),k.prototype.readBigUInt64BE=At(function(a){a=a>>>0,x(a,"offset");const f=this[a],m=this[a+7];(f===void 0||m===void 0)&&D(a,this.length-8);const B=f*2**24+this[++a]*2**16+this[++a]*2**8+this[++a],O=this[++a]*2**24+this[++a]*2**16+this[++a]*2**8+m;return(BigInt(B)<<BigInt(32))+BigInt(O)}),k.prototype.readIntLE=function(a,f,m){a=a>>>0,f=f>>>0,m||Ee(a,f,this.length);let B=this[a],O=1,K=0;for(;++K<f&&(O*=256);)B+=this[a+K]*O;return O*=128,B>=O&&(B-=Math.pow(2,8*f)),B},k.prototype.readIntBE=function(a,f,m){a=a>>>0,f=f>>>0,m||Ee(a,f,this.length);let B=f,O=1,K=this[a+--B];for(;B>0&&(O*=256);)K+=this[a+--B]*O;return O*=128,K>=O&&(K-=Math.pow(2,8*f)),K},k.prototype.readInt8=function(a,f){return a=a>>>0,f||Ee(a,1,this.length),this[a]&128?(255-this[a]+1)*-1:this[a]},k.prototype.readInt16LE=function(a,f){a=a>>>0,f||Ee(a,2,this.length);const m=this[a]|this[a+1]<<8;return m&32768?m|4294901760:m},k.prototype.readInt16BE=function(a,f){a=a>>>0,f||Ee(a,2,this.length);const m=this[a+1]|this[a]<<8;return m&32768?m|4294901760:m},k.prototype.readInt32LE=function(a,f){return a=a>>>0,f||Ee(a,4,this.length),this[a]|this[a+1]<<8|this[a+2]<<16|this[a+3]<<24},k.prototype.readInt32BE=function(a,f){return a=a>>>0,f||Ee(a,4,this.length),this[a]<<24|this[a+1]<<16|this[a+2]<<8|this[a+3]},k.prototype.readBigInt64LE=At(function(a){a=a>>>0,x(a,"offset");const f=this[a],m=this[a+7];(f===void 0||m===void 0)&&D(a,this.length-8);const B=this[a+4]+this[a+5]*2**8+this[a+6]*2**16+(m<<24);return(BigInt(B)<<BigInt(32))+BigInt(f+this[++a]*2**8+this[++a]*2**16+this[++a]*2**24)}),k.prototype.readBigInt64BE=At(function(a){a=a>>>0,x(a,"offset");const f=this[a],m=this[a+7];(f===void 0||m===void 0)&&D(a,this.length-8);const B=(f<<24)+this[++a]*2**16+this[++a]*2**8+this[++a];return(BigInt(B)<<BigInt(32))+BigInt(this[++a]*2**24+this[++a]*2**16+this[++a]*2**8+m)}),k.prototype.readFloatLE=function(a,f){return a=a>>>0,f||Ee(a,4,this.length),S.read(this,a,!0,23,4)},k.prototype.readFloatBE=function(a,f){return a=a>>>0,f||Ee(a,4,this.length),S.read(this,a,!1,23,4)},k.prototype.readDoubleLE=function(a,f){return a=a>>>0,f||Ee(a,8,this.length),S.read(this,a,!0,52,8)},k.prototype.readDoubleBE=function(a,f){return a=a>>>0,f||Ee(a,8,this.length),S.read(this,a,!1,52,8)};function Ie(y,a,f,m,B,O){if(!k.isBuffer(y))throw new TypeError('"buffer" argument must be a Buffer instance');if(a>B||a<O)throw new RangeError('"value" argument is out of bounds');if(f+m>y.length)throw new RangeError("Index out of range")}k.prototype.writeUintLE=k.prototype.writeUIntLE=function(a,f,m,B){if(a=+a,f=f>>>0,m=m>>>0,!B){const ie=Math.pow(2,8*m)-1;Ie(this,a,f,m,ie,0)}let O=1,K=0;for(this[f]=a&255;++K<m&&(O*=256);)this[f+K]=a/O&255;return f+m},k.prototype.writeUintBE=k.prototype.writeUIntBE=function(a,f,m,B){if(a=+a,f=f>>>0,m=m>>>0,!B){const ie=Math.pow(2,8*m)-1;Ie(this,a,f,m,ie,0)}let O=m-1,K=1;for(this[f+O]=a&255;--O>=0&&(K*=256);)this[f+O]=a/K&255;return f+m},k.prototype.writeUint8=k.prototype.writeUInt8=function(a,f,m){return a=+a,f=f>>>0,m||Ie(this,a,f,1,255,0),this[f]=a&255,f+1},k.prototype.writeUint16LE=k.prototype.writeUInt16LE=function(a,f,m){return a=+a,f=f>>>0,m||Ie(this,a,f,2,65535,0),this[f]=a&255,this[f+1]=a>>>8,f+2},k.prototype.writeUint16BE=k.prototype.writeUInt16BE=function(a,f,m){return a=+a,f=f>>>0,m||Ie(this,a,f,2,65535,0),this[f]=a>>>8,this[f+1]=a&255,f+2},k.prototype.writeUint32LE=k.prototype.writeUInt32LE=function(a,f,m){return a=+a,f=f>>>0,m||Ie(this,a,f,4,4294967295,0),this[f+3]=a>>>24,this[f+2]=a>>>16,this[f+1]=a>>>8,this[f]=a&255,f+4},k.prototype.writeUint32BE=k.prototype.writeUInt32BE=function(a,f,m){return a=+a,f=f>>>0,m||Ie(this,a,f,4,4294967295,0),this[f]=a>>>24,this[f+1]=a>>>16,this[f+2]=a>>>8,this[f+3]=a&255,f+4};function Qe(y,a,f,m,B){g(a,m,B,y,f,7);let O=Number(a&BigInt(4294967295));y[f++]=O,O=O>>8,y[f++]=O,O=O>>8,y[f++]=O,O=O>>8,y[f++]=O;let K=Number(a>>BigInt(32)&BigInt(4294967295));return y[f++]=K,K=K>>8,y[f++]=K,K=K>>8,y[f++]=K,K=K>>8,y[f++]=K,f}function Me(y,a,f,m,B){g(a,m,B,y,f,7);let O=Number(a&BigInt(4294967295));y[f+7]=O,O=O>>8,y[f+6]=O,O=O>>8,y[f+5]=O,O=O>>8,y[f+4]=O;let K=Number(a>>BigInt(32)&BigInt(4294967295));return y[f+3]=K,K=K>>8,y[f+2]=K,K=K>>8,y[f+1]=K,K=K>>8,y[f]=K,f+8}k.prototype.writeBigUInt64LE=At(function(a,f=0){return Qe(this,a,f,BigInt(0),BigInt("0xffffffffffffffff"))}),k.prototype.writeBigUInt64BE=At(function(a,f=0){return Me(this,a,f,BigInt(0),BigInt("0xffffffffffffffff"))}),k.prototype.writeIntLE=function(a,f,m,B){if(a=+a,f=f>>>0,!B){const ve=Math.pow(2,8*m-1);Ie(this,a,f,m,ve-1,-ve)}let O=0,K=1,ie=0;for(this[f]=a&255;++O<m&&(K*=256);)a<0&&ie===0&&this[f+O-1]!==0&&(ie=1),this[f+O]=(a/K>>0)-ie&255;return f+m},k.prototype.writeIntBE=function(a,f,m,B){if(a=+a,f=f>>>0,!B){const ve=Math.pow(2,8*m-1);Ie(this,a,f,m,ve-1,-ve)}let O=m-1,K=1,ie=0;for(this[f+O]=a&255;--O>=0&&(K*=256);)a<0&&ie===0&&this[f+O+1]!==0&&(ie=1),this[f+O]=(a/K>>0)-ie&255;return f+m},k.prototype.writeInt8=function(a,f,m){return a=+a,f=f>>>0,m||Ie(this,a,f,1,127,-128),a<0&&(a=255+a+1),this[f]=a&255,f+1},k.prototype.writeInt16LE=function(a,f,m){return a=+a,f=f>>>0,m||Ie(this,a,f,2,32767,-32768),this[f]=a&255,this[f+1]=a>>>8,f+2},k.prototype.writeInt16BE=function(a,f,m){return a=+a,f=f>>>0,m||Ie(this,a,f,2,32767,-32768),this[f]=a>>>8,this[f+1]=a&255,f+2},k.prototype.writeInt32LE=function(a,f,m){return a=+a,f=f>>>0,m||Ie(this,a,f,4,2147483647,-2147483648),this[f]=a&255,this[f+1]=a>>>8,this[f+2]=a>>>16,this[f+3]=a>>>24,f+4},k.prototype.writeInt32BE=function(a,f,m){return a=+a,f=f>>>0,m||Ie(this,a,f,4,2147483647,-2147483648),a<0&&(a=4294967295+a+1),this[f]=a>>>24,this[f+1]=a>>>16,this[f+2]=a>>>8,this[f+3]=a&255,f+4},k.prototype.writeBigInt64LE=At(function(a,f=0){return Qe(this,a,f,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),k.prototype.writeBigInt64BE=At(function(a,f=0){return Me(this,a,f,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Ge(y,a,f,m,B,O){if(f+m>y.length)throw new RangeError("Index out of range");if(f<0)throw new RangeError("Index out of range")}function Xe(y,a,f,m,B){return a=+a,f=f>>>0,B||Ge(y,a,f,4),S.write(y,a,f,m,23,4),f+4}k.prototype.writeFloatLE=function(a,f,m){return Xe(this,a,f,!0,m)},k.prototype.writeFloatBE=function(a,f,m){return Xe(this,a,f,!1,m)};function Ne(y,a,f,m,B){return a=+a,f=f>>>0,B||Ge(y,a,f,8),S.write(y,a,f,m,52,8),f+8}k.prototype.writeDoubleLE=function(a,f,m){return Ne(this,a,f,!0,m)},k.prototype.writeDoubleBE=function(a,f,m){return Ne(this,a,f,!1,m)},k.prototype.copy=function(a,f,m,B){if(!k.isBuffer(a))throw new TypeError("argument should be a Buffer");if(m||(m=0),!B&&B!==0&&(B=this.length),f>=a.length&&(f=a.length),f||(f=0),B>0&&B<m&&(B=m),B===m||a.length===0||this.length===0)return 0;if(f<0)throw new RangeError("targetStart out of bounds");if(m<0||m>=this.length)throw new RangeError("Index out of range");if(B<0)throw new RangeError("sourceEnd out of bounds");B>this.length&&(B=this.length),a.length-f<B-m&&(B=a.length-f+m);const O=B-m;return this===a&&typeof C.prototype.copyWithin=="function"?this.copyWithin(f,m,B):C.prototype.set.call(a,this.subarray(m,B),f),O},k.prototype.fill=function(a,f,m,B){if(typeof a=="string"){if(typeof f=="string"?(B=f,f=0,m=this.length):typeof m=="string"&&(B=m,m=this.length),B!==void 0&&typeof B!="string")throw new TypeError("encoding must be a string");if(typeof B=="string"&&!k.isEncoding(B))throw new TypeError("Unknown encoding: "+B);if(a.length===1){const K=a.charCodeAt(0);(B==="utf8"&&K<128||B==="latin1")&&(a=K)}}else typeof a=="number"?a=a&255:typeof a=="boolean"&&(a=Number(a));if(f<0||this.length<f||this.length<m)throw new RangeError("Out of range index");if(m<=f)return this;f=f>>>0,m=m===void 0?this.length:m>>>0,a||(a=0);let O;if(typeof a=="number")for(O=f;O<m;++O)this[O]=a;else{const K=k.isBuffer(a)?a:k.from(a,B),ie=K.length;if(ie===0)throw new TypeError('The value "'+a+'" is invalid for argument "value"');for(O=0;O<m-f;++O)this[O+f]=K[O%ie]}return this};const xt={};function p(y,a,f){xt[y]=class extends f{constructor(){super(),Object.defineProperty(this,"message",{value:a.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${y}]`,this.stack,delete this.name}get code(){return y}set code(B){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:B,writable:!0})}toString(){return`${this.name} [${y}]: ${this.message}`}}}p("ERR_BUFFER_OUT_OF_BOUNDS",function(y){return y?`${y} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),p("ERR_INVALID_ARG_TYPE",function(y,a){return`The "${y}" argument must be of type number. Received type ${typeof a}`},TypeError),p("ERR_OUT_OF_RANGE",function(y,a,f){let m=`The value of "${y}" is out of range.`,B=f;return Number.isInteger(f)&&Math.abs(f)>2**32?B=o(String(f)):typeof f=="bigint"&&(B=String(f),(f>BigInt(2)**BigInt(32)||f<-(BigInt(2)**BigInt(32)))&&(B=o(B)),B+="n"),m+=` It must be ${a}. Received ${B}`,m},RangeError);function o(y){let a="",f=y.length;const m=y[0]==="-"?1:0;for(;f>=m+4;f-=3)a=`_${y.slice(f-3,f)}${a}`;return`${y.slice(0,f)}${a}`}function u(y,a,f){x(a,"offset"),(y[a]===void 0||y[a+f]===void 0)&&D(a,y.length-(f+1))}function g(y,a,f,m,B,O){if(y>f||y<a){const K=typeof a=="bigint"?"n":"";let ie;throw a===0||a===BigInt(0)?ie=`>= 0${K} and < 2${K} ** ${(O+1)*8}${K}`:ie=`>= -(2${K} ** ${(O+1)*8-1}${K}) and < 2 ** ${(O+1)*8-1}${K}`,new xt.ERR_OUT_OF_RANGE("value",ie,y)}u(m,B,O)}function x(y,a){if(typeof y!="number")throw new xt.ERR_INVALID_ARG_TYPE(a,"number",y)}function D(y,a,f){throw Math.floor(y)!==y?(x(y,f),new xt.ERR_OUT_OF_RANGE("offset","an integer",y)):a<0?new xt.ERR_BUFFER_OUT_OF_BOUNDS:new xt.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${a}`,y)}const q=/[^+/0-9A-Za-z-_]/g;function ne(y){if(y=y.split("=")[0],y=y.trim().replace(q,""),y.length<2)return"";for(;y.length%4!==0;)y=y+"=";return y}function pe(y,a){a=a||1/0;let f;const m=y.length;let B=null;const O=[];for(let K=0;K<m;++K){if(f=y.charCodeAt(K),f>55295&&f<57344){if(!B){if(f>56319){(a-=3)>-1&&O.push(239,191,189);continue}else if(K+1===m){(a-=3)>-1&&O.push(239,191,189);continue}B=f;continue}if(f<56320){(a-=3)>-1&&O.push(239,191,189),B=f;continue}f=(B-55296<<10|f-56320)+65536}else B&&(a-=3)>-1&&O.push(239,191,189);if(B=null,f<128){if((a-=1)<0)break;O.push(f)}else if(f<2048){if((a-=2)<0)break;O.push(f>>6|192,f&63|128)}else if(f<65536){if((a-=3)<0)break;O.push(f>>12|224,f>>6&63|128,f&63|128)}else if(f<1114112){if((a-=4)<0)break;O.push(f>>18|240,f>>12&63|128,f>>6&63|128,f&63|128)}else throw new Error("Invalid code point")}return O}function ye(y){const a=[];for(let f=0;f<y.length;++f)a.push(y.charCodeAt(f)&255);return a}function ge(y,a){let f,m,B;const O=[];for(let K=0;K<y.length&&!((a-=2)<0);++K)f=y.charCodeAt(K),m=f>>8,B=f%256,O.push(B),O.push(m);return O}function ue(y){return R.toByteArray(ne(y))}function Or(y,a,f,m){let B;for(B=0;B<m&&!(B+f>=a.length||B>=y.length);++B)a[B+f]=y[B];return B}function ft(y,a){return y instanceof a||y!=null&&y.constructor!=null&&y.constructor.name!=null&&y.constructor.name===a.name}function Dn(y){return y!==y}const Rc=(function(){const y="0123456789abcdef",a=new Array(256);for(let f=0;f<16;++f){const m=f*16;for(let B=0;B<16;++B)a[m+B]=y[f]+y[B]}return a})();function At(y){return typeof BigInt>"u"?Ic:y}function Ic(){throw new Error("BigInt not supported")}})(e);const _=e.Buffer;t.Blob=e.Blob,t.BlobOptions=e.BlobOptions,t.Buffer=e.Buffer,t.File=e.File,t.FileOptions=e.FileOptions,t.INSPECT_MAX_BYTES=e.INSPECT_MAX_BYTES,t.SlowBuffer=e.SlowBuffer,t.TranscodeEncoding=e.TranscodeEncoding,t.atob=e.atob,t.btoa=e.btoa,t.constants=e.constants,t.default=_,t.isAscii=e.isAscii,t.isUtf8=e.isUtf8,t.kMaxLength=e.kMaxLength,t.kStringMaxLength=e.kStringMaxLength,t.resolveObjectURL=e.resolveObjectURL,t.transcode=e.transcode})(Wr)),Wr}const zn=Qt(Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"})));var Hr,Vn;function zs(){if(Vn)return Hr;Vn=1;function t(F,$){var j=Object.keys(F);if(Object.getOwnPropertySymbols){var _=Object.getOwnPropertySymbols(F);$&&(_=_.filter(function(A){return Object.getOwnPropertyDescriptor(F,A).enumerable})),j.push.apply(j,_)}return j}function e(F){for(var $=1;$<arguments.length;$++){var j=arguments[$]!=null?arguments[$]:{};$%2?t(Object(j),!0).forEach(function(_){r(F,_,j[_])}):Object.getOwnPropertyDescriptors?Object.defineProperties(F,Object.getOwnPropertyDescriptors(j)):t(Object(j)).forEach(function(_){Object.defineProperty(F,_,Object.getOwnPropertyDescriptor(j,_))})}return F}function r(F,$,j){return $=c($),$ in F?Object.defineProperty(F,$,{value:j,enumerable:!0,configurable:!0,writable:!0}):F[$]=j,F}function n(F,$){if(!(F instanceof $))throw new TypeError("Cannot call a class as a function")}function s(F,$){for(var j=0;j<$.length;j++){var _=$[j];_.enumerable=_.enumerable||!1,_.configurable=!0,"value"in _&&(_.writable=!0),Object.defineProperty(F,c(_.key),_)}}function i(F,$,j){return $&&s(F.prototype,$),Object.defineProperty(F,"prototype",{writable:!1}),F}function c(F){var $=l(F,"string");return typeof $=="symbol"?$:String($)}function l(F,$){if(typeof F!="object"||F===null)return F;var j=F[Symbol.toPrimitive];if(j!==void 0){var _=j.call(F,$);if(typeof _!="object")return _;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(F)}var h=gr(),w=h.Buffer,d=zn,I=d.inspect,v=I&&I.custom||"inspect";function N(F,$,j){w.prototype.copy.call(F,$,j)}return Hr=(function(){function F(){n(this,F),this.head=null,this.tail=null,this.length=0}return i(F,[{key:"push",value:function(j){var _={data:j,next:null};this.length>0?this.tail.next=_:this.head=_,this.tail=_,++this.length}},{key:"unshift",value:function(j){var _={data:j,next:this.head};this.length===0&&(this.tail=_),this.head=_,++this.length}},{key:"shift",value:function(){if(this.length!==0){var j=this.head.data;return this.length===1?this.head=this.tail=null:this.head=this.head.next,--this.length,j}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(j){if(this.length===0)return"";for(var _=this.head,A=""+_.data;_=_.next;)A+=j+_.data;return A}},{key:"concat",value:function(j){if(this.length===0)return w.alloc(0);for(var _=w.allocUnsafe(j>>>0),A=this.head,R=0;A;)N(A.data,_,R),R+=A.data.length,A=A.next;return _}},{key:"consume",value:function(j,_){var A;return j<this.head.data.length?(A=this.head.data.slice(0,j),this.head.data=this.head.data.slice(j)):j===this.head.data.length?A=this.shift():A=_?this._getString(j):this._getBuffer(j),A}},{key:"first",value:function(){return this.head.data}},{key:"_getString",value:function(j){var _=this.head,A=1,R=_.data;for(j-=R.length;_=_.next;){var S=_.data,T=j>S.length?S.length:j;if(T===S.length?R+=S:R+=S.slice(0,j),j-=T,j===0){T===S.length?(++A,_.next?this.head=_.next:this.head=this.tail=null):(this.head=_,_.data=S.slice(T));break}++A}return this.length-=A,R}},{key:"_getBuffer",value:function(j){var _=w.allocUnsafe(j),A=this.head,R=1;for(A.data.copy(_),j-=A.data.length;A=A.next;){var S=A.data,T=j>S.length?S.length:j;if(S.copy(_,_.length-j,0,T),j-=T,j===0){T===S.length?(++R,A.next?this.head=A.next:this.head=this.tail=null):(this.head=A,A.data=S.slice(T));break}++R}return this.length-=R,_}},{key:v,value:function(j,_){return I(this,e(e({},_),{},{depth:0,customInspect:!1}))}}]),F})(),Hr}var Gr,Yn;function Qn(){if(Yn)return Gr;Yn=1;function t(c,l){var h=this,w=this._readableState&&this._readableState.destroyed,d=this._writableState&&this._writableState.destroyed;return w||d?(l?l(c):c&&(this._writableState?this._writableState.errorEmitted||(this._writableState.errorEmitted=!0,he.nextTick(s,this,c)):he.nextTick(s,this,c)),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(c||null,function(I){!l&&I?h._writableState?h._writableState.errorEmitted?he.nextTick(r,h):(h._writableState.errorEmitted=!0,he.nextTick(e,h,I)):he.nextTick(e,h,I):l?(he.nextTick(r,h),l(I)):he.nextTick(r,h)}),this)}function e(c,l){s(c,l),r(c)}function r(c){c._writableState&&!c._writableState.emitClose||c._readableState&&!c._readableState.emitClose||c.emit("close")}function n(){this._readableState&&(this._readableState.destroyed=!1,this._readableState.reading=!1,this._readableState.ended=!1,this._readableState.endEmitted=!1),this._writableState&&(this._writableState.destroyed=!1,this._writableState.ended=!1,this._writableState.ending=!1,this._writableState.finalCalled=!1,this._writableState.prefinished=!1,this._writableState.finished=!1,this._writableState.errorEmitted=!1)}function s(c,l){c.emit("error",l)}function i(c,l){var h=c._readableState,w=c._writableState;h&&h.autoDestroy||w&&w.autoDestroy?c.destroy(l):c.emit("error",l)}return Gr={destroy:t,undestroy:n,errorOrDestroy:i},Gr}var Jr={},Xn;function Pt(){if(Xn)return Jr;Xn=1;function t(l,h){l.prototype=Object.create(h.prototype),l.prototype.constructor=l,l.__proto__=h}var e={};function r(l,h,w){w||(w=Error);function d(v,N,F){return typeof h=="string"?h:h(v,N,F)}var I=(function(v){t(N,v);function N(F,$,j){return v.call(this,d(F,$,j))||this}return N})(w);I.prototype.name=w.name,I.prototype.code=l,e[l]=I}function n(l,h){if(Array.isArray(l)){var w=l.length;return l=l.map(function(d){return String(d)}),w>2?"one of ".concat(h," ").concat(l.slice(0,w-1).join(", "),", or ")+l[w-1]:w===2?"one of ".concat(h," ").concat(l[0]," or ").concat(l[1]):"of ".concat(h," ").concat(l[0])}else return"of ".concat(h," ").concat(String(l))}function s(l,h,w){return l.substr(0,h.length)===h}function i(l,h,w){return(w===void 0||w>l.length)&&(w=l.length),l.substring(w-h.length,w)===h}function c(l,h,w){return typeof w!="number"&&(w=0),w+h.length>l.length?!1:l.indexOf(h,w)!==-1}return r("ERR_INVALID_OPT_VALUE",function(l,h){return'The value "'+h+'" is invalid for option "'+l+'"'},TypeError),r("ERR_INVALID_ARG_TYPE",function(l,h,w){var d;typeof h=="string"&&s(h,"not ")?(d="must not be",h=h.replace(/^not /,"")):d="must be";var I;if(i(l," argument"))I="The ".concat(l," ").concat(d," ").concat(n(h,"type"));else{var v=c(l,".")?"property":"argument";I='The "'.concat(l,'" ').concat(v," ").concat(d," ").concat(n(h,"type"))}return I+=". Received type ".concat(typeof w),I},TypeError),r("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF"),r("ERR_METHOD_NOT_IMPLEMENTED",function(l){return"The "+l+" method is not implemented"}),r("ERR_STREAM_PREMATURE_CLOSE","Premature close"),r("ERR_STREAM_DESTROYED",function(l){return"Cannot call "+l+" after a stream was destroyed"}),r("ERR_MULTIPLE_CALLBACK","Callback called multiple times"),r("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable"),r("ERR_STREAM_WRITE_AFTER_END","write after end"),r("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError),r("ERR_UNKNOWN_ENCODING",function(l){return"Unknown encoding: "+l},TypeError),r("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event"),Jr.codes=e,Jr}var zr,Zn;function ei(){if(Zn)return zr;Zn=1;var t=Pt().codes.ERR_INVALID_OPT_VALUE;function e(n,s,i){return n.highWaterMark!=null?n.highWaterMark:s?n[i]:null}function r(n,s,i,c){var l=e(s,c,i);if(l!=null){if(!(isFinite(l)&&Math.floor(l)===l)||l<0){var h=c?i:"highWaterMark";throw new t(h,l)}return Math.floor(l)}return n.objectMode?16:16*1024}return zr={getHighWaterMark:r},zr}var Vr,ti;function Vs(){if(ti)return Vr;ti=1,Vr=t;function t(r,n){if(e("noDeprecation"))return r;var s=!1;function i(){if(!s){if(e("throwDeprecation"))throw new Error(n);e("traceDeprecation")?console.trace(n):console.warn(n),s=!0}return r.apply(this,arguments)}return i}function e(r){try{if(!Ze.localStorage)return!1}catch{return!1}var n=Ze.localStorage[r];return n==null?!1:String(n).toLowerCase()==="true"}return Vr}var Yr,ri;function ni(){if(ri)return Yr;ri=1,Yr=U;function t(P){var L=this;this.next=null,this.entry=null,this.finish=function(){Be(L,P)}}var e;U.WritableState=M;var r={deprecate:Vs()},n=Gn(),s=gr().Buffer,i=(typeof Ze<"u"?Ze:typeof window<"u"?window:typeof self<"u"?self:{}).Uint8Array||function(){};function c(P){return s.from(P)}function l(P){return s.isBuffer(P)||P instanceof i}var h=Qn(),w=ei(),d=w.getHighWaterMark,I=Pt().codes,v=I.ERR_INVALID_ARG_TYPE,N=I.ERR_METHOD_NOT_IMPLEMENTED,F=I.ERR_MULTIPLE_CALLBACK,$=I.ERR_STREAM_CANNOT_PIPE,j=I.ERR_STREAM_DESTROYED,_=I.ERR_STREAM_NULL_VALUES,A=I.ERR_STREAM_WRITE_AFTER_END,R=I.ERR_UNKNOWN_ENCODING,S=h.errorOrDestroy;Lt()(U,n);function T(){}function M(P,L,G){e=e||Dt(),P=P||{},typeof G!="boolean"&&(G=L instanceof e),this.objectMode=!!P.objectMode,G&&(this.objectMode=this.objectMode||!!P.writableObjectMode),this.highWaterMark=d(this,P,"writableHighWaterMark",G),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var X=P.decodeStrings===!1;this.decodeStrings=!X,this.defaultEncoding=P.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(re){Re(L,re)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=P.emitClose!==!1,this.autoDestroy=!!P.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new t(this)}M.prototype.getBuffer=function(){for(var L=this.bufferedRequest,G=[];L;)G.push(L),L=L.next;return G},(function(){try{Object.defineProperty(M.prototype,"buffer",{get:r.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch{}})();var C;typeof Symbol=="function"&&Symbol.hasInstance&&typeof Function.prototype[Symbol.hasInstance]=="function"?(C=Function.prototype[Symbol.hasInstance],Object.defineProperty(U,Symbol.hasInstance,{value:function(L){return C.call(this,L)?!0:this!==U?!1:L&&L._writableState instanceof M}})):C=function(L){return L instanceof this};function U(P){e=e||Dt();var L=this instanceof e;if(!L&&!C.call(U,this))return new U(P);this._writableState=new M(P,this,L),this.writable=!0,P&&(typeof P.write=="function"&&(this._write=P.write),typeof P.writev=="function"&&(this._writev=P.writev),typeof P.destroy=="function"&&(this._destroy=P.destroy),typeof P.final=="function"&&(this._final=P.final)),n.call(this)}U.prototype.pipe=function(){S(this,new $)};function W(P,L){var G=new A;S(P,G),he.nextTick(L,G)}function J(P,L,G,X){var re;return G===null?re=new _:typeof G!="string"&&!L.objectMode&&(re=new v("chunk",["string","Buffer"],G)),re?(S(P,re),he.nextTick(X,re),!1):!0}U.prototype.write=function(P,L,G){var X=this._writableState,re=!1,b=!X.objectMode&&l(P);return b&&!s.isBuffer(P)&&(P=c(P)),typeof L=="function"&&(G=L,L=null),b?L="buffer":L||(L=X.defaultEncoding),typeof G!="function"&&(G=T),X.ending?W(this,G):(b||J(this,X,P,G))&&(X.pendingcb++,re=k(this,X,b,P,L,G)),re},U.prototype.cork=function(){this._writableState.corked++},U.prototype.uncork=function(){var P=this._writableState;P.corked&&(P.corked--,!P.writing&&!P.corked&&!P.bufferProcessing&&P.bufferedRequest&&He(this,P))},U.prototype.setDefaultEncoding=function(L){if(typeof L=="string"&&(L=L.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((L+"").toLowerCase())>-1))throw new R(L);return this._writableState.defaultEncoding=L,this},Object.defineProperty(U.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}});function Q(P,L,G){return!P.objectMode&&P.decodeStrings!==!1&&typeof L=="string"&&(L=s.from(L,G)),L}Object.defineProperty(U.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}});function k(P,L,G,X,re,b){if(!G){var E=Q(L,X,re);X!==E&&(G=!0,re="buffer",X=E)}var H=L.objectMode?1:X.length;L.length+=H;var V=L.length<L.highWaterMark;if(V||(L.needDrain=!0),L.writing||L.corked){var le=L.lastBufferedRequest;L.lastBufferedRequest={chunk:X,encoding:re,isBuf:G,callback:b,next:null},le?le.next=L.lastBufferedRequest:L.bufferedRequest=L.lastBufferedRequest,L.bufferedRequestCount+=1}else Y(P,L,!1,H,X,re,b);return V}function Y(P,L,G,X,re,b,E){L.writelen=X,L.writecb=E,L.writing=!0,L.sync=!0,L.destroyed?L.onwrite(new j("write")):G?P._writev(re,L.onwrite):P._write(re,b,L.onwrite),L.sync=!1}function se(P,L,G,X,re){--L.pendingcb,G?(he.nextTick(re,X),he.nextTick(Ye,P,L),P._writableState.errorEmitted=!0,S(P,X)):(re(X),P._writableState.errorEmitted=!0,S(P,X),Ye(P,L))}function fe(P){P.writing=!1,P.writecb=null,P.length-=P.writelen,P.writelen=0}function Re(P,L){var G=P._writableState,X=G.sync,re=G.writecb;if(typeof re!="function")throw new F;if(fe(G),L)se(P,G,X,L,re);else{var b=at(G)||P.destroyed;!b&&!G.corked&&!G.bufferProcessing&&G.bufferedRequest&&He(P,G),X?he.nextTick(Te,P,G,b,re):Te(P,G,b,re)}}function Te(P,L,G,X){G||Ce(P,L),L.pendingcb--,X(),Ye(P,L)}function Ce(P,L){L.length===0&&L.needDrain&&(L.needDrain=!1,P.emit("drain"))}function He(P,L){L.bufferProcessing=!0;var G=L.bufferedRequest;if(P._writev&&G&&G.next){var X=L.bufferedRequestCount,re=new Array(X),b=L.corkedRequestsFree;b.entry=G;for(var E=0,H=!0;G;)re[E]=G,G.isBuf||(H=!1),G=G.next,E+=1;re.allBuffers=H,Y(P,L,!0,L.length,re,"",b.finish),L.pendingcb++,L.lastBufferedRequest=null,b.next?(L.corkedRequestsFree=b.next,b.next=null):L.corkedRequestsFree=new t(L),L.bufferedRequestCount=0}else{for(;G;){var V=G.chunk,le=G.encoding,Z=G.callback,ae=L.objectMode?1:V.length;if(Y(P,L,!1,ae,V,le,Z),G=G.next,L.bufferedRequestCount--,L.writing)break}G===null&&(L.lastBufferedRequest=null)}L.bufferedRequest=G,L.bufferProcessing=!1}U.prototype._write=function(P,L,G){G(new N("_write()"))},U.prototype._writev=null,U.prototype.end=function(P,L,G){var X=this._writableState;return typeof P=="function"?(G=P,P=null,L=null):typeof L=="function"&&(G=L,L=null),P!=null&&this.write(P,L),X.corked&&(X.corked=1,this.uncork()),X.ending||we(this,X,G),this},Object.defineProperty(U.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function at(P){return P.ending&&P.length===0&&P.bufferedRequest===null&&!P.finished&&!P.writing}function Ut(P,L){P._final(function(G){L.pendingcb--,G&&S(P,G),L.prefinished=!0,P.emit("prefinish"),Ye(P,L)})}function ct(P,L){!L.prefinished&&!L.finalCalled&&(typeof P._final=="function"&&!L.destroyed?(L.pendingcb++,L.finalCalled=!0,he.nextTick(Ut,P,L)):(L.prefinished=!0,P.emit("prefinish")))}function Ye(P,L){var G=at(L);if(G&&(ct(P,L),L.pendingcb===0&&(L.finished=!0,P.emit("finish"),L.autoDestroy))){var X=P._readableState;(!X||X.autoDestroy&&X.endEmitted)&&P.destroy()}return G}function we(P,L,G){L.ending=!0,Ye(P,L),G&&(L.finished?he.nextTick(G):P.once("finish",G)),L.ended=!0,P.writable=!1}function Be(P,L,G){var X=P.entry;for(P.entry=null;X;){var re=X.callback;L.pendingcb--,re(G),X=X.next}L.corkedRequestsFree.next=P}return Object.defineProperty(U.prototype,"destroyed",{enumerable:!1,get:function(){return this._writableState===void 0?!1:this._writableState.destroyed},set:function(L){this._writableState&&(this._writableState.destroyed=L)}}),U.prototype.destroy=h.destroy,U.prototype._undestroy=h.undestroy,U.prototype._destroy=function(P,L){L(P)},Yr}var Qr,ii;function Dt(){if(ii)return Qr;ii=1;var t=Object.keys||function(w){var d=[];for(var I in w)d.push(I);return d};Qr=c;var e=hi(),r=ni();Lt()(c,e);for(var n=t(r.prototype),s=0;s<n.length;s++){var i=n[s];c.prototype[i]||(c.prototype[i]=r.prototype[i])}function c(w){if(!(this instanceof c))return new c(w);e.call(this,w),r.call(this,w),this.allowHalfOpen=!0,w&&(w.readable===!1&&(this.readable=!1),w.writable===!1&&(this.writable=!1),w.allowHalfOpen===!1&&(this.allowHalfOpen=!1,this.once("end",l)))}Object.defineProperty(c.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Object.defineProperty(c.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(c.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function l(){this._writableState.ended||he.nextTick(h,this)}function h(w){w.end()}return Object.defineProperty(c.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState===void 0||this._writableState===void 0?!1:this._readableState.destroyed&&this._writableState.destroyed},set:function(d){this._readableState===void 0||this._writableState===void 0||(this._readableState.destroyed=d,this._writableState.destroyed=d)}}),Qr}var Xr={},mr={exports:{}};var si;function Ys(){return si||(si=1,(function(t,e){var r=gr(),n=r.Buffer;function s(c,l){for(var h in c)l[h]=c[h]}n.from&&n.alloc&&n.allocUnsafe&&n.allocUnsafeSlow?t.exports=r:(s(r,e),e.Buffer=i);function i(c,l,h){return n(c,l,h)}i.prototype=Object.create(n.prototype),s(n,i),i.from=function(c,l,h){if(typeof c=="number")throw new TypeError("Argument must not be a number");return n(c,l,h)},i.alloc=function(c,l,h){if(typeof c!="number")throw new TypeError("Argument must be a number");var w=n(c);return l!==void 0?typeof h=="string"?w.fill(l,h):w.fill(l):w.fill(0),w},i.allocUnsafe=function(c){if(typeof c!="number")throw new TypeError("Argument must be a number");return n(c)},i.allocUnsafeSlow=function(c){if(typeof c!="number")throw new TypeError("Argument must be a number");return r.SlowBuffer(c)}})(mr,mr.exports)),mr.exports}var oi;function ai(){if(oi)return Xr;oi=1;var t=Ys().Buffer,e=t.isEncoding||function(_){switch(_=""+_,_&&_.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};function r(_){if(!_)return"utf8";for(var A;;)switch(_){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return _;default:if(A)return;_=(""+_).toLowerCase(),A=!0}}function n(_){var A=r(_);if(typeof A!="string"&&(t.isEncoding===e||!e(_)))throw new Error("Unknown encoding: "+_);return A||_}Xr.StringDecoder=s;function s(_){this.encoding=n(_);var A;switch(this.encoding){case"utf16le":this.text=I,this.end=v,A=4;break;case"utf8":this.fillLast=h,A=4;break;case"base64":this.text=N,this.end=F,A=3;break;default:this.write=$,this.end=j;return}this.lastNeed=0,this.lastTotal=0,this.lastChar=t.allocUnsafe(A)}s.prototype.write=function(_){if(_.length===0)return"";var A,R;if(this.lastNeed){if(A=this.fillLast(_),A===void 0)return"";R=this.lastNeed,this.lastNeed=0}else R=0;return R<_.length?A?A+this.text(_,R):this.text(_,R):A||""},s.prototype.end=d,s.prototype.text=w,s.prototype.fillLast=function(_){if(this.lastNeed<=_.length)return _.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);_.copy(this.lastChar,this.lastTotal-this.lastNeed,0,_.length),this.lastNeed-=_.length};function i(_){return _<=127?0:_>>5===6?2:_>>4===14?3:_>>3===30?4:_>>6===2?-1:-2}function c(_,A,R){var S=A.length-1;if(S<R)return 0;var T=i(A[S]);return T>=0?(T>0&&(_.lastNeed=T-1),T):--S<R||T===-2?0:(T=i(A[S]),T>=0?(T>0&&(_.lastNeed=T-2),T):--S<R||T===-2?0:(T=i(A[S]),T>=0?(T>0&&(T===2?T=0:_.lastNeed=T-3),T):0))}function l(_,A,R){if((A[0]&192)!==128)return _.lastNeed=0,"�";if(_.lastNeed>1&&A.length>1){if((A[1]&192)!==128)return _.lastNeed=1,"�";if(_.lastNeed>2&&A.length>2&&(A[2]&192)!==128)return _.lastNeed=2,"�"}}function h(_){var A=this.lastTotal-this.lastNeed,R=l(this,_);if(R!==void 0)return R;if(this.lastNeed<=_.length)return _.copy(this.lastChar,A,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);_.copy(this.lastChar,A,0,_.length),this.lastNeed-=_.length}function w(_,A){var R=c(this,_,A);if(!this.lastNeed)return _.toString("utf8",A);this.lastTotal=R;var S=_.length-(R-this.lastNeed);return _.copy(this.lastChar,0,S),_.toString("utf8",A,S)}function d(_){var A=_&&_.length?this.write(_):"";return this.lastNeed?A+"�":A}function I(_,A){if((_.length-A)%2===0){var R=_.toString("utf16le",A);if(R){var S=R.charCodeAt(R.length-1);if(S>=55296&&S<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=_[_.length-2],this.lastChar[1]=_[_.length-1],R.slice(0,-1)}return R}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=_[_.length-1],_.toString("utf16le",A,_.length-1)}function v(_){var A=_&&_.length?this.write(_):"";if(this.lastNeed){var R=this.lastTotal-this.lastNeed;return A+this.lastChar.toString("utf16le",0,R)}return A}function N(_,A){var R=(_.length-A)%3;return R===0?_.toString("base64",A):(this.lastNeed=3-R,this.lastTotal=3,R===1?this.lastChar[0]=_[_.length-1]:(this.lastChar[0]=_[_.length-2],this.lastChar[1]=_[_.length-1]),_.toString("base64",A,_.length-R))}function F(_){var A=_&&_.length?this.write(_):"";return this.lastNeed?A+this.lastChar.toString("base64",0,3-this.lastNeed):A}function $(_){return _.toString(this.encoding)}function j(_){return _&&_.length?this.write(_):""}return Xr}var Zr,ci;function en(){if(ci)return Zr;ci=1;var t=Pt().codes.ERR_STREAM_PREMATURE_CLOSE;function e(i){var c=!1;return function(){if(!c){c=!0;for(var l=arguments.length,h=new Array(l),w=0;w<l;w++)h[w]=arguments[w];i.apply(this,h)}}}function r(){}function n(i){return i.setHeader&&typeof i.abort=="function"}function s(i,c,l){if(typeof c=="function")return s(i,null,c);c||(c={}),l=e(l||r);var h=c.readable||c.readable!==!1&&i.readable,w=c.writable||c.writable!==!1&&i.writable,d=function(){i.writable||v()},I=i._writableState&&i._writableState.finished,v=function(){w=!1,I=!0,h||l.call(i)},N=i._readableState&&i._readableState.endEmitted,F=function(){h=!1,N=!0,w||l.call(i)},$=function(R){l.call(i,R)},j=function(){var R;if(h&&!N)return(!i._readableState||!i._readableState.ended)&&(R=new t),l.call(i,R);if(w&&!I)return(!i._writableState||!i._writableState.ended)&&(R=new t),l.call(i,R)},_=function(){i.req.on("finish",v)};return n(i)?(i.on("complete",v),i.on("abort",j),i.req?_():i.on("request",_)):w&&!i._writableState&&(i.on("end",d),i.on("close",d)),i.on("end",F),i.on("finish",v),c.error!==!1&&i.on("error",$),i.on("close",j),function(){i.removeListener("complete",v),i.removeListener("abort",j),i.removeListener("request",_),i.req&&i.req.removeListener("finish",v),i.removeListener("end",d),i.removeListener("close",d),i.removeListener("finish",v),i.removeListener("end",F),i.removeListener("error",$),i.removeListener("close",j)}}return Zr=s,Zr}var tn,ui;function Qs(){if(ui)return tn;ui=1;var t;function e(R,S,T){return S=r(S),S in R?Object.defineProperty(R,S,{value:T,enumerable:!0,configurable:!0,writable:!0}):R[S]=T,R}function r(R){var S=n(R,"string");return typeof S=="symbol"?S:String(S)}function n(R,S){if(typeof R!="object"||R===null)return R;var T=R[Symbol.toPrimitive];if(T!==void 0){var M=T.call(R,S);if(typeof M!="object")return M;throw new TypeError("@@toPrimitive must return a primitive value.")}return(S==="string"?String:Number)(R)}var s=en(),i=Symbol("lastResolve"),c=Symbol("lastReject"),l=Symbol("error"),h=Symbol("ended"),w=Symbol("lastPromise"),d=Symbol("handlePromise"),I=Symbol("stream");function v(R,S){return{value:R,done:S}}function N(R){var S=R[i];if(S!==null){var T=R[I].read();T!==null&&(R[w]=null,R[i]=null,R[c]=null,S(v(T,!1)))}}function F(R){he.nextTick(N,R)}function $(R,S){return function(T,M){R.then(function(){if(S[h]){T(v(void 0,!0));return}S[d](T,M)},M)}}var j=Object.getPrototypeOf(function(){}),_=Object.setPrototypeOf((t={get stream(){return this[I]},next:function(){var S=this,T=this[l];if(T!==null)return Promise.reject(T);if(this[h])return Promise.resolve(v(void 0,!0));if(this[I].destroyed)return new Promise(function(W,J){he.nextTick(function(){S[l]?J(S[l]):W(v(void 0,!0))})});var M=this[w],C;if(M)C=new Promise($(M,this));else{var U=this[I].read();if(U!==null)return Promise.resolve(v(U,!1));C=new Promise(this[d])}return this[w]=C,C}},e(t,Symbol.asyncIterator,function(){return this}),e(t,"return",function(){var S=this;return new Promise(function(T,M){S[I].destroy(null,function(C){if(C){M(C);return}T(v(void 0,!0))})})}),t),j),A=function(S){var T,M=Object.create(_,(T={},e(T,I,{value:S,writable:!0}),e(T,i,{value:null,writable:!0}),e(T,c,{value:null,writable:!0}),e(T,l,{value:null,writable:!0}),e(T,h,{value:S._readableState.endEmitted,writable:!0}),e(T,d,{value:function(U,W){var J=M[I].read();J?(M[w]=null,M[i]=null,M[c]=null,U(v(J,!1))):(M[i]=U,M[c]=W)},writable:!0}),T));return M[w]=null,s(S,function(C){if(C&&C.code!=="ERR_STREAM_PREMATURE_CLOSE"){var U=M[c];U!==null&&(M[w]=null,M[i]=null,M[c]=null,U(C)),M[l]=C;return}var W=M[i];W!==null&&(M[w]=null,M[i]=null,M[c]=null,W(v(void 0,!0))),M[h]=!0}),S.on("readable",F.bind(null,M)),M};return tn=A,tn}var rn,fi;function Xs(){return fi||(fi=1,rn=function(){throw new Error("Readable.from is not available in the browser")}),rn}var nn,li;function hi(){if(li)return nn;li=1,nn=W;var t;W.ReadableState=U,pr().EventEmitter;var e=function(E,H){return E.listeners(H).length},r=Gn(),n=gr().Buffer,s=(typeof Ze<"u"?Ze:typeof window<"u"?window:typeof self<"u"?self:{}).Uint8Array||function(){};function i(b){return n.from(b)}function c(b){return n.isBuffer(b)||b instanceof s}var l=zn,h;l&&l.debuglog?h=l.debuglog("stream"):h=function(){};var w=zs(),d=Qn(),I=ei(),v=I.getHighWaterMark,N=Pt().codes,F=N.ERR_INVALID_ARG_TYPE,$=N.ERR_STREAM_PUSH_AFTER_EOF,j=N.ERR_METHOD_NOT_IMPLEMENTED,_=N.ERR_STREAM_UNSHIFT_AFTER_END_EVENT,A,R,S;Lt()(W,r);var T=d.errorOrDestroy,M=["error","close","destroy","pause","resume"];function C(b,E,H){if(typeof b.prependListener=="function")return b.prependListener(E,H);!b._events||!b._events[E]?b.on(E,H):Array.isArray(b._events[E])?b._events[E].unshift(H):b._events[E]=[H,b._events[E]]}function U(b,E,H){t=t||Dt(),b=b||{},typeof H!="boolean"&&(H=E instanceof t),this.objectMode=!!b.objectMode,H&&(this.objectMode=this.objectMode||!!b.readableObjectMode),this.highWaterMark=v(this,b,"readableHighWaterMark",H),this.buffer=new w,this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.resumeScheduled=!1,this.paused=!0,this.emitClose=b.emitClose!==!1,this.autoDestroy=!!b.autoDestroy,this.destroyed=!1,this.defaultEncoding=b.defaultEncoding||"utf8",this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,b.encoding&&(A||(A=ai().StringDecoder),this.decoder=new A(b.encoding),this.encoding=b.encoding)}function W(b){if(t=t||Dt(),!(this instanceof W))return new W(b);var E=this instanceof t;this._readableState=new U(b,this,E),this.readable=!0,b&&(typeof b.read=="function"&&(this._read=b.read),typeof b.destroy=="function"&&(this._destroy=b.destroy)),r.call(this)}Object.defineProperty(W.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState===void 0?!1:this._readableState.destroyed},set:function(E){this._readableState&&(this._readableState.destroyed=E)}}),W.prototype.destroy=d.destroy,W.prototype._undestroy=d.undestroy,W.prototype._destroy=function(b,E){E(b)},W.prototype.push=function(b,E){var H=this._readableState,V;return H.objectMode?V=!0:typeof b=="string"&&(E=E||H.defaultEncoding,E!==H.encoding&&(b=n.from(b,E),E=""),V=!0),J(this,b,E,!1,V)},W.prototype.unshift=function(b){return J(this,b,null,!0,!1)};function J(b,E,H,V,le){h("readableAddChunk",E);var Z=b._readableState;if(E===null)Z.reading=!1,Re(b,Z);else{var ae;if(le||(ae=k(Z,E)),ae)T(b,ae);else if(Z.objectMode||E&&E.length>0)if(typeof E!="string"&&!Z.objectMode&&Object.getPrototypeOf(E)!==n.prototype&&(E=i(E)),V)Z.endEmitted?T(b,new _):Q(b,Z,E,!0);else if(Z.ended)T(b,new $);else{if(Z.destroyed)return!1;Z.reading=!1,Z.decoder&&!H?(E=Z.decoder.write(E),Z.objectMode||E.length!==0?Q(b,Z,E,!1):He(b,Z)):Q(b,Z,E,!1)}else V||(Z.reading=!1,He(b,Z))}return!Z.ended&&(Z.length<Z.highWaterMark||Z.length===0)}function Q(b,E,H,V){E.flowing&&E.length===0&&!E.sync?(E.awaitDrain=0,b.emit("data",H)):(E.length+=E.objectMode?1:H.length,V?E.buffer.unshift(H):E.buffer.push(H),E.needReadable&&Te(b)),He(b,E)}function k(b,E){var H;return!c(E)&&typeof E!="string"&&E!==void 0&&!b.objectMode&&(H=new F("chunk",["string","Buffer","Uint8Array"],E)),H}W.prototype.isPaused=function(){return this._readableState.flowing===!1},W.prototype.setEncoding=function(b){A||(A=ai().StringDecoder);var E=new A(b);this._readableState.decoder=E,this._readableState.encoding=this._readableState.decoder.encoding;for(var H=this._readableState.buffer.head,V="";H!==null;)V+=E.write(H.data),H=H.next;return this._readableState.buffer.clear(),V!==""&&this._readableState.buffer.push(V),this._readableState.length=V.length,this};var Y=1073741824;function se(b){return b>=Y?b=Y:(b--,b|=b>>>1,b|=b>>>2,b|=b>>>4,b|=b>>>8,b|=b>>>16,b++),b}function fe(b,E){return b<=0||E.length===0&&E.ended?0:E.objectMode?1:b!==b?E.flowing&&E.length?E.buffer.head.data.length:E.length:(b>E.highWaterMark&&(E.highWaterMark=se(b)),b<=E.length?b:E.ended?E.length:(E.needReadable=!0,0))}W.prototype.read=function(b){h("read",b),b=parseInt(b,10);var E=this._readableState,H=b;if(b!==0&&(E.emittedReadable=!1),b===0&&E.needReadable&&((E.highWaterMark!==0?E.length>=E.highWaterMark:E.length>0)||E.ended))return h("read: emitReadable",E.length,E.ended),E.length===0&&E.ended?G(this):Te(this),null;if(b=fe(b,E),b===0&&E.ended)return E.length===0&&G(this),null;var V=E.needReadable;h("need readable",V),(E.length===0||E.length-b<E.highWaterMark)&&(V=!0,h("length less than watermark",V)),E.ended||E.reading?(V=!1,h("reading or ended",V)):V&&(h("do read"),E.reading=!0,E.sync=!0,E.length===0&&(E.needReadable=!0),this._read(E.highWaterMark),E.sync=!1,E.reading||(b=fe(H,E)));var le;return b>0?le=L(b,E):le=null,le===null?(E.needReadable=E.length<=E.highWaterMark,b=0):(E.length-=b,E.awaitDrain=0),E.length===0&&(E.ended||(E.needReadable=!0),H!==b&&E.ended&&G(this)),le!==null&&this.emit("data",le),le};function Re(b,E){if(h("onEofChunk"),!E.ended){if(E.decoder){var H=E.decoder.end();H&&H.length&&(E.buffer.push(H),E.length+=E.objectMode?1:H.length)}E.ended=!0,E.sync?Te(b):(E.needReadable=!1,E.emittedReadable||(E.emittedReadable=!0,Ce(b)))}}function Te(b){var E=b._readableState;h("emitReadable",E.needReadable,E.emittedReadable),E.needReadable=!1,E.emittedReadable||(h("emitReadable",E.flowing),E.emittedReadable=!0,he.nextTick(Ce,b))}function Ce(b){var E=b._readableState;h("emitReadable_",E.destroyed,E.length,E.ended),!E.destroyed&&(E.length||E.ended)&&(b.emit("readable"),E.emittedReadable=!1),E.needReadable=!E.flowing&&!E.ended&&E.length<=E.highWaterMark,P(b)}function He(b,E){E.readingMore||(E.readingMore=!0,he.nextTick(at,b,E))}function at(b,E){for(;!E.reading&&!E.ended&&(E.length<E.highWaterMark||E.flowing&&E.length===0);){var H=E.length;if(h("maybeReadMore read 0"),b.read(0),H===E.length)break}E.readingMore=!1}W.prototype._read=function(b){T(this,new j("_read()"))},W.prototype.pipe=function(b,E){var H=this,V=this._readableState;switch(V.pipesCount){case 0:V.pipes=b;break;case 1:V.pipes=[V.pipes,b];break;default:V.pipes.push(b);break}V.pipesCount+=1,h("pipe count=%d opts=%j",V.pipesCount,E);var le=(!E||E.end!==!1)&&b!==he.stdout&&b!==he.stderr,Z=le?ut:Ge;V.endEmitted?he.nextTick(Z):H.once("end",Z),b.on("unpipe",ae);function ae(Xe,Ne){h("onunpipe"),Xe===H&&Ne&&Ne.hasUnpiped===!1&&(Ne.hasUnpiped=!0,hr())}function ut(){h("onend"),b.end()}var Tt=Ut(H);b.on("drain",Tt);var vt=!1;function hr(){h("cleanup"),b.removeListener("close",Qe),b.removeListener("finish",Me),b.removeListener("drain",Tt),b.removeListener("error",Ie),b.removeListener("unpipe",ae),H.removeListener("end",ut),H.removeListener("end",Ge),H.removeListener("data",Ee),vt=!0,V.awaitDrain&&(!b._writableState||b._writableState.needDrain)&&Tt()}H.on("data",Ee);function Ee(Xe){h("ondata");var Ne=b.write(Xe);h("dest.write",Ne),Ne===!1&&((V.pipesCount===1&&V.pipes===b||V.pipesCount>1&&re(V.pipes,b)!==-1)&&!vt&&(h("false write response, pause",V.awaitDrain),V.awaitDrain++),H.pause())}function Ie(Xe){h("onerror",Xe),Ge(),b.removeListener("error",Ie),e(b,"error")===0&&T(b,Xe)}C(b,"error",Ie);function Qe(){b.removeListener("finish",Me),Ge()}b.once("close",Qe);function Me(){h("onfinish"),b.removeListener("close",Qe),Ge()}b.once("finish",Me);function Ge(){h("unpipe"),H.unpipe(b)}return b.emit("pipe",H),V.flowing||(h("pipe resume"),H.resume()),b};function Ut(b){return function(){var H=b._readableState;h("pipeOnDrain",H.awaitDrain),H.awaitDrain&&H.awaitDrain--,H.awaitDrain===0&&e(b,"data")&&(H.flowing=!0,P(b))}}W.prototype.unpipe=function(b){var E=this._readableState,H={hasUnpiped:!1};if(E.pipesCount===0)return this;if(E.pipesCount===1)return b&&b!==E.pipes?this:(b||(b=E.pipes),E.pipes=null,E.pipesCount=0,E.flowing=!1,b&&b.emit("unpipe",this,H),this);if(!b){var V=E.pipes,le=E.pipesCount;E.pipes=null,E.pipesCount=0,E.flowing=!1;for(var Z=0;Z<le;Z++)V[Z].emit("unpipe",this,{hasUnpiped:!1});return this}var ae=re(E.pipes,b);return ae===-1?this:(E.pipes.splice(ae,1),E.pipesCount-=1,E.pipesCount===1&&(E.pipes=E.pipes[0]),b.emit("unpipe",this,H),this)},W.prototype.on=function(b,E){var H=r.prototype.on.call(this,b,E),V=this._readableState;return b==="data"?(V.readableListening=this.listenerCount("readable")>0,V.flowing!==!1&&this.resume()):b==="readable"&&!V.endEmitted&&!V.readableListening&&(V.readableListening=V.needReadable=!0,V.flowing=!1,V.emittedReadable=!1,h("on readable",V.length,V.reading),V.length?Te(this):V.reading||he.nextTick(Ye,this)),H},W.prototype.addListener=W.prototype.on,W.prototype.removeListener=function(b,E){var H=r.prototype.removeListener.call(this,b,E);return b==="readable"&&he.nextTick(ct,this),H},W.prototype.removeAllListeners=function(b){var E=r.prototype.removeAllListeners.apply(this,arguments);return(b==="readable"||b===void 0)&&he.nextTick(ct,this),E};function ct(b){var E=b._readableState;E.readableListening=b.listenerCount("readable")>0,E.resumeScheduled&&!E.paused?E.flowing=!0:b.listenerCount("data")>0&&b.resume()}function Ye(b){h("readable nexttick read 0"),b.read(0)}W.prototype.resume=function(){var b=this._readableState;return b.flowing||(h("resume"),b.flowing=!b.readableListening,we(this,b)),b.paused=!1,this};function we(b,E){E.resumeScheduled||(E.resumeScheduled=!0,he.nextTick(Be,b,E))}function Be(b,E){h("resume",E.reading),E.reading||b.read(0),E.resumeScheduled=!1,b.emit("resume"),P(b),E.flowing&&!E.reading&&b.read(0)}W.prototype.pause=function(){return h("call pause flowing=%j",this._readableState.flowing),this._readableState.flowing!==!1&&(h("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this};function P(b){var E=b._readableState;for(h("flow",E.flowing);E.flowing&&b.read()!==null;);}W.prototype.wrap=function(b){var E=this,H=this._readableState,V=!1;b.on("end",function(){if(h("wrapped end"),H.decoder&&!H.ended){var ae=H.decoder.end();ae&&ae.length&&E.push(ae)}E.push(null)}),b.on("data",function(ae){if(h("wrapped data"),H.decoder&&(ae=H.decoder.write(ae)),!(H.objectMode&&ae==null)&&!(!H.objectMode&&(!ae||!ae.length))){var ut=E.push(ae);ut||(V=!0,b.pause())}});for(var le in b)this[le]===void 0&&typeof b[le]=="function"&&(this[le]=(function(ut){return function(){return b[ut].apply(b,arguments)}})(le));for(var Z=0;Z<M.length;Z++)b.on(M[Z],this.emit.bind(this,M[Z]));return this._read=function(ae){h("wrapped _read",ae),V&&(V=!1,b.resume())},this},typeof Symbol=="function"&&(W.prototype[Symbol.asyncIterator]=function(){return R===void 0&&(R=Qs()),R(this)}),Object.defineProperty(W.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty(W.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty(W.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(E){this._readableState&&(this._readableState.flowing=E)}}),W._fromList=L,Object.defineProperty(W.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}});function L(b,E){if(E.length===0)return null;var H;return E.objectMode?H=E.buffer.shift():!b||b>=E.length?(E.decoder?H=E.buffer.join(""):E.buffer.length===1?H=E.buffer.first():H=E.buffer.concat(E.length),E.buffer.clear()):H=E.buffer.consume(b,E.decoder),H}function G(b){var E=b._readableState;h("endReadable",E.endEmitted),E.endEmitted||(E.ended=!0,he.nextTick(X,E,b))}function X(b,E){if(h("endReadableNT",b.endEmitted,b.length),!b.endEmitted&&b.length===0&&(b.endEmitted=!0,E.readable=!1,E.emit("end"),b.autoDestroy)){var H=E._writableState;(!H||H.autoDestroy&&H.finished)&&E.destroy()}}typeof Symbol=="function"&&(W.from=function(b,E){return S===void 0&&(S=Xs()),S(W,b,E)});function re(b,E){for(var H=0,V=b.length;H<V;H++)if(b[H]===E)return H;return-1}return nn}var sn,di;function pi(){if(di)return sn;di=1,sn=l;var t=Pt().codes,e=t.ERR_METHOD_NOT_IMPLEMENTED,r=t.ERR_MULTIPLE_CALLBACK,n=t.ERR_TRANSFORM_ALREADY_TRANSFORMING,s=t.ERR_TRANSFORM_WITH_LENGTH_0,i=Dt();Lt()(l,i);function c(d,I){var v=this._transformState;v.transforming=!1;var N=v.writecb;if(N===null)return this.emit("error",new r);v.writechunk=null,v.writecb=null,I!=null&&this.push(I),N(d);var F=this._readableState;F.reading=!1,(F.needReadable||F.length<F.highWaterMark)&&this._read(F.highWaterMark)}function l(d){if(!(this instanceof l))return new l(d);i.call(this,d),this._transformState={afterTransform:c.bind(this),needTransform:!1,transforming:!1,writecb:null,writechunk:null,writeencoding:null},this._readableState.needReadable=!0,this._readableState.sync=!1,d&&(typeof d.transform=="function"&&(this._transform=d.transform),typeof d.flush=="function"&&(this._flush=d.flush)),this.on("prefinish",h)}function h(){var d=this;typeof this._flush=="function"&&!this._readableState.destroyed?this._flush(function(I,v){w(d,I,v)}):w(this,null,null)}l.prototype.push=function(d,I){return this._transformState.needTransform=!1,i.prototype.push.call(this,d,I)},l.prototype._transform=function(d,I,v){v(new e("_transform()"))},l.prototype._write=function(d,I,v){var N=this._transformState;if(N.writecb=v,N.writechunk=d,N.writeencoding=I,!N.transforming){var F=this._readableState;(N.needTransform||F.needReadable||F.length<F.highWaterMark)&&this._read(F.highWaterMark)}},l.prototype._read=function(d){var I=this._transformState;I.writechunk!==null&&!I.transforming?(I.transforming=!0,this._transform(I.writechunk,I.writeencoding,I.afterTransform)):I.needTransform=!0},l.prototype._destroy=function(d,I){i.prototype._destroy.call(this,d,function(v){I(v)})};function w(d,I,v){if(I)return d.emit("error",I);if(v!=null&&d.push(v),d._writableState.length)throw new s;if(d._transformState.transforming)throw new n;return d.push(null)}return sn}var on,yi;function Zs(){if(yi)return on;yi=1,on=e;var t=pi();Lt()(e,t);function e(r){if(!(this instanceof e))return new e(r);t.call(this,r)}return e.prototype._transform=function(r,n,s){s(null,r)},on}var an,wi;function eo(){if(wi)return an;wi=1;var t;function e(v){var N=!1;return function(){N||(N=!0,v.apply(void 0,arguments))}}var r=Pt().codes,n=r.ERR_MISSING_ARGS,s=r.ERR_STREAM_DESTROYED;function i(v){if(v)throw v}function c(v){return v.setHeader&&typeof v.abort=="function"}function l(v,N,F,$){$=e($);var j=!1;v.on("close",function(){j=!0}),t===void 0&&(t=en()),t(v,{readable:N,writable:F},function(A){if(A)return $(A);j=!0,$()});var _=!1;return function(A){if(!j&&!_){if(_=!0,c(v))return v.abort();if(typeof v.destroy=="function")return v.destroy();$(A||new s("pipe"))}}}function h(v){v()}function w(v,N){return v.pipe(N)}function d(v){return!v.length||typeof v[v.length-1]!="function"?i:v.pop()}function I(){for(var v=arguments.length,N=new Array(v),F=0;F<v;F++)N[F]=arguments[F];var $=d(N);if(Array.isArray(N[0])&&(N=N[0]),N.length<2)throw new n("streams");var j,_=N.map(function(A,R){var S=R<N.length-1,T=R>0;return l(A,S,T,function(M){j||(j=M),M&&_.forEach(h),!S&&(_.forEach(h),$(j))})});return N.reduce(w)}return an=I,an}var cn,gi;function to(){if(gi)return cn;gi=1,cn=r;var t=pr().EventEmitter,e=Lt();e(r,t),r.Readable=hi(),r.Writable=ni(),r.Duplex=Dt(),r.Transform=pi(),r.PassThrough=Zs(),r.finished=en(),r.pipeline=eo(),r.Stream=r;function r(){t.call(this)}return r.prototype.pipe=function(n,s){var i=this;function c(N){n.writable&&n.write(N)===!1&&i.pause&&i.pause()}i.on("data",c);function l(){i.readable&&i.resume&&i.resume()}n.on("drain",l),!n._isStdio&&(!s||s.end!==!1)&&(i.on("end",w),i.on("close",d));var h=!1;function w(){h||(h=!0,n.end())}function d(){h||(h=!0,typeof n.destroy=="function"&&n.destroy())}function I(N){if(v(),t.listenerCount(this,"error")===0)throw N}i.on("error",I),n.on("error",I);function v(){i.removeListener("data",c),n.removeListener("drain",l),i.removeListener("end",w),i.removeListener("close",d),i.removeListener("error",I),n.removeListener("error",I),i.removeListener("end",v),i.removeListener("close",v),n.removeListener("close",v)}return i.on("end",v),i.on("close",v),n.on("close",v),n.emit("pipe",i),n},cn}var Ot=to();const ro="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Xt=(t=21)=>{let e="",r=crypto.getRandomValues(new Uint8Array(t|=0));for(;t--;)e+=ro[r[t]&63];return e};var un={},br={};br.byteLength=so,br.toByteArray=ao,br.fromByteArray=fo;for(var rt=[],$e=[],no=typeof Uint8Array<"u"?Uint8Array:Array,fn="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",$t=0,io=fn.length;$t<io;++$t)rt[$t]=fn[$t],$e[fn.charCodeAt($t)]=$t;$e[45]=62,$e[95]=63;function mi(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");r===-1&&(r=e);var n=r===e?0:4-r%4;return[r,n]}function so(t){var e=mi(t),r=e[0],n=e[1];return(r+n)*3/4-n}function oo(t,e,r){return(e+r)*3/4-r}function ao(t){var e,r=mi(t),n=r[0],s=r[1],i=new no(oo(t,n,s)),c=0,l=s>0?n-4:n,h;for(h=0;h<l;h+=4)e=$e[t.charCodeAt(h)]<<18|$e[t.charCodeAt(h+1)]<<12|$e[t.charCodeAt(h+2)]<<6|$e[t.charCodeAt(h+3)],i[c++]=e>>16&255,i[c++]=e>>8&255,i[c++]=e&255;return s===2&&(e=$e[t.charCodeAt(h)]<<2|$e[t.charCodeAt(h+1)]>>4,i[c++]=e&255),s===1&&(e=$e[t.charCodeAt(h)]<<10|$e[t.charCodeAt(h+1)]<<4|$e[t.charCodeAt(h+2)]>>2,i[c++]=e>>8&255,i[c++]=e&255),i}function co(t){return rt[t>>18&63]+rt[t>>12&63]+rt[t>>6&63]+rt[t&63]}function uo(t,e,r){for(var n,s=[],i=e;i<r;i+=3)n=(t[i]<<16&16711680)+(t[i+1]<<8&65280)+(t[i+2]&255),s.push(co(n));return s.join("")}function fo(t){for(var e,r=t.length,n=r%3,s=[],i=16383,c=0,l=r-n;c<l;c+=i)s.push(uo(t,c,c+i>l?l:c+i));return n===1?(e=t[r-1],s.push(rt[e>>2]+rt[e<<4&63]+"==")):n===2&&(e=(t[r-2]<<8)+t[r-1],s.push(rt[e>>10]+rt[e>>4&63]+rt[e<<2&63]+"=")),s.join("")}var ln={};ln.read=function(t,e,r,n,s){var i,c,l=s*8-n-1,h=(1<<l)-1,w=h>>1,d=-7,I=r?s-1:0,v=r?-1:1,N=t[e+I];for(I+=v,i=N&(1<<-d)-1,N>>=-d,d+=l;d>0;i=i*256+t[e+I],I+=v,d-=8);for(c=i&(1<<-d)-1,i>>=-d,d+=n;d>0;c=c*256+t[e+I],I+=v,d-=8);if(i===0)i=1-w;else{if(i===h)return c?NaN:(N?-1:1)*(1/0);c=c+Math.pow(2,n),i=i-w}return(N?-1:1)*c*Math.pow(2,i-n)},ln.write=function(t,e,r,n,s,i){var c,l,h,w=i*8-s-1,d=(1<<w)-1,I=d>>1,v=s===23?Math.pow(2,-24)-Math.pow(2,-77):0,N=n?0:i-1,F=n?1:-1,$=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(l=isNaN(e)?1:0,c=d):(c=Math.floor(Math.log(e)/Math.LN2),e*(h=Math.pow(2,-c))<1&&(c--,h*=2),c+I>=1?e+=v/h:e+=v*Math.pow(2,1-I),e*h>=2&&(c++,h/=2),c+I>=d?(l=0,c=d):c+I>=1?(l=(e*h-1)*Math.pow(2,s),c=c+I):(l=e*Math.pow(2,I-1)*Math.pow(2,s),c=0));s>=8;t[r+N]=l&255,N+=F,l/=256,s-=8);for(c=c<<s|l,w+=s;w>0;t[r+N]=c&255,N+=F,c/=256,w-=8);t[r+N-F]|=$*128};(function(t){const e=br,r=ln,n=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;t.Buffer=d,t.SlowBuffer=T,t.INSPECT_MAX_BYTES=50;const s=2147483647;t.kMaxLength=s;const{Uint8Array:i,ArrayBuffer:c,SharedArrayBuffer:l}=globalThis;d.TYPED_ARRAY_SUPPORT=h(),!d.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function h(){try{const p=new i(1),o={foo:function(){return 42}};return Object.setPrototypeOf(o,i.prototype),Object.setPrototypeOf(p,o),p.foo()===42}catch{return!1}}Object.defineProperty(d.prototype,"parent",{enumerable:!0,get:function(){if(d.isBuffer(this))return this.buffer}}),Object.defineProperty(d.prototype,"offset",{enumerable:!0,get:function(){if(d.isBuffer(this))return this.byteOffset}});function w(p){if(p>s)throw new RangeError('The value "'+p+'" is invalid for option "size"');const o=new i(p);return Object.setPrototypeOf(o,d.prototype),o}function d(p,o,u){if(typeof p=="number"){if(typeof o=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return F(p)}return I(p,o,u)}d.poolSize=8192;function I(p,o,u){if(typeof p=="string")return $(p,o);if(c.isView(p))return _(p);if(p==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof p);if(Me(p,c)||p&&Me(p.buffer,c)||typeof l<"u"&&(Me(p,l)||p&&Me(p.buffer,l)))return A(p,o,u);if(typeof p=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const g=p.valueOf&&p.valueOf();if(g!=null&&g!==p)return d.from(g,o,u);const x=R(p);if(x)return x;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof p[Symbol.toPrimitive]=="function")return d.from(p[Symbol.toPrimitive]("string"),o,u);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof p)}d.from=function(p,o,u){return I(p,o,u)},Object.setPrototypeOf(d.prototype,i.prototype),Object.setPrototypeOf(d,i);function v(p){if(typeof p!="number")throw new TypeError('"size" argument must be of type number');if(p<0)throw new RangeError('The value "'+p+'" is invalid for option "size"')}function N(p,o,u){return v(p),p<=0?w(p):o!==void 0?typeof u=="string"?w(p).fill(o,u):w(p).fill(o):w(p)}d.alloc=function(p,o,u){return N(p,o,u)};function F(p){return v(p),w(p<0?0:S(p)|0)}d.allocUnsafe=function(p){return F(p)},d.allocUnsafeSlow=function(p){return F(p)};function $(p,o){if((typeof o!="string"||o==="")&&(o="utf8"),!d.isEncoding(o))throw new TypeError("Unknown encoding: "+o);const u=M(p,o)|0;let g=w(u);const x=g.write(p,o);return x!==u&&(g=g.slice(0,x)),g}function j(p){const o=p.length<0?0:S(p.length)|0,u=w(o);for(let g=0;g<o;g+=1)u[g]=p[g]&255;return u}function _(p){if(Me(p,i)){const o=new i(p);return A(o.buffer,o.byteOffset,o.byteLength)}return j(p)}function A(p,o,u){if(o<0||p.byteLength<o)throw new RangeError('"offset" is outside of buffer bounds');if(p.byteLength<o+(u||0))throw new RangeError('"length" is outside of buffer bounds');let g;return o===void 0&&u===void 0?g=new i(p):u===void 0?g=new i(p,o):g=new i(p,o,u),Object.setPrototypeOf(g,d.prototype),g}function R(p){if(d.isBuffer(p)){const o=S(p.length)|0,u=w(o);return u.length===0||p.copy(u,0,0,o),u}if(p.length!==void 0)return typeof p.length!="number"||Ge(p.length)?w(0):j(p);if(p.type==="Buffer"&&Array.isArray(p.data))return j(p.data)}function S(p){if(p>=s)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+s.toString(16)+" bytes");return p|0}function T(p){return+p!=p&&(p=0),d.alloc(+p)}d.isBuffer=function(o){return o!=null&&o._isBuffer===!0&&o!==d.prototype},d.compare=function(o,u){if(Me(o,i)&&(o=d.from(o,o.offset,o.byteLength)),Me(u,i)&&(u=d.from(u,u.offset,u.byteLength)),!d.isBuffer(o)||!d.isBuffer(u))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(o===u)return 0;let g=o.length,x=u.length;for(let D=0,q=Math.min(g,x);D<q;++D)if(o[D]!==u[D]){g=o[D],x=u[D];break}return g<x?-1:x<g?1:0},d.isEncoding=function(o){switch(String(o).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},d.concat=function(o,u){if(!Array.isArray(o))throw new TypeError('"list" argument must be an Array of Buffers');if(o.length===0)return d.alloc(0);let g;if(u===void 0)for(u=0,g=0;g<o.length;++g)u+=o[g].length;const x=d.allocUnsafe(u);let D=0;for(g=0;g<o.length;++g){let q=o[g];if(Me(q,i))D+q.length>x.length?(d.isBuffer(q)||(q=d.from(q)),q.copy(x,D)):i.prototype.set.call(x,q,D);else if(d.isBuffer(q))q.copy(x,D);else throw new TypeError('"list" argument must be an Array of Buffers');D+=q.length}return x};function M(p,o){if(d.isBuffer(p))return p.length;if(c.isView(p)||Me(p,c))return p.byteLength;if(typeof p!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof p);const u=p.length,g=arguments.length>2&&arguments[2]===!0;if(!g&&u===0)return 0;let x=!1;for(;;)switch(o){case"ascii":case"latin1":case"binary":return u;case"utf8":case"utf-8":return vt(p).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return u*2;case"hex":return u>>>1;case"base64":return Ie(p).length;default:if(x)return g?-1:vt(p).length;o=(""+o).toLowerCase(),x=!0}}d.byteLength=M;function C(p,o,u){let g=!1;if((o===void 0||o<0)&&(o=0),o>this.length||((u===void 0||u>this.length)&&(u=this.length),u<=0)||(u>>>=0,o>>>=0,u<=o))return"";for(p||(p="utf8");;)switch(p){case"hex":return ct(this,o,u);case"utf8":case"utf-8":return Te(this,o,u);case"ascii":return at(this,o,u);case"latin1":case"binary":return Ut(this,o,u);case"base64":return Re(this,o,u);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Ye(this,o,u);default:if(g)throw new TypeError("Unknown encoding: "+p);p=(p+"").toLowerCase(),g=!0}}d.prototype._isBuffer=!0;function U(p,o,u){const g=p[o];p[o]=p[u],p[u]=g}d.prototype.swap16=function(){const o=this.length;if(o%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let u=0;u<o;u+=2)U(this,u,u+1);return this},d.prototype.swap32=function(){const o=this.length;if(o%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let u=0;u<o;u+=4)U(this,u,u+3),U(this,u+1,u+2);return this},d.prototype.swap64=function(){const o=this.length;if(o%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let u=0;u<o;u+=8)U(this,u,u+7),U(this,u+1,u+6),U(this,u+2,u+5),U(this,u+3,u+4);return this},d.prototype.toString=function(){const o=this.length;return o===0?"":arguments.length===0?Te(this,0,o):C.apply(this,arguments)},d.prototype.toLocaleString=d.prototype.toString,d.prototype.equals=function(o){if(!d.isBuffer(o))throw new TypeError("Argument must be a Buffer");return this===o?!0:d.compare(this,o)===0},d.prototype.inspect=function(){let o="";const u=t.INSPECT_MAX_BYTES;return o=this.toString("hex",0,u).replace(/(.{2})/g,"$1 ").trim(),this.length>u&&(o+=" ... "),"<Buffer "+o+">"},n&&(d.prototype[n]=d.prototype.inspect),d.prototype.compare=function(o,u,g,x,D){if(Me(o,i)&&(o=d.from(o,o.offset,o.byteLength)),!d.isBuffer(o))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof o);if(u===void 0&&(u=0),g===void 0&&(g=o?o.length:0),x===void 0&&(x=0),D===void 0&&(D=this.length),u<0||g>o.length||x<0||D>this.length)throw new RangeError("out of range index");if(x>=D&&u>=g)return 0;if(x>=D)return-1;if(u>=g)return 1;if(u>>>=0,g>>>=0,x>>>=0,D>>>=0,this===o)return 0;let q=D-x,ne=g-u;const pe=Math.min(q,ne),ye=this.slice(x,D),ge=o.slice(u,g);for(let ue=0;ue<pe;++ue)if(ye[ue]!==ge[ue]){q=ye[ue],ne=ge[ue];break}return q<ne?-1:ne<q?1:0};function W(p,o,u,g,x){if(p.length===0)return-1;if(typeof u=="string"?(g=u,u=0):u>2147483647?u=2147483647:u<-2147483648&&(u=-2147483648),u=+u,Ge(u)&&(u=x?0:p.length-1),u<0&&(u=p.length+u),u>=p.length){if(x)return-1;u=p.length-1}else if(u<0)if(x)u=0;else return-1;if(typeof o=="string"&&(o=d.from(o,g)),d.isBuffer(o))return o.length===0?-1:J(p,o,u,g,x);if(typeof o=="number")return o=o&255,typeof i.prototype.indexOf=="function"?x?i.prototype.indexOf.call(p,o,u):i.prototype.lastIndexOf.call(p,o,u):J(p,[o],u,g,x);throw new TypeError("val must be string, number or Buffer")}function J(p,o,u,g,x){let D=1,q=p.length,ne=o.length;if(g!==void 0&&(g=String(g).toLowerCase(),g==="ucs2"||g==="ucs-2"||g==="utf16le"||g==="utf-16le")){if(p.length<2||o.length<2)return-1;D=2,q/=2,ne/=2,u/=2}function pe(ge,ue){return D===1?ge[ue]:ge.readUInt16BE(ue*D)}let ye;if(x){let ge=-1;for(ye=u;ye<q;ye++)if(pe(p,ye)===pe(o,ge===-1?0:ye-ge)){if(ge===-1&&(ge=ye),ye-ge+1===ne)return ge*D}else ge!==-1&&(ye-=ye-ge),ge=-1}else for(u+ne>q&&(u=q-ne),ye=u;ye>=0;ye--){let ge=!0;for(let ue=0;ue<ne;ue++)if(pe(p,ye+ue)!==pe(o,ue)){ge=!1;break}if(ge)return ye}return-1}d.prototype.includes=function(o,u,g){return this.indexOf(o,u,g)!==-1},d.prototype.indexOf=function(o,u,g){return W(this,o,u,g,!0)},d.prototype.lastIndexOf=function(o,u,g){return W(this,o,u,g,!1)};function Q(p,o,u,g){u=Number(u)||0;const x=p.length-u;g?(g=Number(g),g>x&&(g=x)):g=x;const D=o.length;g>D/2&&(g=D/2);let q;for(q=0;q<g;++q){const ne=parseInt(o.substr(q*2,2),16);if(Ge(ne))return q;p[u+q]=ne}return q}function k(p,o,u,g){return Qe(vt(o,p.length-u),p,u,g)}function Y(p,o,u,g){return Qe(hr(o),p,u,g)}function se(p,o,u,g){return Qe(Ie(o),p,u,g)}function fe(p,o,u,g){return Qe(Ee(o,p.length-u),p,u,g)}d.prototype.write=function(o,u,g,x){if(u===void 0)x="utf8",g=this.length,u=0;else if(g===void 0&&typeof u=="string")x=u,g=this.length,u=0;else if(isFinite(u))u=u>>>0,isFinite(g)?(g=g>>>0,x===void 0&&(x="utf8")):(x=g,g=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const D=this.length-u;if((g===void 0||g>D)&&(g=D),o.length>0&&(g<0||u<0)||u>this.length)throw new RangeError("Attempt to write outside buffer bounds");x||(x="utf8");let q=!1;for(;;)switch(x){case"hex":return Q(this,o,u,g);case"utf8":case"utf-8":return k(this,o,u,g);case"ascii":case"latin1":case"binary":return Y(this,o,u,g);case"base64":return se(this,o,u,g);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return fe(this,o,u,g);default:if(q)throw new TypeError("Unknown encoding: "+x);x=(""+x).toLowerCase(),q=!0}},d.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function Re(p,o,u){return o===0&&u===p.length?e.fromByteArray(p):e.fromByteArray(p.slice(o,u))}function Te(p,o,u){u=Math.min(p.length,u);const g=[];let x=o;for(;x<u;){const D=p[x];let q=null,ne=D>239?4:D>223?3:D>191?2:1;if(x+ne<=u){let pe,ye,ge,ue;switch(ne){case 1:D<128&&(q=D);break;case 2:pe=p[x+1],(pe&192)===128&&(ue=(D&31)<<6|pe&63,ue>127&&(q=ue));break;case 3:pe=p[x+1],ye=p[x+2],(pe&192)===128&&(ye&192)===128&&(ue=(D&15)<<12|(pe&63)<<6|ye&63,ue>2047&&(ue<55296||ue>57343)&&(q=ue));break;case 4:pe=p[x+1],ye=p[x+2],ge=p[x+3],(pe&192)===128&&(ye&192)===128&&(ge&192)===128&&(ue=(D&15)<<18|(pe&63)<<12|(ye&63)<<6|ge&63,ue>65535&&ue<1114112&&(q=ue))}}q===null?(q=65533,ne=1):q>65535&&(q-=65536,g.push(q>>>10&1023|55296),q=56320|q&1023),g.push(q),x+=ne}return He(g)}const Ce=4096;function He(p){const o=p.length;if(o<=Ce)return String.fromCharCode.apply(String,p);let u="",g=0;for(;g<o;)u+=String.fromCharCode.apply(String,p.slice(g,g+=Ce));return u}function at(p,o,u){let g="";u=Math.min(p.length,u);for(let x=o;x<u;++x)g+=String.fromCharCode(p[x]&127);return g}function Ut(p,o,u){let g="";u=Math.min(p.length,u);for(let x=o;x<u;++x)g+=String.fromCharCode(p[x]);return g}function ct(p,o,u){const g=p.length;(!o||o<0)&&(o=0),(!u||u<0||u>g)&&(u=g);let x="";for(let D=o;D<u;++D)x+=Xe[p[D]];return x}function Ye(p,o,u){const g=p.slice(o,u);let x="";for(let D=0;D<g.length-1;D+=2)x+=String.fromCharCode(g[D]+g[D+1]*256);return x}d.prototype.slice=function(o,u){const g=this.length;o=~~o,u=u===void 0?g:~~u,o<0?(o+=g,o<0&&(o=0)):o>g&&(o=g),u<0?(u+=g,u<0&&(u=0)):u>g&&(u=g),u<o&&(u=o);const x=this.subarray(o,u);return Object.setPrototypeOf(x,d.prototype),x};function we(p,o,u){if(p%1!==0||p<0)throw new RangeError("offset is not uint");if(p+o>u)throw new RangeError("Trying to access beyond buffer length")}d.prototype.readUintLE=d.prototype.readUIntLE=function(o,u,g){o=o>>>0,u=u>>>0,g||we(o,u,this.length);let x=this[o],D=1,q=0;for(;++q<u&&(D*=256);)x+=this[o+q]*D;return x},d.prototype.readUintBE=d.prototype.readUIntBE=function(o,u,g){o=o>>>0,u=u>>>0,g||we(o,u,this.length);let x=this[o+--u],D=1;for(;u>0&&(D*=256);)x+=this[o+--u]*D;return x},d.prototype.readUint8=d.prototype.readUInt8=function(o,u){return o=o>>>0,u||we(o,1,this.length),this[o]},d.prototype.readUint16LE=d.prototype.readUInt16LE=function(o,u){return o=o>>>0,u||we(o,2,this.length),this[o]|this[o+1]<<8},d.prototype.readUint16BE=d.prototype.readUInt16BE=function(o,u){return o=o>>>0,u||we(o,2,this.length),this[o]<<8|this[o+1]},d.prototype.readUint32LE=d.prototype.readUInt32LE=function(o,u){return o=o>>>0,u||we(o,4,this.length),(this[o]|this[o+1]<<8|this[o+2]<<16)+this[o+3]*16777216},d.prototype.readUint32BE=d.prototype.readUInt32BE=function(o,u){return o=o>>>0,u||we(o,4,this.length),this[o]*16777216+(this[o+1]<<16|this[o+2]<<8|this[o+3])},d.prototype.readBigUInt64LE=Ne(function(o){o=o>>>0,Z(o,"offset");const u=this[o],g=this[o+7];(u===void 0||g===void 0)&&ae(o,this.length-8);const x=u+this[++o]*2**8+this[++o]*2**16+this[++o]*2**24,D=this[++o]+this[++o]*2**8+this[++o]*2**16+g*2**24;return BigInt(x)+(BigInt(D)<<BigInt(32))}),d.prototype.readBigUInt64BE=Ne(function(o){o=o>>>0,Z(o,"offset");const u=this[o],g=this[o+7];(u===void 0||g===void 0)&&ae(o,this.length-8);const x=u*2**24+this[++o]*2**16+this[++o]*2**8+this[++o],D=this[++o]*2**24+this[++o]*2**16+this[++o]*2**8+g;return(BigInt(x)<<BigInt(32))+BigInt(D)}),d.prototype.readIntLE=function(o,u,g){o=o>>>0,u=u>>>0,g||we(o,u,this.length);let x=this[o],D=1,q=0;for(;++q<u&&(D*=256);)x+=this[o+q]*D;return D*=128,x>=D&&(x-=Math.pow(2,8*u)),x},d.prototype.readIntBE=function(o,u,g){o=o>>>0,u=u>>>0,g||we(o,u,this.length);let x=u,D=1,q=this[o+--x];for(;x>0&&(D*=256);)q+=this[o+--x]*D;return D*=128,q>=D&&(q-=Math.pow(2,8*u)),q},d.prototype.readInt8=function(o,u){return o=o>>>0,u||we(o,1,this.length),this[o]&128?(255-this[o]+1)*-1:this[o]},d.prototype.readInt16LE=function(o,u){o=o>>>0,u||we(o,2,this.length);const g=this[o]|this[o+1]<<8;return g&32768?g|4294901760:g},d.prototype.readInt16BE=function(o,u){o=o>>>0,u||we(o,2,this.length);const g=this[o+1]|this[o]<<8;return g&32768?g|4294901760:g},d.prototype.readInt32LE=function(o,u){return o=o>>>0,u||we(o,4,this.length),this[o]|this[o+1]<<8|this[o+2]<<16|this[o+3]<<24},d.prototype.readInt32BE=function(o,u){return o=o>>>0,u||we(o,4,this.length),this[o]<<24|this[o+1]<<16|this[o+2]<<8|this[o+3]},d.prototype.readBigInt64LE=Ne(function(o){o=o>>>0,Z(o,"offset");const u=this[o],g=this[o+7];(u===void 0||g===void 0)&&ae(o,this.length-8);const x=this[o+4]+this[o+5]*2**8+this[o+6]*2**16+(g<<24);return(BigInt(x)<<BigInt(32))+BigInt(u+this[++o]*2**8+this[++o]*2**16+this[++o]*2**24)}),d.prototype.readBigInt64BE=Ne(function(o){o=o>>>0,Z(o,"offset");const u=this[o],g=this[o+7];(u===void 0||g===void 0)&&ae(o,this.length-8);const x=(u<<24)+this[++o]*2**16+this[++o]*2**8+this[++o];return(BigInt(x)<<BigInt(32))+BigInt(this[++o]*2**24+this[++o]*2**16+this[++o]*2**8+g)}),d.prototype.readFloatLE=function(o,u){return o=o>>>0,u||we(o,4,this.length),r.read(this,o,!0,23,4)},d.prototype.readFloatBE=function(o,u){return o=o>>>0,u||we(o,4,this.length),r.read(this,o,!1,23,4)},d.prototype.readDoubleLE=function(o,u){return o=o>>>0,u||we(o,8,this.length),r.read(this,o,!0,52,8)},d.prototype.readDoubleBE=function(o,u){return o=o>>>0,u||we(o,8,this.length),r.read(this,o,!1,52,8)};function Be(p,o,u,g,x,D){if(!d.isBuffer(p))throw new TypeError('"buffer" argument must be a Buffer instance');if(o>x||o<D)throw new RangeError('"value" argument is out of bounds');if(u+g>p.length)throw new RangeError("Index out of range")}d.prototype.writeUintLE=d.prototype.writeUIntLE=function(o,u,g,x){if(o=+o,u=u>>>0,g=g>>>0,!x){const ne=Math.pow(2,8*g)-1;Be(this,o,u,g,ne,0)}let D=1,q=0;for(this[u]=o&255;++q<g&&(D*=256);)this[u+q]=o/D&255;return u+g},d.prototype.writeUintBE=d.prototype.writeUIntBE=function(o,u,g,x){if(o=+o,u=u>>>0,g=g>>>0,!x){const ne=Math.pow(2,8*g)-1;Be(this,o,u,g,ne,0)}let D=g-1,q=1;for(this[u+D]=o&255;--D>=0&&(q*=256);)this[u+D]=o/q&255;return u+g},d.prototype.writeUint8=d.prototype.writeUInt8=function(o,u,g){return o=+o,u=u>>>0,g||Be(this,o,u,1,255,0),this[u]=o&255,u+1},d.prototype.writeUint16LE=d.prototype.writeUInt16LE=function(o,u,g){return o=+o,u=u>>>0,g||Be(this,o,u,2,65535,0),this[u]=o&255,this[u+1]=o>>>8,u+2},d.prototype.writeUint16BE=d.prototype.writeUInt16BE=function(o,u,g){return o=+o,u=u>>>0,g||Be(this,o,u,2,65535,0),this[u]=o>>>8,this[u+1]=o&255,u+2},d.prototype.writeUint32LE=d.prototype.writeUInt32LE=function(o,u,g){return o=+o,u=u>>>0,g||Be(this,o,u,4,4294967295,0),this[u+3]=o>>>24,this[u+2]=o>>>16,this[u+1]=o>>>8,this[u]=o&255,u+4},d.prototype.writeUint32BE=d.prototype.writeUInt32BE=function(o,u,g){return o=+o,u=u>>>0,g||Be(this,o,u,4,4294967295,0),this[u]=o>>>24,this[u+1]=o>>>16,this[u+2]=o>>>8,this[u+3]=o&255,u+4};function P(p,o,u,g,x){le(o,g,x,p,u,7);let D=Number(o&BigInt(4294967295));p[u++]=D,D=D>>8,p[u++]=D,D=D>>8,p[u++]=D,D=D>>8,p[u++]=D;let q=Number(o>>BigInt(32)&BigInt(4294967295));return p[u++]=q,q=q>>8,p[u++]=q,q=q>>8,p[u++]=q,q=q>>8,p[u++]=q,u}function L(p,o,u,g,x){le(o,g,x,p,u,7);let D=Number(o&BigInt(4294967295));p[u+7]=D,D=D>>8,p[u+6]=D,D=D>>8,p[u+5]=D,D=D>>8,p[u+4]=D;let q=Number(o>>BigInt(32)&BigInt(4294967295));return p[u+3]=q,q=q>>8,p[u+2]=q,q=q>>8,p[u+1]=q,q=q>>8,p[u]=q,u+8}d.prototype.writeBigUInt64LE=Ne(function(o,u=0){return P(this,o,u,BigInt(0),BigInt("0xffffffffffffffff"))}),d.prototype.writeBigUInt64BE=Ne(function(o,u=0){return L(this,o,u,BigInt(0),BigInt("0xffffffffffffffff"))}),d.prototype.writeIntLE=function(o,u,g,x){if(o=+o,u=u>>>0,!x){const pe=Math.pow(2,8*g-1);Be(this,o,u,g,pe-1,-pe)}let D=0,q=1,ne=0;for(this[u]=o&255;++D<g&&(q*=256);)o<0&&ne===0&&this[u+D-1]!==0&&(ne=1),this[u+D]=(o/q>>0)-ne&255;return u+g},d.prototype.writeIntBE=function(o,u,g,x){if(o=+o,u=u>>>0,!x){const pe=Math.pow(2,8*g-1);Be(this,o,u,g,pe-1,-pe)}let D=g-1,q=1,ne=0;for(this[u+D]=o&255;--D>=0&&(q*=256);)o<0&&ne===0&&this[u+D+1]!==0&&(ne=1),this[u+D]=(o/q>>0)-ne&255;return u+g},d.prototype.writeInt8=function(o,u,g){return o=+o,u=u>>>0,g||Be(this,o,u,1,127,-128),o<0&&(o=255+o+1),this[u]=o&255,u+1},d.prototype.writeInt16LE=function(o,u,g){return o=+o,u=u>>>0,g||Be(this,o,u,2,32767,-32768),this[u]=o&255,this[u+1]=o>>>8,u+2},d.prototype.writeInt16BE=function(o,u,g){return o=+o,u=u>>>0,g||Be(this,o,u,2,32767,-32768),this[u]=o>>>8,this[u+1]=o&255,u+2},d.prototype.writeInt32LE=function(o,u,g){return o=+o,u=u>>>0,g||Be(this,o,u,4,2147483647,-2147483648),this[u]=o&255,this[u+1]=o>>>8,this[u+2]=o>>>16,this[u+3]=o>>>24,u+4},d.prototype.writeInt32BE=function(o,u,g){return o=+o,u=u>>>0,g||Be(this,o,u,4,2147483647,-2147483648),o<0&&(o=4294967295+o+1),this[u]=o>>>24,this[u+1]=o>>>16,this[u+2]=o>>>8,this[u+3]=o&255,u+4},d.prototype.writeBigInt64LE=Ne(function(o,u=0){return P(this,o,u,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),d.prototype.writeBigInt64BE=Ne(function(o,u=0){return L(this,o,u,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function G(p,o,u,g,x,D){if(u+g>p.length)throw new RangeError("Index out of range");if(u<0)throw new RangeError("Index out of range")}function X(p,o,u,g,x){return o=+o,u=u>>>0,x||G(p,o,u,4),r.write(p,o,u,g,23,4),u+4}d.prototype.writeFloatLE=function(o,u,g){return X(this,o,u,!0,g)},d.prototype.writeFloatBE=function(o,u,g){return X(this,o,u,!1,g)};function re(p,o,u,g,x){return o=+o,u=u>>>0,x||G(p,o,u,8),r.write(p,o,u,g,52,8),u+8}d.prototype.writeDoubleLE=function(o,u,g){return re(this,o,u,!0,g)},d.prototype.writeDoubleBE=function(o,u,g){return re(this,o,u,!1,g)},d.prototype.copy=function(o,u,g,x){if(!d.isBuffer(o))throw new TypeError("argument should be a Buffer");if(g||(g=0),!x&&x!==0&&(x=this.length),u>=o.length&&(u=o.length),u||(u=0),x>0&&x<g&&(x=g),x===g||o.length===0||this.length===0)return 0;if(u<0)throw new RangeError("targetStart out of bounds");if(g<0||g>=this.length)throw new RangeError("Index out of range");if(x<0)throw new RangeError("sourceEnd out of bounds");x>this.length&&(x=this.length),o.length-u<x-g&&(x=o.length-u+g);const D=x-g;return this===o&&typeof i.prototype.copyWithin=="function"?this.copyWithin(u,g,x):i.prototype.set.call(o,this.subarray(g,x),u),D},d.prototype.fill=function(o,u,g,x){if(typeof o=="string"){if(typeof u=="string"?(x=u,u=0,g=this.length):typeof g=="string"&&(x=g,g=this.length),x!==void 0&&typeof x!="string")throw new TypeError("encoding must be a string");if(typeof x=="string"&&!d.isEncoding(x))throw new TypeError("Unknown encoding: "+x);if(o.length===1){const q=o.charCodeAt(0);(x==="utf8"&&q<128||x==="latin1")&&(o=q)}}else typeof o=="number"?o=o&255:typeof o=="boolean"&&(o=Number(o));if(u<0||this.length<u||this.length<g)throw new RangeError("Out of range index");if(g<=u)return this;u=u>>>0,g=g===void 0?this.length:g>>>0,o||(o=0);let D;if(typeof o=="number")for(D=u;D<g;++D)this[D]=o;else{const q=d.isBuffer(o)?o:d.from(o,x),ne=q.length;if(ne===0)throw new TypeError('The value "'+o+'" is invalid for argument "value"');for(D=0;D<g-u;++D)this[D+u]=q[D%ne]}return this};const b={};function E(p,o,u){b[p]=class extends u{constructor(){super(),Object.defineProperty(this,"message",{value:o.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${p}]`,this.stack,delete this.name}get code(){return p}set code(x){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:x,writable:!0})}toString(){return`${this.name} [${p}]: ${this.message}`}}}E("ERR_BUFFER_OUT_OF_BOUNDS",function(p){return p?`${p} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),E("ERR_INVALID_ARG_TYPE",function(p,o){return`The "${p}" argument must be of type number. Received type ${typeof o}`},TypeError),E("ERR_OUT_OF_RANGE",function(p,o,u){let g=`The value of "${p}" is out of range.`,x=u;return Number.isInteger(u)&&Math.abs(u)>2**32?x=H(String(u)):typeof u=="bigint"&&(x=String(u),(u>BigInt(2)**BigInt(32)||u<-(BigInt(2)**BigInt(32)))&&(x=H(x)),x+="n"),g+=` It must be ${o}. Received ${x}`,g},RangeError);function H(p){let o="",u=p.length;const g=p[0]==="-"?1:0;for(;u>=g+4;u-=3)o=`_${p.slice(u-3,u)}${o}`;return`${p.slice(0,u)}${o}`}function V(p,o,u){Z(o,"offset"),(p[o]===void 0||p[o+u]===void 0)&&ae(o,p.length-(u+1))}function le(p,o,u,g,x,D){if(p>u||p<o){const q=typeof o=="bigint"?"n":"";let ne;throw o===0||o===BigInt(0)?ne=`>= 0${q} and < 2${q} ** ${(D+1)*8}${q}`:ne=`>= -(2${q} ** ${(D+1)*8-1}${q}) and < 2 ** ${(D+1)*8-1}${q}`,new b.ERR_OUT_OF_RANGE("value",ne,p)}V(g,x,D)}function Z(p,o){if(typeof p!="number")throw new b.ERR_INVALID_ARG_TYPE(o,"number",p)}function ae(p,o,u){throw Math.floor(p)!==p?(Z(p,u),new b.ERR_OUT_OF_RANGE("offset","an integer",p)):o<0?new b.ERR_BUFFER_OUT_OF_BOUNDS:new b.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${o}`,p)}const ut=/[^+/0-9A-Za-z-_]/g;function Tt(p){if(p=p.split("=")[0],p=p.trim().replace(ut,""),p.length<2)return"";for(;p.length%4!==0;)p=p+"=";return p}function vt(p,o){o=o||1/0;let u;const g=p.length;let x=null;const D=[];for(let q=0;q<g;++q){if(u=p.charCodeAt(q),u>55295&&u<57344){if(!x){if(u>56319){(o-=3)>-1&&D.push(239,191,189);continue}else if(q+1===g){(o-=3)>-1&&D.push(239,191,189);continue}x=u;continue}if(u<56320){(o-=3)>-1&&D.push(239,191,189),x=u;continue}u=(x-55296<<10|u-56320)+65536}else x&&(o-=3)>-1&&D.push(239,191,189);if(x=null,u<128){if((o-=1)<0)break;D.push(u)}else if(u<2048){if((o-=2)<0)break;D.push(u>>6|192,u&63|128)}else if(u<65536){if((o-=3)<0)break;D.push(u>>12|224,u>>6&63|128,u&63|128)}else if(u<1114112){if((o-=4)<0)break;D.push(u>>18|240,u>>12&63|128,u>>6&63|128,u&63|128)}else throw new Error("Invalid code point")}return D}function hr(p){const o=[];for(let u=0;u<p.length;++u)o.push(p.charCodeAt(u)&255);return o}function Ee(p,o){let u,g,x;const D=[];for(let q=0;q<p.length&&!((o-=2)<0);++q)u=p.charCodeAt(q),g=u>>8,x=u%256,D.push(x),D.push(g);return D}function Ie(p){return e.toByteArray(Tt(p))}function Qe(p,o,u,g){let x;for(x=0;x<g&&!(x+u>=o.length||x>=p.length);++x)o[x+u]=p[x];return x}function Me(p,o){return p instanceof o||p!=null&&p.constructor!=null&&p.constructor.name!=null&&p.constructor.name===o.name}function Ge(p){return p!==p}const Xe=(function(){const p="0123456789abcdef",o=new Array(256);for(let u=0;u<16;++u){const g=u*16;for(let x=0;x<16;++x)o[g+x]=p[u]+p[x]}return o})();function Ne(p){return typeof BigInt>"u"?xt:p}function xt(){throw new Error("BigInt not supported")}})(un);const bi=un.Buffer,It=un.Buffer;class jt extends Promise{#e;#t;constructor(e){super(r=>{r()}),this.#e=e}static from(e){return new jt(r=>{r(e())})}static resolve(e){return new jt(r=>{r(e)})}static reject(e){return new jt((r,n)=>{n(e)})}then(e,r){return this.#t??=new Promise(this.#e),this.#t.then(e,r)}catch(e){return this.#t??=new Promise(this.#e),this.#t.catch(e)}finally(e){return this.#t??=new Promise(this.#e),this.#t.finally(e)}}class hn{constructor(e,r,n=30*1e3){this.subscribeFn=e,this.unsubscribeFn=r,this.lingerMs=n,this.counts=new Map,this.pending=new Map,this.lingers=new Map}async subscribe(e,r={qos:2}){const n=this.counts.get(e)??0;this.counts.set(e,n+1);const s=this.lingers.get(e);if(s){clearTimeout(s),this.lingers.delete(e);return}if(n===0){const i=this.subscribeFn(e,r).finally(()=>{this.pending.delete(e)}).catch(c=>{const l=this.counts.get(e);throw l&&(l<=1?this.counts.delete(e):this.counts.set(e,l-1)),c});return this.pending.set(e,i),i}else{const i=this.pending.get(e);if(i)return i}}async unsubscribe(e){const r=this.counts.get(e);if(r)if(r<=1)if(this.counts.delete(e),this.lingerMs>0){const n=setTimeout(()=>{this.lingers.delete(e),this.unsubscribeFn(e).catch(()=>{})},this.lingerMs);this.lingers.set(e,n)}else await this.unsubscribeFn(e).catch(()=>{});else this.counts.set(e,r-1)}async flush(){const e=[...this.lingers.keys()];for(const r of e)clearTimeout(this.lingers.get(r)),this.lingers.delete(r),await this.unsubscribeFn(r).catch(()=>{})}}class Ei{constructor(e){this.waiters=[],this.aborted=!1,this.remaining=e}async acquire(e){if(this.aborted)throw new Error("credit gate aborted");if(e?.aborted)throw e.reason??new Error("aborted");this.remaining>0?this.remaining--:await new Promise((r,n)=>{const s=()=>{this.waiters.splice(this.waiters.indexOf(i),1),n(e?.reason??new Error("aborted"))};e&&e.addEventListener("abort",s,{once:!0});const i=c=>{if(e&&e.removeEventListener("abort",s),c){n(new Error("credit gate aborted"));return}this.remaining--,r()};this.waiters.push(i)})}replenish(e){for(this.remaining+=e;this.waiters.length>0&&this.remaining>0;)this.waiters.shift()(!1)}abort(){for(this.aborted=!0;this.waiters.length>0;)this.waiters.shift()(!0)}}function lo(t){const e=t.reduce((s,i)=>s+i.byteLength,0),r=new Uint8Array(e);let n=0;for(const s of t)r.set(s,n),n+=s.byteLength;return r}function Si(t){let e;if(t instanceof It)e=new Uint8Array(t.buffer,t.byteOffset,t.length);else if(t instanceof Uint8Array)e=t;else if(typeof t=="string")e=new TextEncoder().encode(t);else throw new Error("invalid chunk type: expected Buffer, Uint8Array, or string");return e}function _i(t){return new jt((e,r)=>{const n=[];t.on("data",s=>{const i=Si(s);n.push(i)}),t.on("end",()=>{e(lo(n))}),t.on("error",s=>{r(s)})})}async function Ti(t,e,r,n,s){if(t.byteLength===0)await r(void 0,void 0,!0);else for(let i=0;i<t.byteLength;i+=e){if(s?.aborted)throw s.reason??new Error("aborted");const c=Math.min(t.byteLength-i,e),l=t.subarray(i,i+c),h=i+c>=t.byteLength;n&&await n.acquire(s),await r(l,void 0,h)}}async function vi(t,e,r,n,s){for await(const i of t){if(s?.aborted)throw s.reason??new Error("aborted");const c=Si(i);if(c.byteLength!==0)for(let l=0;l<c.byteLength;l+=e){if(s?.aborted)throw s.reason??new Error("aborted");const h=Math.min(c.byteLength-l,e),w=c.subarray(l,l+h);n&&await n.acquire(s),await r(w,void 0,!1)}}if(s?.aborted)throw s.reason??new Error("aborted");await r(void 0,void 0,!0)}function xi(t,e,r){if(!(typeof t=="object"&&t!==null))throw new Error("invalid object");let n;const s=t[e],i=t[r];Object.defineProperty(t,e,{get:()=>{if(n==="f2")throw new Error(`field "${e}" is mutually exclusive with field "${r}" and "${r}" was already consumed`);return n="f1",s},enumerable:!0,configurable:!0}),Object.defineProperty(t,r,{get:()=>{if(n==="f1")throw new Error(`field "${r}" is mutually exclusive with field "${e}" and "${e}" was already consumed`);return n="f2",i},enumerable:!0,configurable:!0})}class Pe{constructor(){this.resources=[]}roll(...e){let r,n;if(e.length===1)r=void 0,n=e[0];else if(e.length===2)r=e[0],n=e[1];else throw new Error("invalid number of arguments");this.resources.push({resource:r,cleanup:n})}sub(){const e=new Pe;return this.roll(e,()=>{}),e}unroll(e=!0){try{let r;for(;this.resources.length>0;){const n=this.resources.pop(),s=n.resource,i=n.cleanup;if(r)s instanceof Pe?r=r.then(()=>s.unroll()):r=r.then(()=>i(s));else{let c;s instanceof Pe?c=s.unroll():c=i(s),c instanceof Promise&&(r=c)}}return r?e?r.catch(()=>{}):r:void 0}catch(r){if(e)return;throw r}}}function yt(t,e,r=!1){if(t instanceof Error&&e===void 0&&r===!1)return t;let n=t instanceof Error?t.message:String(t);if(e&&(n=`${e}: ${n}`),r&&t instanceof Error&&(n=`${n}
2
- ${t.stack}`),t instanceof Error){const s=new Error(n,{cause:t});return s.stack=t.stack,s}else return new Error(n)}function wt(t,e){if(!e)return t?Promise.resolve():void 0;let r;try{r=e()}catch(n){if(t)return Promise.reject(n);throw n}if(!t&&r instanceof Promise)throw new Error("onfinally callback returned Promise in non-async context");return t&&!(r instanceof Promise)&&(r=Promise.resolve(r)),r}function Er(t,e){if(!e)return t?Promise.resolve():void 0;let r=e.unroll();if(!t&&r instanceof Promise)throw new Error("spool unroll returned Promise in non-async context");return t&&!(r instanceof Promise)&&(r=Promise.resolve(r)),r}function ke(...t){let e,r,n,s,i,c;if(t.length===1&&typeof t[0]=="object"&&t[0]!==null?(e=t[0].description,r=t[0].spool,n=t[0].action,s=t[0].oncatch,i=t[0].onfinally,c=t[0].oncleanup):typeof t[0]=="string"?(e=t[0],t[1]instanceof Pe?(r=t[1],n=t[2],s=t[3],i=t[4],c=t[5]):(n=t[1],s=t[2],i=t[3],c=t[4])):t[0]instanceof Pe?(r=t[0],n=t[1],s=t[2],i=t[3],c=t[4]):(n=t[0],s=t[1],i=t[2],c=t[3]),c&&!r)throw new Error("oncleanup requires a spool");let l;try{l=n()}catch(h){let w=yt(h,e);if(s){try{l=s(w)}catch(d){throw w=yt(d,e),wt(!1,i),Er(!1,r),w}return wt(!1,i),l}throw wt(!1,i),Er(!1,r),w}return l instanceof Promise?l.then(async h=>(await wt(!0,i),r&&c&&r.roll(h,c),h),async h=>{let w=yt(h,e);if(s)try{const d=s(w);return await wt(!0,i),d}catch(d){throw w=yt(d,e),await wt(!0,i),await Er(!0,r),w}throw await wt(!0,i),await Er(!0,r),w}):(wt(!1,i),r&&c&&r.roll(l,c),l)}let dn;function Ai(t){return{lang:t?.lang??dn?.lang,message:t?.message,abortEarly:t?.abortEarly??dn?.abortEarly,abortPipeEarly:t?.abortPipeEarly??dn?.abortPipeEarly}}let ho;function po(t){return ho?.get(t)}let yo;function wo(t){return yo?.get(t)}let go;function mo(t,e){return go?.get(t)?.get(e)}function Sr(t){const e=typeof t;return e==="string"?`"${t}"`:e==="number"||e==="bigint"||e==="boolean"?`${t}`:e==="object"||e==="function"?(t&&Object.getPrototypeOf(t)?.constructor?.name)??"null":e}function Le(t,e,r,n,s){const i=s&&"input"in s?s.input:r.value,c=s?.expected??t.expects??null,l=s?.received??Sr(i),h={kind:t.kind,type:t.type,input:i,expected:c,received:l,message:`Invalid ${e}: ${c?`Expected ${c} but r`:"R"}eceived ${l}`,requirement:t.requirement,path:s?.path,issues:s?.issues,lang:n.lang,abortEarly:n.abortEarly,abortPipeEarly:n.abortPipeEarly},w=t.kind==="schema",d=s?.message??t.message??mo(t.reference,h.lang)??(w?wo(h.lang):null)??n.message??po(h.lang);d!==void 0&&(h.message=typeof d=="function"?d(h):d),w&&(r.typed=!1),r.issues?r.issues.push(h):r.issues=[h]}function Je(t){return{version:1,vendor:"valibot",validate(e){return t["~run"]({value:e},Ai())}}}function bo(t,e){return Object.hasOwn(t,e)&&e!=="__proto__"&&e!=="prototype"&&e!=="constructor"}function Ri(t,e){return{kind:"validation",type:"check",reference:Ri,async:!1,expects:null,requirement:t,message:e,"~run"(r,n){return r.typed&&!this.requirement(r.value)&&Le(this,"input",r,n),r}}}function Zt(t){return{kind:"validation",type:"integer",reference:Zt,async:!1,expects:null,requirement:Number.isInteger,message:t,"~run"(e,r){return e.typed&&!this.requirement(e.value)&&Le(this,"integer",e,r),e}}}function Bt(t,e){return{kind:"validation",type:"max_length",reference:Bt,async:!1,expects:`<=${t}`,requirement:t,message:e,"~run"(r,n){return r.typed&&r.value.length>this.requirement&&Le(this,"length",r,n,{received:`${r.value.length}`}),r}}}function er(t,e){return{kind:"validation",type:"min_value",reference:er,async:!1,expects:`>=${t instanceof Date?t.toJSON():Sr(t)}`,requirement:t,message:e,"~run"(r,n){return r.typed&&!(r.value>=this.requirement)&&Le(this,"value",r,n,{received:r.value instanceof Date?r.value.toJSON():Sr(r.value)}),r}}}function Ii(t,e){return{kind:"validation",type:"regex",reference:Ii,async:!1,expects:`${t}`,requirement:t,message:e,"~run"(r,n){return r.typed&&!this.requirement.test(r.value)&&Le(this,"format",r,n),r}}}function Eo(t,e,r){return typeof t.fallback=="function"?t.fallback(e,r):t.fallback}function Bi(t,e,r){return typeof t.default=="function"?t.default(e,r):t.default}function qt(t,e){return{kind:"schema",type:"array",reference:qt,expects:"Array",async:!1,item:t,message:e,get"~standard"(){return Je(this)},"~run"(r,n){const s=r.value;if(Array.isArray(s)){r.typed=!0,r.value=[];for(let i=0;i<s.length;i++){const c=s[i],l=this.item["~run"]({value:c},n);if(l.issues){const h={type:"array",origin:"value",input:s,key:i,value:c};for(const w of l.issues)w.path?w.path.unshift(h):w.path=[h],r.issues?.push(w);if(r.issues||(r.issues=l.issues),n.abortEarly){r.typed=!1;break}}l.typed||(r.typed=!1),r.value.push(l.value)}}else Le(this,"type",r,n);return r}}}function pn(t){return{kind:"schema",type:"boolean",reference:pn,expects:"boolean",async:!1,message:t,get"~standard"(){return Je(this)},"~run"(e,r){return typeof e.value=="boolean"?e.typed=!0:Le(this,"type",e,r),e}}}function yn(t,e){return{kind:"schema",type:"instance",reference:yn,expects:t.name,async:!1,class:t,message:e,get"~standard"(){return Je(this)},"~run"(r,n){return r.value instanceof this.class?r.typed=!0:Le(this,"type",r,n),r}}}function je(t,e){return{kind:"schema",type:"literal",reference:je,expects:Sr(t),async:!1,literal:t,message:e,get"~standard"(){return Je(this)},"~run"(r,n){return r.value===this.literal?r.typed=!0:Le(this,"type",r,n),r}}}function tr(t){return{kind:"schema",type:"number",reference:tr,expects:"number",async:!1,message:t,get"~standard"(){return Je(this)},"~run"(e,r){return typeof e.value=="number"&&!isNaN(e.value)?e.typed=!0:Le(this,"type",e,r),e}}}function ce(t,e){return{kind:"schema",type:"optional",reference:ce,expects:`(${t.expects} | undefined)`,async:!1,wrapped:t,default:e,get"~standard"(){return Je(this)},"~run"(r,n){return r.value===void 0&&(this.default!==void 0&&(r.value=Bi(this,r,n)),r.value===void 0)?(r.typed=!0,r):this.wrapped["~run"](r,n)}}}function ki(t,e,r){return{kind:"schema",type:"record",reference:ki,expects:"Object",async:!1,key:t,value:e,message:r,get"~standard"(){return Je(this)},"~run"(n,s){const i=n.value;if(i&&typeof i=="object"){n.typed=!0,n.value={};for(const c in i)if(bo(i,c)){const l=i[c],h=this.key["~run"]({value:c},s);if(h.issues){const d={type:"object",origin:"key",input:i,key:c,value:l};for(const I of h.issues)I.path=[d],n.issues?.push(I);if(n.issues||(n.issues=h.issues),s.abortEarly){n.typed=!1;break}}const w=this.value["~run"]({value:l},s);if(w.issues){const d={type:"object",origin:"value",input:i,key:c,value:l};for(const I of w.issues)I.path?I.path.unshift(d):I.path=[d],n.issues?.push(I);if(n.issues||(n.issues=w.issues),s.abortEarly){n.typed=!1;break}}(!h.typed||!w.typed)&&(n.typed=!1),h.typed&&(n.value[h.value]=w.value)}}else Le(this,"type",n,s);return n}}}function qe(t,e){return{kind:"schema",type:"strict_object",reference:qe,expects:"Object",async:!1,entries:t,message:e,get"~standard"(){return Je(this)},"~run"(r,n){const s=r.value;if(s&&typeof s=="object"){r.typed=!0,r.value={};for(const i in this.entries){const c=this.entries[i];if(i in s||(c.type==="exact_optional"||c.type==="optional"||c.type==="nullish")&&c.default!==void 0){const l=i in s?s[i]:Bi(c),h=c["~run"]({value:l},n);if(h.issues){const w={type:"object",origin:"value",input:s,key:i,value:l};for(const d of h.issues)d.path?d.path.unshift(w):d.path=[w],r.issues?.push(d);if(r.issues||(r.issues=h.issues),n.abortEarly){r.typed=!1;break}}h.typed||(r.typed=!1),r.value[i]=h.value}else if(c.fallback!==void 0)r.value[i]=Eo(c);else if(c.type!=="exact_optional"&&c.type!=="optional"&&c.type!=="nullish"&&(Le(this,"key",r,n,{input:void 0,expected:`"${i}"`,path:[{type:"object",origin:"key",input:s,key:i,value:s[i]}]}),n.abortEarly))break}if(!r.issues||!n.abortEarly){for(const i in s)if(!(i in this.entries)){Le(this,"key",r,n,{input:i,expected:"never",path:[{type:"object",origin:"key",input:s,key:i,value:s[i]}]});break}}}else Le(this,"type",r,n);return r}}}function be(t){return{kind:"schema",type:"string",reference:be,expects:"string",async:!1,message:t,get"~standard"(){return Je(this)},"~run"(e,r){return typeof e.value=="string"?e.typed=!0:Le(this,"type",e,r),e}}}function kt(){return{kind:"schema",type:"unknown",reference:kt,expects:"unknown",async:!1,get"~standard"(){return Je(this)},"~run"(t){return t.typed=!0,t}}}function Ke(...t){return{...t[0],pipe:t,get"~standard"(){return Je(this)},"~run"(e,r){for(const n of t)if(n.kind!=="metadata"){if(e.issues&&(n.kind==="schema"||n.kind==="transformation")){e.typed=!1;break}(!e.issues||!r.abortEarly&&!r.abortPipeEarly)&&(e=n["~run"](e,r))}return e}}}function So(t,e,r){const n=t["~run"]({value:e},Ai(r));return{typed:n.typed,success:!n.issues,output:n.value,issues:n.issues}}const z={POS_INT:0,NEG_INT:1,BYTE_STRING:2,UTF8_STRING:3,ARRAY:4,MAP:5,TAG:6,SIMPLE_FLOAT:7},oe={DATE_STRING:0,DATE_EPOCH:1,POS_BIGINT:2,NEG_BIGINT:3,CBOR:24,URI:32,BASE64URL:33,BASE64:34,DATE_EPOCH_DAYS:100,SET:258,JSON:262,WTF8:273,DATE_FULL:1004,REGEXP:21066,SELF_DESCRIBED:55799,INVALID_16:65535,INVALID_32:4294967295,INVALID_64:0xffffffffffffffffn},te={ZERO:0,ONE:24,TWO:25,FOUR:26,EIGHT:27,INDEFINITE:31},gt={FALSE:20,TRUE:21,NULL:22,UNDEFINED:23};let Fe=class{static BREAK=Symbol.for("github.com/hildjj/cbor2/break");static ENCODED=Symbol.for("github.com/hildjj/cbor2/cbor-encoded");static LENGTH=Symbol.for("github.com/hildjj/cbor2/length")};const _r={MIN:-(2n**63n),MAX:2n**64n-1n};let ee=class $r{static#e=new Map;tag;contents;constructor(e,r=void 0){this.tag=e,this.contents=r}get noChildren(){return!!$r.#e.get(this.tag)?.noChildren}static registerDecoder(e,r,n){const s=this.#e.get(e);return this.#e.set(e,r),s&&("comment"in r||(r.comment=s.comment),"noChildren"in r||(r.noChildren=s.noChildren)),n&&!r.comment&&(r.comment=()=>`(${n})`),s}static clearDecoder(e){const r=this.#e.get(e);return this.#e.delete(e),r}static getDecoder(e){return this.#e.get(e)}static getAllDecoders(){return new Map(this.#e)}*[Symbol.iterator](){yield this.contents}push(e){return this.contents=e,1}decode(e){const r=e?.tags?.get(this.tag)??(e?.ignoreGlobalTags?void 0:$r.#e.get(this.tag));return r?r(this,e):this}comment(e,r){const n=e?.tags?.get(this.tag)??(e?.ignoreGlobalTags?void 0:$r.#e.get(this.tag));if(n?.comment)return n.comment(this,e,r)}toCBOR(){return[this.tag,this.contents]}[Symbol.for("nodejs.util.inspect.custom")](e,r,n){return`${this.tag}(${n(this.contents,r)})`}};function Tr(t){if(t!=null&&typeof t=="object")return t[Fe.ENCODED]}function _o(t){if(t!=null&&typeof t=="object")return t[Fe.LENGTH]}function rr(t,e){Object.defineProperty(t,Fe.ENCODED,{configurable:!0,enumerable:!1,value:e})}function nr(t,e){const r=Object(t);return rr(r,e),r}const wn=Symbol("CBOR_RANGES");function Ni(t,e){Object.defineProperty(t,wn,{configurable:!1,enumerable:!1,writable:!1,value:e})}function vr(t){return t[wn]}function To(t){return vr(t)!==void 0}function gn(t,e=0,r=t.length-1){const n=t.subarray(e,r),s=vr(t);if(s){const i=[];for(const c of s)if(c[0]>=e&&c[0]+c[1]<=r){const l=[...c];l[0]-=e,i.push(l)}i.length&&Ni(n,i)}return n}function Mi(t){let e=Math.ceil(t.length/2);const r=new Uint8Array(e);e--;for(let n=t.length,s=n-2;n>=0;n=s,s-=2,e--)r[e]=parseInt(t.substring(s,n),16);return r}function De(t){return t.reduce((e,r)=>e+r.toString(16).padStart(2,"0"),"")}function vo(t){const e=t.reduce((c,l)=>c+l.length,0),r=t.some(c=>To(c)),n=[],s=new Uint8Array(e);let i=0;for(const c of t){if(!(c instanceof Uint8Array))throw new TypeError(`Invalid array: ${c}`);if(s.set(c,i),r){const l=c[wn]??[[0,c.length]];for(const h of l)h[0]+=i;n.push(...l)}i+=c.length}return r&&Ni(s,n),s}function mn(t){const e=atob(t);return Uint8Array.from(e,r=>r.codePointAt(0))}const xo={"-":"+",_:"/"};function Ao(t){const e=t.replace(/[_-]/g,r=>xo[r]);return mn(e.padEnd(Math.ceil(e.length/4)*4,"="))}function Ro(){const t=new Uint8Array(4),e=new Uint32Array(t.buffer);return!((e[0]=1)&t[0])}function Fi(t){let e="";for(const r of t){const n=r.codePointAt(0)?.toString(16).padStart(4,"0");e&&(e+=", "),e+=`U+${n}`}return e}class Ui{#e=new Map;registerEncoder(e,r){const n=this.#e.get(e);return this.#e.set(e,r),n}get(e){return this.#e.get(e)}delete(e){return this.#e.delete(e)}clear(){this.#e.clear()}}function Li(t,e){const[r,n,s]=t,[i,c,l]=e,h=Math.min(s.length,l.length);for(let w=0;w<h;w++){const d=s[w]-l[w];if(d!==0)return d}return 0}class xr{static defaultOptions={chunkSize:4096};#e;#t=[];#r=null;#n=0;#i=0;constructor(e={}){if(this.#e={...xr.defaultOptions,...e},this.#e.chunkSize<8)throw new RangeError(`Expected size >= 8, got ${this.#e.chunkSize}`);this.#s()}get length(){return this.#i}read(){this.#c();const e=new Uint8Array(this.#i);let r=0;for(const n of this.#t)e.set(n,r),r+=n.length;return this.#s(),e}write(e){const r=e.length;r>this.#u()?(this.#c(),r>this.#e.chunkSize?(this.#t.push(e),this.#s()):(this.#s(),this.#t[this.#t.length-1].set(e),this.#n=r)):(this.#t[this.#t.length-1].set(e,this.#n),this.#n+=r),this.#i+=r}writeUint8(e){this.#o(1),this.#r.setUint8(this.#n,e),this.#a(1)}writeUint16(e,r=!1){this.#o(2),this.#r.setUint16(this.#n,e,r),this.#a(2)}writeUint32(e,r=!1){this.#o(4),this.#r.setUint32(this.#n,e,r),this.#a(4)}writeBigUint64(e,r=!1){this.#o(8),this.#r.setBigUint64(this.#n,e,r),this.#a(8)}writeInt16(e,r=!1){this.#o(2),this.#r.setInt16(this.#n,e,r),this.#a(2)}writeInt32(e,r=!1){this.#o(4),this.#r.setInt32(this.#n,e,r),this.#a(4)}writeBigInt64(e,r=!1){this.#o(8),this.#r.setBigInt64(this.#n,e,r),this.#a(8)}writeFloat32(e,r=!1){this.#o(4),this.#r.setFloat32(this.#n,e,r),this.#a(4)}writeFloat64(e,r=!1){this.#o(8),this.#r.setFloat64(this.#n,e,r),this.#a(8)}clear(){this.#i=0,this.#t=[],this.#s()}#s(){const e=new Uint8Array(this.#e.chunkSize);this.#t.push(e),this.#n=0,this.#r=new DataView(e.buffer,e.byteOffset,e.byteLength)}#c(){if(this.#n===0){this.#t.pop();return}const e=this.#t.length-1;this.#t[e]=this.#t[e].subarray(0,this.#n),this.#n=0,this.#r=null}#u(){const e=this.#t.length-1;return this.#t[e].length-this.#n}#o(e){this.#u()<e&&(this.#c(),this.#s())}#a(e){this.#n+=e,this.#i+=e}}const bn=1n<<15n,ir=0b11111n<<10n,Ci=1n<<9n,Pi=Ci-1n,Di=Ci|Pi,En=1n<<31n,sr=0b11111111n<<23n,Oi=1n<<22n,$i=Oi-1n,ji=Oi|$i,Ar=1n<<63n,dt=0b11111111111n<<52n,or=1n<<51n,Rr=or-1n,qi=or|Rr,Ki=Rr-(Pi<<42n),Wi=Rr-($i<<29n),Io={2:"0b",8:"0o",16:"0x"};var Bo=(t=>(t[t.NATURAL=-2]="NATURAL",t[t.UNKNOWN=-1]="UNKNOWN",t[t.F16=2]="F16",t[t.F32=4]="F32",t[t.F64=8]="F64",t))(Bo||{});function Hi(t,e,r,n){let s="nan'";return t.quiet||(s+="!"),t.sign===-1&&(s+="-"),s+=n(Math.abs(t.payload),r),s+="'",s+=t.encodingIndicator,s}let ko=class extends Number{#e;#t=-1;constructor(e,r=!0,n=-1){super(NaN);const s=e;if(typeof e=="number"){if(!Number.isSafeInteger(e))throw new Error(`Invalid NAN payload: ${e}`);e=BigInt(e);let i=0n;if(e<0&&(i=Ar,e=-e),e>=or)throw new Error(`Payload too large: ${s}`);const c=r?or:0n;switch(this.#e=i|dt|c|e,n){case-2:throw new Error("NAN_SIZE.NATURAL only valid for bigint constructor");case-1:n=this.preferredSize;break;case 2:if(this.#e&Ki)throw new Error("Invalid size for payload");break;case 4:if(this.#e&Wi)throw new Error("Invalid size for payload");break;case 8:break;default:throw new Error(`Invalid size: ${n}`)}this.#t=n}else if(typeof e=="bigint"){let i=-1;if((e&dt)===dt)this.#e=e,i=8;else if((e&sr)===sr){const c=(e&En)<<32n;this.#e=c|dt|(e&ji)<<29n,i=4}else if((e&ir)===ir){const c=(e&bn)<<48n;this.#e=c|dt|(e&Di)<<42n,i=2}else throw new Error(`Invalid raw NaN value: ${e}`);if(n===-1)this.#t=this.preferredSize;else if(n===-2)this.#t=i;else{if(n<i)throw new Error("Invalid bigint NaN size");this.#t=n}}else{const i=new DataView(e.buffer,e.byteOffset,e.byteLength);switch(e.length){case 3:{if(e[0]!==249)throw new Error("Invalid CBOR encoding for half float");const c=BigInt(i.getUint16(1,!1));if((c&ir)!==ir)throw new Error("Not a NaN");const l=(c&bn)<<48n;this.#e=l|dt|(c&Di)<<42n,this.#t=2;break}case 5:{if(e[0]!==250)throw new Error("Invalid CBOR encoding for single float");const c=BigInt(i.getUint32(1,!1));if((c&sr)!==sr)throw new Error("Not a NaN");const l=(c&En)<<32n;this.#e=l|dt|(c&ji)<<29n,this.#t=4;break}case 9:{if(e[0]!==251)throw new Error("Invalid CBOR encoding for double float");if(this.#e=i.getBigUint64(1,!1),(this.#e&dt)!==dt)throw new Error("Not a NaN (NaNaN)");this.#t=8;break}default:throw new RangeError(`Invalid NAN size (should be 2, 4, or 8): ${e.length-1}`)}}if(!this.payload&&!this.quiet)throw new Error("Signalling NaN with zero payload")}get bytes(){const e=new ArrayBuffer(this.#t+1),r=new DataView(e);switch(this.#t){case 2:{r.setUint8(0,249);const n=(this.#e&Ar?bn:0n)|ir|(this.#e&qi)>>42n;r.setUint16(1,Number(n),!1);break}case 4:{r.setUint8(0,250);const n=(this.#e&Ar?En:0n)|sr|(this.#e&qi)>>29n;r.setUint32(1,Number(n),!1);break}case 8:r.setUint8(0,251),r.setBigUint64(1,this.#e);break}return new Uint8Array(e)}get quiet(){return!!(this.#e&or)}get sign(){return this.#e&Ar?-1:1}get payload(){return Number(this.#e&Rr)*this.sign}get raw(){return this.#e}get encodingIndicator(){switch(this.#t){case 2:return"_1";case 4:return"_2"}return"_3"}get size(){return this.#t}get preferredSize(){return(this.#e&Ki)===0n?2:(this.#e&Wi)===0n?4:8}get isShortestEncoding(){return this.preferredSize===this.#t}toCBOR(e){e.write(this.bytes)}toString(e=10){return Hi(this,1,{},r=>(Io[e]??"")+r.toString(e))}[Symbol.for("nodejs.util.inspect.custom")](e,r,n){return Hi(this,e,r,n)}};function Gi(t,e=0,r=!1){const n=t[e]&128?-1:1,s=(t[e]&124)>>2,i=(t[e]&3)<<8|t[e+1];if(s===0){if(r&&i!==0)throw new Error(`Unwanted subnormal: ${n*5960464477539063e-23*i}`);return n*5960464477539063e-23*i}else if(s===31)return i?NaN:n*(1/0);return n*2**(s-25)*(1024+i)}function Ji(t){const e=new DataView(new ArrayBuffer(4));e.setFloat32(0,t,!1);const r=e.getUint32(0,!1);if((r&8191)!==0)return null;let n=r>>16&32768;const s=r>>23&255,i=r&8388607;if(!(s===0&&i===0))if(s>=113&&s<=142)n+=(s-112<<10)+(i>>13);else if(s>=103&&s<113){if(i&(1<<126-s)-1)return null;n+=i+8388608>>126-s}else if(s===255)n|=31744,n|=i>>13;else return null;return n}function No(t){if(t!==0){const e=new ArrayBuffer(8),r=new DataView(e);r.setFloat64(0,t,!1);const n=r.getBigUint64(0,!1);if((n&0x7ff0000000000000n)===0n)return n&0x8000000000000000n?-0:0}return t}function Mo(t){switch(t.length){case 2:Gi(t,0,!0);break;case 4:{const e=new DataView(t.buffer,t.byteOffset,t.byteLength),r=e.getUint32(0,!1);if((r&2139095040)===0&&r&8388607)throw new Error(`Unwanted subnormal: ${e.getFloat32(0,!1)}`);break}case 8:{const e=new DataView(t.buffer,t.byteOffset,t.byteLength),r=e.getBigUint64(0,!1);if((r&0x7ff0000000000000n)===0n&&r&0x000fffffffffffn)throw new Error(`Unwanted subnormal: ${e.getFloat64(0,!1)}`);break}default:throw new TypeError(`Bad input to isSubnormal: ${t}`)}}class Fo extends TypeError{code="ERR_ENCODING_INVALID_ENCODED_DATA";constructor(){super("The encoded data was not valid for encoding wtf-8")}}class Uo extends RangeError{code="ERR_ENCODING_NOT_SUPPORTED";constructor(e){super(`Invalid encoding: "${e}"`)}}const Lo=65279,zi=new Uint8Array(0),Co=55296,Po=56320,Do=65533,Vi="wtf-8";function Oo(t){return t&&!(t instanceof ArrayBuffer)&&t.buffer instanceof ArrayBuffer}function $o(t){return t?t instanceof Uint8Array?t:Oo(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t):zi}const jo=[0,0,0,0,0,0,0,0,-1,-1,-1,-1,1,1,2,3];class Ir{static DEFAULT_BUFFERSIZE=4096;encoding=Vi;fatal;ignoreBOM;bufferSize;#e=0;#t=0;#r=0;#n=!0;#i;constructor(e="wtf8",r=void 0){if(e.toLowerCase().replace("-","")!=="wtf8")throw new Uo(e);if(this.fatal=!!r?.fatal,this.ignoreBOM=!!r?.ignoreBOM,this.bufferSize=Math.floor(r?.bufferSize??Ir.DEFAULT_BUFFERSIZE),isNaN(this.bufferSize)||this.bufferSize<1)throw new RangeError(`Invalid buffer size: ${r?.bufferSize}`);this.#i=new Uint16Array(this.bufferSize)}decode(e,r){const n=!!r?.stream,s=$o(e),i=[],c=this.#i,l=this.bufferSize-3;let h=0;const w=()=>{if(this.#t=0,this.#e=0,this.#r=0,this.fatal)throw new Fo;c[h++]=Do},d=()=>{const v=this.#r;for(let N=0;N<v;N++)w()},I=v=>{if(this.#e===0)switch(jo[v>>4]){case-1:w();break;case 0:c[h++]=v;break;case 1:this.#t=v&31,(this.#t&30)===0?w():(this.#e=1,this.#r=1);break;case 2:this.#t=v&15,this.#e=2,this.#r=1;break;case 3:v&8?w():(this.#t=v&7,this.#e=3,this.#r=1);break}else{if((v&192)!==128||this.#r===1&&this.#e===2&&this.#t===0&&(v&32)===0||this.#e===3&&this.#t===0&&(v&48)===0)return d(),I(v);if(this.#t=this.#t<<6|v&63,this.#r++,--this.#e===0){if(this.ignoreBOM||!this.#n||this.#t!==Lo)if(this.#t<65536)c[h++]=this.#t;else{const N=this.#t-65536;c[h++]=N>>>10&1023|Co,c[h++]=N&1023|Po}this.#t=0,this.#r=0,this.#n=!1}}};for(const v of s)h>=l&&(i.push(String.fromCharCode.apply(null,c.subarray(0,h))),h=0),I(v);return n||(this.#n=!0,(this.#t||this.#e)&&d()),h>0&&i.push(String.fromCharCode.apply(null,c.subarray(0,h))),i.join("")}}function qo(t){let e=0;for(const r of t){const n=r.codePointAt(0);n<128?e++:n<2048?e+=2:n<65536?e+=3:e+=4}return e}class Ko{encoding=Vi;encode(e){if(!e)return zi;const r=new Uint8Array(qo(String(e)));return this.encodeInto(e,r),r}encodeInto(e,r){const n=String(e),s=n.length,i=r.length;let c=0,l=0;for(l=0;l<s;l++){const h=n.codePointAt(l);if(h<128){if(c>=i)break;r[c++]=h}else if(h<2048){if(c>=i-1)break;r[c++]=192|h>>6,r[c++]=128|h&63}else if(h<65536){if(c>=i-2)break;r[c++]=224|h>>12,r[c++]=128|h>>6&63,r[c++]=128|h&63}else{if(c>=i-3)break;r[c++]=240|h>>18,r[c++]=128|h>>12&63,r[c++]=128|h>>6&63,r[c++]=128|h&63,l++}}return{read:l,written:c}}}const Yi=z.SIMPLE_FLOAT<<5|te.TWO,Wo=z.SIMPLE_FLOAT<<5|te.FOUR,Ho=z.SIMPLE_FLOAT<<5|te.EIGHT,Go=z.SIMPLE_FLOAT<<5|gt.TRUE,Jo=z.SIMPLE_FLOAT<<5|gt.FALSE,zo=z.SIMPLE_FLOAT<<5|gt.UNDEFINED,Vo=z.SIMPLE_FLOAT<<5|gt.NULL,Yo=new TextEncoder,Qo=new Ko,Qi={...xr.defaultOptions,avoidInts:!1,cde:!1,collapseBigInts:!0,dateTag:oe.DATE_EPOCH,dcbor:!1,float64:!1,flushToZero:!1,forceEndian:null,ignoreOriginalEncoding:!1,largeNegativeAsBigInt:!1,reduceUnsafeNumbers:!1,rejectBigInts:!1,rejectCustomSimples:!1,rejectDuplicateKeys:!1,rejectFloats:!1,rejectUndefined:!1,simplifyNegativeZero:!1,sortKeys:null,stringNormalization:null,types:null,wtf8:!1,ignoreGlobalTags:!1},Xi={cde:!0,ignoreOriginalEncoding:!0,sortKeys:Li},Xo={...Xi,dcbor:!0,largeNegativeAsBigInt:!0,reduceUnsafeNumbers:!0,rejectCustomSimples:!0,rejectDuplicateKeys:!0,rejectUndefined:!0,simplifyNegativeZero:!0,stringNormalization:"NFC"};function Zi(t){const e=t<0;return typeof t=="bigint"?[e?-t-1n:t,e]:[e?-t-1:t,e]}function Sn(t,e,r){if(r.rejectFloats)throw new Error(`Attempt to encode an unwanted floating point number: ${t}`);if(isNaN(t))e.writeUint8(Yi),e.writeUint16(32256);else if(!r.float64&&Math.fround(t)===t){const n=Ji(t);n===null?(e.writeUint8(Wo),e.writeFloat32(t)):(e.writeUint8(Yi),e.writeUint16(n))}else e.writeUint8(Ho),e.writeFloat64(t)}function We(t,e,r){const[n,s]=Zi(t);if(s&&r)throw new TypeError(`Negative size: ${t}`);r??=s?z.NEG_INT:z.POS_INT,r<<=5,n<24?e.writeUint8(r|n):n<=255?(e.writeUint8(r|te.ONE),e.writeUint8(n)):n<=65535?(e.writeUint8(r|te.TWO),e.writeUint16(n)):n<=4294967295?(e.writeUint8(r|te.FOUR),e.writeUint32(n)):(e.writeUint8(r|te.EIGHT),e.writeBigUint64(BigInt(n)))}function ar(t,e,r){typeof t=="number"?We(t,e,z.TAG):typeof t=="object"&&!r.ignoreOriginalEncoding&&Fe.ENCODED in t?e.write(t[Fe.ENCODED]):t<=Number.MAX_SAFE_INTEGER?We(Number(t),e,z.TAG):(e.writeUint8(z.TAG<<5|te.EIGHT),e.writeBigUint64(BigInt(t)))}function es(t,e,r){const[n,s]=Zi(t);if(r.collapseBigInts&&(!r.largeNegativeAsBigInt||t>=-0x8000000000000000n)){if(n<=0xffffffffn){We(Number(t),e);return}if(n<=0xffffffffffffffffn){const w=(s?z.NEG_INT:z.POS_INT)<<5;e.writeUint8(w|te.EIGHT),e.writeBigUint64(n);return}}if(r.rejectBigInts)throw new Error(`Attempt to encode unwanted bigint: ${t}`);const i=s?oe.NEG_BIGINT:oe.POS_BIGINT,c=n.toString(16),l=c.length%2?"0":"";ar(i,e,r);const h=Mi(l+c);We(h.length,e,z.BYTE_STRING),e.write(h)}function Zo(t,e,r){r.flushToZero&&(t=No(t)),Object.is(t,-0)?r.simplifyNegativeZero?r.avoidInts?Sn(0,e,r):We(0,e):Sn(t,e,r):!r.avoidInts&&Number.isSafeInteger(t)?We(t,e):r.reduceUnsafeNumbers&&Math.floor(t)===t&&t>=_r.MIN&&t<=_r.MAX?es(BigInt(t),e,r):Sn(t,e,r)}function ea(t,e,r){const n=r.stringNormalization?t.normalize(r.stringNormalization):t;if(r.wtf8&&!t.isWellFormed()){const s=Qo.encode(n);ar(oe.WTF8,e,r),We(s.length,e,z.BYTE_STRING),e.write(s)}else{const s=Yo.encode(n);We(s.length,e,z.UTF8_STRING),e.write(s)}}function ta(t,e,r){const n=t;_n(n,n.length,z.ARRAY,e,r);for(const s of n)Nt(s,e,r)}function ra(t,e){We(t.length,e,z.BYTE_STRING),e.write(t)}const Br=new Ui;Br.registerEncoder(Array,ta),Br.registerEncoder(Uint8Array,ra);function Se(t,e){return Br.registerEncoder(t,e)}function _n(t,e,r,n,s){const i=_o(t);i&&!s.ignoreOriginalEncoding?n.write(i):We(e,n,r)}function na(t,e,r){if(t===null){e.writeUint8(Vo);return}if(!r.ignoreOriginalEncoding&&Fe.ENCODED in t){e.write(t[Fe.ENCODED]);return}const n=t.constructor;if(n){const i=r.types?.get(n)??(r.ignoreGlobalTags?void 0:Br.get(n));if(i){const c=i(t,e,r);if(c!==void 0){if(!Array.isArray(c)||c.length!==2)throw new Error("Invalid encoder return value");(typeof c[0]=="bigint"||isFinite(Number(c[0])))&&ar(c[0],e,r),Nt(c[1],e,r)}return}}if(typeof t.toCBOR=="function"){const i=t.toCBOR(e,r);i&&((typeof i[0]=="bigint"||isFinite(Number(i[0])))&&ar(i[0],e,r),Nt(i[1],e,r));return}if(typeof t.toJSON=="function"){Nt(t.toJSON(),e,r);return}const s=Object.entries(t).map(i=>[i[0],i[1],Kt(i[0],r)]);r.sortKeys&&s.sort(r.sortKeys),_n(t,s.length,z.MAP,e,r);for(const[i,c,l]of s)e.write(l),Nt(c,e,r)}function Nt(t,e,r){switch(typeof t){case"number":Zo(t,e,r);break;case"bigint":es(t,e,r);break;case"string":ea(t,e,r);break;case"boolean":e.writeUint8(t?Go:Jo);break;case"undefined":if(r.rejectUndefined)throw new Error("Attempt to encode unwanted undefined.");e.writeUint8(zo);break;case"object":na(t,e,r);break;case"symbol":throw new TypeError(`Unknown symbol: ${t.toString()}`);default:throw new TypeError(`Unknown type: ${typeof t}, ${String(t)}`)}}function Kt(t,e={}){const r={...Qi};e.dcbor?Object.assign(r,Xo):e.cde&&Object.assign(r,Xi),Object.assign(r,e);const n=new xr(r);return Nt(t,n,r),n.read()}var kr=(t=>(t[t.NEVER=-1]="NEVER",t[t.PREFERRED=0]="PREFERRED",t[t.ALWAYS=1]="ALWAYS",t))(kr||{});class nt{static KnownSimple=new Map([[gt.FALSE,!1],[gt.TRUE,!0],[gt.NULL,null],[gt.UNDEFINED,void 0]]);value;constructor(e){this.value=e}static create(e){return nt.KnownSimple.has(e)?nt.KnownSimple.get(e):new nt(e)}toCBOR(e,r){if(r.rejectCustomSimples)throw new Error(`Cannot encode non-standard Simple value: ${this.value}`);We(this.value,e,z.SIMPLE_FLOAT)}toString(){return`simple(${this.value})`}decode(){return nt.KnownSimple.has(this.value)?nt.KnownSimple.get(this.value):this}[Symbol.for("nodejs.util.inspect.custom")](e,r,n){return`simple(${n(this.value,r)})`}}const ia=new TextDecoder("utf8",{fatal:!0,ignoreBOM:!0});let Nr=class qs{static defaultOptions={maxDepth:1024,encoding:"hex",requirePreferred:!1};#e;#t;#r=0;#n;constructor(e,r){if(this.#n={...qs.defaultOptions,...r},typeof e=="string")switch(this.#n.encoding){case"hex":this.#e=Mi(e);break;case"base64":this.#e=mn(e);break;default:throw new TypeError(`Encoding not implemented: "${this.#n.encoding}"`)}else this.#e=e;this.#t=new DataView(this.#e.buffer,this.#e.byteOffset,this.#e.byteLength)}toHere(e){return gn(this.#e,e,this.#r)}*[Symbol.iterator](){if(yield*this.#i(0),this.#r!==this.#e.length)throw new Error("Extra data in input")}*seq(){for(;this.#r<this.#e.length;)yield*this.#i(0)}*#i(e){if(e++>this.#n.maxDepth)throw new Error(`Maximum depth ${this.#n.maxDepth} exceeded`);const r=this.#r,n=this.#t.getUint8(this.#r++),s=n>>5,i=n&31;let c=i,l=!1,h=0;switch(i){case te.ONE:if(h=1,c=this.#t.getUint8(this.#r),s===z.SIMPLE_FLOAT){if(c<32)throw new Error(`Invalid simple encoding in extra byte: ${c}`);l=!0}else if(this.#n.requirePreferred&&c<24)throw new Error(`Unexpectedly long integer encoding (1) for ${c}`);break;case te.TWO:if(h=2,s===z.SIMPLE_FLOAT)c=Gi(this.#e,this.#r);else if(c=this.#t.getUint16(this.#r,!1),this.#n.requirePreferred&&c<=255)throw new Error(`Unexpectedly long integer encoding (2) for ${c}`);break;case te.FOUR:if(h=4,s===z.SIMPLE_FLOAT)c=this.#t.getFloat32(this.#r,!1);else if(c=this.#t.getUint32(this.#r,!1),this.#n.requirePreferred&&c<=65535)throw new Error(`Unexpectedly long integer encoding (4) for ${c}`);break;case te.EIGHT:{if(h=8,s===z.SIMPLE_FLOAT)c=this.#t.getFloat64(this.#r,!1);else if(c=this.#t.getBigUint64(this.#r,!1),c<=Number.MAX_SAFE_INTEGER&&(c=Number(c)),this.#n.requirePreferred&&c<=4294967295)throw new Error(`Unexpectedly long integer encoding (8) for ${c}`);break}case 28:case 29:case 30:throw new Error(`Additional info not implemented: ${i}`);case te.INDEFINITE:switch(s){case z.POS_INT:case z.NEG_INT:case z.TAG:throw new Error(`Invalid indefinite encoding for MT ${s}`);case z.SIMPLE_FLOAT:yield[s,i,Fe.BREAK,r,0];return}c=1/0;break;default:l=!0}switch(this.#r+=h,s){case z.POS_INT:yield[s,i,c,r,h];break;case z.NEG_INT:yield[s,i,typeof c=="bigint"?-1n-c:-1-Number(c),r,h];break;case z.BYTE_STRING:c===1/0?yield*this.#c(s,e,r):yield[s,i,this.#s(c),r,c];break;case z.UTF8_STRING:c===1/0?yield*this.#c(s,e,r):yield[s,i,ia.decode(this.#s(c)),r,c];break;case z.ARRAY:if(c===1/0)yield*this.#c(s,e,r,!1);else{const w=Number(c);yield[s,i,w,r,h];for(let d=0;d<w;d++)yield*this.#i(e+1)}break;case z.MAP:if(c===1/0)yield*this.#c(s,e,r,!1);else{const w=Number(c);yield[s,i,w,r,h];for(let d=0;d<w;d++)yield*this.#i(e),yield*this.#i(e)}break;case z.TAG:yield[s,i,c,r,h],yield*this.#i(e);break;case z.SIMPLE_FLOAT:{const w=c;l&&(c=nt.create(Number(c))),yield[s,i,c,r,w];break}}}#s(e){const r=gn(this.#e,this.#r,this.#r+=e);if(r.length!==e)throw new Error(`Unexpected end of stream reading ${e} bytes, got ${r.length}`);return r}*#c(e,r,n,s=!0){for(yield[e,te.INDEFINITE,1/0,n,1/0];;){const i=this.#i(r),c=i.next(),[l,h,w]=c.value;if(w===Fe.BREAK){yield c.value,i.next();return}if(s){if(l!==e)throw new Error(`Unmatched major type. Expected ${e}, got ${l}.`);if(h===te.INDEFINITE)throw new Error("New stream started in typed stream")}yield c.value,yield*i}}};const sa=new Map([[te.ZERO,1],[te.ONE,2],[te.TWO,3],[te.FOUR,5],[te.EIGHT,9]]),oa=new Uint8Array(0);function aa(t,e){return!e.boxed&&!e.preferMap&&t.every(([r])=>typeof r=="string")?Object.fromEntries(t):new Map(t)}let Oe=class Ks{static defaultDecodeOptions={...Nr.defaultOptions,ParentType:Ks,boxed:!1,cde:!1,dcbor:!1,diagnosticSizes:kr.PREFERRED,collapseBigInts:!1,convertUnsafeIntsToFloat:!1,createObject:aa,keepNanPayloads:!1,pretty:!1,preferBigInt:!1,preferMap:!1,rejectLargeNegatives:!1,rejectBigInts:!1,rejectDuplicateKeys:!1,rejectFloats:!1,rejectInts:!1,rejectLongLoundNaN:!1,rejectLongFloats:!1,rejectNegativeZero:!1,rejectSimple:!1,rejectStreaming:!1,rejectStringsNotNormalizedAs:null,rejectSubnormals:!1,rejectUndefined:!1,rejectUnsafeFloatInts:!1,saveOriginal:!1,sortKeys:null,tags:null,ignoreGlobalTags:!1};static cdeDecodeOptions={cde:!0,rejectStreaming:!0,requirePreferred:!0,sortKeys:Li};static dcborDecodeOptions={...this.cdeDecodeOptions,dcbor:!0,convertUnsafeIntsToFloat:!0,rejectDuplicateKeys:!0,rejectLargeNegatives:!0,rejectLongLoundNaN:!0,rejectLongFloats:!0,rejectNegativeZero:!0,rejectSimple:!0,rejectUndefined:!0,rejectUnsafeFloatInts:!0,rejectStringsNotNormalizedAs:"NFC"};parent;mt;ai;left;offset;count=0;children=[];depth=0;#e;#t=null;constructor(e,r,n,s){if([this.mt,this.ai,,this.offset]=e,this.left=r,this.parent=n,this.#e=s,n&&(this.depth=n.depth+1),this.mt===z.MAP&&(this.#e.sortKeys||this.#e.rejectDuplicateKeys)&&(this.#t=[]),this.#e.rejectStreaming&&this.ai===te.INDEFINITE)throw new Error("Streaming not supported")}get isStreaming(){return this.left===1/0}get done(){return this.left===0}static create(e,r,n,s){const[i,c,l,h]=e;switch(i){case z.POS_INT:case z.NEG_INT:{if(n.rejectInts)throw new Error(`Unexpected integer: ${l}`);if(n.rejectLargeNegatives&&l<-0x8000000000000000n)throw new Error(`Invalid 65bit negative number: ${l}`);let w=l;return n.preferBigInt?w=BigInt(w):n.convertUnsafeIntsToFloat&&w>=_r.MIN&&w<=_r.MAX&&(w=Number(l)),n.boxed?nr(w,s.toHere(h)):w}case z.SIMPLE_FLOAT:if(c>te.ONE){if(typeof l=="symbol")return l;if(n.rejectFloats)throw new Error(`Decoding unwanted floating point number: ${l}`);if(n.rejectNegativeZero&&Object.is(l,-0))throw new Error("Decoding negative zero");if(isNaN(l)){const w=s.toHere(h),d=new ko(w);if(n.rejectLongLoundNaN){if(d.payload||w.length>3)throw new Error(`Invalid NaN encoding: "${De(w)}"`)}else if(n.keepNanPayloads&&(d.payload||d.sign===-1)){if(n.rejectLongFloats&&!d.isShortestEncoding)throw new Error(`NaN should have been encoded shorter: ${l}`);return d}}if(n.rejectSubnormals&&Mo(s.toHere(h+1)),n.rejectLongFloats){const w=Kt(l,{chunkSize:9,reduceUnsafeNumbers:n.rejectUnsafeFloatInts});if(w[0]>>5!==i)throw new Error(`Should have been encoded as int, not float: ${l}`);if(w.length<sa.get(c))throw new Error(`Number should have been encoded shorter: ${l}`)}if(typeof l=="number"&&n.boxed)return nr(l,s.toHere(h))}else{if(n.rejectSimple&&l instanceof nt)throw new Error(`Invalid simple value: ${l}`);if(n.rejectUndefined&&l===void 0)throw new Error("Unexpected undefined")}return l;case z.BYTE_STRING:case z.UTF8_STRING:if(l===1/0)return new n.ParentType(e,1/0,r,n);if(n.rejectStringsNotNormalizedAs&&typeof l=="string"){const w=l.normalize(n.rejectStringsNotNormalizedAs);if(l!==w)throw new Error(`String not normalized as "${n.rejectStringsNotNormalizedAs}", got [${Fi(l)}] instead of [${Fi(w)}]`)}return n.boxed?nr(l,s.toHere(h)):l;case z.ARRAY:return new n.ParentType(e,l,r,n);case z.MAP:return new n.ParentType(e,l*2,r,n);case z.TAG:{const w=new n.ParentType(e,1,r,n);return w.children=new ee(l),w}}throw new TypeError(`Invalid major type: ${i}`)}static decodeToEncodeOpts(e){return{...Qi,avoidInts:e.rejectInts,float64:!e.rejectLongFloats,flushToZero:e.rejectSubnormals,largeNegativeAsBigInt:e.rejectLargeNegatives,sortKeys:e.sortKeys}}push(e,r,n){if(this.children.push(e),this.#t){const s=Tr(e)||r.toHere(n);this.#t.push(s)}return--this.left}replaceLast(e,r,n){let s,i=-1/0;if(this.children instanceof ee?(i=0,s=this.children.contents,this.children.contents=e):(i=this.children.length-1,s=this.children[i],this.children[i]=e),this.#t){const c=Tr(e)||n.toHere(r.offset);this.#t[i]=c}return s}convert(e){let r;switch(this.mt){case z.ARRAY:r=this.children;break;case z.MAP:{const n=this.#r();if(this.#e.sortKeys){let s;for(const i of n){if(s&&this.#e.sortKeys(s,i)>=0)throw new Error(`Duplicate or out of order key: "0x${i[2]}"`);s=i}}else if(this.#e.rejectDuplicateKeys){const s=new Set;for(const[i,c,l]of n){const h=De(l);if(s.has(h))throw new Error(`Duplicate key: "0x${h}"`);s.add(h)}}r=this.#e.createObject(n,this.#e);break}case z.BYTE_STRING:return vo(this.children);case z.UTF8_STRING:{const n=this.children.join("");r=this.#e.boxed?nr(n,e.toHere(this.offset)):n;break}case z.TAG:r=this.children.decode(this.#e);break;default:throw new TypeError(`Invalid mt on convert: ${this.mt}`)}return this.#e.saveOriginal&&r&&typeof r=="object"&&rr(r,e.toHere(this.offset)),r}#r(){const e=this.children,r=e.length;if(r%2)throw new Error("Missing map value");const n=new Array(r/2);if(this.#t)for(let s=0;s<r;s+=2)n[s>>1]=[e[s],e[s+1],this.#t[s]];else for(let s=0;s<r;s+=2)n[s>>1]=[e[s],e[s+1],oa];return n}};const Tn=" ",ca=new TextEncoder;class ts extends Oe{close="";quote='"';get isEmptyStream(){return(this.mt===z.UTF8_STRING||this.mt===z.BYTE_STRING)&&this.count===0}}function mt(t,e,r,n){let s="";if(e===te.INDEFINITE)s+="_";else{if(n.diagnosticSizes===kr.NEVER)return"";{let i=n.diagnosticSizes===kr.ALWAYS;if(!i){let c=te.ZERO;if(Object.is(r,-0))c=te.TWO;else if(t===z.POS_INT||t===z.NEG_INT){const l=r<0,h=typeof r=="bigint"?1n:1,w=l?-r-h:r;w<=23?c=Number(w):w<=255?c=te.ONE:w<=65535?c=te.TWO:w<=4294967295?c=te.FOUR:c=te.EIGHT}else isFinite(r)?Math.fround(r)===r?Ji(r)==null?c=te.FOUR:c=te.TWO:c=te.EIGHT:c=te.TWO;i=c!==e}i&&(s+="_",e<te.ONE?s+="i":s+=String(e-24))}}return s}function ua(t,e){const r={...Oe.defaultDecodeOptions,...e,ParentType:ts},n=new Nr(t,r);let s,i,c="";for(const l of n){const[h,w,d]=l;switch(s&&(s.count>0&&d!==Fe.BREAK&&(s.mt===z.MAP&&s.count%2?c+=": ":(c+=",",r.pretty||(c+=" "))),r.pretty&&(s.mt!==z.MAP||s.count%2===0)&&(c+=`
3
- ${Tn.repeat(s.depth+1)}`)),i=Oe.create(l,s,r,n),h){case z.POS_INT:case z.NEG_INT:c+=String(d),c+=mt(h,w,d,r);break;case z.SIMPLE_FLOAT:if(d!==Fe.BREAK)if(typeof d=="number"){const I=Object.is(d,-0)?"-0.0":String(d);c+=I,isFinite(d)&&!/[.e]/.test(I)&&(c+=".0"),c+=mt(h,w,d,r)}else d instanceof nt?(c+="simple(",c+=String(d.value),c+=mt(z.POS_INT,w,d.value,r),c+=")"):c+=String(d);break;case z.BYTE_STRING:d===1/0?(c+="(_ ",i.close=")",i.quote="'"):(c+="h'",c+=De(d),c+="'",c+=mt(z.POS_INT,w,d.length,r));break;case z.UTF8_STRING:d===1/0?(c+="(_ ",i.close=")"):(c+=JSON.stringify(d),c+=mt(z.POS_INT,w,ca.encode(d).length,r));break;case z.ARRAY:{c+="[";const I=mt(z.POS_INT,w,d,r);c+=I,I&&(c+=" "),r.pretty&&d?i.close=`
4
- ${Tn.repeat(i.depth)}]`:i.close="]";break}case z.MAP:{c+="{";const I=mt(z.POS_INT,w,d,r);c+=I,I&&(c+=" "),r.pretty&&d?i.close=`
5
- ${Tn.repeat(i.depth)}}`:i.close="}";break}case z.TAG:c+=String(d),c+=mt(z.POS_INT,w,d,r),c+="(",i.close=")";break}if(i===Fe.BREAK)if(s?.isStreaming)s.left=0;else throw new Error("Unexpected BREAK");else s&&(s.count++,s.left--);for(i instanceof ts&&(s=i);s?.done;){if(s.isEmptyStream)c=c.slice(0,-3),c+=`${s.quote}${s.quote}_`;else{if(s.mt===z.MAP&&s.count%2!==0)throw new Error(`Odd streaming map size: ${s.count}`);c+=s.close}s=s.parent}}return c}const fa=new TextDecoder;class vn extends Oe{depth=0;leaf=!1;value;length;[Fe.ENCODED];constructor(e,r,n,s){super(e,r,n,s),this.parent?this.depth=this.parent.depth+1:this.depth=s.initialDepth,[,,this.value,,this.length]=e}numBytes(){switch(this.ai){case te.ONE:return 1;case te.TWO:return 2;case te.FOUR:return 4;case te.EIGHT:return 8}return 0}}function rs(t){return t instanceof vn}function Mr(t,e){return t===1/0?"Indefinite":e?`${t} ${e}${t!==1&&t!==1n?"s":""}`:String(t)}function cr(t){return"".padStart(t," ")}function ns(t,e,r){let n="";n+=cr(t.depth*2);const s=Tr(t);n+=De(s.subarray(0,1));const i=t.numBytes();i&&(n+=" ",n+=De(s.subarray(1,i+1))),n=n.padEnd(e.minCol+1," "),n+="-- ",r!==void 0&&(n+=cr(t.depth*2),r!==""&&(n+=`[${r}] `));let c=!1;const[l]=t.children;switch(t.mt){case z.POS_INT:n+=`Unsigned: ${l}`,typeof l=="bigint"&&(n+="n");break;case z.NEG_INT:n+=`Negative: ${l}`,typeof l=="bigint"&&(n+="n");break;case z.BYTE_STRING:n+=`Bytes (Length: ${Mr(t.length)})`;break;case z.UTF8_STRING:n+=`UTF8 (Length: ${Mr(t.length)})`,t.length!==1/0&&(n+=`: ${JSON.stringify(l)}`);break;case z.ARRAY:n+=`Array (Length: ${Mr(t.value,"item")})`;break;case z.MAP:n+=`Map (Length: ${Mr(t.value,"pair")})`;break;case z.TAG:{n+=`Tag #${t.value}`;const h=t.children,[w]=h.contents.children,d=new ee(h.tag,w);rr(d,s);const I=d.comment(e,t.depth);I&&(n+=": ",n+=I),c||=d.noChildren;break}case z.SIMPLE_FLOAT:l===Fe.BREAK?n+="BREAK":t.ai>te.ONE?Object.is(l,-0)?n+="Float: -0":n+=`Float: ${l}`:(n+="Simple: ",l instanceof nt?n+=l.value:n+=l);break}if(!c)if(t.leaf){if(n+=`
6
- `,s.length>i+1){const h=cr((t.depth+1)*2),w=vr(s);if(w?.length){w.sort((I,v)=>I[0]-v[0]||v[1]-I[1]);let d=0;for(const[I,v,N]of w)if(!(I<d)){if(d=I+v,N==="<<"){n+=cr(e.minCol+1),n+="--",n+=h,n+="<< ";const F=gn(s,I,I+v),$=vr(F);if($){const j=$.findIndex(([_,A,R])=>_===0&&A===v&&R==="<<");j>=0&&$.splice(j,1)}n+=ua(F),n+=` >>
7
- `,n+=is(F,{initialDepth:t.depth+1,minCol:e.minCol,noPrefixHex:!0});continue}else N==="'"&&(n+=cr(e.minCol+1),n+="--",n+=h,n+="'",n+=fa.decode(s.subarray(I,I+v)),n+=`'
8
- `);if(I>i)for(let F=I;F<I+v;F+=8){const $=Math.min(F+8,I+v);n+=h,n+=De(s.subarray(F,$)),n+=`
9
- `}}}else for(let d=i+1;d<s.length;d+=8)n+=h,n+=De(s.subarray(d,d+8)),n+=`
1
+ (function(et,Qt){typeof exports=="object"&&typeof module<"u"?module.exports=Qt():typeof define=="function"&&define.amd?define(Qt):(et=typeof globalThis<"u"?globalThis:et||self,et.MQTTp=Qt())})(this,(function(){"use strict";var et=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Qt(t){if(Object.prototype.hasOwnProperty.call(t,"__esModule"))return t;var e=t.default;if(typeof e=="function"){var r=function n(){var s=!1;try{s=this instanceof n}catch{}return s?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};r.prototype=e.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(t).forEach(function(n){var s=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(r,n,s.get?s:{enumerable:!0,get:function(){return t[n]}})}),r}var dr={exports:{}},On;function pr(){if(On)return dr.exports;On=1;var t=typeof Reflect=="object"?Reflect:null,e=t&&typeof t.apply=="function"?t.apply:function(T,F,M){return Function.prototype.apply.call(T,F,M)},r;t&&typeof t.ownKeys=="function"?r=t.ownKeys:Object.getOwnPropertySymbols?r=function(T){return Object.getOwnPropertyNames(T).concat(Object.getOwnPropertySymbols(T))}:r=function(T){return Object.getOwnPropertyNames(T)};function n(S){console&&console.warn&&console.warn(S)}var s=Number.isNaN||function(T){return T!==T};function i(){i.init.call(this)}dr.exports=i,dr.exports.once=_,i.EventEmitter=i,i.prototype._events=void 0,i.prototype._eventsCount=0,i.prototype._maxListeners=void 0;var c=10;function l(S){if(typeof S!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof S)}Object.defineProperty(i,"defaultMaxListeners",{enumerable:!0,get:function(){return c},set:function(S){if(typeof S!="number"||S<0||s(S))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+S+".");c=S}}),i.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},i.prototype.setMaxListeners=function(T){if(typeof T!="number"||T<0||s(T))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+T+".");return this._maxListeners=T,this};function h(S){return S._maxListeners===void 0?i.defaultMaxListeners:S._maxListeners}i.prototype.getMaxListeners=function(){return h(this)},i.prototype.emit=function(T){for(var F=[],M=1;M<arguments.length;M++)F.push(arguments[M]);var L=T==="error",W=this._events;if(W!==void 0)L=L&&W.error===void 0;else if(!L)return!1;if(L){var J;if(F.length>0&&(J=F[0]),J instanceof Error)throw J;var Q=new Error("Unhandled error."+(J?" ("+J.message+")":""));throw Q.context=J,Q}var N=W[T];if(N===void 0)return!1;if(typeof N=="function")e(N,this,F);else for(var V=N.length,ie=U(N,V),M=0;M<V;++M)e(ie[M],this,F);return!0};function w(S,T,F,M){var L,W,J;if(l(F),W=S._events,W===void 0?(W=S._events=Object.create(null),S._eventsCount=0):(W.newListener!==void 0&&(S.emit("newListener",T,F.listener?F.listener:F),W=S._events),J=W[T]),J===void 0)J=W[T]=F,++S._eventsCount;else if(typeof J=="function"?J=W[T]=M?[F,J]:[J,F]:M?J.unshift(F):J.push(F),L=h(S),L>0&&J.length>L&&!J.warned){J.warned=!0;var Q=new Error("Possible EventEmitter memory leak detected. "+J.length+" "+String(T)+" listeners added. Use emitter.setMaxListeners() to increase limit");Q.name="MaxListenersExceededWarning",Q.emitter=S,Q.type=T,Q.count=J.length,n(Q)}return S}i.prototype.addListener=function(T,F){return w(this,T,F,!1)},i.prototype.on=i.prototype.addListener,i.prototype.prependListener=function(T,F){return w(this,T,F,!0)};function d(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function I(S,T,F){var M={fired:!1,wrapFn:void 0,target:S,type:T,listener:F},L=d.bind(M);return L.listener=F,M.wrapFn=L,L}i.prototype.once=function(T,F){return l(F),this.on(T,I(this,T,F)),this},i.prototype.prependOnceListener=function(T,F){return l(F),this.prependListener(T,I(this,T,F)),this},i.prototype.removeListener=function(T,F){var M,L,W,J,Q;if(l(F),L=this._events,L===void 0)return this;if(M=L[T],M===void 0)return this;if(M===F||M.listener===F)--this._eventsCount===0?this._events=Object.create(null):(delete L[T],L.removeListener&&this.emit("removeListener",T,M.listener||F));else if(typeof M!="function"){for(W=-1,J=M.length-1;J>=0;J--)if(M[J]===F||M[J].listener===F){Q=M[J].listener,W=J;break}if(W<0)return this;W===0?M.shift():$(M,W),M.length===1&&(L[T]=M[0]),L.removeListener!==void 0&&this.emit("removeListener",T,Q||F)}return this},i.prototype.off=i.prototype.removeListener,i.prototype.removeAllListeners=function(T){var F,M,L;if(M=this._events,M===void 0)return this;if(M.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):M[T]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete M[T]),this;if(arguments.length===0){var W=Object.keys(M),J;for(L=0;L<W.length;++L)J=W[L],J!=="removeListener"&&this.removeAllListeners(J);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(F=M[T],typeof F=="function")this.removeListener(T,F);else if(F!==void 0)for(L=F.length-1;L>=0;L--)this.removeListener(T,F[L]);return this};function v(S,T,F){var M=S._events;if(M===void 0)return[];var L=M[T];return L===void 0?[]:typeof L=="function"?F?[L.listener||L]:[L]:F?q(L):U(L,L.length)}i.prototype.listeners=function(T){return v(this,T,!0)},i.prototype.rawListeners=function(T){return v(this,T,!1)},i.listenerCount=function(S,T){return typeof S.listenerCount=="function"?S.listenerCount(T):k.call(S,T)},i.prototype.listenerCount=k;function k(S){var T=this._events;if(T!==void 0){var F=T[S];if(typeof F=="function")return 1;if(F!==void 0)return F.length}return 0}i.prototype.eventNames=function(){return this._eventsCount>0?r(this._events):[]};function U(S,T){for(var F=new Array(T),M=0;M<T;++M)F[M]=S[M];return F}function $(S,T){for(;T+1<S.length;T++)S[T]=S[T+1];S.pop()}function q(S){for(var T=new Array(S.length),F=0;F<T.length;++F)T[F]=S[F].listener||S[F];return T}function _(S,T){return new Promise(function(F,M){function L(J){S.removeListener(T,W),M(J)}function W(){typeof S.removeListener=="function"&&S.removeListener("error",L),F([].slice.call(arguments))}R(S,T,W,{once:!0}),T!=="error"&&A(S,L,{once:!0})})}function A(S,T,F){typeof S.on=="function"&&R(S,"error",T,F)}function R(S,T,F,M){if(typeof S.on=="function")M.once?S.once(T,F):S.on(T,F);else if(typeof S.addEventListener=="function")S.addEventListener(T,function L(W){M.once&&S.removeEventListener(T,L),F(W)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof S)}return dr.exports}var yr={exports:{}},Cn;function Mt(){return Cn||(Cn=1,typeof Object.create=="function"?yr.exports=function(e,r){r&&(e.super_=r,e.prototype=Object.create(r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}))}:yr.exports=function(e,r){if(r){e.super_=r;var n=function(){};n.prototype=r.prototype,e.prototype=new n,e.prototype.constructor=e}}),yr.exports}function Ks(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var $n={exports:{}},Ae=$n.exports={},tt,rt;function qr(){throw new Error("setTimeout has not been defined")}function jr(){throw new Error("clearTimeout has not been defined")}(function(){try{typeof setTimeout=="function"?tt=setTimeout:tt=qr}catch{tt=qr}try{typeof clearTimeout=="function"?rt=clearTimeout:rt=jr}catch{rt=jr}})();function qn(t){if(tt===setTimeout)return setTimeout(t,0);if((tt===qr||!tt)&&setTimeout)return tt=setTimeout,setTimeout(t,0);try{return tt(t,0)}catch{try{return tt.call(null,t,0)}catch{return tt.call(this,t,0)}}}function Ws(t){if(rt===clearTimeout)return clearTimeout(t);if((rt===jr||!rt)&&clearTimeout)return rt=clearTimeout,clearTimeout(t);try{return rt(t)}catch{try{return rt.call(null,t)}catch{return rt.call(this,t)}}}var ht=[],Pt=!1,Rt,wr=-1;function Hs(){!Pt||!Rt||(Pt=!1,Rt.length?ht=Rt.concat(ht):wr=-1,ht.length&&jn())}function jn(){if(!Pt){var t=qn(Hs);Pt=!0;for(var e=ht.length;e;){for(Rt=ht,ht=[];++wr<e;)Rt&&Rt[wr].run();wr=-1,e=ht.length}Rt=null,Pt=!1,Ws(t)}}Ae.nextTick=function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)e[r-1]=arguments[r];ht.push(new Kn(t,e)),ht.length===1&&!Pt&&qn(jn)};function Kn(t,e){this.fun=t,this.array=e}Kn.prototype.run=function(){this.fun.apply(null,this.array)},Ae.title="browser",Ae.browser=!0,Ae.env={},Ae.argv=[],Ae.version="",Ae.versions={};function dt(){}Ae.on=dt,Ae.addListener=dt,Ae.once=dt,Ae.off=dt,Ae.removeListener=dt,Ae.removeAllListeners=dt,Ae.emit=dt,Ae.prependListener=dt,Ae.prependOnceListener=dt,Ae.listeners=function(t){return[]},Ae.binding=function(t){throw new Error("process.binding is not supported")},Ae.cwd=function(){return"/"},Ae.chdir=function(t){throw new Error("process.chdir is not supported")},Ae.umask=function(){return 0};var Gs=$n.exports;const he=Ks(Gs);var Kr,Wn;function Hn(){return Wn||(Wn=1,Kr=pr().EventEmitter),Kr}var Wr={},Gn;function gr(){return Gn||(Gn=1,(function(t){Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var e={},r={};r.byteLength=d,r.toByteArray=v,r.fromByteArray=$;for(var n=[],s=[],i=typeof Uint8Array<"u"?Uint8Array:Array,c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",l=0,h=c.length;l<h;++l)n[l]=c[l],s[c.charCodeAt(l)]=l;s[45]=62,s[95]=63;function w(A){var R=A.length;if(R%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var S=A.indexOf("=");S===-1&&(S=R);var T=S===R?0:4-S%4;return[S,T]}function d(A){var R=w(A),S=R[0],T=R[1];return(S+T)*3/4-T}function I(A,R,S){return(R+S)*3/4-S}function v(A){var R,S=w(A),T=S[0],F=S[1],M=new i(I(A,T,F)),L=0,W=F>0?T-4:T,J;for(J=0;J<W;J+=4)R=s[A.charCodeAt(J)]<<18|s[A.charCodeAt(J+1)]<<12|s[A.charCodeAt(J+2)]<<6|s[A.charCodeAt(J+3)],M[L++]=R>>16&255,M[L++]=R>>8&255,M[L++]=R&255;return F===2&&(R=s[A.charCodeAt(J)]<<2|s[A.charCodeAt(J+1)]>>4,M[L++]=R&255),F===1&&(R=s[A.charCodeAt(J)]<<10|s[A.charCodeAt(J+1)]<<4|s[A.charCodeAt(J+2)]>>2,M[L++]=R>>8&255,M[L++]=R&255),M}function k(A){return n[A>>18&63]+n[A>>12&63]+n[A>>6&63]+n[A&63]}function U(A,R,S){for(var T,F=[],M=R;M<S;M+=3)T=(A[M]<<16&16711680)+(A[M+1]<<8&65280)+(A[M+2]&255),F.push(k(T));return F.join("")}function $(A){for(var R,S=A.length,T=S%3,F=[],M=16383,L=0,W=S-T;L<W;L+=M)F.push(U(A,L,L+M>W?W:L+M));return T===1?(R=A[S-1],F.push(n[R>>2]+n[R<<4&63]+"==")):T===2&&(R=(A[S-2]<<8)+A[S-1],F.push(n[R>>10]+n[R>>4&63]+n[R<<2&63]+"=")),F.join("")}var q={};q.read=function(A,R,S,T,F){var M,L,W=F*8-T-1,J=(1<<W)-1,Q=J>>1,N=-7,V=S?F-1:0,ie=S?-1:1,fe=A[R+V];for(V+=ie,M=fe&(1<<-N)-1,fe>>=-N,N+=W;N>0;M=M*256+A[R+V],V+=ie,N-=8);for(L=M&(1<<-N)-1,M>>=-N,N+=T;N>0;L=L*256+A[R+V],V+=ie,N-=8);if(M===0)M=1-Q;else{if(M===J)return L?NaN:(fe?-1:1)*(1/0);L=L+Math.pow(2,T),M=M-Q}return(fe?-1:1)*L*Math.pow(2,M-T)},q.write=function(A,R,S,T,F,M){var L,W,J,Q=M*8-F-1,N=(1<<Q)-1,V=N>>1,ie=F===23?Math.pow(2,-24)-Math.pow(2,-77):0,fe=T?0:M-1,Re=T?1:-1,Te=R<0||R===0&&1/R<0?1:0;for(R=Math.abs(R),isNaN(R)||R===1/0?(W=isNaN(R)?1:0,L=N):(L=Math.floor(Math.log(R)/Math.LN2),R*(J=Math.pow(2,-L))<1&&(L--,J*=2),L+V>=1?R+=ie/J:R+=ie*Math.pow(2,1-V),R*J>=2&&(L++,J/=2),L+V>=N?(W=0,L=N):L+V>=1?(W=(R*J-1)*Math.pow(2,F),L=L+V):(W=R*Math.pow(2,V-1)*Math.pow(2,F),L=0));F>=8;A[S+fe]=W&255,fe+=Re,W/=256,F-=8);for(L=L<<F|W,Q+=F;Q>0;A[S+fe]=L&255,fe+=Re,L/=256,Q-=8);A[S+fe-Re]|=Te*128};(function(A){const R=r,S=q,T=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;A.Buffer=N,A.SlowBuffer=Qe,A.INSPECT_MAX_BYTES=50;const F=2147483647;A.kMaxLength=F;const{Uint8Array:M,ArrayBuffer:L,SharedArrayBuffer:W}=globalThis;N.TYPED_ARRAY_SUPPORT=J(),!N.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function J(){try{const y=new M(1),a={foo:function(){return 42}};return Object.setPrototypeOf(a,M.prototype),Object.setPrototypeOf(y,a),y.foo()===42}catch{return!1}}Object.defineProperty(N.prototype,"parent",{enumerable:!0,get:function(){if(N.isBuffer(this))return this.buffer}}),Object.defineProperty(N.prototype,"offset",{enumerable:!0,get:function(){if(N.isBuffer(this))return this.byteOffset}});function Q(y){if(y>F)throw new RangeError('The value "'+y+'" is invalid for option "size"');const a=new M(y);return Object.setPrototypeOf(a,N.prototype),a}function N(y,a,f){if(typeof y=="number"){if(typeof a=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return Re(y)}return V(y,a,f)}N.poolSize=8192;function V(y,a,f){if(typeof y=="string")return Te(y,a);if(L.isView(y))return Ge(y);if(y==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof y);if(lt(y,L)||y&&lt(y.buffer,L)||typeof W<"u"&&(lt(y,W)||y&&lt(y.buffer,W)))return ct(y,a,f);if(typeof y=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const m=y.valueOf&&y.valueOf();if(m!=null&&m!==y)return N.from(m,a,f);const B=Lt(y);if(B)return B;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof y[Symbol.toPrimitive]=="function")return N.from(y[Symbol.toPrimitive]("string"),a,f);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof y)}N.from=function(y,a,f){return V(y,a,f)},Object.setPrototypeOf(N.prototype,M.prototype),Object.setPrototypeOf(N,M);function ie(y){if(typeof y!="number")throw new TypeError('"size" argument must be of type number');if(y<0)throw new RangeError('The value "'+y+'" is invalid for option "size"')}function fe(y,a,f){return ie(y),y<=0?Q(y):a!==void 0?typeof f=="string"?Q(y).fill(a,f):Q(y).fill(a):Q(y)}N.alloc=function(y,a,f){return fe(y,a,f)};function Re(y){return ie(y),Q(y<0?0:ut(y)|0)}N.allocUnsafe=function(y){return Re(y)},N.allocUnsafeSlow=function(y){return Re(y)};function Te(y,a){if((typeof a!="string"||a==="")&&(a="utf8"),!N.isEncoding(a))throw new TypeError("Unknown encoding: "+a);const f=we(y,a)|0;let m=Q(f);const B=m.write(y,a);return B!==f&&(m=m.slice(0,B)),m}function Pe(y){const a=y.length<0?0:ut(y.length)|0,f=Q(a);for(let m=0;m<a;m+=1)f[m]=y[m]&255;return f}function Ge(y){if(lt(y,M)){const a=new M(y);return ct(a.buffer,a.byteOffset,a.byteLength)}return Pe(y)}function ct(y,a,f){if(a<0||y.byteLength<a)throw new RangeError('"offset" is outside of buffer bounds');if(y.byteLength<a+(f||0))throw new RangeError('"length" is outside of buffer bounds');let m;return a===void 0&&f===void 0?m=new M(y):f===void 0?m=new M(y,a):m=new M(y,a,f),Object.setPrototypeOf(m,N.prototype),m}function Lt(y){if(N.isBuffer(y)){const a=ut(y.length)|0,f=Q(a);return f.length===0||y.copy(f,0,0,a),f}if(y.length!==void 0)return typeof y.length!="number"||Dn(y.length)?Q(0):Pe(y);if(y.type==="Buffer"&&Array.isArray(y.data))return Pe(y.data)}function ut(y){if(y>=F)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+F.toString(16)+" bytes");return y|0}function Qe(y){return+y!=y&&(y=0),N.alloc(+y)}N.isBuffer=function(a){return a!=null&&a._isBuffer===!0&&a!==N.prototype},N.compare=function(a,f){if(lt(a,M)&&(a=N.from(a,a.offset,a.byteLength)),lt(f,M)&&(f=N.from(f,f.offset,f.byteLength)),!N.isBuffer(a)||!N.isBuffer(f))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(a===f)return 0;let m=a.length,B=f.length;for(let C=0,K=Math.min(m,B);C<K;++C)if(a[C]!==f[C]){m=a[C],B=f[C];break}return m<B?-1:B<m?1:0},N.isEncoding=function(a){switch(String(a).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},N.concat=function(a,f){if(!Array.isArray(a))throw new TypeError('"list" argument must be an Array of Buffers');if(a.length===0)return N.alloc(0);let m;if(f===void 0)for(f=0,m=0;m<a.length;++m)f+=a[m].length;const B=N.allocUnsafe(f);let C=0;for(m=0;m<a.length;++m){let K=a[m];if(lt(K,M))C+K.length>B.length?(N.isBuffer(K)||(K=N.from(K)),K.copy(B,C)):M.prototype.set.call(B,K,C);else if(N.isBuffer(K))K.copy(B,C);else throw new TypeError('"list" argument must be an Array of Buffers');C+=K.length}return B};function we(y,a){if(N.isBuffer(y))return y.length;if(L.isView(y)||lt(y,L))return y.byteLength;if(typeof y!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof y);const f=y.length,m=arguments.length>2&&arguments[2]===!0;if(!m&&f===0)return 0;let B=!1;for(;;)switch(a){case"ascii":case"latin1":case"binary":return f;case"utf8":case"utf-8":return pe(y).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return f*2;case"hex":return f>>>1;case"base64":return ue(y).length;default:if(B)return m?-1:pe(y).length;a=(""+a).toLowerCase(),B=!0}}N.byteLength=we;function Be(y,a,f){let m=!1;if((a===void 0||a<0)&&(a=0),a>this.length||((f===void 0||f>this.length)&&(f=this.length),f<=0)||(f>>>=0,a>>>=0,f<=a))return"";for(y||(y="utf8");;)switch(y){case"hex":return vt(this,a,f);case"utf8":case"utf-8":return le(this,a,f);case"ascii":return ft(this,a,f);case"latin1":case"binary":return Tt(this,a,f);case"base64":return Y(this,a,f);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return hr(this,a,f);default:if(m)throw new TypeError("Unknown encoding: "+y);y=(y+"").toLowerCase(),m=!0}}N.prototype._isBuffer=!0;function D(y,a,f){const m=y[a];y[a]=y[f],y[f]=m}N.prototype.swap16=function(){const a=this.length;if(a%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let f=0;f<a;f+=2)D(this,f,f+1);return this},N.prototype.swap32=function(){const a=this.length;if(a%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let f=0;f<a;f+=4)D(this,f,f+3),D(this,f+1,f+2);return this},N.prototype.swap64=function(){const a=this.length;if(a%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let f=0;f<a;f+=8)D(this,f,f+7),D(this,f+1,f+6),D(this,f+2,f+5),D(this,f+3,f+4);return this},N.prototype.toString=function(){const a=this.length;return a===0?"":arguments.length===0?le(this,0,a):Be.apply(this,arguments)},N.prototype.toLocaleString=N.prototype.toString,N.prototype.equals=function(a){if(!N.isBuffer(a))throw new TypeError("Argument must be a Buffer");return this===a?!0:N.compare(this,a)===0},N.prototype.inspect=function(){let a="";const f=A.INSPECT_MAX_BYTES;return a=this.toString("hex",0,f).replace(/(.{2})/g,"$1 ").trim(),this.length>f&&(a+=" ... "),"<Buffer "+a+">"},T&&(N.prototype[T]=N.prototype.inspect),N.prototype.compare=function(a,f,m,B,C){if(lt(a,M)&&(a=N.from(a,a.offset,a.byteLength)),!N.isBuffer(a))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof a);if(f===void 0&&(f=0),m===void 0&&(m=a?a.length:0),B===void 0&&(B=0),C===void 0&&(C=this.length),f<0||m>a.length||B<0||C>this.length)throw new RangeError("out of range index");if(B>=C&&f>=m)return 0;if(B>=C)return-1;if(f>=m)return 1;if(f>>>=0,m>>>=0,B>>>=0,C>>>=0,this===a)return 0;let K=C-B,se=m-f;const ve=Math.min(K,se),me=this.slice(B,C),xe=a.slice(f,m);for(let de=0;de<ve;++de)if(me[de]!==xe[de]){K=me[de],se=xe[de];break}return K<se?-1:se<K?1:0};function P(y,a,f,m,B){if(y.length===0)return-1;if(typeof f=="string"?(m=f,f=0):f>2147483647?f=2147483647:f<-2147483648&&(f=-2147483648),f=+f,Dn(f)&&(f=B?0:y.length-1),f<0&&(f=y.length+f),f>=y.length){if(B)return-1;f=y.length-1}else if(f<0)if(B)f=0;else return-1;if(typeof a=="string"&&(a=N.from(a,m)),N.isBuffer(a))return a.length===0?-1:G(y,a,f,m,B);if(typeof a=="number")return a=a&255,typeof M.prototype.indexOf=="function"?B?M.prototype.indexOf.call(y,a,f):M.prototype.lastIndexOf.call(y,a,f):G(y,[a],f,m,B);throw new TypeError("val must be string, number or Buffer")}function G(y,a,f,m,B){let C=1,K=y.length,se=a.length;if(m!==void 0&&(m=String(m).toLowerCase(),m==="ucs2"||m==="ucs-2"||m==="utf16le"||m==="utf-16le")){if(y.length<2||a.length<2)return-1;C=2,K/=2,se/=2,f/=2}function ve(xe,de){return C===1?xe[de]:xe.readUInt16BE(de*C)}let me;if(B){let xe=-1;for(me=f;me<K;me++)if(ve(y,me)===ve(a,xe===-1?0:me-xe)){if(xe===-1&&(xe=me),me-xe+1===se)return xe*C}else xe!==-1&&(me-=me-xe),xe=-1}else for(f+se>K&&(f=K-se),me=f;me>=0;me--){let xe=!0;for(let de=0;de<se;de++)if(ve(y,me+de)!==ve(a,de)){xe=!1;break}if(xe)return me}return-1}N.prototype.includes=function(a,f,m){return this.indexOf(a,f,m)!==-1},N.prototype.indexOf=function(a,f,m){return P(this,a,f,m,!0)},N.prototype.lastIndexOf=function(a,f,m){return P(this,a,f,m,!1)};function X(y,a,f,m){f=Number(f)||0;const B=y.length-f;m?(m=Number(m),m>B&&(m=B)):m=B;const C=a.length;m>C/2&&(m=C/2);let K;for(K=0;K<m;++K){const se=parseInt(a.substr(K*2,2),16);if(Dn(se))return K;y[f+K]=se}return K}function re(y,a,f,m){return Cr(pe(a,y.length-f),y,f,m)}function b(y,a,f,m){return Cr(ye(a),y,f,m)}function E(y,a,f,m){return Cr(ue(a),y,f,m)}function H(y,a,f,m){return Cr(ge(a,y.length-f),y,f,m)}N.prototype.write=function(a,f,m,B){if(f===void 0)B="utf8",m=this.length,f=0;else if(m===void 0&&typeof f=="string")B=f,m=this.length,f=0;else if(isFinite(f))f=f>>>0,isFinite(m)?(m=m>>>0,B===void 0&&(B="utf8")):(B=m,m=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const C=this.length-f;if((m===void 0||m>C)&&(m=C),a.length>0&&(m<0||f<0)||f>this.length)throw new RangeError("Attempt to write outside buffer bounds");B||(B="utf8");let K=!1;for(;;)switch(B){case"hex":return X(this,a,f,m);case"utf8":case"utf-8":return re(this,a,f,m);case"ascii":case"latin1":case"binary":return b(this,a,f,m);case"base64":return E(this,a,f,m);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return H(this,a,f,m);default:if(K)throw new TypeError("Unknown encoding: "+B);B=(""+B).toLowerCase(),K=!0}},N.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function Y(y,a,f){return a===0&&f===y.length?R.fromByteArray(y):R.fromByteArray(y.slice(a,f))}function le(y,a,f){f=Math.min(y.length,f);const m=[];let B=a;for(;B<f;){const C=y[B];let K=null,se=C>239?4:C>223?3:C>191?2:1;if(B+se<=f){let ve,me,xe,de;switch(se){case 1:C<128&&(K=C);break;case 2:ve=y[B+1],(ve&192)===128&&(de=(C&31)<<6|ve&63,de>127&&(K=de));break;case 3:ve=y[B+1],me=y[B+2],(ve&192)===128&&(me&192)===128&&(de=(C&15)<<12|(ve&63)<<6|me&63,de>2047&&(de<55296||de>57343)&&(K=de));break;case 4:ve=y[B+1],me=y[B+2],xe=y[B+3],(ve&192)===128&&(me&192)===128&&(xe&192)===128&&(de=(C&15)<<18|(ve&63)<<12|(me&63)<<6|xe&63,de>65535&&de<1114112&&(K=de))}}K===null?(K=65533,se=1):K>65535&&(K-=65536,m.push(K>>>10&1023|55296),K=56320|K&1023),m.push(K),B+=se}return ae(m)}const Z=4096;function ae(y){const a=y.length;if(a<=Z)return String.fromCharCode.apply(String,y);let f="",m=0;for(;m<a;)f+=String.fromCharCode.apply(String,y.slice(m,m+=Z));return f}function ft(y,a,f){let m="";f=Math.min(y.length,f);for(let B=a;B<f;++B)m+=String.fromCharCode(y[B]&127);return m}function Tt(y,a,f){let m="";f=Math.min(y.length,f);for(let B=a;B<f;++B)m+=String.fromCharCode(y[B]);return m}function vt(y,a,f){const m=y.length;(!a||a<0)&&(a=0),(!f||f<0||f>m)&&(f=m);let B="";for(let C=a;C<f;++C)B+=Bc[y[C]];return B}function hr(y,a,f){const m=y.slice(a,f);let B="";for(let C=0;C<m.length-1;C+=2)B+=String.fromCharCode(m[C]+m[C+1]*256);return B}N.prototype.slice=function(a,f){const m=this.length;a=~~a,f=f===void 0?m:~~f,a<0?(a+=m,a<0&&(a=0)):a>m&&(a=m),f<0?(f+=m,f<0&&(f=0)):f>m&&(f=m),f<a&&(f=a);const B=this.subarray(a,f);return Object.setPrototypeOf(B,N.prototype),B};function Ee(y,a,f){if(y%1!==0||y<0)throw new RangeError("offset is not uint");if(y+a>f)throw new RangeError("Trying to access beyond buffer length")}N.prototype.readUintLE=N.prototype.readUIntLE=function(a,f,m){a=a>>>0,f=f>>>0,m||Ee(a,f,this.length);let B=this[a],C=1,K=0;for(;++K<f&&(C*=256);)B+=this[a+K]*C;return B},N.prototype.readUintBE=N.prototype.readUIntBE=function(a,f,m){a=a>>>0,f=f>>>0,m||Ee(a,f,this.length);let B=this[a+--f],C=1;for(;f>0&&(C*=256);)B+=this[a+--f]*C;return B},N.prototype.readUint8=N.prototype.readUInt8=function(a,f){return a=a>>>0,f||Ee(a,1,this.length),this[a]},N.prototype.readUint16LE=N.prototype.readUInt16LE=function(a,f){return a=a>>>0,f||Ee(a,2,this.length),this[a]|this[a+1]<<8},N.prototype.readUint16BE=N.prototype.readUInt16BE=function(a,f){return a=a>>>0,f||Ee(a,2,this.length),this[a]<<8|this[a+1]},N.prototype.readUint32LE=N.prototype.readUInt32LE=function(a,f){return a=a>>>0,f||Ee(a,4,this.length),(this[a]|this[a+1]<<8|this[a+2]<<16)+this[a+3]*16777216},N.prototype.readUint32BE=N.prototype.readUInt32BE=function(a,f){return a=a>>>0,f||Ee(a,4,this.length),this[a]*16777216+(this[a+1]<<16|this[a+2]<<8|this[a+3])},N.prototype.readBigUInt64LE=At(function(a){a=a>>>0,x(a,"offset");const f=this[a],m=this[a+7];(f===void 0||m===void 0)&&O(a,this.length-8);const B=f+this[++a]*2**8+this[++a]*2**16+this[++a]*2**24,C=this[++a]+this[++a]*2**8+this[++a]*2**16+m*2**24;return BigInt(B)+(BigInt(C)<<BigInt(32))}),N.prototype.readBigUInt64BE=At(function(a){a=a>>>0,x(a,"offset");const f=this[a],m=this[a+7];(f===void 0||m===void 0)&&O(a,this.length-8);const B=f*2**24+this[++a]*2**16+this[++a]*2**8+this[++a],C=this[++a]*2**24+this[++a]*2**16+this[++a]*2**8+m;return(BigInt(B)<<BigInt(32))+BigInt(C)}),N.prototype.readIntLE=function(a,f,m){a=a>>>0,f=f>>>0,m||Ee(a,f,this.length);let B=this[a],C=1,K=0;for(;++K<f&&(C*=256);)B+=this[a+K]*C;return C*=128,B>=C&&(B-=Math.pow(2,8*f)),B},N.prototype.readIntBE=function(a,f,m){a=a>>>0,f=f>>>0,m||Ee(a,f,this.length);let B=f,C=1,K=this[a+--B];for(;B>0&&(C*=256);)K+=this[a+--B]*C;return C*=128,K>=C&&(K-=Math.pow(2,8*f)),K},N.prototype.readInt8=function(a,f){return a=a>>>0,f||Ee(a,1,this.length),this[a]&128?(255-this[a]+1)*-1:this[a]},N.prototype.readInt16LE=function(a,f){a=a>>>0,f||Ee(a,2,this.length);const m=this[a]|this[a+1]<<8;return m&32768?m|4294901760:m},N.prototype.readInt16BE=function(a,f){a=a>>>0,f||Ee(a,2,this.length);const m=this[a+1]|this[a]<<8;return m&32768?m|4294901760:m},N.prototype.readInt32LE=function(a,f){return a=a>>>0,f||Ee(a,4,this.length),this[a]|this[a+1]<<8|this[a+2]<<16|this[a+3]<<24},N.prototype.readInt32BE=function(a,f){return a=a>>>0,f||Ee(a,4,this.length),this[a]<<24|this[a+1]<<16|this[a+2]<<8|this[a+3]},N.prototype.readBigInt64LE=At(function(a){a=a>>>0,x(a,"offset");const f=this[a],m=this[a+7];(f===void 0||m===void 0)&&O(a,this.length-8);const B=this[a+4]+this[a+5]*2**8+this[a+6]*2**16+(m<<24);return(BigInt(B)<<BigInt(32))+BigInt(f+this[++a]*2**8+this[++a]*2**16+this[++a]*2**24)}),N.prototype.readBigInt64BE=At(function(a){a=a>>>0,x(a,"offset");const f=this[a],m=this[a+7];(f===void 0||m===void 0)&&O(a,this.length-8);const B=(f<<24)+this[++a]*2**16+this[++a]*2**8+this[++a];return(BigInt(B)<<BigInt(32))+BigInt(this[++a]*2**24+this[++a]*2**16+this[++a]*2**8+m)}),N.prototype.readFloatLE=function(a,f){return a=a>>>0,f||Ee(a,4,this.length),S.read(this,a,!0,23,4)},N.prototype.readFloatBE=function(a,f){return a=a>>>0,f||Ee(a,4,this.length),S.read(this,a,!1,23,4)},N.prototype.readDoubleLE=function(a,f){return a=a>>>0,f||Ee(a,8,this.length),S.read(this,a,!0,52,8)},N.prototype.readDoubleBE=function(a,f){return a=a>>>0,f||Ee(a,8,this.length),S.read(this,a,!1,52,8)};function Ie(y,a,f,m,B,C){if(!N.isBuffer(y))throw new TypeError('"buffer" argument must be a Buffer instance');if(a>B||a<C)throw new RangeError('"value" argument is out of bounds');if(f+m>y.length)throw new RangeError("Index out of range")}N.prototype.writeUintLE=N.prototype.writeUIntLE=function(a,f,m,B){if(a=+a,f=f>>>0,m=m>>>0,!B){const se=Math.pow(2,8*m)-1;Ie(this,a,f,m,se,0)}let C=1,K=0;for(this[f]=a&255;++K<m&&(C*=256);)this[f+K]=a/C&255;return f+m},N.prototype.writeUintBE=N.prototype.writeUIntBE=function(a,f,m,B){if(a=+a,f=f>>>0,m=m>>>0,!B){const se=Math.pow(2,8*m)-1;Ie(this,a,f,m,se,0)}let C=m-1,K=1;for(this[f+C]=a&255;--C>=0&&(K*=256);)this[f+C]=a/K&255;return f+m},N.prototype.writeUint8=N.prototype.writeUInt8=function(a,f,m){return a=+a,f=f>>>0,m||Ie(this,a,f,1,255,0),this[f]=a&255,f+1},N.prototype.writeUint16LE=N.prototype.writeUInt16LE=function(a,f,m){return a=+a,f=f>>>0,m||Ie(this,a,f,2,65535,0),this[f]=a&255,this[f+1]=a>>>8,f+2},N.prototype.writeUint16BE=N.prototype.writeUInt16BE=function(a,f,m){return a=+a,f=f>>>0,m||Ie(this,a,f,2,65535,0),this[f]=a>>>8,this[f+1]=a&255,f+2},N.prototype.writeUint32LE=N.prototype.writeUInt32LE=function(a,f,m){return a=+a,f=f>>>0,m||Ie(this,a,f,4,4294967295,0),this[f+3]=a>>>24,this[f+2]=a>>>16,this[f+1]=a>>>8,this[f]=a&255,f+4},N.prototype.writeUint32BE=N.prototype.writeUInt32BE=function(a,f,m){return a=+a,f=f>>>0,m||Ie(this,a,f,4,4294967295,0),this[f]=a>>>24,this[f+1]=a>>>16,this[f+2]=a>>>8,this[f+3]=a&255,f+4};function Xe(y,a,f,m,B){g(a,m,B,y,f,7);let C=Number(a&BigInt(4294967295));y[f++]=C,C=C>>8,y[f++]=C,C=C>>8,y[f++]=C,C=C>>8,y[f++]=C;let K=Number(a>>BigInt(32)&BigInt(4294967295));return y[f++]=K,K=K>>8,y[f++]=K,K=K>>8,y[f++]=K,K=K>>8,y[f++]=K,f}function Fe(y,a,f,m,B){g(a,m,B,y,f,7);let C=Number(a&BigInt(4294967295));y[f+7]=C,C=C>>8,y[f+6]=C,C=C>>8,y[f+5]=C,C=C>>8,y[f+4]=C;let K=Number(a>>BigInt(32)&BigInt(4294967295));return y[f+3]=K,K=K>>8,y[f+2]=K,K=K>>8,y[f+1]=K,K=K>>8,y[f]=K,f+8}N.prototype.writeBigUInt64LE=At(function(a,f=0){return Xe(this,a,f,BigInt(0),BigInt("0xffffffffffffffff"))}),N.prototype.writeBigUInt64BE=At(function(a,f=0){return Fe(this,a,f,BigInt(0),BigInt("0xffffffffffffffff"))}),N.prototype.writeIntLE=function(a,f,m,B){if(a=+a,f=f>>>0,!B){const ve=Math.pow(2,8*m-1);Ie(this,a,f,m,ve-1,-ve)}let C=0,K=1,se=0;for(this[f]=a&255;++C<m&&(K*=256);)a<0&&se===0&&this[f+C-1]!==0&&(se=1),this[f+C]=(a/K>>0)-se&255;return f+m},N.prototype.writeIntBE=function(a,f,m,B){if(a=+a,f=f>>>0,!B){const ve=Math.pow(2,8*m-1);Ie(this,a,f,m,ve-1,-ve)}let C=m-1,K=1,se=0;for(this[f+C]=a&255;--C>=0&&(K*=256);)a<0&&se===0&&this[f+C+1]!==0&&(se=1),this[f+C]=(a/K>>0)-se&255;return f+m},N.prototype.writeInt8=function(a,f,m){return a=+a,f=f>>>0,m||Ie(this,a,f,1,127,-128),a<0&&(a=255+a+1),this[f]=a&255,f+1},N.prototype.writeInt16LE=function(a,f,m){return a=+a,f=f>>>0,m||Ie(this,a,f,2,32767,-32768),this[f]=a&255,this[f+1]=a>>>8,f+2},N.prototype.writeInt16BE=function(a,f,m){return a=+a,f=f>>>0,m||Ie(this,a,f,2,32767,-32768),this[f]=a>>>8,this[f+1]=a&255,f+2},N.prototype.writeInt32LE=function(a,f,m){return a=+a,f=f>>>0,m||Ie(this,a,f,4,2147483647,-2147483648),this[f]=a&255,this[f+1]=a>>>8,this[f+2]=a>>>16,this[f+3]=a>>>24,f+4},N.prototype.writeInt32BE=function(a,f,m){return a=+a,f=f>>>0,m||Ie(this,a,f,4,2147483647,-2147483648),a<0&&(a=4294967295+a+1),this[f]=a>>>24,this[f+1]=a>>>16,this[f+2]=a>>>8,this[f+3]=a&255,f+4},N.prototype.writeBigInt64LE=At(function(a,f=0){return Xe(this,a,f,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),N.prototype.writeBigInt64BE=At(function(a,f=0){return Fe(this,a,f,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function Je(y,a,f,m,B,C){if(f+m>y.length)throw new RangeError("Index out of range");if(f<0)throw new RangeError("Index out of range")}function Ze(y,a,f,m,B){return a=+a,f=f>>>0,B||Je(y,a,f,4),S.write(y,a,f,m,23,4),f+4}N.prototype.writeFloatLE=function(a,f,m){return Ze(this,a,f,!0,m)},N.prototype.writeFloatBE=function(a,f,m){return Ze(this,a,f,!1,m)};function ke(y,a,f,m,B){return a=+a,f=f>>>0,B||Je(y,a,f,8),S.write(y,a,f,m,52,8),f+8}N.prototype.writeDoubleLE=function(a,f,m){return ke(this,a,f,!0,m)},N.prototype.writeDoubleBE=function(a,f,m){return ke(this,a,f,!1,m)},N.prototype.copy=function(a,f,m,B){if(!N.isBuffer(a))throw new TypeError("argument should be a Buffer");if(m||(m=0),!B&&B!==0&&(B=this.length),f>=a.length&&(f=a.length),f||(f=0),B>0&&B<m&&(B=m),B===m||a.length===0||this.length===0)return 0;if(f<0)throw new RangeError("targetStart out of bounds");if(m<0||m>=this.length)throw new RangeError("Index out of range");if(B<0)throw new RangeError("sourceEnd out of bounds");B>this.length&&(B=this.length),a.length-f<B-m&&(B=a.length-f+m);const C=B-m;return this===a&&typeof M.prototype.copyWithin=="function"?this.copyWithin(f,m,B):M.prototype.set.call(a,this.subarray(m,B),f),C},N.prototype.fill=function(a,f,m,B){if(typeof a=="string"){if(typeof f=="string"?(B=f,f=0,m=this.length):typeof m=="string"&&(B=m,m=this.length),B!==void 0&&typeof B!="string")throw new TypeError("encoding must be a string");if(typeof B=="string"&&!N.isEncoding(B))throw new TypeError("Unknown encoding: "+B);if(a.length===1){const K=a.charCodeAt(0);(B==="utf8"&&K<128||B==="latin1")&&(a=K)}}else typeof a=="number"?a=a&255:typeof a=="boolean"&&(a=Number(a));if(f<0||this.length<f||this.length<m)throw new RangeError("Out of range index");if(m<=f)return this;f=f>>>0,m=m===void 0?this.length:m>>>0,a||(a=0);let C;if(typeof a=="number")for(C=f;C<m;++C)this[C]=a;else{const K=N.isBuffer(a)?a:N.from(a,B),se=K.length;if(se===0)throw new TypeError('The value "'+a+'" is invalid for argument "value"');for(C=0;C<m-f;++C)this[C+f]=K[C%se]}return this};const xt={};function p(y,a,f){xt[y]=class extends f{constructor(){super(),Object.defineProperty(this,"message",{value:a.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${y}]`,this.stack,delete this.name}get code(){return y}set code(B){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:B,writable:!0})}toString(){return`${this.name} [${y}]: ${this.message}`}}}p("ERR_BUFFER_OUT_OF_BOUNDS",function(y){return y?`${y} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),p("ERR_INVALID_ARG_TYPE",function(y,a){return`The "${y}" argument must be of type number. Received type ${typeof a}`},TypeError),p("ERR_OUT_OF_RANGE",function(y,a,f){let m=`The value of "${y}" is out of range.`,B=f;return Number.isInteger(f)&&Math.abs(f)>2**32?B=o(String(f)):typeof f=="bigint"&&(B=String(f),(f>BigInt(2)**BigInt(32)||f<-(BigInt(2)**BigInt(32)))&&(B=o(B)),B+="n"),m+=` It must be ${a}. Received ${B}`,m},RangeError);function o(y){let a="",f=y.length;const m=y[0]==="-"?1:0;for(;f>=m+4;f-=3)a=`_${y.slice(f-3,f)}${a}`;return`${y.slice(0,f)}${a}`}function u(y,a,f){x(a,"offset"),(y[a]===void 0||y[a+f]===void 0)&&O(a,y.length-(f+1))}function g(y,a,f,m,B,C){if(y>f||y<a){const K=typeof a=="bigint"?"n":"";let se;throw a===0||a===BigInt(0)?se=`>= 0${K} and < 2${K} ** ${(C+1)*8}${K}`:se=`>= -(2${K} ** ${(C+1)*8-1}${K}) and < 2 ** ${(C+1)*8-1}${K}`,new xt.ERR_OUT_OF_RANGE("value",se,y)}u(m,B,C)}function x(y,a){if(typeof y!="number")throw new xt.ERR_INVALID_ARG_TYPE(a,"number",y)}function O(y,a,f){throw Math.floor(y)!==y?(x(y,f),new xt.ERR_OUT_OF_RANGE("offset","an integer",y)):a<0?new xt.ERR_BUFFER_OUT_OF_BOUNDS:new xt.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${a}`,y)}const j=/[^+/0-9A-Za-z-_]/g;function ne(y){if(y=y.split("=")[0],y=y.trim().replace(j,""),y.length<2)return"";for(;y.length%4!==0;)y=y+"=";return y}function pe(y,a){a=a||1/0;let f;const m=y.length;let B=null;const C=[];for(let K=0;K<m;++K){if(f=y.charCodeAt(K),f>55295&&f<57344){if(!B){if(f>56319){(a-=3)>-1&&C.push(239,191,189);continue}else if(K+1===m){(a-=3)>-1&&C.push(239,191,189);continue}B=f;continue}if(f<56320){(a-=3)>-1&&C.push(239,191,189),B=f;continue}f=(B-55296<<10|f-56320)+65536}else B&&(a-=3)>-1&&C.push(239,191,189);if(B=null,f<128){if((a-=1)<0)break;C.push(f)}else if(f<2048){if((a-=2)<0)break;C.push(f>>6|192,f&63|128)}else if(f<65536){if((a-=3)<0)break;C.push(f>>12|224,f>>6&63|128,f&63|128)}else if(f<1114112){if((a-=4)<0)break;C.push(f>>18|240,f>>12&63|128,f>>6&63|128,f&63|128)}else throw new Error("Invalid code point")}return C}function ye(y){const a=[];for(let f=0;f<y.length;++f)a.push(y.charCodeAt(f)&255);return a}function ge(y,a){let f,m,B;const C=[];for(let K=0;K<y.length&&!((a-=2)<0);++K)f=y.charCodeAt(K),m=f>>8,B=f%256,C.push(B),C.push(m);return C}function ue(y){return R.toByteArray(ne(y))}function Cr(y,a,f,m){let B;for(B=0;B<m&&!(B+f>=a.length||B>=y.length);++B)a[B+f]=y[B];return B}function lt(y,a){return y instanceof a||y!=null&&y.constructor!=null&&y.constructor.name!=null&&y.constructor.name===a.name}function Dn(y){return y!==y}const Bc=(function(){const y="0123456789abcdef",a=new Array(256);for(let f=0;f<16;++f){const m=f*16;for(let B=0;B<16;++B)a[m+B]=y[f]+y[B]}return a})();function At(y){return typeof BigInt>"u"?Nc:y}function Nc(){throw new Error("BigInt not supported")}})(e);const _=e.Buffer;t.Blob=e.Blob,t.BlobOptions=e.BlobOptions,t.Buffer=e.Buffer,t.File=e.File,t.FileOptions=e.FileOptions,t.INSPECT_MAX_BYTES=e.INSPECT_MAX_BYTES,t.SlowBuffer=e.SlowBuffer,t.TranscodeEncoding=e.TranscodeEncoding,t.atob=e.atob,t.btoa=e.btoa,t.constants=e.constants,t.default=_,t.isAscii=e.isAscii,t.isUtf8=e.isUtf8,t.kMaxLength=e.kMaxLength,t.kStringMaxLength=e.kStringMaxLength,t.resolveObjectURL=e.resolveObjectURL,t.transcode=e.transcode})(Wr)),Wr}const Jn=Qt(Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"})));var Hr,zn;function Js(){if(zn)return Hr;zn=1;function t(U,$){var q=Object.keys(U);if(Object.getOwnPropertySymbols){var _=Object.getOwnPropertySymbols(U);$&&(_=_.filter(function(A){return Object.getOwnPropertyDescriptor(U,A).enumerable})),q.push.apply(q,_)}return q}function e(U){for(var $=1;$<arguments.length;$++){var q=arguments[$]!=null?arguments[$]:{};$%2?t(Object(q),!0).forEach(function(_){r(U,_,q[_])}):Object.getOwnPropertyDescriptors?Object.defineProperties(U,Object.getOwnPropertyDescriptors(q)):t(Object(q)).forEach(function(_){Object.defineProperty(U,_,Object.getOwnPropertyDescriptor(q,_))})}return U}function r(U,$,q){return $=c($),$ in U?Object.defineProperty(U,$,{value:q,enumerable:!0,configurable:!0,writable:!0}):U[$]=q,U}function n(U,$){if(!(U instanceof $))throw new TypeError("Cannot call a class as a function")}function s(U,$){for(var q=0;q<$.length;q++){var _=$[q];_.enumerable=_.enumerable||!1,_.configurable=!0,"value"in _&&(_.writable=!0),Object.defineProperty(U,c(_.key),_)}}function i(U,$,q){return $&&s(U.prototype,$),Object.defineProperty(U,"prototype",{writable:!1}),U}function c(U){var $=l(U,"string");return typeof $=="symbol"?$:String($)}function l(U,$){if(typeof U!="object"||U===null)return U;var q=U[Symbol.toPrimitive];if(q!==void 0){var _=q.call(U,$);if(typeof _!="object")return _;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(U)}var h=gr(),w=h.Buffer,d=Jn,I=d.inspect,v=I&&I.custom||"inspect";function k(U,$,q){w.prototype.copy.call(U,$,q)}return Hr=(function(){function U(){n(this,U),this.head=null,this.tail=null,this.length=0}return i(U,[{key:"push",value:function(q){var _={data:q,next:null};this.length>0?this.tail.next=_:this.head=_,this.tail=_,++this.length}},{key:"unshift",value:function(q){var _={data:q,next:this.head};this.length===0&&(this.tail=_),this.head=_,++this.length}},{key:"shift",value:function(){if(this.length!==0){var q=this.head.data;return this.length===1?this.head=this.tail=null:this.head=this.head.next,--this.length,q}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0}},{key:"join",value:function(q){if(this.length===0)return"";for(var _=this.head,A=""+_.data;_=_.next;)A+=q+_.data;return A}},{key:"concat",value:function(q){if(this.length===0)return w.alloc(0);for(var _=w.allocUnsafe(q>>>0),A=this.head,R=0;A;)k(A.data,_,R),R+=A.data.length,A=A.next;return _}},{key:"consume",value:function(q,_){var A;return q<this.head.data.length?(A=this.head.data.slice(0,q),this.head.data=this.head.data.slice(q)):q===this.head.data.length?A=this.shift():A=_?this._getString(q):this._getBuffer(q),A}},{key:"first",value:function(){return this.head.data}},{key:"_getString",value:function(q){var _=this.head,A=1,R=_.data;for(q-=R.length;_=_.next;){var S=_.data,T=q>S.length?S.length:q;if(T===S.length?R+=S:R+=S.slice(0,q),q-=T,q===0){T===S.length?(++A,_.next?this.head=_.next:this.head=this.tail=null):(this.head=_,_.data=S.slice(T));break}++A}return this.length-=A,R}},{key:"_getBuffer",value:function(q){var _=w.allocUnsafe(q),A=this.head,R=1;for(A.data.copy(_),q-=A.data.length;A=A.next;){var S=A.data,T=q>S.length?S.length:q;if(S.copy(_,_.length-q,0,T),q-=T,q===0){T===S.length?(++R,A.next?this.head=A.next:this.head=this.tail=null):(this.head=A,A.data=S.slice(T));break}++R}return this.length-=R,_}},{key:v,value:function(q,_){return I(this,e(e({},_),{},{depth:0,customInspect:!1}))}}]),U})(),Hr}var Gr,Vn;function Yn(){if(Vn)return Gr;Vn=1;function t(c,l){var h=this,w=this._readableState&&this._readableState.destroyed,d=this._writableState&&this._writableState.destroyed;return w||d?(l?l(c):c&&(this._writableState?this._writableState.errorEmitted||(this._writableState.errorEmitted=!0,he.nextTick(s,this,c)):he.nextTick(s,this,c)),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(c||null,function(I){!l&&I?h._writableState?h._writableState.errorEmitted?he.nextTick(r,h):(h._writableState.errorEmitted=!0,he.nextTick(e,h,I)):he.nextTick(e,h,I):l?(he.nextTick(r,h),l(I)):he.nextTick(r,h)}),this)}function e(c,l){s(c,l),r(c)}function r(c){c._writableState&&!c._writableState.emitClose||c._readableState&&!c._readableState.emitClose||c.emit("close")}function n(){this._readableState&&(this._readableState.destroyed=!1,this._readableState.reading=!1,this._readableState.ended=!1,this._readableState.endEmitted=!1),this._writableState&&(this._writableState.destroyed=!1,this._writableState.ended=!1,this._writableState.ending=!1,this._writableState.finalCalled=!1,this._writableState.prefinished=!1,this._writableState.finished=!1,this._writableState.errorEmitted=!1)}function s(c,l){c.emit("error",l)}function i(c,l){var h=c._readableState,w=c._writableState;h&&h.autoDestroy||w&&w.autoDestroy?c.destroy(l):c.emit("error",l)}return Gr={destroy:t,undestroy:n,errorOrDestroy:i},Gr}var Jr={},Qn;function Dt(){if(Qn)return Jr;Qn=1;function t(l,h){l.prototype=Object.create(h.prototype),l.prototype.constructor=l,l.__proto__=h}var e={};function r(l,h,w){w||(w=Error);function d(v,k,U){return typeof h=="string"?h:h(v,k,U)}var I=(function(v){t(k,v);function k(U,$,q){return v.call(this,d(U,$,q))||this}return k})(w);I.prototype.name=w.name,I.prototype.code=l,e[l]=I}function n(l,h){if(Array.isArray(l)){var w=l.length;return l=l.map(function(d){return String(d)}),w>2?"one of ".concat(h," ").concat(l.slice(0,w-1).join(", "),", or ")+l[w-1]:w===2?"one of ".concat(h," ").concat(l[0]," or ").concat(l[1]):"of ".concat(h," ").concat(l[0])}else return"of ".concat(h," ").concat(String(l))}function s(l,h,w){return l.substr(0,h.length)===h}function i(l,h,w){return(w===void 0||w>l.length)&&(w=l.length),l.substring(w-h.length,w)===h}function c(l,h,w){return typeof w!="number"&&(w=0),w+h.length>l.length?!1:l.indexOf(h,w)!==-1}return r("ERR_INVALID_OPT_VALUE",function(l,h){return'The value "'+h+'" is invalid for option "'+l+'"'},TypeError),r("ERR_INVALID_ARG_TYPE",function(l,h,w){var d;typeof h=="string"&&s(h,"not ")?(d="must not be",h=h.replace(/^not /,"")):d="must be";var I;if(i(l," argument"))I="The ".concat(l," ").concat(d," ").concat(n(h,"type"));else{var v=c(l,".")?"property":"argument";I='The "'.concat(l,'" ').concat(v," ").concat(d," ").concat(n(h,"type"))}return I+=". Received type ".concat(typeof w),I},TypeError),r("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF"),r("ERR_METHOD_NOT_IMPLEMENTED",function(l){return"The "+l+" method is not implemented"}),r("ERR_STREAM_PREMATURE_CLOSE","Premature close"),r("ERR_STREAM_DESTROYED",function(l){return"Cannot call "+l+" after a stream was destroyed"}),r("ERR_MULTIPLE_CALLBACK","Callback called multiple times"),r("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable"),r("ERR_STREAM_WRITE_AFTER_END","write after end"),r("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError),r("ERR_UNKNOWN_ENCODING",function(l){return"Unknown encoding: "+l},TypeError),r("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event"),Jr.codes=e,Jr}var zr,Xn;function Zn(){if(Xn)return zr;Xn=1;var t=Dt().codes.ERR_INVALID_OPT_VALUE;function e(n,s,i){return n.highWaterMark!=null?n.highWaterMark:s?n[i]:null}function r(n,s,i,c){var l=e(s,c,i);if(l!=null){if(!(isFinite(l)&&Math.floor(l)===l)||l<0){var h=c?i:"highWaterMark";throw new t(h,l)}return Math.floor(l)}return n.objectMode?16:16*1024}return zr={getHighWaterMark:r},zr}var Vr,ei;function zs(){if(ei)return Vr;ei=1,Vr=t;function t(r,n){if(e("noDeprecation"))return r;var s=!1;function i(){if(!s){if(e("throwDeprecation"))throw new Error(n);e("traceDeprecation")?console.trace(n):console.warn(n),s=!0}return r.apply(this,arguments)}return i}function e(r){try{if(!et.localStorage)return!1}catch{return!1}var n=et.localStorage[r];return n==null?!1:String(n).toLowerCase()==="true"}return Vr}var Yr,ti;function ri(){if(ti)return Yr;ti=1,Yr=L;function t(D){var P=this;this.next=null,this.entry=null,this.finish=function(){Be(P,D)}}var e;L.WritableState=F;var r={deprecate:zs()},n=Hn(),s=gr().Buffer,i=(typeof et<"u"?et:typeof window<"u"?window:typeof self<"u"?self:{}).Uint8Array||function(){};function c(D){return s.from(D)}function l(D){return s.isBuffer(D)||D instanceof i}var h=Yn(),w=Zn(),d=w.getHighWaterMark,I=Dt().codes,v=I.ERR_INVALID_ARG_TYPE,k=I.ERR_METHOD_NOT_IMPLEMENTED,U=I.ERR_MULTIPLE_CALLBACK,$=I.ERR_STREAM_CANNOT_PIPE,q=I.ERR_STREAM_DESTROYED,_=I.ERR_STREAM_NULL_VALUES,A=I.ERR_STREAM_WRITE_AFTER_END,R=I.ERR_UNKNOWN_ENCODING,S=h.errorOrDestroy;Mt()(L,n);function T(){}function F(D,P,G){e=e||Ot(),D=D||{},typeof G!="boolean"&&(G=P instanceof e),this.objectMode=!!D.objectMode,G&&(this.objectMode=this.objectMode||!!D.writableObjectMode),this.highWaterMark=d(this,D,"writableHighWaterMark",G),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var X=D.decodeStrings===!1;this.decodeStrings=!X,this.defaultEncoding=D.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(re){Re(P,re)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=D.emitClose!==!1,this.autoDestroy=!!D.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new t(this)}F.prototype.getBuffer=function(){for(var P=this.bufferedRequest,G=[];P;)G.push(P),P=P.next;return G},(function(){try{Object.defineProperty(F.prototype,"buffer",{get:r.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch{}})();var M;typeof Symbol=="function"&&Symbol.hasInstance&&typeof Function.prototype[Symbol.hasInstance]=="function"?(M=Function.prototype[Symbol.hasInstance],Object.defineProperty(L,Symbol.hasInstance,{value:function(P){return M.call(this,P)?!0:this!==L?!1:P&&P._writableState instanceof F}})):M=function(P){return P instanceof this};function L(D){e=e||Ot();var P=this instanceof e;if(!P&&!M.call(L,this))return new L(D);this._writableState=new F(D,this,P),this.writable=!0,D&&(typeof D.write=="function"&&(this._write=D.write),typeof D.writev=="function"&&(this._writev=D.writev),typeof D.destroy=="function"&&(this._destroy=D.destroy),typeof D.final=="function"&&(this._final=D.final)),n.call(this)}L.prototype.pipe=function(){S(this,new $)};function W(D,P){var G=new A;S(D,G),he.nextTick(P,G)}function J(D,P,G,X){var re;return G===null?re=new _:typeof G!="string"&&!P.objectMode&&(re=new v("chunk",["string","Buffer"],G)),re?(S(D,re),he.nextTick(X,re),!1):!0}L.prototype.write=function(D,P,G){var X=this._writableState,re=!1,b=!X.objectMode&&l(D);return b&&!s.isBuffer(D)&&(D=c(D)),typeof P=="function"&&(G=P,P=null),b?P="buffer":P||(P=X.defaultEncoding),typeof G!="function"&&(G=T),X.ending?W(this,G):(b||J(this,X,D,G))&&(X.pendingcb++,re=N(this,X,b,D,P,G)),re},L.prototype.cork=function(){this._writableState.corked++},L.prototype.uncork=function(){var D=this._writableState;D.corked&&(D.corked--,!D.writing&&!D.corked&&!D.bufferProcessing&&D.bufferedRequest&&Ge(this,D))},L.prototype.setDefaultEncoding=function(P){if(typeof P=="string"&&(P=P.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((P+"").toLowerCase())>-1))throw new R(P);return this._writableState.defaultEncoding=P,this},Object.defineProperty(L.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}});function Q(D,P,G){return!D.objectMode&&D.decodeStrings!==!1&&typeof P=="string"&&(P=s.from(P,G)),P}Object.defineProperty(L.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}});function N(D,P,G,X,re,b){if(!G){var E=Q(P,X,re);X!==E&&(G=!0,re="buffer",X=E)}var H=P.objectMode?1:X.length;P.length+=H;var Y=P.length<P.highWaterMark;if(Y||(P.needDrain=!0),P.writing||P.corked){var le=P.lastBufferedRequest;P.lastBufferedRequest={chunk:X,encoding:re,isBuf:G,callback:b,next:null},le?le.next=P.lastBufferedRequest:P.bufferedRequest=P.lastBufferedRequest,P.bufferedRequestCount+=1}else V(D,P,!1,H,X,re,b);return Y}function V(D,P,G,X,re,b,E){P.writelen=X,P.writecb=E,P.writing=!0,P.sync=!0,P.destroyed?P.onwrite(new q("write")):G?D._writev(re,P.onwrite):D._write(re,b,P.onwrite),P.sync=!1}function ie(D,P,G,X,re){--P.pendingcb,G?(he.nextTick(re,X),he.nextTick(Qe,D,P),D._writableState.errorEmitted=!0,S(D,X)):(re(X),D._writableState.errorEmitted=!0,S(D,X),Qe(D,P))}function fe(D){D.writing=!1,D.writecb=null,D.length-=D.writelen,D.writelen=0}function Re(D,P){var G=D._writableState,X=G.sync,re=G.writecb;if(typeof re!="function")throw new U;if(fe(G),P)ie(D,G,X,P,re);else{var b=ct(G)||D.destroyed;!b&&!G.corked&&!G.bufferProcessing&&G.bufferedRequest&&Ge(D,G),X?he.nextTick(Te,D,G,b,re):Te(D,G,b,re)}}function Te(D,P,G,X){G||Pe(D,P),P.pendingcb--,X(),Qe(D,P)}function Pe(D,P){P.length===0&&P.needDrain&&(P.needDrain=!1,D.emit("drain"))}function Ge(D,P){P.bufferProcessing=!0;var G=P.bufferedRequest;if(D._writev&&G&&G.next){var X=P.bufferedRequestCount,re=new Array(X),b=P.corkedRequestsFree;b.entry=G;for(var E=0,H=!0;G;)re[E]=G,G.isBuf||(H=!1),G=G.next,E+=1;re.allBuffers=H,V(D,P,!0,P.length,re,"",b.finish),P.pendingcb++,P.lastBufferedRequest=null,b.next?(P.corkedRequestsFree=b.next,b.next=null):P.corkedRequestsFree=new t(P),P.bufferedRequestCount=0}else{for(;G;){var Y=G.chunk,le=G.encoding,Z=G.callback,ae=P.objectMode?1:Y.length;if(V(D,P,!1,ae,Y,le,Z),G=G.next,P.bufferedRequestCount--,P.writing)break}G===null&&(P.lastBufferedRequest=null)}P.bufferedRequest=G,P.bufferProcessing=!1}L.prototype._write=function(D,P,G){G(new k("_write()"))},L.prototype._writev=null,L.prototype.end=function(D,P,G){var X=this._writableState;return typeof D=="function"?(G=D,D=null,P=null):typeof P=="function"&&(G=P,P=null),D!=null&&this.write(D,P),X.corked&&(X.corked=1,this.uncork()),X.ending||we(this,X,G),this},Object.defineProperty(L.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function ct(D){return D.ending&&D.length===0&&D.bufferedRequest===null&&!D.finished&&!D.writing}function Lt(D,P){D._final(function(G){P.pendingcb--,G&&S(D,G),P.prefinished=!0,D.emit("prefinish"),Qe(D,P)})}function ut(D,P){!P.prefinished&&!P.finalCalled&&(typeof D._final=="function"&&!P.destroyed?(P.pendingcb++,P.finalCalled=!0,he.nextTick(Lt,D,P)):(P.prefinished=!0,D.emit("prefinish")))}function Qe(D,P){var G=ct(P);if(G&&(ut(D,P),P.pendingcb===0&&(P.finished=!0,D.emit("finish"),P.autoDestroy))){var X=D._readableState;(!X||X.autoDestroy&&X.endEmitted)&&D.destroy()}return G}function we(D,P,G){P.ending=!0,Qe(D,P),G&&(P.finished?he.nextTick(G):D.once("finish",G)),P.ended=!0,D.writable=!1}function Be(D,P,G){var X=D.entry;for(D.entry=null;X;){var re=X.callback;P.pendingcb--,re(G),X=X.next}P.corkedRequestsFree.next=D}return Object.defineProperty(L.prototype,"destroyed",{enumerable:!1,get:function(){return this._writableState===void 0?!1:this._writableState.destroyed},set:function(P){this._writableState&&(this._writableState.destroyed=P)}}),L.prototype.destroy=h.destroy,L.prototype._undestroy=h.undestroy,L.prototype._destroy=function(D,P){P(D)},Yr}var Qr,ni;function Ot(){if(ni)return Qr;ni=1;var t=Object.keys||function(w){var d=[];for(var I in w)d.push(I);return d};Qr=c;var e=li(),r=ri();Mt()(c,e);for(var n=t(r.prototype),s=0;s<n.length;s++){var i=n[s];c.prototype[i]||(c.prototype[i]=r.prototype[i])}function c(w){if(!(this instanceof c))return new c(w);e.call(this,w),r.call(this,w),this.allowHalfOpen=!0,w&&(w.readable===!1&&(this.readable=!1),w.writable===!1&&(this.writable=!1),w.allowHalfOpen===!1&&(this.allowHalfOpen=!1,this.once("end",l)))}Object.defineProperty(c.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Object.defineProperty(c.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(c.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function l(){this._writableState.ended||he.nextTick(h,this)}function h(w){w.end()}return Object.defineProperty(c.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState===void 0||this._writableState===void 0?!1:this._readableState.destroyed&&this._writableState.destroyed},set:function(d){this._readableState===void 0||this._writableState===void 0||(this._readableState.destroyed=d,this._writableState.destroyed=d)}}),Qr}var Xr={},mr={exports:{}};var ii;function Vs(){return ii||(ii=1,(function(t,e){var r=gr(),n=r.Buffer;function s(c,l){for(var h in c)l[h]=c[h]}n.from&&n.alloc&&n.allocUnsafe&&n.allocUnsafeSlow?t.exports=r:(s(r,e),e.Buffer=i);function i(c,l,h){return n(c,l,h)}i.prototype=Object.create(n.prototype),s(n,i),i.from=function(c,l,h){if(typeof c=="number")throw new TypeError("Argument must not be a number");return n(c,l,h)},i.alloc=function(c,l,h){if(typeof c!="number")throw new TypeError("Argument must be a number");var w=n(c);return l!==void 0?typeof h=="string"?w.fill(l,h):w.fill(l):w.fill(0),w},i.allocUnsafe=function(c){if(typeof c!="number")throw new TypeError("Argument must be a number");return n(c)},i.allocUnsafeSlow=function(c){if(typeof c!="number")throw new TypeError("Argument must be a number");return r.SlowBuffer(c)}})(mr,mr.exports)),mr.exports}var si;function oi(){if(si)return Xr;si=1;var t=Vs().Buffer,e=t.isEncoding||function(_){switch(_=""+_,_&&_.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};function r(_){if(!_)return"utf8";for(var A;;)switch(_){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return _;default:if(A)return;_=(""+_).toLowerCase(),A=!0}}function n(_){var A=r(_);if(typeof A!="string"&&(t.isEncoding===e||!e(_)))throw new Error("Unknown encoding: "+_);return A||_}Xr.StringDecoder=s;function s(_){this.encoding=n(_);var A;switch(this.encoding){case"utf16le":this.text=I,this.end=v,A=4;break;case"utf8":this.fillLast=h,A=4;break;case"base64":this.text=k,this.end=U,A=3;break;default:this.write=$,this.end=q;return}this.lastNeed=0,this.lastTotal=0,this.lastChar=t.allocUnsafe(A)}s.prototype.write=function(_){if(_.length===0)return"";var A,R;if(this.lastNeed){if(A=this.fillLast(_),A===void 0)return"";R=this.lastNeed,this.lastNeed=0}else R=0;return R<_.length?A?A+this.text(_,R):this.text(_,R):A||""},s.prototype.end=d,s.prototype.text=w,s.prototype.fillLast=function(_){if(this.lastNeed<=_.length)return _.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);_.copy(this.lastChar,this.lastTotal-this.lastNeed,0,_.length),this.lastNeed-=_.length};function i(_){return _<=127?0:_>>5===6?2:_>>4===14?3:_>>3===30?4:_>>6===2?-1:-2}function c(_,A,R){var S=A.length-1;if(S<R)return 0;var T=i(A[S]);return T>=0?(T>0&&(_.lastNeed=T-1),T):--S<R||T===-2?0:(T=i(A[S]),T>=0?(T>0&&(_.lastNeed=T-2),T):--S<R||T===-2?0:(T=i(A[S]),T>=0?(T>0&&(T===2?T=0:_.lastNeed=T-3),T):0))}function l(_,A,R){if((A[0]&192)!==128)return _.lastNeed=0,"�";if(_.lastNeed>1&&A.length>1){if((A[1]&192)!==128)return _.lastNeed=1,"�";if(_.lastNeed>2&&A.length>2&&(A[2]&192)!==128)return _.lastNeed=2,"�"}}function h(_){var A=this.lastTotal-this.lastNeed,R=l(this,_);if(R!==void 0)return R;if(this.lastNeed<=_.length)return _.copy(this.lastChar,A,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);_.copy(this.lastChar,A,0,_.length),this.lastNeed-=_.length}function w(_,A){var R=c(this,_,A);if(!this.lastNeed)return _.toString("utf8",A);this.lastTotal=R;var S=_.length-(R-this.lastNeed);return _.copy(this.lastChar,0,S),_.toString("utf8",A,S)}function d(_){var A=_&&_.length?this.write(_):"";return this.lastNeed?A+"�":A}function I(_,A){if((_.length-A)%2===0){var R=_.toString("utf16le",A);if(R){var S=R.charCodeAt(R.length-1);if(S>=55296&&S<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=_[_.length-2],this.lastChar[1]=_[_.length-1],R.slice(0,-1)}return R}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=_[_.length-1],_.toString("utf16le",A,_.length-1)}function v(_){var A=_&&_.length?this.write(_):"";if(this.lastNeed){var R=this.lastTotal-this.lastNeed;return A+this.lastChar.toString("utf16le",0,R)}return A}function k(_,A){var R=(_.length-A)%3;return R===0?_.toString("base64",A):(this.lastNeed=3-R,this.lastTotal=3,R===1?this.lastChar[0]=_[_.length-1]:(this.lastChar[0]=_[_.length-2],this.lastChar[1]=_[_.length-1]),_.toString("base64",A,_.length-R))}function U(_){var A=_&&_.length?this.write(_):"";return this.lastNeed?A+this.lastChar.toString("base64",0,3-this.lastNeed):A}function $(_){return _.toString(this.encoding)}function q(_){return _&&_.length?this.write(_):""}return Xr}var Zr,ai;function en(){if(ai)return Zr;ai=1;var t=Dt().codes.ERR_STREAM_PREMATURE_CLOSE;function e(i){var c=!1;return function(){if(!c){c=!0;for(var l=arguments.length,h=new Array(l),w=0;w<l;w++)h[w]=arguments[w];i.apply(this,h)}}}function r(){}function n(i){return i.setHeader&&typeof i.abort=="function"}function s(i,c,l){if(typeof c=="function")return s(i,null,c);c||(c={}),l=e(l||r);var h=c.readable||c.readable!==!1&&i.readable,w=c.writable||c.writable!==!1&&i.writable,d=function(){i.writable||v()},I=i._writableState&&i._writableState.finished,v=function(){w=!1,I=!0,h||l.call(i)},k=i._readableState&&i._readableState.endEmitted,U=function(){h=!1,k=!0,w||l.call(i)},$=function(R){l.call(i,R)},q=function(){var R;if(h&&!k)return(!i._readableState||!i._readableState.ended)&&(R=new t),l.call(i,R);if(w&&!I)return(!i._writableState||!i._writableState.ended)&&(R=new t),l.call(i,R)},_=function(){i.req.on("finish",v)};return n(i)?(i.on("complete",v),i.on("abort",q),i.req?_():i.on("request",_)):w&&!i._writableState&&(i.on("end",d),i.on("close",d)),i.on("end",U),i.on("finish",v),c.error!==!1&&i.on("error",$),i.on("close",q),function(){i.removeListener("complete",v),i.removeListener("abort",q),i.removeListener("request",_),i.req&&i.req.removeListener("finish",v),i.removeListener("end",d),i.removeListener("close",d),i.removeListener("finish",v),i.removeListener("end",U),i.removeListener("error",$),i.removeListener("close",q)}}return Zr=s,Zr}var tn,ci;function Ys(){if(ci)return tn;ci=1;var t;function e(R,S,T){return S=r(S),S in R?Object.defineProperty(R,S,{value:T,enumerable:!0,configurable:!0,writable:!0}):R[S]=T,R}function r(R){var S=n(R,"string");return typeof S=="symbol"?S:String(S)}function n(R,S){if(typeof R!="object"||R===null)return R;var T=R[Symbol.toPrimitive];if(T!==void 0){var F=T.call(R,S);if(typeof F!="object")return F;throw new TypeError("@@toPrimitive must return a primitive value.")}return(S==="string"?String:Number)(R)}var s=en(),i=Symbol("lastResolve"),c=Symbol("lastReject"),l=Symbol("error"),h=Symbol("ended"),w=Symbol("lastPromise"),d=Symbol("handlePromise"),I=Symbol("stream");function v(R,S){return{value:R,done:S}}function k(R){var S=R[i];if(S!==null){var T=R[I].read();T!==null&&(R[w]=null,R[i]=null,R[c]=null,S(v(T,!1)))}}function U(R){he.nextTick(k,R)}function $(R,S){return function(T,F){R.then(function(){if(S[h]){T(v(void 0,!0));return}S[d](T,F)},F)}}var q=Object.getPrototypeOf(function(){}),_=Object.setPrototypeOf((t={get stream(){return this[I]},next:function(){var S=this,T=this[l];if(T!==null)return Promise.reject(T);if(this[h])return Promise.resolve(v(void 0,!0));if(this[I].destroyed)return new Promise(function(W,J){he.nextTick(function(){S[l]?J(S[l]):W(v(void 0,!0))})});var F=this[w],M;if(F)M=new Promise($(F,this));else{var L=this[I].read();if(L!==null)return Promise.resolve(v(L,!1));M=new Promise(this[d])}return this[w]=M,M}},e(t,Symbol.asyncIterator,function(){return this}),e(t,"return",function(){var S=this;return new Promise(function(T,F){S[I].destroy(null,function(M){if(M){F(M);return}T(v(void 0,!0))})})}),t),q),A=function(S){var T,F=Object.create(_,(T={},e(T,I,{value:S,writable:!0}),e(T,i,{value:null,writable:!0}),e(T,c,{value:null,writable:!0}),e(T,l,{value:null,writable:!0}),e(T,h,{value:S._readableState.endEmitted,writable:!0}),e(T,d,{value:function(L,W){var J=F[I].read();J?(F[w]=null,F[i]=null,F[c]=null,L(v(J,!1))):(F[i]=L,F[c]=W)},writable:!0}),T));return F[w]=null,s(S,function(M){if(M&&M.code!=="ERR_STREAM_PREMATURE_CLOSE"){var L=F[c];L!==null&&(F[w]=null,F[i]=null,F[c]=null,L(M)),F[l]=M;return}var W=F[i];W!==null&&(F[w]=null,F[i]=null,F[c]=null,W(v(void 0,!0))),F[h]=!0}),S.on("readable",U.bind(null,F)),F};return tn=A,tn}var rn,ui;function Qs(){return ui||(ui=1,rn=function(){throw new Error("Readable.from is not available in the browser")}),rn}var nn,fi;function li(){if(fi)return nn;fi=1,nn=W;var t;W.ReadableState=L,pr().EventEmitter;var e=function(E,H){return E.listeners(H).length},r=Hn(),n=gr().Buffer,s=(typeof et<"u"?et:typeof window<"u"?window:typeof self<"u"?self:{}).Uint8Array||function(){};function i(b){return n.from(b)}function c(b){return n.isBuffer(b)||b instanceof s}var l=Jn,h;l&&l.debuglog?h=l.debuglog("stream"):h=function(){};var w=Js(),d=Yn(),I=Zn(),v=I.getHighWaterMark,k=Dt().codes,U=k.ERR_INVALID_ARG_TYPE,$=k.ERR_STREAM_PUSH_AFTER_EOF,q=k.ERR_METHOD_NOT_IMPLEMENTED,_=k.ERR_STREAM_UNSHIFT_AFTER_END_EVENT,A,R,S;Mt()(W,r);var T=d.errorOrDestroy,F=["error","close","destroy","pause","resume"];function M(b,E,H){if(typeof b.prependListener=="function")return b.prependListener(E,H);!b._events||!b._events[E]?b.on(E,H):Array.isArray(b._events[E])?b._events[E].unshift(H):b._events[E]=[H,b._events[E]]}function L(b,E,H){t=t||Ot(),b=b||{},typeof H!="boolean"&&(H=E instanceof t),this.objectMode=!!b.objectMode,H&&(this.objectMode=this.objectMode||!!b.readableObjectMode),this.highWaterMark=v(this,b,"readableHighWaterMark",H),this.buffer=new w,this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.resumeScheduled=!1,this.paused=!0,this.emitClose=b.emitClose!==!1,this.autoDestroy=!!b.autoDestroy,this.destroyed=!1,this.defaultEncoding=b.defaultEncoding||"utf8",this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,b.encoding&&(A||(A=oi().StringDecoder),this.decoder=new A(b.encoding),this.encoding=b.encoding)}function W(b){if(t=t||Ot(),!(this instanceof W))return new W(b);var E=this instanceof t;this._readableState=new L(b,this,E),this.readable=!0,b&&(typeof b.read=="function"&&(this._read=b.read),typeof b.destroy=="function"&&(this._destroy=b.destroy)),r.call(this)}Object.defineProperty(W.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState===void 0?!1:this._readableState.destroyed},set:function(E){this._readableState&&(this._readableState.destroyed=E)}}),W.prototype.destroy=d.destroy,W.prototype._undestroy=d.undestroy,W.prototype._destroy=function(b,E){E(b)},W.prototype.push=function(b,E){var H=this._readableState,Y;return H.objectMode?Y=!0:typeof b=="string"&&(E=E||H.defaultEncoding,E!==H.encoding&&(b=n.from(b,E),E=""),Y=!0),J(this,b,E,!1,Y)},W.prototype.unshift=function(b){return J(this,b,null,!0,!1)};function J(b,E,H,Y,le){h("readableAddChunk",E);var Z=b._readableState;if(E===null)Z.reading=!1,Re(b,Z);else{var ae;if(le||(ae=N(Z,E)),ae)T(b,ae);else if(Z.objectMode||E&&E.length>0)if(typeof E!="string"&&!Z.objectMode&&Object.getPrototypeOf(E)!==n.prototype&&(E=i(E)),Y)Z.endEmitted?T(b,new _):Q(b,Z,E,!0);else if(Z.ended)T(b,new $);else{if(Z.destroyed)return!1;Z.reading=!1,Z.decoder&&!H?(E=Z.decoder.write(E),Z.objectMode||E.length!==0?Q(b,Z,E,!1):Ge(b,Z)):Q(b,Z,E,!1)}else Y||(Z.reading=!1,Ge(b,Z))}return!Z.ended&&(Z.length<Z.highWaterMark||Z.length===0)}function Q(b,E,H,Y){E.flowing&&E.length===0&&!E.sync?(E.awaitDrain=0,b.emit("data",H)):(E.length+=E.objectMode?1:H.length,Y?E.buffer.unshift(H):E.buffer.push(H),E.needReadable&&Te(b)),Ge(b,E)}function N(b,E){var H;return!c(E)&&typeof E!="string"&&E!==void 0&&!b.objectMode&&(H=new U("chunk",["string","Buffer","Uint8Array"],E)),H}W.prototype.isPaused=function(){return this._readableState.flowing===!1},W.prototype.setEncoding=function(b){A||(A=oi().StringDecoder);var E=new A(b);this._readableState.decoder=E,this._readableState.encoding=this._readableState.decoder.encoding;for(var H=this._readableState.buffer.head,Y="";H!==null;)Y+=E.write(H.data),H=H.next;return this._readableState.buffer.clear(),Y!==""&&this._readableState.buffer.push(Y),this._readableState.length=Y.length,this};var V=1073741824;function ie(b){return b>=V?b=V:(b--,b|=b>>>1,b|=b>>>2,b|=b>>>4,b|=b>>>8,b|=b>>>16,b++),b}function fe(b,E){return b<=0||E.length===0&&E.ended?0:E.objectMode?1:b!==b?E.flowing&&E.length?E.buffer.head.data.length:E.length:(b>E.highWaterMark&&(E.highWaterMark=ie(b)),b<=E.length?b:E.ended?E.length:(E.needReadable=!0,0))}W.prototype.read=function(b){h("read",b),b=parseInt(b,10);var E=this._readableState,H=b;if(b!==0&&(E.emittedReadable=!1),b===0&&E.needReadable&&((E.highWaterMark!==0?E.length>=E.highWaterMark:E.length>0)||E.ended))return h("read: emitReadable",E.length,E.ended),E.length===0&&E.ended?G(this):Te(this),null;if(b=fe(b,E),b===0&&E.ended)return E.length===0&&G(this),null;var Y=E.needReadable;h("need readable",Y),(E.length===0||E.length-b<E.highWaterMark)&&(Y=!0,h("length less than watermark",Y)),E.ended||E.reading?(Y=!1,h("reading or ended",Y)):Y&&(h("do read"),E.reading=!0,E.sync=!0,E.length===0&&(E.needReadable=!0),this._read(E.highWaterMark),E.sync=!1,E.reading||(b=fe(H,E)));var le;return b>0?le=P(b,E):le=null,le===null?(E.needReadable=E.length<=E.highWaterMark,b=0):(E.length-=b,E.awaitDrain=0),E.length===0&&(E.ended||(E.needReadable=!0),H!==b&&E.ended&&G(this)),le!==null&&this.emit("data",le),le};function Re(b,E){if(h("onEofChunk"),!E.ended){if(E.decoder){var H=E.decoder.end();H&&H.length&&(E.buffer.push(H),E.length+=E.objectMode?1:H.length)}E.ended=!0,E.sync?Te(b):(E.needReadable=!1,E.emittedReadable||(E.emittedReadable=!0,Pe(b)))}}function Te(b){var E=b._readableState;h("emitReadable",E.needReadable,E.emittedReadable),E.needReadable=!1,E.emittedReadable||(h("emitReadable",E.flowing),E.emittedReadable=!0,he.nextTick(Pe,b))}function Pe(b){var E=b._readableState;h("emitReadable_",E.destroyed,E.length,E.ended),!E.destroyed&&(E.length||E.ended)&&(b.emit("readable"),E.emittedReadable=!1),E.needReadable=!E.flowing&&!E.ended&&E.length<=E.highWaterMark,D(b)}function Ge(b,E){E.readingMore||(E.readingMore=!0,he.nextTick(ct,b,E))}function ct(b,E){for(;!E.reading&&!E.ended&&(E.length<E.highWaterMark||E.flowing&&E.length===0);){var H=E.length;if(h("maybeReadMore read 0"),b.read(0),H===E.length)break}E.readingMore=!1}W.prototype._read=function(b){T(this,new q("_read()"))},W.prototype.pipe=function(b,E){var H=this,Y=this._readableState;switch(Y.pipesCount){case 0:Y.pipes=b;break;case 1:Y.pipes=[Y.pipes,b];break;default:Y.pipes.push(b);break}Y.pipesCount+=1,h("pipe count=%d opts=%j",Y.pipesCount,E);var le=(!E||E.end!==!1)&&b!==he.stdout&&b!==he.stderr,Z=le?ft:Je;Y.endEmitted?he.nextTick(Z):H.once("end",Z),b.on("unpipe",ae);function ae(Ze,ke){h("onunpipe"),Ze===H&&ke&&ke.hasUnpiped===!1&&(ke.hasUnpiped=!0,hr())}function ft(){h("onend"),b.end()}var Tt=Lt(H);b.on("drain",Tt);var vt=!1;function hr(){h("cleanup"),b.removeListener("close",Xe),b.removeListener("finish",Fe),b.removeListener("drain",Tt),b.removeListener("error",Ie),b.removeListener("unpipe",ae),H.removeListener("end",ft),H.removeListener("end",Je),H.removeListener("data",Ee),vt=!0,Y.awaitDrain&&(!b._writableState||b._writableState.needDrain)&&Tt()}H.on("data",Ee);function Ee(Ze){h("ondata");var ke=b.write(Ze);h("dest.write",ke),ke===!1&&((Y.pipesCount===1&&Y.pipes===b||Y.pipesCount>1&&re(Y.pipes,b)!==-1)&&!vt&&(h("false write response, pause",Y.awaitDrain),Y.awaitDrain++),H.pause())}function Ie(Ze){h("onerror",Ze),Je(),b.removeListener("error",Ie),e(b,"error")===0&&T(b,Ze)}M(b,"error",Ie);function Xe(){b.removeListener("finish",Fe),Je()}b.once("close",Xe);function Fe(){h("onfinish"),b.removeListener("close",Xe),Je()}b.once("finish",Fe);function Je(){h("unpipe"),H.unpipe(b)}return b.emit("pipe",H),Y.flowing||(h("pipe resume"),H.resume()),b};function Lt(b){return function(){var H=b._readableState;h("pipeOnDrain",H.awaitDrain),H.awaitDrain&&H.awaitDrain--,H.awaitDrain===0&&e(b,"data")&&(H.flowing=!0,D(b))}}W.prototype.unpipe=function(b){var E=this._readableState,H={hasUnpiped:!1};if(E.pipesCount===0)return this;if(E.pipesCount===1)return b&&b!==E.pipes?this:(b||(b=E.pipes),E.pipes=null,E.pipesCount=0,E.flowing=!1,b&&b.emit("unpipe",this,H),this);if(!b){var Y=E.pipes,le=E.pipesCount;E.pipes=null,E.pipesCount=0,E.flowing=!1;for(var Z=0;Z<le;Z++)Y[Z].emit("unpipe",this,{hasUnpiped:!1});return this}var ae=re(E.pipes,b);return ae===-1?this:(E.pipes.splice(ae,1),E.pipesCount-=1,E.pipesCount===1&&(E.pipes=E.pipes[0]),b.emit("unpipe",this,H),this)},W.prototype.on=function(b,E){var H=r.prototype.on.call(this,b,E),Y=this._readableState;return b==="data"?(Y.readableListening=this.listenerCount("readable")>0,Y.flowing!==!1&&this.resume()):b==="readable"&&!Y.endEmitted&&!Y.readableListening&&(Y.readableListening=Y.needReadable=!0,Y.flowing=!1,Y.emittedReadable=!1,h("on readable",Y.length,Y.reading),Y.length?Te(this):Y.reading||he.nextTick(Qe,this)),H},W.prototype.addListener=W.prototype.on,W.prototype.removeListener=function(b,E){var H=r.prototype.removeListener.call(this,b,E);return b==="readable"&&he.nextTick(ut,this),H},W.prototype.removeAllListeners=function(b){var E=r.prototype.removeAllListeners.apply(this,arguments);return(b==="readable"||b===void 0)&&he.nextTick(ut,this),E};function ut(b){var E=b._readableState;E.readableListening=b.listenerCount("readable")>0,E.resumeScheduled&&!E.paused?E.flowing=!0:b.listenerCount("data")>0&&b.resume()}function Qe(b){h("readable nexttick read 0"),b.read(0)}W.prototype.resume=function(){var b=this._readableState;return b.flowing||(h("resume"),b.flowing=!b.readableListening,we(this,b)),b.paused=!1,this};function we(b,E){E.resumeScheduled||(E.resumeScheduled=!0,he.nextTick(Be,b,E))}function Be(b,E){h("resume",E.reading),E.reading||b.read(0),E.resumeScheduled=!1,b.emit("resume"),D(b),E.flowing&&!E.reading&&b.read(0)}W.prototype.pause=function(){return h("call pause flowing=%j",this._readableState.flowing),this._readableState.flowing!==!1&&(h("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this};function D(b){var E=b._readableState;for(h("flow",E.flowing);E.flowing&&b.read()!==null;);}W.prototype.wrap=function(b){var E=this,H=this._readableState,Y=!1;b.on("end",function(){if(h("wrapped end"),H.decoder&&!H.ended){var ae=H.decoder.end();ae&&ae.length&&E.push(ae)}E.push(null)}),b.on("data",function(ae){if(h("wrapped data"),H.decoder&&(ae=H.decoder.write(ae)),!(H.objectMode&&ae==null)&&!(!H.objectMode&&(!ae||!ae.length))){var ft=E.push(ae);ft||(Y=!0,b.pause())}});for(var le in b)this[le]===void 0&&typeof b[le]=="function"&&(this[le]=(function(ft){return function(){return b[ft].apply(b,arguments)}})(le));for(var Z=0;Z<F.length;Z++)b.on(F[Z],this.emit.bind(this,F[Z]));return this._read=function(ae){h("wrapped _read",ae),Y&&(Y=!1,b.resume())},this},typeof Symbol=="function"&&(W.prototype[Symbol.asyncIterator]=function(){return R===void 0&&(R=Ys()),R(this)}),Object.defineProperty(W.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty(W.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty(W.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(E){this._readableState&&(this._readableState.flowing=E)}}),W._fromList=P,Object.defineProperty(W.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}});function P(b,E){if(E.length===0)return null;var H;return E.objectMode?H=E.buffer.shift():!b||b>=E.length?(E.decoder?H=E.buffer.join(""):E.buffer.length===1?H=E.buffer.first():H=E.buffer.concat(E.length),E.buffer.clear()):H=E.buffer.consume(b,E.decoder),H}function G(b){var E=b._readableState;h("endReadable",E.endEmitted),E.endEmitted||(E.ended=!0,he.nextTick(X,E,b))}function X(b,E){if(h("endReadableNT",b.endEmitted,b.length),!b.endEmitted&&b.length===0&&(b.endEmitted=!0,E.readable=!1,E.emit("end"),b.autoDestroy)){var H=E._writableState;(!H||H.autoDestroy&&H.finished)&&E.destroy()}}typeof Symbol=="function"&&(W.from=function(b,E){return S===void 0&&(S=Qs()),S(W,b,E)});function re(b,E){for(var H=0,Y=b.length;H<Y;H++)if(b[H]===E)return H;return-1}return nn}var sn,hi;function di(){if(hi)return sn;hi=1,sn=l;var t=Dt().codes,e=t.ERR_METHOD_NOT_IMPLEMENTED,r=t.ERR_MULTIPLE_CALLBACK,n=t.ERR_TRANSFORM_ALREADY_TRANSFORMING,s=t.ERR_TRANSFORM_WITH_LENGTH_0,i=Ot();Mt()(l,i);function c(d,I){var v=this._transformState;v.transforming=!1;var k=v.writecb;if(k===null)return this.emit("error",new r);v.writechunk=null,v.writecb=null,I!=null&&this.push(I),k(d);var U=this._readableState;U.reading=!1,(U.needReadable||U.length<U.highWaterMark)&&this._read(U.highWaterMark)}function l(d){if(!(this instanceof l))return new l(d);i.call(this,d),this._transformState={afterTransform:c.bind(this),needTransform:!1,transforming:!1,writecb:null,writechunk:null,writeencoding:null},this._readableState.needReadable=!0,this._readableState.sync=!1,d&&(typeof d.transform=="function"&&(this._transform=d.transform),typeof d.flush=="function"&&(this._flush=d.flush)),this.on("prefinish",h)}function h(){var d=this;typeof this._flush=="function"&&!this._readableState.destroyed?this._flush(function(I,v){w(d,I,v)}):w(this,null,null)}l.prototype.push=function(d,I){return this._transformState.needTransform=!1,i.prototype.push.call(this,d,I)},l.prototype._transform=function(d,I,v){v(new e("_transform()"))},l.prototype._write=function(d,I,v){var k=this._transformState;if(k.writecb=v,k.writechunk=d,k.writeencoding=I,!k.transforming){var U=this._readableState;(k.needTransform||U.needReadable||U.length<U.highWaterMark)&&this._read(U.highWaterMark)}},l.prototype._read=function(d){var I=this._transformState;I.writechunk!==null&&!I.transforming?(I.transforming=!0,this._transform(I.writechunk,I.writeencoding,I.afterTransform)):I.needTransform=!0},l.prototype._destroy=function(d,I){i.prototype._destroy.call(this,d,function(v){I(v)})};function w(d,I,v){if(I)return d.emit("error",I);if(v!=null&&d.push(v),d._writableState.length)throw new s;if(d._transformState.transforming)throw new n;return d.push(null)}return sn}var on,pi;function Xs(){if(pi)return on;pi=1,on=e;var t=di();Mt()(e,t);function e(r){if(!(this instanceof e))return new e(r);t.call(this,r)}return e.prototype._transform=function(r,n,s){s(null,r)},on}var an,yi;function Zs(){if(yi)return an;yi=1;var t;function e(v){var k=!1;return function(){k||(k=!0,v.apply(void 0,arguments))}}var r=Dt().codes,n=r.ERR_MISSING_ARGS,s=r.ERR_STREAM_DESTROYED;function i(v){if(v)throw v}function c(v){return v.setHeader&&typeof v.abort=="function"}function l(v,k,U,$){$=e($);var q=!1;v.on("close",function(){q=!0}),t===void 0&&(t=en()),t(v,{readable:k,writable:U},function(A){if(A)return $(A);q=!0,$()});var _=!1;return function(A){if(!q&&!_){if(_=!0,c(v))return v.abort();if(typeof v.destroy=="function")return v.destroy();$(A||new s("pipe"))}}}function h(v){v()}function w(v,k){return v.pipe(k)}function d(v){return!v.length||typeof v[v.length-1]!="function"?i:v.pop()}function I(){for(var v=arguments.length,k=new Array(v),U=0;U<v;U++)k[U]=arguments[U];var $=d(k);if(Array.isArray(k[0])&&(k=k[0]),k.length<2)throw new n("streams");var q,_=k.map(function(A,R){var S=R<k.length-1,T=R>0;return l(A,S,T,function(F){q||(q=F),F&&_.forEach(h),!S&&(_.forEach(h),$(q))})});return k.reduce(w)}return an=I,an}var cn,wi;function eo(){if(wi)return cn;wi=1,cn=r;var t=pr().EventEmitter,e=Mt();e(r,t),r.Readable=li(),r.Writable=ri(),r.Duplex=Ot(),r.Transform=di(),r.PassThrough=Xs(),r.finished=en(),r.pipeline=Zs(),r.Stream=r;function r(){t.call(this)}return r.prototype.pipe=function(n,s){var i=this;function c(k){n.writable&&n.write(k)===!1&&i.pause&&i.pause()}i.on("data",c);function l(){i.readable&&i.resume&&i.resume()}n.on("drain",l),!n._isStdio&&(!s||s.end!==!1)&&(i.on("end",w),i.on("close",d));var h=!1;function w(){h||(h=!0,n.end())}function d(){h||(h=!0,typeof n.destroy=="function"&&n.destroy())}function I(k){if(v(),t.listenerCount(this,"error")===0)throw k}i.on("error",I),n.on("error",I);function v(){i.removeListener("data",c),n.removeListener("drain",l),i.removeListener("end",w),i.removeListener("close",d),i.removeListener("error",I),n.removeListener("error",I),i.removeListener("end",v),i.removeListener("close",v),n.removeListener("close",v)}return i.on("end",v),i.on("close",v),n.on("close",v),n.emit("pipe",i),n},cn}var Ct=eo();const to="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Xt=(t=21)=>{let e="",r=crypto.getRandomValues(new Uint8Array(t|=0));for(;t--;)e+=to[r[t]&63];return e};var un={},br={};br.byteLength=io,br.toByteArray=oo,br.fromByteArray=uo;for(var nt=[],$e=[],ro=typeof Uint8Array<"u"?Uint8Array:Array,fn="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",$t=0,no=fn.length;$t<no;++$t)nt[$t]=fn[$t],$e[fn.charCodeAt($t)]=$t;$e[45]=62,$e[95]=63;function gi(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");r===-1&&(r=e);var n=r===e?0:4-r%4;return[r,n]}function io(t){var e=gi(t),r=e[0],n=e[1];return(r+n)*3/4-n}function so(t,e,r){return(e+r)*3/4-r}function oo(t){var e,r=gi(t),n=r[0],s=r[1],i=new ro(so(t,n,s)),c=0,l=s>0?n-4:n,h;for(h=0;h<l;h+=4)e=$e[t.charCodeAt(h)]<<18|$e[t.charCodeAt(h+1)]<<12|$e[t.charCodeAt(h+2)]<<6|$e[t.charCodeAt(h+3)],i[c++]=e>>16&255,i[c++]=e>>8&255,i[c++]=e&255;return s===2&&(e=$e[t.charCodeAt(h)]<<2|$e[t.charCodeAt(h+1)]>>4,i[c++]=e&255),s===1&&(e=$e[t.charCodeAt(h)]<<10|$e[t.charCodeAt(h+1)]<<4|$e[t.charCodeAt(h+2)]>>2,i[c++]=e>>8&255,i[c++]=e&255),i}function ao(t){return nt[t>>18&63]+nt[t>>12&63]+nt[t>>6&63]+nt[t&63]}function co(t,e,r){for(var n,s=[],i=e;i<r;i+=3)n=(t[i]<<16&16711680)+(t[i+1]<<8&65280)+(t[i+2]&255),s.push(ao(n));return s.join("")}function uo(t){for(var e,r=t.length,n=r%3,s=[],i=16383,c=0,l=r-n;c<l;c+=i)s.push(co(t,c,c+i>l?l:c+i));return n===1?(e=t[r-1],s.push(nt[e>>2]+nt[e<<4&63]+"==")):n===2&&(e=(t[r-2]<<8)+t[r-1],s.push(nt[e>>10]+nt[e>>4&63]+nt[e<<2&63]+"=")),s.join("")}var ln={};ln.read=function(t,e,r,n,s){var i,c,l=s*8-n-1,h=(1<<l)-1,w=h>>1,d=-7,I=r?s-1:0,v=r?-1:1,k=t[e+I];for(I+=v,i=k&(1<<-d)-1,k>>=-d,d+=l;d>0;i=i*256+t[e+I],I+=v,d-=8);for(c=i&(1<<-d)-1,i>>=-d,d+=n;d>0;c=c*256+t[e+I],I+=v,d-=8);if(i===0)i=1-w;else{if(i===h)return c?NaN:(k?-1:1)*(1/0);c=c+Math.pow(2,n),i=i-w}return(k?-1:1)*c*Math.pow(2,i-n)},ln.write=function(t,e,r,n,s,i){var c,l,h,w=i*8-s-1,d=(1<<w)-1,I=d>>1,v=s===23?Math.pow(2,-24)-Math.pow(2,-77):0,k=n?0:i-1,U=n?1:-1,$=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(l=isNaN(e)?1:0,c=d):(c=Math.floor(Math.log(e)/Math.LN2),e*(h=Math.pow(2,-c))<1&&(c--,h*=2),c+I>=1?e+=v/h:e+=v*Math.pow(2,1-I),e*h>=2&&(c++,h/=2),c+I>=d?(l=0,c=d):c+I>=1?(l=(e*h-1)*Math.pow(2,s),c=c+I):(l=e*Math.pow(2,I-1)*Math.pow(2,s),c=0));s>=8;t[r+k]=l&255,k+=U,l/=256,s-=8);for(c=c<<s|l,w+=s;w>0;t[r+k]=c&255,k+=U,c/=256,w-=8);t[r+k-U]|=$*128};(function(t){const e=br,r=ln,n=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;t.Buffer=d,t.SlowBuffer=T,t.INSPECT_MAX_BYTES=50;const s=2147483647;t.kMaxLength=s;const{Uint8Array:i,ArrayBuffer:c,SharedArrayBuffer:l}=globalThis;d.TYPED_ARRAY_SUPPORT=h(),!d.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function h(){try{const p=new i(1),o={foo:function(){return 42}};return Object.setPrototypeOf(o,i.prototype),Object.setPrototypeOf(p,o),p.foo()===42}catch{return!1}}Object.defineProperty(d.prototype,"parent",{enumerable:!0,get:function(){if(d.isBuffer(this))return this.buffer}}),Object.defineProperty(d.prototype,"offset",{enumerable:!0,get:function(){if(d.isBuffer(this))return this.byteOffset}});function w(p){if(p>s)throw new RangeError('The value "'+p+'" is invalid for option "size"');const o=new i(p);return Object.setPrototypeOf(o,d.prototype),o}function d(p,o,u){if(typeof p=="number"){if(typeof o=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return U(p)}return I(p,o,u)}d.poolSize=8192;function I(p,o,u){if(typeof p=="string")return $(p,o);if(c.isView(p))return _(p);if(p==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof p);if(Fe(p,c)||p&&Fe(p.buffer,c)||typeof l<"u"&&(Fe(p,l)||p&&Fe(p.buffer,l)))return A(p,o,u);if(typeof p=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const g=p.valueOf&&p.valueOf();if(g!=null&&g!==p)return d.from(g,o,u);const x=R(p);if(x)return x;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof p[Symbol.toPrimitive]=="function")return d.from(p[Symbol.toPrimitive]("string"),o,u);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof p)}d.from=function(p,o,u){return I(p,o,u)},Object.setPrototypeOf(d.prototype,i.prototype),Object.setPrototypeOf(d,i);function v(p){if(typeof p!="number")throw new TypeError('"size" argument must be of type number');if(p<0)throw new RangeError('The value "'+p+'" is invalid for option "size"')}function k(p,o,u){return v(p),p<=0?w(p):o!==void 0?typeof u=="string"?w(p).fill(o,u):w(p).fill(o):w(p)}d.alloc=function(p,o,u){return k(p,o,u)};function U(p){return v(p),w(p<0?0:S(p)|0)}d.allocUnsafe=function(p){return U(p)},d.allocUnsafeSlow=function(p){return U(p)};function $(p,o){if((typeof o!="string"||o==="")&&(o="utf8"),!d.isEncoding(o))throw new TypeError("Unknown encoding: "+o);const u=F(p,o)|0;let g=w(u);const x=g.write(p,o);return x!==u&&(g=g.slice(0,x)),g}function q(p){const o=p.length<0?0:S(p.length)|0,u=w(o);for(let g=0;g<o;g+=1)u[g]=p[g]&255;return u}function _(p){if(Fe(p,i)){const o=new i(p);return A(o.buffer,o.byteOffset,o.byteLength)}return q(p)}function A(p,o,u){if(o<0||p.byteLength<o)throw new RangeError('"offset" is outside of buffer bounds');if(p.byteLength<o+(u||0))throw new RangeError('"length" is outside of buffer bounds');let g;return o===void 0&&u===void 0?g=new i(p):u===void 0?g=new i(p,o):g=new i(p,o,u),Object.setPrototypeOf(g,d.prototype),g}function R(p){if(d.isBuffer(p)){const o=S(p.length)|0,u=w(o);return u.length===0||p.copy(u,0,0,o),u}if(p.length!==void 0)return typeof p.length!="number"||Je(p.length)?w(0):q(p);if(p.type==="Buffer"&&Array.isArray(p.data))return q(p.data)}function S(p){if(p>=s)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+s.toString(16)+" bytes");return p|0}function T(p){return+p!=p&&(p=0),d.alloc(+p)}d.isBuffer=function(o){return o!=null&&o._isBuffer===!0&&o!==d.prototype},d.compare=function(o,u){if(Fe(o,i)&&(o=d.from(o,o.offset,o.byteLength)),Fe(u,i)&&(u=d.from(u,u.offset,u.byteLength)),!d.isBuffer(o)||!d.isBuffer(u))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(o===u)return 0;let g=o.length,x=u.length;for(let O=0,j=Math.min(g,x);O<j;++O)if(o[O]!==u[O]){g=o[O],x=u[O];break}return g<x?-1:x<g?1:0},d.isEncoding=function(o){switch(String(o).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},d.concat=function(o,u){if(!Array.isArray(o))throw new TypeError('"list" argument must be an Array of Buffers');if(o.length===0)return d.alloc(0);let g;if(u===void 0)for(u=0,g=0;g<o.length;++g)u+=o[g].length;const x=d.allocUnsafe(u);let O=0;for(g=0;g<o.length;++g){let j=o[g];if(Fe(j,i))O+j.length>x.length?(d.isBuffer(j)||(j=d.from(j)),j.copy(x,O)):i.prototype.set.call(x,j,O);else if(d.isBuffer(j))j.copy(x,O);else throw new TypeError('"list" argument must be an Array of Buffers');O+=j.length}return x};function F(p,o){if(d.isBuffer(p))return p.length;if(c.isView(p)||Fe(p,c))return p.byteLength;if(typeof p!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof p);const u=p.length,g=arguments.length>2&&arguments[2]===!0;if(!g&&u===0)return 0;let x=!1;for(;;)switch(o){case"ascii":case"latin1":case"binary":return u;case"utf8":case"utf-8":return vt(p).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return u*2;case"hex":return u>>>1;case"base64":return Ie(p).length;default:if(x)return g?-1:vt(p).length;o=(""+o).toLowerCase(),x=!0}}d.byteLength=F;function M(p,o,u){let g=!1;if((o===void 0||o<0)&&(o=0),o>this.length||((u===void 0||u>this.length)&&(u=this.length),u<=0)||(u>>>=0,o>>>=0,u<=o))return"";for(p||(p="utf8");;)switch(p){case"hex":return ut(this,o,u);case"utf8":case"utf-8":return Te(this,o,u);case"ascii":return ct(this,o,u);case"latin1":case"binary":return Lt(this,o,u);case"base64":return Re(this,o,u);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Qe(this,o,u);default:if(g)throw new TypeError("Unknown encoding: "+p);p=(p+"").toLowerCase(),g=!0}}d.prototype._isBuffer=!0;function L(p,o,u){const g=p[o];p[o]=p[u],p[u]=g}d.prototype.swap16=function(){const o=this.length;if(o%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let u=0;u<o;u+=2)L(this,u,u+1);return this},d.prototype.swap32=function(){const o=this.length;if(o%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let u=0;u<o;u+=4)L(this,u,u+3),L(this,u+1,u+2);return this},d.prototype.swap64=function(){const o=this.length;if(o%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let u=0;u<o;u+=8)L(this,u,u+7),L(this,u+1,u+6),L(this,u+2,u+5),L(this,u+3,u+4);return this},d.prototype.toString=function(){const o=this.length;return o===0?"":arguments.length===0?Te(this,0,o):M.apply(this,arguments)},d.prototype.toLocaleString=d.prototype.toString,d.prototype.equals=function(o){if(!d.isBuffer(o))throw new TypeError("Argument must be a Buffer");return this===o?!0:d.compare(this,o)===0},d.prototype.inspect=function(){let o="";const u=t.INSPECT_MAX_BYTES;return o=this.toString("hex",0,u).replace(/(.{2})/g,"$1 ").trim(),this.length>u&&(o+=" ... "),"<Buffer "+o+">"},n&&(d.prototype[n]=d.prototype.inspect),d.prototype.compare=function(o,u,g,x,O){if(Fe(o,i)&&(o=d.from(o,o.offset,o.byteLength)),!d.isBuffer(o))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof o);if(u===void 0&&(u=0),g===void 0&&(g=o?o.length:0),x===void 0&&(x=0),O===void 0&&(O=this.length),u<0||g>o.length||x<0||O>this.length)throw new RangeError("out of range index");if(x>=O&&u>=g)return 0;if(x>=O)return-1;if(u>=g)return 1;if(u>>>=0,g>>>=0,x>>>=0,O>>>=0,this===o)return 0;let j=O-x,ne=g-u;const pe=Math.min(j,ne),ye=this.slice(x,O),ge=o.slice(u,g);for(let ue=0;ue<pe;++ue)if(ye[ue]!==ge[ue]){j=ye[ue],ne=ge[ue];break}return j<ne?-1:ne<j?1:0};function W(p,o,u,g,x){if(p.length===0)return-1;if(typeof u=="string"?(g=u,u=0):u>2147483647?u=2147483647:u<-2147483648&&(u=-2147483648),u=+u,Je(u)&&(u=x?0:p.length-1),u<0&&(u=p.length+u),u>=p.length){if(x)return-1;u=p.length-1}else if(u<0)if(x)u=0;else return-1;if(typeof o=="string"&&(o=d.from(o,g)),d.isBuffer(o))return o.length===0?-1:J(p,o,u,g,x);if(typeof o=="number")return o=o&255,typeof i.prototype.indexOf=="function"?x?i.prototype.indexOf.call(p,o,u):i.prototype.lastIndexOf.call(p,o,u):J(p,[o],u,g,x);throw new TypeError("val must be string, number or Buffer")}function J(p,o,u,g,x){let O=1,j=p.length,ne=o.length;if(g!==void 0&&(g=String(g).toLowerCase(),g==="ucs2"||g==="ucs-2"||g==="utf16le"||g==="utf-16le")){if(p.length<2||o.length<2)return-1;O=2,j/=2,ne/=2,u/=2}function pe(ge,ue){return O===1?ge[ue]:ge.readUInt16BE(ue*O)}let ye;if(x){let ge=-1;for(ye=u;ye<j;ye++)if(pe(p,ye)===pe(o,ge===-1?0:ye-ge)){if(ge===-1&&(ge=ye),ye-ge+1===ne)return ge*O}else ge!==-1&&(ye-=ye-ge),ge=-1}else for(u+ne>j&&(u=j-ne),ye=u;ye>=0;ye--){let ge=!0;for(let ue=0;ue<ne;ue++)if(pe(p,ye+ue)!==pe(o,ue)){ge=!1;break}if(ge)return ye}return-1}d.prototype.includes=function(o,u,g){return this.indexOf(o,u,g)!==-1},d.prototype.indexOf=function(o,u,g){return W(this,o,u,g,!0)},d.prototype.lastIndexOf=function(o,u,g){return W(this,o,u,g,!1)};function Q(p,o,u,g){u=Number(u)||0;const x=p.length-u;g?(g=Number(g),g>x&&(g=x)):g=x;const O=o.length;g>O/2&&(g=O/2);let j;for(j=0;j<g;++j){const ne=parseInt(o.substr(j*2,2),16);if(Je(ne))return j;p[u+j]=ne}return j}function N(p,o,u,g){return Xe(vt(o,p.length-u),p,u,g)}function V(p,o,u,g){return Xe(hr(o),p,u,g)}function ie(p,o,u,g){return Xe(Ie(o),p,u,g)}function fe(p,o,u,g){return Xe(Ee(o,p.length-u),p,u,g)}d.prototype.write=function(o,u,g,x){if(u===void 0)x="utf8",g=this.length,u=0;else if(g===void 0&&typeof u=="string")x=u,g=this.length,u=0;else if(isFinite(u))u=u>>>0,isFinite(g)?(g=g>>>0,x===void 0&&(x="utf8")):(x=g,g=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const O=this.length-u;if((g===void 0||g>O)&&(g=O),o.length>0&&(g<0||u<0)||u>this.length)throw new RangeError("Attempt to write outside buffer bounds");x||(x="utf8");let j=!1;for(;;)switch(x){case"hex":return Q(this,o,u,g);case"utf8":case"utf-8":return N(this,o,u,g);case"ascii":case"latin1":case"binary":return V(this,o,u,g);case"base64":return ie(this,o,u,g);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return fe(this,o,u,g);default:if(j)throw new TypeError("Unknown encoding: "+x);x=(""+x).toLowerCase(),j=!0}},d.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function Re(p,o,u){return o===0&&u===p.length?e.fromByteArray(p):e.fromByteArray(p.slice(o,u))}function Te(p,o,u){u=Math.min(p.length,u);const g=[];let x=o;for(;x<u;){const O=p[x];let j=null,ne=O>239?4:O>223?3:O>191?2:1;if(x+ne<=u){let pe,ye,ge,ue;switch(ne){case 1:O<128&&(j=O);break;case 2:pe=p[x+1],(pe&192)===128&&(ue=(O&31)<<6|pe&63,ue>127&&(j=ue));break;case 3:pe=p[x+1],ye=p[x+2],(pe&192)===128&&(ye&192)===128&&(ue=(O&15)<<12|(pe&63)<<6|ye&63,ue>2047&&(ue<55296||ue>57343)&&(j=ue));break;case 4:pe=p[x+1],ye=p[x+2],ge=p[x+3],(pe&192)===128&&(ye&192)===128&&(ge&192)===128&&(ue=(O&15)<<18|(pe&63)<<12|(ye&63)<<6|ge&63,ue>65535&&ue<1114112&&(j=ue))}}j===null?(j=65533,ne=1):j>65535&&(j-=65536,g.push(j>>>10&1023|55296),j=56320|j&1023),g.push(j),x+=ne}return Ge(g)}const Pe=4096;function Ge(p){const o=p.length;if(o<=Pe)return String.fromCharCode.apply(String,p);let u="",g=0;for(;g<o;)u+=String.fromCharCode.apply(String,p.slice(g,g+=Pe));return u}function ct(p,o,u){let g="";u=Math.min(p.length,u);for(let x=o;x<u;++x)g+=String.fromCharCode(p[x]&127);return g}function Lt(p,o,u){let g="";u=Math.min(p.length,u);for(let x=o;x<u;++x)g+=String.fromCharCode(p[x]);return g}function ut(p,o,u){const g=p.length;(!o||o<0)&&(o=0),(!u||u<0||u>g)&&(u=g);let x="";for(let O=o;O<u;++O)x+=Ze[p[O]];return x}function Qe(p,o,u){const g=p.slice(o,u);let x="";for(let O=0;O<g.length-1;O+=2)x+=String.fromCharCode(g[O]+g[O+1]*256);return x}d.prototype.slice=function(o,u){const g=this.length;o=~~o,u=u===void 0?g:~~u,o<0?(o+=g,o<0&&(o=0)):o>g&&(o=g),u<0?(u+=g,u<0&&(u=0)):u>g&&(u=g),u<o&&(u=o);const x=this.subarray(o,u);return Object.setPrototypeOf(x,d.prototype),x};function we(p,o,u){if(p%1!==0||p<0)throw new RangeError("offset is not uint");if(p+o>u)throw new RangeError("Trying to access beyond buffer length")}d.prototype.readUintLE=d.prototype.readUIntLE=function(o,u,g){o=o>>>0,u=u>>>0,g||we(o,u,this.length);let x=this[o],O=1,j=0;for(;++j<u&&(O*=256);)x+=this[o+j]*O;return x},d.prototype.readUintBE=d.prototype.readUIntBE=function(o,u,g){o=o>>>0,u=u>>>0,g||we(o,u,this.length);let x=this[o+--u],O=1;for(;u>0&&(O*=256);)x+=this[o+--u]*O;return x},d.prototype.readUint8=d.prototype.readUInt8=function(o,u){return o=o>>>0,u||we(o,1,this.length),this[o]},d.prototype.readUint16LE=d.prototype.readUInt16LE=function(o,u){return o=o>>>0,u||we(o,2,this.length),this[o]|this[o+1]<<8},d.prototype.readUint16BE=d.prototype.readUInt16BE=function(o,u){return o=o>>>0,u||we(o,2,this.length),this[o]<<8|this[o+1]},d.prototype.readUint32LE=d.prototype.readUInt32LE=function(o,u){return o=o>>>0,u||we(o,4,this.length),(this[o]|this[o+1]<<8|this[o+2]<<16)+this[o+3]*16777216},d.prototype.readUint32BE=d.prototype.readUInt32BE=function(o,u){return o=o>>>0,u||we(o,4,this.length),this[o]*16777216+(this[o+1]<<16|this[o+2]<<8|this[o+3])},d.prototype.readBigUInt64LE=ke(function(o){o=o>>>0,Z(o,"offset");const u=this[o],g=this[o+7];(u===void 0||g===void 0)&&ae(o,this.length-8);const x=u+this[++o]*2**8+this[++o]*2**16+this[++o]*2**24,O=this[++o]+this[++o]*2**8+this[++o]*2**16+g*2**24;return BigInt(x)+(BigInt(O)<<BigInt(32))}),d.prototype.readBigUInt64BE=ke(function(o){o=o>>>0,Z(o,"offset");const u=this[o],g=this[o+7];(u===void 0||g===void 0)&&ae(o,this.length-8);const x=u*2**24+this[++o]*2**16+this[++o]*2**8+this[++o],O=this[++o]*2**24+this[++o]*2**16+this[++o]*2**8+g;return(BigInt(x)<<BigInt(32))+BigInt(O)}),d.prototype.readIntLE=function(o,u,g){o=o>>>0,u=u>>>0,g||we(o,u,this.length);let x=this[o],O=1,j=0;for(;++j<u&&(O*=256);)x+=this[o+j]*O;return O*=128,x>=O&&(x-=Math.pow(2,8*u)),x},d.prototype.readIntBE=function(o,u,g){o=o>>>0,u=u>>>0,g||we(o,u,this.length);let x=u,O=1,j=this[o+--x];for(;x>0&&(O*=256);)j+=this[o+--x]*O;return O*=128,j>=O&&(j-=Math.pow(2,8*u)),j},d.prototype.readInt8=function(o,u){return o=o>>>0,u||we(o,1,this.length),this[o]&128?(255-this[o]+1)*-1:this[o]},d.prototype.readInt16LE=function(o,u){o=o>>>0,u||we(o,2,this.length);const g=this[o]|this[o+1]<<8;return g&32768?g|4294901760:g},d.prototype.readInt16BE=function(o,u){o=o>>>0,u||we(o,2,this.length);const g=this[o+1]|this[o]<<8;return g&32768?g|4294901760:g},d.prototype.readInt32LE=function(o,u){return o=o>>>0,u||we(o,4,this.length),this[o]|this[o+1]<<8|this[o+2]<<16|this[o+3]<<24},d.prototype.readInt32BE=function(o,u){return o=o>>>0,u||we(o,4,this.length),this[o]<<24|this[o+1]<<16|this[o+2]<<8|this[o+3]},d.prototype.readBigInt64LE=ke(function(o){o=o>>>0,Z(o,"offset");const u=this[o],g=this[o+7];(u===void 0||g===void 0)&&ae(o,this.length-8);const x=this[o+4]+this[o+5]*2**8+this[o+6]*2**16+(g<<24);return(BigInt(x)<<BigInt(32))+BigInt(u+this[++o]*2**8+this[++o]*2**16+this[++o]*2**24)}),d.prototype.readBigInt64BE=ke(function(o){o=o>>>0,Z(o,"offset");const u=this[o],g=this[o+7];(u===void 0||g===void 0)&&ae(o,this.length-8);const x=(u<<24)+this[++o]*2**16+this[++o]*2**8+this[++o];return(BigInt(x)<<BigInt(32))+BigInt(this[++o]*2**24+this[++o]*2**16+this[++o]*2**8+g)}),d.prototype.readFloatLE=function(o,u){return o=o>>>0,u||we(o,4,this.length),r.read(this,o,!0,23,4)},d.prototype.readFloatBE=function(o,u){return o=o>>>0,u||we(o,4,this.length),r.read(this,o,!1,23,4)},d.prototype.readDoubleLE=function(o,u){return o=o>>>0,u||we(o,8,this.length),r.read(this,o,!0,52,8)},d.prototype.readDoubleBE=function(o,u){return o=o>>>0,u||we(o,8,this.length),r.read(this,o,!1,52,8)};function Be(p,o,u,g,x,O){if(!d.isBuffer(p))throw new TypeError('"buffer" argument must be a Buffer instance');if(o>x||o<O)throw new RangeError('"value" argument is out of bounds');if(u+g>p.length)throw new RangeError("Index out of range")}d.prototype.writeUintLE=d.prototype.writeUIntLE=function(o,u,g,x){if(o=+o,u=u>>>0,g=g>>>0,!x){const ne=Math.pow(2,8*g)-1;Be(this,o,u,g,ne,0)}let O=1,j=0;for(this[u]=o&255;++j<g&&(O*=256);)this[u+j]=o/O&255;return u+g},d.prototype.writeUintBE=d.prototype.writeUIntBE=function(o,u,g,x){if(o=+o,u=u>>>0,g=g>>>0,!x){const ne=Math.pow(2,8*g)-1;Be(this,o,u,g,ne,0)}let O=g-1,j=1;for(this[u+O]=o&255;--O>=0&&(j*=256);)this[u+O]=o/j&255;return u+g},d.prototype.writeUint8=d.prototype.writeUInt8=function(o,u,g){return o=+o,u=u>>>0,g||Be(this,o,u,1,255,0),this[u]=o&255,u+1},d.prototype.writeUint16LE=d.prototype.writeUInt16LE=function(o,u,g){return o=+o,u=u>>>0,g||Be(this,o,u,2,65535,0),this[u]=o&255,this[u+1]=o>>>8,u+2},d.prototype.writeUint16BE=d.prototype.writeUInt16BE=function(o,u,g){return o=+o,u=u>>>0,g||Be(this,o,u,2,65535,0),this[u]=o>>>8,this[u+1]=o&255,u+2},d.prototype.writeUint32LE=d.prototype.writeUInt32LE=function(o,u,g){return o=+o,u=u>>>0,g||Be(this,o,u,4,4294967295,0),this[u+3]=o>>>24,this[u+2]=o>>>16,this[u+1]=o>>>8,this[u]=o&255,u+4},d.prototype.writeUint32BE=d.prototype.writeUInt32BE=function(o,u,g){return o=+o,u=u>>>0,g||Be(this,o,u,4,4294967295,0),this[u]=o>>>24,this[u+1]=o>>>16,this[u+2]=o>>>8,this[u+3]=o&255,u+4};function D(p,o,u,g,x){le(o,g,x,p,u,7);let O=Number(o&BigInt(4294967295));p[u++]=O,O=O>>8,p[u++]=O,O=O>>8,p[u++]=O,O=O>>8,p[u++]=O;let j=Number(o>>BigInt(32)&BigInt(4294967295));return p[u++]=j,j=j>>8,p[u++]=j,j=j>>8,p[u++]=j,j=j>>8,p[u++]=j,u}function P(p,o,u,g,x){le(o,g,x,p,u,7);let O=Number(o&BigInt(4294967295));p[u+7]=O,O=O>>8,p[u+6]=O,O=O>>8,p[u+5]=O,O=O>>8,p[u+4]=O;let j=Number(o>>BigInt(32)&BigInt(4294967295));return p[u+3]=j,j=j>>8,p[u+2]=j,j=j>>8,p[u+1]=j,j=j>>8,p[u]=j,u+8}d.prototype.writeBigUInt64LE=ke(function(o,u=0){return D(this,o,u,BigInt(0),BigInt("0xffffffffffffffff"))}),d.prototype.writeBigUInt64BE=ke(function(o,u=0){return P(this,o,u,BigInt(0),BigInt("0xffffffffffffffff"))}),d.prototype.writeIntLE=function(o,u,g,x){if(o=+o,u=u>>>0,!x){const pe=Math.pow(2,8*g-1);Be(this,o,u,g,pe-1,-pe)}let O=0,j=1,ne=0;for(this[u]=o&255;++O<g&&(j*=256);)o<0&&ne===0&&this[u+O-1]!==0&&(ne=1),this[u+O]=(o/j>>0)-ne&255;return u+g},d.prototype.writeIntBE=function(o,u,g,x){if(o=+o,u=u>>>0,!x){const pe=Math.pow(2,8*g-1);Be(this,o,u,g,pe-1,-pe)}let O=g-1,j=1,ne=0;for(this[u+O]=o&255;--O>=0&&(j*=256);)o<0&&ne===0&&this[u+O+1]!==0&&(ne=1),this[u+O]=(o/j>>0)-ne&255;return u+g},d.prototype.writeInt8=function(o,u,g){return o=+o,u=u>>>0,g||Be(this,o,u,1,127,-128),o<0&&(o=255+o+1),this[u]=o&255,u+1},d.prototype.writeInt16LE=function(o,u,g){return o=+o,u=u>>>0,g||Be(this,o,u,2,32767,-32768),this[u]=o&255,this[u+1]=o>>>8,u+2},d.prototype.writeInt16BE=function(o,u,g){return o=+o,u=u>>>0,g||Be(this,o,u,2,32767,-32768),this[u]=o>>>8,this[u+1]=o&255,u+2},d.prototype.writeInt32LE=function(o,u,g){return o=+o,u=u>>>0,g||Be(this,o,u,4,2147483647,-2147483648),this[u]=o&255,this[u+1]=o>>>8,this[u+2]=o>>>16,this[u+3]=o>>>24,u+4},d.prototype.writeInt32BE=function(o,u,g){return o=+o,u=u>>>0,g||Be(this,o,u,4,2147483647,-2147483648),o<0&&(o=4294967295+o+1),this[u]=o>>>24,this[u+1]=o>>>16,this[u+2]=o>>>8,this[u+3]=o&255,u+4},d.prototype.writeBigInt64LE=ke(function(o,u=0){return D(this,o,u,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),d.prototype.writeBigInt64BE=ke(function(o,u=0){return P(this,o,u,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function G(p,o,u,g,x,O){if(u+g>p.length)throw new RangeError("Index out of range");if(u<0)throw new RangeError("Index out of range")}function X(p,o,u,g,x){return o=+o,u=u>>>0,x||G(p,o,u,4),r.write(p,o,u,g,23,4),u+4}d.prototype.writeFloatLE=function(o,u,g){return X(this,o,u,!0,g)},d.prototype.writeFloatBE=function(o,u,g){return X(this,o,u,!1,g)};function re(p,o,u,g,x){return o=+o,u=u>>>0,x||G(p,o,u,8),r.write(p,o,u,g,52,8),u+8}d.prototype.writeDoubleLE=function(o,u,g){return re(this,o,u,!0,g)},d.prototype.writeDoubleBE=function(o,u,g){return re(this,o,u,!1,g)},d.prototype.copy=function(o,u,g,x){if(!d.isBuffer(o))throw new TypeError("argument should be a Buffer");if(g||(g=0),!x&&x!==0&&(x=this.length),u>=o.length&&(u=o.length),u||(u=0),x>0&&x<g&&(x=g),x===g||o.length===0||this.length===0)return 0;if(u<0)throw new RangeError("targetStart out of bounds");if(g<0||g>=this.length)throw new RangeError("Index out of range");if(x<0)throw new RangeError("sourceEnd out of bounds");x>this.length&&(x=this.length),o.length-u<x-g&&(x=o.length-u+g);const O=x-g;return this===o&&typeof i.prototype.copyWithin=="function"?this.copyWithin(u,g,x):i.prototype.set.call(o,this.subarray(g,x),u),O},d.prototype.fill=function(o,u,g,x){if(typeof o=="string"){if(typeof u=="string"?(x=u,u=0,g=this.length):typeof g=="string"&&(x=g,g=this.length),x!==void 0&&typeof x!="string")throw new TypeError("encoding must be a string");if(typeof x=="string"&&!d.isEncoding(x))throw new TypeError("Unknown encoding: "+x);if(o.length===1){const j=o.charCodeAt(0);(x==="utf8"&&j<128||x==="latin1")&&(o=j)}}else typeof o=="number"?o=o&255:typeof o=="boolean"&&(o=Number(o));if(u<0||this.length<u||this.length<g)throw new RangeError("Out of range index");if(g<=u)return this;u=u>>>0,g=g===void 0?this.length:g>>>0,o||(o=0);let O;if(typeof o=="number")for(O=u;O<g;++O)this[O]=o;else{const j=d.isBuffer(o)?o:d.from(o,x),ne=j.length;if(ne===0)throw new TypeError('The value "'+o+'" is invalid for argument "value"');for(O=0;O<g-u;++O)this[O+u]=j[O%ne]}return this};const b={};function E(p,o,u){b[p]=class extends u{constructor(){super(),Object.defineProperty(this,"message",{value:o.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${p}]`,this.stack,delete this.name}get code(){return p}set code(x){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:x,writable:!0})}toString(){return`${this.name} [${p}]: ${this.message}`}}}E("ERR_BUFFER_OUT_OF_BOUNDS",function(p){return p?`${p} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),E("ERR_INVALID_ARG_TYPE",function(p,o){return`The "${p}" argument must be of type number. Received type ${typeof o}`},TypeError),E("ERR_OUT_OF_RANGE",function(p,o,u){let g=`The value of "${p}" is out of range.`,x=u;return Number.isInteger(u)&&Math.abs(u)>2**32?x=H(String(u)):typeof u=="bigint"&&(x=String(u),(u>BigInt(2)**BigInt(32)||u<-(BigInt(2)**BigInt(32)))&&(x=H(x)),x+="n"),g+=` It must be ${o}. Received ${x}`,g},RangeError);function H(p){let o="",u=p.length;const g=p[0]==="-"?1:0;for(;u>=g+4;u-=3)o=`_${p.slice(u-3,u)}${o}`;return`${p.slice(0,u)}${o}`}function Y(p,o,u){Z(o,"offset"),(p[o]===void 0||p[o+u]===void 0)&&ae(o,p.length-(u+1))}function le(p,o,u,g,x,O){if(p>u||p<o){const j=typeof o=="bigint"?"n":"";let ne;throw o===0||o===BigInt(0)?ne=`>= 0${j} and < 2${j} ** ${(O+1)*8}${j}`:ne=`>= -(2${j} ** ${(O+1)*8-1}${j}) and < 2 ** ${(O+1)*8-1}${j}`,new b.ERR_OUT_OF_RANGE("value",ne,p)}Y(g,x,O)}function Z(p,o){if(typeof p!="number")throw new b.ERR_INVALID_ARG_TYPE(o,"number",p)}function ae(p,o,u){throw Math.floor(p)!==p?(Z(p,u),new b.ERR_OUT_OF_RANGE("offset","an integer",p)):o<0?new b.ERR_BUFFER_OUT_OF_BOUNDS:new b.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${o}`,p)}const ft=/[^+/0-9A-Za-z-_]/g;function Tt(p){if(p=p.split("=")[0],p=p.trim().replace(ft,""),p.length<2)return"";for(;p.length%4!==0;)p=p+"=";return p}function vt(p,o){o=o||1/0;let u;const g=p.length;let x=null;const O=[];for(let j=0;j<g;++j){if(u=p.charCodeAt(j),u>55295&&u<57344){if(!x){if(u>56319){(o-=3)>-1&&O.push(239,191,189);continue}else if(j+1===g){(o-=3)>-1&&O.push(239,191,189);continue}x=u;continue}if(u<56320){(o-=3)>-1&&O.push(239,191,189),x=u;continue}u=(x-55296<<10|u-56320)+65536}else x&&(o-=3)>-1&&O.push(239,191,189);if(x=null,u<128){if((o-=1)<0)break;O.push(u)}else if(u<2048){if((o-=2)<0)break;O.push(u>>6|192,u&63|128)}else if(u<65536){if((o-=3)<0)break;O.push(u>>12|224,u>>6&63|128,u&63|128)}else if(u<1114112){if((o-=4)<0)break;O.push(u>>18|240,u>>12&63|128,u>>6&63|128,u&63|128)}else throw new Error("Invalid code point")}return O}function hr(p){const o=[];for(let u=0;u<p.length;++u)o.push(p.charCodeAt(u)&255);return o}function Ee(p,o){let u,g,x;const O=[];for(let j=0;j<p.length&&!((o-=2)<0);++j)u=p.charCodeAt(j),g=u>>8,x=u%256,O.push(x),O.push(g);return O}function Ie(p){return e.toByteArray(Tt(p))}function Xe(p,o,u,g){let x;for(x=0;x<g&&!(x+u>=o.length||x>=p.length);++x)o[x+u]=p[x];return x}function Fe(p,o){return p instanceof o||p!=null&&p.constructor!=null&&p.constructor.name!=null&&p.constructor.name===o.name}function Je(p){return p!==p}const Ze=(function(){const p="0123456789abcdef",o=new Array(256);for(let u=0;u<16;++u){const g=u*16;for(let x=0;x<16;++x)o[g+x]=p[u]+p[x]}return o})();function ke(p){return typeof BigInt>"u"?xt:p}function xt(){throw new Error("BigInt not supported")}})(un);const mi=un.Buffer,It=un.Buffer;class qt extends Promise{#e;#t;constructor(e){super(r=>{r()}),this.#e=e}static from(e){return new qt(r=>{r(e())})}static resolve(e){return new qt(r=>{r(e)})}static reject(e){return new qt((r,n)=>{n(e)})}then(e,r){return this.#t??=new Promise(this.#e),this.#t.then(e,r)}catch(e){return this.#t??=new Promise(this.#e),this.#t.catch(e)}finally(e){return this.#t??=new Promise(this.#e),this.#t.finally(e)}}class bi{constructor(e){this.waiters=[],this.aborted=!1,this.remaining=e}async acquire(e){if(this.aborted)throw new Error("credit gate aborted");if(e?.aborted)throw e.reason??new Error("aborted");this.remaining>0?this.remaining--:await new Promise((r,n)=>{const s=()=>{this.waiters.splice(this.waiters.indexOf(i),1),n(e?.reason??new Error("aborted"))};e&&e.addEventListener("abort",s,{once:!0});const i=c=>{if(e&&e.removeEventListener("abort",s),c){n(new Error("credit gate aborted"));return}this.remaining--,r()};this.waiters.push(i)})}replenish(e){for(this.remaining+=e;this.waiters.length>0&&this.remaining>0;)this.waiters.shift()(!1)}abort(){for(this.aborted=!0;this.waiters.length>0;)this.waiters.shift()(!0)}}function fo(t){const e=t.reduce((s,i)=>s+i.byteLength,0),r=new Uint8Array(e);let n=0;for(const s of t)r.set(s,n),n+=s.byteLength;return r}function Ei(t){let e;if(t instanceof It)e=new Uint8Array(t.buffer,t.byteOffset,t.length);else if(t instanceof Uint8Array)e=t;else if(typeof t=="string")e=new TextEncoder().encode(t);else throw new Error("invalid chunk type: expected Buffer, Uint8Array, or string");return e}function Si(t){return new qt((e,r)=>{const n=[];t.on("data",s=>{const i=Ei(s);n.push(i)}),t.on("end",()=>{e(fo(n))}),t.on("error",s=>{r(s)})})}async function _i(t,e,r,n,s){if(t.byteLength===0)await r(void 0,void 0,!0);else for(let i=0;i<t.byteLength;i+=e){if(s?.aborted)throw s.reason??new Error("aborted");const c=Math.min(t.byteLength-i,e),l=t.subarray(i,i+c),h=i+c>=t.byteLength;n&&await n.acquire(s),await r(l,void 0,h)}}async function Ti(t,e,r,n,s){for await(const i of t){if(s?.aborted)throw s.reason??new Error("aborted");const c=Ei(i);if(c.byteLength!==0)for(let l=0;l<c.byteLength;l+=e){if(s?.aborted)throw s.reason??new Error("aborted");const h=Math.min(c.byteLength-l,e),w=c.subarray(l,l+h);n&&await n.acquire(s),await r(w,void 0,!1)}}if(s?.aborted)throw s.reason??new Error("aborted");await r(void 0,void 0,!0)}function vi(t,e,r){if(!(typeof t=="object"&&t!==null))throw new Error("invalid object");let n;const s=t[e],i=t[r];Object.defineProperty(t,e,{get:()=>{if(n==="f2")throw new Error(`field "${e}" is mutually exclusive with field "${r}" and "${r}" was already consumed`);return n="f1",s},enumerable:!0,configurable:!0}),Object.defineProperty(t,r,{get:()=>{if(n==="f1")throw new Error(`field "${r}" is mutually exclusive with field "${e}" and "${e}" was already consumed`);return n="f2",i},enumerable:!0,configurable:!0})}class De{constructor(){this.resources=[]}roll(...e){let r,n;if(e.length===1)r=void 0,n=e[0];else if(e.length===2)r=e[0],n=e[1];else throw new Error("invalid number of arguments");this.resources.push({resource:r,cleanup:n})}sub(){const e=new De;return this.roll(e,()=>{}),e}unroll(e=!0){try{let r;for(;this.resources.length>0;){const n=this.resources.pop(),s=n.resource,i=n.cleanup;if(r)s instanceof De?r=r.then(()=>s.unroll()):r=r.then(()=>i(s));else{let c;s instanceof De?c=s.unroll():c=i(s),c instanceof Promise&&(r=c)}}return r?e?r.catch(()=>{}):r:void 0}catch(r){if(e)return;throw r}}}function qe(t,e,r=!1){if(t instanceof Error&&e===void 0&&r===!1)return t;let n=t instanceof Error?t.message:String(t);if(e&&(n=`${e}: ${n}`),r&&t instanceof Error&&(n=`${n}
2
+ ${t.stack}`),t instanceof Error){const s=new Error(n,{cause:t});return s.stack=t.stack,s}else return new Error(n)}function wt(t,e){if(!e)return t?Promise.resolve():void 0;let r;try{r=e()}catch(n){if(t)return Promise.reject(n);throw n}if(!t&&r instanceof Promise)throw new Error("onfinally callback returned Promise in non-async context");return t&&!(r instanceof Promise)&&(r=Promise.resolve(r)),r}function Er(t,e){if(!e)return t?Promise.resolve():void 0;let r=e.unroll();if(!t&&r instanceof Promise)throw new Error("spool unroll returned Promise in non-async context");return t&&!(r instanceof Promise)&&(r=Promise.resolve(r)),r}function Ne(...t){let e,r,n,s,i,c;if(t.length===1&&typeof t[0]=="object"&&t[0]!==null?(e=t[0].description,r=t[0].spool,n=t[0].action,s=t[0].oncatch,i=t[0].onfinally,c=t[0].oncleanup):typeof t[0]=="string"?(e=t[0],t[1]instanceof De?(r=t[1],n=t[2],s=t[3],i=t[4],c=t[5]):(n=t[1],s=t[2],i=t[3],c=t[4])):t[0]instanceof De?(r=t[0],n=t[1],s=t[2],i=t[3],c=t[4]):(n=t[0],s=t[1],i=t[2],c=t[3]),c&&!r)throw new Error("oncleanup requires a spool");let l;try{l=n()}catch(h){let w=qe(h,e);if(s){try{l=s(w)}catch(d){throw w=qe(d,e),wt(!1,i),Er(!1,r),w}return wt(!1,i),l}throw wt(!1,i),Er(!1,r),w}return l instanceof Promise?l.then(async h=>(await wt(!0,i),r&&c&&r.roll(h,c),h),async h=>{let w=qe(h,e);if(s)try{const d=s(w);return await wt(!0,i),d}catch(d){throw w=qe(d,e),await wt(!0,i),await Er(!0,r),w}throw await wt(!0,i),await Er(!0,r),w}):(wt(!1,i),r&&c&&r.roll(l,c),l)}const Sr=new TextEncoder,Zt=new TextDecoder;function xi(...t){const e=t.reduce((s,{length:i})=>s+i,0),r=new Uint8Array(e);let n=0;for(const s of t)r.set(s,n),n+=s.length;return r}function jt(t){const e=new Uint8Array(t.length);for(let r=0;r<t.length;r++){const n=t.charCodeAt(r);if(n>127)throw new TypeError("non-ASCII string encountered in encode()");e[r]=n}return e}function lo(t){if(Uint8Array.prototype.toBase64)return t.toBase64();const e=32768,r=[];for(let n=0;n<t.length;n+=e)r.push(String.fromCharCode.apply(null,t.subarray(n,n+e)));return btoa(r.join(""))}function ho(t){if(Uint8Array.fromBase64)return Uint8Array.fromBase64(t);const e=atob(t),r=new Uint8Array(e.length);for(let n=0;n<e.length;n++)r[n]=e.charCodeAt(n);return r}function _r(t){if(Uint8Array.fromBase64)return Uint8Array.fromBase64(typeof t=="string"?t:Zt.decode(t),{alphabet:"base64url"});let e=t;e instanceof Uint8Array&&(e=Zt.decode(e)),e=e.replace(/-/g,"+").replace(/_/g,"/");try{return ho(e)}catch{throw new TypeError("The input to be decoded is not correctly encoded.")}}function hn(t){let e=t;return typeof e=="string"&&(e=Sr.encode(e)),Uint8Array.prototype.toBase64?e.toBase64({alphabet:"base64url",omitPadding:!0}):lo(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}class Kt extends Error{static code="ERR_JOSE_GENERIC";code="ERR_JOSE_GENERIC";constructor(e,r){super(e,r),this.name=this.constructor.name,Error.captureStackTrace?.(this,this.constructor)}}class it extends Kt{static code="ERR_JWT_CLAIM_VALIDATION_FAILED";code="ERR_JWT_CLAIM_VALIDATION_FAILED";claim;reason;payload;constructor(e,r,n="unspecified",s="unspecified"){super(e,{cause:{claim:n,reason:s,payload:r}}),this.claim=n,this.reason=s,this.payload=r}}class Ai extends Kt{static code="ERR_JWT_EXPIRED";code="ERR_JWT_EXPIRED";claim;reason;payload;constructor(e,r,n="unspecified",s="unspecified"){super(e,{cause:{claim:n,reason:s,payload:r}}),this.claim=n,this.reason=s,this.payload=r}}class Bt extends Kt{static code="ERR_JOSE_NOT_SUPPORTED";code="ERR_JOSE_NOT_SUPPORTED"}class Se extends Kt{static code="ERR_JWS_INVALID";code="ERR_JWS_INVALID"}class dn extends Kt{static code="ERR_JWT_INVALID";code="ERR_JWT_INVALID"}class po extends Kt{static code="ERR_JWS_SIGNATURE_VERIFICATION_FAILED";code="ERR_JWS_SIGNATURE_VERIFICATION_FAILED";constructor(e="signature verification failed",r){super(e,r)}}function Ri(t,e){const r=`SHA-${t.slice(-3)}`;switch(t){case"HS256":case"HS384":case"HS512":return{hash:r,name:"HMAC"};case"PS256":case"PS384":case"PS512":return{hash:r,name:"RSA-PSS",saltLength:parseInt(t.slice(-3),10)>>3};case"RS256":case"RS384":case"RS512":return{hash:r,name:"RSASSA-PKCS1-v1_5"};case"ES256":case"ES384":case"ES512":return{hash:r,name:"ECDSA",namedCurve:e.namedCurve};case"Ed25519":case"EdDSA":return{name:"Ed25519"};case"ML-DSA-44":case"ML-DSA-65":case"ML-DSA-87":return{name:t};default:throw new Bt(`alg ${t} is not supported either by JOSE or your javascript runtime`)}}function Ii(t,e){if(t.startsWith("RS")||t.startsWith("PS")){const{modulusLength:r}=e.algorithm;if(typeof r!="number"||r<2048)throw new TypeError(`${t} requires key modulusLength to be 2048 bits or larger`)}}const st=(t,e="algorithm.name")=>new TypeError(`CryptoKey does not support this operation, its ${e} must be ${t}`),Wt=(t,e)=>t.name===e;function pn(t){return parseInt(t.name.slice(4),10)}function yo(t){switch(t){case"ES256":return"P-256";case"ES384":return"P-384";case"ES512":return"P-521";default:throw new Error("unreachable")}}function wo(t,e){if(e&&!t.usages.includes(e))throw new TypeError(`CryptoKey does not support this operation, its usages must include ${e}.`)}function go(t,e,r){switch(e){case"HS256":case"HS384":case"HS512":{if(!Wt(t.algorithm,"HMAC"))throw st("HMAC");const n=parseInt(e.slice(2),10);if(pn(t.algorithm.hash)!==n)throw st(`SHA-${n}`,"algorithm.hash");break}case"RS256":case"RS384":case"RS512":{if(!Wt(t.algorithm,"RSASSA-PKCS1-v1_5"))throw st("RSASSA-PKCS1-v1_5");const n=parseInt(e.slice(2),10);if(pn(t.algorithm.hash)!==n)throw st(`SHA-${n}`,"algorithm.hash");break}case"PS256":case"PS384":case"PS512":{if(!Wt(t.algorithm,"RSA-PSS"))throw st("RSA-PSS");const n=parseInt(e.slice(2),10);if(pn(t.algorithm.hash)!==n)throw st(`SHA-${n}`,"algorithm.hash");break}case"Ed25519":case"EdDSA":{if(!Wt(t.algorithm,"Ed25519"))throw st("Ed25519");break}case"ML-DSA-44":case"ML-DSA-65":case"ML-DSA-87":{if(!Wt(t.algorithm,e))throw st(e);break}case"ES256":case"ES384":case"ES512":{if(!Wt(t.algorithm,"ECDSA"))throw st("ECDSA");const n=yo(e);if(t.algorithm.namedCurve!==n)throw st(n,"algorithm.namedCurve");break}default:throw new TypeError("CryptoKey does not support this operation")}wo(t,r)}function Bi(t,e,...r){if(r=r.filter(Boolean),r.length>2){const n=r.pop();t+=`one of type ${r.join(", ")}, or ${n}.`}else r.length===2?t+=`one of type ${r[0]} or ${r[1]}.`:t+=`of type ${r[0]}.`;return e==null?t+=` Received ${e}`:typeof e=="function"&&e.name?t+=` Received function ${e.name}`:typeof e=="object"&&e!=null&&e.constructor?.name&&(t+=` Received an instance of ${e.constructor.name}`),t}const mo=(t,...e)=>Bi("Key must be ",t,...e),Ni=(t,e,...r)=>Bi(`Key for the ${t} algorithm must be `,e,...r);async function ki(t,e,r){if(e instanceof Uint8Array){if(!t.startsWith("HS"))throw new TypeError(mo(e,"CryptoKey","KeyObject","JSON Web Key"));return crypto.subtle.importKey("raw",e,{hash:`SHA-${t.slice(-3)}`,name:"HMAC"},!1,[r])}return go(e,t,r),e}async function bo(t,e,r){const n=await ki(t,e,"sign");Ii(t,n);const s=await crypto.subtle.sign(Ri(t,n.algorithm),n,r);return new Uint8Array(s)}function Fi(...t){const e=t.filter(Boolean);if(e.length===0||e.length===1)return!0;let r;for(const n of e){const s=Object.keys(n);if(!r||r.size===0){r=new Set(s);continue}for(const i of s){if(r.has(i))return!1;r.add(i)}}return!0}const Ui=t=>{if(t?.[Symbol.toStringTag]==="CryptoKey")return!0;try{return t instanceof CryptoKey}catch{return!1}},Li=t=>t?.[Symbol.toStringTag]==="KeyObject",Mi=t=>Ui(t)||Li(t),Eo=t=>typeof t=="object"&&t!==null;function er(t){if(!Eo(t)||Object.prototype.toString.call(t)!=="[object Object]")return!1;if(Object.getPrototypeOf(t)===null)return!0;let e=t;for(;Object.getPrototypeOf(e)!==null;)e=Object.getPrototypeOf(e);return Object.getPrototypeOf(t)===e}const yn=t=>er(t)&&typeof t.kty=="string",So=t=>t.kty!=="oct"&&(t.kty==="AKP"&&typeof t.priv=="string"||typeof t.d=="string"),_o=t=>t.kty!=="oct"&&t.d===void 0&&t.priv===void 0,To=t=>t.kty==="oct"&&typeof t.k=="string",Ht=t=>t?.[Symbol.toStringTag],wn=(t,e,r)=>{if(e.use!==void 0){let n;switch(r){case"sign":case"verify":n="sig";break;case"encrypt":case"decrypt":n="enc";break}if(e.use!==n)throw new TypeError(`Invalid key for this operation, its "use" must be "${n}" when present`)}if(e.alg!==void 0&&e.alg!==t)throw new TypeError(`Invalid key for this operation, its "alg" must be "${t}" when present`);if(Array.isArray(e.key_ops)){let n;switch(!0){case(r==="sign"||r==="verify"):case t==="dir":case t.includes("CBC-HS"):n=r;break;case t.startsWith("PBES2"):n="deriveBits";break;case/^A\d{3}(?:GCM)?(?:KW)?$/.test(t):!t.includes("GCM")&&t.endsWith("KW")?n=r==="encrypt"?"wrapKey":"unwrapKey":n=r;break;case(r==="encrypt"&&t.startsWith("RSA")):n="wrapKey";break;case r==="decrypt":n=t.startsWith("RSA")?"unwrapKey":"deriveBits";break}if(n&&e.key_ops?.includes?.(n)===!1)throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${n}" when present`)}return!0},vo=(t,e,r)=>{if(!(e instanceof Uint8Array)){if(yn(e)){if(To(e)&&wn(t,e,r))return;throw new TypeError('JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present')}if(!Mi(e))throw new TypeError(Ni(t,e,"CryptoKey","KeyObject","JSON Web Key","Uint8Array"));if(e.type!=="secret")throw new TypeError(`${Ht(e)} instances for symmetric algorithms must be of type "secret"`)}},xo=(t,e,r)=>{if(yn(e))switch(r){case"decrypt":case"sign":if(So(e)&&wn(t,e,r))return;throw new TypeError("JSON Web Key for this operation must be a private JWK");case"encrypt":case"verify":if(_o(e)&&wn(t,e,r))return;throw new TypeError("JSON Web Key for this operation must be a public JWK")}if(!Mi(e))throw new TypeError(Ni(t,e,"CryptoKey","KeyObject","JSON Web Key"));if(e.type==="secret")throw new TypeError(`${Ht(e)} instances for asymmetric algorithms must not be of type "secret"`);if(e.type==="public")switch(r){case"sign":throw new TypeError(`${Ht(e)} instances for asymmetric algorithm signing must be of type "private"`);case"decrypt":throw new TypeError(`${Ht(e)} instances for asymmetric algorithm decryption must be of type "private"`)}if(e.type==="private")switch(r){case"verify":throw new TypeError(`${Ht(e)} instances for asymmetric algorithm verifying must be of type "public"`);case"encrypt":throw new TypeError(`${Ht(e)} instances for asymmetric algorithm encryption must be of type "public"`)}};function Pi(t,e,r){switch(t.substring(0,2)){case"A1":case"A2":case"di":case"HS":case"PB":vo(t,e,r);break;default:xo(t,e,r)}}function Di(t,e,r,n,s){if(s.crit!==void 0&&n?.crit===void 0)throw new t('"crit" (Critical) Header Parameter MUST be integrity protected');if(!n||n.crit===void 0)return new Set;if(!Array.isArray(n.crit)||n.crit.length===0||n.crit.some(c=>typeof c!="string"||c.length===0))throw new t('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');let i;r!==void 0?i=new Map([...Object.entries(r),...e.entries()]):i=e;for(const c of n.crit){if(!i.has(c))throw new Bt(`Extension Header Parameter "${c}" is not recognized`);if(s[c]===void 0)throw new t(`Extension Header Parameter "${c}" is missing`);if(i.get(c)&&n[c]===void 0)throw new t(`Extension Header Parameter "${c}" MUST be integrity protected`)}return new Set(n.crit)}function Ao(t){let e,r;switch(t.kty){case"AKP":{switch(t.alg){case"ML-DSA-44":case"ML-DSA-65":case"ML-DSA-87":e={name:t.alg},r=t.priv?["sign"]:["verify"];break;default:throw new Bt('Invalid or unsupported JWK "alg" (Algorithm) Parameter value')}break}case"RSA":{switch(t.alg){case"PS256":case"PS384":case"PS512":e={name:"RSA-PSS",hash:`SHA-${t.alg.slice(-3)}`},r=t.d?["sign"]:["verify"];break;case"RS256":case"RS384":case"RS512":e={name:"RSASSA-PKCS1-v1_5",hash:`SHA-${t.alg.slice(-3)}`},r=t.d?["sign"]:["verify"];break;case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":e={name:"RSA-OAEP",hash:`SHA-${parseInt(t.alg.slice(-3),10)||1}`},r=t.d?["decrypt","unwrapKey"]:["encrypt","wrapKey"];break;default:throw new Bt('Invalid or unsupported JWK "alg" (Algorithm) Parameter value')}break}case"EC":{switch(t.alg){case"ES256":e={name:"ECDSA",namedCurve:"P-256"},r=t.d?["sign"]:["verify"];break;case"ES384":e={name:"ECDSA",namedCurve:"P-384"},r=t.d?["sign"]:["verify"];break;case"ES512":e={name:"ECDSA",namedCurve:"P-521"},r=t.d?["sign"]:["verify"];break;case"ECDH-ES":case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":e={name:"ECDH",namedCurve:t.crv},r=t.d?["deriveBits"]:[];break;default:throw new Bt('Invalid or unsupported JWK "alg" (Algorithm) Parameter value')}break}case"OKP":{switch(t.alg){case"Ed25519":case"EdDSA":e={name:"Ed25519"},r=t.d?["sign"]:["verify"];break;case"ECDH-ES":case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":e={name:t.crv},r=t.d?["deriveBits"]:[];break;default:throw new Bt('Invalid or unsupported JWK "alg" (Algorithm) Parameter value')}break}default:throw new Bt('Invalid or unsupported JWK "kty" (Key Type) Parameter value')}return{algorithm:e,keyUsages:r}}async function Ro(t){if(!t.alg)throw new TypeError('"alg" argument is required when "jwk.alg" is not present');const{algorithm:e,keyUsages:r}=Ao(t),n={...t};return n.kty!=="AKP"&&delete n.alg,delete n.use,crypto.subtle.importKey("jwk",n,e,t.ext??!(t.d||t.priv),t.key_ops??r)}let Gt;const Oi=async(t,e,r,n=!1)=>{Gt||=new WeakMap;let s=Gt.get(t);if(s?.[r])return s[r];const i=await Ro({...e,alg:r});return n&&Object.freeze(t),s?s[r]=i:Gt.set(t,{[r]:i}),i},Io=(t,e)=>{Gt||=new WeakMap;let r=Gt.get(t);if(r?.[e])return r[e];const n=t.type==="public",s=!!n;let i;if(t.asymmetricKeyType==="x25519"){switch(e){case"ECDH-ES":case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":break;default:throw new TypeError("given KeyObject instance cannot be used for this algorithm")}i=t.toCryptoKey(t.asymmetricKeyType,s,n?[]:["deriveBits"])}if(t.asymmetricKeyType==="ed25519"){if(e!=="EdDSA"&&e!=="Ed25519")throw new TypeError("given KeyObject instance cannot be used for this algorithm");i=t.toCryptoKey(t.asymmetricKeyType,s,[n?"verify":"sign"])}switch(t.asymmetricKeyType){case"ml-dsa-44":case"ml-dsa-65":case"ml-dsa-87":{if(e!==t.asymmetricKeyType.toUpperCase())throw new TypeError("given KeyObject instance cannot be used for this algorithm");i=t.toCryptoKey(t.asymmetricKeyType,s,[n?"verify":"sign"])}}if(t.asymmetricKeyType==="rsa"){let c;switch(e){case"RSA-OAEP":c="SHA-1";break;case"RS256":case"PS256":case"RSA-OAEP-256":c="SHA-256";break;case"RS384":case"PS384":case"RSA-OAEP-384":c="SHA-384";break;case"RS512":case"PS512":case"RSA-OAEP-512":c="SHA-512";break;default:throw new TypeError("given KeyObject instance cannot be used for this algorithm")}if(e.startsWith("RSA-OAEP"))return t.toCryptoKey({name:"RSA-OAEP",hash:c},s,n?["encrypt"]:["decrypt"]);i=t.toCryptoKey({name:e.startsWith("PS")?"RSA-PSS":"RSASSA-PKCS1-v1_5",hash:c},s,[n?"verify":"sign"])}if(t.asymmetricKeyType==="ec"){const l=new Map([["prime256v1","P-256"],["secp384r1","P-384"],["secp521r1","P-521"]]).get(t.asymmetricKeyDetails?.namedCurve);if(!l)throw new TypeError("given KeyObject instance cannot be used for this algorithm");e==="ES256"&&l==="P-256"&&(i=t.toCryptoKey({name:"ECDSA",namedCurve:l},s,[n?"verify":"sign"])),e==="ES384"&&l==="P-384"&&(i=t.toCryptoKey({name:"ECDSA",namedCurve:l},s,[n?"verify":"sign"])),e==="ES512"&&l==="P-521"&&(i=t.toCryptoKey({name:"ECDSA",namedCurve:l},s,[n?"verify":"sign"])),e.startsWith("ECDH-ES")&&(i=t.toCryptoKey({name:"ECDH",namedCurve:l},s,n?[]:["deriveBits"]))}if(!i)throw new TypeError("given KeyObject instance cannot be used for this algorithm");return r?r[e]=i:Gt.set(t,{[e]:i}),i};async function Ci(t,e){if(t instanceof Uint8Array||Ui(t))return t;if(Li(t)){if(t.type==="secret")return t.export();if("toCryptoKey"in t&&typeof t.toCryptoKey=="function")try{return Io(t,e)}catch(n){if(n instanceof TypeError)throw n}let r=t.export({format:"jwk"});return Oi(t,r,e)}if(yn(t))return t.k?_r(t.k):Oi(t,t,e,!0);throw new Error("unreachable")}class Bo{#e;#t;#r;constructor(e){if(!(e instanceof Uint8Array))throw new TypeError("payload must be an instance of Uint8Array");this.#e=e}setProtectedHeader(e){if(this.#t)throw new TypeError("setProtectedHeader can only be called once");return this.#t=e,this}setUnprotectedHeader(e){if(this.#r)throw new TypeError("setUnprotectedHeader can only be called once");return this.#r=e,this}async sign(e,r){if(!this.#t&&!this.#r)throw new Se("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");if(!Fi(this.#t,this.#r))throw new Se("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");const n={...this.#t,...this.#r},s=Di(Se,new Map([["b64",!0]]),r?.crit,this.#t,n);let i=!0;if(s.has("b64")&&(i=this.#t.b64,typeof i!="boolean"))throw new Se('The "b64" (base64url-encode payload) Header Parameter must be a boolean');const{alg:c}=n;if(typeof c!="string"||!c)throw new Se('JWS "alg" (Algorithm) Header Parameter missing or invalid');Pi(c,e,"sign");let l,h;i?(l=hn(this.#e),h=jt(l)):(h=this.#e,l="");let w,d;this.#t?(w=hn(JSON.stringify(this.#t)),d=jt(w)):(w="",d=new Uint8Array);const I=xi(d,jt("."),h),v=await Ci(e,c),k=await bo(c,v,I),U={signature:hn(k),payload:l};return this.#r&&(U.header=this.#r),this.#t&&(U.protected=w),U}}class No{#e;constructor(e){this.#e=new Bo(e)}setProtectedHeader(e){return this.#e.setProtectedHeader(e),this}async sign(e,r){const n=await this.#e.sign(e,r);if(n.payload===void 0)throw new TypeError("use the flattened module for creating JWS with b64: false");return`${n.protected}.${n.payload}.${n.signature}`}}const gt=t=>Math.floor(t.getTime()/1e3),$i=60,qi=$i*60,gn=qi*24,ko=gn*7,Fo=gn*365.25,Uo=/^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;function tr(t){const e=Uo.exec(t);if(!e||e[4]&&e[1])throw new TypeError("Invalid time period format");const r=parseFloat(e[2]),n=e[3].toLowerCase();let s;switch(n){case"sec":case"secs":case"second":case"seconds":case"s":s=Math.round(r);break;case"minute":case"minutes":case"min":case"mins":case"m":s=Math.round(r*$i);break;case"hour":case"hours":case"hr":case"hrs":case"h":s=Math.round(r*qi);break;case"day":case"days":case"d":s=Math.round(r*gn);break;case"week":case"weeks":case"w":s=Math.round(r*ko);break;default:s=Math.round(r*Fo);break}return e[1]==="-"||e[4]==="ago"?-s:s}function Nt(t,e){if(!Number.isFinite(e))throw new TypeError(`Invalid ${t} input`);return e}const ji=t=>t.includes("/")?t.toLowerCase():`application/${t.toLowerCase()}`,Lo=(t,e)=>typeof t=="string"?e.includes(t):Array.isArray(t)?e.some(Set.prototype.has.bind(new Set(t))):!1;function Mo(t,e,r={}){let n;try{n=JSON.parse(Zt.decode(e))}catch{}if(!er(n))throw new dn("JWT Claims Set must be a top-level JSON object");const{typ:s}=r;if(s&&(typeof t.typ!="string"||ji(t.typ)!==ji(s)))throw new it('unexpected "typ" JWT header value',n,"typ","check_failed");const{requiredClaims:i=[],issuer:c,subject:l,audience:h,maxTokenAge:w}=r,d=[...i];w!==void 0&&d.push("iat"),h!==void 0&&d.push("aud"),l!==void 0&&d.push("sub"),c!==void 0&&d.push("iss");for(const U of new Set(d.reverse()))if(!(U in n))throw new it(`missing required "${U}" claim`,n,U,"missing");if(c&&!(Array.isArray(c)?c:[c]).includes(n.iss))throw new it('unexpected "iss" claim value',n,"iss","check_failed");if(l&&n.sub!==l)throw new it('unexpected "sub" claim value',n,"sub","check_failed");if(h&&!Lo(n.aud,typeof h=="string"?[h]:h))throw new it('unexpected "aud" claim value',n,"aud","check_failed");let I;switch(typeof r.clockTolerance){case"string":I=tr(r.clockTolerance);break;case"number":I=r.clockTolerance;break;case"undefined":I=0;break;default:throw new TypeError("Invalid clockTolerance option type")}const{currentDate:v}=r,k=gt(v||new Date);if((n.iat!==void 0||w)&&typeof n.iat!="number")throw new it('"iat" claim must be a number',n,"iat","invalid");if(n.nbf!==void 0){if(typeof n.nbf!="number")throw new it('"nbf" claim must be a number',n,"nbf","invalid");if(n.nbf>k+I)throw new it('"nbf" claim timestamp check failed',n,"nbf","check_failed")}if(n.exp!==void 0){if(typeof n.exp!="number")throw new it('"exp" claim must be a number',n,"exp","invalid");if(n.exp<=k-I)throw new Ai('"exp" claim timestamp check failed',n,"exp","check_failed")}if(w){const U=k-n.iat,$=typeof w=="number"?w:tr(w);if(U-I>$)throw new Ai('"iat" claim timestamp check failed (too far in the past)',n,"iat","check_failed");if(U<0-I)throw new it('"iat" claim timestamp check failed (it should be in the past)',n,"iat","check_failed")}return n}class Po{#e;constructor(e){if(!er(e))throw new TypeError("JWT Claims Set MUST be an object");this.#e=structuredClone(e)}data(){return Sr.encode(JSON.stringify(this.#e))}get iss(){return this.#e.iss}set iss(e){this.#e.iss=e}get sub(){return this.#e.sub}set sub(e){this.#e.sub=e}get aud(){return this.#e.aud}set aud(e){this.#e.aud=e}set jti(e){this.#e.jti=e}set nbf(e){typeof e=="number"?this.#e.nbf=Nt("setNotBefore",e):e instanceof Date?this.#e.nbf=Nt("setNotBefore",gt(e)):this.#e.nbf=gt(new Date)+tr(e)}set exp(e){typeof e=="number"?this.#e.exp=Nt("setExpirationTime",e):e instanceof Date?this.#e.exp=Nt("setExpirationTime",gt(e)):this.#e.exp=gt(new Date)+tr(e)}set iat(e){e===void 0?this.#e.iat=gt(new Date):e instanceof Date?this.#e.iat=Nt("setIssuedAt",gt(e)):typeof e=="string"?this.#e.iat=Nt("setIssuedAt",gt(new Date)+tr(e)):this.#e.iat=Nt("setIssuedAt",e)}}class Do{#e;#t;constructor(e={}){this.#t=new Po(e)}setIssuer(e){return this.#t.iss=e,this}setSubject(e){return this.#t.sub=e,this}setAudience(e){return this.#t.aud=e,this}setJti(e){return this.#t.jti=e,this}setNotBefore(e){return this.#t.nbf=e,this}setExpirationTime(e){return this.#t.exp=e,this}setIssuedAt(e){return this.#t.iat=e,this}setProtectedHeader(e){return this.#e=e,this}async sign(e,r){const n=new No(this.#t.data());if(n.setProtectedHeader(this.#e),Array.isArray(this.#e?.crit)&&this.#e.crit.includes("b64")&&this.#e.b64===!1)throw new dn("JWTs MUST NOT use unencoded payload");return n.sign(e,r)}}async function Oo(t,e,r,n){const s=await ki(t,e,"verify");Ii(t,s);const i=Ri(t,s.algorithm);try{return await crypto.subtle.verify(i,s,r,n)}catch{return!1}}async function Co(t,e,r){if(!er(t))throw new Se("Flattened JWS must be an object");if(t.protected===void 0&&t.header===void 0)throw new Se('Flattened JWS must have either of the "protected" or "header" members');if(t.protected!==void 0&&typeof t.protected!="string")throw new Se("JWS Protected Header incorrect type");if(t.payload===void 0)throw new Se("JWS Payload missing");if(typeof t.signature!="string")throw new Se("JWS Signature missing or incorrect type");if(t.header!==void 0&&!er(t.header))throw new Se("JWS Unprotected Header incorrect type");let n={};if(t.protected)try{const $=_r(t.protected);n=JSON.parse(Zt.decode($))}catch{throw new Se("JWS Protected Header is invalid")}if(!Fi(n,t.header))throw new Se("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");const s={...n,...t.header},i=Di(Se,new Map([["b64",!0]]),r?.crit,n,s);let c=!0;if(i.has("b64")&&(c=n.b64,typeof c!="boolean"))throw new Se('The "b64" (base64url-encode payload) Header Parameter must be a boolean');const{alg:l}=s;if(typeof l!="string"||!l)throw new Se('JWS "alg" (Algorithm) Header Parameter missing or invalid');if(c){if(typeof t.payload!="string")throw new Se("JWS Payload must be a string")}else if(typeof t.payload!="string"&&!(t.payload instanceof Uint8Array))throw new Se("JWS Payload must be a string or an Uint8Array instance");let h=!1;typeof e=="function"&&(e=await e(n,t),h=!0),Pi(l,e,"verify");const w=xi(t.protected!==void 0?jt(t.protected):new Uint8Array,jt("."),typeof t.payload=="string"?c?jt(t.payload):Sr.encode(t.payload):t.payload);let d;try{d=_r(t.signature)}catch{throw new Se("Failed to base64url decode the signature")}const I=await Ci(e,l);if(!await Oo(l,I,d,w))throw new po;let k;if(c)try{k=_r(t.payload)}catch{throw new Se("Failed to base64url decode the payload")}else typeof t.payload=="string"?k=Sr.encode(t.payload):k=t.payload;const U={payload:k};return t.protected!==void 0&&(U.protectedHeader=n),t.header!==void 0&&(U.unprotectedHeader=t.header),h?{...U,key:I}:U}async function $o(t,e,r){if(t instanceof Uint8Array&&(t=Zt.decode(t)),typeof t!="string")throw new Se("Compact JWS must be a string or Uint8Array");const{0:n,1:s,2:i,length:c}=t.split(".");if(c!==3)throw new Se("Invalid Compact JWS");const l=await Co({payload:s,protected:n,signature:i},e,r),h={payload:l.payload,protectedHeader:l.protectedHeader};return typeof e=="function"?{...h,key:l.key}:h}async function qo(t,e,r){const n=await $o(t,e,r);if(n.protectedHeader.crit?.includes("b64")&&n.protectedHeader.b64===!1)throw new dn("JWTs MUST NOT use unencoded payload");const i={payload:Mo(n.protectedHeader,n.payload,r),protectedHeader:n.protectedHeader};return typeof e=="function"?{...i,key:n.key}:i}function ot(t){return typeof t.saveState<"u"&&typeof t.restoreState<"u"&&typeof t.cleanSavedState<"u"}function mt(t){for(let e=0;e<t.length;e++)t[e]=0;return t}class jo{blockSize;digestLength;_inner;_outer;_finished=!1;_innerKeyedState;_outerKeyedState;constructor(e,r){this._inner=new e,this._outer=new e,this.blockSize=this._outer.blockSize,this.digestLength=this._outer.digestLength;const n=new Uint8Array(this.blockSize);r.length>this.blockSize?this._inner.update(r).finish(n).clean():n.set(r);for(let s=0;s<n.length;s++)n[s]^=54;this._inner.update(n);for(let s=0;s<n.length;s++)n[s]^=106;this._outer.update(n),ot(this._inner)&&ot(this._outer)&&(this._innerKeyedState=this._inner.saveState(),this._outerKeyedState=this._outer.saveState()),mt(n)}reset(){if(!ot(this._inner)||!ot(this._outer))throw new Error("hmac: can't reset() because hash doesn't implement restoreState()");return this._inner.restoreState(this._innerKeyedState),this._outer.restoreState(this._outerKeyedState),this._finished=!1,this}clean(){ot(this._inner)&&this._inner.cleanSavedState(this._innerKeyedState),ot(this._outer)&&this._outer.cleanSavedState(this._outerKeyedState),this._inner.clean(),this._outer.clean()}update(e){return this._inner.update(e),this}finish(e){return this._finished?(this._outer.finish(e),this):(this._inner.finish(e),this._outer.update(e.subarray(0,this.digestLength)).finish(e),this._finished=!0,this)}digest(){const e=new Uint8Array(this.digestLength);return this.finish(e),e}saveState(){if(!ot(this._inner))throw new Error("hmac: can't saveState() because hash doesn't implement it");return this._inner.saveState()}restoreState(e){if(!ot(this._inner)||!ot(this._outer))throw new Error("hmac: can't restoreState() because hash doesn't implement it");return this._inner.restoreState(e),this._outer.restoreState(this._outerKeyedState),this._finished=!1,this}cleanSavedState(e){if(!ot(this._inner))throw new Error("hmac: can't cleanSavedState() because hash doesn't implement it");this._inner.cleanSavedState(e)}}function Ko(t,e=0){return(t[e]<<24|t[e+1]<<16|t[e+2]<<8|t[e+3])>>>0}function Tr(t,e=new Uint8Array(4),r=0){return e[r+0]=t>>>24,e[r+1]=t>>>16,e[r+2]=t>>>8,e[r+3]=t>>>0,e}function Wo(t,e,r,n,s){const i=new jo(t,e),c=i.digestLength,l=new Uint8Array(4),h=new Uint8Array(c),w=new Uint8Array(c),d=new Uint8Array(s),I=i.update(r).saveState();for(let v=0;v*c<s;v++){Tr(v+1,l),i.restoreState(I).update(l).finish(w);for(let k=0;k<c;k++)h[k]=w[k];for(let k=2;k<=n;k++){i.reset().update(w).finish(w);for(let U=0;U<c;U++)h[U]^=w[U]}for(let k=0;k<c&&v*c+k<s;k++)d[v*c+k]=h[k]}return mt(h),mt(w),mt(l),i.cleanSavedState(I),i.clean(),d}const Ho=32,Go=64;class Jo{digestLength=Ho;blockSize=Go;_state=new Int32Array(8);_temp=new Int32Array(64);_buffer=new Uint8Array(128);_bufferLength=0;_bytesHashed=0;_finished=!1;constructor(){this.reset()}_initState(){this._state[0]=1779033703,this._state[1]=3144134277,this._state[2]=1013904242,this._state[3]=2773480762,this._state[4]=1359893119,this._state[5]=2600822924,this._state[6]=528734635,this._state[7]=1541459225}reset(){return this._initState(),this._bufferLength=0,this._bytesHashed=0,this._finished=!1,this}clean(){mt(this._buffer),mt(this._temp),this.reset()}update(e,r=e.length){if(this._finished)throw new Error("SHA256: can't update because hash was finished.");let n=0;if(this._bytesHashed+=r,this._bufferLength>0){for(;this._bufferLength<this.blockSize&&r>0;)this._buffer[this._bufferLength++]=e[n++],r--;this._bufferLength===this.blockSize&&(mn(this._temp,this._state,this._buffer,0,this.blockSize),this._bufferLength=0)}for(r>=this.blockSize&&(n=mn(this._temp,this._state,e,n,r),r%=this.blockSize);r>0;)this._buffer[this._bufferLength++]=e[n++],r--;return this}finish(e){if(!this._finished){const r=this._bytesHashed,n=this._bufferLength,s=r/536870912|0,i=r<<3,c=r%64<56?64:128;this._buffer[n]=128;for(let l=n+1;l<c-8;l++)this._buffer[l]=0;Tr(s,this._buffer,c-8),Tr(i,this._buffer,c-4),mn(this._temp,this._state,this._buffer,0,c),this._finished=!0}for(let r=0;r<this.digestLength/4;r++)Tr(this._state[r],e,r*4);return this}digest(){const e=new Uint8Array(this.digestLength);return this.finish(e),e}saveState(){if(this._finished)throw new Error("SHA256: cannot save finished state");return{state:new Int32Array(this._state),buffer:this._bufferLength>0?new Uint8Array(this._buffer):void 0,bufferLength:this._bufferLength,bytesHashed:this._bytesHashed}}restoreState(e){return this._state.set(e.state),this._bufferLength=e.bufferLength,e.buffer&&this._buffer.set(e.buffer),this._bytesHashed=e.bytesHashed,this._finished=!1,this}cleanSavedState(e){mt(e.state),e.buffer&&mt(e.buffer),e.bufferLength=0,e.bytesHashed=0}}const zo=new Int32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);function mn(t,e,r,n,s){for(;s>=64;){let i=e[0],c=e[1],l=e[2],h=e[3],w=e[4],d=e[5],I=e[6],v=e[7];for(let k=0;k<16;k++){let U=n+k*4;t[k]=Ko(r,U)}for(let k=16;k<64;k++){let U=t[k-2],$=(U>>>17|U<<15)^(U>>>19|U<<13)^U>>>10;U=t[k-15];let q=(U>>>7|U<<25)^(U>>>18|U<<14)^U>>>3;t[k]=($+t[k-7]|0)+(q+t[k-16]|0)}for(let k=0;k<64;k++){let U=(((w>>>6|w<<26)^(w>>>11|w<<21)^(w>>>25|w<<7))+(w&d^~w&I)|0)+(v+(zo[k]+t[k]|0)|0)|0,$=((i>>>2|i<<30)^(i>>>13|i<<19)^(i>>>22|i<<10))+(i&c^i&l^c&l)|0;v=I,I=d,d=w,w=h+U|0,h=l,l=c,c=i,i=U+$|0}e[0]+=i,e[1]+=c,e[2]+=l,e[3]+=h,e[4]+=w,e[5]+=d,e[6]+=I,e[7]+=v,n+=64,s-=64}return n}var Vo=pr();let bn;function Ki(t){return{lang:t?.lang??bn?.lang,message:t?.message,abortEarly:t?.abortEarly??bn?.abortEarly,abortPipeEarly:t?.abortPipeEarly??bn?.abortPipeEarly}}let Yo;function Qo(t){return Yo?.get(t)}let Xo;function Zo(t){return Xo?.get(t)}let ea;function ta(t,e){return ea?.get(t)?.get(e)}function vr(t){const e=typeof t;return e==="string"?`"${t}"`:e==="number"||e==="bigint"||e==="boolean"?`${t}`:e==="object"||e==="function"?(t&&Object.getPrototypeOf(t)?.constructor?.name)??"null":e}function Me(t,e,r,n,s){const i=s&&"input"in s?s.input:r.value,c=s?.expected??t.expects??null,l=s?.received??vr(i),h={kind:t.kind,type:t.type,input:i,expected:c,received:l,message:`Invalid ${e}: ${c?`Expected ${c} but r`:"R"}eceived ${l}`,requirement:t.requirement,path:s?.path,issues:s?.issues,lang:n.lang,abortEarly:n.abortEarly,abortPipeEarly:n.abortPipeEarly},w=t.kind==="schema",d=s?.message??t.message??ta(t.reference,h.lang)??(w?Zo(h.lang):null)??n.message??Qo(h.lang);d!==void 0&&(h.message=typeof d=="function"?d(h):d),w&&(r.typed=!1),r.issues?r.issues.push(h):r.issues=[h]}function ze(t){return{version:1,vendor:"valibot",validate(e){return t["~run"]({value:e},Ki())}}}function ra(t,e){return Object.hasOwn(t,e)&&e!=="__proto__"&&e!=="prototype"&&e!=="constructor"}function Wi(t,e){return{kind:"validation",type:"check",reference:Wi,async:!1,expects:null,requirement:t,message:e,"~run"(r,n){return r.typed&&!this.requirement(r.value)&&Me(this,"input",r,n),r}}}function rr(t){return{kind:"validation",type:"integer",reference:rr,async:!1,expects:null,requirement:Number.isInteger,message:t,"~run"(e,r){return e.typed&&!this.requirement(e.value)&&Me(this,"integer",e,r),e}}}function kt(t,e){return{kind:"validation",type:"max_length",reference:kt,async:!1,expects:`<=${t}`,requirement:t,message:e,"~run"(r,n){return r.typed&&r.value.length>this.requirement&&Me(this,"length",r,n,{received:`${r.value.length}`}),r}}}function nr(t,e){return{kind:"validation",type:"min_value",reference:nr,async:!1,expects:`>=${t instanceof Date?t.toJSON():vr(t)}`,requirement:t,message:e,"~run"(r,n){return r.typed&&!(r.value>=this.requirement)&&Me(this,"value",r,n,{received:r.value instanceof Date?r.value.toJSON():vr(r.value)}),r}}}function Hi(t,e){return{kind:"validation",type:"regex",reference:Hi,async:!1,expects:`${t}`,requirement:t,message:e,"~run"(r,n){return r.typed&&!this.requirement.test(r.value)&&Me(this,"format",r,n),r}}}function na(t,e,r){return typeof t.fallback=="function"?t.fallback(e,r):t.fallback}function Gi(t,e,r){return typeof t.default=="function"?t.default(e,r):t.default}function Jt(t,e){return{kind:"schema",type:"array",reference:Jt,expects:"Array",async:!1,item:t,message:e,get"~standard"(){return ze(this)},"~run"(r,n){const s=r.value;if(Array.isArray(s)){r.typed=!0,r.value=[];for(let i=0;i<s.length;i++){const c=s[i],l=this.item["~run"]({value:c},n);if(l.issues){const h={type:"array",origin:"value",input:s,key:i,value:c};for(const w of l.issues)w.path?w.path.unshift(h):w.path=[h],r.issues?.push(w);if(r.issues||(r.issues=l.issues),n.abortEarly){r.typed=!1;break}}l.typed||(r.typed=!1),r.value.push(l.value)}}else Me(this,"type",r,n);return r}}}function En(t){return{kind:"schema",type:"boolean",reference:En,expects:"boolean",async:!1,message:t,get"~standard"(){return ze(this)},"~run"(e,r){return typeof e.value=="boolean"?e.typed=!0:Me(this,"type",e,r),e}}}function Sn(t,e){return{kind:"schema",type:"instance",reference:Sn,expects:t.name,async:!1,class:t,message:e,get"~standard"(){return ze(this)},"~run"(r,n){return r.value instanceof this.class?r.typed=!0:Me(this,"type",r,n),r}}}function je(t,e){return{kind:"schema",type:"literal",reference:je,expects:vr(t),async:!1,literal:t,message:e,get"~standard"(){return ze(this)},"~run"(r,n){return r.value===this.literal?r.typed=!0:Me(this,"type",r,n),r}}}function ir(t){return{kind:"schema",type:"number",reference:ir,expects:"number",async:!1,message:t,get"~standard"(){return ze(this)},"~run"(e,r){return typeof e.value=="number"&&!isNaN(e.value)?e.typed=!0:Me(this,"type",e,r),e}}}function ce(t,e){return{kind:"schema",type:"optional",reference:ce,expects:`(${t.expects} | undefined)`,async:!1,wrapped:t,default:e,get"~standard"(){return ze(this)},"~run"(r,n){return r.value===void 0&&(this.default!==void 0&&(r.value=Gi(this,r,n)),r.value===void 0)?(r.typed=!0,r):this.wrapped["~run"](r,n)}}}function Ji(t,e,r){return{kind:"schema",type:"record",reference:Ji,expects:"Object",async:!1,key:t,value:e,message:r,get"~standard"(){return ze(this)},"~run"(n,s){const i=n.value;if(i&&typeof i=="object"){n.typed=!0,n.value={};for(const c in i)if(ra(i,c)){const l=i[c],h=this.key["~run"]({value:c},s);if(h.issues){const d={type:"object",origin:"key",input:i,key:c,value:l};for(const I of h.issues)I.path=[d],n.issues?.push(I);if(n.issues||(n.issues=h.issues),s.abortEarly){n.typed=!1;break}}const w=this.value["~run"]({value:l},s);if(w.issues){const d={type:"object",origin:"value",input:i,key:c,value:l};for(const I of w.issues)I.path?I.path.unshift(d):I.path=[d],n.issues?.push(I);if(n.issues||(n.issues=w.issues),s.abortEarly){n.typed=!1;break}}(!h.typed||!w.typed)&&(n.typed=!1),h.typed&&(n.value[h.value]=w.value)}}else Me(this,"type",n,s);return n}}}function Ke(t,e){return{kind:"schema",type:"strict_object",reference:Ke,expects:"Object",async:!1,entries:t,message:e,get"~standard"(){return ze(this)},"~run"(r,n){const s=r.value;if(s&&typeof s=="object"){r.typed=!0,r.value={};for(const i in this.entries){const c=this.entries[i];if(i in s||(c.type==="exact_optional"||c.type==="optional"||c.type==="nullish")&&c.default!==void 0){const l=i in s?s[i]:Gi(c),h=c["~run"]({value:l},n);if(h.issues){const w={type:"object",origin:"value",input:s,key:i,value:l};for(const d of h.issues)d.path?d.path.unshift(w):d.path=[w],r.issues?.push(d);if(r.issues||(r.issues=h.issues),n.abortEarly){r.typed=!1;break}}h.typed||(r.typed=!1),r.value[i]=h.value}else if(c.fallback!==void 0)r.value[i]=na(c);else if(c.type!=="exact_optional"&&c.type!=="optional"&&c.type!=="nullish"&&(Me(this,"key",r,n,{input:void 0,expected:`"${i}"`,path:[{type:"object",origin:"key",input:s,key:i,value:s[i]}]}),n.abortEarly))break}if(!r.issues||!n.abortEarly){for(const i in s)if(!(i in this.entries)){Me(this,"key",r,n,{input:i,expected:"never",path:[{type:"object",origin:"key",input:s,key:i,value:s[i]}]});break}}}else Me(this,"type",r,n);return r}}}function be(t){return{kind:"schema",type:"string",reference:be,expects:"string",async:!1,message:t,get"~standard"(){return ze(this)},"~run"(e,r){return typeof e.value=="string"?e.typed=!0:Me(this,"type",e,r),e}}}function Ft(){return{kind:"schema",type:"unknown",reference:Ft,expects:"unknown",async:!1,get"~standard"(){return ze(this)},"~run"(t){return t.typed=!0,t}}}function We(...t){return{...t[0],pipe:t,get"~standard"(){return ze(this)},"~run"(e,r){for(const n of t)if(n.kind!=="metadata"){if(e.issues&&(n.kind==="schema"||n.kind==="transformation")){e.typed=!1;break}(!e.issues||!r.abortEarly&&!r.abortPipeEarly)&&(e=n["~run"](e,r))}return e}}}function ia(t,e,r){const n=t["~run"]({value:e},Ki(r));return{typed:n.typed,success:!n.issues,output:n.value,issues:n.issues}}const z={POS_INT:0,NEG_INT:1,BYTE_STRING:2,UTF8_STRING:3,ARRAY:4,MAP:5,TAG:6,SIMPLE_FLOAT:7},oe={DATE_STRING:0,DATE_EPOCH:1,POS_BIGINT:2,NEG_BIGINT:3,CBOR:24,URI:32,BASE64URL:33,BASE64:34,DATE_EPOCH_DAYS:100,SET:258,JSON:262,WTF8:273,DATE_FULL:1004,REGEXP:21066,SELF_DESCRIBED:55799,INVALID_16:65535,INVALID_32:4294967295,INVALID_64:0xffffffffffffffffn},te={ZERO:0,ONE:24,TWO:25,FOUR:26,EIGHT:27,INDEFINITE:31},bt={FALSE:20,TRUE:21,NULL:22,UNDEFINED:23};let Ue=class{static BREAK=Symbol.for("github.com/hildjj/cbor2/break");static ENCODED=Symbol.for("github.com/hildjj/cbor2/cbor-encoded");static LENGTH=Symbol.for("github.com/hildjj/cbor2/length")};const xr={MIN:-(2n**63n),MAX:2n**64n-1n};let ee=class $r{static#e=new Map;tag;contents;constructor(e,r=void 0){this.tag=e,this.contents=r}get noChildren(){return!!$r.#e.get(this.tag)?.noChildren}static registerDecoder(e,r,n){const s=this.#e.get(e);return this.#e.set(e,r),s&&("comment"in r||(r.comment=s.comment),"noChildren"in r||(r.noChildren=s.noChildren)),n&&!r.comment&&(r.comment=()=>`(${n})`),s}static clearDecoder(e){const r=this.#e.get(e);return this.#e.delete(e),r}static getDecoder(e){return this.#e.get(e)}static getAllDecoders(){return new Map(this.#e)}*[Symbol.iterator](){yield this.contents}push(e){return this.contents=e,1}decode(e){const r=e?.tags?.get(this.tag)??(e?.ignoreGlobalTags?void 0:$r.#e.get(this.tag));return r?r(this,e):this}comment(e,r){const n=e?.tags?.get(this.tag)??(e?.ignoreGlobalTags?void 0:$r.#e.get(this.tag));if(n?.comment)return n.comment(this,e,r)}toCBOR(){return[this.tag,this.contents]}[Symbol.for("nodejs.util.inspect.custom")](e,r,n){return`${this.tag}(${n(this.contents,r)})`}};function Ar(t){if(t!=null&&typeof t=="object")return t[Ue.ENCODED]}function sa(t){if(t!=null&&typeof t=="object")return t[Ue.LENGTH]}function sr(t,e){Object.defineProperty(t,Ue.ENCODED,{configurable:!0,enumerable:!1,value:e})}function or(t,e){const r=Object(t);return sr(r,e),r}const _n=Symbol("CBOR_RANGES");function zi(t,e){Object.defineProperty(t,_n,{configurable:!1,enumerable:!1,writable:!1,value:e})}function Rr(t){return t[_n]}function oa(t){return Rr(t)!==void 0}function Tn(t,e=0,r=t.length-1){const n=t.subarray(e,r),s=Rr(t);if(s){const i=[];for(const c of s)if(c[0]>=e&&c[0]+c[1]<=r){const l=[...c];l[0]-=e,i.push(l)}i.length&&zi(n,i)}return n}function Vi(t){let e=Math.ceil(t.length/2);const r=new Uint8Array(e);e--;for(let n=t.length,s=n-2;n>=0;n=s,s-=2,e--)r[e]=parseInt(t.substring(s,n),16);return r}function Oe(t){return t.reduce((e,r)=>e+r.toString(16).padStart(2,"0"),"")}function aa(t){const e=t.reduce((c,l)=>c+l.length,0),r=t.some(c=>oa(c)),n=[],s=new Uint8Array(e);let i=0;for(const c of t){if(!(c instanceof Uint8Array))throw new TypeError(`Invalid array: ${c}`);if(s.set(c,i),r){const l=c[_n]??[[0,c.length]];for(const h of l)h[0]+=i;n.push(...l)}i+=c.length}return r&&zi(s,n),s}function vn(t){const e=atob(t);return Uint8Array.from(e,r=>r.codePointAt(0))}const ca={"-":"+",_:"/"};function ua(t){const e=t.replace(/[_-]/g,r=>ca[r]);return vn(e.padEnd(Math.ceil(e.length/4)*4,"="))}function fa(){const t=new Uint8Array(4),e=new Uint32Array(t.buffer);return!((e[0]=1)&t[0])}function Yi(t){let e="";for(const r of t){const n=r.codePointAt(0)?.toString(16).padStart(4,"0");e&&(e+=", "),e+=`U+${n}`}return e}class Qi{#e=new Map;registerEncoder(e,r){const n=this.#e.get(e);return this.#e.set(e,r),n}get(e){return this.#e.get(e)}delete(e){return this.#e.delete(e)}clear(){this.#e.clear()}}function Xi(t,e){const[r,n,s]=t,[i,c,l]=e,h=Math.min(s.length,l.length);for(let w=0;w<h;w++){const d=s[w]-l[w];if(d!==0)return d}return 0}class Ir{static defaultOptions={chunkSize:4096};#e;#t=[];#r=null;#n=0;#i=0;constructor(e={}){if(this.#e={...Ir.defaultOptions,...e},this.#e.chunkSize<8)throw new RangeError(`Expected size >= 8, got ${this.#e.chunkSize}`);this.#s()}get length(){return this.#i}read(){this.#c();const e=new Uint8Array(this.#i);let r=0;for(const n of this.#t)e.set(n,r),r+=n.length;return this.#s(),e}write(e){const r=e.length;r>this.#u()?(this.#c(),r>this.#e.chunkSize?(this.#t.push(e),this.#s()):(this.#s(),this.#t[this.#t.length-1].set(e),this.#n=r)):(this.#t[this.#t.length-1].set(e,this.#n),this.#n+=r),this.#i+=r}writeUint8(e){this.#o(1),this.#r.setUint8(this.#n,e),this.#a(1)}writeUint16(e,r=!1){this.#o(2),this.#r.setUint16(this.#n,e,r),this.#a(2)}writeUint32(e,r=!1){this.#o(4),this.#r.setUint32(this.#n,e,r),this.#a(4)}writeBigUint64(e,r=!1){this.#o(8),this.#r.setBigUint64(this.#n,e,r),this.#a(8)}writeInt16(e,r=!1){this.#o(2),this.#r.setInt16(this.#n,e,r),this.#a(2)}writeInt32(e,r=!1){this.#o(4),this.#r.setInt32(this.#n,e,r),this.#a(4)}writeBigInt64(e,r=!1){this.#o(8),this.#r.setBigInt64(this.#n,e,r),this.#a(8)}writeFloat32(e,r=!1){this.#o(4),this.#r.setFloat32(this.#n,e,r),this.#a(4)}writeFloat64(e,r=!1){this.#o(8),this.#r.setFloat64(this.#n,e,r),this.#a(8)}clear(){this.#i=0,this.#t=[],this.#s()}#s(){const e=new Uint8Array(this.#e.chunkSize);this.#t.push(e),this.#n=0,this.#r=new DataView(e.buffer,e.byteOffset,e.byteLength)}#c(){if(this.#n===0){this.#t.pop();return}const e=this.#t.length-1;this.#t[e]=this.#t[e].subarray(0,this.#n),this.#n=0,this.#r=null}#u(){const e=this.#t.length-1;return this.#t[e].length-this.#n}#o(e){this.#u()<e&&(this.#c(),this.#s())}#a(e){this.#n+=e,this.#i+=e}}const xn=1n<<15n,ar=0b11111n<<10n,Zi=1n<<9n,es=Zi-1n,ts=Zi|es,An=1n<<31n,cr=0b11111111n<<23n,rs=1n<<22n,ns=rs-1n,is=rs|ns,Br=1n<<63n,pt=0b11111111111n<<52n,ur=1n<<51n,Nr=ur-1n,ss=ur|Nr,os=Nr-(es<<42n),as=Nr-(ns<<29n),la={2:"0b",8:"0o",16:"0x"};var ha=(t=>(t[t.NATURAL=-2]="NATURAL",t[t.UNKNOWN=-1]="UNKNOWN",t[t.F16=2]="F16",t[t.F32=4]="F32",t[t.F64=8]="F64",t))(ha||{});function cs(t,e,r,n){let s="nan'";return t.quiet||(s+="!"),t.sign===-1&&(s+="-"),s+=n(Math.abs(t.payload),r),s+="'",s+=t.encodingIndicator,s}let da=class extends Number{#e;#t=-1;constructor(e,r=!0,n=-1){super(NaN);const s=e;if(typeof e=="number"){if(!Number.isSafeInteger(e))throw new Error(`Invalid NAN payload: ${e}`);e=BigInt(e);let i=0n;if(e<0&&(i=Br,e=-e),e>=ur)throw new Error(`Payload too large: ${s}`);const c=r?ur:0n;switch(this.#e=i|pt|c|e,n){case-2:throw new Error("NAN_SIZE.NATURAL only valid for bigint constructor");case-1:n=this.preferredSize;break;case 2:if(this.#e&os)throw new Error("Invalid size for payload");break;case 4:if(this.#e&as)throw new Error("Invalid size for payload");break;case 8:break;default:throw new Error(`Invalid size: ${n}`)}this.#t=n}else if(typeof e=="bigint"){let i=-1;if((e&pt)===pt)this.#e=e,i=8;else if((e&cr)===cr){const c=(e&An)<<32n;this.#e=c|pt|(e&is)<<29n,i=4}else if((e&ar)===ar){const c=(e&xn)<<48n;this.#e=c|pt|(e&ts)<<42n,i=2}else throw new Error(`Invalid raw NaN value: ${e}`);if(n===-1)this.#t=this.preferredSize;else if(n===-2)this.#t=i;else{if(n<i)throw new Error("Invalid bigint NaN size");this.#t=n}}else{const i=new DataView(e.buffer,e.byteOffset,e.byteLength);switch(e.length){case 3:{if(e[0]!==249)throw new Error("Invalid CBOR encoding for half float");const c=BigInt(i.getUint16(1,!1));if((c&ar)!==ar)throw new Error("Not a NaN");const l=(c&xn)<<48n;this.#e=l|pt|(c&ts)<<42n,this.#t=2;break}case 5:{if(e[0]!==250)throw new Error("Invalid CBOR encoding for single float");const c=BigInt(i.getUint32(1,!1));if((c&cr)!==cr)throw new Error("Not a NaN");const l=(c&An)<<32n;this.#e=l|pt|(c&is)<<29n,this.#t=4;break}case 9:{if(e[0]!==251)throw new Error("Invalid CBOR encoding for double float");if(this.#e=i.getBigUint64(1,!1),(this.#e&pt)!==pt)throw new Error("Not a NaN (NaNaN)");this.#t=8;break}default:throw new RangeError(`Invalid NAN size (should be 2, 4, or 8): ${e.length-1}`)}}if(!this.payload&&!this.quiet)throw new Error("Signalling NaN with zero payload")}get bytes(){const e=new ArrayBuffer(this.#t+1),r=new DataView(e);switch(this.#t){case 2:{r.setUint8(0,249);const n=(this.#e&Br?xn:0n)|ar|(this.#e&ss)>>42n;r.setUint16(1,Number(n),!1);break}case 4:{r.setUint8(0,250);const n=(this.#e&Br?An:0n)|cr|(this.#e&ss)>>29n;r.setUint32(1,Number(n),!1);break}case 8:r.setUint8(0,251),r.setBigUint64(1,this.#e);break}return new Uint8Array(e)}get quiet(){return!!(this.#e&ur)}get sign(){return this.#e&Br?-1:1}get payload(){return Number(this.#e&Nr)*this.sign}get raw(){return this.#e}get encodingIndicator(){switch(this.#t){case 2:return"_1";case 4:return"_2"}return"_3"}get size(){return this.#t}get preferredSize(){return(this.#e&os)===0n?2:(this.#e&as)===0n?4:8}get isShortestEncoding(){return this.preferredSize===this.#t}toCBOR(e){e.write(this.bytes)}toString(e=10){return cs(this,1,{},r=>(la[e]??"")+r.toString(e))}[Symbol.for("nodejs.util.inspect.custom")](e,r,n){return cs(this,e,r,n)}};function us(t,e=0,r=!1){const n=t[e]&128?-1:1,s=(t[e]&124)>>2,i=(t[e]&3)<<8|t[e+1];if(s===0){if(r&&i!==0)throw new Error(`Unwanted subnormal: ${n*5960464477539063e-23*i}`);return n*5960464477539063e-23*i}else if(s===31)return i?NaN:n*(1/0);return n*2**(s-25)*(1024+i)}function fs(t){const e=new DataView(new ArrayBuffer(4));e.setFloat32(0,t,!1);const r=e.getUint32(0,!1);if((r&8191)!==0)return null;let n=r>>16&32768;const s=r>>23&255,i=r&8388607;if(!(s===0&&i===0))if(s>=113&&s<=142)n+=(s-112<<10)+(i>>13);else if(s>=103&&s<113){if(i&(1<<126-s)-1)return null;n+=i+8388608>>126-s}else if(s===255)n|=31744,n|=i>>13;else return null;return n}function pa(t){if(t!==0){const e=new ArrayBuffer(8),r=new DataView(e);r.setFloat64(0,t,!1);const n=r.getBigUint64(0,!1);if((n&0x7ff0000000000000n)===0n)return n&0x8000000000000000n?-0:0}return t}function ya(t){switch(t.length){case 2:us(t,0,!0);break;case 4:{const e=new DataView(t.buffer,t.byteOffset,t.byteLength),r=e.getUint32(0,!1);if((r&2139095040)===0&&r&8388607)throw new Error(`Unwanted subnormal: ${e.getFloat32(0,!1)}`);break}case 8:{const e=new DataView(t.buffer,t.byteOffset,t.byteLength),r=e.getBigUint64(0,!1);if((r&0x7ff0000000000000n)===0n&&r&0x000fffffffffffn)throw new Error(`Unwanted subnormal: ${e.getFloat64(0,!1)}`);break}default:throw new TypeError(`Bad input to isSubnormal: ${t}`)}}class wa extends TypeError{code="ERR_ENCODING_INVALID_ENCODED_DATA";constructor(){super("The encoded data was not valid for encoding wtf-8")}}class ga extends RangeError{code="ERR_ENCODING_NOT_SUPPORTED";constructor(e){super(`Invalid encoding: "${e}"`)}}const ma=65279,ls=new Uint8Array(0),ba=55296,Ea=56320,Sa=65533,hs="wtf-8";function _a(t){return t&&!(t instanceof ArrayBuffer)&&t.buffer instanceof ArrayBuffer}function Ta(t){return t?t instanceof Uint8Array?t:_a(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t):ls}const va=[0,0,0,0,0,0,0,0,-1,-1,-1,-1,1,1,2,3];class kr{static DEFAULT_BUFFERSIZE=4096;encoding=hs;fatal;ignoreBOM;bufferSize;#e=0;#t=0;#r=0;#n=!0;#i;constructor(e="wtf8",r=void 0){if(e.toLowerCase().replace("-","")!=="wtf8")throw new ga(e);if(this.fatal=!!r?.fatal,this.ignoreBOM=!!r?.ignoreBOM,this.bufferSize=Math.floor(r?.bufferSize??kr.DEFAULT_BUFFERSIZE),isNaN(this.bufferSize)||this.bufferSize<1)throw new RangeError(`Invalid buffer size: ${r?.bufferSize}`);this.#i=new Uint16Array(this.bufferSize)}decode(e,r){const n=!!r?.stream,s=Ta(e),i=[],c=this.#i,l=this.bufferSize-3;let h=0;const w=()=>{if(this.#t=0,this.#e=0,this.#r=0,this.fatal)throw new wa;c[h++]=Sa},d=()=>{const v=this.#r;for(let k=0;k<v;k++)w()},I=v=>{if(this.#e===0)switch(va[v>>4]){case-1:w();break;case 0:c[h++]=v;break;case 1:this.#t=v&31,(this.#t&30)===0?w():(this.#e=1,this.#r=1);break;case 2:this.#t=v&15,this.#e=2,this.#r=1;break;case 3:v&8?w():(this.#t=v&7,this.#e=3,this.#r=1);break}else{if((v&192)!==128||this.#r===1&&this.#e===2&&this.#t===0&&(v&32)===0||this.#e===3&&this.#t===0&&(v&48)===0)return d(),I(v);if(this.#t=this.#t<<6|v&63,this.#r++,--this.#e===0){if(this.ignoreBOM||!this.#n||this.#t!==ma)if(this.#t<65536)c[h++]=this.#t;else{const k=this.#t-65536;c[h++]=k>>>10&1023|ba,c[h++]=k&1023|Ea}this.#t=0,this.#r=0,this.#n=!1}}};for(const v of s)h>=l&&(i.push(String.fromCharCode.apply(null,c.subarray(0,h))),h=0),I(v);return n||(this.#n=!0,(this.#t||this.#e)&&d()),h>0&&i.push(String.fromCharCode.apply(null,c.subarray(0,h))),i.join("")}}function xa(t){let e=0;for(const r of t){const n=r.codePointAt(0);n<128?e++:n<2048?e+=2:n<65536?e+=3:e+=4}return e}class Aa{encoding=hs;encode(e){if(!e)return ls;const r=new Uint8Array(xa(String(e)));return this.encodeInto(e,r),r}encodeInto(e,r){const n=String(e),s=n.length,i=r.length;let c=0,l=0;for(l=0;l<s;l++){const h=n.codePointAt(l);if(h<128){if(c>=i)break;r[c++]=h}else if(h<2048){if(c>=i-1)break;r[c++]=192|h>>6,r[c++]=128|h&63}else if(h<65536){if(c>=i-2)break;r[c++]=224|h>>12,r[c++]=128|h>>6&63,r[c++]=128|h&63}else{if(c>=i-3)break;r[c++]=240|h>>18,r[c++]=128|h>>12&63,r[c++]=128|h>>6&63,r[c++]=128|h&63,l++}}return{read:l,written:c}}}const ds=z.SIMPLE_FLOAT<<5|te.TWO,Ra=z.SIMPLE_FLOAT<<5|te.FOUR,Ia=z.SIMPLE_FLOAT<<5|te.EIGHT,Ba=z.SIMPLE_FLOAT<<5|bt.TRUE,Na=z.SIMPLE_FLOAT<<5|bt.FALSE,ka=z.SIMPLE_FLOAT<<5|bt.UNDEFINED,Fa=z.SIMPLE_FLOAT<<5|bt.NULL,Ua=new TextEncoder,La=new Aa,ps={...Ir.defaultOptions,avoidInts:!1,cde:!1,collapseBigInts:!0,dateTag:oe.DATE_EPOCH,dcbor:!1,float64:!1,flushToZero:!1,forceEndian:null,ignoreOriginalEncoding:!1,largeNegativeAsBigInt:!1,reduceUnsafeNumbers:!1,rejectBigInts:!1,rejectCustomSimples:!1,rejectDuplicateKeys:!1,rejectFloats:!1,rejectUndefined:!1,simplifyNegativeZero:!1,sortKeys:null,stringNormalization:null,types:null,wtf8:!1,ignoreGlobalTags:!1},ys={cde:!0,ignoreOriginalEncoding:!0,sortKeys:Xi},Ma={...ys,dcbor:!0,largeNegativeAsBigInt:!0,reduceUnsafeNumbers:!0,rejectCustomSimples:!0,rejectDuplicateKeys:!0,rejectUndefined:!0,simplifyNegativeZero:!0,stringNormalization:"NFC"};function ws(t){const e=t<0;return typeof t=="bigint"?[e?-t-1n:t,e]:[e?-t-1:t,e]}function Rn(t,e,r){if(r.rejectFloats)throw new Error(`Attempt to encode an unwanted floating point number: ${t}`);if(isNaN(t))e.writeUint8(ds),e.writeUint16(32256);else if(!r.float64&&Math.fround(t)===t){const n=fs(t);n===null?(e.writeUint8(Ra),e.writeFloat32(t)):(e.writeUint8(ds),e.writeUint16(n))}else e.writeUint8(Ia),e.writeFloat64(t)}function He(t,e,r){const[n,s]=ws(t);if(s&&r)throw new TypeError(`Negative size: ${t}`);r??=s?z.NEG_INT:z.POS_INT,r<<=5,n<24?e.writeUint8(r|n):n<=255?(e.writeUint8(r|te.ONE),e.writeUint8(n)):n<=65535?(e.writeUint8(r|te.TWO),e.writeUint16(n)):n<=4294967295?(e.writeUint8(r|te.FOUR),e.writeUint32(n)):(e.writeUint8(r|te.EIGHT),e.writeBigUint64(BigInt(n)))}function fr(t,e,r){typeof t=="number"?He(t,e,z.TAG):typeof t=="object"&&!r.ignoreOriginalEncoding&&Ue.ENCODED in t?e.write(t[Ue.ENCODED]):t<=Number.MAX_SAFE_INTEGER?He(Number(t),e,z.TAG):(e.writeUint8(z.TAG<<5|te.EIGHT),e.writeBigUint64(BigInt(t)))}function gs(t,e,r){const[n,s]=ws(t);if(r.collapseBigInts&&(!r.largeNegativeAsBigInt||t>=-0x8000000000000000n)){if(n<=0xffffffffn){He(Number(t),e);return}if(n<=0xffffffffffffffffn){const w=(s?z.NEG_INT:z.POS_INT)<<5;e.writeUint8(w|te.EIGHT),e.writeBigUint64(n);return}}if(r.rejectBigInts)throw new Error(`Attempt to encode unwanted bigint: ${t}`);const i=s?oe.NEG_BIGINT:oe.POS_BIGINT,c=n.toString(16),l=c.length%2?"0":"";fr(i,e,r);const h=Vi(l+c);He(h.length,e,z.BYTE_STRING),e.write(h)}function Pa(t,e,r){r.flushToZero&&(t=pa(t)),Object.is(t,-0)?r.simplifyNegativeZero?r.avoidInts?Rn(0,e,r):He(0,e):Rn(t,e,r):!r.avoidInts&&Number.isSafeInteger(t)?He(t,e):r.reduceUnsafeNumbers&&Math.floor(t)===t&&t>=xr.MIN&&t<=xr.MAX?gs(BigInt(t),e,r):Rn(t,e,r)}function Da(t,e,r){const n=r.stringNormalization?t.normalize(r.stringNormalization):t;if(r.wtf8&&!t.isWellFormed()){const s=La.encode(n);fr(oe.WTF8,e,r),He(s.length,e,z.BYTE_STRING),e.write(s)}else{const s=Ua.encode(n);He(s.length,e,z.UTF8_STRING),e.write(s)}}function Oa(t,e,r){const n=t;In(n,n.length,z.ARRAY,e,r);for(const s of n)Ut(s,e,r)}function Ca(t,e){He(t.length,e,z.BYTE_STRING),e.write(t)}const Fr=new Qi;Fr.registerEncoder(Array,Oa),Fr.registerEncoder(Uint8Array,Ca);function _e(t,e){return Fr.registerEncoder(t,e)}function In(t,e,r,n,s){const i=sa(t);i&&!s.ignoreOriginalEncoding?n.write(i):He(e,n,r)}function $a(t,e,r){if(t===null){e.writeUint8(Fa);return}if(!r.ignoreOriginalEncoding&&Ue.ENCODED in t){e.write(t[Ue.ENCODED]);return}const n=t.constructor;if(n){const i=r.types?.get(n)??(r.ignoreGlobalTags?void 0:Fr.get(n));if(i){const c=i(t,e,r);if(c!==void 0){if(!Array.isArray(c)||c.length!==2)throw new Error("Invalid encoder return value");(typeof c[0]=="bigint"||isFinite(Number(c[0])))&&fr(c[0],e,r),Ut(c[1],e,r)}return}}if(typeof t.toCBOR=="function"){const i=t.toCBOR(e,r);i&&((typeof i[0]=="bigint"||isFinite(Number(i[0])))&&fr(i[0],e,r),Ut(i[1],e,r));return}if(typeof t.toJSON=="function"){Ut(t.toJSON(),e,r);return}const s=Object.entries(t).map(i=>[i[0],i[1],zt(i[0],r)]);r.sortKeys&&s.sort(r.sortKeys),In(t,s.length,z.MAP,e,r);for(const[i,c,l]of s)e.write(l),Ut(c,e,r)}function Ut(t,e,r){switch(typeof t){case"number":Pa(t,e,r);break;case"bigint":gs(t,e,r);break;case"string":Da(t,e,r);break;case"boolean":e.writeUint8(t?Ba:Na);break;case"undefined":if(r.rejectUndefined)throw new Error("Attempt to encode unwanted undefined.");e.writeUint8(ka);break;case"object":$a(t,e,r);break;case"symbol":throw new TypeError(`Unknown symbol: ${t.toString()}`);default:throw new TypeError(`Unknown type: ${typeof t}, ${String(t)}`)}}function zt(t,e={}){const r={...ps};e.dcbor?Object.assign(r,Ma):e.cde&&Object.assign(r,ys),Object.assign(r,e);const n=new Ir(r);return Ut(t,n,r),n.read()}var Ur=(t=>(t[t.NEVER=-1]="NEVER",t[t.PREFERRED=0]="PREFERRED",t[t.ALWAYS=1]="ALWAYS",t))(Ur||{});class at{static KnownSimple=new Map([[bt.FALSE,!1],[bt.TRUE,!0],[bt.NULL,null],[bt.UNDEFINED,void 0]]);value;constructor(e){this.value=e}static create(e){return at.KnownSimple.has(e)?at.KnownSimple.get(e):new at(e)}toCBOR(e,r){if(r.rejectCustomSimples)throw new Error(`Cannot encode non-standard Simple value: ${this.value}`);He(this.value,e,z.SIMPLE_FLOAT)}toString(){return`simple(${this.value})`}decode(){return at.KnownSimple.has(this.value)?at.KnownSimple.get(this.value):this}[Symbol.for("nodejs.util.inspect.custom")](e,r,n){return`simple(${n(this.value,r)})`}}const qa=new TextDecoder("utf8",{fatal:!0,ignoreBOM:!0});let Lr=class qs{static defaultOptions={maxDepth:1024,encoding:"hex",requirePreferred:!1};#e;#t;#r=0;#n;constructor(e,r){if(this.#n={...qs.defaultOptions,...r},typeof e=="string")switch(this.#n.encoding){case"hex":this.#e=Vi(e);break;case"base64":this.#e=vn(e);break;default:throw new TypeError(`Encoding not implemented: "${this.#n.encoding}"`)}else this.#e=e;this.#t=new DataView(this.#e.buffer,this.#e.byteOffset,this.#e.byteLength)}toHere(e){return Tn(this.#e,e,this.#r)}*[Symbol.iterator](){if(yield*this.#i(0),this.#r!==this.#e.length)throw new Error("Extra data in input")}*seq(){for(;this.#r<this.#e.length;)yield*this.#i(0)}*#i(e){if(e++>this.#n.maxDepth)throw new Error(`Maximum depth ${this.#n.maxDepth} exceeded`);const r=this.#r,n=this.#t.getUint8(this.#r++),s=n>>5,i=n&31;let c=i,l=!1,h=0;switch(i){case te.ONE:if(h=1,c=this.#t.getUint8(this.#r),s===z.SIMPLE_FLOAT){if(c<32)throw new Error(`Invalid simple encoding in extra byte: ${c}`);l=!0}else if(this.#n.requirePreferred&&c<24)throw new Error(`Unexpectedly long integer encoding (1) for ${c}`);break;case te.TWO:if(h=2,s===z.SIMPLE_FLOAT)c=us(this.#e,this.#r);else if(c=this.#t.getUint16(this.#r,!1),this.#n.requirePreferred&&c<=255)throw new Error(`Unexpectedly long integer encoding (2) for ${c}`);break;case te.FOUR:if(h=4,s===z.SIMPLE_FLOAT)c=this.#t.getFloat32(this.#r,!1);else if(c=this.#t.getUint32(this.#r,!1),this.#n.requirePreferred&&c<=65535)throw new Error(`Unexpectedly long integer encoding (4) for ${c}`);break;case te.EIGHT:{if(h=8,s===z.SIMPLE_FLOAT)c=this.#t.getFloat64(this.#r,!1);else if(c=this.#t.getBigUint64(this.#r,!1),c<=Number.MAX_SAFE_INTEGER&&(c=Number(c)),this.#n.requirePreferred&&c<=4294967295)throw new Error(`Unexpectedly long integer encoding (8) for ${c}`);break}case 28:case 29:case 30:throw new Error(`Additional info not implemented: ${i}`);case te.INDEFINITE:switch(s){case z.POS_INT:case z.NEG_INT:case z.TAG:throw new Error(`Invalid indefinite encoding for MT ${s}`);case z.SIMPLE_FLOAT:yield[s,i,Ue.BREAK,r,0];return}c=1/0;break;default:l=!0}switch(this.#r+=h,s){case z.POS_INT:yield[s,i,c,r,h];break;case z.NEG_INT:yield[s,i,typeof c=="bigint"?-1n-c:-1-Number(c),r,h];break;case z.BYTE_STRING:c===1/0?yield*this.#c(s,e,r):yield[s,i,this.#s(c),r,c];break;case z.UTF8_STRING:c===1/0?yield*this.#c(s,e,r):yield[s,i,qa.decode(this.#s(c)),r,c];break;case z.ARRAY:if(c===1/0)yield*this.#c(s,e,r,!1);else{const w=Number(c);yield[s,i,w,r,h];for(let d=0;d<w;d++)yield*this.#i(e+1)}break;case z.MAP:if(c===1/0)yield*this.#c(s,e,r,!1);else{const w=Number(c);yield[s,i,w,r,h];for(let d=0;d<w;d++)yield*this.#i(e),yield*this.#i(e)}break;case z.TAG:yield[s,i,c,r,h],yield*this.#i(e);break;case z.SIMPLE_FLOAT:{const w=c;l&&(c=at.create(Number(c))),yield[s,i,c,r,w];break}}}#s(e){const r=Tn(this.#e,this.#r,this.#r+=e);if(r.length!==e)throw new Error(`Unexpected end of stream reading ${e} bytes, got ${r.length}`);return r}*#c(e,r,n,s=!0){for(yield[e,te.INDEFINITE,1/0,n,1/0];;){const i=this.#i(r),c=i.next(),[l,h,w]=c.value;if(w===Ue.BREAK){yield c.value,i.next();return}if(s){if(l!==e)throw new Error(`Unmatched major type. Expected ${e}, got ${l}.`);if(h===te.INDEFINITE)throw new Error("New stream started in typed stream")}yield c.value,yield*i}}};const ja=new Map([[te.ZERO,1],[te.ONE,2],[te.TWO,3],[te.FOUR,5],[te.EIGHT,9]]),Ka=new Uint8Array(0);function Wa(t,e){return!e.boxed&&!e.preferMap&&t.every(([r])=>typeof r=="string")?Object.fromEntries(t):new Map(t)}let Ce=class js{static defaultDecodeOptions={...Lr.defaultOptions,ParentType:js,boxed:!1,cde:!1,dcbor:!1,diagnosticSizes:Ur.PREFERRED,collapseBigInts:!1,convertUnsafeIntsToFloat:!1,createObject:Wa,keepNanPayloads:!1,pretty:!1,preferBigInt:!1,preferMap:!1,rejectLargeNegatives:!1,rejectBigInts:!1,rejectDuplicateKeys:!1,rejectFloats:!1,rejectInts:!1,rejectLongLoundNaN:!1,rejectLongFloats:!1,rejectNegativeZero:!1,rejectSimple:!1,rejectStreaming:!1,rejectStringsNotNormalizedAs:null,rejectSubnormals:!1,rejectUndefined:!1,rejectUnsafeFloatInts:!1,saveOriginal:!1,sortKeys:null,tags:null,ignoreGlobalTags:!1};static cdeDecodeOptions={cde:!0,rejectStreaming:!0,requirePreferred:!0,sortKeys:Xi};static dcborDecodeOptions={...this.cdeDecodeOptions,dcbor:!0,convertUnsafeIntsToFloat:!0,rejectDuplicateKeys:!0,rejectLargeNegatives:!0,rejectLongLoundNaN:!0,rejectLongFloats:!0,rejectNegativeZero:!0,rejectSimple:!0,rejectUndefined:!0,rejectUnsafeFloatInts:!0,rejectStringsNotNormalizedAs:"NFC"};parent;mt;ai;left;offset;count=0;children=[];depth=0;#e;#t=null;constructor(e,r,n,s){if([this.mt,this.ai,,this.offset]=e,this.left=r,this.parent=n,this.#e=s,n&&(this.depth=n.depth+1),this.mt===z.MAP&&(this.#e.sortKeys||this.#e.rejectDuplicateKeys)&&(this.#t=[]),this.#e.rejectStreaming&&this.ai===te.INDEFINITE)throw new Error("Streaming not supported")}get isStreaming(){return this.left===1/0}get done(){return this.left===0}static create(e,r,n,s){const[i,c,l,h]=e;switch(i){case z.POS_INT:case z.NEG_INT:{if(n.rejectInts)throw new Error(`Unexpected integer: ${l}`);if(n.rejectLargeNegatives&&l<-0x8000000000000000n)throw new Error(`Invalid 65bit negative number: ${l}`);let w=l;return n.preferBigInt?w=BigInt(w):n.convertUnsafeIntsToFloat&&w>=xr.MIN&&w<=xr.MAX&&(w=Number(l)),n.boxed?or(w,s.toHere(h)):w}case z.SIMPLE_FLOAT:if(c>te.ONE){if(typeof l=="symbol")return l;if(n.rejectFloats)throw new Error(`Decoding unwanted floating point number: ${l}`);if(n.rejectNegativeZero&&Object.is(l,-0))throw new Error("Decoding negative zero");if(isNaN(l)){const w=s.toHere(h),d=new da(w);if(n.rejectLongLoundNaN){if(d.payload||w.length>3)throw new Error(`Invalid NaN encoding: "${Oe(w)}"`)}else if(n.keepNanPayloads&&(d.payload||d.sign===-1)){if(n.rejectLongFloats&&!d.isShortestEncoding)throw new Error(`NaN should have been encoded shorter: ${l}`);return d}}if(n.rejectSubnormals&&ya(s.toHere(h+1)),n.rejectLongFloats){const w=zt(l,{chunkSize:9,reduceUnsafeNumbers:n.rejectUnsafeFloatInts});if(w[0]>>5!==i)throw new Error(`Should have been encoded as int, not float: ${l}`);if(w.length<ja.get(c))throw new Error(`Number should have been encoded shorter: ${l}`)}if(typeof l=="number"&&n.boxed)return or(l,s.toHere(h))}else{if(n.rejectSimple&&l instanceof at)throw new Error(`Invalid simple value: ${l}`);if(n.rejectUndefined&&l===void 0)throw new Error("Unexpected undefined")}return l;case z.BYTE_STRING:case z.UTF8_STRING:if(l===1/0)return new n.ParentType(e,1/0,r,n);if(n.rejectStringsNotNormalizedAs&&typeof l=="string"){const w=l.normalize(n.rejectStringsNotNormalizedAs);if(l!==w)throw new Error(`String not normalized as "${n.rejectStringsNotNormalizedAs}", got [${Yi(l)}] instead of [${Yi(w)}]`)}return n.boxed?or(l,s.toHere(h)):l;case z.ARRAY:return new n.ParentType(e,l,r,n);case z.MAP:return new n.ParentType(e,l*2,r,n);case z.TAG:{const w=new n.ParentType(e,1,r,n);return w.children=new ee(l),w}}throw new TypeError(`Invalid major type: ${i}`)}static decodeToEncodeOpts(e){return{...ps,avoidInts:e.rejectInts,float64:!e.rejectLongFloats,flushToZero:e.rejectSubnormals,largeNegativeAsBigInt:e.rejectLargeNegatives,sortKeys:e.sortKeys}}push(e,r,n){if(this.children.push(e),this.#t){const s=Ar(e)||r.toHere(n);this.#t.push(s)}return--this.left}replaceLast(e,r,n){let s,i=-1/0;if(this.children instanceof ee?(i=0,s=this.children.contents,this.children.contents=e):(i=this.children.length-1,s=this.children[i],this.children[i]=e),this.#t){const c=Ar(e)||n.toHere(r.offset);this.#t[i]=c}return s}convert(e){let r;switch(this.mt){case z.ARRAY:r=this.children;break;case z.MAP:{const n=this.#r();if(this.#e.sortKeys){let s;for(const i of n){if(s&&this.#e.sortKeys(s,i)>=0)throw new Error(`Duplicate or out of order key: "0x${i[2]}"`);s=i}}else if(this.#e.rejectDuplicateKeys){const s=new Set;for(const[i,c,l]of n){const h=Oe(l);if(s.has(h))throw new Error(`Duplicate key: "0x${h}"`);s.add(h)}}r=this.#e.createObject(n,this.#e);break}case z.BYTE_STRING:return aa(this.children);case z.UTF8_STRING:{const n=this.children.join("");r=this.#e.boxed?or(n,e.toHere(this.offset)):n;break}case z.TAG:r=this.children.decode(this.#e);break;default:throw new TypeError(`Invalid mt on convert: ${this.mt}`)}return this.#e.saveOriginal&&r&&typeof r=="object"&&sr(r,e.toHere(this.offset)),r}#r(){const e=this.children,r=e.length;if(r%2)throw new Error("Missing map value");const n=new Array(r/2);if(this.#t)for(let s=0;s<r;s+=2)n[s>>1]=[e[s],e[s+1],this.#t[s]];else for(let s=0;s<r;s+=2)n[s>>1]=[e[s],e[s+1],Ka];return n}};const Bn=" ",Ha=new TextEncoder;class ms extends Ce{close="";quote='"';get isEmptyStream(){return(this.mt===z.UTF8_STRING||this.mt===z.BYTE_STRING)&&this.count===0}}function Et(t,e,r,n){let s="";if(e===te.INDEFINITE)s+="_";else{if(n.diagnosticSizes===Ur.NEVER)return"";{let i=n.diagnosticSizes===Ur.ALWAYS;if(!i){let c=te.ZERO;if(Object.is(r,-0))c=te.TWO;else if(t===z.POS_INT||t===z.NEG_INT){const l=r<0,h=typeof r=="bigint"?1n:1,w=l?-r-h:r;w<=23?c=Number(w):w<=255?c=te.ONE:w<=65535?c=te.TWO:w<=4294967295?c=te.FOUR:c=te.EIGHT}else isFinite(r)?Math.fround(r)===r?fs(r)==null?c=te.FOUR:c=te.TWO:c=te.EIGHT:c=te.TWO;i=c!==e}i&&(s+="_",e<te.ONE?s+="i":s+=String(e-24))}}return s}function Ga(t,e){const r={...Ce.defaultDecodeOptions,...e,ParentType:ms},n=new Lr(t,r);let s,i,c="";for(const l of n){const[h,w,d]=l;switch(s&&(s.count>0&&d!==Ue.BREAK&&(s.mt===z.MAP&&s.count%2?c+=": ":(c+=",",r.pretty||(c+=" "))),r.pretty&&(s.mt!==z.MAP||s.count%2===0)&&(c+=`
3
+ ${Bn.repeat(s.depth+1)}`)),i=Ce.create(l,s,r,n),h){case z.POS_INT:case z.NEG_INT:c+=String(d),c+=Et(h,w,d,r);break;case z.SIMPLE_FLOAT:if(d!==Ue.BREAK)if(typeof d=="number"){const I=Object.is(d,-0)?"-0.0":String(d);c+=I,isFinite(d)&&!/[.e]/.test(I)&&(c+=".0"),c+=Et(h,w,d,r)}else d instanceof at?(c+="simple(",c+=String(d.value),c+=Et(z.POS_INT,w,d.value,r),c+=")"):c+=String(d);break;case z.BYTE_STRING:d===1/0?(c+="(_ ",i.close=")",i.quote="'"):(c+="h'",c+=Oe(d),c+="'",c+=Et(z.POS_INT,w,d.length,r));break;case z.UTF8_STRING:d===1/0?(c+="(_ ",i.close=")"):(c+=JSON.stringify(d),c+=Et(z.POS_INT,w,Ha.encode(d).length,r));break;case z.ARRAY:{c+="[";const I=Et(z.POS_INT,w,d,r);c+=I,I&&(c+=" "),r.pretty&&d?i.close=`
4
+ ${Bn.repeat(i.depth)}]`:i.close="]";break}case z.MAP:{c+="{";const I=Et(z.POS_INT,w,d,r);c+=I,I&&(c+=" "),r.pretty&&d?i.close=`
5
+ ${Bn.repeat(i.depth)}}`:i.close="}";break}case z.TAG:c+=String(d),c+=Et(z.POS_INT,w,d,r),c+="(",i.close=")";break}if(i===Ue.BREAK)if(s?.isStreaming)s.left=0;else throw new Error("Unexpected BREAK");else s&&(s.count++,s.left--);for(i instanceof ms&&(s=i);s?.done;){if(s.isEmptyStream)c=c.slice(0,-3),c+=`${s.quote}${s.quote}_`;else{if(s.mt===z.MAP&&s.count%2!==0)throw new Error(`Odd streaming map size: ${s.count}`);c+=s.close}s=s.parent}}return c}const Ja=new TextDecoder;class Nn extends Ce{depth=0;leaf=!1;value;length;[Ue.ENCODED];constructor(e,r,n,s){super(e,r,n,s),this.parent?this.depth=this.parent.depth+1:this.depth=s.initialDepth,[,,this.value,,this.length]=e}numBytes(){switch(this.ai){case te.ONE:return 1;case te.TWO:return 2;case te.FOUR:return 4;case te.EIGHT:return 8}return 0}}function bs(t){return t instanceof Nn}function Mr(t,e){return t===1/0?"Indefinite":e?`${t} ${e}${t!==1&&t!==1n?"s":""}`:String(t)}function lr(t){return"".padStart(t," ")}function Es(t,e,r){let n="";n+=lr(t.depth*2);const s=Ar(t);n+=Oe(s.subarray(0,1));const i=t.numBytes();i&&(n+=" ",n+=Oe(s.subarray(1,i+1))),n=n.padEnd(e.minCol+1," "),n+="-- ",r!==void 0&&(n+=lr(t.depth*2),r!==""&&(n+=`[${r}] `));let c=!1;const[l]=t.children;switch(t.mt){case z.POS_INT:n+=`Unsigned: ${l}`,typeof l=="bigint"&&(n+="n");break;case z.NEG_INT:n+=`Negative: ${l}`,typeof l=="bigint"&&(n+="n");break;case z.BYTE_STRING:n+=`Bytes (Length: ${Mr(t.length)})`;break;case z.UTF8_STRING:n+=`UTF8 (Length: ${Mr(t.length)})`,t.length!==1/0&&(n+=`: ${JSON.stringify(l)}`);break;case z.ARRAY:n+=`Array (Length: ${Mr(t.value,"item")})`;break;case z.MAP:n+=`Map (Length: ${Mr(t.value,"pair")})`;break;case z.TAG:{n+=`Tag #${t.value}`;const h=t.children,[w]=h.contents.children,d=new ee(h.tag,w);sr(d,s);const I=d.comment(e,t.depth);I&&(n+=": ",n+=I),c||=d.noChildren;break}case z.SIMPLE_FLOAT:l===Ue.BREAK?n+="BREAK":t.ai>te.ONE?Object.is(l,-0)?n+="Float: -0":n+=`Float: ${l}`:(n+="Simple: ",l instanceof at?n+=l.value:n+=l);break}if(!c)if(t.leaf){if(n+=`
6
+ `,s.length>i+1){const h=lr((t.depth+1)*2),w=Rr(s);if(w?.length){w.sort((I,v)=>I[0]-v[0]||v[1]-I[1]);let d=0;for(const[I,v,k]of w)if(!(I<d)){if(d=I+v,k==="<<"){n+=lr(e.minCol+1),n+="--",n+=h,n+="<< ";const U=Tn(s,I,I+v),$=Rr(U);if($){const q=$.findIndex(([_,A,R])=>_===0&&A===v&&R==="<<");q>=0&&$.splice(q,1)}n+=Ga(U),n+=` >>
7
+ `,n+=Ss(U,{initialDepth:t.depth+1,minCol:e.minCol,noPrefixHex:!0});continue}else k==="'"&&(n+=lr(e.minCol+1),n+="--",n+=h,n+="'",n+=Ja.decode(s.subarray(I,I+v)),n+=`'
8
+ `);if(I>i)for(let U=I;U<I+v;U+=8){const $=Math.min(U+8,I+v);n+=h,n+=Oe(s.subarray(U,$)),n+=`
9
+ `}}}else for(let d=i+1;d<s.length;d+=8)n+=h,n+=Oe(s.subarray(d,d+8)),n+=`
10
10
  `}}else{n+=`
11
- `;let h=0;for(const w of t.children){if(rs(w)){let d=String(h);t.mt===z.MAP?d=h%2?`val ${(h-1)/2}`:`key ${h/2}`:t.mt===z.TAG&&(d=""),n+=ns(w,e,d)}h++}}return n}const la={...Oe.defaultDecodeOptions,initialDepth:0,noPrefixHex:!1,minCol:0};function is(t,e){const r={...la,...e,ParentType:vn,saveOriginal:!0},n=new Nr(t,r);let s,i;for(const l of n){if(i=Oe.create(l,s,r,n),l[2]===Fe.BREAK)if(s?.isStreaming)s.left=1;else throw new Error("Unexpected BREAK");if(!rs(i)){const d=new vn(l,0,s,r);d.leaf=!0,d.children.push(i),rr(d,n.toHere(l[3])),i=d}let h=(i.depth+1)*2;const w=i.numBytes();for(w&&(h+=1,h+=w*2),r.minCol=Math.max(r.minCol,h),s&&s.push(i,n,l[3]),s=i;s?.done;)i=s,i.leaf||rr(i,n.toHere(i.offset)),{parent:s}=s}e&&(e.minCol=r.minCol);let c=r.noPrefixHex?"":`0x${De(n.toHere(0))}
12
- `;return c+=ns(i,r),c}const ss=!Ro();function Fr(t){if(typeof t=="object"&&t){if(t.constructor!==Number)throw new Error(`Expected number: ${t}`)}else if(typeof t!="number")throw new Error(`Expected number: ${t}`)}function bt(t){if(typeof t=="object"&&t){if(t.constructor!==String)throw new Error(`Expected string: ${t}`)}else if(typeof t!="string")throw new Error(`Expected string: ${t}`)}function pt(t){if(!(t instanceof Uint8Array))throw new Error(`Expected Uint8Array: ${t}`)}function os(t){if(!Array.isArray(t))throw new Error(`Expected Array: ${t}`)}Se(Map,(t,e,r)=>{const n=[...t.entries()].map(s=>[s[0],s[1],Kt(s[0],r)]);if(r.rejectDuplicateKeys){const s=new Set;for(const[i,c,l]of n){const h=De(l);if(s.has(h))throw new Error(`Duplicate map key: 0x${h}`);s.add(h)}}r.sortKeys&&n.sort(r.sortKeys),_n(t,t.size,z.MAP,e,r);for(const[s,i,c]of n)e.write(c),Nt(i,e,r)});function xn(t){return bt(t.contents),new Date(t.contents)}xn.comment=t=>{bt(t.contents);const e=new Date(t.contents);return`(String ${t.tag===oe.DATE_FULL?"Full ":""}Date) ${e.toISOString()}`},ee.registerDecoder(oe.DATE_STRING,xn),ee.registerDecoder(oe.DATE_FULL,xn);function as(t){return Fr(t.contents),new Date(t.contents*1e3)}as.comment=t=>(Fr(t.contents),`(Epoch Date) ${new Date(t.contents*1e3).toISOString()}`),ee.registerDecoder(oe.DATE_EPOCH,as);const An=1e3*60*60*24;function cs(t){return Fr(t.contents),new Date(t.contents*An)}cs.comment=t=>(Fr(t.contents),`(Epoch Date) ${new Date(t.contents*An).toISOString()}`),ee.registerDecoder(oe.DATE_EPOCH_DAYS,cs),Se(Date,(t,e,r)=>{switch(r.dateTag){case oe.DATE_EPOCH:return[r.dateTag,t.valueOf()/1e3];case oe.DATE_STRING:return[r.dateTag,t.toISOString().replace(/\.000Z$/,"Z")];case oe.DATE_EPOCH_DAYS:return[r.dateTag,Math.floor(t.valueOf()/An)];case oe.DATE_FULL:return[r.dateTag,t.toISOString().split("T")[0]];default:throw new Error(`Unsupported date tag: ${r.dateTag}`)}});function Ur(t,e,r){if(pt(e.contents),r.rejectBigInts)throw new Error(`Decoding unwanted big integer: ${e}(h'${De(e.contents)}')`);if(r.requirePreferred&&e.contents[0]===0)throw new Error(`Decoding overly-large bigint: ${e.tag}(h'${De(e.contents)})`);let n=e.contents.reduce((i,c)=>i<<8n|BigInt(c),0n);t&&(n=-1n-n);const s=n>=Number.MIN_SAFE_INTEGER&&n<=Number.MAX_SAFE_INTEGER;if(r.requirePreferred&&s)throw new Error(`Decoding bigint that could have been int: ${n}n`);return r.collapseBigInts&&s&&(n=Number(n)),r.boxed?nr(n,e.contents):n}const us=Ur.bind(null,!1),fs=Ur.bind(null,!0);us.comment=(t,e)=>`(Positive BigInt) ${Ur(!1,t,e)}n`,fs.comment=(t,e)=>`(Negative BigInt) ${Ur(!0,t,e)}n`,ee.registerDecoder(oe.POS_BIGINT,us),ee.registerDecoder(oe.NEG_BIGINT,fs);function Rn(t,e){return pt(t.contents),t}Rn.comment=(t,e,r)=>{pt(t.contents);const n={...e,initialDepth:r+2,noPrefixHex:!0},s=Tr(t);let i=2**((s[0]&31)-24)+1;const c=s[i]&31;let l=De(s.subarray(i,++i));c>=24&&(l+=" ",l+=De(s.subarray(i,i+2**(c-24)))),n.minCol=Math.max(n.minCol,(r+1)*2+l.length);const h=is(t.contents,n);let w=`Embedded CBOR
11
+ `;let h=0;for(const w of t.children){if(bs(w)){let d=String(h);t.mt===z.MAP?d=h%2?`val ${(h-1)/2}`:`key ${h/2}`:t.mt===z.TAG&&(d=""),n+=Es(w,e,d)}h++}}return n}const za={...Ce.defaultDecodeOptions,initialDepth:0,noPrefixHex:!1,minCol:0};function Ss(t,e){const r={...za,...e,ParentType:Nn,saveOriginal:!0},n=new Lr(t,r);let s,i;for(const l of n){if(i=Ce.create(l,s,r,n),l[2]===Ue.BREAK)if(s?.isStreaming)s.left=1;else throw new Error("Unexpected BREAK");if(!bs(i)){const d=new Nn(l,0,s,r);d.leaf=!0,d.children.push(i),sr(d,n.toHere(l[3])),i=d}let h=(i.depth+1)*2;const w=i.numBytes();for(w&&(h+=1,h+=w*2),r.minCol=Math.max(r.minCol,h),s&&s.push(i,n,l[3]),s=i;s?.done;)i=s,i.leaf||sr(i,n.toHere(i.offset)),{parent:s}=s}e&&(e.minCol=r.minCol);let c=r.noPrefixHex?"":`0x${Oe(n.toHere(0))}
12
+ `;return c+=Es(i,r),c}const _s=!fa();function Pr(t){if(typeof t=="object"&&t){if(t.constructor!==Number)throw new Error(`Expected number: ${t}`)}else if(typeof t!="number")throw new Error(`Expected number: ${t}`)}function St(t){if(typeof t=="object"&&t){if(t.constructor!==String)throw new Error(`Expected string: ${t}`)}else if(typeof t!="string")throw new Error(`Expected string: ${t}`)}function yt(t){if(!(t instanceof Uint8Array))throw new Error(`Expected Uint8Array: ${t}`)}function Ts(t){if(!Array.isArray(t))throw new Error(`Expected Array: ${t}`)}_e(Map,(t,e,r)=>{const n=[...t.entries()].map(s=>[s[0],s[1],zt(s[0],r)]);if(r.rejectDuplicateKeys){const s=new Set;for(const[i,c,l]of n){const h=Oe(l);if(s.has(h))throw new Error(`Duplicate map key: 0x${h}`);s.add(h)}}r.sortKeys&&n.sort(r.sortKeys),In(t,t.size,z.MAP,e,r);for(const[s,i,c]of n)e.write(c),Ut(i,e,r)});function kn(t){return St(t.contents),new Date(t.contents)}kn.comment=t=>{St(t.contents);const e=new Date(t.contents);return`(String ${t.tag===oe.DATE_FULL?"Full ":""}Date) ${e.toISOString()}`},ee.registerDecoder(oe.DATE_STRING,kn),ee.registerDecoder(oe.DATE_FULL,kn);function vs(t){return Pr(t.contents),new Date(t.contents*1e3)}vs.comment=t=>(Pr(t.contents),`(Epoch Date) ${new Date(t.contents*1e3).toISOString()}`),ee.registerDecoder(oe.DATE_EPOCH,vs);const Fn=1e3*60*60*24;function xs(t){return Pr(t.contents),new Date(t.contents*Fn)}xs.comment=t=>(Pr(t.contents),`(Epoch Date) ${new Date(t.contents*Fn).toISOString()}`),ee.registerDecoder(oe.DATE_EPOCH_DAYS,xs),_e(Date,(t,e,r)=>{switch(r.dateTag){case oe.DATE_EPOCH:return[r.dateTag,t.valueOf()/1e3];case oe.DATE_STRING:return[r.dateTag,t.toISOString().replace(/\.000Z$/,"Z")];case oe.DATE_EPOCH_DAYS:return[r.dateTag,Math.floor(t.valueOf()/Fn)];case oe.DATE_FULL:return[r.dateTag,t.toISOString().split("T")[0]];default:throw new Error(`Unsupported date tag: ${r.dateTag}`)}});function Dr(t,e,r){if(yt(e.contents),r.rejectBigInts)throw new Error(`Decoding unwanted big integer: ${e}(h'${Oe(e.contents)}')`);if(r.requirePreferred&&e.contents[0]===0)throw new Error(`Decoding overly-large bigint: ${e.tag}(h'${Oe(e.contents)})`);let n=e.contents.reduce((i,c)=>i<<8n|BigInt(c),0n);t&&(n=-1n-n);const s=n>=Number.MIN_SAFE_INTEGER&&n<=Number.MAX_SAFE_INTEGER;if(r.requirePreferred&&s)throw new Error(`Decoding bigint that could have been int: ${n}n`);return r.collapseBigInts&&s&&(n=Number(n)),r.boxed?or(n,e.contents):n}const As=Dr.bind(null,!1),Rs=Dr.bind(null,!0);As.comment=(t,e)=>`(Positive BigInt) ${Dr(!1,t,e)}n`,Rs.comment=(t,e)=>`(Negative BigInt) ${Dr(!0,t,e)}n`,ee.registerDecoder(oe.POS_BIGINT,As),ee.registerDecoder(oe.NEG_BIGINT,Rs);function Un(t,e){return yt(t.contents),t}Un.comment=(t,e,r)=>{yt(t.contents);const n={...e,initialDepth:r+2,noPrefixHex:!0},s=Ar(t);let i=2**((s[0]&31)-24)+1;const c=s[i]&31;let l=Oe(s.subarray(i,++i));c>=24&&(l+=" ",l+=Oe(s.subarray(i,i+2**(c-24)))),n.minCol=Math.max(n.minCol,(r+1)*2+l.length);const h=Ss(t.contents,n);let w=`Embedded CBOR
13
13
  `;return w+=`${"".padStart((r+1)*2," ")}${l}`.padEnd(n.minCol+1," "),w+=`-- Bytes (Length: ${t.contents.length})
14
- `,w+=h,w},Rn.noChildren=!0,ee.registerDecoder(oe.CBOR,Rn),ee.registerDecoder(oe.URI,t=>(bt(t.contents),new URL(t.contents)),"URI"),Se(URL,t=>[oe.URI,t.toString()]),ee.registerDecoder(oe.BASE64URL,t=>(bt(t.contents),Ao(t.contents)),"Base64url-encoded"),ee.registerDecoder(oe.BASE64,t=>(bt(t.contents),mn(t.contents)),"Base64-encoded"),ee.registerDecoder(35,t=>(bt(t.contents),new RegExp(t.contents)),"RegExp"),ee.registerDecoder(21065,t=>{bt(t.contents);const e=`^(?:${t.contents})$`;return new RegExp(e,"u")},"I-RegExp"),ee.registerDecoder(oe.REGEXP,t=>{if(os(t.contents),t.contents.length<1||t.contents.length>2)throw new Error(`Invalid RegExp Array: ${t.contents}`);return new RegExp(t.contents[0],t.contents[1])},"RegExp"),Se(RegExp,t=>[oe.REGEXP,[t.source,t.flags]]),ee.registerDecoder(64,t=>(pt(t.contents),t.contents),"uint8 Typed Array");function Ue(t,e,r){pt(t.contents);let n=t.contents.length;if(n%e.BYTES_PER_ELEMENT!==0)throw new Error(`Number of bytes must be divisible by ${e.BYTES_PER_ELEMENT}, got: ${n}`);n/=e.BYTES_PER_ELEMENT;const s=new e(n),i=new DataView(t.contents.buffer,t.contents.byteOffset,t.contents.byteLength),c=i[`get${e.name.replace(/Array/,"")}`].bind(i);for(let l=0;l<n;l++)s[l]=c(l*e.BYTES_PER_ELEMENT,r);return s}function Et(t,e,r,n,s){const i=s.forceEndian??ss;if(ar(i?e:r,t,s),We(n.byteLength,t,z.BYTE_STRING),ss===i)t.write(new Uint8Array(n.buffer,n.byteOffset,n.byteLength));else{const c=`write${n.constructor.name.replace(/Array/,"")}`,l=t[c].bind(t);for(const h of n)l(h,i)}}ee.registerDecoder(65,t=>Ue(t,Uint16Array,!1),"uint16, big endian, Typed Array"),ee.registerDecoder(66,t=>Ue(t,Uint32Array,!1),"uint32, big endian, Typed Array"),ee.registerDecoder(67,t=>Ue(t,BigUint64Array,!1),"uint64, big endian, Typed Array"),ee.registerDecoder(68,t=>(pt(t.contents),new Uint8ClampedArray(t.contents)),"uint8 Typed Array, clamped arithmetic"),Se(Uint8ClampedArray,t=>[68,new Uint8Array(t.buffer,t.byteOffset,t.byteLength)]),ee.registerDecoder(69,t=>Ue(t,Uint16Array,!0),"uint16, little endian, Typed Array"),Se(Uint16Array,(t,e,r)=>Et(e,69,65,t,r)),ee.registerDecoder(70,t=>Ue(t,Uint32Array,!0),"uint32, little endian, Typed Array"),Se(Uint32Array,(t,e,r)=>Et(e,70,66,t,r)),ee.registerDecoder(71,t=>Ue(t,BigUint64Array,!0),"uint64, little endian, Typed Array"),Se(BigUint64Array,(t,e,r)=>Et(e,71,67,t,r)),ee.registerDecoder(72,t=>(pt(t.contents),new Int8Array(t.contents)),"sint8 Typed Array"),Se(Int8Array,t=>[72,new Uint8Array(t.buffer,t.byteOffset,t.byteLength)]),ee.registerDecoder(73,t=>Ue(t,Int16Array,!1),"sint16, big endian, Typed Array"),ee.registerDecoder(74,t=>Ue(t,Int32Array,!1),"sint32, big endian, Typed Array"),ee.registerDecoder(75,t=>Ue(t,BigInt64Array,!1),"sint64, big endian, Typed Array"),ee.registerDecoder(77,t=>Ue(t,Int16Array,!0),"sint16, little endian, Typed Array"),Se(Int16Array,(t,e,r)=>Et(e,77,73,t,r)),ee.registerDecoder(78,t=>Ue(t,Int32Array,!0),"sint32, little endian, Typed Array"),Se(Int32Array,(t,e,r)=>Et(e,78,74,t,r)),ee.registerDecoder(79,t=>Ue(t,BigInt64Array,!0),"sint64, little endian, Typed Array"),Se(BigInt64Array,(t,e,r)=>Et(e,79,75,t,r)),ee.registerDecoder(81,t=>Ue(t,Float32Array,!1),"IEEE 754 binary32, big endian, Typed Array"),ee.registerDecoder(82,t=>Ue(t,Float64Array,!1),"IEEE 754 binary64, big endian, Typed Array"),ee.registerDecoder(85,t=>Ue(t,Float32Array,!0),"IEEE 754 binary32, little endian, Typed Array"),Se(Float32Array,(t,e,r)=>Et(e,85,81,t,r)),ee.registerDecoder(86,t=>Ue(t,Float64Array,!0),"IEEE 754 binary64, big endian, Typed Array"),Se(Float64Array,(t,e,r)=>Et(e,86,82,t,r)),ee.registerDecoder(oe.SET,(t,e)=>{if(os(t.contents),e.sortKeys){const r=Oe.decodeToEncodeOpts(e);let n=null;for(const s of t.contents){const i=[s,void 0,Kt(s,r)];if(n&&e.sortKeys(n,i)>=0)throw new Error(`Set items out of order in tag #${oe.SET}`);n=i}}return new Set(t.contents)},"Set"),Se(Set,(t,e,r)=>{let n=[...t];if(r.sortKeys){const s=n.map(i=>[i,void 0,Kt(i,r)]);s.sort(r.sortKeys),n=s.map(([i])=>i)}return[oe.SET,n]}),ee.registerDecoder(oe.JSON,t=>(bt(t.contents),JSON.parse(t.contents)),"JSON-encoded");function ls(t){return pt(t.contents),new Ir().decode(t.contents)}ls.comment=t=>{pt(t.contents);const e=new Ir;return`(WTF8 string): ${JSON.stringify(e.decode(t.contents))}`},ee.registerDecoder(oe.WTF8,ls),ee.registerDecoder(oe.SELF_DESCRIBED,t=>t.contents,"Self-Described"),ee.registerDecoder(oe.INVALID_16,()=>{throw new Error(`Tag always invalid: ${oe.INVALID_16}`)},"Invalid"),ee.registerDecoder(oe.INVALID_32,()=>{throw new Error(`Tag always invalid: ${oe.INVALID_32}`)},"Invalid"),ee.registerDecoder(oe.INVALID_64,()=>{throw new Error(`Tag always invalid: ${oe.INVALID_64}`)},"Invalid");function In(t){throw new Error(`Encoding ${t.constructor.name} intentionally unimplmented. It is not concrete enough to interoperate. Convert to Uint8Array first.`)}Se(ArrayBuffer,In),Se(DataView,In),typeof SharedArrayBuffer<"u"&&Se(SharedArrayBuffer,In);function Lr(t){return[NaN,t.valueOf()]}Se(Boolean,Lr),Se(Number,Lr),Se(String,Lr),Se(BigInt,Lr);function ha(t){const e={...Oe.defaultDecodeOptions};if(t.dcbor?Object.assign(e,Oe.dcborDecodeOptions):t.cde&&Object.assign(e,Oe.cdeDecodeOptions),Object.assign(e,t),Object.hasOwn(e,"rejectLongNumbers"))throw new TypeError("rejectLongNumbers has changed to requirePreferred");return e.boxed&&(e.saveOriginal=!0),e}let da=class{parent=void 0;ret=void 0;step(e,r,n){if(this.ret=Oe.create(e,this.parent,r,n),e[2]===Fe.BREAK)if(this.parent?.isStreaming)this.parent.left=0;else throw new Error("Unexpected BREAK");else this.parent&&this.parent.push(this.ret,n,e[3]);for(this.ret instanceof Oe&&(this.parent=this.ret);this.parent?.done;){this.ret=this.parent.convert(n);const s=this.parent.parent;s?.replaceLast(this.ret,this.parent,n),this.parent=s}}};function pa(t,e={}){const r=ha(e),n=new Nr(t,r),s=new da;for(const i of n)s.step(i,r,n);return s.ret}const{cdeDecodeOptions:Nc,dcborDecodeOptions:Mc,defaultDecodeOptions:Fc}=Oe;class ya{constructor(e={}){this.options={id:Xt(),codec:"cbor",timeout:10*1e3,chunkSize:16*1024,chunkCredit:4,topicMake:(r,n,s)=>`${r}/${n}/${s??"any"}`,topicMatch:r=>{const n=r.match(/^(.+)\/([^/]+)\/([^/]+)$/);return n?{name:n[1],operation:n[2],peerId:n[3]==="any"?void 0:n[3]}:null},...e}}}class Bn{static uint8ArrayToBase64(e){return It.from(e.buffer,e.byteOffset,e.byteLength).toString("base64")}static base64ToUint8Array(e){return new Uint8Array(It.from(e,"base64"))}static stringify(e){return JSON.stringify(e,(r,n)=>n instanceof Uint8Array?{__Uint8Array:this.uint8ArrayToBase64(n)}:n)}static parse(e){return JSON.parse(e,(r,n)=>typeof n?.__Uint8Array=="string"?this.base64ToUint8Array(n.__Uint8Array):n)}}class wa{constructor(e){this.format=e,this.types=new Ui,this.tags=new Map;const r=64e3;this.types.registerEncoder(It,n=>[r,new Uint8Array(n.buffer,n.byteOffset,n.byteLength)]),this.tags.set(r,n=>It.from(n.contents))}encode(e){let r;if(this.format==="cbor")try{r=Kt(e,{types:this.types})}catch(n){throw new Error("failed to encode CBOR format",{cause:n})}else if(this.format==="json")try{r=Bn.stringify(e)}catch(n){throw new Error("failed to encode JSON format",{cause:n})}else throw new Error(`invalid format "${this.format}"`);return r}decode(e){let r;if(this.format==="cbor"){if(!(e instanceof Uint8Array))throw new Error("failed to decode CBOR format (data type is not Uint8Array)");try{r=pa(e,{tags:this.tags})}catch(n){throw new Error("failed to decode CBOR format",{cause:n})}}else if(this.format==="json"){if(typeof e!="string")throw new Error("failed to decode JSON format (data type is not string)");try{r=Bn.parse(e)}catch(n){throw new Error("failed to decode JSON format",{cause:n})}}else throw new Error(`invalid format "${this.format}"`);return r}}class ga extends ya{constructor(e={}){super(e),this.codec=new wa(this.options.codec)}}class ma extends ga{str2buf(e){return new TextEncoder().encode(e)}buf2str(e){return new TextDecoder().decode(e)}arr2buf(e){let r;return e instanceof Uint8Array?r=e:r=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),r}buf2arr(e,r){let n;const s=r;if(s===It)n=It.from(e.buffer,e.byteOffset,e.byteLength);else if(s===Uint8Array)n=e;else if(s===Int8Array)n=new Int8Array(e.buffer,e.byteOffset,e.byteLength);else throw new Error("invalid data type");return n}}const hs=t=>{const e=t.match(/^(\d+)\.(\d+)$/);if(e===null)throw new Error("invalid version string");const r=parseInt(e[2],10);if(r>99)throw new Error("invalid version string: minor version exceeds 99");return parseInt(e[1],10)+r/100},kn="1.4",ba=hs(kn),Wt=Ke(ki(be(),kt()),Ri(t=>!Array.isArray(t))),Ht=Ke(qt(Ke(be(),Bt(8192))),Bt(8));class ze{constructor(e,r,n,s){this.type=e,this.id=r,this.sender=n,this.receiver=s,this.version=`MQTT+/${kn}`}}const Ve={version:Ke(be(),Ii(/^MQTT\+\/\d+\.\d+$/)),type:be(),id:be(),sender:ce(be()),receiver:ce(be())};class ds extends ze{constructor(e,r,n,s,i,c,l){super("event-emission",e,s,i),this.name=r,this.params=n,this.auth=c,this.meta=l}}const Ea=qe({...Ve,type:je("event-emission"),name:be(),params:ce(Ke(qt(kt()),Bt(64))),auth:ce(Ht),meta:ce(Wt)});class ps extends ze{constructor(e,r,n,s,i,c,l){super("service-call-request",e,s,i),this.name=r,this.params=n,this.auth=c,this.meta=l}}const Sa=qe({...Ve,type:je("service-call-request"),name:be(),params:ce(Ke(qt(kt()),Bt(64))),auth:ce(Ht),meta:ce(Wt)});class ys extends ze{constructor(e,r,n,s,i){super("service-call-response",e,s,i),this.result=r,this.error=n}}const _a=qe({...Ve,type:je("service-call-response"),result:ce(kt()),error:ce(be())});class ws extends ze{constructor(e,r,n,s,i,c,l){super("sink-push-request",e,s,i),this.name=r,this.params=n,this.auth=c,this.meta=l}}const Ta=qe({...Ve,type:je("sink-push-request"),name:be(),params:ce(Ke(qt(kt()),Bt(64))),auth:ce(Ht),meta:ce(Wt)});class gs extends ze{constructor(e,r,n,s,i,c,l,h){super("sink-push-response",e,s,i),this.name=r,this.error=n,this.auth=c,this.meta=l,this.credit=h}}const va=qe({...Ve,type:je("sink-push-response"),name:be(),error:ce(be()),auth:ce(Ht),meta:ce(Wt),credit:ce(Ke(tr(),Zt(),er(1)))});class ms extends ze{constructor(e,r,n,s,i,c,l){super("sink-push-chunk",e,c,l),this.name=r,this.chunk=n,this.error=s,this.final=i}}const xa=qe({...Ve,type:je("sink-push-chunk"),name:be(),chunk:ce(yn(Uint8Array)),error:ce(be()),final:ce(pn())});class bs extends ze{constructor(e,r,n,s,i){super("sink-push-credit",e,s,i),this.name=r,this.credit=n}}const Aa=qe({...Ve,type:je("sink-push-credit"),name:be(),credit:Ke(tr(),Zt(),er(1))});class Es extends ze{constructor(e,r,n,s,i,c,l,h){super("source-fetch-request",e,s,i),this.name=r,this.params=n,this.auth=c,this.meta=l,this.credit=h}}const Ra=qe({...Ve,type:je("source-fetch-request"),name:be(),params:ce(Ke(qt(kt()),Bt(64))),auth:ce(Ht),meta:ce(Wt),credit:ce(Ke(tr(),Zt(),er(1)))});class Ss extends ze{constructor(e,r,n,s,i,c,l){super("source-fetch-response",e,s,i),this.name=r,this.error=n,this.auth=c,this.meta=l}}const Ia=qe({...Ve,type:je("source-fetch-response"),name:be(),error:ce(be()),auth:ce(Ht),meta:ce(Wt)});class _s extends ze{constructor(e,r,n,s,i,c,l){super("source-fetch-chunk",e,c,l),this.name=r,this.chunk=n,this.error=s,this.final=i}}const Ba=qe({...Ve,type:je("source-fetch-chunk"),name:be(),chunk:ce(yn(Uint8Array)),error:ce(be()),final:ce(pn())});class Ts extends ze{constructor(e,r,n,s,i){super("source-fetch-credit",e,s,i),this.name=r,this.credit=n}}const ka=qe({...Ve,type:je("source-fetch-credit"),name:be(),credit:Ke(tr(),Zt(),er(1))});class Na{makeEventEmission(e,r,n,s,i,c,l){return new ds(e,r,n,s,i,c,l)}makeServiceCallRequest(e,r,n,s,i,c,l){return new ps(e,r,n,s,i,c,l)}makeServiceCallResponse(e,r,n,s,i){return new ys(e,r,n,s,i)}makeSinkPushRequest(e,r,n,s,i,c,l){return new ws(e,r,n,s,i,c,l)}makeSinkPushResponse(e,r,n,s,i,c,l,h){return new gs(e,r,n,s,i,c,l,h)}makeSinkPushChunk(e,r,n,s,i,c,l){return new ms(e,r,n,s,i,c,l)}makeSinkPushCredit(e,r,n,s,i){return new bs(e,r,n,s,i)}makeSourceFetchRequest(e,r,n,s,i,c,l,h){return new Es(e,r,n,s,i,c,l,h)}makeSourceFetchResponse(e,r,n,s,i,c,l){return new Ss(e,r,n,s,i,c,l)}makeSourceFetchChunk(e,r,n,s,i,c,l){return new _s(e,r,n,s,i,c,l)}makeSourceFetchCredit(e,r,n,s,i){return new Ts(e,r,n,s,i)}parse(e){if(typeof e!="object"||e===null)throw new Error("invalid argument: not an object");if(typeof e.version!="string")throw new Error('invalid object: missing or invalid "version" field');const r=e.version.match(/^MQTT\+\/(\d+\.\d+)$/);if((r!==null?hs(r[1]):0)!==ba)throw new Error(`protocol version mismatch (expected version ${kn}, got version ${e.version})`);const s=(i,c,l)=>{const h=So(l,i);if(!h.success){const w=h.issues.map(d=>d.message).join("; ");throw new Error(`invalid ${c} object: ${w}`)}return h.output};if(typeof e.type!="string")throw new Error('invalid object: missing or invalid "type" field');if(e.type==="event-emission"){const i=s(e,"EventEmission",Ea);return this.makeEventEmission(i.id,i.name,i.params,i.sender,i.receiver,i.auth,i.meta)}else if(e.type==="service-call-request"){const i=s(e,"ServiceCallRequest",Sa);return this.makeServiceCallRequest(i.id,i.name,i.params,i.sender,i.receiver,i.auth,i.meta)}else if(e.type==="service-call-response"){const i=s(e,"ServiceCallResponse",_a);return this.makeServiceCallResponse(i.id,i.result,i.error,i.sender,i.receiver)}else if(e.type==="sink-push-request"){const i=s(e,"SinkPushRequest",Ta);return this.makeSinkPushRequest(i.id,i.name,i.params,i.sender,i.receiver,i.auth,i.meta)}else if(e.type==="sink-push-response"){const i=s(e,"SinkPushResponse",va);return this.makeSinkPushResponse(i.id,i.name,i.error,i.sender,i.receiver,i.auth,i.meta,i.credit)}else if(e.type==="sink-push-chunk"){const i=s(e,"SinkPushChunk",xa);return this.makeSinkPushChunk(i.id,i.name,i.chunk,i.error,i.final,i.sender,i.receiver)}else if(e.type==="sink-push-credit"){const i=s(e,"SinkPushCredit",Aa);return this.makeSinkPushCredit(i.id,i.name,i.credit,i.sender,i.receiver)}else if(e.type==="source-fetch-request"){const i=s(e,"SourceFetchRequest",Ra);return this.makeSourceFetchRequest(i.id,i.name,i.params,i.sender,i.receiver,i.auth,i.meta,i.credit)}else if(e.type==="source-fetch-response"){const i=s(e,"SourceFetchResponse",Ia);return this.makeSourceFetchResponse(i.id,i.name,i.error,i.sender,i.receiver,i.auth,i.meta)}else if(e.type==="source-fetch-chunk"){const i=s(e,"SourceFetchChunk",Ba);return this.makeSourceFetchChunk(i.id,i.name,i.chunk,i.error,i.final,i.sender,i.receiver)}else if(e.type==="source-fetch-credit"){const i=s(e,"SourceFetchCredit",ka);return this.makeSourceFetchCredit(i.id,i.name,i.credit,i.sender,i.receiver)}else throw new Error("invalid object: not of any known type")}}class Ma extends ma{constructor(){super(...arguments),this.msg=new Na}}const Cr=new TextEncoder,ur=new TextDecoder;function vs(...t){const e=t.reduce((s,{length:i})=>s+i,0),r=new Uint8Array(e);let n=0;for(const s of t)r.set(s,n),n+=s.length;return r}function Gt(t){const e=new Uint8Array(t.length);for(let r=0;r<t.length;r++){const n=t.charCodeAt(r);if(n>127)throw new TypeError("non-ASCII string encountered in encode()");e[r]=n}return e}function Fa(t){if(Uint8Array.prototype.toBase64)return t.toBase64();const e=32768,r=[];for(let n=0;n<t.length;n+=e)r.push(String.fromCharCode.apply(null,t.subarray(n,n+e)));return btoa(r.join(""))}function Ua(t){if(Uint8Array.fromBase64)return Uint8Array.fromBase64(t);const e=atob(t),r=new Uint8Array(e.length);for(let n=0;n<e.length;n++)r[n]=e.charCodeAt(n);return r}function Pr(t){if(Uint8Array.fromBase64)return Uint8Array.fromBase64(typeof t=="string"?t:ur.decode(t),{alphabet:"base64url"});let e=t;e instanceof Uint8Array&&(e=ur.decode(e)),e=e.replace(/-/g,"+").replace(/_/g,"/");try{return Ua(e)}catch{throw new TypeError("The input to be decoded is not correctly encoded.")}}function Nn(t){let e=t;return typeof e=="string"&&(e=Cr.encode(e)),Uint8Array.prototype.toBase64?e.toBase64({alphabet:"base64url",omitPadding:!0}):Fa(e).replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}class Jt extends Error{static code="ERR_JOSE_GENERIC";code="ERR_JOSE_GENERIC";constructor(e,r){super(e,r),this.name=this.constructor.name,Error.captureStackTrace?.(this,this.constructor)}}class it extends Jt{static code="ERR_JWT_CLAIM_VALIDATION_FAILED";code="ERR_JWT_CLAIM_VALIDATION_FAILED";claim;reason;payload;constructor(e,r,n="unspecified",s="unspecified"){super(e,{cause:{claim:n,reason:s,payload:r}}),this.claim=n,this.reason=s,this.payload=r}}class xs extends Jt{static code="ERR_JWT_EXPIRED";code="ERR_JWT_EXPIRED";claim;reason;payload;constructor(e,r,n="unspecified",s="unspecified"){super(e,{cause:{claim:n,reason:s,payload:r}}),this.claim=n,this.reason=s,this.payload=r}}class Mt extends Jt{static code="ERR_JOSE_NOT_SUPPORTED";code="ERR_JOSE_NOT_SUPPORTED"}class _e extends Jt{static code="ERR_JWS_INVALID";code="ERR_JWS_INVALID"}class Mn extends Jt{static code="ERR_JWT_INVALID";code="ERR_JWT_INVALID"}class La extends Jt{static code="ERR_JWS_SIGNATURE_VERIFICATION_FAILED";code="ERR_JWS_SIGNATURE_VERIFICATION_FAILED";constructor(e="signature verification failed",r){super(e,r)}}function As(t,e){const r=`SHA-${t.slice(-3)}`;switch(t){case"HS256":case"HS384":case"HS512":return{hash:r,name:"HMAC"};case"PS256":case"PS384":case"PS512":return{hash:r,name:"RSA-PSS",saltLength:parseInt(t.slice(-3),10)>>3};case"RS256":case"RS384":case"RS512":return{hash:r,name:"RSASSA-PKCS1-v1_5"};case"ES256":case"ES384":case"ES512":return{hash:r,name:"ECDSA",namedCurve:e.namedCurve};case"Ed25519":case"EdDSA":return{name:"Ed25519"};case"ML-DSA-44":case"ML-DSA-65":case"ML-DSA-87":return{name:t};default:throw new Mt(`alg ${t} is not supported either by JOSE or your javascript runtime`)}}function Rs(t,e){if(t.startsWith("RS")||t.startsWith("PS")){const{modulusLength:r}=e.algorithm;if(typeof r!="number"||r<2048)throw new TypeError(`${t} requires key modulusLength to be 2048 bits or larger`)}}const st=(t,e="algorithm.name")=>new TypeError(`CryptoKey does not support this operation, its ${e} must be ${t}`),zt=(t,e)=>t.name===e;function Fn(t){return parseInt(t.name.slice(4),10)}function Ca(t){switch(t){case"ES256":return"P-256";case"ES384":return"P-384";case"ES512":return"P-521";default:throw new Error("unreachable")}}function Pa(t,e){if(e&&!t.usages.includes(e))throw new TypeError(`CryptoKey does not support this operation, its usages must include ${e}.`)}function Da(t,e,r){switch(e){case"HS256":case"HS384":case"HS512":{if(!zt(t.algorithm,"HMAC"))throw st("HMAC");const n=parseInt(e.slice(2),10);if(Fn(t.algorithm.hash)!==n)throw st(`SHA-${n}`,"algorithm.hash");break}case"RS256":case"RS384":case"RS512":{if(!zt(t.algorithm,"RSASSA-PKCS1-v1_5"))throw st("RSASSA-PKCS1-v1_5");const n=parseInt(e.slice(2),10);if(Fn(t.algorithm.hash)!==n)throw st(`SHA-${n}`,"algorithm.hash");break}case"PS256":case"PS384":case"PS512":{if(!zt(t.algorithm,"RSA-PSS"))throw st("RSA-PSS");const n=parseInt(e.slice(2),10);if(Fn(t.algorithm.hash)!==n)throw st(`SHA-${n}`,"algorithm.hash");break}case"Ed25519":case"EdDSA":{if(!zt(t.algorithm,"Ed25519"))throw st("Ed25519");break}case"ML-DSA-44":case"ML-DSA-65":case"ML-DSA-87":{if(!zt(t.algorithm,e))throw st(e);break}case"ES256":case"ES384":case"ES512":{if(!zt(t.algorithm,"ECDSA"))throw st("ECDSA");const n=Ca(e);if(t.algorithm.namedCurve!==n)throw st(n,"algorithm.namedCurve");break}default:throw new TypeError("CryptoKey does not support this operation")}Pa(t,r)}function Is(t,e,...r){if(r=r.filter(Boolean),r.length>2){const n=r.pop();t+=`one of type ${r.join(", ")}, or ${n}.`}else r.length===2?t+=`one of type ${r[0]} or ${r[1]}.`:t+=`of type ${r[0]}.`;return e==null?t+=` Received ${e}`:typeof e=="function"&&e.name?t+=` Received function ${e.name}`:typeof e=="object"&&e!=null&&e.constructor?.name&&(t+=` Received an instance of ${e.constructor.name}`),t}const Oa=(t,...e)=>Is("Key must be ",t,...e),Bs=(t,e,...r)=>Is(`Key for the ${t} algorithm must be `,e,...r);async function ks(t,e,r){if(e instanceof Uint8Array){if(!t.startsWith("HS"))throw new TypeError(Oa(e,"CryptoKey","KeyObject","JSON Web Key"));return crypto.subtle.importKey("raw",e,{hash:`SHA-${t.slice(-3)}`,name:"HMAC"},!1,[r])}return Da(e,t,r),e}async function $a(t,e,r){const n=await ks(t,e,"sign");Rs(t,n);const s=await crypto.subtle.sign(As(t,n.algorithm),n,r);return new Uint8Array(s)}function Ns(...t){const e=t.filter(Boolean);if(e.length===0||e.length===1)return!0;let r;for(const n of e){const s=Object.keys(n);if(!r||r.size===0){r=new Set(s);continue}for(const i of s){if(r.has(i))return!1;r.add(i)}}return!0}const Ms=t=>{if(t?.[Symbol.toStringTag]==="CryptoKey")return!0;try{return t instanceof CryptoKey}catch{return!1}},Fs=t=>t?.[Symbol.toStringTag]==="KeyObject",Us=t=>Ms(t)||Fs(t),ja=t=>typeof t=="object"&&t!==null;function fr(t){if(!ja(t)||Object.prototype.toString.call(t)!=="[object Object]")return!1;if(Object.getPrototypeOf(t)===null)return!0;let e=t;for(;Object.getPrototypeOf(e)!==null;)e=Object.getPrototypeOf(e);return Object.getPrototypeOf(t)===e}const Un=t=>fr(t)&&typeof t.kty=="string",qa=t=>t.kty!=="oct"&&(t.kty==="AKP"&&typeof t.priv=="string"||typeof t.d=="string"),Ka=t=>t.kty!=="oct"&&t.d===void 0&&t.priv===void 0,Wa=t=>t.kty==="oct"&&typeof t.k=="string",Vt=t=>t?.[Symbol.toStringTag],Ln=(t,e,r)=>{if(e.use!==void 0){let n;switch(r){case"sign":case"verify":n="sig";break;case"encrypt":case"decrypt":n="enc";break}if(e.use!==n)throw new TypeError(`Invalid key for this operation, its "use" must be "${n}" when present`)}if(e.alg!==void 0&&e.alg!==t)throw new TypeError(`Invalid key for this operation, its "alg" must be "${t}" when present`);if(Array.isArray(e.key_ops)){let n;switch(!0){case(r==="sign"||r==="verify"):case t==="dir":case t.includes("CBC-HS"):n=r;break;case t.startsWith("PBES2"):n="deriveBits";break;case/^A\d{3}(?:GCM)?(?:KW)?$/.test(t):!t.includes("GCM")&&t.endsWith("KW")?n=r==="encrypt"?"wrapKey":"unwrapKey":n=r;break;case(r==="encrypt"&&t.startsWith("RSA")):n="wrapKey";break;case r==="decrypt":n=t.startsWith("RSA")?"unwrapKey":"deriveBits";break}if(n&&e.key_ops?.includes?.(n)===!1)throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${n}" when present`)}return!0},Ha=(t,e,r)=>{if(!(e instanceof Uint8Array)){if(Un(e)){if(Wa(e)&&Ln(t,e,r))return;throw new TypeError('JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present')}if(!Us(e))throw new TypeError(Bs(t,e,"CryptoKey","KeyObject","JSON Web Key","Uint8Array"));if(e.type!=="secret")throw new TypeError(`${Vt(e)} instances for symmetric algorithms must be of type "secret"`)}},Ga=(t,e,r)=>{if(Un(e))switch(r){case"decrypt":case"sign":if(qa(e)&&Ln(t,e,r))return;throw new TypeError("JSON Web Key for this operation must be a private JWK");case"encrypt":case"verify":if(Ka(e)&&Ln(t,e,r))return;throw new TypeError("JSON Web Key for this operation must be a public JWK")}if(!Us(e))throw new TypeError(Bs(t,e,"CryptoKey","KeyObject","JSON Web Key"));if(e.type==="secret")throw new TypeError(`${Vt(e)} instances for asymmetric algorithms must not be of type "secret"`);if(e.type==="public")switch(r){case"sign":throw new TypeError(`${Vt(e)} instances for asymmetric algorithm signing must be of type "private"`);case"decrypt":throw new TypeError(`${Vt(e)} instances for asymmetric algorithm decryption must be of type "private"`)}if(e.type==="private")switch(r){case"verify":throw new TypeError(`${Vt(e)} instances for asymmetric algorithm verifying must be of type "public"`);case"encrypt":throw new TypeError(`${Vt(e)} instances for asymmetric algorithm encryption must be of type "public"`)}};function Ls(t,e,r){switch(t.substring(0,2)){case"A1":case"A2":case"di":case"HS":case"PB":Ha(t,e,r);break;default:Ga(t,e,r)}}function Cs(t,e,r,n,s){if(s.crit!==void 0&&n?.crit===void 0)throw new t('"crit" (Critical) Header Parameter MUST be integrity protected');if(!n||n.crit===void 0)return new Set;if(!Array.isArray(n.crit)||n.crit.length===0||n.crit.some(c=>typeof c!="string"||c.length===0))throw new t('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');let i;r!==void 0?i=new Map([...Object.entries(r),...e.entries()]):i=e;for(const c of n.crit){if(!i.has(c))throw new Mt(`Extension Header Parameter "${c}" is not recognized`);if(s[c]===void 0)throw new t(`Extension Header Parameter "${c}" is missing`);if(i.get(c)&&n[c]===void 0)throw new t(`Extension Header Parameter "${c}" MUST be integrity protected`)}return new Set(n.crit)}function Ja(t){let e,r;switch(t.kty){case"AKP":{switch(t.alg){case"ML-DSA-44":case"ML-DSA-65":case"ML-DSA-87":e={name:t.alg},r=t.priv?["sign"]:["verify"];break;default:throw new Mt('Invalid or unsupported JWK "alg" (Algorithm) Parameter value')}break}case"RSA":{switch(t.alg){case"PS256":case"PS384":case"PS512":e={name:"RSA-PSS",hash:`SHA-${t.alg.slice(-3)}`},r=t.d?["sign"]:["verify"];break;case"RS256":case"RS384":case"RS512":e={name:"RSASSA-PKCS1-v1_5",hash:`SHA-${t.alg.slice(-3)}`},r=t.d?["sign"]:["verify"];break;case"RSA-OAEP":case"RSA-OAEP-256":case"RSA-OAEP-384":case"RSA-OAEP-512":e={name:"RSA-OAEP",hash:`SHA-${parseInt(t.alg.slice(-3),10)||1}`},r=t.d?["decrypt","unwrapKey"]:["encrypt","wrapKey"];break;default:throw new Mt('Invalid or unsupported JWK "alg" (Algorithm) Parameter value')}break}case"EC":{switch(t.alg){case"ES256":e={name:"ECDSA",namedCurve:"P-256"},r=t.d?["sign"]:["verify"];break;case"ES384":e={name:"ECDSA",namedCurve:"P-384"},r=t.d?["sign"]:["verify"];break;case"ES512":e={name:"ECDSA",namedCurve:"P-521"},r=t.d?["sign"]:["verify"];break;case"ECDH-ES":case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":e={name:"ECDH",namedCurve:t.crv},r=t.d?["deriveBits"]:[];break;default:throw new Mt('Invalid or unsupported JWK "alg" (Algorithm) Parameter value')}break}case"OKP":{switch(t.alg){case"Ed25519":case"EdDSA":e={name:"Ed25519"},r=t.d?["sign"]:["verify"];break;case"ECDH-ES":case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":e={name:t.crv},r=t.d?["deriveBits"]:[];break;default:throw new Mt('Invalid or unsupported JWK "alg" (Algorithm) Parameter value')}break}default:throw new Mt('Invalid or unsupported JWK "kty" (Key Type) Parameter value')}return{algorithm:e,keyUsages:r}}async function za(t){if(!t.alg)throw new TypeError('"alg" argument is required when "jwk.alg" is not present');const{algorithm:e,keyUsages:r}=Ja(t),n={...t};return n.kty!=="AKP"&&delete n.alg,delete n.use,crypto.subtle.importKey("jwk",n,e,t.ext??!(t.d||t.priv),t.key_ops??r)}let Yt;const Ps=async(t,e,r,n=!1)=>{Yt||=new WeakMap;let s=Yt.get(t);if(s?.[r])return s[r];const i=await za({...e,alg:r});return n&&Object.freeze(t),s?s[r]=i:Yt.set(t,{[r]:i}),i},Va=(t,e)=>{Yt||=new WeakMap;let r=Yt.get(t);if(r?.[e])return r[e];const n=t.type==="public",s=!!n;let i;if(t.asymmetricKeyType==="x25519"){switch(e){case"ECDH-ES":case"ECDH-ES+A128KW":case"ECDH-ES+A192KW":case"ECDH-ES+A256KW":break;default:throw new TypeError("given KeyObject instance cannot be used for this algorithm")}i=t.toCryptoKey(t.asymmetricKeyType,s,n?[]:["deriveBits"])}if(t.asymmetricKeyType==="ed25519"){if(e!=="EdDSA"&&e!=="Ed25519")throw new TypeError("given KeyObject instance cannot be used for this algorithm");i=t.toCryptoKey(t.asymmetricKeyType,s,[n?"verify":"sign"])}switch(t.asymmetricKeyType){case"ml-dsa-44":case"ml-dsa-65":case"ml-dsa-87":{if(e!==t.asymmetricKeyType.toUpperCase())throw new TypeError("given KeyObject instance cannot be used for this algorithm");i=t.toCryptoKey(t.asymmetricKeyType,s,[n?"verify":"sign"])}}if(t.asymmetricKeyType==="rsa"){let c;switch(e){case"RSA-OAEP":c="SHA-1";break;case"RS256":case"PS256":case"RSA-OAEP-256":c="SHA-256";break;case"RS384":case"PS384":case"RSA-OAEP-384":c="SHA-384";break;case"RS512":case"PS512":case"RSA-OAEP-512":c="SHA-512";break;default:throw new TypeError("given KeyObject instance cannot be used for this algorithm")}if(e.startsWith("RSA-OAEP"))return t.toCryptoKey({name:"RSA-OAEP",hash:c},s,n?["encrypt"]:["decrypt"]);i=t.toCryptoKey({name:e.startsWith("PS")?"RSA-PSS":"RSASSA-PKCS1-v1_5",hash:c},s,[n?"verify":"sign"])}if(t.asymmetricKeyType==="ec"){const l=new Map([["prime256v1","P-256"],["secp384r1","P-384"],["secp521r1","P-521"]]).get(t.asymmetricKeyDetails?.namedCurve);if(!l)throw new TypeError("given KeyObject instance cannot be used for this algorithm");e==="ES256"&&l==="P-256"&&(i=t.toCryptoKey({name:"ECDSA",namedCurve:l},s,[n?"verify":"sign"])),e==="ES384"&&l==="P-384"&&(i=t.toCryptoKey({name:"ECDSA",namedCurve:l},s,[n?"verify":"sign"])),e==="ES512"&&l==="P-521"&&(i=t.toCryptoKey({name:"ECDSA",namedCurve:l},s,[n?"verify":"sign"])),e.startsWith("ECDH-ES")&&(i=t.toCryptoKey({name:"ECDH",namedCurve:l},s,n?[]:["deriveBits"]))}if(!i)throw new TypeError("given KeyObject instance cannot be used for this algorithm");return r?r[e]=i:Yt.set(t,{[e]:i}),i};async function Ds(t,e){if(t instanceof Uint8Array||Ms(t))return t;if(Fs(t)){if(t.type==="secret")return t.export();if("toCryptoKey"in t&&typeof t.toCryptoKey=="function")try{return Va(t,e)}catch(n){if(n instanceof TypeError)throw n}let r=t.export({format:"jwk"});return Ps(t,r,e)}if(Un(t))return t.k?Pr(t.k):Ps(t,t,e,!0);throw new Error("unreachable")}class Ya{#e;#t;#r;constructor(e){if(!(e instanceof Uint8Array))throw new TypeError("payload must be an instance of Uint8Array");this.#e=e}setProtectedHeader(e){if(this.#t)throw new TypeError("setProtectedHeader can only be called once");return this.#t=e,this}setUnprotectedHeader(e){if(this.#r)throw new TypeError("setUnprotectedHeader can only be called once");return this.#r=e,this}async sign(e,r){if(!this.#t&&!this.#r)throw new _e("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");if(!Ns(this.#t,this.#r))throw new _e("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");const n={...this.#t,...this.#r},s=Cs(_e,new Map([["b64",!0]]),r?.crit,this.#t,n);let i=!0;if(s.has("b64")&&(i=this.#t.b64,typeof i!="boolean"))throw new _e('The "b64" (base64url-encode payload) Header Parameter must be a boolean');const{alg:c}=n;if(typeof c!="string"||!c)throw new _e('JWS "alg" (Algorithm) Header Parameter missing or invalid');Ls(c,e,"sign");let l,h;i?(l=Nn(this.#e),h=Gt(l)):(h=this.#e,l="");let w,d;this.#t?(w=Nn(JSON.stringify(this.#t)),d=Gt(w)):(w="",d=new Uint8Array);const I=vs(d,Gt("."),h),v=await Ds(e,c),N=await $a(c,v,I),F={signature:Nn(N),payload:l};return this.#r&&(F.header=this.#r),this.#t&&(F.protected=w),F}}class Qa{#e;constructor(e){this.#e=new Ya(e)}setProtectedHeader(e){return this.#e.setProtectedHeader(e),this}async sign(e,r){const n=await this.#e.sign(e,r);if(n.payload===void 0)throw new TypeError("use the flattened module for creating JWS with b64: false");return`${n.protected}.${n.payload}.${n.signature}`}}const St=t=>Math.floor(t.getTime()/1e3),Os=60,$s=Os*60,Cn=$s*24,Xa=Cn*7,Za=Cn*365.25,ec=/^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;function lr(t){const e=ec.exec(t);if(!e||e[4]&&e[1])throw new TypeError("Invalid time period format");const r=parseFloat(e[2]),n=e[3].toLowerCase();let s;switch(n){case"sec":case"secs":case"second":case"seconds":case"s":s=Math.round(r);break;case"minute":case"minutes":case"min":case"mins":case"m":s=Math.round(r*Os);break;case"hour":case"hours":case"hr":case"hrs":case"h":s=Math.round(r*$s);break;case"day":case"days":case"d":s=Math.round(r*Cn);break;case"week":case"weeks":case"w":s=Math.round(r*Xa);break;default:s=Math.round(r*Za);break}return e[1]==="-"||e[4]==="ago"?-s:s}function Ft(t,e){if(!Number.isFinite(e))throw new TypeError(`Invalid ${t} input`);return e}const js=t=>t.includes("/")?t.toLowerCase():`application/${t.toLowerCase()}`,tc=(t,e)=>typeof t=="string"?e.includes(t):Array.isArray(t)?e.some(Set.prototype.has.bind(new Set(t))):!1;function rc(t,e,r={}){let n;try{n=JSON.parse(ur.decode(e))}catch{}if(!fr(n))throw new Mn("JWT Claims Set must be a top-level JSON object");const{typ:s}=r;if(s&&(typeof t.typ!="string"||js(t.typ)!==js(s)))throw new it('unexpected "typ" JWT header value',n,"typ","check_failed");const{requiredClaims:i=[],issuer:c,subject:l,audience:h,maxTokenAge:w}=r,d=[...i];w!==void 0&&d.push("iat"),h!==void 0&&d.push("aud"),l!==void 0&&d.push("sub"),c!==void 0&&d.push("iss");for(const F of new Set(d.reverse()))if(!(F in n))throw new it(`missing required "${F}" claim`,n,F,"missing");if(c&&!(Array.isArray(c)?c:[c]).includes(n.iss))throw new it('unexpected "iss" claim value',n,"iss","check_failed");if(l&&n.sub!==l)throw new it('unexpected "sub" claim value',n,"sub","check_failed");if(h&&!tc(n.aud,typeof h=="string"?[h]:h))throw new it('unexpected "aud" claim value',n,"aud","check_failed");let I;switch(typeof r.clockTolerance){case"string":I=lr(r.clockTolerance);break;case"number":I=r.clockTolerance;break;case"undefined":I=0;break;default:throw new TypeError("Invalid clockTolerance option type")}const{currentDate:v}=r,N=St(v||new Date);if((n.iat!==void 0||w)&&typeof n.iat!="number")throw new it('"iat" claim must be a number',n,"iat","invalid");if(n.nbf!==void 0){if(typeof n.nbf!="number")throw new it('"nbf" claim must be a number',n,"nbf","invalid");if(n.nbf>N+I)throw new it('"nbf" claim timestamp check failed',n,"nbf","check_failed")}if(n.exp!==void 0){if(typeof n.exp!="number")throw new it('"exp" claim must be a number',n,"exp","invalid");if(n.exp<=N-I)throw new xs('"exp" claim timestamp check failed',n,"exp","check_failed")}if(w){const F=N-n.iat,$=typeof w=="number"?w:lr(w);if(F-I>$)throw new xs('"iat" claim timestamp check failed (too far in the past)',n,"iat","check_failed");if(F<0-I)throw new it('"iat" claim timestamp check failed (it should be in the past)',n,"iat","check_failed")}return n}class nc{#e;constructor(e){if(!fr(e))throw new TypeError("JWT Claims Set MUST be an object");this.#e=structuredClone(e)}data(){return Cr.encode(JSON.stringify(this.#e))}get iss(){return this.#e.iss}set iss(e){this.#e.iss=e}get sub(){return this.#e.sub}set sub(e){this.#e.sub=e}get aud(){return this.#e.aud}set aud(e){this.#e.aud=e}set jti(e){this.#e.jti=e}set nbf(e){typeof e=="number"?this.#e.nbf=Ft("setNotBefore",e):e instanceof Date?this.#e.nbf=Ft("setNotBefore",St(e)):this.#e.nbf=St(new Date)+lr(e)}set exp(e){typeof e=="number"?this.#e.exp=Ft("setExpirationTime",e):e instanceof Date?this.#e.exp=Ft("setExpirationTime",St(e)):this.#e.exp=St(new Date)+lr(e)}set iat(e){e===void 0?this.#e.iat=St(new Date):e instanceof Date?this.#e.iat=Ft("setIssuedAt",St(e)):typeof e=="string"?this.#e.iat=Ft("setIssuedAt",St(new Date)+lr(e)):this.#e.iat=Ft("setIssuedAt",e)}}class ic{#e;#t;constructor(e={}){this.#t=new nc(e)}setIssuer(e){return this.#t.iss=e,this}setSubject(e){return this.#t.sub=e,this}setAudience(e){return this.#t.aud=e,this}setJti(e){return this.#t.jti=e,this}setNotBefore(e){return this.#t.nbf=e,this}setExpirationTime(e){return this.#t.exp=e,this}setIssuedAt(e){return this.#t.iat=e,this}setProtectedHeader(e){return this.#e=e,this}async sign(e,r){const n=new Qa(this.#t.data());if(n.setProtectedHeader(this.#e),Array.isArray(this.#e?.crit)&&this.#e.crit.includes("b64")&&this.#e.b64===!1)throw new Mn("JWTs MUST NOT use unencoded payload");return n.sign(e,r)}}async function sc(t,e,r,n){const s=await ks(t,e,"verify");Rs(t,s);const i=As(t,s.algorithm);try{return await crypto.subtle.verify(i,s,r,n)}catch{return!1}}async function oc(t,e,r){if(!fr(t))throw new _e("Flattened JWS must be an object");if(t.protected===void 0&&t.header===void 0)throw new _e('Flattened JWS must have either of the "protected" or "header" members');if(t.protected!==void 0&&typeof t.protected!="string")throw new _e("JWS Protected Header incorrect type");if(t.payload===void 0)throw new _e("JWS Payload missing");if(typeof t.signature!="string")throw new _e("JWS Signature missing or incorrect type");if(t.header!==void 0&&!fr(t.header))throw new _e("JWS Unprotected Header incorrect type");let n={};if(t.protected)try{const $=Pr(t.protected);n=JSON.parse(ur.decode($))}catch{throw new _e("JWS Protected Header is invalid")}if(!Ns(n,t.header))throw new _e("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");const s={...n,...t.header},i=Cs(_e,new Map([["b64",!0]]),r?.crit,n,s);let c=!0;if(i.has("b64")&&(c=n.b64,typeof c!="boolean"))throw new _e('The "b64" (base64url-encode payload) Header Parameter must be a boolean');const{alg:l}=s;if(typeof l!="string"||!l)throw new _e('JWS "alg" (Algorithm) Header Parameter missing or invalid');if(c){if(typeof t.payload!="string")throw new _e("JWS Payload must be a string")}else if(typeof t.payload!="string"&&!(t.payload instanceof Uint8Array))throw new _e("JWS Payload must be a string or an Uint8Array instance");let h=!1;typeof e=="function"&&(e=await e(n,t),h=!0),Ls(l,e,"verify");const w=vs(t.protected!==void 0?Gt(t.protected):new Uint8Array,Gt("."),typeof t.payload=="string"?c?Gt(t.payload):Cr.encode(t.payload):t.payload);let d;try{d=Pr(t.signature)}catch{throw new _e("Failed to base64url decode the signature")}const I=await Ds(e,l);if(!await sc(l,I,d,w))throw new La;let N;if(c)try{N=Pr(t.payload)}catch{throw new _e("Failed to base64url decode the payload")}else typeof t.payload=="string"?N=Cr.encode(t.payload):N=t.payload;const F={payload:N};return t.protected!==void 0&&(F.protectedHeader=n),t.header!==void 0&&(F.unprotectedHeader=t.header),h?{...F,key:I}:F}async function ac(t,e,r){if(t instanceof Uint8Array&&(t=ur.decode(t)),typeof t!="string")throw new _e("Compact JWS must be a string or Uint8Array");const{0:n,1:s,2:i,length:c}=t.split(".");if(c!==3)throw new _e("Invalid Compact JWS");const l=await oc({payload:s,protected:n,signature:i},e,r),h={payload:l.payload,protectedHeader:l.protectedHeader};return typeof e=="function"?{...h,key:l.key}:h}async function cc(t,e,r){const n=await ac(t,e,r);if(n.protectedHeader.crit?.includes("b64")&&n.protectedHeader.b64===!1)throw new Mn("JWTs MUST NOT use unencoded payload");const i={payload:rc(n.protectedHeader,n.payload,r),protectedHeader:n.protectedHeader};return typeof e=="function"?{...i,key:n.key}:i}function ot(t){return typeof t.saveState<"u"&&typeof t.restoreState<"u"&&typeof t.cleanSavedState<"u"}function _t(t){for(let e=0;e<t.length;e++)t[e]=0;return t}class uc{blockSize;digestLength;_inner;_outer;_finished=!1;_innerKeyedState;_outerKeyedState;constructor(e,r){this._inner=new e,this._outer=new e,this.blockSize=this._outer.blockSize,this.digestLength=this._outer.digestLength;const n=new Uint8Array(this.blockSize);r.length>this.blockSize?this._inner.update(r).finish(n).clean():n.set(r);for(let s=0;s<n.length;s++)n[s]^=54;this._inner.update(n);for(let s=0;s<n.length;s++)n[s]^=106;this._outer.update(n),ot(this._inner)&&ot(this._outer)&&(this._innerKeyedState=this._inner.saveState(),this._outerKeyedState=this._outer.saveState()),_t(n)}reset(){if(!ot(this._inner)||!ot(this._outer))throw new Error("hmac: can't reset() because hash doesn't implement restoreState()");return this._inner.restoreState(this._innerKeyedState),this._outer.restoreState(this._outerKeyedState),this._finished=!1,this}clean(){ot(this._inner)&&this._inner.cleanSavedState(this._innerKeyedState),ot(this._outer)&&this._outer.cleanSavedState(this._outerKeyedState),this._inner.clean(),this._outer.clean()}update(e){return this._inner.update(e),this}finish(e){return this._finished?(this._outer.finish(e),this):(this._inner.finish(e),this._outer.update(e.subarray(0,this.digestLength)).finish(e),this._finished=!0,this)}digest(){const e=new Uint8Array(this.digestLength);return this.finish(e),e}saveState(){if(!ot(this._inner))throw new Error("hmac: can't saveState() because hash doesn't implement it");return this._inner.saveState()}restoreState(e){if(!ot(this._inner)||!ot(this._outer))throw new Error("hmac: can't restoreState() because hash doesn't implement it");return this._inner.restoreState(e),this._outer.restoreState(this._outerKeyedState),this._finished=!1,this}cleanSavedState(e){if(!ot(this._inner))throw new Error("hmac: can't cleanSavedState() because hash doesn't implement it");this._inner.cleanSavedState(e)}}function fc(t,e=0){return(t[e]<<24|t[e+1]<<16|t[e+2]<<8|t[e+3])>>>0}function Dr(t,e=new Uint8Array(4),r=0){return e[r+0]=t>>>24,e[r+1]=t>>>16,e[r+2]=t>>>8,e[r+3]=t>>>0,e}function lc(t,e,r,n,s){const i=new uc(t,e),c=i.digestLength,l=new Uint8Array(4),h=new Uint8Array(c),w=new Uint8Array(c),d=new Uint8Array(s),I=i.update(r).saveState();for(let v=0;v*c<s;v++){Dr(v+1,l),i.restoreState(I).update(l).finish(w);for(let N=0;N<c;N++)h[N]=w[N];for(let N=2;N<=n;N++){i.reset().update(w).finish(w);for(let F=0;F<c;F++)h[F]^=w[F]}for(let N=0;N<c&&v*c+N<s;N++)d[v*c+N]=h[N]}return _t(h),_t(w),_t(l),i.cleanSavedState(I),i.clean(),d}const hc=32,dc=64;class pc{digestLength=hc;blockSize=dc;_state=new Int32Array(8);_temp=new Int32Array(64);_buffer=new Uint8Array(128);_bufferLength=0;_bytesHashed=0;_finished=!1;constructor(){this.reset()}_initState(){this._state[0]=1779033703,this._state[1]=3144134277,this._state[2]=1013904242,this._state[3]=2773480762,this._state[4]=1359893119,this._state[5]=2600822924,this._state[6]=528734635,this._state[7]=1541459225}reset(){return this._initState(),this._bufferLength=0,this._bytesHashed=0,this._finished=!1,this}clean(){_t(this._buffer),_t(this._temp),this.reset()}update(e,r=e.length){if(this._finished)throw new Error("SHA256: can't update because hash was finished.");let n=0;if(this._bytesHashed+=r,this._bufferLength>0){for(;this._bufferLength<this.blockSize&&r>0;)this._buffer[this._bufferLength++]=e[n++],r--;this._bufferLength===this.blockSize&&(Pn(this._temp,this._state,this._buffer,0,this.blockSize),this._bufferLength=0)}for(r>=this.blockSize&&(n=Pn(this._temp,this._state,e,n,r),r%=this.blockSize);r>0;)this._buffer[this._bufferLength++]=e[n++],r--;return this}finish(e){if(!this._finished){const r=this._bytesHashed,n=this._bufferLength,s=r/536870912|0,i=r<<3,c=r%64<56?64:128;this._buffer[n]=128;for(let l=n+1;l<c-8;l++)this._buffer[l]=0;Dr(s,this._buffer,c-8),Dr(i,this._buffer,c-4),Pn(this._temp,this._state,this._buffer,0,c),this._finished=!0}for(let r=0;r<this.digestLength/4;r++)Dr(this._state[r],e,r*4);return this}digest(){const e=new Uint8Array(this.digestLength);return this.finish(e),e}saveState(){if(this._finished)throw new Error("SHA256: cannot save finished state");return{state:new Int32Array(this._state),buffer:this._bufferLength>0?new Uint8Array(this._buffer):void 0,bufferLength:this._bufferLength,bytesHashed:this._bytesHashed}}restoreState(e){return this._state.set(e.state),this._bufferLength=e.bufferLength,e.buffer&&this._buffer.set(e.buffer),this._bytesHashed=e.bytesHashed,this._finished=!1,this}cleanSavedState(e){_t(e.state),e.buffer&&_t(e.buffer),e.bufferLength=0,e.bytesHashed=0}}const yc=new Int32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);function Pn(t,e,r,n,s){for(;s>=64;){let i=e[0],c=e[1],l=e[2],h=e[3],w=e[4],d=e[5],I=e[6],v=e[7];for(let N=0;N<16;N++){let F=n+N*4;t[N]=fc(r,F)}for(let N=16;N<64;N++){let F=t[N-2],$=(F>>>17|F<<15)^(F>>>19|F<<13)^F>>>10;F=t[N-15];let j=(F>>>7|F<<25)^(F>>>18|F<<14)^F>>>3;t[N]=($+t[N-7]|0)+(j+t[N-16]|0)}for(let N=0;N<64;N++){let F=(((w>>>6|w<<26)^(w>>>11|w<<21)^(w>>>25|w<<7))+(w&d^~w&I)|0)+(v+(yc[N]+t[N]|0)|0)|0,$=((i>>>2|i<<30)^(i>>>13|i<<19)^(i>>>22|i<<10))+(i&c^i&l^c&l)|0;v=I,I=d,d=w,w=h+F|0,h=l,l=c,c=i,i=F+$|0}e[0]+=i,e[1]+=c,e[2]+=l,e[3]+=h,e[4]+=w,e[5]+=d,e[6]+=I,e[7]+=v,n+=64,s-=64}return n}var wc=pr();class gc{constructor(e,r,n,s){this.timestamp=e,this.level=r,this.msg=n,this.data=s}async resolve(){if(this.msg instanceof Promise&&(this.msg=await this.msg.catch(()=>"<resolve-failed>")),this.data)for(const e of Object.keys(this.data))this.data[e]instanceof Promise&&(this.data[e]=await this.data[e].catch(()=>"<resolve-failed>"))}toString(){const e=new Date(this.timestamp),r=e.getFullYear(),n=(e.getMonth()+1).toString().padStart(2,"0"),s=e.getDate().toString().padStart(2,"0"),i=e.getHours().toString().padStart(2,"0"),c=e.getMinutes().toString().padStart(2,"0"),l=e.getSeconds().toString().padStart(2,"0"),h=e.getMilliseconds().toString().padStart(3,"0"),w=`${r}-${n}-${s} ${i}:${c}:${l}.${h}`,d=this.msg instanceof Promise?"<unresolved>":this.msg;let I="";if(this.data!==void 0){const v=this.data;I=` (${Object.keys(v).map(F=>{const $=v[F]instanceof Promise?"<unresolved>":v[F];return`${F}: ${Bn.stringify($)}`}).join(", ")})`}return`[${w}] ${this.level}: ${d}${I}`}}class mc extends Ma{constructor(){super(...arguments),this._events=new wc.EventEmitter}on(...e){this._events.on(...e)}off(...e){this._events.off(...e)}emitEvent(...e){return this._events.listenerCount(e[0])===0?!1:this._events.emit(...e)}log(e,r,n){const s=new gc(Date.now(),e,r,n);this.emitEvent("log",s)}error(e,r){let n=e;r!==void 0&&(n=new Error(`${r}: ${e.message}`,{cause:e})),this.emitEvent("error",n),this.log("error",n.message)}}class bc extends mc{constructor(e,r={}){super(r),e===null&&(this.log("info","establishing proxy MQTT client"),e=new Proxy({},{get(n,s,i){return s==="isFakeProxy"?!0:typeof s=="string"&&["on","off","once"].includes(s)?()=>{}:()=>{throw new Error(`Underlying MQTT operation "${String(s)}" called on a null MQTT client -- only MQTT+ "emit({ ..., dry: true })" is supported in this special operation mode`)}}})),this.mqtt=e,this.log("info","hooking into MQTT client"),this._messageHandler=(n,s,i)=>{let c;if(this.options.codec==="json")c=s.toString();else if(this.options.codec==="cbor")c=bi.isBuffer(s)?new Uint8Array(s.buffer,s.byteOffset,s.byteLength):s;else throw new Error("invalid codec configured");this._onMessage(n,c,i)},this.mqtt.on("message",this._messageHandler)}destroy(){this.log("info","un-hooking from MQTT client"),this.mqtt.off("message",this._messageHandler)}async _subscribeTopic(e,r={}){return this.log("info",`subscribing to MQTT topic "${e}"`),new Promise((n,s)=>{this.mqtt.subscribe(e,{qos:2,...r},(i,c)=>{i?(this.error(i,`subscribing to MQTT topic "${e}" failed`),s(i)):n()})})}async _unsubscribeTopic(e){return this.log("info",`unsubscribing from MQTT topic "${e}"`),new Promise((r,n)=>{this.mqtt.unsubscribe(e,(s,i)=>{s?(this.error(s,`unsubscribing from MQTT topic "${e}" failed`),n(s)):r()})})}async _publishToTopic(e,r,n={}){typeof r=="string"?this.log("info",`publishing to MQTT topic "${e}" (type: string, length: ${r.length} chars)`):this.log("info",`publishing to MQTT topic "${e}" (type: buffer, length: ${r.byteLength} bytes)`);const s=new jt((i,c)=>{let l;try{const h=this.codec.decode(r);l=this.msg.parse(h)}catch(h){return c(h)}i(l)});return this.log("debug",`publishing to MQTT topic "${e}"`,{message:s}),new Promise((i,c)=>{const l=typeof r=="string"?r:bi.from(r.buffer,r.byteOffset,r.byteLength);this.mqtt.publish(e,l,n,h=>{h?(this.error(h,`publishing to MQTT topic "${e}" failed`),c(h)):i()})})}_onMessage(e,r,n){typeof r=="string"?this.log("info",`received from MQTT topic "${e}" (type: string, length: ${r.length} chars)`):this.log("info",`received from MQTT topic "${e}" (type: buffer, length: ${r.byteLength} bytes)`);let s;try{const i=this.codec.decode(r);s=this.msg.parse(i)}catch(i){const c=i instanceof Error?new Error(`failed to parse message: ${i.message}`,{cause:i}):new Error("failed to parse message");this.error(c);return}this.log("debug",`received from MQTT topic "${e}"`,{message:s}),this._dispatchMessage(e,s).catch(i=>{this.error(i,`dispatching message from MQTT topic "${e}" failed`)})}async _dispatchMessage(e,r){}}class Ec extends bc{constructor(){super(...arguments),this._meta=new Map}meta(e,r){if(e===void 0)return Object.fromEntries(this._meta);if(arguments.length===1)return this._meta.get(e);r==null?this._meta.delete(e):this._meta.set(e,r)}metaStore(e){const r=e===void 0||Object.keys(e).length===0;if(!(this._meta.size===0&&r))return this._meta.size>0&&r?Object.fromEntries(this._meta):this._meta.size===0&&!r?e:{...Object.fromEntries(this._meta),...e}}}class Sc extends Ec{constructor(){super(...arguments),this._credential=null,this._tokens=new Set}credential(e){if(e.length===0)throw new Error("credential must not be empty");const r=new TextEncoder().encode(e),n=new TextEncoder().encode("mqtt-plus");this._credential=lc(pc,r,n,6e5,32)}async issue(e){if(this._credential===null)throw new Error("credential has to be provided before issuing tokens");const r=new ic(e);return r.setProtectedHeader({alg:"HS256",typ:"JWT"}),await r.sign(this._credential)}authenticate(e,r){if(e===void 0)return this._tokens.size>0?Array.from(this._tokens):void 0;r===!0?this._tokens.delete(e):this._tokens.add(e)}async validateToken(e){if(this._credential===null)throw new Error("credential has to be provided before validating tokens");return(await cc(e,this._credential).catch(()=>null))?.payload??null}async authenticated(e,r,n){let s=!1,i,c;if(typeof n=="string"?(i="require",c=[n]):(i=n.mode,c=n.roles),r!==void 0)for(const l of r.slice(0,8)){if(l.length>8192)continue;const h=await this.validateToken(l);if(h!==null&&!(h.id&&h.id!==e)&&Array.isArray(h.roles)&&!(h.roles.length>64)){for(const w of c)if(h.roles.includes(w)){s=!0;break}if(s)break}}return!s&&i==="optional"&&(s=!0),s}}class _c extends Sc{constructor(){super(...arguments),this.events=new Map}async event(e,...r){let n,s,i={},c,l;typeof e=="object"&&e!==null?(n=e.name,s=e.callback,i=e.options??{},c=e.share,l=e.auth):(n=e,s=r[0]);const h=new Pe;if(this.events.has(n))throw new Error(`event: event "${n}" already registered`);const w=c?`$share/${c}/${n}`:n,d=this.options.topicMake(w,"event-emission"),I=this.options.topicMake(n,"event-emission",this.options.id);return this.events.set(n,(v,N)=>{const F=v.sender,$=v.params??[],j={sender:F??""};v.receiver&&(j.receiver=v.receiver),v.meta&&(j.meta=v.meta),Promise.resolve().then(async()=>{if(N!==n)throw new Error(`event name mismatch (topic: "${N}", payload: "${n}")`);if(l&&(j.authenticated=await this.authenticated(v.sender,v.auth,l)),j.authenticated!==void 0&&!j.authenticated)throw new Error(`authentication on event "${n}" failed`);return s(...$,j)}).catch(_=>{const A=yt(_);this.error(A,`handler for event "${n}" failed`)})}),h.roll(()=>{this.events.delete(n)}),await ke(`subscribe to MQTT topic "${d}"`,h,()=>this._subscribeTopic(d,{qos:2,...i})),h.roll(()=>this._unsubscribeTopic(d).catch(()=>{})),await ke(`subscribe to MQTT topic "${I}"`,h,()=>this._subscribeTopic(I,{qos:2,...i})),h.roll(()=>this._unsubscribeTopic(I).catch(()=>{})),{destroy:async()=>{if(!this.events.has(n))throw new Error(`destroy: event "${n}" not registered`);await h.unroll(!1)?.catch(v=>{this.error(v,`destroy: failed to cleanup: ${v.message}`)})}}}emit(e,...r){let n,s,i,c={},l={},h;typeof e=="object"&&e!==null?(n=e.event,s=e.params,i=e.receiver,c=e.options??{},l=e.meta??{},h=e.dry):(n=e,s=r);const w=Xt(),d=this.authenticate(),I=this.metaStore(l),v=this.msg.makeEventEmission(w,n,s,this.options.id,i,d,I),N=this.codec.encode(v),F=this.options.topicMake(n,"event-emission",i);if(h)return{topic:F,payload:N,options:{qos:0,...c}};this._publishToTopic(F,N,{qos:0,...c}).catch($=>{this.error($,`emitting event "${n}" failed`)})}async _dispatchMessage(e,r){await super._dispatchMessage(e,r);const n=this.options.topicMatch(e);if(n!==null&&n.operation==="event-emission"&&r instanceof ds){const s=this.events.get(r.name);s!==void 0&&s(r,n.name)}}}class Tc extends _c{constructor(){super(...arguments),this.services=new Map,this.callCallbacks=new Map,this.callSubscriptions=new hn((e,r)=>this._subscribeTopic(e,r),e=>this._unsubscribeTopic(e))}destroy(){super.destroy(),this.callSubscriptions.flush()}async service(e,...r){let n,s,i={},c="default",l;typeof e=="object"&&e!==null?(n=e.name,s=e.callback,i=e.options??{},c=e.share??"default",l=e.auth):(n=e,s=r[0]);const h=new Pe;if(this.services.has(n))throw new Error(`register: service "${n}" already registered`);const w=`$share/${c}/${n}`,d=this.options.topicMake(w,"service-call-request"),I=this.options.topicMake(n,"service-call-request",this.options.id);return this.services.set(n,(v,N)=>{const F=v.id,$=v.sender;if($===void 0||$==="")throw new Error("invalid request: missing sender");const j=v.params??[],_={sender:$};v.receiver&&(_.receiver=v.receiver),v.meta&&(_.meta=v.meta),Promise.resolve().then(async()=>{if(N!==n)throw new Error(`service name mismatch (topic: "${N}", payload: "${n}")`);if(l&&(_.authenticated=await this.authenticated($,v.auth,l)),_.authenticated!==void 0&&!_.authenticated)throw new Error(`service "${n}" failed authentication`);return s(...j,_)}).then(A=>this.msg.makeServiceCallResponse(F,A,void 0,this.options.id,$),A=>{const R=yt(A);return this.error(R,`handler for service "${n}" failed`),this.msg.makeServiceCallResponse(F,void 0,R.message,this.options.id,$)}).then(A=>{const R=this.codec.encode(A),S=this.options.topicMake(n,"service-call-response",$);return this._publishToTopic(S,R,{qos:2})}).catch(A=>{this.error(A,`handler for service "${n}" failed`)})}),h.roll(()=>{this.services.delete(n)}),await ke(`subscribe to MQTT topic "${d}"`,h,()=>this._subscribeTopic(d,{qos:2,...i})),h.roll(()=>this._unsubscribeTopic(d).catch(()=>{})),await ke(`subscribe to MQTT topic "${I}"`,h,()=>this._subscribeTopic(I,{qos:2,...i})),h.roll(()=>this._unsubscribeTopic(I).catch(()=>{})),{destroy:async()=>{if(!this.services.has(n))throw new Error(`destroy: service "${n}" no longer registered`);await h.unroll(!1)?.catch(v=>{this.error(v,`destroy: failed to cleanup: ${v.message}`)})}}}async call(e,...r){let n,s,i,c={},l={};typeof e=="object"&&e!==null?(n=e.name,s=e.params,i=e.receiver,c=e.options??{},l=e.meta??{}):(n=e,s=r);const h=new Pe,w=Xt(),d=this.options.topicMake(n,"service-call-response",this.options.id);await ke(`subscribe to MQTT topic "${d}"`,h,()=>this.callSubscriptions.subscribe(d,{qos:c.qos??2})),h.roll(()=>this.callSubscriptions.unsubscribe(d));const I=new Promise((_,A)=>{let R=setTimeout(async()=>{R=null,await h.unroll(),A(new Error("communication timeout"))},this.options.timeout);h.roll(()=>{R!==null&&(clearTimeout(R),R=null)}),this.callCallbacks.set(w,async S=>{await h.unroll(),S.error!==void 0?A(new Error(S.error)):_(S.result)}),h.roll(()=>{this.callCallbacks.delete(w)})}),v=this.authenticate(),N=this.metaStore(l),F=this.msg.makeServiceCallRequest(w,n,s,this.options.id,i,v,N),$=this.codec.encode(F),j=this.options.topicMake(n,"service-call-request",i);return await ke(`publish service request as MQTT message to topic "${j}"`,h,()=>this._publishToTopic(j,$,{qos:2,...c})),I}async _dispatchMessage(e,r){await super._dispatchMessage(e,r);const n=this.options.topicMatch(e);if(n!==null&&n.operation==="service-call-request"&&r instanceof ps){const s=this.services.get(r.name);s!==void 0&&s(r,n.name)}else if(n!==null&&n.operation==="service-call-response"&&n.peerId===this.options.id&&r instanceof ys){const s=this.callCallbacks.get(r.id);s!==void 0&&s(r)}}}class vc extends Tc{constructor(){super(...arguments),this.sources=new Map,this.fetchResponseCallbacks=new Map,this.fetchChunkCallbacks=new Map,this.sourceCreditCallbacks=new Map,this.sourceCreditGates=new Map,this.sourceTimers=new Map,this.fetchSubscriptions=new hn((e,r)=>this._subscribeTopic(e,r),e=>this._unsubscribeTopic(e))}_refreshSourceTimer(e){const r=this.sourceTimers.get(e);r!==void 0&&clearTimeout(r),this.sourceTimers.set(e,setTimeout(()=>{this.sourceTimers.delete(e);const n=this.sourceCreditGates.get(e);n!==void 0&&n.abort()},this.options.timeout))}_clearSourceTimer(e){const r=this.sourceTimers.get(e);r!==void 0&&(clearTimeout(r),this.sourceTimers.delete(e))}destroy(){super.destroy(),this.fetchSubscriptions.flush()}async source(e,...r){let n,s,i={},c="default",l;typeof e=="object"&&e!==null?(n=e.name,s=e.callback,i=e.options??{},c=e.share??"default",l=e.auth):(n=e,s=r[0]);const h=new Pe;if(this.sources.has(n))throw new Error(`source: source "${n}" already established`);const w=`$share/${c}/${n}`,d=this.options.topicMake(w,"source-fetch-request"),I=this.options.topicMake(n,"source-fetch-request",this.options.id),v=this.options.topicMake(n,"source-fetch-credit",this.options.id);return this.sources.set(n,(N,F)=>{const $=N.id,j=N.params??[],_=N.sender;if(_===void 0||_==="")throw new Error("invalid request: missing sender");const A=N.receiver,R={sender:_};A&&(R.receiver=A),N.meta&&(R.meta=N.meta);const S=this.options.topicMake(n,"source-fetch-response",_),T=this.options.topicMake(n,"source-fetch-chunk",_),M=async Y=>{const se=this.authenticate(),fe=this.metaStore(R.meta),Re=this.msg.makeSourceFetchResponse($,n,Y,this.options.id,_,se,fe),Te=this.codec.encode(Re);await this._publishToTopic(S,Te,{qos:2})},C=()=>this._refreshSourceTimer($),U=()=>this._clearSourceTimer($);C();const W=async(Y,se,fe)=>{C();const Re=this.msg.makeSourceFetchChunk($,n,Y,se,fe,this.options.id,_),Te=this.codec.encode(Re);await this._publishToTopic(T,Te,{qos:2})},J=N.credit,Q=J!==void 0&&J>0?new Ei(J):void 0;Q&&(this.sourceCreditGates.set($,Q),this.sourceCreditCallbacks.set($,Y=>{Q.replenish(Y.credit),this._refreshSourceTimer($)}));let k=!1;Promise.resolve().then(async()=>{if(F!==N.name)throw new Error(`source name mismatch between topic "${F}" and payload "${N.name}"`);if(l&&(R.authenticated=await this.authenticated(N.sender,N.auth,l)),R.authenticated!==void 0&&!R.authenticated)throw new Error(`source "${n}" failed authentication`);return s(...j,R)}).then(async()=>{if(!(R.stream instanceof Ot.Readable)&&!(R.buffer instanceof Promise))throw new Error("handler did not provide data via info.stream or info.buffer fields");if(R.stream instanceof Ot.Readable&&R.buffer instanceof Promise)throw new Error("handler has set both info.stream and info.buffer fields");await M(),k=!0,R.stream instanceof Ot.Readable?await vi(R.stream,this.options.chunkSize,W,Q):R.buffer instanceof Promise&&await Ti(await R.buffer,this.options.chunkSize,W,Q)}).catch(Y=>{const se=yt(Y);return this.error(se,`handler for source "${n}" failed`),k?W(void 0,se.message,!0).catch(()=>{}):M(se.message).catch(()=>{})}).finally(()=>{U(),Q&&(Q.abort(),this.sourceCreditGates.delete($)),this.sourceCreditCallbacks.delete($)})}),h.roll(()=>{this.sources.delete(n)}),await ke(`subscribe to MQTT topic "${d}"`,h,()=>this._subscribeTopic(d,{qos:2,...i})),h.roll(()=>this._unsubscribeTopic(d).catch(()=>{})),await ke(`subscribe to MQTT topic "${I}"`,h,()=>this._subscribeTopic(I,{qos:2,...i})),h.roll(()=>this._unsubscribeTopic(I).catch(()=>{})),await ke(`subscribe to MQTT topic "${v}"`,h,()=>this._subscribeTopic(v,{qos:2,...i})),h.roll(()=>this._unsubscribeTopic(v).catch(()=>{})),{destroy:async()=>{if(!this.sources.has(n))throw new Error(`destroy: source "${n}" not established`);await h.unroll(!1)?.catch(N=>{this.error(N,`destroy: failed to cleanup: ${N.message}`)})}}}async fetch(e,...r){let n,s,i,c={},l;typeof e=="object"&&e!==null?(n=e.name,s=e.params,i=e.receiver,c=e.options??{},l=e.meta):(n=e,s=r);const h=new Pe,w=Xt(),d=this.options.topicMake(n,"source-fetch-response",this.options.id),I=this.options.topicMake(n,"source-fetch-chunk",this.options.id);await ke(`subscribe to MQTT topic "${d}"`,h,()=>this.fetchSubscriptions.subscribe(d,{qos:c.qos??2})),h.roll(()=>this.fetchSubscriptions.unsubscribe(d)),await ke(`subscribe to MQTT topic "${I}"`,h,()=>this.fetchSubscriptions.subscribe(I,{qos:c.qos??2})),h.roll(()=>this.fetchSubscriptions.unsubscribe(I));const v=this.options.chunkCredit;let N=0,F=v,$;const j=new Ot.Readable({highWaterMark:v>0?v*this.options.chunkSize:16*1024,read:Y=>{if(v<=0||!this.fetchChunkCallbacks.has(w))return;const se=$??i;if(!se)return;const fe=Math.max(0,N+v-F);if(fe>0){F+=fe;const Re=this.msg.makeSourceFetchCredit(w,n,fe,this.options.id,se),Te=this.codec.encode(Re),Ce=this.options.topicMake(n,"source-fetch-credit",se);this._publishToTopic(Ce,Te,{qos:2}).catch(He=>{this.error(He,`sending credit for fetch "${n}" failed`)})}}}),_=_i(j);let A;const R=new Promise(Y=>{A=Y});h.roll(()=>{A?.(void 0)});let S=null;h.roll(()=>{S!==null&&(clearTimeout(S),S=null)});const T=()=>{S!==null&&clearTimeout(S),S=setTimeout(()=>{j.destroy(new Error("communication timeout")),h.unroll()},this.options.timeout)};T(),j.once("close",()=>h.unroll()),j.once("error",()=>h.unroll()),this.fetchResponseCallbacks.set(w,Y=>{Y.sender&&($=Y.sender),A?.(Y.meta),Y.error?(j.destroy(new Error(Y.error)),h.unroll()):T()}),this.fetchChunkCallbacks.set(w,Y=>{Y.sender&&($=Y.sender),Y.error?(j.destroy(new Error(Y.error)),h.unroll()):(T(),Y.chunk!==void 0&&(N++,j.push(Y.chunk)),Y.final&&(j.push(null),h.unroll()))}),h.roll(()=>{this.fetchResponseCallbacks.delete(w),this.fetchChunkCallbacks.delete(w)});const M=this.authenticate(),C=this.metaStore(l),U=v>0?v:void 0,W=this.msg.makeSourceFetchRequest(w,n,s,this.options.id,i,M,C,U),J=this.codec.encode(W),Q=this.options.topicMake(n,"source-fetch-request",i);ke(`publish fetch request as MQTT message to topic "${Q}"`,h,()=>this._publishToTopic(Q,J,{qos:2,...c})).catch(Y=>{j.destroy(yt(Y)),h.unroll()});const k={stream:j,buffer:_,meta:R};return xi(k,"stream","buffer"),k}async _dispatchMessage(e,r){await super._dispatchMessage(e,r);const n=this.options.topicMatch(e);if(n!==null&&n.operation==="source-fetch-request"&&r instanceof Es){const s=this.sources.get(r.name);s!==void 0&&s(r,n.name)}else if(n!==null&&n.operation==="source-fetch-response"&&r instanceof Ss){const s=this.fetchResponseCallbacks.get(r.id);s!==void 0&&s(r)}else if(n!==null&&n.operation==="source-fetch-chunk"&&r instanceof _s){const s=this.fetchChunkCallbacks.get(r.id);s!==void 0&&s(r)}else if(n!==null&&n.operation==="source-fetch-credit"&&r instanceof Ts){const s=this.sourceCreditCallbacks.get(r.id);s!==void 0&&s(r)}}}class xc extends vc{constructor(){super(...arguments),this.sinks=new Map,this.pushStreams=new Map,this.pushSpools=new Map,this.pushTimers=new Map,this.pushChunkCallbacks=new Map,this.pushResponseCallbacks=new Map,this.pushCreditCallbacks=new Map,this.pushSubscriptions=new hn((e,r)=>this._subscribeTopic(e,r),e=>this._unsubscribeTopic(e))}destroy(){super.destroy(),this.pushSubscriptions.flush()}_refreshPushTimer(e){const r=this.pushTimers.get(e);r!==void 0&&clearTimeout(r),this.pushTimers.set(e,setTimeout(()=>{this.pushTimers.delete(e);const n=this.pushStreams.get(e);n!==void 0&&n.destroy(new Error("push stream timeout")),this.pushSpools.get(e)?.unroll()},this.options.timeout))}_clearPushTimer(e){const r=this.pushTimers.get(e);r!==void 0&&(clearTimeout(r),this.pushTimers.delete(e))}async sink(e,...r){let n,s,i={},c="default",l;typeof e=="object"&&e!==null?(n=e.name,s=e.callback,i=e.options??{},c=e.share??"default",l=e.auth):(n=e,s=r[0]);const h=new Pe;if(this.sinks.has(n))throw new Error(`sink: sink "${n}" already established`);const w=`$share/${c}/${n}`,d=this.options.topicMake(w,"sink-push-request"),I=this.options.topicMake(n,"sink-push-request",this.options.id),v=this.options.topicMake(n,"sink-push-chunk",this.options.id);return this.sinks.set(n,(N,F)=>{const $=N.id,j=N.params??[],_=N.sender;if(_===void 0||_==="")throw new Error("invalid request: missing sender");const A=N.receiver,R={sender:_};A&&(R.receiver=A),N.meta&&(R.meta=N.meta);const S=this.options.topicMake(n,"sink-push-response",_),T=this.options.chunkCredit,M=async U=>{const W=this.authenticate(),J=this.metaStore(R.meta),Q=T>0?T:void 0,k=this.msg.makeSinkPushResponse($,n,U,this.options.id,_,W,J,Q),Y=this.codec.encode(k);await this._publishToTopic(S,Y,{qos:2})},C=new Pe;this.pushSpools.set($,C),C.roll(()=>{this.pushSpools.delete($)}),Promise.resolve().then(async()=>{if(F!==N.name)throw new Error(`sink name mismatch between topic "${F}" and payload "${N.name}"`);if(l&&(R.authenticated=await this.authenticated(N.sender,N.auth,l)),R.authenticated!==void 0&&!R.authenticated)throw new Error(`sink "${n}" failed authentication`);const U=T>0?{chunksReceived:0,creditGranted:T}:void 0,W=()=>this._refreshPushTimer($),J=()=>this._clearPushTimer($),Q=new Ot.Readable({highWaterMark:T>0?T*this.options.chunkSize:16*1024,read:Y=>{if(!U||!this.pushSpools.has($))return;const se=Math.max(0,U.chunksReceived+T-U.creditGranted);if(se>0){U.creditGranted+=se;const fe=this.msg.makeSinkPushCredit($,n,se,this.options.id,_),Re=this.codec.encode(fe),Te=this.options.topicMake(n,"sink-push-credit",_);this._publishToTopic(Te,Re,{qos:2}).catch(Ce=>{this.error(Ce,`sending credit for push "${n}" failed`)}),W()}}});this.pushStreams.set($,Q),C.roll(()=>{this.pushStreams.delete($)}),Q.once("close",()=>C.unroll()),Q.once("error",()=>C.unroll()),this.pushChunkCallbacks.set($,(Y,se)=>{if(se!==Y.name)throw new Error(`sink name mismatch between topic "${se}" and payload "${Y.name}"`);Y.error!==void 0?(Q.destroy(new Error(Y.error)),C.unroll()):(W(),Y.chunk!==void 0&&(U&&U.chunksReceived++,Q.push(Y.chunk)),Y.final&&(Q.push(null),C.unroll()))}),C.roll(()=>{this.pushChunkCallbacks.delete($)}),W(),C.roll(()=>{J()});const k=_i(Q);return R.stream=Q,R.buffer=k,xi(R,"stream","buffer"),await M(),s(...j,R)}).catch(async U=>{const W=this.pushStreams.get($);W!==void 0&&W.destroy(),C.unroll(),this.error(U),await M(U.message).catch(()=>{})})}),h.roll(()=>{this.sinks.delete(n)}),await ke(`subscribe to MQTT topic "${d}"`,h,()=>this._subscribeTopic(d,{qos:2,...i})),h.roll(()=>this._unsubscribeTopic(d).catch(()=>{})),await ke(`subscribe to MQTT topic "${I}"`,h,()=>this._subscribeTopic(I,{qos:2,...i})),h.roll(()=>this._unsubscribeTopic(I).catch(()=>{})),await ke(`subscribe to MQTT topic "${v}"`,h,()=>this._subscribeTopic(v,{qos:2,...i})),h.roll(()=>this._unsubscribeTopic(v).catch(()=>{})),{destroy:async()=>{if(!this.sinks.has(n))throw new Error(`destroy: sink "${n}" not established`);await h.unroll(!1)?.catch(N=>{this.error(N,`destroy: failed to cleanup: ${N.message}`)})}}}async push(e,...r){let n,s,i,c,l={},h;typeof e=="object"&&e!==null?(n=e.name,s=e.data,i=e.params,c=e.receiver,l=e.options??{},h=e.meta):(n=e,s=r[0],i=r.slice(1));const w=new Pe,d=Xt(),I=this.options.topicMake(n,"sink-push-response",this.options.id);await ke(`subscribe to MQTT topic "${I}"`,w,()=>this.pushSubscriptions.subscribe(I,{qos:l.qos??2})),w.roll(()=>this.pushSubscriptions.unsubscribe(I));const v=new AbortController,N=v.signal;let F=null;w.roll(()=>{F!==null&&(clearTimeout(F),F=null)});const $=()=>{F!==null&&clearTimeout(F),F=setTimeout(()=>{v.abort(new Error(`push to sink "${n}" timed out`)),w.unroll()},this.options.timeout)};$();let j,_;try{if(await new Promise((S,T)=>{const M=()=>{T(N.reason)};N.addEventListener("abort",M,{once:!0}),w.roll(()=>{N.removeEventListener("abort",M)}),this.pushResponseCallbacks.set(d,k=>{k.error?T(new Error(k.error)):(k.sender&&(c=k.sender),j=k.credit,S())}),w.roll(()=>{this.pushResponseCallbacks.delete(d)}),this.pushCreditCallbacks.set(d,k=>{$()}),w.roll(()=>{this.pushCreditCallbacks.delete(d)});const C=this.authenticate(),U=this.metaStore(h),W=this.msg.makeSinkPushRequest(d,n,i,this.options.id,c,C,U),J=this.codec.encode(W),Q=this.options.topicMake(n,"sink-push-request",c);ke(`publish push request as MQTT message to topic "${Q}"`,w,()=>this._publishToTopic(Q,J,{qos:2,...l})).catch(k=>{T(k)})}),this.pushResponseCallbacks.set(d,S=>{S.error&&v.abort(new Error(S.error))}),j!==void 0&&j>0&&(_=new Ei(j)),_){const S=this.options.topicMake(n,"sink-push-credit",this.options.id);await ke(`subscribe to MQTT topic "${S}"`,w,()=>this.pushSubscriptions.subscribe(S,{qos:2})),w.roll(()=>this.pushSubscriptions.unsubscribe(S));const T=_;w.roll(()=>{T.abort()}),this.pushCreditCallbacks.set(d,M=>{T.replenish(M.credit),$()})}const A=this.options.topicMake(n,"sink-push-chunk",c),R=async(S,T,M)=>{$();const C=this.msg.makeSinkPushChunk(d,n,S,T,M,this.options.id,c),U=this.codec.encode(C);await this._publishToTopic(A,U,{qos:2,...l})};s instanceof Ot.Readable?await vi(s,this.options.chunkSize,R,_,N):s instanceof Uint8Array&&await Ti(s,this.options.chunkSize,R,_,N)}catch(A){const R=A instanceof Error?A.message:String(A),S=this.options.topicMake(n,"sink-push-chunk",c),T=this.msg.makeSinkPushChunk(d,n,void 0,R,!0,this.options.id,c),M=this.codec.encode(T);throw await this._publishToTopic(S,M,{qos:2,...l}).catch(()=>{}),A}finally{await w.unroll()}}async _dispatchMessage(e,r){await super._dispatchMessage(e,r);const n=this.options.topicMatch(e);if(n!==null&&n.operation==="sink-push-request"&&r instanceof ws){const s=this.sinks.get(r.name);s!==void 0&&s(r,n.name)}else if(n!==null&&n.operation==="sink-push-response"&&r instanceof gs){const s=this.pushResponseCallbacks.get(r.id);s!==void 0&&s(r)}else if(n!==null&&n.operation==="sink-push-chunk"&&r instanceof ms){const s=this.pushChunkCallbacks.get(r.id);s!==void 0&&s(r,n.name)}else if(n!==null&&n.operation==="sink-push-credit"&&r instanceof bs){const s=this.pushCreditCallbacks.get(r.id);s!==void 0&&s(r)}}}class Ac extends xc{}return Ac}));
14
+ `,w+=h,w},Un.noChildren=!0,ee.registerDecoder(oe.CBOR,Un),ee.registerDecoder(oe.URI,t=>(St(t.contents),new URL(t.contents)),"URI"),_e(URL,t=>[oe.URI,t.toString()]),ee.registerDecoder(oe.BASE64URL,t=>(St(t.contents),ua(t.contents)),"Base64url-encoded"),ee.registerDecoder(oe.BASE64,t=>(St(t.contents),vn(t.contents)),"Base64-encoded"),ee.registerDecoder(35,t=>(St(t.contents),new RegExp(t.contents)),"RegExp"),ee.registerDecoder(21065,t=>{St(t.contents);const e=`^(?:${t.contents})$`;return new RegExp(e,"u")},"I-RegExp"),ee.registerDecoder(oe.REGEXP,t=>{if(Ts(t.contents),t.contents.length<1||t.contents.length>2)throw new Error(`Invalid RegExp Array: ${t.contents}`);return new RegExp(t.contents[0],t.contents[1])},"RegExp"),_e(RegExp,t=>[oe.REGEXP,[t.source,t.flags]]),ee.registerDecoder(64,t=>(yt(t.contents),t.contents),"uint8 Typed Array");function Le(t,e,r){yt(t.contents);let n=t.contents.length;if(n%e.BYTES_PER_ELEMENT!==0)throw new Error(`Number of bytes must be divisible by ${e.BYTES_PER_ELEMENT}, got: ${n}`);n/=e.BYTES_PER_ELEMENT;const s=new e(n),i=new DataView(t.contents.buffer,t.contents.byteOffset,t.contents.byteLength),c=i[`get${e.name.replace(/Array/,"")}`].bind(i);for(let l=0;l<n;l++)s[l]=c(l*e.BYTES_PER_ELEMENT,r);return s}function _t(t,e,r,n,s){const i=s.forceEndian??_s;if(fr(i?e:r,t,s),He(n.byteLength,t,z.BYTE_STRING),_s===i)t.write(new Uint8Array(n.buffer,n.byteOffset,n.byteLength));else{const c=`write${n.constructor.name.replace(/Array/,"")}`,l=t[c].bind(t);for(const h of n)l(h,i)}}ee.registerDecoder(65,t=>Le(t,Uint16Array,!1),"uint16, big endian, Typed Array"),ee.registerDecoder(66,t=>Le(t,Uint32Array,!1),"uint32, big endian, Typed Array"),ee.registerDecoder(67,t=>Le(t,BigUint64Array,!1),"uint64, big endian, Typed Array"),ee.registerDecoder(68,t=>(yt(t.contents),new Uint8ClampedArray(t.contents)),"uint8 Typed Array, clamped arithmetic"),_e(Uint8ClampedArray,t=>[68,new Uint8Array(t.buffer,t.byteOffset,t.byteLength)]),ee.registerDecoder(69,t=>Le(t,Uint16Array,!0),"uint16, little endian, Typed Array"),_e(Uint16Array,(t,e,r)=>_t(e,69,65,t,r)),ee.registerDecoder(70,t=>Le(t,Uint32Array,!0),"uint32, little endian, Typed Array"),_e(Uint32Array,(t,e,r)=>_t(e,70,66,t,r)),ee.registerDecoder(71,t=>Le(t,BigUint64Array,!0),"uint64, little endian, Typed Array"),_e(BigUint64Array,(t,e,r)=>_t(e,71,67,t,r)),ee.registerDecoder(72,t=>(yt(t.contents),new Int8Array(t.contents)),"sint8 Typed Array"),_e(Int8Array,t=>[72,new Uint8Array(t.buffer,t.byteOffset,t.byteLength)]),ee.registerDecoder(73,t=>Le(t,Int16Array,!1),"sint16, big endian, Typed Array"),ee.registerDecoder(74,t=>Le(t,Int32Array,!1),"sint32, big endian, Typed Array"),ee.registerDecoder(75,t=>Le(t,BigInt64Array,!1),"sint64, big endian, Typed Array"),ee.registerDecoder(77,t=>Le(t,Int16Array,!0),"sint16, little endian, Typed Array"),_e(Int16Array,(t,e,r)=>_t(e,77,73,t,r)),ee.registerDecoder(78,t=>Le(t,Int32Array,!0),"sint32, little endian, Typed Array"),_e(Int32Array,(t,e,r)=>_t(e,78,74,t,r)),ee.registerDecoder(79,t=>Le(t,BigInt64Array,!0),"sint64, little endian, Typed Array"),_e(BigInt64Array,(t,e,r)=>_t(e,79,75,t,r)),ee.registerDecoder(81,t=>Le(t,Float32Array,!1),"IEEE 754 binary32, big endian, Typed Array"),ee.registerDecoder(82,t=>Le(t,Float64Array,!1),"IEEE 754 binary64, big endian, Typed Array"),ee.registerDecoder(85,t=>Le(t,Float32Array,!0),"IEEE 754 binary32, little endian, Typed Array"),_e(Float32Array,(t,e,r)=>_t(e,85,81,t,r)),ee.registerDecoder(86,t=>Le(t,Float64Array,!0),"IEEE 754 binary64, big endian, Typed Array"),_e(Float64Array,(t,e,r)=>_t(e,86,82,t,r)),ee.registerDecoder(oe.SET,(t,e)=>{if(Ts(t.contents),e.sortKeys){const r=Ce.decodeToEncodeOpts(e);let n=null;for(const s of t.contents){const i=[s,void 0,zt(s,r)];if(n&&e.sortKeys(n,i)>=0)throw new Error(`Set items out of order in tag #${oe.SET}`);n=i}}return new Set(t.contents)},"Set"),_e(Set,(t,e,r)=>{let n=[...t];if(r.sortKeys){const s=n.map(i=>[i,void 0,zt(i,r)]);s.sort(r.sortKeys),n=s.map(([i])=>i)}return[oe.SET,n]}),ee.registerDecoder(oe.JSON,t=>(St(t.contents),JSON.parse(t.contents)),"JSON-encoded");function Is(t){return yt(t.contents),new kr().decode(t.contents)}Is.comment=t=>{yt(t.contents);const e=new kr;return`(WTF8 string): ${JSON.stringify(e.decode(t.contents))}`},ee.registerDecoder(oe.WTF8,Is),ee.registerDecoder(oe.SELF_DESCRIBED,t=>t.contents,"Self-Described"),ee.registerDecoder(oe.INVALID_16,()=>{throw new Error(`Tag always invalid: ${oe.INVALID_16}`)},"Invalid"),ee.registerDecoder(oe.INVALID_32,()=>{throw new Error(`Tag always invalid: ${oe.INVALID_32}`)},"Invalid"),ee.registerDecoder(oe.INVALID_64,()=>{throw new Error(`Tag always invalid: ${oe.INVALID_64}`)},"Invalid");function Ln(t){throw new Error(`Encoding ${t.constructor.name} intentionally unimplmented. It is not concrete enough to interoperate. Convert to Uint8Array first.`)}_e(ArrayBuffer,Ln),_e(DataView,Ln),typeof SharedArrayBuffer<"u"&&_e(SharedArrayBuffer,Ln);function Or(t){return[NaN,t.valueOf()]}_e(Boolean,Or),_e(Number,Or),_e(String,Or),_e(BigInt,Or);function Va(t){const e={...Ce.defaultDecodeOptions};if(t.dcbor?Object.assign(e,Ce.dcborDecodeOptions):t.cde&&Object.assign(e,Ce.cdeDecodeOptions),Object.assign(e,t),Object.hasOwn(e,"rejectLongNumbers"))throw new TypeError("rejectLongNumbers has changed to requirePreferred");return e.boxed&&(e.saveOriginal=!0),e}let Ya=class{parent=void 0;ret=void 0;step(e,r,n){if(this.ret=Ce.create(e,this.parent,r,n),e[2]===Ue.BREAK)if(this.parent?.isStreaming)this.parent.left=0;else throw new Error("Unexpected BREAK");else this.parent&&this.parent.push(this.ret,n,e[3]);for(this.ret instanceof Ce&&(this.parent=this.ret);this.parent?.done;){this.ret=this.parent.convert(n);const s=this.parent.parent;s?.replaceLast(this.ret,this.parent,n),this.parent=s}}};function Qa(t,e={}){const r=Va(e),n=new Lr(t,r),s=new Ya;for(const i of n)s.step(i,r,n);return s.ret}const{cdeDecodeOptions:Uc,dcborDecodeOptions:Lc,defaultDecodeOptions:Mc}=Ce;class Xa{constructor(e={}){this.options={id:Xt(),codec:"cbor",timeout:10*1e3,chunkSize:16*1024,chunkCredit:4,topicMake:(r,n,s)=>`${r}/${n}/${s??"any"}`,topicMatch:r=>{const n=r.match(/^(.+)\/([^/]+)\/([^/]+)$/);return n?{name:n[1],operation:n[2],peerId:n[3]==="any"?void 0:n[3]}:null},...e}}}class Mn{static uint8ArrayToBase64(e){return It.from(e.buffer,e.byteOffset,e.byteLength).toString("base64")}static base64ToUint8Array(e){return new Uint8Array(It.from(e,"base64"))}static stringify(e){return JSON.stringify(e,(r,n)=>n instanceof Uint8Array?{__Uint8Array:this.uint8ArrayToBase64(n)}:n)}static parse(e){return JSON.parse(e,(r,n)=>typeof n?.__Uint8Array=="string"?this.base64ToUint8Array(n.__Uint8Array):n)}}class Za{constructor(e){this.format=e,this.types=new Qi,this.tags=new Map;const r=64e3;this.types.registerEncoder(It,n=>[r,new Uint8Array(n.buffer,n.byteOffset,n.byteLength)]),this.tags.set(r,n=>It.from(n.contents))}encode(e){let r;if(this.format==="cbor")try{r=zt(e,{types:this.types})}catch(n){throw new Error("failed to encode CBOR format",{cause:n})}else if(this.format==="json")try{r=Mn.stringify(e)}catch(n){throw new Error("failed to encode JSON format",{cause:n})}else throw new Error(`invalid format "${this.format}"`);return r}decode(e){let r;if(this.format==="cbor"){if(!(e instanceof Uint8Array))throw new Error("failed to decode CBOR format (data type is not Uint8Array)");try{r=Qa(e,{tags:this.tags})}catch(n){throw new Error("failed to decode CBOR format",{cause:n})}}else if(this.format==="json"){if(typeof e!="string")throw new Error("failed to decode JSON format (data type is not string)");try{r=Mn.parse(e)}catch(n){throw new Error("failed to decode JSON format",{cause:n})}}else throw new Error(`invalid format "${this.format}"`);return r}}class ec extends Xa{constructor(e={}){super(e),this.codec=new Za(this.options.codec)}}class tc extends ec{str2buf(e){return new TextEncoder().encode(e)}buf2str(e){return new TextDecoder().decode(e)}arr2buf(e){let r;return e instanceof Uint8Array?r=e:r=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),r}buf2arr(e,r){let n;const s=r;if(s===It)n=It.from(e.buffer,e.byteOffset,e.byteLength);else if(s===Uint8Array)n=e;else if(s===Int8Array)n=new Int8Array(e.buffer,e.byteOffset,e.byteLength);else throw new Error("invalid data type");return n}}const Bs=t=>{const e=t.match(/^(\d+)\.(\d+)$/);if(e===null)throw new Error("invalid version string");const r=parseInt(e[2],10);if(r>99)throw new Error("invalid version string: minor version exceeds 99");return parseInt(e[1],10)+r/100},Pn="1.4",rc=Bs(Pn),Vt=We(Ji(be(),Ft()),Wi(t=>!Array.isArray(t))),Yt=We(Jt(We(be(),kt(8192))),kt(8));class Ve{constructor(e,r,n,s){this.type=e,this.id=r,this.sender=n,this.receiver=s,this.version=`MQTT+/${Pn}`}}const Ye={version:We(be(),Hi(/^MQTT\+\/\d+\.\d+$/)),type:be(),id:be(),sender:ce(be()),receiver:ce(be())};class Ns extends Ve{constructor(e,r,n,s,i,c,l){super("event-emission",e,s,i),this.name=r,this.params=n,this.auth=c,this.meta=l}}const nc=Ke({...Ye,type:je("event-emission"),name:be(),params:ce(We(Jt(Ft()),kt(64))),auth:ce(Yt),meta:ce(Vt)});class ks extends Ve{constructor(e,r,n,s,i,c,l){super("service-call-request",e,s,i),this.name=r,this.params=n,this.auth=c,this.meta=l}}const ic=Ke({...Ye,type:je("service-call-request"),name:be(),params:ce(We(Jt(Ft()),kt(64))),auth:ce(Yt),meta:ce(Vt)});class Fs extends Ve{constructor(e,r,n,s,i){super("service-call-response",e,s,i),this.result=r,this.error=n}}const sc=Ke({...Ye,type:je("service-call-response"),result:ce(Ft()),error:ce(be())});class Us extends Ve{constructor(e,r,n,s,i,c,l){super("sink-push-request",e,s,i),this.name=r,this.params=n,this.auth=c,this.meta=l}}const oc=Ke({...Ye,type:je("sink-push-request"),name:be(),params:ce(We(Jt(Ft()),kt(64))),auth:ce(Yt),meta:ce(Vt)});class Ls extends Ve{constructor(e,r,n,s,i,c,l,h){super("sink-push-response",e,s,i),this.name=r,this.error=n,this.auth=c,this.meta=l,this.credit=h}}const ac=Ke({...Ye,type:je("sink-push-response"),name:be(),error:ce(be()),auth:ce(Yt),meta:ce(Vt),credit:ce(We(ir(),rr(),nr(1)))});class Ms extends Ve{constructor(e,r,n,s,i,c,l){super("sink-push-chunk",e,c,l),this.name=r,this.chunk=n,this.error=s,this.final=i}}const cc=Ke({...Ye,type:je("sink-push-chunk"),name:be(),chunk:ce(Sn(Uint8Array)),error:ce(be()),final:ce(En())});class Ps extends Ve{constructor(e,r,n,s,i){super("sink-push-credit",e,s,i),this.name=r,this.credit=n}}const uc=Ke({...Ye,type:je("sink-push-credit"),name:be(),credit:We(ir(),rr(),nr(1))});class Ds extends Ve{constructor(e,r,n,s,i,c,l,h){super("source-fetch-request",e,s,i),this.name=r,this.params=n,this.auth=c,this.meta=l,this.credit=h}}const fc=Ke({...Ye,type:je("source-fetch-request"),name:be(),params:ce(We(Jt(Ft()),kt(64))),auth:ce(Yt),meta:ce(Vt),credit:ce(We(ir(),rr(),nr(1)))});class Os extends Ve{constructor(e,r,n,s,i,c,l){super("source-fetch-response",e,s,i),this.name=r,this.error=n,this.auth=c,this.meta=l}}const lc=Ke({...Ye,type:je("source-fetch-response"),name:be(),error:ce(be()),auth:ce(Yt),meta:ce(Vt)});class Cs extends Ve{constructor(e,r,n,s,i,c,l){super("source-fetch-chunk",e,c,l),this.name=r,this.chunk=n,this.error=s,this.final=i}}const hc=Ke({...Ye,type:je("source-fetch-chunk"),name:be(),chunk:ce(Sn(Uint8Array)),error:ce(be()),final:ce(En())});class $s extends Ve{constructor(e,r,n,s,i){super("source-fetch-credit",e,s,i),this.name=r,this.credit=n}}const dc=Ke({...Ye,type:je("source-fetch-credit"),name:be(),credit:We(ir(),rr(),nr(1))});class pc{makeEventEmission(e,r,n,s,i,c,l){return new Ns(e,r,n,s,i,c,l)}makeServiceCallRequest(e,r,n,s,i,c,l){return new ks(e,r,n,s,i,c,l)}makeServiceCallResponse(e,r,n,s,i){return new Fs(e,r,n,s,i)}makeSinkPushRequest(e,r,n,s,i,c,l){return new Us(e,r,n,s,i,c,l)}makeSinkPushResponse(e,r,n,s,i,c,l,h){return new Ls(e,r,n,s,i,c,l,h)}makeSinkPushChunk(e,r,n,s,i,c,l){return new Ms(e,r,n,s,i,c,l)}makeSinkPushCredit(e,r,n,s,i){return new Ps(e,r,n,s,i)}makeSourceFetchRequest(e,r,n,s,i,c,l,h){return new Ds(e,r,n,s,i,c,l,h)}makeSourceFetchResponse(e,r,n,s,i,c,l){return new Os(e,r,n,s,i,c,l)}makeSourceFetchChunk(e,r,n,s,i,c,l){return new Cs(e,r,n,s,i,c,l)}makeSourceFetchCredit(e,r,n,s,i){return new $s(e,r,n,s,i)}parse(e){if(typeof e!="object"||e===null)throw new Error("invalid argument: not an object");if(typeof e.version!="string")throw new Error('invalid object: missing or invalid "version" field');const r=e.version.match(/^MQTT\+\/(\d+\.\d+)$/);if((r!==null?Bs(r[1]):0)!==rc)throw new Error(`protocol version mismatch (expected version ${Pn}, got version ${e.version})`);const s=(i,c,l)=>{const h=ia(l,i);if(!h.success){const w=h.issues.map(d=>d.message).join("; ");throw new Error(`invalid ${c} object: ${w}`)}return h.output};if(typeof e.type!="string")throw new Error('invalid object: missing or invalid "type" field');if(e.type==="event-emission"){const i=s(e,"EventEmission",nc);return this.makeEventEmission(i.id,i.name,i.params,i.sender,i.receiver,i.auth,i.meta)}else if(e.type==="service-call-request"){const i=s(e,"ServiceCallRequest",ic);return this.makeServiceCallRequest(i.id,i.name,i.params,i.sender,i.receiver,i.auth,i.meta)}else if(e.type==="service-call-response"){const i=s(e,"ServiceCallResponse",sc);return this.makeServiceCallResponse(i.id,i.result,i.error,i.sender,i.receiver)}else if(e.type==="sink-push-request"){const i=s(e,"SinkPushRequest",oc);return this.makeSinkPushRequest(i.id,i.name,i.params,i.sender,i.receiver,i.auth,i.meta)}else if(e.type==="sink-push-response"){const i=s(e,"SinkPushResponse",ac);return this.makeSinkPushResponse(i.id,i.name,i.error,i.sender,i.receiver,i.auth,i.meta,i.credit)}else if(e.type==="sink-push-chunk"){const i=s(e,"SinkPushChunk",cc);return this.makeSinkPushChunk(i.id,i.name,i.chunk,i.error,i.final,i.sender,i.receiver)}else if(e.type==="sink-push-credit"){const i=s(e,"SinkPushCredit",uc);return this.makeSinkPushCredit(i.id,i.name,i.credit,i.sender,i.receiver)}else if(e.type==="source-fetch-request"){const i=s(e,"SourceFetchRequest",fc);return this.makeSourceFetchRequest(i.id,i.name,i.params,i.sender,i.receiver,i.auth,i.meta,i.credit)}else if(e.type==="source-fetch-response"){const i=s(e,"SourceFetchResponse",lc);return this.makeSourceFetchResponse(i.id,i.name,i.error,i.sender,i.receiver,i.auth,i.meta)}else if(e.type==="source-fetch-chunk"){const i=s(e,"SourceFetchChunk",hc);return this.makeSourceFetchChunk(i.id,i.name,i.chunk,i.error,i.final,i.sender,i.receiver)}else if(e.type==="source-fetch-credit"){const i=s(e,"SourceFetchCredit",dc);return this.makeSourceFetchCredit(i.id,i.name,i.credit,i.sender,i.receiver)}else throw new Error("invalid object: not of any known type")}isRequest(e){return e instanceof Ns||e instanceof ks||e instanceof Ds||e instanceof Us}isResponse(e){return e instanceof Fs||e instanceof Ls||e instanceof Ms||e instanceof Ps||e instanceof Os||e instanceof Cs||e instanceof $s}}class yc extends tc{constructor(){super(...arguments),this.msg=new pc}}class wc{constructor(e,r,n,s){this.timestamp=e,this.level=r,this.msg=n,this.data=s}async resolve(){if(this.msg instanceof Promise&&(this.msg=await this.msg.catch(()=>"<resolve-failed>")),this.data)for(const e of Object.keys(this.data))this.data[e]instanceof Promise&&(this.data[e]=await this.data[e].catch(()=>"<resolve-failed>"))}toString(){const e=new Date(this.timestamp),r=e.getFullYear(),n=(e.getMonth()+1).toString().padStart(2,"0"),s=e.getDate().toString().padStart(2,"0"),i=e.getHours().toString().padStart(2,"0"),c=e.getMinutes().toString().padStart(2,"0"),l=e.getSeconds().toString().padStart(2,"0"),h=e.getMilliseconds().toString().padStart(3,"0"),w=`${r}-${n}-${s} ${i}:${c}:${l}.${h}`,d=this.msg instanceof Promise?"<unresolved>":this.msg;let I="";if(this.data!==void 0){const v=this.data;I=` (${Object.keys(v).map(U=>{const $=v[U]instanceof Promise?"<unresolved>":v[U];return`${U}: ${Mn.stringify($)}`}).join(", ")})`}return`[${w}] ${this.level}: ${d}${I}`}}class gc extends yc{constructor(){super(...arguments),this._events=new Vo.EventEmitter}on(...e){this._events.on(...e)}off(...e){this._events.off(...e)}emitEvent(...e){return this._events.listenerCount(e[0])===0?!1:this._events.emit(...e)}log(e,r,n){const s=new wc(Date.now(),e,r,n);this.emitEvent("log",s)}error(e,r){let n=e;r!==void 0&&(n=new Error(`${r}: ${e.message}`,{cause:e})),this.emitEvent("error",n),this.log("error",n.message)}}class mc extends gc{constructor(e,r={}){super(r),this.onRequest=new Map,this.onResponse=new Map,e===null&&(this.log("info","establishing proxy MQTT client"),e=new Proxy({},{get(n,s,i){return s==="isFakeProxy"?!0:typeof s=="string"&&["on","off","once"].includes(s)?()=>{}:()=>{throw new Error(`Underlying MQTT operation "${String(s)}" called on a null MQTT client -- only MQTT+ "emit({ ..., dry: true })" is supported in this special operation mode`)}}})),this.mqtt=e,this.log("info","hooking into MQTT client"),this._messageHandler=(n,s,i)=>{let c;if(this.options.codec==="json")c=s.toString();else if(this.options.codec==="cbor")c=mi.isBuffer(s)?new Uint8Array(s.buffer,s.byteOffset,s.byteLength):s;else throw new Error("invalid codec configured");this._onMessage(n,c,i)},this.mqtt.on("message",this._messageHandler)}async destroy(){this.log("info","un-hooking from MQTT client"),this.mqtt.off("message",this._messageHandler)}async _subscribeTopic(e,r={}){return this.log("info",`subscribing to MQTT topic "${e}"`),new Promise((n,s)=>{this.mqtt.subscribe(e,{qos:2,...r},(i,c)=>{i?(this.error(i,`subscribing to MQTT topic "${e}" failed`),s(i)):n()})})}async _unsubscribeTopic(e){return this.log("info",`unsubscribing from MQTT topic "${e}"`),new Promise((r,n)=>{this.mqtt.unsubscribe(e,(s,i)=>{s?(this.error(s,`unsubscribing from MQTT topic "${e}" failed`),n(s)):r()})})}async _publishToTopic(e,r,n={}){typeof r=="string"?this.log("info",`publishing to MQTT topic "${e}" (type: string, length: ${r.length} chars)`):this.log("info",`publishing to MQTT topic "${e}" (type: buffer, length: ${r.byteLength} bytes)`);const s=new qt((i,c)=>{let l;try{const h=this.codec.decode(r);l=this.msg.parse(h)}catch(h){return c(h)}i(l)});return this.log("debug",`publishing to MQTT topic "${e}"`,{message:s}),new Promise((i,c)=>{const l=typeof r=="string"?r:mi.from(r.buffer,r.byteOffset,r.byteLength);this.mqtt.publish(e,l,n,h=>{h?(this.error(h,`publishing to MQTT topic "${e}" failed`),c(h)):i()})})}_onMessage(e,r,n){const s=this.options.topicMatch(e);if(s===null)return;typeof r=="string"?this.log("info",`received from MQTT topic "${e}" (type: string, length: ${r.length} chars)`):this.log("info",`received from MQTT topic "${e}" (type: buffer, length: ${r.byteLength} bytes)`);let i;try{i=this.codec.decode(r)}catch(l){this.error(qe(l,"failed to parse message into object"));return}let c;try{c=this.msg.parse(i)}catch(l){this.error(qe(l,"failed to parse object into typed message object"));return}if(this.log("debug",`received from MQTT topic "${e}"`,{message:c}),this.msg.isRequest(c)){const l=this.onRequest.get(`${s.operation}:${c.name}`);if(l!==void 0)try{l(c,s.name)}catch(h){this.error(qe(h,`dispatching request message from MQTT topic "${e}" failed`))}}else if(this.msg.isResponse(c)){const l=this.onResponse.get(`${s.operation}:${c.id}`);if(l!==void 0)try{l(c,s.name)}catch(h){this.error(qe(h,`dispatching response message from MQTT topic "${e}" failed`))}}}}class bc{constructor(e,r,n=30*1e3){this.subscribeFn=e,this.unsubscribeFn=r,this.lingerMs=n,this.counts=new Map,this.pending=new Map,this.lingers=new Map}async subscribe(e,r={qos:2}){const n=this.counts.get(e)??0;this.counts.set(e,n+1);const s=this.lingers.get(e);if(s){clearTimeout(s),this.lingers.delete(e);return}if(n===0){const i=this.subscribeFn(e,r).finally(()=>{this.pending.delete(e)}).catch(c=>{const l=this.counts.get(e);throw l&&(l<=1?this.counts.delete(e):this.counts.set(e,l-1)),c});return this.pending.set(e,i),i}else{const i=this.pending.get(e);if(i)return i.catch(c=>{const l=this.counts.get(e);throw l&&(l<=1?this.counts.delete(e):this.counts.set(e,l-1)),c})}}async unsubscribe(e){const r=this.counts.get(e);if(r)if(r<=1)if(this.counts.delete(e),this.lingerMs>0){const n=setTimeout(()=>{this.lingers.delete(e),this.unsubscribeFn(e).catch(()=>{})},this.lingerMs);this.lingers.set(e,n)}else await this.unsubscribeFn(e).catch(()=>{});else this.counts.set(e,r-1)}async flush(){const e=[...this.lingers.keys()];for(const r of e)clearTimeout(this.lingers.get(r)),this.lingers.delete(r);for(const r of e)await this.unsubscribeFn(r).catch(()=>{})}}class Ec extends mc{constructor(){super(...arguments),this.subscriptions=new bc((e,r)=>this._subscribeTopic(e,r),e=>this._unsubscribeTopic(e))}async destroy(){await this.subscriptions.flush(),await super.destroy()}}class Sc extends Ec{constructor(){super(...arguments),this.timers=new Map}async destroy(){for(const e of this.timers.values())clearTimeout(e);this.timers.clear(),await super.destroy()}timerRefresh(e,r){const n=this.timers.get(e);n!==void 0&&clearTimeout(n),this.timers.set(e,setTimeout(()=>{this.timers.delete(e),r()},this.options.timeout))}timerClear(e){const r=this.timers.get(e);r!==void 0&&(clearTimeout(r),this.timers.delete(e))}}class _c extends Sc{constructor(){super(...arguments),this._meta=new Map}meta(e,r){if(e===void 0)return Object.fromEntries(this._meta);if(arguments.length===1)return this._meta.get(e);r==null?this._meta.delete(e):this._meta.set(e,r)}metaStore(e){const r=e===void 0||Object.keys(e).length===0;if(!(this._meta.size===0&&r))return this._meta.size>0&&r?Object.fromEntries(this._meta):this._meta.size===0&&!r?e:{...Object.fromEntries(this._meta),...e}}}class Tc extends _c{constructor(){super(...arguments),this._credential=null,this._tokens=new Set}credential(e){if(e.length===0)throw new Error("credential must not be empty");const r=new TextEncoder().encode(e),n=new TextEncoder().encode("mqtt-plus");this._credential=Wo(Jo,r,n,6e5,32)}async issue(e){if(this._credential===null)throw new Error("credential has to be provided before issuing tokens");const r=new Do(e);return r.setProtectedHeader({alg:"HS256",typ:"JWT"}),await r.sign(this._credential)}authenticate(e,r){if(e===void 0)return this._tokens.size>0?Array.from(this._tokens):void 0;r===!0?this._tokens.delete(e):this._tokens.add(e)}async validateToken(e){if(this._credential===null)throw new Error("credential has to be provided before validating tokens");return(await qo(e,this._credential).catch(()=>null))?.payload??null}async authenticated(e,r,n){let s=!1,i,c;if(typeof n=="string"?(i="require",c=[n]):(i=n.mode,c=n.roles),r!==void 0)for(const l of r.slice(0,8)){if(l.length>8192)continue;const h=await this.validateToken(l);if(h!==null&&!(h.id&&h.id!==e)&&Array.isArray(h.roles)&&!(h.roles.length>64)){for(const w of c)if(h.roles.includes(w)){s=!0;break}if(s)break}}return!s&&i==="optional"&&(s=!0),s}}class vc extends Tc{async event(e,...r){let n,s,i={},c,l;typeof e=="object"&&e!==null?(n=e.name,s=e.callback,i=e.options??{},c=e.share,l=e.auth):(n=e,s=r[0]);const h=new De;if(this.onRequest.has(`event-emission:${n}`))throw new Error(`event: event "${n}" already registered`);const w=c?`$share/${c}/${n}`:n,d=this.options.topicMake(w,"event-emission"),I=this.options.topicMake(n,"event-emission",this.options.id);return this.onRequest.set(`event-emission:${n}`,(v,k)=>{const U=v.sender,$=v.params??[],q={sender:U??""};v.receiver&&(q.receiver=v.receiver),v.meta&&(q.meta=v.meta),Promise.resolve().then(async()=>{if(k!==n)throw new Error(`event name mismatch (topic: "${k}", payload: "${n}")`);if(l&&(q.authenticated=await this.authenticated(v.sender,v.auth,l)),q.authenticated!==void 0&&!q.authenticated)throw new Error(`authentication on event "${n}" failed`);return s(...$,q)}).catch(_=>{const A=qe(_);this.error(A,`handler for event "${n}" failed`)})}),h.roll(()=>{this.onRequest.delete(`event-emission:${n}`)}),await Ne(`subscribe to MQTT topic "${d}"`,h,()=>this._subscribeTopic(d,{qos:2,...i})),h.roll(()=>this._unsubscribeTopic(d).catch(()=>{})),await Ne(`subscribe to MQTT topic "${I}"`,h,()=>this._subscribeTopic(I,{qos:2,...i})),h.roll(()=>this._unsubscribeTopic(I).catch(()=>{})),{destroy:async()=>{if(!this.onRequest.has(`event-emission:${n}`))throw new Error(`destroy: event "${n}" not registered`);await h.unroll(!1)?.catch(v=>{this.error(v,`destroy: failed to cleanup: ${v.message}`)})}}}emit(e,...r){let n,s,i,c={},l,h;typeof e=="object"&&e!==null?(n=e.event,s=e.params,i=e.receiver,c=e.options??{},l=e.meta,h=e.dry):(n=e,s=r);const w=Xt(),d=this.authenticate(),I=this.metaStore(l),v=this.msg.makeEventEmission(w,n,s,this.options.id,i,d,I),k=this.codec.encode(v),U=this.options.topicMake(n,"event-emission",i);if(h)return{topic:U,payload:k,options:{qos:0,...c}};this._publishToTopic(U,k,{qos:0,...c}).catch($=>{this.error($,`emitting event "${n}" failed`)})}}class xc extends vc{async service(e,...r){let n,s,i={},c="default",l;typeof e=="object"&&e!==null?(n=e.name,s=e.callback,i=e.options??{},c=e.share??"default",l=e.auth):(n=e,s=r[0]);const h=new De;if(this.onRequest.has(`service-call-request:${n}`))throw new Error(`service: service "${n}" already registered`);const w=`$share/${c}/${n}`,d=this.options.topicMake(w,"service-call-request"),I=this.options.topicMake(n,"service-call-request",this.options.id);return this.onRequest.set(`service-call-request:${n}`,(v,k)=>{const U=v.id,$=v.sender;if($===void 0||$==="")throw new Error("invalid request: missing sender");const q=v.params??[],_={sender:$};v.receiver&&(_.receiver=v.receiver),v.meta&&(_.meta=v.meta),Promise.resolve().then(async()=>{if(k!==n)throw new Error(`service name mismatch (topic: "${k}", payload: "${n}")`);if(l&&(_.authenticated=await this.authenticated($,v.auth,l)),_.authenticated!==void 0&&!_.authenticated)throw new Error(`service "${n}" failed authentication`);return s(...q,_)}).then(A=>this.msg.makeServiceCallResponse(U,A,void 0,this.options.id,$),A=>{const R=qe(A);return this.error(R,`handler for service "${n}" failed`),this.msg.makeServiceCallResponse(U,void 0,R.message,this.options.id,$)}).then(A=>{const R=this.codec.encode(A),S=this.options.topicMake(n,"service-call-response",$);return this._publishToTopic(S,R,{qos:2})}).catch(A=>{this.error(A,`handler for service "${n}" failed`)})}),h.roll(()=>{this.onRequest.delete(`service-call-request:${n}`)}),await Ne(`subscribe to MQTT topic "${d}"`,h,()=>this._subscribeTopic(d,{qos:2,...i})),h.roll(()=>this._unsubscribeTopic(d).catch(()=>{})),await Ne(`subscribe to MQTT topic "${I}"`,h,()=>this._subscribeTopic(I,{qos:2,...i})),h.roll(()=>this._unsubscribeTopic(I).catch(()=>{})),{destroy:async()=>{if(!this.onRequest.has(`service-call-request:${n}`))throw new Error(`destroy: service "${n}" not registered`);await h.unroll(!1)?.catch(v=>{this.error(v,`destroy: failed to cleanup: ${v.message}`)})}}}async call(e,...r){let n,s,i,c={},l;typeof e=="object"&&e!==null?(n=e.name,s=e.params,i=e.receiver,c=e.options??{},l=e.meta):(n=e,s=r);const h=new De,w=Xt(),d=this.options.topicMake(n,"service-call-response",this.options.id);await Ne(`subscribe to MQTT topic "${d}"`,h,()=>this.subscriptions.subscribe(d,{qos:c.qos??2})),h.roll(()=>this.subscriptions.unsubscribe(d));const I=new Promise((_,A)=>{let R=setTimeout(async()=>{R=null,await h.unroll(),A(new Error("communication timeout"))},this.options.timeout);h.roll(()=>{R!==null&&(clearTimeout(R),R=null)}),this.onResponse.set(`service-call-response:${w}`,async S=>{await h.unroll(),S.error!==void 0?A(new Error(S.error)):_(S.result)}),h.roll(()=>{this.onResponse.delete(`service-call-response:${w}`)})}),v=this.authenticate(),k=this.metaStore(l),U=this.msg.makeServiceCallRequest(w,n,s,this.options.id,i,v,k),$=this.codec.encode(U),q=this.options.topicMake(n,"service-call-request",i);return await Ne(`publish service request as MQTT message to topic "${q}"`,h,()=>this._publishToTopic(q,$,{qos:2,...c})),I}}class Ac extends xc{constructor(){super(...arguments),this.sourceCreditGates=new Map}async source(e,...r){let n,s,i={},c="default",l;typeof e=="object"&&e!==null?(n=e.name,s=e.callback,i=e.options??{},c=e.share??"default",l=e.auth):(n=e,s=r[0]);const h=new De;if(this.onRequest.has(`source-fetch-request:${n}`))throw new Error(`source: source "${n}" already established`);const w=`$share/${c}/${n}`,d=this.options.topicMake(w,"source-fetch-request"),I=this.options.topicMake(n,"source-fetch-request",this.options.id),v=this.options.topicMake(n,"source-fetch-credit",this.options.id);return this.onRequest.set(`source-fetch-request:${n}`,(k,U)=>{const $=k.id,q=k.params??[],_=k.sender;if(_===void 0||_==="")throw new Error("invalid request: missing sender");const A=k.receiver,R={sender:_};A&&(R.receiver=A),k.meta&&(R.meta=k.meta);const S=this.options.topicMake(n,"source-fetch-response",_),T=this.options.topicMake(n,"source-fetch-chunk",_),F=async V=>{const ie=this.authenticate(),fe=this.metaStore(R.meta),Re=this.msg.makeSourceFetchResponse($,n,V,this.options.id,_,ie,fe),Te=this.codec.encode(Re);await this._publishToTopic(S,Te,{qos:2})},M=()=>this.timerRefresh($,()=>{const V=this.sourceCreditGates.get($);V!==void 0&&V.abort()}),L=()=>this.timerClear($);M();const W=async(V,ie,fe)=>{M();const Re=this.msg.makeSourceFetchChunk($,n,V,ie,fe,this.options.id,_),Te=this.codec.encode(Re);await this._publishToTopic(T,Te,{qos:2})},J=k.credit,Q=J!==void 0&&J>0?new bi(J):void 0;Q&&(this.sourceCreditGates.set($,Q),this.onResponse.set(`source-fetch-credit:${$}`,V=>{Q.replenish(V.credit),M()}));let N=!1;Promise.resolve().then(async()=>{if(U!==k.name)throw new Error(`source name mismatch between topic "${U}" and payload "${k.name}"`);if(l&&(R.authenticated=await this.authenticated(k.sender,k.auth,l)),R.authenticated!==void 0&&!R.authenticated)throw new Error(`source "${n}" failed authentication`);return s(...q,R)}).then(async()=>{if(!(R.stream instanceof Ct.Readable)&&!(R.buffer instanceof Promise))throw new Error("handler did not provide data via info.stream or info.buffer fields");if(R.stream instanceof Ct.Readable&&R.buffer instanceof Promise)throw new Error("handler has set both info.stream and info.buffer fields");await F(),N=!0,R.stream instanceof Ct.Readable?await Ti(R.stream,this.options.chunkSize,W,Q):R.buffer instanceof Promise&&await _i(await R.buffer,this.options.chunkSize,W,Q)}).catch(V=>{const ie=qe(V);return this.error(ie,`handler for source "${n}" failed`),N?W(void 0,ie.message,!0).catch(()=>{}):F(ie.message).catch(()=>{})}).finally(()=>{L(),Q&&(Q.abort(),this.sourceCreditGates.delete($)),this.onResponse.delete(`source-fetch-credit:${$}`)})}),h.roll(()=>{this.onRequest.delete(`source-fetch-request:${n}`)}),await Ne(`subscribe to MQTT topic "${d}"`,h,()=>this._subscribeTopic(d,{qos:2,...i})),h.roll(()=>this._unsubscribeTopic(d).catch(()=>{})),await Ne(`subscribe to MQTT topic "${I}"`,h,()=>this._subscribeTopic(I,{qos:2,...i})),h.roll(()=>this._unsubscribeTopic(I).catch(()=>{})),await Ne(`subscribe to MQTT topic "${v}"`,h,()=>this._subscribeTopic(v,{qos:2,...i})),h.roll(()=>this._unsubscribeTopic(v).catch(()=>{})),{destroy:async()=>{if(!this.onRequest.has(`source-fetch-request:${n}`))throw new Error(`destroy: source "${n}" not established`);await h.unroll(!1)?.catch(k=>{this.error(k,`destroy: failed to cleanup: ${k.message}`)})}}}async fetch(e,...r){let n,s,i,c={},l;typeof e=="object"&&e!==null?(n=e.name,s=e.params,i=e.receiver,c=e.options??{},l=e.meta):(n=e,s=r);const h=new De,w=Xt(),d=this.options.topicMake(n,"source-fetch-response",this.options.id),I=this.options.topicMake(n,"source-fetch-chunk",this.options.id);await Ne(`subscribe to MQTT topic "${d}"`,h,()=>this.subscriptions.subscribe(d,{qos:c.qos??2})),h.roll(()=>this.subscriptions.unsubscribe(d)),await Ne(`subscribe to MQTT topic "${I}"`,h,()=>this.subscriptions.subscribe(I,{qos:c.qos??2})),h.roll(()=>this.subscriptions.unsubscribe(I));const v=this.options.chunkCredit;let k=0,U=v,$;const q=new Ct.Readable({highWaterMark:v>0?v*this.options.chunkSize:16*1024,read:V=>{if(v<=0||!this.onResponse.has(`source-fetch-chunk:${w}`))return;const ie=$??i;if(!ie)return;const fe=Math.max(0,k+v-U);if(fe>0){U+=fe;const Re=this.msg.makeSourceFetchCredit(w,n,fe,this.options.id,ie),Te=this.codec.encode(Re),Pe=this.options.topicMake(n,"source-fetch-credit",ie);this._publishToTopic(Pe,Te,{qos:2}).catch(Ge=>{this.error(Ge,`sending credit for fetch "${n}" failed`)})}}}),_=Si(q);let A;const R=new Promise(V=>{A=V});h.roll(()=>{A?.(void 0)});let S=null;h.roll(()=>{S!==null&&(clearTimeout(S),S=null)});const T=()=>{S!==null&&clearTimeout(S),S=setTimeout(()=>{q.destroy(new Error("communication timeout")),h.unroll()},this.options.timeout)};T(),q.once("close",()=>h.unroll()),q.once("error",()=>h.unroll()),this.onResponse.set(`source-fetch-response:${w}`,V=>{V.sender&&($=V.sender),A?.(V.meta),V.error?(q.destroy(new Error(V.error)),h.unroll()):T()}),this.onResponse.set(`source-fetch-chunk:${w}`,V=>{V.sender&&($=V.sender),V.error?(q.destroy(new Error(V.error)),h.unroll()):(T(),V.chunk!==void 0&&(k++,q.push(V.chunk)),V.final&&(q.push(null),h.unroll()))}),h.roll(()=>{this.onResponse.delete(`source-fetch-response:${w}`),this.onResponse.delete(`source-fetch-chunk:${w}`)});const F=this.authenticate(),M=this.metaStore(l),L=v>0?v:void 0,W=this.msg.makeSourceFetchRequest(w,n,s,this.options.id,i,F,M,L),J=this.codec.encode(W),Q=this.options.topicMake(n,"source-fetch-request",i);Ne(`publish fetch request as MQTT message to topic "${Q}"`,h,()=>this._publishToTopic(Q,J,{qos:2,...c})).catch(V=>{q.destroy(qe(V)),h.unroll()});const N={stream:q,buffer:_,meta:R};return vi(N,"stream","buffer"),N}}class Rc extends Ac{constructor(){super(...arguments),this.pushStreams=new Map,this.pushSpools=new Map}async sink(e,...r){let n,s,i={},c="default",l;typeof e=="object"&&e!==null?(n=e.name,s=e.callback,i=e.options??{},c=e.share??"default",l=e.auth):(n=e,s=r[0]);const h=new De;if(this.onRequest.has(`sink-push-request:${n}`))throw new Error(`sink: sink "${n}" already established`);const w=`$share/${c}/${n}`,d=this.options.topicMake(w,"sink-push-request"),I=this.options.topicMake(n,"sink-push-request",this.options.id),v=this.options.topicMake(n,"sink-push-chunk",this.options.id);return this.onRequest.set(`sink-push-request:${n}`,(k,U)=>{const $=k.id,q=k.params??[],_=k.sender;if(_===void 0||_==="")throw new Error("invalid request: missing sender");const A=k.receiver,R={sender:_};A&&(R.receiver=A),k.meta&&(R.meta=k.meta);const S=this.options.topicMake(n,"sink-push-response",_),T=this.options.chunkCredit,F=async L=>{const W=this.authenticate(),J=this.metaStore(R.meta),Q=T>0?T:void 0,N=this.msg.makeSinkPushResponse($,n,L,this.options.id,_,W,J,Q),V=this.codec.encode(N);await this._publishToTopic(S,V,{qos:2})},M=new De;this.pushSpools.set($,M),M.roll(()=>{this.pushSpools.delete($)}),Promise.resolve().then(async()=>{if(U!==k.name)throw new Error(`sink name mismatch between topic "${U}" and payload "${k.name}"`);if(l&&(R.authenticated=await this.authenticated(k.sender,k.auth,l)),R.authenticated!==void 0&&!R.authenticated)throw new Error(`sink "${n}" failed authentication`);const L=T>0?{chunksReceived:0,creditGranted:T}:void 0,W=()=>this.timerRefresh($,()=>{const V=this.pushStreams.get($);V!==void 0&&V.destroy(new Error("push stream timeout")),this.pushSpools.get($)?.unroll()}),J=()=>this.timerClear($),Q=new Ct.Readable({highWaterMark:T>0?T*this.options.chunkSize:16*1024,read:V=>{if(!L||!this.pushSpools.has($))return;const ie=Math.max(0,L.chunksReceived+T-L.creditGranted);if(ie>0){L.creditGranted+=ie;const fe=this.msg.makeSinkPushCredit($,n,ie,this.options.id,_),Re=this.codec.encode(fe),Te=this.options.topicMake(n,"sink-push-credit",_);this._publishToTopic(Te,Re,{qos:2}).catch(Pe=>{this.error(Pe,`sending credit for push "${n}" failed`)}),W()}}});this.pushStreams.set($,Q),M.roll(()=>{this.pushStreams.delete($)}),Q.once("close",()=>M.unroll()),Q.once("error",()=>M.unroll()),this.onResponse.set(`sink-push-chunk:${$}`,(V,ie)=>{if(ie!==V.name)throw new Error(`sink name mismatch between topic "${ie}" and payload "${V.name}"`);V.error!==void 0?(Q.destroy(new Error(V.error)),M.unroll()):(W(),V.chunk!==void 0&&(L&&L.chunksReceived++,Q.push(V.chunk)),V.final&&(Q.push(null),M.unroll()))}),M.roll(()=>{this.onResponse.delete(`sink-push-chunk:${$}`)}),W(),M.roll(()=>{J()});const N=Si(Q);return R.stream=Q,R.buffer=N,vi(R,"stream","buffer"),await F(),s(...q,R)}).catch(async L=>{const W=this.pushStreams.get($);W!==void 0&&W.destroy(),M.unroll(),this.error(L),await F(L.message).catch(()=>{})})}),h.roll(()=>{this.onRequest.delete(`sink-push-request:${n}`)}),await Ne(`subscribe to MQTT topic "${d}"`,h,()=>this._subscribeTopic(d,{qos:2,...i})),h.roll(()=>this._unsubscribeTopic(d).catch(()=>{})),await Ne(`subscribe to MQTT topic "${I}"`,h,()=>this._subscribeTopic(I,{qos:2,...i})),h.roll(()=>this._unsubscribeTopic(I).catch(()=>{})),await Ne(`subscribe to MQTT topic "${v}"`,h,()=>this._subscribeTopic(v,{qos:2,...i})),h.roll(()=>this._unsubscribeTopic(v).catch(()=>{})),{destroy:async()=>{if(!this.onRequest.has(`sink-push-request:${n}`))throw new Error(`destroy: sink "${n}" not established`);await h.unroll(!1)?.catch(k=>{this.error(k,`destroy: failed to cleanup: ${k.message}`)})}}}async push(e,...r){let n,s,i,c,l={},h;typeof e=="object"&&e!==null?(n=e.name,s=e.data,i=e.params,c=e.receiver,l=e.options??{},h=e.meta):(n=e,s=r[0],i=r.slice(1));const w=new De,d=Xt(),I=this.options.topicMake(n,"sink-push-response",this.options.id);await Ne(`subscribe to MQTT topic "${I}"`,w,()=>this.subscriptions.subscribe(I,{qos:l.qos??2})),w.roll(()=>this.subscriptions.unsubscribe(I));const v=new AbortController,k=v.signal;let U=null;w.roll(()=>{U!==null&&(clearTimeout(U),U=null)});const $=()=>{U!==null&&clearTimeout(U),U=setTimeout(()=>{v.abort(new Error(`push to sink "${n}" timed out`)),w.unroll()},this.options.timeout)};$();let q,_;try{if(await new Promise((S,T)=>{const F=()=>{T(k.reason)};k.addEventListener("abort",F,{once:!0}),w.roll(()=>{k.removeEventListener("abort",F)}),this.onResponse.set(`sink-push-response:${d}`,N=>{N.error?T(new Error(N.error)):(N.sender&&(c=N.sender),q=N.credit,S())}),w.roll(()=>{this.onResponse.delete(`sink-push-response:${d}`)}),this.onResponse.set(`sink-push-credit:${d}`,N=>{$()}),w.roll(()=>{this.onResponse.delete(`sink-push-credit:${d}`)});const M=this.authenticate(),L=this.metaStore(h),W=this.msg.makeSinkPushRequest(d,n,i,this.options.id,c,M,L),J=this.codec.encode(W),Q=this.options.topicMake(n,"sink-push-request",c);Ne(`publish push request as MQTT message to topic "${Q}"`,w,()=>this._publishToTopic(Q,J,{qos:2,...l})).catch(N=>{T(N)})}),this.onResponse.set(`sink-push-response:${d}`,S=>{S.error&&v.abort(new Error(S.error))}),q!==void 0&&q>0&&(_=new bi(q)),_){const S=this.options.topicMake(n,"sink-push-credit",this.options.id);await Ne(`subscribe to MQTT topic "${S}"`,w,()=>this.subscriptions.subscribe(S,{qos:2})),w.roll(()=>this.subscriptions.unsubscribe(S));const T=_;w.roll(()=>{T.abort()}),this.onResponse.set(`sink-push-credit:${d}`,F=>{T.replenish(F.credit),$()})}const A=this.options.topicMake(n,"sink-push-chunk",c),R=async(S,T,F)=>{$();const M=this.msg.makeSinkPushChunk(d,n,S,T,F,this.options.id,c),L=this.codec.encode(M);await this._publishToTopic(A,L,{qos:2,...l})};s instanceof Ct.Readable?await Ti(s,this.options.chunkSize,R,_,k):s instanceof Uint8Array&&await _i(s,this.options.chunkSize,R,_,k)}catch(A){const R=A instanceof Error?A.message:String(A),S=this.options.topicMake(n,"sink-push-chunk",c),T=this.msg.makeSinkPushChunk(d,n,void 0,R,!0,this.options.id,c),F=this.codec.encode(T);throw await this._publishToTopic(S,F,{qos:2,...l}).catch(()=>{}),A}finally{await w.unroll()}}}class Ic extends Rc{}return Ic}));