@helia/http 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +4 -0
- package/README.md +70 -0
- package/dist/index.min.js +143 -0
- package/dist/src/index.d.ts +100 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +71 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/utils/libp2p-defaults.d.ts +7 -0
- package/dist/src/utils/libp2p-defaults.d.ts.map +1 -0
- package/dist/src/utils/libp2p-defaults.js +13 -0
- package/dist/src/utils/libp2p-defaults.js.map +1 -0
- package/dist/src/utils/libp2p.d.ts +15 -0
- package/dist/src/utils/libp2p.d.ts.map +1 -0
- package/dist/src/utils/libp2p.js +13 -0
- package/dist/src/utils/libp2p.js.map +1 -0
- package/dist/typedoc-urls.json +6 -0
- package/package.json +67 -0
- package/src/index.ts +162 -0
- package/src/utils/libp2p-defaults.ts +19 -0
- package/src/utils/libp2p.ts +29 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.HeliaHttp = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
+
"use strict";var HeliaHttp=(()=>{var TR=Object.create;var Bu=Object.defineProperty;var kR=Object.getOwnPropertyDescriptor;var CR=Object.getOwnPropertyNames;var PR=Object.getPrototypeOf,DR=Object.prototype.hasOwnProperty;var re=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Y=(t,e)=>{for(var r in e)Bu(t,r,{get:e[r],enumerable:!0})},Eb=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of CR(e))!DR.call(t,i)&&i!==r&&Bu(t,i,{get:()=>e[i],enumerable:!(n=kR(e,i))||n.enumerable});return t};var me=(t,e,r)=>(r=t!=null?TR(PR(t)):{},Eb(e||!t||!t.__esModule?Bu(r,"default",{value:t,enumerable:!0}):r,t)),NR=t=>Eb(Bu({},"__esModule",{value:!0}),t);var Gb=re((wK,zb)=>{zb.exports=$b;var qb=128,EB=127,AB=~EB,SB=Math.pow(2,31);function $b(t,e,r){e=e||[],r=r||0;for(var n=r;t>=SB;)e[r++]=t&255|qb,t/=128;for(;t&AB;)e[r++]=t&255|qb,t>>>=7;return e[r]=t|0,$b.bytes=r-n+1,e}});var jb=re((xK,Yb)=>{Yb.exports=Wd;var _B=128,Wb=127;function Wd(t,n){var r=0,n=n||0,i=0,o=n,s,a=t.length;do{if(o>=a)throw Wd.bytes=0,new RangeError("Could not decode varint");s=t[o++],r+=i<28?(s&Wb)<<i:(s&Wb)*Math.pow(2,i),i+=7}while(s>=_B);return Wd.bytes=o-n,r}});var Jb=re((vK,Qb)=>{var IB=Math.pow(2,7),RB=Math.pow(2,14),BB=Math.pow(2,21),TB=Math.pow(2,28),kB=Math.pow(2,35),CB=Math.pow(2,42),PB=Math.pow(2,49),DB=Math.pow(2,56),NB=Math.pow(2,63);Qb.exports=function(t){return t<IB?1:t<RB?2:t<BB?3:t<TB?4:t<kB?5:t<CB?6:t<PB?7:t<DB?8:t<NB?9:10}});var Zb=re((EK,Xb)=>{Xb.exports={encode:Gb(),decode:jb(),encodingLength:Jb()}});var rw=re((AK,tw)=>{"use strict";var ew=Zb();tw.exports=t=>{if(!(t instanceof Uint8Array))throw new Error("arg needs to be a Uint8Array");let e=[];for(;t.length>0;){let r=ew.decode(t);e.push(r),t=t.slice(ew.decode.bytes)}return e}});var Yd=re((SK,nw)=>{var us=1e3,ls=us*60,fs=ls*60,so=fs*24,LB=so*7,OB=so*365.25;nw.exports=function(t,e){e=e||{};var r=typeof t;if(r==="string"&&t.length>0)return UB(t);if(r==="number"&&isFinite(t))return e.long?MB(t):KB(t);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(t))};function UB(t){if(t=String(t),!(t.length>100)){var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(t);if(e){var r=parseFloat(e[1]),n=(e[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return r*OB;case"weeks":case"week":case"w":return r*LB;case"days":case"day":case"d":return r*so;case"hours":case"hour":case"hrs":case"hr":case"h":return r*fs;case"minutes":case"minute":case"mins":case"min":case"m":return r*ls;case"seconds":case"second":case"secs":case"sec":case"s":return r*us;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:return}}}}function KB(t){var e=Math.abs(t);return e>=so?Math.round(t/so)+"d":e>=fs?Math.round(t/fs)+"h":e>=ls?Math.round(t/ls)+"m":e>=us?Math.round(t/us)+"s":t+"ms"}function MB(t){var e=Math.abs(t);return e>=so?Lu(t,e,so,"day"):e>=fs?Lu(t,e,fs,"hour"):e>=ls?Lu(t,e,ls,"minute"):e>=us?Lu(t,e,us,"second"):t+" ms"}function Lu(t,e,r,n){var i=e>=r*1.5;return Math.round(t/r)+" "+n+(i?"s":"")}});var ow=re((_K,iw)=>{function FB(t){r.debug=r,r.default=r,r.coerce=c,r.disable=o,r.enable=i,r.enabled=s,r.humanize=Yd(),r.destroy=u,Object.keys(t).forEach(l=>{r[l]=t[l]}),r.names=[],r.skips=[],r.formatters={};function e(l){let f=0;for(let d=0;d<l.length;d++)f=(f<<5)-f+l.charCodeAt(d),f|=0;return r.colors[Math.abs(f)%r.colors.length]}r.selectColor=e;function r(l){let f,d=null,p,h;function m(...y){if(!m.enabled)return;let g=m,b=Number(new Date),w=b-(f||b);g.diff=w,g.prev=f,g.curr=b,f=b,y[0]=r.coerce(y[0]),typeof y[0]!="string"&&y.unshift("%O");let _=0;y[0]=y[0].replace(/%([a-zA-Z%])/g,(A,B)=>{if(A==="%%")return"%";_++;let I=r.formatters[B];if(typeof I=="function"){let L=y[_];A=I.call(g,L),y.splice(_,1),_--}return A}),r.formatArgs.call(g,y),(g.log||r.log).apply(g,y)}return m.namespace=l,m.useColors=r.useColors(),m.color=r.selectColor(l),m.extend=n,m.destroy=r.destroy,Object.defineProperty(m,"enabled",{enumerable:!0,configurable:!1,get:()=>d!==null?d:(p!==r.namespaces&&(p=r.namespaces,h=r.enabled(l)),h),set:y=>{d=y}}),typeof r.init=="function"&&r.init(m),m}function n(l,f){let d=r(this.namespace+(typeof f>"u"?":":f)+l);return d.log=this.log,d}function i(l){r.save(l),r.namespaces=l,r.names=[],r.skips=[];let f,d=(typeof l=="string"?l:"").split(/[\s,]+/),p=d.length;for(f=0;f<p;f++)d[f]&&(l=d[f].replace(/\*/g,".*?"),l[0]==="-"?r.skips.push(new RegExp("^"+l.slice(1)+"$")):r.names.push(new RegExp("^"+l+"$")))}function o(){let l=[...r.names.map(a),...r.skips.map(a).map(f=>"-"+f)].join(",");return r.enable(""),l}function s(l){if(l[l.length-1]==="*")return!0;let f,d;for(f=0,d=r.skips.length;f<d;f++)if(r.skips[f].test(l))return!1;for(f=0,d=r.names.length;f<d;f++)if(r.names[f].test(l))return!0;return!1}function a(l){return l.toString().substring(2,l.toString().length-2).replace(/\.\*\?$/,"*")}function c(l){return l instanceof Error?l.stack||l.message:l}function u(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return r.enable(r.load()),r}iw.exports=FB});var Uu=re((cr,Ou)=>{cr.formatArgs=HB;cr.save=qB;cr.load=$B;cr.useColors=VB;cr.storage=zB();cr.destroy=(()=>{let t=!1;return()=>{t||(t=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})();cr.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function VB(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)?!1:typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function HB(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+Ou.exports.humanize(this.diff),!this.useColors)return;let e="color: "+this.color;t.splice(1,0,e,"color: inherit");let r=0,n=0;t[0].replace(/%[a-zA-Z%]/g,i=>{i!=="%%"&&(r++,i==="%c"&&(n=r))}),t.splice(n,0,e)}cr.log=console.debug||console.log||(()=>{});function qB(t){try{t?cr.storage.setItem("debug",t):cr.storage.removeItem("debug")}catch{}}function $B(){let t;try{t=cr.storage.getItem("debug")}catch{}return!t&&typeof process<"u"&&"env"in process&&(t=process.env.DEBUG),t}function zB(){try{return localStorage}catch{}}Ou.exports=ow()(cr);var{formatters:GB}=Ou.exports;GB.j=function(t){try{return JSON.stringify(t)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var mw=re((JK,pw)=>{pw.exports=np;var dw=128,lT=127,fT=~lT,hT=Math.pow(2,31);function np(t,e,r){if(Number.MAX_SAFE_INTEGER&&t>Number.MAX_SAFE_INTEGER)throw np.bytes=0,new RangeError("Could not encode varint");e=e||[],r=r||0;for(var n=r;t>=hT;)e[r++]=t&255|dw,t/=128;for(;t&fT;)e[r++]=t&255|dw,t>>>=7;return e[r]=t|0,np.bytes=r-n+1,e}});var bw=re((XK,gw)=>{gw.exports=ip;var dT=128,yw=127;function ip(t,n){var r=0,n=n||0,i=0,o=n,s,a=t.length;do{if(o>=a||i>49)throw ip.bytes=0,new RangeError("Could not decode varint");s=t[o++],r+=i<28?(s&yw)<<i:(s&yw)*Math.pow(2,i),i+=7}while(s>=dT);return ip.bytes=o-n,r}});var xw=re((ZK,ww)=>{var pT=Math.pow(2,7),mT=Math.pow(2,14),yT=Math.pow(2,21),gT=Math.pow(2,28),bT=Math.pow(2,35),wT=Math.pow(2,42),xT=Math.pow(2,49),vT=Math.pow(2,56),ET=Math.pow(2,63);ww.exports=function(t){return t<pT?1:t<mT?2:t<yT?3:t<gT?4:t<bT?5:t<wT?6:t<xT?7:t<vT?8:t<ET?9:10}});var Ew=re((eM,vw)=>{vw.exports={encode:mw(),decode:bw(),encodingLength:xw()}});var fo=re((b9,Zw)=>{"use strict";function Xw(t,e){for(let r in e)Object.defineProperty(t,r,{value:e[r],enumerable:!0,configurable:!0});return t}function _8(t,e,r){if(!t||typeof t=="string")throw new TypeError("Please pass an Error to err-code");r||(r={}),typeof e=="object"&&(r=e,e=""),e&&(r.code=e);try{return Xw(t,r)}catch{r.message=t.message,r.stack=t.stack;let i=function(){};return i.prototype=Object.create(Object.getPrototypeOf(t)),Xw(new i,r)}}Zw.exports=_8});var rx=re((K9,tx)=>{"use strict";tx.exports=function(){return Date.now()}});var ix=re((M9,nx)=>{"use strict";var Ju=rx(),Kp=class{constructor(e,r,n){let i=this;this._started=Ju(),this._rescheduled=0,this._scheduled=r,this._args=n,this._triggered=!1,this._timerWrapper=()=>{i._rescheduled>0?(i._scheduled=i._rescheduled-(Ju()-i._started),i._schedule(i._scheduled)):(i._triggered=!0,e.apply(null,i._args))},this._timer=setTimeout(this._timerWrapper,r)}reschedule(e){e||(e=this._scheduled);let r=Ju();r+e-(this._started+this._scheduled)<0?(clearTimeout(this._timer),this._schedule(e)):this._triggered?this._schedule(e):(this._started=r,this._rescheduled=e)}_schedule(e){this._triggered=!1,this._started=Ju(),this._rescheduled=0,this._scheduled=e,this._timer=setTimeout(this._timerWrapper,e)}clear(){clearTimeout(this._timer)}};function L8(){if(typeof arguments[0]!="function")throw new Error("callback needed");if(typeof arguments[1]!="number")throw new Error("timeout needed");let t;if(arguments.length>0){t=new Array(arguments.length-2);for(var e=0;e<t.length;e++)t[e]=arguments[e+2]}return new Kp(arguments[0],arguments[1],t)}nx.exports=L8});var ax=re((F9,sx)=>{"use strict";var{AbortController:O8}=globalThis,ox=ix(),Mp=class t extends O8{constructor(e){super(),this._ms=e,this._timer=ox(()=>this.abort(),e),Object.setPrototypeOf(this,t.prototype)}abort(){return this._timer.clear(),super.abort()}clear(){this._timer.clear()}reset(){this._timer.clear(),this._timer=ox(()=>this.abort(),this._ms)}};sx.exports={TimeoutController:Mp}});var el=re((J9,Vp)=>{"use strict";var xs=typeof Reflect=="object"?Reflect:null,cx=xs&&typeof xs.apply=="function"?xs.apply:function(e,r,n){return Function.prototype.apply.call(e,r,n)},Xu;xs&&typeof xs.ownKeys=="function"?Xu=xs.ownKeys:Object.getOwnPropertySymbols?Xu=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:Xu=function(e){return Object.getOwnPropertyNames(e)};function F8(t){console&&console.warn&&console.warn(t)}var lx=Number.isNaN||function(e){return e!==e};function De(){De.init.call(this)}Vp.exports=De;Vp.exports.once=$8;De.EventEmitter=De;De.prototype._events=void 0;De.prototype._eventsCount=0;De.prototype._maxListeners=void 0;var ux=10;function Zu(t){if(typeof t!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}Object.defineProperty(De,"defaultMaxListeners",{enumerable:!0,get:function(){return ux},set:function(t){if(typeof t!="number"||t<0||lx(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");ux=t}});De.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};De.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||lx(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this};function fx(t){return t._maxListeners===void 0?De.defaultMaxListeners:t._maxListeners}De.prototype.getMaxListeners=function(){return fx(this)};De.prototype.emit=function(e){for(var r=[],n=1;n<arguments.length;n++)r.push(arguments[n]);var i=e==="error",o=this._events;if(o!==void 0)i=i&&o.error===void 0;else if(!i)return!1;if(i){var s;if(r.length>0&&(s=r[0]),s instanceof Error)throw s;var a=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw a.context=s,a}var c=o[e];if(c===void 0)return!1;if(typeof c=="function")cx(c,this,r);else for(var u=c.length,l=yx(c,u),n=0;n<u;++n)cx(l[n],this,r);return!0};function hx(t,e,r,n){var i,o,s;if(Zu(r),o=t._events,o===void 0?(o=t._events=Object.create(null),t._eventsCount=0):(o.newListener!==void 0&&(t.emit("newListener",e,r.listener?r.listener:r),o=t._events),s=o[e]),s===void 0)s=o[e]=r,++t._eventsCount;else if(typeof s=="function"?s=o[e]=n?[r,s]:[s,r]:n?s.unshift(r):s.push(r),i=fx(t),i>0&&s.length>i&&!s.warned){s.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=t,a.type=e,a.count=s.length,F8(a)}return t}De.prototype.addListener=function(e,r){return hx(this,e,r,!1)};De.prototype.on=De.prototype.addListener;De.prototype.prependListener=function(e,r){return hx(this,e,r,!0)};function V8(){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 dx(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},i=V8.bind(n);return i.listener=r,n.wrapFn=i,i}De.prototype.once=function(e,r){return Zu(r),this.on(e,dx(this,e,r)),this};De.prototype.prependOnceListener=function(e,r){return Zu(r),this.prependListener(e,dx(this,e,r)),this};De.prototype.removeListener=function(e,r){var n,i,o,s,a;if(Zu(r),i=this._events,i===void 0)return this;if(n=i[e],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete i[e],i.removeListener&&this.emit("removeListener",e,n.listener||r));else if(typeof n!="function"){for(o=-1,s=n.length-1;s>=0;s--)if(n[s]===r||n[s].listener===r){a=n[s].listener,o=s;break}if(o<0)return this;o===0?n.shift():H8(n,o),n.length===1&&(i[e]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",e,a||r)}return this};De.prototype.off=De.prototype.removeListener;De.prototype.removeAllListeners=function(e){var r,n,i;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var o=Object.keys(n),s;for(i=0;i<o.length;++i)s=o[i],s!=="removeListener"&&this.removeAllListeners(s);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(r=n[e],typeof r=="function")this.removeListener(e,r);else if(r!==void 0)for(i=r.length-1;i>=0;i--)this.removeListener(e,r[i]);return this};function px(t,e,r){var n=t._events;if(n===void 0)return[];var i=n[e];return i===void 0?[]:typeof i=="function"?r?[i.listener||i]:[i]:r?q8(i):yx(i,i.length)}De.prototype.listeners=function(e){return px(this,e,!0)};De.prototype.rawListeners=function(e){return px(this,e,!1)};De.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):mx.call(t,e)};De.prototype.listenerCount=mx;function mx(t){var e=this._events;if(e!==void 0){var r=e[t];if(typeof r=="function")return 1;if(r!==void 0)return r.length}return 0}De.prototype.eventNames=function(){return this._eventsCount>0?Xu(this._events):[]};function yx(t,e){for(var r=new Array(e),n=0;n<e;++n)r[n]=t[n];return r}function H8(t,e){for(;e+1<t.length;e++)t[e]=t[e+1];t.pop()}function q8(t){for(var e=new Array(t.length),r=0;r<e.length;++r)e[r]=t[r].listener||t[r];return e}function $8(t,e){return new Promise(function(r,n){function i(s){t.removeListener(e,o),n(s)}function o(){typeof t.removeListener=="function"&&t.removeListener("error",i),r([].slice.call(arguments))}gx(t,e,o,{once:!0}),e!=="error"&&z8(t,i,{once:!0})})}function z8(t,e,r){typeof t.on=="function"&&gx(t,"error",e,r)}function gx(t,e,r,n){if(typeof t.on=="function")n.once?t.once(e,r):t.on(e,r);else if(typeof t.addEventListener=="function")t.addEventListener(e,function i(o){n.once&&t.removeEventListener(e,i),r(o)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof t)}});var Rx=re((_x,Ix)=>{"use strict";var mk=Math.exp;_x=Ix.exports=function(e){if(typeof e!="number")throw new Error("must provide a timespan to the moving average constructor");if(e<=0)throw new Error("must provide a timespan > 0 to the moving average constructor");let r,n=0,i=0,o=0,s,a={};function c(u,l){return 1-mk(-(u-l)/e)}return a.push=function(l,f){if(s){let d=c(l,s),p=f-r,h=d*p;r=d*f+(1-d)*r,n=(1-d)*(n+p*h),i=Math.sqrt(n),o=r+d*p}else r=f;s=l},a.movingAverage=function(){return r},a.variance=function(){return n},a.deviation=function(){return i},a.forecast=function(){return o},a}});var Q1=re(($q,y0)=>{"use strict";var cC=Object.prototype.hasOwnProperty,zt="~";function gc(){}Object.create&&(gc.prototype=Object.create(null),new gc().__proto__||(zt=!1));function uC(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function j1(t,e,r,n,i){if(typeof r!="function")throw new TypeError("The listener must be a function");var o=new uC(r,n||t,i),s=zt?zt+e:e;return t._events[s]?t._events[s].fn?t._events[s]=[t._events[s],o]:t._events[s].push(o):(t._events[s]=o,t._eventsCount++),t}function Sl(t,e){--t._eventsCount===0?t._events=new gc:delete t._events[e]}function Vt(){this._events=new gc,this._eventsCount=0}Vt.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)cC.call(r,n)&&e.push(zt?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};Vt.prototype.listeners=function(e){var r=zt?zt+e:e,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,o=n.length,s=new Array(o);i<o;i++)s[i]=n[i].fn;return s};Vt.prototype.listenerCount=function(e){var r=zt?zt+e:e,n=this._events[r];return n?n.fn?1:n.length:0};Vt.prototype.emit=function(e,r,n,i,o,s){var a=zt?zt+e:e;if(!this._events[a])return!1;var c=this._events[a],u=arguments.length,l,f;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),u){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,r),!0;case 3:return c.fn.call(c.context,r,n),!0;case 4:return c.fn.call(c.context,r,n,i),!0;case 5:return c.fn.call(c.context,r,n,i,o),!0;case 6:return c.fn.call(c.context,r,n,i,o,s),!0}for(f=1,l=new Array(u-1);f<u;f++)l[f-1]=arguments[f];c.fn.apply(c.context,l)}else{var d=c.length,p;for(f=0;f<d;f++)switch(c[f].once&&this.removeListener(e,c[f].fn,void 0,!0),u){case 1:c[f].fn.call(c[f].context);break;case 2:c[f].fn.call(c[f].context,r);break;case 3:c[f].fn.call(c[f].context,r,n);break;case 4:c[f].fn.call(c[f].context,r,n,i);break;default:if(!l)for(p=1,l=new Array(u-1);p<u;p++)l[p-1]=arguments[p];c[f].fn.apply(c[f].context,l)}}return!0};Vt.prototype.on=function(e,r,n){return j1(this,e,r,n,!1)};Vt.prototype.once=function(e,r,n){return j1(this,e,r,n,!0)};Vt.prototype.removeListener=function(e,r,n,i){var o=zt?zt+e:e;if(!this._events[o])return this;if(!r)return Sl(this,o),this;var s=this._events[o];if(s.fn)s.fn===r&&(!i||s.once)&&(!n||s.context===n)&&Sl(this,o);else{for(var a=0,c=[],u=s.length;a<u;a++)(s[a].fn!==r||i&&!s[a].once||n&&s[a].context!==n)&&c.push(s[a]);c.length?this._events[o]=c.length===1?c[0]:c:Sl(this,o)}return this};Vt.prototype.removeAllListeners=function(e){var r;return e?(r=zt?zt+e:e,this._events[r]&&Sl(this,r)):(this._events=new gc,this._eventsCount=0),this};Vt.prototype.off=Vt.prototype.removeListener;Vt.prototype.addListener=Vt.prototype.on;Vt.prefixed=zt;Vt.EventEmitter=Vt;typeof y0<"u"&&(y0.exports=Vt)});var Kv=re(Vs=>{"use strict";var z4="[object ArrayBuffer]",$n=class t{static isArrayBuffer(e){return Object.prototype.toString.call(e)===z4}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}static toUint8Array(e){return this.toView(e,Uint8Array)}static toView(e,r){if(e.constructor===r)return e;if(this.isArrayBuffer(e))return new r(e);if(this.isArrayBufferView(e))return new r(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}static isArrayBufferView(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}static isEqual(e,r){let n=t.toUint8Array(e),i=t.toUint8Array(r);if(n.length!==i.byteLength)return!1;for(let o=0;o<n.length;o++)if(n[o]!==i[o])return!1;return!0}static concat(...e){let r;Array.isArray(e[0])&&!(e[1]instanceof Function)||Array.isArray(e[0])&&e[1]instanceof Function?r=e[0]:e[e.length-1]instanceof Function?r=e.slice(0,e.length-1):r=e;let n=0;for(let s of r)n+=s.byteLength;let i=new Uint8Array(n),o=0;for(let s of r){let a=this.toUint8Array(s);i.set(a,o),o+=a.length}return e[e.length-1]instanceof Function?this.toView(i,e[e.length-1]):i.buffer}},W0="string",G4=/^[0-9a-f]+$/i,W4=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Y4=/^[a-zA-Z0-9-_]+$/,zl=class{static fromString(e){let r=unescape(encodeURIComponent(e)),n=new Uint8Array(r.length);for(let i=0;i<r.length;i++)n[i]=r.charCodeAt(i);return n.buffer}static toString(e){let r=$n.toUint8Array(e),n="";for(let o=0;o<r.length;o++)n+=String.fromCharCode(r[o]);return decodeURIComponent(escape(n))}},Rr=class{static toString(e,r=!1){let n=$n.toArrayBuffer(e),i=new DataView(n),o="";for(let s=0;s<n.byteLength;s+=2){let a=i.getUint16(s,r);o+=String.fromCharCode(a)}return o}static fromString(e,r=!1){let n=new ArrayBuffer(e.length*2),i=new DataView(n);for(let o=0;o<e.length;o++)i.setUint16(o*2,e.charCodeAt(o),r);return n}},Gl=class t{static isHex(e){return typeof e===W0&&G4.test(e)}static isBase64(e){return typeof e===W0&&W4.test(e)}static isBase64Url(e){return typeof e===W0&&Y4.test(e)}static ToString(e,r="utf8"){let n=$n.toUint8Array(e);switch(r.toLowerCase()){case"utf8":return this.ToUtf8String(n);case"binary":return this.ToBinary(n);case"hex":return this.ToHex(n);case"base64":return this.ToBase64(n);case"base64url":return this.ToBase64Url(n);case"utf16le":return Rr.toString(n,!0);case"utf16":case"utf16be":return Rr.toString(n);default:throw new Error(`Unknown type of encoding '${r}'`)}}static FromString(e,r="utf8"){if(!e)return new ArrayBuffer(0);switch(r.toLowerCase()){case"utf8":return this.FromUtf8String(e);case"binary":return this.FromBinary(e);case"hex":return this.FromHex(e);case"base64":return this.FromBase64(e);case"base64url":return this.FromBase64Url(e);case"utf16le":return Rr.fromString(e,!0);case"utf16":case"utf16be":return Rr.fromString(e);default:throw new Error(`Unknown type of encoding '${r}'`)}}static ToBase64(e){let r=$n.toUint8Array(e);if(typeof btoa<"u"){let n=this.ToString(r,"binary");return btoa(n)}else return Buffer.from(r).toString("base64")}static FromBase64(e){let r=this.formatString(e);if(!r)return new ArrayBuffer(0);if(!t.isBase64(r))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(r)):new Uint8Array(Buffer.from(r,"base64")).buffer}static FromBase64Url(e){let r=this.formatString(e);if(!r)return new ArrayBuffer(0);if(!t.isBase64Url(r))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(r.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(e){return this.ToBase64(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(e,r=t.DEFAULT_UTF8_ENCODING){switch(r){case"ascii":return this.FromBinary(e);case"utf8":return zl.fromString(e);case"utf16":case"utf16be":return Rr.fromString(e);case"utf16le":case"usc2":return Rr.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${r}'`)}}static ToUtf8String(e,r=t.DEFAULT_UTF8_ENCODING){switch(r){case"ascii":return this.ToBinary(e);case"utf8":return zl.toString(e);case"utf16":case"utf16be":return Rr.toString(e);case"utf16le":case"usc2":return Rr.toString(e,!0);default:throw new Error(`Unknown type of encoding '${r}'`)}}static FromBinary(e){let r=e.length,n=new Uint8Array(r);for(let i=0;i<r;i++)n[i]=e.charCodeAt(i);return n.buffer}static ToBinary(e){let r=$n.toUint8Array(e),n="";for(let i=0;i<r.length;i++)n+=String.fromCharCode(r[i]);return n}static ToHex(e){let r=$n.toUint8Array(e),n="",i=r.length;for(let o=0;o<i;o++){let s=r[o];s<16&&(n+="0"),n+=s.toString(16)}return n}static FromHex(e){let r=this.formatString(e);if(!r)return new ArrayBuffer(0);if(!t.isHex(r))throw new TypeError("Argument 'hexString' is not HEX encoded");r.length%2&&(r=`0${r}`);let n=new Uint8Array(r.length/2);for(let i=0;i<r.length;i=i+2){let o=r.slice(i,i+2);n[i/2]=parseInt(o,16)}return n.buffer}static ToUtf16String(e,r=!1){return Rr.toString(e,r)}static FromUtf16String(e,r=!1){return Rr.fromString(e,r)}static Base64Padding(e){let r=4-e.length%4;if(r<4)for(let n=0;n<r;n++)e+="=";return e}static formatString(e){return e?.replace(/[\n\r\t ]/g,"")||""}};Gl.DEFAULT_UTF8_ENCODING="utf8";function j4(t,...e){let r=arguments[0];for(let n=1;n<arguments.length;n++){let i=arguments[n];for(let o in i)r[o]=i[o]}return r}function Q4(...t){let e=t.map(i=>i.byteLength).reduce((i,o)=>i+o),r=new Uint8Array(e),n=0;return t.map(i=>new Uint8Array(i)).forEach(i=>{for(let o of i)r[n++]=o}),r.buffer}function J4(t,e){if(!(t&&e)||t.byteLength!==e.byteLength)return!1;let r=new Uint8Array(t),n=new Uint8Array(e);for(let i=0;i<t.byteLength;i++)if(r[i]!==n[i])return!1;return!0}Vs.BufferSourceConverter=$n;Vs.Convert=Gl;Vs.assign=j4;Vs.combine=Q4;Vs.isEqual=J4});var lA=re($c=>{(function(){var t,e,r,n,i,o,s,a;a=function(c){var u,l,f,d;return u=(c&255<<24)>>>24,l=(c&255<<16)>>>16,f=(c&65280)>>>8,d=c&255,[u,l,f,d].join(".")},s=function(c){var u,l,f,d,p,h;for(u=[],f=d=0;d<=3&&c.length!==0;f=++d){if(f>0){if(c[0]!==".")throw new Error("Invalid IP");c=c.substring(1)}h=e(c),p=h[0],l=h[1],c=c.substring(l),u.push(p)}if(c.length!==0)throw new Error("Invalid IP");switch(u.length){case 1:if(u[0]>4294967295)throw new Error("Invalid IP");return u[0]>>>0;case 2:if(u[0]>255||u[1]>16777215)throw new Error("Invalid IP");return(u[0]<<24|u[1])>>>0;case 3:if(u[0]>255||u[1]>255||u[2]>65535)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2])>>>0;case 4:if(u[0]>255||u[1]>255||u[2]>255||u[3]>255)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2]<<8|u[3])>>>0;default:throw new Error("Invalid IP")}},r=function(c){return c.charCodeAt(0)},n=r("0"),o=r("a"),i=r("A"),e=function(c){var u,l,f,d,p;for(d=0,u=10,l="9",f=0,c.length>1&&c[f]==="0"&&(c[f+1]==="x"||c[f+1]==="X"?(f+=2,u=16):"0"<=c[f+1]&&c[f+1]<="9"&&(f++,u=8,l="7")),p=f;f<c.length;){if("0"<=c[f]&&c[f]<=l)d=d*u+(r(c[f])-n)>>>0;else if(u===16)if("a"<=c[f]&&c[f]<="f")d=d*u+(10+r(c[f])-o)>>>0;else if("A"<=c[f]&&c[f]<="F")d=d*u+(10+r(c[f])-i)>>>0;else break;else break;if(d>4294967295)throw new Error("too large");f++}if(f===p)throw new Error("empty octet");return[d,f]},t=function(){function c(u,l){var f,d,p,h;if(typeof u!="string")throw new Error("Missing `net' parameter");if(l||(h=u.split("/",2),u=h[0],l=h[1]),l||(l=32),typeof l=="string"&&l.indexOf(".")>-1){try{this.maskLong=s(l)}catch(m){throw f=m,new Error("Invalid mask: "+l)}for(d=p=32;p>=0;d=--p)if(this.maskLong===4294967295<<32-d>>>0){this.bitmask=d;break}}else if(l||l===0)this.bitmask=parseInt(l,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(s(u)&this.maskLong)>>>0}catch(m){throw f=m,new Error("Invalid net address: "+u)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+l);this.size=Math.pow(2,32-this.bitmask),this.base=a(this.netLong),this.mask=a(this.maskLong),this.hostmask=a(~this.maskLong),this.first=this.bitmask<=30?a(this.netLong+1):this.base,this.last=this.bitmask<=30?a(this.netLong+this.size-2):a(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?a(this.netLong+this.size-1):void 0}return c.prototype.contains=function(u){return typeof u=="string"&&(u.indexOf("/")>0||u.split(".").length!==4)&&(u=new c(u)),u instanceof c?this.contains(u.base)&&this.contains(u.broadcast||u.last):(s(u)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},c.prototype.next=function(u){return u==null&&(u=1),new c(a(this.netLong+this.size*u),this.mask)},c.prototype.forEach=function(u){var l,f,d;for(d=s(this.first),f=s(this.last),l=0;d<=f;)u(a(d),d,l),l++,d++},c.prototype.toString=function(){return this.base+"/"+this.bitmask},c}(),$c.ip2long=s,$c.long2ip=a,$c.Netmask=t}).call($c)});var pA=re((dA,ih)=>{(function(t){"use strict";let e="(0?\\d+|0x[a-f0-9]+)",r={fourOctet:new RegExp(`^${e}\\.${e}\\.${e}\\.${e}$`,"i"),threeOctet:new RegExp(`^${e}\\.${e}\\.${e}$`,"i"),twoOctet:new RegExp(`^${e}\\.${e}$`,"i"),longValue:new RegExp(`^${e}$`,"i")},n=new RegExp("^0[0-7]+$","i"),i=new RegExp("^0x[a-f0-9]+$","i"),o="%[0-9a-z]{1,}",s="(?:[0-9a-f]+::?)+",a={zoneIndex:new RegExp(o,"i"),native:new RegExp(`^(::)?(${s})?([0-9a-f]+)?(::)?(${o})?$`,"i"),deprecatedTransitional:new RegExp(`^(?:::)(${e}\\.${e}\\.${e}\\.${e}(${o})?)$`,"i"),transitional:new RegExp(`^((?:${s})|(?:::)(?:${s})?)${e}\\.${e}\\.${e}\\.${e}(${o})?$`,"i")};function c(p,h){if(p.indexOf("::")!==p.lastIndexOf("::"))return null;let m=0,y=-1,g=(p.match(a.zoneIndex)||[])[0],b,w;for(g&&(g=g.substring(1),p=p.replace(/%.+$/,""));(y=p.indexOf(":",y+1))>=0;)m++;if(p.substr(0,2)==="::"&&m--,p.substr(-2,2)==="::"&&m--,m>h)return null;for(w=h-m,b=":";w--;)b+="0:";return p=p.replace("::",b),p[0]===":"&&(p=p.slice(1)),p[p.length-1]===":"&&(p=p.slice(0,-1)),h=function(){let _=p.split(":"),E=[];for(let A=0;A<_.length;A++)E.push(parseInt(_[A],16));return E}(),{parts:h,zoneId:g}}function u(p,h,m,y){if(p.length!==h.length)throw new Error("ipaddr: cannot match CIDR for objects with different lengths");let g=0,b;for(;y>0;){if(b=m-y,b<0&&(b=0),p[g]>>b!==h[g]>>b)return!1;y-=m,g+=1}return!0}function l(p){if(i.test(p))return parseInt(p,16);if(p[0]==="0"&&!isNaN(parseInt(p[1],10))){if(n.test(p))return parseInt(p,8);throw new Error(`ipaddr: cannot parse ${p} as octal`)}return parseInt(p,10)}function f(p,h){for(;p.length<h;)p=`0${p}`;return p}let d={};d.IPv4=function(){function p(h){if(h.length!==4)throw new Error("ipaddr: ipv4 octet count should be 4");let m,y;for(m=0;m<h.length;m++)if(y=h[m],!(0<=y&&y<=255))throw new Error("ipaddr: ipv4 octet should fit in 8 bits");this.octets=h}return p.prototype.SpecialRanges={unspecified:[[new p([0,0,0,0]),8]],broadcast:[[new p([255,255,255,255]),32]],multicast:[[new p([224,0,0,0]),4]],linkLocal:[[new p([169,254,0,0]),16]],loopback:[[new p([127,0,0,0]),8]],carrierGradeNat:[[new p([100,64,0,0]),10]],private:[[new p([10,0,0,0]),8],[new p([172,16,0,0]),12],[new p([192,168,0,0]),16]],reserved:[[new p([192,0,0,0]),24],[new p([192,0,2,0]),24],[new p([192,88,99,0]),24],[new p([198,18,0,0]),15],[new p([198,51,100,0]),24],[new p([203,0,113,0]),24],[new p([240,0,0,0]),4]]},p.prototype.kind=function(){return"ipv4"},p.prototype.match=function(h,m){let y;if(m===void 0&&(y=h,h=y[0],m=y[1]),h.kind()!=="ipv4")throw new Error("ipaddr: cannot match ipv4 address with non-ipv4 one");return u(this.octets,h.octets,8,m)},p.prototype.prefixLengthFromSubnetMask=function(){let h=0,m=!1,y={0:8,128:7,192:6,224:5,240:4,248:3,252:2,254:1,255:0},g,b,w;for(g=3;g>=0;g-=1)if(b=this.octets[g],b in y){if(w=y[b],m&&w!==0)return null;w!==8&&(m=!0),h+=w}else return null;return 32-h},p.prototype.range=function(){return d.subnetMatch(this,this.SpecialRanges)},p.prototype.toByteArray=function(){return this.octets.slice(0)},p.prototype.toIPv4MappedAddress=function(){return d.IPv6.parse(`::ffff:${this.toString()}`)},p.prototype.toNormalizedString=function(){return this.toString()},p.prototype.toString=function(){return this.octets.join(".")},p}(),d.IPv4.broadcastAddressFromCIDR=function(p){try{let h=this.parseCIDR(p),m=h[0].toByteArray(),y=this.subnetMaskFromPrefixLength(h[1]).toByteArray(),g=[],b=0;for(;b<4;)g.push(parseInt(m[b],10)|parseInt(y[b],10)^255),b++;return new this(g)}catch{throw new Error("ipaddr: the address does not have IPv4 CIDR format")}},d.IPv4.isIPv4=function(p){return this.parser(p)!==null},d.IPv4.isValid=function(p){try{return new this(this.parser(p)),!0}catch{return!1}},d.IPv4.isValidFourPartDecimal=function(p){return!!(d.IPv4.isValid(p)&&p.match(/^(0|[1-9]\d*)(\.(0|[1-9]\d*)){3}$/))},d.IPv4.networkAddressFromCIDR=function(p){let h,m,y,g,b;try{for(h=this.parseCIDR(p),y=h[0].toByteArray(),b=this.subnetMaskFromPrefixLength(h[1]).toByteArray(),g=[],m=0;m<4;)g.push(parseInt(y[m],10)&parseInt(b[m],10)),m++;return new this(g)}catch{throw new Error("ipaddr: the address does not have IPv4 CIDR format")}},d.IPv4.parse=function(p){let h=this.parser(p);if(h===null)throw new Error("ipaddr: string is not formatted like an IPv4 Address");return new this(h)},d.IPv4.parseCIDR=function(p){let h;if(h=p.match(/^(.+)\/(\d+)$/)){let m=parseInt(h[2]);if(m>=0&&m<=32){let y=[this.parse(h[1]),m];return Object.defineProperty(y,"toString",{value:function(){return this.join("/")}}),y}}throw new Error("ipaddr: string is not formatted like an IPv4 CIDR range")},d.IPv4.parser=function(p){let h,m,y;if(h=p.match(r.fourOctet))return function(){let g=h.slice(1,6),b=[];for(let w=0;w<g.length;w++)m=g[w],b.push(l(m));return b}();if(h=p.match(r.longValue)){if(y=l(h[1]),y>4294967295||y<0)throw new Error("ipaddr: address outside defined range");return function(){let g=[],b;for(b=0;b<=24;b+=8)g.push(y>>b&255);return g}().reverse()}else return(h=p.match(r.twoOctet))?function(){let g=h.slice(1,4),b=[];if(y=l(g[1]),y>16777215||y<0)throw new Error("ipaddr: address outside defined range");return b.push(l(g[0])),b.push(y>>16&255),b.push(y>>8&255),b.push(y&255),b}():(h=p.match(r.threeOctet))?function(){let g=h.slice(1,5),b=[];if(y=l(g[2]),y>65535||y<0)throw new Error("ipaddr: address outside defined range");return b.push(l(g[0])),b.push(l(g[1])),b.push(y>>8&255),b.push(y&255),b}():null},d.IPv4.subnetMaskFromPrefixLength=function(p){if(p=parseInt(p),p<0||p>32)throw new Error("ipaddr: invalid IPv4 prefix length");let h=[0,0,0,0],m=0,y=Math.floor(p/8);for(;m<y;)h[m]=255,m++;return y<4&&(h[y]=Math.pow(2,p%8)-1<<8-p%8),new this(h)},d.IPv6=function(){function p(h,m){let y,g;if(h.length===16)for(this.parts=[],y=0;y<=14;y+=2)this.parts.push(h[y]<<8|h[y+1]);else if(h.length===8)this.parts=h;else throw new Error("ipaddr: ipv6 part count should be 8 or 16");for(y=0;y<this.parts.length;y++)if(g=this.parts[y],!(0<=g&&g<=65535))throw new Error("ipaddr: ipv6 part should fit in 16 bits");m&&(this.zoneId=m)}return p.prototype.SpecialRanges={unspecified:[new p([0,0,0,0,0,0,0,0]),128],linkLocal:[new p([65152,0,0,0,0,0,0,0]),10],multicast:[new p([65280,0,0,0,0,0,0,0]),8],loopback:[new p([0,0,0,0,0,0,0,1]),128],uniqueLocal:[new p([64512,0,0,0,0,0,0,0]),7],ipv4Mapped:[new p([0,0,0,0,0,65535,0,0]),96],rfc6145:[new p([0,0,0,0,65535,0,0,0]),96],rfc6052:[new p([100,65435,0,0,0,0,0,0]),96],"6to4":[new p([8194,0,0,0,0,0,0,0]),16],teredo:[new p([8193,0,0,0,0,0,0,0]),32],reserved:[[new p([8193,3512,0,0,0,0,0,0]),32]],benchmarking:[new p([8193,2,0,0,0,0,0,0]),48],amt:[new p([8193,3,0,0,0,0,0,0]),32],as112v6:[new p([8193,4,274,0,0,0,0,0]),48],deprecated:[new p([8193,16,0,0,0,0,0,0]),28],orchid2:[new p([8193,32,0,0,0,0,0,0]),28]},p.prototype.isIPv4MappedAddress=function(){return this.range()==="ipv4Mapped"},p.prototype.kind=function(){return"ipv6"},p.prototype.match=function(h,m){let y;if(m===void 0&&(y=h,h=y[0],m=y[1]),h.kind()!=="ipv6")throw new Error("ipaddr: cannot match ipv6 address with non-ipv6 one");return u(this.parts,h.parts,16,m)},p.prototype.prefixLengthFromSubnetMask=function(){let h=0,m=!1,y={0:16,32768:15,49152:14,57344:13,61440:12,63488:11,64512:10,65024:9,65280:8,65408:7,65472:6,65504:5,65520:4,65528:3,65532:2,65534:1,65535:0},g,b;for(let w=7;w>=0;w-=1)if(g=this.parts[w],g in y){if(b=y[g],m&&b!==0)return null;b!==16&&(m=!0),h+=b}else return null;return 128-h},p.prototype.range=function(){return d.subnetMatch(this,this.SpecialRanges)},p.prototype.toByteArray=function(){let h,m=[],y=this.parts;for(let g=0;g<y.length;g++)h=y[g],m.push(h>>8),m.push(h&255);return m},p.prototype.toFixedLengthString=function(){let h=function(){let y=[];for(let g=0;g<this.parts.length;g++)y.push(f(this.parts[g].toString(16),4));return y}.call(this).join(":"),m="";return this.zoneId&&(m=`%${this.zoneId}`),h+m},p.prototype.toIPv4Address=function(){if(!this.isIPv4MappedAddress())throw new Error("ipaddr: trying to convert a generic ipv6 address to ipv4");let h=this.parts.slice(-2),m=h[0],y=h[1];return new d.IPv4([m>>8,m&255,y>>8,y&255])},p.prototype.toNormalizedString=function(){let h=function(){let y=[];for(let g=0;g<this.parts.length;g++)y.push(this.parts[g].toString(16));return y}.call(this).join(":"),m="";return this.zoneId&&(m=`%${this.zoneId}`),h+m},p.prototype.toRFC5952String=function(){let h=/((^|:)(0(:|$)){2,})/g,m=this.toNormalizedString(),y=0,g=-1,b;for(;b=h.exec(m);)b[0].length>g&&(y=b.index,g=b[0].length);return g<0?m:`${m.substring(0,y)}::${m.substring(y+g)}`},p.prototype.toString=function(){return this.toRFC5952String()},p}(),d.IPv6.broadcastAddressFromCIDR=function(p){try{let h=this.parseCIDR(p),m=h[0].toByteArray(),y=this.subnetMaskFromPrefixLength(h[1]).toByteArray(),g=[],b=0;for(;b<16;)g.push(parseInt(m[b],10)|parseInt(y[b],10)^255),b++;return new this(g)}catch(h){throw new Error(`ipaddr: the address does not have IPv6 CIDR format (${h})`)}},d.IPv6.isIPv6=function(p){return this.parser(p)!==null},d.IPv6.isValid=function(p){if(typeof p=="string"&&p.indexOf(":")===-1)return!1;try{let h=this.parser(p);return new this(h.parts,h.zoneId),!0}catch{return!1}},d.IPv6.networkAddressFromCIDR=function(p){let h,m,y,g,b;try{for(h=this.parseCIDR(p),y=h[0].toByteArray(),b=this.subnetMaskFromPrefixLength(h[1]).toByteArray(),g=[],m=0;m<16;)g.push(parseInt(y[m],10)&parseInt(b[m],10)),m++;return new this(g)}catch(w){throw new Error(`ipaddr: the address does not have IPv6 CIDR format (${w})`)}},d.IPv6.parse=function(p){let h=this.parser(p);if(h.parts===null)throw new Error("ipaddr: string is not formatted like an IPv6 Address");return new this(h.parts,h.zoneId)},d.IPv6.parseCIDR=function(p){let h,m,y;if((m=p.match(/^(.+)\/(\d+)$/))&&(h=parseInt(m[2]),h>=0&&h<=128))return y=[this.parse(m[1]),h],Object.defineProperty(y,"toString",{value:function(){return this.join("/")}}),y;throw new Error("ipaddr: string is not formatted like an IPv6 CIDR range")},d.IPv6.parser=function(p){let h,m,y,g,b,w;if(y=p.match(a.deprecatedTransitional))return this.parser(`::ffff:${y[1]}`);if(a.native.test(p))return c(p,8);if((y=p.match(a.transitional))&&(w=y[6]||"",h=c(y[1].slice(0,-1)+w,6),h.parts)){for(b=[parseInt(y[2]),parseInt(y[3]),parseInt(y[4]),parseInt(y[5])],m=0;m<b.length;m++)if(g=b[m],!(0<=g&&g<=255))return null;return h.parts.push(b[0]<<8|b[1]),h.parts.push(b[2]<<8|b[3]),{parts:h.parts,zoneId:h.zoneId}}return null},d.IPv6.subnetMaskFromPrefixLength=function(p){if(p=parseInt(p),p<0||p>128)throw new Error("ipaddr: invalid IPv6 prefix length");let h=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],m=0,y=Math.floor(p/8);for(;m<y;)h[m]=255,m++;return y<16&&(h[y]=Math.pow(2,p%8)-1<<8-p%8),new this(h)},d.fromByteArray=function(p){let h=p.length;if(h===4)return new d.IPv4(p);if(h===16)return new d.IPv6(p);throw new Error("ipaddr: the binary input is neither an IPv6 nor IPv4 address")},d.isValid=function(p){return d.IPv6.isValid(p)||d.IPv4.isValid(p)},d.parse=function(p){if(d.IPv6.isValid(p))return d.IPv6.parse(p);if(d.IPv4.isValid(p))return d.IPv4.parse(p);throw new Error("ipaddr: the address has neither IPv6 nor IPv4 format")},d.parseCIDR=function(p){try{return d.IPv6.parseCIDR(p)}catch{try{return d.IPv4.parseCIDR(p)}catch{throw new Error("ipaddr: the address has neither IPv6 nor IPv4 CIDR format")}}},d.process=function(p){let h=this.parse(p);return h.kind()==="ipv6"&&h.isIPv4MappedAddress()?h.toIPv4Address():h},d.subnetMatch=function(p,h,m){let y,g,b,w;m==null&&(m="unicast");for(g in h)if(Object.prototype.hasOwnProperty.call(h,g)){for(b=h[g],b[0]&&!(b[0]instanceof Array)&&(b=[b]),y=0;y<b.length;y++)if(w=b[y],p.kind()===w[0].kind()&&p.match.apply(p,w))return g}return m},typeof ih<"u"&&ih.exports?ih.exports=d:t.ipaddr=d})(dA)});var CA=re((pre,kA)=>{"use strict";kA.exports=TA;var pP=Yd(),$i=TA.prototype,mP=new Date%1e9;function yP(){return(Math.random()*1e9>>>0)+mP++}function TA(t){t=t||{},this.id=t.id||yP(),this.max=t.max||1/0,this.items=t.items||[],this._lookup={},this.size=this.items.length,this.lastModified=new Date(t.lastModified||new Date);for(var e,r,n=this.items.length;n--;)e=this.items[n],r=new Date(e.expires)-new Date,this._lookup[e.key]=e,r>0?this.expire(e.key,r):r<=0&&this.delete(e.key)}$i.has=function(t){return t in this._lookup};$i.get=function(t){if(!this.has(t))return null;var e=this._lookup[t];return e.refresh&&this.expire(t,e.refresh),this.items.splice(this.items.indexOf(e),1),this.items.push(e),e.value};$i.meta=function(t){if(!this.has(t))return null;var e=this._lookup[t];return"meta"in e?e.meta:null};$i.set=function(t,e,r){var n=this._lookup[t],i=this._lookup[t]={key:t,value:e};return this.lastModified=new Date,n?(clearTimeout(n.timeout),this.items.splice(this.items.indexOf(n),1,i)):(this.size>=this.max&&this.delete(this.items[0].key),this.items.push(i),this.size++),r&&("ttl"in r&&this.expire(t,r.ttl),"meta"in r&&(i.meta=r.meta),r.refresh&&(i.refresh=r.ttl)),this};$i.delete=function(t){var e=this._lookup[t];return e?(this.lastModified=new Date,this.items.splice(this.items.indexOf(e),1),clearTimeout(e.timeout),delete this._lookup[t],this.size--,this):!1};$i.expire=function(t,e){var r=e||0,n=this._lookup[t];if(!n)return this;if(typeof r=="string"&&(r=pP(e)),typeof r!="number")throw new TypeError("Expiration time must be a string or number.");return clearTimeout(n.timeout),n.timeout=setTimeout(this.delete.bind(this,n.key),r),n.expires=Number(new Date)+r,this};$i.clear=function(){for(var t=this.items.length;t--;)this.delete(this.items[t].key);return this};$i.toJSON=function(){for(var t=new Array(this.items.length),e,r=t.length;r--;)e=this.items[r],t[r]={key:e.key,meta:e.meta,value:e.value,expires:e.expires,refresh:e.refresh};return{id:this.id,max:isFinite(this.max)?this.max:void 0,lastModified:this.lastModified,items:t}}});var OA=re((vre,LA)=>{"use strict";LA.exports=t=>{if(Object.prototype.toString.call(t)!=="[object Object]")return!1;let e=Object.getPrototypeOf(t);return e===null||e===Object.prototype}});var HA=re((FA,VA)=>{"use strict";var hh=OA(),{hasOwnProperty:KA}=Object.prototype,{propertyIsEnumerable:wP}=Object,wa=(t,e,r)=>Object.defineProperty(t,e,{value:r,writable:!0,enumerable:!0,configurable:!0}),xP=FA,UA={concatArrays:!1,ignoreUndefined:!1},dh=t=>{let e=[];for(let r in t)KA.call(t,r)&&e.push(r);if(Object.getOwnPropertySymbols){let r=Object.getOwnPropertySymbols(t);for(let n of r)wP.call(t,n)&&e.push(n)}return e};function xa(t){return Array.isArray(t)?vP(t):hh(t)?EP(t):t}function vP(t){let e=t.slice(0,0);return dh(t).forEach(r=>{wa(e,r,xa(t[r]))}),e}function EP(t){let e=Object.getPrototypeOf(t)===null?Object.create(null):{};return dh(t).forEach(r=>{wa(e,r,xa(t[r]))}),e}var MA=(t,e,r,n)=>(r.forEach(i=>{typeof e[i]>"u"&&n.ignoreUndefined||(i in t&&t[i]!==Object.getPrototypeOf(t)?wa(t,i,ay(t[i],e[i],n)):wa(t,i,xa(e[i])))}),t),AP=(t,e,r)=>{let n=t.slice(0,0),i=0;return[t,e].forEach(o=>{let s=[];for(let a=0;a<o.length;a++)KA.call(o,a)&&(s.push(String(a)),o===t?wa(n,i++,o[a]):wa(n,i++,xa(o[a])));n=MA(n,o,dh(o).filter(a=>!s.includes(a)),r)}),n};function ay(t,e,r){return r.concatArrays&&Array.isArray(t)&&Array.isArray(e)?AP(t,e,r):!hh(e)||!hh(t)?xa(e):MA(t,e,dh(e),r)}VA.exports=function(...t){let e=ay(xa(UA),this!==xP&&this||{},UA),r={_:{}};for(let n of t)if(n!==void 0){if(!hh(n))throw new TypeError("`"+n+"` is not an Option Object");r=ay(r,{_:n},e)}return r._}});var Le=re((pse,PS)=>{PS.exports={options:{usePureJavaScript:!1}}});var LS=re((mse,NS)=>{var Gy={};NS.exports=Gy;var DS={};Gy.encode=function(t,e,r){if(typeof e!="string")throw new TypeError('"alphabet" must be a string.');if(r!==void 0&&typeof r!="number")throw new TypeError('"maxline" must be a number.');var n="";if(!(t instanceof Uint8Array))n=jD(t,e);else{var i=0,o=e.length,s=e.charAt(0),a=[0];for(i=0;i<t.length;++i){for(var c=0,u=t[i];c<a.length;++c)u+=a[c]<<8,a[c]=u%o,u=u/o|0;for(;u>0;)a.push(u%o),u=u/o|0}for(i=0;t[i]===0&&i<t.length-1;++i)n+=s;for(i=a.length-1;i>=0;--i)n+=e[a[i]]}if(r){var l=new RegExp(".{1,"+r+"}","g");n=n.match(l).join(`\r
|
|
3
|
+
`)}return n};Gy.decode=function(t,e){if(typeof t!="string")throw new TypeError('"input" must be a string.');if(typeof e!="string")throw new TypeError('"alphabet" must be a string.');var r=DS[e];if(!r){r=DS[e]=[];for(var n=0;n<e.length;++n)r[e.charCodeAt(n)]=n}t=t.replace(/\s/g,"");for(var i=e.length,o=e.charAt(0),s=[0],n=0;n<t.length;n++){var a=r[t.charCodeAt(n)];if(a===void 0)return;for(var c=0,u=a;c<s.length;++c)u+=s[c]*i,s[c]=u&255,u>>=8;for(;u>0;)s.push(u&255),u>>=8}for(var l=0;t[l]===o&&l<t.length-1;++l)s.push(0);return typeof Buffer<"u"?Buffer.from(s.reverse()):new Uint8Array(s.reverse())};function jD(t,e){var r=0,n=e.length,i=e.charAt(0),o=[0];for(r=0;r<t.length();++r){for(var s=0,a=t.at(r);s<o.length;++s)a+=o[s]<<8,o[s]=a%n,a=a/n|0;for(;a>0;)o.push(a%n),a=a/n|0}var c="";for(r=0;t.at(r)===0&&r<t.length()-1;++r)c+=i;for(r=o.length-1;r>=0;--r)c+=e[o[r]];return c}});var ft=re((yse,MS)=>{var OS=Le(),US=LS(),v=MS.exports=OS.util=OS.util||{};(function(){if(typeof process<"u"&&process.nextTick&&!process.browser){v.nextTick=process.nextTick,typeof setImmediate=="function"?v.setImmediate=setImmediate:v.setImmediate=v.nextTick;return}if(typeof setImmediate=="function"){v.setImmediate=function(){return setImmediate.apply(void 0,arguments)},v.nextTick=function(a){return setImmediate(a)};return}if(v.setImmediate=function(a){setTimeout(a,0)},typeof window<"u"&&typeof window.postMessage=="function"){let a=function(c){if(c.source===window&&c.data===t){c.stopPropagation();var u=e.slice();e.length=0,u.forEach(function(l){l()})}};var s=a,t="forge.setImmediate",e=[];v.setImmediate=function(c){e.push(c),e.length===1&&window.postMessage(t,"*")},window.addEventListener("message",a,!0)}if(typeof MutationObserver<"u"){var r=Date.now(),n=!0,i=document.createElement("div"),e=[];new MutationObserver(function(){var c=e.slice();e.length=0,c.forEach(function(u){u()})}).observe(i,{attributes:!0});var o=v.setImmediate;v.setImmediate=function(c){Date.now()-r>15?(r=Date.now(),o(c)):(e.push(c),e.length===1&&i.setAttribute("a",n=!n))}}v.nextTick=v.setImmediate})();v.isNodejs=typeof process<"u"&&process.versions&&process.versions.node;v.globalScope=function(){return v.isNodejs?globalThis:typeof self>"u"?window:self}();v.isArray=Array.isArray||function(t){return Object.prototype.toString.call(t)==="[object Array]"};v.isArrayBuffer=function(t){return typeof ArrayBuffer<"u"&&t instanceof ArrayBuffer};v.isArrayBufferView=function(t){return t&&v.isArrayBuffer(t.buffer)&&t.byteLength!==void 0};function ru(t){if(!(t===8||t===16||t===24||t===32))throw new Error("Only 8, 16, 24, or 32 bits supported: "+t)}v.ByteBuffer=Wy;function Wy(t){if(this.data="",this.read=0,typeof t=="string")this.data=t;else if(v.isArrayBuffer(t)||v.isArrayBufferView(t))if(typeof Buffer<"u"&&t instanceof Buffer)this.data=t.toString("binary");else{var e=new Uint8Array(t);try{this.data=String.fromCharCode.apply(null,e)}catch{for(var r=0;r<e.length;++r)this.putByte(e[r])}}else(t instanceof Wy||typeof t=="object"&&typeof t.data=="string"&&typeof t.read=="number")&&(this.data=t.data,this.read=t.read);this._constructedStringLength=0}v.ByteStringBuffer=Wy;var QD=4096;v.ByteStringBuffer.prototype._optimizeConstructedString=function(t){this._constructedStringLength+=t,this._constructedStringLength>QD&&(this.data.substr(0,1),this._constructedStringLength=0)};v.ByteStringBuffer.prototype.length=function(){return this.data.length-this.read};v.ByteStringBuffer.prototype.isEmpty=function(){return this.length()<=0};v.ByteStringBuffer.prototype.putByte=function(t){return this.putBytes(String.fromCharCode(t))};v.ByteStringBuffer.prototype.fillWithByte=function(t,e){t=String.fromCharCode(t);for(var r=this.data;e>0;)e&1&&(r+=t),e>>>=1,e>0&&(t+=t);return this.data=r,this._optimizeConstructedString(e),this};v.ByteStringBuffer.prototype.putBytes=function(t){return this.data+=t,this._optimizeConstructedString(t.length),this};v.ByteStringBuffer.prototype.putString=function(t){return this.putBytes(v.encodeUtf8(t))};v.ByteStringBuffer.prototype.putInt16=function(t){return this.putBytes(String.fromCharCode(t>>8&255)+String.fromCharCode(t&255))};v.ByteStringBuffer.prototype.putInt24=function(t){return this.putBytes(String.fromCharCode(t>>16&255)+String.fromCharCode(t>>8&255)+String.fromCharCode(t&255))};v.ByteStringBuffer.prototype.putInt32=function(t){return this.putBytes(String.fromCharCode(t>>24&255)+String.fromCharCode(t>>16&255)+String.fromCharCode(t>>8&255)+String.fromCharCode(t&255))};v.ByteStringBuffer.prototype.putInt16Le=function(t){return this.putBytes(String.fromCharCode(t&255)+String.fromCharCode(t>>8&255))};v.ByteStringBuffer.prototype.putInt24Le=function(t){return this.putBytes(String.fromCharCode(t&255)+String.fromCharCode(t>>8&255)+String.fromCharCode(t>>16&255))};v.ByteStringBuffer.prototype.putInt32Le=function(t){return this.putBytes(String.fromCharCode(t&255)+String.fromCharCode(t>>8&255)+String.fromCharCode(t>>16&255)+String.fromCharCode(t>>24&255))};v.ByteStringBuffer.prototype.putInt=function(t,e){ru(e);var r="";do e-=8,r+=String.fromCharCode(t>>e&255);while(e>0);return this.putBytes(r)};v.ByteStringBuffer.prototype.putSignedInt=function(t,e){return t<0&&(t+=2<<e-1),this.putInt(t,e)};v.ByteStringBuffer.prototype.putBuffer=function(t){return this.putBytes(t.getBytes())};v.ByteStringBuffer.prototype.getByte=function(){return this.data.charCodeAt(this.read++)};v.ByteStringBuffer.prototype.getInt16=function(){var t=this.data.charCodeAt(this.read)<<8^this.data.charCodeAt(this.read+1);return this.read+=2,t};v.ByteStringBuffer.prototype.getInt24=function(){var t=this.data.charCodeAt(this.read)<<16^this.data.charCodeAt(this.read+1)<<8^this.data.charCodeAt(this.read+2);return this.read+=3,t};v.ByteStringBuffer.prototype.getInt32=function(){var t=this.data.charCodeAt(this.read)<<24^this.data.charCodeAt(this.read+1)<<16^this.data.charCodeAt(this.read+2)<<8^this.data.charCodeAt(this.read+3);return this.read+=4,t};v.ByteStringBuffer.prototype.getInt16Le=function(){var t=this.data.charCodeAt(this.read)^this.data.charCodeAt(this.read+1)<<8;return this.read+=2,t};v.ByteStringBuffer.prototype.getInt24Le=function(){var t=this.data.charCodeAt(this.read)^this.data.charCodeAt(this.read+1)<<8^this.data.charCodeAt(this.read+2)<<16;return this.read+=3,t};v.ByteStringBuffer.prototype.getInt32Le=function(){var t=this.data.charCodeAt(this.read)^this.data.charCodeAt(this.read+1)<<8^this.data.charCodeAt(this.read+2)<<16^this.data.charCodeAt(this.read+3)<<24;return this.read+=4,t};v.ByteStringBuffer.prototype.getInt=function(t){ru(t);var e=0;do e=(e<<8)+this.data.charCodeAt(this.read++),t-=8;while(t>0);return e};v.ByteStringBuffer.prototype.getSignedInt=function(t){var e=this.getInt(t),r=2<<t-2;return e>=r&&(e-=r<<1),e};v.ByteStringBuffer.prototype.getBytes=function(t){var e;return t?(t=Math.min(this.length(),t),e=this.data.slice(this.read,this.read+t),this.read+=t):t===0?e="":(e=this.read===0?this.data:this.data.slice(this.read),this.clear()),e};v.ByteStringBuffer.prototype.bytes=function(t){return typeof t>"u"?this.data.slice(this.read):this.data.slice(this.read,this.read+t)};v.ByteStringBuffer.prototype.at=function(t){return this.data.charCodeAt(this.read+t)};v.ByteStringBuffer.prototype.setAt=function(t,e){return this.data=this.data.substr(0,this.read+t)+String.fromCharCode(e)+this.data.substr(this.read+t+1),this};v.ByteStringBuffer.prototype.last=function(){return this.data.charCodeAt(this.data.length-1)};v.ByteStringBuffer.prototype.copy=function(){var t=v.createBuffer(this.data);return t.read=this.read,t};v.ByteStringBuffer.prototype.compact=function(){return this.read>0&&(this.data=this.data.slice(this.read),this.read=0),this};v.ByteStringBuffer.prototype.clear=function(){return this.data="",this.read=0,this};v.ByteStringBuffer.prototype.truncate=function(t){var e=Math.max(0,this.length()-t);return this.data=this.data.substr(this.read,e),this.read=0,this};v.ByteStringBuffer.prototype.toHex=function(){for(var t="",e=this.read;e<this.data.length;++e){var r=this.data.charCodeAt(e);r<16&&(t+="0"),t+=r.toString(16)}return t};v.ByteStringBuffer.prototype.toString=function(){return v.decodeUtf8(this.bytes())};function JD(t,e){e=e||{},this.read=e.readOffset||0,this.growSize=e.growSize||1024;var r=v.isArrayBuffer(t),n=v.isArrayBufferView(t);if(r||n){r?this.data=new DataView(t):this.data=new DataView(t.buffer,t.byteOffset,t.byteLength),this.write="writeOffset"in e?e.writeOffset:this.data.byteLength;return}this.data=new DataView(new ArrayBuffer(0)),this.write=0,t!=null&&this.putBytes(t),"writeOffset"in e&&(this.write=e.writeOffset)}v.DataBuffer=JD;v.DataBuffer.prototype.length=function(){return this.write-this.read};v.DataBuffer.prototype.isEmpty=function(){return this.length()<=0};v.DataBuffer.prototype.accommodate=function(t,e){if(this.length()>=t)return this;e=Math.max(e||this.growSize,t);var r=new Uint8Array(this.data.buffer,this.data.byteOffset,this.data.byteLength),n=new Uint8Array(this.length()+e);return n.set(r),this.data=new DataView(n.buffer),this};v.DataBuffer.prototype.putByte=function(t){return this.accommodate(1),this.data.setUint8(this.write++,t),this};v.DataBuffer.prototype.fillWithByte=function(t,e){this.accommodate(e);for(var r=0;r<e;++r)this.data.setUint8(t);return this};v.DataBuffer.prototype.putBytes=function(t,e){if(v.isArrayBufferView(t)){var r=new Uint8Array(t.buffer,t.byteOffset,t.byteLength),n=r.byteLength-r.byteOffset;this.accommodate(n);var i=new Uint8Array(this.data.buffer,this.write);return i.set(r),this.write+=n,this}if(v.isArrayBuffer(t)){var r=new Uint8Array(t);this.accommodate(r.byteLength);var i=new Uint8Array(this.data.buffer);return i.set(r,this.write),this.write+=r.byteLength,this}if(t instanceof v.DataBuffer||typeof t=="object"&&typeof t.read=="number"&&typeof t.write=="number"&&v.isArrayBufferView(t.data)){var r=new Uint8Array(t.data.byteLength,t.read,t.length());this.accommodate(r.byteLength);var i=new Uint8Array(t.data.byteLength,this.write);return i.set(r),this.write+=r.byteLength,this}if(t instanceof v.ByteStringBuffer&&(t=t.data,e="binary"),e=e||"binary",typeof t=="string"){var o;if(e==="hex")return this.accommodate(Math.ceil(t.length/2)),o=new Uint8Array(this.data.buffer,this.write),this.write+=v.binary.hex.decode(t,o,this.write),this;if(e==="base64")return this.accommodate(Math.ceil(t.length/4)*3),o=new Uint8Array(this.data.buffer,this.write),this.write+=v.binary.base64.decode(t,o,this.write),this;if(e==="utf8"&&(t=v.encodeUtf8(t),e="binary"),e==="binary"||e==="raw")return this.accommodate(t.length),o=new Uint8Array(this.data.buffer,this.write),this.write+=v.binary.raw.decode(o),this;if(e==="utf16")return this.accommodate(t.length*2),o=new Uint16Array(this.data.buffer,this.write),this.write+=v.text.utf16.encode(o),this;throw new Error("Invalid encoding: "+e)}throw Error("Invalid parameter: "+t)};v.DataBuffer.prototype.putBuffer=function(t){return this.putBytes(t),t.clear(),this};v.DataBuffer.prototype.putString=function(t){return this.putBytes(t,"utf16")};v.DataBuffer.prototype.putInt16=function(t){return this.accommodate(2),this.data.setInt16(this.write,t),this.write+=2,this};v.DataBuffer.prototype.putInt24=function(t){return this.accommodate(3),this.data.setInt16(this.write,t>>8&65535),this.data.setInt8(this.write,t>>16&255),this.write+=3,this};v.DataBuffer.prototype.putInt32=function(t){return this.accommodate(4),this.data.setInt32(this.write,t),this.write+=4,this};v.DataBuffer.prototype.putInt16Le=function(t){return this.accommodate(2),this.data.setInt16(this.write,t,!0),this.write+=2,this};v.DataBuffer.prototype.putInt24Le=function(t){return this.accommodate(3),this.data.setInt8(this.write,t>>16&255),this.data.setInt16(this.write,t>>8&65535,!0),this.write+=3,this};v.DataBuffer.prototype.putInt32Le=function(t){return this.accommodate(4),this.data.setInt32(this.write,t,!0),this.write+=4,this};v.DataBuffer.prototype.putInt=function(t,e){ru(e),this.accommodate(e/8);do e-=8,this.data.setInt8(this.write++,t>>e&255);while(e>0);return this};v.DataBuffer.prototype.putSignedInt=function(t,e){return ru(e),this.accommodate(e/8),t<0&&(t+=2<<e-1),this.putInt(t,e)};v.DataBuffer.prototype.getByte=function(){return this.data.getInt8(this.read++)};v.DataBuffer.prototype.getInt16=function(){var t=this.data.getInt16(this.read);return this.read+=2,t};v.DataBuffer.prototype.getInt24=function(){var t=this.data.getInt16(this.read)<<8^this.data.getInt8(this.read+2);return this.read+=3,t};v.DataBuffer.prototype.getInt32=function(){var t=this.data.getInt32(this.read);return this.read+=4,t};v.DataBuffer.prototype.getInt16Le=function(){var t=this.data.getInt16(this.read,!0);return this.read+=2,t};v.DataBuffer.prototype.getInt24Le=function(){var t=this.data.getInt8(this.read)^this.data.getInt16(this.read+1,!0)<<8;return this.read+=3,t};v.DataBuffer.prototype.getInt32Le=function(){var t=this.data.getInt32(this.read,!0);return this.read+=4,t};v.DataBuffer.prototype.getInt=function(t){ru(t);var e=0;do e=(e<<8)+this.data.getInt8(this.read++),t-=8;while(t>0);return e};v.DataBuffer.prototype.getSignedInt=function(t){var e=this.getInt(t),r=2<<t-2;return e>=r&&(e-=r<<1),e};v.DataBuffer.prototype.getBytes=function(t){var e;return t?(t=Math.min(this.length(),t),e=this.data.slice(this.read,this.read+t),this.read+=t):t===0?e="":(e=this.read===0?this.data:this.data.slice(this.read),this.clear()),e};v.DataBuffer.prototype.bytes=function(t){return typeof t>"u"?this.data.slice(this.read):this.data.slice(this.read,this.read+t)};v.DataBuffer.prototype.at=function(t){return this.data.getUint8(this.read+t)};v.DataBuffer.prototype.setAt=function(t,e){return this.data.setUint8(t,e),this};v.DataBuffer.prototype.last=function(){return this.data.getUint8(this.write-1)};v.DataBuffer.prototype.copy=function(){return new v.DataBuffer(this)};v.DataBuffer.prototype.compact=function(){if(this.read>0){var t=new Uint8Array(this.data.buffer,this.read),e=new Uint8Array(t.byteLength);e.set(t),this.data=new DataView(e),this.write-=this.read,this.read=0}return this};v.DataBuffer.prototype.clear=function(){return this.data=new DataView(new ArrayBuffer(0)),this.read=this.write=0,this};v.DataBuffer.prototype.truncate=function(t){return this.write=Math.max(0,this.length()-t),this.read=Math.min(this.read,this.write),this};v.DataBuffer.prototype.toHex=function(){for(var t="",e=this.read;e<this.data.byteLength;++e){var r=this.data.getUint8(e);r<16&&(t+="0"),t+=r.toString(16)}return t};v.DataBuffer.prototype.toString=function(t){var e=new Uint8Array(this.data,this.read,this.length());if(t=t||"utf8",t==="binary"||t==="raw")return v.binary.raw.encode(e);if(t==="hex")return v.binary.hex.encode(e);if(t==="base64")return v.binary.base64.encode(e);if(t==="utf8")return v.text.utf8.decode(e);if(t==="utf16")return v.text.utf16.decode(e);throw new Error("Invalid encoding: "+t)};v.createBuffer=function(t,e){return e=e||"raw",t!==void 0&&e==="utf8"&&(t=v.encodeUtf8(t)),new v.ByteBuffer(t)};v.fillString=function(t,e){for(var r="";e>0;)e&1&&(r+=t),e>>>=1,e>0&&(t+=t);return r};v.xorBytes=function(t,e,r){for(var n="",i="",o="",s=0,a=0;r>0;--r,++s)i=t.charCodeAt(s)^e.charCodeAt(s),a>=10&&(n+=o,o="",a=0),o+=String.fromCharCode(i),++a;return n+=o,n};v.hexToBytes=function(t){var e="",r=0;for(t.length&!0&&(r=1,e+=String.fromCharCode(parseInt(t[0],16)));r<t.length;r+=2)e+=String.fromCharCode(parseInt(t.substr(r,2),16));return e};v.bytesToHex=function(t){return v.createBuffer(t).toHex()};v.int32ToBytes=function(t){return String.fromCharCode(t>>24&255)+String.fromCharCode(t>>16&255)+String.fromCharCode(t>>8&255)+String.fromCharCode(t&255)};var ji="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",Qi=[62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,64,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51],KS="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";v.encode64=function(t,e){for(var r="",n="",i,o,s,a=0;a<t.length;)i=t.charCodeAt(a++),o=t.charCodeAt(a++),s=t.charCodeAt(a++),r+=ji.charAt(i>>2),r+=ji.charAt((i&3)<<4|o>>4),isNaN(o)?r+="==":(r+=ji.charAt((o&15)<<2|s>>6),r+=isNaN(s)?"=":ji.charAt(s&63)),e&&r.length>e&&(n+=r.substr(0,e)+`\r
|
|
4
|
+
`,r=r.substr(e));return n+=r,n};v.decode64=function(t){t=t.replace(/[^A-Za-z0-9\+\/\=]/g,"");for(var e="",r,n,i,o,s=0;s<t.length;)r=Qi[t.charCodeAt(s++)-43],n=Qi[t.charCodeAt(s++)-43],i=Qi[t.charCodeAt(s++)-43],o=Qi[t.charCodeAt(s++)-43],e+=String.fromCharCode(r<<2|n>>4),i!==64&&(e+=String.fromCharCode((n&15)<<4|i>>2),o!==64&&(e+=String.fromCharCode((i&3)<<6|o)));return e};v.encodeUtf8=function(t){return unescape(encodeURIComponent(t))};v.decodeUtf8=function(t){return decodeURIComponent(escape(t))};v.binary={raw:{},hex:{},base64:{},base58:{},baseN:{encode:US.encode,decode:US.decode}};v.binary.raw.encode=function(t){return String.fromCharCode.apply(null,t)};v.binary.raw.decode=function(t,e,r){var n=e;n||(n=new Uint8Array(t.length)),r=r||0;for(var i=r,o=0;o<t.length;++o)n[i++]=t.charCodeAt(o);return e?i-r:n};v.binary.hex.encode=v.bytesToHex;v.binary.hex.decode=function(t,e,r){var n=e;n||(n=new Uint8Array(Math.ceil(t.length/2))),r=r||0;var i=0,o=r;for(t.length&1&&(i=1,n[o++]=parseInt(t[0],16));i<t.length;i+=2)n[o++]=parseInt(t.substr(i,2),16);return e?o-r:n};v.binary.base64.encode=function(t,e){for(var r="",n="",i,o,s,a=0;a<t.byteLength;)i=t[a++],o=t[a++],s=t[a++],r+=ji.charAt(i>>2),r+=ji.charAt((i&3)<<4|o>>4),isNaN(o)?r+="==":(r+=ji.charAt((o&15)<<2|s>>6),r+=isNaN(s)?"=":ji.charAt(s&63)),e&&r.length>e&&(n+=r.substr(0,e)+`\r
|
|
5
|
+
`,r=r.substr(e));return n+=r,n};v.binary.base64.decode=function(t,e,r){var n=e;n||(n=new Uint8Array(Math.ceil(t.length/4)*3)),t=t.replace(/[^A-Za-z0-9\+\/\=]/g,""),r=r||0;for(var i,o,s,a,c=0,u=r;c<t.length;)i=Qi[t.charCodeAt(c++)-43],o=Qi[t.charCodeAt(c++)-43],s=Qi[t.charCodeAt(c++)-43],a=Qi[t.charCodeAt(c++)-43],n[u++]=i<<2|o>>4,s!==64&&(n[u++]=(o&15)<<4|s>>2,a!==64&&(n[u++]=(s&3)<<6|a));return e?u-r:n.subarray(0,u)};v.binary.base58.encode=function(t,e){return v.binary.baseN.encode(t,KS,e)};v.binary.base58.decode=function(t,e){return v.binary.baseN.decode(t,KS,e)};v.text={utf8:{},utf16:{}};v.text.utf8.encode=function(t,e,r){t=v.encodeUtf8(t);var n=e;n||(n=new Uint8Array(t.length)),r=r||0;for(var i=r,o=0;o<t.length;++o)n[i++]=t.charCodeAt(o);return e?i-r:n};v.text.utf8.decode=function(t){return v.decodeUtf8(String.fromCharCode.apply(null,t))};v.text.utf16.encode=function(t,e,r){var n=e;n||(n=new Uint8Array(t.length*2));var i=new Uint16Array(n.buffer);r=r||0;for(var o=r,s=r,a=0;a<t.length;++a)i[s++]=t.charCodeAt(a),o+=2;return e?o-r:n};v.text.utf16.decode=function(t){return String.fromCharCode.apply(null,new Uint16Array(t.buffer))};v.deflate=function(t,e,r){if(e=v.decode64(t.deflate(v.encode64(e)).rval),r){var n=2,i=e.charCodeAt(1);i&32&&(n=6),e=e.substring(n,e.length-4)}return e};v.inflate=function(t,e,r){var n=t.inflate(v.encode64(e)).rval;return n===null?null:v.decode64(n)};var Yy=function(t,e,r){if(!t)throw new Error("WebStorage not available.");var n;if(r===null?n=t.removeItem(e):(r=v.encode64(JSON.stringify(r)),n=t.setItem(e,r)),typeof n<"u"&&n.rval!==!0){var i=new Error(n.error.message);throw i.id=n.error.id,i.name=n.error.name,i}},jy=function(t,e){if(!t)throw new Error("WebStorage not available.");var r=t.getItem(e);if(t.init)if(r.rval===null){if(r.error){var n=new Error(r.error.message);throw n.id=r.error.id,n.name=r.error.name,n}r=null}else r=r.rval;return r!==null&&(r=JSON.parse(v.decode64(r))),r},XD=function(t,e,r,n){var i=jy(t,e);i===null&&(i={}),i[r]=n,Yy(t,e,i)},ZD=function(t,e,r){var n=jy(t,e);return n!==null&&(n=r in n?n[r]:null),n},e5=function(t,e,r){var n=jy(t,e);if(n!==null&&r in n){delete n[r];var i=!0;for(var o in n){i=!1;break}i&&(n=null),Yy(t,e,n)}},t5=function(t,e){Yy(t,e,null)},Mh=function(t,e,r){var n=null;typeof r>"u"&&(r=["web","flash"]);var i,o=!1,s=null;for(var a in r){i=r[a];try{if(i==="flash"||i==="both"){if(e[0]===null)throw new Error("Flash local storage not available.");n=t.apply(this,e),o=i==="flash"}(i==="web"||i==="both")&&(e[0]=localStorage,n=t.apply(this,e),o=!0)}catch(c){s=c}if(o)break}if(!o)throw s;return n};v.setItem=function(t,e,r,n,i){Mh(XD,arguments,i)};v.getItem=function(t,e,r,n){return Mh(ZD,arguments,n)};v.removeItem=function(t,e,r,n){Mh(e5,arguments,n)};v.clearItems=function(t,e,r){Mh(t5,arguments,r)};v.isEmpty=function(t){for(var e in t)if(t.hasOwnProperty(e))return!1;return!0};v.format=function(t){for(var e=/%./g,r,n,i=0,o=[],s=0;r=e.exec(t);){n=t.substring(s,e.lastIndex-2),n.length>0&&o.push(n),s=e.lastIndex;var a=r[0][1];switch(a){case"s":case"o":i<arguments.length?o.push(arguments[i+++1]):o.push("<?>");break;case"%":o.push("%");break;default:o.push("<%"+a+"?>")}}return o.push(t.substring(s)),o.join("")};v.formatNumber=function(t,e,r,n){var i=t,o=isNaN(e=Math.abs(e))?2:e,s=r===void 0?",":r,a=n===void 0?".":n,c=i<0?"-":"",u=parseInt(i=Math.abs(+i||0).toFixed(o),10)+"",l=u.length>3?u.length%3:0;return c+(l?u.substr(0,l)+a:"")+u.substr(l).replace(/(\d{3})(?=\d)/g,"$1"+a)+(o?s+Math.abs(i-u).toFixed(o).slice(2):"")};v.formatSize=function(t){return t>=1073741824?t=v.formatNumber(t/1073741824,2,".","")+" GiB":t>=1048576?t=v.formatNumber(t/1048576,2,".","")+" MiB":t>=1024?t=v.formatNumber(t/1024,0)+" KiB":t=v.formatNumber(t,0)+" bytes",t};v.bytesFromIP=function(t){return t.indexOf(".")!==-1?v.bytesFromIPv4(t):t.indexOf(":")!==-1?v.bytesFromIPv6(t):null};v.bytesFromIPv4=function(t){if(t=t.split("."),t.length!==4)return null;for(var e=v.createBuffer(),r=0;r<t.length;++r){var n=parseInt(t[r],10);if(isNaN(n))return null;e.putByte(n)}return e.getBytes()};v.bytesFromIPv6=function(t){var e=0;t=t.split(":").filter(function(s){return s.length===0&&++e,!0});for(var r=(8-t.length+e)*2,n=v.createBuffer(),i=0;i<8;++i){if(!t[i]||t[i].length===0){n.fillWithByte(0,r),r=0;continue}var o=v.hexToBytes(t[i]);o.length<2&&n.putByte(0),n.putBytes(o)}return n.getBytes()};v.bytesToIP=function(t){return t.length===4?v.bytesToIPv4(t):t.length===16?v.bytesToIPv6(t):null};v.bytesToIPv4=function(t){if(t.length!==4)return null;for(var e=[],r=0;r<t.length;++r)e.push(t.charCodeAt(r));return e.join(".")};v.bytesToIPv6=function(t){if(t.length!==16)return null;for(var e=[],r=[],n=0,i=0;i<t.length;i+=2){for(var o=v.bytesToHex(t[i]+t[i+1]);o[0]==="0"&&o!=="0";)o=o.substr(1);if(o==="0"){var s=r[r.length-1],a=e.length;!s||a!==s.end+1?r.push({start:a,end:a}):(s.end=a,s.end-s.start>r[n].end-r[n].start&&(n=r.length-1))}e.push(o)}if(r.length>0){var c=r[n];c.end-c.start>0&&(e.splice(c.start,c.end-c.start+1,""),c.start===0&&e.unshift(""),c.end===7&&e.push(""))}return e.join(":")};v.estimateCores=function(t,e){if(typeof t=="function"&&(e=t,t={}),t=t||{},"cores"in v&&!t.update)return e(null,v.cores);if(typeof navigator<"u"&&"hardwareConcurrency"in navigator&&navigator.hardwareConcurrency>0)return v.cores=navigator.hardwareConcurrency,e(null,v.cores);if(typeof Worker>"u")return v.cores=1,e(null,v.cores);if(typeof Blob>"u")return v.cores=2,e(null,v.cores);var r=URL.createObjectURL(new Blob(["(",function(){self.addEventListener("message",function(s){for(var a=Date.now(),c=a+4;Date.now()<c;);self.postMessage({st:a,et:c})})}.toString(),")()"],{type:"application/javascript"}));n([],5,16);function n(s,a,c){if(a===0){var u=Math.floor(s.reduce(function(l,f){return l+f},0)/s.length);return v.cores=Math.max(1,u),URL.revokeObjectURL(r),e(null,v.cores)}i(c,function(l,f){s.push(o(c,f)),n(s,a-1,c)})}function i(s,a){for(var c=[],u=[],l=0;l<s;++l){var f=new Worker(r);f.addEventListener("message",function(d){if(u.push(d.data),u.length===s){for(var p=0;p<s;++p)c[p].terminate();a(null,u)}}),c.push(f)}for(var l=0;l<s;++l)c[l].postMessage(l)}function o(s,a){for(var c=[],u=0;u<s;++u)for(var l=a[u],f=c[u]=[],d=0;d<s;++d)if(u!==d){var p=a[d];(l.st>p.st&&l.st<p.et||p.st>l.st&&p.st<l.et)&&f.push(d)}return c.reduce(function(h,m){return Math.max(h,m.length)},0)}}});var Fh=re((gse,FS)=>{var nu=Le();nu.pki=nu.pki||{};var Qy=FS.exports=nu.pki.oids=nu.oids=nu.oids||{};function O(t,e){Qy[t]=e,Qy[e]=t}function Be(t,e){Qy[t]=e}O("1.2.840.113549.1.1.1","rsaEncryption");O("1.2.840.113549.1.1.4","md5WithRSAEncryption");O("1.2.840.113549.1.1.5","sha1WithRSAEncryption");O("1.2.840.113549.1.1.7","RSAES-OAEP");O("1.2.840.113549.1.1.8","mgf1");O("1.2.840.113549.1.1.9","pSpecified");O("1.2.840.113549.1.1.10","RSASSA-PSS");O("1.2.840.113549.1.1.11","sha256WithRSAEncryption");O("1.2.840.113549.1.1.12","sha384WithRSAEncryption");O("1.2.840.113549.1.1.13","sha512WithRSAEncryption");O("1.3.101.112","EdDSA25519");O("1.2.840.10040.4.3","dsa-with-sha1");O("1.3.14.3.2.7","desCBC");O("1.3.14.3.2.26","sha1");O("1.3.14.3.2.29","sha1WithRSASignature");O("2.16.840.1.101.3.4.2.1","sha256");O("2.16.840.1.101.3.4.2.2","sha384");O("2.16.840.1.101.3.4.2.3","sha512");O("2.16.840.1.101.3.4.2.4","sha224");O("2.16.840.1.101.3.4.2.5","sha512-224");O("2.16.840.1.101.3.4.2.6","sha512-256");O("1.2.840.113549.2.2","md2");O("1.2.840.113549.2.5","md5");O("1.2.840.113549.1.7.1","data");O("1.2.840.113549.1.7.2","signedData");O("1.2.840.113549.1.7.3","envelopedData");O("1.2.840.113549.1.7.4","signedAndEnvelopedData");O("1.2.840.113549.1.7.5","digestedData");O("1.2.840.113549.1.7.6","encryptedData");O("1.2.840.113549.1.9.1","emailAddress");O("1.2.840.113549.1.9.2","unstructuredName");O("1.2.840.113549.1.9.3","contentType");O("1.2.840.113549.1.9.4","messageDigest");O("1.2.840.113549.1.9.5","signingTime");O("1.2.840.113549.1.9.6","counterSignature");O("1.2.840.113549.1.9.7","challengePassword");O("1.2.840.113549.1.9.8","unstructuredAddress");O("1.2.840.113549.1.9.14","extensionRequest");O("1.2.840.113549.1.9.20","friendlyName");O("1.2.840.113549.1.9.21","localKeyId");O("1.2.840.113549.1.9.22.1","x509Certificate");O("1.2.840.113549.1.12.10.1.1","keyBag");O("1.2.840.113549.1.12.10.1.2","pkcs8ShroudedKeyBag");O("1.2.840.113549.1.12.10.1.3","certBag");O("1.2.840.113549.1.12.10.1.4","crlBag");O("1.2.840.113549.1.12.10.1.5","secretBag");O("1.2.840.113549.1.12.10.1.6","safeContentsBag");O("1.2.840.113549.1.5.13","pkcs5PBES2");O("1.2.840.113549.1.5.12","pkcs5PBKDF2");O("1.2.840.113549.1.12.1.1","pbeWithSHAAnd128BitRC4");O("1.2.840.113549.1.12.1.2","pbeWithSHAAnd40BitRC4");O("1.2.840.113549.1.12.1.3","pbeWithSHAAnd3-KeyTripleDES-CBC");O("1.2.840.113549.1.12.1.4","pbeWithSHAAnd2-KeyTripleDES-CBC");O("1.2.840.113549.1.12.1.5","pbeWithSHAAnd128BitRC2-CBC");O("1.2.840.113549.1.12.1.6","pbewithSHAAnd40BitRC2-CBC");O("1.2.840.113549.2.7","hmacWithSHA1");O("1.2.840.113549.2.8","hmacWithSHA224");O("1.2.840.113549.2.9","hmacWithSHA256");O("1.2.840.113549.2.10","hmacWithSHA384");O("1.2.840.113549.2.11","hmacWithSHA512");O("1.2.840.113549.3.7","des-EDE3-CBC");O("2.16.840.1.101.3.4.1.2","aes128-CBC");O("2.16.840.1.101.3.4.1.22","aes192-CBC");O("2.16.840.1.101.3.4.1.42","aes256-CBC");O("2.5.4.3","commonName");O("2.5.4.4","surname");O("2.5.4.5","serialNumber");O("2.5.4.6","countryName");O("2.5.4.7","localityName");O("2.5.4.8","stateOrProvinceName");O("2.5.4.9","streetAddress");O("2.5.4.10","organizationName");O("2.5.4.11","organizationalUnitName");O("2.5.4.12","title");O("2.5.4.13","description");O("2.5.4.15","businessCategory");O("2.5.4.17","postalCode");O("2.5.4.42","givenName");O("1.3.6.1.4.1.311.60.2.1.2","jurisdictionOfIncorporationStateOrProvinceName");O("1.3.6.1.4.1.311.60.2.1.3","jurisdictionOfIncorporationCountryName");O("2.16.840.1.113730.1.1","nsCertType");O("2.16.840.1.113730.1.13","nsComment");Be("2.5.29.1","authorityKeyIdentifier");Be("2.5.29.2","keyAttributes");Be("2.5.29.3","certificatePolicies");Be("2.5.29.4","keyUsageRestriction");Be("2.5.29.5","policyMapping");Be("2.5.29.6","subtreesConstraint");Be("2.5.29.7","subjectAltName");Be("2.5.29.8","issuerAltName");Be("2.5.29.9","subjectDirectoryAttributes");Be("2.5.29.10","basicConstraints");Be("2.5.29.11","nameConstraints");Be("2.5.29.12","policyConstraints");Be("2.5.29.13","basicConstraints");O("2.5.29.14","subjectKeyIdentifier");O("2.5.29.15","keyUsage");Be("2.5.29.16","privateKeyUsagePeriod");O("2.5.29.17","subjectAltName");O("2.5.29.18","issuerAltName");O("2.5.29.19","basicConstraints");Be("2.5.29.20","cRLNumber");Be("2.5.29.21","cRLReason");Be("2.5.29.22","expirationDate");Be("2.5.29.23","instructionCode");Be("2.5.29.24","invalidityDate");Be("2.5.29.25","cRLDistributionPoints");Be("2.5.29.26","issuingDistributionPoint");Be("2.5.29.27","deltaCRLIndicator");Be("2.5.29.28","issuingDistributionPoint");Be("2.5.29.29","certificateIssuer");Be("2.5.29.30","nameConstraints");O("2.5.29.31","cRLDistributionPoints");O("2.5.29.32","certificatePolicies");Be("2.5.29.33","policyMappings");Be("2.5.29.34","policyConstraints");O("2.5.29.35","authorityKeyIdentifier");Be("2.5.29.36","policyConstraints");O("2.5.29.37","extKeyUsage");Be("2.5.29.46","freshestCRL");Be("2.5.29.54","inhibitAnyPolicy");O("1.3.6.1.4.1.11129.2.4.2","timestampList");O("1.3.6.1.5.5.7.1.1","authorityInfoAccess");O("1.3.6.1.5.5.7.3.1","serverAuth");O("1.3.6.1.5.5.7.3.2","clientAuth");O("1.3.6.1.5.5.7.3.3","codeSigning");O("1.3.6.1.5.5.7.3.4","emailProtection");O("1.3.6.1.5.5.7.3.8","timeStamping")});var ou=re((bse,HS)=>{var He=Le();ft();Fh();var q=HS.exports=He.asn1=He.asn1||{};q.Class={UNIVERSAL:0,APPLICATION:64,CONTEXT_SPECIFIC:128,PRIVATE:192};q.Type={NONE:0,BOOLEAN:1,INTEGER:2,BITSTRING:3,OCTETSTRING:4,NULL:5,OID:6,ODESC:7,EXTERNAL:8,REAL:9,ENUMERATED:10,EMBEDDED:11,UTF8:12,ROID:13,SEQUENCE:16,SET:17,PRINTABLESTRING:19,IA5STRING:22,UTCTIME:23,GENERALIZEDTIME:24,BMPSTRING:30};q.create=function(t,e,r,n,i){if(He.util.isArray(n)){for(var o=[],s=0;s<n.length;++s)n[s]!==void 0&&o.push(n[s]);n=o}var a={tagClass:t,type:e,constructed:r,composed:r||He.util.isArray(n),value:n};return i&&"bitStringContents"in i&&(a.bitStringContents=i.bitStringContents,a.original=q.copy(a)),a};q.copy=function(t,e){var r;if(He.util.isArray(t)){r=[];for(var n=0;n<t.length;++n)r.push(q.copy(t[n],e));return r}return typeof t=="string"?t:(r={tagClass:t.tagClass,type:t.type,constructed:t.constructed,composed:t.composed,value:q.copy(t.value,e)},e&&!e.excludeBitStringContents&&(r.bitStringContents=t.bitStringContents),r)};q.equals=function(t,e,r){if(He.util.isArray(t)){if(!He.util.isArray(e)||t.length!==e.length)return!1;for(var n=0;n<t.length;++n)if(!q.equals(t[n],e[n]))return!1;return!0}if(typeof t!=typeof e)return!1;if(typeof t=="string")return t===e;var i=t.tagClass===e.tagClass&&t.type===e.type&&t.constructed===e.constructed&&t.composed===e.composed&&q.equals(t.value,e.value);return r&&r.includeBitStringContents&&(i=i&&t.bitStringContents===e.bitStringContents),i};q.getBerValueLength=function(t){var e=t.getByte();if(e!==128){var r,n=e&128;return n?r=t.getInt((e&127)<<3):r=e,r}};function iu(t,e,r){if(r>e){var n=new Error("Too few bytes to parse DER.");throw n.available=t.length(),n.remaining=e,n.requested=r,n}}var r5=function(t,e){var r=t.getByte();if(e--,r!==128){var n,i=r&128;if(!i)n=r;else{var o=r&127;iu(t,e,o),n=t.getInt(o<<3)}if(n<0)throw new Error("Negative length: "+n);return n}};q.fromDer=function(t,e){e===void 0&&(e={strict:!0,parseAllBytes:!0,decodeBitStrings:!0}),typeof e=="boolean"&&(e={strict:e,parseAllBytes:!0,decodeBitStrings:!0}),"strict"in e||(e.strict=!0),"parseAllBytes"in e||(e.parseAllBytes=!0),"decodeBitStrings"in e||(e.decodeBitStrings=!0),typeof t=="string"&&(t=He.util.createBuffer(t));var r=t.length(),n=Vh(t,t.length(),0,e);if(e.parseAllBytes&&t.length()!==0){var i=new Error("Unparsed DER bytes remain after ASN.1 parsing.");throw i.byteCount=r,i.remaining=t.length(),i}return n};function Vh(t,e,r,n){var i;iu(t,e,2);var o=t.getByte();e--;var s=o&192,a=o&31;i=t.length();var c=r5(t,e);if(e-=i-t.length(),c!==void 0&&c>e){if(n.strict){var u=new Error("Too few bytes to read ASN.1 value.");throw u.available=t.length(),u.remaining=e,u.requested=c,u}c=e}var l,f,d=(o&32)===32;if(d)if(l=[],c===void 0)for(;;){if(iu(t,e,2),t.bytes(2)==="\0\0"){t.getBytes(2),e-=2;break}i=t.length(),l.push(Vh(t,e,r+1,n)),e-=i-t.length()}else for(;c>0;)i=t.length(),l.push(Vh(t,c,r+1,n)),e-=i-t.length(),c-=i-t.length();if(l===void 0&&s===q.Class.UNIVERSAL&&a===q.Type.BITSTRING&&(f=t.bytes(c)),l===void 0&&n.decodeBitStrings&&s===q.Class.UNIVERSAL&&a===q.Type.BITSTRING&&c>1){var p=t.read,h=e,m=0;if(a===q.Type.BITSTRING&&(iu(t,e,1),m=t.getByte(),e--),m===0)try{i=t.length();var y={strict:!0,decodeBitStrings:!0},g=Vh(t,e,r+1,y),b=i-t.length();e-=b,a==q.Type.BITSTRING&&b++;var w=g.tagClass;b===c&&(w===q.Class.UNIVERSAL||w===q.Class.CONTEXT_SPECIFIC)&&(l=[g])}catch{}l===void 0&&(t.read=p,e=h)}if(l===void 0){if(c===void 0){if(n.strict)throw new Error("Non-constructed ASN.1 object of indefinite length.");c=e}if(a===q.Type.BMPSTRING)for(l="";c>0;c-=2)iu(t,e,2),l+=String.fromCharCode(t.getInt16()),e-=2;else l=t.getBytes(c),e-=c}var _=f===void 0?null:{bitStringContents:f};return q.create(s,a,d,l,_)}q.toDer=function(t){var e=He.util.createBuffer(),r=t.tagClass|t.type,n=He.util.createBuffer(),i=!1;if("bitStringContents"in t&&(i=!0,t.original&&(i=q.equals(t,t.original))),i)n.putBytes(t.bitStringContents);else if(t.composed){t.constructed?r|=32:n.putByte(0);for(var o=0;o<t.value.length;++o)t.value[o]!==void 0&&n.putBuffer(q.toDer(t.value[o]))}else if(t.type===q.Type.BMPSTRING)for(var o=0;o<t.value.length;++o)n.putInt16(t.value.charCodeAt(o));else t.type===q.Type.INTEGER&&t.value.length>1&&(t.value.charCodeAt(0)===0&&!(t.value.charCodeAt(1)&128)||t.value.charCodeAt(0)===255&&(t.value.charCodeAt(1)&128)===128)?n.putBytes(t.value.substr(1)):n.putBytes(t.value);if(e.putByte(r),n.length()<=127)e.putByte(n.length()&127);else{var s=n.length(),a="";do a+=String.fromCharCode(s&255),s=s>>>8;while(s>0);e.putByte(a.length|128);for(var o=a.length-1;o>=0;--o)e.putByte(a.charCodeAt(o))}return e.putBuffer(n),e};q.oidToDer=function(t){var e=t.split("."),r=He.util.createBuffer();r.putByte(40*parseInt(e[0],10)+parseInt(e[1],10));for(var n,i,o,s,a=2;a<e.length;++a){n=!0,i=[],o=parseInt(e[a],10);do s=o&127,o=o>>>7,n||(s|=128),i.push(s),n=!1;while(o>0);for(var c=i.length-1;c>=0;--c)r.putByte(i[c])}return r};q.derToOid=function(t){var e;typeof t=="string"&&(t=He.util.createBuffer(t));var r=t.getByte();e=Math.floor(r/40)+"."+r%40;for(var n=0;t.length()>0;)r=t.getByte(),n=n<<7,r&128?n+=r&127:(e+="."+(n+r),n=0);return e};q.utcTimeToDate=function(t){var e=new Date,r=parseInt(t.substr(0,2),10);r=r>=50?1900+r:2e3+r;var n=parseInt(t.substr(2,2),10)-1,i=parseInt(t.substr(4,2),10),o=parseInt(t.substr(6,2),10),s=parseInt(t.substr(8,2),10),a=0;if(t.length>11){var c=t.charAt(10),u=10;c!=="+"&&c!=="-"&&(a=parseInt(t.substr(10,2),10),u+=2)}if(e.setUTCFullYear(r,n,i),e.setUTCHours(o,s,a,0),u&&(c=t.charAt(u),c==="+"||c==="-")){var l=parseInt(t.substr(u+1,2),10),f=parseInt(t.substr(u+4,2),10),d=l*60+f;d*=6e4,c==="+"?e.setTime(+e-d):e.setTime(+e+d)}return e};q.generalizedTimeToDate=function(t){var e=new Date,r=parseInt(t.substr(0,4),10),n=parseInt(t.substr(4,2),10)-1,i=parseInt(t.substr(6,2),10),o=parseInt(t.substr(8,2),10),s=parseInt(t.substr(10,2),10),a=parseInt(t.substr(12,2),10),c=0,u=0,l=!1;t.charAt(t.length-1)==="Z"&&(l=!0);var f=t.length-5,d=t.charAt(f);if(d==="+"||d==="-"){var p=parseInt(t.substr(f+1,2),10),h=parseInt(t.substr(f+4,2),10);u=p*60+h,u*=6e4,d==="+"&&(u*=-1),l=!0}return t.charAt(14)==="."&&(c=parseFloat(t.substr(14),10)*1e3),l?(e.setUTCFullYear(r,n,i),e.setUTCHours(o,s,a,c),e.setTime(+e+u)):(e.setFullYear(r,n,i),e.setHours(o,s,a,c)),e};q.dateToUtcTime=function(t){if(typeof t=="string")return t;var e="",r=[];r.push((""+t.getUTCFullYear()).substr(2)),r.push(""+(t.getUTCMonth()+1)),r.push(""+t.getUTCDate()),r.push(""+t.getUTCHours()),r.push(""+t.getUTCMinutes()),r.push(""+t.getUTCSeconds());for(var n=0;n<r.length;++n)r[n].length<2&&(e+="0"),e+=r[n];return e+="Z",e};q.dateToGeneralizedTime=function(t){if(typeof t=="string")return t;var e="",r=[];r.push(""+t.getUTCFullYear()),r.push(""+(t.getUTCMonth()+1)),r.push(""+t.getUTCDate()),r.push(""+t.getUTCHours()),r.push(""+t.getUTCMinutes()),r.push(""+t.getUTCSeconds());for(var n=0;n<r.length;++n)r[n].length<2&&(e+="0"),e+=r[n];return e+="Z",e};q.integerToDer=function(t){var e=He.util.createBuffer();if(t>=-128&&t<128)return e.putSignedInt(t,8);if(t>=-32768&&t<32768)return e.putSignedInt(t,16);if(t>=-8388608&&t<8388608)return e.putSignedInt(t,24);if(t>=-2147483648&&t<2147483648)return e.putSignedInt(t,32);var r=new Error("Integer too large; max is 32-bits.");throw r.integer=t,r};q.derToInteger=function(t){typeof t=="string"&&(t=He.util.createBuffer(t));var e=t.length()*8;if(e>32)throw new Error("Integer too large; max is 32-bits.");return t.getSignedInt(e)};q.validate=function(t,e,r,n){var i=!1;if((t.tagClass===e.tagClass||typeof e.tagClass>"u")&&(t.type===e.type||typeof e.type>"u"))if(t.constructed===e.constructed||typeof e.constructed>"u"){if(i=!0,e.value&&He.util.isArray(e.value))for(var o=0,s=0;i&&s<e.value.length;++s)i=e.value[s].optional||!1,t.value[o]&&(i=q.validate(t.value[o],e.value[s],r,n),i?++o:e.value[s].optional&&(i=!0)),!i&&n&&n.push("["+e.name+'] Tag class "'+e.tagClass+'", type "'+e.type+'" expected value length "'+e.value.length+'", got "'+t.value.length+'"');if(i&&r&&(e.capture&&(r[e.capture]=t.value),e.captureAsn1&&(r[e.captureAsn1]=t),e.captureBitStringContents&&"bitStringContents"in t&&(r[e.captureBitStringContents]=t.bitStringContents),e.captureBitStringValue&&"bitStringContents"in t)){var a;if(t.bitStringContents.length<2)r[e.captureBitStringValue]="";else{var c=t.bitStringContents.charCodeAt(0);if(c!==0)throw new Error("captureBitStringValue only supported for zero unused bits");r[e.captureBitStringValue]=t.bitStringContents.slice(1)}}}else n&&n.push("["+e.name+'] Expected constructed "'+e.constructed+'", got "'+t.constructed+'"');else n&&(t.tagClass!==e.tagClass&&n.push("["+e.name+'] Expected tag class "'+e.tagClass+'", got "'+t.tagClass+'"'),t.type!==e.type&&n.push("["+e.name+'] Expected type "'+e.type+'", got "'+t.type+'"'));return i};var VS=/[^\\u0000-\\u00ff]/;q.prettyPrint=function(t,e,r){var n="";e=e||0,r=r||2,e>0&&(n+=`
|
|
6
|
+
`);for(var i="",o=0;o<e*r;++o)i+=" ";switch(n+=i+"Tag: ",t.tagClass){case q.Class.UNIVERSAL:n+="Universal:";break;case q.Class.APPLICATION:n+="Application:";break;case q.Class.CONTEXT_SPECIFIC:n+="Context-Specific:";break;case q.Class.PRIVATE:n+="Private:";break}if(t.tagClass===q.Class.UNIVERSAL)switch(n+=t.type,t.type){case q.Type.NONE:n+=" (None)";break;case q.Type.BOOLEAN:n+=" (Boolean)";break;case q.Type.INTEGER:n+=" (Integer)";break;case q.Type.BITSTRING:n+=" (Bit string)";break;case q.Type.OCTETSTRING:n+=" (Octet string)";break;case q.Type.NULL:n+=" (Null)";break;case q.Type.OID:n+=" (Object Identifier)";break;case q.Type.ODESC:n+=" (Object Descriptor)";break;case q.Type.EXTERNAL:n+=" (External or Instance of)";break;case q.Type.REAL:n+=" (Real)";break;case q.Type.ENUMERATED:n+=" (Enumerated)";break;case q.Type.EMBEDDED:n+=" (Embedded PDV)";break;case q.Type.UTF8:n+=" (UTF8)";break;case q.Type.ROID:n+=" (Relative Object Identifier)";break;case q.Type.SEQUENCE:n+=" (Sequence)";break;case q.Type.SET:n+=" (Set)";break;case q.Type.PRINTABLESTRING:n+=" (Printable String)";break;case q.Type.IA5String:n+=" (IA5String (ASCII))";break;case q.Type.UTCTIME:n+=" (UTC time)";break;case q.Type.GENERALIZEDTIME:n+=" (Generalized time)";break;case q.Type.BMPSTRING:n+=" (BMP String)";break}else n+=t.type;if(n+=`
|
|
7
|
+
`,n+=i+"Constructed: "+t.constructed+`
|
|
8
|
+
`,t.composed){for(var s=0,a="",o=0;o<t.value.length;++o)t.value[o]!==void 0&&(s+=1,a+=q.prettyPrint(t.value[o],e+1,r),o+1<t.value.length&&(a+=","));n+=i+"Sub values: "+s+a}else{if(n+=i+"Value: ",t.type===q.Type.OID){var c=q.derToOid(t.value);n+=c,He.pki&&He.pki.oids&&c in He.pki.oids&&(n+=" ("+He.pki.oids[c]+") ")}if(t.type===q.Type.INTEGER)try{n+=q.derToInteger(t.value)}catch{n+="0x"+He.util.bytesToHex(t.value)}else if(t.type===q.Type.BITSTRING){if(t.value.length>1?n+="0x"+He.util.bytesToHex(t.value.slice(1)):n+="(none)",t.value.length>0){var u=t.value.charCodeAt(0);u==1?n+=" (1 unused bit shown)":u>1&&(n+=" ("+u+" unused bits shown)")}}else if(t.type===q.Type.OCTETSTRING)VS.test(t.value)||(n+="("+t.value+") "),n+="0x"+He.util.bytesToHex(t.value);else if(t.type===q.Type.UTF8)try{n+=He.util.decodeUtf8(t.value)}catch(l){if(l.message==="URI malformed")n+="0x"+He.util.bytesToHex(t.value)+" (malformed UTF8)";else throw l}else t.type===q.Type.PRINTABLESTRING||t.type===q.Type.IA5String?n+=t.value:VS.test(t.value)?n+="0x"+He.util.bytesToHex(t.value):t.value.length===0?n+="[null]":n+=t.value}return n}});var Xy=re((wse,qS)=>{var Et=Le();ft();qS.exports=Et.cipher=Et.cipher||{};Et.cipher.algorithms=Et.cipher.algorithms||{};Et.cipher.createCipher=function(t,e){var r=t;if(typeof r=="string"&&(r=Et.cipher.getAlgorithm(r),r&&(r=r())),!r)throw new Error("Unsupported algorithm: "+t);return new Et.cipher.BlockCipher({algorithm:r,key:e,decrypt:!1})};Et.cipher.createDecipher=function(t,e){var r=t;if(typeof r=="string"&&(r=Et.cipher.getAlgorithm(r),r&&(r=r())),!r)throw new Error("Unsupported algorithm: "+t);return new Et.cipher.BlockCipher({algorithm:r,key:e,decrypt:!0})};Et.cipher.registerAlgorithm=function(t,e){t=t.toUpperCase(),Et.cipher.algorithms[t]=e};Et.cipher.getAlgorithm=function(t){return t=t.toUpperCase(),t in Et.cipher.algorithms?Et.cipher.algorithms[t]:null};var Jy=Et.cipher.BlockCipher=function(t){this.algorithm=t.algorithm,this.mode=this.algorithm.mode,this.blockSize=this.mode.blockSize,this._finish=!1,this._input=null,this.output=null,this._op=t.decrypt?this.mode.decrypt:this.mode.encrypt,this._decrypt=t.decrypt,this.algorithm.initialize(t)};Jy.prototype.start=function(t){t=t||{};var e={};for(var r in t)e[r]=t[r];e.decrypt=this._decrypt,this._finish=!1,this._input=Et.util.createBuffer(),this.output=t.output||Et.util.createBuffer(),this.mode.start(e)};Jy.prototype.update=function(t){for(t&&this._input.putBuffer(t);!this._op.call(this.mode,this._input,this.output,this._finish)&&!this._finish;);this._input.compact()};Jy.prototype.finish=function(t){t&&(this.mode.name==="ECB"||this.mode.name==="CBC")&&(this.mode.pad=function(r){return t(this.blockSize,r,!1)},this.mode.unpad=function(r){return t(this.blockSize,r,!0)});var e={};return e.decrypt=this._decrypt,e.overflow=this._input.length()%this.blockSize,!(!this._decrypt&&this.mode.pad&&!this.mode.pad(this._input,e)||(this._finish=!0,this.update(),this._decrypt&&this.mode.unpad&&!this.mode.unpad(this.output,e))||this.mode.afterFinish&&!this.mode.afterFinish(this.output,e))}});var eg=re((xse,$S)=>{var At=Le();ft();At.cipher=At.cipher||{};var ye=$S.exports=At.cipher.modes=At.cipher.modes||{};ye.ecb=function(t){t=t||{},this.name="ECB",this.cipher=t.cipher,this.blockSize=t.blockSize||16,this._ints=this.blockSize/4,this._inBlock=new Array(this._ints),this._outBlock=new Array(this._ints)};ye.ecb.prototype.start=function(t){};ye.ecb.prototype.encrypt=function(t,e,r){if(t.length()<this.blockSize&&!(r&&t.length()>0))return!0;for(var n=0;n<this._ints;++n)this._inBlock[n]=t.getInt32();this.cipher.encrypt(this._inBlock,this._outBlock);for(var n=0;n<this._ints;++n)e.putInt32(this._outBlock[n])};ye.ecb.prototype.decrypt=function(t,e,r){if(t.length()<this.blockSize&&!(r&&t.length()>0))return!0;for(var n=0;n<this._ints;++n)this._inBlock[n]=t.getInt32();this.cipher.decrypt(this._inBlock,this._outBlock);for(var n=0;n<this._ints;++n)e.putInt32(this._outBlock[n])};ye.ecb.prototype.pad=function(t,e){var r=t.length()===this.blockSize?this.blockSize:this.blockSize-t.length();return t.fillWithByte(r,r),!0};ye.ecb.prototype.unpad=function(t,e){if(e.overflow>0)return!1;var r=t.length(),n=t.at(r-1);return n>this.blockSize<<2?!1:(t.truncate(n),!0)};ye.cbc=function(t){t=t||{},this.name="CBC",this.cipher=t.cipher,this.blockSize=t.blockSize||16,this._ints=this.blockSize/4,this._inBlock=new Array(this._ints),this._outBlock=new Array(this._ints)};ye.cbc.prototype.start=function(t){if(t.iv===null){if(!this._prev)throw new Error("Invalid IV parameter.");this._iv=this._prev.slice(0)}else if("iv"in t)this._iv=Hh(t.iv,this.blockSize),this._prev=this._iv.slice(0);else throw new Error("Invalid IV parameter.")};ye.cbc.prototype.encrypt=function(t,e,r){if(t.length()<this.blockSize&&!(r&&t.length()>0))return!0;for(var n=0;n<this._ints;++n)this._inBlock[n]=this._prev[n]^t.getInt32();this.cipher.encrypt(this._inBlock,this._outBlock);for(var n=0;n<this._ints;++n)e.putInt32(this._outBlock[n]);this._prev=this._outBlock};ye.cbc.prototype.decrypt=function(t,e,r){if(t.length()<this.blockSize&&!(r&&t.length()>0))return!0;for(var n=0;n<this._ints;++n)this._inBlock[n]=t.getInt32();this.cipher.decrypt(this._inBlock,this._outBlock);for(var n=0;n<this._ints;++n)e.putInt32(this._prev[n]^this._outBlock[n]);this._prev=this._inBlock.slice(0)};ye.cbc.prototype.pad=function(t,e){var r=t.length()===this.blockSize?this.blockSize:this.blockSize-t.length();return t.fillWithByte(r,r),!0};ye.cbc.prototype.unpad=function(t,e){if(e.overflow>0)return!1;var r=t.length(),n=t.at(r-1);return n>this.blockSize<<2?!1:(t.truncate(n),!0)};ye.cfb=function(t){t=t||{},this.name="CFB",this.cipher=t.cipher,this.blockSize=t.blockSize||16,this._ints=this.blockSize/4,this._inBlock=null,this._outBlock=new Array(this._ints),this._partialBlock=new Array(this._ints),this._partialOutput=At.util.createBuffer(),this._partialBytes=0};ye.cfb.prototype.start=function(t){if(!("iv"in t))throw new Error("Invalid IV parameter.");this._iv=Hh(t.iv,this.blockSize),this._inBlock=this._iv.slice(0),this._partialBytes=0};ye.cfb.prototype.encrypt=function(t,e,r){var n=t.length();if(n===0)return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),this._partialBytes===0&&n>=this.blockSize){for(var i=0;i<this._ints;++i)this._inBlock[i]=t.getInt32()^this._outBlock[i],e.putInt32(this._inBlock[i]);return}var o=(this.blockSize-n)%this.blockSize;o>0&&(o=this.blockSize-o),this._partialOutput.clear();for(var i=0;i<this._ints;++i)this._partialBlock[i]=t.getInt32()^this._outBlock[i],this._partialOutput.putInt32(this._partialBlock[i]);if(o>0)t.read-=this.blockSize;else for(var i=0;i<this._ints;++i)this._inBlock[i]=this._partialBlock[i];if(this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),o>0&&!r)return e.putBytes(this._partialOutput.getBytes(o-this._partialBytes)),this._partialBytes=o,!0;e.putBytes(this._partialOutput.getBytes(n-this._partialBytes)),this._partialBytes=0};ye.cfb.prototype.decrypt=function(t,e,r){var n=t.length();if(n===0)return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),this._partialBytes===0&&n>=this.blockSize){for(var i=0;i<this._ints;++i)this._inBlock[i]=t.getInt32(),e.putInt32(this._inBlock[i]^this._outBlock[i]);return}var o=(this.blockSize-n)%this.blockSize;o>0&&(o=this.blockSize-o),this._partialOutput.clear();for(var i=0;i<this._ints;++i)this._partialBlock[i]=t.getInt32(),this._partialOutput.putInt32(this._partialBlock[i]^this._outBlock[i]);if(o>0)t.read-=this.blockSize;else for(var i=0;i<this._ints;++i)this._inBlock[i]=this._partialBlock[i];if(this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),o>0&&!r)return e.putBytes(this._partialOutput.getBytes(o-this._partialBytes)),this._partialBytes=o,!0;e.putBytes(this._partialOutput.getBytes(n-this._partialBytes)),this._partialBytes=0};ye.ofb=function(t){t=t||{},this.name="OFB",this.cipher=t.cipher,this.blockSize=t.blockSize||16,this._ints=this.blockSize/4,this._inBlock=null,this._outBlock=new Array(this._ints),this._partialOutput=At.util.createBuffer(),this._partialBytes=0};ye.ofb.prototype.start=function(t){if(!("iv"in t))throw new Error("Invalid IV parameter.");this._iv=Hh(t.iv,this.blockSize),this._inBlock=this._iv.slice(0),this._partialBytes=0};ye.ofb.prototype.encrypt=function(t,e,r){var n=t.length();if(t.length()===0)return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),this._partialBytes===0&&n>=this.blockSize){for(var i=0;i<this._ints;++i)e.putInt32(t.getInt32()^this._outBlock[i]),this._inBlock[i]=this._outBlock[i];return}var o=(this.blockSize-n)%this.blockSize;o>0&&(o=this.blockSize-o),this._partialOutput.clear();for(var i=0;i<this._ints;++i)this._partialOutput.putInt32(t.getInt32()^this._outBlock[i]);if(o>0)t.read-=this.blockSize;else for(var i=0;i<this._ints;++i)this._inBlock[i]=this._outBlock[i];if(this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),o>0&&!r)return e.putBytes(this._partialOutput.getBytes(o-this._partialBytes)),this._partialBytes=o,!0;e.putBytes(this._partialOutput.getBytes(n-this._partialBytes)),this._partialBytes=0};ye.ofb.prototype.decrypt=ye.ofb.prototype.encrypt;ye.ctr=function(t){t=t||{},this.name="CTR",this.cipher=t.cipher,this.blockSize=t.blockSize||16,this._ints=this.blockSize/4,this._inBlock=null,this._outBlock=new Array(this._ints),this._partialOutput=At.util.createBuffer(),this._partialBytes=0};ye.ctr.prototype.start=function(t){if(!("iv"in t))throw new Error("Invalid IV parameter.");this._iv=Hh(t.iv,this.blockSize),this._inBlock=this._iv.slice(0),this._partialBytes=0};ye.ctr.prototype.encrypt=function(t,e,r){var n=t.length();if(n===0)return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),this._partialBytes===0&&n>=this.blockSize)for(var i=0;i<this._ints;++i)e.putInt32(t.getInt32()^this._outBlock[i]);else{var o=(this.blockSize-n)%this.blockSize;o>0&&(o=this.blockSize-o),this._partialOutput.clear();for(var i=0;i<this._ints;++i)this._partialOutput.putInt32(t.getInt32()^this._outBlock[i]);if(o>0&&(t.read-=this.blockSize),this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),o>0&&!r)return e.putBytes(this._partialOutput.getBytes(o-this._partialBytes)),this._partialBytes=o,!0;e.putBytes(this._partialOutput.getBytes(n-this._partialBytes)),this._partialBytes=0}qh(this._inBlock)};ye.ctr.prototype.decrypt=ye.ctr.prototype.encrypt;ye.gcm=function(t){t=t||{},this.name="GCM",this.cipher=t.cipher,this.blockSize=t.blockSize||16,this._ints=this.blockSize/4,this._inBlock=new Array(this._ints),this._outBlock=new Array(this._ints),this._partialOutput=At.util.createBuffer(),this._partialBytes=0,this._R=3774873600};ye.gcm.prototype.start=function(t){if(!("iv"in t))throw new Error("Invalid IV parameter.");var e=At.util.createBuffer(t.iv);this._cipherLength=0;var r;if("additionalData"in t?r=At.util.createBuffer(t.additionalData):r=At.util.createBuffer(),"tagLength"in t?this._tagLength=t.tagLength:this._tagLength=128,this._tag=null,t.decrypt&&(this._tag=At.util.createBuffer(t.tag).getBytes(),this._tag.length!==this._tagLength/8))throw new Error("Authentication tag does not match tag length.");this._hashBlock=new Array(this._ints),this.tag=null,this._hashSubkey=new Array(this._ints),this.cipher.encrypt([0,0,0,0],this._hashSubkey),this.componentBits=4,this._m=this.generateHashTable(this._hashSubkey,this.componentBits);var n=e.length();if(n===12)this._j0=[e.getInt32(),e.getInt32(),e.getInt32(),1];else{for(this._j0=[0,0,0,0];e.length()>0;)this._j0=this.ghash(this._hashSubkey,this._j0,[e.getInt32(),e.getInt32(),e.getInt32(),e.getInt32()]);this._j0=this.ghash(this._hashSubkey,this._j0,[0,0].concat(Zy(n*8)))}this._inBlock=this._j0.slice(0),qh(this._inBlock),this._partialBytes=0,r=At.util.createBuffer(r),this._aDataLength=Zy(r.length()*8);var i=r.length()%this.blockSize;for(i&&r.fillWithByte(0,this.blockSize-i),this._s=[0,0,0,0];r.length()>0;)this._s=this.ghash(this._hashSubkey,this._s,[r.getInt32(),r.getInt32(),r.getInt32(),r.getInt32()])};ye.gcm.prototype.encrypt=function(t,e,r){var n=t.length();if(n===0)return!0;if(this.cipher.encrypt(this._inBlock,this._outBlock),this._partialBytes===0&&n>=this.blockSize){for(var i=0;i<this._ints;++i)e.putInt32(this._outBlock[i]^=t.getInt32());this._cipherLength+=this.blockSize}else{var o=(this.blockSize-n)%this.blockSize;o>0&&(o=this.blockSize-o),this._partialOutput.clear();for(var i=0;i<this._ints;++i)this._partialOutput.putInt32(t.getInt32()^this._outBlock[i]);if(o<=0||r){if(r){var s=n%this.blockSize;this._cipherLength+=s,this._partialOutput.truncate(this.blockSize-s)}else this._cipherLength+=this.blockSize;for(var i=0;i<this._ints;++i)this._outBlock[i]=this._partialOutput.getInt32();this._partialOutput.read-=this.blockSize}if(this._partialBytes>0&&this._partialOutput.getBytes(this._partialBytes),o>0&&!r)return t.read-=this.blockSize,e.putBytes(this._partialOutput.getBytes(o-this._partialBytes)),this._partialBytes=o,!0;e.putBytes(this._partialOutput.getBytes(n-this._partialBytes)),this._partialBytes=0}this._s=this.ghash(this._hashSubkey,this._s,this._outBlock),qh(this._inBlock)};ye.gcm.prototype.decrypt=function(t,e,r){var n=t.length();if(n<this.blockSize&&!(r&&n>0))return!0;this.cipher.encrypt(this._inBlock,this._outBlock),qh(this._inBlock),this._hashBlock[0]=t.getInt32(),this._hashBlock[1]=t.getInt32(),this._hashBlock[2]=t.getInt32(),this._hashBlock[3]=t.getInt32(),this._s=this.ghash(this._hashSubkey,this._s,this._hashBlock);for(var i=0;i<this._ints;++i)e.putInt32(this._outBlock[i]^this._hashBlock[i]);n<this.blockSize?this._cipherLength+=n%this.blockSize:this._cipherLength+=this.blockSize};ye.gcm.prototype.afterFinish=function(t,e){var r=!0;e.decrypt&&e.overflow&&t.truncate(this.blockSize-e.overflow),this.tag=At.util.createBuffer();var n=this._aDataLength.concat(Zy(this._cipherLength*8));this._s=this.ghash(this._hashSubkey,this._s,n);var i=[];this.cipher.encrypt(this._j0,i);for(var o=0;o<this._ints;++o)this.tag.putInt32(this._s[o]^i[o]);return this.tag.truncate(this.tag.length()%(this._tagLength/8)),e.decrypt&&this.tag.bytes()!==this._tag&&(r=!1),r};ye.gcm.prototype.multiply=function(t,e){for(var r=[0,0,0,0],n=e.slice(0),i=0;i<128;++i){var o=t[i/32|0]&1<<31-i%32;o&&(r[0]^=n[0],r[1]^=n[1],r[2]^=n[2],r[3]^=n[3]),this.pow(n,n)}return r};ye.gcm.prototype.pow=function(t,e){for(var r=t[3]&1,n=3;n>0;--n)e[n]=t[n]>>>1|(t[n-1]&1)<<31;e[0]=t[0]>>>1,r&&(e[0]^=this._R)};ye.gcm.prototype.tableMultiply=function(t){for(var e=[0,0,0,0],r=0;r<32;++r){var n=r/8|0,i=t[n]>>>(7-r%8)*4&15,o=this._m[r][i];e[0]^=o[0],e[1]^=o[1],e[2]^=o[2],e[3]^=o[3]}return e};ye.gcm.prototype.ghash=function(t,e,r){return e[0]^=r[0],e[1]^=r[1],e[2]^=r[2],e[3]^=r[3],this.tableMultiply(e)};ye.gcm.prototype.generateHashTable=function(t,e){for(var r=8/e,n=4*r,i=16*r,o=new Array(i),s=0;s<i;++s){var a=[0,0,0,0],c=s/n|0,u=(n-1-s%n)*e;a[c]=1<<e-1<<u,o[s]=this.generateSubHashTable(this.multiply(a,t),e)}return o};ye.gcm.prototype.generateSubHashTable=function(t,e){var r=1<<e,n=r>>>1,i=new Array(r);i[n]=t.slice(0);for(var o=n>>>1;o>0;)this.pow(i[2*o],i[o]=[]),o>>=1;for(o=2;o<n;){for(var s=1;s<o;++s){var a=i[o],c=i[s];i[o+s]=[a[0]^c[0],a[1]^c[1],a[2]^c[2],a[3]^c[3]]}o*=2}for(i[0]=[0,0,0,0],o=n+1;o<r;++o){var u=i[o^n];i[o]=[t[0]^u[0],t[1]^u[1],t[2]^u[2],t[3]^u[3]]}return i};function Hh(t,e){if(typeof t=="string"&&(t=At.util.createBuffer(t)),At.util.isArray(t)&&t.length>4){var r=t;t=At.util.createBuffer();for(var n=0;n<r.length;++n)t.putByte(r[n])}if(t.length()<e)throw new Error("Invalid IV length; got "+t.length()+" bytes and expected "+e+" bytes.");if(!At.util.isArray(t)){for(var i=[],o=e/4,n=0;n<o;++n)i.push(t.getInt32());t=i}return t}function qh(t){t[t.length-1]=t[t.length-1]+1&4294967295}function Zy(t){return[t/4294967296|0,t&4294967295]}});var ig=re((vse,YS)=>{var Me=Le();Xy();eg();ft();YS.exports=Me.aes=Me.aes||{};Me.aes.startEncrypting=function(t,e,r,n){var i=$h({key:t,output:r,decrypt:!1,mode:n});return i.start(e),i};Me.aes.createEncryptionCipher=function(t,e){return $h({key:t,output:null,decrypt:!1,mode:e})};Me.aes.startDecrypting=function(t,e,r,n){var i=$h({key:t,output:r,decrypt:!0,mode:n});return i.start(e),i};Me.aes.createDecryptionCipher=function(t,e){return $h({key:t,output:null,decrypt:!0,mode:e})};Me.aes.Algorithm=function(t,e){ng||GS();var r=this;r.name=t,r.mode=new e({blockSize:16,cipher:{encrypt:function(n,i){return rg(r._w,n,i,!1)},decrypt:function(n,i){return rg(r._w,n,i,!0)}}}),r._init=!1};Me.aes.Algorithm.prototype.initialize=function(t){if(!this._init){var e=t.key,r;if(typeof e=="string"&&(e.length===16||e.length===24||e.length===32))e=Me.util.createBuffer(e);else if(Me.util.isArray(e)&&(e.length===16||e.length===24||e.length===32)){r=e,e=Me.util.createBuffer();for(var n=0;n<r.length;++n)e.putByte(r[n])}if(!Me.util.isArray(e)){r=e,e=[];var i=r.length();if(i===16||i===24||i===32){i=i>>>2;for(var n=0;n<i;++n)e.push(r.getInt32())}}if(!Me.util.isArray(e)||!(e.length===4||e.length===6||e.length===8))throw new Error("Invalid key parameter.");var o=this.mode.name,s=["CFB","OFB","CTR","GCM"].indexOf(o)!==-1;this._w=WS(e,t.decrypt&&!s),this._init=!0}};Me.aes._expandKey=function(t,e){return ng||GS(),WS(t,e)};Me.aes._updateBlock=rg;Da("AES-ECB",Me.cipher.modes.ecb);Da("AES-CBC",Me.cipher.modes.cbc);Da("AES-CFB",Me.cipher.modes.cfb);Da("AES-OFB",Me.cipher.modes.ofb);Da("AES-CTR",Me.cipher.modes.ctr);Da("AES-GCM",Me.cipher.modes.gcm);function Da(t,e){var r=function(){return new Me.aes.Algorithm(t,e)};Me.cipher.registerAlgorithm(t,r)}var ng=!1,Pa=4,Yt,tg,zS,Ho,Wr;function GS(){ng=!0,zS=[0,1,2,4,8,16,32,64,128,27,54];for(var t=new Array(256),e=0;e<128;++e)t[e]=e<<1,t[e+128]=e+128<<1^283;Yt=new Array(256),tg=new Array(256),Ho=new Array(4),Wr=new Array(4);for(var e=0;e<4;++e)Ho[e]=new Array(256),Wr[e]=new Array(256);for(var r=0,n=0,i,o,s,a,c,u,l,e=0;e<256;++e){a=n^n<<1^n<<2^n<<3^n<<4,a=a>>8^a&255^99,Yt[r]=a,tg[a]=r,c=t[a],i=t[r],o=t[i],s=t[o],u=c<<24^a<<16^a<<8^(a^c),l=(i^o^s)<<24^(r^s)<<16^(r^o^s)<<8^(r^i^s);for(var f=0;f<4;++f)Ho[f][r]=u,Wr[f][a]=l,u=u<<24|u>>>8,l=l<<24|l>>>8;r===0?r=n=1:(r=i^t[t[t[i^s]]],n^=t[t[n]])}}function WS(t,e){for(var r=t.slice(0),n,i=1,o=r.length,s=o+6+1,a=Pa*s,c=o;c<a;++c)n=r[c-1],c%o===0?(n=Yt[n>>>16&255]<<24^Yt[n>>>8&255]<<16^Yt[n&255]<<8^Yt[n>>>24]^zS[i]<<24,i++):o>6&&c%o===4&&(n=Yt[n>>>24]<<24^Yt[n>>>16&255]<<16^Yt[n>>>8&255]<<8^Yt[n&255]),r[c]=r[c-o]^n;if(e){var u,l=Wr[0],f=Wr[1],d=Wr[2],p=Wr[3],h=r.slice(0);a=r.length;for(var c=0,m=a-Pa;c<a;c+=Pa,m-=Pa)if(c===0||c===a-Pa)h[c]=r[m],h[c+1]=r[m+3],h[c+2]=r[m+2],h[c+3]=r[m+1];else for(var y=0;y<Pa;++y)u=r[m+y],h[c+(3&-y)]=l[Yt[u>>>24]]^f[Yt[u>>>16&255]]^d[Yt[u>>>8&255]]^p[Yt[u&255]];r=h}return r}function rg(t,e,r,n){var i=t.length/4-1,o,s,a,c,u;n?(o=Wr[0],s=Wr[1],a=Wr[2],c=Wr[3],u=tg):(o=Ho[0],s=Ho[1],a=Ho[2],c=Ho[3],u=Yt);var l,f,d,p,h,m,y;l=e[0]^t[0],f=e[n?3:1]^t[1],d=e[2]^t[2],p=e[n?1:3]^t[3];for(var g=3,b=1;b<i;++b)h=o[l>>>24]^s[f>>>16&255]^a[d>>>8&255]^c[p&255]^t[++g],m=o[f>>>24]^s[d>>>16&255]^a[p>>>8&255]^c[l&255]^t[++g],y=o[d>>>24]^s[p>>>16&255]^a[l>>>8&255]^c[f&255]^t[++g],p=o[p>>>24]^s[l>>>16&255]^a[f>>>8&255]^c[d&255]^t[++g],l=h,f=m,d=y;r[0]=u[l>>>24]<<24^u[f>>>16&255]<<16^u[d>>>8&255]<<8^u[p&255]^t[++g],r[n?3:1]=u[f>>>24]<<24^u[d>>>16&255]<<16^u[p>>>8&255]<<8^u[l&255]^t[++g],r[2]=u[d>>>24]<<24^u[p>>>16&255]<<16^u[l>>>8&255]<<8^u[f&255]^t[++g],r[n?1:3]=u[p>>>24]<<24^u[l>>>16&255]<<16^u[f>>>8&255]<<8^u[d&255]^t[++g]}function $h(t){t=t||{};var e=(t.mode||"CBC").toUpperCase(),r="AES-"+e,n;t.decrypt?n=Me.cipher.createDecipher(r,t.key):n=Me.cipher.createCipher(r,t.key);var i=n.start;return n.start=function(o,s){var a=null;s instanceof Me.util.ByteBuffer&&(a=s,s={}),s=s||{},s.output=a,s.iv=o,i.call(n,s)},n}});var JS=re((Ese,QS)=>{var Ye=Le();Xy();eg();ft();QS.exports=Ye.des=Ye.des||{};Ye.des.startEncrypting=function(t,e,r,n){var i=zh({key:t,output:r,decrypt:!1,mode:n||(e===null?"ECB":"CBC")});return i.start(e),i};Ye.des.createEncryptionCipher=function(t,e){return zh({key:t,output:null,decrypt:!1,mode:e})};Ye.des.startDecrypting=function(t,e,r,n){var i=zh({key:t,output:r,decrypt:!0,mode:n||(e===null?"ECB":"CBC")});return i.start(e),i};Ye.des.createDecryptionCipher=function(t,e){return zh({key:t,output:null,decrypt:!0,mode:e})};Ye.des.Algorithm=function(t,e){var r=this;r.name=t,r.mode=new e({blockSize:8,cipher:{encrypt:function(n,i){return jS(r._keys,n,i,!1)},decrypt:function(n,i){return jS(r._keys,n,i,!0)}}}),r._init=!1};Ye.des.Algorithm.prototype.initialize=function(t){if(!this._init){var e=Ye.util.createBuffer(t.key);if(this.name.indexOf("3DES")===0&&e.length()!==24)throw new Error("Invalid Triple-DES key size: "+e.length()*8);this._keys=f5(e),this._init=!0}};gn("DES-ECB",Ye.cipher.modes.ecb);gn("DES-CBC",Ye.cipher.modes.cbc);gn("DES-CFB",Ye.cipher.modes.cfb);gn("DES-OFB",Ye.cipher.modes.ofb);gn("DES-CTR",Ye.cipher.modes.ctr);gn("3DES-ECB",Ye.cipher.modes.ecb);gn("3DES-CBC",Ye.cipher.modes.cbc);gn("3DES-CFB",Ye.cipher.modes.cfb);gn("3DES-OFB",Ye.cipher.modes.ofb);gn("3DES-CTR",Ye.cipher.modes.ctr);function gn(t,e){var r=function(){return new Ye.des.Algorithm(t,e)};Ye.cipher.registerAlgorithm(t,r)}var n5=[16843776,0,65536,16843780,16842756,66564,4,65536,1024,16843776,16843780,1024,16778244,16842756,16777216,4,1028,16778240,16778240,66560,66560,16842752,16842752,16778244,65540,16777220,16777220,65540,0,1028,66564,16777216,65536,16843780,4,16842752,16843776,16777216,16777216,1024,16842756,65536,66560,16777220,1024,4,16778244,66564,16843780,65540,16842752,16778244,16777220,1028,66564,16843776,1028,16778240,16778240,0,65540,66560,0,16842756],i5=[-2146402272,-2147450880,32768,1081376,1048576,32,-2146435040,-2147450848,-2147483616,-2146402272,-2146402304,-2147483648,-2147450880,1048576,32,-2146435040,1081344,1048608,-2147450848,0,-2147483648,32768,1081376,-2146435072,1048608,-2147483616,0,1081344,32800,-2146402304,-2146435072,32800,0,1081376,-2146435040,1048576,-2147450848,-2146435072,-2146402304,32768,-2146435072,-2147450880,32,-2146402272,1081376,32,32768,-2147483648,32800,-2146402304,1048576,-2147483616,1048608,-2147450848,-2147483616,1048608,1081344,0,-2147450880,32800,-2147483648,-2146435040,-2146402272,1081344],o5=[520,134349312,0,134348808,134218240,0,131592,134218240,131080,134217736,134217736,131072,134349320,131080,134348800,520,134217728,8,134349312,512,131584,134348800,134348808,131592,134218248,131584,131072,134218248,8,134349320,512,134217728,134349312,134217728,131080,520,131072,134349312,134218240,0,512,131080,134349320,134218240,134217736,512,0,134348808,134218248,131072,134217728,134349320,8,131592,131584,134217736,134348800,134218248,520,134348800,131592,8,134348808,131584],s5=[8396801,8321,8321,128,8396928,8388737,8388609,8193,0,8396800,8396800,8396929,129,0,8388736,8388609,1,8192,8388608,8396801,128,8388608,8193,8320,8388737,1,8320,8388736,8192,8396928,8396929,129,8388736,8388609,8396800,8396929,129,0,0,8396800,8320,8388736,8388737,1,8396801,8321,8321,128,8396929,129,1,8192,8388609,8193,8396928,8388737,8193,8320,8388608,8396801,128,8388608,8192,8396928],a5=[256,34078976,34078720,1107296512,524288,256,1073741824,34078720,1074266368,524288,33554688,1074266368,1107296512,1107820544,524544,1073741824,33554432,1074266112,1074266112,0,1073742080,1107820800,1107820800,33554688,1107820544,1073742080,0,1107296256,34078976,33554432,1107296256,524544,524288,1107296512,256,33554432,1073741824,34078720,1107296512,1074266368,33554688,1073741824,1107820544,34078976,1074266368,256,33554432,1107820544,1107820800,524544,1107296256,1107820800,34078720,0,1074266112,1107296256,524544,33554688,1073742080,524288,0,1074266112,34078976,1073742080],c5=[536870928,541065216,16384,541081616,541065216,16,541081616,4194304,536887296,4210704,4194304,536870928,4194320,536887296,536870912,16400,0,4194320,536887312,16384,4210688,536887312,16,541065232,541065232,0,4210704,541081600,16400,4210688,541081600,536870912,536887296,16,541065232,4210688,541081616,4194304,16400,536870928,4194304,536887296,536870912,16400,536870928,541081616,4210688,541065216,4210704,541081600,0,541065232,16,16384,541065216,4210704,16384,4194320,536887312,0,541081600,536870912,4194320,536887312],u5=[2097152,69206018,67110914,0,2048,67110914,2099202,69208064,69208066,2097152,0,67108866,2,67108864,69206018,2050,67110912,2099202,2097154,67110912,67108866,69206016,69208064,2097154,69206016,2048,2050,69208066,2099200,2,67108864,2099200,67108864,2099200,2097152,67110914,67110914,69206018,69206018,2,2097154,67108864,67110912,2097152,69208064,2050,2099202,69208064,2050,67108866,69208066,69206016,2099200,0,2,69208066,0,2099202,69206016,2048,67108866,67110912,2048,2097154],l5=[268439616,4096,262144,268701760,268435456,268439616,64,268435456,262208,268697600,268701760,266240,268701696,266304,4096,64,268697600,268435520,268439552,4160,266240,262208,268697664,268701696,4160,0,0,268697664,268435520,268439552,266304,262144,266304,262144,268701696,4096,64,268697664,4096,266304,268439552,64,268435520,268697600,268697664,268435456,262144,268439616,0,268701760,262208,268435520,268697600,268439552,268439616,0,268701760,266240,266240,4160,4160,262208,268435456,268701696];function f5(t){for(var e=[0,4,536870912,536870916,65536,65540,536936448,536936452,512,516,536871424,536871428,66048,66052,536936960,536936964],r=[0,1,1048576,1048577,67108864,67108865,68157440,68157441,256,257,1048832,1048833,67109120,67109121,68157696,68157697],n=[0,8,2048,2056,16777216,16777224,16779264,16779272,0,8,2048,2056,16777216,16777224,16779264,16779272],i=[0,2097152,134217728,136314880,8192,2105344,134225920,136323072,131072,2228224,134348800,136445952,139264,2236416,134356992,136454144],o=[0,262144,16,262160,0,262144,16,262160,4096,266240,4112,266256,4096,266240,4112,266256],s=[0,1024,32,1056,0,1024,32,1056,33554432,33555456,33554464,33555488,33554432,33555456,33554464,33555488],a=[0,268435456,524288,268959744,2,268435458,524290,268959746,0,268435456,524288,268959744,2,268435458,524290,268959746],c=[0,65536,2048,67584,536870912,536936448,536872960,536938496,131072,196608,133120,198656,537001984,537067520,537004032,537069568],u=[0,262144,0,262144,2,262146,2,262146,33554432,33816576,33554432,33816576,33554434,33816578,33554434,33816578],l=[0,268435456,8,268435464,0,268435456,8,268435464,1024,268436480,1032,268436488,1024,268436480,1032,268436488],f=[0,32,0,32,1048576,1048608,1048576,1048608,8192,8224,8192,8224,1056768,1056800,1056768,1056800],d=[0,16777216,512,16777728,2097152,18874368,2097664,18874880,67108864,83886080,67109376,83886592,69206016,85983232,69206528,85983744],p=[0,4096,134217728,134221824,524288,528384,134742016,134746112,16,4112,134217744,134221840,524304,528400,134742032,134746128],h=[0,4,256,260,0,4,256,260,1,5,257,261,1,5,257,261],m=t.length()>8?3:1,y=[],g=[0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0],b=0,w,_=0;_<m;_++){var E=t.getInt32(),A=t.getInt32();w=(E>>>4^A)&252645135,A^=w,E^=w<<4,w=(A>>>-16^E)&65535,E^=w,A^=w<<-16,w=(E>>>2^A)&858993459,A^=w,E^=w<<2,w=(A>>>-16^E)&65535,E^=w,A^=w<<-16,w=(E>>>1^A)&1431655765,A^=w,E^=w<<1,w=(A>>>8^E)&16711935,E^=w,A^=w<<8,w=(E>>>1^A)&1431655765,A^=w,E^=w<<1,w=E<<8|A>>>20&240,E=A<<24|A<<8&16711680|A>>>8&65280|A>>>24&240,A=w;for(var B=0;B<g.length;++B){g[B]?(E=E<<2|E>>>26,A=A<<2|A>>>26):(E=E<<1|E>>>27,A=A<<1|A>>>27),E&=-15,A&=-15;var I=e[E>>>28]|r[E>>>24&15]|n[E>>>20&15]|i[E>>>16&15]|o[E>>>12&15]|s[E>>>8&15]|a[E>>>4&15],L=c[A>>>28]|u[A>>>24&15]|l[A>>>20&15]|f[A>>>16&15]|d[A>>>12&15]|p[A>>>8&15]|h[A>>>4&15];w=(L>>>16^I)&65535,y[b++]=I^w,y[b++]=L^w<<16}}return y}function jS(t,e,r,n){var i=t.length===32?3:9,o;i===3?o=n?[30,-2,-2]:[0,32,2]:o=n?[94,62,-2,32,64,2,30,-2,-2]:[0,32,2,62,30,-2,64,96,2];var s,a=e[0],c=e[1];s=(a>>>4^c)&252645135,c^=s,a^=s<<4,s=(a>>>16^c)&65535,c^=s,a^=s<<16,s=(c>>>2^a)&858993459,a^=s,c^=s<<2,s=(c>>>8^a)&16711935,a^=s,c^=s<<8,s=(a>>>1^c)&1431655765,c^=s,a^=s<<1,a=a<<1|a>>>31,c=c<<1|c>>>31;for(var u=0;u<i;u+=3){for(var l=o[u+1],f=o[u+2],d=o[u];d!=l;d+=f){var p=c^t[d],h=(c>>>4|c<<28)^t[d+1];s=a,a=c,c=s^(i5[p>>>24&63]|s5[p>>>16&63]|c5[p>>>8&63]|l5[p&63]|n5[h>>>24&63]|o5[h>>>16&63]|a5[h>>>8&63]|u5[h&63])}s=a,a=c,c=s}a=a>>>1|a<<31,c=c>>>1|c<<31,s=(a>>>1^c)&1431655765,c^=s,a^=s<<1,s=(c>>>8^a)&16711935,a^=s,c^=s<<8,s=(c>>>2^a)&858993459,a^=s,c^=s<<2,s=(a>>>16^c)&65535,c^=s,a^=s<<16,s=(a>>>4^c)&252645135,c^=s,a^=s<<4,r[0]=a,r[1]=c}function zh(t){t=t||{};var e=(t.mode||"CBC").toUpperCase(),r="DES-"+e,n;t.decrypt?n=Ye.cipher.createDecipher(r,t.key):n=Ye.cipher.createCipher(r,t.key);var i=n.start;return n.start=function(o,s){var a=null;s instanceof Ye.util.ByteBuffer&&(a=s,s={}),s=s||{},s.output=a,s.iv=o,i.call(n,s)},n}});var qo=re((Ase,XS)=>{var Gh=Le();XS.exports=Gh.md=Gh.md||{};Gh.md.algorithms=Gh.md.algorithms||{}});var e_=re((Sse,ZS)=>{var ri=Le();qo();ft();var h5=ZS.exports=ri.hmac=ri.hmac||{};h5.create=function(){var t=null,e=null,r=null,n=null,i={};return i.start=function(o,s){if(o!==null)if(typeof o=="string")if(o=o.toLowerCase(),o in ri.md.algorithms)e=ri.md.algorithms[o].create();else throw new Error('Unknown hash algorithm "'+o+'"');else e=o;if(s===null)s=t;else{if(typeof s=="string")s=ri.util.createBuffer(s);else if(ri.util.isArray(s)){var a=s;s=ri.util.createBuffer();for(var c=0;c<a.length;++c)s.putByte(a[c])}var u=s.length();u>e.blockLength&&(e.start(),e.update(s.bytes()),s=e.digest()),r=ri.util.createBuffer(),n=ri.util.createBuffer(),u=s.length();for(var c=0;c<u;++c){var a=s.at(c);r.putByte(54^a),n.putByte(92^a)}if(u<e.blockLength)for(var a=e.blockLength-u,c=0;c<a;++c)r.putByte(54),n.putByte(92);t=s,r=r.bytes(),n=n.bytes()}e.start(),e.update(r)},i.update=function(o){e.update(o)},i.getMac=function(){var o=e.digest().bytes();return e.start(),e.update(n),e.update(o),e.digest()},i.digest=i.getMac,i}});var Wh=re(()=>{});var r_=re((Rse,t_)=>{var jt=Le();e_();qo();ft();var d5=jt.pkcs5=jt.pkcs5||{},ni;jt.util.isNodejs&&!jt.options.usePureJavaScript&&(ni=Wh());t_.exports=jt.pbkdf2=d5.pbkdf2=function(t,e,r,n,i,o){if(typeof i=="function"&&(o=i,i=null),jt.util.isNodejs&&!jt.options.usePureJavaScript&&ni.pbkdf2&&(i===null||typeof i!="object")&&(ni.pbkdf2Sync.length>4||!i||i==="sha1"))return typeof i!="string"&&(i="sha1"),t=Buffer.from(t,"binary"),e=Buffer.from(e,"binary"),o?ni.pbkdf2Sync.length===4?ni.pbkdf2(t,e,r,n,function(w,_){if(w)return o(w);o(null,_.toString("binary"))}):ni.pbkdf2(t,e,r,n,i,function(w,_){if(w)return o(w);o(null,_.toString("binary"))}):ni.pbkdf2Sync.length===4?ni.pbkdf2Sync(t,e,r,n).toString("binary"):ni.pbkdf2Sync(t,e,r,n,i).toString("binary");if((typeof i>"u"||i===null)&&(i="sha1"),typeof i=="string"){if(!(i in jt.md.algorithms))throw new Error("Unknown hash algorithm: "+i);i=jt.md[i].create()}var s=i.digestLength;if(n>4294967295*s){var a=new Error("Derived key is too long.");if(o)return o(a);throw a}var c=Math.ceil(n/s),u=n-(c-1)*s,l=jt.hmac.create();l.start(i,t);var f="",d,p,h;if(!o){for(var m=1;m<=c;++m){l.start(null,null),l.update(e),l.update(jt.util.int32ToBytes(m)),d=h=l.digest().getBytes();for(var y=2;y<=r;++y)l.start(null,null),l.update(h),p=l.digest().getBytes(),d=jt.util.xorBytes(d,p,s),h=p;f+=m<c?d:d.substr(0,u)}return f}var m=1,y;function g(){if(m>c)return o(null,f);l.start(null,null),l.update(e),l.update(jt.util.int32ToBytes(m)),d=h=l.digest().getBytes(),y=2,b()}function b(){if(y<=r)return l.start(null,null),l.update(h),p=l.digest().getBytes(),d=jt.util.xorBytes(d,p,s),h=p,++y,jt.util.setImmediate(b);f+=m<c?d:d.substr(0,u),++m,g()}g()}});var o_=re((Bse,i_)=>{var jh=Le();ft();var n_=i_.exports=jh.pem=jh.pem||{};n_.encode=function(t,e){e=e||{};var r="-----BEGIN "+t.type+`-----\r
|
|
9
|
+
`,n;if(t.procType&&(n={name:"Proc-Type",values:[String(t.procType.version),t.procType.type]},r+=Yh(n)),t.contentDomain&&(n={name:"Content-Domain",values:[t.contentDomain]},r+=Yh(n)),t.dekInfo&&(n={name:"DEK-Info",values:[t.dekInfo.algorithm]},t.dekInfo.parameters&&n.values.push(t.dekInfo.parameters),r+=Yh(n)),t.headers)for(var i=0;i<t.headers.length;++i)r+=Yh(t.headers[i]);return t.procType&&(r+=`\r
|
|
10
|
+
`),r+=jh.util.encode64(t.body,e.maxline||64)+`\r
|
|
11
|
+
`,r+="-----END "+t.type+`-----\r
|
|
12
|
+
`,r};n_.decode=function(t){for(var e=[],r=/\s*-----BEGIN ([A-Z0-9- ]+)-----\r?\n?([\x21-\x7e\s]+?(?:\r?\n\r?\n))?([:A-Za-z0-9+\/=\s]+?)-----END \1-----/g,n=/([\x21-\x7e]+):\s*([\x21-\x7e\s^:]+)/,i=/\r?\n/,o;o=r.exec(t),!!o;){var s=o[1];s==="NEW CERTIFICATE REQUEST"&&(s="CERTIFICATE REQUEST");var a={type:s,procType:null,contentDomain:null,dekInfo:null,headers:[],body:jh.util.decode64(o[3])};if(e.push(a),!!o[2]){for(var c=o[2].split(i),u=0;o&&u<c.length;){for(var l=c[u].replace(/\s+$/,""),f=u+1;f<c.length;++f){var d=c[f];if(!/\s/.test(d[0]))break;l+=d,u=f}if(o=l.match(n),o){for(var p={name:o[1],values:[]},h=o[2].split(","),m=0;m<h.length;++m)p.values.push(p5(h[m]));if(a.procType)if(!a.contentDomain&&p.name==="Content-Domain")a.contentDomain=h[0]||"";else if(!a.dekInfo&&p.name==="DEK-Info"){if(p.values.length===0)throw new Error('Invalid PEM formatted message. The "DEK-Info" header must have at least one subfield.');a.dekInfo={algorithm:h[0],parameters:h[1]||null}}else a.headers.push(p);else{if(p.name!=="Proc-Type")throw new Error('Invalid PEM formatted message. The first encapsulated header must be "Proc-Type".');if(p.values.length!==2)throw new Error('Invalid PEM formatted message. The "Proc-Type" header must have two subfields.');a.procType={version:h[0],type:h[1]}}}++u}if(a.procType==="ENCRYPTED"&&!a.dekInfo)throw new Error('Invalid PEM formatted message. The "DEK-Info" header must be present if "Proc-Type" is "ENCRYPTED".')}}if(e.length===0)throw new Error("Invalid PEM formatted message.");return e};function Yh(t){for(var e=t.name+": ",r=[],n=function(c,u){return" "+u},i=0;i<t.values.length;++i)r.push(t.values[i].replace(/^(\S+\r\n)/,n));e+=r.join(",")+`\r
|
|
13
|
+
`;for(var o=0,s=-1,i=0;i<e.length;++i,++o)if(o>65&&s!==-1){var a=e[s];a===","?(++s,e=e.substr(0,s)+`\r
|
|
14
|
+
`+e.substr(s)):e=e.substr(0,s)+`\r
|
|
15
|
+
`+a+e.substr(s+1),o=i-s-1,s=-1,++i}else(e[i]===" "||e[i]===" "||e[i]===",")&&(s=i);return e}function p5(t){return t.replace(/^\s+/,"")}});var f_=re((Tse,l_)=>{var bn=Le();qo();ft();var a_=l_.exports=bn.sha256=bn.sha256||{};bn.md.sha256=bn.md.algorithms.sha256=a_;a_.create=function(){c_||m5();var t=null,e=bn.util.createBuffer(),r=new Array(64),n={algorithm:"sha256",blockLength:64,digestLength:32,messageLength:0,fullMessageLength:null,messageLengthSize:8};return n.start=function(){n.messageLength=0,n.fullMessageLength=n.messageLength64=[];for(var i=n.messageLengthSize/4,o=0;o<i;++o)n.fullMessageLength.push(0);return e=bn.util.createBuffer(),t={h0:1779033703,h1:3144134277,h2:1013904242,h3:2773480762,h4:1359893119,h5:2600822924,h6:528734635,h7:1541459225},n},n.start(),n.update=function(i,o){o==="utf8"&&(i=bn.util.encodeUtf8(i));var s=i.length;n.messageLength+=s,s=[s/4294967296>>>0,s>>>0];for(var a=n.fullMessageLength.length-1;a>=0;--a)n.fullMessageLength[a]+=s[1],s[1]=s[0]+(n.fullMessageLength[a]/4294967296>>>0),n.fullMessageLength[a]=n.fullMessageLength[a]>>>0,s[0]=s[1]/4294967296>>>0;return e.putBytes(i),s_(t,r,e),(e.read>2048||e.length()===0)&&e.compact(),n},n.digest=function(){var i=bn.util.createBuffer();i.putBytes(e.bytes());var o=n.fullMessageLength[n.fullMessageLength.length-1]+n.messageLengthSize,s=o&n.blockLength-1;i.putBytes(og.substr(0,n.blockLength-s));for(var a,c,u=n.fullMessageLength[0]*8,l=0;l<n.fullMessageLength.length-1;++l)a=n.fullMessageLength[l+1]*8,c=a/4294967296>>>0,u+=c,i.putInt32(u>>>0),u=a>>>0;i.putInt32(u);var f={h0:t.h0,h1:t.h1,h2:t.h2,h3:t.h3,h4:t.h4,h5:t.h5,h6:t.h6,h7:t.h7};s_(f,r,i);var d=bn.util.createBuffer();return d.putInt32(f.h0),d.putInt32(f.h1),d.putInt32(f.h2),d.putInt32(f.h3),d.putInt32(f.h4),d.putInt32(f.h5),d.putInt32(f.h6),d.putInt32(f.h7),d},n};var og=null,c_=!1,u_=null;function m5(){og="\x80",og+=bn.util.fillString("\0",64),u_=[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],c_=!0}function s_(t,e,r){for(var n,i,o,s,a,c,u,l,f,d,p,h,m,y,g,b=r.length();b>=64;){for(u=0;u<16;++u)e[u]=r.getInt32();for(;u<64;++u)n=e[u-2],n=(n>>>17|n<<15)^(n>>>19|n<<13)^n>>>10,i=e[u-15],i=(i>>>7|i<<25)^(i>>>18|i<<14)^i>>>3,e[u]=n+e[u-7]+i+e[u-16]|0;for(l=t.h0,f=t.h1,d=t.h2,p=t.h3,h=t.h4,m=t.h5,y=t.h6,g=t.h7,u=0;u<64;++u)s=(h>>>6|h<<26)^(h>>>11|h<<21)^(h>>>25|h<<7),a=y^h&(m^y),o=(l>>>2|l<<30)^(l>>>13|l<<19)^(l>>>22|l<<10),c=l&f|d&(l^f),n=g+s+a+u_[u]+e[u],i=o+c,g=y,y=m,m=h,h=p+n>>>0,p=d,d=f,f=l,l=n+i>>>0;t.h0=t.h0+l|0,t.h1=t.h1+f|0,t.h2=t.h2+d|0,t.h3=t.h3+p|0,t.h4=t.h4+h|0,t.h5=t.h5+m|0,t.h6=t.h6+y|0,t.h7=t.h7+g|0,b-=64}}});var d_=re((kse,h_)=>{var wn=Le();ft();var Qh=null;wn.util.isNodejs&&!wn.options.usePureJavaScript&&!process.versions["node-webkit"]&&(Qh=Wh());var y5=h_.exports=wn.prng=wn.prng||{};y5.create=function(t){for(var e={plugin:t,key:null,seed:null,time:null,reseeds:0,generated:0,keyBytes:""},r=t.md,n=new Array(32),i=0;i<32;++i)n[i]=r.create();e.pools=n,e.pool=0,e.generate=function(u,l){if(!l)return e.generateSync(u);var f=e.plugin.cipher,d=e.plugin.increment,p=e.plugin.formatKey,h=e.plugin.formatSeed,m=wn.util.createBuffer();e.key=null,y();function y(g){if(g)return l(g);if(m.length()>=u)return l(null,m.getBytes(u));if(e.generated>1048575&&(e.key=null),e.key===null)return wn.util.nextTick(function(){o(y)});var b=f(e.key,e.seed);e.generated+=b.length,m.putBytes(b),e.key=p(f(e.key,d(e.seed))),e.seed=h(f(e.key,e.seed)),wn.util.setImmediate(y)}},e.generateSync=function(u){var l=e.plugin.cipher,f=e.plugin.increment,d=e.plugin.formatKey,p=e.plugin.formatSeed;e.key=null;for(var h=wn.util.createBuffer();h.length()<u;){e.generated>1048575&&(e.key=null),e.key===null&&s();var m=l(e.key,e.seed);e.generated+=m.length,h.putBytes(m),e.key=d(l(e.key,f(e.seed))),e.seed=p(l(e.key,e.seed))}return h.getBytes(u)};function o(u){if(e.pools[0].messageLength>=32)return a(),u();var l=32-e.pools[0].messageLength<<5;e.seedFile(l,function(f,d){if(f)return u(f);e.collect(d),a(),u()})}function s(){if(e.pools[0].messageLength>=32)return a();var u=32-e.pools[0].messageLength<<5;e.collect(e.seedFileSync(u)),a()}function a(){e.reseeds=e.reseeds===4294967295?0:e.reseeds+1;var u=e.plugin.md.create();u.update(e.keyBytes);for(var l=1,f=0;f<32;++f)e.reseeds%l===0&&(u.update(e.pools[f].digest().getBytes()),e.pools[f].start()),l=l<<1;e.keyBytes=u.digest().getBytes(),u.start(),u.update(e.keyBytes);var d=u.digest().getBytes();e.key=e.plugin.formatKey(e.keyBytes),e.seed=e.plugin.formatSeed(d),e.generated=0}function c(u){var l=null,f=wn.util.globalScope,d=f.crypto||f.msCrypto;d&&d.getRandomValues&&(l=function(E){return d.getRandomValues(E)});var p=wn.util.createBuffer();if(l)for(;p.length()<u;){var h=Math.max(1,Math.min(u-p.length(),65536)/4),m=new Uint32Array(Math.floor(h));try{l(m);for(var y=0;y<m.length;++y)p.putInt32(m[y])}catch(E){if(!(typeof QuotaExceededError<"u"&&E instanceof QuotaExceededError))throw E}}if(p.length()<u)for(var g,b,w,_=Math.floor(Math.random()*65536);p.length()<u;){b=16807*(_&65535),g=16807*(_>>16),b+=(g&32767)<<16,b+=g>>15,b=(b&2147483647)+(b>>31),_=b&4294967295;for(var y=0;y<3;++y)w=_>>>(y<<3),w^=Math.floor(Math.random()*256),p.putByte(w&255)}return p.getBytes(u)}return Qh?(e.seedFile=function(u,l){Qh.randomBytes(u,function(f,d){if(f)return l(f);l(null,d.toString())})},e.seedFileSync=function(u){return Qh.randomBytes(u).toString()}):(e.seedFile=function(u,l){try{l(null,c(u))}catch(f){l(f)}},e.seedFileSync=c),e.collect=function(u){for(var l=u.length,f=0;f<l;++f)e.pools[e.pool].update(u.substr(f,1)),e.pool=e.pool===31?0:e.pool+1},e.collectInt=function(u,l){for(var f="",d=0;d<l;d+=8)f+=String.fromCharCode(u>>d&255);e.collect(f)},e.registerWorker=function(u){if(u===self)e.seedFile=function(f,d){function p(h){var m=h.data;m.forge&&m.forge.prng&&(self.removeEventListener("message",p),d(m.forge.prng.err,m.forge.prng.bytes))}self.addEventListener("message",p),self.postMessage({forge:{prng:{needed:f}}})};else{var l=function(f){var d=f.data;d.forge&&d.forge.prng&&e.seedFile(d.forge.prng.needed,function(p,h){u.postMessage({forge:{prng:{err:p,bytes:h}}})})};u.addEventListener("message",l)}},e}});var su=re((Cse,sg)=>{var St=Le();ig();f_();d_();ft();(function(){if(St.random&&St.random.getBytes){sg.exports=St.random;return}(function(t){var e={},r=new Array(4),n=St.util.createBuffer();e.formatKey=function(f){var d=St.util.createBuffer(f);return f=new Array(4),f[0]=d.getInt32(),f[1]=d.getInt32(),f[2]=d.getInt32(),f[3]=d.getInt32(),St.aes._expandKey(f,!1)},e.formatSeed=function(f){var d=St.util.createBuffer(f);return f=new Array(4),f[0]=d.getInt32(),f[1]=d.getInt32(),f[2]=d.getInt32(),f[3]=d.getInt32(),f},e.cipher=function(f,d){return St.aes._updateBlock(f,d,r,!1),n.putInt32(r[0]),n.putInt32(r[1]),n.putInt32(r[2]),n.putInt32(r[3]),n.getBytes()},e.increment=function(f){return++f[3],f},e.md=St.md.sha256;function i(){var f=St.prng.create(e);return f.getBytes=function(d,p){return f.generate(d,p)},f.getBytesSync=function(d){return f.generate(d)},f}var o=i(),s=null,a=St.util.globalScope,c=a.crypto||a.msCrypto;if(c&&c.getRandomValues&&(s=function(f){return c.getRandomValues(f)}),St.options.usePureJavaScript||!St.util.isNodejs&&!s){if(typeof window>"u"||window.document,o.collectInt(+new Date,32),typeof navigator<"u"){var u="";for(var l in navigator)try{typeof navigator[l]=="string"&&(u+=navigator[l])}catch{}o.collect(u),u=null}t&&(t().mousemove(function(f){o.collectInt(f.clientX,16),o.collectInt(f.clientY,16)}),t().keypress(function(f){o.collectInt(f.charCode,8)}))}if(!St.random)St.random=o;else for(var l in o)St.random[l]=o[l];St.random.createInstance=i,sg.exports=St.random})(typeof jQuery<"u"?jQuery:null)})()});var g_=re((Pse,y_)=>{var ir=Le();ft();var ag=[217,120,249,196,25,221,181,237,40,233,253,121,74,160,216,157,198,126,55,131,43,118,83,142,98,76,100,136,68,139,251,162,23,154,89,245,135,179,79,19,97,69,109,141,9,129,125,50,189,143,64,235,134,183,123,11,240,149,33,34,92,107,78,130,84,214,101,147,206,96,178,28,115,86,192,20,167,140,241,220,18,117,202,31,59,190,228,209,66,61,212,48,163,60,182,38,111,191,14,218,70,105,7,87,39,242,29,155,188,148,67,3,248,17,199,246,144,239,62,231,6,195,213,47,200,102,30,215,8,232,234,222,128,82,238,247,132,170,114,172,53,77,106,42,150,26,210,113,90,21,73,116,75,159,208,94,4,24,164,236,194,224,65,110,15,81,203,204,36,145,175,80,161,244,112,57,153,124,58,133,35,184,180,122,252,2,54,91,37,85,151,49,45,93,250,152,227,138,146,174,5,223,41,16,103,108,186,201,211,0,230,207,225,158,168,44,99,22,1,63,88,226,137,169,13,56,52,27,171,51,255,176,187,72,12,95,185,177,205,46,197,243,219,71,229,165,156,119,10,166,32,104,254,127,193,173],p_=[1,2,3,5],g5=function(t,e){return t<<e&65535|(t&65535)>>16-e},b5=function(t,e){return(t&65535)>>e|t<<16-e&65535};y_.exports=ir.rc2=ir.rc2||{};ir.rc2.expandKey=function(t,e){typeof t=="string"&&(t=ir.util.createBuffer(t)),e=e||128;var r=t,n=t.length(),i=e,o=Math.ceil(i/8),s=255>>(i&7),a;for(a=n;a<128;a++)r.putByte(ag[r.at(a-1)+r.at(a-n)&255]);for(r.setAt(128-o,ag[r.at(128-o)&s]),a=127-o;a>=0;a--)r.setAt(a,ag[r.at(a+1)^r.at(a+o)]);return r};var m_=function(t,e,r){var n=!1,i=null,o=null,s=null,a,c,u,l,f=[];for(t=ir.rc2.expandKey(t,e),u=0;u<64;u++)f.push(t.getInt16Le());r?(a=function(h){for(u=0;u<4;u++)h[u]+=f[l]+(h[(u+3)%4]&h[(u+2)%4])+(~h[(u+3)%4]&h[(u+1)%4]),h[u]=g5(h[u],p_[u]),l++},c=function(h){for(u=0;u<4;u++)h[u]+=f[h[(u+3)%4]&63]}):(a=function(h){for(u=3;u>=0;u--)h[u]=b5(h[u],p_[u]),h[u]-=f[l]+(h[(u+3)%4]&h[(u+2)%4])+(~h[(u+3)%4]&h[(u+1)%4]),l--},c=function(h){for(u=3;u>=0;u--)h[u]-=f[h[(u+3)%4]&63]});var d=function(h){var m=[];for(u=0;u<4;u++){var y=i.getInt16Le();s!==null&&(r?y^=s.getInt16Le():s.putInt16Le(y)),m.push(y&65535)}l=r?0:63;for(var g=0;g<h.length;g++)for(var b=0;b<h[g][0];b++)h[g][1](m);for(u=0;u<4;u++)s!==null&&(r?s.putInt16Le(m[u]):m[u]^=s.getInt16Le()),o.putInt16Le(m[u])},p=null;return p={start:function(h,m){h&&typeof h=="string"&&(h=ir.util.createBuffer(h)),n=!1,i=ir.util.createBuffer(),o=m||new ir.util.createBuffer,s=h,p.output=o},update:function(h){for(n||i.putBuffer(h);i.length()>=8;)d([[5,a],[1,c],[6,a],[1,c],[5,a]])},finish:function(h){var m=!0;if(r)if(h)m=h(8,i,!r);else{var y=i.length()===8?8:8-i.length();i.fillWithByte(y,y)}if(m&&(n=!0,p.update()),!r&&(m=i.length()===0,m))if(h)m=h(8,o,!r);else{var g=o.length(),b=o.at(g-1);b>g?m=!1:o.truncate(b)}return m}},p};ir.rc2.startEncrypting=function(t,e,r){var n=ir.rc2.createEncryptionCipher(t,128);return n.start(e,r),n};ir.rc2.createEncryptionCipher=function(t,e){return m_(t,e,!0)};ir.rc2.startDecrypting=function(t,e,r){var n=ir.rc2.createDecryptionCipher(t,128);return n.start(e,r),n};ir.rc2.createDecryptionCipher=function(t,e){return m_(t,e,!1)}});var Zh=re((Dse,__)=>{var cg=Le();__.exports=cg.jsbn=cg.jsbn||{};var ii,w5=0xdeadbeefcafe,b_=(w5&16777215)==15715070;function P(t,e,r){this.data=[],t!=null&&(typeof t=="number"?this.fromNumber(t,e,r):e==null&&typeof t!="string"?this.fromString(t,256):this.fromString(t,e))}cg.jsbn.BigInteger=P;function Se(){return new P(null)}function x5(t,e,r,n,i,o){for(;--o>=0;){var s=e*this.data[t++]+r.data[n]+i;i=Math.floor(s/67108864),r.data[n++]=s&67108863}return i}function v5(t,e,r,n,i,o){for(var s=e&32767,a=e>>15;--o>=0;){var c=this.data[t]&32767,u=this.data[t++]>>15,l=a*c+u*s;c=s*c+((l&32767)<<15)+r.data[n]+(i&1073741823),i=(c>>>30)+(l>>>15)+a*u+(i>>>30),r.data[n++]=c&1073741823}return i}function w_(t,e,r,n,i,o){for(var s=e&16383,a=e>>14;--o>=0;){var c=this.data[t]&16383,u=this.data[t++]>>14,l=a*c+u*s;c=s*c+((l&16383)<<14)+r.data[n]+i,i=(c>>28)+(l>>14)+a*u,r.data[n++]=c&268435455}return i}typeof navigator>"u"?(P.prototype.am=w_,ii=28):b_&&navigator.appName=="Microsoft Internet Explorer"?(P.prototype.am=v5,ii=30):b_&&navigator.appName!="Netscape"?(P.prototype.am=x5,ii=26):(P.prototype.am=w_,ii=28);P.prototype.DB=ii;P.prototype.DM=(1<<ii)-1;P.prototype.DV=1<<ii;var ug=52;P.prototype.FV=Math.pow(2,ug);P.prototype.F1=ug-ii;P.prototype.F2=2*ii-ug;var E5="0123456789abcdefghijklmnopqrstuvwxyz",Jh=new Array,Na,Dr;Na=48;for(Dr=0;Dr<=9;++Dr)Jh[Na++]=Dr;Na=97;for(Dr=10;Dr<36;++Dr)Jh[Na++]=Dr;Na=65;for(Dr=10;Dr<36;++Dr)Jh[Na++]=Dr;function x_(t){return E5.charAt(t)}function v_(t,e){var r=Jh[t.charCodeAt(e)];return r??-1}function A5(t){for(var e=this.t-1;e>=0;--e)t.data[e]=this.data[e];t.t=this.t,t.s=this.s}function S5(t){this.t=1,this.s=t<0?-1:0,t>0?this.data[0]=t:t<-1?this.data[0]=t+this.DV:this.t=0}function Ji(t){var e=Se();return e.fromInt(t),e}function _5(t,e){var r;if(e==16)r=4;else if(e==8)r=3;else if(e==256)r=8;else if(e==2)r=1;else if(e==32)r=5;else if(e==4)r=2;else{this.fromRadix(t,e);return}this.t=0,this.s=0;for(var n=t.length,i=!1,o=0;--n>=0;){var s=r==8?t[n]&255:v_(t,n);if(s<0){t.charAt(n)=="-"&&(i=!0);continue}i=!1,o==0?this.data[this.t++]=s:o+r>this.DB?(this.data[this.t-1]|=(s&(1<<this.DB-o)-1)<<o,this.data[this.t++]=s>>this.DB-o):this.data[this.t-1]|=s<<o,o+=r,o>=this.DB&&(o-=this.DB)}r==8&&t[0]&128&&(this.s=-1,o>0&&(this.data[this.t-1]|=(1<<this.DB-o)-1<<o)),this.clamp(),i&&P.ZERO.subTo(this,this)}function I5(){for(var t=this.s&this.DM;this.t>0&&this.data[this.t-1]==t;)--this.t}function R5(t){if(this.s<0)return"-"+this.negate().toString(t);var e;if(t==16)e=4;else if(t==8)e=3;else if(t==2)e=1;else if(t==32)e=5;else if(t==4)e=2;else return this.toRadix(t);var r=(1<<e)-1,n,i=!1,o="",s=this.t,a=this.DB-s*this.DB%e;if(s-- >0)for(a<this.DB&&(n=this.data[s]>>a)>0&&(i=!0,o=x_(n));s>=0;)a<e?(n=(this.data[s]&(1<<a)-1)<<e-a,n|=this.data[--s]>>(a+=this.DB-e)):(n=this.data[s]>>(a-=e)&r,a<=0&&(a+=this.DB,--s)),n>0&&(i=!0),i&&(o+=x_(n));return i?o:"0"}function B5(){var t=Se();return P.ZERO.subTo(this,t),t}function T5(){return this.s<0?this.negate():this}function k5(t){var e=this.s-t.s;if(e!=0)return e;var r=this.t;if(e=r-t.t,e!=0)return this.s<0?-e:e;for(;--r>=0;)if((e=this.data[r]-t.data[r])!=0)return e;return 0}function Xh(t){var e=1,r;return(r=t>>>16)!=0&&(t=r,e+=16),(r=t>>8)!=0&&(t=r,e+=8),(r=t>>4)!=0&&(t=r,e+=4),(r=t>>2)!=0&&(t=r,e+=2),(r=t>>1)!=0&&(t=r,e+=1),e}function C5(){return this.t<=0?0:this.DB*(this.t-1)+Xh(this.data[this.t-1]^this.s&this.DM)}function P5(t,e){var r;for(r=this.t-1;r>=0;--r)e.data[r+t]=this.data[r];for(r=t-1;r>=0;--r)e.data[r]=0;e.t=this.t+t,e.s=this.s}function D5(t,e){for(var r=t;r<this.t;++r)e.data[r-t]=this.data[r];e.t=Math.max(this.t-t,0),e.s=this.s}function N5(t,e){var r=t%this.DB,n=this.DB-r,i=(1<<n)-1,o=Math.floor(t/this.DB),s=this.s<<r&this.DM,a;for(a=this.t-1;a>=0;--a)e.data[a+o+1]=this.data[a]>>n|s,s=(this.data[a]&i)<<r;for(a=o-1;a>=0;--a)e.data[a]=0;e.data[o]=s,e.t=this.t+o+1,e.s=this.s,e.clamp()}function L5(t,e){e.s=this.s;var r=Math.floor(t/this.DB);if(r>=this.t){e.t=0;return}var n=t%this.DB,i=this.DB-n,o=(1<<n)-1;e.data[0]=this.data[r]>>n;for(var s=r+1;s<this.t;++s)e.data[s-r-1]|=(this.data[s]&o)<<i,e.data[s-r]=this.data[s]>>n;n>0&&(e.data[this.t-r-1]|=(this.s&o)<<i),e.t=this.t-r,e.clamp()}function O5(t,e){for(var r=0,n=0,i=Math.min(t.t,this.t);r<i;)n+=this.data[r]-t.data[r],e.data[r++]=n&this.DM,n>>=this.DB;if(t.t<this.t){for(n-=t.s;r<this.t;)n+=this.data[r],e.data[r++]=n&this.DM,n>>=this.DB;n+=this.s}else{for(n+=this.s;r<t.t;)n-=t.data[r],e.data[r++]=n&this.DM,n>>=this.DB;n-=t.s}e.s=n<0?-1:0,n<-1?e.data[r++]=this.DV+n:n>0&&(e.data[r++]=n),e.t=r,e.clamp()}function U5(t,e){var r=this.abs(),n=t.abs(),i=r.t;for(e.t=i+n.t;--i>=0;)e.data[i]=0;for(i=0;i<n.t;++i)e.data[i+r.t]=r.am(0,n.data[i],e,i,0,r.t);e.s=0,e.clamp(),this.s!=t.s&&P.ZERO.subTo(e,e)}function K5(t){for(var e=this.abs(),r=t.t=2*e.t;--r>=0;)t.data[r]=0;for(r=0;r<e.t-1;++r){var n=e.am(r,e.data[r],t,2*r,0,1);(t.data[r+e.t]+=e.am(r+1,2*e.data[r],t,2*r+1,n,e.t-r-1))>=e.DV&&(t.data[r+e.t]-=e.DV,t.data[r+e.t+1]=1)}t.t>0&&(t.data[t.t-1]+=e.am(r,e.data[r],t,2*r,0,1)),t.s=0,t.clamp()}function M5(t,e,r){var n=t.abs();if(!(n.t<=0)){var i=this.abs();if(i.t<n.t){e?.fromInt(0),r!=null&&this.copyTo(r);return}r==null&&(r=Se());var o=Se(),s=this.s,a=t.s,c=this.DB-Xh(n.data[n.t-1]);c>0?(n.lShiftTo(c,o),i.lShiftTo(c,r)):(n.copyTo(o),i.copyTo(r));var u=o.t,l=o.data[u-1];if(l!=0){var f=l*(1<<this.F1)+(u>1?o.data[u-2]>>this.F2:0),d=this.FV/f,p=(1<<this.F1)/f,h=1<<this.F2,m=r.t,y=m-u,g=e??Se();for(o.dlShiftTo(y,g),r.compareTo(g)>=0&&(r.data[r.t++]=1,r.subTo(g,r)),P.ONE.dlShiftTo(u,g),g.subTo(o,o);o.t<u;)o.data[o.t++]=0;for(;--y>=0;){var b=r.data[--m]==l?this.DM:Math.floor(r.data[m]*d+(r.data[m-1]+h)*p);if((r.data[m]+=o.am(0,b,r,y,0,u))<b)for(o.dlShiftTo(y,g),r.subTo(g,r);r.data[m]<--b;)r.subTo(g,r)}e!=null&&(r.drShiftTo(u,e),s!=a&&P.ZERO.subTo(e,e)),r.t=u,r.clamp(),c>0&&r.rShiftTo(c,r),s<0&&P.ZERO.subTo(r,r)}}}function F5(t){var e=Se();return this.abs().divRemTo(t,null,e),this.s<0&&e.compareTo(P.ZERO)>0&&t.subTo(e,e),e}function $o(t){this.m=t}function V5(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t}function H5(t){return t}function q5(t){t.divRemTo(this.m,null,t)}function $5(t,e,r){t.multiplyTo(e,r),this.reduce(r)}function z5(t,e){t.squareTo(e),this.reduce(e)}$o.prototype.convert=V5;$o.prototype.revert=H5;$o.prototype.reduce=q5;$o.prototype.mulTo=$5;$o.prototype.sqrTo=z5;function G5(){if(this.t<1)return 0;var t=this.data[0];if(!(t&1))return 0;var e=t&3;return e=e*(2-(t&15)*e)&15,e=e*(2-(t&255)*e)&255,e=e*(2-((t&65535)*e&65535))&65535,e=e*(2-t*e%this.DV)%this.DV,e>0?this.DV-e:-e}function zo(t){this.m=t,this.mp=t.invDigit(),this.mpl=this.mp&32767,this.mph=this.mp>>15,this.um=(1<<t.DB-15)-1,this.mt2=2*t.t}function W5(t){var e=Se();return t.abs().dlShiftTo(this.m.t,e),e.divRemTo(this.m,null,e),t.s<0&&e.compareTo(P.ZERO)>0&&this.m.subTo(e,e),e}function Y5(t){var e=Se();return t.copyTo(e),this.reduce(e),e}function j5(t){for(;t.t<=this.mt2;)t.data[t.t++]=0;for(var e=0;e<this.m.t;++e){var r=t.data[e]&32767,n=r*this.mpl+((r*this.mph+(t.data[e]>>15)*this.mpl&this.um)<<15)&t.DM;for(r=e+this.m.t,t.data[r]+=this.m.am(0,n,t,e,0,this.m.t);t.data[r]>=t.DV;)t.data[r]-=t.DV,t.data[++r]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)}function Q5(t,e){t.squareTo(e),this.reduce(e)}function J5(t,e,r){t.multiplyTo(e,r),this.reduce(r)}zo.prototype.convert=W5;zo.prototype.revert=Y5;zo.prototype.reduce=j5;zo.prototype.mulTo=J5;zo.prototype.sqrTo=Q5;function X5(){return(this.t>0?this.data[0]&1:this.s)==0}function Z5(t,e){if(t>4294967295||t<1)return P.ONE;var r=Se(),n=Se(),i=e.convert(this),o=Xh(t)-1;for(i.copyTo(r);--o>=0;)if(e.sqrTo(r,n),(t&1<<o)>0)e.mulTo(n,i,r);else{var s=r;r=n,n=s}return e.revert(r)}function eN(t,e){var r;return t<256||e.isEven()?r=new $o(e):r=new zo(e),this.exp(t,r)}P.prototype.copyTo=A5;P.prototype.fromInt=S5;P.prototype.fromString=_5;P.prototype.clamp=I5;P.prototype.dlShiftTo=P5;P.prototype.drShiftTo=D5;P.prototype.lShiftTo=N5;P.prototype.rShiftTo=L5;P.prototype.subTo=O5;P.prototype.multiplyTo=U5;P.prototype.squareTo=K5;P.prototype.divRemTo=M5;P.prototype.invDigit=G5;P.prototype.isEven=X5;P.prototype.exp=Z5;P.prototype.toString=R5;P.prototype.negate=B5;P.prototype.abs=T5;P.prototype.compareTo=k5;P.prototype.bitLength=C5;P.prototype.mod=F5;P.prototype.modPowInt=eN;P.ZERO=Ji(0);P.ONE=Ji(1);function tN(){var t=Se();return this.copyTo(t),t}function rN(){if(this.s<0){if(this.t==1)return this.data[0]-this.DV;if(this.t==0)return-1}else{if(this.t==1)return this.data[0];if(this.t==0)return 0}return(this.data[1]&(1<<32-this.DB)-1)<<this.DB|this.data[0]}function nN(){return this.t==0?this.s:this.data[0]<<24>>24}function iN(){return this.t==0?this.s:this.data[0]<<16>>16}function oN(t){return Math.floor(Math.LN2*this.DB/Math.log(t))}function sN(){return this.s<0?-1:this.t<=0||this.t==1&&this.data[0]<=0?0:1}function aN(t){if(t==null&&(t=10),this.signum()==0||t<2||t>36)return"0";var e=this.chunkSize(t),r=Math.pow(t,e),n=Ji(r),i=Se(),o=Se(),s="";for(this.divRemTo(n,i,o);i.signum()>0;)s=(r+o.intValue()).toString(t).substr(1)+s,i.divRemTo(n,i,o);return o.intValue().toString(t)+s}function cN(t,e){this.fromInt(0),e==null&&(e=10);for(var r=this.chunkSize(e),n=Math.pow(e,r),i=!1,o=0,s=0,a=0;a<t.length;++a){var c=v_(t,a);if(c<0){t.charAt(a)=="-"&&this.signum()==0&&(i=!0);continue}s=e*s+c,++o>=r&&(this.dMultiply(n),this.dAddOffset(s,0),o=0,s=0)}o>0&&(this.dMultiply(Math.pow(e,o)),this.dAddOffset(s,0)),i&&P.ZERO.subTo(this,this)}function uN(t,e,r){if(typeof e=="number")if(t<2)this.fromInt(1);else for(this.fromNumber(t,r),this.testBit(t-1)||this.bitwiseTo(P.ONE.shiftLeft(t-1),lg,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(e);)this.dAddOffset(2,0),this.bitLength()>t&&this.subTo(P.ONE.shiftLeft(t-1),this);else{var n=new Array,i=t&7;n.length=(t>>3)+1,e.nextBytes(n),i>0?n[0]&=(1<<i)-1:n[0]=0,this.fromString(n,256)}}function lN(){var t=this.t,e=new Array;e[0]=this.s;var r=this.DB-t*this.DB%8,n,i=0;if(t-- >0)for(r<this.DB&&(n=this.data[t]>>r)!=(this.s&this.DM)>>r&&(e[i++]=n|this.s<<this.DB-r);t>=0;)r<8?(n=(this.data[t]&(1<<r)-1)<<8-r,n|=this.data[--t]>>(r+=this.DB-8)):(n=this.data[t]>>(r-=8)&255,r<=0&&(r+=this.DB,--t)),n&128&&(n|=-256),i==0&&(this.s&128)!=(n&128)&&++i,(i>0||n!=this.s)&&(e[i++]=n);return e}function fN(t){return this.compareTo(t)==0}function hN(t){return this.compareTo(t)<0?this:t}function dN(t){return this.compareTo(t)>0?this:t}function pN(t,e,r){var n,i,o=Math.min(t.t,this.t);for(n=0;n<o;++n)r.data[n]=e(this.data[n],t.data[n]);if(t.t<this.t){for(i=t.s&this.DM,n=o;n<this.t;++n)r.data[n]=e(this.data[n],i);r.t=this.t}else{for(i=this.s&this.DM,n=o;n<t.t;++n)r.data[n]=e(i,t.data[n]);r.t=t.t}r.s=e(this.s,t.s),r.clamp()}function mN(t,e){return t&e}function yN(t){var e=Se();return this.bitwiseTo(t,mN,e),e}function lg(t,e){return t|e}function gN(t){var e=Se();return this.bitwiseTo(t,lg,e),e}function E_(t,e){return t^e}function bN(t){var e=Se();return this.bitwiseTo(t,E_,e),e}function A_(t,e){return t&~e}function wN(t){var e=Se();return this.bitwiseTo(t,A_,e),e}function xN(){for(var t=Se(),e=0;e<this.t;++e)t.data[e]=this.DM&~this.data[e];return t.t=this.t,t.s=~this.s,t}function vN(t){var e=Se();return t<0?this.rShiftTo(-t,e):this.lShiftTo(t,e),e}function EN(t){var e=Se();return t<0?this.lShiftTo(-t,e):this.rShiftTo(t,e),e}function AN(t){if(t==0)return-1;var e=0;return t&65535||(t>>=16,e+=16),t&255||(t>>=8,e+=8),t&15||(t>>=4,e+=4),t&3||(t>>=2,e+=2),t&1||++e,e}function SN(){for(var t=0;t<this.t;++t)if(this.data[t]!=0)return t*this.DB+AN(this.data[t]);return this.s<0?this.t*this.DB:-1}function _N(t){for(var e=0;t!=0;)t&=t-1,++e;return e}function IN(){for(var t=0,e=this.s&this.DM,r=0;r<this.t;++r)t+=_N(this.data[r]^e);return t}function RN(t){var e=Math.floor(t/this.DB);return e>=this.t?this.s!=0:(this.data[e]&1<<t%this.DB)!=0}function BN(t,e){var r=P.ONE.shiftLeft(t);return this.bitwiseTo(r,e,r),r}function TN(t){return this.changeBit(t,lg)}function kN(t){return this.changeBit(t,A_)}function CN(t){return this.changeBit(t,E_)}function PN(t,e){for(var r=0,n=0,i=Math.min(t.t,this.t);r<i;)n+=this.data[r]+t.data[r],e.data[r++]=n&this.DM,n>>=this.DB;if(t.t<this.t){for(n+=t.s;r<this.t;)n+=this.data[r],e.data[r++]=n&this.DM,n>>=this.DB;n+=this.s}else{for(n+=this.s;r<t.t;)n+=t.data[r],e.data[r++]=n&this.DM,n>>=this.DB;n+=t.s}e.s=n<0?-1:0,n>0?e.data[r++]=n:n<-1&&(e.data[r++]=this.DV+n),e.t=r,e.clamp()}function DN(t){var e=Se();return this.addTo(t,e),e}function NN(t){var e=Se();return this.subTo(t,e),e}function LN(t){var e=Se();return this.multiplyTo(t,e),e}function ON(t){var e=Se();return this.divRemTo(t,e,null),e}function UN(t){var e=Se();return this.divRemTo(t,null,e),e}function KN(t){var e=Se(),r=Se();return this.divRemTo(t,e,r),new Array(e,r)}function MN(t){this.data[this.t]=this.am(0,t-1,this,0,0,this.t),++this.t,this.clamp()}function FN(t,e){if(t!=0){for(;this.t<=e;)this.data[this.t++]=0;for(this.data[e]+=t;this.data[e]>=this.DV;)this.data[e]-=this.DV,++e>=this.t&&(this.data[this.t++]=0),++this.data[e]}}function au(){}function S_(t){return t}function VN(t,e,r){t.multiplyTo(e,r)}function HN(t,e){t.squareTo(e)}au.prototype.convert=S_;au.prototype.revert=S_;au.prototype.mulTo=VN;au.prototype.sqrTo=HN;function qN(t){return this.exp(t,new au)}function $N(t,e,r){var n=Math.min(this.t+t.t,e);for(r.s=0,r.t=n;n>0;)r.data[--n]=0;var i;for(i=r.t-this.t;n<i;++n)r.data[n+this.t]=this.am(0,t.data[n],r,n,0,this.t);for(i=Math.min(t.t,e);n<i;++n)this.am(0,t.data[n],r,n,0,e-n);r.clamp()}function zN(t,e,r){--e;var n=r.t=this.t+t.t-e;for(r.s=0;--n>=0;)r.data[n]=0;for(n=Math.max(e-this.t,0);n<t.t;++n)r.data[this.t+n-e]=this.am(e-n,t.data[n],r,0,0,this.t+n-e);r.clamp(),r.drShiftTo(1,r)}function La(t){this.r2=Se(),this.q3=Se(),P.ONE.dlShiftTo(2*t.t,this.r2),this.mu=this.r2.divide(t),this.m=t}function GN(t){if(t.s<0||t.t>2*this.m.t)return t.mod(this.m);if(t.compareTo(this.m)<0)return t;var e=Se();return t.copyTo(e),this.reduce(e),e}function WN(t){return t}function YN(t){for(t.drShiftTo(this.m.t-1,this.r2),t.t>this.m.t+1&&(t.t=this.m.t+1,t.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);t.compareTo(this.r2)<0;)t.dAddOffset(1,this.m.t+1);for(t.subTo(this.r2,t);t.compareTo(this.m)>=0;)t.subTo(this.m,t)}function jN(t,e){t.squareTo(e),this.reduce(e)}function QN(t,e,r){t.multiplyTo(e,r),this.reduce(r)}La.prototype.convert=GN;La.prototype.revert=WN;La.prototype.reduce=YN;La.prototype.mulTo=QN;La.prototype.sqrTo=jN;function JN(t,e){var r=t.bitLength(),n,i=Ji(1),o;if(r<=0)return i;r<18?n=1:r<48?n=3:r<144?n=4:r<768?n=5:n=6,r<8?o=new $o(e):e.isEven()?o=new La(e):o=new zo(e);var s=new Array,a=3,c=n-1,u=(1<<n)-1;if(s[1]=o.convert(this),n>1){var l=Se();for(o.sqrTo(s[1],l);a<=u;)s[a]=Se(),o.mulTo(l,s[a-2],s[a]),a+=2}var f=t.t-1,d,p=!0,h=Se(),m;for(r=Xh(t.data[f])-1;f>=0;){for(r>=c?d=t.data[f]>>r-c&u:(d=(t.data[f]&(1<<r+1)-1)<<c-r,f>0&&(d|=t.data[f-1]>>this.DB+r-c)),a=n;!(d&1);)d>>=1,--a;if((r-=a)<0&&(r+=this.DB,--f),p)s[d].copyTo(i),p=!1;else{for(;a>1;)o.sqrTo(i,h),o.sqrTo(h,i),a-=2;a>0?o.sqrTo(i,h):(m=i,i=h,h=m),o.mulTo(h,s[d],i)}for(;f>=0&&!(t.data[f]&1<<r);)o.sqrTo(i,h),m=i,i=h,h=m,--r<0&&(r=this.DB-1,--f)}return o.revert(i)}function XN(t){var e=this.s<0?this.negate():this.clone(),r=t.s<0?t.negate():t.clone();if(e.compareTo(r)<0){var n=e;e=r,r=n}var i=e.getLowestSetBit(),o=r.getLowestSetBit();if(o<0)return e;for(i<o&&(o=i),o>0&&(e.rShiftTo(o,e),r.rShiftTo(o,r));e.signum()>0;)(i=e.getLowestSetBit())>0&&e.rShiftTo(i,e),(i=r.getLowestSetBit())>0&&r.rShiftTo(i,r),e.compareTo(r)>=0?(e.subTo(r,e),e.rShiftTo(1,e)):(r.subTo(e,r),r.rShiftTo(1,r));return o>0&&r.lShiftTo(o,r),r}function ZN(t){if(t<=0)return 0;var e=this.DV%t,r=this.s<0?t-1:0;if(this.t>0)if(e==0)r=this.data[0]%t;else for(var n=this.t-1;n>=0;--n)r=(e*r+this.data[n])%t;return r}function eL(t){var e=t.isEven();if(this.isEven()&&e||t.signum()==0)return P.ZERO;for(var r=t.clone(),n=this.clone(),i=Ji(1),o=Ji(0),s=Ji(0),a=Ji(1);r.signum()!=0;){for(;r.isEven();)r.rShiftTo(1,r),e?((!i.isEven()||!o.isEven())&&(i.addTo(this,i),o.subTo(t,o)),i.rShiftTo(1,i)):o.isEven()||o.subTo(t,o),o.rShiftTo(1,o);for(;n.isEven();)n.rShiftTo(1,n),e?((!s.isEven()||!a.isEven())&&(s.addTo(this,s),a.subTo(t,a)),s.rShiftTo(1,s)):a.isEven()||a.subTo(t,a),a.rShiftTo(1,a);r.compareTo(n)>=0?(r.subTo(n,r),e&&i.subTo(s,i),o.subTo(a,o)):(n.subTo(r,n),e&&s.subTo(i,s),a.subTo(o,a))}if(n.compareTo(P.ONE)!=0)return P.ZERO;if(a.compareTo(t)>=0)return a.subtract(t);if(a.signum()<0)a.addTo(t,a);else return a;return a.signum()<0?a.add(t):a}var Yr=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509],tL=(1<<26)/Yr[Yr.length-1];function rL(t){var e,r=this.abs();if(r.t==1&&r.data[0]<=Yr[Yr.length-1]){for(e=0;e<Yr.length;++e)if(r.data[0]==Yr[e])return!0;return!1}if(r.isEven())return!1;for(e=1;e<Yr.length;){for(var n=Yr[e],i=e+1;i<Yr.length&&n<tL;)n*=Yr[i++];for(n=r.modInt(n);e<i;)if(n%Yr[e++]==0)return!1}return r.millerRabin(t)}function nL(t){var e=this.subtract(P.ONE),r=e.getLowestSetBit();if(r<=0)return!1;for(var n=e.shiftRight(r),i=iL(),o,s=0;s<t;++s){do o=new P(this.bitLength(),i);while(o.compareTo(P.ONE)<=0||o.compareTo(e)>=0);var a=o.modPow(n,this);if(a.compareTo(P.ONE)!=0&&a.compareTo(e)!=0){for(var c=1;c++<r&&a.compareTo(e)!=0;)if(a=a.modPowInt(2,this),a.compareTo(P.ONE)==0)return!1;if(a.compareTo(e)!=0)return!1}}return!0}function iL(){return{nextBytes:function(t){for(var e=0;e<t.length;++e)t[e]=Math.floor(Math.random()*256)}}}P.prototype.chunkSize=oN;P.prototype.toRadix=aN;P.prototype.fromRadix=cN;P.prototype.fromNumber=uN;P.prototype.bitwiseTo=pN;P.prototype.changeBit=BN;P.prototype.addTo=PN;P.prototype.dMultiply=MN;P.prototype.dAddOffset=FN;P.prototype.multiplyLowerTo=$N;P.prototype.multiplyUpperTo=zN;P.prototype.modInt=ZN;P.prototype.millerRabin=nL;P.prototype.clone=tN;P.prototype.intValue=rN;P.prototype.byteValue=nN;P.prototype.shortValue=iN;P.prototype.signum=sN;P.prototype.toByteArray=lN;P.prototype.equals=fN;P.prototype.min=hN;P.prototype.max=dN;P.prototype.and=yN;P.prototype.or=gN;P.prototype.xor=bN;P.prototype.andNot=wN;P.prototype.not=xN;P.prototype.shiftLeft=vN;P.prototype.shiftRight=EN;P.prototype.getLowestSetBit=SN;P.prototype.bitCount=IN;P.prototype.testBit=RN;P.prototype.setBit=TN;P.prototype.clearBit=kN;P.prototype.flipBit=CN;P.prototype.add=DN;P.prototype.subtract=NN;P.prototype.multiply=LN;P.prototype.divide=ON;P.prototype.remainder=UN;P.prototype.divideAndRemainder=KN;P.prototype.modPow=JN;P.prototype.modInverse=eL;P.prototype.pow=qN;P.prototype.gcd=XN;P.prototype.isProbablePrime=rL});var k_=re((Nse,T_)=>{var xn=Le();qo();ft();var R_=T_.exports=xn.sha1=xn.sha1||{};xn.md.sha1=xn.md.algorithms.sha1=R_;R_.create=function(){B_||oL();var t=null,e=xn.util.createBuffer(),r=new Array(80),n={algorithm:"sha1",blockLength:64,digestLength:20,messageLength:0,fullMessageLength:null,messageLengthSize:8};return n.start=function(){n.messageLength=0,n.fullMessageLength=n.messageLength64=[];for(var i=n.messageLengthSize/4,o=0;o<i;++o)n.fullMessageLength.push(0);return e=xn.util.createBuffer(),t={h0:1732584193,h1:4023233417,h2:2562383102,h3:271733878,h4:3285377520},n},n.start(),n.update=function(i,o){o==="utf8"&&(i=xn.util.encodeUtf8(i));var s=i.length;n.messageLength+=s,s=[s/4294967296>>>0,s>>>0];for(var a=n.fullMessageLength.length-1;a>=0;--a)n.fullMessageLength[a]+=s[1],s[1]=s[0]+(n.fullMessageLength[a]/4294967296>>>0),n.fullMessageLength[a]=n.fullMessageLength[a]>>>0,s[0]=s[1]/4294967296>>>0;return e.putBytes(i),I_(t,r,e),(e.read>2048||e.length()===0)&&e.compact(),n},n.digest=function(){var i=xn.util.createBuffer();i.putBytes(e.bytes());var o=n.fullMessageLength[n.fullMessageLength.length-1]+n.messageLengthSize,s=o&n.blockLength-1;i.putBytes(fg.substr(0,n.blockLength-s));for(var a,c,u=n.fullMessageLength[0]*8,l=0;l<n.fullMessageLength.length-1;++l)a=n.fullMessageLength[l+1]*8,c=a/4294967296>>>0,u+=c,i.putInt32(u>>>0),u=a>>>0;i.putInt32(u);var f={h0:t.h0,h1:t.h1,h2:t.h2,h3:t.h3,h4:t.h4};I_(f,r,i);var d=xn.util.createBuffer();return d.putInt32(f.h0),d.putInt32(f.h1),d.putInt32(f.h2),d.putInt32(f.h3),d.putInt32(f.h4),d},n};var fg=null,B_=!1;function oL(){fg="\x80",fg+=xn.util.fillString("\0",64),B_=!0}function I_(t,e,r){for(var n,i,o,s,a,c,u,l,f=r.length();f>=64;){for(i=t.h0,o=t.h1,s=t.h2,a=t.h3,c=t.h4,l=0;l<16;++l)n=r.getInt32(),e[l]=n,u=a^o&(s^a),n=(i<<5|i>>>27)+u+c+1518500249+n,c=a,a=s,s=(o<<30|o>>>2)>>>0,o=i,i=n;for(;l<20;++l)n=e[l-3]^e[l-8]^e[l-14]^e[l-16],n=n<<1|n>>>31,e[l]=n,u=a^o&(s^a),n=(i<<5|i>>>27)+u+c+1518500249+n,c=a,a=s,s=(o<<30|o>>>2)>>>0,o=i,i=n;for(;l<32;++l)n=e[l-3]^e[l-8]^e[l-14]^e[l-16],n=n<<1|n>>>31,e[l]=n,u=o^s^a,n=(i<<5|i>>>27)+u+c+1859775393+n,c=a,a=s,s=(o<<30|o>>>2)>>>0,o=i,i=n;for(;l<40;++l)n=e[l-6]^e[l-16]^e[l-28]^e[l-32],n=n<<2|n>>>30,e[l]=n,u=o^s^a,n=(i<<5|i>>>27)+u+c+1859775393+n,c=a,a=s,s=(o<<30|o>>>2)>>>0,o=i,i=n;for(;l<60;++l)n=e[l-6]^e[l-16]^e[l-28]^e[l-32],n=n<<2|n>>>30,e[l]=n,u=o&s|a&(o^s),n=(i<<5|i>>>27)+u+c+2400959708+n,c=a,a=s,s=(o<<30|o>>>2)>>>0,o=i,i=n;for(;l<80;++l)n=e[l-6]^e[l-16]^e[l-28]^e[l-32],n=n<<2|n>>>30,e[l]=n,u=o^s^a,n=(i<<5|i>>>27)+u+c+3395469782+n,c=a,a=s,s=(o<<30|o>>>2)>>>0,o=i,i=n;t.h0=t.h0+i|0,t.h1=t.h1+o|0,t.h2=t.h2+s|0,t.h3=t.h3+a|0,t.h4=t.h4+c|0,f-=64}}});var D_=re((Lse,P_)=>{var vn=Le();ft();su();k_();var C_=P_.exports=vn.pkcs1=vn.pkcs1||{};C_.encode_rsa_oaep=function(t,e,r){var n,i,o,s;typeof r=="string"?(n=r,i=arguments[3]||void 0,o=arguments[4]||void 0):r&&(n=r.label||void 0,i=r.seed||void 0,o=r.md||void 0,r.mgf1&&r.mgf1.md&&(s=r.mgf1.md)),o?o.start():o=vn.md.sha1.create(),s||(s=o);var a=Math.ceil(t.n.bitLength()/8),c=a-2*o.digestLength-2;if(e.length>c){var u=new Error("RSAES-OAEP input message length is too long.");throw u.length=e.length,u.maxLength=c,u}n||(n=""),o.update(n,"raw");for(var l=o.digest(),f="",d=c-e.length,p=0;p<d;p++)f+="\0";var h=l.getBytes()+f+""+e;if(!i)i=vn.random.getBytes(o.digestLength);else if(i.length!==o.digestLength){var u=new Error("Invalid RSAES-OAEP seed. The seed length must match the digest length.");throw u.seedLength=i.length,u.digestLength=o.digestLength,u}var m=ed(i,a-o.digestLength-1,s),y=vn.util.xorBytes(h,m,h.length),g=ed(y,o.digestLength,s),b=vn.util.xorBytes(i,g,i.length);return"\0"+b+y};C_.decode_rsa_oaep=function(t,e,r){var n,i,o;typeof r=="string"?(n=r,i=arguments[3]||void 0):r&&(n=r.label||void 0,i=r.md||void 0,r.mgf1&&r.mgf1.md&&(o=r.mgf1.md));var s=Math.ceil(t.n.bitLength()/8);if(e.length!==s){var y=new Error("RSAES-OAEP encoded message length is invalid.");throw y.length=e.length,y.expectedLength=s,y}if(i===void 0?i=vn.md.sha1.create():i.start(),o||(o=i),s<2*i.digestLength+2)throw new Error("RSAES-OAEP key is too short for the hash function.");n||(n=""),i.update(n,"raw");for(var a=i.digest().getBytes(),c=e.charAt(0),u=e.substring(1,i.digestLength+1),l=e.substring(1+i.digestLength),f=ed(l,i.digestLength,o),d=vn.util.xorBytes(u,f,u.length),p=ed(d,s-i.digestLength-1,o),h=vn.util.xorBytes(l,p,l.length),m=h.substring(0,i.digestLength),y=c!=="\0",g=0;g<i.digestLength;++g)y|=a.charAt(g)!==m.charAt(g);for(var b=1,w=i.digestLength,_=i.digestLength;_<h.length;_++){var E=h.charCodeAt(_),A=E&1^1,B=b?65534:0;y|=E&B,b=b&A,w+=b}if(y||h.charCodeAt(w)!==1)throw new Error("Invalid RSAES-OAEP padding.");return h.substring(w+1)};function ed(t,e,r){r||(r=vn.md.sha1.create());for(var n="",i=Math.ceil(e/r.digestLength),o=0;o<i;++o){var s=String.fromCharCode(o>>24&255,o>>16&255,o>>8&255,o&255);r.start(),r.update(t+s),n+=r.digest().getBytes()}return n.substring(0,e)}});var N_=re((Ose,hg)=>{var Xi=Le();ft();Zh();su();(function(){if(Xi.prime){hg.exports=Xi.prime;return}var t=hg.exports=Xi.prime=Xi.prime||{},e=Xi.jsbn.BigInteger,r=[6,4,2,4,2,4,6,2],n=new e(null);n.fromInt(30);var i=function(f,d){return f|d};t.generateProbablePrime=function(f,d,p){typeof d=="function"&&(p=d,d={}),d=d||{};var h=d.algorithm||"PRIMEINC";typeof h=="string"&&(h={name:h}),h.options=h.options||{};var m=d.prng||Xi.random,y={nextBytes:function(g){for(var b=m.getBytesSync(g.length),w=0;w<g.length;++w)g[w]=b.charCodeAt(w)}};if(h.name==="PRIMEINC")return o(f,y,h.options,p);throw new Error("Invalid prime generation algorithm: "+h.name)};function o(f,d,p,h){return"workers"in p?c(f,d,p,h):s(f,d,p,h)}function s(f,d,p,h){var m=u(f,d),y=0,g=l(m.bitLength());"millerRabinTests"in p&&(g=p.millerRabinTests);var b=10;"maxBlockTime"in p&&(b=p.maxBlockTime),a(m,f,d,y,g,b,h)}function a(f,d,p,h,m,y,g){var b=+new Date;do{if(f.bitLength()>d&&(f=u(d,p)),f.isProbablePrime(m))return g(null,f);f.dAddOffset(r[h++%8],0)}while(y<0||+new Date-b<y);Xi.util.setImmediate(function(){a(f,d,p,h,m,y,g)})}function c(f,d,p,h){if(typeof Worker>"u")return s(f,d,p,h);var m=u(f,d),y=p.workers,g=p.workLoad||100,b=g*30/8,w=p.workerScript||"forge/prime.worker.js";if(y===-1)return Xi.util.estimateCores(function(E,A){E&&(A=2),y=A-1,_()});_();function _(){y=Math.max(1,y);for(var E=[],A=0;A<y;++A)E[A]=new Worker(w);for(var B=y,A=0;A<y;++A)E[A].addEventListener("message",L);var I=!1;function L(H){if(!I){--B;var F=H.data;if(F.found){for(var $=0;$<E.length;++$)E[$].terminate();return I=!0,h(null,new e(F.prime,16))}m.bitLength()>f&&(m=u(f,d));var te=m.toString(16);H.target.postMessage({hex:te,workLoad:g}),m.dAddOffset(b,0)}}}}function u(f,d){var p=new e(f,d),h=f-1;return p.testBit(h)||p.bitwiseTo(e.ONE.shiftLeft(h),i,p),p.dAddOffset(31-p.mod(n).byteValue(),0),p}function l(f){return f<=100?27:f<=150?18:f<=200?15:f<=250?12:f<=300?9:f<=350?8:f<=400?7:f<=500?6:f<=600?5:f<=800?4:f<=1250?3:2}})()});var rd=re((Use,V_)=>{var ee=Le();ou();Zh();Fh();D_();N_();su();ft();typeof Ae>"u"&&(Ae=ee.jsbn.BigInteger);var Ae,dg=ee.util.isNodejs?Wh():null,R=ee.asn1,Nr=ee.util;ee.pki=ee.pki||{};V_.exports=ee.pki.rsa=ee.rsa=ee.rsa||{};var ue=ee.pki,sL=[6,4,2,4,2,4,6,2],aL={name:"PrivateKeyInfo",tagClass:R.Class.UNIVERSAL,type:R.Type.SEQUENCE,constructed:!0,value:[{name:"PrivateKeyInfo.version",tagClass:R.Class.UNIVERSAL,type:R.Type.INTEGER,constructed:!1,capture:"privateKeyVersion"},{name:"PrivateKeyInfo.privateKeyAlgorithm",tagClass:R.Class.UNIVERSAL,type:R.Type.SEQUENCE,constructed:!0,value:[{name:"AlgorithmIdentifier.algorithm",tagClass:R.Class.UNIVERSAL,type:R.Type.OID,constructed:!1,capture:"privateKeyOid"}]},{name:"PrivateKeyInfo",tagClass:R.Class.UNIVERSAL,type:R.Type.OCTETSTRING,constructed:!1,capture:"privateKey"}]},cL={name:"RSAPrivateKey",tagClass:R.Class.UNIVERSAL,type:R.Type.SEQUENCE,constructed:!0,value:[{name:"RSAPrivateKey.version",tagClass:R.Class.UNIVERSAL,type:R.Type.INTEGER,constructed:!1,capture:"privateKeyVersion"},{name:"RSAPrivateKey.modulus",tagClass:R.Class.UNIVERSAL,type:R.Type.INTEGER,constructed:!1,capture:"privateKeyModulus"},{name:"RSAPrivateKey.publicExponent",tagClass:R.Class.UNIVERSAL,type:R.Type.INTEGER,constructed:!1,capture:"privateKeyPublicExponent"},{name:"RSAPrivateKey.privateExponent",tagClass:R.Class.UNIVERSAL,type:R.Type.INTEGER,constructed:!1,capture:"privateKeyPrivateExponent"},{name:"RSAPrivateKey.prime1",tagClass:R.Class.UNIVERSAL,type:R.Type.INTEGER,constructed:!1,capture:"privateKeyPrime1"},{name:"RSAPrivateKey.prime2",tagClass:R.Class.UNIVERSAL,type:R.Type.INTEGER,constructed:!1,capture:"privateKeyPrime2"},{name:"RSAPrivateKey.exponent1",tagClass:R.Class.UNIVERSAL,type:R.Type.INTEGER,constructed:!1,capture:"privateKeyExponent1"},{name:"RSAPrivateKey.exponent2",tagClass:R.Class.UNIVERSAL,type:R.Type.INTEGER,constructed:!1,capture:"privateKeyExponent2"},{name:"RSAPrivateKey.coefficient",tagClass:R.Class.UNIVERSAL,type:R.Type.INTEGER,constructed:!1,capture:"privateKeyCoefficient"}]},uL={name:"RSAPublicKey",tagClass:R.Class.UNIVERSAL,type:R.Type.SEQUENCE,constructed:!0,value:[{name:"RSAPublicKey.modulus",tagClass:R.Class.UNIVERSAL,type:R.Type.INTEGER,constructed:!1,capture:"publicKeyModulus"},{name:"RSAPublicKey.exponent",tagClass:R.Class.UNIVERSAL,type:R.Type.INTEGER,constructed:!1,capture:"publicKeyExponent"}]},lL=ee.pki.rsa.publicKeyValidator={name:"SubjectPublicKeyInfo",tagClass:R.Class.UNIVERSAL,type:R.Type.SEQUENCE,constructed:!0,captureAsn1:"subjectPublicKeyInfo",value:[{name:"SubjectPublicKeyInfo.AlgorithmIdentifier",tagClass:R.Class.UNIVERSAL,type:R.Type.SEQUENCE,constructed:!0,value:[{name:"AlgorithmIdentifier.algorithm",tagClass:R.Class.UNIVERSAL,type:R.Type.OID,constructed:!1,capture:"publicKeyOid"}]},{name:"SubjectPublicKeyInfo.subjectPublicKey",tagClass:R.Class.UNIVERSAL,type:R.Type.BITSTRING,constructed:!1,value:[{name:"SubjectPublicKeyInfo.subjectPublicKey.RSAPublicKey",tagClass:R.Class.UNIVERSAL,type:R.Type.SEQUENCE,constructed:!0,optional:!0,captureAsn1:"rsaPublicKey"}]}]},fL={name:"DigestInfo",tagClass:R.Class.UNIVERSAL,type:R.Type.SEQUENCE,constructed:!0,value:[{name:"DigestInfo.DigestAlgorithm",tagClass:R.Class.UNIVERSAL,type:R.Type.SEQUENCE,constructed:!0,value:[{name:"DigestInfo.DigestAlgorithm.algorithmIdentifier",tagClass:R.Class.UNIVERSAL,type:R.Type.OID,constructed:!1,capture:"algorithmIdentifier"},{name:"DigestInfo.DigestAlgorithm.parameters",tagClass:R.Class.UNIVERSAL,type:R.Type.NULL,capture:"parameters",optional:!0,constructed:!1}]},{name:"DigestInfo.digest",tagClass:R.Class.UNIVERSAL,type:R.Type.OCTETSTRING,constructed:!1,capture:"digest"}]},hL=function(t){var e;if(t.algorithm in ue.oids)e=ue.oids[t.algorithm];else{var r=new Error("Unknown message digest algorithm.");throw r.algorithm=t.algorithm,r}var n=R.oidToDer(e).getBytes(),i=R.create(R.Class.UNIVERSAL,R.Type.SEQUENCE,!0,[]),o=R.create(R.Class.UNIVERSAL,R.Type.SEQUENCE,!0,[]);o.value.push(R.create(R.Class.UNIVERSAL,R.Type.OID,!1,n)),o.value.push(R.create(R.Class.UNIVERSAL,R.Type.NULL,!1,""));var s=R.create(R.Class.UNIVERSAL,R.Type.OCTETSTRING,!1,t.digest().getBytes());return i.value.push(o),i.value.push(s),R.toDer(i).getBytes()},M_=function(t,e,r){if(r)return t.modPow(e.e,e.n);if(!e.p||!e.q)return t.modPow(e.d,e.n);e.dP||(e.dP=e.d.mod(e.p.subtract(Ae.ONE))),e.dQ||(e.dQ=e.d.mod(e.q.subtract(Ae.ONE))),e.qInv||(e.qInv=e.q.modInverse(e.p));var n;do n=new Ae(ee.util.bytesToHex(ee.random.getBytes(e.n.bitLength()/8)),16);while(n.compareTo(e.n)>=0||!n.gcd(e.n).equals(Ae.ONE));t=t.multiply(n.modPow(e.e,e.n)).mod(e.n);for(var i=t.mod(e.p).modPow(e.dP,e.p),o=t.mod(e.q).modPow(e.dQ,e.q);i.compareTo(o)<0;)i=i.add(e.p);var s=i.subtract(o).multiply(e.qInv).mod(e.p).multiply(e.q).add(o);return s=s.multiply(n.modInverse(e.n)).mod(e.n),s};ue.rsa.encrypt=function(t,e,r){var n=r,i,o=Math.ceil(e.n.bitLength()/8);r!==!1&&r!==!0?(n=r===2,i=F_(t,e,r)):(i=ee.util.createBuffer(),i.putBytes(t));for(var s=new Ae(i.toHex(),16),a=M_(s,e,n),c=a.toString(16),u=ee.util.createBuffer(),l=o-Math.ceil(c.length/2);l>0;)u.putByte(0),--l;return u.putBytes(ee.util.hexToBytes(c)),u.getBytes()};ue.rsa.decrypt=function(t,e,r,n){var i=Math.ceil(e.n.bitLength()/8);if(t.length!==i){var o=new Error("Encrypted message length is invalid.");throw o.length=t.length,o.expected=i,o}var s=new Ae(ee.util.createBuffer(t).toHex(),16);if(s.compareTo(e.n)>=0)throw new Error("Encrypted message is invalid.");for(var a=M_(s,e,r),c=a.toString(16),u=ee.util.createBuffer(),l=i-Math.ceil(c.length/2);l>0;)u.putByte(0),--l;return u.putBytes(ee.util.hexToBytes(c)),n!==!1?td(u.getBytes(),e,r):u.getBytes()};ue.rsa.createKeyPairGenerationState=function(t,e,r){typeof t=="string"&&(t=parseInt(t,10)),t=t||2048,r=r||{};var n=r.prng||ee.random,i={nextBytes:function(a){for(var c=n.getBytesSync(a.length),u=0;u<a.length;++u)a[u]=c.charCodeAt(u)}},o=r.algorithm||"PRIMEINC",s;if(o==="PRIMEINC")s={algorithm:o,state:0,bits:t,rng:i,eInt:e||65537,e:new Ae(null),p:null,q:null,qBits:t>>1,pBits:t-(t>>1),pqState:0,num:null,keys:null},s.e.fromInt(s.eInt);else throw new Error("Invalid key generation algorithm: "+o);return s};ue.rsa.stepKeyPairGenerationState=function(t,e){"algorithm"in t||(t.algorithm="PRIMEINC");var r=new Ae(null);r.fromInt(30);for(var n=0,i=function(f,d){return f|d},o=+new Date,s,a=0;t.keys===null&&(e<=0||a<e);){if(t.state===0){var c=t.p===null?t.pBits:t.qBits,u=c-1;t.pqState===0?(t.num=new Ae(c,t.rng),t.num.testBit(u)||t.num.bitwiseTo(Ae.ONE.shiftLeft(u),i,t.num),t.num.dAddOffset(31-t.num.mod(r).byteValue(),0),n=0,++t.pqState):t.pqState===1?t.num.bitLength()>c?t.pqState=0:t.num.isProbablePrime(pL(t.num.bitLength()))?++t.pqState:t.num.dAddOffset(sL[n++%8],0):t.pqState===2?t.pqState=t.num.subtract(Ae.ONE).gcd(t.e).compareTo(Ae.ONE)===0?3:0:t.pqState===3&&(t.pqState=0,t.p===null?t.p=t.num:t.q=t.num,t.p!==null&&t.q!==null&&++t.state,t.num=null)}else if(t.state===1)t.p.compareTo(t.q)<0&&(t.num=t.p,t.p=t.q,t.q=t.num),++t.state;else if(t.state===2)t.p1=t.p.subtract(Ae.ONE),t.q1=t.q.subtract(Ae.ONE),t.phi=t.p1.multiply(t.q1),++t.state;else if(t.state===3)t.phi.gcd(t.e).compareTo(Ae.ONE)===0?++t.state:(t.p=null,t.q=null,t.state=0);else if(t.state===4)t.n=t.p.multiply(t.q),t.n.bitLength()===t.bits?++t.state:(t.q=null,t.state=0);else if(t.state===5){var l=t.e.modInverse(t.phi);t.keys={privateKey:ue.rsa.setPrivateKey(t.n,t.e,l,t.p,t.q,l.mod(t.p1),l.mod(t.q1),t.q.modInverse(t.p)),publicKey:ue.rsa.setPublicKey(t.n,t.e)}}s=+new Date,a+=s-o,o=s}return t.keys!==null};ue.rsa.generateKeyPair=function(t,e,r,n){if(arguments.length===1?typeof t=="object"?(r=t,t=void 0):typeof t=="function"&&(n=t,t=void 0):arguments.length===2?typeof t=="number"?typeof e=="function"?(n=e,e=void 0):typeof e!="number"&&(r=e,e=void 0):(r=t,n=e,t=void 0,e=void 0):arguments.length===3&&(typeof e=="number"?typeof r=="function"&&(n=r,r=void 0):(n=r,r=e,e=void 0)),r=r||{},t===void 0&&(t=r.bits||2048),e===void 0&&(e=r.e||65537),!ee.options.usePureJavaScript&&!r.prng&&t>=256&&t<=16384&&(e===65537||e===3)){if(n){if(L_("generateKeyPair"))return dg.generateKeyPair("rsa",{modulusLength:t,publicExponent:e,publicKeyEncoding:{type:"spki",format:"pem"},privateKeyEncoding:{type:"pkcs8",format:"pem"}},function(a,c,u){if(a)return n(a);n(null,{privateKey:ue.privateKeyFromPem(u),publicKey:ue.publicKeyFromPem(c)})});if(O_("generateKey")&&O_("exportKey"))return Nr.globalScope.crypto.subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:t,publicExponent:K_(e),hash:{name:"SHA-256"}},!0,["sign","verify"]).then(function(a){return Nr.globalScope.crypto.subtle.exportKey("pkcs8",a.privateKey)}).then(void 0,function(a){n(a)}).then(function(a){if(a){var c=ue.privateKeyFromAsn1(R.fromDer(ee.util.createBuffer(a)));n(null,{privateKey:c,publicKey:ue.setRsaPublicKey(c.n,c.e)})}});if(U_("generateKey")&&U_("exportKey")){var i=Nr.globalScope.msCrypto.subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:t,publicExponent:K_(e),hash:{name:"SHA-256"}},!0,["sign","verify"]);i.oncomplete=function(a){var c=a.target.result,u=Nr.globalScope.msCrypto.subtle.exportKey("pkcs8",c.privateKey);u.oncomplete=function(l){var f=l.target.result,d=ue.privateKeyFromAsn1(R.fromDer(ee.util.createBuffer(f)));n(null,{privateKey:d,publicKey:ue.setRsaPublicKey(d.n,d.e)})},u.onerror=function(l){n(l)}},i.onerror=function(a){n(a)};return}}else if(L_("generateKeyPairSync")){var o=dg.generateKeyPairSync("rsa",{modulusLength:t,publicExponent:e,publicKeyEncoding:{type:"spki",format:"pem"},privateKeyEncoding:{type:"pkcs8",format:"pem"}});return{privateKey:ue.privateKeyFromPem(o.privateKey),publicKey:ue.publicKeyFromPem(o.publicKey)}}}var s=ue.rsa.createKeyPairGenerationState(t,e,r);if(!n)return ue.rsa.stepKeyPairGenerationState(s,0),s.keys;dL(s,r,n)};ue.setRsaPublicKey=ue.rsa.setPublicKey=function(t,e){var r={n:t,e};return r.encrypt=function(n,i,o){if(typeof i=="string"?i=i.toUpperCase():i===void 0&&(i="RSAES-PKCS1-V1_5"),i==="RSAES-PKCS1-V1_5")i={encode:function(a,c,u){return F_(a,c,2).getBytes()}};else if(i==="RSA-OAEP"||i==="RSAES-OAEP")i={encode:function(a,c){return ee.pkcs1.encode_rsa_oaep(c,a,o)}};else if(["RAW","NONE","NULL",null].indexOf(i)!==-1)i={encode:function(a){return a}};else if(typeof i=="string")throw new Error('Unsupported encryption scheme: "'+i+'".');var s=i.encode(n,r,!0);return ue.rsa.encrypt(s,r,!0)},r.verify=function(n,i,o,s){typeof o=="string"?o=o.toUpperCase():o===void 0&&(o="RSASSA-PKCS1-V1_5"),s===void 0&&(s={_parseAllDigestBytes:!0}),"_parseAllDigestBytes"in s||(s._parseAllDigestBytes=!0),o==="RSASSA-PKCS1-V1_5"?o={verify:function(c,u){u=td(u,r,!0);var l=R.fromDer(u,{parseAllBytes:s._parseAllDigestBytes}),f={},d=[];if(!R.validate(l,fL,f,d)){var p=new Error("ASN.1 object does not contain a valid RSASSA-PKCS1-v1_5 DigestInfo value.");throw p.errors=d,p}var h=R.derToOid(f.algorithmIdentifier);if(!(h===ee.oids.md2||h===ee.oids.md5||h===ee.oids.sha1||h===ee.oids.sha224||h===ee.oids.sha256||h===ee.oids.sha384||h===ee.oids.sha512||h===ee.oids["sha512-224"]||h===ee.oids["sha512-256"])){var p=new Error("Unknown RSASSA-PKCS1-v1_5 DigestAlgorithm identifier.");throw p.oid=h,p}if((h===ee.oids.md2||h===ee.oids.md5)&&!("parameters"in f))throw new Error("ASN.1 object does not contain a valid RSASSA-PKCS1-v1_5 DigestInfo value. Missing algorithm identifer NULL parameters.");return c===f.digest}}:(o==="NONE"||o==="NULL"||o===null)&&(o={verify:function(c,u){return u=td(u,r,!0),c===u}});var a=ue.rsa.decrypt(i,r,!0,!1);return o.verify(n,a,r.n.bitLength())},r};ue.setRsaPrivateKey=ue.rsa.setPrivateKey=function(t,e,r,n,i,o,s,a){var c={n:t,e,d:r,p:n,q:i,dP:o,dQ:s,qInv:a};return c.decrypt=function(u,l,f){typeof l=="string"?l=l.toUpperCase():l===void 0&&(l="RSAES-PKCS1-V1_5");var d=ue.rsa.decrypt(u,c,!1,!1);if(l==="RSAES-PKCS1-V1_5")l={decode:td};else if(l==="RSA-OAEP"||l==="RSAES-OAEP")l={decode:function(p,h){return ee.pkcs1.decode_rsa_oaep(h,p,f)}};else if(["RAW","NONE","NULL",null].indexOf(l)!==-1)l={decode:function(p){return p}};else throw new Error('Unsupported encryption scheme: "'+l+'".');return l.decode(d,c,!1)},c.sign=function(u,l){var f=!1;typeof l=="string"&&(l=l.toUpperCase()),l===void 0||l==="RSASSA-PKCS1-V1_5"?(l={encode:hL},f=1):(l==="NONE"||l==="NULL"||l===null)&&(l={encode:function(){return u}},f=1);var d=l.encode(u,c.n.bitLength());return ue.rsa.encrypt(d,c,f)},c};ue.wrapRsaPrivateKey=function(t){return R.create(R.Class.UNIVERSAL,R.Type.SEQUENCE,!0,[R.create(R.Class.UNIVERSAL,R.Type.INTEGER,!1,R.integerToDer(0).getBytes()),R.create(R.Class.UNIVERSAL,R.Type.SEQUENCE,!0,[R.create(R.Class.UNIVERSAL,R.Type.OID,!1,R.oidToDer(ue.oids.rsaEncryption).getBytes()),R.create(R.Class.UNIVERSAL,R.Type.NULL,!1,"")]),R.create(R.Class.UNIVERSAL,R.Type.OCTETSTRING,!1,R.toDer(t).getBytes())])};ue.privateKeyFromAsn1=function(t){var e={},r=[];if(R.validate(t,aL,e,r)&&(t=R.fromDer(ee.util.createBuffer(e.privateKey))),e={},r=[],!R.validate(t,cL,e,r)){var n=new Error("Cannot read private key. ASN.1 object does not contain an RSAPrivateKey.");throw n.errors=r,n}var i,o,s,a,c,u,l,f;return i=ee.util.createBuffer(e.privateKeyModulus).toHex(),o=ee.util.createBuffer(e.privateKeyPublicExponent).toHex(),s=ee.util.createBuffer(e.privateKeyPrivateExponent).toHex(),a=ee.util.createBuffer(e.privateKeyPrime1).toHex(),c=ee.util.createBuffer(e.privateKeyPrime2).toHex(),u=ee.util.createBuffer(e.privateKeyExponent1).toHex(),l=ee.util.createBuffer(e.privateKeyExponent2).toHex(),f=ee.util.createBuffer(e.privateKeyCoefficient).toHex(),ue.setRsaPrivateKey(new Ae(i,16),new Ae(o,16),new Ae(s,16),new Ae(a,16),new Ae(c,16),new Ae(u,16),new Ae(l,16),new Ae(f,16))};ue.privateKeyToAsn1=ue.privateKeyToRSAPrivateKey=function(t){return R.create(R.Class.UNIVERSAL,R.Type.SEQUENCE,!0,[R.create(R.Class.UNIVERSAL,R.Type.INTEGER,!1,R.integerToDer(0).getBytes()),R.create(R.Class.UNIVERSAL,R.Type.INTEGER,!1,En(t.n)),R.create(R.Class.UNIVERSAL,R.Type.INTEGER,!1,En(t.e)),R.create(R.Class.UNIVERSAL,R.Type.INTEGER,!1,En(t.d)),R.create(R.Class.UNIVERSAL,R.Type.INTEGER,!1,En(t.p)),R.create(R.Class.UNIVERSAL,R.Type.INTEGER,!1,En(t.q)),R.create(R.Class.UNIVERSAL,R.Type.INTEGER,!1,En(t.dP)),R.create(R.Class.UNIVERSAL,R.Type.INTEGER,!1,En(t.dQ)),R.create(R.Class.UNIVERSAL,R.Type.INTEGER,!1,En(t.qInv))])};ue.publicKeyFromAsn1=function(t){var e={},r=[];if(R.validate(t,lL,e,r)){var n=R.derToOid(e.publicKeyOid);if(n!==ue.oids.rsaEncryption){var i=new Error("Cannot read public key. Unknown OID.");throw i.oid=n,i}t=e.rsaPublicKey}if(r=[],!R.validate(t,uL,e,r)){var i=new Error("Cannot read public key. ASN.1 object does not contain an RSAPublicKey.");throw i.errors=r,i}var o=ee.util.createBuffer(e.publicKeyModulus).toHex(),s=ee.util.createBuffer(e.publicKeyExponent).toHex();return ue.setRsaPublicKey(new Ae(o,16),new Ae(s,16))};ue.publicKeyToAsn1=ue.publicKeyToSubjectPublicKeyInfo=function(t){return R.create(R.Class.UNIVERSAL,R.Type.SEQUENCE,!0,[R.create(R.Class.UNIVERSAL,R.Type.SEQUENCE,!0,[R.create(R.Class.UNIVERSAL,R.Type.OID,!1,R.oidToDer(ue.oids.rsaEncryption).getBytes()),R.create(R.Class.UNIVERSAL,R.Type.NULL,!1,"")]),R.create(R.Class.UNIVERSAL,R.Type.BITSTRING,!1,[ue.publicKeyToRSAPublicKey(t)])])};ue.publicKeyToRSAPublicKey=function(t){return R.create(R.Class.UNIVERSAL,R.Type.SEQUENCE,!0,[R.create(R.Class.UNIVERSAL,R.Type.INTEGER,!1,En(t.n)),R.create(R.Class.UNIVERSAL,R.Type.INTEGER,!1,En(t.e))])};function F_(t,e,r){var n=ee.util.createBuffer(),i=Math.ceil(e.n.bitLength()/8);if(t.length>i-11){var o=new Error("Message is too long for PKCS#1 v1.5 padding.");throw o.length=t.length,o.max=i-11,o}n.putByte(0),n.putByte(r);var s=i-3-t.length,a;if(r===0||r===1){a=r===0?0:255;for(var c=0;c<s;++c)n.putByte(a)}else for(;s>0;){for(var u=0,l=ee.random.getBytes(s),c=0;c<s;++c)a=l.charCodeAt(c),a===0?++u:n.putByte(a);s=u}return n.putByte(0),n.putBytes(t),n}function td(t,e,r,n){var i=Math.ceil(e.n.bitLength()/8),o=ee.util.createBuffer(t),s=o.getByte(),a=o.getByte();if(s!==0||r&&a!==0&&a!==1||!r&&a!=2||r&&a===0&&typeof n>"u")throw new Error("Encryption block is invalid.");var c=0;if(a===0){c=i-3-n;for(var u=0;u<c;++u)if(o.getByte()!==0)throw new Error("Encryption block is invalid.")}else if(a===1)for(c=0;o.length()>1;){if(o.getByte()!==255){--o.read;break}++c}else if(a===2)for(c=0;o.length()>1;){if(o.getByte()===0){--o.read;break}++c}var l=o.getByte();if(l!==0||c!==i-3-o.length())throw new Error("Encryption block is invalid.");return o.getBytes()}function dL(t,e,r){typeof e=="function"&&(r=e,e={}),e=e||{};var n={algorithm:{name:e.algorithm||"PRIMEINC",options:{workers:e.workers||2,workLoad:e.workLoad||100,workerScript:e.workerScript}}};"prng"in e&&(n.prng=e.prng),i();function i(){o(t.pBits,function(a,c){if(a)return r(a);if(t.p=c,t.q!==null)return s(a,t.q);o(t.qBits,s)})}function o(a,c){ee.prime.generateProbablePrime(a,n,c)}function s(a,c){if(a)return r(a);if(t.q=c,t.p.compareTo(t.q)<0){var u=t.p;t.p=t.q,t.q=u}if(t.p.subtract(Ae.ONE).gcd(t.e).compareTo(Ae.ONE)!==0){t.p=null,i();return}if(t.q.subtract(Ae.ONE).gcd(t.e).compareTo(Ae.ONE)!==0){t.q=null,o(t.qBits,s);return}if(t.p1=t.p.subtract(Ae.ONE),t.q1=t.q.subtract(Ae.ONE),t.phi=t.p1.multiply(t.q1),t.phi.gcd(t.e).compareTo(Ae.ONE)!==0){t.p=t.q=null,i();return}if(t.n=t.p.multiply(t.q),t.n.bitLength()!==t.bits){t.q=null,o(t.qBits,s);return}var l=t.e.modInverse(t.phi);t.keys={privateKey:ue.rsa.setPrivateKey(t.n,t.e,l,t.p,t.q,l.mod(t.p1),l.mod(t.q1),t.q.modInverse(t.p)),publicKey:ue.rsa.setPublicKey(t.n,t.e)},r(null,t.keys)}}function En(t){var e=t.toString(16);e[0]>="8"&&(e="00"+e);var r=ee.util.hexToBytes(e);return r.length>1&&(r.charCodeAt(0)===0&&!(r.charCodeAt(1)&128)||r.charCodeAt(0)===255&&(r.charCodeAt(1)&128)===128)?r.substr(1):r}function pL(t){return t<=100?27:t<=150?18:t<=200?15:t<=250?12:t<=300?9:t<=350?8:t<=400?7:t<=500?6:t<=600?5:t<=800?4:t<=1250?3:2}function L_(t){return ee.util.isNodejs&&typeof dg[t]=="function"}function O_(t){return typeof Nr.globalScope<"u"&&typeof Nr.globalScope.crypto=="object"&&typeof Nr.globalScope.crypto.subtle=="object"&&typeof Nr.globalScope.crypto.subtle[t]=="function"}function U_(t){return typeof Nr.globalScope<"u"&&typeof Nr.globalScope.msCrypto=="object"&&typeof Nr.globalScope.msCrypto.subtle=="object"&&typeof Nr.globalScope.msCrypto.subtle[t]=="function"}function K_(t){for(var e=ee.util.hexToBytes(t.toString(16)),r=new Uint8Array(e.length),n=0;n<e.length;++n)r[n]=e.charCodeAt(n);return r}});var W_=re((Kse,G_)=>{var G=Le();ig();ou();JS();qo();Fh();r_();o_();su();g_();rd();ft();typeof H_>"u"&&(H_=G.jsbn.BigInteger);var H_,k=G.asn1,fe=G.pki=G.pki||{};G_.exports=fe.pbe=G.pbe=G.pbe||{};var Go=fe.oids,mL={name:"EncryptedPrivateKeyInfo",tagClass:k.Class.UNIVERSAL,type:k.Type.SEQUENCE,constructed:!0,value:[{name:"EncryptedPrivateKeyInfo.encryptionAlgorithm",tagClass:k.Class.UNIVERSAL,type:k.Type.SEQUENCE,constructed:!0,value:[{name:"AlgorithmIdentifier.algorithm",tagClass:k.Class.UNIVERSAL,type:k.Type.OID,constructed:!1,capture:"encryptionOid"},{name:"AlgorithmIdentifier.parameters",tagClass:k.Class.UNIVERSAL,type:k.Type.SEQUENCE,constructed:!0,captureAsn1:"encryptionParams"}]},{name:"EncryptedPrivateKeyInfo.encryptedData",tagClass:k.Class.UNIVERSAL,type:k.Type.OCTETSTRING,constructed:!1,capture:"encryptedData"}]},yL={name:"PBES2Algorithms",tagClass:k.Class.UNIVERSAL,type:k.Type.SEQUENCE,constructed:!0,value:[{name:"PBES2Algorithms.keyDerivationFunc",tagClass:k.Class.UNIVERSAL,type:k.Type.SEQUENCE,constructed:!0,value:[{name:"PBES2Algorithms.keyDerivationFunc.oid",tagClass:k.Class.UNIVERSAL,type:k.Type.OID,constructed:!1,capture:"kdfOid"},{name:"PBES2Algorithms.params",tagClass:k.Class.UNIVERSAL,type:k.Type.SEQUENCE,constructed:!0,value:[{name:"PBES2Algorithms.params.salt",tagClass:k.Class.UNIVERSAL,type:k.Type.OCTETSTRING,constructed:!1,capture:"kdfSalt"},{name:"PBES2Algorithms.params.iterationCount",tagClass:k.Class.UNIVERSAL,type:k.Type.INTEGER,constructed:!1,capture:"kdfIterationCount"},{name:"PBES2Algorithms.params.keyLength",tagClass:k.Class.UNIVERSAL,type:k.Type.INTEGER,constructed:!1,optional:!0,capture:"keyLength"},{name:"PBES2Algorithms.params.prf",tagClass:k.Class.UNIVERSAL,type:k.Type.SEQUENCE,constructed:!0,optional:!0,value:[{name:"PBES2Algorithms.params.prf.algorithm",tagClass:k.Class.UNIVERSAL,type:k.Type.OID,constructed:!1,capture:"prfOid"}]}]}]},{name:"PBES2Algorithms.encryptionScheme",tagClass:k.Class.UNIVERSAL,type:k.Type.SEQUENCE,constructed:!0,value:[{name:"PBES2Algorithms.encryptionScheme.oid",tagClass:k.Class.UNIVERSAL,type:k.Type.OID,constructed:!1,capture:"encOid"},{name:"PBES2Algorithms.encryptionScheme.iv",tagClass:k.Class.UNIVERSAL,type:k.Type.OCTETSTRING,constructed:!1,capture:"encIv"}]}]},gL={name:"pkcs-12PbeParams",tagClass:k.Class.UNIVERSAL,type:k.Type.SEQUENCE,constructed:!0,value:[{name:"pkcs-12PbeParams.salt",tagClass:k.Class.UNIVERSAL,type:k.Type.OCTETSTRING,constructed:!1,capture:"salt"},{name:"pkcs-12PbeParams.iterations",tagClass:k.Class.UNIVERSAL,type:k.Type.INTEGER,constructed:!1,capture:"iterations"}]};fe.encryptPrivateKeyInfo=function(t,e,r){r=r||{},r.saltSize=r.saltSize||8,r.count=r.count||2048,r.algorithm=r.algorithm||"aes128",r.prfAlgorithm=r.prfAlgorithm||"sha1";var n=G.random.getBytesSync(r.saltSize),i=r.count,o=k.integerToDer(i),s,a,c;if(r.algorithm.indexOf("aes")===0||r.algorithm==="des"){var u,l,f;switch(r.algorithm){case"aes128":s=16,u=16,l=Go["aes128-CBC"],f=G.aes.createEncryptionCipher;break;case"aes192":s=24,u=16,l=Go["aes192-CBC"],f=G.aes.createEncryptionCipher;break;case"aes256":s=32,u=16,l=Go["aes256-CBC"],f=G.aes.createEncryptionCipher;break;case"des":s=8,u=8,l=Go.desCBC,f=G.des.createEncryptionCipher;break;default:var d=new Error("Cannot encrypt private key. Unknown encryption algorithm.");throw d.algorithm=r.algorithm,d}var p="hmacWith"+r.prfAlgorithm.toUpperCase(),h=z_(p),m=G.pkcs5.pbkdf2(e,n,i,s,h),y=G.random.getBytesSync(u),g=f(m);g.start(y),g.update(k.toDer(t)),g.finish(),c=g.output.getBytes();var b=bL(n,o,s,p);a=k.create(k.Class.UNIVERSAL,k.Type.SEQUENCE,!0,[k.create(k.Class.UNIVERSAL,k.Type.OID,!1,k.oidToDer(Go.pkcs5PBES2).getBytes()),k.create(k.Class.UNIVERSAL,k.Type.SEQUENCE,!0,[k.create(k.Class.UNIVERSAL,k.Type.SEQUENCE,!0,[k.create(k.Class.UNIVERSAL,k.Type.OID,!1,k.oidToDer(Go.pkcs5PBKDF2).getBytes()),b]),k.create(k.Class.UNIVERSAL,k.Type.SEQUENCE,!0,[k.create(k.Class.UNIVERSAL,k.Type.OID,!1,k.oidToDer(l).getBytes()),k.create(k.Class.UNIVERSAL,k.Type.OCTETSTRING,!1,y)])])])}else if(r.algorithm==="3des"){s=24;var w=new G.util.ByteBuffer(n),m=fe.pbe.generatePkcs12Key(e,w,1,i,s),y=fe.pbe.generatePkcs12Key(e,w,2,i,s),g=G.des.createEncryptionCipher(m);g.start(y),g.update(k.toDer(t)),g.finish(),c=g.output.getBytes(),a=k.create(k.Class.UNIVERSAL,k.Type.SEQUENCE,!0,[k.create(k.Class.UNIVERSAL,k.Type.OID,!1,k.oidToDer(Go["pbeWithSHAAnd3-KeyTripleDES-CBC"]).getBytes()),k.create(k.Class.UNIVERSAL,k.Type.SEQUENCE,!0,[k.create(k.Class.UNIVERSAL,k.Type.OCTETSTRING,!1,n),k.create(k.Class.UNIVERSAL,k.Type.INTEGER,!1,o.getBytes())])])}else{var d=new Error("Cannot encrypt private key. Unknown encryption algorithm.");throw d.algorithm=r.algorithm,d}var _=k.create(k.Class.UNIVERSAL,k.Type.SEQUENCE,!0,[a,k.create(k.Class.UNIVERSAL,k.Type.OCTETSTRING,!1,c)]);return _};fe.decryptPrivateKeyInfo=function(t,e){var r=null,n={},i=[];if(!k.validate(t,mL,n,i)){var o=new Error("Cannot read encrypted private key. ASN.1 object is not a supported EncryptedPrivateKeyInfo.");throw o.errors=i,o}var s=k.derToOid(n.encryptionOid),a=fe.pbe.getCipher(s,n.encryptionParams,e),c=G.util.createBuffer(n.encryptedData);return a.update(c),a.finish()&&(r=k.fromDer(a.output)),r};fe.encryptedPrivateKeyToPem=function(t,e){var r={type:"ENCRYPTED PRIVATE KEY",body:k.toDer(t).getBytes()};return G.pem.encode(r,{maxline:e})};fe.encryptedPrivateKeyFromPem=function(t){var e=G.pem.decode(t)[0];if(e.type!=="ENCRYPTED PRIVATE KEY"){var r=new Error('Could not convert encrypted private key from PEM; PEM header type is "ENCRYPTED PRIVATE KEY".');throw r.headerType=e.type,r}if(e.procType&&e.procType.type==="ENCRYPTED")throw new Error("Could not convert encrypted private key from PEM; PEM is encrypted.");return k.fromDer(e.body)};fe.encryptRsaPrivateKey=function(t,e,r){if(r=r||{},!r.legacy){var n=fe.wrapRsaPrivateKey(fe.privateKeyToAsn1(t));return n=fe.encryptPrivateKeyInfo(n,e,r),fe.encryptedPrivateKeyToPem(n)}var i,o,s,a;switch(r.algorithm){case"aes128":i="AES-128-CBC",s=16,o=G.random.getBytesSync(16),a=G.aes.createEncryptionCipher;break;case"aes192":i="AES-192-CBC",s=24,o=G.random.getBytesSync(16),a=G.aes.createEncryptionCipher;break;case"aes256":i="AES-256-CBC",s=32,o=G.random.getBytesSync(16),a=G.aes.createEncryptionCipher;break;case"3des":i="DES-EDE3-CBC",s=24,o=G.random.getBytesSync(8),a=G.des.createEncryptionCipher;break;case"des":i="DES-CBC",s=8,o=G.random.getBytesSync(8),a=G.des.createEncryptionCipher;break;default:var c=new Error('Could not encrypt RSA private key; unsupported encryption algorithm "'+r.algorithm+'".');throw c.algorithm=r.algorithm,c}var u=G.pbe.opensslDeriveBytes(e,o.substr(0,8),s),l=a(u);l.start(o),l.update(k.toDer(fe.privateKeyToAsn1(t))),l.finish();var f={type:"RSA PRIVATE KEY",procType:{version:"4",type:"ENCRYPTED"},dekInfo:{algorithm:i,parameters:G.util.bytesToHex(o).toUpperCase()},body:l.output.getBytes()};return G.pem.encode(f)};fe.decryptRsaPrivateKey=function(t,e){var r=null,n=G.pem.decode(t)[0];if(n.type!=="ENCRYPTED PRIVATE KEY"&&n.type!=="PRIVATE KEY"&&n.type!=="RSA PRIVATE KEY"){var i=new Error('Could not convert private key from PEM; PEM header type is not "ENCRYPTED PRIVATE KEY", "PRIVATE KEY", or "RSA PRIVATE KEY".');throw i.headerType=i,i}if(n.procType&&n.procType.type==="ENCRYPTED"){var o,s;switch(n.dekInfo.algorithm){case"DES-CBC":o=8,s=G.des.createDecryptionCipher;break;case"DES-EDE3-CBC":o=24,s=G.des.createDecryptionCipher;break;case"AES-128-CBC":o=16,s=G.aes.createDecryptionCipher;break;case"AES-192-CBC":o=24,s=G.aes.createDecryptionCipher;break;case"AES-256-CBC":o=32,s=G.aes.createDecryptionCipher;break;case"RC2-40-CBC":o=5,s=function(f){return G.rc2.createDecryptionCipher(f,40)};break;case"RC2-64-CBC":o=8,s=function(f){return G.rc2.createDecryptionCipher(f,64)};break;case"RC2-128-CBC":o=16,s=function(f){return G.rc2.createDecryptionCipher(f,128)};break;default:var i=new Error('Could not decrypt private key; unsupported encryption algorithm "'+n.dekInfo.algorithm+'".');throw i.algorithm=n.dekInfo.algorithm,i}var a=G.util.hexToBytes(n.dekInfo.parameters),c=G.pbe.opensslDeriveBytes(e,a.substr(0,8),o),u=s(c);if(u.start(a),u.update(G.util.createBuffer(n.body)),u.finish())r=u.output.getBytes();else return r}else r=n.body;return n.type==="ENCRYPTED PRIVATE KEY"?r=fe.decryptPrivateKeyInfo(k.fromDer(r),e):r=k.fromDer(r),r!==null&&(r=fe.privateKeyFromAsn1(r)),r};fe.pbe.generatePkcs12Key=function(t,e,r,n,i,o){var s,a;if(typeof o>"u"||o===null){if(!("sha1"in G.md))throw new Error('"sha1" hash algorithm unavailable.');o=G.md.sha1.create()}var c=o.digestLength,u=o.blockLength,l=new G.util.ByteBuffer,f=new G.util.ByteBuffer;if(t!=null){for(a=0;a<t.length;a++)f.putInt16(t.charCodeAt(a));f.putInt16(0)}var d=f.length(),p=e.length(),h=new G.util.ByteBuffer;h.fillWithByte(r,u);var m=u*Math.ceil(p/u),y=new G.util.ByteBuffer;for(a=0;a<m;a++)y.putByte(e.at(a%p));var g=u*Math.ceil(d/u),b=new G.util.ByteBuffer;for(a=0;a<g;a++)b.putByte(f.at(a%d));var w=y;w.putBuffer(b);for(var _=Math.ceil(i/c),E=1;E<=_;E++){var A=new G.util.ByteBuffer;A.putBytes(h.bytes()),A.putBytes(w.bytes());for(var B=0;B<n;B++)o.start(),o.update(A.getBytes()),A=o.digest();var I=new G.util.ByteBuffer;for(a=0;a<u;a++)I.putByte(A.at(a%c));var L=Math.ceil(p/u)+Math.ceil(d/u),H=new G.util.ByteBuffer;for(s=0;s<L;s++){var F=new G.util.ByteBuffer(w.getBytes(u)),$=511;for(a=I.length()-1;a>=0;a--)$=$>>8,$+=I.at(a)+F.at(a),F.setAt(a,$&255);H.putBuffer(F)}w=H,l.putBuffer(A)}return l.truncate(l.length()-i),l};fe.pbe.getCipher=function(t,e,r){switch(t){case fe.oids.pkcs5PBES2:return fe.pbe.getCipherForPBES2(t,e,r);case fe.oids["pbeWithSHAAnd3-KeyTripleDES-CBC"]:case fe.oids["pbewithSHAAnd40BitRC2-CBC"]:return fe.pbe.getCipherForPKCS12PBE(t,e,r);default:var n=new Error("Cannot read encrypted PBE data block. Unsupported OID.");throw n.oid=t,n.supportedOids=["pkcs5PBES2","pbeWithSHAAnd3-KeyTripleDES-CBC","pbewithSHAAnd40BitRC2-CBC"],n}};fe.pbe.getCipherForPBES2=function(t,e,r){var n={},i=[];if(!k.validate(e,yL,n,i)){var o=new Error("Cannot read password-based-encryption algorithm parameters. ASN.1 object is not a supported EncryptedPrivateKeyInfo.");throw o.errors=i,o}if(t=k.derToOid(n.kdfOid),t!==fe.oids.pkcs5PBKDF2){var o=new Error("Cannot read encrypted private key. Unsupported key derivation function OID.");throw o.oid=t,o.supportedOids=["pkcs5PBKDF2"],o}if(t=k.derToOid(n.encOid),t!==fe.oids["aes128-CBC"]&&t!==fe.oids["aes192-CBC"]&&t!==fe.oids["aes256-CBC"]&&t!==fe.oids["des-EDE3-CBC"]&&t!==fe.oids.desCBC){var o=new Error("Cannot read encrypted private key. Unsupported encryption scheme OID.");throw o.oid=t,o.supportedOids=["aes128-CBC","aes192-CBC","aes256-CBC","des-EDE3-CBC","desCBC"],o}var s=n.kdfSalt,a=G.util.createBuffer(n.kdfIterationCount);a=a.getInt(a.length()<<3);var c,u;switch(fe.oids[t]){case"aes128-CBC":c=16,u=G.aes.createDecryptionCipher;break;case"aes192-CBC":c=24,u=G.aes.createDecryptionCipher;break;case"aes256-CBC":c=32,u=G.aes.createDecryptionCipher;break;case"des-EDE3-CBC":c=24,u=G.des.createDecryptionCipher;break;case"desCBC":c=8,u=G.des.createDecryptionCipher;break}var l=$_(n.prfOid),f=G.pkcs5.pbkdf2(r,s,a,c,l),d=n.encIv,p=u(f);return p.start(d),p};fe.pbe.getCipherForPKCS12PBE=function(t,e,r){var n={},i=[];if(!k.validate(e,gL,n,i)){var o=new Error("Cannot read password-based-encryption algorithm parameters. ASN.1 object is not a supported EncryptedPrivateKeyInfo.");throw o.errors=i,o}var s=G.util.createBuffer(n.salt),a=G.util.createBuffer(n.iterations);a=a.getInt(a.length()<<3);var c,u,l;switch(t){case fe.oids["pbeWithSHAAnd3-KeyTripleDES-CBC"]:c=24,u=8,l=G.des.startDecrypting;break;case fe.oids["pbewithSHAAnd40BitRC2-CBC"]:c=5,u=8,l=function(m,y){var g=G.rc2.createDecryptionCipher(m,40);return g.start(y,null),g};break;default:var o=new Error("Cannot read PKCS #12 PBE data block. Unsupported OID.");throw o.oid=t,o}var f=$_(n.prfOid),d=fe.pbe.generatePkcs12Key(r,s,1,a,c,f);f.start();var p=fe.pbe.generatePkcs12Key(r,s,2,a,u,f);return l(d,p)};fe.pbe.opensslDeriveBytes=function(t,e,r,n){if(typeof n>"u"||n===null){if(!("md5"in G.md))throw new Error('"md5" hash algorithm unavailable.');n=G.md.md5.create()}e===null&&(e="");for(var i=[q_(n,t+e)],o=16,s=1;o<r;++s,o+=16)i.push(q_(n,i[s-1]+t+e));return i.join("").substr(0,r)};function q_(t,e){return t.start().update(e).digest().getBytes()}function $_(t){var e;if(!t)e="hmacWithSHA1";else if(e=fe.oids[k.derToOid(t)],!e){var r=new Error("Unsupported PRF OID.");throw r.oid=t,r.supported=["hmacWithSHA1","hmacWithSHA224","hmacWithSHA256","hmacWithSHA384","hmacWithSHA512"],r}return z_(e)}function z_(t){var e=G.md;switch(t){case"hmacWithSHA224":e=G.md.sha512;case"hmacWithSHA1":case"hmacWithSHA256":case"hmacWithSHA384":case"hmacWithSHA512":t=t.substr(8).toLowerCase();break;default:var r=new Error("Unsupported PRF algorithm.");throw r.algorithm=t,r.supported=["hmacWithSHA1","hmacWithSHA224","hmacWithSHA256","hmacWithSHA384","hmacWithSHA512"],r}if(!e||!(t in e))throw new Error("Unknown hash algorithm: "+t);return e[t].create()}function bL(t,e,r,n){var i=k.create(k.Class.UNIVERSAL,k.Type.SEQUENCE,!0,[k.create(k.Class.UNIVERSAL,k.Type.OCTETSTRING,!1,t),k.create(k.Class.UNIVERSAL,k.Type.INTEGER,!1,e.getBytes())]);return n!=="hmacWithSHA1"&&i.value.push(k.create(k.Class.UNIVERSAL,k.Type.INTEGER,!1,G.util.hexToBytes(r.toString(16))),k.create(k.Class.UNIVERSAL,k.Type.SEQUENCE,!0,[k.create(k.Class.UNIVERSAL,k.Type.OID,!1,k.oidToDer(fe.oids[n]).getBytes()),k.create(k.Class.UNIVERSAL,k.Type.NULL,!1,"")])),i}});var uI=re((Vae,cI)=>{var qe=Le();qo();ft();var uu=cI.exports=qe.sha512=qe.sha512||{};qe.md.sha512=qe.md.algorithms.sha512=uu;var sI=qe.sha384=qe.sha512.sha384=qe.sha512.sha384||{};sI.create=function(){return uu.create("SHA-384")};qe.md.sha384=qe.md.algorithms.sha384=sI;qe.sha512.sha256=qe.sha512.sha256||{create:function(){return uu.create("SHA-512/256")}};qe.md["sha512/256"]=qe.md.algorithms["sha512/256"]=qe.sha512.sha256;qe.sha512.sha224=qe.sha512.sha224||{create:function(){return uu.create("SHA-512/224")}};qe.md["sha512/224"]=qe.md.algorithms["sha512/224"]=qe.sha512.sha224;uu.create=function(t){if(aI||RL(),typeof t>"u"&&(t="SHA-512"),!(t in jo))throw new Error("Invalid SHA-512 algorithm: "+t);for(var e=jo[t],r=null,n=qe.util.createBuffer(),i=new Array(80),o=0;o<80;++o)i[o]=new Array(2);var s=64;switch(t){case"SHA-384":s=48;break;case"SHA-512/256":s=32;break;case"SHA-512/224":s=28;break}var a={algorithm:t.replace("-","").toLowerCase(),blockLength:128,digestLength:s,messageLength:0,fullMessageLength:null,messageLengthSize:16};return a.start=function(){a.messageLength=0,a.fullMessageLength=a.messageLength128=[];for(var c=a.messageLengthSize/4,u=0;u<c;++u)a.fullMessageLength.push(0);n=qe.util.createBuffer(),r=new Array(e.length);for(var u=0;u<e.length;++u)r[u]=e[u].slice(0);return a},a.start(),a.update=function(c,u){u==="utf8"&&(c=qe.util.encodeUtf8(c));var l=c.length;a.messageLength+=l,l=[l/4294967296>>>0,l>>>0];for(var f=a.fullMessageLength.length-1;f>=0;--f)a.fullMessageLength[f]+=l[1],l[1]=l[0]+(a.fullMessageLength[f]/4294967296>>>0),a.fullMessageLength[f]=a.fullMessageLength[f]>>>0,l[0]=l[1]/4294967296>>>0;return n.putBytes(c),oI(r,i,n),(n.read>2048||n.length()===0)&&n.compact(),a},a.digest=function(){var c=qe.util.createBuffer();c.putBytes(n.bytes());var u=a.fullMessageLength[a.fullMessageLength.length-1]+a.messageLengthSize,l=u&a.blockLength-1;c.putBytes(wg.substr(0,a.blockLength-l));for(var f,d,p=a.fullMessageLength[0]*8,h=0;h<a.fullMessageLength.length-1;++h)f=a.fullMessageLength[h+1]*8,d=f/4294967296>>>0,p+=d,c.putInt32(p>>>0),p=f>>>0;c.putInt32(p);for(var m=new Array(r.length),h=0;h<r.length;++h)m[h]=r[h].slice(0);oI(m,i,c);var y=qe.util.createBuffer(),g;t==="SHA-512"?g=m.length:t==="SHA-384"?g=m.length-2:g=m.length-4;for(var h=0;h<g;++h)y.putInt32(m[h][0]),(h!==g-1||t!=="SHA-512/224")&&y.putInt32(m[h][1]);return y},a};var wg=null,aI=!1,xg=null,jo=null;function RL(){wg="\x80",wg+=qe.util.fillString("\0",128),xg=[[1116352408,3609767458],[1899447441,602891725],[3049323471,3964484399],[3921009573,2173295548],[961987163,4081628472],[1508970993,3053834265],[2453635748,2937671579],[2870763221,3664609560],[3624381080,2734883394],[310598401,1164996542],[607225278,1323610764],[1426881987,3590304994],[1925078388,4068182383],[2162078206,991336113],[2614888103,633803317],[3248222580,3479774868],[3835390401,2666613458],[4022224774,944711139],[264347078,2341262773],[604807628,2007800933],[770255983,1495990901],[1249150122,1856431235],[1555081692,3175218132],[1996064986,2198950837],[2554220882,3999719339],[2821834349,766784016],[2952996808,2566594879],[3210313671,3203337956],[3336571891,1034457026],[3584528711,2466948901],[113926993,3758326383],[338241895,168717936],[666307205,1188179964],[773529912,1546045734],[1294757372,1522805485],[1396182291,2643833823],[1695183700,2343527390],[1986661051,1014477480],[2177026350,1206759142],[2456956037,344077627],[2730485921,1290863460],[2820302411,3158454273],[3259730800,3505952657],[3345764771,106217008],[3516065817,3606008344],[3600352804,1432725776],[4094571909,1467031594],[275423344,851169720],[430227734,3100823752],[506948616,1363258195],[659060556,3750685593],[883997877,3785050280],[958139571,3318307427],[1322822218,3812723403],[1537002063,2003034995],[1747873779,3602036899],[1955562222,1575990012],[2024104815,1125592928],[2227730452,2716904306],[2361852424,442776044],[2428436474,593698344],[2756734187,3733110249],[3204031479,2999351573],[3329325298,3815920427],[3391569614,3928383900],[3515267271,566280711],[3940187606,3454069534],[4118630271,4000239992],[116418474,1914138554],[174292421,2731055270],[289380356,3203993006],[460393269,320620315],[685471733,587496836],[852142971,1086792851],[1017036298,365543100],[1126000580,2618297676],[1288033470,3409855158],[1501505948,4234509866],[1607167915,987167468],[1816402316,1246189591]],jo={},jo["SHA-512"]=[[1779033703,4089235720],[3144134277,2227873595],[1013904242,4271175723],[2773480762,1595750129],[1359893119,2917565137],[2600822924,725511199],[528734635,4215389547],[1541459225,327033209]],jo["SHA-384"]=[[3418070365,3238371032],[1654270250,914150663],[2438529370,812702999],[355462360,4144912697],[1731405415,4290775857],[2394180231,1750603025],[3675008525,1694076839],[1203062813,3204075428]],jo["SHA-512/256"]=[[573645204,4230739756],[2673172387,3360449730],[596883563,1867755857],[2520282905,1497426621],[2519219938,2827943907],[3193839141,1401305490],[721525244,746961066],[246885852,2177182882]],jo["SHA-512/224"]=[[2352822216,424955298],[1944164710,2312950998],[502970286,855612546],[1738396948,1479516111],[258812777,2077511080],[2011393907,79989058],[1067287976,1780299464],[286451373,2446758561]],aI=!0}function oI(t,e,r){for(var n,i,o,s,a,c,u,l,f,d,p,h,m,y,g,b,w,_,E,A,B,I,L,H,F,$,te,de,T,D,N,K,C,W,Z,oe=r.length();oe>=128;){for(T=0;T<16;++T)e[T][0]=r.getInt32()>>>0,e[T][1]=r.getInt32()>>>0;for(;T<80;++T)K=e[T-2],D=K[0],N=K[1],n=((D>>>19|N<<13)^(N>>>29|D<<3)^D>>>6)>>>0,i=((D<<13|N>>>19)^(N<<3|D>>>29)^(D<<26|N>>>6))>>>0,W=e[T-15],D=W[0],N=W[1],o=((D>>>1|N<<31)^(D>>>8|N<<24)^D>>>7)>>>0,s=((D<<31|N>>>1)^(D<<24|N>>>8)^(D<<25|N>>>7))>>>0,C=e[T-7],Z=e[T-16],N=i+C[1]+s+Z[1],e[T][0]=n+C[0]+o+Z[0]+(N/4294967296>>>0)>>>0,e[T][1]=N>>>0;for(m=t[0][0],y=t[0][1],g=t[1][0],b=t[1][1],w=t[2][0],_=t[2][1],E=t[3][0],A=t[3][1],B=t[4][0],I=t[4][1],L=t[5][0],H=t[5][1],F=t[6][0],$=t[6][1],te=t[7][0],de=t[7][1],T=0;T<80;++T)u=((B>>>14|I<<18)^(B>>>18|I<<14)^(I>>>9|B<<23))>>>0,l=((B<<18|I>>>14)^(B<<14|I>>>18)^(I<<23|B>>>9))>>>0,f=(F^B&(L^F))>>>0,d=($^I&(H^$))>>>0,a=((m>>>28|y<<4)^(y>>>2|m<<30)^(y>>>7|m<<25))>>>0,c=((m<<4|y>>>28)^(y<<30|m>>>2)^(y<<25|m>>>7))>>>0,p=(m&g|w&(m^g))>>>0,h=(y&b|_&(y^b))>>>0,N=de+l+d+xg[T][1]+e[T][1],n=te+u+f+xg[T][0]+e[T][0]+(N/4294967296>>>0)>>>0,i=N>>>0,N=c+h,o=a+p+(N/4294967296>>>0)>>>0,s=N>>>0,te=F,de=$,F=L,$=H,L=B,H=I,N=A+i,B=E+n+(N/4294967296>>>0)>>>0,I=N>>>0,E=w,A=_,w=g,_=b,g=m,b=y,N=i+s,m=n+o+(N/4294967296>>>0)>>>0,y=N>>>0;N=t[0][1]+y,t[0][0]=t[0][0]+m+(N/4294967296>>>0)>>>0,t[0][1]=N>>>0,N=t[1][1]+b,t[1][0]=t[1][0]+g+(N/4294967296>>>0)>>>0,t[1][1]=N>>>0,N=t[2][1]+_,t[2][0]=t[2][0]+w+(N/4294967296>>>0)>>>0,t[2][1]=N>>>0,N=t[3][1]+A,t[3][0]=t[3][0]+E+(N/4294967296>>>0)>>>0,t[3][1]=N>>>0,N=t[4][1]+I,t[4][0]=t[4][0]+B+(N/4294967296>>>0)>>>0,t[4][1]=N>>>0,N=t[5][1]+H,t[5][0]=t[5][0]+L+(N/4294967296>>>0)>>>0,t[5][1]=N>>>0,N=t[6][1]+$,t[6][0]=t[6][0]+F+(N/4294967296>>>0)>>>0,t[6][1]=N>>>0,N=t[7][1]+de,t[7][0]=t[7][0]+te+(N/4294967296>>>0)>>>0,t[7][1]=N>>>0,oe-=128}}});var Bg=re((Pce,Rg)=>{var Cce=function(){typeof Rg<"u"&&(Rg.exports=m);var t=86400,e=3200,r=146097*e/400,n=t*r,i=1e3*n,o=864e13,s=4294967296,a=1e6,c="000000000",u=Math.trunc||function(I){var L=I-I%1;return L==0&&(I<0||I===0&&1/I!=1/0)?-0:L},l=m.prototype,f=(m.fromDate=function(I){return new m(+I)},m.fromInt64BE=_(0,1,2,3,0,4),m.fromInt64LE=_(3,2,1,0,4,0),m.fromString=function(F){var L,H=new m,F=(F+="").replace(/^\s*[+\-]?\d+/,function(te){var te=+te,de=1970+(te-1970)%400;return H.year=te-de,de}).replace(/(?:Z|([+\-]\d{2}):?(\d{2}))$/,function($,te,de){return te<0&&(de*=-1),L=6e4*(60*+te+ +de),""}).replace(/\.\d+$/,function($){return H.nano=+($+c).substr(1,9),""}).split(/\D+/);if(1<F.length?F[1]--:F[1]=0,H.time=L=Date.UTC.apply(Date,F)-(L||0),isNaN(L))throw new TypeError("Invalid Date");return y(H)},m.fromTimeT=function(I){return b(I,0)},l.year=0,l.time=0,l.nano=0,l.addNano=function(I){return this.nano+=+I||0,this},l.getNano=function(){var I=y(this);return(I.time%1e3*a+ +I.nano+1e9)%1e9},l.getTimeT=function(){var L=y(this),I=Math.floor(L.time/1e3),L=L.year;return L&&(I+=L*r*t/e),I},l.getYear=function(){return this.toDate().getUTCFullYear()+this.year},l.toDate=function(){return g(y(this).time)},l.toJSON=function(){return this.toString().replace(/0{1,6}Z$/,"Z")},l.toString=function(I){var L=this,H=L.toDate(),F={H:function(){return A(H.getUTCHours())},L:function(){return B(H.getUTCMilliseconds(),3)},M:function(){return A(H.getUTCMinutes())},N:function(){return B(L.getNano(),9)},S:function(){return A(H.getUTCSeconds())},Y:function(){var $=L.getYear();return 999999<$?"+"+$:9999<$?"+"+B($,6):0<=$?B($,4):-999999<=$?"-"+B(-$,6):$},a:function(){return p[H.getUTCDay()]},b:function(){return d[H.getUTCMonth()]},d:function(){return A(H.getUTCDate())},e:function(){return function($){return(9<$?"":" ")+(0|$)}(H.getUTCDate())},m:function(){return A(H.getUTCMonth()+1)}};return function $(te){return te.replace(/%./g,function(de){var D=de[1],T=h[D],D=F[D];return T?$(T):D?D():de})}(I||f)},l.writeInt64BE=w(0,1,2,3,0,4),l.writeInt64LE=w(3,2,1,0,4,0),"%Y-%m-%dT%H:%M:%S.%NZ"),d=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],p=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],h={"%":"%",F:"%Y-%m-%d",n:`
|
|
16
|
+
`,R:"%H:%M",T:"%H:%M:%S",t:" ",X:"%T",Z:"GMT",z:"+0000"};return m;function m(I,L,H){var F=this;if(!(F instanceof m))return new m(I,L,H);F.time=+I||0,F.nano=+L||0,F.year=+H||0,y(F)}function y(I){var L,H,F,$=I.year,te=I.time,de=I.nano,T=((de<0||a<=de)&&(de-=(H=Math.floor(de/a))*a,te+=H,H=1),$%e);return(te<-o||o<te||T)&&((L=u(te/i))&&($+=L*e,te-=L*i),(F=g(te)).setUTCFullYear(T+F.getUTCFullYear()),F=(te=+F)+(L=u(($-=T)/e))*i,L&&-o<=F&&F<=o&&($-=L*e,te=F),H=1),H&&(I.year=$,I.time=te,I.nano=de),I}function g(I){var L=new Date(0);return L.setTime(I),L}function b($,F){$=+$||0;var H=u((F=(F|0)*s)/n)+u($/n),F=F%n+$%n,$=u(F/n);return $&&(H+=$,F-=$*n),new m(1e3*F,0,H*e)}function w(I,L,H,F,$,te){return function(T,D){var K=y(this);T=T||new Array(8),E(T,D|=0);var C=Math.floor(K.time/1e3),K=K.year*(r*t/e),N=u(K/s)+u(C/s),K=K%s+C%s,C=Math.floor(K/s);return C&&(N+=C,K-=C*s),de(T,D+$,N),de(T,D+te,K),T};function de(T,D,N){T[D+I]=N>>24&255,T[D+L]=N>>16&255,T[D+H]=N>>8&255,T[D+F]=255&N}}function _(I,L,H,F,$,te){return function(T,D){E(T,D|=0);var N=de(T,D+$);return b(de(T,D+te),N)};function de(T,D){return 16777216*T[D+I]+(T[D+L]<<16|T[D+H]<<8|T[D+F])}}function E(I,L){if(I=I&&I.length,I==null)throw new TypeError("Invalid Buffer");if(I<L+8)throw new RangeError("Out of range")}function A(I){return(9<I?"":"0")+(0|I)}function B(I,L){return(c+(0|I)).substr(-L)}}()});var lU={};Y(lU,{createHeliaHTTP:()=>cU});function Jr(t){let e=new globalThis.AbortController;function r(){e.abort();for(let o of t)o?.removeEventListener!=null&&o.removeEventListener("abort",r)}for(let o of t){if(o?.aborted===!0){r();break}o?.addEventListener!=null&&o.addEventListener("abort",r)}function n(){for(let o of t)o?.removeEventListener!=null&&o.removeEventListener("abort",r)}let i=e.signal;return i.clear=n,i}function LR(t){let[e,r]=t[Symbol.asyncIterator]!=null?[t[Symbol.asyncIterator](),Symbol.asyncIterator]:[t[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:i=>{n.push(i)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[r](){return this}}}var es=LR;function OR(t){return t[Symbol.asyncIterator]!=null}function Ab(t){return t?.then!=null}function UR(t,e){if(OR(t))return async function*(){for await(let a of t){let c=e(a);Ab(c)&&await c,yield a}}();let r=es(t),{value:n,done:i}=r.next();if(i===!0)return function*(){}();if(typeof e(n)?.then=="function")return async function*(){yield n;for await(let a of r){let c=e(a);Ab(c)&&await c,yield a}}();let s=e;return function*(){yield n;for(let a of r)s(a),yield a}()}var Tu=UR;var Dd={};Y(Dd,{base32:()=>rs,base32hex:()=>GR,base32hexpad:()=>YR,base32hexpadupper:()=>jR,base32hexupper:()=>WR,base32pad:()=>$R,base32padupper:()=>zR,base32upper:()=>qR,base32z:()=>QR});function KR(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var i=0;i<t.length;i++){var o=t.charAt(i),s=o.charCodeAt(0);if(r[s]!==255)throw new TypeError(o+" is ambiguous");r[s]=i}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function f(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var m=0,y=0,g=0,b=h.length;g!==b&&h[g]===0;)g++,m++;for(var w=(b-g)*l+1>>>0,_=new Uint8Array(w);g!==b;){for(var E=h[g],A=0,B=w-1;(E!==0||A<y)&&B!==-1;B--,A++)E+=256*_[B]>>>0,_[B]=E%a>>>0,E=E/a>>>0;if(E!==0)throw new Error("Non-zero carry");y=A,g++}for(var I=w-y;I!==w&&_[I]===0;)I++;for(var L=c.repeat(m);I<w;++I)L+=t.charAt(_[I]);return L}function d(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var m=0;if(h[m]!==" "){for(var y=0,g=0;h[m]===c;)y++,m++;for(var b=(h.length-m)*u+1>>>0,w=new Uint8Array(b);h[m];){var _=r[h.charCodeAt(m)];if(_===255)return;for(var E=0,A=b-1;(_!==0||E<g)&&A!==-1;A--,E++)_+=a*w[A]>>>0,w[A]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");g=E,m++}if(h[m]!==" "){for(var B=b-g;B!==b&&w[B]===0;)B++;for(var I=new Uint8Array(y+(b-B)),L=y;B!==b;)I[L++]=w[B++];return I}}}function p(h){var m=d(h);if(m)return m;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:d,decode:p}}var MR=KR,FR=MR,Sb=FR;var gU=new Uint8Array(0);var _b=(t,e)=>{if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0},Rn=t=>{if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")};var Ib=t=>new TextEncoder().encode(t),Rb=t=>new TextDecoder().decode(t);var Td=class{constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},kd=class{constructor(e,r,n){if(this.name=e,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Tb(this,e)}},Cd=class{constructor(e){this.decoders=e}or(e){return Tb(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},Tb=(t,e)=>new Cd({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}}),Pd=class{constructor(e,r,n,i){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=i,this.encoder=new Td(e,r,n),this.decoder=new kd(e,r,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},ts=({name:t,prefix:e,encode:r,decode:n})=>new Pd(t,e,r,n),fi=({prefix:t,name:e,alphabet:r})=>{let{encode:n,decode:i}=Sb(r,e);return ts({prefix:t,name:e,encode:n,decode:o=>Rn(i(o))})},VR=(t,e,r,n)=>{let i={};for(let l=0;l<e.length;++l)i[e[l]]=l;let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),a=0,c=0,u=0;for(let l=0;l<o;++l){let f=i[t[l]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|f,a+=r,a>=8&&(a-=8,s[u++]=255&c>>a)}if(a>=r||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return s},HR=(t,e,r)=>{let n=e[e.length-1]==="=",i=(1<<r)-1,o="",s=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],s+=8;s>r;)s-=r,o+=e[i&a>>s];if(s&&(o+=e[i&a<<r-s]),n)for(;o.length*r&7;)o+="=";return o},Xe=({name:t,prefix:e,bitsPerChar:r,alphabet:n})=>ts({prefix:e,name:t,encode(i){return HR(i,n,r)},decode(i){return VR(i,n,r,t)}});var rs=Xe({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),qR=Xe({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),$R=Xe({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),zR=Xe({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),GR=Xe({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),WR=Xe({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),YR=Xe({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),jR=Xe({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),QR=Xe({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Nd={};Y(Nd,{base58btc:()=>je,base58flickr:()=>JR});var je=fi({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),JR=fi({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var XR=Pb,kb=128,ZR=127,eB=~ZR,tB=Math.pow(2,31);function Pb(t,e,r){e=e||[],r=r||0;for(var n=r;t>=tB;)e[r++]=t&255|kb,t/=128;for(;t&eB;)e[r++]=t&255|kb,t>>>=7;return e[r]=t|0,Pb.bytes=r-n+1,e}var rB=Ld,nB=128,Cb=127;function Ld(t,n){var r=0,n=n||0,i=0,o=n,s,a=t.length;do{if(o>=a)throw Ld.bytes=0,new RangeError("Could not decode varint");s=t[o++],r+=i<28?(s&Cb)<<i:(s&Cb)*Math.pow(2,i),i+=7}while(s>=nB);return Ld.bytes=o-n,r}var iB=Math.pow(2,7),oB=Math.pow(2,14),sB=Math.pow(2,21),aB=Math.pow(2,28),cB=Math.pow(2,35),uB=Math.pow(2,42),lB=Math.pow(2,49),fB=Math.pow(2,56),hB=Math.pow(2,63),dB=function(t){return t<iB?1:t<oB?2:t<sB?3:t<aB?4:t<cB?5:t<uB?6:t<lB?7:t<fB?8:t<hB?9:10},pB={encode:XR,decode:rB,encodingLength:dB},mB=pB,Ya=mB;var ja=(t,e=0)=>[Ya.decode(t,e),Ya.decode.bytes],ns=(t,e,r=0)=>(Ya.encode(t,e,r),e),is=t=>Ya.encodingLength(t);var io=(t,e)=>{let r=e.byteLength,n=is(t),i=n+is(r),o=new Uint8Array(i+r);return ns(t,o,0),ns(r,o,n),o.set(e,i),new os(t,r,e,o)},Db=t=>{let e=Rn(t),[r,n]=ja(e),[i,o]=ja(e.subarray(n)),s=e.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new os(r,i,s,e)},Nb=(t,e)=>{if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&_b(t.bytes,r.bytes)}},os=class{constructor(e,r,n,i){this.code=e,this.size=r,this.digest=n,this.bytes=i}};var Lb=(t,e)=>{let{bytes:r,version:n}=t;switch(n){case 0:return gB(r,Od(t),e||je.encoder);default:return bB(r,Od(t),e||rs.encoder)}};var Ob=new WeakMap,Od=t=>{let e=Ob.get(t);if(e==null){let r=new Map;return Ob.set(t,r),r}return e},ar=class t{constructor(e,r,n,i){this.code=r,this.version=e,this.multihash=n,this.bytes=i,this["/"]=i}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==Ja)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==wB)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=io(e,r);return t.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let n=r;return n&&e.code===n.code&&e.version===n.version&&Nb(e.multihash,n.multihash)}toString(e){return Lb(this,e)}toJSON(){return{"/":Lb(this)}}link(){return this}get[Symbol.toStringTag](){return"CID"}[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:i,multihash:o,bytes:s}=r;return new t(n,i,o,s||Ub(n,i,o.bytes))}else if(r[xB]===!0){let{version:n,multihash:i,code:o}=r,s=Db(i);return t.create(n,o,s)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==Ja)throw new Error(`Version 0 CID must use dag-pb (code: ${Ja}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let i=Ub(e,r,n.bytes);return new t(e,r,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Ja,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,i=Rn(e.subarray(n,n+r.multihashSize));if(i.byteLength!==r.multihashSize)throw new Error("Incorrect length");let o=i.subarray(r.multihashSize-r.digestSize),s=new os(r.multihashCode,r.digestSize,o,i);return[r.version===0?t.createV0(s):t.createV1(r.codec,s),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[f,d]=ja(e.subarray(r));return r+=d,f},i=n(),o=Ja;if(i===18?(i=0,r=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let s=r,a=n(),c=n(),u=r+c,l=u-s;return{version:i,codec:o,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(e,r){let[n,i]=yB(e,r),o=t.decode(i);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Od(o).set(n,e),o}},yB=(t,e)=>{switch(t[0]){case"Q":{let r=e||je;return[je.prefix,r.decode(`${je.prefix}${t}`)]}case je.prefix:{let r=e||je;return[je.prefix,r.decode(t)]}case rs.prefix:{let r=e||rs;return[rs.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}},gB=(t,e,r)=>{let{prefix:n}=r;if(n!==je.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let i=e.get(n);if(i==null){let o=r.encode(t).slice(1);return e.set(n,o),o}else return i},bB=(t,e,r)=>{let{prefix:n}=r,i=e.get(n);if(i==null){let o=r.encode(t);return e.set(n,o),o}else return i},Ja=112,wB=18,Ub=(t,e,r)=>{let n=is(t),i=n+is(e),o=new Uint8Array(i+r.byteLength);return ns(t,o,0),ns(e,o,n),o.set(r,i),o},xB=Symbol.for("@ipld/js-cid/CID");var Ud=class extends Map{metric;constructor(e){super();let{name:r,metrics:n}=e;this.metric=n.registerMetric(r),this.updateComponentMetric()}set(e,r){return super.set(e,r),this.updateComponentMetric(),this}delete(e){let r=super.delete(e);return this.updateComponentMetric(),r}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function ss(t){let{name:e,metrics:r}=t,n;return r!=null?n=new Ud({name:e,metrics:r}):n=new Map,n}var Kb=Symbol.for("@libp2p/connection");var Kd=Symbol.for("@libp2p/content-routing");var Md=Symbol.for("@libp2p/peer-discovery");var Fd=Symbol.for("@libp2p/peer-id");function Cu(t){return t!=null&&!!t[Fd]}var Vd=Symbol.for("@libp2p/peer-routing");var Mb="keep-alive";var Fb;(function(t){t.Accept="accept",t.Ignore="ignore",t.Reject="reject"})(Fb||(Fb={}));var FU=Symbol.for("@libp2p/transport");var hi;(function(t){t[t.FATAL_ALL=0]="FATAL_ALL",t[t.NO_FATAL=1]="NO_FATAL"})(hi||(hi={}));var di=class t extends Error{code;type;constructor(e="The operation was aborted"){super(e),this.code=t.code,this.type=t.type}static code="ABORT_ERR";static type="aborted"},x=class extends Error{code;props;constructor(e,r,n){super(e),this.code=r,this.name=n?.name??"CodeError",this.props=n??{}}},Pu=class extends AggregateError{code;props;constructor(e,r,n,i){super(e,r),this.code=n,this.name=i?.name??"AggregateCodeError",this.props=i??{}}};var Du="ERR_TIMEOUT";var oo=class extends EventTarget{#e=new Map;listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){super.addEventListener(e,r,n);let i=this.#e.get(e);i==null&&(i=[],this.#e.set(e,i)),i.push({callback:r,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,r,n){super.removeEventListener(e.toString(),r??null,n);let i=this.#e.get(e);i!=null&&(i=i.filter(({callback:o})=>o!==r),this.#e.set(e,i))}dispatchEvent(e){let r=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:i})=>!i),this.#e.set(e.type,n)),r}safeDispatchEvent(e,r={}){return this.dispatchEvent(new qd(e,r))}},Hd=class extends Event{detail;constructor(e,r){super(e,r),this.detail=r?.detail}},qd=globalThis.CustomEvent??Hd;var xr=(t,...e)=>{try{[...e]}catch{}};function Nu(t){return t!=null&&typeof t.start=="function"&&typeof t.stop=="function"}async function as(...t){let e=[];for(let r of t)Nu(r)&&e.push(r);await Promise.all(e.map(async r=>{r.beforeStart!=null&&await r.beforeStart()})),await Promise.all(e.map(async r=>{await r.start()})),await Promise.all(e.map(async r=>{r.afterStart!=null&&await r.afterStart()}))}async function cs(...t){let e=[];for(let r of t)Nu(r)&&e.push(r);await Promise.all(e.map(async r=>{r.beforeStop!=null&&await r.beforeStop()})),await Promise.all(e.map(async r=>{await r.stop()})),await Promise.all(e.map(async r=>{r.afterStop!=null&&await r.afterStop()}))}var Gd={};Y(Gd,{sha256:()=>Xa,sha512:()=>vB});var zd=({name:t,code:e,encode:r})=>new $d(t,e,r),$d=class{constructor(e,r,n){this.name=e,this.code=r,this.encode=n}digest(e){if(e instanceof Uint8Array){let r=this.encode(e);return r instanceof Uint8Array?io(this.code,r):r.then(n=>io(this.code,n))}else throw Error("Unknown type, must be binary type")}};var Hb=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),Xa=zd({name:"sha2-256",code:18,encode:Hb("SHA-256")}),vB=zd({name:"sha2-512",code:19,encode:Hb("SHA-512")});var Yw=me(rw(),1);var ur=me(Uu(),1);var Zd={};Y(Zd,{base32:()=>dt,base32hex:()=>tT,base32hexpad:()=>nT,base32hexpadupper:()=>iT,base32hexupper:()=>rT,base32pad:()=>ZB,base32padupper:()=>eT,base32upper:()=>XB,base32z:()=>oT});var IK=new Uint8Array(0);function sw(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Bn(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function aw(t){return new TextEncoder().encode(t)}function cw(t){return new TextDecoder().decode(t)}function WB(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var i=0;i<t.length;i++){var o=t.charAt(i),s=o.charCodeAt(0);if(r[s]!==255)throw new TypeError(o+" is ambiguous");r[s]=i}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function f(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var m=0,y=0,g=0,b=h.length;g!==b&&h[g]===0;)g++,m++;for(var w=(b-g)*l+1>>>0,_=new Uint8Array(w);g!==b;){for(var E=h[g],A=0,B=w-1;(E!==0||A<y)&&B!==-1;B--,A++)E+=256*_[B]>>>0,_[B]=E%a>>>0,E=E/a>>>0;if(E!==0)throw new Error("Non-zero carry");y=A,g++}for(var I=w-y;I!==w&&_[I]===0;)I++;for(var L=c.repeat(m);I<w;++I)L+=t.charAt(_[I]);return L}function d(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var m=0;if(h[m]!==" "){for(var y=0,g=0;h[m]===c;)y++,m++;for(var b=(h.length-m)*u+1>>>0,w=new Uint8Array(b);h[m];){var _=r[h.charCodeAt(m)];if(_===255)return;for(var E=0,A=b-1;(_!==0||E<g)&&A!==-1;A--,E++)_+=a*w[A]>>>0,w[A]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");g=E,m++}if(h[m]!==" "){for(var B=b-g;B!==b&&w[B]===0;)B++;for(var I=new Uint8Array(y+(b-B)),L=y;B!==b;)I[L++]=w[B++];return I}}}function p(h){var m=d(h);if(m)return m;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:d,decode:p}}var YB=WB,jB=YB,lw=jB;var jd=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Qd=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){if(this.name=e,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return fw(this,e)}},Jd=class{decoders;constructor(e){this.decoders=e}or(e){return fw(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function fw(t,e){return new Jd({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Xd=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,i){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=i,this.encoder=new jd(e,r,n),this.decoder=new Qd(e,r,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function hs({name:t,prefix:e,encode:r,decode:n}){return new Xd(t,e,r,n)}function pi({name:t,prefix:e,alphabet:r}){let{encode:n,decode:i}=lw(r,t);return hs({prefix:e,name:t,encode:n,decode:o=>Bn(i(o))})}function QB(t,e,r,n){let i={};for(let l=0;l<e.length;++l)i[e[l]]=l;let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),a=0,c=0,u=0;for(let l=0;l<o;++l){let f=i[t[l]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|f,a+=r,a>=8&&(a-=8,s[u++]=255&c>>a)}if(a>=r||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return s}function JB(t,e,r){let n=e[e.length-1]==="=",i=(1<<r)-1,o="",s=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],s+=8;s>r;)s-=r,o+=e[i&a>>s];if(s!==0&&(o+=e[i&a<<r-s]),n)for(;o.length*r&7;)o+="=";return o}function Ze({name:t,prefix:e,bitsPerChar:r,alphabet:n}){return hs({prefix:e,name:t,encode(i){return JB(i,n,r)},decode(i){return QB(i,n,r,t)}})}var dt=Ze({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),XB=Ze({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),ZB=Ze({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),eT=Ze({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),tT=Ze({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),rT=Ze({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),nT=Ze({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),iT=Ze({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),oT=Ze({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ep={};Y(ep,{base58btc:()=>Oe,base58flickr:()=>sT});var Oe=pi({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),sT=pi({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var rp={};Y(rp,{base64:()=>$t,base64pad:()=>aT,base64url:()=>tp,base64urlpad:()=>cT});var $t=Ze({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),aT=Ze({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),tp=Ze({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),cT=Ze({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});ur.default.formatters.b=t=>t==null?"undefined":Oe.baseEncode(t);ur.default.formatters.t=t=>t==null?"undefined":dt.baseEncode(t);ur.default.formatters.m=t=>t==null?"undefined":$t.baseEncode(t);ur.default.formatters.p=t=>t==null?"undefined":t.toString();ur.default.formatters.c=t=>t==null?"undefined":t.toString();ur.default.formatters.k=t=>t==null?"undefined":t.toString();ur.default.formatters.a=t=>t==null?"undefined":t.toString();function uT(t){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=t,e.destroy=()=>!0,e.extend=()=>e,e}function Ku(){return{forComponent(t){return ds(t)}}}function ds(t){let e=uT(`${t}:trace`);return ur.default.enabled(`${t}:trace`)&&ur.default.names.map(r=>r.toString()).find(r=>r.includes(":trace"))!=null&&(e=(0,ur.default)(`${t}:trace`)),Object.assign((0,ur.default)(t),{error:(0,ur.default)(`${t}:error`),trace:e})}function hw(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}var Za=class{_refCounter;cid;priority;wantType;constructor(e,r,n){this._refCounter=1,this.cid=e,this.priority=r??1,this.wantType=n}inc(){this._refCounter+=1}dec(){this._refCounter=Math.max(0,this._refCounter-1)}hasRefs(){return this._refCounter>0}get[Symbol.toStringTag](){return`WantlistEntry <key: ${this.cid.toString(je)}, priority: ${this.priority}, refs: ${this._refCounter}>`}equals(e){return this._refCounter===e._refCounter&&this.cid.equals(e.cid)&&this.priority===e.priority&&this.wantType===e.wantType}};var mi=class{entry;cancel;sendDontHave;constructor(e,r,n,i,o){this.entry=new Za(e,r,n),this.cancel=!!i,this.sendDontHave=!!o}get cid(){return this.entry.cid}set cid(e){this.entry.cid=e}get priority(){return this.entry.priority}set priority(e){this.entry.priority=e}get wantType(){return this.entry.wantType}set wantType(e){this.entry.wantType=e}get[Symbol.toStringTag](){return`BitswapMessageEntry ${this.cid.toString(je)} <cancel: ${this.cancel}, priority: ${this.priority}>`}equals(e){return this.cancel===e.cancel&&this.sendDontHave===e.sendDontHave&&this.wantType===e.wantType&&this.entry.equals(e.entry)}};var Mu=(t,e)=>{if(t.size!==e.size)return!1;for(let[r,n]of t){let i=e.get(r);if(i===void 0||n instanceof Uint8Array&&i instanceof Uint8Array&&!hw(n,i)||n instanceof mi&&i instanceof mi&&!n.equals(i))return!1}return!0};var ec=me(Ew(),1);function AT(t){let e=new Uint8Array(t.reduce((n,i)=>n+ec.default.encodingLength(i),0)),r=0;for(let n of t)e=ec.encode(n,e,r),r+=ec.default.encodingLength(n);return e}var Aw=AT;var op=new Float32Array([-0]),yi=new Uint8Array(op.buffer);function Sw(t,e,r){op[0]=t,e[r]=yi[0],e[r+1]=yi[1],e[r+2]=yi[2],e[r+3]=yi[3]}function _w(t,e){return yi[0]=t[e],yi[1]=t[e+1],yi[2]=t[e+2],yi[3]=t[e+3],op[0]}var sp=new Float64Array([-0]),Ut=new Uint8Array(sp.buffer);function Iw(t,e,r){sp[0]=t,e[r]=Ut[0],e[r+1]=Ut[1],e[r+2]=Ut[2],e[r+3]=Ut[3],e[r+4]=Ut[4],e[r+5]=Ut[5],e[r+6]=Ut[6],e[r+7]=Ut[7]}function Rw(t,e){return Ut[0]=t[e],Ut[1]=t[e+1],Ut[2]=t[e+2],Ut[3]=t[e+3],Ut[4]=t[e+4],Ut[5]=t[e+5],Ut[6]=t[e+6],Ut[7]=t[e+7],sp[0]}var ST=BigInt(Number.MAX_SAFE_INTEGER),_T=BigInt(Number.MIN_SAFE_INTEGER),Jt=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return ao;if(e<ST&&e>_T)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,i=e-(n<<32n);return r&&(n=~n|0n,i=~i|0n,++i>Bw&&(i=0n,++n>Bw&&(n=0n))),new t(Number(i),Number(n))}static fromNumber(e){if(e===0)return ao;let r=e<0;r&&(e=-e);let n=e>>>0,i=(e-n)/4294967296>>>0;return r&&(i=~i>>>0,n=~n>>>0,++n>4294967295&&(n=0,++i>4294967295&&(i=0))),new t(n,i)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):ao}},ao=new Jt(0,0);ao.toBigInt=function(){return 0n};ao.zzEncode=ao.zzDecode=function(){return this};ao.length=function(){return 1};var Bw=4294967296n;function Tw(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function kw(t,e,r){if(r-e<1)return"";let i,o=[],s=0,a;for(;e<r;)a=t[e++],a<128?o[s++]=a:a>191&&a<224?o[s++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,o[s++]=55296+(a>>10),o[s++]=56320+(a&1023)):o[s++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,s>8191&&((i??(i=[])).push(String.fromCharCode.apply(String,o)),s=0);return i!=null?(s>0&&i.push(String.fromCharCode.apply(String,o.slice(0,s))),i.join("")):String.fromCharCode.apply(String,o.slice(0,s))}function ap(t,e,r){let n=r,i,o;for(let s=0;s<t.length;++s)i=t.charCodeAt(s),i<128?e[r++]=i:i<2048?(e[r++]=i>>6|192,e[r++]=i&63|128):(i&64512)===55296&&((o=t.charCodeAt(s+1))&64512)===56320?(i=65536+((i&1023)<<10)+(o&1023),++s,e[r++]=i>>18|240,e[r++]=i>>12&63|128,e[r++]=i>>6&63|128,e[r++]=i&63|128):(e[r++]=i>>12|224,e[r++]=i>>6&63|128,e[r++]=i&63|128);return r-n}function Or(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function Fu(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var cp=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Or(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Or(this,4);return Fu(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Or(this,4);return Fu(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Or(this,4);let e=_w(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Or(this,4);let e=Rw(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw Or(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return kw(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Or(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Or(this);while(this.buf[this.pos++]&128);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Jt(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Or(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw Or(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Or(this,8);let e=Fu(this.buf,this.pos+=4),r=Fu(this.buf,this.pos+=4);return new Jt(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){return this.readLongVarint().toNumber(!0)}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function up(t){return new cp(t instanceof Uint8Array?t:t.subarray())}function xe(t,e){let r=up(t);return e.decode(r)}function gi(t){return globalThis.Buffer!=null?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t}function Tn(t=0){return globalThis.Buffer?.alloc!=null?gi(globalThis.Buffer.alloc(t)):new Uint8Array(t)}function Kt(t=0){return globalThis.Buffer?.allocUnsafe!=null?gi(globalThis.Buffer.allocUnsafe(t)):new Uint8Array(t)}var lp={};Y(lp,{base10:()=>IT});var IT=pi({prefix:"9",name:"base10",alphabet:"0123456789"});var fp={};Y(fp,{base16:()=>RT,base16upper:()=>BT});var RT=Ze({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),BT=Ze({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var hp={};Y(hp,{base2:()=>TT});var TT=Ze({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var dp={};Y(dp,{base256emoji:()=>NT});var Pw=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),kT=Pw.reduce((t,e,r)=>(t[r]=e,t),[]),CT=Pw.reduce((t,e,r)=>(t[e.codePointAt(0)]=r,t),[]);function PT(t){return t.reduce((e,r)=>(e+=kT[r],e),"")}function DT(t){let e=[];for(let r of t){let n=CT[r.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${r}`);e.push(n)}return new Uint8Array(e)}var NT=hs({prefix:"\u{1F680}",name:"base256emoji",encode:PT,decode:DT});var pp={};Y(pp,{base36:()=>tc,base36upper:()=>LT});var tc=pi({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),LT=pi({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var mp={};Y(mp,{base8:()=>OT});var OT=Ze({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var yp={};Y(yp,{identity:()=>UT});var UT=hs({prefix:"\0",name:"identity",encode:t=>cw(t),decode:t=>aw(t)});var xM=new TextEncoder,vM=new TextDecoder;var Dw=512;var Vu=85;var wp={};Y(wp,{identity:()=>Xt});var KT=Uw,Lw=128,MT=127,FT=~MT,VT=Math.pow(2,31);function Uw(t,e,r){e=e||[],r=r||0;for(var n=r;t>=VT;)e[r++]=t&255|Lw,t/=128;for(;t&FT;)e[r++]=t&255|Lw,t>>>=7;return e[r]=t|0,Uw.bytes=r-n+1,e}var HT=bp,qT=128,Ow=127;function bp(t,n){var r=0,n=n||0,i=0,o=n,s,a=t.length;do{if(o>=a)throw bp.bytes=0,new RangeError("Could not decode varint");s=t[o++],r+=i<28?(s&Ow)<<i:(s&Ow)*Math.pow(2,i),i+=7}while(s>=qT);return bp.bytes=o-n,r}var $T=Math.pow(2,7),zT=Math.pow(2,14),GT=Math.pow(2,21),WT=Math.pow(2,28),YT=Math.pow(2,35),jT=Math.pow(2,42),QT=Math.pow(2,49),JT=Math.pow(2,56),XT=Math.pow(2,63),ZT=function(t){return t<$T?1:t<zT?2:t<GT?3:t<WT?4:t<YT?5:t<jT?6:t<QT?7:t<JT?8:t<XT?9:10},e8={encode:KT,decode:HT,encodingLength:ZT},t8=e8,rc=t8;function nc(t,e=0){return[rc.decode(t,e),rc.decode.bytes]}function ps(t,e,r=0){return rc.encode(t,e,r),e}function ms(t){return rc.encodingLength(t)}function Xr(t,e){let r=e.byteLength,n=ms(t),i=n+ms(r),o=new Uint8Array(i+r);return ps(t,o,0),ps(r,o,n),o.set(e,i),new ys(t,r,e,o)}function kn(t){let e=Bn(t),[r,n]=nc(e),[i,o]=nc(e.subarray(n)),s=e.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new ys(r,i,s,e)}function Kw(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&sw(t.bytes,r.bytes)}}var ys=class{code;size;digest;bytes;constructor(e,r,n,i){this.code=e,this.size=r,this.digest=n,this.bytes=i}};var Mw=0,r8="identity",Fw=Bn;function n8(t){return Xr(Mw,Fw(t))}var Xt={code:Mw,name:r8,encode:Fw,digest:n8};var Ap={};Y(Ap,{sha256:()=>ae,sha512:()=>Ep});function vp({name:t,code:e,encode:r}){return new xp(t,e,r)}var xp=class{name;code;encode;constructor(e,r,n){this.name=e,this.code=r,this.encode=n}digest(e){if(e instanceof Uint8Array){let r=this.encode(e);return r instanceof Uint8Array?Xr(this.code,r):r.then(n=>Xr(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Hw(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var ae=vp({name:"sha2-256",code:18,encode:Hw("SHA-256")}),Ep=vp({name:"sha2-512",code:19,encode:Hw("SHA-512")});function qw(t,e){let{bytes:r,version:n}=t;switch(n){case 0:return o8(r,Sp(t),e??Oe.encoder);default:return s8(r,Sp(t),e??dt.encoder)}}var $w=new WeakMap;function Sp(t){let e=$w.get(t);if(e==null){let r=new Map;return $w.set(t,r),r}return e}var Fe=class t{code;version;multihash;bytes;"/";constructor(e,r,n,i){this.code=r,this.version=e,this.multihash=n,this.bytes=i,this["/"]=i}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==ic)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==a8)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=Xr(e,r);return t.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&Kw(e.multihash,n.multihash)}toString(e){return qw(this,e)}toJSON(){return{"/":qw(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:i,multihash:o,bytes:s}=r;return new t(n,i,o,s??zw(n,i,o.bytes))}else if(r[c8]===!0){let{version:n,multihash:i,code:o}=r,s=kn(i);return t.create(n,o,s)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==ic)throw new Error(`Version 0 CID must use dag-pb (code: ${ic}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let i=zw(e,r,n.bytes);return new t(e,r,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,ic,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,i=Bn(e.subarray(n,n+r.multihashSize));if(i.byteLength!==r.multihashSize)throw new Error("Incorrect length");let o=i.subarray(r.multihashSize-r.digestSize),s=new ys(r.multihashCode,r.digestSize,o,i);return[r.version===0?t.createV0(s):t.createV1(r.codec,s),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[f,d]=nc(e.subarray(r));return r+=d,f},i=n(),o=ic;if(i===18?(i=0,r=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let s=r,a=n(),c=n(),u=r+c,l=u-s;return{version:i,codec:o,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(e,r){let[n,i]=i8(e,r),o=t.decode(i);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Sp(o).set(n,e),o}};function i8(t,e){switch(t[0]){case"Q":{let r=e??Oe;return[Oe.prefix,r.decode(`${Oe.prefix}${t}`)]}case Oe.prefix:{let r=e??Oe;return[Oe.prefix,r.decode(t)]}case dt.prefix:{let r=e??dt;return[dt.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function o8(t,e,r){let{prefix:n}=r;if(n!==Oe.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let i=e.get(n);if(i==null){let o=r.encode(t).slice(1);return e.set(n,o),o}else return i}function s8(t,e,r){let{prefix:n}=r,i=e.get(n);if(i==null){let o=r.encode(t);return e.set(n,o),o}else return i}var ic=112,a8=18;function zw(t,e,r){let n=ms(t),i=n+ms(e),o=new Uint8Array(i+r.byteLength);return ps(t,o,0),ps(e,o,n),o.set(r,i),o}var c8=Symbol.for("@ipld/js-cid/CID");var wi={...yp,...hp,...mp,...lp,...fp,...Zd,...pp,...ep,...rp,...dp},HM={...Ap,...wp};function Ww(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Gw=Ww("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),_p=Ww("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=Kt(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),u8={utf8:Gw,"utf-8":Gw,hex:wi.base16,latin1:_p,ascii:_p,binary:_p,...wi},qu=u8;function U(t,e="utf8"){let r=qu[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?gi(globalThis.Buffer.from(t,"utf-8")):r.decoder.decode(`${r.prefix}${t}`)}function Ip(t){let e=t??8192,r=e>>>1,n,i=e;return function(s){if(s<1||s>r)return Kt(s);i+s>e&&(n=Kt(e),i=0);let a=n.subarray(i,i+=s);return i&7&&(i=(i|7)+1),a}}var co=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function Rp(){}var Tp=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},l8=Ip();function f8(t){return globalThis.Buffer!=null?Kt(t):l8(t)}var ac=class{len;head;tail;states;constructor(){this.len=0,this.head=new co(Rp,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new co(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new kp((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(oc,10,Jt.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=Jt.fromBigInt(e);return this._push(oc,r.length(),r)}uint64Number(e){let r=Jt.fromNumber(e);return this._push(oc,r.length(),r)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=Jt.fromBigInt(e).zzEncode();return this._push(oc,r.length(),r)}sint64Number(e){let r=Jt.fromNumber(e).zzEncode();return this._push(oc,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Bp,1,e?1:0)}fixed32(e){return this._push(sc,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=Jt.fromBigInt(e);return this._push(sc,4,r.lo)._push(sc,4,r.hi)}fixed64Number(e){let r=Jt.fromNumber(e);return this._push(sc,4,r.lo)._push(sc,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(Sw,4,e)}double(e){return this._push(Iw,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(Bp,1,0):this.uint32(r)._push(d8,r,e)}string(e){let r=Tw(e);return r!==0?this.uint32(r)._push(ap,r,e):this._push(Bp,1,0)}fork(){return this.states=new Tp(this),this.head=this.tail=new co(Rp,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new co(Rp,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=f8(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function Bp(t,e,r){e[r]=t&255}function h8(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var kp=class extends co{next;constructor(e,r){super(h8,e,r),this.next=void 0}};function oc(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function sc(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function d8(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(ac.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(p8,e,t),this},ac.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(m8,e,t),this});function p8(t,e,r){e.set(t,r)}function m8(t,e,r){t.length<40?ap(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(U(t),r)}function Cp(){return new ac}function ve(t,e){let r=Cp();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}var gs;(function(t){t[t.VARINT=0]="VARINT",t[t.BIT64=1]="BIT64",t[t.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",t[t.START_GROUP=3]="START_GROUP",t[t.END_GROUP=4]="END_GROUP",t[t.BIT32=5]="BIT32"})(gs||(gs={}));function $u(t,e,r,n){return{name:t,type:e,encode:r,decode:n}}function Zt(t){function e(i){if(t[i.toString()]==null)throw new Error("Invalid enum value");return t[i]}let r=function(o,s){let a=e(o);s.int32(a)},n=function(o){let s=o.int32();return e(s)};return $u("enum",gs.VARINT,r,n)}function Ee(t,e){return $u("message",gs.LENGTH_DELIMITED,t,e)}var er;(function(t){let e;(function(a){let c;(function(d){d.Block="Block",d.Have="Have"})(c=a.WantType||(a.WantType={}));let u;(function(d){d[d.Block=0]="Block",d[d.Have=1]="Have"})(u||(u={})),function(d){d.codec=()=>Zt(u)}(c=a.WantType||(a.WantType={}));let l;(function(d){let p;d.codec=()=>(p==null&&(p=Ee((h,m,y={})=>{y.lengthDelimited!==!1&&m.fork(),h.block!=null&&h.block.byteLength>0&&(m.uint32(10),m.bytes(h.block)),h.priority!=null&&h.priority!==0&&(m.uint32(16),m.int32(h.priority)),h.cancel!=null&&h.cancel!==!1&&(m.uint32(24),m.bool(h.cancel)),h.wantType!=null&&u[h.wantType]!==0&&(m.uint32(32),t.Wantlist.WantType.codec().encode(h.wantType,m)),h.sendDontHave!=null&&h.sendDontHave!==!1&&(m.uint32(40),m.bool(h.sendDontHave)),y.lengthDelimited!==!1&&m.ldelim()},(h,m)=>{let y={block:new Uint8Array(0),priority:0,cancel:!1,wantType:c.Block,sendDontHave:!1},g=m==null?h.len:h.pos+m;for(;h.pos<g;){let b=h.uint32();switch(b>>>3){case 1:y.block=h.bytes();break;case 2:y.priority=h.int32();break;case 3:y.cancel=h.bool();break;case 4:y.wantType=t.Wantlist.WantType.codec().decode(h);break;case 5:y.sendDontHave=h.bool();break;default:h.skipType(b&7);break}}return y})),p),d.encode=h=>ve(h,d.codec()),d.decode=h=>xe(h,d.codec())})(l=a.Entry||(a.Entry={}));let f;a.codec=()=>(f==null&&(f=Ee((d,p,h={})=>{if(h.lengthDelimited!==!1&&p.fork(),d.entries!=null)for(let m of d.entries)p.uint32(10),t.Wantlist.Entry.codec().encode(m,p);d.full!=null&&d.full!==!1&&(p.uint32(16),p.bool(d.full)),h.lengthDelimited!==!1&&p.ldelim()},(d,p)=>{let h={entries:[],full:!1},m=p==null?d.len:d.pos+p;for(;d.pos<m;){let y=d.uint32();switch(y>>>3){case 1:h.entries.push(t.Wantlist.Entry.codec().decode(d,d.uint32()));break;case 2:h.full=d.bool();break;default:d.skipType(y&7);break}}return h})),f),a.encode=d=>ve(d,a.codec()),a.decode=d=>xe(d,a.codec())})(e=t.Wantlist||(t.Wantlist={}));let r;(function(a){let c;a.codec=()=>(c==null&&(c=Ee((u,l,f={})=>{f.lengthDelimited!==!1&&l.fork(),u.prefix!=null&&u.prefix.byteLength>0&&(l.uint32(10),l.bytes(u.prefix)),u.data!=null&&u.data.byteLength>0&&(l.uint32(18),l.bytes(u.data)),f.lengthDelimited!==!1&&l.ldelim()},(u,l)=>{let f={prefix:new Uint8Array(0),data:new Uint8Array(0)},d=l==null?u.len:u.pos+l;for(;u.pos<d;){let p=u.uint32();switch(p>>>3){case 1:f.prefix=u.bytes();break;case 2:f.data=u.bytes();break;default:u.skipType(p&7);break}}return f})),c),a.encode=u=>ve(u,a.codec()),a.decode=u=>xe(u,a.codec())})(r=t.Block||(t.Block={}));let n;(function(a){a.Have="Have",a.DontHave="DontHave"})(n=t.BlockPresenceType||(t.BlockPresenceType={}));let i;(function(a){a[a.Have=0]="Have",a[a.DontHave=1]="DontHave"})(i||(i={})),function(a){a.codec=()=>Zt(i)}(n=t.BlockPresenceType||(t.BlockPresenceType={}));let o;(function(a){let c;a.codec=()=>(c==null&&(c=Ee((u,l,f={})=>{f.lengthDelimited!==!1&&l.fork(),u.cid!=null&&u.cid.byteLength>0&&(l.uint32(10),l.bytes(u.cid)),u.type!=null&&i[u.type]!==0&&(l.uint32(16),t.BlockPresenceType.codec().encode(u.type,l)),f.lengthDelimited!==!1&&l.ldelim()},(u,l)=>{let f={cid:new Uint8Array(0),type:n.Have},d=l==null?u.len:u.pos+l;for(;u.pos<d;){let p=u.uint32();switch(p>>>3){case 1:f.cid=u.bytes();break;case 2:f.type=t.BlockPresenceType.codec().decode(u);break;default:u.skipType(p&7);break}}return f})),c),a.encode=u=>ve(u,a.codec()),a.decode=u=>xe(u,a.codec())})(o=t.BlockPresence||(t.BlockPresence={}));let s;t.codec=()=>(s==null&&(s=Ee((a,c,u={})=>{if(u.lengthDelimited!==!1&&c.fork(),a.wantlist!=null&&(c.uint32(10),t.Wantlist.codec().encode(a.wantlist,c)),a.blocks!=null)for(let l of a.blocks)c.uint32(18),c.bytes(l);if(a.payload!=null)for(let l of a.payload)c.uint32(26),t.Block.codec().encode(l,c);if(a.blockPresences!=null)for(let l of a.blockPresences)c.uint32(34),t.BlockPresence.codec().encode(l,c);a.pendingBytes!=null&&a.pendingBytes!==0&&(c.uint32(40),c.int32(a.pendingBytes)),u.lengthDelimited!==!1&&c.ldelim()},(a,c)=>{let u={blocks:[],payload:[],blockPresences:[],pendingBytes:0},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let f=a.uint32();switch(f>>>3){case 1:u.wantlist=t.Wantlist.codec().decode(a,a.uint32());break;case 2:u.blocks.push(a.bytes());break;case 3:u.payload.push(t.Block.codec().decode(a,a.uint32()));break;case 4:u.blockPresences.push(t.BlockPresence.codec().decode(a,a.uint32()));break;case 5:u.pendingBytes=a.int32();break;default:a.skipType(f&7);break}}return u})),s),t.encode=a=>ve(a,t.codec()),t.decode=a=>xe(a,t.codec())})(er||(er={}));var uo=class t{static Entry=mi;static WantType={Block:er.Wantlist.WantType.Block,Have:er.Wantlist.WantType.Have};static BlockPresenceType={Have:er.BlockPresenceType.Have,DontHave:er.BlockPresenceType.DontHave};static deserialize=async(e,r)=>{let n=er.decode(e),i=n.wantlist?.full===!0,o=new t(i);return n.wantlist?.entries.forEach(s=>{if(s.block==null)return;let a=ar.decode(s.block);o.addEntry(a,s.priority??0,s.wantType,!!s.cancel,!!s.sendDontHave)}),n.blockPresences.forEach(s=>{if(s.cid==null)return;let a=ar.decode(s.cid);s.type===t.BlockPresenceType.Have?o.addHave(a):o.addDontHave(a)}),n.blocks.length>0?(await Promise.all(n.blocks.map(async s=>{let a=await Xa.digest(s),c=ar.createV0(a);o.addBlock(c,s)})),o):(n.payload.length>0&&(await Promise.all(n.payload.map(async s=>{if(s.prefix==null||s.data==null)return;let a=(0,Yw.default)(s.prefix),c=a[0],u=a[1],l=a[2],f=l===Xa.code?Xa:await r?.getHasher(l);if(f==null)throw new x("Unknown hash algorithm","ERR_UNKNOWN_HASH_ALG");let d=await f.digest(s.data),p=ar.create(c,u,d);o.addBlock(p,s.data)})),o.setPendingBytes(n.pendingBytes)),o)};static blockPresenceSize=e=>e.bytes.length+1;full;wantlist;blocks;blockPresences;pendingBytes;constructor(e){this.full=e,this.wantlist=new Map,this.blocks=new Map,this.blockPresences=new Map,this.pendingBytes=0}get empty(){return this.blocks.size===0&&this.wantlist.size===0&&this.blockPresences.size===0}addEntry(e,r,n,i,o){n==null&&(n=t.WantType.Block);let s=e.toString(je),a=this.wantlist.get(s);a!=null?(a.wantType===n&&(a.priority=r),i===!0&&(a.cancel=!!i),o===!0&&(a.sendDontHave=!!o),n===t.WantType.Block&&a.wantType===t.WantType.Have&&(a.wantType=n)):this.wantlist.set(s,new mi(e,r,n,i,o))}addBlock(e,r){let n=e.toString(je);this.blocks.set(n,r)}addHave(e){let r=e.toString(je);this.blockPresences.has(r)||this.blockPresences.set(r,t.BlockPresenceType.Have)}addDontHave(e){let r=e.toString(je);this.blockPresences.has(r)||this.blockPresences.set(r,t.BlockPresenceType.DontHave)}cancel(e){let r=e.toString(je);this.wantlist.delete(r),this.addEntry(e,0,t.WantType.Block,!0,!1)}setPendingBytes(e){this.pendingBytes=e}serializeToBitswap100(){return er.encode({wantlist:{entries:Array.from(this.wantlist.values()).map(e=>({block:e.cid.bytes,priority:Number(e.priority),cancel:!!e.cancel,wantType:er.Wantlist.WantType.Block,sendDontHave:!1})),full:!!this.full},blocks:Array.from(this.blocks.values())})}serializeToBitswap110(){let e={wantlist:{entries:Array.from(this.wantlist.values()).map(r=>({block:r.cid.bytes,priority:Number(r.priority),wantType:r.wantType,cancel:!!r.cancel,sendDontHave:!!r.sendDontHave})),full:!!this.full},blockPresences:[],payload:[],pendingBytes:this.pendingBytes,blocks:[]};for(let[r,n]of this.blocks.entries()){let i=ar.parse(r),o=i.version,s=i.code,a=i.multihash.code,c=i.multihash.digest.length,u=Aw([o,s,a,c]);e.payload.push({prefix:u,data:n})}for(let[r,n]of this.blockPresences)e.blockPresences.push({cid:ar.parse(r).bytes,type:n});return this.pendingBytes>0&&(e.pendingBytes=this.pendingBytes),er.encode(e)}equals(e){return!(this.full!==e.full||this.pendingBytes!==e.pendingBytes||!Mu(this.wantlist,e.wantlist)||!Mu(this.blocks,e.blocks)||!Mu(this.blockPresences,e.blockPresences))}get[Symbol.toStringTag](){let e=Array.from(this.wantlist.keys()),r=Array.from(this.blocks.keys());return`BitswapMessage <full: ${this.full}, list: ${e}, blocks: ${r}>`}};var DF={Block:er.Wantlist.WantType.Block,Have:er.Wantlist.WantType.Have};var e9=uo.WantType,t9=16*1024;function y8(t){return t[Symbol.asyncIterator]!=null}function g8(t){if(y8(t))return(async()=>{for await(let e of t);})();for(let e of t);}var xi=g8;var b8=Math.pow(2,7),w8=Math.pow(2,14),x8=Math.pow(2,21),Pp=Math.pow(2,28),Dp=Math.pow(2,35),Np=Math.pow(2,42),Lp=Math.pow(2,49),Re=128,Mt=127;function Ft(t){if(t<b8)return 1;if(t<w8)return 2;if(t<x8)return 3;if(t<Pp)return 4;if(t<Dp)return 5;if(t<Np)return 6;if(t<Lp)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function v8(t,e,r=0){switch(Ft(t)){case 8:e[r++]=t&255|Re,t/=128;case 7:e[r++]=t&255|Re,t/=128;case 6:e[r++]=t&255|Re,t/=128;case 5:e[r++]=t&255|Re,t/=128;case 4:e[r++]=t&255|Re,t>>>=7;case 3:e[r++]=t&255|Re,t>>>=7;case 2:e[r++]=t&255|Re,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function E8(t,e,r=0){switch(Ft(t)){case 8:e.set(r++,t&255|Re),t/=128;case 7:e.set(r++,t&255|Re),t/=128;case 6:e.set(r++,t&255|Re),t/=128;case 5:e.set(r++,t&255|Re),t/=128;case 4:e.set(r++,t&255|Re),t>>>=7;case 3:e.set(r++,t&255|Re),t>>>=7;case 2:e.set(r++,t&255|Re),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function A8(t,e){let r=t[e],n=0;if(n+=r&Mt,r<Re||(r=t[e+1],n+=(r&Mt)<<7,r<Re)||(r=t[e+2],n+=(r&Mt)<<14,r<Re)||(r=t[e+3],n+=(r&Mt)<<21,r<Re)||(r=t[e+4],n+=(r&Mt)*Pp,r<Re)||(r=t[e+5],n+=(r&Mt)*Dp,r<Re)||(r=t[e+6],n+=(r&Mt)*Np,r<Re)||(r=t[e+7],n+=(r&Mt)*Lp,r<Re))return n;throw new RangeError("Could not decode varint")}function S8(t,e){let r=t.get(e),n=0;if(n+=r&Mt,r<Re||(r=t.get(e+1),n+=(r&Mt)<<7,r<Re)||(r=t.get(e+2),n+=(r&Mt)<<14,r<Re)||(r=t.get(e+3),n+=(r&Mt)<<21,r<Re)||(r=t.get(e+4),n+=(r&Mt)*Pp,r<Re)||(r=t.get(e+5),n+=(r&Mt)*Dp,r<Re)||(r=t.get(e+6),n+=(r&Mt)*Np,r<Re)||(r=t.get(e+7),n+=(r&Mt)*Lp,r<Re))return n;throw new RangeError("Could not decode varint")}function tr(t,e,r=0){return e==null&&(e=Kt(Ft(t))),e instanceof Uint8Array?v8(t,e,r):E8(t,e,r)}function Ur(t,e=0){return t instanceof Uint8Array?A8(t,e):S8(t,e)}function ke(t,e){if(globalThis.Buffer!=null)return gi(globalThis.Buffer.concat(t,e));e==null&&(e=t.reduce((i,o)=>i+o.length,0));let r=Kt(e),n=0;for(let i of t)r.set(i,n),n+=i.length;return gi(r)}function ie(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}var Jw=Symbol.for("@achingbrain/uint8arraylist");function Qw(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let i=r+n.byteLength;if(e<i)return{buf:n,index:e-r};r=i}throw new RangeError("index is out of bounds")}function zu(t){return!!t?.[Jw]}var bt=class t{bufs;length;[Jw]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let r=0;for(let n of e)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(zu(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(zu(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(e){let r=Qw(this.bufs,e);return r.buf[r.index]}set(e,r){let n=Qw(this.bufs,e);n.buf[n.index]=r}write(e,r=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(r+n,e[n]);else if(zu(e))for(let n=0;n<e.length;n++)this.set(r+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,r){let{bufs:n,length:i}=this._subList(e,r);return ke(n,i)}subarray(e,r){let{bufs:n,length:i}=this._subList(e,r);return n.length===1?n[0]:ke(n,i)}sublist(e,r){let{bufs:n,length:i}=this._subList(e,r),o=new t;return o.length=i,o.bufs=[...n],o}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],i=0;for(let o=0;o<this.bufs.length;o++){let s=this.bufs[o],a=i,c=a+s.byteLength;if(i=c,e>=c)continue;let u=e>=a&&e<c,l=r>a&&r<=c;if(u&&l){if(e===a&&r===c){n.push(s);break}let f=e-a;n.push(s.subarray(f,f+(r-e)));break}if(u){if(e===0){n.push(s);continue}n.push(s.subarray(e-a));continue}if(l){if(r===c){n.push(s);break}n.push(s.subarray(0,r-a));break}n.push(s)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!zu(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let i=n.byteLength;if(i===0)throw new TypeError("search must be at least 1 byte long");let o=256,s=new Int32Array(o);for(let f=0;f<o;f++)s[f]=-1;for(let f=0;f<i;f++)s[n[f]]=f;let a=s,c=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let f=r;f<=c;f+=l){l=0;for(let d=u;d>=0;d--){let p=this.get(f+d);if(n[d]!==p){l=Math.max(1,d-a[p]);break}}if(l===0)return f}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=Kt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let i=Tn(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt16(0,r,n),this.write(i,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let i=Tn(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt32(0,r,n),this.write(i,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let i=Tn(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigInt64(0,r,n),this.write(i,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=Kt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let i=Tn(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint16(0,r,n),this.write(i,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let i=Tn(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint32(0,r,n),this.write(i,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let i=Tn(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigUint64(0,r,n),this.write(i,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let i=Tn(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat32(0,r,n),this.write(i,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let i=Tn(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat64(0,r,n),this.write(i,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!ie(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((i,o)=>i+o.byteLength,0)),n.length=r,n}};function Gu(t){return t[Symbol.asyncIterator]!=null}var Wu=t=>{let e=Ft(t),r=Kt(e);return tr(t,r),Wu.bytes=e,r};Wu.bytes=0;function vi(t,e){e=e??{};let r=e.lengthEncoder??Wu;function*n(i){let o=r(i.byteLength);o instanceof Uint8Array?yield o:yield*o,i instanceof Uint8Array?yield i:yield*i}return Gu(t)?async function*(){for await(let i of t)yield*n(i)}():function*(){for(let i of t)yield*n(i)}()}vi.single=(t,e)=>{e=e??{};let r=e.lengthEncoder??Wu;return new bt(r(t.byteLength),t)};var bs=me(fo(),1);var I8=8,R8=1024*1024*4,ho;(function(t){t[t.LENGTH=0]="LENGTH",t[t.DATA=1]="DATA"})(ho||(ho={}));var Op=t=>{let e=Ur(t);return Op.bytes=Ft(e),e};Op.bytes=0;function Yu(t,e){let r=new bt,n=ho.LENGTH,i=-1,o=e?.lengthDecoder??Op,s=e?.maxLengthLength??I8,a=e?.maxDataLength??R8;function*c(){for(;r.byteLength>0;){if(n===ho.LENGTH)try{if(i=o(r),i<0)throw(0,bs.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(i>a)throw(0,bs.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let u=o.bytes;r.consume(u),e?.onLength!=null&&e.onLength(i),n=ho.DATA}catch(u){if(u instanceof RangeError){if(r.byteLength>s)throw(0,bs.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw u}if(n===ho.DATA){if(r.byteLength<i)break;let u=r.sublist(0,i);r.consume(i),e?.onData!=null&&e.onData(u),yield u,n=ho.LENGTH}}}return Gu(t)?async function*(){for await(let u of t)r.append(u),yield*c();if(r.byteLength>0)throw(0,bs.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}():function*(){for(let u of t)r.append(u),yield*c();if(r.byteLength>0)throw(0,bs.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}Yu.fromReader=(t,e)=>{let r=1,n=async function*(){for(;;)try{let{done:o,value:s}=await t.next(r);if(o===!0)return;s!=null&&(yield s)}catch(o){if(o.code==="ERR_UNDER_READ")return{done:!0,value:null};throw o}finally{r=1}}();return Yu(n,{...e??{},onLength:o=>{r=o}})};function B8(t){return t[Symbol.asyncIterator]!=null}function T8(t,e){if(B8(t))return async function*(){for await(let a of t)yield e(a)}();let r=es(t),{value:n,done:i}=r.next();if(i===!0)return function*(){}();let o=e(n);if(typeof o.then=="function")return async function*(){yield await o;for await(let a of r)yield e(a)}();let s=e;return function*(){yield o;for(let a of r)yield s(a)}()}var ju=T8;function Ce(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Qu=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||e-1&e)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},ws=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new Qu(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let r=this.head;this.head=r.next=new Qu(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var Up=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function po(t={}){return k8(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},t)}function k8(t,e){e=e??{};let r=e.onEnd,n=new ws,i,o,s,a=Ce(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((y,g)=>{o=b=>{o=null,n.push(b);try{y(t(n))}catch(w){g(w)}return i}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Ce()})}},u=y=>o!=null?o(y):(n.push(y),i),l=y=>(n=new ws,o!=null?o({error:y}):(n.push({error:y}),i)),f=y=>{if(s)return i;if(e?.objectMode!==!0&&y?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:y})},d=y=>s?i:(s=!0,y!=null?l(y):u({done:!0})),p=()=>(n=new ws,d(),{done:!0}),h=y=>(d(y),{done:!0});if(i={[Symbol.asyncIterator](){return this},next:c,return:p,throw:h,push:f,end:d,get readableLength(){return n.size},onEmpty:async y=>{let g=y?.signal;if(g?.throwIfAborted(),n.isEmpty())return;let b,w;g!=null&&(b=new Promise((_,E)=>{w=()=>{E(new Up)},g.addEventListener("abort",w)}));try{await Promise.race([a.promise,b])}finally{w!=null&&g!=null&&g?.removeEventListener("abort",w)}}},r==null)return i;let m=i;return i={[Symbol.asyncIterator](){return this},next(){return m.next()},throw(y){return m.throw(y),r!=null&&(r(y),r=void 0),{done:!0}},return(){return m.return(),r!=null&&(r(),r=void 0),{done:!0}},push:f,end(y){return m.end(y),r!=null&&(r(y),r=void 0),i},get readableLength(){return m.readableLength},onEmpty:y=>m.onEmpty(y)},i}function C8(t){return t[Symbol.asyncIterator]!=null}function P8(...t){let e=[];for(let r of t)C8(r)||e.push(r);return e.length===t.length?function*(){for(let r of e)yield*r}():async function*(){let r=po({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(t.map(async n=>{for await(let i of n)r.push(i)})),r.end()}catch(n){r.end(n)}}),yield*r}()}var Ei=P8;function D8(t){return t[Symbol.asyncIterator]!=null}function N8(t,e){return D8(t)?async function*(){let r=0;if(!(e<1)){for await(let n of t)if(yield n,r++,r===e)return}}():function*(){let r=0;if(!(e<1)){for(let n of t)if(yield n,r++,r===e)return}}()}var uc=N8;var Ue=class extends Event{constructor(e,r){super(e),this.detail=r}};var M8=me(ax(),1);var U8=Math.pow(2,31)-1;var pk=me(el(),1);var Hp={};Y(Hp,{base10:()=>G8});var G8=fi({prefix:"9",name:"base10",alphabet:"0123456789"});var qp={};Y(qp,{base16:()=>W8,base16upper:()=>Y8});var W8=Xe({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Y8=Xe({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var $p={};Y($p,{base2:()=>j8});var j8=Xe({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var zp={};Y(zp,{base256emoji:()=>ek});var bx=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Q8=bx.reduce((t,e,r)=>(t[r]=e,t),[]),J8=bx.reduce((t,e,r)=>(t[e.codePointAt(0)]=r,t),[]);function X8(t){return t.reduce((e,r)=>(e+=Q8[r],e),"")}function Z8(t){let e=[];for(let r of t){let n=J8[r.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${r}`);e.push(n)}return new Uint8Array(e)}var ek=ts({prefix:"\u{1F680}",name:"base256emoji",encode:X8,decode:Z8});var Gp={};Y(Gp,{base36:()=>tk,base36upper:()=>rk});var tk=fi({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),rk=fi({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Wp={};Y(Wp,{base64:()=>nk,base64pad:()=>ik,base64url:()=>ok,base64urlpad:()=>sk});var nk=Xe({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ik=Xe({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ok=Xe({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),sk=Xe({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Yp={};Y(Yp,{base8:()=>ak});var ak=Xe({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var jp={};Y(jp,{identity:()=>ck});var ck=ts({prefix:"\0",name:"identity",encode:t=>Rb(t),decode:t=>Ib(t)});var a7=new TextEncoder,c7=new TextDecoder;var Qp={};Y(Qp,{identity:()=>dk});var wx=0,fk="identity",xx=Rn,hk=t=>io(wx,xx(t)),dk={code:wx,name:fk,encode:xx,digest:hk};var Jp={...jp,...$p,...Yp,...Hp,...qp,...Dd,...Gp,...Nd,...Wp,...zp},m7={...Gd,...Qp};function vx(t){return globalThis.Buffer!=null?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t}function Ex(t=0){return globalThis.Buffer?.allocUnsafe!=null?vx(globalThis.Buffer.allocUnsafe(t)):new Uint8Array(t)}function Sx(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Ax=Sx("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Xp=Sx("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=Ex(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),E7={utf8:Ax,"utf-8":Ax,hex:Jp.base16,latin1:Xp,ascii:Xp,binary:Xp,...Jp};var bk=me(el(),1);var yk=me(el(),1),gk=me(Rx(),1);var U7={enabled:!1,computeThrottleTimeout:1e3,computeThrottleMaxQueueSize:1e3,movingAverageIntervals:[60*1e3,5*60*1e3,15*60*1e3]};var tl=class{url;#e=0;#t=0;#r=0;#s=0;constructor(e){this.url=e instanceof URL?e:new URL(e)}async getRawBlock(e,r){let n=this.url;if(n.pathname=`/ipfs/${e.toString()}`,n.search="?format=raw",r?.aborted===!0)throw new Error(`Signal to fetch raw block for CID ${e} from gateway ${this.url} was aborted prior to fetch`);try{this.#e++;let i=await fetch(n.toString(),{signal:r,headers:{Accept:"application/vnd.ipld.raw"},cache:"force-cache"});if(!i.ok)throw this.#t++,new Error(`unable to fetch raw block for CID ${e} from gateway ${this.url}`);return this.#s++,new Uint8Array(await i.arrayBuffer())}catch{throw r?.aborted===!0?new Error(`fetching raw block for CID ${e} from gateway ${this.url} was aborted`):(this.#t++,new Error(`unable to fetch raw block for CID ${e}`))}}reliability(){return this.#e===0?1:this.#r>0?-1/0:this.#s/(this.#e+this.#t*3)}incrementInvalidBlocks(){this.#r++}};var rl=class{gateways;log;constructor(e,r={}){this.log=e.logger.forComponent("helia:trustless-gateway-block-broker"),this.gateways=(r.gateways??Bx).map(n=>new tl(n))}async retrieve(e,r={}){let n=this.gateways.sort((o,s)=>s.reliability()-o.reliability()),i=[];for(let o of n){this.log("getting block for %c from %s",e,o.url);try{let s=await o.getRawBlock(e,r.signal);this.log.trace("got block for %c from %s",e,o.url);try{await r.validateFn?.(s)}catch(a){throw this.log.error("failed to validate block for %c from %s",e,o.url,a),o.incrementInvalidBlocks(),new Error(`unable to validate block for CID ${e} from gateway ${o.url}`)}return s}catch(s){if(this.log.error("failed to get block for %c from %s",e,o.url,s),s instanceof Error?i.push(s):i.push(new Error(`unable to fetch raw block for CID ${e} from gateway ${o.url}`)),r.signal?.aborted===!0){this.log.trace("request aborted while fetching raw block for CID %c from gateway %s",e,o.url);break}}}throw new AggregateError(i,`unable to fetch raw block for CID ${e} from any gateway`)}};var Bx=["https://dweb.link","https://cf-ipfs.com","https://4everland.io","https://w3s.link"];function Zp(t={}){return e=>new rl(e,t)}var e0=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=r??"ABORT_ERR"}};async function nl(t,e,r,n){let i=new e0(n?.errorMessage,n?.errorCode);return r?.aborted===!0?Promise.reject(i):new Promise((o,s)=>{let a=u=>{n?.filter?.(u)!==!1&&(t.removeEventListener(e,a),r?.removeEventListener("abort",c),o(u))},c=()=>{t.removeEventListener(e,a),r?.removeEventListener("abort",c),s(i)};t.addEventListener(e,a),r?.addEventListener("abort",c)})}var il=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=r??"ABORT_ERR"}};async function vs(t,e,r){if(e==null)return t;if(e.aborted)return Promise.reject(new il(r?.errorMessage,r?.errorCode));let n,i=new il(r?.errorMessage,r?.errorCode);try{return await Promise.race([t,new Promise((o,s)=>{n=()=>{s(i)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}var ol=class{deferred;signal;where;constructor(e,r){this.signal=r,this.deferred=Ce(),this.where=e,this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(new di)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function wk(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var sl=class{id;fn;options;priority;recipients;status;timeline;controller;constructor(e,r,n=0){this.id=wk(),this.status="queued",this.fn=e,this.priority=n,this.options=r,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,xr(1/0,this.controller.signal),this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((r,n)=>r&&n.signal?.aborted===!0,!0)&&this.controller.abort(new di)}async join(e={}){let r=new ol(new Error("where").stack,e.signal);return this.recipients.push(r),e.signal?.addEventListener("abort",this.onAbort),r.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await vs(this.fn({...this.options??{},signal:this.controller.signal}),this.controller.signal);this.recipients.forEach(r=>{r.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(r=>{r.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.signal?.removeEventListener("abort",this.onAbort)})}};function xk(t,e,r){let n=0,i=t.length;for(;i>0;){let o=Math.trunc(i/2),s=n+o;r(t[s],e)<=0?(n=++s,i-=o+1):i=o}return n}var Cn=class extends oo{concurrency;queue;pending;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.pending=0,e.metricName!=null&&e.metrics?.registerMetricGroup(e.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.queue=[]}tryToStartAnother(){if(this.size===0)return queueMicrotask(()=>{this.safeDispatchEvent("empty")}),this.running===0&&queueMicrotask(()=>{this.safeDispatchEvent("idle")}),!1;if(this.pending<this.concurrency){let e;for(let r of this.queue)if(r.status==="queued"){e=r;break}return e==null?!1:(this.safeDispatchEvent("active"),this.pending++,e.run().finally(()=>{for(let r=0;r<this.queue.length;r++)if(this.queue[r]===e){this.queue.splice(r,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(e){if(this.queue[this.size-1]?.priority>=e.priority){this.queue.push(e);return}let r=xk(this.queue,e,(n,i)=>i.priority-n.priority);this.queue.splice(r,0,e)}async add(e,r){r?.signal?.throwIfAborted();let n=new sl(e,r,r?.priority),i=n.join(r).then(o=>(this.safeDispatchEvent("completed",{detail:o}),o)).catch(o=>{throw this.safeDispatchEvent("error",{detail:o}),o});return this.enqueue(n),this.safeDispatchEvent("add"),this.tryToStartAnother(),i}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new di)}),this.clear()}async onEmpty(e){this.size!==0&&await nl(this,"empty",e?.signal)}async onSizeLessThan(e,r){this.size<e||await nl(this,"next",r?.signal,{filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await nl(this,"idle",e?.signal)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(e){e?.signal?.throwIfAborted();let r=po({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),r.end(c)},i=c=>{c.detail!=null&&r.push(c.detail)},o=c=>{n(c.detail)},s=()=>{n()},a=()=>{n(new x("Queue aborted","ERR_QUEUE_ABORTED"))};this.addEventListener("completed",i),this.addEventListener("error",o),this.addEventListener("idle",s),e?.signal?.addEventListener("abort",a);try{yield*r}finally{this.removeEventListener("completed",i),this.removeEventListener("error",o),this.removeEventListener("idle",s),e?.signal?.removeEventListener("abort",a),n()}}};var vk=["string","number","bigint","symbol"],Ek=["Function","Generator","AsyncGenerator","GeneratorFunction","AsyncGeneratorFunction","AsyncFunction","Observable","Array","Buffer","Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function Tx(t){if(t===null)return"null";if(t===void 0)return"undefined";if(t===!0||t===!1)return"boolean";let e=typeof t;if(vk.includes(e))return e;if(e==="function")return"Function";if(Array.isArray(t))return"Array";if(Ak(t))return"Buffer";let r=Sk(t);return r||"Object"}function Ak(t){return t&&t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer.call(null,t)}function Sk(t){let e=Object.prototype.toString.call(t).slice(8,-1);if(Ek.includes(e))return e}var S=class{constructor(e,r,n){this.major=e,this.majorEncoded=e<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}};S.uint=new S(0,"uint",!0);S.negint=new S(1,"negint",!0);S.bytes=new S(2,"bytes",!0);S.string=new S(3,"string",!0);S.array=new S(4,"array",!1);S.map=new S(5,"map",!1);S.tag=new S(6,"tag",!1);S.float=new S(7,"float",!0);S.false=new S(7,"false",!0);S.true=new S(7,"true",!0);S.null=new S(7,"null",!0);S.undefined=new S(7,"undefined",!0);S.break=new S(7,"break",!0);var M=class{constructor(e,r,n){this.type=e,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var Es=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",_k=new TextDecoder,Ik=new TextEncoder;function al(t){return Es&&globalThis.Buffer.isBuffer(t)}function lc(t){return t instanceof Uint8Array?al(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t:Uint8Array.from(t)}var Dx=Es?(t,e,r)=>r-e>64?globalThis.Buffer.from(t.subarray(e,r)).toString("utf8"):Cx(t,e,r):(t,e,r)=>r-e>64?_k.decode(t.subarray(e,r)):Cx(t,e,r),cl=Es?t=>t.length>64?globalThis.Buffer.from(t):kx(t):t=>t.length>64?Ik.encode(t):kx(t),Zr=t=>Uint8Array.from(t),As=Es?(t,e,r)=>al(t)?new Uint8Array(t.subarray(e,r)):t.slice(e,r):(t,e,r)=>t.slice(e,r),Nx=Es?(t,e)=>(t=t.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),lc(globalThis.Buffer.concat(t,e))):(t,e)=>{let r=new Uint8Array(e),n=0;for(let i of t)n+i.length>r.length&&(i=i.subarray(0,r.length-n)),r.set(i,n),n+=i.length;return r},Lx=Es?t=>globalThis.Buffer.allocUnsafe(t):t=>new Uint8Array(t);function Ox(t,e){if(al(t)&&al(e))return t.compare(e);for(let r=0;r<t.length;r++)if(t[r]!==e[r])return t[r]<e[r]?-1:1;return 0}function kx(t){let e=[],r=0;for(let n=0;n<t.length;n++){let i=t.charCodeAt(n);i<128?e[r++]=i:i<2048?(e[r++]=i>>6|192,e[r++]=i&63|128):(i&64512)===55296&&n+1<t.length&&(t.charCodeAt(n+1)&64512)===56320?(i=65536+((i&1023)<<10)+(t.charCodeAt(++n)&1023),e[r++]=i>>18|240,e[r++]=i>>12&63|128,e[r++]=i>>6&63|128,e[r++]=i&63|128):(e[r++]=i>>12|224,e[r++]=i>>6&63|128,e[r++]=i&63|128)}return e}function Cx(t,e,r){let n=[];for(;e<r;){let i=t[e],o=null,s=i>239?4:i>223?3:i>191?2:1;if(e+s<=r){let a,c,u,l;switch(s){case 1:i<128&&(o=i);break;case 2:a=t[e+1],(a&192)===128&&(l=(i&31)<<6|a&63,l>127&&(o=l));break;case 3:a=t[e+1],c=t[e+2],(a&192)===128&&(c&192)===128&&(l=(i&15)<<12|(a&63)<<6|c&63,l>2047&&(l<55296||l>57343)&&(o=l));break;case 4:a=t[e+1],c=t[e+2],u=t[e+3],(a&192)===128&&(c&192)===128&&(u&192)===128&&(l=(i&15)<<18|(a&63)<<12|(c&63)<<6|u&63,l>65535&&l<1114112&&(o=l))}}o===null?(o=65533,s=1):o>65535&&(o-=65536,n.push(o>>>10&1023|55296),o=56320|o&1023),n.push(o),e+=s}return t0(n)}var Px=4096;function t0(t){let e=t.length;if(e<=Px)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=Px));return r}var Rk=256,fc=class{constructor(e=Rk){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let r=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let i=r.length-(this.maxCursor-this.cursor)-1;r.set(e,i)}else{if(r){let i=r.length-(this.maxCursor-this.cursor)-1;i<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,i),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(r=Lx(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r),r.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let r;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(r=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):r=As(n,0,this.cursor)}else r=Nx(this.chunks,this.cursor);return e&&this.reset(),r}};var J="CBOR decode error:",Ss="CBOR encode error:",hc=[];hc[23]=1;hc[24]=2;hc[25]=3;hc[26]=5;hc[27]=9;function Pn(t,e,r){if(t.length-e<r)throw new Error(`${J} not enough data for type`)}var wt=[24,256,65536,4294967296,BigInt("18446744073709551616")];function lr(t,e,r){Pn(t,e,1);let n=t[e];if(r.strict===!0&&n<wt[0])throw new Error(`${J} integer encoded in more bytes than necessary (strict decode)`);return n}function fr(t,e,r){Pn(t,e,2);let n=t[e]<<8|t[e+1];if(r.strict===!0&&n<wt[1])throw new Error(`${J} integer encoded in more bytes than necessary (strict decode)`);return n}function hr(t,e,r){Pn(t,e,4);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3];if(r.strict===!0&&n<wt[2])throw new Error(`${J} integer encoded in more bytes than necessary (strict decode)`);return n}function dr(t,e,r){Pn(t,e,8);let n=t[e]*16777216+(t[e+1]<<16)+(t[e+2]<<8)+t[e+3],i=t[e+4]*16777216+(t[e+5]<<16)+(t[e+6]<<8)+t[e+7],o=(BigInt(n)<<BigInt(32))+BigInt(i);if(r.strict===!0&&o<wt[3])throw new Error(`${J} integer encoded in more bytes than necessary (strict decode)`);if(o<=Number.MAX_SAFE_INTEGER)return Number(o);if(r.allowBigInt===!0)return o;throw new Error(`${J} integers outside of the safe integer range are not supported`)}function Ux(t,e,r,n){return new M(S.uint,lr(t,e+1,n),2)}function Kx(t,e,r,n){return new M(S.uint,fr(t,e+1,n),3)}function Mx(t,e,r,n){return new M(S.uint,hr(t,e+1,n),5)}function Fx(t,e,r,n){return new M(S.uint,dr(t,e+1,n),9)}function vr(t,e){return Rt(t,0,e.value)}function Rt(t,e,r){if(r<wt[0]){let n=Number(r);t.push([e|n])}else if(r<wt[1]){let n=Number(r);t.push([e|24,n])}else if(r<wt[2]){let n=Number(r);t.push([e|25,n>>>8,n&255])}else if(r<wt[3]){let n=Number(r);t.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<wt[4]){let i=[e|27,0,0,0,0,0,0,0],o=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));i[8]=o&255,o=o>>8,i[7]=o&255,o=o>>8,i[6]=o&255,o=o>>8,i[5]=o&255,i[4]=s&255,s=s>>8,i[3]=s&255,s=s>>8,i[2]=s&255,s=s>>8,i[1]=s&255,t.push(i)}else throw new Error(`${J} encountered BigInt larger than allowable range`)}}vr.encodedSize=function(e){return Rt.encodedSize(e.value)};Rt.encodedSize=function(e){return e<wt[0]?1:e<wt[1]?2:e<wt[2]?3:e<wt[3]?5:9};vr.compareTokens=function(e,r){return e.value<r.value?-1:e.value>r.value?1:0};function Vx(t,e,r,n){return new M(S.negint,-1-lr(t,e+1,n),2)}function Hx(t,e,r,n){return new M(S.negint,-1-fr(t,e+1,n),3)}function qx(t,e,r,n){return new M(S.negint,-1-hr(t,e+1,n),5)}var r0=BigInt(-1),$x=BigInt(1);function zx(t,e,r,n){let i=dr(t,e+1,n);if(typeof i!="bigint"){let o=-1-i;if(o>=Number.MIN_SAFE_INTEGER)return new M(S.negint,o,9)}if(n.allowBigInt!==!0)throw new Error(`${J} integers outside of the safe integer range are not supported`);return new M(S.negint,r0-BigInt(i),9)}function ul(t,e){let r=e.value,n=typeof r=="bigint"?r*r0-$x:r*-1-1;Rt(t,e.type.majorEncoded,n)}ul.encodedSize=function(e){let r=e.value,n=typeof r=="bigint"?r*r0-$x:r*-1-1;return n<wt[0]?1:n<wt[1]?2:n<wt[2]?3:n<wt[3]?5:9};ul.compareTokens=function(e,r){return e.value<r.value?1:e.value>r.value?-1:0};function dc(t,e,r,n){Pn(t,e,r+n);let i=As(t,e+r,e+r+n);return new M(S.bytes,i,r+n)}function Gx(t,e,r,n){return dc(t,e,1,r)}function Wx(t,e,r,n){return dc(t,e,2,lr(t,e+1,n))}function Yx(t,e,r,n){return dc(t,e,3,fr(t,e+1,n))}function jx(t,e,r,n){return dc(t,e,5,hr(t,e+1,n))}function Qx(t,e,r,n){let i=dr(t,e+1,n);if(typeof i=="bigint")throw new Error(`${J} 64-bit integer bytes lengths not supported`);return dc(t,e,9,i)}function ll(t){return t.encodedBytes===void 0&&(t.encodedBytes=t.type===S.string?cl(t.value):t.value),t.encodedBytes}function _s(t,e){let r=ll(e);Rt(t,e.type.majorEncoded,r.length),t.push(r)}_s.encodedSize=function(e){let r=ll(e);return Rt.encodedSize(r.length)+r.length};_s.compareTokens=function(e,r){return Tk(ll(e),ll(r))};function Tk(t,e){return t.length<e.length?-1:t.length>e.length?1:Ox(t,e)}function pc(t,e,r,n,i){let o=r+n;Pn(t,e,o);let s=new M(S.string,Dx(t,e+r,e+o),o);return i.retainStringBytes===!0&&(s.byteValue=As(t,e+r,e+o)),s}function Jx(t,e,r,n){return pc(t,e,1,r,n)}function Xx(t,e,r,n){return pc(t,e,2,lr(t,e+1,n),n)}function Zx(t,e,r,n){return pc(t,e,3,fr(t,e+1,n),n)}function e1(t,e,r,n){return pc(t,e,5,hr(t,e+1,n),n)}function t1(t,e,r,n){let i=dr(t,e+1,n);if(typeof i=="bigint")throw new Error(`${J} 64-bit integer string lengths not supported`);return pc(t,e,9,i,n)}var r1=_s;function Is(t,e,r,n){return new M(S.array,n,r)}function n1(t,e,r,n){return Is(t,e,1,r)}function i1(t,e,r,n){return Is(t,e,2,lr(t,e+1,n))}function o1(t,e,r,n){return Is(t,e,3,fr(t,e+1,n))}function s1(t,e,r,n){return Is(t,e,5,hr(t,e+1,n))}function a1(t,e,r,n){let i=dr(t,e+1,n);if(typeof i=="bigint")throw new Error(`${J} 64-bit integer array lengths not supported`);return Is(t,e,9,i)}function c1(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${J} indefinite length items not allowed`);return Is(t,e,1,1/0)}function fl(t,e){Rt(t,S.array.majorEncoded,e.value)}fl.compareTokens=vr.compareTokens;fl.encodedSize=function(e){return Rt.encodedSize(e.value)};function Rs(t,e,r,n){return new M(S.map,n,r)}function u1(t,e,r,n){return Rs(t,e,1,r)}function l1(t,e,r,n){return Rs(t,e,2,lr(t,e+1,n))}function f1(t,e,r,n){return Rs(t,e,3,fr(t,e+1,n))}function h1(t,e,r,n){return Rs(t,e,5,hr(t,e+1,n))}function d1(t,e,r,n){let i=dr(t,e+1,n);if(typeof i=="bigint")throw new Error(`${J} 64-bit integer map lengths not supported`);return Rs(t,e,9,i)}function p1(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${J} indefinite length items not allowed`);return Rs(t,e,1,1/0)}function hl(t,e){Rt(t,S.map.majorEncoded,e.value)}hl.compareTokens=vr.compareTokens;hl.encodedSize=function(e){return Rt.encodedSize(e.value)};function m1(t,e,r,n){return new M(S.tag,r,1)}function y1(t,e,r,n){return new M(S.tag,lr(t,e+1,n),2)}function g1(t,e,r,n){return new M(S.tag,fr(t,e+1,n),3)}function b1(t,e,r,n){return new M(S.tag,hr(t,e+1,n),5)}function w1(t,e,r,n){return new M(S.tag,dr(t,e+1,n),9)}function dl(t,e){Rt(t,S.tag.majorEncoded,e.value)}dl.compareTokens=vr.compareTokens;dl.encodedSize=function(e){return Rt.encodedSize(e.value)};var Lk=20,Ok=21,Uk=22,Kk=23;function x1(t,e,r,n){if(n.allowUndefined===!1)throw new Error(`${J} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new M(S.null,null,1):new M(S.undefined,void 0,1)}function v1(t,e,r,n){if(n.allowIndefinite===!1)throw new Error(`${J} indefinite length items not allowed`);return new M(S.break,void 0,1)}function n0(t,e,r){if(r){if(r.allowNaN===!1&&Number.isNaN(t))throw new Error(`${J} NaN values are not supported`);if(r.allowInfinity===!1&&(t===1/0||t===-1/0))throw new Error(`${J} Infinity values are not supported`)}return new M(S.float,t,e)}function E1(t,e,r,n){return n0(i0(t,e+1),3,n)}function A1(t,e,r,n){return n0(o0(t,e+1),5,n)}function S1(t,e,r,n){return n0(B1(t,e+1),9,n)}function pl(t,e,r){let n=e.value;if(n===!1)t.push([S.float.majorEncoded|Lk]);else if(n===!0)t.push([S.float.majorEncoded|Ok]);else if(n===null)t.push([S.float.majorEncoded|Uk]);else if(n===void 0)t.push([S.float.majorEncoded|Kk]);else{let i,o=!1;(!r||r.float64!==!0)&&(I1(n),i=i0(Kr,1),n===i||Number.isNaN(n)?(Kr[0]=249,t.push(Kr.slice(0,3)),o=!0):(R1(n),i=o0(Kr,1),n===i&&(Kr[0]=250,t.push(Kr.slice(0,5)),o=!0))),o||(Mk(n),i=B1(Kr,1),Kr[0]=251,t.push(Kr.slice(0,9)))}}pl.encodedSize=function(e,r){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!r||r.float64!==!0){I1(n);let i=i0(Kr,1);if(n===i||Number.isNaN(n))return 3;if(R1(n),i=o0(Kr,1),n===i)return 5}return 9};var _1=new ArrayBuffer(9),Er=new DataView(_1,1),Kr=new Uint8Array(_1,0);function I1(t){if(t===1/0)Er.setUint16(0,31744,!1);else if(t===-1/0)Er.setUint16(0,64512,!1);else if(Number.isNaN(t))Er.setUint16(0,32256,!1);else{Er.setFloat32(0,t);let e=Er.getUint32(0),r=(e&2139095040)>>23,n=e&8388607;if(r===255)Er.setUint16(0,31744,!1);else if(r===0)Er.setUint16(0,(t&2147483648)>>16|n>>13,!1);else{let i=r-127;i<-24?Er.setUint16(0,0):i<-14?Er.setUint16(0,(e&2147483648)>>16|1<<24+i,!1):Er.setUint16(0,(e&2147483648)>>16|i+15<<10|n>>13,!1)}}}function i0(t,e){if(t.length-e<2)throw new Error(`${J} not enough data for float16`);let r=(t[e]<<8)+t[e+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,i=r&1023,o;return n===0?o=i*2**-24:n!==31?o=(i+1024)*2**(n-25):o=i===0?1/0:NaN,r&32768?-o:o}function R1(t){Er.setFloat32(0,t,!1)}function o0(t,e){if(t.length-e<4)throw new Error(`${J} not enough data for float32`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,4).getFloat32(0,!1)}function Mk(t){Er.setFloat64(0,t,!1)}function B1(t,e){if(t.length-e<8)throw new Error(`${J} not enough data for float64`);let r=(t.byteOffset||0)+e;return new DataView(t.buffer,r,8).getFloat64(0,!1)}pl.compareTokens=vr.compareTokens;function Ie(t,e,r){throw new Error(`${J} encountered invalid minor (${r}) for major ${t[e]>>>5}`)}function ml(t){return()=>{throw new Error(`${J} ${t}`)}}var V=[];for(let t=0;t<=23;t++)V[t]=Ie;V[24]=Ux;V[25]=Kx;V[26]=Mx;V[27]=Fx;V[28]=Ie;V[29]=Ie;V[30]=Ie;V[31]=Ie;for(let t=32;t<=55;t++)V[t]=Ie;V[56]=Vx;V[57]=Hx;V[58]=qx;V[59]=zx;V[60]=Ie;V[61]=Ie;V[62]=Ie;V[63]=Ie;for(let t=64;t<=87;t++)V[t]=Gx;V[88]=Wx;V[89]=Yx;V[90]=jx;V[91]=Qx;V[92]=Ie;V[93]=Ie;V[94]=Ie;V[95]=ml("indefinite length bytes/strings are not supported");for(let t=96;t<=119;t++)V[t]=Jx;V[120]=Xx;V[121]=Zx;V[122]=e1;V[123]=t1;V[124]=Ie;V[125]=Ie;V[126]=Ie;V[127]=ml("indefinite length bytes/strings are not supported");for(let t=128;t<=151;t++)V[t]=n1;V[152]=i1;V[153]=o1;V[154]=s1;V[155]=a1;V[156]=Ie;V[157]=Ie;V[158]=Ie;V[159]=c1;for(let t=160;t<=183;t++)V[t]=u1;V[184]=l1;V[185]=f1;V[186]=h1;V[187]=d1;V[188]=Ie;V[189]=Ie;V[190]=Ie;V[191]=p1;for(let t=192;t<=215;t++)V[t]=m1;V[216]=y1;V[217]=g1;V[218]=b1;V[219]=w1;V[220]=Ie;V[221]=Ie;V[222]=Ie;V[223]=Ie;for(let t=224;t<=243;t++)V[t]=ml("simple values are not supported");V[244]=Ie;V[245]=Ie;V[246]=Ie;V[247]=x1;V[248]=ml("simple values are not supported");V[249]=E1;V[250]=A1;V[251]=S1;V[252]=Ie;V[253]=Ie;V[254]=Ie;V[255]=v1;var Mr=[];for(let t=0;t<24;t++)Mr[t]=new M(S.uint,t,1);for(let t=-1;t>=-24;t--)Mr[31-t]=new M(S.negint,t,1);Mr[64]=new M(S.bytes,new Uint8Array(0),1);Mr[96]=new M(S.string,"",1);Mr[128]=new M(S.array,0,1);Mr[160]=new M(S.map,0,1);Mr[244]=new M(S.false,!1,1);Mr[245]=new M(S.true,!0,1);Mr[246]=new M(S.null,null,1);function T1(t){switch(t.type){case S.false:return Zr([244]);case S.true:return Zr([245]);case S.null:return Zr([246]);case S.bytes:return t.value.length?void 0:Zr([64]);case S.string:return t.value===""?Zr([96]):void 0;case S.array:return t.value===0?Zr([128]):void 0;case S.map:return t.value===0?Zr([160]):void 0;case S.uint:return t.value<24?Zr([Number(t.value)]):void 0;case S.negint:if(t.value>=-24)return Zr([31-Number(t.value)])}}var Vk={float64:!1,mapSorter:$k,quickEncodeToken:T1};function Hk(){let t=[];return t[S.uint.major]=vr,t[S.negint.major]=ul,t[S.bytes.major]=_s,t[S.string.major]=r1,t[S.array.major]=fl,t[S.map.major]=hl,t[S.tag.major]=dl,t[S.float.major]=pl,t}var k1=Hk(),s0=new fc,gl=class t{constructor(e,r){this.obj=e,this.parent=r}includes(e){let r=this;do if(r.obj===e)return!0;while(r=r.parent);return!1}static createCheck(e,r){if(e&&e.includes(r))throw new Error(`${Ss} object contains circular references`);return new t(r,e)}},Ai={null:new M(S.null,null),undefined:new M(S.undefined,void 0),true:new M(S.true,!0),false:new M(S.false,!1),emptyArray:new M(S.array,0),emptyMap:new M(S.map,0)},Si={number(t,e,r,n){return!Number.isInteger(t)||!Number.isSafeInteger(t)?new M(S.float,t):t>=0?new M(S.uint,t):new M(S.negint,t)},bigint(t,e,r,n){return t>=BigInt(0)?new M(S.uint,t):new M(S.negint,t)},Uint8Array(t,e,r,n){return new M(S.bytes,t)},string(t,e,r,n){return new M(S.string,t)},boolean(t,e,r,n){return t?Ai.true:Ai.false},null(t,e,r,n){return Ai.null},undefined(t,e,r,n){return Ai.undefined},ArrayBuffer(t,e,r,n){return new M(S.bytes,new Uint8Array(t))},DataView(t,e,r,n){return new M(S.bytes,new Uint8Array(t.buffer,t.byteOffset,t.byteLength))},Array(t,e,r,n){if(!t.length)return r.addBreakTokens===!0?[Ai.emptyArray,new M(S.break)]:Ai.emptyArray;n=gl.createCheck(n,t);let i=[],o=0;for(let s of t)i[o++]=yl(s,r,n);return r.addBreakTokens?[new M(S.array,t.length),i,new M(S.break)]:[new M(S.array,t.length),i]},Object(t,e,r,n){let i=e!=="Object",o=i?t.keys():Object.keys(t),s=i?t.size:o.length;if(!s)return r.addBreakTokens===!0?[Ai.emptyMap,new M(S.break)]:Ai.emptyMap;n=gl.createCheck(n,t);let a=[],c=0;for(let u of o)a[c++]=[yl(u,r,n),yl(i?t.get(u):t[u],r,n)];return qk(a,r),r.addBreakTokens?[new M(S.map,s),a,new M(S.break)]:[new M(S.map,s),a]}};Si.Map=Si.Object;Si.Buffer=Si.Uint8Array;for(let t of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Si[`${t}Array`]=Si.DataView;function yl(t,e={},r){let n=Tx(t),i=e&&e.typeEncoders&&e.typeEncoders[n]||Si[n];if(typeof i=="function"){let s=i(t,n,e,r);if(s!=null)return s}let o=Si[n];if(!o)throw new Error(`${Ss} unsupported type: ${n}`);return o(t,n,e,r)}function qk(t,e){e.mapSorter&&t.sort(e.mapSorter)}function $k(t,e){let r=Array.isArray(t[0])?t[0][0]:t[0],n=Array.isArray(e[0])?e[0][0]:e[0];if(r.type!==n.type)return r.type.compare(n.type);let i=r.type.major,o=k1[i].compareTokens(r,n);return o===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),o}function C1(t,e,r,n){if(Array.isArray(e))for(let i of e)C1(t,i,r,n);else r[e.type.major](t,e,n)}function P1(t,e,r){let n=yl(t,r);if(!Array.isArray(n)&&r.quickEncodeToken){let i=r.quickEncodeToken(n);if(i)return i;let o=e[n.type.major];if(o.encodedSize){let s=o.encodedSize(n,r),a=new fc(s);if(o(a,n,r),a.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return lc(a.chunks[0])}}return s0.reset(),C1(s0,n,e,r),s0.toBytes(!0)}function Bs(t,e){return e=Object.assign({},Vk,e),P1(t,k1,e)}var zk={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},a0=class{constructor(e,r={}){this._pos=0,this.data=e,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],r=Mr[e];if(r===void 0){let n=V[e];if(!n)throw new Error(`${J} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let i=e&31;r=n(this.data,this._pos,i,this.options)}return this._pos+=r.encodedLength,r}},mc=Symbol.for("DONE"),bl=Symbol.for("BREAK");function Gk(t,e,r){let n=[];for(let i=0;i<t.value;i++){let o=yc(e,r);if(o===bl){if(t.value===1/0)break;throw new Error(`${J} got unexpected break to lengthed array`)}if(o===mc)throw new Error(`${J} found array but not enough entries (got ${i}, expected ${t.value})`);n[i]=o}return n}function Wk(t,e,r){let n=r.useMaps===!0,i=n?void 0:{},o=n?new Map:void 0;for(let s=0;s<t.value;s++){let a=yc(e,r);if(a===bl){if(t.value===1/0)break;throw new Error(`${J} got unexpected break to lengthed map`)}if(a===mc)throw new Error(`${J} found map but not enough entries (got ${s} [no key], expected ${t.value})`);if(n!==!0&&typeof a!="string")throw new Error(`${J} non-string keys not supported (got ${typeof a})`);if(r.rejectDuplicateMapKeys===!0&&(n&&o.has(a)||!n&&a in i))throw new Error(`${J} found repeat map key "${a}"`);let c=yc(e,r);if(c===mc)throw new Error(`${J} found map but not enough entries (got ${s} [no value], expected ${t.value})`);n?o.set(a,c):i[a]=c}return n?o:i}function yc(t,e){if(t.done())return mc;let r=t.next();if(r.type===S.break)return bl;if(r.type.terminal)return r.value;if(r.type===S.array)return Gk(r,t,e);if(r.type===S.map)return Wk(r,t,e);if(r.type===S.tag){if(e.tags&&typeof e.tags[r.value]=="function"){let n=yc(t,e);return e.tags[r.value](n)}throw new Error(`${J} tag not supported (${r.value})`)}throw new Error("unsupported")}function c0(t,e){if(!(t instanceof Uint8Array))throw new Error(`${J} data to decode must be a Uint8Array`);e=Object.assign({},zk,e);let r=e.tokenizer||new a0(t,e),n=yc(r,e);if(n===mc)throw new Error(`${J} did not find any content to decode`);if(n===bl)throw new Error(`${J} got unexpected break`);return[n,t.subarray(r.pos())]}function Ar(t,e){let[r,n]=c0(t,e);if(n.length>0)throw new Error(`${J} too many terminals, data makes no sense`);return r}function z(t,e="utf8"){let r=qu[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(t.buffer,t.byteOffset,t.byteLength).toString("utf8"):r.encoder.encode(t).substring(1)}var Dn="/",D1=new TextEncoder().encode(Dn),xl=D1[0],pt=class t{_buf;constructor(e,r){if(typeof e=="string")this._buf=U(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(r==null&&(r=!0),r&&this.clean(),this._buf.byteLength===0||this._buf[0]!==xl)throw new Error("Invalid key")}toString(e="utf8"){return z(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new t(e.join(Dn))}static random(){return new t(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new t(e):typeof e.uint8Array=="function"?new t(e.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=D1),this._buf[0]!==xl){let e=new Uint8Array(this._buf.byteLength+1);e.fill(xl,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===xl;)this._buf=this._buf.subarray(0,-1)}less(e){let r=this.list(),n=e.list();for(let i=0;i<r.length;i++){if(n.length<i+1)return!1;let o=r[i],s=n[i];if(o<s)return!0;if(o>s)return!1}return r.length<n.length}reverse(){return t.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(Dn).slice(1)}type(){return Yk(this.baseNamespace())}name(){return jk(this.baseNamespace())}instance(e){return new t(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(Dn)||(e+=Dn),e+=this.type(),new t(e)}parent(){let e=this.list();return e.length===1?new t(Dn):new t(e.slice(0,-1).join(Dn))}child(e){return this.toString()===Dn?e:e.toString()===Dn?this:new t(this.toString()+e.toString(),!1)}isAncestorOf(e){return e.toString()===this.toString()?!1:e.toString().startsWith(this.toString())}isDecendantOf(e){return e.toString()===this.toString()?!1:this.toString().startsWith(e.toString())}isTopLevel(){return this.list().length===1}concat(...e){return t.withNamespaces([...this.namespaces(),...Qk(e.map(r=>r.namespaces()))])}};function Yk(t){let e=t.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function jk(t){let e=t.split(":");return e[e.length-1]}function Qk(t){return[].concat(...t)}var Jk=42;function Xk(t){if(t[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return Fe.decode(t.subarray(1))}var Zk={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};Zk.tags[Jk]=Xk;var N1=113;var L1=class extends Array{constructor(){super(),this.inRecursive=[]}prefix(e){let r=this.inRecursive[this.inRecursive.length-1];r&&(r.type===S.array&&(r.elements++,r.elements!==1&&e.push([44])),r.type===S.map&&(r.elements++,r.elements!==1&&(r.elements%2===1?e.push([44]):e.push([58]))))}[S.uint.major](e,r){this.prefix(e);let n=String(r.value),i=[];for(let o=0;o<n.length;o++)i[o]=n.charCodeAt(o);e.push(i)}[S.negint.major](e,r){this[S.uint.major](e,r)}[S.bytes.major](e,r){throw new Error(`${Ss} unsupported type: Uint8Array`)}[S.string.major](e,r){this.prefix(e);let n=cl(JSON.stringify(r.value));e.push(n.length>32?lc(n):n)}[S.array.major](e,r){this.prefix(e),this.inRecursive.push({type:S.array,elements:0}),e.push([91])}[S.map.major](e,r){this.prefix(e),this.inRecursive.push({type:S.map,elements:0}),e.push([123])}[S.tag.major](e,r){}[S.float.major](e,r){if(r.type.name==="break"){let s=this.inRecursive.pop();if(s){if(s.type===S.array)e.push([93]);else if(s.type===S.map)e.push([125]);else throw new Error("Unexpected recursive type; this should not happen!");return}throw new Error("Unexpected break; this should not happen!")}if(r.value===void 0)throw new Error(`${Ss} unsupported type: undefined`);if(this.prefix(e),r.type.name==="true"){e.push([116,114,117,101]);return}else if(r.type.name==="false"){e.push([102,97,108,115,101]);return}else if(r.type.name==="null"){e.push([110,117,108,108]);return}let n=String(r.value),i=[],o=!1;for(let s=0;s<n.length;s++)i[s]=n.charCodeAt(s),!o&&(i[s]===46||i[s]===101||i[s]===69)&&(o=!0);o||(i.push(46),i.push(48)),e.push(i)}};var yo=class{constructor(e,r={}){this._pos=0,this.data=e,this.options=r,this.modeStack=["value"],this.lastToken=""}pos(){return this._pos}done(){return this._pos>=this.data.length}ch(){return this.data[this._pos]}currentMode(){return this.modeStack[this.modeStack.length-1]}skipWhitespace(){let e=this.ch();for(;e===32||e===9||e===13||e===10;)e=this.data[++this._pos]}expect(e){if(this.data.length-this._pos<e.length)throw new Error(`${J} unexpected end of input at position ${this._pos}`);for(let r=0;r<e.length;r++)if(this.data[this._pos++]!==e[r])throw new Error(`${J} unexpected token at position ${this._pos}, expected to find '${String.fromCharCode(...e)}'`)}parseNumber(){let e=this._pos,r=!1,n=!1,i=a=>{for(;!this.done();){let c=this.ch();if(a.includes(c))this._pos++;else break}};if(this.ch()===45&&(r=!0,this._pos++),this.ch()===48)if(this._pos++,this.ch()===46)this._pos++,n=!0;else return new M(S.uint,0,this._pos-e);if(i([48,49,50,51,52,53,54,55,56,57]),r&&this._pos===e+1)throw new Error(`${J} unexpected token at position ${this._pos}`);if(!this.done()&&this.ch()===46){if(n)throw new Error(`${J} unexpected token at position ${this._pos}`);n=!0,this._pos++,i([48,49,50,51,52,53,54,55,56,57])}!this.done()&&(this.ch()===101||this.ch()===69)&&(n=!0,this._pos++,!this.done()&&(this.ch()===43||this.ch()===45)&&this._pos++,i([48,49,50,51,52,53,54,55,56,57]));let o=String.fromCharCode.apply(null,this.data.subarray(e,this._pos)),s=parseFloat(o);return n?new M(S.float,s,this._pos-e):this.options.allowBigInt!==!0||Number.isSafeInteger(s)?new M(s>=0?S.uint:S.negint,s,this._pos-e):new M(s>=0?S.uint:S.negint,BigInt(o),this._pos-e)}parseString(){if(this.ch()!==34)throw new Error(`${J} unexpected character at position ${this._pos}; this shouldn't happen`);this._pos++;for(let o=this._pos,s=0;o<this.data.length&&s<65536;o++,s++){let a=this.data[o];if(a===92||a<32||a>=128)break;if(a===34){let c=String.fromCharCode.apply(null,this.data.subarray(this._pos,o));return this._pos=o+1,new M(S.string,c,s)}}let e=this._pos,r=[],n=()=>{if(this._pos+4>=this.data.length)throw new Error(`${J} unexpected end of unicode escape sequence at position ${this._pos}`);let o=0;for(let s=0;s<4;s++){let a=this.ch();if(a>=48&&a<=57)a-=48;else if(a>=97&&a<=102)a=a-97+10;else if(a>=65&&a<=70)a=a-65+10;else throw new Error(`${J} unexpected unicode escape character at position ${this._pos}`);o=o*16+a,this._pos++}return o},i=()=>{let o=this.ch(),s=null,a=o>239?4:o>223?3:o>191?2:1;if(this._pos+a>this.data.length)throw new Error(`${J} unexpected unicode sequence at position ${this._pos}`);let c,u,l,f;switch(a){case 1:o<128&&(s=o);break;case 2:c=this.data[this._pos+1],(c&192)===128&&(f=(o&31)<<6|c&63,f>127&&(s=f));break;case 3:c=this.data[this._pos+1],u=this.data[this._pos+2],(c&192)===128&&(u&192)===128&&(f=(o&15)<<12|(c&63)<<6|u&63,f>2047&&(f<55296||f>57343)&&(s=f));break;case 4:c=this.data[this._pos+1],u=this.data[this._pos+2],l=this.data[this._pos+3],(c&192)===128&&(u&192)===128&&(l&192)===128&&(f=(o&15)<<18|(c&63)<<12|(u&63)<<6|l&63,f>65535&&f<1114112&&(s=f))}s===null?(s=65533,a=1):s>65535&&(s-=65536,r.push(s>>>10&1023|55296),s=56320|s&1023),r.push(s),this._pos+=a};for(;!this.done();){let o=this.ch(),s;switch(o){case 92:if(this._pos++,this.done())throw new Error(`${J} unexpected string termination at position ${this._pos}`);switch(s=this.ch(),this._pos++,s){case 34:case 39:case 92:case 47:r.push(s);break;case 98:r.push(8);break;case 116:r.push(9);break;case 110:r.push(10);break;case 102:r.push(12);break;case 114:r.push(13);break;case 117:r.push(n());break;default:throw new Error(`${J} unexpected string escape character at position ${this._pos}`)}break;case 34:return this._pos++,new M(S.string,t0(r),this._pos-e);default:if(o<32)throw new Error(`${J} invalid control character at position ${this._pos}`);o<128?(r.push(o),this._pos++):i()}}throw new Error(`${J} unexpected end of string at position ${this._pos}`)}parseValue(){switch(this.ch()){case 123:return this.modeStack.push("obj-start"),this._pos++,new M(S.map,1/0,1);case 91:return this.modeStack.push("array-start"),this._pos++,new M(S.array,1/0,1);case 34:return this.parseString();case 110:return this.expect([110,117,108,108]),new M(S.null,null,4);case 102:return this.expect([102,97,108,115,101]),new M(S.false,!1,5);case 116:return this.expect([116,114,117,101]),new M(S.true,!0,4);case 45:case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return this.parseNumber();default:throw new Error(`${J} unexpected character at position ${this._pos}`)}}next(){switch(this.skipWhitespace(),this.currentMode()){case"value":return this.modeStack.pop(),this.parseValue();case"array-value":{if(this.modeStack.pop(),this.ch()===93)return this._pos++,this.skipWhitespace(),new M(S.break,void 0,1);if(this.ch()!==44)throw new Error(`${J} unexpected character at position ${this._pos}, was expecting array delimiter but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue()}case"array-start":return this.modeStack.pop(),this.ch()===93?(this._pos++,this.skipWhitespace(),new M(S.break,void 0,1)):(this.modeStack.push("array-value"),this.skipWhitespace(),this.parseValue());case"obj-key":if(this.ch()===125)return this.modeStack.pop(),this._pos++,this.skipWhitespace(),new M(S.break,void 0,1);if(this.ch()!==44)throw new Error(`${J} unexpected character at position ${this._pos}, was expecting object delimiter but found '${String.fromCharCode(this.ch())}'`);this._pos++,this.skipWhitespace();case"obj-start":{if(this.modeStack.pop(),this.ch()===125)return this._pos++,this.skipWhitespace(),new M(S.break,void 0,1);let e=this.parseString();if(this.skipWhitespace(),this.ch()!==58)throw new Error(`${J} unexpected character at position ${this._pos}, was expecting key/value delimiter ':' but found '${String.fromCharCode(this.ch())}'`);return this._pos++,this.modeStack.push("obj-value"),e}case"obj-value":return this.modeStack.pop(),this.modeStack.push("obj-key"),this.skipWhitespace(),this.parseValue();default:throw new Error(`${J} unexpected parse state at position ${this._pos}; this shouldn't happen`)}}};function vl(t,e){return e=Object.assign({tokenizer:new yo(t,e)},e),Ar(t,e)}var rC={allowIndefinite:!1,allowUndefined:!1,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};rC.tags[42]=Fe.parse;var U1=297;var dq=new TextDecoder;var pq=new TextEncoder;var iC=new TextDecoder;function u0(t,e){let r=0;for(let n=0;;n+=7){if(n>=64)throw new Error("protobuf: varint overflow");if(e>=t.length)throw new Error("protobuf: unexpected end of data");let i=t[e++];if(r+=n<28?(i&127)<<n:(i&127)*2**n,i<128)break}return[r,e]}function El(t,e){let r;[r,e]=u0(t,e);let n=e+r;if(r<0||n<0)throw new Error("protobuf: invalid length");if(n>t.length)throw new Error("protobuf: unexpected end of data");return[t.subarray(e,n),n]}function K1(t,e){let r;return[r,e]=u0(t,e),[r&7,r>>3,e]}function oC(t){let e={},r=t.length,n=0;for(;n<r;){let i,o;if([i,o,n]=K1(t,n),o===1){if(e.Hash)throw new Error("protobuf: (PBLink) duplicate Hash section");if(i!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Hash`);if(e.Name!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Name before Hash");if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Hash");[e.Hash,n]=El(t,n)}else if(o===2){if(e.Name!==void 0)throw new Error("protobuf: (PBLink) duplicate Name section");if(i!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Name`);if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Name");let s;[s,n]=El(t,n),e.Name=iC.decode(s)}else if(o===3){if(e.Tsize!==void 0)throw new Error("protobuf: (PBLink) duplicate Tsize section");if(i!==0)throw new Error(`protobuf: (PBLink) wrong wireType (${i}) for Tsize`);[e.Tsize,n]=u0(t,n)}else throw new Error(`protobuf: (PBLink) invalid fieldNumber, expected 1, 2 or 3, got ${o}`)}if(n>r)throw new Error("protobuf: (PBLink) unexpected end of data");return e}function M1(t){let e=t.length,r=0,n,i=!1,o;for(;r<e;){let a,c;if([a,c,r]=K1(t,r),a!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${a}`);if(c===1){if(o)throw new Error("protobuf: (PBNode) duplicate Data section");[o,r]=El(t,r),n&&(i=!0)}else if(c===2){if(i)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let u;[u,r]=El(t,r),n.push(oC(u))}else throw new Error(`protobuf: (PBNode) invalid fieldNumber, expected 1 or 2, got ${c}`)}if(r>e)throw new Error("protobuf: (PBNode) unexpected end of data");let s={};return o&&(s.Data=o),s.Links=n||[],s}var yq=new TextEncoder,gq=2**32,bq=2**31;var vq=new TextEncoder;var F1=112;function V1(t){let e=M1(t),r={};return e.Data&&(r.Data=e.Data),e.Links&&(r.Links=e.Links.map(n=>{let i={};try{i.Hash=Fe.decode(n.Hash)}catch{}if(!i.Hash)throw new Error("Invalid Hash field found in link, expected CID");return n.Name!==void 0&&(i.Name=n.Name),n.Tsize!==void 0&&(i.Tsize=n.Tsize),i})),r}var f0={codec:F1,*walk(t){yield*V1(t).Links.map(r=>r.Hash)}},h0={codec:Vu,*walk(){}},H1=42,d0={codec:N1,*walk(t){let e=[],r=[];r[H1]=n=>{if(n[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");let i=Fe.decode(n.subarray(1));return e.push(i),i},Ar(t,{tags:r}),yield*e}},l0=class extends yo{tokenBuffer;constructor(e,r){super(e,r),this.tokenBuffer=[]}done(){return this.tokenBuffer.length===0&&super.done()}_next(){return this.tokenBuffer.length>0?this.tokenBuffer.pop():super.next()}next(){let e=this._next();if(e.type===S.map){let r=this._next();if(r.type===S.string&&r.value==="/"){let n=this._next();if(n.type===S.string){if(this._next().type!==S.break)throw new Error("Invalid encoded CID form");return this.tokenBuffer.push(n),new M(S.tag,42,0)}if(n.type===S.map){let i=this._next();if(i.type===S.string&&i.value==="bytes"){let o=this._next();if(o.type===S.string){for(let a=0;a<2;a++)if(this._next().type!==S.break)throw new Error("Invalid encoded Bytes form");let s=$t.decode(`m${o.value}`);return new M(S.bytes,s,o.value.length)}this.tokenBuffer.push(o)}this.tokenBuffer.push(i)}this.tokenBuffer.push(n)}this.tokenBuffer.push(r)}return e}},p0={codec:U1,*walk(t){let e=[],r=[];r[H1]=n=>{let i=Fe.parse(n);return e.push(i),i},vl(t,{tags:r,tokenizer:new l0(t,{tags:r,allowIndefinite:!0,allowUndefined:!0,allowNaN:!0,allowInfinity:!0,allowBigInt:!0,strict:!1,rejectDuplicateMapKeys:!1})}),yield*e}},q1={codec:Dw,*walk(){}};function $1(t=[]){return[f0,h0,d0,p0,...t]}var aC=[h0,f0,d0,p0,q1],Y1="/pin/",z1="/pinned-block/",m0=tc,G1=1;function W1(t){return t.version===0&&(t=t.toV1()),new pt(`${Y1}${t.toString(m0)}`)}var Al=class{datastore;blockstore;dagWalkers;constructor(e,r,n){this.datastore=e,this.blockstore=r,this.dagWalkers={},[...aC,...n].forEach(i=>{this.dagWalkers[i.codec]=i})}async*add(e,r={}){let n=W1(e);if(await this.datastore.has(n))throw new Error("Already pinned");let i=Math.round(r.depth??1/0);if(i<0)throw new Error("Depth must be greater than or equal to 0");let o=new Cn({concurrency:G1});for await(let a of this.#e(e,o,{...r,depth:i}))await this.#t(a,c=>c.pinnedBy.find(u=>ie(u,e.bytes))!=null?!1:(c.pinCount++,c.pinnedBy.push(e.bytes),!0),r),yield a;let s={depth:i,metadata:r.metadata??{}};await this.datastore.put(n,Bs(s),r)}async*#e(e,r,n){if(n.depth===-1)return;let i=this.dagWalkers[e.code];if(i==null)throw new Error(`No dag walker found for cid codec ${e.code}`);let o=await this.blockstore.get(e,n);yield e;for await(let s of i.walk(o))yield*await r.add(async()=>this.#e(s,r,{...n,depth:n.depth-1}))}async#t(e,r,n){let i=new pt(`${z1}${m0.encode(e.multihash.bytes)}`),o={pinCount:0,pinnedBy:[]};try{o=Ar(await this.datastore.get(i,n))}catch(a){if(a.code!=="ERR_NOT_FOUND")throw a}if(r(o)){if(o.pinCount===0&&await this.datastore.has(i)){await this.datastore.delete(i);return}await this.datastore.put(i,Bs(o),n),n.onProgress?.(new Ue("helia:pin:add",e))}}async*rm(e,r={}){let n=W1(e),i=await this.datastore.get(n,r),o=Ar(i);await this.datastore.delete(n,r);let s=new Cn({concurrency:G1});for await(let a of this.#e(e,s,{...r,depth:o.depth}))await this.#t(a,c=>(c.pinCount--,c.pinnedBy=c.pinnedBy.filter(u=>ie(u,e.bytes)),!0),{...r,depth:o.depth}),yield a}async*ls(e={}){for await(let{key:r,value:n}of this.datastore.query({prefix:Y1+(e.cid!=null?`${e.cid.toString(tc)}`:"")},e)){let i=Fe.parse(r.toString().substring(5),tc),o=Ar(n);yield{cid:i,...o}}}async isPinned(e,r={}){let n=new pt(`${z1}${m0.encode(e.multihash.bytes)}`);return this.datastore.has(n,r)}};var bc=me(Q1(),1);var wc=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},g0=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},J1=t=>globalThis.DOMException===void 0?new g0(t):new DOMException(t),X1=t=>{let e=t.reason===void 0?J1("This operation was aborted."):t.reason;return e instanceof Error?e:J1(e)};function xc(t,e){let{milliseconds:r,fallback:n,message:i,customTimers:o={setTimeout,clearTimeout}}=e,s,c=new Promise((u,l)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(e.signal){let{signal:d}=e;d.aborted&&l(X1(d)),d.addEventListener("abort",()=>{l(X1(d))})}if(r===Number.POSITIVE_INFINITY){t.then(u,l);return}let f=new wc;s=o.setTimeout.call(void 0,()=>{if(n){try{u(n())}catch(d){l(d)}return}typeof t.cancel=="function"&&t.cancel(),i===!1?u():i instanceof Error?l(i):(f.message=i??`Promise timed out after ${r} milliseconds`,l(f))},r),(async()=>{try{u(await t)}catch(d){l(d)}})()}).finally(()=>{c.clear()});return c.clear=()=>{o.clearTimeout.call(void 0,s),s=void 0},c}function b0(t,e,r){let n=0,i=t.length;for(;i>0;){let o=Math.trunc(i/2),s=n+o;r(t[s],e)<=0?(n=++s,i-=o+1):i=o}return n}var vc=class{#e=[];enqueue(e,r){r={priority:0,...r};let n={priority:r.priority,run:e};if(this.size&&this.#e[this.size-1].priority>=r.priority){this.#e.push(n);return}let i=b0(this.#e,n,(o,s)=>s.priority-o.priority);this.#e.splice(i,0,n)}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(r=>r.priority===e.priority).map(r=>r.run)}get size(){return this.#e.length}};var Ts=class extends bc.default{#e;#t;#r=0;#s;#c;#p=0;#i;#u;#n;#m;#o=0;#l;#a;#y;timeout;constructor(e){if(super(),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:vc,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??""}\` (${typeof e.interval})`);this.#e=e.carryoverConcurrencyCount,this.#t=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#s=e.intervalCap,this.#c=e.interval,this.#n=new e.queueClass,this.#m=e.queueClass,this.concurrency=e.concurrency,this.timeout=e.timeout,this.#y=e.throwOnTimeout===!0,this.#a=e.autoStart===!1}get#w(){return this.#t||this.#r<this.#s}get#x(){return this.#o<this.#l}#v(){this.#o--,this.#f(),this.emit("next")}#E(){this.#b(),this.#g(),this.#u=void 0}get#A(){let e=Date.now();if(this.#i===void 0){let r=this.#p-e;if(r<0)this.#r=this.#e?this.#o:0;else return this.#u===void 0&&(this.#u=setTimeout(()=>{this.#E()},r)),!0}return!1}#f(){if(this.#n.size===0)return this.#i&&clearInterval(this.#i),this.#i=void 0,this.emit("empty"),this.#o===0&&this.emit("idle"),!1;if(!this.#a){let e=!this.#A;if(this.#w&&this.#x){let r=this.#n.dequeue();return r?(this.emit("active"),r(),e&&this.#g(),!0):!1}}return!1}#g(){this.#t||this.#i!==void 0||(this.#i=setInterval(()=>{this.#b()},this.#c),this.#p=Date.now()+this.#c)}#b(){this.#r===0&&this.#o===0&&this.#i&&(clearInterval(this.#i),this.#i=void 0),this.#r=this.#e?this.#o:0,this.#h()}#h(){for(;this.#f(););}get concurrency(){return this.#l}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#l=e,this.#h()}async#S(e){return new Promise((r,n)=>{e.addEventListener("abort",()=>{n(e.reason)},{once:!0})})}async add(e,r={}){return r={timeout:this.timeout,throwOnTimeout:this.#y,...r},new Promise((n,i)=>{this.#n.enqueue(async()=>{this.#o++,this.#r++;try{r.signal?.throwIfAborted();let o=e({signal:r.signal});r.timeout&&(o=xc(Promise.resolve(o),{milliseconds:r.timeout})),r.signal&&(o=Promise.race([o,this.#S(r.signal)]));let s=await o;n(s),this.emit("completed",s)}catch(o){if(o instanceof wc&&!r.throwOnTimeout){n();return}i(o),this.emit("error",o)}finally{this.#v()}},r),this.emit("add"),this.#f()})}async addAll(e,r){return Promise.all(e.map(async n=>this.add(n,r)))}start(){return this.#a?(this.#a=!1,this.#h(),this):this}pause(){this.#a=!0}clear(){this.#n=new this.#m}async onEmpty(){this.#n.size!==0&&await this.#d("empty")}async onSizeLessThan(e){this.#n.size<e||await this.#d("next",()=>this.#n.size<e)}async onIdle(){this.#o===0&&this.#n.size===0||await this.#d("idle")}async#d(e,r){return new Promise(n=>{let i=()=>{r&&!r()||(this.off(e,i),n())};this.on(e,i)})}get size(){return this.#n.size}sizeBy(e){return this.#n.filter(e).length}get pending(){return this.#o}get isPaused(){return this.#a}};var _i={},ks=t=>{t.addEventListener("message",e=>{ks.dispatchEvent("message",t,e)}),t.port!=null&&t.port.addEventListener("message",e=>{ks.dispatchEvent("message",t,e)})};ks.addEventListener=(t,e)=>{_i[t]==null&&(_i[t]=[]),_i[t].push(e)};ks.removeEventListener=(t,e)=>{_i[t]!=null&&(_i[t]=_i[t].filter(r=>r===e))};ks.dispatchEvent=function(t,e,r){_i[t]!=null&&_i[t].forEach(n=>n(e,r))};var w0=ks;var x0="lock:worker:request-read",v0="lock:worker:release-read",E0="lock:master:grant-read",A0="lock:worker:request-write",S0="lock:worker:release-write",_0="lock:master:grant-write";var Z1=(t=21)=>Math.random().toString().substring(2);var ev=(t,e,r,n,i)=>(o,s)=>{if(s.data.type!==r)return;let a={type:s.data.type,name:s.data.name,identifier:s.data.identifier};t.dispatchEvent(new MessageEvent(e,{data:{name:a.name,handler:async()=>{o.postMessage({type:i,name:a.name,identifier:a.identifier}),await new Promise(c=>{let u=l=>{if(l==null||l.data==null)return;let f={type:l.data.type,name:l.data.name,identifier:l.data.identifier};f.type===n&&f.identifier===a.identifier&&(o.removeEventListener("message",u),c())};o.addEventListener("message",u)})}}}))},tv=(t,e,r,n)=>async()=>{let i=Z1();return globalThis.postMessage({type:e,identifier:i,name:t}),new Promise(o=>{let s=a=>{if(a==null||a.data==null)return;let c={type:a.data.type,identifier:a.data.identifier};c.type===r&&c.identifier===i&&(globalThis.removeEventListener("message",s),o(()=>{globalThis.postMessage({type:n,identifier:i,name:t})}))};globalThis.addEventListener("message",s)})},lC={singleProcess:!1},rv=t=>{if(t=Object.assign({},lC,t),!!globalThis.document||t.singleProcess){let r=new EventTarget;return w0.addEventListener("message",ev(r,"requestReadLock",x0,v0,E0)),w0.addEventListener("message",ev(r,"requestWriteLock",A0,S0,_0)),r}return{isWorker:!0,readLock:r=>tv(r,x0,E0,v0),writeLock:r=>tv(r,A0,_0,S0)}};var go={},Ii;async function I0(t,e){let r,n=new Promise(i=>{r=i});return t.add(async()=>xc((async()=>{await new Promise(i=>{r(()=>{i()})})})(),{milliseconds:e.timeout})),n}var fC=(t,e)=>{if(Ii.isWorker===!0)return{readLock:Ii.readLock(t,e),writeLock:Ii.writeLock(t,e)};let r=new Ts({concurrency:1}),n;return{async readLock(){if(n!=null)return I0(n,e);n=new Ts({concurrency:e.concurrency,autoStart:!1});let i=n,o=I0(n,e);return r.add(async()=>{i.start(),await i.onIdle().then(()=>{n===i&&(n=null)})}),o},async writeLock(){return n=null,I0(r,e)}}},hC={name:"lock",concurrency:1/0,timeout:846e5,singleProcess:!1};function Ec(t){let e=Object.assign({},hC,t);return Ii==null&&(Ii=rv(e),Ii.isWorker!==!0&&(Ii.addEventListener("requestReadLock",r=>{go[r.data.name]!=null&&go[r.data.name].readLock().then(async n=>r.data.handler().finally(()=>{n()}))}),Ii.addEventListener("requestWriteLock",async r=>{go[r.data.name]!=null&&go[r.data.name].writeLock().then(async n=>r.data.handler().finally(()=>{n()}))}))),go[e.name]==null&&(go[e.name]=fC(e.name,e)),go[e.name]}var _l=class{lock;child;pins;started;constructor(e,r,n={}){this.child=e,this.pins=r,this.lock=Ec({singleProcess:n.holdGcLock}),this.started=!1}isStarted(){return this.started}async start(){await as(this.child),this.started=!0}async stop(){await cs(this.child),this.started=!1}unwrap(){return this.child}async put(e,r,n={}){let i=await this.lock.readLock();try{return await this.child.put(e,r,n)}finally{i()}}async*putMany(e,r={}){let n=await this.lock.readLock();try{yield*this.child.putMany(e,r)}finally{n()}}async get(e,r={}){let n=await this.lock.readLock();try{return await this.child.get(e,r)}finally{n()}}async*getMany(e,r={}){let n=await this.lock.readLock();try{yield*this.child.getMany(e,r)}finally{n()}}async delete(e,r={}){let n=await this.lock.writeLock();try{if(await this.pins.isPinned(e))throw new Error("CID was pinned");await this.child.delete(e,r)}finally{n()}}async*deleteMany(e,r={}){let n=await this.lock.writeLock();try{let i=this;yield*this.child.deleteMany(async function*(){for await(let o of e){if(await i.pins.isPinned(o))throw new Error("CID was pinned");yield o}}(),r)}finally{n()}}async has(e,r={}){let n=await this.lock.readLock();try{return await this.child.has(e,r)}finally{n()}}async*getAll(e={}){let r=await this.lock.readLock();try{yield*this.child.getAll(e)}finally{r()}}};var R0=new pt("/version"),nv=1;async function iv(t){if(!await t.has(R0)){await t.put(R0,U(`${nv}`));return}let e=await t.get(R0),r=z(e);if(parseInt(r,10)!==nv)throw new Error("Unknown datastore version, a datastore migration may be required")}function ov(t=[]){return[ae,Ep,Xt,...t]}function dC(t){return t[Symbol.asyncIterator]!=null}function pC(t,e){if(dC(t))return async function*(){for await(let a of t)await e(a)&&(yield a)}();let r=es(t),{value:n,done:i}=r.next();if(i===!0)return function*(){}();let o=e(n);if(typeof o.then=="function")return async function*(){await o&&(yield n);for await(let a of r)await e(a)&&(yield a)}();let s=e;return function*(){o===!0&&(yield n);for(let a of r)s(a)&&(yield a)}()}var Fr=pC;function mC(t){return typeof t.retrieve=="function"}function yC(t){return typeof t.announce=="function"}var Il=class{child;blockRetrievers;blockAnnouncers;hashers;started;log;constructor(e,r){this.log=e.logger.forComponent("helia:networked-storage"),this.child=e.blockstore,this.blockRetrievers=(r.blockBrokers??[]).filter(mC),this.blockAnnouncers=(r.blockBrokers??[]).filter(yC),this.hashers=r.hashers??[],this.started=!1}isStarted(){return this.started}async start(){await as(this.child,...new Set([...this.blockRetrievers,...this.blockAnnouncers])),this.started=!0}async stop(){await cs(this.child,...new Set([...this.blockRetrievers,...this.blockAnnouncers])),this.started=!1}unwrap(){return this.child}async put(e,r,n={}){return await this.child.has(e)?(n.onProgress?.(new Ue("blocks:put:duplicate",e)),e):(n.onProgress?.(new Ue("blocks:put:providers:notify",e)),this.blockAnnouncers.forEach(i=>{i.announce(e,r,n)}),n.onProgress?.(new Ue("blocks:put:blockstore:put",e)),this.child.put(e,r,n))}async*putMany(e,r={}){let n=Fr(e,async({cid:o})=>{let s=await this.child.has(o);return s&&r.onProgress?.(new Ue("blocks:put-many:duplicate",o)),!s}),i=Tu(n,({cid:o,block:s})=>{r.onProgress?.(new Ue("blocks:put-many:providers:notify",o)),this.blockAnnouncers.forEach(a=>{a.announce(o,s,r)})});r.onProgress?.(new Ue("blocks:put-many:blockstore:put-many")),yield*this.child.putMany(i,r)}async get(e,r={}){if(r.offline!==!0&&!await this.child.has(e)){r.onProgress?.(new Ue("blocks:get:providers:get",e));let n=await sv(e,this.blockRetrievers,this.hashers,{...r,log:this.log});return r.onProgress?.(new Ue("blocks:get:blockstore:put",e)),await this.child.put(e,n,r),r.onProgress?.(new Ue("blocks:get:providers:notify",e)),this.blockAnnouncers.forEach(i=>{i.announce(e,n,r)}),n}return r.onProgress?.(new Ue("blocks:get:blockstore:get",e)),this.child.get(e,r)}async*getMany(e,r={}){r.onProgress?.(new Ue("blocks:get-many:blockstore:get-many")),yield*this.child.getMany(Tu(e,async n=>{if(r.offline!==!0&&!await this.child.has(n)){r.onProgress?.(new Ue("blocks:get-many:providers:get",n));let i=await sv(n,this.blockRetrievers,this.hashers,{...r,log:this.log});r.onProgress?.(new Ue("blocks:get-many:blockstore:put",n)),await this.child.put(n,i,r),r.onProgress?.(new Ue("blocks:get-many:providers:notify",n)),this.blockAnnouncers.forEach(o=>{o.announce(n,i,r)})}}))}async delete(e,r={}){r.onProgress?.(new Ue("blocks:delete:blockstore:delete",e)),await this.child.delete(e,r)}async*deleteMany(e,r={}){r.onProgress?.(new Ue("blocks:delete-many:blockstore:delete-many")),yield*this.child.deleteMany(async function*(){for await(let n of e)yield n}(),r)}async has(e,r={}){return this.child.has(e,r)}async*getAll(e={}){e.onProgress?.(new Ue("blocks:get-all:blockstore:get-many")),yield*this.child.getAll(e)}},gC=(t,e)=>{let r=e.find(n=>n.code===t.multihash.code);if(r==null)throw new x(`No hasher configured for multihash code 0x${t.multihash.code.toString(16)}, please configure one. You can look up which hash this is at https://github.com/multiformats/multicodec/blob/master/table.csv`,"ERR_UNKNOWN_HASH_ALG");return async n=>{let i=await r.digest(n);if(!ie(i.digest,t.multihash.digest))throw new x("Hash of downloaded block did not match multihash from passed CID","ERR_HASH_MISMATCH")}};async function sv(t,e,r,n){let i=gC(t,r),o=new AbortController,s=Jr([o.signal,n.signal]);try{return await Promise.any(e.map(async a=>{try{let c=!1,u=await a.retrieve(t,{...n,signal:s,validateFn:async l=>{await i(l),c=!0}});return c||await i(u),u}catch(c){throw n.log.error("could not retrieve verified block for %c",t,c),c}}))}finally{s.clear()}}var Rl=class{libp2p;blockstore;datastore;pins;logger;log;constructor(e){this.logger=e.libp2p.logger,this.log=this.logger.forComponent("helia");let r=ov(e.hashers),n={blockstore:e.blockstore,datastore:e.datastore,libp2p:e.libp2p,hashers:r,logger:e.libp2p.logger},i=e.blockBrokers.map(s=>s(n)),o=new Il(n,{blockBrokers:i,hashers:r});this.pins=new Al(e.datastore,o,$1(e.dagWalkers)),this.libp2p=e.libp2p,this.blockstore=new _l(o,this.pins,{holdGcLock:e.holdGcLock}),this.datastore=e.datastore}async start(){await iv(this.datastore),await as(this.blockstore),await this.libp2p.start()}async stop(){await this.libp2p.stop(),await cs(this.blockstore)}async gc(e={}){let r=await this.blockstore.lock.writeLock();try{let n=this,i=this.blockstore.unwrap();this.log("gc start"),await xi(i.deleteMany(async function*(){for await(let{cid:o}of i.getAll())try{if(await n.pins.isPinned(o,e))continue;yield o,e.onProgress?.(new Ue("helia:gc:deleted",o))}catch(s){n.log.error("Error during gc",s),e.onProgress?.(new Ue("helia:gc:error",s))}}()))}finally{r()}this.log("gc finished")}};var Cs={};Y(Cs,{abortedError:()=>EC,closeFailedError:()=>wC,deleteFailedError:()=>cv,getFailedError:()=>xC,hasFailedError:()=>vC,notFoundError:()=>Ac,openFailedError:()=>bC,putFailedError:()=>av});var Nn=me(fo(),1);function bC(t){return t=t??new Error("Open failed"),(0,Nn.default)(t,"ERR_OPEN_FAILED")}function wC(t){return t=t??new Error("Close failed"),(0,Nn.default)(t,"ERR_CLOSE_FAILED")}function av(t){return t=t??new Error("Put failed"),(0,Nn.default)(t,"ERR_PUT_FAILED")}function xC(t){return t=t??new Error("Get failed"),(0,Nn.default)(t,"ERR_GET_FAILED")}function cv(t){return t=t??new Error("Delete failed"),(0,Nn.default)(t,"ERR_DELETE_FAILED")}function vC(t){return t=t??new Error("Has failed"),(0,Nn.default)(t,"ERR_HAS_FAILED")}function Ac(t){return t=t??new Error("Not Found"),(0,Nn.default)(t,"ERR_NOT_FOUND")}function EC(t){return t=t??new Error("Aborted"),(0,Nn.default)(t,"ERR_ABORTED")}var bo=class{has(e,r){return Promise.reject(new Error(".has is not implemented"))}put(e,r,n){return Promise.reject(new Error(".put is not implemented"))}async*putMany(e,r){for await(let{cid:n,block:i}of e)await this.put(n,i,r),yield n}get(e,r){return Promise.reject(new Error(".get is not implemented"))}async*getMany(e,r){for await(let n of e)yield{cid:n,block:await this.get(n,r)}}async delete(e,r){await Promise.reject(new Error(".delete is not implemented"))}async*deleteMany(e,r){for await(let n of e)await this.delete(n,r),yield n}async*getAll(e){throw new Error(".getAll is not implemented")}};var Sc=class extends bo{data;constructor(){super(),this.data=new Map}put(e,r){return this.data.set(dt.encode(e.multihash.bytes),r),e}get(e){let r=this.data.get(dt.encode(e.multihash.bytes));if(r==null)throw Ac();return r}has(e){return this.data.has(dt.encode(e.multihash.bytes))}async delete(e){this.data.delete(dt.encode(e.multihash.bytes))}async*getAll(){for(let[e,r]of this.data.entries())yield{cid:Fe.createV1(Vu,kn(dt.decode(e))),block:r}}};var Z$=ds("blockstore:core:tiered");var nz={...Cs};var uv=me(fo(),1);function Bl(t){return t=t??new Error("Not Found"),(0,uv.default)(t,"ERR_NOT_FOUND")}var lv="SHARDING";function SC(t){return t[Symbol.asyncIterator]!=null}function _C(t){if(SC(t))return(async()=>{let r=[];for await(let n of t)r.push(n);return r})();let e=[];for(let r of t)e.push(r);return e}var Ic=_C;function IC(t){return t[Symbol.asyncIterator]!=null}function RC(t,e){return IC(t)?async function*(){yield*(await Ic(t)).sort(e)}():function*(){yield*Ic(t).sort(e)}()}var Tl=RC;var Ln=class{put(e,r,n){return Promise.reject(new Error(".put is not implemented"))}get(e,r){return Promise.reject(new Error(".get is not implemented"))}has(e,r){return Promise.reject(new Error(".has is not implemented"))}delete(e,r){return Promise.reject(new Error(".delete is not implemented"))}async*putMany(e,r={}){for await(let{key:n,value:i}of e)await this.put(n,i,r),yield n}async*getMany(e,r={}){for await(let n of e)yield{key:n,value:await this.get(n,r)}}async*deleteMany(e,r={}){for await(let n of e)await this.delete(n,r),yield n}batch(){let e=[],r=[];return{put(n,i){e.push({key:n,value:i})},delete(n){r.push(n)},commit:async n=>{await xi(this.putMany(e,n)),e=[],await xi(this.deleteMany(r,n)),r=[]}}}async*_all(e,r){throw new Error("._all is not implemented")}async*_allKeys(e,r){throw new Error("._allKeys is not implemented")}query(e,r){let n=this._all(e,r);if(e.prefix!=null){let i=e.prefix;n=Fr(n,o=>o.key.toString().startsWith(i))}if(Array.isArray(e.filters)&&(n=e.filters.reduce((i,o)=>Fr(i,o),n)),Array.isArray(e.orders)&&(n=e.orders.reduce((i,o)=>Tl(i,o),n)),e.offset!=null){let i=0,o=e.offset;n=Fr(n,()=>i++>=o)}return e.limit!=null&&(n=uc(n,e.limit)),n}queryKeys(e,r){let n=this._allKeys(e,r);if(e.prefix!=null){let i=e.prefix;n=Fr(n,o=>o.toString().startsWith(i))}if(Array.isArray(e.filters)&&(n=e.filters.reduce((i,o)=>Fr(i,o),n)),Array.isArray(e.orders)&&(n=e.orders.reduce((i,o)=>Tl(i,o),n)),e.offset!=null){let i=e.offset,o=0;n=Fr(n,()=>o++>=i)}return e.limit!=null&&(n=uc(n,e.limit)),n}};var wo=class extends Ln{data;constructor(){super(),this.data=new Map}put(e,r){return this.data.set(e.toString(),r),e}get(e){let r=this.data.get(e.toString());if(r==null)throw Bl();return r}has(e){return this.data.has(e.toString())}delete(e){this.data.delete(e.toString())}*_all(){for(let[e,r]of this.data.entries())yield{key:new pt(e),value:r}}*_allKeys(){for(let e of this.data.keys())yield new pt(e)}};var Cz=new pt(lv);var qz=ds("datastore:core:tiered");var G0={};Y(G0,{Ed25519PrivateKey:()=>Pi,Ed25519PublicKey:()=>Ms,generateKeyPair:()=>M4,generateKeyPairFromSeed:()=>Uv,unmarshalEd25519PrivateKey:()=>U4,unmarshalEd25519PublicKey:()=>K4});function Sr(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}function Ps(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function kC(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}function B0(t,...e){if(!kC(t))throw new Error("Expected Uint8Array");if(e.length>0&&!e.includes(t.length))throw new Error(`Expected Uint8Array of length ${e}, not of length=${t.length}`)}function kl(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Ps(t.outputLen),Ps(t.blockLen)}function Ds(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function hv(t,e){B0(t);let r=e.outputLen;if(t.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}var Cl=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function dv(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}var Ls=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),Vr=(t,e)=>t<<32-e|t>>>e,CC=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!CC)throw new Error("Non little-endian hardware is not supported");var PC=async()=>{};async function pv(t,e,r){let n=Date.now();for(let i=0;i<t;i++){r(i);let o=Date.now()-n;o>=0&&o<e||(await PC(),n+=o)}}function T0(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function Ri(t){if(typeof t=="string"&&(t=T0(t)),!dv(t))throw new Error(`expected Uint8Array, got ${typeof t}`);return t}function Pl(...t){let e=0;for(let n=0;n<t.length;n++){let i=t[n];if(!dv(i))throw new Error("Uint8Array expected");e+=i.length}let r=new Uint8Array(e);for(let n=0,i=0;n<t.length;n++){let o=t[n];r.set(o,i),i+=o.length}return r}var Ns=class{clone(){return this._cloneInto()}},DC={}.toString;function mv(t,e){if(e!==void 0&&DC.call(e)!=="[object Object]")throw new Error("Options should be object or undefined");return Object.assign(t,e)}function Dl(t){let e=n=>t().update(Ri(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function _r(t=32){if(Cl&&typeof Cl.getRandomValues=="function")return Cl.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}function NC(t,e,r,n){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,n);let i=BigInt(32),o=BigInt(4294967295),s=Number(r>>i&o),a=Number(r&o),c=n?4:0,u=n?0:4;t.setUint32(e+c,s,n),t.setUint32(e+u,a,n)}var Os=class extends Ns{constructor(e,r,n,i){super(),this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=Ls(this.buffer)}update(e){Ds(this);let{view:r,buffer:n,blockLen:i}=this;e=Ri(e);let o=e.length;for(let s=0;s<o;){let a=Math.min(i-this.pos,o-s);if(a===i){let c=Ls(e);for(;i<=o-s;s+=i)this.process(c,s);continue}n.set(e.subarray(s,s+a),this.pos),this.pos+=a,s+=a,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Ds(this),hv(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:i,isLE:o}=this,{pos:s}=this;r[s++]=128,this.buffer.subarray(s).fill(0),this.padOffset>i-s&&(this.process(n,0),s=0);for(let f=s;f<i;f++)r[f]=0;NC(n,i-8,BigInt(this.length*8),o),this.process(n,0);let a=Ls(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)a.setUint32(4*f,l[f],o)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:r,buffer:n,length:i,finished:o,destroyed:s,pos:a}=this;return e.length=i,e.pos=a,e.finished=o,e.destroyed=s,i%r&&e.buffer.set(n),e}};var Nl=BigInt(4294967295),k0=BigInt(32);function yv(t,e=!1){return e?{h:Number(t&Nl),l:Number(t>>k0&Nl)}:{h:Number(t>>k0&Nl)|0,l:Number(t&Nl)|0}}function LC(t,e=!1){let r=new Uint32Array(t.length),n=new Uint32Array(t.length);for(let i=0;i<t.length;i++){let{h:o,l:s}=yv(t[i],e);[r[i],n[i]]=[o,s]}return[r,n]}var OC=(t,e)=>BigInt(t>>>0)<<k0|BigInt(e>>>0),UC=(t,e,r)=>t>>>r,KC=(t,e,r)=>t<<32-r|e>>>r,MC=(t,e,r)=>t>>>r|e<<32-r,FC=(t,e,r)=>t<<32-r|e>>>r,VC=(t,e,r)=>t<<64-r|e>>>r-32,HC=(t,e,r)=>t>>>r-32|e<<64-r,qC=(t,e)=>e,$C=(t,e)=>t,zC=(t,e,r)=>t<<r|e>>>32-r,GC=(t,e,r)=>e<<r|t>>>32-r,WC=(t,e,r)=>e<<r-32|t>>>64-r,YC=(t,e,r)=>t<<r-32|e>>>64-r;function jC(t,e,r,n){let i=(e>>>0)+(n>>>0);return{h:t+r+(i/2**32|0)|0,l:i|0}}var QC=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),JC=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,XC=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),ZC=(t,e,r,n,i)=>e+r+n+i+(t/2**32|0)|0,e4=(t,e,r,n,i)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(i>>>0),t4=(t,e,r,n,i,o)=>e+r+n+i+o+(t/2**32|0)|0;var r4={fromBig:yv,split:LC,toBig:OC,shrSH:UC,shrSL:KC,rotrSH:MC,rotrSL:FC,rotrBH:VC,rotrBL:HC,rotr32H:qC,rotr32L:$C,rotlSH:zC,rotlSL:GC,rotlBH:WC,rotlBL:YC,add:jC,add3L:QC,add3H:JC,add4L:XC,add4H:ZC,add5H:t4,add5L:e4},le=r4;var[n4,i4]=le.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),Bi=new Uint32Array(80),Ti=new Uint32Array(80),C0=class extends Os{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:e,Al:r,Bh:n,Bl:i,Ch:o,Cl:s,Dh:a,Dl:c,Eh:u,El:l,Fh:f,Fl:d,Gh:p,Gl:h,Hh:m,Hl:y}=this;return[e,r,n,i,o,s,a,c,u,l,f,d,p,h,m,y]}set(e,r,n,i,o,s,a,c,u,l,f,d,p,h,m,y){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=i|0,this.Ch=o|0,this.Cl=s|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=l|0,this.Fh=f|0,this.Fl=d|0,this.Gh=p|0,this.Gl=h|0,this.Hh=m|0,this.Hl=y|0}process(e,r){for(let w=0;w<16;w++,r+=4)Bi[w]=e.getUint32(r),Ti[w]=e.getUint32(r+=4);for(let w=16;w<80;w++){let _=Bi[w-15]|0,E=Ti[w-15]|0,A=le.rotrSH(_,E,1)^le.rotrSH(_,E,8)^le.shrSH(_,E,7),B=le.rotrSL(_,E,1)^le.rotrSL(_,E,8)^le.shrSL(_,E,7),I=Bi[w-2]|0,L=Ti[w-2]|0,H=le.rotrSH(I,L,19)^le.rotrBH(I,L,61)^le.shrSH(I,L,6),F=le.rotrSL(I,L,19)^le.rotrBL(I,L,61)^le.shrSL(I,L,6),$=le.add4L(B,F,Ti[w-7],Ti[w-16]),te=le.add4H($,A,H,Bi[w-7],Bi[w-16]);Bi[w]=te|0,Ti[w]=$|0}let{Ah:n,Al:i,Bh:o,Bl:s,Ch:a,Cl:c,Dh:u,Dl:l,Eh:f,El:d,Fh:p,Fl:h,Gh:m,Gl:y,Hh:g,Hl:b}=this;for(let w=0;w<80;w++){let _=le.rotrSH(f,d,14)^le.rotrSH(f,d,18)^le.rotrBH(f,d,41),E=le.rotrSL(f,d,14)^le.rotrSL(f,d,18)^le.rotrBL(f,d,41),A=f&p^~f&m,B=d&h^~d&y,I=le.add5L(b,E,B,i4[w],Ti[w]),L=le.add5H(I,g,_,A,n4[w],Bi[w]),H=I|0,F=le.rotrSH(n,i,28)^le.rotrBH(n,i,34)^le.rotrBH(n,i,39),$=le.rotrSL(n,i,28)^le.rotrBL(n,i,34)^le.rotrBL(n,i,39),te=n&o^n&a^o&a,de=i&s^i&c^s&c;g=m|0,b=y|0,m=p|0,y=h|0,p=f|0,h=d|0,{h:f,l:d}=le.add(u|0,l|0,L|0,H|0),u=a|0,l=c|0,a=o|0,c=s|0,o=n|0,s=i|0;let T=le.add3L(H,$,de);n=le.add3H(T,L,F,te),i=T|0}({h:n,l:i}=le.add(this.Ah|0,this.Al|0,n|0,i|0)),{h:o,l:s}=le.add(this.Bh|0,this.Bl|0,o|0,s|0),{h:a,l:c}=le.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=le.add(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:d}=le.add(this.Eh|0,this.El|0,f|0,d|0),{h:p,l:h}=le.add(this.Fh|0,this.Fl|0,p|0,h|0),{h:m,l:y}=le.add(this.Gh|0,this.Gl|0,m|0,y|0),{h:g,l:b}=le.add(this.Hh|0,this.Hl|0,g|0,b|0),this.set(n,i,o,s,a,c,u,l,f,d,p,h,m,y,g,b)}roundClean(){Bi.fill(0),Ti.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Ir=Dl(()=>new C0);var Ol={};Y(Ol,{bitGet:()=>f4,bitLen:()=>l4,bitMask:()=>Rc,bitSet:()=>h4,bytesToHex:()=>Un,bytesToNumberBE:()=>Kn,bytesToNumberLE:()=>ki,concatBytes:()=>Mn,createHmacDrbg:()=>N0,ensureBytes:()=>et,equalBytes:()=>c4,hexToBytes:()=>xo,hexToNumber:()=>D0,isBytes:()=>Hr,numberToBytesBE:()=>Ci,numberToBytesLE:()=>vo,numberToHexUnpadded:()=>xv,numberToVarBytesBE:()=>a4,utf8ToBytes:()=>u4,validateObject:()=>en});var wv=BigInt(0),Ll=BigInt(1),o4=BigInt(2);function Hr(t){return t instanceof Uint8Array||t!=null&&typeof t=="object"&&t.constructor.name==="Uint8Array"}var s4=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Un(t){if(!Hr(t))throw new Error("Uint8Array expected");let e="";for(let r=0;r<t.length;r++)e+=s4[t[r]];return e}function xv(t){let e=t.toString(16);return e.length&1?`0${e}`:e}function D0(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return BigInt(t===""?"0":`0x${t}`)}var On={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function gv(t){if(t>=On._0&&t<=On._9)return t-On._0;if(t>=On._A&&t<=On._F)return t-(On._A-10);if(t>=On._a&&t<=On._f)return t-(On._a-10)}function xo(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);let e=t.length,r=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let i=0,o=0;i<r;i++,o+=2){let s=gv(t.charCodeAt(o)),a=gv(t.charCodeAt(o+1));if(s===void 0||a===void 0){let c=t[o]+t[o+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+o)}n[i]=s*16+a}return n}function Kn(t){return D0(Un(t))}function ki(t){if(!Hr(t))throw new Error("Uint8Array expected");return D0(Un(Uint8Array.from(t).reverse()))}function Ci(t,e){return xo(t.toString(16).padStart(e*2,"0"))}function vo(t,e){return Ci(t,e).reverse()}function a4(t){return xo(xv(t))}function et(t,e,r){let n;if(typeof e=="string")try{n=xo(e)}catch(o){throw new Error(`${t} must be valid hex string, got "${e}". Cause: ${o}`)}else if(Hr(e))n=Uint8Array.from(e);else throw new Error(`${t} must be hex string or Uint8Array`);let i=n.length;if(typeof r=="number"&&i!==r)throw new Error(`${t} expected ${r} bytes, got ${i}`);return n}function Mn(...t){let e=0;for(let i=0;i<t.length;i++){let o=t[i];if(!Hr(o))throw new Error("Uint8Array expected");e+=o.length}let r=new Uint8Array(e),n=0;for(let i=0;i<t.length;i++){let o=t[i];r.set(o,n),n+=o.length}return r}function c4(t,e){if(t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function u4(t){if(typeof t!="string")throw new Error(`utf8ToBytes expected string, got ${typeof t}`);return new Uint8Array(new TextEncoder().encode(t))}function l4(t){let e;for(e=0;t>wv;t>>=Ll,e+=1);return e}function f4(t,e){return t>>BigInt(e)&Ll}var h4=(t,e,r)=>t|(r?Ll:wv)<<BigInt(e),Rc=t=>(o4<<BigInt(t-1))-Ll,P0=t=>new Uint8Array(t),bv=t=>Uint8Array.from(t);function N0(t,e,r){if(typeof t!="number"||t<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=P0(t),i=P0(t),o=0,s=()=>{n.fill(1),i.fill(0),o=0},a=(...f)=>r(i,n,...f),c=(f=P0())=>{i=a(bv([0]),f),n=a(),f.length!==0&&(i=a(bv([1]),f),n=a())},u=()=>{if(o++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,d=[];for(;f<e;){n=a();let p=n.slice();d.push(p),f+=n.length}return Mn(...d)};return(f,d)=>{s(),c(f);let p;for(;!(p=d(u()));)c();return s(),p}}var d4={bigint:t=>typeof t=="bigint",function:t=>typeof t=="function",boolean:t=>typeof t=="boolean",string:t=>typeof t=="string",stringOrUint8Array:t=>typeof t=="string"||Hr(t),isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>typeof t=="function"&&Number.isSafeInteger(t.outputLen)};function en(t,e,r={}){let n=(i,o,s)=>{let a=d4[o];if(typeof a!="function")throw new Error(`Invalid validator "${o}", expected function`);let c=t[i];if(!(s&&c===void 0)&&!a(c,t))throw new Error(`Invalid param ${String(i)}=${c} (${typeof c}), expected ${o}`)};for(let[i,o]of Object.entries(e))n(i,o,!1);for(let[i,o]of Object.entries(r))n(i,o,!0);return t}var mt=BigInt(0),$e=BigInt(1),Eo=BigInt(2),p4=BigInt(3),L0=BigInt(4),vv=BigInt(5),Ev=BigInt(8),m4=BigInt(9),y4=BigInt(16);function Ne(t,e){let r=t%e;return r>=mt?r:e+r}function g4(t,e,r){if(r<=mt||e<mt)throw new Error("Expected power/modulo > 0");if(r===$e)return mt;let n=$e;for(;e>mt;)e&$e&&(n=n*t%r),t=t*t%r,e>>=$e;return n}function ze(t,e,r){let n=t;for(;e-- >mt;)n*=n,n%=r;return n}function Ul(t,e){if(t===mt||e<=mt)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let r=Ne(t,e),n=e,i=mt,o=$e,s=$e,a=mt;for(;r!==mt;){let u=n/r,l=n%r,f=i-s*u,d=o-a*u;n=r,r=l,i=s,o=a,s=f,a=d}if(n!==$e)throw new Error("invert: does not exist");return Ne(i,e)}function b4(t){let e=(t-$e)/Eo,r,n,i;for(r=t-$e,n=0;r%Eo===mt;r/=Eo,n++);for(i=Eo;i<t&&g4(i,e,t)!==t-$e;i++);if(n===1){let s=(t+$e)/L0;return function(c,u){let l=c.pow(u,s);if(!c.eql(c.sqr(l),u))throw new Error("Cannot find square root");return l}}let o=(r+$e)/Eo;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let u=n,l=a.pow(a.mul(a.ONE,i),r),f=a.pow(c,o),d=a.pow(c,r);for(;!a.eql(d,a.ONE);){if(a.eql(d,a.ZERO))return a.ZERO;let p=1;for(let m=a.sqr(d);p<u&&!a.eql(m,a.ONE);p++)m=a.sqr(m);let h=a.pow(l,$e<<BigInt(u-p-1));l=a.sqr(h),f=a.mul(f,h),d=a.mul(d,l),u=p}return f}}function w4(t){if(t%L0===p4){let e=(t+$e)/L0;return function(n,i){let o=n.pow(i,e);if(!n.eql(n.sqr(o),i))throw new Error("Cannot find square root");return o}}if(t%Ev===vv){let e=(t-vv)/Ev;return function(n,i){let o=n.mul(i,Eo),s=n.pow(o,e),a=n.mul(i,s),c=n.mul(n.mul(a,Eo),s),u=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(u),i))throw new Error("Cannot find square root");return u}}return t%y4,b4(t)}var Av=(t,e)=>(Ne(t,e)&$e)===$e,x4=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function O0(t){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},r=x4.reduce((n,i)=>(n[i]="function",n),e);return en(t,r)}function v4(t,e,r){if(r<mt)throw new Error("Expected power > 0");if(r===mt)return t.ONE;if(r===$e)return e;let n=t.ONE,i=e;for(;r>mt;)r&$e&&(n=t.mul(n,i)),i=t.sqr(i),r>>=$e;return n}function E4(t,e){let r=new Array(e.length),n=e.reduce((o,s,a)=>t.is0(s)?o:(r[a]=o,t.mul(o,s)),t.ONE),i=t.inv(n);return e.reduceRight((o,s,a)=>t.is0(s)?o:(r[a]=t.mul(o,r[a]),t.mul(o,s)),i),r}function U0(t,e){let r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function Kl(t,e,r=!1,n={}){if(t<=mt)throw new Error(`Expected Field ORDER > 0, got ${t}`);let{nBitLength:i,nByteLength:o}=U0(t,e);if(o>2048)throw new Error("Field lengths over 2048 bytes are not supported");let s=w4(t),a=Object.freeze({ORDER:t,BITS:i,BYTES:o,MASK:Rc(i),ZERO:mt,ONE:$e,create:c=>Ne(c,t),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return mt<=c&&c<t},is0:c=>c===mt,isOdd:c=>(c&$e)===$e,neg:c=>Ne(-c,t),eql:(c,u)=>c===u,sqr:c=>Ne(c*c,t),add:(c,u)=>Ne(c+u,t),sub:(c,u)=>Ne(c-u,t),mul:(c,u)=>Ne(c*u,t),pow:(c,u)=>v4(a,c,u),div:(c,u)=>Ne(c*Ul(u,t),t),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>Ul(c,t),sqrt:n.sqrt||(c=>s(a,c)),invertBatch:c=>E4(a,c),cmov:(c,u,l)=>l?u:c,toBytes:c=>r?vo(c,o):Ci(c,o),fromBytes:c=>{if(c.length!==o)throw new Error(`Fp.fromBytes: expected ${o}, got ${c.length}`);return r?ki(c):Kn(c)}});return Object.freeze(a)}function Sv(t,e){if(!t.isOdd)throw new Error("Field doesn't have isOdd");let r=t.sqrt(e);return t.isOdd(r)?t.neg(r):r}function _v(t){if(typeof t!="bigint")throw new Error("field order must be bigint");let e=t.toString(2).length;return Math.ceil(e/8)}function K0(t){let e=_v(t);return e+Math.ceil(e/2)}function Iv(t,e,r=!1){let n=t.length,i=_v(e),o=K0(e);if(n<16||n<o||n>1024)throw new Error(`expected ${o}-1024 bytes of input, got ${n}`);let s=r?Kn(t):ki(t),a=Ne(s,e-$e)+$e;return r?vo(a,i):Ci(a,i)}var S4=BigInt(0),M0=BigInt(1);function Ml(t,e){let r=(i,o)=>{let s=o.negate();return i?s:o},n=i=>{let o=Math.ceil(e/i)+1,s=2**(i-1);return{windows:o,windowSize:s}};return{constTimeNegate:r,unsafeLadder(i,o){let s=t.ZERO,a=i;for(;o>S4;)o&M0&&(s=s.add(a)),a=a.double(),o>>=M0;return s},precomputeWindow(i,o){let{windows:s,windowSize:a}=n(o),c=[],u=i,l=u;for(let f=0;f<s;f++){l=u,c.push(l);for(let d=1;d<a;d++)l=l.add(u),c.push(l);u=l.double()}return c},wNAF(i,o,s){let{windows:a,windowSize:c}=n(i),u=t.ZERO,l=t.BASE,f=BigInt(2**i-1),d=2**i,p=BigInt(i);for(let h=0;h<a;h++){let m=h*c,y=Number(s&f);s>>=p,y>c&&(y-=d,s+=M0);let g=m,b=m+Math.abs(y)-1,w=h%2!==0,_=y<0;y===0?l=l.add(r(w,o[g])):u=u.add(r(_,o[b]))}return{p:u,f:l}},wNAFCached(i,o,s,a){let c=i._WINDOW_SIZE||1,u=o.get(i);return u||(u=this.precomputeWindow(i,c),c!==1&&o.set(i,a(u))),this.wNAF(c,u,s)}}}function Bc(t){return O0(t.Fp),en(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...U0(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}var qr=BigInt(0),pr=BigInt(1),Fl=BigInt(2),_4=BigInt(8),I4={zip215:!0};function R4(t){let e=Bc(t);return en(t,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function Vl(t){let e=R4(t),{Fp:r,n,prehash:i,hash:o,randomBytes:s,nByteLength:a,h:c}=e,u=Fl<<BigInt(a*8)-pr,l=r.create,f=e.uvRatio||((K,C)=>{try{return{isValid:!0,value:r.sqrt(K*r.inv(C))}}catch{return{isValid:!1,value:qr}}}),d=e.adjustScalarBytes||(K=>K),p=e.domain||((K,C,W)=>{if(C.length||W)throw new Error("Contexts/pre-hash are not supported");return K}),h=K=>typeof K=="bigint"&&qr<K,m=(K,C)=>h(K)&&h(C)&&K<C,y=K=>K===qr||m(K,u);function g(K,C){if(m(K,C))return K;throw new Error(`Expected valid scalar < ${C}, got ${typeof K} ${K}`)}function b(K){return K===qr?K:g(K,n)}let w=new Map;function _(K){if(!(K instanceof E))throw new Error("ExtendedPoint expected")}class E{constructor(C,W,Z,oe){if(this.ex=C,this.ey=W,this.ez=Z,this.et=oe,!y(C))throw new Error("x required");if(!y(W))throw new Error("y required");if(!y(Z))throw new Error("z required");if(!y(oe))throw new Error("t required")}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(C){if(C instanceof E)throw new Error("extended point not allowed");let{x:W,y:Z}=C||{};if(!y(W)||!y(Z))throw new Error("invalid affine point");return new E(W,Z,pr,l(W*Z))}static normalizeZ(C){let W=r.invertBatch(C.map(Z=>Z.ez));return C.map((Z,oe)=>Z.toAffine(W[oe])).map(E.fromAffine)}_setWindowSize(C){this._WINDOW_SIZE=C,w.delete(this)}assertValidity(){let{a:C,d:W}=e;if(this.is0())throw new Error("bad point: ZERO");let{ex:Z,ey:oe,ez:pe,et:ge}=this,Te=l(Z*Z),we=l(oe*oe),_e=l(pe*pe),ct=l(_e*_e),Je=l(Te*C),_t=l(_e*l(Je+we)),It=l(ct+l(W*l(Te*we)));if(_t!==It)throw new Error("bad point: equation left != right (1)");let ht=l(Z*oe),Ot=l(pe*ge);if(ht!==Ot)throw new Error("bad point: equation left != right (2)")}equals(C){_(C);let{ex:W,ey:Z,ez:oe}=this,{ex:pe,ey:ge,ez:Te}=C,we=l(W*Te),_e=l(pe*oe),ct=l(Z*Te),Je=l(ge*oe);return we===_e&&ct===Je}is0(){return this.equals(E.ZERO)}negate(){return new E(l(-this.ex),this.ey,this.ez,l(-this.et))}double(){let{a:C}=e,{ex:W,ey:Z,ez:oe}=this,pe=l(W*W),ge=l(Z*Z),Te=l(Fl*l(oe*oe)),we=l(C*pe),_e=W+Z,ct=l(l(_e*_e)-pe-ge),Je=we+ge,_t=Je-Te,It=we-ge,ht=l(ct*_t),Ot=l(Je*It),In=l(ct*It),no=l(_t*Je);return new E(ht,Ot,no,In)}add(C){_(C);let{a:W,d:Z}=e,{ex:oe,ey:pe,ez:ge,et:Te}=this,{ex:we,ey:_e,ez:ct,et:Je}=C;if(W===BigInt(-1)){let mb=l((pe-oe)*(_e+we)),yb=l((pe+oe)*(_e-we)),Bd=l(yb-mb);if(Bd===qr)return this.double();let gb=l(ge*Fl*Je),bb=l(Te*Fl*ct),wb=bb+gb,xb=yb+mb,vb=bb-gb,_R=l(wb*Bd),IR=l(xb*vb),RR=l(wb*vb),BR=l(Bd*xb);return new E(_R,IR,BR,RR)}let _t=l(oe*we),It=l(pe*_e),ht=l(Te*Z*Je),Ot=l(ge*ct),In=l((oe+pe)*(we+_e)-_t-It),no=Ot-ht,Wa=Ot+ht,pb=l(It-W*_t),vR=l(In*no),ER=l(Wa*pb),AR=l(In*pb),SR=l(no*Wa);return new E(vR,ER,SR,AR)}subtract(C){return this.add(C.negate())}wNAF(C){return I.wNAFCached(this,w,C,E.normalizeZ)}multiply(C){let{p:W,f:Z}=this.wNAF(g(C,n));return E.normalizeZ([W,Z])[0]}multiplyUnsafe(C){let W=b(C);return W===qr?B:this.equals(B)||W===pr?this:this.equals(A)?this.wNAF(W).p:I.unsafeLadder(this,W)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return I.unsafeLadder(this,n).is0()}toAffine(C){let{ex:W,ey:Z,ez:oe}=this,pe=this.is0();C==null&&(C=pe?_4:r.inv(oe));let ge=l(W*C),Te=l(Z*C),we=l(oe*C);if(pe)return{x:qr,y:pr};if(we!==pr)throw new Error("invZ was invalid");return{x:ge,y:Te}}clearCofactor(){let{h:C}=e;return C===pr?this:this.multiplyUnsafe(C)}static fromHex(C,W=!1){let{d:Z,a:oe}=e,pe=r.BYTES;C=et("pointHex",C,pe);let ge=C.slice(),Te=C[pe-1];ge[pe-1]=Te&-129;let we=ki(ge);we===qr||(W?g(we,u):g(we,r.ORDER));let _e=l(we*we),ct=l(_e-pr),Je=l(Z*_e-oe),{isValid:_t,value:It}=f(ct,Je);if(!_t)throw new Error("Point.fromHex: invalid y coordinate");let ht=(It&pr)===pr,Ot=(Te&128)!==0;if(!W&&It===qr&&Ot)throw new Error("Point.fromHex: x=0 and x_0=1");return Ot!==ht&&(It=l(-It)),E.fromAffine({x:It,y:we})}static fromPrivateKey(C){return F(C).point}toRawBytes(){let{x:C,y:W}=this.toAffine(),Z=vo(W,r.BYTES);return Z[Z.length-1]|=C&pr?128:0,Z}toHex(){return Un(this.toRawBytes())}}E.BASE=new E(e.Gx,e.Gy,pr,l(e.Gx*e.Gy)),E.ZERO=new E(qr,pr,pr,qr);let{BASE:A,ZERO:B}=E,I=Ml(E,a*8);function L(K){return Ne(K,n)}function H(K){return L(ki(K))}function F(K){let C=a;K=et("private key",K,C);let W=et("hashed private key",o(K),2*C),Z=d(W.slice(0,C)),oe=W.slice(C,2*C),pe=H(Z),ge=A.multiply(pe),Te=ge.toRawBytes();return{head:Z,prefix:oe,scalar:pe,point:ge,pointBytes:Te}}function $(K){return F(K).pointBytes}function te(K=new Uint8Array,...C){let W=Mn(...C);return H(o(p(W,et("context",K),!!i)))}function de(K,C,W={}){K=et("message",K),i&&(K=i(K));let{prefix:Z,scalar:oe,pointBytes:pe}=F(C),ge=te(W.context,Z,K),Te=A.multiply(ge).toRawBytes(),we=te(W.context,Te,pe,K),_e=L(ge+we*oe);b(_e);let ct=Mn(Te,vo(_e,r.BYTES));return et("result",ct,a*2)}let T=I4;function D(K,C,W,Z=T){let{context:oe,zip215:pe}=Z,ge=r.BYTES;K=et("signature",K,2*ge),C=et("message",C),i&&(C=i(C));let Te=ki(K.slice(ge,2*ge)),we,_e,ct;try{we=E.fromHex(W,pe),_e=E.fromHex(K.slice(0,ge),pe),ct=A.multiplyUnsafe(Te)}catch{return!1}if(!pe&&we.isSmallOrder())return!1;let Je=te(oe,_e.toRawBytes(),we.toRawBytes(),C);return _e.add(we.multiplyUnsafe(Je)).subtract(ct).clearCofactor().equals(E.ZERO)}return A._setWindowSize(8),{CURVE:e,getPublicKey:$,sign:de,verify:D,ExtendedPoint:E,utils:{getExtendedPublicKey:F,randomPrivateKey:()=>s(r.BYTES),precompute(K=8,C=E.BASE){return C._setWindowSize(K),C.multiply(BigInt(3)),C}}}}var V0=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Rv=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),DG=BigInt(0),B4=BigInt(1),F0=BigInt(2),T4=BigInt(5),Bv=BigInt(10),k4=BigInt(20),C4=BigInt(40),Tv=BigInt(80);function P4(t){let e=V0,n=t*t%e*t%e,i=ze(n,F0,e)*n%e,o=ze(i,B4,e)*t%e,s=ze(o,T4,e)*o%e,a=ze(s,Bv,e)*s%e,c=ze(a,k4,e)*a%e,u=ze(c,C4,e)*c%e,l=ze(u,Tv,e)*u%e,f=ze(l,Tv,e)*u%e,d=ze(f,Bv,e)*s%e;return{pow_p_5_8:ze(d,F0,e)*t%e,b2:n}}function D4(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}function N4(t,e){let r=V0,n=Ne(e*e*e,r),i=Ne(n*n*e,r),o=P4(t*i).pow_p_5_8,s=Ne(t*n*o,r),a=Ne(e*s*s,r),c=s,u=Ne(s*Rv,r),l=a===t,f=a===Ne(-t,r),d=a===Ne(-t*Rv,r);return l&&(s=c),(f||d)&&(s=u),Av(s,r)&&(s=Ne(-s,r)),{isValid:l||f,value:s}}var Fn=Kl(V0,void 0,!0),H0={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Fn,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:BigInt(8),Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Ir,randomBytes:_r,adjustScalarBytes:D4,uvRatio:N4},Ge=Vl(H0);function kv(t,e,r){if(e.length>255)throw new Error("Context is too big");return Pl(T0("SigEd25519 no Ed25519 collisions"),new Uint8Array([r?1:0,e.length]),e,t)}var NG=Vl({...H0,domain:kv}),LG=Vl({...H0,domain:kv,prehash:Ir});var L4=(Fn.ORDER+BigInt(3))/BigInt(8),OG=Fn.pow(F0,L4),UG=Fn.sqrt(Fn.neg(Fn.ONE)),KG=(Fn.ORDER-BigInt(5))/BigInt(8),MG=BigInt(486662);var FG=Sv(Fn,Fn.neg(BigInt(486664)));var VG=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),HG=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),qG=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),$G=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952");var zG=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");var Us=32,Vn=64,Hl=32;function Cv(){let t=Ge.utils.randomPrivateKey(),e=Ge.getPublicKey(t);return{privateKey:Lv(t,e),publicKey:e}}function Pv(t){if(t.length!==Hl)throw new TypeError('"seed" must be 32 bytes in length.');if(!(t instanceof Uint8Array))throw new TypeError('"seed" must be a node.js Buffer, or Uint8Array.');let e=t,r=Ge.getPublicKey(e);return{privateKey:Lv(e,r),publicKey:r}}function Dv(t,e){let r=t.subarray(0,Hl);return Ge.sign(e instanceof Uint8Array?e:e.subarray(),r)}function Nv(t,e,r){return Ge.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}function Lv(t,e){let r=new Uint8Array(Vn);for(let n=0;n<Hl;n++)r[n]=t[n],r[Hl+n]=e[n];return r}var Bt={get(t=globalThis){let e=t.crypto;if(e==null||e.subtle==null)throw Object.assign(new Error("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api"),{code:"ERR_MISSING_WEB_CRYPTO"});return e}};var q0={alg:"A128GCM",ext:!0,k:"scm9jmO_4BJAgdwWGVulLg",key_ops:["encrypt","decrypt"],kty:"oct"};function $0(t){let e=t?.algorithm??"AES-GCM",r=t?.keyLength??16,n=t?.nonceLength??12,i=t?.digest??"SHA-256",o=t?.saltLength??16,s=t?.iterations??32767,a=Bt.get();r*=8;async function c(f,d){let p=a.getRandomValues(new Uint8Array(o)),h=a.getRandomValues(new Uint8Array(n)),m={name:e,iv:h};typeof d=="string"&&(d=U(d));let y;if(d.length===0){y=await a.subtle.importKey("jwk",q0,{name:"AES-GCM"},!0,["encrypt"]);try{let b={name:"PBKDF2",salt:p,iterations:s,hash:{name:i}},w=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(b,w,{name:e,length:r},!0,["encrypt"])}catch{y=await a.subtle.importKey("jwk",q0,{name:"AES-GCM"},!0,["encrypt"])}}else{let b={name:"PBKDF2",salt:p,iterations:s,hash:{name:i}},w=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(b,w,{name:e,length:r},!0,["encrypt"])}let g=await a.subtle.encrypt(m,y,f);return ke([p,m.iv,new Uint8Array(g)])}async function u(f,d){let p=f.subarray(0,o),h=f.subarray(o,o+n),m=f.subarray(o+n),y={name:e,iv:h};typeof d=="string"&&(d=U(d));let g;if(d.length===0)try{let w={name:"PBKDF2",salt:p,iterations:s,hash:{name:i}},_=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);g=await a.subtle.deriveKey(w,_,{name:e,length:r},!0,["decrypt"])}catch{g=await a.subtle.importKey("jwk",q0,{name:"AES-GCM"},!0,["decrypt"])}else{let w={name:"PBKDF2",salt:p,iterations:s,hash:{name:i}},_=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);g=await a.subtle.deriveKey(w,_,{name:e,length:r},!0,["decrypt"])}let b=await a.subtle.decrypt(y,g,m);return new Uint8Array(b)}return{encrypt:c,decrypt:u}}async function Ks(t,e){let n=await $0().encrypt(t,e);return $t.encode(n)}var nt;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.Secp256k1="Secp256k1"})(nt||(nt={}));var z0;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.Secp256k1=2]="Secp256k1"})(z0||(z0={}));(function(t){t.codec=()=>Zt(z0)})(nt||(nt={}));var tn;(function(t){let e;t.codec=()=>(e==null&&(e=Ee((r,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),nt.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),i.lengthDelimited!==!1&&n.ldelim()},(r,n)=>{let i={},o=n==null?r.len:r.pos+n;for(;r.pos<o;){let s=r.uint32();switch(s>>>3){case 1:i.Type=nt.codec().decode(r);break;case 2:i.Data=r.bytes();break;default:r.skipType(s&7);break}}return i})),e),t.encode=r=>ve(r,t.codec()),t.decode=r=>xe(r,t.codec())})(tn||(tn={}));var Hn;(function(t){let e;t.codec=()=>(e==null&&(e=Ee((r,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),nt.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),i.lengthDelimited!==!1&&n.ldelim()},(r,n)=>{let i={},o=n==null?r.len:r.pos+n;for(;r.pos<o;){let s=r.uint32();switch(s>>>3){case 1:i.Type=nt.codec().decode(r);break;case 2:i.Data=r.bytes();break;default:r.skipType(s&7);break}}return i})),e),t.encode=r=>ve(r,t.codec()),t.decode=r=>xe(r,t.codec())})(Hn||(Hn={}));var Ms=class{_key;constructor(e){this._key=Fs(e,Us)}verify(e,r){return Nv(this._key,r,e)}marshal(){return this._key}get bytes(){return tn.encode({Type:nt.Ed25519,Data:this.marshal()}).subarray()}equals(e){return ie(this.bytes,e.bytes)}hash(){let e=ae.digest(this.bytes);return Sr(e)?e.then(({bytes:r})=>r):e.bytes}},Pi=class{_key;_publicKey;constructor(e,r){this._key=Fs(e,Vn),this._publicKey=Fs(r,Us)}sign(e){return Dv(this._key,e)}get public(){return new Ms(this._publicKey)}marshal(){return this._key}get bytes(){return Hn.encode({Type:nt.Ed25519,Data:this.marshal()}).subarray()}equals(e){return ie(this.bytes,e.bytes)}async hash(){let e=ae.digest(this.bytes),r;return Sr(e)?{bytes:r}=await e:r=e.bytes,r}async id(){let e=Xt.digest(this.public.bytes);return Oe.encode(e.bytes).substring(1)}async export(e,r="libp2p-key"){if(r==="libp2p-key")return Ks(this.bytes,e);throw new x(`export format '${r}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function U4(t){if(t.length>Vn){t=Fs(t,Vn+Us);let n=t.subarray(0,Vn),i=t.subarray(Vn,t.length);return new Pi(n,i)}t=Fs(t,Vn);let e=t.subarray(0,Vn),r=t.subarray(Us);return new Pi(e,r)}function K4(t){return t=Fs(t,Us),new Ms(t)}async function M4(){let{privateKey:t,publicKey:e}=Cv();return new Pi(t,e)}async function Uv(t){let{privateKey:e,publicKey:r}=Pv(t);return new Pi(e,r)}function Fs(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new x(`Key must be a Uint8Array of length ${e}, got ${t.length}`,"ERR_INVALID_KEY_TYPE");return t}var F4={"P-256":256,"P-384":384,"P-521":521},V4=Object.keys(F4),mW=V4.join(" / ");var rm={};Y(rm,{MAX_RSA_KEY_SIZE:()=>$s,RsaPrivateKey:()=>_o,RsaPublicKey:()=>qs,fromJwk:()=>d6,generateKeyPair:()=>p6,unmarshalRsaPrivateKey:()=>em,unmarshalRsaPublicKey:()=>h6});function Ao(t){if(isNaN(t)||t<=0)throw new x("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return _r(t)}var Li={};Y(Li,{exportToPem:()=>c6,importFromPem:()=>IE,jwkToPkcs1:()=>i6,jwkToPkix:()=>s6,pkcs1ToJwk:()=>n6,pkixToJwk:()=>o6});var $l=class extends Ns{constructor(e,r){super(),this.finished=!1,this.destroyed=!1,kl(e);let n=Ri(r);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let i=this.blockLen,o=new Uint8Array(i);o.set(n.length>i?e.create().update(n).digest():n);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),o.fill(0)}update(e){return Ds(this),this.iHash.update(e),this}digestInto(e){Ds(this),B0(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));let{oHash:r,iHash:n,finished:i,destroyed:o,blockLen:s,outputLen:a}=this;return e=e,e.finished=i,e.destroyed=o,e.blockLen=s,e.outputLen=a,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Tc=(t,e,r)=>new $l(t,e).update(r).digest();Tc.create=(t,e)=>new $l(t,e);function q4(t,e,r,n){kl(t);let i=mv({dkLen:32,asyncTick:10},n),{c:o,dkLen:s,asyncTick:a}=i;if(Ps(o),Ps(s),Ps(a),o<1)throw new Error("PBKDF2: iterations (c) should be >= 1");let c=Ri(e),u=Ri(r),l=new Uint8Array(s),f=Tc.create(t,c),d=f._cloneInto().update(u);return{c:o,dkLen:s,asyncTick:a,DK:l,PRF:f,PRFSalt:d}}function $4(t,e,r,n,i){return t.destroy(),e.destroy(),n&&n.destroy(),i.fill(0),r}async function qn(t,e,r,n){let{c:i,dkLen:o,asyncTick:s,DK:a,PRF:c,PRFSalt:u}=q4(t,e,r,n),l,f=new Uint8Array(4),d=Ls(f),p=new Uint8Array(c.outputLen);for(let h=1,m=0;m<o;h++,m+=c.outputLen){let y=a.subarray(m,m+c.outputLen);d.setInt32(0,h,!1),(l=u._cloneInto(l)).update(f).digestInto(p),y.set(p.subarray(0,y.length)),await pv(i-1,s,()=>{c._cloneInto(l).update(p).digestInto(p);for(let g=0;g<y.length;g++)y[g]^=p[g]})}return $4(c,u,a,l,p)}var be=me(Kv());function So(t,e){let r=0;if(t.length===1)return t[0];for(let n=t.length-1;n>=0;n--)r+=t[t.length-1-n]*Math.pow(2,e*n);return r}function Di(t,e,r=-1){let n=r,i=t,o=0,s=Math.pow(2,e);for(let a=1;a<8;a++){if(t<s){let c;if(n<0)c=new ArrayBuffer(a),o=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),o=n}let u=new Uint8Array(c);for(let l=a-1;l>=0;l--){let f=Math.pow(2,l*e);u[o-l-1]=Math.floor(i/f),i-=u[o-l-1]*f}return c}s*=Math.pow(2,e)}return new ArrayBuffer(0)}function Wl(...t){let e=0,r=0;for(let o of t)e+=o.length;let n=new ArrayBuffer(e),i=new Uint8Array(n);for(let o of t)i.set(o,r),r+=o.length;return i}function Y0(){let t=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){let a=t[0]===255&&t[1]&128,c=t[0]===0&&(t[1]&128)===0;(a||c)&&this.warnings.push("Needlessly long format")}let e=new ArrayBuffer(this.valueHex.byteLength),r=new Uint8Array(e);for(let a=0;a<this.valueHex.byteLength;a++)r[a]=0;r[0]=t[0]&128;let n=So(r,8),i=new ArrayBuffer(this.valueHex.byteLength),o=new Uint8Array(i);for(let a=0;a<this.valueHex.byteLength;a++)o[a]=t[a];return o[0]&=127,So(o,8)-n}function Mv(t){let e=t<0?t*-1:t,r=128;for(let n=1;n<8;n++){if(e<=r){if(t<0){let s=r-e,a=Di(s,8,n),c=new Uint8Array(a);return c[0]|=128,a}let i=Di(e,8,n),o=new Uint8Array(i);if(o[0]&128){let s=i.slice(0),a=new Uint8Array(s);i=new ArrayBuffer(i.byteLength+1),o=new Uint8Array(i);for(let c=0;c<s.byteLength;c++)o[c+1]=a[c];o[0]=0}return i}r*=Math.pow(2,8)}return new ArrayBuffer(0)}function Fv(t,e){if(t.byteLength!==e.byteLength)return!1;let r=new Uint8Array(t),n=new Uint8Array(e);for(let i=0;i<r.length;i++)if(r[i]!==n[i])return!1;return!0}function rr(t,e){let r=t.toString(10);if(e<r.length)return"";let n=e-r.length,i=new Array(n);for(let s=0;s<n;s++)i[s]="0";return i.join("").concat(r)}var HW=Math.log(2);function Yl(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function j0(t){let e=0,r=0;for(let i=0;i<t.length;i++){let o=t[i];e+=o.byteLength}let n=new Uint8Array(e);for(let i=0;i<t.length;i++){let o=t[i];n.set(new Uint8Array(o),r),r+=o.byteLength}return n.buffer}function Wn(t,e,r,n){return e instanceof Uint8Array?e.byteLength?r<0?(t.error="Wrong parameter: inputOffset less than zero",!1):n<0?(t.error="Wrong parameter: inputLength less than zero",!1):e.byteLength-r-n<0?(t.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):!0:(t.error="Wrong parameter: inputBuffer has zero length",!1):(t.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}var Cc=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return j0(this.items)}},kc=[new Uint8Array([1])],Vv="0123456789";var Hs="",$r=new ArrayBuffer(0),Q0=new Uint8Array(0),Pc="EndOfContent",qv="OCTET STRING",$v="BIT STRING";function Yn(t){var e;return e=class extends t{constructor(...n){var i;super(...n);let o=n[0]||{};this.isHexOnly=(i=o.isHexOnly)!==null&&i!==void 0?i:!1,this.valueHexView=o.valueHex?be.BufferSourceConverter.toUint8Array(o.valueHex):Q0}get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}fromBER(n,i,o){let s=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!Wn(this,s,i,o))return-1;let a=i+o;return this.valueHexView=s.subarray(i,a),this.valueHexView.length?(this.blockLength=o,a):(this.warnings.push("Zero buffer length"),i)}toBER(n=!1){return this.isHexOnly?n?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",$r)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:be.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var zn=class{constructor({blockLength:e=0,error:r=Hs,warnings:n=[],valueBeforeDecode:i=Q0}={}){this.blockLength=e,this.error=r,this.warnings=n,this.valueBeforeDecodeView=be.BufferSourceConverter.toUint8Array(i)}static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:be.Convert.ToHex(this.valueBeforeDecodeView)}}};zn.NAME="baseBlock";var Ht=class extends zn{fromBER(e,r,n){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(e,r){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}};Ht.NAME="valueBlock";var jl=class extends Yn(zn){constructor({idBlock:e={}}={}){var r,n,i,o;super(),e?(this.isHexOnly=(r=e.isHexOnly)!==null&&r!==void 0?r:!1,this.valueHexView=e.valueHex?be.BufferSourceConverter.toUint8Array(e.valueHex):Q0,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(i=e.tagNumber)!==null&&i!==void 0?i:-1,this.isConstructed=(o=e.isConstructed)!==null&&o!==void 0?o:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let r=0;switch(this.tagClass){case 1:r|=0;break;case 2:r|=64;break;case 3:r|=128;break;case 4:r|=192;break;default:return this.error="Unknown tag class",$r}if(this.isConstructed&&(r|=32),this.tagNumber<31&&!this.isHexOnly){let i=new Uint8Array(1);if(!e){let o=this.tagNumber;o&=31,r|=o,i[0]=r}return i.buffer}if(!this.isHexOnly){let i=Di(this.tagNumber,7),o=new Uint8Array(i),s=i.byteLength,a=new Uint8Array(s+1);if(a[0]=r|31,!e){for(let c=0;c<s-1;c++)a[c+1]=o[c]|128;a[s]=o[s-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=r|31,!e){let i=this.valueHexView;for(let o=0;o<i.length-1;o++)n[o+1]=i[o]|128;n[this.valueHexView.byteLength]=i[i.length-1]}return n.buffer}fromBER(e,r,n){let i=be.BufferSourceConverter.toUint8Array(e);if(!Wn(this,i,r,n))return-1;let o=i.subarray(r,r+n);if(o.length===0)return this.error="Zero buffer length",-1;switch(o[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(o[0]&32)===32,this.isHexOnly=!1;let a=o[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,u=this.valueHexView=new Uint8Array(255),l=255;for(;o[c]&128;){if(u[c-1]=o[c]&127,c++,c>=o.length)return this.error="End of input reached before message was fully decoded",-1;if(c===l){l+=255;let d=new Uint8Array(l);for(let p=0;p<u.length;p++)d[p]=u[p];u=this.valueHexView=new Uint8Array(l)}}this.blockLength=c+1,u[c-1]=o[c]&127;let f=new Uint8Array(c);for(let d=0;d<c;d++)f[d]=u[d];u=this.valueHexView=new Uint8Array(c),u.set(f),this.blockLength<=9?this.tagNumber=So(u,7):(this.isHexOnly=!0,this.warnings.push("Tag too long, represented as hex-coded"))}if(this.tagClass===1&&this.isConstructed)switch(this.tagNumber){case 1:case 2:case 5:case 6:case 9:case 13:case 14:case 23:case 24:case 31:case 32:case 33:case 34:return this.error="Constructed encoding used for primitive type",-1}return r+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}};jl.NAME="identificationBlock";var Ql=class extends zn{constructor({lenBlock:e={}}={}){var r,n,i;super(),this.isIndefiniteForm=(r=e.isIndefiniteForm)!==null&&r!==void 0?r:!1,this.longFormUsed=(n=e.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(i=e.length)!==null&&i!==void 0?i:0}fromBER(e,r,n){let i=be.BufferSourceConverter.toUint8Array(e);if(!Wn(this,i,r,n))return-1;let o=i.subarray(r,r+n);if(o.length===0)return this.error="Zero buffer length",-1;if(o[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=o[0]===128,this.isIndefiniteForm)return this.blockLength=1,r+this.blockLength;if(this.longFormUsed=!!(o[0]&128),this.longFormUsed===!1)return this.length=o[0],this.blockLength=1,r+this.blockLength;let s=o[0]&127;if(s>8)return this.error="Too big integer",-1;if(s+1>o.length)return this.error="End of input reached before message was fully decoded",-1;let a=r+1,c=i.subarray(a,a+s);return c[s-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=So(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=s+1,r+this.blockLength}toBER(e=!1){let r,n;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return r=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(r),n[0]=128),r;if(this.longFormUsed){let i=Di(this.length,8);if(i.byteLength>127)return this.error="Too big length",$r;if(r=new ArrayBuffer(i.byteLength+1),e)return r;let o=new Uint8Array(i);n=new Uint8Array(r),n[0]=i.byteLength|128;for(let s=0;s<i.byteLength;s++)n[s+1]=o[s];return r}return r=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(r),n[0]=this.length),r}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};Ql.NAME="lengthBlock";var j={},Tt=class extends zn{constructor({name:e=Hs,optional:r=!1,primitiveSchema:n,...i}={},o){super(i),this.name=e,this.optional=r,n&&(this.primitiveSchema=n),this.idBlock=new jl(i),this.lenBlock=new Ql(i),this.valueBlock=o?new o(i):new Ht(i)}fromBER(e,r,n){let i=this.valueBlock.fromBER(e,r,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return i===-1?(this.error=this.valueBlock.error,i):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),i)}toBER(e,r){let n=r||new Cc;r||zv(this);let i=this.idBlock.toBER(e);if(n.write(i),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,n),n.write(new ArrayBuffer(2));else{let o=this.valueBlock.toBER(e);this.lenBlock.length=o.byteLength;let s=this.lenBlock.toBER(e);n.write(s),n.write(o)}return r?$r:n.final()}toJSON(){let e={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(e.primitiveSchema=this.primitiveSchema.toJSON()),e}toString(e="ascii"){return e==="ascii"?this.onAsciiEncoding():be.Convert.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${be.Convert.ToHex(this.valueBlock.valueBeforeDecodeView)}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;let r=this.toBER(),n=e.toBER();return Fv(r,n)}};Tt.NAME="BaseBlock";function zv(t){if(t instanceof j.Constructed)for(let e of t.valueBlock.value)zv(e)&&(t.lenBlock.isIndefiniteForm=!0);return!!t.lenBlock.isIndefiniteForm}var Jl=class extends Tt{constructor({value:e=Hs,...r}={},n){super(r,n),e&&this.fromString(e)}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}fromBER(e,r,n){let i=this.valueBlock.fromBER(e,r,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return i===-1?(this.error=this.valueBlock.error,i):(this.fromBuffer(this.valueBlock.valueHexView),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),i)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};Jl.NAME="BaseStringBlock";var Xl=class extends Yn(Ht){constructor({isHexOnly:e=!0,...r}={}){super(r),this.isHexOnly=e}};Xl.NAME="PrimitiveValueBlock";var Gv,Zl=class extends Tt{constructor(e={}){super(e,Xl),this.idBlock.isConstructed=!1}};Gv=Zl;j.Primitive=Gv;Zl.NAME="PRIMITIVE";function Z4(t,e){if(t instanceof e)return t;let r=new e;return r.idBlock=t.idBlock,r.lenBlock=t.lenBlock,r.warnings=t.warnings,r.valueBeforeDecodeView=t.valueBeforeDecodeView,r}function Df(t,e=0,r=t.length){let n=e,i=new Tt({},Ht),o=new zn;if(!Wn(o,t,e,r))return i.error=o.error,{offset:-1,result:i};if(!t.subarray(e,e+r).length)return i.error="Zero buffer length",{offset:-1,result:i};let a=i.idBlock.fromBER(t,e,r);if(i.idBlock.warnings.length&&i.warnings.concat(i.idBlock.warnings),a===-1)return i.error=i.idBlock.error,{offset:-1,result:i};if(e=a,r-=i.idBlock.blockLength,a=i.lenBlock.fromBER(t,e,r),i.lenBlock.warnings.length&&i.warnings.concat(i.lenBlock.warnings),a===-1)return i.error=i.lenBlock.error,{offset:-1,result:i};if(e=a,r-=i.lenBlock.blockLength,!i.idBlock.isConstructed&&i.lenBlock.isIndefiniteForm)return i.error="Indefinite length form used for primitive encoding form",{offset:-1,result:i};let c=Tt;switch(i.idBlock.tagClass){case 1:if(i.idBlock.tagNumber>=37&&i.idBlock.isHexOnly===!1)return i.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:i};switch(i.idBlock.tagNumber){case 0:if(i.idBlock.isConstructed&&i.lenBlock.length>0)return i.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:i};c=j.EndOfContent;break;case 1:c=j.Boolean;break;case 2:c=j.Integer;break;case 3:c=j.BitString;break;case 4:c=j.OctetString;break;case 5:c=j.Null;break;case 6:c=j.ObjectIdentifier;break;case 10:c=j.Enumerated;break;case 12:c=j.Utf8String;break;case 13:c=j.RelativeObjectIdentifier;break;case 14:c=j.TIME;break;case 15:return i.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:i};case 16:c=j.Sequence;break;case 17:c=j.Set;break;case 18:c=j.NumericString;break;case 19:c=j.PrintableString;break;case 20:c=j.TeletexString;break;case 21:c=j.VideotexString;break;case 22:c=j.IA5String;break;case 23:c=j.UTCTime;break;case 24:c=j.GeneralizedTime;break;case 25:c=j.GraphicString;break;case 26:c=j.VisibleString;break;case 27:c=j.GeneralString;break;case 28:c=j.UniversalString;break;case 29:c=j.CharacterString;break;case 30:c=j.BmpString;break;case 31:c=j.DATE;break;case 32:c=j.TimeOfDay;break;case 33:c=j.DateTime;break;case 34:c=j.Duration;break;default:{let u=i.idBlock.isConstructed?new j.Constructed:new j.Primitive;u.idBlock=i.idBlock,u.lenBlock=i.lenBlock,u.warnings=i.warnings,i=u}}break;case 2:case 3:case 4:default:c=i.idBlock.isConstructed?j.Constructed:j.Primitive}return i=Z4(i,c),a=i.fromBER(t,e,i.lenBlock.isIndefiniteForm?r:i.lenBlock.length),i.valueBeforeDecodeView=t.subarray(n,n+i.blockLength),{offset:a,result:i}}function xt(t){if(!t.byteLength){let e=new Tt({},Ht);return e.error="Input buffer has zero length",{offset:-1,result:e}}return Df(be.BufferSourceConverter.toUint8Array(t).slice(),0,t.byteLength)}function e6(t,e){return t?1:e}var rn=class extends Ht{constructor({value:e=[],isIndefiniteForm:r=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=r}fromBER(e,r,n){let i=be.BufferSourceConverter.toUint8Array(e);if(!Wn(this,i,r,n))return-1;if(this.valueBeforeDecodeView=i.subarray(r,r+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),r;let o=r;for(;e6(this.isIndefiniteForm,n)>0;){let s=Df(i,o,n);if(s.offset===-1)return this.error=s.result.error,this.warnings.concat(s.result.warnings),-1;if(o=s.offset,this.blockLength+=s.result.blockLength,n-=s.result.blockLength,this.value.push(s.result),this.isIndefiniteForm&&s.result.constructor.NAME===Pc)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===Pc?this.value.pop():this.warnings.push("No EndOfContent block encoded")),o}toBER(e,r){let n=r||new Cc;for(let i=0;i<this.value.length;i++)this.value[i].toBER(e,n);return r?$r:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let r of this.value)e.value.push(r.toJSON());return e}};rn.NAME="ConstructedValueBlock";var Wv,Ni=class extends Tt{constructor(e={}){super(e,rn),this.idBlock.isConstructed=!0}fromBER(e,r,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let i=this.valueBlock.fromBER(e,r,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return i===-1?(this.error=this.valueBlock.error,i):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),i)}onAsciiEncoding(){let e=[];for(let n of this.valueBlock.value)e.push(n.toString("ascii").split(`
|
|
17
|
+
`).map(i=>` ${i}`).join(`
|
|
18
|
+
`));let r=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return e.length?`${r} :
|
|
19
|
+
${e.join(`
|
|
20
|
+
`)}`:`${r} :`}};Wv=Ni;j.Constructed=Wv;Ni.NAME="CONSTRUCTED";var ef=class extends Ht{fromBER(e,r,n){return r}toBER(e){return $r}};ef.override="EndOfContentValueBlock";var Yv,tf=class extends Tt{constructor(e={}){super(e,ef),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};Yv=tf;j.EndOfContent=Yv;tf.NAME=Pc;var jv,qt=class extends Tt{constructor(e={}){super(e,Ht),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,r,n){return this.lenBlock.length>0&&this.warnings.push("Non-zero length of value block for Null type"),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.blockLength+=n,r+n>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):r+n}toBER(e,r){let n=new ArrayBuffer(2);if(!e){let i=new Uint8Array(n);i[0]=5,i[1]=0}return r&&r.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};jv=qt;j.Null=jv;qt.NAME="NULL";var rf=class extends Yn(Ht){constructor({value:e,...r}={}){super(r),r.valueHex?this.valueHexView=be.BufferSourceConverter.toUint8Array(r.valueHex):this.valueHexView=new Uint8Array(1),e&&(this.value=e)}get value(){for(let e of this.valueHexView)if(e>0)return!0;return!1}set value(e){this.valueHexView[0]=e?255:0}fromBER(e,r,n){let i=be.BufferSourceConverter.toUint8Array(e);return Wn(this,i,r,n)?(this.valueHexView=i.subarray(r,r+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,Y0.call(this),this.blockLength=n,r+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};rf.NAME="BooleanValueBlock";var Qv,nf=class extends Tt{constructor(e={}){super(e,rf),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};Qv=nf;j.Boolean=Qv;nf.NAME="BOOLEAN";var of=class extends Yn(rn){constructor({isConstructed:e=!1,...r}={}){super(r),this.isConstructed=e}fromBER(e,r,n){let i=0;if(this.isConstructed){if(this.isHexOnly=!1,i=rn.prototype.fromBER.call(this,e,r,n),i===-1)return i;for(let o=0;o<this.value.length;o++){let s=this.value[o].constructor.NAME;if(s===Pc){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(s!==qv)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,i=super.fromBER(e,r,n),this.blockLength=n;return i}toBER(e,r){return this.isConstructed?rn.prototype.toBER.call(this,e,r):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};of.NAME="OctetStringValueBlock";var Jv,yt=class t extends Tt{constructor({idBlock:e={},lenBlock:r={},...n}={}){var i,o;(i=n.isConstructed)!==null&&i!==void 0||(n.isConstructed=!!(!((o=n.value)===null||o===void 0)&&o.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...r,isIndefiniteForm:!!n.isIndefiniteForm},...n},of),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,r,n){if(this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,n===0)return this.idBlock.error.length===0&&(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length===0&&(this.blockLength+=this.lenBlock.blockLength),r;if(!this.valueBlock.isConstructed){let o=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(r,r+n);try{if(o.byteLength){let s=Df(o,0,o.byteLength);s.offset!==-1&&s.offset===n&&(this.valueBlock.value=[s.result])}}catch{}}return super.fromBER(e,r,n)}onAsciiEncoding(){return this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length?Ni.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${be.Convert.ToHex(this.valueBlock.valueHexView)}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let e=[];for(let r of this.valueBlock.value)r instanceof t&&e.push(r.valueBlock.valueHexView);return be.BufferSourceConverter.concat(e)}};Jv=yt;j.OctetString=Jv;yt.NAME=qv;var sf=class extends Yn(rn){constructor({unusedBits:e=0,isConstructed:r=!1,...n}={}){super(n),this.unusedBits=e,this.isConstructed=r,this.blockLength=this.valueHexView.byteLength}fromBER(e,r,n){if(!n)return r;let i=-1;if(this.isConstructed){if(i=rn.prototype.fromBER.call(this,e,r,n),i===-1)return i;for(let a of this.value){let c=a.constructor.NAME;if(c===Pc){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==$v)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let u=a.valueBlock;if(this.unusedBits>0&&u.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=u.unusedBits}return i}let o=be.BufferSourceConverter.toUint8Array(e);if(!Wn(this,o,r,n))return-1;let s=o.subarray(r,r+n);if(this.unusedBits=s[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let a=s.subarray(1);try{if(a.byteLength){let c=Df(a,0,a.byteLength);c.offset!==-1&&c.offset===n-1&&(this.value=[c.result])}}catch{}}return this.valueHexView=s.subarray(1),this.blockLength=s.length,r+n}toBER(e,r){if(this.isConstructed)return rn.prototype.toBER.call(this,e,r);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return $r;let n=new Uint8Array(this.valueHexView.length+1);return n[0]=this.unusedBits,n.set(this.valueHexView,1),n.buffer}toJSON(){return{...super.toJSON(),unusedBits:this.unusedBits,isConstructed:this.isConstructed}}};sf.NAME="BitStringValueBlock";var Xv,nn=class extends Tt{constructor({idBlock:e={},lenBlock:r={},...n}={}){var i,o;(i=n.isConstructed)!==null&&i!==void 0||(n.isConstructed=!!(!((o=n.value)===null||o===void 0)&&o.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...r,isIndefiniteForm:!!n.isIndefiniteForm},...n},sf),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(e,r,n){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(e,r,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return Ni.prototype.onAsciiEncoding.call(this);{let e=[],r=this.valueBlock.valueHexView;for(let i of r)e.push(i.toString(2).padStart(8,"0"));let n=e.join("");return`${this.constructor.NAME} : ${n.substring(0,n.length-this.valueBlock.unusedBits)}`}}};Xv=nn;j.BitString=Xv;nn.NAME=$v;var Zv;function t6(t,e){let r=new Uint8Array([0]),n=new Uint8Array(t),i=new Uint8Array(e),o=n.slice(0),s=o.length-1,a=i.slice(0),c=a.length-1,u=0,l=c<s?s:c,f=0;for(let d=l;d>=0;d--,f++){switch(!0){case f<a.length:u=o[s-f]+a[c-f]+r[0];break;default:u=o[s-f]+r[0]}switch(r[0]=u/10,!0){case f>=o.length:o=Wl(new Uint8Array([u%10]),o);break;default:o[s-f]=u%10}}return r[0]>0&&(o=Wl(r,o)),o}function Hv(t){if(t>=kc.length)for(let e=kc.length;e<=t;e++){let r=new Uint8Array([0]),n=kc[e-1].slice(0);for(let i=n.length-1;i>=0;i--){let o=new Uint8Array([(n[i]<<1)+r[0]]);r[0]=o[0]/10,n[i]=o[0]%10}r[0]>0&&(n=Wl(r,n)),kc.push(n)}return kc[t]}function r6(t,e){let r=0,n=new Uint8Array(t),i=new Uint8Array(e),o=n.slice(0),s=o.length-1,a=i.slice(0),c=a.length-1,u,l=0;for(let f=c;f>=0;f--,l++)switch(u=o[s-l]-a[c-l]-r,!0){case u<0:r=1,o[s-l]=u+10;break;default:r=0,o[s-l]=u}if(r>0)for(let f=s-c+1;f>=0;f--,l++)if(u=o[s-l]-r,u<0)r=1,o[s-l]=u+10;else{r=0,o[s-l]=u;break}return o.slice()}var Dc=class extends Yn(Ht){constructor({value:e,...r}={}){super(r),this._valueDec=0,r.valueHex&&this.setValueHex(),e!==void 0&&(this.valueDec=e)}setValueHex(){this.valueHexView.length>=4?(this.warnings.push("Too big Integer for decoding, hex only"),this.isHexOnly=!0,this._valueDec=0):(this.isHexOnly=!1,this.valueHexView.length>0&&(this._valueDec=Y0.call(this)))}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(Mv(e))}get valueDec(){return this._valueDec}fromDER(e,r,n,i=0){let o=this.fromBER(e,r,n);if(o===-1)return o;let s=this.valueHexView;return s[0]===0&&s[1]&128?this.valueHexView=s.subarray(1):i!==0&&s.length<i&&(i-s.length>1&&(i=s.length+1),this.valueHexView=s.subarray(i-s.length)),o}toDER(e=!1){let r=this.valueHexView;switch(!0){case(r[0]&128)!==0:{let n=new Uint8Array(this.valueHexView.length+1);n[0]=0,n.set(r,1),this.valueHexView=n}break;case(r[0]===0&&(r[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(e)}fromBER(e,r,n){let i=super.fromBER(e,r,n);return i===-1||this.setValueHex(),i}toBER(e){return e?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){let e=this.valueHexView.length*8-1,r=new Uint8Array(this.valueHexView.length*8/3),n=0,i,o=this.valueHexView,s="",a=!1;for(let c=o.byteLength-1;c>=0;c--){i=o[c];for(let u=0;u<8;u++){if((i&1)===1)switch(n){case e:r=r6(Hv(n),r),s="-";break;default:r=t6(r,Hv(n))}n++,i>>=1}}for(let c=0;c<r.length;c++)r[c]&&(a=!0),a&&(s+=Vv.charAt(r[c]));return a===!1&&(s+=Vv.charAt(0)),s}};Zv=Dc;Dc.NAME="IntegerValueBlock";Object.defineProperty(Zv.prototype,"valueHex",{set:function(t){this.valueHexView=new Uint8Array(t),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var eE,ne=class t extends Tt{constructor(e={}){super(e,Dc),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return Yl(),BigInt(this.valueBlock.toString())}static fromBigInt(e){Yl();let r=BigInt(e),n=new Cc,i=r.toString(16).replace(/^-/,""),o=new Uint8Array(be.Convert.FromHex(i));if(r<0){let a=new Uint8Array(o.length+(o[0]&128?1:0));a[0]|=128;let u=BigInt(`0x${be.Convert.ToHex(a)}`)+r,l=be.BufferSourceConverter.toUint8Array(be.Convert.FromHex(u.toString(16)));l[0]|=128,n.write(l)}else o[0]&128&&n.write(new Uint8Array([0])),n.write(o);return new t({valueHex:n.final()})}convertToDER(){let e=new t({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new t({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}};eE=ne;j.Integer=eE;ne.NAME="INTEGER";var tE,af=class extends ne{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};tE=af;j.Enumerated=tE;af.NAME="ENUMERATED";var Nc=class extends Yn(Ht){constructor({valueDec:e=-1,isFirstSid:r=!1,...n}={}){super(n),this.valueDec=e,this.isFirstSid=r}fromBER(e,r,n){if(!n)return r;let i=be.BufferSourceConverter.toUint8Array(e);if(!Wn(this,i,r,n))return-1;let o=i.subarray(r,r+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=o[a]&127,this.blockLength++,!!(o[a]&128));a++);let s=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)s[a]=this.valueHexView[a];return this.valueHexView=s,o[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=So(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),r+this.blockLength)}set valueBigInt(e){Yl();let r=BigInt(e).toString(2);for(;r.length%7;)r="0"+r;let n=new Uint8Array(r.length/7);for(let i=0;i<n.length;i++)n[i]=parseInt(r.slice(i*7,i*7+7),2)+(i+1<n.length?128:0);this.fromBER(n.buffer,0,n.length)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let i=this.valueHexView,o=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)o[s]=i[s]|128;return o[this.blockLength-1]=i[this.blockLength-1],o.buffer}let r=Di(this.valueDec,7);if(r.byteLength===0)return this.error="Error during encoding SID value",$r;let n=new Uint8Array(r.byteLength);if(!e){let i=new Uint8Array(r),o=r.byteLength-1;for(let s=0;s<o;s++)n[s]=i[s]|128;n[o]=i[o]}return n}toString(){let e="";if(this.isHexOnly)e=be.Convert.ToHex(this.valueHexView);else if(this.isFirstSid){let r=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",r-=40):(e="2.",r-=80),e+=r.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}};Nc.NAME="sidBlock";var cf=class extends Ht{constructor({value:e=Hs,...r}={}){super(r),this.value=[],e&&this.fromString(e)}fromBER(e,r,n){let i=r;for(;n>0;){let o=new Nc;if(i=o.fromBER(e,i,n),i===-1)return this.blockLength=0,this.error=o.error,i;this.value.length===0&&(o.isFirstSid=!0),this.blockLength+=o.blockLength,n-=o.blockLength,this.value.push(o)}return i}toBER(e){let r=[];for(let n=0;n<this.value.length;n++){let i=this.value[n].toBER(e);if(i.byteLength===0)return this.error=this.value[n].error,$r;r.push(i)}return j0(r)}fromString(e){this.value=[];let r=0,n=0,i="",o=!1;do if(n=e.indexOf(".",r),n===-1?i=e.substring(r):i=e.substring(r,n),r=n+1,o){let s=this.value[0],a=0;switch(s.valueDec){case 0:break;case 1:a=40;break;case 2:a=80;break;default:this.value=[];return}let c=parseInt(i,10);if(isNaN(c))return;s.valueDec=c+a,o=!1}else{let s=new Nc;if(i>Number.MAX_SAFE_INTEGER){Yl();let a=BigInt(i);s.valueBigInt=a}else if(s.valueDec=parseInt(i,10),isNaN(s.valueDec))return;this.value.length||(s.isFirstSid=!0,o=!0),this.value.push(s)}while(n!==-1)}toString(){let e="",r=!1;for(let n=0;n<this.value.length;n++){r=this.value[n].isHexOnly;let i=this.value[n].toString();n!==0&&(e=`${e}.`),r?(i=`{${i}}`,this.value[n].isFirstSid?e=`2.{${i} - 80}`:e+=i):e+=i}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let r=0;r<this.value.length;r++)e.sidArray.push(this.value[r].toJSON());return e}};cf.NAME="ObjectIdentifierValueBlock";var rE,Ve=class extends Tt{constructor(e={}){super(e,cf),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};rE=Ve;j.ObjectIdentifier=rE;Ve.NAME="OBJECT IDENTIFIER";var Lc=class extends Yn(zn){constructor({valueDec:e=0,...r}={}){super(r),this.valueDec=e}fromBER(e,r,n){if(n===0)return r;let i=be.BufferSourceConverter.toUint8Array(e);if(!Wn(this,i,r,n))return-1;let o=i.subarray(r,r+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=o[a]&127,this.blockLength++,!!(o[a]&128));a++);let s=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)s[a]=this.valueHexView[a];return this.valueHexView=s,o[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=So(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),r+this.blockLength)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let i=this.valueHexView,o=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)o[s]=i[s]|128;return o[this.blockLength-1]=i[this.blockLength-1],o.buffer}let r=Di(this.valueDec,7);if(r.byteLength===0)return this.error="Error during encoding SID value",$r;let n=new Uint8Array(r.byteLength);if(!e){let i=new Uint8Array(r),o=r.byteLength-1;for(let s=0;s<o;s++)n[s]=i[s]|128;n[o]=i[o]}return n.buffer}toString(){let e="";return this.isHexOnly?e=be.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};Lc.NAME="relativeSidBlock";var uf=class extends Ht{constructor({value:e=Hs,...r}={}){super(r),this.value=[],e&&this.fromString(e)}fromBER(e,r,n){let i=r;for(;n>0;){let o=new Lc;if(i=o.fromBER(e,i,n),i===-1)return this.blockLength=0,this.error=o.error,i;this.blockLength+=o.blockLength,n-=o.blockLength,this.value.push(o)}return i}toBER(e,r){let n=[];for(let i=0;i<this.value.length;i++){let o=this.value[i].toBER(e);if(o.byteLength===0)return this.error=this.value[i].error,$r;n.push(o)}return j0(n)}fromString(e){this.value=[];let r=0,n=0,i="";do{n=e.indexOf(".",r),n===-1?i=e.substring(r):i=e.substring(r,n),r=n+1;let o=new Lc;if(o.valueDec=parseInt(i,10),isNaN(o.valueDec))return!0;this.value.push(o)}while(n!==-1);return!0}toString(){let e="",r=!1;for(let n=0;n<this.value.length;n++){r=this.value[n].isHexOnly;let i=this.value[n].toString();n!==0&&(e=`${e}.`),r&&(i=`{${i}}`),e+=i}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let r=0;r<this.value.length;r++)e.sidArray.push(this.value[r].toJSON());return e}};uf.NAME="RelativeObjectIdentifierValueBlock";var nE,lf=class extends Tt{constructor(e={}){super(e,uf),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}getValue(){return this.valueBlock.toString()}setValue(e){this.valueBlock.fromString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};nE=lf;j.RelativeObjectIdentifier=nE;lf.NAME="RelativeObjectIdentifier";var iE,se=class extends Ni{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};iE=se;j.Sequence=iE;se.NAME="SEQUENCE";var oE,ff=class extends Ni{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};oE=ff;j.Set=oE;ff.NAME="SET";var hf=class extends Yn(Ht){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=Hs}toJSON(){return{...super.toJSON(),value:this.value}}};hf.NAME="StringValueBlock";var df=class extends hf{};df.NAME="SimpleStringValueBlock";var Gt=class extends Jl{constructor({...e}={}){super(e,df)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,be.BufferSourceConverter.toUint8Array(e))}fromString(e){let r=e.length,n=this.valueBlock.valueHexView=new Uint8Array(r);for(let i=0;i<r;i++)n[i]=e.charCodeAt(i);this.valueBlock.value=e}};Gt.NAME="SIMPLE STRING";var pf=class extends Gt{fromBuffer(e){this.valueBlock.valueHexView=be.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=be.Convert.ToUtf8String(e)}catch(r){this.warnings.push(`Error during "decodeURIComponent": ${r}, using raw string`),this.valueBlock.value=be.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(be.Convert.FromUtf8String(e)),this.valueBlock.value=e}};pf.NAME="Utf8StringValueBlock";var sE,Gn=class extends pf{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};sE=Gn;j.Utf8String=sE;Gn.NAME="UTF8String";var mf=class extends Gt{fromBuffer(e){this.valueBlock.value=be.Convert.ToUtf16String(e),this.valueBlock.valueHexView=be.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(be.Convert.FromUtf16String(e))}};mf.NAME="BmpStringValueBlock";var aE,yf=class extends mf{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};aE=yf;j.BmpString=aE;yf.NAME="BMPString";var gf=class extends Gt{fromBuffer(e){let r=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),n=new Uint8Array(r);for(let i=0;i<n.length;i+=4)n[i]=n[i+3],n[i+1]=n[i+2],n[i+2]=0,n[i+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(r))}fromString(e){let r=e.length,n=this.valueBlock.valueHexView=new Uint8Array(r*4);for(let i=0;i<r;i++){let o=Di(e.charCodeAt(i),8),s=new Uint8Array(o);if(s.length>4)continue;let a=4-s.length;for(let c=s.length-1;c>=0;c--)n[i*4+c+a]=s[c]}this.valueBlock.value=e}};gf.NAME="UniversalStringValueBlock";var cE,bf=class extends gf{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};cE=bf;j.UniversalString=cE;bf.NAME="UniversalString";var uE,wf=class extends Gt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};uE=wf;j.NumericString=uE;wf.NAME="NumericString";var lE,xf=class extends Gt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};lE=xf;j.PrintableString=lE;xf.NAME="PrintableString";var fE,vf=class extends Gt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};fE=vf;j.TeletexString=fE;vf.NAME="TeletexString";var hE,Ef=class extends Gt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};hE=Ef;j.VideotexString=hE;Ef.NAME="VideotexString";var dE,Af=class extends Gt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};dE=Af;j.IA5String=dE;Af.NAME="IA5String";var pE,Sf=class extends Gt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};pE=Sf;j.GraphicString=pE;Sf.NAME="GraphicString";var mE,Oc=class extends Gt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};mE=Oc;j.VisibleString=mE;Oc.NAME="VisibleString";var yE,_f=class extends Gt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};yE=_f;j.GeneralString=yE;_f.NAME="GeneralString";var gE,If=class extends Gt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};gE=If;j.CharacterString=gE;If.NAME="CharacterString";var bE,Uc=class extends Oc{constructor({value:e,valueDate:r,...n}={}){if(super(n),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,e){this.fromString(e),this.valueBlock.valueHexView=new Uint8Array(e.length);for(let i=0;i<e.length;i++)this.valueBlock.valueHexView[i]=e.charCodeAt(i)}r&&(this.fromDate(r),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,be.BufferSourceConverter.toUint8Array(e)))}toBuffer(){let e=this.toString(),r=new ArrayBuffer(e.length),n=new Uint8Array(r);for(let i=0;i<e.length;i++)n[i]=e.charCodeAt(i);return r}fromDate(e){this.year=e.getUTCFullYear(),this.month=e.getUTCMonth()+1,this.day=e.getUTCDate(),this.hour=e.getUTCHours(),this.minute=e.getUTCMinutes(),this.second=e.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(e){let n=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(e);if(n===null){this.error="Wrong input string for conversion";return}let i=parseInt(n[1],10);i>=50?this.year=1900+i:this.year=2e3+i,this.month=parseInt(n[2],10),this.day=parseInt(n[3],10),this.hour=parseInt(n[4],10),this.minute=parseInt(n[5],10),this.second=parseInt(n[6],10)}toString(e="iso"){if(e==="iso"){let r=new Array(7);return r[0]=rr(this.year<2e3?this.year-1900:this.year-2e3,2),r[1]=rr(this.month,2),r[2]=rr(this.day,2),r[3]=rr(this.hour,2),r[4]=rr(this.minute,2),r[5]=rr(this.second,2),r[6]="Z",r.join("")}return super.toString(e)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.toDate().toISOString()}`}toJSON(){return{...super.toJSON(),year:this.year,month:this.month,day:this.day,hour:this.hour,minute:this.minute,second:this.second}}};bE=Uc;j.UTCTime=bE;Uc.NAME="UTCTime";var wE,Rf=class extends Uc{constructor(e={}){var r;super(e),(r=this.millisecond)!==null&&r!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(e){super.fromDate(e),this.millisecond=e.getUTCMilliseconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond))}fromString(e){let r=!1,n="",i="",o=0,s,a=0,c=0;if(e[e.length-1]==="Z")n=e.substring(0,e.length-1),r=!0;else{let f=new Number(e[e.length-1]);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");n=e}if(r){if(n.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(n.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let f=1,d=n.indexOf("+"),p="";if(d===-1&&(d=n.indexOf("-"),f=-1),d!==-1){if(p=n.substring(d+1),n=n.substring(0,d),p.length!==2&&p.length!==4)throw new Error("Wrong input string for conversion");let h=parseInt(p.substring(0,2),10);if(isNaN(h.valueOf()))throw new Error("Wrong input string for conversion");if(a=f*h,p.length===4){if(h=parseInt(p.substring(2,4),10),isNaN(h.valueOf()))throw new Error("Wrong input string for conversion");c=f*h}}}let u=n.indexOf(".");if(u===-1&&(u=n.indexOf(",")),u!==-1){let f=new Number(`0${n.substring(u)}`);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");o=f.valueOf(),i=n.substring(0,u)}else i=n;switch(!0){case i.length===8:if(s=/(\d{4})(\d{2})(\d{2})/ig,u!==-1)throw new Error("Wrong input string for conversion");break;case i.length===10:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let f=60*o;this.minute=Math.floor(f),f=60*(f-this.minute),this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case i.length===12:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let f=60*o;this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case i.length===14:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,u!==-1){let f=1e3*o;this.millisecond=Math.floor(f)}break;default:throw new Error("Wrong input string for conversion")}let l=s.exec(i);if(l===null)throw new Error("Wrong input string for conversion");for(let f=1;f<l.length;f++)switch(f){case 1:this.year=parseInt(l[f],10);break;case 2:this.month=parseInt(l[f],10);break;case 3:this.day=parseInt(l[f],10);break;case 4:this.hour=parseInt(l[f],10)+a;break;case 5:this.minute=parseInt(l[f],10)+c;break;case 6:this.second=parseInt(l[f],10);break;default:throw new Error("Wrong input string for conversion")}if(r===!1){let f=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=f.getUTCFullYear(),this.month=f.getUTCMonth(),this.day=f.getUTCDay(),this.hour=f.getUTCHours(),this.minute=f.getUTCMinutes(),this.second=f.getUTCSeconds(),this.millisecond=f.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){let r=[];return r.push(rr(this.year,4)),r.push(rr(this.month,2)),r.push(rr(this.day,2)),r.push(rr(this.hour,2)),r.push(rr(this.minute,2)),r.push(rr(this.second,2)),this.millisecond!==0&&(r.push("."),r.push(rr(this.millisecond,3))),r.push("Z"),r.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};wE=Rf;j.GeneralizedTime=wE;Rf.NAME="GeneralizedTime";var xE,Bf=class extends Gn{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};xE=Bf;j.DATE=xE;Bf.NAME="DATE";var vE,Tf=class extends Gn{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};vE=Tf;j.TimeOfDay=vE;Tf.NAME="TimeOfDay";var EE,kf=class extends Gn{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};EE=kf;j.DateTime=EE;kf.NAME="DateTime";var AE,Cf=class extends Gn{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};AE=Cf;j.Duration=AE;Cf.NAME="Duration";var SE,Pf=class extends Gn{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};SE=Pf;j.TIME=SE;Pf.NAME="TIME";function n6(t){let{result:e}=xt(t),r=e.valueBlock.value;return{n:z(on(r[1].toBigInt()),"base64url"),e:z(on(r[2].toBigInt()),"base64url"),d:z(on(r[3].toBigInt()),"base64url"),p:z(on(r[4].toBigInt()),"base64url"),q:z(on(r[5].toBigInt()),"base64url"),dp:z(on(r[6].toBigInt()),"base64url"),dq:z(on(r[7].toBigInt()),"base64url"),qi:z(on(r[8].toBigInt()),"base64url"),kty:"RSA",alg:"RS256"}}function i6(t){if(t.n==null||t.e==null||t.d==null||t.p==null||t.q==null||t.dp==null||t.dq==null||t.qi==null)throw new x("JWK was missing components","ERR_INVALID_PARAMETERS");let r=new se({value:[new ne({value:0}),ne.fromBigInt(sn(U(t.n,"base64url"))),ne.fromBigInt(sn(U(t.e,"base64url"))),ne.fromBigInt(sn(U(t.d,"base64url"))),ne.fromBigInt(sn(U(t.p,"base64url"))),ne.fromBigInt(sn(U(t.q,"base64url"))),ne.fromBigInt(sn(U(t.dp,"base64url"))),ne.fromBigInt(sn(U(t.dq,"base64url"))),ne.fromBigInt(sn(U(t.qi,"base64url")))]}).toBER();return new Uint8Array(r,0,r.byteLength)}function o6(t){let{result:e}=xt(t),r=e.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:z(on(r[0].toBigInt()),"base64url"),e:z(on(r[1].toBigInt()),"base64url")}}function s6(t){if(t.n==null||t.e==null)throw new x("JWK was missing components","ERR_INVALID_PARAMETERS");let r=new se({value:[new se({value:[new Ve({value:"1.2.840.113549.1.1.1"}),new qt]}),new nn({valueHex:new se({value:[ne.fromBigInt(sn(U(t.n,"base64url"))),ne.fromBigInt(sn(U(t.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(r,0,r.byteLength)}function on(t){let e=t.toString(16);e.length%2>0&&(e=`0${e}`);let r=e.length/2,n=new Uint8Array(r),i=0,o=0;for(;i<r;)n[i]=parseInt(e.slice(o,o+2),16),i+=1,o+=2;return n}function sn(t){let e=[];return t.forEach(function(r){let n=r.toString(16);n.length%2>0&&(n=`0${n}`),e.push(n)}),BigInt("0x"+e.join(""))}var a6=16,X0=32,Z0=1e4;async function c6(t,e){let r=Bt.get(),i=new se({value:[new ne({value:0}),new se({value:[new Ve({value:"1.2.840.113549.1.1.1"}),new qt]}),new yt({valueHex:t.marshal()})]}).toBER(),o=new Uint8Array(i,0,i.byteLength),s=Ao(a6),a=await qn(Ir,e,s,{c:Z0,dkLen:X0}),c=Ao(16),u=await r.subtle.importKey("raw",a,"AES-CBC",!1,["encrypt"]),l=await r.subtle.encrypt({name:"AES-CBC",iv:c},u,o),f=new se({value:[new yt({valueHex:s}),new ne({value:Z0}),new ne({value:X0}),new se({value:[new Ve({value:"1.2.840.113549.2.11"}),new qt]})]}),d=new se({value:[new Ve({value:"1.2.840.113549.1.5.13"}),new se({value:[new se({value:[new Ve({value:"1.2.840.113549.1.5.12"}),f]}),new se({value:[new Ve({value:"2.16.840.1.101.3.4.1.42"}),new yt({valueHex:c})]})]})]}),h=new se({value:[d,new yt({valueHex:l})]}).toBER(),m=new Uint8Array(h,0,h.byteLength);return["-----BEGIN ENCRYPTED PRIVATE KEY-----",...z(m,"base64pad").split(/(.{64})/).filter(Boolean),"-----END ENCRYPTED PRIVATE KEY-----"].join(`
|
|
21
|
+
`)}async function IE(t,e){let r=Bt.get(),n;if(t.includes("-----BEGIN ENCRYPTED PRIVATE KEY-----")){let i=U(t.replace("-----BEGIN ENCRYPTED PRIVATE KEY-----","").replace("-----END ENCRYPTED PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:o}=xt(i),{iv:s,salt:a,iterations:c,keySize:u,cipherText:l}=u6(o),f=await qn(Ir,e,a,{c,dkLen:u}),d=await r.subtle.importKey("raw",f,"AES-CBC",!1,["decrypt"]),p=Kc(await r.subtle.decrypt({name:"AES-CBC",iv:s},d,l)),{result:h}=xt(p);n=_E(h)}else if(t.includes("-----BEGIN PRIVATE KEY-----")){let i=U(t.replace("-----BEGIN PRIVATE KEY-----","").replace("-----END PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:o}=xt(i);n=_E(o)}else throw new x("Could not parse private key from PEM data","ERR_INVALID_PARAMETERS");return em(n)}function u6(t){let e=t.valueBlock.value[0];if(e.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.13")throw new x("Only pkcs5PBES2 encrypted private keys are supported","ERR_INVALID_PARAMS");let n=e.valueBlock.value[1].valueBlock.value[0];if(n.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.12")throw new x("Only pkcs5PBKDF2 key derivation functions are supported","ERR_INVALID_PARAMS");let o=n.valueBlock.value[1],s=Kc(o.valueBlock.value[0].getValue()),a=Z0,c=X0;if(o.valueBlock.value.length===3)a=Number(o.valueBlock.value[1].toBigInt()),c=Number(o.valueBlock.value[2].toBigInt());else if(o.valueBlock.value.length===2)throw new x("Could not derive key size and iterations from PEM file - please use @libp2p/rsa to re-import your key","ERR_INVALID_PARAMS");let u=e.valueBlock.value[1].valueBlock.value[1],l=u.valueBlock.value[0].toString();if(l!=="OBJECT IDENTIFIER : 1.2.840.113549.3.7"){if(l!=="OBJECT IDENTIFIER : 1.3.14.3.2.7"){if(l!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.2"){if(l!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.22"){if(l!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.42")throw new x("Only AES-CBC encryption schemes are supported","ERR_INVALID_PARAMS")}}}}let f=Kc(u.valueBlock.value[1].getValue());return{cipherText:Kc(t.valueBlock.value[1].getValue()),salt:s,iterations:a,keySize:c,iv:f}}function _E(t){return Kc(t.valueBlock.value[2].getValue())}function Kc(t){return new Uint8Array(t,0,t.byteLength)}async function RE(t){let e=await Bt.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:t,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),r=await kE(e);return{privateKey:r[0],publicKey:r[1]}}async function tm(t){let r=[await Bt.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),await l6(t)],n=await kE({privateKey:r[0],publicKey:r[1]});return{privateKey:n[0],publicKey:n[1]}}async function BE(t,e){let r=await Bt.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await Bt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},r,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(n,0,n.byteLength)}async function TE(t,e,r){let n=await Bt.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return Bt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,e,r instanceof Uint8Array?r:r.subarray())}async function kE(t){if(t.privateKey==null||t.publicKey==null)throw new x("Private and public key are required","ERR_INVALID_PARAMETERS");return Promise.all([Bt.get().subtle.exportKey("jwk",t.privateKey),Bt.get().subtle.exportKey("jwk",t.publicKey)])}async function l6(t){return Bt.get().subtle.importKey("jwk",{kty:t.kty,n:t.n,e:t.e},{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])}function Nf(t){if(t.kty!=="RSA")throw new x("invalid key type","ERR_INVALID_KEY_TYPE");if(t.n==null)throw new x("invalid key modulus","ERR_INVALID_KEY_MODULUS");return U(t.n,"base64url").length*8}var $s=8192,qs=class{_key;constructor(e){this._key=e}verify(e,r){return TE(this._key,r,e)}marshal(){return Li.jwkToPkix(this._key)}get bytes(){return tn.encode({Type:nt.RSA,Data:this.marshal()}).subarray()}equals(e){return ie(this.bytes,e.bytes)}hash(){let e=ae.digest(this.bytes);return Sr(e)?e.then(({bytes:r})=>r):e.bytes}},_o=class{_key;_publicKey;constructor(e,r){this._key=e,this._publicKey=r}genSecret(){return Ao(16)}sign(e){return BE(this._key,e)}get public(){if(this._publicKey==null)throw new x("public key not provided","ERR_PUBKEY_NOT_PROVIDED");return new qs(this._publicKey)}marshal(){return Li.jwkToPkcs1(this._key)}get bytes(){return Hn.encode({Type:nt.RSA,Data:this.marshal()}).subarray()}equals(e){return ie(this.bytes,e.bytes)}hash(){let e=ae.digest(this.bytes);return Sr(e)?e.then(({bytes:r})=>r):e.bytes}async id(){let e=await this.public.hash();return z(e,"base58btc")}async export(e,r="pkcs-8"){if(r==="pkcs-8")return Li.exportToPem(this,e);if(r==="libp2p-key")return Ks(this.bytes,e);throw new x(`export format '${r}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};async function em(t){let e=Li.pkcs1ToJwk(t);if(Nf(e)>$s)throw new x("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let r=await tm(e);return new _o(r.privateKey,r.publicKey)}function h6(t){let e=Li.pkixToJwk(t);if(Nf(e)>$s)throw new x("key size is too large","ERR_KEY_SIZE_TOO_LARGE");return new qs(e)}async function d6(t){if(Nf(t)>$s)throw new x("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await tm(t);return new _o(e.privateKey,e.publicKey)}async function p6(t){if(t>$s)throw new x("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await RE(t);return new _o(e.privateKey,e.publicKey)}var am={};Y(am,{Secp256k1PrivateKey:()=>Gs,Secp256k1PublicKey:()=>zs,generateKeyPair:()=>T6,unmarshalSecp256k1PrivateKey:()=>R6,unmarshalSecp256k1PublicKey:()=>B6});var m6=(t,e,r)=>t&e^~t&r,y6=(t,e,r)=>t&e^t&r^e&r,g6=new Uint32Array([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]),Oi=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Ui=new Uint32Array(64),nm=class extends Os{constructor(){super(64,32,8,!1),this.A=Oi[0]|0,this.B=Oi[1]|0,this.C=Oi[2]|0,this.D=Oi[3]|0,this.E=Oi[4]|0,this.F=Oi[5]|0,this.G=Oi[6]|0,this.H=Oi[7]|0}get(){let{A:e,B:r,C:n,D:i,E:o,F:s,G:a,H:c}=this;return[e,r,n,i,o,s,a,c]}set(e,r,n,i,o,s,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=o|0,this.F=s|0,this.G=a|0,this.H=c|0}process(e,r){for(let f=0;f<16;f++,r+=4)Ui[f]=e.getUint32(r,!1);for(let f=16;f<64;f++){let d=Ui[f-15],p=Ui[f-2],h=Vr(d,7)^Vr(d,18)^d>>>3,m=Vr(p,17)^Vr(p,19)^p>>>10;Ui[f]=m+Ui[f-7]+h+Ui[f-16]|0}let{A:n,B:i,C:o,D:s,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){let d=Vr(a,6)^Vr(a,11)^Vr(a,25),p=l+d+m6(a,c,u)+g6[f]+Ui[f]|0,m=(Vr(n,2)^Vr(n,13)^Vr(n,22))+y6(n,i,o)|0;l=u,u=c,c=a,a=s+p|0,s=o,o=i,i=n,n=p+m|0}n=n+this.A|0,i=i+this.B|0,o=o+this.C|0,s=s+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,i,o,s,a,c,u,l)}roundClean(){Ui.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var CE=Dl(()=>new nm);function b6(t){let e=Bc(t);en(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:r,Fp:n,a:i}=e;if(r){if(!n.eql(i,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof r!="object"||typeof r.beta!="bigint"||typeof r.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}var{bytesToNumberBE:w6,hexToBytes:x6}=Ol,Io={Err:class extends Error{constructor(e=""){super(e)}},_parseInt(t){let{Err:e}=Io;if(t.length<2||t[0]!==2)throw new e("Invalid signature integer tag");let r=t[1],n=t.subarray(2,r+2);if(!r||n.length!==r)throw new e("Invalid signature integer: wrong length");if(n[0]&128)throw new e("Invalid signature integer: negative");if(n[0]===0&&!(n[1]&128))throw new e("Invalid signature integer: unnecessary leading zero");return{d:w6(n),l:t.subarray(r+2)}},toSig(t){let{Err:e}=Io,r=typeof t=="string"?x6(t):t;if(!Hr(r))throw new Error("ui8a expected");let n=r.length;if(n<2||r[0]!=48)throw new e("Invalid signature tag");if(r[1]!==n-2)throw new e("Invalid signature: incorrect length");let{d:i,l:o}=Io._parseInt(r.subarray(2)),{d:s,l:a}=Io._parseInt(o);if(a.length)throw new e("Invalid signature: left bytes after parsing");return{r:i,s}},hexFromSig(t){let e=u=>Number.parseInt(u[0],16)&8?"00"+u:u,r=u=>{let l=u.toString(16);return l.length&1?`0${l}`:l},n=e(r(t.s)),i=e(r(t.r)),o=n.length/2,s=i.length/2,a=r(o),c=r(s);return`30${r(s+o+4)}02${c}${i}02${a}${n}`}},jn=BigInt(0),Br=BigInt(1),pY=BigInt(2),PE=BigInt(3),mY=BigInt(4);function v6(t){let e=b6(t),{Fp:r}=e,n=e.toBytes||((h,m,y)=>{let g=m.toAffine();return Mn(Uint8Array.from([4]),r.toBytes(g.x),r.toBytes(g.y))}),i=e.fromBytes||(h=>{let m=h.subarray(1),y=r.fromBytes(m.subarray(0,r.BYTES)),g=r.fromBytes(m.subarray(r.BYTES,2*r.BYTES));return{x:y,y:g}});function o(h){let{a:m,b:y}=e,g=r.sqr(h),b=r.mul(g,h);return r.add(r.add(b,r.mul(h,m)),y)}if(!r.eql(r.sqr(e.Gy),o(e.Gx)))throw new Error("bad generator point: equation left != right");function s(h){return typeof h=="bigint"&&jn<h&&h<e.n}function a(h){if(!s(h))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(h){let{allowedPrivateKeyLengths:m,nByteLength:y,wrapPrivateKey:g,n:b}=e;if(m&&typeof h!="bigint"){if(Hr(h)&&(h=Un(h)),typeof h!="string"||!m.includes(h.length))throw new Error("Invalid key");h=h.padStart(y*2,"0")}let w;try{w=typeof h=="bigint"?h:Kn(et("private key",h,y))}catch{throw new Error(`private key must be ${y} bytes, hex or bigint, not ${typeof h}`)}return g&&(w=Ne(w,b)),a(w),w}let u=new Map;function l(h){if(!(h instanceof f))throw new Error("ProjectivePoint expected")}class f{constructor(m,y,g){if(this.px=m,this.py=y,this.pz=g,m==null||!r.isValid(m))throw new Error("x required");if(y==null||!r.isValid(y))throw new Error("y required");if(g==null||!r.isValid(g))throw new Error("z required")}static fromAffine(m){let{x:y,y:g}=m||{};if(!m||!r.isValid(y)||!r.isValid(g))throw new Error("invalid affine point");if(m instanceof f)throw new Error("projective point not allowed");let b=w=>r.eql(w,r.ZERO);return b(y)&&b(g)?f.ZERO:new f(y,g,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(m){let y=r.invertBatch(m.map(g=>g.pz));return m.map((g,b)=>g.toAffine(y[b])).map(f.fromAffine)}static fromHex(m){let y=f.fromAffine(i(et("pointHex",m)));return y.assertValidity(),y}static fromPrivateKey(m){return f.BASE.multiply(c(m))}_setWindowSize(m){this._WINDOW_SIZE=m,u.delete(this)}assertValidity(){if(this.is0()){if(e.allowInfinityPoint&&!r.is0(this.py))return;throw new Error("bad point: ZERO")}let{x:m,y}=this.toAffine();if(!r.isValid(m)||!r.isValid(y))throw new Error("bad point: x or y not FE");let g=r.sqr(y),b=o(m);if(!r.eql(g,b))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:m}=this.toAffine();if(r.isOdd)return!r.isOdd(m);throw new Error("Field doesn't support isOdd")}equals(m){l(m);let{px:y,py:g,pz:b}=this,{px:w,py:_,pz:E}=m,A=r.eql(r.mul(y,E),r.mul(w,b)),B=r.eql(r.mul(g,E),r.mul(_,b));return A&&B}negate(){return new f(this.px,r.neg(this.py),this.pz)}double(){let{a:m,b:y}=e,g=r.mul(y,PE),{px:b,py:w,pz:_}=this,E=r.ZERO,A=r.ZERO,B=r.ZERO,I=r.mul(b,b),L=r.mul(w,w),H=r.mul(_,_),F=r.mul(b,w);return F=r.add(F,F),B=r.mul(b,_),B=r.add(B,B),E=r.mul(m,B),A=r.mul(g,H),A=r.add(E,A),E=r.sub(L,A),A=r.add(L,A),A=r.mul(E,A),E=r.mul(F,E),B=r.mul(g,B),H=r.mul(m,H),F=r.sub(I,H),F=r.mul(m,F),F=r.add(F,B),B=r.add(I,I),I=r.add(B,I),I=r.add(I,H),I=r.mul(I,F),A=r.add(A,I),H=r.mul(w,_),H=r.add(H,H),I=r.mul(H,F),E=r.sub(E,I),B=r.mul(H,L),B=r.add(B,B),B=r.add(B,B),new f(E,A,B)}add(m){l(m);let{px:y,py:g,pz:b}=this,{px:w,py:_,pz:E}=m,A=r.ZERO,B=r.ZERO,I=r.ZERO,L=e.a,H=r.mul(e.b,PE),F=r.mul(y,w),$=r.mul(g,_),te=r.mul(b,E),de=r.add(y,g),T=r.add(w,_);de=r.mul(de,T),T=r.add(F,$),de=r.sub(de,T),T=r.add(y,b);let D=r.add(w,E);return T=r.mul(T,D),D=r.add(F,te),T=r.sub(T,D),D=r.add(g,b),A=r.add(_,E),D=r.mul(D,A),A=r.add($,te),D=r.sub(D,A),I=r.mul(L,T),A=r.mul(H,te),I=r.add(A,I),A=r.sub($,I),I=r.add($,I),B=r.mul(A,I),$=r.add(F,F),$=r.add($,F),te=r.mul(L,te),T=r.mul(H,T),$=r.add($,te),te=r.sub(F,te),te=r.mul(L,te),T=r.add(T,te),F=r.mul($,T),B=r.add(B,F),F=r.mul(D,T),A=r.mul(de,A),A=r.sub(A,F),F=r.mul(de,$),I=r.mul(D,I),I=r.add(I,F),new f(A,B,I)}subtract(m){return this.add(m.negate())}is0(){return this.equals(f.ZERO)}wNAF(m){return p.wNAFCached(this,u,m,y=>{let g=r.invertBatch(y.map(b=>b.pz));return y.map((b,w)=>b.toAffine(g[w])).map(f.fromAffine)})}multiplyUnsafe(m){let y=f.ZERO;if(m===jn)return y;if(a(m),m===Br)return this;let{endo:g}=e;if(!g)return p.unsafeLadder(this,m);let{k1neg:b,k1:w,k2neg:_,k2:E}=g.splitScalar(m),A=y,B=y,I=this;for(;w>jn||E>jn;)w&Br&&(A=A.add(I)),E&Br&&(B=B.add(I)),I=I.double(),w>>=Br,E>>=Br;return b&&(A=A.negate()),_&&(B=B.negate()),B=new f(r.mul(B.px,g.beta),B.py,B.pz),A.add(B)}multiply(m){a(m);let y=m,g,b,{endo:w}=e;if(w){let{k1neg:_,k1:E,k2neg:A,k2:B}=w.splitScalar(y),{p:I,f:L}=this.wNAF(E),{p:H,f:F}=this.wNAF(B);I=p.constTimeNegate(_,I),H=p.constTimeNegate(A,H),H=new f(r.mul(H.px,w.beta),H.py,H.pz),g=I.add(H),b=L.add(F)}else{let{p:_,f:E}=this.wNAF(y);g=_,b=E}return f.normalizeZ([g,b])[0]}multiplyAndAddUnsafe(m,y,g){let b=f.BASE,w=(E,A)=>A===jn||A===Br||!E.equals(b)?E.multiplyUnsafe(A):E.multiply(A),_=w(this,y).add(w(m,g));return _.is0()?void 0:_}toAffine(m){let{px:y,py:g,pz:b}=this,w=this.is0();m==null&&(m=w?r.ONE:r.inv(b));let _=r.mul(y,m),E=r.mul(g,m),A=r.mul(b,m);if(w)return{x:r.ZERO,y:r.ZERO};if(!r.eql(A,r.ONE))throw new Error("invZ was invalid");return{x:_,y:E}}isTorsionFree(){let{h:m,isTorsionFree:y}=e;if(m===Br)return!0;if(y)return y(f,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:m,clearCofactor:y}=e;return m===Br?this:y?y(f,this):this.multiplyUnsafe(e.h)}toRawBytes(m=!0){return this.assertValidity(),n(f,this,m)}toHex(m=!0){return Un(this.toRawBytes(m))}}f.BASE=new f(e.Gx,e.Gy,r.ONE),f.ZERO=new f(r.ZERO,r.ONE,r.ZERO);let d=e.nBitLength,p=Ml(f,e.endo?Math.ceil(d/2):d);return{CURVE:e,ProjectivePoint:f,normPrivateKeyToScalar:c,weierstrassEquation:o,isWithinCurveOrder:s}}function E6(t){let e=Bc(t);return en(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function DE(t){let e=E6(t),{Fp:r,n}=e,i=r.BYTES+1,o=2*r.BYTES+1;function s(T){return jn<T&&T<r.ORDER}function a(T){return Ne(T,n)}function c(T){return Ul(T,n)}let{ProjectivePoint:u,normPrivateKeyToScalar:l,weierstrassEquation:f,isWithinCurveOrder:d}=v6({...e,toBytes(T,D,N){let K=D.toAffine(),C=r.toBytes(K.x),W=Mn;return N?W(Uint8Array.from([D.hasEvenY()?2:3]),C):W(Uint8Array.from([4]),C,r.toBytes(K.y))},fromBytes(T){let D=T.length,N=T[0],K=T.subarray(1);if(D===i&&(N===2||N===3)){let C=Kn(K);if(!s(C))throw new Error("Point is not on curve");let W=f(C),Z=r.sqrt(W),oe=(Z&Br)===Br;return(N&1)===1!==oe&&(Z=r.neg(Z)),{x:C,y:Z}}else if(D===o&&N===4){let C=r.fromBytes(K.subarray(0,r.BYTES)),W=r.fromBytes(K.subarray(r.BYTES,2*r.BYTES));return{x:C,y:W}}else throw new Error(`Point of length ${D} was invalid. Expected ${i} compressed bytes or ${o} uncompressed bytes`)}}),p=T=>Un(Ci(T,e.nByteLength));function h(T){let D=n>>Br;return T>D}function m(T){return h(T)?a(-T):T}let y=(T,D,N)=>Kn(T.slice(D,N));class g{constructor(D,N,K){this.r=D,this.s=N,this.recovery=K,this.assertValidity()}static fromCompact(D){let N=e.nByteLength;return D=et("compactSignature",D,N*2),new g(y(D,0,N),y(D,N,2*N))}static fromDER(D){let{r:N,s:K}=Io.toSig(et("DER",D));return new g(N,K)}assertValidity(){if(!d(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!d(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(D){return new g(this.r,this.s,D)}recoverPublicKey(D){let{r:N,s:K,recovery:C}=this,W=B(et("msgHash",D));if(C==null||![0,1,2,3].includes(C))throw new Error("recovery id invalid");let Z=C===2||C===3?N+e.n:N;if(Z>=r.ORDER)throw new Error("recovery id 2 or 3 invalid");let oe=C&1?"03":"02",pe=u.fromHex(oe+p(Z)),ge=c(Z),Te=a(-W*ge),we=a(K*ge),_e=u.BASE.multiplyAndAddUnsafe(pe,Te,we);if(!_e)throw new Error("point at infinify");return _e.assertValidity(),_e}hasHighS(){return h(this.s)}normalizeS(){return this.hasHighS()?new g(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return xo(this.toDERHex())}toDERHex(){return Io.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return xo(this.toCompactHex())}toCompactHex(){return p(this.r)+p(this.s)}}let b={isValidPrivateKey(T){try{return l(T),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let T=K0(e.n);return Iv(e.randomBytes(T),e.n)},precompute(T=8,D=u.BASE){return D._setWindowSize(T),D.multiply(BigInt(3)),D}};function w(T,D=!0){return u.fromPrivateKey(T).toRawBytes(D)}function _(T){let D=Hr(T),N=typeof T=="string",K=(D||N)&&T.length;return D?K===i||K===o:N?K===2*i||K===2*o:T instanceof u}function E(T,D,N=!0){if(_(T))throw new Error("first arg must be private key");if(!_(D))throw new Error("second arg must be public key");return u.fromHex(D).multiply(l(T)).toRawBytes(N)}let A=e.bits2int||function(T){let D=Kn(T),N=T.length*8-e.nBitLength;return N>0?D>>BigInt(N):D},B=e.bits2int_modN||function(T){return a(A(T))},I=Rc(e.nBitLength);function L(T){if(typeof T!="bigint")throw new Error("bigint expected");if(!(jn<=T&&T<I))throw new Error(`bigint expected < 2^${e.nBitLength}`);return Ci(T,e.nByteLength)}function H(T,D,N=F){if(["recovered","canonical"].some(Je=>Je in N))throw new Error("sign() legacy options not supported");let{hash:K,randomBytes:C}=e,{lowS:W,prehash:Z,extraEntropy:oe}=N;W==null&&(W=!0),T=et("msgHash",T),Z&&(T=et("prehashed msgHash",K(T)));let pe=B(T),ge=l(D),Te=[L(ge),L(pe)];if(oe!=null){let Je=oe===!0?C(r.BYTES):oe;Te.push(et("extraEntropy",Je))}let we=Mn(...Te),_e=pe;function ct(Je){let _t=A(Je);if(!d(_t))return;let It=c(_t),ht=u.BASE.multiply(_t).toAffine(),Ot=a(ht.x);if(Ot===jn)return;let In=a(It*a(_e+Ot*ge));if(In===jn)return;let no=(ht.x===Ot?0:2)|Number(ht.y&Br),Wa=In;return W&&h(In)&&(Wa=m(In),no^=1),new g(Ot,Wa,no)}return{seed:we,k2sig:ct}}let F={lowS:e.lowS,prehash:!1},$={lowS:e.lowS,prehash:!1};function te(T,D,N=F){let{seed:K,k2sig:C}=H(T,D,N),W=e;return N0(W.hash.outputLen,W.nByteLength,W.hmac)(K,C)}u.BASE._setWindowSize(8);function de(T,D,N,K=$){let C=T;if(D=et("msgHash",D),N=et("publicKey",N),"strict"in K)throw new Error("options.strict was renamed to lowS");let{lowS:W,prehash:Z}=K,oe,pe;try{if(typeof C=="string"||Hr(C))try{oe=g.fromDER(C)}catch(ht){if(!(ht instanceof Io.Err))throw ht;oe=g.fromCompact(C)}else if(typeof C=="object"&&typeof C.r=="bigint"&&typeof C.s=="bigint"){let{r:ht,s:Ot}=C;oe=new g(ht,Ot)}else throw new Error("PARSE");pe=u.fromHex(N)}catch(ht){if(ht.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(W&&oe.hasHighS())return!1;Z&&(D=e.hash(D));let{r:ge,s:Te}=oe,we=B(D),_e=c(Te),ct=a(we*_e),Je=a(ge*_e),_t=u.BASE.multiplyAndAddUnsafe(pe,ct,Je)?.toAffine();return _t?a(_t.x)===ge:!1}return{CURVE:e,getPublicKey:w,getSharedSecret:E,sign:te,verify:de,ProjectivePoint:u,Signature:g,utils:b}}function A6(t){return{hash:t,hmac:(e,...r)=>Tc(t,e,Pl(...r)),randomBytes:_r}}function NE(t,e){let r=n=>DE({...t,...A6(n)});return Object.freeze({...r(e),create:r})}var UE=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),LE=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),S6=BigInt(1),im=BigInt(2),OE=(t,e)=>(t+e/im)/e;function _6(t){let e=UE,r=BigInt(3),n=BigInt(6),i=BigInt(11),o=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),u=t*t*t%e,l=u*u*t%e,f=ze(l,r,e)*l%e,d=ze(f,r,e)*l%e,p=ze(d,im,e)*u%e,h=ze(p,i,e)*p%e,m=ze(h,o,e)*h%e,y=ze(m,a,e)*m%e,g=ze(y,c,e)*y%e,b=ze(g,a,e)*m%e,w=ze(b,r,e)*l%e,_=ze(w,s,e)*h%e,E=ze(_,n,e)*u%e,A=ze(E,im,e);if(!om.eql(om.sqr(A),t))throw new Error("Cannot find square root");return A}var om=Kl(UE,void 0,void 0,{sqrt:_6}),he=NE({a:BigInt(0),b:BigInt(7),Fp:om,n:LE,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:t=>{let e=LE,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-S6*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=r,s=BigInt("0x100000000000000000000000000000000"),a=OE(o*t,e),c=OE(-n*t,e),u=Ne(t-a*r-c*i,e),l=Ne(-a*n-c*o,e),f=u>s,d=l>s;if(f&&(u=e-u),d&&(l=e-l),u>s||l>s)throw new Error("splitScalar: Endomorphism failed, k="+t);return{k1neg:f,k1:u,k2neg:d,k2:l}}}},CE),SY=BigInt(0);var _Y=he.ProjectivePoint;function KE(){return he.utils.randomPrivateKey()}function ME(t,e){let r=ae.digest(e instanceof Uint8Array?e:e.subarray());if(Sr(r))return r.then(({digest:n})=>he.sign(n,t).toDERRawBytes()).catch(n=>{throw new x(String(n),"ERR_INVALID_INPUT")});try{return he.sign(r.digest,t).toDERRawBytes()}catch(n){throw new x(String(n),"ERR_INVALID_INPUT")}}function FE(t,e,r){let n=ae.digest(r instanceof Uint8Array?r:r.subarray());if(Sr(n))return n.then(({digest:i})=>he.verify(e,i,t)).catch(i=>{throw new x(String(i),"ERR_INVALID_INPUT")});try{return he.verify(e,n.digest,t)}catch(i){throw new x(String(i),"ERR_INVALID_INPUT")}}function VE(t){return he.ProjectivePoint.fromHex(t).toRawBytes(!0)}function HE(t){try{he.getPublicKey(t,!0)}catch(e){throw new x(String(e),"ERR_INVALID_PRIVATE_KEY")}}function sm(t){try{he.ProjectivePoint.fromHex(t)}catch(e){throw new x(String(e),"ERR_INVALID_PUBLIC_KEY")}}function qE(t){try{return he.getPublicKey(t,!0)}catch(e){throw new x(String(e),"ERR_INVALID_PRIVATE_KEY")}}var zs=class{_key;constructor(e){sm(e),this._key=e}verify(e,r){return FE(this._key,r,e)}marshal(){return VE(this._key)}get bytes(){return tn.encode({Type:nt.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return ie(this.bytes,e.bytes)}async hash(){let e=ae.digest(this.bytes),r;return Sr(e)?{bytes:r}=await e:r=e.bytes,r}},Gs=class{_key;_publicKey;constructor(e,r){this._key=e,this._publicKey=r??qE(e),HE(this._key),sm(this._publicKey)}sign(e){return ME(this._key,e)}get public(){return new zs(this._publicKey)}marshal(){return this._key}get bytes(){return Hn.encode({Type:nt.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return ie(this.bytes,e.bytes)}hash(){let e=ae.digest(this.bytes);return Sr(e)?e.then(({bytes:r})=>r):e.bytes}async id(){let e=await this.public.hash();return z(e,"base58btc")}async export(e,r="libp2p-key"){if(r==="libp2p-key")return Ks(this.bytes,e);throw new x(`export format '${r}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function R6(t){return new Gs(t)}function B6(t){return new zs(t)}async function T6(){let t=KE();return new Gs(t)}var Lf={rsa:rm,ed25519:G0,secp256k1:am};function k6(t){let e=Object.keys(Lf).join(" / ");return new x(`invalid or unsupported key type ${t}. Must be ${e}`,"ERR_UNSUPPORTED_KEY_TYPE")}function $E(t){let e=tn.decode(t),r=e.Data??new Uint8Array;switch(e.Type){case nt.RSA:return Lf.rsa.unmarshalRsaPublicKey(r);case nt.Ed25519:return Lf.ed25519.unmarshalEd25519PublicKey(r);case nt.Secp256k1:return Lf.secp256k1.unmarshalSecp256k1PublicKey(r);default:throw k6(e.Type??"unknown")}}var C6=Symbol.for("nodejs.util.inspect.custom"),zE=Object.values(wi).map(t=>t.decoder).reduce((t,e)=>t.or(e),wi.identity.decoder),GE=114,cm=36,um=37,Mc=class{type;multihash;privateKey;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,this.privateKey=e.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Fd]=!0;toString(){return this.string==null&&(this.string=Oe.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return Fe.createV1(GE,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return ie(this.multihash.bytes,e);if(typeof e=="string")return ut(e).equals(this);if(e?.multihash?.bytes!=null)return ie(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[C6](){return`PeerId(${this.toString()})`}},Ro=class extends Mc{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Bo=class extends Mc{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}},To=class extends Mc{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}};function WE(t){if(t.type==="RSA")return new Ro(t);if(t.type==="Ed25519")return new Bo(t);if(t.type==="secp256k1")return new To(t);throw new x("Not a PeerId","ERR_INVALID_PARAMETERS")}function ut(t,e){if(e=e??zE,t.charAt(0)==="1"||t.charAt(0)==="Q"){let r=kn(Oe.decode(`z${t}`));return t.startsWith("12D")?new Bo({multihash:r}):t.startsWith("16U")?new To({multihash:r}):new Ro({multihash:r})}return Ws(zE.decode(t))}function Ws(t){try{let e=kn(t);if(e.code===Xt.code){if(e.digest.length===cm)return new Bo({multihash:e});if(e.digest.length===um)return new To({multihash:e})}if(e.code===ae.code)return new Ro({multihash:e})}catch{return P6(Fe.decode(t))}throw new Error("Supplied PeerID CID is invalid")}function P6(t){if(t==null||t.multihash==null||t.version==null||t.version===1&&t.code!==GE)throw new Error("Supplied PeerID CID is invalid");let e=t.multihash;if(e.code===ae.code)return new Ro({multihash:t.multihash});if(e.code===Xt.code){if(e.digest.length===cm)return new Bo({multihash:t.multihash});if(e.digest.length===um)return new To({multihash:t.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function Of(t,e){return t.length===cm?new Bo({multihash:Xr(Xt.code,t),privateKey:e}):t.length===um?new To({multihash:Xr(Xt.code,t),privateKey:e}):new Ro({multihash:await ae.digest(t),publicKey:t,privateKey:e})}function ko(t,e){let r={[Symbol.iterator]:()=>r,next:()=>{let n=t.next(),i=n.value;return n.done===!0||i==null?{done:!0,value:void 0}:{done:!1,value:e(i)}}};return r}var nr=class{map;constructor(e){if(this.map=new Map,e!=null)for(let[r,n]of e.entries())this.map.set(r.toString(),n)}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(e){return this.map.delete(e.toString())}entries(){return ko(this.map.entries(),e=>[ut(e[0]),e[1]])}forEach(e){this.map.forEach((r,n)=>{e(r,ut(n),this)})}get(e){return this.map.get(e.toString())}has(e){return this.map.has(e.toString())}set(e,r){this.map.set(e.toString(),r)}keys(){return ko(this.map.keys(),e=>ut(e))}values(){return this.map.values()}get size(){return this.map.size}};var Tr=class t{set;constructor(e){if(this.set=new Set,e!=null)for(let r of e)this.set.add(r.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(e){this.set.add(e.toString())}clear(){this.set.clear()}delete(e){this.set.delete(e.toString())}entries(){return ko(this.set.entries(),e=>{let r=ut(e[0]);return[r,r]})}forEach(e){this.set.forEach(r=>{let n=ut(r);e(n,n,this)})}has(e){return this.set.has(e.toString())}values(){return ko(this.set.values(),e=>ut(e))}intersection(e){let r=new t;for(let n of e)this.has(n)&&r.add(n);return r}difference(e){let r=new t;for(let n of this)e.has(n)||r.add(n);return r}union(e){let r=new t;for(let n of e)r.add(n);for(let n of this)r.add(n);return r}};var dm={};Y(dm,{Ed25519PrivateKey:()=>Ki,Ed25519PublicKey:()=>Qs,generateKeyPair:()=>U6,generateKeyPairFromSeed:()=>e2,unmarshalEd25519PrivateKey:()=>L6,unmarshalEd25519PublicKey:()=>O6});function kr(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Ys=32,Qn=64,Uf=32;function YE(){let t=Ge.utils.randomPrivateKey(),e=Ge.getPublicKey(t);return{privateKey:XE(t,e),publicKey:e}}function jE(t){if(t.length!==Uf)throw new TypeError('"seed" must be 32 bytes in length.');if(!(t instanceof Uint8Array))throw new TypeError('"seed" must be a node.js Buffer, or Uint8Array.');let e=t,r=Ge.getPublicKey(e);return{privateKey:XE(e,r),publicKey:r}}function QE(t,e){let r=t.subarray(0,Uf);return Ge.sign(e instanceof Uint8Array?e:e.subarray(),r)}function JE(t,e,r){return Ge.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}function XE(t,e){let r=new Uint8Array(Qn);for(let n=0;n<Uf;n++)r[n]=t[n],r[Uf+n]=e[n];return r}var kt={get(t=globalThis){let e=t.crypto;if(e==null||e.subtle==null)throw Object.assign(new Error("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api"),{code:"ERR_MISSING_WEB_CRYPTO"});return e}};var lm={alg:"A128GCM",ext:!0,k:"scm9jmO_4BJAgdwWGVulLg",key_ops:["encrypt","decrypt"],kty:"oct"};function fm(t){let e=t?.algorithm??"AES-GCM",r=t?.keyLength??16,n=t?.nonceLength??12,i=t?.digest??"SHA-256",o=t?.saltLength??16,s=t?.iterations??32767,a=kt.get();r*=8;async function c(f,d){let p=a.getRandomValues(new Uint8Array(o)),h=a.getRandomValues(new Uint8Array(n)),m={name:e,iv:h};typeof d=="string"&&(d=U(d));let y;if(d.length===0){y=await a.subtle.importKey("jwk",lm,{name:"AES-GCM"},!0,["encrypt"]);try{let b={name:"PBKDF2",salt:p,iterations:s,hash:{name:i}},w=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(b,w,{name:e,length:r},!0,["encrypt"])}catch{y=await a.subtle.importKey("jwk",lm,{name:"AES-GCM"},!0,["encrypt"])}}else{let b={name:"PBKDF2",salt:p,iterations:s,hash:{name:i}},w=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(b,w,{name:e,length:r},!0,["encrypt"])}let g=await a.subtle.encrypt(m,y,f);return ke([p,m.iv,new Uint8Array(g)])}async function u(f,d){let p=f.subarray(0,o),h=f.subarray(o,o+n),m=f.subarray(o+n),y={name:e,iv:h};typeof d=="string"&&(d=U(d));let g;if(d.length===0)try{let w={name:"PBKDF2",salt:p,iterations:s,hash:{name:i}},_=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);g=await a.subtle.deriveKey(w,_,{name:e,length:r},!0,["decrypt"])}catch{g=await a.subtle.importKey("jwk",lm,{name:"AES-GCM"},!0,["decrypt"])}else{let w={name:"PBKDF2",salt:p,iterations:s,hash:{name:i}},_=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);g=await a.subtle.deriveKey(w,_,{name:e,length:r},!0,["decrypt"])}let b=await a.subtle.decrypt(y,g,m);return new Uint8Array(b)}return{encrypt:c,decrypt:u}}async function js(t,e){let n=await fm().encrypt(t,e);return $t.encode(n)}var vt;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.Secp256k1="Secp256k1"})(vt||(vt={}));var hm;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.Secp256k1=2]="Secp256k1"})(hm||(hm={}));(function(t){t.codec=()=>Zt(hm)})(vt||(vt={}));var Jn;(function(t){let e;t.codec=()=>(e==null&&(e=Ee((r,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),vt.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),i.lengthDelimited!==!1&&n.ldelim()},(r,n)=>{let i={},o=n==null?r.len:r.pos+n;for(;r.pos<o;){let s=r.uint32();switch(s>>>3){case 1:i.Type=vt.codec().decode(r);break;case 2:i.Data=r.bytes();break;default:r.skipType(s&7);break}}return i})),e),t.encode=r=>ve(r,t.codec()),t.decode=r=>xe(r,t.codec())})(Jn||(Jn={}));var Xn;(function(t){let e;t.codec=()=>(e==null&&(e=Ee((r,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),vt.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),i.lengthDelimited!==!1&&n.ldelim()},(r,n)=>{let i={},o=n==null?r.len:r.pos+n;for(;r.pos<o;){let s=r.uint32();switch(s>>>3){case 1:i.Type=vt.codec().decode(r);break;case 2:i.Data=r.bytes();break;default:r.skipType(s&7);break}}return i})),e),t.encode=r=>ve(r,t.codec()),t.decode=r=>xe(r,t.codec())})(Xn||(Xn={}));var Qs=class{_key;constructor(e){this._key=Js(e,Ys)}verify(e,r){return JE(this._key,r,e)}marshal(){return this._key}get bytes(){return Jn.encode({Type:vt.Ed25519,Data:this.marshal()}).subarray()}equals(e){return ie(this.bytes,e.bytes)}hash(){let e=ae.digest(this.bytes);return kr(e)?e.then(({bytes:r})=>r):e.bytes}},Ki=class{_key;_publicKey;constructor(e,r){this._key=Js(e,Qn),this._publicKey=Js(r,Ys)}sign(e){return QE(this._key,e)}get public(){return new Qs(this._publicKey)}marshal(){return this._key}get bytes(){return Xn.encode({Type:vt.Ed25519,Data:this.marshal()}).subarray()}equals(e){return ie(this.bytes,e.bytes)}async hash(){let e=ae.digest(this.bytes),r;return kr(e)?{bytes:r}=await e:r=e.bytes,r}async id(){let e=Xt.digest(this.public.bytes);return Oe.encode(e.bytes).substring(1)}async export(e,r="libp2p-key"){if(r==="libp2p-key")return js(this.bytes,e);throw new x(`export format '${r}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function L6(t){if(t.length>Qn){t=Js(t,Qn+Ys);let n=t.subarray(0,Qn),i=t.subarray(Qn,t.length);return new Ki(n,i)}t=Js(t,Qn);let e=t.subarray(0,Qn),r=t.subarray(Ys);return new Ki(e,r)}function O6(t){return t=Js(t,Ys),new Qs(t)}async function U6(){let{privateKey:t,publicKey:e}=YE();return new Ki(t,e)}async function e2(t){let{privateKey:e,publicKey:r}=jE(t);return new Ki(e,r)}function Js(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new x(`Key must be a Uint8Array of length ${e}, got ${t.length}`,"ERR_INVALID_KEY_TYPE");return t}var K6={"P-256":256,"P-384":384,"P-521":521},M6=Object.keys(K6),iQ=M6.join(" / ");var bm={};Y(bm,{MAX_RSA_KEY_SIZE:()=>Zs,RsaPrivateKey:()=>Po,RsaPublicKey:()=>Xs,fromJwk:()=>J6,generateKeyPair:()=>X6,unmarshalRsaPrivateKey:()=>ym,unmarshalRsaPublicKey:()=>Q6});function Co(t){if(isNaN(t)||t<=0)throw new x("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return _r(t)}var Mi={};Y(Mi,{exportToPem:()=>G6,importFromPem:()=>r2,jwkToPkcs1:()=>H6,jwkToPkix:()=>$6,pkcs1ToJwk:()=>V6,pkixToJwk:()=>q6});function V6(t){let{result:e}=xt(t),r=e.valueBlock.value;return{n:z(an(r[1].toBigInt()),"base64url"),e:z(an(r[2].toBigInt()),"base64url"),d:z(an(r[3].toBigInt()),"base64url"),p:z(an(r[4].toBigInt()),"base64url"),q:z(an(r[5].toBigInt()),"base64url"),dp:z(an(r[6].toBigInt()),"base64url"),dq:z(an(r[7].toBigInt()),"base64url"),qi:z(an(r[8].toBigInt()),"base64url"),kty:"RSA",alg:"RS256"}}function H6(t){if(t.n==null||t.e==null||t.d==null||t.p==null||t.q==null||t.dp==null||t.dq==null||t.qi==null)throw new x("JWK was missing components","ERR_INVALID_PARAMETERS");let r=new se({value:[new ne({value:0}),ne.fromBigInt(cn(U(t.n,"base64url"))),ne.fromBigInt(cn(U(t.e,"base64url"))),ne.fromBigInt(cn(U(t.d,"base64url"))),ne.fromBigInt(cn(U(t.p,"base64url"))),ne.fromBigInt(cn(U(t.q,"base64url"))),ne.fromBigInt(cn(U(t.dp,"base64url"))),ne.fromBigInt(cn(U(t.dq,"base64url"))),ne.fromBigInt(cn(U(t.qi,"base64url")))]}).toBER();return new Uint8Array(r,0,r.byteLength)}function q6(t){let{result:e}=xt(t),r=e.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:z(an(r[0].toBigInt()),"base64url"),e:z(an(r[1].toBigInt()),"base64url")}}function $6(t){if(t.n==null||t.e==null)throw new x("JWK was missing components","ERR_INVALID_PARAMETERS");let r=new se({value:[new se({value:[new Ve({value:"1.2.840.113549.1.1.1"}),new qt]}),new nn({valueHex:new se({value:[ne.fromBigInt(cn(U(t.n,"base64url"))),ne.fromBigInt(cn(U(t.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(r,0,r.byteLength)}function an(t){let e=t.toString(16);e.length%2>0&&(e=`0${e}`);let r=e.length/2,n=new Uint8Array(r),i=0,o=0;for(;i<r;)n[i]=parseInt(e.slice(o,o+2),16),i+=1,o+=2;return n}function cn(t){let e=[];return t.forEach(function(r){let n=r.toString(16);n.length%2>0&&(n=`0${n}`),e.push(n)}),BigInt("0x"+e.join(""))}var z6=16,pm=32,mm=1e4;async function G6(t,e){let r=kt.get(),i=new se({value:[new ne({value:0}),new se({value:[new Ve({value:"1.2.840.113549.1.1.1"}),new qt]}),new yt({valueHex:t.marshal()})]}).toBER(),o=new Uint8Array(i,0,i.byteLength),s=Co(z6),a=await qn(Ir,e,s,{c:mm,dkLen:pm}),c=Co(16),u=await r.subtle.importKey("raw",a,"AES-CBC",!1,["encrypt"]),l=await r.subtle.encrypt({name:"AES-CBC",iv:c},u,o),f=new se({value:[new yt({valueHex:s}),new ne({value:mm}),new ne({value:pm}),new se({value:[new Ve({value:"1.2.840.113549.2.11"}),new qt]})]}),d=new se({value:[new Ve({value:"1.2.840.113549.1.5.13"}),new se({value:[new se({value:[new Ve({value:"1.2.840.113549.1.5.12"}),f]}),new se({value:[new Ve({value:"2.16.840.1.101.3.4.1.42"}),new yt({valueHex:c})]})]})]}),h=new se({value:[d,new yt({valueHex:l})]}).toBER(),m=new Uint8Array(h,0,h.byteLength);return["-----BEGIN ENCRYPTED PRIVATE KEY-----",...z(m,"base64pad").split(/(.{64})/).filter(Boolean),"-----END ENCRYPTED PRIVATE KEY-----"].join(`
|
|
22
|
+
`)}async function r2(t,e){let r=kt.get(),n;if(t.includes("-----BEGIN ENCRYPTED PRIVATE KEY-----")){let i=U(t.replace("-----BEGIN ENCRYPTED PRIVATE KEY-----","").replace("-----END ENCRYPTED PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:o}=xt(i),{iv:s,salt:a,iterations:c,keySize:u,cipherText:l}=W6(o),f=await qn(Ir,e,a,{c,dkLen:u}),d=await r.subtle.importKey("raw",f,"AES-CBC",!1,["decrypt"]),p=Fc(await r.subtle.decrypt({name:"AES-CBC",iv:s},d,l)),{result:h}=xt(p);n=t2(h)}else if(t.includes("-----BEGIN PRIVATE KEY-----")){let i=U(t.replace("-----BEGIN PRIVATE KEY-----","").replace("-----END PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:o}=xt(i);n=t2(o)}else throw new x("Could not parse private key from PEM data","ERR_INVALID_PARAMETERS");return ym(n)}function W6(t){let e=t.valueBlock.value[0];if(e.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.13")throw new x("Only pkcs5PBES2 encrypted private keys are supported","ERR_INVALID_PARAMS");let n=e.valueBlock.value[1].valueBlock.value[0];if(n.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.12")throw new x("Only pkcs5PBKDF2 key derivation functions are supported","ERR_INVALID_PARAMS");let o=n.valueBlock.value[1],s=Fc(o.valueBlock.value[0].getValue()),a=mm,c=pm;if(o.valueBlock.value.length===3)a=Number(o.valueBlock.value[1].toBigInt()),c=Number(o.valueBlock.value[2].toBigInt());else if(o.valueBlock.value.length===2)throw new x("Could not derive key size and iterations from PEM file - please use @libp2p/rsa to re-import your key","ERR_INVALID_PARAMS");let u=e.valueBlock.value[1].valueBlock.value[1],l=u.valueBlock.value[0].toString();if(l!=="OBJECT IDENTIFIER : 1.2.840.113549.3.7"){if(l!=="OBJECT IDENTIFIER : 1.3.14.3.2.7"){if(l!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.2"){if(l!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.22"){if(l!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.42")throw new x("Only AES-CBC encryption schemes are supported","ERR_INVALID_PARAMS")}}}}let f=Fc(u.valueBlock.value[1].getValue());return{cipherText:Fc(t.valueBlock.value[1].getValue()),salt:s,iterations:a,keySize:c,iv:f}}function t2(t){return Fc(t.valueBlock.value[2].getValue())}function Fc(t){return new Uint8Array(t,0,t.byteLength)}async function n2(t){let e=await kt.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:t,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),r=await s2(e);return{privateKey:r[0],publicKey:r[1]}}async function gm(t){let r=[await kt.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),await Y6(t)],n=await s2({privateKey:r[0],publicKey:r[1]});return{privateKey:n[0],publicKey:n[1]}}async function i2(t,e){let r=await kt.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await kt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},r,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(n,0,n.byteLength)}async function o2(t,e,r){let n=await kt.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return kt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,e,r instanceof Uint8Array?r:r.subarray())}async function s2(t){if(t.privateKey==null||t.publicKey==null)throw new x("Private and public key are required","ERR_INVALID_PARAMETERS");return Promise.all([kt.get().subtle.exportKey("jwk",t.privateKey),kt.get().subtle.exportKey("jwk",t.publicKey)])}async function Y6(t){return kt.get().subtle.importKey("jwk",{kty:t.kty,n:t.n,e:t.e},{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])}function Mf(t){if(t.kty!=="RSA")throw new x("invalid key type","ERR_INVALID_KEY_TYPE");if(t.n==null)throw new x("invalid key modulus","ERR_INVALID_KEY_MODULUS");return U(t.n,"base64url").length*8}var Zs=8192,Xs=class{_key;constructor(e){this._key=e}verify(e,r){return o2(this._key,r,e)}marshal(){return Mi.jwkToPkix(this._key)}get bytes(){return Jn.encode({Type:vt.RSA,Data:this.marshal()}).subarray()}equals(e){return ie(this.bytes,e.bytes)}hash(){let e=ae.digest(this.bytes);return kr(e)?e.then(({bytes:r})=>r):e.bytes}},Po=class{_key;_publicKey;constructor(e,r){this._key=e,this._publicKey=r}genSecret(){return Co(16)}sign(e){return i2(this._key,e)}get public(){if(this._publicKey==null)throw new x("public key not provided","ERR_PUBKEY_NOT_PROVIDED");return new Xs(this._publicKey)}marshal(){return Mi.jwkToPkcs1(this._key)}get bytes(){return Xn.encode({Type:vt.RSA,Data:this.marshal()}).subarray()}equals(e){return ie(this.bytes,e.bytes)}hash(){let e=ae.digest(this.bytes);return kr(e)?e.then(({bytes:r})=>r):e.bytes}async id(){let e=await this.public.hash();return z(e,"base58btc")}async export(e,r="pkcs-8"){if(r==="pkcs-8")return Mi.exportToPem(this,e);if(r==="libp2p-key")return js(this.bytes,e);throw new x(`export format '${r}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};async function ym(t){let e=Mi.pkcs1ToJwk(t);if(Mf(e)>Zs)throw new x("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let r=await gm(e);return new Po(r.privateKey,r.publicKey)}function Q6(t){let e=Mi.pkixToJwk(t);if(Mf(e)>Zs)throw new x("key size is too large","ERR_KEY_SIZE_TOO_LARGE");return new Xs(e)}async function J6(t){if(Mf(t)>Zs)throw new x("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await gm(t);return new Po(e.privateKey,e.publicKey)}async function X6(t){if(t>Zs)throw new x("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await n2(t);return new Po(e.privateKey,e.publicKey)}var xm={};Y(xm,{Secp256k1PrivateKey:()=>ta,Secp256k1PublicKey:()=>ea,generateKeyPair:()=>r3,unmarshalSecp256k1PrivateKey:()=>e3,unmarshalSecp256k1PublicKey:()=>t3});function a2(){return he.utils.randomPrivateKey()}function c2(t,e){let r=ae.digest(e instanceof Uint8Array?e:e.subarray());if(kr(r))return r.then(({digest:n})=>he.sign(n,t).toDERRawBytes()).catch(n=>{throw new x(String(n),"ERR_INVALID_INPUT")});try{return he.sign(r.digest,t).toDERRawBytes()}catch(n){throw new x(String(n),"ERR_INVALID_INPUT")}}function u2(t,e,r){let n=ae.digest(r instanceof Uint8Array?r:r.subarray());if(kr(n))return n.then(({digest:i})=>he.verify(e,i,t)).catch(i=>{throw new x(String(i),"ERR_INVALID_INPUT")});try{return he.verify(e,n.digest,t)}catch(i){throw new x(String(i),"ERR_INVALID_INPUT")}}function l2(t){return he.ProjectivePoint.fromHex(t).toRawBytes(!0)}function f2(t){try{he.getPublicKey(t,!0)}catch(e){throw new x(String(e),"ERR_INVALID_PRIVATE_KEY")}}function wm(t){try{he.ProjectivePoint.fromHex(t)}catch(e){throw new x(String(e),"ERR_INVALID_PUBLIC_KEY")}}function h2(t){try{return he.getPublicKey(t,!0)}catch(e){throw new x(String(e),"ERR_INVALID_PRIVATE_KEY")}}var ea=class{_key;constructor(e){wm(e),this._key=e}verify(e,r){return u2(this._key,r,e)}marshal(){return l2(this._key)}get bytes(){return Jn.encode({Type:vt.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return ie(this.bytes,e.bytes)}async hash(){let e=ae.digest(this.bytes),r;return kr(e)?{bytes:r}=await e:r=e.bytes,r}},ta=class{_key;_publicKey;constructor(e,r){this._key=e,this._publicKey=r??h2(e),f2(this._key),wm(this._publicKey)}sign(e){return c2(this._key,e)}get public(){return new ea(this._publicKey)}marshal(){return this._key}get bytes(){return Xn.encode({Type:vt.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return ie(this.bytes,e.bytes)}hash(){let e=ae.digest(this.bytes);return kr(e)?e.then(({bytes:r})=>r):e.bytes}async id(){let e=await this.public.hash();return z(e,"base58btc")}async export(e,r="libp2p-key"){if(r==="libp2p-key")return js(this.bytes,e);throw new x(`export format '${r}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function e3(t){return new ta(t)}function t3(t){return new ea(t)}async function r3(){let t=a2();return new ta(t)}var d2={rsa:bm,ed25519:dm,secp256k1:xm};function n3(t){let e=Object.keys(d2).join(" / ");return new x(`invalid or unsupported key type ${t}. Must be ${e}`,"ERR_UNSUPPORTED_KEY_TYPE")}function vm(t){if(t=t.toLowerCase(),t==="rsa"||t==="ed25519"||t==="secp256k1")return d2[t];throw n3(t)}async function p2(t,e){return vm(t).generateKeyPair(e??2048)}function m2(t,e){return e=(e??"rsa").toLowerCase(),vm(e),t.bytes}function y2(t,e){return e=(e??"rsa").toLowerCase(),vm(e),t.bytes}var Em;(function(t){let e;t.codec=()=>(e==null&&(e=Ee((r,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),r.id!=null&&(n.uint32(10),n.bytes(r.id)),r.pubKey!=null&&(n.uint32(18),n.bytes(r.pubKey)),r.privKey!=null&&(n.uint32(26),n.bytes(r.privKey)),i.lengthDelimited!==!1&&n.ldelim()},(r,n)=>{let i={},o=n==null?r.len:r.pos+n;for(;r.pos<o;){let s=r.uint32();switch(s>>>3){case 1:i.id=r.bytes();break;case 2:i.pubKey=r.bytes();break;case 3:i.privKey=r.bytes();break;default:r.skipType(s&7);break}}return i})),e),t.encode=r=>ve(r,t.codec()),t.decode=r=>xe(r,t.codec())})(Em||(Em={}));var g2=async()=>{let t=await p2("Ed25519"),e=await i3(t);if(e.type==="Ed25519")return e;throw new Error(`Generated unexpected PeerId type "${e.type}"`)};async function i3(t){return Of(m2(t.public),y2(t))}var Im={};Y(Im,{Ed25519PrivateKey:()=>Fi,Ed25519PublicKey:()=>ia,generateKeyPair:()=>c3,generateKeyPairFromSeed:()=>S2,unmarshalEd25519PrivateKey:()=>s3,unmarshalEd25519PublicKey:()=>a3});function Cr(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var ra=32,Zn=64,Ff=32;function b2(){let t=Ge.utils.randomPrivateKey(),e=Ge.getPublicKey(t);return{privateKey:E2(t,e),publicKey:e}}function w2(t){if(t.length!==Ff)throw new TypeError('"seed" must be 32 bytes in length.');if(!(t instanceof Uint8Array))throw new TypeError('"seed" must be a node.js Buffer, or Uint8Array.');let e=t,r=Ge.getPublicKey(e);return{privateKey:E2(e,r),publicKey:r}}function x2(t,e){let r=t.subarray(0,Ff);return Ge.sign(e instanceof Uint8Array?e:e.subarray(),r)}function v2(t,e,r){return Ge.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}function E2(t,e){let r=new Uint8Array(Zn);for(let n=0;n<Ff;n++)r[n]=t[n],r[Ff+n]=e[n];return r}var Ct={get(t=globalThis){let e=t.crypto;if(e==null||e.subtle==null)throw Object.assign(new Error("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api"),{code:"ERR_MISSING_WEB_CRYPTO"});return e}};var Am={alg:"A128GCM",ext:!0,k:"scm9jmO_4BJAgdwWGVulLg",key_ops:["encrypt","decrypt"],kty:"oct"};function Sm(t){let e=t?.algorithm??"AES-GCM",r=t?.keyLength??16,n=t?.nonceLength??12,i=t?.digest??"SHA-256",o=t?.saltLength??16,s=t?.iterations??32767,a=Ct.get();r*=8;async function c(f,d){let p=a.getRandomValues(new Uint8Array(o)),h=a.getRandomValues(new Uint8Array(n)),m={name:e,iv:h};typeof d=="string"&&(d=U(d));let y;if(d.length===0){y=await a.subtle.importKey("jwk",Am,{name:"AES-GCM"},!0,["encrypt"]);try{let b={name:"PBKDF2",salt:p,iterations:s,hash:{name:i}},w=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(b,w,{name:e,length:r},!0,["encrypt"])}catch{y=await a.subtle.importKey("jwk",Am,{name:"AES-GCM"},!0,["encrypt"])}}else{let b={name:"PBKDF2",salt:p,iterations:s,hash:{name:i}},w=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(b,w,{name:e,length:r},!0,["encrypt"])}let g=await a.subtle.encrypt(m,y,f);return ke([p,m.iv,new Uint8Array(g)])}async function u(f,d){let p=f.subarray(0,o),h=f.subarray(o,o+n),m=f.subarray(o+n),y={name:e,iv:h};typeof d=="string"&&(d=U(d));let g;if(d.length===0)try{let w={name:"PBKDF2",salt:p,iterations:s,hash:{name:i}},_=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);g=await a.subtle.deriveKey(w,_,{name:e,length:r},!0,["decrypt"])}catch{g=await a.subtle.importKey("jwk",Am,{name:"AES-GCM"},!0,["decrypt"])}else{let w={name:"PBKDF2",salt:p,iterations:s,hash:{name:i}},_=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);g=await a.subtle.deriveKey(w,_,{name:e,length:r},!0,["decrypt"])}let b=await a.subtle.decrypt(y,g,m);return new Uint8Array(b)}return{encrypt:c,decrypt:u}}async function na(t,e){let n=await Sm().encrypt(t,e);return $t.encode(n)}var We;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.Secp256k1="Secp256k1"})(We||(We={}));var _m;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.Secp256k1=2]="Secp256k1"})(_m||(_m={}));(function(t){t.codec=()=>Zt(_m)})(We||(We={}));var un;(function(t){let e;t.codec=()=>(e==null&&(e=Ee((r,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),We.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),i.lengthDelimited!==!1&&n.ldelim()},(r,n)=>{let i={},o=n==null?r.len:r.pos+n;for(;r.pos<o;){let s=r.uint32();switch(s>>>3){case 1:i.Type=We.codec().decode(r);break;case 2:i.Data=r.bytes();break;default:r.skipType(s&7);break}}return i})),e),t.encode=r=>ve(r,t.codec()),t.decode=r=>xe(r,t.codec())})(un||(un={}));var ln;(function(t){let e;t.codec=()=>(e==null&&(e=Ee((r,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),We.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),i.lengthDelimited!==!1&&n.ldelim()},(r,n)=>{let i={},o=n==null?r.len:r.pos+n;for(;r.pos<o;){let s=r.uint32();switch(s>>>3){case 1:i.Type=We.codec().decode(r);break;case 2:i.Data=r.bytes();break;default:r.skipType(s&7);break}}return i})),e),t.encode=r=>ve(r,t.codec()),t.decode=r=>xe(r,t.codec())})(ln||(ln={}));var ia=class{_key;constructor(e){this._key=oa(e,ra)}verify(e,r){return v2(this._key,r,e)}marshal(){return this._key}get bytes(){return un.encode({Type:We.Ed25519,Data:this.marshal()}).subarray()}equals(e){return ie(this.bytes,e.bytes)}hash(){let e=ae.digest(this.bytes);return Cr(e)?e.then(({bytes:r})=>r):e.bytes}},Fi=class{_key;_publicKey;constructor(e,r){this._key=oa(e,Zn),this._publicKey=oa(r,ra)}sign(e){return x2(this._key,e)}get public(){return new ia(this._publicKey)}marshal(){return this._key}get bytes(){return ln.encode({Type:We.Ed25519,Data:this.marshal()}).subarray()}equals(e){return ie(this.bytes,e.bytes)}async hash(){let e=ae.digest(this.bytes),r;return Cr(e)?{bytes:r}=await e:r=e.bytes,r}async id(){let e=Xt.digest(this.public.bytes);return Oe.encode(e.bytes).substring(1)}async export(e,r="libp2p-key"){if(r==="libp2p-key")return na(this.bytes,e);throw new x(`export format '${r}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function s3(t){if(t.length>Zn){t=oa(t,Zn+ra);let n=t.subarray(0,Zn),i=t.subarray(Zn,t.length);return new Fi(n,i)}t=oa(t,Zn);let e=t.subarray(0,Zn),r=t.subarray(ra);return new Fi(e,r)}function a3(t){return t=oa(t,ra),new ia(t)}async function c3(){let{privateKey:t,publicKey:e}=b2();return new Fi(t,e)}async function S2(t){let{privateKey:e,publicKey:r}=w2(t);return new Fi(e,r)}function oa(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new x(`Key must be a Uint8Array of length ${e}, got ${t.length}`,"ERR_INVALID_KEY_TYPE");return t}var u3={"P-256":256,"P-384":384,"P-521":521},l3=Object.keys(u3),qJ=l3.join(" / ");var Cm={};Y(Cm,{MAX_RSA_KEY_SIZE:()=>aa,RsaPrivateKey:()=>No,RsaPublicKey:()=>sa,fromJwk:()=>E3,generateKeyPair:()=>A3,unmarshalRsaPrivateKey:()=>Tm,unmarshalRsaPublicKey:()=>v3});function Do(t){if(isNaN(t)||t<=0)throw new x("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return _r(t)}var Vi={};Y(Vi,{exportToPem:()=>g3,importFromPem:()=>I2,jwkToPkcs1:()=>d3,jwkToPkix:()=>m3,pkcs1ToJwk:()=>h3,pkixToJwk:()=>p3});function h3(t){let{result:e}=xt(t),r=e.valueBlock.value;return{n:z(fn(r[1].toBigInt()),"base64url"),e:z(fn(r[2].toBigInt()),"base64url"),d:z(fn(r[3].toBigInt()),"base64url"),p:z(fn(r[4].toBigInt()),"base64url"),q:z(fn(r[5].toBigInt()),"base64url"),dp:z(fn(r[6].toBigInt()),"base64url"),dq:z(fn(r[7].toBigInt()),"base64url"),qi:z(fn(r[8].toBigInt()),"base64url"),kty:"RSA",alg:"RS256"}}function d3(t){if(t.n==null||t.e==null||t.d==null||t.p==null||t.q==null||t.dp==null||t.dq==null||t.qi==null)throw new x("JWK was missing components","ERR_INVALID_PARAMETERS");let r=new se({value:[new ne({value:0}),ne.fromBigInt(hn(U(t.n,"base64url"))),ne.fromBigInt(hn(U(t.e,"base64url"))),ne.fromBigInt(hn(U(t.d,"base64url"))),ne.fromBigInt(hn(U(t.p,"base64url"))),ne.fromBigInt(hn(U(t.q,"base64url"))),ne.fromBigInt(hn(U(t.dp,"base64url"))),ne.fromBigInt(hn(U(t.dq,"base64url"))),ne.fromBigInt(hn(U(t.qi,"base64url")))]}).toBER();return new Uint8Array(r,0,r.byteLength)}function p3(t){let{result:e}=xt(t),r=e.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:z(fn(r[0].toBigInt()),"base64url"),e:z(fn(r[1].toBigInt()),"base64url")}}function m3(t){if(t.n==null||t.e==null)throw new x("JWK was missing components","ERR_INVALID_PARAMETERS");let r=new se({value:[new se({value:[new Ve({value:"1.2.840.113549.1.1.1"}),new qt]}),new nn({valueHex:new se({value:[ne.fromBigInt(hn(U(t.n,"base64url"))),ne.fromBigInt(hn(U(t.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(r,0,r.byteLength)}function fn(t){let e=t.toString(16);e.length%2>0&&(e=`0${e}`);let r=e.length/2,n=new Uint8Array(r),i=0,o=0;for(;i<r;)n[i]=parseInt(e.slice(o,o+2),16),i+=1,o+=2;return n}function hn(t){let e=[];return t.forEach(function(r){let n=r.toString(16);n.length%2>0&&(n=`0${n}`),e.push(n)}),BigInt("0x"+e.join(""))}var y3=16,Rm=32,Bm=1e4;async function g3(t,e){let r=Ct.get(),i=new se({value:[new ne({value:0}),new se({value:[new Ve({value:"1.2.840.113549.1.1.1"}),new qt]}),new yt({valueHex:t.marshal()})]}).toBER(),o=new Uint8Array(i,0,i.byteLength),s=Do(y3),a=await qn(Ir,e,s,{c:Bm,dkLen:Rm}),c=Do(16),u=await r.subtle.importKey("raw",a,"AES-CBC",!1,["encrypt"]),l=await r.subtle.encrypt({name:"AES-CBC",iv:c},u,o),f=new se({value:[new yt({valueHex:s}),new ne({value:Bm}),new ne({value:Rm}),new se({value:[new Ve({value:"1.2.840.113549.2.11"}),new qt]})]}),d=new se({value:[new Ve({value:"1.2.840.113549.1.5.13"}),new se({value:[new se({value:[new Ve({value:"1.2.840.113549.1.5.12"}),f]}),new se({value:[new Ve({value:"2.16.840.1.101.3.4.1.42"}),new yt({valueHex:c})]})]})]}),h=new se({value:[d,new yt({valueHex:l})]}).toBER(),m=new Uint8Array(h,0,h.byteLength);return["-----BEGIN ENCRYPTED PRIVATE KEY-----",...z(m,"base64pad").split(/(.{64})/).filter(Boolean),"-----END ENCRYPTED PRIVATE KEY-----"].join(`
|
|
23
|
+
`)}async function I2(t,e){let r=Ct.get(),n;if(t.includes("-----BEGIN ENCRYPTED PRIVATE KEY-----")){let i=U(t.replace("-----BEGIN ENCRYPTED PRIVATE KEY-----","").replace("-----END ENCRYPTED PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:o}=xt(i),{iv:s,salt:a,iterations:c,keySize:u,cipherText:l}=b3(o),f=await qn(Ir,e,a,{c,dkLen:u}),d=await r.subtle.importKey("raw",f,"AES-CBC",!1,["decrypt"]),p=Vc(await r.subtle.decrypt({name:"AES-CBC",iv:s},d,l)),{result:h}=xt(p);n=_2(h)}else if(t.includes("-----BEGIN PRIVATE KEY-----")){let i=U(t.replace("-----BEGIN PRIVATE KEY-----","").replace("-----END PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:o}=xt(i);n=_2(o)}else throw new x("Could not parse private key from PEM data","ERR_INVALID_PARAMETERS");return Tm(n)}function b3(t){let e=t.valueBlock.value[0];if(e.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.13")throw new x("Only pkcs5PBES2 encrypted private keys are supported","ERR_INVALID_PARAMS");let n=e.valueBlock.value[1].valueBlock.value[0];if(n.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.12")throw new x("Only pkcs5PBKDF2 key derivation functions are supported","ERR_INVALID_PARAMS");let o=n.valueBlock.value[1],s=Vc(o.valueBlock.value[0].getValue()),a=Bm,c=Rm;if(o.valueBlock.value.length===3)a=Number(o.valueBlock.value[1].toBigInt()),c=Number(o.valueBlock.value[2].toBigInt());else if(o.valueBlock.value.length===2)throw new x("Could not derive key size and iterations from PEM file - please use @libp2p/rsa to re-import your key","ERR_INVALID_PARAMS");let u=e.valueBlock.value[1].valueBlock.value[1],l=u.valueBlock.value[0].toString();if(l!=="OBJECT IDENTIFIER : 1.2.840.113549.3.7"){if(l!=="OBJECT IDENTIFIER : 1.3.14.3.2.7"){if(l!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.2"){if(l!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.22"){if(l!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.42")throw new x("Only AES-CBC encryption schemes are supported","ERR_INVALID_PARAMS")}}}}let f=Vc(u.valueBlock.value[1].getValue());return{cipherText:Vc(t.valueBlock.value[1].getValue()),salt:s,iterations:a,keySize:c,iv:f}}function _2(t){return Vc(t.valueBlock.value[2].getValue())}function Vc(t){return new Uint8Array(t,0,t.byteLength)}async function R2(t){let e=await Ct.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:t,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),r=await k2(e);return{privateKey:r[0],publicKey:r[1]}}async function km(t){let r=[await Ct.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),await w3(t)],n=await k2({privateKey:r[0],publicKey:r[1]});return{privateKey:n[0],publicKey:n[1]}}async function B2(t,e){let r=await Ct.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await Ct.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},r,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(n,0,n.byteLength)}async function T2(t,e,r){let n=await Ct.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return Ct.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,e,r instanceof Uint8Array?r:r.subarray())}async function k2(t){if(t.privateKey==null||t.publicKey==null)throw new x("Private and public key are required","ERR_INVALID_PARAMETERS");return Promise.all([Ct.get().subtle.exportKey("jwk",t.privateKey),Ct.get().subtle.exportKey("jwk",t.publicKey)])}async function w3(t){return Ct.get().subtle.importKey("jwk",{kty:t.kty,n:t.n,e:t.e},{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])}function Hf(t){if(t.kty!=="RSA")throw new x("invalid key type","ERR_INVALID_KEY_TYPE");if(t.n==null)throw new x("invalid key modulus","ERR_INVALID_KEY_MODULUS");return U(t.n,"base64url").length*8}var aa=8192,sa=class{_key;constructor(e){this._key=e}verify(e,r){return T2(this._key,r,e)}marshal(){return Vi.jwkToPkix(this._key)}get bytes(){return un.encode({Type:We.RSA,Data:this.marshal()}).subarray()}equals(e){return ie(this.bytes,e.bytes)}hash(){let e=ae.digest(this.bytes);return Cr(e)?e.then(({bytes:r})=>r):e.bytes}},No=class{_key;_publicKey;constructor(e,r){this._key=e,this._publicKey=r}genSecret(){return Do(16)}sign(e){return B2(this._key,e)}get public(){if(this._publicKey==null)throw new x("public key not provided","ERR_PUBKEY_NOT_PROVIDED");return new sa(this._publicKey)}marshal(){return Vi.jwkToPkcs1(this._key)}get bytes(){return ln.encode({Type:We.RSA,Data:this.marshal()}).subarray()}equals(e){return ie(this.bytes,e.bytes)}hash(){let e=ae.digest(this.bytes);return Cr(e)?e.then(({bytes:r})=>r):e.bytes}async id(){let e=await this.public.hash();return z(e,"base58btc")}async export(e,r="pkcs-8"){if(r==="pkcs-8")return Vi.exportToPem(this,e);if(r==="libp2p-key")return na(this.bytes,e);throw new x(`export format '${r}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};async function Tm(t){let e=Vi.pkcs1ToJwk(t);if(Hf(e)>aa)throw new x("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let r=await km(e);return new No(r.privateKey,r.publicKey)}function v3(t){let e=Vi.pkixToJwk(t);if(Hf(e)>aa)throw new x("key size is too large","ERR_KEY_SIZE_TOO_LARGE");return new sa(e)}async function E3(t){if(Hf(t)>aa)throw new x("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await km(t);return new No(e.privateKey,e.publicKey)}async function A3(t){if(t>aa)throw new x("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await R2(t);return new No(e.privateKey,e.publicKey)}var Dm={};Y(Dm,{Secp256k1PrivateKey:()=>ua,Secp256k1PublicKey:()=>ca,generateKeyPair:()=>R3,unmarshalSecp256k1PrivateKey:()=>_3,unmarshalSecp256k1PublicKey:()=>I3});function C2(){return he.utils.randomPrivateKey()}function P2(t,e){let r=ae.digest(e instanceof Uint8Array?e:e.subarray());if(Cr(r))return r.then(({digest:n})=>he.sign(n,t).toDERRawBytes()).catch(n=>{throw new x(String(n),"ERR_INVALID_INPUT")});try{return he.sign(r.digest,t).toDERRawBytes()}catch(n){throw new x(String(n),"ERR_INVALID_INPUT")}}function D2(t,e,r){let n=ae.digest(r instanceof Uint8Array?r:r.subarray());if(Cr(n))return n.then(({digest:i})=>he.verify(e,i,t)).catch(i=>{throw new x(String(i),"ERR_INVALID_INPUT")});try{return he.verify(e,n.digest,t)}catch(i){throw new x(String(i),"ERR_INVALID_INPUT")}}function N2(t){return he.ProjectivePoint.fromHex(t).toRawBytes(!0)}function L2(t){try{he.getPublicKey(t,!0)}catch(e){throw new x(String(e),"ERR_INVALID_PRIVATE_KEY")}}function Pm(t){try{he.ProjectivePoint.fromHex(t)}catch(e){throw new x(String(e),"ERR_INVALID_PUBLIC_KEY")}}function O2(t){try{return he.getPublicKey(t,!0)}catch(e){throw new x(String(e),"ERR_INVALID_PRIVATE_KEY")}}var ca=class{_key;constructor(e){Pm(e),this._key=e}verify(e,r){return D2(this._key,r,e)}marshal(){return N2(this._key)}get bytes(){return un.encode({Type:We.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return ie(this.bytes,e.bytes)}async hash(){let e=ae.digest(this.bytes),r;return Cr(e)?{bytes:r}=await e:r=e.bytes,r}},ua=class{_key;_publicKey;constructor(e,r){this._key=e,this._publicKey=r??O2(e),L2(this._key),Pm(this._publicKey)}sign(e){return P2(this._key,e)}get public(){return new ca(this._publicKey)}marshal(){return this._key}get bytes(){return ln.encode({Type:We.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return ie(this.bytes,e.bytes)}hash(){let e=ae.digest(this.bytes);return Cr(e)?e.then(({bytes:r})=>r):e.bytes}async id(){let e=await this.public.hash();return z(e,"base58btc")}async export(e,r="libp2p-key"){if(r==="libp2p-key")return na(this.bytes,e);throw new x(`export format '${r}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function _3(t){return new ua(t)}function I3(t){return new ca(t)}async function R3(){let t=C2();return new ua(t)}var Lo={rsa:Cm,ed25519:Im,secp256k1:Dm};function U2(t){let e=Object.keys(Lo).join(" / ");return new x(`invalid or unsupported key type ${t}. Must be ${e}`,"ERR_UNSUPPORTED_KEY_TYPE")}function K2(t){let e=un.decode(t),r=e.Data??new Uint8Array;switch(e.Type){case We.RSA:return Lo.rsa.unmarshalRsaPublicKey(r);case We.Ed25519:return Lo.ed25519.unmarshalEd25519PublicKey(r);case We.Secp256k1:return Lo.secp256k1.unmarshalSecp256k1PublicKey(r);default:throw U2(e.Type??"unknown")}}async function M2(t){let e=ln.decode(t),r=e.Data??new Uint8Array;switch(e.Type){case We.RSA:return Lo.rsa.unmarshalRsaPrivateKey(r);case We.Ed25519:return Lo.ed25519.unmarshalEd25519PrivateKey(r);case We.Secp256k1:return Lo.secp256k1.unmarshalSecp256k1PrivateKey(r);default:throw U2(e.Type??"RSA")}}var F2={ERR_SIGNATURE_NOT_VALID:"ERR_SIGNATURE_NOT_VALID"};var Hc;(function(t){let e;t.codec=()=>(e==null&&(e=Ee((r,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),r.publicKey!=null&&r.publicKey.byteLength>0&&(n.uint32(10),n.bytes(r.publicKey)),r.payloadType!=null&&r.payloadType.byteLength>0&&(n.uint32(18),n.bytes(r.payloadType)),r.payload!=null&&r.payload.byteLength>0&&(n.uint32(26),n.bytes(r.payload)),r.signature!=null&&r.signature.byteLength>0&&(n.uint32(42),n.bytes(r.signature)),i.lengthDelimited!==!1&&n.ldelim()},(r,n)=>{let i={publicKey:new Uint8Array(0),payloadType:new Uint8Array(0),payload:new Uint8Array(0),signature:new Uint8Array(0)},o=n==null?r.len:r.pos+n;for(;r.pos<o;){let s=r.uint32();switch(s>>>3){case 1:i.publicKey=r.bytes();break;case 2:i.payloadType=r.bytes();break;case 3:i.payload=r.bytes();break;case 5:i.signature=r.bytes();break;default:r.skipType(s&7);break}}return i})),e),t.encode=r=>ve(r,t.codec()),t.decode=r=>xe(r,t.codec())})(Hc||(Hc={}));var la=class t{static createFromProtobuf=async e=>{let r=Hc.decode(e),n=await Of(r.publicKey);return new t({peerId:n,payloadType:r.payloadType,payload:r.payload,signature:r.signature})};static seal=async(e,r)=>{if(r.privateKey==null)throw new Error("Missing private key");let n=e.domain,i=e.codec,o=e.marshal(),s=V2(n,i,o),c=await(await M2(r.privateKey)).sign(s.subarray());return new t({peerId:r,payloadType:i,payload:o,signature:c})};static openAndCertify=async(e,r)=>{let n=await t.createFromProtobuf(e);if(!await n.validate(r))throw new x("envelope signature is not valid for the given domain",F2.ERR_SIGNATURE_NOT_VALID);return n};peerId;payloadType;payload;signature;marshaled;constructor(e){let{peerId:r,payloadType:n,payload:i,signature:o}=e;this.peerId=r,this.payloadType=n,this.payload=i,this.signature=o}marshal(){if(this.peerId.publicKey==null)throw new Error("Missing public key");return this.marshaled==null&&(this.marshaled=Hc.encode({publicKey:this.peerId.publicKey,payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(e){return ie(this.marshal(),e.marshal())}async validate(e){let r=V2(e,this.payloadType,this.payload);if(this.peerId.publicKey==null)throw new Error("Missing public key");return K2(this.peerId.publicKey).verify(r.subarray(),this.signature)}},V2=(t,e,r)=>{let n=U(t),i=tr(n.byteLength),o=tr(e.length),s=tr(r.length);return new bt(i,n,o,e,s,r)};function H2(t,e){let r=(n,i)=>n.toString().localeCompare(i.toString());return t.length!==e.length?!1:(e.sort(r),t.sort(r).every((n,i)=>e[i].equals(n)))}var qf=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let r=this.index,n=e();return n===void 0&&(this.index=r),n}parseWith(e){let r=e();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let r=this.readChar();if(r===e)return r})}readSeparator(e,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,r,n,i){return this.readAtomically(()=>{let o=0,s=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*i)-1;for(;;){let l=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let d=Number.parseInt(f,e);if(!Number.isNaN(d))return d});if(l===void 0)break;if(o*=e,o+=l,o>u||(s+=1,r!==void 0&&s>r))return}if(s!==0)return!n&&c&&s>1?void 0:o})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let r=0;r<e.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[r]=n}return e})}readIPv6Addr(){let e=r=>{for(let n=0;n<r.length/2;n++){let i=n*2;if(n<r.length-3){let s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return r[i]=s[0],r[i+1]=s[1],r[i+2]=s[2],r[i+3]=s[3],[i+4,!0]}let o=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(o===void 0)return[i,!1];r[i]=o>>8,r[i+1]=o&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,i]=e(r);if(n===16)return r;if(i||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let o=new Uint8Array(14),s=16-(n+2),[a]=e(o.subarray(0,s));return r.set(o.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var q2=45,B3=15,fa=new qf;function Nm(t){if(!(t.length>B3))return fa.new(t).parseWith(()=>fa.readIPv4Addr())}function Lm(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>q2))return fa.new(t).parseWith(()=>fa.readIPv6Addr())}function $f(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>q2))return fa.new(t).parseWith(()=>fa.readIPAddr())}var yZ=parseInt("0xFFFF",16),gZ=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function zf(t){return!!Nm(t)}function Gf(t){return!!Lm(t)}function ha(t){return!!$f(t)}var G2=zf,D3=Gf,Om=function(t){let e=0;if(t=t.toString().trim(),G2(t)){let r=new Uint8Array(e+4);return t.split(/\./g).forEach(n=>{r[e++]=parseInt(n,10)&255}),r}if(D3(t)){let r=t.split(":",8),n;for(n=0;n<r.length;n++){let o=G2(r[n]),s;o&&(s=Om(r[n]),r[n]=z(s.slice(0,2),"base16")),s!=null&&++n<8&&r.splice(n,0,z(s.slice(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let o=[n,1];for(n=9-r.length;n>0;n--)o.push("0");r.splice.apply(r,o)}let i=new Uint8Array(e+16);for(n=0;n<r.length;n++){let o=parseInt(r[n],16);i[e++]=o>>8&255,i[e++]=o&255}return i}throw new Error("invalid ip address")},W2=function(t,e=0,r){e=~~e,r=r??t.length-e;let n=new DataView(t.buffer);if(r===4){let i=[];for(let o=0;o<r;o++)i.push(t[e+o]);return i.join(".")}if(r===16){let i=[];for(let o=0;o<r;o+=2)i.push(n.getUint16(e+o).toString(16));return i.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var da={},Um={},L3=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[777,-1,"memory"]];L3.forEach(t=>{let e=O3(...t);Um[e.code]=e,da[e.name]=e});function O3(t,e,r,n,i){return{code:t,size:e,name:r,resolvable:!!n,path:!!i}}function Pe(t){if(typeof t=="number"){if(Um[t]!=null)return Um[t];throw new Error(`no protocol with code: ${t}`)}else if(typeof t=="string"){if(da[t]!=null)return da[t];throw new Error(`no protocol with name: ${t}`)}throw new Error(`invalid protocol id type: ${typeof t}`)}var eee=Pe("ip4"),tee=Pe("ip6"),ree=Pe("ipcidr");function Mm(t,e){switch(Pe(t).code){case 4:case 41:return K3(e);case 42:return Q2(e);case 6:case 273:case 33:case 132:return X2(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Q2(e);case 421:return H3(e);case 444:return J2(e);case 445:return J2(e);case 466:return V3(e);default:return z(e,"base16")}}function Fm(t,e){switch(Pe(t).code){case 4:return Y2(e);case 41:return Y2(e);case 42:return j2(e);case 6:case 273:case 33:case 132:return Vm(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return j2(e);case 421:return M3(e);case 444:return q3(e);case 445:return $3(e);case 466:return F3(e);default:return U(e,"base16")}}var Km=Object.values(wi).map(t=>t.decoder),U3=function(){let t=Km[0].or(Km[1]);return Km.slice(2).forEach(e=>t=t.or(e)),t}();function Y2(t){if(!ha(t))throw new Error("invalid ip address");return Om(t)}function K3(t){let e=W2(t,0,t.length);if(e==null)throw new Error("ipBuff is required");if(!ha(e))throw new Error("invalid ip address");return e}function Vm(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,t),new Uint8Array(e)}function X2(t){return new DataView(t.buffer).getUint16(t.byteOffset)}function j2(t){let e=U(t),r=Uint8Array.from(tr(e.length));return ke([r,e],r.length+e.length)}function Q2(t){let e=Ur(t);if(t=t.slice(Ft(e)),t.length!==e)throw new Error("inconsistent lengths");return z(t)}function M3(t){let e;t[0]==="Q"||t[0]==="1"?e=kn(Oe.decode(`z${t}`)).bytes:e=Fe.parse(t).multihash.bytes;let r=Uint8Array.from(tr(e.length));return ke([r,e],r.length+e.length)}function F3(t){let e=U3.decode(t),r=Uint8Array.from(tr(e.length));return ke([r,e],r.length+e.length)}function V3(t){let e=Ur(t),r=t.slice(Ft(e));if(r.length!==e)throw new Error("inconsistent lengths");return"u"+z(r,"base64url")}function H3(t){let e=Ur(t),r=t.slice(Ft(e));if(r.length!==e)throw new Error("inconsistent lengths");return z(r,"base58btc")}function q3(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let r=dt.decode("b"+e[0]),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let i=Vm(n);return ke([r,i],r.length+i.length)}function $3(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let r=dt.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let i=Vm(n);return ke([r,i],r.length+i.length)}function J2(t){let e=t.slice(0,t.length-2),r=t.slice(t.length-2),n=z(e,"base32"),i=X2(r);return`${n}:${i}`}function Z2(t){t=Hm(t);let e=[],r=[],n=null,i=t.split("/").slice(1);if(i.length===1&&i[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let o=0;o<i.length;o++){let s=i[o],a=Pe(s);if(a.size===0){e.push([a.code]),r.push([a.code]);continue}if(o++,o>=i.length)throw tA("invalid address: "+t);if(a.path===!0){n=Hm(i.slice(o).join("/")),e.push([a.code,Fm(a.code,n)]),r.push([a.code,n]);break}let c=Fm(a.code,i[o]);e.push([a.code,c]),r.push([a.code,Mm(a.code,c)])}return{string:eA(r),bytes:$m(e),tuples:e,stringTuples:r,path:n}}function qm(t){let e=[],r=[],n=null,i=0;for(;i<t.length;){let o=Ur(t,i),s=Ft(o),a=Pe(o),c=z3(a,t.slice(i+s));if(c===0){e.push([o]),r.push([o]),i+=s;continue}let u=t.slice(i+s,i+s+c);if(i+=c+s,i>t.length)throw tA("Invalid address Uint8Array: "+z(t,"base16"));e.push([o,u]);let l=Mm(o,u);if(r.push([o,l]),a.path===!0){n=l;break}}return{bytes:Uint8Array.from(t),string:eA(r),tuples:e,stringTuples:r,path:n}}function eA(t){let e=[];return t.map(r=>{let n=Pe(r[0]);return e.push(n.name),r.length>1&&r[1]!=null&&e.push(r[1]),null}),Hm(e.join("/"))}function $m(t){return ke(t.map(e=>{let r=Pe(e[0]),n=Uint8Array.from(tr(r.code));return e.length>1&&e[1]!=null&&(n=ke([n,e[1]])),n}))}function z3(t,e){if(t.size>0)return t.size/8;if(t.size===0)return 0;{let r=Ur(e instanceof Uint8Array?e:Uint8Array.from(e));return r+Ft(r)}}function Hm(t){return"/"+t.trim().split("/").filter(e=>e).join("/")}function tA(t){return new Error("Error parsing address: "+t)}var G3=Symbol.for("nodejs.util.inspect.custom"),zm=Symbol.for("@multiformats/js-multiaddr/multiaddr"),W3=[Pe("dns").code,Pe("dns4").code,Pe("dns6").code,Pe("dnsaddr").code],Wf=class t{bytes;#e;#t;#r;#s;[zm]=!0;constructor(e){e==null&&(e="");let r;if(e instanceof Uint8Array)r=qm(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);r=Z2(e)}else if(Hi(e))r=qm(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=r.bytes,this.#e=r.string,this.#t=r.tuples,this.#r=r.stringTuples,this.#s=r.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,r,n,i,o="",s=Pe("tcp"),a=Pe("udp"),c=Pe("ip4"),u=Pe("ip6"),l=Pe("dns6"),f=Pe("ip6zone");for(let[p,h]of this.stringTuples())p===f.code&&(o=`%${h??""}`),W3.includes(p)&&(r=s.name,i=443,n=`${h??""}${o}`,e=p===l.code?6:4),(p===s.code||p===a.code)&&(r=Pe(p).name,i=parseInt(h??"")),(p===c.code||p===u.code)&&(r=Pe(p).name,n=`${h??""}${o}`,e=p===u.code?6:4);if(e==null||r==null||n==null||i==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:r,port:i}}protos(){return this.#t.map(([e])=>Object.assign({},Pe(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>Pe(e).name)}tuples(){return this.#t}stringTuples(){return this.#r}encapsulate(e){return e=new t(e),new t(this.toString()+e.toString())}decapsulate(e){let r=e.toString(),n=this.toString(),i=n.lastIndexOf(r);if(i<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new t(n.slice(0,i))}decapsulateCode(e){let r=this.tuples();for(let n=r.length-1;n>=0;n--)if(r[n][0]===e)return new t($m(r.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,i])=>{n===da.p2p.code&&e.push([n,i]),n===da["p2p-circuit"].code&&(e=[])});let r=e.pop();if(r?.[1]!=null){let n=r[1];return n[0]==="Q"||n[0]==="1"?z(Oe.decode(`z${n}`),"base58btc"):z(Fe.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#s}equals(e){return ie(this.bytes,e.bytes)}async resolve(e){let r=this.protos().find(o=>o.resolvable);if(r==null)return[this];let n=Yf.get(r.name);if(n==null)throw new x(`no available resolver for ${r.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,e)).map(o=>new t(o))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(e){let r=(e??this).protos();return!(r.length!==2||r[0].code!==4&&r[0].code!==41||r[1].code!==6&&r[1].code!==273)}[G3](){return`Multiaddr(${this.#e})`}};var Yf=new Map;function Hi(t){return!!t?.[zm]}function Ke(t){return new Wf(t)}var rA="libp2p-peer-record",nA=Uint8Array.from([3,1]);var qc;(function(t){let e;(function(n){let i;n.codec=()=>(i==null&&(i=Ee((o,s,a={})=>{a.lengthDelimited!==!1&&s.fork(),o.multiaddr!=null&&o.multiaddr.byteLength>0&&(s.uint32(10),s.bytes(o.multiaddr)),a.lengthDelimited!==!1&&s.ldelim()},(o,s)=>{let a={multiaddr:new Uint8Array(0)},c=s==null?o.len:o.pos+s;for(;o.pos<c;){let u=o.uint32();switch(u>>>3){case 1:a.multiaddr=o.bytes();break;default:o.skipType(u&7);break}}return a})),i),n.encode=o=>ve(o,n.codec()),n.decode=o=>xe(o,n.codec())})(e=t.AddressInfo||(t.AddressInfo={}));let r;t.codec=()=>(r==null&&(r=Ee((n,i,o={})=>{if(o.lengthDelimited!==!1&&i.fork(),n.peerId!=null&&n.peerId.byteLength>0&&(i.uint32(10),i.bytes(n.peerId)),n.seq!=null&&n.seq!==0n&&(i.uint32(16),i.uint64(n.seq)),n.addresses!=null)for(let s of n.addresses)i.uint32(26),t.AddressInfo.codec().encode(s,i);o.lengthDelimited!==!1&&i.ldelim()},(n,i)=>{let o={peerId:new Uint8Array(0),seq:0n,addresses:[]},s=i==null?n.len:n.pos+i;for(;n.pos<s;){let a=n.uint32();switch(a>>>3){case 1:o.peerId=n.bytes();break;case 2:o.seq=n.uint64();break;case 3:o.addresses.push(t.AddressInfo.codec().decode(n,n.uint32()));break;default:n.skipType(a&7);break}}return o})),r),t.encode=n=>ve(n,t.codec()),t.decode=n=>xe(n,t.codec())})(qc||(qc={}));var Oo=class t{static createFromProtobuf=e=>{let r=qc.decode(e),n=Ws(r.peerId),i=(r.addresses??[]).map(s=>Ke(s.multiaddr)),o=r.seq;return new t({peerId:n,multiaddrs:i,seqNumber:o})};static DOMAIN=rA;static CODEC=nA;peerId;multiaddrs;seqNumber;domain=t.DOMAIN;codec=t.CODEC;marshaled;constructor(e){let{peerId:r,multiaddrs:n,seqNumber:i}=e;this.peerId=r,this.multiaddrs=n??[],this.seqNumber=i??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=qc.encode({peerId:this.peerId.toBytes(),seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(e=>({multiaddr:e.bytes}))})),this.marshaled}equals(e){return!(!(e instanceof t)||!this.peerId.equals(e.peerId)||this.seqNumber!==e.seqNumber||!H2(this.multiaddrs,e.multiaddrs))}};var Pt={ERR_INVALID_PARAMETERS:"ERR_INVALID_PARAMETERS"};var pa;(function(t){let e;(function(i){let o;i.codec=()=>(o==null&&(o=Ee((s,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),s.key!=null&&s.key!==""&&(a.uint32(10),a.string(s.key)),s.value!=null&&s.value.byteLength>0&&(a.uint32(18),a.bytes(s.value)),c.lengthDelimited!==!1&&a.ldelim()},(s,a)=>{let c={key:"",value:new Uint8Array(0)},u=a==null?s.len:s.pos+a;for(;s.pos<u;){let l=s.uint32();switch(l>>>3){case 1:c.key=s.string();break;case 2:c.value=s.bytes();break;default:s.skipType(l&7);break}}return c})),o),i.encode=s=>ve(s,i.codec()),i.decode=s=>xe(s,i.codec())})(e=t.Peer$metadataEntry||(t.Peer$metadataEntry={}));let r;(function(i){let o;i.codec=()=>(o==null&&(o=Ee((s,a,c={})=>{c.lengthDelimited!==!1&&a.fork(),s.key!=null&&s.key!==""&&(a.uint32(10),a.string(s.key)),s.value!=null&&(a.uint32(18),Qf.codec().encode(s.value,a)),c.lengthDelimited!==!1&&a.ldelim()},(s,a)=>{let c={key:""},u=a==null?s.len:s.pos+a;for(;s.pos<u;){let l=s.uint32();switch(l>>>3){case 1:c.key=s.string();break;case 2:c.value=Qf.codec().decode(s,s.uint32());break;default:s.skipType(l&7);break}}return c})),o),i.encode=s=>ve(s,i.codec()),i.decode=s=>xe(s,i.codec())})(r=t.Peer$tagsEntry||(t.Peer$tagsEntry={}));let n;t.codec=()=>(n==null&&(n=Ee((i,o,s={})=>{if(s.lengthDelimited!==!1&&o.fork(),i.addresses!=null)for(let a of i.addresses)o.uint32(10),jf.codec().encode(a,o);if(i.protocols!=null)for(let a of i.protocols)o.uint32(18),o.string(a);if(i.publicKey!=null&&(o.uint32(34),o.bytes(i.publicKey)),i.peerRecordEnvelope!=null&&(o.uint32(42),o.bytes(i.peerRecordEnvelope)),i.metadata!=null&&i.metadata.size!==0)for(let[a,c]of i.metadata.entries())o.uint32(50),t.Peer$metadataEntry.codec().encode({key:a,value:c},o);if(i.tags!=null&&i.tags.size!==0)for(let[a,c]of i.tags.entries())o.uint32(58),t.Peer$tagsEntry.codec().encode({key:a,value:c},o);s.lengthDelimited!==!1&&o.ldelim()},(i,o)=>{let s={addresses:[],protocols:[],metadata:new Map,tags:new Map},a=o==null?i.len:i.pos+o;for(;i.pos<a;){let c=i.uint32();switch(c>>>3){case 1:s.addresses.push(jf.codec().decode(i,i.uint32()));break;case 2:s.protocols.push(i.string());break;case 4:s.publicKey=i.bytes();break;case 5:s.peerRecordEnvelope=i.bytes();break;case 6:{let u=t.Peer$metadataEntry.codec().decode(i,i.uint32());s.metadata.set(u.key,u.value);break}case 7:{let u=t.Peer$tagsEntry.codec().decode(i,i.uint32());s.tags.set(u.key,u.value);break}default:i.skipType(c&7);break}}return s})),n),t.encode=i=>ve(i,t.codec()),t.decode=i=>xe(i,t.codec())})(pa||(pa={}));var jf;(function(t){let e;t.codec=()=>(e==null&&(e=Ee((r,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),r.multiaddr!=null&&r.multiaddr.byteLength>0&&(n.uint32(10),n.bytes(r.multiaddr)),r.isCertified!=null&&(n.uint32(16),n.bool(r.isCertified)),i.lengthDelimited!==!1&&n.ldelim()},(r,n)=>{let i={multiaddr:new Uint8Array(0)},o=n==null?r.len:r.pos+n;for(;r.pos<o;){let s=r.uint32();switch(s>>>3){case 1:i.multiaddr=r.bytes();break;case 2:i.isCertified=r.bool();break;default:r.skipType(s&7);break}}return i})),e),t.encode=r=>ve(r,t.codec()),t.decode=r=>xe(r,t.codec())})(jf||(jf={}));var Qf;(function(t){let e;t.codec=()=>(e==null&&(e=Ee((r,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),r.value!=null&&r.value!==0&&(n.uint32(8),n.uint32(r.value)),r.expiry!=null&&(n.uint32(16),n.uint64(r.expiry)),i.lengthDelimited!==!1&&n.ldelim()},(r,n)=>{let i={value:0},o=n==null?r.len:r.pos+n;for(;r.pos<o;){let s=r.uint32();switch(s>>>3){case 1:i.value=r.uint32();break;case 2:i.expiry=r.uint64();break;default:r.skipType(s&7);break}}return i})),e),t.encode=r=>ve(r,t.codec()),t.decode=r=>xe(r,t.codec())})(Qf||(Qf={}));function ma(t,e){let r=pa.decode(e);r.publicKey!=null&&t.publicKey==null&&(t=WE({...t,publicKey:t.publicKey}));let n=new Map,i=BigInt(Date.now());for(let[o,s]of r.tags.entries())s.expiry!=null&&s.expiry<i||n.set(o,s);return{...r,id:t,addresses:r.addresses.map(({multiaddr:o,isCertified:s})=>({multiaddr:Ke(o),isCertified:s??!1})),metadata:r.metadata,peerRecordEnvelope:r.peerRecordEnvelope??void 0,tags:n}}var Gm="/peers/";function ya(t){if(!Cu(t)||t.type==null)throw new x("Invalid PeerId",Pt.ERR_INVALID_PARAMETERS);let e=t.toCID().toString();return new pt(`${Gm}${e}`)}async function iA(t,e,r){let n=new Map;for(let i of r){if(i==null)continue;if(i.multiaddr instanceof Uint8Array&&(i.multiaddr=Ke(i.multiaddr)),!Hi(i.multiaddr))throw new x("Multiaddr was invalid",Pt.ERR_INVALID_PARAMETERS);if(!await e(t,i.multiaddr))continue;let o=i.isCertified??!1,s=i.multiaddr.toString(),a=n.get(s);a!=null?i.isCertified=a.isCertified||o:n.set(s,{multiaddr:i.multiaddr,isCertified:o})}return[...n.values()].sort((i,o)=>i.multiaddr.toString().localeCompare(o.multiaddr.toString())).map(({isCertified:i,multiaddr:o})=>({isCertified:i,multiaddr:o.bytes}))}async function Xf(t,e,r,n){if(e==null)throw new x("Invalid PeerData",Pt.ERR_INVALID_PARAMETERS);if(e.publicKey!=null&&t.publicKey!=null&&!ie(e.publicKey,t.publicKey))throw new x("publicKey bytes do not match peer id publicKey bytes",Pt.ERR_INVALID_PARAMETERS);let i=n.existingPeer;if(i!=null&&!t.equals(i.id))throw new x("peer id did not match existing peer id",Pt.ERR_INVALID_PARAMETERS);let o=i?.addresses??[],s=new Set(i?.protocols??[]),a=i?.metadata??new Map,c=i?.tags??new Map,u=i?.peerRecordEnvelope;if(r==="patch"){if((e.multiaddrs!=null||e.addresses!=null)&&(o=[],e.multiaddrs!=null&&o.push(...e.multiaddrs.map(f=>({isCertified:!1,multiaddr:f}))),e.addresses!=null&&o.push(...e.addresses)),e.protocols!=null&&(s=new Set(e.protocols)),e.metadata!=null){let f=e.metadata instanceof Map?[...e.metadata.entries()]:Object.entries(e.metadata);a=Jf(f,{validate:oA})}if(e.tags!=null){let f=e.tags instanceof Map?[...e.tags.entries()]:Object.entries(e.tags);c=Jf(f,{validate:sA,map:aA})}e.peerRecordEnvelope!=null&&(u=e.peerRecordEnvelope)}if(r==="merge"){if(e.multiaddrs!=null&&o.push(...e.multiaddrs.map(f=>({isCertified:!1,multiaddr:f}))),e.addresses!=null&&o.push(...e.addresses),e.protocols!=null&&(s=new Set([...s,...e.protocols])),e.metadata!=null){let f=e.metadata instanceof Map?[...e.metadata.entries()]:Object.entries(e.metadata);for(let[d,p]of f)p==null?a.delete(d):a.set(d,p);a=Jf([...a.entries()],{validate:oA})}if(e.tags!=null){let f=e.tags instanceof Map?[...e.tags.entries()]:Object.entries(e.tags),d=new Map(c);for(let[p,h]of f)h==null?d.delete(p):d.set(p,h);c=Jf([...d.entries()],{validate:sA,map:aA})}e.peerRecordEnvelope!=null&&(u=e.peerRecordEnvelope)}let l={addresses:await iA(t,n.addressFilter??(async()=>!0),o),protocols:[...s.values()].sort((f,d)=>f.localeCompare(d)),metadata:a,tags:c,publicKey:i?.id.publicKey??e.publicKey??t.publicKey,peerRecordEnvelope:u};return t.type!=="RSA"&&delete l.publicKey,l}function Jf(t,e){let r=new Map;for(let[n,i]of t)i!=null&&e.validate(n,i);for(let[n,i]of t.sort(([o],[s])=>o.localeCompare(s)))i!=null&&r.set(n,e.map?.(n,i)??i);return r}function oA(t,e){if(typeof t!="string")throw new x("Metadata key must be a string",Pt.ERR_INVALID_PARAMETERS);if(!(e instanceof Uint8Array))throw new x("Metadata value must be a Uint8Array",Pt.ERR_INVALID_PARAMETERS)}function sA(t,e){if(typeof t!="string")throw new x("Tag name must be a string",Pt.ERR_INVALID_PARAMETERS);if(e.value!=null){if(parseInt(`${e.value}`,10)!==e.value)throw new x("Tag value must be an integer",Pt.ERR_INVALID_PARAMETERS);if(e.value<0||e.value>100)throw new x("Tag value must be between 0-100",Pt.ERR_INVALID_PARAMETERS)}if(e.ttl!=null){if(parseInt(`${e.ttl}`,10)!==e.ttl)throw new x("Tag ttl must be an integer",Pt.ERR_INVALID_PARAMETERS);if(e.ttl<0)throw new x("Tag ttl must be between greater than 0",Pt.ERR_INVALID_PARAMETERS)}}function aA(t,e){let r;return e.expiry!=null&&(r=e.expiry),e.ttl!=null&&(r=BigInt(Date.now()+Number(e.ttl))),{value:e.value??0,expiry:r}}function Zf(t,e,r){let n=t.toString().split("/")[2],i=dt.decode(n),o=Ws(i),s=r.get(o);if(s!=null)return s;let a=ma(o,e);return r.set(o,a),a}function Y3(t,e){return t==null?{}:{prefix:Gm,filters:(t.filters??[]).map(r=>({key:n,value:i})=>r(Zf(n,i,e))),orders:(t.orders??[]).map(r=>(n,i)=>r(Zf(n.key,n.value,e),Zf(i.key,i.value,e)))}}var eh=class{peerId;datastore;lock;addressFilter;constructor(e,r={}){this.peerId=e.peerId,this.datastore=e.datastore,this.addressFilter=r.addressFilter,this.lock=Ec({name:"peer-store",singleProcess:!0})}async has(e){return this.datastore.has(ya(e))}async delete(e){if(this.peerId.equals(e))throw new x("Cannot delete self peer",Pt.ERR_INVALID_PARAMETERS);await this.datastore.delete(ya(e))}async load(e){let r=await this.datastore.get(ya(e));return ma(e,r)}async save(e,r){let{existingBuf:n,existingPeer:i}=await this.#e(e),o=await Xf(e,r,"patch",{addressFilter:this.addressFilter});return this.#t(e,o,n,i)}async patch(e,r){let{existingBuf:n,existingPeer:i}=await this.#e(e),o=await Xf(e,r,"patch",{addressFilter:this.addressFilter,existingPeer:i});return this.#t(e,o,n,i)}async merge(e,r){let{existingBuf:n,existingPeer:i}=await this.#e(e),o=await Xf(e,r,"merge",{addressFilter:this.addressFilter,existingPeer:i});return this.#t(e,o,n,i)}async*all(e){let r=new nr;for await(let{key:n,value:i}of this.datastore.query(Y3(e??{},r))){let o=Zf(n,i,r);o.id.equals(this.peerId)||(yield o)}}async#e(e){try{let r=await this.datastore.get(ya(e)),n=ma(e,r);return{existingBuf:r,existingPeer:n}}catch(r){if(r.code!=="ERR_NOT_FOUND")throw r}return{}}async#t(e,r,n,i){let o=pa.encode(r);return n!=null&&ie(o,n)?{peer:ma(e,o),previous:i,updated:!1}:(await this.datastore.put(ya(e),o),{peer:ma(e,o),previous:i,updated:!0})}};var th=class{store;events;peerId;log;constructor(e,r={}){this.log=e.logger.forComponent("libp2p:peer-store"),this.events=e.events,this.peerId=e.peerId,this.store=new eh(e,r)}async forEach(e,r){this.log.trace("forEach await read lock");let n=await this.store.lock.readLock();this.log.trace("forEach got read lock");try{for await(let i of this.store.all(r))e(i)}finally{this.log.trace("forEach release read lock"),n()}}async all(e){this.log.trace("all await read lock");let r=await this.store.lock.readLock();this.log.trace("all got read lock");try{return await Ic(this.store.all(e))}finally{this.log.trace("all release read lock"),r()}}async delete(e){this.log.trace("delete await write lock");let r=await this.store.lock.writeLock();this.log.trace("delete got write lock");try{await this.store.delete(e)}finally{this.log.trace("delete release write lock"),r()}}async has(e){this.log.trace("has await read lock");let r=await this.store.lock.readLock();this.log.trace("has got read lock");try{return await this.store.has(e)}finally{this.log.trace("has release read lock"),r()}}async get(e){this.log.trace("get await read lock");let r=await this.store.lock.readLock();this.log.trace("get got read lock");try{return await this.store.load(e)}finally{this.log.trace("get release read lock"),r()}}async save(e,r){this.log.trace("save await write lock");let n=await this.store.lock.writeLock();this.log.trace("save got write lock");try{let i=await this.store.save(e,r);return this.#e(e,i),i.peer}finally{this.log.trace("save release write lock"),n()}}async patch(e,r){this.log.trace("patch await write lock");let n=await this.store.lock.writeLock();this.log.trace("patch got write lock");try{let i=await this.store.patch(e,r);return this.#e(e,i),i.peer}finally{this.log.trace("patch release write lock"),n()}}async merge(e,r){this.log.trace("merge await write lock");let n=await this.store.lock.writeLock();this.log.trace("merge got write lock");try{let i=await this.store.merge(e,r);return this.#e(e,i),i.peer}finally{this.log.trace("merge release write lock"),n()}}async consumePeerRecord(e,r){let n=await la.openAndCertify(e,Oo.DOMAIN);if(r?.equals(n.peerId)===!1)return this.log("envelope peer id was not the expected peer id - expected: %p received: %p",r,n.peerId),!1;let i=Oo.createFromProtobuf(n.payload),o;try{o=await this.get(n.peerId)}catch(s){if(s.code!=="ERR_NOT_FOUND")throw s}if(o?.peerRecordEnvelope!=null){let s=await la.createFromProtobuf(o.peerRecordEnvelope),a=Oo.createFromProtobuf(s.payload);if(a.seqNumber>=i.seqNumber)return this.log("sequence number was lower or equal to existing sequence number - stored: %d received: %d",a.seqNumber,i.seqNumber),!1}return await this.patch(i.peerId,{peerRecordEnvelope:e,addresses:i.multiaddrs.map(s=>({isCertified:!0,multiaddr:s}))}),!0}#e(e,r){r.updated&&(this.peerId.equals(e)?this.events.safeDispatchEvent("self:peer:update",{detail:r}):this.events.safeDispatchEvent("peer:update",{detail:r}))}};function cA(t,e){let r;return function(){let n=function(){r=void 0,t()};clearTimeout(r),r=setTimeout(n,e)}}var j3=t=>t;function Wm(t,e){let r=t.getPeerId();return r!=null&&ut(r).equals(e)&&(t=t.decapsulate(Ke(`/p2p/${e.toString()}`))),t}var rh=class{log;components;listen;announce;observed;announceFilter;constructor(e,r={}){let{listen:n=[],announce:i=[]}=r;this.components=e,this.log=e.logger.forComponent("libp2p:address-manager"),this.listen=n.map(o=>o.toString()),this.announce=new Set(i.map(o=>o.toString())),this.observed=new Map,this.announceFilter=r.announceFilter??j3,this._updatePeerStoreAddresses=cA(this._updatePeerStoreAddresses.bind(this),1e3),e.events.addEventListener("transport:listening",()=>{this._updatePeerStoreAddresses()}),e.events.addEventListener("transport:close",()=>{this._updatePeerStoreAddresses()})}_updatePeerStoreAddresses(){let e=this.getAnnounceAddrs().concat(this.components.transportManager.getAddrs()).concat([...this.observed.entries()].filter(([r,n])=>n.confident).map(([r])=>Ke(r))).map(r=>r.getPeerId()===this.components.peerId.toString()?r.decapsulate(`/p2p/${this.components.peerId.toString()}`):r);this.components.peerStore.patch(this.components.peerId,{multiaddrs:e}).catch(r=>{this.log.error("error updating addresses",r)})}getListenAddrs(){return Array.from(this.listen).map(e=>Ke(e))}getAnnounceAddrs(){return Array.from(this.announce).map(e=>Ke(e))}getObservedAddrs(){return Array.from(this.observed).map(([e])=>Ke(e))}addObservedAddr(e){e=Wm(e,this.components.peerId);let r=e.toString();this.observed.has(r)||this.observed.set(r,{confident:!1})}confirmObservedAddr(e){e=Wm(e,this.components.peerId);let r=e.toString(),i=(this.observed.get(r)??{confident:!1}).confident;this.observed.set(r,{confident:!0}),i||this._updatePeerStoreAddresses()}removeObservedAddr(e){e=Wm(e,this.components.peerId);let r=e.toString();this.observed.delete(r)}getAddresses(){let e=this.getAnnounceAddrs().map(n=>n.toString());e.length===0&&(e=this.components.transportManager.getAddrs().map(n=>n.toString())),e=e.concat(Array.from(this.observed).filter(([n,i])=>i.confident).map(([n])=>n));let r=new Set(e);return this.announceFilter(Array.from(r).map(n=>Ke(n))).map(n=>n.protos().pop()?.path===!0||n.getPeerId()===this.components.peerId.toString()?n:n.encapsulate(`/p2p/${this.components.peerId.toString()}`))}};var Ym=class{components={};_started=!1;constructor(e={}){this.components={};for(let[r,n]of Object.entries(e))this.components[r]=n;this.components.logger==null&&(this.components.logger=Ku())}isStarted(){return this._started}async _invokeStartableMethod(e){await Promise.all(Object.values(this.components).filter(r=>Nu(r)).map(async r=>{await r[e]?.()}))}async beforeStart(){await this._invokeStartableMethod("beforeStart")}async start(){await this._invokeStartableMethod("start"),this._started=!0}async afterStart(){await this._invokeStartableMethod("afterStart")}async beforeStop(){await this._invokeStartableMethod("beforeStop")}async stop(){await this._invokeStartableMethod("stop"),this._started=!1}async afterStop(){await this._invokeStartableMethod("afterStop")}},Q3=["metrics","connectionProtector"],J3=["components","isStarted","beforeStart","start","afterStart","beforeStop","stop","afterStop","then","_invokeStartableMethod"];function uA(t={}){let e=new Ym(t);return new Proxy(e,{get(n,i,o){if(typeof i=="string"&&!J3.includes(i)){let s=e.components[i];if(s==null&&!Q3.includes(i))throw new x(`${i} not set`,"ERR_SERVICE_MISSING");return s}return Reflect.get(n,i,o)},set(n,i,o){return typeof i=="string"?e.components[i]=o:Reflect.set(n,i,o),!0}})}var yA=me(lA(),1);var fA="[a-fA-F\\d:]",qi=t=>t&&t.includeBoundaries?`(?:(?<=\\s|^)(?=${fA})|(?<=${fA})(?=\\s|$))`:"",zr="(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}",lt="[a-fA-F\\d]{1,4}",nh=`
|
|
24
|
+
(?:
|
|
25
|
+
(?:${lt}:){7}(?:${lt}|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8
|
|
26
|
+
(?:${lt}:){6}(?:${zr}|:${lt}|:)| // 1:2:3:4:5:6:: 1:2:3:4:5:6::8 1:2:3:4:5:6::8 1:2:3:4:5:6::1.2.3.4
|
|
27
|
+
(?:${lt}:){5}(?::${zr}|(?::${lt}){1,2}|:)| // 1:2:3:4:5:: 1:2:3:4:5::7:8 1:2:3:4:5::8 1:2:3:4:5::7:1.2.3.4
|
|
28
|
+
(?:${lt}:){4}(?:(?::${lt}){0,1}:${zr}|(?::${lt}){1,3}|:)| // 1:2:3:4:: 1:2:3:4::6:7:8 1:2:3:4::8 1:2:3:4::6:7:1.2.3.4
|
|
29
|
+
(?:${lt}:){3}(?:(?::${lt}){0,2}:${zr}|(?::${lt}){1,4}|:)| // 1:2:3:: 1:2:3::5:6:7:8 1:2:3::8 1:2:3::5:6:7:1.2.3.4
|
|
30
|
+
(?:${lt}:){2}(?:(?::${lt}){0,3}:${zr}|(?::${lt}){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4
|
|
31
|
+
(?:${lt}:){1}(?:(?::${lt}){0,4}:${zr}|(?::${lt}){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4
|
|
32
|
+
(?::(?:(?::${lt}){0,5}:${zr}|(?::${lt}){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4
|
|
33
|
+
)(?:%[0-9a-zA-Z]{1,})? // %eth0 %1
|
|
34
|
+
`.replace(/\s*\/\/.*$/gm,"").replace(/\n/g,"").trim(),X3=new RegExp(`(?:^${zr}$)|(?:^${nh}$)`),Z3=new RegExp(`^${zr}$`),eP=new RegExp(`^${nh}$`),jm=t=>t&&t.exact?X3:new RegExp(`(?:${qi(t)}${zr}${qi(t)})|(?:${qi(t)}${nh}${qi(t)})`,"g");jm.v4=t=>t&&t.exact?Z3:new RegExp(`${qi(t)}${zr}${qi(t)}`,"g");jm.v6=t=>t&&t.exact?eP:new RegExp(`${qi(t)}${nh}${qi(t)}`,"g");var hA=jm;var gA=me(pA(),1),{isValid:tP,parse:rP}=gA.default,nP=["0.0.0.0/8","10.0.0.0/8","100.64.0.0/10","127.0.0.0/8","169.254.0.0/16","172.16.0.0/12","192.0.0.0/24","192.0.0.0/29","192.0.0.8/32","192.0.0.9/32","192.0.0.10/32","192.0.0.170/32","192.0.0.171/32","192.0.2.0/24","192.31.196.0/24","192.52.193.0/24","192.88.99.0/24","192.168.0.0/16","192.175.48.0/24","198.18.0.0/15","198.51.100.0/24","203.0.113.0/24","240.0.0.0/4","255.255.255.255/32"],iP=nP.map(t=>new yA.Netmask(t));function oP(t){for(let e of iP)if(e.contains(t))return!0;return!1}function mA(t){return/^::$/.test(t)||/^::1$/.test(t)||/^::f{4}:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)||/^::f{4}:0.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(t)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(t)||/^ff([0-9a-fA-F]{2,2}):/i.test(t)}var bA=t=>{if(tP(t)){let e=rP(t);if(e.kind()==="ipv4")return oP(e.toNormalizedString());if(e.kind()==="ipv6")return mA(t)}else if(ha(t)&&hA.v6().test(t))return mA(t)};var oh=bA;function wA(t={}){return{denyDialPeer:async()=>!1,denyDialMultiaddr:async e=>{let r=e.stringTuples();return r[0][0]===4||r[0][0]===41?!!oh(`${r[0][1]}`):!1},denyInboundConnection:async()=>!1,denyOutboundConnection:async()=>!1,denyInboundEncryptedConnection:async()=>!1,denyOutboundEncryptedConnection:async()=>!1,denyInboundUpgradedConnection:async()=>!1,denyOutboundUpgradedConnection:async()=>!1,filterMultiaddrForPeer:async()=>!0,...t}}var sP=t=>t.toString().split("/").slice(1),zc=t=>({match:e=>e.length<1?!1:t(e[0])?e.slice(1):!1,pattern:"fn"}),it=t=>({match:e=>zc(r=>r===t).match(e),pattern:t}),ch=()=>({match:t=>zc(e=>typeof e=="string").match(t),pattern:"{string}"}),xA=()=>({match:t=>zc(e=>!isNaN(parseInt(e))).match(t),pattern:"{number}"}),Pr=()=>({match:t=>{if(t.length<2||t[0]!=="p2p"&&t[0]!=="ipfs")return!1;if(t[1].startsWith("Q")||t[1].startsWith("1"))try{Oe.decode(`z${t[1]}`)}catch{return!1}else return!1;return t.slice(2)},pattern:"/p2p/{peerid}"}),sh=()=>({match:t=>{if(t.length<2||t[0]!=="certhash")return!1;try{tp.decode(t[1])}catch{return!1}return t.slice(2)},pattern:"/certhash/{certhash}"}),dn=t=>({match:e=>{let r=t.match(e);return r===!1?e:r},pattern:`optional(${t.pattern})`}),pn=(...t)=>({match:e=>{let r;for(let n of t){let i=n.match(e);i!==!1&&(r==null||i.length<r.length)&&(r=i)}return r??!1},pattern:`or(${t.map(e=>e.pattern).join(", ")})`}),ot=(...t)=>({match:e=>{for(let r of t){let n=r.match(e);if(n===!1)return!1;e=n}return e},pattern:`and(${t.map(e=>e.pattern).join(", ")})`});function gt(...t){function e(i){let o=sP(i);for(let s of t){let a=s.match(o);if(a===!1)return!1;o=a}return o}function r(i){return e(i)!==!1}function n(i){let o=e(i);return o===!1?!1:o.length===0}return{matches:r,exactMatch:n}}var Jm=ot(it("dns4"),ch()),Xm=ot(it("dns6"),ch()),Zm=ot(it("dnsaddr"),ch()),vA=ot(it("dns"),ch()),$te=gt(Jm),zte=gt(Xm),Gte=gt(Zm),Wte=gt(pn(vA,Zm,Jm,Xm)),EA=ot(it("ip4"),zc(zf)),AA=ot(it("ip6"),zc(Gf)),SA=pn(EA,AA),Gc=pn(SA,vA,Jm,Xm,Zm),Yte=gt(Gc),jte=gt(EA),Qte=gt(AA),Jte=gt(SA),uh=ot(Gc,it("tcp"),xA()),Wc=ot(Gc,it("udp"),xA()),aP=pn(uh,Wc),Xte=gt(uh),Zte=gt(Wc),ey=ot(Wc,it("quic")),lh=ot(Wc,it("quic-v1")),cP=pn(ey,lh),ere=gt(ey),tre=gt(lh),Qm=pn(Gc,uh,Wc,ey,lh),_A=pn(ot(Qm,it("ws"),dn(Pr()))),rre=gt(_A),IA=pn(ot(Qm,it("wss"),dn(Pr())),ot(Qm,it("tls"),it("ws"),dn(Pr()))),nre=gt(IA),RA=ot(aP,it("webrtc-direct"),sh(),dn(sh()),dn(Pr())),ire=gt(RA),BA=ot(lh,it("webtransport"),sh(),sh(),dn(Pr())),ore=gt(BA),ah=pn(_A,IA,ot(uh,dn(Pr())),ot(cP,dn(Pr())),ot(Gc,dn(Pr())),RA,BA,Pr()),sre=gt(ah),uP=ot(ah,it("p2p-circuit"),Pr()),ty=gt(uP),lP=pn(ot(ah,it("p2p-circuit"),it("webrtc"),Pr()),ot(ah,it("webrtc"),dn(Pr())),it("webrtc")),are=gt(lP);function ry(t){try{let{address:e}=t.nodeAddress();return!!oh(e)}catch{return!0}}function fP(t,e){let r=ry(t.multiaddr),n=ry(e.multiaddr);return r&&!n?1:!r&&n?-1:0}function hP(t,e){return t.isCertified&&!e.isCertified?-1:!t.isCertified&&e.isCertified?1:0}function dP(t,e){let r=ty.exactMatch(t.multiaddr),n=ty.exactMatch(e.multiaddr);return r&&!n?1:!r&&n?-1:0}function ga(t,e){let r=fP(t,e);if(r!==0)return r;let n=dP(t,e);return n!==0?n:hP(t,e)}var iy=me(Uu(),1),oy=me(CA(),1);function fh(t,e,r){return`${t}?name=${e}&type=${r}`}async function PA(t,e){return await(await fetch(t,{headers:new Headers({accept:"application/dns-json"}),signal:e})).json()}function Uo(t,e){return`${e}_${t}`}var ny=Object.assign((0,iy.default)("dns-over-http-resolver"),{error:(0,iy.default)("dns-over-http-resolver:error")}),sy=class{_cache;_TXTcache;_servers;_request;_abortControllers;constructor(e={}){this._cache=new oy.default({max:e?.maxCache??100}),this._TXTcache=new oy.default({max:e?.maxCache??100}),this._servers=["https://cloudflare-dns.com/dns-query","https://dns.google/resolve"],this._request=e.request??PA,this._abortControllers=[]}cancel(){this._abortControllers.forEach(e=>{e.abort()})}getServers(){return this._servers}_getShuffledServers(){let e=[...this._servers];for(let r=e.length-1;r>0;r--){let n=Math.floor(Math.random()*r),i=e[r];e[r]=e[n],e[n]=i}return e}setServers(e){this._servers=e}async resolve(e,r="A"){switch(r){case"A":return this.resolve4(e);case"AAAA":return this.resolve6(e);case"TXT":return this.resolveTxt(e);default:throw new Error(`${r} is not supported`)}}async resolve4(e){let r="A",n=this._cache.get(Uo(e,r));if(n!=null)return n;let i=!1;for(let o of this._getShuffledServers()){let s=new AbortController;this._abortControllers.push(s);try{let a=await this._request(fh(o,e,r),s.signal),c=a.Answer.map(l=>l.data),u=Math.min(...a.Answer.map(l=>l.TTL));return this._cache.set(Uo(e,r),c,{ttl:u}),c}catch{s.signal.aborted&&(i=!0),ny.error(`${o} could not resolve ${e} record ${r}`)}finally{this._abortControllers=this._abortControllers.filter(a=>a!==s)}}throw i?Object.assign(new Error("queryA ECANCELLED"),{code:"ECANCELLED"}):new Error(`Could not resolve ${e} record ${r}`)}async resolve6(e){let r="AAAA",n=this._cache.get(Uo(e,r));if(n!=null)return n;let i=!1;for(let o of this._getShuffledServers()){let s=new AbortController;this._abortControllers.push(s);try{let a=await this._request(fh(o,e,r),s.signal),c=a.Answer.map(l=>l.data),u=Math.min(...a.Answer.map(l=>l.TTL));return this._cache.set(Uo(e,r),c,{ttl:u}),c}catch{s.signal.aborted&&(i=!0),ny.error(`${o} could not resolve ${e} record ${r}`)}finally{this._abortControllers=this._abortControllers.filter(a=>a!==s)}}throw i?Object.assign(new Error("queryAaaa ECANCELLED"),{code:"ECANCELLED"}):new Error(`Could not resolve ${e} record ${r}`)}async resolveTxt(e){let r="TXT",n=this._TXTcache.get(Uo(e,r));if(n!=null)return n;let i=!1;for(let o of this._getShuffledServers()){let s=new AbortController;this._abortControllers.push(s);try{let a=await this._request(fh(o,e,r),s.signal),c=a.Answer.map(l=>[l.data.replace(/['"]+/g,"")]),u=Math.min(...a.Answer.map(l=>l.TTL));return this._TXTcache.set(Uo(e,r),c,{ttl:u}),c}catch{s.signal.aborted&&(i=!0),ny.error(`${o} could not resolve ${e} record ${r}`)}finally{this._abortControllers=this._abortControllers.filter(a=>a!==s)}}throw i?Object.assign(new Error("queryTxt ECANCELLED"),{code:"ECANCELLED"}):new Error(`Could not resolve ${e} record ${r}`)}clearCache(){this._cache.clear(),this._TXTcache.clear()}},DA=sy;var NA=DA;var{code:bP}=Pe("dnsaddr");async function ba(t,e={}){let r=new NA;e.signal!=null&&e.signal.addEventListener("abort",()=>{r.cancel()});let n=t.getPeerId(),[,i]=t.stringTuples().find(([a])=>a===bP)??[];if(i==null)throw new Error("No hostname found in multiaddr");let s=(await r.resolveTxt(`_dnsaddr.${i}`)).flat().map(a=>a.split("=")[1]).filter(Boolean);return n!=null&&(s=s.filter(a=>a.includes(n))),s}var qA=me(HA(),1),ph=qA.default;var ei;(function(t){t.NOT_STARTED_YET="The libp2p node is not started yet",t.ERR_PROTECTOR_REQUIRED="Private network is enforced, but no protector was provided",t.NOT_FOUND="Not found"})(ei||(ei={}));var Q;(function(t){t.ERR_PROTECTOR_REQUIRED="ERR_PROTECTOR_REQUIRED",t.ERR_PEER_DIAL_INTERCEPTED="ERR_PEER_DIAL_INTERCEPTED",t.ERR_CONNECTION_INTERCEPTED="ERR_CONNECTION_INTERCEPTED",t.ERR_INVALID_PROTOCOLS_FOR_STREAM="ERR_INVALID_PROTOCOLS_FOR_STREAM",t.ERR_CONNECTION_ENDED="ERR_CONNECTION_ENDED",t.ERR_CONNECTION_FAILED="ERR_CONNECTION_FAILED",t.ERR_NODE_NOT_STARTED="ERR_NODE_NOT_STARTED",t.ERR_ALREADY_ABORTED="ERR_ALREADY_ABORTED",t.ERR_TOO_MANY_ADDRESSES="ERR_TOO_MANY_ADDRESSES",t.ERR_NO_VALID_ADDRESSES="ERR_NO_VALID_ADDRESSES",t.ERR_RELAYED_DIAL="ERR_RELAYED_DIAL",t.ERR_DIALED_SELF="ERR_DIALED_SELF",t.ERR_DISCOVERED_SELF="ERR_DISCOVERED_SELF",t.ERR_DUPLICATE_TRANSPORT="ERR_DUPLICATE_TRANSPORT",t.ERR_ENCRYPTION_FAILED="ERR_ENCRYPTION_FAILED",t.ERR_HOP_REQUEST_FAILED="ERR_HOP_REQUEST_FAILED",t.ERR_INVALID_KEY="ERR_INVALID_KEY",t.ERR_INVALID_MESSAGE="ERR_INVALID_MESSAGE",t.ERR_INVALID_PARAMETERS="ERR_INVALID_PARAMETERS",t.ERR_INVALID_PEER="ERR_INVALID_PEER",t.ERR_MUXER_UNAVAILABLE="ERR_MUXER_UNAVAILABLE",t.ERR_NOT_FOUND="ERR_NOT_FOUND",t.ERR_TRANSPORT_UNAVAILABLE="ERR_TRANSPORT_UNAVAILABLE",t.ERR_TRANSPORT_DIAL_FAILED="ERR_TRANSPORT_DIAL_FAILED",t.ERR_UNSUPPORTED_PROTOCOL="ERR_UNSUPPORTED_PROTOCOL",t.ERR_PROTOCOL_HANDLER_ALREADY_REGISTERED="ERR_PROTOCOL_HANDLER_ALREADY_REGISTERED",t.ERR_INVALID_MULTIADDR="ERR_INVALID_MULTIADDR",t.ERR_SIGNATURE_NOT_VALID="ERR_SIGNATURE_NOT_VALID",t.ERR_FIND_SELF="ERR_FIND_SELF",t.ERR_NO_ROUTERS_AVAILABLE="ERR_NO_ROUTERS_AVAILABLE",t.ERR_CONNECTION_NOT_MULTIPLEXED="ERR_CONNECTION_NOT_MULTIPLEXED",t.ERR_NO_DIAL_TOKENS="ERR_NO_DIAL_TOKENS",t.ERR_INVALID_CMS="ERR_INVALID_CMS",t.ERR_MISSING_KEYS="ERR_MISSING_KEYS",t.ERR_NO_KEY="ERR_NO_KEY",t.ERR_INVALID_KEY_NAME="ERR_INVALID_KEY_NAME",t.ERR_INVALID_KEY_TYPE="ERR_INVALID_KEY_TYPE",t.ERR_KEY_ALREADY_EXISTS="ERR_KEY_ALREADY_EXISTS",t.ERR_INVALID_KEY_SIZE="ERR_INVALID_KEY_SIZE",t.ERR_KEY_NOT_FOUND="ERR_KEY_NOT_FOUND",t.ERR_OLD_KEY_NAME_INVALID="ERR_OLD_KEY_NAME_INVALID",t.ERR_NEW_KEY_NAME_INVALID="ERR_NEW_KEY_NAME_INVALID",t.ERR_PASSWORD_REQUIRED="ERR_PASSWORD_REQUIRED",t.ERR_PEM_REQUIRED="ERR_PEM_REQUIRED",t.ERR_CANNOT_READ_KEY="ERR_CANNOT_READ_KEY",t.ERR_MISSING_PRIVATE_KEY="ERR_MISSING_PRIVATE_KEY",t.ERR_MISSING_PUBLIC_KEY="ERR_MISSING_PUBLIC_KEY",t.ERR_INVALID_OLD_PASS_TYPE="ERR_INVALID_OLD_PASS_TYPE",t.ERR_INVALID_NEW_PASS_TYPE="ERR_INVALID_NEW_PASS_TYPE",t.ERR_INVALID_PASS_LENGTH="ERR_INVALID_PASS_LENGTH",t.ERR_NOT_IMPLEMENTED="ERR_NOT_IMPLEMENTED",t.ERR_WRONG_PING_ACK="ERR_WRONG_PING_ACK",t.ERR_INVALID_RECORD="ERR_INVALID_RECORD",t.ERR_ALREADY_SUCCEEDED="ERR_ALREADY_SUCCEEDED",t.ERR_NO_HANDLER_FOR_PROTOCOL="ERR_NO_HANDLER_FOR_PROTOCOL",t.ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS="ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS",t.ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS="ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS",t.ERR_CONNECTION_DENIED="ERR_CONNECTION_DENIED",t.ERR_TRANSFER_LIMIT_EXCEEDED="ERR_TRANSFER_LIMIT_EXCEEDED"})(Q||(Q={}));var SP={addresses:{listen:[],announce:[],noAnnounce:[],announceFilter:t=>t},connectionManager:{resolvers:{dnsaddr:ba},addressSorter:ga},transportManager:{faultTolerance:hi.FATAL_ALL}};function $A(t){let e=ph(SP,t);if(e.connectionProtector===null&&globalThis.process?.env?.LIBP2P_FORCE_PNET!=null)throw new x(ei.ERR_PROTECTOR_REQUIRED,Q.ERR_PROTECTOR_REQUIRED);return e}var zA=()=>{let t=new Error("Delay aborted");return t.name="AbortError",t},_P=new WeakMap;function IP({clearTimeout:t,setTimeout:e}={}){return(r,{value:n,signal:i}={})=>{if(i?.aborted)return Promise.reject(zA());let o,s,a,c=t??clearTimeout,u=()=>{c(o),a(zA())},l=()=>{i&&i.removeEventListener("abort",u)},f=new Promise((d,p)=>{s=()=>{l(),d(n)},a=p,o=(e??setTimeout)(s,r)});return i&&i.addEventListener("abort",u,{once:!0}),_P.set(f,()=>{c(o),o=null,s()}),f}}var RP=IP(),GA=RP;var mh=class{memoryStorage;points;duration;blockDuration;execEvenly;execEvenlyMinDelayMs;keyPrefix;constructor(e={}){this.points=e.points??4,this.duration=e.duration??1,this.blockDuration=e.blockDuration??0,this.execEvenly=e.execEvenly??!1,this.execEvenlyMinDelayMs=e.execEvenlyMinDelayMs??this.duration*1e3/this.points,this.keyPrefix=e.keyPrefix??"rlflx",this.memoryStorage=new cy}async consume(e,r=1,n={}){let i=this.getKey(e),o=this._getKeySecDuration(n),s=this.memoryStorage.incrby(i,r,o);if(s.remainingPoints=Math.max(this.points-s.consumedPoints,0),s.consumedPoints>this.points)throw this.blockDuration>0&&s.consumedPoints<=this.points+r&&(s=this.memoryStorage.set(i,s.consumedPoints,this.blockDuration)),new x("Rate limit exceeded","ERR_RATE_LIMIT_EXCEEDED",s);if(this.execEvenly&&s.msBeforeNext>0&&!s.isFirstInDuration){let a=Math.ceil(s.msBeforeNext/(s.remainingPoints+2));a<this.execEvenlyMinDelayMs&&(a=s.consumedPoints*this.execEvenlyMinDelayMs),await GA(a)}return s}penalty(e,r=1,n={}){let i=this.getKey(e),o=this._getKeySecDuration(n),s=this.memoryStorage.incrby(i,r,o);return s.remainingPoints=Math.max(this.points-s.consumedPoints,0),s}reward(e,r=1,n={}){let i=this.getKey(e),o=this._getKeySecDuration(n),s=this.memoryStorage.incrby(i,-r,o);return s.remainingPoints=Math.max(this.points-s.consumedPoints,0),s}block(e,r){let n=r*1e3,i=this.points+1;return this.memoryStorage.set(this.getKey(e),i,r),{remainingPoints:0,msBeforeNext:n===0?-1:n,consumedPoints:i,isFirstInDuration:!1}}set(e,r,n=0){let i=(n>=0?n:this.duration)*1e3;return this.memoryStorage.set(this.getKey(e),r,n),{remainingPoints:0,msBeforeNext:i===0?-1:i,consumedPoints:r,isFirstInDuration:!1}}get(e){let r=this.memoryStorage.get(this.getKey(e));return r!=null&&(r.remainingPoints=Math.max(this.points-r.consumedPoints,0)),r}delete(e){this.memoryStorage.delete(this.getKey(e))}_getKeySecDuration(e){return e?.customDuration!=null&&e.customDuration>=0?e.customDuration:this.duration}getKey(e){return this.keyPrefix.length>0?`${this.keyPrefix}:${e}`:e}parseKey(e){return e.substring(this.keyPrefix.length)}},cy=class{storage;constructor(){this.storage=new Map}incrby(e,r,n){let i=this.storage.get(e);if(i!=null){let o=i.expiresAt!=null?i.expiresAt.getTime()-new Date().getTime():-1;return i.expiresAt==null||o>0?(i.value+=r,{remainingPoints:0,msBeforeNext:o,consumedPoints:i.value,isFirstInDuration:!1}):this.set(e,r,n)}return this.set(e,r,n)}set(e,r,n){let i=n*1e3,o=this.storage.get(e);o!=null&&clearTimeout(o.timeoutId);let s={value:r,expiresAt:i>0?new Date(Date.now()+i):void 0};return this.storage.set(e,s),i>0&&(s.timeoutId=setTimeout(()=>{this.storage.delete(e)},i),s.timeoutId.unref!=null&&s.timeoutId.unref()),{remainingPoints:0,msBeforeNext:i===0?-1:i,consumedPoints:s.value,isFirstInDuration:!0}}get(e){let r=this.storage.get(e);if(r!=null)return{remainingPoints:0,msBeforeNext:r.expiresAt!=null?r.expiresAt.getTime()-new Date().getTime():-1,consumedPoints:r.value,isFirstInDuration:!1}}delete(e){let r=this.storage.get(e);return r!=null?(r.timeoutId!=null&&clearTimeout(r.timeoutId),this.storage.delete(e),!0):!1}};function yh(t){if(Cu(t))return{peerId:t,multiaddrs:[]};Array.isArray(t)||(t=[t]);let e;if(t.length>0){let r=t[0].getPeerId();e=r==null?void 0:ut(r),t.forEach(n=>{if(!Hi(n))throw new x("Invalid Multiaddr",Q.ERR_INVALID_MULTIADDR);let i=n.getPeerId();if(i==null){if(e!=null)throw new x("Multiaddrs must all have the same peer id or have no peer id",Q.ERR_INVALID_PARAMETERS)}else{let o=ut(i);if(e==null||!e.equals(o))throw new x("Multiaddrs must all have the same peer id or have no peer id",Q.ERR_INVALID_PARAMETERS)}})}return{peerId:e,multiaddrs:t}}var gh=class extends Cn{has(e){return this.find(e)!=null}find(e){return this.queue.find(r=>e.equals(r.options.peerId))}};var bh="last-dial-failure";var wh=5,xh=100,vh=50,WA=1e3*60*7;var Ko={minConnections:wh,maxQueueLength:100,autoDialConcurrency:25,autoDialPriority:0,autoDialInterval:5e3,autoDialPeerRetryThreshold:WA,autoDialDiscoveredPeersDebounce:10},Eh=class{connectionManager;peerStore;queue;minConnections;autoDialPriority;autoDialIntervalMs;autoDialMaxQueueLength;autoDialPeerRetryThresholdMs;autoDialDiscoveredPeersDebounce;autoDialInterval;started;running;log;constructor(e,r){this.connectionManager=e.connectionManager,this.peerStore=e.peerStore,this.minConnections=r.minConnections??Ko.minConnections,this.autoDialPriority=r.autoDialPriority??Ko.autoDialPriority,this.autoDialIntervalMs=r.autoDialInterval??Ko.autoDialInterval,this.autoDialMaxQueueLength=r.maxQueueLength??Ko.maxQueueLength,this.autoDialPeerRetryThresholdMs=r.autoDialPeerRetryThreshold??Ko.autoDialPeerRetryThreshold,this.autoDialDiscoveredPeersDebounce=r.autoDialDiscoveredPeersDebounce??Ko.autoDialDiscoveredPeersDebounce,this.log=e.logger.forComponent("libp2p:connection-manager:auto-dial"),this.started=!1,this.running=!1,this.queue=new gh({concurrency:r.autoDialConcurrency??Ko.autoDialConcurrency,metricName:"libp2p_autodial_queue",metrics:e.metrics}),this.queue.addEventListener("error",i=>{this.log.error("error during auto-dial",i.detail)}),e.events.addEventListener("connection:close",()=>{this.autoDial().catch(i=>{this.log.error(i)})});let n;e.events.addEventListener("peer:discovery",()=>{clearTimeout(n),n=setTimeout(()=>{this.autoDial().catch(i=>{this.log.error(i)})},this.autoDialDiscoveredPeersDebounce)})}isStarted(){return this.started}start(){this.started=!0}afterStart(){this.autoDial().catch(e=>{this.log.error("error while autodialing",e)})}stop(){this.queue.clear(),clearTimeout(this.autoDialInterval),this.started=!1,this.running=!1}async autoDial(){if(!this.started||this.running)return;let e=this.connectionManager.getConnectionsMap(),r=e.size;if(r>=this.minConnections){this.minConnections>0&&this.log.trace("have enough connections %d/%d",r,this.minConnections);return}if(this.queue.size>this.autoDialMaxQueueLength){this.log("not enough connections %d/%d but auto dial queue is full",r,this.minConnections),this.sheduleNextAutodial();return}this.running=!0,this.log("not enough connections %d/%d - will dial peers to increase the number of connections",r,this.minConnections);let n=new Tr(this.connectionManager.getDialQueue().map(u=>u.peerId).filter(Boolean)),i=await this.peerStore.all({filters:[u=>u.addresses.length===0?(this.log.trace("not autodialing %p because they have no addresses",u.id),!1):e.has(u.id)?(this.log.trace("not autodialing %p because they are already connected",u.id),!1):n.has(u.id)?(this.log.trace("not autodialing %p because they are already being dialed",u.id),!1):this.queue.has(u.id)?(this.log.trace("not autodialing %p because they are already being autodialed",u.id),!1):!0]}),o=i.sort(()=>Math.random()>.5?1:-1),s=new nr;for(let u of o)s.has(u.id)||s.set(u.id,[...u.tags.values()].reduce((l,f)=>l+f.value,0));let c=o.sort((u,l)=>{let f=s.get(u.id)??0,d=s.get(l.id)??0;return f>d?-1:f<d?1:0}).filter(u=>{let l=u.metadata.get(bh);if(l==null)return!0;let f=parseInt(z(l));return isNaN(f)?!0:Date.now()-f>this.autoDialPeerRetryThresholdMs});this.log("selected %d/%d peers to dial",c.length,i.length);for(let u of c)this.queue.add(async()=>{let l=this.connectionManager.getConnectionsMap().size;if(l>=this.minConnections){this.log("got enough connections now %d/%d",l,this.minConnections),this.queue.clear();return}this.log("connecting to a peerStore stored peer %p",u.id),await this.connectionManager.openConnection(u.id,{priority:this.autoDialPriority})},{peerId:u.id}).catch(l=>{this.log.error("could not connect to peerStore stored peer",l)});this.running=!1,this.sheduleNextAutodial()}sheduleNextAutodial(){this.started&&(this.autoDialInterval=setTimeout(()=>{this.autoDial().catch(e=>{this.log.error("error while autodialing",e)})},this.autoDialIntervalMs))}};var YA={maxConnections:xh,allow:[]},Ah=class{maxConnections;connectionManager;peerStore;allow;events;log;constructor(e,r={}){this.maxConnections=r.maxConnections??YA.maxConnections,this.allow=r.allow??YA.allow,this.connectionManager=e.connectionManager,this.peerStore=e.peerStore,this.events=e.events,this.log=e.logger.forComponent("libp2p:connection-manager:connection-pruner"),e.events.addEventListener("connection:open",()=>{this.maybePruneConnections().catch(n=>{this.log.error(n)})})}async maybePruneConnections(){let e=this.connectionManager.getConnections(),r=e.length,n=Math.max(r-this.maxConnections,0);if(this.log("checking max connections limit %d/%d",r,this.maxConnections),r<=this.maxConnections)return;this.log("max connections limit exceeded %d/%d, pruning %d connection(s)",r,this.maxConnections,n);let i=new nr;for(let a of e){let c=a.remotePeer;if(!i.has(c)){i.set(c,0);try{let u=await this.peerStore.get(c);i.set(c,[...u.tags.values()].reduce((l,f)=>l+f.value,0))}catch(u){u.code!=="ERR_NOT_FOUND"&&this.log.error("error loading peer tags",u)}}}let o=e.sort((a,c)=>{let u=i.get(a.remotePeer)??0,l=i.get(c.remotePeer)??0;if(u>l)return 1;if(u<l)return-1;let f=a.timeline.open,d=c.timeline.open;return f<d?1:f>d?-1:0}),s=[];for(let a of o)if(this.log("too many connections open - closing a connection to %p",a.remotePeer),this.allow.some(u=>a.remoteAddr.toString().startsWith(u.toString()))||s.push(a),s.length===n)break;await Promise.all(s.map(async a=>{try{await a.close()}catch(c){this.log.error(c)}})),this.events.safeDispatchEvent("connection:prune",{detail:s})}};async function hy(t,e){if(!t.protoNames().includes("dnsaddr"))return[t];let n=await kP(t,e),s=(await Promise.all(n.map(async a=>hy(a,e)))).flat().reduce((a,c)=>(a.find(u=>u.equals(c))==null&&a.push(c),a),[]);return e.log("resolved %s to",t,s.map(a=>a.toString())),s}async function kP(t,e){try{return t=Ke(t.toString()),await t.resolve(e)}catch(r){return e.log.error(`multiaddr ${t.toString()} could not be resolved`,r),[]}}var Sh={addressSorter:ga,maxParallelDials:vh,maxPeerAddrsToDial:25,dialTimeout:3e4,resolvers:{dnsaddr:ba}},_h=class{queue;components;addressSorter;maxPeerAddrsToDial;dialTimeout;shutDownController;connections;log;constructor(e,r={}){this.addressSorter=r.addressSorter??Sh.addressSorter,this.maxPeerAddrsToDial=r.maxPeerAddrsToDial??Sh.maxPeerAddrsToDial,this.dialTimeout=r.dialTimeout??Sh.dialTimeout,this.connections=r.connections??new nr,this.log=e.logger.forComponent("libp2p:connection-manager:dial-queue"),this.components=e,this.shutDownController=new AbortController,xr(1/0,this.shutDownController.signal);for(let[n,i]of Object.entries(r.resolvers??{}))Yf.set(n,i);this.queue=new Cn({concurrency:r.maxParallelDials??Sh.maxParallelDials,metricName:"libp2p_dial_queue",metrics:e.metrics}),this.queue.addEventListener("error",n=>{this.log.error("error in dial queue",n.detail)})}start(){this.shutDownController=new AbortController}stop(){this.shutDownController.abort(),this.queue.abort()}async dial(e,r={}){let{peerId:n,multiaddrs:i}=yh(e),o=Array.from(this.connections.values()).flat().find(a=>r.force===!0?!1:a.remotePeer.equals(n)?!0:i.find(c=>c.equals(a.remoteAddr)));if(o!=null)return this.log("already connected to %a",o.remoteAddr),o;let s=this.queue.queue.find(a=>{if(n?.equals(a.options.peerId)===!0)return!0;let c=a.options.multiaddrs;if(c==null)return!1;for(let u of i)if(c.has(u.toString()))return!0;return!1});if(s!=null){this.log("joining existing dial target for %p",n);for(let a of i)s.options.multiaddrs.add(a.toString());return s.join(r)}return this.log("creating dial target for %p",n,i.map(a=>a.toString())),this.queue.add(async a=>{let c=this.createDialAbortController(a?.signal),u;try{u=await this.calculateMultiaddrs(n,a?.multiaddrs,{...a,signal:c}),u.map(({multiaddr:l})=>l.toString()).forEach(l=>{a?.multiaddrs.add(l)})}catch(l){throw c.clear(),l}try{let l=0,f=[];for(let d of u){if(l===this.maxPeerAddrsToDial)throw this.log("dialed maxPeerAddrsToDial (%d) addresses for %p, not trying any others",l,n),new x("Peer had more than maxPeerAddrsToDial",Q.ERR_TOO_MANY_ADDRESSES);l++;try{let p=await this.components.transportManager.dial(d.multiaddr,{...a,signal:c});return this.log("dial to %a succeeded",d.multiaddr),p}catch(p){if(this.log.error("dial failed to %a",d.multiaddr,p),n!=null)try{await this.components.peerStore.patch(n,{metadata:{[bh]:U(Date.now().toString())}})}catch(h){this.log.error("could not update last dial failure key for %p",n,h)}if(c.aborted)throw new x(p.message,Du);f.push(p)}}throw f.length===1?f[0]:new Pu(f,"All multiaddr dials failed",Q.ERR_TRANSPORT_DIAL_FAILED)}finally{c.clear()}},{peerId:n,priority:r.priority,multiaddrs:new Set(i.map(a=>a.toString())),signal:r.signal})}createDialAbortController(e){let r=Jr([AbortSignal.timeout(this.dialTimeout),this.shutDownController.signal,e]);return xr(1/0,r),r}async calculateMultiaddrs(e,r=new Set,n={}){let i=[...r].map(f=>({multiaddr:Ke(f),isCertified:!1}));if(e!=null){if(this.components.peerId.equals(e))throw new x("Tried to dial self",Q.ERR_DIALED_SELF);if(await this.components.connectionGater.denyDialPeer?.(e)===!0)throw new x("The dial request is blocked by gater.allowDialPeer",Q.ERR_PEER_DIAL_INTERCEPTED);if(i.length===0){this.log("loading multiaddrs for %p",e);try{let f=await this.components.peerStore.get(e);i.push(...f.addresses),this.log("loaded multiaddrs for %p",e,i.map(({multiaddr:d})=>d.toString()))}catch(f){if(f.code!==Q.ERR_NOT_FOUND)throw f}}if(i.length===0){this.log("looking up multiaddrs for %p in the peer routing",e);try{let f=await this.components.peerRouting.findPeer(e);this.log("found multiaddrs for %p in the peer routing",e,i.map(({multiaddr:d})=>d.toString())),i.push(...f.multiaddrs.map(d=>({multiaddr:d,isCertified:!1})))}catch(f){f.code!==Q.ERR_NO_ROUTERS_AVAILABLE&&this.log.error("looking up multiaddrs for %p in the peer routing failed",e,f)}}}let o=(await Promise.all(i.map(async f=>{let d=await hy(f.multiaddr,{...n,log:this.log});return d.length===1&&d[0].equals(f.multiaddr)?f:d.map(p=>({multiaddr:p,isCertified:!1}))}))).flat();if(e!=null){let f=`/p2p/${e.toString()}`;o=o.map(d=>d.multiaddr.protos().pop()?.path===!0?d:d.multiaddr.getPeerId()==null?{multiaddr:d.multiaddr.encapsulate(f),isCertified:d.isCertified}:d)}let s=o.filter(f=>{if(this.components.transportManager.transportForMultiaddr(f.multiaddr)==null)return!1;let d=f.multiaddr.getPeerId();return e!=null&&d!=null?e.equals(d):!0}),a=new Map;for(let f of s){let d=f.multiaddr.toString(),p=a.get(d);if(p!=null){p.isCertified=p.isCertified||f.isCertified||!1;continue}a.set(d,f)}let c=[...a.values()];if(c.length===0)throw new x("The dial request has no valid addresses",Q.ERR_NO_VALID_ADDRESSES);let u=[];for(let f of c)this.components.connectionGater.denyDialMultiaddr!=null&&await this.components.connectionGater.denyDialMultiaddr(f.multiaddr)||u.push(f);let l=u.sort(this.addressSorter);if(l.length===0)throw new x("The connection gater denied all addresses in the dial request",Q.ERR_NO_VALID_ADDRESSES);return this.log.trace("addresses for %p before filtering",e??"unknown peer",o.map(({multiaddr:f})=>f.toString())),this.log.trace("addresses for %p after filtering",e??"unknown peer",l.map(({multiaddr:f})=>f.toString())),l}};var DP=50,Mo={minConnections:wh,maxConnections:xh,inboundConnectionThreshold:5,maxIncomingPendingConnections:10,autoDialConcurrency:25,autoDialPriority:0,autoDialMaxQueueLength:100},Ih=class{started;connections;allow;deny;maxIncomingPendingConnections;incomingPendingConnections;maxConnections;dialQueue;autoDial;connectionPruner;inboundConnectionRateLimiter;peerStore;metrics;events;log;constructor(e,r={}){this.maxConnections=r.maxConnections??Mo.maxConnections;let n=r.minConnections??Mo.minConnections;if(this.maxConnections<n)throw new x("Connection Manager maxConnections must be greater than minConnections",Q.ERR_INVALID_PARAMETERS);this.connections=new nr,this.started=!1,this.peerStore=e.peerStore,this.metrics=e.metrics,this.events=e.events,this.log=e.logger.forComponent("libp2p:connection-manager"),this.onConnect=this.onConnect.bind(this),this.onDisconnect=this.onDisconnect.bind(this),this.events.addEventListener("connection:open",this.onConnect),this.events.addEventListener("connection:close",this.onDisconnect),this.allow=(r.allow??[]).map(i=>Ke(i)),this.deny=(r.deny??[]).map(i=>Ke(i)),this.incomingPendingConnections=0,this.maxIncomingPendingConnections=r.maxIncomingPendingConnections??Mo.maxIncomingPendingConnections,this.inboundConnectionRateLimiter=new mh({points:r.inboundConnectionThreshold??Mo.inboundConnectionThreshold,duration:1}),this.autoDial=new Eh({connectionManager:this,peerStore:e.peerStore,events:e.events,logger:e.logger},{minConnections:n,autoDialConcurrency:r.autoDialConcurrency??Mo.autoDialConcurrency,autoDialPriority:r.autoDialPriority??Mo.autoDialPriority,maxQueueLength:r.autoDialMaxQueueLength??Mo.autoDialMaxQueueLength}),this.connectionPruner=new Ah({connectionManager:this,peerStore:e.peerStore,events:e.events,logger:e.logger},{maxConnections:this.maxConnections,allow:this.allow}),this.dialQueue=new _h(e,{addressSorter:r.addressSorter??ga,maxParallelDials:r.maxParallelDials??vh,maxPeerAddrsToDial:r.maxPeerAddrsToDial??25,dialTimeout:r.dialTimeout??3e4,resolvers:r.resolvers??{dnsaddr:ba},connections:this.connections})}isStarted(){return this.started}async start(){this.metrics?.registerMetricGroup("libp2p_connection_manager_connections",{calculate:()=>{let e={inbound:0,outbound:0};for(let r of this.connections.values())for(let n of r)n.direction==="inbound"?e.inbound++:e.outbound++;return e}}),this.metrics?.registerMetricGroup("libp2p_protocol_streams_total",{label:"protocol",calculate:()=>{let e={};for(let r of this.connections.values())for(let n of r)for(let i of n.streams){let o=`${i.direction} ${i.protocol??"unnegotiated"}`;e[o]=(e[o]??0)+1}return e}}),this.metrics?.registerMetricGroup("libp2p_connection_manager_protocol_streams_per_connection_90th_percentile",{label:"protocol",calculate:()=>{let e={};for(let n of this.connections.values())for(let i of n){let o={};for(let s of i.streams){let a=`${s.direction} ${s.protocol??"unnegotiated"}`;o[a]=(o[a]??0)+1}for(let[s,a]of Object.entries(o))e[s]=e[s]??[],e[s].push(a)}let r={};for(let[n,i]of Object.entries(e)){i=i.sort((s,a)=>s-a);let o=Math.floor(i.length*.9);r[n]=i[o]}return r}}),this.dialQueue.start(),this.autoDial.start(),this.started=!0,this.log("started")}async afterStart(){Promise.resolve().then(async()=>{let e=await this.peerStore.all({filters:[r=>r.tags.has(Mb)]});await Promise.all(e.map(async r=>{await this.openConnection(r.id).catch(n=>{this.log.error(n)})}))}).catch(e=>{this.log.error(e)}),this.autoDial.afterStart()}async stop(){this.dialQueue.stop(),this.autoDial.stop();let e=[];for(let r of this.connections.values())for(let n of r)e.push((async()=>{try{await n.close()}catch(i){this.log.error(i)}})());this.log("closing %d connections",e.length),await Promise.all(e),this.connections.clear(),this.log("stopped")}onConnect(e){this._onConnect(e).catch(r=>{this.log.error(r)})}async _onConnect(e){let{detail:r}=e;if(!this.started){await r.close();return}let n=r.remotePeer,i=this.connections.get(n),o=!1;i!=null?i.push(r):(o=!0,this.connections.set(n,[r])),n.publicKey!=null&&n.type==="RSA"&&await this.peerStore.patch(n,{publicKey:n.publicKey}),o&&this.events.safeDispatchEvent("peer:connect",{detail:r.remotePeer})}onDisconnect(e){let{detail:r}=e;if(!this.started)return;let n=r.remotePeer,i=this.connections.get(n);i!=null&&i.length>1?(i=i.filter(o=>o.id!==r.id),this.connections.set(n,i)):i!=null&&(this.connections.delete(n),this.events.safeDispatchEvent("peer:disconnect",{detail:r.remotePeer}))}getConnections(e){if(e!=null)return this.connections.get(e)??[];let r=[];for(let n of this.connections.values())r=r.concat(n);return r}getConnectionsMap(){return this.connections}async openConnection(e,r={}){if(!this.isStarted())throw new x("Not started",Q.ERR_NODE_NOT_STARTED);r.signal?.throwIfAborted();let{peerId:n}=yh(e);if(n!=null&&r.force!==!0){this.log("dial %p",n);let a=this.getConnections(n).find(c=>!c.transient);if(a!=null)return this.log("had an existing non-transient connection to %p",n),a}let i=await this.dialQueue.dial(e,{...r,priority:r.priority??DP}),o=this.connections.get(i.remotePeer);o==null&&(o=[],this.connections.set(i.remotePeer,o));let s=!1;for(let a of o)a.id===i.id&&(s=!0);return s||o.push(i),i}async closeConnections(e,r={}){let n=this.connections.get(e)??[];await Promise.all(n.map(async i=>{try{await i.close(r)}catch(o){i.abort(o)}}))}async acceptIncomingConnection(e){if(this.deny.some(i=>e.remoteAddr.toString().startsWith(i.toString())))return this.log("connection from %a refused - connection remote address was in deny list",e.remoteAddr),!1;if(this.allow.some(i=>e.remoteAddr.toString().startsWith(i.toString())))return this.incomingPendingConnections++,!0;if(this.incomingPendingConnections===this.maxIncomingPendingConnections)return this.log("connection from %a refused - incomingPendingConnections exceeded by host",e.remoteAddr),!1;if(e.remoteAddr.isThinWaistAddress()){let i=e.remoteAddr.nodeAddress().address;try{await this.inboundConnectionRateLimiter.consume(i,1)}catch{return this.log("connection from %a refused - inboundConnectionThreshold exceeded by host %s",e.remoteAddr,i),!1}}return this.getConnections().length<this.maxConnections?(this.incomingPendingConnections++,!0):(this.log("connection from %a refused - maxConnections exceeded",e.remoteAddr),!1)}afterUpgradeInbound(){this.incomingPendingConnections--}getDialQueue(){let e={queued:"queued",running:"active",errored:"error",complete:"success"};return this.dialQueue.queue.queue.map(r=>({id:r.id,status:e[r.status],peerId:r.options.peerId,multiaddrs:[...r.options.multiaddrs].map(n=>Ke(n))}))}};var Rh=class{routers;started;components;constructor(e,r){this.routers=r.routers??[],this.started=!1,this.components=e}isStarted(){return this.started}async start(){this.started=!0}async stop(){this.started=!1}async*findProviders(e,r={}){if(this.routers.length===0)throw new x("No content routers available",Q.ERR_NO_ROUTERS_AVAILABLE);let n=this,i=new Tr;for await(let o of Ei(...n.routers.map(s=>s.findProviders(e,r))))o!=null&&(o.multiaddrs.length>0&&await this.components.peerStore.merge(o.id,{multiaddrs:o.multiaddrs}),!i.has(o.id)&&(i.add(o.id),yield o))}async provide(e,r={}){if(this.routers.length===0)throw new x("No content routers available",Q.ERR_NO_ROUTERS_AVAILABLE);await Promise.all(this.routers.map(async n=>{await n.provide(e,r)}))}async put(e,r,n){if(!this.isStarted())throw new x(ei.NOT_STARTED_YET,Q.ERR_NODE_NOT_STARTED);await Promise.all(this.routers.map(async i=>{await i.put(e,r,n)}))}async get(e,r){if(!this.isStarted())throw new x(ei.NOT_STARTED_YET,Q.ERR_NODE_NOT_STARTED);return Promise.any(this.routers.map(async n=>n.get(e,r)))}};var Bh=globalThis.CustomEvent??Event;async function*my(t,e={}){let r=e.concurrency??1/0;r<1&&(r=1/0);let n=e.ordered==null?!1:e.ordered,i=new EventTarget,o=[],s=Ce(),a=Ce(),c=!1,u,l=!1;i.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let h of t){if(o.length===r&&(s=Ce(),await s.promise),l)break;let m={done:!1};o.push(m),h().then(y=>{m.done=!0,m.ok=!0,m.value=y,i.dispatchEvent(new Bh("task-complete"))},y=>{m.done=!0,m.err=y,i.dispatchEvent(new Bh("task-complete"))})}c=!0,i.dispatchEvent(new Bh("task-complete"))}catch(h){u=h,i.dispatchEvent(new Bh("task-complete"))}});function f(){return n?o[0]?.done:!!o.find(h=>h.done)}function*d(){for(;o.length>0&&o[0].done;){let h=o[0];if(o.shift(),h.ok)yield h.value;else throw l=!0,s.resolve(),h.err;s.resolve()}}function*p(){for(;f();)for(let h=0;h<o.length;h++)if(o[h].done){let m=o[h];if(o.splice(h,1),h--,m.ok)yield m.value;else throw l=!0,s.resolve(),m.err;s.resolve()}}for(;;){if(f()||(a=Ce(),await a.promise),u!=null)throw u;if(n?yield*d():yield*p(),c&&o.length===0)break}}var Th=class{log;peerId;peerStore;routers;constructor(e,r={}){this.log=e.logger.forComponent("libp2p:peer-routing"),this.peerId=e.peerId,this.peerStore=e.peerStore,this.routers=r.routers??[]}async findPeer(e,r){if(this.routers.length===0)throw new x("No peer routers available",Q.ERR_NO_ROUTERS_AVAILABLE);if(e.toString()===this.peerId.toString())throw new x("Should not try to find self",Q.ERR_FIND_SELF);let n=this,i=Ei(...this.routers.map(o=>async function*(){try{yield await o.findPeer(e,r)}catch(s){n.log.error(s)}}()));for await(let o of i)if(o!=null)return o.multiaddrs.length>0&&await this.peerStore.merge(o.id,{multiaddrs:o.multiaddrs}),o;throw new x(ei.NOT_FOUND,Q.ERR_NOT_FOUND)}async*getClosestPeers(e,r={}){if(this.routers.length===0)throw new x("No peer routers available",Q.ERR_NO_ROUTERS_AVAILABLE);let n=this,i=new Tr;for await(let o of my(async function*(){let s=Ei(...n.routers.map(a=>a.getClosestPeers(e,r)));for await(let a of s)yield async()=>{if(a.multiaddrs.length===0)try{a=await n.findPeer(a.id,{...r,useCache:!1})}catch(c){n.log.error("could not find peer multiaddrs",c);return}return a}}()))o!=null&&(o.multiaddrs.length>0&&await this.peerStore.merge(o.id,{multiaddrs:o.multiaddrs}),!i.has(o.id)&&(i.add(o.id),yield o))}};var yy=32,gy=64,kh=class{log;topologies;handlers;components;constructor(e){this.log=e.logger.forComponent("libp2p:registrar"),this.topologies=new Map,this.handlers=new Map,this.components=e,this._onDisconnect=this._onDisconnect.bind(this),this._onPeerUpdate=this._onPeerUpdate.bind(this),this._onPeerIdentify=this._onPeerIdentify.bind(this),this.components.events.addEventListener("peer:disconnect",this._onDisconnect),this.components.events.addEventListener("peer:update",this._onPeerUpdate),this.components.events.addEventListener("peer:identify",this._onPeerIdentify)}getProtocols(){return Array.from(new Set([...this.handlers.keys()])).sort()}getHandler(e){let r=this.handlers.get(e);if(r==null)throw new x(`No handler registered for protocol ${e}`,Q.ERR_NO_HANDLER_FOR_PROTOCOL);return r}getTopologies(e){let r=this.topologies.get(e);return r==null?[]:[...r.values()]}async handle(e,r,n){if(this.handlers.has(e))throw new x(`Handler already registered for protocol ${e}`,Q.ERR_PROTOCOL_HANDLER_ALREADY_REGISTERED);let i=ph.bind({ignoreUndefined:!0})({maxInboundStreams:yy,maxOutboundStreams:gy},n);this.handlers.set(e,{handler:r,options:i}),await this.components.peerStore.merge(this.components.peerId,{protocols:[e]})}async unhandle(e){(Array.isArray(e)?e:[e]).forEach(n=>{this.handlers.delete(n)}),await this.components.peerStore.patch(this.components.peerId,{protocols:this.getProtocols()})}async register(e,r){if(r==null)throw new x("invalid topology",Q.ERR_INVALID_PARAMETERS);let n=`${(Math.random()*1e9).toString(36)}${Date.now()}`,i=this.topologies.get(e);return i==null&&(i=new Map,this.topologies.set(e,i)),i.set(n,r),n}unregister(e){for(let[r,n]of this.topologies.entries())n.has(e)&&(n.delete(e),n.size===0&&this.topologies.delete(r))}_onDisconnect(e){let r=e.detail;this.components.peerStore.get(r).then(n=>{for(let i of n.protocols){let o=this.topologies.get(i);if(o!=null)for(let s of o.values())s.onDisconnect?.(r)}}).catch(n=>{n.code!==Q.ERR_NOT_FOUND&&this.log.error("could not inform topologies of disconnecting peer %p",r,n)})}_onPeerUpdate(e){let{peer:r,previous:n}=e.detail,i=(n?.protocols??[]).filter(o=>!r.protocols.includes(o));for(let o of i){let s=this.topologies.get(o);if(s!=null)for(let a of s.values())a.onDisconnect?.(r.id)}}_onPeerIdentify(e){let r=e.detail.protocols,n=e.detail.connection,i=e.detail.peerId;for(let o of r){let s=this.topologies.get(o);if(s!=null)for(let a of s.values())n.transient&&a.notifyOnTransient!==!0||a.onConnect?.(i,n)}}};var Ch=class{log;components;transports;listeners;faultTolerance;started;constructor(e,r={}){this.log=e.logger.forComponent("libp2p:transports"),this.components=e,this.started=!1,this.transports=new Map,this.listeners=ss({name:"libp2p_transport_manager_listeners",metrics:this.components.metrics}),this.faultTolerance=r.faultTolerance??hi.FATAL_ALL}add(e){let r=e[Symbol.toStringTag];if(r==null)throw new x("Transport must have a valid tag",Q.ERR_INVALID_KEY);if(this.transports.has(r))throw new x(`There is already a transport with the tag ${r}`,Q.ERR_DUPLICATE_TRANSPORT);this.log("adding transport %s",r),this.transports.set(r,e),this.listeners.has(r)||this.listeners.set(r,[])}isStarted(){return this.started}start(){this.started=!0}async afterStart(){let e=this.components.addressManager.getListenAddrs();await this.listen(e)}async stop(){let e=[];for(let[r,n]of this.listeners)for(this.log("closing listeners for %s",r);n.length>0;){let i=n.pop();i!=null&&e.push(i.close())}await Promise.all(e),this.log("all listeners closed");for(let r of this.listeners.keys())this.listeners.set(r,[]);this.started=!1}async dial(e,r){let n=this.transportForMultiaddr(e);if(n==null)throw new x(`No transport available for address ${String(e)}`,Q.ERR_TRANSPORT_UNAVAILABLE);try{return await n.dial(e,{...r,upgrader:this.components.upgrader})}catch(i){throw i.code==null&&(i.code=Q.ERR_TRANSPORT_DIAL_FAILED),i}}getAddrs(){let e=[];for(let r of this.listeners.values())for(let n of r)e=[...e,...n.getAddrs()];return e}getTransports(){return Array.of(...this.transports.values())}getListeners(){return Array.of(...this.listeners.values()).flat()}transportForMultiaddr(e){for(let r of this.transports.values())if(r.filter([e]).length>0)return r}async listen(e){if(!this.isStarted())throw new x("Not started",Q.ERR_NODE_NOT_STARTED);if(e==null||e.length===0){this.log("no addresses were provided for listening, this node is dial only");return}let r=[];for(let[n,i]of this.transports.entries()){let o=i.filter(e),s=[];for(let u of o){this.log("creating listener for %s on %a",n,u);let l=i.createListener({upgrader:this.components.upgrader}),f=this.listeners.get(n)??[];f==null&&(f=[],this.listeners.set(n,f)),f.push(l),l.addEventListener("listening",()=>{this.components.events.safeDispatchEvent("transport:listening",{detail:l})}),l.addEventListener("close",()=>{let d=f.findIndex(p=>p===l);f.splice(d,1),this.components.events.safeDispatchEvent("transport:close",{detail:l})}),s.push(l.listen(u))}if(s.length===0){r.push(n);continue}if((await Promise.allSettled(s)).find(u=>u.status==="fulfilled")==null&&this.faultTolerance!==hi.NO_FATAL)throw new x(`Transport (${n}) could not listen on any available address`,Q.ERR_NO_VALID_ADDRESSES)}if(r.length===this.transports.size){let n=`no valid addresses were provided for transports [${r.join(", ")}]`;if(this.faultTolerance===hi.FATAL_ALL)throw new x(n,Q.ERR_NO_VALID_ADDRESSES);this.log(`libp2p in dial mode only: ${n}`)}}async remove(e){let r=this.listeners.get(e)??[];this.log.trace("removing transport %s",e);let n=[];for(this.log.trace("closing listeners for %s",e);r.length>0;){let i=r.pop();i!=null&&n.push(i.close())}await Promise.all(n),this.transports.delete(e),this.listeners.delete(e)}async removeAll(){let e=[];for(let r of this.transports.keys())e.push(this.remove(r));await Promise.all(e)}};var Dt="/multistream/1.0.0";var by=class{needNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.needNext=Ce(),this.haveNext=Ce()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("Have next but next was undefined");let e=this.nextResult;return this.nextResult=void 0,this.needNext.resolve(),this.needNext=Ce(),e}async throw(e){return this.ended=!0,e!=null&&this.haveNext.reject(e),{done:!0,value:void 0}}async return(){let e={done:!0,value:void 0};return await this._push(void 0),e}async push(e,r){await this._push(e,r)}async end(e,r){e!=null?await this.throw(e):await this._push(void 0,r)}async _push(e,r){if(e!=null&&this.ended)throw new Error("Cannot push value onto an ended pushable");this.nextResult!=null&&await this.needNext.promise,e!=null?this.nextResult={done:!1,value:e}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Ce(),await vs(this.needNext.promise,r?.signal,r)}};function jA(){return new by}var Ph=class extends Error{code;constructor(e,r){super(e),this.code=r}},wy=class extends Ph{type;constructor(e){super(e,"ABORT_ERR"),this.type="aborted"}};function QA(t,e){let r=jA();t.sink(r).catch(async s=>{await r.end(s)}),t.sink=async s=>{for await(let a of s)await r.push(a);await r.end()};let n=t.source;t.source[Symbol.iterator]!=null?n=t.source[Symbol.iterator]():t.source[Symbol.asyncIterator]!=null&&(n=t.source[Symbol.asyncIterator]());let i=new bt;return{read:async(s,a)=>{a?.signal?.throwIfAborted();let c,u=new Promise((l,f)=>{c=()=>{f(new wy("Read aborted"))},a?.signal?.addEventListener("abort",c)});try{if(s==null){let{done:f,value:d}=await Promise.race([n.next(),u]);return f===!0?new bt:d}for(;i.byteLength<s;){let{value:f,done:d}=await Promise.race([n.next(),u]);if(d===!0)throw new Ph("unexpected end of input","ERR_UNEXPECTED_EOF");i.append(f)}let l=i.sublist(0,s);return i.consume(s),l}finally{c!=null&&a?.signal?.removeEventListener("abort",c)}},write:async(s,a)=>{a?.signal?.throwIfAborted(),s instanceof Uint8Array?await r.push(s,a):await r.push(s.subarray(),a)},unwrap:()=>{if(i.byteLength>0){let s=t.source;t.source=async function*(){e?.yieldBytes===!1?yield i:yield*i,yield*s}()}return t}}}var Dh=class extends Error{code;constructor(e,r){super(e),this.code=r}},JA=t=>Ur(t);JA.bytes=0;function Yc(t,e={}){let r=QA(t,e);return e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Ft(e.maxDataLength)),{read:async i=>{let o=-1,s=new bt,a=e?.lengthDecoder??JA;for(;;){s.append(await r.read(1,i));try{o=a(s)}catch(c){if(c instanceof RangeError)continue;throw c}if(e?.maxLengthLength!=null&&s.byteLength>e.maxLengthLength)throw new Dh("message length length too long","ERR_MSG_LENGTH_TOO_LONG");if(o>-1)break}if(e?.maxDataLength!=null&&o>e.maxDataLength)throw new Dh("message length too long","ERR_MSG_DATA_TOO_LONG");return r.read(o,i)},write:async(i,o)=>{await r.write(vi.single(i,e),o)},writeV:async(i,o)=>{let s=new bt(...i.map(a=>vi.single(a,e)));await r.write(s,o)},unwrap:()=>r.unwrap()}}var NP=U(`
|
|
35
|
+
`);async function Fo(t,e,r){await t.write(e,r)}async function XA(t,e,r){await t.writeV(e,r)}async function LP(t,e){let r=await t.read(e);if(r.byteLength===0||r.get(r.byteLength-1)!==NP[0])throw e.log.error("Invalid mss message - missing newline",r),new x("missing newline","ERR_INVALID_MULTISTREAM_SELECT_MESSAGE");return r.sublist(0,-1)}async function zi(t,e){let r=await LP(t,e);return z(r.subarray())}async function jc(t,e,r){if(e=Array.isArray(e)?[...e]:[e],e.length===1&&r.negotiateFully===!1)return OP(t,e[0],r);let n=Yc(t,{...r,maxDataLength:1024}),i=e.shift();if(i==null)throw new Error("At least one protocol must be specified");r.log.trace('select: write ["%s", "%s"]',Dt,i);let o=U(`${Dt}
|
|
36
|
+
`),s=U(`${i}
|
|
37
|
+
`);await XA(n,[o,s],r),r.log.trace("select: reading multistream-select header");let a=await zi(n,r);if(r.log.trace('select: read "%s"',a),a===Dt&&(r.log.trace("select: reading protocol response"),a=await zi(n,r),r.log.trace('select: read "%s"',a)),a===i)return{stream:n.unwrap(),protocol:i};for(let c of e){r.log.trace('select: write "%s"',c),await Fo(n,U(`${c}
|
|
38
|
+
`),r),r.log.trace("select: reading protocol response");let u=await zi(n,r);if(r.log.trace('select: read "%s" for "%s"',u,c),u===c)return{stream:n.unwrap(),protocol:c}}throw new x("protocol selection failed","ERR_UNSUPPORTED_PROTOCOL")}function OP(t,e,r){let n=t.sink.bind(t),i=t.source,o=!1,s=!1,a=Ce(),c=!1,u=!1,l=Ce(),f=!1,d=!1,p=Ce(),h=Yc({sink:n,source:i},{...r,maxDataLength:1024});t.sink=async b=>{let{sink:w}=h.unwrap();await w(async function*(){let _=!1;for await(let E of b){if(u&&await l.promise,c)yield E;else{u=!0,r.log.trace('optimistic: write ["%s", "%s", data(%d)] in sink',Dt,e,E.byteLength);let A=`${e}
|
|
39
|
+
`;yield new bt(Uint8Array.from([19]),U(`${Dt}
|
|
40
|
+
`),tr(A.length),U(A),E).subarray(),r.log.trace('optimistic: wrote ["%s", "%s", data(%d)] in sink',Dt,e,E.byteLength),c=!0,u=!1,l.resolve(),m().catch(B=>{r.log.error("could not finish optimistic protocol negotiation of %s",e,B)})}_=!0}_||await m()}())};async function m(){if(s){r.log.trace("optimistic: already negotiating %s stream",e),await a.promise;return}s=!0;try{c||(r.log.trace("optimistic: doing send protocol for %s stream",e),await y()),f||(r.log.trace("optimistic: doing read protocol for %s stream",e),await g())}finally{s=!1,o=!0,a.resolve()}}async function y(){if(u){await l.promise;return}u=!0;try{r.log.trace('optimistic: write ["%s", "%s", data] in source',Dt,e),await h.writeV([U(`${Dt}
|
|
41
|
+
`),U(`${e}
|
|
42
|
+
`)]),r.log.trace('optimistic: wrote ["%s", "%s", data] in source',Dt,e)}finally{c=!0,u=!1,l.resolve()}}async function g(){if(d){await p.promise;return}d=!0;try{r.log.trace("optimistic: reading multistream select header");let b=await zi(h,r);if(r.log.trace('optimistic: read multistream select header "%s"',b),b===Dt&&(b=await zi(h,r)),r.log.trace('optimistic: read protocol "%s", expecting "%s"',b,e),b!==e)throw new x("protocol selection failed","ERR_UNSUPPORTED_PROTOCOL")}finally{f=!0,d=!1,p.resolve()}}if(t.source=async function*(){await m(),r.log.trace('optimistic: reading data from "%s" stream',e),yield*h.unwrap().source}(),t.closeRead!=null){let b=t.closeRead.bind(t);t.closeRead=async w=>{o||await m().catch(_=>{r.log.error("could not negotiate protocol before close read",_)}),await b(w)}}if(t.closeWrite!=null){let b=t.closeWrite.bind(t);t.closeWrite=async w=>{o||await m().catch(_=>{r.log.error("could not negotiate protocol before close write",_)}),await b(w)}}if(t.close!=null){let b=t.close.bind(t);t.close=async w=>{let _=[];u&&_.push(l.promise),d&&_.push(p.promise),_.length>0?await vs(Promise.all(_),w?.signal):(o=!0,s=!1,a.resolve()),await b(w)}}return{stream:t,protocol:e}}async function Qc(t,e,r){e=Array.isArray(e)?e:[e],r.log.trace("handle: available protocols %s",e);let n=Yc(t,{...r,maxDataLength:1024,maxLengthLength:2});for(;;){r.log.trace("handle: reading incoming string");let i=await zi(n,r);if(r.log.trace('handle: read "%s"',i),i===Dt){r.log.trace('handle: respond with "%s" for "%s"',Dt,i),await Fo(n,U(`${Dt}
|
|
43
|
+
`),r),r.log.trace('handle: responded with "%s" for "%s"',Dt,i);continue}if(e.includes(i))return r.log.trace('handle: respond with "%s" for "%s"',i,i),await Fo(n,U(`${i}
|
|
44
|
+
`),r),r.log.trace('handle: responded with "%s" for "%s"',i,i),{stream:n.unwrap(),protocol:i};if(i==="ls"){let o=new bt(...e.map(s=>vi.single(U(`${s}
|
|
45
|
+
`))),U(`
|
|
46
|
+
`));r.log.trace('handle: respond with "%s" for %s',e,i),await Fo(n,o,r),r.log.trace('handle: responded with "%s" for %s',e,i);continue}r.log('handle: respond with "na" for "%s"',i),await Fo(n,U(`na
|
|
47
|
+
`),r),r.log('handle: responded with "na" for "%s"',i)}}var KP=500,xy=class{id;remoteAddr;remotePeer;direction;timeline;multiplexer;encryption;status;transient;log;tags;_newStream;_close;_abort;_getStreams;constructor(e){let{remoteAddr:r,remotePeer:n,newStream:i,close:o,abort:s,getStreams:a}=e;this.id=`${parseInt(String(Math.random()*1e9)).toString(36)}${Date.now()}`,this.remoteAddr=r,this.remotePeer=n,this.direction=e.direction,this.status="open",this.timeline=e.timeline,this.multiplexer=e.multiplexer,this.encryption=e.encryption,this.transient=e.transient??!1,this.log=e.logger.forComponent(`libp2p:connection:${this.direction}:${this.id}`),this.remoteAddr.getPeerId()==null&&(this.remoteAddr=this.remoteAddr.encapsulate(`/p2p/${this.remotePeer}`)),this._newStream=i,this._close=o,this._abort=s,this._getStreams=a,this.tags=[]}[Symbol.toStringTag]="Connection";[Kb]=!0;get streams(){return this._getStreams()}async newStream(e,r){if(this.status==="closing")throw new x("the connection is being closed","ERR_CONNECTION_BEING_CLOSED");if(this.status==="closed")throw new x("the connection is closed","ERR_CONNECTION_CLOSED");if(Array.isArray(e)||(e=[e]),this.transient&&r?.runOnTransientConnection!==!0)throw new x("Cannot open protocol stream on transient connection","ERR_TRANSIENT_CONNECTION");let n=await this._newStream(e,r);return n.direction="outbound",n}async close(e={}){if(!(this.status==="closed"||this.status==="closing")){if(this.log("closing connection to %a",this.remoteAddr),this.status="closing",e.signal==null){let r=AbortSignal.timeout(KP);xr(1/0,r),e={...e,signal:r}}try{this.log.trace("closing all streams"),await Promise.all(this.streams.map(async r=>r.close(e))),this.log.trace("closing underlying transport"),await this._close(e),this.log.trace("updating timeline with close time"),this.status="closed",this.timeline.close=Date.now()}catch(r){this.log.error("error encountered during graceful close of connection to %a",this.remoteAddr,r),this.abort(r)}}}abort(e){this.log.error("aborting connection to %a due to error",this.remoteAddr,e),this.status="closing",this.streams.forEach(r=>{r.abort(e)}),this.log.error("all streams aborted",this.streams.length),this._abort(e),this.timeline.close=Date.now(),this.status="closed"}};function eS(t){return new xy(t)}var FP=3e4;function VP(t,e){try{let{options:r}=e.getHandler(t);return r.maxInboundStreams}catch(r){if(r.code!==Q.ERR_NO_HANDLER_FOR_PROTOCOL)throw r}return yy}function HP(t,e,r={}){try{let{options:n}=e.getHandler(t);if(n.maxOutboundStreams!=null)return n.maxOutboundStreams}catch(n){if(n.code!==Q.ERR_NO_HANDLER_FOR_PROTOCOL)throw n}return r.maxOutboundStreams??gy}function tS(t,e,r){let n=0;return r.streams.forEach(i=>{i.direction===e&&i.protocol===t&&n++}),n}var Lh=class{components;connectionEncryption;muxers;inboundUpgradeTimeout;events;constructor(e,r){this.components=e,this.connectionEncryption=new Map,r.connectionEncryption.forEach(n=>{this.connectionEncryption.set(n.protocol,n)}),this.muxers=new Map,r.muxers.forEach(n=>{this.muxers.set(n.protocol,n)}),this.inboundUpgradeTimeout=r.inboundUpgradeTimeout??3e4,this.events=e.events}async shouldBlockConnection(e,r,n){let i=this.components.connectionGater[n];if(i!==void 0&&await i(e,r))throw new x(`The multiaddr connection is blocked by gater.${n}`,Q.ERR_CONNECTION_INTERCEPTED)}async upgradeInbound(e,r){if(!await this.components.connectionManager.acceptIncomingConnection(e))throw new x("connection denied",Q.ERR_CONNECTION_DENIED);let i,o,s,a,c,u=AbortSignal.timeout(this.inboundUpgradeTimeout),l=()=>{e.abort(new x("inbound upgrade timeout",Du))};u.addEventListener("abort",l,{once:!0}),xr(1/0,u);try{if(await this.components.connectionGater.denyInboundConnection?.(e)===!0)throw new x("The multiaddr connection is blocked by gater.acceptConnection",Q.ERR_CONNECTION_INTERCEPTED);this.components.metrics?.trackMultiaddrConnection(e),e.log("starting the inbound connection upgrade");let f=e;if(r?.skipProtection!==!0){let d=this.components.connectionProtector;d!=null&&(e.log("protecting the inbound connection"),f=await d.protect(e))}try{if(i=f,r?.skipEncryption!==!0){({conn:i,remotePeer:o,protocol:c}=await this._encryptInbound(f));let d={...f,...i};await this.shouldBlockConnection(o,d,"denyInboundEncryptedConnection")}else{let d=e.remoteAddr.getPeerId();if(d==null)throw new x("inbound connection that skipped encryption must have a peer id",Q.ERR_INVALID_MULTIADDR);let p=ut(d);c="native",o=p}if(s=i,r?.muxerFactory!=null)a=r.muxerFactory;else if(this.muxers.size>0){let d=await this._multiplexInbound({...f,...i},this.muxers);a=d.muxerFactory,s=d.stream}}catch(d){throw e.log.error("failed to upgrade inbound connection",d),d}return await this.shouldBlockConnection(o,e,"denyInboundUpgradedConnection"),e.log("successfully upgraded inbound connection"),this._createConnection({cryptoProtocol:c,direction:"inbound",maConn:e,upgradedConn:s,muxerFactory:a,remotePeer:o,transient:r?.transient})}finally{u.removeEventListener("abort",l),this.components.connectionManager.afterUpgradeInbound()}}async upgradeOutbound(e,r){let n=e.remoteAddr.getPeerId(),i;n!=null&&(i=ut(n),await this.shouldBlockConnection(i,e,"denyOutboundConnection"));let o,s,a,c,u;this.components.metrics?.trackMultiaddrConnection(e),e.log("starting the outbound connection upgrade");let l=e;if(r?.skipProtection!==!0){let f=this.components.connectionProtector;f!=null&&(l=await f.protect(e))}try{if(o=l,r?.skipEncryption!==!0){({conn:o,remotePeer:s,protocol:c}=await this._encryptOutbound(l,i));let f={...l,...o};await this.shouldBlockConnection(s,f,"denyOutboundEncryptedConnection")}else{if(i==null)throw new x("Encryption was skipped but no peer id was passed",Q.ERR_INVALID_PEER);c="native",s=i}if(a=o,r?.muxerFactory!=null)u=r.muxerFactory;else if(this.muxers.size>0){let f=await this._multiplexOutbound({...l,...o},this.muxers);u=f.muxerFactory,a=f.stream}}catch(f){throw e.log.error("failed to upgrade outbound connection",f),await e.close(f),f}return await this.shouldBlockConnection(s,e,"denyOutboundUpgradedConnection"),e.log("successfully upgraded outbound connection"),this._createConnection({cryptoProtocol:c,direction:"outbound",maConn:e,upgradedConn:a,muxerFactory:u,remotePeer:s,transient:r?.transient})}_createConnection(e){let{cryptoProtocol:r,direction:n,maConn:i,upgradedConn:o,remotePeer:s,muxerFactory:a,transient:c}=e,u,l,f;a!=null&&(u=a.createStreamMuxer({direction:n,onIncomingStream:h=>{f!=null&&Promise.resolve().then(async()=>{let m=this.components.registrar.getProtocols(),{stream:y,protocol:g}=await Qc(h,m,{log:h.log,yieldBytes:!1});if(f==null)return;f.log("incoming stream opened on %s",g);let b=VP(g,this.components.registrar);if(tS(g,"inbound",f)===b){let _=new x(`Too many inbound protocol streams for protocol "${g}" - limit ${b}`,Q.ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS);throw h.abort(_),_}h.source=y.source,h.sink=y.sink,h.protocol=g,y.closeWrite!=null&&(h.closeWrite=y.closeWrite),y.closeRead!=null&&(h.closeRead=y.closeRead),y.close!=null&&(h.close=y.close),await this.components.peerStore.merge(s,{protocols:[g]}),this.components.metrics?.trackProtocolStream(h,f),this._onStream({connection:f,stream:h,protocol:g})}).catch(async m=>{f.log.error("error handling incoming stream id %s",h.id,m.message,m.code,m.stack),h.timeline.close==null&&await h.close()})}}),l=async(h,m={})=>{if(u==null)throw new x("Stream is not multiplexed",Q.ERR_MUXER_UNAVAILABLE);f.log("starting new stream for protocols %s",h);let y=await u.newStream();f.log.trace("started new stream %s for protocols %s",y.id,h);try{if(m.signal==null){y.log("no abort signal was passed while trying to negotiate protocols %s falling back to default timeout",h);let E=AbortSignal.timeout(FP);xr(1/0,E),m={...m,signal:E}}y.log.trace("selecting protocol from protocols %s",h);let{stream:g,protocol:b}=await jc(y,h,{...m,log:y.log,yieldBytes:!0});y.log("selected protocol %s",b);let w=HP(b,this.components.registrar,m);if(tS(b,"outbound",f)>=w){let E=new x(`Too many outbound protocol streams for protocol "${b}" - limit ${w}`,Q.ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS);throw y.abort(E),E}return await this.components.peerStore.merge(s,{protocols:[b]}),y.source=g.source,y.sink=g.sink,y.protocol=b,g.closeWrite!=null&&(y.closeWrite=g.closeWrite),g.closeRead!=null&&(y.closeRead=g.closeRead),g.close!=null&&(y.close=g.close),this.components.metrics?.trackProtocolStream(y,f),y}catch(g){throw f.log.error("could not create new stream for protocols %s",h,g),y.timeline.close==null&&y.abort(g),g.code!=null?g:new x(String(g),Q.ERR_UNSUPPORTED_PROTOCOL)}},Promise.all([u.sink(o.source),o.sink(u.source)]).catch(h=>{f.log.error("error piping data through muxer",h)}));let d=i.timeline;i.timeline=new Proxy(d,{set:(...h)=>(f!=null&&h[1]==="close"&&h[2]!=null&&d.close==null&&(async()=>{try{f.status==="open"&&await f.close()}catch(m){f.log.error("error closing connection after timeline close",m)}finally{this.events.safeDispatchEvent("connection:close",{detail:f})}})().catch(m=>{f.log.error("error thrown while dispatching connection:close event",m)}),Reflect.set(...h))}),i.timeline.upgraded=Date.now();let p=()=>{throw new x("connection is not multiplexed",Q.ERR_CONNECTION_NOT_MULTIPLEXED)};return f=eS({remoteAddr:i.remoteAddr,remotePeer:s,status:"open",direction:n,timeline:i.timeline,multiplexer:u?.protocol,encryption:r,transient:c,logger:this.components.logger,newStream:l??p,getStreams:()=>u!=null?u.streams:[],close:async h=>{u!=null&&(f.log.trace("close muxer"),await u.close(h)),f.log.trace("close maconn"),await i.close(h),f.log.trace("closed maconn")},abort:h=>{i.abort(h),u?.abort(h)}}),this.events.safeDispatchEvent("connection:open",{detail:f}),f}_onStream(e){let{connection:r,stream:n,protocol:i}=e,{handler:o,options:s}=this.components.registrar.getHandler(i);if(r.transient&&s.runOnTransientConnection!==!0)throw new x("Cannot open protocol stream on transient connection","ERR_TRANSIENT_CONNECTION");o({connection:r,stream:n})}async _encryptInbound(e){let r=Array.from(this.connectionEncryption.keys());e.log("handling inbound crypto protocol selection",r);try{let{stream:n,protocol:i}=await Qc(e,r,{log:e.log}),o=this.connectionEncryption.get(i);if(o==null)throw new Error(`no crypto module found for ${i}`);return e.log("encrypting inbound connection using",i),{...await o.secureInbound(this.components.peerId,n),protocol:i}}catch(n){throw e.log.error("encrypting inbound connection to %p failed",n),new x(n.message,Q.ERR_ENCRYPTION_FAILED)}}async _encryptOutbound(e,r){let n=Array.from(this.connectionEncryption.keys());e.log("selecting outbound crypto protocol",n);try{e.log.trace("selecting encrypter from %s",n);let{stream:i,protocol:o}=await jc(e,n,{log:e.log,yieldBytes:!0}),s=this.connectionEncryption.get(o);if(s==null)throw new Error(`no crypto module found for ${o}`);return e.log("encrypting outbound connection to %p using %p",r),{...await s.secureOutbound(this.components.peerId,i,r),protocol:o}}catch(i){throw e.log.error("encrypting outbound connection to %p failed",i),new x(i.message,Q.ERR_ENCRYPTION_FAILED)}}async _multiplexOutbound(e,r){let n=Array.from(r.keys());e.log("outbound selecting muxer %s",n);try{e.log.trace("selecting stream muxer from %s",n);let{stream:i,protocol:o}=await jc(e,n,{log:e.log,yieldBytes:!0});e.log("selected %s as muxer protocol",o);let s=r.get(o);return{stream:i,muxerFactory:s}}catch(i){throw e.log.error("error multiplexing outbound connection",i),new x(String(i),Q.ERR_MUXER_UNAVAILABLE)}}async _multiplexInbound(e,r){let n=Array.from(r.keys());e.log("inbound handling muxers %s",n);try{let{stream:i,protocol:o}=await Qc(e,n,{log:e.log}),s=r.get(o);return{stream:i,muxerFactory:s}}catch(i){throw e.log.error("error multiplexing inbound connection",i),new x(String(i),Q.ERR_MUXER_UNAVAILABLE)}}};var rS="1.1.2",nS="libp2p";var vy=class extends oo{peerId;peerStore;contentRouting;peerRouting;metrics;services;logger;status;components;log;constructor(e){super(),this.status="stopped";let r=new oo,n=r.dispatchEvent.bind(r);r.dispatchEvent=a=>{let c=n(a),u=this.dispatchEvent(new qd(a.type,{detail:a.detail}));return c||u},xr(1/0,r),this.peerId=e.peerId,this.logger=e.logger??Ku(),this.log=this.logger.forComponent("libp2p"),this.services={};let i=this.components=uA({peerId:e.peerId,nodeInfo:e.nodeInfo??{name:nS,version:rS},logger:this.logger,events:r,datastore:e.datastore??new wo,connectionGater:wA(e.connectionGater)});this.peerStore=this.configureComponent("peerStore",new th(i,{addressFilter:this.components.connectionGater.filterMultiaddrForPeer,...e.peerStore})),e.metrics!=null&&(this.metrics=this.configureComponent("metrics",e.metrics(this.components))),i.events.addEventListener("peer:update",a=>{if(a.detail.previous==null){let c={id:a.detail.peer.id,multiaddrs:a.detail.peer.addresses.map(u=>u.multiaddr)};i.events.safeDispatchEvent("peer:discovery",{detail:c})}}),e.connectionProtector!=null&&this.configureComponent("connectionProtector",e.connectionProtector(i)),this.components.upgrader=new Lh(this.components,{connectionEncryption:(e.connectionEncryption??[]).map((a,c)=>this.configureComponent(`connection-encryption-${c}`,a(this.components))),muxers:(e.streamMuxers??[]).map((a,c)=>this.configureComponent(`stream-muxers-${c}`,a(this.components))),inboundUpgradeTimeout:e.connectionManager.inboundUpgradeTimeout}),this.configureComponent("transportManager",new Ch(this.components,e.transportManager)),this.configureComponent("connectionManager",new Ih(this.components,e.connectionManager)),this.configureComponent("registrar",new kh(this.components)),this.configureComponent("addressManager",new rh(this.components,e.addresses));let o=(e.peerRouters??[]).map((a,c)=>this.configureComponent(`peer-router-${c}`,a(this.components)));this.peerRouting=this.components.peerRouting=this.configureComponent("peerRouting",new Th(this.components,{routers:o}));let s=(e.contentRouters??[]).map((a,c)=>this.configureComponent(`content-router-${c}`,a(this.components)));if(this.contentRouting=this.components.contentRouting=this.configureComponent("contentRouting",new Rh(this.components,{routers:s})),(e.peerDiscovery??[]).forEach((a,c)=>{this.configureComponent(`peer-discovery-${c}`,a(this.components)).addEventListener("peer",l=>{this.#e(l)})}),e.transports?.forEach((a,c)=>{this.components.transportManager.add(this.configureComponent(`transport-${c}`,a(this.components)))}),e.services!=null)for(let a of Object.keys(e.services)){let c=e.services[a],u=c(this.components);if(u==null){this.log.error("service factory %s returned null or undefined instance",a);continue}this.services[a]=u,this.configureComponent(a,u),u[Kd]!=null&&(this.log("registering service %s for content routing",a),s.push(u[Kd])),u[Vd]!=null&&(this.log("registering service %s for peer routing",a),o.push(u[Vd])),u[Md]!=null&&(this.log("registering service %s for peer discovery",a),u[Md].addEventListener?.("peer",l=>{this.#e(l)}))}}configureComponent(e,r){return r==null&&this.log.error("component %s was null or undefined",e),this.components[e]=r,r}async start(){if(this.status==="stopped"){this.status="starting",this.log("libp2p is starting");try{await this.components.beforeStart?.(),await this.components.start(),await this.components.afterStart?.(),this.status="started",this.safeDispatchEvent("start",{detail:this}),this.log("libp2p has started")}catch(e){throw this.log.error("An error occurred starting libp2p",e),this.status="started",await this.stop(),e}}}async stop(){this.status==="started"&&(this.log("libp2p is stopping"),this.status="stopping",await this.components.beforeStop?.(),await this.components.stop(),await this.components.afterStop?.(),this.status="stopped",this.safeDispatchEvent("stop",{detail:this}),this.log("libp2p has stopped"))}getConnections(e){return this.components.connectionManager.getConnections(e)}getDialQueue(){return this.components.connectionManager.getDialQueue()}getPeers(){let e=new Tr;for(let r of this.components.connectionManager.getConnections())e.add(r.remotePeer);return Array.from(e)}async dial(e,r={}){return this.components.connectionManager.openConnection(e,{priority:75,...r})}async dialProtocol(e,r,n={}){if(r==null)throw new x("no protocols were provided to open a stream",Q.ERR_INVALID_PROTOCOLS_FOR_STREAM);if(r=Array.isArray(r)?r:[r],r.length===0)throw new x("no protocols were provided to open a stream",Q.ERR_INVALID_PROTOCOLS_FOR_STREAM);return(await this.dial(e,n)).newStream(r,n)}getMultiaddrs(){return this.components.addressManager.getAddresses()}getProtocols(){return this.components.registrar.getProtocols()}async hangUp(e,r={}){Hi(e)&&(e=ut(e.getPeerId()??"")),await this.components.connectionManager.closeConnections(e,r)}async getPublicKey(e,r={}){if(this.log("getPublicKey %p",e),e.publicKey!=null)return e.publicKey;try{let o=await this.peerStore.get(e);if(o.id.publicKey!=null)return o.id.publicKey}catch(o){if(o.code!==Q.ERR_NOT_FOUND)throw o}let n=ke([U("/pk/"),e.multihash.digest]),i=await this.contentRouting.get(n,r);return $E(i),await this.peerStore.patch(e,{publicKey:i}),i}async handle(e,r,n){Array.isArray(e)||(e=[e]),await Promise.all(e.map(async i=>{await this.components.registrar.handle(i,r,n)}))}async unhandle(e){Array.isArray(e)||(e=[e]),await Promise.all(e.map(async r=>{await this.components.registrar.unhandle(r)}))}async register(e,r){return this.components.registrar.register(e,r)}unregister(e){this.components.registrar.unregister(e)}#e(e){let{detail:r}=e;if(r.id.toString()===this.peerId.toString()){this.log.error(new Error(Q.ERR_DISCOVERED_SELF));return}this.components.peerStore.merge(r.id,{multiaddrs:r.multiaddrs}).catch(n=>{this.log.error(n)})}};async function iS(t={}){return t.peerId??=await g2(),new vy($A(t))}async function oS(t={}){let e=await iS(t);return t.start!==!1&&await e.start(),e}var sS=Symbol.for("@libp2p/content-routing");var ce=class extends Error{code;props;constructor(e,r,n){super(e),this.code=r,this.name=n?.name??"CodeError",this.props=n??{}}};var Ey=class extends Event{detail;constructor(e,r){super(e,r),this.detail=r?.detail}},foe=globalThis.CustomEvent??Ey;var aS=(t,...e)=>{try{[...e]}catch{}};var cS=Symbol.for("@libp2p/peer-routing");var mr=me(Uu(),1);var Ry={};Y(Ry,{base32:()=>Wi,base32hex:()=>JP,base32hexpad:()=>ZP,base32hexpadupper:()=>eD,base32hexupper:()=>XP,base32pad:()=>jP,base32padupper:()=>QP,base32upper:()=>mS,base32z:()=>tD});function $P(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var i=0;i<t.length;i++){var o=t.charAt(i),s=o.charCodeAt(0);if(r[s]!==255)throw new TypeError(o+" is ambiguous");r[s]=i}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function f(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var m=0,y=0,g=0,b=h.length;g!==b&&h[g]===0;)g++,m++;for(var w=(b-g)*l+1>>>0,_=new Uint8Array(w);g!==b;){for(var E=h[g],A=0,B=w-1;(E!==0||A<y)&&B!==-1;B--,A++)E+=256*_[B]>>>0,_[B]=E%a>>>0,E=E/a>>>0;if(E!==0)throw new Error("Non-zero carry");y=A,g++}for(var I=w-y;I!==w&&_[I]===0;)I++;for(var L=c.repeat(m);I<w;++I)L+=t.charAt(_[I]);return L}function d(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var m=0;if(h[m]!==" "){for(var y=0,g=0;h[m]===c;)y++,m++;for(var b=(h.length-m)*u+1>>>0,w=new Uint8Array(b);h[m];){var _=r[h.charCodeAt(m)];if(_===255)return;for(var E=0,A=b-1;(_!==0||E<g)&&A!==-1;A--,E++)_+=a*w[A]>>>0,w[A]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");g=E,m++}if(h[m]!==" "){for(var B=b-g;B!==b&&w[B]===0;)B++;for(var I=new Uint8Array(y+(b-B)),L=y;B!==b;)I[L++]=w[B++];return I}}}function p(h){var m=d(h);if(m)return m;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:d,decode:p}}var zP=$P,GP=zP,uS=GP;var moe=new Uint8Array(0);var lS=(t,e)=>{if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0},ti=t=>{if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")};var fS=t=>new TextEncoder().encode(t),hS=t=>new TextDecoder().decode(t);var Ay=class{constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Sy=class{constructor(e,r,n){if(this.name=e,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return pS(this,e)}},_y=class{constructor(e){this.decoders=e}or(e){return pS(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},pS=(t,e)=>new _y({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}}),Iy=class{constructor(e,r,n,i){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=i,this.encoder=new Ay(e,r,n),this.decoder=new Sy(e,r,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},va=({name:t,prefix:e,encode:r,decode:n})=>new Iy(t,e,r,n),Gi=({prefix:t,name:e,alphabet:r})=>{let{encode:n,decode:i}=uS(r,e);return va({prefix:t,name:e,encode:n,decode:o=>ti(i(o))})},WP=(t,e,r,n)=>{let i={};for(let l=0;l<e.length;++l)i[e[l]]=l;let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),a=0,c=0,u=0;for(let l=0;l<o;++l){let f=i[t[l]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|f,a+=r,a>=8&&(a-=8,s[u++]=255&c>>a)}if(a>=r||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return s},YP=(t,e,r)=>{let n=e[e.length-1]==="=",i=(1<<r)-1,o="",s=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],s+=8;s>r;)s-=r,o+=e[i&a>>s];if(s&&(o+=e[i&a<<r-s]),n)for(;o.length*r&7;)o+="=";return o},tt=({name:t,prefix:e,bitsPerChar:r,alphabet:n})=>va({prefix:e,name:t,encode(i){return YP(i,n,r)},decode(i){return WP(i,n,r,t)}});var Wi=tt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),mS=tt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),jP=tt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),QP=tt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),JP=tt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),XP=tt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ZP=tt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),eD=tt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),tD=tt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var By={};Y(By,{base58btc:()=>Nt,base58flickr:()=>rD});var Nt=Gi({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),rD=Gi({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ty={};Y(Ty,{base64:()=>Ea,base64pad:()=>nD,base64url:()=>iD,base64urlpad:()=>oD});var Ea=tt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),nD=tt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),iD=tt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),oD=tt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});mr.default.formatters.b=t=>t==null?"undefined":Nt.baseEncode(t);mr.default.formatters.t=t=>t==null?"undefined":Wi.baseEncode(t);mr.default.formatters.m=t=>t==null?"undefined":Ea.baseEncode(t);mr.default.formatters.p=t=>t==null?"undefined":t.toString();mr.default.formatters.c=t=>t==null?"undefined":t.toString();mr.default.formatters.k=t=>t==null?"undefined":t.toString();mr.default.formatters.a=t=>t==null?"undefined":t.toString();function sD(t){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=t,e.destroy=()=>!0,e.extend=()=>e,e}function Yi(t){let e=sD(`${t}:trace`);return mr.default.enabled(`${t}:trace`)&&mr.default.names.map(r=>r.toString()).find(r=>r.includes(":trace"))!=null&&(e=(0,mr.default)(`${t}:trace`)),Object.assign((0,mr.default)(t),{error:(0,mr.default)(`${t}:error`),trace:e})}var ky=Symbol.for("@libp2p/peer-id");function yS(t){return t!=null&&!!t[ky]}var Cy={};Y(Cy,{base10:()=>aD});var aD=Gi({prefix:"9",name:"base10",alphabet:"0123456789"});var Py={};Y(Py,{base16:()=>cD,base16upper:()=>uD});var cD=tt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),uD=tt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Dy={};Y(Dy,{base2:()=>lD});var lD=tt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ny={};Y(Ny,{base256emoji:()=>mD});var gS=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),fD=gS.reduce((t,e,r)=>(t[r]=e,t),[]),hD=gS.reduce((t,e,r)=>(t[e.codePointAt(0)]=r,t),[]);function dD(t){return t.reduce((e,r)=>(e+=fD[r],e),"")}function pD(t){let e=[];for(let r of t){let n=hD[r.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${r}`);e.push(n)}return new Uint8Array(e)}var mD=va({prefix:"\u{1F680}",name:"base256emoji",encode:dD,decode:pD});var Ly={};Y(Ly,{base36:()=>Oh,base36upper:()=>yD});var Oh=Gi({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),yD=Gi({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Oy={};Y(Oy,{base8:()=>gD});var gD=tt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Uy={};Y(Uy,{identity:()=>bD});var bD=va({prefix:"\0",name:"identity",encode:t=>hS(t),decode:t=>fS(t)});var Koe=new TextEncoder,Moe=new TextDecoder;var My={};Y(My,{identity:()=>yn});var vD=xS,bS=128,ED=127,AD=~ED,SD=Math.pow(2,31);function xS(t,e,r){e=e||[],r=r||0;for(var n=r;t>=SD;)e[r++]=t&255|bS,t/=128;for(;t&AD;)e[r++]=t&255|bS,t>>>=7;return e[r]=t|0,xS.bytes=r-n+1,e}var _D=Ky,ID=128,wS=127;function Ky(t,n){var r=0,n=n||0,i=0,o=n,s,a=t.length;do{if(o>=a)throw Ky.bytes=0,new RangeError("Could not decode varint");s=t[o++],r+=i<28?(s&wS)<<i:(s&wS)*Math.pow(2,i),i+=7}while(s>=ID);return Ky.bytes=o-n,r}var RD=Math.pow(2,7),BD=Math.pow(2,14),TD=Math.pow(2,21),kD=Math.pow(2,28),CD=Math.pow(2,35),PD=Math.pow(2,42),DD=Math.pow(2,49),ND=Math.pow(2,56),LD=Math.pow(2,63),OD=function(t){return t<RD?1:t<BD?2:t<TD?3:t<kD?4:t<CD?5:t<PD?6:t<DD?7:t<ND?8:t<LD?9:10},UD={encode:vD,decode:_D,encodingLength:OD},KD=UD,Jc=KD;var Xc=(t,e=0)=>[Jc.decode(t,e),Jc.decode.bytes],Aa=(t,e,r=0)=>(Jc.encode(t,e,r),e),Sa=t=>Jc.encodingLength(t);var mn=(t,e)=>{let r=e.byteLength,n=Sa(t),i=n+Sa(r),o=new Uint8Array(i+r);return Aa(t,o,0),Aa(r,o,n),o.set(e,i),new _a(t,r,e,o)},Ia=t=>{let e=ti(t),[r,n]=Xc(e),[i,o]=Xc(e.subarray(n)),s=e.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new _a(r,i,s,e)},vS=(t,e)=>{if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&lS(t.bytes,r.bytes)}},_a=class{constructor(e,r,n,i){this.code=e,this.size=r,this.digest=n,this.bytes=i}};var ES=0,MD="identity",AS=ti,FD=t=>mn(ES,AS(t)),yn={code:ES,name:MD,encode:AS,digest:FD};var Hy={};Y(Hy,{sha256:()=>Lt,sha512:()=>VD});var Vy=({name:t,code:e,encode:r})=>new Fy(t,e,r),Fy=class{constructor(e,r,n){this.name=e,this.code=r,this.encode=n}digest(e){if(e instanceof Uint8Array){let r=this.encode(e);return r instanceof Uint8Array?mn(this.code,r):r.then(n=>mn(this.code,n))}else throw Error("Unknown type, must be binary type")}};var _S=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),Lt=Vy({name:"sha2-256",code:18,encode:_S("SHA-256")}),VD=Vy({name:"sha2-512",code:19,encode:_S("SHA-512")});var IS=(t,e)=>{let{bytes:r,version:n}=t;switch(n){case 0:return qD(r,qy(t),e||Nt.encoder);default:return $D(r,qy(t),e||Wi.encoder)}};var RS=new WeakMap,qy=t=>{let e=RS.get(t);if(e==null){let r=new Map;return RS.set(t,r),r}return e},Gr=class t{constructor(e,r,n,i){this.code=r,this.version=e,this.multihash=n,this.bytes=i,this["/"]=i}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==Zc)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==zD)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=mn(e,r);return t.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let n=r;return n&&e.code===n.code&&e.version===n.version&&vS(e.multihash,n.multihash)}toString(e){return IS(this,e)}toJSON(){return{"/":IS(this)}}link(){return this}get[Symbol.toStringTag](){return"CID"}[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:i,multihash:o,bytes:s}=r;return new t(n,i,o,s||BS(n,i,o.bytes))}else if(r[GD]===!0){let{version:n,multihash:i,code:o}=r,s=Ia(i);return t.create(n,o,s)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==Zc)throw new Error(`Version 0 CID must use dag-pb (code: ${Zc}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let i=BS(e,r,n.bytes);return new t(e,r,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Zc,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,i=ti(e.subarray(n,n+r.multihashSize));if(i.byteLength!==r.multihashSize)throw new Error("Incorrect length");let o=i.subarray(r.multihashSize-r.digestSize),s=new _a(r.multihashCode,r.digestSize,o,i);return[r.version===0?t.createV0(s):t.createV1(r.codec,s),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[f,d]=Xc(e.subarray(r));return r+=d,f},i=n(),o=Zc;if(i===18?(i=0,r=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let s=r,a=n(),c=n(),u=r+c,l=u-s;return{version:i,codec:o,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(e,r){let[n,i]=HD(e,r),o=t.decode(i);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return qy(o).set(n,e),o}},HD=(t,e)=>{switch(t[0]){case"Q":{let r=e||Nt;return[Nt.prefix,r.decode(`${Nt.prefix}${t}`)]}case Nt.prefix:{let r=e||Nt;return[Nt.prefix,r.decode(t)]}case Wi.prefix:{let r=e||Wi;return[Wi.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}},qD=(t,e,r)=>{let{prefix:n}=r;if(n!==Nt.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let i=e.get(n);if(i==null){let o=r.encode(t).slice(1);return e.set(n,o),o}else return i},$D=(t,e,r)=>{let{prefix:n}=r,i=e.get(n);if(i==null){let o=r.encode(t);return e.set(n,o),o}else return i},Zc=112,zD=18,BS=(t,e,r)=>{let n=Sa(t),i=n+Sa(e),o=new Uint8Array(i+r.byteLength);return Aa(t,o,0),Aa(e,o,n),o.set(r,i),o},GD=Symbol.for("@ipld/js-cid/CID");var Ra={...Uy,...Dy,...Oy,...Cy,...Py,...Ry,...Ly,...By,...Ty,...Ny},tse={...Hy,...My};function Wt(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}var WD=Symbol.for("nodejs.util.inspect.custom"),TS=Object.values(Ra).map(t=>t.decoder).reduce((t,e)=>t.or(e),Ra.identity.decoder),kS=114,$y=36,zy=37,eu=class{type;multihash;privateKey;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,this.privateKey=e.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[ky]=!0;toString(){return this.string==null&&(this.string=Nt.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return Gr.createV1(kS,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(e){if(e instanceof Uint8Array)return Wt(this.multihash.bytes,e);if(typeof e=="string")return Ca(e).equals(this);if(e?.multihash?.bytes!=null)return Wt(this.multihash.bytes,e.multihash.bytes);throw new Error("not valid Id")}[WD](){return`PeerId(${this.toString()})`}},Ba=class extends eu{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Ta=class extends eu{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.multihash.digest}},ka=class extends eu{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.multihash.digest}};function Ca(t,e){if(e=e??TS,t.charAt(0)==="1"||t.charAt(0)==="Q"){let r=Ia(Nt.decode(`z${t}`));return t.startsWith("12D")?new Ta({multihash:r}):t.startsWith("16U")?new ka({multihash:r}):new Ba({multihash:r})}return tu(TS.decode(t))}function tu(t){try{let e=Ia(t);if(e.code===yn.code){if(e.digest.length===$y)return new Ta({multihash:e});if(e.digest.length===zy)return new ka({multihash:e})}if(e.code===Lt.code)return new Ba({multihash:e})}catch{return YD(Gr.decode(t))}throw new Error("Supplied PeerID CID is invalid")}function YD(t){if(t==null||t.multihash==null||t.version==null||t.version===1&&t.code!==kS)throw new Error("Supplied PeerID CID is invalid");let e=t.multihash;if(e.code===Lt.code)return new Ba({multihash:t.multihash});if(e.code===yn.code){if(e.digest.length===$y)return new Ta({multihash:t.multihash});if(e.digest.length===zy)return new ka({multihash:t.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function CS(t,e){return t.length===$y?new Ta({multihash:mn(yn.code,t),privateKey:e}):t.length===zy?new ka({multihash:mn(yn.code,t),privateKey:e}):new Ba({multihash:await Lt.digest(t),publicKey:t,privateKey:e})}async function*Kh(t,e={}){let r=t.getReader();try{for(;;){let n=await r.read();if(n.done)return;yield n.value}}finally{e.preventCancel!==!0&&await r.cancel(),r.releaseLock()}}var Ace=me(ou(),1),Sce=me(W_(),1);var HL=me(Le(),1);function Oa(t){return globalThis.Buffer!=null?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t}function nd(t=0){return globalThis.Buffer?.allocUnsafe!=null?Oa(globalThis.Buffer.allocUnsafe(t)):new Uint8Array(t)}function j_(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Y_=j_("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),pg=j_("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=nd(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),wL={utf8:Y_,"utf-8":Y_,hex:Ra.base16,latin1:pg,ascii:pg,binary:pg,...Ra},id=wL;function Qt(t,e="utf8"){let r=id[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?Oa(globalThis.Buffer.from(t,"utf-8")):r.decoder.decode(`${r.prefix}${t}`)}var bg={};Y(bg,{Ed25519PrivateKey:()=>Yo,Ed25519PublicKey:()=>cu,generateKeyPair:()=>AL,generateKeyPairFromSeed:()=>rI,unmarshalEd25519PrivateKey:()=>vL,unmarshalEd25519PublicKey:()=>EL});var Ua=32,oi=64,od=32;async function Q_(){let t=Ge.utils.randomPrivateKey(),e=Ge.getPublicKey(t);return{privateKey:eI(t,e),publicKey:e}}async function J_(t){if(t.length!==od)throw new TypeError('"seed" must be 32 bytes in length.');if(!(t instanceof Uint8Array))throw new TypeError('"seed" must be a node.js Buffer, or Uint8Array.');let e=t,r=Ge.getPublicKey(e);return{privateKey:eI(e,r),publicKey:r}}async function X_(t,e){let r=t.subarray(0,od);return Ge.sign(e,r)}async function Z_(t,e,r){return Ge.verify(e,r,t)}function eI(t,e){let r=new Uint8Array(oi);for(let n=0;n<od;n++)r[n]=t[n],r[od+n]=e[n];return r}function Wo(t,e){e==null&&(e=t.reduce((i,o)=>i+o.length,0));let r=nd(e),n=0;for(let i of t)r.set(i,n),n+=i.length;return Oa(r)}var or={get(t=globalThis){let e=t.crypto;if(e==null||e.subtle==null)throw Object.assign(new Error("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p-crypto/blob/master/README.md#web-crypto-api"),{code:"ERR_MISSING_WEB_CRYPTO"});return e}};var mg={alg:"A128GCM",ext:!0,k:"scm9jmO_4BJAgdwWGVulLg",key_ops:["encrypt","decrypt"],kty:"oct"};function yg(t){let e=t?.algorithm??"AES-GCM",r=t?.keyLength??16,n=t?.nonceLength??12,i=t?.digest??"SHA-256",o=t?.saltLength??16,s=t?.iterations??32767,a=or.get();r*=8;async function c(f,d){let p=a.getRandomValues(new Uint8Array(o)),h=a.getRandomValues(new Uint8Array(n)),m={name:e,iv:h};typeof d=="string"&&(d=Qt(d));let y;if(d.length===0){y=await a.subtle.importKey("jwk",mg,{name:"AES-GCM"},!0,["encrypt"]);try{let b={name:"PBKDF2",salt:p,iterations:s,hash:{name:i}},w=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(b,w,{name:e,length:r},!0,["encrypt"])}catch{y=await a.subtle.importKey("jwk",mg,{name:"AES-GCM"},!0,["encrypt"])}}else{let b={name:"PBKDF2",salt:p,iterations:s,hash:{name:i}},w=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);y=await a.subtle.deriveKey(b,w,{name:e,length:r},!0,["encrypt"])}let g=await a.subtle.encrypt(m,y,f);return Wo([p,m.iv,new Uint8Array(g)])}async function u(f,d){let p=f.subarray(0,o),h=f.subarray(o,o+n),m=f.subarray(o+n),y={name:e,iv:h};typeof d=="string"&&(d=Qt(d));let g;if(d.length===0)try{let w={name:"PBKDF2",salt:p,iterations:s,hash:{name:i}},_=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);g=await a.subtle.deriveKey(w,_,{name:e,length:r},!0,["decrypt"])}catch{g=await a.subtle.importKey("jwk",mg,{name:"AES-GCM"},!0,["decrypt"])}else{let w={name:"PBKDF2",salt:p,iterations:s,hash:{name:i}},_=await a.subtle.importKey("raw",d,{name:"PBKDF2"},!1,["deriveKey"]);g=await a.subtle.deriveKey(w,_,{name:e,length:r},!0,["decrypt"])}let b=await a.subtle.decrypt(y,g,m);return new Uint8Array(b)}return{encrypt:c,decrypt:u}}async function Ka(t,e){let n=await yg().encrypt(t,e);return Ea.encode(n)}var st;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.Secp256k1="Secp256k1"})(st||(st={}));var gg;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.Secp256k1=2]="Secp256k1"})(gg||(gg={}));(function(t){t.codec=()=>Zt(gg)})(st||(st={}));var An;(function(t){let e;t.codec=()=>(e==null&&(e=Ee((r,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),st.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),i.lengthDelimited!==!1&&n.ldelim()},(r,n)=>{let i={},o=n==null?r.len:r.pos+n;for(;r.pos<o;){let s=r.uint32();switch(s>>>3){case 1:i.Type=st.codec().decode(r);break;case 2:i.Data=r.bytes();break;default:r.skipType(s&7);break}}return i})),e),t.encode=r=>ve(r,t.codec()),t.decode=r=>xe(r,t.codec())})(An||(An={}));var si;(function(t){let e;t.codec=()=>(e==null&&(e=Ee((r,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),st.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),i.lengthDelimited!==!1&&n.ldelim()},(r,n)=>{let i={},o=n==null?r.len:r.pos+n;for(;r.pos<o;){let s=r.uint32();switch(s>>>3){case 1:i.Type=st.codec().decode(r);break;case 2:i.Data=r.bytes();break;default:r.skipType(s&7);break}}return i})),e),t.encode=r=>ve(r,t.codec()),t.decode=r=>xe(r,t.codec())})(si||(si={}));var cu=class{_key;constructor(e){this._key=Ma(e,Ua)}async verify(e,r){return Z_(this._key,r,e)}marshal(){return this._key}get bytes(){return An.encode({Type:st.Ed25519,Data:this.marshal()}).subarray()}equals(e){return Wt(this.bytes,e.bytes)}async hash(){let{bytes:e}=await Lt.digest(this.bytes);return e}},Yo=class{_key;_publicKey;constructor(e,r){this._key=Ma(e,oi),this._publicKey=Ma(r,Ua)}async sign(e){return X_(this._key,e)}get public(){return new cu(this._publicKey)}marshal(){return this._key}get bytes(){return si.encode({Type:st.Ed25519,Data:this.marshal()}).subarray()}equals(e){return Wt(this.bytes,e.bytes)}async hash(){let{bytes:e}=await Lt.digest(this.bytes);return e}async id(){let e=yn.digest(this.public.bytes);return Nt.encode(e.bytes).substring(1)}async export(e,r="libp2p-key"){if(r==="libp2p-key")return Ka(this.bytes,e);throw new ce(`export format '${r}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function vL(t){if(t.length>oi){t=Ma(t,oi+Ua);let n=t.subarray(0,oi),i=t.subarray(oi,t.length);return new Yo(n,i)}t=Ma(t,oi);let e=t.subarray(0,oi),r=t.subarray(Ua);return new Yo(e,r)}function EL(t){return t=Ma(t,Ua),new cu(t)}async function AL(){let{privateKey:t,publicKey:e}=await Q_();return new Yo(t,e)}async function rI(t){let{privateKey:e,publicKey:r}=await J_(t);return new Yo(e,r)}function Ma(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new ce(`Key must be a Uint8Array of length ${e}, got ${t.length}`,"ERR_INVALID_KEY_TYPE");return t}function yr(t,e="utf8"){let r=id[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(t.buffer,t.byteOffset,t.byteLength).toString("utf8"):r.encoder.encode(t).substring(1)}var dae=me(ft(),1),pae=me(Zh(),1),nI=me(Le(),1);function jr(t,e){let r=Uint8Array.from(t.abs().toByteArray());if(r=r[0]===0?r.subarray(1):r,e!=null){if(r.length>e)throw new Error("byte array longer than desired length");r=Wo([new Uint8Array(e-r.length),r])}return yr(r,"base64url")}function gr(t){let e=iI(t);return new nI.default.jsbn.BigInteger(yr(e,"base16"),16)}function iI(t,e){let r=Qt(t,"base64urlpad");if(e!=null){if(r.length>e)throw new Error("byte array longer than desired length");r=Wo([new Uint8Array(e-r.length),r])}return r}var SL={"P-256":256,"P-384":384,"P-521":521},_L=Object.keys(SL),_ae=_L.join(" / ");var Ag={};Y(Ag,{MAX_KEY_SIZE:()=>hu,RsaPrivateKey:()=>Fa,RsaPublicKey:()=>fu,fromJwk:()=>OL,generateKeyPair:()=>UL,unmarshalRsaPrivateKey:()=>NL,unmarshalRsaPublicKey:()=>LL});var lu=me(Le(),1);var uce=me(uI(),1);function ad(t){if(isNaN(t)||t<=0)throw new ce("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return _r(t)}var zae=me(rd(),1),vg=me(Le(),1);function lI(t,e){return e.map(r=>gr(t[r]))}function fI(t){return vg.default.pki.setRsaPrivateKey(...lI(t,["n","e","d","p","q","dp","dq","qi"]))}function hI(t){return vg.default.pki.setRsaPublicKey(...lI(t,["n","e"]))}var Qo={};Y(Qo,{jwkToPkcs1:()=>TL,jwkToPkix:()=>CL,pkcs1ToJwk:()=>BL,pkixToJwk:()=>kL});var Yae=me(ou(),1),jae=me(rd(),1);var ai=me(Le(),1);function BL(t){let e=ai.default.asn1.fromDer(yr(t,"ascii")),r=ai.default.pki.privateKeyFromAsn1(e);return{kty:"RSA",n:jr(r.n),e:jr(r.e),d:jr(r.d),p:jr(r.p),q:jr(r.q),dp:jr(r.dP),dq:jr(r.dQ),qi:jr(r.qInv),alg:"RS256"}}function TL(t){if(t.n==null||t.e==null||t.d==null||t.p==null||t.q==null||t.dp==null||t.dq==null||t.qi==null)throw new ce("JWK was missing components","ERR_INVALID_PARAMETERS");let e=ai.default.pki.privateKeyToAsn1({n:gr(t.n),e:gr(t.e),d:gr(t.d),p:gr(t.p),q:gr(t.q),dP:gr(t.dp),dQ:gr(t.dq),qInv:gr(t.qi)});return Qt(ai.default.asn1.toDer(e).getBytes(),"ascii")}function kL(t){let e=ai.default.asn1.fromDer(yr(t,"ascii")),r=ai.default.pki.publicKeyFromAsn1(e);return{kty:"RSA",n:jr(r.n),e:jr(r.e)}}function CL(t){if(t.n==null||t.e==null)throw new ce("JWK was missing components","ERR_INVALID_PARAMETERS");let e=ai.default.pki.publicKeyToAsn1({n:gr(t.n),e:gr(t.e)});return Qt(ai.default.asn1.toDer(e).getBytes(),"ascii")}async function dI(t){let e=await or.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:t,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),r=await yI(e);return{privateKey:r[0],publicKey:r[1]}}async function Eg(t){let r=[await or.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),await PL(t)],n=await yI({privateKey:r[0],publicKey:r[1]});return{privateKey:n[0],publicKey:n[1]}}async function pI(t,e){let r=await or.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await or.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},r,Uint8Array.from(e));return new Uint8Array(n,0,n.byteLength)}async function mI(t,e,r){let n=await or.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return or.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,e,r)}async function yI(t){if(t.privateKey==null||t.publicKey==null)throw new ce("Private and public key are required","ERR_INVALID_PARAMETERS");return Promise.all([or.get().subtle.exportKey("jwk",t.privateKey),or.get().subtle.exportKey("jwk",t.publicKey)])}async function PL(t){return or.get().subtle.importKey("jwk",{kty:t.kty,n:t.n,e:t.e},{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])}function gI(t,e,r,n){let i=e?hI(t):fI(t),o=yr(Uint8Array.from(r),"ascii"),s=n(o,i);return Qt(s,"ascii")}function bI(t,e){return gI(t,!0,e,(r,n)=>n.encrypt(r))}function wI(t,e){return gI(t,!1,e,(r,n)=>n.decrypt(r))}function cd(t){if(t.kty!=="RSA")throw new ce("invalid key type","ERR_INVALID_KEY_TYPE");if(t.n==null)throw new ce("invalid key modulus","ERR_INVALID_KEY_MODULUS");return Qt(t.n,"base64url").length*8}var hu=8192,fu=class{_key;constructor(e){this._key=e}async verify(e,r){return mI(this._key,r,e)}marshal(){return Qo.jwkToPkix(this._key)}get bytes(){return An.encode({Type:st.RSA,Data:this.marshal()}).subarray()}encrypt(e){return bI(this._key,e)}equals(e){return Wt(this.bytes,e.bytes)}async hash(){let{bytes:e}=await Lt.digest(this.bytes);return e}},Fa=class{_key;_publicKey;constructor(e,r){this._key=e,this._publicKey=r}genSecret(){return ad(16)}async sign(e){return pI(this._key,e)}get public(){if(this._publicKey==null)throw new ce("public key not provided","ERR_PUBKEY_NOT_PROVIDED");return new fu(this._publicKey)}decrypt(e){return wI(this._key,e)}marshal(){return Qo.jwkToPkcs1(this._key)}get bytes(){return si.encode({Type:st.RSA,Data:this.marshal()}).subarray()}equals(e){return Wt(this.bytes,e.bytes)}async hash(){let{bytes:e}=await Lt.digest(this.bytes);return e}async id(){let e=await this.public.hash();return yr(e,"base58btc")}async export(e,r="pkcs-8"){if(r==="pkcs-8"){let n=new lu.default.util.ByteBuffer(this.marshal()),i=lu.default.asn1.fromDer(n),o=lu.default.pki.privateKeyFromAsn1(i),s={algorithm:"aes256",count:1e4,saltSize:128/8,prfAlgorithm:"sha512"};return lu.default.pki.encryptRsaPrivateKey(o,e,s)}else{if(r==="libp2p-key")return Ka(this.bytes,e);throw new ce(`export format '${r}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}}};async function NL(t){let e=Qo.pkcs1ToJwk(t);if(cd(e)>hu)throw new ce("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let r=await Eg(e);return new Fa(r.privateKey,r.publicKey)}function LL(t){let e=Qo.pkixToJwk(t);if(cd(e)>hu)throw new ce("key size is too large","ERR_KEY_SIZE_TOO_LARGE");return new fu(e)}async function OL(t){if(cd(t)>hu)throw new ce("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await Eg(t);return new Fa(e.privateKey,e.publicKey)}async function UL(t){if(t>hu)throw new ce("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await dI(t);return new Fa(e.privateKey,e.publicKey)}var _g={};Y(_g,{Secp256k1PrivateKey:()=>pu,Secp256k1PublicKey:()=>du,generateKeyPair:()=>VL,unmarshalSecp256k1PrivateKey:()=>ML,unmarshalSecp256k1PublicKey:()=>FL});function xI(){return he.utils.randomPrivateKey()}async function vI(t,e){let{digest:r}=await Lt.digest(e);try{return he.sign(r,t).toDERRawBytes()}catch(n){throw new ce(String(n),"ERR_INVALID_INPUT")}}async function EI(t,e,r){try{let{digest:n}=await Lt.digest(r);return he.verify(e,n,t)}catch(n){throw new ce(String(n),"ERR_INVALID_INPUT")}}function AI(t){return he.ProjectivePoint.fromHex(t).toRawBytes(!0)}function SI(t){try{he.getPublicKey(t,!0)}catch(e){throw new ce(String(e),"ERR_INVALID_PRIVATE_KEY")}}function Sg(t){try{he.ProjectivePoint.fromHex(t)}catch(e){throw new ce(String(e),"ERR_INVALID_PUBLIC_KEY")}}function _I(t){try{return he.getPublicKey(t,!0)}catch(e){throw new ce(String(e),"ERR_INVALID_PRIVATE_KEY")}}var du=class{_key;constructor(e){Sg(e),this._key=e}async verify(e,r){return EI(this._key,r,e)}marshal(){return AI(this._key)}get bytes(){return An.encode({Type:st.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return Wt(this.bytes,e.bytes)}async hash(){let{bytes:e}=await Lt.digest(this.bytes);return e}},pu=class{_key;_publicKey;constructor(e,r){this._key=e,this._publicKey=r??_I(e),SI(this._key),Sg(this._publicKey)}async sign(e){return vI(this._key,e)}get public(){return new du(this._publicKey)}marshal(){return this._key}get bytes(){return si.encode({Type:st.Secp256k1,Data:this.marshal()}).subarray()}equals(e){return Wt(this.bytes,e.bytes)}async hash(){let{bytes:e}=await Lt.digest(this.bytes);return e}async id(){let e=await this.public.hash();return yr(e,"base58btc")}async export(e,r="libp2p-key"){if(r==="libp2p-key")return Ka(this.bytes,e);throw new ce(`export format '${r}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function ML(t){return new pu(t)}function FL(t){return new du(t)}async function VL(){let t=xI();return new pu(t)}var ud={rsa:Ag,ed25519:bg,secp256k1:_g};function qL(t){let e=Object.keys(ud).join(" / ");return new ce(`invalid or unsupported key type ${t}. Must be ${e}`,"ERR_UNSUPPORTED_KEY_TYPE")}function Ig(t){let e=An.decode(t),r=e.Data??new Uint8Array;switch(e.Type){case st.RSA:return ud.rsa.unmarshalRsaPublicKey(r);case st.Ed25519:return ud.ed25519.unmarshalEd25519PublicKey(r);case st.Secp256k1:return ud.secp256k1.unmarshalSecp256k1PublicKey(r);default:throw qL(e.Type??"unknown")}}var tU=me(fo(),1);var rU=me(Bg(),1);function ld(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Jo(t){return globalThis.Buffer!=null?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t}var Dg={};Y(Dg,{base10:()=>jL});var Lce=new Uint8Array(0);function II(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function ci(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function RI(t){return new TextEncoder().encode(t)}function BI(t){return new TextDecoder().decode(t)}function $L(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var i=0;i<t.length;i++){var o=t.charAt(i),s=o.charCodeAt(0);if(r[s]!==255)throw new TypeError(o+" is ambiguous");r[s]=i}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function f(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var m=0,y=0,g=0,b=h.length;g!==b&&h[g]===0;)g++,m++;for(var w=(b-g)*l+1>>>0,_=new Uint8Array(w);g!==b;){for(var E=h[g],A=0,B=w-1;(E!==0||A<y)&&B!==-1;B--,A++)E+=256*_[B]>>>0,_[B]=E%a>>>0,E=E/a>>>0;if(E!==0)throw new Error("Non-zero carry");y=A,g++}for(var I=w-y;I!==w&&_[I]===0;)I++;for(var L=c.repeat(m);I<w;++I)L+=t.charAt(_[I]);return L}function d(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var m=0;if(h[m]!==" "){for(var y=0,g=0;h[m]===c;)y++,m++;for(var b=(h.length-m)*u+1>>>0,w=new Uint8Array(b);h[m];){var _=r[h.charCodeAt(m)];if(_===255)return;for(var E=0,A=b-1;(_!==0||E<g)&&A!==-1;A--,E++)_+=a*w[A]>>>0,w[A]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");g=E,m++}if(h[m]!==" "){for(var B=b-g;B!==b&&w[B]===0;)B++;for(var I=new Uint8Array(y+(b-B)),L=y;B!==b;)I[L++]=w[B++];return I}}}function p(h){var m=d(h);if(m)return m;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:d,decode:p}}var zL=$L,GL=zL,kI=GL;var Tg=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},kg=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){if(this.name=e,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return CI(this,e)}},Cg=class{decoders;constructor(e){this.decoders=e}or(e){return CI(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function CI(t,e){return new Cg({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Pg=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,i){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=i,this.encoder=new Tg(e,r,n),this.decoder=new kg(e,r,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Va({name:t,prefix:e,encode:r,decode:n}){return new Pg(t,e,r,n)}function Zi({name:t,prefix:e,alphabet:r}){let{encode:n,decode:i}=kI(r,t);return Va({prefix:e,name:t,encode:n,decode:o=>ci(i(o))})}function WL(t,e,r,n){let i={};for(let l=0;l<e.length;++l)i[e[l]]=l;let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),a=0,c=0,u=0;for(let l=0;l<o;++l){let f=i[t[l]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|f,a+=r,a>=8&&(a-=8,s[u++]=255&c>>a)}if(a>=r||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return s}function YL(t,e,r){let n=e[e.length-1]==="=",i=(1<<r)-1,o="",s=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],s+=8;s>r;)s-=r,o+=e[i&a>>s];if(s!==0&&(o+=e[i&a<<r-s]),n)for(;o.length*r&7;)o+="=";return o}function rt({name:t,prefix:e,bitsPerChar:r,alphabet:n}){return Va({prefix:e,name:t,encode(i){return YL(i,n,r)},decode(i){return WL(i,n,r,t)}})}var jL=Zi({prefix:"9",name:"base10",alphabet:"0123456789"});var Ng={};Y(Ng,{base16:()=>QL,base16upper:()=>JL});var QL=rt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),JL=rt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Lg={};Y(Lg,{base2:()=>XL});var XL=rt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Og={};Y(Og,{base256emoji:()=>nO});var PI=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),ZL=PI.reduce((t,e,r)=>(t[r]=e,t),[]),eO=PI.reduce((t,e,r)=>(t[e.codePointAt(0)]=r,t),[]);function tO(t){return t.reduce((e,r)=>(e+=ZL[r],e),"")}function rO(t){let e=[];for(let r of t){let n=eO[r.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${r}`);e.push(n)}return new Uint8Array(e)}var nO=Va({prefix:"\u{1F680}",name:"base256emoji",encode:tO,decode:rO});var Ug={};Y(Ug,{base32:()=>Ha,base32hex:()=>aO,base32hexpad:()=>uO,base32hexpadupper:()=>lO,base32hexupper:()=>cO,base32pad:()=>oO,base32padupper:()=>sO,base32upper:()=>iO,base32z:()=>fO});var Ha=rt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),iO=rt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),oO=rt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),sO=rt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),aO=rt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),cO=rt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),uO=rt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),lO=rt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),fO=rt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Kg={};Y(Kg,{base36:()=>hO,base36upper:()=>dO});var hO=Zi({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),dO=Zi({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Mg={};Y(Mg,{base58btc:()=>Sn,base58flickr:()=>pO});var Sn=Zi({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),pO=Zi({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Fg={};Y(Fg,{base64:()=>mO,base64pad:()=>yO,base64url:()=>gO,base64urlpad:()=>bO});var mO=rt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),yO=rt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),gO=rt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),bO=rt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Vg={};Y(Vg,{base8:()=>wO});var wO=rt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Hg={};Y(Hg,{identity:()=>xO});var xO=Va({prefix:"\0",name:"identity",encode:t=>BI(t),decode:t=>RI(t)});var Jce=new TextEncoder,Xce=new TextDecoder;var $g={};Y($g,{identity:()=>qO});var AO=LI,DI=128,SO=127,_O=~SO,IO=Math.pow(2,31);function LI(t,e,r){e=e||[],r=r||0;for(var n=r;t>=IO;)e[r++]=t&255|DI,t/=128;for(;t&_O;)e[r++]=t&255|DI,t>>>=7;return e[r]=t|0,LI.bytes=r-n+1,e}var RO=qg,BO=128,NI=127;function qg(t,n){var r=0,n=n||0,i=0,o=n,s,a=t.length;do{if(o>=a)throw qg.bytes=0,new RangeError("Could not decode varint");s=t[o++],r+=i<28?(s&NI)<<i:(s&NI)*Math.pow(2,i),i+=7}while(s>=BO);return qg.bytes=o-n,r}var TO=Math.pow(2,7),kO=Math.pow(2,14),CO=Math.pow(2,21),PO=Math.pow(2,28),DO=Math.pow(2,35),NO=Math.pow(2,42),LO=Math.pow(2,49),OO=Math.pow(2,56),UO=Math.pow(2,63),KO=function(t){return t<TO?1:t<kO?2:t<CO?3:t<PO?4:t<DO?5:t<NO?6:t<LO?7:t<OO?8:t<UO?9:10},MO={encode:AO,decode:RO,encodingLength:KO},FO=MO,mu=FO;function yu(t,e=0){return[mu.decode(t,e),mu.decode.bytes]}function qa(t,e,r=0){return mu.encode(t,e,r),e}function $a(t){return mu.encodingLength(t)}function Xo(t,e){let r=e.byteLength,n=$a(t),i=n+$a(r),o=new Uint8Array(i+r);return qa(t,o,0),qa(r,o,n),o.set(e,i),new za(t,r,e,o)}function OI(t){let e=ci(t),[r,n]=yu(e),[i,o]=yu(e.subarray(n)),s=e.subarray(n+o);if(s.byteLength!==i)throw new Error("Incorrect length");return new za(r,i,s,e)}function UI(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&II(t.bytes,r.bytes)}}var za=class{code;size;digest;bytes;constructor(e,r,n,i){this.code=e,this.size=r,this.digest=n,this.bytes=i}};var KI=0,VO="identity",MI=ci;function HO(t){return Xo(KI,MI(t))}var qO={code:KI,name:VO,encode:MI,digest:HO};var Wg={};Y(Wg,{sha256:()=>$O,sha512:()=>zO});function Gg({name:t,code:e,encode:r}){return new zg(t,e,r)}var zg=class{name;code;encode;constructor(e,r,n){this.name=e,this.code=r,this.encode=n}digest(e){if(e instanceof Uint8Array){let r=this.encode(e);return r instanceof Uint8Array?Xo(this.code,r):r.then(n=>Xo(this.code,n))}else throw Error("Unknown type, must be binary type")}};function VI(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var $O=Gg({name:"sha2-256",code:18,encode:VI("SHA-256")}),zO=Gg({name:"sha2-512",code:19,encode:VI("SHA-512")});function HI(t,e){let{bytes:r,version:n}=t;switch(n){case 0:return WO(r,Yg(t),e??Sn.encoder);default:return YO(r,Yg(t),e??Ha.encoder)}}var qI=new WeakMap;function Yg(t){let e=qI.get(t);if(e==null){let r=new Map;return qI.set(t,r),r}return e}var hd=class t{code;version;multihash;bytes;"/";constructor(e,r,n,i){this.code=r,this.version=e,this.multihash=n,this.bytes=i,this["/"]=i}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==bu)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==jO)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=Xo(e,r);return t.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&UI(e.multihash,n.multihash)}toString(e){return HI(this,e)}toJSON(){return{"/":HI(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:i,multihash:o,bytes:s}=r;return new t(n,i,o,s??$I(n,i,o.bytes))}else if(r[QO]===!0){let{version:n,multihash:i,code:o}=r,s=OI(i);return t.create(n,o,s)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==bu)throw new Error(`Version 0 CID must use dag-pb (code: ${bu}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let i=$I(e,r,n.bytes);return new t(e,r,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,bu,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,i=ci(e.subarray(n,n+r.multihashSize));if(i.byteLength!==r.multihashSize)throw new Error("Incorrect length");let o=i.subarray(r.multihashSize-r.digestSize),s=new za(r.multihashCode,r.digestSize,o,i);return[r.version===0?t.createV0(s):t.createV1(r.codec,s),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[f,d]=yu(e.subarray(r));return r+=d,f},i=n(),o=bu;if(i===18?(i=0,r=0):o=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let s=r,a=n(),c=n(),u=r+c,l=u-s;return{version:i,codec:o,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(e,r){let[n,i]=GO(e,r),o=t.decode(i);if(o.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Yg(o).set(n,e),o}};function GO(t,e){switch(t[0]){case"Q":{let r=e??Sn;return[Sn.prefix,r.decode(`${Sn.prefix}${t}`)]}case Sn.prefix:{let r=e??Sn;return[Sn.prefix,r.decode(t)]}case Ha.prefix:{let r=e??Ha;return[Ha.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function WO(t,e,r){let{prefix:n}=r;if(n!==Sn.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let i=e.get(n);if(i==null){let o=r.encode(t).slice(1);return e.set(n,o),o}else return i}function YO(t,e,r){let{prefix:n}=r,i=e.get(n);if(i==null){let o=r.encode(t);return e.set(n,o),o}else return i}var bu=112,jO=18;function $I(t,e,r){let n=$a(t),i=n+$a(e),o=new Uint8Array(i+r.byteLength);return qa(t,o,0),qa(e,o,n),o.set(r,i),o}var QO=Symbol.for("@ipld/js-cid/CID");var jg={...Hg,...Lg,...Vg,...Dg,...Ng,...Ug,...Kg,...Mg,...Fg,...Og},wue={...Wg,...$g};function dd(t=0){return globalThis.Buffer?.allocUnsafe!=null?Jo(globalThis.Buffer.allocUnsafe(t)):new Uint8Array(t)}function GI(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var zI=GI("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Qg=GI("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=dd(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),JO={utf8:zI,"utf-8":zI,hex:jg.base16,latin1:Qg,ascii:Qg,binary:Qg,...jg},pd=JO;function Ga(t,e="utf8"){let r=pd[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?Jo(globalThis.Buffer.from(t,"utf-8")):r.decoder.decode(`${r.prefix}${t}`)}var WI="ERR_IPNS_EXPIRED_RECORD",md="ERR_UNRECOGNIZED_VALIDITY";var ui="ERR_SIGNATURE_VERIFICATION",YI="ERR_UNRECOGNIZED_FORMAT";var Jg="ERR_UNDEFINED_PARAMETER",jI="ERR_INVALID_RECORD_DATA",QI="ERR_INVALID_VALUE",JI="ERR_INVALID_EMBEDDED_KEY";var XI="ERR_RECORD_TOO_LARGE";var Lr;(function(t){let e;(function(i){i.EOL="EOL"})(e=t.ValidityType||(t.ValidityType={}));let r;(function(i){i[i.EOL=0]="EOL"})(r||(r={})),function(i){i.codec=()=>Zt(r)}(e=t.ValidityType||(t.ValidityType={}));let n;t.codec=()=>(n==null&&(n=Ee((i,o,s={})=>{s.lengthDelimited!==!1&&o.fork(),i.value!=null&&(o.uint32(10),o.bytes(i.value)),i.signatureV1!=null&&(o.uint32(18),o.bytes(i.signatureV1)),i.validityType!=null&&(o.uint32(24),t.ValidityType.codec().encode(i.validityType,o)),i.validity!=null&&(o.uint32(34),o.bytes(i.validity)),i.sequence!=null&&(o.uint32(40),o.uint64(i.sequence)),i.ttl!=null&&(o.uint32(48),o.uint64(i.ttl)),i.pubKey!=null&&(o.uint32(58),o.bytes(i.pubKey)),i.signatureV2!=null&&(o.uint32(66),o.bytes(i.signatureV2)),i.data!=null&&(o.uint32(74),o.bytes(i.data)),s.lengthDelimited!==!1&&o.ldelim()},(i,o)=>{let s={},a=o==null?i.len:i.pos+o;for(;i.pos<a;){let c=i.uint32();switch(c>>>3){case 1:s.value=i.bytes();break;case 2:s.signatureV1=i.bytes();break;case 3:s.validityType=t.ValidityType.codec().decode(i);break;case 4:s.validity=i.bytes();break;case 5:s.sequence=i.uint64();break;case 6:s.ttl=i.uint64();break;case 7:s.pubKey=i.bytes();break;case 8:s.signatureV2=i.bytes();break;case 9:s.data=i.bytes();break;default:i.skipType(c&7);break}}return s})),n),t.encode=i=>ve(i,t.codec()),t.decode=i=>xe(i,t.codec())})(Lr||(Lr={}));var sr=me(fo(),1);var ZI=me(Bg(),1);function Zg(t,e){if(globalThis.Buffer!=null)return Jo(globalThis.Buffer.concat(t,e));e==null&&(e=t.reduce((i,o)=>i+o.length,0));let r=dd(e),n=0;for(let i of t)r.set(i,n),n+=i.length;return Jo(r)}function eb(t,e="utf8"){let r=pd[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(t.buffer,t.byteOffset,t.byteLength).toString("utf8"):r.encoder.encode(t).substring(1)}var tb=Yi("ipns:utils"),eR=Ga("/ipns/"),XO=114;function ZO(t){let e=new RegExp("(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d+)Z"),r=String(t).trim().match(e);if(r==null)throw new Error("Invalid format");let n=parseInt(r[1],10),i=parseInt(r[2],10)-1,o=parseInt(r[3],10),s=parseInt(r[4],10),a=parseInt(r[5],10),c=parseInt(r[6],10),u=parseInt(r[7].padEnd(6,"0").slice(0,3),10);return new Date(Date.UTC(n,i,o,s,a,c,u))}var rb=async(t,e)=>{if(e==null||t==null){let n=new Error("one or more of the provided parameters are not defined");throw tb.error(n),(0,sr.default)(n,Jg)}let r;if(e.pubKey!=null){try{r=Ig(e.pubKey)}catch(i){throw tb.error(i),i}if(!(await CS(e.pubKey)).equals(t))throw(0,sr.default)(new Error("Embedded public key did not match PeerID"),JI)}else t.publicKey!=null&&(r=Ig(t.publicKey));if(r!=null)return r;throw(0,sr.default)(new Error("no public key is available"),Jg)};var nb=t=>{let e=Ga("ipns-signature:");return Zg([e,t])},wu=t=>"signatureV1"in t?Lr.encode({value:Ga(t.value),signatureV1:t.signatureV1,validityType:t.validityType,validity:Ga(t.validity.toString()),sequence:t.sequence,ttl:t.ttl,pubKey:t.pubKey,signatureV2:t.signatureV2,data:t.data}):Lr.encode({pubKey:t.pubKey,signatureV2:t.signatureV2,data:t.data});function eo(t){let e=Lr.decode(t);if(e.sequence!=null&&(e.sequence=BigInt(e.sequence)),e.ttl!=null&&(e.ttl=BigInt(e.ttl)),e.signatureV2==null||e.data==null)throw(0,sr.default)(new Error("missing data or signatureV2"),ui);let r=tR(e.data),n=rR(r.Value),i;try{i=ZI.default.fromDate(ZO(eb(r.Validity)))}catch{throw tb.error("unrecognized validity format (not an rfc3339 format)"),(0,sr.default)(new Error("unrecognized validity format (not an rfc3339 format)"),YI)}if(e.value!=null&&e.signatureV1!=null)return eU(e),{value:n,validityType:Lr.ValidityType.EOL,validity:i,sequence:r.Sequence,ttl:r.TTL,pubKey:e.pubKey,signatureV1:e.signatureV1,signatureV2:e.signatureV2,data:e.data};if(e.signatureV2!=null)return{value:n,validityType:Lr.ValidityType.EOL,validity:i,sequence:r.Sequence,ttl:r.TTL,pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data};throw new Error("invalid record: does not include signatureV1 or signatureV2")}var ib=t=>Zg([eR,t.toBytes()]),ob=t=>tu(t.slice(eR.length));var tR=t=>{let e=Ar(t);if(e.ValidityType===0)e.ValidityType=Lr.ValidityType.EOL;else throw(0,sr.default)(new Error("Unknown validity type"),md);return Number.isInteger(e.Sequence)&&(e.Sequence=BigInt(e.Sequence)),Number.isInteger(e.TTL)&&(e.TTL=BigInt(e.TTL)),e},rR=t=>{if(t!=null){if(yS(t))return`/ipns/${t.toCID().toString(Oh)}`;if(t instanceof Uint8Array){let n=eb(t);n.startsWith("/")&&(t=n)}let e=t.toString().trim();if(e.startsWith("/")&&e.length>1)return e;let r=Gr.asCID(t);if(r!=null)return r.code===XO?`/ipns/${r.toString(Oh)}`:`/ipfs/${r.toV1().toString()}`;try{return t instanceof Uint8Array?`/ipfs/${Gr.decode(t).toV1().toString()}`:`/ipfs/${Gr.parse(e).toV1().toString()}`}catch{}}throw(0,sr.default)(new Error("Value must be a valid content path starting with /"),QI)},eU=t=>{if(t.data==null)throw(0,sr.default)(new Error("Record data is missing"),jI);let e=tR(t.data);if(!ld(e.Value,t.value??new Uint8Array(0)))throw(0,sr.default)(new Error('Field "value" did not match between protobuf and CBOR'),ui);if(!ld(e.Validity,t.validity??new Uint8Array(0)))throw(0,sr.default)(new Error('Field "validity" did not match between protobuf and CBOR'),ui);if(e.ValidityType!==t.validityType)throw(0,sr.default)(new Error('Field "validityType" did not match between protobuf and CBOR'),ui);if(e.Sequence!==t.sequence)throw(0,sr.default)(new Error('Field "sequence" did not match between protobuf and CBOR'),ui);if(e.TTL!==t.ttl)throw(0,sr.default)(new Error('Field "ttl" did not match between protobuf and CBOR'),ui)};var cle=Yi("ipns"),ule=yn.code,nU="/ipns/",lle=nU.length;var xu=me(fo(),1);var yd=Yi("ipns:validator"),iU=1024*10,oU=async(t,e)=>{let r=eo(e),n;try{let i=nb(r.data);n=await t.verify(i,r.signatureV2)}catch{n=!1}if(!n)throw yd.error("record signature verification failed"),(0,xu.default)(new Error("record signature verification failed"),ui);if(r.validityType===Lr.ValidityType.EOL){if(r.validity.toDate().getTime()<Date.now())throw yd.error("record has expired"),(0,xu.default)(new Error("record has expired"),WI)}else if(r.validityType!=null)throw yd.error("unrecognized validity type"),(0,xu.default)(new Error("unrecognized validity type"),md);yd("ipns record for %b is valid",r.value)};async function nR(t,e){if(e.byteLength>iU)throw(0,xu.default)(new Error("record too large"),XI);let r=ob(t),n=eo(e),i=await rb(r,n);await oU(i,e)}async function*vu(t){let e=/\r?\n/,r=new TextDecoder("utf8"),n="";for await(let i of t){typeof i=="string"&&(i=new TextEncoder().encode(i)),n+=r.decode(i,{stream:!0});let o=n.split(e);n=o.pop()??"";for(let s=0;s<o.length;s++)yield JSON.parse(o[s])}n+=r.decode(),n!==""&&(yield JSON.parse(n))}var Eu=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},sb=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},iR=t=>globalThis.DOMException===void 0?new sb(t):new DOMException(t),oR=t=>{let e=t.reason===void 0?iR("This operation was aborted."):t.reason;return e instanceof Error?e:iR(e)};function ab(t,e,r,n){let i,o=new Promise((s,a)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(e===Number.POSITIVE_INFINITY){s(t);return}if(n={customTimers:{setTimeout,clearTimeout},...n},n.signal){let{signal:c}=n;c.aborted&&a(oR(c)),c.addEventListener("abort",()=>{a(oR(c))})}i=n.customTimers.setTimeout.call(void 0,()=>{if(typeof r=="function"){try{s(r())}catch(l){a(l)}return}let c=typeof r=="string"?r:`Promise timed out after ${e} milliseconds`,u=r instanceof Error?r:new Eu(c);typeof t.cancel=="function"&&t.cancel(),a(u)},e),(async()=>{try{s(await t)}catch(c){a(c)}finally{n.customTimers.clearTimeout.call(void 0,i)}})()});return o.clear=()=>{clearTimeout(i),i=void 0},o}function cb(t,e,r){let n=0,i=t.length;for(;i>0;){let o=Math.trunc(i/2),s=n+o;r(t[s],e)<=0?(n=++s,i-=o+1):i=o}return n}var Zo=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},li,ub=class{constructor(){li.set(this,[])}enqueue(e,r){r={priority:0,...r};let n={priority:r.priority,run:e};if(this.size&&Zo(this,li,"f")[this.size-1].priority>=r.priority){Zo(this,li,"f").push(n);return}let i=cb(Zo(this,li,"f"),n,(o,s)=>s.priority-o.priority);Zo(this,li,"f").splice(i,0,n)}dequeue(){let e=Zo(this,li,"f").shift();return e?.run}filter(e){return Zo(this,li,"f").filter(r=>r.priority===e.priority).map(r=>r.run)}get size(){return Zo(this,li,"f").length}};li=new WeakMap;var sR=ub;var Qe=function(t,e,r,n,i){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?t!==e||!i:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?i.call(t,r):i?i.value=r:e.set(t,r),r},X=function(t,e,r,n){if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?t!==e||!n:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return r==="m"?n:r==="a"?n.call(t):n?n.value:e.get(t)},at,Su,_u,ro,Ed,Iu,gd,Qr,Au,br,bd,wr,Ru,to,wd,aR,cR,fR,uR,lR,xd,lb,fb,Ad,hR,vd,Sd=class extends Error{},hb=class extends bc.default{constructor(e){var r,n,i,o;if(super(),at.add(this),Su.set(this,void 0),_u.set(this,void 0),ro.set(this,0),Ed.set(this,void 0),Iu.set(this,void 0),gd.set(this,0),Qr.set(this,void 0),Au.set(this,void 0),br.set(this,void 0),bd.set(this,void 0),wr.set(this,0),Ru.set(this,void 0),to.set(this,void 0),wd.set(this,void 0),Object.defineProperty(this,"timeout",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:sR,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${(n=(r=e.intervalCap)===null||r===void 0?void 0:r.toString())!==null&&n!==void 0?n:""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${(o=(i=e.interval)===null||i===void 0?void 0:i.toString())!==null&&o!==void 0?o:""}\` (${typeof e.interval})`);Qe(this,Su,e.carryoverConcurrencyCount,"f"),Qe(this,_u,e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,"f"),Qe(this,Ed,e.intervalCap,"f"),Qe(this,Iu,e.interval,"f"),Qe(this,br,new e.queueClass,"f"),Qe(this,bd,e.queueClass,"f"),this.concurrency=e.concurrency,this.timeout=e.timeout,Qe(this,wd,e.throwOnTimeout===!0,"f"),Qe(this,to,e.autoStart===!1,"f")}get concurrency(){return X(this,Ru,"f")}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);Qe(this,Ru,e,"f"),X(this,at,"m",Ad).call(this)}async add(e,r={}){return r={timeout:this.timeout,throwOnTimeout:X(this,wd,"f"),...r},new Promise((n,i)=>{X(this,br,"f").enqueue(async()=>{var o,s,a;Qe(this,wr,(s=X(this,wr,"f"),s++,s),"f"),Qe(this,ro,(a=X(this,ro,"f"),a++,a),"f");try{if(!((o=r.signal)===null||o===void 0)&&o.aborted)throw new Sd("The task was aborted.");let c=e({signal:r.signal});r.timeout&&(c=ab(Promise.resolve(c),r.timeout)),r.signal&&(c=Promise.race([c,X(this,at,"m",hR).call(this,r.signal)]));let u=await c;n(u),this.emit("completed",u)}catch(c){if(c instanceof Eu&&!r.throwOnTimeout){n();return}i(c),this.emit("error",c)}finally{X(this,at,"m",fR).call(this)}},r),this.emit("add"),X(this,at,"m",xd).call(this)})}async addAll(e,r){return Promise.all(e.map(async n=>this.add(n,r)))}start(){return X(this,to,"f")?(Qe(this,to,!1,"f"),X(this,at,"m",Ad).call(this),this):this}pause(){Qe(this,to,!0,"f")}clear(){Qe(this,br,new(X(this,bd,"f")),"f")}async onEmpty(){X(this,br,"f").size!==0&&await X(this,at,"m",vd).call(this,"empty")}async onSizeLessThan(e){X(this,br,"f").size<e||await X(this,at,"m",vd).call(this,"next",()=>X(this,br,"f").size<e)}async onIdle(){X(this,wr,"f")===0&&X(this,br,"f").size===0||await X(this,at,"m",vd).call(this,"idle")}get size(){return X(this,br,"f").size}sizeBy(e){return X(this,br,"f").filter(e).length}get pending(){return X(this,wr,"f")}get isPaused(){return X(this,to,"f")}};Su=new WeakMap,_u=new WeakMap,ro=new WeakMap,Ed=new WeakMap,Iu=new WeakMap,gd=new WeakMap,Qr=new WeakMap,Au=new WeakMap,br=new WeakMap,bd=new WeakMap,wr=new WeakMap,Ru=new WeakMap,to=new WeakMap,wd=new WeakMap,at=new WeakSet,aR=function(){return X(this,_u,"f")||X(this,ro,"f")<X(this,Ed,"f")},cR=function(){return X(this,wr,"f")<X(this,Ru,"f")},fR=function(){var e;Qe(this,wr,(e=X(this,wr,"f"),e--,e),"f"),X(this,at,"m",xd).call(this),this.emit("next")},uR=function(){X(this,at,"m",fb).call(this),X(this,at,"m",lb).call(this),Qe(this,Au,void 0,"f")},lR=function(){let e=Date.now();if(X(this,Qr,"f")===void 0){let r=X(this,gd,"f")-e;if(r<0)Qe(this,ro,X(this,Su,"f")?X(this,wr,"f"):0,"f");else return X(this,Au,"f")===void 0&&Qe(this,Au,setTimeout(()=>{X(this,at,"m",uR).call(this)},r),"f"),!0}return!1},xd=function(){if(X(this,br,"f").size===0)return X(this,Qr,"f")&&clearInterval(X(this,Qr,"f")),Qe(this,Qr,void 0,"f"),this.emit("empty"),X(this,wr,"f")===0&&this.emit("idle"),!1;if(!X(this,to,"f")){let e=!X(this,at,"a",lR);if(X(this,at,"a",aR)&&X(this,at,"a",cR)){let r=X(this,br,"f").dequeue();return r?(this.emit("active"),r(),e&&X(this,at,"m",lb).call(this),!0):!1}}return!1},lb=function(){X(this,_u,"f")||X(this,Qr,"f")!==void 0||(Qe(this,Qr,setInterval(()=>{X(this,at,"m",fb).call(this)},X(this,Iu,"f")),"f"),Qe(this,gd,Date.now()+X(this,Iu,"f"),"f"))},fb=function(){X(this,ro,"f")===0&&X(this,wr,"f")===0&&X(this,Qr,"f")&&(clearInterval(X(this,Qr,"f")),Qe(this,Qr,void 0,"f")),Qe(this,ro,X(this,Su,"f")?X(this,wr,"f"):0,"f"),X(this,at,"m",Ad).call(this)},Ad=function(){for(;X(this,at,"m",xd).call(this););},hR=async function(e){return new Promise((r,n)=>{e.addEventListener("abort",()=>{n(new Sd("The task was aborted."))},{once:!0})})},vd=async function(e,r){return new Promise(n=>{let i=()=>{r&&!r()||(this.off(e,i),n())};this.on(e,i)})};var dR=hb;function sU(t){return t[Symbol.asyncIterator]!=null}function aU(t){if(sU(t))return(async()=>{for await(let e of t)return e})();for(let e of t)return e}var pR=aU;var db=Qt("/ipns/");function mR(t){return Wt(t.subarray(0,db.byteLength),db)}var yR=t=>tu(t.slice(db.length)),_d=class{client;constructor(e){this.client=e}async*findProviders(e,r={}){yield*ju(this.client.getProviders(e,r),n=>({id:n.ID,multiaddrs:n.Addrs??[],protocols:[]}))}async provide(){}async put(e,r,n){if(!mR(e))return;let i=yR(e),o=eo(r);await this.client.putIPNS(i,o,n)}async get(e,r){if(!mR(e))throw new ce("Not found","ERR_NOT_FOUND");let n=yR(e);try{let i=await this.client.getIPNS(n,r);return wu(i)}catch(i){throw i.code==="ERR_BAD_RESPONSE"?new ce("Not found","ERR_NOT_FOUND"):i}}},Id=class{client;constructor(e){this.client=e}async findPeer(e,r={}){let n=await pR(this.client.getPeers(e,r));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs,protocols:[]};throw new ce("Not found","ERR_NOT_FOUND")}async*getClosestPeers(e,r={}){}};var _n=Yi("delegated-routing-v1-http-api-client"),gR={concurrentRequests:4,timeout:3e4},Rd=class{started;httpQueue;shutDownController;clientUrl;timeout;contentRouting;peerRouting;constructor(e,r={}){this.started=!1,this.shutDownController=new AbortController,aS(1/0,this.shutDownController.signal),this.httpQueue=new dR({concurrency:r.concurrentRequests??gR.concurrentRequests}),this.clientUrl=e instanceof URL?e:new URL(e),this.timeout=r.timeout??gR.timeout,this.contentRouting=new _d(this),this.peerRouting=new Id(this)}get[sS](){return this.contentRouting}get[cS](){return this.peerRouting}isStarted(){return this.started}start(){this.started=!0}stop(){this.httpQueue.clear(),this.shutDownController.abort(),this.started=!1}async*getProviders(e,r={}){_n("getProviders starts: %c",e);let n=Jr([this.shutDownController.signal,r.signal,AbortSignal.timeout(this.timeout)]),i=Ce(),o=Ce();this.httpQueue.add(async()=>(i.resolve(),o.promise));try{await i.promise;let s=`${this.clientUrl}routing/v1/providers/${e.toString()}`,c=await fetch(s,{headers:{Accept:"application/x-ndjson"},signal:n});if(c.body==null)throw new ce("Routing response had no body","ERR_BAD_RESPONSE");if(c.headers.get("Content-Type")==="application/json"){let l=await c.json();for(let f of l.Providers){let d=this.#e(f);d!=null&&(yield d)}}else for await(let l of vu(Kh(c.body))){let f=this.#e(l);f!=null&&(yield f)}}catch(s){_n.error("getProviders errored:",s)}finally{n.clear(),o.resolve(),_n("getProviders finished: %c",e)}}async*getPeers(e,r={}){_n("getPeers starts: %c",e);let n=Jr([this.shutDownController.signal,r.signal,AbortSignal.timeout(this.timeout)]),i=Ce(),o=Ce();this.httpQueue.add(async()=>(i.resolve(),o.promise));try{await i.promise;let s=`${this.clientUrl}routing/v1/peers/${e.toCID().toString()}`,c=await fetch(s,{headers:{Accept:"application/x-ndjson"},signal:n});if(c.body==null)throw new ce("Routing response had no body","ERR_BAD_RESPONSE");if(c.headers.get("Content-Type")==="application/json"){let l=await c.json();for(let f of l.Peers){let d=this.#t(e,f);d!=null&&(yield d)}}else for await(let l of vu(Kh(c.body))){let f=this.#t(e,l);f!=null&&(yield f)}}catch(s){_n.error("getPeers errored:",s)}finally{n.clear(),o.resolve(),_n("getPeers finished: %c",e)}}async getIPNS(e,r={}){_n("getIPNS starts: %c",e);let n=Jr([this.shutDownController.signal,r.signal,AbortSignal.timeout(this.timeout)]),i=Ce(),o=Ce();this.httpQueue.add(async()=>(i.resolve(),o.promise));try{await i.promise;let s=`${this.clientUrl}routing/v1/ipns/${e.toCID().toString()}`,c=await fetch(s,{headers:{Accept:"application/vnd.ipfs.ipns-record"},signal:n});if(c.body==null)throw new ce("GET ipns response had no body","ERR_BAD_RESPONSE");let u=new Uint8Array(await c.arrayBuffer());return await nR(ib(e),u),eo(u)}finally{n.clear(),o.resolve(),_n("getIPNS finished: %c",e)}}async putIPNS(e,r,n={}){_n("getIPNS starts: %c",e);let i=Jr([this.shutDownController.signal,n.signal,AbortSignal.timeout(this.timeout)]),o=Ce(),s=Ce();this.httpQueue.add(async()=>(o.resolve(),s.promise));try{await o.promise;let a=wu(r),c=`${this.clientUrl}routing/v1/ipns/${e.toCID().toString()}`;if((await fetch(c,{method:"PUT",headers:{"Content-Type":"application/vnd.ipfs.ipns-record"},body:a,signal:i})).status!==200)throw new ce("PUT ipns response had status other than 200","ERR_BAD_RESPONSE")}finally{i.clear(),s.resolve(),_n("getIPNS finished: %c",e)}}#e(e){if(e.Schema==="peer")return e.ID=Ca(e.ID),e.Addrs=e.Addrs.map(Ke),e.Protocols=e.Protocols??[],e;if(e.Schema==="bitswap")return{Schema:"peer",ID:Ca(e.ID),Addrs:e.Addrs.map(Ke),Protocols:e.Protocol!=null?[e.Protocol]:[]};if(e.ID!=null&&Array.isArray(e.Addrs))return{Schema:"peer",ID:Ca(e.ID),Addrs:e.Addrs.map(Ke),Protocols:Array.isArray(e.Protocols)?e.Protocols:[]}}#t(e,r){if(r.Schema==="peer"&&(r.ID=Ca(r.ID),r.Addrs=r.Addrs.map(Ke),e.equals(r.ID)))return r}};function bR(t,e={}){return new Rd(new URL(t),e)}function wR(t={}){return{services:{delegatedRouting:()=>bR("https://delegated-ipfs.dev")},connectionManager:{minConnections:0},...t}}async function xR(t){let e=wR();return t=t??{},oS({...e,...t.libp2p,start:!1})}async function cU(t={}){let e=t.datastore??new wo,r=t.blockstore??new Sc,n;uU(t.libp2p)?n=t.libp2p:n=await xR({...t,libp2p:t.libp2p,datastore:e});let i=new Rl({...t,libp2p:n,datastore:e,blockstore:r,blockBrokers:t.blockBrokers??[Zp()]});return t.start!==!1&&await i.start(),i}function uU(t){return t==null?!1:["dial","dialProtocol","hangUp","handle","unhandle","getMultiaddrs","getProtocols"].every(r=>typeof t[r]=="function")}return NR(lU);})();
|
|
48
|
+
/*! Bundled license information:
|
|
49
|
+
|
|
50
|
+
pvtsutils/build/index.js:
|
|
51
|
+
(*!
|
|
52
|
+
* MIT License
|
|
53
|
+
*
|
|
54
|
+
* Copyright (c) 2017-2022 Peculiar Ventures, LLC
|
|
55
|
+
*
|
|
56
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
57
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
58
|
+
* in the Software without restriction, including without limitation the rights
|
|
59
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
60
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
61
|
+
* furnished to do so, subject to the following conditions:
|
|
62
|
+
*
|
|
63
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
64
|
+
* copies or substantial portions of the Software.
|
|
65
|
+
*
|
|
66
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
67
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
68
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
69
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
70
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
71
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
72
|
+
* SOFTWARE.
|
|
73
|
+
*
|
|
74
|
+
*)
|
|
75
|
+
|
|
76
|
+
@noble/hashes/esm/utils.js:
|
|
77
|
+
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
78
|
+
|
|
79
|
+
@noble/curves/esm/abstract/utils.js:
|
|
80
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
81
|
+
|
|
82
|
+
@noble/curves/esm/abstract/modular.js:
|
|
83
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
84
|
+
|
|
85
|
+
@noble/curves/esm/abstract/curve.js:
|
|
86
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
87
|
+
|
|
88
|
+
@noble/curves/esm/abstract/edwards.js:
|
|
89
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
90
|
+
|
|
91
|
+
@noble/curves/esm/ed25519.js:
|
|
92
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
93
|
+
|
|
94
|
+
pvutils/build/utils.es.js:
|
|
95
|
+
(*!
|
|
96
|
+
Copyright (c) Peculiar Ventures, LLC
|
|
97
|
+
*)
|
|
98
|
+
|
|
99
|
+
asn1js/build/index.es.js:
|
|
100
|
+
(*!
|
|
101
|
+
* Copyright (c) 2014, GMO GlobalSign
|
|
102
|
+
* Copyright (c) 2015-2022, Peculiar Ventures
|
|
103
|
+
* All rights reserved.
|
|
104
|
+
*
|
|
105
|
+
* Author 2014-2019, Yury Strozhevsky
|
|
106
|
+
*
|
|
107
|
+
* Redistribution and use in source and binary forms, with or without modification,
|
|
108
|
+
* are permitted provided that the following conditions are met:
|
|
109
|
+
*
|
|
110
|
+
* * Redistributions of source code must retain the above copyright notice, this
|
|
111
|
+
* list of conditions and the following disclaimer.
|
|
112
|
+
*
|
|
113
|
+
* * Redistributions in binary form must reproduce the above copyright notice, this
|
|
114
|
+
* list of conditions and the following disclaimer in the documentation and/or
|
|
115
|
+
* other materials provided with the distribution.
|
|
116
|
+
*
|
|
117
|
+
* * Neither the name of the copyright holder nor the names of its
|
|
118
|
+
* contributors may be used to endorse or promote products derived from
|
|
119
|
+
* this software without specific prior written permission.
|
|
120
|
+
*
|
|
121
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
122
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
123
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
124
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
125
|
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
126
|
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
127
|
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
128
|
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
129
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
130
|
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
131
|
+
*
|
|
132
|
+
*)
|
|
133
|
+
|
|
134
|
+
@noble/curves/esm/abstract/weierstrass.js:
|
|
135
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
136
|
+
|
|
137
|
+
@noble/curves/esm/_shortw_utils.js:
|
|
138
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
139
|
+
|
|
140
|
+
@noble/curves/esm/secp256k1.js:
|
|
141
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
142
|
+
*/
|
|
143
|
+
return HeliaHttp}));
|