@libp2p/webtransport 4.0.17-e1db332a4 → 4.0.18-0c7bbbb07
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/package.json +12 -12
package/dist/index.min.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
`));let e=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return t.length?`${e} :
|
|
5
5
|
${t.join(`
|
|
6
6
|
`)}`:`${e} :`}};Zc=He;U.Constructed=Zc;He.NAME="CONSTRUCTED";var Xn=class extends Tt{fromBER(t,e,n){return e}toBER(t){return Xt}};Xn.override="EndOfContentValueBlock";var Xc,Jn=class extends St{constructor(t={}){super(t,Xn),this.idBlock.tagClass=1,this.idBlock.tagNumber=0}};Xc=Jn;U.EndOfContent=Xc;Jn.NAME=en;var Jc,Me=class extends St{constructor(t={}){super(t,Tt),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}`}};Jc=Me;U.Null=Jc;Me.NAME="NULL";var Qn=class extends ke(Tt){constructor({value:t,...e}={}){super(e),e.valueHex?this.valueHexView=Y.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=Y.BufferSourceConverter.toUint8Array(t);return Se(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,gi.call(this),this.blockLength=n,e+n):-1}toBER(){return this.valueHexView.slice()}toJSON(){return{...super.toJSON(),value:this.value}}};Qn.NAME="BooleanValueBlock";var Qc,ts=class extends St{constructor(t={}){super(t,Qn),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}`}};Qc=ts;U.Boolean=Qc;ts.NAME="BOOLEAN";var es=class extends ke(oe){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=oe.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===en){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, OCTET STRING may consists of OCTET STRINGs only",-1}if(i!==jc)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?oe.prototype.toBER.call(this,t,e):t?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.slice().buffer}toJSON(){return{...super.toJSON(),isConstructed:this.isConstructed}}};es.NAME="OctetStringValueBlock";var tl,Be=class r extends St{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},es),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=Ns(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?He.prototype.onAsciiEncoding.call(this):`${this.constructor.NAME} : ${Y.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 Y.BufferSourceConverter.concat(t)}};tl=Be;U.OctetString=tl;Be.NAME=jc;var rs=class extends ke(oe){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=oe.prototype.fromBER.call(this,t,e,n),s===-1)return s;for(let a of this.value){let c=a.constructor.NAME;if(c===en){if(this.isIndefiniteForm)break;return this.error="EndOfContent is unexpected, BIT STRING may consists of BIT STRINGs only",-1}if(c!==zc)return this.error="BIT STRING may consists of BIT STRINGs only",-1;let l=a.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=Y.BufferSourceConverter.toUint8Array(t);if(!Se(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 a=i.subarray(1);try{if(a.byteLength){let c=Ns(a,0,a.byteLength);c.offset!==-1&&c.offset===n-1&&(this.value=[c.result])}}catch{}}return this.valueHexView=i.subarray(1),this.blockLength=i.length,e+n}toBER(t,e){if(this.isConstructed)return oe.prototype.toBER.call(this,t,e);if(t)return new ArrayBuffer(this.valueHexView.byteLength+1);if(!this.valueHexView.byteLength)return Xt;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}}};rs.NAME="BitStringValueBlock";var el,Br=class extends St{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},rs),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 He.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)}`}}};el=Br;U.BitString=el;Br.NAME=zc;var rl;function a0(r,t){let e=new Uint8Array([0]),n=new Uint8Array(r),s=new Uint8Array(t),o=n.slice(0),i=o.length-1,a=s.slice(0),c=a.length-1,l=0,u=c<i?i:c,f=0;for(let g=u;g>=0;g--,f++){switch(!0){case f<a.length:l=o[i-f]+a[c-f]+e[0];break;default:l=o[i-f]+e[0]}switch(e[0]=l/10,!0){case f>=o.length:o=qn(new Uint8Array([l%10]),o);break;default:o[i-f]=l%10}}return e[0]>0&&(o=qn(e,o)),o}function Gc(r){if(r>=Qr.length)for(let t=Qr.length;t<=r;t++){let e=new Uint8Array([0]),n=Qr[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=qn(e,n)),Qr.push(n)}return Qr[r]}function c0(r,t){let e=0,n=new Uint8Array(r),s=new Uint8Array(t),o=n.slice(0),i=o.length-1,a=s.slice(0),c=a.length-1,l,u=0;for(let f=c;f>=0;f--,u++)switch(l=o[i-u]-a[c-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-c+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 rn=class extends ke(Tt){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=gi.call(this)))}set valueDec(t){this._valueDec=t,this.isHexOnly=!1,this.valueHexView=new Uint8Array(Fc(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="",a=!1;for(let c=o.byteLength-1;c>=0;c--){s=o[c];for(let l=0;l<8;l++){if((s&1)===1)switch(n){case t:e=c0(Gc(n),e),i="-";break;default:e=a0(e,Gc(n))}n++,s>>=1}}for(let c=0;c<e.length;c++)e[c]&&(a=!0),a&&(i+=qc.charAt(e[c]));return a===!1&&(i+=qc.charAt(0)),i}};rl=rn;rn.NAME="IntegerValueBlock";Object.defineProperty(rl.prototype,"valueHex",{set:function(r){this.valueHexView=new Uint8Array(r),this.setValueHex()},get:function(){return this.valueHexView.slice().buffer}});var nl,dt=class r extends St{constructor(t={}){super(t,rn),this.idBlock.tagClass=1,this.idBlock.tagNumber=2}toBigInt(){return Gn(),BigInt(this.valueBlock.toString())}static fromBigInt(t){Gn();let e=BigInt(t),n=new tn,s=e.toString(16).replace(/^-/,""),o=new Uint8Array(Y.Convert.FromHex(s));if(e<0){let a=new Uint8Array(o.length+(o[0]&128?1:0));a[0]|=128;let l=BigInt(`0x${Y.Convert.ToHex(a)}`)+e,u=Y.BufferSourceConverter.toUint8Array(Y.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()}`}};nl=dt;U.Integer=nl;dt.NAME="INTEGER";var sl,ns=class extends dt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=10}};sl=ns;U.Enumerated=sl;ns.NAME="ENUMERATED";var nn=class extends ke(Tt){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=Y.BufferSourceConverter.toUint8Array(t);if(!Se(this,s,e,n))return-1;let o=s.subarray(e,e+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=o[a]&127,this.blockLength++,!!(o[a]&128));a++);let i=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)i[a]=this.valueHexView[a];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=nr(this.valueHexView,7):(this.isHexOnly=!0,this.warnings.push("Too big SID for decoding, hex only")),e+this.blockLength)}set valueBigInt(t){Gn();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=Oe(this.valueDec,7);if(e.byteLength===0)return this.error="Error during encoding SID value",Xt;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=Y.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}}};nn.NAME="sidBlock";var ss=class extends Tt{constructor({value:t=Ar,...e}={}){super(e),this.value=[],t&&this.fromString(t)}fromBER(t,e,n){let s=e;for(;n>0;){let o=new nn;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,Xt;e.push(s)}return yi(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],a=0;switch(i.valueDec){case 0:break;case 1:a=40;break;case 2:a=80;break;default:this.value=[];return}let c=parseInt(s,10);if(isNaN(c))return;i.valueDec=c+a,o=!1}else{let i=new nn;if(s>Number.MAX_SAFE_INTEGER){Gn();let a=BigInt(s);i.valueBigInt=a}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}};ss.NAME="ObjectIdentifierValueBlock";var ol,Zt=class extends St{constructor(t={}){super(t,ss),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()}}};ol=Zt;U.ObjectIdentifier=ol;Zt.NAME="OBJECT IDENTIFIER";var sn=class extends ke(ve){constructor({valueDec:t=0,...e}={}){super(e),this.valueDec=t}fromBER(t,e,n){if(n===0)return e;let s=Y.BufferSourceConverter.toUint8Array(t);if(!Se(this,s,e,n))return-1;let o=s.subarray(e,e+n);this.valueHexView=new Uint8Array(n);for(let a=0;a<n&&(this.valueHexView[a]=o[a]&127,this.blockLength++,!!(o[a]&128));a++);let i=new Uint8Array(this.blockLength);for(let a=0;a<this.blockLength;a++)i[a]=this.valueHexView[a];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=nr(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=Oe(this.valueDec,7);if(e.byteLength===0)return this.error="Error during encoding SID value",Xt;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=Y.Convert.ToHex(this.valueHexView):t=this.valueDec.toString(),t}toJSON(){return{...super.toJSON(),valueDec:this.valueDec}}};sn.NAME="relativeSidBlock";var os=class extends Tt{constructor({value:t=Ar,...e}={}){super(e),this.value=[],t&&this.fromString(t)}fromBER(t,e,n){let s=e;for(;n>0;){let o=new sn;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,Xt;n.push(o)}return yi(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 sn;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}};os.NAME="RelativeObjectIdentifierValueBlock";var il,is=class extends St{constructor(t={}){super(t,os),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()}}};il=is;U.RelativeObjectIdentifier=il;is.NAME="RelativeObjectIdentifier";var al,Et=class extends He{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=16}};al=Et;U.Sequence=al;Et.NAME="SEQUENCE";var cl,as=class extends He{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=17}};cl=as;U.Set=cl;as.NAME="SET";var cs=class extends ke(Tt){constructor({...t}={}){super(t),this.isHexOnly=!0,this.value=Ar}toJSON(){return{...super.toJSON(),value:this.value}}};cs.NAME="StringValueBlock";var ls=class extends cs{};ls.NAME="SimpleStringValueBlock";var Rt=class extends Wn{constructor({...t}={}){super(t,ls)}fromBuffer(t){this.valueBlock.value=String.fromCharCode.apply(null,Y.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}};Rt.NAME="SIMPLE STRING";var us=class extends Rt{fromBuffer(t){this.valueBlock.valueHexView=Y.BufferSourceConverter.toUint8Array(t);try{this.valueBlock.value=Y.Convert.ToUtf8String(t)}catch(e){this.warnings.push(`Error during "decodeURIComponent": ${e}, using raw string`),this.valueBlock.value=Y.Convert.ToBinary(t)}}fromString(t){this.valueBlock.valueHexView=new Uint8Array(Y.Convert.FromUtf8String(t)),this.valueBlock.value=t}};us.NAME="Utf8StringValueBlock";var ll,Ae=class extends us{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=12}};ll=Ae;U.Utf8String=ll;Ae.NAME="UTF8String";var fs=class extends Rt{fromBuffer(t){this.valueBlock.value=Y.Convert.ToUtf16String(t),this.valueBlock.valueHexView=Y.BufferSourceConverter.toUint8Array(t)}fromString(t){this.valueBlock.value=t,this.valueBlock.valueHexView=new Uint8Array(Y.Convert.FromUtf16String(t))}};fs.NAME="BmpStringValueBlock";var ul,hs=class extends fs{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=30}};ul=hs;U.BmpString=ul;hs.NAME="BMPString";var ds=class extends Rt{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=Oe(t.charCodeAt(s),8),i=new Uint8Array(o);if(i.length>4)continue;let a=4-i.length;for(let c=i.length-1;c>=0;c--)n[s*4+c+a]=i[c]}this.valueBlock.value=t}};ds.NAME="UniversalStringValueBlock";var fl,ps=class extends ds{constructor({...t}={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=28}};fl=ps;U.UniversalString=fl;ps.NAME="UniversalString";var hl,gs=class extends Rt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=18}};hl=gs;U.NumericString=hl;gs.NAME="NumericString";var dl,ys=class extends Rt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=19}};dl=ys;U.PrintableString=dl;ys.NAME="PrintableString";var pl,ms=class extends Rt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=20}};pl=ms;U.TeletexString=pl;ms.NAME="TeletexString";var gl,ws=class extends Rt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=21}};gl=ws;U.VideotexString=gl;ws.NAME="VideotexString";var yl,bs=class extends Rt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=22}};yl=bs;U.IA5String=yl;bs.NAME="IA5String";var ml,xs=class extends Rt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=25}};ml=xs;U.GraphicString=ml;xs.NAME="GraphicString";var wl,on=class extends Rt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=26}};wl=on;U.VisibleString=wl;on.NAME="VisibleString";var bl,Es=class extends Rt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=27}};bl=Es;U.GeneralString=bl;Es.NAME="GeneralString";var xl,vs=class extends Rt{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=29}};xl=vs;U.CharacterString=xl;vs.NAME="CharacterString";var El,an=class extends on{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,Y.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]=Ct(this.year<2e3?this.year-1900:this.year-2e3,2),e[1]=Ct(this.month,2),e[2]=Ct(this.day,2),e[3]=Ct(this.hour,2),e[4]=Ct(this.minute,2),e[5]=Ct(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}}};El=an;U.UTCTime=El;an.NAME="UTCTime";var vl,Bs=class extends an{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,a=0,c=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,g=n.indexOf("+"),m="";if(g===-1&&(g=n.indexOf("-"),f=-1),g!==-1){if(m=n.substring(g+1),n=n.substring(0,g),m.length!==2&&m.length!==4)throw new Error("Wrong input string for conversion");let d=parseInt(m.substring(0,2),10);if(isNaN(d.valueOf()))throw new Error("Wrong input string for conversion");if(a=f*d,m.length===4){if(d=parseInt(m.substring(2,4),10),isNaN(d.valueOf()))throw new Error("Wrong input string for conversion");c=f*d}}}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)+a;break;case 5:this.minute=parseInt(u[f],10)+c;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(Ct(this.year,4)),e.push(Ct(this.month,2)),e.push(Ct(this.day,2)),e.push(Ct(this.hour,2)),e.push(Ct(this.minute,2)),e.push(Ct(this.second,2)),this.millisecond!==0&&(e.push("."),e.push(Ct(this.millisecond,3))),e.push("Z"),e.join("")}return super.toString(t)}toJSON(){return{...super.toJSON(),millisecond:this.millisecond}}};vl=Bs;U.GeneralizedTime=vl;Bs.NAME="GeneralizedTime";var Bl,As=class extends Ae{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=31}};Bl=As;U.DATE=Bl;As.NAME="DATE";var Al,Ss=class extends Ae{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=32}};Al=Ss;U.TimeOfDay=Al;Ss.NAME="TimeOfDay";var Sl,ks=class extends Ae{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=33}};Sl=ks;U.DateTime=Sl;ks.NAME="DateTime";var kl,Is=class extends Ae{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=34}};kl=Is;U.Duration=kl;Is.NAME="Duration";var Il,_s=class extends Ae{constructor(t={}){super(t),this.idBlock.tagClass=1,this.idBlock.tagNumber=14}};Il=_s;U.TIME=Il;_s.NAME="TIME";function u0(r){let{result:t}=Sr(r),e=t.valueBlock.value;return{n:q(ie(e[1].toBigInt()),"base64url"),e:q(ie(e[2].toBigInt()),"base64url"),d:q(ie(e[3].toBigInt()),"base64url"),p:q(ie(e[4].toBigInt()),"base64url"),q:q(ie(e[5].toBigInt()),"base64url"),dp:q(ie(e[6].toBigInt()),"base64url"),dq:q(ie(e[7].toBigInt()),"base64url"),qi:q(ie(e[8].toBigInt()),"base64url"),kty:"RSA",alg:"RS256"}}function f0(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 F("JWK was missing components","ERR_INVALID_PARAMETERS");let e=new Et({value:[new dt({value:0}),dt.fromBigInt(ae(tt(r.n,"base64url"))),dt.fromBigInt(ae(tt(r.e,"base64url"))),dt.fromBigInt(ae(tt(r.d,"base64url"))),dt.fromBigInt(ae(tt(r.p,"base64url"))),dt.fromBigInt(ae(tt(r.q,"base64url"))),dt.fromBigInt(ae(tt(r.dp,"base64url"))),dt.fromBigInt(ae(tt(r.dq,"base64url"))),dt.fromBigInt(ae(tt(r.qi,"base64url")))]}).toBER();return new Uint8Array(e,0,e.byteLength)}function h0(r){let{result:t}=Sr(r),e=t.valueBlock.value[1].valueBlock.value[0].valueBlock.value;return{kty:"RSA",n:q(ie(e[0].toBigInt()),"base64url"),e:q(ie(e[1].toBigInt()),"base64url")}}function d0(r){if(r.n==null||r.e==null)throw new F("JWK was missing components","ERR_INVALID_PARAMETERS");let e=new Et({value:[new Et({value:[new Zt({value:"1.2.840.113549.1.1.1"}),new Me]}),new Br({valueHex:new Et({value:[dt.fromBigInt(ae(tt(r.n,"base64url"))),dt.fromBigInt(ae(tt(r.e,"base64url")))]}).toBER()})]}).toBER();return new Uint8Array(e,0,e.byteLength)}function ie(r){let t=r.toString(16);t.length%2>0&&(t=`0${t}`);let e=t.length/2,n=new Uint8Array(e),s=0,o=0;for(;s<e;)n[s]=parseInt(t.slice(o,o+2),16),s+=1,o+=2;return n}function ae(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(""))}var p0=16,wi=32,bi=1e4;async function g0(r,t){let e=Lt.get(),s=new Et({value:[new dt({value:0}),new Et({value:[new Zt({value:"1.2.840.113549.1.1.1"}),new Me]}),new Be({valueHex:r.marshal()})]}).toBER(),o=new Uint8Array(s,0,s.byteLength),i=rr(p0),a=await di(yr,t,i,{c:bi,dkLen:wi}),c=rr(16),l=await e.subtle.importKey("raw",a,"AES-CBC",!1,["encrypt"]),u=await e.subtle.encrypt({name:"AES-CBC",iv:c},l,o),f=new Et({value:[new Be({valueHex:i}),new dt({value:bi}),new dt({value:wi}),new Et({value:[new Zt({value:"1.2.840.113549.2.11"}),new Me]})]}),g=new Et({value:[new Zt({value:"1.2.840.113549.1.5.13"}),new Et({value:[new Et({value:[new Zt({value:"1.2.840.113549.1.5.12"}),f]}),new Et({value:[new Zt({value:"2.16.840.1.101.3.4.1.42"}),new Be({valueHex:c})]})]})]}),d=new Et({value:[g,new Be({valueHex:u})]}).toBER(),h=new Uint8Array(d,0,d.byteLength);return["-----BEGIN ENCRYPTED PRIVATE KEY-----",...q(h,"base64pad").split(/(.{64})/).filter(Boolean),"-----END ENCRYPTED PRIVATE KEY-----"].join(`
|
|
7
|
-
`)}async function y0(r,t){let e=Lt.get(),n;if(r.includes("-----BEGIN ENCRYPTED PRIVATE KEY-----")){let s=tt(r.replace("-----BEGIN ENCRYPTED PRIVATE KEY-----","").replace("-----END ENCRYPTED PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:o}=Sr(s),{iv:i,salt:a,iterations:c,keySize:l,cipherText:u}=m0(o),f=await di(yr,t,a,{c,dkLen:l}),g=await e.subtle.importKey("raw",f,"AES-CBC",!1,["decrypt"]),m=cn(await e.subtle.decrypt({name:"AES-CBC",iv:i},g,u)),{result:d}=Sr(m);n=_l(d)}else if(r.includes("-----BEGIN PRIVATE KEY-----")){let s=tt(r.replace("-----BEGIN PRIVATE KEY-----","").replace("-----END PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:o}=Sr(s);n=_l(o)}else throw new F("Could not parse private key from PEM data","ERR_INVALID_PARAMETERS");return xi(n)}function m0(r){let t=r.valueBlock.value[0];if(t.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.13")throw new F("Only pkcs5PBES2 encrypted private keys are supported","ERR_INVALID_PARAMS");let n=t.valueBlock.value[1].valueBlock.value[0];if(n.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.12")throw new F("Only pkcs5PBKDF2 key derivation functions are supported","ERR_INVALID_PARAMS");let o=n.valueBlock.value[1],i=cn(o.valueBlock.value[0].getValue()),a=bi,c=wi;if(o.valueBlock.value.length===3)a=Number(o.valueBlock.value[1].toBigInt()),c=Number(o.valueBlock.value[2].toBigInt());else if(o.valueBlock.value.length===2)throw new F("Could not derive key size and iterations from PEM file - please use @libp2p/rsa to re-import your key","ERR_INVALID_PARAMS");let l=t.valueBlock.value[1].valueBlock.value[1],u=l.valueBlock.value[0].toString();if(u!=="OBJECT IDENTIFIER : 1.2.840.113549.3.7"){if(u!=="OBJECT IDENTIFIER : 1.3.14.3.2.7"){if(u!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.2"){if(u!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.22"){if(u!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.42")throw new F("Only AES-CBC encryption schemes are supported","ERR_INVALID_PARAMS")}}}}let f=cn(l.valueBlock.value[1].getValue());return{cipherText:cn(r.valueBlock.value[1].getValue()),salt:i,iterations:a,keySize:c,iv:f}}function _l(r){return cn(r.valueBlock.value[2].getValue())}function cn(r){return new Uint8Array(r,0,r.byteLength)}async function Nl(r){let t=await Lt.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 Rl(t);return{privateKey:e[0],publicKey:e[1]}}async function Ei(r){let e=[await Lt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),await w0(r)],n=await Rl({privateKey:e[0],publicKey:e[1]});return{privateKey:n[0],publicKey:n[1]}}async function Tl(r,t){let e=await Lt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await Lt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},e,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function Ll(r,t,e){let n=await Lt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return Lt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,e instanceof Uint8Array?e:e.subarray())}async function Rl(r){if(r.privateKey==null||r.publicKey==null)throw new F("Private and public key are required","ERR_INVALID_PARAMETERS");return Promise.all([Lt.get().subtle.exportKey("jwk",r.privateKey),Lt.get().subtle.exportKey("jwk",r.publicKey)])}async function w0(r){return Lt.get().subtle.importKey("jwk",{kty:r.kty,n:r.n,e:r.e},{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])}function Ts(r){if(r.kty!=="RSA")throw new F("invalid key type","ERR_INVALID_KEY_TYPE");if(r.n==null)throw new F("invalid key modulus","ERR_INVALID_KEY_MODULUS");return tt(r.n,"base64url").length*8}var un=8192,ln=class{_key;constructor(t){this._key=t}verify(t,e){return Ll(this._key,e,t)}marshal(){return Ke.jwkToPkix(this._key)}get bytes(){return ne.encode({Type:ot.RSA,Data:this.marshal()}).subarray()}equals(t){return lt(this.bytes,t.bytes)}hash(){let t=At.digest(this.bytes);return Dt(t)?t.then(({bytes:e})=>e):t.bytes}},kr=class{_key;_publicKey;constructor(t,e){this._key=t,this._publicKey=e}genSecret(){return rr(16)}sign(t){return Tl(this._key,t)}get public(){if(this._publicKey==null)throw new F("public key not provided","ERR_PUBKEY_NOT_PROVIDED");return new ln(this._publicKey)}marshal(){return Ke.jwkToPkcs1(this._key)}get bytes(){return se.encode({Type:ot.RSA,Data:this.marshal()}).subarray()}equals(t){return lt(this.bytes,t.bytes)}hash(){let t=At.digest(this.bytes);return Dt(t)?t.then(({bytes:e})=>e):t.bytes}async id(){let t=await this.public.hash();return q(t,"base58btc")}async export(t,e="pkcs-8"){if(e==="pkcs-8")return Ke.exportToPem(this,t);if(e==="libp2p-key")return br(this.bytes,t);throw new F(`export format '${e}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};async function xi(r){let t=Ke.pkcs1ToJwk(r);if(Ts(t)>un)throw new F("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await Ei(t);return new kr(e.privateKey,e.publicKey)}function x0(r){let t=Ke.pkixToJwk(r);if(Ts(t)>un)throw new F("key size is too large","ERR_KEY_SIZE_TOO_LARGE");return new ln(t)}async function E0(r){if(Ts(r)>un)throw new F("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await Ei(r);return new kr(t.privateKey,t.publicKey)}async function v0(r){if(r>un)throw new F("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await Nl(r);return new kr(t.privateKey,t.publicKey)}var Ii={};gt(Ii,{Secp256k1PrivateKey:()=>hn,Secp256k1PublicKey:()=>fn,generateKeyPair:()=>V0,unmarshalSecp256k1PrivateKey:()=>P0,unmarshalSecp256k1PublicKey:()=>D0});var B0=(r,t,e)=>r&t^~r&e,A0=(r,t,e)=>r&t^r&e^t&e,S0=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Fe=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),$e=new Uint32Array(64),Bi=class extends gr{constructor(){super(64,32,8,!1),this.A=Fe[0]|0,this.B=Fe[1]|0,this.C=Fe[2]|0,this.D=Fe[3]|0,this.E=Fe[4]|0,this.F=Fe[5]|0,this.G=Fe[6]|0,this.H=Fe[7]|0}get(){let{A:t,B:e,C:n,D:s,E:o,F:i,G:a,H:c}=this;return[t,e,n,s,o,i,a,c]}set(t,e,n,s,o,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let f=0;f<16;f++,e+=4)$e[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let g=$e[f-15],m=$e[f-2],d=$t(g,7)^$t(g,18)^g>>>3,h=$t(m,17)^$t(m,19)^m>>>10;$e[f]=h+$e[f-7]+d+$e[f-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:l,H:u}=this;for(let f=0;f<64;f++){let g=$t(a,6)^$t(a,11)^$t(a,25),m=u+g+B0(a,c,l)+S0[f]+$e[f]|0,h=($t(n,2)^$t(n,13)^$t(n,22))+A0(n,s,o)|0;u=l,l=c,c=a,a=i+m|0,i=o,o=s,s=n,n=m+h|0}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,l=l+this.G|0,u=u+this.H|0,this.set(n,s,o,i,a,c,l,u)}roundClean(){$e.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Ir=In(()=>new Bi);function k0(r){let t=Gr(r);Vt(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("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("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:I0,hexToBytes:_0}=Tn,sr={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(r){let{Err:t}=sr;if(r.length<2||r[0]!==2)throw new t("Invalid signature integer tag");let e=r[1],n=r.subarray(2,e+2);if(!e||n.length!==e)throw new t("Invalid signature integer: wrong length");if(n[0]&128)throw new t("Invalid signature integer: negative");if(n[0]===0&&!(n[1]&128))throw new t("Invalid signature integer: unnecessary leading zero");return{d:I0(n),l:r.subarray(e+2)}},toSig(r){let{Err:t}=sr,e=typeof r=="string"?_0(r):r;if(!Gt(e))throw new Error("ui8a expected");let n=e.length;if(n<2||e[0]!=48)throw new t("Invalid signature tag");if(e[1]!==n-2)throw new t("Invalid signature: incorrect length");let{d:s,l:o}=sr._parseInt(e.subarray(2)),{d:i,l:a}=sr._parseInt(o);if(a.length)throw new t("Invalid signature: left bytes after parsing");return{r:s,s:i}},hexFromSig(r){let t=l=>Number.parseInt(l[0],16)&8?"00"+l:l,e=l=>{let u=l.toString(16);return u.length&1?`0${u}`:u},n=t(e(r.s)),s=t(e(r.r)),o=n.length/2,i=s.length/2,a=e(o),c=e(i);return`30${e(i+o+4)}02${c}${s}02${a}${n}`}},Ie=BigInt(0),Ht=BigInt(1),gw=BigInt(2),Cl=BigInt(3),yw=BigInt(4);function N0(r){let t=k0(r),{Fp:e}=t,n=t.toBytes||((d,h,p)=>{let b=h.toAffine();return we(Uint8Array.from([4]),e.toBytes(b.x),e.toBytes(b.y))}),s=t.fromBytes||(d=>{let h=d.subarray(1),p=e.fromBytes(h.subarray(0,e.BYTES)),b=e.fromBytes(h.subarray(e.BYTES,2*e.BYTES));return{x:p,y:b}});function o(d){let{a:h,b:p}=t,b=e.sqr(d),v=e.mul(b,d);return e.add(e.add(v,e.mul(d,h)),p)}if(!e.eql(e.sqr(t.Gy),o(t.Gx)))throw new Error("bad generator point: equation left != right");function i(d){return typeof d=="bigint"&&Ie<d&&d<t.n}function a(d){if(!i(d))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(d){let{allowedPrivateKeyLengths:h,nByteLength:p,wrapPrivateKey:b,n:v}=t;if(h&&typeof d!="bigint"){if(Gt(d)&&(d=ge(d)),typeof d!="string"||!h.includes(d.length))throw new Error("Invalid key");d=d.padStart(p*2,"0")}let w;try{w=typeof d=="bigint"?d:ye(rt("private key",d,p))}catch{throw new Error(`private key must be ${p} bytes, hex or bigint, not ${typeof d}`)}return b&&(w=Z(w,v)),a(w),w}let l=new Map;function u(d){if(!(d instanceof f))throw new Error("ProjectivePoint expected")}class f{constructor(h,p,b){if(this.px=h,this.py=p,this.pz=b,h==null||!e.isValid(h))throw new Error("x required");if(p==null||!e.isValid(p))throw new Error("y required");if(b==null||!e.isValid(b))throw new Error("z required")}static fromAffine(h){let{x:p,y:b}=h||{};if(!h||!e.isValid(p)||!e.isValid(b))throw new Error("invalid affine point");if(h instanceof f)throw new Error("projective point not allowed");let v=w=>e.eql(w,e.ZERO);return v(p)&&v(b)?f.ZERO:new f(p,b,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let p=e.invertBatch(h.map(b=>b.pz));return h.map((b,v)=>b.toAffine(p[v])).map(f.fromAffine)}static fromHex(h){let p=f.fromAffine(s(rt("pointHex",h)));return p.assertValidity(),p}static fromPrivateKey(h){return f.BASE.multiply(c(h))}_setWindowSize(h){this._WINDOW_SIZE=h,l.delete(this)}assertValidity(){if(this.is0()){if(t.allowInfinityPoint&&!e.is0(this.py))return;throw new Error("bad point: ZERO")}let{x:h,y:p}=this.toAffine();if(!e.isValid(h)||!e.isValid(p))throw new Error("bad point: x or y not FE");let b=e.sqr(p),v=o(h);if(!e.eql(b,v))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:h}=this.toAffine();if(e.isOdd)return!e.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){u(h);let{px:p,py:b,pz:v}=this,{px:w,py:A,pz:B}=h,S=e.eql(e.mul(p,B),e.mul(w,v)),N=e.eql(e.mul(b,B),e.mul(A,v));return S&&N}negate(){return new f(this.px,e.neg(this.py),this.pz)}double(){let{a:h,b:p}=t,b=e.mul(p,Cl),{px:v,py:w,pz:A}=this,B=e.ZERO,S=e.ZERO,N=e.ZERO,_=e.mul(v,v),V=e.mul(w,w),P=e.mul(A,A),L=e.mul(v,w);return L=e.add(L,L),N=e.mul(v,A),N=e.add(N,N),B=e.mul(h,N),S=e.mul(b,P),S=e.add(B,S),B=e.sub(V,S),S=e.add(V,S),S=e.mul(B,S),B=e.mul(L,B),N=e.mul(b,N),P=e.mul(h,P),L=e.sub(_,P),L=e.mul(h,L),L=e.add(L,N),N=e.add(_,_),_=e.add(N,_),_=e.add(_,P),_=e.mul(_,L),S=e.add(S,_),P=e.mul(w,A),P=e.add(P,P),_=e.mul(P,L),B=e.sub(B,_),N=e.mul(P,V),N=e.add(N,N),N=e.add(N,N),new f(B,S,N)}add(h){u(h);let{px:p,py:b,pz:v}=this,{px:w,py:A,pz:B}=h,S=e.ZERO,N=e.ZERO,_=e.ZERO,V=t.a,P=e.mul(t.b,Cl),L=e.mul(p,w),H=e.mul(b,A),O=e.mul(v,B),z=e.add(p,b),x=e.add(w,A);z=e.mul(z,x),x=e.add(L,H),z=e.sub(z,x),x=e.add(p,v);let I=e.add(w,B);return x=e.mul(x,I),I=e.add(L,O),x=e.sub(x,I),I=e.add(b,v),S=e.add(A,B),I=e.mul(I,S),S=e.add(H,O),I=e.sub(I,S),_=e.mul(V,x),S=e.mul(P,O),_=e.add(S,_),S=e.sub(H,_),_=e.add(H,_),N=e.mul(S,_),H=e.add(L,L),H=e.add(H,L),O=e.mul(V,O),x=e.mul(P,x),H=e.add(H,O),O=e.sub(L,O),O=e.mul(V,O),x=e.add(x,O),L=e.mul(H,x),N=e.add(N,L),L=e.mul(I,x),S=e.mul(z,S),S=e.sub(S,L),L=e.mul(z,H),_=e.mul(I,_),_=e.add(_,L),new f(S,N,_)}subtract(h){return this.add(h.negate())}is0(){return this.equals(f.ZERO)}wNAF(h){return m.wNAFCached(this,l,h,p=>{let b=e.invertBatch(p.map(v=>v.pz));return p.map((v,w)=>v.toAffine(b[w])).map(f.fromAffine)})}multiplyUnsafe(h){let p=f.ZERO;if(h===Ie)return p;if(a(h),h===Ht)return this;let{endo:b}=t;if(!b)return m.unsafeLadder(this,h);let{k1neg:v,k1:w,k2neg:A,k2:B}=b.splitScalar(h),S=p,N=p,_=this;for(;w>Ie||B>Ie;)w&Ht&&(S=S.add(_)),B&Ht&&(N=N.add(_)),_=_.double(),w>>=Ht,B>>=Ht;return v&&(S=S.negate()),A&&(N=N.negate()),N=new f(e.mul(N.px,b.beta),N.py,N.pz),S.add(N)}multiply(h){a(h);let p=h,b,v,{endo:w}=t;if(w){let{k1neg:A,k1:B,k2neg:S,k2:N}=w.splitScalar(p),{p:_,f:V}=this.wNAF(B),{p:P,f:L}=this.wNAF(N);_=m.constTimeNegate(A,_),P=m.constTimeNegate(S,P),P=new f(e.mul(P.px,w.beta),P.py,P.pz),b=_.add(P),v=V.add(L)}else{let{p:A,f:B}=this.wNAF(p);b=A,v=B}return f.normalizeZ([b,v])[0]}multiplyAndAddUnsafe(h,p,b){let v=f.BASE,w=(B,S)=>S===Ie||S===Ht||!B.equals(v)?B.multiplyUnsafe(S):B.multiply(S),A=w(this,p).add(w(h,b));return A.is0()?void 0:A}toAffine(h){let{px:p,py:b,pz:v}=this,w=this.is0();h==null&&(h=w?e.ONE:e.inv(v));let A=e.mul(p,h),B=e.mul(b,h),S=e.mul(v,h);if(w)return{x:e.ZERO,y:e.ZERO};if(!e.eql(S,e.ONE))throw new Error("invZ was invalid");return{x:A,y:B}}isTorsionFree(){let{h,isTorsionFree:p}=t;if(h===Ht)return!0;if(p)return p(f,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:p}=t;return h===Ht?this:p?p(f,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return this.assertValidity(),n(f,this,h)}toHex(h=!0){return ge(this.toRawBytes(h))}}f.BASE=new f(t.Gx,t.Gy,e.ONE),f.ZERO=new f(e.ZERO,e.ONE,e.ZERO);let g=t.nBitLength,m=Cn(f,t.endo?Math.ceil(g/2):g);return{CURVE:t,ProjectivePoint:f,normPrivateKeyToScalar:c,weierstrassEquation:o,isWithinCurveOrder:i}}function T0(r){let t=Gr(r);return Vt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Ul(r){let t=T0(r),{Fp:e,n}=t,s=e.BYTES+1,o=2*e.BYTES+1;function i(x){return Ie<x&&x<e.ORDER}function a(x){return Z(x,n)}function c(x){return Ln(x,n)}let{ProjectivePoint:l,normPrivateKeyToScalar:u,weierstrassEquation:f,isWithinCurveOrder:g}=N0({...t,toBytes(x,I,C){let E=I.toAffine(),y=e.toBytes(E.x),k=we;return C?k(Uint8Array.from([I.hasEvenY()?2:3]),y):k(Uint8Array.from([4]),y,e.toBytes(E.y))},fromBytes(x){let I=x.length,C=x[0],E=x.subarray(1);if(I===s&&(C===2||C===3)){let y=ye(E);if(!i(y))throw new Error("Point is not on curve");let k=f(y),T=e.sqrt(k),R=(T&Ht)===Ht;return(C&1)===1!==R&&(T=e.neg(T)),{x:y,y:T}}else if(I===o&&C===4){let y=e.fromBytes(E.subarray(0,e.BYTES)),k=e.fromBytes(E.subarray(e.BYTES,2*e.BYTES));return{x:y,y:k}}else throw new Error(`Point of length ${I} was invalid. Expected ${s} compressed bytes or ${o} uncompressed bytes`)}}),m=x=>ge(Pe(x,t.nByteLength));function d(x){let I=n>>Ht;return x>I}function h(x){return d(x)?a(-x):x}let p=(x,I,C)=>ye(x.slice(I,C));class b{constructor(I,C,E){this.r=I,this.s=C,this.recovery=E,this.assertValidity()}static fromCompact(I){let C=t.nByteLength;return I=rt("compactSignature",I,C*2),new b(p(I,0,C),p(I,C,2*C))}static fromDER(I){let{r:C,s:E}=sr.toSig(rt("DER",I));return new b(C,E)}assertValidity(){if(!g(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!g(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(I){return new b(this.r,this.s,I)}recoverPublicKey(I){let{r:C,s:E,recovery:y}=this,k=N(rt("msgHash",I));if(y==null||![0,1,2,3].includes(y))throw new Error("recovery id invalid");let T=y===2||y===3?C+t.n:C;if(T>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let R=y&1?"03":"02",M=l.fromHex(R+m(T)),K=c(T),W=a(-k*K),$=a(E*K),G=l.BASE.multiplyAndAddUnsafe(M,W,$);if(!G)throw new Error("point at infinify");return G.assertValidity(),G}hasHighS(){return d(this.s)}normalizeS(){return this.hasHighS()?new b(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return We(this.toDERHex())}toDERHex(){return sr.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return We(this.toCompactHex())}toCompactHex(){return m(this.r)+m(this.s)}}let v={isValidPrivateKey(x){try{return u(x),!0}catch{return!1}},normPrivateKeyToScalar:u,randomPrivateKey:()=>{let x=Ko(t.n);return wc(t.randomBytes(x),t.n)},precompute(x=8,I=l.BASE){return I._setWindowSize(x),I.multiply(BigInt(3)),I}};function w(x,I=!0){return l.fromPrivateKey(x).toRawBytes(I)}function A(x){let I=Gt(x),C=typeof x=="string",E=(I||C)&&x.length;return I?E===s||E===o:C?E===2*s||E===2*o:x instanceof l}function B(x,I,C=!0){if(A(x))throw new Error("first arg must be private key");if(!A(I))throw new Error("second arg must be public key");return l.fromHex(I).multiply(u(x)).toRawBytes(C)}let S=t.bits2int||function(x){let I=ye(x),C=x.length*8-t.nBitLength;return C>0?I>>BigInt(C):I},N=t.bits2int_modN||function(x){return a(S(x))},_=qr(t.nBitLength);function V(x){if(typeof x!="bigint")throw new Error("bigint expected");if(!(Ie<=x&&x<_))throw new Error(`bigint expected < 2^${t.nBitLength}`);return Pe(x,t.nByteLength)}function P(x,I,C=L){if(["recovered","canonical"].some(Q=>Q in C))throw new Error("sign() legacy options not supported");let{hash:E,randomBytes:y}=t,{lowS:k,prehash:T,extraEntropy:R}=C;k==null&&(k=!0),x=rt("msgHash",x),T&&(x=rt("prehashed msgHash",E(x)));let M=N(x),K=u(I),W=[V(K),V(M)];if(R!=null){let Q=R===!0?y(e.BYTES):R;W.push(rt("extraEntropy",Q))}let $=we(...W),G=M;function et(Q){let vt=S(Q);if(!g(vt))return;let Bt=c(vt),pt=l.BASE.multiply(vt).toAffine(),It=a(pt.x);if(It===Ie)return;let ue=a(Bt*a(G+It*K));if(ue===Ie)return;let qe=(pt.x===It?0:2)|Number(pt.y&Ht),Mr=ue;return k&&d(ue)&&(Mr=h(ue),qe^=1),new b(It,Mr,qe)}return{seed:$,k2sig:et}}let L={lowS:t.lowS,prehash:!1},H={lowS:t.lowS,prehash:!1};function O(x,I,C=L){let{seed:E,k2sig:y}=P(x,I,C),k=t;return Do(k.hash.outputLen,k.nByteLength,k.hmac)(E,y)}l.BASE._setWindowSize(8);function z(x,I,C,E=H){let y=x;if(I=rt("msgHash",I),C=rt("publicKey",C),"strict"in E)throw new Error("options.strict was renamed to lowS");let{lowS:k,prehash:T}=E,R,M;try{if(typeof y=="string"||Gt(y))try{R=b.fromDER(y)}catch(pt){if(!(pt instanceof sr.Err))throw pt;R=b.fromCompact(y)}else if(typeof y=="object"&&typeof y.r=="bigint"&&typeof y.s=="bigint"){let{r:pt,s:It}=y;R=new b(pt,It)}else throw new Error("PARSE");M=l.fromHex(C)}catch(pt){if(pt.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(k&&R.hasHighS())return!1;T&&(I=t.hash(I));let{r:K,s:W}=R,$=N(I),G=c(W),et=a($*G),Q=a(K*G),vt=l.BASE.multiplyAndAddUnsafe(M,et,Q)?.toAffine();return vt?a(vt.x)===K:!1}return{CURVE:t,getPublicKey:w,getSharedSecret:B,sign:O,verify:z,ProjectivePoint:l,Signature:b,utils:v}}function L0(r){return{hash:r,hmac:(t,...e)=>Ve(r,t,kn(...e)),randomBytes:ze}}function Pl(r,t){let e=n=>Ul({...r,...L0(n)});return Object.freeze({...e(t),create:e})}var Ol=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Dl=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),R0=BigInt(1),Ai=BigInt(2),Vl=(r,t)=>(r+t/Ai)/t;function C0(r){let t=Ol,e=BigInt(3),n=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),l=r*r*r%t,u=l*l*r%t,f=nt(u,e,t)*u%t,g=nt(f,e,t)*u%t,m=nt(g,Ai,t)*l%t,d=nt(m,s,t)*m%t,h=nt(d,o,t)*d%t,p=nt(h,a,t)*h%t,b=nt(p,c,t)*p%t,v=nt(b,a,t)*h%t,w=nt(v,e,t)*u%t,A=nt(w,i,t)*d%t,B=nt(A,n,t)*l%t,S=nt(B,Ai,t);if(!Si.eql(Si.sqr(S),r))throw new Error("Cannot find square root");return S}var Si=Rn(Ol,void 0,void 0,{sqrt:C0}),Jt=Pl({a:BigInt(0),b:BigInt(7),Fp:Si,n:Dl,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Dl,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-R0*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=e,i=BigInt("0x100000000000000000000000000000000"),a=Vl(o*r,t),c=Vl(-n*r,t),l=Z(r-a*e-c*s,t),u=Z(-a*n-c*o,t),f=l>i,g=u>i;if(f&&(l=t-l),g&&(u=t-u),l>i||u>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:l,k2neg:g,k2:u}}}},Ir),Sw=BigInt(0);var kw=Jt.ProjectivePoint;function Hl(){return Jt.utils.randomPrivateKey()}function Ml(r,t){let e=At.digest(t instanceof Uint8Array?t:t.subarray());if(Dt(e))return e.then(({digest:n})=>Jt.sign(n,r).toDERRawBytes()).catch(n=>{throw new F(String(n),"ERR_INVALID_INPUT")});try{return Jt.sign(e.digest,r).toDERRawBytes()}catch(n){throw new F(String(n),"ERR_INVALID_INPUT")}}function Kl(r,t,e){let n=At.digest(e instanceof Uint8Array?e:e.subarray());if(Dt(n))return n.then(({digest:s})=>Jt.verify(t,s,r)).catch(s=>{throw new F(String(s),"ERR_INVALID_INPUT")});try{return Jt.verify(t,n.digest,r)}catch(s){throw new F(String(s),"ERR_INVALID_INPUT")}}function Fl(r){return Jt.ProjectivePoint.fromHex(r).toRawBytes(!0)}function $l(r){try{Jt.getPublicKey(r,!0)}catch(t){throw new F(String(t),"ERR_INVALID_PRIVATE_KEY")}}function ki(r){try{Jt.ProjectivePoint.fromHex(r)}catch(t){throw new F(String(t),"ERR_INVALID_PUBLIC_KEY")}}function ql(r){try{return Jt.getPublicKey(r,!0)}catch(t){throw new F(String(t),"ERR_INVALID_PRIVATE_KEY")}}var fn=class{_key;constructor(t){ki(t),this._key=t}verify(t,e){return Kl(this._key,e,t)}marshal(){return Fl(this._key)}get bytes(){return ne.encode({Type:ot.Secp256k1,Data:this.marshal()}).subarray()}equals(t){return lt(this.bytes,t.bytes)}async hash(){let t=At.digest(this.bytes),e;return Dt(t)?{bytes:e}=await t:e=t.bytes,e}},hn=class{_key;_publicKey;constructor(t,e){this._key=t,this._publicKey=e??ql(t),$l(this._key),ki(this._publicKey)}sign(t){return Ml(this._key,t)}get public(){return new fn(this._publicKey)}marshal(){return this._key}get bytes(){return se.encode({Type:ot.Secp256k1,Data:this.marshal()}).subarray()}equals(t){return lt(this.bytes,t.bytes)}hash(){let t=At.digest(this.bytes);return Dt(t)?t.then(({bytes:e})=>e):t.bytes}async id(){let t=await this.public.hash();return q(t,"base58btc")}async export(t,e="libp2p-key"){if(e==="libp2p-key")return br(this.bytes,t);throw new F(`export format '${e}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function P0(r){return new hn(r)}function D0(r){return new fn(r)}async function V0(){let r=Hl();return new hn(r)}var or={rsa:vi,ed25519:hi,secp256k1:Ii};function Gl(r){let t=Object.keys(or).join(" / ");return new F(`invalid or unsupported key type ${r}. Must be ${t}`,"ERR_UNSUPPORTED_KEY_TYPE")}function jl(r){let t=ne.decode(r),e=t.Data??new Uint8Array;switch(t.Type){case ot.RSA:return or.rsa.unmarshalRsaPublicKey(e);case ot.Ed25519:return or.ed25519.unmarshalEd25519PublicKey(e);case ot.Secp256k1:return or.secp256k1.unmarshalSecp256k1PublicKey(e);default:throw Gl(t.Type??"unknown")}}async function _i(r){let t=se.decode(r),e=t.Data??new Uint8Array;switch(t.Type){case ot.RSA:return or.rsa.unmarshalRsaPrivateKey(e);case ot.Ed25519:return or.ed25519.unmarshalEd25519PrivateKey(e);case ot.Secp256k1:return or.secp256k1.unmarshalSecp256k1PrivateKey(e);default:throw Gl(t.Type??"RSA")}}var O0=Symbol.for("nodejs.util.inspect.custom"),zl=Object.values(ee).map(r=>r.decoder).reduce((r,t)=>r.or(t),ee.identity.decoder),Wl=114,Ni=36,Ti=37,dn=class{type;multihash;privateKey;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,this.privateKey=t.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Da]=!0;toString(){return this.string==null&&(this.string=ct.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return Ft.createV1(Wl,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return lt(this.multihash.bytes,t);if(typeof t=="string")return Li(t).equals(this);if(t?.multihash?.bytes!=null)return lt(this.multihash.bytes,t.multihash.bytes);throw new Error("not valid Id")}[O0](){return`PeerId(${this.toString()})`}},_r=class extends dn{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Nr=class extends dn{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.multihash.digest}},Tr=class extends dn{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.multihash.digest}};function Li(r,t){if(t=t??zl,r.charAt(0)==="1"||r.charAt(0)==="Q"){let e=Te(ct.decode(`z${r}`));return r.startsWith("12D")?new Nr({multihash:e}):r.startsWith("16U")?new Tr({multihash:e}):new _r({multihash:e})}return H0(zl.decode(r))}function H0(r){try{let t=Te(r);if(t.code===Le.code){if(t.digest.length===Ni)return new Nr({multihash:t});if(t.digest.length===Ti)return new Tr({multihash:t})}if(t.code===At.code)return new _r({multihash:t})}catch{return M0(Ft.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function M0(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==Wl)throw new Error("Supplied PeerID CID is invalid");let t=r.multihash;if(t.code===At.code)return new _r({multihash:r.multihash});if(t.code===Le.code){if(t.digest.length===Ni)return new Nr({multihash:r.multihash});if(t.digest.length===Ti)return new Tr({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function Ri(r,t){return r.length===Ni?new Nr({multihash:Kt(Le.code,r),privateKey:t}):r.length===Ti?new Tr({multihash:Kt(Le.code,r),privateKey:t}):new _r({multihash:await At.digest(r),publicKey:r,privateKey:t})}var Zl=Symbol.for("@achingbrain/uint8arraylist");function Yl(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 Ls(r){return!!r?.[Zl]}var at=class r{bufs;length;[Zl]=!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(Ls(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(Ls(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=Yl(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Yl(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(Ls(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 xt(n,s)}subarray(t,e){let{bufs:n,length:s}=this._subList(t,e);return n.length===1?n[0]:xt(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],a=s,c=a+i.byteLength;if(s=c,t>=c)continue;let l=t>=a&&t<c,u=e>a&&e<=c;if(l&&u){if(t===a&&e===c){n.push(i);break}let f=t-a;n.push(i.subarray(f,f+(e-t)));break}if(l){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(u){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Ls(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 a=i,c=this.byteLength-n.byteLength,l=n.byteLength-1,u;for(let f=e;f<=c;f+=u){u=0;for(let g=l;g>=0;g--){let m=this.get(f+g);if(n[g]!==m){u=Math.max(1,g-a[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=mt(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=yt(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=yt(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=yt(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=mt(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=yt(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=yt(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=yt(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=yt(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=yt(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(!lt(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}};function Rs(r){return r[Symbol.asyncIterator]!=null}var Cs=r=>{let t=ht(r),e=mt(t);return re(r,e),Cs.bytes=t,e};Cs.bytes=0;function Xl(r,t){t=t??{};let e=t.lengthEncoder??Cs;function*n(s){let o=e(s.byteLength);o instanceof Uint8Array?yield o:yield*o,s instanceof Uint8Array?yield s:yield*s}return Rs(r)?async function*(){for await(let s of r)yield*n(s)}():function*(){for(let s of r)yield*n(s)}()}Xl.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??Cs;return new at(e(r.byteLength),r)};var Lr=Pa(tu(),1);var F0=8,$0=1024*1024*4,ir;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(ir||(ir={}));var Ci=r=>{let t=Wt(r);return Ci.bytes=ht(t),t};Ci.bytes=0;function pn(r,t){let e=new at,n=ir.LENGTH,s=-1,o=t?.lengthDecoder??Ci,i=t?.maxLengthLength??F0,a=t?.maxDataLength??$0;function*c(){for(;e.byteLength>0;){if(n===ir.LENGTH)try{if(s=o(e),s<0)throw(0,Lr.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(s>a)throw(0,Lr.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let l=o.bytes;e.consume(l),t?.onLength!=null&&t.onLength(s),n=ir.DATA}catch(l){if(l instanceof RangeError){if(e.byteLength>i)throw(0,Lr.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw l}if(n===ir.DATA){if(e.byteLength<s)break;let l=e.sublist(0,s);e.consume(s),t?.onData!=null&&t.onData(l),yield l,n=ir.LENGTH}}}return Rs(r)?async function*(){for await(let l of r)e.append(l),yield*c();if(e.byteLength>0)throw(0,Lr.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}():function*(){for(let l of r)e.append(l),yield*c();if(e.byteLength>0)throw(0,Lr.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}pn.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:o,value:i}=await r.next(e);if(o===!0)return;i!=null&&(yield i)}catch(o){if(o.code==="ERR_UNDER_READ")return{done:!0,value:null};throw o}finally{e=1}}();return pn(n,{...t??{},onLength:o=>{e=o}})};function Qt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Us=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=e??"ABORT_ERR"}};async function eu(r,t,e){if(t==null)return r;if(t.aborted)return Promise.reject(new Us(e?.errorMessage,e?.errorCode));let n,s=new Us(e?.errorMessage,e?.errorCode);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 Ui=class{needNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.needNext=Qt(),this.haveNext=Qt()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("Have next but next was undefined");let t=this.nextResult;return this.nextResult=void 0,this.needNext.resolve(),this.needNext=Qt(),t}async throw(t){return this.ended=!0,t!=null&&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");this.nextResult!=null&&await this.needNext.promise,t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Qt(),await eu(this.needNext.promise,e?.signal,e)}};function ru(){return new Ui}var Ps=class extends Error{code;constructor(t,e){super(t),this.code=e}},Pi=class extends Ps{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted"}};function nu(r,t){let e=ru();r.sink(e).catch(async i=>{await e.end(i)}),r.sink=async i=>{for await(let a of i)await e.push(a);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 at;return{read:async(i,a)=>{a?.signal?.throwIfAborted();let c,l=new Promise((u,f)=>{c=()=>{f(new Pi("Read aborted"))},a?.signal?.addEventListener("abort",c)});try{if(i==null){let{done:f,value:g}=await Promise.race([n.next(),l]);return f===!0?new at:g}for(;s.byteLength<i;){let{value:f,done:g}=await Promise.race([n.next(),l]);if(g===!0)throw new Ps("unexpected end of input","ERR_UNEXPECTED_EOF");s.append(f)}let u=s.sublist(0,i);return s.consume(i),u}finally{c!=null&&a?.signal?.removeEventListener("abort",c)}},write:async(i,a)=>{a?.signal?.throwIfAborted(),i instanceof Uint8Array?await e.push(i,a):await e.push(i.subarray(),a)},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 Ds=class extends Error{code;constructor(t,e){super(t),this.code=e}};function Di(r,t={}){let e=nu(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=ht(t.maxDataLength));let n=t?.lengthDecoder??Wt,s=t?.lengthEncoder??re;return{read:async i=>{let a=-1,c=new at;for(;;){c.append(await e.read(1,i));try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new Ds("message length length too long","ERR_MSG_LENGTH_TOO_LONG");if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new Ds("message length too long","ERR_MSG_DATA_TOO_LONG");return e.read(a,i)},write:async(i,a)=>{await e.write(new at(s(i.byteLength),i),a)},writeV:async(i,a)=>{let c=new at(...i.flatMap(l=>[s(l.byteLength),l]));await e.write(c,a)},unwrap:()=>e.unwrap()}}function Vi(){let r=Qt(),t=!1;return{sink:async e=>{if(t)throw new Error("already piped");t=!0,r.resolve(e)},source:async function*(){yield*await r.promise}()}}function su(){let r=Vi(),t=Vi();return[{source:r.source,sink:t.sink},{source:t.source,sink:r.sink}]}var Vs=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||t-1&t)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},Rr=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Vs(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new Vs(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var Oi=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function Os(r={}){return q0(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function q0(r,t){t=t??{};let e=t.onEnd,n=new Rr,s,o,i,a=Qt(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((p,b)=>{o=v=>{o=null,n.push(v);try{p(r(n))}catch(w){b(w)}return s}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Qt()})}},l=p=>o!=null?o(p):(n.push(p),s),u=p=>(n=new Rr,o!=null?o({error:p}):(n.push({error:p}),s)),f=p=>{if(i)return s;if(t?.objectMode!==!0&&p?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:p})},g=p=>i?s:(i=!0,p!=null?u(p):l({done:!0})),m=()=>(n=new Rr,g(),{done:!0}),d=p=>(g(p),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:c,return:m,throw:d,push:f,end:g,get readableLength(){return n.size},onEmpty:async p=>{let b=p?.signal;if(b?.throwIfAborted(),n.isEmpty())return;let v,w;b!=null&&(v=new Promise((A,B)=>{w=()=>{B(new Oi)},b.addEventListener("abort",w)}));try{await Promise.race([a.promise,v])}finally{w!=null&&b!=null&&b?.removeEventListener("abort",w)}}},e==null)return s;let h=s;return s={[Symbol.asyncIterator](){return this},next(){return h.next()},throw(p){return h.throw(p),e!=null&&(e(p),e=void 0),{done:!0}},return(){return h.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(p){return h.end(p),e!=null&&(e(p),e=void 0),s},get readableLength(){return h.readableLength},onEmpty:p=>h.onEmpty(p)},s}function G0(r){return r[Symbol.asyncIterator]!=null}function j0(...r){let t=[];for(let e of r)G0(e)||t.push(e);return t.length===r.length?function*(){for(let e of t)yield*e}():async function*(){let e=Os({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let s of n)e.push(s)})),e.end()}catch(n){e.end(n)}}),yield*e}()}var ou=j0;function iu(r,...t){if(r==null)throw new Error("Empty pipeline");if(Hi(r)){let n=r;r=()=>n.source}else if(cu(r)||au(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&Hi(e[e.length-1])&&(e[e.length-1]=e[e.length-1].sink),e.length>2)for(let n=1;n<e.length-1;n++)Hi(e[n])&&(e[n]=W0(e[n]));return z0(...e)}var z0=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},au=r=>r?.[Symbol.asyncIterator]!=null,cu=r=>r?.[Symbol.iterator]!=null,Hi=r=>r==null?!1:r.sink!=null&&r.source!=null,W0=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=Os({objectMode:!0});e.then(()=>{n.end()},i=>{n.end(i)});let s,o=r.source;if(au(o))s=async function*(){yield*o,n.end()};else if(cu(o))s=function*(){yield*o,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return ou(n,s())}return r.source};var Cr=!!globalThis.process?.env?.DUMP_SESSION_KEYS;var _e=r=>new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4));function lu(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var uu=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Y0=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Y0)throw new Error("Non little-endian hardware is not supported");function Hs(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Ms(r){if(typeof r=="string")r=Hs(r);else if(lu(r))r=r.slice();else throw new Error(`expected Uint8Array, got ${typeof r}`);return r}var Z0=r=>Object.prototype.toString.call(r)==="[object Object]"&&r.constructor===Object;function fu(r,t){if(t!==void 0&&(typeof t!="object"||!Z0(t)))throw new Error("options must be object or undefined");return Object.assign(r,t)}function ar(r,t){if(!lu(r))throw new Error("Uint8Array expected");if(typeof t=="number"&&r.length!==t)throw new Error(`Uint8Array length ${t} expected`)}function hu(r,t){if(r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}var Mi=(r,t)=>(Object.assign(t,r),t);function Ki(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let s=BigInt(32),o=BigInt(4294967295),i=Number(e>>s&o),a=Number(e&o),c=n?4:0,l=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+l,a,n)}function Ks(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`wrong positive integer: ${r}`)}function Fi(r){if(typeof r!="boolean")throw new Error(`boolean expected, not ${r}`)}function X0(r){return r!=null&&typeof r=="object"&&(r instanceof Uint8Array||r.constructor.name==="Uint8Array")}function Ur(r,...t){if(!X0(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${r.length}`)}function $i(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function du(r,t){Ur(r);let e=t.outputLen;if(r.length<e)throw new Error(`digestInto() expects output buffer of length at least ${e}`)}var kt=(r,t)=>r[t++]&255|(r[t++]&255)<<8,qi=class{constructor(t){this.blockLen=16,this.outputLen=16,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.pos=0,this.finished=!1,t=Ms(t),ar(t,32);let e=kt(t,0),n=kt(t,2),s=kt(t,4),o=kt(t,6),i=kt(t,8),a=kt(t,10),c=kt(t,12),l=kt(t,14);this.r[0]=e&8191,this.r[1]=(e>>>13|n<<3)&8191,this.r[2]=(n>>>10|s<<6)&7939,this.r[3]=(s>>>7|o<<9)&8191,this.r[4]=(o>>>4|i<<12)&255,this.r[5]=i>>>1&8190,this.r[6]=(i>>>14|a<<2)&8191,this.r[7]=(a>>>11|c<<5)&8065,this.r[8]=(c>>>8|l<<8)&8191,this.r[9]=l>>>5&127;for(let u=0;u<8;u++)this.pad[u]=kt(t,16+2*u)}process(t,e,n=!1){let s=n?0:2048,{h:o,r:i}=this,a=i[0],c=i[1],l=i[2],u=i[3],f=i[4],g=i[5],m=i[6],d=i[7],h=i[8],p=i[9],b=kt(t,e+0),v=kt(t,e+2),w=kt(t,e+4),A=kt(t,e+6),B=kt(t,e+8),S=kt(t,e+10),N=kt(t,e+12),_=kt(t,e+14),V=o[0]+(b&8191),P=o[1]+((b>>>13|v<<3)&8191),L=o[2]+((v>>>10|w<<6)&8191),H=o[3]+((w>>>7|A<<9)&8191),O=o[4]+((A>>>4|B<<12)&8191),z=o[5]+(B>>>1&8191),x=o[6]+((B>>>14|S<<2)&8191),I=o[7]+((S>>>11|N<<5)&8191),C=o[8]+((N>>>8|_<<8)&8191),E=o[9]+(_>>>5|s),y=0,k=y+V*a+P*(5*p)+L*(5*h)+H*(5*d)+O*(5*m);y=k>>>13,k&=8191,k+=z*(5*g)+x*(5*f)+I*(5*u)+C*(5*l)+E*(5*c),y+=k>>>13,k&=8191;let T=y+V*c+P*a+L*(5*p)+H*(5*h)+O*(5*d);y=T>>>13,T&=8191,T+=z*(5*m)+x*(5*g)+I*(5*f)+C*(5*u)+E*(5*l),y+=T>>>13,T&=8191;let R=y+V*l+P*c+L*a+H*(5*p)+O*(5*h);y=R>>>13,R&=8191,R+=z*(5*d)+x*(5*m)+I*(5*g)+C*(5*f)+E*(5*u),y+=R>>>13,R&=8191;let M=y+V*u+P*l+L*c+H*a+O*(5*p);y=M>>>13,M&=8191,M+=z*(5*h)+x*(5*d)+I*(5*m)+C*(5*g)+E*(5*f),y+=M>>>13,M&=8191;let K=y+V*f+P*u+L*l+H*c+O*a;y=K>>>13,K&=8191,K+=z*(5*p)+x*(5*h)+I*(5*d)+C*(5*m)+E*(5*g),y+=K>>>13,K&=8191;let W=y+V*g+P*f+L*u+H*l+O*c;y=W>>>13,W&=8191,W+=z*a+x*(5*p)+I*(5*h)+C*(5*d)+E*(5*m),y+=W>>>13,W&=8191;let $=y+V*m+P*g+L*f+H*u+O*l;y=$>>>13,$&=8191,$+=z*c+x*a+I*(5*p)+C*(5*h)+E*(5*d),y+=$>>>13,$&=8191;let G=y+V*d+P*m+L*g+H*f+O*u;y=G>>>13,G&=8191,G+=z*l+x*c+I*a+C*(5*p)+E*(5*h),y+=G>>>13,G&=8191;let et=y+V*h+P*d+L*m+H*g+O*f;y=et>>>13,et&=8191,et+=z*u+x*l+I*c+C*a+E*(5*p),y+=et>>>13,et&=8191;let Q=y+V*p+P*h+L*d+H*m+O*g;y=Q>>>13,Q&=8191,Q+=z*f+x*u+I*l+C*c+E*a,y+=Q>>>13,Q&=8191,y=(y<<2)+y|0,y=y+k|0,k=y&8191,y=y>>>13,T+=y,o[0]=k,o[1]=T,o[2]=R,o[3]=M,o[4]=K,o[5]=W,o[6]=$,o[7]=G,o[8]=et,o[9]=Q}finalize(){let{h:t,pad:e}=this,n=new Uint16Array(10),s=t[1]>>>13;t[1]&=8191;for(let a=2;a<10;a++)t[a]+=s,s=t[a]>>>13,t[a]&=8191;t[0]+=s*5,s=t[0]>>>13,t[0]&=8191,t[1]+=s,s=t[1]>>>13,t[1]&=8191,t[2]+=s,n[0]=t[0]+5,s=n[0]>>>13,n[0]&=8191;for(let a=1;a<10;a++)n[a]=t[a]+s,s=n[a]>>>13,n[a]&=8191;n[9]-=8192;let o=(s^1)-1;for(let a=0;a<10;a++)n[a]&=o;o=~o;for(let a=0;a<10;a++)t[a]=t[a]&o|n[a];t[0]=(t[0]|t[1]<<13)&65535,t[1]=(t[1]>>>3|t[2]<<10)&65535,t[2]=(t[2]>>>6|t[3]<<7)&65535,t[3]=(t[3]>>>9|t[4]<<4)&65535,t[4]=(t[4]>>>12|t[5]<<1|t[6]<<14)&65535,t[5]=(t[6]>>>2|t[7]<<11)&65535,t[6]=(t[7]>>>5|t[8]<<8)&65535,t[7]=(t[8]>>>8|t[9]<<5)&65535;let i=t[0]+e[0];t[0]=i&65535;for(let a=1;a<8;a++)i=(t[a]+e[a]|0)+(i>>>16)|0,t[a]=i&65535}update(t){$i(this);let{buffer:e,blockLen:n}=this;t=Ms(t);let s=t.length;for(let o=0;o<s;){let i=Math.min(n-this.pos,s-o);if(i===n){for(;n<=s-o;o+=n)this.process(t,o);continue}e.set(t.subarray(o,o+i),this.pos),this.pos+=i,o+=i,this.pos===n&&(this.process(e,0,!1),this.pos=0)}return this}destroy(){this.h.fill(0),this.r.fill(0),this.buffer.fill(0),this.pad.fill(0)}digestInto(t){$i(this),du(t,this),this.finished=!0;let{buffer:e,h:n}=this,{pos:s}=this;if(s){for(e[s++]=1;s<16;s++)e[s]=0;this.process(e,0,!0)}this.finalize();let o=0;for(let i=0;i<8;i++)t[o++]=n[i]>>>0,t[o++]=n[i]>>>8;return t}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}};function J0(r){let t=(n,s)=>r(s).update(Ms(n)).digest(),e=r(new Uint8Array(32));return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=n=>r(n),t}var pu=J0(r=>new qi(r));var Q0=Hs("expand 16-byte k"),tp=Hs("expand 32-byte k"),ep=_e(Q0),rp=_e(tp);function D(r,t){return r<<t|r>>>32-t}function Gi(r){return r.byteOffset%4===0}var Fs=64,np=16,yu=2**32-1,gu=new Uint32Array;function sp(r,t,e,n,s,o,i,a){let c=s.length,l=new Uint8Array(Fs),u=_e(l),f=Gi(s)&&Gi(o),g=f?_e(s):gu,m=f?_e(o):gu;for(let d=0;d<c;i++){if(r(t,e,n,u,i,a),i>=yu)throw new Error("arx: counter overflow");let h=Math.min(Fs,c-d);if(f&&h===Fs){let p=d/4;if(d%4!==0)throw new Error("arx: invalid block position");for(let b=0,v;b<np;b++)v=p+b,m[v]=g[v]^u[b];d+=Fs;continue}for(let p=0,b;p<h;p++)b=d+p,o[b]=s[b]^l[p];d+=h}}function ji(r,t){let{allowShortKeys:e,extendNonceFn:n,counterLength:s,counterRight:o,rounds:i}=fu({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t);if(typeof r!="function")throw new Error("core must be a function");return Ks(s),Ks(i),Fi(o),Fi(e),(a,c,l,u,f=0)=>{Ur(a),Ur(c),Ur(l);let g=l.length;if(u||(u=new Uint8Array(g)),Ur(u),Ks(f),f<0||f>=yu)throw new Error("arx: counter overflow");if(u.length<g)throw new Error(`arx: output (${u.length}) is shorter than data (${g})`);let m=[],d=a.length,h,p;if(d===32)h=a.slice(),m.push(h),p=rp;else if(d===16&&e)h=new Uint8Array(32),h.set(a),h.set(a,16),p=ep,m.push(h);else throw new Error(`arx: invalid 32-byte key, got length=${d}`);Gi(c)||(c=c.slice(),m.push(c));let b=_e(h);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(p,b,_e(c.subarray(0,16)),b),c=c.subarray(16)}let v=16-s;if(v!==c.length)throw new Error(`arx: nonce must be ${v} or 16 bytes`);if(v!==12){let A=new Uint8Array(12);A.set(c,o?0:12-c.length),c=A,m.push(c)}let w=_e(c);for(sp(r,p,b,w,l,u,f,i);m.length>0;)m.pop().fill(0);return u}}function bu(r,t,e,n,s,o=20){let i=r[0],a=r[1],c=r[2],l=r[3],u=t[0],f=t[1],g=t[2],m=t[3],d=t[4],h=t[5],p=t[6],b=t[7],v=s,w=e[0],A=e[1],B=e[2],S=i,N=a,_=c,V=l,P=u,L=f,H=g,O=m,z=d,x=h,I=p,C=b,E=v,y=w,k=A,T=B;for(let M=0;M<o;M+=2)S=S+P|0,E=D(E^S,16),z=z+E|0,P=D(P^z,12),S=S+P|0,E=D(E^S,8),z=z+E|0,P=D(P^z,7),N=N+L|0,y=D(y^N,16),x=x+y|0,L=D(L^x,12),N=N+L|0,y=D(y^N,8),x=x+y|0,L=D(L^x,7),_=_+H|0,k=D(k^_,16),I=I+k|0,H=D(H^I,12),_=_+H|0,k=D(k^_,8),I=I+k|0,H=D(H^I,7),V=V+O|0,T=D(T^V,16),C=C+T|0,O=D(O^C,12),V=V+O|0,T=D(T^V,8),C=C+T|0,O=D(O^C,7),S=S+L|0,T=D(T^S,16),I=I+T|0,L=D(L^I,12),S=S+L|0,T=D(T^S,8),I=I+T|0,L=D(L^I,7),N=N+H|0,E=D(E^N,16),C=C+E|0,H=D(H^C,12),N=N+H|0,E=D(E^N,8),C=C+E|0,H=D(H^C,7),_=_+O|0,y=D(y^_,16),z=z+y|0,O=D(O^z,12),_=_+O|0,y=D(y^_,8),z=z+y|0,O=D(O^z,7),V=V+P|0,k=D(k^V,16),x=x+k|0,P=D(P^x,12),V=V+P|0,k=D(k^V,8),x=x+k|0,P=D(P^x,7);let R=0;n[R++]=i+S|0,n[R++]=a+N|0,n[R++]=c+_|0,n[R++]=l+V|0,n[R++]=u+P|0,n[R++]=f+L|0,n[R++]=g+H|0,n[R++]=m+O|0,n[R++]=d+z|0,n[R++]=h+x|0,n[R++]=p+I|0,n[R++]=b+C|0,n[R++]=v+E|0,n[R++]=w+y|0,n[R++]=A+k|0,n[R++]=B+T|0}function op(r,t,e,n){let s=r[0],o=r[1],i=r[2],a=r[3],c=t[0],l=t[1],u=t[2],f=t[3],g=t[4],m=t[5],d=t[6],h=t[7],p=e[0],b=e[1],v=e[2],w=e[3];for(let B=0;B<20;B+=2)s=s+c|0,p=D(p^s,16),g=g+p|0,c=D(c^g,12),s=s+c|0,p=D(p^s,8),g=g+p|0,c=D(c^g,7),o=o+l|0,b=D(b^o,16),m=m+b|0,l=D(l^m,12),o=o+l|0,b=D(b^o,8),m=m+b|0,l=D(l^m,7),i=i+u|0,v=D(v^i,16),d=d+v|0,u=D(u^d,12),i=i+u|0,v=D(v^i,8),d=d+v|0,u=D(u^d,7),a=a+f|0,w=D(w^a,16),h=h+w|0,f=D(f^h,12),a=a+f|0,w=D(w^a,8),h=h+w|0,f=D(f^h,7),s=s+l|0,w=D(w^s,16),d=d+w|0,l=D(l^d,12),s=s+l|0,w=D(w^s,8),d=d+w|0,l=D(l^d,7),o=o+u|0,p=D(p^o,16),h=h+p|0,u=D(u^h,12),o=o+u|0,p=D(p^o,8),h=h+p|0,u=D(u^h,7),i=i+f|0,b=D(b^i,16),g=g+b|0,f=D(f^g,12),i=i+f|0,b=D(b^i,8),g=g+b|0,f=D(f^g,7),a=a+c|0,v=D(v^a,16),m=m+v|0,c=D(c^m,12),a=a+c|0,v=D(v^a,8),m=m+v|0,c=D(c^m,7);let A=0;n[A++]=s,n[A++]=o,n[A++]=i,n[A++]=a,n[A++]=p,n[A++]=b,n[A++]=v,n[A++]=w}var ip=ji(bu,{counterRight:!1,counterLength:4,allowShortKeys:!1}),ap=ji(bu,{counterRight:!1,counterLength:8,extendNonceFn:op,allowShortKeys:!1});var cp=new Uint8Array(16),mu=(r,t)=>{r.update(t);let e=t.length%16;e&&r.update(cp.subarray(e))},lp=new Uint8Array(32);function wu(r,t,e,n,s){let o=r(t,e,lp),i=pu.create(o);s&&mu(i,s),mu(i,n);let a=new Uint8Array(16),c=uu(a);Ki(c,0,BigInt(s?s.length:0),!0),Ki(c,8,BigInt(n.length),!0),i.update(a);let l=i.digest();return o.fill(0),l}var xu=r=>(t,e,n)=>(ar(t,32),ar(e),{encrypt:(o,i)=>{let a=o.length,c=a+16;i?ar(i,c):i=new Uint8Array(c),r(t,e,o,i,1);let l=wu(r,t,e,i.subarray(0,-16),n);return i.set(l,a),i},decrypt:(o,i)=>{let a=o.length,c=a-16;if(a<16)throw new Error("encrypted data must be at least 16 bytes");i?ar(i,c):i=new Uint8Array(c);let l=o.subarray(0,-16),u=o.subarray(-16),f=wu(r,t,e,l,n);if(!hu(u,f))throw new Error("invalid tag");return r(t,e,l,i,1),i}}),zi=Mi({blockSize:64,nonceLength:12,tagLength:16},xu(ip)),zb=Mi({blockSize:64,nonceLength:24,tagLength:16},xu(ap));function vu(r,t,e){return je(r),e===void 0&&(e=new Uint8Array(r.outputLen)),Ve(r,qt(e),qt(t))}var Wi=new Uint8Array([0]),Eu=new Uint8Array;function Bu(r,t,e,n=32){if(je(r),Re(n),n>255*r.outputLen)throw new Error("Length should be <= 255*HashLen");let s=Math.ceil(n/r.outputLen);e===void 0&&(e=Eu);let o=new Uint8Array(s*r.outputLen),i=Ve.create(r,t),a=i._cloneInto(),c=new Uint8Array(i.outputLen);for(let l=0;l<s;l++)Wi[0]=l+1,a.update(l===0?Eu:c).update(e).update(Wi).digestInto(c),o.set(c,r.outputLen*l),i._cloneInto(a);return i.destroy(),a.destroy(),c.fill(0),Wi.fill(0),o.slice(0,n)}var Yi={hashSHA256(r){return Ir(r.subarray())},getHKDF(r,t){let e=vu(Ir,t,r),s=Bu(Ir,e,void 0,96),o=s.subarray(0,32),i=s.subarray(32,64),a=s.subarray(64,96);return[o,i,a]},generateX25519KeyPair(){let r=Wr.utils.randomPrivateKey();return{publicKey:Wr.getPublicKey(r),privateKey:r}},generateX25519KeyPairFromSeed(r){return{publicKey:Wr.getPublicKey(r),privateKey:r}},generateX25519SharedKey(r,t){return Wr.getSharedSecret(r.subarray(),t.subarray())},chaCha20Poly1305Encrypt(r,t,e,n){return zi(n,t,e).encrypt(r.subarray())},chaCha20Poly1305Decrypt(r,t,e,n,s){return zi(n,t,e).decrypt(r.subarray(),s)}};var Au=Yi;function Su(r){return{generateKeypair:r.generateX25519KeyPair,dh:(t,e)=>r.generateX25519SharedKey(t.privateKey,e).subarray(0,32),encrypt:r.chaCha20Poly1305Encrypt,decrypt:r.chaCha20Poly1305Decrypt,hash:r.hashSHA256,hkdf:r.getHKDF}}var Pr=r=>{let t=mt(2);return t[0]=r>>8,t[1]=r,t};Pr.bytes=2;var gn=r=>{if(r.length<2)throw RangeError("Could not decode int16BE");if(r instanceof Uint8Array){let t=0;return t+=r[0]<<8,t+=r[1],t}return r.getUint16(0)};gn.bytes=2;function ku(r){return{xxHandshakeSuccesses:r.registerCounter("libp2p_noise_xxhandshake_successes_total",{help:"Total count of noise xxHandshakes successes_"}),xxHandshakeErrors:r.registerCounter("libp2p_noise_xxhandshake_error_total",{help:"Total count of noise xxHandshakes errors"}),encryptedPackets:r.registerCounter("libp2p_noise_encrypted_packets_total",{help:"Total count of noise encrypted packets successfully"}),decryptedPackets:r.registerCounter("libp2p_noise_decrypted_packets_total",{help:"Total count of noise decrypted packets"}),decryptErrors:r.registerCounter("libp2p_noise_decrypt_errors_total",{help:"Total count of noise decrypt errors"})}}function Zi(r,t){!t.enabled||!Cr||(r?(t(`LOCAL_STATIC_PUBLIC_KEY ${q(r.publicKey,"hex")}`),t(`LOCAL_STATIC_PRIVATE_KEY ${q(r.privateKey,"hex")}`)):t("Missing local static keys."))}function Xi(r,t){!t.enabled||!Cr||(r?(t(`LOCAL_PUBLIC_EPHEMERAL_KEY ${q(r.publicKey,"hex")}`),t(`LOCAL_PRIVATE_EPHEMERAL_KEY ${q(r.privateKey,"hex")}`)):t("Missing local ephemeral keys."))}function Iu(r,t){!t.enabled||!Cr||t(r?`REMOTE_STATIC_PUBLIC_KEY ${q(r.subarray(),"hex")}`:"Missing remote static public key.")}function Ji(r,t){!t.enabled||!Cr||t(r?`REMOTE_EPHEMERAL_PUBLIC_KEY ${q(r.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function Qi(r,t,e){!e.enabled||!Cr||(e(`CIPHER_STATE_1 ${r.n.getUint64()} ${r.k&&q(r.k,"hex")}`),e(`CIPHER_STATE_2 ${t.n.getUint64()} ${t.k&&q(t.k,"hex")}`))}var $s=class r extends Error{code;constructor(t="Unexpected Peer"){super(t),this.code=r.code}static code="ERR_UNEXPECTED_PEER"},Dr=class r extends Error{code;constructor(t="Invalid crypto exchange"){super(t),this.code=r.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var up=0,fp=4294967295,hp="Cipherstate has reached maximum n, a new handshake must be performed",qs=class{n;bytes;view;constructor(t=up){this.n=t,this.bytes=yt(12),this.view=new DataView(this.bytes.buffer,this.bytes.byteOffset,this.bytes.byteLength),this.view.setUint32(4,t,!0)}increment(){this.n++,this.view.setUint32(4,this.n,!0)}getBytes(){return this.bytes}getUint64(){return this.n}assertValue(){if(this.n>fp)throw new Error(hp)}};var cr=yt(0),Vr=class{k;n;crypto;constructor(t,e=void 0,n=0){this.crypto=t,this.k=e,this.n=new qs(n)}hasKey(){return!!this.k}encryptWithAd(t,e){if(!this.hasKey())return e;this.n.assertValue();let n=this.crypto.encrypt(e,this.n.getBytes(),t,this.k);return this.n.increment(),n}decryptWithAd(t,e,n){if(!this.hasKey())return e;this.n.assertValue();let s=this.crypto.decrypt(e,this.n.getBytes(),t,this.k,n);return this.n.increment(),s}},ta=class{cs;ck;h;crypto;constructor(t,e){this.crypto=t;let n=tt(e,"utf-8");this.h=dp(t,n),this.ck=this.h,this.cs=new Vr(t)}mixKey(t){let[e,n]=this.crypto.hkdf(this.ck,t);this.ck=e,this.cs=new Vr(this.crypto,n)}mixHash(t){this.h=this.crypto.hash(new at(this.h,t))}encryptAndHash(t){let e=this.cs.encryptWithAd(this.h,t);return this.mixHash(e),e}decryptAndHash(t){let e=this.cs.decryptWithAd(this.h,t);return this.mixHash(t),e}split(){let[t,e]=this.crypto.hkdf(this.ck,cr);return[new Vr(this.crypto,t),new Vr(this.crypto,e)]}},ea=class{ss;s;e;rs;re;initiator;crypto;constructor(t){let{crypto:e,protocolName:n,prologue:s,initiator:o,s:i,e:a,rs:c,re:l}=t;this.crypto=e,this.ss=new ta(e,n),this.ss.mixHash(s),this.initiator=o,this.s=i,this.e=a,this.rs=c,this.re=l}writeE(){if(this.e)throw new Error("ephemeral keypair is already set");let t=this.crypto.generateKeypair();return this.ss.mixHash(t.publicKey),this.e=t,t.publicKey}writeS(){if(!this.s)throw new Error("static keypair is not set");return this.ss.encryptAndHash(this.s.publicKey)}writeEE(){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.re))}writeES(){if(this.initiator){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}else{if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}}writeSE(){if(this.initiator){if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}else{if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}}readE(t,e=0){if(this.re)throw new Error("remote ephemeral public key is already set");if(t.byteLength<e+32)throw new Error("message is not long enough");this.re=t.sublist(e,e+32),this.ss.mixHash(this.re)}readS(t,e=0){if(this.rs)throw new Error("remote static public key is already set");let n=32+(this.ss.cs.hasKey()?16:0);if(t.byteLength<e+n)throw new Error("message is not long enough");let s=t.sublist(e,e+n);return this.rs=this.ss.decryptAndHash(s),n}readEE(){this.writeEE()}readES(){this.writeES()}readSE(){this.writeSE()}},yn=class extends ea{writeMessageA(t){return new at(this.writeE(),this.ss.encryptAndHash(t))}writeMessageB(t){let e=this.writeE();this.writeEE();let n=this.writeS();return this.writeES(),new at(e,n,this.ss.encryptAndHash(t))}writeMessageC(t){let e=this.writeS();return this.writeSE(),new at(e,this.ss.encryptAndHash(t))}readMessageA(t){try{return this.readE(t),this.ss.decryptAndHash(t.sublist(32))}catch(e){throw new Dr(`handshake stage 0 validation fail: ${e.message}`)}}readMessageB(t){try{this.readE(t),this.readEE();let e=this.readS(t,32);return this.readES(),this.ss.decryptAndHash(t.sublist(32+e))}catch(e){throw new Dr(`handshake stage 1 validation fail: ${e.message}`)}}readMessageC(t){try{let e=this.readS(t);return this.readSE(),this.ss.decryptAndHash(t.sublist(e))}catch(e){throw new Dr(`handshake stage 2 validation fail: ${e.message}`)}}};function dp(r,t){if(t.length<=32){let e=yt(32);return e.set(t),e}else return r.hash(t)}var Gs;(function(r){let t;r.codec=()=>(t==null&&(t=tr((e,n,s={})=>{if(s.lengthDelimited!==!1&&n.fork(),e.webtransportCerthashes!=null)for(let o of e.webtransportCerthashes)n.uint32(10),n.bytes(o);s.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let s={webtransportCerthashes:[]},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let i=e.uint32();switch(i>>>3){case 1:{s.webtransportCerthashes.push(e.bytes());break}default:{e.skipType(i&7);break}}}return s})),t),r.encode=e=>Qe(e,r.codec()),r.decode=e=>Xe(e,r.codec())})(Gs||(Gs={}));var mn;(function(r){let t;r.codec=()=>(t==null&&(t=tr((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.identityKey!=null&&e.identityKey.byteLength>0&&(n.uint32(10),n.bytes(e.identityKey)),e.identitySig!=null&&e.identitySig.byteLength>0&&(n.uint32(18),n.bytes(e.identitySig)),e.extensions!=null&&(n.uint32(34),Gs.codec().encode(e.extensions,n)),s.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let s={identityKey:yt(0),identitySig:yt(0)},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let i=e.uint32();switch(i>>>3){case 1:{s.identityKey=e.bytes();break}case 2:{s.identitySig=e.bytes();break}case 4:{s.extensions=Gs.codec().decode(e,e.uint32());break}default:{e.skipType(i&7);break}}}return s})),t),r.encode=e=>Qe(e,r.codec()),r.decode=e=>Xe(e,r.codec())})(mn||(mn={}));async function ra(r,t,e){let n=await r.sign(_u(t));return mn.encode({identityKey:r.public.bytes,identitySig:n,extensions:e})}async function na(r,t,e){try{let n=mn.decode(r);if(e){let i=e.subarray();if(!lt(i,n.identityKey))throw new Error(`Payload identity key ${q(n.identityKey,"hex")} does not match expected remote identity key ${q(i,"hex")}`)}if(!t)throw new Error("Remote static does not exist");let s=_u(t);if(!await jl(n.identityKey).verify(s,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new $s(n.message)}}function _u(r){let t=tt("noise-libp2p-static-key:");return r instanceof Uint8Array?xt([t,r],t.length+r.length):(r.prepend(t),r)}async function Nu(r){let{log:t,connection:e,crypto:n,privateKey:s,prologue:o,s:i,remoteIdentityKey:a,extensions:c}=r,l=await ra(s,i.publicKey,c),u=new yn({crypto:n,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:o,s:i});Zi(u.s,t),t.trace("Stage 0 - Initiator starting to send first message."),await e.write(u.writeMessageA(cr)),t.trace("Stage 0 - Initiator finished sending first message."),Xi(u.e,t),t.trace("Stage 1 - Initiator waiting to receive first message from responder...");let f=u.readMessageB(await e.read());t.trace("Stage 1 - Initiator received the message."),Ji(u.re,t),Iu(u.rs,t),t.trace("Initiator going to check remote's signature...");let g=await na(f,u.rs,a);t.trace("All good with the signature!"),t.trace("Stage 2 - Initiator sending third handshake message."),await e.write(u.writeMessageC(l)),t.trace("Stage 2 - Initiator sent message with signed payload.");let[m,d]=u.ss.split();return Qi(m,d,t),{payload:g,encrypt:h=>m.encryptWithAd(cr,h),decrypt:(h,p)=>d.decryptWithAd(cr,h,p)}}async function Tu(r){let{log:t,connection:e,crypto:n,privateKey:s,prologue:o,s:i,remoteIdentityKey:a,extensions:c}=r,l=await ra(s,i.publicKey,c),u=new yn({crypto:n,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:o,s:i});Zi(u.s,t),t.trace("Stage 0 - Responder waiting to receive first message."),u.readMessageA(await e.read()),t.trace("Stage 0 - Responder received first message."),Ji(u.re,t),t.trace("Stage 1 - Responder sending out first message with signed payload and static key."),await e.write(u.writeMessageB(l)),t.trace("Stage 1 - Responder sent the second handshake message with signed payload."),Xi(u.e,t),t.trace("Stage 2 - Responder waiting for third handshake message...");let f=u.readMessageC(await e.read());t.trace("Stage 2 - Responder received the message, finished handshake.");let g=await na(f,u.rs,a),[m,d]=u.ss.split();return Qi(m,d,t),{payload:g,encrypt:h=>d.encryptWithAd(cr,h),decrypt:(h,p)=>m.decryptWithAd(cr,h,p)}}var Ru=16;function Cu(r,t){return async function*(e){for await(let n of e)for(let s=0;s<n.length;s+=65519){let o=s+65519;o>n.length&&(o=n.length);let i;n instanceof Uint8Array?i=r.encrypt(n.subarray(s,o)):i=r.encrypt(n.sublist(s,o)),t?.encryptedPackets.increment(),yield new at(Pr(i.byteLength),i)}}}function Uu(r,t){return async function*(e){for await(let n of e)for(let s=0;s<n.length;s+=65535){let o=s+65535;if(o>n.length&&(o=n.length),o-Ru<s)throw new Error("Invalid chunk");let i=n.sublist(s,o),a=n.subarray(s,o-Ru);try{let c=r.decrypt(i,a);t?.decryptedPackets.increment(),yield c}catch(c){throw t?.decryptErrors.increment(),c}}}}var js=class{protocol="/noise";crypto;prologue;staticKey;extensions;metrics;components;constructor(t,e={}){let{staticNoiseKey:n,extensions:s,crypto:o,prologueBytes:i}=e,{metrics:a}=t;this.components=t;let c=o??Au;this.crypto=Su(c),this.extensions=s,this.metrics=a?ku(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=i??yt(0)}async secureOutbound(t,e,n){let s=Di(e,{lengthEncoder:Pr,lengthDecoder:gn,maxDataLength:65535});if(!t.privateKey)throw new F("local peerId does not contain private key","ERR_NO_PRIVATE_KEY");let o=await _i(t.privateKey),i=n?.publicKey,a=await this.performHandshakeInitiator(s,o,i),c=await this.createSecureConnection(s,a);return e.source=c.source,e.sink=c.sink,{conn:e,remoteExtensions:a.payload.extensions,remotePeer:await Ri(a.payload.identityKey)}}async secureInbound(t,e,n){let s=Di(e,{lengthEncoder:Pr,lengthDecoder:gn,maxDataLength:65535});if(!t.privateKey)throw new F("local peerId does not contain private key","ERR_NO_PRIVATE_KEY");let o=await _i(t.privateKey),i=n?.publicKey,a=await this.performHandshakeResponder(s,o,i),c=await this.createSecureConnection(s,a);return e.source=c.source,e.sink=c.sink,{conn:e,remoteExtensions:a.payload.extensions,remotePeer:await Ri(a.payload.identityKey)}}async performHandshakeInitiator(t,e,n){let s;try{s=await Nu({connection:t,privateKey:e,remoteIdentityKey:n,log:this.components.logger.forComponent("libp2p:noise:xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:this.extensions}),this.metrics?.xxHandshakeSuccesses.increment()}catch(o){throw this.metrics?.xxHandshakeErrors.increment(),o}return s}async performHandshakeResponder(t,e,n){let s;try{s=await Tu({connection:t,privateKey:e,remoteIdentityKey:n,log:this.components.logger.forComponent("libp2p:noise:xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:this.extensions}),this.metrics?.xxHandshakeSuccesses.increment()}catch(o){throw this.metrics?.xxHandshakeErrors.increment(),o}return s}async createSecureConnection(t,e){let[n,s]=su(),o=t.unwrap();return await iu(n,Cu(e,this.metrics),o,i=>pn(i,{lengthDecoder:gn}),Uu(e,this.metrics),n),s}};function Pu(r={}){return t=>new js(t,r)}var zs=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,a=this.peekChar();if(a===void 0)return;let c=a==="0",l=2**(8*s)-1;for(;;){let u=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let g=Number.parseInt(f,t);if(!Number.isNaN(g))return g});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&&c&&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),[a]=t(o.subarray(0,i));return e.set(o.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Du=45,pp=15,Or=new zs;function sa(r){if(!(r.length>pp))return Or.new(r).parseWith(()=>Or.readIPv4Addr())}function oa(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Du))return Or.new(r).parseWith(()=>Or.readIPv6Addr())}function Ws(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Du))return Or.new(r).parseWith(()=>Or.readIPAddr())}var Nx=parseInt("0xFFFF",16),Tx=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Ys(r){return!!sa(r)}function Zs(r){return!!oa(r)}function Xs(r){return!!Ws(r)}var Hu=Ys,bp=Zs,ia=function(r){let t=0;if(r=r.toString().trim(),Hu(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(bp(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let o=Hu(e[n]),i;o&&(i=ia(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")},Mu=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 Hr={},aa={},Ep=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[777,-1,"memory"]];Ep.forEach(r=>{let t=vp(...r);aa[t.code]=t,Hr[t.name]=t});function vp(r,t,e,n,s){return{code:r,size:t,name:e,resolvable:!!n,path:!!s}}function J(r){if(typeof r=="number"){if(aa[r]!=null)return aa[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Hr[r]!=null)return Hr[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var d2=J("ip4"),p2=J("ip6"),g2=J("ipcidr");function la(r,t){switch(J(r).code){case 4:case 41:return Ap(t);case 42:return $u(t);case 6:case 273:case 33:case 132:return Gu(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return $u(t);case 421:return _p(t);case 444:return qu(t);case 445:return qu(t);case 466:return Ip(t);default:return q(t,"base16")}}function ua(r,t){switch(J(r).code){case 4:return Ku(t);case 41:return Ku(t);case 42:return Fu(t);case 6:case 273:case 33:case 132:return fa(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Fu(t);case 421:return Sp(t);case 444:return Np(t);case 445:return Tp(t);case 466:return kp(t);default:return tt(t,"base16")}}var ca=Object.values(ee).map(r=>r.decoder),Bp=function(){let r=ca[0].or(ca[1]);return ca.slice(2).forEach(t=>r=r.or(t)),r}();function Ku(r){if(!Xs(r))throw new Error("invalid ip address");return ia(r)}function Ap(r){let t=Mu(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!Xs(t))throw new Error("invalid ip address");return t}function fa(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Gu(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Fu(r){let t=tt(r),e=Uint8Array.from(re(t.length));return xt([e,t],e.length+t.length)}function $u(r){let t=Wt(r);if(r=r.slice(ht(t)),r.length!==t)throw new Error("inconsistent lengths");return q(r)}function Sp(r){let t;r[0]==="Q"||r[0]==="1"?t=Te(ct.decode(`z${r}`)).bytes:t=Ft.parse(r).multihash.bytes;let e=Uint8Array.from(re(t.length));return xt([e,t],e.length+t.length)}function kp(r){let t=Bp.decode(r),e=Uint8Array.from(re(t.length));return xt([e,t],e.length+t.length)}function Ip(r){let t=Wt(r),e=r.slice(ht(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+q(e,"base64url")}function _p(r){let t=Wt(r),e=r.slice(ht(t));if(e.length!==t)throw new Error("inconsistent lengths");return q(e,"base58btc")}function Np(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=de.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=fa(n);return xt([e,s],e.length+s.length)}function Tp(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=de.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=fa(n);return xt([e,s],e.length+s.length)}function qu(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=q(t,"base32"),s=Gu(e);return`${n}:${s}`}function ju(r){r=ha(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],a=J(i);if(a.size===0){t.push([a.code]),e.push([a.code]);continue}if(o++,o>=s.length)throw Wu("invalid address: "+r);if(a.path===!0){n=ha(s.slice(o).join("/")),t.push([a.code,ua(a.code,n)]),e.push([a.code,n]);break}let c=ua(a.code,s[o]);t.push([a.code,c]),e.push([a.code,la(a.code,c)])}return{string:zu(e),bytes:pa(t),tuples:t,stringTuples:e,path:n}}function da(r){let t=[],e=[],n=null,s=0;for(;s<r.length;){let o=Wt(r,s),i=ht(o),a=J(o),c=Lp(a,r.slice(s+i));if(c===0){t.push([o]),e.push([o]),s+=i;continue}let l=r.slice(s+i,s+i+c);if(s+=c+i,s>r.length)throw Wu("Invalid address Uint8Array: "+q(r,"base16"));t.push([o,l]);let u=la(o,l);if(e.push([o,u]),a.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:zu(e),tuples:t,stringTuples:e,path:n}}function zu(r){let t=[];return r.map(e=>{let n=J(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),ha(t.join("/"))}function pa(r){return xt(r.map(t=>{let e=J(t[0]),n=Uint8Array.from(re(e.code));return t.length>1&&t[1]!=null&&(n=xt([n,t[1]])),n}))}function Lp(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=Wt(t instanceof Uint8Array?t:Uint8Array.from(t));return e+ht(e)}}function ha(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}function Wu(r){return new Error("Error parsing address: "+r)}var Rp=Symbol.for("nodejs.util.inspect.custom"),ya=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Cp=[J("dns").code,J("dns4").code,J("dns6").code,J("dnsaddr").code],ga=class r{bytes;#e;#t;#r;#n;[ya]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=da(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=ju(t)}else if(Zu(t))e=da(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=J("tcp"),a=J("udp"),c=J("ip4"),l=J("ip6"),u=J("dns6"),f=J("ip6zone");for(let[m,d]of this.stringTuples())m===f.code&&(o=`%${d??""}`),Cp.includes(m)&&(e=i.name,s=443,n=`${d??""}${o}`,t=m===u.code?6:4),(m===i.code||m===a.code)&&(e=J(m).name,s=parseInt(d??"")),(m===c.code||m===l.code)&&(e=J(m).name,n=`${d??""}${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({},J(t)))}protoCodes(){return this.#t.map(([t])=>t)}protoNames(){return this.#t.map(([t])=>J(t).name)}tuples(){return this.#t}stringTuples(){return this.#r}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(pa(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,s])=>{n===Hr.p2p.code&&t.push([n,s]),n===Hr["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?q(ct.decode(`z${n}`),"base58btc"):q(Ft.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return lt(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(o=>o.resolvable);if(e==null)return[this];let n=Yu.get(e.name);if(n==null)throw new F(`no available resolver for ${e.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,t)).map(o=>new r(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)}[Rp](){return`Multiaddr(${this.#e})`}};var Yu=new Map;function Zu(r){return!!r?.[ya]}var Up=r=>r.toString().split("/").slice(1),bn=r=>({match:t=>t.length<1?!1:r(t[0])?t.slice(1):!1,pattern:"fn"}),ut=r=>({match:t=>bn(e=>e===r).match(t),pattern:r}),to=()=>({match:r=>bn(t=>typeof t=="string").match(r),pattern:"{string}"}),Xu=()=>({match:r=>bn(t=>!isNaN(parseInt(t))).match(r),pattern:"{number}"}),Mt=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{ct.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),Js=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{Ao.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),ce=r=>({match:t=>{let e=r.match(t);return e===!1?t:e},pattern:`optional(${r.pattern})`}),le=(...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(", ")})`}),ft=(...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 bt(...r){function t(s){let o=Up(s);for(let i of r){let a=i.match(o);if(a===!1)return!1;o=a}return o}function e(s){return t(s)!==!1}function n(s){let o=t(s);return o===!1?!1:o.length===0}return{matches:e,exactMatch:n}}var wa=ft(ut("dns4"),to()),ba=ft(ut("dns6"),to()),xa=ft(ut("dnsaddr"),to()),Ju=ft(ut("dns"),to()),G2=bt(wa),j2=bt(ba),z2=bt(xa),W2=bt(le(Ju,xa,wa,ba)),Qu=ft(ut("ip4"),bn(Ys)),tf=ft(ut("ip6"),bn(Zs)),ef=le(Qu,tf),xn=le(ef,Ju,wa,ba,xa),Y2=bt(xn),Z2=bt(Qu),X2=bt(tf),J2=bt(ef),eo=ft(xn,ut("tcp"),Xu()),En=ft(xn,ut("udp"),Xu()),Pp=le(eo,En),Q2=bt(eo),tE=bt(En),Ea=ft(En,ut("quic")),ro=ft(En,ut("quic-v1")),Dp=le(Ea,ro),eE=bt(Ea),rE=bt(ro),ma=le(xn,eo,En,Ea,ro),rf=le(ft(ma,ut("ws"),ce(Mt()))),nE=bt(rf),nf=le(ft(ma,ut("wss"),ce(Mt())),ft(ma,ut("tls"),ut("ws"),ce(Mt()))),sE=bt(nf),sf=ft(Pp,ut("webrtc-direct"),Js(),ce(Js()),ce(Mt())),oE=bt(sf),of=ft(ro,ut("webtransport"),Js(),Js(),ce(Mt())),no=bt(of),Qs=le(rf,nf,ft(eo,ce(Mt())),ft(Dp,ce(Mt())),ft(xn,ce(Mt())),sf,of,Mt()),iE=bt(Qs),Vp=ft(Qs,ut("p2p-circuit"),Mt()),aE=bt(Vp),Op=le(ft(Qs,ut("p2p-circuit"),ut("webrtc"),Mt()),ft(Qs,ut("webrtc"),ce(Mt())),ut("webrtc")),cE=bt(Op);async function va(r,t,e,n,s,o){let i=o.forComponent(`libp2p:webtransport:stream:${e}:${t}`),a=r.writable.getWriter(),c=r.readable.getReader();await a.ready;function l(){let d=n.findIndex(h=>h===m);d!==-1&&(n.splice(d,1),m.timeline.close=Date.now(),s?.(m))}let u=!1,f=!1;(async function(){let d=await a.closed.catch(h=>h);if(d!=null){let h=d.message;h.includes("aborted by the remote server")||h.includes("STOP_SENDING")||i.error(`WebTransport writer closed unexpectedly: streamId=${t} err=${d.message}`)}u=!0,u&&f&&l()})().catch(()=>{i.error("WebTransport failed to cleanup closed stream")}),async function(){let d=await c.closed.catch(h=>h);d!=null&&i.error(`WebTransport reader closed unexpectedly: streamId=${t} err=${d.message}`),f=!0,u&&f&&l()}().catch(()=>{i.error("WebTransport failed to cleanup closed stream")});let g=!1,m={id:t,status:"open",writeStatus:"ready",readStatus:"ready",abort(d){u||(a.abort(d).catch(h=>{i.error("could not abort stream",h)}),u=!0),f=!0,this.status="aborted",this.writeStatus="closed",this.readStatus="closed",this.timeline.reset=this.timeline.close=this.timeline.closeRead=this.timeline.closeWrite=Date.now(),l()},async close(d){this.status="closing",await Promise.all([m.closeRead(d),m.closeWrite(d)]),l(),this.status="closed",this.timeline.close=Date.now()},async closeRead(d){if(!f){this.readStatus="closing";try{await c.cancel()}catch(h){h.toString().includes("RESET_STREAM")===!0&&(u=!0)}this.timeline.closeRead=Date.now(),this.readStatus="closed",f=!0}u&&l()},async closeWrite(d){if(!u){u=!0,this.writeStatus="closing";try{await a.close()}catch(h){h.toString().includes("RESET_STREAM")===!0&&(f=!0)}this.timeline.closeWrite=Date.now(),this.writeStatus="closed"}f&&l()},direction:e,timeline:{open:Date.now()},metadata:{},source:async function*(){for(;;){let d=await c.read();if(d.done){f=!0,u&&l();return}yield new at(d.value)}}(),sink:async function(d){if(g)throw new Error("sink already called on stream");g=!0;try{this.writeStatus="writing";for await(let h of d)if(h instanceof Uint8Array)await a.write(h);else for(let p of h)await a.write(p);this.writeStatus="done"}finally{this.timeline.closeWrite=Date.now(),this.writeStatus="closed",await m.closeWrite()}},log:i};return m}function Ba(){return{source:{[Symbol.asyncIterator](){return{async next(){return new Promise(()=>{})}}}},sink:async r=>new Promise(()=>{})}}function af(r,t){return t.filter(n=>!!r.find(s=>lt(n,s))).length===t.length}var Hp=Object.values(ee).map(r=>r.decoder).reduce((r,t)=>r.or(t));function Mp(r){return te.decode(Hp.decode(r))}function cf(r){if(!no.matches(r))throw new F("Invalid multiaddr, was not a WebTransport address","ERR_INVALID_MULTIADDR");let t=r.stringTuples(),e=t.filter(([i,a])=>i===J("certhash").code).map(([i,a])=>Mp(a??"")),n=t.filter(([i,a])=>i===J("p2p").code).map(([i,a])=>Li(a??""))[0],s=r.toOptions(),o=s.host;return s.family===6&&o?.includes(":")&&(o=`[${o}]`),{url:`https://${o}:${s.port}`,certhashes:e,remotePeer:n}}var Aa=class{log;components;config;metrics;constructor(t,e={}){this.log=t.logger.forComponent("libp2p:webtransport"),this.components=t,this.config={maxInboundStreams:e.maxInboundStreams??1e3},t.metrics!=null&&(this.metrics={dialerEvents:t.metrics.registerCounterGroup("libp2p_webtransport_dialer_events_total",{label:"event",help:"Total count of WebTransport dialer events by type"})})}[Symbol.toStringTag]="@libp2p/webtransport";[Oa]=!0;async dial(t,e){e?.signal?.throwIfAborted(),this.log("dialing %s",t);let n=this.components.peerId;if(n===void 0)throw new Error("Need a local peerid");e=e??{};let{url:s,certhashes:o,remotePeer:i}=cf(t);if(i==null)throw new Error("Need a target peerid");if(o.length===0)throw new Error("Expected multiaddr to contain certhashes");let a,c,l=()=>{},u=!1,f=!1,g=!1;try{this.metrics?.dialerEvents.increment({pending:!0});let m=new WebTransport(`${s}/.well-known/libp2p-webtransport?type=noise`,{serverCertificateHashes:o.map(d=>({algorithm:"sha-256",value:d.digest}))});if(l=d=>{if(!u)try{this.metrics?.dialerEvents.increment({[d]:!0}),m.close()}catch(h){this.log.error("error closing wt session",h)}finally{c!=null&&(c.timeline.close=Date.now()),u=!0}},a=()=>{l(f?"noise_timeout":"ready_timeout")},e.signal?.addEventListener("abort",a,{once:!0}),await Promise.race([m.closed,m.ready]),f=!0,this.metrics?.dialerEvents.increment({ready:!0}),m.closed.catch(d=>{this.log.error("error on remote wt session close",d)}).finally(()=>{l("remote_close")}),!await this.authenticateWebTransport(m,n,i,o))throw new Error("Failed to authenticate webtransport");return this.metrics?.dialerEvents.increment({open:!0}),c={close:async()=>{this.log("Closing webtransport"),l("close")},abort:d=>{this.log("aborting webtransport due to passed err",d),l("abort")},remoteAddr:t,timeline:{open:Date.now()},log:this.components.logger.forComponent("libp2p:webtransport:maconn"),...Ba()},g=!0,await e.upgrader.upgradeOutbound(c,{skipEncryption:!0,muxerFactory:this.webtransportMuxer(m),skipProtection:!0})}catch(m){throw this.log.error("caught wt session err",m),l(g?"upgrade_error":f?"noise_error":"ready_error"),m}finally{a!=null&&e.signal?.removeEventListener("abort",a)}}async authenticateWebTransport(t,e,n,s){let o=await t.createBidirectionalStream(),i=o.writable.getWriter(),a=o.readable.getReader();await i.ready;let c={source:async function*(){for(;;){let f=await a.read();if(f.value!=null&&(yield f.value),f.done)break}}(),sink:async function(f){for await(let g of f)g instanceof Uint8Array?await i.write(g):await i.write(g.subarray())}},l=Pu()(this.components),{remoteExtensions:u}=await l.secureOutbound(e,c,n);if(i.close().catch(f=>{this.log.error(`Failed to close authentication stream writer: ${f.message}`)}),a.cancel().catch(f=>{this.log.error(`Failed to close authentication stream reader: ${f.message}`)}),!af(u?.webtransportCerthashes??[],s.map(f=>f.bytes)))throw new Error("Our certhashes are not a subset of the remote's reported certhashes");return!0}webtransportMuxer(t){let e=0,n=this.config,s=this;return{protocol:"webtransport",createStreamMuxer:o=>{typeof o=="function"&&(o={onIncomingStream:o});let i=[];return async function(){let c=t.incomingBidirectionalStreams.getReader();for(;;){let{done:l,value:u}=await c.read();if(l)break;if(i.length>=n.maxInboundStreams)u.writable.close().catch(f=>{s.log.error(`Failed to close inbound stream that crossed our maxInboundStream limit: ${f.message}`)}),u.readable.cancel().catch(f=>{s.log.error(`Failed to close inbound stream that crossed our maxInboundStream limit: ${f.message}`)});else{let f=await va(u,String(e++),"inbound",i,o?.onStreamEnd,s.components.logger);i.push(f),o?.onIncomingStream?.(f)}}}().catch(()=>{this.log.error("WebTransport failed to receive incoming stream")}),{protocol:"webtransport",streams:i,newStream:async c=>{let l=await t.createBidirectionalStream(),u=await va(l,String(e++),o?.direction??"outbound",i,o?.onStreamEnd,s.components.logger);return i.push(u),u},close:async c=>{this.log("Closing webtransport muxer"),await Promise.all(i.map(async l=>l.close(c)))},abort:c=>{this.log("Aborting webtransport muxer with err:",c);for(let l of i)l.abort(c)},...Ba()}}}}createListener(t){throw new Error("Webtransport servers are not supported in Node or the browser")}filter(t){return t.filter(no.exactMatch)}};function Kp(r={}){return t=>new Aa(t,r)}return vf(Fp);})();
|
|
7
|
+
`)}async function y0(r,t){let e=Lt.get(),n;if(r.includes("-----BEGIN ENCRYPTED PRIVATE KEY-----")){let s=tt(r.replace("-----BEGIN ENCRYPTED PRIVATE KEY-----","").replace("-----END ENCRYPTED PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:o}=Sr(s),{iv:i,salt:a,iterations:c,keySize:l,cipherText:u}=m0(o),f=await di(yr,t,a,{c,dkLen:l}),g=await e.subtle.importKey("raw",f,"AES-CBC",!1,["decrypt"]),m=cn(await e.subtle.decrypt({name:"AES-CBC",iv:i},g,u)),{result:d}=Sr(m);n=_l(d)}else if(r.includes("-----BEGIN PRIVATE KEY-----")){let s=tt(r.replace("-----BEGIN PRIVATE KEY-----","").replace("-----END PRIVATE KEY-----","").replace(/\n/g,"").trim(),"base64pad"),{result:o}=Sr(s);n=_l(o)}else throw new F("Could not parse private key from PEM data","ERR_INVALID_PARAMETERS");return xi(n)}function m0(r){let t=r.valueBlock.value[0];if(t.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.13")throw new F("Only pkcs5PBES2 encrypted private keys are supported","ERR_INVALID_PARAMS");let n=t.valueBlock.value[1].valueBlock.value[0];if(n.valueBlock.value[0].toString()!=="OBJECT IDENTIFIER : 1.2.840.113549.1.5.12")throw new F("Only pkcs5PBKDF2 key derivation functions are supported","ERR_INVALID_PARAMS");let o=n.valueBlock.value[1],i=cn(o.valueBlock.value[0].getValue()),a=bi,c=wi;if(o.valueBlock.value.length===3)a=Number(o.valueBlock.value[1].toBigInt()),c=Number(o.valueBlock.value[2].toBigInt());else if(o.valueBlock.value.length===2)throw new F("Could not derive key size and iterations from PEM file - please use @libp2p/rsa to re-import your key","ERR_INVALID_PARAMS");let l=t.valueBlock.value[1].valueBlock.value[1],u=l.valueBlock.value[0].toString();if(u!=="OBJECT IDENTIFIER : 1.2.840.113549.3.7"){if(u!=="OBJECT IDENTIFIER : 1.3.14.3.2.7"){if(u!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.2"){if(u!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.22"){if(u!=="OBJECT IDENTIFIER : 2.16.840.1.101.3.4.1.42")throw new F("Only AES-CBC encryption schemes are supported","ERR_INVALID_PARAMS")}}}}let f=cn(l.valueBlock.value[1].getValue());return{cipherText:cn(r.valueBlock.value[1].getValue()),salt:i,iterations:a,keySize:c,iv:f}}function _l(r){return cn(r.valueBlock.value[2].getValue())}function cn(r){return new Uint8Array(r,0,r.byteLength)}async function Nl(r){let t=await Lt.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 Rl(t);return{privateKey:e[0],publicKey:e[1]}}async function Ei(r){let e=[await Lt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["sign"]),await w0(r)],n=await Rl({privateKey:e[0],publicKey:e[1]});return{privateKey:n[0],publicKey:n[1]}}async function Tl(r,t){let e=await Lt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await Lt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},e,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function Ll(r,t,e){let n=await Lt.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return Lt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,e instanceof Uint8Array?e:e.subarray())}async function Rl(r){if(r.privateKey==null||r.publicKey==null)throw new F("Private and public key are required","ERR_INVALID_PARAMETERS");return Promise.all([Lt.get().subtle.exportKey("jwk",r.privateKey),Lt.get().subtle.exportKey("jwk",r.publicKey)])}async function w0(r){return Lt.get().subtle.importKey("jwk",{kty:r.kty,n:r.n,e:r.e},{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!0,["verify"])}function Ts(r){if(r.kty!=="RSA")throw new F("invalid key type","ERR_INVALID_KEY_TYPE");if(r.n==null)throw new F("invalid key modulus","ERR_INVALID_KEY_MODULUS");return tt(r.n,"base64url").length*8}var un=8192,ln=class{_key;constructor(t){this._key=t}verify(t,e){return Ll(this._key,e,t)}marshal(){return Ke.jwkToPkix(this._key)}get bytes(){return ne.encode({Type:ot.RSA,Data:this.marshal()}).subarray()}equals(t){return lt(this.bytes,t.bytes)}hash(){let t=At.digest(this.bytes);return Dt(t)?t.then(({bytes:e})=>e):t.bytes}},kr=class{_key;_publicKey;constructor(t,e){this._key=t,this._publicKey=e}genSecret(){return rr(16)}sign(t){return Tl(this._key,t)}get public(){if(this._publicKey==null)throw new F("public key not provided","ERR_PUBKEY_NOT_PROVIDED");return new ln(this._publicKey)}marshal(){return Ke.jwkToPkcs1(this._key)}get bytes(){return se.encode({Type:ot.RSA,Data:this.marshal()}).subarray()}equals(t){return lt(this.bytes,t.bytes)}hash(){let t=At.digest(this.bytes);return Dt(t)?t.then(({bytes:e})=>e):t.bytes}async id(){let t=await this.public.hash();return q(t,"base58btc")}async export(t,e="pkcs-8"){if(e==="pkcs-8")return Ke.exportToPem(this,t);if(e==="libp2p-key")return br(this.bytes,t);throw new F(`export format '${e}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};async function xi(r){let t=Ke.pkcs1ToJwk(r);if(Ts(t)>un)throw new F("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let e=await Ei(t);return new kr(e.privateKey,e.publicKey)}function x0(r){let t=Ke.pkixToJwk(r);if(Ts(t)>un)throw new F("key size is too large","ERR_KEY_SIZE_TOO_LARGE");return new ln(t)}async function E0(r){if(Ts(r)>un)throw new F("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await Ei(r);return new kr(t.privateKey,t.publicKey)}async function v0(r){if(r>un)throw new F("key size is too large","ERR_KEY_SIZE_TOO_LARGE");let t=await Nl(r);return new kr(t.privateKey,t.publicKey)}var Ii={};gt(Ii,{Secp256k1PrivateKey:()=>hn,Secp256k1PublicKey:()=>fn,generateKeyPair:()=>V0,unmarshalSecp256k1PrivateKey:()=>P0,unmarshalSecp256k1PublicKey:()=>D0});var B0=(r,t,e)=>r&t^~r&e,A0=(r,t,e)=>r&t^r&e^t&e,S0=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Fe=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),$e=new Uint32Array(64),Bi=class extends gr{constructor(){super(64,32,8,!1),this.A=Fe[0]|0,this.B=Fe[1]|0,this.C=Fe[2]|0,this.D=Fe[3]|0,this.E=Fe[4]|0,this.F=Fe[5]|0,this.G=Fe[6]|0,this.H=Fe[7]|0}get(){let{A:t,B:e,C:n,D:s,E:o,F:i,G:a,H:c}=this;return[t,e,n,s,o,i,a,c]}set(t,e,n,s,o,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let f=0;f<16;f++,e+=4)$e[f]=t.getUint32(e,!1);for(let f=16;f<64;f++){let g=$e[f-15],m=$e[f-2],d=$t(g,7)^$t(g,18)^g>>>3,h=$t(m,17)^$t(m,19)^m>>>10;$e[f]=h+$e[f-7]+d+$e[f-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:l,H:u}=this;for(let f=0;f<64;f++){let g=$t(a,6)^$t(a,11)^$t(a,25),m=u+g+B0(a,c,l)+S0[f]+$e[f]|0,h=($t(n,2)^$t(n,13)^$t(n,22))+A0(n,s,o)|0;u=l,l=c,c=a,a=i+m|0,i=o,o=s,s=n,n=m+h|0}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,l=l+this.G|0,u=u+this.H|0,this.set(n,s,o,i,a,c,l,u)}roundClean(){$e.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Ir=In(()=>new Bi);function k0(r){let t=Gr(r);Vt(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("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("Expected endomorphism with beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:I0,hexToBytes:_0}=Tn,sr={Err:class extends Error{constructor(t=""){super(t)}},_parseInt(r){let{Err:t}=sr;if(r.length<2||r[0]!==2)throw new t("Invalid signature integer tag");let e=r[1],n=r.subarray(2,e+2);if(!e||n.length!==e)throw new t("Invalid signature integer: wrong length");if(n[0]&128)throw new t("Invalid signature integer: negative");if(n[0]===0&&!(n[1]&128))throw new t("Invalid signature integer: unnecessary leading zero");return{d:I0(n),l:r.subarray(e+2)}},toSig(r){let{Err:t}=sr,e=typeof r=="string"?_0(r):r;if(!Gt(e))throw new Error("ui8a expected");let n=e.length;if(n<2||e[0]!=48)throw new t("Invalid signature tag");if(e[1]!==n-2)throw new t("Invalid signature: incorrect length");let{d:s,l:o}=sr._parseInt(e.subarray(2)),{d:i,l:a}=sr._parseInt(o);if(a.length)throw new t("Invalid signature: left bytes after parsing");return{r:s,s:i}},hexFromSig(r){let t=l=>Number.parseInt(l[0],16)&8?"00"+l:l,e=l=>{let u=l.toString(16);return u.length&1?`0${u}`:u},n=t(e(r.s)),s=t(e(r.r)),o=n.length/2,i=s.length/2,a=e(o),c=e(i);return`30${e(i+o+4)}02${c}${s}02${a}${n}`}},Ie=BigInt(0),Ht=BigInt(1),gw=BigInt(2),Cl=BigInt(3),yw=BigInt(4);function N0(r){let t=k0(r),{Fp:e}=t,n=t.toBytes||((d,h,p)=>{let b=h.toAffine();return we(Uint8Array.from([4]),e.toBytes(b.x),e.toBytes(b.y))}),s=t.fromBytes||(d=>{let h=d.subarray(1),p=e.fromBytes(h.subarray(0,e.BYTES)),b=e.fromBytes(h.subarray(e.BYTES,2*e.BYTES));return{x:p,y:b}});function o(d){let{a:h,b:p}=t,b=e.sqr(d),v=e.mul(b,d);return e.add(e.add(v,e.mul(d,h)),p)}if(!e.eql(e.sqr(t.Gy),o(t.Gx)))throw new Error("bad generator point: equation left != right");function i(d){return typeof d=="bigint"&&Ie<d&&d<t.n}function a(d){if(!i(d))throw new Error("Expected valid bigint: 0 < bigint < curve.n")}function c(d){let{allowedPrivateKeyLengths:h,nByteLength:p,wrapPrivateKey:b,n:v}=t;if(h&&typeof d!="bigint"){if(Gt(d)&&(d=ge(d)),typeof d!="string"||!h.includes(d.length))throw new Error("Invalid key");d=d.padStart(p*2,"0")}let w;try{w=typeof d=="bigint"?d:ye(rt("private key",d,p))}catch{throw new Error(`private key must be ${p} bytes, hex or bigint, not ${typeof d}`)}return b&&(w=Z(w,v)),a(w),w}let l=new Map;function u(d){if(!(d instanceof f))throw new Error("ProjectivePoint expected")}class f{constructor(h,p,b){if(this.px=h,this.py=p,this.pz=b,h==null||!e.isValid(h))throw new Error("x required");if(p==null||!e.isValid(p))throw new Error("y required");if(b==null||!e.isValid(b))throw new Error("z required")}static fromAffine(h){let{x:p,y:b}=h||{};if(!h||!e.isValid(p)||!e.isValid(b))throw new Error("invalid affine point");if(h instanceof f)throw new Error("projective point not allowed");let v=w=>e.eql(w,e.ZERO);return v(p)&&v(b)?f.ZERO:new f(p,b,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let p=e.invertBatch(h.map(b=>b.pz));return h.map((b,v)=>b.toAffine(p[v])).map(f.fromAffine)}static fromHex(h){let p=f.fromAffine(s(rt("pointHex",h)));return p.assertValidity(),p}static fromPrivateKey(h){return f.BASE.multiply(c(h))}_setWindowSize(h){this._WINDOW_SIZE=h,l.delete(this)}assertValidity(){if(this.is0()){if(t.allowInfinityPoint&&!e.is0(this.py))return;throw new Error("bad point: ZERO")}let{x:h,y:p}=this.toAffine();if(!e.isValid(h)||!e.isValid(p))throw new Error("bad point: x or y not FE");let b=e.sqr(p),v=o(h);if(!e.eql(b,v))throw new Error("bad point: equation left != right");if(!this.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:h}=this.toAffine();if(e.isOdd)return!e.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){u(h);let{px:p,py:b,pz:v}=this,{px:w,py:A,pz:B}=h,S=e.eql(e.mul(p,B),e.mul(w,v)),N=e.eql(e.mul(b,B),e.mul(A,v));return S&&N}negate(){return new f(this.px,e.neg(this.py),this.pz)}double(){let{a:h,b:p}=t,b=e.mul(p,Cl),{px:v,py:w,pz:A}=this,B=e.ZERO,S=e.ZERO,N=e.ZERO,_=e.mul(v,v),V=e.mul(w,w),P=e.mul(A,A),L=e.mul(v,w);return L=e.add(L,L),N=e.mul(v,A),N=e.add(N,N),B=e.mul(h,N),S=e.mul(b,P),S=e.add(B,S),B=e.sub(V,S),S=e.add(V,S),S=e.mul(B,S),B=e.mul(L,B),N=e.mul(b,N),P=e.mul(h,P),L=e.sub(_,P),L=e.mul(h,L),L=e.add(L,N),N=e.add(_,_),_=e.add(N,_),_=e.add(_,P),_=e.mul(_,L),S=e.add(S,_),P=e.mul(w,A),P=e.add(P,P),_=e.mul(P,L),B=e.sub(B,_),N=e.mul(P,V),N=e.add(N,N),N=e.add(N,N),new f(B,S,N)}add(h){u(h);let{px:p,py:b,pz:v}=this,{px:w,py:A,pz:B}=h,S=e.ZERO,N=e.ZERO,_=e.ZERO,V=t.a,P=e.mul(t.b,Cl),L=e.mul(p,w),H=e.mul(b,A),O=e.mul(v,B),z=e.add(p,b),x=e.add(w,A);z=e.mul(z,x),x=e.add(L,H),z=e.sub(z,x),x=e.add(p,v);let I=e.add(w,B);return x=e.mul(x,I),I=e.add(L,O),x=e.sub(x,I),I=e.add(b,v),S=e.add(A,B),I=e.mul(I,S),S=e.add(H,O),I=e.sub(I,S),_=e.mul(V,x),S=e.mul(P,O),_=e.add(S,_),S=e.sub(H,_),_=e.add(H,_),N=e.mul(S,_),H=e.add(L,L),H=e.add(H,L),O=e.mul(V,O),x=e.mul(P,x),H=e.add(H,O),O=e.sub(L,O),O=e.mul(V,O),x=e.add(x,O),L=e.mul(H,x),N=e.add(N,L),L=e.mul(I,x),S=e.mul(z,S),S=e.sub(S,L),L=e.mul(z,H),_=e.mul(I,_),_=e.add(_,L),new f(S,N,_)}subtract(h){return this.add(h.negate())}is0(){return this.equals(f.ZERO)}wNAF(h){return m.wNAFCached(this,l,h,p=>{let b=e.invertBatch(p.map(v=>v.pz));return p.map((v,w)=>v.toAffine(b[w])).map(f.fromAffine)})}multiplyUnsafe(h){let p=f.ZERO;if(h===Ie)return p;if(a(h),h===Ht)return this;let{endo:b}=t;if(!b)return m.unsafeLadder(this,h);let{k1neg:v,k1:w,k2neg:A,k2:B}=b.splitScalar(h),S=p,N=p,_=this;for(;w>Ie||B>Ie;)w&Ht&&(S=S.add(_)),B&Ht&&(N=N.add(_)),_=_.double(),w>>=Ht,B>>=Ht;return v&&(S=S.negate()),A&&(N=N.negate()),N=new f(e.mul(N.px,b.beta),N.py,N.pz),S.add(N)}multiply(h){a(h);let p=h,b,v,{endo:w}=t;if(w){let{k1neg:A,k1:B,k2neg:S,k2:N}=w.splitScalar(p),{p:_,f:V}=this.wNAF(B),{p:P,f:L}=this.wNAF(N);_=m.constTimeNegate(A,_),P=m.constTimeNegate(S,P),P=new f(e.mul(P.px,w.beta),P.py,P.pz),b=_.add(P),v=V.add(L)}else{let{p:A,f:B}=this.wNAF(p);b=A,v=B}return f.normalizeZ([b,v])[0]}multiplyAndAddUnsafe(h,p,b){let v=f.BASE,w=(B,S)=>S===Ie||S===Ht||!B.equals(v)?B.multiplyUnsafe(S):B.multiply(S),A=w(this,p).add(w(h,b));return A.is0()?void 0:A}toAffine(h){let{px:p,py:b,pz:v}=this,w=this.is0();h==null&&(h=w?e.ONE:e.inv(v));let A=e.mul(p,h),B=e.mul(b,h),S=e.mul(v,h);if(w)return{x:e.ZERO,y:e.ZERO};if(!e.eql(S,e.ONE))throw new Error("invZ was invalid");return{x:A,y:B}}isTorsionFree(){let{h,isTorsionFree:p}=t;if(h===Ht)return!0;if(p)return p(f,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:p}=t;return h===Ht?this:p?p(f,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return this.assertValidity(),n(f,this,h)}toHex(h=!0){return ge(this.toRawBytes(h))}}f.BASE=new f(t.Gx,t.Gy,e.ONE),f.ZERO=new f(e.ZERO,e.ONE,e.ZERO);let g=t.nBitLength,m=Cn(f,t.endo?Math.ceil(g/2):g);return{CURVE:t,ProjectivePoint:f,normPrivateKeyToScalar:c,weierstrassEquation:o,isWithinCurveOrder:i}}function T0(r){let t=Gr(r);return Vt(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Ul(r){let t=T0(r),{Fp:e,n}=t,s=e.BYTES+1,o=2*e.BYTES+1;function i(x){return Ie<x&&x<e.ORDER}function a(x){return Z(x,n)}function c(x){return Ln(x,n)}let{ProjectivePoint:l,normPrivateKeyToScalar:u,weierstrassEquation:f,isWithinCurveOrder:g}=N0({...t,toBytes(x,I,C){let E=I.toAffine(),y=e.toBytes(E.x),k=we;return C?k(Uint8Array.from([I.hasEvenY()?2:3]),y):k(Uint8Array.from([4]),y,e.toBytes(E.y))},fromBytes(x){let I=x.length,C=x[0],E=x.subarray(1);if(I===s&&(C===2||C===3)){let y=ye(E);if(!i(y))throw new Error("Point is not on curve");let k=f(y),T=e.sqrt(k),R=(T&Ht)===Ht;return(C&1)===1!==R&&(T=e.neg(T)),{x:y,y:T}}else if(I===o&&C===4){let y=e.fromBytes(E.subarray(0,e.BYTES)),k=e.fromBytes(E.subarray(e.BYTES,2*e.BYTES));return{x:y,y:k}}else throw new Error(`Point of length ${I} was invalid. Expected ${s} compressed bytes or ${o} uncompressed bytes`)}}),m=x=>ge(Pe(x,t.nByteLength));function d(x){let I=n>>Ht;return x>I}function h(x){return d(x)?a(-x):x}let p=(x,I,C)=>ye(x.slice(I,C));class b{constructor(I,C,E){this.r=I,this.s=C,this.recovery=E,this.assertValidity()}static fromCompact(I){let C=t.nByteLength;return I=rt("compactSignature",I,C*2),new b(p(I,0,C),p(I,C,2*C))}static fromDER(I){let{r:C,s:E}=sr.toSig(rt("DER",I));return new b(C,E)}assertValidity(){if(!g(this.r))throw new Error("r must be 0 < r < CURVE.n");if(!g(this.s))throw new Error("s must be 0 < s < CURVE.n")}addRecoveryBit(I){return new b(this.r,this.s,I)}recoverPublicKey(I){let{r:C,s:E,recovery:y}=this,k=N(rt("msgHash",I));if(y==null||![0,1,2,3].includes(y))throw new Error("recovery id invalid");let T=y===2||y===3?C+t.n:C;if(T>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let R=y&1?"03":"02",M=l.fromHex(R+m(T)),K=c(T),W=a(-k*K),$=a(E*K),G=l.BASE.multiplyAndAddUnsafe(M,W,$);if(!G)throw new Error("point at infinify");return G.assertValidity(),G}hasHighS(){return d(this.s)}normalizeS(){return this.hasHighS()?new b(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return We(this.toDERHex())}toDERHex(){return sr.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return We(this.toCompactHex())}toCompactHex(){return m(this.r)+m(this.s)}}let v={isValidPrivateKey(x){try{return u(x),!0}catch{return!1}},normPrivateKeyToScalar:u,randomPrivateKey:()=>{let x=Ko(t.n);return wc(t.randomBytes(x),t.n)},precompute(x=8,I=l.BASE){return I._setWindowSize(x),I.multiply(BigInt(3)),I}};function w(x,I=!0){return l.fromPrivateKey(x).toRawBytes(I)}function A(x){let I=Gt(x),C=typeof x=="string",E=(I||C)&&x.length;return I?E===s||E===o:C?E===2*s||E===2*o:x instanceof l}function B(x,I,C=!0){if(A(x))throw new Error("first arg must be private key");if(!A(I))throw new Error("second arg must be public key");return l.fromHex(I).multiply(u(x)).toRawBytes(C)}let S=t.bits2int||function(x){let I=ye(x),C=x.length*8-t.nBitLength;return C>0?I>>BigInt(C):I},N=t.bits2int_modN||function(x){return a(S(x))},_=qr(t.nBitLength);function V(x){if(typeof x!="bigint")throw new Error("bigint expected");if(!(Ie<=x&&x<_))throw new Error(`bigint expected < 2^${t.nBitLength}`);return Pe(x,t.nByteLength)}function P(x,I,C=L){if(["recovered","canonical"].some(Q=>Q in C))throw new Error("sign() legacy options not supported");let{hash:E,randomBytes:y}=t,{lowS:k,prehash:T,extraEntropy:R}=C;k==null&&(k=!0),x=rt("msgHash",x),T&&(x=rt("prehashed msgHash",E(x)));let M=N(x),K=u(I),W=[V(K),V(M)];if(R!=null){let Q=R===!0?y(e.BYTES):R;W.push(rt("extraEntropy",Q))}let $=we(...W),G=M;function et(Q){let vt=S(Q);if(!g(vt))return;let Bt=c(vt),pt=l.BASE.multiply(vt).toAffine(),It=a(pt.x);if(It===Ie)return;let ue=a(Bt*a(G+It*K));if(ue===Ie)return;let qe=(pt.x===It?0:2)|Number(pt.y&Ht),Mr=ue;return k&&d(ue)&&(Mr=h(ue),qe^=1),new b(It,Mr,qe)}return{seed:$,k2sig:et}}let L={lowS:t.lowS,prehash:!1},H={lowS:t.lowS,prehash:!1};function O(x,I,C=L){let{seed:E,k2sig:y}=P(x,I,C),k=t;return Do(k.hash.outputLen,k.nByteLength,k.hmac)(E,y)}l.BASE._setWindowSize(8);function z(x,I,C,E=H){let y=x;if(I=rt("msgHash",I),C=rt("publicKey",C),"strict"in E)throw new Error("options.strict was renamed to lowS");let{lowS:k,prehash:T}=E,R,M;try{if(typeof y=="string"||Gt(y))try{R=b.fromDER(y)}catch(pt){if(!(pt instanceof sr.Err))throw pt;R=b.fromCompact(y)}else if(typeof y=="object"&&typeof y.r=="bigint"&&typeof y.s=="bigint"){let{r:pt,s:It}=y;R=new b(pt,It)}else throw new Error("PARSE");M=l.fromHex(C)}catch(pt){if(pt.message==="PARSE")throw new Error("signature must be Signature instance, Uint8Array or hex string");return!1}if(k&&R.hasHighS())return!1;T&&(I=t.hash(I));let{r:K,s:W}=R,$=N(I),G=c(W),et=a($*G),Q=a(K*G),vt=l.BASE.multiplyAndAddUnsafe(M,et,Q)?.toAffine();return vt?a(vt.x)===K:!1}return{CURVE:t,getPublicKey:w,getSharedSecret:B,sign:O,verify:z,ProjectivePoint:l,Signature:b,utils:v}}function L0(r){return{hash:r,hmac:(t,...e)=>Ve(r,t,kn(...e)),randomBytes:ze}}function Pl(r,t){let e=n=>Ul({...r,...L0(n)});return Object.freeze({...e(t),create:e})}var Ol=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Dl=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),R0=BigInt(1),Ai=BigInt(2),Vl=(r,t)=>(r+t/Ai)/t;function C0(r){let t=Ol,e=BigInt(3),n=BigInt(6),s=BigInt(11),o=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),l=r*r*r%t,u=l*l*r%t,f=nt(u,e,t)*u%t,g=nt(f,e,t)*u%t,m=nt(g,Ai,t)*l%t,d=nt(m,s,t)*m%t,h=nt(d,o,t)*d%t,p=nt(h,a,t)*h%t,b=nt(p,c,t)*p%t,v=nt(b,a,t)*h%t,w=nt(v,e,t)*u%t,A=nt(w,i,t)*d%t,B=nt(A,n,t)*l%t,S=nt(B,Ai,t);if(!Si.eql(Si.sqr(S),r))throw new Error("Cannot find square root");return S}var Si=Rn(Ol,void 0,void 0,{sqrt:C0}),Jt=Pl({a:BigInt(0),b:BigInt(7),Fp:Si,n:Dl,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Dl,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-R0*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),s=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),o=e,i=BigInt("0x100000000000000000000000000000000"),a=Vl(o*r,t),c=Vl(-n*r,t),l=Z(r-a*e-c*s,t),u=Z(-a*n-c*o,t),f=l>i,g=u>i;if(f&&(l=t-l),g&&(u=t-u),l>i||u>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:f,k1:l,k2neg:g,k2:u}}}},Ir),Sw=BigInt(0);var kw=Jt.ProjectivePoint;function Hl(){return Jt.utils.randomPrivateKey()}function Ml(r,t){let e=At.digest(t instanceof Uint8Array?t:t.subarray());if(Dt(e))return e.then(({digest:n})=>Jt.sign(n,r).toDERRawBytes()).catch(n=>{throw new F(String(n),"ERR_INVALID_INPUT")});try{return Jt.sign(e.digest,r).toDERRawBytes()}catch(n){throw new F(String(n),"ERR_INVALID_INPUT")}}function Kl(r,t,e){let n=At.digest(e instanceof Uint8Array?e:e.subarray());if(Dt(n))return n.then(({digest:s})=>Jt.verify(t,s,r)).catch(s=>{throw new F(String(s),"ERR_INVALID_INPUT")});try{return Jt.verify(t,n.digest,r)}catch(s){throw new F(String(s),"ERR_INVALID_INPUT")}}function Fl(r){return Jt.ProjectivePoint.fromHex(r).toRawBytes(!0)}function $l(r){try{Jt.getPublicKey(r,!0)}catch(t){throw new F(String(t),"ERR_INVALID_PRIVATE_KEY")}}function ki(r){try{Jt.ProjectivePoint.fromHex(r)}catch(t){throw new F(String(t),"ERR_INVALID_PUBLIC_KEY")}}function ql(r){try{return Jt.getPublicKey(r,!0)}catch(t){throw new F(String(t),"ERR_INVALID_PRIVATE_KEY")}}var fn=class{_key;constructor(t){ki(t),this._key=t}verify(t,e){return Kl(this._key,e,t)}marshal(){return Fl(this._key)}get bytes(){return ne.encode({Type:ot.Secp256k1,Data:this.marshal()}).subarray()}equals(t){return lt(this.bytes,t.bytes)}async hash(){let t=At.digest(this.bytes),e;return Dt(t)?{bytes:e}=await t:e=t.bytes,e}},hn=class{_key;_publicKey;constructor(t,e){this._key=t,this._publicKey=e??ql(t),$l(this._key),ki(this._publicKey)}sign(t){return Ml(this._key,t)}get public(){return new fn(this._publicKey)}marshal(){return this._key}get bytes(){return se.encode({Type:ot.Secp256k1,Data:this.marshal()}).subarray()}equals(t){return lt(this.bytes,t.bytes)}hash(){let t=At.digest(this.bytes);return Dt(t)?t.then(({bytes:e})=>e):t.bytes}async id(){let t=await this.public.hash();return q(t,"base58btc")}async export(t,e="libp2p-key"){if(e==="libp2p-key")return br(this.bytes,t);throw new F(`export format '${e}' is not supported`,"ERR_INVALID_EXPORT_FORMAT")}};function P0(r){return new hn(r)}function D0(r){return new fn(r)}async function V0(){let r=Hl();return new hn(r)}var or={rsa:vi,ed25519:hi,secp256k1:Ii};function Gl(r){let t=Object.keys(or).join(" / ");return new F(`invalid or unsupported key type ${r}. Must be ${t}`,"ERR_UNSUPPORTED_KEY_TYPE")}function jl(r){let t=ne.decode(r),e=t.Data??new Uint8Array;switch(t.Type){case ot.RSA:return or.rsa.unmarshalRsaPublicKey(e);case ot.Ed25519:return or.ed25519.unmarshalEd25519PublicKey(e);case ot.Secp256k1:return or.secp256k1.unmarshalSecp256k1PublicKey(e);default:throw Gl(t.Type??"unknown")}}async function _i(r){let t=se.decode(r),e=t.Data??new Uint8Array;switch(t.Type){case ot.RSA:return or.rsa.unmarshalRsaPrivateKey(e);case ot.Ed25519:return or.ed25519.unmarshalEd25519PrivateKey(e);case ot.Secp256k1:return or.secp256k1.unmarshalSecp256k1PrivateKey(e);default:throw Gl(t.Type??"RSA")}}var O0=Symbol.for("nodejs.util.inspect.custom"),zl=Object.values(ee).map(r=>r.decoder).reduce((r,t)=>r.or(t),ee.identity.decoder),Wl=114,Ni=36,Ti=37,dn=class{type;multihash;privateKey;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,this.privateKey=t.privateKey,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Da]=!0;toString(){return this.string==null&&(this.string=ct.encode(this.multihash.bytes).slice(1)),this.string}toCID(){return Ft.createV1(Wl,this.multihash)}toBytes(){return this.multihash.bytes}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return lt(this.multihash.bytes,t);if(typeof t=="string")return Li(t).equals(this);if(t?.multihash?.bytes!=null)return lt(this.multihash.bytes,t.multihash.bytes);throw new Error("not valid Id")}[O0](){return`PeerId(${this.toString()})`}},_r=class extends dn{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Nr=class extends dn{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.multihash.digest}},Tr=class extends dn{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.multihash.digest}};function Li(r,t){if(t=t??zl,r.charAt(0)==="1"||r.charAt(0)==="Q"){let e=Te(ct.decode(`z${r}`));return r.startsWith("12D")?new Nr({multihash:e}):r.startsWith("16U")?new Tr({multihash:e}):new _r({multihash:e})}return H0(zl.decode(r))}function H0(r){try{let t=Te(r);if(t.code===Le.code){if(t.digest.length===Ni)return new Nr({multihash:t});if(t.digest.length===Ti)return new Tr({multihash:t})}if(t.code===At.code)return new _r({multihash:t})}catch{return M0(Ft.decode(r))}throw new Error("Supplied PeerID CID is invalid")}function M0(r){if(r==null||r.multihash==null||r.version==null||r.version===1&&r.code!==Wl)throw new Error("Supplied PeerID CID is invalid");let t=r.multihash;if(t.code===At.code)return new _r({multihash:r.multihash});if(t.code===Le.code){if(t.digest.length===Ni)return new Nr({multihash:r.multihash});if(t.digest.length===Ti)return new Tr({multihash:r.multihash})}throw new Error("Supplied PeerID CID is invalid")}async function Ri(r,t){return r.length===Ni?new Nr({multihash:Kt(Le.code,r),privateKey:t}):r.length===Ti?new Tr({multihash:Kt(Le.code,r),privateKey:t}):new _r({multihash:await At.digest(r),publicKey:r,privateKey:t})}var Zl=Symbol.for("@achingbrain/uint8arraylist");function Yl(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 Ls(r){return!!r?.[Zl]}var at=class r{bufs;length;[Zl]=!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(Ls(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(Ls(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=Yl(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Yl(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(Ls(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 xt(n,s)}subarray(t,e){let{bufs:n,length:s}=this._subList(t,e);return n.length===1?n[0]:xt(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],a=s,c=a+i.byteLength;if(s=c,t>=c)continue;let l=t>=a&&t<c,u=e>a&&e<=c;if(l&&u){if(t===a&&e===c){n.push(i);break}let f=t-a;n.push(i.subarray(f,f+(e-t)));break}if(l){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(u){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Ls(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 a=i,c=this.byteLength-n.byteLength,l=n.byteLength-1,u;for(let f=e;f<=c;f+=u){u=0;for(let g=l;g>=0;g--){let m=this.get(f+g);if(n[g]!==m){u=Math.max(1,g-a[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=mt(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=yt(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=yt(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=yt(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=mt(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=yt(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=yt(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=yt(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=yt(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=yt(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(!lt(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}};function Rs(r){return r[Symbol.asyncIterator]!=null}var Cs=r=>{let t=ht(r),e=mt(t);return re(r,e),Cs.bytes=t,e};Cs.bytes=0;function Xl(r,t){t=t??{};let e=t.lengthEncoder??Cs;function*n(s){let o=e(s.byteLength);o instanceof Uint8Array?yield o:yield*o,s instanceof Uint8Array?yield s:yield*s}return Rs(r)?async function*(){for await(let s of r)yield*n(s)}():function*(){for(let s of r)yield*n(s)}()}Xl.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??Cs;return new at(e(r.byteLength),r)};var Lr=Pa(tu(),1);var F0=8,$0=1024*1024*4,ir;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(ir||(ir={}));var Ci=r=>{let t=Wt(r);return Ci.bytes=ht(t),t};Ci.bytes=0;function pn(r,t){let e=new at,n=ir.LENGTH,s=-1,o=t?.lengthDecoder??Ci,i=t?.maxLengthLength??F0,a=t?.maxDataLength??$0;function*c(){for(;e.byteLength>0;){if(n===ir.LENGTH)try{if(s=o(e),s<0)throw(0,Lr.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(s>a)throw(0,Lr.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let l=o.bytes;e.consume(l),t?.onLength!=null&&t.onLength(s),n=ir.DATA}catch(l){if(l instanceof RangeError){if(e.byteLength>i)throw(0,Lr.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw l}if(n===ir.DATA){if(e.byteLength<s)break;let l=e.sublist(0,s);e.consume(s),t?.onData!=null&&t.onData(l),yield l,n=ir.LENGTH}}}return Rs(r)?async function*(){for await(let l of r)e.append(l),yield*c();if(e.byteLength>0)throw(0,Lr.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}():function*(){for(let l of r)e.append(l),yield*c();if(e.byteLength>0)throw(0,Lr.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}pn.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:o,value:i}=await r.next(e);if(o===!0)return;i!=null&&(yield i)}catch(o){if(o.code==="ERR_UNDER_READ")return{done:!0,value:null};throw o}finally{e=1}}();return pn(n,{...t??{},onLength:o=>{e=o}})};function Qt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Us=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=e??"ABORT_ERR"}};async function eu(r,t,e){if(t==null)return r;if(t.aborted)return Promise.reject(new Us(e?.errorMessage,e?.errorCode));let n,s=new Us(e?.errorMessage,e?.errorCode);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 Ui=class{readNext;haveNext;ended;nextResult;constructor(){this.ended=!1,this.readNext=Qt(),this.haveNext=Qt()}[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=Qt(),t}async throw(t){return this.ended=!0,t!=null&&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");if(this.nextResult!=null&&(await this.readNext.promise,this.nextResult!=null))throw new Error("NeedNext promise resolved but nextResult was not consumed");t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Qt(),await eu(this.readNext.promise,e?.signal,e)}};function ru(){return new Ui}var Ps=class extends Error{code;constructor(t,e){super(t),this.code=e}},Pi=class extends Ps{type;constructor(t){super(t,"ABORT_ERR"),this.type="aborted"}};function nu(r,t){let e=ru();r.sink(e).catch(async i=>{await e.end(i)}),r.sink=async i=>{for await(let a of i)await e.push(a);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 at;return{read:async(i,a)=>{a?.signal?.throwIfAborted();let c,l=new Promise((u,f)=>{c=()=>{f(new Pi("Read aborted"))},a?.signal?.addEventListener("abort",c)});try{if(i==null){let{done:f,value:g}=await Promise.race([n.next(),l]);return f===!0?new at:g}for(;s.byteLength<i;){let{value:f,done:g}=await Promise.race([n.next(),l]);if(g===!0)throw new Ps("unexpected end of input","ERR_UNEXPECTED_EOF");s.append(f)}let u=s.sublist(0,i);return s.consume(i),u}finally{c!=null&&a?.signal?.removeEventListener("abort",c)}},write:async(i,a)=>{a?.signal?.throwIfAborted(),i instanceof Uint8Array?await e.push(i,a):await e.push(i.subarray(),a)},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 Ds=class extends Error{code;constructor(t,e){super(t),this.code=e}};function Di(r,t={}){let e=nu(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=ht(t.maxDataLength));let n=t?.lengthDecoder??Wt,s=t?.lengthEncoder??re;return{read:async i=>{let a=-1,c=new at;for(;;){c.append(await e.read(1,i));try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new Ds("message length length too long","ERR_MSG_LENGTH_TOO_LONG");if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new Ds("message length too long","ERR_MSG_DATA_TOO_LONG");return e.read(a,i)},write:async(i,a)=>{await e.write(new at(s(i.byteLength),i),a)},writeV:async(i,a)=>{let c=new at(...i.flatMap(l=>[s(l.byteLength),l]));await e.write(c,a)},unwrap:()=>e.unwrap()}}function Vi(){let r=Qt(),t=!1;return{sink:async e=>{if(t)throw new Error("already piped");t=!0,r.resolve(e)},source:async function*(){yield*await r.promise}()}}function su(){let r=Vi(),t=Vi();return[{source:r.source,sink:t.sink},{source:t.source,sink:r.sink}]}var Vs=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||t-1&t)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},Rr=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new Vs(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new Vs(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var Oi=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function Os(r={}){return q0(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function q0(r,t){t=t??{};let e=t.onEnd,n=new Rr,s,o,i,a=Qt(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((p,b)=>{o=v=>{o=null,n.push(v);try{p(r(n))}catch(w){b(w)}return s}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Qt()})}},l=p=>o!=null?o(p):(n.push(p),s),u=p=>(n=new Rr,o!=null?o({error:p}):(n.push({error:p}),s)),f=p=>{if(i)return s;if(t?.objectMode!==!0&&p?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:p})},g=p=>i?s:(i=!0,p!=null?u(p):l({done:!0})),m=()=>(n=new Rr,g(),{done:!0}),d=p=>(g(p),{done:!0});if(s={[Symbol.asyncIterator](){return this},next:c,return:m,throw:d,push:f,end:g,get readableLength(){return n.size},onEmpty:async p=>{let b=p?.signal;if(b?.throwIfAborted(),n.isEmpty())return;let v,w;b!=null&&(v=new Promise((A,B)=>{w=()=>{B(new Oi)},b.addEventListener("abort",w)}));try{await Promise.race([a.promise,v])}finally{w!=null&&b!=null&&b?.removeEventListener("abort",w)}}},e==null)return s;let h=s;return s={[Symbol.asyncIterator](){return this},next(){return h.next()},throw(p){return h.throw(p),e!=null&&(e(p),e=void 0),{done:!0}},return(){return h.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(p){return h.end(p),e!=null&&(e(p),e=void 0),s},get readableLength(){return h.readableLength},onEmpty:p=>h.onEmpty(p)},s}function G0(r){return r[Symbol.asyncIterator]!=null}function j0(...r){let t=[];for(let e of r)G0(e)||t.push(e);return t.length===r.length?function*(){for(let e of t)yield*e}():async function*(){let e=Os({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let s of n)e.push(s)})),e.end()}catch(n){e.end(n)}}),yield*e}()}var ou=j0;function iu(r,...t){if(r==null)throw new Error("Empty pipeline");if(Hi(r)){let n=r;r=()=>n.source}else if(cu(r)||au(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&Hi(e[e.length-1])&&(e[e.length-1]=e[e.length-1].sink),e.length>2)for(let n=1;n<e.length-1;n++)Hi(e[n])&&(e[n]=W0(e[n]));return z0(...e)}var z0=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},au=r=>r?.[Symbol.asyncIterator]!=null,cu=r=>r?.[Symbol.iterator]!=null,Hi=r=>r==null?!1:r.sink!=null&&r.source!=null,W0=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=Os({objectMode:!0});e.then(()=>{n.end()},i=>{n.end(i)});let s,o=r.source;if(au(o))s=async function*(){yield*o,n.end()};else if(cu(o))s=function*(){yield*o,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return ou(n,s())}return r.source};var Cr=!!globalThis.process?.env?.DUMP_SESSION_KEYS;var _e=r=>new Uint32Array(r.buffer,r.byteOffset,Math.floor(r.byteLength/4));function lu(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}var uu=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),Y0=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;if(!Y0)throw new Error("Non little-endian hardware is not supported");function Hs(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function Ms(r){if(typeof r=="string")r=Hs(r);else if(lu(r))r=r.slice();else throw new Error(`expected Uint8Array, got ${typeof r}`);return r}var Z0=r=>Object.prototype.toString.call(r)==="[object Object]"&&r.constructor===Object;function fu(r,t){if(t!==void 0&&(typeof t!="object"||!Z0(t)))throw new Error("options must be object or undefined");return Object.assign(r,t)}function ar(r,t){if(!lu(r))throw new Error("Uint8Array expected");if(typeof t=="number"&&r.length!==t)throw new Error(`Uint8Array length ${t} expected`)}function hu(r,t){if(r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}var Mi=(r,t)=>(Object.assign(t,r),t);function Ki(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let s=BigInt(32),o=BigInt(4294967295),i=Number(e>>s&o),a=Number(e&o),c=n?4:0,l=n?0:4;r.setUint32(t+c,i,n),r.setUint32(t+l,a,n)}function Ks(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`wrong positive integer: ${r}`)}function Fi(r){if(typeof r!="boolean")throw new Error(`boolean expected, not ${r}`)}function X0(r){return r!=null&&typeof r=="object"&&(r instanceof Uint8Array||r.constructor.name==="Uint8Array")}function Ur(r,...t){if(!X0(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${r.length}`)}function $i(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function du(r,t){Ur(r);let e=t.outputLen;if(r.length<e)throw new Error(`digestInto() expects output buffer of length at least ${e}`)}var kt=(r,t)=>r[t++]&255|(r[t++]&255)<<8,qi=class{constructor(t){this.blockLen=16,this.outputLen=16,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.pos=0,this.finished=!1,t=Ms(t),ar(t,32);let e=kt(t,0),n=kt(t,2),s=kt(t,4),o=kt(t,6),i=kt(t,8),a=kt(t,10),c=kt(t,12),l=kt(t,14);this.r[0]=e&8191,this.r[1]=(e>>>13|n<<3)&8191,this.r[2]=(n>>>10|s<<6)&7939,this.r[3]=(s>>>7|o<<9)&8191,this.r[4]=(o>>>4|i<<12)&255,this.r[5]=i>>>1&8190,this.r[6]=(i>>>14|a<<2)&8191,this.r[7]=(a>>>11|c<<5)&8065,this.r[8]=(c>>>8|l<<8)&8191,this.r[9]=l>>>5&127;for(let u=0;u<8;u++)this.pad[u]=kt(t,16+2*u)}process(t,e,n=!1){let s=n?0:2048,{h:o,r:i}=this,a=i[0],c=i[1],l=i[2],u=i[3],f=i[4],g=i[5],m=i[6],d=i[7],h=i[8],p=i[9],b=kt(t,e+0),v=kt(t,e+2),w=kt(t,e+4),A=kt(t,e+6),B=kt(t,e+8),S=kt(t,e+10),N=kt(t,e+12),_=kt(t,e+14),V=o[0]+(b&8191),P=o[1]+((b>>>13|v<<3)&8191),L=o[2]+((v>>>10|w<<6)&8191),H=o[3]+((w>>>7|A<<9)&8191),O=o[4]+((A>>>4|B<<12)&8191),z=o[5]+(B>>>1&8191),x=o[6]+((B>>>14|S<<2)&8191),I=o[7]+((S>>>11|N<<5)&8191),C=o[8]+((N>>>8|_<<8)&8191),E=o[9]+(_>>>5|s),y=0,k=y+V*a+P*(5*p)+L*(5*h)+H*(5*d)+O*(5*m);y=k>>>13,k&=8191,k+=z*(5*g)+x*(5*f)+I*(5*u)+C*(5*l)+E*(5*c),y+=k>>>13,k&=8191;let T=y+V*c+P*a+L*(5*p)+H*(5*h)+O*(5*d);y=T>>>13,T&=8191,T+=z*(5*m)+x*(5*g)+I*(5*f)+C*(5*u)+E*(5*l),y+=T>>>13,T&=8191;let R=y+V*l+P*c+L*a+H*(5*p)+O*(5*h);y=R>>>13,R&=8191,R+=z*(5*d)+x*(5*m)+I*(5*g)+C*(5*f)+E*(5*u),y+=R>>>13,R&=8191;let M=y+V*u+P*l+L*c+H*a+O*(5*p);y=M>>>13,M&=8191,M+=z*(5*h)+x*(5*d)+I*(5*m)+C*(5*g)+E*(5*f),y+=M>>>13,M&=8191;let K=y+V*f+P*u+L*l+H*c+O*a;y=K>>>13,K&=8191,K+=z*(5*p)+x*(5*h)+I*(5*d)+C*(5*m)+E*(5*g),y+=K>>>13,K&=8191;let W=y+V*g+P*f+L*u+H*l+O*c;y=W>>>13,W&=8191,W+=z*a+x*(5*p)+I*(5*h)+C*(5*d)+E*(5*m),y+=W>>>13,W&=8191;let $=y+V*m+P*g+L*f+H*u+O*l;y=$>>>13,$&=8191,$+=z*c+x*a+I*(5*p)+C*(5*h)+E*(5*d),y+=$>>>13,$&=8191;let G=y+V*d+P*m+L*g+H*f+O*u;y=G>>>13,G&=8191,G+=z*l+x*c+I*a+C*(5*p)+E*(5*h),y+=G>>>13,G&=8191;let et=y+V*h+P*d+L*m+H*g+O*f;y=et>>>13,et&=8191,et+=z*u+x*l+I*c+C*a+E*(5*p),y+=et>>>13,et&=8191;let Q=y+V*p+P*h+L*d+H*m+O*g;y=Q>>>13,Q&=8191,Q+=z*f+x*u+I*l+C*c+E*a,y+=Q>>>13,Q&=8191,y=(y<<2)+y|0,y=y+k|0,k=y&8191,y=y>>>13,T+=y,o[0]=k,o[1]=T,o[2]=R,o[3]=M,o[4]=K,o[5]=W,o[6]=$,o[7]=G,o[8]=et,o[9]=Q}finalize(){let{h:t,pad:e}=this,n=new Uint16Array(10),s=t[1]>>>13;t[1]&=8191;for(let a=2;a<10;a++)t[a]+=s,s=t[a]>>>13,t[a]&=8191;t[0]+=s*5,s=t[0]>>>13,t[0]&=8191,t[1]+=s,s=t[1]>>>13,t[1]&=8191,t[2]+=s,n[0]=t[0]+5,s=n[0]>>>13,n[0]&=8191;for(let a=1;a<10;a++)n[a]=t[a]+s,s=n[a]>>>13,n[a]&=8191;n[9]-=8192;let o=(s^1)-1;for(let a=0;a<10;a++)n[a]&=o;o=~o;for(let a=0;a<10;a++)t[a]=t[a]&o|n[a];t[0]=(t[0]|t[1]<<13)&65535,t[1]=(t[1]>>>3|t[2]<<10)&65535,t[2]=(t[2]>>>6|t[3]<<7)&65535,t[3]=(t[3]>>>9|t[4]<<4)&65535,t[4]=(t[4]>>>12|t[5]<<1|t[6]<<14)&65535,t[5]=(t[6]>>>2|t[7]<<11)&65535,t[6]=(t[7]>>>5|t[8]<<8)&65535,t[7]=(t[8]>>>8|t[9]<<5)&65535;let i=t[0]+e[0];t[0]=i&65535;for(let a=1;a<8;a++)i=(t[a]+e[a]|0)+(i>>>16)|0,t[a]=i&65535}update(t){$i(this);let{buffer:e,blockLen:n}=this;t=Ms(t);let s=t.length;for(let o=0;o<s;){let i=Math.min(n-this.pos,s-o);if(i===n){for(;n<=s-o;o+=n)this.process(t,o);continue}e.set(t.subarray(o,o+i),this.pos),this.pos+=i,o+=i,this.pos===n&&(this.process(e,0,!1),this.pos=0)}return this}destroy(){this.h.fill(0),this.r.fill(0),this.buffer.fill(0),this.pad.fill(0)}digestInto(t){$i(this),du(t,this),this.finished=!0;let{buffer:e,h:n}=this,{pos:s}=this;if(s){for(e[s++]=1;s<16;s++)e[s]=0;this.process(e,0,!0)}this.finalize();let o=0;for(let i=0;i<8;i++)t[o++]=n[i]>>>0,t[o++]=n[i]>>>8;return t}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}};function J0(r){let t=(n,s)=>r(s).update(Ms(n)).digest(),e=r(new Uint8Array(32));return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=n=>r(n),t}var pu=J0(r=>new qi(r));var Q0=Hs("expand 16-byte k"),tp=Hs("expand 32-byte k"),ep=_e(Q0),rp=_e(tp);function D(r,t){return r<<t|r>>>32-t}function Gi(r){return r.byteOffset%4===0}var Fs=64,np=16,yu=2**32-1,gu=new Uint32Array;function sp(r,t,e,n,s,o,i,a){let c=s.length,l=new Uint8Array(Fs),u=_e(l),f=Gi(s)&&Gi(o),g=f?_e(s):gu,m=f?_e(o):gu;for(let d=0;d<c;i++){if(r(t,e,n,u,i,a),i>=yu)throw new Error("arx: counter overflow");let h=Math.min(Fs,c-d);if(f&&h===Fs){let p=d/4;if(d%4!==0)throw new Error("arx: invalid block position");for(let b=0,v;b<np;b++)v=p+b,m[v]=g[v]^u[b];d+=Fs;continue}for(let p=0,b;p<h;p++)b=d+p,o[b]=s[b]^l[p];d+=h}}function ji(r,t){let{allowShortKeys:e,extendNonceFn:n,counterLength:s,counterRight:o,rounds:i}=fu({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t);if(typeof r!="function")throw new Error("core must be a function");return Ks(s),Ks(i),Fi(o),Fi(e),(a,c,l,u,f=0)=>{Ur(a),Ur(c),Ur(l);let g=l.length;if(u||(u=new Uint8Array(g)),Ur(u),Ks(f),f<0||f>=yu)throw new Error("arx: counter overflow");if(u.length<g)throw new Error(`arx: output (${u.length}) is shorter than data (${g})`);let m=[],d=a.length,h,p;if(d===32)h=a.slice(),m.push(h),p=rp;else if(d===16&&e)h=new Uint8Array(32),h.set(a),h.set(a,16),p=ep,m.push(h);else throw new Error(`arx: invalid 32-byte key, got length=${d}`);Gi(c)||(c=c.slice(),m.push(c));let b=_e(h);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(p,b,_e(c.subarray(0,16)),b),c=c.subarray(16)}let v=16-s;if(v!==c.length)throw new Error(`arx: nonce must be ${v} or 16 bytes`);if(v!==12){let A=new Uint8Array(12);A.set(c,o?0:12-c.length),c=A,m.push(c)}let w=_e(c);for(sp(r,p,b,w,l,u,f,i);m.length>0;)m.pop().fill(0);return u}}function bu(r,t,e,n,s,o=20){let i=r[0],a=r[1],c=r[2],l=r[3],u=t[0],f=t[1],g=t[2],m=t[3],d=t[4],h=t[5],p=t[6],b=t[7],v=s,w=e[0],A=e[1],B=e[2],S=i,N=a,_=c,V=l,P=u,L=f,H=g,O=m,z=d,x=h,I=p,C=b,E=v,y=w,k=A,T=B;for(let M=0;M<o;M+=2)S=S+P|0,E=D(E^S,16),z=z+E|0,P=D(P^z,12),S=S+P|0,E=D(E^S,8),z=z+E|0,P=D(P^z,7),N=N+L|0,y=D(y^N,16),x=x+y|0,L=D(L^x,12),N=N+L|0,y=D(y^N,8),x=x+y|0,L=D(L^x,7),_=_+H|0,k=D(k^_,16),I=I+k|0,H=D(H^I,12),_=_+H|0,k=D(k^_,8),I=I+k|0,H=D(H^I,7),V=V+O|0,T=D(T^V,16),C=C+T|0,O=D(O^C,12),V=V+O|0,T=D(T^V,8),C=C+T|0,O=D(O^C,7),S=S+L|0,T=D(T^S,16),I=I+T|0,L=D(L^I,12),S=S+L|0,T=D(T^S,8),I=I+T|0,L=D(L^I,7),N=N+H|0,E=D(E^N,16),C=C+E|0,H=D(H^C,12),N=N+H|0,E=D(E^N,8),C=C+E|0,H=D(H^C,7),_=_+O|0,y=D(y^_,16),z=z+y|0,O=D(O^z,12),_=_+O|0,y=D(y^_,8),z=z+y|0,O=D(O^z,7),V=V+P|0,k=D(k^V,16),x=x+k|0,P=D(P^x,12),V=V+P|0,k=D(k^V,8),x=x+k|0,P=D(P^x,7);let R=0;n[R++]=i+S|0,n[R++]=a+N|0,n[R++]=c+_|0,n[R++]=l+V|0,n[R++]=u+P|0,n[R++]=f+L|0,n[R++]=g+H|0,n[R++]=m+O|0,n[R++]=d+z|0,n[R++]=h+x|0,n[R++]=p+I|0,n[R++]=b+C|0,n[R++]=v+E|0,n[R++]=w+y|0,n[R++]=A+k|0,n[R++]=B+T|0}function op(r,t,e,n){let s=r[0],o=r[1],i=r[2],a=r[3],c=t[0],l=t[1],u=t[2],f=t[3],g=t[4],m=t[5],d=t[6],h=t[7],p=e[0],b=e[1],v=e[2],w=e[3];for(let B=0;B<20;B+=2)s=s+c|0,p=D(p^s,16),g=g+p|0,c=D(c^g,12),s=s+c|0,p=D(p^s,8),g=g+p|0,c=D(c^g,7),o=o+l|0,b=D(b^o,16),m=m+b|0,l=D(l^m,12),o=o+l|0,b=D(b^o,8),m=m+b|0,l=D(l^m,7),i=i+u|0,v=D(v^i,16),d=d+v|0,u=D(u^d,12),i=i+u|0,v=D(v^i,8),d=d+v|0,u=D(u^d,7),a=a+f|0,w=D(w^a,16),h=h+w|0,f=D(f^h,12),a=a+f|0,w=D(w^a,8),h=h+w|0,f=D(f^h,7),s=s+l|0,w=D(w^s,16),d=d+w|0,l=D(l^d,12),s=s+l|0,w=D(w^s,8),d=d+w|0,l=D(l^d,7),o=o+u|0,p=D(p^o,16),h=h+p|0,u=D(u^h,12),o=o+u|0,p=D(p^o,8),h=h+p|0,u=D(u^h,7),i=i+f|0,b=D(b^i,16),g=g+b|0,f=D(f^g,12),i=i+f|0,b=D(b^i,8),g=g+b|0,f=D(f^g,7),a=a+c|0,v=D(v^a,16),m=m+v|0,c=D(c^m,12),a=a+c|0,v=D(v^a,8),m=m+v|0,c=D(c^m,7);let A=0;n[A++]=s,n[A++]=o,n[A++]=i,n[A++]=a,n[A++]=p,n[A++]=b,n[A++]=v,n[A++]=w}var ip=ji(bu,{counterRight:!1,counterLength:4,allowShortKeys:!1}),ap=ji(bu,{counterRight:!1,counterLength:8,extendNonceFn:op,allowShortKeys:!1});var cp=new Uint8Array(16),mu=(r,t)=>{r.update(t);let e=t.length%16;e&&r.update(cp.subarray(e))},lp=new Uint8Array(32);function wu(r,t,e,n,s){let o=r(t,e,lp),i=pu.create(o);s&&mu(i,s),mu(i,n);let a=new Uint8Array(16),c=uu(a);Ki(c,0,BigInt(s?s.length:0),!0),Ki(c,8,BigInt(n.length),!0),i.update(a);let l=i.digest();return o.fill(0),l}var xu=r=>(t,e,n)=>(ar(t,32),ar(e),{encrypt:(o,i)=>{let a=o.length,c=a+16;i?ar(i,c):i=new Uint8Array(c),r(t,e,o,i,1);let l=wu(r,t,e,i.subarray(0,-16),n);return i.set(l,a),i},decrypt:(o,i)=>{let a=o.length,c=a-16;if(a<16)throw new Error("encrypted data must be at least 16 bytes");i?ar(i,c):i=new Uint8Array(c);let l=o.subarray(0,-16),u=o.subarray(-16),f=wu(r,t,e,l,n);if(!hu(u,f))throw new Error("invalid tag");return r(t,e,l,i,1),i}}),zi=Mi({blockSize:64,nonceLength:12,tagLength:16},xu(ip)),zb=Mi({blockSize:64,nonceLength:24,tagLength:16},xu(ap));function vu(r,t,e){return je(r),e===void 0&&(e=new Uint8Array(r.outputLen)),Ve(r,qt(e),qt(t))}var Wi=new Uint8Array([0]),Eu=new Uint8Array;function Bu(r,t,e,n=32){if(je(r),Re(n),n>255*r.outputLen)throw new Error("Length should be <= 255*HashLen");let s=Math.ceil(n/r.outputLen);e===void 0&&(e=Eu);let o=new Uint8Array(s*r.outputLen),i=Ve.create(r,t),a=i._cloneInto(),c=new Uint8Array(i.outputLen);for(let l=0;l<s;l++)Wi[0]=l+1,a.update(l===0?Eu:c).update(e).update(Wi).digestInto(c),o.set(c,r.outputLen*l),i._cloneInto(a);return i.destroy(),a.destroy(),c.fill(0),Wi.fill(0),o.slice(0,n)}var Yi={hashSHA256(r){return Ir(r.subarray())},getHKDF(r,t){let e=vu(Ir,t,r),s=Bu(Ir,e,void 0,96),o=s.subarray(0,32),i=s.subarray(32,64),a=s.subarray(64,96);return[o,i,a]},generateX25519KeyPair(){let r=Wr.utils.randomPrivateKey();return{publicKey:Wr.getPublicKey(r),privateKey:r}},generateX25519KeyPairFromSeed(r){return{publicKey:Wr.getPublicKey(r),privateKey:r}},generateX25519SharedKey(r,t){return Wr.getSharedSecret(r.subarray(),t.subarray())},chaCha20Poly1305Encrypt(r,t,e,n){return zi(n,t,e).encrypt(r.subarray())},chaCha20Poly1305Decrypt(r,t,e,n,s){return zi(n,t,e).decrypt(r.subarray(),s)}};var Au=Yi;function Su(r){return{generateKeypair:r.generateX25519KeyPair,dh:(t,e)=>r.generateX25519SharedKey(t.privateKey,e).subarray(0,32),encrypt:r.chaCha20Poly1305Encrypt,decrypt:r.chaCha20Poly1305Decrypt,hash:r.hashSHA256,hkdf:r.getHKDF}}var Pr=r=>{let t=mt(2);return t[0]=r>>8,t[1]=r,t};Pr.bytes=2;var gn=r=>{if(r.length<2)throw RangeError("Could not decode int16BE");if(r instanceof Uint8Array){let t=0;return t+=r[0]<<8,t+=r[1],t}return r.getUint16(0)};gn.bytes=2;function ku(r){return{xxHandshakeSuccesses:r.registerCounter("libp2p_noise_xxhandshake_successes_total",{help:"Total count of noise xxHandshakes successes_"}),xxHandshakeErrors:r.registerCounter("libp2p_noise_xxhandshake_error_total",{help:"Total count of noise xxHandshakes errors"}),encryptedPackets:r.registerCounter("libp2p_noise_encrypted_packets_total",{help:"Total count of noise encrypted packets successfully"}),decryptedPackets:r.registerCounter("libp2p_noise_decrypted_packets_total",{help:"Total count of noise decrypted packets"}),decryptErrors:r.registerCounter("libp2p_noise_decrypt_errors_total",{help:"Total count of noise decrypt errors"})}}function Zi(r,t){!t.enabled||!Cr||(r?(t(`LOCAL_STATIC_PUBLIC_KEY ${q(r.publicKey,"hex")}`),t(`LOCAL_STATIC_PRIVATE_KEY ${q(r.privateKey,"hex")}`)):t("Missing local static keys."))}function Xi(r,t){!t.enabled||!Cr||(r?(t(`LOCAL_PUBLIC_EPHEMERAL_KEY ${q(r.publicKey,"hex")}`),t(`LOCAL_PRIVATE_EPHEMERAL_KEY ${q(r.privateKey,"hex")}`)):t("Missing local ephemeral keys."))}function Iu(r,t){!t.enabled||!Cr||t(r?`REMOTE_STATIC_PUBLIC_KEY ${q(r.subarray(),"hex")}`:"Missing remote static public key.")}function Ji(r,t){!t.enabled||!Cr||t(r?`REMOTE_EPHEMERAL_PUBLIC_KEY ${q(r.subarray(),"hex")}`:"Missing remote ephemeral keys.")}function Qi(r,t,e){!e.enabled||!Cr||(e(`CIPHER_STATE_1 ${r.n.getUint64()} ${r.k&&q(r.k,"hex")}`),e(`CIPHER_STATE_2 ${t.n.getUint64()} ${t.k&&q(t.k,"hex")}`))}var $s=class r extends Error{code;constructor(t="Unexpected Peer"){super(t),this.code=r.code}static code="ERR_UNEXPECTED_PEER"},Dr=class r extends Error{code;constructor(t="Invalid crypto exchange"){super(t),this.code=r.code}static code="ERR_INVALID_CRYPTO_EXCHANGE"};var up=0,fp=4294967295,hp="Cipherstate has reached maximum n, a new handshake must be performed",qs=class{n;bytes;view;constructor(t=up){this.n=t,this.bytes=yt(12),this.view=new DataView(this.bytes.buffer,this.bytes.byteOffset,this.bytes.byteLength),this.view.setUint32(4,t,!0)}increment(){this.n++,this.view.setUint32(4,this.n,!0)}getBytes(){return this.bytes}getUint64(){return this.n}assertValue(){if(this.n>fp)throw new Error(hp)}};var cr=yt(0),Vr=class{k;n;crypto;constructor(t,e=void 0,n=0){this.crypto=t,this.k=e,this.n=new qs(n)}hasKey(){return!!this.k}encryptWithAd(t,e){if(!this.hasKey())return e;this.n.assertValue();let n=this.crypto.encrypt(e,this.n.getBytes(),t,this.k);return this.n.increment(),n}decryptWithAd(t,e,n){if(!this.hasKey())return e;this.n.assertValue();let s=this.crypto.decrypt(e,this.n.getBytes(),t,this.k,n);return this.n.increment(),s}},ta=class{cs;ck;h;crypto;constructor(t,e){this.crypto=t;let n=tt(e,"utf-8");this.h=dp(t,n),this.ck=this.h,this.cs=new Vr(t)}mixKey(t){let[e,n]=this.crypto.hkdf(this.ck,t);this.ck=e,this.cs=new Vr(this.crypto,n)}mixHash(t){this.h=this.crypto.hash(new at(this.h,t))}encryptAndHash(t){let e=this.cs.encryptWithAd(this.h,t);return this.mixHash(e),e}decryptAndHash(t){let e=this.cs.decryptWithAd(this.h,t);return this.mixHash(t),e}split(){let[t,e]=this.crypto.hkdf(this.ck,cr);return[new Vr(this.crypto,t),new Vr(this.crypto,e)]}},ea=class{ss;s;e;rs;re;initiator;crypto;constructor(t){let{crypto:e,protocolName:n,prologue:s,initiator:o,s:i,e:a,rs:c,re:l}=t;this.crypto=e,this.ss=new ta(e,n),this.ss.mixHash(s),this.initiator=o,this.s=i,this.e=a,this.rs=c,this.re=l}writeE(){if(this.e)throw new Error("ephemeral keypair is already set");let t=this.crypto.generateKeypair();return this.ss.mixHash(t.publicKey),this.e=t,t.publicKey}writeS(){if(!this.s)throw new Error("static keypair is not set");return this.ss.encryptAndHash(this.s.publicKey)}writeEE(){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.re))}writeES(){if(this.initiator){if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}else{if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}}writeSE(){if(this.initiator){if(!this.s)throw new Error("static keypair is not set");if(!this.re)throw new Error("remote ephemeral public key is not set");this.ss.mixKey(this.crypto.dh(this.s,this.re))}else{if(!this.e)throw new Error("ephemeral keypair is not set");if(!this.rs)throw new Error("remote static public key is not set");this.ss.mixKey(this.crypto.dh(this.e,this.rs))}}readE(t,e=0){if(this.re)throw new Error("remote ephemeral public key is already set");if(t.byteLength<e+32)throw new Error("message is not long enough");this.re=t.sublist(e,e+32),this.ss.mixHash(this.re)}readS(t,e=0){if(this.rs)throw new Error("remote static public key is already set");let n=32+(this.ss.cs.hasKey()?16:0);if(t.byteLength<e+n)throw new Error("message is not long enough");let s=t.sublist(e,e+n);return this.rs=this.ss.decryptAndHash(s),n}readEE(){this.writeEE()}readES(){this.writeES()}readSE(){this.writeSE()}},yn=class extends ea{writeMessageA(t){return new at(this.writeE(),this.ss.encryptAndHash(t))}writeMessageB(t){let e=this.writeE();this.writeEE();let n=this.writeS();return this.writeES(),new at(e,n,this.ss.encryptAndHash(t))}writeMessageC(t){let e=this.writeS();return this.writeSE(),new at(e,this.ss.encryptAndHash(t))}readMessageA(t){try{return this.readE(t),this.ss.decryptAndHash(t.sublist(32))}catch(e){throw new Dr(`handshake stage 0 validation fail: ${e.message}`)}}readMessageB(t){try{this.readE(t),this.readEE();let e=this.readS(t,32);return this.readES(),this.ss.decryptAndHash(t.sublist(32+e))}catch(e){throw new Dr(`handshake stage 1 validation fail: ${e.message}`)}}readMessageC(t){try{let e=this.readS(t);return this.readSE(),this.ss.decryptAndHash(t.sublist(e))}catch(e){throw new Dr(`handshake stage 2 validation fail: ${e.message}`)}}};function dp(r,t){if(t.length<=32){let e=yt(32);return e.set(t),e}else return r.hash(t)}var Gs;(function(r){let t;r.codec=()=>(t==null&&(t=tr((e,n,s={})=>{if(s.lengthDelimited!==!1&&n.fork(),e.webtransportCerthashes!=null)for(let o of e.webtransportCerthashes)n.uint32(10),n.bytes(o);s.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let s={webtransportCerthashes:[]},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let i=e.uint32();switch(i>>>3){case 1:{s.webtransportCerthashes.push(e.bytes());break}default:{e.skipType(i&7);break}}}return s})),t),r.encode=e=>Qe(e,r.codec()),r.decode=e=>Xe(e,r.codec())})(Gs||(Gs={}));var mn;(function(r){let t;r.codec=()=>(t==null&&(t=tr((e,n,s={})=>{s.lengthDelimited!==!1&&n.fork(),e.identityKey!=null&&e.identityKey.byteLength>0&&(n.uint32(10),n.bytes(e.identityKey)),e.identitySig!=null&&e.identitySig.byteLength>0&&(n.uint32(18),n.bytes(e.identitySig)),e.extensions!=null&&(n.uint32(34),Gs.codec().encode(e.extensions,n)),s.lengthDelimited!==!1&&n.ldelim()},(e,n)=>{let s={identityKey:yt(0),identitySig:yt(0)},o=n==null?e.len:e.pos+n;for(;e.pos<o;){let i=e.uint32();switch(i>>>3){case 1:{s.identityKey=e.bytes();break}case 2:{s.identitySig=e.bytes();break}case 4:{s.extensions=Gs.codec().decode(e,e.uint32());break}default:{e.skipType(i&7);break}}}return s})),t),r.encode=e=>Qe(e,r.codec()),r.decode=e=>Xe(e,r.codec())})(mn||(mn={}));async function ra(r,t,e){let n=await r.sign(_u(t));return mn.encode({identityKey:r.public.bytes,identitySig:n,extensions:e})}async function na(r,t,e){try{let n=mn.decode(r);if(e){let i=e.subarray();if(!lt(i,n.identityKey))throw new Error(`Payload identity key ${q(n.identityKey,"hex")} does not match expected remote identity key ${q(i,"hex")}`)}if(!t)throw new Error("Remote static does not exist");let s=_u(t);if(!await jl(n.identityKey).verify(s,n.identitySig))throw new Error("Invalid payload signature");return n}catch(n){throw new $s(n.message)}}function _u(r){let t=tt("noise-libp2p-static-key:");return r instanceof Uint8Array?xt([t,r],t.length+r.length):(r.prepend(t),r)}async function Nu(r){let{log:t,connection:e,crypto:n,privateKey:s,prologue:o,s:i,remoteIdentityKey:a,extensions:c}=r,l=await ra(s,i.publicKey,c),u=new yn({crypto:n,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!0,prologue:o,s:i});Zi(u.s,t),t.trace("Stage 0 - Initiator starting to send first message."),await e.write(u.writeMessageA(cr)),t.trace("Stage 0 - Initiator finished sending first message."),Xi(u.e,t),t.trace("Stage 1 - Initiator waiting to receive first message from responder...");let f=u.readMessageB(await e.read());t.trace("Stage 1 - Initiator received the message."),Ji(u.re,t),Iu(u.rs,t),t.trace("Initiator going to check remote's signature...");let g=await na(f,u.rs,a);t.trace("All good with the signature!"),t.trace("Stage 2 - Initiator sending third handshake message."),await e.write(u.writeMessageC(l)),t.trace("Stage 2 - Initiator sent message with signed payload.");let[m,d]=u.ss.split();return Qi(m,d,t),{payload:g,encrypt:h=>m.encryptWithAd(cr,h),decrypt:(h,p)=>d.decryptWithAd(cr,h,p)}}async function Tu(r){let{log:t,connection:e,crypto:n,privateKey:s,prologue:o,s:i,remoteIdentityKey:a,extensions:c}=r,l=await ra(s,i.publicKey,c),u=new yn({crypto:n,protocolName:"Noise_XX_25519_ChaChaPoly_SHA256",initiator:!1,prologue:o,s:i});Zi(u.s,t),t.trace("Stage 0 - Responder waiting to receive first message."),u.readMessageA(await e.read()),t.trace("Stage 0 - Responder received first message."),Ji(u.re,t),t.trace("Stage 1 - Responder sending out first message with signed payload and static key."),await e.write(u.writeMessageB(l)),t.trace("Stage 1 - Responder sent the second handshake message with signed payload."),Xi(u.e,t),t.trace("Stage 2 - Responder waiting for third handshake message...");let f=u.readMessageC(await e.read());t.trace("Stage 2 - Responder received the message, finished handshake.");let g=await na(f,u.rs,a),[m,d]=u.ss.split();return Qi(m,d,t),{payload:g,encrypt:h=>d.encryptWithAd(cr,h),decrypt:(h,p)=>m.decryptWithAd(cr,h,p)}}var Ru=16;function Cu(r,t){return async function*(e){for await(let n of e)for(let s=0;s<n.length;s+=65519){let o=s+65519;o>n.length&&(o=n.length);let i;n instanceof Uint8Array?i=r.encrypt(n.subarray(s,o)):i=r.encrypt(n.sublist(s,o)),t?.encryptedPackets.increment(),yield new at(Pr(i.byteLength),i)}}}function Uu(r,t){return async function*(e){for await(let n of e)for(let s=0;s<n.length;s+=65535){let o=s+65535;if(o>n.length&&(o=n.length),o-Ru<s)throw new Error("Invalid chunk");let i=n.sublist(s,o),a=n.subarray(s,o-Ru);try{let c=r.decrypt(i,a);t?.decryptedPackets.increment(),yield c}catch(c){throw t?.decryptErrors.increment(),c}}}}var js=class{protocol="/noise";crypto;prologue;staticKey;extensions;metrics;components;constructor(t,e={}){let{staticNoiseKey:n,extensions:s,crypto:o,prologueBytes:i}=e,{metrics:a}=t;this.components=t;let c=o??Au;this.crypto=Su(c),this.extensions=s,this.metrics=a?ku(a):void 0,n?this.staticKey=c.generateX25519KeyPairFromSeed(n):this.staticKey=c.generateX25519KeyPair(),this.prologue=i??yt(0)}async secureOutbound(t,e,n){let s=Di(e,{lengthEncoder:Pr,lengthDecoder:gn,maxDataLength:65535});if(!t.privateKey)throw new F("local peerId does not contain private key","ERR_NO_PRIVATE_KEY");let o=await _i(t.privateKey),i=n?.publicKey,a=await this.performHandshakeInitiator(s,o,i),c=await this.createSecureConnection(s,a);return e.source=c.source,e.sink=c.sink,{conn:e,remoteExtensions:a.payload.extensions,remotePeer:await Ri(a.payload.identityKey)}}async secureInbound(t,e,n){let s=Di(e,{lengthEncoder:Pr,lengthDecoder:gn,maxDataLength:65535});if(!t.privateKey)throw new F("local peerId does not contain private key","ERR_NO_PRIVATE_KEY");let o=await _i(t.privateKey),i=n?.publicKey,a=await this.performHandshakeResponder(s,o,i),c=await this.createSecureConnection(s,a);return e.source=c.source,e.sink=c.sink,{conn:e,remoteExtensions:a.payload.extensions,remotePeer:await Ri(a.payload.identityKey)}}async performHandshakeInitiator(t,e,n){let s;try{s=await Nu({connection:t,privateKey:e,remoteIdentityKey:n,log:this.components.logger.forComponent("libp2p:noise:xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:this.extensions}),this.metrics?.xxHandshakeSuccesses.increment()}catch(o){throw this.metrics?.xxHandshakeErrors.increment(),o}return s}async performHandshakeResponder(t,e,n){let s;try{s=await Tu({connection:t,privateKey:e,remoteIdentityKey:n,log:this.components.logger.forComponent("libp2p:noise:xxhandshake"),crypto:this.crypto,prologue:this.prologue,s:this.staticKey,extensions:this.extensions}),this.metrics?.xxHandshakeSuccesses.increment()}catch(o){throw this.metrics?.xxHandshakeErrors.increment(),o}return s}async createSecureConnection(t,e){let[n,s]=su(),o=t.unwrap();return await iu(n,Cu(e,this.metrics),o,i=>pn(i,{lengthDecoder:gn}),Uu(e,this.metrics),n),s}};function Pu(r={}){return t=>new js(t,r)}var zs=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,a=this.peekChar();if(a===void 0)return;let c=a==="0",l=2**(8*s)-1;for(;;){let u=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let g=Number.parseInt(f,t);if(!Number.isNaN(g))return g});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&&c&&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),[a]=t(o.subarray(0,i));return e.set(o.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Du=45,pp=15,Or=new zs;function sa(r){if(!(r.length>pp))return Or.new(r).parseWith(()=>Or.readIPv4Addr())}function oa(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Du))return Or.new(r).parseWith(()=>Or.readIPv6Addr())}function Ws(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Du))return Or.new(r).parseWith(()=>Or.readIPAddr())}var Nx=parseInt("0xFFFF",16),Tx=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Ys(r){return!!sa(r)}function Zs(r){return!!oa(r)}function Xs(r){return!!Ws(r)}var Hu=Ys,bp=Zs,ia=function(r){let t=0;if(r=r.toString().trim(),Hu(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(bp(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let o=Hu(e[n]),i;o&&(i=ia(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")},Mu=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 Hr={},aa={},Ep=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[777,-1,"memory"]];Ep.forEach(r=>{let t=vp(...r);aa[t.code]=t,Hr[t.name]=t});function vp(r,t,e,n,s){return{code:r,size:t,name:e,resolvable:!!n,path:!!s}}function J(r){if(typeof r=="number"){if(aa[r]!=null)return aa[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Hr[r]!=null)return Hr[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var d2=J("ip4"),p2=J("ip6"),g2=J("ipcidr");function la(r,t){switch(J(r).code){case 4:case 41:return Ap(t);case 42:return $u(t);case 6:case 273:case 33:case 132:return Gu(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return $u(t);case 421:return _p(t);case 444:return qu(t);case 445:return qu(t);case 466:return Ip(t);default:return q(t,"base16")}}function ua(r,t){switch(J(r).code){case 4:return Ku(t);case 41:return Ku(t);case 42:return Fu(t);case 6:case 273:case 33:case 132:return fa(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Fu(t);case 421:return Sp(t);case 444:return Np(t);case 445:return Tp(t);case 466:return kp(t);default:return tt(t,"base16")}}var ca=Object.values(ee).map(r=>r.decoder),Bp=function(){let r=ca[0].or(ca[1]);return ca.slice(2).forEach(t=>r=r.or(t)),r}();function Ku(r){if(!Xs(r))throw new Error("invalid ip address");return ia(r)}function Ap(r){let t=Mu(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!Xs(t))throw new Error("invalid ip address");return t}function fa(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Gu(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Fu(r){let t=tt(r),e=Uint8Array.from(re(t.length));return xt([e,t],e.length+t.length)}function $u(r){let t=Wt(r);if(r=r.slice(ht(t)),r.length!==t)throw new Error("inconsistent lengths");return q(r)}function Sp(r){let t;r[0]==="Q"||r[0]==="1"?t=Te(ct.decode(`z${r}`)).bytes:t=Ft.parse(r).multihash.bytes;let e=Uint8Array.from(re(t.length));return xt([e,t],e.length+t.length)}function kp(r){let t=Bp.decode(r),e=Uint8Array.from(re(t.length));return xt([e,t],e.length+t.length)}function Ip(r){let t=Wt(r),e=r.slice(ht(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+q(e,"base64url")}function _p(r){let t=Wt(r),e=r.slice(ht(t));if(e.length!==t)throw new Error("inconsistent lengths");return q(e,"base58btc")}function Np(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=de.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=fa(n);return xt([e,s],e.length+s.length)}function Tp(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=de.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=fa(n);return xt([e,s],e.length+s.length)}function qu(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=q(t,"base32"),s=Gu(e);return`${n}:${s}`}function ju(r){r=ha(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],a=J(i);if(a.size===0){t.push([a.code]),e.push([a.code]);continue}if(o++,o>=s.length)throw Wu("invalid address: "+r);if(a.path===!0){n=ha(s.slice(o).join("/")),t.push([a.code,ua(a.code,n)]),e.push([a.code,n]);break}let c=ua(a.code,s[o]);t.push([a.code,c]),e.push([a.code,la(a.code,c)])}return{string:zu(e),bytes:pa(t),tuples:t,stringTuples:e,path:n}}function da(r){let t=[],e=[],n=null,s=0;for(;s<r.length;){let o=Wt(r,s),i=ht(o),a=J(o),c=Lp(a,r.slice(s+i));if(c===0){t.push([o]),e.push([o]),s+=i;continue}let l=r.slice(s+i,s+i+c);if(s+=c+i,s>r.length)throw Wu("Invalid address Uint8Array: "+q(r,"base16"));t.push([o,l]);let u=la(o,l);if(e.push([o,u]),a.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:zu(e),tuples:t,stringTuples:e,path:n}}function zu(r){let t=[];return r.map(e=>{let n=J(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),ha(t.join("/"))}function pa(r){return xt(r.map(t=>{let e=J(t[0]),n=Uint8Array.from(re(e.code));return t.length>1&&t[1]!=null&&(n=xt([n,t[1]])),n}))}function Lp(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=Wt(t instanceof Uint8Array?t:Uint8Array.from(t));return e+ht(e)}}function ha(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}function Wu(r){return new Error("Error parsing address: "+r)}var Rp=Symbol.for("nodejs.util.inspect.custom"),ya=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Cp=[J("dns").code,J("dns4").code,J("dns6").code,J("dnsaddr").code],ga=class r{bytes;#e;#t;#r;#n;[ya]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=da(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=ju(t)}else if(Zu(t))e=da(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=J("tcp"),a=J("udp"),c=J("ip4"),l=J("ip6"),u=J("dns6"),f=J("ip6zone");for(let[m,d]of this.stringTuples())m===f.code&&(o=`%${d??""}`),Cp.includes(m)&&(e=i.name,s=443,n=`${d??""}${o}`,t=m===u.code?6:4),(m===i.code||m===a.code)&&(e=J(m).name,s=parseInt(d??"")),(m===c.code||m===l.code)&&(e=J(m).name,n=`${d??""}${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({},J(t)))}protoCodes(){return this.#t.map(([t])=>t)}protoNames(){return this.#t.map(([t])=>J(t).name)}tuples(){return this.#t}stringTuples(){return this.#r}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(pa(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,s])=>{n===Hr.p2p.code&&t.push([n,s]),n===Hr["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?q(ct.decode(`z${n}`),"base58btc"):q(Ft.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return lt(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(o=>o.resolvable);if(e==null)return[this];let n=Yu.get(e.name);if(n==null)throw new F(`no available resolver for ${e.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,t)).map(o=>new r(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)}[Rp](){return`Multiaddr(${this.#e})`}};var Yu=new Map;function Zu(r){return!!r?.[ya]}var Up=r=>r.toString().split("/").slice(1),bn=r=>({match:t=>t.length<1?!1:r(t[0])?t.slice(1):!1,pattern:"fn"}),ut=r=>({match:t=>bn(e=>e===r).match(t),pattern:r}),to=()=>({match:r=>bn(t=>typeof t=="string").match(r),pattern:"{string}"}),Xu=()=>({match:r=>bn(t=>!isNaN(parseInt(t))).match(r),pattern:"{number}"}),Mt=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{ct.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),Js=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{Ao.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),ce=r=>({match:t=>{let e=r.match(t);return e===!1?t:e},pattern:`optional(${r.pattern})`}),le=(...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(", ")})`}),ft=(...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 bt(...r){function t(s){let o=Up(s);for(let i of r){let a=i.match(o);if(a===!1)return!1;o=a}return o}function e(s){return t(s)!==!1}function n(s){let o=t(s);return o===!1?!1:o.length===0}return{matches:e,exactMatch:n}}var wa=ft(ut("dns4"),to()),ba=ft(ut("dns6"),to()),xa=ft(ut("dnsaddr"),to()),Ju=ft(ut("dns"),to()),G2=bt(wa),j2=bt(ba),z2=bt(xa),W2=bt(le(Ju,xa,wa,ba)),Qu=ft(ut("ip4"),bn(Ys)),tf=ft(ut("ip6"),bn(Zs)),ef=le(Qu,tf),xn=le(ef,Ju,wa,ba,xa),Y2=bt(xn),Z2=bt(Qu),X2=bt(tf),J2=bt(ef),eo=ft(xn,ut("tcp"),Xu()),En=ft(xn,ut("udp"),Xu()),Pp=le(eo,En),Q2=bt(eo),tE=bt(En),Ea=ft(En,ut("quic")),ro=ft(En,ut("quic-v1")),Dp=le(Ea,ro),eE=bt(Ea),rE=bt(ro),ma=le(xn,eo,En,Ea,ro),rf=le(ft(ma,ut("ws"),ce(Mt()))),nE=bt(rf),nf=le(ft(ma,ut("wss"),ce(Mt())),ft(ma,ut("tls"),ut("ws"),ce(Mt()))),sE=bt(nf),sf=ft(Pp,ut("webrtc-direct"),Js(),ce(Js()),ce(Mt())),oE=bt(sf),of=ft(ro,ut("webtransport"),Js(),Js(),ce(Mt())),no=bt(of),Qs=le(rf,nf,ft(eo,ce(Mt())),ft(Dp,ce(Mt())),ft(xn,ce(Mt())),sf,of,Mt()),iE=bt(Qs),Vp=ft(Qs,ut("p2p-circuit"),Mt()),aE=bt(Vp),Op=le(ft(Qs,ut("p2p-circuit"),ut("webrtc"),Mt()),ft(Qs,ut("webrtc"),ce(Mt())),ut("webrtc")),cE=bt(Op);async function va(r,t,e,n,s,o){let i=o.forComponent(`libp2p:webtransport:stream:${e}:${t}`),a=r.writable.getWriter(),c=r.readable.getReader();await a.ready;function l(){let d=n.findIndex(h=>h===m);d!==-1&&(n.splice(d,1),m.timeline.close=Date.now(),s?.(m))}let u=!1,f=!1;(async function(){let d=await a.closed.catch(h=>h);if(d!=null){let h=d.message;h.includes("aborted by the remote server")||h.includes("STOP_SENDING")||i.error(`WebTransport writer closed unexpectedly: streamId=${t} err=${d.message}`)}u=!0,u&&f&&l()})().catch(()=>{i.error("WebTransport failed to cleanup closed stream")}),async function(){let d=await c.closed.catch(h=>h);d!=null&&i.error(`WebTransport reader closed unexpectedly: streamId=${t} err=${d.message}`),f=!0,u&&f&&l()}().catch(()=>{i.error("WebTransport failed to cleanup closed stream")});let g=!1,m={id:t,status:"open",writeStatus:"ready",readStatus:"ready",abort(d){u||(a.abort(d).catch(h=>{i.error("could not abort stream",h)}),u=!0),f=!0,this.status="aborted",this.writeStatus="closed",this.readStatus="closed",this.timeline.reset=this.timeline.close=this.timeline.closeRead=this.timeline.closeWrite=Date.now(),l()},async close(d){this.status="closing",await Promise.all([m.closeRead(d),m.closeWrite(d)]),l(),this.status="closed",this.timeline.close=Date.now()},async closeRead(d){if(!f){this.readStatus="closing";try{await c.cancel()}catch(h){h.toString().includes("RESET_STREAM")===!0&&(u=!0)}this.timeline.closeRead=Date.now(),this.readStatus="closed",f=!0}u&&l()},async closeWrite(d){if(!u){u=!0,this.writeStatus="closing";try{await a.close()}catch(h){h.toString().includes("RESET_STREAM")===!0&&(f=!0)}this.timeline.closeWrite=Date.now(),this.writeStatus="closed"}f&&l()},direction:e,timeline:{open:Date.now()},metadata:{},source:async function*(){for(;;){let d=await c.read();if(d.done){f=!0,u&&l();return}yield new at(d.value)}}(),sink:async function(d){if(g)throw new Error("sink already called on stream");g=!0;try{this.writeStatus="writing";for await(let h of d)if(h instanceof Uint8Array)await a.write(h);else for(let p of h)await a.write(p);this.writeStatus="done"}finally{this.timeline.closeWrite=Date.now(),this.writeStatus="closed",await m.closeWrite()}},log:i};return m}function Ba(){return{source:{[Symbol.asyncIterator](){return{async next(){return new Promise(()=>{})}}}},sink:async r=>new Promise(()=>{})}}function af(r,t){return t.filter(n=>!!r.find(s=>lt(n,s))).length===t.length}var Hp=Object.values(ee).map(r=>r.decoder).reduce((r,t)=>r.or(t));function Mp(r){return te.decode(Hp.decode(r))}function cf(r){if(!no.matches(r))throw new F("Invalid multiaddr, was not a WebTransport address","ERR_INVALID_MULTIADDR");let t=r.stringTuples(),e=t.filter(([i,a])=>i===J("certhash").code).map(([i,a])=>Mp(a??"")),n=t.filter(([i,a])=>i===J("p2p").code).map(([i,a])=>Li(a??""))[0],s=r.toOptions(),o=s.host;return s.family===6&&o?.includes(":")&&(o=`[${o}]`),{url:`https://${o}:${s.port}`,certhashes:e,remotePeer:n}}var Aa=class{log;components;config;metrics;constructor(t,e={}){this.log=t.logger.forComponent("libp2p:webtransport"),this.components=t,this.config={maxInboundStreams:e.maxInboundStreams??1e3},t.metrics!=null&&(this.metrics={dialerEvents:t.metrics.registerCounterGroup("libp2p_webtransport_dialer_events_total",{label:"event",help:"Total count of WebTransport dialer events by type"})})}[Symbol.toStringTag]="@libp2p/webtransport";[Oa]=!0;async dial(t,e){e?.signal?.throwIfAborted(),this.log("dialing %s",t);let n=this.components.peerId;if(n===void 0)throw new Error("Need a local peerid");e=e??{};let{url:s,certhashes:o,remotePeer:i}=cf(t);if(i==null)throw new Error("Need a target peerid");if(o.length===0)throw new Error("Expected multiaddr to contain certhashes");let a,c,l=()=>{},u=!1,f=!1,g=!1;try{this.metrics?.dialerEvents.increment({pending:!0});let m=new WebTransport(`${s}/.well-known/libp2p-webtransport?type=noise`,{serverCertificateHashes:o.map(d=>({algorithm:"sha-256",value:d.digest}))});if(l=d=>{if(!u)try{this.metrics?.dialerEvents.increment({[d]:!0}),m.close()}catch(h){this.log.error("error closing wt session",h)}finally{c!=null&&(c.timeline.close=Date.now()),u=!0}},a=()=>{l(f?"noise_timeout":"ready_timeout")},e.signal?.addEventListener("abort",a,{once:!0}),await Promise.race([m.closed,m.ready]),f=!0,this.metrics?.dialerEvents.increment({ready:!0}),m.closed.catch(d=>{this.log.error("error on remote wt session close",d)}).finally(()=>{l("remote_close")}),!await this.authenticateWebTransport(m,n,i,o))throw new Error("Failed to authenticate webtransport");return this.metrics?.dialerEvents.increment({open:!0}),c={close:async()=>{this.log("Closing webtransport"),l("close")},abort:d=>{this.log("aborting webtransport due to passed err",d),l("abort")},remoteAddr:t,timeline:{open:Date.now()},log:this.components.logger.forComponent("libp2p:webtransport:maconn"),...Ba()},g=!0,await e.upgrader.upgradeOutbound(c,{skipEncryption:!0,muxerFactory:this.webtransportMuxer(m),skipProtection:!0})}catch(m){throw this.log.error("caught wt session err",m),l(g?"upgrade_error":f?"noise_error":"ready_error"),m}finally{a!=null&&e.signal?.removeEventListener("abort",a)}}async authenticateWebTransport(t,e,n,s){let o=await t.createBidirectionalStream(),i=o.writable.getWriter(),a=o.readable.getReader();await i.ready;let c={source:async function*(){for(;;){let f=await a.read();if(f.value!=null&&(yield f.value),f.done)break}}(),sink:async function(f){for await(let g of f)g instanceof Uint8Array?await i.write(g):await i.write(g.subarray())}},l=Pu()(this.components),{remoteExtensions:u}=await l.secureOutbound(e,c,n);if(i.close().catch(f=>{this.log.error(`Failed to close authentication stream writer: ${f.message}`)}),a.cancel().catch(f=>{this.log.error(`Failed to close authentication stream reader: ${f.message}`)}),!af(u?.webtransportCerthashes??[],s.map(f=>f.bytes)))throw new Error("Our certhashes are not a subset of the remote's reported certhashes");return!0}webtransportMuxer(t){let e=0,n=this.config,s=this;return{protocol:"webtransport",createStreamMuxer:o=>{typeof o=="function"&&(o={onIncomingStream:o});let i=[];return async function(){let c=t.incomingBidirectionalStreams.getReader();for(;;){let{done:l,value:u}=await c.read();if(l)break;if(i.length>=n.maxInboundStreams)u.writable.close().catch(f=>{s.log.error(`Failed to close inbound stream that crossed our maxInboundStream limit: ${f.message}`)}),u.readable.cancel().catch(f=>{s.log.error(`Failed to close inbound stream that crossed our maxInboundStream limit: ${f.message}`)});else{let f=await va(u,String(e++),"inbound",i,o?.onStreamEnd,s.components.logger);i.push(f),o?.onIncomingStream?.(f)}}}().catch(()=>{this.log.error("WebTransport failed to receive incoming stream")}),{protocol:"webtransport",streams:i,newStream:async c=>{let l=await t.createBidirectionalStream(),u=await va(l,String(e++),o?.direction??"outbound",i,o?.onStreamEnd,s.components.logger);return i.push(u),u},close:async c=>{this.log("Closing webtransport muxer"),await Promise.all(i.map(async l=>l.close(c)))},abort:c=>{this.log("Aborting webtransport muxer with err:",c);for(let l of i)l.abort(c)},...Ba()}}}}createListener(t){throw new Error("Webtransport servers are not supported in Node or the browser")}filter(t){return t.filter(no.exactMatch)}};function Kp(r={}){return t=>new Aa(t,r)}return vf(Fp);})();
|
|
8
8
|
//! TODO unclear how to add backpressure here?
|
|
9
9
|
/*! Bundled license information:
|
|
10
10
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/webtransport",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.18-0c7bbbb07",
|
|
4
4
|
"description": "JavaScript implementation of the WebTransport module that libp2p uses and that implements the interface-transport spec",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/transport-webtransport#readme",
|
|
@@ -50,20 +50,20 @@
|
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@chainsafe/libp2p-noise": "^15.0.0",
|
|
53
|
-
"@libp2p/interface": "1.1.
|
|
54
|
-
"@libp2p/peer-id": "4.0.
|
|
55
|
-
"@multiformats/multiaddr": "^12.1.
|
|
56
|
-
"@multiformats/multiaddr-matcher": "^1.1.
|
|
53
|
+
"@libp2p/interface": "1.1.3-0c7bbbb07",
|
|
54
|
+
"@libp2p/peer-id": "4.0.6-0c7bbbb07",
|
|
55
|
+
"@multiformats/multiaddr": "^12.1.14",
|
|
56
|
+
"@multiformats/multiaddr-matcher": "^1.1.2",
|
|
57
57
|
"it-stream-types": "^2.0.1",
|
|
58
|
-
"multiformats": "^13.0.
|
|
59
|
-
"uint8arraylist": "^2.4.
|
|
60
|
-
"uint8arrays": "^5.0.
|
|
58
|
+
"multiformats": "^13.0.1",
|
|
59
|
+
"uint8arraylist": "^2.4.8",
|
|
60
|
+
"uint8arrays": "^5.0.1"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@libp2p/logger": "4.0.
|
|
64
|
-
"@libp2p/peer-id-factory": "4.0.
|
|
65
|
-
"aegir": "^42.
|
|
66
|
-
"libp2p": "1.2.
|
|
63
|
+
"@libp2p/logger": "4.0.6-0c7bbbb07",
|
|
64
|
+
"@libp2p/peer-id-factory": "4.0.6-0c7bbbb07",
|
|
65
|
+
"aegir": "^42.2.3",
|
|
66
|
+
"libp2p": "1.2.2-0c7bbbb07",
|
|
67
67
|
"p-defer": "^4.0.0"
|
|
68
68
|
},
|
|
69
69
|
"browser": {
|