@libp2p/identify 3.0.21-a4f0db1e9 → 3.0.21
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 +1 -1
- package/dist/typedoc-urls.json +18 -0
- package/package.json +8 -8
package/dist/index.min.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
`).map(s=>` ${s}`).join(`
|
|
4
4
|
`));let e=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return t.length?`${e} :
|
|
5
5
|
${t.join(`
|
|
6
|
-
`)}`:`${e} :`}};mc=Oe;B.Constructed=mc;Oe.NAME="CONSTRUCTED";var Gn=class extends Et{fromBER(t,e,n){return e}toBER(t){return Wt}};Gn.override="EndOfContentValueBlock";var gc,Wn=class extends mt{constructor(t={}){super(t,Gn),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};gc=Wn;B.EndOfContent=gc;Wn.NAME=$r;var yc,mr=class extends mt{constructor(t={}){super(t,Et),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(t,e,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,e+n>t.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):e+n}toBER(t,e){let n=new ArrayBuffer(2);if(!t){let s=new Uint8Array(n);s[0]=5,s[1]=0}return e&&e.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};yc=mr;B.Null=yc;mr.NAME="NULL";var jn=class extends we(Et){constructor({value:t,...e}={}){super(e),e.valueHex?this.valueHexView=M.BufferSourceConverter.toUint8Array(e.valueHex):this.valueHexView=new Uint8Array(1),t&&(this.value=t)}get value(){for(let t of this.valueHexView)if(t>0)return!0;return!1}set value(t){this.valueHexView[0]=t?255:0}fromBER(t,e,n){let s=M.BufferSourceConverter.toUint8Array(t);return be(this,s,e,n)?(this.valueHexView=s.subarray(e,e+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,hi.call(this),this.blockLength=n,e+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};jn.NAME="BooleanValueBlock";var bc,Zn=class extends mt{constructor(t={}){super(t,jn),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}getValue(){return this.valueBlock.value}setValue(t){this.valueBlock.value=t}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};bc=Zn;B.Boolean=bc;Zn.NAME="BOOLEAN";var Yn=class extends we(te){constructor({isConstructed:t=!1,...e}={}){super(e),this.isConstructed=t}fromBER(t,e,n){let s=0;if(this.isConstructed){if(this.isHexOnly=!1,s=te.prototype.fromBER.call(this,t,e,n),s===-1)return s;for(let o=0;o<this.value.length;o++){let i=this.value[o].constructor.NAME;if(i===$r){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(i!==fc)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,s=super.fromBER(t,e,n),this.blockLength=n;return s}toBER(t,e){return this.isConstructed?te.prototype.toBER.call(this,t,e):t?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};Yn.NAME="OctetStringValueBlock";var wc,Jn=class r extends mt{constructor({idBlock:t={},lenBlock:e={},...n}={}){var s,o;(s=n.isConstructed)!==null&&s!==void 0||(n.isConstructed=!!(!((o=n.value)===null||o===void 0)&&o.length)),super({idBlock:{isConstructed:n.isConstructed,...t},lenBlock:{...e,isIndefiniteForm:!!n.isIndefiniteForm},...n},Yn),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(t,e,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),e;if(!this.valueBlock.isConstructed){let o=(t instanceof ArrayBuffer?new Uint8Array(t):t).subarray(e,e+n);try{if(o.byteLength){let i=Ss(o,0,o.byteLength);i.offset!==-1&&i.offset===n&&(this.valueBlock.value=[i.result])}}catch{}}return super.fromBER(t,e,n)}onAsciiEncoding(){return this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length?Oe.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${M.Convert.ToHex(this.valueBlock.valueHexView)}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let t=[];for(let e of this.valueBlock.value)e instanceof r&&t.push(e.valueBlock.valueHexView);return M.BufferSourceConverter.concat(t)}};wc=Jn;B.OctetString=wc;Jn.NAME=fc;var Xn=class extends we(te){constructor({unusedBits:t=0,isConstructed:e=!1,...n}={}){super(n),this.unusedBits=t,this.isConstructed=e,this.blockLength=this.valueHexView.byteLength}fromBER(t,e,n){if(!n)return e;let s=-1;if(this.isConstructed){if(s=te.prototype.fromBER.call(this,t,e,n),s===-1)return s;for(let c of this.value){let a=c.constructor.NAME;if(a===$r){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(a!==hc)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let l=c.valueBlock;if(this.unusedBits>0&&l.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=l.unusedBits}return s}let o=M.BufferSourceConverter.toUint8Array(t);if(!be(this,o,e,n))return-1;let i=o.subarray(e,e+n);if(this.unusedBits=i[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let c=i.subarray(1);try{if(c.byteLength){let a=Ss(c,0,c.byteLength);a.offset!==-1&&a.offset===n-1&&(this.value=[a.result])}}catch{}}return this.valueHexView=i.subarray(1),this.blockLength=i.length,e+n}toBER(t,e){if(this.isConstructed)return te.prototype.toBER.call(this,t,e);if(t)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return Wt;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}}};Xn.NAME="BitStringValueBlock";var xc,gr=class extends mt{constructor({idBlock:t={},lenBlock:e={},...n}={}){var s,o;(s=n.isConstructed)!==null&&s!==void 0||(n.isConstructed=!!(!((o=n.value)===null||o===void 0)&&o.length)),super({idBlock:{isConstructed:n.isConstructed,...t},lenBlock:{...e,isIndefiniteForm:!!n.isIndefiniteForm},...n},Xn),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(t,e,n){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(t,e,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return Oe.prototype.onAsciiEncoding.call(this);{let t=[],e=this.valueBlock.valueHexView;for(let s of e)t.push(s.toString(2).padStart(8,"0"));let n=t.join("");return`${this.constructor.NAME} : ${n.substring(0,n.length-this.valueBlock.unusedBits)}`}}};xc=gr;B.BitString=xc;gr.NAME=hc;var vc;function sd(r,t){let e=new Uint8Array([0]),n=new Uint8Array(r),s=new Uint8Array(t),o=n.slice(0),i=o.length-1,c=s.slice(0),a=c.length-1,l=0,u=a<i?i:a,f=0;for(let h=u;h>=0;h--,f++){switch(!0){case f<c.length:l=o[i-f]+c[a-f]+e[0];break;default:l=o[i-f]+e[0]}switch(e[0]=l/10,!0){case f>=o.length:o=Mn(new Uint8Array([l%10]),o);break;default:o[i-f]=l%10}}return e[0]>0&&(o=Mn(e,o)),o}function uc(r){if(r>=Kr.length)for(let t=Kr.length;t<=r;t++){let e=new Uint8Array([0]),n=Kr[t-1].slice(0);for(let s=n.length-1;s>=0;s--){let o=new Uint8Array([(n[s]<<1)+e[0]]);e[0]=o[0]/10,n[s]=o[0]%10}e[0]>0&&(n=Mn(e,n)),Kr.push(n)}return Kr[r]}function od(r,t){let e=0,n=new Uint8Array(r),s=new Uint8Array(t),o=n.slice(0),i=o.length-1,c=s.slice(0),a=c.length-1,l,u=0;for(let f=a;f>=0;f--,u++)switch(l=o[i-u]-c[a-u]-e,!0){case l<0:e=1,o[i-u]=l+10;break;default:e=0,o[i-u]=l}if(e>0)for(let f=i-a+1;f>=0;f--,u++)if(l=o[i-u]-e,l<0)e=1,o[i-u]=l+10;else{e=0,o[i-u]=l;break}return o.slice()}var zr=class extends we(Et){constructor({value:t,...e}={}){super(e),this._valueDec=0,e.valueHex&&this.setValueHex(),t!==void 0&&(this.valueDec=t)}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=hi.call(this)))}set valueDec(t){this._valueDec=t,this.isHexOnly=!1,this.valueHexView=new Uint8Array(ac(t))}get valueDec(){return this._valueDec}fromDER(t,e,n,s=0){let o=this.fromBER(t,e,n);if(o===-1)return o;let i=this.valueHexView;return i[0]===0&&i[1]&128?this.valueHexView=i.subarray(1):s!==0&&i.length<s&&(s-i.length>1&&(s=i.length+1),this.valueHexView=i.subarray(s-i.length)),o}toDER(t=!1){let e=this.valueHexView;switch(!0){case(e[0]&128)!==0:{let n=new Uint8Array(this.valueHexView.length+1);n[0]=0,n.set(e,1),this.valueHexView=n}break;case(e[0]===0&&(e[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(t)}fromBER(t,e,n){let s=super.fromBER(t,e,n);return s===-1||this.setValueHex(),s}toBER(t){return t?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){let t=this.valueHexView.length*8-1,e=new Uint8Array(this.valueHexView.length*8/3),n=0,s,o=this.valueHexView,i="",c=!1;for(let a=o.byteLength-1;a>=0;a--){s=o[a];for(let l=0;l<8;l++){if((s&1)===1)switch(n){case t:e=od(uc(n),e),i="-";break;default:e=sd(e,uc(n))}n++,s>>=1}}for(let a=0;a<e.length;a++)e[a]&&(c=!0),c&&(i+=lc.charAt(e[a]));return c===!1&&(i+=lc.charAt(0)),i}};vc=zr;zr.NAME="IntegerValueBlock";Object.defineProperty(vc.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var Ec,gt=class r extends mt{constructor(t={}){super(t,zr),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return Fn(),BigInt(this.valueBlock.toString())}static fromBigInt(t){Fn();let e=BigInt(t),n=new qr,s=e.toString(16).replace(/^-/,""),o=new Uint8Array(M.Convert.FromHex(s));if(e<0){let c=new Uint8Array(o.length+(o[0]&128?1:0));c[0]|=128;let l=BigInt(`0x${M.Convert.ToHex(c)}`)+e,u=M.BufferSourceConverter.toUint8Array(M.Convert.FromHex(l.toString(16)));u[0]|=128,n.write(u)}else o[0]&128&&n.write(new Uint8Array([0])),n.write(o);return new r({valueHex:n.final()})}convertToDER(){let t=new r({valueHex:this.valueBlock.valueHexView});return t.valueBlock.toDER(),t}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()}`}};Ec=gt;B.Integer=Ec;gt.NAME="INTEGER";var Bc,Qn=class extends gt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};Bc=Qn;B.Enumerated=Bc;Qn.NAME="ENUMERATED";var Gr=class extends we(Et){constructor({valueDec:t=-1,isFirstSid:e=!1,...n}={}){super(n),this.valueDec=t,this.isFirstSid=e}fromBER(t,e,n){if(!n)return e;let s=M.BufferSourceConverter.toUint8Array(t);if(!be(this,s,e,n))return-1;let o=s.subarray(e,e+n);this.valueHexView=new Uint8Array(n);for(let c=0;c<n&&(this.valueHexView[c]=o[c]&127,this.blockLength++,!!(o[c]&128));c++);let i=new Uint8Array(this.blockLength);for(let c=0;c<this.blockLength;c++)i[c]=this.valueHexView[c];return this.valueHexView=i,o[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=Ye(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),e+this.blockLength)}set valueBigInt(t){Fn();let e=BigInt(t).toString(2);for(;e.length%7;)e="0"+e;let n=new Uint8Array(e.length/7);for(let s=0;s<n.length;s++)n[s]=parseInt(e.slice(s*7,s*7+7),2)+(s+1<n.length?128:0);this.fromBER(n.buffer,0,n.length)}toBER(t){if(this.isHexOnly){if(t)return new ArrayBuffer(this.valueHexView.byteLength);let s=this.valueHexView,o=new Uint8Array(this.blockLength);for(let i=0;i<this.blockLength-1;i++)o[i]=s[i]|128;return o[this.blockLength-1]=s[this.blockLength-1],o.buffer}let e=_e(this.valueDec,7);if(e.byteLength===0)return this.error="Error during encoding SID value",Wt;let n=new Uint8Array(e.byteLength);if(!t){let s=new Uint8Array(e),o=e.byteLength-1;for(let i=0;i<o;i++)n[i]=s[i]|128;n[o]=s[o]}return n}toString(){let t="";if(this.isHexOnly)t=M.Convert.ToHex(this.valueHexView);else if(this.isFirstSid){let e=this.valueDec;this.valueDec<=39?t="0.":this.valueDec<=79?(t="1.",e-=40):(t="2.",e-=80),t+=e.toString()}else t=this.valueDec.toString();return t}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}};Gr.NAME="sidBlock";var ts=class extends Et{constructor({value:t=br,...e}={}){super(e),this.value=[],t&&this.fromString(t)}fromBER(t,e,n){let s=e;for(;n>0;){let o=new Gr;if(s=o.fromBER(t,s,n),s===-1)return this.blockLength=0,this.error=o.error,s;this.value.length===0&&(o.isFirstSid=!0),this.blockLength+=o.blockLength,n-=o.blockLength,this.value.push(o)}return s}toBER(t){let e=[];for(let n=0;n<this.value.length;n++){let s=this.value[n].toBER(t);if(s.byteLength===0)return this.error=this.value[n].error,Wt;e.push(s)}return di(e)}fromString(t){this.value=[];let e=0,n=0,s="",o=!1;do if(n=t.indexOf(".",e),n===-1?s=t.substring(e):s=t.substring(e,n),e=n+1,o){let i=this.value[0],c=0;switch(i.valueDec){case 0:break;case 1:c=40;break;case 2:c=80;break;default:this.value=[];return}let a=parseInt(s,10);if(isNaN(a))return;i.valueDec=a+c,o=!1}else{let i=new Gr;if(s>Number.MAX_SAFE_INTEGER){Fn();let c=BigInt(s);i.valueBigInt=c}else if(i.valueDec=parseInt(s,10),isNaN(i.valueDec))return;this.value.length||(i.isFirstSid=!0,o=!0),this.value.push(i)}while(n!==-1)}toString(){let t="",e=!1;for(let n=0;n<this.value.length;n++){e=this.value[n].isHexOnly;let s=this.value[n].toString();n!==0&&(t=`${t}.`),e?(s=`{${s}}`,this.value[n].isFirstSid?t=`2.{${s} - 80}`:t+=s):t+=s}return t}toJSON(){let t={...super.toJSON(),value:this.toString(),sidArray:[]};for(let e=0;e<this.value.length;e++)t.sidArray.push(this.value[e].toJSON());return t}};ts.NAME="ObjectIdentifierValueBlock";var Ac,yr=class extends mt{constructor(t={}){super(t,ts),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}getValue(){return this.valueBlock.toString()}setValue(t){this.valueBlock.fromString(t)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};Ac=yr;B.ObjectIdentifier=Ac;yr.NAME="OBJECT IDENTIFIER";var Wr=class extends we(me){constructor({valueDec:t=0,...e}={}){super(e),this.valueDec=t}fromBER(t,e,n){if(n===0)return e;let s=M.BufferSourceConverter.toUint8Array(t);if(!be(this,s,e,n))return-1;let o=s.subarray(e,e+n);this.valueHexView=new Uint8Array(n);for(let c=0;c<n&&(this.valueHexView[c]=o[c]&127,this.blockLength++,!!(o[c]&128));c++);let i=new Uint8Array(this.blockLength);for(let c=0;c<this.blockLength;c++)i[c]=this.valueHexView[c];return this.valueHexView=i,o[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=Ye(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),e+this.blockLength)}toBER(t){if(this.isHexOnly){if(t)return new ArrayBuffer(this.valueHexView.byteLength);let s=this.valueHexView,o=new Uint8Array(this.blockLength);for(let i=0;i<this.blockLength-1;i++)o[i]=s[i]|128;return o[this.blockLength-1]=s[this.blockLength-1],o.buffer}let e=_e(this.valueDec,7);if(e.byteLength===0)return this.error="Error during encoding SID value",Wt;let n=new Uint8Array(e.byteLength);if(!t){let s=new Uint8Array(e),o=e.byteLength-1;for(let i=0;i<o;i++)n[i]=s[i]|128;n[o]=s[o]}return n.buffer}toString(){let t="";return this.isHexOnly?t=M.Convert.ToHex(this.valueHexView):t=this.valueDec.toString(),t}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};Wr.NAME="relativeSidBlock";var es=class extends Et{constructor({value:t=br,...e}={}){super(e),this.value=[],t&&this.fromString(t)}fromBER(t,e,n){let s=e;for(;n>0;){let o=new Wr;if(s=o.fromBER(t,s,n),s===-1)return this.blockLength=0,this.error=o.error,s;this.blockLength+=o.blockLength,n-=o.blockLength,this.value.push(o)}return s}toBER(t,e){let n=[];for(let s=0;s<this.value.length;s++){let o=this.value[s].toBER(t);if(o.byteLength===0)return this.error=this.value[s].error,Wt;n.push(o)}return di(n)}fromString(t){this.value=[];let e=0,n=0,s="";do{n=t.indexOf(".",e),n===-1?s=t.substring(e):s=t.substring(e,n),e=n+1;let o=new Wr;if(o.valueDec=parseInt(s,10),isNaN(o.valueDec))return!0;this.value.push(o)}while(n!==-1);return!0}toString(){let t="",e=!1;for(let n=0;n<this.value.length;n++){e=this.value[n].isHexOnly;let s=this.value[n].toString();n!==0&&(t=`${t}.`),e&&(s=`{${s}}`),t+=s}return t}toJSON(){let t={...super.toJSON(),value:this.toString(),sidArray:[]};for(let e=0;e<this.value.length;e++)t.sidArray.push(this.value[e].toJSON());return t}};es.NAME="RelativeObjectIdentifierValueBlock";var Sc,rs=class extends mt{constructor(t={}){super(t,es),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}getValue(){return this.valueBlock.toString()}setValue(t){this.valueBlock.fromString(t)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};Sc=rs;B.RelativeObjectIdentifier=Sc;rs.NAME="RelativeObjectIdentifier";var Ic,ge=class extends Oe{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};Ic=ge;B.Sequence=Ic;ge.NAME="SEQUENCE";var kc,ns=class extends Oe{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};kc=ns;B.Set=kc;ns.NAME="SET";var ss=class extends we(Et){constructor({...t}={}){super(t),this.isHexOnly=!0,this.value=br}toJSON(){return{...super.toJSON(),value:this.value}}};ss.NAME="StringValueBlock";var os=class extends ss{};os.NAME="SimpleStringValueBlock";var kt=class extends qn{constructor({...t}={}){super(t,os)}fromBuffer(t){this.valueBlock.value=String.fromCharCode.apply(null,M.BufferSourceConverter.toUint8Array(t))}fromString(t){let e=t.length,n=this.valueBlock.valueHexView=new Uint8Array(e);for(let s=0;s<e;s++)n[s]=t.charCodeAt(s);this.valueBlock.value=t}};kt.NAME="SIMPLE STRING";var is=class extends kt{fromBuffer(t){this.valueBlock.valueHexView=M.BufferSourceConverter.toUint8Array(t);try{this.valueBlock.value=M.Convert.ToUtf8String(t)}catch(e){this.warnings.push(`Error during "decodeURIComponent": ${e}, using raw string`),this.valueBlock.value=M.Convert.ToBinary(t)}}fromString(t){this.valueBlock.valueHexView=new Uint8Array(M.Convert.FromUtf8String(t)),this.valueBlock.value=t}};is.NAME="Utf8StringValueBlock";var Cc,ye=class extends is{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};Cc=ye;B.Utf8String=Cc;ye.NAME="UTF8String";var as=class extends kt{fromBuffer(t){this.valueBlock.value=M.Convert.ToUtf16String(t),this.valueBlock.valueHexView=M.BufferSourceConverter.toUint8Array(t)}fromString(t){this.valueBlock.value=t,this.valueBlock.valueHexView=new Uint8Array(M.Convert.FromUtf16String(t))}};as.NAME="BmpStringValueBlock";var Nc,cs=class extends as{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};Nc=cs;B.BmpString=Nc;cs.NAME="BMPString";var ls=class extends kt{fromBuffer(t){let e=ArrayBuffer.isView(t)?t.slice().buffer:t.slice(0),n=new Uint8Array(e);for(let s=0;s<n.length;s+=4)n[s]=n[s+3],n[s+1]=n[s+2],n[s+2]=0,n[s+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(e))}fromString(t){let e=t.length,n=this.valueBlock.valueHexView=new Uint8Array(e*4);for(let s=0;s<e;s++){let o=_e(t.charCodeAt(s),8),i=new Uint8Array(o);if(i.length>4)continue;let c=4-i.length;for(let a=i.length-1;a>=0;a--)n[s*4+a+c]=i[a]}this.valueBlock.value=t}};ls.NAME="UniversalStringValueBlock";var Tc,us=class extends ls{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};Tc=us;B.UniversalString=Tc;us.NAME="UniversalString";var Uc,fs=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};Uc=fs;B.NumericString=Uc;fs.NAME="NumericString";var Lc,hs=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};Lc=hs;B.PrintableString=Lc;hs.NAME="PrintableString";var Rc,ds=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};Rc=ds;B.TeletexString=Rc;ds.NAME="TeletexString";var Pc,ps=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};Pc=ps;B.VideotexString=Pc;ps.NAME="VideotexString";var _c,ms=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};_c=ms;B.IA5String=_c;ms.NAME="IA5String";var Oc,gs=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};Oc=gs;B.GraphicString=Oc;gs.NAME="GraphicString";var Vc,jr=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};Vc=jr;B.VisibleString=Vc;jr.NAME="VisibleString";var Dc,ys=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};Dc=ys;B.GeneralString=Dc;ys.NAME="GeneralString";var Mc,bs=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};Mc=bs;B.CharacterString=Mc;bs.NAME="CharacterString";var Fc,Zr=class extends jr{constructor({value:t,valueDate:e,...n}={}){if(super(n),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,t){this.fromString(t),this.valueBlock.valueHexView=new Uint8Array(t.length);for(let s=0;s<t.length;s++)this.valueBlock.valueHexView[s]=t.charCodeAt(s)}e&&(this.fromDate(e),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(t){this.fromString(String.fromCharCode.apply(null,M.BufferSourceConverter.toUint8Array(t)))}toBuffer(){let t=this.toString(),e=new ArrayBuffer(t.length),n=new Uint8Array(e);for(let s=0;s<t.length;s++)n[s]=t.charCodeAt(s);return e}fromDate(t){this.year=t.getUTCFullYear(),this.month=t.getUTCMonth()+1,this.day=t.getUTCDate(),this.hour=t.getUTCHours(),this.minute=t.getUTCMinutes(),this.second=t.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(t){let n=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(t);if(n===null){this.error="Wrong input string for conversion";return}let s=parseInt(n[1],10);s>=50?this.year=1900+s:this.year=2e3+s,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(t="iso"){if(t==="iso"){let e=new Array(7);return e[0]=Lt(this.year<2e3?this.year-1900:this.year-2e3,2),e[1]=Lt(this.month,2),e[2]=Lt(this.day,2),e[3]=Lt(this.hour,2),e[4]=Lt(this.minute,2),e[5]=Lt(this.second,2),e[6]="Z",e.join("")}return super.toString(t)}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}}};Fc=Zr;B.UTCTime=Fc;Zr.NAME="UTCTime";var Hc,ws=class extends Zr{constructor(t={}){var e;super(t),(e=this.millisecond)!==null&&e!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(t){super.fromDate(t),this.millisecond=t.getUTCMilliseconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond))}fromString(t){let e=!1,n="",s="",o=0,i,c=0,a=0;if(t[t.length-1]==="Z")n=t.substring(0,t.length-1),e=!0;else{let f=new Number(t[t.length-1]);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");n=t}if(e){if(n.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(n.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let f=1,h=n.indexOf("+"),m="";if(h===-1&&(h=n.indexOf("-"),f=-1),h!==-1){if(m=n.substring(h+1),n=n.substring(0,h),m.length!==2&&m.length!==4)throw new Error("Wrong input string for conversion");let p=parseInt(m.substring(0,2),10);if(isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");if(c=f*p,m.length===4){if(p=parseInt(m.substring(2,4),10),isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");a=f*p}}}let l=n.indexOf(".");if(l===-1&&(l=n.indexOf(",")),l!==-1){let f=new Number(`0${n.substring(l)}`);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");o=f.valueOf(),s=n.substring(0,l)}else s=n;switch(!0){case s.length===8:if(i=/(\d{4})(\d{2})(\d{2})/ig,l!==-1)throw new Error("Wrong input string for conversion");break;case s.length===10:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let f=60*o;this.minute=Math.floor(f),f=60*(f-this.minute),this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case s.length===12:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let f=60*o;this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case s.length===14:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let f=1e3*o;this.millisecond=Math.floor(f)}break;default:throw new Error("Wrong input string for conversion")}let u=i.exec(s);if(u===null)throw new Error("Wrong input string for conversion");for(let f=1;f<u.length;f++)switch(f){case 1:this.year=parseInt(u[f],10);break;case 2:this.month=parseInt(u[f],10);break;case 3:this.day=parseInt(u[f],10);break;case 4:this.hour=parseInt(u[f],10)+c;break;case 5:this.minute=parseInt(u[f],10)+a;break;case 6:this.second=parseInt(u[f],10);break;default:throw new Error("Wrong input string for conversion")}if(e===!1){let f=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=f.getUTCFullYear(),this.month=f.getUTCMonth(),this.day=f.getUTCDay(),this.hour=f.getUTCHours(),this.minute=f.getUTCMinutes(),this.second=f.getUTCSeconds(),this.millisecond=f.getUTCMilliseconds()}}toString(t="iso"){if(t==="iso"){let e=[];return e.push(Lt(this.year,4)),e.push(Lt(this.month,2)),e.push(Lt(this.day,2)),e.push(Lt(this.hour,2)),e.push(Lt(this.minute,2)),e.push(Lt(this.second,2)),this.millisecond!==0&&(e.push("."),e.push(Lt(this.millisecond,3))),e.push("Z"),e.join("")}return super.toString(t)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};Hc=ws;B.GeneralizedTime=Hc;ws.NAME="GeneralizedTime";var Kc,xs=class extends ye{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};Kc=xs;B.DATE=Kc;xs.NAME="DATE";var qc,vs=class extends ye{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};qc=vs;B.TimeOfDay=qc;vs.NAME="TimeOfDay";var $c,Es=class extends ye{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};$c=Es;B.DateTime=$c;Es.NAME="DateTime";var zc,Bs=class extends ye{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};zc=Bs;B.Duration=zc;Bs.NAME="Duration";var Gc,As=class extends ye{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};Gc=As;B.TIME=Gc;As.NAME="TIME";function Q(r,t="utf8"){let e=Pn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Yr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Is=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Wc={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Is("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 t}};var Ve=Wc;async function jc(r){let t=await Ve.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),e=await ad(t);return{privateKey:e[0],publicKey:e[1]}}async function Zc(r,t){let e=await Ve.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await Ve.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},e,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function Yc(r,t,e){let n=await Ve.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return Ve.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,e instanceof Uint8Array?e:e.subarray())}async function ad(r){if(r.privateKey==null||r.publicKey==null)throw new It("Private and public key are required");return Promise.all([Ve.get().subtle.exportKey("jwk",r.privateKey),Ve.get().subtle.exportKey("jwk",r.publicKey)])}function gi(r){if(r.kty!=="RSA")throw new It("invalid key type");if(r.n==null)throw new It("invalid key modulus");return $(r.n,"base64url").length*8}var wr=class{type="RSA";_key;_raw;_multihash;constructor(t,e){this._key=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=Jr.jwkToPkix(this._key)),this._raw}toMultihash(){return this._multihash}toCID(){return dt.createV1(114,this._multihash)}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,e){return Yc(this._key,e,t)}},Xr=class{type="RSA";_key;_raw;publicKey;constructor(t,e){this._key=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=Jr.jwkToPkcs1(this._key)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}sign(t){return Zc(this._key,t)}};var ks=8192,yi=18;function Jc(r){let{result:t}=mi(r),e=t.valueBlock.value;return{n:ee(e[1]),e:ee(e[2]),d:ee(e[3]),p:ee(e[4]),q:ee(e[5]),dp:ee(e[6]),dq:ee(e[7]),qi:ee(e[8]),kty:"RSA",alg:"RS256"}}function cd(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 It("JWK was missing components");let e=new ge({value:[new gt({value:0}),gt.fromBigInt(re($(r.n,"base64url"))),gt.fromBigInt(re($(r.e,"base64url"))),gt.fromBigInt(re($(r.d,"base64url"))),gt.fromBigInt(re($(r.p,"base64url"))),gt.fromBigInt(re($(r.q,"base64url"))),gt.fromBigInt(re($(r.dp,"base64url"))),gt.fromBigInt(re($(r.dq,"base64url"))),gt.fromBigInt(re($(r.qi,"base64url")))]}).toBER();return new Uint8Array(e,0,e.byteLength)}function Xc(r){let{result:t}=mi(r),e=t.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:ee(e[0]),e:ee(e[1])}}function bi(r){if(r.n==null||r.e==null)throw new It("JWK was missing components");let e=new ge({value:[new ge({value:[new yr({value:"1.2.840.113549.1.1.1"}),new mr]}),new gr({valueHex:new ge({value:[gt.fromBigInt(re($(r.n,"base64url"))),gt.fromBigInt(re($(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(e,0,e.byteLength)}function ee(r){let t=r.valueBlock.valueHexView;for(;t[0]===0;)t=t.subarray(1);return Q(t,"base64url")}function re(r){let t=[];return r.forEach(function(e){let n=e.toString(16);n.length%2>0&&(n=`0${n}`),t.push(n)}),BigInt("0x"+t.join(""))}function Qc(r){let t=Jc(r);return tl(t)}function wi(r){let t=Xc(r);if(gi(t)>ks)throw new rr("Key size is too large");let e=dr(Qt.encode({Type:ct.RSA,Data:r})),n=Mt(yi,e);return new wr(t,n)}function tl(r){if(gi(r)>ks)throw new It("Key size is too large");let t=rl(r),e=dr(Qt.encode({Type:ct.RSA,Data:bi(t.publicKey)})),n=Mt(yi,e);return new Xr(t.privateKey,new wr(t.publicKey,n))}async function el(r){if(r>ks)throw new It("Key size is too large");let t=await jc(r),e=dr(Qt.encode({Type:ct.RSA,Data:bi(t.publicKey)})),n=Mt(yi,e);return new Xr(t.privateKey,new wr(t.publicKey,n))}function rl(r){if(r==null)throw new It("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}var Cs=class extends lr{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Ba(t);let n=Pr(e);if(this.iHash=t.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 s=this.blockLen,o=new Uint8Array(s);o.set(n.length>s?t.create().update(n).digest():n);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=t.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),o.fill(0)}update(t){return cr(this),this.iHash.update(t),this}digestInto(t){cr(this),ar(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:s,destroyed:o,blockLen:i,outputLen:c}=this;return t=t,t.finished=s,t.destroyed=o,t.blockLen=i,t.outputLen=c,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},xi=(r,t,e)=>new Cs(r,t).update(e).digest();xi.create=(r,t)=>new Cs(r,t);function nl(r){r.lowS!==void 0&&Ht("lowS",r.lowS),r.prehash!==void 0&&Ht("prehash",r.prehash)}function ld(r){let t=Vr(r);Xt(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:s}=t;if(e){if(!n.eql(s,n.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:ud,hexToBytes:fd}=An,vi=class extends Error{constructor(t=""){super(t)}},xe={Err:vi,_tlv:{encode:(r,t)=>{let{Err:e}=xe;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,s=Ke(n);if(s.length/2&128)throw new e("tlv.encode: long form length too big");let o=n>127?Ke(s.length/2|128):"";return Ke(r)+o+s+t},decode(r,t){let{Err:e}=xe,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let s=t[n++],o=!!(s&128),i=0;if(!o)i=s;else{let a=s&127;if(!a)throw new e("tlv.decode(long): indefinite length not supported");if(a>4)throw new e("tlv.decode(long): byte length is too big");let l=t.subarray(n,n+a);if(l.length!==a)throw new e("tlv.decode: length bytes not complete");if(l[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let u of l)i=i<<8|u;if(n+=a,i<128)throw new e("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new e("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=xe;if(r<ve)throw new t("integer: negative integers are not allowed");let e=Ke(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=xe;if(r[0]&128)throw new t("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return ud(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=xe,s=typeof r=="string"?fd(r):r;fr(s);let{v:o,l:i}=n.decode(48,s);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,o),{v:l,l:u}=n.decode(2,a);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(c),s:e.decode(l)}},hexFromSig(r){let{_tlv:t,_int:e}=xe,n=t.encode(2,e.encode(r.r)),s=t.encode(2,e.encode(r.s)),o=n+s;return t.encode(48,o)}},ve=BigInt(0),ft=BigInt(1),Vg=BigInt(2),sl=BigInt(3),Dg=BigInt(4);function hd(r){let t=ld(r),{Fp:e}=t,n=Te(t.n,t.nBitLength),s=t.toBytes||((b,d,v)=>{let A=d.toAffine();return he(Uint8Array.from([4]),e.toBytes(A.x),e.toBytes(A.y))}),o=t.fromBytes||(b=>{let d=b.subarray(1),v=e.fromBytes(d.subarray(0,e.BYTES)),A=e.fromBytes(d.subarray(e.BYTES,2*e.BYTES));return{x:v,y:A}});function i(b){let{a:d,b:v}=t,A=e.sqr(b),y=e.mul(A,b);return e.add(e.add(y,e.mul(b,d)),v)}if(!e.eql(e.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function c(b){return _r(b,ft,t.n)}function a(b){let{allowedPrivateKeyLengths:d,nByteLength:v,wrapPrivateKey:A,n:y}=t;if(d&&typeof b!="bigint"){if(ke(b)&&(b=ue(b)),typeof b!="string"||!d.includes(b.length))throw new Error("invalid private key");b=b.padStart(v*2,"0")}let I;try{I=typeof b=="bigint"?b:fe(nt("private key",b,v))}catch{throw new Error("invalid private key, expected hex or "+v+" bytes, got "+typeof b)}return A&&(I=Z(I,y)),Nt("private key",I,ft,y),I}function l(b){if(!(b instanceof h))throw new Error("ProjectivePoint expected")}let u=ze((b,d)=>{let{px:v,py:A,pz:y}=b;if(e.eql(y,e.ONE))return{x:v,y:A};let I=b.is0();d==null&&(d=I?e.ONE:e.inv(y));let L=e.mul(v,d),U=e.mul(A,d),k=e.mul(y,d);if(I)return{x:e.ZERO,y:e.ZERO};if(!e.eql(k,e.ONE))throw new Error("invZ was invalid");return{x:L,y:U}}),f=ze(b=>{if(b.is0()){if(t.allowInfinityPoint&&!e.is0(b.py))return;throw new Error("bad point: ZERO")}let{x:d,y:v}=b.toAffine();if(!e.isValid(d)||!e.isValid(v))throw new Error("bad point: x or y not FE");let A=e.sqr(v),y=i(d);if(!e.eql(A,y))throw new Error("bad point: equation left != right");if(!b.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class h{constructor(d,v,A){if(this.px=d,this.py=v,this.pz=A,d==null||!e.isValid(d))throw new Error("x required");if(v==null||!e.isValid(v))throw new Error("y required");if(A==null||!e.isValid(A))throw new Error("z required");Object.freeze(this)}static fromAffine(d){let{x:v,y:A}=d||{};if(!d||!e.isValid(v)||!e.isValid(A))throw new Error("invalid affine point");if(d instanceof h)throw new Error("projective point not allowed");let y=I=>e.eql(I,e.ZERO);return y(v)&&y(A)?h.ZERO:new h(v,A,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){let v=e.invertBatch(d.map(A=>A.pz));return d.map((A,y)=>A.toAffine(v[y])).map(h.fromAffine)}static fromHex(d){let v=h.fromAffine(o(nt("pointHex",d)));return v.assertValidity(),v}static fromPrivateKey(d){return h.BASE.multiply(a(d))}static msm(d,v){return Cn(h,n,d,v)}_setWindowSize(d){p.setWindowSize(this,d)}assertValidity(){f(this)}hasEvenY(){let{y:d}=this.toAffine();if(e.isOdd)return!e.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){l(d);let{px:v,py:A,pz:y}=this,{px:I,py:L,pz:U}=d,k=e.eql(e.mul(v,U),e.mul(I,y)),T=e.eql(e.mul(A,U),e.mul(L,y));return k&&T}negate(){return new h(this.px,e.neg(this.py),this.pz)}double(){let{a:d,b:v}=t,A=e.mul(v,sl),{px:y,py:I,pz:L}=this,U=e.ZERO,k=e.ZERO,T=e.ZERO,C=e.mul(y,y),tt=e.mul(I,I),q=e.mul(L,L),D=e.mul(y,I);return D=e.add(D,D),T=e.mul(y,L),T=e.add(T,T),U=e.mul(d,T),k=e.mul(A,q),k=e.add(U,k),U=e.sub(tt,k),k=e.add(tt,k),k=e.mul(U,k),U=e.mul(D,U),T=e.mul(A,T),q=e.mul(d,q),D=e.sub(C,q),D=e.mul(d,D),D=e.add(D,T),T=e.add(C,C),C=e.add(T,C),C=e.add(C,q),C=e.mul(C,D),k=e.add(k,C),q=e.mul(I,L),q=e.add(q,q),C=e.mul(q,D),U=e.sub(U,C),T=e.mul(q,tt),T=e.add(T,T),T=e.add(T,T),new h(U,k,T)}add(d){l(d);let{px:v,py:A,pz:y}=this,{px:I,py:L,pz:U}=d,k=e.ZERO,T=e.ZERO,C=e.ZERO,tt=t.a,q=e.mul(t.b,sl),D=e.mul(v,I),it=e.mul(A,L),E=e.mul(y,U),N=e.add(v,A),w=e.add(I,L);N=e.mul(N,w),w=e.add(D,it),N=e.sub(N,w),w=e.add(v,y);let g=e.add(I,U);return w=e.mul(w,g),g=e.add(D,E),w=e.sub(w,g),g=e.add(A,y),k=e.add(L,U),g=e.mul(g,k),k=e.add(it,E),g=e.sub(g,k),C=e.mul(tt,w),k=e.mul(q,E),C=e.add(k,C),k=e.sub(it,C),C=e.add(it,C),T=e.mul(k,C),it=e.add(D,D),it=e.add(it,D),E=e.mul(tt,E),w=e.mul(q,w),it=e.add(it,E),E=e.sub(D,E),E=e.mul(tt,E),w=e.add(w,E),D=e.mul(it,w),T=e.add(T,D),D=e.mul(g,w),k=e.mul(N,k),k=e.sub(k,D),D=e.mul(N,it),C=e.mul(g,C),C=e.add(C,D),new h(k,T,C)}subtract(d){return this.add(d.negate())}is0(){return this.equals(h.ZERO)}wNAF(d){return p.wNAFCached(this,d,h.normalizeZ)}multiplyUnsafe(d){let{endo:v,n:A}=t;Nt("scalar",d,ve,A);let y=h.ZERO;if(d===ve)return y;if(this.is0()||d===ft)return this;if(!v||p.hasPrecomputes(this))return p.wNAFCachedUnsafe(this,d,h.normalizeZ);let{k1neg:I,k1:L,k2neg:U,k2:k}=v.splitScalar(d),T=y,C=y,tt=this;for(;L>ve||k>ve;)L&ft&&(T=T.add(tt)),k&ft&&(C=C.add(tt)),tt=tt.double(),L>>=ft,k>>=ft;return I&&(T=T.negate()),U&&(C=C.negate()),C=new h(e.mul(C.px,v.beta),C.py,C.pz),T.add(C)}multiply(d){let{endo:v,n:A}=t;Nt("scalar",d,ft,A);let y,I;if(v){let{k1neg:L,k1:U,k2neg:k,k2:T}=v.splitScalar(d),{p:C,f:tt}=this.wNAF(U),{p:q,f:D}=this.wNAF(T);C=p.constTimeNegate(L,C),q=p.constTimeNegate(k,q),q=new h(e.mul(q.px,v.beta),q.py,q.pz),y=C.add(q),I=tt.add(D)}else{let{p:L,f:U}=this.wNAF(d);y=L,I=U}return h.normalizeZ([y,I])[0]}multiplyAndAddUnsafe(d,v,A){let y=h.BASE,I=(U,k)=>k===ve||k===ft||!U.equals(y)?U.multiplyUnsafe(k):U.multiply(k),L=I(this,v).add(I(d,A));return L.is0()?void 0:L}toAffine(d){return u(this,d)}isTorsionFree(){let{h:d,isTorsionFree:v}=t;if(d===ft)return!0;if(v)return v(h,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:d,clearCofactor:v}=t;return d===ft?this:v?v(h,this):this.multiplyUnsafe(t.h)}toRawBytes(d=!0){return Ht("isCompressed",d),this.assertValidity(),s(h,this,d)}toHex(d=!0){return Ht("isCompressed",d),ue(this.toRawBytes(d))}}h.BASE=new h(t.Gx,t.Gy,e.ONE),h.ZERO=new h(e.ZERO,e.ONE,e.ZERO);let m=t.nBitLength,p=kn(h,t.endo?Math.ceil(m/2):m);return{CURVE:t,ProjectivePoint:h,normPrivateKeyToScalar:a,weierstrassEquation:i,isWithinCurveOrder:c}}function dd(r){let t=Vr(r);return Xt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function ol(r){let t=dd(r),{Fp:e,n}=t,s=e.BYTES+1,o=2*e.BYTES+1;function i(E){return Z(E,n)}function c(E){return Sn(E,n)}let{ProjectivePoint:a,normPrivateKeyToScalar:l,weierstrassEquation:u,isWithinCurveOrder:f}=hd({...t,toBytes(E,N,w){let g=N.toAffine(),x=e.toBytes(g.x),S=he;return Ht("isCompressed",w),w?S(Uint8Array.from([N.hasEvenY()?2:3]),x):S(Uint8Array.from([4]),x,e.toBytes(g.y))},fromBytes(E){let N=E.length,w=E[0],g=E.subarray(1);if(N===s&&(w===2||w===3)){let x=fe(g);if(!_r(x,ft,e.ORDER))throw new Error("Point is not on curve");let S=u(x),R;try{R=e.sqrt(S)}catch(F){let _=F instanceof Error?": "+F.message:"";throw new Error("Point is not on curve"+_)}let P=(R&ft)===ft;return(w&1)===1!==P&&(R=e.neg(R)),{x,y:R}}else if(N===o&&w===4){let x=e.fromBytes(g.subarray(0,e.BYTES)),S=e.fromBytes(g.subarray(e.BYTES,2*e.BYTES));return{x,y:S}}else{let x=s,S=o;throw new Error("invalid Point, expected length of "+x+", or uncompressed "+S+", got "+N)}}}),h=E=>ue(Ne(E,t.nByteLength));function m(E){let N=n>>ft;return E>N}function p(E){return m(E)?i(-E):E}let b=(E,N,w)=>fe(E.slice(N,w));class d{constructor(N,w,g){this.r=N,this.s=w,this.recovery=g,this.assertValidity()}static fromCompact(N){let w=t.nByteLength;return N=nt("compactSignature",N,w*2),new d(b(N,0,w),b(N,w,2*w))}static fromDER(N){let{r:w,s:g}=xe.toSig(nt("DER",N));return new d(w,g)}assertValidity(){Nt("r",this.r,ft,n),Nt("s",this.s,ft,n)}addRecoveryBit(N){return new d(this.r,this.s,N)}recoverPublicKey(N){let{r:w,s:g,recovery:x}=this,S=U(nt("msgHash",N));if(x==null||![0,1,2,3].includes(x))throw new Error("recovery id invalid");let R=x===2||x===3?w+t.n:w;if(R>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let P=x&1?"03":"02",V=a.fromHex(P+h(R)),F=c(R),_=i(-S*F),j=i(g*F),J=a.BASE.multiplyAndAddUnsafe(V,_,j);if(!J)throw new Error("point at infinify");return J.assertValidity(),J}hasHighS(){return m(this.s)}normalizeS(){return this.hasHighS()?new d(this.r,i(-this.s),this.recovery):this}toDERRawBytes(){return qe(this.toDERHex())}toDERHex(){return xe.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return qe(this.toCompactHex())}toCompactHex(){return h(this.r)+h(this.s)}}let v={isValidPrivateKey(E){try{return l(E),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let E=Ao(t.n);return Oa(t.randomBytes(E),t.n)},precompute(E=8,N=a.BASE){return N._setWindowSize(E),N.multiply(BigInt(3)),N}};function A(E,N=!0){return a.fromPrivateKey(E).toRawBytes(N)}function y(E){let N=ke(E),w=typeof E=="string",g=(N||w)&&E.length;return N?g===s||g===o:w?g===2*s||g===2*o:E instanceof a}function I(E,N,w=!0){if(y(E))throw new Error("first arg must be private key");if(!y(N))throw new Error("second arg must be public key");return a.fromHex(N).multiply(l(E)).toRawBytes(w)}let L=t.bits2int||function(E){if(E.length>8192)throw new Error("input is too large");let N=fe(E),w=E.length*8-t.nBitLength;return w>0?N>>BigInt(w):N},U=t.bits2int_modN||function(E){return i(L(E))},k=Or(t.nBitLength);function T(E){return Nt("num < 2^"+t.nBitLength,E,ve,k),Ne(E,t.nByteLength)}function C(E,N,w=tt){if(["recovered","canonical"].some(ut=>ut in w))throw new Error("sign() legacy options not supported");let{hash:g,randomBytes:x}=t,{lowS:S,prehash:R,extraEntropy:P}=w;S==null&&(S=!0),E=nt("msgHash",E),nl(w),R&&(E=nt("prehashed msgHash",g(E)));let V=U(E),F=l(N),_=[T(F),T(V)];if(P!=null&&P!==!1){let ut=P===!0?x(e.BYTES):P;_.push(nt("extraEntropy",ut))}let j=he(..._),J=V;function lt(ut){let ht=L(ut);if(!f(ht))return;let yt=c(ht),Ct=a.BASE.multiply(ht).toAffine(),At=i(Ct.x);if(At===ve)return;let Jt=i(yt*i(J+At*F));if(Jt===ve)return;let oe=(Ct.x===At?0:2)|Number(Ct.y&ft),Nr=Jt;return S&&m(Jt)&&(Nr=p(Jt),oe^=1),new d(At,Nr,oe)}return{seed:j,k2sig:lt}}let tt={lowS:t.lowS,prehash:!1},q={lowS:t.lowS,prehash:!1};function D(E,N,w=tt){let{seed:g,k2sig:x}=C(E,N,w),S=t;return xo(S.hash.outputLen,S.nByteLength,S.hmac)(g,x)}a.BASE._setWindowSize(8);function it(E,N,w,g=q){let x=E;N=nt("msgHash",N),w=nt("publicKey",w);let{lowS:S,prehash:R,format:P}=g;if(nl(g),"strict"in g)throw new Error("options.strict was renamed to lowS");if(P!==void 0&&P!=="compact"&&P!=="der")throw new Error("format must be compact or der");let V=typeof x=="string"||ke(x),F=!V&&!P&&typeof x=="object"&&x!==null&&typeof x.r=="bigint"&&typeof x.s=="bigint";if(!V&&!F)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let _,j;try{if(F&&(_=new d(x.r,x.s)),V){try{P!=="compact"&&(_=d.fromDER(x))}catch(oe){if(!(oe instanceof xe.Err))throw oe}!_&&P!=="der"&&(_=d.fromCompact(x))}j=a.fromHex(w)}catch{return!1}if(!_||S&&_.hasHighS())return!1;R&&(N=t.hash(N));let{r:J,s:lt}=_,ut=U(N),ht=c(lt),yt=i(ut*ht),Ct=i(J*ht),At=a.BASE.multiplyAndAddUnsafe(j,yt,Ct)?.toAffine();return At?i(At.x)===J:!1}return{CURVE:t,getPublicKey:A,getSharedSecret:I,sign:D,verify:it,ProjectivePoint:a,Signature:d,utils:v}}function pd(r){return{hash:r,hmac:(t,...e)=>xi(r,t,ho(...e)),randomBytes:xn}}function il(r,t){let e=n=>ol({...r,...pd(n)});return{...e(t),create:e}}var ll=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),al=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),md=BigInt(1),Ei=BigInt(2),cl=(r,t)=>(r+t/Ei)/t;function gd(r){let t=ll,e=BigInt(3),n=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),l=r*r*r%t,u=l*l*r%t,f=rt(u,e,t)*u%t,h=rt(f,e,t)*u%t,m=rt(h,Ei,t)*l%t,p=rt(m,s,t)*m%t,b=rt(p,o,t)*p%t,d=rt(b,c,t)*b%t,v=rt(d,a,t)*d%t,A=rt(v,c,t)*b%t,y=rt(A,e,t)*u%t,I=rt(y,i,t)*p%t,L=rt(I,n,t)*l%t,U=rt(L,Ei,t);if(!Bi.eql(Bi.sqr(U),r))throw new Error("Cannot find square root");return U}var Bi=Te(ll,void 0,void 0,{sqrt:gd}),Je=il({a:BigInt(0),b:BigInt(7),Fp:Bi,n:al,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=al,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-md*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=e,i=BigInt("0x100000000000000000000000000000000"),c=cl(o*r,t),a=cl(-n*r,t),l=Z(r-c*e-a*s,t),u=Z(-c*n-a*o,t),f=l>i,h=u>i;if(f&&(l=t-l),h&&(u=t-u),l>i||u>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:l,k2neg:h,k2:u}}}},dr),Wg=BigInt(0);var jg=Je.ProjectivePoint;function _t(r,t){t==null&&(t=r.reduce((s,o)=>s+o.length,0));let e=Ut(t),n=0;for(let s of r)e.set(s,n),n+=s.length;return e}function ul(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function fl(r,t,e){let n=Dr.digest(e instanceof Uint8Array?e:e.subarray());if(ul(n))return n.then(({digest:s})=>Je.verify(t,s,r)).catch(s=>{throw new Yr(String(s))});try{return Je.verify(t,n.digest,r)}catch(s){throw new Yr(String(s))}}var Ns=class{type="secp256k1";raw;_key;constructor(t){this._key=dl(t),this.raw=hl(this._key)}toMultihash(){return ce.digest(Ue(this))}toCID(){return dt.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,e){return fl(this._key,e,t)}};function Ai(r){return new Ns(r)}function hl(r){return Je.ProjectivePoint.fromHex(r).toRawBytes(!0)}function dl(r){try{return Je.ProjectivePoint.fromHex(r),r}catch(t){throw new rr(String(t))}}function xr(r){let{Type:t,Data:e}=Qt.decode(r),n=e??new Uint8Array;switch(t){case ct.RSA:return wi(n);case ct.Ed25519:return Uo(n);case ct.secp256k1:return Ai(n);default:throw new Me}}function pl(r){let{Type:t,Data:e}=Qt.decode(r.digest),n=e??new Uint8Array;switch(t){case ct.Ed25519:return Uo(n);case ct.secp256k1:return Ai(n);default:throw new Me}}function Ue(r){return Qt.encode({Type:ct[r.type],Data:r.raw})}var gl=Symbol.for("@achingbrain/uint8arraylist");function ml(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let s=e+n.byteLength;if(t<s)return{buf:n,index:t-e};e=s}throw new RangeError("index is out of bounds")}function Ts(r){return!!r?.[gl]}var jt=class r{bufs;length;[gl]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(Ts(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(Ts(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=ml(this.bufs,t);return e.buf[e.index]}set(t,e){let n=ml(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(Ts(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:s}=this._subList(t,e);return _t(n,s)}subarray(t,e){let{bufs:n,length:s}=this._subList(t,e);return n.length===1?n[0]:_t(n,s)}sublist(t,e){let{bufs:n,length:s}=this._subList(t,e),o=new r;return o.length=s,o.bufs=[...n],o}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],s=0;for(let o=0;o<this.bufs.length;o++){let i=this.bufs[o],c=s,a=c+i.byteLength;if(s=a,t>=a)continue;let l=t>=c&&t<a,u=e>c&&e<=a;if(l&&u){if(t===c&&e===a){n.push(i);break}let f=t-c;n.push(i.subarray(f,f+(e-t)));break}if(l){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(u){if(e===a){n.push(i);break}n.push(i.subarray(0,e-c));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Ts(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let o=256,i=new Int32Array(o);for(let f=0;f<o;f++)i[f]=-1;for(let f=0;f<s;f++)i[n[f]]=f;let c=i,a=this.byteLength-n.byteLength,l=n.byteLength-1,u;for(let f=e;f<=a;f+=u){u=0;for(let h=l;h>=0;h--){let m=this.get(f+h);if(n[h]!==m){u=Math.max(1,h-c[m]);break}}if(u===0)return f}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=Ut(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let s=pt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,e,n),this.write(s,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let s=pt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,e,n),this.write(s,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let s=pt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,e,n),this.write(s,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=Ut(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let s=pt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,e,n),this.write(s,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let s=pt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,e,n),this.write(s,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let s=pt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,e,n),this.write(s,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let s=pt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,e,n),this.write(s,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let s=pt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,e,n),this.write(s,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!bt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((s,o)=>s+o.byteLength,0)),n.length=e,n}};var Qr;(function(r){let t;r.codec=()=>(t==null&&(t=Gt((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.publicKey!=null&&e.publicKey.byteLength>0&&(n.uint32(10),n.bytes(e.publicKey)),e.payloadType!=null&&e.payloadType.byteLength>0&&(n.uint32(18),n.bytes(e.payloadType)),e.payload!=null&&e.payload.byteLength>0&&(n.uint32(26),n.bytes(e.payload)),e.signature!=null&&e.signature.byteLength>0&&(n.uint32(42),n.bytes(e.signature)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let o={publicKey:pt(0),payloadType:pt(0),payload:pt(0),signature:pt(0)},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let c=e.uint32();switch(c>>>3){case 1:{o.publicKey=e.bytes();break}case 2:{o.payloadType=e.bytes();break}case 3:{o.payload=e.bytes();break}case 5:{o.signature=e.bytes();break}default:{e.skipType(c&7);break}}}return o})),t),r.encode=e=>zt(e,r.codec()),r.decode=(e,n)=>$t(e,r.codec(),n)})(Qr||(Qr={}));var Us=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var ne=class r{static createFromProtobuf=async t=>{let e=Qr.decode(t),n=xr(e.publicKey);return new r({publicKey:n,payloadType:e.payloadType,payload:e.payload,signature:e.signature})};static seal=async(t,e)=>{if(e==null)throw new Error("Missing private key");let n=t.domain,s=t.codec,o=t.marshal(),i=yl(n,s,o),c=await e.sign(i.subarray());return new r({publicKey:e.publicKey,payloadType:s,payload:o,signature:c})};static openAndCertify=async(t,e)=>{let n=await r.createFromProtobuf(t);if(!await n.validate(e))throw new Us("Envelope signature is not valid for the given domain");return n};publicKey;payloadType;payload;signature;marshaled;constructor(t){let{publicKey:e,payloadType:n,payload:s,signature:o}=t;this.publicKey=e,this.payloadType=n,this.payload=s,this.signature=o}marshal(){return this.marshaled==null&&(this.marshaled=Qr.encode({publicKey:Ue(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return bt(this.marshal(),t.marshal())}async validate(t){let e=yl(t,this.payloadType,this.payload);return this.publicKey.verify(e.subarray(),this.signature)}},yl=(r,t,e)=>{let n=$(r),s=Ot(n.byteLength),o=Ot(t.length),i=Ot(e.length);return new jt(s,n,o,t,i,e)};var bl=Symbol.for("nodejs.util.inspect.custom"),yd=114,tn=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[eo]=!0;toString(){return this.string==null&&(this.string=X.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return dt.createV1(yd,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return bt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return bt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[bl](){return`PeerId(${this.toString()})`}},en=class extends tn{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},rn=class extends tn{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},nn=class extends tn{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},bd=2336,sn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=ce.digest($(this.url))}[bl](){return`PeerId(${this.url})`}[eo]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return dt.createV1(bd,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=Q(t)),t.toString()===this.toString())}};var wd=114,wl=2336;function xl(r){if(r.type==="Ed25519")return new rn({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new nn({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new en({multihash:r.toCID().multihash,publicKey:r});throw new Me}function Si(r){if(vd(r))return new en({multihash:r});if(xd(r))try{let t=pl(r);if(t.type==="Ed25519")return new rn({multihash:r,publicKey:t});if(t.type==="secp256k1")return new nn({multihash:r,publicKey:t})}catch{let e=Q(r.digest);return new sn(new URL(e))}throw new pn("Supplied PeerID Multihash is invalid")}function Ls(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==wd&&r.code!==wl)throw new dn("Supplied PeerID CID is invalid");if(r.code===wl){let t=Q(r.multihash.digest);return new sn(new URL(t))}return Si(r.multihash)}function xd(r){return r.code===ce.code}function vd(r){return r.code===Dr.code}function vl(r,t){let e=(n,s)=>n.toString().localeCompare(s.toString());return r.length!==t.length?!1:(t.sort(e),r.sort(e).every((n,s)=>t[s].equals(n)))}var Rs=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}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(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,s){return this.readAtomically(()=>{let o=0,i=0,c=this.peekChar();if(c===void 0)return;let a=c==="0",l=2**(8*s)-1;for(;;){let u=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let h=Number.parseInt(f,t);if(!Number.isNaN(h))return h});if(u===void 0)break;if(o*=t,o+=u,o>l||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&a&&i>1?void 0:o})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let s=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[s]=i[0],e[s+1]=i[1],e[s+2]=i[2],e[s+3]=i[3],[s+4,!0]}let o=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(o===void 0)return[s,!1];e[s]=o>>8,e[s+1]=o&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,s]=t(e);if(n===16)return e;if(s||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let o=new Uint8Array(14),i=16-(n+2),[c]=t(o.subarray(0,i));return e.set(o.subarray(0,c),16-c),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var El=45,Ed=15,vr=new Rs;function Ps(r){if(!(r.length>Ed))return vr.new(r).parseWith(()=>vr.readIPv4Addr())}function _s(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>El))return vr.new(r).parseWith(()=>vr.readIPv6Addr())}function Xe(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>El)return;let e=vr.new(r).parseWith(()=>vr.readIPAddr());if(e)return t&&e.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,e[0],e[1],e[2],e[3]]):e}function Bl(r,t,e){let n=0;for(let s of r)if(!(n<t)){if(n>e)break;if(s!==255)return!1;n++}return!0}function Al(r,t,e,n){let s=0;for(let o of r)if(!(s<e)){if(s>n)break;if(o!==t[s])return!1;s++}return!0}function Ii(r){switch(r.length){case Qe:return r.join(".");case tr:{let t=[];for(let e=0;e<r.length;e++)e%2===0&&t.push(r[e].toString(16).padStart(2,"0")+r[e+1].toString(16).padStart(2,"0"));return t.join(":")}default:throw new Error("Invalid ip length")}}function Sl(r){let t=0;for(let[e,n]of r.entries()){if(n===255){t+=8;continue}for(;n&128;)t++,n=n<<1;if(n&128)return-1;for(let s=e+1;s<r.length;s++)if(r[s]!=0)return-1;break}return t}function Il(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var Qe=4,tr=16,Bb=parseInt("0xFFFF",16),Bd=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function on(r,t){t.length===tr&&r.length===Qe&&Bl(t,0,11)&&(t=t.slice(12)),t.length===Qe&&r.length===tr&&Al(r,Bd,0,11)&&(r=r.slice(12));let e=r.length;if(e!=t.length)throw new Error("Failed to mask ip");let n=new Uint8Array(e);for(let s=0;s<e;s++)n[s]=r[s]&t[s];return n}function kl(r,t){if(typeof t=="string"&&(t=Xe(t)),t==null)throw new Error("Invalid ip");if(t.length!==r.network.length)return!1;for(let e=0;e<t.length;e++)if((r.network[e]&r.mask[e])!==(t[e]&r.mask[e]))return!1;return!0}function ki(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=Qe,s=Ps(t);if(s==null&&(n=tr,s=_s(t),s==null))throw new Error("Failed to parse given CIDR: "+r);let o=parseInt(e,10);if(Number.isNaN(o)||String(o).length!==e.length||o<0||o>n*8)throw new Error("Failed to parse given CIDR: "+r);let i=Ci(o,8*n);return{network:on(s,i),mask:i}}function Ci(r,t){if(t!==8*Qe&&t!==8*tr)throw new Error("Invalid CIDR mask");if(r<0||r>t)throw new Error("Invalid CIDR mask");let e=t/8,n=new Uint8Array(e);for(let s=0;s<e;s++){if(r>=8){n[s]=255,r-=8;continue}n[s]=255-(255>>r),r=0}return n}var Er=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=ki(t));else{let n=Xe(t);if(n==null)throw new Error("Failed to parse network");e=String(e);let s=parseInt(e,10);if(Number.isNaN(s)||String(s).length!==e.length||s<0||s>n.length*8){let o=Xe(e);if(o==null)throw new Error("Failed to parse mask");this.mask=o}else this.mask=Ci(s,8*n.length);this.network=on(n,this.mask)}}contains(t){return kl({network:this.network,mask:this.mask},t)}toString(){let t=Sl(this.mask),e=t!==-1?String(t):Il(this.mask);return Ii(this.network)+"/"+e}};function Cl(r,t){return new Er(r).contains(t)}function Br(r){return!!Ps(r)}function Ar(r){return!!_s(r)}function Os(r){return!!Xe(r)}var Nl=Br,Ad=Ar,Ni=function(r){let t=0;if(r=r.toString().trim(),Nl(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(Ad(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let o=Nl(e[n]),i;o&&(i=Ni(e[n]),e[n]=Q(i.slice(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,Q(i.slice(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let o=[n,1];for(n=9-e.length;n>0;n--)o.push("0");e.splice.apply(e,o)}let s=new Uint8Array(t+16);for(n=0;n<e.length;n++){let o=parseInt(e[n],16);s[t++]=o>>8&255,s[t++]=o&255}return s}throw new Error("invalid ip address")},Tl=function(r,t=0,e){t=~~t,e=e??r.length-t;let n=new DataView(r.buffer);if(e===4){let s=[];for(let o=0;o<e;o++)s.push(r[t+o]);return s.join(".")}if(e===16){let s=[];for(let o=0;o<e;o+=2)s.push(n.getUint16(t+o).toString(16));return s.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var Sr={},Ti={},Id=[[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"]];Id.forEach(r=>{let t=kd(...r);Ti[t.code]=t,Sr[t.name]=t});function kd(r,t,e,n,s){return{code:r,size:t,name:e,resolvable:!!n,path:!!s}}function z(r){if(typeof r=="number"){if(Ti[r]!=null)return Ti[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Sr[r]!=null)return Sr[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var rw=z("ip4"),nw=z("ip6"),sw=z("ipcidr");function Pi(r,t){switch(z(r).code){case 4:case 41:return Nd(t);case 42:return Ri(t);case 43:return Q(t,"base10");case 6:case 273:case 33:case 132:return Rl(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Ri(t);case 421:return Rd(t);case 444:return Ll(t);case 445:return Ll(t);case 466:return Ld(t);case 481:return globalThis.encodeURIComponent(Ri(t));default:return Q(t,"base16")}}function _i(r,t){switch(z(r).code){case 4:return Ul(t);case 41:return Ul(t);case 42:return Li(t);case 43:return $(t,"base10");case 6:case 273:case 33:case 132:return Oi(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Li(t);case 421:return Td(t);case 444:return Pd(t);case 445:return _d(t);case 466:return Ud(t);case 481:return Li(globalThis.decodeURIComponent(t));default:return $(t,"base16")}}var Ui=Object.values(Mr).map(r=>r.decoder),Cd=function(){let r=Ui[0].or(Ui[1]);return Ui.slice(2).forEach(t=>r=r.or(t)),r}();function Ul(r){if(!Os(r))throw new Error("invalid ip address");return Ni(r)}function Nd(r){let t=Tl(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!Os(t))throw new Error("invalid ip address");return t}function Oi(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Rl(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Li(r){let t=$(r),e=Uint8Array.from(Ot(t.length));return _t([e,t],e.length+t.length)}function Ri(r){let t=de(r);if(r=r.slice(xt(t)),r.length!==t)throw new Error("inconsistent lengths");return Q(r)}function Td(r){let t;r[0]==="Q"||r[0]==="1"?t=Fe(X.decode(`z${r}`)).bytes:t=dt.parse(r).multihash.bytes;let e=Uint8Array.from(Ot(t.length));return _t([e,t],e.length+t.length)}function Ud(r){let t=Cd.decode(r),e=Uint8Array.from(Ot(t.length));return _t([e,t],e.length+t.length)}function Ld(r){let t=de(r),e=r.slice(xt(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+Q(e,"base64url")}function Rd(r){let t=de(r),e=r.slice(xt(t));if(e.length!==t)throw new Error("inconsistent lengths");return Q(e,"base58btc")}function Pd(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=ae.decode("b"+t[0]),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let s=Oi(n);return _t([e,s],e.length+s.length)}function _d(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=ae.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let s=Oi(n);return _t([e,s],e.length+s.length)}function Ll(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=Q(t,"base32"),s=Rl(e);return`${n}:${s}`}function Pl(r){r=Vi(r);let t=[],e=[],n=null,s=r.split("/").slice(1);if(s.length===1&&s[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let o=0;o<s.length;o++){let i=s[o],c=z(i);if(c.size===0){t.push([c.code]),e.push([c.code]);continue}if(o++,o>=s.length)throw new Vs("invalid address: "+r);if(c.path===!0){n=Vi(s.slice(o).join("/")),t.push([c.code,_i(c.code,n)]),e.push([c.code,n]);break}let a=_i(c.code,s[o]);t.push([c.code,a]),e.push([c.code,Pi(c.code,a)])}return{string:_l(e),bytes:Ds(t),tuples:t,stringTuples:e,path:n}}function Di(r){let t=[],e=[],n=null,s=0;for(;s<r.length;){let o=de(r,s),i=xt(o),c=z(o),a=Od(c,r.slice(s+i));if(a===0){t.push([o]),e.push([o]),s+=i;continue}let l=r.slice(s+i,s+i+a);if(s+=a+i,s>r.length)throw new Vs("Invalid address Uint8Array: "+Q(r,"base16"));t.push([o,l]);let u=Pi(o,l);if(e.push([o,u]),c.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:_l(e),tuples:t,stringTuples:e,path:n}}function _l(r){let t=[];return r.map(e=>{let n=z(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),Vi(t.join("/"))}function Ds(r){return _t(r.map(t=>{let e=z(t[0]),n=Uint8Array.from(Ot(e.code));return t.length>1&&t[1]!=null&&(n=_t([n,t[1]])),n}))}function Od(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=de(t instanceof Uint8Array?t:Uint8Array.from(t));return e+xt(e)}}function Vi(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}var Vs=class extends Error{static name="ParseError";name="ParseError";constructor(t){super(`Error parsing address: ${t}`)}};var Vd=Symbol.for("nodejs.util.inspect.custom"),Fi=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Dd=[z("dns").code,z("dns4").code,z("dns6").code,z("dnsaddr").code],Mi=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},Ms=class r{bytes;#e;#t;#r;#n;[Fi]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=Di(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=Pl(t)}else if(Vl(t))e=Di(t.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=e.bytes,this.#e=e.string,this.#t=e.tuples,this.#r=e.stringTuples,this.#n=e.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let t,e,n,s,o="",i=z("tcp"),c=z("udp"),a=z("ip4"),l=z("ip6"),u=z("dns6"),f=z("ip6zone");for(let[m,p]of this.stringTuples())m===f.code&&(o=`%${p??""}`),Dd.includes(m)&&(e=i.name==="tcp"?"tcp":"udp",s=443,n=`${p??""}${o}`,t=m===u.code?6:4),(m===i.code||m===c.code)&&(e=z(m).name==="tcp"?"tcp":"udp",s=parseInt(p??"")),(m===a.code||m===l.code)&&(e=z(m).name==="tcp"?"tcp":"udp",n=`${p??""}${o}`,t=m===l.code?6:4);if(t==null||e==null||n==null||s==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:t,host:n,transport:e,port:s}}protos(){return this.#t.map(([t])=>Object.assign({},z(t)))}protoCodes(){return this.#t.map(([t])=>t)}protoNames(){return this.#t.map(([t])=>z(t).name)}tuples(){return this.#t.map(([t,e])=>e==null?[t]:[t,e])}stringTuples(){return this.#r.map(([t,e])=>e==null?[t]:[t,e])}encapsulate(t){return t=new r(t),new r(this.toString()+t.toString())}decapsulate(t){let e=t.toString(),n=this.toString(),s=n.lastIndexOf(e);if(s<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,s))}decapsulateCode(t){let e=this.tuples();for(let n=e.length-1;n>=0;n--)if(e[n][0]===t)return new r(Ds(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,s])=>{n===Sr.p2p.code&&t.push([n,s]),n===Sr["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?Q(X.decode(`z${n}`),"base58btc"):Q(dt.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return bt(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(o=>o.resolvable);if(e==null)return[this];let n=Ol.get(e.name);if(n==null)throw new Mi(`no available resolver for ${e.name}`);return(await n(this,t)).map(o=>se(o))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(t){let e=(t??this).protos();return!(e.length!==2||e[0].code!==4&&e[0].code!==41||e[1].code!==6&&e[1].code!==273)}[Vd](){return`Multiaddr(${this.#e})`}};var Ol=new Map;function Vl(r){return!!r?.[Fi]}function se(r){return new Ms(r)}var Dl="libp2p-peer-record",Ml=Uint8Array.from([3,1]);var an;(function(r){let t;(function(n){let s;n.codec=()=>(s==null&&(s=Gt((o,i,c={})=>{c.lengthDelimited!==!1&&i.fork(),o.multiaddr!=null&&o.multiaddr.byteLength>0&&(i.uint32(10),i.bytes(o.multiaddr)),c.lengthDelimited!==!1&&i.ldelim()},(o,i,c={})=>{let a={multiaddr:pt(0)},l=i==null?o.len:o.pos+i;for(;o.pos<l;){let u=o.uint32();switch(u>>>3){case 1:{a.multiaddr=o.bytes();break}default:{o.skipType(u&7);break}}}return a})),s),n.encode=o=>zt(o,n.codec()),n.decode=(o,i)=>$t(o,n.codec(),i)})(t=r.AddressInfo||(r.AddressInfo={}));let e;r.codec=()=>(e==null&&(e=Gt((n,s,o={})=>{if(o.lengthDelimited!==!1&&s.fork(),n.peerId!=null&&n.peerId.byteLength>0&&(s.uint32(10),s.bytes(n.peerId)),n.seq!=null&&n.seq!==0n&&(s.uint32(16),s.uint64(n.seq)),n.addresses!=null)for(let i of n.addresses)s.uint32(26),r.AddressInfo.codec().encode(i,s);o.lengthDelimited!==!1&&s.ldelim()},(n,s,o={})=>{let i={peerId:pt(0),seq:0n,addresses:[]},c=s==null?n.len:n.pos+s;for(;n.pos<c;){let a=n.uint32();switch(a>>>3){case 1:{i.peerId=n.bytes();break}case 2:{i.seq=n.uint64();break}case 3:{if(o.limits?.addresses!=null&&i.addresses.length===o.limits.addresses)throw new Ze('Decode error - map field "addresses" had too many elements');i.addresses.push(r.AddressInfo.codec().decode(n,n.uint32(),{limits:o.limits?.addresses$}));break}default:{n.skipType(a&7);break}}}return i})),e),r.encode=n=>zt(n,r.codec()),r.decode=(n,s)=>$t(n,r.codec(),s)})(an||(an={}));var Zt=class r{static createFromProtobuf=t=>{let e=an.decode(t),n=Si(Fe(e.peerId)),s=(e.addresses??[]).map(i=>se(i.multiaddr)),o=e.seq;return new r({peerId:n,multiaddrs:s,seqNumber:o})};static DOMAIN=Dl;static CODEC=Ml;peerId;multiaddrs;seqNumber;domain=r.DOMAIN;codec=r.CODEC;marshaled;constructor(t){let{peerId:e,multiaddrs:n,seqNumber:s}=t;this.peerId=e,this.multiaddrs=n??[],this.seqNumber=s??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=an.encode({peerId:this.peerId.toMultihash().bytes,seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(t=>({multiaddr:t.bytes}))})),this.marshaled}equals(t){return!(!(t instanceof r)||!this.peerId.equals(t.peerId)||this.seqNumber!==t.seqNumber||!vl(this.multiaddrs,t.multiaddrs))}};function Md(r){return r[Symbol.asyncIterator]!=null}function Fd(r){if(Md(r))return(async()=>{for await(let t of r);})();for(let t of r);}var Fl=Fd;function Yt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Fs=globalThis.CustomEvent??Event;async function*Hi(r,t={}){let e=t.concurrency??1/0;e<1&&(e=1/0);let n=t.ordered==null?!1:t.ordered,s=new EventTarget,o=[],i=Yt(),c=Yt(),a=!1,l,u=!1;s.addEventListener("task-complete",()=>{c.resolve()}),Promise.resolve().then(async()=>{try{for await(let p of r){if(o.length===e&&(i=Yt(),await i.promise),u)break;let b={done:!1};o.push(b),p().then(d=>{b.done=!0,b.ok=!0,b.value=d,s.dispatchEvent(new Fs("task-complete"))},d=>{b.done=!0,b.err=d,s.dispatchEvent(new Fs("task-complete"))})}a=!0,s.dispatchEvent(new Fs("task-complete"))}catch(p){l=p,s.dispatchEvent(new Fs("task-complete"))}});function f(){return n?o[0]?.done:!!o.find(p=>p.done)}function*h(){for(;o.length>0&&o[0].done;){let p=o[0];if(o.shift(),p.ok)yield p.value;else throw u=!0,i.resolve(),p.err;i.resolve()}}function*m(){for(;f();)for(let p=0;p<o.length;p++)if(o[p].done){let b=o[p];if(o.splice(p,1),p--,b.ok)yield b.value;else throw u=!0,i.resolve(),b.err;i.resolve()}}for(;;){if(f()||(c=Yt(),await c.promise),l!=null)throw l;if(n?yield*h():yield*m(),a&&o.length===0)break}}var Hs=class extends Error{type;code;constructor(t,e,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=e??"ABORT_ERR"}};async function Hl(r,t,e){if(t==null)return r;if(t.aborted){let o=Promise.reject(new Hs(e?.errorMessage,e?.errorCode,e?.errorName));return Promise.race([o,Promise.resolve().then(async()=>{try{await r}catch{}return o})])}let n,s=new Hs(e?.errorMessage,e?.errorCode,e?.errorName);try{return await Promise.race([r,new Promise((o,i)=>{n=()=>{i(s)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var Ki=class{readNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.readNext=Yt(),this.haveNext=Yt()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Yt(),t}async throw(t){return this.ended=!0,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return await this._push(void 0),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Yt(),await Hl(this.readNext.promise,e?.signal,e)}};function Kl(){return new Ki}var Ks=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};var qi=class extends Error{code;constructor(t,e){super(t),this.code=e}},$i=class extends qi{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted",this.name="AbortError"}};function ql(r,t){let e=Kl();r.sink(e).catch(async i=>{await e.end(i)}),r.sink=async i=>{for await(let c of i)await e.push(c);await e.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let s=new jt;return{read:async(i,c)=>{c?.signal?.throwIfAborted();let a,l=new Promise((u,f)=>{a=()=>{f(new $i("Read aborted"))},c?.signal?.addEventListener("abort",a)});try{if(i==null){let{done:f,value:h}=await Promise.race([n.next(),l]);return f===!0?new jt:h}for(;s.byteLength<i;){let{value:f,done:h}=await Promise.race([n.next(),l]);if(h===!0)throw new Ks("unexpected end of input");s.append(f)}let u=s.sublist(0,i);return s.consume(i),u}finally{a!=null&&c?.signal?.removeEventListener("abort",a)}},write:async(i,c)=>{c?.signal?.throwIfAborted(),i instanceof Uint8Array?await e.push(i,c):await e.push(i.subarray(),c)},unwrap:()=>{if(s.byteLength>0){let i=r.source;r.source=async function*(){t?.yieldBytes===!1?yield s:yield*s,yield*i}()}return r}}}var qs=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},$s=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},zs=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function $l(r,t={}){let e=ql(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=xt(t.maxDataLength));let n=t?.lengthDecoder??de,s=t?.lengthEncoder??Ot;return{read:async i=>{let c=-1,a=new jt;for(;;){a.append(await e.read(1,i));try{c=n(a)}catch(l){if(l instanceof RangeError)continue;throw l}if(c<0)throw new qs("Invalid message length");if(t?.maxLengthLength!=null&&a.byteLength>t.maxLengthLength)throw new zs("message length length too long");if(c>-1)break}if(t?.maxDataLength!=null&&c>t.maxDataLength)throw new $s("message length too long");return e.read(c,i)},write:async(i,c)=>{await e.write(new jt(s(i.byteLength),i),c)},writeV:async(i,c)=>{let a=new jt(...i.flatMap(l=>[s(l.byteLength),l]));await e.write(a,c)},unwrap:()=>e.unwrap()}}function Ir(r,t){let e=$l(r,t),n={read:async(s,o)=>{let i=await e.read(o);return s.decode(i)},write:async(s,o,i)=>{await e.write(o.encode(s),i)},writeV:async(s,o,i)=>{await e.writeV(s.map(c=>o.encode(c)),i)},pb:s=>({read:async o=>n.read(s,o),write:async(o,i)=>n.write(o,s,i),writeV:async(o,i)=>n.writeV(o,s,i),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var zl="0.1.0",Gl="id",Wl="id/push",jl="1.0.0",Zl="1.0.0";var De;(function(r){let t;r.codec=()=>(t==null&&(t=Gt((e,n,s={})=>{if(s.lengthDelimited!==!1&&n.fork(),e.protocolVersion!=null&&(n.uint32(42),n.string(e.protocolVersion)),e.agentVersion!=null&&(n.uint32(50),n.string(e.agentVersion)),e.publicKey!=null&&(n.uint32(10),n.bytes(e.publicKey)),e.listenAddrs!=null)for(let o of e.listenAddrs)n.uint32(18),n.bytes(o);if(e.observedAddr!=null&&(n.uint32(34),n.bytes(e.observedAddr)),e.protocols!=null)for(let o of e.protocols)n.uint32(26),n.string(o);e.signedPeerRecord!=null&&(n.uint32(66),n.bytes(e.signedPeerRecord)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let o={listenAddrs:[],protocols:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let c=e.uint32();switch(c>>>3){case 5:{o.protocolVersion=e.string();break}case 6:{o.agentVersion=e.string();break}case 1:{o.publicKey=e.bytes();break}case 2:{if(s.limits?.listenAddrs!=null&&o.listenAddrs.length===s.limits.listenAddrs)throw new Ze('Decode error - map field "listenAddrs" had too many elements');o.listenAddrs.push(e.bytes());break}case 4:{o.observedAddr=e.bytes();break}case 3:{if(s.limits?.protocols!=null&&o.protocols.length===s.limits.protocols)throw new Ze('Decode error - map field "protocols" had too many elements');o.protocols.push(e.string());break}case 8:{o.signedPeerRecord=e.bytes();break}default:{e.skipType(c&7);break}}}return o})),t),r.encode=e=>zt(e,r.codec()),r.decode=(e,n)=>$t(e,r.codec(),n)})(De||(De={}));var Rt={protocolPrefix:"ipfs",timeout:5e3,maxInboundStreams:1,maxOutboundStreams:1,maxObservedAddresses:10,maxMessageSize:8192,runOnConnectionOpen:!0,runOnSelfUpdate:!0,runOnLimitedConnection:!0,concurrency:32};function Yl(r){if(r!=null&&r.length>0)try{return se(r)}catch{}}function qd(r,t){return t??r.userAgent}async function Gs(r,t,e,n,s){if(e("received identify from %p",n.remotePeer),s==null)throw new Dt("message was null or undefined");let o={};if(s.listenAddrs.length>0&&(o.addresses=s.listenAddrs.map(a=>({isCertified:!1,multiaddr:se(a)}))),s.protocols.length>0&&(o.protocols=s.protocols),s.publicKey!=null){let a=xr(s.publicKey);if(!xl(a).equals(n.remotePeer))throw new Dt("public key did not match remote PeerId");o.publicKey=a}let i;if(s.signedPeerRecord!=null){e.trace("received signedPeerRecord from %p",n.remotePeer);let a=s.signedPeerRecord,l=await ne.openAndCertify(a,Zt.DOMAIN),u=Zt.createFromProtobuf(l.payload),f=Ls(l.publicKey.toCID());if(!u.peerId.equals(f))throw new Dt("signing key does not match PeerId in the PeerRecord");if(!n.remotePeer.equals(u.peerId))throw new Dt("signing key does not match remote PeerId");let h;try{h=await r.get(u.peerId)}catch(m){if(m.name!=="NotFoundError")throw m}if(h!=null&&(o.metadata=h.metadata,h.peerRecordEnvelope!=null)){let m=await ne.createFromProtobuf(h.peerRecordEnvelope),p=Zt.createFromProtobuf(m.payload);p.seqNumber>=u.seqNumber&&(e("sequence number was lower or equal to existing sequence number - stored: %d received: %d",p.seqNumber,u.seqNumber),u=p,a=h.peerRecordEnvelope)}o.peerRecordEnvelope=a,o.addresses=u.multiaddrs.map(m=>({isCertified:!0,multiaddr:m})),i={seq:u.seqNumber,addresses:u.multiaddrs}}else e("%p did not send a signed peer record",n.remotePeer);if(e.trace("patching %p with",n.remotePeer,o),await r.patch(n.remotePeer,o),s.agentVersion!=null||s.protocolVersion!=null){let a={};s.agentVersion!=null&&(a.AgentVersion=$(s.agentVersion)),s.protocolVersion!=null&&(a.ProtocolVersion=$(s.protocolVersion)),e.trace("merging %p metadata",n.remotePeer,a),await r.merge(n.remotePeer,{metadata:a})}let c={peerId:n.remotePeer,protocolVersion:s.protocolVersion,agentVersion:s.agentVersion,publicKey:s.publicKey,listenAddrs:s.listenAddrs.map(a=>se(a)),observedAddr:s.observedAddr==null?void 0:se(s.observedAddr),protocols:s.protocols,signedPeerRecord:i,connection:n};return t.safeDispatchEvent("peer:identify",{detail:c}),c}var kr=class{host;protocol;started;timeout;peerId;privateKey;peerStore;registrar;addressManager;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxObservedAddresses;events;runOnLimitedConnection;log;constructor(t,e){this.protocol=e.protocol,this.started=!1,this.peerId=t.peerId,this.privateKey=t.privateKey,this.peerStore=t.peerStore,this.registrar=t.registrar,this.addressManager=t.addressManager,this.events=t.events,this.log=e.log,this.timeout=e.timeout??Rt.timeout,this.maxInboundStreams=e.maxInboundStreams??Rt.maxInboundStreams,this.maxOutboundStreams=e.maxOutboundStreams??Rt.maxOutboundStreams,this.maxMessageSize=e.maxMessageSize??Rt.maxMessageSize,this.maxObservedAddresses=e.maxObservedAddresses??Rt.maxObservedAddresses,this.runOnLimitedConnection=e.runOnLimitedConnection??Rt.runOnLimitedConnection,this.host={protocolVersion:`${e.protocolPrefix??Rt.protocolPrefix}/${zl}`,agentVersion:qd(t.nodeInfo,e.agentVersion)}}isStarted(){return this.started}async start(){this.started||(await this.peerStore.merge(this.peerId,{metadata:{AgentVersion:$(this.host.agentVersion),ProtocolVersion:$(this.host.protocolVersion)}}),await this.registrar.handle(this.protocol,t=>{this.handleProtocol(t).catch(e=>{this.log.error(e)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams,runOnLimitedConnection:this.runOnLimitedConnection}),this.started=!0)}async stop(){await this.registrar.unhandle(this.protocol),this.started=!1}};var Ws=class extends kr{connectionManager;concurrency;constructor(t,e={}){super(t,{...e,protocol:`/${e.protocolPrefix??Rt.protocolPrefix}/${Wl}/${Zl}`,log:t.logger.forComponent("libp2p:identify-push")}),this.connectionManager=t.connectionManager,this.concurrency=e.concurrency??Rt.concurrency,(e.runOnSelfUpdate??Rt.runOnSelfUpdate)&&t.events.addEventListener("self:peer:update",n=>{this.push().catch(s=>{this.log.error(s)})})}[gn]=["@libp2p/identify-push"];async push(){if(!this.isStarted())return;let t=this.addressManager.getAddresses().map(u=>u.decapsulateCode(z("p2p").code)),e=new Zt({peerId:this.peerId,multiaddrs:t}),n=await ne.seal(e,this.privateKey),s=this.registrar.getProtocols(),o=await this.peerStore.get(this.peerId),i=Q(o.metadata.get("AgentVersion")??$(this.host.agentVersion)),c=Q(o.metadata.get("ProtocolVersion")??$(this.host.protocolVersion)),a=this;async function*l(){for(let u of a.connectionManager.getConnections())(await a.peerStore.get(u.remotePeer)).protocols.includes(a.protocol)&&(yield async()=>{let h,m=AbortSignal.timeout(a.timeout);try{h=await u.newStream(a.protocol,{signal:m,runOnLimitedConnection:a.runOnLimitedConnection}),await Ir(h,{maxDataLength:a.maxMessageSize}).pb(De).write({listenAddrs:t.map(b=>b.bytes),signedPeerRecord:n.marshal(),protocols:s,agentVersion:i,protocolVersion:c},{signal:m}),await h.close({signal:m})}catch(p){a.log.error("could not push identify update to peer",p),h?.abort(p)}})}await Fl(Hi(l(),{concurrency:this.concurrency}))}async handleProtocol(t){let{connection:e,stream:n}=t;try{if(this.peerId.equals(e.remotePeer))throw new Error("received push from ourselves?");let s={signal:AbortSignal.timeout(this.timeout)},i=await Ir(n,{maxDataLength:this.maxMessageSize}).pb(De).read(s);await n.close(s),await Gs(this.peerStore,this.events,this.log,e,i)}catch(s){this.log.error("received invalid message",s),n.abort(s);return}this.log.trace("handled push from %p",e.remotePeer)}};var zd=41;function Jl(r){try{let[[t,e]]=r.stringTuples();if(e==null)return!1;if(t===zd)return Cl("2000::/3",e)}catch{}return!1}var Ql=ia(Xl(),1),Gd=["0.0.0.0/8","10.0.0.0/8","100.64.0.0/10","127.0.0.0/8","169.254.0.0/16","172.16.0.0/12","192.0.0.0/24","192.0.0.0/29","192.0.0.8/32","192.0.0.9/32","192.0.0.10/32","192.0.0.170/32","192.0.0.171/32","192.0.2.0/24","192.31.196.0/24","192.52.193.0/24","192.88.99.0/24","192.168.0.0/16","192.175.48.0/24","198.18.0.0/15","198.51.100.0/24","203.0.113.0/24","240.0.0.0/4","255.255.255.255/32"],Wd=Gd.map(r=>new Ql.Netmask(r));function zi(r){for(let t of Wd)if(t.contains(r))return!0;return!1}function jd(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function Zd(r){let t=r.split(":");if(t.length<2)return!1;let e=t[t.length-1].padStart(4,"0"),n=t[t.length-2].padStart(4,"0"),s=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(e.substring(0,2),16)}.${parseInt(e.substring(2),16)}`;return zi(s)}function Yd(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function Jd(r){let t=r.split(":"),e=t[t.length-1];return zi(e)}function Xd(r){return/^::$/.test(r)||/^::1$/.test(r)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(r)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(r)||/^ff([0-9a-fA-F]{2,2}):/i.test(r)}function tu(r){return Br(r)?zi(r):jd(r)?Zd(r):Yd(r)?Jd(r):Ar(r)?Xd(r):void 0}function eu(r){try{let[[t]]=r.stringTuples();return t===4||t===41}catch{}return!1}function ru(r){try{if(!eu(r))return!1;let[[,t]]=r.stringTuples();return t==null?!1:tu(t)??!1}catch{}return!0}var Qd=r=>r.toString().split("/").slice(1),Cr=r=>({match:t=>t.length<1?!1:r(t[0])?t.slice(1):!1,pattern:"fn"}),H=r=>({match:t=>Cr(e=>e===r).match(t),pattern:r}),er=()=>({match:r=>Cr(t=>typeof t=="string").match(r),pattern:"{string}"}),ln=()=>({match:r=>Cr(t=>!isNaN(parseInt(t))).match(r),pattern:"{number}"}),Y=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{X.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),un=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{Wo.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),G=r=>({match:t=>{let e=r.match(t);return e===!1?t:e},pattern:`optional(${r.pattern})`}),Bt=(...r)=>({match:t=>{let e;for(let n of r){let s=n.match(t);s!==!1&&(e==null||s.length<e.length)&&(e=s)}return e??!1},pattern:`or(${r.map(t=>t.pattern).join(", ")})`}),K=(...r)=>({match:t=>{for(let e of r){let n=e.match(t);if(n===!1)return!1;t=n}return t},pattern:`and(${r.map(t=>t.pattern).join(", ")})`});function st(...r){function t(s){let o=Qd(s);for(let i of r){let c=i.match(o);if(c===!1)return!1;o=c}return o}function e(s){return t(s)!==!1}function n(s){let o=t(s);return o===!1?!1:o.length===0}return{matchers:r,matches:e,exactMatch:n}}var Zs=K(H("dns4"),er()),Ys=K(H("dns6"),er()),Js=K(H("dnsaddr"),er()),Wi=K(H("dns"),er()),Gx=st(Zs,G(Y())),Wx=st(Ys,G(Y())),jx=st(Js,G(Y())),Zx=st(Bt(Wi,Js,Zs,Ys),G(Y())),nu=K(H("ip4"),Cr(Br)),su=K(H("ip6"),Cr(Ar)),ji=Bt(nu,su),Ee=Bt(ji,Wi,Zs,Ys,Js),ou=st(Bt(ji,K(Bt(Wi,Js,Zs,Ys),G(Y())))),Yx=st(nu),Jx=st(su),Xx=st(ji),Zi=K(Ee,H("tcp"),ln()),fn=K(Ee,H("udp"),ln()),iu=st(K(Zi,G(Y()))),Qx=st(fn),Yi=K(fn,H("quic"),G(Y())),Xs=K(fn,H("quic-v1"),G(Y())),t0=Bt(Yi,Xs),t1=st(Yi),e1=st(Xs),Gi=Bt(Ee,Zi,fn,Yi,Xs),au=Bt(K(Gi,H("ws"),G(Y()))),r1=st(au),cu=Bt(K(Gi,H("wss"),G(Y())),K(Gi,H("tls"),G(K(H("sni"),er())),H("ws"),G(Y()))),n1=st(cu),lu=K(fn,H("webrtc-direct"),G(un()),G(un()),G(Y())),s1=st(lu),uu=K(Xs,H("webtransport"),G(un()),G(un()),G(Y())),o1=st(uu),js=Bt(au,cu,K(Zi,G(Y())),K(t0,G(Y())),K(Ee,G(Y())),lu,uu,Y()),i1=st(js),e0=K(js,H("p2p-circuit"),Y()),a1=st(e0),r0=Bt(K(js,H("p2p-circuit"),H("webrtc"),G(Y())),K(js,H("webrtc"),G(Y())),K(H("webrtc"),G(Y()))),c1=st(r0),n0=Bt(K(Ee,H("tcp"),ln(),H("http"),G(Y())),K(Ee,H("http"),G(Y()))),l1=st(n0),s0=Bt(K(Ee,H("tcp"),Bt(K(H("443"),H("http")),K(ln(),H("https"))),G(Y())),K(Ee,H("tls"),H("http"),G(Y())),K(Ee,H("https"),G(Y()))),u1=st(s0),o0=Bt(K(H("memory"),er(),G(Y()))),f1=st(o0);var i0=41,Qs=class extends kr{constructor(t,e={}){super(t,{...e,protocol:`/${e.protocolPrefix??Rt.protocolPrefix}/${Gl}/${jl}`,log:t.logger.forComponent("libp2p:identify")}),(e.runOnConnectionOpen??Rt.runOnConnectionOpen)&&t.events.addEventListener("connection:open",n=>{let s=n.detail;this.identify(s).catch(o=>{o.name!==mn.name&&this.log.error("error during identify trigged by connection:open",o)})})}[gn]=["@libp2p/identify"];async _identify(t,e={}){let n;if(e.signal==null){let s=AbortSignal.timeout(this.timeout);e={...e,signal:s}}try{n=await t.newStream(this.protocol,{...e,runOnLimitedConnection:this.runOnLimitedConnection});let o=await Ir(n,{maxDataLength:this.maxMessageSize}).pb(De).read(e);return await n.close(e),o}catch(s){throw n?.abort(s),s}}async identify(t,e={}){let n=await this._identify(t,e),{publicKey:s,protocols:o,observedAddr:i}=n;if(s==null)throw new Dt("public key was missing from identify message");let c=xr(s),a=Ls(c.toCID());if(!t.remotePeer.equals(a))throw new Dt("identified peer does not match the expected peer");if(this.peerId.equals(a))throw new Dt("identified peer is our own peer id?");return this.maybeAddObservedAddress(i),this.log("identify completed for peer %p and protocols %o",a,o),Gs(this.peerStore,this.events,this.log,t,n)}maybeAddObservedAddress(t){let e=Yl(t);if(e==null)return;if(this.log.trace("our observed address was %a",e),ru(e)){this.log.trace("our observed address was private");return}if(e.stringTuples()[0][0]===i0&&!Jl(e)){this.log.trace("our observed address was IPv6 but not a global unicast address");return}iu.exactMatch(e)||(this.log.trace("storing the observed address"),this.addressManager.addObservedAddr(e))}async handleProtocol(t){let{connection:e,stream:n}=t,s=AbortSignal.timeout(this.timeout);try{let o=await this.peerStore.get(this.peerId),i=this.addressManager.getAddresses().map(u=>u.decapsulateCode(z("p2p").code)),c=o.peerRecordEnvelope;if(i.length>0&&c==null){let u=new Zt({peerId:this.peerId,multiaddrs:i});c=(await ne.seal(u,this.privateKey)).marshal().subarray()}let a=e.remoteAddr.bytes;ou.matches(e.remoteAddr)||(a=void 0),await Ir(n).pb(De).write({protocolVersion:this.host.protocolVersion,agentVersion:this.host.agentVersion,publicKey:Ue(this.privateKey.publicKey),listenAddrs:i.map(u=>u.bytes),signedPeerRecord:c,observedAddr:a,protocols:o.protocols},{signal:s}),await n.close({signal:s})}catch(o){this.log.error("could not respond to identify request",o),n.abort(o)}}};function a0(r={}){return t=>new Qs(t,r)}function c0(r={}){return t=>new Ws(t,r)}return Au(l0);})();
|
|
6
|
+
`)}`:`${e} :`}};mc=Oe;B.Constructed=mc;Oe.NAME="CONSTRUCTED";var Gn=class extends Et{fromBER(t,e,n){return e}toBER(t){return Wt}};Gn.override="EndOfContentValueBlock";var gc,Wn=class extends mt{constructor(t={}){super(t,Gn),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};gc=Wn;B.EndOfContent=gc;Wn.NAME=$r;var yc,mr=class extends mt{constructor(t={}){super(t,Et),this.idBlock.tagClass=1,this.idBlock.tagNumber=5}fromBER(t,e,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,e+n>t.byteLength?(this.error="End of input reached before message was fully decoded (inconsistent offset and length values)",-1):e+n}toBER(t,e){let n=new ArrayBuffer(2);if(!t){let s=new Uint8Array(n);s[0]=5,s[1]=0}return e&&e.write(n),n}onAsciiEncoding(){return`${this.constructor.NAME}`}};yc=mr;B.Null=yc;mr.NAME="NULL";var jn=class extends we(Et){constructor({value:t,...e}={}){super(e),e.valueHex?this.valueHexView=M.BufferSourceConverter.toUint8Array(e.valueHex):this.valueHexView=new Uint8Array(1),t&&(this.value=t)}get value(){for(let t of this.valueHexView)if(t>0)return!0;return!1}set value(t){this.valueHexView[0]=t?255:0}fromBER(t,e,n){let s=M.BufferSourceConverter.toUint8Array(t);return be(this,s,e,n)?(this.valueHexView=s.subarray(e,e+n),n>1&&this.warnings.push("Boolean value encoded in more then 1 octet"),this.isHexOnly=!0,hi.call(this),this.blockLength=n,e+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};jn.NAME="BooleanValueBlock";var bc,Zn=class extends mt{constructor(t={}){super(t,jn),this.idBlock.tagClass=1,this.idBlock.tagNumber=1}getValue(){return this.valueBlock.value}setValue(t){this.valueBlock.value=t}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.getValue}`}};bc=Zn;B.Boolean=bc;Zn.NAME="BOOLEAN";var Yn=class extends we(te){constructor({isConstructed:t=!1,...e}={}){super(e),this.isConstructed=t}fromBER(t,e,n){let s=0;if(this.isConstructed){if(this.isHexOnly=!1,s=te.prototype.fromBER.call(this,t,e,n),s===-1)return s;for(let o=0;o<this.value.length;o++){let i=this.value[o].constructor.NAME;if(i===$r){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(i!==fc)return this.error="OCTET STRING may consists of OCTET STRINGs only",-1}}else this.isHexOnly=!0,s=super.fromBER(t,e,n),this.blockLength=n;return s}toBER(t,e){return this.isConstructed?te.prototype.toBER.call(this,t,e):t?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};Yn.NAME="OctetStringValueBlock";var wc,Jn=class r extends mt{constructor({idBlock:t={},lenBlock:e={},...n}={}){var s,o;(s=n.isConstructed)!==null&&s!==void 0||(n.isConstructed=!!(!((o=n.value)===null||o===void 0)&&o.length)),super({idBlock:{isConstructed:n.isConstructed,...t},lenBlock:{...e,isIndefiniteForm:!!n.isIndefiniteForm},...n},Yn),this.idBlock.tagClass=1,this.idBlock.tagNumber=4}fromBER(t,e,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),e;if(!this.valueBlock.isConstructed){let o=(t instanceof ArrayBuffer?new Uint8Array(t):t).subarray(e,e+n);try{if(o.byteLength){let i=Ss(o,0,o.byteLength);i.offset!==-1&&i.offset===n&&(this.valueBlock.value=[i.result])}}catch{}}return super.fromBER(t,e,n)}onAsciiEncoding(){return this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length?Oe.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${M.Convert.ToHex(this.valueBlock.valueHexView)}`}getValue(){if(!this.idBlock.isConstructed)return this.valueBlock.valueHexView.slice().buffer;let t=[];for(let e of this.valueBlock.value)e instanceof r&&t.push(e.valueBlock.valueHexView);return M.BufferSourceConverter.concat(t)}};wc=Jn;B.OctetString=wc;Jn.NAME=fc;var Xn=class extends we(te){constructor({unusedBits:t=0,isConstructed:e=!1,...n}={}){super(n),this.unusedBits=t,this.isConstructed=e,this.blockLength=this.valueHexView.byteLength}fromBER(t,e,n){if(!n)return e;let s=-1;if(this.isConstructed){if(s=te.prototype.fromBER.call(this,t,e,n),s===-1)return s;for(let c of this.value){let a=c.constructor.NAME;if(a===$r){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(a!==hc)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let l=c.valueBlock;if(this.unusedBits>0&&l.unusedBits>0)return this.error='Using of "unused bits" inside constructive BIT STRING allowed for least one only',-1;this.unusedBits=l.unusedBits}return s}let o=M.BufferSourceConverter.toUint8Array(t);if(!be(this,o,e,n))return-1;let i=o.subarray(e,e+n);if(this.unusedBits=i[0],this.unusedBits>7)return this.error="Unused bits for BitString must be in range 0-7",-1;if(!this.unusedBits){let c=i.subarray(1);try{if(c.byteLength){let a=Ss(c,0,c.byteLength);a.offset!==-1&&a.offset===n-1&&(this.value=[a.result])}}catch{}}return this.valueHexView=i.subarray(1),this.blockLength=i.length,e+n}toBER(t,e){if(this.isConstructed)return te.prototype.toBER.call(this,t,e);if(t)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return Wt;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}}};Xn.NAME="BitStringValueBlock";var xc,gr=class extends mt{constructor({idBlock:t={},lenBlock:e={},...n}={}){var s,o;(s=n.isConstructed)!==null&&s!==void 0||(n.isConstructed=!!(!((o=n.value)===null||o===void 0)&&o.length)),super({idBlock:{isConstructed:n.isConstructed,...t},lenBlock:{...e,isIndefiniteForm:!!n.isIndefiniteForm},...n},Xn),this.idBlock.tagClass=1,this.idBlock.tagNumber=3}fromBER(t,e,n){return this.valueBlock.isConstructed=this.idBlock.isConstructed,this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm,super.fromBER(t,e,n)}onAsciiEncoding(){if(this.valueBlock.isConstructed||this.valueBlock.value&&this.valueBlock.value.length)return Oe.prototype.onAsciiEncoding.call(this);{let t=[],e=this.valueBlock.valueHexView;for(let s of e)t.push(s.toString(2).padStart(8,"0"));let n=t.join("");return`${this.constructor.NAME} : ${n.substring(0,n.length-this.valueBlock.unusedBits)}`}}};xc=gr;B.BitString=xc;gr.NAME=hc;var vc;function sd(r,t){let e=new Uint8Array([0]),n=new Uint8Array(r),s=new Uint8Array(t),o=n.slice(0),i=o.length-1,c=s.slice(0),a=c.length-1,l=0,u=a<i?i:a,f=0;for(let h=u;h>=0;h--,f++){switch(!0){case f<c.length:l=o[i-f]+c[a-f]+e[0];break;default:l=o[i-f]+e[0]}switch(e[0]=l/10,!0){case f>=o.length:o=Mn(new Uint8Array([l%10]),o);break;default:o[i-f]=l%10}}return e[0]>0&&(o=Mn(e,o)),o}function uc(r){if(r>=Kr.length)for(let t=Kr.length;t<=r;t++){let e=new Uint8Array([0]),n=Kr[t-1].slice(0);for(let s=n.length-1;s>=0;s--){let o=new Uint8Array([(n[s]<<1)+e[0]]);e[0]=o[0]/10,n[s]=o[0]%10}e[0]>0&&(n=Mn(e,n)),Kr.push(n)}return Kr[r]}function od(r,t){let e=0,n=new Uint8Array(r),s=new Uint8Array(t),o=n.slice(0),i=o.length-1,c=s.slice(0),a=c.length-1,l,u=0;for(let f=a;f>=0;f--,u++)switch(l=o[i-u]-c[a-u]-e,!0){case l<0:e=1,o[i-u]=l+10;break;default:e=0,o[i-u]=l}if(e>0)for(let f=i-a+1;f>=0;f--,u++)if(l=o[i-u]-e,l<0)e=1,o[i-u]=l+10;else{e=0,o[i-u]=l;break}return o.slice()}var zr=class extends we(Et){constructor({value:t,...e}={}){super(e),this._valueDec=0,e.valueHex&&this.setValueHex(),t!==void 0&&(this.valueDec=t)}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=hi.call(this)))}set valueDec(t){this._valueDec=t,this.isHexOnly=!1,this.valueHexView=new Uint8Array(ac(t))}get valueDec(){return this._valueDec}fromDER(t,e,n,s=0){let o=this.fromBER(t,e,n);if(o===-1)return o;let i=this.valueHexView;return i[0]===0&&i[1]&128?this.valueHexView=i.subarray(1):s!==0&&i.length<s&&(s-i.length>1&&(s=i.length+1),this.valueHexView=i.subarray(s-i.length)),o}toDER(t=!1){let e=this.valueHexView;switch(!0){case(e[0]&128)!==0:{let n=new Uint8Array(this.valueHexView.length+1);n[0]=0,n.set(e,1),this.valueHexView=n}break;case(e[0]===0&&(e[1]&128)===0):this.valueHexView=this.valueHexView.subarray(1);break}return this.toBER(t)}fromBER(t,e,n){let s=super.fromBER(t,e,n);return s===-1||this.setValueHex(),s}toBER(t){return t?new ArrayBuffer(this.valueHexView.length):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}toString(){let t=this.valueHexView.length*8-1,e=new Uint8Array(this.valueHexView.length*8/3),n=0,s,o=this.valueHexView,i="",c=!1;for(let a=o.byteLength-1;a>=0;a--){s=o[a];for(let l=0;l<8;l++){if((s&1)===1)switch(n){case t:e=od(uc(n),e),i="-";break;default:e=sd(e,uc(n))}n++,s>>=1}}for(let a=0;a<e.length;a++)e[a]&&(c=!0),c&&(i+=lc.charAt(e[a]));return c===!1&&(i+=lc.charAt(0)),i}};vc=zr;zr.NAME="IntegerValueBlock";Object.defineProperty(vc.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var Ec,gt=class r extends mt{constructor(t={}){super(t,zr),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return Fn(),BigInt(this.valueBlock.toString())}static fromBigInt(t){Fn();let e=BigInt(t),n=new qr,s=e.toString(16).replace(/^-/,""),o=new Uint8Array(M.Convert.FromHex(s));if(e<0){let c=new Uint8Array(o.length+(o[0]&128?1:0));c[0]|=128;let l=BigInt(`0x${M.Convert.ToHex(c)}`)+e,u=M.BufferSourceConverter.toUint8Array(M.Convert.FromHex(l.toString(16)));u[0]|=128,n.write(u)}else o[0]&128&&n.write(new Uint8Array([0])),n.write(o);return new r({valueHex:n.final()})}convertToDER(){let t=new r({valueHex:this.valueBlock.valueHexView});return t.valueBlock.toDER(),t}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()}`}};Ec=gt;B.Integer=Ec;gt.NAME="INTEGER";var Bc,Qn=class extends gt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};Bc=Qn;B.Enumerated=Bc;Qn.NAME="ENUMERATED";var Gr=class extends we(Et){constructor({valueDec:t=-1,isFirstSid:e=!1,...n}={}){super(n),this.valueDec=t,this.isFirstSid=e}fromBER(t,e,n){if(!n)return e;let s=M.BufferSourceConverter.toUint8Array(t);if(!be(this,s,e,n))return-1;let o=s.subarray(e,e+n);this.valueHexView=new Uint8Array(n);for(let c=0;c<n&&(this.valueHexView[c]=o[c]&127,this.blockLength++,!!(o[c]&128));c++);let i=new Uint8Array(this.blockLength);for(let c=0;c<this.blockLength;c++)i[c]=this.valueHexView[c];return this.valueHexView=i,o[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=Ye(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),e+this.blockLength)}set valueBigInt(t){Fn();let e=BigInt(t).toString(2);for(;e.length%7;)e="0"+e;let n=new Uint8Array(e.length/7);for(let s=0;s<n.length;s++)n[s]=parseInt(e.slice(s*7,s*7+7),2)+(s+1<n.length?128:0);this.fromBER(n.buffer,0,n.length)}toBER(t){if(this.isHexOnly){if(t)return new ArrayBuffer(this.valueHexView.byteLength);let s=this.valueHexView,o=new Uint8Array(this.blockLength);for(let i=0;i<this.blockLength-1;i++)o[i]=s[i]|128;return o[this.blockLength-1]=s[this.blockLength-1],o.buffer}let e=_e(this.valueDec,7);if(e.byteLength===0)return this.error="Error during encoding SID value",Wt;let n=new Uint8Array(e.byteLength);if(!t){let s=new Uint8Array(e),o=e.byteLength-1;for(let i=0;i<o;i++)n[i]=s[i]|128;n[o]=s[o]}return n}toString(){let t="";if(this.isHexOnly)t=M.Convert.ToHex(this.valueHexView);else if(this.isFirstSid){let e=this.valueDec;this.valueDec<=39?t="0.":this.valueDec<=79?(t="1.",e-=40):(t="2.",e-=80),t+=e.toString()}else t=this.valueDec.toString();return t}toJSON(){return{...super.toJSON(),valueDec:this.valueDec,isFirstSid:this.isFirstSid}}};Gr.NAME="sidBlock";var ts=class extends Et{constructor({value:t=br,...e}={}){super(e),this.value=[],t&&this.fromString(t)}fromBER(t,e,n){let s=e;for(;n>0;){let o=new Gr;if(s=o.fromBER(t,s,n),s===-1)return this.blockLength=0,this.error=o.error,s;this.value.length===0&&(o.isFirstSid=!0),this.blockLength+=o.blockLength,n-=o.blockLength,this.value.push(o)}return s}toBER(t){let e=[];for(let n=0;n<this.value.length;n++){let s=this.value[n].toBER(t);if(s.byteLength===0)return this.error=this.value[n].error,Wt;e.push(s)}return di(e)}fromString(t){this.value=[];let e=0,n=0,s="",o=!1;do if(n=t.indexOf(".",e),n===-1?s=t.substring(e):s=t.substring(e,n),e=n+1,o){let i=this.value[0],c=0;switch(i.valueDec){case 0:break;case 1:c=40;break;case 2:c=80;break;default:this.value=[];return}let a=parseInt(s,10);if(isNaN(a))return;i.valueDec=a+c,o=!1}else{let i=new Gr;if(s>Number.MAX_SAFE_INTEGER){Fn();let c=BigInt(s);i.valueBigInt=c}else if(i.valueDec=parseInt(s,10),isNaN(i.valueDec))return;this.value.length||(i.isFirstSid=!0,o=!0),this.value.push(i)}while(n!==-1)}toString(){let t="",e=!1;for(let n=0;n<this.value.length;n++){e=this.value[n].isHexOnly;let s=this.value[n].toString();n!==0&&(t=`${t}.`),e?(s=`{${s}}`,this.value[n].isFirstSid?t=`2.{${s} - 80}`:t+=s):t+=s}return t}toJSON(){let t={...super.toJSON(),value:this.toString(),sidArray:[]};for(let e=0;e<this.value.length;e++)t.sidArray.push(this.value[e].toJSON());return t}};ts.NAME="ObjectIdentifierValueBlock";var Ac,yr=class extends mt{constructor(t={}){super(t,ts),this.idBlock.tagClass=1,this.idBlock.tagNumber=6}getValue(){return this.valueBlock.toString()}setValue(t){this.valueBlock.fromString(t)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};Ac=yr;B.ObjectIdentifier=Ac;yr.NAME="OBJECT IDENTIFIER";var Wr=class extends we(me){constructor({valueDec:t=0,...e}={}){super(e),this.valueDec=t}fromBER(t,e,n){if(n===0)return e;let s=M.BufferSourceConverter.toUint8Array(t);if(!be(this,s,e,n))return-1;let o=s.subarray(e,e+n);this.valueHexView=new Uint8Array(n);for(let c=0;c<n&&(this.valueHexView[c]=o[c]&127,this.blockLength++,!!(o[c]&128));c++);let i=new Uint8Array(this.blockLength);for(let c=0;c<this.blockLength;c++)i[c]=this.valueHexView[c];return this.valueHexView=i,o[this.blockLength-1]&128?(this.error="End of input reached before message was fully decoded",-1):(this.valueHexView[0]===0&&this.warnings.push("Needlessly long format of SID encoding"),this.blockLength<=8?this.valueDec=Ye(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),e+this.blockLength)}toBER(t){if(this.isHexOnly){if(t)return new ArrayBuffer(this.valueHexView.byteLength);let s=this.valueHexView,o=new Uint8Array(this.blockLength);for(let i=0;i<this.blockLength-1;i++)o[i]=s[i]|128;return o[this.blockLength-1]=s[this.blockLength-1],o.buffer}let e=_e(this.valueDec,7);if(e.byteLength===0)return this.error="Error during encoding SID value",Wt;let n=new Uint8Array(e.byteLength);if(!t){let s=new Uint8Array(e),o=e.byteLength-1;for(let i=0;i<o;i++)n[i]=s[i]|128;n[o]=s[o]}return n.buffer}toString(){let t="";return this.isHexOnly?t=M.Convert.ToHex(this.valueHexView):t=this.valueDec.toString(),t}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};Wr.NAME="relativeSidBlock";var es=class extends Et{constructor({value:t=br,...e}={}){super(e),this.value=[],t&&this.fromString(t)}fromBER(t,e,n){let s=e;for(;n>0;){let o=new Wr;if(s=o.fromBER(t,s,n),s===-1)return this.blockLength=0,this.error=o.error,s;this.blockLength+=o.blockLength,n-=o.blockLength,this.value.push(o)}return s}toBER(t,e){let n=[];for(let s=0;s<this.value.length;s++){let o=this.value[s].toBER(t);if(o.byteLength===0)return this.error=this.value[s].error,Wt;n.push(o)}return di(n)}fromString(t){this.value=[];let e=0,n=0,s="";do{n=t.indexOf(".",e),n===-1?s=t.substring(e):s=t.substring(e,n),e=n+1;let o=new Wr;if(o.valueDec=parseInt(s,10),isNaN(o.valueDec))return!0;this.value.push(o)}while(n!==-1);return!0}toString(){let t="",e=!1;for(let n=0;n<this.value.length;n++){e=this.value[n].isHexOnly;let s=this.value[n].toString();n!==0&&(t=`${t}.`),e&&(s=`{${s}}`),t+=s}return t}toJSON(){let t={...super.toJSON(),value:this.toString(),sidArray:[]};for(let e=0;e<this.value.length;e++)t.sidArray.push(this.value[e].toJSON());return t}};es.NAME="RelativeObjectIdentifierValueBlock";var Sc,rs=class extends mt{constructor(t={}){super(t,es),this.idBlock.tagClass=1,this.idBlock.tagNumber=13}getValue(){return this.valueBlock.toString()}setValue(t){this.valueBlock.fromString(t)}onAsciiEncoding(){return`${this.constructor.NAME} : ${this.valueBlock.toString()||"empty"}`}toJSON(){return{...super.toJSON(),value:this.getValue()}}};Sc=rs;B.RelativeObjectIdentifier=Sc;rs.NAME="RelativeObjectIdentifier";var Ic,ge=class extends Oe{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};Ic=ge;B.Sequence=Ic;ge.NAME="SEQUENCE";var kc,ns=class extends Oe{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};kc=ns;B.Set=kc;ns.NAME="SET";var ss=class extends we(Et){constructor({...t}={}){super(t),this.isHexOnly=!0,this.value=br}toJSON(){return{...super.toJSON(),value:this.value}}};ss.NAME="StringValueBlock";var os=class extends ss{};os.NAME="SimpleStringValueBlock";var kt=class extends qn{constructor({...t}={}){super(t,os)}fromBuffer(t){this.valueBlock.value=String.fromCharCode.apply(null,M.BufferSourceConverter.toUint8Array(t))}fromString(t){let e=t.length,n=this.valueBlock.valueHexView=new Uint8Array(e);for(let s=0;s<e;s++)n[s]=t.charCodeAt(s);this.valueBlock.value=t}};kt.NAME="SIMPLE STRING";var is=class extends kt{fromBuffer(t){this.valueBlock.valueHexView=M.BufferSourceConverter.toUint8Array(t);try{this.valueBlock.value=M.Convert.ToUtf8String(t)}catch(e){this.warnings.push(`Error during "decodeURIComponent": ${e}, using raw string`),this.valueBlock.value=M.Convert.ToBinary(t)}}fromString(t){this.valueBlock.valueHexView=new Uint8Array(M.Convert.FromUtf8String(t)),this.valueBlock.value=t}};is.NAME="Utf8StringValueBlock";var Cc,ye=class extends is{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};Cc=ye;B.Utf8String=Cc;ye.NAME="UTF8String";var as=class extends kt{fromBuffer(t){this.valueBlock.value=M.Convert.ToUtf16String(t),this.valueBlock.valueHexView=M.BufferSourceConverter.toUint8Array(t)}fromString(t){this.valueBlock.value=t,this.valueBlock.valueHexView=new Uint8Array(M.Convert.FromUtf16String(t))}};as.NAME="BmpStringValueBlock";var Nc,cs=class extends as{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};Nc=cs;B.BmpString=Nc;cs.NAME="BMPString";var ls=class extends kt{fromBuffer(t){let e=ArrayBuffer.isView(t)?t.slice().buffer:t.slice(0),n=new Uint8Array(e);for(let s=0;s<n.length;s+=4)n[s]=n[s+3],n[s+1]=n[s+2],n[s+2]=0,n[s+3]=0;this.valueBlock.value=String.fromCharCode.apply(null,new Uint32Array(e))}fromString(t){let e=t.length,n=this.valueBlock.valueHexView=new Uint8Array(e*4);for(let s=0;s<e;s++){let o=_e(t.charCodeAt(s),8),i=new Uint8Array(o);if(i.length>4)continue;let c=4-i.length;for(let a=i.length-1;a>=0;a--)n[s*4+a+c]=i[a]}this.valueBlock.value=t}};ls.NAME="UniversalStringValueBlock";var Tc,us=class extends ls{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};Tc=us;B.UniversalString=Tc;us.NAME="UniversalString";var Uc,fs=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};Uc=fs;B.NumericString=Uc;fs.NAME="NumericString";var Lc,hs=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};Lc=hs;B.PrintableString=Lc;hs.NAME="PrintableString";var Rc,ds=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};Rc=ds;B.TeletexString=Rc;ds.NAME="TeletexString";var Pc,ps=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};Pc=ps;B.VideotexString=Pc;ps.NAME="VideotexString";var _c,ms=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};_c=ms;B.IA5String=_c;ms.NAME="IA5String";var Oc,gs=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};Oc=gs;B.GraphicString=Oc;gs.NAME="GraphicString";var Vc,jr=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};Vc=jr;B.VisibleString=Vc;jr.NAME="VisibleString";var Dc,ys=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};Dc=ys;B.GeneralString=Dc;ys.NAME="GeneralString";var Mc,bs=class extends kt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};Mc=bs;B.CharacterString=Mc;bs.NAME="CharacterString";var Fc,Zr=class extends jr{constructor({value:t,valueDate:e,...n}={}){if(super(n),this.year=0,this.month=0,this.day=0,this.hour=0,this.minute=0,this.second=0,t){this.fromString(t),this.valueBlock.valueHexView=new Uint8Array(t.length);for(let s=0;s<t.length;s++)this.valueBlock.valueHexView[s]=t.charCodeAt(s)}e&&(this.fromDate(e),this.valueBlock.valueHexView=new Uint8Array(this.toBuffer())),this.idBlock.tagClass=1,this.idBlock.tagNumber=23}fromBuffer(t){this.fromString(String.fromCharCode.apply(null,M.BufferSourceConverter.toUint8Array(t)))}toBuffer(){let t=this.toString(),e=new ArrayBuffer(t.length),n=new Uint8Array(e);for(let s=0;s<t.length;s++)n[s]=t.charCodeAt(s);return e}fromDate(t){this.year=t.getUTCFullYear(),this.month=t.getUTCMonth()+1,this.day=t.getUTCDate(),this.hour=t.getUTCHours(),this.minute=t.getUTCMinutes(),this.second=t.getUTCSeconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second))}fromString(t){let n=/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/ig.exec(t);if(n===null){this.error="Wrong input string for conversion";return}let s=parseInt(n[1],10);s>=50?this.year=1900+s:this.year=2e3+s,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(t="iso"){if(t==="iso"){let e=new Array(7);return e[0]=Lt(this.year<2e3?this.year-1900:this.year-2e3,2),e[1]=Lt(this.month,2),e[2]=Lt(this.day,2),e[3]=Lt(this.hour,2),e[4]=Lt(this.minute,2),e[5]=Lt(this.second,2),e[6]="Z",e.join("")}return super.toString(t)}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}}};Fc=Zr;B.UTCTime=Fc;Zr.NAME="UTCTime";var Hc,ws=class extends Zr{constructor(t={}){var e;super(t),(e=this.millisecond)!==null&&e!==void 0||(this.millisecond=0),this.idBlock.tagClass=1,this.idBlock.tagNumber=24}fromDate(t){super.fromDate(t),this.millisecond=t.getUTCMilliseconds()}toDate(){return new Date(Date.UTC(this.year,this.month-1,this.day,this.hour,this.minute,this.second,this.millisecond))}fromString(t){let e=!1,n="",s="",o=0,i,c=0,a=0;if(t[t.length-1]==="Z")n=t.substring(0,t.length-1),e=!0;else{let f=new Number(t[t.length-1]);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");n=t}if(e){if(n.indexOf("+")!==-1)throw new Error("Wrong input string for conversion");if(n.indexOf("-")!==-1)throw new Error("Wrong input string for conversion")}else{let f=1,h=n.indexOf("+"),m="";if(h===-1&&(h=n.indexOf("-"),f=-1),h!==-1){if(m=n.substring(h+1),n=n.substring(0,h),m.length!==2&&m.length!==4)throw new Error("Wrong input string for conversion");let p=parseInt(m.substring(0,2),10);if(isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");if(c=f*p,m.length===4){if(p=parseInt(m.substring(2,4),10),isNaN(p.valueOf()))throw new Error("Wrong input string for conversion");a=f*p}}}let l=n.indexOf(".");if(l===-1&&(l=n.indexOf(",")),l!==-1){let f=new Number(`0${n.substring(l)}`);if(isNaN(f.valueOf()))throw new Error("Wrong input string for conversion");o=f.valueOf(),s=n.substring(0,l)}else s=n;switch(!0){case s.length===8:if(i=/(\d{4})(\d{2})(\d{2})/ig,l!==-1)throw new Error("Wrong input string for conversion");break;case s.length===10:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let f=60*o;this.minute=Math.floor(f),f=60*(f-this.minute),this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case s.length===12:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let f=60*o;this.second=Math.floor(f),f=1e3*(f-this.second),this.millisecond=Math.floor(f)}break;case s.length===14:if(i=/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ig,l!==-1){let f=1e3*o;this.millisecond=Math.floor(f)}break;default:throw new Error("Wrong input string for conversion")}let u=i.exec(s);if(u===null)throw new Error("Wrong input string for conversion");for(let f=1;f<u.length;f++)switch(f){case 1:this.year=parseInt(u[f],10);break;case 2:this.month=parseInt(u[f],10);break;case 3:this.day=parseInt(u[f],10);break;case 4:this.hour=parseInt(u[f],10)+c;break;case 5:this.minute=parseInt(u[f],10)+a;break;case 6:this.second=parseInt(u[f],10);break;default:throw new Error("Wrong input string for conversion")}if(e===!1){let f=new Date(this.year,this.month,this.day,this.hour,this.minute,this.second,this.millisecond);this.year=f.getUTCFullYear(),this.month=f.getUTCMonth(),this.day=f.getUTCDay(),this.hour=f.getUTCHours(),this.minute=f.getUTCMinutes(),this.second=f.getUTCSeconds(),this.millisecond=f.getUTCMilliseconds()}}toString(t="iso"){if(t==="iso"){let e=[];return e.push(Lt(this.year,4)),e.push(Lt(this.month,2)),e.push(Lt(this.day,2)),e.push(Lt(this.hour,2)),e.push(Lt(this.minute,2)),e.push(Lt(this.second,2)),this.millisecond!==0&&(e.push("."),e.push(Lt(this.millisecond,3))),e.push("Z"),e.join("")}return super.toString(t)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};Hc=ws;B.GeneralizedTime=Hc;ws.NAME="GeneralizedTime";var Kc,xs=class extends ye{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};Kc=xs;B.DATE=Kc;xs.NAME="DATE";var qc,vs=class extends ye{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};qc=vs;B.TimeOfDay=qc;vs.NAME="TimeOfDay";var $c,Es=class extends ye{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};$c=Es;B.DateTime=$c;Es.NAME="DateTime";var zc,Bs=class extends ye{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};zc=Bs;B.Duration=zc;Bs.NAME="Duration";var Gc,As=class extends ye{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};Gc=As;B.TIME=Gc;As.NAME="TIME";function Q(r,t="utf8"){let e=Pn[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Yr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Is=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Wc={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Is("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 t}};var Ve=Wc;async function jc(r){let t=await Ve.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),e=await ad(t);return{privateKey:e[0],publicKey:e[1]}}async function Zc(r,t){let e=await Ve.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await Ve.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},e,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function Yc(r,t,e){let n=await Ve.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return Ve.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,e instanceof Uint8Array?e:e.subarray())}async function ad(r){if(r.privateKey==null||r.publicKey==null)throw new It("Private and public key are required");return Promise.all([Ve.get().subtle.exportKey("jwk",r.privateKey),Ve.get().subtle.exportKey("jwk",r.publicKey)])}function gi(r){if(r.kty!=="RSA")throw new It("invalid key type");if(r.n==null)throw new It("invalid key modulus");return $(r.n,"base64url").length*8}var wr=class{type="RSA";_key;_raw;_multihash;constructor(t,e){this._key=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=Jr.jwkToPkix(this._key)),this._raw}toMultihash(){return this._multihash}toCID(){return dt.createV1(114,this._multihash)}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,e){return Yc(this._key,e,t)}},Xr=class{type="RSA";_key;_raw;publicKey;constructor(t,e){this._key=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=Jr.jwkToPkcs1(this._key)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}sign(t){return Zc(this._key,t)}};var ks=8192,yi=18;function Jc(r){let{result:t}=mi(r),e=t.valueBlock.value;return{n:ee(e[1]),e:ee(e[2]),d:ee(e[3]),p:ee(e[4]),q:ee(e[5]),dp:ee(e[6]),dq:ee(e[7]),qi:ee(e[8]),kty:"RSA",alg:"RS256"}}function cd(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 It("JWK was missing components");let e=new ge({value:[new gt({value:0}),gt.fromBigInt(re($(r.n,"base64url"))),gt.fromBigInt(re($(r.e,"base64url"))),gt.fromBigInt(re($(r.d,"base64url"))),gt.fromBigInt(re($(r.p,"base64url"))),gt.fromBigInt(re($(r.q,"base64url"))),gt.fromBigInt(re($(r.dp,"base64url"))),gt.fromBigInt(re($(r.dq,"base64url"))),gt.fromBigInt(re($(r.qi,"base64url")))]}).toBER();return new Uint8Array(e,0,e.byteLength)}function Xc(r){let{result:t}=mi(r),e=t.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:ee(e[0]),e:ee(e[1])}}function bi(r){if(r.n==null||r.e==null)throw new It("JWK was missing components");let e=new ge({value:[new ge({value:[new yr({value:"1.2.840.113549.1.1.1"}),new mr]}),new gr({valueHex:new ge({value:[gt.fromBigInt(re($(r.n,"base64url"))),gt.fromBigInt(re($(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(e,0,e.byteLength)}function ee(r){let t=r.valueBlock.valueHexView;for(;t[0]===0;)t=t.subarray(1);return Q(t,"base64url")}function re(r){let t=[];return r.forEach(function(e){let n=e.toString(16);n.length%2>0&&(n=`0${n}`),t.push(n)}),BigInt("0x"+t.join(""))}function Qc(r){let t=Jc(r);return tl(t)}function wi(r){let t=Xc(r);if(gi(t)>ks)throw new rr("Key size is too large");let e=dr(Qt.encode({Type:ct.RSA,Data:r})),n=Mt(yi,e);return new wr(t,n)}function tl(r){if(gi(r)>ks)throw new It("Key size is too large");let t=rl(r),e=dr(Qt.encode({Type:ct.RSA,Data:bi(t.publicKey)})),n=Mt(yi,e);return new Xr(t.privateKey,new wr(t.publicKey,n))}async function el(r){if(r>ks)throw new It("Key size is too large");let t=await jc(r),e=dr(Qt.encode({Type:ct.RSA,Data:bi(t.publicKey)})),n=Mt(yi,e);return new Xr(t.privateKey,new wr(t.publicKey,n))}function rl(r){if(r==null)throw new It("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}var Cs=class extends lr{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Ba(t);let n=Pr(e);if(this.iHash=t.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 s=this.blockLen,o=new Uint8Array(s);o.set(n.length>s?t.create().update(n).digest():n);for(let i=0;i<o.length;i++)o[i]^=54;this.iHash.update(o),this.oHash=t.create();for(let i=0;i<o.length;i++)o[i]^=106;this.oHash.update(o),o.fill(0)}update(t){return cr(this),this.iHash.update(t),this}digestInto(t){cr(this),ar(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:s,destroyed:o,blockLen:i,outputLen:c}=this;return t=t,t.finished=s,t.destroyed=o,t.blockLen=i,t.outputLen=c,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},xi=(r,t,e)=>new Cs(r,t).update(e).digest();xi.create=(r,t)=>new Cs(r,t);function nl(r){r.lowS!==void 0&&Ht("lowS",r.lowS),r.prehash!==void 0&&Ht("prehash",r.prehash)}function ld(r){let t=Vr(r);Xt(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:s}=t;if(e){if(!n.eql(s,n.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:ud,hexToBytes:fd}=An,vi=class extends Error{constructor(t=""){super(t)}},xe={Err:vi,_tlv:{encode:(r,t)=>{let{Err:e}=xe;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,s=Ke(n);if(s.length/2&128)throw new e("tlv.encode: long form length too big");let o=n>127?Ke(s.length/2|128):"";return Ke(r)+o+s+t},decode(r,t){let{Err:e}=xe,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let s=t[n++],o=!!(s&128),i=0;if(!o)i=s;else{let a=s&127;if(!a)throw new e("tlv.decode(long): indefinite length not supported");if(a>4)throw new e("tlv.decode(long): byte length is too big");let l=t.subarray(n,n+a);if(l.length!==a)throw new e("tlv.decode: length bytes not complete");if(l[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let u of l)i=i<<8|u;if(n+=a,i<128)throw new e("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new e("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=xe;if(r<ve)throw new t("integer: negative integers are not allowed");let e=Ke(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=xe;if(r[0]&128)throw new t("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return ud(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=xe,s=typeof r=="string"?fd(r):r;fr(s);let{v:o,l:i}=n.decode(48,s);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,o),{v:l,l:u}=n.decode(2,a);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(c),s:e.decode(l)}},hexFromSig(r){let{_tlv:t,_int:e}=xe,n=t.encode(2,e.encode(r.r)),s=t.encode(2,e.encode(r.s)),o=n+s;return t.encode(48,o)}},ve=BigInt(0),ft=BigInt(1),Vg=BigInt(2),sl=BigInt(3),Dg=BigInt(4);function hd(r){let t=ld(r),{Fp:e}=t,n=Te(t.n,t.nBitLength),s=t.toBytes||((b,d,v)=>{let A=d.toAffine();return he(Uint8Array.from([4]),e.toBytes(A.x),e.toBytes(A.y))}),o=t.fromBytes||(b=>{let d=b.subarray(1),v=e.fromBytes(d.subarray(0,e.BYTES)),A=e.fromBytes(d.subarray(e.BYTES,2*e.BYTES));return{x:v,y:A}});function i(b){let{a:d,b:v}=t,A=e.sqr(b),y=e.mul(A,b);return e.add(e.add(y,e.mul(b,d)),v)}if(!e.eql(e.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function c(b){return _r(b,ft,t.n)}function a(b){let{allowedPrivateKeyLengths:d,nByteLength:v,wrapPrivateKey:A,n:y}=t;if(d&&typeof b!="bigint"){if(ke(b)&&(b=ue(b)),typeof b!="string"||!d.includes(b.length))throw new Error("invalid private key");b=b.padStart(v*2,"0")}let I;try{I=typeof b=="bigint"?b:fe(nt("private key",b,v))}catch{throw new Error("invalid private key, expected hex or "+v+" bytes, got "+typeof b)}return A&&(I=Z(I,y)),Nt("private key",I,ft,y),I}function l(b){if(!(b instanceof h))throw new Error("ProjectivePoint expected")}let u=ze((b,d)=>{let{px:v,py:A,pz:y}=b;if(e.eql(y,e.ONE))return{x:v,y:A};let I=b.is0();d==null&&(d=I?e.ONE:e.inv(y));let L=e.mul(v,d),U=e.mul(A,d),k=e.mul(y,d);if(I)return{x:e.ZERO,y:e.ZERO};if(!e.eql(k,e.ONE))throw new Error("invZ was invalid");return{x:L,y:U}}),f=ze(b=>{if(b.is0()){if(t.allowInfinityPoint&&!e.is0(b.py))return;throw new Error("bad point: ZERO")}let{x:d,y:v}=b.toAffine();if(!e.isValid(d)||!e.isValid(v))throw new Error("bad point: x or y not FE");let A=e.sqr(v),y=i(d);if(!e.eql(A,y))throw new Error("bad point: equation left != right");if(!b.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class h{constructor(d,v,A){if(this.px=d,this.py=v,this.pz=A,d==null||!e.isValid(d))throw new Error("x required");if(v==null||!e.isValid(v))throw new Error("y required");if(A==null||!e.isValid(A))throw new Error("z required");Object.freeze(this)}static fromAffine(d){let{x:v,y:A}=d||{};if(!d||!e.isValid(v)||!e.isValid(A))throw new Error("invalid affine point");if(d instanceof h)throw new Error("projective point not allowed");let y=I=>e.eql(I,e.ZERO);return y(v)&&y(A)?h.ZERO:new h(v,A,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){let v=e.invertBatch(d.map(A=>A.pz));return d.map((A,y)=>A.toAffine(v[y])).map(h.fromAffine)}static fromHex(d){let v=h.fromAffine(o(nt("pointHex",d)));return v.assertValidity(),v}static fromPrivateKey(d){return h.BASE.multiply(a(d))}static msm(d,v){return Cn(h,n,d,v)}_setWindowSize(d){p.setWindowSize(this,d)}assertValidity(){f(this)}hasEvenY(){let{y:d}=this.toAffine();if(e.isOdd)return!e.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){l(d);let{px:v,py:A,pz:y}=this,{px:I,py:L,pz:U}=d,k=e.eql(e.mul(v,U),e.mul(I,y)),T=e.eql(e.mul(A,U),e.mul(L,y));return k&&T}negate(){return new h(this.px,e.neg(this.py),this.pz)}double(){let{a:d,b:v}=t,A=e.mul(v,sl),{px:y,py:I,pz:L}=this,U=e.ZERO,k=e.ZERO,T=e.ZERO,C=e.mul(y,y),tt=e.mul(I,I),q=e.mul(L,L),D=e.mul(y,I);return D=e.add(D,D),T=e.mul(y,L),T=e.add(T,T),U=e.mul(d,T),k=e.mul(A,q),k=e.add(U,k),U=e.sub(tt,k),k=e.add(tt,k),k=e.mul(U,k),U=e.mul(D,U),T=e.mul(A,T),q=e.mul(d,q),D=e.sub(C,q),D=e.mul(d,D),D=e.add(D,T),T=e.add(C,C),C=e.add(T,C),C=e.add(C,q),C=e.mul(C,D),k=e.add(k,C),q=e.mul(I,L),q=e.add(q,q),C=e.mul(q,D),U=e.sub(U,C),T=e.mul(q,tt),T=e.add(T,T),T=e.add(T,T),new h(U,k,T)}add(d){l(d);let{px:v,py:A,pz:y}=this,{px:I,py:L,pz:U}=d,k=e.ZERO,T=e.ZERO,C=e.ZERO,tt=t.a,q=e.mul(t.b,sl),D=e.mul(v,I),it=e.mul(A,L),E=e.mul(y,U),N=e.add(v,A),w=e.add(I,L);N=e.mul(N,w),w=e.add(D,it),N=e.sub(N,w),w=e.add(v,y);let g=e.add(I,U);return w=e.mul(w,g),g=e.add(D,E),w=e.sub(w,g),g=e.add(A,y),k=e.add(L,U),g=e.mul(g,k),k=e.add(it,E),g=e.sub(g,k),C=e.mul(tt,w),k=e.mul(q,E),C=e.add(k,C),k=e.sub(it,C),C=e.add(it,C),T=e.mul(k,C),it=e.add(D,D),it=e.add(it,D),E=e.mul(tt,E),w=e.mul(q,w),it=e.add(it,E),E=e.sub(D,E),E=e.mul(tt,E),w=e.add(w,E),D=e.mul(it,w),T=e.add(T,D),D=e.mul(g,w),k=e.mul(N,k),k=e.sub(k,D),D=e.mul(N,it),C=e.mul(g,C),C=e.add(C,D),new h(k,T,C)}subtract(d){return this.add(d.negate())}is0(){return this.equals(h.ZERO)}wNAF(d){return p.wNAFCached(this,d,h.normalizeZ)}multiplyUnsafe(d){let{endo:v,n:A}=t;Nt("scalar",d,ve,A);let y=h.ZERO;if(d===ve)return y;if(this.is0()||d===ft)return this;if(!v||p.hasPrecomputes(this))return p.wNAFCachedUnsafe(this,d,h.normalizeZ);let{k1neg:I,k1:L,k2neg:U,k2:k}=v.splitScalar(d),T=y,C=y,tt=this;for(;L>ve||k>ve;)L&ft&&(T=T.add(tt)),k&ft&&(C=C.add(tt)),tt=tt.double(),L>>=ft,k>>=ft;return I&&(T=T.negate()),U&&(C=C.negate()),C=new h(e.mul(C.px,v.beta),C.py,C.pz),T.add(C)}multiply(d){let{endo:v,n:A}=t;Nt("scalar",d,ft,A);let y,I;if(v){let{k1neg:L,k1:U,k2neg:k,k2:T}=v.splitScalar(d),{p:C,f:tt}=this.wNAF(U),{p:q,f:D}=this.wNAF(T);C=p.constTimeNegate(L,C),q=p.constTimeNegate(k,q),q=new h(e.mul(q.px,v.beta),q.py,q.pz),y=C.add(q),I=tt.add(D)}else{let{p:L,f:U}=this.wNAF(d);y=L,I=U}return h.normalizeZ([y,I])[0]}multiplyAndAddUnsafe(d,v,A){let y=h.BASE,I=(U,k)=>k===ve||k===ft||!U.equals(y)?U.multiplyUnsafe(k):U.multiply(k),L=I(this,v).add(I(d,A));return L.is0()?void 0:L}toAffine(d){return u(this,d)}isTorsionFree(){let{h:d,isTorsionFree:v}=t;if(d===ft)return!0;if(v)return v(h,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:d,clearCofactor:v}=t;return d===ft?this:v?v(h,this):this.multiplyUnsafe(t.h)}toRawBytes(d=!0){return Ht("isCompressed",d),this.assertValidity(),s(h,this,d)}toHex(d=!0){return Ht("isCompressed",d),ue(this.toRawBytes(d))}}h.BASE=new h(t.Gx,t.Gy,e.ONE),h.ZERO=new h(e.ZERO,e.ONE,e.ZERO);let m=t.nBitLength,p=kn(h,t.endo?Math.ceil(m/2):m);return{CURVE:t,ProjectivePoint:h,normPrivateKeyToScalar:a,weierstrassEquation:i,isWithinCurveOrder:c}}function dd(r){let t=Vr(r);return Xt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function ol(r){let t=dd(r),{Fp:e,n}=t,s=e.BYTES+1,o=2*e.BYTES+1;function i(E){return Z(E,n)}function c(E){return Sn(E,n)}let{ProjectivePoint:a,normPrivateKeyToScalar:l,weierstrassEquation:u,isWithinCurveOrder:f}=hd({...t,toBytes(E,N,w){let g=N.toAffine(),x=e.toBytes(g.x),S=he;return Ht("isCompressed",w),w?S(Uint8Array.from([N.hasEvenY()?2:3]),x):S(Uint8Array.from([4]),x,e.toBytes(g.y))},fromBytes(E){let N=E.length,w=E[0],g=E.subarray(1);if(N===s&&(w===2||w===3)){let x=fe(g);if(!_r(x,ft,e.ORDER))throw new Error("Point is not on curve");let S=u(x),R;try{R=e.sqrt(S)}catch(F){let _=F instanceof Error?": "+F.message:"";throw new Error("Point is not on curve"+_)}let P=(R&ft)===ft;return(w&1)===1!==P&&(R=e.neg(R)),{x,y:R}}else if(N===o&&w===4){let x=e.fromBytes(g.subarray(0,e.BYTES)),S=e.fromBytes(g.subarray(e.BYTES,2*e.BYTES));return{x,y:S}}else{let x=s,S=o;throw new Error("invalid Point, expected length of "+x+", or uncompressed "+S+", got "+N)}}}),h=E=>ue(Ne(E,t.nByteLength));function m(E){let N=n>>ft;return E>N}function p(E){return m(E)?i(-E):E}let b=(E,N,w)=>fe(E.slice(N,w));class d{constructor(N,w,g){this.r=N,this.s=w,this.recovery=g,this.assertValidity()}static fromCompact(N){let w=t.nByteLength;return N=nt("compactSignature",N,w*2),new d(b(N,0,w),b(N,w,2*w))}static fromDER(N){let{r:w,s:g}=xe.toSig(nt("DER",N));return new d(w,g)}assertValidity(){Nt("r",this.r,ft,n),Nt("s",this.s,ft,n)}addRecoveryBit(N){return new d(this.r,this.s,N)}recoverPublicKey(N){let{r:w,s:g,recovery:x}=this,S=U(nt("msgHash",N));if(x==null||![0,1,2,3].includes(x))throw new Error("recovery id invalid");let R=x===2||x===3?w+t.n:w;if(R>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let P=x&1?"03":"02",V=a.fromHex(P+h(R)),F=c(R),_=i(-S*F),j=i(g*F),J=a.BASE.multiplyAndAddUnsafe(V,_,j);if(!J)throw new Error("point at infinify");return J.assertValidity(),J}hasHighS(){return m(this.s)}normalizeS(){return this.hasHighS()?new d(this.r,i(-this.s),this.recovery):this}toDERRawBytes(){return qe(this.toDERHex())}toDERHex(){return xe.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return qe(this.toCompactHex())}toCompactHex(){return h(this.r)+h(this.s)}}let v={isValidPrivateKey(E){try{return l(E),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let E=Ao(t.n);return Oa(t.randomBytes(E),t.n)},precompute(E=8,N=a.BASE){return N._setWindowSize(E),N.multiply(BigInt(3)),N}};function A(E,N=!0){return a.fromPrivateKey(E).toRawBytes(N)}function y(E){let N=ke(E),w=typeof E=="string",g=(N||w)&&E.length;return N?g===s||g===o:w?g===2*s||g===2*o:E instanceof a}function I(E,N,w=!0){if(y(E))throw new Error("first arg must be private key");if(!y(N))throw new Error("second arg must be public key");return a.fromHex(N).multiply(l(E)).toRawBytes(w)}let L=t.bits2int||function(E){if(E.length>8192)throw new Error("input is too large");let N=fe(E),w=E.length*8-t.nBitLength;return w>0?N>>BigInt(w):N},U=t.bits2int_modN||function(E){return i(L(E))},k=Or(t.nBitLength);function T(E){return Nt("num < 2^"+t.nBitLength,E,ve,k),Ne(E,t.nByteLength)}function C(E,N,w=tt){if(["recovered","canonical"].some(ut=>ut in w))throw new Error("sign() legacy options not supported");let{hash:g,randomBytes:x}=t,{lowS:S,prehash:R,extraEntropy:P}=w;S==null&&(S=!0),E=nt("msgHash",E),nl(w),R&&(E=nt("prehashed msgHash",g(E)));let V=U(E),F=l(N),_=[T(F),T(V)];if(P!=null&&P!==!1){let ut=P===!0?x(e.BYTES):P;_.push(nt("extraEntropy",ut))}let j=he(..._),J=V;function lt(ut){let ht=L(ut);if(!f(ht))return;let yt=c(ht),Ct=a.BASE.multiply(ht).toAffine(),At=i(Ct.x);if(At===ve)return;let Jt=i(yt*i(J+At*F));if(Jt===ve)return;let oe=(Ct.x===At?0:2)|Number(Ct.y&ft),Nr=Jt;return S&&m(Jt)&&(Nr=p(Jt),oe^=1),new d(At,Nr,oe)}return{seed:j,k2sig:lt}}let tt={lowS:t.lowS,prehash:!1},q={lowS:t.lowS,prehash:!1};function D(E,N,w=tt){let{seed:g,k2sig:x}=C(E,N,w),S=t;return xo(S.hash.outputLen,S.nByteLength,S.hmac)(g,x)}a.BASE._setWindowSize(8);function it(E,N,w,g=q){let x=E;N=nt("msgHash",N),w=nt("publicKey",w);let{lowS:S,prehash:R,format:P}=g;if(nl(g),"strict"in g)throw new Error("options.strict was renamed to lowS");if(P!==void 0&&P!=="compact"&&P!=="der")throw new Error("format must be compact or der");let V=typeof x=="string"||ke(x),F=!V&&!P&&typeof x=="object"&&x!==null&&typeof x.r=="bigint"&&typeof x.s=="bigint";if(!V&&!F)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let _,j;try{if(F&&(_=new d(x.r,x.s)),V){try{P!=="compact"&&(_=d.fromDER(x))}catch(oe){if(!(oe instanceof xe.Err))throw oe}!_&&P!=="der"&&(_=d.fromCompact(x))}j=a.fromHex(w)}catch{return!1}if(!_||S&&_.hasHighS())return!1;R&&(N=t.hash(N));let{r:J,s:lt}=_,ut=U(N),ht=c(lt),yt=i(ut*ht),Ct=i(J*ht),At=a.BASE.multiplyAndAddUnsafe(j,yt,Ct)?.toAffine();return At?i(At.x)===J:!1}return{CURVE:t,getPublicKey:A,getSharedSecret:I,sign:D,verify:it,ProjectivePoint:a,Signature:d,utils:v}}function pd(r){return{hash:r,hmac:(t,...e)=>xi(r,t,ho(...e)),randomBytes:xn}}function il(r,t){let e=n=>ol({...r,...pd(n)});return{...e(t),create:e}}var ll=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),al=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),md=BigInt(1),Ei=BigInt(2),cl=(r,t)=>(r+t/Ei)/t;function gd(r){let t=ll,e=BigInt(3),n=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),l=r*r*r%t,u=l*l*r%t,f=rt(u,e,t)*u%t,h=rt(f,e,t)*u%t,m=rt(h,Ei,t)*l%t,p=rt(m,s,t)*m%t,b=rt(p,o,t)*p%t,d=rt(b,c,t)*b%t,v=rt(d,a,t)*d%t,A=rt(v,c,t)*b%t,y=rt(A,e,t)*u%t,I=rt(y,i,t)*p%t,L=rt(I,n,t)*l%t,U=rt(L,Ei,t);if(!Bi.eql(Bi.sqr(U),r))throw new Error("Cannot find square root");return U}var Bi=Te(ll,void 0,void 0,{sqrt:gd}),Je=il({a:BigInt(0),b:BigInt(7),Fp:Bi,n:al,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=al,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-md*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=e,i=BigInt("0x100000000000000000000000000000000"),c=cl(o*r,t),a=cl(-n*r,t),l=Z(r-c*e-a*s,t),u=Z(-c*n-a*o,t),f=l>i,h=u>i;if(f&&(l=t-l),h&&(u=t-u),l>i||u>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:l,k2neg:h,k2:u}}}},dr),Wg=BigInt(0);var jg=Je.ProjectivePoint;function _t(r,t){t==null&&(t=r.reduce((s,o)=>s+o.length,0));let e=Ut(t),n=0;for(let s of r)e.set(s,n),n+=s.length;return e}function ul(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function fl(r,t,e){let n=Dr.digest(e instanceof Uint8Array?e:e.subarray());if(ul(n))return n.then(({digest:s})=>Je.verify(t,s,r)).catch(s=>{throw new Yr(String(s))});try{return Je.verify(t,n.digest,r)}catch(s){throw new Yr(String(s))}}var Ns=class{type="secp256k1";raw;_key;constructor(t){this._key=dl(t),this.raw=hl(this._key)}toMultihash(){return ce.digest(Ue(this))}toCID(){return dt.createV1(114,this.toMultihash())}toString(){return X.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,e){return fl(this._key,e,t)}};function Ai(r){return new Ns(r)}function hl(r){return Je.ProjectivePoint.fromHex(r).toRawBytes(!0)}function dl(r){try{return Je.ProjectivePoint.fromHex(r),r}catch(t){throw new rr(String(t))}}function xr(r){let{Type:t,Data:e}=Qt.decode(r),n=e??new Uint8Array;switch(t){case ct.RSA:return wi(n);case ct.Ed25519:return Uo(n);case ct.secp256k1:return Ai(n);default:throw new Me}}function pl(r){let{Type:t,Data:e}=Qt.decode(r.digest),n=e??new Uint8Array;switch(t){case ct.Ed25519:return Uo(n);case ct.secp256k1:return Ai(n);default:throw new Me}}function Ue(r){return Qt.encode({Type:ct[r.type],Data:r.raw})}var gl=Symbol.for("@achingbrain/uint8arraylist");function ml(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let s=e+n.byteLength;if(t<s)return{buf:n,index:t-e};e=s}throw new RangeError("index is out of bounds")}function Ts(r){return!!r?.[gl]}var jt=class r{bufs;length;[gl]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(Ts(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(Ts(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=ml(this.bufs,t);return e.buf[e.index]}set(t,e){let n=ml(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(Ts(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:s}=this._subList(t,e);return _t(n,s)}subarray(t,e){let{bufs:n,length:s}=this._subList(t,e);return n.length===1?n[0]:_t(n,s)}sublist(t,e){let{bufs:n,length:s}=this._subList(t,e),o=new r;return o.length=s,o.bufs=[...n],o}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],s=0;for(let o=0;o<this.bufs.length;o++){let i=this.bufs[o],c=s,a=c+i.byteLength;if(s=a,t>=a)continue;let l=t>=c&&t<a,u=e>c&&e<=a;if(l&&u){if(t===c&&e===a){n.push(i);break}let f=t-c;n.push(i.subarray(f,f+(e-t)));break}if(l){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(u){if(e===a){n.push(i);break}n.push(i.subarray(0,e-c));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Ts(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let o=256,i=new Int32Array(o);for(let f=0;f<o;f++)i[f]=-1;for(let f=0;f<s;f++)i[n[f]]=f;let c=i,a=this.byteLength-n.byteLength,l=n.byteLength-1,u;for(let f=e;f<=a;f+=u){u=0;for(let h=l;h>=0;h--){let m=this.get(f+h);if(n[h]!==m){u=Math.max(1,h-c[m]);break}}if(u===0)return f}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=Ut(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let s=pt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,e,n),this.write(s,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let s=pt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,e,n),this.write(s,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let s=pt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,e,n),this.write(s,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=Ut(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let s=pt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,e,n),this.write(s,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let s=pt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,e,n),this.write(s,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let s=pt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,e,n),this.write(s,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let s=pt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,e,n),this.write(s,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let s=pt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,e,n),this.write(s,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!bt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((s,o)=>s+o.byteLength,0)),n.length=e,n}};var Qr;(function(r){let t;r.codec=()=>(t==null&&(t=Gt((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.publicKey!=null&&e.publicKey.byteLength>0&&(n.uint32(10),n.bytes(e.publicKey)),e.payloadType!=null&&e.payloadType.byteLength>0&&(n.uint32(18),n.bytes(e.payloadType)),e.payload!=null&&e.payload.byteLength>0&&(n.uint32(26),n.bytes(e.payload)),e.signature!=null&&e.signature.byteLength>0&&(n.uint32(42),n.bytes(e.signature)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let o={publicKey:pt(0),payloadType:pt(0),payload:pt(0),signature:pt(0)},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let c=e.uint32();switch(c>>>3){case 1:{o.publicKey=e.bytes();break}case 2:{o.payloadType=e.bytes();break}case 3:{o.payload=e.bytes();break}case 5:{o.signature=e.bytes();break}default:{e.skipType(c&7);break}}}return o})),t),r.encode=e=>zt(e,r.codec()),r.decode=(e,n)=>$t(e,r.codec(),n)})(Qr||(Qr={}));var Us=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var ne=class r{static createFromProtobuf=async t=>{let e=Qr.decode(t),n=xr(e.publicKey);return new r({publicKey:n,payloadType:e.payloadType,payload:e.payload,signature:e.signature})};static seal=async(t,e)=>{if(e==null)throw new Error("Missing private key");let n=t.domain,s=t.codec,o=t.marshal(),i=yl(n,s,o),c=await e.sign(i.subarray());return new r({publicKey:e.publicKey,payloadType:s,payload:o,signature:c})};static openAndCertify=async(t,e)=>{let n=await r.createFromProtobuf(t);if(!await n.validate(e))throw new Us("Envelope signature is not valid for the given domain");return n};publicKey;payloadType;payload;signature;marshaled;constructor(t){let{publicKey:e,payloadType:n,payload:s,signature:o}=t;this.publicKey=e,this.payloadType=n,this.payload=s,this.signature=o}marshal(){return this.marshaled==null&&(this.marshaled=Qr.encode({publicKey:Ue(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return bt(this.marshal(),t.marshal())}async validate(t){let e=yl(t,this.payloadType,this.payload);return this.publicKey.verify(e.subarray(),this.signature)}},yl=(r,t,e)=>{let n=$(r),s=Ot(n.byteLength),o=Ot(t.length),i=Ot(e.length);return new jt(s,n,o,t,i,e)};var bl=Symbol.for("nodejs.util.inspect.custom"),yd=114,tn=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[eo]=!0;toString(){return this.string==null&&(this.string=X.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return dt.createV1(yd,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return bt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return bt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[bl](){return`PeerId(${this.toString()})`}},en=class extends tn{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},rn=class extends tn{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},nn=class extends tn{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},bd=2336,sn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=ce.digest($(this.url))}[bl](){return`PeerId(${this.url})`}[eo]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return dt.createV1(bd,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=Q(t)),t.toString()===this.toString())}};var wd=114,wl=2336;function xl(r){if(r.type==="Ed25519")return new rn({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new nn({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new en({multihash:r.toCID().multihash,publicKey:r});throw new Me}function Si(r){if(vd(r))return new en({multihash:r});if(xd(r))try{let t=pl(r);if(t.type==="Ed25519")return new rn({multihash:r,publicKey:t});if(t.type==="secp256k1")return new nn({multihash:r,publicKey:t})}catch{let e=Q(r.digest);return new sn(new URL(e))}throw new pn("Supplied PeerID Multihash is invalid")}function Ls(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==wd&&r.code!==wl)throw new dn("Supplied PeerID CID is invalid");if(r.code===wl){let t=Q(r.multihash.digest);return new sn(new URL(t))}return Si(r.multihash)}function xd(r){return r.code===ce.code}function vd(r){return r.code===Dr.code}function vl(r,t){let e=(n,s)=>n.toString().localeCompare(s.toString());return r.length!==t.length?!1:(t.sort(e),r.sort(e).every((n,s)=>t[s].equals(n)))}var Rs=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}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(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,s){return this.readAtomically(()=>{let o=0,i=0,c=this.peekChar();if(c===void 0)return;let a=c==="0",l=2**(8*s)-1;for(;;){let u=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let h=Number.parseInt(f,t);if(!Number.isNaN(h))return h});if(u===void 0)break;if(o*=t,o+=u,o>l||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&a&&i>1?void 0:o})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let s=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[s]=i[0],e[s+1]=i[1],e[s+2]=i[2],e[s+3]=i[3],[s+4,!0]}let o=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(o===void 0)return[s,!1];e[s]=o>>8,e[s+1]=o&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,s]=t(e);if(n===16)return e;if(s||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let o=new Uint8Array(14),i=16-(n+2),[c]=t(o.subarray(0,i));return e.set(o.subarray(0,c),16-c),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var El=45,Ed=15,vr=new Rs;function Ps(r){if(!(r.length>Ed))return vr.new(r).parseWith(()=>vr.readIPv4Addr())}function _s(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>El))return vr.new(r).parseWith(()=>vr.readIPv6Addr())}function Xe(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>El)return;let e=vr.new(r).parseWith(()=>vr.readIPAddr());if(e)return t&&e.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,e[0],e[1],e[2],e[3]]):e}function Bl(r,t,e){let n=0;for(let s of r)if(!(n<t)){if(n>e)break;if(s!==255)return!1;n++}return!0}function Al(r,t,e,n){let s=0;for(let o of r)if(!(s<e)){if(s>n)break;if(o!==t[s])return!1;s++}return!0}function Ii(r){switch(r.length){case Qe:return r.join(".");case tr:{let t=[];for(let e=0;e<r.length;e++)e%2===0&&t.push(r[e].toString(16).padStart(2,"0")+r[e+1].toString(16).padStart(2,"0"));return t.join(":")}default:throw new Error("Invalid ip length")}}function Sl(r){let t=0;for(let[e,n]of r.entries()){if(n===255){t+=8;continue}for(;n&128;)t++,n=n<<1;if(n&128)return-1;for(let s=e+1;s<r.length;s++)if(r[s]!=0)return-1;break}return t}function Il(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var Qe=4,tr=16,Bb=parseInt("0xFFFF",16),Bd=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function on(r,t){t.length===tr&&r.length===Qe&&Bl(t,0,11)&&(t=t.slice(12)),t.length===Qe&&r.length===tr&&Al(r,Bd,0,11)&&(r=r.slice(12));let e=r.length;if(e!=t.length)throw new Error("Failed to mask ip");let n=new Uint8Array(e);for(let s=0;s<e;s++)n[s]=r[s]&t[s];return n}function kl(r,t){if(typeof t=="string"&&(t=Xe(t)),t==null)throw new Error("Invalid ip");if(t.length!==r.network.length)return!1;for(let e=0;e<t.length;e++)if((r.network[e]&r.mask[e])!==(t[e]&r.mask[e]))return!1;return!0}function ki(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=Qe,s=Ps(t);if(s==null&&(n=tr,s=_s(t),s==null))throw new Error("Failed to parse given CIDR: "+r);let o=parseInt(e,10);if(Number.isNaN(o)||String(o).length!==e.length||o<0||o>n*8)throw new Error("Failed to parse given CIDR: "+r);let i=Ci(o,8*n);return{network:on(s,i),mask:i}}function Ci(r,t){if(t!==8*Qe&&t!==8*tr)throw new Error("Invalid CIDR mask");if(r<0||r>t)throw new Error("Invalid CIDR mask");let e=t/8,n=new Uint8Array(e);for(let s=0;s<e;s++){if(r>=8){n[s]=255,r-=8;continue}n[s]=255-(255>>r),r=0}return n}var Er=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=ki(t));else{let n=Xe(t);if(n==null)throw new Error("Failed to parse network");e=String(e);let s=parseInt(e,10);if(Number.isNaN(s)||String(s).length!==e.length||s<0||s>n.length*8){let o=Xe(e);if(o==null)throw new Error("Failed to parse mask");this.mask=o}else this.mask=Ci(s,8*n.length);this.network=on(n,this.mask)}}contains(t){return kl({network:this.network,mask:this.mask},t)}toString(){let t=Sl(this.mask),e=t!==-1?String(t):Il(this.mask);return Ii(this.network)+"/"+e}};function Cl(r,t){return new Er(r).contains(t)}function Br(r){return!!Ps(r)}function Ar(r){return!!_s(r)}function Os(r){return!!Xe(r)}var Nl=Br,Ad=Ar,Ni=function(r){let t=0;if(r=r.toString().trim(),Nl(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(Ad(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let o=Nl(e[n]),i;o&&(i=Ni(e[n]),e[n]=Q(i.slice(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,Q(i.slice(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let o=[n,1];for(n=9-e.length;n>0;n--)o.push("0");e.splice.apply(e,o)}let s=new Uint8Array(t+16);for(n=0;n<e.length;n++){let o=parseInt(e[n],16);s[t++]=o>>8&255,s[t++]=o&255}return s}throw new Error("invalid ip address")},Tl=function(r,t=0,e){t=~~t,e=e??r.length-t;let n=new DataView(r.buffer);if(e===4){let s=[];for(let o=0;o<e;o++)s.push(r[t+o]);return s.join(".")}if(e===16){let s=[];for(let o=0;o<e;o+=2)s.push(n.getUint16(t+o).toString(16));return s.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var Sr={},Ti={},Id=[[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"]];Id.forEach(r=>{let t=kd(...r);Ti[t.code]=t,Sr[t.name]=t});function kd(r,t,e,n,s){return{code:r,size:t,name:e,resolvable:!!n,path:!!s}}function z(r){if(typeof r=="number"){if(Ti[r]!=null)return Ti[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Sr[r]!=null)return Sr[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var rw=z("ip4"),nw=z("ip6"),sw=z("ipcidr");function Pi(r,t){switch(z(r).code){case 4:case 41:return Nd(t);case 42:return Ri(t);case 43:return Q(t,"base10");case 6:case 273:case 33:case 132:return Rl(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Ri(t);case 421:return Rd(t);case 444:return Ll(t);case 445:return Ll(t);case 466:return Ld(t);case 481:return globalThis.encodeURIComponent(Ri(t));default:return Q(t,"base16")}}function _i(r,t){switch(z(r).code){case 4:return Ul(t);case 41:return Ul(t);case 42:return Li(t);case 43:return $(t,"base10");case 6:case 273:case 33:case 132:return Oi(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Li(t);case 421:return Td(t);case 444:return Pd(t);case 445:return _d(t);case 466:return Ud(t);case 481:return Li(globalThis.decodeURIComponent(t));default:return $(t,"base16")}}var Ui=Object.values(Mr).map(r=>r.decoder),Cd=function(){let r=Ui[0].or(Ui[1]);return Ui.slice(2).forEach(t=>r=r.or(t)),r}();function Ul(r){if(!Os(r))throw new Error("invalid ip address");return Ni(r)}function Nd(r){let t=Tl(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!Os(t))throw new Error("invalid ip address");return t}function Oi(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Rl(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Li(r){let t=$(r),e=Uint8Array.from(Ot(t.length));return _t([e,t],e.length+t.length)}function Ri(r){let t=de(r);if(r=r.slice(xt(t)),r.length!==t)throw new Error("inconsistent lengths");return Q(r)}function Td(r){let t;r[0]==="Q"||r[0]==="1"?t=Fe(X.decode(`z${r}`)).bytes:t=dt.parse(r).multihash.bytes;let e=Uint8Array.from(Ot(t.length));return _t([e,t],e.length+t.length)}function Ud(r){let t=Cd.decode(r),e=Uint8Array.from(Ot(t.length));return _t([e,t],e.length+t.length)}function Ld(r){let t=de(r),e=r.slice(xt(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+Q(e,"base64url")}function Rd(r){let t=de(r),e=r.slice(xt(t));if(e.length!==t)throw new Error("inconsistent lengths");return Q(e,"base58btc")}function Pd(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=ae.decode("b"+t[0]),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let s=Oi(n);return _t([e,s],e.length+s.length)}function _d(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=ae.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let s=Oi(n);return _t([e,s],e.length+s.length)}function Ll(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=Q(t,"base32"),s=Rl(e);return`${n}:${s}`}function Pl(r){r=Vi(r);let t=[],e=[],n=null,s=r.split("/").slice(1);if(s.length===1&&s[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let o=0;o<s.length;o++){let i=s[o],c=z(i);if(c.size===0){t.push([c.code]),e.push([c.code]);continue}if(o++,o>=s.length)throw new Vs("invalid address: "+r);if(c.path===!0){n=Vi(s.slice(o).join("/")),t.push([c.code,_i(c.code,n)]),e.push([c.code,n]);break}let a=_i(c.code,s[o]);t.push([c.code,a]),e.push([c.code,Pi(c.code,a)])}return{string:_l(e),bytes:Ds(t),tuples:t,stringTuples:e,path:n}}function Di(r){let t=[],e=[],n=null,s=0;for(;s<r.length;){let o=de(r,s),i=xt(o),c=z(o),a=Od(c,r.slice(s+i));if(a===0){t.push([o]),e.push([o]),s+=i;continue}let l=r.slice(s+i,s+i+a);if(s+=a+i,s>r.length)throw new Vs("Invalid address Uint8Array: "+Q(r,"base16"));t.push([o,l]);let u=Pi(o,l);if(e.push([o,u]),c.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:_l(e),tuples:t,stringTuples:e,path:n}}function _l(r){let t=[];return r.map(e=>{let n=z(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),Vi(t.join("/"))}function Ds(r){return _t(r.map(t=>{let e=z(t[0]),n=Uint8Array.from(Ot(e.code));return t.length>1&&t[1]!=null&&(n=_t([n,t[1]])),n}))}function Od(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=de(t instanceof Uint8Array?t:Uint8Array.from(t));return e+xt(e)}}function Vi(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}var Vs=class extends Error{static name="ParseError";name="ParseError";constructor(t){super(`Error parsing address: ${t}`)}};var Vd=Symbol.for("nodejs.util.inspect.custom"),Fi=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Dd=[z("dns").code,z("dns4").code,z("dns6").code,z("dnsaddr").code],Mi=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},Ms=class r{bytes;#e;#t;#r;#n;[Fi]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=Di(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=Pl(t)}else if(Vl(t))e=Di(t.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=e.bytes,this.#e=e.string,this.#t=e.tuples,this.#r=e.stringTuples,this.#n=e.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let t,e,n,s,o="",i=z("tcp"),c=z("udp"),a=z("ip4"),l=z("ip6"),u=z("dns6"),f=z("ip6zone");for(let[m,p]of this.stringTuples())m===f.code&&(o=`%${p??""}`),Dd.includes(m)&&(e=i.name==="tcp"?"tcp":"udp",s=443,n=`${p??""}${o}`,t=m===u.code?6:4),(m===i.code||m===c.code)&&(e=z(m).name==="tcp"?"tcp":"udp",s=parseInt(p??"")),(m===a.code||m===l.code)&&(e=z(m).name==="tcp"?"tcp":"udp",n=`${p??""}${o}`,t=m===l.code?6:4);if(t==null||e==null||n==null||s==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:t,host:n,transport:e,port:s}}protos(){return this.#t.map(([t])=>Object.assign({},z(t)))}protoCodes(){return this.#t.map(([t])=>t)}protoNames(){return this.#t.map(([t])=>z(t).name)}tuples(){return this.#t.map(([t,e])=>e==null?[t]:[t,e])}stringTuples(){return this.#r.map(([t,e])=>e==null?[t]:[t,e])}encapsulate(t){return t=new r(t),new r(this.toString()+t.toString())}decapsulate(t){let e=t.toString(),n=this.toString(),s=n.lastIndexOf(e);if(s<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,s))}decapsulateCode(t){let e=this.tuples();for(let n=e.length-1;n>=0;n--)if(e[n][0]===t)return new r(Ds(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,s])=>{n===Sr.p2p.code&&t.push([n,s]),n===Sr["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?Q(X.decode(`z${n}`),"base58btc"):Q(dt.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return bt(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(o=>o.resolvable);if(e==null)return[this];let n=Ol.get(e.name);if(n==null)throw new Mi(`no available resolver for ${e.name}`);return(await n(this,t)).map(o=>se(o))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(t){let e=(t??this).protos();return!(e.length!==2||e[0].code!==4&&e[0].code!==41||e[1].code!==6&&e[1].code!==273)}[Vd](){return`Multiaddr(${this.#e})`}};var Ol=new Map;function Vl(r){return!!r?.[Fi]}function se(r){return new Ms(r)}var Dl="libp2p-peer-record",Ml=Uint8Array.from([3,1]);var an;(function(r){let t;(function(n){let s;n.codec=()=>(s==null&&(s=Gt((o,i,c={})=>{c.lengthDelimited!==!1&&i.fork(),o.multiaddr!=null&&o.multiaddr.byteLength>0&&(i.uint32(10),i.bytes(o.multiaddr)),c.lengthDelimited!==!1&&i.ldelim()},(o,i,c={})=>{let a={multiaddr:pt(0)},l=i==null?o.len:o.pos+i;for(;o.pos<l;){let u=o.uint32();switch(u>>>3){case 1:{a.multiaddr=o.bytes();break}default:{o.skipType(u&7);break}}}return a})),s),n.encode=o=>zt(o,n.codec()),n.decode=(o,i)=>$t(o,n.codec(),i)})(t=r.AddressInfo||(r.AddressInfo={}));let e;r.codec=()=>(e==null&&(e=Gt((n,s,o={})=>{if(o.lengthDelimited!==!1&&s.fork(),n.peerId!=null&&n.peerId.byteLength>0&&(s.uint32(10),s.bytes(n.peerId)),n.seq!=null&&n.seq!==0n&&(s.uint32(16),s.uint64(n.seq)),n.addresses!=null)for(let i of n.addresses)s.uint32(26),r.AddressInfo.codec().encode(i,s);o.lengthDelimited!==!1&&s.ldelim()},(n,s,o={})=>{let i={peerId:pt(0),seq:0n,addresses:[]},c=s==null?n.len:n.pos+s;for(;n.pos<c;){let a=n.uint32();switch(a>>>3){case 1:{i.peerId=n.bytes();break}case 2:{i.seq=n.uint64();break}case 3:{if(o.limits?.addresses!=null&&i.addresses.length===o.limits.addresses)throw new Ze('Decode error - map field "addresses" had too many elements');i.addresses.push(r.AddressInfo.codec().decode(n,n.uint32(),{limits:o.limits?.addresses$}));break}default:{n.skipType(a&7);break}}}return i})),e),r.encode=n=>zt(n,r.codec()),r.decode=(n,s)=>$t(n,r.codec(),s)})(an||(an={}));var Zt=class r{static createFromProtobuf=t=>{let e=an.decode(t),n=Si(Fe(e.peerId)),s=(e.addresses??[]).map(i=>se(i.multiaddr)),o=e.seq;return new r({peerId:n,multiaddrs:s,seqNumber:o})};static DOMAIN=Dl;static CODEC=Ml;peerId;multiaddrs;seqNumber;domain=r.DOMAIN;codec=r.CODEC;marshaled;constructor(t){let{peerId:e,multiaddrs:n,seqNumber:s}=t;this.peerId=e,this.multiaddrs=n??[],this.seqNumber=s??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=an.encode({peerId:this.peerId.toMultihash().bytes,seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(t=>({multiaddr:t.bytes}))})),this.marshaled}equals(t){return!(!(t instanceof r)||!this.peerId.equals(t.peerId)||this.seqNumber!==t.seqNumber||!vl(this.multiaddrs,t.multiaddrs))}};function Md(r){return r[Symbol.asyncIterator]!=null}function Fd(r){if(Md(r))return(async()=>{for await(let t of r);})();for(let t of r);}var Fl=Fd;function Yt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Fs=globalThis.CustomEvent??Event;async function*Hi(r,t={}){let e=t.concurrency??1/0;e<1&&(e=1/0);let n=t.ordered==null?!1:t.ordered,s=new EventTarget,o=[],i=Yt(),c=Yt(),a=!1,l,u=!1;s.addEventListener("task-complete",()=>{c.resolve()}),Promise.resolve().then(async()=>{try{for await(let p of r){if(o.length===e&&(i=Yt(),await i.promise),u)break;let b={done:!1};o.push(b),p().then(d=>{b.done=!0,b.ok=!0,b.value=d,s.dispatchEvent(new Fs("task-complete"))},d=>{b.done=!0,b.err=d,s.dispatchEvent(new Fs("task-complete"))})}a=!0,s.dispatchEvent(new Fs("task-complete"))}catch(p){l=p,s.dispatchEvent(new Fs("task-complete"))}});function f(){return n?o[0]?.done:!!o.find(p=>p.done)}function*h(){for(;o.length>0&&o[0].done;){let p=o[0];if(o.shift(),p.ok)yield p.value;else throw u=!0,i.resolve(),p.err;i.resolve()}}function*m(){for(;f();)for(let p=0;p<o.length;p++)if(o[p].done){let b=o[p];if(o.splice(p,1),p--,b.ok)yield b.value;else throw u=!0,i.resolve(),b.err;i.resolve()}}for(;;){if(f()||(c=Yt(),await c.promise),l!=null)throw l;if(n?yield*h():yield*m(),a&&o.length===0)break}}var Hs=class extends Error{type;code;constructor(t,e,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=e??"ABORT_ERR"}};async function Hl(r,t,e){if(t==null)return r;if(t.aborted)return Promise.reject(new Hs(e?.errorMessage,e?.errorCode,e?.errorName));let n,s=new Hs(e?.errorMessage,e?.errorCode,e?.errorName);try{return await Promise.race([r,new Promise((o,i)=>{n=()=>{i(s)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var Ki=class{readNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.readNext=Yt(),this.haveNext=Yt()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Yt(),t}async throw(t){return this.ended=!0,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return await this._push(void 0),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Yt(),await Hl(this.readNext.promise,e?.signal,e)}};function Kl(){return new Ki}var Ks=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};var qi=class extends Error{code;constructor(t,e){super(t),this.code=e}},$i=class extends qi{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted",this.name="AbortError"}};function ql(r,t){let e=Kl();r.sink(e).catch(async i=>{await e.end(i)}),r.sink=async i=>{for await(let c of i)await e.push(c);await e.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let s=new jt;return{read:async(i,c)=>{c?.signal?.throwIfAborted();let a,l=new Promise((u,f)=>{a=()=>{f(new $i("Read aborted"))},c?.signal?.addEventListener("abort",a)});try{if(i==null){let{done:f,value:h}=await Promise.race([n.next(),l]);return f===!0?new jt:h}for(;s.byteLength<i;){let{value:f,done:h}=await Promise.race([n.next(),l]);if(h===!0)throw new Ks("unexpected end of input");s.append(f)}let u=s.sublist(0,i);return s.consume(i),u}finally{a!=null&&c?.signal?.removeEventListener("abort",a)}},write:async(i,c)=>{c?.signal?.throwIfAborted(),i instanceof Uint8Array?await e.push(i,c):await e.push(i.subarray(),c)},unwrap:()=>{if(s.byteLength>0){let i=r.source;r.source=async function*(){t?.yieldBytes===!1?yield s:yield*s,yield*i}()}return r}}}var qs=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},$s=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},zs=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function $l(r,t={}){let e=ql(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=xt(t.maxDataLength));let n=t?.lengthDecoder??de,s=t?.lengthEncoder??Ot;return{read:async i=>{let c=-1,a=new jt;for(;;){a.append(await e.read(1,i));try{c=n(a)}catch(l){if(l instanceof RangeError)continue;throw l}if(c<0)throw new qs("Invalid message length");if(t?.maxLengthLength!=null&&a.byteLength>t.maxLengthLength)throw new zs("message length length too long");if(c>-1)break}if(t?.maxDataLength!=null&&c>t.maxDataLength)throw new $s("message length too long");return e.read(c,i)},write:async(i,c)=>{await e.write(new jt(s(i.byteLength),i),c)},writeV:async(i,c)=>{let a=new jt(...i.flatMap(l=>[s(l.byteLength),l]));await e.write(a,c)},unwrap:()=>e.unwrap()}}function Ir(r,t){let e=$l(r,t),n={read:async(s,o)=>{let i=await e.read(o);return s.decode(i)},write:async(s,o,i)=>{await e.write(o.encode(s),i)},writeV:async(s,o,i)=>{await e.writeV(s.map(c=>o.encode(c)),i)},pb:s=>({read:async o=>n.read(s,o),write:async(o,i)=>n.write(o,s,i),writeV:async(o,i)=>n.writeV(o,s,i),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var zl="0.1.0",Gl="id",Wl="id/push",jl="1.0.0",Zl="1.0.0";var De;(function(r){let t;r.codec=()=>(t==null&&(t=Gt((e,n,s={})=>{if(s.lengthDelimited!==!1&&n.fork(),e.protocolVersion!=null&&(n.uint32(42),n.string(e.protocolVersion)),e.agentVersion!=null&&(n.uint32(50),n.string(e.agentVersion)),e.publicKey!=null&&(n.uint32(10),n.bytes(e.publicKey)),e.listenAddrs!=null)for(let o of e.listenAddrs)n.uint32(18),n.bytes(o);if(e.observedAddr!=null&&(n.uint32(34),n.bytes(e.observedAddr)),e.protocols!=null)for(let o of e.protocols)n.uint32(26),n.string(o);e.signedPeerRecord!=null&&(n.uint32(66),n.bytes(e.signedPeerRecord)),s.lengthDelimited!==!1&&n.ldelim()},(e,n,s={})=>{let o={listenAddrs:[],protocols:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let c=e.uint32();switch(c>>>3){case 5:{o.protocolVersion=e.string();break}case 6:{o.agentVersion=e.string();break}case 1:{o.publicKey=e.bytes();break}case 2:{if(s.limits?.listenAddrs!=null&&o.listenAddrs.length===s.limits.listenAddrs)throw new Ze('Decode error - map field "listenAddrs" had too many elements');o.listenAddrs.push(e.bytes());break}case 4:{o.observedAddr=e.bytes();break}case 3:{if(s.limits?.protocols!=null&&o.protocols.length===s.limits.protocols)throw new Ze('Decode error - map field "protocols" had too many elements');o.protocols.push(e.string());break}case 8:{o.signedPeerRecord=e.bytes();break}default:{e.skipType(c&7);break}}}return o})),t),r.encode=e=>zt(e,r.codec()),r.decode=(e,n)=>$t(e,r.codec(),n)})(De||(De={}));var Rt={protocolPrefix:"ipfs",timeout:5e3,maxInboundStreams:1,maxOutboundStreams:1,maxObservedAddresses:10,maxMessageSize:8192,runOnConnectionOpen:!0,runOnSelfUpdate:!0,runOnLimitedConnection:!0,concurrency:32};function Yl(r){if(r!=null&&r.length>0)try{return se(r)}catch{}}function qd(r,t){return t??r.userAgent}async function Gs(r,t,e,n,s){if(e("received identify from %p",n.remotePeer),s==null)throw new Dt("message was null or undefined");let o={};if(s.listenAddrs.length>0&&(o.addresses=s.listenAddrs.map(a=>({isCertified:!1,multiaddr:se(a)}))),s.protocols.length>0&&(o.protocols=s.protocols),s.publicKey!=null){let a=xr(s.publicKey);if(!xl(a).equals(n.remotePeer))throw new Dt("public key did not match remote PeerId");o.publicKey=a}let i;if(s.signedPeerRecord!=null){e.trace("received signedPeerRecord from %p",n.remotePeer);let a=s.signedPeerRecord,l=await ne.openAndCertify(a,Zt.DOMAIN),u=Zt.createFromProtobuf(l.payload),f=Ls(l.publicKey.toCID());if(!u.peerId.equals(f))throw new Dt("signing key does not match PeerId in the PeerRecord");if(!n.remotePeer.equals(u.peerId))throw new Dt("signing key does not match remote PeerId");let h;try{h=await r.get(u.peerId)}catch(m){if(m.name!=="NotFoundError")throw m}if(h!=null&&(o.metadata=h.metadata,h.peerRecordEnvelope!=null)){let m=await ne.createFromProtobuf(h.peerRecordEnvelope),p=Zt.createFromProtobuf(m.payload);p.seqNumber>=u.seqNumber&&(e("sequence number was lower or equal to existing sequence number - stored: %d received: %d",p.seqNumber,u.seqNumber),u=p,a=h.peerRecordEnvelope)}o.peerRecordEnvelope=a,o.addresses=u.multiaddrs.map(m=>({isCertified:!0,multiaddr:m})),i={seq:u.seqNumber,addresses:u.multiaddrs}}else e("%p did not send a signed peer record",n.remotePeer);if(e.trace("patching %p with",n.remotePeer,o),await r.patch(n.remotePeer,o),s.agentVersion!=null||s.protocolVersion!=null){let a={};s.agentVersion!=null&&(a.AgentVersion=$(s.agentVersion)),s.protocolVersion!=null&&(a.ProtocolVersion=$(s.protocolVersion)),e.trace("merging %p metadata",n.remotePeer,a),await r.merge(n.remotePeer,{metadata:a})}let c={peerId:n.remotePeer,protocolVersion:s.protocolVersion,agentVersion:s.agentVersion,publicKey:s.publicKey,listenAddrs:s.listenAddrs.map(a=>se(a)),observedAddr:s.observedAddr==null?void 0:se(s.observedAddr),protocols:s.protocols,signedPeerRecord:i,connection:n};return t.safeDispatchEvent("peer:identify",{detail:c}),c}var kr=class{host;protocol;started;timeout;peerId;privateKey;peerStore;registrar;addressManager;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxObservedAddresses;events;runOnLimitedConnection;log;constructor(t,e){this.protocol=e.protocol,this.started=!1,this.peerId=t.peerId,this.privateKey=t.privateKey,this.peerStore=t.peerStore,this.registrar=t.registrar,this.addressManager=t.addressManager,this.events=t.events,this.log=e.log,this.timeout=e.timeout??Rt.timeout,this.maxInboundStreams=e.maxInboundStreams??Rt.maxInboundStreams,this.maxOutboundStreams=e.maxOutboundStreams??Rt.maxOutboundStreams,this.maxMessageSize=e.maxMessageSize??Rt.maxMessageSize,this.maxObservedAddresses=e.maxObservedAddresses??Rt.maxObservedAddresses,this.runOnLimitedConnection=e.runOnLimitedConnection??Rt.runOnLimitedConnection,this.host={protocolVersion:`${e.protocolPrefix??Rt.protocolPrefix}/${zl}`,agentVersion:qd(t.nodeInfo,e.agentVersion)}}isStarted(){return this.started}async start(){this.started||(await this.peerStore.merge(this.peerId,{metadata:{AgentVersion:$(this.host.agentVersion),ProtocolVersion:$(this.host.protocolVersion)}}),await this.registrar.handle(this.protocol,t=>{this.handleProtocol(t).catch(e=>{this.log.error(e)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams,runOnLimitedConnection:this.runOnLimitedConnection}),this.started=!0)}async stop(){await this.registrar.unhandle(this.protocol),this.started=!1}};var Ws=class extends kr{connectionManager;concurrency;constructor(t,e={}){super(t,{...e,protocol:`/${e.protocolPrefix??Rt.protocolPrefix}/${Wl}/${Zl}`,log:t.logger.forComponent("libp2p:identify-push")}),this.connectionManager=t.connectionManager,this.concurrency=e.concurrency??Rt.concurrency,(e.runOnSelfUpdate??Rt.runOnSelfUpdate)&&t.events.addEventListener("self:peer:update",n=>{this.push().catch(s=>{this.log.error(s)})})}[gn]=["@libp2p/identify-push"];async push(){if(!this.isStarted())return;let t=this.addressManager.getAddresses().map(u=>u.decapsulateCode(z("p2p").code)),e=new Zt({peerId:this.peerId,multiaddrs:t}),n=await ne.seal(e,this.privateKey),s=this.registrar.getProtocols(),o=await this.peerStore.get(this.peerId),i=Q(o.metadata.get("AgentVersion")??$(this.host.agentVersion)),c=Q(o.metadata.get("ProtocolVersion")??$(this.host.protocolVersion)),a=this;async function*l(){for(let u of a.connectionManager.getConnections())(await a.peerStore.get(u.remotePeer)).protocols.includes(a.protocol)&&(yield async()=>{let h,m=AbortSignal.timeout(a.timeout);try{h=await u.newStream(a.protocol,{signal:m,runOnLimitedConnection:a.runOnLimitedConnection}),await Ir(h,{maxDataLength:a.maxMessageSize}).pb(De).write({listenAddrs:t.map(b=>b.bytes),signedPeerRecord:n.marshal(),protocols:s,agentVersion:i,protocolVersion:c},{signal:m}),await h.close({signal:m})}catch(p){a.log.error("could not push identify update to peer",p),h?.abort(p)}})}await Fl(Hi(l(),{concurrency:this.concurrency}))}async handleProtocol(t){let{connection:e,stream:n}=t;try{if(this.peerId.equals(e.remotePeer))throw new Error("received push from ourselves?");let s={signal:AbortSignal.timeout(this.timeout)},i=await Ir(n,{maxDataLength:this.maxMessageSize}).pb(De).read(s);await n.close(s),await Gs(this.peerStore,this.events,this.log,e,i)}catch(s){this.log.error("received invalid message",s),n.abort(s);return}this.log.trace("handled push from %p",e.remotePeer)}};var zd=41;function Jl(r){try{let[[t,e]]=r.stringTuples();if(e==null)return!1;if(t===zd)return Cl("2000::/3",e)}catch{}return!1}var Ql=ia(Xl(),1),Gd=["0.0.0.0/8","10.0.0.0/8","100.64.0.0/10","127.0.0.0/8","169.254.0.0/16","172.16.0.0/12","192.0.0.0/24","192.0.0.0/29","192.0.0.8/32","192.0.0.9/32","192.0.0.10/32","192.0.0.170/32","192.0.0.171/32","192.0.2.0/24","192.31.196.0/24","192.52.193.0/24","192.88.99.0/24","192.168.0.0/16","192.175.48.0/24","198.18.0.0/15","198.51.100.0/24","203.0.113.0/24","240.0.0.0/4","255.255.255.255/32"],Wd=Gd.map(r=>new Ql.Netmask(r));function zi(r){for(let t of Wd)if(t.contains(r))return!0;return!1}function jd(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function Zd(r){let t=r.split(":");if(t.length<2)return!1;let e=t[t.length-1].padStart(4,"0"),n=t[t.length-2].padStart(4,"0"),s=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(e.substring(0,2),16)}.${parseInt(e.substring(2),16)}`;return zi(s)}function Yd(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function Jd(r){let t=r.split(":"),e=t[t.length-1];return zi(e)}function Xd(r){return/^::$/.test(r)||/^::1$/.test(r)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(r)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(r)||/^ff([0-9a-fA-F]{2,2}):/i.test(r)}function tu(r){return Br(r)?zi(r):jd(r)?Zd(r):Yd(r)?Jd(r):Ar(r)?Xd(r):void 0}function eu(r){try{let[[t]]=r.stringTuples();return t===4||t===41}catch{}return!1}function ru(r){try{if(!eu(r))return!1;let[[,t]]=r.stringTuples();return t==null?!1:tu(t)??!1}catch{}return!0}var Qd=r=>r.toString().split("/").slice(1),Cr=r=>({match:t=>t.length<1?!1:r(t[0])?t.slice(1):!1,pattern:"fn"}),H=r=>({match:t=>Cr(e=>e===r).match(t),pattern:r}),er=()=>({match:r=>Cr(t=>typeof t=="string").match(r),pattern:"{string}"}),ln=()=>({match:r=>Cr(t=>!isNaN(parseInt(t))).match(r),pattern:"{number}"}),Y=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{X.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),un=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{Wo.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),G=r=>({match:t=>{let e=r.match(t);return e===!1?t:e},pattern:`optional(${r.pattern})`}),Bt=(...r)=>({match:t=>{let e;for(let n of r){let s=n.match(t);s!==!1&&(e==null||s.length<e.length)&&(e=s)}return e??!1},pattern:`or(${r.map(t=>t.pattern).join(", ")})`}),K=(...r)=>({match:t=>{for(let e of r){let n=e.match(t);if(n===!1)return!1;t=n}return t},pattern:`and(${r.map(t=>t.pattern).join(", ")})`});function st(...r){function t(s){let o=Qd(s);for(let i of r){let c=i.match(o);if(c===!1)return!1;o=c}return o}function e(s){return t(s)!==!1}function n(s){let o=t(s);return o===!1?!1:o.length===0}return{matchers:r,matches:e,exactMatch:n}}var Zs=K(H("dns4"),er()),Ys=K(H("dns6"),er()),Js=K(H("dnsaddr"),er()),Wi=K(H("dns"),er()),Gx=st(Zs,G(Y())),Wx=st(Ys,G(Y())),jx=st(Js,G(Y())),Zx=st(Bt(Wi,Js,Zs,Ys),G(Y())),nu=K(H("ip4"),Cr(Br)),su=K(H("ip6"),Cr(Ar)),ji=Bt(nu,su),Ee=Bt(ji,Wi,Zs,Ys,Js),ou=st(Bt(ji,K(Bt(Wi,Js,Zs,Ys),G(Y())))),Yx=st(nu),Jx=st(su),Xx=st(ji),Zi=K(Ee,H("tcp"),ln()),fn=K(Ee,H("udp"),ln()),iu=st(K(Zi,G(Y()))),Qx=st(fn),Yi=K(fn,H("quic"),G(Y())),Xs=K(fn,H("quic-v1"),G(Y())),t0=Bt(Yi,Xs),t1=st(Yi),e1=st(Xs),Gi=Bt(Ee,Zi,fn,Yi,Xs),au=Bt(K(Gi,H("ws"),G(Y()))),r1=st(au),cu=Bt(K(Gi,H("wss"),G(Y())),K(Gi,H("tls"),G(K(H("sni"),er())),H("ws"),G(Y()))),n1=st(cu),lu=K(fn,H("webrtc-direct"),G(un()),G(un()),G(Y())),s1=st(lu),uu=K(Xs,H("webtransport"),G(un()),G(un()),G(Y())),o1=st(uu),js=Bt(au,cu,K(Zi,G(Y())),K(t0,G(Y())),K(Ee,G(Y())),lu,uu,Y()),i1=st(js),e0=K(js,H("p2p-circuit"),Y()),a1=st(e0),r0=Bt(K(js,H("p2p-circuit"),H("webrtc"),G(Y())),K(js,H("webrtc"),G(Y())),K(H("webrtc"),G(Y()))),c1=st(r0),n0=Bt(K(Ee,H("tcp"),ln(),H("http"),G(Y())),K(Ee,H("http"),G(Y()))),l1=st(n0),s0=Bt(K(Ee,H("tcp"),Bt(K(H("443"),H("http")),K(ln(),H("https"))),G(Y())),K(Ee,H("tls"),H("http"),G(Y())),K(Ee,H("https"),G(Y()))),u1=st(s0),o0=Bt(K(H("memory"),er(),G(Y()))),f1=st(o0);var i0=41,Qs=class extends kr{constructor(t,e={}){super(t,{...e,protocol:`/${e.protocolPrefix??Rt.protocolPrefix}/${Gl}/${jl}`,log:t.logger.forComponent("libp2p:identify")}),(e.runOnConnectionOpen??Rt.runOnConnectionOpen)&&t.events.addEventListener("connection:open",n=>{let s=n.detail;this.identify(s).catch(o=>{o.name!==mn.name&&this.log.error("error during identify trigged by connection:open",o)})})}[gn]=["@libp2p/identify"];async _identify(t,e={}){let n;if(e.signal==null){let s=AbortSignal.timeout(this.timeout);e={...e,signal:s}}try{n=await t.newStream(this.protocol,{...e,runOnLimitedConnection:this.runOnLimitedConnection});let o=await Ir(n,{maxDataLength:this.maxMessageSize}).pb(De).read(e);return await n.close(e),o}catch(s){throw n?.abort(s),s}}async identify(t,e={}){let n=await this._identify(t,e),{publicKey:s,protocols:o,observedAddr:i}=n;if(s==null)throw new Dt("public key was missing from identify message");let c=xr(s),a=Ls(c.toCID());if(!t.remotePeer.equals(a))throw new Dt("identified peer does not match the expected peer");if(this.peerId.equals(a))throw new Dt("identified peer is our own peer id?");return this.maybeAddObservedAddress(i),this.log("identify completed for peer %p and protocols %o",a,o),Gs(this.peerStore,this.events,this.log,t,n)}maybeAddObservedAddress(t){let e=Yl(t);if(e==null)return;if(this.log.trace("our observed address was %a",e),ru(e)){this.log.trace("our observed address was private");return}if(e.stringTuples()[0][0]===i0&&!Jl(e)){this.log.trace("our observed address was IPv6 but not a global unicast address");return}iu.exactMatch(e)||(this.log.trace("storing the observed address"),this.addressManager.addObservedAddr(e))}async handleProtocol(t){let{connection:e,stream:n}=t,s=AbortSignal.timeout(this.timeout);try{let o=await this.peerStore.get(this.peerId),i=this.addressManager.getAddresses().map(u=>u.decapsulateCode(z("p2p").code)),c=o.peerRecordEnvelope;if(i.length>0&&c==null){let u=new Zt({peerId:this.peerId,multiaddrs:i});c=(await ne.seal(u,this.privateKey)).marshal().subarray()}let a=e.remoteAddr.bytes;ou.matches(e.remoteAddr)||(a=void 0),await Ir(n).pb(De).write({protocolVersion:this.host.protocolVersion,agentVersion:this.host.agentVersion,publicKey:Ue(this.privateKey.publicKey),listenAddrs:i.map(u=>u.bytes),signedPeerRecord:c,observedAddr:a,protocols:o.protocols},{signal:s}),await n.close({signal:s})}catch(o){this.log.error("could not respond to identify request",o),n.abort(o)}}};function a0(r={}){return t=>new Qs(t,r)}function c0(r={}){return t=>new Ws(t,r)}return Au(l0);})();
|
|
7
7
|
/*! Bundled license information:
|
|
8
8
|
|
|
9
9
|
pvtsutils/build/index.js:
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Identify": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_identify.Identify.html",
|
|
3
|
+
".:Identify": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_identify.Identify.html",
|
|
4
|
+
"IdentifyComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_identify.IdentifyComponents.html",
|
|
5
|
+
".:IdentifyComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_identify.IdentifyComponents.html",
|
|
6
|
+
"IdentifyInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_identify.IdentifyInit.html",
|
|
7
|
+
".:IdentifyInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_identify.IdentifyInit.html",
|
|
8
|
+
"IdentifyPush": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_identify.IdentifyPush.html",
|
|
9
|
+
".:IdentifyPush": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_identify.IdentifyPush.html",
|
|
10
|
+
"IdentifyPushComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_identify.IdentifyPushComponents.html",
|
|
11
|
+
".:IdentifyPushComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_identify.IdentifyPushComponents.html",
|
|
12
|
+
"IdentifyPushInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_identify.IdentifyPushInit.html",
|
|
13
|
+
".:IdentifyPushInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_identify.IdentifyPushInit.html",
|
|
14
|
+
"identify": "https://libp2p.github.io/js-libp2p/functions/_libp2p_identify.identify-1.html",
|
|
15
|
+
".:identify": "https://libp2p.github.io/js-libp2p/functions/_libp2p_identify.identify-1.html",
|
|
16
|
+
"identifyPush": "https://libp2p.github.io/js-libp2p/functions/_libp2p_identify.identifyPush-1.html",
|
|
17
|
+
".:identifyPush": "https://libp2p.github.io/js-libp2p/functions/_libp2p_identify.identifyPush-1.html"
|
|
18
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/identify",
|
|
3
|
-
"version": "3.0.21
|
|
3
|
+
"version": "3.0.21",
|
|
4
4
|
"description": "Implementation of the Identify Protocol",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/protocol-identify#readme",
|
|
@@ -52,12 +52,12 @@
|
|
|
52
52
|
"doc-check": "aegir doc-check"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@libp2p/crypto": "5.0.12
|
|
56
|
-
"@libp2p/interface": "2.6.0
|
|
57
|
-
"@libp2p/interface-internal": "2.3.3
|
|
58
|
-
"@libp2p/peer-id": "5.0.13
|
|
59
|
-
"@libp2p/peer-record": "8.0.19
|
|
60
|
-
"@libp2p/utils": "6.5.3
|
|
55
|
+
"@libp2p/crypto": "^5.0.12",
|
|
56
|
+
"@libp2p/interface": "^2.6.0",
|
|
57
|
+
"@libp2p/interface-internal": "^2.3.3",
|
|
58
|
+
"@libp2p/peer-id": "^5.0.13",
|
|
59
|
+
"@libp2p/peer-record": "^8.0.19",
|
|
60
|
+
"@libp2p/utils": "^6.5.3",
|
|
61
61
|
"@multiformats/multiaddr": "^12.3.3",
|
|
62
62
|
"@multiformats/multiaddr-matcher": "^1.6.0",
|
|
63
63
|
"it-drain": "^3.0.7",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"uint8arrays": "^5.1.0"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
|
-
"@libp2p/logger": "5.1.9
|
|
71
|
+
"@libp2p/logger": "^5.1.9",
|
|
72
72
|
"aegir": "^45.0.5",
|
|
73
73
|
"delay": "^6.0.0",
|
|
74
74
|
"it-length-prefixed": "^10.0.1",
|