@helia/routers 2.1.0-dff82ec → 2.1.0-e58e49c

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/dist/index.min.js CHANGED
@@ -4,7 +4,7 @@
4
4
  `).map(o=>` ${o}`).join(`
5
5
  `));let t=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return e.length?`${t} :
6
6
  ${e.join(`
7
- `)}`:`${t} :`}};nu=qt;_.Constructed=nu;qt.NAME="CONSTRUCTED";var fo=class extends Ae{fromBER(e,t,n){return t}toBER(e){return tt}};fo.override="EndOfContentValueBlock";var ou,ho=class extends we{constructor(e={}){super(e,fo),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};ou=ho;_.EndOfContent=ou;ho.NAME=un;var iu,Ur=class extends we{constructor(e={}){super(e,Ae),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,t,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,t+n>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):t+n}toBER(e,t){let n=new ArrayBuffer(2);if(!e){let o=new Uint8Array(n);o[0]=5,o[1]=0}return t&&t.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};iu=Ur;_.Null=iu;Ur.NAME="NULL";var po=class extends It(Ae){constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=j.BufferSourceConverter.toUint8Array(t.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,t,n){let o=j.BufferSourceConverter.toUint8Array(e);return St(this,o,t,n)?(this.valueHexView=o.subarray(t,t+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,$s.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};po.NAME="BooleanValueBlock";var su,mo=class extends we{constructor(e={}){super(e,po),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}`}};su=mo;_.Boolean=su;mo.NAME="BOOLEAN";var go=class extends It(ut){constructor({isConstructed:e=!1,...t}={}){super(t),this.isConstructed=e}fromBER(e,t,n){let o=0;if(this.isConstructed){if(this.isHexOnly=!1,o=ut.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let i=0;i<this.value.length;i++){let s=this.value[i].constructor.NAME;if(s===un){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(s!==Qc)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,o=super.fromBER(e,t,n),this.blockLength=n;return o}toBER(e,t){return this.isConstructed?ut.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};go.NAME="OctetStringValueBlock";var au,yo=class r extends we{constructor({idBlock:e={},lenBlock:t={},...n}={}){var o,i;(o=n.isConstructed)!==null&&o!==void 0||(n.isConstructed=!!(!((i=n.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},go),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,t,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),t;if(!this.valueBlock.isConstructed){let i=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+n);try{if(i.byteLength){let s=zo(i,0,i.byteLength);s.offset!==-1&&s.offset===n&&(this.valueBlock.value=[s.result])}}catch{}}return super.fromBER(e,t,n)}onAsciiEncoding(){return this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length?qt.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${j.Convert.ToHex(this.valueBlock.valueHexView)}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let e=[];for(let t of this.valueBlock.value)t instanceof r&&e.push(t.valueBlock.valueHexView);return j.BufferSourceConverter.concat(e)}};au=yo;_.OctetString=au;yo.NAME=Qc;var wo=class extends It(ut){constructor({unusedBits:e=0,isConstructed:t=!1,...n}={}){super(n),this.unusedBits=e,this.isConstructed=t,this.blockLength=this.valueHexView.byteLength}fromBER(e,t,n){if(!n)return t;let o=-1;if(this.isConstructed){if(o=ut.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let a of this.value){let c=a.constructor.NAME;if(c===un){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==eu)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let f=a.valueBlock;if(this.unusedBits>0&&f.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=f.unusedBits}return o}let i=j.BufferSourceConverter.toUint8Array(e);if(!St(this,i,t,n))return-1;let s=i.subarray(t,t+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=zo(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,t+n}toBER(e,t){if(this.isConstructed)return ut.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return tt;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}}};wo.NAME="BitStringValueBlock";var cu,Rr=class extends we{constructor({idBlock:e={},lenBlock:t={},...n}={}){var o,i;(o=n.isConstructed)!==null&&o!==void 0||(n.isConstructed=!!(!((i=n.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},wo),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(e,t,n){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(e,t,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return qt.prototype.onAsciiEncoding.call(this);{let e=[],t=this.valueBlock.valueHexView;for(let o of t)e.push(o.toString(2).padStart(8,"0"));let n=e.join("");return`${this.constructor.NAME} : ${n.substring(0,n.length-this.valueBlock.unusedBits)}`}}};cu=Rr;_.BitString=cu;Rr.NAME=eu;var uu;function ap(r,e){let t=new Uint8Array([0]),n=new Uint8Array(r),o=new Uint8Array(e),i=n.slice(0),s=i.length-1,a=o.slice(0),c=a.length-1,f=0,u=c<s?s:c,l=0;for(let d=u;d>=0;d--,l++){switch(!0){case l<a.length:f=i[s-l]+a[c-l]+t[0];break;default:f=i[s-l]+t[0]}switch(t[0]=f/10,!0){case l>=i.length:i=oo(new Uint8Array([f%10]),i);break;default:i[s-l]=f%10}}return t[0]>0&&(i=oo(t,i)),i}function Xc(r){if(r>=an.length)for(let e=an.length;e<=r;e++){let t=new Uint8Array([0]),n=an[e-1].slice(0);for(let o=n.length-1;o>=0;o--){let i=new Uint8Array([(n[o]<<1)+t[0]]);t[0]=i[0]/10,n[o]=i[0]%10}t[0]>0&&(n=oo(t,n)),an.push(n)}return an[r]}function cp(r,e){let t=0,n=new Uint8Array(r),o=new Uint8Array(e),i=n.slice(0),s=i.length-1,a=o.slice(0),c=a.length-1,f,u=0;for(let l=c;l>=0;l--,u++)switch(f=i[s-u]-a[c-u]-t,!0){case f<0:t=1,i[s-u]=f+10;break;default:t=0,i[s-u]=f}if(t>0)for(let l=s-c+1;l>=0;l--,u++)if(f=i[s-u]-t,f<0)t=1,i[s-u]=f+10;else{t=0,i[s-u]=f;break}return i.slice()}var ln=class extends It(Ae){constructor({value:e,...t}={}){super(t),this._valueDec=0,t.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=$s.call(this)))}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(Wc(e))}get valueDec(){return this._valueDec}fromDER(e,t,n,o=0){let i=this.fromBER(e,t,n);if(i===-1)return i;let s=this.valueHexView;return s[0]===0&&s[1]&128?this.valueHexView=s.subarray(1):o!==0&&s.length<o&&(o-s.length>1&&(o=s.length+1),this.valueHexView=s.subarray(o-s.length)),i}toDER(e=!1){let t=this.valueHexView;switch(!0){case(t[0]&128)!==0:{let n=new Uint8Array(this.valueHexView.length+1);n[0]=0,n.set(t,1),this.valueHexView=n}break;case(t[0]===0&&(t[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(e)}fromBER(e,t,n){let o=super.fromBER(e,t,n);return o===-1||this.setValueHex(),o}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,t=new Uint8Array(this.valueHexView.length*8/3),n=0,o,i=this.valueHexView,s="",a=!1;for(let c=i.byteLength-1;c>=0;c--){o=i[c];for(let f=0;f<8;f++){if((o&1)===1)switch(n){case e:t=cp(Xc(n),t),s="-";break;default:t=ap(t,Xc(n))}n++,o>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(s+=Jc.charAt(t[c]));return a===!1&&(s+=Jc.charAt(0)),s}};uu=ln;ln.NAME="IntegerValueBlock";Object.defineProperty(uu.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var lu,xe=class r extends we{constructor(e={}){super(e,ln),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return io(),BigInt(this.valueBlock.toString())}static fromBigInt(e){io();let t=BigInt(e),n=new cn,o=t.toString(16).replace(/^-/,""),i=new Uint8Array(j.Convert.FromHex(o));if(t<0){let a=new Uint8Array(i.length+(i[0]&128?1:0));a[0]|=128;let f=BigInt(`0x${j.Convert.ToHex(a)}`)+t,u=j.BufferSourceConverter.toUint8Array(j.Convert.FromHex(f.toString(16)));u[0]|=128,n.write(u)}else i[0]&128&&n.write(new Uint8Array([0])),n.write(i);return new r({valueHex:n.final()})}convertToDER(){let e=new r({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new r({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}};lu=xe;_.Integer=lu;xe.NAME="INTEGER";var fu,xo=class extends xe{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};fu=xo;_.Enumerated=fu;xo.NAME="ENUMERATED";var fn=class extends It(Ae){constructor({valueDec:e=-1,isFirstSid:t=!1,...n}={}){super(n),this.valueDec=e,this.isFirstSid=t}fromBER(e,t,n){if(!n)return t;let o=j.BufferSourceConverter.toUint8Array(e);if(!St(this,o,t,n))return-1;let i=o.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=i[a]&127,this.blockLength++,!!(i[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,i[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=or(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){io();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;let n=new Uint8Array(t.length/7);for(let o=0;o<n.length;o++)n[o]=parseInt(t.slice(o*7,o*7+7),2)+(o+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 o=this.valueHexView,i=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)i[s]=o[s]|128;return i[this.blockLength-1]=o[this.blockLength-1],i.buffer}let t=Kt(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",tt;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n}toString(){let e="";if(this.isHexOnly)e=j.Convert.ToHex(this.valueHexView);else if(this.isFirstSid){let t=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",t-=40):(e="2.",t-=80),e+=t.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}};fn.NAME="sidBlock";var bo=class extends Ae{constructor({value:e=Lr,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new fn;if(o=i.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=i.error,o;this.value.length===0&&(i.isFirstSid=!0),this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return o}toBER(e){let t=[];for(let n=0;n<this.value.length;n++){let o=this.value[n].toBER(e);if(o.byteLength===0)return this.error=this.value[n].error,tt;t.push(o)}return Hs(t)}fromString(e){this.value=[];let t=0,n=0,o="",i=!1;do if(n=e.indexOf(".",t),n===-1?o=e.substring(t):o=e.substring(t,n),t=n+1,i){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(o,10);if(isNaN(c))return;s.valueDec=c+a,i=!1}else{let s=new fn;if(o>Number.MAX_SAFE_INTEGER){io();let a=BigInt(o);s.valueBigInt=a}else if(s.valueDec=parseInt(o,10),isNaN(s.valueDec))return;this.value.length||(s.isFirstSid=!0,i=!0),this.value.push(s)}while(n!==-1)}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let o=this.value[n].toString();n!==0&&(e=`${e}.`),t?(o=`{${o}}`,this.value[n].isFirstSid?e=`2.{${o} - 80}`:e+=o):e+=o}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};bo.NAME="ObjectIdentifierValueBlock";var du,_r=class extends we{constructor(e={}){super(e,bo),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()}}};du=_r;_.ObjectIdentifier=du;_r.NAME="OBJECT IDENTIFIER";var dn=class extends It(Et){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let o=j.BufferSourceConverter.toUint8Array(e);if(!St(this,o,t,n))return-1;let i=o.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=i[a]&127,this.blockLength++,!!(i[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,i[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=or(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let o=this.valueHexView,i=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)i[s]=o[s]|128;return i[this.blockLength-1]=o[this.blockLength-1],i.buffer}let t=Kt(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",tt;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n.buffer}toString(){let e="";return this.isHexOnly?e=j.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};dn.NAME="relativeSidBlock";var vo=class extends Ae{constructor({value:e=Lr,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new dn;if(o=i.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=i.error,o;this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return o}toBER(e,t){let n=[];for(let o=0;o<this.value.length;o++){let i=this.value[o].toBER(e);if(i.byteLength===0)return this.error=this.value[o].error,tt;n.push(i)}return Hs(n)}fromString(e){this.value=[];let t=0,n=0,o="";do{n=e.indexOf(".",t),n===-1?o=e.substring(t):o=e.substring(t,n),t=n+1;let i=new dn;if(i.valueDec=parseInt(o,10),isNaN(i.valueDec))return!0;this.value.push(i)}while(n!==-1);return!0}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let o=this.value[n].toString();n!==0&&(e=`${e}.`),t&&(o=`{${o}}`),e+=o}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};vo.NAME="RelativeObjectIdentifierValueBlock";var hu,Eo=class extends we{constructor(e={}){super(e,vo),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()}}};hu=Eo;_.RelativeObjectIdentifier=hu;Eo.NAME="RelativeObjectIdentifier";var pu,Bt=class extends qt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};pu=Bt;_.Sequence=pu;Bt.NAME="SEQUENCE";var mu,Bo=class extends qt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};mu=Bo;_.Set=mu;Bo.NAME="SET";var Ao=class extends It(Ae){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=Lr}toJSON(){return{...super.toJSON(),value:this.value}}};Ao.NAME="StringValueBlock";var So=class extends Ao{};So.NAME="SimpleStringValueBlock";var Ce=class extends co{constructor({...e}={}){super(e,So)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,j.BufferSourceConverter.toUint8Array(e))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);this.valueBlock.value=e}};Ce.NAME="SIMPLE STRING";var Io=class extends Ce{fromBuffer(e){this.valueBlock.valueHexView=j.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=j.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=j.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(j.Convert.FromUtf8String(e)),this.valueBlock.value=e}};Io.NAME="Utf8StringValueBlock";var gu,At=class extends Io{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};gu=At;_.Utf8String=gu;At.NAME="UTF8String";var ko=class extends Ce{fromBuffer(e){this.valueBlock.value=j.Convert.ToUtf16String(e),this.valueBlock.valueHexView=j.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(j.Convert.FromUtf16String(e))}};ko.NAME="BmpStringValueBlock";var yu,Co=class extends ko{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};yu=Co;_.BmpString=yu;Co.NAME="BMPString";var To=class extends Ce{fromBuffer(e){let t=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),n=new Uint8Array(t);for(let o=0;o<n.length;o+=4)n[o]=n[o+3],n[o+1]=n[o+2],n[o+2]=0,n[o+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(t))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t*4);for(let o=0;o<t;o++){let i=Kt(e.charCodeAt(o),8),s=new Uint8Array(i);if(s.length>4)continue;let a=4-s.length;for(let c=s.length-1;c>=0;c--)n[o*4+c+a]=s[c]}this.valueBlock.value=e}};To.NAME="UniversalStringValueBlock";var wu,No=class extends To{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};wu=No;_.UniversalString=wu;No.NAME="UniversalString";var xu,Uo=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};xu=Uo;_.NumericString=xu;Uo.NAME="NumericString";var bu,Ro=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};bu=Ro;_.PrintableString=bu;Ro.NAME="PrintableString";var vu,_o=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};vu=_o;_.TeletexString=vu;_o.NAME="TeletexString";var Eu,Lo=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};Eu=Lo;_.VideotexString=Eu;Lo.NAME="VideotexString";var Bu,Vo=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};Bu=Vo;_.IA5String=Bu;Vo.NAME="IA5String";var Au,Po=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};Au=Po;_.GraphicString=Au;Po.NAME="GraphicString";var Su,hn=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};Su=hn;_.VisibleString=Su;hn.NAME="VisibleString";var Iu,Fo=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};Iu=Fo;_.GeneralString=Iu;Fo.NAME="GeneralString";var ku,Oo=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};ku=Oo;_.CharacterString=ku;Oo.NAME="CharacterString";var Cu,pn=class extends hn{constructor({value:e,valueDate:t,...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 o=0;o<e.length;o++)this.valueBlock.valueHexView[o]=e.charCodeAt(o)}t&&(this.fromDate(t),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,j.BufferSourceConverter.toUint8Array(e)))}toBuffer(){let e=this.toString(),t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let o=0;o<e.length;o++)n[o]=e.charCodeAt(o);return t}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 o=parseInt(n[1],10);o>=50?this.year=1900+o:this.year=2e3+o,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 t=new Array(7);return t[0]=Fe(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=Fe(this.month,2),t[2]=Fe(this.day,2),t[3]=Fe(this.hour,2),t[4]=Fe(this.minute,2),t[5]=Fe(this.second,2),t[6]="Z",t.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}}};Cu=pn;_.UTCTime=Cu;pn.NAME="UTCTime";var Tu,Do=class extends pn{constructor(e={}){var t;super(e),(t=this.millisecond)!==null&&t!==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 t=!1,n="",o="",i=0,s,a=0,c=0;if(e[e.length-1]==="Z")n=e.substring(0,e.length-1),t=!0;else{let l=new Number(e[e.length-1]);if(isNaN(l.valueOf()))throw new Error("Wrong input string for conversion");n=e}if(t){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 l=1,d=n.indexOf("+"),b="";if(d===-1&&(d=n.indexOf("-"),l=-1),d!==-1){if(b=n.substring(d+1),n=n.substring(0,d),b.length!==2&&b.length!==4)throw new Error("Wrong input string for conversion");let I=parseInt(b.substring(0,2),10);if(isNaN(I.valueOf()))throw new Error("Wrong input string for conversion");if(a=l*I,b.length===4){if(I=parseInt(b.substring(2,4),10),isNaN(I.valueOf()))throw new Error("Wrong input string for conversion");c=l*I}}}let f=n.indexOf(".");if(f===-1&&(f=n.indexOf(",")),f!==-1){let l=new Number(`0${n.substring(f)}`);if(isNaN(l.valueOf()))throw new Error("Wrong input string for conversion");i=l.valueOf(),o=n.substring(0,f)}else o=n;switch(!0){case o.length===8:if(s=/(\d{4})(\d{2})(\d{2})/ig,f!==-1)throw new Error("Wrong input string for conversion");break;case o.length===10:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let l=60*i;this.minute=Math.floor(l),l=60*(l-this.minute),this.second=Math.floor(l),l=1e3*(l-this.second),this.millisecond=Math.floor(l)}break;case o.length===12:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let l=60*i;this.second=Math.floor(l),l=1e3*(l-this.second),this.millisecond=Math.floor(l)}break;case o.length===14:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let l=1e3*i;this.millisecond=Math.floor(l)}break;default:throw new Error("Wrong input string for conversion")}let u=s.exec(o);if(u===null)throw new Error("Wrong input string for conversion");for(let l=1;l<u.length;l++)switch(l){case 1:this.year=parseInt(u[l],10);break;case 2:this.month=parseInt(u[l],10);break;case 3:this.day=parseInt(u[l],10);break;case 4:this.hour=parseInt(u[l],10)+a;break;case 5:this.minute=parseInt(u[l],10)+c;break;case 6:this.second=parseInt(u[l],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){let l=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=l.getUTCFullYear(),this.month=l.getUTCMonth(),this.day=l.getUTCDay(),this.hour=l.getUTCHours(),this.minute=l.getUTCMinutes(),this.second=l.getUTCSeconds(),this.millisecond=l.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){let t=[];return t.push(Fe(this.year,4)),t.push(Fe(this.month,2)),t.push(Fe(this.day,2)),t.push(Fe(this.hour,2)),t.push(Fe(this.minute,2)),t.push(Fe(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(Fe(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};Tu=Do;_.GeneralizedTime=Tu;Do.NAME="GeneralizedTime";var Nu,Mo=class extends At{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};Nu=Mo;_.DATE=Nu;Mo.NAME="DATE";var Uu,$o=class extends At{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};Uu=$o;_.TimeOfDay=Uu;$o.NAME="TimeOfDay";var Ru,Ho=class extends At{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};Ru=Ho;_.DateTime=Ru;Ho.NAME="DateTime";var _u,Ko=class extends At{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};_u=Ko;_.Duration=_u;Ko.NAME="Duration";var Lu,qo=class extends At{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};Lu=qo;_.TIME=Lu;qo.NAME="TIME";function ne(r,e="utf8"){let t=Qn[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var mn=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},jo=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var Vu={get(r=globalThis){let e=r.crypto;if(e?.subtle==null)throw new jo("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");return e}};var zt=Vu;async function Pu(r){let e=await zt.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),t=await lp(e);return{privateKey:t[0],publicKey:t[1]}}async function Fu(r,e){let t=await zt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await zt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},t,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(n,0,n.byteLength)}async function Ou(r,e,t){let n=await zt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return zt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,e,t instanceof Uint8Array?t:t.subarray())}async function lp(r){if(r.privateKey==null||r.publicKey==null)throw new ve("Private and public key are required");return Promise.all([zt.get().subtle.exportKey("jwk",r.privateKey),zt.get().subtle.exportKey("jwk",r.publicKey)])}function zs(r){if(r.kty!=="RSA")throw new ve("invalid key type");if(r.n==null)throw new ve("invalid key modulus");return Z(r.n,"base64url").length*8}var Vr=class{type="RSA";_key;_raw;_multihash;constructor(e,t){this._key=e,this._multihash=t}get raw(){return this._raw==null&&(this._raw=gn.jwkToPkix(this._key)),this._raw}toMultihash(){return this._multihash}toCID(){return X.createV1(114,this._multihash)}toString(){return re.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ce(this.raw,e.raw)}verify(e,t){return Ou(this._key,t,e)}},yn=class{type="RSA";_key;_raw;publicKey;constructor(e,t){this._key=e,this.publicKey=t}get raw(){return this._raw==null&&(this._raw=gn.jwkToPkcs1(this._key)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ce(this.raw,e.raw)}sign(e){return Fu(this._key,e)}};var Go=8192,js=18;function Du(r){let{result:e}=qs(r),t=e.valueBlock.value;return{n:lt(t[1]),e:lt(t[2]),d:lt(t[3]),p:lt(t[4]),q:lt(t[5]),dp:lt(t[6]),dq:lt(t[7]),qi:lt(t[8]),kty:"RSA",alg:"RS256"}}function fp(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new ve("JWK was missing components");let t=new Bt({value:[new xe({value:0}),xe.fromBigInt(ft(Z(r.n,"base64url"))),xe.fromBigInt(ft(Z(r.e,"base64url"))),xe.fromBigInt(ft(Z(r.d,"base64url"))),xe.fromBigInt(ft(Z(r.p,"base64url"))),xe.fromBigInt(ft(Z(r.q,"base64url"))),xe.fromBigInt(ft(Z(r.dp,"base64url"))),xe.fromBigInt(ft(Z(r.dq,"base64url"))),xe.fromBigInt(ft(Z(r.qi,"base64url")))]}).toBER();return new Uint8Array(t,0,t.byteLength)}function Mu(r){let{result:e}=qs(r),t=e.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:lt(t[0]),e:lt(t[1])}}function Gs(r){if(r.n==null||r.e==null)throw new ve("JWK was missing components");let t=new Bt({value:[new Bt({value:[new _r({value:"1.2.840.113549.1.1.1"}),new Ur]}),new Rr({valueHex:new Bt({value:[xe.fromBigInt(ft(Z(r.n,"base64url"))),xe.fromBigInt(ft(Z(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(t,0,t.byteLength)}function lt(r){let e=r.valueBlock.valueHexView;for(;e[0]===0;)e=e.subarray(1);return ne(e,"base64url")}function ft(r){let e=[];return r.forEach(function(t){let n=t.toString(16);n.length%2>0&&(n=`0${n}`),e.push(n)}),BigInt("0x"+e.join(""))}function $u(r){let e=Du(r);return Hu(e)}function Zs(r){let e=Mu(r);if(zs(e)>Go)throw new lr("Key size is too large");let t=Tr(ct.encode({Type:de.RSA,Data:r})),n=Ze(js,t);return new Vr(e,n)}function Hu(r){if(zs(r)>Go)throw new ve("Key size is too large");let e=qu(r),t=Tr(ct.encode({Type:de.RSA,Data:Gs(e.publicKey)})),n=Ze(js,t);return new yn(e.privateKey,new Vr(e.publicKey,n))}async function Ku(r){if(r>Go)throw new ve("Key size is too large");let e=await Pu(r),t=Tr(ct.encode({Type:de.RSA,Data:Gs(e.publicKey)})),n=Ze(js,t);return new yn(e.privateKey,new Vr(e.publicKey,n))}function qu(r){if(r==null)throw new ve("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}var Zo=class extends vr{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,dc(e);let n=Jr(t);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 o=this.blockLen,i=new Uint8Array(o);i.set(n.length>o?e.create().update(n).digest():n);for(let s=0;s<i.length;s++)i[s]^=54;this.iHash.update(i),this.oHash=e.create();for(let s=0;s<i.length;s++)i[s]^=106;this.oHash.update(i),i.fill(0)}update(e){return br(this),this.iHash.update(e),this}digestInto(e){br(this),xr(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:t,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=i,e.blockLen=s,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ws=(r,e,t)=>new Zo(r,e).update(t).digest();Ws.create=(r,e)=>new Zo(r,e);function zu(r){r.lowS!==void 0&&Je("lowS",r.lowS),r.prehash!==void 0&&Je("prehash",r.prehash)}function dp(r){let e=en(r);at(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:t,Fp:n,a:o}=e;if(t){if(!n.eql(o,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof t!="object"||typeof t.beta!="bigint"||typeof t.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}var{bytesToNumberBE:hp,hexToBytes:pp}=qn,kt={Err:class extends Error{constructor(e=""){super(e)}},_tlv:{encode:(r,e)=>{let{Err:t}=kt;if(r<0||r>256)throw new t("tlv.encode: wrong tag");if(e.length&1)throw new t("tlv.encode: unpadded data");let n=e.length/2,o=Yt(n);if(o.length/2&128)throw new t("tlv.encode: long form length too big");let i=n>127?Yt(o.length/2|128):"";return`${Yt(r)}${i}${o}${e}`},decode(r,e){let{Err:t}=kt,n=0;if(r<0||r>256)throw new t("tlv.encode: wrong tag");if(e.length<2||e[n++]!==r)throw new t("tlv.decode: wrong tlv");let o=e[n++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new t("tlv.decode(long): indefinite length not supported");if(c>4)throw new t("tlv.decode(long): byte length is too big");let f=e.subarray(n,n+c);if(f.length!==c)throw new t("tlv.decode: length bytes not complete");if(f[0]===0)throw new t("tlv.decode(long): zero leftmost byte");for(let u of f)s=s<<8|u;if(n+=c,s<128)throw new t("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+s);if(a.length!==s)throw new t("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+s)}}},_int:{encode(r){let{Err:e}=kt;if(r<Ct)throw new e("integer: negative integers are not allowed");let t=Yt(r);if(Number.parseInt(t[0],16)&8&&(t="00"+t),t.length&1)throw new e("unexpected assertion");return t},decode(r){let{Err:e}=kt;if(r[0]&128)throw new e("Invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new e("Invalid signature integer: unnecessary leading zero");return hp(r)}},toSig(r){let{Err:e,_int:t,_tlv:n}=kt,o=typeof r=="string"?pp(r):r;Br(o);let{v:i,l:s}=n.decode(48,o);if(s.length)throw new e("Invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:f,l:u}=n.decode(2,c);if(u.length)throw new e("Invalid signature: left bytes after parsing");return{r:t.decode(a),s:t.decode(f)}},hexFromSig(r){let{_tlv:e,_int:t}=kt,n=`${e.encode(2,t.encode(r.r))}${e.encode(2,t.encode(r.s))}`;return e.encode(48,n)}},Ct=BigInt(0),me=BigInt(1),bx=BigInt(2),ju=BigInt(3),vx=BigInt(4);function mp(r){let e=dp(r),{Fp:t}=e,n=Dt(e.n,e.nBitLength),o=e.toBytes||((w,h,E)=>{let C=h.toAffine();return bt(Uint8Array.from([4]),t.toBytes(C.x),t.toBytes(C.y))}),i=e.fromBytes||(w=>{let h=w.subarray(1),E=t.fromBytes(h.subarray(0,t.BYTES)),C=t.fromBytes(h.subarray(t.BYTES,2*t.BYTES));return{x:E,y:C}});function s(w){let{a:h,b:E}=e,C=t.sqr(w),x=t.mul(C,w);return t.add(t.add(x,t.mul(w,h)),E)}if(!t.eql(t.sqr(e.Gy),s(e.Gx)))throw new Error("bad generator point: equation left != right");function a(w){return Xr(w,me,e.n)}function c(w){let{allowedPrivateKeyLengths:h,nByteLength:E,wrapPrivateKey:C,n:x}=e;if(h&&typeof w!="bigint"){if(Pt(w)&&(w=wt(w)),typeof w!="string"||!h.includes(w.length))throw new Error("Invalid key");w=w.padStart(E*2,"0")}let T;try{T=typeof w=="bigint"?w:xt(ae("private key",w,E))}catch{throw new Error(`private key must be ${E} bytes, hex or bigint, not ${typeof w}`)}return C&&(T=Q(T,x)),Le("private key",T,me,x),T}function f(w){if(!(w instanceof d))throw new Error("ProjectivePoint expected")}let u=Qt((w,h)=>{let{px:E,py:C,pz:x}=w;if(t.eql(x,t.ONE))return{x:E,y:C};let T=w.is0();h==null&&(h=T?t.ONE:t.inv(x));let F=t.mul(E,h),V=t.mul(C,h),U=t.mul(x,h);if(T)return{x:t.ZERO,y:t.ZERO};if(!t.eql(U,t.ONE))throw new Error("invZ was invalid");return{x:F,y:V}}),l=Qt(w=>{if(w.is0()){if(e.allowInfinityPoint&&!t.is0(w.py))return;throw new Error("bad point: ZERO")}let{x:h,y:E}=w.toAffine();if(!t.isValid(h)||!t.isValid(E))throw new Error("bad point: x or y not FE");let C=t.sqr(E),x=s(h);if(!t.eql(C,x))throw new Error("bad point: equation left != right");if(!w.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class d{constructor(h,E,C){if(this.px=h,this.py=E,this.pz=C,h==null||!t.isValid(h))throw new Error("x required");if(E==null||!t.isValid(E))throw new Error("y required");if(C==null||!t.isValid(C))throw new Error("z required");Object.freeze(this)}static fromAffine(h){let{x:E,y:C}=h||{};if(!h||!t.isValid(E)||!t.isValid(C))throw new Error("invalid affine point");if(h instanceof d)throw new Error("projective point not allowed");let x=T=>t.eql(T,t.ZERO);return x(E)&&x(C)?d.ZERO:new d(E,C,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let E=t.invertBatch(h.map(C=>C.pz));return h.map((C,x)=>C.toAffine(E[x])).map(d.fromAffine)}static fromHex(h){let E=d.fromAffine(i(ae("pointHex",h)));return E.assertValidity(),E}static fromPrivateKey(h){return d.BASE.multiply(c(h))}static msm(h,E){return Gn(d,n,h,E)}_setWindowSize(h){I.setWindowSize(this,h)}assertValidity(){l(this)}hasEvenY(){let{y:h}=this.toAffine();if(t.isOdd)return!t.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){f(h);let{px:E,py:C,pz:x}=this,{px:T,py:F,pz:V}=h,U=t.eql(t.mul(E,V),t.mul(T,x)),g=t.eql(t.mul(C,V),t.mul(F,x));return U&&g}negate(){return new d(this.px,t.neg(this.py),this.pz)}double(){let{a:h,b:E}=e,C=t.mul(E,ju),{px:x,py:T,pz:F}=this,V=t.ZERO,U=t.ZERO,g=t.ZERO,v=t.mul(x,x),O=t.mul(T,T),R=t.mul(F,F),N=t.mul(x,T);return N=t.add(N,N),g=t.mul(x,F),g=t.add(g,g),V=t.mul(h,g),U=t.mul(C,R),U=t.add(V,U),V=t.sub(O,U),U=t.add(O,U),U=t.mul(V,U),V=t.mul(N,V),g=t.mul(C,g),R=t.mul(h,R),N=t.sub(v,R),N=t.mul(h,N),N=t.add(N,g),g=t.add(v,v),v=t.add(g,v),v=t.add(v,R),v=t.mul(v,N),U=t.add(U,v),R=t.mul(T,F),R=t.add(R,R),v=t.mul(R,N),V=t.sub(V,v),g=t.mul(R,O),g=t.add(g,g),g=t.add(g,g),new d(V,U,g)}add(h){f(h);let{px:E,py:C,pz:x}=this,{px:T,py:F,pz:V}=h,U=t.ZERO,g=t.ZERO,v=t.ZERO,O=e.a,R=t.mul(e.b,ju),N=t.mul(E,T),H=t.mul(C,F),A=t.mul(x,V),S=t.add(E,C),m=t.add(T,F);S=t.mul(S,m),m=t.add(N,H),S=t.sub(S,m),m=t.add(E,x);let p=t.add(T,V);return m=t.mul(m,p),p=t.add(N,A),m=t.sub(m,p),p=t.add(C,x),U=t.add(F,V),p=t.mul(p,U),U=t.add(H,A),p=t.sub(p,U),v=t.mul(O,m),U=t.mul(R,A),v=t.add(U,v),U=t.sub(H,v),v=t.add(H,v),g=t.mul(U,v),H=t.add(N,N),H=t.add(H,N),A=t.mul(O,A),m=t.mul(R,m),H=t.add(H,A),A=t.sub(N,A),A=t.mul(O,A),m=t.add(m,A),N=t.mul(H,m),g=t.add(g,N),N=t.mul(p,m),U=t.mul(S,U),U=t.sub(U,N),N=t.mul(S,H),v=t.mul(p,v),v=t.add(v,N),new d(U,g,v)}subtract(h){return this.add(h.negate())}is0(){return this.equals(d.ZERO)}wNAF(h){return I.wNAFCached(this,h,d.normalizeZ)}multiplyUnsafe(h){Le("scalar",h,Ct,e.n);let E=d.ZERO;if(h===Ct)return E;if(h===me)return this;let{endo:C}=e;if(!C)return I.unsafeLadder(this,h);let{k1neg:x,k1:T,k2neg:F,k2:V}=C.splitScalar(h),U=E,g=E,v=this;for(;T>Ct||V>Ct;)T&me&&(U=U.add(v)),V&me&&(g=g.add(v)),v=v.double(),T>>=me,V>>=me;return x&&(U=U.negate()),F&&(g=g.negate()),g=new d(t.mul(g.px,C.beta),g.py,g.pz),U.add(g)}multiply(h){let{endo:E,n:C}=e;Le("scalar",h,me,C);let x,T;if(E){let{k1neg:F,k1:V,k2neg:U,k2:g}=E.splitScalar(h),{p:v,f:O}=this.wNAF(V),{p:R,f:N}=this.wNAF(g);v=I.constTimeNegate(F,v),R=I.constTimeNegate(U,R),R=new d(t.mul(R.px,E.beta),R.py,R.pz),x=v.add(R),T=O.add(N)}else{let{p:F,f:V}=this.wNAF(h);x=F,T=V}return d.normalizeZ([x,T])[0]}multiplyAndAddUnsafe(h,E,C){let x=d.BASE,T=(V,U)=>U===Ct||U===me||!V.equals(x)?V.multiplyUnsafe(U):V.multiply(U),F=T(this,E).add(T(h,C));return F.is0()?void 0:F}toAffine(h){return u(this,h)}isTorsionFree(){let{h,isTorsionFree:E}=e;if(h===me)return!0;if(E)return E(d,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:E}=e;return h===me?this:E?E(d,this):this.multiplyUnsafe(e.h)}toRawBytes(h=!0){return Je("isCompressed",h),this.assertValidity(),o(d,this,h)}toHex(h=!0){return Je("isCompressed",h),wt(this.toRawBytes(h))}}d.BASE=new d(e.Gx,e.Gy,t.ONE),d.ZERO=new d(t.ZERO,t.ONE,t.ZERO);let b=e.nBitLength,I=jn(d,e.endo?Math.ceil(b/2):b);return{CURVE:e,ProjectivePoint:d,normPrivateKeyToScalar:c,weierstrassEquation:s,isWithinCurveOrder:a}}function gp(r){let e=en(r);return at(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function Gu(r){let e=gp(r),{Fp:t,n}=e,o=t.BYTES+1,i=2*t.BYTES+1;function s(A){return Q(A,n)}function a(A){return zn(A,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:f,weierstrassEquation:u,isWithinCurveOrder:l}=mp({...e,toBytes(A,S,m){let p=S.toAffine(),B=t.toBytes(p.x),P=bt;return Je("isCompressed",m),m?P(Uint8Array.from([S.hasEvenY()?2:3]),B):P(Uint8Array.from([4]),B,t.toBytes(p.y))},fromBytes(A){let S=A.length,m=A[0],p=A.subarray(1);if(S===o&&(m===2||m===3)){let B=xt(p);if(!Xr(B,me,t.ORDER))throw new Error("Point is not on curve");let P=u(B),D;try{D=t.sqrt(P)}catch(G){let z=G instanceof Error?": "+G.message:"";throw new Error("Point is not on curve"+z)}let M=(D&me)===me;return(m&1)===1!==M&&(D=t.neg(D)),{x:B,y:D}}else if(S===i&&m===4){let B=t.fromBytes(p.subarray(0,t.BYTES)),P=t.fromBytes(p.subarray(t.BYTES,2*t.BYTES));return{x:B,y:P}}else throw new Error(`Point of length ${S} was invalid. Expected ${o} compressed bytes or ${i} uncompressed bytes`)}}),d=A=>wt(Ot(A,e.nByteLength));function b(A){let S=n>>me;return A>S}function I(A){return b(A)?s(-A):A}let w=(A,S,m)=>xt(A.slice(S,m));class h{constructor(S,m,p){this.r=S,this.s=m,this.recovery=p,this.assertValidity()}static fromCompact(S){let m=e.nByteLength;return S=ae("compactSignature",S,m*2),new h(w(S,0,m),w(S,m,2*m))}static fromDER(S){let{r:m,s:p}=kt.toSig(ae("DER",S));return new h(m,p)}assertValidity(){Le("r",this.r,me,n),Le("s",this.s,me,n)}addRecoveryBit(S){return new h(this.r,this.s,S)}recoverPublicKey(S){let{r:m,s:p,recovery:B}=this,P=V(ae("msgHash",S));if(B==null||![0,1,2,3].includes(B))throw new Error("recovery id invalid");let D=B===2||B===3?m+e.n:m;if(D>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let M=B&1?"03":"02",q=c.fromHex(M+d(D)),G=a(D),z=s(-P*G),J=s(p*G),te=c.BASE.multiplyAndAddUnsafe(q,z,J);if(!te)throw new Error("point at infinify");return te.assertValidity(),te}hasHighS(){return b(this.s)}normalizeS(){return this.hasHighS()?new h(this.r,s(-this.s),this.recovery):this}toDERRawBytes(){return Jt(this.toDERHex())}toDERHex(){return kt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Jt(this.toCompactHex())}toCompactHex(){return d(this.r)+d(this.s)}}let E={isValidPrivateKey(A){try{return f(A),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let A=os(e.n);return Sc(e.randomBytes(A),e.n)},precompute(A=8,S=c.BASE){return S._setWindowSize(A),S.multiply(BigInt(3)),S}};function C(A,S=!0){return c.fromPrivateKey(A).toRawBytes(S)}function x(A){let S=Pt(A),m=typeof A=="string",p=(S||m)&&A.length;return S?p===o||p===i:m?p===2*o||p===2*i:A instanceof c}function T(A,S,m=!0){if(x(A))throw new Error("first arg must be private key");if(!x(S))throw new Error("second arg must be public key");return c.fromHex(S).multiply(f(A)).toRawBytes(m)}let F=e.bits2int||function(A){let S=xt(A),m=A.length*8-e.nBitLength;return m>0?S>>BigInt(m):S},V=e.bits2int_modN||function(A){return s(F(A))},U=Qr(e.nBitLength);function g(A){return Le(`num < 2^${e.nBitLength}`,A,Ct,U),Ot(A,e.nByteLength)}function v(A,S,m=O){if(["recovered","canonical"].some(pe=>pe in m))throw new Error("sign() legacy options not supported");let{hash:p,randomBytes:B}=e,{lowS:P,prehash:D,extraEntropy:M}=m;P==null&&(P=!0),A=ae("msgHash",A),zu(m),D&&(A=ae("prehashed msgHash",p(A)));let q=V(A),G=f(S),z=[g(G),g(q)];if(M!=null&&M!==!1){let pe=M===!0?B(t.BYTES):M;z.push(ae("extraEntropy",pe))}let J=bt(...z),te=q;function he(pe){let ye=F(pe);if(!l(ye))return;let Ie=a(ye),le=c.BASE.multiply(ye).toAffine(),Ue=s(le.x);if(Ue===Ct)return;let pt=s(Ie*s(te+Ue*G));if(pt===Ct)return;let jr=(le.x===Ue?0:2)|Number(le.y&me),Gr=pt;return P&&b(pt)&&(Gr=I(pt),jr^=1),new h(Ue,Gr,jr)}return{seed:J,k2sig:he}}let O={lowS:e.lowS,prehash:!1},R={lowS:e.lowS,prehash:!1};function N(A,S,m=O){let{seed:p,k2sig:B}=v(A,S,m),P=e;return es(P.hash.outputLen,P.nByteLength,P.hmac)(p,B)}c.BASE._setWindowSize(8);function H(A,S,m,p=R){let B=A;if(S=ae("msgHash",S),m=ae("publicKey",m),"strict"in p)throw new Error("options.strict was renamed to lowS");zu(p);let{lowS:P,prehash:D}=p,M,q;try{if(typeof B=="string"||Pt(B))try{M=h.fromDER(B)}catch(le){if(!(le instanceof kt.Err))throw le;M=h.fromCompact(B)}else if(typeof B=="object"&&typeof B.r=="bigint"&&typeof B.s=="bigint"){let{r:le,s:Ue}=B;M=new h(le,Ue)}else throw new Error("PARSE");q=c.fromHex(m)}catch(le){if(le.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(P&&M.hasHighS())return!1;D&&(S=e.hash(S));let{r:G,s:z}=M,J=V(S),te=a(z),he=s(J*te),pe=s(G*te),ye=c.BASE.multiplyAndAddUnsafe(q,he,pe)?.toAffine();return ye?s(ye.x)===G:!1}return{CURVE:e,getPublicKey:C,getSharedSecret:T,sign:N,verify:H,ProjectivePoint:c,Signature:h,utils:E}}function yp(r){return{hash:r,hmac:(e,...t)=>Ws(r,e,ji(...t)),randomBytes:$n}}function Zu(r,e){let t=n=>Gu({...r,...yp(n)});return Object.freeze({...t(e),create:t})}var Ju=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Wu=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),wp=BigInt(1),Ys=BigInt(2),Yu=(r,e)=>(r+e/Ys)/e;function xp(r){let e=Ju,t=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%e,u=f*f*r%e,l=ie(u,t,e)*u%e,d=ie(l,t,e)*u%e,b=ie(d,Ys,e)*f%e,I=ie(b,o,e)*b%e,w=ie(I,i,e)*I%e,h=ie(w,a,e)*w%e,E=ie(h,c,e)*h%e,C=ie(E,a,e)*w%e,x=ie(C,t,e)*u%e,T=ie(x,s,e)*I%e,F=ie(T,n,e)*f%e,V=ie(F,Ys,e);if(!Js.eql(Js.sqr(V),r))throw new Error("Cannot find square root");return V}var Js=Dt(Ju,void 0,void 0,{sqrt:xp}),ir=Zu({a:BigInt(0),b:BigInt(7),Fp:Js,n:Wu,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=Wu,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-wp*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=t,s=BigInt("0x100000000000000000000000000000000"),a=Yu(i*r,e),c=Yu(-n*r,e),f=Q(r-a*t-c*o,e),u=Q(-a*n-c*i,e),l=f>s,d=u>s;if(l&&(f=e-f),d&&(u=e-u),f>s||u>s)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:l,k1:f,k2neg:d,k2:u}}}},Tr),Nx=BigInt(0);var Ux=ir.ProjectivePoint;function De(r,e){e==null&&(e=r.reduce((o,i)=>o+i.length,0));let t=Qe(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}function Xu(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Qu(r,e,t){let n=tn.digest(t instanceof Uint8Array?t:t.subarray());if(Xu(n))return n.then(({digest:o})=>ir.verify(e,o,r)).catch(o=>{throw new mn(String(o))});try{return ir.verify(e,n.digest,r)}catch(o){throw new mn(String(o))}}var Wo=class{type="secp256k1";raw;_key;constructor(e){this._key=tl(e),this.raw=el(this._key)}toMultihash(){return We.digest(Jn(this))}toCID(){return X.createV1(114,this.toMultihash())}toString(){return re.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ce(this.raw,e.raw)}verify(e,t){return Qu(this._key,t,e)}};function Xs(r){return new Wo(r)}function el(r){return ir.ProjectivePoint.fromHex(r).toRawBytes(!0)}function tl(r){try{return ir.ProjectivePoint.fromHex(r),r}catch(e){throw new lr(String(e))}}function rl(r){let{Type:e,Data:t}=ct.decode(r),n=t??new Uint8Array;switch(e){case de.RSA:return Zs(n);case de.Ed25519:return us(n);case de.secp256k1:return Xs(n);default:throw new dr}}function Yo(r){let{Type:e,Data:t}=ct.decode(r.digest),n=t??new Uint8Array;switch(e){case de.Ed25519:return us(n);case de.secp256k1:return Xs(n);default:throw new dr}}function Jn(r){return ct.encode({Type:de[r.type],Data:r.raw})}var nl=Symbol.for("nodejs.util.inspect.custom"),bp=114,wn=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Ri]=!0;toString(){return this.string==null&&(this.string=re.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return X.createV1(bp,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return ce(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return ce(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[nl](){return`PeerId(${this.toString()})`}},Jo=class extends wn{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Xo=class extends wn{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Qo=class extends wn{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},vp=2336,xn=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=We.digest(Z(this.url))}[nl](){return`PeerId(${this.url})`}[Ri]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return X.createV1(vp,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=ne(e)),e.toString()===this.toString())}};var Ep=114,ol=2336;function il(r,e){let t;if(r.charAt(0)==="1"||r.charAt(0)==="Q")t=gt(re.decode(`z${r}`));else{if(e==null)throw new ve('Please pass a multibase decoder for strings that do not start with "1" or "Q"');t=gt(e.decode(r))}return sl(t)}function sl(r){if(Ap(r))return new Jo({multihash:r});if(Bp(r))try{let e=Yo(r);if(e.type==="Ed25519")return new Xo({multihash:r,publicKey:e});if(e.type==="secp256k1")return new Qo({multihash:r,publicKey:e})}catch{let t=ne(r.digest);return new xn(new URL(t))}throw new fr("Supplied PeerID Multihash is invalid")}function al(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==Ep&&r.code!==ol)throw new Ln("Supplied PeerID CID is invalid");if(r.code===ol){let e=ne(r.multihash.digest);return new xn(new URL(e))}return sl(r.multihash)}function Bp(r){return r.code===We.code}function Ap(r){return r.code===tn.code}var ei=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}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 t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let i=0,s=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",f=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let d=Number.parseInt(l,e);if(!Number.isNaN(d))return d});if(u===void 0)break;if(i*=e,i+=u,i>f||(s+=1,t!==void 0&&s>t))return}if(s!==0)return!n&&c&&s>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return t[o]=s[0],t[o+1]=s[1],t[o+2]=s[2],t[o+3]=s[3],[o+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[o,!1];t[o]=i>>8,t[o+1]=i&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),s=16-(n+2),[a]=e(i.subarray(0,s));return t.set(i.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var cl=45,Sp=15,Pr=new ei;function Qs(r){if(!(r.length>Sp))return Pr.new(r).parseWith(()=>Pr.readIPv4Addr())}function ea(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>cl))return Pr.new(r).parseWith(()=>Pr.readIPv6Addr())}function ti(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>cl))return Pr.new(r).parseWith(()=>Pr.readIPAddr())}var jb=parseInt("0xFFFF",16),Gb=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function fl(r){return!!Qs(r)}function dl(r){return!!ea(r)}function ri(r){return!!ti(r)}var hl=fl,Np=dl,ta=function(r){let e=0;if(r=r.toString().trim(),hl(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(Np(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=hl(t[n]),s;i&&(s=ta(t[n]),t[n]=ne(s.slice(0,2),"base16")),s!=null&&++n<8&&t.splice(n,0,ne(s.slice(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let i=[n,1];for(n=9-t.length;n>0;n--)i.push("0");t.splice.apply(t,i)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){let i=parseInt(t[n],16);o[e++]=i>>8&255,o[e++]=i&255}return o}throw new Error("invalid ip address")},pl=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let o=[];for(let i=0;i<t;i++)o.push(r[e+i]);return o.join(".")}if(t===16){let o=[];for(let i=0;i<t;i+=2)o.push(n.getUint16(e+i).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var Fr={},ra={},Rp=[[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"],[481,-1,"http-path"],[777,-1,"memory"]];Rp.forEach(r=>{let e=_p(...r);ra[e.code]=e,Fr[e.name]=e});function _p(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function ee(r){if(typeof r=="number"){if(ra[r]!=null)return ra[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Fr[r]!=null)return Fr[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var N1=ee("ip4"),U1=ee("ip6"),R1=ee("ipcidr");function sa(r,e){switch(ee(r).code){case 4:case 41:return Vp(e);case 42:return ia(e);case 6:case 273:case 33:case 132:return yl(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return ia(e);case 421:return Dp(e);case 444:return gl(e);case 445:return gl(e);case 466:return Op(e);case 481:return globalThis.encodeURIComponent(ia(e));default:return ne(e,"base16")}}function aa(r,e){switch(ee(r).code){case 4:return ml(e);case 41:return ml(e);case 42:return oa(e);case 6:case 273:case 33:case 132:return ca(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return oa(e);case 421:return Pp(e);case 444:return Mp(e);case 445:return $p(e);case 466:return Fp(e);case 481:return oa(globalThis.decodeURIComponent(e));default:return Z(e,"base16")}}var na=Object.values(rn).map(r=>r.decoder),Lp=function(){let r=na[0].or(na[1]);return na.slice(2).forEach(e=>r=r.or(e)),r}();function ml(r){if(!ri(r))throw new Error("invalid ip address");return ta(r)}function Vp(r){let e=pl(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!ri(e))throw new Error("invalid ip address");return e}function ca(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function yl(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function oa(r){let e=Z(r),t=Uint8Array.from(Ar(e.length));return De([t,e],t.length+e.length)}function ia(r){let e=tr(r);if(r=r.slice(Pe(e)),r.length!==e)throw new Error("inconsistent lengths");return ne(r)}function Pp(r){let e;r[0]==="Q"||r[0]==="1"?e=gt(re.decode(`z${r}`)).bytes:e=X.parse(r).multihash.bytes;let t=Uint8Array.from(Ar(e.length));return De([t,e],t.length+e.length)}function Fp(r){let e=Lp.decode(r),t=Uint8Array.from(Ar(e.length));return De([t,e],t.length+e.length)}function Op(r){let e=tr(r),t=r.slice(Pe(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+ne(t,"base64url")}function Dp(r){let e=tr(r),t=r.slice(Pe(e));if(t.length!==e)throw new Error("inconsistent lengths");return ne(t,"base58btc")}function Mp(r){let e=r.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 t=Ge.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 o=ca(n);return De([t,o],t.length+o.length)}function $p(r){let e=r.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 t=Ge.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 o=ca(n);return De([t,o],t.length+o.length)}function gl(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=ne(e,"base32"),o=yl(t);return`${n}:${o}`}function wl(r){r=ua(r);let e=[],t=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let i=0;i<o.length;i++){let s=o[i],a=ee(s);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(i++,i>=o.length)throw bl("invalid address: "+r);if(a.path===!0){n=ua(o.slice(i).join("/")),e.push([a.code,aa(a.code,n)]),t.push([a.code,n]);break}let c=aa(a.code,o[i]);e.push([a.code,c]),t.push([a.code,sa(a.code,c)])}return{string:xl(t),bytes:fa(e),tuples:e,stringTuples:t,path:n}}function la(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let i=tr(r,o),s=Pe(i),a=ee(i),c=Hp(a,r.slice(o+s));if(c===0){e.push([i]),t.push([i]),o+=s;continue}let f=r.slice(o+s,o+s+c);if(o+=c+s,o>r.length)throw bl("Invalid address Uint8Array: "+ne(r,"base16"));e.push([i,f]);let u=sa(i,f);if(t.push([i,u]),a.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:xl(t),tuples:e,stringTuples:t,path:n}}function xl(r){let e=[];return r.map(t=>{let n=ee(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),ua(e.join("/"))}function fa(r){return De(r.map(e=>{let t=ee(e[0]),n=Uint8Array.from(Ar(t.code));return e.length>1&&e[1]!=null&&(n=De([n,e[1]])),n}))}function Hp(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=tr(e instanceof Uint8Array?e:Uint8Array.from(e));return t+Pe(t)}}function ua(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function bl(r){return new Error("Error parsing address: "+r)}var Kp=Symbol.for("nodejs.util.inspect.custom"),ha=Symbol.for("@multiformats/js-multiaddr/multiaddr"),qp=[ee("dns").code,ee("dns4").code,ee("dns6").code,ee("dnsaddr").code],da=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}},ni=class r{bytes;#e;#t;#i;#a;[ha]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=la(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=wl(e)}else if(El(e))t=la(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#t=t.tuples,this.#i=t.stringTuples,this.#a=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,o,i="",s=ee("tcp"),a=ee("udp"),c=ee("ip4"),f=ee("ip6"),u=ee("dns6"),l=ee("ip6zone");for(let[b,I]of this.stringTuples())b===l.code&&(i=`%${I??""}`),qp.includes(b)&&(t=s.name,o=443,n=`${I??""}${i}`,e=b===u.code?6:4),(b===s.code||b===a.code)&&(t=ee(b).name,o=parseInt(I??"")),(b===c.code||b===f.code)&&(t=ee(b).name,n=`${I??""}${i}`,e=b===f.code?6:4);if(e==null||t==null||n==null||o==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:t,port:o}}protos(){return this.#t.map(([e])=>Object.assign({},ee(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>ee(e).name)}tuples(){return this.#t}stringTuples(){return this.#i}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(fa(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===Fr.p2p.code&&e.push([n,o]),n===Fr["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?ne(re.decode(`z${n}`),"base58btc"):ne(X.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#a}equals(e){return ce(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(i=>i.resolvable);if(t==null)return[this];let n=vl.get(t.name);if(n==null)throw new da(`no available resolver for ${t.name}`);return(await n(this,e)).map(i=>sr(i))}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 t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[Kp](){return`Multiaddr(${this.#e})`}};var vl=new Map;function El(r){return!!r?.[ha]}function sr(r){return new ni(r)}function bn(r){let e=new globalThis.AbortController;function t(){e.abort();for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}for(let i of r){if(i?.aborted===!0){t();break}i?.addEventListener!=null&&i.addEventListener("abort",t)}function n(){for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}let o=e.signal;return o.clear=n,o}async function*oi(r,e={}){let t=r.getReader();try{for(;;){let n=await t.read();if(n.done)return;yield n.value}}finally{e.preventCancel!==!0&&await t.cancel(),t.releaseLock()}}var zp="/",jp=new TextEncoder().encode(zp),s2=jp[0];var Im=_n(ma(),1);var rt=class extends Error{static name="SignatureVerificationError";constructor(e="Record signature verification failed"){super(e),this.name="SignatureVerificationError"}},ii=class extends Error{static name="RecordExpiredError";constructor(e="Record has expired"){super(e),this.name="RecordExpiredError"}},Or=class extends Error{static name="UnsupportedValidityError";constructor(e="The validity type is unsupported"){super(e),this.name="UnsupportedValidityError"}},si=class extends Error{static name="RecordTooLargeError";constructor(e="The record is too large"){super(e),this.name="RecordTooLargeError"}},ai=class extends Error{static name="InvalidValueError";constructor(e="Value must be a valid content path starting with /"){super(e),this.name="InvalidValueError"}},ci=class extends Error{static name="InvalidRecordDataError";constructor(e="Invalid record data"){super(e),this.name="InvalidRecordDataError"}},vn=class extends Error{static name="InvalidEmbeddedPublicKeyError";constructor(e="Invalid embedded public key"){super(e),this.name="InvalidEmbeddedPublicKeyError"}};var nt;(function(r){let e;(function(o){o.EOL="EOL"})(e=r.ValidityType||(r.ValidityType={}));let t;(function(o){o[o.EOL=0]="EOL"})(t||(t={})),function(o){o.codec=()=>sn(t)}(e=r.ValidityType||(r.ValidityType={}));let n;r.codec=()=>(n==null&&(n=Cr((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.value!=null&&(i.uint32(10),i.bytes(o.value)),o.signatureV1!=null&&(i.uint32(18),i.bytes(o.signatureV1)),o.validityType!=null&&(i.uint32(24),r.ValidityType.codec().encode(o.validityType,i)),o.validity!=null&&(i.uint32(34),i.bytes(o.validity)),o.sequence!=null&&(i.uint32(40),i.uint64(o.sequence)),o.ttl!=null&&(i.uint32(48),i.uint64(o.ttl)),o.pubKey!=null&&(i.uint32(58),i.bytes(o.pubKey)),o.signatureV2!=null&&(i.uint32(66),i.bytes(o.signatureV2)),o.data!=null&&(i.uint32(74),i.bytes(o.data)),s.lengthDelimited!==!1&&i.ldelim()},(o,i,s={})=>{let a={},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let f=o.uint32();switch(f>>>3){case 1:{a.value=o.bytes();break}case 2:{a.signatureV1=o.bytes();break}case 3:{a.validityType=r.ValidityType.codec().decode(o);break}case 4:{a.validity=o.bytes();break}case 5:{a.sequence=o.uint64();break}case 6:{a.ttl=o.uint64();break}case 7:{a.pubKey=o.bytes();break}case 8:{a.signatureV2=o.bytes();break}case 9:{a.data=o.bytes();break}default:{o.skipType(f&7);break}}}return a})),n),r.encode=o=>Ir(o,r.codec()),r.decode=(o,i)=>Sr(o,r.codec(),i)})(nt||(nt={}));var Gp=["string","number","bigint","symbol"],Zp=["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 Bl(r){if(r===null)return"null";if(r===void 0)return"undefined";if(r===!0||r===!1)return"boolean";let e=typeof r;if(Gp.includes(e))return e;if(e==="function")return"Function";if(Array.isArray(r))return"Array";if(Wp(r))return"Buffer";let t=Yp(r);return t||"Object"}function Wp(r){return r&&r.constructor&&r.constructor.isBuffer&&r.constructor.isBuffer.call(null,r)}function Yp(r){let e=Object.prototype.toString.call(r).slice(8,-1);if(Zp.includes(e))return e}var y=class{constructor(e,t,n){this.major=e,this.majorEncoded=e<<5,this.name=t,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}};y.uint=new y(0,"uint",!0);y.negint=new y(1,"negint",!0);y.bytes=new y(2,"bytes",!0);y.string=new y(3,"string",!0);y.array=new y(4,"array",!1);y.map=new y(5,"map",!1);y.tag=new y(6,"tag",!1);y.float=new y(7,"float",!0);y.false=new y(7,"false",!0);y.true=new y(7,"true",!0);y.null=new y(7,"null",!0);y.undefined=new y(7,"undefined",!0);y.break=new y(7,"break",!0);var L=class{constructor(e,t,n){this.type=e,this.value=t,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var Dr=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Jp=new TextDecoder,Xp=new TextEncoder;function ui(r){return Dr&&globalThis.Buffer.isBuffer(r)}function kl(r){return r instanceof Uint8Array?ui(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r:Uint8Array.from(r)}var Cl=Dr?(r,e,t)=>t-e>64?globalThis.Buffer.from(r.subarray(e,t)).toString("utf8"):Sl(r,e,t):(r,e,t)=>t-e>64?Jp.decode(r.subarray(e,t)):Sl(r,e,t),Tl=Dr?r=>r.length>64?globalThis.Buffer.from(r):Al(r):r=>r.length>64?Xp.encode(r):Al(r);var Mr=Dr?(r,e,t)=>ui(r)?new Uint8Array(r.subarray(e,t)):r.slice(e,t):(r,e,t)=>r.slice(e,t),Nl=Dr?(r,e)=>(r=r.map(t=>t instanceof Uint8Array?t:globalThis.Buffer.from(t)),kl(globalThis.Buffer.concat(r,e))):(r,e)=>{let t=new Uint8Array(e),n=0;for(let o of r)n+o.length>t.length&&(o=o.subarray(0,t.length-n)),t.set(o,n),n+=o.length;return t},Ul=Dr?r=>globalThis.Buffer.allocUnsafe(r):r=>new Uint8Array(r);function Rl(r,e){if(ui(r)&&ui(e))return r.compare(e);for(let t=0;t<r.length;t++)if(r[t]!==e[t])return r[t]<e[t]?-1:1;return 0}function Al(r){let e=[],t=0;for(let n=0;n<r.length;n++){let o=r.charCodeAt(n);o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&n+1<r.length&&(r.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(r.charCodeAt(++n)&1023),e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128)}return e}function Sl(r,e,t){let n=[];for(;e<t;){let o=r[e],i=null,s=o>239?4:o>223?3:o>191?2:1;if(e+s<=t){let a,c,f,u;switch(s){case 1:o<128&&(i=o);break;case 2:a=r[e+1],(a&192)===128&&(u=(o&31)<<6|a&63,u>127&&(i=u));break;case 3:a=r[e+1],c=r[e+2],(a&192)===128&&(c&192)===128&&(u=(o&15)<<12|(a&63)<<6|c&63,u>2047&&(u<55296||u>57343)&&(i=u));break;case 4:a=r[e+1],c=r[e+2],f=r[e+3],(a&192)===128&&(c&192)===128&&(f&192)===128&&(u=(o&15)<<18|(a&63)<<12|(c&63)<<6|f&63,u>65535&&u<1114112&&(i=u))}}i===null?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),e+=s}return Qp(n)}var Il=4096;function Qp(r){let e=r.length;if(e<=Il)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=Il));return t}var em=256,li=class{constructor(e=em){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 t=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=t.length-(this.maxCursor-this.cursor)-1;t.set(e,o)}else{if(t){let o=t.length-(this.maxCursor-this.cursor)-1;o<t.length&&(this.chunks[this.chunks.length-1]=t.subarray(0,o),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(t=Ul(this.chunkSize),this.chunks.push(t),this.maxCursor+=t.length,this._initReuseChunk===null&&(this._initReuseChunk=t),t.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let t;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(t=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):t=Mr(n,0,this.cursor)}else t=Nl(this.chunks,this.cursor);return e&&this.reset(),t}};var $="CBOR decode error:",ga="CBOR encode error:",En=[];En[23]=1;En[24]=2;En[25]=3;En[26]=5;En[27]=9;function Tt(r,e,t){if(r.length-e<t)throw new Error(`${$} not enough data for type`)}var ge=[24,256,65536,4294967296,BigInt("18446744073709551616")];function Me(r,e,t){Tt(r,e,1);let n=r[e];if(t.strict===!0&&n<ge[0])throw new Error(`${$} integer encoded in more bytes than necessary (strict decode)`);return n}function $e(r,e,t){Tt(r,e,2);let n=r[e]<<8|r[e+1];if(t.strict===!0&&n<ge[1])throw new Error(`${$} integer encoded in more bytes than necessary (strict decode)`);return n}function He(r,e,t){Tt(r,e,4);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3];if(t.strict===!0&&n<ge[2])throw new Error(`${$} integer encoded in more bytes than necessary (strict decode)`);return n}function Ke(r,e,t){Tt(r,e,8);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3],o=r[e+4]*16777216+(r[e+5]<<16)+(r[e+6]<<8)+r[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(t.strict===!0&&i<ge[3])throw new Error(`${$} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(t.allowBigInt===!0)return i;throw new Error(`${$} integers outside of the safe integer range are not supported`)}function _l(r,e,t,n){return new L(y.uint,Me(r,e+1,n),2)}function Ll(r,e,t,n){return new L(y.uint,$e(r,e+1,n),3)}function Vl(r,e,t,n){return new L(y.uint,He(r,e+1,n),5)}function Pl(r,e,t,n){return new L(y.uint,Ke(r,e+1,n),9)}function ze(r,e){return be(r,0,e.value)}function be(r,e,t){if(t<ge[0]){let n=Number(t);r.push([e|n])}else if(t<ge[1]){let n=Number(t);r.push([e|24,n])}else if(t<ge[2]){let n=Number(t);r.push([e|25,n>>>8,n&255])}else if(t<ge[3]){let n=Number(t);r.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(t);if(n<ge[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,r.push(o)}else throw new Error(`${$} encountered BigInt larger than allowable range`)}}ze.encodedSize=function(e){return be.encodedSize(e.value)};be.encodedSize=function(e){return e<ge[0]?1:e<ge[1]?2:e<ge[2]?3:e<ge[3]?5:9};ze.compareTokens=function(e,t){return e.value<t.value?-1:e.value>t.value?1:0};function Fl(r,e,t,n){return new L(y.negint,-1-Me(r,e+1,n),2)}function Ol(r,e,t,n){return new L(y.negint,-1-$e(r,e+1,n),3)}function Dl(r,e,t,n){return new L(y.negint,-1-He(r,e+1,n),5)}var ya=BigInt(-1),Ml=BigInt(1);function $l(r,e,t,n){let o=Ke(r,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new L(y.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${$} integers outside of the safe integer range are not supported`);return new L(y.negint,ya-BigInt(o),9)}function fi(r,e){let t=e.value,n=typeof t=="bigint"?t*ya-Ml:t*-1-1;be(r,e.type.majorEncoded,n)}fi.encodedSize=function(e){let t=e.value,n=typeof t=="bigint"?t*ya-Ml:t*-1-1;return n<ge[0]?1:n<ge[1]?2:n<ge[2]?3:n<ge[3]?5:9};fi.compareTokens=function(e,t){return e.value<t.value?1:e.value>t.value?-1:0};function Bn(r,e,t,n){Tt(r,e,t+n);let o=Mr(r,e+t,e+t+n);return new L(y.bytes,o,t+n)}function Hl(r,e,t,n){return Bn(r,e,1,t)}function Kl(r,e,t,n){return Bn(r,e,2,Me(r,e+1,n))}function ql(r,e,t,n){return Bn(r,e,3,$e(r,e+1,n))}function zl(r,e,t,n){return Bn(r,e,5,He(r,e+1,n))}function jl(r,e,t,n){let o=Ke(r,e+1,n);if(typeof o=="bigint")throw new Error(`${$} 64-bit integer bytes lengths not supported`);return Bn(r,e,9,o)}function di(r){return r.encodedBytes===void 0&&(r.encodedBytes=r.type===y.string?Tl(r.value):r.value),r.encodedBytes}function $r(r,e){let t=di(e);be(r,e.type.majorEncoded,t.length),r.push(t)}$r.encodedSize=function(e){let t=di(e);return be.encodedSize(t.length)+t.length};$r.compareTokens=function(e,t){return rm(di(e),di(t))};function rm(r,e){return r.length<e.length?-1:r.length>e.length?1:Rl(r,e)}function An(r,e,t,n,o){let i=t+n;Tt(r,e,i);let s=new L(y.string,Cl(r,e+t,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=Mr(r,e+t,e+i)),s}function Gl(r,e,t,n){return An(r,e,1,t,n)}function Zl(r,e,t,n){return An(r,e,2,Me(r,e+1,n),n)}function Wl(r,e,t,n){return An(r,e,3,$e(r,e+1,n),n)}function Yl(r,e,t,n){return An(r,e,5,He(r,e+1,n),n)}function Jl(r,e,t,n){let o=Ke(r,e+1,n);if(typeof o=="bigint")throw new Error(`${$} 64-bit integer string lengths not supported`);return An(r,e,9,o,n)}var Xl=$r;function Hr(r,e,t,n){return new L(y.array,n,t)}function Ql(r,e,t,n){return Hr(r,e,1,t)}function ef(r,e,t,n){return Hr(r,e,2,Me(r,e+1,n))}function tf(r,e,t,n){return Hr(r,e,3,$e(r,e+1,n))}function rf(r,e,t,n){return Hr(r,e,5,He(r,e+1,n))}function nf(r,e,t,n){let o=Ke(r,e+1,n);if(typeof o=="bigint")throw new Error(`${$} 64-bit integer array lengths not supported`);return Hr(r,e,9,o)}function of(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${$} indefinite length items not allowed`);return Hr(r,e,1,1/0)}function hi(r,e){be(r,y.array.majorEncoded,e.value)}hi.compareTokens=ze.compareTokens;hi.encodedSize=function(e){return be.encodedSize(e.value)};function Kr(r,e,t,n){return new L(y.map,n,t)}function sf(r,e,t,n){return Kr(r,e,1,t)}function af(r,e,t,n){return Kr(r,e,2,Me(r,e+1,n))}function cf(r,e,t,n){return Kr(r,e,3,$e(r,e+1,n))}function uf(r,e,t,n){return Kr(r,e,5,He(r,e+1,n))}function lf(r,e,t,n){let o=Ke(r,e+1,n);if(typeof o=="bigint")throw new Error(`${$} 64-bit integer map lengths not supported`);return Kr(r,e,9,o)}function ff(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${$} indefinite length items not allowed`);return Kr(r,e,1,1/0)}function pi(r,e){be(r,y.map.majorEncoded,e.value)}pi.compareTokens=ze.compareTokens;pi.encodedSize=function(e){return be.encodedSize(e.value)};function df(r,e,t,n){return new L(y.tag,t,1)}function hf(r,e,t,n){return new L(y.tag,Me(r,e+1,n),2)}function pf(r,e,t,n){return new L(y.tag,$e(r,e+1,n),3)}function mf(r,e,t,n){return new L(y.tag,He(r,e+1,n),5)}function gf(r,e,t,n){return new L(y.tag,Ke(r,e+1,n),9)}function mi(r,e){be(r,y.tag.majorEncoded,e.value)}mi.compareTokens=ze.compareTokens;mi.encodedSize=function(e){return be.encodedSize(e.value)};var cm=20,um=21,lm=22,fm=23;function yf(r,e,t,n){if(n.allowUndefined===!1)throw new Error(`${$} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new L(y.null,null,1):new L(y.undefined,void 0,1)}function wf(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${$} indefinite length items not allowed`);return new L(y.break,void 0,1)}function wa(r,e,t){if(t){if(t.allowNaN===!1&&Number.isNaN(r))throw new Error(`${$} NaN values are not supported`);if(t.allowInfinity===!1&&(r===1/0||r===-1/0))throw new Error(`${$} Infinity values are not supported`)}return new L(y.float,r,e)}function xf(r,e,t,n){return wa(xa(r,e+1),3,n)}function bf(r,e,t,n){return wa(ba(r,e+1),5,n)}function vf(r,e,t,n){return wa(Sf(r,e+1),9,n)}function gi(r,e,t){let n=e.value;if(n===!1)r.push([y.float.majorEncoded|cm]);else if(n===!0)r.push([y.float.majorEncoded|um]);else if(n===null)r.push([y.float.majorEncoded|lm]);else if(n===void 0)r.push([y.float.majorEncoded|fm]);else{let o,i=!1;(!t||t.float64!==!0)&&(Bf(n),o=xa(ot,1),n===o||Number.isNaN(n)?(ot[0]=249,r.push(ot.slice(0,3)),i=!0):(Af(n),o=ba(ot,1),n===o&&(ot[0]=250,r.push(ot.slice(0,5)),i=!0))),i||(dm(n),o=Sf(ot,1),ot[0]=251,r.push(ot.slice(0,9)))}}gi.encodedSize=function(e,t){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!t||t.float64!==!0){Bf(n);let o=xa(ot,1);if(n===o||Number.isNaN(n))return 3;if(Af(n),o=ba(ot,1),n===o)return 5}return 9};var Ef=new ArrayBuffer(9),je=new DataView(Ef,1),ot=new Uint8Array(Ef,0);function Bf(r){if(r===1/0)je.setUint16(0,31744,!1);else if(r===-1/0)je.setUint16(0,64512,!1);else if(Number.isNaN(r))je.setUint16(0,32256,!1);else{je.setFloat32(0,r);let e=je.getUint32(0),t=(e&2139095040)>>23,n=e&8388607;if(t===255)je.setUint16(0,31744,!1);else if(t===0)je.setUint16(0,(r&2147483648)>>16|n>>13,!1);else{let o=t-127;o<-24?je.setUint16(0,0):o<-14?je.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):je.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function xa(r,e){if(r.length-e<2)throw new Error(`${$} not enough data for float16`);let t=(r[e]<<8)+r[e+1];if(t===31744)return 1/0;if(t===64512)return-1/0;if(t===32256)return NaN;let n=t>>10&31,o=t&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,t&32768?-i:i}function Af(r){je.setFloat32(0,r,!1)}function ba(r,e){if(r.length-e<4)throw new Error(`${$} not enough data for float32`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,4).getFloat32(0,!1)}function dm(r){je.setFloat64(0,r,!1)}function Sf(r,e){if(r.length-e<8)throw new Error(`${$} not enough data for float64`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,8).getFloat64(0,!1)}gi.compareTokens=ze.compareTokens;function W(r,e,t){throw new Error(`${$} encountered invalid minor (${t}) for major ${r[e]>>>5}`)}function yi(r){return()=>{throw new Error(`${$} ${r}`)}}var k=[];for(let r=0;r<=23;r++)k[r]=W;k[24]=_l;k[25]=Ll;k[26]=Vl;k[27]=Pl;k[28]=W;k[29]=W;k[30]=W;k[31]=W;for(let r=32;r<=55;r++)k[r]=W;k[56]=Fl;k[57]=Ol;k[58]=Dl;k[59]=$l;k[60]=W;k[61]=W;k[62]=W;k[63]=W;for(let r=64;r<=87;r++)k[r]=Hl;k[88]=Kl;k[89]=ql;k[90]=zl;k[91]=jl;k[92]=W;k[93]=W;k[94]=W;k[95]=yi("indefinite length bytes/strings are not supported");for(let r=96;r<=119;r++)k[r]=Gl;k[120]=Zl;k[121]=Wl;k[122]=Yl;k[123]=Jl;k[124]=W;k[125]=W;k[126]=W;k[127]=yi("indefinite length bytes/strings are not supported");for(let r=128;r<=151;r++)k[r]=Ql;k[152]=ef;k[153]=tf;k[154]=rf;k[155]=nf;k[156]=W;k[157]=W;k[158]=W;k[159]=of;for(let r=160;r<=183;r++)k[r]=sf;k[184]=af;k[185]=cf;k[186]=uf;k[187]=lf;k[188]=W;k[189]=W;k[190]=W;k[191]=ff;for(let r=192;r<=215;r++)k[r]=df;k[216]=hf;k[217]=pf;k[218]=mf;k[219]=gf;k[220]=W;k[221]=W;k[222]=W;k[223]=W;for(let r=224;r<=243;r++)k[r]=yi("simple values are not supported");k[244]=W;k[245]=W;k[246]=W;k[247]=yf;k[248]=yi("simple values are not supported");k[249]=xf;k[250]=bf;k[251]=vf;k[252]=W;k[253]=W;k[254]=W;k[255]=wf;var it=[];for(let r=0;r<24;r++)it[r]=new L(y.uint,r,1);for(let r=-1;r>=-24;r--)it[31-r]=new L(y.negint,r,1);it[64]=new L(y.bytes,new Uint8Array(0),1);it[96]=new L(y.string,"",1);it[128]=new L(y.array,0,1);it[160]=new L(y.map,0,1);it[244]=new L(y.false,!1,1);it[245]=new L(y.true,!0,1);it[246]=new L(y.null,null,1);function pm(){let r=[];return r[y.uint.major]=ze,r[y.negint.major]=fi,r[y.bytes.major]=$r,r[y.string.major]=Xl,r[y.array.major]=hi,r[y.map.major]=pi,r[y.tag.major]=mi,r[y.float.major]=gi,r}var ov=pm(),iv=new li,wi=class r{constructor(e,t){this.obj=e,this.parent=t}includes(e){let t=this;do if(t.obj===e)return!0;while(t=t.parent);return!1}static createCheck(e,t){if(e&&e.includes(t))throw new Error(`${ga} object contains circular references`);return new r(t,e)}},jt={null:new L(y.null,null),undefined:new L(y.undefined,void 0),true:new L(y.true,!0),false:new L(y.false,!1),emptyArray:new L(y.array,0),emptyMap:new L(y.map,0)},Gt={number(r,e,t,n){return!Number.isInteger(r)||!Number.isSafeInteger(r)?new L(y.float,r):r>=0?new L(y.uint,r):new L(y.negint,r)},bigint(r,e,t,n){return r>=BigInt(0)?new L(y.uint,r):new L(y.negint,r)},Uint8Array(r,e,t,n){return new L(y.bytes,r)},string(r,e,t,n){return new L(y.string,r)},boolean(r,e,t,n){return r?jt.true:jt.false},null(r,e,t,n){return jt.null},undefined(r,e,t,n){return jt.undefined},ArrayBuffer(r,e,t,n){return new L(y.bytes,new Uint8Array(r))},DataView(r,e,t,n){return new L(y.bytes,new Uint8Array(r.buffer,r.byteOffset,r.byteLength))},Array(r,e,t,n){if(!r.length)return t.addBreakTokens===!0?[jt.emptyArray,new L(y.break)]:jt.emptyArray;n=wi.createCheck(n,r);let o=[],i=0;for(let s of r)o[i++]=va(s,t,n);return t.addBreakTokens?[new L(y.array,r.length),o,new L(y.break)]:[new L(y.array,r.length),o]},Object(r,e,t,n){let o=e!=="Object",i=o?r.keys():Object.keys(r),s=o?r.size:i.length;if(!s)return t.addBreakTokens===!0?[jt.emptyMap,new L(y.break)]:jt.emptyMap;n=wi.createCheck(n,r);let a=[],c=0;for(let f of i)a[c++]=[va(f,t,n),va(o?r.get(f):r[f],t,n)];return mm(a,t),t.addBreakTokens?[new L(y.map,s),a,new L(y.break)]:[new L(y.map,s),a]}};Gt.Map=Gt.Object;Gt.Buffer=Gt.Uint8Array;for(let r of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Gt[`${r}Array`]=Gt.DataView;function va(r,e={},t){let n=Bl(r),o=e&&e.typeEncoders&&e.typeEncoders[n]||Gt[n];if(typeof o=="function"){let s=o(r,n,e,t);if(s!=null)return s}let i=Gt[n];if(!i)throw new Error(`${ga} unsupported type: ${n}`);return i(r,n,e,t)}function mm(r,e){e.mapSorter&&r.sort(e.mapSorter)}var gm={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},xi=class{constructor(e,t={}){this._pos=0,this.data=e,this.options=t}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],t=it[e];if(t===void 0){let n=k[e];if(!n)throw new Error(`${$} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;t=n(this.data,this._pos,o,this.options)}return this._pos+=t.encodedLength,t}},Sn=Symbol.for("DONE"),bi=Symbol.for("BREAK");function ym(r,e,t){let n=[];for(let o=0;o<r.value;o++){let i=qr(e,t);if(i===bi){if(r.value===1/0)break;throw new Error(`${$} got unexpected break to lengthed array`)}if(i===Sn)throw new Error(`${$} found array but not enough entries (got ${o}, expected ${r.value})`);n[o]=i}return n}function wm(r,e,t){let n=t.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<r.value;s++){let a=qr(e,t);if(a===bi){if(r.value===1/0)break;throw new Error(`${$} got unexpected break to lengthed map`)}if(a===Sn)throw new Error(`${$} found map but not enough entries (got ${s} [no key], expected ${r.value})`);if(n!==!0&&typeof a!="string")throw new Error(`${$} non-string keys not supported (got ${typeof a})`);if(t.rejectDuplicateMapKeys===!0&&(n&&i.has(a)||!n&&a in o))throw new Error(`${$} found repeat map key "${a}"`);let c=qr(e,t);if(c===Sn)throw new Error(`${$} found map but not enough entries (got ${s} [no value], expected ${r.value})`);n?i.set(a,c):o[a]=c}return n?i:o}function qr(r,e){if(r.done())return Sn;let t=r.next();if(t.type===y.break)return bi;if(t.type.terminal)return t.value;if(t.type===y.array)return ym(t,r,e);if(t.type===y.map)return wm(t,r,e);if(t.type===y.tag){if(e.tags&&typeof e.tags[t.value]=="function"){let n=qr(r,e);return e.tags[t.value](n)}throw new Error(`${$} tag not supported (${t.value})`)}throw new Error("unsupported")}function If(r,e){if(!(r instanceof Uint8Array))throw new Error(`${$} data to decode must be a Uint8Array`);e=Object.assign({},gm,e);let t=e.tokenizer||new xi(r,e),n=qr(t,e);if(n===Sn)throw new Error(`${$} did not find any content to decode`);if(n===bi)throw new Error(`${$} got unexpected break`);return[n,r.subarray(t.pos())]}function Ea(r,e){let[t,n]=If(r,e);if(n.length>0)throw new Error(`${$} too many terminals, data makes no sense`);return t}var vm=Rt("ipns:utils"),kf=Z("/ipns/");var Em=0,Bm=18;function Cf(r){let e;if(r.pubKey!=null)try{e=rl(r.pubKey)}catch(t){throw vm.error(t),t}if(e!=null)return e}function Tf(r){let e=Z("ipns-signature:");return De([e,r])}function cr(r){return"signatureV1"in r?nt.encode({value:Z(r.value),signatureV1:r.signatureV1,validityType:r.validityType,validity:Z(r.validity),sequence:r.sequence,ttl:r.ttl,pubKey:r.pubKey,signatureV2:r.signatureV2,data:r.data}):nt.encode({pubKey:r.pubKey,signatureV2:r.signatureV2,data:r.data})}function dt(r){let e=nt.decode(r);if(e.sequence!=null&&(e.sequence=BigInt(e.sequence)),e.ttl!=null&&(e.ttl=BigInt(e.ttl)),e.signatureV2==null||e.data==null)throw new rt("Missing data or signatureV2");let t=Nf(e.data),n=Am(t.Value),o=ne(t.Validity);if(e.value!=null&&e.signatureV1!=null)return Sm(e),{value:n,validityType:nt.ValidityType.EOL,validity:o,sequence:t.Sequence,ttl:t.TTL,pubKey:e.pubKey,signatureV1:e.signatureV1,signatureV2:e.signatureV2,data:e.data};if(e.signatureV2!=null)return{value:n,validityType:nt.ValidityType.EOL,validity:o,sequence:t.Sequence,ttl:t.TTL,pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data};throw new Error("invalid record: does not include signatureV1 or signatureV2")}function In(r){return De([kf,r.bytes])}function Nt(r){let e=gt(r.slice(kf.length));if(!vi(e,Em)&&!vi(e,Bm))throw new fr("Multihash in IPNS key was not identity or sha2-256");return e}function Nf(r){let e=Ea(r);if(e.ValidityType===0)e.ValidityType=nt.ValidityType.EOL;else throw new Or("The validity type is unsupported");return Number.isInteger(e.Sequence)&&(e.Sequence=BigInt(e.Sequence)),Number.isInteger(e.TTL)&&(e.TTL=BigInt(e.TTL)),e}function Am(r){let e=ne(r).trim();if(e.startsWith("/"))return e;try{return`/ipfs/${X.decode(r).toV1().toString()}`}catch{}try{return`/ipfs/${X.parse(e).toV1().toString()}`}catch{}throw new ai("Value must be a valid content path starting with /")}function Sm(r){if(r.data==null)throw new ci("Record data is missing");let e=Nf(r.data);if(!ce(e.Value,r.value??new Uint8Array(0)))throw new rt('Field "value" did not match between protobuf and CBOR');if(!ce(e.Validity,r.validity??new Uint8Array(0)))throw new rt('Field "validity" did not match between protobuf and CBOR');if(e.ValidityType!==r.validityType)throw new rt('Field "validityType" did not match between protobuf and CBOR');if(e.Sequence!==r.sequence)throw new rt('Field "sequence" did not match between protobuf and CBOR');if(e.TTL!==r.ttl)throw new rt('Field "ttl" did not match between protobuf and CBOR')}function vi(r,e){return r.code===e}var Tv=Rt("ipns"),Nv=60*60*1e9,km="/ipns/",Uv=km.length;var Uf=_n(ma(),1);var Ei=Rt("ipns:validator"),Cm=1024*10,Tm=async(r,e)=>{let t=dt(e),n;try{let o=Tf(t.data);n=await r.verify(o,t.signatureV2)}catch{n=!1}if(!n)throw Ei.error("record signature verification failed"),new rt("Record signature verification failed");if(t.validityType===nt.ValidityType.EOL){if(Uf.default.fromString(t.validity).toDate().getTime()<Date.now())throw Ei.error("record has expired"),new ii("record has expired")}else if(t.validityType!=null)throw Ei.error("the validity type is unsupported"),new Or("The validity type is unsupported");Ei("ipns record for %s is valid",t.value)};async function Rf(r,e){if(e.byteLength>Cm)throw new si("The record is too large");let t=Nt(r),n;vi(t,0)&&(n=Yo(t));let o=dt(e),i=Cf(o)??n;if(i==null)throw new vn("Could not extract public key from IPNS record or routing key");let s=In(i.toMultihash());if(!ce(r,s))throw new vn("Embedded public key did not match routing key");await Tm(i,e)}async function*kn(r){let e=/\r?\n/,t=new TextDecoder("utf8"),n="";for await(let o of r){typeof o=="string"&&(o=new TextEncoder().encode(o)),n+=t.decode(o,{stream:!0});let i=n.split(e);n=i.pop()??"";for(let s=0;s<i.length;s++)yield JSON.parse(i[s])}n+=t.decode(),n!==""&&(yield JSON.parse(n))}function ht(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Aa=_n(Lf(),1);var Tn=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Sa=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Vf=r=>globalThis.DOMException===void 0?new Sa(r):new DOMException(r),Pf=r=>{let e=r.reason===void 0?Vf("This operation was aborted."):r.reason;return e instanceof Error?e:Vf(e)};function Ia(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,c=new Promise((f,u)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:d}=e;d.aborted&&u(Pf(d));let b=()=>{u(Pf(d))};d.addEventListener("abort",b,{once:!0}),r.finally(()=>{d.removeEventListener("abort",b)})}if(t===Number.POSITIVE_INFINITY){r.then(f,u);return}let l=new Tn;s=i.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(d){u(d)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?f():o instanceof Error?u(o):(l.message=o??`Promise timed out after ${t} milliseconds`,u(l))},t),(async()=>{try{f(await r)}catch(d){u(d)}})()}).finally(()=>{c.clear()});return c.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},c}function ka(r,e,t){let n=0,o=r.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;t(r[s],e)<=0?(n=++s,o-=i+1):o=i}return n}var Nn=class{#e=[];enqueue(e,t){t={priority:0,...t};let n={priority:t.priority,run:e};if(this.size&&this.#e[this.size-1].priority>=t.priority){this.#e.push(n);return}let o=ka(this.#e,n,(i,s)=>s.priority-i.priority);this.#e.splice(o,0,n)}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(t=>t.priority===e.priority).map(t=>t.run)}get size(){return this.#e.length}};var Un=class extends Aa.default{#e;#t;#i=0;#a;#c;#p=0;#n;#u;#r;#m;#o=0;#l;#s;#g;timeout;constructor(e){if(super(),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Nn,...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.#a=e.intervalCap,this.#c=e.interval,this.#r=new e.queueClass,this.#m=e.queueClass,this.concurrency=e.concurrency,this.timeout=e.timeout,this.#g=e.throwOnTimeout===!0,this.#s=e.autoStart===!1}get#x(){return this.#t||this.#i<this.#a}get#b(){return this.#o<this.#l}#v(){this.#o--,this.#f(),this.emit("next")}#E(){this.#w(),this.#y(),this.#u=void 0}get#B(){let e=Date.now();if(this.#n===void 0){let t=this.#p-e;if(t<0)this.#i=this.#e?this.#o:0;else return this.#u===void 0&&(this.#u=setTimeout(()=>{this.#E()},t)),!0}return!1}#f(){if(this.#r.size===0)return this.#n&&clearInterval(this.#n),this.#n=void 0,this.emit("empty"),this.#o===0&&this.emit("idle"),!1;if(!this.#s){let e=!this.#B;if(this.#x&&this.#b){let t=this.#r.dequeue();return t?(this.emit("active"),t(),e&&this.#y(),!0):!1}}return!1}#y(){this.#t||this.#n!==void 0||(this.#n=setInterval(()=>{this.#w()},this.#c),this.#p=Date.now()+this.#c)}#w(){this.#i===0&&this.#o===0&&this.#n&&(clearInterval(this.#n),this.#n=void 0),this.#i=this.#e?this.#o:0,this.#d()}#d(){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.#d()}async#A(e){return new Promise((t,n)=>{e.addEventListener("abort",()=>{n(e.reason)},{once:!0})})}async add(e,t={}){return t={timeout:this.timeout,throwOnTimeout:this.#g,...t},new Promise((n,o)=>{this.#r.enqueue(async()=>{this.#o++,this.#i++;try{t.signal?.throwIfAborted();let i=e({signal:t.signal});t.timeout&&(i=Ia(Promise.resolve(i),{milliseconds:t.timeout})),t.signal&&(i=Promise.race([i,this.#A(t.signal)]));let s=await i;n(s),this.emit("completed",s)}catch(i){if(i instanceof Tn&&!t.throwOnTimeout){n();return}o(i),this.emit("error",i)}finally{this.#v()}},t),this.emit("add"),this.#f()})}async addAll(e,t){return Promise.all(e.map(async n=>this.add(n,t)))}start(){return this.#s?(this.#s=!1,this.#d(),this):this}pause(){this.#s=!0}clear(){this.#r=new this.#m}async onEmpty(){this.#r.size!==0&&await this.#h("empty")}async onSizeLessThan(e){this.#r.size<e||await this.#h("next",()=>this.#r.size<e)}async onIdle(){this.#o===0&&this.#r.size===0||await this.#h("idle")}async#h(e,t){return new Promise(n=>{let o=()=>{t&&!t()||(this.off(e,o),n())};this.on(e,o)})}get size(){return this.#r.size}sizeBy(e){return this.#r.filter(e).length}get pending(){return this.#o}get isPaused(){return this.#s}};var zr=class extends Error{static name="InvalidRequestError";constructor(e="Invalid request"){super(e),this.name="InvalidRequestError"}},ur=class extends Error{static name="BadResponseError";constructor(e="Bad response"){super(e),this.name="BadResponseError"}};function Rm(r){return r[Symbol.asyncIterator]!=null}function _m(r){if(Rm(r))return(async()=>{for await(let e of r)return e})();for(let e of r)return e}var Ai=_m;function Lm(r){let[e,t]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[t](){return this}}}var Ff=Lm;function Vm(r){return r[Symbol.asyncIterator]!=null}function Pm(r,e){let t=0;if(Vm(r))return async function*(){for await(let c of r)yield e(c,t++)}();let n=Ff(r),{value:o,done:i}=n.next();if(i===!0)return function*(){}();let s=e(o,t++);if(typeof s.then=="function")return async function*(){yield await s;for await(let c of n)yield e(c,t++)}();let a=e;return function*(){yield s;for(let c of n)yield a(c,t++)}()}var Si=Pm;var Of=Z("/ipns/");function Df(r){return ce(r.subarray(0,Of.byteLength),Of)}var Ii=class{client;constructor(e){this.client=e}async*findProviders(e,t={}){yield*Si(this.client.getProviders(e,t),n=>({id:n.ID,multiaddrs:n.Addrs??[]}))}async provide(){}async put(e,t,n){if(!Df(e))return;let o=Nt(e),i=X.createV1(114,o),s=dt(t);await this.client.putIPNS(i,s,n)}async get(e,t){if(!Df(e))throw new Re("Not found");let n=Nt(e),o=X.createV1(114,n);try{let i=await this.client.getIPNS(o,t);return cr(i)}catch(i){throw i.name==="BadResponseError"?new Re("Not found"):i}}},ki=class{client;constructor(e){this.client=e}async findPeer(e,t={}){let n=await Ai(this.client.getPeers(e,t));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new Re("Not found")}async*getClosestPeers(e,t={}){}};var Ne=Rt("delegated-routing-v1-http-api-client"),Mf={concurrentRequests:4,timeout:3e4},Ci=class{started;httpQueue;shutDownController;clientUrl;timeout;contentRouting;peerRouting;filterAddrs;filterProtocols;constructor(e,t={}){this.started=!1,this.shutDownController=new AbortController,hr(1/0,this.shutDownController.signal),this.httpQueue=new Un({concurrency:t.concurrentRequests??Mf.concurrentRequests}),this.clientUrl=e instanceof URL?e:new URL(e),this.timeout=t.timeout??Mf.timeout,this.filterAddrs=t.filterAddrs,this.filterProtocols=t.filterProtocols,this.contentRouting=new Ii(this),this.peerRouting=new ki(this)}get[ja](){return this.contentRouting}get[Ga](){return this.peerRouting}isStarted(){return this.started}start(){this.started=!0}stop(){this.httpQueue.clear(),this.shutDownController.abort(),this.started=!1}async*getProviders(e,t={}){Ne("getProviders starts: %c",e);let n=AbortSignal.timeout(this.timeout),o=bn([this.shutDownController.signal,n,t.signal]);hr(1/0,n,o);let i=ht(),s=ht();this.httpQueue.add(async()=>(i.resolve(),s.promise));try{await i.promise;let a=new URL(`${this.clientUrl}routing/v1/providers/${e.toString()}`);this.#t(a,t.filterAddrs,t.filterProtocols);let f=await fetch(a,{headers:{Accept:"application/x-ndjson"},signal:o});if(f.status===404)throw new Re("No matching records found");if(f.status===422)throw new zr("Request does not conform to schema or semantic constraints");if(f.body==null)throw new ur("Routing response had no body");if(f.headers.get("Content-Type")==="application/json"){let l=await f.json();for(let d of l.Providers){let b=this.#e(d);b!=null&&(yield b)}}else for await(let l of kn(oi(f.body))){let d=this.#e(l);d!=null&&(yield d)}}catch(a){Ne.error("getProviders errored:",a)}finally{o.clear(),s.resolve(),Ne("getProviders finished: %c",e)}}async*getPeers(e,t={}){Ne("getPeers starts: %c",e);let n=AbortSignal.timeout(this.timeout),o=bn([this.shutDownController.signal,n,t.signal]);hr(1/0,n,o);let i=ht(),s=ht();this.httpQueue.add(async()=>(i.resolve(),s.promise));try{await i.promise;let a=new URL(`${this.clientUrl}routing/v1/peers/${e.toCID().toString()}`);this.#t(a,t.filterAddrs,t.filterProtocols);let f=await fetch(a,{headers:{Accept:"application/x-ndjson"},signal:o});if(f.status===404)throw new Re("No matching records found");if(f.status===422)throw new zr("Request does not conform to schema or semantic constraints");if(f.body==null)throw new ur("Routing response had no body");if(f.headers.get("Content-Type")==="application/json"){let l=await f.json();for(let d of l.Peers){let b=this.#e(d);b!=null&&(yield b)}}else for await(let l of kn(oi(f.body))){let d=this.#e(l);d!=null&&(yield d)}}catch(a){Ne.error("getPeers errored:",a)}finally{o.clear(),s.resolve(),Ne("getPeers finished: %c",e)}}async getIPNS(e,t={}){Ne("getIPNS starts: %s",e);let n=AbortSignal.timeout(this.timeout),o=bn([this.shutDownController.signal,n,t.signal]);hr(1/0,n,o);let i=ht(),s=ht();this.httpQueue.add(async()=>(i.resolve(),s.promise));let a=`${this.clientUrl}routing/v1/ipns/${e}`;try{await i.promise;let f=await fetch(a,{headers:{Accept:"application/vnd.ipfs.ipns-record"},signal:o});if(Ne("getIPNS GET %s %d",a,f.status),f.status===404)throw new Re("No matching records found");if(f.status===422)throw new zr("Request does not conform to schema or semantic constraints");if(f.body==null)throw new ur("GET ipns response had no body");let u=await f.arrayBuffer(),l=new Uint8Array(u,0,u.byteLength);return t.validate!==!1&&await Rf(In(e.multihash),l),dt(l)}catch(c){throw Ne.error("getIPNS GET %s error:",a,c),c}finally{o.clear(),s.resolve(),Ne("getIPNS finished: %s",e)}}async putIPNS(e,t,n={}){Ne("putIPNS starts: %c",e);let o=AbortSignal.timeout(this.timeout),i=bn([this.shutDownController.signal,o,n.signal]);hr(1/0,o,i);let s=ht(),a=ht();this.httpQueue.add(async()=>(s.resolve(),a.promise));let c=`${this.clientUrl}routing/v1/ipns/${e}`;try{await s.promise;let f=cr(t),l=await fetch(c,{method:"PUT",headers:{"Content-Type":"application/vnd.ipfs.ipns-record"},body:f,signal:i});if(Ne("putIPNS PUT %s %d",c,l.status),l.status!==200)throw new ur("PUT ipns response had status other than 200")}catch(f){throw Ne.error("putIPNS PUT %s error:",c,f.stack),f}finally{i.clear(),a.resolve(),Ne("putIPNS finished: %c",e)}}#e(e){try{let t=[],n=e.Addrs?.map(sr)??[];return e.Protocols!=null&&t.push(...e.Protocols),e.Protocol!=null&&(t.push(e.Protocol),delete e.Protocol),{...e,Schema:"peer",ID:il(e.ID),Addrs:n,Protocols:t}}catch(t){Ne.error("could not conform record to peer schema",t)}}#t(e,t,n){if(t!=null||this.filterAddrs!=null){let o=t?.join(",")??this.filterAddrs?.join(",")??"";o!==""&&e.searchParams.set("filter-addrs",o)}if(n!=null||this.filterProtocols!=null){let o=n?.join(",")??this.filterProtocols?.join(",")??"";o!==""&&e.searchParams.set("filter-protocols",o)}}};function $f(r,e={}){return new Ci(new URL(r),e)}function Hf(){return{filterProtocols:["unknown","transport-bitswap","transport-ipfs-gateway-http"],filterAddrs:["https","webtransport","webrtc","webrtc-direct","wss"]}}var Kf=Z("/ipns/");function qf(r){return ce(r.subarray(0,Kf.byteLength),Kf)}var Ca=class{client;constructor(e,t={}){this.client=$f(e,t)}async provide(e,t){}async*findProviders(e,t){yield*Si(this.client.getProviders(e,t),n=>({id:n.ID,multiaddrs:n.Addrs,protocols:n.Protocols}))}async put(e,t,n){if(!qf(e))return;let o=Nt(e),i=X.createV1(114,o),s=dt(t);await this.client.putIPNS(i,s,n)}async get(e,t){if(!qf(e))throw new Re("Not found");let n=Nt(e),o=X.createV1(114,n);try{let i=await this.client.getIPNS(o,t);return cr(i)}catch(i){throw i.name==="BadResponseError"?new Re("Not found"):i}}async findPeer(e,t){let n=await Ai(this.client.getPeers(e,t));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new Re("Not found")}async*getClosestPeers(e,t){}};function zf(r,e){let t=e??Hf();return new Ca(new URL(r),t)}var jf="[a-fA-F\\d:]",Zt=r=>r&&r.includeBoundaries?`(?:(?<=\\s|^)(?=${jf})|(?<=${jf})(?=\\s|$))`:"",st="(?: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}",ue="[a-fA-F\\d]{1,4}",Ti=`
7
+ `)}`:`${t} :`}};nu=qt;_.Constructed=nu;qt.NAME="CONSTRUCTED";var fo=class extends Ae{fromBER(e,t,n){return t}toBER(e){return tt}};fo.override="EndOfContentValueBlock";var ou,ho=class extends we{constructor(e={}){super(e,fo),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};ou=ho;_.EndOfContent=ou;ho.NAME=un;var iu,Ur=class extends we{constructor(e={}){super(e,Ae),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(e,t,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,t+n>e.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):t+n}toBER(e,t){let n=new ArrayBuffer(2);if(!e){let o=new Uint8Array(n);o[0]=5,o[1]=0}return t&&t.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};iu=Ur;_.Null=iu;Ur.NAME="NULL";var po=class extends It(Ae){constructor({value:e,...t}={}){super(t),t.valueHex?this.valueHexView=j.BufferSourceConverter.toUint8Array(t.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,t,n){let o=j.BufferSourceConverter.toUint8Array(e);return St(this,o,t,n)?(this.valueHexView=o.subarray(t,t+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,$s.call(this),this.blockLength=n,t+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};po.NAME="BooleanValueBlock";var su,mo=class extends we{constructor(e={}){super(e,po),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}`}};su=mo;_.Boolean=su;mo.NAME="BOOLEAN";var go=class extends It(ut){constructor({isConstructed:e=!1,...t}={}){super(t),this.isConstructed=e}fromBER(e,t,n){let o=0;if(this.isConstructed){if(this.isHexOnly=!1,o=ut.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let i=0;i<this.value.length;i++){let s=this.value[i].constructor.NAME;if(s===un){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(s!==Qc)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,o=super.fromBER(e,t,n),this.blockLength=n;return o}toBER(e,t){return this.isConstructed?ut.prototype.toBER.call(this,e,t):e?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};go.NAME="OctetStringValueBlock";var au,yo=class r extends we{constructor({idBlock:e={},lenBlock:t={},...n}={}){var o,i;(o=n.isConstructed)!==null&&o!==void 0||(n.isConstructed=!!(!((i=n.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},go),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(e,t,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),t;if(!this.valueBlock.isConstructed){let i=(e instanceof ArrayBuffer?new Uint8Array(e):e).subarray(t,t+n);try{if(i.byteLength){let s=zo(i,0,i.byteLength);s.offset!==-1&&s.offset===n&&(this.valueBlock.value=[s.result])}}catch{}}return super.fromBER(e,t,n)}onAsciiEncoding(){return this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length?qt.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${j.Convert.ToHex(this.valueBlock.valueHexView)}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let e=[];for(let t of this.valueBlock.value)t instanceof r&&e.push(t.valueBlock.valueHexView);return j.BufferSourceConverter.concat(e)}};au=yo;_.OctetString=au;yo.NAME=Qc;var wo=class extends It(ut){constructor({unusedBits:e=0,isConstructed:t=!1,...n}={}){super(n),this.unusedBits=e,this.isConstructed=t,this.blockLength=this.valueHexView.byteLength}fromBER(e,t,n){if(!n)return t;let o=-1;if(this.isConstructed){if(o=ut.prototype.fromBER.call(this,e,t,n),o===-1)return o;for(let a of this.value){let c=a.constructor.NAME;if(c===un){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==eu)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let f=a.valueBlock;if(this.unusedBits>0&&f.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=f.unusedBits}return o}let i=j.BufferSourceConverter.toUint8Array(e);if(!St(this,i,t,n))return-1;let s=i.subarray(t,t+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=zo(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,t+n}toBER(e,t){if(this.isConstructed)return ut.prototype.toBER.call(this,e,t);if(e)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return tt;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}}};wo.NAME="BitStringValueBlock";var cu,Rr=class extends we{constructor({idBlock:e={},lenBlock:t={},...n}={}){var o,i;(o=n.isConstructed)!==null&&o!==void 0||(n.isConstructed=!!(!((i=n.value)===null||i===void 0)&&i.length)),super({idBlock:{isConstructed:n.isConstructed,...e},lenBlock:{...t,isIndefiniteForm:!!n.isIndefiniteForm},...n},wo),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(e,t,n){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(e,t,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return qt.prototype.onAsciiEncoding.call(this);{let e=[],t=this.valueBlock.valueHexView;for(let o of t)e.push(o.toString(2).padStart(8,"0"));let n=e.join("");return`${this.constructor.NAME} : ${n.substring(0,n.length-this.valueBlock.unusedBits)}`}}};cu=Rr;_.BitString=cu;Rr.NAME=eu;var uu;function ap(r,e){let t=new Uint8Array([0]),n=new Uint8Array(r),o=new Uint8Array(e),i=n.slice(0),s=i.length-1,a=o.slice(0),c=a.length-1,f=0,u=c<s?s:c,l=0;for(let d=u;d>=0;d--,l++){switch(!0){case l<a.length:f=i[s-l]+a[c-l]+t[0];break;default:f=i[s-l]+t[0]}switch(t[0]=f/10,!0){case l>=i.length:i=oo(new Uint8Array([f%10]),i);break;default:i[s-l]=f%10}}return t[0]>0&&(i=oo(t,i)),i}function Xc(r){if(r>=an.length)for(let e=an.length;e<=r;e++){let t=new Uint8Array([0]),n=an[e-1].slice(0);for(let o=n.length-1;o>=0;o--){let i=new Uint8Array([(n[o]<<1)+t[0]]);t[0]=i[0]/10,n[o]=i[0]%10}t[0]>0&&(n=oo(t,n)),an.push(n)}return an[r]}function cp(r,e){let t=0,n=new Uint8Array(r),o=new Uint8Array(e),i=n.slice(0),s=i.length-1,a=o.slice(0),c=a.length-1,f,u=0;for(let l=c;l>=0;l--,u++)switch(f=i[s-u]-a[c-u]-t,!0){case f<0:t=1,i[s-u]=f+10;break;default:t=0,i[s-u]=f}if(t>0)for(let l=s-c+1;l>=0;l--,u++)if(f=i[s-u]-t,f<0)t=1,i[s-u]=f+10;else{t=0,i[s-u]=f;break}return i.slice()}var ln=class extends It(Ae){constructor({value:e,...t}={}){super(t),this._valueDec=0,t.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=$s.call(this)))}set valueDec(e){this._valueDec=e,this.isHexOnly=!1,this.valueHexView=new Uint8Array(Wc(e))}get valueDec(){return this._valueDec}fromDER(e,t,n,o=0){let i=this.fromBER(e,t,n);if(i===-1)return i;let s=this.valueHexView;return s[0]===0&&s[1]&128?this.valueHexView=s.subarray(1):o!==0&&s.length<o&&(o-s.length>1&&(o=s.length+1),this.valueHexView=s.subarray(o-s.length)),i}toDER(e=!1){let t=this.valueHexView;switch(!0){case(t[0]&128)!==0:{let n=new Uint8Array(this.valueHexView.length+1);n[0]=0,n.set(t,1),this.valueHexView=n}break;case(t[0]===0&&(t[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(e)}fromBER(e,t,n){let o=super.fromBER(e,t,n);return o===-1||this.setValueHex(),o}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,t=new Uint8Array(this.valueHexView.length*8/3),n=0,o,i=this.valueHexView,s="",a=!1;for(let c=i.byteLength-1;c>=0;c--){o=i[c];for(let f=0;f<8;f++){if((o&1)===1)switch(n){case e:t=cp(Xc(n),t),s="-";break;default:t=ap(t,Xc(n))}n++,o>>=1}}for(let c=0;c<t.length;c++)t[c]&&(a=!0),a&&(s+=Jc.charAt(t[c]));return a===!1&&(s+=Jc.charAt(0)),s}};uu=ln;ln.NAME="IntegerValueBlock";Object.defineProperty(uu.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var lu,xe=class r extends we{constructor(e={}){super(e,ln),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return io(),BigInt(this.valueBlock.toString())}static fromBigInt(e){io();let t=BigInt(e),n=new cn,o=t.toString(16).replace(/^-/,""),i=new Uint8Array(j.Convert.FromHex(o));if(t<0){let a=new Uint8Array(i.length+(i[0]&128?1:0));a[0]|=128;let f=BigInt(`0x${j.Convert.ToHex(a)}`)+t,u=j.BufferSourceConverter.toUint8Array(j.Convert.FromHex(f.toString(16)));u[0]|=128,n.write(u)}else i[0]&128&&n.write(new Uint8Array([0])),n.write(i);return new r({valueHex:n.final()})}convertToDER(){let e=new r({valueHex:this.valueBlock.valueHexView});return e.valueBlock.toDER(),e}convertFromDER(){return new r({valueHex:this.valueBlock.valueHexView[0]===0?this.valueBlock.valueHexView.subarray(1):this.valueBlock.valueHexView})}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()}`}};lu=xe;_.Integer=lu;xe.NAME="INTEGER";var fu,xo=class extends xe{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};fu=xo;_.Enumerated=fu;xo.NAME="ENUMERATED";var fn=class extends It(Ae){constructor({valueDec:e=-1,isFirstSid:t=!1,...n}={}){super(n),this.valueDec=e,this.isFirstSid=t}fromBER(e,t,n){if(!n)return t;let o=j.BufferSourceConverter.toUint8Array(e);if(!St(this,o,t,n))return-1;let i=o.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=i[a]&127,this.blockLength++,!!(i[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,i[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=or(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}set valueBigInt(e){io();let t=BigInt(e).toString(2);for(;t.length%7;)t="0"+t;let n=new Uint8Array(t.length/7);for(let o=0;o<n.length;o++)n[o]=parseInt(t.slice(o*7,o*7+7),2)+(o+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 o=this.valueHexView,i=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)i[s]=o[s]|128;return i[this.blockLength-1]=o[this.blockLength-1],i.buffer}let t=Kt(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",tt;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n}toString(){let e="";if(this.isHexOnly)e=j.Convert.ToHex(this.valueHexView);else if(this.isFirstSid){let t=this.valueDec;this.valueDec<=39?e="0.":this.valueDec<=79?(e="1.",t-=40):(e="2.",t-=80),e+=t.toString()}else e=this.valueDec.toString();return e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}};fn.NAME="sidBlock";var bo=class extends Ae{constructor({value:e=Lr,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new fn;if(o=i.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=i.error,o;this.value.length===0&&(i.isFirstSid=!0),this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return o}toBER(e){let t=[];for(let n=0;n<this.value.length;n++){let o=this.value[n].toBER(e);if(o.byteLength===0)return this.error=this.value[n].error,tt;t.push(o)}return Hs(t)}fromString(e){this.value=[];let t=0,n=0,o="",i=!1;do if(n=e.indexOf(".",t),n===-1?o=e.substring(t):o=e.substring(t,n),t=n+1,i){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(o,10);if(isNaN(c))return;s.valueDec=c+a,i=!1}else{let s=new fn;if(o>Number.MAX_SAFE_INTEGER){io();let a=BigInt(o);s.valueBigInt=a}else if(s.valueDec=parseInt(o,10),isNaN(s.valueDec))return;this.value.length||(s.isFirstSid=!0,i=!0),this.value.push(s)}while(n!==-1)}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let o=this.value[n].toString();n!==0&&(e=`${e}.`),t?(o=`{${o}}`,this.value[n].isFirstSid?e=`2.{${o} - 80}`:e+=o):e+=o}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};bo.NAME="ObjectIdentifierValueBlock";var du,_r=class extends we{constructor(e={}){super(e,bo),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()}}};du=_r;_.ObjectIdentifier=du;_r.NAME="OBJECT IDENTIFIER";var dn=class extends It(Et){constructor({valueDec:e=0,...t}={}){super(t),this.valueDec=e}fromBER(e,t,n){if(n===0)return t;let o=j.BufferSourceConverter.toUint8Array(e);if(!St(this,o,t,n))return-1;let i=o.subarray(t,t+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=i[a]&127,this.blockLength++,!!(i[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,i[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=or(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),t+this.blockLength)}toBER(e){if(this.isHexOnly){if(e)return new ArrayBuffer(this.valueHexView.byteLength);let o=this.valueHexView,i=new Uint8Array(this.blockLength);for(let s=0;s<this.blockLength-1;s++)i[s]=o[s]|128;return i[this.blockLength-1]=o[this.blockLength-1],i.buffer}let t=Kt(this.valueDec,7);if(t.byteLength===0)return this.error="Error during encoding SID value",tt;let n=new Uint8Array(t.byteLength);if(!e){let o=new Uint8Array(t),i=t.byteLength-1;for(let s=0;s<i;s++)n[s]=o[s]|128;n[i]=o[i]}return n.buffer}toString(){let e="";return this.isHexOnly?e=j.Convert.ToHex(this.valueHexView):e=this.valueDec.toString(),e}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};dn.NAME="relativeSidBlock";var vo=class extends Ae{constructor({value:e=Lr,...t}={}){super(t),this.value=[],e&&this.fromString(e)}fromBER(e,t,n){let o=t;for(;n>0;){let i=new dn;if(o=i.fromBER(e,o,n),o===-1)return this.blockLength=0,this.error=i.error,o;this.blockLength+=i.blockLength,n-=i.blockLength,this.value.push(i)}return o}toBER(e,t){let n=[];for(let o=0;o<this.value.length;o++){let i=this.value[o].toBER(e);if(i.byteLength===0)return this.error=this.value[o].error,tt;n.push(i)}return Hs(n)}fromString(e){this.value=[];let t=0,n=0,o="";do{n=e.indexOf(".",t),n===-1?o=e.substring(t):o=e.substring(t,n),t=n+1;let i=new dn;if(i.valueDec=parseInt(o,10),isNaN(i.valueDec))return!0;this.value.push(i)}while(n!==-1);return!0}toString(){let e="",t=!1;for(let n=0;n<this.value.length;n++){t=this.value[n].isHexOnly;let o=this.value[n].toString();n!==0&&(e=`${e}.`),t&&(o=`{${o}}`),e+=o}return e}toJSON(){let e={...super.toJSON(),value:this.toString(),sidArray:[]};for(let t=0;t<this.value.length;t++)e.sidArray.push(this.value[t].toJSON());return e}};vo.NAME="RelativeObjectIdentifierValueBlock";var hu,Eo=class extends we{constructor(e={}){super(e,vo),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()}}};hu=Eo;_.RelativeObjectIdentifier=hu;Eo.NAME="RelativeObjectIdentifier";var pu,Bt=class extends qt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};pu=Bt;_.Sequence=pu;Bt.NAME="SEQUENCE";var mu,Bo=class extends qt{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};mu=Bo;_.Set=mu;Bo.NAME="SET";var Ao=class extends It(Ae){constructor({...e}={}){super(e),this.isHexOnly=!0,this.value=Lr}toJSON(){return{...super.toJSON(),value:this.value}}};Ao.NAME="StringValueBlock";var So=class extends Ao{};So.NAME="SimpleStringValueBlock";var Ce=class extends co{constructor({...e}={}){super(e,So)}fromBuffer(e){this.valueBlock.value=String.fromCharCode.apply(null,j.BufferSourceConverter.toUint8Array(e))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);this.valueBlock.value=e}};Ce.NAME="SIMPLE STRING";var Io=class extends Ce{fromBuffer(e){this.valueBlock.valueHexView=j.BufferSourceConverter.toUint8Array(e);try{this.valueBlock.value=j.Convert.ToUtf8String(e)}catch(t){this.warnings.push(`Error during "decodeURIComponent": ${t}, using raw string`),this.valueBlock.value=j.Convert.ToBinary(e)}}fromString(e){this.valueBlock.valueHexView=new Uint8Array(j.Convert.FromUtf8String(e)),this.valueBlock.value=e}};Io.NAME="Utf8StringValueBlock";var gu,At=class extends Io{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};gu=At;_.Utf8String=gu;At.NAME="UTF8String";var ko=class extends Ce{fromBuffer(e){this.valueBlock.value=j.Convert.ToUtf16String(e),this.valueBlock.valueHexView=j.BufferSourceConverter.toUint8Array(e)}fromString(e){this.valueBlock.value=e,this.valueBlock.valueHexView=new Uint8Array(j.Convert.FromUtf16String(e))}};ko.NAME="BmpStringValueBlock";var yu,Co=class extends ko{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};yu=Co;_.BmpString=yu;Co.NAME="BMPString";var To=class extends Ce{fromBuffer(e){let t=ArrayBuffer.isView(e)?e.slice().buffer:e.slice(0),n=new Uint8Array(t);for(let o=0;o<n.length;o+=4)n[o]=n[o+3],n[o+1]=n[o+2],n[o+2]=0,n[o+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(t))}fromString(e){let t=e.length,n=this.valueBlock.valueHexView=new Uint8Array(t*4);for(let o=0;o<t;o++){let i=Kt(e.charCodeAt(o),8),s=new Uint8Array(i);if(s.length>4)continue;let a=4-s.length;for(let c=s.length-1;c>=0;c--)n[o*4+c+a]=s[c]}this.valueBlock.value=e}};To.NAME="UniversalStringValueBlock";var wu,No=class extends To{constructor({...e}={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};wu=No;_.UniversalString=wu;No.NAME="UniversalString";var xu,Uo=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};xu=Uo;_.NumericString=xu;Uo.NAME="NumericString";var bu,Ro=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};bu=Ro;_.PrintableString=bu;Ro.NAME="PrintableString";var vu,_o=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};vu=_o;_.TeletexString=vu;_o.NAME="TeletexString";var Eu,Lo=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};Eu=Lo;_.VideotexString=Eu;Lo.NAME="VideotexString";var Bu,Vo=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};Bu=Vo;_.IA5String=Bu;Vo.NAME="IA5String";var Au,Po=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};Au=Po;_.GraphicString=Au;Po.NAME="GraphicString";var Su,hn=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};Su=hn;_.VisibleString=Su;hn.NAME="VisibleString";var Iu,Fo=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};Iu=Fo;_.GeneralString=Iu;Fo.NAME="GeneralString";var ku,Oo=class extends Ce{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};ku=Oo;_.CharacterString=ku;Oo.NAME="CharacterString";var Cu,pn=class extends hn{constructor({value:e,valueDate:t,...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 o=0;o<e.length;o++)this.valueBlock.valueHexView[o]=e.charCodeAt(o)}t&&(this.fromDate(t),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(e){this.fromString(String.fromCharCode.apply(null,j.BufferSourceConverter.toUint8Array(e)))}toBuffer(){let e=this.toString(),t=new ArrayBuffer(e.length),n=new Uint8Array(t);for(let o=0;o<e.length;o++)n[o]=e.charCodeAt(o);return t}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 o=parseInt(n[1],10);o>=50?this.year=1900+o:this.year=2e3+o,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 t=new Array(7);return t[0]=Fe(this.year<2e3?this.year-1900:this.year-2e3,2),t[1]=Fe(this.month,2),t[2]=Fe(this.day,2),t[3]=Fe(this.hour,2),t[4]=Fe(this.minute,2),t[5]=Fe(this.second,2),t[6]="Z",t.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}}};Cu=pn;_.UTCTime=Cu;pn.NAME="UTCTime";var Tu,Do=class extends pn{constructor(e={}){var t;super(e),(t=this.millisecond)!==null&&t!==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 t=!1,n="",o="",i=0,s,a=0,c=0;if(e[e.length-1]==="Z")n=e.substring(0,e.length-1),t=!0;else{let l=new Number(e[e.length-1]);if(isNaN(l.valueOf()))throw new Error("Wrong input string for conversion");n=e}if(t){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 l=1,d=n.indexOf("+"),b="";if(d===-1&&(d=n.indexOf("-"),l=-1),d!==-1){if(b=n.substring(d+1),n=n.substring(0,d),b.length!==2&&b.length!==4)throw new Error("Wrong input string for conversion");let I=parseInt(b.substring(0,2),10);if(isNaN(I.valueOf()))throw new Error("Wrong input string for conversion");if(a=l*I,b.length===4){if(I=parseInt(b.substring(2,4),10),isNaN(I.valueOf()))throw new Error("Wrong input string for conversion");c=l*I}}}let f=n.indexOf(".");if(f===-1&&(f=n.indexOf(",")),f!==-1){let l=new Number(`0${n.substring(f)}`);if(isNaN(l.valueOf()))throw new Error("Wrong input string for conversion");i=l.valueOf(),o=n.substring(0,f)}else o=n;switch(!0){case o.length===8:if(s=/(\d{4})(\d{2})(\d{2})/ig,f!==-1)throw new Error("Wrong input string for conversion");break;case o.length===10:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let l=60*i;this.minute=Math.floor(l),l=60*(l-this.minute),this.second=Math.floor(l),l=1e3*(l-this.second),this.millisecond=Math.floor(l)}break;case o.length===12:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let l=60*i;this.second=Math.floor(l),l=1e3*(l-this.second),this.millisecond=Math.floor(l)}break;case o.length===14:if(s=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,f!==-1){let l=1e3*i;this.millisecond=Math.floor(l)}break;default:throw new Error("Wrong input string for conversion")}let u=s.exec(o);if(u===null)throw new Error("Wrong input string for conversion");for(let l=1;l<u.length;l++)switch(l){case 1:this.year=parseInt(u[l],10);break;case 2:this.month=parseInt(u[l],10);break;case 3:this.day=parseInt(u[l],10);break;case 4:this.hour=parseInt(u[l],10)+a;break;case 5:this.minute=parseInt(u[l],10)+c;break;case 6:this.second=parseInt(u[l],10);break;default:throw new Error("Wrong input string for conversion")}if(t===!1){let l=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=l.getUTCFullYear(),this.month=l.getUTCMonth(),this.day=l.getUTCDay(),this.hour=l.getUTCHours(),this.minute=l.getUTCMinutes(),this.second=l.getUTCSeconds(),this.millisecond=l.getUTCMilliseconds()}}toString(e="iso"){if(e==="iso"){let t=[];return t.push(Fe(this.year,4)),t.push(Fe(this.month,2)),t.push(Fe(this.day,2)),t.push(Fe(this.hour,2)),t.push(Fe(this.minute,2)),t.push(Fe(this.second,2)),this.millisecond!==0&&(t.push("."),t.push(Fe(this.millisecond,3))),t.push("Z"),t.join("")}return super.toString(e)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};Tu=Do;_.GeneralizedTime=Tu;Do.NAME="GeneralizedTime";var Nu,Mo=class extends At{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};Nu=Mo;_.DATE=Nu;Mo.NAME="DATE";var Uu,$o=class extends At{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};Uu=$o;_.TimeOfDay=Uu;$o.NAME="TimeOfDay";var Ru,Ho=class extends At{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};Ru=Ho;_.DateTime=Ru;Ho.NAME="DateTime";var _u,Ko=class extends At{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};_u=Ko;_.Duration=_u;Ko.NAME="Duration";var Lu,qo=class extends At{constructor(e={}){super(e),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};Lu=qo;_.TIME=Lu;qo.NAME="TIME";function ne(r,e="utf8"){let t=Qn[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var mn=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},jo=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var Vu={get(r=globalThis){let e=r.crypto;if(e?.subtle==null)throw new jo("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");return e}};var zt=Vu;async function Pu(r){let e=await zt.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),t=await lp(e);return{privateKey:t[0],publicKey:t[1]}}async function Fu(r,e){let t=await zt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await zt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},t,e instanceof Uint8Array?e:e.subarray());return new Uint8Array(n,0,n.byteLength)}async function Ou(r,e,t){let n=await zt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return zt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,e,t instanceof Uint8Array?t:t.subarray())}async function lp(r){if(r.privateKey==null||r.publicKey==null)throw new ve("Private and public key are required");return Promise.all([zt.get().subtle.exportKey("jwk",r.privateKey),zt.get().subtle.exportKey("jwk",r.publicKey)])}function zs(r){if(r.kty!=="RSA")throw new ve("invalid key type");if(r.n==null)throw new ve("invalid key modulus");return Z(r.n,"base64url").length*8}var Vr=class{type="RSA";_key;_raw;_multihash;constructor(e,t){this._key=e,this._multihash=t}get raw(){return this._raw==null&&(this._raw=gn.jwkToPkix(this._key)),this._raw}toMultihash(){return this._multihash}toCID(){return X.createV1(114,this._multihash)}toString(){return re.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ce(this.raw,e.raw)}verify(e,t){return Ou(this._key,t,e)}},yn=class{type="RSA";_key;_raw;publicKey;constructor(e,t){this._key=e,this.publicKey=t}get raw(){return this._raw==null&&(this._raw=gn.jwkToPkcs1(this._key)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ce(this.raw,e.raw)}sign(e){return Fu(this._key,e)}};var Go=8192,js=18;function Du(r){let{result:e}=qs(r),t=e.valueBlock.value;return{n:lt(t[1]),e:lt(t[2]),d:lt(t[3]),p:lt(t[4]),q:lt(t[5]),dp:lt(t[6]),dq:lt(t[7]),qi:lt(t[8]),kty:"RSA",alg:"RS256"}}function fp(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new ve("JWK was missing components");let t=new Bt({value:[new xe({value:0}),xe.fromBigInt(ft(Z(r.n,"base64url"))),xe.fromBigInt(ft(Z(r.e,"base64url"))),xe.fromBigInt(ft(Z(r.d,"base64url"))),xe.fromBigInt(ft(Z(r.p,"base64url"))),xe.fromBigInt(ft(Z(r.q,"base64url"))),xe.fromBigInt(ft(Z(r.dp,"base64url"))),xe.fromBigInt(ft(Z(r.dq,"base64url"))),xe.fromBigInt(ft(Z(r.qi,"base64url")))]}).toBER();return new Uint8Array(t,0,t.byteLength)}function Mu(r){let{result:e}=qs(r),t=e.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:lt(t[0]),e:lt(t[1])}}function Gs(r){if(r.n==null||r.e==null)throw new ve("JWK was missing components");let t=new Bt({value:[new Bt({value:[new _r({value:"1.2.840.113549.1.1.1"}),new Ur]}),new Rr({valueHex:new Bt({value:[xe.fromBigInt(ft(Z(r.n,"base64url"))),xe.fromBigInt(ft(Z(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(t,0,t.byteLength)}function lt(r){let e=r.valueBlock.valueHexView;for(;e[0]===0;)e=e.subarray(1);return ne(e,"base64url")}function ft(r){let e=[];return r.forEach(function(t){let n=t.toString(16);n.length%2>0&&(n=`0${n}`),e.push(n)}),BigInt("0x"+e.join(""))}function $u(r){let e=Du(r);return Hu(e)}function Zs(r){let e=Mu(r);if(zs(e)>Go)throw new lr("Key size is too large");let t=Tr(ct.encode({Type:de.RSA,Data:r})),n=Ze(js,t);return new Vr(e,n)}function Hu(r){if(zs(r)>Go)throw new ve("Key size is too large");let e=qu(r),t=Tr(ct.encode({Type:de.RSA,Data:Gs(e.publicKey)})),n=Ze(js,t);return new yn(e.privateKey,new Vr(e.publicKey,n))}async function Ku(r){if(r>Go)throw new ve("Key size is too large");let e=await Pu(r),t=Tr(ct.encode({Type:de.RSA,Data:Gs(e.publicKey)})),n=Ze(js,t);return new yn(e.privateKey,new Vr(e.publicKey,n))}function qu(r){if(r==null)throw new ve("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}var Zo=class extends vr{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,dc(e);let n=Jr(t);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 o=this.blockLen,i=new Uint8Array(o);i.set(n.length>o?e.create().update(n).digest():n);for(let s=0;s<i.length;s++)i[s]^=54;this.iHash.update(i),this.oHash=e.create();for(let s=0;s<i.length;s++)i[s]^=106;this.oHash.update(i),i.fill(0)}update(e){return br(this),this.iHash.update(e),this}digestInto(e){br(this),xr(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:t,iHash:n,finished:o,destroyed:i,blockLen:s,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=i,e.blockLen=s,e.outputLen=a,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Ws=(r,e,t)=>new Zo(r,e).update(t).digest();Ws.create=(r,e)=>new Zo(r,e);function zu(r){r.lowS!==void 0&&Je("lowS",r.lowS),r.prehash!==void 0&&Je("prehash",r.prehash)}function dp(r){let e=en(r);at(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:t,Fp:n,a:o}=e;if(t){if(!n.eql(o,n.ZERO))throw new Error("Endomorphism can only be defined for Koblitz curves that have a=0");if(typeof t!="object"||typeof t.beta!="bigint"||typeof t.splitScalar!="function")throw new Error("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...e})}var{bytesToNumberBE:hp,hexToBytes:pp}=qn,kt={Err:class extends Error{constructor(e=""){super(e)}},_tlv:{encode:(r,e)=>{let{Err:t}=kt;if(r<0||r>256)throw new t("tlv.encode: wrong tag");if(e.length&1)throw new t("tlv.encode: unpadded data");let n=e.length/2,o=Yt(n);if(o.length/2&128)throw new t("tlv.encode: long form length too big");let i=n>127?Yt(o.length/2|128):"";return`${Yt(r)}${i}${o}${e}`},decode(r,e){let{Err:t}=kt,n=0;if(r<0||r>256)throw new t("tlv.encode: wrong tag");if(e.length<2||e[n++]!==r)throw new t("tlv.decode: wrong tlv");let o=e[n++],i=!!(o&128),s=0;if(!i)s=o;else{let c=o&127;if(!c)throw new t("tlv.decode(long): indefinite length not supported");if(c>4)throw new t("tlv.decode(long): byte length is too big");let f=e.subarray(n,n+c);if(f.length!==c)throw new t("tlv.decode: length bytes not complete");if(f[0]===0)throw new t("tlv.decode(long): zero leftmost byte");for(let u of f)s=s<<8|u;if(n+=c,s<128)throw new t("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+s);if(a.length!==s)throw new t("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+s)}}},_int:{encode(r){let{Err:e}=kt;if(r<Ct)throw new e("integer: negative integers are not allowed");let t=Yt(r);if(Number.parseInt(t[0],16)&8&&(t="00"+t),t.length&1)throw new e("unexpected assertion");return t},decode(r){let{Err:e}=kt;if(r[0]&128)throw new e("Invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new e("Invalid signature integer: unnecessary leading zero");return hp(r)}},toSig(r){let{Err:e,_int:t,_tlv:n}=kt,o=typeof r=="string"?pp(r):r;Br(o);let{v:i,l:s}=n.decode(48,o);if(s.length)throw new e("Invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,i),{v:f,l:u}=n.decode(2,c);if(u.length)throw new e("Invalid signature: left bytes after parsing");return{r:t.decode(a),s:t.decode(f)}},hexFromSig(r){let{_tlv:e,_int:t}=kt,n=`${e.encode(2,t.encode(r.r))}${e.encode(2,t.encode(r.s))}`;return e.encode(48,n)}},Ct=BigInt(0),me=BigInt(1),bx=BigInt(2),ju=BigInt(3),vx=BigInt(4);function mp(r){let e=dp(r),{Fp:t}=e,n=Dt(e.n,e.nBitLength),o=e.toBytes||((w,h,E)=>{let C=h.toAffine();return bt(Uint8Array.from([4]),t.toBytes(C.x),t.toBytes(C.y))}),i=e.fromBytes||(w=>{let h=w.subarray(1),E=t.fromBytes(h.subarray(0,t.BYTES)),C=t.fromBytes(h.subarray(t.BYTES,2*t.BYTES));return{x:E,y:C}});function s(w){let{a:h,b:E}=e,C=t.sqr(w),x=t.mul(C,w);return t.add(t.add(x,t.mul(w,h)),E)}if(!t.eql(t.sqr(e.Gy),s(e.Gx)))throw new Error("bad generator point: equation left != right");function a(w){return Xr(w,me,e.n)}function c(w){let{allowedPrivateKeyLengths:h,nByteLength:E,wrapPrivateKey:C,n:x}=e;if(h&&typeof w!="bigint"){if(Pt(w)&&(w=wt(w)),typeof w!="string"||!h.includes(w.length))throw new Error("Invalid key");w=w.padStart(E*2,"0")}let T;try{T=typeof w=="bigint"?w:xt(ae("private key",w,E))}catch{throw new Error(`private key must be ${E} bytes, hex or bigint, not ${typeof w}`)}return C&&(T=Q(T,x)),Le("private key",T,me,x),T}function f(w){if(!(w instanceof d))throw new Error("ProjectivePoint expected")}let u=Qt((w,h)=>{let{px:E,py:C,pz:x}=w;if(t.eql(x,t.ONE))return{x:E,y:C};let T=w.is0();h==null&&(h=T?t.ONE:t.inv(x));let F=t.mul(E,h),V=t.mul(C,h),U=t.mul(x,h);if(T)return{x:t.ZERO,y:t.ZERO};if(!t.eql(U,t.ONE))throw new Error("invZ was invalid");return{x:F,y:V}}),l=Qt(w=>{if(w.is0()){if(e.allowInfinityPoint&&!t.is0(w.py))return;throw new Error("bad point: ZERO")}let{x:h,y:E}=w.toAffine();if(!t.isValid(h)||!t.isValid(E))throw new Error("bad point: x or y not FE");let C=t.sqr(E),x=s(h);if(!t.eql(C,x))throw new Error("bad point: equation left != right");if(!w.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class d{constructor(h,E,C){if(this.px=h,this.py=E,this.pz=C,h==null||!t.isValid(h))throw new Error("x required");if(E==null||!t.isValid(E))throw new Error("y required");if(C==null||!t.isValid(C))throw new Error("z required");Object.freeze(this)}static fromAffine(h){let{x:E,y:C}=h||{};if(!h||!t.isValid(E)||!t.isValid(C))throw new Error("invalid affine point");if(h instanceof d)throw new Error("projective point not allowed");let x=T=>t.eql(T,t.ZERO);return x(E)&&x(C)?d.ZERO:new d(E,C,t.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let E=t.invertBatch(h.map(C=>C.pz));return h.map((C,x)=>C.toAffine(E[x])).map(d.fromAffine)}static fromHex(h){let E=d.fromAffine(i(ae("pointHex",h)));return E.assertValidity(),E}static fromPrivateKey(h){return d.BASE.multiply(c(h))}static msm(h,E){return Gn(d,n,h,E)}_setWindowSize(h){I.setWindowSize(this,h)}assertValidity(){l(this)}hasEvenY(){let{y:h}=this.toAffine();if(t.isOdd)return!t.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){f(h);let{px:E,py:C,pz:x}=this,{px:T,py:F,pz:V}=h,U=t.eql(t.mul(E,V),t.mul(T,x)),g=t.eql(t.mul(C,V),t.mul(F,x));return U&&g}negate(){return new d(this.px,t.neg(this.py),this.pz)}double(){let{a:h,b:E}=e,C=t.mul(E,ju),{px:x,py:T,pz:F}=this,V=t.ZERO,U=t.ZERO,g=t.ZERO,v=t.mul(x,x),O=t.mul(T,T),R=t.mul(F,F),N=t.mul(x,T);return N=t.add(N,N),g=t.mul(x,F),g=t.add(g,g),V=t.mul(h,g),U=t.mul(C,R),U=t.add(V,U),V=t.sub(O,U),U=t.add(O,U),U=t.mul(V,U),V=t.mul(N,V),g=t.mul(C,g),R=t.mul(h,R),N=t.sub(v,R),N=t.mul(h,N),N=t.add(N,g),g=t.add(v,v),v=t.add(g,v),v=t.add(v,R),v=t.mul(v,N),U=t.add(U,v),R=t.mul(T,F),R=t.add(R,R),v=t.mul(R,N),V=t.sub(V,v),g=t.mul(R,O),g=t.add(g,g),g=t.add(g,g),new d(V,U,g)}add(h){f(h);let{px:E,py:C,pz:x}=this,{px:T,py:F,pz:V}=h,U=t.ZERO,g=t.ZERO,v=t.ZERO,O=e.a,R=t.mul(e.b,ju),N=t.mul(E,T),H=t.mul(C,F),A=t.mul(x,V),S=t.add(E,C),m=t.add(T,F);S=t.mul(S,m),m=t.add(N,H),S=t.sub(S,m),m=t.add(E,x);let p=t.add(T,V);return m=t.mul(m,p),p=t.add(N,A),m=t.sub(m,p),p=t.add(C,x),U=t.add(F,V),p=t.mul(p,U),U=t.add(H,A),p=t.sub(p,U),v=t.mul(O,m),U=t.mul(R,A),v=t.add(U,v),U=t.sub(H,v),v=t.add(H,v),g=t.mul(U,v),H=t.add(N,N),H=t.add(H,N),A=t.mul(O,A),m=t.mul(R,m),H=t.add(H,A),A=t.sub(N,A),A=t.mul(O,A),m=t.add(m,A),N=t.mul(H,m),g=t.add(g,N),N=t.mul(p,m),U=t.mul(S,U),U=t.sub(U,N),N=t.mul(S,H),v=t.mul(p,v),v=t.add(v,N),new d(U,g,v)}subtract(h){return this.add(h.negate())}is0(){return this.equals(d.ZERO)}wNAF(h){return I.wNAFCached(this,h,d.normalizeZ)}multiplyUnsafe(h){Le("scalar",h,Ct,e.n);let E=d.ZERO;if(h===Ct)return E;if(h===me)return this;let{endo:C}=e;if(!C)return I.unsafeLadder(this,h);let{k1neg:x,k1:T,k2neg:F,k2:V}=C.splitScalar(h),U=E,g=E,v=this;for(;T>Ct||V>Ct;)T&me&&(U=U.add(v)),V&me&&(g=g.add(v)),v=v.double(),T>>=me,V>>=me;return x&&(U=U.negate()),F&&(g=g.negate()),g=new d(t.mul(g.px,C.beta),g.py,g.pz),U.add(g)}multiply(h){let{endo:E,n:C}=e;Le("scalar",h,me,C);let x,T;if(E){let{k1neg:F,k1:V,k2neg:U,k2:g}=E.splitScalar(h),{p:v,f:O}=this.wNAF(V),{p:R,f:N}=this.wNAF(g);v=I.constTimeNegate(F,v),R=I.constTimeNegate(U,R),R=new d(t.mul(R.px,E.beta),R.py,R.pz),x=v.add(R),T=O.add(N)}else{let{p:F,f:V}=this.wNAF(h);x=F,T=V}return d.normalizeZ([x,T])[0]}multiplyAndAddUnsafe(h,E,C){let x=d.BASE,T=(V,U)=>U===Ct||U===me||!V.equals(x)?V.multiplyUnsafe(U):V.multiply(U),F=T(this,E).add(T(h,C));return F.is0()?void 0:F}toAffine(h){return u(this,h)}isTorsionFree(){let{h,isTorsionFree:E}=e;if(h===me)return!0;if(E)return E(d,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:E}=e;return h===me?this:E?E(d,this):this.multiplyUnsafe(e.h)}toRawBytes(h=!0){return Je("isCompressed",h),this.assertValidity(),o(d,this,h)}toHex(h=!0){return Je("isCompressed",h),wt(this.toRawBytes(h))}}d.BASE=new d(e.Gx,e.Gy,t.ONE),d.ZERO=new d(t.ZERO,t.ONE,t.ZERO);let b=e.nBitLength,I=jn(d,e.endo?Math.ceil(b/2):b);return{CURVE:e,ProjectivePoint:d,normPrivateKeyToScalar:c,weierstrassEquation:s,isWithinCurveOrder:a}}function gp(r){let e=en(r);return at(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function Gu(r){let e=gp(r),{Fp:t,n}=e,o=t.BYTES+1,i=2*t.BYTES+1;function s(A){return Q(A,n)}function a(A){return zn(A,n)}let{ProjectivePoint:c,normPrivateKeyToScalar:f,weierstrassEquation:u,isWithinCurveOrder:l}=mp({...e,toBytes(A,S,m){let p=S.toAffine(),B=t.toBytes(p.x),P=bt;return Je("isCompressed",m),m?P(Uint8Array.from([S.hasEvenY()?2:3]),B):P(Uint8Array.from([4]),B,t.toBytes(p.y))},fromBytes(A){let S=A.length,m=A[0],p=A.subarray(1);if(S===o&&(m===2||m===3)){let B=xt(p);if(!Xr(B,me,t.ORDER))throw new Error("Point is not on curve");let P=u(B),D;try{D=t.sqrt(P)}catch(G){let z=G instanceof Error?": "+G.message:"";throw new Error("Point is not on curve"+z)}let M=(D&me)===me;return(m&1)===1!==M&&(D=t.neg(D)),{x:B,y:D}}else if(S===i&&m===4){let B=t.fromBytes(p.subarray(0,t.BYTES)),P=t.fromBytes(p.subarray(t.BYTES,2*t.BYTES));return{x:B,y:P}}else throw new Error(`Point of length ${S} was invalid. Expected ${o} compressed bytes or ${i} uncompressed bytes`)}}),d=A=>wt(Ot(A,e.nByteLength));function b(A){let S=n>>me;return A>S}function I(A){return b(A)?s(-A):A}let w=(A,S,m)=>xt(A.slice(S,m));class h{constructor(S,m,p){this.r=S,this.s=m,this.recovery=p,this.assertValidity()}static fromCompact(S){let m=e.nByteLength;return S=ae("compactSignature",S,m*2),new h(w(S,0,m),w(S,m,2*m))}static fromDER(S){let{r:m,s:p}=kt.toSig(ae("DER",S));return new h(m,p)}assertValidity(){Le("r",this.r,me,n),Le("s",this.s,me,n)}addRecoveryBit(S){return new h(this.r,this.s,S)}recoverPublicKey(S){let{r:m,s:p,recovery:B}=this,P=V(ae("msgHash",S));if(B==null||![0,1,2,3].includes(B))throw new Error("recovery id invalid");let D=B===2||B===3?m+e.n:m;if(D>=t.ORDER)throw new Error("recovery id 2 or 3 invalid");let M=B&1?"03":"02",q=c.fromHex(M+d(D)),G=a(D),z=s(-P*G),J=s(p*G),te=c.BASE.multiplyAndAddUnsafe(q,z,J);if(!te)throw new Error("point at infinify");return te.assertValidity(),te}hasHighS(){return b(this.s)}normalizeS(){return this.hasHighS()?new h(this.r,s(-this.s),this.recovery):this}toDERRawBytes(){return Jt(this.toDERHex())}toDERHex(){return kt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Jt(this.toCompactHex())}toCompactHex(){return d(this.r)+d(this.s)}}let E={isValidPrivateKey(A){try{return f(A),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{let A=os(e.n);return Sc(e.randomBytes(A),e.n)},precompute(A=8,S=c.BASE){return S._setWindowSize(A),S.multiply(BigInt(3)),S}};function C(A,S=!0){return c.fromPrivateKey(A).toRawBytes(S)}function x(A){let S=Pt(A),m=typeof A=="string",p=(S||m)&&A.length;return S?p===o||p===i:m?p===2*o||p===2*i:A instanceof c}function T(A,S,m=!0){if(x(A))throw new Error("first arg must be private key");if(!x(S))throw new Error("second arg must be public key");return c.fromHex(S).multiply(f(A)).toRawBytes(m)}let F=e.bits2int||function(A){let S=xt(A),m=A.length*8-e.nBitLength;return m>0?S>>BigInt(m):S},V=e.bits2int_modN||function(A){return s(F(A))},U=Qr(e.nBitLength);function g(A){return Le(`num < 2^${e.nBitLength}`,A,Ct,U),Ot(A,e.nByteLength)}function v(A,S,m=O){if(["recovered","canonical"].some(pe=>pe in m))throw new Error("sign() legacy options not supported");let{hash:p,randomBytes:B}=e,{lowS:P,prehash:D,extraEntropy:M}=m;P==null&&(P=!0),A=ae("msgHash",A),zu(m),D&&(A=ae("prehashed msgHash",p(A)));let q=V(A),G=f(S),z=[g(G),g(q)];if(M!=null&&M!==!1){let pe=M===!0?B(t.BYTES):M;z.push(ae("extraEntropy",pe))}let J=bt(...z),te=q;function he(pe){let ye=F(pe);if(!l(ye))return;let Ie=a(ye),le=c.BASE.multiply(ye).toAffine(),Ue=s(le.x);if(Ue===Ct)return;let pt=s(Ie*s(te+Ue*G));if(pt===Ct)return;let jr=(le.x===Ue?0:2)|Number(le.y&me),Gr=pt;return P&&b(pt)&&(Gr=I(pt),jr^=1),new h(Ue,Gr,jr)}return{seed:J,k2sig:he}}let O={lowS:e.lowS,prehash:!1},R={lowS:e.lowS,prehash:!1};function N(A,S,m=O){let{seed:p,k2sig:B}=v(A,S,m),P=e;return es(P.hash.outputLen,P.nByteLength,P.hmac)(p,B)}c.BASE._setWindowSize(8);function H(A,S,m,p=R){let B=A;if(S=ae("msgHash",S),m=ae("publicKey",m),"strict"in p)throw new Error("options.strict was renamed to lowS");zu(p);let{lowS:P,prehash:D}=p,M,q;try{if(typeof B=="string"||Pt(B))try{M=h.fromDER(B)}catch(le){if(!(le instanceof kt.Err))throw le;M=h.fromCompact(B)}else if(typeof B=="object"&&typeof B.r=="bigint"&&typeof B.s=="bigint"){let{r:le,s:Ue}=B;M=new h(le,Ue)}else throw new Error("PARSE");q=c.fromHex(m)}catch(le){if(le.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(P&&M.hasHighS())return!1;D&&(S=e.hash(S));let{r:G,s:z}=M,J=V(S),te=a(z),he=s(J*te),pe=s(G*te),ye=c.BASE.multiplyAndAddUnsafe(q,he,pe)?.toAffine();return ye?s(ye.x)===G:!1}return{CURVE:e,getPublicKey:C,getSharedSecret:T,sign:N,verify:H,ProjectivePoint:c,Signature:h,utils:E}}function yp(r){return{hash:r,hmac:(e,...t)=>Ws(r,e,ji(...t)),randomBytes:$n}}function Zu(r,e){let t=n=>Gu({...r,...yp(n)});return Object.freeze({...t(e),create:t})}var Ju=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Wu=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),wp=BigInt(1),Ys=BigInt(2),Yu=(r,e)=>(r+e/Ys)/e;function xp(r){let e=Ju,t=BigInt(3),n=BigInt(6),o=BigInt(11),i=BigInt(22),s=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%e,u=f*f*r%e,l=ie(u,t,e)*u%e,d=ie(l,t,e)*u%e,b=ie(d,Ys,e)*f%e,I=ie(b,o,e)*b%e,w=ie(I,i,e)*I%e,h=ie(w,a,e)*w%e,E=ie(h,c,e)*h%e,C=ie(E,a,e)*w%e,x=ie(C,t,e)*u%e,T=ie(x,s,e)*I%e,F=ie(T,n,e)*f%e,V=ie(F,Ys,e);if(!Js.eql(Js.sqr(V),r))throw new Error("Cannot find square root");return V}var Js=Dt(Ju,void 0,void 0,{sqrt:xp}),ir=Zu({a:BigInt(0),b:BigInt(7),Fp:Js,n:Wu,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let e=Wu,t=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-wp*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),i=t,s=BigInt("0x100000000000000000000000000000000"),a=Yu(i*r,e),c=Yu(-n*r,e),f=Q(r-a*t-c*o,e),u=Q(-a*n-c*i,e),l=f>s,d=u>s;if(l&&(f=e-f),d&&(u=e-u),f>s||u>s)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:l,k1:f,k2neg:d,k2:u}}}},Tr),Nx=BigInt(0);var Ux=ir.ProjectivePoint;function De(r,e){e==null&&(e=r.reduce((o,i)=>o+i.length,0));let t=Qe(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}function Xu(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Qu(r,e,t){let n=tn.digest(t instanceof Uint8Array?t:t.subarray());if(Xu(n))return n.then(({digest:o})=>ir.verify(e,o,r)).catch(o=>{throw new mn(String(o))});try{return ir.verify(e,n.digest,r)}catch(o){throw new mn(String(o))}}var Wo=class{type="secp256k1";raw;_key;constructor(e){this._key=tl(e),this.raw=el(this._key)}toMultihash(){return We.digest(Jn(this))}toCID(){return X.createV1(114,this.toMultihash())}toString(){return re.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ce(this.raw,e.raw)}verify(e,t){return Qu(this._key,t,e)}};function Xs(r){return new Wo(r)}function el(r){return ir.ProjectivePoint.fromHex(r).toRawBytes(!0)}function tl(r){try{return ir.ProjectivePoint.fromHex(r),r}catch(e){throw new lr(String(e))}}function rl(r){let{Type:e,Data:t}=ct.decode(r),n=t??new Uint8Array;switch(e){case de.RSA:return Zs(n);case de.Ed25519:return us(n);case de.secp256k1:return Xs(n);default:throw new dr}}function Yo(r){let{Type:e,Data:t}=ct.decode(r.digest),n=t??new Uint8Array;switch(e){case de.Ed25519:return us(n);case de.secp256k1:return Xs(n);default:throw new dr}}function Jn(r){return ct.encode({Type:de[r.type],Data:r.raw})}var nl=Symbol.for("nodejs.util.inspect.custom"),bp=114,wn=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Ri]=!0;toString(){return this.string==null&&(this.string=re.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return X.createV1(bp,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return ce(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return ce(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[nl](){return`PeerId(${this.toString()})`}},Jo=class extends wn{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Xo=class extends wn{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Qo=class extends wn{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},vp=2336,xn=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=We.digest(Z(this.url))}[nl](){return`PeerId(${this.url})`}[Ri]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return X.createV1(vp,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=ne(e)),e.toString()===this.toString())}};var Ep=114,ol=2336;function il(r,e){let t;if(r.charAt(0)==="1"||r.charAt(0)==="Q")t=gt(re.decode(`z${r}`));else{if(e==null)throw new ve('Please pass a multibase decoder for strings that do not start with "1" or "Q"');t=gt(e.decode(r))}return sl(t)}function sl(r){if(Ap(r))return new Jo({multihash:r});if(Bp(r))try{let e=Yo(r);if(e.type==="Ed25519")return new Xo({multihash:r,publicKey:e});if(e.type==="secp256k1")return new Qo({multihash:r,publicKey:e})}catch{let t=ne(r.digest);return new xn(new URL(t))}throw new fr("Supplied PeerID Multihash is invalid")}function al(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==Ep&&r.code!==ol)throw new Ln("Supplied PeerID CID is invalid");if(r.code===ol){let e=ne(r.multihash.digest);return new xn(new URL(e))}return sl(r.multihash)}function Bp(r){return r.code===We.code}function Ap(r){return r.code===tn.code}var ei=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}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 t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let i=0,s=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",f=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let d=Number.parseInt(l,e);if(!Number.isNaN(d))return d});if(u===void 0)break;if(i*=e,i+=u,i>f||(s+=1,t!==void 0&&s>t))return}if(s!==0)return!n&&c&&s>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return t[o]=s[0],t[o+1]=s[1],t[o+2]=s[2],t[o+3]=s[3],[o+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[o,!1];t[o]=i>>8,t[o+1]=i&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),s=16-(n+2),[a]=e(i.subarray(0,s));return t.set(i.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var cl=45,Sp=15,Pr=new ei;function Qs(r){if(!(r.length>Sp))return Pr.new(r).parseWith(()=>Pr.readIPv4Addr())}function ea(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>cl))return Pr.new(r).parseWith(()=>Pr.readIPv6Addr())}function ti(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>cl))return Pr.new(r).parseWith(()=>Pr.readIPAddr())}var jb=parseInt("0xFFFF",16),Gb=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function fl(r){return!!Qs(r)}function dl(r){return!!ea(r)}function ri(r){return!!ti(r)}var hl=fl,Np=dl,ta=function(r){let e=0;if(r=r.toString().trim(),hl(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(Np(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=hl(t[n]),s;i&&(s=ta(t[n]),t[n]=ne(s.slice(0,2),"base16")),s!=null&&++n<8&&t.splice(n,0,ne(s.slice(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let i=[n,1];for(n=9-t.length;n>0;n--)i.push("0");t.splice.apply(t,i)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){let i=parseInt(t[n],16);o[e++]=i>>8&255,o[e++]=i&255}return o}throw new Error("invalid ip address")},pl=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let o=[];for(let i=0;i<t;i++)o.push(r[e+i]);return o.join(".")}if(t===16){let o=[];for(let i=0;i<t;i+=2)o.push(n.getUint16(e+i).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var Fr={},ra={},Rp=[[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"],[481,-1,"http-path"],[777,-1,"memory"]];Rp.forEach(r=>{let e=_p(...r);ra[e.code]=e,Fr[e.name]=e});function _p(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function ee(r){if(typeof r=="number"){if(ra[r]!=null)return ra[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Fr[r]!=null)return Fr[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var N1=ee("ip4"),U1=ee("ip6"),R1=ee("ipcidr");function sa(r,e){switch(ee(r).code){case 4:case 41:return Vp(e);case 42:return ia(e);case 6:case 273:case 33:case 132:return yl(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return ia(e);case 421:return Dp(e);case 444:return gl(e);case 445:return gl(e);case 466:return Op(e);case 481:return globalThis.encodeURIComponent(ia(e));default:return ne(e,"base16")}}function aa(r,e){switch(ee(r).code){case 4:return ml(e);case 41:return ml(e);case 42:return oa(e);case 6:case 273:case 33:case 132:return ca(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return oa(e);case 421:return Pp(e);case 444:return Mp(e);case 445:return $p(e);case 466:return Fp(e);case 481:return oa(globalThis.decodeURIComponent(e));default:return Z(e,"base16")}}var na=Object.values(rn).map(r=>r.decoder),Lp=function(){let r=na[0].or(na[1]);return na.slice(2).forEach(e=>r=r.or(e)),r}();function ml(r){if(!ri(r))throw new Error("invalid ip address");return ta(r)}function Vp(r){let e=pl(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!ri(e))throw new Error("invalid ip address");return e}function ca(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function yl(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function oa(r){let e=Z(r),t=Uint8Array.from(Ar(e.length));return De([t,e],t.length+e.length)}function ia(r){let e=tr(r);if(r=r.slice(Pe(e)),r.length!==e)throw new Error("inconsistent lengths");return ne(r)}function Pp(r){let e;r[0]==="Q"||r[0]==="1"?e=gt(re.decode(`z${r}`)).bytes:e=X.parse(r).multihash.bytes;let t=Uint8Array.from(Ar(e.length));return De([t,e],t.length+e.length)}function Fp(r){let e=Lp.decode(r),t=Uint8Array.from(Ar(e.length));return De([t,e],t.length+e.length)}function Op(r){let e=tr(r),t=r.slice(Pe(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+ne(t,"base64url")}function Dp(r){let e=tr(r),t=r.slice(Pe(e));if(t.length!==e)throw new Error("inconsistent lengths");return ne(t,"base58btc")}function Mp(r){let e=r.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 t=Ge.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 o=ca(n);return De([t,o],t.length+o.length)}function $p(r){let e=r.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 t=Ge.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 o=ca(n);return De([t,o],t.length+o.length)}function gl(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=ne(e,"base32"),o=yl(t);return`${n}:${o}`}function wl(r){r=ua(r);let e=[],t=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let i=0;i<o.length;i++){let s=o[i],a=ee(s);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(i++,i>=o.length)throw bl("invalid address: "+r);if(a.path===!0){n=ua(o.slice(i).join("/")),e.push([a.code,aa(a.code,n)]),t.push([a.code,n]);break}let c=aa(a.code,o[i]);e.push([a.code,c]),t.push([a.code,sa(a.code,c)])}return{string:xl(t),bytes:fa(e),tuples:e,stringTuples:t,path:n}}function la(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let i=tr(r,o),s=Pe(i),a=ee(i),c=Hp(a,r.slice(o+s));if(c===0){e.push([i]),t.push([i]),o+=s;continue}let f=r.slice(o+s,o+s+c);if(o+=c+s,o>r.length)throw bl("Invalid address Uint8Array: "+ne(r,"base16"));e.push([i,f]);let u=sa(i,f);if(t.push([i,u]),a.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:xl(t),tuples:e,stringTuples:t,path:n}}function xl(r){let e=[];return r.map(t=>{let n=ee(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),ua(e.join("/"))}function fa(r){return De(r.map(e=>{let t=ee(e[0]),n=Uint8Array.from(Ar(t.code));return e.length>1&&e[1]!=null&&(n=De([n,e[1]])),n}))}function Hp(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=tr(e instanceof Uint8Array?e:Uint8Array.from(e));return t+Pe(t)}}function ua(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function bl(r){return new Error("Error parsing address: "+r)}var Kp=Symbol.for("nodejs.util.inspect.custom"),ha=Symbol.for("@multiformats/js-multiaddr/multiaddr"),qp=[ee("dns").code,ee("dns4").code,ee("dns6").code,ee("dnsaddr").code],da=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}},ni=class r{bytes;#e;#t;#i;#a;[ha]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=la(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=wl(e)}else if(El(e))t=la(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#t=t.tuples,this.#i=t.stringTuples,this.#a=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,o,i="",s=ee("tcp"),a=ee("udp"),c=ee("ip4"),f=ee("ip6"),u=ee("dns6"),l=ee("ip6zone");for(let[b,I]of this.stringTuples())b===l.code&&(i=`%${I??""}`),qp.includes(b)&&(t=s.name,o=443,n=`${I??""}${i}`,e=b===u.code?6:4),(b===s.code||b===a.code)&&(t=ee(b).name,o=parseInt(I??"")),(b===c.code||b===f.code)&&(t=ee(b).name,n=`${I??""}${i}`,e=b===f.code?6:4);if(e==null||t==null||n==null||o==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:t,port:o}}protos(){return this.#t.map(([e])=>Object.assign({},ee(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>ee(e).name)}tuples(){return this.#t}stringTuples(){return this.#i}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(fa(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===Fr.p2p.code&&e.push([n,o]),n===Fr["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?ne(re.decode(`z${n}`),"base58btc"):ne(X.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#a}equals(e){return ce(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(i=>i.resolvable);if(t==null)return[this];let n=vl.get(t.name);if(n==null)throw new da(`no available resolver for ${t.name}`);return(await n(this,e)).map(i=>sr(i))}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 t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[Kp](){return`Multiaddr(${this.#e})`}};var vl=new Map;function El(r){return!!r?.[ha]}function sr(r){return new ni(r)}function bn(r){let e=new globalThis.AbortController;function t(){e.abort();for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}for(let i of r){if(i?.aborted===!0){t();break}i?.addEventListener!=null&&i.addEventListener("abort",t)}function n(){for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}let o=e.signal;return o.clear=n,o}async function*oi(r,e={}){let t=r.getReader();try{for(;;){let n=await t.read();if(n.done)return;yield n.value}}finally{e.preventCancel!==!0&&await t.cancel(),t.releaseLock()}}var zp="/",jp=new TextEncoder().encode(zp),s2=jp[0];var Im=_n(ma(),1);var rt=class extends Error{static name="SignatureVerificationError";constructor(e="Record signature verification failed"){super(e),this.name="SignatureVerificationError"}},ii=class extends Error{static name="RecordExpiredError";constructor(e="Record has expired"){super(e),this.name="RecordExpiredError"}},Or=class extends Error{static name="UnsupportedValidityError";constructor(e="The validity type is unsupported"){super(e),this.name="UnsupportedValidityError"}},si=class extends Error{static name="RecordTooLargeError";constructor(e="The record is too large"){super(e),this.name="RecordTooLargeError"}},ai=class extends Error{static name="InvalidValueError";constructor(e="Value must be a valid content path starting with /"){super(e),this.name="InvalidValueError"}},ci=class extends Error{static name="InvalidRecordDataError";constructor(e="Invalid record data"){super(e),this.name="InvalidRecordDataError"}},vn=class extends Error{static name="InvalidEmbeddedPublicKeyError";constructor(e="Invalid embedded public key"){super(e),this.name="InvalidEmbeddedPublicKeyError"}};var nt;(function(r){let e;(function(o){o.EOL="EOL"})(e=r.ValidityType||(r.ValidityType={}));let t;(function(o){o[o.EOL=0]="EOL"})(t||(t={})),function(o){o.codec=()=>sn(t)}(e=r.ValidityType||(r.ValidityType={}));let n;r.codec=()=>(n==null&&(n=Cr((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.value!=null&&(i.uint32(10),i.bytes(o.value)),o.signatureV1!=null&&(i.uint32(18),i.bytes(o.signatureV1)),o.validityType!=null&&(i.uint32(24),r.ValidityType.codec().encode(o.validityType,i)),o.validity!=null&&(i.uint32(34),i.bytes(o.validity)),o.sequence!=null&&(i.uint32(40),i.uint64(o.sequence)),o.ttl!=null&&(i.uint32(48),i.uint64(o.ttl)),o.pubKey!=null&&(i.uint32(58),i.bytes(o.pubKey)),o.signatureV2!=null&&(i.uint32(66),i.bytes(o.signatureV2)),o.data!=null&&(i.uint32(74),i.bytes(o.data)),s.lengthDelimited!==!1&&i.ldelim()},(o,i,s={})=>{let a={},c=i==null?o.len:o.pos+i;for(;o.pos<c;){let f=o.uint32();switch(f>>>3){case 1:{a.value=o.bytes();break}case 2:{a.signatureV1=o.bytes();break}case 3:{a.validityType=r.ValidityType.codec().decode(o);break}case 4:{a.validity=o.bytes();break}case 5:{a.sequence=o.uint64();break}case 6:{a.ttl=o.uint64();break}case 7:{a.pubKey=o.bytes();break}case 8:{a.signatureV2=o.bytes();break}case 9:{a.data=o.bytes();break}default:{o.skipType(f&7);break}}}return a})),n),r.encode=o=>Ir(o,r.codec()),r.decode=(o,i)=>Sr(o,r.codec(),i)})(nt||(nt={}));var Gp=["string","number","bigint","symbol"],Zp=["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 Bl(r){if(r===null)return"null";if(r===void 0)return"undefined";if(r===!0||r===!1)return"boolean";let e=typeof r;if(Gp.includes(e))return e;if(e==="function")return"Function";if(Array.isArray(r))return"Array";if(Wp(r))return"Buffer";let t=Yp(r);return t||"Object"}function Wp(r){return r&&r.constructor&&r.constructor.isBuffer&&r.constructor.isBuffer.call(null,r)}function Yp(r){let e=Object.prototype.toString.call(r).slice(8,-1);if(Zp.includes(e))return e}var y=class{constructor(e,t,n){this.major=e,this.majorEncoded=e<<5,this.name=t,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.major<e.major?-1:this.major>e.major?1:0}};y.uint=new y(0,"uint",!0);y.negint=new y(1,"negint",!0);y.bytes=new y(2,"bytes",!0);y.string=new y(3,"string",!0);y.array=new y(4,"array",!1);y.map=new y(5,"map",!1);y.tag=new y(6,"tag",!1);y.float=new y(7,"float",!0);y.false=new y(7,"false",!0);y.true=new y(7,"true",!0);y.null=new y(7,"null",!0);y.undefined=new y(7,"undefined",!0);y.break=new y(7,"break",!0);var L=class{constructor(e,t,n){this.type=e,this.value=t,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var Dr=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Jp=new TextDecoder,Xp=new TextEncoder;function ui(r){return Dr&&globalThis.Buffer.isBuffer(r)}function kl(r){return r instanceof Uint8Array?ui(r)?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r:Uint8Array.from(r)}var Cl=Dr?(r,e,t)=>t-e>64?globalThis.Buffer.from(r.subarray(e,t)).toString("utf8"):Sl(r,e,t):(r,e,t)=>t-e>64?Jp.decode(r.subarray(e,t)):Sl(r,e,t),Tl=Dr?r=>r.length>64?globalThis.Buffer.from(r):Al(r):r=>r.length>64?Xp.encode(r):Al(r);var Mr=Dr?(r,e,t)=>ui(r)?new Uint8Array(r.subarray(e,t)):r.slice(e,t):(r,e,t)=>r.slice(e,t),Nl=Dr?(r,e)=>(r=r.map(t=>t instanceof Uint8Array?t:globalThis.Buffer.from(t)),kl(globalThis.Buffer.concat(r,e))):(r,e)=>{let t=new Uint8Array(e),n=0;for(let o of r)n+o.length>t.length&&(o=o.subarray(0,t.length-n)),t.set(o,n),n+=o.length;return t},Ul=Dr?r=>globalThis.Buffer.allocUnsafe(r):r=>new Uint8Array(r);function Rl(r,e){if(ui(r)&&ui(e))return r.compare(e);for(let t=0;t<r.length;t++)if(r[t]!==e[t])return r[t]<e[t]?-1:1;return 0}function Al(r){let e=[],t=0;for(let n=0;n<r.length;n++){let o=r.charCodeAt(n);o<128?e[t++]=o:o<2048?(e[t++]=o>>6|192,e[t++]=o&63|128):(o&64512)===55296&&n+1<r.length&&(r.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(r.charCodeAt(++n)&1023),e[t++]=o>>18|240,e[t++]=o>>12&63|128,e[t++]=o>>6&63|128,e[t++]=o&63|128):(e[t++]=o>>12|224,e[t++]=o>>6&63|128,e[t++]=o&63|128)}return e}function Sl(r,e,t){let n=[];for(;e<t;){let o=r[e],i=null,s=o>239?4:o>223?3:o>191?2:1;if(e+s<=t){let a,c,f,u;switch(s){case 1:o<128&&(i=o);break;case 2:a=r[e+1],(a&192)===128&&(u=(o&31)<<6|a&63,u>127&&(i=u));break;case 3:a=r[e+1],c=r[e+2],(a&192)===128&&(c&192)===128&&(u=(o&15)<<12|(a&63)<<6|c&63,u>2047&&(u<55296||u>57343)&&(i=u));break;case 4:a=r[e+1],c=r[e+2],f=r[e+3],(a&192)===128&&(c&192)===128&&(f&192)===128&&(u=(o&15)<<18|(a&63)<<12|(c&63)<<6|f&63,u>65535&&u<1114112&&(i=u))}}i===null?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),e+=s}return Qp(n)}var Il=4096;function Qp(r){let e=r.length;if(e<=Il)return String.fromCharCode.apply(String,r);let t="",n=0;for(;n<e;)t+=String.fromCharCode.apply(String,r.slice(n,n+=Il));return t}var em=256,li=class{constructor(e=em){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 t=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){let o=t.length-(this.maxCursor-this.cursor)-1;t.set(e,o)}else{if(t){let o=t.length-(this.maxCursor-this.cursor)-1;o<t.length&&(this.chunks[this.chunks.length-1]=t.subarray(0,o),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(t=Ul(this.chunkSize),this.chunks.push(t),this.maxCursor+=t.length,this._initReuseChunk===null&&(this._initReuseChunk=t),t.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let t;if(this.chunks.length===1){let n=this.chunks[0];e&&this.cursor>n.length/2?(t=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):t=Mr(n,0,this.cursor)}else t=Nl(this.chunks,this.cursor);return e&&this.reset(),t}};var $="CBOR decode error:",ga="CBOR encode error:",En=[];En[23]=1;En[24]=2;En[25]=3;En[26]=5;En[27]=9;function Tt(r,e,t){if(r.length-e<t)throw new Error(`${$} not enough data for type`)}var ge=[24,256,65536,4294967296,BigInt("18446744073709551616")];function Me(r,e,t){Tt(r,e,1);let n=r[e];if(t.strict===!0&&n<ge[0])throw new Error(`${$} integer encoded in more bytes than necessary (strict decode)`);return n}function $e(r,e,t){Tt(r,e,2);let n=r[e]<<8|r[e+1];if(t.strict===!0&&n<ge[1])throw new Error(`${$} integer encoded in more bytes than necessary (strict decode)`);return n}function He(r,e,t){Tt(r,e,4);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3];if(t.strict===!0&&n<ge[2])throw new Error(`${$} integer encoded in more bytes than necessary (strict decode)`);return n}function Ke(r,e,t){Tt(r,e,8);let n=r[e]*16777216+(r[e+1]<<16)+(r[e+2]<<8)+r[e+3],o=r[e+4]*16777216+(r[e+5]<<16)+(r[e+6]<<8)+r[e+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(t.strict===!0&&i<ge[3])throw new Error(`${$} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(t.allowBigInt===!0)return i;throw new Error(`${$} integers outside of the safe integer range are not supported`)}function _l(r,e,t,n){return new L(y.uint,Me(r,e+1,n),2)}function Ll(r,e,t,n){return new L(y.uint,$e(r,e+1,n),3)}function Vl(r,e,t,n){return new L(y.uint,He(r,e+1,n),5)}function Pl(r,e,t,n){return new L(y.uint,Ke(r,e+1,n),9)}function ze(r,e){return be(r,0,e.value)}function be(r,e,t){if(t<ge[0]){let n=Number(t);r.push([e|n])}else if(t<ge[1]){let n=Number(t);r.push([e|24,n])}else if(t<ge[2]){let n=Number(t);r.push([e|25,n>>>8,n&255])}else if(t<ge[3]){let n=Number(t);r.push([e|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(t);if(n<ge[4]){let o=[e|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,r.push(o)}else throw new Error(`${$} encountered BigInt larger than allowable range`)}}ze.encodedSize=function(e){return be.encodedSize(e.value)};be.encodedSize=function(e){return e<ge[0]?1:e<ge[1]?2:e<ge[2]?3:e<ge[3]?5:9};ze.compareTokens=function(e,t){return e.value<t.value?-1:e.value>t.value?1:0};function Fl(r,e,t,n){return new L(y.negint,-1-Me(r,e+1,n),2)}function Ol(r,e,t,n){return new L(y.negint,-1-$e(r,e+1,n),3)}function Dl(r,e,t,n){return new L(y.negint,-1-He(r,e+1,n),5)}var ya=BigInt(-1),Ml=BigInt(1);function $l(r,e,t,n){let o=Ke(r,e+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new L(y.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${$} integers outside of the safe integer range are not supported`);return new L(y.negint,ya-BigInt(o),9)}function fi(r,e){let t=e.value,n=typeof t=="bigint"?t*ya-Ml:t*-1-1;be(r,e.type.majorEncoded,n)}fi.encodedSize=function(e){let t=e.value,n=typeof t=="bigint"?t*ya-Ml:t*-1-1;return n<ge[0]?1:n<ge[1]?2:n<ge[2]?3:n<ge[3]?5:9};fi.compareTokens=function(e,t){return e.value<t.value?1:e.value>t.value?-1:0};function Bn(r,e,t,n){Tt(r,e,t+n);let o=Mr(r,e+t,e+t+n);return new L(y.bytes,o,t+n)}function Hl(r,e,t,n){return Bn(r,e,1,t)}function Kl(r,e,t,n){return Bn(r,e,2,Me(r,e+1,n))}function ql(r,e,t,n){return Bn(r,e,3,$e(r,e+1,n))}function zl(r,e,t,n){return Bn(r,e,5,He(r,e+1,n))}function jl(r,e,t,n){let o=Ke(r,e+1,n);if(typeof o=="bigint")throw new Error(`${$} 64-bit integer bytes lengths not supported`);return Bn(r,e,9,o)}function di(r){return r.encodedBytes===void 0&&(r.encodedBytes=r.type===y.string?Tl(r.value):r.value),r.encodedBytes}function $r(r,e){let t=di(e);be(r,e.type.majorEncoded,t.length),r.push(t)}$r.encodedSize=function(e){let t=di(e);return be.encodedSize(t.length)+t.length};$r.compareTokens=function(e,t){return rm(di(e),di(t))};function rm(r,e){return r.length<e.length?-1:r.length>e.length?1:Rl(r,e)}function An(r,e,t,n,o){let i=t+n;Tt(r,e,i);let s=new L(y.string,Cl(r,e+t,e+i),i);return o.retainStringBytes===!0&&(s.byteValue=Mr(r,e+t,e+i)),s}function Gl(r,e,t,n){return An(r,e,1,t,n)}function Zl(r,e,t,n){return An(r,e,2,Me(r,e+1,n),n)}function Wl(r,e,t,n){return An(r,e,3,$e(r,e+1,n),n)}function Yl(r,e,t,n){return An(r,e,5,He(r,e+1,n),n)}function Jl(r,e,t,n){let o=Ke(r,e+1,n);if(typeof o=="bigint")throw new Error(`${$} 64-bit integer string lengths not supported`);return An(r,e,9,o,n)}var Xl=$r;function Hr(r,e,t,n){return new L(y.array,n,t)}function Ql(r,e,t,n){return Hr(r,e,1,t)}function ef(r,e,t,n){return Hr(r,e,2,Me(r,e+1,n))}function tf(r,e,t,n){return Hr(r,e,3,$e(r,e+1,n))}function rf(r,e,t,n){return Hr(r,e,5,He(r,e+1,n))}function nf(r,e,t,n){let o=Ke(r,e+1,n);if(typeof o=="bigint")throw new Error(`${$} 64-bit integer array lengths not supported`);return Hr(r,e,9,o)}function of(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${$} indefinite length items not allowed`);return Hr(r,e,1,1/0)}function hi(r,e){be(r,y.array.majorEncoded,e.value)}hi.compareTokens=ze.compareTokens;hi.encodedSize=function(e){return be.encodedSize(e.value)};function Kr(r,e,t,n){return new L(y.map,n,t)}function sf(r,e,t,n){return Kr(r,e,1,t)}function af(r,e,t,n){return Kr(r,e,2,Me(r,e+1,n))}function cf(r,e,t,n){return Kr(r,e,3,$e(r,e+1,n))}function uf(r,e,t,n){return Kr(r,e,5,He(r,e+1,n))}function lf(r,e,t,n){let o=Ke(r,e+1,n);if(typeof o=="bigint")throw new Error(`${$} 64-bit integer map lengths not supported`);return Kr(r,e,9,o)}function ff(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${$} indefinite length items not allowed`);return Kr(r,e,1,1/0)}function pi(r,e){be(r,y.map.majorEncoded,e.value)}pi.compareTokens=ze.compareTokens;pi.encodedSize=function(e){return be.encodedSize(e.value)};function df(r,e,t,n){return new L(y.tag,t,1)}function hf(r,e,t,n){return new L(y.tag,Me(r,e+1,n),2)}function pf(r,e,t,n){return new L(y.tag,$e(r,e+1,n),3)}function mf(r,e,t,n){return new L(y.tag,He(r,e+1,n),5)}function gf(r,e,t,n){return new L(y.tag,Ke(r,e+1,n),9)}function mi(r,e){be(r,y.tag.majorEncoded,e.value)}mi.compareTokens=ze.compareTokens;mi.encodedSize=function(e){return be.encodedSize(e.value)};var cm=20,um=21,lm=22,fm=23;function yf(r,e,t,n){if(n.allowUndefined===!1)throw new Error(`${$} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new L(y.null,null,1):new L(y.undefined,void 0,1)}function wf(r,e,t,n){if(n.allowIndefinite===!1)throw new Error(`${$} indefinite length items not allowed`);return new L(y.break,void 0,1)}function wa(r,e,t){if(t){if(t.allowNaN===!1&&Number.isNaN(r))throw new Error(`${$} NaN values are not supported`);if(t.allowInfinity===!1&&(r===1/0||r===-1/0))throw new Error(`${$} Infinity values are not supported`)}return new L(y.float,r,e)}function xf(r,e,t,n){return wa(xa(r,e+1),3,n)}function bf(r,e,t,n){return wa(ba(r,e+1),5,n)}function vf(r,e,t,n){return wa(Sf(r,e+1),9,n)}function gi(r,e,t){let n=e.value;if(n===!1)r.push([y.float.majorEncoded|cm]);else if(n===!0)r.push([y.float.majorEncoded|um]);else if(n===null)r.push([y.float.majorEncoded|lm]);else if(n===void 0)r.push([y.float.majorEncoded|fm]);else{let o,i=!1;(!t||t.float64!==!0)&&(Bf(n),o=xa(ot,1),n===o||Number.isNaN(n)?(ot[0]=249,r.push(ot.slice(0,3)),i=!0):(Af(n),o=ba(ot,1),n===o&&(ot[0]=250,r.push(ot.slice(0,5)),i=!0))),i||(dm(n),o=Sf(ot,1),ot[0]=251,r.push(ot.slice(0,9)))}}gi.encodedSize=function(e,t){let n=e.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!t||t.float64!==!0){Bf(n);let o=xa(ot,1);if(n===o||Number.isNaN(n))return 3;if(Af(n),o=ba(ot,1),n===o)return 5}return 9};var Ef=new ArrayBuffer(9),je=new DataView(Ef,1),ot=new Uint8Array(Ef,0);function Bf(r){if(r===1/0)je.setUint16(0,31744,!1);else if(r===-1/0)je.setUint16(0,64512,!1);else if(Number.isNaN(r))je.setUint16(0,32256,!1);else{je.setFloat32(0,r);let e=je.getUint32(0),t=(e&2139095040)>>23,n=e&8388607;if(t===255)je.setUint16(0,31744,!1);else if(t===0)je.setUint16(0,(r&2147483648)>>16|n>>13,!1);else{let o=t-127;o<-24?je.setUint16(0,0):o<-14?je.setUint16(0,(e&2147483648)>>16|1<<24+o,!1):je.setUint16(0,(e&2147483648)>>16|o+15<<10|n>>13,!1)}}}function xa(r,e){if(r.length-e<2)throw new Error(`${$} not enough data for float16`);let t=(r[e]<<8)+r[e+1];if(t===31744)return 1/0;if(t===64512)return-1/0;if(t===32256)return NaN;let n=t>>10&31,o=t&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,t&32768?-i:i}function Af(r){je.setFloat32(0,r,!1)}function ba(r,e){if(r.length-e<4)throw new Error(`${$} not enough data for float32`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,4).getFloat32(0,!1)}function dm(r){je.setFloat64(0,r,!1)}function Sf(r,e){if(r.length-e<8)throw new Error(`${$} not enough data for float64`);let t=(r.byteOffset||0)+e;return new DataView(r.buffer,t,8).getFloat64(0,!1)}gi.compareTokens=ze.compareTokens;function W(r,e,t){throw new Error(`${$} encountered invalid minor (${t}) for major ${r[e]>>>5}`)}function yi(r){return()=>{throw new Error(`${$} ${r}`)}}var k=[];for(let r=0;r<=23;r++)k[r]=W;k[24]=_l;k[25]=Ll;k[26]=Vl;k[27]=Pl;k[28]=W;k[29]=W;k[30]=W;k[31]=W;for(let r=32;r<=55;r++)k[r]=W;k[56]=Fl;k[57]=Ol;k[58]=Dl;k[59]=$l;k[60]=W;k[61]=W;k[62]=W;k[63]=W;for(let r=64;r<=87;r++)k[r]=Hl;k[88]=Kl;k[89]=ql;k[90]=zl;k[91]=jl;k[92]=W;k[93]=W;k[94]=W;k[95]=yi("indefinite length bytes/strings are not supported");for(let r=96;r<=119;r++)k[r]=Gl;k[120]=Zl;k[121]=Wl;k[122]=Yl;k[123]=Jl;k[124]=W;k[125]=W;k[126]=W;k[127]=yi("indefinite length bytes/strings are not supported");for(let r=128;r<=151;r++)k[r]=Ql;k[152]=ef;k[153]=tf;k[154]=rf;k[155]=nf;k[156]=W;k[157]=W;k[158]=W;k[159]=of;for(let r=160;r<=183;r++)k[r]=sf;k[184]=af;k[185]=cf;k[186]=uf;k[187]=lf;k[188]=W;k[189]=W;k[190]=W;k[191]=ff;for(let r=192;r<=215;r++)k[r]=df;k[216]=hf;k[217]=pf;k[218]=mf;k[219]=gf;k[220]=W;k[221]=W;k[222]=W;k[223]=W;for(let r=224;r<=243;r++)k[r]=yi("simple values are not supported");k[244]=W;k[245]=W;k[246]=W;k[247]=yf;k[248]=yi("simple values are not supported");k[249]=xf;k[250]=bf;k[251]=vf;k[252]=W;k[253]=W;k[254]=W;k[255]=wf;var it=[];for(let r=0;r<24;r++)it[r]=new L(y.uint,r,1);for(let r=-1;r>=-24;r--)it[31-r]=new L(y.negint,r,1);it[64]=new L(y.bytes,new Uint8Array(0),1);it[96]=new L(y.string,"",1);it[128]=new L(y.array,0,1);it[160]=new L(y.map,0,1);it[244]=new L(y.false,!1,1);it[245]=new L(y.true,!0,1);it[246]=new L(y.null,null,1);function pm(){let r=[];return r[y.uint.major]=ze,r[y.negint.major]=fi,r[y.bytes.major]=$r,r[y.string.major]=Xl,r[y.array.major]=hi,r[y.map.major]=pi,r[y.tag.major]=mi,r[y.float.major]=gi,r}var ov=pm(),iv=new li,wi=class r{constructor(e,t){this.obj=e,this.parent=t}includes(e){let t=this;do if(t.obj===e)return!0;while(t=t.parent);return!1}static createCheck(e,t){if(e&&e.includes(t))throw new Error(`${ga} object contains circular references`);return new r(t,e)}},jt={null:new L(y.null,null),undefined:new L(y.undefined,void 0),true:new L(y.true,!0),false:new L(y.false,!1),emptyArray:new L(y.array,0),emptyMap:new L(y.map,0)},Gt={number(r,e,t,n){return!Number.isInteger(r)||!Number.isSafeInteger(r)?new L(y.float,r):r>=0?new L(y.uint,r):new L(y.negint,r)},bigint(r,e,t,n){return r>=BigInt(0)?new L(y.uint,r):new L(y.negint,r)},Uint8Array(r,e,t,n){return new L(y.bytes,r)},string(r,e,t,n){return new L(y.string,r)},boolean(r,e,t,n){return r?jt.true:jt.false},null(r,e,t,n){return jt.null},undefined(r,e,t,n){return jt.undefined},ArrayBuffer(r,e,t,n){return new L(y.bytes,new Uint8Array(r))},DataView(r,e,t,n){return new L(y.bytes,new Uint8Array(r.buffer,r.byteOffset,r.byteLength))},Array(r,e,t,n){if(!r.length)return t.addBreakTokens===!0?[jt.emptyArray,new L(y.break)]:jt.emptyArray;n=wi.createCheck(n,r);let o=[],i=0;for(let s of r)o[i++]=va(s,t,n);return t.addBreakTokens?[new L(y.array,r.length),o,new L(y.break)]:[new L(y.array,r.length),o]},Object(r,e,t,n){let o=e!=="Object",i=o?r.keys():Object.keys(r),s=o?r.size:i.length;if(!s)return t.addBreakTokens===!0?[jt.emptyMap,new L(y.break)]:jt.emptyMap;n=wi.createCheck(n,r);let a=[],c=0;for(let f of i)a[c++]=[va(f,t,n),va(o?r.get(f):r[f],t,n)];return mm(a,t),t.addBreakTokens?[new L(y.map,s),a,new L(y.break)]:[new L(y.map,s),a]}};Gt.Map=Gt.Object;Gt.Buffer=Gt.Uint8Array;for(let r of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))Gt[`${r}Array`]=Gt.DataView;function va(r,e={},t){let n=Bl(r),o=e&&e.typeEncoders&&e.typeEncoders[n]||Gt[n];if(typeof o=="function"){let s=o(r,n,e,t);if(s!=null)return s}let i=Gt[n];if(!i)throw new Error(`${ga} unsupported type: ${n}`);return i(r,n,e,t)}function mm(r,e){e.mapSorter&&r.sort(e.mapSorter)}var gm={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},xi=class{constructor(e,t={}){this._pos=0,this.data=e,this.options=t}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let e=this.data[this._pos],t=it[e];if(t===void 0){let n=k[e];if(!n)throw new Error(`${$} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);let o=e&31;t=n(this.data,this._pos,o,this.options)}return this._pos+=t.encodedLength,t}},Sn=Symbol.for("DONE"),bi=Symbol.for("BREAK");function ym(r,e,t){let n=[];for(let o=0;o<r.value;o++){let i=qr(e,t);if(i===bi){if(r.value===1/0)break;throw new Error(`${$} got unexpected break to lengthed array`)}if(i===Sn)throw new Error(`${$} found array but not enough entries (got ${o}, expected ${r.value})`);n[o]=i}return n}function wm(r,e,t){let n=t.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<r.value;s++){let a=qr(e,t);if(a===bi){if(r.value===1/0)break;throw new Error(`${$} got unexpected break to lengthed map`)}if(a===Sn)throw new Error(`${$} found map but not enough entries (got ${s} [no key], expected ${r.value})`);if(n!==!0&&typeof a!="string")throw new Error(`${$} non-string keys not supported (got ${typeof a})`);if(t.rejectDuplicateMapKeys===!0&&(n&&i.has(a)||!n&&a in o))throw new Error(`${$} found repeat map key "${a}"`);let c=qr(e,t);if(c===Sn)throw new Error(`${$} found map but not enough entries (got ${s} [no value], expected ${r.value})`);n?i.set(a,c):o[a]=c}return n?i:o}function qr(r,e){if(r.done())return Sn;let t=r.next();if(t.type===y.break)return bi;if(t.type.terminal)return t.value;if(t.type===y.array)return ym(t,r,e);if(t.type===y.map)return wm(t,r,e);if(t.type===y.tag){if(e.tags&&typeof e.tags[t.value]=="function"){let n=qr(r,e);return e.tags[t.value](n)}throw new Error(`${$} tag not supported (${t.value})`)}throw new Error("unsupported")}function If(r,e){if(!(r instanceof Uint8Array))throw new Error(`${$} data to decode must be a Uint8Array`);e=Object.assign({},gm,e);let t=e.tokenizer||new xi(r,e),n=qr(t,e);if(n===Sn)throw new Error(`${$} did not find any content to decode`);if(n===bi)throw new Error(`${$} got unexpected break`);return[n,r.subarray(t.pos())]}function Ea(r,e){let[t,n]=If(r,e);if(n.length>0)throw new Error(`${$} too many terminals, data makes no sense`);return t}var vm=Rt("ipns:utils"),kf=Z("/ipns/");var Em=0,Bm=18;function Cf(r){let e;if(r.pubKey!=null)try{e=rl(r.pubKey)}catch(t){throw vm.error(t),t}if(e!=null)return e}function Tf(r){let e=Z("ipns-signature:");return De([e,r])}function cr(r){return"signatureV1"in r?nt.encode({value:Z(r.value),signatureV1:r.signatureV1,validityType:r.validityType,validity:Z(r.validity),sequence:r.sequence,ttl:r.ttl,pubKey:r.pubKey,signatureV2:r.signatureV2,data:r.data}):nt.encode({pubKey:r.pubKey,signatureV2:r.signatureV2,data:r.data})}function dt(r){let e=nt.decode(r);if(e.sequence!=null&&(e.sequence=BigInt(e.sequence)),e.ttl!=null&&(e.ttl=BigInt(e.ttl)),e.signatureV2==null||e.data==null)throw new rt("Missing data or signatureV2");let t=Nf(e.data),n=Am(t.Value),o=ne(t.Validity);if(e.value!=null&&e.signatureV1!=null)return Sm(e),{value:n,validityType:nt.ValidityType.EOL,validity:o,sequence:t.Sequence,ttl:t.TTL,pubKey:e.pubKey,signatureV1:e.signatureV1,signatureV2:e.signatureV2,data:e.data};if(e.signatureV2!=null)return{value:n,validityType:nt.ValidityType.EOL,validity:o,sequence:t.Sequence,ttl:t.TTL,pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data};throw new Error("invalid record: does not include signatureV1 or signatureV2")}function In(r){return De([kf,r.bytes])}function Nt(r){let e=gt(r.slice(kf.length));if(!vi(e,Em)&&!vi(e,Bm))throw new fr("Multihash in IPNS key was not identity or sha2-256");return e}function Nf(r){let e=Ea(r);if(e.ValidityType===0)e.ValidityType=nt.ValidityType.EOL;else throw new Or("The validity type is unsupported");return Number.isInteger(e.Sequence)&&(e.Sequence=BigInt(e.Sequence)),Number.isInteger(e.TTL)&&(e.TTL=BigInt(e.TTL)),e}function Am(r){let e=ne(r).trim();if(e.startsWith("/"))return e;try{return`/ipfs/${X.decode(r).toV1().toString()}`}catch{}try{return`/ipfs/${X.parse(e).toV1().toString()}`}catch{}throw new ai("Value must be a valid content path starting with /")}function Sm(r){if(r.data==null)throw new ci("Record data is missing");let e=Nf(r.data);if(!ce(e.Value,r.value??new Uint8Array(0)))throw new rt('Field "value" did not match between protobuf and CBOR');if(!ce(e.Validity,r.validity??new Uint8Array(0)))throw new rt('Field "validity" did not match between protobuf and CBOR');if(e.ValidityType!==r.validityType)throw new rt('Field "validityType" did not match between protobuf and CBOR');if(e.Sequence!==r.sequence)throw new rt('Field "sequence" did not match between protobuf and CBOR');if(e.TTL!==r.ttl)throw new rt('Field "ttl" did not match between protobuf and CBOR')}function vi(r,e){return r.code===e}var Tv=Rt("ipns"),Nv=60*60*1e9,km="/ipns/",Uv=km.length;var Uf=_n(ma(),1);var Ei=Rt("ipns:validator"),Cm=1024*10,Tm=async(r,e)=>{let t=dt(e),n;try{let o=Tf(t.data);n=await r.verify(o,t.signatureV2)}catch{n=!1}if(!n)throw Ei.error("record signature verification failed"),new rt("Record signature verification failed");if(t.validityType===nt.ValidityType.EOL){if(Uf.default.fromString(t.validity).toDate().getTime()<Date.now())throw Ei.error("record has expired"),new ii("record has expired")}else if(t.validityType!=null)throw Ei.error("the validity type is unsupported"),new Or("The validity type is unsupported");Ei("ipns record for %s is valid",t.value)};async function Rf(r,e){if(e.byteLength>Cm)throw new si("The record is too large");let t=Nt(r),n;vi(t,0)&&(n=Yo(t));let o=dt(e),i=Cf(o)??n;if(i==null)throw new vn("Could not extract public key from IPNS record or routing key");let s=In(i.toMultihash());if(!ce(r,s))throw new vn("Embedded public key did not match routing key");await Tm(i,e)}async function*kn(r){let e=/\r?\n/,t=new TextDecoder("utf8"),n="";for await(let o of r){typeof o=="string"&&(o=new TextEncoder().encode(o)),n+=t.decode(o,{stream:!0});let i=n.split(e);n=i.pop()??"";for(let s=0;s<i.length;s++)yield JSON.parse(i[s])}n+=t.decode(),n!==""&&(yield JSON.parse(n))}function ht(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Aa=_n(Lf(),1);var Tn=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Sa=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Vf=r=>globalThis.DOMException===void 0?new Sa(r):new DOMException(r),Pf=r=>{let e=r.reason===void 0?Vf("This operation was aborted."):r.reason;return e instanceof Error?e:Vf(e)};function Ia(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,c=new Promise((f,u)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:d}=e;d.aborted&&u(Pf(d));let b=()=>{u(Pf(d))};d.addEventListener("abort",b,{once:!0}),r.finally(()=>{d.removeEventListener("abort",b)})}if(t===Number.POSITIVE_INFINITY){r.then(f,u);return}let l=new Tn;s=i.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(d){u(d)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?f():o instanceof Error?u(o):(l.message=o??`Promise timed out after ${t} milliseconds`,u(l))},t),(async()=>{try{f(await r)}catch(d){u(d)}})()}).finally(()=>{c.clear()});return c.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},c}function ka(r,e,t){let n=0,o=r.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;t(r[s],e)<=0?(n=++s,o-=i+1):o=i}return n}var Nn=class{#e=[];enqueue(e,t){t={priority:0,...t};let n={priority:t.priority,run:e};if(this.size&&this.#e[this.size-1].priority>=t.priority){this.#e.push(n);return}let o=ka(this.#e,n,(i,s)=>s.priority-i.priority);this.#e.splice(o,0,n)}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(t=>t.priority===e.priority).map(t=>t.run)}get size(){return this.#e.length}};var Un=class extends Aa.default{#e;#t;#i=0;#a;#c;#p=0;#n;#u;#r;#m;#o=0;#l;#s;#g;timeout;constructor(e){if(super(),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Nn,...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.#a=e.intervalCap,this.#c=e.interval,this.#r=new e.queueClass,this.#m=e.queueClass,this.concurrency=e.concurrency,this.timeout=e.timeout,this.#g=e.throwOnTimeout===!0,this.#s=e.autoStart===!1}get#x(){return this.#t||this.#i<this.#a}get#b(){return this.#o<this.#l}#v(){this.#o--,this.#f(),this.emit("next")}#E(){this.#w(),this.#y(),this.#u=void 0}get#B(){let e=Date.now();if(this.#n===void 0){let t=this.#p-e;if(t<0)this.#i=this.#e?this.#o:0;else return this.#u===void 0&&(this.#u=setTimeout(()=>{this.#E()},t)),!0}return!1}#f(){if(this.#r.size===0)return this.#n&&clearInterval(this.#n),this.#n=void 0,this.emit("empty"),this.#o===0&&this.emit("idle"),!1;if(!this.#s){let e=!this.#B;if(this.#x&&this.#b){let t=this.#r.dequeue();return t?(this.emit("active"),t(),e&&this.#y(),!0):!1}}return!1}#y(){this.#t||this.#n!==void 0||(this.#n=setInterval(()=>{this.#w()},this.#c),this.#p=Date.now()+this.#c)}#w(){this.#i===0&&this.#o===0&&this.#n&&(clearInterval(this.#n),this.#n=void 0),this.#i=this.#e?this.#o:0,this.#d()}#d(){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.#d()}async#A(e){return new Promise((t,n)=>{e.addEventListener("abort",()=>{n(e.reason)},{once:!0})})}async add(e,t={}){return t={timeout:this.timeout,throwOnTimeout:this.#g,...t},new Promise((n,o)=>{this.#r.enqueue(async()=>{this.#o++,this.#i++;try{t.signal?.throwIfAborted();let i=e({signal:t.signal});t.timeout&&(i=Ia(Promise.resolve(i),{milliseconds:t.timeout})),t.signal&&(i=Promise.race([i,this.#A(t.signal)]));let s=await i;n(s),this.emit("completed",s)}catch(i){if(i instanceof Tn&&!t.throwOnTimeout){n();return}o(i),this.emit("error",i)}finally{this.#v()}},t),this.emit("add"),this.#f()})}async addAll(e,t){return Promise.all(e.map(async n=>this.add(n,t)))}start(){return this.#s?(this.#s=!1,this.#d(),this):this}pause(){this.#s=!0}clear(){this.#r=new this.#m}async onEmpty(){this.#r.size!==0&&await this.#h("empty")}async onSizeLessThan(e){this.#r.size<e||await this.#h("next",()=>this.#r.size<e)}async onIdle(){this.#o===0&&this.#r.size===0||await this.#h("idle")}async#h(e,t){return new Promise(n=>{let o=()=>{t&&!t()||(this.off(e,o),n())};this.on(e,o)})}get size(){return this.#r.size}sizeBy(e){return this.#r.filter(e).length}get pending(){return this.#o}get isPaused(){return this.#s}};var zr=class extends Error{static name="InvalidRequestError";constructor(e="Invalid request"){super(e),this.name="InvalidRequestError"}},ur=class extends Error{static name="BadResponseError";constructor(e="Bad response"){super(e),this.name="BadResponseError"}};function Rm(r){return r[Symbol.asyncIterator]!=null}function _m(r){if(Rm(r))return(async()=>{for await(let e of r)return e})();for(let e of r)return e}var Ai=_m;function Lm(r){let[e,t]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[t](){return this}}}var Ff=Lm;function Vm(r){return r[Symbol.asyncIterator]!=null}function Pm(r,e){let t=0;if(Vm(r))return async function*(){for await(let c of r)yield e(c,t++)}();let n=Ff(r),{value:o,done:i}=n.next();if(i===!0)return function*(){}();let s=e(o,t++);if(typeof s.then=="function")return async function*(){yield await s;for await(let c of n)yield e(c,t++)}();let a=e;return function*(){yield s;for(let c of n)yield a(c,t++)}()}var Si=Pm;var Of=Z("/ipns/");function Df(r){return ce(r.subarray(0,Of.byteLength),Of)}var Ii=class{client;constructor(e){this.client=e}async*findProviders(e,t={}){yield*Si(this.client.getProviders(e,t),n=>({id:n.ID,multiaddrs:n.Addrs??[]}))}async provide(){}async cancelReprovide(){}async put(e,t,n){if(!Df(e))return;let o=Nt(e),i=X.createV1(114,o),s=dt(t);await this.client.putIPNS(i,s,n)}async get(e,t){if(!Df(e))throw new Re("Not found");let n=Nt(e),o=X.createV1(114,n);try{let i=await this.client.getIPNS(o,t);return cr(i)}catch(i){throw i.name==="BadResponseError"?new Re("Not found"):i}}},ki=class{client;constructor(e){this.client=e}async findPeer(e,t={}){let n=await Ai(this.client.getPeers(e,t));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new Re("Not found")}async*getClosestPeers(e,t={}){}};var Ne=Rt("delegated-routing-v1-http-api-client"),Mf={concurrentRequests:4,timeout:3e4},Ci=class{started;httpQueue;shutDownController;clientUrl;timeout;contentRouting;peerRouting;filterAddrs;filterProtocols;constructor(e,t={}){this.started=!1,this.shutDownController=new AbortController,hr(1/0,this.shutDownController.signal),this.httpQueue=new Un({concurrency:t.concurrentRequests??Mf.concurrentRequests}),this.clientUrl=e instanceof URL?e:new URL(e),this.timeout=t.timeout??Mf.timeout,this.filterAddrs=t.filterAddrs,this.filterProtocols=t.filterProtocols,this.contentRouting=new Ii(this),this.peerRouting=new ki(this)}get[ja](){return this.contentRouting}get[Ga](){return this.peerRouting}isStarted(){return this.started}start(){this.started=!0}stop(){this.httpQueue.clear(),this.shutDownController.abort(),this.started=!1}async*getProviders(e,t={}){Ne("getProviders starts: %c",e);let n=AbortSignal.timeout(this.timeout),o=bn([this.shutDownController.signal,n,t.signal]);hr(1/0,n,o);let i=ht(),s=ht();this.httpQueue.add(async()=>(i.resolve(),s.promise));try{await i.promise;let a=new URL(`${this.clientUrl}routing/v1/providers/${e.toString()}`);this.#t(a,t.filterAddrs,t.filterProtocols);let f=await fetch(a,{headers:{Accept:"application/x-ndjson"},signal:o});if(f.status===404)throw new Re("No matching records found");if(f.status===422)throw new zr("Request does not conform to schema or semantic constraints");if(f.body==null)throw new ur("Routing response had no body");if(f.headers.get("Content-Type")==="application/json"){let l=await f.json();for(let d of l.Providers){let b=this.#e(d);b!=null&&(yield b)}}else for await(let l of kn(oi(f.body))){let d=this.#e(l);d!=null&&(yield d)}}catch(a){Ne.error("getProviders errored:",a)}finally{o.clear(),s.resolve(),Ne("getProviders finished: %c",e)}}async*getPeers(e,t={}){Ne("getPeers starts: %c",e);let n=AbortSignal.timeout(this.timeout),o=bn([this.shutDownController.signal,n,t.signal]);hr(1/0,n,o);let i=ht(),s=ht();this.httpQueue.add(async()=>(i.resolve(),s.promise));try{await i.promise;let a=new URL(`${this.clientUrl}routing/v1/peers/${e.toCID().toString()}`);this.#t(a,t.filterAddrs,t.filterProtocols);let f=await fetch(a,{headers:{Accept:"application/x-ndjson"},signal:o});if(f.status===404)throw new Re("No matching records found");if(f.status===422)throw new zr("Request does not conform to schema or semantic constraints");if(f.body==null)throw new ur("Routing response had no body");if(f.headers.get("Content-Type")==="application/json"){let l=await f.json();for(let d of l.Peers){let b=this.#e(d);b!=null&&(yield b)}}else for await(let l of kn(oi(f.body))){let d=this.#e(l);d!=null&&(yield d)}}catch(a){Ne.error("getPeers errored:",a)}finally{o.clear(),s.resolve(),Ne("getPeers finished: %c",e)}}async getIPNS(e,t={}){Ne("getIPNS starts: %s",e);let n=AbortSignal.timeout(this.timeout),o=bn([this.shutDownController.signal,n,t.signal]);hr(1/0,n,o);let i=ht(),s=ht();this.httpQueue.add(async()=>(i.resolve(),s.promise));let a=`${this.clientUrl}routing/v1/ipns/${e}`;try{await i.promise;let f=await fetch(a,{headers:{Accept:"application/vnd.ipfs.ipns-record"},signal:o});if(Ne("getIPNS GET %s %d",a,f.status),f.status===404)throw new Re("No matching records found");if(f.status===422)throw new zr("Request does not conform to schema or semantic constraints");if(f.body==null)throw new ur("GET ipns response had no body");let u=await f.arrayBuffer(),l=new Uint8Array(u,0,u.byteLength);return t.validate!==!1&&await Rf(In(e.multihash),l),dt(l)}catch(c){throw Ne.error("getIPNS GET %s error:",a,c),c}finally{o.clear(),s.resolve(),Ne("getIPNS finished: %s",e)}}async putIPNS(e,t,n={}){Ne("putIPNS starts: %c",e);let o=AbortSignal.timeout(this.timeout),i=bn([this.shutDownController.signal,o,n.signal]);hr(1/0,o,i);let s=ht(),a=ht();this.httpQueue.add(async()=>(s.resolve(),a.promise));let c=`${this.clientUrl}routing/v1/ipns/${e}`;try{await s.promise;let f=cr(t),l=await fetch(c,{method:"PUT",headers:{"Content-Type":"application/vnd.ipfs.ipns-record"},body:f,signal:i});if(Ne("putIPNS PUT %s %d",c,l.status),l.status!==200)throw new ur("PUT ipns response had status other than 200")}catch(f){throw Ne.error("putIPNS PUT %s error:",c,f.stack),f}finally{i.clear(),a.resolve(),Ne("putIPNS finished: %c",e)}}#e(e){try{let t=[],n=e.Addrs?.map(sr)??[];return e.Protocols!=null&&t.push(...e.Protocols),e.Protocol!=null&&(t.push(e.Protocol),delete e.Protocol),{...e,Schema:"peer",ID:il(e.ID),Addrs:n,Protocols:t}}catch(t){Ne.error("could not conform record to peer schema",t)}}#t(e,t,n){if(t!=null||this.filterAddrs!=null){let o=t?.join(",")??this.filterAddrs?.join(",")??"";o!==""&&e.searchParams.set("filter-addrs",o)}if(n!=null||this.filterProtocols!=null){let o=n?.join(",")??this.filterProtocols?.join(",")??"";o!==""&&e.searchParams.set("filter-protocols",o)}}};function $f(r,e={}){return new Ci(new URL(r),e)}function Hf(){return{filterProtocols:["unknown","transport-bitswap","transport-ipfs-gateway-http"],filterAddrs:["https","webtransport","webrtc","webrtc-direct","wss"]}}var Kf=Z("/ipns/");function qf(r){return ce(r.subarray(0,Kf.byteLength),Kf)}var Ca=class{client;constructor(e,t={}){this.client=$f(e,t)}async provide(e,t){}async*findProviders(e,t){yield*Si(this.client.getProviders(e,t),n=>({id:n.ID,multiaddrs:n.Addrs,protocols:n.Protocols}))}async put(e,t,n){if(!qf(e))return;let o=Nt(e),i=X.createV1(114,o),s=dt(t);await this.client.putIPNS(i,s,n)}async get(e,t){if(!qf(e))throw new Re("Not found");let n=Nt(e),o=X.createV1(114,n);try{let i=await this.client.getIPNS(o,t);return cr(i)}catch(i){throw i.name==="BadResponseError"?new Re("Not found"):i}}async findPeer(e,t){let n=await Ai(this.client.getPeers(e,t));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new Re("Not found")}async*getClosestPeers(e,t){}};function zf(r,e){let t=e??Hf();return new Ca(new URL(r),t)}var jf="[a-fA-F\\d:]",Zt=r=>r&&r.includeBoundaries?`(?:(?<=\\s|^)(?=${jf})|(?<=${jf})(?=\\s|$))`:"",st="(?: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}",ue="[a-fA-F\\d]{1,4}",Ti=`
8
8
  (?:
9
9
  (?:${ue}:){7}(?:${ue}|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8
10
10
  (?:${ue}:){6}(?:${st}|:${ue}|:)| // 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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helia/routers",
3
- "version": "2.1.0-dff82ec",
3
+ "version": "2.1.0-e58e49c",
4
4
  "description": "Routers for Helia",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/ipfs/helia/tree/main/packages/routers#readme",
@@ -55,7 +55,7 @@
55
55
  },
56
56
  "dependencies": {
57
57
  "@helia/delegated-routing-v1-http-api-client": "^4.1.0",
58
- "@helia/interface": "5.0.0-dff82ec",
58
+ "@helia/interface": "5.0.0-e58e49c",
59
59
  "@libp2p/peer-id": "^5.0.0",
60
60
  "@libp2p/interface": "^2.0.0",
61
61
  "@multiformats/uri-to-multiaddr": "^8.0.0",
@@ -67,7 +67,7 @@
67
67
  },
68
68
  "devDependencies": {
69
69
  "@libp2p/crypto": "^5.0.0",
70
- "aegir": "^44.0.1",
70
+ "aegir": "^45.0.1",
71
71
  "it-all": "^3.0.4",
72
72
  "it-drain": "^3.0.5",
73
73
  "sinon-ts": "^2.0.0"