@libp2p/identify 4.1.7-a34745c01 → 4.1.8-08898d7df

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 vl=Object.create;var Rn=Object.defineProperty;var Sl=Object.getOwnPropertyDescriptor;var Al=Object.getOwnPropertyNames;var Il=Object.getPrototypeOf,Cl=Object.prototype.hasOwnProperty;var $o=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Z=(t,e)=>{for(var r in e)Rn(t,r,{get:e[r],enumerable:!0})},rc=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Al(e))!Cl.call(t,o)&&o!==r&&Rn(t,o,{get:()=>e[o],enumerable:!(n=Sl(e,o))||n.enumerable});return t};var _l=(t,e,r)=>(r=t!=null?vl(Il(t)):{},rc(e||!t||!t.__esModule?Rn(r,"default",{value:t,enumerable:!0}):r,t)),Tl=t=>rc(Rn({},"__esModule",{value:!0}),t);var Ra=$o(Rr=>{"use strict";Object.defineProperty(Rr,"__esModule",{value:!0});Rr.Netmask4Impl=void 0;Rr.ip2long=Pr;Rr.long2ip=Je;function Je(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 Xm=48,Qm=97,Jm=65;function e0(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)-Xm)>>>0;else if(r===16)if("a"<=t[o]&&t[o]<="f")e=e*r+(10+t.charCodeAt(o)-Qm)>>>0;else if("A"<=t[o]&&t[o]<="F")e=e*r+(10+t.charCodeAt(o)-Jm)>>>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 Pr(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]=e0(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 Pa=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=Pr(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=(Pr(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=Je(this.netLong),this.mask=Je(this.maskLong),this.hostmask=Je(~this.maskLong),this.first=this.bitmask<=30?Je(this.netLong+1):this.base,this.last=this.bitmask<=30?Je(this.netLong+this.size-2):Je(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?Je(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):(Pr(e)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(e=1){return new t(Je(this.netLong+this.size*e),this.mask)}forEach(e){let r=Pr(this.first),n=Pr(this.last),o=0;for(;r<=n;)e(Je(r),r,o),o++,r++}toString(){return this.base+"/"+this.bitmask}};Rr.Netmask4Impl=Pa});var Qu=$o(Fr=>{"use strict";Object.defineProperty(Fr,"__esModule",{value:!0});Fr.Netmask6Impl=void 0;Fr.ip6bigint=Na;Fr.bigint2ip6=Zt;var t0=Ra(),Fa=(1n<<128n)-1n;function Na(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,t0.ip2long)(n),s=t.substring(0,r+1)+"0:0";return Xu(s)&~0xffffffffn|BigInt(o)}return Xu(t)}function Xu(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 Zt(t){if(t<0n||t>Fa)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 ka=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=Fa>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=Na(e)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+e)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=Zt(this.netBigint),this.mask=Zt(this.maskBigint),this.hostmask=Zt(~this.maskBigint&Fa),this.first=this.base,this.last=Zt(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):(Na(e)&this.maskBigint)===this.netBigint}next(e=1){let r=1n<<BigInt(128-this.bitmask);return new t(Zt(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(Zt(r),Number(r),s),s++,r++}toString(){return this.base+"/"+this.bitmask}};Fr.Netmask6Impl=ka});var Ju=$o(Tt=>{"use strict";Object.defineProperty(Tt,"__esModule",{value:!0});Tt.long2ip=Tt.ip2long=Tt.Netmask=void 0;var Lo=Ra();Object.defineProperty(Tt,"ip2long",{enumerable:!0,get:function(){return Lo.ip2long}});Object.defineProperty(Tt,"long2ip",{enumerable:!0,get:function(){return Lo.long2ip}});var r0=Qu(),Ua=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 r0.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()}};Tt.Netmask=Ua});var N0={};Z(N0,{identify:()=>R0,identifyPush:()=>F0});var J=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Qt=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var Fn=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},Nn=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Oe=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var Bt=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var jo=Symbol.for("@libp2p/peer-id");var kn=Symbol.for("@libp2p/service-capabilities");var Xo={};Z(Xo,{base58btc:()=>ie,base58flickr:()=>Nl});var ly=new Uint8Array(0);function nc(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 et(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return Ot(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return Ot(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function oc(t){return new TextEncoder().encode(t)}function sc(t){return new TextDecoder().decode(t)}function Dl(t){return t?.buffer instanceof ArrayBuffer}function Ot(t){return Dl(t)?t:t.slice()}function Bl(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var s=t.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=t.length,c=t.charAt(0),f=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function l(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var b=0,m=0,g=0,v=d.length;g!==v&&d[g]===0;)g++,b++;for(var S=(v-g)*u+1>>>0,T=new Uint8Array(S);g!==v;){for(var _=d[g],R=0,O=S-1;(_!==0||R<m)&&O!==-1;O--,R++)_+=256*T[O]>>>0,T[O]=_%a>>>0,_=_/a>>>0;if(_!==0)throw new Error("Non-zero carry");m=R,g++}for(var C=S-m;C!==S&&T[C]===0;)C++;for(var N=c.repeat(b);C<S;++C)N+=t.charAt(T[C]);return N}function p(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var b=0;if(d[b]!==" "){for(var m=0,g=0;d[b]===c;)m++,b++;for(var v=(d.length-b)*f+1>>>0,S=new Uint8Array(v);d[b];){var T=r[d.charCodeAt(b)];if(T===255)return;for(var _=0,R=v-1;(T!==0||_<g)&&R!==-1;R--,_++)T+=a*S[R]>>>0,S[R]=T%256>>>0,T=T/256>>>0;if(T!==0)throw new Error("Non-zero carry");g=_,b++}if(d[b]!==" "){for(var O=v-g;O!==v&&S[O]===0;)O++;for(var C=new Uint8Array(m+(v-O)),N=m;O!==v;)C[N++]=S[O++];return C}}}function h(d){var b=p(d);if(b)return b;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:p,decode:h}}var Ol=Bl,Ll=Ol,ac=Ll;var Yo=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")}},Go=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 cc(this,e)}},Zo=class{decoders;constructor(e){this.decoders=e}or(e){return cc(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 cc(t,e){return new Zo({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Wo=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 Yo(e,r,n),this.decoder=new Go(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Jt({name:t,prefix:e,encode:r,decode:n}){return new Wo(t,e,r,n)}function pt({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=ac(r,t);return Jt({prefix:e,name:t,encode:n,decode:s=>et(o(s))})}function Pl(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 f=0;f<o;++f){let u=e[t[f]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|u,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 Rl(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 Fl(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function re({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=Fl(n);return Jt({prefix:e,name:t,encode(s){return Rl(s,n,r)},decode(s){return Pl(s,o,r,t)}})}var ie=pt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Nl=pt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Qo={};Z(Qo,{base32:()=>mt,base32hex:()=>Kl,base32hexpad:()=>ql,base32hexpadupper:()=>zl,base32hexupper:()=>Vl,base32pad:()=>Ul,base32padupper:()=>Ml,base32upper:()=>kl,base32z:()=>Hl});var mt=re({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),kl=re({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ul=re({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ml=re({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Kl=re({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Vl=re({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ql=re({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),zl=re({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Hl=re({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Jo={};Z(Jo,{base36:()=>Vr,base36upper:()=>$l});var Vr=pt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),$l=pt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var jl=lc,fc=128,Yl=127,Gl=~Yl,Zl=Math.pow(2,31);function lc(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Zl;)e[r++]=t&255|fc,t/=128;for(;t&Gl;)e[r++]=t&255|fc,t>>>=7;return e[r]=t|0,lc.bytes=r-n+1,e}var Wl=es,Xl=128,uc=127;function es(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw es.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&uc)<<o:(i&uc)*Math.pow(2,o),o+=7}while(i>=Xl);return es.bytes=s-n,r}var Ql=Math.pow(2,7),Jl=Math.pow(2,14),ed=Math.pow(2,21),td=Math.pow(2,28),rd=Math.pow(2,35),nd=Math.pow(2,42),od=Math.pow(2,49),sd=Math.pow(2,56),id=Math.pow(2,63),ad=function(t){return t<Ql?1:t<Jl?2:t<ed?3:t<td?4:t<rd?5:t<nd?6:t<od?7:t<sd?8:t<id?9:10},cd={encode:jl,decode:Wl,encodingLength:ad},fd=cd,qr=fd;function zr(t,e=0){return[qr.decode(t,e),qr.decode.bytes]}function er(t,e,r=0){return qr.encode(t,e,r),e}function tr(t){return qr.encodingLength(t)}function He(t,e){let r=e.byteLength,n=tr(t),o=n+tr(r),s=new Uint8Array(o+r);return er(t,s,0),er(r,s,n),s.set(e,o),new rr(t,r,e,s)}function Hr(t){let e=et(t),[r,n]=zr(e),[o,s]=zr(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new rr(r,o,i,e)}function dc(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&nc(t.bytes,r.bytes)}}var rr=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=Ot(n),this.bytes=Ot(o)}};function hc(t,e){let{bytes:r,version:n}=t;return n===0?ld(r,ts(t),e??ie.encoder):dd(r,ts(t),e??mt.encoder)}var pc=new WeakMap;function ts(t){let e=pc.get(t);if(e==null){let r=new Map;return pc.set(t,r),r}return e}var he=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=Ot(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!==$r)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==hd)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=He(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&&dc(e.multihash,n.multihash)}toString(e){return hc(this,e)}toJSON(){return{"/":hc(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??mc(n,o,s.bytes))}else if(r[pd]===!0){let{version:n,multihash:o,code:s}=r,i=Hr(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!==$r)throw new Error(`Version 0 CID must use dag-pb (code: ${$r}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=mc(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,$r,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=et(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 rr(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,p]=zr(e.subarray(r));return r+=p,l},o=n(),s=$r;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(),f=r+c,u=f-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(e,r){let[n,o]=ud(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 ts(s).set(n,e),s}};function ud(t,e){switch(t[0]){case"Q":{let r=e??ie;return[ie.prefix,r.decode(`${ie.prefix}${t}`)]}case ie.prefix:{let r=e??ie;return[ie.prefix,r.decode(t)]}case mt.prefix:{let r=e??mt;return[mt.prefix,r.decode(t)]}case Vr.prefix:{let r=e??Vr;return[Vr.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 ld(t,e,r){let{prefix:n}=r;if(n!==ie.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 dd(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 $r=112,hd=18;function mc(t,e,r){let n=tr(t),o=n+tr(e),s=new Uint8Array(o+r.byteLength);return er(t,s,0),er(e,s,n),s.set(r,o),s}var pd=Symbol.for("@ipld/js-cid/CID");var rs={};Z(rs,{identity:()=>Le});var yc=0,md="identity",bc=et;function yd(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 He(yc,bc(t))}var Le={code:yc,name:md,encode:bc,digest:yd};function ye(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 bd(t){return t.buffer instanceof ArrayBuffer}function _e(t){return bd(t)?t:t.slice()}async function gc(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 tt(t=0){return new Uint8Array(t)}function jr(t=0){return new Uint8Array(t)}function ns(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=jr(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}function xc(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 Ec=Symbol.for("@achingbrain/uint8arraylist");function wc(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 Mn(t){return!!t?.[Ec]}var ce=class t{bufs;length;[Ec]=!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(Mn(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(Mn(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=wc(this.bufs,e);return r.buf[r.index]}set(e,r){let n=wc(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(Mn(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 ns(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:ns(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 f=e>=a&&e<c,u=r>a&&r<=c;if(f&&u){if(e===a&&r===c){n.push(i);break}let l=e-a;n.push(i.subarray(l,l+(r-e)));break}if(f){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(u){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(!Mn(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,f=n.byteLength-1,u;for(let l=r;l<=c;l+=u){u=0;for(let p=f;p>=0;p--){let h=this.get(l+p);if(n[p]!==h){u=Math.max(1,p-a[h]);break}}if(u===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=jr(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=tt(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=tt(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=tt(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=jr(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=tt(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=tt(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=tt(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=tt(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=tt(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(!xc(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 os={};Z(os,{base10:()=>gd});var gd=pt({prefix:"9",name:"base10",alphabet:"0123456789"});var ss={};Z(ss,{base16:()=>xd,base16upper:()=>wd});var xd=re({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),wd=re({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var is={};Z(is,{base2:()=>Ed});var Ed=re({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var as={};Z(as,{base256emoji:()=>Cd});var vc=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}"),vd=vc.reduce((t,e,r)=>(t[r]=e,t),[]),Sd=vc.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Ad(t){return t.reduce((e,r)=>(e+=vd[r],e),"")}function Id(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Sd[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Cd=Jt({prefix:"\u{1F680}",name:"base256emoji",encode:Ad,decode:Id});var fs={};Z(fs,{base64:()=>_d,base64pad:()=>Td,base64url:()=>cs,base64urlpad:()=>Dd});var _d=re({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Td=re({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),cs=re({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Dd=re({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var us={};Z(us,{base8:()=>Bd});var Bd=re({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ls={};Z(ls,{identity:()=>Od});var Od=Jt({prefix:"\0",name:"identity",encode:t=>sc(t),decode:t=>oc(t)});var Qy=new TextEncoder,Jy=new TextDecoder;var ps={};Z(ps,{sha256:()=>Yr,sha512:()=>Fd});var Rd=20;function hs({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new ds(t,e,r,n,o)}var ds=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??Rd,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?Sc(n,this.code,r?.truncate):n.then(o=>Sc(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Sc(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 He(e,t)}function Ic(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Yr=hs({name:"sha2-256",code:18,encode:Ic("SHA-256")}),Fd=hs({name:"sha2-512",code:19,encode:Ic("SHA-512")});var Gr={...ls,...is,...us,...os,...ss,...Qo,...Jo,...Xo,...fs,...as},lb={...ps,...rs};function rt(t=0){return new Uint8Array(t)}function Pt(t=0){return new Uint8Array(t)}function _c(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Cc=_c("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),ms=_c("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=Pt(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Nd={utf8:Cc,"utf-8":Cc,hex:Gr.base16,latin1:ms,ascii:ms,binary:ms,...Gr},Kn=Nd;function K(t,e="utf8"){let r=Kn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function V(t,e="utf8"){let r=Kn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var kd=parseInt("11111",2),ys=parseInt("10000000",2),Ud=parseInt("01111111",2),Tc={0:Zr,1:Zr,2:Md,3:qd,4:zd,5:Vd,6:Kd,16:Zr,22:Zr,48:Zr};function nt(t,e={offset:0}){let r=t[e.offset]&kd;if(e.offset++,Tc[r]!=null)return Tc[r](t,e);throw new Error("No decoder for tag "+r)}function Wr(t,e){let r=0;if((t[e.offset]&ys)===ys){let n=t[e.offset]&Ud,o="0x";e.offset++;for(let s=0;s<n;s++,e.offset++)o+=t[e.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=t[e.offset],e.offset++;return r}function Zr(t,e){Wr(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=nt(t,e);if(n===null)break;r.push(n)}return r}function Md(t,e){let r=Wr(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 Kd(t,e){let r=Wr(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 f=t[e.offset];if(e.offset++,c.push(f&127),f<128){c.reverse();let u=0;for(let l=0;l<c.length;l++)u+=c[l]<<l*7;a+=`.${u}`,c=[]}}return a}function Vd(t,e){return e.offset++,null}function qd(t,e){let r=Wr(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 zd(t,e){let r=Wr(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function Hd(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new ce;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function bs(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=Hd(t.byteLength);return new ce(Uint8Array.from([e.byteLength|ys]),e)}function Ie(t){let e=new ce,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new ce(Uint8Array.from([2]),bs(e),e)}function Vn(t){let e=Uint8Array.from([0]),r=new ce(e,t);return new ce(Uint8Array.from([3]),bs(r),r)}function yt(t,e=48){let r=new ce;for(let n of t)r.append(n);return new ce(Uint8Array.from([e]),bs(r),r)}var $d=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),jd=Uint8Array.from([6,5,43,129,4,0,34]),Yd=Uint8Array.from([6,5,43,129,4,0,35]),Gd={ext:!0,kty:"EC",crv:"P-256"},Zd={ext:!0,kty:"EC",crv:"P-384"},Wd={ext:!0,kty:"EC",crv:"P-521"},gs=32,xs=48,ws=66;function Es(t){let e=nt(t);return Dc(e)}function Dc(t){let e=t[1][1][0],r=1,n,o;if(e.byteLength===gs*2+1)return n=V(e.subarray(r,r+gs),"base64url"),o=V(e.subarray(r+gs),"base64url"),new nr({...Gd,key_ops:["verify"],x:n,y:o});if(e.byteLength===xs*2+1)return n=V(e.subarray(r,r+xs),"base64url"),o=V(e.subarray(r+xs),"base64url"),new nr({...Zd,key_ops:["verify"],x:n,y:o});if(e.byteLength===ws*2+1)return n=V(e.subarray(r,r+ws),"base64url"),o=V(e.subarray(r+ws),"base64url"),new nr({...Wd,key_ops:["verify"],x:n,y:o});throw new J(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Bc(t){return yt([Ie(Uint8Array.from([1])),yt([Xd(t.crv)],160),yt([Vn(new ce(Uint8Array.from([4]),K(t.x??"","base64url"),K(t.y??"","base64url")))],161)]).subarray()}function Xd(t){if(t==="P-256")return $d;if(t==="P-384")return jd;if(t==="P-521")return Yd;throw new J(`Invalid curve ${t}`)}var nr=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=Bc(this.jwk)),this._raw}toMultihash(){return Le.digest($e(this))}toCID(){return he.createV1(114,this.toMultihash())}toString(){return ie.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ye(this.raw,e.raw)}async verify(e,r,n){return gc(this.jwk,r,e,n)}};function vs(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}function bt(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(`${r}expected number, got ${typeof t}`)}if(!Number.isSafeInteger(t)||t<0){let r=e&&`"${e}" `;throw new RangeError(`${r}expected integer >= 0, got ${t}`)}}function Te(t,e,r=""){let n=vs(t),o=t?.length,s=e!==void 0;if(!n||s&&o!==e){let i=r&&`"${r}" `,a=s?` of length ${e}`:"",c=n?`length=${o}`:`type=${typeof t}`,f=i+"expected Uint8Array"+a+", got "+c;throw n?new RangeError(f):new TypeError(f)}return t}function qn(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(bt(t.outputLen),bt(t.blockLen),t.outputLen<1)throw new Error('"outputLen" must be >= 1');if(t.blockLen<1)throw new Error('"blockLen" must be >= 1')}function or(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function zn(t,e){Te(t,void 0,"digestInto() output");let r=e.outputLen;if(t.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function st(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Hn(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Pe(t,e){return t<<32-e|t>>>e}var Lc=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Qd=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function $n(t){if(Te(t),Lc)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=Qd[t[r]];return e}var ot={_0:48,_9:57,A:65,F:70,a:97,f:102};function Oc(t){if(t>=ot._0&&t<=ot._9)return t-ot._0;if(t>=ot.A&&t<=ot.F)return t-(ot.A-10);if(t>=ot.a&&t<=ot.f)return t-(ot.a-10)}function Xr(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(Lc)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=Oc(t.charCodeAt(s)),a=Oc(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 Ss(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];Te(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 As(t,e={}){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 Pc(t=32){bt(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 Is=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function Rc(t,e,r){return t&e^~t&r}function Fc(t,e,r){return t&e^t&r^e&r}var Qr=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=Hn(this.buffer)}update(e){or(this),Te(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=Hn(e);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){or(this),zn(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,st(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=Hn(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)a.setUint32(4*l,u[l],s)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return e.destroyed=i,e.finished=s,e.length=o,e.pos=a,o%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},it=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var be=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var jn=BigInt(4294967295),Nc=BigInt(32);function Jd(t,e=!1){return e?{h:Number(t&jn),l:Number(t>>Nc&jn)}:{h:Number(t>>Nc&jn)|0,l:Number(t&jn)|0}}function kc(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}=Jd(t[s],e);[n[s],o[s]]=[i,a]}return[n,o]}var Cs=(t,e,r)=>t>>>r,_s=(t,e,r)=>t<<32-r|e>>>r,Rt=(t,e,r)=>t>>>r|e<<32-r,Ft=(t,e,r)=>t<<32-r|e>>>r,Jr=(t,e,r)=>t<<64-r|e>>>r-32,en=(t,e,r)=>t>>>r-32|e<<64-r;function je(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var Uc=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Mc=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,Kc=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),Vc=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,qc=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),zc=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0;var th=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]),gt=new Uint32Array(64),Ts=class extends Qr{constructor(e){super(64,e,8,!1)}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}process(e,r){for(let l=0;l<16;l++,r+=4)gt[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let p=gt[l-15],h=gt[l-2],d=Pe(p,7)^Pe(p,18)^p>>>3,b=Pe(h,17)^Pe(h,19)^h>>>10;gt[l]=b+gt[l-7]+d+gt[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:f,H:u}=this;for(let l=0;l<64;l++){let p=Pe(a,6)^Pe(a,11)^Pe(a,25),h=u+p+Rc(a,c,f)+th[l]+gt[l]|0,b=(Pe(n,2)^Pe(n,13)^Pe(n,22))+Fc(n,o,s)|0;u=f,f=c,c=a,a=i+h|0,i=s,s=o,o=n,n=h+b|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,f=f+this.G|0,u=u+this.H|0,this.set(n,o,s,i,a,c,f,u)}roundClean(){st(gt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),st(this.buffer)}},Ds=class extends Ts{A=it[0]|0;B=it[1]|0;C=it[2]|0;D=it[3]|0;E=it[4]|0;F=it[5]|0;G=it[6]|0;H=it[7]|0;constructor(){super(32)}};var Hc=kc(["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))),rh=Hc[0],nh=Hc[1],xt=new Uint32Array(80),wt=new Uint32Array(80),Bs=class extends Qr{constructor(e){super(128,e,16,!1)}get(){let{Ah:e,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:f,El:u,Fh:l,Fl:p,Gh:h,Gl:d,Hh:b,Hl:m}=this;return[e,r,n,o,s,i,a,c,f,u,l,p,h,d,b,m]}set(e,r,n,o,s,i,a,c,f,u,l,p,h,d,b,m){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=f|0,this.El=u|0,this.Fh=l|0,this.Fl=p|0,this.Gh=h|0,this.Gl=d|0,this.Hh=b|0,this.Hl=m|0}process(e,r){for(let S=0;S<16;S++,r+=4)xt[S]=e.getUint32(r),wt[S]=e.getUint32(r+=4);for(let S=16;S<80;S++){let T=xt[S-15]|0,_=wt[S-15]|0,R=Rt(T,_,1)^Rt(T,_,8)^Cs(T,_,7),O=Ft(T,_,1)^Ft(T,_,8)^_s(T,_,7),C=xt[S-2]|0,N=wt[S-2]|0,G=Rt(C,N,19)^Jr(C,N,61)^Cs(C,N,6),k=Ft(C,N,19)^en(C,N,61)^_s(C,N,6),y=Kc(O,k,wt[S-7],wt[S-16]),x=Vc(y,R,G,xt[S-7],xt[S-16]);xt[S]=x|0,wt[S]=y|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:f,Dl:u,Eh:l,El:p,Fh:h,Fl:d,Gh:b,Gl:m,Hh:g,Hl:v}=this;for(let S=0;S<80;S++){let T=Rt(l,p,14)^Rt(l,p,18)^Jr(l,p,41),_=Ft(l,p,14)^Ft(l,p,18)^en(l,p,41),R=l&h^~l&b,O=p&d^~p&m,C=qc(v,_,O,nh[S],wt[S]),N=zc(C,g,T,R,rh[S],xt[S]),G=C|0,k=Rt(n,o,28)^Jr(n,o,34)^Jr(n,o,39),y=Ft(n,o,28)^en(n,o,34)^en(n,o,39),x=n&s^n&a^s&a,A=o&i^o&c^i&c;g=b|0,v=m|0,b=h|0,m=d|0,h=l|0,d=p|0,{h:l,l:p}=je(f|0,u|0,N|0,G|0),f=a|0,u=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let E=Uc(G,y,A);n=Mc(E,N,k,x),o=E|0}({h:n,l:o}=je(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=je(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=je(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=je(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:p}=je(this.Eh|0,this.El|0,l|0,p|0),{h,l:d}=je(this.Fh|0,this.Fl|0,h|0,d|0),{h:b,l:m}=je(this.Gh|0,this.Gl|0,b|0,m|0),{h:g,l:v}=je(this.Hh|0,this.Hl|0,g|0,v|0),this.set(n,o,s,i,a,c,f,u,l,p,h,d,b,m,g,v)}roundClean(){st(xt,wt)}destroy(){this.destroyed=!0,st(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Os=class extends Bs{Ah=be[0]|0;Al=be[1]|0;Bh=be[2]|0;Bl=be[3]|0;Ch=be[4]|0;Cl=be[5]|0;Dh=be[6]|0;Dl=be[7]|0;Eh=be[8]|0;El=be[9]|0;Fh=be[10]|0;Fl=be[11]|0;Gh=be[12]|0;Gl=be[13]|0;Hh=be[14]|0;Hl=be[15]|0;constructor(){super(64)}};var sr=As(()=>new Ds,Is(1));var Yn=As(()=>new Os,Is(3));var z=(t,e,r)=>Te(t,e,r),Ps=bt,ir=$n,ue=(...t)=>Ss(...t),ar=t=>Xr(t),Nt=vs,tn=t=>Pc(t),Zn=BigInt(0),Ls=BigInt(1);function Re(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}" `;throw new TypeError(r+"expected boolean, got type="+typeof t)}return t}function Wn(t){if(typeof t=="bigint"){if(!Gn(t))throw new RangeError("positive bigint expected, got "+t)}else Ps(t);return t}function Fe(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 rn(t){let e=Wn(t).toString(16);return e.length&1?"0"+e:e}function $c(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?Zn:BigInt("0x"+t)}function kt(t){return $c($n(t))}function Ye(t){return $c($n(nn(Te(t)).reverse()))}function Xn(t,e){if(bt(e),e===0)throw new RangeError("zero length");t=Wn(t);let r=t.toString(16);if(r.length>e*2)throw new RangeError("number too large");return Xr(r.padStart(e*2,"0"))}function Rs(t,e){return Xn(t,e).reverse()}function jc(t,e){if(t=z(t),e=z(e),t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function nn(t){return Uint8Array.from(z(t))}function Qn(t){if(typeof t!="string")throw new TypeError("ascii string expected, got "+typeof t);return Uint8Array.from(t,(e,r)=>{let n=e.charCodeAt(0);if(e.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${t[r]}" with code ${n} at position ${r}`);return n})}var Gn=t=>typeof t=="bigint"&&Zn<=t;function oh(t,e,r){return Gn(t)&&Gn(e)&&Gn(r)&&e<=t&&t<r}function cr(t,e,r,n){if(!oh(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function fr(t){if(t<Zn)throw new Error("expected non-negative bigint, got "+t);let e;for(e=0;t>Zn;t>>=Ls,e+=1);return e}var on=t=>(Ls<<BigInt(t))-Ls;function Yc(t,e,r){if(bt(t,"hashLen"),bt(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=m=>new Uint8Array(m),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(t),f=n(t),u=0,l=()=>{c.fill(1),f.fill(0),u=0},p=(...m)=>r(f,ue(c,...m)),h=(m=o)=>{f=p(s,m),c=p(),m.length!==0&&(f=p(i,m),c=p())},d=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let m=0,g=[];for(;m<e;){c=p();let v=c.slice();g.push(v),m+=c.length}return ue(...g)};return(m,g)=>{l(),h(m);let v;for(;(v=g(d()))===void 0;)h();return l(),v}}function Ne(t,e={},r={}){if(Object.prototype.toString.call(t)!=="[object Object]")throw new TypeError("expected valid options object");function n(s,i,a){if(!a&&i!=="function"&&!Object.hasOwn(t,s))throw new TypeError(`param "${s}" is invalid: expected own property`);let c=t[s];if(a&&c===void 0)return;let f=typeof c;if(f!==i||c===null)throw new TypeError(`param "${s}" is invalid: expected ${i}, got ${f}`)}let o=(s,i)=>Object.entries(s).forEach(([a,c])=>n(a,c,i));o(e,!1),o(r,!0)}var Fs=()=>{throw new Error("not implemented")};var ge=BigInt(0),ne=BigInt(1),Ut=BigInt(2),Xc=BigInt(3),Qc=BigInt(4),Jc=BigInt(5),sh=BigInt(7),ef=BigInt(8),ih=BigInt(9),tf=BigInt(16);function ae(t,e){if(e<=ge)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=ge?r:e+r}function Q(t,e,r){if(e<ge)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >ge;)n*=n,n%=r;return n}function Gc(t,e){if(t===ge)throw new Error("invert: expected non-zero number");if(e<=ge)throw new Error("invert: expected positive modulus, got "+e);let r=ae(t,e),n=e,o=ge,s=ne,i=ne,a=ge;for(;r!==ge;){let f=n/r,u=n-r*f,l=o-i*f,p=s-a*f;n=r,r=u,o=i,s=a,i=l,a=p}if(n!==ne)throw new Error("invert: does not exist");return ae(o,e)}function Ns(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function rf(t,e){let r=t,n=(r.ORDER+ne)/Qc,o=r.pow(e,n);return Ns(r,o,e),o}function ah(t,e){let r=t,n=(r.ORDER-Jc)/ef,o=r.mul(e,Ut),s=r.pow(o,n),i=r.mul(e,s),a=r.mul(r.mul(i,Ut),s),c=r.mul(i,r.sub(a,r.ONE));return Ns(r,c,e),c}function ch(t){let e=ur(t),r=nf(t),n=r(e,e.neg(e.ONE)),o=r(e,n),s=r(e,e.neg(n)),i=(t+sh)/tf;return((a,c)=>{let f=a,u=f.pow(c,i),l=f.mul(u,n),p=f.mul(u,o),h=f.mul(u,s),d=f.eql(f.sqr(l),c),b=f.eql(f.sqr(p),c);u=f.cmov(u,l,d),l=f.cmov(h,p,b);let m=f.eql(f.sqr(l),c),g=f.cmov(u,l,m);return Ns(f,g,c),g})}function nf(t){if(t<Xc)throw new Error("sqrt is not defined for small field");let e=t-ne,r=0;for(;e%Ut===ge;)e/=Ut,r++;let n=Ut,o=ur(t);for(;Zc(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return rf;let s=o.pow(n,e),i=(e+ne)/Ut;return function(c,f){let u=c;if(u.is0(f))return f;if(Zc(u,f)!==1)throw new Error("Cannot find square root");let l=r,p=u.mul(u.ONE,s),h=u.pow(f,e),d=u.pow(f,i);for(;!u.eql(h,u.ONE);){if(u.is0(h))return u.ZERO;let b=1,m=u.sqr(h);for(;!u.eql(m,u.ONE);)if(b++,m=u.sqr(m),b===l)throw new Error("Cannot find square root");let g=ne<<BigInt(l-b-1),v=u.pow(p,g);l=b,p=u.sqr(v),h=u.mul(h,p),d=u.mul(d,v)}return d}}function fh(t){return t%Qc===Xc?rf:t%ef===Jc?ah:t%tf===ih?ch(t):nf(t)}var at=(t,e)=>(ae(t,e)&ne)===ne,uh=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ks(t){let e={ORDER:"bigint",BYTES:"number",BITS:"number"},r=uh.reduce((n,o)=>(n[o]="function",n),e);if(Ne(t,r),Fe(t.BYTES,"BYTES"),Fe(t.BITS,"BITS"),t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=ne)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function lh(t,e,r){let n=t;if(r<ge)throw new Error("invalid exponent, negatives unsupported");if(r===ge)return n.ONE;if(r===ne)return e;let o=n.ONE,s=e;for(;r>ge;)r&ne&&(o=n.mul(o,s)),s=n.sqr(s),r>>=ne;return o}function sn(t,e,r=!1){let n=t,o=new Array(e.length).fill(r?n.ZERO:void 0),s=e.reduce((a,c,f)=>n.is0(c)?a:(o[f]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return e.reduceRight((a,c,f)=>n.is0(c)?a:(o[f]=n.mul(a,o[f]),n.mul(a,c)),i),o}function Zc(t,e){let r=t,n=(r.ORDER-ne)/Ut,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 dh(t,e){if(e!==void 0&&Ps(e),t<=ge)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=fr(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected bit length (${r}) >= n.length (${e})`);let n=e!==void 0?e:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var Wc=new WeakMap,Jn=class{ORDER;BITS;BYTES;isLE;ZERO=ge;ONE=ne;_lengths;_mod;constructor(e,r={}){if(e<=ne)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}=dh(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 ae(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return ge<=e&&e<this.ORDER}is0(e){return e===ge}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&ne)===ne}neg(e){return ae(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return ae(e*e,this.ORDER)}add(e,r){return ae(e+r,this.ORDER)}sub(e,r){return ae(e-r,this.ORDER)}mul(e,r){return ae(e*r,this.ORDER)}pow(e,r){return lh(this,e,r)}div(e,r){return ae(e*Gc(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 Gc(e,this.ORDER)}sqrt(e){let r=Wc.get(this);return r||Wc.set(this,r=fh(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?Rs(e,this.BYTES):Xn(e,this.BYTES)}fromBytes(e,r=!1){z(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 f=new Uint8Array(o);f.set(e,s?0:f.length-e.length),e=f}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let c=s?Ye(e):kt(e);if(a&&(c=ae(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)}cmov(e,r,n){return Re(n,"condition"),n?r:e}};Object.freeze(Jn.prototype);function ur(t,e={}){return new Jn(t,e)}function of(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=ne)throw new Error("field order must be greater than 1");let e=fr(t-ne);return Math.ceil(e/8)}function Us(t){let e=of(t);return e+Math.ceil(e/2)}function Ms(t,e,r=!1){z(t);let n=t.length,o=of(e),s=Math.max(Us(e),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Ye(t):kt(t),a=ae(i,e-ne)+ne;return r?Rs(a,o):Xn(a,o)}var lr=BigInt(0),Mt=BigInt(1);function an(t,e){let r=e.negate();return t?r:e}function Kt(t,e){let r=sn(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function ff(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function Ks(t,e){ff(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),o=2**t,s=on(t),i=BigInt(t);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function sf(t,e,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(t&o),c=t>>i;a>n&&(a-=s,c+=Mt);let f=e*n,u=f+Math.abs(a)-1,l=a===0,p=a<0,h=e%2!==0;return{nextN:c,offset:u,isZero:l,isNeg:p,isNegF:h,offsetF:f}}var Vs=new WeakMap,uf=new WeakMap;function qs(t){return uf.get(t)||1}function af(t){if(t!==lr)throw new Error("invalid wNAF")}var dr=class{BASE;ZERO;Fn;bits;constructor(e,r){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=r}_unsafeLadder(e,r,n=this.ZERO){let o=e;for(;r>lr;)r&Mt&&(n=n.add(o)),o=o.double(),r>>=Mt;return n}precomputeWindow(e,r){let{windows:n,windowSize:o}=Ks(r,this.bits),s=[],i=e,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let f=1;f<o;f++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=Ks(e,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:f,isZero:u,isNeg:l,isNegF:p,offsetF:h}=sf(n,a,i);n=c,u?s=s.add(an(p,r[h])):o=o.add(an(l,r[f]))}return af(n),{p:o,f:s}}wNAFUnsafe(e,r,n,o=this.ZERO){let s=Ks(e,this.bits);for(let i=0;i<s.windows&&n!==lr;i++){let{nextN:a,offset:c,isZero:f,isNeg:u}=sf(n,i,s);if(n=a,!f){let l=r[c];o=o.add(u?l.negate():l)}}return af(n),o}getPrecomputes(e,r,n){let o=Vs.get(r);return o||(o=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(o=n(o)),Vs.set(r,o))),o}cached(e,r,n){let o=qs(e);return this.wNAF(o,this.getPrecomputes(o,e,n),r)}unsafe(e,r,n,o){let s=qs(e);return s===1?this._unsafeLadder(e,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,e,n),r,o)}createCache(e,r){ff(r,this.bits),uf.set(e,r),Vs.delete(e)}hasCache(e){return qs(e)!==1}};function lf(t,e,r,n){let o=e,s=t.ZERO,i=t.ZERO;for(;r>lr||n>lr;)r&Mt&&(s=s.add(o)),n&Mt&&(i=i.add(o)),o=o.double(),r>>=Mt,n>>=Mt;return{p1:s,p2:i}}function cf(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return ks(e),e}else return ur(t,{isLE:r})}function eo(t,e,r={},n){if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(let c of["p","n","h"]){let f=e[c];if(!(typeof f=="bigint"&&f>lr))throw new Error(`CURVE.${c} must be positive bigint`)}let o=cf(e.p,r.Fp,n),s=cf(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 to(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}var Et=BigInt(0),pe=BigInt(1),zs=BigInt(2),hh=BigInt(8);function ph(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 df(t,e={}){let r=e,n=eo("edwards",t,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;Ne(r,{},{uvRatio:"function"});let c=zs<<BigInt(s.BYTES*8)-pe,f=b=>o.create(b),u=r.uvRatio===void 0?(b,m)=>{try{return{isValid:!0,value:o.sqrt(o.div(b,m))}}catch{return{isValid:!1,value:Et}}}:r.uvRatio;if(!ph(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function l(b,m,g=!1){let v=g?pe:Et;return cr("coordinate "+b,m,v,c),m}function p(b){if(!(b instanceof h))throw new Error("EdwardsPoint expected")}class h{static BASE=new h(i.Gx,i.Gy,pe,f(i.Gx*i.Gy));static ZERO=new h(Et,pe,pe,Et);static Fp=o;static Fn=s;X;Y;Z;T;constructor(m,g,v,S){this.X=l("x",m),this.Y=l("y",g),this.Z=l("z",v,!0),this.T=l("t",S),Object.freeze(this)}static CURVE(){return i}static fromAffine(m){if(m instanceof h)throw new Error("extended point not allowed");let{x:g,y:v}=m||{};return l("x",g),l("y",v),new h(g,v,pe,f(g*v))}static fromBytes(m,g=!1){let v=o.BYTES,{a:S,d:T}=i;m=nn(z(m,v,"point")),Re(g,"zip215");let _=nn(m),R=m[v-1];_[v-1]=R&-129;let O=Ye(_),C=g?c:o.ORDER;cr("point.y",O,Et,C);let N=f(O*O),G=f(N-pe),k=f(T*N-S),{isValid:y,value:x}=u(G,k);if(!y)throw new Error("bad point: invalid y coordinate");let A=(x&pe)===pe,E=(R&128)!==0;if(!g&&x===Et&&E)throw new Error("bad point: x=0 and x_0=1");return E!==A&&(x=f(-x)),h.fromAffine({x,y:O})}static fromHex(m,g=!1){return h.fromBytes(ar(m),g)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,g=!0){return d.createCache(this,m),g||this.multiply(zs),this}assertValidity(){let m=this,{a:g,d:v}=i;if(m.is0())throw new Error("bad point: ZERO");let{X:S,Y:T,Z:_,T:R}=m,O=f(S*S),C=f(T*T),N=f(_*_),G=f(N*N),k=f(O*g),y=f(N*f(k+C)),x=f(G+f(v*f(O*C)));if(y!==x)throw new Error("bad point: equation left != right (1)");let A=f(S*T),E=f(_*R);if(A!==E)throw new Error("bad point: equation left != right (2)")}equals(m){p(m);let{X:g,Y:v,Z:S}=this,{X:T,Y:_,Z:R}=m,O=f(g*R),C=f(T*S),N=f(v*R),G=f(_*S);return O===C&&N===G}is0(){return this.equals(h.ZERO)}negate(){return new h(f(-this.X),this.Y,this.Z,f(-this.T))}double(){let{a:m}=i,{X:g,Y:v,Z:S}=this,T=f(g*g),_=f(v*v),R=f(zs*f(S*S)),O=f(m*T),C=g+v,N=f(f(C*C)-T-_),G=O+_,k=G-R,y=O-_,x=f(N*k),A=f(G*y),E=f(N*y),w=f(k*G);return new h(x,A,w,E)}add(m){p(m);let{a:g,d:v}=i,{X:S,Y:T,Z:_,T:R}=this,{X:O,Y:C,Z:N,T:G}=m,k=f(S*O),y=f(T*C),x=f(R*v*G),A=f(_*N),E=f((S+T)*(O+C)-k-y),w=A-x,I=A+x,B=f(y-g*k),D=f(E*w),L=f(I*B),F=f(E*B),q=f(w*I);return new h(D,L,q,F)}subtract(m){return p(m),this.add(m.negate())}multiply(m){if(!s.isValidNot0(m))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:g,f:v}=d.cached(this,m,S=>Kt(h,S));return Kt(h,[g,v])[0]}multiplyUnsafe(m){if(!s.isValid(m))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return m===Et?h.ZERO:this.is0()||m===pe?this:d.unsafe(this,m,g=>Kt(h,g))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return d.unsafe(this,i.n).is0()}toAffine(m){let g=this,v=m,{X:S,Y:T,Z:_}=g,R=g.is0();v==null&&(v=R?hh:o.inv(_));let O=f(S*v),C=f(T*v),N=o.mul(_,v);if(R)return{x:Et,y:pe};if(N!==pe)throw new Error("invZ was invalid");return{x:O,y:C}}clearCofactor(){return a===pe?this:this.multiplyUnsafe(a)}toBytes(){let{x:m,y:g}=this.toAffine(),v=o.toBytes(g);return v[v.length-1]|=m&pe?128:0,v}toHex(){return ir(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let d=new dr(h,s.BITS);return s.BITS>=8&&h.BASE.precompute(8),Object.freeze(h.prototype),Object.freeze(h),h}var ro=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(e){this.ep=e}static fromBytes(e){Fs()}static fromHex(e){Fs()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(e){return this.ep.toAffine(e)}toHex(){return ir(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(e){return this.assertSame(e),this.init(this.ep.add(e.ep))}subtract(e){return this.assertSame(e),this.init(this.ep.subtract(e.ep))}multiply(e){return this.init(this.ep.multiply(e))}multiplyUnsafe(e){return this.init(this.ep.multiplyUnsafe(e))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(e,r){return this.ep.precompute(e,r),this}};function hf(t,e,r={}){if(typeof e!="function")throw new Error('"hash" function param is required');let n=e,o=r;Ne(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=t,f=n.outputLen,u=2*a.BYTES;if(f!==void 0&&(Fe(f,"hash.outputLen"),f!==u))throw new Error(`hash.outputLen must be ${u}, got ${f}`);let l=o.randomBytes===void 0?tn:o.randomBytes,p=o.adjustScalarBytes===void 0?y=>y:o.adjustScalarBytes,h=o.domain===void 0?(y,x,A)=>{if(Re(A,"phflag"),x.length||A)throw new Error("Contexts/pre-hash are not supported");return y}:o.domain;function d(y){return c.create(Ye(y))}function b(y){let x=O.secretKey;z(y,O.secretKey,"secretKey");let A=z(n(y),2*x,"hashedSecretKey"),E=p(A.slice(0,x)),w=A.slice(x,2*x),I=d(E);return{head:E,prefix:w,scalar:I}}function m(y){let{head:x,prefix:A,scalar:E}=b(y),w=i.multiply(E),I=w.toBytes();return{head:x,prefix:A,scalar:E,point:w,pointBytes:I}}function g(y){return m(y).pointBytes}function v(y=Uint8Array.of(),...x){let A=ue(...x);return d(n(h(A,z(y,void 0,"context"),!!s)))}function S(y,x,A={}){y=z(y,void 0,"message"),s&&(y=s(y));let{prefix:E,scalar:w,pointBytes:I}=m(x),B=v(A.context,E,y),D=i.multiply(B).toBytes(),L=v(A.context,D,I,y),F=c.create(B+L*w);if(!c.isValid(F))throw new Error("sign failed: invalid s");let q=ue(D,c.toBytes(F));return z(q,O.signature,"result")}let T={zip215:o.zip215};function _(y,x,A,E=T){let{context:w}=E,I=E.zip215===void 0?!!T.zip215:E.zip215,B=O.signature;y=z(y,B,"signature"),x=z(x,void 0,"message"),A=z(A,O.publicKey,"publicKey"),I!==void 0&&Re(I,"zip215"),s&&(x=s(x));let D=B/2,L=y.subarray(0,D),F=Ye(y.subarray(D,B)),q,j,U;try{q=t.fromBytes(A,I),j=t.fromBytes(L,I),U=i.multiplyUnsafe(F)}catch{return!1}if(!I&&q.isSmallOrder())return!1;let fe=v(w,L,A,x);return j.add(q.multiplyUnsafe(fe)).subtract(U).clearCofactor().is0()}let R=a.BYTES,O={secretKey:R,publicKey:R,signature:2*R,seed:R};function C(y){return y=y===void 0?l(O.seed):y,z(y,O.seed,"seed")}function N(y){return Nt(y)&&y.length===O.secretKey}function G(y,x){try{return!!t.fromBytes(y,x===void 0?T.zip215:x)}catch{return!1}}let k={getExtendedPublicKey:m,randomSecretKey:C,isValidSecretKey:N,isValidPublicKey:G,toMontgomery(y){let{y:x}=t.fromBytes(y),A=O.publicKey,E=A===32;if(!E&&A!==57)throw new Error("only defined for 25519 and 448");let w=E?a.div(pe+x,pe-x):a.div(x-pe,x+pe);return a.toBytes(w)},toMontgomerySecret(y){let x=O.secretKey;z(y,x);let A=n(y.subarray(0,x));return p(A).subarray(0,x)}};return Object.freeze(O),Object.freeze(k),Object.freeze({keygen:to(C,g),getPublicKey:g,sign:S,verify:_,utils:k,Point:t,lengths:O})}function cn(t,e){if(Fe(t),Fe(e),e<0||e>4)throw new Error("invalid I2OSP length: "+e);if(t<0||t>2**(8*e)-1)throw new Error("invalid I2OSP input: "+t);let r=Array.from({length:e}).fill(0);for(let n=e-1;n>=0;n--)r[n]=t&255,t>>>=8;return new Uint8Array(r)}function mh(t,e){let r=new Uint8Array(t.length);for(let n=0;n<t.length;n++)r[n]=t[n]^e[n];return r}function yh(t){if(!Nt(t)&&typeof t!="string")throw new Error("DST must be Uint8Array or ascii string");let e=typeof t=="string"?Qn(t):t;if(e.length===0)throw new Error("DST must be non-empty");return e}function Hs(t,e,r,n){z(t),Fe(r),e=yh(e),e.length>255&&(e=n(ue(Qn("H2C-OVERSIZE-DST-"),e)));let{outputLen:o,blockLen:s}=n,i=Math.ceil(r/o);if(r>65535||i>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=ue(e,cn(e.length,1)),c=new Uint8Array(s),f=cn(r,2),u=new Array(i),l=n(ue(c,t,f,cn(0,1),a));u[0]=n(ue(l,cn(1,1),a));for(let h=1;h<i;h++){let d=[mh(l,u[h-1]),cn(h+1,1),a];u[h]=n(ue(...d))}return ue(...u).slice(0,r)}var pf="HashToScalar-";var bh=BigInt(0),ct=BigInt(1),mf=BigInt(2);var gh=BigInt(5),xh=BigInt(8),hr=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Gs={p:hr,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:xh,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function wh(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=hr,a=t*t%s*t%s,c=Q(a,mf,s)*a%s,f=Q(c,ct,s)*t%s,u=Q(f,gh,s)*f%s,l=Q(u,e,s)*u%s,p=Q(l,r,s)*l%s,h=Q(p,n,s)*p%s,d=Q(h,o,s)*h%s,b=Q(d,o,s)*h%s,m=Q(b,e,s)*u%s;return{pow_p_5_8:Q(m,mf,s)*t%s,b2:a}}function Eh(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var $s=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Zs(t,e){let r=hr,n=ae(e*e*e,r),o=ae(n*n*e,r),s=wh(t*o).pow_p_5_8,i=ae(t*n*s,r),a=ae(e*i*i,r),c=i,f=ae(i*$s,r),u=a===t,l=a===ae(-t,r),p=a===ae(-t*$s,r);return u&&(i=c),(l||p)&&(i=f),at(i,r)&&(i=ae(-i,r)),{isValid:u||l,value:i}}var St=df(Gs,{uvRatio:Zs}),vt=St.Fp,gf=St.Fn;function vh(t){return hf(St,Yn,Object.assign({adjustScalarBytes:Eh,zip215:!0},t))}var xf=vh({});var js=$s,Sh=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Ah=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Ih=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Ch=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),yf=t=>Zs(ct,t),_h=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Ys=t=>vt.create(Ye(t)&_h);function bf(t){let{d:e}=Gs,r=hr,n=g=>vt.create(g),o=n(js*t*t),s=n((o+ct)*Ih),i=BigInt(-1),a=n((i-e*o)*n(o+e)),{isValid:c,value:f}=Zs(s,a),u=n(f*t);at(u,r)||(u=n(-u)),c||(f=u),c||(i=o);let l=n(i*(o-ct)*Ch-a),p=f*f,h=n((f+f)*a),d=n(l*Sh),b=n(ct-p),m=n(ct+p);return new St(n(h*m),n(b*d),n(d*m),n(h*b))}var At=class t extends ro{static BASE=new t(St.BASE);static ZERO=new t(St.ZERO);static Fp=vt;static Fn=gf;constructor(e){super(e)}static fromAffine(e){return new t(St.fromAffine(e))}assertSame(e){if(!(e instanceof t))throw new Error("RistrettoPoint expected")}init(e){return new t(e)}static fromBytes(e){Te(e,32);let{a:r,d:n}=Gs,o=hr,s=T=>vt.create(T),i=Ys(e);if(!jc(vt.toBytes(i),e)||at(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(ct+r*a),f=s(ct-r*a),u=s(c*c),l=s(f*f),p=s(r*n*u-l),{isValid:h,value:d}=yf(s(p*l)),b=s(d*f),m=s(d*b*p),g=s((i+i)*b);at(g,o)&&(g=s(-g));let v=s(c*m),S=s(g*v);if(!h||at(S,o)||v===bh)throw new Error("invalid ristretto255 encoding 2");return new t(new St(g,v,ct,S))}static fromHex(e){return t.fromBytes(Xr(e))}toBytes(){let{X:e,Y:r,Z:n,T:o}=this.ep,s=hr,i=m=>vt.create(m),a=i(i(n+r)*i(n-r)),c=i(e*r),f=i(c*c),{value:u}=yf(i(a*f)),l=i(u*a),p=i(u*c),h=i(l*p*o),d;if(at(o*h,s)){let m=i(r*js),g=i(e*js);e=m,r=g,d=i(l*Ah)}else d=p;at(e*h,s)&&(r=i(-r));let b=i((n-r)*d);return at(b,s)&&(b=i(-b)),vt.toBytes(b)}equals(e){this.assertSame(e);let{X:r,Y:n}=this.ep,{X:o,Y:s}=e.ep,i=f=>vt.create(f),a=i(r*s)===i(n*o),c=i(n*s)===i(r*o);return a||c}is0(){return this.equals(t.ZERO)}};Object.freeze(At.BASE);Object.freeze(At.ZERO);Object.freeze(At.prototype);Object.freeze(At);var Th=Object.freeze({Point:At,hashToCurve(t,e){let r=e?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":e.DST,n=Hs(t,r,64,Yn);return Th.deriveToCurve(n)},hashToScalar(t,e={DST:pf}){let r=Hs(t,e.DST,64,Yn);return gf.create(Ye(r))},deriveToCurve(t){Te(t,64);let e=Ys(t.subarray(0,32)),r=bf(e),n=Ys(t.subarray(32,64)),o=bf(n);return new At(r.add(o))}});var fn=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},no=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var Be={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new no("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 oo=32;var Ws,Dh=(async()=>{try{return await Be.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Bh(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await Be.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await Be.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 Oh(t,e,r){return xf.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function wf(t,e,r){return Ws==null&&(Ws=await Dh),Ws?Bh(t,e,r):Oh(t,e,r)}function Lh(t){return t?.buffer instanceof ArrayBuffer}function Xs(t){if(Lh(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function Vt(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=Pt(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return Xs(r)}function so(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var io=class{type="Ed25519";raw;constructor(e){this.raw=Qs(e,oo)}toMultihash(){return Le.digest($e(this))}toCID(){return he.createV1(114,this.toMultihash())}toString(){return ie.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ye(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let o=wf(this.raw,r,e);return so(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Js(t){return t=Qs(t,oo),new io(t)}function Qs(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new J(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}function vf(t=0){return new Uint8Array(t)}var Rh=Math.pow(2,7),Fh=Math.pow(2,14),Nh=Math.pow(2,21),ei=Math.pow(2,28),ti=Math.pow(2,35),ri=Math.pow(2,42),ni=Math.pow(2,49),Y=128,we=127;function ft(t){if(t<Rh)return 1;if(t<Fh)return 2;if(t<Nh)return 3;if(t<ei)return 4;if(t<ti)return 5;if(t<ri)return 6;if(t<ni)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function oi(t,e,r=0){switch(ft(t)){case 8:e[r++]=t&255|Y,t/=128;case 7:e[r++]=t&255|Y,t/=128;case 6:e[r++]=t&255|Y,t/=128;case 5:e[r++]=t&255|Y,t/=128;case 4:e[r++]=t&255|Y,t>>>=7;case 3:e[r++]=t&255|Y,t>>>=7;case 2:e[r++]=t&255|Y,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function kh(t,e,r=0){switch(ft(t)){case 8:e.set(r++,t&255|Y),t/=128;case 7:e.set(r++,t&255|Y),t/=128;case 6:e.set(r++,t&255|Y),t/=128;case 5:e.set(r++,t&255|Y),t/=128;case 4:e.set(r++,t&255|Y),t>>>=7;case 3:e.set(r++,t&255|Y),t>>>=7;case 2:e.set(r++,t&255|Y),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function si(t,e){let r=t[e],n=0;if(n+=r&we,r<Y||(r=t[e+1],n+=(r&we)<<7,r<Y)||(r=t[e+2],n+=(r&we)<<14,r<Y)||(r=t[e+3],n+=(r&we)<<21,r<Y)||(r=t[e+4],n+=(r&we)*ei,r<Y)||(r=t[e+5],n+=(r&we)*ti,r<Y)||(r=t[e+6],n+=(r&we)*ri,r<Y)||(r=t[e+7],n+=(r&we)*ni,r<Y))return n;throw new RangeError("Could not decode varint")}function Uh(t,e){let r=t.get(e),n=0;if(n+=r&we,r<Y||(r=t.get(e+1),n+=(r&we)<<7,r<Y)||(r=t.get(e+2),n+=(r&we)<<14,r<Y)||(r=t.get(e+3),n+=(r&we)<<21,r<Y)||(r=t.get(e+4),n+=(r&we)*ei,r<Y)||(r=t.get(e+5),n+=(r&we)*ti,r<Y)||(r=t.get(e+6),n+=(r&we)*ri,r<Y)||(r=t.get(e+7),n+=(r&we)*ni,r<Y))return n;throw new RangeError("Could not decode varint")}function pr(t,e,r=0){return e==null&&(e=vf(ft(t))),e instanceof Uint8Array?oi(t,e,r):kh(t,e,r)}function Sf(t,e=0){return t instanceof Uint8Array?si(t,e):Uh(t,e)}var ii=new Float32Array([-0]),It=new Uint8Array(ii.buffer);function If(t,e,r){ii[0]=t,e[r]=It[0],e[r+1]=It[1],e[r+2]=It[2],e[r+3]=It[3]}function Cf(t,e){return It[0]=t[e],It[1]=t[e+1],It[2]=t[e+2],It[3]=t[e+3],ii[0]}var ai=new Float64Array([-0]),Ee=new Uint8Array(ai.buffer);function _f(t,e,r){ai[0]=t,e[r]=Ee[0],e[r+1]=Ee[1],e[r+2]=Ee[2],e[r+3]=Ee[3],e[r+4]=Ee[4],e[r+5]=Ee[5],e[r+6]=Ee[6],e[r+7]=Ee[7]}function Tf(t,e){return Ee[0]=t[e],Ee[1]=t[e+1],Ee[2]=t[e+2],Ee[3]=t[e+3],Ee[4]=t[e+4],Ee[5]=t[e+5],Ee[6]=t[e+6],Ee[7]=t[e+7],ai[0]}var Mh=BigInt(Number.MAX_SAFE_INTEGER),Kh=BigInt(Number.MIN_SAFE_INTEGER),De=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 qt;if(e<Mh&&e>Kh)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>Df&&(o=0n,++n>Df&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return qt;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):qt}},qt=new De(0,0);qt.toBigInt=function(){return 0n};qt.zzEncode=qt.zzDecode=function(){return this};qt.length=function(){return 1};var Df=4294967296n;function Bf(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 Of(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 ci(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 ke(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function ao(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var fi=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,ke(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 ke(this,4);return ao(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw ke(this,4);return ao(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw ke(this,4);let e=Cf(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw ke(this,4);let e=Tf(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 ke(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return Of(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw ke(this,e);this.pos+=e}else do if(this.pos>=this.len)throw ke(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 De(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 ke(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 ke(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 ke(this,8);let e=ao(this.buf,this.pos+=4),r=ao(this.buf,this.pos+=4);return new De(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=si(this.buf,this.pos);return this.pos+=ft(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 un(t){return new fi(t instanceof Uint8Array?t:t.subarray())}function Ue(t,e,r){let n=un(t);return e.decode(n,void 0,r)}function zt(t=0){return new Uint8Array(t)}var pi={};Z(pi,{base10:()=>Yh});var nx=new Uint8Array(0);function Pf(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 ut(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function Rf(t){return new TextEncoder().encode(t)}function Ff(t){return new TextDecoder().decode(t)}function Vh(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var s=t.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=t.length,c=t.charAt(0),f=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function l(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var b=0,m=0,g=0,v=d.length;g!==v&&d[g]===0;)g++,b++;for(var S=(v-g)*u+1>>>0,T=new Uint8Array(S);g!==v;){for(var _=d[g],R=0,O=S-1;(_!==0||R<m)&&O!==-1;O--,R++)_+=256*T[O]>>>0,T[O]=_%a>>>0,_=_/a>>>0;if(_!==0)throw new Error("Non-zero carry");m=R,g++}for(var C=S-m;C!==S&&T[C]===0;)C++;for(var N=c.repeat(b);C<S;++C)N+=t.charAt(T[C]);return N}function p(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var b=0;if(d[b]!==" "){for(var m=0,g=0;d[b]===c;)m++,b++;for(var v=(d.length-b)*f+1>>>0,S=new Uint8Array(v);d[b];){var T=r[d.charCodeAt(b)];if(T===255)return;for(var _=0,R=v-1;(T!==0||_<g)&&R!==-1;R--,_++)T+=a*S[R]>>>0,S[R]=T%256>>>0,T=T/256>>>0;if(T!==0)throw new Error("Non-zero carry");g=_,b++}if(d[b]!==" "){for(var O=v-g;O!==v&&S[O]===0;)O++;for(var C=new Uint8Array(m+(v-O)),N=m;O!==v;)C[N++]=S[O++];return C}}}function h(d){var b=p(d);if(b)return b;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:p,decode:h}}var qh=Vh,zh=qh,kf=zh;var ui=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")}},li=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 Uf(this,e)}},di=class{decoders;constructor(e){this.decoders=e}or(e){return Uf(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 Uf(t,e){return new di({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var hi=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 ui(e,r,n),this.decoder=new li(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function mr({name:t,prefix:e,encode:r,decode:n}){return new hi(t,e,r,n)}function Ct({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=kf(r,t);return mr({prefix:e,name:t,encode:n,decode:s=>ut(o(s))})}function Hh(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 f=0;f<o;++f){let u=e[t[f]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|u,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 $h(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 jh(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function oe({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=jh(n);return mr({prefix:e,name:t,encode(s){return $h(s,n,r)},decode(s){return Hh(s,o,r,t)}})}var Yh=Ct({prefix:"9",name:"base10",alphabet:"0123456789"});var mi={};Z(mi,{base16:()=>Gh,base16upper:()=>Zh});var Gh=oe({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Zh=oe({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var yi={};Z(yi,{base2:()=>Wh});var Wh=oe({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var bi={};Z(bi,{base256emoji:()=>tp});var Mf=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}"),Xh=Mf.reduce((t,e,r)=>(t[r]=e,t),[]),Qh=Mf.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Jh(t){return t.reduce((e,r)=>(e+=Xh[r],e),"")}function ep(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Qh[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var tp=mr({prefix:"\u{1F680}",name:"base256emoji",encode:Jh,decode:ep});var gi={};Z(gi,{base32:()=>yr,base32hex:()=>sp,base32hexpad:()=>ap,base32hexpadupper:()=>cp,base32hexupper:()=>ip,base32pad:()=>np,base32padupper:()=>op,base32upper:()=>rp,base32z:()=>fp});var yr=oe({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),rp=oe({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),np=oe({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),op=oe({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),sp=oe({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ip=oe({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ap=oe({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),cp=oe({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),fp=oe({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var xi={};Z(xi,{base36:()=>ln,base36upper:()=>up});var ln=Ct({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),up=Ct({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var wi={};Z(wi,{base58btc:()=>Ge,base58flickr:()=>lp});var Ge=Ct({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),lp=Ct({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ei={};Z(Ei,{base64:()=>dp,base64pad:()=>hp,base64url:()=>pp,base64urlpad:()=>mp});var dp=oe({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),hp=oe({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),pp=oe({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),mp=oe({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var vi={};Z(vi,{base8:()=>yp});var yp=oe({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Si={};Z(Si,{identity:()=>bp});var bp=mr({prefix:"\0",name:"identity",encode:t=>Ff(t),decode:t=>Rf(t)});var xx=new TextEncoder,wx=new TextDecoder;var Ii={};Z(Ii,{identity:()=>Kp});var wp=qf,Kf=128,Ep=127,vp=~Ep,Sp=Math.pow(2,31);function qf(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Sp;)e[r++]=t&255|Kf,t/=128;for(;t&vp;)e[r++]=t&255|Kf,t>>>=7;return e[r]=t|0,qf.bytes=r-n+1,e}var Ap=Ai,Ip=128,Vf=127;function Ai(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw Ai.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&Vf)<<o:(i&Vf)*Math.pow(2,o),o+=7}while(i>=Ip);return Ai.bytes=s-n,r}var Cp=Math.pow(2,7),_p=Math.pow(2,14),Tp=Math.pow(2,21),Dp=Math.pow(2,28),Bp=Math.pow(2,35),Op=Math.pow(2,42),Lp=Math.pow(2,49),Pp=Math.pow(2,56),Rp=Math.pow(2,63),Fp=function(t){return t<Cp?1:t<_p?2:t<Tp?3:t<Dp?4:t<Bp?5:t<Op?6:t<Lp?7:t<Pp?8:t<Rp?9:10},Np={encode:wp,decode:Ap,encodingLength:Fp},kp=Np,dn=kp;function hn(t,e=0){return[dn.decode(t,e),dn.decode.bytes]}function br(t,e,r=0){return dn.encode(t,e,r),e}function gr(t){return dn.encodingLength(t)}function wr(t,e){let r=e.byteLength,n=gr(t),o=n+gr(r),s=new Uint8Array(o+r);return br(t,s,0),br(r,s,n),s.set(e,o),new xr(t,r,e,s)}function zf(t){let e=ut(t),[r,n]=hn(e),[o,s]=hn(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new xr(r,o,i,e)}function Hf(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Pf(t.bytes,r.bytes)}}var xr=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};var $f=0,Up="identity",jf=ut;function Mp(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 wr($f,jf(t))}var Kp={code:$f,name:Up,encode:jf,digest:Mp};var Ti={};Z(Ti,{sha256:()=>qp,sha512:()=>zp});var Vp=20;function _i({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new Ci(t,e,r,n,o)}var Ci=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??Vp,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?Yf(n,this.code,r?.truncate):n.then(o=>Yf(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Yf(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 wr(e,t)}function Zf(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var qp=_i({name:"sha2-256",code:18,encode:Zf("SHA-256")}),zp=_i({name:"sha2-512",code:19,encode:Zf("SHA-512")});function Wf(t,e){let{bytes:r,version:n}=t;return n===0?$p(r,Di(t),e??Ge.encoder):jp(r,Di(t),e??yr.encoder)}var Xf=new WeakMap;function Di(t){let e=Xf.get(t);if(e==null){let r=new Map;return Xf.set(t,r),r}return e}var fo=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}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!==mn)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Yp)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=wr(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&&Hf(e.multihash,n.multihash)}toString(e){return Wf(this,e)}toJSON(){return{"/":Wf(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??Qf(n,o,s.bytes))}else if(r[Gp]===!0){let{version:n,multihash:o,code:s}=r,i=zf(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!==mn)throw new Error(`Version 0 CID must use dag-pb (code: ${mn}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=Qf(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,mn,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=ut(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 xr(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,p]=hn(e.subarray(r));return r+=p,l},o=n(),s=mn;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(),f=r+c,u=f-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:f}}static parse(e,r){let[n,o]=Hp(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 Di(s).set(n,e),s}};function Hp(t,e){switch(t[0]){case"Q":{let r=e??Ge;return[Ge.prefix,r.decode(`${Ge.prefix}${t}`)]}case Ge.prefix:{let r=e??Ge;return[Ge.prefix,r.decode(t)]}case yr.prefix:{let r=e??yr;return[yr.prefix,r.decode(t)]}case ln.prefix:{let r=e??ln;return[ln.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 $p(t,e,r){let{prefix:n}=r;if(n!==Ge.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 jp(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 mn=112,Yp=18;function Qf(t,e,r){let n=gr(t),o=n+gr(e),s=new Uint8Array(o+r.byteLength);return br(t,s,0),br(e,s,n),s.set(r,o),s}var Gp=Symbol.for("@ipld/js-cid/CID");var Bi={...Si,...yi,...vi,...pi,...mi,...gi,...xi,...wi,...Ei,...bi},qx={...Ti,...Ii};function eu(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Jf=eu("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Oi=eu("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=zt(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Zp={utf8:Jf,"utf-8":Jf,hex:Bi.base16,latin1:Oi,ascii:Oi,binary:Oi,...Bi},tu=Zp;function ru(t,e="utf8"){let r=tu[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function Li(t){let e=t??8192,r=e>>>1,n,o=e;return function(i){if(i<1||i>r)return zt(i);o+i>e&&(n=zt(e),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Ht=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function Pi(){}var Fi=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Wp=Li();function Xp(t){return globalThis.Buffer!=null?zt(t):Wp(t)}var bn=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ht(Pi,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Ht(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Ni((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(uo,10,De.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=De.fromBigInt(e);return this._push(uo,r.length(),r)}uint64Number(e){return this._push(oi,ft(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=De.fromBigInt(e).zzEncode();return this._push(uo,r.length(),r)}sint64Number(e){let r=De.fromNumber(e).zzEncode();return this._push(uo,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Ri,1,e?1:0)}fixed32(e){return this._push(yn,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=De.fromBigInt(e);return this._push(yn,4,r.lo)._push(yn,4,r.hi)}fixed64Number(e){let r=De.fromNumber(e);return this._push(yn,4,r.lo)._push(yn,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(If,4,e)}double(e){return this._push(_f,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(Ri,1,0):this.uint32(r)._push(Jp,r,e)}string(e){let r=Bf(e);return r!==0?this.uint32(r)._push(ci,r,e):this._push(Ri,1,0)}fork(){return this.states=new Fi(this),this.head=this.tail=new Ht(Pi,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 Ht(Pi,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=Xp(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function Ri(t,e,r){e[r]=t&255}function Qp(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var Ni=class extends Ht{next;constructor(e,r){super(Qp,e,r),this.next=void 0}};function uo(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 yn(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 Jp(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(bn.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(em,e,t),this},bn.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(tm,e,t),this});function em(t,e,r){e.set(t,r)}function tm(t,e,r){t.length<40?ci(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(ru(t),r)}function ki(){return new bn}function Me(t,e){let r=ki();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*Ke(t,e,r){let n=un(t);yield*e.stream(n,void 0,"$",r)}var lo={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function ho(t,e,r,n,o){return{name:t,type:e,encode:r,decode:n,stream:o}}function Ui(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){let a=i.int32();yield e(a)};return ho("enum",lo.VARINT,r,n,o)}function Ve(t,e,r){return ho("message",lo.LENGTH_DELIMITED,t,e,r)}var Ze=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var ee;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(ee||(ee={}));var Mi;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(Mi||(Mi={}));(function(t){t.codec=()=>Ui(Mi)})(ee||(ee={}));var We;(function(t){let e;t.codec=()=>(e==null&&(e=Ve((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ee.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={},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{c.Type=ee.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return c},function*(s,i,a,c={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:ee.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),e);function r(s){return Me(s,t.codec())}t.encode=r;function n(s,i){return Ue(s,t.codec(),i)}t.decode=n;function o(s,i){return Ke(s,t.codec(),i)}t.stream=o})(We||(We={}));var Ki;(function(t){let e;t.codec=()=>(e==null&&(e=Ve((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ee.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={},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{c.Type=ee.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return c},function*(s,i,a,c={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:ee.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),e);function r(s){return Me(s,t.codec())}t.encode=r;function n(s,i){return Ue(s,t.codec(),i)}t.decode=n;function o(s,i){return Ke(s,t.codec(),i)}t.stream=o})(Ki||(Ki={}));var xn={};Z(xn,{MAX_RSA_KEY_SIZE:()=>Vi,generateRSAKeyPair:()=>au,jwkToJWKKeyPair:()=>cu,jwkToPkcs1:()=>sm,jwkToPkix:()=>$i,jwkToRSAPrivateKey:()=>Zi,pkcs1MessageToJwk:()=>zi,pkcs1MessageToRSAPrivateKey:()=>ji,pkcs1ToJwk:()=>om,pkcs1ToRSAPrivateKey:()=>iu,pkixMessageToJwk:()=>Hi,pkixMessageToRSAPublicKey:()=>Gi,pkixToJwk:()=>im,pkixToRSAPublicKey:()=>Yi});var Er=class{type="RSA";jwk;_raw;_multihash;constructor(e,r){this.jwk=e,this._multihash=r}get raw(){return this._raw==null&&(this._raw=xn.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return he.createV1(114,this._multihash)}toString(){return ie.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ye(this.raw,e.raw)}verify(e,r,n){return su(this.jwk,r,e,n)}},gn=class{type="RSA";jwk;_raw;publicKey;constructor(e,r){this.jwk=e,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=xn.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ye(this.raw,e.raw)}sign(e,r){return ou(this.jwk,e,r)}};var Vi=8192,qi=18,rm=1062,nm=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function om(t){let e=nt(t);return zi(e)}function zi(t){return{n:V(t[1],"base64url"),e:V(t[2],"base64url"),d:V(t[3],"base64url"),p:V(t[4],"base64url"),q:V(t[5],"base64url"),dp:V(t[6],"base64url"),dq:V(t[7],"base64url"),qi:V(t[8],"base64url"),kty:"RSA"}}function sm(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 J("JWK was missing components");return yt([Ie(Uint8Array.from([0])),Ie(K(t.n,"base64url")),Ie(K(t.e,"base64url")),Ie(K(t.d,"base64url")),Ie(K(t.p,"base64url")),Ie(K(t.q,"base64url")),Ie(K(t.dp,"base64url")),Ie(K(t.dq,"base64url")),Ie(K(t.qi,"base64url"))]).subarray()}function im(t){let e=nt(t,{offset:0});return Hi(e)}function Hi(t){let e=nt(t[1],{offset:0});return{kty:"RSA",n:V(e[0],"base64url"),e:V(e[1],"base64url")}}function $i(t){if(t.n==null||t.e==null)throw new J("JWK was missing components");return yt([nm,Vn(yt([Ie(K(t.n,"base64url")),Ie(K(t.e,"base64url"))]))]).subarray()}function iu(t){let e=nt(t);return ji(e)}function ji(t){let e=zi(t);return Zi(e)}function Yi(t,e){if(t.byteLength>=rm)throw new Qt("Key size is too large");let r=nt(t,{offset:0});return Gi(r,t,e)}function Gi(t,e,r){let n=Hi(t);if(r==null){let o=sr(We.encode({Type:ee.RSA,Data:e}));r=He(qi,o)}return new Er(n,r)}function Zi(t){if(uu(t)>Vi)throw new J("Key size is too large");let e=cu(t),r=sr(We.encode({Type:ee.RSA,Data:$i(e.publicKey)})),n=He(qi,r);return new gn(e.privateKey,new Er(e.publicKey,n))}async function au(t){if(t>Vi)throw new J("Key size is too large");let e=await fu(t),r=sr(We.encode({Type:ee.RSA,Data:$i(e.publicKey)})),n=He(qi,r);return new gn(e.privateKey,new Er(e.publicKey,n))}function cu(t){if(t==null)throw new J("Missing key parameter");return{privateKey:t,publicKey:{kty:t.kty,n:t.n,e:t.e}}}async function fu(t,e){let r=await Be.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 am(r,e);return{privateKey:n[0],publicKey:n[1]}}async function ou(t,e,r){let n=await Be.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Be.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 su(t,e,r,n){let o=await Be.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Be.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 am(t,e){if(t.privateKey==null||t.publicKey==null)throw new J("Private and public key are required");let r=await Promise.all([Be.get().subtle.exportKey("jwk",t.privateKey),Be.get().subtle.exportKey("jwk",t.publicKey)]);return e?.signal?.throwIfAborted(),r}function uu(t){if(t.kty!=="RSA")throw new J("invalid key type");if(t.n==null)throw new J("invalid key modulus");return K(t.n,"base64url").length*8}var po=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(qn(e),Te(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let 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),st(o)}update(e){return or(this),this.iHash.update(e),this}digestInto(e){or(this),zn(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}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=a,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()}},lu=(()=>{let t=((e,r,n)=>new po(e,r).update(n).digest());return t.create=(e,r)=>new po(e,r),t})();var du=(t,e)=>(t+(t>=0?e:-e)/hu)/e;function cm(t,e,r){cr("scalar",t,Xe,r);let[[n,o],[s,i]]=e,a=du(i*t,r),c=du(-o*t,r),f=t-a*n-c*s,u=-a*o-c*i,l=f<Xe,p=u<Xe;l&&(f=-f),p&&(u=-u);let h=on(Math.ceil(fr(r)/2))+_t;if(f<Xe||f>=h||u<Xe||u>=h)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:f,k2neg:p,k2:u}}function Xi(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Wi(t,e){Ne(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Re(r.lowS,"lowS"),Re(r.prehash,"prehash"),r.format!==void 0&&Xi(r.format),r}var Qi=class extends Error{constructor(e=""){super(e)}},qe={Err:Qi,_tlv:{encode:(t,e)=>{let{Err:r}=qe;if(Fe(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(typeof e!="string")throw new TypeError('"data" expected string, got type='+typeof e);if(e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,o=rn(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?rn(o.length/2|128):"";return rn(t)+s+o+e},decode(t,e){let{Err:r}=qe;e=z(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.encode: 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 f=e.subarray(n,n+c);if(f.length!==c)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let u of f)i=i<<8|u;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}=qe;if(Wn(t),t<Xe)throw new e("integer: negative integers are not allowed");let r=rn(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}=qe;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 kt(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=qe,o=z(t,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:f,l:u}=n.decode(2,c);if(u.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(f)}},hexFromSig(t){let{_tlv:e,_int:r}=qe,n=e.encode(2,r.encode(t.r)),o=e.encode(2,r.encode(t.s)),s=n+o;return e.encode(48,s)}};Object.freeze(qe._tlv);Object.freeze(qe._int);Object.freeze(qe);var Xe=BigInt(0),_t=BigInt(1),hu=BigInt(2),mo=BigInt(3),fm=BigInt(4);function pu(t,e={}){let r=eo("weierstrass",t,e),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;Ne(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c,allowInfinityPoint:f}=e;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 u=yu(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function p(k,y,x){if(f&&y.is0())return Uint8Array.of(0);let{x:A,y:E}=y.toAffine(),w=n.toBytes(A);if(Re(x,"isCompressed"),x){l();let I=!n.isOdd(E);return ue(mu(I),w)}else return ue(Uint8Array.of(4),w,n.toBytes(E))}function h(k){z(k,void 0,"Point");let{publicKey:y,publicKeyUncompressed:x}=u,A=k.length,E=k[0],w=k.subarray(1);if(f&&A===1&&E===0)return{x:n.ZERO,y:n.ZERO};if(A===y&&(E===2||E===3)){let I=n.fromBytes(w);if(!n.isValid(I))throw new Error("bad point: is not on curve, wrong x");let B=m(I),D;try{D=n.sqrt(B)}catch(q){let j=q instanceof Error?": "+q.message:"";throw new Error("bad point: is not on curve, sqrt error"+j)}l();let L=n.isOdd(D);return(E&1)===1!==L&&(D=n.neg(D)),{x:I,y:D}}else if(A===x&&E===4){let I=n.BYTES,B=n.fromBytes(w.subarray(0,I)),D=n.fromBytes(w.subarray(I,I*2));if(!g(B,D))throw new Error("bad point: is not on curve");return{x:B,y:D}}else throw new Error(`bad point: got length ${A}, expected compressed=${y} or uncompressed=${x}`)}let d=e.toBytes===void 0?p:e.toBytes,b=e.fromBytes===void 0?h:e.fromBytes;function m(k){let y=n.sqr(k),x=n.mul(y,k);return n.add(n.add(x,n.mul(k,s.a)),s.b)}function g(k,y){let x=n.sqr(y),A=m(k);return n.eql(x,A)}if(!g(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let v=n.mul(n.pow(s.a,mo),fm),S=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(v,S)))throw new Error("bad curve params: a or b");function T(k,y,x=!1){if(!n.isValid(y)||x&&n.is0(y))throw new Error(`bad point coordinate ${k}`);return y}function _(k){if(!(k instanceof C))throw new Error("Weierstrass Point expected")}function R(k){if(!c||!c.basises)throw new Error("no endo");return cm(k,c.basises,o.ORDER)}function O(k,y,x,A,E){return x=new C(n.mul(x.X,k),x.Y,x.Z),y=an(A,y),x=an(E,x),y.add(x)}class C{static BASE=new C(s.Gx,s.Gy,n.ONE);static ZERO=new C(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(y,x,A){this.X=T("x",y),this.Y=T("y",x,!0),this.Z=T("z",A),Object.freeze(this)}static CURVE(){return s}static fromAffine(y){let{x,y:A}=y||{};if(!y||!n.isValid(x)||!n.isValid(A))throw new Error("invalid affine point");if(y instanceof C)throw new Error("projective point not allowed");return n.is0(x)&&n.is0(A)?C.ZERO:new C(x,A,n.ONE)}static fromBytes(y){let x=C.fromAffine(b(z(y,void 0,"point")));return x.assertValidity(),x}static fromHex(y){return C.fromBytes(ar(y))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,x=!0){return G.createCache(this,y),x||this.multiply(mo),this}assertValidity(){let y=this;if(y.is0()){if(e.allowInfinityPoint&&n.is0(y.X)&&n.eql(y.Y,n.ONE)&&n.is0(y.Z))return;throw new Error("bad point: ZERO")}let{x,y:A}=y.toAffine();if(!n.isValid(x)||!n.isValid(A))throw new Error("bad point: x or y not field elements");if(!g(x,A))throw new Error("bad point: equation left != right");if(!y.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(y)}equals(y){_(y);let{X:x,Y:A,Z:E}=this,{X:w,Y:I,Z:B}=y,D=n.eql(n.mul(x,B),n.mul(w,E)),L=n.eql(n.mul(A,B),n.mul(I,E));return D&&L}negate(){return new C(this.X,n.neg(this.Y),this.Z)}double(){let{a:y,b:x}=s,A=n.mul(x,mo),{X:E,Y:w,Z:I}=this,B=n.ZERO,D=n.ZERO,L=n.ZERO,F=n.mul(E,E),q=n.mul(w,w),j=n.mul(I,I),U=n.mul(E,w);return U=n.add(U,U),L=n.mul(E,I),L=n.add(L,L),B=n.mul(y,L),D=n.mul(A,j),D=n.add(B,D),B=n.sub(q,D),D=n.add(q,D),D=n.mul(B,D),B=n.mul(U,B),L=n.mul(A,L),j=n.mul(y,j),U=n.sub(F,j),U=n.mul(y,U),U=n.add(U,L),L=n.add(F,F),F=n.add(L,F),F=n.add(F,j),F=n.mul(F,U),D=n.add(D,F),j=n.mul(w,I),j=n.add(j,j),F=n.mul(j,U),B=n.sub(B,F),L=n.mul(j,q),L=n.add(L,L),L=n.add(L,L),new C(B,D,L)}add(y){_(y);let{X:x,Y:A,Z:E}=this,{X:w,Y:I,Z:B}=y,D=n.ZERO,L=n.ZERO,F=n.ZERO,q=s.a,j=n.mul(s.b,mo),U=n.mul(x,w),fe=n.mul(A,I),le=n.mul(E,B),de=n.add(x,A),se=n.add(w,I);de=n.mul(de,se),se=n.add(U,fe),de=n.sub(de,se),se=n.add(x,E);let Ae=n.add(w,B);return se=n.mul(se,Ae),Ae=n.add(U,le),se=n.sub(se,Ae),Ae=n.add(A,E),D=n.add(I,B),Ae=n.mul(Ae,D),D=n.add(fe,le),Ae=n.sub(Ae,D),F=n.mul(q,se),D=n.mul(j,le),F=n.add(D,F),D=n.sub(fe,F),F=n.add(fe,F),L=n.mul(D,F),fe=n.add(U,U),fe=n.add(fe,U),le=n.mul(q,le),se=n.mul(j,se),fe=n.add(fe,le),le=n.sub(U,le),le=n.mul(q,le),se=n.add(se,le),U=n.mul(fe,se),L=n.add(L,U),U=n.mul(Ae,se),D=n.mul(de,D),D=n.sub(D,U),U=n.mul(de,fe),F=n.mul(Ae,F),F=n.add(F,U),new C(D,L,F)}subtract(y){return _(y),this.add(y.negate())}is0(){return this.equals(C.ZERO)}multiply(y){let{endo:x}=e;if(!o.isValidNot0(y))throw new RangeError("invalid scalar: out of range");let A,E,w=I=>G.cached(this,I,B=>Kt(C,B));if(x){let{k1neg:I,k1:B,k2neg:D,k2:L}=R(y),{p:F,f:q}=w(B),{p:j,f:U}=w(L);E=q.add(U),A=O(x.beta,F,j,I,D)}else{let{p:I,f:B}=w(y);A=I,E=B}return Kt(C,[A,E])[0]}multiplyUnsafe(y){let{endo:x}=e,A=this,E=y;if(!o.isValid(E))throw new RangeError("invalid scalar: out of range");if(E===Xe||A.is0())return C.ZERO;if(E===_t)return A;if(G.hasCache(this))return this.multiply(E);if(x){let{k1neg:w,k1:I,k2neg:B,k2:D}=R(E),{p1:L,p2:F}=lf(C,A,I,D);return O(x.beta,L,F,w,B)}else return G.unsafe(A,E)}toAffine(y){let x=this,A=y,{X:E,Y:w,Z:I}=x;if(n.eql(I,n.ONE))return{x:E,y:w};let B=x.is0();A==null&&(A=B?n.ONE:n.inv(I));let D=n.mul(E,A),L=n.mul(w,A),F=n.mul(I,A);if(B)return{x:n.ZERO,y:n.ZERO};if(!n.eql(F,n.ONE))throw new Error("invZ was invalid");return{x:D,y:L}}isTorsionFree(){let{isTorsionFree:y}=e;return i===_t?!0:y?y(C,this):G.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:y}=e;return i===_t?this:y?y(C,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===_t?this.is0():this.clearCofactor().is0()}toBytes(y=!0){return Re(y,"isCompressed"),this.assertValidity(),d(C,this,y)}toHex(y=!0){return ir(this.toBytes(y))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let N=o.BITS,G=new dr(C,e.endo?Math.ceil(N/2):N);return N>=8&&C.BASE.precompute(8),Object.freeze(C.prototype),Object.freeze(C),C}function mu(t){return Uint8Array.of(t?2:3)}function yu(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function um(t,e={}){let{Fn:r}=t,n=e.randomBytes===void 0?tn:e.randomBytes,o=Object.assign(yu(t.Fp,r),{seed:Math.max(Us(r.ORDER),16)});function s(h){try{let d=r.fromBytes(h);return r.isValidNot0(d)}catch{return!1}}function i(h,d){let{publicKey:b,publicKeyUncompressed:m}=o;try{let g=h.length;return d===!0&&g!==b||d===!1&&g!==m?!1:!!t.fromBytes(h)}catch{return!1}}function a(h){return h=h===void 0?n(o.seed):h,Ms(z(h,o.seed,"seed"),r.ORDER)}function c(h,d=!0){return t.BASE.multiply(r.fromBytes(h)).toBytes(d)}function f(h){let{secretKey:d,publicKey:b,publicKeyUncompressed:m}=o,g=r._lengths;if(!Nt(h))return;let v=z(h,void 0,"key").length,S=v===b||v===m,T=v===d||!!g?.includes(v);if(!(S&&T))return S}function u(h,d,b=!0){if(f(h)===!0)throw new Error("first arg must be private key");if(f(d)===!1)throw new Error("second arg must be public key");let m=r.fromBytes(h);return t.fromBytes(d).multiply(m).toBytes(b)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},p=to(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:p,Point:t,utils:l,lengths:o})}function bu(t,e,r={}){let n=e;qn(n),Ne(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let o=r.randomBytes===void 0?tn:r.randomBytes,s=r.hmac===void 0?(E,w)=>lu(n,E,w):r.hmac,{Fp:i,Fn:a}=t,{ORDER:c,BITS:f}=a,{keygen:u,getPublicKey:l,getSharedSecret:p,utils:h,lengths:d}=um(t,r),b={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},m=c*hu+_t<i.ORDER;function g(E){let w=c>>_t;return E>w}function v(E,w){if(!a.isValidNot0(w))throw new Error(`invalid signature ${E}: out of range 1..Point.Fn.ORDER`);return w}function S(){if(m)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function T(E,w){Xi(w);let I=d.signature,B=w==="compact"?I:w==="recovered"?I+1:void 0;return z(E,B)}class _{r;s;recovery;constructor(w,I,B){if(this.r=v("r",w),this.s=v("s",I),B!=null){if(S(),![0,1,2,3].includes(B))throw new Error("invalid recovery id");this.recovery=B}Object.freeze(this)}static fromBytes(w,I=b.format){T(w,I);let B;if(I==="der"){let{r:q,s:j}=qe.toSig(z(w));return new _(q,j)}I==="recovered"&&(B=w[0],I="compact",w=w.subarray(1));let D=d.signature/2,L=w.subarray(0,D),F=w.subarray(D,D*2);return new _(a.fromBytes(L),a.fromBytes(F),B)}static fromHex(w,I){return this.fromBytes(ar(w),I)}assertRecovery(){let{recovery:w}=this;if(w==null)throw new Error("invalid recovery id: must be present");return w}addRecoveryBit(w){return new _(this.r,this.s,w)}recoverPublicKey(w){let{r:I,s:B}=this,D=this.assertRecovery(),L=D===2||D===3?I+c:I;if(!i.isValid(L))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let F=i.toBytes(L),q=t.fromBytes(ue(mu((D&1)===0),F)),j=a.inv(L),U=O(z(w,void 0,"msgHash")),fe=a.create(-U*j),le=a.create(B*j),de=t.BASE.multiplyUnsafe(fe).add(q.multiplyUnsafe(le));if(de.is0())throw new Error("invalid recovery: point at infinify");return de.assertValidity(),de}hasHighS(){return g(this.s)}toBytes(w=b.format){if(Xi(w),w==="der")return ar(qe.hexFromSig(this));let{r:I,s:B}=this,D=a.toBytes(I),L=a.toBytes(B);return w==="recovered"?(S(),ue(Uint8Array.of(this.assertRecovery()),D,L)):ue(D,L)}toHex(w){return ir(this.toBytes(w))}}Object.freeze(_.prototype),Object.freeze(_);let R=r.bits2int===void 0?function(w){if(w.length>8192)throw new Error("input is too large");let I=kt(w),B=w.length*8-f;return B>0?I>>BigInt(B):I}:r.bits2int,O=r.bits2int_modN===void 0?function(w){return a.create(R(w))}:r.bits2int_modN,C=on(f);function N(E){return cr("num < 2^"+f,E,Xe,C),a.toBytes(E)}function G(E,w){return z(E,void 0,"message"),w?z(n(E),void 0,"prehashed message"):E}function k(E,w,I){let{lowS:B,prehash:D,extraEntropy:L}=Wi(I,b);E=G(E,D);let F=O(E),q=a.fromBytes(w);if(!a.isValidNot0(q))throw new Error("invalid private key");let j=[N(q),N(F)];if(L!=null&&L!==!1){let de=L===!0?o(d.secretKey):L;j.push(z(de,void 0,"extraEntropy"))}let U=ue(...j),fe=F;function le(de){let se=R(de);if(!a.isValidNot0(se))return;let Ae=a.inv(se),Xt=t.BASE.multiply(se).toAffine(),Kr=a.create(Xt.x);if(Kr===Xe)return;let Pn=a.create(Ae*a.create(fe+Kr*q));if(Pn===Xe)return;let ec=(Xt.x===Kr?0:2)|Number(Xt.y&_t),tc=Pn;return B&&g(Pn)&&(tc=a.neg(Pn),ec^=1),new _(Kr,tc,m?void 0:ec)}return{seed:U,k2sig:le}}function y(E,w,I={}){let{seed:B,k2sig:D}=k(E,w,I);return Yc(n.outputLen,a.BYTES,s)(B,D).toBytes(I.format)}function x(E,w,I,B={}){let{lowS:D,prehash:L,format:F}=Wi(B,b);if(I=z(I,void 0,"publicKey"),w=G(w,L),!Nt(E)){let q=E instanceof _?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+q)}T(E,F);try{let q=_.fromBytes(E,F),j=t.fromBytes(I);if(D&&q.hasHighS())return!1;let{r:U,s:fe}=q,le=O(w),de=a.inv(fe),se=a.create(le*de),Ae=a.create(U*de),Xt=t.BASE.multiplyUnsafe(se).add(j.multiplyUnsafe(Ae));return Xt.is0()?!1:a.create(Xt.x)===U}catch{return!1}}function A(E,w,I={}){let{prehash:B}=Wi(I,b);return w=G(w,B),_.fromBytes(E,"recovered").recoverPublicKey(w).toBytes()}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:p,utils:h,lengths:d,Point:t,sign:y,verify:x,recoverPublicKey:A,Signature:_,hash:n})}var ea={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},lm={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var gu=BigInt(2);function dm(t){let e=ea.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),f=t*t*t%e,u=f*f*t%e,l=Q(u,r,e)*u%e,p=Q(l,r,e)*u%e,h=Q(p,gu,e)*f%e,d=Q(h,o,e)*h%e,b=Q(d,s,e)*d%e,m=Q(b,a,e)*b%e,g=Q(m,c,e)*m%e,v=Q(g,a,e)*b%e,S=Q(v,r,e)*u%e,T=Q(S,i,e)*d%e,_=Q(T,n,e)*f%e,R=Q(_,gu,e);if(!Ji.eql(Ji.sqr(R),t))throw new Error("Cannot find square root");return R}var Ji=ur(ea.p,{sqrt:dm}),hm=pu(ea,{Fp:Ji,endo:lm}),vr=bu(hm,sr);function xu(t,e,r,n){let o=Yr.digest(r instanceof Uint8Array?r:r.subarray());if(so(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),vr.verify(e,s,t,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new fn(String(s))});try{return n?.signal?.throwIfAborted(),vr.verify(e,o.digest,t,{prehash:!1,format:"der"})}catch(s){throw new fn(String(s))}}var yo=class{type="secp256k1";raw;_key;constructor(e){this._key=Eu(e),this.raw=wu(this._key)}toMultihash(){return Le.digest($e(this))}toCID(){return he.createV1(114,this.toMultihash())}toString(){return ie.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ye(this.raw,e.raw)}verify(e,r,n){return xu(this._key,r,e,n)}};function ta(t){return new yo(t)}function wu(t){return vr.Point.fromBytes(t).toBytes()}function Eu(t){try{return vr.Point.fromBytes(t),t}catch(e){throw new Qt(String(e))}}function Sr(t,e){let{Type:r,Data:n}=We.decode(t),o=n??new Uint8Array;switch(r){case ee.RSA:return Yi(o,e);case ee.Ed25519:return Js(o);case ee.secp256k1:return ta(o);case ee.ECDSA:return Es(o);default:throw new Bt}}function vu(t){let{Type:e,Data:r}=We.decode(t.digest),n=r??new Uint8Array;switch(e){case ee.Ed25519:return Js(n);case ee.secp256k1:return ta(n);case ee.ECDSA:return Es(n);default:throw new Bt}}function $e(t){return We.encode({Type:ee[t.type],Data:t.raw})}var wn;(function(t){let e;t.codec=()=>(e==null&&(e=Ve((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:rt(0),payloadType:rt(0),payload:rt(0),signature:rt(0)},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>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(u&7);break}}}return c},function*(s,i,a,c={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>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(u&7);break}}}})),e);function r(s){return Me(s,t.codec())}t.encode=r;function n(s,i){return Ue(s,t.codec(),i)}t.decode=n;function o(s,i){return Ke(s,t.codec(),i)}t.stream=o})(wn||(wn={}));var bo=class extends Error{constructor(e="Invalid signature"){super(e),this.name="InvalidSignatureError"}};var Qe=class t{static createFromProtobuf=e=>{let r=wn.decode(e),n=Sr(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=Su(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 bo("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=wn.encode({publicKey:$e(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(e){return e==null?!1:ye(this.marshal(),e.marshal())}async validate(e,r){let n=Su(e,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},Su=(t,e,r)=>{let n=K(t),o=pr(n.byteLength),s=pr(e.length),i=pr(r.length);return new ce(o,n,s,e,i,r)};var Au=Symbol.for("nodejs.util.inspect.custom"),pm=114,En=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()})`}[jo]=!0;toString(){return this.string==null&&(this.string=ie.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return he.createV1(pm,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return ye(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return ye(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[Au](){return`PeerId(${this.toString()})`}},vn=class extends En{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},Sn=class extends En{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},An=class extends En{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},mm=2336,In=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Le.digest(K(this.url))}[Au](){return`PeerId(${this.url})`}[jo]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return he.createV1(mm,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=V(e)),e.toString()===this.toString())}};var ym=114,Iu=2336;function Cu(t){if(t.type==="Ed25519")return new Sn({multihash:t.toCID().multihash,publicKey:t});if(t.type==="secp256k1")return new An({multihash:t.toCID().multihash,publicKey:t});if(t.type==="RSA")return new vn({multihash:t.toCID().multihash,publicKey:t});throw new Bt}function ra(t){if(gm(t))return new vn({multihash:t});if(bm(t))try{let e=vu(t);if(e.type==="Ed25519")return new Sn({multihash:t,publicKey:e});if(e.type==="secp256k1")return new An({multihash:t,publicKey:e})}catch{let r=V(t.digest);return new In(new URL(r))}throw new Nn("Supplied PeerID Multihash is invalid")}function go(t){if(t?.multihash==null||t.version==null||t.version===1&&t.code!==ym&&t.code!==Iu)throw new Fn("Supplied PeerID CID is invalid");if(t.code===Iu){let e=V(t.multihash.digest);return new In(new URL(e))}return ra(t.multihash)}function bm(t){return t.code===Le.code}function gm(t){return t.code===Yr.code}var xm=Math.pow(2,7),wm=Math.pow(2,14),Em=Math.pow(2,21),na=Math.pow(2,28),oa=Math.pow(2,35),sa=Math.pow(2,42),ia=Math.pow(2,49),te=128,ve=127;function Ar(t){if(t<xm)return 1;if(t<wm)return 2;if(t<Em)return 3;if(t<na)return 4;if(t<oa)return 5;if(t<sa)return 6;if(t<ia)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function aa(t,e,r=0){switch(Ar(t)){case 8:e[r++]=t&255|te,t/=128;case 7:e[r++]=t&255|te,t/=128;case 6:e[r++]=t&255|te,t/=128;case 5:e[r++]=t&255|te,t/=128;case 4:e[r++]=t&255|te,t>>>=7;case 3:e[r++]=t&255|te,t>>>=7;case 2:e[r++]=t&255|te,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function vm(t,e){let r=t[e],n=0;if(n+=r&ve,r<te||(r=t[e+1],n+=(r&ve)<<7,r<te)||(r=t[e+2],n+=(r&ve)<<14,r<te)||(r=t[e+3],n+=(r&ve)<<21,r<te)||(r=t[e+4],n+=(r&ve)*na,r<te)||(r=t[e+5],n+=(r&ve)*oa,r<te)||(r=t[e+6],n+=(r&ve)*sa,r<te)||(r=t[e+7],n+=(r&ve)*ia,r<te))return n;throw new RangeError("Could not decode varint")}function Sm(t,e){let r=t.get(e),n=0;if(n+=r&ve,r<te||(r=t.get(e+1),n+=(r&ve)<<7,r<te)||(r=t.get(e+2),n+=(r&ve)<<14,r<te)||(r=t.get(e+3),n+=(r&ve)<<21,r<te)||(r=t.get(e+4),n+=(r&ve)*na,r<te)||(r=t.get(e+5),n+=(r&ve)*oa,r<te)||(r=t.get(e+6),n+=(r&ve)*sa,r<te)||(r=t.get(e+7),n+=(r&ve)*ia,r<te))return n;throw new RangeError("Could not decode varint")}function ca(t,e=0){return t instanceof Uint8Array?vm(t,e):Sm(t,e)}var xe=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},lt=class extends Error{static name="ValidationError";name="ValidationError"},xo=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},wo=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",f=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let p=Number.parseInt(l,e);if(!Number.isNaN(p))return p});if(u===void 0)break;if(s*=e,s+=u,s>f||(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 _u=45,Im=15,Ir=new Eo;function vo(t){if(!(t.length>Im))return Ir.new(t).parseWith(()=>Ir.readIPv4Addr())}function So(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>_u))return Ir.new(t).parseWith(()=>Ir.readIPv6Addr())}function Cr(t,e=!1){if(t.includes("%")&&(t=t.split("%")[0]),t.length>_u)return;let r=Ir.new(t).parseWith(()=>Ir.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 _r(t){return!!vo(t)}function Ao(t){return!!So(t)}function ua(t){return e=>V(e,t)}function la(t){return e=>K(e,t)}function Tr(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function $t(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function Tu(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=K(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=$t(n);return Vt([r,o],r.length+o.length)}function Du(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=mt.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=$t(n);return Vt([r,o],r.length+o.length)}function da(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=V(e,"base32"),o=Tr(r);return`${n}:${o}`}var ha=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 xe("Invalid byte value in IP address");e[n]=o}),e},Bu=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let s=_r(r[n]),i;s&&(i=ha(r[n]),r[n]=V(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,V(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 xe("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},Ou=function(t){if(t.byteLength!==4)throw new xe("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},Lu=function(t){if(t.byteLength!==16)throw new xe("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 xe(`Invalid IPv6 address "${r}"`)}};function Pu(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new xe(`Invalid IPv6 address "${t}"`)}}var fa=Object.values(Gr).map(t=>t.decoder),Cm=(function(){let t=fa[0].or(fa[1]);return fa.slice(2).forEach(e=>t=t.or(e)),t})();function Ru(t){return Cm.decode(t)}function Fu(t){return e=>t.encoder.encode(e)}function _m(t){if(parseInt(t).toString()!==t)throw new lt("Value must be an integer")}function Tm(t){if(t<0)throw new lt("Value must be a positive integer, or zero")}function Dm(t){return e=>{if(e>t)throw new lt(`Value must be smaller than or equal to ${t}`)}}function Bm(...t){return e=>{for(let r of t)r(e)}}var Cn=Bm(_m,Tm,Dm(65535));var me=-1,pa=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 wo(`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)}))}},ht=new pa,Hm=[{code:4,name:"ip4",size:32,valueToBytes:ha,bytesToValue:Ou,validate:t=>{if(!_r(t))throw new lt(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:$t,bytesToValue:Tr,validate:Cn},{code:273,name:"udp",size:16,valueToBytes:$t,bytesToValue:Tr,validate:Cn},{code:33,name:"dccp",size:16,valueToBytes:$t,bytesToValue:Tr,validate:Cn},{code:41,name:"ip6",size:128,valueToBytes:Bu,bytesToValue:Lu,stringToValue:Pu,validate:t=>{if(!Ao(t))throw new lt(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:me},{code:43,name:"ipcidr",size:8,bytesToValue:ua("base10"),valueToBytes:la("base10")},{code:53,name:"dns",size:me},{code:54,name:"dns4",size:me},{code:55,name:"dns6",size:me},{code:56,name:"dnsaddr",size:me},{code:132,name:"sctp",size:16,valueToBytes:$t,bytesToValue:Tr,validate:Cn},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:me,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:me,bytesToValue:ua("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?la("base58btc")(t):he.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:da,valueToBytes:Tu},{code:445,name:"onion3",size:296,bytesToValue:da,valueToBytes:Du},{code:446,name:"garlic64",size:me},{code:447,name:"garlic32",size:me},{code:448,name:"tls"},{code:449,name:"sni",size:me},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:me,bytesToValue:Fu(cs),valueToBytes:Ru},{code:480,name:"http"},{code:481,name:"http-path",size:me,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:me}];Hm.forEach(t=>{ht.addProtocol(t)});function Nu(t){let e=[],r=0;for(;r<t.length;){let n=ca(t,r),o=ht.getProtocol(n),s=Ar(n),i=$m(o,t,r+s),a=0;i>0&&o.size===me&&(a=Ar(i));let c=s+a+i,f={code:n,name:o.name,bytes:_e(t.subarray(r,r+c))};if(i>0){let u=r+s+a,l=t.subarray(u,u+i);f.value=o.bytesToValue?.(l)??V(l)}e.push(f),r+=c}return e}function ku(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let o=ht.getProtocol(n.code),s=Ar(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??K(n.value),a=i.byteLength,o.size===me&&(c=Ar(a)));let f=new Uint8Array(s+c+a),u=0;aa(n.code,f,u),u+=s,i!=null&&(o.size===me&&(aa(a,f,u),u+=c),f.set(i,u)),n.bytes=f}r.push(n.bytes),e+=n.bytes.byteLength}return Vt(r,e)}function Uu(t){if(t.charAt(0)!=="/")throw new xe('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=ht.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 xe(`Component ${o} was missing value`);r="value"}else if(r==="value"){let f={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new xe(`Component ${o} was missing value`);f.value=c.stringToValue?.(n)??n}e.push(f),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new xe("Incomplete multiaddr");return e}function Mu(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=ht.getProtocol(e.code);if(r==null)throw new xe(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function $m(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:ca(e,r)}var jm=Symbol.for("nodejs.util.inspect.custom"),Da=Symbol.for("@multiformats/multiaddr");function Ym(t){if(t==null&&(t="/"),Ku(t))return t.getComponents();if(t instanceof Uint8Array)return Nu(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),Uu(t);if(Array.isArray(t))return t;throw new xe("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Bo=class t{[Da]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=Ym(e),r.validate!==!1&&Gm(this)}get bytes(){return this.#r==null&&(this.#r=ku(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=Mu(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 xo(`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 ye(this.bytes,e.bytes)}[jm](){return`Multiaddr(${this.toString()})`}};function Gm(t){t.getComponents().forEach(e=>{let r=ht.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function Ku(t){return!!t?.[Da]}function Tn(t){return new Bo(t)}var Vu="libp2p-peer-record",qu=Uint8Array.from([3,1]);var Dn;(function(t){let e;(function(i){let a;i.codec=()=>(a==null&&(a=Ve((l,p,h={})=>{h.lengthDelimited!==!1&&p.fork(),l.multiaddr!=null&&l.multiaddr.byteLength>0&&(p.uint32(10),p.bytes(l.multiaddr)),h.lengthDelimited!==!1&&p.ldelim()},(l,p,h={})=>{let d={multiaddr:rt(0)},b=p==null?l.len:l.pos+p;for(;l.pos<b;){let m=l.uint32();m>>>3===1?d.multiaddr=l.bytes():l.skipType(m&7)}return d},function*(l,p,h,d={}){let b=p==null?l.len:l.pos+p;for(;l.pos<b;){let m=l.uint32();m>>>3===1?yield{field:`${h}.multiaddr`,value:l.bytes()}:l.skipType(m&7)}})),a);function c(l){return Me(l,i.codec())}i.encode=c;function f(l,p){return Ue(l,i.codec(),p)}i.decode=f;function u(l,p){return Ke(l,i.codec(),p)}i.stream=u})(e=t.AddressInfo||(t.AddressInfo={}));let r;t.codec=()=>(r==null&&(r=Ve((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 f of i.addresses)a.uint32(26),t.AddressInfo.codec().encode(f,a);c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let f={peerId:rt(0),seq:0n,addresses:[]},u=a==null?i.len:i.pos+a;for(;i.pos<u;){let l=i.uint32();switch(l>>>3){case 1:{f.peerId=i.bytes();break}case 2:{f.seq=i.uint64();break}case 3:{if(c.limits?.addresses!=null&&f.addresses.length===c.limits.addresses)throw new Ze('Decode error - repeated field "addresses" had too many elements');f.addresses.push(t.AddressInfo.codec().decode(i,i.uint32(),{limits:c.limits?.addresses$}));break}default:{i.skipType(l&7);break}}}return f},function*(i,a,c,f={}){let u={addresses:0},l=a==null?i.len:i.pos+a;for(;i.pos<l;){let p=i.uint32();switch(p>>>3){case 1:{yield{field:`${c}.peerId`,value:i.bytes()};break}case 2:{yield{field:`${c}.seq`,value:i.uint64()};break}case 3:{if(f.limits?.addresses!=null&&u.addresses===f.limits.addresses)throw new Ze('Streaming decode error - repeated field "addresses" had too many elements');for(let h of t.AddressInfo.codec().stream(i,i.uint32(),`${c}.addresses[]`,{limits:f.limits?.addresses$}))yield{...h,index:u.addresses};u.addresses++;break}default:{i.skipType(p&7);break}}}})),r);function n(i){return Me(i,t.codec())}t.encode=n;function o(i,a){return Ue(i,t.codec(),a)}t.decode=o;function s(i,a){return Ke(i,t.codec(),a)}t.stream=s})(Dn||(Dn={}));function zu(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 ze=class t{static createFromProtobuf=e=>{let r=Dn.decode(e),n=ra(Hr(r.peerId)),o=(r.addresses??[]).map(i=>Tn(i.multiaddr)),s=r.seq;return new t({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=Vu;static CODEC=qu;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=Dn.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||!zu(this.multiaddrs,e.multiaddrs))}};function Zm(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 Oo(t){let e=Zm(t);if(e==null)throw new J(`Multiaddr ${t} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}function Hu(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 $u(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 Ba(t){switch(t.length){case Yt:return t.join(".");case Gt:{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 ju(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 Yu(t){let e="0x";for(let r of t)e+=(r>>4).toString(16)+(r&15).toString(16);return e}var Yt=4,Gt=16,UE=parseInt("0xFFFF",16),Wm=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Bn(t,e){e.length===Gt&&t.length===Yt&&Hu(e,0,11)&&(e=e.slice(12)),e.length===Yt&&t.length===Gt&&$u(t,Wm,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 Gu(t,e){if(typeof e=="string"&&(e=Cr(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 Oa(t){let[e,r]=t.split("/");if(!e||!r)throw new Error("Failed to parse given CIDR: "+t);let n=Yt,o=vo(e);if(o==null&&(n=Gt,o=So(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=La(s,8*n);return{network:Bn(o,i),mask:i}}function La(t,e){if(e!==8*Yt&&e!==8*Gt)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 On=class{constructor(e,r){if(r==null)({network:this.network,mask:this.mask}=Oa(e));else{let n=Cr(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=Cr(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=La(o,8*n.length);this.network=Bn(n,this.mask)}}contains(e){return Gu({network:this.network,mask:this.mask},e)}toString(){let e=ju(this.mask),r=e!==-1?String(e):Yu(this.mask);return Ba(this.network)+"/"+r}};function Zu(t,e){return new On(t).contains(e)}function Wu(t){try{let e=Oo(t);return e.type==="ip6"?Zu("2000::/3",e.host):!1}catch{return!1}}var el=_l(Ju(),1),n0=["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"],o0=n0.map(t=>new el.Netmask(t));function Ma(t){for(let e of o0)if(e.contains(t))return!0;return!1}function s0(t){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(t)}function i0(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 Ma(o)}function a0(t){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)}function c0(t){let e=t.split(":"),r=e[e.length-1];return Ma(r)}function f0(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 tl(t){if(_r(t))return Ma(t);if(s0(t))return i0(t);if(a0(t))return c0(t);if(Ao(t))return f0(t)}function rl(t){try{let e=Oo(t);switch(e.type){case"ip4":case"ip6":return tl(e.host)??!1;default:return e.host==="localhost"}}catch{return!1}}var W=t=>({match:e=>{let r=e[0];return r==null||r.code!==t||r.value!=null?!1:e.slice(1)}}),P=(t,e)=>({match:r=>{let n=r[0];return n?.code!==t||n.value==null||e!=null&&n.value!==e?!1:r.slice(1)}}),nl=t=>({match:e=>t.match(e)===!1?e:!1}),M=t=>({match:e=>{let r=t.match(e);return r===!1?e:r}}),Se=(...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}}),$=(...t)=>({match:e=>{for(let r of t){let n=r.match(e);if(n===!1)return!1;e=n}return e}});function X(...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 u0=P(421),y6=X(u0),Ro=P(54),Fo=P(55),No=P(56),Va=P(53),b6=X(Ro,M(P(421))),g6=X(Fo,M(P(421))),x6=X(No,M(P(421))),w6=X(Se(Va,No,Ro,Fo),M(P(421))),ol=$(P(4),M(P(43))),sl=$(M(P(42)),P(41),M(P(43))),qa=Se(ol,sl),Nr=Se(qa,Va,Ro,Fo,No),il=X(Se(qa,$(Se(Va,No,Ro,Fo),M(P(421))))),E6=X(ol),v6=X(sl),S6=X(qa),za=$(Nr,P(6)),Ln=$(Nr,P(273)),al=X($(za,M(P(421)))),A6=X(Ln),Ha=$(Ln,W(460),M(P(421))),ko=$(Ln,W(461),M(P(421))),l0=Se(Ha,ko),I6=X(Ha),C6=X(ko),Ka=Se(Nr,za,Ln,Ha,ko),cl=Se($(Ka,W(477),M(P(421)))),_6=X(cl),fl=Se($(Ka,W(478),M(P(421))),$(Ka,W(448),M(P(449)),W(477),M(P(421)))),T6=X(fl),ul=$(Ln,W(280),M(P(466)),M(P(466)),M(P(421))),D6=X(ul),ll=$(ko,W(465),M(P(466)),M(P(466)),M(P(421))),B6=X(ll),Po=Se(cl,fl,$(za,M(P(421))),$(l0,M(P(421))),$(Nr,M(P(421))),ul,ll,P(421)),O6=X(Po),d0=$(M(Po),W(290),nl(W(281)),M(P(421))),L6=X(d0),h0=Se($(Po,W(290),W(281),M(P(421))),$(Po,W(281),M(P(421))),$(W(281),M(P(421)))),P6=X(h0),p0=$(Nr,Se($(P(6,"80")),$(P(6),W(480)),W(480)),M(P(481)),M(P(421))),R6=X(p0),m0=$(Nr,Se($(P(6,"443")),$(P(6,"443"),W(480)),$(P(6),W(443)),$(P(6),W(448),W(480)),$(W(448),W(480)),W(448),W(443)),M(P(481)),M(P(421))),F6=X(m0),y0=Se($(P(777),M(P(421)))),N6=X(y0),b0=Se($(P(400),M(P(421)))),k6=X(b0);function kr(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var $a=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},dl=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function ja(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=e,a,c,u=new Promise((l,p)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){p(dl(i));return}if(i&&(c=()=>{p(dl(i))},i.addEventListener("abort",c,{once:!0})),t.then(l,p),r===Number.POSITIVE_INFINITY)return;let h=new $a;a=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(d){p(d)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?l():o instanceof Error?p(o):(h.message=o??`Promise timed out after ${r} milliseconds`,p(h))},r)}).finally(()=>{u.clear(),c&&i&&i.removeEventListener("abort",c)});return u.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},u}var g0=t=>{let e=t.addEventListener||t.on||t.addListener,r=t.removeEventListener||t.off||t.removeListener;if(!e||!r)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(t),removeListener:r.bind(t)}};function x0(t,e,r){let n,o=new Promise((s,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:f,removeListener:u}=g0(t),l=async(...h)=>{let d=r.multiArgs?h:h[0];if(r.filter)try{if(!await r.filter(d))return}catch(b){n(),i(b);return}c.push(d),r.count===c.length&&(n(),s(c))},p=(...h)=>{n(),i(r.rejectionMultiArgs?h:h[0])};n=()=>{for(let h of a)u(h,l);for(let h of r.rejectionEvents)a.includes(h)||u(h,p)};for(let h of a)f(h,l);for(let h of r.rejectionEvents)a.includes(h)||f(h,p);r.signal&&r.signal.addEventListener("abort",()=>{p(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(c)});if(o.cancel=n,typeof r.timeout=="number"){let s=ja(o,{milliseconds:r.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function hl(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=x0(t,e,r),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function pl(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 Wt=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function w0(t){return t.reason}async function Ya(t,e,r){if(e==null)return t;let n=r?.translateError??w0;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([t,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var v0=4194304,Uo=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Za=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Wa=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Xa=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function S0(t){return typeof t?.closeRead=="function"}function A0(t){return typeof t?.close=="function"}function Ga(t){return S0(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:A0(t)?t.status!=="open":!1}function I0(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function C0(t,e){let r=e?.maxBufferSize??v0,n=new ce,o,s=!1;if(!I0(t))throw new J("Argument should be a Stream or a Multiaddr");let i=u=>{if(n.append(u.data),n.byteLength>r){let l=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${l} > ${r}`))}o?.resolve()};t.addEventListener("message",i);let a=u=>{u.error!=null?o?.reject(u.error):o?.resolve()};t.addEventListener("close",a);let c=()=>{o?.resolve()};t.addEventListener("remoteCloseWrite",c);let f={readBuffer:n,async read(u){if(s===!0)throw new Uo("Stream was unwrapped");if(Ga(t)){if(n.byteLength===0&&u?.bytes==null)return null;if(u?.bytes!=null&&n.byteLength<u.bytes)throw t.log.error("closed after reading %d/%d bytes",n.byteLength,u.bytes),new Wt(`Unexpected EOF - stream closed after reading ${n.byteLength}/${u.bytes} bytes`)}let l=u?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=l){o.resolve();break}if(await Ya(o.promise,u?.signal),Ga(t)){if(n.byteLength===0&&u?.bytes==null)return null;break}o=Promise.withResolvers()}let p=u?.bytes??n.byteLength;if(n.byteLength<p){if(Ga(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,p),new Wt(`Unexpected EOF - stream closed while reading ${n.byteLength}/${p} bytes`);return f.read(u)}let h=n.sublist(0,p);return n.consume(p),h},async write(u,l){if(s===!0)throw new Uo("Stream was unwrapped");t.send(u)||await hl(t,"drain",{signal:l?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,t.removeEventListener("message",i),t.removeEventListener("close",a),t.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.unshift(n))),t}};return f}function _0(t,e={}){let r=C0(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=ft(e.maxDataLength));let n=e?.lengthDecoder??Sf,o=e?.lengthEncoder??pr;return{async read(i){let a=-1,c=new ce;for(;;){let u=await r.read({...i,bytes:1});if(u==null)break;c.append(u);try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new Za("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new Xa(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new Wa(`Message length too long - ${a} > ${e.maxDataLength}`);let f=await r.read({...i,bytes:a});if(f==null)throw t.log.error("tried to read %d bytes but the stream closed",a),new Wt(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(f.byteLength!==a)throw t.log.error("read %d/%d bytes before the stream closed",f.byteLength,a),new Wt(`Unexpected EOF - read ${f.byteLength}/${a} bytes before the stream closed`);return f},async write(i,a){await r.write(new ce(o(i.byteLength),i),a)},async writeV(i,a){let c=new ce(...i.flatMap(f=>[o(f.byteLength),f]));await r.write(c,a)},unwrap(){return r.unwrap()}}}function Ur(t,e){let r=_0(t,e),n={read:async(o,s)=>{let i=await r.read(s);return o.decode(i)},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 T0(t){return t[Symbol.asyncIterator]!=null}function D0(t){if(T0(t))return(async()=>{for await(let e of t);})();for(let e of t);}var ml=D0;var Mo=globalThis.CustomEvent??Event;async function*Qa(t,e={}){let r=e.concurrency??1/0;r<1&&(r=1/0);let n=e.ordered??!1,o=new EventTarget,s=[],i=kr(),a=kr(),c=!1,f,u=!1;o.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let d of t){if(s.length===r&&(i=kr(),await i.promise),u)break;let b={done:!1};s.push(b),d().then(m=>{b.done=!0,b.ok=!0,b.value=m,o.dispatchEvent(new Mo("task-complete"))},m=>{b.done=!0,b.err=m,o.dispatchEvent(new Mo("task-complete"))})}c=!0,o.dispatchEvent(new Mo("task-complete"))}catch(d){f=d,o.dispatchEvent(new Mo("task-complete"))}});function l(){return n?s[0]?.done:!!s.find(d=>d.done)}function*p(){for(;s.length>0&&s[0].done;){let d=s[0];if(s.shift(),d.ok)yield d.value;else throw u=!0,i.resolve(),d.err;i.resolve()}}function*h(){for(;l();)for(let d=0;d<s.length;d++)if(s[d].done){let b=s[d];if(s.splice(d,1),d--,b.ok)yield b.value;else throw u=!0,i.resolve(),b.err;i.resolve()}}for(;;){if(l()||(a=kr(),await a.promise),f!=null||(n?yield*p():yield*h(),f!=null))throw f;if(c&&s.length===0)break}}var yl="0.1.0";var bl="id/push",gl="1.0.0",xl="1.0.0";var Dt;(function(t){let e;t.codec=()=>(e==null&&(e=Ve((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:[]},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>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 Ze('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 Ze('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(u&7);break}}}return c},function*(s,i,a,c={}){let f={listenAddrs:0,protocols:0},u=i==null?s.len:s.pos+i;for(;s.pos<u;){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&&f.listenAddrs===c.limits.listenAddrs)throw new Ze('Streaming decode error - repeated field "listenAddrs" had too many elements');yield{field:`${a}.listenAddrs[]`,index:f.listenAddrs,value:s.bytes()},f.listenAddrs++;break}case 4:{yield{field:`${a}.observedAddr`,value:s.bytes()};break}case 3:{if(c.limits?.protocols!=null&&f.protocols===c.limits.protocols)throw new Ze('Streaming decode error - repeated field "protocols" had too many elements');yield{field:`${a}.protocols[]`,index:f.protocols,value:s.string()},f.protocols++;break}case 8:{yield{field:`${a}.signedPeerRecord`,value:s.bytes()};break}default:{s.skipType(l&7);break}}}})),e);function r(s){return Me(s,t.codec())}t.encode=r;function n(s,i){return Ue(s,t.codec(),i)}t.decode=n;function o(s,i){return Ke(s,t.codec(),i)}t.stream=o})(Dt||(Dt={}));var Ce={protocolPrefix:"ipfs",timeout:5e3,maxInboundStreams:1,maxOutboundStreams:1,maxObservedAddresses:10,maxMessageSize:8192,runOnConnectionOpen:!0,runOnSelfUpdate:!0,runOnLimitedConnection:!0,concurrency:32};function El(t){return t.bytes.length===0}function Ja(t){if(t!=null&&t.length>0)try{let e=Tn(t);if(!El(e))return e}catch{}}async function Ko(t,e,r,n,o){if(r("received identify from %p",n.remotePeer),o==null)throw new Oe("message was null or undefined");let s={},i=o.listenAddrs.map(Ja).filter(f=>f!=null);if(o.listenAddrs.length>0&&(s.addresses=i.map(f=>({isCertified:!1,multiaddr:f}))),o.protocols.length>0&&(s.protocols=o.protocols),o.publicKey!=null){let f=Sr(o.publicKey);if(!Cu(f).equals(n.remotePeer))throw new Oe("public key did not match remote PeerId");s.publicKey=f}let a;if(o.signedPeerRecord!=null){r.trace("received signedPeerRecord from %p",n.remotePeer);let f=o.signedPeerRecord,u=await Qe.openAndCertify(f,ze.DOMAIN),l=ze.createFromProtobuf(u.payload),p=go(u.publicKey.toCID());if(!l.peerId.equals(p))throw new Oe("signing key does not match PeerId in the PeerRecord");if(!n.remotePeer.equals(l.peerId))throw new Oe("signing key does not match remote PeerId");let h;try{h=await t.get(l.peerId)}catch(b){if(b.name!=="NotFoundError")throw b}if(h!=null&&(s.metadata=h.metadata,h.peerRecordEnvelope!=null)){let b=Qe.createFromProtobuf(h.peerRecordEnvelope),m=ze.createFromProtobuf(b.payload);m.seqNumber>=l.seqNumber&&(r("sequence number was lower or equal to existing sequence number - stored: %d received: %d",m.seqNumber,l.seqNumber),l=m,f=h.peerRecordEnvelope)}s.peerRecordEnvelope=f;let d=l.multiaddrs.filter(b=>!El(b));s.addresses=d.map(b=>({isCertified:!0,multiaddr:b})),a={seq:l.seqNumber,addresses:d}}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 f={};o.agentVersion!=null&&(f.AgentVersion=K(o.agentVersion)),o.protocolVersion!=null&&(f.ProtocolVersion=K(o.protocolVersion)),r.trace("merging %p metadata",n.remotePeer,f),await t.merge(n.remotePeer,{metadata:f})}let c={peerId:n.remotePeer,protocolVersion:o.protocolVersion,agentVersion:o.agentVersion,publicKey:o.publicKey,listenAddrs:i,observedAddr:o.observedAddr==null?void 0:Tn(o.observedAddr),protocols:o.protocols,signedPeerRecord:a,connection:n};return e.safeDispatchEvent("peer:identify",{detail:c}),c}function Vo(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 qo(t,e,r,n){let o=Ur(t,{maxDataLength:e}).pb(Dt),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 Mr=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??Ce.timeout,this.maxInboundStreams=r.maxInboundStreams??Ce.maxInboundStreams,this.maxOutboundStreams=r.maxOutboundStreams??Ce.maxOutboundStreams,this.maxMessageSize=r.maxMessageSize??Ce.maxMessageSize,this.maxObservedAddresses=r.maxObservedAddresses??Ce.maxObservedAddresses,this.runOnLimitedConnection=r.runOnLimitedConnection??Ce.runOnLimitedConnection,this.host={protocolVersion:`${r.protocolPrefix??Ce.protocolPrefix}/${yl}`,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:K(this.host.agentVersion),ProtocolVersion:K(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 zo=class extends Mr{connectionManager;concurrency;_push;constructor(e,r={}){super(e,{...r,protocol:`/${r.protocolPrefix??Ce.protocolPrefix}/${bl}/${xl}`,log:e.logger.forComponent("libp2p:identify-push")}),this.connectionManager=e.connectionManager,this.concurrency=r.concurrency??Ce.concurrency,this._push=pl(this.sendPushMessage.bind(this),r.debounce??1e3),(r.runOnSelfUpdate??Ce.runOnSelfUpdate)&&e.events.addEventListener("self:peer:update",n=>{this.push().catch(o=>{this.log.error("error pushing updates to peers - %e",o)})})}[kn]=["@libp2p/identify-push"];async push(){this._push()}async sendPushMessage(){if(this.isStarted())try{let e=this.components.addressManager.getAddresses().map(u=>u.decapsulateCode(421)),r=new ze({peerId:this.components.peerId,multiaddrs:e}),n=await Qe.seal(r,this.components.privateKey),o=this.components.registrar.getProtocols(),s=await this.components.peerStore.get(this.components.peerId),i=V(s.metadata.get("AgentVersion")??K(this.host.agentVersion)),a=V(s.metadata.get("ProtocolVersion")??K(this.host.protocolVersion)),c=this;async function*f(){for(let u of c.connectionManager.getConnections())(await c.components.peerStore.get(u.remotePeer)).protocols.includes(c.protocol)&&(yield async()=>{let p,h=AbortSignal.timeout(c.timeout);try{p=await u.newStream(c.protocol,{signal:h,runOnLimitedConnection:c.runOnLimitedConnection}),await Ur(p,{maxDataLength:c.maxMessageSize}).pb(Dt).write({listenAddrs:e.map(b=>b.bytes),signedPeerRecord:n.marshal(),protocols:o,agentVersion:i,protocolVersion:a},{signal:h}),await p.close({signal:h})}catch(d){p?.log.newScope("identify-push")?.error("could not push identify update to peer",d),p?.abort(d)}})}await ml(Qa(f(),{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 qo(e,this.maxMessageSize,o,n);await Ko(this.components.peerStore,this.components.events,n,r,Vo(s)),n.trace("handled push from %p",r.remotePeer)}};var Ho=class extends Mr{constructor(e,r={}){super(e,{...r,protocol:`/${r.protocolPrefix??Ce.protocolPrefix}/${"id"}/${gl}`,log:e.logger.forComponent("libp2p:identify")}),(r.runOnConnectionOpen??Ce.runOnConnectionOpen)&&e.events.addEventListener("connection:open",n=>{let o=n.detail;this.identify(o).catch(()=>{})})}[kn]=["@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 qo(n,this.maxMessageSize,r,o);return Vo(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 Oe("Public key was missing from identify message");let a=Sr(o),c=go(a.toCID());if(!e.remotePeer.equals(c))throw new Oe("Identified peer does not match the expected peer");if(this.components.peerId.equals(c))throw new Oe("Identified peer is our own peer id?");return this.maybeAddObservedAddress(i),this.log("completed for peer %p and protocols %o",c,s),Ko(this.components.peerStore,this.components.events,this.log,e,n)}maybeAddObservedAddress(e){let r=Ja(e);if(r==null||(this.log.trace("our observed address was %a",r),rl(r)))return;let n=r.getComponents();if((n[0].code===41||n[0].code===42&&n[1].code===41)&&!Wu(r)){this.log.trace("our observed address was IPv6 but not a global unicast address");return}al.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(u=>u.decapsulateCode(421)),a=s.peerRecordEnvelope;if(i.length>0&&a==null){let u=new ze({peerId:this.components.peerId,multiaddrs:i});a=(await Qe.seal(u,this.components.privateKey,{signal:o})).marshal().subarray()}let c=r.remoteAddr.bytes;il.matches(r.remoteAddr)||(c=void 0);let f=Ur(e).pb(Dt);n("send response"),await f.write({protocolVersion:this.host.protocolVersion,agentVersion:this.host.agentVersion,publicKey:$e(this.components.privateKey.publicKey),listenAddrs:i.map(u=>u.bytes),signedPeerRecord:a,observedAddr:c,protocols:s.protocols},{signal:o}),n("close write"),await f.unwrap().unwrap().close({signal:o})}};function R0(t={}){return e=>new Ho(e,t)}function F0(t={}){return e=>new zo(e,t)}return Tl(N0);})();
2
+ "use strict";var Libp2PIdentify=(()=>{var Jf=Object.create;var mn=Object.defineProperty;var eu=Object.getOwnPropertyDescriptor;var tu=Object.getOwnPropertyNames;var ru=Object.getPrototypeOf,nu=Object.prototype.hasOwnProperty;var Ao=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(r){throw e=0,r}},Ae=(t,e)=>{for(var r in e)mn(t,r,{get:e[r],enumerable:!0})},ia=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of tu(e))!nu.call(t,o)&&o!==r&&mn(t,o,{get:()=>e[o],enumerable:!(n=eu(e,o))||n.enumerable});return t};var ou=(t,e,r)=>(r=t!=null?Jf(ru(t)):{},ia(e||!t||!t.__esModule?mn(r,"default",{value:t,enumerable:!0}):r,t)),su=t=>ia(mn({},"__esModule",{value:!0}),t);var Ui=Ao(wr=>{"use strict";Object.defineProperty(wr,"__esModule",{value:!0});wr.Netmask4Impl=void 0;wr.ip2long=xr;wr.long2ip=et;function et(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 hh=48,ph=97,mh=65;function yh(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)-hh)>>>0;else if(r===16)if("a"<=t[o]&&t[o]<="f")e=e*r+(10+t.charCodeAt(o)-ph)>>>0;else if("A"<=t[o]&&t[o]<="F")e=e*r+(10+t.charCodeAt(o)-mh)>>>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 xr(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]=yh(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 ki=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=xr(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=(xr(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=et(this.netLong),this.mask=et(this.maskLong),this.hostmask=et(~this.maskLong),this.first=this.bitmask<=30?et(this.netLong+1):this.base,this.last=this.bitmask<=30?et(this.netLong+this.size-2):et(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?et(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):(xr(e)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(e=1){return new t(et(this.netLong+this.size*e),this.mask)}forEach(e){let r=xr(this.first),n=xr(this.last),o=0;for(;r<=n;)e(et(r),r,o),o++,r++}toString(){return this.base+"/"+this.bitmask}};wr.Netmask4Impl=ki});var Bf=Ao(Er=>{"use strict";Object.defineProperty(Er,"__esModule",{value:!0});Er.Netmask6Impl=void 0;Er.ip6bigint=Mi;Er.bigint2ip6=Vt;var bh=Ui(),Ki=(1n<<128n)-1n;function Mi(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,bh.ip2long)(n),s=t.substring(0,r+1)+"0:0";return Tf(s)&~0xffffffffn|BigInt(o)}return Tf(t)}function Tf(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(":"),f=8-i.length-a.length;if(f<0)throw new Error("Invalid IPv6: too many groups");r=[...i,...Array(f).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>Ki)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(f=>f.toString(16)),a=e.slice(r+n).map(f=>f.toString(16));return i.join(":")+"::"+a.join(":")}else return e.map(i=>i.toString(16)).join(":")}var Vi=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=Ki>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=Mi(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&Ki),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):(Mi(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}};Er.Netmask6Impl=Vi});var Df=Ao(St=>{"use strict";Object.defineProperty(St,"__esModule",{value:!0});St.long2ip=St.ip2long=St.Netmask=void 0;var uo=Ui();Object.defineProperty(St,"ip2long",{enumerable:!0,get:function(){return uo.ip2long}});Object.defineProperty(St,"long2ip",{enumerable:!0,get:function(){return uo.long2ip}});var gh=Bf(),qi=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 gh.Netmask6Impl(e,r):this._impl=new uo.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 uo.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=qi});var Qh={};Ae(Qh,{identify:()=>Wh,identifyPush:()=>Xh});var Q=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},zt=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var yn=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},bn=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Pe=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 Io=Symbol.for("@libp2p/peer-id");var gn=Symbol.for("@libp2p/service-capabilities");var Do={};Ae(Do,{base58btc:()=>ne,base58flickr:()=>hu});var Cp=new Uint8Array(0);function ca(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 De(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return _t(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return _t(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function fa(t){let e=new Uint8Array(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}var aa=4096;function ua(t){let e=t.length;if(e<=aa)return String.fromCharCode.apply(String,t);let r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.subarray(n,n+=aa));return r}function iu(t){return t?.buffer instanceof ArrayBuffer}function _t(t){return iu(t)?t:t.slice()}function au(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 f=i.toLowerCase().charCodeAt(0),c=i.toUpperCase().charCodeAt(0);f!==a&&(n[f]=s),c!==a&&(n[c]=s)}}var u=t.length,l=t.charAt(0),h=Math.log(u)/Math.log(256),d=Math.log(256)/Math.log(u);function E(y){if(y instanceof Uint8Array||(ArrayBuffer.isView(y)?y=new Uint8Array(y.buffer,y.byteOffset,y.byteLength):Array.isArray(y)&&(y=Uint8Array.from(y))),!(y instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(y.length===0)return"";for(var v=0,I=0,P=0,B=y.length;P!==B&&y[P]===0;)P++,v++;for(var N=(B-P)*d+1>>>0,O=new Uint8Array(N);P!==B;){for(var _=y[P],k=0,U=N-1;(_!==0||k<I)&&U!==-1;U--,k++)_+=256*O[U]>>>0,O[U]=_%u>>>0,_=_/u>>>0;if(_!==0)throw new Error("Non-zero carry");I=k,P++}for(var F=N-I;F!==N&&O[F]===0;)F++;for(var p=l.repeat(v);F<N;++F)p+=t.charAt(O[F]);return p}function b(y){if(typeof y!="string")throw new TypeError("Expected String");if(y.length===0)return new Uint8Array;var v=0;if(y[v]!==" "){for(var I=0,P=0;y[v]===l;)I++,v++;for(var B=(y.length-v)*h+1>>>0,N=new Uint8Array(B);y[v];){var O=n[y.charCodeAt(v)];if(O===255)return;for(var _=0,k=B-1;(O!==0||_<P)&&k!==-1;k--,_++)O+=u*N[k]>>>0,N[k]=O%256>>>0,O=O/256>>>0;if(O!==0)throw new Error("Non-zero carry");P=_,v++}if(y[v]!==" "){for(var U=B-P;U!==B&&N[U]===0;)U++;for(var F=new Uint8Array(I+(B-U)),p=I;U!==B;)F[p++]=N[U++];return F}}}function m(y){var v=b(y);if(v)return v;throw new Error(`Non-${e} character`)}return{encode:E,decodeUnsafe:b,decode:m}}var cu=au,fu=cu,da=fu;var _o=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 ha(this,e)}},To=class{decoders;constructor(e){this.decoders=e}or(e){return ha(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 ha(t,e){return new To({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Bo=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 _o(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 $t({name:t,prefix:e,encode:r,decode:n}){return new Bo(t,e,r,n)}function ut({name:t,prefix:e,alphabet:r,caseInsensitive:n=!1}){let{encode:o,decode:s}=da(r,t,n);return $t({prefix:e,name:t,encode:o,decode:i=>De(s(i))})}function uu(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,f=0;for(let c=0;c<o;++c){let u=e[t[c]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|u,i+=r,i>=8&&(i-=8,s[f++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function lu(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let f=0;f<t.length;++f)for(a=a<<8|t[f],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 du(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 ee({name:t,prefix:e,bitsPerChar:r,alphabet:n,caseInsensitive:o=!1}){let s=du(n,o);return $t({prefix:e,name:t,encode(i){return lu(i,n,r)},decode(i){return uu(i,s,r,t)}})}var ne=ut({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),hu=ut({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Oo={};Ae(Oo,{base32:()=>lt,base32hex:()=>bu,base32hexpad:()=>xu,base32hexpadupper:()=>wu,base32hexupper:()=>gu,base32pad:()=>mu,base32padupper:()=>yu,base32upper:()=>pu,base32z:()=>Eu});var lt=ee({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),pu=ee({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),mu=ee({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),yu=ee({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),bu=ee({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),gu=ee({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),xu=ee({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),wu=ee({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),Eu=ee({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Po={};Ae(Po,{base36:()=>Cr,base36upper:()=>vu});var Cr=ut({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),vu=ut({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var Su=ya,pa=128,Au=127,Iu=~Au,_u=Math.pow(2,31);function ya(t,e,r){e=e||[],r=r||0;for(var n=r;t>=_u;)e[r++]=t&255|pa,t/=128;for(;t&Iu;)e[r++]=t&255|pa,t>>>=7;return e[r]=t|0,ya.bytes=r-n+1,e}var Cu=Lo,Tu=128,ma=127;function Lo(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw Lo.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&ma)<<o:(i&ma)*Math.pow(2,o),o+=7}while(i>=Tu);return Lo.bytes=s-n,r}var Bu=Math.pow(2,7),Du=Math.pow(2,14),Ou=Math.pow(2,21),Pu=Math.pow(2,28),Lu=Math.pow(2,35),Ru=Math.pow(2,42),Fu=Math.pow(2,49),Nu=Math.pow(2,56),ku=Math.pow(2,63),Uu=function(t){return t<Bu?1:t<Du?2:t<Ou?3:t<Pu?4:t<Lu?5:t<Ru?6:t<Fu?7:t<Nu?8:t<ku?9:10},Ku={encode:Su,decode:Cu,encodingLength:Uu},Mu=Ku,Tr=Mu;function Br(t,e=0){return[Tr.decode(t,e),Tr.decode.bytes]}function jt(t,e,r=0){return Tr.encode(t,e,r),e}function Yt(t){return Tr.encodingLength(t)}function $e(t,e){let r=e.byteLength,n=Yt(t),o=n+Yt(r),s=new Uint8Array(o+r);return jt(t,s,0),jt(r,s,n),s.set(e,o),new Zt(t,r,e,s)}function Dr(t){let e=De(t),[r,n]=Br(e),[o,s]=Br(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Zt(r,o,i,e)}function ba(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&ca(t.bytes,r.bytes)}}var Zt=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=_t(n),this.bytes=_t(o)}};function ga(t,e){let{bytes:r,version:n}=t;return n===0?qu(r,Ro(t),e??ne.encoder):Hu(r,Ro(t),e??lt.encoder)}var xa=new WeakMap;function Ro(t){let e=xa.get(t);if(e==null){let r=new Map;return xa.set(t,r),r}return e}var le=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=_t(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!==Or)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==zu)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=$e(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&&ba(e.multihash,n.multihash)}toString(e){return ga(this,e)}toJSON(){return{"/":ga(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??wa(n,o,s.bytes))}else if(r[$u]===!0){let{version:n,multihash:o,code:s}=r,i=Dr(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!==Or)throw new Error(`Version 0 CID must use dag-pb (code: ${Or}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=wa(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Or,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=De(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 Zt(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]=Br(e.subarray(r));return r+=h,l},o=n(),s=Or;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(),f=n(),c=r+f,u=c-i;return{version:o,codec:s,multihashCode:a,digestSize:f,multihashSize:u,size:c}}static parse(e,r){let[n,o]=Vu(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 Ro(s).set(n,e),s}};function Vu(t,e){switch(t[0]){case"Q":{let r=e??ne;return[ne.prefix,r.decode(`${ne.prefix}${t}`)]}case ne.prefix:{let r=e??ne;return[ne.prefix,r.decode(t)]}case lt.prefix:{let r=e??lt;return[lt.prefix,r.decode(t)]}case Cr.prefix:{let r=e??Cr;return[Cr.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 qu(t,e,r){let{prefix:n}=r;if(n!==ne.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 Hu(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 Or=112,zu=18;function wa(t,e,r){let n=Yt(t),o=n+Yt(e),s=new Uint8Array(o+r.byteLength);return jt(t,s,0),jt(e,s,n),s.set(r,o),s}var $u=Symbol.for("@ipld/js-cid/CID");var Fo={};Ae(Fo,{identity:()=>Le});var Ea=0,ju="identity",va=De;function Yu(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 $e(Ea,va(t))}var Le={code:Ea,name:ju,encode:va,digest:Yu};function ae(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 Zu(t){return t.buffer instanceof ArrayBuffer}function ve(t){return Zu(t)?t:t.slice()}async function Sa(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,ve(e),ve(r.subarray()));return n?.signal?.throwIfAborted(),s}function de(t=0){return new Uint8Array(t)}function ge(t=0){return new Uint8Array(t)}function Gu(t){return t?.buffer instanceof ArrayBuffer}function No(t){if(Gu(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function je(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=ge(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return No(r)}var Ia=Symbol.for("@achingbrain/uint8arraylist");function Aa(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 wn(t){return!!t?.[Ia]}var se=class t{bufs;length;[Ia]=!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(wn(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(wn(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=Aa(this.bufs,e);return r.buf[r.index]}set(e,r){let n=Aa(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(wn(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 je(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:je(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,f=a+i.byteLength;if(o=f,e>=f)continue;let c=e>=a&&e<f,u=r>a&&r<=f;if(c&&u){if(e===a&&r===f){n.push(i);break}let l=e-a;n.push(i.subarray(l,l+(r-e)));break}if(c){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(u){if(r===f){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(!wn(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,f=this.byteLength-n.byteLength,c=n.byteLength-1,u;for(let l=r;l<=f;l+=u){u=0;for(let h=c;h>=0;h--){let d=this.get(l+h);if(n[h]!==d){u=Math.max(1,h-a[d]);break}}if(u===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=ge(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=de(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=de(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=de(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=ge(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=de(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=de(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=de(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=de(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=de(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(!ae(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 ko={};Ae(ko,{base10:()=>Wu});var Wu=ut({prefix:"9",name:"base10",alphabet:"0123456789"});var Uo={};Ae(Uo,{base16:()=>Xu,base16upper:()=>Qu});var Xu=ee({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Qu=ee({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var Ko={};Ae(Ko,{base2:()=>Ju});var Ju=ee({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Mo={};Ae(Mo,{base256emoji:()=>ol});var _a=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}"),el=_a.reduce((t,e,r)=>(t[r]=e,t),[]),tl=_a.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function rl(t){return t.reduce((e,r)=>(e+=el[r],e),"")}function nl(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=tl[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var ol=$t({prefix:"\u{1F680}",name:"base256emoji",encode:rl,decode:nl});var qo={};Ae(qo,{base64:()=>sl,base64pad:()=>il,base64url:()=>Vo,base64urlpad:()=>al});var sl=ee({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),il=ee({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Vo=ee({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),al=ee({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ho={};Ae(Ho,{base8:()=>cl});var cl=ee({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var zo={};Ae(zo,{identity:()=>fl});var fl=$t({prefix:"\0",name:"identity",encode:t=>ua(De(t)),decode:t=>De(fa(t))});var dm=new TextEncoder,hm=new TextDecoder;var Yo={};Ae(Yo,{sha256:()=>Pr,sha512:()=>hl});var dl=20;function jo({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new $o(t,e,r,n,o)}var $o=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??dl,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?Ca(n,this.code,r?.truncate):n.then(o=>Ca(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ca(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 $e(e,t)}function Ba(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Pr=jo({name:"sha2-256",code:18,encode:Ba("SHA-256")}),hl=jo({name:"sha2-512",code:19,encode:Ba("SHA-512")});var Lr={...zo,...Ko,...Ho,...ko,...Uo,...Oo,...Po,...Do,...qo,...Mo},Im={...Yo,...Fo};function Oa(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Da=Oa("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Zo=Oa("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=ge(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),pl={utf8:Da,"utf-8":Da,hex:Lr.base16,latin1:Zo,ascii:Zo,binary:Zo,...Lr},En=pl;function K(t,e="utf8"){let r=En[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function q(t,e="utf8"){let r=En[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var ml=parseInt("11111",2),Go=parseInt("10000000",2),yl=parseInt("01111111",2),Pa={0:Rr,1:Rr,2:bl,3:wl,4:El,5:xl,6:gl,16:Rr,22:Rr,48:Rr};function tt(t,e={offset:0}){let r=t[e.offset]&ml;if(e.offset++,Pa[r]!=null)return Pa[r](t,e);throw new Error("No decoder for tag "+r)}function Fr(t,e){let r=0;if((t[e.offset]&Go)===Go){let n=t[e.offset]&yl,o="0x";e.offset++;for(let s=0;s<n;s++,e.offset++)o+=t[e.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=t[e.offset],e.offset++;return r}function Rr(t,e){Fr(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=tt(t,e);if(n===null)break;r.push(n)}return r}function bl(t,e){let r=Fr(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 gl(t,e){let r=Fr(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}`,f=[];for(;e.offset<n;){let c=t[e.offset];if(e.offset++,f.push(c&127),c<128){f.reverse();let u=0;for(let l=0;l<f.length;l++)u+=f[l]<<l*7;a+=`.${u}`,f=[]}}return a}function xl(t,e){return e.offset++,null}function wl(t,e){let r=Fr(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 El(t,e){let r=Fr(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function vl(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new se;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function Wo(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=vl(t.byteLength);return new se(Uint8Array.from([e.byteLength|Go]),e)}function Ie(t){let e=new se,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new se(Uint8Array.from([2]),Wo(e),e)}function vn(t){let e=Uint8Array.from([0]),r=new se(e,t);return new se(Uint8Array.from([3]),Wo(r),r)}function dt(t,e=48){let r=new se;for(let n of t)r.append(n);return new se(Uint8Array.from([e]),Wo(r),r)}var Sl=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Al=Uint8Array.from([6,5,43,129,4,0,34]),Il=Uint8Array.from([6,5,43,129,4,0,35]),_l={ext:!0,kty:"EC",crv:"P-256"},Cl={ext:!0,kty:"EC",crv:"P-384"},Tl={ext:!0,kty:"EC",crv:"P-521"},Xo=32,Qo=48,Jo=66;function es(t){let e=tt(t);return La(e)}function La(t){let e=t[1][1][0],r=1,n,o;if(e.byteLength===Xo*2+1)return n=q(e.subarray(r,r+Xo),"base64url"),o=q(e.subarray(r+Xo),"base64url"),new Gt({..._l,key_ops:["verify"],x:n,y:o});if(e.byteLength===Qo*2+1)return n=q(e.subarray(r,r+Qo),"base64url"),o=q(e.subarray(r+Qo),"base64url"),new Gt({...Cl,key_ops:["verify"],x:n,y:o});if(e.byteLength===Jo*2+1)return n=q(e.subarray(r,r+Jo),"base64url"),o=q(e.subarray(r+Jo),"base64url"),new Gt({...Tl,key_ops:["verify"],x:n,y:o});throw new Q(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Ra(t){return dt([Ie(Uint8Array.from([1])),dt([Bl(t.crv)],160),dt([vn(new se(Uint8Array.from([4]),K(t.x??"","base64url"),K(t.y??"","base64url")))],161)]).subarray()}function Bl(t){if(t==="P-256")return Sl;if(t==="P-384")return Al;if(t==="P-521")return Il;throw new Q(`Invalid curve ${t}`)}var Gt=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=Ra(this.jwk)),this._raw}toMultihash(){return Le.digest(Ye(this))}toCID(){return le.createV1(114,this.toMultihash())}toString(){return ne.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ae(this.raw,e.raw)}async verify(e,r,n){return Sa(this.jwk,r,e,n)}};function ts(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}function ht(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(`${r}expected number, got ${typeof t}`)}if(!Number.isSafeInteger(t)||t<0){let r=e&&`"${e}" `;throw new RangeError(`${r}expected integer >= 0, got ${t}`)}}function Te(t,e,r=""){let n=ts(t),o=t?.length,s=e!==void 0;if(!n||s&&o!==e){let i=r&&`"${r}" `,a=s?` of length ${e}`:"",f=n?`length=${o}`:`type=${typeof t}`,c=i+"expected Uint8Array"+a+", got "+f;throw n?new RangeError(c):new TypeError(c)}return t}function Sn(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(ht(t.outputLen),ht(t.blockLen),t.outputLen<1)throw new Error('"outputLen" must be >= 1');if(t.blockLen<1)throw new Error('"blockLen" must be >= 1')}function Wt(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function An(t,e){Te(t,void 0,"digestInto() output");let r=e.outputLen;if(t.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function nt(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function In(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Re(t,e){return t<<32-e|t>>>e}var Na=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Dl=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function _n(t){if(Te(t),Na)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=Dl[t[r]];return e}var rt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Fa(t){if(t>=rt._0&&t<=rt._9)return t-rt._0;if(t>=rt.A&&t<=rt.F)return t-(rt.A-10);if(t>=rt.a&&t<=rt.f)return t-(rt.a-10)}function Nr(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(Na)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=Fa(t.charCodeAt(s)),a=Fa(t.charCodeAt(s+1));if(i===void 0||a===void 0){let f=t[s]+t[s+1];throw new RangeError('hex string expected, got non-hex character "'+f+'" at index '+s)}n[o]=i*16+a}return n}function rs(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];Te(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 ns(t,e={}){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 ka(t=32){ht(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 os=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function Ua(t,e,r){return t&e^~t&r}function Ka(t,e,r){return t&e^t&r^e&r}var kr=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=In(this.buffer)}update(e){Wt(this),Te(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let f=In(e);for(;o<=s-i;i+=o)this.process(f,i);continue}n.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Wt(this),An(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,nt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=In(e),f=this.outputLen;if(f%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let c=f/4,u=this.get();if(c>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<c;l++)a.setUint32(4*l,u[l],s)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return e.destroyed=i,e.finished=s,e.length=o,e.pos=a,o%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},ot=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var me=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Cn=BigInt(4294967295),Ma=BigInt(32);function Ol(t,e=!1){return e?{h:Number(t&Cn),l:Number(t>>Ma&Cn)}:{h:Number(t>>Ma&Cn)|0,l:Number(t&Cn)|0}}function Va(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}=Ol(t[s],e);[n[s],o[s]]=[i,a]}return[n,o]}var ss=(t,e,r)=>t>>>r,is=(t,e,r)=>t<<32-r|e>>>r,Tt=(t,e,r)=>t>>>r|e<<32-r,Bt=(t,e,r)=>t<<32-r|e>>>r,Ur=(t,e,r)=>t<<64-r|e>>>r-32,Kr=(t,e,r)=>t>>>r-32|e<<64-r;function Ze(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var qa=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Ha=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,za=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),$a=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,ja=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Ya=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0;var Ll=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),as=class extends kr{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:r,C:n,D:o,E:s,F:i,G:a,H:f}=this;return[e,r,n,o,s,i,a,f]}set(e,r,n,o,s,i,a,f){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=f|0}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],d=pt[l-2],E=Re(h,7)^Re(h,18)^h>>>3,b=Re(d,17)^Re(d,19)^d>>>10;pt[l]=b+pt[l-7]+E+pt[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:f,G:c,H:u}=this;for(let l=0;l<64;l++){let h=Re(a,6)^Re(a,11)^Re(a,25),d=u+h+Ua(a,f,c)+Ll[l]+pt[l]|0,b=(Re(n,2)^Re(n,13)^Re(n,22))+Ka(n,o,s)|0;u=c,c=f,f=a,a=i+d|0,i=s,s=o,o=n,n=d+b|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,f=f+this.F|0,c=c+this.G|0,u=u+this.H|0,this.set(n,o,s,i,a,f,c,u)}roundClean(){nt(pt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),nt(this.buffer)}},cs=class extends as{A=ot[0]|0;B=ot[1]|0;C=ot[2]|0;D=ot[3]|0;E=ot[4]|0;F=ot[5]|0;G=ot[6]|0;H=ot[7]|0;constructor(){super(32)}};var Za=Va(["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))),Rl=Za[0],Fl=Za[1],mt=new Uint32Array(80),yt=new Uint32Array(80),fs=class extends kr{constructor(e){super(128,e,16,!1)}get(){let{Ah:e,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:f,Eh:c,El:u,Fh:l,Fl:h,Gh:d,Gl:E,Hh:b,Hl:m}=this;return[e,r,n,o,s,i,a,f,c,u,l,h,d,E,b,m]}set(e,r,n,o,s,i,a,f,c,u,l,h,d,E,b,m){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=f|0,this.Eh=c|0,this.El=u|0,this.Fh=l|0,this.Fl=h|0,this.Gh=d|0,this.Gl=E|0,this.Hh=b|0,this.Hl=m|0}process(e,r){for(let I=0;I<16;I++,r+=4)mt[I]=e.getUint32(r),yt[I]=e.getUint32(r+=4);for(let I=16;I<80;I++){let P=mt[I-15]|0,B=yt[I-15]|0,N=Tt(P,B,1)^Tt(P,B,8)^ss(P,B,7),O=Bt(P,B,1)^Bt(P,B,8)^is(P,B,7),_=mt[I-2]|0,k=yt[I-2]|0,U=Tt(_,k,19)^Ur(_,k,61)^ss(_,k,6),F=Bt(_,k,19)^Kr(_,k,61)^is(_,k,6),p=za(O,F,yt[I-7],yt[I-16]),g=$a(p,N,U,mt[I-7],mt[I-16]);mt[I]=g|0,yt[I]=p|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:f,Dh:c,Dl:u,Eh:l,El:h,Fh:d,Fl:E,Gh:b,Gl:m,Hh:y,Hl:v}=this;for(let I=0;I<80;I++){let P=Tt(l,h,14)^Tt(l,h,18)^Ur(l,h,41),B=Bt(l,h,14)^Bt(l,h,18)^Kr(l,h,41),N=l&d^~l&b,O=h&E^~h&m,_=ja(v,B,O,Fl[I],yt[I]),k=Ya(_,y,P,N,Rl[I],mt[I]),U=_|0,F=Tt(n,o,28)^Ur(n,o,34)^Ur(n,o,39),p=Bt(n,o,28)^Kr(n,o,34)^Kr(n,o,39),g=n&s^n&a^s&a,S=o&i^o&f^i&f;y=b|0,v=m|0,b=d|0,m=E|0,d=l|0,E=h|0,{h:l,l:h}=Ze(c|0,u|0,k|0,U|0),c=a|0,u=f|0,a=s|0,f=i|0,s=n|0,i=o|0;let w=qa(U,p,S);n=Ha(w,k,F,g),o=w|0}({h:n,l:o}=Ze(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Ze(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:f}=Ze(this.Ch|0,this.Cl|0,a|0,f|0),{h:c,l:u}=Ze(this.Dh|0,this.Dl|0,c|0,u|0),{h:l,l:h}=Ze(this.Eh|0,this.El|0,l|0,h|0),{h:d,l:E}=Ze(this.Fh|0,this.Fl|0,d|0,E|0),{h:b,l:m}=Ze(this.Gh|0,this.Gl|0,b|0,m|0),{h:y,l:v}=Ze(this.Hh|0,this.Hl|0,y|0,v|0),this.set(n,o,s,i,a,f,c,u,l,h,d,E,b,m,y,v)}roundClean(){nt(mt,yt)}destroy(){this.destroyed=!0,nt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},us=class extends fs{Ah=me[0]|0;Al=me[1]|0;Bh=me[2]|0;Bl=me[3]|0;Ch=me[4]|0;Cl=me[5]|0;Dh=me[6]|0;Dl=me[7]|0;Eh=me[8]|0;El=me[9]|0;Fh=me[10]|0;Fl=me[11]|0;Gh=me[12]|0;Gl=me[13]|0;Hh=me[14]|0;Hl=me[15]|0;constructor(){super(64)}};var Xt=ns(()=>new cs,os(1));var Tn=ns(()=>new us,os(3));var z=(t,e,r)=>Te(t,e,r),ds=ht,Qt=_n,ce=(...t)=>rs(...t),Jt=t=>Nr(t),Dt=ts,Mr=t=>ka(t),Dn=BigInt(0),ls=BigInt(1);function Fe(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}" `;throw new TypeError(r+"expected boolean, got type="+typeof t)}return t}function On(t){if(typeof t=="bigint"){if(!Bn(t))throw new RangeError("positive bigint expected, got "+t)}else ds(t);return t}function Ne(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 Vr(t){let e=On(t).toString(16);return e.length&1?"0"+e:e}function Ga(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?Dn:BigInt("0x"+t)}function Ot(t){return Ga(_n(t))}function Ge(t){return Ga(_n(qr(Te(t)).reverse()))}function Pn(t,e){if(ht(e),e===0)throw new RangeError("zero length");t=On(t);let r=t.toString(16);if(r.length>e*2)throw new RangeError("number too large");return Nr(r.padStart(e*2,"0"))}function hs(t,e){return Pn(t,e).reverse()}function Wa(t,e){if(t=z(t),e=z(e),t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function qr(t){return Uint8Array.from(z(t))}function Ln(t){if(typeof t!="string")throw new TypeError("ascii string expected, got "+typeof t);return Uint8Array.from(t,(e,r)=>{let n=e.charCodeAt(0);if(e.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${t[r]}" with code ${n} at position ${r}`);return n})}var Bn=t=>typeof t=="bigint"&&Dn<=t;function Nl(t,e,r){return Bn(t)&&Bn(e)&&Bn(r)&&e<=t&&t<r}function er(t,e,r,n){if(!Nl(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function tr(t){if(t<Dn)throw new Error("expected non-negative bigint, got "+t);let e;for(e=0;t>Dn;t>>=ls,e+=1);return e}var Hr=t=>(ls<<BigInt(t))-ls;function Xa(t,e,r){if(ht(t,"hashLen"),ht(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=m=>new Uint8Array(m),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,f=n(t),c=n(t),u=0,l=()=>{f.fill(1),c.fill(0),u=0},h=(...m)=>r(c,ce(f,...m)),d=(m=o)=>{c=h(s,m),f=h(),m.length!==0&&(c=h(i,m),f=h())},E=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let m=0,y=[];for(;m<e;){f=h();let v=f.slice();y.push(v),m+=f.length}return ce(...y)};return(m,y)=>{l(),d(m);let v;for(;(v=y(E()))===void 0;)d();return l(),v}}function ke(t,e={},r={}){if(Object.prototype.toString.call(t)!=="[object Object]")throw new TypeError("expected valid options object");function n(s,i,a){if(!a&&i!=="function"&&!Object.hasOwn(t,s))throw new TypeError(`param "${s}" is invalid: expected own property`);let f=t[s];if(a&&f===void 0)return;let c=typeof f;if(c!==i||f===null)throw new TypeError(`param "${s}" is invalid: expected ${i}, got ${c}`)}let o=(s,i)=>Object.entries(s).forEach(([a,f])=>n(a,f,i));o(e,!1),o(r,!0)}var ps=()=>{throw new Error("not implemented")};var ye=BigInt(0),te=BigInt(1),Pt=BigInt(2),tc=BigInt(3),rc=BigInt(4),nc=BigInt(5),kl=BigInt(7),oc=BigInt(8),Ul=BigInt(9),sc=BigInt(16);function oe(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 X(t,e,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<=ye)throw new Error("invert: expected positive modulus, got "+e);let r=oe(t,e),n=e,o=ye,s=te,i=te,a=ye;for(;r!==ye;){let c=n/r,u=n-r*c,l=o-i*c,h=s-a*c;n=r,r=u,o=i,s=a,i=l,a=h}if(n!==te)throw new Error("invert: does not exist");return oe(o,e)}function ms(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function ic(t,e){let r=t,n=(r.ORDER+te)/rc,o=r.pow(e,n);return ms(r,o,e),o}function Kl(t,e){let r=t,n=(r.ORDER-nc)/oc,o=r.mul(e,Pt),s=r.pow(o,n),i=r.mul(e,s),a=r.mul(r.mul(i,Pt),s),f=r.mul(i,r.sub(a,r.ONE));return ms(r,f,e),f}function Ml(t){let e=rr(t),r=ac(t),n=r(e,e.neg(e.ONE)),o=r(e,n),s=r(e,e.neg(n)),i=(t+kl)/sc;return((a,f)=>{let c=a,u=c.pow(f,i),l=c.mul(u,n),h=c.mul(u,o),d=c.mul(u,s),E=c.eql(c.sqr(l),f),b=c.eql(c.sqr(h),f);u=c.cmov(u,l,E),l=c.cmov(d,h,b);let m=c.eql(c.sqr(l),f),y=c.cmov(u,l,m);return ms(c,y,f),y})}function ac(t){if(t<tc)throw new Error("sqrt is not defined for small field");let e=t-te,r=0;for(;e%Pt===ye;)e/=Pt,r++;let n=Pt,o=rr(t);for(;Ja(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return ic;let s=o.pow(n,e),i=(e+te)/Pt;return function(f,c){let u=f;if(u.is0(c))return c;if(Ja(u,c)!==1)throw new Error("Cannot find square root");let l=r,h=u.mul(u.ONE,s),d=u.pow(c,e),E=u.pow(c,i);for(;!u.eql(d,u.ONE);){if(u.is0(d))return u.ZERO;let b=1,m=u.sqr(d);for(;!u.eql(m,u.ONE);)if(b++,m=u.sqr(m),b===l)throw new Error("Cannot find square root");let y=te<<BigInt(l-b-1),v=u.pow(h,y);l=b,h=u.sqr(v),d=u.mul(d,h),E=u.mul(E,v)}return E}}function Vl(t){return t%rc===tc?ic:t%oc===nc?Kl:t%sc===Ul?Ml(t):ac(t)}var st=(t,e)=>(oe(t,e)&te)===te,ql=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ys(t){let e={ORDER:"bigint",BYTES:"number",BITS:"number"},r=ql.reduce((n,o)=>(n[o]="function",n),e);if(ke(t,r),Ne(t.BYTES,"BYTES"),Ne(t.BITS,"BITS"),t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=te)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function Hl(t,e,r){let n=t;if(r<ye)throw new Error("invalid exponent, negatives unsupported");if(r===ye)return n.ONE;if(r===te)return e;let o=n.ONE,s=e;for(;r>ye;)r&te&&(o=n.mul(o,s)),s=n.sqr(s),r>>=te;return o}function zr(t,e,r=!1){let n=t,o=new Array(e.length).fill(r?n.ZERO:void 0),s=e.reduce((a,f,c)=>n.is0(f)?a:(o[c]=a,n.mul(a,f)),n.ONE),i=n.inv(s);return e.reduceRight((a,f,c)=>n.is0(f)?a:(o[c]=n.mul(a,o[c]),n.mul(a,f)),i),o}function Ja(t,e){let r=t,n=(r.ORDER-te)/Pt,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 zl(t,e){if(e!==void 0&&ds(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=tr(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected bit length (${r}) >= n.length (${e})`);let n=e!==void 0?e:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var ec=new WeakMap,Rn=class{ORDER;BITS;BYTES;isLE;ZERO=ye;ONE=te;_lengths;_mod;constructor(e,r={}){if(e<=te)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}=zl(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 oe(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&te)===te}neg(e){return oe(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return oe(e*e,this.ORDER)}add(e,r){return oe(e+r,this.ORDER)}sub(e,r){return oe(e-r,this.ORDER)}mul(e,r){return oe(e*r,this.ORDER)}pow(e,r){return Hl(this,e,r)}div(e,r){return oe(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=ec.get(this);return r||ec.set(this,r=Vl(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?hs(e,this.BYTES):Pn(e,this.BYTES)}fromBytes(e,r=!1){z(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 c=new Uint8Array(o);c.set(e,s?0:c.length-e.length),e=c}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let f=s?Ge(e):Ot(e);if(a&&(f=oe(f,i)),!r&&!this.isValid(f))throw new Error("invalid field element: outside of range 0..ORDER");return f}invertBatch(e){return zr(this,e)}cmov(e,r,n){return Fe(n,"condition"),n?r:e}};Object.freeze(Rn.prototype);function rr(t,e={}){return new Rn(t,e)}function cc(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=te)throw new Error("field order must be greater than 1");let e=tr(t-te);return Math.ceil(e/8)}function bs(t){let e=cc(t);return e+Math.ceil(e/2)}function gs(t,e,r=!1){z(t);let n=t.length,o=cc(e),s=Math.max(bs(e),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Ge(t):Ot(t),a=oe(i,e-te)+te;return r?hs(a,o):Pn(a,o)}var nr=BigInt(0),Lt=BigInt(1);function $r(t,e){let r=e.negate();return t?r:e}function Rt(t,e){let r=zr(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function dc(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function xs(t,e){dc(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),o=2**t,s=Hr(t),i=BigInt(t);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function fc(t,e,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(t&o),f=t>>i;a>n&&(a-=s,f+=Lt);let c=e*n,u=c+Math.abs(a)-1,l=a===0,h=a<0,d=e%2!==0;return{nextN:f,offset:u,isZero:l,isNeg:h,isNegF:d,offsetF:c}}var ws=new WeakMap,hc=new WeakMap;function Es(t){return hc.get(t)||1}function uc(t){if(t!==nr)throw new Error("invalid wNAF")}var or=class{BASE;ZERO;Fn;bits;constructor(e,r){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=r}_unsafeLadder(e,r,n=this.ZERO){let o=e;for(;r>nr;)r&Lt&&(n=n.add(o)),o=o.double(),r>>=Lt;return n}precomputeWindow(e,r){let{windows:n,windowSize:o}=xs(r,this.bits),s=[],i=e,a=i;for(let f=0;f<n;f++){a=i,s.push(a);for(let c=1;c<o;c++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=xs(e,this.bits);for(let a=0;a<i.windows;a++){let{nextN:f,offset:c,isZero:u,isNeg:l,isNegF:h,offsetF:d}=fc(n,a,i);n=f,u?s=s.add($r(h,r[d])):o=o.add($r(l,r[c]))}return uc(n),{p:o,f:s}}wNAFUnsafe(e,r,n,o=this.ZERO){let s=xs(e,this.bits);for(let i=0;i<s.windows&&n!==nr;i++){let{nextN:a,offset:f,isZero:c,isNeg:u}=fc(n,i,s);if(n=a,!c){let l=r[f];o=o.add(u?l.negate():l)}}return uc(n),o}getPrecomputes(e,r,n){let o=ws.get(r);return o||(o=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(o=n(o)),ws.set(r,o))),o}cached(e,r,n){let o=Es(e);return this.wNAF(o,this.getPrecomputes(o,e,n),r)}unsafe(e,r,n,o){let s=Es(e);return s===1?this._unsafeLadder(e,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,e,n),r,o)}createCache(e,r){dc(r,this.bits),hc.set(e,r),ws.delete(e)}hasCache(e){return Es(e)!==1}};function pc(t,e,r,n){let o=e,s=t.ZERO,i=t.ZERO;for(;r>nr||n>nr;)r&Lt&&(s=s.add(o)),n&Lt&&(i=i.add(o)),o=o.double(),r>>=Lt,n>>=Lt;return{p1:s,p2:i}}function lc(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return ys(e),e}else return rr(t,{isLE:r})}function Fn(t,e,r={},n){if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(let f of["p","n","h"]){let c=e[f];if(!(typeof c=="bigint"&&c>nr))throw new Error(`CURVE.${f} must be positive bigint`)}let o=lc(e.p,r.Fp,n),s=lc(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let f of a)if(!o.isValid(e[f]))throw new Error(`CURVE.${f} 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 bt=BigInt(0),he=BigInt(1),vs=BigInt(2),$l=BigInt(8);function jl(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 mc(t,e={}){let r=e,n=Fn("edwards",t,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;ke(r,{},{uvRatio:"function"});let f=vs<<BigInt(s.BYTES*8)-he,c=b=>o.create(b),u=r.uvRatio===void 0?(b,m)=>{try{return{isValid:!0,value:o.sqrt(o.div(b,m))}}catch{return{isValid:!1,value:bt}}}:r.uvRatio;if(!jl(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function l(b,m,y=!1){let v=y?he:bt;return er("coordinate "+b,m,v,f),m}function h(b){if(!(b instanceof d))throw new Error("EdwardsPoint expected")}class d{static BASE=new d(i.Gx,i.Gy,he,c(i.Gx*i.Gy));static ZERO=new d(bt,he,he,bt);static Fp=o;static Fn=s;X;Y;Z;T;constructor(m,y,v,I){this.X=l("x",m),this.Y=l("y",y),this.Z=l("z",v,!0),this.T=l("t",I),Object.freeze(this)}static CURVE(){return i}static fromAffine(m){if(m instanceof d)throw new Error("extended point not allowed");let{x:y,y:v}=m||{};return l("x",y),l("y",v),new d(y,v,he,c(y*v))}static fromBytes(m,y=!1){let v=o.BYTES,{a:I,d:P}=i;m=qr(z(m,v,"point")),Fe(y,"zip215");let B=qr(m),N=m[v-1];B[v-1]=N&-129;let O=Ge(B),_=y?f:o.ORDER;er("point.y",O,bt,_);let k=c(O*O),U=c(k-he),F=c(P*k-I),{isValid:p,value:g}=u(U,F);if(!p)throw new Error("bad point: invalid y coordinate");let S=(g&he)===he,w=(N&128)!==0;if(!y&&g===bt&&w)throw new Error("bad point: x=0 and x_0=1");return w!==S&&(g=c(-g)),d.fromAffine({x:g,y:O})}static fromHex(m,y=!1){return d.fromBytes(Jt(m),y)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,y=!0){return E.createCache(this,m),y||this.multiply(vs),this}assertValidity(){let m=this,{a:y,d:v}=i;if(m.is0())throw new Error("bad point: ZERO");let{X:I,Y:P,Z:B,T:N}=m,O=c(I*I),_=c(P*P),k=c(B*B),U=c(k*k),F=c(O*y),p=c(k*c(F+_)),g=c(U+c(v*c(O*_)));if(p!==g)throw new Error("bad point: equation left != right (1)");let S=c(I*P),w=c(B*N);if(S!==w)throw new Error("bad point: equation left != right (2)")}equals(m){h(m);let{X:y,Y:v,Z:I}=this,{X:P,Y:B,Z:N}=m,O=c(y*N),_=c(P*I),k=c(v*N),U=c(B*I);return O===_&&k===U}is0(){return this.equals(d.ZERO)}negate(){return new d(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:m}=i,{X:y,Y:v,Z:I}=this,P=c(y*y),B=c(v*v),N=c(vs*c(I*I)),O=c(m*P),_=y+v,k=c(c(_*_)-P-B),U=O+B,F=U-N,p=O-B,g=c(k*F),S=c(U*p),w=c(k*p),x=c(F*U);return new d(g,S,x,w)}add(m){h(m);let{a:y,d:v}=i,{X:I,Y:P,Z:B,T:N}=this,{X:O,Y:_,Z:k,T:U}=m,F=c(I*O),p=c(P*_),g=c(N*v*U),S=c(B*k),w=c((I+P)*(O+_)-F-p),x=S-g,A=S+g,T=c(p-y*F),C=c(w*x),D=c(A*T),R=c(w*T),H=c(x*A);return new d(C,D,H,R)}subtract(m){return h(m),this.add(m.negate())}multiply(m){if(!s.isValidNot0(m))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:y,f:v}=E.cached(this,m,I=>Rt(d,I));return Rt(d,[y,v])[0]}multiplyUnsafe(m){if(!s.isValid(m))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return m===bt?d.ZERO:this.is0()||m===he?this:E.unsafe(this,m,y=>Rt(d,y))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return E.unsafe(this,i.n).is0()}toAffine(m){let y=this,v=m,{X:I,Y:P,Z:B}=y,N=y.is0();v==null&&(v=N?$l:o.inv(B));let O=c(I*v),_=c(P*v),k=o.mul(B,v);if(N)return{x:bt,y:he};if(k!==he)throw new Error("invZ was invalid");return{x:O,y:_}}clearCofactor(){return a===he?this:this.multiplyUnsafe(a)}toBytes(){let{x:m,y}=this.toAffine(),v=o.toBytes(y);return v[v.length-1]|=m&he?128:0,v}toHex(){return Qt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let E=new or(d,s.BITS);return s.BITS>=8&&d.BASE.precompute(8),Object.freeze(d.prototype),Object.freeze(d),d}var kn=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(e){this.ep=e}static fromBytes(e){ps()}static fromHex(e){ps()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(e){return this.ep.toAffine(e)}toHex(){return Qt(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(e){return this.assertSame(e),this.init(this.ep.add(e.ep))}subtract(e){return this.assertSame(e),this.init(this.ep.subtract(e.ep))}multiply(e){return this.init(this.ep.multiply(e))}multiplyUnsafe(e){return this.init(this.ep.multiplyUnsafe(e))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(e,r){return this.ep.precompute(e,r),this}};function yc(t,e,r={}){if(typeof e!="function")throw new Error('"hash" function param is required');let n=e,o=r;ke(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:f}=t,c=n.outputLen,u=2*a.BYTES;if(c!==void 0&&(Ne(c,"hash.outputLen"),c!==u))throw new Error(`hash.outputLen must be ${u}, got ${c}`);let l=o.randomBytes===void 0?Mr:o.randomBytes,h=o.adjustScalarBytes===void 0?p=>p:o.adjustScalarBytes,d=o.domain===void 0?(p,g,S)=>{if(Fe(S,"phflag"),g.length||S)throw new Error("Contexts/pre-hash are not supported");return p}:o.domain;function E(p){return f.create(Ge(p))}function b(p){let g=O.secretKey;z(p,O.secretKey,"secretKey");let S=z(n(p),2*g,"hashedSecretKey"),w=h(S.slice(0,g)),x=S.slice(g,2*g),A=E(w);return{head:w,prefix:x,scalar:A}}function m(p){let{head:g,prefix:S,scalar:w}=b(p),x=i.multiply(w),A=x.toBytes();return{head:g,prefix:S,scalar:w,point:x,pointBytes:A}}function y(p){return m(p).pointBytes}function v(p=Uint8Array.of(),...g){let S=ce(...g);return E(n(d(S,z(p,void 0,"context"),!!s)))}function I(p,g,S={}){p=z(p,void 0,"message"),s&&(p=s(p));let{prefix:w,scalar:x,pointBytes:A}=m(g),T=v(S.context,w,p),C=i.multiply(T).toBytes(),D=v(S.context,C,A,p),R=f.create(T+D*x);if(!f.isValid(R))throw new Error("sign failed: invalid s");let H=ce(C,f.toBytes(R));return z(H,O.signature,"result")}let P={zip215:o.zip215};function B(p,g,S,w=P){let{context:x}=w,A=w.zip215===void 0?!!P.zip215:w.zip215,T=O.signature;p=z(p,T,"signature"),g=z(g,void 0,"message"),S=z(S,O.publicKey,"publicKey"),A!==void 0&&Fe(A,"zip215"),s&&(g=s(g));let C=T/2,D=p.subarray(0,C),R=Ge(p.subarray(C,T)),H,Y,M;try{H=t.fromBytes(S,A),Y=t.fromBytes(D,A),M=i.multiplyUnsafe(R)}catch{return!1}if(!A&&H.isSmallOrder())return!1;let ie=v(x,D,S,g);return Y.add(H.multiplyUnsafe(ie)).subtract(M).clearCofactor().is0()}let N=a.BYTES,O={secretKey:N,publicKey:N,signature:2*N,seed:N};function _(p){return p=p===void 0?l(O.seed):p,z(p,O.seed,"seed")}function k(p){return Dt(p)&&p.length===O.secretKey}function U(p,g){try{return!!t.fromBytes(p,g===void 0?P.zip215:g)}catch{return!1}}let F={getExtendedPublicKey:m,randomSecretKey:_,isValidSecretKey:k,isValidPublicKey:U,toMontgomery(p){let{y:g}=t.fromBytes(p),S=O.publicKey,w=S===32;if(!w&&S!==57)throw new Error("only defined for 25519 and 448");let x=w?a.div(he+g,he-g):a.div(g-he,g+he);return a.toBytes(x)},toMontgomerySecret(p){let g=O.secretKey;z(p,g);let S=n(p.subarray(0,g));return h(S).subarray(0,g)}};return Object.freeze(O),Object.freeze(F),Object.freeze({keygen:Nn(_,y),getPublicKey:y,sign:I,verify:B,utils:F,Point:t,lengths:O})}function jr(t,e){if(Ne(t),Ne(e),e<0||e>4)throw new Error("invalid I2OSP length: "+e);if(t<0||t>2**(8*e)-1)throw new Error("invalid I2OSP input: "+t);let r=Array.from({length:e}).fill(0);for(let n=e-1;n>=0;n--)r[n]=t&255,t>>>=8;return new Uint8Array(r)}function Yl(t,e){let r=new Uint8Array(t.length);for(let n=0;n<t.length;n++)r[n]=t[n]^e[n];return r}function Zl(t){if(!Dt(t)&&typeof t!="string")throw new Error("DST must be Uint8Array or ascii string");let e=typeof t=="string"?Ln(t):t;if(e.length===0)throw new Error("DST must be non-empty");return e}function Ss(t,e,r,n){z(t),Ne(r),e=Zl(e),e.length>255&&(e=n(ce(Ln("H2C-OVERSIZE-DST-"),e)));let{outputLen:o,blockLen:s}=n,i=Math.ceil(r/o);if(r>65535||i>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=ce(e,jr(e.length,1)),f=new Uint8Array(s),c=jr(r,2),u=new Array(i),l=n(ce(f,t,c,jr(0,1),a));u[0]=n(ce(l,jr(1,1),a));for(let d=1;d<i;d++){let E=[Yl(l,u[d-1]),jr(d+1,1),a];u[d]=n(ce(...E))}return ce(...u).slice(0,r)}var bc="HashToScalar-";var Gl=BigInt(0),it=BigInt(1),gc=BigInt(2);var Wl=BigInt(5),Xl=BigInt(8),sr=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Cs={p:sr,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Xl,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Ql(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=sr,a=t*t%s*t%s,f=X(a,gc,s)*a%s,c=X(f,it,s)*t%s,u=X(c,Wl,s)*c%s,l=X(u,e,s)*u%s,h=X(l,r,s)*l%s,d=X(h,n,s)*h%s,E=X(d,o,s)*d%s,b=X(E,o,s)*d%s,m=X(b,e,s)*u%s;return{pow_p_5_8:X(m,gc,s)*t%s,b2:a}}function Jl(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var As=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Ts(t,e){let r=sr,n=oe(e*e*e,r),o=oe(n*n*e,r),s=Ql(t*o).pow_p_5_8,i=oe(t*n*s,r),a=oe(e*i*i,r),f=i,c=oe(i*As,r),u=a===t,l=a===oe(-t,r),h=a===oe(-t*As,r);return u&&(i=f),(l||h)&&(i=c),st(i,r)&&(i=oe(-i,r)),{isValid:u||l,value:i}}var xt=mc(Cs,{uvRatio:Ts}),gt=xt.Fp,Ec=xt.Fn;function ed(t){return yc(xt,Tn,Object.assign({adjustScalarBytes:Jl,zip215:!0},t))}var vc=ed({});var Is=As,td=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),rd=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),nd=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),od=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),xc=t=>Ts(it,t),sd=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),_s=t=>gt.create(Ge(t)&sd);function wc(t){let{d:e}=Cs,r=sr,n=y=>gt.create(y),o=n(Is*t*t),s=n((o+it)*nd),i=BigInt(-1),a=n((i-e*o)*n(o+e)),{isValid:f,value:c}=Ts(s,a),u=n(c*t);st(u,r)||(u=n(-u)),f||(c=u),f||(i=o);let l=n(i*(o-it)*od-a),h=c*c,d=n((c+c)*a),E=n(l*td),b=n(it-h),m=n(it+h);return new xt(n(d*m),n(b*E),n(E*m),n(d*b))}var wt=class t extends kn{static BASE=new t(xt.BASE);static ZERO=new t(xt.ZERO);static Fp=gt;static Fn=Ec;constructor(e){super(e)}static fromAffine(e){return new t(xt.fromAffine(e))}assertSame(e){if(!(e instanceof t))throw new Error("RistrettoPoint expected")}init(e){return new t(e)}static fromBytes(e){Te(e,32);let{a:r,d:n}=Cs,o=sr,s=P=>gt.create(P),i=_s(e);if(!Wa(gt.toBytes(i),e)||st(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),f=s(it+r*a),c=s(it-r*a),u=s(f*f),l=s(c*c),h=s(r*n*u-l),{isValid:d,value:E}=xc(s(h*l)),b=s(E*c),m=s(E*b*h),y=s((i+i)*b);st(y,o)&&(y=s(-y));let v=s(f*m),I=s(y*v);if(!d||st(I,o)||v===Gl)throw new Error("invalid ristretto255 encoding 2");return new t(new xt(y,v,it,I))}static fromHex(e){return t.fromBytes(Nr(e))}toBytes(){let{X:e,Y:r,Z:n,T:o}=this.ep,s=sr,i=m=>gt.create(m),a=i(i(n+r)*i(n-r)),f=i(e*r),c=i(f*f),{value:u}=xc(i(a*c)),l=i(u*a),h=i(u*f),d=i(l*h*o),E;if(st(o*d,s)){let m=i(r*Is),y=i(e*Is);e=m,r=y,E=i(l*rd)}else E=h;st(e*d,s)&&(r=i(-r));let b=i((n-r)*E);return st(b,s)&&(b=i(-b)),gt.toBytes(b)}equals(e){this.assertSame(e);let{X:r,Y:n}=this.ep,{X:o,Y:s}=e.ep,i=c=>gt.create(c),a=i(r*s)===i(n*o),f=i(n*s)===i(r*o);return a||f}is0(){return this.equals(t.ZERO)}};Object.freeze(wt.BASE);Object.freeze(wt.ZERO);Object.freeze(wt.prototype);Object.freeze(wt);var id=Object.freeze({Point:wt,hashToCurve(t,e){let r=e?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":e.DST,n=Ss(t,r,64,Tn);return id.deriveToCurve(n)},hashToScalar(t,e={DST:bc}){let r=Ss(t,e.DST,64,Tn);return Ec.create(Ge(r))},deriveToCurve(t){Te(t,64);let e=_s(t.subarray(0,32)),r=wc(e),n=_s(t.subarray(32,64)),o=wc(n);return new wt(r.add(o))}});var Yr=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},Un=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var Oe={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new Un("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,ad=(async()=>{try{return await Oe.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function cd(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await Oe.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await Oe.get().subtle.verify({name:"Ed25519"},n,ve(e),ve(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function fd(t,e,r){return vc.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function Sc(t,e,r){return Bs==null&&(Bs=await ad),Bs?cd(t,e,r):fd(t,e,r)}function Mn(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=Ds(e,Kn)}toMultihash(){return Le.digest(Ye(this))}toCID(){return le.createV1(114,this.toMultihash())}toString(){return ne.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ae(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let o=Sc(this.raw,r,e);return Mn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Os(t){return t=Ds(t,Kn),new Vn(t)}function Ds(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new Q(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}var ld=Math.pow(2,7),dd=Math.pow(2,14),hd=Math.pow(2,21),Ps=Math.pow(2,28),Ls=Math.pow(2,35),Rs=Math.pow(2,42),Fs=Math.pow(2,49),Z=128,xe=127;function _e(t){if(t<ld)return 1;if(t<dd)return 2;if(t<hd)return 3;if(t<Ps)return 4;if(t<Ls)return 5;if(t<Rs)return 6;if(t<Fs)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ir(t,e,r=0){switch(_e(t)){case 8:e[r++]=t&255|Z,t/=128;case 7:e[r++]=t&255|Z,t/=128;case 6:e[r++]=t&255|Z,t/=128;case 5:e[r++]=t&255|Z,t/=128;case 4:e[r++]=t&255|Z,t>>>=7;case 3:e[r++]=t&255|Z,t>>>=7;case 2:e[r++]=t&255|Z,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function pd(t,e,r=0){switch(_e(t)){case 8:e.set(r++,t&255|Z),t/=128;case 7:e.set(r++,t&255|Z),t/=128;case 6:e.set(r++,t&255|Z),t/=128;case 5:e.set(r++,t&255|Z),t/=128;case 4:e.set(r++,t&255|Z),t>>>=7;case 3:e.set(r++,t&255|Z),t>>>=7;case 2:e.set(r++,t&255|Z),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function Ns(t,e){let r=t[e],n=0;if(n+=r&xe,r<Z||(r=t[e+1],n+=(r&xe)<<7,r<Z)||(r=t[e+2],n+=(r&xe)<<14,r<Z)||(r=t[e+3],n+=(r&xe)<<21,r<Z)||(r=t[e+4],n+=(r&xe)*Ps,r<Z)||(r=t[e+5],n+=(r&xe)*Ls,r<Z)||(r=t[e+6],n+=(r&xe)*Rs,r<Z)||(r=t[e+7],n+=(r&xe)*Fs,r<Z))return n;throw new RangeError("Could not decode varint")}function md(t,e){let r=t.get(e),n=0;if(n+=r&xe,r<Z||(r=t.get(e+1),n+=(r&xe)<<7,r<Z)||(r=t.get(e+2),n+=(r&xe)<<14,r<Z)||(r=t.get(e+3),n+=(r&xe)<<21,r<Z)||(r=t.get(e+4),n+=(r&xe)*Ps,r<Z)||(r=t.get(e+5),n+=(r&xe)*Ls,r<Z)||(r=t.get(e+6),n+=(r&xe)*Rs,r<Z)||(r=t.get(e+7),n+=(r&xe)*Fs,r<Z))return n;throw new RangeError("Could not decode varint")}function ar(t,e,r=0){return e==null&&(e=ge(_e(t))),e instanceof Uint8Array?ir(t,e,r):pd(t,e,r)}function Zr(t,e=0){return t instanceof Uint8Array?Ns(t,e):md(t,e)}var Us=new Float32Array([-0]),Et=new Uint8Array(Us.buffer);function Ic(t,e,r){Us[0]=t,e[r]=Et[0],e[r+1]=Et[1],e[r+2]=Et[2],e[r+3]=Et[3]}function _c(t,e){return Et[0]=t[e],Et[1]=t[e+1],Et[2]=t[e+2],Et[3]=t[e+3],Us[0]}var Ks=new Float64Array([-0]),we=new Uint8Array(Ks.buffer);function Cc(t,e,r){Ks[0]=t,e[r]=we[0],e[r+1]=we[1],e[r+2]=we[2],e[r+3]=we[3],e[r+4]=we[4],e[r+5]=we[5],e[r+6]=we[6],e[r+7]=we[7]}function Tc(t,e){return we[0]=t[e],we[1]=t[e+1],we[2]=t[e+2],we[3]=t[e+3],we[4]=t[e+4],we[5]=t[e+5],we[6]=t[e+6],we[7]=t[e+7],Ks[0]}var yd=BigInt(Number.MAX_SAFE_INTEGER),bd=BigInt(Number.MIN_SAFE_INTEGER),Be=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 Ft;if(e<yd&&e>bd)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>Bc&&(o=0n,++n>Bc&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return Ft;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):Ft}},Ft=new Be(0,0);Ft.toBigInt=function(){return 0n};Ft.zzEncode=Ft.zzDecode=function(){return this};Ft.length=function(){return 1};var Bc=4294967296n;function Dc(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 Oc(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 Ms(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 Ue(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function qn(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var Vs=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=ve(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,Ue(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 Ue(this,4);return qn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ue(this,4);return qn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ue(this,4);let e=_c(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ue(this,4);let e=Tc(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 Ue(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return Oc(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ue(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ue(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 Be(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 Ue(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 Ue(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 Ue(this,8);let e=qn(this.buf,this.pos+=4),r=qn(this.buf,this.pos+=4);return new Be(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=Ns(this.buf,this.pos);return this.pos+=_e(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 Gr(t){return new Vs(t instanceof Uint8Array?t:t.subarray())}function Ke(t,e,r){let n=Gr(t);return e.decode(n,void 0,r)}function qs(t){let e=t??8192,r=e>>>1,n,o=e;return function(i){if(i<1||i>r)return ge(i);o+i>e&&(n=ge(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 Hs(){}var $s=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},gd=qs();function xd(t){return globalThis.Buffer!=null?ge(t):gd(t)}var Xr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Nt(Hs,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 js((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,Be.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=Be.fromBigInt(e);return this._push(Hn,r.length(),r)}uint64Number(e){return this._push(ir,_e(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=Be.fromBigInt(e).zzEncode();return this._push(Hn,r.length(),r)}sint64Number(e){let r=Be.fromNumber(e).zzEncode();return this._push(Hn,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(zs,1,e?1:0)}fixed32(e){return this._push(Wr,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=Be.fromBigInt(e);return this._push(Wr,4,r.lo)._push(Wr,4,r.hi)}fixed64Number(e){let r=Be.fromNumber(e);return this._push(Wr,4,r.lo)._push(Wr,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(Ic,4,e)}double(e){return this._push(Cc,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(zs,1,0):this.uint32(r)._push(Ed,r,e)}string(e){let r=Dc(e);return r!==0?this.uint32(r)._push(Ms,r,e):this._push(zs,1,0)}fork(){return this.states=new $s(this),this.head=this.tail=new Nt(Hs,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(Hs,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=xd(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function zs(t,e,r){e[r]=t&255}function wd(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var js=class extends Nt{next;constructor(e,r){super(wd,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 Wr(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 Ed(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(Xr.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(vd,e,t),this},Xr.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(Sd,e,t),this});function vd(t,e,r){e.set(t,r)}function Sd(t,e,r){t.length<40?Ms(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(K(t),r)}function Ys(){return new Xr}function Me(t,e){let r=Ys();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*Ve(t,e,r){let n=Gr(t);yield*e.stream(n,void 0,"$",r)}var zn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function $n(t,e,r,n,o){return{name:t,type:e,encode:r,decode:n,stream:o}}function Zs(t){function e(s){if(t[s.toString()]==null)throw new Error("Invalid enum value");return t[s]}let r=function(i,a){let f=e(i);a.int32(f)},n=function(i){let a=i.int32();return e(a)},o=function*(i){let a=i.int32();yield e(a)};return $n("enum",zn.VARINT,r,n,o)}function qe(t,e,r){return $n("message",zn.LENGTH_DELIMITED,t,e,r)}var We=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var J;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(J||(J={}));var Gs;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(Gs||(Gs={}));(function(t){t.codec=()=>Zs(Gs)})(J||(J={}));var Xe;(function(t){let e;t.codec=()=>(e==null&&(e=qe((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),J.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let f={},c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{f.Type=J.codec().decode(s);break}case 2:{f.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return f},function*(s,i,a,f={}){let c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:J.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),e);function r(s){return Me(s,t.codec())}t.encode=r;function n(s,i){return Ke(s,t.codec(),i)}t.decode=n;function o(s,i){return Ve(s,t.codec(),i)}t.stream=o})(Xe||(Xe={}));var Ws;(function(t){let e;t.codec=()=>(e==null&&(e=qe((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),J.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let f={},c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{f.Type=J.codec().decode(s);break}case 2:{f.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return f},function*(s,i,a,f={}){let c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:J.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),e);function r(s){return Me(s,t.codec())}t.encode=r;function n(s,i){return Ke(s,t.codec(),i)}t.decode=n;function o(s,i){return Ve(s,t.codec(),i)}t.stream=o})(Ws||(Ws={}));var Jr={};Ae(Jr,{MAX_RSA_KEY_SIZE:()=>Xs,generateRSAKeyPair:()=>kc,jwkToJWKKeyPair:()=>Uc,jwkToPkcs1:()=>Cd,jwkToPkix:()=>ti,jwkToRSAPrivateKey:()=>si,pkcs1MessageToJwk:()=>Js,pkcs1MessageToRSAPrivateKey:()=>ri,pkcs1ToJwk:()=>_d,pkcs1ToRSAPrivateKey:()=>Nc,pkixMessageToJwk:()=>ei,pkixMessageToRSAPublicKey:()=>oi,pkixToJwk:()=>Td,pkixToRSAPublicKey:()=>ni});var cr=class{type="RSA";jwk;_raw;_multihash;constructor(e,r){this.jwk=e,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Jr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return le.createV1(114,this._multihash)}toString(){return ne.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ae(this.raw,e.raw)}verify(e,r,n){return Fc(this.jwk,r,e,n)}},Qr=class{type="RSA";jwk;_raw;publicKey;constructor(e,r){this.jwk=e,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Jr.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ae(this.raw,e.raw)}sign(e,r){return Rc(this.jwk,e,r)}};var Xs=8192,Qs=18,Ad=1062,Id=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function _d(t){let e=tt(t);return Js(e)}function Js(t){return{n:q(t[1],"base64url"),e:q(t[2],"base64url"),d:q(t[3],"base64url"),p:q(t[4],"base64url"),q:q(t[5],"base64url"),dp:q(t[6],"base64url"),dq:q(t[7],"base64url"),qi:q(t[8],"base64url"),kty:"RSA"}}function Cd(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 Q("JWK was missing components");return dt([Ie(Uint8Array.from([0])),Ie(K(t.n,"base64url")),Ie(K(t.e,"base64url")),Ie(K(t.d,"base64url")),Ie(K(t.p,"base64url")),Ie(K(t.q,"base64url")),Ie(K(t.dp,"base64url")),Ie(K(t.dq,"base64url")),Ie(K(t.qi,"base64url"))]).subarray()}function Td(t){let e=tt(t,{offset:0});return ei(e)}function ei(t){let e=tt(t[1],{offset:0});return{kty:"RSA",n:q(e[0],"base64url"),e:q(e[1],"base64url")}}function ti(t){if(t.n==null||t.e==null)throw new Q("JWK was missing components");return dt([Id,vn(dt([Ie(K(t.n,"base64url")),Ie(K(t.e,"base64url"))]))]).subarray()}function Nc(t){let e=tt(t);return ri(e)}function ri(t){let e=Js(t);return si(e)}function ni(t,e){if(t.byteLength>=Ad)throw new zt("Key size is too large");let r=tt(t,{offset:0});return oi(r,t,e)}function oi(t,e,r){let n=ei(t);if(r==null){let o=Xt(Xe.encode({Type:J.RSA,Data:e}));r=$e(Qs,o)}return new cr(n,r)}function si(t){if(Mc(t)>Xs)throw new Q("Key size is too large");let e=Uc(t),r=Xt(Xe.encode({Type:J.RSA,Data:ti(e.publicKey)})),n=$e(Qs,r);return new Qr(e.privateKey,new cr(e.publicKey,n))}async function kc(t){if(t>Xs)throw new Q("Key size is too large");let e=await Kc(t),r=Xt(Xe.encode({Type:J.RSA,Data:ti(e.publicKey)})),n=$e(Qs,r);return new Qr(e.privateKey,new cr(e.publicKey,n))}function Uc(t){if(t==null)throw new Q("Missing key parameter");return{privateKey:t,publicKey:{kty:t.kty,n:t.n,e:t.e}}}async function Kc(t,e){let r=await Oe.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 Bd(r,e);return{privateKey:n[0],publicKey:n[1]}}async function Rc(t,e,r){let n=await Oe.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Oe.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,ve(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 Oe.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Oe.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,ve(e),ve(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),s}async function Bd(t,e){if(t.privateKey==null||t.publicKey==null)throw new Q("Private and public key are required");let r=await Promise.all([Oe.get().subtle.exportKey("jwk",t.privateKey),Oe.get().subtle.exportKey("jwk",t.publicKey)]);return e?.signal?.throwIfAborted(),r}function Mc(t){if(t.kty!=="RSA")throw new Q("invalid key type");if(t.n==null)throw new Q("invalid key modulus");return K(t.n,"base64url").length*8}var jn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(Sn(e),Te(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let 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),nt(o)}update(e){return Wt(this),this.iHash.update(e),this}digestInto(e){Wt(this),An(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}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=a,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()}},Vc=(()=>{let t=((e,r,n)=>new jn(e,r).update(n).digest());return t.create=(e,r)=>new jn(e,r),t})();var qc=(t,e)=>(t+(t>=0?e:-e)/Hc)/e;function Dd(t,e,r){er("scalar",t,Qe,r);let[[n,o],[s,i]]=e,a=qc(i*t,r),f=qc(-o*t,r),c=t-a*n-f*s,u=-a*o-f*i,l=c<Qe,h=u<Qe;l&&(c=-c),h&&(u=-u);let d=Hr(Math.ceil(tr(r)/2))+vt;if(c<Qe||c>=d||u<Qe||u>=d)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:c,k2neg:h,k2:u}}function ai(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function ii(t,e){ke(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Fe(r.lowS,"lowS"),Fe(r.prehash,"prehash"),r.format!==void 0&&ai(r.format),r}var ci=class extends Error{constructor(e=""){super(e)}},He={Err:ci,_tlv:{encode:(t,e)=>{let{Err:r}=He;if(Ne(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(typeof e!="string")throw new TypeError('"data" expected string, got type='+typeof e);if(e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,o=Vr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Vr(o.length/2|128):"";return Vr(t)+s+o+e},decode(t,e){let{Err:r}=He;e=z(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.encode: 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 f=o&127;if(!f)throw new r("tlv.decode(long): indefinite length not supported");if(f>4)throw new r("tlv.decode(long): byte length is too big");let c=e.subarray(n,n+f);if(c.length!==f)throw new r("tlv.decode: length bytes not complete");if(c[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let u of c)i=i<<8|u;if(n+=f,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}=He;if(On(t),t<Qe)throw new e("integer: negative integers are not allowed");let r=Vr(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}=He;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 Ot(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=He,o=z(t,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:f}=n.decode(2,s),{v:c,l:u}=n.decode(2,f);if(u.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(c)}},hexFromSig(t){let{_tlv:e,_int:r}=He,n=e.encode(2,r.encode(t.r)),o=e.encode(2,r.encode(t.s)),s=n+o;return e.encode(48,s)}};Object.freeze(He._tlv);Object.freeze(He._int);Object.freeze(He);var Qe=BigInt(0),vt=BigInt(1),Hc=BigInt(2),Yn=BigInt(3),Od=BigInt(4);function zc(t,e={}){let r=Fn("weierstrass",t,e),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;ke(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:f,allowInfinityPoint:c}=e;if(f&&(!n.is0(s.a)||typeof f.beta!="bigint"||!Array.isArray(f.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=jc(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function h(F,p,g){if(c&&p.is0())return Uint8Array.of(0);let{x:S,y:w}=p.toAffine(),x=n.toBytes(S);if(Fe(g,"isCompressed"),g){l();let A=!n.isOdd(w);return ce($c(A),x)}else return ce(Uint8Array.of(4),x,n.toBytes(w))}function d(F){z(F,void 0,"Point");let{publicKey:p,publicKeyUncompressed:g}=u,S=F.length,w=F[0],x=F.subarray(1);if(c&&S===1&&w===0)return{x:n.ZERO,y:n.ZERO};if(S===p&&(w===2||w===3)){let A=n.fromBytes(x);if(!n.isValid(A))throw new Error("bad point: is not on curve, wrong x");let T=m(A),C;try{C=n.sqrt(T)}catch(H){let Y=H instanceof Error?": "+H.message:"";throw new Error("bad point: is not on curve, sqrt error"+Y)}l();let D=n.isOdd(C);return(w&1)===1!==D&&(C=n.neg(C)),{x:A,y:C}}else if(S===g&&w===4){let A=n.BYTES,T=n.fromBytes(x.subarray(0,A)),C=n.fromBytes(x.subarray(A,A*2));if(!y(T,C))throw new Error("bad point: is not on curve");return{x:T,y:C}}else throw new Error(`bad point: got length ${S}, expected compressed=${p} or uncompressed=${g}`)}let E=e.toBytes===void 0?h:e.toBytes,b=e.fromBytes===void 0?d:e.fromBytes;function m(F){let p=n.sqr(F),g=n.mul(p,F);return n.add(n.add(g,n.mul(F,s.a)),s.b)}function y(F,p){let g=n.sqr(p),S=m(F);return n.eql(g,S)}if(!y(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let v=n.mul(n.pow(s.a,Yn),Od),I=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(v,I)))throw new Error("bad curve params: a or b");function P(F,p,g=!1){if(!n.isValid(p)||g&&n.is0(p))throw new Error(`bad point coordinate ${F}`);return p}function B(F){if(!(F instanceof _))throw new Error("Weierstrass Point expected")}function N(F){if(!f||!f.basises)throw new Error("no endo");return Dd(F,f.basises,o.ORDER)}function O(F,p,g,S,w){return g=new _(n.mul(g.X,F),g.Y,g.Z),p=$r(S,p),g=$r(w,g),p.add(g)}class _{static BASE=new _(s.Gx,s.Gy,n.ONE);static ZERO=new _(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(p,g,S){this.X=P("x",p),this.Y=P("y",g,!0),this.Z=P("z",S),Object.freeze(this)}static CURVE(){return s}static fromAffine(p){let{x:g,y:S}=p||{};if(!p||!n.isValid(g)||!n.isValid(S))throw new Error("invalid affine point");if(p instanceof _)throw new Error("projective point not allowed");return n.is0(g)&&n.is0(S)?_.ZERO:new _(g,S,n.ONE)}static fromBytes(p){let g=_.fromAffine(b(z(p,void 0,"point")));return g.assertValidity(),g}static fromHex(p){return _.fromBytes(Jt(p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=8,g=!0){return U.createCache(this,p),g||this.multiply(Yn),this}assertValidity(){let p=this;if(p.is0()){if(e.allowInfinityPoint&&n.is0(p.X)&&n.eql(p.Y,n.ONE)&&n.is0(p.Z))return;throw new Error("bad point: ZERO")}let{x:g,y:S}=p.toAffine();if(!n.isValid(g)||!n.isValid(S))throw new Error("bad point: x or y not field elements");if(!y(g,S))throw new Error("bad point: equation left != right");if(!p.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:p}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(p)}equals(p){B(p);let{X:g,Y:S,Z:w}=this,{X:x,Y:A,Z:T}=p,C=n.eql(n.mul(g,T),n.mul(x,w)),D=n.eql(n.mul(S,T),n.mul(A,w));return C&&D}negate(){return new _(this.X,n.neg(this.Y),this.Z)}double(){let{a:p,b:g}=s,S=n.mul(g,Yn),{X:w,Y:x,Z:A}=this,T=n.ZERO,C=n.ZERO,D=n.ZERO,R=n.mul(w,w),H=n.mul(x,x),Y=n.mul(A,A),M=n.mul(w,x);return M=n.add(M,M),D=n.mul(w,A),D=n.add(D,D),T=n.mul(p,D),C=n.mul(S,Y),C=n.add(T,C),T=n.sub(H,C),C=n.add(H,C),C=n.mul(T,C),T=n.mul(M,T),D=n.mul(S,D),Y=n.mul(p,Y),M=n.sub(R,Y),M=n.mul(p,M),M=n.add(M,D),D=n.add(R,R),R=n.add(D,R),R=n.add(R,Y),R=n.mul(R,M),C=n.add(C,R),Y=n.mul(x,A),Y=n.add(Y,Y),R=n.mul(Y,M),T=n.sub(T,R),D=n.mul(Y,H),D=n.add(D,D),D=n.add(D,D),new _(T,C,D)}add(p){B(p);let{X:g,Y:S,Z:w}=this,{X:x,Y:A,Z:T}=p,C=n.ZERO,D=n.ZERO,R=n.ZERO,H=s.a,Y=n.mul(s.b,Yn),M=n.mul(g,x),ie=n.mul(S,A),fe=n.mul(w,T),ue=n.add(g,S),re=n.add(x,A);ue=n.mul(ue,re),re=n.add(M,ie),ue=n.sub(ue,re),re=n.add(g,w);let Se=n.add(x,T);return re=n.mul(re,Se),Se=n.add(M,fe),re=n.sub(re,Se),Se=n.add(S,w),C=n.add(A,T),Se=n.mul(Se,C),C=n.add(ie,fe),Se=n.sub(Se,C),R=n.mul(H,re),C=n.mul(Y,fe),R=n.add(C,R),C=n.sub(ie,R),R=n.add(ie,R),D=n.mul(C,R),ie=n.add(M,M),ie=n.add(ie,M),fe=n.mul(H,fe),re=n.mul(Y,re),ie=n.add(ie,fe),fe=n.sub(M,fe),fe=n.mul(H,fe),re=n.add(re,fe),M=n.mul(ie,re),D=n.add(D,M),M=n.mul(Se,re),C=n.mul(ue,C),C=n.sub(C,M),M=n.mul(ue,ie),R=n.mul(Se,R),R=n.add(R,M),new _(C,D,R)}subtract(p){return B(p),this.add(p.negate())}is0(){return this.equals(_.ZERO)}multiply(p){let{endo:g}=e;if(!o.isValidNot0(p))throw new RangeError("invalid scalar: out of range");let S,w,x=A=>U.cached(this,A,T=>Rt(_,T));if(g){let{k1neg:A,k1:T,k2neg:C,k2:D}=N(p),{p:R,f:H}=x(T),{p:Y,f:M}=x(D);w=H.add(M),S=O(g.beta,R,Y,A,C)}else{let{p:A,f:T}=x(p);S=A,w=T}return Rt(_,[S,w])[0]}multiplyUnsafe(p){let{endo:g}=e,S=this,w=p;if(!o.isValid(w))throw new RangeError("invalid scalar: out of range");if(w===Qe||S.is0())return _.ZERO;if(w===vt)return S;if(U.hasCache(this))return this.multiply(w);if(g){let{k1neg:x,k1:A,k2neg:T,k2:C}=N(w),{p1:D,p2:R}=pc(_,S,A,C);return O(g.beta,D,R,x,T)}else return U.unsafe(S,w)}toAffine(p){let g=this,S=p,{X:w,Y:x,Z:A}=g;if(n.eql(A,n.ONE))return{x:w,y:x};let T=g.is0();S==null&&(S=T?n.ONE:n.inv(A));let C=n.mul(w,S),D=n.mul(x,S),R=n.mul(A,S);if(T)return{x:n.ZERO,y:n.ZERO};if(!n.eql(R,n.ONE))throw new Error("invZ was invalid");return{x:C,y:D}}isTorsionFree(){let{isTorsionFree:p}=e;return i===vt?!0:p?p(_,this):U.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:p}=e;return i===vt?this:p?p(_,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===vt?this.is0():this.clearCofactor().is0()}toBytes(p=!0){return Fe(p,"isCompressed"),this.assertValidity(),E(_,this,p)}toHex(p=!0){return Qt(this.toBytes(p))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let k=o.BITS,U=new or(_,e.endo?Math.ceil(k/2):k);return k>=8&&_.BASE.precompute(8),Object.freeze(_.prototype),Object.freeze(_),_}function $c(t){return Uint8Array.of(t?2:3)}function jc(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function Pd(t,e={}){let{Fn:r}=t,n=e.randomBytes===void 0?Mr:e.randomBytes,o=Object.assign(jc(t.Fp,r),{seed:Math.max(bs(r.ORDER),16)});function s(d){try{let E=r.fromBytes(d);return r.isValidNot0(E)}catch{return!1}}function i(d,E){let{publicKey:b,publicKeyUncompressed:m}=o;try{let y=d.length;return E===!0&&y!==b||E===!1&&y!==m?!1:!!t.fromBytes(d)}catch{return!1}}function a(d){return d=d===void 0?n(o.seed):d,gs(z(d,o.seed,"seed"),r.ORDER)}function f(d,E=!0){return t.BASE.multiply(r.fromBytes(d)).toBytes(E)}function c(d){let{secretKey:E,publicKey:b,publicKeyUncompressed:m}=o,y=r._lengths;if(!Dt(d))return;let v=z(d,void 0,"key").length,I=v===b||v===m,P=v===E||!!y?.includes(v);if(!(I&&P))return I}function u(d,E,b=!0){if(c(d)===!0)throw new Error("first arg must be private key");if(c(E)===!1)throw new Error("second arg must be public key");let m=r.fromBytes(d);return t.fromBytes(E).multiply(m).toBytes(b)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},h=Nn(a,f);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:f,getSharedSecret:u,keygen:h,Point:t,utils:l,lengths:o})}function Yc(t,e,r={}){let n=e;Sn(n),ke(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let o=r.randomBytes===void 0?Mr:r.randomBytes,s=r.hmac===void 0?(w,x)=>Vc(n,w,x):r.hmac,{Fp:i,Fn:a}=t,{ORDER:f,BITS:c}=a,{keygen:u,getPublicKey:l,getSharedSecret:h,utils:d,lengths:E}=Pd(t,r),b={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},m=f*Hc+vt<i.ORDER;function y(w){let x=f>>vt;return w>x}function v(w,x){if(!a.isValidNot0(x))throw new Error(`invalid signature ${w}: out of range 1..Point.Fn.ORDER`);return x}function I(){if(m)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function P(w,x){ai(x);let A=E.signature,T=x==="compact"?A:x==="recovered"?A+1:void 0;return z(w,T)}class B{r;s;recovery;constructor(x,A,T){if(this.r=v("r",x),this.s=v("s",A),T!=null){if(I(),![0,1,2,3].includes(T))throw new Error("invalid recovery id");this.recovery=T}Object.freeze(this)}static fromBytes(x,A=b.format){P(x,A);let T;if(A==="der"){let{r:H,s:Y}=He.toSig(z(x));return new B(H,Y)}A==="recovered"&&(T=x[0],A="compact",x=x.subarray(1));let C=E.signature/2,D=x.subarray(0,C),R=x.subarray(C,C*2);return new B(a.fromBytes(D),a.fromBytes(R),T)}static fromHex(x,A){return this.fromBytes(Jt(x),A)}assertRecovery(){let{recovery:x}=this;if(x==null)throw new Error("invalid recovery id: must be present");return x}addRecoveryBit(x){return new B(this.r,this.s,x)}recoverPublicKey(x){let{r:A,s:T}=this,C=this.assertRecovery(),D=C===2||C===3?A+f:A;if(!i.isValid(D))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let R=i.toBytes(D),H=t.fromBytes(ce($c((C&1)===0),R)),Y=a.inv(D),M=O(z(x,void 0,"msgHash")),ie=a.create(-M*Y),fe=a.create(T*Y),ue=t.BASE.multiplyUnsafe(ie).add(H.multiplyUnsafe(fe));if(ue.is0())throw new Error("invalid recovery: point at infinify");return ue.assertValidity(),ue}hasHighS(){return y(this.s)}toBytes(x=b.format){if(ai(x),x==="der")return Jt(He.hexFromSig(this));let{r:A,s:T}=this,C=a.toBytes(A),D=a.toBytes(T);return x==="recovered"?(I(),ce(Uint8Array.of(this.assertRecovery()),C,D)):ce(C,D)}toHex(x){return Qt(this.toBytes(x))}}Object.freeze(B.prototype),Object.freeze(B);let N=r.bits2int===void 0?function(x){if(x.length>8192)throw new Error("input is too large");let A=Ot(x),T=x.length*8-c;return T>0?A>>BigInt(T):A}:r.bits2int,O=r.bits2int_modN===void 0?function(x){return a.create(N(x))}:r.bits2int_modN,_=Hr(c);function k(w){return er("num < 2^"+c,w,Qe,_),a.toBytes(w)}function U(w,x){return z(w,void 0,"message"),x?z(n(w),void 0,"prehashed message"):w}function F(w,x,A){let{lowS:T,prehash:C,extraEntropy:D}=ii(A,b);w=U(w,C);let R=O(w),H=a.fromBytes(x);if(!a.isValidNot0(H))throw new Error("invalid private key");let Y=[k(H),k(R)];if(D!=null&&D!==!1){let ue=D===!0?o(E.secretKey):D;Y.push(z(ue,void 0,"extraEntropy"))}let M=ce(...Y),ie=R;function fe(ue){let re=N(ue);if(!a.isValidNot0(re))return;let Se=a.inv(re),Ht=t.BASE.multiply(re).toAffine(),_r=a.create(Ht.x);if(_r===Qe)return;let pn=a.create(Se*a.create(ie+_r*H));if(pn===Qe)return;let oa=(Ht.x===_r?0:2)|Number(Ht.y&vt),sa=pn;return T&&y(pn)&&(sa=a.neg(pn),oa^=1),new B(_r,sa,m?void 0:oa)}return{seed:M,k2sig:fe}}function p(w,x,A={}){let{seed:T,k2sig:C}=F(w,x,A);return Xa(n.outputLen,a.BYTES,s)(T,C).toBytes(A.format)}function g(w,x,A,T={}){let{lowS:C,prehash:D,format:R}=ii(T,b);if(A=z(A,void 0,"publicKey"),x=U(x,D),!Dt(w)){let H=w instanceof B?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+H)}P(w,R);try{let H=B.fromBytes(w,R),Y=t.fromBytes(A);if(C&&H.hasHighS())return!1;let{r:M,s:ie}=H,fe=O(x),ue=a.inv(ie),re=a.create(fe*ue),Se=a.create(M*ue),Ht=t.BASE.multiplyUnsafe(re).add(Y.multiplyUnsafe(Se));return Ht.is0()?!1:a.create(Ht.x)===M}catch{return!1}}function S(w,x,A={}){let{prehash:T}=ii(A,b);return x=U(x,T),B.fromBytes(w,"recovered").recoverPublicKey(x).toBytes()}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:h,utils:d,lengths:E,Point:t,sign:p,verify:g,recoverPublicKey:S,Signature:B,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")},Ld={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Zc=BigInt(2);function Rd(t){let e=ui.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),f=BigInt(88),c=t*t*t%e,u=c*c*t%e,l=X(u,r,e)*u%e,h=X(l,r,e)*u%e,d=X(h,Zc,e)*c%e,E=X(d,o,e)*d%e,b=X(E,s,e)*E%e,m=X(b,a,e)*b%e,y=X(m,f,e)*m%e,v=X(y,a,e)*b%e,I=X(v,r,e)*u%e,P=X(I,i,e)*E%e,B=X(P,n,e)*c%e,N=X(B,Zc,e);if(!fi.eql(fi.sqr(N),t))throw new Error("Cannot find square root");return N}var fi=rr(ui.p,{sqrt:Rd}),Fd=zc(ui,{Fp:fi,endo:Ld}),fr=Yc(Fd,Xt);function Gc(t,e,r,n){let o=Pr.digest(r instanceof Uint8Array?r:r.subarray());if(Mn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),fr.verify(e,s,t,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Yr(String(s))});try{return n?.signal?.throwIfAborted(),fr.verify(e,o.digest,t,{prehash:!1,format:"der"})}catch(s){throw new Yr(String(s))}}var Zn=class{type="secp256k1";raw;_key;constructor(e){this._key=Xc(e),this.raw=Wc(this._key)}toMultihash(){return Le.digest(Ye(this))}toCID(){return le.createV1(114,this.toMultihash())}toString(){return ne.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ae(this.raw,e.raw)}verify(e,r,n){return Gc(this._key,r,e,n)}};function li(t){return new Zn(t)}function Wc(t){return fr.Point.fromBytes(t).toBytes()}function Xc(t){try{return fr.Point.fromBytes(t),t}catch(e){throw new zt(String(e))}}function ur(t,e){let{Type:r,Data:n}=Xe.decode(t),o=n??new Uint8Array;switch(r){case J.RSA:return ni(o,e);case J.Ed25519:return Os(o);case J.secp256k1:return li(o);case J.ECDSA:return es(o);default:throw new It}}function Qc(t){let{Type:e,Data:r}=Xe.decode(t.digest),n=r??new Uint8Array;switch(e){case J.Ed25519:return Os(n);case J.secp256k1:return li(n);case J.ECDSA:return es(n);default:throw new It}}function Ye(t){return Xe.encode({Type:J[t.type],Data:t.raw})}var en;(function(t){let e;t.codec=()=>(e==null&&(e=qe((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 f={publicKey:de(0),payloadType:de(0),payload:de(0),signature:de(0)},c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{f.publicKey=s.bytes();break}case 2:{f.payloadType=s.bytes();break}case 3:{f.payload=s.bytes();break}case 5:{f.signature=s.bytes();break}default:{s.skipType(u&7);break}}}return f},function*(s,i,a,f={}){let c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>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(u&7);break}}}})),e);function r(s){return Me(s,t.codec())}t.encode=r;function n(s,i){return Ke(s,t.codec(),i)}t.decode=n;function o(s,i){return Ve(s,t.codec(),i)}t.stream=o})(en||(en={}));var Gn=class extends Error{constructor(e="Invalid signature"){super(e),this.name="InvalidSignatureError"}};var Je=class t{static createFromProtobuf=e=>{let r=en.decode(e),n=ur(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=Jc(o,s,i),f=await r.sign(a.subarray(),n);return new t({publicKey:r.publicKey,payloadType:s,payload:i,signature:f})};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=en.encode({publicKey:Ye(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(e){return e==null?!1:ae(this.marshal(),e.marshal())}async validate(e,r){let n=Jc(e,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},Jc=(t,e,r)=>{let n=K(t),o=ar(n.byteLength),s=ar(e.length),i=ar(r.length);return new se(o,n,s,e,i,r)};var ef=Symbol.for("nodejs.util.inspect.custom"),Nd=114,tn=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()})`}[Io]=!0;toString(){return this.string==null&&(this.string=ne.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return le.createV1(Nd,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return ae(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return ae(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[ef](){return`PeerId(${this.toString()})`}},rn=class extends tn{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},nn=class extends tn{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},on=class extends tn{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},kd=2336,sn=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Le.digest(K(this.url))}[ef](){return`PeerId(${this.url})`}[Io]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return le.createV1(kd,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=q(e)),e.toString()===this.toString())}};var Ud=114,tf=2336;function rf(t){if(t.type==="Ed25519")return new nn({multihash:t.toCID().multihash,publicKey:t});if(t.type==="secp256k1")return new on({multihash:t.toCID().multihash,publicKey:t});if(t.type==="RSA")return new rn({multihash:t.toCID().multihash,publicKey:t});throw new It}function di(t){if(Md(t))return new rn({multihash:t});if(Kd(t))try{let e=Qc(t);if(e.type==="Ed25519")return new nn({multihash:t,publicKey:e});if(e.type==="secp256k1")return new on({multihash:t,publicKey:e})}catch{let r=q(t.digest);return new sn(new URL(r))}throw new bn("Supplied PeerID Multihash is invalid")}function Wn(t){if(t?.multihash==null||t.version==null||t.version===1&&t.code!==Ud&&t.code!==tf)throw new yn("Supplied PeerID CID is invalid");if(t.code===tf){let e=q(t.multihash.digest);return new sn(new URL(e))}return di(t.multihash)}function Kd(t){return t.code===Le.code}function Md(t){return t.code===Pr.code}var be=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},at=class extends Error{static name="ValidationError";name="ValidationError"},Xn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Qn=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 f=a==="0",c=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let h=Number.parseInt(l,e);if(!Number.isNaN(h))return h});if(u===void 0)break;if(s*=e,s+=u,s>c||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&f&&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 nf=45,Vd=15,lr=new Jn;function eo(t){if(!(t.length>Vd))return lr.new(t).parseWith(()=>lr.readIPv4Addr())}function to(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>nf))return lr.new(t).parseWith(()=>lr.readIPv6Addr())}function dr(t,e=!1){if(t.includes("%")&&(t=t.split("%")[0]),t.length>nf)return;let r=lr.new(t).parseWith(()=>lr.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 hr(t){return!!eo(t)}function ro(t){return!!to(t)}function pi(t){return e=>q(e,t)}function mi(t){return e=>K(e,t)}function pr(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 of(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=K(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 je([r,o],r.length+o.length)}function sf(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 je([r,o],r.length+o.length)}function yi(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=q(e,"base32"),o=pr(r);return`${n}:${o}`}var bi=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 be("Invalid byte value in IP address");e[n]=o}),e},af=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let s=hr(r[n]),i;s&&(i=bi(r[n]),r[n]=q(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,q(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 be("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},cf=function(t){if(t.byteLength!==4)throw new be("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},ff=function(t){if(t.byteLength!==16)throw new be("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 be(`Invalid IPv6 address "${r}"`)}};function uf(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new be(`Invalid IPv6 address "${t}"`)}}var hi=Object.values(Lr).map(t=>t.decoder),qd=(function(){let t=hi[0].or(hi[1]);return hi.slice(2).forEach(e=>t=t.or(e)),t})();function lf(t){return qd.decode(t)}function df(t){return e=>t.encoder.encode(e)}function Hd(t){if(parseInt(t).toString()!==t)throw new at("Value must be an integer")}function zd(t){if(t<0)throw new at("Value must be a positive integer, or zero")}function $d(t){return e=>{if(e>t)throw new at(`Value must be smaller than or equal to ${t}`)}}function jd(...t){return e=>{for(let r of t)r(e)}}var an=jd(Hd,zd,$d(65535));var pe=-1,gi=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 Qn(`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 gi,ih=[{code:4,name:"ip4",size:32,valueToBytes:bi,bytesToValue:cf,validate:t=>{if(!hr(t))throw new at(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:kt,bytesToValue:pr,validate:an},{code:273,name:"udp",size:16,valueToBytes:kt,bytesToValue:pr,validate:an},{code:33,name:"dccp",size:16,valueToBytes:kt,bytesToValue:pr,validate:an},{code:41,name:"ip6",size:128,valueToBytes:af,bytesToValue:ff,stringToValue:uf,validate:t=>{if(!ro(t))throw new at(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:pe},{code:43,name:"ipcidr",size:8,bytesToValue:pi("base10"),valueToBytes:mi("base10")},{code:53,name:"dns",size:pe},{code:54,name:"dns4",size:pe},{code:55,name:"dns6",size:pe},{code:56,name:"dnsaddr",size:pe},{code:132,name:"sctp",size:16,valueToBytes:kt,bytesToValue:pr,validate:an},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:pe,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:pe,bytesToValue:pi("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?mi("base58btc")(t):le.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:yi,valueToBytes:of},{code:445,name:"onion3",size:296,bytesToValue:yi,valueToBytes:sf},{code:446,name:"garlic64",size:pe},{code:447,name:"garlic32",size:pe},{code:448,name:"tls"},{code:449,name:"sni",size:pe},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:pe,bytesToValue:df(Vo),valueToBytes:lf},{code:480,name:"http"},{code:481,name:"http-path",size:pe,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:pe}];ih.forEach(t=>{ft.addProtocol(t)});function hf(t){let e=[],r=0;for(;r<t.length;){let n=Zr(t,r),o=ft.getProtocol(n),s=_e(n),i=ah(o,t,r+s),a=0;i>0&&o.size===pe&&(a=_e(i));let f=s+a+i,c={code:n,name:o.name,bytes:ve(t.subarray(r,r+f))};if(i>0){let u=r+s+a,l=t.subarray(u,u+i);c.value=o.bytesToValue?.(l)??q(l)}e.push(c),r+=f}return e}function pf(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let o=ft.getProtocol(n.code),s=_e(n.code),i,a=0,f=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??K(n.value),a=i.byteLength,o.size===pe&&(f=_e(a)));let c=new Uint8Array(s+f+a),u=0;ir(n.code,c,u),u+=s,i!=null&&(o.size===pe&&(ir(a,c,u),u+=f),c.set(i,u)),n.bytes=c}r.push(n.bytes),e+=n.bytes.byteLength}return je(r,e)}function mf(t){if(t.charAt(0)!=="/")throw new be('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 f=ft.getProtocol(o);if(r==="protocol"){if(f.size==null||f.size===0){e.push({code:f.code,name:f.name}),n="",o="",r="protocol";continue}else if(a)throw new be(`Component ${o} was missing value`);r="value"}else if(r==="value"){let c={code:f.code,name:f.name};if(f.size!=null&&f.size!==0){if(n==="")throw new be(`Component ${o} was missing value`);c.value=f.stringToValue?.(n)??n}e.push(c),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new be("Incomplete multiaddr");return e}function yf(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=ft.getProtocol(e.code);if(r==null)throw new be(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function ah(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:Zr(e,r)}var ch=Symbol.for("nodejs.util.inspect.custom"),Li=Symbol.for("@multiformats/multiaddr");function fh(t){if(t==null&&(t="/"),bf(t))return t.getComponents();if(t instanceof Uint8Array)return hf(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),mf(t);if(Array.isArray(t))return t;throw new be("Must be a string, Uint8Array, Component[], or another Multiaddr")}var co=class t{[Li]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=fh(e),r.validate!==!1&&uh(this)}get bytes(){return this.#r==null&&(this.#r=pf(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=yf(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 Xn(`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 ae(this.bytes,e.bytes)}[ch](){return`Multiaddr(${this.toString()})`}};function uh(t){t.getComponents().forEach(e=>{let r=ft.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function bf(t){return!!t?.[Li]}function fn(t){return new co(t)}var gf="libp2p-peer-record",xf=Uint8Array.from([3,1]);var un;(function(t){let e;(function(i){let a;i.codec=()=>(a==null&&(a=qe((l,h,d={})=>{d.lengthDelimited!==!1&&h.fork(),l.multiaddr!=null&&l.multiaddr.byteLength>0&&(h.uint32(10),h.bytes(l.multiaddr)),d.lengthDelimited!==!1&&h.ldelim()},(l,h,d={})=>{let E={multiaddr:de(0)},b=h==null?l.len:l.pos+h;for(;l.pos<b;){let m=l.uint32();m>>>3===1?E.multiaddr=l.bytes():l.skipType(m&7)}return E},function*(l,h,d,E={}){let b=h==null?l.len:l.pos+h;for(;l.pos<b;){let m=l.uint32();m>>>3===1?yield{field:`${d}.multiaddr`,value:l.bytes()}:l.skipType(m&7)}})),a);function f(l){return Me(l,i.codec())}i.encode=f;function c(l,h){return Ke(l,i.codec(),h)}i.decode=c;function u(l,h){return Ve(l,i.codec(),h)}i.stream=u})(e=t.AddressInfo||(t.AddressInfo={}));let r;t.codec=()=>(r==null&&(r=qe((i,a,f={})=>{if(f.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 c of i.addresses)a.uint32(26),t.AddressInfo.codec().encode(c,a);f.lengthDelimited!==!1&&a.ldelim()},(i,a,f={})=>{let c={peerId:de(0),seq:0n,addresses:[]},u=a==null?i.len:i.pos+a;for(;i.pos<u;){let l=i.uint32();switch(l>>>3){case 1:{c.peerId=i.bytes();break}case 2:{c.seq=i.uint64();break}case 3:{if(f.limits?.addresses!=null&&c.addresses.length===f.limits.addresses)throw new We('Decode error - repeated field "addresses" had too many elements');c.addresses.push(t.AddressInfo.codec().decode(i,i.uint32(),{limits:f.limits?.addresses$}));break}default:{i.skipType(l&7);break}}}return c},function*(i,a,f,c={}){let u={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:`${f}.peerId`,value:i.bytes()};break}case 2:{yield{field:`${f}.seq`,value:i.uint64()};break}case 3:{if(c.limits?.addresses!=null&&u.addresses===c.limits.addresses)throw new We('Streaming decode error - repeated field "addresses" had too many elements');for(let d of t.AddressInfo.codec().stream(i,i.uint32(),`${f}.addresses[]`,{limits:c.limits?.addresses$}))yield{...d,index:u.addresses};u.addresses++;break}default:{i.skipType(h&7);break}}}})),r);function n(i){return Me(i,t.codec())}t.encode=n;function o(i,a){return Ke(i,t.codec(),a)}t.decode=o;function s(i,a){return Ve(i,t.codec(),a)}t.stream=s})(un||(un={}));function wf(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 ze=class t{static createFromProtobuf=e=>{let r=un.decode(e),n=di(Dr(r.peerId)),o=(r.addresses??[]).map(i=>fn(i.multiaddr)),s=r.seq;return new t({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=gf;static CODEC=xf;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=un.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||!wf(this.multiaddrs,e.multiaddrs))}};function lh(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=lh(t);if(e==null)throw new Q(`Multiaddr ${t} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}function Ef(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 vf(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 Ri(t){switch(t.length){case Kt:return t.join(".");case Mt:{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 Sf(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 Af(t){let e="0x";for(let r of t)e+=(r>>4).toString(16)+(r&15).toString(16);return e}var Kt=4,Mt=16,Jx=parseInt("0xFFFF",16),dh=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function ln(t,e){e.length===Mt&&t.length===Kt&&Ef(e,0,11)&&(e=e.slice(12)),e.length===Kt&&t.length===Mt&&vf(t,dh,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 If(t,e){if(typeof e=="string"&&(e=dr(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 Fi(t){let[e,r]=t.split("/");if(!e||!r)throw new Error("Failed to parse given CIDR: "+t);let n=Kt,o=eo(e);if(o==null&&(n=Mt,o=to(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=Ni(s,8*n);return{network:ln(o,i),mask:i}}function Ni(t,e){if(e!==8*Kt&&e!==8*Mt)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 dn=class{constructor(e,r){if(r==null)({network:this.network,mask:this.mask}=Fi(e));else{let n=dr(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=dr(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Ni(o,8*n.length);this.network=ln(n,this.mask)}}contains(e){return If({network:this.network,mask:this.mask},e)}toString(){let e=Sf(this.mask),r=e!==-1?String(e):Af(this.mask);return Ri(this.network)+"/"+r}};function _f(t,e){return new dn(t).contains(e)}function Cf(t){try{let e=fo(t);return e.type==="ip6"?_f("2000::/3",e.host):!1}catch{return!1}}var Of=ou(Df(),1),xh=["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"],wh=xh.map(t=>new Of.Netmask(t));function Hi(t){for(let e of wh)if(e.contains(t))return!0;return!1}function Eh(t){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(t)}function vh(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 Hi(o)}function Sh(t){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)}function Ah(t){let e=t.split(":"),r=e[e.length-1];return Hi(r)}function Ih(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 Pf(t){if(hr(t))return Hi(t);if(Eh(t))return vh(t);if(Sh(t))return Ah(t);if(ro(t))return Ih(t)}function Lf(t){try{let e=fo(t);switch(e.type){case"ip4":case"ip6":return Pf(e.host)??!1;default:return e.host==="localhost"}}catch{return!1}}var G=t=>({match:e=>{let r=e[0];return r==null||r.code!==t||r.value!=null?!1:e.slice(1)}}),L=(t,e)=>({match:r=>{let n=r[0];return n?.code!==t||n.value==null||e!=null&&n.value!==e?!1:r.slice(1)}}),Rf=t=>({match:e=>t.match(e)===!1?e:!1}),V=t=>({match:e=>{let r=t.match(e);return r===!1?e:r}}),Ee=(...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}}),j=(...t)=>({match:e=>{for(let r of t){let n=r.match(e);if(n===!1)return!1;e=n}return e}});function W(...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 _h=L(421),Ow=W(_h),ho=L(54),po=L(55),mo=L(56),$i=L(53),Pw=W(ho,V(L(421))),Lw=W(po,V(L(421))),Rw=W(mo,V(L(421))),Fw=W(Ee($i,mo,ho,po),V(L(421))),Ff=j(L(4),V(L(43))),Nf=j(V(L(42)),L(41),V(L(43))),ji=Ee(Ff,Nf),vr=Ee(ji,$i,ho,po,mo),kf=W(Ee(ji,j(Ee($i,mo,ho,po),V(L(421))))),Nw=W(Ff),kw=W(Nf),Uw=W(ji),Yi=j(vr,L(6)),hn=j(vr,L(273)),Uf=W(j(Yi,V(L(421)))),Kw=W(hn),Zi=j(hn,G(460),V(L(421))),yo=j(hn,G(461),V(L(421))),Ch=Ee(Zi,yo),Mw=W(Zi),Vw=W(yo),zi=Ee(vr,Yi,hn,Zi,yo),Kf=Ee(j(zi,G(477),V(L(421)))),qw=W(Kf),Mf=Ee(j(zi,G(478),V(L(421))),j(zi,G(448),V(L(449)),G(477),V(L(421)))),Hw=W(Mf),Vf=j(hn,G(280),V(L(466)),V(L(466)),V(L(421))),zw=W(Vf),qf=j(yo,G(465),V(L(466)),V(L(466)),V(L(421))),$w=W(qf),lo=Ee(Kf,Mf,j(Yi,V(L(421))),j(Ch,V(L(421))),j(vr,V(L(421))),Vf,qf,L(421)),jw=W(lo),Th=j(V(lo),G(290),Rf(G(281)),V(L(421))),Yw=W(Th),Bh=Ee(j(lo,G(290),G(281),V(L(421))),j(lo,G(281),V(L(421))),j(G(281),V(L(421)))),Zw=W(Bh),Dh=j(vr,Ee(j(L(6,"80")),j(L(6),G(480)),G(480)),V(L(481)),V(L(421))),Gw=W(Dh),Oh=j(vr,Ee(j(L(6,"443")),j(L(6,"443"),G(480)),j(L(6),G(443)),j(L(6),G(448),G(480)),j(G(448),G(480)),G(448),G(443)),V(L(481)),V(L(421))),Ww=W(Oh),Ph=Ee(j(L(777),V(L(421)))),Xw=W(Ph),Lh=Ee(j(L(400),V(L(421)))),Qw=W(Lh);function Sr(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Gi=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},Hf=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,f,u=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(Hf(i));return}if(i&&(f=()=>{h(Hf(i))},i.addEventListener("abort",f,{once:!0})),t.then(l,h),r===Number.POSITIVE_INFINITY)return;let d=new Gi;a=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(E){h(E)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?l():o instanceof Error?h(o):(d.message=o??`Promise timed out after ${r} milliseconds`,h(d))},r)}).finally(()=>{u.clear(),f&&i&&i.removeEventListener("abort",f)});return u.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},u}var Rh=t=>{let e=t.addEventListener||t.on||t.addListener,r=t.removeEventListener||t.off||t.removeListener;if(!e||!r)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(t),removeListener:r.bind(t)}};function Fh(t,e,r){let n,o=new Promise((s,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[e].flat(),f=[],{addListener:c,removeListener:u}=Rh(t),l=async(...d)=>{let E=r.multiArgs?d:d[0];if(r.filter)try{if(!await r.filter(E))return}catch(b){n(),i(b);return}f.push(E),r.count===f.length&&(n(),s(f))},h=(...d)=>{n(),i(r.rejectionMultiArgs?d:d[0])};n=()=>{for(let d of a)u(d,l);for(let d of r.rejectionEvents)a.includes(d)||u(d,h)};for(let d of a)c(d,l);for(let d of r.rejectionEvents)a.includes(d)||c(d,h);r.signal&&r.signal.addEventListener("abort",()=>{h(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(f)});if(o.cancel=n,typeof r.timeout=="number"){let s=Wi(o,{milliseconds:r.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function zf(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Fh(t,e,r),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function $f(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 qt=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Nh(t){return t.reason}async function Xi(t,e,r){if(e==null)return t;let n=r?.translateError??Nh;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([t,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var Uh=4194304,bo=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Ji=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},ea=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},ta=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Kh(t){return typeof t?.closeRead=="function"}function Mh(t){return typeof t?.close=="function"}function Qi(t){return Kh(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:Mh(t)?t.status!=="open":!1}function Vh(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function qh(t,e){let r=e?.maxBufferSize??Uh,n=new se,o,s=!1;if(!Vh(t))throw new Q("Argument should be a Stream or a Multiaddr");let i=u=>{if(n.append(u.data),n.byteLength>r){let l=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${l} > ${r}`))}o?.resolve()};t.addEventListener("message",i);let a=u=>{u.error!=null?o?.reject(u.error):o?.resolve()};t.addEventListener("close",a);let f=()=>{o?.resolve()};t.addEventListener("remoteCloseWrite",f);let c={readBuffer:n,async read(u){if(s===!0)throw new bo("Stream was unwrapped");if(Qi(t)){if(n.byteLength===0&&u?.bytes==null)return null;if(u?.bytes!=null&&n.byteLength<u.bytes)throw t.log.error("closed after reading %d/%d bytes",n.byteLength,u.bytes),new qt(`Unexpected EOF - stream closed after reading ${n.byteLength}/${u.bytes} bytes`)}let l=u?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=l){o.resolve();break}if(await Xi(o.promise,u?.signal),Qi(t)){if(n.byteLength===0&&u?.bytes==null)return null;break}o=Promise.withResolvers()}let h=u?.bytes??n.byteLength;if(n.byteLength<h){if(Qi(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,h),new qt(`Unexpected EOF - stream closed while reading ${n.byteLength}/${h} bytes`);return c.read(u)}let d=n.sublist(0,h);return n.consume(h),d},async write(u,l){if(s===!0)throw new bo("Stream was unwrapped");t.send(u)||await zf(t,"drain",{signal:l?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,t.removeEventListener("message",i),t.removeEventListener("close",a),t.removeEventListener("remoteCloseWrite",f),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.unshift(n))),t}};return c}function Hh(t,e={}){let r=qh(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=_e(e.maxDataLength));let n=e?.lengthDecoder??Zr,o=e?.lengthEncoder??ar;return{async read(i){let a=-1,f=new se;for(;;){let u=await r.read({...i,bytes:1});if(u==null)break;f.append(u);try{a=n(f)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new Ji("Invalid message length");if(e?.maxLengthLength!=null&&f.byteLength>e.maxLengthLength)throw new ta(`Message length length too long - ${f.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new ea(`Message length too long - ${a} > ${e.maxDataLength}`);let c=await r.read({...i,bytes:a});if(c==null)throw t.log.error("tried to read %d bytes but the stream closed",a),new qt(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(c.byteLength!==a)throw t.log.error("read %d/%d bytes before the stream closed",c.byteLength,a),new qt(`Unexpected EOF - read ${c.byteLength}/${a} bytes before the stream closed`);return c},async write(i,a){await r.write(new se(o(i.byteLength),i),a)},async writeV(i,a){let f=new se(...i.flatMap(c=>[o(c.byteLength),c]));await r.write(f,a)},unwrap(){return r.unwrap()}}}function Ar(t,e){let r=Hh(t,e),n={read:async(o,s)=>{let i=await r.read(s);return o.decode(i)},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 zh(t){return t[Symbol.asyncIterator]!=null}function $h(t){if(zh(t))return(async()=>{for await(let e of t);})();for(let e of t);}var jf=$h;var go=globalThis.CustomEvent??Event;async function*ra(t,e={}){let r=e.concurrency??1/0;r<1&&(r=1/0);let n=e.ordered??!1,o=new EventTarget,s=[],i=Sr(),a=Sr(),f=!1,c,u=!1,l=!1;o.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let b of t){if(s.length===r&&(i=Sr(),await i.promise),u||l)break;let m={done:!1};s.push(m),b().then(y=>{m.done=!0,m.ok=!0,m.value=y,o.dispatchEvent(new go("task-complete"))},y=>{m.done=!0,m.err=y,o.dispatchEvent(new go("task-complete"))})}f=!0,o.dispatchEvent(new go("task-complete"))}catch(b){c=b,o.dispatchEvent(new go("task-complete"))}});function h(){return n?s[0]?.done:!!s.find(b=>b.done)}function*d(){for(;s.length>0&&s[0].done;){let b=s[0];if(s.shift(),b.ok)yield b.value;else throw u=!0,i.resolve(),b.err;i.resolve()}}function*E(){for(;h();)for(let b=0;b<s.length;b++)if(s[b].done){let m=s[b];if(s.splice(b,1),b--,m.ok)yield m.value;else throw u=!0,i.resolve(),m.err;i.resolve()}}try{for(;;){if(h()||(a=Sr(),await a.promise),c!=null||(n?yield*d():yield*E(),c!=null))throw c;if(f&&s.length===0)break}}finally{l=!0,i.resolve()}}var Yf="0.1.0";var Zf="id/push",Gf="1.0.0",Wf="1.0.0";var At;(function(t){let e;t.codec=()=>(e==null&&(e=qe((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 f of s.listenAddrs)i.uint32(18),i.bytes(f);if(s.observedAddr!=null&&(i.uint32(34),i.bytes(s.observedAddr)),s.protocols!=null&&s.protocols.length>0)for(let f of s.protocols)i.uint32(26),i.string(f);s.signedPeerRecord!=null&&(i.uint32(66),i.bytes(s.signedPeerRecord)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let f={listenAddrs:[],protocols:[]},c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 5:{f.protocolVersion=s.string();break}case 6:{f.agentVersion=s.string();break}case 1:{f.publicKey=s.bytes();break}case 2:{if(a.limits?.listenAddrs!=null&&f.listenAddrs.length===a.limits.listenAddrs)throw new We('Decode error - repeated field "listenAddrs" had too many elements');f.listenAddrs.push(s.bytes());break}case 4:{f.observedAddr=s.bytes();break}case 3:{if(a.limits?.protocols!=null&&f.protocols.length===a.limits.protocols)throw new We('Decode error - repeated field "protocols" had too many elements');f.protocols.push(s.string());break}case 8:{f.signedPeerRecord=s.bytes();break}default:{s.skipType(u&7);break}}}return f},function*(s,i,a,f={}){let c={listenAddrs:0,protocols:0},u=i==null?s.len:s.pos+i;for(;s.pos<u;){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(f.limits?.listenAddrs!=null&&c.listenAddrs===f.limits.listenAddrs)throw new We('Streaming decode error - repeated field "listenAddrs" had too many elements');yield{field:`${a}.listenAddrs[]`,index:c.listenAddrs,value:s.bytes()},c.listenAddrs++;break}case 4:{yield{field:`${a}.observedAddr`,value:s.bytes()};break}case 3:{if(f.limits?.protocols!=null&&c.protocols===f.limits.protocols)throw new We('Streaming decode error - repeated field "protocols" had too many elements');yield{field:`${a}.protocols[]`,index:c.protocols,value:s.string()},c.protocols++;break}case 8:{yield{field:`${a}.signedPeerRecord`,value:s.bytes()};break}default:{s.skipType(l&7);break}}}})),e);function r(s){return Me(s,t.codec())}t.encode=r;function n(s,i){return Ke(s,t.codec(),i)}t.decode=n;function o(s,i){return Ve(s,t.codec(),i)}t.stream=o})(At||(At={}));var Ce={protocolPrefix:"ipfs",timeout:5e3,maxInboundStreams:1,maxOutboundStreams:1,maxObservedAddresses:10,maxMessageSize:8192,runOnConnectionOpen:!0,runOnSelfUpdate:!0,runOnLimitedConnection:!0,concurrency:32};function Qf(t){return t.bytes.length===0}function na(t){if(t!=null&&t.length>0)try{let e=fn(t);if(!Qf(e))return e}catch{}}async function xo(t,e,r,n,o){if(r("received identify from %p",n.remotePeer),o==null)throw new Pe("message was null or undefined");let s={},i=o.listenAddrs.map(na).filter(c=>c!=null);if(o.listenAddrs.length>0&&(s.addresses=i.map(c=>({isCertified:!1,multiaddr:c}))),o.protocols.length>0&&(s.protocols=o.protocols),o.publicKey!=null){let c=ur(o.publicKey);if(!rf(c).equals(n.remotePeer))throw new Pe("public key did not match remote PeerId");s.publicKey=c}let a;if(o.signedPeerRecord!=null){r.trace("received signedPeerRecord from %p",n.remotePeer);let c=o.signedPeerRecord,u=await Je.openAndCertify(c,ze.DOMAIN),l=ze.createFromProtobuf(u.payload),h=Wn(u.publicKey.toCID());if(!l.peerId.equals(h))throw new Pe("signing key does not match PeerId in the PeerRecord");if(!n.remotePeer.equals(l.peerId))throw new Pe("signing key does not match remote PeerId");let d;try{d=await t.get(l.peerId)}catch(b){if(b.name!=="NotFoundError")throw b}if(d!=null&&(s.metadata=d.metadata,d.peerRecordEnvelope!=null)){let b=Je.createFromProtobuf(d.peerRecordEnvelope),m=ze.createFromProtobuf(b.payload);m.seqNumber>=l.seqNumber&&(r("sequence number was lower or equal to existing sequence number - stored: %d received: %d",m.seqNumber,l.seqNumber),l=m,c=d.peerRecordEnvelope)}s.peerRecordEnvelope=c;let E=l.multiaddrs.filter(b=>!Qf(b));s.addresses=E.map(b=>({isCertified:!0,multiaddr:b})),a={seq:l.seqNumber,addresses:E}}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 c={};o.agentVersion!=null&&(c.AgentVersion=K(o.agentVersion)),o.protocolVersion!=null&&(c.ProtocolVersion=K(o.protocolVersion)),r.trace("merging %p metadata",n.remotePeer,c),await t.merge(n.remotePeer,{metadata:c})}let f={peerId:n.remotePeer,protocolVersion:o.protocolVersion,agentVersion:o.agentVersion,publicKey:o.publicKey,listenAddrs:i,observedAddr:o.observedAddr==null?void 0:fn(o.observedAddr),protocols:o.protocols,signedPeerRecord:a,connection:n};return e.safeDispatchEvent("peer:identify",{detail:f}),f}function wo(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 Eo(t,e,r,n){let o=Ar(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 Ir=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??Ce.timeout,this.maxInboundStreams=r.maxInboundStreams??Ce.maxInboundStreams,this.maxOutboundStreams=r.maxOutboundStreams??Ce.maxOutboundStreams,this.maxMessageSize=r.maxMessageSize??Ce.maxMessageSize,this.maxObservedAddresses=r.maxObservedAddresses??Ce.maxObservedAddresses,this.runOnLimitedConnection=r.runOnLimitedConnection??Ce.runOnLimitedConnection,this.host={protocolVersion:`${r.protocolPrefix??Ce.protocolPrefix}/${Yf}`,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:K(this.host.agentVersion),ProtocolVersion:K(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 vo=class extends Ir{connectionManager;concurrency;_push;constructor(e,r={}){super(e,{...r,protocol:`/${r.protocolPrefix??Ce.protocolPrefix}/${Zf}/${Wf}`,log:e.logger.forComponent("libp2p:identify-push")}),this.connectionManager=e.connectionManager,this.concurrency=r.concurrency??Ce.concurrency,this._push=$f(this.sendPushMessage.bind(this),r.debounce??1e3),(r.runOnSelfUpdate??Ce.runOnSelfUpdate)&&e.events.addEventListener("self:peer:update",n=>{this.push().catch(o=>{this.log.error("error pushing updates to peers - %e",o)})})}[gn]=["@libp2p/identify-push"];async push(){this._push()}async sendPushMessage(){if(this.isStarted())try{let e=this.components.addressManager.getAddresses().map(u=>u.decapsulateCode(421)),r=new ze({peerId:this.components.peerId,multiaddrs:e}),n=await Je.seal(r,this.components.privateKey),o=this.components.registrar.getProtocols(),s=await this.components.peerStore.get(this.components.peerId),i=q(s.metadata.get("AgentVersion")??K(this.host.agentVersion)),a=q(s.metadata.get("ProtocolVersion")??K(this.host.protocolVersion)),f=this;async function*c(){for(let u of f.connectionManager.getConnections())(await f.components.peerStore.get(u.remotePeer)).protocols.includes(f.protocol)&&(yield async()=>{let h,d=AbortSignal.timeout(f.timeout);try{h=await u.newStream(f.protocol,{signal:d,runOnLimitedConnection:f.runOnLimitedConnection}),await Ar(h,{maxDataLength:f.maxMessageSize}).pb(At).write({listenAddrs:e.map(b=>b.bytes),signedPeerRecord:n.marshal(),protocols:o,agentVersion:i,protocolVersion:a},{signal:d}),await h.close({signal:d})}catch(E){h?.log.newScope("identify-push")?.error("could not push identify update to peer",E),h?.abort(E)}})}await jf(ra(c(),{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 Eo(e,this.maxMessageSize,o,n);await xo(this.components.peerStore,this.components.events,n,r,wo(s)),n.trace("handled push from %p",r.remotePeer)}};var So=class extends Ir{constructor(e,r={}){super(e,{...r,protocol:`/${r.protocolPrefix??Ce.protocolPrefix}/${"id"}/${Gf}`,log:e.logger.forComponent("libp2p:identify")}),(r.runOnConnectionOpen??Ce.runOnConnectionOpen)&&e.events.addEventListener("connection:open",n=>{let o=n.detail;this.identify(o).catch(()=>{})})}[gn]=["@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 Eo(n,this.maxMessageSize,r,o);return wo(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 Pe("Public key was missing from identify message");let a=ur(o),f=Wn(a.toCID());if(!e.remotePeer.equals(f))throw new Pe("Identified peer does not match the expected peer");if(this.components.peerId.equals(f))throw new Pe("Identified peer is our own peer id?");return this.maybeAddObservedAddress(i),this.log("completed for peer %p and protocols %o",f,s),xo(this.components.peerStore,this.components.events,this.log,e,n)}maybeAddObservedAddress(e){let r=na(e);if(r==null||(this.log.trace("our observed address was %a",r),Lf(r)))return;let n=r.getComponents();if((n[0].code===41||n[0].code===42&&n[1].code===41)&&!Cf(r)){this.log.trace("our observed address was IPv6 but not a global unicast address");return}Uf.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(u=>u.decapsulateCode(421)),a=s.peerRecordEnvelope;if(i.length>0&&a==null){let u=new ze({peerId:this.components.peerId,multiaddrs:i});a=(await Je.seal(u,this.components.privateKey,{signal:o})).marshal().subarray()}let f=r.remoteAddr.bytes;kf.matches(r.remoteAddr)||(f=void 0);let c=Ar(e).pb(At);n("send response"),await c.write({protocolVersion:this.host.protocolVersion,agentVersion:this.host.agentVersion,publicKey:Ye(this.components.privateKey.publicKey),listenAddrs:i.map(u=>u.bytes),signedPeerRecord:a,observedAddr:f,protocols:s.protocols},{signal:o}),n("close write"),await c.unwrap().unwrap().close({signal:o})}};function Wh(t={}){return e=>new So(e,t)}function Xh(t={}){return e=>new vo(e,t)}return su(Qh);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/curves/utils.js: