@libp2p/identify 4.1.18 → 4.1.19-67732803f

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PIdentify = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PIdentify=(()=>{var nf=Object.create;var un=Object.defineProperty;var of=Object.getOwnPropertyDescriptor;var sf=Object.getOwnPropertyNames;var af=Object.getPrototypeOf,cf=Object.prototype.hasOwnProperty;var _o=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(r){throw e=0,r}},Be=(t,e)=>{for(var r in e)un(t,r,{get:e[r],enumerable:!0})},na=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of sf(e))!cf.call(t,o)&&o!==r&&un(t,o,{get:()=>e[o],enumerable:!(n=of(e,o))||n.enumerable});return t};var uf=(t,e,r)=>(r=t!=null?nf(af(t)):{},na(e||!t||!t.__esModule?un(r,"default",{value:t,enumerable:!0}):r,t)),ff=t=>na(un({},"__esModule",{value:!0}),t);var ki=_o(gr=>{"use strict";Object.defineProperty(gr,"__esModule",{value:!0});gr.Netmask4Impl=void 0;gr.ip2long=yr;gr.long2ip=rt;function rt(t){let e=(t&-16777216)>>>24,r=(t&255<<16)>>>16,n=(t&65280)>>>8,o=t&255;return[e,r,n,o].join(".")}var _h=48,Bh=97,Th=65;function Ch(t){let e=0,r=10,n="9",o=0;t.length>1&&t[o]==="0"&&(t[o+1]==="x"||t[o+1]==="X"?(o+=2,r=16):"0"<=t[o+1]&&t[o+1]<="9"&&(o++,r=8,n="7"));let s=o;for(;o<t.length;){if("0"<=t[o]&&t[o]<=n)e=e*r+(t.charCodeAt(o)-_h)>>>0;else if(r===16)if("a"<=t[o]&&t[o]<="f")e=e*r+(10+t.charCodeAt(o)-Bh)>>>0;else if("A"<=t[o]&&t[o]<="F")e=e*r+(10+t.charCodeAt(o)-Th)>>>0;else break;else break;if(e>4294967295)throw new Error("too large");o++}if(o===s)throw new Error("empty octet");return[e,o]}function yr(t){let e=[];for(let r=0;r<=3&&t.length!==0;r++){if(r>0){if(t[0]!==".")throw new Error("Invalid IP");t=t.substring(1)}let[n,o]=Ch(t);t=t.substring(o),e.push(n)}if(t.length!==0)throw new Error("Invalid IP");switch(e.length){case 1:if(e[0]>4294967295)throw new Error("Invalid IP");return e[0]>>>0;case 2:if(e[0]>255||e[1]>16777215)throw new Error("Invalid IP");return(e[0]<<24|e[1])>>>0;case 3:if(e[0]>255||e[1]>255||e[2]>65535)throw new Error("Invalid IP");return(e[0]<<24|e[1]<<16|e[2])>>>0;case 4:if(e[0]>255||e[1]>255||e[2]>255||e[3]>255)throw new Error("Invalid IP");return(e[0]<<24|e[1]<<16|e[2]<<8|e[3])>>>0;default:throw new Error("Invalid IP")}}var Ni=class t{constructor(e,r){if(typeof e!="string")throw new Error("Missing `net' parameter");let n=r;if(!n){let o=e.split("/",2);e=o[0],n=o[1]}if(n||(n=32),typeof n=="string"&&n.indexOf(".")>-1){try{this.maskLong=yr(n)}catch{throw new Error("Invalid mask: "+n)}this.bitmask=NaN;for(let o=32;o>=0;o--)if(this.maskLong===4294967295<<32-o>>>0){this.bitmask=o;break}}else if(n||n===0)this.bitmask=parseInt(n,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(yr(e)&this.maskLong)>>>0}catch{throw new Error("Invalid net address: "+e)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+n);this.size=Math.pow(2,32-this.bitmask),this.base=rt(this.netLong),this.mask=rt(this.maskLong),this.hostmask=rt(~this.maskLong),this.first=this.bitmask<=30?rt(this.netLong+1):this.base,this.last=this.bitmask<=30?rt(this.netLong+this.size-2):rt(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?rt(this.netLong+this.size-1):void 0}contains(e){return typeof e=="string"&&(e.indexOf("/")>0||e.split(".").length!==4)&&(e=new t(e)),e instanceof t?this.contains(e.base)&&this.contains(e.broadcast||e.last):(yr(e)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(e=1){return new t(rt(this.netLong+this.size*e),this.mask)}forEach(e){let r=yr(this.first),n=yr(this.last),o=0;for(;r<=n;)e(rt(r),r,o),o++,r++}toString(){return this.base+"/"+this.bitmask}};gr.Netmask4Impl=Ni});var Cu=_o(br=>{"use strict";Object.defineProperty(br,"__esModule",{value:!0});br.Netmask6Impl=void 0;br.ip6bigint=Ui;br.bigint2ip6=Vt;var Oh=ki(),Fi=(1n<<128n)-1n;function Ui(t){let e=t.indexOf("%");e!==-1&&(t=t.substring(0,e));let r=t.lastIndexOf(":");if(r!==-1&&t.indexOf(".",r)!==-1){let n=t.substring(r+1),o=(0,Oh.ip2long)(n),s=t.substring(0,r+1)+"0:0";return Tu(s)&~0xffffffffn|BigInt(o)}return Tu(t)}function Tu(t){let e=t.indexOf("::"),r;if(e!==-1){let o=t.substring(0,e),s=t.substring(e+2),i=o===""?[]:o.split(":"),a=s===""?[]:s.split(":"),c=8-i.length-a.length;if(c<0)throw new Error("Invalid IPv6: too many groups");r=[...i,...Array(c).fill("0"),...a]}else r=t.split(":");if(r.length!==8)throw new Error("Invalid IPv6: expected 8 groups, got "+r.length);let n=0n;for(let o=0;o<8;o++){let s=r[o];if(s.length===0||s.length>4)throw new Error('Invalid IPv6: bad group "'+s+'"');let i=parseInt(s,16);if(isNaN(i)||i<0||i>65535)throw new Error('Invalid IPv6: bad group "'+s+'"');n=n<<16n|BigInt(i)}return n}function Vt(t){if(t<0n||t>Fi)throw new Error("Invalid IPv6 address value");let e=[];for(let i=0;i<8;i++)e.unshift(Number(t&0xffffn)),t>>=16n;let r=-1,n=0,o=-1,s=0;for(let i=0;i<8;i++)e[i]===0?o===-1?(o=i,s=1):s++:(s>n&&s>=2&&(r=o,n=s),o=-1,s=0);if(s>n&&s>=2&&(r=o,n=s),r!==-1&&r+n===8&&r>0)return e.slice(0,r).map(a=>a.toString(16)).join(":")+"::";if(r===0)return"::"+e.slice(n).map(a=>a.toString(16)).join(":");if(r>0){let i=e.slice(0,r).map(c=>c.toString(16)),a=e.slice(r+n).map(c=>c.toString(16));return i.join(":")+"::"+a.join(":")}else return e.map(i=>i.toString(16)).join(":")}var Mi=class t{constructor(e,r){if(typeof e!="string")throw new Error("Missing `net' parameter");let n=r;if(n==null){let o=e.indexOf("/");o!==-1?(n=parseInt(e.substring(o+1),10),e=e.substring(0,o)):n=128}if(isNaN(n)||n<0||n>128)throw new Error("Invalid mask for IPv6: "+n);this.bitmask=n,this.bitmask===0?this.maskBigint=0n:this.maskBigint=Fi>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=Ui(e)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+e)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=Vt(this.netBigint),this.mask=Vt(this.maskBigint),this.hostmask=Vt(~this.maskBigint&Fi),this.first=this.base,this.last=Vt(this.netBigint+(1n<<BigInt(128-this.bitmask))-1n),this.broadcast=void 0}contains(e){return typeof e=="string"&&e.indexOf("/")>0&&(e=new t(e)),e instanceof t?this.contains(e.base)&&this.contains(e.last):(Ui(e)&this.maskBigint)===this.netBigint}next(e=1){let r=1n<<BigInt(128-this.bitmask);return new t(Vt(this.netBigint+r*BigInt(e)),this.bitmask)}forEach(e){let r=this.netBigint,n=1n<<BigInt(128-this.bitmask),o=this.netBigint+n-1n,s=0;for(;r<=o;)e(Vt(r),Number(r),s),s++,r++}toString(){return this.base+"/"+this.bitmask}};br.Netmask6Impl=Mi});var Ou=_o(St=>{"use strict";Object.defineProperty(St,"__esModule",{value:!0});St.long2ip=St.ip2long=St.Netmask=void 0;var lo=ki();Object.defineProperty(St,"ip2long",{enumerable:!0,get:function(){return lo.ip2long}});Object.defineProperty(St,"long2ip",{enumerable:!0,get:function(){return lo.long2ip}});var Dh=Cu(),Ki=class t{constructor(e,r){if(typeof e!="string")throw new Error("Missing `net' parameter");(e.indexOf("/")!==-1?e.substring(0,e.indexOf("/")):e).indexOf(":")!==-1?this._impl=new Dh.Netmask6Impl(e,r):this._impl=new lo.Netmask4Impl(e,r),this.base=this._impl.base,this.mask=this._impl.mask,this.hostmask=this._impl.hostmask,this.bitmask=this._impl.bitmask,this.size=this._impl.size,this.first=this._impl.first,this.last=this._impl.last,this.broadcast=this._impl.broadcast,this._impl instanceof lo.Netmask4Impl?(this.maskLong=this._impl.maskLong,this.netLong=this._impl.netLong):(this.maskLong=0,this.netLong=0)}contains(e){return typeof e=="string"&&(e.indexOf("/")>0?e=new t(e):e.indexOf(":")===-1&&e.split(".").length!==4&&(e=new t(e))),e instanceof t?this.contains(e.base)&&this.contains(e.broadcast||e.last):this._impl.contains(e)}next(e=1){let r=this._impl.next(e);return new t(r.base,r.bitmask)}forEach(e){this._impl.forEach(e)}toString(){return this._impl.toString()}};St.Netmask=Ki});var gp={};Be(gp,{identify:()=>mp,identifyPush:()=>yp});var ae=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},It=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var fn=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var ln=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Me=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var _t=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var Bo=Symbol.for("@libp2p/peer-id");var dn=Symbol.for("@libp2p/service-capabilities");function pe(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}var Po={};Be(Po,{base58btc:()=>he,base58flickr:()=>bf});var Yp=new Uint8Array(0);function sa(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Ne(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return Bt(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return Bt(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function ia(t){let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}var oa=4096;function aa(t){let e=t.length;if(e<=oa)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.subarray(n,n+=oa));return r}function lf(t){return t?.buffer instanceof ArrayBuffer}function Bt(t){return lf(t)?t:t.slice()}function df(t,e,r){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var s=0;s<t.length;s++){var i=t.charAt(s),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=s,r){var c=i.toLowerCase().charCodeAt(0),u=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=s),u!==a&&(n[u]=s)}}var f=t.length,l=t.charAt(0),h=Math.log(f)/Math.log(256),p=Math.log(256)/Math.log(f);function x(v){if(v instanceof Uint8Array||(ArrayBuffer.isView(v)?v=new Uint8Array(v.buffer,v.byteOffset,v.byteLength):Array.isArray(v)&&(v=Uint8Array.from(v))),!(v instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(v.length===0)return"";for(var I=0,g=0,E=0,A=v.length;E!==A&&v[E]===0;)E++,I++;for(var R=(A-E)*p+1>>>0,U=new Uint8Array(R);E!==A;){for(var k=v[E],O=0,L=R-1;(k!==0||O<g)&&L!==-1;L--,O++)k+=256*U[L]>>>0,U[L]=k%f>>>0,k=k/f>>>0;if(k!==0)throw new Error("Non-zero carry");g=O,E++}for(var H=R-g;H!==R&&U[H]===0;)H++;for(var z=l.repeat(I);H<R;++H)z+=t.charAt(U[H]);return z}function m(v){if(typeof v!="string")throw new TypeError("Expected String");if(v.length===0)return new Uint8Array;var I=0;if(v[I]!==" "){for(var g=0,E=0;v[I]===l;)g++,I++;for(var A=(v.length-I)*h+1>>>0,R=new Uint8Array(A);v[I];){var U=n[v.charCodeAt(I)];if(U===255)return;for(var k=0,O=A-1;(U!==0||k<E)&&O!==-1;O--,k++)U+=f*R[O]>>>0,R[O]=U%256>>>0,U=U/256>>>0;if(U!==0)throw new Error("Non-zero carry");E=k,I++}if(v[I]!==" "){for(var L=A-E;L!==A&&R[L]===0;)L++;for(var H=new Uint8Array(g+(A-L)),z=g;L!==A;)H[z++]=R[L++];return H}}}function b(v){var I=m(v);if(I)return I;throw new Error(`Non-${e} character`)}return{encode:x,decodeUnsafe:m,decode:b}}var hf=df,pf=hf,ua=pf;var To=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Co=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return fa(this,e)}},Oo=class{decoders;constructor(e){this.decoders=e}or(e){return fa(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function fa(t,e){return new Oo({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Do=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new To(e,r,n),this.decoder=new Co(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Ht({name:t,prefix:e,encode:r,decode:n}){return new Do(t,e,r,n)}function lt({name:t,prefix:e,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:s}=ua(r,t,n);return Ht({prefix:e,name:t,encode:o,decode:i=>Ne(s(i))})}function mf(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function yf(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function gf(t,e){let r={};for(let n=0;n<t.length;++n)if(r[t[n]]=n,e){let o=t[n].toLowerCase(),s=t[n].toUpperCase();o!==t[n]&&(r[o]=n),s!==t[n]&&(r[s]=n)}return r}function fe({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let s=gf(n,o);return Ht({prefix:e,name:t,encode(i){return yf(i,n,r)},decode(i){return mf(i,s,r,t)}})}var he=lt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),bf=lt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Lo={};Be(Lo,{base32:()=>dt,base32hex:()=>vf,base32hexpad:()=>Af,base32hexpadupper:()=>If,base32hexupper:()=>Sf,base32pad:()=>xf,base32padupper:()=>Ef,base32upper:()=>wf,base32z:()=>_f});var dt=fe({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),wf=fe({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),xf=fe({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),Ef=fe({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),vf=fe({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),Sf=fe({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),Af=fe({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),If=fe({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),_f=fe({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ro={};Be(Ro,{base36:()=>Ar,base36upper:()=>Bf});var Ar=lt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),Bf=lt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Tf=ha,la=128,Cf=127,Of=~Cf,Df=Math.pow(2,31);function ha(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Df;)e[r++]=t&255|la,t/=128;for(;t&Of;)e[r++]=t&255|la,t>>>=7;return e[r]=t|0,ha.bytes=r-n+1,e}var Pf=No,Lf=128,da=127;function No(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw No.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&da)<<o:(i&da)*Math.pow(2,o),o+=7}while(i>=Lf);return No.bytes=s-n,r}var Rf=Math.pow(2,7),Nf=Math.pow(2,14),kf=Math.pow(2,21),Ff=Math.pow(2,28),Uf=Math.pow(2,35),Mf=Math.pow(2,42),Kf=Math.pow(2,49),qf=Math.pow(2,56),Vf=Math.pow(2,63),zf=function(t){return t<Rf?1:t<Nf?2:t<kf?3:t<Ff?4:t<Uf?5:t<Mf?6:t<Kf?7:t<qf?8:t<Vf?9:10},Hf={encode:Tf,decode:Pf,encodingLength:zf},$f=Hf,Ir=$f;function _r(t,e=0){let r=Ir.decode(t,e),n=Ir.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&t[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function $t(t,e,r=0){return Ir.encode(t,e,r),e}function jt(t){return Ir.encodingLength(t)}function We(t,e){let r=e.byteLength,n=jt(t),o=n+jt(r),s=new Uint8Array(o+r);return $t(t,s,0),$t(r,s,n),s.set(e,o),new Yt(t,r,e,s)}function Br(t){let e=Ne(t),[r,n]=_r(e),[o,s]=_r(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Yt(r,o,i,e)}function pa(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&sa(t.bytes,r.bytes)}}var Yt=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=Bt(n),this.bytes=Bt(o)}};function ma(t,e){let{bytes:r,version:n}=t;return n===0?Yf(r,ko(t),e??he.encoder):Wf(r,ko(t),e??dt.encoder)}var ya=new WeakMap;function ko(t){let e=ya.get(t);if(e==null){let r=new Map;return ya.set(t,r),r}return e}var be=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=Bt(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==Tr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Zf)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=We(e,r);return t.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&pa(e.multihash,n.multihash)}toString(e){return ma(this,e)}toJSON(){return{"/":ma(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new t(n,o,s,i??ga(n,o,s.bytes))}else if(r[Gf]===!0){let{version:n,multihash:o,code:s}=r,i=Br(o);return t.create(n,s,i)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==Tr)throw new Error(`Version 0 CID must use dag-pb (code: ${Tr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=ga(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Tr,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=Ne(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Yt(r.multihashCode,r.digestSize,s,o);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[l,h]=_r(e.subarray(r));return r+=h,l},o=n(),s=Tr;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,o]=jf(e,r),s=t.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ko(s).set(n,e),s}};function jf(t,e){switch(t[0]){case"Q":{let r=e??he;return[he.prefix,r.decode(`${he.prefix}${t}`)]}case he.prefix:{let r=e??he;return[he.prefix,r.decode(t)]}case dt.prefix:{let r=e??dt;return[dt.prefix,r.decode(t)]}case Ar.prefix:{let r=e??Ar;return[Ar.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function Yf(t,e,r){let{prefix:n}=r;if(n!==he.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o}function Wf(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let s=r.encode(t);return e.set(n,s),s}else return o}var Tr=112,Zf=18;function ga(t,e,r){let n=jt(t),o=n+jt(e),s=new Uint8Array(o+r.byteLength);return $t(t,s,0),$t(e,s,n),s.set(r,o),s}var Gf=Symbol.for("@ipld/js-cid/CID");var Fo={};Be(Fo,{identity:()=>Ke});var ba=0,Xf="identity",wa=Ne;function Qf(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return We(ba,wa(t))}var Ke={code:ba,name:Xf,encode:wa,digest:Qf};function Jf(t){return t.buffer instanceof ArrayBuffer}function _e(t){return Jf(t)?t:t.slice()}async function xa(t,e,r,n){let o=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,_e(e),_e(r.subarray()));return n?.signal?.throwIfAborted(),s}function we(t=0){return new Uint8Array(t)}function ve(t=0){return new Uint8Array(t)}function el(t){return t?.buffer instanceof ArrayBuffer}function Uo(t){if(el(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function Ze(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=ve(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return Uo(r)}var va=Symbol.for("@achingbrain/uint8arraylist");function Ea(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let o=r+n.byteLength;if(e<o)return{buf:n,index:e-r};r=o}throw new RangeError("index is out of bounds")}function pn(t){return!!t?.[va]}var me=class t{bufs;length;[va]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let r=0;for(let n of e)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(pn(n)){r+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(pn(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(e){let r=Ea(this.bufs,e);return r.buf[r.index]}set(e,r){let n=Ea(this.bufs,e);n.buf[n.index]=r}write(e,r=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(r+n,e[n]);else if(pn(e))for(let n=0;n<e.length;n++)this.set(r+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,r){let{bufs:n,length:o}=this._subList(e,r);return Ze(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:Ze(n,o)}sublist(e,r){let{bufs:n,length:o}=this._subList(e,r),s=new t;return s.length=o,s.bufs=n,s}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,e>=c)continue;let u=e>=a&&e<c,f=r>a&&r<=c;if(u&&f){if(e===a&&r===c){n.push(i);break}let l=e-a;n.push(i.subarray(l,l+(r-e)));break}if(u){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!pn(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let h=u;h>=0;h--){let p=this.get(l+h);if(n[h]!==p){f=Math.max(1,h-a[p]);break}}if(f===0)return l}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=ve(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let o=we(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let o=we(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let o=we(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=ve(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let o=we(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let o=we(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let o=we(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let o=we(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let o=we(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!pe(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var Mo={};Be(Mo,{base10:()=>tl});var tl=lt({prefix:"9",name:"base10",alphabet:"0123456789"});var Ko={};Be(Ko,{base16:()=>rl,base16upper:()=>nl});var rl=fe({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),nl=fe({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var qo={};Be(qo,{base2:()=>ol});var ol=fe({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Vo={};Be(Vo,{base256emoji:()=>ul});var Sa=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),sl=Sa.reduce((t,e,r)=>(t[r]=e,t),[]),il=Sa.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function al(t){return t.reduce((e,r)=>(e+=sl[r],e),"")}function cl(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=il[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var ul=Ht({prefix:"\u{1F680}",name:"base256emoji",encode:al,decode:cl});var Ho={};Be(Ho,{base64:()=>fl,base64pad:()=>ll,base64url:()=>zo,base64urlpad:()=>dl});var fl=fe({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ll=fe({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),zo=fe({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),dl=fe({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var $o={};Be($o,{base8:()=>hl});var hl=fe({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var jo={};Be(jo,{identity:()=>pl});var pl=Ht({prefix:"\0",name:"identity",encode:t=>aa(Ne(t)),decode:t=>Ne(ia(t))});var Dm=new TextEncoder,Pm=new TextDecoder;var Zo={};Be(Zo,{sha256:()=>Cr,sha512:()=>bl});var gl=20;function Wo({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new Yo(t,e,r,n,o)}var Yo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??gl,this.maxDigestLength=s}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?Aa(n,this.code,r?.truncate):n.then(o=>Aa(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Aa(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return We(e,t)}function _a(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Cr=Wo({name:"sha2-256",code:18,encode:_a("SHA-256")}),bl=Wo({name:"sha2-512",code:19,encode:_a("SHA-512")});var Or={...jo,...qo,...$o,...Mo,...Ko,...Lo,...Ro,...Po,...Ho,...Vo},Hm={...Zo,...Fo};function Ta(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Ba=Ta("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Go=Ta("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=ve(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),wl={utf8:Ba,"utf-8":Ba,hex:Or.base16,latin1:Go,ascii:Go,binary:Go,...Or},mn=wl;function q(t,e="utf8"){let r=mn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function j(t,e="utf8"){let r=mn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var xl=parseInt("11111",2),Xo=parseInt("10000000",2),El=parseInt("01111111",2),Ca={0:Dr,1:Dr,2:vl,3:Il,4:_l,5:Al,6:Sl,16:Dr,22:Dr,48:Dr};function nt(t,e={offset:0}){let r=t[e.offset]&xl;if(e.offset++,Ca[r]!=null)return Ca[r](t,e);throw new Error("No decoder for tag "+r)}function Pr(t,e){let r=0;if((t[e.offset]&Xo)===Xo){let n=t[e.offset]&El,o="0x";e.offset++;for(let s=0;s<n;s++,e.offset++){if(e.offset>=t.byteLength)throw new Error("invalid DER element length");o+=t[e.offset].toString(16).padStart(2,"0")}r=parseInt(o,16)}else r=t[e.offset],e.offset++;if(!Number.isInteger(r)||r<0||r>t.byteLength-e.offset)throw new Error("invalid DER element length");return r}function Dr(t,e){Pr(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=nt(t,e);if(n===null)break;r.push(n)}return r}function vl(t,e){let r=Pr(t,e),n=e.offset,o=e.offset+r,s=[];for(let i=n;i<o;i++)i===n&&t[i]===0||s.push(t[i]);return e.offset+=r,Uint8Array.from(s)}function Sl(t,e){let r=Pr(t,e),n=e.offset+r,o=t[e.offset];e.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;e.offset<n;){let u=t[e.offset];if(e.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function Al(t,e){return e.offset++,null}function Il(t,e){let r=Pr(t,e),n=t[e.offset];e.offset++;let o=t.subarray(e.offset,e.offset+r-1);if(e.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function _l(t,e){let r=Pr(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function Bl(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new me;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function Qo(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=Bl(t.byteLength);return new me(Uint8Array.from([e.byteLength|Xo]),e)}function Te(t){let e=new me,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new me(Uint8Array.from([2]),Qo(e),e)}function yn(t){let e=Uint8Array.from([0]),r=new me(e,t);return new me(Uint8Array.from([3]),Qo(r),r)}function ht(t,e=48){let r=new me;for(let n of t)r.append(n);return new me(Uint8Array.from([e]),Qo(r),r)}var Tl=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Cl=Uint8Array.from([6,5,43,129,4,0,34]),Ol=Uint8Array.from([6,5,43,129,4,0,35]),Dl={ext:!0,kty:"EC",crv:"P-256"},Pl={ext:!0,kty:"EC",crv:"P-384"},Ll={ext:!0,kty:"EC",crv:"P-521"},Jo=32,es=48,ts=66;function rs(t){let e=nt(t);return Oa(e)}function Oa(t){let e=t[1][1][0],r=1,n,o;if(e.byteLength===Jo*2+1)return n=j(e.subarray(r,r+Jo),"base64url"),o=j(e.subarray(r+Jo),"base64url"),new Wt({...Dl,key_ops:["verify"],x:n,y:o});if(e.byteLength===es*2+1)return n=j(e.subarray(r,r+es),"base64url"),o=j(e.subarray(r+es),"base64url"),new Wt({...Pl,key_ops:["verify"],x:n,y:o});if(e.byteLength===ts*2+1)return n=j(e.subarray(r,r+ts),"base64url"),o=j(e.subarray(r+ts),"base64url"),new Wt({...Ll,key_ops:["verify"],x:n,y:o});throw new ae(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Da(t){return ht([Te(Uint8Array.from([1])),ht([Rl(t.crv)],160),ht([yn(new me(Uint8Array.from([4]),q(t.x??"","base64url"),q(t.y??"","base64url")))],161)]).subarray()}function Rl(t){if(t==="P-256")return Tl;if(t==="P-384")return Cl;if(t==="P-521")return Ol;throw new ae(`Invalid curve ${t}`)}var Wt=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=Da(this.jwk)),this._raw}toMultihash(){return Ke.digest(Ge(this))}toCID(){return be.createV1(114,this.toMultihash())}toString(){return he.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:pe(this.raw,e.raw)}async verify(e,r,n){return xa(this.jwk,r,e,n)}};var gn=BigInt(4294967295),Pa=BigInt(32);function Nl(t,e=!1){return e?{h:Number(t&gn),l:Number(t>>Pa&gn)}:{h:Number(t>>Pa&gn)|0,l:Number(t&gn)|0}}function La(t,e=!1){let r=t.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=Nl(t[s],e);[n[s],o[s]]=[i,a]}return[n,o]}var kl=t=>t/2**32|0,Fl=t=>t>>>0;function Ra(t,e,r,n){let o=kl(r),s=Fl(r);t.setUint32(e,n?s:o,n),t.setUint32(e+4,n?o:s,n)}var ns=(t,e,r)=>t>>>r,os=(t,e,r)=>t<<32-r|e>>>r,Ct=(t,e,r)=>t>>>r|e<<32-r,Ot=(t,e,r)=>t<<32-r|e>>>r,Lr=(t,e,r)=>t<<64-r|e>>>r-32,Rr=(t,e,r)=>t>>>r-32|e<<64-r;function Xe(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var Na=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),ka=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,Fa=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),Ua=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,Ma=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Ka=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0;function bn(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var ss=t=>t?`"${t}" `:"";function ot(t,e=""){if(typeof t!="number")throw new TypeError(ss(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(ss(e)+"expected integer >= 0, got "+t);return t}function ke(t,e,r=""){if(bn(t)&&(e===void 0||t.length===e))return t;e!==void 0&&ot(e,"length");let n=bn(t),o=e!==void 0?` of length ${e}`:"",s=n?`length=${t.length}`:`type=${typeof t}`,i=ss(r)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}function wn(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(ot(t.outputLen),ot(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var Ml=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)},qa=(t,e)=>{Ml(t,e);let r=Object.getPrototypeOf(t);if(r!==Object.prototype&&r!==null)throw new TypeError(`"${e}" expected plain object`);if(Object.hasOwn(t,"__proto__"))throw new TypeError(`"${e}.__proto__" is not allowed`)};function Zt(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function xn(t,e){ke(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function Dt(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function En(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function qe(t,e){return t<<32-e|t>>>e}var za=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Kl=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function vn(t){if(ke(t),za)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=Kl[t[r]];return e}function Va(t){return t>=48&&t<=57?t-48:t>=65&&t<=70?t-55:t>=97&&t<=102?t-87:void 0}function Sn(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(za)try{return Uint8Array.fromHex(t)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let e=t.length,r=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=Va(t.charCodeAt(s)),a=Va(t.charCodeAt(s+1));if(i===void 0||a===void 0){let c=t[s]+t[s+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function is(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];ke(o),e+=o.length}let r=new Uint8Array(e);for(let n=0,o=0;n<t.length;n++){let s=t[n];r.set(s,o),o+=s.length}return r}function ql(t,e,r="opts"){return qa(t,"defaults"),e!==void 0&&qa(e,r),Object.assign(Object.create(null),t,e)}function as(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=ql({},e,"info");let r=(o,s)=>t(s).update(o).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>t(o),Object.assign(r,e),Object.freeze(r)}function Ha(t=32){ot(t,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(t>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);return e.getRandomValues(new Uint8Array(t))}var cs=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function $a(t,e,r){return t&e^~t&r}function ja(t,e,r){return t&e^t&r^e&r}var Nr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,o){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=En(this.buffer)}update(e){Zt(this),ke(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length,i=!1;for(let a=0;a<s;){let c=Math.min(o-this.pos,s-a);if(c===o){let u=En(e);for(;o<=s-a;a+=o)this.process(u,a);i=!0;continue}n.set(a===0&&c===s?e:e.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===o&&(this.process(r,0),this.pos=0,i=!0)}return this.length+=e.length,i&&this.roundClean(),this}digestInto(e){Zt(this),xn(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,r.fill(0,i),this.padOffset>o-i&&(this.process(n,0),r.fill(0)),Ra(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let a=e===r?n:En(e),c=this.outputLen,u=c/4,f=this.get();if(c%4||u>f.length)throw new Error("invalid outputLen");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],s)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneIntoMeta(e){let{buffer:r,length:n,finished:o,destroyed:s,pos:i}=this;return e.destroyed=s,e.finished=o,e.length=n,e.pos=i,i&&e.buffer.set(r),e}clone(){return this._cloneInto()}},Ya=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Wa=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Vl=Uint32Array.from([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]),pt=new Uint32Array(64),us=class extends Nr{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(e,r){super(64,e,8,!1),this.A=r[0]|0,this.B=r[1]|0,this.C=r[2]|0,this.D=r[3]|0,this.E=r[4]|0,this.F=r[5]|0,this.G=r[6]|0,this.H=r[7]|0}get(){let{A:e,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[e,r,n,o,s,i,a,c]}set(e,r,n,o,s,i,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let l=0;l<16;l++,r+=4)pt[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let h=pt[l-15],p=pt[l-2],x=qe(h,7)^qe(h,18)^h>>>3,m=qe(p,17)^qe(p,19)^p>>>10;pt[l]=m+pt[l-7]+x+pt[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let h=qe(a,6)^qe(a,11)^qe(a,25),p=f+h+$a(a,c,u)+Vl[l]+pt[l]|0,m=(qe(n,2)^qe(n,13)^qe(n,22))+ja(n,o,s)|0;f=u,u=c,c=a,a=i+p|0,i=s,s=o,o=n,n=p+m|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,o,s,i,a,c,u,f)}roundClean(){Dt(pt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Dt(this.buffer)}},fs=class extends us{constructor(){super(32,Ya)}};var Za=La(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),zl=Za[0],Hl=Za[1],mt=new Uint32Array(80),yt=new Uint32Array(80),ls=class extends Nr{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(e,r){super(128,e,16,!1),this.Ah=r[0]|0,this.Al=r[1]|0,this.Bh=r[2]|0,this.Bl=r[3]|0,this.Ch=r[4]|0,this.Cl=r[5]|0,this.Dh=r[6]|0,this.Dl=r[7]|0,this.Eh=r[8]|0,this.El=r[9]|0,this.Fh=r[10]|0,this.Fl=r[11]|0,this.Gh=r[12]|0,this.Gl=r[13]|0,this.Hh=r[14]|0,this.Hl=r[15]|0}get(){let{Ah:e,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:h,Gh:p,Gl:x,Hh:m,Hl:b}=this;return[e,r,n,o,s,i,a,c,u,f,l,h,p,x,m,b]}set(e,r,n,o,s,i,a,c,u,f,l,h,p,x,m,b){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=h|0,this.Gh=p|0,this.Gl=x|0,this.Hh=m|0,this.Hl=b|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let g=0;g<16;g++,r+=4)mt[g]=e.getUint32(r),yt[g]=e.getUint32(r+=4);for(let g=16;g<80;g++){let E=mt[g-15]|0,A=yt[g-15]|0,R=Ct(E,A,1)^Ct(E,A,8)^ns(E,A,7),U=Ot(E,A,1)^Ot(E,A,8)^os(E,A,7),k=mt[g-2]|0,O=yt[g-2]|0,L=Ct(k,O,19)^Lr(k,O,61)^ns(k,O,6),H=Ot(k,O,19)^Rr(k,O,61)^os(k,O,6),z=Fa(U,H,yt[g-7],yt[g-16]),J=Ua(z,R,L,mt[g-7],mt[g-16]);mt[g]=J|0,yt[g]=z|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:h,Fh:p,Fl:x,Gh:m,Gl:b,Hh:v,Hl:I}=this;for(let g=0;g<80;g++){let E=Ct(l,h,14)^Ct(l,h,18)^Lr(l,h,41),A=Ot(l,h,14)^Ot(l,h,18)^Rr(l,h,41),R=l&p^~l&m,U=h&x^~h&b,k=Ma(I,A,U,Hl[g],yt[g]),O=Ka(k,v,E,R,zl[g],mt[g]),L=k|0,H=Ct(n,o,28)^Lr(n,o,34)^Lr(n,o,39),z=Ot(n,o,28)^Rr(n,o,34)^Rr(n,o,39),J=n&s^n&a^s&a,B=o&i^o&c^i&c;v=m|0,I=b|0,m=p|0,b=x|0,p=l|0,x=h|0,{h:l,l:h}=Xe(u|0,f|0,O|0,L|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let M=Na(L,z,B);n=ka(M,O,H,J),o=M|0}({h:n,l:o}=Xe(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Xe(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Xe(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Xe(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:h}=Xe(this.Eh|0,this.El|0,l|0,h|0),{h:p,l:x}=Xe(this.Fh|0,this.Fl|0,p|0,x|0),{h:m,l:b}=Xe(this.Gh|0,this.Gl|0,m|0,b|0),{h:v,l:I}=Xe(this.Hh|0,this.Hl|0,v|0,I|0),this.set(n,o,s,i,a,c,u,f,l,h,p,x,m,b,v,I)}roundClean(){Dt(mt,yt)}destroy(){this.destroyed=!0,Dt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},ds=class extends ls{constructor(){super(64,Wa)}};var Gt=as(()=>new fs,cs(1));var hs=as(()=>new ds,cs(3));function In(t,e,r=()=>{}){if(!Array.isArray(t))throw new TypeError(`"${e}" expected array, got type=${typeof t}`);for(let n=0;n<t.length;n++)r(t[n],`${e}[${n}]`);return t}var G=(t,e,r)=>ke(t,e,r),ps=ot;function Xa(t,e=""){if(typeof t!="string"){let r=e&&`"${e}" `;throw new TypeError(r+"expected string, got type="+typeof t)}return t}function gt(t,e="object"){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof t}`);return t}function Pt(t,e){if(typeof t!="function")throw new TypeError(`"${e}" is invalid: expected function, got ${typeof t}`);return t}var kr=vn,Fe=(...t)=>is(...t),Xt=t=>Sn(t),wt=bn,Lt=t=>Ha(t),An=BigInt(0),Ga=BigInt(1),$l=t=>t?`"${t}" `:"";function Ce(t,e=""){if(typeof t!="boolean")throw new TypeError($l(e)+"expected boolean, got type="+typeof t);return t}function _n(t){if(typeof t=="bigint"){if(!bt(t))throw new RangeError("positive bigint expected, got "+t)}else ps(t);return t}function st(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(r+"expected number, got type="+typeof t)}if(!Number.isSafeInteger(t)){let r=e&&`"${e}" `;throw new RangeError(r+"expected safe integer, got "+t)}}function Fr(t){let e=_n(t).toString(16);return e.length&1?"0"+e:e}function Qa(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?An:BigInt("0x"+t)}function Qe(t){return Qa(vn(t))}function Rt(t){return Qa(vn(Ur(ke(t)).reverse()))}function Bn(t,e){if(ot(e),e===0)throw new Error("zero output length is invalid");t=_n(t);let r=e*2,n=t.toString(16);if(n.length>r)throw new RangeError("number is too large");return Sn(n.padStart(r,"0"))}function ms(t,e){return Bn(t,e).reverse()}function Ur(t){return Uint8Array.from(G(t))}function bt(t){return typeof t=="bigint"&&An<=t}function ys(t,e,r){return bt(t)&&bt(e)&&bt(r)&&e<=t&&t<r}function Qt(t,e,r,n){if(!ys(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Jt(t){if(t<An)throw new Error("expected non-negative bigint, got "+t);return t===An?0:t.toString(2).length}var Mr=t=>(st(t,"n"),(Ga<<BigInt(t))-Ga);function Ja(t,e,r){if(ot(t,"hashLen"),ot(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=b=>new Uint8Array(b),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(t),u=n(t),f=0,l=()=>{c.fill(1),u.fill(0),f=0},h=(...b)=>r(u,Fe(c,...b)),p=(b=o)=>{u=h(s,b),c=h(),b.length!==0&&(u=h(i,b),c=h())},x=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let b=0,v=[];for(;b<e;){c=h();let I=c.slice();v.push(I),b+=c.length}return Fe(...v)};return(b,v)=>{l(),p(b);let I;for(;(I=v(x()))===void 0;)p();return l(),I}}function Oe(t,e={},r={},n="object"){gt(t,n),gt(e,"fields"),gt(r,"optFields");function o(i,a,c){let u=n==="object"?`param "${String(i)}"`:`"${n}.${String(i)}"`,f=t[i];if(!Object.hasOwn(t,i)&&(c?f!==void 0:a!=="function"))throw new TypeError(`${u} is invalid: expected own property`);if(c&&f===void 0)return;let l=typeof f;if(l!==a||f===null)throw new TypeError(`${u} is invalid: expected ${a}, got ${l}`)}let s=(i,a)=>Object.entries(i).forEach(([c,u])=>o(c,u,a));s(e,!1),s(r,!0)}var ye=BigInt(0),X=BigInt(1),xt=BigInt(2),rc=BigInt(3),gs=BigInt(4),nc=BigInt(5),jl=BigInt(7),oc=BigInt(8),Yl=BigInt(9),Wl=BigInt(15),sc=BigInt(16),Zl=BigInt("0x10000000000000000");function ce(t,e){if(e<=ye)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=ye?r:e+r}function ic(t,e,r){if(r<=X)throw new Error("pow: expected modulus > 1, got "+r);if(typeof e!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof e);if(e<ye)throw new Error("invalid exponent, negatives unsupported");if(e===ye)return X;if(e===X)return t;let n=t%r;if(n<ye&&(n+=r),e<Zl){let a=X;for(;e>ye;)e&X&&(a=a*n%r),n=n*n%r,e>>=X;return a}let o=[];for(;e>ye;)o.push(Number(e&Wl)),e>>=gs;let s=new Array(16);s[0]=X,s[1]=n;for(let a=2;a<16;a++)s[a]=s[a-1]*n%r;let i=s[o[o.length-1]];for(let a=o.length-2;a>=0;a--){i=i*i%r,i=i*i%r,i=i*i%r,i=i*i%r;let c=o[a];c!==0&&(i=i*s[c]%r)}return i}function se(t,e,r){if(r<=X)throw new Error("pow2: expected modulus > 1, got "+r);if(e<ye)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >ye;)n*=n,n%=r;return n}function ec(t,e){if(t===ye)throw new Error("invert: expected non-zero number");if(e<=X)throw new Error("invert: expected modulus > 1, got "+e);let r=ce(t,e),n=e,o=ye,s=X;for(;r!==ye;){let a=n/r,c=n-r*a,u=o-s*a;n=r,r=c,o=s,s=u}if(n!==X)throw new Error("invert: does not exist");return ce(o,e)}function ac(t,e){if(e<=X)throw new Error("invertCt: expected prime modulus > 1, got "+e);let r=ce(t,e);if(r===ye)throw new Error("invertCt: expected non-zero number");let n=ic(r,e-xt,e);if(ce(r*n,e)!==X)throw new Error("invertCt: does not exist");return n}function bs(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function ws(t,e){if((t&X)===ye)throw new Error(e+": expected odd modulus, got "+t)}function cc(t,e){let r=t,n=(r.ORDER+X)/gs,o=r.pow(e,n);return bs(r,o,e),o}function Gl(t,e){let r=t,n=(r.ORDER-nc)/oc,o=r.mul(e,xt),s=r.pow(o,n),i=r.mul(e,s),a=r.mul(r.mul(i,xt),s),c=r.mul(i,r.sub(a,r.ONE));return bs(r,c,e),c}function Xl(t){let e=tr(t),r=uc(t),n=r(e,e.neg(e.ONE)),o=r(e,n),s=r(e,e.neg(n)),i=(t+jl)/sc;return((a,c)=>{let u=a,f=u.pow(c,i),l=u.mul(f,n),h=u.mul(f,o),p=u.mul(f,s),x=u.eql(u.sqr(l),c),m=u.eql(u.sqr(h),c);f=u.cmov(f,l,x),l=u.cmov(p,h,m);let b=u.eql(u.sqr(l),c),v=u.cmov(f,l,b);return bs(u,v,c),v})}function uc(t){if(t<rc)throw new Error("sqrt is not defined for small field");ws(t,"tonelliShanks");let e=t-X,r=0;for(;e%xt===ye;)e/=xt,r++;let n=xt,o=tr(t);for(;Kr(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return cc;let s=o.pow(n,e),i=(e+X)/xt;return function(c,u){let f=c;if(f.is0(u))return u;if(Kr(f,u)!==1)throw new Error("Cannot find square root");let l=r,h=f.mul(f.ONE,s),p=f.pow(u,e),x=f.pow(u,i);for(;!f.eql(p,f.ONE);){if(f.is0(p))throw new Error("Cannot find square root: probably non-prime P");let m=1,b=f.sqr(p);for(;!f.eql(b,f.ONE);)if(m++,b=f.sqr(b),m===l)throw new Error("Cannot find square root");let v=X<<BigInt(l-m-1),I=f.pow(h,v);l=m,h=f.sqr(I),p=f.mul(p,h),x=f.mul(x,I)}return x}}function Ql(t){return ws(t,"Fp.sqrt"),t%gs===rc?cc:t%oc===nc?Gl:t%sc===Yl?Xl(t):uc(t)}var fc=(t,e)=>(ce(t,e)&X)===X,Jl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function er(t){if(gt(t,"field"),typeof t.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof t.ORDER);st(t.BYTES,"BYTES"),st(t.BITS,"BITS");for(let e of Jl)Pt(t[e],"field."+e);if(t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=X)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function Cn(t,e,r=!1){er(t),In(e,"nums"),Ce(r,"passZero");let n=t,o=new Array(e.length).fill(r?n.ZERO:void 0),s=e.reduce((a,c,u)=>n.is0(c)?a:(o[u]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return e.reduceRight((a,c,u)=>n.is0(c)?a:(o[u]=n.mul(a,o[u]),n.mul(a,c)),i),o}function Kr(t,e){er(t);let r=t;ws(r.ORDER,"FpLegendre");let n=(r.ORDER-X)/xt,o=r.pow(e,n),s=r.eql(o,r.ONE),i=r.eql(o,r.ZERO),a=r.eql(o,r.neg(r.ONE));if(!s&&!i&&!a)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function ed(t,e){if(e!==void 0&&ps(e),t<=ye)throw new Error("invalid n length: expected positive n, got "+t);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let r=Jt(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected nBitLength (${e}) >= bitLen(n) (${r})`);let n=e!==void 0?e:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var tc=new WeakMap,Tn=class{ORDER;BITS;BYTES;isLE;ZERO=ye;ONE=X;_lengths;_mod;constructor(e,r={}){if(e<=X)throw new Error("invalid field: expected ORDER > 1, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=ed(e,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(e){return ce(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return ye<=e&&e<this.ORDER}is0(e){return e===ye}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&X)===X}neg(e){return ce(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return ce(e*e,this.ORDER)}add(e,r){return ce(e+r,this.ORDER)}sub(e,r){return ce(e-r,this.ORDER)}mul(e,r){return ce(e*r,this.ORDER)}pow(e,r){return ic(e,r,this.ORDER)}div(e,r){return ce(e*ec(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return ec(e,this.ORDER)}sqrt(e){let r=tc.get(this);return r||tc.set(this,r=Ql(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?ms(e,this.BYTES):Bn(e,this.BYTES)}fromBytes(e,r=!1){G(e);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let u=new Uint8Array(o);u.set(e,s?0:u.length-e.length),e=u}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let c=s?Rt(e):Qe(e);if(a&&(c=ce(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return Cn(this,e,!0)}cmov(e,r,n){return Ce(n,"condition"),n?r:e}};function tr(t,e={}){return Object.freeze(Tn.prototype),new Tn(t,e)}function lc(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=X)throw new Error("field order must be greater than 1");let e=Jt(t-X);return Math.ceil(e/8)}function On(t){let e=lc(t);return e+Math.ceil(e/2)}function Dn(t,e,r=!1){G(t);let n=t.length,o=lc(e),s=Math.max(On(e),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Rt(t):Qe(t),a=ce(i,e-X)+X;return r?ms(a,o):Bn(a,o)}var vs=BigInt(0),qr=BigInt(1),td=BigInt(4),xs=16,dc=128,rd=5,hc=2**31;function Et(t){let e=t;if(typeof e!="function")throw new TypeError('"Point" expected constructor, got type='+typeof t);Pt(e.fromAffine,"Point.fromAffine"),Pt(e.fromBytes,"Point.fromBytes"),Pt(e.fromHex,"Point.fromHex"),gt(e.BASE,"Point.BASE"),gt(e.ZERO,"Point.ZERO"),er(e.Fp),er(e.Fn)}function Pn(t,e){Et(t),mc(e,t);let r=Cn(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function nd(t,e,r=1){if(!Number.isSafeInteger(t)||t<r||t>e)throw new Error("invalid window size, expected ["+r+".."+e+"], got W="+t)}function od(t,e){let r=t*(4*e+128);if(r>hc)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+hc/2**20+" MiB")}function Ss(t,e){if(t!==void 0){Pt(t,"randomBytes");try{let r=t(e);if(!wt(r)||r.length!==e)return}catch{return}return t}}function mc(t,e){In(t,"points"),t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function sd(t,e,r){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((n,o)=>{if(!(r===void 0?e.isValid(n):bt(n)&&n<r))throw new Error("invalid scalar at index "+o)})}var yc=new WeakMap;function Es(t){return yc.get(t)||1}function id(t,e){let r=t.double(),n=[t];for(let o=1;o<e;o++)n.push(n[o-1].add(r));return n}function ad(t,e){let r=2**e,n=r/2,o=BigInt(r-1),s=[];for(;t>vs;){let i=0;t&qr&&(i=Number(t&o),i>=n&&(i-=r),t-=BigInt(i)),s.push(i),t>>=qr}return s}function cd(t,e,r){let n=2**e,o=n/2,s=BigInt(n-1),i=BigInt(e),a=[];for(let c=0;c<r;c++){let u=Number(t&s);t>>=i,u>o&&(u-=n,t+=qr),a.push(u)}if(t!==vs)throw new Error("invalid wnaf");return a}function ud(t,e,r){let n=0;for(let s of r)n=Math.max(n,s.length);let o=t;for(let s=n-1;s>=0;s--){s!==n-1&&(o=o.double());for(let i=0;i<r.length;i++){let a=r[i][s];if(a){let c=e[i][Math.abs(a)-1>>1];o=o.add(a<0?c.negate():c)}}}return o}var rr=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(e,r){Et(e),this.randomBytes=Ss(r,xs),this.Point=e,this.BASE=e.BASE,this.ZERO=e.ZERO,this.bits=e.Fn.BITS}buildWnafTable(e,r,n){let o=Math.ceil(n/r)+1,s=2**(r-1),i=[],a=e;for(let c=0;c<o;c++){let u=a;for(let f=0;f<s;f++)i.push(u),u=u.add(a);a=i[i.length-1].double()}return{W:r,bits:n,windows:o,comp:i}}wnafCachedCT(e,r){let{W:n,windows:o,comp:s}=e,i=2**(n-1),a=cd(r,n,o),c=this.ZERO,u=this.BASE;for(let f=0;f<o;f++){let l=a[f],h=f*i,p=Math.abs(l)-1,x=s[h];for(let b=1;b<i;b++)x=b===p?s[h+b]:x;let m=x.negate();l===0?u=u.add(s[h]):c=c.add(l<0?m:x)}return{p:c,f:u}}getWnafPrecomputes(e,r,n,o){let s=this.wnafPrecomputes.get(r),i=s?.find(a=>a.W===e&&a.bits===n);return i||(i=this.buildWnafTable(r,e,n),typeof o=="function"&&(i={...i,comp:o(i.comp)}),s||(s=[],this.wnafPrecomputes.set(r,s)),s.push(i)),i}assertPoint(e){if(!(e instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof e)}validateMulInput(e,r){if(this.assertPoint(e),!ys(r,qr,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(e,r,n,o){let s=Es(e);return s===1?this.fixedWindowCT(e,r,n):this.wnafCachedCT(this.getWnafPrecomputes(s,e,n,o),r)}mulCT(e,r,n){return this.validateMulInput(e,r),this.runCT(e,r,this.bits,n)}mulCTBlinded(e,r,n){if(this.validateMulInput(e,r),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let o=this.Point.Fn.BITS+dc,s=this.randomBytes(xs);if(!wt(s)||s.length!==xs)throw new Error("randomBytes returned invalid byte array");s[0]=s[0]&63|128;let i=r+Qe(s)*this.Point.Fn.ORDER;return this.runCT(e,i,o,n)}fixedWindowCT(e,r,n){let o=rd,s=1<<o,i=Mr(o),a=new Array(s);a[0]=this.ZERO;for(let f=1;f<s;f++)a[f]=a[f-1].add(e);let c=Math.ceil(n/o),u=this.ZERO;for(let f=c-1;f>=0;f--){if(f!==c-1)for(let p=0;p<o;p++)u=u.double();let l=Number(r>>BigInt(f*o)&i),h=a[0];for(let p=1;p<s;p++)h=p===l?a[p]:h;u=u.add(h)}return{p:u,f:u}}shouldBlind(e,r){return this.randomBytes===void 0?!1:r===qr?!0:e!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(e,r,n,o){return this.shouldBlind(e,n)?this.mulCTBlinded(e,r,o):this.mulCT(e,r,o)}mulUnsafe(e,r,n){if(this.assertPoint(e),!bt(r))throw new Error("invalid scalar");let o=Es(e);if(o===1||r>=this.Point.Fn.ORDER)return Ln(this.Point,[e],[r],!0);let s=this.getWnafPrecomputes(o,e,this.bits,n);return this.wnafCachedCT(s,r).p}setWindowSize(e,r){this.assertPoint(e),nd(r,this.bits);let n=Math.ceil((this.bits+dc)/r)+1;od(n*2**(r-1),this.Point.Fp.BYTES),yc.set(e,r),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return Es(e)!==1}};function Ln(t,e,r,n=!1){if(Et(t),mc(e,t),Ce(n,"allowOversized"),sd(r,t.Fn,n?t.Fn.ORDER**td:void 0),e.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let o=e.map(i=>id(i,4)),s=r.map(i=>ad(i,4));return ud(t.ZERO,o,s)}function pc(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return er(e),e}else return tr(t,{isLE:r})}function Rn(t,e,r={},n){if(t!=="weierstrass"&&t!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);Oe(r);for(let c of["p","n","h"]){let u=e[c];if(!(bt(u)&&u!==vs))throw new Error(`CURVE.${c} must be positive bigint`)}let o=pc(e.p,r.Fp,n),s=pc(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:s}}function Nn(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}var kn=BigInt(0),Fn=BigInt(1),Un=BigInt(2),fd=BigInt(4),gc=BigInt(8);function ld(t,e,r,n){let o=t.sqr(r),s=t.sqr(n),i=t.add(t.mul(e.a,o),s),a=t.add(t.ONE,t.mul(e.d,t.mul(o,s)));return t.eql(i,a)}function bc(t,e={}){Oe(e,{},{},"extraOpts");let r=e,n=Rn("edwards",t,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;if(Kr(o,i.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(Kr(o,i.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");Oe(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?Lt:r.randomBytes,u=Un<<BigInt(o.BYTES*8)-Fn;function f(I){if(!o.isOdd)throw new Error("Field does not have .isOdd()");return o.isOdd(I)}let l=r.uvRatio===void 0?(I,g)=>{try{return{isValid:!0,value:o.sqrt(o.div(I,g))}}catch{return{isValid:!1,value:kn}}}:r.uvRatio;if(!ld(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");let h=o.eql(i.a,o.neg(o.ONE))?I=>o.neg(I):o.eql(i.a,o.ONE)?I=>I:I=>o.mul(i.a,I);function p(I,g,E=!1){let A=E?Fn:kn;return Qt("coordinate "+I,g,A,u),g}function x(I){if(!(I instanceof m))throw new Error("EdwardsPoint expected")}class m{static BASE=new m(i.Gx,i.Gy,o.ONE,o.mul(i.Gx,i.Gy));static ZERO=new m(o.ZERO,o.ONE,o.ONE,o.ZERO);static Fp=o;static Fn=s;X;Y;Z;T;constructor(g,E,A,R){this.X=p("x",g),this.Y=p("y",E),this.Z=p("z",A,!0),this.T=p("t",R),Object.freeze(this)}static CURVE(){return i}static fromAffine(g){if(g instanceof m)throw new Error("extended point not allowed");let{x:E,y:A}=g||{};return p("x",E),p("y",A),new m(E,A,o.ONE,o.mul(E,A))}static fromBytes(g,E=!1){let A=o.BYTES,{a:R,d:U}=i;g=Ur(G(g,A,"point")),Ce(E,"zip215");let k=Ur(g),O=g[A-1];k[A-1]=O&-129;let L=Rt(k),H=E?u:o.ORDER;Qt("point.y",L,kn,H);let z=o.sqr(L),J=o.sub(z,o.ONE),B=o.sub(o.mulN(U,z),R),{isValid:M,value:K}=l(J,B);if(!M)throw new Error("bad point: invalid y coordinate");let P=f(K),re=(O&128)!==0;if(!E&&o.is0(K)&&re)throw new Error("bad point: x=0 and x_0=1");return re!==P&&(K=o.neg(K)),m.fromAffine({x:K,y:L})}static fromHex(g,E=!1){return m.fromBytes(Xt(g),E)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=6,E=!0){return v.setWindowSize(this,g),E||this.multiply(Un),this}assertValidity(){let g=this,{a:E,d:A}=i;if(g.is0())throw new Error("bad point: ZERO");let{X:R,Y:U,Z:k,T:O}=g,L=o.sqr(R),H=o.sqr(U),z=o.sqr(k),J=o.sqr(z),B=o.mul(L,E),M=o.mul(o.add(B,H),z),K=o.add(J,o.mul(A,o.mul(L,H)));if(!o.eql(M,K))throw new Error("bad point: equation left != right (1)");let P=o.mul(R,U),re=o.mul(k,O);if(!o.eql(P,re))throw new Error("bad point: equation left != right (2)")}equals(g){x(g);let{X:E,Y:A,Z:R}=this,{X:U,Y:k,Z:O}=g,L=o.mul(E,O),H=o.mul(U,R),z=o.mul(A,O),J=o.mul(k,R);return o.eql(L,H)&&o.eql(z,J)}is0(){return this.equals(m.ZERO)}negate(){return new m(o.neg(this.X),this.Y,this.Z,o.neg(this.T))}double(){let{X:g,Y:E,Z:A}=this,R=o.sqr(g),U=o.sqr(E),k=o.mul(o.sqr(A),Un),O=h(R),L=o.addN(g,E),H=o.sub(o.subN(o.sqr(L),R),U),z=o.addN(O,U),J=o.subN(z,k),B=o.subN(O,U),M=o.mul(H,J),K=o.mul(z,B),P=o.mul(H,B),re=o.mul(J,z);return new m(M,K,re,P)}add(g){x(g);let{d:E}=i,{X:A,Y:R,Z:U,T:k}=this,{X:O,Y:L,Z:H,T:z}=g,J=o.mul(A,O),B=o.mul(R,L),M=o.mul(o.mulN(k,E),z),K=o.mul(U,H),P=o.sub(o.subN(o.mulN(o.addN(A,R),o.addN(O,L)),J),B),re=o.subN(K,M),ie=o.addN(K,M),S=o.sub(B,h(J)),d=o.mul(P,re),y=o.mul(ie,S),w=o.mul(P,S),_=o.mul(re,ie);return new m(d,y,_,w)}subtract(g){return x(g),this.add(g.negate())}multiply(g){if(!s.isValidNot0(g))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:E,f:A}=v.mulSecret(this,g,a,b);return b([E,A])[0]}multiplyUnsafe(g){if(!s.isValid(g))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return g===kn?m.ZERO:this.is0()||g===Fn?this:v.mulUnsafe(this,g,b)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return v.mulUnsafe(this,i.n).is0()}toAffine(g){let E=this,A=g;if(A!=null&&typeof A!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof A);let{X:R,Y:U,Z:k}=E,O=E.is0();A==null&&(A=O?o.create(gc):o.inv(k));let L=o.mul(R,A),H=o.mul(U,A),z=o.mul(k,A);if(O)return{x:o.ZERO,y:o.ONE};if(!o.eql(z,o.ONE))throw new Error("invZ was invalid");return{x:L,y:H}}clearCofactor(){return a===Fn?this:a===Un?this.double():a===fd?this.double().double():a===gc?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:g,y:E}=this.toAffine(),A=o.toBytes(E);return A[A.length-1]|=f(g)?128:0,A}toHex(){return kr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let b=I=>Pn(m,I),v=new rr(m,c);return v.bits>=6&&m.BASE.precompute(6),Object.freeze(m.prototype),Object.freeze(m),m}function wc(t,e,r={}){if(Et(t),typeof e!="function")throw new Error('"hash" function param is required');let n=e,o=r;Oe(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function",toMontgomery:"function",toMontgomerySecret:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=t,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(st(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=o.randomBytes===void 0?Lt:o.randomBytes,h=o.toMontgomery,p=o.toMontgomerySecret,x=o.adjustScalarBytes===void 0?B=>B:o.adjustScalarBytes,m=o.domain===void 0?(B,M,K)=>{if(Ce(K,"phflag"),M.length||K)throw new Error("Contexts/pre-hash are not supported");return B}:o.domain;function b(B){return c.create(Rt(B))}function v(B){let M=O.secretKey;G(B,O.secretKey,"secretKey");let K=G(n(B),2*M,"hashedSecretKey"),P=x(K.slice(0,M)),re=K.slice(M,2*M),ie=b(P);return{head:P,prefix:re,scalar:ie}}function I(B){let{head:M,prefix:K,scalar:P}=v(B),re=i.multiply(P),ie=re.toBytes();return{head:M,prefix:K,scalar:P,point:re,pointBytes:ie}}function g(B){return I(B).pointBytes}function E(B=Uint8Array.of(),...M){let K=Fe(...M);return b(n(m(K,G(B,void 0,"context"),!!s)))}function A(B,M,K={}){Oe(K,{},{},"options"),B=Ur(G(B,void 0,"message")),s&&(B=s(B));let{prefix:P,scalar:re,pointBytes:ie}=I(M),S=E(K.context,P,B),d=i.multiply(S).toBytes(),y=E(K.context,d,ie,B),w=c.create(S+y*re);if(!c.isValid(w))throw new Error("sign failed: invalid s");let _=Fe(d,c.toBytes(w));return G(_,O.signature,"result")}let R={zip215:o.zip215};function U(B,M,K,P=R){Oe(P);let{context:re}=P,ie=P.zip215===void 0?!!R.zip215:P.zip215,S=O.signature;B=G(B,S,"signature"),M=G(M,void 0,"message"),K=G(K,O.publicKey,"publicKey"),ie!==void 0&&Ce(ie,"zip215"),s&&(M=s(M));let d=S/2,y=B.subarray(0,d),w=Rt(B.subarray(d,S)),_,T,C;try{_=t.fromBytes(K,ie),T=t.fromBytes(y,ie),C=i.multiplyUnsafe(w)}catch{return!1}if(!ie&&_.isSmallOrder())return!1;let N=E(re,y,K,M);return T.add(_.multiplyUnsafe(N)).subtract(C).clearCofactor().is0()}let k=a.BYTES,O={secretKey:k,publicKey:k,signature:2*k,seed:k};function L(B){return B=B===void 0?l(O.seed):B,G(B,O.seed,"seed")}function H(B){return wt(B)&&B.length===O.secretKey}function z(B,M){try{return!!t.fromBytes(B,M===void 0?R.zip215:M)}catch{return!1}}let J={getExtendedPublicKey:I,randomSecretKey:L,isValidSecretKey:H,isValidPublicKey:z,toMontgomery(B){if(h===void 0)throw new Error("Montgomery conversion is not supported for this curve");return h(t.fromBytes(B))},toMontgomerySecret(B){if(p===void 0)throw new Error("Montgomery conversion is not supported for this curve");return p(B)}};return Object.freeze(O),Object.freeze(J),Object.freeze({keygen:Nn(L,g),getPublicKey:g,sign:A,verify:U,utils:J,Point:t,lengths:O})}var As=BigInt(1),xc=BigInt(2);var dd=BigInt(5),hd=BigInt(8),Is=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),pd={p:Is,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:hd,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function md(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Is,a=t*t%s*t%s,c=se(a,xc,s)*a%s,u=se(c,As,s)*t%s,f=se(u,dd,s)*u%s,l=se(f,e,s)*f%s,h=se(l,r,s)*l%s,p=se(h,n,s)*h%s,x=se(p,o,s)*p%s,m=se(x,o,s)*p%s,b=se(m,e,s)*f%s;return{pow_p_5_8:se(b,xc,s)*t%s,b2:a}}function Sc(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var Ec=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function yd(t,e){let r=Is,n=ce(e*e*e,r),o=ce(n*n*e,r),s=md(t*o).pow_p_5_8,i=ce(t*n*s,r),a=ce(e*i*i,r),c=i,u=ce(i*Ec,r),f=a===t,l=a===ce(-t,r),h=a===ce(-t*Ec,r);return f&&(i=c),(l||h)&&(i=u),fc(i,r)&&(i=ce(-i,r)),{isValid:f||l,value:i}}var _s=bc(pd,{uvRatio:yd}),vc=_s.Fp;function gd(t){let{y:e}=t;return vc.toBytes(vc.div(As+e,As-e))}function bd(t){let e=_s.Fp.BYTES;return ke(t,e),Sc(hs(t.subarray(0,e))).subarray(0,e)}function wd(t){return wc(_s,hs,Object.assign({adjustScalarBytes:Sc,toMontgomery:gd,toMontgomerySecret:bd,zip215:!0},t))}var Ac=wd({});var Vr=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},Mn=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var Ue={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new Mn("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return e}};var Kn=32;var Bs,xd=(async()=>{try{return await Ue.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Ed(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await Ue.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await Ue.get().subtle.verify({name:"Ed25519"},n,_e(e),_e(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function vd(t,e,r){return Ac.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function Ic(t,e,r){return Bs==null&&(Bs=await xd),Bs?Ed(t,e,r):vd(t,e,r)}function qn(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Vn=class{type="Ed25519";raw;constructor(e){this.raw=Ts(e,Kn)}toMultihash(){return Ke.digest(Ge(this))}toCID(){return be.createV1(114,this.toMultihash())}toString(){return he.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:pe(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let o=Ic(this.raw,r,e);return qn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Cs(t){return t=Ts(t,Kn),new Vn(t)}function Ts(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new ae(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}var Ad=Math.pow(2,7),Id=Math.pow(2,14),_d=Math.pow(2,21),Os=Math.pow(2,28),Ds=Math.pow(2,35),Ps=Math.pow(2,42),Ls=Math.pow(2,49),Q=128,Se=127;function De(t){if(t<Ad)return 1;if(t<Id)return 2;if(t<_d)return 3;if(t<Os)return 4;if(t<Ds)return 5;if(t<Ps)return 6;if(t<Ls)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function nr(t,e,r=0){switch(De(t)){case 8:e[r++]=t&255|Q,t/=128;case 7:e[r++]=t&255|Q,t/=128;case 6:e[r++]=t&255|Q,t/=128;case 5:e[r++]=t&255|Q,t/=128;case 4:e[r++]=t&255|Q,t>>>=7;case 3:e[r++]=t&255|Q,t>>>=7;case 2:e[r++]=t&255|Q,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Bd(t,e,r=0){switch(De(t)){case 8:e.set(r++,t&255|Q),t/=128;case 7:e.set(r++,t&255|Q),t/=128;case 6:e.set(r++,t&255|Q),t/=128;case 5:e.set(r++,t&255|Q),t/=128;case 4:e.set(r++,t&255|Q),t>>>=7;case 3:e.set(r++,t&255|Q),t>>>=7;case 2:e.set(r++,t&255|Q),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function Rs(t,e){let r=t[e],n=0;if(n+=r&Se,r<Q||(r=t[e+1],n+=(r&Se)<<7,r<Q)||(r=t[e+2],n+=(r&Se)<<14,r<Q)||(r=t[e+3],n+=(r&Se)<<21,r<Q)||(r=t[e+4],n+=(r&Se)*Os,r<Q)||(r=t[e+5],n+=(r&Se)*Ds,r<Q)||(r=t[e+6],n+=(r&Se)*Ps,r<Q)||(r=t[e+7],n+=(r&Se)*Ls,r<Q))return n;throw new RangeError("Could not decode varint")}function Td(t,e){let r=t.get(e),n=0;if(n+=r&Se,r<Q||(r=t.get(e+1),n+=(r&Se)<<7,r<Q)||(r=t.get(e+2),n+=(r&Se)<<14,r<Q)||(r=t.get(e+3),n+=(r&Se)<<21,r<Q)||(r=t.get(e+4),n+=(r&Se)*Os,r<Q)||(r=t.get(e+5),n+=(r&Se)*Ds,r<Q)||(r=t.get(e+6),n+=(r&Se)*Ps,r<Q)||(r=t.get(e+7),n+=(r&Se)*Ls,r<Q))return n;throw new RangeError("Could not decode varint")}function or(t,e,r=0){return e==null&&(e=ve(De(t))),e instanceof Uint8Array?nr(t,e,r):Bd(t,e,r)}function zr(t,e=0){return t instanceof Uint8Array?Rs(t,e):Td(t,e)}var ks=new Float32Array([-0]),vt=new Uint8Array(ks.buffer);function Bc(t,e,r){ks[0]=t,e[r]=vt[0],e[r+1]=vt[1],e[r+2]=vt[2],e[r+3]=vt[3]}function Tc(t,e){return vt[0]=t[e],vt[1]=t[e+1],vt[2]=t[e+2],vt[3]=t[e+3],ks[0]}var Fs=new Float64Array([-0]),Ae=new Uint8Array(Fs.buffer);function Cc(t,e,r){Fs[0]=t,e[r]=Ae[0],e[r+1]=Ae[1],e[r+2]=Ae[2],e[r+3]=Ae[3],e[r+4]=Ae[4],e[r+5]=Ae[5],e[r+6]=Ae[6],e[r+7]=Ae[7]}function Oc(t,e){return Ae[0]=t[e],Ae[1]=t[e+1],Ae[2]=t[e+2],Ae[3]=t[e+3],Ae[4]=t[e+4],Ae[5]=t[e+5],Ae[6]=t[e+6],Ae[7]=t[e+7],Fs[0]}var Cd=BigInt(Number.MAX_SAFE_INTEGER),Od=BigInt(Number.MIN_SAFE_INTEGER),Le=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Nt;if(e<Cd&&e>Od)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,o=e-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Dc&&(o=0n,++n>Dc&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return Nt;let r=e<0;r&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new t(n,o)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):Nt}},Nt=new Le(0,0);Nt.toBigInt=function(){return 0n};Nt.zzEncode=Nt.zzDecode=function(){return this};Nt.length=function(){return 1};var Dc=4294967296n;function Pc(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function Lc(t,e,r){if(r-e<1)return"";let o,s=[],i=0,a;for(;e<r;)a=t[e++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Us(t,e,r){let n=r,o,s;for(let i=0;i<t.length;++i)o=t.charCodeAt(i),o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&((s=t.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128);return r-n}function Ve(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function zn(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var Ms=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=_e(e),this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Ve(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Ve(this,4);return zn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ve(this,4);return zn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ve(this,4);let e=Tc(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ve(this,4);let e=Oc(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw Ve(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return Lc(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ve(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ve(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Le(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Ve(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw Ve(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ve(this,8);let e=zn(this.buf,this.pos+=4),r=zn(this.buf,this.pos+=4);return new Le(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Rs(this.buf,this.pos);return this.pos+=De(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Hr(t){return new Ms(t instanceof Uint8Array?t:t.subarray())}function ze(t,e,r){let n=Hr(t);return e.decode(n,void 0,r)}function Ks(t){let e=t??8192,r=e>>>1,n,o=e;return function(i){if(i<1||i>r)return ve(i);o+i>e&&(n=ve(e),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var kt=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function qs(){}var zs=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Dd=Ks();function Pd(t){return globalThis.Buffer!=null?ve(t):Dd(t)}var jr=class{len;head;tail;states;constructor(){this.len=0,this.head=new kt(qs,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new kt(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Hs((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(Hn,10,Le.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=Le.fromBigInt(e);return this._push(Hn,r.length(),r)}uint64Number(e){return this._push(nr,De(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=Le.fromBigInt(e).zzEncode();return this._push(Hn,r.length(),r)}sint64Number(e){let r=Le.fromNumber(e).zzEncode();return this._push(Hn,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Vs,1,e?1:0)}fixed32(e){return this._push($r,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=Le.fromBigInt(e);return this._push($r,4,r.lo)._push($r,4,r.hi)}fixed64Number(e){let r=Le.fromNumber(e);return this._push($r,4,r.lo)._push($r,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(Bc,4,e)}double(e){return this._push(Cc,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(Vs,1,0):this.uint32(r)._push(Rd,r,e)}string(e){let r=Pc(e);return r!==0?this.uint32(r)._push(Us,r,e):this._push(Vs,1,0)}fork(){return this.states=new zs(this),this.head=this.tail=new kt(qs,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new kt(qs,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=Pd(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function Vs(t,e,r){e[r]=t&255}function Ld(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var Hs=class extends kt{next;constructor(e,r){super(Ld,e,r),this.next=void 0}};function Hn(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function $r(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function Rd(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(jr.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(Nd,e,t),this},jr.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(kd,e,t),this});function Nd(t,e,r){e.set(t,r)}function kd(t,e,r){t.length<40?Us(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(q(t),r)}function $s(){return new jr}function He(t,e){let r=$s();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*$e(t,e,r){let n=Hr(t);yield*e.stream(n,void 0,".",r)}var $n={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function jn(t,e,r,n,o){return{name:t,type:e,encode:r,decode:n,stream:o}}function js(t){function e(s){if(t[s.toString()]==null)throw new Error("Invalid enum value");return t[s]}let r=function(i,a){let c=e(i);a.int32(c)},n=function(i){let a=i.int32();return e(a)},o=function*(i,a){};return jn("enum",$n.VARINT,r,n,o)}function je(t,e,r){return jn("message",$n.LENGTH_DELIMITED,t,e,r)}var Je=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var ue;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(ue||(ue={}));var Ys;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(Ys||(Ys={}));(function(t){t.codec=()=>js(Ys)})(ue||(ue={}));var et;(function(t){let e;t.codec=()=>(e==null&&(e=je((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ue.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=ue.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:ue.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return He(s,t.codec())}t.encode=r;function n(s,i){return ze(s,t.codec(),i)}t.decode=n;function o(s,i){return $e(s,t.codec(),i)}t.stream=o})(et||(et={}));var Ws;(function(t){let e;t.codec=()=>(e==null&&(e=je((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ue.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=ue.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:ue.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return He(s,t.codec())}t.encode=r;function n(s,i){return ze(s,t.codec(),i)}t.decode=n;function o(s,i){return $e(s,t.codec(),i)}t.stream=o})(Ws||(Ws={}));var Wr={};Be(Wr,{MAX_RSA_KEY_SIZE:()=>Zs,generateRSAKeyPair:()=>Mc,jwkToJWKKeyPair:()=>Kc,jwkToPkcs1:()=>Kd,jwkToPkix:()=>Js,jwkToRSAPrivateKey:()=>ni,pkcs1MessageToJwk:()=>Xs,pkcs1MessageToRSAPrivateKey:()=>ei,pkcs1ToJwk:()=>Md,pkcs1ToRSAPrivateKey:()=>Uc,pkixMessageToJwk:()=>Qs,pkixMessageToRSAPublicKey:()=>ri,pkixToJwk:()=>qd,pkixToRSAPublicKey:()=>ti});var sr=class{type="RSA";jwk;_raw;_multihash;constructor(e,r){this.jwk=e,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Wr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return be.createV1(114,this._multihash)}toString(){return he.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:pe(this.raw,e.raw)}verify(e,r,n){return Fc(this.jwk,r,e,n)}},Yr=class{type="RSA";jwk;_raw;publicKey;constructor(e,r){this.jwk=e,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Wr.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:pe(this.raw,e.raw)}sign(e,r){return kc(this.jwk,e,r)}};var Zs=8192,Gs=18,Fd=1062,Ud=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Md(t){let e=nt(t);return Xs(e)}function Xs(t){return{n:j(t[1],"base64url"),e:j(t[2],"base64url"),d:j(t[3],"base64url"),p:j(t[4],"base64url"),q:j(t[5],"base64url"),dp:j(t[6],"base64url"),dq:j(t[7],"base64url"),qi:j(t[8],"base64url"),kty:"RSA"}}function Kd(t){if(t.n==null||t.e==null||t.d==null||t.p==null||t.q==null||t.dp==null||t.dq==null||t.qi==null)throw new ae("JWK was missing components");return ht([Te(Uint8Array.from([0])),Te(q(t.n,"base64url")),Te(q(t.e,"base64url")),Te(q(t.d,"base64url")),Te(q(t.p,"base64url")),Te(q(t.q,"base64url")),Te(q(t.dp,"base64url")),Te(q(t.dq,"base64url")),Te(q(t.qi,"base64url"))]).subarray()}function qd(t){let e=nt(t,{offset:0});return Qs(e)}function Qs(t){let e=nt(t[1],{offset:0});return{kty:"RSA",n:j(e[0],"base64url"),e:j(e[1],"base64url")}}function Js(t){if(t.n==null||t.e==null)throw new ae("JWK was missing components");return ht([Ud,yn(ht([Te(q(t.n,"base64url")),Te(q(t.e,"base64url"))]))]).subarray()}function Uc(t){let e=nt(t);return ei(e)}function ei(t){let e=Xs(t);return ni(e)}function ti(t,e){if(t.byteLength>=Fd)throw new It("Key size is too large");let r=nt(t,{offset:0});return ri(r,t,e)}function ri(t,e,r){let n=Qs(t);if(r==null){let o=Gt(et.encode({Type:ue.RSA,Data:e}));r=We(Gs,o)}return new sr(n,r)}function ni(t){if(Vc(t)>Zs)throw new ae("Key size is too large");let e=Kc(t),r=Gt(et.encode({Type:ue.RSA,Data:Js(e.publicKey)})),n=We(Gs,r);return new Yr(e.privateKey,new sr(e.publicKey,n))}async function Mc(t){if(t>Zs)throw new ae("Key size is too large");let e=await qc(t),r=Gt(et.encode({Type:ue.RSA,Data:Js(e.publicKey)})),n=We(Gs,r);return new Yr(e.privateKey,new sr(e.publicKey,n))}function Kc(t){if(t==null)throw new ae("Missing key parameter");return{privateKey:t,publicKey:{kty:t.kty,n:t.n,e:t.e}}}async function qc(t,e){let r=await Ue.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:t,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);e?.signal?.throwIfAborted();let n=await Vd(r,e);return{privateKey:n[0],publicKey:n[1]}}async function kc(t,e,r){let n=await Ue.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Ue.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,_e(e instanceof Uint8Array?e:e.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Fc(t,e,r,n){let o=await Ue.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Ue.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,_e(e),_e(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),s}async function Vd(t,e){if(t.privateKey==null||t.publicKey==null)throw new ae("Private and public key are required");let r=await Promise.all([Ue.get().subtle.exportKey("jwk",t.privateKey),Ue.get().subtle.exportKey("jwk",t.publicKey)]);return e?.signal?.throwIfAborted(),r}function Vc(t){if(t.kty!=="RSA")throw new ae("invalid key type");if(t.n==null)throw new ae("invalid key modulus");return q(t.n,"base64url").length*8}var Yn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(wn(e),ke(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),Dt(o)}update(e){return Zt(this),this.iHash.update(e),this}digestInto(e){Zt(this),xn(e,this),this.finished=!0;let r=e.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a,canXOF:c}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=a,e.canXOF=c,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},zc=(()=>{let t=((e,r,n)=>new Yn(e,r).update(n).digest());return t.create=(e,r)=>new Yn(e,r),t})();var zd=BigInt(0),oi=class extends Error{constructor(e=""){super(e)}},it={Err:oi,_tlv:{encode:(t,e)=>{let{Err:r}=it;if(st(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(Xa(e,"data"),e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,o=Fr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Fr(o.length/2|128):"";return Fr(t)+s+o+e},decode(t,e){let{Err:r}=it;e=G(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.decode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let o=e[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+i)}}},_int:{encode(t){let{Err:e}=it;if(_n(t),t<zd)throw new e("integer: negative integers are not allowed");let r=Fr(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=it;if(t.length<1)throw new e("invalid signature integer: empty");if(t[0]&128)throw new e("invalid signature integer: negative");if(t.length>1&&t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return Qe(t)}},toSig(t,e){let{Err:r,_int:n,_tlv:o}=it;if(e!==void 0&&(st(e,"maxScalarBytes"),e<1))throw new r("invalid signature: maxScalarBytes must be positive");let s=G(t,void 0,"signature"),{v:i,l:a}=o.decode(48,s);if(a.length)throw new r("invalid signature: left bytes after parsing");let{v:c,l:u}=o.decode(2,i),{v:f,l}=o.decode(2,u);if(l.length)throw new r("invalid signature: left bytes after parsing");if(e!==void 0&&(c.length>e||f.length>e))throw new r("invalid signature: integer too large");return{r:n.decode(c),s:n.decode(f)}},hexFromSig(t){let{_tlv:e,_int:r}=it;Oe(t,{r:"bigint",s:"bigint"},{},"sig");let n=e.encode(2,r.encode(t.r)),o=e.encode(2,r.encode(t.s)),s=n+o;return e.encode(48,s)}},Wn=(Object.freeze(it._tlv),Object.freeze(it._int),Object.freeze(it));var Hc=(t,e)=>(t+(t>=0?e:-e)/$c)/e;function Hd(t,e,r){Qt("scalar",t,at,r);let[[n,o],[s,i]]=e,a=Hc(i*t,r),c=Hc(-o*t,r),u=t-a*n-c*s,f=-a*o-c*i,l=u<at,h=f<at;l&&(u=-u),h&&(f=-f);let p=Mr(Math.ceil(Jt(r)/2))+Ft;if(u<at||u>=p||f<at||f>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:h,k2:f}}function ai(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function si(t,e){Oe(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Ce(r.lowS,"lowS"),Ce(r.prehash,"prehash"),r.format!==void 0&&ai(r.format),r}var at=BigInt(0),Ft=BigInt(1),$c=BigInt(2),ii=BigInt(3),$d=BigInt(4);function jc(t,e={}){let r=Rn("weierstrass",t,e),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;Oe(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:u,clearCofactor:f,isTorsionFree:l,fromBytes:h,toBytes:p}=e,x=e.randomBytes===void 0?Lt:e.randomBytes;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let m=c?{beta:c.beta,basises:c.basises.map(S=>[...S])}:void 0,b=Wc(n,o);function v(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function I(S,d,y){if(d.is0()){if(!u)throw new Error("bad point: ZERO");return Uint8Array.of(0)}let{x:w,y:_}=d.toAffine(),T=n.toBytes(w);if(Ce(y,"isCompressed"),y){v();let C=!n.isOdd(_);return Fe(Yc(C),T)}else return Fe(Uint8Array.of(4),T,n.toBytes(_))}function g(S){G(S,void 0,"Point");let{publicKey:d,publicKeyUncompressed:y}=b,w=S.length,_=S[0],T=S.subarray(1);if(u&&w===1&&_===0)return{x:n.ZERO,y:n.ZERO};if(w===d&&(_===2||_===3)){let C=n.fromBytes(T);if(!n.isValid(C))throw new Error("bad point: is not on curve, wrong x");let N=k(C),F;try{F=n.sqrt(N)}catch(le){let ne=le instanceof Error?": "+le.message:"";throw new Error("bad point: is not on curve, sqrt error"+ne)}v();let Z=n.isOdd(F);return(_&1)===1!==Z&&(F=n.neg(F)),{x:C,y:F}}else if(w===y&&_===4){let C=n.BYTES,N=n.fromBytes(T.subarray(0,C)),F=n.fromBytes(T.subarray(C,C*2));if(!O(N,F))throw new Error("bad point: is not on curve");return{x:N,y:F}}else throw new Error(`bad point: got length ${w}, expected compressed=${d} or uncompressed=${y}`)}let E=p===void 0?I:p,A=h===void 0?g:h,R=n.mul(s.b,ii),U=n.is0(s.a)?S=>n.ZERO:S=>n.mul(s.a,S);function k(S){let d=n.sqr(S),y=n.mul(d,S);return n.add(n.add(y,n.mul(S,s.a)),s.b)}function O(S,d){let y=n.sqr(d),w=k(S);return n.eql(y,w)}if(!O(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let L=n.mul(n.pow(s.a,ii),$d),H=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(L,H)))throw new Error("bad curve params: a or b");function z(S,d,y=!1){if(!n.isValid(d)||y&&n.is0(d))throw new Error(`bad point coordinate ${S}`);return typeof d=="object"&&d!==null?n.create(d):d}function J(S){if(!(S instanceof P))throw new Error("Weierstrass Point expected")}function B(S){if(!m||!m.basises)throw new Error("no endo");return Hd(S,m.basises,o.ORDER)}function M(S,d,y,w){if(!o.isValid(w))throw new RangeError("invalid scalar: out of range");if(m){let{k1neg:_,k1:T,k2neg:C,k2:N}=B(w),F=new P(n.mul(y.X,m.beta),y.Y,y.Z);S.push(_?y.negate():y,C?F.negate():F),d.push(T,N)}else S.push(y),d.push(w)}let K=new WeakSet;class P{static BASE=new P(s.Gx,s.Gy,n.ONE);static ZERO=new P(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(d,y,w){this.X=z("x",d),this.Y=z("y",y,!0),this.Z=z("z",w),Object.freeze(this)}static CURVE(){return s}static fromAffine(d){let{x:y,y:w}=d||{};if(!d||!n.isValid(y)||!n.isValid(w))throw new Error("invalid affine point");if(d instanceof P)throw new Error("projective point not allowed");return n.is0(y)&&n.is0(w)?P.ZERO:new P(y,w,n.ONE)}static fromBytes(d){let y=P.fromAffine(A(G(d,void 0,"point")));return y.assertValidity(),y}static fromHex(d){return P.fromBytes(Xt(d))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(d=6,y=!0){return ie.setWindowSize(this,d),y||this.multiply(ii),this}assertValidity(){let d=this;if(d.is0()){if(u&&n.is0(d.X)&&n.eql(d.Y,n.ONE)&&n.is0(d.Z))return;throw new Error("bad point: ZERO")}if(K.has(d))return;let{x:y,y:w}=d.toAffine();if(!n.isValid(y)||!n.isValid(w))throw new Error("bad point: x or y not field elements");if(!O(y,w))throw new Error("bad point: equation left != right");if(!d.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");K.add(d)}hasEvenY(){let{y:d}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(d)}equals(d){J(d);let{X:y,Y:w,Z:_}=this,{X:T,Y:C,Z:N}=d,F=n.eql(n.mul(y,N),n.mul(T,_)),Z=n.eql(n.mul(w,N),n.mul(C,_));return F&&Z}negate(){return new P(this.X,n.neg(this.Y),this.Z)}double(){let{X:d,Y:y,Z:w}=this,_=n.ZERO,T=n.ZERO,C=n.ZERO,N=n.mul(d,d),F=n.mul(y,y),Z=n.mul(w,w),$=n.mul(d,y);return $=n.add($,$),C=n.mul(d,w),C=n.add(C,C),_=U(C),T=n.mul(R,Z),T=n.add(_,T),_=n.sub(F,T),T=n.add(F,T),T=n.mul(_,T),_=n.mul($,_),C=n.mul(R,C),Z=U(Z),$=n.sub(N,Z),$=U($),$=n.add($,C),C=n.add(N,N),N=n.add(C,N),N=n.add(N,Z),N=n.mul(N,$),T=n.add(T,N),Z=n.mul(y,w),Z=n.add(Z,Z),N=n.mul(Z,$),_=n.sub(_,N),C=n.mul(Z,F),C=n.add(C,C),C=n.add(C,C),new P(_,T,C)}add(d){J(d);let{X:y,Y:w,Z:_}=this,{X:T,Y:C,Z:N}=d,F=n.ZERO,Z=n.ZERO,$=n.ZERO,le=n.mul(y,T),ne=n.mul(w,C),ge=n.mul(_,N),Re=n.add(y,w),oe=n.add(T,C);Re=n.mul(Re,oe),oe=n.add(le,ne),Re=n.sub(Re,oe),oe=n.add(y,_);let de=n.add(T,N);return oe=n.mul(oe,de),de=n.add(le,ge),oe=n.sub(oe,de),de=n.add(w,_),F=n.add(C,N),de=n.mul(de,F),F=n.add(ne,ge),de=n.sub(de,F),$=U(oe),F=n.mul(R,ge),$=n.add(F,$),F=n.sub(ne,$),$=n.add(ne,$),Z=n.mul(F,$),ne=n.add(le,le),ne=n.add(ne,le),ge=U(ge),oe=n.mul(R,oe),ne=n.add(ne,ge),ge=n.sub(le,ge),ge=U(ge),oe=n.add(oe,ge),le=n.mul(ne,oe),Z=n.add(Z,le),le=n.mul(de,oe),F=n.mul(Re,F),F=n.sub(F,le),le=n.mul(Re,ne),$=n.mul(de,$),$=n.add($,le),new P(F,Z,$)}subtract(d){return J(d),this.add(d.negate())}is0(){return this.equals(P.ZERO)}multiply(d){if(!o.isValidNot0(d))throw new RangeError("invalid scalar: out of range");let{p:y,f:w}=ie.mulSecret(this,d,i,re);return re([y,w])[0]}multiplyUnsafe(d){let y=this,w=d;if(!o.isValid(w))throw new RangeError("invalid scalar: out of range");if(w===at||y.is0())return P.ZERO;if(w===Ft)return y;if(ie.hasWindowSize(this))return ie.mulUnsafe(y,w,re);let _=[],T=[];return M(_,T,y,w),Ln(P,_,T)}mulAddUnsafe(d,y,w){J(y);let _=[],T=[];return M(_,T,this,d),M(_,T,y,w),Ln(P,_,T)}toAffine(d){let y=this,w=d;if(w!=null&&!n.isValid(w))throw new RangeError('"invertedZ" expected valid field element');let{X:_,Y:T,Z:C}=y;if(n.eql(C,n.ONE))return{x:_,y:T};let N=y.is0();w==null&&(w=N?n.ONE:n.inv(C));let F=n.mul(_,w),Z=n.mul(T,w),$=n.mul(C,w);if(N)return{x:n.ZERO,y:n.ZERO};if(!n.eql($,n.ONE))throw new Error("invZ was invalid");return{x:F,y:Z}}isTorsionFree(){return i===Ft?!0:l?l(P,this):ie.mulUnsafe(this,a).is0()}clearCofactor(){return i===Ft?this:f?f(P,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===Ft?this.is0():this.clearCofactor().is0()}toBytes(d=!0){return Ce(d,"isCompressed"),this.assertValidity(),E(P,this,d)}toHex(d=!0){return kr(this.toBytes(d))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let re=S=>Pn(P,S),ie=new rr(P,x);return ie.bits>=6&&P.BASE.precompute(6),Object.freeze(P.prototype),Object.freeze(P),P}function Yc(t){return Uint8Array.of(t?2:3)}function Wc(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function jd(t,e={}){Et(t);let{Fn:r}=t,n=e.randomBytes===void 0?Lt:e.randomBytes,o=Object.assign(Wc(t.Fp,r),{seed:Math.max(On(r.ORDER),16)});function s(p){try{let x=r.fromBytes(p);return r.isValidNot0(x)}catch{return!1}}function i(p,x){let{publicKey:m,publicKeyUncompressed:b}=o;try{let v=p.length;return x===!0&&v!==m||x===!1&&v!==b?!1:!t.fromBytes(p).is0()}catch{return!1}}function a(p){return p=p===void 0?n(o.seed):p,Dn(G(p,o.seed,"seed"),r.ORDER)}function c(p,x=!0){return t.BASE.multiply(r.fromBytes(p)).toBytes(x)}function u(p){let{secretKey:x,publicKey:m,publicKeyUncompressed:b}=o,v=r._lengths;if(!wt(p))return;let I=G(p,void 0,"key").length,g=I===m||I===b,E=I===x||!!v?.includes(I);if(!(g&&E))return g}function f(p,x,m=!0){if(u(p)===!0)throw new Error("first arg must be private key");if(u(x)===!1)throw new Error("second arg must be public key");let b=r.fromBytes(p),v=t.fromBytes(x);if(v.is0())throw new Error("invalid public key: point at infinity");return v.multiply(b).toBytes(m)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},h=Nn(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:h,Point:t,utils:l,lengths:o})}function Zc(t,e,r={}){Et(t);let n=e;wn(n),Oe(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},r),s=o.randomBytes===void 0?Lt:o.randomBytes,i=o.hmac===void 0?(S,d)=>zc(n,S,d):o.hmac,{Fp:a,Fn:c}=t,{ORDER:u,BITS:f}=c,l=On(u),h=Ss(s,l),{keygen:p,getPublicKey:x,getSharedSecret:m,utils:b,lengths:v}=jd(t,o),I={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},g=u*$c+Ft<a.ORDER;function E(S){let d=u>>Ft;return S>d}function A(S,d){if(!c.isValidNot0(d))throw new Error(`invalid signature ${S}: out of range 1..Point.Fn.ORDER`);return d}function R(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function U(S,d,y){return R(),(S===y?0:2)|Number(a.isOdd(d))}function k(){if(g)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function O(S,d){ai(d);let y=v.signature,w=d==="compact"?y:d==="recovered"?y+1:void 0;return G(S,w)}class L{r;s;recovery;constructor(d,y,w){if(this.r=A("r",d),this.s=A("s",y),w!=null){if(k(),![0,1,2,3].includes(w))throw new Error("invalid recovery id");this.recovery=w}Object.freeze(this)}static fromBytes(d,y=I.format){O(d,y);let w;if(y==="der"){if(d.length>2*c.BYTES+16)throw new Wn.Err("invalid signature: DER signature too long");let{r:N,s:F}=Wn.toSig(G(d),c.BYTES+1);return new L(N,F)}y==="recovered"&&(w=d[0],y="compact",d=d.subarray(1));let _=v.signature/2,T=d.subarray(0,_),C=d.subarray(_,_*2);return new L(c.fromBytes(T),c.fromBytes(C),w)}static fromHex(d,y){return this.fromBytes(Xt(d),y)}assertRecovery(){let{recovery:d}=this;if(d==null)throw new Error("invalid recovery id: must be present");return d}addRecoveryBit(d){return new L(this.r,this.s,d)}recoverPublicKey(d){let{r:y,s:w}=this,_=this.assertRecovery(),T=_===2||_===3?y+u:y;if(!a.isValid(T))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let C=a.toBytes(T),N=t.fromBytes(Fe(Yc((_&1)===0),C)),F=c.inv(T),Z=z(G(d,void 0,"msgHash")),$=c.create(-Z*F),le=c.create(w*F),ne=t.BASE.mulAddUnsafe($,N,le);if(ne.is0())throw new Error("invalid recovery: point at infinify");return ne.assertValidity(),ne}hasHighS(){return E(this.s)}toBytes(d=I.format){if(ai(d),d==="der")return Xt(Wn.hexFromSig(this));let{r:y,s:w}=this,_=c.toBytes(y),T=c.toBytes(w);return d==="recovered"?(k(),Fe(Uint8Array.of(this.assertRecovery()),_,T)):Fe(_,T)}toHex(d){return kr(this.toBytes(d))}}Object.freeze(L.prototype),Object.freeze(L);let H=o.bits2int===void 0?function(d){if(d.length>8192)throw new Error("input is too large");let y=Qe(d),w=d.length*8-f;return w>0?y>>BigInt(w):y}:o.bits2int,z=o.bits2int_modN===void 0?function(d){return c.create(H(d))}:o.bits2int_modN,J=Mr(f);function B(S){return Qt("num < 2^"+f,S,at,J),c.toBytes(S)}function M(S,d){return G(S,void 0,"message"),d?G(n(S),void 0,"prehashed message"):S}function K(S,d,y){let{lowS:w,prehash:_,extraEntropy:T}=si(y,I);S=M(S,_);let C=z(S),N=c.fromBytes(d);if(!c.isValidNot0(N))throw new Error("invalid private key");let F=[B(N),B(C)];if(T!=null&&T!==!1){let ne=T===!0?s(v.secretKey):T;F.push(G(ne,void 0,"extraEntropy"))}let Z=Fe(...F),$=C;function le(ne){let ge=H(ne);if(!c.isValidNot0(ge))return;let Re=t.BASE.multiply(ge).toAffine(),oe=c.create(Re.x);if(oe===at)return;let de;if(h!==void 0){let Sr=Qe(Dn(h(l),u)),ef=c.inv(c.mul(Sr,ge)),tf=c.mul(Sr,$),rf=c.mul(Sr,N);de=c.create(ef*c.create(tf+rf*oe))}else{let Sr=ac(ge,u);de=c.create(Sr*c.create($+oe*N))}if(de===at)return;let Io=U(Re.x,Re.y,oe),ra=de;return w&&E(de)&&(ra=c.neg(de),Io^=1),new L(oe,ra,g?void 0:Io)}return{seed:Z,k2sig:le}}function P(S,d,y={}){let{seed:w,k2sig:_}=K(S,d,y);return Ja(n.outputLen,c.BYTES,i)(w,_).toBytes(y.format)}function re(S,d,y,w={}){let{lowS:_,prehash:T,format:C}=si(w,I);if(y=G(y,void 0,"publicKey"),d=M(d,T),!wt(S)){let N=S instanceof L?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+N)}O(S,C);try{let N=L.fromBytes(S,C),F=t.fromBytes(y);if(F.is0()||_&&N.hasHighS())return!1;let{r:Z,s:$}=N,le=z(d),ne=c.inv($),ge=c.create(le*ne),Re=c.create(Z*ne),oe=t.BASE.mulAddUnsafe(ge,F,Re);if(oe.is0())return!1;let de=oe.toAffine();return!(c.create(de.x)!==Z||C==="recovered"&&N.recovery!==U(de.x,de.y,Z))}catch{return!1}}function ie(S,d,y={}){let{prehash:w}=si(y,I);return d=M(d,w),L.fromBytes(S,"recovered").recoverPublicKey(d).toBytes()}return Object.freeze({keygen:p,getPublicKey:x,getSharedSecret:m,utils:b,lengths:v,Point:t,sign:P,verify:re,recoverPublicKey:ie,Signature:L,hash:n})}var ui={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Yd={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Gc=BigInt(2);function Wd(t){let e=ui.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=t*t*t%e,f=u*u*t%e,l=se(f,r,e)*f%e,h=se(l,r,e)*f%e,p=se(h,Gc,e)*u%e,x=se(p,o,e)*p%e,m=se(x,s,e)*x%e,b=se(m,a,e)*m%e,v=se(b,c,e)*b%e,I=se(v,a,e)*m%e,g=se(I,r,e)*f%e,E=se(g,i,e)*x%e,A=se(E,n,e)*u%e,R=se(A,Gc,e);if(!ci.eql(ci.sqr(R),t))throw new Error("Cannot find square root");return R}var ci=tr(ui.p,{sqrt:Wd}),Zd=jc(ui,{Fp:ci,endo:Yd}),ir=Zc(Zd,Gt);function Xc(t,e,r,n){let o=Cr.digest(r instanceof Uint8Array?r:r.subarray());if(qn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),ir.verify(e,s,t,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Vr(String(s))});try{return n?.signal?.throwIfAborted(),ir.verify(e,o.digest,t,{prehash:!1,format:"der"})}catch(s){throw new Vr(String(s))}}var Zn=class{type="secp256k1";raw;_key;constructor(e){this._key=Jc(e),this.raw=Qc(this._key)}toMultihash(){return Ke.digest(Ge(this))}toCID(){return be.createV1(114,this.toMultihash())}toString(){return he.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:pe(this.raw,e.raw)}verify(e,r,n){return Xc(this._key,r,e,n)}};function fi(t){return new Zn(t)}function Qc(t){return ir.Point.fromBytes(t).toBytes()}function Jc(t){try{return ir.Point.fromBytes(t),t}catch(e){throw new It(String(e))}}function ar(t,e){let{Type:r,Data:n}=et.decode(t),o=n??new Uint8Array;switch(r){case ue.RSA:return ti(o,e);case ue.Ed25519:return Cs(o);case ue.secp256k1:return fi(o);case ue.ECDSA:return rs(o);default:throw new _t}}function eu(t){let{Type:e,Data:r}=et.decode(t.digest),n=r??new Uint8Array;switch(e){case ue.Ed25519:return Cs(n);case ue.secp256k1:return fi(n);case ue.ECDSA:return rs(n);default:throw new _t}}function Ge(t){return et.encode({Type:ue[t.type],Data:t.raw})}var Zr;(function(t){let e;t.codec=()=>(e==null&&(e=je((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.publicKey!=null&&s.publicKey.byteLength>0&&(i.uint32(10),i.bytes(s.publicKey)),s.payloadType!=null&&s.payloadType.byteLength>0&&(i.uint32(18),i.bytes(s.payloadType)),s.payload!=null&&s.payload.byteLength>0&&(i.uint32(26),i.bytes(s.payload)),s.signature!=null&&s.signature.byteLength>0&&(i.uint32(42),i.bytes(s.signature)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={publicKey:we(0),payloadType:we(0),payload:we(0),signature:we(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.publicKey=s.bytes();break}case 2:{c.payloadType=s.bytes();break}case 3:{c.payload=s.bytes();break}case 5:{c.signature=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.publicKey`,value:s.bytes()};break}case 2:{yield{field:`${a}.payloadType`,value:s.bytes()};break}case 3:{yield{field:`${a}.payload`,value:s.bytes()};break}case 5:{yield{field:`${a}.signature`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return He(s,t.codec())}t.encode=r;function n(s,i){return ze(s,t.codec(),i)}t.decode=n;function o(s,i){return $e(s,t.codec(),i)}t.stream=o})(Zr||(Zr={}));var Gn=class extends Error{constructor(e="Invalid signature"){super(e),this.name="InvalidSignatureError"}};var tt=class t{static createFromProtobuf=e=>{let r=Zr.decode(e),n=ar(r.publicKey);return new t({publicKey:n,payloadType:r.payloadType,payload:r.payload,signature:r.signature})};static seal=async(e,r,n)=>{if(r==null)throw new Error("Missing private key");let o=e.domain,s=e.codec,i=e.marshal(),a=tu(o,s,i),c=await r.sign(a.subarray(),n);return new t({publicKey:r.publicKey,payloadType:s,payload:i,signature:c})};static openAndCertify=async(e,r,n)=>{let o=t.createFromProtobuf(e);if(!await o.validate(r,n))throw new Gn("Envelope signature is not valid for the given domain");return o};publicKey;payloadType;payload;signature;marshaled;constructor(e){let{publicKey:r,payloadType:n,payload:o,signature:s}=e;this.publicKey=r,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=Zr.encode({publicKey:Ge(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(e){return e==null?!1:pe(this.marshal(),e.marshal())}async validate(e,r){let n=tu(e,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},tu=(t,e,r)=>{let n=q(t),o=or(n.byteLength),s=or(e.length),i=or(r.length);return new me(o,n,s,e,i,r)};var ru=Symbol.for("nodejs.util.inspect.custom"),Gd=114,Gr=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Bo]=!0;toString(){return this.string==null&&(this.string=he.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return be.createV1(Gd,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return pe(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return pe(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[ru](){return`PeerId(${this.toString()})`}},Xr=class extends Gr{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Qr=class extends Gr{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Jr=class extends Gr{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},Xd=2336,Xn=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Ke.digest(q(this.url))}[ru](){return`PeerId(${this.url})`}[Bo]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return be.createV1(Xd,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=j(e)),e.toString()===this.toString())}};function en(t){if(t.type==="Ed25519")return new Qr({multihash:t.toCID().multihash,publicKey:t});if(t.type==="secp256k1")return new Jr({multihash:t.toCID().multihash,publicKey:t});if(t.type==="RSA")return new Xr({multihash:t.toCID().multihash,publicKey:t});throw new _t}function nu(t){if(Jd(t))return new Xr({multihash:t});if(Qd(t))try{let e=eu(t);if(e.type==="Ed25519")return new Qr({multihash:t,publicKey:e});if(e.type==="secp256k1")return new Jr({multihash:t,publicKey:e})}catch{let r=j(t.digest);return new Xn(new URL(r))}throw new ln("Supplied PeerID Multihash is invalid")}function Qd(t){return t.code===Ke.code}function Jd(t){return t.code===Cr.code}var Ee=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},ct=class extends Error{static name="ValidationError";name="ValidationError"},Qn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Jn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var eo=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let r=this.index,n=e();return n===void 0&&(this.index=r),n}parseWith(e){let r=e();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let r=this.readChar();if(r===e)return r})}readSeparator(e,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,r,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let h=Number.parseInt(l,e);if(!Number.isNaN(h))return h});if(f===void 0)break;if(s*=e,s+=f,s>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let r=0;r<e.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[r]=n}return e})}readIPv6Addr(){let e=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=e(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var ou=45,eh=15,cr=new eo;function to(t){if(!(t.length>eh))return cr.new(t).parseWith(()=>cr.readIPv4Addr())}function ro(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>ou))return cr.new(t).parseWith(()=>cr.readIPv6Addr())}function ur(t,e=!1){if(t.includes("%")&&(t=t.split("%")[0]),t.length>ou)return;let r=cr.new(t).parseWith(()=>cr.readIPAddr());if(r)return e&&r.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,r[0],r[1],r[2],r[3]]):r}function fr(t){return!!to(t)}function no(t){return!!ro(t)}function di(t){return e=>j(e,t)}function hi(t){return e=>q(e,t)}function lr(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function Ut(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function su(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let r=q(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Ut(n);return Ze([r,o],r.length+o.length)}function iu(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let r=dt.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Ut(n);return Ze([r,o],r.length+o.length)}function pi(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=j(e,"base32"),o=lr(r);return`${n}:${o}`}var mi=function(t){t=t.toString().trim();let e=new Uint8Array(4);return t.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new Ee("Invalid byte value in IP address");e[n]=o}),e},au=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let s=fr(r[n]),i;s&&(i=mi(r[n]),r[n]=j(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,j(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(e+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new Ee("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},cu=function(t){if(t.byteLength!==4)throw new Ee("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},uu=function(t){if(t.byteLength!==16)throw new Ee("IPv6 address was incorrect length");let e=[];for(let n=0;n<t.byteLength;n+=2){let o=t[n],s=t[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;e.push(i)}let r=e.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new Ee(`Invalid IPv6 address "${r}"`)}};function fu(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new Ee(`Invalid IPv6 address "${t}"`)}}var li=Object.values(Or).map(t=>t.decoder),th=(function(){let t=li[0].or(li[1]);return li.slice(2).forEach(e=>t=t.or(e)),t})();function lu(t){return th.decode(t)}function du(t){return e=>t.encoder.encode(e)}function rh(t){if(parseInt(t).toString()!==t)throw new ct("Value must be an integer")}function nh(t){if(t<0)throw new ct("Value must be a positive integer, or zero")}function oh(t){return e=>{if(e>t)throw new ct(`Value must be smaller than or equal to ${t}`)}}function sh(...t){return e=>{for(let r of t)r(e)}}var tn=sh(rh,nh,oh(65535));var xe=-1,yi=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let r;if(typeof e=="string"?r=this.protocolsByName.get(e):r=this.protocolsByCode.get(e),r==null)throw new Jn(`Protocol ${e} was unknown`);return r}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(r=>{this.protocolsByName.set(r,e)})}removeProtocol(e){let r=this.protocolsByCode.get(e);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},ft=new yi,wh=[{code:4,name:"ip4",size:32,valueToBytes:mi,bytesToValue:cu,validate:t=>{if(!fr(t))throw new ct(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Ut,bytesToValue:lr,validate:tn},{code:273,name:"udp",size:16,valueToBytes:Ut,bytesToValue:lr,validate:tn},{code:33,name:"dccp",size:16,valueToBytes:Ut,bytesToValue:lr,validate:tn},{code:41,name:"ip6",size:128,valueToBytes:au,bytesToValue:uu,stringToValue:fu,validate:t=>{if(!no(t))throw new ct(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:xe},{code:43,name:"ipcidr",size:8,bytesToValue:di("base10"),valueToBytes:hi("base10")},{code:53,name:"dns",size:xe},{code:54,name:"dns4",size:xe},{code:55,name:"dns6",size:xe},{code:56,name:"dnsaddr",size:xe},{code:132,name:"sctp",size:16,valueToBytes:Ut,bytesToValue:lr,validate:tn},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:xe,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:xe,bytesToValue:di("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?hi("base58btc")(t):be.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:pi,valueToBytes:su},{code:445,name:"onion3",size:296,bytesToValue:pi,valueToBytes:iu},{code:446,name:"garlic64",size:xe},{code:447,name:"garlic32",size:xe},{code:448,name:"tls"},{code:449,name:"sni",size:xe},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:xe,bytesToValue:du(zo),valueToBytes:lu},{code:480,name:"http"},{code:481,name:"http-path",size:xe,stringToValue:t=>`/${decodeURIComponent(t)}`,valueToString:t=>encodeURIComponent(t.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:xe}];wh.forEach(t=>{ft.addProtocol(t)});function hu(t){let e=[],r=0;for(;r<t.length;){let n=zr(t,r),o=ft.getProtocol(n),s=De(n),i=xh(o,t,r+s),a=0;i>0&&o.size===xe&&(a=De(i));let c=s+a+i,u={code:n,name:o.name,bytes:_e(t.subarray(r,r+c))};if(i>0){let f=r+s+a,l=t.subarray(f,f+i);u.value=o.bytesToValue?.(l)??j(l)}e.push(u),r+=c}return e}function pu(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let o=ft.getProtocol(n.code),s=De(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??q(n.value),a=i.byteLength,o.size===xe&&(c=De(a)));let u=new Uint8Array(s+c+a),f=0;nr(n.code,u,f),f+=s,i!=null&&(o.size===xe&&(nr(a,u,f),f+=c),u.set(i,f)),n.bytes=u}r.push(n.bytes),e+=n.bytes.byteLength}return Ze(r,e)}function mu(t){if(t.charAt(0)!=="/")throw new Ee('String multiaddr must start with "/"');let e=[],r="protocol",n="",o="";for(let s=1;s<t.length;s++){let i=t.charAt(s);i!=="/"&&(r==="protocol"?o+=t.charAt(s):n+=t.charAt(s));let a=s===t.length-1;if(i==="/"||a){let c=ft.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new Ee(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new Ee(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}e.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new Ee("Incomplete multiaddr");return e}function yu(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=ft.getProtocol(e.code);if(r==null)throw new Ee(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function xh(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:zr(e,r)}var Eh=Symbol.for("nodejs.util.inspect.custom"),Di=Symbol.for("@multiformats/multiaddr");function vh(t){if(t==null&&(t="/"),gu(t))return t.getComponents();if(t instanceof Uint8Array)return hu(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),mu(t);if(Array.isArray(t))return t;throw new Ee("Must be a string, Uint8Array, Component[], or another Multiaddr")}var uo=class t{[Di]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=vh(e),r.validate!==!1&&Sh(this)}get bytes(){return this.#r==null&&(this.#r=pu(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=yu(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}encapsulate(e){let r=new t(e);return new t([...this.#e,...r.getComponents()],{validate:!1})}decapsulate(e){let r=e.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new Qn(`Address ${this.toString()} does not contain subaddress: ${r}`);return new t(n.slice(0,o),{validate:!1})}decapsulateCode(e){let r;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){r=n;break}return new t(this.#e.slice(0,r),{validate:!1})}equals(e){return pe(this.bytes,e.bytes)}[Eh](){return`Multiaddr(${this.toString()})`}};function Sh(t){t.getComponents().forEach(e=>{let r=ft.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function gu(t){return!!t?.[Di]}function nn(t){return new uo(t)}var bu="libp2p-peer-record",wu=Uint8Array.from([3,1]);var on;(function(t){let e;(function(i){let a;i.codec=()=>(a==null&&(a=je((l,h,p={})=>{p.lengthDelimited!==!1&&h.fork(),l.multiaddr!=null&&l.multiaddr.byteLength>0&&(h.uint32(10),h.bytes(l.multiaddr)),p.lengthDelimited!==!1&&h.ldelim()},(l,h,p={})=>{let x={multiaddr:we(0)},m=h==null?l.len:l.pos+h;for(;l.pos<m;){let b=l.uint32();b>>>3===1?x.multiaddr=l.bytes():l.skipType(b&7)}return x},function*(l,h,p,x={}){let m=h==null?l.len:l.pos+h;for(;l.pos<m;){let b=l.uint32();b>>>3===1?yield{field:`${p}.multiaddr`,value:l.bytes()}:l.skipType(b&7)}})),a);function c(l){return He(l,i.codec())}i.encode=c;function u(l,h){return ze(l,i.codec(),h)}i.decode=u;function f(l,h){return $e(l,i.codec(),h)}i.stream=f})(e=t.AddressInfo||(t.AddressInfo={}));let r;t.codec=()=>(r==null&&(r=je((i,a,c={})=>{if(c.lengthDelimited!==!1&&a.fork(),i.peerId!=null&&i.peerId.byteLength>0&&(a.uint32(10),a.bytes(i.peerId)),i.seq!=null&&i.seq!==0n&&(a.uint32(16),a.uint64(i.seq)),i.addresses!=null&&i.addresses.length>0)for(let u of i.addresses)a.uint32(26),t.AddressInfo.codec().encode(u,a);c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let u={peerId:we(0),seq:0n,addresses:[]},f=a==null?i.len:i.pos+a;for(;i.pos<f;){let l=i.uint32();switch(l>>>3){case 1:{u.peerId=i.bytes();break}case 2:{u.seq=i.uint64();break}case 3:{if(c.limits?.addresses!=null&&u.addresses.length===c.limits.addresses)throw new Je('Decode error - repeated field "addresses" had too many elements');u.addresses.push(t.AddressInfo.codec().decode(i,i.uint32(),{limits:c.limits?.addresses$}));break}default:{i.skipType(l&7);break}}}return u},function*(i,a,c,u={}){let f={addresses:0},l=a==null?i.len:i.pos+a;for(;i.pos<l;){let h=i.uint32();switch(h>>>3){case 1:{yield{field:`${c}.peerId`,value:i.bytes()};break}case 2:{yield{field:`${c}.seq`,value:i.uint64()};break}case 3:{if(u.limits?.addresses!=null&&f.addresses===u.limits.addresses)throw new Je('Streaming decode error - repeated field "addresses" had too many elements');for(let p of t.AddressInfo.codec().stream(i,i.uint32(),`${c}.addresses[]`,{limits:u.limits?.addresses$}))yield{...p,index:f.addresses};f.addresses++;break}default:{i.skipType(h&7);break}}}})),r);function n(i){return He(i,t.codec())}t.encode=n;function o(i,a){return ze(i,t.codec(),a)}t.decode=o;function s(i,a){return $e(i,t.codec(),a)}t.stream=s})(on||(on={}));function xu(t,e){let r=(n,o)=>n.toString().localeCompare(o.toString());return t.length!==e.length?!1:(e.sort(r),t.sort(r).every((n,o)=>e[o].equals(n)))}var Ye=class t{static createFromProtobuf=e=>{let r=on.decode(e),n=nu(Br(r.peerId)),o=(r.addresses??[]).map(i=>nn(i.multiaddr)),s=r.seq;return new t({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=bu;static CODEC=wu;peerId;multiaddrs;seqNumber;domain=t.DOMAIN;codec=t.CODEC;marshaled;constructor(e){let{peerId:r,multiaddrs:n,seqNumber:o}=e;this.peerId=r,this.multiaddrs=n??[],this.seqNumber=o??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=on.encode({peerId:this.peerId.toMultihash().bytes,seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(e=>({multiaddr:e.bytes}))})),this.marshaled}equals(e){return!(!(e instanceof t)||!this.peerId.equals(e.peerId)||this.seqNumber!==e.seqNumber||!xu(this.multiaddrs,e.multiaddrs))}};function Ah(t){let e=t.getComponents(),r={},n=0;return e[n]?.name==="ip6zone"&&(r.zone=`${e[n].value}`,n++),e[n]?.name==="ip4"||e[n]?.name==="ip6"||e[n]?.name==="dns"||e[n]?.name==="dns4"||e[n]?.name==="dns6"?(r.type=e[n].name,r.host=e[n].value,n++):e[n]?.name==="dnsaddr"&&(r.type=e[n].name,r.host=`_dnsaddr.${e[n].value}`,n++),(e[n]?.name==="tcp"||e[n]?.name==="udp")&&(r.protocol=e[n].name==="tcp"?"tcp":"udp",r.port=parseInt(`${e[n].value}`),n++),e[n]?.name==="ipcidr"&&(r.type==="ip4"?r.cidr=parseInt(`${e[n].value}`):r.type==="ip6"&&(r.cidr=`${e[n].value}`),n++),r.type==null||r.host==null?null:(e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(r.sni=e[n+1].value,n+=2),r)}function fo(t){let e=Ah(t);if(e==null)throw new ae(`Multiaddr ${t} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}function Eu(t,e,r){let n=0;for(let o of t)if(!(n<e)){if(n>r)break;if(o!==255)return!1;n++}return!0}function vu(t,e,r,n){let o=0;for(let s of t)if(!(o<r)){if(o>n)break;if(s!==e[o])return!1;o++}return!0}function Pi(t){switch(t.length){case Kt:return t.join(".");case qt:{let e=[];for(let r=0;r<t.length;r++)r%2===0&&e.push(t[r].toString(16).padStart(2,"0")+t[r+1].toString(16).padStart(2,"0"));return e.join(":")}default:throw new Error("Invalid ip length")}}function Su(t){let e=0;for(let[r,n]of t.entries()){if(n===255){e+=8;continue}for(;(n&128)!=0;)e++,n=n<<1;if((n&128)!=0)return-1;for(let o=r+1;o<t.length;o++)if(t[o]!=0)return-1;break}return e}function Au(t){let e="0x";for(let r of t)e+=(r>>4).toString(16)+(r&15).toString(16);return e}var Kt=4,qt=16,xx=parseInt("0xFFFF",16),Ih=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function sn(t,e){e.length===qt&&t.length===Kt&&Eu(e,0,11)&&(e=e.slice(12)),e.length===Kt&&t.length===qt&&vu(t,Ih,0,11)&&(t=t.slice(12));let r=t.length;if(r!=e.length)throw new Error("Failed to mask ip");let n=new Uint8Array(r);for(let o=0;o<r;o++)n[o]=t[o]&e[o];return n}function Iu(t,e){if(typeof e=="string"&&(e=ur(e)),e==null)throw new Error("Invalid ip");if(e.length!==t.network.length)return!1;for(let r=0;r<e.length;r++)if((t.network[r]&t.mask[r])!==(e[r]&t.mask[r]))return!1;return!0}function Li(t){let[e,r]=t.split("/");if(!e||!r)throw new Error("Failed to parse given CIDR: "+t);let n=Kt,o=to(e);if(o==null&&(n=qt,o=ro(e),o==null))throw new Error("Failed to parse given CIDR: "+t);let s=parseInt(r,10);if(Number.isNaN(s)||String(s).length!==r.length||s<0||s>n*8)throw new Error("Failed to parse given CIDR: "+t);let i=Ri(s,8*n);return{network:sn(o,i),mask:i}}function Ri(t,e){if(e!==8*Kt&&e!==8*qt)throw new Error("Invalid CIDR mask");if(t<0||t>e)throw new Error("Invalid CIDR mask");let r=e/8,n=new Uint8Array(r);for(let o=0;o<r;o++){if(t>=8){n[o]=255,t-=8;continue}n[o]=255-(255>>t),t=0}return n}var an=class{constructor(e,r){if(r==null)({network:this.network,mask:this.mask}=Li(e));else{let n=ur(e);if(n==null)throw new Error("Failed to parse network");r=String(r);let o=parseInt(r,10);if(Number.isNaN(o)||String(o).length!==r.length||o<0||o>n.length*8){let s=ur(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Ri(o,8*n.length);this.network=sn(n,this.mask)}}contains(e){return Iu({network:this.network,mask:this.mask},e)}toString(){let e=Su(this.mask),r=e!==-1?String(e):Au(this.mask);return Pi(this.network)+"/"+r}};function _u(t,e){return new an(t).contains(e)}function Bu(t){try{let e=fo(t);return e.type==="ip6"?_u("2000::/3",e.host):!1}catch{return!1}}var Du=uf(Ou(),1),Ph=["0.0.0.0/8","10.0.0.0/8","100.64.0.0/10","127.0.0.0/8","169.254.0.0/16","172.16.0.0/12","192.0.0.0/24","192.0.0.0/29","192.0.0.8/32","192.0.0.9/32","192.0.0.10/32","192.0.0.170/32","192.0.0.171/32","192.0.2.0/24","192.31.196.0/24","192.52.193.0/24","192.88.99.0/24","192.168.0.0/16","192.175.48.0/24","198.18.0.0/15","198.51.100.0/24","203.0.113.0/24","240.0.0.0/4","255.255.255.255/32"],Lh=Ph.map(t=>new Du.Netmask(t));function qi(t){for(let e of Lh)if(e.contains(t))return!0;return!1}function Rh(t){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(t)}function Nh(t){let e=t.split(":");if(e.length<2)return!1;let r=e[e.length-1].padStart(4,"0"),n=e[e.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(r.substring(0,2),16)}.${parseInt(r.substring(2),16)}`;return qi(o)}function kh(t){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)}function Fh(t){let e=t.split(":"),r=e[e.length-1];return qi(r)}function Uh(t){return/^::$/.test(t)||/^::1$/.test(t)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(t)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(t)||/^ff([0-9a-fA-F]{2,2}):/i.test(t)}function Pu(t){if(fr(t))return qi(t);if(Rh(t))return Nh(t);if(kh(t))return Fh(t);if(no(t))return Uh(t)}function Lu(t){try{let e=fo(t);switch(e.type){case"ip4":case"ip6":return Pu(e.host)??!1;default:return e.host==="localhost"}}catch{return!1}}var ee=t=>({match:e=>{let r=e[0];return r==null||r.code!==t||r.value!=null?!1:e.slice(1)}}),D=(t,e)=>({match:r=>{let n=r[0];return n?.code!==t||n.value==null||e!=null&&n.value!==e?!1:r.slice(1)}}),Ru=t=>({match:e=>t.match(e)===!1?e:!1}),V=t=>({match:e=>{let r=t.match(e);return r===!1?e:r}}),Ie=(...t)=>({match:e=>{let r;for(let n of t){let o=n.match(e);o!==!1&&(r==null||o.length<r.length)&&(r=o)}return r??!1}}),W=(...t)=>({match:e=>{for(let r of t){let n=r.match(e);if(n===!1)return!1;e=n}return e}});function te(...t){function e(o){if(o==null)return!1;let s=o.getComponents();for(let i of t){let a=i.match(s);if(a===!1)return!1;s=a}return s}function r(o){return e(o)!==!1}function n(o){let s=e(o);return s===!1?!1:s.length===0}return{matchers:t,matches:r,exactMatch:n}}var Mh=D(421),Qx=te(Mh),po=D(54),mo=D(55),yo=D(56),zi=D(53),Jx=te(po,V(D(421))),e1=te(mo,V(D(421))),t1=te(yo,V(D(421))),r1=te(Ie(zi,yo,po,mo),V(D(421))),Nu=W(D(4),V(D(43))),ku=W(V(D(42)),D(41),V(D(43))),Hi=Ie(Nu,ku),wr=Ie(Hi,zi,po,mo,yo),Fu=te(Ie(Hi,W(Ie(zi,yo,po,mo),V(D(421))))),n1=te(Nu),o1=te(ku),s1=te(Hi),$i=W(wr,D(6)),cn=W(wr,D(273)),Uu=te(W($i,V(D(421)))),i1=te(cn),ji=W(cn,ee(460),V(D(421))),go=W(cn,ee(461),V(D(421))),Kh=Ie(ji,go),a1=te(ji),c1=te(go),Vi=Ie(wr,$i,cn,ji,go),Mu=Ie(W(Vi,ee(477),V(D(421)))),u1=te(Mu),Ku=Ie(W(Vi,ee(478),V(D(421))),W(Vi,ee(448),V(D(449)),ee(477),V(D(421)))),f1=te(Ku),qu=W(cn,ee(280),V(D(466)),V(D(466)),V(D(421))),l1=te(qu),Vu=W(go,ee(465),V(D(466)),V(D(466)),V(D(421))),d1=te(Vu),ho=Ie(Mu,Ku,W($i,V(D(421))),W(Kh,V(D(421))),W(wr,V(D(421))),qu,Vu,D(421)),h1=te(ho),qh=W(V(ho),ee(290),Ru(ee(281)),V(D(421))),p1=te(qh),Vh=Ie(W(ho,ee(290),ee(281),V(D(421))),W(ho,ee(281),V(D(421))),W(ee(281),V(D(421)))),m1=te(Vh),zh=W(wr,Ie(W(D(6,"80")),W(D(6),ee(480)),ee(480)),V(D(481)),V(D(421))),y1=te(zh),Hh=W(wr,Ie(W(D(6,"443")),W(D(6,"443"),ee(480)),W(D(6),ee(443)),W(D(6),ee(448),ee(480)),W(ee(448),ee(480)),ee(448),ee(443)),V(D(481)),V(D(421))),g1=te(Hh),$h=Ie(W(D(777),V(D(421)))),b1=te($h),jh=Ie(W(D(400),V(D(421)))),w1=te(jh);function xr(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Yi=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},zu=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function Wi(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=e,a,c,f=new Promise((l,h)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){h(zu(i)),t.then(l,h);return}if(i&&(c=()=>{h(zu(i))},i.addEventListener("abort",c,{once:!0})),t.then(l,h),r===Number.POSITIVE_INFINITY)return;let p=new Yi;a=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(x){h(x)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?l():o instanceof Error?h(o):(p.message=o??`Promise timed out after ${r} milliseconds`,h(p))},r)}).finally(()=>{f.clear(),c&&i&&i.removeEventListener("abort",c)});return f.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},f}var Hu=t=>typeof t=="function"?{filter:t}:{...t},Yh=t=>t===1/0||Number.isSafeInteger(t)&&t>=0,Wh=[["addEventListener","removeEventListener"],["on","off"],["addListener","removeListener"]],Zh=t=>{for(let[e,r]of Wh){let n=t?.[e],o=t?.[r];if(typeof n=="function"&&typeof o=="function")return{addListener:n.bind(t),removeListener:o.bind(t)}}throw new TypeError("Emitter is not compatible")},Gh=t=>{let e=new Map;for(let[r,n]of t)for(let o of Array.isArray(r)?r:[r])e.has(o)||e.set(o,n);return e},Xh=({addListener:t,removeListener:e,handlers:r,signal:n,abortHandler:o,isDone:s})=>{n?.addEventListener("abort",o,{once:!0});for(let[i,a]of r)if(t(i,a),s()){e(i,a);return}},Qh=({removeListener:t,handlers:e,signal:r,abortHandler:n})=>{for(let[o,s]of e)t(o,s);r?.removeEventListener("abort",n)},Jh=(t,e,r)=>{let n=Promise.resolve();return(o,s)=>{n=n.then(async()=>{if(e())return;let i;try{i=t?await t(o):!0}catch(a){e()||r(a);return}e()||s(i)})}};function ep(t,e,r){let n=()=>{},o=!1,s,i=new Promise((a,c)=>{r=Hu(r);let{filter:u}=r;if(!Yh(r.count))throw new TypeError("The `count` option should be at least 0 or more");if(typeof r.timeout=="number"&&!(r.timeout>0))throw new TypeError(`Expected the \`timeout\` option to be a positive number, got \`${r.timeout}\``);r.signal?.throwIfAborted();let{addListener:f,removeListener:l}=Zh(t);if(r.count===0){a([]);return}let h=[],p=E=>{n(),c(E)},x=Jh(u,()=>o,p),m=E=>{h.push(E),r.count===h.length&&(n(),a(h))},b=(...E)=>{if(o)return;let A=r.multiArgs?E:E[0];if(!u){m(A);return}x(A,R=>{R&&m(A)})},v=(...E)=>{p(r.rejectionMultiArgs?E:E[0])},I=()=>{p(r.signal.reason)},g={addListener:f,removeListener:l,handlers:Gh([[e,b],[r.rejectionEvents??["error"],v]]),signal:r.signal,abortHandler:I,isDone:()=>o};n=()=>{o=!0,clearTimeout(s),Qh(g)},Xh(g),!(o||!r.resolveImmediately)&&(Number.isFinite(r.timeout)&&(s=setTimeout(n,r.timeout)),a(h))});if(i.cancel=n,typeof r.timeout=="number"&&r.timeout>0&&!r.resolveImmediately){let a=Wi(i,{milliseconds:r.timeout});return a.cancel=()=>{n(),a.clear()},a}return i}function $u(t,e,r){let n=ep(t,e,{...Hu(r),count:1,resolveImmediately:!1}),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function ju(t,e){let r,n=function(){let o=function(){r=void 0,t()};clearTimeout(r),r=setTimeout(o,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var zt=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function tp(t){return t.reason}function Zi(t,e,r){if(e==null||t==null)return t;let n=r?.translateError??tp;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;return Promise.race([t,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})]).finally(()=>{o!=null&&e.removeEventListener("abort",o)})}var np=4194304,bo=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Xi=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Qi=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Ji=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function op(t){return typeof t?.closeRead=="function"}function sp(t){return typeof t?.close=="function"}function Gi(t){return op(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:sp(t)?t.status!=="open":!1}function ip(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function ap(t,e){let r=e?.maxBufferSize??np,n=new me,o,s=!1,i;if(!ip(t))throw new ae("Argument should be a Stream or a Multiaddr");let a=l=>{if(!s&&i==null){if(n.append(l.data),n.byteLength>r){let h=n.byteLength;n.consume(h);let p=new fn(`Read buffer overflow - ${h} > ${r}`);i=p,o?.reject(p),queueMicrotask(()=>{t.abort(p)});return}o?.resolve()}};t.addEventListener("message",a);let c=l=>{l.error!=null?o?.reject(l.error):o?.resolve()};t.addEventListener("close",c);let u=()=>{o?.resolve()};t.addEventListener("remoteCloseWrite",u);let f={readBuffer:n,async read(l){if(s===!0)throw new bo("Stream was unwrapped");if(i!=null)throw i;if(Gi(t)){if(n.byteLength===0&&l?.bytes==null)return null;if(l?.bytes!=null&&n.byteLength<l.bytes)throw t.log.error("closed after reading %d/%d bytes",n.byteLength,l.bytes),new zt(`Unexpected EOF - stream closed after reading ${n.byteLength}/${l.bytes} bytes`)}let h=l?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=h){o.resolve();break}if(await Zi(o.promise,l?.signal),Gi(t)){if(n.byteLength===0&&l?.bytes==null)return null;break}o=Promise.withResolvers()}let p=l?.bytes??n.byteLength;if(n.byteLength<p){if(Gi(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,p),new zt(`Unexpected EOF - stream closed while reading ${n.byteLength}/${p} bytes`);return f.read(l)}let x=n.sublist(0,p);return n.consume(p),x},async write(l,h){if(s===!0)throw new bo("Stream was unwrapped");t.send(l)||await $u(t,"drain",{signal:h?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,t.removeEventListener("message",a),t.removeEventListener("close",c),t.removeEventListener("remoteCloseWrite",u),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.unshift(n),n.consume(n.byteLength))),t}};return f}function cp(t,e={}){let r=ap(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=De(e.maxDataLength));let n=e?.lengthDecoder??zr,o=e?.lengthEncoder??or;return{async read(i){let a=-1,c=new me;for(;;){let f=await r.read({...i,bytes:1});if(f==null)break;c.append(f);try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new Xi("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new Ji(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new Qi(`Message length too long - ${a} > ${e.maxDataLength}`);let u=await r.read({...i,bytes:a});if(u==null)throw t.log.error("tried to read %d bytes but the stream closed",a),new zt(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw t.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new zt(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await r.write(new me(o(i.byteLength),i),a)},async writeV(i,a){let c=new me(...i.flatMap(u=>[o(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}function Er(t,e){let r=cp(t,e),n={read:async(o,s)=>{let i=await r.read(s);return o.decode(i,s)},write:async(o,s,i)=>{await r.write(s.encode(o),i)},writeV:async(o,s,i)=>{await r.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}function up(t){return t[Symbol.asyncIterator]!=null}function fp(t){if(up(t))return(async()=>{for await(let e of t);})();for(let e of t);}var Yu=fp;var wo=globalThis.CustomEvent??Event;async function*ea(t,e={}){let r=e.concurrency??1/0;r<1&&(r=1/0);let n=e.ordered??!1,o=new EventTarget,s=[],i=xr(),a=xr(),c=!1,u,f=!1,l=!1;o.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let m of t){if(s.length===r&&(i=xr(),await i.promise),f||l)break;let b={done:!1};s.push(b),m().then(v=>{b.done=!0,b.ok=!0,b.value=v,o.dispatchEvent(new wo("task-complete"))},v=>{b.done=!0,b.err=v,o.dispatchEvent(new wo("task-complete"))})}c=!0,o.dispatchEvent(new wo("task-complete"))}catch(m){u=m,o.dispatchEvent(new wo("task-complete"))}});function h(){return n?s[0]?.done:!!s.find(m=>m.done)}function*p(){for(;s.length>0&&s[0].done;){let m=s[0];if(s.shift(),m.ok)yield m.value;else throw f=!0,i.resolve(),m.err;i.resolve()}}function*x(){for(;h();)for(let m=0;m<s.length;m++)if(s[m].done){let b=s[m];if(s.splice(m,1),m--,b.ok)yield b.value;else throw f=!0,i.resolve(),b.err;i.resolve()}}try{for(;;){if(h()||(a=xr(),await a.promise),u!=null||(n?yield*p():yield*x(),u!=null))throw u;if(c&&s.length===0)break}}finally{l=!0,i.resolve()}}var Wu="0.1.0";var Zu="id/push",Gu="1.0.0",Xu="1.0.0";var At;(function(t){let e;t.codec=()=>(e==null&&(e=je((s,i,a={})=>{if(a.lengthDelimited!==!1&&i.fork(),s.protocolVersion!=null&&(i.uint32(42),i.string(s.protocolVersion)),s.agentVersion!=null&&(i.uint32(50),i.string(s.agentVersion)),s.publicKey!=null&&(i.uint32(10),i.bytes(s.publicKey)),s.listenAddrs!=null&&s.listenAddrs.length>0)for(let c of s.listenAddrs)i.uint32(18),i.bytes(c);if(s.observedAddr!=null&&(i.uint32(34),i.bytes(s.observedAddr)),s.protocols!=null&&s.protocols.length>0)for(let c of s.protocols)i.uint32(26),i.string(c);s.signedPeerRecord!=null&&(i.uint32(66),i.bytes(s.signedPeerRecord)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={listenAddrs:[],protocols:[]},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 5:{c.protocolVersion=s.string();break}case 6:{c.agentVersion=s.string();break}case 1:{c.publicKey=s.bytes();break}case 2:{if(a.limits?.listenAddrs!=null&&c.listenAddrs.length===a.limits.listenAddrs)throw new Je('Decode error - repeated field "listenAddrs" had too many elements');c.listenAddrs.push(s.bytes());break}case 4:{c.observedAddr=s.bytes();break}case 3:{if(a.limits?.protocols!=null&&c.protocols.length===a.limits.protocols)throw new Je('Decode error - repeated field "protocols" had too many elements');c.protocols.push(s.string());break}case 8:{c.signedPeerRecord=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u={listenAddrs:0,protocols:0},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let l=s.uint32();switch(l>>>3){case 5:{yield{field:`${a}.protocolVersion`,value:s.string()};break}case 6:{yield{field:`${a}.agentVersion`,value:s.string()};break}case 1:{yield{field:`${a}.publicKey`,value:s.bytes()};break}case 2:{if(c.limits?.listenAddrs!=null&&u.listenAddrs===c.limits.listenAddrs)throw new Je('Streaming decode error - repeated field "listenAddrs" had too many elements');yield{field:`${a}.listenAddrs[]`,index:u.listenAddrs,value:s.bytes()},u.listenAddrs++;break}case 4:{yield{field:`${a}.observedAddr`,value:s.bytes()};break}case 3:{if(c.limits?.protocols!=null&&u.protocols===c.limits.protocols)throw new Je('Streaming decode error - repeated field "protocols" had too many elements');yield{field:`${a}.protocols[]`,index:u.protocols,value:s.string()},u.protocols++;break}case 8:{yield{field:`${a}.signedPeerRecord`,value:s.bytes()};break}default:{s.skipType(l&7);break}}}})),e);function r(s){return He(s,t.codec())}t.encode=r;function n(s,i){return ze(s,t.codec(),i)}t.decode=n;function o(s,i){return $e(s,t.codec(),i)}t.stream=o})(At||(At={}));var Pe={protocolPrefix:"ipfs",timeout:5e3,maxInboundStreams:1,maxOutboundStreams:1,maxObservedAddresses:10,maxMessageSize:8192,runOnConnectionOpen:!0,runOnSelfUpdate:!0,runOnLimitedConnection:!0,concurrency:32};function Ju(t){return t.bytes.length===0}function ta(t){if(t!=null&&t.length>0)try{let e=nn(t);if(!Ju(e))return e}catch{}}async function xo(t,e,r,n,o){if(r("received identify from %p",n.remotePeer),o==null)throw new Me("message was null or undefined");let s={},i=o.listenAddrs.map(ta).filter(u=>u!=null);if(o.listenAddrs.length>0&&(s.addresses=i.map(u=>({isCertified:!1,multiaddr:u}))),o.protocols.length>0&&(s.protocols=o.protocols),o.publicKey!=null){let u=ar(o.publicKey);if(!en(u).equals(n.remotePeer))throw new Me("public key did not match remote PeerId");s.publicKey=u}let a;if(o.signedPeerRecord!=null){r.trace("received signedPeerRecord from %p",n.remotePeer);let u=o.signedPeerRecord,f=await tt.openAndCertify(u,Ye.DOMAIN),l=Ye.createFromProtobuf(f.payload),h=en(f.publicKey);if(!l.peerId.equals(h))throw new Me("signing key does not match PeerId in the PeerRecord");if(!n.remotePeer.equals(l.peerId))throw new Me("signing key does not match remote PeerId");let p;try{p=await t.get(l.peerId)}catch(m){if(m.name!=="NotFoundError")throw m}if(p!=null&&(s.metadata=p.metadata,p.peerRecordEnvelope!=null)){let m=tt.createFromProtobuf(p.peerRecordEnvelope),b=Ye.createFromProtobuf(m.payload);b.seqNumber>=l.seqNumber&&(r("sequence number was lower or equal to existing sequence number - stored: %d received: %d",b.seqNumber,l.seqNumber),l=b,u=p.peerRecordEnvelope)}s.peerRecordEnvelope=u;let x=l.multiaddrs.filter(m=>!Ju(m));s.addresses=x.map(m=>({isCertified:!0,multiaddr:m})),a={seq:l.seqNumber,addresses:x}}else r("%p did not send a signed peer record",n.remotePeer);if(r.trace("patching %p with",n.remotePeer,s),await t.patch(n.remotePeer,s),o.agentVersion!=null||o.protocolVersion!=null){let u={};o.agentVersion!=null&&(u.AgentVersion=q(o.agentVersion)),o.protocolVersion!=null&&(u.ProtocolVersion=q(o.protocolVersion)),r.trace("merging %p metadata",n.remotePeer,u),await t.merge(n.remotePeer,{metadata:u})}let c={peerId:n.remotePeer,protocolVersion:o.protocolVersion,agentVersion:o.agentVersion,publicKey:o.publicKey,listenAddrs:i,observedAddr:o.observedAddr==null?void 0:nn(o.observedAddr),protocols:o.protocols,signedPeerRecord:a,connection:n};return e.safeDispatchEvent("peer:identify",{detail:c}),c}function Eo(t){let e={...t[0]};for(let r of t.slice(1))r.protocolVersion!=null&&(e.protocolVersion=r.protocolVersion),r.agentVersion!=null&&(e.agentVersion=r.agentVersion),r.publicKey!=null&&(e.publicKey=r.publicKey),r.observedAddr!=null&&(e.observedAddr=r.observedAddr),r.signedPeerRecord!=null&&(e.signedPeerRecord=r.signedPeerRecord),e.listenAddrs=[...e.listenAddrs,...r.listenAddrs],e.protocols=[...new Set([...e.protocols,...r.protocols])];return e}async function vo(t,e,r,n){let o=Er(t,{maxDataLength:e}).pb(At),s=[];for(let i=0;i<10;i++)try{s.push(await o.read(r))}catch(a){if(s.length===0)throw a;n.trace("stopped reading identify - %e",a);break}s.length>=10&&n("reached MAX_IDENTIFY_MESSAGES, returning truncated identify");try{await t.close(r)}catch(i){n.trace("error closing identify stream after read - %e",i),t.abort(i)}return s}var vr=class{host;components;protocol;started;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxObservedAddresses;runOnLimitedConnection;log;constructor(e,r){this.protocol=r.protocol,this.started=!1,this.components=e,this.log=r.log,this.timeout=r.timeout??Pe.timeout,this.maxInboundStreams=r.maxInboundStreams??Pe.maxInboundStreams,this.maxOutboundStreams=r.maxOutboundStreams??Pe.maxOutboundStreams,this.maxMessageSize=r.maxMessageSize??Pe.maxMessageSize,this.maxObservedAddresses=r.maxObservedAddresses??Pe.maxObservedAddresses,this.runOnLimitedConnection=r.runOnLimitedConnection??Pe.runOnLimitedConnection,this.host={protocolVersion:`${r.protocolPrefix??Pe.protocolPrefix}/${Wu}`,agentVersion:e.nodeInfo.userAgent},this.handleProtocol=this.handleProtocol.bind(this)}isStarted(){return this.started}async start(){this.started||(await this.components.peerStore.merge(this.components.peerId,{metadata:{AgentVersion:q(this.host.agentVersion),ProtocolVersion:q(this.host.protocolVersion)}}),await this.components.registrar.handle(this.protocol,this.handleProtocol,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams,runOnLimitedConnection:this.runOnLimitedConnection}),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.protocol),this.started=!1}};var So=class extends vr{connectionManager;concurrency;_push;constructor(e,r={}){super(e,{...r,protocol:`/${r.protocolPrefix??Pe.protocolPrefix}/${Zu}/${Xu}`,log:e.logger.forComponent("libp2p:identify-push")}),this.connectionManager=e.connectionManager,this.concurrency=r.concurrency??Pe.concurrency,this._push=ju(this.sendPushMessage.bind(this),r.debounce??1e3),(r.runOnSelfUpdate??Pe.runOnSelfUpdate)&&e.events.addEventListener("self:peer:update",n=>{this.push().catch(o=>{this.log.error("error pushing updates to peers - %e",o)})})}[dn]=["@libp2p/identify-push"];async push(){this._push()}async sendPushMessage(){if(this.isStarted())try{let e=this.components.addressManager.getAddresses().map(f=>f.decapsulateCode(421)),r=new Ye({peerId:this.components.peerId,multiaddrs:e}),n=await tt.seal(r,this.components.privateKey),o=this.components.registrar.getProtocols(),s=await this.components.peerStore.get(this.components.peerId),i=j(s.metadata.get("AgentVersion")??q(this.host.agentVersion)),a=j(s.metadata.get("ProtocolVersion")??q(this.host.protocolVersion)),c=this;async function*u(){for(let f of c.connectionManager.getConnections())(await c.components.peerStore.get(f.remotePeer)).protocols.includes(c.protocol)&&(yield async()=>{let h,p=AbortSignal.timeout(c.timeout);try{h=await f.newStream(c.protocol,{signal:p,runOnLimitedConnection:c.runOnLimitedConnection}),await Er(h,{maxDataLength:c.maxMessageSize}).pb(At).write({listenAddrs:e.map(m=>m.bytes),signedPeerRecord:n.marshal(),protocols:o,agentVersion:i,protocolVersion:a},{signal:p}),await h.close({signal:p})}catch(x){h?.log.newScope("identify-push")?.error("could not push identify update to peer",x),h?.abort(x)}})}await Yu(ea(u(),{concurrency:this.concurrency}))}catch(e){this.log.error("error pushing updates to peers - %e",e)}}async handleProtocol(e,r){let n=e.log.newScope("identify-push");if(this.components.peerId.equals(r.remotePeer))throw new Error("received push from ourselves?");let o={signal:AbortSignal.timeout(this.timeout)},s=await vo(e,this.maxMessageSize,o,n);await xo(this.components.peerStore,this.components.events,n,r,Eo(s)),n.trace("handled push from %p",r.remotePeer)}};var Ao=class extends vr{constructor(e,r={}){super(e,{...r,protocol:`/${r.protocolPrefix??Pe.protocolPrefix}/${"id"}/${Gu}`,log:e.logger.forComponent("libp2p:identify")}),(r.runOnConnectionOpen??Pe.runOnConnectionOpen)&&e.events.addEventListener("connection:open",n=>{let o=n.detail;this.identify(o).catch(()=>{})})}[dn]=["@libp2p/identify"];async _identify(e,r={}){let n,o;if(r.signal==null){let s=AbortSignal.timeout(this.timeout);r={...r,signal:s}}this.log("run identify on new connection %a",e.remoteAddr);try{n=await e.newStream(this.protocol,{...r,runOnLimitedConnection:this.runOnLimitedConnection}),o=n.log.newScope("identify");let s=await vo(n,this.maxMessageSize,r,o);return Eo(s)}catch(s){throw o?.error("identify failed - %e",s),n?.abort(s),s}}async identify(e,r={}){let n=await this._identify(e,r),{publicKey:o,protocols:s,observedAddr:i}=n;if(o==null)throw new Me("Public key was missing from identify message");let a=ar(o),c=en(a);if(!e.remotePeer.equals(c))throw new Me("Identified peer does not match the expected peer");if(this.components.peerId.equals(c))throw new Me("Identified peer is our own peer id?");return this.maybeAddObservedAddress(i),this.log("completed for peer %p and protocols %o",c,s),xo(this.components.peerStore,this.components.events,this.log,e,n)}maybeAddObservedAddress(e){let r=ta(e);if(r==null||(this.log.trace("our observed address was %a",r),Lu(r)))return;let n=r.getComponents();if((n[0].code===41||n[0].code===42&&n[1].code===41)&&!Bu(r)){this.log.trace("our observed address was IPv6 but not a global unicast address");return}Uu.exactMatch(r)||(this.log.trace("storing the observed address"),this.components.addressManager.addObservedAddr(r))}async handleProtocol(e,r){let n=e.log.newScope("identify");n("responding to identify");let o=AbortSignal.timeout(this.timeout);let s=await this.components.peerStore.get(this.components.peerId,{signal:o}),i=this.components.addressManager.getAddresses().map(f=>f.decapsulateCode(421)),a=s.peerRecordEnvelope;if(i.length>0&&a==null){let f=new Ye({peerId:this.components.peerId,multiaddrs:i});a=(await tt.seal(f,this.components.privateKey,{signal:o})).marshal().subarray()}let c=r.remoteAddr.bytes;Fu.matches(r.remoteAddr)||(c=void 0);let u=Er(e).pb(At);n("send response"),await u.write({protocolVersion:this.host.protocolVersion,agentVersion:this.host.agentVersion,publicKey:Ge(this.components.privateKey.publicKey),listenAddrs:i.map(f=>f.bytes),signedPeerRecord:a,observedAddr:c,protocols:s.protocols},{signal:o}),n("close write"),await u.unwrap().unwrap().close({signal:o})}};function mp(t={}){return e=>new Ao(e,t)}function yp(t={}){return e=>new So(e,t)}return ff(gp);})();
2
+ "use strict";var Libp2PIdentify=(()=>{var xo=Object.defineProperty;var Ku=Object.getOwnPropertyDescriptor;var Fu=Object.getOwnPropertyNames;var qu=Object.prototype.hasOwnProperty;var Ce=(t,e)=>{for(var r in e)xo(t,r,{get:e[r],enumerable:!0})},Vu=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Fu(e))!qu.call(t,o)&&o!==r&&xo(t,o,{get:()=>e[o],enumerable:!(n=Ku(e,o))||n.enumerable});return t};var Hu=t=>Vu(xo({},"__esModule",{value:!0}),t);var Vh={};Ce(Vh,{identify:()=>Fh,identifyPush:()=>qh});var ae=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},At=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var rn=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var nn=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Ke=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var It=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var wo=Symbol.for("@libp2p/peer-id");var on=Symbol.for("@libp2p/service-capabilities");function pe(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}var Io={};Ce(Io,{base58btc:()=>he,base58flickr:()=>Xu});var gp=new Uint8Array(0);function Yi(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Ne(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return Tt(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return Tt(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function ji(t){let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}var $i=4096;function Wi(t){let e=t.length;if(e<=$i)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.subarray(n,n+=$i));return r}function zu(t){return t?.buffer instanceof ArrayBuffer}function Tt(t){return zu(t)?t:t.slice()}function $u(t,e,r){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),o=0;o<n.length;o++)n[o]=255;for(var s=0;s<t.length;s++){var i=t.charAt(s),a=i.charCodeAt(0);if(n[a]!==255)throw new TypeError(i+" is ambiguous");if(n[a]=s,r){var c=i.toLowerCase().charCodeAt(0),u=i.toUpperCase().charCodeAt(0);c!==a&&(n[c]=s),u!==a&&(n[u]=s)}}var f=t.length,l=t.charAt(0),h=Math.log(f)/Math.log(256),p=Math.log(256)/Math.log(f);function x(w){if(w instanceof Uint8Array||(ArrayBuffer.isView(w)?w=new Uint8Array(w.buffer,w.byteOffset,w.byteLength):Array.isArray(w)&&(w=Uint8Array.from(w))),!(w instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(w.length===0)return"";for(var I=0,b=0,S=0,A=w.length;S!==A&&w[S]===0;)S++,I++;for(var R=(A-S)*p+1>>>0,K=new Uint8Array(R);S!==A;){for(var P=w[S],O=0,N=R-1;(P!==0||O<b)&&N!==-1;N--,O++)P+=256*K[N]>>>0,K[N]=P%f>>>0,P=P/f>>>0;if(P!==0)throw new Error("Non-zero carry");b=O,S++}for(var F=R-b;F!==R&&K[F]===0;)F++;for(var H=l.repeat(I);F<R;++F)H+=t.charAt(K[F]);return H}function m(w){if(typeof w!="string")throw new TypeError("Expected String");if(w.length===0)return new Uint8Array;var I=0;if(w[I]!==" "){for(var b=0,S=0;w[I]===l;)b++,I++;for(var A=(w.length-I)*h+1>>>0,R=new Uint8Array(A);w[I];){var K=w.charCodeAt(I);if(K>255)return;var P=n[K];if(P===255)return;for(var O=0,N=A-1;(P!==0||O<S)&&N!==-1;N--,O++)P+=f*R[N]>>>0,R[N]=P%256>>>0,P=P/256>>>0;if(P!==0)throw new Error("Non-zero carry");S=O,I++}if(w[I]!==" "){for(var F=A-S;F!==A&&R[F]===0;)F++;for(var H=new Uint8Array(b+(A-F)),J=b;F!==A;)H[J++]=R[F++];return H}}}function g(w){var I=m(w);if(I)return I;throw new Error(`Non-${e} character`)}return{encode:x,decodeUnsafe:m,decode:g}}var Yu=$u,ju=Yu,Gi=ju;var Eo=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},So=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Xi(this,e)}},vo=class{decoders;constructor(e){this.decoders=e}or(e){return Xi(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Xi(t,e){return new vo({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Ao=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Eo(e,r,n),this.decoder=new So(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Ht({name:t,prefix:e,encode:r,decode:n}){return new Ao(t,e,r,n)}function ft({name:t,prefix:e,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:s}=Gi(r,t,n);return Ht({prefix:e,name:t,encode:o,decode:i=>Ne(s(i))})}function Wu(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Zu(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Gu(t,e){let r={};for(let n=0;n<t.length;++n)if(t[n]!=="="&&(r[t[n]]=n,e)){let o=t[n].toLowerCase(),s=t[n].toUpperCase();o!==t[n]&&(r[o]=n),s!==t[n]&&(r[s]=n)}return r}function fe({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let s=Gu(n,o);return Ht({prefix:e,name:t,encode(i){return Zu(i,n,r)},decode(i){return Wu(i,s,r,t)}})}var he=ft({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Xu=ft({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var To={};Ce(To,{base32:()=>lt,base32hex:()=>tf,base32hexpad:()=>nf,base32hexpadupper:()=>of,base32hexupper:()=>rf,base32pad:()=>Ju,base32padupper:()=>ef,base32upper:()=>Qu,base32z:()=>sf});var lt=fe({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Qu=fe({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Ju=fe({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),ef=fe({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),tf=fe({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),rf=fe({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),nf=fe({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),of=fe({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),sf=fe({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var _o={};Ce(_o,{base36:()=>xr,base36upper:()=>af});var xr=ft({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),af=ft({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var cf=ea,Qi=128,uf=127,ff=~uf,lf=Math.pow(2,31);function ea(t,e,r){e=e||[],r=r||0;for(var n=r;t>=lf;)e[r++]=t&255|Qi,t/=128;for(;t&ff;)e[r++]=t&255|Qi,t>>>=7;return e[r]=t|0,ea.bytes=r-n+1,e}var df=Co,hf=128,Ji=127;function Co(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw Co.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&Ji)<<o:(i&Ji)*Math.pow(2,o),o+=7}while(i>=hf);return Co.bytes=s-n,r}var pf=Math.pow(2,7),mf=Math.pow(2,14),yf=Math.pow(2,21),bf=Math.pow(2,28),gf=Math.pow(2,35),xf=Math.pow(2,42),wf=Math.pow(2,49),Ef=Math.pow(2,56),Sf=Math.pow(2,63),vf=function(t){return t<pf?1:t<mf?2:t<yf?3:t<bf?4:t<gf?5:t<xf?6:t<wf?7:t<Ef?8:t<Sf?9:10},Af={encode:cf,decode:df,encodingLength:vf},If=Af,wr=If;function Er(t,e=0){let r=wr.decode(t,e),n=wr.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&t[e+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function zt(t,e,r=0){return wr.encode(t,e,r),e}function $t(t){return wr.encodingLength(t)}function We(t,e){let r=e.byteLength,n=$t(t),o=n+$t(r),s=new Uint8Array(o+r);return zt(t,s,0),zt(r,s,n),s.set(e,o),new Yt(t,r,e,s)}function Sr(t){let e=Ne(t),[r,n]=Er(e),[o,s]=Er(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Yt(r,o,i,e)}function ta(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Yi(t.bytes,r.bytes)}}var Yt=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=Tt(n),this.bytes=Tt(o)}};function ra(t,e){let{bytes:r,version:n}=t;return n===0?_f(r,Bo(t),e??he.encoder):Cf(r,Bo(t),e??lt.encoder)}var na=new WeakMap;function Bo(t){let e=na.get(t);if(e==null){let r=new Map;return na.set(t,r),r}return e}var ge=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=Tt(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==vr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Bf)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=We(e,r);return t.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&ta(e.multihash,n.multihash)}toString(e){return ra(this,e)}toJSON(){return{"/":ra(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new t(n,o,s,i??oa(n,o,s.bytes))}else if(r[Df]===!0){let{version:n,multihash:o,code:s}=r,i=Sr(o);return t.create(n,s,i)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==vr)throw new Error(`Version 0 CID must use dag-pb (code: ${vr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=oa(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,vr,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=Ne(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Yt(r.multihashCode,r.digestSize,s,o);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[l,h]=Er(e.subarray(r));return r+=h,l},o=n(),s=vr;if(o===18)o=0,r=0;else if(o===1)s=n();else throw o===0?new RangeError("Invalid CID version, v0 is always implicit"):new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,o]=Tf(e,r),s=t.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Bo(s).set(n,e),s}};function Tf(t,e){switch(t[0]){case"Q":{let r=e??he;return[he.prefix,r.decode(`${he.prefix}${t}`)]}case he.prefix:{let r=e??he;return[he.prefix,r.decode(t)]}case lt.prefix:{let r=e??lt;return[lt.prefix,r.decode(t)]}case xr.prefix:{let r=e??xr;return[xr.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function _f(t,e,r){let{prefix:n}=r;if(n!==he.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o}function Cf(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let s=r.encode(t);return e.set(n,s),s}else return o}var vr=112,Bf=18;function oa(t,e,r){let n=$t(t),o=n+$t(e),s=new Uint8Array(o+r.byteLength);return zt(t,s,0),zt(e,s,n),s.set(r,o),s}var Df=Symbol.for("@ipld/js-cid/CID");var Do={};Ce(Do,{identity:()=>Fe});var sa=0,Of="identity",ia=Ne;function Pf(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return We(sa,ia(t))}var Fe={code:sa,name:Of,encode:ia,digest:Pf};function Lf(t){return t.buffer instanceof ArrayBuffer}function _e(t){return Lf(t)?t:t.slice()}async function aa(t,e,r,n){let o=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,_e(e),_e(r.subarray()));return n?.signal?.throwIfAborted(),s}function xe(t=0){return new Uint8Array(t)}function Se(t=0){return new Uint8Array(t)}function Rf(t){return t?.buffer instanceof ArrayBuffer}function Oo(t){if(Rf(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function Ze(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=Se(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return Oo(r)}var ua=Symbol.for("@achingbrain/uint8arraylist");function ca(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let o=r+n.byteLength;if(e<o)return{buf:n,index:e-r};r=o}throw new RangeError("index is out of bounds")}function an(t){return!!t?.[ua]}var me=class t{bufs;length;[ua]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let r=0;for(let n of e)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(an(n)){r+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(an(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(e){let r=ca(this.bufs,e);return r.buf[r.index]}set(e,r){let n=ca(this.bufs,e);n.buf[n.index]=r}write(e,r=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(r+n,e[n]);else if(an(e))for(let n=0;n<e.length;n++)this.set(r+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,r){let{bufs:n,length:o}=this._subList(e,r);return Ze(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:Ze(n,o)}sublist(e,r){let{bufs:n,length:o}=this._subList(e,r),s=new t;return s.length=o,s.bufs=n,s}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,e>=c)continue;let u=e>=a&&e<c,f=r>a&&r<=c;if(u&&f){if(e===a&&r===c){n.push(i);break}let l=e-a;n.push(i.subarray(l,l+(r-e)));break}if(u){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!an(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let h=u;h>=0;h--){let p=this.get(l+h);if(n[h]!==p){f=Math.max(1,h-a[p]);break}}if(f===0)return l}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=Se(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let o=xe(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let o=xe(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let o=xe(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=Se(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let o=xe(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let o=xe(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let o=xe(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let o=xe(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let o=xe(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!pe(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var Po={};Ce(Po,{base10:()=>Nf});var Nf=ft({prefix:"9",name:"base10",alphabet:"0123456789"});var Lo={};Ce(Lo,{base16:()=>Uf,base16upper:()=>kf});var Uf=fe({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),kf=fe({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var Ro={};Ce(Ro,{base2:()=>Mf});var Mf=fe({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var No={};Ce(No,{base256emoji:()=>Hf});var fa=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Kf=fa.reduce((t,e,r)=>(t[r]=e,t),[]),Ff=fa.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function qf(t){return t.reduce((e,r)=>(e+=Kf[r],e),"")}function Vf(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Ff[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Hf=Ht({prefix:"\u{1F680}",name:"base256emoji",encode:qf,decode:Vf});var ko={};Ce(ko,{base64:()=>zf,base64pad:()=>$f,base64url:()=>Uo,base64urlpad:()=>Yf});var zf=fe({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),$f=fe({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Uo=fe({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Yf=fe({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Mo={};Ce(Mo,{base8:()=>jf});var jf=fe({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ko={};Ce(Ko,{identity:()=>Wf});var Wf=Ht({prefix:"\0",name:"identity",encode:t=>Wi(Ne(t)),decode:t=>Ne(ji(t))});var rm=new TextEncoder,nm=new TextDecoder;var Vo={};Ce(Vo,{sha256:()=>Ar,sha512:()=>Qf});var Xf=20;function qo({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new Fo(t,e,r,n,o)}var Fo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??Xf,this.maxDigestLength=s}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?la(n,this.code,r?.truncate):n.then(o=>la(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function la(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return We(e,t)}function ha(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Ar=qo({name:"sha2-256",code:18,encode:ha("SHA-256")}),Qf=qo({name:"sha2-512",code:19,encode:ha("SHA-512")});var Ir={...Ko,...Ro,...Mo,...Po,...Lo,...To,..._o,...Io,...ko,...No},mm={...Vo,...Do};function ma(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var pa=ma("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Ho=ma("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=Se(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Jf={utf8:pa,"utf-8":pa,hex:Ir.base16,latin1:Ho,ascii:Ho,binary:Ho,...Ir},cn=Jf;function V(t,e="utf8"){let r=cn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function Y(t,e="utf8"){let r=cn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var el=parseInt("11111",2),zo=parseInt("10000000",2),tl=parseInt("01111111",2),ya={0:Tr,1:Tr,2:rl,3:sl,4:il,5:ol,6:nl,16:Tr,22:Tr,48:Tr};function rt(t,e={offset:0}){let r=t[e.offset]&el;if(e.offset++,ya[r]!=null)return ya[r](t,e);throw new Error("No decoder for tag "+r)}function _r(t,e){let r=0;if((t[e.offset]&zo)===zo){let n=t[e.offset]&tl,o="0x";e.offset++;for(let s=0;s<n;s++,e.offset++){if(e.offset>=t.byteLength)throw new Error("invalid DER element length");o+=t[e.offset].toString(16).padStart(2,"0")}r=parseInt(o,16)}else r=t[e.offset],e.offset++;if(!Number.isInteger(r)||r<0||r>t.byteLength-e.offset)throw new Error("invalid DER element length");return r}function Tr(t,e){_r(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=rt(t,e);if(n===null)break;r.push(n)}return r}function rl(t,e){let r=_r(t,e),n=e.offset,o=e.offset+r,s=[];for(let i=n;i<o;i++)i===n&&t[i]===0||s.push(t[i]);return e.offset+=r,Uint8Array.from(s)}function nl(t,e){let r=_r(t,e),n=e.offset+r,o=t[e.offset];e.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;e.offset<n;){let u=t[e.offset];if(e.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function ol(t,e){return e.offset++,null}function sl(t,e){let r=_r(t,e),n=t[e.offset];e.offset++;let o=t.subarray(e.offset,e.offset+r-1);if(e.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function il(t,e){let r=_r(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function al(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new me;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function $o(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=al(t.byteLength);return new me(Uint8Array.from([e.byteLength|zo]),e)}function Be(t){let e=new me,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new me(Uint8Array.from([2]),$o(e),e)}function un(t){let e=Uint8Array.from([0]),r=new me(e,t);return new me(Uint8Array.from([3]),$o(r),r)}function dt(t,e=48){let r=new me;for(let n of t)r.append(n);return new me(Uint8Array.from([e]),$o(r),r)}var cl=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),ul=Uint8Array.from([6,5,43,129,4,0,34]),fl=Uint8Array.from([6,5,43,129,4,0,35]),ll={ext:!0,kty:"EC",crv:"P-256"},dl={ext:!0,kty:"EC",crv:"P-384"},hl={ext:!0,kty:"EC",crv:"P-521"},Yo=32,jo=48,Wo=66;function Zo(t){let e=rt(t);return ba(e)}function ba(t){let e=t[1][1][0],r=1,n,o;if(e.byteLength===Yo*2+1)return n=Y(e.subarray(r,r+Yo),"base64url"),o=Y(e.subarray(r+Yo),"base64url"),new jt({...ll,key_ops:["verify"],x:n,y:o});if(e.byteLength===jo*2+1)return n=Y(e.subarray(r,r+jo),"base64url"),o=Y(e.subarray(r+jo),"base64url"),new jt({...dl,key_ops:["verify"],x:n,y:o});if(e.byteLength===Wo*2+1)return n=Y(e.subarray(r,r+Wo),"base64url"),o=Y(e.subarray(r+Wo),"base64url"),new jt({...hl,key_ops:["verify"],x:n,y:o});throw new ae(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function ga(t){return dt([Be(Uint8Array.from([1])),dt([pl(t.crv)],160),dt([un(new me(Uint8Array.from([4]),V(t.x??"","base64url"),V(t.y??"","base64url")))],161)]).subarray()}function pl(t){if(t==="P-256")return cl;if(t==="P-384")return ul;if(t==="P-521")return fl;throw new ae(`Invalid curve ${t}`)}var jt=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=ga(this.jwk)),this._raw}toMultihash(){return Fe.digest(Ge(this))}toCID(){return ge.createV1(114,this.toMultihash())}toString(){return he.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:pe(this.raw,e.raw)}async verify(e,r,n){return aa(this.jwk,r,e,n)}};var fn=BigInt(4294967295),xa=BigInt(32);function ml(t,e=!1){return e?{h:Number(t&fn),l:Number(t>>xa&fn)}:{h:Number(t>>xa&fn)|0,l:Number(t&fn)|0}}function wa(t,e=!1){let r=t.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=ml(t[s],e);[n[s],o[s]]=[i,a]}return[n,o]}var yl=t=>t/2**32|0,bl=t=>t>>>0;function Ea(t,e,r,n){let o=yl(r),s=bl(r);t.setUint32(e,n?s:o,n),t.setUint32(e+4,n?o:s,n)}var Go=(t,e,r)=>t>>>r,Xo=(t,e,r)=>t<<32-r|e>>>r,Ct=(t,e,r)=>t>>>r|e<<32-r,Bt=(t,e,r)=>t<<32-r|e>>>r,Cr=(t,e,r)=>t<<64-r|e>>>r-32,Br=(t,e,r)=>t>>>r-32|e<<64-r;function Xe(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var Sa=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),va=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,Aa=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),Ia=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,Ta=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),_a=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0;function ln(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}var Qo=t=>t?`"${t}" `:"";function nt(t,e=""){if(typeof t!="number")throw new TypeError(Qo(e)+"expected number, got "+typeof t);if(!Number.isSafeInteger(t)||t<0)throw new RangeError(Qo(e)+"expected integer >= 0, got "+t);return t}function Ue(t,e,r=""){if(ln(t)&&(e===void 0||t.length===e))return t;e!==void 0&&nt(e,"length");let n=ln(t),o=e!==void 0?` of length ${e}`:"",s=n?`length=${t.length}`:`type=${typeof t}`,i=Qo(r)+"expected Uint8Array"+o+", got "+s;throw n?new RangeError(i):new TypeError(i)}function dn(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(nt(t.outputLen),nt(t.blockLen),t.outputLen<1||t.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var xl=(t,e)=>{if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError((e==="object"?"":`"${e}" `)+"expected object, got type="+typeof t)},Ca=(t,e)=>{xl(t,e);let r=Object.getPrototypeOf(t);if(r!==Object.prototype&&r!==null)throw new TypeError(`"${e}" expected plain object`);if(Object.hasOwn(t,"__proto__"))throw new TypeError(`"${e}.__proto__" is not allowed`)};function Wt(t,e=!0){if(t.destroyed)throw new Error("hash was destroyed");if(e&&t.finished)throw new Error("digest() was already called")}function hn(t,e){Ue(t,void 0,"output");let r=e.outputLen;if(!(t.length>=r))throw new RangeError('"output" expected length >= '+r)}function Dt(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function pn(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function qe(t,e){return t<<32-e|t>>>e}var Da=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",wl=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function mn(t){if(Ue(t),Da)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=wl[t[r]];return e}function Ba(t){return t>=48&&t<=57?t-48:t>=65&&t<=70?t-55:t>=97&&t<=102?t-87:void 0}function yn(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(Da)try{return Uint8Array.fromHex(t)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let e=t.length,r=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=Ba(t.charCodeAt(s)),a=Ba(t.charCodeAt(s+1));if(i===void 0||a===void 0){let c=t[s]+t[s+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Jo(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];Ue(o),e+=o.length}let r=new Uint8Array(e);for(let n=0,o=0;n<t.length;n++){let s=t[n];r.set(s,o),o+=s.length}return r}function El(t,e,r="opts"){return Ca(t,"defaults"),e!==void 0&&Ca(e,r),Object.assign(Object.create(null),t,e)}function es(t,e={}){if(typeof t!="function")throw new TypeError('"hashCons" expected function, got type='+typeof t);e=El({},e,"info");let r=(o,s)=>t(s).update(o).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>t(o),Object.assign(r,e),Object.freeze(r)}function Oa(t=32){nt(t,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(t>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);return e.getRandomValues(new Uint8Array(t))}var ts=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function Pa(t,e,r){return t&e^~t&r}function La(t,e,r){return t&e^t&r^e&r}var Dr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,o){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=pn(this.buffer)}update(e){Wt(this),Ue(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length,i=!1;for(let a=0;a<s;){let c=Math.min(o-this.pos,s-a);if(c===o){let u=pn(e);for(;o<=s-a;a+=o)this.process(u,a);i=!0;continue}n.set(a===0&&c===s?e:e.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===o&&(this.process(r,0),this.pos=0,i=!0)}return this.length+=e.length,i&&this.roundClean(),this}digestInto(e){Wt(this),hn(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,r.fill(0,i),this.padOffset>o-i&&(this.process(n,0),r.fill(0)),Ea(n,o-8,this.length*8,s),this.process(n,0),this.roundClean();let a=e===r?n:pn(e),c=this.outputLen,u=c/4,f=this.get();if(c%4||u>f.length)throw new Error("invalid outputLen");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],s)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneIntoMeta(e){let{buffer:r,length:n,finished:o,destroyed:s,pos:i}=this;return e.destroyed=s,e.finished=o,e.length=n,e.pos=i,i&&e.buffer.set(r),e}clone(){return this._cloneInto()}},Ra=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Na=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Sl=Uint32Array.from([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]),ht=new Uint32Array(64),rs=class extends Dr{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(e,r){super(64,e,8,!1),this.A=r[0]|0,this.B=r[1]|0,this.C=r[2]|0,this.D=r[3]|0,this.E=r[4]|0,this.F=r[5]|0,this.G=r[6]|0,this.H=r[7]|0}get(){let{A:e,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[e,r,n,o,s,i,a,c]}set(e,r,n,o,s,i,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let l=0;l<16;l++,r+=4)ht[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let h=ht[l-15],p=ht[l-2],x=qe(h,7)^qe(h,18)^h>>>3,m=qe(p,17)^qe(p,19)^p>>>10;ht[l]=m+ht[l-7]+x+ht[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let h=qe(a,6)^qe(a,11)^qe(a,25),p=f+h+Pa(a,c,u)+Sl[l]+ht[l]|0,m=(qe(n,2)^qe(n,13)^qe(n,22))+La(n,o,s)|0;f=u,u=c,c=a,a=i+p|0,i=s,s=o,o=n,n=p+m|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,o,s,i,a,c,u,f)}roundClean(){Dt(ht)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Dt(this.buffer)}},ns=class extends rs{constructor(){super(32,Ra)}};var Ua=wa(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),vl=Ua[0],Al=Ua[1],pt=new Uint32Array(80),mt=new Uint32Array(80),os=class extends Dr{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(e,r){super(128,e,16,!1),this.Ah=r[0]|0,this.Al=r[1]|0,this.Bh=r[2]|0,this.Bl=r[3]|0,this.Ch=r[4]|0,this.Cl=r[5]|0,this.Dh=r[6]|0,this.Dl=r[7]|0,this.Eh=r[8]|0,this.El=r[9]|0,this.Fh=r[10]|0,this.Fl=r[11]|0,this.Gh=r[12]|0,this.Gl=r[13]|0,this.Hh=r[14]|0,this.Hl=r[15]|0}get(){let{Ah:e,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:h,Gh:p,Gl:x,Hh:m,Hl:g}=this;return[e,r,n,o,s,i,a,c,u,f,l,h,p,x,m,g]}set(e,r,n,o,s,i,a,c,u,f,l,h,p,x,m,g){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=h|0,this.Gh=p|0,this.Gl=x|0,this.Hh=m|0,this.Hl=g|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,r){for(let b=0;b<16;b++,r+=4)pt[b]=e.getUint32(r),mt[b]=e.getUint32(r+=4);for(let b=16;b<80;b++){let S=pt[b-15]|0,A=mt[b-15]|0,R=Ct(S,A,1)^Ct(S,A,8)^Go(S,A,7),K=Bt(S,A,1)^Bt(S,A,8)^Xo(S,A,7),P=pt[b-2]|0,O=mt[b-2]|0,N=Ct(P,O,19)^Cr(P,O,61)^Go(P,O,6),F=Bt(P,O,19)^Br(P,O,61)^Xo(P,O,6),H=Aa(K,F,mt[b-7],mt[b-16]),J=Ia(H,R,N,pt[b-7],pt[b-16]);pt[b]=J|0,mt[b]=H|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:h,Fh:p,Fl:x,Gh:m,Gl:g,Hh:w,Hl:I}=this;for(let b=0;b<80;b++){let S=Ct(l,h,14)^Ct(l,h,18)^Cr(l,h,41),A=Bt(l,h,14)^Bt(l,h,18)^Br(l,h,41),R=l&p^~l&m,K=h&x^~h&g,P=Ta(I,A,K,Al[b],mt[b]),O=_a(P,w,S,R,vl[b],pt[b]),N=P|0,F=Ct(n,o,28)^Cr(n,o,34)^Cr(n,o,39),H=Bt(n,o,28)^Br(n,o,34)^Br(n,o,39),J=n&s^n&a^s&a,_=o&i^o&c^i&c;w=m|0,I=g|0,m=p|0,g=x|0,p=l|0,x=h|0,{h:l,l:h}=Xe(u|0,f|0,O|0,N|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let M=Sa(N,H,_);n=va(M,O,F,J),o=M|0}({h:n,l:o}=Xe(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Xe(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Xe(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Xe(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:h}=Xe(this.Eh|0,this.El|0,l|0,h|0),{h:p,l:x}=Xe(this.Fh|0,this.Fl|0,p|0,x|0),{h:m,l:g}=Xe(this.Gh|0,this.Gl|0,m|0,g|0),{h:w,l:I}=Xe(this.Hh|0,this.Hl|0,w|0,I|0),this.set(n,o,s,i,a,c,u,f,l,h,p,x,m,g,w,I)}roundClean(){Dt(pt,mt)}destroy(){this.destroyed=!0,Dt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},ss=class extends os{constructor(){super(64,Na)}};var Zt=es(()=>new ns,ts(1));var is=es(()=>new ss,ts(3));function gn(t,e,r=()=>{}){if(!Array.isArray(t))throw new TypeError(`"${e}" expected array, got type=${typeof t}`);for(let n=0;n<t.length;n++)r(t[n],`${e}[${n}]`);return t}var G=(t,e,r)=>Ue(t,e,r),as=nt;function Ma(t,e=""){if(typeof t!="string"){let r=e&&`"${e}" `;throw new TypeError(r+"expected string, got type="+typeof t)}return t}function yt(t,e="object"){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(e==="object"?"expected valid options object":`"${e}" expected object, got type=${typeof t}`);return t}function Ot(t,e){if(typeof t!="function")throw new TypeError(`"${e}" is invalid: expected function, got ${typeof t}`);return t}var Or=mn,ke=(...t)=>Jo(...t),Gt=t=>yn(t),gt=ln,Pt=t=>Oa(t),bn=BigInt(0),ka=BigInt(1),Il=t=>t?`"${t}" `:"";function De(t,e=""){if(typeof t!="boolean")throw new TypeError(Il(e)+"expected boolean, got type="+typeof t);return t}function xn(t){if(typeof t=="bigint"){if(!bt(t))throw new RangeError("positive bigint expected, got "+t)}else as(t);return t}function ot(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(r+"expected number, got type="+typeof t)}if(!Number.isSafeInteger(t)){let r=e&&`"${e}" `;throw new RangeError(r+"expected safe integer, got "+t)}}function Pr(t){let e=xn(t).toString(16);return e.length&1?"0"+e:e}function Ka(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?bn:BigInt("0x"+t)}function Qe(t){return Ka(mn(t))}function Lt(t){return Ka(mn(Lr(Ue(t)).reverse()))}function wn(t,e){if(nt(e),e===0)throw new Error("zero output length is invalid");t=xn(t);let r=e*2,n=t.toString(16);if(n.length>r)throw new RangeError("number is too large");return yn(n.padStart(r,"0"))}function cs(t,e){return wn(t,e).reverse()}function Lr(t){return Uint8Array.from(G(t))}function bt(t){return typeof t=="bigint"&&bn<=t}function us(t,e,r){return bt(t)&&bt(e)&&bt(r)&&e<=t&&t<r}function Xt(t,e,r,n){if(!us(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Qt(t){if(t<bn)throw new Error("expected non-negative bigint, got "+t);return t===bn?0:t.toString(2).length}var Rr=t=>(ot(t,"n"),(ka<<BigInt(t))-ka);function Fa(t,e,r){if(nt(t,"hashLen"),nt(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=g=>new Uint8Array(g),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(t),u=n(t),f=0,l=()=>{c.fill(1),u.fill(0),f=0},h=(...g)=>r(u,ke(c,...g)),p=(g=o)=>{u=h(s,g),c=h(),g.length!==0&&(u=h(i,g),c=h())},x=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let g=0,w=[];for(;g<e;){c=h();let I=c.slice();w.push(I),g+=c.length}return ke(...w)};return(g,w)=>{l(),p(g);let I;for(;(I=w(x()))===void 0;)p();return l(),I}}function Oe(t,e={},r={},n="object"){yt(t,n),yt(e,"fields"),yt(r,"optFields");function o(i,a,c){let u=n==="object"?`param "${String(i)}"`:`"${n}.${String(i)}"`,f=t[i];if(!Object.hasOwn(t,i)&&(c?f!==void 0:a!=="function"))throw new TypeError(`${u} is invalid: expected own property`);if(c&&f===void 0)return;let l=typeof f;if(l!==a||f===null)throw new TypeError(`${u} is invalid: expected ${a}, got ${l}`)}let s=(i,a)=>Object.entries(i).forEach(([c,u])=>o(c,u,a));s(e,!1),s(r,!0)}var ye=BigInt(0),X=BigInt(1),xt=BigInt(2),Ha=BigInt(3),fs=BigInt(4),za=BigInt(5),Tl=BigInt(7),$a=BigInt(8),_l=BigInt(9),Cl=BigInt(15),Ya=BigInt(16),Bl=BigInt("0x10000000000000000");function ce(t,e){if(e<=ye)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=ye?r:e+r}function ja(t,e,r){if(r<=X)throw new Error("pow: expected modulus > 1, got "+r);if(typeof e!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof e);if(e<ye)throw new Error("invalid exponent, negatives unsupported");if(e===ye)return X;if(e===X)return t;let n=t%r;if(n<ye&&(n+=r),e<Bl){let a=X;for(;e>ye;)e&X&&(a=a*n%r),n=n*n%r,e>>=X;return a}let o=[];for(;e>ye;)o.push(Number(e&Cl)),e>>=fs;let s=new Array(16);s[0]=X,s[1]=n;for(let a=2;a<16;a++)s[a]=s[a-1]*n%r;let i=s[o[o.length-1]];for(let a=o.length-2;a>=0;a--){i=i*i%r,i=i*i%r,i=i*i%r,i=i*i%r;let c=o[a];c!==0&&(i=i*s[c]%r)}return i}function se(t,e,r){if(r<=X)throw new Error("pow2: expected modulus > 1, got "+r);if(e<ye)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >ye;)n*=n,n%=r;return n}function qa(t,e){if(t===ye)throw new Error("invert: expected non-zero number");if(e<=X)throw new Error("invert: expected modulus > 1, got "+e);let r=ce(t,e),n=e,o=ye,s=X;for(;r!==ye;){let a=n/r,c=n-r*a,u=o-s*a;n=r,r=c,o=s,s=u}if(n!==X)throw new Error("invert: does not exist");return ce(o,e)}function Wa(t,e){if(e<=X)throw new Error("invertCt: expected prime modulus > 1, got "+e);let r=ce(t,e);if(r===ye)throw new Error("invertCt: expected non-zero number");let n=ja(r,e-xt,e);if(ce(r*n,e)!==X)throw new Error("invertCt: does not exist");return n}function ls(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function ds(t,e){if((t&X)===ye)throw new Error(e+": expected odd modulus, got "+t)}function Za(t,e){let r=t,n=(r.ORDER+X)/fs,o=r.pow(e,n);return ls(r,o,e),o}function Dl(t,e){let r=t,n=(r.ORDER-za)/$a,o=r.mul(e,xt),s=r.pow(o,n),i=r.mul(e,s),a=r.mul(r.mul(i,xt),s),c=r.mul(i,r.sub(a,r.ONE));return ls(r,c,e),c}function Ol(t){let e=er(t),r=Ga(t),n=r(e,e.neg(e.ONE)),o=r(e,n),s=r(e,e.neg(n)),i=(t+Tl)/Ya;return((a,c)=>{let u=a,f=u.pow(c,i),l=u.mul(f,n),h=u.mul(f,o),p=u.mul(f,s),x=u.eql(u.sqr(l),c),m=u.eql(u.sqr(h),c);f=u.cmov(f,l,x),l=u.cmov(p,h,m);let g=u.eql(u.sqr(l),c),w=u.cmov(f,l,g);return ls(u,w,c),w})}function Ga(t){if(t<Ha)throw new Error("sqrt is not defined for small field");ds(t,"tonelliShanks");let e=t-X,r=0;for(;e%xt===ye;)e/=xt,r++;let n=xt,o=er(t);for(;Nr(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Za;let s=o.pow(n,e),i=(e+X)/xt;return function(c,u){let f=c;if(f.is0(u))return u;if(Nr(f,u)!==1)throw new Error("Cannot find square root");let l=r,h=f.mul(f.ONE,s),p=f.pow(u,e),x=f.pow(u,i);for(;!f.eql(p,f.ONE);){if(f.is0(p))throw new Error("Cannot find square root: probably non-prime P");let m=1,g=f.sqr(p);for(;!f.eql(g,f.ONE);)if(m++,g=f.sqr(g),m===l)throw new Error("Cannot find square root");let w=X<<BigInt(l-m-1),I=f.pow(h,w);l=m,h=f.sqr(I),p=f.mul(p,h),x=f.mul(x,I)}return x}}function Pl(t){return ds(t,"Fp.sqrt"),t%fs===Ha?Za:t%$a===za?Dl:t%Ya===_l?Ol(t):Ga(t)}var Xa=(t,e)=>(ce(t,e)&X)===X,Ll=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Jt(t){if(yt(t,"field"),typeof t.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof t.ORDER);ot(t.BYTES,"BYTES"),ot(t.BITS,"BITS");for(let e of Ll)Ot(t[e],"field."+e);if(t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=X)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function Sn(t,e,r=!1){Jt(t),gn(e,"nums"),De(r,"passZero");let n=t,o=new Array(e.length).fill(r?n.ZERO:void 0),s=e.reduce((a,c,u)=>n.is0(c)?a:(o[u]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return e.reduceRight((a,c,u)=>n.is0(c)?a:(o[u]=n.mul(a,o[u]),n.mul(a,c)),i),o}function Nr(t,e){Jt(t);let r=t;ds(r.ORDER,"FpLegendre");let n=(r.ORDER-X)/xt,o=r.pow(e,n),s=r.eql(o,r.ONE),i=r.eql(o,r.ZERO),a=r.eql(o,r.neg(r.ONE));if(!s&&!i&&!a)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function Rl(t,e){if(e!==void 0&&as(e),t<=ye)throw new Error("invalid n length: expected positive n, got "+t);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let r=Qt(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected nBitLength (${e}) >= bitLen(n) (${r})`);let n=e!==void 0?e:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var Va=new WeakMap,En=class{ORDER;BITS;BYTES;isLE;ZERO=ye;ONE=X;_lengths;_mod;constructor(e,r={}){if(e<=X)throw new Error("invalid field: expected ORDER > 1, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=Rl(e,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(e){return ce(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return ye<=e&&e<this.ORDER}is0(e){return e===ye}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&X)===X}neg(e){return ce(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return ce(e*e,this.ORDER)}add(e,r){return ce(e+r,this.ORDER)}sub(e,r){return ce(e-r,this.ORDER)}mul(e,r){return ce(e*r,this.ORDER)}pow(e,r){return ja(e,r,this.ORDER)}div(e,r){return ce(e*qa(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return qa(e,this.ORDER)}sqrt(e){let r=Va.get(this);return r||Va.set(this,r=Pl(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?cs(e,this.BYTES):wn(e,this.BYTES)}fromBytes(e,r=!1){G(e);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let u=new Uint8Array(o);u.set(e,s?0:u.length-e.length),e=u}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let c=s?Lt(e):Qe(e);if(a&&(c=ce(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return Sn(this,e,!0)}cmov(e,r,n){return De(n,"condition"),n?r:e}};function er(t,e={}){return Object.freeze(En.prototype),new En(t,e)}function Qa(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=X)throw new Error("field order must be greater than 1");let e=Qt(t-X);return Math.ceil(e/8)}function vn(t){let e=Qa(t);return e+Math.ceil(e/2)}function An(t,e,r=!1){G(t);let n=t.length,o=Qa(e),s=Math.max(vn(e),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Lt(t):Qe(t),a=ce(i,e-X)+X;return r?cs(a,o):wn(a,o)}var ms=BigInt(0),Ur=BigInt(1),Nl=BigInt(4),hs=16,Ja=128,Ul=5,ec=2**31;function wt(t){let e=t;if(typeof e!="function")throw new TypeError('"Point" expected constructor, got type='+typeof t);Ot(e.fromAffine,"Point.fromAffine"),Ot(e.fromBytes,"Point.fromBytes"),Ot(e.fromHex,"Point.fromHex"),yt(e.BASE,"Point.BASE"),yt(e.ZERO,"Point.ZERO"),Jt(e.Fp),Jt(e.Fn)}function In(t,e){wt(t),rc(e,t);let r=Sn(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function kl(t,e,r=1){if(!Number.isSafeInteger(t)||t<r||t>e)throw new Error("invalid window size, expected ["+r+".."+e+"], got W="+t)}function Ml(t,e){let r=t*(4*e+128);if(r>ec)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+ec/2**20+" MiB")}function ys(t,e){if(t!==void 0){Ot(t,"randomBytes");try{let r=t(e);if(!gt(r)||r.length!==e)return}catch{return}return t}}function rc(t,e){gn(t,"points"),t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function Kl(t,e,r){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((n,o)=>{if(!(r===void 0?e.isValid(n):bt(n)&&n<r))throw new Error("invalid scalar at index "+o)})}var nc=new WeakMap;function ps(t){return nc.get(t)||1}function Fl(t,e){let r=t.double(),n=[t];for(let o=1;o<e;o++)n.push(n[o-1].add(r));return n}function ql(t,e){let r=2**e,n=r/2,o=BigInt(r-1),s=[];for(;t>ms;){let i=0;t&Ur&&(i=Number(t&o),i>=n&&(i-=r),t-=BigInt(i)),s.push(i),t>>=Ur}return s}function Vl(t,e,r){let n=2**e,o=n/2,s=BigInt(n-1),i=BigInt(e),a=[];for(let c=0;c<r;c++){let u=Number(t&s);t>>=i,u>o&&(u-=n,t+=Ur),a.push(u)}if(t!==ms)throw new Error("invalid wnaf");return a}function Hl(t,e,r){let n=0;for(let s of r)n=Math.max(n,s.length);let o=t;for(let s=n-1;s>=0;s--){s!==n-1&&(o=o.double());for(let i=0;i<r.length;i++){let a=r[i][s];if(a){let c=e[i][Math.abs(a)-1>>1];o=o.add(a<0?c.negate():c)}}}return o}var tr=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(e,r){wt(e),this.randomBytes=ys(r,hs),this.Point=e,this.BASE=e.BASE,this.ZERO=e.ZERO,this.bits=e.Fn.BITS}buildWnafTable(e,r,n){let o=Math.ceil(n/r)+1,s=2**(r-1),i=[],a=e;for(let c=0;c<o;c++){let u=a;for(let f=0;f<s;f++)i.push(u),u=u.add(a);a=i[i.length-1].double()}return{W:r,bits:n,windows:o,comp:i}}wnafCachedCT(e,r){let{W:n,windows:o,comp:s}=e,i=2**(n-1),a=Vl(r,n,o),c=this.ZERO,u=this.BASE;for(let f=0;f<o;f++){let l=a[f],h=f*i,p=Math.abs(l)-1,x=s[h];for(let g=1;g<i;g++)x=g===p?s[h+g]:x;let m=x.negate();l===0?u=u.add(s[h]):c=c.add(l<0?m:x)}return{p:c,f:u}}getWnafPrecomputes(e,r,n,o){let s=this.wnafPrecomputes.get(r),i=s?.find(a=>a.W===e&&a.bits===n);return i||(i=this.buildWnafTable(r,e,n),typeof o=="function"&&(i={...i,comp:o(i.comp)}),s||(s=[],this.wnafPrecomputes.set(r,s)),s.push(i)),i}assertPoint(e){if(!(e instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof e)}validateMulInput(e,r){if(this.assertPoint(e),!us(r,Ur,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(e,r,n,o){let s=ps(e);return s===1?this.fixedWindowCT(e,r,n):this.wnafCachedCT(this.getWnafPrecomputes(s,e,n,o),r)}mulCT(e,r,n){return this.validateMulInput(e,r),this.runCT(e,r,this.bits,n)}mulCTBlinded(e,r,n){if(this.validateMulInput(e,r),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let o=this.Point.Fn.BITS+Ja,s=this.randomBytes(hs);if(!gt(s)||s.length!==hs)throw new Error("randomBytes returned invalid byte array");s[0]=s[0]&63|128;let i=r+Qe(s)*this.Point.Fn.ORDER;return this.runCT(e,i,o,n)}fixedWindowCT(e,r,n){let o=Ul,s=1<<o,i=Rr(o),a=new Array(s);a[0]=this.ZERO;for(let f=1;f<s;f++)a[f]=a[f-1].add(e);let c=Math.ceil(n/o),u=this.ZERO;for(let f=c-1;f>=0;f--){if(f!==c-1)for(let p=0;p<o;p++)u=u.double();let l=Number(r>>BigInt(f*o)&i),h=a[0];for(let p=1;p<s;p++)h=p===l?a[p]:h;u=u.add(h)}return{p:u,f:u}}shouldBlind(e,r){return this.randomBytes===void 0?!1:r===Ur?!0:e!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(e,r,n,o){return this.shouldBlind(e,n)?this.mulCTBlinded(e,r,o):this.mulCT(e,r,o)}mulUnsafe(e,r,n){if(this.assertPoint(e),!bt(r))throw new Error("invalid scalar");let o=ps(e);if(o===1||r>=this.Point.Fn.ORDER)return Tn(this.Point,[e],[r],!0);let s=this.getWnafPrecomputes(o,e,this.bits,n);return this.wnafCachedCT(s,r).p}setWindowSize(e,r){this.assertPoint(e),kl(r,this.bits);let n=Math.ceil((this.bits+Ja)/r)+1;Ml(n*2**(r-1),this.Point.Fp.BYTES),nc.set(e,r),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return ps(e)!==1}};function Tn(t,e,r,n=!1){if(wt(t),rc(e,t),De(n,"allowOversized"),Kl(r,t.Fn,n?t.Fn.ORDER**Nl:void 0),e.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let o=e.map(i=>Fl(i,4)),s=r.map(i=>ql(i,4));return Hl(t.ZERO,o,s)}function tc(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Jt(e),e}else return er(t,{isLE:r})}function _n(t,e,r={},n){if(t!=="weierstrass"&&t!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);Oe(r);for(let c of["p","n","h"]){let u=e[c];if(!(bt(u)&&u!==ms))throw new Error(`CURVE.${c} must be positive bigint`)}let o=tc(e.p,r.Fp,n),s=tc(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:s}}function Cn(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}var Bn=BigInt(0),Dn=BigInt(1),On=BigInt(2),zl=BigInt(4),oc=BigInt(8);function $l(t,e,r,n){let o=t.sqr(r),s=t.sqr(n),i=t.add(t.mul(e.a,o),s),a=t.add(t.ONE,t.mul(e.d,t.mul(o,s)));return t.eql(i,a)}function sc(t,e={}){Oe(e,{},{},"extraOpts");let r=e,n=_n("edwards",t,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;if(Nr(o,i.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(Nr(o,i.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");Oe(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?Pt:r.randomBytes,u=On<<BigInt(o.BYTES*8)-Dn;function f(I){if(!o.isOdd)throw new Error("Field does not have .isOdd()");return o.isOdd(I)}let l=r.uvRatio===void 0?(I,b)=>{try{return{isValid:!0,value:o.sqrt(o.div(I,b))}}catch{return{isValid:!1,value:Bn}}}:r.uvRatio;if(!$l(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");let h=o.eql(i.a,o.neg(o.ONE))?I=>o.neg(I):o.eql(i.a,o.ONE)?I=>I:I=>o.mul(i.a,I);function p(I,b,S=!1){let A=S?Dn:Bn;return Xt("coordinate "+I,b,A,u),b}function x(I){if(!(I instanceof m))throw new Error("EdwardsPoint expected")}class m{static BASE=new m(i.Gx,i.Gy,o.ONE,o.mul(i.Gx,i.Gy));static ZERO=new m(o.ZERO,o.ONE,o.ONE,o.ZERO);static Fp=o;static Fn=s;X;Y;Z;T;constructor(b,S,A,R){this.X=p("x",b),this.Y=p("y",S),this.Z=p("z",A,!0),this.T=p("t",R),Object.freeze(this)}static CURVE(){return i}static fromAffine(b){if(b instanceof m)throw new Error("extended point not allowed");let{x:S,y:A}=b||{};return p("x",S),p("y",A),new m(S,A,o.ONE,o.mul(S,A))}static fromBytes(b,S=!1){let A=o.BYTES,{a:R,d:K}=i;b=Lr(G(b,A,"point")),De(S,"zip215");let P=Lr(b),O=b[A-1];P[A-1]=O&-129;let N=Lt(P),F=S?u:o.ORDER;Xt("point.y",N,Bn,F);let H=o.sqr(N),J=o.sub(H,o.ONE),_=o.sub(o.mulN(K,H),R),{isValid:M,value:q}=l(J,_);if(!M)throw new Error("bad point: invalid y coordinate");let L=f(q),re=(O&128)!==0;if(!S&&o.is0(q)&&re)throw new Error("bad point: x=0 and x_0=1");return re!==L&&(q=o.neg(q)),m.fromAffine({x:q,y:N})}static fromHex(b,S=!1){return m.fromBytes(Gt(b),S)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=6,S=!0){return w.setWindowSize(this,b),S||this.multiply(On),this}assertValidity(){let b=this,{a:S,d:A}=i;if(b.is0())throw new Error("bad point: ZERO");let{X:R,Y:K,Z:P,T:O}=b,N=o.sqr(R),F=o.sqr(K),H=o.sqr(P),J=o.sqr(H),_=o.mul(N,S),M=o.mul(o.add(_,F),H),q=o.add(J,o.mul(A,o.mul(N,F)));if(!o.eql(M,q))throw new Error("bad point: equation left != right (1)");let L=o.mul(R,K),re=o.mul(P,O);if(!o.eql(L,re))throw new Error("bad point: equation left != right (2)")}equals(b){x(b);let{X:S,Y:A,Z:R}=this,{X:K,Y:P,Z:O}=b,N=o.mul(S,O),F=o.mul(K,R),H=o.mul(A,O),J=o.mul(P,R);return o.eql(N,F)&&o.eql(H,J)}is0(){return this.equals(m.ZERO)}negate(){return new m(o.neg(this.X),this.Y,this.Z,o.neg(this.T))}double(){let{X:b,Y:S,Z:A}=this,R=o.sqr(b),K=o.sqr(S),P=o.mul(o.sqr(A),On),O=h(R),N=o.addN(b,S),F=o.sub(o.subN(o.sqr(N),R),K),H=o.addN(O,K),J=o.subN(H,P),_=o.subN(O,K),M=o.mul(F,J),q=o.mul(H,_),L=o.mul(F,_),re=o.mul(J,H);return new m(M,q,re,L)}add(b){x(b);let{d:S}=i,{X:A,Y:R,Z:K,T:P}=this,{X:O,Y:N,Z:F,T:H}=b,J=o.mul(A,O),_=o.mul(R,N),M=o.mul(o.mulN(P,S),H),q=o.mul(K,F),L=o.sub(o.subN(o.mulN(o.addN(A,R),o.addN(O,N)),J),_),re=o.subN(q,M),ie=o.addN(q,M),v=o.sub(_,h(J)),d=o.mul(L,re),y=o.mul(ie,v),E=o.mul(L,v),T=o.mul(re,ie);return new m(d,y,T,E)}subtract(b){return x(b),this.add(b.negate())}multiply(b){if(!s.isValidNot0(b))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:S,f:A}=w.mulSecret(this,b,a,g);return g([S,A])[0]}multiplyUnsafe(b){if(!s.isValid(b))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return b===Bn?m.ZERO:this.is0()||b===Dn?this:w.mulUnsafe(this,b,g)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return w.mulUnsafe(this,i.n).is0()}toAffine(b){let S=this,A=b;if(A!=null&&typeof A!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof A);let{X:R,Y:K,Z:P}=S,O=S.is0();A==null&&(A=O?o.create(oc):o.inv(P));let N=o.mul(R,A),F=o.mul(K,A),H=o.mul(P,A);if(O)return{x:o.ZERO,y:o.ONE};if(!o.eql(H,o.ONE))throw new Error("invZ was invalid");return{x:N,y:F}}clearCofactor(){return a===Dn?this:a===On?this.double():a===zl?this.double().double():a===oc?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:b,y:S}=this.toAffine(),A=o.toBytes(S);return A[A.length-1]|=f(b)?128:0,A}toHex(){return Or(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let g=I=>In(m,I),w=new tr(m,c);return w.bits>=6&&m.BASE.precompute(6),Object.freeze(m.prototype),Object.freeze(m),m}function ic(t,e,r={}){if(wt(t),typeof e!="function")throw new Error('"hash" function param is required');let n=e,o=r;Oe(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function",toMontgomery:"function",toMontgomerySecret:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=t,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(ot(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=o.randomBytes===void 0?Pt:o.randomBytes,h=o.toMontgomery,p=o.toMontgomerySecret,x=o.adjustScalarBytes===void 0?_=>_:o.adjustScalarBytes,m=o.domain===void 0?(_,M,q)=>{if(De(q,"phflag"),M.length||q)throw new Error("Contexts/pre-hash are not supported");return _}:o.domain;function g(_){return c.create(Lt(_))}function w(_){let M=O.secretKey;G(_,O.secretKey,"secretKey");let q=G(n(_),2*M,"hashedSecretKey"),L=x(q.slice(0,M)),re=q.slice(M,2*M),ie=g(L);return{head:L,prefix:re,scalar:ie}}function I(_){let{head:M,prefix:q,scalar:L}=w(_),re=i.multiply(L),ie=re.toBytes();return{head:M,prefix:q,scalar:L,point:re,pointBytes:ie}}function b(_){return I(_).pointBytes}function S(_=Uint8Array.of(),...M){let q=ke(...M);return g(n(m(q,G(_,void 0,"context"),!!s)))}function A(_,M,q={}){Oe(q,{},{},"options"),_=Lr(G(_,void 0,"message")),s&&(_=s(_));let{prefix:L,scalar:re,pointBytes:ie}=I(M),v=S(q.context,L,_),d=i.multiply(v).toBytes(),y=S(q.context,d,ie,_),E=c.create(v+y*re);if(!c.isValid(E))throw new Error("sign failed: invalid s");let T=ke(d,c.toBytes(E));return G(T,O.signature,"result")}let R={zip215:o.zip215};function K(_,M,q,L=R){Oe(L);let{context:re}=L,ie=L.zip215===void 0?!!R.zip215:L.zip215,v=O.signature;_=G(_,v,"signature"),M=G(M,void 0,"message"),q=G(q,O.publicKey,"publicKey"),ie!==void 0&&De(ie,"zip215"),s&&(M=s(M));let d=v/2,y=_.subarray(0,d),E=Lt(_.subarray(d,v)),T,C,B;try{T=t.fromBytes(q,ie),C=t.fromBytes(y,ie),B=i.multiplyUnsafe(E)}catch{return!1}if(!ie&&T.isSmallOrder())return!1;let U=S(re,y,q,M);return C.add(T.multiplyUnsafe(U)).subtract(B).clearCofactor().is0()}let P=a.BYTES,O={secretKey:P,publicKey:P,signature:2*P,seed:P};function N(_){return _=_===void 0?l(O.seed):_,G(_,O.seed,"seed")}function F(_){return gt(_)&&_.length===O.secretKey}function H(_,M){try{return!!t.fromBytes(_,M===void 0?R.zip215:M)}catch{return!1}}let J={getExtendedPublicKey:I,randomSecretKey:N,isValidSecretKey:F,isValidPublicKey:H,toMontgomery(_){if(h===void 0)throw new Error("Montgomery conversion is not supported for this curve");return h(t.fromBytes(_))},toMontgomerySecret(_){if(p===void 0)throw new Error("Montgomery conversion is not supported for this curve");return p(_)}};return Object.freeze(O),Object.freeze(J),Object.freeze({keygen:Cn(N,b),getPublicKey:b,sign:A,verify:K,utils:J,Point:t,lengths:O})}var bs=BigInt(1),ac=BigInt(2);var Yl=BigInt(5),jl=BigInt(8),gs=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Wl={p:gs,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:jl,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Zl(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=gs,a=t*t%s*t%s,c=se(a,ac,s)*a%s,u=se(c,bs,s)*t%s,f=se(u,Yl,s)*u%s,l=se(f,e,s)*f%s,h=se(l,r,s)*l%s,p=se(h,n,s)*h%s,x=se(p,o,s)*p%s,m=se(x,o,s)*p%s,g=se(m,e,s)*f%s;return{pow_p_5_8:se(g,ac,s)*t%s,b2:a}}function fc(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var cc=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Gl(t,e){let r=gs,n=ce(e*e*e,r),o=ce(n*n*e,r),s=Zl(t*o).pow_p_5_8,i=ce(t*n*s,r),a=ce(e*i*i,r),c=i,u=ce(i*cc,r),f=a===t,l=a===ce(-t,r),h=a===ce(-t*cc,r);return f&&(i=c),(l||h)&&(i=u),Xa(i,r)&&(i=ce(-i,r)),{isValid:f||l,value:i}}var xs=sc(Wl,{uvRatio:Gl}),uc=xs.Fp;function Xl(t){let{y:e}=t;return uc.toBytes(uc.div(bs+e,bs-e))}function Ql(t){let e=xs.Fp.BYTES;return Ue(t,e),fc(is(t.subarray(0,e))).subarray(0,e)}function Jl(t){return ic(xs,is,Object.assign({adjustScalarBytes:fc,toMontgomery:Xl,toMontgomerySecret:Ql,zip215:!0},t))}var lc=Jl({});var kr=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},Pn=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var Me={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new Pn("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return e}};var Ln=32;var ws,ed=(async()=>{try{return await Me.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function td(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await Me.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await Me.get().subtle.verify({name:"Ed25519"},n,_e(e),_e(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function rd(t,e,r){return lc.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function dc(t,e,r){return ws==null&&(ws=await ed),ws?td(t,e,r):rd(t,e,r)}function Rn(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Nn=class{type="Ed25519";raw;constructor(e){this.raw=Es(e,Ln)}toMultihash(){return Fe.digest(Ge(this))}toCID(){return ge.createV1(114,this.toMultihash())}toString(){return he.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:pe(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let o=dc(this.raw,r,e);return Rn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Ss(t){return t=Es(t,Ln),new Nn(t)}function Es(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new ae(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}var od=Math.pow(2,7),sd=Math.pow(2,14),id=Math.pow(2,21),vs=Math.pow(2,28),As=Math.pow(2,35),Is=Math.pow(2,42),Ts=Math.pow(2,49),Q=128,ve=127;function Pe(t){if(t<od)return 1;if(t<sd)return 2;if(t<id)return 3;if(t<vs)return 4;if(t<As)return 5;if(t<Is)return 6;if(t<Ts)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function rr(t,e,r=0){switch(Pe(t)){case 8:e[r++]=t&255|Q,t/=128;case 7:e[r++]=t&255|Q,t/=128;case 6:e[r++]=t&255|Q,t/=128;case 5:e[r++]=t&255|Q,t/=128;case 4:e[r++]=t&255|Q,t>>>=7;case 3:e[r++]=t&255|Q,t>>>=7;case 2:e[r++]=t&255|Q,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function ad(t,e,r=0){switch(Pe(t)){case 8:e.set(r++,t&255|Q),t/=128;case 7:e.set(r++,t&255|Q),t/=128;case 6:e.set(r++,t&255|Q),t/=128;case 5:e.set(r++,t&255|Q),t/=128;case 4:e.set(r++,t&255|Q),t>>>=7;case 3:e.set(r++,t&255|Q),t>>>=7;case 2:e.set(r++,t&255|Q),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function _s(t,e){let r=t[e],n=0;if(n+=r&ve,r<Q||(r=t[e+1],n+=(r&ve)<<7,r<Q)||(r=t[e+2],n+=(r&ve)<<14,r<Q)||(r=t[e+3],n+=(r&ve)<<21,r<Q)||(r=t[e+4],n+=(r&ve)*vs,r<Q)||(r=t[e+5],n+=(r&ve)*As,r<Q)||(r=t[e+6],n+=(r&ve)*Is,r<Q)||(r=t[e+7],n+=(r&ve)*Ts,r<Q))return n;throw new RangeError("Could not decode varint")}function cd(t,e){let r=t.get(e),n=0;if(n+=r&ve,r<Q||(r=t.get(e+1),n+=(r&ve)<<7,r<Q)||(r=t.get(e+2),n+=(r&ve)<<14,r<Q)||(r=t.get(e+3),n+=(r&ve)<<21,r<Q)||(r=t.get(e+4),n+=(r&ve)*vs,r<Q)||(r=t.get(e+5),n+=(r&ve)*As,r<Q)||(r=t.get(e+6),n+=(r&ve)*Is,r<Q)||(r=t.get(e+7),n+=(r&ve)*Ts,r<Q))return n;throw new RangeError("Could not decode varint")}function nr(t,e,r=0){return e==null&&(e=Se(Pe(t))),e instanceof Uint8Array?rr(t,e,r):ad(t,e,r)}function Mr(t,e=0){return t instanceof Uint8Array?_s(t,e):cd(t,e)}var Bs=new Float32Array([-0]),Et=new Uint8Array(Bs.buffer);function pc(t,e,r){Bs[0]=t,e[r]=Et[0],e[r+1]=Et[1],e[r+2]=Et[2],e[r+3]=Et[3]}function mc(t,e){return Et[0]=t[e],Et[1]=t[e+1],Et[2]=t[e+2],Et[3]=t[e+3],Bs[0]}var Ds=new Float64Array([-0]),Ae=new Uint8Array(Ds.buffer);function yc(t,e,r){Ds[0]=t,e[r]=Ae[0],e[r+1]=Ae[1],e[r+2]=Ae[2],e[r+3]=Ae[3],e[r+4]=Ae[4],e[r+5]=Ae[5],e[r+6]=Ae[6],e[r+7]=Ae[7]}function bc(t,e){return Ae[0]=t[e],Ae[1]=t[e+1],Ae[2]=t[e+2],Ae[3]=t[e+3],Ae[4]=t[e+4],Ae[5]=t[e+5],Ae[6]=t[e+6],Ae[7]=t[e+7],Ds[0]}var ud=BigInt(Number.MAX_SAFE_INTEGER),fd=BigInt(Number.MIN_SAFE_INTEGER),Le=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Rt;if(e<ud&&e>fd)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,o=e-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>gc&&(o=0n,++n>gc&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return Rt;let r=e<0;r&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new t(n,o)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):Rt}},Rt=new Le(0,0);Rt.toBigInt=function(){return 0n};Rt.zzEncode=Rt.zzDecode=function(){return this};Rt.length=function(){return 1};var gc=4294967296n;function xc(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function wc(t,e,r){if(r-e<1)return"";let o,s=[],i=0,a;for(;e<r;)a=t[e++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Os(t,e,r){let n=r,o,s;for(let i=0;i<t.length;++i)o=t.charCodeAt(i),o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&((s=t.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128);return r-n}function Ve(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function Un(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var Ps=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=_e(e),this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Ve(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Ve(this,4);return Un(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ve(this,4);return Un(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ve(this,4);let e=mc(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ve(this,4);let e=bc(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw Ve(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return wc(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ve(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ve(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Le(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Ve(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw Ve(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ve(this,8);let e=Un(this.buf,this.pos+=4),r=Un(this.buf,this.pos+=4);return new Le(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=_s(this.buf,this.pos);return this.pos+=Pe(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Kr(t){return new Ps(t instanceof Uint8Array?t:t.subarray())}function He(t,e,r){let n=Kr(t);return e.decode(n,void 0,r)}function Ls(t){let e=t??8192,r=e>>>1,n,o=e;return function(i){if(i<1||i>r)return Se(i);o+i>e&&(n=Se(e),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Nt=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function Rs(){}var Us=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},ld=Ls();function dd(t){return globalThis.Buffer!=null?Se(t):ld(t)}var qr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Nt(Rs,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Nt(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new ks((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(kn,10,Le.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=Le.fromBigInt(e);return this._push(kn,r.length(),r)}uint64Number(e){return this._push(rr,Pe(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=Le.fromBigInt(e).zzEncode();return this._push(kn,r.length(),r)}sint64Number(e){let r=Le.fromNumber(e).zzEncode();return this._push(kn,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Ns,1,e?1:0)}fixed32(e){return this._push(Fr,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=Le.fromBigInt(e);return this._push(Fr,4,r.lo)._push(Fr,4,r.hi)}fixed64Number(e){let r=Le.fromNumber(e);return this._push(Fr,4,r.lo)._push(Fr,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(pc,4,e)}double(e){return this._push(yc,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(Ns,1,0):this.uint32(r)._push(pd,r,e)}string(e){let r=xc(e);return r!==0?this.uint32(r)._push(Os,r,e):this._push(Ns,1,0)}fork(){return this.states=new Us(this),this.head=this.tail=new Nt(Rs,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Nt(Rs,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=dd(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function Ns(t,e,r){e[r]=t&255}function hd(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var ks=class extends Nt{next;constructor(e,r){super(hd,e,r),this.next=void 0}};function kn(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function Fr(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function pd(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(qr.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(md,e,t),this},qr.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(yd,e,t),this});function md(t,e,r){e.set(t,r)}function yd(t,e,r){t.length<40?Os(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(V(t),r)}function Ms(){return new qr}function ze(t,e){let r=Ms();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*$e(t,e,r){let n=Kr(t);yield*e.stream(n,void 0,".",r)}var Mn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Kn(t,e,r,n,o){return{name:t,type:e,encode:r,decode:n,stream:o}}function Ks(t){function e(s){if(t[s.toString()]==null)throw new Error("Invalid enum value");return t[s]}let r=function(i,a){let c=e(i);a.int32(c)},n=function(i){let a=i.int32();return e(a)},o=function*(i,a){};return Kn("enum",Mn.VARINT,r,n,o)}function Ye(t,e,r){return Kn("message",Mn.LENGTH_DELIMITED,t,e,r)}var Je=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var ue;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(ue||(ue={}));var Fs;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(Fs||(Fs={}));(function(t){t.codec=()=>Ks(Fs)})(ue||(ue={}));var et;(function(t){let e;t.codec=()=>(e==null&&(e=Ye((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ue.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=ue.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:ue.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return ze(s,t.codec())}t.encode=r;function n(s,i){return He(s,t.codec(),i)}t.decode=n;function o(s,i){return $e(s,t.codec(),i)}t.stream=o})(et||(et={}));var qs;(function(t){let e;t.codec=()=>(e==null&&(e=Ye((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ue.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=ue.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:ue.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return ze(s,t.codec())}t.encode=r;function n(s,i){return He(s,t.codec(),i)}t.decode=n;function o(s,i){return $e(s,t.codec(),i)}t.stream=o})(qs||(qs={}));var Hr={};Ce(Hr,{MAX_RSA_KEY_SIZE:()=>Vs,generateRSAKeyPair:()=>Tc,jwkToJWKKeyPair:()=>_c,jwkToPkcs1:()=>wd,jwkToPkix:()=>Ys,jwkToRSAPrivateKey:()=>Gs,pkcs1MessageToJwk:()=>zs,pkcs1MessageToRSAPrivateKey:()=>js,pkcs1ToJwk:()=>xd,pkcs1ToRSAPrivateKey:()=>Ic,pkixMessageToJwk:()=>$s,pkixMessageToRSAPublicKey:()=>Zs,pkixToJwk:()=>Ed,pkixToRSAPublicKey:()=>Ws});var or=class{type="RSA";jwk;_raw;_multihash;constructor(e,r){this.jwk=e,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Hr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return ge.createV1(114,this._multihash)}toString(){return he.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:pe(this.raw,e.raw)}verify(e,r,n){return Ac(this.jwk,r,e,n)}},Vr=class{type="RSA";jwk;_raw;publicKey;constructor(e,r){this.jwk=e,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Hr.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:pe(this.raw,e.raw)}sign(e,r){return vc(this.jwk,e,r)}};var Vs=8192,Hs=18,bd=1062,gd=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function xd(t){let e=rt(t);return zs(e)}function zs(t){return{n:Y(t[1],"base64url"),e:Y(t[2],"base64url"),d:Y(t[3],"base64url"),p:Y(t[4],"base64url"),q:Y(t[5],"base64url"),dp:Y(t[6],"base64url"),dq:Y(t[7],"base64url"),qi:Y(t[8],"base64url"),kty:"RSA"}}function wd(t){if(t.n==null||t.e==null||t.d==null||t.p==null||t.q==null||t.dp==null||t.dq==null||t.qi==null)throw new ae("JWK was missing components");return dt([Be(Uint8Array.from([0])),Be(V(t.n,"base64url")),Be(V(t.e,"base64url")),Be(V(t.d,"base64url")),Be(V(t.p,"base64url")),Be(V(t.q,"base64url")),Be(V(t.dp,"base64url")),Be(V(t.dq,"base64url")),Be(V(t.qi,"base64url"))]).subarray()}function Ed(t){let e=rt(t,{offset:0});return $s(e)}function $s(t){let e=rt(t[1],{offset:0});return{kty:"RSA",n:Y(e[0],"base64url"),e:Y(e[1],"base64url")}}function Ys(t){if(t.n==null||t.e==null)throw new ae("JWK was missing components");return dt([gd,un(dt([Be(V(t.n,"base64url")),Be(V(t.e,"base64url"))]))]).subarray()}function Ic(t){let e=rt(t);return js(e)}function js(t){let e=zs(t);return Gs(e)}function Ws(t,e){if(t.byteLength>=bd)throw new At("Key size is too large");let r=rt(t,{offset:0});return Zs(r,t,e)}function Zs(t,e,r){let n=$s(t);if(r==null){let o=Zt(et.encode({Type:ue.RSA,Data:e}));r=We(Hs,o)}return new or(n,r)}function Gs(t){if(Bc(t)>Vs)throw new ae("Key size is too large");let e=_c(t),r=Zt(et.encode({Type:ue.RSA,Data:Ys(e.publicKey)})),n=We(Hs,r);return new Vr(e.privateKey,new or(e.publicKey,n))}async function Tc(t){if(t>Vs)throw new ae("Key size is too large");let e=await Cc(t),r=Zt(et.encode({Type:ue.RSA,Data:Ys(e.publicKey)})),n=We(Hs,r);return new Vr(e.privateKey,new or(e.publicKey,n))}function _c(t){if(t==null)throw new ae("Missing key parameter");return{privateKey:t,publicKey:{kty:t.kty,n:t.n,e:t.e}}}async function Cc(t,e){let r=await Me.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:t,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);e?.signal?.throwIfAborted();let n=await Sd(r,e);return{privateKey:n[0],publicKey:n[1]}}async function vc(t,e,r){let n=await Me.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Me.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,_e(e instanceof Uint8Array?e:e.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Ac(t,e,r,n){let o=await Me.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Me.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,_e(e),_e(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),s}async function Sd(t,e){if(t.privateKey==null||t.publicKey==null)throw new ae("Private and public key are required");let r=await Promise.all([Me.get().subtle.exportKey("jwk",t.privateKey),Me.get().subtle.exportKey("jwk",t.publicKey)]);return e?.signal?.throwIfAborted(),r}function Bc(t){if(t.kty!=="RSA")throw new ae("invalid key type");if(t.n==null)throw new ae("invalid key modulus");return V(t.n,"base64url").length*8}var Fn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(dn(e),Ue(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),Dt(o)}update(e){return Wt(this),this.iHash.update(e),this}digestInto(e){Wt(this),hn(e,this),this.finished=!0;let r=e.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a,canXOF:c}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=a,e.canXOF=c,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Dc=(()=>{let t=((e,r,n)=>new Fn(e,r).update(n).digest());return t.create=(e,r)=>new Fn(e,r),t})();var vd=BigInt(0),Xs=class extends Error{constructor(e=""){super(e)}},st={Err:Xs,_tlv:{encode:(t,e)=>{let{Err:r}=st;if(ot(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(Ma(e,"data"),e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,o=Pr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Pr(o.length/2|128):"";return Pr(t)+s+o+e},decode(t,e){let{Err:r}=st;e=G(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.decode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let o=e[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+i)}}},_int:{encode(t){let{Err:e}=st;if(xn(t),t<vd)throw new e("integer: negative integers are not allowed");let r=Pr(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=st;if(t.length<1)throw new e("invalid signature integer: empty");if(t[0]&128)throw new e("invalid signature integer: negative");if(t.length>1&&t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return Qe(t)}},toSig(t,e){let{Err:r,_int:n,_tlv:o}=st;if(e!==void 0&&(ot(e,"maxScalarBytes"),e<1))throw new r("invalid signature: maxScalarBytes must be positive");let s=G(t,void 0,"signature"),{v:i,l:a}=o.decode(48,s);if(a.length)throw new r("invalid signature: left bytes after parsing");let{v:c,l:u}=o.decode(2,i),{v:f,l}=o.decode(2,u);if(l.length)throw new r("invalid signature: left bytes after parsing");if(e!==void 0&&(c.length>e||f.length>e))throw new r("invalid signature: integer too large");return{r:n.decode(c),s:n.decode(f)}},hexFromSig(t){let{_tlv:e,_int:r}=st;Oe(t,{r:"bigint",s:"bigint"},{},"sig");let n=e.encode(2,r.encode(t.r)),o=e.encode(2,r.encode(t.s)),s=n+o;return e.encode(48,s)}},qn=(Object.freeze(st._tlv),Object.freeze(st._int),Object.freeze(st));var Oc=(t,e)=>(t+(t>=0?e:-e)/Pc)/e;function Ad(t,e,r){Xt("scalar",t,it,r);let[[n,o],[s,i]]=e,a=Oc(i*t,r),c=Oc(-o*t,r),u=t-a*n-c*s,f=-a*o-c*i,l=u<it,h=f<it;l&&(u=-u),h&&(f=-f);let p=Rr(Math.ceil(Qt(r)/2))+Ut;if(u<it||u>=p||f<it||f>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:h,k2:f}}function ei(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Qs(t,e){Oe(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return De(r.lowS,"lowS"),De(r.prehash,"prehash"),r.format!==void 0&&ei(r.format),r}var it=BigInt(0),Ut=BigInt(1),Pc=BigInt(2),Js=BigInt(3),Id=BigInt(4);function Lc(t,e={}){let r=_n("weierstrass",t,e),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;Oe(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:u,clearCofactor:f,isTorsionFree:l,fromBytes:h,toBytes:p}=e,x=e.randomBytes===void 0?Pt:e.randomBytes;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let m=c?{beta:c.beta,basises:c.basises.map(v=>[...v])}:void 0,g=Nc(n,o);function w(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function I(v,d,y){if(d.is0()){if(!u)throw new Error("bad point: ZERO");return Uint8Array.of(0)}let{x:E,y:T}=d.toAffine(),C=n.toBytes(E);if(De(y,"isCompressed"),y){w();let B=!n.isOdd(T);return ke(Rc(B),C)}else return ke(Uint8Array.of(4),C,n.toBytes(T))}function b(v){G(v,void 0,"Point");let{publicKey:d,publicKeyUncompressed:y}=g,E=v.length,T=v[0],C=v.subarray(1);if(u&&E===1&&T===0)return{x:n.ZERO,y:n.ZERO};if(E===d&&(T===2||T===3)){let B=n.fromBytes(C);if(!n.isValid(B))throw new Error("bad point: is not on curve, wrong x");let U=P(B),k;try{k=n.sqrt(U)}catch(le){let ne=le instanceof Error?": "+le.message:"";throw new Error("bad point: is not on curve, sqrt error"+ne)}w();let Z=n.isOdd(k);return(T&1)===1!==Z&&(k=n.neg(k)),{x:B,y:k}}else if(E===y&&T===4){let B=n.BYTES,U=n.fromBytes(C.subarray(0,B)),k=n.fromBytes(C.subarray(B,B*2));if(!O(U,k))throw new Error("bad point: is not on curve");return{x:U,y:k}}else throw new Error(`bad point: got length ${E}, expected compressed=${d} or uncompressed=${y}`)}let S=p===void 0?I:p,A=h===void 0?b:h,R=n.mul(s.b,Js),K=n.is0(s.a)?v=>n.ZERO:v=>n.mul(s.a,v);function P(v){let d=n.sqr(v),y=n.mul(d,v);return n.add(n.add(y,n.mul(v,s.a)),s.b)}function O(v,d){let y=n.sqr(d),E=P(v);return n.eql(y,E)}if(!O(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let N=n.mul(n.pow(s.a,Js),Id),F=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(N,F)))throw new Error("bad curve params: a or b");function H(v,d,y=!1){if(!n.isValid(d)||y&&n.is0(d))throw new Error(`bad point coordinate ${v}`);return typeof d=="object"&&d!==null?n.create(d):d}function J(v){if(!(v instanceof L))throw new Error("Weierstrass Point expected")}function _(v){if(!m||!m.basises)throw new Error("no endo");return Ad(v,m.basises,o.ORDER)}function M(v,d,y,E){if(!o.isValid(E))throw new RangeError("invalid scalar: out of range");if(m){let{k1neg:T,k1:C,k2neg:B,k2:U}=_(E),k=new L(n.mul(y.X,m.beta),y.Y,y.Z);v.push(T?y.negate():y,B?k.negate():k),d.push(C,U)}else v.push(y),d.push(E)}let q=new WeakSet;class L{static BASE=new L(s.Gx,s.Gy,n.ONE);static ZERO=new L(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(d,y,E){this.X=H("x",d),this.Y=H("y",y,!0),this.Z=H("z",E),Object.freeze(this)}static CURVE(){return s}static fromAffine(d){let{x:y,y:E}=d||{};if(!d||!n.isValid(y)||!n.isValid(E))throw new Error("invalid affine point");if(d instanceof L)throw new Error("projective point not allowed");return n.is0(y)&&n.is0(E)?L.ZERO:new L(y,E,n.ONE)}static fromBytes(d){let y=L.fromAffine(A(G(d,void 0,"point")));return y.assertValidity(),y}static fromHex(d){return L.fromBytes(Gt(d))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(d=6,y=!0){return ie.setWindowSize(this,d),y||this.multiply(Js),this}assertValidity(){let d=this;if(d.is0()){if(u&&n.is0(d.X)&&n.eql(d.Y,n.ONE)&&n.is0(d.Z))return;throw new Error("bad point: ZERO")}if(q.has(d))return;let{x:y,y:E}=d.toAffine();if(!n.isValid(y)||!n.isValid(E))throw new Error("bad point: x or y not field elements");if(!O(y,E))throw new Error("bad point: equation left != right");if(!d.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");q.add(d)}hasEvenY(){let{y:d}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(d)}equals(d){J(d);let{X:y,Y:E,Z:T}=this,{X:C,Y:B,Z:U}=d,k=n.eql(n.mul(y,U),n.mul(C,T)),Z=n.eql(n.mul(E,U),n.mul(B,T));return k&&Z}negate(){return new L(this.X,n.neg(this.Y),this.Z)}double(){let{X:d,Y:y,Z:E}=this,T=n.ZERO,C=n.ZERO,B=n.ZERO,U=n.mul(d,d),k=n.mul(y,y),Z=n.mul(E,E),$=n.mul(d,y);return $=n.add($,$),B=n.mul(d,E),B=n.add(B,B),T=K(B),C=n.mul(R,Z),C=n.add(T,C),T=n.sub(k,C),C=n.add(k,C),C=n.mul(T,C),T=n.mul($,T),B=n.mul(R,B),Z=K(Z),$=n.sub(U,Z),$=K($),$=n.add($,B),B=n.add(U,U),U=n.add(B,U),U=n.add(U,Z),U=n.mul(U,$),C=n.add(C,U),Z=n.mul(y,E),Z=n.add(Z,Z),U=n.mul(Z,$),T=n.sub(T,U),B=n.mul(Z,k),B=n.add(B,B),B=n.add(B,B),new L(T,C,B)}add(d){J(d);let{X:y,Y:E,Z:T}=this,{X:C,Y:B,Z:U}=d,k=n.ZERO,Z=n.ZERO,$=n.ZERO,le=n.mul(y,C),ne=n.mul(E,B),be=n.mul(T,U),Re=n.add(y,E),oe=n.add(C,B);Re=n.mul(Re,oe),oe=n.add(le,ne),Re=n.sub(Re,oe),oe=n.add(y,T);let de=n.add(C,U);return oe=n.mul(oe,de),de=n.add(le,be),oe=n.sub(oe,de),de=n.add(E,T),k=n.add(B,U),de=n.mul(de,k),k=n.add(ne,be),de=n.sub(de,k),$=K(oe),k=n.mul(R,be),$=n.add(k,$),k=n.sub(ne,$),$=n.add(ne,$),Z=n.mul(k,$),ne=n.add(le,le),ne=n.add(ne,le),be=K(be),oe=n.mul(R,oe),ne=n.add(ne,be),be=n.sub(le,be),be=K(be),oe=n.add(oe,be),le=n.mul(ne,oe),Z=n.add(Z,le),le=n.mul(de,oe),k=n.mul(Re,k),k=n.sub(k,le),le=n.mul(Re,ne),$=n.mul(de,$),$=n.add($,le),new L(k,Z,$)}subtract(d){return J(d),this.add(d.negate())}is0(){return this.equals(L.ZERO)}multiply(d){if(!o.isValidNot0(d))throw new RangeError("invalid scalar: out of range");let{p:y,f:E}=ie.mulSecret(this,d,i,re);return re([y,E])[0]}multiplyUnsafe(d){let y=this,E=d;if(!o.isValid(E))throw new RangeError("invalid scalar: out of range");if(E===it||y.is0())return L.ZERO;if(E===Ut)return y;if(ie.hasWindowSize(this))return ie.mulUnsafe(y,E,re);let T=[],C=[];return M(T,C,y,E),Tn(L,T,C)}mulAddUnsafe(d,y,E){J(y);let T=[],C=[];return M(T,C,this,d),M(T,C,y,E),Tn(L,T,C)}toAffine(d){let y=this,E=d;if(E!=null&&!n.isValid(E))throw new RangeError('"invertedZ" expected valid field element');let{X:T,Y:C,Z:B}=y;if(n.eql(B,n.ONE))return{x:T,y:C};let U=y.is0();E==null&&(E=U?n.ONE:n.inv(B));let k=n.mul(T,E),Z=n.mul(C,E),$=n.mul(B,E);if(U)return{x:n.ZERO,y:n.ZERO};if(!n.eql($,n.ONE))throw new Error("invZ was invalid");return{x:k,y:Z}}isTorsionFree(){return i===Ut?!0:l?l(L,this):ie.mulUnsafe(this,a).is0()}clearCofactor(){return i===Ut?this:f?f(L,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===Ut?this.is0():this.clearCofactor().is0()}toBytes(d=!0){return De(d,"isCompressed"),this.assertValidity(),S(L,this,d)}toHex(d=!0){return Or(this.toBytes(d))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let re=v=>In(L,v),ie=new tr(L,x);return ie.bits>=6&&L.BASE.precompute(6),Object.freeze(L.prototype),Object.freeze(L),L}function Rc(t){return Uint8Array.of(t?2:3)}function Nc(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function Td(t,e={}){wt(t);let{Fn:r}=t,n=e.randomBytes===void 0?Pt:e.randomBytes,o=Object.assign(Nc(t.Fp,r),{seed:Math.max(vn(r.ORDER),16)});function s(p){try{let x=r.fromBytes(p);return r.isValidNot0(x)}catch{return!1}}function i(p,x){let{publicKey:m,publicKeyUncompressed:g}=o;try{let w=p.length;return x===!0&&w!==m||x===!1&&w!==g?!1:!t.fromBytes(p).is0()}catch{return!1}}function a(p){return p=p===void 0?n(o.seed):p,An(G(p,o.seed,"seed"),r.ORDER)}function c(p,x=!0){return t.BASE.multiply(r.fromBytes(p)).toBytes(x)}function u(p){let{secretKey:x,publicKey:m,publicKeyUncompressed:g}=o,w=r._lengths;if(!gt(p))return;let I=G(p,void 0,"key").length,b=I===m||I===g,S=I===x||!!w?.includes(I);if(!(b&&S))return b}function f(p,x,m=!0){if(u(p)===!0)throw new Error("first arg must be private key");if(u(x)===!1)throw new Error("second arg must be public key");let g=r.fromBytes(p),w=t.fromBytes(x);if(w.is0())throw new Error("invalid public key: point at infinity");return w.multiply(g).toBytes(m)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},h=Cn(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:h,Point:t,utils:l,lengths:o})}function Uc(t,e,r={}){wt(t);let n=e;dn(n),Oe(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let o=Object.assign({},r),s=o.randomBytes===void 0?Pt:o.randomBytes,i=o.hmac===void 0?(v,d)=>Dc(n,v,d):o.hmac,{Fp:a,Fn:c}=t,{ORDER:u,BITS:f}=c,l=vn(u),h=ys(s,l),{keygen:p,getPublicKey:x,getSharedSecret:m,utils:g,lengths:w}=Td(t,o),I={prehash:!0,lowS:typeof o.lowS=="boolean"?o.lowS:!0,format:"compact",extraEntropy:!1},b=u*Pc+Ut<a.ORDER;function S(v){let d=u>>Ut;return v>d}function A(v,d){if(!c.isValidNot0(d))throw new Error(`invalid signature ${v}: out of range 1..Point.Fn.ORDER`);return d}function R(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function K(v,d,y){return R(),(v===y?0:2)|Number(a.isOdd(d))}function P(){if(b)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function O(v,d){ei(d);let y=w.signature,E=d==="compact"?y:d==="recovered"?y+1:void 0;return G(v,E)}class N{r;s;recovery;constructor(d,y,E){if(this.r=A("r",d),this.s=A("s",y),E!=null){if(P(),![0,1,2,3].includes(E))throw new Error("invalid recovery id");this.recovery=E}Object.freeze(this)}static fromBytes(d,y=I.format){O(d,y);let E;if(y==="der"){if(d.length>2*c.BYTES+16)throw new qn.Err("invalid signature: DER signature too long");let{r:U,s:k}=qn.toSig(G(d),c.BYTES+1);return new N(U,k)}y==="recovered"&&(E=d[0],y="compact",d=d.subarray(1));let T=w.signature/2,C=d.subarray(0,T),B=d.subarray(T,T*2);return new N(c.fromBytes(C),c.fromBytes(B),E)}static fromHex(d,y){return this.fromBytes(Gt(d),y)}assertRecovery(){let{recovery:d}=this;if(d==null)throw new Error("invalid recovery id: must be present");return d}addRecoveryBit(d){return new N(this.r,this.s,d)}recoverPublicKey(d){let{r:y,s:E}=this,T=this.assertRecovery(),C=T===2||T===3?y+u:y;if(!a.isValid(C))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let B=a.toBytes(C),U=t.fromBytes(ke(Rc((T&1)===0),B)),k=c.inv(C),Z=H(G(d,void 0,"msgHash")),$=c.create(-Z*k),le=c.create(E*k),ne=t.BASE.mulAddUnsafe($,U,le);if(ne.is0())throw new Error("invalid recovery: point at infinify");return ne.assertValidity(),ne}hasHighS(){return S(this.s)}toBytes(d=I.format){if(ei(d),d==="der")return Gt(qn.hexFromSig(this));let{r:y,s:E}=this,T=c.toBytes(y),C=c.toBytes(E);return d==="recovered"?(P(),ke(Uint8Array.of(this.assertRecovery()),T,C)):ke(T,C)}toHex(d){return Or(this.toBytes(d))}}Object.freeze(N.prototype),Object.freeze(N);let F=o.bits2int===void 0?function(d){if(d.length>8192)throw new Error("input is too large");let y=Qe(d),E=d.length*8-f;return E>0?y>>BigInt(E):y}:o.bits2int,H=o.bits2int_modN===void 0?function(d){return c.create(F(d))}:o.bits2int_modN,J=Rr(f);function _(v){return Xt("num < 2^"+f,v,it,J),c.toBytes(v)}function M(v,d){return G(v,void 0,"message"),d?G(n(v),void 0,"prehashed message"):v}function q(v,d,y){let{lowS:E,prehash:T,extraEntropy:C}=Qs(y,I);v=M(v,T);let B=H(v),U=c.fromBytes(d);if(!c.isValidNot0(U))throw new Error("invalid private key");let k=[_(U),_(B)];if(C!=null&&C!==!1){let ne=C===!0?s(w.secretKey):C;k.push(G(ne,void 0,"extraEntropy"))}let Z=ke(...k),$=B;function le(ne){let be=F(ne);if(!c.isValidNot0(be))return;let Re=t.BASE.multiply(be).toAffine(),oe=c.create(Re.x);if(oe===it)return;let de;if(h!==void 0){let gr=Qe(An(h(l),u)),Uu=c.inv(c.mul(gr,be)),ku=c.mul(gr,$),Mu=c.mul(gr,U);de=c.create(Uu*c.create(ku+Mu*oe))}else{let gr=Wa(be,u);de=c.create(gr*c.create($+oe*U))}if(de===it)return;let go=K(Re.x,Re.y,oe),zi=de;return E&&S(de)&&(zi=c.neg(de),go^=1),new N(oe,zi,b?void 0:go)}return{seed:Z,k2sig:le}}function L(v,d,y={}){let{seed:E,k2sig:T}=q(v,d,y);return Fa(n.outputLen,c.BYTES,i)(E,T).toBytes(y.format)}function re(v,d,y,E={}){let{lowS:T,prehash:C,format:B}=Qs(E,I);if(y=G(y,void 0,"publicKey"),d=M(d,C),!gt(v)){let U=v instanceof N?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+U)}O(v,B);try{let U=N.fromBytes(v,B),k=t.fromBytes(y);if(k.is0()||T&&U.hasHighS())return!1;let{r:Z,s:$}=U,le=H(d),ne=c.inv($),be=c.create(le*ne),Re=c.create(Z*ne),oe=t.BASE.mulAddUnsafe(be,k,Re);if(oe.is0())return!1;let de=oe.toAffine();return!(c.create(de.x)!==Z||B==="recovered"&&U.recovery!==K(de.x,de.y,Z))}catch{return!1}}function ie(v,d,y={}){let{prehash:E}=Qs(y,I);return d=M(d,E),N.fromBytes(v,"recovered").recoverPublicKey(d).toBytes()}return Object.freeze({keygen:p,getPublicKey:x,getSharedSecret:m,utils:g,lengths:w,Point:t,sign:L,verify:re,recoverPublicKey:ie,Signature:N,hash:n})}var ri={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},_d={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var kc=BigInt(2);function Cd(t){let e=ri.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=t*t*t%e,f=u*u*t%e,l=se(f,r,e)*f%e,h=se(l,r,e)*f%e,p=se(h,kc,e)*u%e,x=se(p,o,e)*p%e,m=se(x,s,e)*x%e,g=se(m,a,e)*m%e,w=se(g,c,e)*g%e,I=se(w,a,e)*m%e,b=se(I,r,e)*f%e,S=se(b,i,e)*x%e,A=se(S,n,e)*u%e,R=se(A,kc,e);if(!ti.eql(ti.sqr(R),t))throw new Error("Cannot find square root");return R}var ti=er(ri.p,{sqrt:Cd}),Bd=Lc(ri,{Fp:ti,endo:_d}),sr=Uc(Bd,Zt);function Mc(t,e,r,n){let o=Ar.digest(r instanceof Uint8Array?r:r.subarray());if(Rn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),sr.verify(e,s,t,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new kr(String(s))});try{return n?.signal?.throwIfAborted(),sr.verify(e,o.digest,t,{prehash:!1,format:"der"})}catch(s){throw new kr(String(s))}}var Vn=class{type="secp256k1";raw;_key;constructor(e){this._key=Fc(e),this.raw=Kc(this._key)}toMultihash(){return Fe.digest(Ge(this))}toCID(){return ge.createV1(114,this.toMultihash())}toString(){return he.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:pe(this.raw,e.raw)}verify(e,r,n){return Mc(this._key,r,e,n)}};function ni(t){return new Vn(t)}function Kc(t){return sr.Point.fromBytes(t).toBytes()}function Fc(t){try{return sr.Point.fromBytes(t),t}catch(e){throw new At(String(e))}}function ir(t,e){let{Type:r,Data:n}=et.decode(t),o=n??new Uint8Array;switch(r){case ue.RSA:return Ws(o,e);case ue.Ed25519:return Ss(o);case ue.secp256k1:return ni(o);case ue.ECDSA:return Zo(o);default:throw new It}}function qc(t){let{Type:e,Data:r}=et.decode(t.digest),n=r??new Uint8Array;switch(e){case ue.Ed25519:return Ss(n);case ue.secp256k1:return ni(n);case ue.ECDSA:return Zo(n);default:throw new It}}function Ge(t){return et.encode({Type:ue[t.type],Data:t.raw})}var zr;(function(t){let e;t.codec=()=>(e==null&&(e=Ye((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.publicKey!=null&&s.publicKey.byteLength>0&&(i.uint32(10),i.bytes(s.publicKey)),s.payloadType!=null&&s.payloadType.byteLength>0&&(i.uint32(18),i.bytes(s.payloadType)),s.payload!=null&&s.payload.byteLength>0&&(i.uint32(26),i.bytes(s.payload)),s.signature!=null&&s.signature.byteLength>0&&(i.uint32(42),i.bytes(s.signature)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={publicKey:xe(0),payloadType:xe(0),payload:xe(0),signature:xe(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.publicKey=s.bytes();break}case 2:{c.payloadType=s.bytes();break}case 3:{c.payload=s.bytes();break}case 5:{c.signature=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.publicKey`,value:s.bytes()};break}case 2:{yield{field:`${a}.payloadType`,value:s.bytes()};break}case 3:{yield{field:`${a}.payload`,value:s.bytes()};break}case 5:{yield{field:`${a}.signature`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return ze(s,t.codec())}t.encode=r;function n(s,i){return He(s,t.codec(),i)}t.decode=n;function o(s,i){return $e(s,t.codec(),i)}t.stream=o})(zr||(zr={}));var Hn=class extends Error{constructor(e="Invalid signature"){super(e),this.name="InvalidSignatureError"}};var tt=class t{static createFromProtobuf=e=>{let r=zr.decode(e),n=ir(r.publicKey);return new t({publicKey:n,payloadType:r.payloadType,payload:r.payload,signature:r.signature})};static seal=async(e,r,n)=>{if(r==null)throw new Error("Missing private key");let o=e.domain,s=e.codec,i=e.marshal(),a=Vc(o,s,i),c=await r.sign(a.subarray(),n);return new t({publicKey:r.publicKey,payloadType:s,payload:i,signature:c})};static openAndCertify=async(e,r,n)=>{let o=t.createFromProtobuf(e);if(!await o.validate(r,n))throw new Hn("Envelope signature is not valid for the given domain");return o};publicKey;payloadType;payload;signature;marshaled;constructor(e){let{publicKey:r,payloadType:n,payload:o,signature:s}=e;this.publicKey=r,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=zr.encode({publicKey:Ge(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(e){return e==null?!1:pe(this.marshal(),e.marshal())}async validate(e,r){let n=Vc(e,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},Vc=(t,e,r)=>{let n=V(t),o=nr(n.byteLength),s=nr(e.length),i=nr(r.length);return new me(o,n,s,e,i,r)};var Hc=Symbol.for("nodejs.util.inspect.custom"),Dd=114,$r=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[wo]=!0;toString(){return this.string==null&&(this.string=he.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ge.createV1(Dd,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return pe(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return pe(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[Hc](){return`PeerId(${this.toString()})`}},Yr=class extends $r{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},jr=class extends $r{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Wr=class extends $r{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},Od=2336,zn=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Fe.digest(V(this.url))}[Hc](){return`PeerId(${this.url})`}[wo]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ge.createV1(Od,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=Y(e)),e.toString()===this.toString())}};function Zr(t){if(t.type==="Ed25519")return new jr({multihash:t.toCID().multihash,publicKey:t});if(t.type==="secp256k1")return new Wr({multihash:t.toCID().multihash,publicKey:t});if(t.type==="RSA")return new Yr({multihash:t.toCID().multihash,publicKey:t});throw new It}function zc(t){if(Ld(t))return new Yr({multihash:t});if(Pd(t))try{let e=qc(t);if(e.type==="Ed25519")return new jr({multihash:t,publicKey:e});if(e.type==="secp256k1")return new Wr({multihash:t,publicKey:e})}catch{let r=Y(t.digest);return new zn(new URL(r))}throw new nn("Supplied PeerID Multihash is invalid")}function Pd(t){return t.code===Fe.code}function Ld(t){return t.code===Ar.code}var Ee=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},at=class extends Error{static name="ValidationError";name="ValidationError"},$n=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Yn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var jn=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let r=this.index,n=e();return n===void 0&&(this.index=r),n}parseWith(e){let r=e();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let r=this.readChar();if(r===e)return r})}readSeparator(e,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,r,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let h=Number.parseInt(l,e);if(!Number.isNaN(h))return h});if(f===void 0)break;if(s*=e,s+=f,s>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let r=0;r<e.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[r]=n}return e})}readIPv6Addr(){let e=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=e(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var $c=45,Rd=15,ar=new jn;function Wn(t){if(!(t.length>Rd))return ar.new(t).parseWith(()=>ar.readIPv4Addr())}function Zn(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>$c))return ar.new(t).parseWith(()=>ar.readIPv6Addr())}function St(t,e=!1){if(t.includes("%")&&(t=t.split("%")[0]),t.length>$c)return;let r=ar.new(t).parseWith(()=>ar.readIPAddr());if(r)return e&&r.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,r[0],r[1],r[2],r[3]]):r}function cr(t){return!!Wn(t)}function Gn(t){return!!Zn(t)}function si(t){return e=>Y(e,t)}function ii(t){return e=>V(e,t)}function ur(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function kt(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function Yc(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let r=V(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=kt(n);return Ze([r,o],r.length+o.length)}function jc(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let r=lt.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=kt(n);return Ze([r,o],r.length+o.length)}function ai(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=Y(e,"base32"),o=ur(r);return`${n}:${o}`}var ci=function(t){t=t.toString().trim();let e=new Uint8Array(4);return t.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new Ee("Invalid byte value in IP address");e[n]=o}),e},Wc=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let s=cr(r[n]),i;s&&(i=ci(r[n]),r[n]=Y(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,Y(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(e+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new Ee("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},Zc=function(t){if(t.byteLength!==4)throw new Ee("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},Gc=function(t){if(t.byteLength!==16)throw new Ee("IPv6 address was incorrect length");let e=[];for(let n=0;n<t.byteLength;n+=2){let o=t[n],s=t[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;e.push(i)}let r=e.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new Ee(`Invalid IPv6 address "${r}"`)}};function Xc(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new Ee(`Invalid IPv6 address "${t}"`)}}var oi=Object.values(Ir).map(t=>t.decoder),Nd=(function(){let t=oi[0].or(oi[1]);return oi.slice(2).forEach(e=>t=t.or(e)),t})();function Qc(t){return Nd.decode(t)}function Jc(t){return e=>t.encoder.encode(e)}function Ud(t){if(parseInt(t).toString()!==t)throw new at("Value must be an integer")}function kd(t){if(t<0)throw new at("Value must be a positive integer, or zero")}function Md(t){return e=>{if(e>t)throw new at(`Value must be smaller than or equal to ${t}`)}}function Kd(...t){return e=>{for(let r of t)r(e)}}var Gr=Kd(Ud,kd,Md(65535));var we=-1,ui=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let r;if(typeof e=="string"?r=this.protocolsByName.get(e):r=this.protocolsByCode.get(e),r==null)throw new Yn(`Protocol ${e} was unknown`);return r}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(r=>{this.protocolsByName.set(r,e)})}removeProtocol(e){let r=this.protocolsByCode.get(e);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},ut=new ui,Jd=[{code:4,name:"ip4",size:32,valueToBytes:ci,bytesToValue:Zc,validate:t=>{if(!cr(t))throw new at(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:kt,bytesToValue:ur,validate:Gr},{code:273,name:"udp",size:16,valueToBytes:kt,bytesToValue:ur,validate:Gr},{code:33,name:"dccp",size:16,valueToBytes:kt,bytesToValue:ur,validate:Gr},{code:41,name:"ip6",size:128,valueToBytes:Wc,bytesToValue:Gc,stringToValue:Xc,validate:t=>{if(!Gn(t))throw new at(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:we},{code:43,name:"ipcidr",size:8,bytesToValue:si("base10"),valueToBytes:ii("base10")},{code:53,name:"dns",size:we},{code:54,name:"dns4",size:we},{code:55,name:"dns6",size:we},{code:56,name:"dnsaddr",size:we},{code:132,name:"sctp",size:16,valueToBytes:kt,bytesToValue:ur,validate:Gr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:we,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:we,bytesToValue:si("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?ii("base58btc")(t):ge.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:ai,valueToBytes:Yc},{code:445,name:"onion3",size:296,bytesToValue:ai,valueToBytes:jc},{code:446,name:"garlic64",size:we},{code:447,name:"garlic32",size:we},{code:448,name:"tls"},{code:449,name:"sni",size:we},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:we,bytesToValue:Jc(Uo),valueToBytes:Qc},{code:480,name:"http"},{code:481,name:"http-path",size:we,stringToValue:t=>`/${decodeURIComponent(t)}`,valueToString:t=>encodeURIComponent(t.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:we}];Jd.forEach(t=>{ut.addProtocol(t)});function eu(t){let e=[],r=0;for(;r<t.length;){let n=Mr(t,r),o=ut.getProtocol(n),s=Pe(n),i=eh(o,t,r+s),a=0;i>0&&o.size===we&&(a=Pe(i));let c=s+a+i,u={code:n,name:o.name,bytes:_e(t.subarray(r,r+c))};if(i>0){let f=r+s+a,l=t.subarray(f,f+i);u.value=o.bytesToValue?.(l)??Y(l)}e.push(u),r+=c}return e}function tu(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let o=ut.getProtocol(n.code),s=Pe(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??V(n.value),a=i.byteLength,o.size===we&&(c=Pe(a)));let u=new Uint8Array(s+c+a),f=0;rr(n.code,u,f),f+=s,i!=null&&(o.size===we&&(rr(a,u,f),f+=c),u.set(i,f)),n.bytes=u}r.push(n.bytes),e+=n.bytes.byteLength}return Ze(r,e)}function ru(t){if(t.charAt(0)!=="/")throw new Ee('String multiaddr must start with "/"');let e=[],r="protocol",n="",o="";for(let s=1;s<t.length;s++){let i=t.charAt(s);i!=="/"&&(r==="protocol"?o+=t.charAt(s):n+=t.charAt(s));let a=s===t.length-1;if(i==="/"||a){let c=ut.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new Ee(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new Ee(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}e.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new Ee("Incomplete multiaddr");return e}function nu(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=ut.getProtocol(e.code);if(r==null)throw new Ee(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function eh(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:Mr(e,r)}var th=Symbol.for("nodejs.util.inspect.custom"),Ai=Symbol.for("@multiformats/multiaddr");function rh(t){if(t==null&&(t="/"),ou(t))return t.getComponents();if(t instanceof Uint8Array)return eu(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),ru(t);if(Array.isArray(t))return t;throw new Ee("Must be a string, Uint8Array, Component[], or another Multiaddr")}var ro=class t{[Ai]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=rh(e),r.validate!==!1&&nh(this)}get bytes(){return this.#r==null&&(this.#r=tu(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=nu(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}encapsulate(e){let r=new t(e);return new t([...this.#e,...r.getComponents()],{validate:!1})}decapsulate(e){let r=e.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new $n(`Address ${this.toString()} does not contain subaddress: ${r}`);return new t(n.slice(0,o),{validate:!1})}decapsulateCode(e){let r;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){r=n;break}return new t(this.#e.slice(0,r),{validate:!1})}equals(e){return pe(this.bytes,e.bytes)}[th](){return`Multiaddr(${this.toString()})`}};function nh(t){t.getComponents().forEach(e=>{let r=ut.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function ou(t){return!!t?.[Ai]}function Qr(t){return new ro(t)}var su="libp2p-peer-record",iu=Uint8Array.from([3,1]);var Jr;(function(t){let e;(function(i){let a;i.codec=()=>(a==null&&(a=Ye((l,h,p={})=>{p.lengthDelimited!==!1&&h.fork(),l.multiaddr!=null&&l.multiaddr.byteLength>0&&(h.uint32(10),h.bytes(l.multiaddr)),p.lengthDelimited!==!1&&h.ldelim()},(l,h,p={})=>{let x={multiaddr:xe(0)},m=h==null?l.len:l.pos+h;for(;l.pos<m;){let g=l.uint32();g>>>3===1?x.multiaddr=l.bytes():l.skipType(g&7)}return x},function*(l,h,p,x={}){let m=h==null?l.len:l.pos+h;for(;l.pos<m;){let g=l.uint32();g>>>3===1?yield{field:`${p}.multiaddr`,value:l.bytes()}:l.skipType(g&7)}})),a);function c(l){return ze(l,i.codec())}i.encode=c;function u(l,h){return He(l,i.codec(),h)}i.decode=u;function f(l,h){return $e(l,i.codec(),h)}i.stream=f})(e=t.AddressInfo||(t.AddressInfo={}));let r;t.codec=()=>(r==null&&(r=Ye((i,a,c={})=>{if(c.lengthDelimited!==!1&&a.fork(),i.peerId!=null&&i.peerId.byteLength>0&&(a.uint32(10),a.bytes(i.peerId)),i.seq!=null&&i.seq!==0n&&(a.uint32(16),a.uint64(i.seq)),i.addresses!=null&&i.addresses.length>0)for(let u of i.addresses)a.uint32(26),t.AddressInfo.codec().encode(u,a);c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let u={peerId:xe(0),seq:0n,addresses:[]},f=a==null?i.len:i.pos+a;for(;i.pos<f;){let l=i.uint32();switch(l>>>3){case 1:{u.peerId=i.bytes();break}case 2:{u.seq=i.uint64();break}case 3:{if(c.limits?.addresses!=null&&u.addresses.length===c.limits.addresses)throw new Je('Decode error - repeated field "addresses" had too many elements');u.addresses.push(t.AddressInfo.codec().decode(i,i.uint32(),{limits:c.limits?.addresses$}));break}default:{i.skipType(l&7);break}}}return u},function*(i,a,c,u={}){let f={addresses:0},l=a==null?i.len:i.pos+a;for(;i.pos<l;){let h=i.uint32();switch(h>>>3){case 1:{yield{field:`${c}.peerId`,value:i.bytes()};break}case 2:{yield{field:`${c}.seq`,value:i.uint64()};break}case 3:{if(u.limits?.addresses!=null&&f.addresses===u.limits.addresses)throw new Je('Streaming decode error - repeated field "addresses" had too many elements');for(let p of t.AddressInfo.codec().stream(i,i.uint32(),`${c}.addresses[]`,{limits:u.limits?.addresses$}))yield{...p,index:f.addresses};f.addresses++;break}default:{i.skipType(h&7);break}}}})),r);function n(i){return ze(i,t.codec())}t.encode=n;function o(i,a){return He(i,t.codec(),a)}t.decode=o;function s(i,a){return $e(i,t.codec(),a)}t.stream=s})(Jr||(Jr={}));function au(t,e){let r=(n,o)=>n.toString().localeCompare(o.toString());return t.length!==e.length?!1:(e.sort(r),t.sort(r).every((n,o)=>e[o].equals(n)))}var je=class t{static createFromProtobuf=e=>{let r=Jr.decode(e),n=zc(Sr(r.peerId)),o=(r.addresses??[]).map(i=>Qr(i.multiaddr)),s=r.seq;return new t({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=su;static CODEC=iu;peerId;multiaddrs;seqNumber;domain=t.DOMAIN;codec=t.CODEC;marshaled;constructor(e){let{peerId:r,multiaddrs:n,seqNumber:o}=e;this.peerId=r,this.multiaddrs=n??[],this.seqNumber=o??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=Jr.encode({peerId:this.peerId.toMultihash().bytes,seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(e=>({multiaddr:e.bytes}))})),this.marshaled}equals(e){return!(!(e instanceof t)||!this.peerId.equals(e.peerId)||this.seqNumber!==e.seqNumber||!au(this.multiaddrs,e.multiaddrs))}};function oh(t){let e=t.getComponents(),r={},n=0;return e[n]?.name==="ip6zone"&&(r.zone=`${e[n].value}`,n++),e[n]?.name==="ip4"||e[n]?.name==="ip6"||e[n]?.name==="dns"||e[n]?.name==="dns4"||e[n]?.name==="dns6"?(r.type=e[n].name,r.host=e[n].value,n++):e[n]?.name==="dnsaddr"&&(r.type=e[n].name,r.host=`_dnsaddr.${e[n].value}`,n++),(e[n]?.name==="tcp"||e[n]?.name==="udp")&&(r.protocol=e[n].name==="tcp"?"tcp":"udp",r.port=parseInt(`${e[n].value}`),n++),e[n]?.name==="ipcidr"&&(r.type==="ip4"?r.cidr=parseInt(`${e[n].value}`):r.type==="ip6"&&(r.cidr=`${e[n].value}`),n++),r.type==null||r.host==null?null:(e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(r.sni=e[n+1].value,n+=2),r)}function no(t){let e=oh(t);if(e==null)throw new ae(`Multiaddr ${t} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}function cu(t,e,r){let n=0;for(let o of t)if(!(n<e)){if(n>r)break;if(o!==255)return!1;n++}return!0}function Ii(t,e,r,n){let o=0;for(let s of t)if(!(o<r)){if(o>n)break;if(s!==e[o])return!1;o++}return!0}function Ti(t){switch(t.length){case Kt:return t.join(".");case Ft:{let e=[];for(let r=0;r<t.length;r++)r%2===0&&e.push(t[r].toString(16).padStart(2,"0")+t[r+1].toString(16).padStart(2,"0"));return e.join(":")}default:throw new Error("Invalid ip length")}}function uu(t){let e=0;for(let[r,n]of t.entries()){if(n===255){e+=8;continue}for(;(n&128)!=0;)e++,n=n<<1;if((n&128)!=0)return-1;for(let o=r+1;o<t.length;o++)if(t[o]!=0)return-1;break}return e}function fu(t){let e="0x";for(let r of t)e+=(r>>4).toString(16)+(r&15).toString(16);return e}var Kt=4,Ft=16,$x=parseInt("0xFFFF",16),lu=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function en(t,e){e.length===Ft&&t.length===Kt&&cu(e,0,11)&&(e=e.slice(12)),e.length===Kt&&t.length===Ft&&Ii(t,lu,0,11)&&(t=t.slice(12));let r=t.length;if(r!=e.length)throw new Error("Failed to mask ip");let n=new Uint8Array(r);for(let o=0;o<r;o++)n[o]=t[o]&e[o];return n}function du(t,e){if(typeof e=="string"&&(e=St(e)),e==null)throw new Error("Invalid ip");if(e.length!==t.network.length)return!1;for(let r=0;r<e.length;r++)if((t.network[r]&t.mask[r])!==(e[r]&t.mask[r]))return!1;return!0}function _i(t){if(!oo(t))throw new Error("Must have 0xffff prefix");return t.slice(12)}function oo(t){return Ii(t,lu,0,11)}function Ci(t){let[e,r]=t.split("/");if(!e||!r)throw new Error("Failed to parse given CIDR: "+t);let n=Kt,o=Wn(e);if(o==null&&(n=Ft,o=Zn(e),o==null))throw new Error("Failed to parse given CIDR: "+t);let s=parseInt(r,10);if(Number.isNaN(s)||String(s).length!==r.length||s<0||s>n*8)throw new Error("Failed to parse given CIDR: "+t);let i=Bi(s,8*n);return{network:en(o,i),mask:i}}function Bi(t,e){if(e!==8*Kt&&e!==8*Ft)throw new Error("Invalid CIDR mask");if(t<0||t>e)throw new Error("Invalid CIDR mask");let r=e/8,n=new Uint8Array(r);for(let o=0;o<r;o++){if(t>=8){n[o]=255,t-=8;continue}n[o]=255-(255>>t),t=0}return n}var qt=class{constructor(e,r){if(r==null)({network:this.network,mask:this.mask}=Ci(e));else{let n=St(e);if(n==null)throw new Error("Failed to parse network");r=String(r);let o=parseInt(r,10);if(Number.isNaN(o)||String(o).length!==r.length||o<0||o>n.length*8){let s=St(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Bi(o,8*n.length);this.network=en(n,this.mask)}}contains(e){return du({network:this.network,mask:this.mask},e)}toString(){let e=uu(this.mask),r=e!==-1?String(e):fu(this.mask);return Ti(this.network)+"/"+r}};function hu(t,e){return new qt(t).contains(e)}function pu(t){try{let e=no(t);return e.type==="ip6"?hu("2000::/3",e.host):!1}catch{return!1}}var sh=["0.0.0.0/8","10.0.0.0/8","100.64.0.0/10","127.0.0.0/8","169.254.0.0/16","172.16.0.0/12","192.0.0.0/24","192.0.0.0/29","192.0.0.8/32","192.0.0.9/32","192.0.0.10/32","192.0.0.170/32","192.0.0.171/32","192.0.2.0/24","192.31.196.0/24","192.52.193.0/24","192.88.99.0/24","192.168.0.0/16","192.175.48.0/24","198.18.0.0/15","198.51.100.0/24","203.0.113.0/24","240.0.0.0/4","255.255.255.255/32","::/128","::1/128","64:ff9b::/96","100::/64","2001::/32","2001:20::/28","2001:db8::/32","2002::/16","fc00::/7","fe80::/10","ff00::/8"].map(t=>new qt(t));function mu(t){if(!cr(t)&&!Gn(t))return;let e=St(t);if(e==null)return;let r=e.length===16&&oo(e)?_i(e):e;return sh.some(n=>n.contains(r))}function yu(t){try{let e=no(t);switch(e.type){case"ip4":case"ip6":return mu(e.host)??!1;default:return e.host==="localhost"}}catch{return!1}}var ee=t=>({match:e=>{let r=e[0];return r==null||r.code!==t||r.value!=null?!1:e.slice(1)}}),D=(t,e)=>({match:r=>{let n=r[0];return n?.code!==t||n.value==null||e!=null&&n.value!==e?!1:r.slice(1)}}),bu=t=>({match:e=>t.match(e)===!1?e:!1}),z=t=>({match:e=>{let r=t.match(e);return r===!1?e:r}}),Ie=(...t)=>({match:e=>{let r;for(let n of t){let o=n.match(e);o!==!1&&(r==null||o.length<r.length)&&(r=o)}return r??!1}}),W=(...t)=>({match:e=>{for(let r of t){let n=r.match(e);if(n===!1)return!1;e=n}return e}});function te(...t){function e(o){if(o==null)return!1;let s=o.getComponents();for(let i of t){let a=i.match(s);if(a===!1)return!1;s=a}return s}function r(o){return e(o)!==!1}function n(o){let s=e(o);return s===!1?!1:s.length===0}return{matchers:t,matches:r,exactMatch:n}}var ih=D(421),ww=te(ih),io=D(54),ao=D(55),co=D(56),Oi=D(53),Ew=te(io,z(D(421))),Sw=te(ao,z(D(421))),vw=te(co,z(D(421))),Aw=te(Ie(Oi,co,io,ao),z(D(421))),gu=W(D(4),z(D(43))),xu=W(z(D(42)),D(41),z(D(43))),Pi=Ie(gu,xu),pr=Ie(Pi,Oi,io,ao,co),wu=te(Ie(Pi,W(Ie(Oi,co,io,ao),z(D(421))))),Iw=te(gu),Tw=te(xu),_w=te(Pi),Li=W(pr,D(6)),tn=W(pr,D(273)),Eu=te(W(Li,z(D(421)))),Cw=te(tn),Ri=W(tn,ee(460),z(D(421))),uo=W(tn,ee(461),z(D(421))),ah=Ie(Ri,uo),Bw=te(Ri),Dw=te(uo),Di=Ie(pr,Li,tn,Ri,uo),Su=Ie(W(Di,ee(477),z(D(421)))),Ow=te(Su),vu=Ie(W(Di,ee(478),z(D(421))),W(Di,ee(448),z(D(449)),ee(477),z(D(421)))),Pw=te(vu),Au=W(tn,ee(280),z(D(466)),z(D(466)),z(D(421))),Lw=te(Au),Iu=W(uo,ee(465),z(D(466)),z(D(466)),z(D(421))),Rw=te(Iu),so=Ie(Su,vu,W(Li,z(D(421))),W(ah,z(D(421))),W(pr,z(D(421))),Au,Iu,D(421)),Nw=te(so),ch=W(z(so),ee(290),bu(ee(281)),z(D(421))),Uw=te(ch),uh=Ie(W(so,ee(290),ee(281),z(D(421))),W(so,ee(281),z(D(421))),W(ee(281),z(D(421)))),kw=te(uh),fh=W(pr,Ie(W(D(6,"80")),W(D(6),ee(480)),ee(480)),z(D(481)),z(D(421))),Mw=te(fh),lh=W(pr,Ie(W(D(6,"443")),W(D(6,"443"),ee(480)),W(D(6),ee(443)),W(D(6),ee(448),ee(480)),W(ee(448),ee(480)),ee(448),ee(443)),z(D(481)),z(D(421))),Kw=te(lh),dh=Ie(W(D(777),z(D(421)))),Fw=te(dh),hh=Ie(W(D(400),z(D(421)))),qw=te(hh);function mr(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Ni=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},ph=t=>"reason"in t?t.reason:new DOMException("This operation was aborted.","AbortError"),mh=2**31-1,yh=(t,e)=>{if(typeof t!="number"||Math.sign(t)!==1)return new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(typeof e?.setTimeout!="function"||typeof e?.clearTimeout!="function")return new TypeError("Expected `customTimers` to have a `setTimeout` and a `clearTimeout` function")};function Ui(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=e,a,c,u=()=>{try{t.cancel?.()}catch{}},l=new Promise((h,p)=>{let x=()=>{p(ph(i)),u()},m=yh(r,s);try{m?p(m):i?.aborted?x():i&&(c=x,i.addEventListener("abort",c,{once:!0}))}finally{t.then(h,p)}if(m||i?.aborted||r>mh)return;let g=n||o===!1||o instanceof Error?void 0:new Ni(o??`Promise timed out after ${r} milliseconds`);a=s.setTimeout.call(void 0,()=>{if(n)try{h(n())}catch(w){p(w)}else o===!1?h():p(o instanceof Error?o:g);u()},r)}).finally(()=>{try{l.clear()}catch{}try{c&&i.removeEventListener("abort",c)}catch{}});return l.clear=()=>{a!==void 0&&(s.clearTimeout.call(void 0,a),a=void 0)},l}var Tu=t=>typeof t=="function"?{filter:t}:{...t},bh=t=>t===1/0||Number.isSafeInteger(t)&&t>=0,gh=[["addEventListener","removeEventListener"],["on","off"],["addListener","removeListener"]],xh=t=>{for(let[e,r]of gh){let n=t?.[e],o=t?.[r];if(typeof n=="function"&&typeof o=="function")return{addListener:n.bind(t),removeListener:o.bind(t)}}throw new TypeError("Emitter is not compatible")},wh=t=>{let e=new Map;for(let[r,n]of t)for(let o of Array.isArray(r)?r:[r])e.has(o)||e.set(o,n);return e},Eh=({addListener:t,removeListener:e,handlers:r,signal:n,abortHandler:o,isDone:s})=>{n?.addEventListener("abort",o,{once:!0});for(let[i,a]of r)if(t(i,a),s()){e(i,a);return}},Sh=({removeListener:t,handlers:e,signal:r,abortHandler:n})=>{for(let[o,s]of e)t(o,s);r?.removeEventListener("abort",n)},vh=(t,e,r)=>{let n=Promise.resolve();return(o,s)=>{n=n.then(async()=>{if(e())return;let i;try{i=t?await t(o):!0}catch(a){e()||r(a);return}e()||s(i)})}};function Ah(t,e,r){let n=()=>{},o=!1,s,i=new Promise((a,c)=>{r=Tu(r);let{filter:u}=r;if(!bh(r.count))throw new TypeError("The `count` option should be at least 0 or more");if(typeof r.timeout=="number"&&!(r.timeout>0))throw new TypeError(`Expected the \`timeout\` option to be a positive number, got \`${r.timeout}\``);r.signal?.throwIfAborted();let{addListener:f,removeListener:l}=xh(t);if(r.count===0){a([]);return}let h=[],p=S=>{n(),c(S)},x=vh(u,()=>o,p),m=S=>{h.push(S),r.count===h.length&&(n(),a(h))},g=(...S)=>{if(o)return;let A=r.multiArgs?S:S[0];if(!u){m(A);return}x(A,R=>{R&&m(A)})},w=(...S)=>{p(r.rejectionMultiArgs?S:S[0])},I=()=>{p(r.signal.reason)},b={addListener:f,removeListener:l,handlers:wh([[e,g],[r.rejectionEvents??["error"],w]]),signal:r.signal,abortHandler:I,isDone:()=>o};n=()=>{o=!0,clearTimeout(s),Sh(b)},Eh(b),!(o||!r.resolveImmediately)&&(Number.isFinite(r.timeout)&&r.timeout<=2**31-1&&(s=setTimeout(n,r.timeout)),a(h))});if(i.cancel=n,typeof r.timeout=="number"&&r.timeout>0&&!r.resolveImmediately){let a=Ui(i,{milliseconds:r.timeout});return a.cancel=()=>{n(),a.clear()},a}return i}function _u(t,e,r){let n=Ah(t,e,{...Tu(r),count:1,resolveImmediately:!1}),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function Cu(t,e){let r,n=function(){let o=function(){r=void 0,t()};clearTimeout(r),r=setTimeout(o,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var Vt=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Ih(t){return t.reason}function ki(t,e,r){if(e==null||t==null)return t;let n=r?.translateError??Ih;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;return Promise.race([t,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})]).finally(()=>{o!=null&&e.removeEventListener("abort",o)})}var _h=4194304,fo=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Ki=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Fi=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},qi=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Ch(t){return typeof t?.closeRead=="function"}function Bh(t){return typeof t?.close=="function"}function Mi(t){return Ch(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:Bh(t)?t.status!=="open":!1}function Dh(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function Oh(t,e){let r=e?.maxBufferSize??_h,n=new me,o,s=!1,i;if(!Dh(t))throw new ae("Argument should be a Stream or a Multiaddr");let a=l=>{if(!s&&i==null){if(n.append(l.data),n.byteLength>r){let h=n.byteLength;n.consume(h);let p=new rn(`Read buffer overflow - ${h} > ${r}`);i=p,o?.reject(p),queueMicrotask(()=>{t.abort(p)});return}o?.resolve()}};t.addEventListener("message",a);let c=l=>{l.error!=null?o?.reject(l.error):o?.resolve()};t.addEventListener("close",c);let u=()=>{o?.resolve()};t.addEventListener("remoteCloseWrite",u);let f={readBuffer:n,async read(l){if(s===!0)throw new fo("Stream was unwrapped");if(i!=null)throw i;if(Mi(t)){if(n.byteLength===0&&l?.bytes==null)return null;if(l?.bytes!=null&&n.byteLength<l.bytes)throw t.log.error("closed after reading %d/%d bytes",n.byteLength,l.bytes),new Vt(`Unexpected EOF - stream closed after reading ${n.byteLength}/${l.bytes} bytes`)}let h=l?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=h){o.resolve();break}if(await ki(o.promise,l?.signal),Mi(t)){if(n.byteLength===0&&l?.bytes==null)return null;break}o=Promise.withResolvers()}let p=l?.bytes??n.byteLength;if(n.byteLength<p){if(Mi(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,p),new Vt(`Unexpected EOF - stream closed while reading ${n.byteLength}/${p} bytes`);return f.read(l)}let x=n.sublist(0,p);return n.consume(p),x},async write(l,h){if(s===!0)throw new fo("Stream was unwrapped");t.send(l)||await _u(t,"drain",{signal:h?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,t.removeEventListener("message",a),t.removeEventListener("close",c),t.removeEventListener("remoteCloseWrite",u),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.unshift(n),n.consume(n.byteLength))),t}};return f}function Ph(t,e={}){let r=Oh(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Pe(e.maxDataLength));let n=e?.lengthDecoder??Mr,o=e?.lengthEncoder??nr;return{async read(i){let a=-1,c=new me;for(;;){let f=await r.read({...i,bytes:1});if(f==null)break;c.append(f);try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new Ki("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new qi(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new Fi(`Message length too long - ${a} > ${e.maxDataLength}`);let u=await r.read({...i,bytes:a});if(u==null)throw t.log.error("tried to read %d bytes but the stream closed",a),new Vt(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw t.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new Vt(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await r.write(new me(o(i.byteLength),i),a)},async writeV(i,a){let c=new me(...i.flatMap(u=>[o(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}function yr(t,e){let r=Ph(t,e),n={read:async(o,s)=>{let i=await r.read(s);return o.decode(i,s)},write:async(o,s,i)=>{await r.write(s.encode(o),i)},writeV:async(o,s,i)=>{await r.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}function Lh(t){return t[Symbol.asyncIterator]!=null}function Rh(t){if(Lh(t))return(async()=>{for await(let e of t);})();for(let e of t);}var Bu=Rh;var lo=globalThis.CustomEvent??Event;async function*Vi(t,e={}){let r=e.concurrency??1/0;r<1&&(r=1/0);let n=e.ordered??!1,o=new EventTarget,s=[],i=mr(),a=mr(),c=!1,u,f=!1,l=!1;o.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let m of t){if(s.length===r&&(i=mr(),await i.promise),f||l)break;let g={done:!1};s.push(g),m().then(w=>{g.done=!0,g.ok=!0,g.value=w,o.dispatchEvent(new lo("task-complete"))},w=>{g.done=!0,g.err=w,o.dispatchEvent(new lo("task-complete"))})}c=!0,o.dispatchEvent(new lo("task-complete"))}catch(m){u=m,o.dispatchEvent(new lo("task-complete"))}});function h(){return n?s[0]?.done:!!s.find(m=>m.done)}function*p(){for(;s.length>0&&s[0].done;){let m=s[0];if(s.shift(),m.ok)yield m.value;else throw f=!0,i.resolve(),m.err;i.resolve()}}function*x(){for(;h();)for(let m=0;m<s.length;m++)if(s[m].done){let g=s[m];if(s.splice(m,1),m--,g.ok)yield g.value;else throw f=!0,i.resolve(),g.err;i.resolve()}}try{for(;;){if(h()||(a=mr(),await a.promise),u!=null||(n?yield*p():yield*x(),u!=null))throw u;if(c&&s.length===0)break}}finally{l=!0,i.resolve()}}var Du="0.1.0";var Ou="id/push",Pu="1.0.0",Lu="1.0.0";var vt;(function(t){let e;t.codec=()=>(e==null&&(e=Ye((s,i,a={})=>{if(a.lengthDelimited!==!1&&i.fork(),s.protocolVersion!=null&&(i.uint32(42),i.string(s.protocolVersion)),s.agentVersion!=null&&(i.uint32(50),i.string(s.agentVersion)),s.publicKey!=null&&(i.uint32(10),i.bytes(s.publicKey)),s.listenAddrs!=null&&s.listenAddrs.length>0)for(let c of s.listenAddrs)i.uint32(18),i.bytes(c);if(s.observedAddr!=null&&(i.uint32(34),i.bytes(s.observedAddr)),s.protocols!=null&&s.protocols.length>0)for(let c of s.protocols)i.uint32(26),i.string(c);s.signedPeerRecord!=null&&(i.uint32(66),i.bytes(s.signedPeerRecord)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={listenAddrs:[],protocols:[]},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 5:{c.protocolVersion=s.string();break}case 6:{c.agentVersion=s.string();break}case 1:{c.publicKey=s.bytes();break}case 2:{if(a.limits?.listenAddrs!=null&&c.listenAddrs.length===a.limits.listenAddrs)throw new Je('Decode error - repeated field "listenAddrs" had too many elements');c.listenAddrs.push(s.bytes());break}case 4:{c.observedAddr=s.bytes();break}case 3:{if(a.limits?.protocols!=null&&c.protocols.length===a.limits.protocols)throw new Je('Decode error - repeated field "protocols" had too many elements');c.protocols.push(s.string());break}case 8:{c.signedPeerRecord=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u={listenAddrs:0,protocols:0},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let l=s.uint32();switch(l>>>3){case 5:{yield{field:`${a}.protocolVersion`,value:s.string()};break}case 6:{yield{field:`${a}.agentVersion`,value:s.string()};break}case 1:{yield{field:`${a}.publicKey`,value:s.bytes()};break}case 2:{if(c.limits?.listenAddrs!=null&&u.listenAddrs===c.limits.listenAddrs)throw new Je('Streaming decode error - repeated field "listenAddrs" had too many elements');yield{field:`${a}.listenAddrs[]`,index:u.listenAddrs,value:s.bytes()},u.listenAddrs++;break}case 4:{yield{field:`${a}.observedAddr`,value:s.bytes()};break}case 3:{if(c.limits?.protocols!=null&&u.protocols===c.limits.protocols)throw new Je('Streaming decode error - repeated field "protocols" had too many elements');yield{field:`${a}.protocols[]`,index:u.protocols,value:s.string()},u.protocols++;break}case 8:{yield{field:`${a}.signedPeerRecord`,value:s.bytes()};break}default:{s.skipType(l&7);break}}}})),e);function r(s){return ze(s,t.codec())}t.encode=r;function n(s,i){return He(s,t.codec(),i)}t.decode=n;function o(s,i){return $e(s,t.codec(),i)}t.stream=o})(vt||(vt={}));var Te={protocolPrefix:"ipfs",timeout:5e3,maxInboundStreams:1,maxOutboundStreams:1,maxObservedAddresses:10,maxListenAddresses:100,maxMessageSize:8192,runOnConnectionOpen:!0,runOnSelfUpdate:!0,runOnLimitedConnection:!0,concurrency:32};function Nu(t){return t.bytes.length===0}function Hi(t){if(t!=null&&t.length>0)try{let e=Qr(t);if(!Nu(e))return e}catch{}}async function ho(t,e,r,n,o,s=Te.maxListenAddresses){if(r("received identify from %p",n.remotePeer),o==null)throw new Ke("message was null or undefined");let i={};o.listenAddrs.length>s&&r("%p sent %d listen addresses, ignoring all but the first %d",n.remotePeer,o.listenAddrs.length,s);let a=o.listenAddrs.slice(0,s).map(Hi).filter(f=>f!=null);if(o.listenAddrs.length>0&&(i.addresses=a.map(f=>({isCertified:!1,multiaddr:f}))),o.protocols.length>0&&(i.protocols=o.protocols),o.publicKey!=null){let f=ir(o.publicKey);if(!Zr(f).equals(n.remotePeer))throw new Ke("public key did not match remote PeerId");i.publicKey=f}let c;if(o.signedPeerRecord!=null){r.trace("received signedPeerRecord from %p",n.remotePeer);let f=o.signedPeerRecord,l=await tt.openAndCertify(f,je.DOMAIN),h=je.createFromProtobuf(l.payload),p=Zr(l.publicKey);if(!h.peerId.equals(p))throw new Ke("signing key does not match PeerId in the PeerRecord");if(!n.remotePeer.equals(h.peerId))throw new Ke("signing key does not match remote PeerId");let x;try{x=await t.get(h.peerId)}catch(g){if(g.name!=="NotFoundError")throw g}if(x!=null&&(i.metadata=x.metadata,x.peerRecordEnvelope!=null)){let g=tt.createFromProtobuf(x.peerRecordEnvelope),w=je.createFromProtobuf(g.payload);w.seqNumber>=h.seqNumber&&(r("sequence number was lower or equal to existing sequence number - stored: %d received: %d",w.seqNumber,h.seqNumber),h=w,f=x.peerRecordEnvelope)}i.peerRecordEnvelope=f;let m=h.multiaddrs.filter(g=>!Nu(g)).slice(0,s);i.addresses=m.map(g=>({isCertified:!0,multiaddr:g})),c={seq:h.seqNumber,addresses:m}}else r("%p did not send a signed peer record",n.remotePeer);if(r.trace("patching %p with",n.remotePeer,i),await t.patch(n.remotePeer,i),o.agentVersion!=null||o.protocolVersion!=null){let f={};o.agentVersion!=null&&(f.AgentVersion=V(o.agentVersion)),o.protocolVersion!=null&&(f.ProtocolVersion=V(o.protocolVersion)),r.trace("merging %p metadata",n.remotePeer,f),await t.merge(n.remotePeer,{metadata:f})}let u={peerId:n.remotePeer,protocolVersion:o.protocolVersion,agentVersion:o.agentVersion,publicKey:o.publicKey,listenAddrs:a,observedAddr:o.observedAddr==null?void 0:Qr(o.observedAddr),protocols:o.protocols,signedPeerRecord:c,connection:n};return e.safeDispatchEvent("peer:identify",{detail:u}),u}function po(t){let e={...t[0]};for(let r of t.slice(1))r.protocolVersion!=null&&(e.protocolVersion=r.protocolVersion),r.agentVersion!=null&&(e.agentVersion=r.agentVersion),r.publicKey!=null&&(e.publicKey=r.publicKey),r.observedAddr!=null&&(e.observedAddr=r.observedAddr),r.signedPeerRecord!=null&&(e.signedPeerRecord=r.signedPeerRecord),e.listenAddrs=[...e.listenAddrs,...r.listenAddrs],e.protocols=[...new Set([...e.protocols,...r.protocols])];return e}async function mo(t,e,r,n){let o=yr(t,{maxDataLength:e}).pb(vt),s=[];for(let i=0;i<10;i++)try{s.push(await o.read(r))}catch(a){if(s.length===0)throw a;n.trace("stopped reading identify - %e",a);break}s.length>=10&&n("reached MAX_IDENTIFY_MESSAGES, returning truncated identify");try{await t.close(r)}catch(i){n.trace("error closing identify stream after read - %e",i),t.abort(i)}return s}var br=class{host;components;protocol;started;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxObservedAddresses;maxListenAddresses;runOnLimitedConnection;log;constructor(e,r){this.protocol=r.protocol,this.started=!1,this.components=e,this.log=r.log,this.timeout=r.timeout??Te.timeout,this.maxInboundStreams=r.maxInboundStreams??Te.maxInboundStreams,this.maxOutboundStreams=r.maxOutboundStreams??Te.maxOutboundStreams,this.maxMessageSize=r.maxMessageSize??Te.maxMessageSize,this.maxObservedAddresses=r.maxObservedAddresses??Te.maxObservedAddresses,this.maxListenAddresses=r.maxListenAddresses??Te.maxListenAddresses,this.runOnLimitedConnection=r.runOnLimitedConnection??Te.runOnLimitedConnection,this.host={protocolVersion:`${r.protocolPrefix??Te.protocolPrefix}/${Du}`,agentVersion:e.nodeInfo.userAgent},this.handleProtocol=this.handleProtocol.bind(this)}isStarted(){return this.started}async start(){this.started||(await this.components.peerStore.merge(this.components.peerId,{metadata:{AgentVersion:V(this.host.agentVersion),ProtocolVersion:V(this.host.protocolVersion)}}),await this.components.registrar.handle(this.protocol,this.handleProtocol,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams,runOnLimitedConnection:this.runOnLimitedConnection}),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.protocol),this.started=!1}};var yo=class extends br{connectionManager;concurrency;_push;constructor(e,r={}){super(e,{...r,protocol:`/${r.protocolPrefix??Te.protocolPrefix}/${Ou}/${Lu}`,log:e.logger.forComponent("libp2p:identify-push")}),this.connectionManager=e.connectionManager,this.concurrency=r.concurrency??Te.concurrency,this._push=Cu(this.sendPushMessage.bind(this),r.debounce??1e3),(r.runOnSelfUpdate??Te.runOnSelfUpdate)&&e.events.addEventListener("self:peer:update",n=>{this.push().catch(o=>{this.log.error("error pushing updates to peers - %e",o)})})}[on]=["@libp2p/identify-push"];async push(){this._push()}async sendPushMessage(){if(this.isStarted())try{let e=this.components.addressManager.getAddresses().map(f=>f.decapsulateCode(421)),r=new je({peerId:this.components.peerId,multiaddrs:e}),n=await tt.seal(r,this.components.privateKey),o=this.components.registrar.getProtocols(),s=await this.components.peerStore.get(this.components.peerId),i=Y(s.metadata.get("AgentVersion")??V(this.host.agentVersion)),a=Y(s.metadata.get("ProtocolVersion")??V(this.host.protocolVersion)),c=this;async function*u(){for(let f of c.connectionManager.getConnections())(await c.components.peerStore.get(f.remotePeer)).protocols.includes(c.protocol)&&(yield async()=>{let h,p=AbortSignal.timeout(c.timeout);try{h=await f.newStream(c.protocol,{signal:p,runOnLimitedConnection:c.runOnLimitedConnection}),await yr(h,{maxDataLength:c.maxMessageSize}).pb(vt).write({listenAddrs:e.map(m=>m.bytes),signedPeerRecord:n.marshal(),protocols:o,agentVersion:i,protocolVersion:a},{signal:p}),await h.close({signal:p})}catch(x){h?.log.newScope("identify-push")?.error("could not push identify update to peer",x),h?.abort(x)}})}await Bu(Vi(u(),{concurrency:this.concurrency}))}catch(e){this.log.error("error pushing updates to peers - %e",e)}}async handleProtocol(e,r){let n=e.log.newScope("identify-push");if(this.components.peerId.equals(r.remotePeer))throw new Error("received push from ourselves?");let o={signal:AbortSignal.timeout(this.timeout)},s=await mo(e,this.maxMessageSize,o,n);await ho(this.components.peerStore,this.components.events,n,r,po(s),this.maxListenAddresses),n.trace("handled push from %p",r.remotePeer)}};var bo=class extends br{constructor(e,r={}){super(e,{...r,protocol:`/${r.protocolPrefix??Te.protocolPrefix}/${"id"}/${Pu}`,log:e.logger.forComponent("libp2p:identify")}),(r.runOnConnectionOpen??Te.runOnConnectionOpen)&&e.events.addEventListener("connection:open",n=>{let o=n.detail;this.identify(o).catch(()=>{})})}[on]=["@libp2p/identify"];async _identify(e,r={}){let n,o;if(r.signal==null){let s=AbortSignal.timeout(this.timeout);r={...r,signal:s}}this.log("run identify on new connection %a",e.remoteAddr);try{n=await e.newStream(this.protocol,{...r,runOnLimitedConnection:this.runOnLimitedConnection}),o=n.log.newScope("identify");let s=await mo(n,this.maxMessageSize,r,o);return po(s)}catch(s){throw o?.error("identify failed - %e",s),n?.abort(s),s}}async identify(e,r={}){let n=await this._identify(e,r),{publicKey:o,protocols:s,observedAddr:i}=n;if(o==null)throw new Ke("Public key was missing from identify message");let a=ir(o),c=Zr(a);if(!e.remotePeer.equals(c))throw new Ke("Identified peer does not match the expected peer");if(this.components.peerId.equals(c))throw new Ke("Identified peer is our own peer id?");return this.maybeAddObservedAddress(i),this.log("completed for peer %p and protocols %o",c,s),ho(this.components.peerStore,this.components.events,this.log,e,n,this.maxListenAddresses)}maybeAddObservedAddress(e){let r=Hi(e);if(r==null||(this.log.trace("our observed address was %a",r),yu(r)))return;let n=r.getComponents();if((n[0].code===41||n[0].code===42&&n[1].code===41)&&!pu(r)){this.log.trace("our observed address was IPv6 but not a global unicast address");return}Eu.exactMatch(r)||(this.log.trace("storing the observed address"),this.components.addressManager.addObservedAddr(r))}async handleProtocol(e,r){let n=e.log.newScope("identify");n("responding to identify");let o=AbortSignal.timeout(this.timeout);let s=await this.components.peerStore.get(this.components.peerId,{signal:o}),i=this.components.addressManager.getAddresses().map(f=>f.decapsulateCode(421)),a=s.peerRecordEnvelope;if(i.length>0&&a==null){let f=new je({peerId:this.components.peerId,multiaddrs:i});a=(await tt.seal(f,this.components.privateKey,{signal:o})).marshal().subarray()}let c=r.remoteAddr.bytes;wu.matches(r.remoteAddr)||(c=void 0);let u=yr(e).pb(vt);n("send response"),await u.write({protocolVersion:this.host.protocolVersion,agentVersion:this.host.agentVersion,publicKey:Ge(this.components.privateKey.publicKey),listenAddrs:i.map(f=>f.bytes),signedPeerRecord:a,observedAddr:c,protocols:s.protocols},{signal:o}),n("close write"),await u.unwrap().unwrap().close({signal:o})}};function Fh(t={}){return e=>new bo(e,t)}function qh(t={}){return e=>new yo(e,t)}return Hu(Vh);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/curves/utils.js: