@libp2p/identify 4.1.6-29797a5bb → 4.1.6-5b8813abc

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 wl=Object.create;var Rn=Object.defineProperty;var El=Object.getOwnPropertyDescriptor;var vl=Object.getOwnPropertyNames;var Sl=Object.getPrototypeOf,Al=Object.prototype.hasOwnProperty;var Yo=(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})},Ja=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of vl(e))!Al.call(t,o)&&o!==r&&Rn(t,o,{get:()=>e[o],enumerable:!(n=El(e,o))||n.enumerable});return t};var Il=(t,e,r)=>(r=t!=null?wl(Sl(t)):{},Ja(e||!t||!t.__esModule?Rn(r,"default",{value:t,enumerable:!0}):r,t)),Cl=t=>Ja(Rn({},"__esModule",{value:!0}),t);var Oa=Yo(Lr=>{"use strict";Object.defineProperty(Lr,"__esModule",{value:!0});Lr.Netmask4Impl=void 0;Lr.ip2long=Or;Lr.long2ip=Qe;function Qe(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 zm=48,Hm=97,$m=65;function jm(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)-zm)>>>0;else if(r===16)if("a"<=t[o]&&t[o]<="f")e=e*r+(10+t.charCodeAt(o)-Hm)>>>0;else if("A"<=t[o]&&t[o]<="F")e=e*r+(10+t.charCodeAt(o)-$m)>>>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 Or(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]=jm(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 Ba=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=Or(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=(Or(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=Qe(this.netLong),this.mask=Qe(this.maskLong),this.hostmask=Qe(~this.maskLong),this.first=this.bitmask<=30?Qe(this.netLong+1):this.base,this.last=this.bitmask<=30?Qe(this.netLong+this.size-2):Qe(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?Qe(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):(Or(e)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(e=1){return new t(Qe(this.netLong+this.size*e),this.mask)}forEach(e){let r=Or(this.first),n=Or(this.last),o=0;for(;r<=n;)e(Qe(r),r,o),o++,r++}toString(){return this.base+"/"+this.bitmask}};Lr.Netmask4Impl=Ba});var Wu=Yo(Pr=>{"use strict";Object.defineProperty(Pr,"__esModule",{value:!0});Pr.Netmask6Impl=void 0;Pr.ip6bigint=Pa;Pr.bigint2ip6=Yt;var Ym=Oa(),La=(1n<<128n)-1n;function Pa(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,Ym.ip2long)(n),s=t.substring(0,r+1)+"0:0";return Zu(s)&~0xffffffffn|BigInt(o)}return Zu(t)}function Zu(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 Yt(t){if(t<0n||t>La)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 Ra=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=La>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=Pa(e)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+e)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=Yt(this.netBigint),this.mask=Yt(this.maskBigint),this.hostmask=Yt(~this.maskBigint&La),this.first=this.base,this.last=Yt(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):(Pa(e)&this.maskBigint)===this.netBigint}next(e=1){let r=1n<<BigInt(128-this.bitmask);return new t(Yt(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(Yt(r),Number(r),s),s++,r++}toString(){return this.base+"/"+this.bitmask}};Pr.Netmask6Impl=Ra});var Xu=Yo(_t=>{"use strict";Object.defineProperty(_t,"__esModule",{value:!0});_t.long2ip=_t.ip2long=_t.Netmask=void 0;var Ro=Oa();Object.defineProperty(_t,"ip2long",{enumerable:!0,get:function(){return Ro.ip2long}});Object.defineProperty(_t,"long2ip",{enumerable:!0,get:function(){return Ro.long2ip}});var Gm=Wu(),Na=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 Gm.Netmask6Impl(e,r):this._impl=new Ro.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 Ro.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()}};_t.Netmask=Na});var T0={};Z(T0,{identify:()=>C0,identifyPush:()=>_0});var J=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Wt=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var Nn=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},Fn=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var De=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var Dt=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var Go=Symbol.for("@libp2p/peer-id");var kn=Symbol.for("@libp2p/service-capabilities");var Jo={};Z(Jo,{base58btc:()=>se,base58flickr:()=>Pl});var ny=new Uint8Array(0);function ec(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 Je(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 tc(t){return new TextEncoder().encode(t)}function rc(t){return new TextDecoder().decode(t)}function _l(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 F=c.repeat(b);C<S;++C)F+=t.charAt(T[C]);return F}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)),F=m;O!==v;)C[F++]=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 Tl=_l,Dl=Tl,oc=Dl;var Zo=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")}},Wo=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 sc(this,e)}},Xo=class{decoders;constructor(e){this.decoders=e}or(e){return sc(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 sc(t,e){return new Xo({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Qo=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 Zo(e,r,n),this.decoder=new Wo(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Xt({name:t,prefix:e,encode:r,decode:n}){return new Qo(t,e,r,n)}function lt({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=oc(r,t);return Xt({prefix:e,name:t,encode:n,decode:s=>Je(o(s))})}function Bl(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 Ol(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 Ll(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function te({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=Ll(n);return Xt({prefix:e,name:t,encode(s){return Ol(s,n,r)},decode(s){return Bl(s,o,r,t)}})}var se=lt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Pl=lt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var es={};Z(es,{base32:()=>dt,base32hex:()=>kl,base32hexpad:()=>Ml,base32hexpadupper:()=>Kl,base32hexupper:()=>Ul,base32pad:()=>Nl,base32padupper:()=>Fl,base32upper:()=>Rl,base32z:()=>Vl});var dt=te({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Rl=te({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Nl=te({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Fl=te({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),kl=te({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ul=te({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ml=te({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Kl=te({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Vl=te({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ts={};Z(ts,{base36:()=>Mr,base36upper:()=>ql});var Mr=lt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ql=lt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var zl=cc,ic=128,Hl=127,$l=~Hl,jl=Math.pow(2,31);function cc(t,e,r){e=e||[],r=r||0;for(var n=r;t>=jl;)e[r++]=t&255|ic,t/=128;for(;t&$l;)e[r++]=t&255|ic,t>>>=7;return e[r]=t|0,cc.bytes=r-n+1,e}var Yl=rs,Gl=128,ac=127;function rs(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw rs.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&ac)<<o:(i&ac)*Math.pow(2,o),o+=7}while(i>=Gl);return rs.bytes=s-n,r}var Zl=Math.pow(2,7),Wl=Math.pow(2,14),Xl=Math.pow(2,21),Ql=Math.pow(2,28),Jl=Math.pow(2,35),ed=Math.pow(2,42),td=Math.pow(2,49),rd=Math.pow(2,56),nd=Math.pow(2,63),od=function(t){return t<Zl?1:t<Wl?2:t<Xl?3:t<Ql?4:t<Jl?5:t<ed?6:t<td?7:t<rd?8:t<nd?9:10},sd={encode:zl,decode:Yl,encodingLength:od},id=sd,Kr=id;function Vr(t,e=0){return[Kr.decode(t,e),Kr.decode.bytes]}function Qt(t,e,r=0){return Kr.encode(t,e,r),e}function Jt(t){return Kr.encodingLength(t)}function qe(t,e){let r=e.byteLength,n=Jt(t),o=n+Jt(r),s=new Uint8Array(o+r);return Qt(t,s,0),Qt(r,s,n),s.set(e,o),new er(t,r,e,s)}function qr(t){let e=Je(t),[r,n]=Vr(e),[o,s]=Vr(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new er(r,o,i,e)}function fc(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&ec(t.bytes,r.bytes)}}var er=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};function uc(t,e){let{bytes:r,version:n}=t;return n===0?cd(r,ns(t),e??se.encoder):fd(r,ns(t),e??dt.encoder)}var lc=new WeakMap;function ns(t){let e=lc.get(t);if(e==null){let r=new Map;return lc.set(t,r),r}return e}var de=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!==zr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==ud)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=qe(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&&fc(e.multihash,n.multihash)}toString(e){return uc(this,e)}toJSON(){return{"/":uc(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??dc(n,o,s.bytes))}else if(r[ld]===!0){let{version:n,multihash:o,code:s}=r,i=qr(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!==zr)throw new Error(`Version 0 CID must use dag-pb (code: ${zr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=dc(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,zr,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=Je(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 er(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]=Vr(e.subarray(r));return r+=p,l},o=n(),s=zr;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]=ad(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 ns(s).set(n,e),s}};function ad(t,e){switch(t[0]){case"Q":{let r=e??se;return[se.prefix,r.decode(`${se.prefix}${t}`)]}case se.prefix:{let r=e??se;return[se.prefix,r.decode(t)]}case dt.prefix:{let r=e??dt;return[dt.prefix,r.decode(t)]}case Mr.prefix:{let r=e??Mr;return[Mr.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 cd(t,e,r){let{prefix:n}=r;if(n!==se.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 fd(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 zr=112,ud=18;function dc(t,e,r){let n=Jt(t),o=n+Jt(e),s=new Uint8Array(o+r.byteLength);return Qt(t,s,0),Qt(e,s,n),s.set(r,o),s}var ld=Symbol.for("@ipld/js-cid/CID");var os={};Z(os,{identity:()=>Be});var hc=0,dd="identity",pc=Je;function hd(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 qe(hc,pc(t))}var Be={code:hc,name:dd,encode:pc,digest:hd};function ve(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 pd(t){return t.buffer instanceof ArrayBuffer}function ze(t){return pd(t)?t:t.slice()}async function mc(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,ze(e),ze(r.subarray()));return n?.signal?.throwIfAborted(),s}function et(t=0){return new Uint8Array(t)}function Hr(t=0){return new Uint8Array(t)}function ss(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=Hr(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}function yc(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 gc=Symbol.for("@achingbrain/uint8arraylist");function bc(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?.[gc]}var ae=class t{bufs;length;[gc]=!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=bc(this.bufs,e);return r.buf[r.index]}set(e,r){let n=bc(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 ss(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:ss(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=Hr(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=et(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=et(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=et(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=Hr(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=et(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=et(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=et(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=et(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=et(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(!yc(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 us={};Z(us,{base10:()=>vd});var Fy=new Uint8Array(0);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}function tt(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 wc(t){return new TextEncoder().encode(t)}function Ec(t){return new TextDecoder().decode(t)}function md(t){return t?.buffer instanceof ArrayBuffer}function Ot(t){return md(t)?t:t.slice()}function yd(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 F=c.repeat(b);C<S;++C)F+=t.charAt(T[C]);return F}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)),F=m;O!==v;)C[F++]=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 bd=yd,gd=bd,Sc=gd;var is=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")}},as=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 Ac(this,e)}},cs=class{decoders;constructor(e){this.decoders=e}or(e){return Ac(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 Ac(t,e){return new cs({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var fs=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 is(e,r,n),this.decoder=new as(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function tr({name:t,prefix:e,encode:r,decode:n}){return new fs(t,e,r,n)}function ht({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=Sc(r,t);return tr({prefix:e,name:t,encode:n,decode:s=>tt(o(s))})}function xd(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 wd(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 Ed(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=Ed(n);return tr({prefix:e,name:t,encode(s){return wd(s,n,r)},decode(s){return xd(s,o,r,t)}})}var vd=ht({prefix:"9",name:"base10",alphabet:"0123456789"});var ls={};Z(ls,{base16:()=>Sd,base16upper:()=>Ad});var Sd=re({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ad=re({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ds={};Z(ds,{base2:()=>Id});var Id=re({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var hs={};Z(hs,{base256emoji:()=>Bd});var Ic=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}"),Cd=Ic.reduce((t,e,r)=>(t[r]=e,t),[]),_d=Ic.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Td(t){return t.reduce((e,r)=>(e+=Cd[r],e),"")}function Dd(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=_d[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Bd=tr({prefix:"\u{1F680}",name:"base256emoji",encode:Td,decode:Dd});var ps={};Z(ps,{base32:()=>rr,base32hex:()=>Rd,base32hexpad:()=>Fd,base32hexpadupper:()=>kd,base32hexupper:()=>Nd,base32pad:()=>Ld,base32padupper:()=>Pd,base32upper:()=>Od,base32z:()=>Ud});var rr=re({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Od=re({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ld=re({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Pd=re({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Rd=re({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Nd=re({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Fd=re({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),kd=re({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ud=re({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ms={};Z(ms,{base36:()=>$r,base36upper:()=>Md});var $r=ht({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Md=ht({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ys={};Z(ys,{base58btc:()=>He,base58flickr:()=>Kd});var He=ht({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Kd=ht({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var bs={};Z(bs,{base64:()=>Vd,base64pad:()=>qd,base64url:()=>zd,base64urlpad:()=>Hd});var Vd=re({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),qd=re({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),zd=re({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Hd=re({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var gs={};Z(gs,{base8:()=>$d});var $d=re({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var xs={};Z(xs,{identity:()=>jd});var jd=tr({prefix:"\0",name:"identity",encode:t=>Ec(t),decode:t=>wc(t)});var Qy=new TextEncoder,Jy=new TextDecoder;var Es={};Z(Es,{identity:()=>mh});var Zd=Tc,Cc=128,Wd=127,Xd=~Wd,Qd=Math.pow(2,31);function Tc(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Qd;)e[r++]=t&255|Cc,t/=128;for(;t&Xd;)e[r++]=t&255|Cc,t>>>=7;return e[r]=t|0,Tc.bytes=r-n+1,e}var Jd=ws,eh=128,_c=127;function ws(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw ws.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&_c)<<o:(i&_c)*Math.pow(2,o),o+=7}while(i>=eh);return ws.bytes=s-n,r}var th=Math.pow(2,7),rh=Math.pow(2,14),nh=Math.pow(2,21),oh=Math.pow(2,28),sh=Math.pow(2,35),ih=Math.pow(2,42),ah=Math.pow(2,49),ch=Math.pow(2,56),fh=Math.pow(2,63),uh=function(t){return t<th?1:t<rh?2:t<nh?3:t<oh?4:t<sh?5:t<ih?6:t<ah?7:t<ch?8:t<fh?9:10},lh={encode:Zd,decode:Jd,encodingLength:uh},dh=lh,jr=dh;function Yr(t,e=0){return[jr.decode(t,e),jr.decode.bytes]}function nr(t,e,r=0){return jr.encode(t,e,r),e}function or(t){return jr.encodingLength(t)}function ir(t,e){let r=e.byteLength,n=or(t),o=n+or(r),s=new Uint8Array(o+r);return nr(t,s,0),nr(r,s,n),s.set(e,o),new sr(t,r,e,s)}function Dc(t){let e=tt(t),[r,n]=Yr(e),[o,s]=Yr(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new sr(r,o,i,e)}function Bc(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&xc(t.bytes,r.bytes)}}var sr=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=Ot(n),this.bytes=Ot(o)}};var Oc=0,hh="identity",Lc=tt;function ph(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 ir(Oc,Lc(t))}var mh={code:Oc,name:hh,encode:Lc,digest:ph};var As={};Z(As,{sha256:()=>bh,sha512:()=>gh});var yh=20;function Ss({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new vs(t,e,r,n,o)}var vs=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??yh,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?Pc(n,this.code,r?.truncate):n.then(o=>Pc(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Pc(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 ir(e,t)}function Nc(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var bh=Ss({name:"sha2-256",code:18,encode:Nc("SHA-256")}),gh=Ss({name:"sha2-512",code:19,encode:Nc("SHA-512")});function Fc(t,e){let{bytes:r,version:n}=t;return n===0?wh(r,Is(t),e??He.encoder):Eh(r,Is(t),e??rr.encoder)}var kc=new WeakMap;function Is(t){let e=kc.get(t);if(e==null){let r=new Map;return kc.set(t,r),r}return e}var Vn=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!==Zr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==vh)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=ir(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&&Bc(e.multihash,n.multihash)}toString(e){return Fc(this,e)}toJSON(){return{"/":Fc(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??Uc(n,o,s.bytes))}else if(r[Sh]===!0){let{version:n,multihash:o,code:s}=r,i=Dc(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!==Zr)throw new Error(`Version 0 CID must use dag-pb (code: ${Zr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=Uc(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Zr,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=tt(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 sr(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]=Yr(e.subarray(r));return r+=p,l},o=n(),s=Zr;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]=xh(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 Is(s).set(n,e),s}};function xh(t,e){switch(t[0]){case"Q":{let r=e??He;return[He.prefix,r.decode(`${He.prefix}${t}`)]}case He.prefix:{let r=e??He;return[He.prefix,r.decode(t)]}case rr.prefix:{let r=e??rr;return[rr.prefix,r.decode(t)]}case $r.prefix:{let r=e??$r;return[$r.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 wh(t,e,r){let{prefix:n}=r;if(n!==He.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o}function Eh(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 Zr=112,vh=18;function Uc(t,e,r){let n=or(t),o=n+or(e),s=new Uint8Array(o+r.byteLength);return nr(t,s,0),nr(e,s,n),s.set(r,o),s}var Sh=Symbol.for("@ipld/js-cid/CID");var Cs={...xs,...ds,...gs,...us,...ls,...ps,...ms,...ys,...bs,...hs},Eb={...As,...Es};function pt(t=0){return new Uint8Array(t)}function _s(t=0){return new Uint8Array(t)}function Kc(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Mc=Kc("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Ts=Kc("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=_s(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Ah={utf8:Mc,"utf-8":Mc,hex:Cs.base16,latin1:Ts,ascii:Ts,binary:Ts,...Cs},qn=Ah;function j(t,e="utf8"){let r=qn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function G(t,e="utf8"){let r=qn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var Ih=parseInt("11111",2),Ds=parseInt("10000000",2),Ch=parseInt("01111111",2),Vc={0:Wr,1:Wr,2:_h,3:Bh,4:Oh,5:Dh,6:Th,16:Wr,22:Wr,48:Wr};function rt(t,e={offset:0}){let r=t[e.offset]&Ih;if(e.offset++,Vc[r]!=null)return Vc[r](t,e);throw new Error("No decoder for tag "+r)}function Xr(t,e){let r=0;if((t[e.offset]&Ds)===Ds){let n=t[e.offset]&Ch,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 Wr(t,e){Xr(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=rt(t,e);if(n===null)break;r.push(n)}return r}function _h(t,e){let r=Xr(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 Th(t,e){let r=Xr(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 Dh(t,e){return e.offset++,null}function Bh(t,e){let r=Xr(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 Oh(t,e){let r=Xr(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function Lh(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new ae;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=Lh(t.byteLength);return new ae(Uint8Array.from([e.byteLength|Ds]),e)}function Se(t){let e=new ae,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new ae(Uint8Array.from([2]),Bs(e),e)}function zn(t){let e=Uint8Array.from([0]),r=new ae(e,t);return new ae(Uint8Array.from([3]),Bs(r),r)}function mt(t,e=48){let r=new ae;for(let n of t)r.append(n);return new ae(Uint8Array.from([e]),Bs(r),r)}var Ph=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Rh=Uint8Array.from([6,5,43,129,4,0,34]),Nh=Uint8Array.from([6,5,43,129,4,0,35]),Fh={ext:!0,kty:"EC",crv:"P-256"},kh={ext:!0,kty:"EC",crv:"P-384"},Uh={ext:!0,kty:"EC",crv:"P-521"},Os=32,Ls=48,Ps=66;function Rs(t){let e=rt(t);return qc(e)}function qc(t){let e=t[1][1][0],r=1,n,o;if(e.byteLength===Os*2+1)return n=G(e.subarray(r,r+Os),"base64url"),o=G(e.subarray(r+Os),"base64url"),new ar({...Fh,key_ops:["verify"],x:n,y:o});if(e.byteLength===Ls*2+1)return n=G(e.subarray(r,r+Ls),"base64url"),o=G(e.subarray(r+Ls),"base64url"),new ar({...kh,key_ops:["verify"],x:n,y:o});if(e.byteLength===Ps*2+1)return n=G(e.subarray(r,r+Ps),"base64url"),o=G(e.subarray(r+Ps),"base64url"),new ar({...Uh,key_ops:["verify"],x:n,y:o});throw new J(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function zc(t){return mt([Se(Uint8Array.from([1])),mt([Mh(t.crv)],160),mt([zn(new ae(Uint8Array.from([4]),j(t.x??"","base64url"),j(t.y??"","base64url")))],161)]).subarray()}function Mh(t){if(t==="P-256")return Ph;if(t==="P-384")return Rh;if(t==="P-521")return Nh;throw new J(`Invalid curve ${t}`)}var ar=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=zc(this.jwk)),this._raw}toMultihash(){return Be.digest($e(this))}toCID(){return de.createV1(114,this.toMultihash())}toString(){return se.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ve(this.raw,e.raw)}async verify(e,r,n){return mc(this.jwk,r,e,n)}};function Ns(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}function yt(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 Ce(t,e,r=""){let n=Ns(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 Hn(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(yt(t.outputLen),yt(t.blockLen),t.outputLen<1)throw new Error('"outputLen" must be >= 1');if(t.blockLen<1)throw new Error('"blockLen" must be >= 1')}function cr(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 $n(t,e){Ce(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 ot(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function jn(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Oe(t,e){return t<<32-e|t>>>e}var $c=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Kh=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Yn(t){if(Ce(t),$c)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=Kh[t[r]];return e}var nt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Hc(t){if(t>=nt._0&&t<=nt._9)return t-nt._0;if(t>=nt.A&&t<=nt.F)return t-(nt.A-10);if(t>=nt.a&&t<=nt.f)return t-(nt.a-10)}function Qr(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if($c)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=Hc(t.charCodeAt(s)),a=Hc(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 Fs(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];Ce(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 ks(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 jc(t=32){yt(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 Us=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function Yc(t,e,r){return t&e^~t&r}function Gc(t,e,r){return t&e^t&r^e&r}var Jr=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=jn(this.buffer)}update(e){cr(this),Ce(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=jn(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){cr(this),$n(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,ot(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=jn(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()}},st=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 Gn=BigInt(4294967295),Zc=BigInt(32);function Vh(t,e=!1){return e?{h:Number(t&Gn),l:Number(t>>Zc&Gn)}:{h:Number(t>>Zc&Gn)|0,l:Number(t&Gn)|0}}function Wc(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}=Vh(t[s],e);[n[s],o[s]]=[i,a]}return[n,o]}var Ms=(t,e,r)=>t>>>r,Ks=(t,e,r)=>t<<32-r|e>>>r,Lt=(t,e,r)=>t>>>r|e<<32-r,Pt=(t,e,r)=>t<<32-r|e>>>r,en=(t,e,r)=>t<<64-r|e>>>r-32,tn=(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 Xc=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Qc=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,Jc=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),ef=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,tf=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),rf=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0;var zh=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]),bt=new Uint32Array(64),Vs=class extends Jr{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)bt[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let p=bt[l-15],h=bt[l-2],d=Oe(p,7)^Oe(p,18)^p>>>3,b=Oe(h,17)^Oe(h,19)^h>>>10;bt[l]=b+bt[l-7]+d+bt[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=Oe(a,6)^Oe(a,11)^Oe(a,25),h=u+p+Yc(a,c,f)+zh[l]+bt[l]|0,b=(Oe(n,2)^Oe(n,13)^Oe(n,22))+Gc(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(){ot(bt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),ot(this.buffer)}},qs=class extends Vs{A=st[0]|0;B=st[1]|0;C=st[2]|0;D=st[3]|0;E=st[4]|0;F=st[5]|0;G=st[6]|0;H=st[7]|0;constructor(){super(32)}};var nf=Wc(["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))),Hh=nf[0],$h=nf[1],gt=new Uint32Array(80),xt=new Uint32Array(80),zs=class extends Jr{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)gt[S]=e.getUint32(r),xt[S]=e.getUint32(r+=4);for(let S=16;S<80;S++){let T=gt[S-15]|0,_=xt[S-15]|0,R=Lt(T,_,1)^Lt(T,_,8)^Ms(T,_,7),O=Pt(T,_,1)^Pt(T,_,8)^Ks(T,_,7),C=gt[S-2]|0,F=xt[S-2]|0,Y=Lt(C,F,19)^en(C,F,61)^Ms(C,F,6),k=Pt(C,F,19)^tn(C,F,61)^Ks(C,F,6),y=Jc(O,k,xt[S-7],xt[S-16]),x=ef(y,R,Y,gt[S-7],gt[S-16]);gt[S]=x|0,xt[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=Lt(l,p,14)^Lt(l,p,18)^en(l,p,41),_=Pt(l,p,14)^Pt(l,p,18)^tn(l,p,41),R=l&h^~l&b,O=p&d^~p&m,C=tf(v,_,O,$h[S],xt[S]),F=rf(C,g,T,R,Hh[S],gt[S]),Y=C|0,k=Lt(n,o,28)^en(n,o,34)^en(n,o,39),y=Pt(n,o,28)^tn(n,o,34)^tn(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,F|0,Y|0),f=a|0,u=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let E=Xc(Y,y,A);n=Qc(E,F,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(){ot(gt,xt)}destroy(){this.destroyed=!0,ot(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Hs=class extends zs{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 fr=ks(()=>new qs,Us(1));var Zn=ks(()=>new Hs,Us(3));var V=(t,e,r)=>Ce(t,e,r),js=yt,ur=Yn,fe=(...t)=>Fs(...t),lr=t=>Qr(t),Rt=Ns,rn=t=>jc(t),Xn=BigInt(0),$s=BigInt(1);function Le(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}" `;throw new TypeError(r+"expected boolean, got type="+typeof t)}return t}function Qn(t){if(typeof t=="bigint"){if(!Wn(t))throw new RangeError("positive bigint expected, got "+t)}else js(t);return t}function Pe(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 nn(t){let e=Qn(t).toString(16);return e.length&1?"0"+e:e}function of(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?Xn:BigInt("0x"+t)}function Nt(t){return of(Yn(t))}function Ye(t){return of(Yn(on(Ce(t)).reverse()))}function Jn(t,e){if(yt(e),e===0)throw new RangeError("zero length");t=Qn(t);let r=t.toString(16);if(r.length>e*2)throw new RangeError("number too large");return Qr(r.padStart(e*2,"0"))}function Ys(t,e){return Jn(t,e).reverse()}function sf(t,e){if(t=V(t),e=V(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 on(t){return Uint8Array.from(V(t))}function eo(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 Wn=t=>typeof t=="bigint"&&Xn<=t;function jh(t,e,r){return Wn(t)&&Wn(e)&&Wn(r)&&e<=t&&t<r}function dr(t,e,r,n){if(!jh(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function hr(t){if(t<Xn)throw new Error("expected non-negative bigint, got "+t);let e;for(e=0;t>Xn;t>>=$s,e+=1);return e}var sn=t=>($s<<BigInt(t))-$s;function af(t,e,r){if(yt(t,"hashLen"),yt(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,fe(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 fe(...g)};return(m,g)=>{l(),h(m);let v;for(;(v=g(d()))===void 0;)h();return l(),v}}function Re(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 Gs=()=>{throw new Error("not implemented")};var ye=BigInt(0),ne=BigInt(1),Ft=BigInt(2),lf=BigInt(3),df=BigInt(4),hf=BigInt(5),Yh=BigInt(7),pf=BigInt(8),Gh=BigInt(9),mf=BigInt(16);function ie(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 Q(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 cf(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=ie(t,e),n=e,o=ye,s=ne,i=ne,a=ye;for(;r!==ye;){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 ie(o,e)}function Zs(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function yf(t,e){let r=t,n=(r.ORDER+ne)/df,o=r.pow(e,n);return Zs(r,o,e),o}function Zh(t,e){let r=t,n=(r.ORDER-hf)/pf,o=r.mul(e,Ft),s=r.pow(o,n),i=r.mul(e,s),a=r.mul(r.mul(i,Ft),s),c=r.mul(i,r.sub(a,r.ONE));return Zs(r,c,e),c}function Wh(t){let e=pr(t),r=bf(t),n=r(e,e.neg(e.ONE)),o=r(e,n),s=r(e,e.neg(n)),i=(t+Yh)/mf;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 Zs(f,g,c),g})}function bf(t){if(t<lf)throw new Error("sqrt is not defined for small field");let e=t-ne,r=0;for(;e%Ft===ye;)e/=Ft,r++;let n=Ft,o=pr(t);for(;ff(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return yf;let s=o.pow(n,e),i=(e+ne)/Ft;return function(c,f){let u=c;if(u.is0(f))return f;if(ff(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 Xh(t){return t%df===lf?yf:t%pf===hf?Zh:t%mf===Gh?Wh(t):bf(t)}var it=(t,e)=>(ie(t,e)&ne)===ne,Qh=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ws(t){let e={ORDER:"bigint",BYTES:"number",BITS:"number"},r=Qh.reduce((n,o)=>(n[o]="function",n),e);if(Re(t,r),Pe(t.BYTES,"BYTES"),Pe(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 Jh(t,e,r){let n=t;if(r<ye)throw new Error("invalid exponent, negatives unsupported");if(r===ye)return n.ONE;if(r===ne)return e;let o=n.ONE,s=e;for(;r>ye;)r&ne&&(o=n.mul(o,s)),s=n.sqr(s),r>>=ne;return o}function an(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 ff(t,e){let r=t,n=(r.ORDER-ne)/Ft,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 ep(t,e){if(e!==void 0&&js(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=hr(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 uf=new WeakMap,to=class{ORDER;BITS;BYTES;isLE;ZERO=ye;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}=ep(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 ie(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&ne)===ne}neg(e){return ie(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return ie(e*e,this.ORDER)}add(e,r){return ie(e+r,this.ORDER)}sub(e,r){return ie(e-r,this.ORDER)}mul(e,r){return ie(e*r,this.ORDER)}pow(e,r){return Jh(this,e,r)}div(e,r){return ie(e*cf(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 cf(e,this.ORDER)}sqrt(e){let r=uf.get(this);return r||uf.set(this,r=Xh(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?Ys(e,this.BYTES):Jn(e,this.BYTES)}fromBytes(e,r=!1){V(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):Nt(e);if(a&&(c=ie(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return an(this,e)}cmov(e,r,n){return Le(n,"condition"),n?r:e}};Object.freeze(to.prototype);function pr(t,e={}){return new to(t,e)}function gf(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=hr(t-ne);return Math.ceil(e/8)}function Xs(t){let e=gf(t);return e+Math.ceil(e/2)}function Qs(t,e,r=!1){V(t);let n=t.length,o=gf(e),s=Math.max(Xs(e),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Ye(t):Nt(t),a=ie(i,e-ne)+ne;return r?Ys(a,o):Jn(a,o)}var mr=BigInt(0),kt=BigInt(1);function cn(t,e){let r=e.negate();return t?r:e}function Ut(t,e){let r=an(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function vf(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function Js(t,e){vf(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),o=2**t,s=sn(t),i=BigInt(t);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function xf(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+=kt);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 ei=new WeakMap,Sf=new WeakMap;function ti(t){return Sf.get(t)||1}function wf(t){if(t!==mr)throw new Error("invalid wNAF")}var yr=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>mr;)r&kt&&(n=n.add(o)),o=o.double(),r>>=kt;return n}precomputeWindow(e,r){let{windows:n,windowSize:o}=Js(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=Js(e,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:f,isZero:u,isNeg:l,isNegF:p,offsetF:h}=xf(n,a,i);n=c,u?s=s.add(cn(p,r[h])):o=o.add(cn(l,r[f]))}return wf(n),{p:o,f:s}}wNAFUnsafe(e,r,n,o=this.ZERO){let s=Js(e,this.bits);for(let i=0;i<s.windows&&n!==mr;i++){let{nextN:a,offset:c,isZero:f,isNeg:u}=xf(n,i,s);if(n=a,!f){let l=r[c];o=o.add(u?l.negate():l)}}return wf(n),o}getPrecomputes(e,r,n){let o=ei.get(r);return o||(o=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(o=n(o)),ei.set(r,o))),o}cached(e,r,n){let o=ti(e);return this.wNAF(o,this.getPrecomputes(o,e,n),r)}unsafe(e,r,n,o){let s=ti(e);return s===1?this._unsafeLadder(e,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,e,n),r,o)}createCache(e,r){vf(r,this.bits),Sf.set(e,r),ei.delete(e)}hasCache(e){return ti(e)!==1}};function Af(t,e,r,n){let o=e,s=t.ZERO,i=t.ZERO;for(;r>mr||n>mr;)r&kt&&(s=s.add(o)),n&kt&&(i=i.add(o)),o=o.double(),r>>=kt,n>>=kt;return{p1:s,p2:i}}function Ef(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Ws(e),e}else return pr(t,{isLE:r})}function ro(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>mr))throw new Error(`CURVE.${c} must be positive bigint`)}let o=Ef(e.p,r.Fp,n),s=Ef(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 no(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}var wt=BigInt(0),he=BigInt(1),ri=BigInt(2),tp=BigInt(8);function rp(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 If(t,e={}){let r=e,n=ro("edwards",t,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;Re(r,{},{uvRatio:"function"});let c=ri<<BigInt(s.BYTES*8)-he,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:wt}}}:r.uvRatio;if(!rp(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function l(b,m,g=!1){let v=g?he:wt;return dr("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,he,f(i.Gx*i.Gy));static ZERO=new h(wt,he,he,wt);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,he,f(g*v))}static fromBytes(m,g=!1){let v=o.BYTES,{a:S,d:T}=i;m=on(V(m,v,"point")),Le(g,"zip215");let _=on(m),R=m[v-1];_[v-1]=R&-129;let O=Ye(_),C=g?c:o.ORDER;dr("point.y",O,wt,C);let F=f(O*O),Y=f(F-he),k=f(T*F-S),{isValid:y,value:x}=u(Y,k);if(!y)throw new Error("bad point: invalid y coordinate");let A=(x&he)===he,E=(R&128)!==0;if(!g&&x===wt&&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(lr(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(ri),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),F=f(_*_),Y=f(F*F),k=f(O*g),y=f(F*f(k+C)),x=f(Y+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),F=f(v*R),Y=f(_*S);return O===C&&F===Y}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(ri*f(S*S)),O=f(m*T),C=g+v,F=f(f(C*C)-T-_),Y=O+_,k=Y-R,y=O-_,x=f(F*k),A=f(Y*y),E=f(F*y),w=f(k*Y);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:F,T:Y}=m,k=f(S*O),y=f(T*C),x=f(R*v*Y),A=f(_*F),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),N=f(E*B),K=f(w*I);return new h(D,L,K,N)}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=>Ut(h,S));return Ut(h,[g,v])[0]}multiplyUnsafe(m){if(!s.isValid(m))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return m===wt?h.ZERO:this.is0()||m===he?this:d.unsafe(this,m,g=>Ut(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?tp:o.inv(_));let O=f(S*v),C=f(T*v),F=o.mul(_,v);if(R)return{x:wt,y:he};if(F!==he)throw new Error("invZ was invalid");return{x:O,y:C}}clearCofactor(){return a===he?this:this.multiplyUnsafe(a)}toBytes(){let{x:m,y:g}=this.toAffine(),v=o.toBytes(g);return v[v.length-1]|=m&he?128:0,v}toHex(){return ur(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let d=new yr(h,s.BITS);return s.BITS>=8&&h.BASE.precompute(8),Object.freeze(h.prototype),Object.freeze(h),h}var oo=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(e){this.ep=e}static fromBytes(e){Gs()}static fromHex(e){Gs()}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 ur(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 Cf(t,e,r={}){if(typeof e!="function")throw new Error('"hash" function param is required');let n=e,o=r;Re(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&&(Pe(f,"hash.outputLen"),f!==u))throw new Error(`hash.outputLen must be ${u}, got ${f}`);let l=o.randomBytes===void 0?rn:o.randomBytes,p=o.adjustScalarBytes===void 0?y=>y:o.adjustScalarBytes,h=o.domain===void 0?(y,x,A)=>{if(Le(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;V(y,O.secretKey,"secretKey");let A=V(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=fe(...x);return d(n(h(A,V(y,void 0,"context"),!!s)))}function S(y,x,A={}){y=V(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),N=c.create(B+L*w);if(!c.isValid(N))throw new Error("sign failed: invalid s");let K=fe(D,c.toBytes(N));return V(K,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=V(y,B,"signature"),x=V(x,void 0,"message"),A=V(A,O.publicKey,"publicKey"),I!==void 0&&Le(I,"zip215"),s&&(x=s(x));let D=B/2,L=y.subarray(0,D),N=Ye(y.subarray(D,B)),K,H,U;try{K=t.fromBytes(A,I),H=t.fromBytes(L,I),U=i.multiplyUnsafe(N)}catch{return!1}if(!I&&K.isSmallOrder())return!1;let ce=v(w,L,A,x);return H.add(K.multiplyUnsafe(ce)).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,V(y,O.seed,"seed")}function F(y){return Rt(y)&&y.length===O.secretKey}function Y(y,x){try{return!!t.fromBytes(y,x===void 0?T.zip215:x)}catch{return!1}}let k={getExtendedPublicKey:m,randomSecretKey:C,isValidSecretKey:F,isValidPublicKey:Y,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(he+x,he-x):a.div(x-he,x+he);return a.toBytes(w)},toMontgomerySecret(y){let x=O.secretKey;V(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:no(C,g),getPublicKey:g,sign:S,verify:_,utils:k,Point:t,lengths:O})}function fn(t,e){if(Pe(t),Pe(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 np(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 op(t){if(!Rt(t)&&typeof t!="string")throw new Error("DST must be Uint8Array or ascii string");let e=typeof t=="string"?eo(t):t;if(e.length===0)throw new Error("DST must be non-empty");return e}function ni(t,e,r,n){V(t),Pe(r),e=op(e),e.length>255&&(e=n(fe(eo("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=fe(e,fn(e.length,1)),c=new Uint8Array(s),f=fn(r,2),u=new Array(i),l=n(fe(c,t,f,fn(0,1),a));u[0]=n(fe(l,fn(1,1),a));for(let h=1;h<i;h++){let d=[np(l,u[h-1]),fn(h+1,1),a];u[h]=n(fe(...d))}return fe(...u).slice(0,r)}var _f="HashToScalar-";var sp=BigInt(0),at=BigInt(1),Tf=BigInt(2);var ip=BigInt(5),ap=BigInt(8),br=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),ai={p:br,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:ap,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function cp(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=br,a=t*t%s*t%s,c=Q(a,Tf,s)*a%s,f=Q(c,at,s)*t%s,u=Q(f,ip,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,Tf,s)*t%s,b2:a}}function fp(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var oi=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function ci(t,e){let r=br,n=ie(e*e*e,r),o=ie(n*n*e,r),s=cp(t*o).pow_p_5_8,i=ie(t*n*s,r),a=ie(e*i*i,r),c=i,f=ie(i*oi,r),u=a===t,l=a===ie(-t,r),p=a===ie(-t*oi,r);return u&&(i=c),(l||p)&&(i=f),it(i,r)&&(i=ie(-i,r)),{isValid:u||l,value:i}}var vt=If(ai,{uvRatio:ci}),Et=vt.Fp,Of=vt.Fn;function up(t){return Cf(vt,Zn,Object.assign({adjustScalarBytes:fp,zip215:!0},t))}var Lf=up({});var si=oi,lp=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),dp=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),hp=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),pp=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Df=t=>ci(at,t),mp=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),ii=t=>Et.create(Ye(t)&mp);function Bf(t){let{d:e}=ai,r=br,n=g=>Et.create(g),o=n(si*t*t),s=n((o+at)*hp),i=BigInt(-1),a=n((i-e*o)*n(o+e)),{isValid:c,value:f}=ci(s,a),u=n(f*t);it(u,r)||(u=n(-u)),c||(f=u),c||(i=o);let l=n(i*(o-at)*pp-a),p=f*f,h=n((f+f)*a),d=n(l*lp),b=n(at-p),m=n(at+p);return new vt(n(h*m),n(b*d),n(d*m),n(h*b))}var St=class t extends oo{static BASE=new t(vt.BASE);static ZERO=new t(vt.ZERO);static Fp=Et;static Fn=Of;constructor(e){super(e)}static fromAffine(e){return new t(vt.fromAffine(e))}assertSame(e){if(!(e instanceof t))throw new Error("RistrettoPoint expected")}init(e){return new t(e)}static fromBytes(e){Ce(e,32);let{a:r,d:n}=ai,o=br,s=T=>Et.create(T),i=ii(e);if(!sf(Et.toBytes(i),e)||it(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(at+r*a),f=s(at-r*a),u=s(c*c),l=s(f*f),p=s(r*n*u-l),{isValid:h,value:d}=Df(s(p*l)),b=s(d*f),m=s(d*b*p),g=s((i+i)*b);it(g,o)&&(g=s(-g));let v=s(c*m),S=s(g*v);if(!h||it(S,o)||v===sp)throw new Error("invalid ristretto255 encoding 2");return new t(new vt(g,v,at,S))}static fromHex(e){return t.fromBytes(Qr(e))}toBytes(){let{X:e,Y:r,Z:n,T:o}=this.ep,s=br,i=m=>Et.create(m),a=i(i(n+r)*i(n-r)),c=i(e*r),f=i(c*c),{value:u}=Df(i(a*f)),l=i(u*a),p=i(u*c),h=i(l*p*o),d;if(it(o*h,s)){let m=i(r*si),g=i(e*si);e=m,r=g,d=i(l*dp)}else d=p;it(e*h,s)&&(r=i(-r));let b=i((n-r)*d);return it(b,s)&&(b=i(-b)),Et.toBytes(b)}equals(e){this.assertSame(e);let{X:r,Y:n}=this.ep,{X:o,Y:s}=e.ep,i=f=>Et.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(St.BASE);Object.freeze(St.ZERO);Object.freeze(St.prototype);Object.freeze(St);var yp=Object.freeze({Point:St,hashToCurve(t,e){let r=e?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":e.DST,n=ni(t,r,64,Zn);return yp.deriveToCurve(n)},hashToScalar(t,e={DST:_f}){let r=ni(t,e.DST,64,Zn);return Of.create(Ye(r))},deriveToCurve(t){Ce(t,64);let e=ii(t.subarray(0,32)),r=Bf(e),n=ii(t.subarray(32,64)),o=Bf(n);return new St(r.add(o))}});var un=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},so=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var Te={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new so("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 io=32;var fi,bp=(async()=>{try{return await Te.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function gp(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await Te.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await Te.get().subtle.verify({name:"Ed25519"},n,ze(e),ze(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function xp(t,e,r){return Lf.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function Pf(t,e,r){return fi==null&&(fi=await bp),fi?gp(t,e,r):xp(t,e,r)}function ao(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var co=class{type="Ed25519";raw;constructor(e){this.raw=ui(e,io)}toMultihash(){return Be.digest($e(this))}toCID(){return de.createV1(114,this.toMultihash())}toString(){return se.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ve(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let o=Pf(this.raw,r,e);return ao(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function li(t){return t=ui(t,io),new co(t)}function ui(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 Nf(t=0){return new Uint8Array(t)}var Ep=Math.pow(2,7),vp=Math.pow(2,14),Sp=Math.pow(2,21),di=Math.pow(2,28),hi=Math.pow(2,35),pi=Math.pow(2,42),mi=Math.pow(2,49),$=128,ge=127;function Ae(t){if(t<Ep)return 1;if(t<vp)return 2;if(t<Sp)return 3;if(t<di)return 4;if(t<hi)return 5;if(t<pi)return 6;if(t<mi)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function gr(t,e,r=0){switch(Ae(t)){case 8:e[r++]=t&255|$,t/=128;case 7:e[r++]=t&255|$,t/=128;case 6:e[r++]=t&255|$,t/=128;case 5:e[r++]=t&255|$,t/=128;case 4:e[r++]=t&255|$,t>>>=7;case 3:e[r++]=t&255|$,t>>>=7;case 2:e[r++]=t&255|$,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Ap(t,e,r=0){switch(Ae(t)){case 8:e.set(r++,t&255|$),t/=128;case 7:e.set(r++,t&255|$),t/=128;case 6:e.set(r++,t&255|$),t/=128;case 5:e.set(r++,t&255|$),t/=128;case 4:e.set(r++,t&255|$),t>>>=7;case 3:e.set(r++,t&255|$),t>>>=7;case 2:e.set(r++,t&255|$),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function yi(t,e){let r=t[e],n=0;if(n+=r&ge,r<$||(r=t[e+1],n+=(r&ge)<<7,r<$)||(r=t[e+2],n+=(r&ge)<<14,r<$)||(r=t[e+3],n+=(r&ge)<<21,r<$)||(r=t[e+4],n+=(r&ge)*di,r<$)||(r=t[e+5],n+=(r&ge)*hi,r<$)||(r=t[e+6],n+=(r&ge)*pi,r<$)||(r=t[e+7],n+=(r&ge)*mi,r<$))return n;throw new RangeError("Could not decode varint")}function Ip(t,e){let r=t.get(e),n=0;if(n+=r&ge,r<$||(r=t.get(e+1),n+=(r&ge)<<7,r<$)||(r=t.get(e+2),n+=(r&ge)<<14,r<$)||(r=t.get(e+3),n+=(r&ge)<<21,r<$)||(r=t.get(e+4),n+=(r&ge)*di,r<$)||(r=t.get(e+5),n+=(r&ge)*hi,r<$)||(r=t.get(e+6),n+=(r&ge)*pi,r<$)||(r=t.get(e+7),n+=(r&ge)*mi,r<$))return n;throw new RangeError("Could not decode varint")}function xr(t,e,r=0){return e==null&&(e=Nf(Ae(t))),e instanceof Uint8Array?gr(t,e,r):Ap(t,e,r)}function ln(t,e=0){return t instanceof Uint8Array?yi(t,e):Ip(t,e)}var gi=new Float32Array([-0]),At=new Uint8Array(gi.buffer);function Ff(t,e,r){gi[0]=t,e[r]=At[0],e[r+1]=At[1],e[r+2]=At[2],e[r+3]=At[3]}function kf(t,e){return At[0]=t[e],At[1]=t[e+1],At[2]=t[e+2],At[3]=t[e+3],gi[0]}var xi=new Float64Array([-0]),xe=new Uint8Array(xi.buffer);function Uf(t,e,r){xi[0]=t,e[r]=xe[0],e[r+1]=xe[1],e[r+2]=xe[2],e[r+3]=xe[3],e[r+4]=xe[4],e[r+5]=xe[5],e[r+6]=xe[6],e[r+7]=xe[7]}function Mf(t,e){return xe[0]=t[e],xe[1]=t[e+1],xe[2]=t[e+2],xe[3]=t[e+3],xe[4]=t[e+4],xe[5]=t[e+5],xe[6]=t[e+6],xe[7]=t[e+7],xi[0]}var Cp=BigInt(Number.MAX_SAFE_INTEGER),_p=BigInt(Number.MIN_SAFE_INTEGER),_e=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 Mt;if(e<Cp&&e>_p)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>Kf&&(o=0n,++n>Kf&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return Mt;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):Mt}},Mt=new _e(0,0);Mt.toBigInt=function(){return 0n};Mt.zzEncode=Mt.zzDecode=function(){return this};Mt.length=function(){return 1};var Kf=4294967296n;function Vf(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 qf(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 wi(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 Ne(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function fo(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var Ei=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,Ne(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 Ne(this,4);return fo(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ne(this,4);return fo(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ne(this,4);let e=kf(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ne(this,4);let e=Mf(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 Ne(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return qf(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ne(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ne(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 _e(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 Ne(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 Ne(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 Ne(this,8);let e=fo(this.buf,this.pos+=4),r=fo(this.buf,this.pos+=4);return new _e(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=yi(this.buf,this.pos);return this.pos+=Ae(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 dn(t){return new Ei(t instanceof Uint8Array?t:t.subarray())}function Fe(t,e,r){let n=dn(t);return e.decode(n,void 0,r)}function Kt(t=0){return new Uint8Array(t)}var vi={};Z(vi,{base10:()=>Tp});var Tp=lt({prefix:"9",name:"base10",alphabet:"0123456789"});var Si={};Z(Si,{base16:()=>Dp,base16upper:()=>Bp});var Dp=te({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Bp=te({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Ai={};Z(Ai,{base2:()=>Op});var Op=te({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ii={};Z(Ii,{base256emoji:()=>Fp});var Hf=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}"),Lp=Hf.reduce((t,e,r)=>(t[r]=e,t),[]),Pp=Hf.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Rp(t){return t.reduce((e,r)=>(e+=Lp[r],e),"")}function Np(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Pp[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Fp=Xt({prefix:"\u{1F680}",name:"base256emoji",encode:Rp,decode:Np});var _i={};Z(_i,{base64:()=>kp,base64pad:()=>Up,base64url:()=>Ci,base64urlpad:()=>Mp});var kp=te({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Up=te({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ci=te({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Mp=te({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ti={};Z(Ti,{base8:()=>Kp});var Kp=te({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Di={};Z(Di,{identity:()=>Vp});var Vp=Xt({prefix:"\0",name:"identity",encode:t=>rc(t),decode:t=>tc(t)});var Sx=new TextEncoder,Ax=new TextDecoder;var Li={};Z(Li,{sha256:()=>hn,sha512:()=>$p});var Hp=20;function Oi({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new Bi(t,e,r,n,o)}var Bi=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??Hp,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?$f(n,this.code,r?.truncate):n.then(o=>$f(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function $f(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 qe(e,t)}function Yf(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var hn=Oi({name:"sha2-256",code:18,encode:Yf("SHA-256")}),$p=Oi({name:"sha2-512",code:19,encode:Yf("SHA-512")});var It={...Di,...Ai,...Ti,...vi,...Si,...es,...ts,...Jo,..._i,...Ii},Fx={...Li,...os};function Zf(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Gf=Zf("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Pi=Zf("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=Kt(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),jp={utf8:Gf,"utf-8":Gf,hex:It.base16,latin1:Pi,ascii:Pi,binary:Pi,...It},Wf=jp;function Xf(t,e="utf8"){let r=Wf[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function Ri(t){let e=t??8192,r=e>>>1,n,o=e;return function(i){if(i<1||i>r)return Kt(i);o+i>e&&(n=Kt(e),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Vt=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function Ni(){}var ki=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Yp=Ri();function Gp(t){return globalThis.Buffer!=null?Kt(t):Yp(t)}var mn=class{len;head;tail;states;constructor(){this.len=0,this.head=new Vt(Ni,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Vt(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Ui((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,_e.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=_e.fromBigInt(e);return this._push(uo,r.length(),r)}uint64Number(e){return this._push(gr,Ae(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=_e.fromBigInt(e).zzEncode();return this._push(uo,r.length(),r)}sint64Number(e){let r=_e.fromNumber(e).zzEncode();return this._push(uo,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Fi,1,e?1:0)}fixed32(e){return this._push(pn,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=_e.fromBigInt(e);return this._push(pn,4,r.lo)._push(pn,4,r.hi)}fixed64Number(e){let r=_e.fromNumber(e);return this._push(pn,4,r.lo)._push(pn,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(Ff,4,e)}double(e){return this._push(Uf,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(Fi,1,0):this.uint32(r)._push(Wp,r,e)}string(e){let r=Vf(e);return r!==0?this.uint32(r)._push(wi,r,e):this._push(Fi,1,0)}fork(){return this.states=new ki(this),this.head=this.tail=new Vt(Ni,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 Vt(Ni,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=Gp(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function Fi(t,e,r){e[r]=t&255}function Zp(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var Ui=class extends Vt{next;constructor(e,r){super(Zp,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 pn(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 Wp(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(mn.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(Xp,e,t),this},mn.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(Qp,e,t),this});function Xp(t,e,r){e.set(t,r)}function Qp(t,e,r){t.length<40?wi(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(Xf(t),r)}function Mi(){return new mn}function ke(t,e){let r=Mi();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*Ue(t,e,r){let n=dn(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 Ki(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 Me(t,e,r){return ho("message",lo.LENGTH_DELIMITED,t,e,r)}var Ge=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 Vi;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(Vi||(Vi={}));(function(t){t.codec=()=>Ki(Vi)})(ee||(ee={}));var Ze;(function(t){let e;t.codec=()=>(e==null&&(e=Me((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 ke(s,t.codec())}t.encode=r;function n(s,i){return Fe(s,t.codec(),i)}t.decode=n;function o(s,i){return Ue(s,t.codec(),i)}t.stream=o})(Ze||(Ze={}));var qi;(function(t){let e;t.codec=()=>(e==null&&(e=Me((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 ke(s,t.codec())}t.encode=r;function n(s,i){return Fe(s,t.codec(),i)}t.decode=n;function o(s,i){return Ue(s,t.codec(),i)}t.stream=o})(qi||(qi={}));var bn={};Z(bn,{MAX_RSA_KEY_SIZE:()=>zi,generateRSAKeyPair:()=>ru,jwkToJWKKeyPair:()=>nu,jwkToPkcs1:()=>rm,jwkToPkix:()=>Yi,jwkToRSAPrivateKey:()=>Xi,pkcs1MessageToJwk:()=>$i,pkcs1MessageToRSAPrivateKey:()=>Gi,pkcs1ToJwk:()=>tm,pkcs1ToRSAPrivateKey:()=>tu,pkixMessageToJwk:()=>ji,pkixMessageToRSAPublicKey:()=>Wi,pkixToJwk:()=>nm,pkixToRSAPublicKey:()=>Zi});var wr=class{type="RSA";jwk;_raw;_multihash;constructor(e,r){this.jwk=e,this._multihash=r}get raw(){return this._raw==null&&(this._raw=bn.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return de.createV1(114,this._multihash)}toString(){return se.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ve(this.raw,e.raw)}verify(e,r,n){return eu(this.jwk,r,e,n)}},yn=class{type="RSA";jwk;_raw;publicKey;constructor(e,r){this.jwk=e,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=bn.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ve(this.raw,e.raw)}sign(e,r){return Jf(this.jwk,e,r)}};var zi=8192,Hi=18,Jp=1062,em=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function tm(t){let e=rt(t);return $i(e)}function $i(t){return{n:G(t[1],"base64url"),e:G(t[2],"base64url"),d:G(t[3],"base64url"),p:G(t[4],"base64url"),q:G(t[5],"base64url"),dp:G(t[6],"base64url"),dq:G(t[7],"base64url"),qi:G(t[8],"base64url"),kty:"RSA"}}function rm(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 mt([Se(Uint8Array.from([0])),Se(j(t.n,"base64url")),Se(j(t.e,"base64url")),Se(j(t.d,"base64url")),Se(j(t.p,"base64url")),Se(j(t.q,"base64url")),Se(j(t.dp,"base64url")),Se(j(t.dq,"base64url")),Se(j(t.qi,"base64url"))]).subarray()}function nm(t){let e=rt(t,{offset:0});return ji(e)}function ji(t){let e=rt(t[1],{offset:0});return{kty:"RSA",n:G(e[0],"base64url"),e:G(e[1],"base64url")}}function Yi(t){if(t.n==null||t.e==null)throw new J("JWK was missing components");return mt([em,zn(mt([Se(j(t.n,"base64url")),Se(j(t.e,"base64url"))]))]).subarray()}function tu(t){let e=rt(t);return Gi(e)}function Gi(t){let e=$i(t);return Xi(e)}function Zi(t,e){if(t.byteLength>=Jp)throw new Wt("Key size is too large");let r=rt(t,{offset:0});return Wi(r,t,e)}function Wi(t,e,r){let n=ji(t);if(r==null){let o=fr(Ze.encode({Type:ee.RSA,Data:e}));r=qe(Hi,o)}return new wr(n,r)}function Xi(t){if(su(t)>zi)throw new J("Key size is too large");let e=nu(t),r=fr(Ze.encode({Type:ee.RSA,Data:Yi(e.publicKey)})),n=qe(Hi,r);return new yn(e.privateKey,new wr(e.publicKey,n))}async function ru(t){if(t>zi)throw new J("Key size is too large");let e=await ou(t),r=fr(Ze.encode({Type:ee.RSA,Data:Yi(e.publicKey)})),n=qe(Hi,r);return new yn(e.privateKey,new wr(e.publicKey,n))}function nu(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 ou(t,e){let r=await Te.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 om(r,e);return{privateKey:n[0],publicKey:n[1]}}async function Jf(t,e,r){let n=await Te.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Te.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,ze(e instanceof Uint8Array?e:e.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function eu(t,e,r,n){let o=await Te.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Te.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,ze(e),ze(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),s}async function om(t,e){if(t.privateKey==null||t.publicKey==null)throw new J("Private and public key are required");let r=await Promise.all([Te.get().subtle.exportKey("jwk",t.privateKey),Te.get().subtle.exportKey("jwk",t.publicKey)]);return e?.signal?.throwIfAborted(),r}function su(t){if(t.kty!=="RSA")throw new J("invalid key type");if(t.n==null)throw new J("invalid key modulus");return j(t.n,"base64url").length*8}var po=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(Hn(e),Ce(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),ot(o)}update(e){return cr(this),this.iHash.update(e),this}digestInto(e){cr(this),$n(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()}},iu=(()=>{let t=((e,r,n)=>new po(e,r).update(n).digest());return t.create=(e,r)=>new po(e,r),t})();var au=(t,e)=>(t+(t>=0?e:-e)/cu)/e;function sm(t,e,r){dr("scalar",t,We,r);let[[n,o],[s,i]]=e,a=au(i*t,r),c=au(-o*t,r),f=t-a*n-c*s,u=-a*o-c*i,l=f<We,p=u<We;l&&(f=-f),p&&(u=-u);let h=sn(Math.ceil(hr(r)/2))+Ct;if(f<We||f>=h||u<We||u>=h)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:f,k2neg:p,k2:u}}function Ji(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Qi(t,e){Re(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Le(r.lowS,"lowS"),Le(r.prehash,"prehash"),r.format!==void 0&&Ji(r.format),r}var ea=class extends Error{constructor(e=""){super(e)}},Ke={Err:ea,_tlv:{encode:(t,e)=>{let{Err:r}=Ke;if(Pe(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=nn(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?nn(o.length/2|128):"";return nn(t)+s+o+e},decode(t,e){let{Err:r}=Ke;e=V(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}=Ke;if(Qn(t),t<We)throw new e("integer: negative integers are not allowed");let r=nn(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}=Ke;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 Nt(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=Ke,o=V(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}=Ke,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(Ke._tlv);Object.freeze(Ke._int);Object.freeze(Ke);var We=BigInt(0),Ct=BigInt(1),cu=BigInt(2),mo=BigInt(3),im=BigInt(4);function fu(t,e={}){let r=ro("weierstrass",t,e),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;Re(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=lu(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(Le(x,"isCompressed"),x){l();let I=!n.isOdd(E);return fe(uu(I),w)}else return fe(Uint8Array.of(4),w,n.toBytes(E))}function h(k){V(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(K){let H=K instanceof Error?": "+K.message:"";throw new Error("bad point: is not on curve, sqrt error"+H)}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),im),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 sm(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=cn(A,y),x=cn(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(V(y,void 0,"point")));return x.assertValidity(),x}static fromHex(y){return C.fromBytes(lr(y))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,x=!0){return Y.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,N=n.mul(E,E),K=n.mul(w,w),H=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,H),D=n.add(B,D),B=n.sub(K,D),D=n.add(K,D),D=n.mul(B,D),B=n.mul(U,B),L=n.mul(A,L),H=n.mul(y,H),U=n.sub(N,H),U=n.mul(y,U),U=n.add(U,L),L=n.add(N,N),N=n.add(L,N),N=n.add(N,H),N=n.mul(N,U),D=n.add(D,N),H=n.mul(w,I),H=n.add(H,H),N=n.mul(H,U),B=n.sub(B,N),L=n.mul(H,K),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,N=n.ZERO,K=s.a,H=n.mul(s.b,mo),U=n.mul(x,w),ce=n.mul(A,I),ue=n.mul(E,B),le=n.add(x,A),oe=n.add(w,I);le=n.mul(le,oe),oe=n.add(U,ce),le=n.sub(le,oe),oe=n.add(x,E);let Ee=n.add(w,B);return oe=n.mul(oe,Ee),Ee=n.add(U,ue),oe=n.sub(oe,Ee),Ee=n.add(A,E),D=n.add(I,B),Ee=n.mul(Ee,D),D=n.add(ce,ue),Ee=n.sub(Ee,D),N=n.mul(K,oe),D=n.mul(H,ue),N=n.add(D,N),D=n.sub(ce,N),N=n.add(ce,N),L=n.mul(D,N),ce=n.add(U,U),ce=n.add(ce,U),ue=n.mul(K,ue),oe=n.mul(H,oe),ce=n.add(ce,ue),ue=n.sub(U,ue),ue=n.mul(K,ue),oe=n.add(oe,ue),U=n.mul(ce,oe),L=n.add(L,U),U=n.mul(Ee,oe),D=n.mul(le,D),D=n.sub(D,U),U=n.mul(le,ce),N=n.mul(Ee,N),N=n.add(N,U),new C(D,L,N)}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=>Y.cached(this,I,B=>Ut(C,B));if(x){let{k1neg:I,k1:B,k2neg:D,k2:L}=R(y),{p:N,f:K}=w(B),{p:H,f:U}=w(L);E=K.add(U),A=O(x.beta,N,H,I,D)}else{let{p:I,f:B}=w(y);A=I,E=B}return Ut(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===We||A.is0())return C.ZERO;if(E===Ct)return A;if(Y.hasCache(this))return this.multiply(E);if(x){let{k1neg:w,k1:I,k2neg:B,k2:D}=R(E),{p1:L,p2:N}=Af(C,A,I,D);return O(x.beta,L,N,w,B)}else return Y.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),N=n.mul(I,A);if(B)return{x:n.ZERO,y:n.ZERO};if(!n.eql(N,n.ONE))throw new Error("invZ was invalid");return{x:D,y:L}}isTorsionFree(){let{isTorsionFree:y}=e;return i===Ct?!0:y?y(C,this):Y.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:y}=e;return i===Ct?this:y?y(C,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===Ct?this.is0():this.clearCofactor().is0()}toBytes(y=!0){return Le(y,"isCompressed"),this.assertValidity(),d(C,this,y)}toHex(y=!0){return ur(this.toBytes(y))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let F=o.BITS,Y=new yr(C,e.endo?Math.ceil(F/2):F);return F>=8&&C.BASE.precompute(8),Object.freeze(C.prototype),Object.freeze(C),C}function uu(t){return Uint8Array.of(t?2:3)}function lu(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function am(t,e={}){let{Fn:r}=t,n=e.randomBytes===void 0?rn:e.randomBytes,o=Object.assign(lu(t.Fp,r),{seed:Math.max(Xs(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,Qs(V(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(!Rt(h))return;let v=V(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=no(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:p,Point:t,utils:l,lengths:o})}function du(t,e,r={}){let n=e;Hn(n),Re(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let o=r.randomBytes===void 0?rn:r.randomBytes,s=r.hmac===void 0?(E,w)=>iu(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}=am(t,r),b={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},m=c*cu+Ct<i.ORDER;function g(E){let w=c>>Ct;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){Ji(w);let I=d.signature,B=w==="compact"?I:w==="recovered"?I+1:void 0;return V(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:K,s:H}=Ke.toSig(V(w));return new _(K,H)}I==="recovered"&&(B=w[0],I="compact",w=w.subarray(1));let D=d.signature/2,L=w.subarray(0,D),N=w.subarray(D,D*2);return new _(a.fromBytes(L),a.fromBytes(N),B)}static fromHex(w,I){return this.fromBytes(lr(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 N=i.toBytes(L),K=t.fromBytes(fe(uu((D&1)===0),N)),H=a.inv(L),U=O(V(w,void 0,"msgHash")),ce=a.create(-U*H),ue=a.create(B*H),le=t.BASE.multiplyUnsafe(ce).add(K.multiplyUnsafe(ue));if(le.is0())throw new Error("invalid recovery: point at infinify");return le.assertValidity(),le}hasHighS(){return g(this.s)}toBytes(w=b.format){if(Ji(w),w==="der")return lr(Ke.hexFromSig(this));let{r:I,s:B}=this,D=a.toBytes(I),L=a.toBytes(B);return w==="recovered"?(S(),fe(Uint8Array.of(this.assertRecovery()),D,L)):fe(D,L)}toHex(w){return ur(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=Nt(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=sn(f);function F(E){return dr("num < 2^"+f,E,We,C),a.toBytes(E)}function Y(E,w){return V(E,void 0,"message"),w?V(n(E),void 0,"prehashed message"):E}function k(E,w,I){let{lowS:B,prehash:D,extraEntropy:L}=Qi(I,b);E=Y(E,D);let N=O(E),K=a.fromBytes(w);if(!a.isValidNot0(K))throw new Error("invalid private key");let H=[F(K),F(N)];if(L!=null&&L!==!1){let le=L===!0?o(d.secretKey):L;H.push(V(le,void 0,"extraEntropy"))}let U=fe(...H),ce=N;function ue(le){let oe=R(le);if(!a.isValidNot0(oe))return;let Ee=a.inv(oe),Zt=t.BASE.multiply(oe).toAffine(),Ur=a.create(Zt.x);if(Ur===We)return;let Pn=a.create(Ee*a.create(ce+Ur*K));if(Pn===We)return;let Xa=(Zt.x===Ur?0:2)|Number(Zt.y&Ct),Qa=Pn;return B&&g(Pn)&&(Qa=a.neg(Pn),Xa^=1),new _(Ur,Qa,m?void 0:Xa)}return{seed:U,k2sig:ue}}function y(E,w,I={}){let{seed:B,k2sig:D}=k(E,w,I);return af(n.outputLen,a.BYTES,s)(B,D).toBytes(I.format)}function x(E,w,I,B={}){let{lowS:D,prehash:L,format:N}=Qi(B,b);if(I=V(I,void 0,"publicKey"),w=Y(w,L),!Rt(E)){let K=E instanceof _?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+K)}T(E,N);try{let K=_.fromBytes(E,N),H=t.fromBytes(I);if(D&&K.hasHighS())return!1;let{r:U,s:ce}=K,ue=O(w),le=a.inv(ce),oe=a.create(ue*le),Ee=a.create(U*le),Zt=t.BASE.multiplyUnsafe(oe).add(H.multiplyUnsafe(Ee));return Zt.is0()?!1:a.create(Zt.x)===U}catch{return!1}}function A(E,w,I={}){let{prehash:B}=Qi(I,b);return w=Y(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 ra={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},cm={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var hu=BigInt(2);function fm(t){let e=ra.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,hu,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(_,hu,e);if(!ta.eql(ta.sqr(R),t))throw new Error("Cannot find square root");return R}var ta=pr(ra.p,{sqrt:fm}),um=fu(ra,{Fp:ta,endo:cm}),Er=du(um,fr);function pu(t,e,r,n){let o=hn.digest(r instanceof Uint8Array?r:r.subarray());if(ao(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Er.verify(e,s,t,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new un(String(s))});try{return n?.signal?.throwIfAborted(),Er.verify(e,o.digest,t,{prehash:!1,format:"der"})}catch(s){throw new un(String(s))}}var yo=class{type="secp256k1";raw;_key;constructor(e){this._key=yu(e),this.raw=mu(this._key)}toMultihash(){return Be.digest($e(this))}toCID(){return de.createV1(114,this.toMultihash())}toString(){return se.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ve(this.raw,e.raw)}verify(e,r,n){return pu(this._key,r,e,n)}};function na(t){return new yo(t)}function mu(t){return Er.Point.fromBytes(t).toBytes()}function yu(t){try{return Er.Point.fromBytes(t),t}catch(e){throw new Wt(String(e))}}function vr(t,e){let{Type:r,Data:n}=Ze.decode(t),o=n??new Uint8Array;switch(r){case ee.RSA:return Zi(o,e);case ee.Ed25519:return li(o);case ee.secp256k1:return na(o);case ee.ECDSA:return Rs(o);default:throw new Dt}}function bu(t){let{Type:e,Data:r}=Ze.decode(t.digest),n=r??new Uint8Array;switch(e){case ee.Ed25519:return li(n);case ee.secp256k1:return na(n);case ee.ECDSA:return Rs(n);default:throw new Dt}}function $e(t){return Ze.encode({Type:ee[t.type],Data:t.raw})}var gn;(function(t){let e;t.codec=()=>(e==null&&(e=Me((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:pt(0),payloadType:pt(0),payload:pt(0),signature:pt(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 ke(s,t.codec())}t.encode=r;function n(s,i){return Fe(s,t.codec(),i)}t.decode=n;function o(s,i){return Ue(s,t.codec(),i)}t.stream=o})(gn||(gn={}));var bo=class extends Error{constructor(e="Invalid signature"){super(e),this.name="InvalidSignatureError"}};var Xe=class t{static createFromProtobuf=e=>{let r=gn.decode(e),n=vr(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=gu(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=gn.encode({publicKey:$e(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(e){return e==null?!1:ve(this.marshal(),e.marshal())}async validate(e,r){let n=gu(e,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},gu=(t,e,r)=>{let n=j(t),o=xr(n.byteLength),s=xr(e.length),i=xr(r.length);return new ae(o,n,s,e,i,r)};var xu=Symbol.for("nodejs.util.inspect.custom"),lm=114,xn=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()})`}[Go]=!0;toString(){return this.string==null&&(this.string=se.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return de.createV1(lm,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return ve(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return ve(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[xu](){return`PeerId(${this.toString()})`}},wn=class extends xn{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},En=class extends xn{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},vn=class extends xn{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},dm=2336,Sn=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Be.digest(j(this.url))}[xu](){return`PeerId(${this.url})`}[Go]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return de.createV1(dm,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=G(e)),e.toString()===this.toString())}};var hm=114,wu=2336;function Eu(t){if(t.type==="Ed25519")return new En({multihash:t.toCID().multihash,publicKey:t});if(t.type==="secp256k1")return new vn({multihash:t.toCID().multihash,publicKey:t});if(t.type==="RSA")return new wn({multihash:t.toCID().multihash,publicKey:t});throw new Dt}function oa(t){if(mm(t))return new wn({multihash:t});if(pm(t))try{let e=bu(t);if(e.type==="Ed25519")return new En({multihash:t,publicKey:e});if(e.type==="secp256k1")return new vn({multihash:t,publicKey:e})}catch{let r=G(t.digest);return new Sn(new URL(r))}throw new Fn("Supplied PeerID Multihash is invalid")}function go(t){if(t?.multihash==null||t.version==null||t.version===1&&t.code!==hm&&t.code!==wu)throw new Nn("Supplied PeerID CID is invalid");if(t.code===wu){let e=G(t.multihash.digest);return new Sn(new URL(e))}return oa(t.multihash)}function pm(t){return t.code===Be.code}function mm(t){return t.code===hn.code}function vu(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 xo(t=0){return new Uint8Array(t)}function An(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=xo(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}function Au(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Su=Au("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),sa=Au("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=xo(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),ym={utf8:Su,"utf-8":Su,hex:It.base16,latin1:sa,ascii:sa,binary:sa,...It},wo=ym;function In(t,e="utf8"){let r=wo[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function qt(t,e="utf8"){let r=wo[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var be=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},ct=class extends Error{static name="ValidationError";name="ValidationError"},Eo=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},vo=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var So=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 Iu=45,bm=15,Sr=new So;function Ao(t){if(!(t.length>bm))return Sr.new(t).parseWith(()=>Sr.readIPv4Addr())}function Io(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>Iu))return Sr.new(t).parseWith(()=>Sr.readIPv6Addr())}function Ar(t,e=!1){if(t.includes("%")&&(t=t.split("%")[0]),t.length>Iu)return;let r=Sr.new(t).parseWith(()=>Sr.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 Ir(t){return!!Ao(t)}function Co(t){return!!Io(t)}function aa(t){return e=>qt(e,t)}function ca(t){return e=>In(e,t)}function Cr(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function zt(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function Cu(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=In(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=zt(n);return An([r,o],r.length+o.length)}function _u(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let r=dt.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=zt(n);return An([r,o],r.length+o.length)}function fa(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=qt(e,"base32"),o=Cr(r);return`${n}:${o}`}var ua=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},Tu=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let s=Ir(r[n]),i;s&&(i=ua(r[n]),r[n]=qt(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,qt(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},Du=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(".")},Bu=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 Ou(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 ia=Object.values(It).map(t=>t.decoder),gm=(function(){let t=ia[0].or(ia[1]);return ia.slice(2).forEach(e=>t=t.or(e)),t})();function Lu(t){return gm.decode(t)}function Pu(t){return e=>t.encoder.encode(e)}function xm(t){if(parseInt(t).toString()!==t)throw new ct("Value must be an integer")}function wm(t){if(t<0)throw new ct("Value must be a positive integer, or zero")}function Em(t){return e=>{if(e>t)throw new ct(`Value must be smaller than or equal to ${t}`)}}function vm(...t){return e=>{for(let r of t)r(e)}}var Cn=vm(xm,wm,Em(65535));var pe=-1,la=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 vo(`Protocol ${e} was unknown`);return r}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(r=>{this.protocolsByName.set(r,e)})}removeProtocol(e){let r=this.protocolsByCode.get(e);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},ut=new la,Fm=[{code:4,name:"ip4",size:32,valueToBytes:ua,bytesToValue:Du,validate:t=>{if(!Ir(t))throw new ct(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:zt,bytesToValue:Cr,validate:Cn},{code:273,name:"udp",size:16,valueToBytes:zt,bytesToValue:Cr,validate:Cn},{code:33,name:"dccp",size:16,valueToBytes:zt,bytesToValue:Cr,validate:Cn},{code:41,name:"ip6",size:128,valueToBytes:Tu,bytesToValue:Bu,stringToValue:Ou,validate:t=>{if(!Co(t))throw new ct(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:pe},{code:43,name:"ipcidr",size:8,bytesToValue:aa("base10"),valueToBytes:ca("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:zt,bytesToValue:Cr,validate:Cn},{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:aa("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?ca("base58btc")(t):de.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:fa,valueToBytes:Cu},{code:445,name:"onion3",size:296,bytesToValue:fa,valueToBytes:_u},{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:Pu(Ci),valueToBytes:Lu},{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}];Fm.forEach(t=>{ut.addProtocol(t)});function Ru(t){let e=[],r=0;for(;r<t.length;){let n=ln(t,r),o=ut.getProtocol(n),s=Ae(n),i=km(o,t,r+s),a=0;i>0&&o.size===pe&&(a=Ae(i));let c=s+a+i,f={code:n,name:o.name,bytes:t.subarray(r,r+c)};if(i>0){let u=r+s+a,l=t.subarray(u,u+i);f.value=o.bytesToValue?.(l)??qt(l)}e.push(f),r+=c}return e}function Nu(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let o=ut.getProtocol(n.code),s=Ae(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??In(n.value),a=i.byteLength,o.size===pe&&(c=Ae(a)));let f=new Uint8Array(s+c+a),u=0;gr(n.code,f,u),u+=s,i!=null&&(o.size===pe&&(gr(a,f,u),u+=c),f.set(i,u)),n.bytes=f}r.push(n.bytes),e+=n.bytes.byteLength}return An(r,e)}function Fu(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 c=ut.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new be(`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 be(`Component ${o} was missing value`);f.value=c.stringToValue?.(n)??n}e.push(f),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new be("Incomplete multiaddr");return e}function ku(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=ut.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 km(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:ln(e,r)}var Um=Symbol.for("nodejs.util.inspect.custom"),Ca=Symbol.for("@multiformats/multiaddr");function Mm(t){if(t==null&&(t="/"),Uu(t))return t.getComponents();if(t instanceof Uint8Array)return Ru(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),Fu(t);if(Array.isArray(t))return t;throw new be("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Lo=class t{[Ca]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=Mm(e),r.validate!==!1&&Km(this)}get bytes(){return this.#r==null&&(this.#r=Nu(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=ku(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 Eo(`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 vu(this.bytes,e.bytes)}[Um](){return`Multiaddr(${this.toString()})`}};function Km(t){t.getComponents().forEach(e=>{let r=ut.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function Uu(t){return!!t?.[Ca]}function Tn(t){return new Lo(t)}var Mu="libp2p-peer-record",Ku=Uint8Array.from([3,1]);var Dn;(function(t){let e;(function(i){let a;i.codec=()=>(a==null&&(a=Me((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:pt(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 ke(l,i.codec())}i.encode=c;function f(l,p){return Fe(l,i.codec(),p)}i.decode=f;function u(l,p){return Ue(l,i.codec(),p)}i.stream=u})(e=t.AddressInfo||(t.AddressInfo={}));let r;t.codec=()=>(r==null&&(r=Me((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:pt(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 Ge('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 Ge('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 ke(i,t.codec())}t.encode=n;function o(i,a){return Fe(i,t.codec(),a)}t.decode=o;function s(i,a){return Ue(i,t.codec(),a)}t.stream=s})(Dn||(Dn={}));function Vu(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 Ve=class t{static createFromProtobuf=e=>{let r=Dn.decode(e),n=oa(qr(r.peerId)),o=(r.addresses??[]).map(i=>Tn(i.multiaddr)),s=r.seq;return new t({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=Mu;static CODEC=Ku;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||!Vu(this.multiaddrs,e.multiaddrs))}};function Vm(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 Po(t){let e=Vm(t);if(e==null)throw new J(`Multiaddr ${t} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}function qu(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 zu(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 _a(t){switch(t.length){case $t:return t.join(".");case jt:{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 Hu(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 $u(t){let e="0x";for(let r of t)e+=(r>>4).toString(16)+(r&15).toString(16);return e}var $t=4,jt=16,CE=parseInt("0xFFFF",16),qm=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Bn(t,e){e.length===jt&&t.length===$t&&qu(e,0,11)&&(e=e.slice(12)),e.length===$t&&t.length===jt&&zu(t,qm,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 ju(t,e){if(typeof e=="string"&&(e=Ar(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 Ta(t){let[e,r]=t.split("/");if(!e||!r)throw new Error("Failed to parse given CIDR: "+t);let n=$t,o=Ao(e);if(o==null&&(n=jt,o=Io(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=Da(s,8*n);return{network:Bn(o,i),mask:i}}function Da(t,e){if(e!==8*$t&&e!==8*jt)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}=Ta(e));else{let n=Ar(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=Ar(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Da(o,8*n.length);this.network=Bn(n,this.mask)}}contains(e){return ju({network:this.network,mask:this.mask},e)}toString(){let e=Hu(this.mask),r=e!==-1?String(e):$u(this.mask);return _a(this.network)+"/"+r}};function Yu(t,e){return new On(t).contains(e)}function Gu(t){try{let e=Po(t);return e.type==="ip6"?Yu("2000::/3",e.host):!1}catch{return!1}}var Qu=Il(Xu(),1),Zm=["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"],Wm=Zm.map(t=>new Qu.Netmask(t));function Fa(t){for(let e of Wm)if(e.contains(t))return!0;return!1}function Xm(t){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(t)}function Qm(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 Fa(o)}function Jm(t){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)}function e0(t){let e=t.split(":"),r=e[e.length-1];return Fa(r)}function t0(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 Ju(t){if(Ir(t))return Fa(t);if(Xm(t))return Qm(t);if(Jm(t))return e0(t);if(Co(t))return t0(t)}function el(t){try{let e=Po(t);switch(e.type){case"ip4":case"ip6":return Ju(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)}}),tl=t=>({match:e=>t.match(e)===!1?e:!1}),M=t=>({match:e=>{let r=t.match(e);return r===!1?e:r}}),we=(...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}}),z=(...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 r0=P(421),ov=X(r0),Fo=P(54),ko=P(55),Uo=P(56),Ua=P(53),sv=X(Fo,M(P(421))),iv=X(ko,M(P(421))),av=X(Uo,M(P(421))),cv=X(we(Ua,Uo,Fo,ko),M(P(421))),rl=z(P(4),M(P(43))),nl=z(M(P(42)),P(41),M(P(43))),Ma=we(rl,nl),Rr=we(Ma,Ua,Fo,ko,Uo),ol=X(we(Ma,z(we(Ua,Uo,Fo,ko),M(P(421))))),fv=X(rl),uv=X(nl),lv=X(Ma),Ka=z(Rr,P(6)),Ln=z(Rr,P(273)),sl=X(z(Ka,M(P(421)))),dv=X(Ln),Va=z(Ln,W(460),M(P(421))),Mo=z(Ln,W(461),M(P(421))),n0=we(Va,Mo),hv=X(Va),pv=X(Mo),ka=we(Rr,Ka,Ln,Va,Mo),il=we(z(ka,W(477),M(P(421)))),mv=X(il),al=we(z(ka,W(478),M(P(421))),z(ka,W(448),M(P(449)),W(477),M(P(421)))),yv=X(al),cl=z(Ln,W(280),M(P(466)),M(P(466)),M(P(421))),bv=X(cl),fl=z(Mo,W(465),M(P(466)),M(P(466)),M(P(421))),gv=X(fl),No=we(il,al,z(Ka,M(P(421))),z(n0,M(P(421))),z(Rr,M(P(421))),cl,fl,P(421)),xv=X(No),o0=z(M(No),W(290),tl(W(281)),M(P(421))),wv=X(o0),s0=we(z(No,W(290),W(281),M(P(421))),z(No,W(281),M(P(421))),z(W(281),M(P(421)))),Ev=X(s0),i0=z(Rr,we(z(P(6,"80")),z(P(6),W(480)),W(480)),M(P(481)),M(P(421))),vv=X(i0),a0=z(Rr,we(z(P(6,"443")),z(P(6,"443"),W(480)),z(P(6),W(443)),z(P(6),W(448),W(480)),z(W(448),W(480)),W(448),W(443)),M(P(481)),M(P(421))),Sv=X(a0),c0=we(z(P(777),M(P(421)))),Av=X(c0),f0=we(z(P(400),M(P(421)))),Iv=X(f0);function Nr(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var qa=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},ul=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function za(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(ul(i));return}if(i&&(c=()=>{p(ul(i))},i.addEventListener("abort",c,{once:!0})),t.then(l,p),r===Number.POSITIVE_INFINITY)return;let h=new qa;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 u0=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 l0(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}=u0(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=za(o,{milliseconds:r.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function ll(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=l0(t,e,r),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function dl(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 Gt=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function d0(t){return t.reason}async function Ha(t,e,r){if(e==null)return t;let n=r?.translateError??d0;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 p0=4194304,Ko=class extends Error{static name="UnwrappedError";name="UnwrappedError"},ja=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Ya=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Ga=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function m0(t){return typeof t?.closeRead=="function"}function y0(t){return typeof t?.close=="function"}function $a(t){return m0(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:y0(t)?t.status!=="open":!1}function b0(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function g0(t,e){let r=e?.maxBufferSize??p0,n=new ae,o,s=!1;if(!b0(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 Ko("Stream was unwrapped");if($a(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 Gt(`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 Ha(o.promise,u?.signal),$a(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($a(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,p),new Gt(`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 Ko("Stream was unwrapped");t.send(u)||await ll(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 x0(t,e={}){let r=g0(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Ae(e.maxDataLength));let n=e?.lengthDecoder??ln,o=e?.lengthEncoder??xr;return{async read(i){let a=-1,c=new ae;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 ja("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new Ga(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new Ya(`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 Gt(`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 Gt(`Unexpected EOF - read ${f.byteLength}/${a} bytes before the stream closed`);return f},async write(i,a){await r.write(new ae(o(i.byteLength),i),a)},async writeV(i,a){let c=new ae(...i.flatMap(f=>[o(f.byteLength),f]));await r.write(c,a)},unwrap(){return r.unwrap()}}}function Fr(t,e){let r=x0(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 w0(t){return t[Symbol.asyncIterator]!=null}function E0(t){if(w0(t))return(async()=>{for await(let e of t);})();for(let e of t);}var hl=E0;var Vo=globalThis.CustomEvent??Event;async function*Za(t,e={}){let r=e.concurrency??1/0;r<1&&(r=1/0);let n=e.ordered??!1,o=new EventTarget,s=[],i=Nr(),a=Nr(),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=Nr(),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 Vo("task-complete"))},m=>{b.done=!0,b.err=m,o.dispatchEvent(new Vo("task-complete"))})}c=!0,o.dispatchEvent(new Vo("task-complete"))}catch(d){f=d,o.dispatchEvent(new Vo("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=Nr(),await a.promise),f!=null||(n?yield*p():yield*h(),f!=null))throw f;if(c&&s.length===0)break}}var pl="0.1.0";var ml="id/push",yl="1.0.0",bl="1.0.0";var Tt;(function(t){let e;t.codec=()=>(e==null&&(e=Me((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 Ge('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 Ge('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 Ge('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 Ge('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 ke(s,t.codec())}t.encode=r;function n(s,i){return Fe(s,t.codec(),i)}t.decode=n;function o(s,i){return Ue(s,t.codec(),i)}t.stream=o})(Tt||(Tt={}));var Ie={protocolPrefix:"ipfs",timeout:5e3,maxInboundStreams:1,maxOutboundStreams:1,maxObservedAddresses:10,maxMessageSize:8192,runOnConnectionOpen:!0,runOnSelfUpdate:!0,runOnLimitedConnection:!0,concurrency:32};function xl(t){return t.bytes.length===0}function Wa(t){if(t!=null&&t.length>0)try{let e=Tn(t);if(!xl(e))return e}catch{}}async function qo(t,e,r,n,o){if(r("received identify from %p",n.remotePeer),o==null)throw new De("message was null or undefined");let s={},i=o.listenAddrs.map(Wa).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=vr(o.publicKey);if(!Eu(f).equals(n.remotePeer))throw new De("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 Xe.openAndCertify(f,Ve.DOMAIN),l=Ve.createFromProtobuf(u.payload),p=go(u.publicKey.toCID());if(!l.peerId.equals(p))throw new De("signing key does not match PeerId in the PeerRecord");if(!n.remotePeer.equals(l.peerId))throw new De("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=Xe.createFromProtobuf(h.peerRecordEnvelope),m=Ve.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=>!xl(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=j(o.agentVersion)),o.protocolVersion!=null&&(f.ProtocolVersion=j(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 zo(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 Ho(t,e,r,n){let o=Fr(t,{maxDataLength:e}).pb(Tt),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 kr=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??Ie.timeout,this.maxInboundStreams=r.maxInboundStreams??Ie.maxInboundStreams,this.maxOutboundStreams=r.maxOutboundStreams??Ie.maxOutboundStreams,this.maxMessageSize=r.maxMessageSize??Ie.maxMessageSize,this.maxObservedAddresses=r.maxObservedAddresses??Ie.maxObservedAddresses,this.runOnLimitedConnection=r.runOnLimitedConnection??Ie.runOnLimitedConnection,this.host={protocolVersion:`${r.protocolPrefix??Ie.protocolPrefix}/${pl}`,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:j(this.host.agentVersion),ProtocolVersion:j(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 $o=class extends kr{connectionManager;concurrency;_push;constructor(e,r={}){super(e,{...r,protocol:`/${r.protocolPrefix??Ie.protocolPrefix}/${ml}/${bl}`,log:e.logger.forComponent("libp2p:identify-push")}),this.connectionManager=e.connectionManager,this.concurrency=r.concurrency??Ie.concurrency,this._push=dl(this.sendPushMessage.bind(this),r.debounce??1e3),(r.runOnSelfUpdate??Ie.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 Ve({peerId:this.components.peerId,multiaddrs:e}),n=await Xe.seal(r,this.components.privateKey),o=this.components.registrar.getProtocols(),s=await this.components.peerStore.get(this.components.peerId),i=G(s.metadata.get("AgentVersion")??j(this.host.agentVersion)),a=G(s.metadata.get("ProtocolVersion")??j(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 Fr(p,{maxDataLength:c.maxMessageSize}).pb(Tt).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 hl(Za(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 Ho(e,this.maxMessageSize,o,n);await qo(this.components.peerStore,this.components.events,n,r,zo(s)),n.trace("handled push from %p",r.remotePeer)}};var jo=class extends kr{constructor(e,r={}){super(e,{...r,protocol:`/${r.protocolPrefix??Ie.protocolPrefix}/${"id"}/${yl}`,log:e.logger.forComponent("libp2p:identify")}),(r.runOnConnectionOpen??Ie.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 Ho(n,this.maxMessageSize,r,o);return zo(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 De("Public key was missing from identify message");let a=vr(o),c=go(a.toCID());if(!e.remotePeer.equals(c))throw new De("Identified peer does not match the expected peer");if(this.components.peerId.equals(c))throw new De("Identified peer is our own peer id?");return this.maybeAddObservedAddress(i),this.log("completed for peer %p and protocols %o",c,s),qo(this.components.peerStore,this.components.events,this.log,e,n)}maybeAddObservedAddress(e){let r=Wa(e);if(r==null||(this.log.trace("our observed address was %a",r),el(r)))return;let n=r.getComponents();if((n[0].code===41||n[0].code===42&&n[1].code===41)&&!Gu(r)){this.log.trace("our observed address was IPv6 but not a global unicast address");return}sl.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 Ve({peerId:this.components.peerId,multiaddrs:i});a=(await Xe.seal(u,this.components.privateKey,{signal:o})).marshal().subarray()}let c=r.remoteAddr.bytes;ol.matches(r.remoteAddr)||(c=void 0);let f=Fr(e).pb(Tt);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 C0(t={}){return e=>new jo(e,t)}function _0(t={}){return e=>new $o(e,t)}return Cl(T0);})();
2
+ "use strict";var Libp2PIdentify=(()=>{var Ol=Object.create;var Un=Object.defineProperty;var Pl=Object.getOwnPropertyDescriptor;var Fl=Object.getOwnPropertyNames;var Rl=Object.getPrototypeOf,Nl=Object.prototype.hasOwnProperty;var Zo=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Z=(t,e)=>{for(var r in e)Un(t,r,{get:e[r],enumerable:!0})},sc=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Fl(e))!Nl.call(t,o)&&o!==r&&Un(t,o,{get:()=>e[o],enumerable:!(n=Pl(e,o))||n.enumerable});return t};var Ul=(t,e,r)=>(r=t!=null?Ol(Rl(t)):{},sc(e||!t||!t.__esModule?Un(r,"default",{value:t,enumerable:!0}):r,t)),kl=t=>sc(Un({},"__esModule",{value:!0}),t);var Pa=Zo(Rr=>{"use strict";Object.defineProperty(Rr,"__esModule",{value:!0});Rr.Netmask4Impl=void 0;Rr.ip2long=Fr;Rr.long2ip=tt;function tt(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 m0=48,y0=97,g0=65;function b0(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)-m0)>>>0;else if(r===16)if("a"<=t[o]&&t[o]<="f")e=e*r+(10+t.charCodeAt(o)-y0)>>>0;else if("A"<=t[o]&&t[o]<="F")e=e*r+(10+t.charCodeAt(o)-g0)>>>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 Fr(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]=b0(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 Oa=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=Fr(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=(Fr(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=tt(this.netLong),this.mask=tt(this.maskLong),this.hostmask=tt(~this.maskLong),this.first=this.bitmask<=30?tt(this.netLong+1):this.base,this.last=this.bitmask<=30?tt(this.netLong+this.size-2):tt(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?tt(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):(Fr(e)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(e=1){return new t(tt(this.netLong+this.size*e),this.mask)}forEach(e){let r=Fr(this.first),n=Fr(this.last),o=0;for(;r<=n;)e(tt(r),r,o),o++,r++}toString(){return this.base+"/"+this.bitmask}};Rr.Netmask4Impl=Oa});var sl=Zo(Nr=>{"use strict";Object.defineProperty(Nr,"__esModule",{value:!0});Nr.Netmask6Impl=void 0;Nr.ip6bigint=Ra;Nr.bigint2ip6=Xt;var x0=Pa(),Fa=(1n<<128n)-1n;function Ra(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,x0.ip2long)(n),s=t.substring(0,r+1)+"0:0";return ol(s)&~0xffffffffn|BigInt(o)}return ol(t)}function ol(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 Xt(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 Na=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=Ra(e)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+e)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=Xt(this.netBigint),this.mask=Xt(this.maskBigint),this.hostmask=Xt(~this.maskBigint&Fa),this.first=this.base,this.last=Xt(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):(Ra(e)&this.maskBigint)===this.netBigint}next(e=1){let r=1n<<BigInt(128-this.bitmask);return new t(Xt(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(Xt(r),Number(r),s),s++,r++}toString(){return this.base+"/"+this.bitmask}};Nr.Netmask6Impl=Na});var il=Zo(Lt=>{"use strict";Object.defineProperty(Lt,"__esModule",{value:!0});Lt.long2ip=Lt.ip2long=Lt.Netmask=void 0;var No=Pa();Object.defineProperty(Lt,"ip2long",{enumerable:!0,get:function(){return No.ip2long}});Object.defineProperty(Lt,"long2ip",{enumerable:!0,get:function(){return No.long2ip}});var w0=sl(),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 w0.Netmask6Impl(e,r):this._impl=new No.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 No.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()}};Lt.Netmask=Ua});var cy={};Z(cy,{identify:()=>iy,identifyPush:()=>ay});var J=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},er=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var kn=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},Mn=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 Pt=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var Wo=Symbol.for("@libp2p/peer-id");var Kn=Symbol.for("@libp2p/service-capabilities");var ts={};Z(ts,{base58btc:()=>ie,base58flickr:()=>jl});var Uy=new Uint8Array(0);function ic(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 rt(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return Ft(t);if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return Ft(new Uint8Array(t.buffer,t.byteOffset,t.byteLength));throw new Error("Unknown type, must be binary type")}function ac(t){return new TextEncoder().encode(t)}function cc(t){return new TextDecoder().decode(t)}function Ml(t){return t?.buffer instanceof ArrayBuffer}function Ft(t){return Ml(t)?t:t.slice()}function Kl(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 g=0,m=0,b=0,S=d.length;b!==S&&d[b]===0;)b++,g++;for(var v=(S-b)*u+1>>>0,T=new Uint8Array(v);b!==S;){for(var _=d[b],F=0,L=v-1;(_!==0||F<m)&&L!==-1;L--,F++)_+=256*T[L]>>>0,T[L]=_%a>>>0,_=_/a>>>0;if(_!==0)throw new Error("Non-zero carry");m=F,b++}for(var C=v-m;C!==v&&T[C]===0;)C++;for(var N=c.repeat(g);C<v;++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 g=0;if(d[g]!==" "){for(var m=0,b=0;d[g]===c;)m++,g++;for(var S=(d.length-g)*f+1>>>0,v=new Uint8Array(S);d[g];){var T=r[d.charCodeAt(g)];if(T===255)return;for(var _=0,F=S-1;(T!==0||_<b)&&F!==-1;F--,_++)T+=a*v[F]>>>0,v[F]=T%256>>>0,T=T/256>>>0;if(T!==0)throw new Error("Non-zero carry");b=_,g++}if(d[g]!==" "){for(var L=S-b;L!==S&&v[L]===0;)L++;for(var C=new Uint8Array(m+(S-L)),N=m;L!==S;)C[N++]=v[L++];return C}}}function h(d){var g=p(d);if(g)return g;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:p,decode:h}}var Vl=Kl,ql=Vl,uc=ql;var Xo=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")}},Qo=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 lc(this,e)}},Jo=class{decoders;constructor(e){this.decoders=e}or(e){return lc(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 lc(t,e){return new Jo({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var es=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 Xo(e,r,n),this.decoder=new Qo(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function tr({name:t,prefix:e,encode:r,decode:n}){return new es(t,e,r,n)}function mt({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=uc(r,t);return tr({prefix:e,name:t,encode:n,decode:s=>rt(o(s))})}function zl(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 Hl(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 $l(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=$l(n);return tr({prefix:e,name:t,encode(s){return Hl(s,n,r)},decode(s){return zl(s,o,r,t)}})}var ie=mt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),jl=mt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var rs={};Z(rs,{base32:()=>yt,base32hex:()=>Wl,base32hexpad:()=>Ql,base32hexpadupper:()=>Jl,base32hexupper:()=>Xl,base32pad:()=>Gl,base32padupper:()=>Zl,base32upper:()=>Yl,base32z:()=>ed});var yt=re({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Yl=re({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Gl=re({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Zl=re({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Wl=re({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Xl=re({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ql=re({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Jl=re({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ed=re({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ns={};Z(ns,{base36:()=>qr,base36upper:()=>td});var qr=mt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),td=mt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var rd=pc,dc=128,nd=127,od=~nd,sd=Math.pow(2,31);function pc(t,e,r){e=e||[],r=r||0;for(var n=r;t>=sd;)e[r++]=t&255|dc,t/=128;for(;t&od;)e[r++]=t&255|dc,t>>>=7;return e[r]=t|0,pc.bytes=r-n+1,e}var id=os,ad=128,hc=127;function os(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw os.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&hc)<<o:(i&hc)*Math.pow(2,o),o+=7}while(i>=ad);return os.bytes=s-n,r}var cd=Math.pow(2,7),fd=Math.pow(2,14),ud=Math.pow(2,21),ld=Math.pow(2,28),dd=Math.pow(2,35),hd=Math.pow(2,42),pd=Math.pow(2,49),md=Math.pow(2,56),yd=Math.pow(2,63),gd=function(t){return t<cd?1:t<fd?2:t<ud?3:t<ld?4:t<dd?5:t<hd?6:t<pd?7:t<md?8:t<yd?9:10},bd={encode:rd,decode:id,encodingLength:gd},xd=bd,zr=xd;function Hr(t,e=0){return[zr.decode(t,e),zr.decode.bytes]}function rr(t,e,r=0){return zr.encode(t,e,r),e}function nr(t){return zr.encodingLength(t)}function je(t,e){let r=e.byteLength,n=nr(t),o=n+nr(r),s=new Uint8Array(o+r);return rr(t,s,0),rr(r,s,n),s.set(e,o),new or(t,r,e,s)}function $r(t){let e=rt(t),[r,n]=Hr(e),[o,s]=Hr(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new or(r,o,i,e)}function mc(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&ic(t.bytes,r.bytes)}}var or=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=Ft(n),this.bytes=Ft(o)}};function yc(t,e){let{bytes:r,version:n}=t;return n===0?Ed(r,ss(t),e??ie.encoder):Sd(r,ss(t),e??yt.encoder)}var gc=new WeakMap;function ss(t){let e=gc.get(t);if(e==null){let r=new Map;return gc.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=Ft(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!==jr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==vd)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=je(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&&mc(e.multihash,n.multihash)}toString(e){return yc(this,e)}toJSON(){return{"/":yc(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??bc(n,o,s.bytes))}else if(r[Ad]===!0){let{version:n,multihash:o,code:s}=r,i=$r(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!==jr)throw new Error(`Version 0 CID must use dag-pb (code: ${jr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=bc(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,jr,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=rt(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 or(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]=Hr(e.subarray(r));return r+=p,l},o=n(),s=jr;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]=wd(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 ss(s).set(n,e),s}};function wd(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 yt.prefix:{let r=e??yt;return[yt.prefix,r.decode(t)]}case qr.prefix:{let r=e??qr;return[qr.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 Ed(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 Sd(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 jr=112,vd=18;function bc(t,e,r){let n=nr(t),o=n+nr(e),s=new Uint8Array(o+r.byteLength);return rr(t,s,0),rr(e,s,n),s.set(r,o),s}var Ad=Symbol.for("@ipld/js-cid/CID");var is={};Z(is,{identity:()=>Fe});var xc=0,Id="identity",wc=rt;function Cd(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 je(xc,wc(t))}var Fe={code:xc,name:Id,encode:wc,digest:Cd};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 _d(t){return t.buffer instanceof ArrayBuffer}function De(t){return _d(t)?t:t.slice()}async function Ec(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,De(e),De(r.subarray()));return n?.signal?.throwIfAborted(),s}function nt(t=0){return new Uint8Array(t)}function Yr(t=0){return new Uint8Array(t)}function as(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=Yr(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}function Sc(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 Ac=Symbol.for("@achingbrain/uint8arraylist");function vc(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 qn(t){return!!t?.[Ac]}var ce=class t{bufs;length;[Ac]=!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(qn(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(qn(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=vc(this.bufs,e);return r.buf[r.index]}set(e,r){let n=vc(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(qn(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 as(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:as(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(!qn(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=Yr(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=nt(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=nt(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=nt(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=Yr(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=nt(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=nt(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=nt(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=nt(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=nt(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(!Sc(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 cs={};Z(cs,{base10:()=>Td});var Td=mt({prefix:"9",name:"base10",alphabet:"0123456789"});var fs={};Z(fs,{base16:()=>Dd,base16upper:()=>Bd});var Dd=re({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Bd=re({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var us={};Z(us,{base2:()=>Ld});var Ld=re({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ls={};Z(ls,{base256emoji:()=>Nd});var Ic=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}"),Od=Ic.reduce((t,e,r)=>(t[r]=e,t),[]),Pd=Ic.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Fd(t){return t.reduce((e,r)=>(e+=Od[r],e),"")}function Rd(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Pd[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Nd=tr({prefix:"\u{1F680}",name:"base256emoji",encode:Fd,decode:Rd});var hs={};Z(hs,{base64:()=>Ud,base64pad:()=>kd,base64url:()=>ds,base64urlpad:()=>Md});var Ud=re({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),kd=re({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ds=re({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Md=re({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ps={};Z(ps,{base8:()=>Kd});var Kd=re({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ms={};Z(ms,{identity:()=>Vd});var Vd=tr({prefix:"\0",name:"identity",encode:t=>cc(t),decode:t=>ac(t)});var Ag=new TextEncoder,Ig=new TextDecoder;var bs={};Z(bs,{sha256:()=>Gr,sha512:()=>$d});var Hd=20;function gs({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new ys(t,e,r,n,o)}var ys=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??Hd,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?Cc(n,this.code,r?.truncate):n.then(o=>Cc(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Cc(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 je(e,t)}function Tc(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Gr=gs({name:"sha2-256",code:18,encode:Tc("SHA-256")}),$d=gs({name:"sha2-512",code:19,encode:Tc("SHA-512")});var Zr={...ms,...us,...ps,...cs,...fs,...rs,...ns,...ts,...hs,...ls},Ug={...bs,...is};function ot(t=0){return new Uint8Array(t)}function Nt(t=0){return new Uint8Array(t)}function Bc(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Dc=Bc("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),xs=Bc("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=Nt(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),jd={utf8:Dc,"utf-8":Dc,hex:Zr.base16,latin1:xs,ascii:xs,binary:xs,...Zr},zn=jd;function K(t,e="utf8"){let r=zn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function V(t,e="utf8"){let r=zn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var Yd=parseInt("11111",2),ws=parseInt("10000000",2),Gd=parseInt("01111111",2),Lc={0:Wr,1:Wr,2:Zd,3:Qd,4:Jd,5:Xd,6:Wd,16:Wr,22:Wr,48:Wr};function st(t,e={offset:0}){let r=t[e.offset]&Yd;if(e.offset++,Lc[r]!=null)return Lc[r](t,e);throw new Error("No decoder for tag "+r)}function Xr(t,e){let r=0;if((t[e.offset]&ws)===ws){let n=t[e.offset]&Gd,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 Wr(t,e){Xr(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=st(t,e);if(n===null)break;r.push(n)}return r}function Zd(t,e){let r=Xr(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 Wd(t,e){let r=Xr(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 Xd(t,e){return e.offset++,null}function Qd(t,e){let r=Xr(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 Jd(t,e){let r=Xr(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function eh(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 Es(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=eh(t.byteLength);return new ce(Uint8Array.from([e.byteLength|ws]),e)}function Ce(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]),Es(e),e)}function Hn(t){let e=Uint8Array.from([0]),r=new ce(e,t);return new ce(Uint8Array.from([3]),Es(r),r)}function gt(t,e=48){let r=new ce;for(let n of t)r.append(n);return new ce(Uint8Array.from([e]),Es(r),r)}var th=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),rh=Uint8Array.from([6,5,43,129,4,0,34]),nh=Uint8Array.from([6,5,43,129,4,0,35]),oh={ext:!0,kty:"EC",crv:"P-256"},sh={ext:!0,kty:"EC",crv:"P-384"},ih={ext:!0,kty:"EC",crv:"P-521"},Ss=32,vs=48,As=66;function Is(t){let e=st(t);return Oc(e)}function Oc(t){let e=t[1][1][0],r=1,n,o;if(e.byteLength===Ss*2+1)return n=V(e.subarray(r,r+Ss),"base64url"),o=V(e.subarray(r+Ss),"base64url"),new sr({...oh,key_ops:["verify"],x:n,y:o});if(e.byteLength===vs*2+1)return n=V(e.subarray(r,r+vs),"base64url"),o=V(e.subarray(r+vs),"base64url"),new sr({...sh,key_ops:["verify"],x:n,y:o});if(e.byteLength===As*2+1)return n=V(e.subarray(r,r+As),"base64url"),o=V(e.subarray(r+As),"base64url"),new sr({...ih,key_ops:["verify"],x:n,y:o});throw new J(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Pc(t){return gt([Ce(Uint8Array.from([1])),gt([ah(t.crv)],160),gt([Hn(new ce(Uint8Array.from([4]),K(t.x??"","base64url"),K(t.y??"","base64url")))],161)]).subarray()}function ah(t){if(t==="P-256")return th;if(t==="P-384")return rh;if(t==="P-521")return nh;throw new J(`Invalid curve ${t}`)}var sr=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=Pc(this.jwk)),this._raw}toMultihash(){return Fe.digest(Ye(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 Ec(this.jwk,r,e,n)}};function Cs(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 Be(t,e,r=""){let n=Cs(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 $n(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 ir(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 jn(t,e){Be(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 at(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Yn(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Re(t,e){return t<<32-e|t>>>e}var Rc=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",ch=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Gn(t){if(Be(t),Rc)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=ch[t[r]];return e}var it={_0:48,_9:57,A:65,F:70,a:97,f:102};function Fc(t){if(t>=it._0&&t<=it._9)return t-it._0;if(t>=it.A&&t<=it.F)return t-(it.A-10);if(t>=it.a&&t<=it.f)return t-(it.a-10)}function Qr(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(Rc)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=Fc(t.charCodeAt(s)),a=Fc(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 _s(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];Be(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 Ts(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 Nc(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 Ds=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function Uc(t,e,r){return t&e^~t&r}function kc(t,e,r){return t&e^t&r^e&r}var Jr=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=Yn(this.buffer)}update(e){ir(this),Be(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=Yn(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){ir(this),jn(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,at(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=Yn(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()}},ct=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ge=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Zn=BigInt(4294967295),Mc=BigInt(32);function fh(t,e=!1){return e?{h:Number(t&Zn),l:Number(t>>Mc&Zn)}:{h:Number(t>>Mc&Zn)|0,l:Number(t&Zn)|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}=fh(t[s],e);[n[s],o[s]]=[i,a]}return[n,o]}var Bs=(t,e,r)=>t>>>r,Ls=(t,e,r)=>t<<32-r|e>>>r,Ut=(t,e,r)=>t>>>r|e<<32-r,kt=(t,e,r)=>t<<32-r|e>>>r,en=(t,e,r)=>t<<64-r|e>>>r-32,tn=(t,e,r)=>t>>>r-32|e<<64-r;function Ge(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var Vc=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),qc=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,zc=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),Hc=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,$c=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),jc=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0;var lh=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]),xt=new Uint32Array(64),Os=class extends Jr{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)xt[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let p=xt[l-15],h=xt[l-2],d=Re(p,7)^Re(p,18)^p>>>3,g=Re(h,17)^Re(h,19)^h>>>10;xt[l]=g+xt[l-7]+d+xt[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=Re(a,6)^Re(a,11)^Re(a,25),h=u+p+Uc(a,c,f)+lh[l]+xt[l]|0,g=(Re(n,2)^Re(n,13)^Re(n,22))+kc(n,o,s)|0;u=f,f=c,c=a,a=i+h|0,i=s,s=o,o=n,n=h+g|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(){at(xt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),at(this.buffer)}},Ps=class extends Os{A=ct[0]|0;B=ct[1]|0;C=ct[2]|0;D=ct[3]|0;E=ct[4]|0;F=ct[5]|0;G=ct[6]|0;H=ct[7]|0;constructor(){super(32)}};var Yc=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))),dh=Yc[0],hh=Yc[1],wt=new Uint32Array(80),Et=new Uint32Array(80),Fs=class extends Jr{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:g,Hl:m}=this;return[e,r,n,o,s,i,a,c,f,u,l,p,h,d,g,m]}set(e,r,n,o,s,i,a,c,f,u,l,p,h,d,g,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=g|0,this.Hl=m|0}process(e,r){for(let v=0;v<16;v++,r+=4)wt[v]=e.getUint32(r),Et[v]=e.getUint32(r+=4);for(let v=16;v<80;v++){let T=wt[v-15]|0,_=Et[v-15]|0,F=Ut(T,_,1)^Ut(T,_,8)^Bs(T,_,7),L=kt(T,_,1)^kt(T,_,8)^Ls(T,_,7),C=wt[v-2]|0,N=Et[v-2]|0,G=Ut(C,N,19)^en(C,N,61)^Bs(C,N,6),U=kt(C,N,19)^tn(C,N,61)^Ls(C,N,6),y=zc(L,U,Et[v-7],Et[v-16]),x=Hc(y,F,G,wt[v-7],wt[v-16]);wt[v]=x|0,Et[v]=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:g,Gl:m,Hh:b,Hl:S}=this;for(let v=0;v<80;v++){let T=Ut(l,p,14)^Ut(l,p,18)^en(l,p,41),_=kt(l,p,14)^kt(l,p,18)^tn(l,p,41),F=l&h^~l&g,L=p&d^~p&m,C=$c(S,_,L,hh[v],Et[v]),N=jc(C,b,T,F,dh[v],wt[v]),G=C|0,U=Ut(n,o,28)^en(n,o,34)^en(n,o,39),y=kt(n,o,28)^tn(n,o,34)^tn(n,o,39),x=n&s^n&a^s&a,A=o&i^o&c^i&c;b=g|0,S=m|0,g=h|0,m=d|0,h=l|0,d=p|0,{h:l,l:p}=Ge(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=Vc(G,y,A);n=qc(E,N,U,x),o=E|0}({h:n,l:o}=Ge(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Ge(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Ge(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=Ge(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:p}=Ge(this.Eh|0,this.El|0,l|0,p|0),{h,l:d}=Ge(this.Fh|0,this.Fl|0,h|0,d|0),{h:g,l:m}=Ge(this.Gh|0,this.Gl|0,g|0,m|0),{h:b,l:S}=Ge(this.Hh|0,this.Hl|0,b|0,S|0),this.set(n,o,s,i,a,c,f,u,l,p,h,d,g,m,b,S)}roundClean(){at(wt,Et)}destroy(){this.destroyed=!0,at(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Rs=class extends Fs{Ah=ge[0]|0;Al=ge[1]|0;Bh=ge[2]|0;Bl=ge[3]|0;Ch=ge[4]|0;Cl=ge[5]|0;Dh=ge[6]|0;Dl=ge[7]|0;Eh=ge[8]|0;El=ge[9]|0;Fh=ge[10]|0;Fl=ge[11]|0;Gh=ge[12]|0;Gl=ge[13]|0;Hh=ge[14]|0;Hl=ge[15]|0;constructor(){super(64)}};var ar=Ts(()=>new Ps,Ds(1));var Wn=Ts(()=>new Rs,Ds(3));var z=(t,e,r)=>Be(t,e,r),Us=bt,cr=Gn,ue=(...t)=>_s(...t),fr=t=>Qr(t),Mt=Cs,rn=t=>Nc(t),Qn=BigInt(0),Ns=BigInt(1);function Ne(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}" `;throw new TypeError(r+"expected boolean, got type="+typeof t)}return t}function Jn(t){if(typeof t=="bigint"){if(!Xn(t))throw new RangeError("positive bigint expected, got "+t)}else Us(t);return t}function Ue(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 nn(t){let e=Jn(t).toString(16);return e.length&1?"0"+e:e}function Gc(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?Qn:BigInt("0x"+t)}function Kt(t){return Gc(Gn(t))}function Ze(t){return Gc(Gn(on(Be(t)).reverse()))}function eo(t,e){if(bt(e),e===0)throw new RangeError("zero length");t=Jn(t);let r=t.toString(16);if(r.length>e*2)throw new RangeError("number too large");return Qr(r.padStart(e*2,"0"))}function ks(t,e){return eo(t,e).reverse()}function Zc(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 on(t){return Uint8Array.from(z(t))}function to(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 Xn=t=>typeof t=="bigint"&&Qn<=t;function ph(t,e,r){return Xn(t)&&Xn(e)&&Xn(r)&&e<=t&&t<r}function ur(t,e,r,n){if(!ph(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function lr(t){if(t<Qn)throw new Error("expected non-negative bigint, got "+t);let e;for(e=0;t>Qn;t>>=Ns,e+=1);return e}var sn=t=>(Ns<<BigInt(t))-Ns;function Wc(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,b=[];for(;m<e;){c=p();let S=c.slice();b.push(S),m+=c.length}return ue(...b)};return(m,b)=>{l(),h(m);let S;for(;(S=b(d()))===void 0;)h();return l(),S}}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 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 Ms=()=>{throw new Error("not implemented")};var be=BigInt(0),ne=BigInt(1),Vt=BigInt(2),ef=BigInt(3),tf=BigInt(4),rf=BigInt(5),mh=BigInt(7),nf=BigInt(8),yh=BigInt(9),of=BigInt(16);function ae(t,e){if(e<=be)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=be?r:e+r}function Q(t,e,r){if(e<be)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >be;)n*=n,n%=r;return n}function Xc(t,e){if(t===be)throw new Error("invert: expected non-zero number");if(e<=be)throw new Error("invert: expected positive modulus, got "+e);let r=ae(t,e),n=e,o=be,s=ne,i=ne,a=be;for(;r!==be;){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 Ks(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function sf(t,e){let r=t,n=(r.ORDER+ne)/tf,o=r.pow(e,n);return Ks(r,o,e),o}function gh(t,e){let r=t,n=(r.ORDER-rf)/nf,o=r.mul(e,Vt),s=r.pow(o,n),i=r.mul(e,s),a=r.mul(r.mul(i,Vt),s),c=r.mul(i,r.sub(a,r.ONE));return Ks(r,c,e),c}function bh(t){let e=dr(t),r=af(t),n=r(e,e.neg(e.ONE)),o=r(e,n),s=r(e,e.neg(n)),i=(t+mh)/of;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),g=f.eql(f.sqr(p),c);u=f.cmov(u,l,d),l=f.cmov(h,p,g);let m=f.eql(f.sqr(l),c),b=f.cmov(u,l,m);return Ks(f,b,c),b})}function af(t){if(t<ef)throw new Error("sqrt is not defined for small field");let e=t-ne,r=0;for(;e%Vt===be;)e/=Vt,r++;let n=Vt,o=dr(t);for(;Qc(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return sf;let s=o.pow(n,e),i=(e+ne)/Vt;return function(c,f){let u=c;if(u.is0(f))return f;if(Qc(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 g=1,m=u.sqr(h);for(;!u.eql(m,u.ONE);)if(g++,m=u.sqr(m),g===l)throw new Error("Cannot find square root");let b=ne<<BigInt(l-g-1),S=u.pow(p,b);l=g,p=u.sqr(S),h=u.mul(h,p),d=u.mul(d,S)}return d}}function xh(t){return t%tf===ef?sf:t%nf===rf?gh:t%of===yh?bh(t):af(t)}var ft=(t,e)=>(ae(t,e)&ne)===ne,wh=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Vs(t){let e={ORDER:"bigint",BYTES:"number",BITS:"number"},r=wh.reduce((n,o)=>(n[o]="function",n),e);if(ke(t,r),Ue(t.BYTES,"BYTES"),Ue(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 Eh(t,e,r){let n=t;if(r<be)throw new Error("invalid exponent, negatives unsupported");if(r===be)return n.ONE;if(r===ne)return e;let o=n.ONE,s=e;for(;r>be;)r&ne&&(o=n.mul(o,s)),s=n.sqr(s),r>>=ne;return o}function an(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 Qc(t,e){let r=t,n=(r.ORDER-ne)/Vt,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 Sh(t,e){if(e!==void 0&&Us(e),t<=be)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=lr(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 Jc=new WeakMap,ro=class{ORDER;BITS;BYTES;isLE;ZERO=be;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}=Sh(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 be<=e&&e<this.ORDER}is0(e){return e===be}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 Eh(this,e,r)}div(e,r){return ae(e*Xc(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 Xc(e,this.ORDER)}sqrt(e){let r=Jc.get(this);return r||Jc.set(this,r=xh(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?ks(e,this.BYTES):eo(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?Ze(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 an(this,e)}cmov(e,r,n){return Ne(n,"condition"),n?r:e}};Object.freeze(ro.prototype);function dr(t,e={}){return new ro(t,e)}function cf(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=lr(t-ne);return Math.ceil(e/8)}function qs(t){let e=cf(t);return e+Math.ceil(e/2)}function zs(t,e,r=!1){z(t);let n=t.length,o=cf(e),s=Math.max(qs(e),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Ze(t):Kt(t),a=ae(i,e-ne)+ne;return r?ks(a,o):eo(a,o)}var hr=BigInt(0),qt=BigInt(1);function cn(t,e){let r=e.negate();return t?r:e}function zt(t,e){let r=an(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function df(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function Hs(t,e){df(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),o=2**t,s=sn(t),i=BigInt(t);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function ff(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+=qt);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 $s=new WeakMap,hf=new WeakMap;function js(t){return hf.get(t)||1}function uf(t){if(t!==hr)throw new Error("invalid wNAF")}var pr=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>hr;)r&qt&&(n=n.add(o)),o=o.double(),r>>=qt;return n}precomputeWindow(e,r){let{windows:n,windowSize:o}=Hs(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=Hs(e,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:f,isZero:u,isNeg:l,isNegF:p,offsetF:h}=ff(n,a,i);n=c,u?s=s.add(cn(p,r[h])):o=o.add(cn(l,r[f]))}return uf(n),{p:o,f:s}}wNAFUnsafe(e,r,n,o=this.ZERO){let s=Hs(e,this.bits);for(let i=0;i<s.windows&&n!==hr;i++){let{nextN:a,offset:c,isZero:f,isNeg:u}=ff(n,i,s);if(n=a,!f){let l=r[c];o=o.add(u?l.negate():l)}}return uf(n),o}getPrecomputes(e,r,n){let o=$s.get(r);return o||(o=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(o=n(o)),$s.set(r,o))),o}cached(e,r,n){let o=js(e);return this.wNAF(o,this.getPrecomputes(o,e,n),r)}unsafe(e,r,n,o){let s=js(e);return s===1?this._unsafeLadder(e,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,e,n),r,o)}createCache(e,r){df(r,this.bits),hf.set(e,r),$s.delete(e)}hasCache(e){return js(e)!==1}};function pf(t,e,r,n){let o=e,s=t.ZERO,i=t.ZERO;for(;r>hr||n>hr;)r&qt&&(s=s.add(o)),n&qt&&(i=i.add(o)),o=o.double(),r>>=qt,n>>=qt;return{p1:s,p2:i}}function lf(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Vs(e),e}else return dr(t,{isLE:r})}function no(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>hr))throw new Error(`CURVE.${c} must be positive bigint`)}let o=lf(e.p,r.Fp,n),s=lf(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 oo(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}var St=BigInt(0),pe=BigInt(1),Ys=BigInt(2),vh=BigInt(8);function Ah(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 mf(t,e={}){let r=e,n=no("edwards",t,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;ke(r,{},{uvRatio:"function"});let c=Ys<<BigInt(s.BYTES*8)-pe,f=g=>o.create(g),u=r.uvRatio===void 0?(g,m)=>{try{return{isValid:!0,value:o.sqrt(o.div(g,m))}}catch{return{isValid:!1,value:St}}}:r.uvRatio;if(!Ah(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function l(g,m,b=!1){let S=b?pe:St;return ur("coordinate "+g,m,S,c),m}function p(g){if(!(g 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(St,pe,pe,St);static Fp=o;static Fn=s;X;Y;Z;T;constructor(m,b,S,v){this.X=l("x",m),this.Y=l("y",b),this.Z=l("z",S,!0),this.T=l("t",v),Object.freeze(this)}static CURVE(){return i}static fromAffine(m){if(m instanceof h)throw new Error("extended point not allowed");let{x:b,y:S}=m||{};return l("x",b),l("y",S),new h(b,S,pe,f(b*S))}static fromBytes(m,b=!1){let S=o.BYTES,{a:v,d:T}=i;m=on(z(m,S,"point")),Ne(b,"zip215");let _=on(m),F=m[S-1];_[S-1]=F&-129;let L=Ze(_),C=b?c:o.ORDER;ur("point.y",L,St,C);let N=f(L*L),G=f(N-pe),U=f(T*N-v),{isValid:y,value:x}=u(G,U);if(!y)throw new Error("bad point: invalid y coordinate");let A=(x&pe)===pe,E=(F&128)!==0;if(!b&&x===St&&E)throw new Error("bad point: x=0 and x_0=1");return E!==A&&(x=f(-x)),h.fromAffine({x,y:L})}static fromHex(m,b=!1){return h.fromBytes(fr(m),b)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(m=8,b=!0){return d.createCache(this,m),b||this.multiply(Ys),this}assertValidity(){let m=this,{a:b,d:S}=i;if(m.is0())throw new Error("bad point: ZERO");let{X:v,Y:T,Z:_,T:F}=m,L=f(v*v),C=f(T*T),N=f(_*_),G=f(N*N),U=f(L*b),y=f(N*f(U+C)),x=f(G+f(S*f(L*C)));if(y!==x)throw new Error("bad point: equation left != right (1)");let A=f(v*T),E=f(_*F);if(A!==E)throw new Error("bad point: equation left != right (2)")}equals(m){p(m);let{X:b,Y:S,Z:v}=this,{X:T,Y:_,Z:F}=m,L=f(b*F),C=f(T*v),N=f(S*F),G=f(_*v);return L===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:b,Y:S,Z:v}=this,T=f(b*b),_=f(S*S),F=f(Ys*f(v*v)),L=f(m*T),C=b+S,N=f(f(C*C)-T-_),G=L+_,U=G-F,y=L-_,x=f(N*U),A=f(G*y),E=f(N*y),w=f(U*G);return new h(x,A,w,E)}add(m){p(m);let{a:b,d:S}=i,{X:v,Y:T,Z:_,T:F}=this,{X:L,Y:C,Z:N,T:G}=m,U=f(v*L),y=f(T*C),x=f(F*S*G),A=f(_*N),E=f((v+T)*(L+C)-U-y),w=A-x,I=A+x,B=f(y-b*U),D=f(E*w),O=f(I*B),R=f(E*B),q=f(w*I);return new h(D,O,q,R)}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:b,f:S}=d.cached(this,m,v=>zt(h,v));return zt(h,[b,S])[0]}multiplyUnsafe(m){if(!s.isValid(m))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return m===St?h.ZERO:this.is0()||m===pe?this:d.unsafe(this,m,b=>zt(h,b))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return d.unsafe(this,i.n).is0()}toAffine(m){let b=this,S=m,{X:v,Y:T,Z:_}=b,F=b.is0();S==null&&(S=F?vh:o.inv(_));let L=f(v*S),C=f(T*S),N=o.mul(_,S);if(F)return{x:St,y:pe};if(N!==pe)throw new Error("invZ was invalid");return{x:L,y:C}}clearCofactor(){return a===pe?this:this.multiplyUnsafe(a)}toBytes(){let{x:m,y:b}=this.toAffine(),S=o.toBytes(b);return S[S.length-1]|=m&pe?128:0,S}toHex(){return cr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let d=new pr(h,s.BITS);return s.BITS>=8&&h.BASE.precompute(8),Object.freeze(h.prototype),Object.freeze(h),h}var so=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(e){this.ep=e}static fromBytes(e){Ms()}static fromHex(e){Ms()}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 cr(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 yf(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:c}=t,f=n.outputLen,u=2*a.BYTES;if(f!==void 0&&(Ue(f,"hash.outputLen"),f!==u))throw new Error(`hash.outputLen must be ${u}, got ${f}`);let l=o.randomBytes===void 0?rn:o.randomBytes,p=o.adjustScalarBytes===void 0?y=>y:o.adjustScalarBytes,h=o.domain===void 0?(y,x,A)=>{if(Ne(A,"phflag"),x.length||A)throw new Error("Contexts/pre-hash are not supported");return y}:o.domain;function d(y){return c.create(Ze(y))}function g(y){let x=L.secretKey;z(y,L.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}=g(y),w=i.multiply(E),I=w.toBytes();return{head:x,prefix:A,scalar:E,point:w,pointBytes:I}}function b(y){return m(y).pointBytes}function S(y=Uint8Array.of(),...x){let A=ue(...x);return d(n(h(A,z(y,void 0,"context"),!!s)))}function v(y,x,A={}){y=z(y,void 0,"message"),s&&(y=s(y));let{prefix:E,scalar:w,pointBytes:I}=m(x),B=S(A.context,E,y),D=i.multiply(B).toBytes(),O=S(A.context,D,I,y),R=c.create(B+O*w);if(!c.isValid(R))throw new Error("sign failed: invalid s");let q=ue(D,c.toBytes(R));return z(q,L.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=L.signature;y=z(y,B,"signature"),x=z(x,void 0,"message"),A=z(A,L.publicKey,"publicKey"),I!==void 0&&Ne(I,"zip215"),s&&(x=s(x));let D=B/2,O=y.subarray(0,D),R=Ze(y.subarray(D,B)),q,j,k;try{q=t.fromBytes(A,I),j=t.fromBytes(O,I),k=i.multiplyUnsafe(R)}catch{return!1}if(!I&&q.isSmallOrder())return!1;let fe=S(w,O,A,x);return j.add(q.multiplyUnsafe(fe)).subtract(k).clearCofactor().is0()}let F=a.BYTES,L={secretKey:F,publicKey:F,signature:2*F,seed:F};function C(y){return y=y===void 0?l(L.seed):y,z(y,L.seed,"seed")}function N(y){return Mt(y)&&y.length===L.secretKey}function G(y,x){try{return!!t.fromBytes(y,x===void 0?T.zip215:x)}catch{return!1}}let U={getExtendedPublicKey:m,randomSecretKey:C,isValidSecretKey:N,isValidPublicKey:G,toMontgomery(y){let{y:x}=t.fromBytes(y),A=L.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=L.secretKey;z(y,x);let A=n(y.subarray(0,x));return p(A).subarray(0,x)}};return Object.freeze(L),Object.freeze(U),Object.freeze({keygen:oo(C,b),getPublicKey:b,sign:v,verify:_,utils:U,Point:t,lengths:L})}function fn(t,e){if(Ue(t),Ue(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 Ih(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 Ch(t){if(!Mt(t)&&typeof t!="string")throw new Error("DST must be Uint8Array or ascii string");let e=typeof t=="string"?to(t):t;if(e.length===0)throw new Error("DST must be non-empty");return e}function Gs(t,e,r,n){z(t),Ue(r),e=Ch(e),e.length>255&&(e=n(ue(to("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,fn(e.length,1)),c=new Uint8Array(s),f=fn(r,2),u=new Array(i),l=n(ue(c,t,f,fn(0,1),a));u[0]=n(ue(l,fn(1,1),a));for(let h=1;h<i;h++){let d=[Ih(l,u[h-1]),fn(h+1,1),a];u[h]=n(ue(...d))}return ue(...u).slice(0,r)}var gf="HashToScalar-";var _h=BigInt(0),ut=BigInt(1),bf=BigInt(2);var Th=BigInt(5),Dh=BigInt(8),mr=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Qs={p:mr,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Dh,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Bh(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=mr,a=t*t%s*t%s,c=Q(a,bf,s)*a%s,f=Q(c,ut,s)*t%s,u=Q(f,Th,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,g=Q(d,o,s)*h%s,m=Q(g,e,s)*u%s;return{pow_p_5_8:Q(m,bf,s)*t%s,b2:a}}function Lh(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var Zs=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Js(t,e){let r=mr,n=ae(e*e*e,r),o=ae(n*n*e,r),s=Bh(t*o).pow_p_5_8,i=ae(t*n*s,r),a=ae(e*i*i,r),c=i,f=ae(i*Zs,r),u=a===t,l=a===ae(-t,r),p=a===ae(-t*Zs,r);return u&&(i=c),(l||p)&&(i=f),ft(i,r)&&(i=ae(-i,r)),{isValid:u||l,value:i}}var At=mf(Qs,{uvRatio:Js}),vt=At.Fp,Ef=At.Fn;function Oh(t){return yf(At,Wn,Object.assign({adjustScalarBytes:Lh,zip215:!0},t))}var Sf=Oh({});var Ws=Zs,Ph=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Fh=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Rh=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Nh=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),xf=t=>Js(ut,t),Uh=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Xs=t=>vt.create(Ze(t)&Uh);function wf(t){let{d:e}=Qs,r=mr,n=b=>vt.create(b),o=n(Ws*t*t),s=n((o+ut)*Rh),i=BigInt(-1),a=n((i-e*o)*n(o+e)),{isValid:c,value:f}=Js(s,a),u=n(f*t);ft(u,r)||(u=n(-u)),c||(f=u),c||(i=o);let l=n(i*(o-ut)*Nh-a),p=f*f,h=n((f+f)*a),d=n(l*Ph),g=n(ut-p),m=n(ut+p);return new At(n(h*m),n(g*d),n(d*m),n(h*g))}var It=class t extends so{static BASE=new t(At.BASE);static ZERO=new t(At.ZERO);static Fp=vt;static Fn=Ef;constructor(e){super(e)}static fromAffine(e){return new t(At.fromAffine(e))}assertSame(e){if(!(e instanceof t))throw new Error("RistrettoPoint expected")}init(e){return new t(e)}static fromBytes(e){Be(e,32);let{a:r,d:n}=Qs,o=mr,s=T=>vt.create(T),i=Xs(e);if(!Zc(vt.toBytes(i),e)||ft(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(ut+r*a),f=s(ut-r*a),u=s(c*c),l=s(f*f),p=s(r*n*u-l),{isValid:h,value:d}=xf(s(p*l)),g=s(d*f),m=s(d*g*p),b=s((i+i)*g);ft(b,o)&&(b=s(-b));let S=s(c*m),v=s(b*S);if(!h||ft(v,o)||S===_h)throw new Error("invalid ristretto255 encoding 2");return new t(new At(b,S,ut,v))}static fromHex(e){return t.fromBytes(Qr(e))}toBytes(){let{X:e,Y:r,Z:n,T:o}=this.ep,s=mr,i=m=>vt.create(m),a=i(i(n+r)*i(n-r)),c=i(e*r),f=i(c*c),{value:u}=xf(i(a*f)),l=i(u*a),p=i(u*c),h=i(l*p*o),d;if(ft(o*h,s)){let m=i(r*Ws),b=i(e*Ws);e=m,r=b,d=i(l*Fh)}else d=p;ft(e*h,s)&&(r=i(-r));let g=i((n-r)*d);return ft(g,s)&&(g=i(-g)),vt.toBytes(g)}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(It.BASE);Object.freeze(It.ZERO);Object.freeze(It.prototype);Object.freeze(It);var kh=Object.freeze({Point:It,hashToCurve(t,e){let r=e?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":e.DST,n=Gs(t,r,64,Wn);return kh.deriveToCurve(n)},hashToScalar(t,e={DST:gf}){let r=Gs(t,e.DST,64,Wn);return Ef.create(Ze(r))},deriveToCurve(t){Be(t,64);let e=Xs(t.subarray(0,32)),r=wf(e),n=Xs(t.subarray(32,64)),o=wf(n);return new It(r.add(o))}});var un=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},io=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 io("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 ao=32;var ei,Mh=(async()=>{try{return await Oe.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Kh(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,De(e),De(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Vh(t,e,r){return Sf.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function vf(t,e,r){return ei==null&&(ei=await Mh),ei?Kh(t,e,r):Vh(t,e,r)}function qh(t){return t?.buffer instanceof ArrayBuffer}function ti(t){if(qh(t))return t;let e=t.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function Ht(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=Nt(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return ti(r)}function co(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var fo=class{type="Ed25519";raw;constructor(e){this.raw=ri(e,ao)}toMultihash(){return Fe.digest(Ye(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=vf(this.raw,r,e);return co(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function ni(t){return t=ri(t,ao),new fo(t)}function ri(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 Ct(t=0){return new Uint8Array(t)}var Hh=Math.pow(2,7),$h=Math.pow(2,14),jh=Math.pow(2,21),If=Math.pow(2,28),Cf=Math.pow(2,35),_f=Math.pow(2,42),Tf=Math.pow(2,49),Ae=128,_t=127;function ln(t){if(t<Hh)return 1;if(t<$h)return 2;if(t<jh)return 3;if(t<If)return 4;if(t<Cf)return 5;if(t<_f)return 6;if(t<Tf)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Df(t,e,r=0){switch(ln(t)){case 8:e[r++]=t&255|Ae,t/=128;case 7:e[r++]=t&255|Ae,t/=128;case 6:e[r++]=t&255|Ae,t/=128;case 5:e[r++]=t&255|Ae,t/=128;case 4:e[r++]=t&255|Ae,t>>>=7;case 3:e[r++]=t&255|Ae,t>>>=7;case 2:e[r++]=t&255|Ae,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Bf(t,e){let r=t[e],n=0;if(n+=r&_t,r<Ae||(r=t[e+1],n+=(r&_t)<<7,r<Ae)||(r=t[e+2],n+=(r&_t)<<14,r<Ae)||(r=t[e+3],n+=(r&_t)<<21,r<Ae)||(r=t[e+4],n+=(r&_t)*If,r<Ae)||(r=t[e+5],n+=(r&_t)*Cf,r<Ae)||(r=t[e+6],n+=(r&_t)*_f,r<Ae)||(r=t[e+7],n+=(r&_t)*Tf,r<Ae))return n;throw new RangeError("Could not decode varint")}var oi=new Float32Array([-0]),Tt=new Uint8Array(oi.buffer);function Lf(t,e,r){oi[0]=t,e[r]=Tt[0],e[r+1]=Tt[1],e[r+2]=Tt[2],e[r+3]=Tt[3]}function Of(t,e){return Tt[0]=t[e],Tt[1]=t[e+1],Tt[2]=t[e+2],Tt[3]=t[e+3],oi[0]}var si=new Float64Array([-0]),we=new Uint8Array(si.buffer);function Pf(t,e,r){si[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 Ff(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],si[0]}var Yh=BigInt(Number.MAX_SAFE_INTEGER),Gh=BigInt(Number.MIN_SAFE_INTEGER),Le=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return $t;if(e<Yh&&e>Gh)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>Rf&&(o=0n,++n>Rf&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return $t;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):$t}},$t=new Le(0,0);$t.toBigInt=function(){return 0n};$t.zzEncode=$t.zzDecode=function(){return this};$t.length=function(){return 1};var Rf=4294967296n;function Nf(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 Uf(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 ii(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 Me(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function uo(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var ai=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,Me(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 Me(this,4);return uo(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Me(this,4);return uo(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Me(this,4);let e=Of(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Me(this,4);let e=Ff(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 Me(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return Uf(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Me(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Me(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Le(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Me(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 Me(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 Me(this,8);let e=uo(this.buf,this.pos+=4),r=uo(this.buf,this.pos+=4);return new Le(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Bf(this.buf,this.pos);return this.pos+=ln(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 dn(t){return new ai(t instanceof Uint8Array?t:t.subarray())}function Ke(t,e,r){let n=dn(t);return e.decode(n,void 0,r)}var di={};Z(di,{base10:()=>tp});var Dx=new Uint8Array(0);function Mf(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 lt(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 Kf(t){return new TextEncoder().encode(t)}function Vf(t){return new TextDecoder().decode(t)}function Zh(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 g=0,m=0,b=0,S=d.length;b!==S&&d[b]===0;)b++,g++;for(var v=(S-b)*u+1>>>0,T=new Uint8Array(v);b!==S;){for(var _=d[b],F=0,L=v-1;(_!==0||F<m)&&L!==-1;L--,F++)_+=256*T[L]>>>0,T[L]=_%a>>>0,_=_/a>>>0;if(_!==0)throw new Error("Non-zero carry");m=F,b++}for(var C=v-m;C!==v&&T[C]===0;)C++;for(var N=c.repeat(g);C<v;++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 g=0;if(d[g]!==" "){for(var m=0,b=0;d[g]===c;)m++,g++;for(var S=(d.length-g)*f+1>>>0,v=new Uint8Array(S);d[g];){var T=r[d.charCodeAt(g)];if(T===255)return;for(var _=0,F=S-1;(T!==0||_<b)&&F!==-1;F--,_++)T+=a*v[F]>>>0,v[F]=T%256>>>0,T=T/256>>>0;if(T!==0)throw new Error("Non-zero carry");b=_,g++}if(d[g]!==" "){for(var L=S-b;L!==S&&v[L]===0;)L++;for(var C=new Uint8Array(m+(S-L)),N=m;L!==S;)C[N++]=v[L++];return C}}}function h(d){var g=p(d);if(g)return g;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:p,decode:h}}var Wh=Zh,Xh=Wh,zf=Xh;var ci=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")}},fi=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 Hf(this,e)}},ui=class{decoders;constructor(e){this.decoders=e}or(e){return Hf(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 Hf(t,e){return new ui({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var li=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 ci(e,r,n),this.decoder=new fi(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function yr({name:t,prefix:e,encode:r,decode:n}){return new li(t,e,r,n)}function Dt({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=zf(r,t);return yr({prefix:e,name:t,encode:n,decode:s=>lt(o(s))})}function Qh(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 Jh(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 ep(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=ep(n);return yr({prefix:e,name:t,encode(s){return Jh(s,n,r)},decode(s){return Qh(s,o,r,t)}})}var tp=Dt({prefix:"9",name:"base10",alphabet:"0123456789"});var hi={};Z(hi,{base16:()=>rp,base16upper:()=>np});var rp=oe({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),np=oe({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var pi={};Z(pi,{base2:()=>op});var op=oe({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var mi={};Z(mi,{base256emoji:()=>fp});var $f=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}"),sp=$f.reduce((t,e,r)=>(t[r]=e,t),[]),ip=$f.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function ap(t){return t.reduce((e,r)=>(e+=sp[r],e),"")}function cp(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=ip[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var fp=yr({prefix:"\u{1F680}",name:"base256emoji",encode:ap,decode:cp});var yi={};Z(yi,{base32:()=>gr,base32hex:()=>hp,base32hexpad:()=>mp,base32hexpadupper:()=>yp,base32hexupper:()=>pp,base32pad:()=>lp,base32padupper:()=>dp,base32upper:()=>up,base32z:()=>gp});var gr=oe({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),up=oe({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),lp=oe({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),dp=oe({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),hp=oe({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),pp=oe({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),mp=oe({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),yp=oe({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),gp=oe({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var gi={};Z(gi,{base36:()=>hn,base36upper:()=>bp});var hn=Dt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),bp=Dt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var bi={};Z(bi,{base58btc:()=>We,base58flickr:()=>xp});var We=Dt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),xp=Dt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var xi={};Z(xi,{base64:()=>wp,base64pad:()=>Ep,base64url:()=>Sp,base64urlpad:()=>vp});var wp=oe({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ep=oe({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Sp=oe({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),vp=oe({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var wi={};Z(wi,{base8:()=>Ap});var Ap=oe({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ei={};Z(Ei,{identity:()=>Ip});var Ip=yr({prefix:"\0",name:"identity",encode:t=>Vf(t),decode:t=>Kf(t)});var $x=new TextEncoder,jx=new TextDecoder;var vi={};Z(vi,{identity:()=>Gp});var Tp=Gf,jf=128,Dp=127,Bp=~Dp,Lp=Math.pow(2,31);function Gf(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Lp;)e[r++]=t&255|jf,t/=128;for(;t&Bp;)e[r++]=t&255|jf,t>>>=7;return e[r]=t|0,Gf.bytes=r-n+1,e}var Op=Si,Pp=128,Yf=127;function Si(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw Si.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&Yf)<<o:(i&Yf)*Math.pow(2,o),o+=7}while(i>=Pp);return Si.bytes=s-n,r}var Fp=Math.pow(2,7),Rp=Math.pow(2,14),Np=Math.pow(2,21),Up=Math.pow(2,28),kp=Math.pow(2,35),Mp=Math.pow(2,42),Kp=Math.pow(2,49),Vp=Math.pow(2,56),qp=Math.pow(2,63),zp=function(t){return t<Fp?1:t<Rp?2:t<Np?3:t<Up?4:t<kp?5:t<Mp?6:t<Kp?7:t<Vp?8:t<qp?9:10},Hp={encode:Tp,decode:Op,encodingLength:zp},$p=Hp,pn=$p;function mn(t,e=0){return[pn.decode(t,e),pn.decode.bytes]}function br(t,e,r=0){return pn.encode(t,e,r),e}function xr(t){return pn.encodingLength(t)}function Er(t,e){let r=e.byteLength,n=xr(t),o=n+xr(r),s=new Uint8Array(o+r);return br(t,s,0),br(r,s,n),s.set(e,o),new wr(t,r,e,s)}function Zf(t){let e=lt(t),[r,n]=mn(e),[o,s]=mn(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new wr(r,o,i,e)}function Wf(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Mf(t.bytes,r.bytes)}}var wr=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};var Xf=0,jp="identity",Qf=lt;function Yp(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 Er(Xf,Qf(t))}var Gp={code:Xf,name:jp,encode:Qf,digest:Yp};var Ci={};Z(Ci,{sha256:()=>Wp,sha512:()=>Xp});var Zp=20;function Ii({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new Ai(t,e,r,n,o)}var Ai=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??Zp,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?Jf(n,this.code,r?.truncate):n.then(o=>Jf(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Jf(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 Er(e,t)}function tu(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Wp=Ii({name:"sha2-256",code:18,encode:tu("SHA-256")}),Xp=Ii({name:"sha2-512",code:19,encode:tu("SHA-512")});function ru(t,e){let{bytes:r,version:n}=t;return n===0?Jp(r,_i(t),e??We.encoder):em(r,_i(t),e??gr.encoder)}var nu=new WeakMap;function _i(t){let e=nu.get(t);if(e==null){let r=new Map;return nu.set(t,r),r}return e}var ho=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!==gn)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==tm)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=Er(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&&Wf(e.multihash,n.multihash)}toString(e){return ru(this,e)}toJSON(){return{"/":ru(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??ou(n,o,s.bytes))}else if(r[rm]===!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!==gn)throw new Error(`Version 0 CID must use dag-pb (code: ${gn}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=ou(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,gn,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=lt(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 wr(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]=mn(e.subarray(r));return r+=p,l},o=n(),s=gn;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]=Qp(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 _i(s).set(n,e),s}};function Qp(t,e){switch(t[0]){case"Q":{let r=e??We;return[We.prefix,r.decode(`${We.prefix}${t}`)]}case We.prefix:{let r=e??We;return[We.prefix,r.decode(t)]}case gr.prefix:{let r=e??gr;return[gr.prefix,r.decode(t)]}case hn.prefix:{let r=e??hn;return[hn.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 Jp(t,e,r){let{prefix:n}=r;if(n!==We.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 em(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 gn=112,tm=18;function ou(t,e,r){let n=xr(t),o=n+xr(e),s=new Uint8Array(o+r.byteLength);return br(t,s,0),br(e,s,n),s.set(r,o),s}var rm=Symbol.for("@ipld/js-cid/CID");var Ti={...Ei,...pi,...wi,...di,...hi,...yi,...gi,...bi,...xi,...mi},pw={...Ci,...vi};function iu(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var su=iu("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Di=iu("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=Ct(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),nm={utf8:su,"utf-8":su,hex:Ti.base16,latin1:Di,ascii:Di,binary:Di,...Ti},au=nm;function cu(t,e="utf8"){let r=au[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function Bi(t){let e=t??8192,r=e>>>1,n,o=e;return function(i){if(i<1||i>r)return Ct(i);o+i>e&&(n=Ct(e),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var jt=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function Li(){}var Pi=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},om=Bi();function sm(t){return globalThis.Buffer!=null?Ct(t):om(t)}var xn=class{len;head;tail;states;constructor(){this.len=0,this.head=new jt(Li,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new jt(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Fi((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(po,10,Le.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=Le.fromBigInt(e);return this._push(po,r.length(),r)}uint64Number(e){return this._push(Df,ln(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=Le.fromBigInt(e).zzEncode();return this._push(po,r.length(),r)}sint64Number(e){let r=Le.fromNumber(e).zzEncode();return this._push(po,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Oi,1,e?1:0)}fixed32(e){return this._push(bn,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=Le.fromBigInt(e);return this._push(bn,4,r.lo)._push(bn,4,r.hi)}fixed64Number(e){let r=Le.fromNumber(e);return this._push(bn,4,r.lo)._push(bn,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(Lf,4,e)}double(e){return this._push(Pf,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(Oi,1,0):this.uint32(r)._push(am,r,e)}string(e){let r=Nf(e);return r!==0?this.uint32(r)._push(ii,r,e):this._push(Oi,1,0)}fork(){return this.states=new Pi(this),this.head=this.tail=new jt(Li,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 jt(Li,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=sm(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function Oi(t,e,r){e[r]=t&255}function im(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var Fi=class extends jt{next;constructor(e,r){super(im,e,r),this.next=void 0}};function po(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 bn(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 am(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(xn.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(cm,e,t),this},xn.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(fm,e,t),this});function cm(t,e,r){e.set(t,r)}function fm(t,e,r){t.length<40?ii(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(cu(t),r)}function Ri(){return new xn}function Ve(t,e){let r=Ri();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*qe(t,e,r){let n=dn(t);yield*e.stream(n,void 0,"$",r)}var mo={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function yo(t,e,r,n,o){return{name:t,type:e,encode:r,decode:n,stream:o}}function Ni(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 yo("enum",mo.VARINT,r,n,o)}function ze(t,e,r){return yo("message",mo.LENGTH_DELIMITED,t,e,r)}var Xe=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 Ui;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(Ui||(Ui={}));(function(t){t.codec=()=>Ni(Ui)})(ee||(ee={}));var Qe;(function(t){let e;t.codec=()=>(e==null&&(e=ze((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 Ve(s,t.codec())}t.encode=r;function n(s,i){return Ke(s,t.codec(),i)}t.decode=n;function o(s,i){return qe(s,t.codec(),i)}t.stream=o})(Qe||(Qe={}));var ki;(function(t){let e;t.codec=()=>(e==null&&(e=ze((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 Ve(s,t.codec())}t.encode=r;function n(s,i){return Ke(s,t.codec(),i)}t.decode=n;function o(s,i){return qe(s,t.codec(),i)}t.stream=o})(ki||(ki={}));var En={};Z(En,{MAX_RSA_KEY_SIZE:()=>Mi,generateRSAKeyPair:()=>hu,jwkToJWKKeyPair:()=>pu,jwkToPkcs1:()=>hm,jwkToPkix:()=>zi,jwkToRSAPrivateKey:()=>Yi,pkcs1MessageToJwk:()=>Vi,pkcs1MessageToRSAPrivateKey:()=>Hi,pkcs1ToJwk:()=>dm,pkcs1ToRSAPrivateKey:()=>du,pkixMessageToJwk:()=>qi,pkixMessageToRSAPublicKey:()=>ji,pkixToJwk:()=>pm,pkixToRSAPublicKey:()=>$i});var Sr=class{type="RSA";jwk;_raw;_multihash;constructor(e,r){this.jwk=e,this._multihash=r}get raw(){return this._raw==null&&(this._raw=En.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 lu(this.jwk,r,e,n)}},wn=class{type="RSA";jwk;_raw;publicKey;constructor(e,r){this.jwk=e,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=En.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:ye(this.raw,e.raw)}sign(e,r){return uu(this.jwk,e,r)}};var Mi=8192,Ki=18,um=1062,lm=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function dm(t){let e=st(t);return Vi(e)}function Vi(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 hm(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 gt([Ce(Uint8Array.from([0])),Ce(K(t.n,"base64url")),Ce(K(t.e,"base64url")),Ce(K(t.d,"base64url")),Ce(K(t.p,"base64url")),Ce(K(t.q,"base64url")),Ce(K(t.dp,"base64url")),Ce(K(t.dq,"base64url")),Ce(K(t.qi,"base64url"))]).subarray()}function pm(t){let e=st(t,{offset:0});return qi(e)}function qi(t){let e=st(t[1],{offset:0});return{kty:"RSA",n:V(e[0],"base64url"),e:V(e[1],"base64url")}}function zi(t){if(t.n==null||t.e==null)throw new J("JWK was missing components");return gt([lm,Hn(gt([Ce(K(t.n,"base64url")),Ce(K(t.e,"base64url"))]))]).subarray()}function du(t){let e=st(t);return Hi(e)}function Hi(t){let e=Vi(t);return Yi(e)}function $i(t,e){if(t.byteLength>=um)throw new er("Key size is too large");let r=st(t,{offset:0});return ji(r,t,e)}function ji(t,e,r){let n=qi(t);if(r==null){let o=ar(Qe.encode({Type:ee.RSA,Data:e}));r=je(Ki,o)}return new Sr(n,r)}function Yi(t){if(yu(t)>Mi)throw new J("Key size is too large");let e=pu(t),r=ar(Qe.encode({Type:ee.RSA,Data:zi(e.publicKey)})),n=je(Ki,r);return new wn(e.privateKey,new Sr(e.publicKey,n))}async function hu(t){if(t>Mi)throw new J("Key size is too large");let e=await mu(t),r=ar(Qe.encode({Type:ee.RSA,Data:zi(e.publicKey)})),n=je(Ki,r);return new wn(e.privateKey,new Sr(e.publicKey,n))}function pu(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 mu(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 mm(r,e);return{privateKey:n[0],publicKey:n[1]}}async function uu(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,De(e instanceof Uint8Array?e:e.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function lu(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,De(e),De(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),s}async function mm(t,e){if(t.privateKey==null||t.publicKey==null)throw new J("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 yu(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 go=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if($n(e),Be(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),at(o)}update(e){return ir(this),this.iHash.update(e),this}digestInto(e){ir(this),jn(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()}},gu=(()=>{let t=((e,r,n)=>new go(e,r).update(n).digest());return t.create=(e,r)=>new go(e,r),t})();var bu=(t,e)=>(t+(t>=0?e:-e)/xu)/e;function ym(t,e,r){ur("scalar",t,Je,r);let[[n,o],[s,i]]=e,a=bu(i*t,r),c=bu(-o*t,r),f=t-a*n-c*s,u=-a*o-c*i,l=f<Je,p=u<Je;l&&(f=-f),p&&(u=-u);let h=sn(Math.ceil(lr(r)/2))+Bt;if(f<Je||f>=h||u<Je||u>=h)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:f,k2neg:p,k2:u}}function Zi(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Gi(t,e){ke(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Ne(r.lowS,"lowS"),Ne(r.prehash,"prehash"),r.format!==void 0&&Zi(r.format),r}var Wi=class extends Error{constructor(e=""){super(e)}},He={Err:Wi,_tlv:{encode:(t,e)=>{let{Err:r}=He;if(Ue(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=nn(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?nn(o.length/2|128):"";return nn(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 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}=He;if(Jn(t),t<Je)throw new e("integer: negative integers are not allowed");let r=nn(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 Kt(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: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}=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 Je=BigInt(0),Bt=BigInt(1),xu=BigInt(2),bo=BigInt(3),gm=BigInt(4);function wu(t,e={}){let r=no("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: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=Su(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function p(U,y,x){if(f&&y.is0())return Uint8Array.of(0);let{x:A,y:E}=y.toAffine(),w=n.toBytes(A);if(Ne(x,"isCompressed"),x){l();let I=!n.isOdd(E);return ue(Eu(I),w)}else return ue(Uint8Array.of(4),w,n.toBytes(E))}function h(U){z(U,void 0,"Point");let{publicKey:y,publicKeyUncompressed:x}=u,A=U.length,E=U[0],w=U.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 O=n.isOdd(D);return(E&1)===1!==O&&(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(!b(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,g=e.fromBytes===void 0?h:e.fromBytes;function m(U){let y=n.sqr(U),x=n.mul(y,U);return n.add(n.add(x,n.mul(U,s.a)),s.b)}function b(U,y){let x=n.sqr(y),A=m(U);return n.eql(x,A)}if(!b(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let S=n.mul(n.pow(s.a,bo),gm),v=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(S,v)))throw new Error("bad curve params: a or b");function T(U,y,x=!1){if(!n.isValid(y)||x&&n.is0(y))throw new Error(`bad point coordinate ${U}`);return y}function _(U){if(!(U instanceof C))throw new Error("Weierstrass Point expected")}function F(U){if(!c||!c.basises)throw new Error("no endo");return ym(U,c.basises,o.ORDER)}function L(U,y,x,A,E){return x=new C(n.mul(x.X,U),x.Y,x.Z),y=cn(A,y),x=cn(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(g(z(y,void 0,"point")));return x.assertValidity(),x}static fromHex(y){return C.fromBytes(fr(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(bo),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(!b(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)),O=n.eql(n.mul(A,B),n.mul(I,E));return D&&O}negate(){return new C(this.X,n.neg(this.Y),this.Z)}double(){let{a:y,b:x}=s,A=n.mul(x,bo),{X:E,Y:w,Z:I}=this,B=n.ZERO,D=n.ZERO,O=n.ZERO,R=n.mul(E,E),q=n.mul(w,w),j=n.mul(I,I),k=n.mul(E,w);return k=n.add(k,k),O=n.mul(E,I),O=n.add(O,O),B=n.mul(y,O),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(k,B),O=n.mul(A,O),j=n.mul(y,j),k=n.sub(R,j),k=n.mul(y,k),k=n.add(k,O),O=n.add(R,R),R=n.add(O,R),R=n.add(R,j),R=n.mul(R,k),D=n.add(D,R),j=n.mul(w,I),j=n.add(j,j),R=n.mul(j,k),B=n.sub(B,R),O=n.mul(j,q),O=n.add(O,O),O=n.add(O,O),new C(B,D,O)}add(y){_(y);let{X:x,Y:A,Z:E}=this,{X:w,Y:I,Z:B}=y,D=n.ZERO,O=n.ZERO,R=n.ZERO,q=s.a,j=n.mul(s.b,bo),k=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(k,fe),de=n.sub(de,se),se=n.add(x,E);let Ie=n.add(w,B);return se=n.mul(se,Ie),Ie=n.add(k,le),se=n.sub(se,Ie),Ie=n.add(A,E),D=n.add(I,B),Ie=n.mul(Ie,D),D=n.add(fe,le),Ie=n.sub(Ie,D),R=n.mul(q,se),D=n.mul(j,le),R=n.add(D,R),D=n.sub(fe,R),R=n.add(fe,R),O=n.mul(D,R),fe=n.add(k,k),fe=n.add(fe,k),le=n.mul(q,le),se=n.mul(j,se),fe=n.add(fe,le),le=n.sub(k,le),le=n.mul(q,le),se=n.add(se,le),k=n.mul(fe,se),O=n.add(O,k),k=n.mul(Ie,se),D=n.mul(de,D),D=n.sub(D,k),k=n.mul(de,fe),R=n.mul(Ie,R),R=n.add(R,k),new C(D,O,R)}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=>zt(C,B));if(x){let{k1neg:I,k1:B,k2neg:D,k2:O}=F(y),{p:R,f:q}=w(B),{p:j,f:k}=w(O);E=q.add(k),A=L(x.beta,R,j,I,D)}else{let{p:I,f:B}=w(y);A=I,E=B}return zt(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===Je||A.is0())return C.ZERO;if(E===Bt)return A;if(G.hasCache(this))return this.multiply(E);if(x){let{k1neg:w,k1:I,k2neg:B,k2:D}=F(E),{p1:O,p2:R}=pf(C,A,I,D);return L(x.beta,O,R,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),O=n.mul(w,A),R=n.mul(I,A);if(B)return{x:n.ZERO,y:n.ZERO};if(!n.eql(R,n.ONE))throw new Error("invZ was invalid");return{x:D,y:O}}isTorsionFree(){let{isTorsionFree:y}=e;return i===Bt?!0:y?y(C,this):G.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:y}=e;return i===Bt?this:y?y(C,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===Bt?this.is0():this.clearCofactor().is0()}toBytes(y=!0){return Ne(y,"isCompressed"),this.assertValidity(),d(C,this,y)}toHex(y=!0){return cr(this.toBytes(y))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let N=o.BITS,G=new pr(C,e.endo?Math.ceil(N/2):N);return N>=8&&C.BASE.precompute(8),Object.freeze(C.prototype),Object.freeze(C),C}function Eu(t){return Uint8Array.of(t?2:3)}function Su(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function bm(t,e={}){let{Fn:r}=t,n=e.randomBytes===void 0?rn:e.randomBytes,o=Object.assign(Su(t.Fp,r),{seed:Math.max(qs(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:g,publicKeyUncompressed:m}=o;try{let b=h.length;return d===!0&&b!==g||d===!1&&b!==m?!1:!!t.fromBytes(h)}catch{return!1}}function a(h){return h=h===void 0?n(o.seed):h,zs(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:g,publicKeyUncompressed:m}=o,b=r._lengths;if(!Mt(h))return;let S=z(h,void 0,"key").length,v=S===g||S===m,T=S===d||!!b?.includes(S);if(!(v&&T))return v}function u(h,d,g=!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(g)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},p=oo(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:p,Point:t,utils:l,lengths:o})}function vu(t,e,r={}){let n=e;$n(n),ke(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let o=r.randomBytes===void 0?rn:r.randomBytes,s=r.hmac===void 0?(E,w)=>gu(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}=bm(t,r),g={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},m=c*xu+Bt<i.ORDER;function b(E){let w=c>>Bt;return E>w}function S(E,w){if(!a.isValidNot0(w))throw new Error(`invalid signature ${E}: out of range 1..Point.Fn.ORDER`);return w}function v(){if(m)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function T(E,w){Zi(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=S("r",w),this.s=S("s",I),B!=null){if(v(),![0,1,2,3].includes(B))throw new Error("invalid recovery id");this.recovery=B}Object.freeze(this)}static fromBytes(w,I=g.format){T(w,I);let B;if(I==="der"){let{r:q,s:j}=He.toSig(z(w));return new _(q,j)}I==="recovered"&&(B=w[0],I="compact",w=w.subarray(1));let D=d.signature/2,O=w.subarray(0,D),R=w.subarray(D,D*2);return new _(a.fromBytes(O),a.fromBytes(R),B)}static fromHex(w,I){return this.fromBytes(fr(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(),O=D===2||D===3?I+c:I;if(!i.isValid(O))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let R=i.toBytes(O),q=t.fromBytes(ue(Eu((D&1)===0),R)),j=a.inv(O),k=L(z(w,void 0,"msgHash")),fe=a.create(-k*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 b(this.s)}toBytes(w=g.format){if(Zi(w),w==="der")return fr(He.hexFromSig(this));let{r:I,s:B}=this,D=a.toBytes(I),O=a.toBytes(B);return w==="recovered"?(v(),ue(Uint8Array.of(this.assertRecovery()),D,O)):ue(D,O)}toHex(w){return cr(this.toBytes(w))}}Object.freeze(_.prototype),Object.freeze(_);let F=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,L=r.bits2int_modN===void 0?function(w){return a.create(F(w))}:r.bits2int_modN,C=sn(f);function N(E){return ur("num < 2^"+f,E,Je,C),a.toBytes(E)}function G(E,w){return z(E,void 0,"message"),w?z(n(E),void 0,"prehashed message"):E}function U(E,w,I){let{lowS:B,prehash:D,extraEntropy:O}=Gi(I,g);E=G(E,D);let R=L(E),q=a.fromBytes(w);if(!a.isValidNot0(q))throw new Error("invalid private key");let j=[N(q),N(R)];if(O!=null&&O!==!1){let de=O===!0?o(d.secretKey):O;j.push(z(de,void 0,"extraEntropy"))}let k=ue(...j),fe=R;function le(de){let se=F(de);if(!a.isValidNot0(se))return;let Ie=a.inv(se),Jt=t.BASE.multiply(se).toAffine(),Vr=a.create(Jt.x);if(Vr===Je)return;let Nn=a.create(Ie*a.create(fe+Vr*q));if(Nn===Je)return;let nc=(Jt.x===Vr?0:2)|Number(Jt.y&Bt),oc=Nn;return B&&b(Nn)&&(oc=a.neg(Nn),nc^=1),new _(Vr,oc,m?void 0:nc)}return{seed:k,k2sig:le}}function y(E,w,I={}){let{seed:B,k2sig:D}=U(E,w,I);return Wc(n.outputLen,a.BYTES,s)(B,D).toBytes(I.format)}function x(E,w,I,B={}){let{lowS:D,prehash:O,format:R}=Gi(B,g);if(I=z(I,void 0,"publicKey"),w=G(w,O),!Mt(E)){let q=E instanceof _?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+q)}T(E,R);try{let q=_.fromBytes(E,R),j=t.fromBytes(I);if(D&&q.hasHighS())return!1;let{r:k,s:fe}=q,le=L(w),de=a.inv(fe),se=a.create(le*de),Ie=a.create(k*de),Jt=t.BASE.multiplyUnsafe(se).add(j.multiplyUnsafe(Ie));return Jt.is0()?!1:a.create(Jt.x)===k}catch{return!1}}function A(E,w,I={}){let{prehash:B}=Gi(I,g);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 Qi={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},xm={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Au=BigInt(2);function wm(t){let e=Qi.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,Au,e)*f%e,d=Q(h,o,e)*h%e,g=Q(d,s,e)*d%e,m=Q(g,a,e)*g%e,b=Q(m,c,e)*m%e,S=Q(b,a,e)*g%e,v=Q(S,r,e)*u%e,T=Q(v,i,e)*d%e,_=Q(T,n,e)*f%e,F=Q(_,Au,e);if(!Xi.eql(Xi.sqr(F),t))throw new Error("Cannot find square root");return F}var Xi=dr(Qi.p,{sqrt:wm}),Em=wu(Qi,{Fp:Xi,endo:xm}),vr=vu(Em,ar);function Iu(t,e,r,n){let o=Gr.digest(r instanceof Uint8Array?r:r.subarray());if(co(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 un(String(s))});try{return n?.signal?.throwIfAborted(),vr.verify(e,o.digest,t,{prehash:!1,format:"der"})}catch(s){throw new un(String(s))}}var xo=class{type="secp256k1";raw;_key;constructor(e){this._key=_u(e),this.raw=Cu(this._key)}toMultihash(){return Fe.digest(Ye(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 Iu(this._key,r,e,n)}};function Ji(t){return new xo(t)}function Cu(t){return vr.Point.fromBytes(t).toBytes()}function _u(t){try{return vr.Point.fromBytes(t),t}catch(e){throw new er(String(e))}}function Ar(t,e){let{Type:r,Data:n}=Qe.decode(t),o=n??new Uint8Array;switch(r){case ee.RSA:return $i(o,e);case ee.Ed25519:return ni(o);case ee.secp256k1:return Ji(o);case ee.ECDSA:return Is(o);default:throw new Pt}}function Tu(t){let{Type:e,Data:r}=Qe.decode(t.digest),n=r??new Uint8Array;switch(e){case ee.Ed25519:return ni(n);case ee.secp256k1:return Ji(n);case ee.ECDSA:return Is(n);default:throw new Pt}}function Ye(t){return Qe.encode({Type:ee[t.type],Data:t.raw})}function Du(t=0){return new Uint8Array(t)}var Sm=Math.pow(2,7),vm=Math.pow(2,14),Am=Math.pow(2,21),Im=Math.pow(2,28),Cm=Math.pow(2,35),_m=Math.pow(2,42),Tm=Math.pow(2,49),_e=128;function ea(t){if(t<Sm)return 1;if(t<vm)return 2;if(t<Am)return 3;if(t<Im)return 4;if(t<Cm)return 5;if(t<_m)return 6;if(t<Tm)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Dm(t,e,r=0){switch(ea(t)){case 8:e[r++]=t&255|_e,t/=128;case 7:e[r++]=t&255|_e,t/=128;case 6:e[r++]=t&255|_e,t/=128;case 5:e[r++]=t&255|_e,t/=128;case 4:e[r++]=t&255|_e,t>>>=7;case 3:e[r++]=t&255|_e,t>>>=7;case 2:e[r++]=t&255|_e,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function Bm(t,e,r=0){switch(ea(t)){case 8:e.set(r++,t&255|_e),t/=128;case 7:e.set(r++,t&255|_e),t/=128;case 6:e.set(r++,t&255|_e),t/=128;case 5:e.set(r++,t&255|_e),t/=128;case 4:e.set(r++,t&255|_e),t>>>=7;case 3:e.set(r++,t&255|_e),t>>>=7;case 2:e.set(r++,t&255|_e),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function wo(t,e,r=0){return e==null&&(e=Du(ea(t))),e instanceof Uint8Array?Dm(t,e,r):Bm(t,e,r)}var Sn;(function(t){let e;t.codec=()=>(e==null&&(e=ze((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:ot(0),payloadType:ot(0),payload:ot(0),signature:ot(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 Ve(s,t.codec())}t.encode=r;function n(s,i){return Ke(s,t.codec(),i)}t.decode=n;function o(s,i){return qe(s,t.codec(),i)}t.stream=o})(Sn||(Sn={}));var Eo=class extends Error{constructor(e="Invalid signature"){super(e),this.name="InvalidSignatureError"}};var et=class t{static createFromProtobuf=e=>{let r=Sn.decode(e),n=Ar(r.publicKey);return new t({publicKey:n,payloadType:r.payloadType,payload:r.payload,signature:r.signature})};static seal=async(e,r,n)=>{if(r==null)throw new Error("Missing private key");let o=e.domain,s=e.codec,i=e.marshal(),a=Bu(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 Eo("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=Sn.encode({publicKey:Ye(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=Bu(e,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},Bu=(t,e,r)=>{let n=K(t),o=wo(n.byteLength),s=wo(e.length),i=wo(r.length);return new ce(o,n,s,e,i,r)};var Lu=Symbol.for("nodejs.util.inspect.custom"),Om=114,vn=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Wo]=!0;toString(){return this.string==null&&(this.string=ie.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return he.createV1(Om,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")}[Lu](){return`PeerId(${this.toString()})`}},An=class extends vn{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},In=class extends vn{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},Cn=class extends vn{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},Pm=2336,_n=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Fe.digest(K(this.url))}[Lu](){return`PeerId(${this.url})`}[Wo]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return he.createV1(Pm,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=V(e)),e.toString()===this.toString())}};var Fm=114,Ou=2336;function Pu(t){if(t.type==="Ed25519")return new In({multihash:t.toCID().multihash,publicKey:t});if(t.type==="secp256k1")return new Cn({multihash:t.toCID().multihash,publicKey:t});if(t.type==="RSA")return new An({multihash:t.toCID().multihash,publicKey:t});throw new Pt}function ta(t){if(Nm(t))return new An({multihash:t});if(Rm(t))try{let e=Tu(t);if(e.type==="Ed25519")return new In({multihash:t,publicKey:e});if(e.type==="secp256k1")return new Cn({multihash:t,publicKey:e})}catch{let r=V(t.digest);return new _n(new URL(r))}throw new Mn("Supplied PeerID Multihash is invalid")}function So(t){if(t?.multihash==null||t.version==null||t.version===1&&t.code!==Fm&&t.code!==Ou)throw new kn("Supplied PeerID CID is invalid");if(t.code===Ou){let e=V(t.multihash.digest);return new _n(new URL(e))}return ta(t.multihash)}function Rm(t){return t.code===Fe.code}function Nm(t){return t.code===Gr.code}var Um=Math.pow(2,7),km=Math.pow(2,14),Mm=Math.pow(2,21),ra=Math.pow(2,28),na=Math.pow(2,35),oa=Math.pow(2,42),sa=Math.pow(2,49),te=128,Ee=127;function Ir(t){if(t<Um)return 1;if(t<km)return 2;if(t<Mm)return 3;if(t<ra)return 4;if(t<na)return 5;if(t<oa)return 6;if(t<sa)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ia(t,e,r=0){switch(Ir(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 Km(t,e){let r=t[e],n=0;if(n+=r&Ee,r<te||(r=t[e+1],n+=(r&Ee)<<7,r<te)||(r=t[e+2],n+=(r&Ee)<<14,r<te)||(r=t[e+3],n+=(r&Ee)<<21,r<te)||(r=t[e+4],n+=(r&Ee)*ra,r<te)||(r=t[e+5],n+=(r&Ee)*na,r<te)||(r=t[e+6],n+=(r&Ee)*oa,r<te)||(r=t[e+7],n+=(r&Ee)*sa,r<te))return n;throw new RangeError("Could not decode varint")}function Vm(t,e){let r=t.get(e),n=0;if(n+=r&Ee,r<te||(r=t.get(e+1),n+=(r&Ee)<<7,r<te)||(r=t.get(e+2),n+=(r&Ee)<<14,r<te)||(r=t.get(e+3),n+=(r&Ee)<<21,r<te)||(r=t.get(e+4),n+=(r&Ee)*ra,r<te)||(r=t.get(e+5),n+=(r&Ee)*na,r<te)||(r=t.get(e+6),n+=(r&Ee)*oa,r<te)||(r=t.get(e+7),n+=(r&Ee)*sa,r<te))return n;throw new RangeError("Could not decode varint")}function aa(t,e=0){return t instanceof Uint8Array?Km(t,e):Vm(t,e)}var xe=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},dt=class extends Error{static name="ValidationError";name="ValidationError"},vo=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Ao=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var Io=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 Fu=45,zm=15,Cr=new Io;function Co(t){if(!(t.length>zm))return Cr.new(t).parseWith(()=>Cr.readIPv4Addr())}function _o(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>Fu))return Cr.new(t).parseWith(()=>Cr.readIPv6Addr())}function _r(t,e=!1){if(t.includes("%")&&(t=t.split("%")[0]),t.length>Fu)return;let r=Cr.new(t).parseWith(()=>Cr.readIPAddr());if(r)return e&&r.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,r[0],r[1],r[2],r[3]]):r}function Tr(t){return!!Co(t)}function To(t){return!!_o(t)}function fa(t){return e=>V(e,t)}function ua(t){return e=>K(e,t)}function Dr(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function Yt(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function Ru(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=Yt(n);return Ht([r,o],r.length+o.length)}function Nu(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=yt.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=Yt(n);return Ht([r,o],r.length+o.length)}function la(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=V(e,"base32"),o=Dr(r);return`${n}:${o}`}var da=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},Uu=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let s=Tr(r[n]),i;s&&(i=da(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},ku=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(".")},Mu=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 Ku(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 ca=Object.values(Zr).map(t=>t.decoder),Hm=(function(){let t=ca[0].or(ca[1]);return ca.slice(2).forEach(e=>t=t.or(e)),t})();function Vu(t){return Hm.decode(t)}function qu(t){return e=>t.encoder.encode(e)}function $m(t){if(parseInt(t).toString()!==t)throw new dt("Value must be an integer")}function jm(t){if(t<0)throw new dt("Value must be a positive integer, or zero")}function Ym(t){return e=>{if(e>t)throw new dt(`Value must be smaller than or equal to ${t}`)}}function Gm(...t){return e=>{for(let r of t)r(e)}}var Tn=Gm($m,jm,Ym(65535));var me=-1,ha=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 Ao(`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)}))}},pt=new ha,c0=[{code:4,name:"ip4",size:32,valueToBytes:da,bytesToValue:ku,validate:t=>{if(!Tr(t))throw new dt(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Yt,bytesToValue:Dr,validate:Tn},{code:273,name:"udp",size:16,valueToBytes:Yt,bytesToValue:Dr,validate:Tn},{code:33,name:"dccp",size:16,valueToBytes:Yt,bytesToValue:Dr,validate:Tn},{code:41,name:"ip6",size:128,valueToBytes:Uu,bytesToValue:Mu,stringToValue:Ku,validate:t=>{if(!To(t))throw new dt(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:me},{code:43,name:"ipcidr",size:8,bytesToValue:fa("base10"),valueToBytes:ua("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:Yt,bytesToValue:Dr,validate:Tn},{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:fa("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?ua("base58btc")(t):he.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:la,valueToBytes:Ru},{code:445,name:"onion3",size:296,bytesToValue:la,valueToBytes:Nu},{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:qu(ds),valueToBytes:Vu},{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}];c0.forEach(t=>{pt.addProtocol(t)});function zu(t){let e=[],r=0;for(;r<t.length;){let n=aa(t,r),o=pt.getProtocol(n),s=Ir(n),i=f0(o,t,r+s),a=0;i>0&&o.size===me&&(a=Ir(i));let c=s+a+i,f={code:n,name:o.name,bytes:De(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 Hu(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let o=pt.getProtocol(n.code),s=Ir(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=Ir(a)));let f=new Uint8Array(s+c+a),u=0;ia(n.code,f,u),u+=s,i!=null&&(o.size===me&&(ia(a,f,u),u+=c),f.set(i,u)),n.bytes=f}r.push(n.bytes),e+=n.bytes.byteLength}return Ht(r,e)}function $u(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=pt.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 ju(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=pt.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 f0(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:aa(e,r)}var u0=Symbol.for("nodejs.util.inspect.custom"),Ta=Symbol.for("@multiformats/multiaddr");function l0(t){if(t==null&&(t="/"),Yu(t))return t.getComponents();if(t instanceof Uint8Array)return zu(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),$u(t);if(Array.isArray(t))return t;throw new xe("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Fo=class t{[Ta]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=l0(e),r.validate!==!1&&d0(this)}get bytes(){return this.#r==null&&(this.#r=Hu(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=ju(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 vo(`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)}[u0](){return`Multiaddr(${this.toString()})`}};function d0(t){t.getComponents().forEach(e=>{let r=pt.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function Yu(t){return!!t?.[Ta]}function Bn(t){return new Fo(t)}var Gu="libp2p-peer-record",Zu=Uint8Array.from([3,1]);var Ln;(function(t){let e;(function(i){let a;i.codec=()=>(a==null&&(a=ze((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:ot(0)},g=p==null?l.len:l.pos+p;for(;l.pos<g;){let m=l.uint32();m>>>3===1?d.multiaddr=l.bytes():l.skipType(m&7)}return d},function*(l,p,h,d={}){let g=p==null?l.len:l.pos+p;for(;l.pos<g;){let m=l.uint32();m>>>3===1?yield{field:`${h}.multiaddr`,value:l.bytes()}:l.skipType(m&7)}})),a);function c(l){return Ve(l,i.codec())}i.encode=c;function f(l,p){return Ke(l,i.codec(),p)}i.decode=f;function u(l,p){return qe(l,i.codec(),p)}i.stream=u})(e=t.AddressInfo||(t.AddressInfo={}));let r;t.codec=()=>(r==null&&(r=ze((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:ot(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 Xe('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 Xe('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 Ve(i,t.codec())}t.encode=n;function o(i,a){return Ke(i,t.codec(),a)}t.decode=o;function s(i,a){return qe(i,t.codec(),a)}t.stream=s})(Ln||(Ln={}));function Wu(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 $e=class t{static createFromProtobuf=e=>{let r=Ln.decode(e),n=ta($r(r.peerId)),o=(r.addresses??[]).map(i=>Bn(i.multiaddr)),s=r.seq;return new t({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=Gu;static CODEC=Zu;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=Ln.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||!Wu(this.multiaddrs,e.multiaddrs))}};function h0(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 Ro(t){let e=h0(t);if(e==null)throw new J(`Multiaddr ${t} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}function Xu(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 Qu(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 Da(t){switch(t.length){case Zt:return t.join(".");case Wt:{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 el(t){let e="0x";for(let r of t)e+=(r>>4).toString(16)+(r&15).toString(16);return e}var Zt=4,Wt=16,d6=parseInt("0xFFFF",16),p0=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function On(t,e){e.length===Wt&&t.length===Zt&&Xu(e,0,11)&&(e=e.slice(12)),e.length===Zt&&t.length===Wt&&Qu(t,p0,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 tl(t,e){if(typeof e=="string"&&(e=_r(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 Ba(t){let[e,r]=t.split("/");if(!e||!r)throw new Error("Failed to parse given CIDR: "+t);let n=Zt,o=Co(e);if(o==null&&(n=Wt,o=_o(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:On(o,i),mask:i}}function La(t,e){if(e!==8*Zt&&e!==8*Wt)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 Pn=class{constructor(e,r){if(r==null)({network:this.network,mask:this.mask}=Ba(e));else{let n=_r(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=_r(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=La(o,8*n.length);this.network=On(n,this.mask)}}contains(e){return tl({network:this.network,mask:this.mask},e)}toString(){let e=Ju(this.mask),r=e!==-1?String(e):el(this.mask);return Da(this.network)+"/"+r}};function rl(t,e){return new Pn(t).contains(e)}function nl(t){try{let e=Ro(t);return e.type==="ip6"?rl("2000::/3",e.host):!1}catch{return!1}}var al=Ul(il(),1),E0=["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"],S0=E0.map(t=>new al.Netmask(t));function ka(t){for(let e of S0)if(e.contains(t))return!0;return!1}function v0(t){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(t)}function A0(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 ka(o)}function I0(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 ka(r)}function _0(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 cl(t){if(Tr(t))return ka(t);if(v0(t))return A0(t);if(I0(t))return C0(t);if(To(t))return _0(t)}function fl(t){try{let e=Ro(t);switch(e.type){case"ip4":case"ip6":return cl(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)}}),ul=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 T0=P(421),H6=X(T0),ko=P(54),Mo=P(55),Ko=P(56),Ka=P(53),$6=X(ko,M(P(421))),j6=X(Mo,M(P(421))),Y6=X(Ko,M(P(421))),G6=X(Se(Ka,Ko,ko,Mo),M(P(421))),ll=$(P(4),M(P(43))),dl=$(M(P(42)),P(41),M(P(43))),Va=Se(ll,dl),Ur=Se(Va,Ka,ko,Mo,Ko),hl=X(Se(Va,$(Se(Ka,Ko,ko,Mo),M(P(421))))),Z6=X(ll),W6=X(dl),X6=X(Va),qa=$(Ur,P(6)),Fn=$(Ur,P(273)),pl=X($(qa,M(P(421)))),Q6=X(Fn),za=$(Fn,W(460),M(P(421))),Vo=$(Fn,W(461),M(P(421))),D0=Se(za,Vo),J6=X(za),eS=X(Vo),Ma=Se(Ur,qa,Fn,za,Vo),ml=Se($(Ma,W(477),M(P(421)))),tS=X(ml),yl=Se($(Ma,W(478),M(P(421))),$(Ma,W(448),M(P(449)),W(477),M(P(421)))),rS=X(yl),gl=$(Fn,W(280),M(P(466)),M(P(466)),M(P(421))),nS=X(gl),bl=$(Vo,W(465),M(P(466)),M(P(466)),M(P(421))),oS=X(bl),Uo=Se(ml,yl,$(qa,M(P(421))),$(D0,M(P(421))),$(Ur,M(P(421))),gl,bl,P(421)),sS=X(Uo),B0=$(M(Uo),W(290),ul(W(281)),M(P(421))),iS=X(B0),L0=Se($(Uo,W(290),W(281),M(P(421))),$(Uo,W(281),M(P(421))),$(W(281),M(P(421)))),aS=X(L0),O0=$(Ur,Se($(P(6,"80")),$(P(6),W(480)),W(480)),M(P(481)),M(P(421))),cS=X(O0),P0=$(Ur,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))),fS=X(P0),F0=Se($(P(777),M(P(421)))),uS=X(F0),R0=Se($(P(400),M(P(421)))),lS=X(R0);function kr(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Ha=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},xl=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function $a(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(xl(i));return}if(i&&(c=()=>{p(xl(i))},i.addEventListener("abort",c,{once:!0})),t.then(l,p),r===Number.POSITIVE_INFINITY)return;let h=new Ha;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 N0=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 U0(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}=N0(t),l=async(...h)=>{let d=r.multiArgs?h:h[0];if(r.filter)try{if(!await r.filter(d))return}catch(g){n(),i(g);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=$a(o,{milliseconds:r.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function wl(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=U0(t,e,r),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function El(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 k0(t){return t.reason}async function ja(t,e,r){if(e==null)return t;let n=r?.translateError??k0;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)}}function Sl(t=0){return new Uint8Array(t)}var M0=Math.pow(2,7),K0=Math.pow(2,14),V0=Math.pow(2,21),Ya=Math.pow(2,28),Ga=Math.pow(2,35),Za=Math.pow(2,42),Wa=Math.pow(2,49),Y=128,ve=127;function Rn(t){if(t<M0)return 1;if(t<K0)return 2;if(t<V0)return 3;if(t<Ya)return 4;if(t<Ga)return 5;if(t<Za)return 6;if(t<Wa)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function q0(t,e,r=0){switch(Rn(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 z0(t,e,r=0){switch(Rn(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 H0(t,e){let r=t[e],n=0;if(n+=r&ve,r<Y||(r=t[e+1],n+=(r&ve)<<7,r<Y)||(r=t[e+2],n+=(r&ve)<<14,r<Y)||(r=t[e+3],n+=(r&ve)<<21,r<Y)||(r=t[e+4],n+=(r&ve)*Ya,r<Y)||(r=t[e+5],n+=(r&ve)*Ga,r<Y)||(r=t[e+6],n+=(r&ve)*Za,r<Y)||(r=t[e+7],n+=(r&ve)*Wa,r<Y))return n;throw new RangeError("Could not decode varint")}function $0(t,e){let r=t.get(e),n=0;if(n+=r&ve,r<Y||(r=t.get(e+1),n+=(r&ve)<<7,r<Y)||(r=t.get(e+2),n+=(r&ve)<<14,r<Y)||(r=t.get(e+3),n+=(r&ve)<<21,r<Y)||(r=t.get(e+4),n+=(r&ve)*Ya,r<Y)||(r=t.get(e+5),n+=(r&ve)*Ga,r<Y)||(r=t.get(e+6),n+=(r&ve)*Za,r<Y)||(r=t.get(e+7),n+=(r&ve)*Wa,r<Y))return n;throw new RangeError("Could not decode varint")}function vl(t,e,r=0){return e==null&&(e=Sl(Rn(t))),e instanceof Uint8Array?q0(t,e,r):z0(t,e,r)}function Al(t,e=0){return t instanceof Uint8Array?H0(t,e):$0(t,e)}var G0=4194304,qo=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Qa=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Ja=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},ec=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Z0(t){return typeof t?.closeRead=="function"}function W0(t){return typeof t?.close=="function"}function Xa(t){return Z0(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:W0(t)?t.status!=="open":!1}function X0(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function Q0(t,e){let r=e?.maxBufferSize??G0,n=new ce,o,s=!1;if(!X0(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 qo("Stream was unwrapped");if(Xa(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 ja(o.promise,u?.signal),Xa(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(Xa(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,p),new Qt(`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 qo("Stream was unwrapped");t.send(u)||await wl(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 J0(t,e={}){let r=Q0(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Rn(e.maxDataLength));let n=e?.lengthDecoder??Al,o=e?.lengthEncoder??vl;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 Qa("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new ec(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new Ja(`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 Qt(`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 Qt(`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 Mr(t,e){let r=J0(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 ey(t){return t[Symbol.asyncIterator]!=null}function ty(t){if(ey(t))return(async()=>{for await(let e of t);})();for(let e of t);}var Il=ty;var zo=globalThis.CustomEvent??Event;async function*tc(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 g={done:!1};s.push(g),d().then(m=>{g.done=!0,g.ok=!0,g.value=m,o.dispatchEvent(new zo("task-complete"))},m=>{g.done=!0,g.err=m,o.dispatchEvent(new zo("task-complete"))})}c=!0,o.dispatchEvent(new zo("task-complete"))}catch(d){f=d,o.dispatchEvent(new zo("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 g=s[d];if(s.splice(d,1),d--,g.ok)yield g.value;else throw u=!0,i.resolve(),g.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 Cl="0.1.0";var _l="id/push",Tl="1.0.0",Dl="1.0.0";var Ot;(function(t){let e;t.codec=()=>(e==null&&(e=ze((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 Xe('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 Xe('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 Xe('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 Xe('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 Ve(s,t.codec())}t.encode=r;function n(s,i){return Ke(s,t.codec(),i)}t.decode=n;function o(s,i){return qe(s,t.codec(),i)}t.stream=o})(Ot||(Ot={}));var Te={protocolPrefix:"ipfs",timeout:5e3,maxInboundStreams:1,maxOutboundStreams:1,maxObservedAddresses:10,maxMessageSize:8192,runOnConnectionOpen:!0,runOnSelfUpdate:!0,runOnLimitedConnection:!0,concurrency:32};function Ll(t){return t.bytes.length===0}function rc(t){if(t!=null&&t.length>0)try{let e=Bn(t);if(!Ll(e))return e}catch{}}async function Ho(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(rc).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=Ar(o.publicKey);if(!Pu(f).equals(n.remotePeer))throw new Pe("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 et.openAndCertify(f,$e.DOMAIN),l=$e.createFromProtobuf(u.payload),p=So(u.publicKey.toCID());if(!l.peerId.equals(p))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 h;try{h=await t.get(l.peerId)}catch(g){if(g.name!=="NotFoundError")throw g}if(h!=null&&(s.metadata=h.metadata,h.peerRecordEnvelope!=null)){let g=et.createFromProtobuf(h.peerRecordEnvelope),m=$e.createFromProtobuf(g.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(g=>!Ll(g));s.addresses=d.map(g=>({isCertified:!0,multiaddr:g})),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:Bn(o.observedAddr),protocols:o.protocols,signedPeerRecord:a,connection:n};return e.safeDispatchEvent("peer:identify",{detail:c}),c}function $o(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 jo(t,e,r,n){let o=Mr(t,{maxDataLength:e}).pb(Ot),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 Kr=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??Te.timeout,this.maxInboundStreams=r.maxInboundStreams??Te.maxInboundStreams,this.maxOutboundStreams=r.maxOutboundStreams??Te.maxOutboundStreams,this.maxMessageSize=r.maxMessageSize??Te.maxMessageSize,this.maxObservedAddresses=r.maxObservedAddresses??Te.maxObservedAddresses,this.runOnLimitedConnection=r.runOnLimitedConnection??Te.runOnLimitedConnection,this.host={protocolVersion:`${r.protocolPrefix??Te.protocolPrefix}/${Cl}`,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 Yo=class extends Kr{connectionManager;concurrency;_push;constructor(e,r={}){super(e,{...r,protocol:`/${r.protocolPrefix??Te.protocolPrefix}/${_l}/${Dl}`,log:e.logger.forComponent("libp2p:identify-push")}),this.connectionManager=e.connectionManager,this.concurrency=r.concurrency??Te.concurrency,this._push=El(this.sendPushMessage.bind(this),r.debounce??1e3),(r.runOnSelfUpdate??Te.runOnSelfUpdate)&&e.events.addEventListener("self:peer:update",n=>{this.push().catch(o=>{this.log.error("error pushing updates to peers - %e",o)})})}[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 $e({peerId:this.components.peerId,multiaddrs:e}),n=await et.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 Mr(p,{maxDataLength:c.maxMessageSize}).pb(Ot).write({listenAddrs:e.map(g=>g.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 Il(tc(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 jo(e,this.maxMessageSize,o,n);await Ho(this.components.peerStore,this.components.events,n,r,$o(s)),n.trace("handled push from %p",r.remotePeer)}};var Go=class extends Kr{constructor(e,r={}){super(e,{...r,protocol:`/${r.protocolPrefix??Te.protocolPrefix}/${"id"}/${Tl}`,log:e.logger.forComponent("libp2p:identify")}),(r.runOnConnectionOpen??Te.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 jo(n,this.maxMessageSize,r,o);return $o(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=Ar(o),c=So(a.toCID());if(!e.remotePeer.equals(c))throw new Pe("Identified peer does not match the expected peer");if(this.components.peerId.equals(c))throw new Pe("Identified peer is our own peer id?");return this.maybeAddObservedAddress(i),this.log("completed for peer %p and protocols %o",c,s),Ho(this.components.peerStore,this.components.events,this.log,e,n)}maybeAddObservedAddress(e){let r=rc(e);if(r==null||(this.log.trace("our observed address was %a",r),fl(r)))return;let n=r.getComponents();if((n[0].code===41||n[0].code===42&&n[1].code===41)&&!nl(r)){this.log.trace("our observed address was IPv6 but not a global unicast address");return}pl.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 $e({peerId:this.components.peerId,multiaddrs:i});a=(await et.seal(u,this.components.privateKey,{signal:o})).marshal().subarray()}let c=r.remoteAddr.bytes;hl.matches(r.remoteAddr)||(c=void 0);let f=Mr(e).pb(Ot);n("send response"),await f.write({protocolVersion:this.host.protocolVersion,agentVersion:this.host.agentVersion,publicKey:Ye(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 iy(t={}){return e=>new Go(e,t)}function ay(t={}){return e=>new Yo(e,t)}return kl(cy);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/curves/utils.js: