@libp2p/autonat 2.0.12-4761dd701 → 2.0.12-6ab85ea68

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/README.md CHANGED
@@ -61,7 +61,7 @@ $ npm i @libp2p/autonat
61
61
 
62
62
  ## Browser `<script>` tag
63
63
 
64
- Loading this module through a script tag will make it's exports available as `Libp2pAutonat` in the global namespace.
64
+ Loading this module through a script tag will make its exports available as `Libp2pAutonat` in the global namespace.
65
65
 
66
66
  ```html
67
67
  <script src="https://unpkg.com/@libp2p/autonat/dist/index.min.js"></script>
package/dist/index.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PAutonat = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PAutonat=(()=>{var Ui=Object.create;var Qe=Object.defineProperty;var _i=Object.getOwnPropertyDescriptor;var Ni=Object.getOwnPropertyNames;var Pi=Object.getPrototypeOf,Oi=Object.prototype.hasOwnProperty;var Ci=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),ht=(r,t)=>{for(var e in t)Qe(r,e,{get:t[e],enumerable:!0})},Oo=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ni(t))!Oi.call(r,o)&&o!==e&&Qe(r,o,{get:()=>t[o],enumerable:!(n=_i(t,o))||n.enumerable});return r};var ki=(r,t,e)=>(e=r!=null?Ui(Pi(r)):{},Oo(t||!r||!r.__esModule?Qe(e,"default",{value:r,enumerable:!0}):e,r)),Fi=r=>Oo(Qe({},"__esModule",{value:!0}),r);var Js=Ci(Xe=>{(function(){var r,t,e,n,o,s,i,f;f=function(u){var a,l,c,d;return a=(u&255<<24)>>>24,l=(u&255<<16)>>>16,c=(u&65280)>>>8,d=u&255,[a,l,c,d].join(".")},i=function(u){var a,l,c,d,g,p;for(a=[],c=d=0;d<=3&&u.length!==0;c=++d){if(c>0){if(u[0]!==".")throw new Error("Invalid IP");u=u.substring(1)}p=t(u),g=p[0],l=p[1],u=u.substring(l),a.push(g)}if(u.length!==0)throw new Error("Invalid IP");switch(a.length){case 1:if(a[0]>4294967295)throw new Error("Invalid IP");return a[0]>>>0;case 2:if(a[0]>255||a[1]>16777215)throw new Error("Invalid IP");return(a[0]<<24|a[1])>>>0;case 3:if(a[0]>255||a[1]>255||a[2]>65535)throw new Error("Invalid IP");return(a[0]<<24|a[1]<<16|a[2])>>>0;case 4:if(a[0]>255||a[1]>255||a[2]>255||a[3]>255)throw new Error("Invalid IP");return(a[0]<<24|a[1]<<16|a[2]<<8|a[3])>>>0;default:throw new Error("Invalid IP")}},e=function(u){return u.charCodeAt(0)},n=e("0"),s=e("a"),o=e("A"),t=function(u){var a,l,c,d,g;for(d=0,a=10,l="9",c=0,u.length>1&&u[c]==="0"&&(u[c+1]==="x"||u[c+1]==="X"?(c+=2,a=16):"0"<=u[c+1]&&u[c+1]<="9"&&(c++,a=8,l="7")),g=c;c<u.length;){if("0"<=u[c]&&u[c]<=l)d=d*a+(e(u[c])-n)>>>0;else if(a===16)if("a"<=u[c]&&u[c]<="f")d=d*a+(10+e(u[c])-s)>>>0;else if("A"<=u[c]&&u[c]<="F")d=d*a+(10+e(u[c])-o)>>>0;else break;else break;if(d>4294967295)throw new Error("too large");c++}if(c===g)throw new Error("empty octet");return[d,c]},r=function(){function u(a,l){var c,d,g,p;if(typeof a!="string")throw new Error("Missing `net' parameter");if(l||(p=a.split("/",2),a=p[0],l=p[1]),l||(l=32),typeof l=="string"&&l.indexOf(".")>-1){try{this.maskLong=i(l)}catch(m){throw c=m,new Error("Invalid mask: "+l)}for(d=g=32;g>=0;d=--g)if(this.maskLong===4294967295<<32-d>>>0){this.bitmask=d;break}}else if(l||l===0)this.bitmask=parseInt(l,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(i(a)&this.maskLong)>>>0}catch(m){throw c=m,new Error("Invalid net address: "+a)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+l);this.size=Math.pow(2,32-this.bitmask),this.base=f(this.netLong),this.mask=f(this.maskLong),this.hostmask=f(~this.maskLong),this.first=this.bitmask<=30?f(this.netLong+1):this.base,this.last=this.bitmask<=30?f(this.netLong+this.size-2):f(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?f(this.netLong+this.size-1):void 0}return u.prototype.contains=function(a){return typeof a=="string"&&(a.indexOf("/")>0||a.split(".").length!==4)&&(a=new u(a)),a instanceof u?this.contains(a.base)&&this.contains(a.broadcast||a.last):(i(a)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},u.prototype.next=function(a){return a==null&&(a=1),new u(f(this.netLong+this.size*a),this.mask)},u.prototype.forEach=function(a){var l,c,d;for(d=i(this.first),c=i(this.last),l=0;d<=c;)a(f(d),d,l),l++,d++},u.prototype.toString=function(){return this.base+"/"+this.bitmask},u}(),Xe.ip2long=i,Xe.long2ip=f,Xe.Netmask=r}).call(Xe)});var mf={};ht(mf,{autoNAT:()=>pf});var Zr=Symbol.for("@libp2p/peer-id");var Ue=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var _e=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Je=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var tr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Ne=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var jr=(r,...t)=>{try{[...t]}catch{}};var Co=Symbol.for("@libp2p/service-capabilities"),wf=Symbol.for("@libp2p/service-dependencies");var Qr={};ht(Qr,{base58btc:()=>W,base58flickr:()=>Vi});var Vf=new Uint8Array(0);function ko(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Lt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function Fo(r){return new TextEncoder().encode(r)}function Mo(r){return new TextDecoder().decode(r)}function Mi(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var f=r.length,u=r.charAt(0),a=Math.log(f)/Math.log(256),l=Math.log(256)/Math.log(f);function c(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var m=0,h=0,w=0,v=p.length;w!==v&&p[w]===0;)w++,m++;for(var x=(v-w)*l+1>>>0,I=new Uint8Array(x);w!==v;){for(var D=p[w],U=0,B=x-1;(D!==0||U<h)&&B!==-1;B--,U++)D+=256*I[B]>>>0,I[B]=D%f>>>0,D=D/f>>>0;if(D!==0)throw new Error("Non-zero carry");h=U,w++}for(var R=x-h;R!==x&&I[R]===0;)R++;for(var L=u.repeat(m);R<x;++R)L+=r.charAt(I[R]);return L}function d(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var m=0;if(p[m]!==" "){for(var h=0,w=0;p[m]===u;)h++,m++;for(var v=(p.length-m)*a+1>>>0,x=new Uint8Array(v);p[m];){var I=e[p.charCodeAt(m)];if(I===255)return;for(var D=0,U=v-1;(I!==0||D<w)&&U!==-1;U--,D++)I+=f*x[U]>>>0,x[U]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");w=D,m++}if(p[m]!==" "){for(var B=v-w;B!==v&&x[B]===0;)B++;for(var R=new Uint8Array(h+(v-B)),L=h;B!==v;)R[L++]=x[B++];return R}}}function g(p){var m=d(p);if(m)return m;throw new Error(`Non-${t} character`)}return{encode:c,decodeUnsafe:d,decode:g}}var Hi=Mi,Ki=Hi,Ko=Ki;var $r=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Xr=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return qo(this,t)}},Yr=class{decoders;constructor(t){this.decoders=t}or(t){return qo(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function qo(r,t){return new Yr({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Wr=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new $r(t,e,n),this.decoder=new Xr(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function he({name:r,prefix:t,encode:e,decode:n}){return new Wr(r,t,e,n)}function qt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Ko(e,r);return he({prefix:t,name:r,encode:n,decode:s=>Lt(o(s))})}function qi(r,t,e,n){let o={};for(let l=0;l<t.length;++l)o[t[l]]=l;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*e/8|0),f=0,u=0,a=0;for(let l=0;l<s;++l){let c=o[r[l]];if(c===void 0)throw new SyntaxError(`Non-${n} character`);u=u<<e|c,f+=e,f>=8&&(f-=8,i[a++]=255&u>>f)}if(f>=e||255&u<<8-f)throw new SyntaxError("Unexpected end of data");return i}function zi(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,f=0;for(let u=0;u<r.length;++u)for(f=f<<8|r[u],i+=8;i>e;)i-=e,s+=t[o&f>>i];if(i!==0&&(s+=t[o&f<<e-i]),n)for(;s.length*e&7;)s+="=";return s}function Y({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return he({prefix:t,name:r,encode(o){return zi(o,n,e)},decode(o){return qi(o,n,e,r)}})}var W=qt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Vi=qt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Jr={};ht(Jr,{base32:()=>Tt,base32hex:()=>$i,base32hexpad:()=>Yi,base32hexpadupper:()=>Wi,base32hexupper:()=>Xi,base32pad:()=>Zi,base32padupper:()=>ji,base32upper:()=>Gi,base32z:()=>Qi});var Tt=Y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Gi=Y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Zi=Y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ji=Y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),$i=Y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Xi=Y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Yi=Y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Wi=Y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Qi=Y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var tn={};ht(tn,{base36:()=>Pe,base36upper:()=>Ji});var Pe=qt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ji=qt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ta=Go,zo=128,ea=127,ra=~ea,na=Math.pow(2,31);function Go(r,t,e){t=t||[],e=e||0;for(var n=e;r>=na;)t[e++]=r&255|zo,r/=128;for(;r&ra;)t[e++]=r&255|zo,r>>>=7;return t[e]=r|0,Go.bytes=e-n+1,t}var oa=en,sa=128,Vo=127;function en(r,n){var e=0,n=n||0,o=0,s=n,i,f=r.length;do{if(s>=f)throw en.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Vo)<<o:(i&Vo)*Math.pow(2,o),o+=7}while(i>=sa);return en.bytes=s-n,e}var ia=Math.pow(2,7),aa=Math.pow(2,14),ca=Math.pow(2,21),ua=Math.pow(2,28),fa=Math.pow(2,35),la=Math.pow(2,42),da=Math.pow(2,49),ha=Math.pow(2,56),pa=Math.pow(2,63),ma=function(r){return r<ia?1:r<aa?2:r<ca?3:r<ua?4:r<fa?5:r<la?6:r<da?7:r<ha?8:r<pa?9:10},ga={encode:ta,decode:oa,encodingLength:ma},ya=ga,Oe=ya;function Ce(r,t=0){return[Oe.decode(r,t),Oe.decode.bytes]}function pe(r,t,e=0){return Oe.encode(r,t,e),t}function me(r){return Oe.encodingLength(r)}function ee(r,t){let e=t.byteLength,n=me(r),o=n+me(e),s=new Uint8Array(o+e);return pe(r,s,0),pe(e,s,n),s.set(t,o),new ge(r,e,t,s)}function re(r){let t=Lt(r),[e,n]=Ce(t),[o,s]=Ce(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ge(e,o,i,t)}function Zo(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&ko(r.bytes,e.bytes)}}var ge=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function jo(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return ba(e,rn(r),t??W.encoder);default:return wa(e,rn(r),t??Tt.encoder)}}var $o=new WeakMap;function rn(r){let t=$o.get(r);if(t==null){let e=new Map;return $o.set(r,e),e}return t}var lt=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,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:t,multihash:e}=this;if(t!==ke)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Ea)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}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:t,digest:e}=this.multihash,n=ee(t,e);return r.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(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&Zo(t.multihash,n.multihash)}toString(t){return jo(this,t)}toJSON(){return{"/":jo(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??Xo(n,o,s.bytes))}else if(e[va]===!0){let{version:n,multihash:o,code:s}=e,i=re(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==ke)throw new Error(`Version 0 CID must use dag-pb (code: ${ke}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Xo(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,ke,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=Lt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new ge(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[c,d]=Ce(t.subarray(e));return e+=d,c},o=n(),s=ke;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,f=n(),u=n(),a=e+u,l=a-i;return{version:o,codec:s,multihashCode:f,digestSize:u,multihashSize:l,size:a}}static parse(t,e){let[n,o]=xa(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return rn(s).set(n,t),s}};function xa(r,t){switch(r[0]){case"Q":{let e=t??W;return[W.prefix,e.decode(`${W.prefix}${r}`)]}case W.prefix:{let e=t??W;return[W.prefix,e.decode(r)]}case Tt.prefix:{let e=t??Tt;return[Tt.prefix,e.decode(r)]}case Pe.prefix:{let e=t??Pe;return[Pe.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function ba(r,t,e){let{prefix:n}=e;if(n!==W.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function wa(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var ke=112,Ea=18;function Xo(r,t,e){let n=me(r),o=n+me(t),s=new Uint8Array(o+e.byteLength);return pe(r,s,0),pe(t,s,n),s.set(e,o),s}var va=Symbol.for("@ipld/js-cid/CID");var nn={};ht(nn,{identity:()=>Rt});var Yo=0,Aa="identity",Wo=Lt;function Sa(r){return ee(Yo,Wo(r))}var Rt={code:Yo,name:Aa,encode:Wo,digest:Sa};function bt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Qo(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function Ia(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function ye(r,...t){if(!Ia(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error("Uint8Array expected of length "+t+", got length="+r.length)}function Jo(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Qo(r.outputLen),Qo(r.blockLen)}function xe(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function ts(r,t){ye(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}var ne=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var rr=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),wt=(r,t)=>r<<32-t|r>>>t;function es(r){if(typeof r!="string")throw new Error("utf8ToBytes expected string, got "+typeof r);return new Uint8Array(new TextEncoder().encode(r))}function Fe(r){return typeof r=="string"&&(r=es(r)),ye(r),r}function on(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];ye(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}var be=class{clone(){return this._cloneInto()}};function nr(r){let t=n=>r().update(Fe(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function or(r=32){if(ne&&typeof ne.getRandomValues=="function")return ne.getRandomValues(new Uint8Array(r));if(ne&&typeof ne.randomBytes=="function")return ne.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}function Ba(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(e>>o&s),f=Number(e&s),u=n?4:0,a=n?0:4;r.setUint32(t+u,i,n),r.setUint32(t+a,f,n)}var rs=(r,t,e)=>r&t^~r&e,ns=(r,t,e)=>r&t^r&e^t&e,we=class extends be{constructor(t,e,n,o){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=rr(this.buffer)}update(t){xe(this);let{view:e,buffer:n,blockLen:o}=this;t=Fe(t);let s=t.length;for(let i=0;i<s;){let f=Math.min(o-this.pos,s-i);if(f===o){let u=rr(t);for(;o<=s-i;i+=o)this.process(u,i);continue}n.set(t.subarray(i,i+f),this.pos),this.pos+=f,i+=f,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){xe(this),ts(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>o-i&&(this.process(n,0),i=0);for(let c=i;c<o;c++)e[c]=0;Ba(n,o-8,BigInt(this.length*8),s),this.process(n,0);let f=rr(t),u=this.outputLen;if(u%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let a=u/4,l=this.get();if(a>l.length)throw new Error("_sha2: outputLen bigger than state");for(let c=0;c<a;c++)f.setUint32(4*c,l[c],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:f}=this;return t.length=o,t.pos=f,t.finished=s,t.destroyed=i,o%e&&t.buffer.set(n),t}};var sr=BigInt(4294967295),sn=BigInt(32);function os(r,t=!1){return t?{h:Number(r&sr),l:Number(r>>sn&sr)}:{h:Number(r>>sn&sr)|0,l:Number(r&sr)|0}}function La(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let o=0;o<r.length;o++){let{h:s,l:i}=os(r[o],t);[e[o],n[o]]=[s,i]}return[e,n]}var Ta=(r,t)=>BigInt(r>>>0)<<sn|BigInt(t>>>0),Ra=(r,t,e)=>r>>>e,Da=(r,t,e)=>r<<32-e|t>>>e,Ua=(r,t,e)=>r>>>e|t<<32-e,_a=(r,t,e)=>r<<32-e|t>>>e,Na=(r,t,e)=>r<<64-e|t>>>e-32,Pa=(r,t,e)=>r>>>e-32|t<<64-e,Oa=(r,t)=>t,Ca=(r,t)=>r,ka=(r,t,e)=>r<<e|t>>>32-e,Fa=(r,t,e)=>t<<e|r>>>32-e,Ma=(r,t,e)=>t<<e-32|r>>>64-e,Ha=(r,t,e)=>r<<e-32|t>>>64-e;function Ka(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var qa=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),za=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Va=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Ga=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Za=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),ja=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var $a={fromBig:os,split:La,toBig:Ta,shrSH:Ra,shrSL:Da,rotrSH:Ua,rotrSL:_a,rotrBH:Na,rotrBL:Pa,rotr32H:Oa,rotr32L:Ca,rotlSH:ka,rotlSL:Fa,rotlBH:Ma,rotlBL:Ha,add:Ka,add3L:qa,add3H:za,add4L:Va,add4H:Ga,add5H:ja,add5L:Za},O=$a;var[Xa,Ya]=O.split(["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(r=>BigInt(r))),Vt=new Uint32Array(80),Gt=new Uint32Array(80),an=class extends we{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:f,Dl:u,Eh:a,El:l,Fh:c,Fl:d,Gh:g,Gl:p,Hh:m,Hl:h}=this;return[t,e,n,o,s,i,f,u,a,l,c,d,g,p,m,h]}set(t,e,n,o,s,i,f,u,a,l,c,d,g,p,m,h){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=f|0,this.Dl=u|0,this.Eh=a|0,this.El=l|0,this.Fh=c|0,this.Fl=d|0,this.Gh=g|0,this.Gl=p|0,this.Hh=m|0,this.Hl=h|0}process(t,e){for(let x=0;x<16;x++,e+=4)Vt[x]=t.getUint32(e),Gt[x]=t.getUint32(e+=4);for(let x=16;x<80;x++){let I=Vt[x-15]|0,D=Gt[x-15]|0,U=O.rotrSH(I,D,1)^O.rotrSH(I,D,8)^O.shrSH(I,D,7),B=O.rotrSL(I,D,1)^O.rotrSL(I,D,8)^O.shrSL(I,D,7),R=Vt[x-2]|0,L=Gt[x-2]|0,Z=O.rotrSH(R,L,19)^O.rotrBH(R,L,61)^O.shrSH(R,L,6),H=O.rotrSL(R,L,19)^O.rotrBL(R,L,61)^O.shrSL(R,L,6),k=O.add4L(B,H,Gt[x-7],Gt[x-16]),Q=O.add4H(k,U,Z,Vt[x-7],Vt[x-16]);Vt[x]=Q|0,Gt[x]=k|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:f,Cl:u,Dh:a,Dl:l,Eh:c,El:d,Fh:g,Fl:p,Gh:m,Gl:h,Hh:w,Hl:v}=this;for(let x=0;x<80;x++){let I=O.rotrSH(c,d,14)^O.rotrSH(c,d,18)^O.rotrBH(c,d,41),D=O.rotrSL(c,d,14)^O.rotrSL(c,d,18)^O.rotrBL(c,d,41),U=c&g^~c&m,B=d&p^~d&h,R=O.add5L(v,D,B,Ya[x],Gt[x]),L=O.add5H(R,w,I,U,Xa[x],Vt[x]),Z=R|0,H=O.rotrSH(n,o,28)^O.rotrBH(n,o,34)^O.rotrBH(n,o,39),k=O.rotrSL(n,o,28)^O.rotrBL(n,o,34)^O.rotrBL(n,o,39),Q=n&s^n&f^s&f,A=o&i^o&u^i&u;w=m|0,v=h|0,m=g|0,h=p|0,g=c|0,p=d|0,{h:c,l:d}=O.add(a|0,l|0,L|0,Z|0),a=f|0,l=u|0,f=s|0,u=i|0,s=n|0,i=o|0;let T=O.add3L(Z,k,A);n=O.add3H(T,L,H,Q),o=T|0}({h:n,l:o}=O.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=O.add(this.Bh|0,this.Bl|0,s|0,i|0),{h:f,l:u}=O.add(this.Ch|0,this.Cl|0,f|0,u|0),{h:a,l}=O.add(this.Dh|0,this.Dl|0,a|0,l|0),{h:c,l:d}=O.add(this.Eh|0,this.El|0,c|0,d|0),{h:g,l:p}=O.add(this.Fh|0,this.Fl|0,g|0,p|0),{h:m,l:h}=O.add(this.Gh|0,this.Gl|0,m|0,h|0),{h:w,l:v}=O.add(this.Hh|0,this.Hl|0,w|0,v|0),this.set(n,o,s,i,f,u,a,l,c,d,g,p,m,h,w,v)}roundClean(){Vt.fill(0),Gt.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var ss=nr(()=>new an);var cr={};ht(cr,{aInRange:()=>pt,abool:()=>Et,abytes:()=>Ee,bitGet:()=>rc,bitLen:()=>ln,bitMask:()=>He,bitSet:()=>nc,bytesToHex:()=>Ut,bytesToNumberBE:()=>_t,bytesToNumberLE:()=>jt,concatBytes:()=>Nt,createHmacDrbg:()=>dn,ensureBytes:()=>X,equalBytes:()=>tc,hexToBytes:()=>se,hexToNumber:()=>fn,inRange:()=>Me,isBytes:()=>Zt,memoized:()=>ae,notImplemented:()=>sc,numberToBytesBE:()=>$t,numberToBytesLE:()=>ie,numberToHexUnpadded:()=>oe,numberToVarBytesBE:()=>Ja,utf8ToBytes:()=>ec,validateObject:()=>It});var ir=BigInt(0),ar=BigInt(1),Wa=BigInt(2);function Zt(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Ee(r){if(!Zt(r))throw new Error("Uint8Array expected")}function Et(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}var Qa=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Ut(r){Ee(r);let t="";for(let e=0;e<r.length;e++)t+=Qa[r[e]];return t}function oe(r){let t=r.toString(16);return t.length&1?"0"+t:t}function fn(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?ir:BigInt("0x"+r)}var Dt={_0:48,_9:57,A:65,F:70,a:97,f:102};function is(r){if(r>=Dt._0&&r<=Dt._9)return r-Dt._0;if(r>=Dt.A&&r<=Dt.F)return r-(Dt.A-10);if(r>=Dt.a&&r<=Dt.f)return r-(Dt.a-10)}function se(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let t=r.length,e=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=is(r.charCodeAt(s)),f=is(r.charCodeAt(s+1));if(i===void 0||f===void 0){let u=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+u+'" at index '+s)}n[o]=i*16+f}return n}function _t(r){return fn(Ut(r))}function jt(r){return Ee(r),fn(Ut(Uint8Array.from(r).reverse()))}function $t(r,t){return se(r.toString(16).padStart(t*2,"0"))}function ie(r,t){return $t(r,t).reverse()}function Ja(r){return se(oe(r))}function X(r,t,e){let n;if(typeof t=="string")try{n=se(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(Zt(t))n=Uint8Array.from(t);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof e=="number"&&o!==e)throw new Error(r+" of length "+e+" expected, got "+o);return n}function Nt(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Ee(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}function tc(r,t){if(r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}function ec(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}var cn=r=>typeof r=="bigint"&&ir<=r;function Me(r,t,e){return cn(r)&&cn(t)&&cn(e)&&t<=r&&r<e}function pt(r,t,e,n){if(!Me(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function ln(r){let t;for(t=0;r>ir;r>>=ar,t+=1);return t}function rc(r,t){return r>>BigInt(t)&ar}function nc(r,t,e){return r|(e?ar:ir)<<BigInt(t)}var He=r=>(Wa<<BigInt(r-1))-ar,un=r=>new Uint8Array(r),as=r=>Uint8Array.from(r);function dn(r,t,e){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof e!="function")throw new Error("hmacFn must be a function");let n=un(r),o=un(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},f=(...c)=>e(o,n,...c),u=(c=un())=>{o=f(as([0]),c),n=f(),c.length!==0&&(o=f(as([1]),c),n=f())},a=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let c=0,d=[];for(;c<t;){n=f();let g=n.slice();d.push(g),c+=n.length}return Nt(...d)};return(c,d)=>{i(),u(c);let g;for(;!(g=d(a()));)u();return i(),g}}var oc={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||Zt(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function It(r,t,e={}){let n=(o,s,i)=>{let f=oc[s];if(typeof f!="function")throw new Error("invalid validator function");let u=r[o];if(!(i&&u===void 0)&&!f(u,r))throw new Error("param "+String(o)+" is invalid. Expected "+s+", got "+u)};for(let[o,s]of Object.entries(t))n(o,s,!1);for(let[o,s]of Object.entries(e))n(o,s,!0);return r}var sc=()=>{throw new Error("not implemented")};function ae(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let s=r(e,...n);return t.set(e,s),s}}var J=BigInt(0),j=BigInt(1),ce=BigInt(2),ic=BigInt(3),hn=BigInt(4),cs=BigInt(5),us=BigInt(8),ac=BigInt(9),cc=BigInt(16);function V(r,t){let e=r%t;return e>=J?e:t+e}function uc(r,t,e){if(t<J)throw new Error("invalid exponent, negatives unsupported");if(e<=J)throw new Error("invalid modulus");if(e===j)return J;let n=j;for(;t>J;)t&j&&(n=n*r%e),r=r*r%e,t>>=j;return n}function $(r,t,e){let n=r;for(;t-- >J;)n*=n,n%=e;return n}function ur(r,t){if(r===J)throw new Error("invert: expected non-zero number");if(t<=J)throw new Error("invert: expected positive modulus, got "+t);let e=V(r,t),n=t,o=J,s=j,i=j,f=J;for(;e!==J;){let a=n/e,l=n%e,c=o-i*a,d=s-f*a;n=e,e=l,o=i,s=f,i=c,f=d}if(n!==j)throw new Error("invert: does not exist");return V(o,t)}function fc(r){let t=(r-j)/ce,e,n,o;for(e=r-j,n=0;e%ce===J;e/=ce,n++);for(o=ce;o<r&&uc(o,t,r)!==r-j;o++)if(o>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let i=(r+j)/hn;return function(u,a){let l=u.pow(a,i);if(!u.eql(u.sqr(l),a))throw new Error("Cannot find square root");return l}}let s=(e+j)/ce;return function(f,u){if(f.pow(u,t)===f.neg(f.ONE))throw new Error("Cannot find square root");let a=n,l=f.pow(f.mul(f.ONE,o),e),c=f.pow(u,s),d=f.pow(u,e);for(;!f.eql(d,f.ONE);){if(f.eql(d,f.ZERO))return f.ZERO;let g=1;for(let m=f.sqr(d);g<a&&!f.eql(m,f.ONE);g++)m=f.sqr(m);let p=f.pow(l,j<<BigInt(a-g-1));l=f.sqr(p),c=f.mul(c,p),d=f.mul(d,l),a=g}return c}}function lc(r){if(r%hn===ic){let t=(r+j)/hn;return function(n,o){let s=n.pow(o,t);if(!n.eql(n.sqr(s),o))throw new Error("Cannot find square root");return s}}if(r%us===cs){let t=(r-cs)/us;return function(n,o){let s=n.mul(o,ce),i=n.pow(s,t),f=n.mul(o,i),u=n.mul(n.mul(f,ce),i),a=n.mul(f,n.sub(u,n.ONE));if(!n.eql(n.sqr(a),o))throw new Error("Cannot find square root");return a}}return r%cc,fc(r)}var fs=(r,t)=>(V(r,t)&j)===j,dc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function pn(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=dc.reduce((n,o)=>(n[o]="function",n),t);return It(r,e)}function hc(r,t,e){if(e<J)throw new Error("invalid exponent, negatives unsupported");if(e===J)return r.ONE;if(e===j)return t;let n=r.ONE,o=t;for(;e>J;)e&j&&(n=r.mul(n,o)),o=r.sqr(o),e>>=j;return n}function pc(r,t){let e=new Array(t.length),n=t.reduce((s,i,f)=>r.is0(i)?s:(e[f]=s,r.mul(s,i)),r.ONE),o=r.inv(n);return t.reduceRight((s,i,f)=>r.is0(i)?s:(e[f]=r.mul(s,e[f]),r.mul(s,i)),o),e}function mn(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function Xt(r,t,e=!1,n={}){if(r<=J)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:s}=mn(r,t);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let i,f=Object.freeze({ORDER:r,BITS:o,BYTES:s,MASK:He(o),ZERO:J,ONE:j,create:u=>V(u,r),isValid:u=>{if(typeof u!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof u);return J<=u&&u<r},is0:u=>u===J,isOdd:u=>(u&j)===j,neg:u=>V(-u,r),eql:(u,a)=>u===a,sqr:u=>V(u*u,r),add:(u,a)=>V(u+a,r),sub:(u,a)=>V(u-a,r),mul:(u,a)=>V(u*a,r),pow:(u,a)=>hc(f,u,a),div:(u,a)=>V(u*ur(a,r),r),sqrN:u=>u*u,addN:(u,a)=>u+a,subN:(u,a)=>u-a,mulN:(u,a)=>u*a,inv:u=>ur(u,r),sqrt:n.sqrt||(u=>(i||(i=lc(r)),i(f,u))),invertBatch:u=>pc(f,u),cmov:(u,a,l)=>l?a:u,toBytes:u=>e?ie(u,s):$t(u,s),fromBytes:u=>{if(u.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+u.length);return e?jt(u):_t(u)}});return Object.freeze(f)}function ls(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function gn(r){let t=ls(r);return t+Math.ceil(t/2)}function ds(r,t,e=!1){let n=r.length,o=ls(t),s=gn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?_t(r):jt(r),f=V(i,t-j)+j;return e?ie(f,o):$t(f,o)}var hs=BigInt(0),fr=BigInt(1);function yn(r,t){let e=t.negate();return r?e:t}function ps(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function xn(r,t){ps(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1);return{windows:e,windowSize:n}}function gc(r,t){if(!Array.isArray(r))throw new Error("array expected");r.forEach((e,n)=>{if(!(e instanceof t))throw new Error("invalid point at index "+n)})}function yc(r,t){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((e,n)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+n)})}var bn=new WeakMap,ms=new WeakMap;function wn(r){return ms.get(r)||1}function lr(r,t){return{constTimeNegate:yn,hasPrecomputes(e){return wn(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>hs;)n&fr&&(o=o.add(s)),s=s.double(),n>>=fr;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=xn(n,t),i=[],f=e,u=f;for(let a=0;a<o;a++){u=f,i.push(u);for(let l=1;l<s;l++)u=u.add(f),i.push(u);f=u.double()}return i},wNAF(e,n,o){let{windows:s,windowSize:i}=xn(e,t),f=r.ZERO,u=r.BASE,a=BigInt(2**e-1),l=2**e,c=BigInt(e);for(let d=0;d<s;d++){let g=d*i,p=Number(o&a);o>>=c,p>i&&(p-=l,o+=fr);let m=g,h=g+Math.abs(p)-1,w=d%2!==0,v=p<0;p===0?u=u.add(yn(w,n[m])):f=f.add(yn(v,n[h]))}return{p:f,f:u}},wNAFUnsafe(e,n,o,s=r.ZERO){let{windows:i,windowSize:f}=xn(e,t),u=BigInt(2**e-1),a=2**e,l=BigInt(e);for(let c=0;c<i;c++){let d=c*f;if(o===hs)break;let g=Number(o&u);if(o>>=l,g>f&&(g-=a,o+=fr),g===0)continue;let p=n[d+Math.abs(g)-1];g<0&&(p=p.negate()),s=s.add(p)}return s},getPrecomputes(e,n,o){let s=bn.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&bn.set(n,o(s))),s},wNAFCached(e,n,o){let s=wn(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=wn(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){ps(n,t),ms.set(e,n),bn.delete(e)}}}function dr(r,t,e,n){if(gc(e,r),yc(n,t),e.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=r.ZERO,s=ln(BigInt(e.length)),i=s>12?s-3:s>4?s-2:s?2:1,f=(1<<i)-1,u=new Array(f+1).fill(o),a=Math.floor((t.BITS-1)/i)*i,l=o;for(let c=a;c>=0;c-=i){u.fill(o);for(let g=0;g<n.length;g++){let p=n[g],m=Number(p>>BigInt(c)&BigInt(f));u[m]=u[m].add(e[g])}let d=o;for(let g=u.length-1,p=o;g>0;g--)p=p.add(u[g]),d=d.add(p);if(l=l.add(d),c!==0)for(let g=0;g<i;g++)l=l.double()}return l}function Ke(r){return pn(r.Fp),It(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...mn(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var vt=BigInt(0),mt=BigInt(1),hr=BigInt(2),xc=BigInt(8),bc={zip215:!0};function wc(r){let t=Ke(r);return It(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function gs(r){let t=wc(r),{Fp:e,n,prehash:o,hash:s,randomBytes:i,nByteLength:f,h:u}=t,a=hr<<BigInt(f*8)-mt,l=e.create,c=Xt(t.n,t.nBitLength),d=t.uvRatio||((b,y)=>{try{return{isValid:!0,value:e.sqrt(b*e.inv(y))}}catch{return{isValid:!1,value:vt}}}),g=t.adjustScalarBytes||(b=>b),p=t.domain||((b,y,E)=>{if(Et("phflag",E),y.length||E)throw new Error("Contexts/pre-hash are not supported");return b});function m(b,y){pt("coordinate "+b,y,vt,a)}function h(b){if(!(b instanceof x))throw new Error("ExtendedPoint expected")}let w=ae((b,y)=>{let{ex:E,ey:S,ez:_}=b,N=b.is0();y==null&&(y=N?xc:e.inv(_));let C=l(E*y),F=l(S*y),P=l(_*y);if(N)return{x:vt,y:mt};if(P!==mt)throw new Error("invZ was invalid");return{x:C,y:F}}),v=ae(b=>{let{a:y,d:E}=t;if(b.is0())throw new Error("bad point: ZERO");let{ex:S,ey:_,ez:N,et:C}=b,F=l(S*S),P=l(_*_),q=l(N*N),G=l(q*q),tt=l(F*y),et=l(q*l(tt+P)),st=l(G+l(E*l(F*P)));if(et!==st)throw new Error("bad point: equation left != right (1)");let it=l(S*_),dt=l(N*C);if(it!==dt)throw new Error("bad point: equation left != right (2)");return!0});class x{constructor(y,E,S,_){this.ex=y,this.ey=E,this.ez=S,this.et=_,m("x",y),m("y",E),m("z",S),m("t",_),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(y){if(y instanceof x)throw new Error("extended point not allowed");let{x:E,y:S}=y||{};return m("x",E),m("y",S),new x(E,S,mt,l(E*S))}static normalizeZ(y){let E=e.invertBatch(y.map(S=>S.ez));return y.map((S,_)=>S.toAffine(E[_])).map(x.fromAffine)}static msm(y,E){return dr(x,c,y,E)}_setWindowSize(y){U.setWindowSize(this,y)}assertValidity(){v(this)}equals(y){h(y);let{ex:E,ey:S,ez:_}=this,{ex:N,ey:C,ez:F}=y,P=l(E*F),q=l(N*_),G=l(S*F),tt=l(C*_);return P===q&&G===tt}is0(){return this.equals(x.ZERO)}negate(){return new x(l(-this.ex),this.ey,this.ez,l(-this.et))}double(){let{a:y}=t,{ex:E,ey:S,ez:_}=this,N=l(E*E),C=l(S*S),F=l(hr*l(_*_)),P=l(y*N),q=E+S,G=l(l(q*q)-N-C),tt=P+C,et=tt-F,st=P-C,it=l(G*et),dt=l(tt*st),ft=l(G*st),St=l(et*tt);return new x(it,dt,St,ft)}add(y){h(y);let{a:E,d:S}=t,{ex:_,ey:N,ez:C,et:F}=this,{ex:P,ey:q,ez:G,et:tt}=y;if(E===BigInt(-1)){let To=l((N-_)*(q+P)),Ro=l((N+_)*(q-P)),Gr=l(Ro-To);if(Gr===vt)return this.double();let Do=l(C*hr*tt),Uo=l(F*hr*G),_o=Uo+Do,No=Ro+To,Po=Uo-Do,Li=l(_o*Gr),Ti=l(No*Po),Ri=l(_o*Po),Di=l(Gr*No);return new x(Li,Ti,Di,Ri)}let et=l(_*P),st=l(N*q),it=l(F*S*tt),dt=l(C*G),ft=l((_+N)*(P+q)-et-st),St=dt-it,Bt=dt+it,De=l(st-E*et),Ai=l(ft*St),Si=l(Bt*De),Ii=l(ft*De),Bi=l(St*Bt);return new x(Ai,Si,Bi,Ii)}subtract(y){return this.add(y.negate())}wNAF(y){return U.wNAFCached(this,y,x.normalizeZ)}multiply(y){let E=y;pt("scalar",E,mt,n);let{p:S,f:_}=this.wNAF(E);return x.normalizeZ([S,_])[0]}multiplyUnsafe(y,E=x.ZERO){let S=y;return pt("scalar",S,vt,n),S===vt?D:this.is0()||S===mt?this:U.wNAFCachedUnsafe(this,S,x.normalizeZ,E)}isSmallOrder(){return this.multiplyUnsafe(u).is0()}isTorsionFree(){return U.unsafeLadder(this,n).is0()}toAffine(y){return w(this,y)}clearCofactor(){let{h:y}=t;return y===mt?this:this.multiplyUnsafe(y)}static fromHex(y,E=!1){let{d:S,a:_}=t,N=e.BYTES;y=X("pointHex",y,N),Et("zip215",E);let C=y.slice(),F=y[N-1];C[N-1]=F&-129;let P=jt(C),q=E?a:e.ORDER;pt("pointHex.y",P,vt,q);let G=l(P*P),tt=l(G-mt),et=l(S*G-_),{isValid:st,value:it}=d(tt,et);if(!st)throw new Error("Point.fromHex: invalid y coordinate");let dt=(it&mt)===mt,ft=(F&128)!==0;if(!E&&it===vt&&ft)throw new Error("Point.fromHex: x=0 and x_0=1");return ft!==dt&&(it=l(-it)),x.fromAffine({x:it,y:P})}static fromPrivateKey(y){return L(y).point}toRawBytes(){let{x:y,y:E}=this.toAffine(),S=ie(E,e.BYTES);return S[S.length-1]|=y&mt?128:0,S}toHex(){return Ut(this.toRawBytes())}}x.BASE=new x(t.Gx,t.Gy,mt,l(t.Gx*t.Gy)),x.ZERO=new x(vt,mt,mt,vt);let{BASE:I,ZERO:D}=x,U=lr(x,f*8);function B(b){return V(b,n)}function R(b){return B(jt(b))}function L(b){let y=e.BYTES;b=X("private key",b,y);let E=X("hashed private key",s(b),2*y),S=g(E.slice(0,y)),_=E.slice(y,2*y),N=R(S),C=I.multiply(N),F=C.toRawBytes();return{head:S,prefix:_,scalar:N,point:C,pointBytes:F}}function Z(b){return L(b).pointBytes}function H(b=new Uint8Array,...y){let E=Nt(...y);return R(s(p(E,X("context",b),!!o)))}function k(b,y,E={}){b=X("message",b),o&&(b=o(b));let{prefix:S,scalar:_,pointBytes:N}=L(y),C=H(E.context,S,b),F=I.multiply(C).toRawBytes(),P=H(E.context,F,N,b),q=B(C+P*_);pt("signature.s",q,vt,n);let G=Nt(F,ie(q,e.BYTES));return X("result",G,e.BYTES*2)}let Q=bc;function A(b,y,E,S=Q){let{context:_,zip215:N}=S,C=e.BYTES;b=X("signature",b,2*C),y=X("message",y),E=X("publicKey",E,C),N!==void 0&&Et("zip215",N),o&&(y=o(y));let F=jt(b.slice(C,2*C)),P,q,G;try{P=x.fromHex(E,N),q=x.fromHex(b.slice(0,C),N),G=I.multiplyUnsafe(F)}catch{return!1}if(!N&&P.isSmallOrder())return!1;let tt=H(_,q.toRawBytes(),P.toRawBytes(),y);return q.add(P.multiplyUnsafe(tt)).subtract(G).clearCofactor().equals(x.ZERO)}return I._setWindowSize(8),{CURVE:t,getPublicKey:Z,sign:k,verify:A,ExtendedPoint:x,utils:{getExtendedPublicKey:L,randomPrivateKey:()=>i(e.BYTES),precompute(b=8,y=x.BASE){return y._setWindowSize(b),y.multiply(BigInt(3)),y}}}}var En=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),ys=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Ol=BigInt(0),Ec=BigInt(1),xs=BigInt(2),Cl=BigInt(3),vc=BigInt(5),Ac=BigInt(8);function Sc(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=En,f=r*r%s*r%s,u=$(f,xs,s)*f%s,a=$(u,Ec,s)*r%s,l=$(a,vc,s)*a%s,c=$(l,t,s)*l%s,d=$(c,e,s)*c%s,g=$(d,n,s)*d%s,p=$(g,o,s)*g%s,m=$(p,o,s)*g%s,h=$(m,t,s)*l%s;return{pow_p_5_8:$(h,xs,s)*r%s,b2:f}}function Ic(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Bc(r,t){let e=En,n=V(t*t*t,e),o=V(n*n*t,e),s=Sc(r*o).pow_p_5_8,i=V(r*n*s,e),f=V(t*i*i,e),u=i,a=V(i*ys,e),l=f===r,c=f===V(-r,e),d=f===V(-r*ys,e);return l&&(i=u),(c||d)&&(i=a),fs(i,e)&&(i=V(-i,e)),{isValid:l||c,value:i}}var Lc=Xt(En,void 0,!0),Tc={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Lc,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:Ac,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:ss,randomBytes:or,adjustScalarBytes:Ic,uvRatio:Bc},bs=gs(Tc);var pr=32;function ws(r,t,e){return bs.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var mr=class{type="Ed25519";raw;constructor(t){this.raw=vn(t,pr)}toMultihash(){return Rt.digest(gr(this))}toCID(){return lt.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,e){return ws(this.raw,e,t)}};function vs(r){return r=vn(r,pr),new mr(r)}function vn(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new _e(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}function Pt(r=0){return new Uint8Array(r)}function at(r=0){return new Uint8Array(r)}var Dc=Math.pow(2,7),Uc=Math.pow(2,14),_c=Math.pow(2,21),An=Math.pow(2,28),Sn=Math.pow(2,35),In=Math.pow(2,42),Bn=Math.pow(2,49),K=128,ct=127;function rt(r){if(r<Dc)return 1;if(r<Uc)return 2;if(r<_c)return 3;if(r<An)return 4;if(r<Sn)return 5;if(r<In)return 6;if(r<Bn)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ln(r,t,e=0){switch(rt(r)){case 8:t[e++]=r&255|K,r/=128;case 7:t[e++]=r&255|K,r/=128;case 6:t[e++]=r&255|K,r/=128;case 5:t[e++]=r&255|K,r/=128;case 4:t[e++]=r&255|K,r>>>=7;case 3:t[e++]=r&255|K,r>>>=7;case 2:t[e++]=r&255|K,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Nc(r,t,e=0){switch(rt(r)){case 8:t.set(e++,r&255|K),r/=128;case 7:t.set(e++,r&255|K),r/=128;case 6:t.set(e++,r&255|K),r/=128;case 5:t.set(e++,r&255|K),r/=128;case 4:t.set(e++,r&255|K),r>>>=7;case 3:t.set(e++,r&255|K),r>>>=7;case 2:t.set(e++,r&255|K),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Tn(r,t){let e=r[t],n=0;if(n+=e&ct,e<K||(e=r[t+1],n+=(e&ct)<<7,e<K)||(e=r[t+2],n+=(e&ct)<<14,e<K)||(e=r[t+3],n+=(e&ct)<<21,e<K)||(e=r[t+4],n+=(e&ct)*An,e<K)||(e=r[t+5],n+=(e&ct)*Sn,e<K)||(e=r[t+6],n+=(e&ct)*In,e<K)||(e=r[t+7],n+=(e&ct)*Bn,e<K))return n;throw new RangeError("Could not decode varint")}function Pc(r,t){let e=r.get(t),n=0;if(n+=e&ct,e<K||(e=r.get(t+1),n+=(e&ct)<<7,e<K)||(e=r.get(t+2),n+=(e&ct)<<14,e<K)||(e=r.get(t+3),n+=(e&ct)<<21,e<K)||(e=r.get(t+4),n+=(e&ct)*An,e<K)||(e=r.get(t+5),n+=(e&ct)*Sn,e<K)||(e=r.get(t+6),n+=(e&ct)*In,e<K)||(e=r.get(t+7),n+=(e&ct)*Bn,e<K))return n;throw new RangeError("Could not decode varint")}function Yt(r,t,e=0){return t==null&&(t=at(rt(r))),t instanceof Uint8Array?Ln(r,t,e):Nc(r,t,e)}function Ot(r,t=0){return r instanceof Uint8Array?Tn(r,t):Pc(r,t)}var Rn=new Float32Array([-0]),Wt=new Uint8Array(Rn.buffer);function As(r,t,e){Rn[0]=r,t[e]=Wt[0],t[e+1]=Wt[1],t[e+2]=Wt[2],t[e+3]=Wt[3]}function Ss(r,t){return Wt[0]=r[t],Wt[1]=r[t+1],Wt[2]=r[t+2],Wt[3]=r[t+3],Rn[0]}var Dn=new Float64Array([-0]),ut=new Uint8Array(Dn.buffer);function Is(r,t,e){Dn[0]=r,t[e]=ut[0],t[e+1]=ut[1],t[e+2]=ut[2],t[e+3]=ut[3],t[e+4]=ut[4],t[e+5]=ut[5],t[e+6]=ut[6],t[e+7]=ut[7]}function Bs(r,t){return ut[0]=r[t],ut[1]=r[t+1],ut[2]=r[t+2],ut[3]=r[t+3],ut[4]=r[t+4],ut[5]=r[t+5],ut[6]=r[t+6],ut[7]=r[t+7],Dn[0]}var Oc=BigInt(Number.MAX_SAFE_INTEGER),Cc=BigInt(Number.MIN_SAFE_INTEGER),gt=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return ue;if(t<Oc&&t>Cc)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>Ls&&(o=0n,++n>Ls&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return ue;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):ue}},ue=new gt(0,0);ue.toBigInt=function(){return 0n};ue.zzEncode=ue.zzDecode=function(){return this};ue.length=function(){return 1};var Ls=4294967296n;function Ts(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Rs(r,t,e){if(e-t<1)return"";let o,s=[],i=0,f;for(;t<e;)f=r[t++],f<128?s[i++]=f:f>191&&f<224?s[i++]=(f&31)<<6|r[t++]&63:f>239&&f<365?(f=((f&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(f>>10),s[i++]=56320+(f&1023)):s[i++]=(f&15)<<12|(r[t++]&63)<<6|r[t++]&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 Un(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function At(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function xr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var _n=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,At(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw At(this,4);return xr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw At(this,4);return xr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw At(this,4);let t=Ss(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw At(this,4);let t=Bs(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw At(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Rs(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw At(this,t);this.pos+=t}else do if(this.pos>=this.len)throw At(this);while(this.buf[this.pos++]&128);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new gt(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw At(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw At(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw At(this,8);let t=xr(this.buf,this.pos+=4),e=xr(this.buf,this.pos+=4);return new gt(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Tn(this.buf,this.pos);return this.pos+=rt(t),t}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 Nn(r){return new _n(r instanceof Uint8Array?r:r.subarray())}function Ct(r,t,e){let n=Nn(r);return t.decode(n,void 0,e)}var Pn={};ht(Pn,{base10:()=>kc});var kc=qt({prefix:"9",name:"base10",alphabet:"0123456789"});var On={};ht(On,{base16:()=>Fc,base16upper:()=>Mc});var Fc=Y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Mc=Y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Cn={};ht(Cn,{base2:()=>Hc});var Hc=Y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var kn={};ht(kn,{base256emoji:()=>Gc});var Us=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}"),Kc=Us.reduce((r,t,e)=>(r[e]=t,r),[]),qc=Us.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function zc(r){return r.reduce((t,e)=>(t+=Kc[e],t),"")}function Vc(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=qc[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Gc=he({prefix:"\u{1F680}",name:"base256emoji",encode:zc,decode:Vc});var Fn={};ht(Fn,{base64:()=>Zc,base64pad:()=>jc,base64url:()=>$c,base64urlpad:()=>Xc});var Zc=Y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),jc=Y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),$c=Y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Xc=Y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Mn={};ht(Mn,{base8:()=>Yc});var Yc=Y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Hn={};ht(Hn,{identity:()=>Wc});var Wc=he({prefix:"\0",name:"identity",encode:r=>Mo(r),decode:r=>Fo(r)});var xd=new TextEncoder,bd=new TextDecoder;var zn={};ht(zn,{sha256:()=>qe,sha512:()=>tu});function qn({name:r,code:t,encode:e}){return new Kn(r,t,e)}var Kn=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?ee(this.code,e):e.then(n=>ee(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Ns(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var qe=qn({name:"sha2-256",code:18,encode:Ns("SHA-256")}),tu=qn({name:"sha2-512",code:19,encode:Ns("SHA-512")});var ze={...Hn,...Cn,...Mn,...Pn,...On,...Jr,...tn,...Qr,...Fn,...kn},Ud={...zn,...nn};function Os(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Ps=Os("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Vn=Os("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=at(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),eu={utf8:Ps,"utf-8":Ps,hex:ze.base16,latin1:Vn,ascii:Vn,binary:Vn,...ze},br=eu;function Qt(r,t="utf8"){let e=br[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function Gn(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return at(i);o+i>t&&(n=at(t),o=0);let f=n.subarray(o,o+=i);return o&7&&(o=(o|7)+1),f}}var fe=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Zn(){}var $n=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},ru=Gn();function nu(r){return globalThis.Buffer!=null?at(r):ru(r)}var Ge=class{len;head;tail;states;constructor(){this.len=0,this.head=new fe(Zn,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new fe(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Xn((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(wr,10,gt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=gt.fromBigInt(t);return this._push(wr,e.length(),e)}uint64Number(t){return this._push(Ln,rt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=gt.fromBigInt(t).zzEncode();return this._push(wr,e.length(),e)}sint64Number(t){let e=gt.fromNumber(t).zzEncode();return this._push(wr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(jn,1,t?1:0)}fixed32(t){return this._push(Ve,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=gt.fromBigInt(t);return this._push(Ve,4,e.lo)._push(Ve,4,e.hi)}fixed64Number(t){let e=gt.fromNumber(t);return this._push(Ve,4,e.lo)._push(Ve,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(As,4,t)}double(t){return this._push(Is,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(jn,1,0):this.uint32(e)._push(su,e,t)}string(t){let e=Ts(t);return e!==0?this.uint32(e)._push(Un,e,t):this._push(jn,1,0)}fork(){return this.states=new $n(this),this.head=this.tail=new fe(Zn,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 fe(Zn,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=nu(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function jn(r,t,e){t[e]=r&255}function ou(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Xn=class extends fe{next;constructor(t,e){super(ou,t,e),this.next=void 0}};function wr(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function Ve(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function su(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Ge.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(iu,t,r),this},Ge.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(au,t,r),this});function iu(r,t,e){t.set(r,e)}function au(r,t,e){r.length<40?Un(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(Qt(r),e)}function Yn(){return new Ge}function kt(r,t){let e=Yn();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var ve;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(ve||(ve={}));function Er(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Ae(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let f=t(s);i.int32(f)},n=function(s){let i=s.int32();return t(i)};return Er("enum",ve.VARINT,e,n)}function Ft(r,t){return Er("message",ve.LENGTH_DELIMITED,r,t)}var vr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var xt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1"})(xt||(xt={}));var Wn;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1"})(Wn||(Wn={}));(function(r){r.codec=()=>Ae(Wn)})(xt||(xt={}));var Ze;(function(r){let t;r.codec=()=>(t==null&&(t=Ft((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),xt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let f=e.uint32();switch(f>>>3){case 1:{s.Type=xt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(f&7);break}}}return s})),t),r.encode=e=>kt(e,r.codec()),r.decode=(e,n)=>Ct(e,r.codec(),n)})(Ze||(Ze={}));var Qn;(function(r){let t;r.codec=()=>(t==null&&(t=Ft((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),xt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let f=e.uint32();switch(f>>>3){case 1:{s.Type=xt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(f&7);break}}}return s})),t),r.encode=e=>kt(e,r.codec()),r.decode=(e,n)=>Ct(e,r.codec(),n)})(Qn||(Qn={}));function nt(r,t="utf8"){let e=br[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var je=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}};var uu=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Jt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),te=new Uint32Array(64),Jn=class extends we{constructor(){super(64,32,8,!1),this.A=Jt[0]|0,this.B=Jt[1]|0,this.C=Jt[2]|0,this.D=Jt[3]|0,this.E=Jt[4]|0,this.F=Jt[5]|0,this.G=Jt[6]|0,this.H=Jt[7]|0}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:f,H:u}=this;return[t,e,n,o,s,i,f,u]}set(t,e,n,o,s,i,f,u){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=f|0,this.H=u|0}process(t,e){for(let c=0;c<16;c++,e+=4)te[c]=t.getUint32(e,!1);for(let c=16;c<64;c++){let d=te[c-15],g=te[c-2],p=wt(d,7)^wt(d,18)^d>>>3,m=wt(g,17)^wt(g,19)^g>>>10;te[c]=m+te[c-7]+p+te[c-16]|0}let{A:n,B:o,C:s,D:i,E:f,F:u,G:a,H:l}=this;for(let c=0;c<64;c++){let d=wt(f,6)^wt(f,11)^wt(f,25),g=l+d+rs(f,u,a)+uu[c]+te[c]|0,m=(wt(n,2)^wt(n,13)^wt(n,22))+ns(n,o,s)|0;l=a,a=u,u=f,f=i+g|0,i=s,s=o,o=n,n=g+m|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,f=f+this.E|0,u=u+this.F|0,a=a+this.G|0,l=l+this.H|0,this.set(n,o,s,i,f,u,a,l)}roundClean(){te.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Cs=nr(()=>new Jn);var Ar=class extends be{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Jo(t);let n=Fe(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),s.fill(0)}update(t){return xe(this),this.iHash.update(t),this}digestInto(t){xe(this),ye(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:f}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=f,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},to=(r,t,e)=>new Ar(r,t).update(e).digest();to.create=(r,t)=>new Ar(r,t);function ks(r){r.lowS!==void 0&&Et("lowS",r.lowS),r.prehash!==void 0&&Et("prehash",r.prehash)}function fu(r){let t=Ke(r);It(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:o}=t;if(e){if(!n.eql(o,n.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:lu,hexToBytes:du}=cr,Mt={Err:class extends Error{constructor(t=""){super(t)}},_tlv:{encode:(r,t)=>{let{Err:e}=Mt;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=oe(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?oe(o.length/2|128):"";return oe(r)+s+o+t},decode(r,t){let{Err:e}=Mt,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let u=o&127;if(!u)throw new e("tlv.decode(long): indefinite length not supported");if(u>4)throw new e("tlv.decode(long): byte length is too big");let a=t.subarray(n,n+u);if(a.length!==u)throw new e("tlv.decode: length bytes not complete");if(a[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let l of a)i=i<<8|l;if(n+=u,i<128)throw new e("tlv.decode(long): not minimal encoding")}let f=t.subarray(n,n+i);if(f.length!==i)throw new e("tlv.decode: wrong value length");return{v:f,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=Mt;if(r<Ht)throw new t("integer: negative integers are not allowed");let e=oe(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=Mt;if(r[0]&128)throw new t("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return lu(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Mt,o=typeof r=="string"?du(r):r;Ee(o);let{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:f,l:u}=n.decode(2,s),{v:a,l}=n.decode(2,u);if(l.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(f),s:e.decode(a)}},hexFromSig(r){let{_tlv:t,_int:e}=Mt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},Ht=BigInt(0),ot=BigInt(1),wh=BigInt(2),Fs=BigInt(3),Eh=BigInt(4);function hu(r){let t=fu(r),{Fp:e}=t,n=Xt(t.n,t.nBitLength),o=t.toBytes||((m,h,w)=>{let v=h.toAffine();return Nt(Uint8Array.from([4]),e.toBytes(v.x),e.toBytes(v.y))}),s=t.fromBytes||(m=>{let h=m.subarray(1),w=e.fromBytes(h.subarray(0,e.BYTES)),v=e.fromBytes(h.subarray(e.BYTES,2*e.BYTES));return{x:w,y:v}});function i(m){let{a:h,b:w}=t,v=e.sqr(m),x=e.mul(v,m);return e.add(e.add(x,e.mul(m,h)),w)}if(!e.eql(e.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function f(m){return Me(m,ot,t.n)}function u(m){let{allowedPrivateKeyLengths:h,nByteLength:w,wrapPrivateKey:v,n:x}=t;if(h&&typeof m!="bigint"){if(Zt(m)&&(m=Ut(m)),typeof m!="string"||!h.includes(m.length))throw new Error("invalid private key");m=m.padStart(w*2,"0")}let I;try{I=typeof m=="bigint"?m:_t(X("private key",m,w))}catch{throw new Error("invalid private key, expected hex or "+w+" bytes, got "+typeof m)}return v&&(I=V(I,x)),pt("private key",I,ot,x),I}function a(m){if(!(m instanceof d))throw new Error("ProjectivePoint expected")}let l=ae((m,h)=>{let{px:w,py:v,pz:x}=m;if(e.eql(x,e.ONE))return{x:w,y:v};let I=m.is0();h==null&&(h=I?e.ONE:e.inv(x));let D=e.mul(w,h),U=e.mul(v,h),B=e.mul(x,h);if(I)return{x:e.ZERO,y:e.ZERO};if(!e.eql(B,e.ONE))throw new Error("invZ was invalid");return{x:D,y:U}}),c=ae(m=>{if(m.is0()){if(t.allowInfinityPoint&&!e.is0(m.py))return;throw new Error("bad point: ZERO")}let{x:h,y:w}=m.toAffine();if(!e.isValid(h)||!e.isValid(w))throw new Error("bad point: x or y not FE");let v=e.sqr(w),x=i(h);if(!e.eql(v,x))throw new Error("bad point: equation left != right");if(!m.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class d{constructor(h,w,v){if(this.px=h,this.py=w,this.pz=v,h==null||!e.isValid(h))throw new Error("x required");if(w==null||!e.isValid(w))throw new Error("y required");if(v==null||!e.isValid(v))throw new Error("z required");Object.freeze(this)}static fromAffine(h){let{x:w,y:v}=h||{};if(!h||!e.isValid(w)||!e.isValid(v))throw new Error("invalid affine point");if(h instanceof d)throw new Error("projective point not allowed");let x=I=>e.eql(I,e.ZERO);return x(w)&&x(v)?d.ZERO:new d(w,v,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let w=e.invertBatch(h.map(v=>v.pz));return h.map((v,x)=>v.toAffine(w[x])).map(d.fromAffine)}static fromHex(h){let w=d.fromAffine(s(X("pointHex",h)));return w.assertValidity(),w}static fromPrivateKey(h){return d.BASE.multiply(u(h))}static msm(h,w){return dr(d,n,h,w)}_setWindowSize(h){p.setWindowSize(this,h)}assertValidity(){c(this)}hasEvenY(){let{y:h}=this.toAffine();if(e.isOdd)return!e.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){a(h);let{px:w,py:v,pz:x}=this,{px:I,py:D,pz:U}=h,B=e.eql(e.mul(w,U),e.mul(I,x)),R=e.eql(e.mul(v,U),e.mul(D,x));return B&&R}negate(){return new d(this.px,e.neg(this.py),this.pz)}double(){let{a:h,b:w}=t,v=e.mul(w,Fs),{px:x,py:I,pz:D}=this,U=e.ZERO,B=e.ZERO,R=e.ZERO,L=e.mul(x,x),Z=e.mul(I,I),H=e.mul(D,D),k=e.mul(x,I);return k=e.add(k,k),R=e.mul(x,D),R=e.add(R,R),U=e.mul(h,R),B=e.mul(v,H),B=e.add(U,B),U=e.sub(Z,B),B=e.add(Z,B),B=e.mul(U,B),U=e.mul(k,U),R=e.mul(v,R),H=e.mul(h,H),k=e.sub(L,H),k=e.mul(h,k),k=e.add(k,R),R=e.add(L,L),L=e.add(R,L),L=e.add(L,H),L=e.mul(L,k),B=e.add(B,L),H=e.mul(I,D),H=e.add(H,H),L=e.mul(H,k),U=e.sub(U,L),R=e.mul(H,Z),R=e.add(R,R),R=e.add(R,R),new d(U,B,R)}add(h){a(h);let{px:w,py:v,pz:x}=this,{px:I,py:D,pz:U}=h,B=e.ZERO,R=e.ZERO,L=e.ZERO,Z=t.a,H=e.mul(t.b,Fs),k=e.mul(w,I),Q=e.mul(v,D),A=e.mul(x,U),T=e.add(w,v),b=e.add(I,D);T=e.mul(T,b),b=e.add(k,Q),T=e.sub(T,b),b=e.add(w,x);let y=e.add(I,U);return b=e.mul(b,y),y=e.add(k,A),b=e.sub(b,y),y=e.add(v,x),B=e.add(D,U),y=e.mul(y,B),B=e.add(Q,A),y=e.sub(y,B),L=e.mul(Z,b),B=e.mul(H,A),L=e.add(B,L),B=e.sub(Q,L),L=e.add(Q,L),R=e.mul(B,L),Q=e.add(k,k),Q=e.add(Q,k),A=e.mul(Z,A),b=e.mul(H,b),Q=e.add(Q,A),A=e.sub(k,A),A=e.mul(Z,A),b=e.add(b,A),k=e.mul(Q,b),R=e.add(R,k),k=e.mul(y,b),B=e.mul(T,B),B=e.sub(B,k),k=e.mul(T,Q),L=e.mul(y,L),L=e.add(L,k),new d(B,R,L)}subtract(h){return this.add(h.negate())}is0(){return this.equals(d.ZERO)}wNAF(h){return p.wNAFCached(this,h,d.normalizeZ)}multiplyUnsafe(h){let{endo:w,n:v}=t;pt("scalar",h,Ht,v);let x=d.ZERO;if(h===Ht)return x;if(this.is0()||h===ot)return this;if(!w||p.hasPrecomputes(this))return p.wNAFCachedUnsafe(this,h,d.normalizeZ);let{k1neg:I,k1:D,k2neg:U,k2:B}=w.splitScalar(h),R=x,L=x,Z=this;for(;D>Ht||B>Ht;)D&ot&&(R=R.add(Z)),B&ot&&(L=L.add(Z)),Z=Z.double(),D>>=ot,B>>=ot;return I&&(R=R.negate()),U&&(L=L.negate()),L=new d(e.mul(L.px,w.beta),L.py,L.pz),R.add(L)}multiply(h){let{endo:w,n:v}=t;pt("scalar",h,ot,v);let x,I;if(w){let{k1neg:D,k1:U,k2neg:B,k2:R}=w.splitScalar(h),{p:L,f:Z}=this.wNAF(U),{p:H,f:k}=this.wNAF(R);L=p.constTimeNegate(D,L),H=p.constTimeNegate(B,H),H=new d(e.mul(H.px,w.beta),H.py,H.pz),x=L.add(H),I=Z.add(k)}else{let{p:D,f:U}=this.wNAF(h);x=D,I=U}return d.normalizeZ([x,I])[0]}multiplyAndAddUnsafe(h,w,v){let x=d.BASE,I=(U,B)=>B===Ht||B===ot||!U.equals(x)?U.multiplyUnsafe(B):U.multiply(B),D=I(this,w).add(I(h,v));return D.is0()?void 0:D}toAffine(h){return l(this,h)}isTorsionFree(){let{h,isTorsionFree:w}=t;if(h===ot)return!0;if(w)return w(d,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:w}=t;return h===ot?this:w?w(d,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return Et("isCompressed",h),this.assertValidity(),o(d,this,h)}toHex(h=!0){return Et("isCompressed",h),Ut(this.toRawBytes(h))}}d.BASE=new d(t.Gx,t.Gy,e.ONE),d.ZERO=new d(e.ZERO,e.ONE,e.ZERO);let g=t.nBitLength,p=lr(d,t.endo?Math.ceil(g/2):g);return{CURVE:t,ProjectivePoint:d,normPrivateKeyToScalar:u,weierstrassEquation:i,isWithinCurveOrder:f}}function pu(r){let t=Ke(r);return It(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Ms(r){let t=pu(r),{Fp:e,n}=t,o=e.BYTES+1,s=2*e.BYTES+1;function i(A){return V(A,n)}function f(A){return ur(A,n)}let{ProjectivePoint:u,normPrivateKeyToScalar:a,weierstrassEquation:l,isWithinCurveOrder:c}=hu({...t,toBytes(A,T,b){let y=T.toAffine(),E=e.toBytes(y.x),S=Nt;return Et("isCompressed",b),b?S(Uint8Array.from([T.hasEvenY()?2:3]),E):S(Uint8Array.from([4]),E,e.toBytes(y.y))},fromBytes(A){let T=A.length,b=A[0],y=A.subarray(1);if(T===o&&(b===2||b===3)){let E=_t(y);if(!Me(E,ot,e.ORDER))throw new Error("Point is not on curve");let S=l(E),_;try{_=e.sqrt(S)}catch(F){let P=F instanceof Error?": "+F.message:"";throw new Error("Point is not on curve"+P)}let N=(_&ot)===ot;return(b&1)===1!==N&&(_=e.neg(_)),{x:E,y:_}}else if(T===s&&b===4){let E=e.fromBytes(y.subarray(0,e.BYTES)),S=e.fromBytes(y.subarray(e.BYTES,2*e.BYTES));return{x:E,y:S}}else{let E=o,S=s;throw new Error("invalid Point, expected length of "+E+", or uncompressed "+S+", got "+T)}}}),d=A=>Ut($t(A,t.nByteLength));function g(A){let T=n>>ot;return A>T}function p(A){return g(A)?i(-A):A}let m=(A,T,b)=>_t(A.slice(T,b));class h{constructor(T,b,y){this.r=T,this.s=b,this.recovery=y,this.assertValidity()}static fromCompact(T){let b=t.nByteLength;return T=X("compactSignature",T,b*2),new h(m(T,0,b),m(T,b,2*b))}static fromDER(T){let{r:b,s:y}=Mt.toSig(X("DER",T));return new h(b,y)}assertValidity(){pt("r",this.r,ot,n),pt("s",this.s,ot,n)}addRecoveryBit(T){return new h(this.r,this.s,T)}recoverPublicKey(T){let{r:b,s:y,recovery:E}=this,S=U(X("msgHash",T));if(E==null||![0,1,2,3].includes(E))throw new Error("recovery id invalid");let _=E===2||E===3?b+t.n:b;if(_>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let N=E&1?"03":"02",C=u.fromHex(N+d(_)),F=f(_),P=i(-S*F),q=i(y*F),G=u.BASE.multiplyAndAddUnsafe(C,P,q);if(!G)throw new Error("point at infinify");return G.assertValidity(),G}hasHighS(){return g(this.s)}normalizeS(){return this.hasHighS()?new h(this.r,i(-this.s),this.recovery):this}toDERRawBytes(){return se(this.toDERHex())}toDERHex(){return Mt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return se(this.toCompactHex())}toCompactHex(){return d(this.r)+d(this.s)}}let w={isValidPrivateKey(A){try{return a(A),!0}catch{return!1}},normPrivateKeyToScalar:a,randomPrivateKey:()=>{let A=gn(t.n);return ds(t.randomBytes(A),t.n)},precompute(A=8,T=u.BASE){return T._setWindowSize(A),T.multiply(BigInt(3)),T}};function v(A,T=!0){return u.fromPrivateKey(A).toRawBytes(T)}function x(A){let T=Zt(A),b=typeof A=="string",y=(T||b)&&A.length;return T?y===o||y===s:b?y===2*o||y===2*s:A instanceof u}function I(A,T,b=!0){if(x(A))throw new Error("first arg must be private key");if(!x(T))throw new Error("second arg must be public key");return u.fromHex(T).multiply(a(A)).toRawBytes(b)}let D=t.bits2int||function(A){if(A.length>8192)throw new Error("input is too large");let T=_t(A),b=A.length*8-t.nBitLength;return b>0?T>>BigInt(b):T},U=t.bits2int_modN||function(A){return i(D(A))},B=He(t.nBitLength);function R(A){return pt("num < 2^"+t.nBitLength,A,Ht,B),$t(A,t.nByteLength)}function L(A,T,b=Z){if(["recovered","canonical"].some(et=>et in b))throw new Error("sign() legacy options not supported");let{hash:y,randomBytes:E}=t,{lowS:S,prehash:_,extraEntropy:N}=b;S==null&&(S=!0),A=X("msgHash",A),ks(b),_&&(A=X("prehashed msgHash",y(A)));let C=U(A),F=a(T),P=[R(F),R(C)];if(N!=null&&N!==!1){let et=N===!0?E(e.BYTES):N;P.push(X("extraEntropy",et))}let q=Nt(...P),G=C;function tt(et){let st=D(et);if(!c(st))return;let it=f(st),dt=u.BASE.multiply(st).toAffine(),ft=i(dt.x);if(ft===Ht)return;let St=i(it*i(G+ft*F));if(St===Ht)return;let Bt=(dt.x===ft?0:2)|Number(dt.y&ot),De=St;return S&&g(St)&&(De=p(St),Bt^=1),new h(ft,De,Bt)}return{seed:q,k2sig:tt}}let Z={lowS:t.lowS,prehash:!1},H={lowS:t.lowS,prehash:!1};function k(A,T,b=Z){let{seed:y,k2sig:E}=L(A,T,b),S=t;return dn(S.hash.outputLen,S.nByteLength,S.hmac)(y,E)}u.BASE._setWindowSize(8);function Q(A,T,b,y=H){let E=A;T=X("msgHash",T),b=X("publicKey",b);let{lowS:S,prehash:_,format:N}=y;if(ks(y),"strict"in y)throw new Error("options.strict was renamed to lowS");if(N!==void 0&&N!=="compact"&&N!=="der")throw new Error("format must be compact or der");let C=typeof E=="string"||Zt(E),F=!C&&!N&&typeof E=="object"&&E!==null&&typeof E.r=="bigint"&&typeof E.s=="bigint";if(!C&&!F)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let P,q;try{if(F&&(P=new h(E.r,E.s)),C){try{N!=="compact"&&(P=h.fromDER(E))}catch(Bt){if(!(Bt instanceof Mt.Err))throw Bt}!P&&N!=="der"&&(P=h.fromCompact(E))}q=u.fromHex(b)}catch{return!1}if(!P||S&&P.hasHighS())return!1;_&&(T=t.hash(T));let{r:G,s:tt}=P,et=U(T),st=f(tt),it=i(et*st),dt=i(G*st),ft=u.BASE.multiplyAndAddUnsafe(q,it,dt)?.toAffine();return ft?i(ft.x)===G:!1}return{CURVE:t,getPublicKey:v,getSharedSecret:I,sign:k,verify:Q,ProjectivePoint:u,Signature:h,utils:w}}function mu(r){return{hash:r,hmac:(t,...e)=>to(r,t,on(...e)),randomBytes:or}}function Hs(r,t){let e=n=>Ms({...r,...mu(n)});return Object.freeze({...e(t),create:e})}var zs=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Ks=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),gu=BigInt(1),eo=BigInt(2),qs=(r,t)=>(r+t/eo)/t;function yu(r){let t=zs,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),f=BigInt(44),u=BigInt(88),a=r*r*r%t,l=a*a*r%t,c=$(l,e,t)*l%t,d=$(c,e,t)*l%t,g=$(d,eo,t)*a%t,p=$(g,o,t)*g%t,m=$(p,s,t)*p%t,h=$(m,f,t)*m%t,w=$(h,u,t)*h%t,v=$(w,f,t)*m%t,x=$(v,e,t)*l%t,I=$(x,i,t)*p%t,D=$(I,n,t)*a%t,U=$(D,eo,t);if(!ro.eql(ro.sqr(U),r))throw new Error("Cannot find square root");return U}var ro=Xt(zs,void 0,void 0,{sqrt:yu}),le=Hs({a:BigInt(0),b:BigInt(7),Fp:ro,n:Ks,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Ks,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-gu*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),f=qs(s*r,t),u=qs(-n*r,t),a=V(r-f*e-u*o,t),l=V(-f*n-u*s,t),c=a>i,d=l>i;if(c&&(a=t-a),d&&(l=t-l),a>i||l>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:c,k1:a,k2neg:d,k2:l}}}},Cs),Dh=BigInt(0);var Uh=le.ProjectivePoint;function yt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=at(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}function Vs(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Gs(r,t,e){let n=qe.digest(e instanceof Uint8Array?e:e.subarray());if(Vs(n))return n.then(({digest:o})=>le.verify(t,o,r)).catch(o=>{throw new je(String(o))});try{return le.verify(t,n.digest,r)}catch(o){throw new je(String(o))}}var Sr=class{type="secp256k1";raw;_key;constructor(t){this._key=js(t),this.raw=Zs(this._key)}toMultihash(){return Rt.digest(gr(this))}toCID(){return lt.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}verify(t,e){return Gs(this._key,e,t)}};function $s(r){return new Sr(r)}function Zs(r){return le.ProjectivePoint.fromHex(r).toRawBytes(!0)}function js(r){try{return le.ProjectivePoint.fromHex(r),r}catch(t){throw new Je(String(t))}}function Xs(r){let{Type:t,Data:e}=Ze.decode(r.digest),n=e??new Uint8Array;switch(t){case xt.Ed25519:return vs(n);case xt.secp256k1:return $s(n);default:throw new Ne}}function gr(r){return Ze.encode({Type:xt[r.type],Data:r.raw})}var Ys=Symbol.for("nodejs.util.inspect.custom"),xu=114,$e=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Zr]=!0;toString(){return this.string==null&&(this.string=W.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return lt.createV1(xu,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return bt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return bt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Ys](){return`PeerId(${this.toString()})`}},Ir=class extends $e{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Br=class extends $e{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Lr=class extends $e{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},bu=2336,Tr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Rt.digest(Qt(this.url))}[Ys](){return`PeerId(${this.url})`}[Zr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return lt.createV1(bu,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=nt(t)),t.toString()===this.toString())}};function Ws(r){if(Eu(r))return new Ir({multihash:r});if(wu(r))try{let t=Xs(r);if(t.type==="Ed25519")return new Br({multihash:r,publicKey:t});if(t.type==="secp256k1")return new Lr({multihash:r,publicKey:t})}catch{let e=nt(r.digest);return new Tr(new URL(e))}throw new tr("Supplied PeerID Multihash is invalid")}function wu(r){return r.code===Rt.code}function Eu(r){return r.code===qe.code}var Rr=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let s=0,i=0,f=this.peekChar();if(f===void 0)return;let u=f==="0",a=2**(8*o)-1;for(;;){let l=this.readAtomically(()=>{let c=this.readChar();if(c===void 0)return;let d=Number.parseInt(c,t);if(!Number.isNaN(d))return d});if(l===void 0)break;if(s*=t,s+=l,s>a||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&u&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2],e[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];e[o]=s>>8,e[o+1]=s&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[f]=t(s.subarray(0,i));return e.set(s.subarray(0,f),16-f),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Qs=45,vu=15,Se=new Rr;function no(r){if(!(r.length>vu))return Se.new(r).parseWith(()=>Se.readIPv4Addr())}function oo(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Qs))return Se.new(r).parseWith(()=>Se.readIPv6Addr())}function Dr(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Qs))return Se.new(r).parseWith(()=>Se.readIPAddr())}function Ur(r){return!!no(r)}function _r(r){return!!oo(r)}function Nr(r){return!!Dr(r)}var ti=ki(Js(),1),Au=["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"],Su=Au.map(r=>new ti.Netmask(r));function so(r){for(let t of Su)if(t.contains(r))return!0;return!1}function Iu(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function Bu(r){let t=r.split(":");if(t.length<2)return!1;let e=t[t.length-1].padStart(4,"0"),n=t[t.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(e.substring(0,2),16)}.${parseInt(e.substring(2),16)}`;return so(o)}function Lu(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function Tu(r){let t=r.split(":"),e=t[t.length-1];return so(e)}function Ru(r){return/^::$/.test(r)||/^::1$/.test(r)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(r)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(r)||/^ff([0-9a-fA-F]{2,2}):/i.test(r)}function io(r){return Ur(r)?so(r):Iu(r)?Bu(r):Lu(r)?Tu(r):_r(r)?Ru(r):void 0}var W0=parseInt("0xFFFF",16),Q0=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var ni=Ur,Pu=_r,ao=function(r){let t=0;if(r=r.toString().trim(),ni(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(Pu(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=ni(e[n]),i;s&&(i=ao(e[n]),e[n]=nt(i.slice(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,nt(i.slice(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let s=[n,1];for(n=9-e.length;n>0;n--)s.push("0");e.splice.apply(e,s)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){let s=parseInt(e[n],16);o[t++]=s>>8&255,o[t++]=s&255}return o}throw new Error("invalid ip address")},oi=function(r,t=0,e){t=~~t,e=e??r.length-t;let n=new DataView(r.buffer);if(e===4){let o=[];for(let s=0;s<e;s++)o.push(r[t+s]);return o.join(".")}if(e===16){let o=[];for(let s=0;s<e;s+=2)o.push(n.getUint16(t+s).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var Ie={},co={},Cu=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];Cu.forEach(r=>{let t=ku(...r);co[t.code]=t,Ie[t.name]=t});function ku(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function z(r){if(typeof r=="number"){if(co[r]!=null)return co[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Ie[r]!=null)return Ie[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Np=z("ip4"),Pp=z("ip6"),Op=z("ipcidr");function ho(r,t){switch(z(r).code){case 4:case 41:return Mu(t);case 42:return lo(t);case 6:case 273:case 33:case 132:return ai(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return lo(t);case 421:return zu(t);case 444:return ii(t);case 445:return ii(t);case 466:return qu(t);case 481:return globalThis.encodeURIComponent(lo(t));default:return nt(t,"base16")}}function po(r,t){switch(z(r).code){case 4:return si(t);case 41:return si(t);case 42:return fo(t);case 6:case 273:case 33:case 132:return mo(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return fo(t);case 421:return Hu(t);case 444:return Vu(t);case 445:return Gu(t);case 466:return Ku(t);case 481:return fo(globalThis.decodeURIComponent(t));default:return Qt(t,"base16")}}var uo=Object.values(ze).map(r=>r.decoder),Fu=function(){let r=uo[0].or(uo[1]);return uo.slice(2).forEach(t=>r=r.or(t)),r}();function si(r){if(!Nr(r))throw new Error("invalid ip address");return ao(r)}function Mu(r){let t=oi(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!Nr(t))throw new Error("invalid ip address");return t}function mo(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function ai(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function fo(r){let t=Qt(r),e=Uint8Array.from(Yt(t.length));return yt([e,t],e.length+t.length)}function lo(r){let t=Ot(r);if(r=r.slice(rt(t)),r.length!==t)throw new Error("inconsistent lengths");return nt(r)}function Hu(r){let t;r[0]==="Q"||r[0]==="1"?t=re(W.decode(`z${r}`)).bytes:t=lt.parse(r).multihash.bytes;let e=Uint8Array.from(Yt(t.length));return yt([e,t],e.length+t.length)}function Ku(r){let t=Fu.decode(r),e=Uint8Array.from(Yt(t.length));return yt([e,t],e.length+t.length)}function qu(r){let t=Ot(r),e=r.slice(rt(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+nt(e,"base64url")}function zu(r){let t=Ot(r),e=r.slice(rt(t));if(e.length!==t)throw new Error("inconsistent lengths");return nt(e,"base58btc")}function Vu(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=Tt.decode("b"+t[0]),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=mo(n);return yt([e,o],e.length+o.length)}function Gu(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=Tt.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=mo(n);return yt([e,o],e.length+o.length)}function ii(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=nt(t,"base32"),o=ai(e);return`${n}:${o}`}function ci(r){r=go(r);let t=[],e=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let s=0;s<o.length;s++){let i=o[s],f=z(i);if(f.size===0){t.push([f.code]),e.push([f.code]);continue}if(s++,s>=o.length)throw fi("invalid address: "+r);if(f.path===!0){n=go(o.slice(s).join("/")),t.push([f.code,po(f.code,n)]),e.push([f.code,n]);break}let u=po(f.code,o[s]);t.push([f.code,u]),e.push([f.code,ho(f.code,u)])}return{string:ui(e),bytes:xo(t),tuples:t,stringTuples:e,path:n}}function yo(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let s=Ot(r,o),i=rt(s),f=z(s),u=Zu(f,r.slice(o+i));if(u===0){t.push([s]),e.push([s]),o+=i;continue}let a=r.slice(o+i,o+i+u);if(o+=u+i,o>r.length)throw fi("Invalid address Uint8Array: "+nt(r,"base16"));t.push([s,a]);let l=ho(s,a);if(e.push([s,l]),f.path===!0){n=l;break}}return{bytes:Uint8Array.from(r),string:ui(e),tuples:t,stringTuples:e,path:n}}function ui(r){let t=[];return r.map(e=>{let n=z(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),go(t.join("/"))}function xo(r){return yt(r.map(t=>{let e=z(t[0]),n=Uint8Array.from(Yt(e.code));return t.length>1&&t[1]!=null&&(n=yt([n,t[1]])),n}))}function Zu(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=Ot(t instanceof Uint8Array?t:Uint8Array.from(t));return e+rt(e)}}function go(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}function fi(r){return new Error("Error parsing address: "+r)}var ju=Symbol.for("nodejs.util.inspect.custom"),wo=Symbol.for("@multiformats/js-multiaddr/multiaddr"),$u=[z("dns").code,z("dns4").code,z("dns6").code,z("dnsaddr").code],bo=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},Pr=class r{bytes;#e;#t;#r;#n;[wo]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=yo(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=ci(t)}else if(di(t))e=yo(t.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=e.bytes,this.#e=e.string,this.#t=e.tuples,this.#r=e.stringTuples,this.#n=e.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let t,e,n,o,s="",i=z("tcp"),f=z("udp"),u=z("ip4"),a=z("ip6"),l=z("dns6"),c=z("ip6zone");for(let[g,p]of this.stringTuples())g===c.code&&(s=`%${p??""}`),$u.includes(g)&&(e=i.name,o=443,n=`${p??""}${s}`,t=g===l.code?6:4),(g===i.code||g===f.code)&&(e=z(g).name,o=parseInt(p??"")),(g===u.code||g===a.code)&&(e=z(g).name,n=`${p??""}${s}`,t=g===a.code?6:4);if(t==null||e==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:t,host:n,transport:e,port:o}}protos(){return this.#t.map(([t])=>Object.assign({},z(t)))}protoCodes(){return this.#t.map(([t])=>t)}protoNames(){return this.#t.map(([t])=>z(t).name)}tuples(){return this.#t.map(([t,e])=>e==null?[t]:[t,e])}stringTuples(){return this.#r.map(([t,e])=>e==null?[t]:[t,e])}encapsulate(t){return t=new r(t),new r(this.toString()+t.toString())}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,o))}decapsulateCode(t){let e=this.tuples();for(let n=e.length-1;n>=0;n--)if(e[n][0]===t)return new r(xo(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===Ie.p2p.code&&t.push([n,o]),n===Ie["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?nt(W.decode(`z${n}`),"base58btc"):nt(lt.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return bt(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(s=>s.resolvable);if(e==null)return[this];let n=li.get(e.name);if(n==null)throw new bo(`no available resolver for ${e.name}`);return(await n(this,t)).map(s=>Be(s))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(t){let e=(t??this).protos();return!(e.length!==2||e[0].code!==4&&e[0].code!==41||e[1].code!==6&&e[1].code!==273)}[ju](){return`Multiaddr(${this.#e})`}};var li=new Map;function di(r){return!!r?.[wo]}function Be(r){return new Pr(r)}function Xu(r){return r[Symbol.asyncIterator]!=null}function Yu(r){if(Xu(r))return(async()=>{for await(let t of r)return t})();for(let t of r)return t}var Eo=Yu;var pi=Symbol.for("@achingbrain/uint8arraylist");function hi(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function Or(r){return!!r?.[pi]}var Le=class r{bufs;length;[pi]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(Or(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(Or(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=hi(this.bufs,t);return e.buf[e.index]}set(t,e){let n=hi(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(Or(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return yt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:yt(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],f=o,u=f+i.byteLength;if(o=u,t>=u)continue;let a=t>=f&&t<u,l=e>f&&e<=u;if(a&&l){if(t===f&&e===u){n.push(i);break}let c=t-f;n.push(i.subarray(c,c+(e-t)));break}if(a){if(t===0){n.push(i);continue}n.push(i.subarray(t-f));continue}if(l){if(e===u){n.push(i);break}n.push(i.subarray(0,e-f));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Or(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let 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 c=0;c<s;c++)i[c]=-1;for(let c=0;c<o;c++)i[n[c]]=c;let f=i,u=this.byteLength-n.byteLength,a=n.byteLength-1,l;for(let c=e;c<=u;c+=l){l=0;for(let d=a;d>=0;d--){let g=this.get(c+d);if(n[d]!==g){l=Math.max(1,d-f[g]);break}}if(l===0)return c}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=at(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=Pt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=Pt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=Pt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=at(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=Pt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=Pt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=Pt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=Pt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=Pt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!bt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};function Cr(r){return r[Symbol.asyncIterator]!=null}var kr=r=>{let t=rt(r),e=at(t);return Yt(r,e),kr.bytes=t,e};kr.bytes=0;function Ye(r,t){t=t??{};let e=t.lengthEncoder??kr;function*n(o){let s=e(o.byteLength);s instanceof Uint8Array?yield s:yield*s,o instanceof Uint8Array?yield o:yield*o}return Cr(r)?async function*(){for await(let o of r)yield*n(o)}():function*(){for(let o of r)yield*n(o)}()}Ye.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??kr;return new Le(e(r.byteLength),r)};var Fr=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Mr=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Hr=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},We=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};var Wu=8,Qu=1024*1024*4,de;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(de||(de={}));var vo=r=>{let t=Ot(r);return vo.bytes=rt(t),t};vo.bytes=0;function Te(r,t){let e=new Le,n=de.LENGTH,o=-1,s=t?.lengthDecoder??vo,i=t?.maxLengthLength??Wu,f=t?.maxDataLength??Qu;function*u(){for(;e.byteLength>0;){if(n===de.LENGTH)try{if(o=s(e),o<0)throw new Fr("Invalid message length");if(o>f)throw new Mr("Message length too long");let a=s.bytes;e.consume(a),t?.onLength!=null&&t.onLength(o),n=de.DATA}catch(a){if(a instanceof RangeError){if(e.byteLength>i)throw new Hr("Message length length too long");break}throw a}if(n===de.DATA){if(e.byteLength<o)break;let a=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(a),yield a,n=de.LENGTH}}}return Cr(r)?async function*(){for await(let a of r)e.append(a),yield*u();if(e.byteLength>0)throw new We("Unexpected end of input")}():function*(){for(let a of r)e.append(a),yield*u();if(e.byteLength>0)throw new We("Unexpected end of input")}()}Te.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:s,value:i}=await r.next(e);if(s===!0)return;i!=null&&(yield i)}catch(s){if(s.code==="ERR_UNDER_READ")return{done:!0,value:null};throw s}finally{e=1}}();return Te(n,{...t??{},onLength:s=>{e=s}})};function tf(r){let[t,e]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>t.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:t.next(),[e](){return this}}}var mi=tf;function ef(r){return r[Symbol.asyncIterator]!=null}function rf(r,t){let e=0;if(ef(r))return async function*(){for await(let u of r)yield t(u,e++)}();let n=mi(r),{value:o,done:s}=n.next();if(s===!0)return function*(){}();let i=t(o,e++);if(typeof i.then=="function")return async function*(){yield await i;for await(let u of n)yield t(u,e++)}();let f=t;return function*(){yield i;for(let u of n)yield f(u,e++)}()}var gi=rf;function Kt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Kr=globalThis.CustomEvent??Event;async function*Ao(r,t={}){let e=t.concurrency??1/0;e<1&&(e=1/0);let n=t.ordered==null?!1:t.ordered,o=new EventTarget,s=[],i=Kt(),f=Kt(),u=!1,a,l=!1;o.addEventListener("task-complete",()=>{f.resolve()}),Promise.resolve().then(async()=>{try{for await(let p of r){if(s.length===e&&(i=Kt(),await i.promise),l)break;let m={done:!1};s.push(m),p().then(h=>{m.done=!0,m.ok=!0,m.value=h,o.dispatchEvent(new Kr("task-complete"))},h=>{m.done=!0,m.err=h,o.dispatchEvent(new Kr("task-complete"))})}u=!0,o.dispatchEvent(new Kr("task-complete"))}catch(p){a=p,o.dispatchEvent(new Kr("task-complete"))}});function c(){return n?s[0]?.done:!!s.find(p=>p.done)}function*d(){for(;s.length>0&&s[0].done;){let p=s[0];if(s.shift(),p.ok)yield p.value;else throw l=!0,i.resolve(),p.err;i.resolve()}}function*g(){for(;c();)for(let p=0;p<s.length;p++)if(s[p].done){let m=s[p];if(s.splice(p,1),p--,m.ok)yield m.value;else throw l=!0,i.resolve(),m.err;i.resolve()}}for(;;){if(c()||(f=Kt(),await f.promise),a!=null)throw a;if(n?yield*d():yield*g(),u&&s.length===0)break}}var qr=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||t-1&t)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},Re=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new qr(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new qr(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var So=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function zr(r={}){return nf(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function nf(r,t){t=t??{};let e=t.onEnd,n=new Re,o,s,i,f=Kt(),u=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((h,w)=>{s=v=>{s=null,n.push(v);try{h(r(n))}catch(x){w(x)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{f.resolve(),f=Kt()})}},a=h=>s!=null?s(h):(n.push(h),o),l=h=>(n=new Re,s!=null?s({error:h}):(n.push({error:h}),o)),c=h=>{if(i)return o;if(t?.objectMode!==!0&&h?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return a({done:!1,value:h})},d=h=>i?o:(i=!0,h!=null?l(h):a({done:!0})),g=()=>(n=new Re,d(),{done:!0}),p=h=>(d(h),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:u,return:g,throw:p,push:c,end:d,get readableLength(){return n.size},onEmpty:async h=>{let w=h?.signal;if(w?.throwIfAborted(),n.isEmpty())return;let v,x;w!=null&&(v=new Promise((I,D)=>{x=()=>{D(new So)},w.addEventListener("abort",x)}));try{await Promise.race([f.promise,v])}finally{x!=null&&w!=null&&w?.removeEventListener("abort",x)}}},e==null)return o;let m=o;return o={[Symbol.asyncIterator](){return this},next(){return m.next()},throw(h){return m.throw(h),e!=null&&(e(h),e=void 0),{done:!0}},return(){return m.return(),e!=null&&(e(),e=void 0),{done:!0}},push:c,end(h){return m.end(h),e!=null&&(e(h),e=void 0),o},get readableLength(){return m.readableLength},onEmpty:h=>m.onEmpty(h)},o}function of(r){return r[Symbol.asyncIterator]!=null}function sf(...r){let t=[];for(let e of r)of(e)||t.push(e);return t.length===r.length?function*(){for(let e of t)yield*e}():async function*(){let e=zr({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let o of n)e.push(o)})),e.end()}catch(n){e.end(n)}}),yield*e}()}var yi=sf;function Bo(r,...t){if(r==null)throw new Error("Empty pipeline");if(Io(r)){let n=r;r=()=>n.source}else if(bi(r)||xi(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&Io(e[e.length-1])&&(e[e.length-1]=e[e.length-1].sink),e.length>2)for(let n=1;n<e.length-1;n++)Io(e[n])&&(e[n]=cf(e[n]));return af(...e)}var af=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},xi=r=>r?.[Symbol.asyncIterator]!=null,bi=r=>r?.[Symbol.iterator]!=null,Io=r=>r==null?!1:r.sink!=null&&r.source!=null,cf=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=zr({objectMode:!0});e.then(()=>{n.end()},i=>{n.end(i)});let o,s=r.source;if(xi(s))o=async function*(){yield*s,n.end()};else if(bi(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return yi(n,o())}return r.source};var wi="libp2p",Ei="autonat",vi="1.0.0";var M;(function(r){let t;(function(a){a.DIAL="DIAL",a.DIAL_RESPONSE="DIAL_RESPONSE"})(t=r.MessageType||(r.MessageType={}));let e;(function(a){a[a.DIAL=0]="DIAL",a[a.DIAL_RESPONSE=1]="DIAL_RESPONSE"})(e||(e={})),function(a){a.codec=()=>Ae(e)}(t=r.MessageType||(r.MessageType={}));let n;(function(a){a.OK="OK",a.E_DIAL_ERROR="E_DIAL_ERROR",a.E_DIAL_REFUSED="E_DIAL_REFUSED",a.E_BAD_REQUEST="E_BAD_REQUEST",a.E_INTERNAL_ERROR="E_INTERNAL_ERROR"})(n=r.ResponseStatus||(r.ResponseStatus={}));let o;(function(a){a[a.OK=0]="OK",a[a.E_DIAL_ERROR=100]="E_DIAL_ERROR",a[a.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",a[a.E_BAD_REQUEST=200]="E_BAD_REQUEST",a[a.E_INTERNAL_ERROR=300]="E_INTERNAL_ERROR"})(o||(o={})),function(a){a.codec=()=>Ae(o)}(n=r.ResponseStatus||(r.ResponseStatus={}));let s;(function(a){let l;a.codec=()=>(l==null&&(l=Ft((c,d,g={})=>{if(g.lengthDelimited!==!1&&d.fork(),c.id!=null&&(d.uint32(10),d.bytes(c.id)),c.addrs!=null)for(let p of c.addrs)d.uint32(18),d.bytes(p);g.lengthDelimited!==!1&&d.ldelim()},(c,d,g={})=>{let p={addrs:[]},m=d==null?c.len:c.pos+d;for(;c.pos<m;){let h=c.uint32();switch(h>>>3){case 1:{p.id=c.bytes();break}case 2:{if(g.limits?.addrs!=null&&p.addrs.length===g.limits.addrs)throw new vr('Decode error - map field "addrs" had too many elements');p.addrs.push(c.bytes());break}default:{c.skipType(h&7);break}}}return p})),l),a.encode=c=>kt(c,a.codec()),a.decode=(c,d)=>Ct(c,a.codec(),d)})(s=r.PeerInfo||(r.PeerInfo={}));let i;(function(a){let l;a.codec=()=>(l==null&&(l=Ft((c,d,g={})=>{g.lengthDelimited!==!1&&d.fork(),c.peer!=null&&(d.uint32(10),r.PeerInfo.codec().encode(c.peer,d)),g.lengthDelimited!==!1&&d.ldelim()},(c,d,g={})=>{let p={},m=d==null?c.len:c.pos+d;for(;c.pos<m;){let h=c.uint32();switch(h>>>3){case 1:{p.peer=r.PeerInfo.codec().decode(c,c.uint32(),{limits:g.limits?.peer});break}default:{c.skipType(h&7);break}}}return p})),l),a.encode=c=>kt(c,a.codec()),a.decode=(c,d)=>Ct(c,a.codec(),d)})(i=r.Dial||(r.Dial={}));let f;(function(a){let l;a.codec=()=>(l==null&&(l=Ft((c,d,g={})=>{g.lengthDelimited!==!1&&d.fork(),c.status!=null&&(d.uint32(8),r.ResponseStatus.codec().encode(c.status,d)),c.statusText!=null&&(d.uint32(18),d.string(c.statusText)),c.addr!=null&&(d.uint32(26),d.bytes(c.addr)),g.lengthDelimited!==!1&&d.ldelim()},(c,d,g={})=>{let p={},m=d==null?c.len:c.pos+d;for(;c.pos<m;){let h=c.uint32();switch(h>>>3){case 1:{p.status=r.ResponseStatus.codec().decode(c);break}case 2:{p.statusText=c.string();break}case 3:{p.addr=c.bytes();break}default:{c.skipType(h&7);break}}}return p})),l),a.encode=c=>kt(c,a.codec()),a.decode=(c,d)=>Ct(c,a.codec(),d)})(f=r.DialResponse||(r.DialResponse={}));let u;r.codec=()=>(u==null&&(u=Ft((a,l,c={})=>{c.lengthDelimited!==!1&&l.fork(),a.type!=null&&(l.uint32(8),r.MessageType.codec().encode(a.type,l)),a.dial!=null&&(l.uint32(18),r.Dial.codec().encode(a.dial,l)),a.dialResponse!=null&&(l.uint32(26),r.DialResponse.codec().encode(a.dialResponse,l)),c.lengthDelimited!==!1&&l.ldelim()},(a,l,c={})=>{let d={},g=l==null?a.len:a.pos+l;for(;a.pos<g;){let p=a.uint32();switch(p>>>3){case 1:{d.type=r.MessageType.codec().decode(a);break}case 2:{d.dial=r.Dial.codec().decode(a,a.uint32(),{limits:c.limits?.dial});break}case 3:{d.dialResponse=r.DialResponse.codec().decode(a,a.uint32(),{limits:c.limits?.dialResponse});break}default:{a.skipType(p&7);break}}}return d})),u),r.encode=a=>kt(a,r.codec()),r.decode=(a,l)=>Ct(a,r.codec(),l)})(M||(M={}));var Lo=4,Vr=class{components;startupDelay;refreshInterval;protocol;timeout;maxInboundStreams;maxOutboundStreams;verifyAddressTimeout;started;log;constructor(t,e){this.components=t,this.log=t.logger.forComponent("libp2p:autonat"),this.started=!1,this.protocol=`/${e.protocolPrefix??wi}/${Ei}/${vi}`,this.timeout=e.timeout??3e4,this.maxInboundStreams=e.maxInboundStreams??1,this.maxOutboundStreams=e.maxOutboundStreams??1,this.startupDelay=e.startupDelay??5e3,this.refreshInterval=e.refreshInterval??6e4,this._verifyExternalAddresses=this._verifyExternalAddresses.bind(this)}[Symbol.toStringTag]="@libp2p/autonat";[Co]=["@libp2p/autonat"];isStarted(){return this.started}async start(){this.started||(await this.components.registrar.handle(this.protocol,t=>{this.handleIncomingAutonatStream(t).catch(e=>{this.log.error("error handling incoming autonat stream",e)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.verifyAddressTimeout=setTimeout(this._verifyExternalAddresses,this.startupDelay),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.protocol),clearTimeout(this.verifyAddressTimeout),this.started=!1}async handleIncomingAutonatStream(t){let e=AbortSignal.timeout(this.timeout),n=()=>{t.stream.abort(new Ue)};e.addEventListener("abort",n,{once:!0}),jr(1/0,e);try{let o=this;await Bo(t.stream,s=>Te(s),async function*(s){let i=await Eo(s);if(i==null){o.log("no message received"),yield M.encode({type:M.MessageType.DIAL_RESPONSE,dialResponse:{status:M.ResponseStatus.E_BAD_REQUEST,statusText:"No message was sent"}});return}let f;try{f=M.decode(i)}catch(u){o.log.error("could not decode message",u),yield M.encode({type:M.MessageType.DIAL_RESPONSE,dialResponse:{status:M.ResponseStatus.E_BAD_REQUEST,statusText:"Could not decode message"}});return}yield M.encode(await o.handleAutonatMessage(f,t.connection,{signal:e}))},s=>Ye(s),t.stream)}catch(o){this.log.error("error handling incoming autonat stream",o)}finally{e.removeEventListener("abort",n)}}_verifyExternalAddresses(){this.verifyExternalAddresses().catch(t=>{this.log.error("error verifying external address",t)})}async handleAutonatMessage(t,e,n){let o=this.components.addressManager.getAddresses().map(c=>c.toOptions().host),s=t.dial;if(s==null)return this.log.error("dial was missing from message"),{type:M.MessageType.DIAL_RESPONSE,dialResponse:{status:M.ResponseStatus.E_BAD_REQUEST,statusText:"No Dial message found in message"}};let i,f=s.peer;if(f?.id==null)return this.log.error("PeerId missing from message"),{type:M.MessageType.DIAL_RESPONSE,dialResponse:{status:M.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}};try{let c=re(f.id);i=Ws(c)}catch(c){return this.log.error("invalid PeerId",c),{type:M.MessageType.DIAL_RESPONSE,dialResponse:{status:M.ResponseStatus.E_BAD_REQUEST,statusText:"bad peer id"}}}if(this.log("incoming request from %p",i),!e.remotePeer.equals(i))return this.log("target peer %p did not equal sending peer %p",i,e.remotePeer),{type:M.MessageType.DIAL_RESPONSE,dialResponse:{status:M.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}};let u=f.addrs.map(c=>Be(c)).filter(c=>{let d=c.toOptions().host===e.remoteAddr.toOptions().host;return this.log.trace("request to dial %a was sent from %a is same host %s",c,e.remoteAddr,d),d}).filter(c=>{let d=c.toOptions().host,g=!(io(d)??!1);return this.log.trace("host %s was public %s",d,g),g}).filter(c=>{let d=c.toOptions().host,g=!o.includes(d);return this.log.trace("host %s was not our host %s",d,g),g}).filter(c=>{let d=!!this.components.transportManager.dialTransportForMultiaddr(c);return this.log.trace("transport for %a is supported %s",c,d),d}).map(c=>(c.getPeerId()==null&&(c=c.encapsulate(`/p2p/${i.toString()}`)),c));if(u.length===0)return this.log("no valid multiaddrs for %p in message",i),{type:M.MessageType.DIAL_RESPONSE,dialResponse:{status:M.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}};this.log("dial multiaddrs %s for peer %p",u.map(c=>c.toString()).join(", "),i);let a="",l=u[0];for await(let c of u){let d;l=c;try{if(d=await this.components.connectionManager.openConnection(c,n),!d.remoteAddr.equals(c))throw this.log.error("tried to dial %a but dialed %a",c,d.remoteAddr),new Error("Unexpected remote address");return this.log("Success %p",i),{type:M.MessageType.DIAL_RESPONSE,dialResponse:{status:M.ResponseStatus.OK,addr:d.remoteAddr.decapsulateCode(z("p2p").code).bytes}}}catch(g){this.log("could not dial %p",i,g),a=g.message}finally{d!=null&&await d.close()}}return{type:M.MessageType.DIAL_RESPONSE,dialResponse:{status:M.ResponseStatus.E_DIAL_ERROR,statusText:a,addr:l.bytes}}}async verifyExternalAddresses(){if(clearTimeout(this.verifyAddressTimeout),!this.isStarted())return;let t=this.components.addressManager,e=t.getObservedAddrs().filter(s=>{let i=s.toOptions();return!(io(i.host)??!1)});if(e.length===0){this.log("no public addresses found, not requesting verification"),this.verifyAddressTimeout=setTimeout(this._verifyExternalAddresses,this.refreshInterval);return}let n=AbortSignal.timeout(this.timeout);jr(1/0,n);let o=this;try{this.log("verify multiaddrs %s",e.map(a=>a.toString()).join(", "));let s=M.encode({type:M.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toMultihash().bytes,addrs:e.map(a=>a.bytes)}}}),i={},f=[],u=async a=>{let l=()=>{};try{this.log("asking %p to verify multiaddr",a.id);let c=await o.components.connectionManager.openConnection(a.id,{signal:n}),d=await c.newStream(this.protocol,{signal:n});l=()=>{d.abort(new Ue)},n.addEventListener("abort",l,{once:!0});let g=await Bo([s],m=>Ye(m),d,m=>Te(m),async m=>Eo(m));if(g==null){this.log("no response received from %p",c.remotePeer);return}let p=M.decode(g);if(p.type!==M.MessageType.DIAL_RESPONSE||p.dialResponse==null){this.log("invalid autonat response from %p",c.remotePeer);return}if(p.dialResponse.status===M.ResponseStatus.OK){let m=c.remoteAddr.toOptions(),h;if(m.family===4)h=m.host.split(".")[0];else if(m.family===6)h=m.host.split(":")[0];else{this.log('remote address "%s" was not IP4 or IP6?',m.host);return}if(f.includes(h)){this.log("already have response from network segment %d - %s",h,m.host);return}f.push(h)}return p.dialResponse}catch(c){this.log.error("error asking remote to verify multiaddr",c)}finally{n.removeEventListener("abort",l)}};for await(let a of Ao(gi(this.components.randomWalk.walk({signal:n}),l=>async()=>u(l)),{concurrency:Lo}))try{if(a==null)continue;let l=a.addr==null?e[0]:Be(a.addr);if(this.log("autonat response for %a is %s",l,a.status),a.status===M.ResponseStatus.E_BAD_REQUEST||a.status===M.ResponseStatus.E_DIAL_REFUSED||a.addr==null&&e.length>1)continue;if(!e.some(d=>d.equals(l))){this.log("peer reported %a as %s but it was not in our observed address list",l,a.status);continue}let c=l.toString();if(i[c]==null&&(i[c]={success:0,failure:0}),a.status===M.ResponseStatus.OK?i[c].success++:a.status===M.ResponseStatus.E_DIAL_ERROR&&i[c].failure++,i[c].success===Lo){this.log("%a is externally dialable",l),t.confirmObservedAddr(l);return}if(i[c].failure===Lo){this.log("%a is not externally dialable",l),t.removeObservedAddr(l);return}}catch(l){this.log.error("could not verify external address",l)}}finally{this.verifyAddressTimeout=setTimeout(this._verifyExternalAddresses,this.refreshInterval)}}};function pf(r={}){return t=>new Vr(t,r)}return Fi(mf);})();
2
+ "use strict";var Libp2PAutonat=(()=>{var Ui=Object.create;var Qe=Object.defineProperty;var _i=Object.getOwnPropertyDescriptor;var Ni=Object.getOwnPropertyNames;var Pi=Object.getPrototypeOf,Oi=Object.prototype.hasOwnProperty;var Ci=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),ht=(r,t)=>{for(var e in t)Qe(r,e,{get:t[e],enumerable:!0})},Oo=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ni(t))!Oi.call(r,o)&&o!==e&&Qe(r,o,{get:()=>t[o],enumerable:!(n=_i(t,o))||n.enumerable});return r};var ki=(r,t,e)=>(e=r!=null?Ui(Pi(r)):{},Oo(t||!r||!r.__esModule?Qe(e,"default",{value:r,enumerable:!0}):e,r)),Fi=r=>Oo(Qe({},"__esModule",{value:!0}),r);var Js=Ci(Xe=>{(function(){var r,t,e,n,o,s,i,f;f=function(u){var a,l,c,d;return a=(u&255<<24)>>>24,l=(u&255<<16)>>>16,c=(u&65280)>>>8,d=u&255,[a,l,c,d].join(".")},i=function(u){var a,l,c,d,g,p;for(a=[],c=d=0;d<=3&&u.length!==0;c=++d){if(c>0){if(u[0]!==".")throw new Error("Invalid IP");u=u.substring(1)}p=t(u),g=p[0],l=p[1],u=u.substring(l),a.push(g)}if(u.length!==0)throw new Error("Invalid IP");switch(a.length){case 1:if(a[0]>4294967295)throw new Error("Invalid IP");return a[0]>>>0;case 2:if(a[0]>255||a[1]>16777215)throw new Error("Invalid IP");return(a[0]<<24|a[1])>>>0;case 3:if(a[0]>255||a[1]>255||a[2]>65535)throw new Error("Invalid IP");return(a[0]<<24|a[1]<<16|a[2])>>>0;case 4:if(a[0]>255||a[1]>255||a[2]>255||a[3]>255)throw new Error("Invalid IP");return(a[0]<<24|a[1]<<16|a[2]<<8|a[3])>>>0;default:throw new Error("Invalid IP")}},e=function(u){return u.charCodeAt(0)},n=e("0"),s=e("a"),o=e("A"),t=function(u){var a,l,c,d,g;for(d=0,a=10,l="9",c=0,u.length>1&&u[c]==="0"&&(u[c+1]==="x"||u[c+1]==="X"?(c+=2,a=16):"0"<=u[c+1]&&u[c+1]<="9"&&(c++,a=8,l="7")),g=c;c<u.length;){if("0"<=u[c]&&u[c]<=l)d=d*a+(e(u[c])-n)>>>0;else if(a===16)if("a"<=u[c]&&u[c]<="f")d=d*a+(10+e(u[c])-s)>>>0;else if("A"<=u[c]&&u[c]<="F")d=d*a+(10+e(u[c])-o)>>>0;else break;else break;if(d>4294967295)throw new Error("too large");c++}if(c===g)throw new Error("empty octet");return[d,c]},r=function(){function u(a,l){var c,d,g,p;if(typeof a!="string")throw new Error("Missing `net' parameter");if(l||(p=a.split("/",2),a=p[0],l=p[1]),l||(l=32),typeof l=="string"&&l.indexOf(".")>-1){try{this.maskLong=i(l)}catch(m){throw c=m,new Error("Invalid mask: "+l)}for(d=g=32;g>=0;d=--g)if(this.maskLong===4294967295<<32-d>>>0){this.bitmask=d;break}}else if(l||l===0)this.bitmask=parseInt(l,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(i(a)&this.maskLong)>>>0}catch(m){throw c=m,new Error("Invalid net address: "+a)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+l);this.size=Math.pow(2,32-this.bitmask),this.base=f(this.netLong),this.mask=f(this.maskLong),this.hostmask=f(~this.maskLong),this.first=this.bitmask<=30?f(this.netLong+1):this.base,this.last=this.bitmask<=30?f(this.netLong+this.size-2):f(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?f(this.netLong+this.size-1):void 0}return u.prototype.contains=function(a){return typeof a=="string"&&(a.indexOf("/")>0||a.split(".").length!==4)&&(a=new u(a)),a instanceof u?this.contains(a.base)&&this.contains(a.broadcast||a.last):(i(a)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},u.prototype.next=function(a){return a==null&&(a=1),new u(f(this.netLong+this.size*a),this.mask)},u.prototype.forEach=function(a){var l,c,d;for(d=i(this.first),c=i(this.last),l=0;d<=c;)a(f(d),d,l),l++,d++},u.prototype.toString=function(){return this.base+"/"+this.bitmask},u}(),Xe.ip2long=i,Xe.long2ip=f,Xe.Netmask=r}).call(Xe)});var mf={};ht(mf,{autoNAT:()=>pf});var Zr=Symbol.for("@libp2p/peer-id");var Ue=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var _e=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Je=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var tr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Ne=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var jr=(r,...t)=>{try{[...t]}catch{}};var Co=Symbol.for("@libp2p/service-capabilities"),wf=Symbol.for("@libp2p/service-dependencies");var Qr={};ht(Qr,{base58btc:()=>W,base58flickr:()=>Vi});var Vf=new Uint8Array(0);function ko(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Lt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function Fo(r){return new TextEncoder().encode(r)}function Mo(r){return new TextDecoder().decode(r)}function Mi(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var f=r.length,u=r.charAt(0),a=Math.log(f)/Math.log(256),l=Math.log(256)/Math.log(f);function c(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var m=0,h=0,w=0,v=p.length;w!==v&&p[w]===0;)w++,m++;for(var b=(v-w)*l+1>>>0,I=new Uint8Array(b);w!==v;){for(var D=p[w],U=0,B=b-1;(D!==0||U<h)&&B!==-1;B--,U++)D+=256*I[B]>>>0,I[B]=D%f>>>0,D=D/f>>>0;if(D!==0)throw new Error("Non-zero carry");h=U,w++}for(var R=b-h;R!==b&&I[R]===0;)R++;for(var L=u.repeat(m);R<b;++R)L+=r.charAt(I[R]);return L}function d(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var m=0;if(p[m]!==" "){for(var h=0,w=0;p[m]===u;)h++,m++;for(var v=(p.length-m)*a+1>>>0,b=new Uint8Array(v);p[m];){var I=e[p.charCodeAt(m)];if(I===255)return;for(var D=0,U=v-1;(I!==0||D<w)&&U!==-1;U--,D++)I+=f*b[U]>>>0,b[U]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");w=D,m++}if(p[m]!==" "){for(var B=v-w;B!==v&&b[B]===0;)B++;for(var R=new Uint8Array(h+(v-B)),L=h;B!==v;)R[L++]=b[B++];return R}}}function g(p){var m=d(p);if(m)return m;throw new Error(`Non-${t} character`)}return{encode:c,decodeUnsafe:d,decode:g}}var Hi=Mi,Ki=Hi,Ko=Ki;var $r=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Xr=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return qo(this,t)}},Yr=class{decoders;constructor(t){this.decoders=t}or(t){return qo(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function qo(r,t){return new Yr({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Wr=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new $r(t,e,n),this.decoder=new Xr(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function he({name:r,prefix:t,encode:e,decode:n}){return new Wr(r,t,e,n)}function zt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Ko(e,r);return he({prefix:t,name:r,encode:n,decode:s=>Lt(o(s))})}function qi(r,t,e,n){let o={};for(let l=0;l<t.length;++l)o[t[l]]=l;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*e/8|0),f=0,u=0,a=0;for(let l=0;l<s;++l){let c=o[r[l]];if(c===void 0)throw new SyntaxError(`Non-${n} character`);u=u<<e|c,f+=e,f>=8&&(f-=8,i[a++]=255&u>>f)}if(f>=e||255&u<<8-f)throw new SyntaxError("Unexpected end of data");return i}function zi(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,f=0;for(let u=0;u<r.length;++u)for(f=f<<8|r[u],i+=8;i>e;)i-=e,s+=t[o&f>>i];if(i!==0&&(s+=t[o&f<<e-i]),n)for(;s.length*e&7;)s+="=";return s}function Y({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return he({prefix:t,name:r,encode(o){return zi(o,n,e)},decode(o){return qi(o,n,e,r)}})}var W=zt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Vi=zt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Jr={};ht(Jr,{base32:()=>Tt,base32hex:()=>$i,base32hexpad:()=>Yi,base32hexpadupper:()=>Wi,base32hexupper:()=>Xi,base32pad:()=>Zi,base32padupper:()=>ji,base32upper:()=>Gi,base32z:()=>Qi});var Tt=Y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Gi=Y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Zi=Y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ji=Y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),$i=Y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Xi=Y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Yi=Y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Wi=Y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Qi=Y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var tn={};ht(tn,{base36:()=>Pe,base36upper:()=>Ji});var Pe=zt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ji=zt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ta=Go,zo=128,ea=127,ra=~ea,na=Math.pow(2,31);function Go(r,t,e){t=t||[],e=e||0;for(var n=e;r>=na;)t[e++]=r&255|zo,r/=128;for(;r&ra;)t[e++]=r&255|zo,r>>>=7;return t[e]=r|0,Go.bytes=e-n+1,t}var oa=en,sa=128,Vo=127;function en(r,n){var e=0,n=n||0,o=0,s=n,i,f=r.length;do{if(s>=f)throw en.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Vo)<<o:(i&Vo)*Math.pow(2,o),o+=7}while(i>=sa);return en.bytes=s-n,e}var ia=Math.pow(2,7),aa=Math.pow(2,14),ca=Math.pow(2,21),ua=Math.pow(2,28),fa=Math.pow(2,35),la=Math.pow(2,42),da=Math.pow(2,49),ha=Math.pow(2,56),pa=Math.pow(2,63),ma=function(r){return r<ia?1:r<aa?2:r<ca?3:r<ua?4:r<fa?5:r<la?6:r<da?7:r<ha?8:r<pa?9:10},ga={encode:ta,decode:oa,encodingLength:ma},ya=ga,Oe=ya;function Ce(r,t=0){return[Oe.decode(r,t),Oe.decode.bytes]}function pe(r,t,e=0){return Oe.encode(r,t,e),t}function me(r){return Oe.encodingLength(r)}function ee(r,t){let e=t.byteLength,n=me(r),o=n+me(e),s=new Uint8Array(o+e);return pe(r,s,0),pe(e,s,n),s.set(t,o),new ge(r,e,t,s)}function re(r){let t=Lt(r),[e,n]=Ce(t),[o,s]=Ce(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ge(e,o,i,t)}function Zo(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&ko(r.bytes,e.bytes)}}var ge=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function jo(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return xa(e,rn(r),t??W.encoder);default:return wa(e,rn(r),t??Tt.encoder)}}var $o=new WeakMap;function rn(r){let t=$o.get(r);if(t==null){let e=new Map;return $o.set(r,e),e}return t}var lt=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,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:t,multihash:e}=this;if(t!==ke)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Ea)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}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:t,digest:e}=this.multihash,n=ee(t,e);return r.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(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&Zo(t.multihash,n.multihash)}toString(t){return jo(this,t)}toJSON(){return{"/":jo(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??Xo(n,o,s.bytes))}else if(e[va]===!0){let{version:n,multihash:o,code:s}=e,i=re(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==ke)throw new Error(`Version 0 CID must use dag-pb (code: ${ke}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Xo(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,ke,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=Lt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new ge(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[c,d]=Ce(t.subarray(e));return e+=d,c},o=n(),s=ke;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,f=n(),u=n(),a=e+u,l=a-i;return{version:o,codec:s,multihashCode:f,digestSize:u,multihashSize:l,size:a}}static parse(t,e){let[n,o]=ba(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return rn(s).set(n,t),s}};function ba(r,t){switch(r[0]){case"Q":{let e=t??W;return[W.prefix,e.decode(`${W.prefix}${r}`)]}case W.prefix:{let e=t??W;return[W.prefix,e.decode(r)]}case Tt.prefix:{let e=t??Tt;return[Tt.prefix,e.decode(r)]}case Pe.prefix:{let e=t??Pe;return[Pe.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function xa(r,t,e){let{prefix:n}=e;if(n!==W.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function wa(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var ke=112,Ea=18;function Xo(r,t,e){let n=me(r),o=n+me(t),s=new Uint8Array(o+e.byteLength);return pe(r,s,0),pe(t,s,n),s.set(e,o),s}var va=Symbol.for("@ipld/js-cid/CID");var nn={};ht(nn,{identity:()=>Rt});var Yo=0,Aa="identity",Wo=Lt;function Sa(r){return ee(Yo,Wo(r))}var Rt={code:Yo,name:Aa,encode:Wo,digest:Sa};function xt(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Qo(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function Ia(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function ye(r,...t){if(!Ia(r))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(r.length))throw new Error("Uint8Array expected of length "+t+", got length="+r.length)}function Jo(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Qo(r.outputLen),Qo(r.blockLen)}function be(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function ts(r,t){ye(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}var ne=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var rr=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),wt=(r,t)=>r<<32-t|r>>>t;function es(r){if(typeof r!="string")throw new Error("utf8ToBytes expected string, got "+typeof r);return new Uint8Array(new TextEncoder().encode(r))}function Fe(r){return typeof r=="string"&&(r=es(r)),ye(r),r}function on(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];ye(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}var xe=class{clone(){return this._cloneInto()}};function nr(r){let t=n=>r().update(Fe(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function or(r=32){if(ne&&typeof ne.getRandomValues=="function")return ne.getRandomValues(new Uint8Array(r));if(ne&&typeof ne.randomBytes=="function")return ne.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}function Ba(r,t,e,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(t,e,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(e>>o&s),f=Number(e&s),u=n?4:0,a=n?0:4;r.setUint32(t+u,i,n),r.setUint32(t+a,f,n)}var rs=(r,t,e)=>r&t^~r&e,ns=(r,t,e)=>r&t^r&e^t&e,we=class extends xe{constructor(t,e,n,o){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=rr(this.buffer)}update(t){be(this);let{view:e,buffer:n,blockLen:o}=this;t=Fe(t);let s=t.length;for(let i=0;i<s;){let f=Math.min(o-this.pos,s-i);if(f===o){let u=rr(t);for(;o<=s-i;i+=o)this.process(u,i);continue}n.set(t.subarray(i,i+f),this.pos),this.pos+=f,i+=f,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){be(this),ts(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,this.buffer.subarray(i).fill(0),this.padOffset>o-i&&(this.process(n,0),i=0);for(let c=i;c<o;c++)e[c]=0;Ba(n,o-8,BigInt(this.length*8),s),this.process(n,0);let f=rr(t),u=this.outputLen;if(u%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let a=u/4,l=this.get();if(a>l.length)throw new Error("_sha2: outputLen bigger than state");for(let c=0;c<a;c++)f.setUint32(4*c,l[c],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:f}=this;return t.length=o,t.pos=f,t.finished=s,t.destroyed=i,o%e&&t.buffer.set(n),t}};var sr=BigInt(4294967295),sn=BigInt(32);function os(r,t=!1){return t?{h:Number(r&sr),l:Number(r>>sn&sr)}:{h:Number(r>>sn&sr)|0,l:Number(r&sr)|0}}function La(r,t=!1){let e=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let o=0;o<r.length;o++){let{h:s,l:i}=os(r[o],t);[e[o],n[o]]=[s,i]}return[e,n]}var Ta=(r,t)=>BigInt(r>>>0)<<sn|BigInt(t>>>0),Ra=(r,t,e)=>r>>>e,Da=(r,t,e)=>r<<32-e|t>>>e,Ua=(r,t,e)=>r>>>e|t<<32-e,_a=(r,t,e)=>r<<32-e|t>>>e,Na=(r,t,e)=>r<<64-e|t>>>e-32,Pa=(r,t,e)=>r>>>e-32|t<<64-e,Oa=(r,t)=>t,Ca=(r,t)=>r,ka=(r,t,e)=>r<<e|t>>>32-e,Fa=(r,t,e)=>t<<e|r>>>32-e,Ma=(r,t,e)=>t<<e-32|r>>>64-e,Ha=(r,t,e)=>r<<e-32|t>>>64-e;function Ka(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var qa=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),za=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Va=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Ga=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Za=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),ja=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var $a={fromBig:os,split:La,toBig:Ta,shrSH:Ra,shrSL:Da,rotrSH:Ua,rotrSL:_a,rotrBH:Na,rotrBL:Pa,rotr32H:Oa,rotr32L:Ca,rotlSH:ka,rotlSL:Fa,rotlBH:Ma,rotlBL:Ha,add:Ka,add3L:qa,add3H:za,add4L:Va,add4H:Ga,add5H:ja,add5L:Za},O=$a;var[Xa,Ya]=O.split(["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(r=>BigInt(r))),Gt=new Uint32Array(80),Zt=new Uint32Array(80),an=class extends we{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:f,Dl:u,Eh:a,El:l,Fh:c,Fl:d,Gh:g,Gl:p,Hh:m,Hl:h}=this;return[t,e,n,o,s,i,f,u,a,l,c,d,g,p,m,h]}set(t,e,n,o,s,i,f,u,a,l,c,d,g,p,m,h){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=f|0,this.Dl=u|0,this.Eh=a|0,this.El=l|0,this.Fh=c|0,this.Fl=d|0,this.Gh=g|0,this.Gl=p|0,this.Hh=m|0,this.Hl=h|0}process(t,e){for(let b=0;b<16;b++,e+=4)Gt[b]=t.getUint32(e),Zt[b]=t.getUint32(e+=4);for(let b=16;b<80;b++){let I=Gt[b-15]|0,D=Zt[b-15]|0,U=O.rotrSH(I,D,1)^O.rotrSH(I,D,8)^O.shrSH(I,D,7),B=O.rotrSL(I,D,1)^O.rotrSL(I,D,8)^O.shrSL(I,D,7),R=Gt[b-2]|0,L=Zt[b-2]|0,Z=O.rotrSH(R,L,19)^O.rotrBH(R,L,61)^O.shrSH(R,L,6),H=O.rotrSL(R,L,19)^O.rotrBL(R,L,61)^O.shrSL(R,L,6),k=O.add4L(B,H,Zt[b-7],Zt[b-16]),Q=O.add4H(k,U,Z,Gt[b-7],Gt[b-16]);Gt[b]=Q|0,Zt[b]=k|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:f,Cl:u,Dh:a,Dl:l,Eh:c,El:d,Fh:g,Fl:p,Gh:m,Gl:h,Hh:w,Hl:v}=this;for(let b=0;b<80;b++){let I=O.rotrSH(c,d,14)^O.rotrSH(c,d,18)^O.rotrBH(c,d,41),D=O.rotrSL(c,d,14)^O.rotrSL(c,d,18)^O.rotrBL(c,d,41),U=c&g^~c&m,B=d&p^~d&h,R=O.add5L(v,D,B,Ya[b],Zt[b]),L=O.add5H(R,w,I,U,Xa[b],Gt[b]),Z=R|0,H=O.rotrSH(n,o,28)^O.rotrBH(n,o,34)^O.rotrBH(n,o,39),k=O.rotrSL(n,o,28)^O.rotrBL(n,o,34)^O.rotrBL(n,o,39),Q=n&s^n&f^s&f,A=o&i^o&u^i&u;w=m|0,v=h|0,m=g|0,h=p|0,g=c|0,p=d|0,{h:c,l:d}=O.add(a|0,l|0,L|0,Z|0),a=f|0,l=u|0,f=s|0,u=i|0,s=n|0,i=o|0;let T=O.add3L(Z,k,A);n=O.add3H(T,L,H,Q),o=T|0}({h:n,l:o}=O.add(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=O.add(this.Bh|0,this.Bl|0,s|0,i|0),{h:f,l:u}=O.add(this.Ch|0,this.Cl|0,f|0,u|0),{h:a,l}=O.add(this.Dh|0,this.Dl|0,a|0,l|0),{h:c,l:d}=O.add(this.Eh|0,this.El|0,c|0,d|0),{h:g,l:p}=O.add(this.Fh|0,this.Fl|0,g|0,p|0),{h:m,l:h}=O.add(this.Gh|0,this.Gl|0,m|0,h|0),{h:w,l:v}=O.add(this.Hh|0,this.Hl|0,w|0,v|0),this.set(n,o,s,i,f,u,a,l,c,d,g,p,m,h,w,v)}roundClean(){Gt.fill(0),Zt.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var ss=nr(()=>new an);var cr={};ht(cr,{aInRange:()=>pt,abool:()=>Et,abytes:()=>Ee,bitGet:()=>rc,bitLen:()=>ln,bitMask:()=>He,bitSet:()=>nc,bytesToHex:()=>Ut,bytesToNumberBE:()=>_t,bytesToNumberLE:()=>$t,concatBytes:()=>Nt,createHmacDrbg:()=>dn,ensureBytes:()=>X,equalBytes:()=>tc,hexToBytes:()=>se,hexToNumber:()=>fn,inRange:()=>Me,isBytes:()=>jt,memoized:()=>ae,notImplemented:()=>sc,numberToBytesBE:()=>Xt,numberToBytesLE:()=>ie,numberToHexUnpadded:()=>oe,numberToVarBytesBE:()=>Ja,utf8ToBytes:()=>ec,validateObject:()=>It});var ir=BigInt(0),ar=BigInt(1),Wa=BigInt(2);function jt(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Ee(r){if(!jt(r))throw new Error("Uint8Array expected")}function Et(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}var Qa=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Ut(r){Ee(r);let t="";for(let e=0;e<r.length;e++)t+=Qa[r[e]];return t}function oe(r){let t=r.toString(16);return t.length&1?"0"+t:t}function fn(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?ir:BigInt("0x"+r)}var Dt={_0:48,_9:57,A:65,F:70,a:97,f:102};function is(r){if(r>=Dt._0&&r<=Dt._9)return r-Dt._0;if(r>=Dt.A&&r<=Dt.F)return r-(Dt.A-10);if(r>=Dt.a&&r<=Dt.f)return r-(Dt.a-10)}function se(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let t=r.length,e=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=is(r.charCodeAt(s)),f=is(r.charCodeAt(s+1));if(i===void 0||f===void 0){let u=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+u+'" at index '+s)}n[o]=i*16+f}return n}function _t(r){return fn(Ut(r))}function $t(r){return Ee(r),fn(Ut(Uint8Array.from(r).reverse()))}function Xt(r,t){return se(r.toString(16).padStart(t*2,"0"))}function ie(r,t){return Xt(r,t).reverse()}function Ja(r){return se(oe(r))}function X(r,t,e){let n;if(typeof t=="string")try{n=se(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(jt(t))n=Uint8Array.from(t);else throw new Error(r+" must be hex string or Uint8Array");let o=n.length;if(typeof e=="number"&&o!==e)throw new Error(r+" of length "+e+" expected, got "+o);return n}function Nt(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Ee(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}function tc(r,t){if(r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}function ec(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}var cn=r=>typeof r=="bigint"&&ir<=r;function Me(r,t,e){return cn(r)&&cn(t)&&cn(e)&&t<=r&&r<e}function pt(r,t,e,n){if(!Me(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function ln(r){let t;for(t=0;r>ir;r>>=ar,t+=1);return t}function rc(r,t){return r>>BigInt(t)&ar}function nc(r,t,e){return r|(e?ar:ir)<<BigInt(t)}var He=r=>(Wa<<BigInt(r-1))-ar,un=r=>new Uint8Array(r),as=r=>Uint8Array.from(r);function dn(r,t,e){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof e!="function")throw new Error("hmacFn must be a function");let n=un(r),o=un(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},f=(...c)=>e(o,n,...c),u=(c=un())=>{o=f(as([0]),c),n=f(),c.length!==0&&(o=f(as([1]),c),n=f())},a=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let c=0,d=[];for(;c<t;){n=f();let g=n.slice();d.push(g),c+=n.length}return Nt(...d)};return(c,d)=>{i(),u(c);let g;for(;!(g=d(a()));)u();return i(),g}}var oc={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||jt(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,t)=>t.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function It(r,t,e={}){let n=(o,s,i)=>{let f=oc[s];if(typeof f!="function")throw new Error("invalid validator function");let u=r[o];if(!(i&&u===void 0)&&!f(u,r))throw new Error("param "+String(o)+" is invalid. Expected "+s+", got "+u)};for(let[o,s]of Object.entries(t))n(o,s,!1);for(let[o,s]of Object.entries(e))n(o,s,!0);return r}var sc=()=>{throw new Error("not implemented")};function ae(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let s=r(e,...n);return t.set(e,s),s}}var J=BigInt(0),j=BigInt(1),ce=BigInt(2),ic=BigInt(3),hn=BigInt(4),cs=BigInt(5),us=BigInt(8),ac=BigInt(9),cc=BigInt(16);function V(r,t){let e=r%t;return e>=J?e:t+e}function uc(r,t,e){if(t<J)throw new Error("invalid exponent, negatives unsupported");if(e<=J)throw new Error("invalid modulus");if(e===j)return J;let n=j;for(;t>J;)t&j&&(n=n*r%e),r=r*r%e,t>>=j;return n}function $(r,t,e){let n=r;for(;t-- >J;)n*=n,n%=e;return n}function ur(r,t){if(r===J)throw new Error("invert: expected non-zero number");if(t<=J)throw new Error("invert: expected positive modulus, got "+t);let e=V(r,t),n=t,o=J,s=j,i=j,f=J;for(;e!==J;){let a=n/e,l=n%e,c=o-i*a,d=s-f*a;n=e,e=l,o=i,s=f,i=c,f=d}if(n!==j)throw new Error("invert: does not exist");return V(o,t)}function fc(r){let t=(r-j)/ce,e,n,o;for(e=r-j,n=0;e%ce===J;e/=ce,n++);for(o=ce;o<r&&uc(o,t,r)!==r-j;o++)if(o>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){let i=(r+j)/hn;return function(u,a){let l=u.pow(a,i);if(!u.eql(u.sqr(l),a))throw new Error("Cannot find square root");return l}}let s=(e+j)/ce;return function(f,u){if(f.pow(u,t)===f.neg(f.ONE))throw new Error("Cannot find square root");let a=n,l=f.pow(f.mul(f.ONE,o),e),c=f.pow(u,s),d=f.pow(u,e);for(;!f.eql(d,f.ONE);){if(f.eql(d,f.ZERO))return f.ZERO;let g=1;for(let m=f.sqr(d);g<a&&!f.eql(m,f.ONE);g++)m=f.sqr(m);let p=f.pow(l,j<<BigInt(a-g-1));l=f.sqr(p),c=f.mul(c,p),d=f.mul(d,l),a=g}return c}}function lc(r){if(r%hn===ic){let t=(r+j)/hn;return function(n,o){let s=n.pow(o,t);if(!n.eql(n.sqr(s),o))throw new Error("Cannot find square root");return s}}if(r%us===cs){let t=(r-cs)/us;return function(n,o){let s=n.mul(o,ce),i=n.pow(s,t),f=n.mul(o,i),u=n.mul(n.mul(f,ce),i),a=n.mul(f,n.sub(u,n.ONE));if(!n.eql(n.sqr(a),o))throw new Error("Cannot find square root");return a}}return r%cc,fc(r)}var fs=(r,t)=>(V(r,t)&j)===j,dc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function pn(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=dc.reduce((n,o)=>(n[o]="function",n),t);return It(r,e)}function hc(r,t,e){if(e<J)throw new Error("invalid exponent, negatives unsupported");if(e===J)return r.ONE;if(e===j)return t;let n=r.ONE,o=t;for(;e>J;)e&j&&(n=r.mul(n,o)),o=r.sqr(o),e>>=j;return n}function pc(r,t){let e=new Array(t.length),n=t.reduce((s,i,f)=>r.is0(i)?s:(e[f]=s,r.mul(s,i)),r.ONE),o=r.inv(n);return t.reduceRight((s,i,f)=>r.is0(i)?s:(e[f]=r.mul(s,e[f]),r.mul(s,i)),o),e}function mn(r,t){let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function Yt(r,t,e=!1,n={}){if(r<=J)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:s}=mn(r,t);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let i,f=Object.freeze({ORDER:r,BITS:o,BYTES:s,MASK:He(o),ZERO:J,ONE:j,create:u=>V(u,r),isValid:u=>{if(typeof u!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof u);return J<=u&&u<r},is0:u=>u===J,isOdd:u=>(u&j)===j,neg:u=>V(-u,r),eql:(u,a)=>u===a,sqr:u=>V(u*u,r),add:(u,a)=>V(u+a,r),sub:(u,a)=>V(u-a,r),mul:(u,a)=>V(u*a,r),pow:(u,a)=>hc(f,u,a),div:(u,a)=>V(u*ur(a,r),r),sqrN:u=>u*u,addN:(u,a)=>u+a,subN:(u,a)=>u-a,mulN:(u,a)=>u*a,inv:u=>ur(u,r),sqrt:n.sqrt||(u=>(i||(i=lc(r)),i(f,u))),invertBatch:u=>pc(f,u),cmov:(u,a,l)=>l?a:u,toBytes:u=>e?ie(u,s):Xt(u,s),fromBytes:u=>{if(u.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+u.length);return e?$t(u):_t(u)}});return Object.freeze(f)}function ls(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function gn(r){let t=ls(r);return t+Math.ceil(t/2)}function ds(r,t,e=!1){let n=r.length,o=ls(t),s=gn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?_t(r):$t(r),f=V(i,t-j)+j;return e?ie(f,o):Xt(f,o)}var hs=BigInt(0),fr=BigInt(1);function yn(r,t){let e=t.negate();return r?e:t}function ps(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function bn(r,t){ps(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1);return{windows:e,windowSize:n}}function gc(r,t){if(!Array.isArray(r))throw new Error("array expected");r.forEach((e,n)=>{if(!(e instanceof t))throw new Error("invalid point at index "+n)})}function yc(r,t){if(!Array.isArray(r))throw new Error("array of scalars expected");r.forEach((e,n)=>{if(!t.isValid(e))throw new Error("invalid scalar at index "+n)})}var xn=new WeakMap,ms=new WeakMap;function wn(r){return ms.get(r)||1}function lr(r,t){return{constTimeNegate:yn,hasPrecomputes(e){return wn(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>hs;)n&fr&&(o=o.add(s)),s=s.double(),n>>=fr;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=bn(n,t),i=[],f=e,u=f;for(let a=0;a<o;a++){u=f,i.push(u);for(let l=1;l<s;l++)u=u.add(f),i.push(u);f=u.double()}return i},wNAF(e,n,o){let{windows:s,windowSize:i}=bn(e,t),f=r.ZERO,u=r.BASE,a=BigInt(2**e-1),l=2**e,c=BigInt(e);for(let d=0;d<s;d++){let g=d*i,p=Number(o&a);o>>=c,p>i&&(p-=l,o+=fr);let m=g,h=g+Math.abs(p)-1,w=d%2!==0,v=p<0;p===0?u=u.add(yn(w,n[m])):f=f.add(yn(v,n[h]))}return{p:f,f:u}},wNAFUnsafe(e,n,o,s=r.ZERO){let{windows:i,windowSize:f}=bn(e,t),u=BigInt(2**e-1),a=2**e,l=BigInt(e);for(let c=0;c<i;c++){let d=c*f;if(o===hs)break;let g=Number(o&u);if(o>>=l,g>f&&(g-=a,o+=fr),g===0)continue;let p=n[d+Math.abs(g)-1];g<0&&(p=p.negate()),s=s.add(p)}return s},getPrecomputes(e,n,o){let s=xn.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&xn.set(n,o(s))),s},wNAFCached(e,n,o){let s=wn(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=wn(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){ps(n,t),ms.set(e,n),xn.delete(e)}}}function dr(r,t,e,n){if(gc(e,r),yc(n,t),e.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=r.ZERO,s=ln(BigInt(e.length)),i=s>12?s-3:s>4?s-2:s?2:1,f=(1<<i)-1,u=new Array(f+1).fill(o),a=Math.floor((t.BITS-1)/i)*i,l=o;for(let c=a;c>=0;c-=i){u.fill(o);for(let g=0;g<n.length;g++){let p=n[g],m=Number(p>>BigInt(c)&BigInt(f));u[m]=u[m].add(e[g])}let d=o;for(let g=u.length-1,p=o;g>0;g--)p=p.add(u[g]),d=d.add(p);if(l=l.add(d),c!==0)for(let g=0;g<i;g++)l=l.double()}return l}function Ke(r){return pn(r.Fp),It(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...mn(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var vt=BigInt(0),mt=BigInt(1),hr=BigInt(2),bc=BigInt(8),xc={zip215:!0};function wc(r){let t=Ke(r);return It(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function gs(r){let t=wc(r),{Fp:e,n,prehash:o,hash:s,randomBytes:i,nByteLength:f,h:u}=t,a=hr<<BigInt(f*8)-mt,l=e.create,c=Yt(t.n,t.nBitLength),d=t.uvRatio||((x,y)=>{try{return{isValid:!0,value:e.sqrt(x*e.inv(y))}}catch{return{isValid:!1,value:vt}}}),g=t.adjustScalarBytes||(x=>x),p=t.domain||((x,y,E)=>{if(Et("phflag",E),y.length||E)throw new Error("Contexts/pre-hash are not supported");return x});function m(x,y){pt("coordinate "+x,y,vt,a)}function h(x){if(!(x instanceof b))throw new Error("ExtendedPoint expected")}let w=ae((x,y)=>{let{ex:E,ey:S,ez:_}=x,N=x.is0();y==null&&(y=N?bc:e.inv(_));let C=l(E*y),F=l(S*y),P=l(_*y);if(N)return{x:vt,y:mt};if(P!==mt)throw new Error("invZ was invalid");return{x:C,y:F}}),v=ae(x=>{let{a:y,d:E}=t;if(x.is0())throw new Error("bad point: ZERO");let{ex:S,ey:_,ez:N,et:C}=x,F=l(S*S),P=l(_*_),q=l(N*N),G=l(q*q),et=l(F*y),rt=l(q*l(et+P)),st=l(G+l(E*l(F*P)));if(rt!==st)throw new Error("bad point: equation left != right (1)");let it=l(S*_),dt=l(N*C);if(it!==dt)throw new Error("bad point: equation left != right (2)");return!0});class b{constructor(y,E,S,_){this.ex=y,this.ey=E,this.ez=S,this.et=_,m("x",y),m("y",E),m("z",S),m("t",_),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(y){if(y instanceof b)throw new Error("extended point not allowed");let{x:E,y:S}=y||{};return m("x",E),m("y",S),new b(E,S,mt,l(E*S))}static normalizeZ(y){let E=e.invertBatch(y.map(S=>S.ez));return y.map((S,_)=>S.toAffine(E[_])).map(b.fromAffine)}static msm(y,E){return dr(b,c,y,E)}_setWindowSize(y){U.setWindowSize(this,y)}assertValidity(){v(this)}equals(y){h(y);let{ex:E,ey:S,ez:_}=this,{ex:N,ey:C,ez:F}=y,P=l(E*F),q=l(N*_),G=l(S*F),et=l(C*_);return P===q&&G===et}is0(){return this.equals(b.ZERO)}negate(){return new b(l(-this.ex),this.ey,this.ez,l(-this.et))}double(){let{a:y}=t,{ex:E,ey:S,ez:_}=this,N=l(E*E),C=l(S*S),F=l(hr*l(_*_)),P=l(y*N),q=E+S,G=l(l(q*q)-N-C),et=P+C,rt=et-F,st=P-C,it=l(G*rt),dt=l(et*st),ft=l(G*st),St=l(rt*et);return new b(it,dt,St,ft)}add(y){h(y);let{a:E,d:S}=t,{ex:_,ey:N,ez:C,et:F}=this,{ex:P,ey:q,ez:G,et}=y;if(E===BigInt(-1)){let To=l((N-_)*(q+P)),Ro=l((N+_)*(q-P)),Gr=l(Ro-To);if(Gr===vt)return this.double();let Do=l(C*hr*et),Uo=l(F*hr*G),_o=Uo+Do,No=Ro+To,Po=Uo-Do,Li=l(_o*Gr),Ti=l(No*Po),Ri=l(_o*Po),Di=l(Gr*No);return new b(Li,Ti,Di,Ri)}let rt=l(_*P),st=l(N*q),it=l(F*S*et),dt=l(C*G),ft=l((_+N)*(P+q)-rt-st),St=dt-it,Bt=dt+it,De=l(st-E*rt),Ai=l(ft*St),Si=l(Bt*De),Ii=l(ft*De),Bi=l(St*Bt);return new b(Ai,Si,Bi,Ii)}subtract(y){return this.add(y.negate())}wNAF(y){return U.wNAFCached(this,y,b.normalizeZ)}multiply(y){let E=y;pt("scalar",E,mt,n);let{p:S,f:_}=this.wNAF(E);return b.normalizeZ([S,_])[0]}multiplyUnsafe(y,E=b.ZERO){let S=y;return pt("scalar",S,vt,n),S===vt?D:this.is0()||S===mt?this:U.wNAFCachedUnsafe(this,S,b.normalizeZ,E)}isSmallOrder(){return this.multiplyUnsafe(u).is0()}isTorsionFree(){return U.unsafeLadder(this,n).is0()}toAffine(y){return w(this,y)}clearCofactor(){let{h:y}=t;return y===mt?this:this.multiplyUnsafe(y)}static fromHex(y,E=!1){let{d:S,a:_}=t,N=e.BYTES;y=X("pointHex",y,N),Et("zip215",E);let C=y.slice(),F=y[N-1];C[N-1]=F&-129;let P=$t(C),q=E?a:e.ORDER;pt("pointHex.y",P,vt,q);let G=l(P*P),et=l(G-mt),rt=l(S*G-_),{isValid:st,value:it}=d(et,rt);if(!st)throw new Error("Point.fromHex: invalid y coordinate");let dt=(it&mt)===mt,ft=(F&128)!==0;if(!E&&it===vt&&ft)throw new Error("Point.fromHex: x=0 and x_0=1");return ft!==dt&&(it=l(-it)),b.fromAffine({x:it,y:P})}static fromPrivateKey(y){return L(y).point}toRawBytes(){let{x:y,y:E}=this.toAffine(),S=ie(E,e.BYTES);return S[S.length-1]|=y&mt?128:0,S}toHex(){return Ut(this.toRawBytes())}}b.BASE=new b(t.Gx,t.Gy,mt,l(t.Gx*t.Gy)),b.ZERO=new b(vt,mt,mt,vt);let{BASE:I,ZERO:D}=b,U=lr(b,f*8);function B(x){return V(x,n)}function R(x){return B($t(x))}function L(x){let y=e.BYTES;x=X("private key",x,y);let E=X("hashed private key",s(x),2*y),S=g(E.slice(0,y)),_=E.slice(y,2*y),N=R(S),C=I.multiply(N),F=C.toRawBytes();return{head:S,prefix:_,scalar:N,point:C,pointBytes:F}}function Z(x){return L(x).pointBytes}function H(x=new Uint8Array,...y){let E=Nt(...y);return R(s(p(E,X("context",x),!!o)))}function k(x,y,E={}){x=X("message",x),o&&(x=o(x));let{prefix:S,scalar:_,pointBytes:N}=L(y),C=H(E.context,S,x),F=I.multiply(C).toRawBytes(),P=H(E.context,F,N,x),q=B(C+P*_);pt("signature.s",q,vt,n);let G=Nt(F,ie(q,e.BYTES));return X("result",G,e.BYTES*2)}let Q=xc;function A(x,y,E,S=Q){let{context:_,zip215:N}=S,C=e.BYTES;x=X("signature",x,2*C),y=X("message",y),E=X("publicKey",E,C),N!==void 0&&Et("zip215",N),o&&(y=o(y));let F=$t(x.slice(C,2*C)),P,q,G;try{P=b.fromHex(E,N),q=b.fromHex(x.slice(0,C),N),G=I.multiplyUnsafe(F)}catch{return!1}if(!N&&P.isSmallOrder())return!1;let et=H(_,q.toRawBytes(),P.toRawBytes(),y);return q.add(P.multiplyUnsafe(et)).subtract(G).clearCofactor().equals(b.ZERO)}return I._setWindowSize(8),{CURVE:t,getPublicKey:Z,sign:k,verify:A,ExtendedPoint:b,utils:{getExtendedPublicKey:L,randomPrivateKey:()=>i(e.BYTES),precompute(x=8,y=b.BASE){return y._setWindowSize(x),y.multiply(BigInt(3)),y}}}}var En=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),ys=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Ol=BigInt(0),Ec=BigInt(1),bs=BigInt(2),Cl=BigInt(3),vc=BigInt(5),Ac=BigInt(8);function Sc(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=En,f=r*r%s*r%s,u=$(f,bs,s)*f%s,a=$(u,Ec,s)*r%s,l=$(a,vc,s)*a%s,c=$(l,t,s)*l%s,d=$(c,e,s)*c%s,g=$(d,n,s)*d%s,p=$(g,o,s)*g%s,m=$(p,o,s)*g%s,h=$(m,t,s)*l%s;return{pow_p_5_8:$(h,bs,s)*r%s,b2:f}}function Ic(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Bc(r,t){let e=En,n=V(t*t*t,e),o=V(n*n*t,e),s=Sc(r*o).pow_p_5_8,i=V(r*n*s,e),f=V(t*i*i,e),u=i,a=V(i*ys,e),l=f===r,c=f===V(-r,e),d=f===V(-r*ys,e);return l&&(i=u),(c||d)&&(i=a),fs(i,e)&&(i=V(-i,e)),{isValid:l||c,value:i}}var Lc=Yt(En,void 0,!0),Tc={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Lc,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:Ac,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:ss,randomBytes:or,adjustScalarBytes:Ic,uvRatio:Bc},xs=gs(Tc);var pr=32;function ws(r,t,e){return xs.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var mr=class{type="Ed25519";raw;constructor(t){this.raw=vn(t,pr)}toMultihash(){return Rt.digest(gr(this))}toCID(){return lt.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:xt(this.raw,t.raw)}verify(t,e){return ws(this.raw,e,t)}};function vs(r){return r=vn(r,pr),new mr(r)}function vn(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new _e(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}function Pt(r=0){return new Uint8Array(r)}function at(r=0){return new Uint8Array(r)}var Dc=Math.pow(2,7),Uc=Math.pow(2,14),_c=Math.pow(2,21),An=Math.pow(2,28),Sn=Math.pow(2,35),In=Math.pow(2,42),Bn=Math.pow(2,49),K=128,ct=127;function nt(r){if(r<Dc)return 1;if(r<Uc)return 2;if(r<_c)return 3;if(r<An)return 4;if(r<Sn)return 5;if(r<In)return 6;if(r<Bn)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ln(r,t,e=0){switch(nt(r)){case 8:t[e++]=r&255|K,r/=128;case 7:t[e++]=r&255|K,r/=128;case 6:t[e++]=r&255|K,r/=128;case 5:t[e++]=r&255|K,r/=128;case 4:t[e++]=r&255|K,r>>>=7;case 3:t[e++]=r&255|K,r>>>=7;case 2:t[e++]=r&255|K,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Nc(r,t,e=0){switch(nt(r)){case 8:t.set(e++,r&255|K),r/=128;case 7:t.set(e++,r&255|K),r/=128;case 6:t.set(e++,r&255|K),r/=128;case 5:t.set(e++,r&255|K),r/=128;case 4:t.set(e++,r&255|K),r>>>=7;case 3:t.set(e++,r&255|K),r>>>=7;case 2:t.set(e++,r&255|K),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function Tn(r,t){let e=r[t],n=0;if(n+=e&ct,e<K||(e=r[t+1],n+=(e&ct)<<7,e<K)||(e=r[t+2],n+=(e&ct)<<14,e<K)||(e=r[t+3],n+=(e&ct)<<21,e<K)||(e=r[t+4],n+=(e&ct)*An,e<K)||(e=r[t+5],n+=(e&ct)*Sn,e<K)||(e=r[t+6],n+=(e&ct)*In,e<K)||(e=r[t+7],n+=(e&ct)*Bn,e<K))return n;throw new RangeError("Could not decode varint")}function Pc(r,t){let e=r.get(t),n=0;if(n+=e&ct,e<K||(e=r.get(t+1),n+=(e&ct)<<7,e<K)||(e=r.get(t+2),n+=(e&ct)<<14,e<K)||(e=r.get(t+3),n+=(e&ct)<<21,e<K)||(e=r.get(t+4),n+=(e&ct)*An,e<K)||(e=r.get(t+5),n+=(e&ct)*Sn,e<K)||(e=r.get(t+6),n+=(e&ct)*In,e<K)||(e=r.get(t+7),n+=(e&ct)*Bn,e<K))return n;throw new RangeError("Could not decode varint")}function Wt(r,t,e=0){return t==null&&(t=at(nt(r))),t instanceof Uint8Array?Ln(r,t,e):Nc(r,t,e)}function Ot(r,t=0){return r instanceof Uint8Array?Tn(r,t):Pc(r,t)}var Rn=new Float32Array([-0]),Qt=new Uint8Array(Rn.buffer);function As(r,t,e){Rn[0]=r,t[e]=Qt[0],t[e+1]=Qt[1],t[e+2]=Qt[2],t[e+3]=Qt[3]}function Ss(r,t){return Qt[0]=r[t],Qt[1]=r[t+1],Qt[2]=r[t+2],Qt[3]=r[t+3],Rn[0]}var Dn=new Float64Array([-0]),ut=new Uint8Array(Dn.buffer);function Is(r,t,e){Dn[0]=r,t[e]=ut[0],t[e+1]=ut[1],t[e+2]=ut[2],t[e+3]=ut[3],t[e+4]=ut[4],t[e+5]=ut[5],t[e+6]=ut[6],t[e+7]=ut[7]}function Bs(r,t){return ut[0]=r[t],ut[1]=r[t+1],ut[2]=r[t+2],ut[3]=r[t+3],ut[4]=r[t+4],ut[5]=r[t+5],ut[6]=r[t+6],ut[7]=r[t+7],Dn[0]}var Oc=BigInt(Number.MAX_SAFE_INTEGER),Cc=BigInt(Number.MIN_SAFE_INTEGER),gt=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return ue;if(t<Oc&&t>Cc)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>Ls&&(o=0n,++n>Ls&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return ue;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):ue}},ue=new gt(0,0);ue.toBigInt=function(){return 0n};ue.zzEncode=ue.zzDecode=function(){return this};ue.length=function(){return 1};var Ls=4294967296n;function Ts(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Rs(r,t,e){if(e-t<1)return"";let o,s=[],i=0,f;for(;t<e;)f=r[t++],f<128?s[i++]=f:f>191&&f<224?s[i++]=(f&31)<<6|r[t++]&63:f>239&&f<365?(f=((f&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(f>>10),s[i++]=56320+(f&1023)):s[i++]=(f&15)<<12|(r[t++]&63)<<6|r[t++]&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 Un(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function At(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function br(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var _n=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,At(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw At(this,4);return br(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw At(this,4);return br(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw At(this,4);let t=Ss(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw At(this,4);let t=Bs(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw At(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Rs(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw At(this,t);this.pos+=t}else do if(this.pos>=this.len)throw At(this);while(this.buf[this.pos++]&128);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new gt(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw At(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw At(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw At(this,8);let t=br(this.buf,this.pos+=4),e=br(this.buf,this.pos+=4);return new gt(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Tn(this.buf,this.pos);return this.pos+=nt(t),t}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 Nn(r){return new _n(r instanceof Uint8Array?r:r.subarray())}function Ct(r,t,e){let n=Nn(r);return t.decode(n,void 0,e)}var Pn={};ht(Pn,{base10:()=>kc});var kc=zt({prefix:"9",name:"base10",alphabet:"0123456789"});var On={};ht(On,{base16:()=>Fc,base16upper:()=>Mc});var Fc=Y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Mc=Y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Cn={};ht(Cn,{base2:()=>Hc});var Hc=Y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var kn={};ht(kn,{base256emoji:()=>Gc});var Us=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}"),Kc=Us.reduce((r,t,e)=>(r[e]=t,r),[]),qc=Us.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function zc(r){return r.reduce((t,e)=>(t+=Kc[e],t),"")}function Vc(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=qc[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Gc=he({prefix:"\u{1F680}",name:"base256emoji",encode:zc,decode:Vc});var Fn={};ht(Fn,{base64:()=>Zc,base64pad:()=>jc,base64url:()=>$c,base64urlpad:()=>Xc});var Zc=Y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),jc=Y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),$c=Y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Xc=Y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Mn={};ht(Mn,{base8:()=>Yc});var Yc=Y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Hn={};ht(Hn,{identity:()=>Wc});var Wc=he({prefix:"\0",name:"identity",encode:r=>Mo(r),decode:r=>Fo(r)});var bd=new TextEncoder,xd=new TextDecoder;var zn={};ht(zn,{sha256:()=>qe,sha512:()=>tu});function qn({name:r,code:t,encode:e}){return new Kn(r,t,e)}var Kn=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?ee(this.code,e):e.then(n=>ee(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Ns(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var qe=qn({name:"sha2-256",code:18,encode:Ns("SHA-256")}),tu=qn({name:"sha2-512",code:19,encode:Ns("SHA-512")});var ze={...Hn,...Cn,...Mn,...Pn,...On,...Jr,...tn,...Qr,...Fn,...kn},Ud={...zn,...nn};function Os(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Ps=Os("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Vn=Os("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=at(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),eu={utf8:Ps,"utf-8":Ps,hex:ze.base16,latin1:Vn,ascii:Vn,binary:Vn,...ze},xr=eu;function kt(r,t="utf8"){let e=xr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function Gn(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return at(i);o+i>t&&(n=at(t),o=0);let f=n.subarray(o,o+=i);return o&7&&(o=(o|7)+1),f}}var fe=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Zn(){}var $n=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},ru=Gn();function nu(r){return globalThis.Buffer!=null?at(r):ru(r)}var Ge=class{len;head;tail;states;constructor(){this.len=0,this.head=new fe(Zn,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new fe(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Xn((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(wr,10,gt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=gt.fromBigInt(t);return this._push(wr,e.length(),e)}uint64Number(t){return this._push(Ln,nt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let e=gt.fromBigInt(t).zzEncode();return this._push(wr,e.length(),e)}sint64Number(t){let e=gt.fromNumber(t).zzEncode();return this._push(wr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(jn,1,t?1:0)}fixed32(t){return this._push(Ve,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=gt.fromBigInt(t);return this._push(Ve,4,e.lo)._push(Ve,4,e.hi)}fixed64Number(t){let e=gt.fromNumber(t);return this._push(Ve,4,e.lo)._push(Ve,4,e.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(As,4,t)}double(t){return this._push(Is,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(jn,1,0):this.uint32(e)._push(su,e,t)}string(t){let e=Ts(t);return e!==0?this.uint32(e)._push(Un,e,t):this._push(jn,1,0)}fork(){return this.states=new $n(this),this.head=this.tail=new fe(Zn,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 fe(Zn,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=nu(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function jn(r,t,e){t[e]=r&255}function ou(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Xn=class extends fe{next;constructor(t,e){super(ou,t,e),this.next=void 0}};function wr(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function Ve(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function su(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Ge.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(iu,t,r),this},Ge.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(au,t,r),this});function iu(r,t,e){t.set(r,e)}function au(r,t,e){r.length<40?Un(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(kt(r),e)}function Yn(){return new Ge}function Ft(r,t){let e=Yn();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var ve;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(ve||(ve={}));function Er(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function Ae(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let f=t(s);i.int32(f)},n=function(s){let i=s.int32();return t(i)};return Er("enum",ve.VARINT,e,n)}function Mt(r,t){return Er("message",ve.LENGTH_DELIMITED,r,t)}var vr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var bt;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1"})(bt||(bt={}));var Wn;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1"})(Wn||(Wn={}));(function(r){r.codec=()=>Ae(Wn)})(bt||(bt={}));var Ze;(function(r){let t;r.codec=()=>(t==null&&(t=Mt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),bt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let f=e.uint32();switch(f>>>3){case 1:{s.Type=bt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(f&7);break}}}return s})),t),r.encode=e=>Ft(e,r.codec()),r.decode=(e,n)=>Ct(e,r.codec(),n)})(Ze||(Ze={}));var Qn;(function(r){let t;r.codec=()=>(t==null&&(t=Mt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),bt.codec().encode(e.Type,n)),e.Data!=null&&(n.uint32(18),n.bytes(e.Data)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let f=e.uint32();switch(f>>>3){case 1:{s.Type=bt.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(f&7);break}}}return s})),t),r.encode=e=>Ft(e,r.codec()),r.decode=(e,n)=>Ct(e,r.codec(),n)})(Qn||(Qn={}));function tt(r,t="utf8"){let e=xr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var je=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}};var uu=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Jt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),te=new Uint32Array(64),Jn=class extends we{constructor(){super(64,32,8,!1),this.A=Jt[0]|0,this.B=Jt[1]|0,this.C=Jt[2]|0,this.D=Jt[3]|0,this.E=Jt[4]|0,this.F=Jt[5]|0,this.G=Jt[6]|0,this.H=Jt[7]|0}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:f,H:u}=this;return[t,e,n,o,s,i,f,u]}set(t,e,n,o,s,i,f,u){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=f|0,this.H=u|0}process(t,e){for(let c=0;c<16;c++,e+=4)te[c]=t.getUint32(e,!1);for(let c=16;c<64;c++){let d=te[c-15],g=te[c-2],p=wt(d,7)^wt(d,18)^d>>>3,m=wt(g,17)^wt(g,19)^g>>>10;te[c]=m+te[c-7]+p+te[c-16]|0}let{A:n,B:o,C:s,D:i,E:f,F:u,G:a,H:l}=this;for(let c=0;c<64;c++){let d=wt(f,6)^wt(f,11)^wt(f,25),g=l+d+rs(f,u,a)+uu[c]+te[c]|0,m=(wt(n,2)^wt(n,13)^wt(n,22))+ns(n,o,s)|0;l=a,a=u,u=f,f=i+g|0,i=s,s=o,o=n,n=g+m|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,f=f+this.E|0,u=u+this.F|0,a=a+this.G|0,l=l+this.H|0,this.set(n,o,s,i,f,u,a,l)}roundClean(){te.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var Cs=nr(()=>new Jn);var Ar=class extends xe{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,Jo(t);let n=Fe(e);if(this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let i=0;i<s.length;i++)s[i]^=54;this.iHash.update(s),this.oHash=t.create();for(let i=0;i<s.length;i++)s[i]^=106;this.oHash.update(s),s.fill(0)}update(t){return be(this),this.iHash.update(t),this}digestInto(t){be(this),ye(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:f}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=f,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},to=(r,t,e)=>new Ar(r,t).update(e).digest();to.create=(r,t)=>new Ar(r,t);function ks(r){r.lowS!==void 0&&Et("lowS",r.lowS),r.prehash!==void 0&&Et("prehash",r.prehash)}function fu(r){let t=Ke(r);It(t,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});let{endo:e,Fp:n,a:o}=t;if(e){if(!n.eql(o,n.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...t})}var{bytesToNumberBE:lu,hexToBytes:du}=cr,Ht={Err:class extends Error{constructor(t=""){super(t)}},_tlv:{encode:(r,t)=>{let{Err:e}=Ht;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=oe(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?oe(o.length/2|128):"";return oe(r)+s+o+t},decode(r,t){let{Err:e}=Ht,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let u=o&127;if(!u)throw new e("tlv.decode(long): indefinite length not supported");if(u>4)throw new e("tlv.decode(long): byte length is too big");let a=t.subarray(n,n+u);if(a.length!==u)throw new e("tlv.decode: length bytes not complete");if(a[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let l of a)i=i<<8|l;if(n+=u,i<128)throw new e("tlv.decode(long): not minimal encoding")}let f=t.subarray(n,n+i);if(f.length!==i)throw new e("tlv.decode: wrong value length");return{v:f,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=Ht;if(r<Kt)throw new t("integer: negative integers are not allowed");let e=oe(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=Ht;if(r[0]&128)throw new t("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return lu(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Ht,o=typeof r=="string"?du(r):r;Ee(o);let{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:f,l:u}=n.decode(2,s),{v:a,l}=n.decode(2,u);if(l.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(f),s:e.decode(a)}},hexFromSig(r){let{_tlv:t,_int:e}=Ht,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},Kt=BigInt(0),ot=BigInt(1),wh=BigInt(2),Fs=BigInt(3),Eh=BigInt(4);function hu(r){let t=fu(r),{Fp:e}=t,n=Yt(t.n,t.nBitLength),o=t.toBytes||((m,h,w)=>{let v=h.toAffine();return Nt(Uint8Array.from([4]),e.toBytes(v.x),e.toBytes(v.y))}),s=t.fromBytes||(m=>{let h=m.subarray(1),w=e.fromBytes(h.subarray(0,e.BYTES)),v=e.fromBytes(h.subarray(e.BYTES,2*e.BYTES));return{x:w,y:v}});function i(m){let{a:h,b:w}=t,v=e.sqr(m),b=e.mul(v,m);return e.add(e.add(b,e.mul(m,h)),w)}if(!e.eql(e.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function f(m){return Me(m,ot,t.n)}function u(m){let{allowedPrivateKeyLengths:h,nByteLength:w,wrapPrivateKey:v,n:b}=t;if(h&&typeof m!="bigint"){if(jt(m)&&(m=Ut(m)),typeof m!="string"||!h.includes(m.length))throw new Error("invalid private key");m=m.padStart(w*2,"0")}let I;try{I=typeof m=="bigint"?m:_t(X("private key",m,w))}catch{throw new Error("invalid private key, expected hex or "+w+" bytes, got "+typeof m)}return v&&(I=V(I,b)),pt("private key",I,ot,b),I}function a(m){if(!(m instanceof d))throw new Error("ProjectivePoint expected")}let l=ae((m,h)=>{let{px:w,py:v,pz:b}=m;if(e.eql(b,e.ONE))return{x:w,y:v};let I=m.is0();h==null&&(h=I?e.ONE:e.inv(b));let D=e.mul(w,h),U=e.mul(v,h),B=e.mul(b,h);if(I)return{x:e.ZERO,y:e.ZERO};if(!e.eql(B,e.ONE))throw new Error("invZ was invalid");return{x:D,y:U}}),c=ae(m=>{if(m.is0()){if(t.allowInfinityPoint&&!e.is0(m.py))return;throw new Error("bad point: ZERO")}let{x:h,y:w}=m.toAffine();if(!e.isValid(h)||!e.isValid(w))throw new Error("bad point: x or y not FE");let v=e.sqr(w),b=i(h);if(!e.eql(v,b))throw new Error("bad point: equation left != right");if(!m.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class d{constructor(h,w,v){if(this.px=h,this.py=w,this.pz=v,h==null||!e.isValid(h))throw new Error("x required");if(w==null||!e.isValid(w))throw new Error("y required");if(v==null||!e.isValid(v))throw new Error("z required");Object.freeze(this)}static fromAffine(h){let{x:w,y:v}=h||{};if(!h||!e.isValid(w)||!e.isValid(v))throw new Error("invalid affine point");if(h instanceof d)throw new Error("projective point not allowed");let b=I=>e.eql(I,e.ZERO);return b(w)&&b(v)?d.ZERO:new d(w,v,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(h){let w=e.invertBatch(h.map(v=>v.pz));return h.map((v,b)=>v.toAffine(w[b])).map(d.fromAffine)}static fromHex(h){let w=d.fromAffine(s(X("pointHex",h)));return w.assertValidity(),w}static fromPrivateKey(h){return d.BASE.multiply(u(h))}static msm(h,w){return dr(d,n,h,w)}_setWindowSize(h){p.setWindowSize(this,h)}assertValidity(){c(this)}hasEvenY(){let{y:h}=this.toAffine();if(e.isOdd)return!e.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){a(h);let{px:w,py:v,pz:b}=this,{px:I,py:D,pz:U}=h,B=e.eql(e.mul(w,U),e.mul(I,b)),R=e.eql(e.mul(v,U),e.mul(D,b));return B&&R}negate(){return new d(this.px,e.neg(this.py),this.pz)}double(){let{a:h,b:w}=t,v=e.mul(w,Fs),{px:b,py:I,pz:D}=this,U=e.ZERO,B=e.ZERO,R=e.ZERO,L=e.mul(b,b),Z=e.mul(I,I),H=e.mul(D,D),k=e.mul(b,I);return k=e.add(k,k),R=e.mul(b,D),R=e.add(R,R),U=e.mul(h,R),B=e.mul(v,H),B=e.add(U,B),U=e.sub(Z,B),B=e.add(Z,B),B=e.mul(U,B),U=e.mul(k,U),R=e.mul(v,R),H=e.mul(h,H),k=e.sub(L,H),k=e.mul(h,k),k=e.add(k,R),R=e.add(L,L),L=e.add(R,L),L=e.add(L,H),L=e.mul(L,k),B=e.add(B,L),H=e.mul(I,D),H=e.add(H,H),L=e.mul(H,k),U=e.sub(U,L),R=e.mul(H,Z),R=e.add(R,R),R=e.add(R,R),new d(U,B,R)}add(h){a(h);let{px:w,py:v,pz:b}=this,{px:I,py:D,pz:U}=h,B=e.ZERO,R=e.ZERO,L=e.ZERO,Z=t.a,H=e.mul(t.b,Fs),k=e.mul(w,I),Q=e.mul(v,D),A=e.mul(b,U),T=e.add(w,v),x=e.add(I,D);T=e.mul(T,x),x=e.add(k,Q),T=e.sub(T,x),x=e.add(w,b);let y=e.add(I,U);return x=e.mul(x,y),y=e.add(k,A),x=e.sub(x,y),y=e.add(v,b),B=e.add(D,U),y=e.mul(y,B),B=e.add(Q,A),y=e.sub(y,B),L=e.mul(Z,x),B=e.mul(H,A),L=e.add(B,L),B=e.sub(Q,L),L=e.add(Q,L),R=e.mul(B,L),Q=e.add(k,k),Q=e.add(Q,k),A=e.mul(Z,A),x=e.mul(H,x),Q=e.add(Q,A),A=e.sub(k,A),A=e.mul(Z,A),x=e.add(x,A),k=e.mul(Q,x),R=e.add(R,k),k=e.mul(y,x),B=e.mul(T,B),B=e.sub(B,k),k=e.mul(T,Q),L=e.mul(y,L),L=e.add(L,k),new d(B,R,L)}subtract(h){return this.add(h.negate())}is0(){return this.equals(d.ZERO)}wNAF(h){return p.wNAFCached(this,h,d.normalizeZ)}multiplyUnsafe(h){let{endo:w,n:v}=t;pt("scalar",h,Kt,v);let b=d.ZERO;if(h===Kt)return b;if(this.is0()||h===ot)return this;if(!w||p.hasPrecomputes(this))return p.wNAFCachedUnsafe(this,h,d.normalizeZ);let{k1neg:I,k1:D,k2neg:U,k2:B}=w.splitScalar(h),R=b,L=b,Z=this;for(;D>Kt||B>Kt;)D&ot&&(R=R.add(Z)),B&ot&&(L=L.add(Z)),Z=Z.double(),D>>=ot,B>>=ot;return I&&(R=R.negate()),U&&(L=L.negate()),L=new d(e.mul(L.px,w.beta),L.py,L.pz),R.add(L)}multiply(h){let{endo:w,n:v}=t;pt("scalar",h,ot,v);let b,I;if(w){let{k1neg:D,k1:U,k2neg:B,k2:R}=w.splitScalar(h),{p:L,f:Z}=this.wNAF(U),{p:H,f:k}=this.wNAF(R);L=p.constTimeNegate(D,L),H=p.constTimeNegate(B,H),H=new d(e.mul(H.px,w.beta),H.py,H.pz),b=L.add(H),I=Z.add(k)}else{let{p:D,f:U}=this.wNAF(h);b=D,I=U}return d.normalizeZ([b,I])[0]}multiplyAndAddUnsafe(h,w,v){let b=d.BASE,I=(U,B)=>B===Kt||B===ot||!U.equals(b)?U.multiplyUnsafe(B):U.multiply(B),D=I(this,w).add(I(h,v));return D.is0()?void 0:D}toAffine(h){return l(this,h)}isTorsionFree(){let{h,isTorsionFree:w}=t;if(h===ot)return!0;if(w)return w(d,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h,clearCofactor:w}=t;return h===ot?this:w?w(d,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return Et("isCompressed",h),this.assertValidity(),o(d,this,h)}toHex(h=!0){return Et("isCompressed",h),Ut(this.toRawBytes(h))}}d.BASE=new d(t.Gx,t.Gy,e.ONE),d.ZERO=new d(e.ZERO,e.ONE,e.ZERO);let g=t.nBitLength,p=lr(d,t.endo?Math.ceil(g/2):g);return{CURVE:t,ProjectivePoint:d,normPrivateKeyToScalar:u,weierstrassEquation:i,isWithinCurveOrder:f}}function pu(r){let t=Ke(r);return It(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Ms(r){let t=pu(r),{Fp:e,n}=t,o=e.BYTES+1,s=2*e.BYTES+1;function i(A){return V(A,n)}function f(A){return ur(A,n)}let{ProjectivePoint:u,normPrivateKeyToScalar:a,weierstrassEquation:l,isWithinCurveOrder:c}=hu({...t,toBytes(A,T,x){let y=T.toAffine(),E=e.toBytes(y.x),S=Nt;return Et("isCompressed",x),x?S(Uint8Array.from([T.hasEvenY()?2:3]),E):S(Uint8Array.from([4]),E,e.toBytes(y.y))},fromBytes(A){let T=A.length,x=A[0],y=A.subarray(1);if(T===o&&(x===2||x===3)){let E=_t(y);if(!Me(E,ot,e.ORDER))throw new Error("Point is not on curve");let S=l(E),_;try{_=e.sqrt(S)}catch(F){let P=F instanceof Error?": "+F.message:"";throw new Error("Point is not on curve"+P)}let N=(_&ot)===ot;return(x&1)===1!==N&&(_=e.neg(_)),{x:E,y:_}}else if(T===s&&x===4){let E=e.fromBytes(y.subarray(0,e.BYTES)),S=e.fromBytes(y.subarray(e.BYTES,2*e.BYTES));return{x:E,y:S}}else{let E=o,S=s;throw new Error("invalid Point, expected length of "+E+", or uncompressed "+S+", got "+T)}}}),d=A=>Ut(Xt(A,t.nByteLength));function g(A){let T=n>>ot;return A>T}function p(A){return g(A)?i(-A):A}let m=(A,T,x)=>_t(A.slice(T,x));class h{constructor(T,x,y){this.r=T,this.s=x,this.recovery=y,this.assertValidity()}static fromCompact(T){let x=t.nByteLength;return T=X("compactSignature",T,x*2),new h(m(T,0,x),m(T,x,2*x))}static fromDER(T){let{r:x,s:y}=Ht.toSig(X("DER",T));return new h(x,y)}assertValidity(){pt("r",this.r,ot,n),pt("s",this.s,ot,n)}addRecoveryBit(T){return new h(this.r,this.s,T)}recoverPublicKey(T){let{r:x,s:y,recovery:E}=this,S=U(X("msgHash",T));if(E==null||![0,1,2,3].includes(E))throw new Error("recovery id invalid");let _=E===2||E===3?x+t.n:x;if(_>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let N=E&1?"03":"02",C=u.fromHex(N+d(_)),F=f(_),P=i(-S*F),q=i(y*F),G=u.BASE.multiplyAndAddUnsafe(C,P,q);if(!G)throw new Error("point at infinify");return G.assertValidity(),G}hasHighS(){return g(this.s)}normalizeS(){return this.hasHighS()?new h(this.r,i(-this.s),this.recovery):this}toDERRawBytes(){return se(this.toDERHex())}toDERHex(){return Ht.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return se(this.toCompactHex())}toCompactHex(){return d(this.r)+d(this.s)}}let w={isValidPrivateKey(A){try{return a(A),!0}catch{return!1}},normPrivateKeyToScalar:a,randomPrivateKey:()=>{let A=gn(t.n);return ds(t.randomBytes(A),t.n)},precompute(A=8,T=u.BASE){return T._setWindowSize(A),T.multiply(BigInt(3)),T}};function v(A,T=!0){return u.fromPrivateKey(A).toRawBytes(T)}function b(A){let T=jt(A),x=typeof A=="string",y=(T||x)&&A.length;return T?y===o||y===s:x?y===2*o||y===2*s:A instanceof u}function I(A,T,x=!0){if(b(A))throw new Error("first arg must be private key");if(!b(T))throw new Error("second arg must be public key");return u.fromHex(T).multiply(a(A)).toRawBytes(x)}let D=t.bits2int||function(A){if(A.length>8192)throw new Error("input is too large");let T=_t(A),x=A.length*8-t.nBitLength;return x>0?T>>BigInt(x):T},U=t.bits2int_modN||function(A){return i(D(A))},B=He(t.nBitLength);function R(A){return pt("num < 2^"+t.nBitLength,A,Kt,B),Xt(A,t.nByteLength)}function L(A,T,x=Z){if(["recovered","canonical"].some(rt=>rt in x))throw new Error("sign() legacy options not supported");let{hash:y,randomBytes:E}=t,{lowS:S,prehash:_,extraEntropy:N}=x;S==null&&(S=!0),A=X("msgHash",A),ks(x),_&&(A=X("prehashed msgHash",y(A)));let C=U(A),F=a(T),P=[R(F),R(C)];if(N!=null&&N!==!1){let rt=N===!0?E(e.BYTES):N;P.push(X("extraEntropy",rt))}let q=Nt(...P),G=C;function et(rt){let st=D(rt);if(!c(st))return;let it=f(st),dt=u.BASE.multiply(st).toAffine(),ft=i(dt.x);if(ft===Kt)return;let St=i(it*i(G+ft*F));if(St===Kt)return;let Bt=(dt.x===ft?0:2)|Number(dt.y&ot),De=St;return S&&g(St)&&(De=p(St),Bt^=1),new h(ft,De,Bt)}return{seed:q,k2sig:et}}let Z={lowS:t.lowS,prehash:!1},H={lowS:t.lowS,prehash:!1};function k(A,T,x=Z){let{seed:y,k2sig:E}=L(A,T,x),S=t;return dn(S.hash.outputLen,S.nByteLength,S.hmac)(y,E)}u.BASE._setWindowSize(8);function Q(A,T,x,y=H){let E=A;T=X("msgHash",T),x=X("publicKey",x);let{lowS:S,prehash:_,format:N}=y;if(ks(y),"strict"in y)throw new Error("options.strict was renamed to lowS");if(N!==void 0&&N!=="compact"&&N!=="der")throw new Error("format must be compact or der");let C=typeof E=="string"||jt(E),F=!C&&!N&&typeof E=="object"&&E!==null&&typeof E.r=="bigint"&&typeof E.s=="bigint";if(!C&&!F)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let P,q;try{if(F&&(P=new h(E.r,E.s)),C){try{N!=="compact"&&(P=h.fromDER(E))}catch(Bt){if(!(Bt instanceof Ht.Err))throw Bt}!P&&N!=="der"&&(P=h.fromCompact(E))}q=u.fromHex(x)}catch{return!1}if(!P||S&&P.hasHighS())return!1;_&&(T=t.hash(T));let{r:G,s:et}=P,rt=U(T),st=f(et),it=i(rt*st),dt=i(G*st),ft=u.BASE.multiplyAndAddUnsafe(q,it,dt)?.toAffine();return ft?i(ft.x)===G:!1}return{CURVE:t,getPublicKey:v,getSharedSecret:I,sign:k,verify:Q,ProjectivePoint:u,Signature:h,utils:w}}function mu(r){return{hash:r,hmac:(t,...e)=>to(r,t,on(...e)),randomBytes:or}}function Hs(r,t){let e=n=>Ms({...r,...mu(n)});return Object.freeze({...e(t),create:e})}var zs=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Ks=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),gu=BigInt(1),eo=BigInt(2),qs=(r,t)=>(r+t/eo)/t;function yu(r){let t=zs,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),f=BigInt(44),u=BigInt(88),a=r*r*r%t,l=a*a*r%t,c=$(l,e,t)*l%t,d=$(c,e,t)*l%t,g=$(d,eo,t)*a%t,p=$(g,o,t)*g%t,m=$(p,s,t)*p%t,h=$(m,f,t)*m%t,w=$(h,u,t)*h%t,v=$(w,f,t)*m%t,b=$(v,e,t)*l%t,I=$(b,i,t)*p%t,D=$(I,n,t)*a%t,U=$(D,eo,t);if(!ro.eql(ro.sqr(U),r))throw new Error("Cannot find square root");return U}var ro=Yt(zs,void 0,void 0,{sqrt:yu}),le=Hs({a:BigInt(0),b:BigInt(7),Fp:ro,n:Ks,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Ks,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-gu*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),f=qs(s*r,t),u=qs(-n*r,t),a=V(r-f*e-u*o,t),l=V(-f*n-u*s,t),c=a>i,d=l>i;if(c&&(a=t-a),d&&(l=t-l),a>i||l>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:c,k1:a,k2neg:d,k2:l}}}},Cs),Dh=BigInt(0);var Uh=le.ProjectivePoint;function yt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=at(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}function Vs(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Gs(r,t,e){let n=qe.digest(e instanceof Uint8Array?e:e.subarray());if(Vs(n))return n.then(({digest:o})=>le.verify(t,o,r)).catch(o=>{throw new je(String(o))});try{return le.verify(t,n.digest,r)}catch(o){throw new je(String(o))}}var Sr=class{type="secp256k1";raw;_key;constructor(t){this._key=js(t),this.raw=Zs(this._key)}toMultihash(){return Rt.digest(gr(this))}toCID(){return lt.createV1(114,this.toMultihash())}toString(){return W.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:xt(this.raw,t.raw)}verify(t,e){return Gs(this._key,e,t)}};function $s(r){return new Sr(r)}function Zs(r){return le.ProjectivePoint.fromHex(r).toRawBytes(!0)}function js(r){try{return le.ProjectivePoint.fromHex(r),r}catch(t){throw new Je(String(t))}}function Xs(r){let{Type:t,Data:e}=Ze.decode(r.digest),n=e??new Uint8Array;switch(t){case bt.Ed25519:return vs(n);case bt.secp256k1:return $s(n);default:throw new Ne}}function gr(r){return Ze.encode({Type:bt[r.type],Data:r.raw})}var Ys=Symbol.for("nodejs.util.inspect.custom"),bu=114,$e=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[Zr]=!0;toString(){return this.string==null&&(this.string=W.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return lt.createV1(bu,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return xt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return xt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Ys](){return`PeerId(${this.toString()})`}},Ir=class extends $e{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Br=class extends $e{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Lr=class extends $e{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},xu=2336,Tr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Rt.digest(kt(this.url))}[Ys](){return`PeerId(${this.url})`}[Zr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return lt.createV1(xu,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=tt(t)),t.toString()===this.toString())}};function Ws(r){if(Eu(r))return new Ir({multihash:r});if(wu(r))try{let t=Xs(r);if(t.type==="Ed25519")return new Br({multihash:r,publicKey:t});if(t.type==="secp256k1")return new Lr({multihash:r,publicKey:t})}catch{let e=tt(r.digest);return new Tr(new URL(e))}throw new tr("Supplied PeerID Multihash is invalid")}function wu(r){return r.code===Rt.code}function Eu(r){return r.code===qe.code}var Rr=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let s=0,i=0,f=this.peekChar();if(f===void 0)return;let u=f==="0",a=2**(8*o)-1;for(;;){let l=this.readAtomically(()=>{let c=this.readChar();if(c===void 0)return;let d=Number.parseInt(c,t);if(!Number.isNaN(d))return d});if(l===void 0)break;if(s*=t,s+=l,s>a||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&u&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2],e[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];e[o]=s>>8,e[o+1]=s&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[f]=t(s.subarray(0,i));return e.set(s.subarray(0,f),16-f),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Qs=45,vu=15,Se=new Rr;function no(r){if(!(r.length>vu))return Se.new(r).parseWith(()=>Se.readIPv4Addr())}function oo(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Qs))return Se.new(r).parseWith(()=>Se.readIPv6Addr())}function Dr(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Qs))return Se.new(r).parseWith(()=>Se.readIPAddr())}function Ur(r){return!!no(r)}function _r(r){return!!oo(r)}function Nr(r){return!!Dr(r)}var ti=ki(Js(),1),Au=["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"],Su=Au.map(r=>new ti.Netmask(r));function so(r){for(let t of Su)if(t.contains(r))return!0;return!1}function Iu(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function Bu(r){let t=r.split(":");if(t.length<2)return!1;let e=t[t.length-1].padStart(4,"0"),n=t[t.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(e.substring(0,2),16)}.${parseInt(e.substring(2),16)}`;return so(o)}function Lu(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function Tu(r){let t=r.split(":"),e=t[t.length-1];return so(e)}function Ru(r){return/^::$/.test(r)||/^::1$/.test(r)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(r)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(r)||/^ff([0-9a-fA-F]{2,2}):/i.test(r)}function io(r){return Ur(r)?so(r):Iu(r)?Bu(r):Lu(r)?Tu(r):_r(r)?Ru(r):void 0}var W0=parseInt("0xFFFF",16),Q0=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var ni=Ur,Pu=_r,ao=function(r){let t=0;if(r=r.toString().trim(),ni(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(Pu(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=ni(e[n]),i;s&&(i=ao(e[n]),e[n]=tt(i.slice(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,tt(i.slice(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let s=[n,1];for(n=9-e.length;n>0;n--)s.push("0");e.splice.apply(e,s)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){let s=parseInt(e[n],16);o[t++]=s>>8&255,o[t++]=s&255}return o}throw new Error("invalid ip address")},oi=function(r,t=0,e){t=~~t,e=e??r.length-t;let n=new DataView(r.buffer);if(e===4){let o=[];for(let s=0;s<e;s++)o.push(r[t+s]);return o.join(".")}if(e===16){let o=[];for(let s=0;s<e;s+=2)o.push(n.getUint16(t+s).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var Ie={},co={},Cu=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];Cu.forEach(r=>{let t=ku(...r);co[t.code]=t,Ie[t.name]=t});function ku(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function z(r){if(typeof r=="number"){if(co[r]!=null)return co[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Ie[r]!=null)return Ie[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Np=z("ip4"),Pp=z("ip6"),Op=z("ipcidr");function ho(r,t){switch(z(r).code){case 4:case 41:return Mu(t);case 42:return lo(t);case 43:return tt(t,"base10");case 6:case 273:case 33:case 132:return ai(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return lo(t);case 421:return zu(t);case 444:return ii(t);case 445:return ii(t);case 466:return qu(t);case 481:return globalThis.encodeURIComponent(lo(t));default:return tt(t,"base16")}}function po(r,t){switch(z(r).code){case 4:return si(t);case 41:return si(t);case 42:return fo(t);case 43:return kt(t,"base10");case 6:case 273:case 33:case 132:return mo(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return fo(t);case 421:return Hu(t);case 444:return Vu(t);case 445:return Gu(t);case 466:return Ku(t);case 481:return fo(globalThis.decodeURIComponent(t));default:return kt(t,"base16")}}var uo=Object.values(ze).map(r=>r.decoder),Fu=function(){let r=uo[0].or(uo[1]);return uo.slice(2).forEach(t=>r=r.or(t)),r}();function si(r){if(!Nr(r))throw new Error("invalid ip address");return ao(r)}function Mu(r){let t=oi(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!Nr(t))throw new Error("invalid ip address");return t}function mo(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function ai(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function fo(r){let t=kt(r),e=Uint8Array.from(Wt(t.length));return yt([e,t],e.length+t.length)}function lo(r){let t=Ot(r);if(r=r.slice(nt(t)),r.length!==t)throw new Error("inconsistent lengths");return tt(r)}function Hu(r){let t;r[0]==="Q"||r[0]==="1"?t=re(W.decode(`z${r}`)).bytes:t=lt.parse(r).multihash.bytes;let e=Uint8Array.from(Wt(t.length));return yt([e,t],e.length+t.length)}function Ku(r){let t=Fu.decode(r),e=Uint8Array.from(Wt(t.length));return yt([e,t],e.length+t.length)}function qu(r){let t=Ot(r),e=r.slice(nt(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+tt(e,"base64url")}function zu(r){let t=Ot(r),e=r.slice(nt(t));if(e.length!==t)throw new Error("inconsistent lengths");return tt(e,"base58btc")}function Vu(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=Tt.decode("b"+t[0]),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=mo(n);return yt([e,o],e.length+o.length)}function Gu(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=Tt.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=mo(n);return yt([e,o],e.length+o.length)}function ii(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=tt(t,"base32"),o=ai(e);return`${n}:${o}`}function ci(r){r=go(r);let t=[],e=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let s=0;s<o.length;s++){let i=o[s],f=z(i);if(f.size===0){t.push([f.code]),e.push([f.code]);continue}if(s++,s>=o.length)throw fi("invalid address: "+r);if(f.path===!0){n=go(o.slice(s).join("/")),t.push([f.code,po(f.code,n)]),e.push([f.code,n]);break}let u=po(f.code,o[s]);t.push([f.code,u]),e.push([f.code,ho(f.code,u)])}return{string:ui(e),bytes:bo(t),tuples:t,stringTuples:e,path:n}}function yo(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let s=Ot(r,o),i=nt(s),f=z(s),u=Zu(f,r.slice(o+i));if(u===0){t.push([s]),e.push([s]),o+=i;continue}let a=r.slice(o+i,o+i+u);if(o+=u+i,o>r.length)throw fi("Invalid address Uint8Array: "+tt(r,"base16"));t.push([s,a]);let l=ho(s,a);if(e.push([s,l]),f.path===!0){n=l;break}}return{bytes:Uint8Array.from(r),string:ui(e),tuples:t,stringTuples:e,path:n}}function ui(r){let t=[];return r.map(e=>{let n=z(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),go(t.join("/"))}function bo(r){return yt(r.map(t=>{let e=z(t[0]),n=Uint8Array.from(Wt(e.code));return t.length>1&&t[1]!=null&&(n=yt([n,t[1]])),n}))}function Zu(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=Ot(t instanceof Uint8Array?t:Uint8Array.from(t));return e+nt(e)}}function go(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}function fi(r){return new Error("Error parsing address: "+r)}var ju=Symbol.for("nodejs.util.inspect.custom"),wo=Symbol.for("@multiformats/js-multiaddr/multiaddr"),$u=[z("dns").code,z("dns4").code,z("dns6").code,z("dnsaddr").code],xo=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},Pr=class r{bytes;#e;#t;#r;#n;[wo]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=yo(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=ci(t)}else if(di(t))e=yo(t.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=e.bytes,this.#e=e.string,this.#t=e.tuples,this.#r=e.stringTuples,this.#n=e.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let t,e,n,o,s="",i=z("tcp"),f=z("udp"),u=z("ip4"),a=z("ip6"),l=z("dns6"),c=z("ip6zone");for(let[g,p]of this.stringTuples())g===c.code&&(s=`%${p??""}`),$u.includes(g)&&(e=i.name,o=443,n=`${p??""}${s}`,t=g===l.code?6:4),(g===i.code||g===f.code)&&(e=z(g).name,o=parseInt(p??"")),(g===u.code||g===a.code)&&(e=z(g).name,n=`${p??""}${s}`,t=g===a.code?6:4);if(t==null||e==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:t,host:n,transport:e,port:o}}protos(){return this.#t.map(([t])=>Object.assign({},z(t)))}protoCodes(){return this.#t.map(([t])=>t)}protoNames(){return this.#t.map(([t])=>z(t).name)}tuples(){return this.#t.map(([t,e])=>e==null?[t]:[t,e])}stringTuples(){return this.#r.map(([t,e])=>e==null?[t]:[t,e])}encapsulate(t){return t=new r(t),new r(this.toString()+t.toString())}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,o))}decapsulateCode(t){let e=this.tuples();for(let n=e.length-1;n>=0;n--)if(e[n][0]===t)return new r(bo(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===Ie.p2p.code&&t.push([n,o]),n===Ie["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?tt(W.decode(`z${n}`),"base58btc"):tt(lt.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return xt(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(s=>s.resolvable);if(e==null)return[this];let n=li.get(e.name);if(n==null)throw new xo(`no available resolver for ${e.name}`);return(await n(this,t)).map(s=>Be(s))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(t){let e=(t??this).protos();return!(e.length!==2||e[0].code!==4&&e[0].code!==41||e[1].code!==6&&e[1].code!==273)}[ju](){return`Multiaddr(${this.#e})`}};var li=new Map;function di(r){return!!r?.[wo]}function Be(r){return new Pr(r)}function Xu(r){return r[Symbol.asyncIterator]!=null}function Yu(r){if(Xu(r))return(async()=>{for await(let t of r)return t})();for(let t of r)return t}var Eo=Yu;var pi=Symbol.for("@achingbrain/uint8arraylist");function hi(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function Or(r){return!!r?.[pi]}var Le=class r{bufs;length;[pi]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(Or(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(Or(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=hi(this.bufs,t);return e.buf[e.index]}set(t,e){let n=hi(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(Or(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return yt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:yt(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],f=o,u=f+i.byteLength;if(o=u,t>=u)continue;let a=t>=f&&t<u,l=e>f&&e<=u;if(a&&l){if(t===f&&e===u){n.push(i);break}let c=t-f;n.push(i.subarray(c,c+(e-t)));break}if(a){if(t===0){n.push(i);continue}n.push(i.subarray(t-f));continue}if(l){if(e===u){n.push(i);break}n.push(i.subarray(0,e-f));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Or(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;let 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 c=0;c<s;c++)i[c]=-1;for(let c=0;c<o;c++)i[n[c]]=c;let f=i,u=this.byteLength-n.byteLength,a=n.byteLength-1,l;for(let c=e;c<=u;c+=l){l=0;for(let d=a;d>=0;d--){let g=this.get(c+d);if(n[d]!==g){l=Math.max(1,d-f[g]);break}}if(l===0)return c}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=at(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=Pt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=Pt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=Pt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=at(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=Pt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=Pt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=Pt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=Pt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=Pt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!xt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};function Cr(r){return r[Symbol.asyncIterator]!=null}var kr=r=>{let t=nt(r),e=at(t);return Wt(r,e),kr.bytes=t,e};kr.bytes=0;function Ye(r,t){t=t??{};let e=t.lengthEncoder??kr;function*n(o){let s=e(o.byteLength);s instanceof Uint8Array?yield s:yield*s,o instanceof Uint8Array?yield o:yield*o}return Cr(r)?async function*(){for await(let o of r)yield*n(o)}():function*(){for(let o of r)yield*n(o)}()}Ye.single=(r,t)=>{t=t??{};let e=t.lengthEncoder??kr;return new Le(e(r.byteLength),r)};var Fr=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Mr=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Hr=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"},We=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};var Wu=8,Qu=1024*1024*4,de;(function(r){r[r.LENGTH=0]="LENGTH",r[r.DATA=1]="DATA"})(de||(de={}));var vo=r=>{let t=Ot(r);return vo.bytes=nt(t),t};vo.bytes=0;function Te(r,t){let e=new Le,n=de.LENGTH,o=-1,s=t?.lengthDecoder??vo,i=t?.maxLengthLength??Wu,f=t?.maxDataLength??Qu;function*u(){for(;e.byteLength>0;){if(n===de.LENGTH)try{if(o=s(e),o<0)throw new Fr("Invalid message length");if(o>f)throw new Mr("Message length too long");let a=s.bytes;e.consume(a),t?.onLength!=null&&t.onLength(o),n=de.DATA}catch(a){if(a instanceof RangeError){if(e.byteLength>i)throw new Hr("Message length length too long");break}throw a}if(n===de.DATA){if(e.byteLength<o)break;let a=e.sublist(0,o);e.consume(o),t?.onData!=null&&t.onData(a),yield a,n=de.LENGTH}}}return Cr(r)?async function*(){for await(let a of r)e.append(a),yield*u();if(e.byteLength>0)throw new We("Unexpected end of input")}():function*(){for(let a of r)e.append(a),yield*u();if(e.byteLength>0)throw new We("Unexpected end of input")}()}Te.fromReader=(r,t)=>{let e=1,n=async function*(){for(;;)try{let{done:s,value:i}=await r.next(e);if(s===!0)return;i!=null&&(yield i)}catch(s){if(s.code==="ERR_UNDER_READ")return{done:!0,value:null};throw s}finally{e=1}}();return Te(n,{...t??{},onLength:s=>{e=s}})};function tf(r){let[t,e]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>t.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:t.next(),[e](){return this}}}var mi=tf;function ef(r){return r[Symbol.asyncIterator]!=null}function rf(r,t){let e=0;if(ef(r))return async function*(){for await(let u of r)yield t(u,e++)}();let n=mi(r),{value:o,done:s}=n.next();if(s===!0)return function*(){}();let i=t(o,e++);if(typeof i.then=="function")return async function*(){yield await i;for await(let u of n)yield t(u,e++)}();let f=t;return function*(){yield i;for(let u of n)yield f(u,e++)}()}var gi=rf;function qt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Kr=globalThis.CustomEvent??Event;async function*Ao(r,t={}){let e=t.concurrency??1/0;e<1&&(e=1/0);let n=t.ordered==null?!1:t.ordered,o=new EventTarget,s=[],i=qt(),f=qt(),u=!1,a,l=!1;o.addEventListener("task-complete",()=>{f.resolve()}),Promise.resolve().then(async()=>{try{for await(let p of r){if(s.length===e&&(i=qt(),await i.promise),l)break;let m={done:!1};s.push(m),p().then(h=>{m.done=!0,m.ok=!0,m.value=h,o.dispatchEvent(new Kr("task-complete"))},h=>{m.done=!0,m.err=h,o.dispatchEvent(new Kr("task-complete"))})}u=!0,o.dispatchEvent(new Kr("task-complete"))}catch(p){a=p,o.dispatchEvent(new Kr("task-complete"))}});function c(){return n?s[0]?.done:!!s.find(p=>p.done)}function*d(){for(;s.length>0&&s[0].done;){let p=s[0];if(s.shift(),p.ok)yield p.value;else throw l=!0,i.resolve(),p.err;i.resolve()}}function*g(){for(;c();)for(let p=0;p<s.length;p++)if(s[p].done){let m=s[p];if(s.splice(p,1),p--,m.ok)yield m.value;else throw l=!0,i.resolve(),m.err;i.resolve()}}for(;;){if(c()||(f=qt(),await f.promise),a!=null)throw a;if(n?yield*d():yield*g(),u&&s.length===0)break}}var qr=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||t-1&t)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},Re=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new qr(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new qr(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var So=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function zr(r={}){return nf(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function nf(r,t){t=t??{};let e=t.onEnd,n=new Re,o,s,i,f=qt(),u=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((h,w)=>{s=v=>{s=null,n.push(v);try{h(r(n))}catch(b){w(b)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{f.resolve(),f=qt()})}},a=h=>s!=null?s(h):(n.push(h),o),l=h=>(n=new Re,s!=null?s({error:h}):(n.push({error:h}),o)),c=h=>{if(i)return o;if(t?.objectMode!==!0&&h?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return a({done:!1,value:h})},d=h=>i?o:(i=!0,h!=null?l(h):a({done:!0})),g=()=>(n=new Re,d(),{done:!0}),p=h=>(d(h),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:u,return:g,throw:p,push:c,end:d,get readableLength(){return n.size},onEmpty:async h=>{let w=h?.signal;if(w?.throwIfAborted(),n.isEmpty())return;let v,b;w!=null&&(v=new Promise((I,D)=>{b=()=>{D(new So)},w.addEventListener("abort",b)}));try{await Promise.race([f.promise,v])}finally{b!=null&&w!=null&&w?.removeEventListener("abort",b)}}},e==null)return o;let m=o;return o={[Symbol.asyncIterator](){return this},next(){return m.next()},throw(h){return m.throw(h),e!=null&&(e(h),e=void 0),{done:!0}},return(){return m.return(),e!=null&&(e(),e=void 0),{done:!0}},push:c,end(h){return m.end(h),e!=null&&(e(h),e=void 0),o},get readableLength(){return m.readableLength},onEmpty:h=>m.onEmpty(h)},o}function of(r){return r[Symbol.asyncIterator]!=null}function sf(...r){let t=[];for(let e of r)of(e)||t.push(e);return t.length===r.length?function*(){for(let e of t)yield*e}():async function*(){let e=zr({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let o of n)e.push(o)})),e.end()}catch(n){e.end(n)}}),yield*e}()}var yi=sf;function Bo(r,...t){if(r==null)throw new Error("Empty pipeline");if(Io(r)){let n=r;r=()=>n.source}else if(xi(r)||bi(r)){let n=r;r=()=>n}let e=[r,...t];if(e.length>1&&Io(e[e.length-1])&&(e[e.length-1]=e[e.length-1].sink),e.length>2)for(let n=1;n<e.length-1;n++)Io(e[n])&&(e[n]=cf(e[n]));return af(...e)}var af=(...r)=>{let t;for(;r.length>0;)t=r.shift()(t);return t},bi=r=>r?.[Symbol.asyncIterator]!=null,xi=r=>r?.[Symbol.iterator]!=null,Io=r=>r==null?!1:r.sink!=null&&r.source!=null,cf=r=>t=>{let e=r.sink(t);if(e?.then!=null){let n=zr({objectMode:!0});e.then(()=>{n.end()},i=>{n.end(i)});let o,s=r.source;if(bi(s))o=async function*(){yield*s,n.end()};else if(xi(s))o=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return yi(n,o())}return r.source};var wi="libp2p",Ei="autonat",vi="1.0.0";var M;(function(r){let t;(function(a){a.DIAL="DIAL",a.DIAL_RESPONSE="DIAL_RESPONSE"})(t=r.MessageType||(r.MessageType={}));let e;(function(a){a[a.DIAL=0]="DIAL",a[a.DIAL_RESPONSE=1]="DIAL_RESPONSE"})(e||(e={})),function(a){a.codec=()=>Ae(e)}(t=r.MessageType||(r.MessageType={}));let n;(function(a){a.OK="OK",a.E_DIAL_ERROR="E_DIAL_ERROR",a.E_DIAL_REFUSED="E_DIAL_REFUSED",a.E_BAD_REQUEST="E_BAD_REQUEST",a.E_INTERNAL_ERROR="E_INTERNAL_ERROR"})(n=r.ResponseStatus||(r.ResponseStatus={}));let o;(function(a){a[a.OK=0]="OK",a[a.E_DIAL_ERROR=100]="E_DIAL_ERROR",a[a.E_DIAL_REFUSED=101]="E_DIAL_REFUSED",a[a.E_BAD_REQUEST=200]="E_BAD_REQUEST",a[a.E_INTERNAL_ERROR=300]="E_INTERNAL_ERROR"})(o||(o={})),function(a){a.codec=()=>Ae(o)}(n=r.ResponseStatus||(r.ResponseStatus={}));let s;(function(a){let l;a.codec=()=>(l==null&&(l=Mt((c,d,g={})=>{if(g.lengthDelimited!==!1&&d.fork(),c.id!=null&&(d.uint32(10),d.bytes(c.id)),c.addrs!=null)for(let p of c.addrs)d.uint32(18),d.bytes(p);g.lengthDelimited!==!1&&d.ldelim()},(c,d,g={})=>{let p={addrs:[]},m=d==null?c.len:c.pos+d;for(;c.pos<m;){let h=c.uint32();switch(h>>>3){case 1:{p.id=c.bytes();break}case 2:{if(g.limits?.addrs!=null&&p.addrs.length===g.limits.addrs)throw new vr('Decode error - map field "addrs" had too many elements');p.addrs.push(c.bytes());break}default:{c.skipType(h&7);break}}}return p})),l),a.encode=c=>Ft(c,a.codec()),a.decode=(c,d)=>Ct(c,a.codec(),d)})(s=r.PeerInfo||(r.PeerInfo={}));let i;(function(a){let l;a.codec=()=>(l==null&&(l=Mt((c,d,g={})=>{g.lengthDelimited!==!1&&d.fork(),c.peer!=null&&(d.uint32(10),r.PeerInfo.codec().encode(c.peer,d)),g.lengthDelimited!==!1&&d.ldelim()},(c,d,g={})=>{let p={},m=d==null?c.len:c.pos+d;for(;c.pos<m;){let h=c.uint32();switch(h>>>3){case 1:{p.peer=r.PeerInfo.codec().decode(c,c.uint32(),{limits:g.limits?.peer});break}default:{c.skipType(h&7);break}}}return p})),l),a.encode=c=>Ft(c,a.codec()),a.decode=(c,d)=>Ct(c,a.codec(),d)})(i=r.Dial||(r.Dial={}));let f;(function(a){let l;a.codec=()=>(l==null&&(l=Mt((c,d,g={})=>{g.lengthDelimited!==!1&&d.fork(),c.status!=null&&(d.uint32(8),r.ResponseStatus.codec().encode(c.status,d)),c.statusText!=null&&(d.uint32(18),d.string(c.statusText)),c.addr!=null&&(d.uint32(26),d.bytes(c.addr)),g.lengthDelimited!==!1&&d.ldelim()},(c,d,g={})=>{let p={},m=d==null?c.len:c.pos+d;for(;c.pos<m;){let h=c.uint32();switch(h>>>3){case 1:{p.status=r.ResponseStatus.codec().decode(c);break}case 2:{p.statusText=c.string();break}case 3:{p.addr=c.bytes();break}default:{c.skipType(h&7);break}}}return p})),l),a.encode=c=>Ft(c,a.codec()),a.decode=(c,d)=>Ct(c,a.codec(),d)})(f=r.DialResponse||(r.DialResponse={}));let u;r.codec=()=>(u==null&&(u=Mt((a,l,c={})=>{c.lengthDelimited!==!1&&l.fork(),a.type!=null&&(l.uint32(8),r.MessageType.codec().encode(a.type,l)),a.dial!=null&&(l.uint32(18),r.Dial.codec().encode(a.dial,l)),a.dialResponse!=null&&(l.uint32(26),r.DialResponse.codec().encode(a.dialResponse,l)),c.lengthDelimited!==!1&&l.ldelim()},(a,l,c={})=>{let d={},g=l==null?a.len:a.pos+l;for(;a.pos<g;){let p=a.uint32();switch(p>>>3){case 1:{d.type=r.MessageType.codec().decode(a);break}case 2:{d.dial=r.Dial.codec().decode(a,a.uint32(),{limits:c.limits?.dial});break}case 3:{d.dialResponse=r.DialResponse.codec().decode(a,a.uint32(),{limits:c.limits?.dialResponse});break}default:{a.skipType(p&7);break}}}return d})),u),r.encode=a=>Ft(a,r.codec()),r.decode=(a,l)=>Ct(a,r.codec(),l)})(M||(M={}));var Lo=4,Vr=class{components;startupDelay;refreshInterval;protocol;timeout;maxInboundStreams;maxOutboundStreams;verifyAddressTimeout;started;log;constructor(t,e){this.components=t,this.log=t.logger.forComponent("libp2p:autonat"),this.started=!1,this.protocol=`/${e.protocolPrefix??wi}/${Ei}/${vi}`,this.timeout=e.timeout??3e4,this.maxInboundStreams=e.maxInboundStreams??1,this.maxOutboundStreams=e.maxOutboundStreams??1,this.startupDelay=e.startupDelay??5e3,this.refreshInterval=e.refreshInterval??6e4,this._verifyExternalAddresses=this._verifyExternalAddresses.bind(this)}[Symbol.toStringTag]="@libp2p/autonat";[Co]=["@libp2p/autonat"];isStarted(){return this.started}async start(){this.started||(await this.components.registrar.handle(this.protocol,t=>{this.handleIncomingAutonatStream(t).catch(e=>{this.log.error("error handling incoming autonat stream",e)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this.verifyAddressTimeout=setTimeout(this._verifyExternalAddresses,this.startupDelay),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.protocol),clearTimeout(this.verifyAddressTimeout),this.started=!1}async handleIncomingAutonatStream(t){let e=AbortSignal.timeout(this.timeout),n=()=>{t.stream.abort(new Ue)};e.addEventListener("abort",n,{once:!0}),jr(1/0,e);try{let o=this;await Bo(t.stream,s=>Te(s),async function*(s){let i=await Eo(s);if(i==null){o.log("no message received"),yield M.encode({type:M.MessageType.DIAL_RESPONSE,dialResponse:{status:M.ResponseStatus.E_BAD_REQUEST,statusText:"No message was sent"}});return}let f;try{f=M.decode(i)}catch(u){o.log.error("could not decode message",u),yield M.encode({type:M.MessageType.DIAL_RESPONSE,dialResponse:{status:M.ResponseStatus.E_BAD_REQUEST,statusText:"Could not decode message"}});return}yield M.encode(await o.handleAutonatMessage(f,t.connection,{signal:e}))},s=>Ye(s),t.stream)}catch(o){this.log.error("error handling incoming autonat stream",o)}finally{e.removeEventListener("abort",n)}}_verifyExternalAddresses(){this.verifyExternalAddresses().catch(t=>{this.log.error("error verifying external address",t)})}async handleAutonatMessage(t,e,n){let o=this.components.addressManager.getAddresses().map(c=>c.toOptions().host),s=t.dial;if(s==null)return this.log.error("dial was missing from message"),{type:M.MessageType.DIAL_RESPONSE,dialResponse:{status:M.ResponseStatus.E_BAD_REQUEST,statusText:"No Dial message found in message"}};let i,f=s.peer;if(f?.id==null)return this.log.error("PeerId missing from message"),{type:M.MessageType.DIAL_RESPONSE,dialResponse:{status:M.ResponseStatus.E_BAD_REQUEST,statusText:"missing peer info"}};try{let c=re(f.id);i=Ws(c)}catch(c){return this.log.error("invalid PeerId",c),{type:M.MessageType.DIAL_RESPONSE,dialResponse:{status:M.ResponseStatus.E_BAD_REQUEST,statusText:"bad peer id"}}}if(this.log("incoming request from %p",i),!e.remotePeer.equals(i))return this.log("target peer %p did not equal sending peer %p",i,e.remotePeer),{type:M.MessageType.DIAL_RESPONSE,dialResponse:{status:M.ResponseStatus.E_BAD_REQUEST,statusText:"peer id mismatch"}};let u=f.addrs.map(c=>Be(c)).filter(c=>{let d=c.toOptions().host===e.remoteAddr.toOptions().host;return this.log.trace("request to dial %a was sent from %a is same host %s",c,e.remoteAddr,d),d}).filter(c=>{let d=c.toOptions().host,g=!(io(d)??!1);return this.log.trace("host %s was public %s",d,g),g}).filter(c=>{let d=c.toOptions().host,g=!o.includes(d);return this.log.trace("host %s was not our host %s",d,g),g}).filter(c=>{let d=!!this.components.transportManager.dialTransportForMultiaddr(c);return this.log.trace("transport for %a is supported %s",c,d),d}).map(c=>(c.getPeerId()==null&&(c=c.encapsulate(`/p2p/${i.toString()}`)),c));if(u.length===0)return this.log("no valid multiaddrs for %p in message",i),{type:M.MessageType.DIAL_RESPONSE,dialResponse:{status:M.ResponseStatus.E_DIAL_REFUSED,statusText:"no dialable addresses"}};this.log("dial multiaddrs %s for peer %p",u.map(c=>c.toString()).join(", "),i);let a="",l=u[0];for await(let c of u){let d;l=c;try{if(d=await this.components.connectionManager.openConnection(c,n),!d.remoteAddr.equals(c))throw this.log.error("tried to dial %a but dialed %a",c,d.remoteAddr),new Error("Unexpected remote address");return this.log("Success %p",i),{type:M.MessageType.DIAL_RESPONSE,dialResponse:{status:M.ResponseStatus.OK,addr:d.remoteAddr.decapsulateCode(z("p2p").code).bytes}}}catch(g){this.log("could not dial %p",i,g),a=g.message}finally{d!=null&&await d.close()}}return{type:M.MessageType.DIAL_RESPONSE,dialResponse:{status:M.ResponseStatus.E_DIAL_ERROR,statusText:a,addr:l.bytes}}}async verifyExternalAddresses(){if(clearTimeout(this.verifyAddressTimeout),!this.isStarted())return;let t=this.components.addressManager,e=t.getObservedAddrs().filter(s=>{let i=s.toOptions();return!(io(i.host)??!1)});if(e.length===0){this.log("no public addresses found, not requesting verification"),this.verifyAddressTimeout=setTimeout(this._verifyExternalAddresses,this.refreshInterval);return}let n=AbortSignal.timeout(this.timeout);jr(1/0,n);let o=this;try{this.log("verify multiaddrs %s",e.map(a=>a.toString()).join(", "));let s=M.encode({type:M.MessageType.DIAL,dial:{peer:{id:this.components.peerId.toMultihash().bytes,addrs:e.map(a=>a.bytes)}}}),i={},f=[],u=async a=>{let l=()=>{};try{this.log("asking %p to verify multiaddr",a.id);let c=await o.components.connectionManager.openConnection(a.id,{signal:n}),d=await c.newStream(this.protocol,{signal:n});l=()=>{d.abort(new Ue)},n.addEventListener("abort",l,{once:!0});let g=await Bo([s],m=>Ye(m),d,m=>Te(m),async m=>Eo(m));if(g==null){this.log("no response received from %p",c.remotePeer);return}let p=M.decode(g);if(p.type!==M.MessageType.DIAL_RESPONSE||p.dialResponse==null){this.log("invalid autonat response from %p",c.remotePeer);return}if(p.dialResponse.status===M.ResponseStatus.OK){let m=c.remoteAddr.toOptions(),h;if(m.family===4)h=m.host.split(".")[0];else if(m.family===6)h=m.host.split(":")[0];else{this.log('remote address "%s" was not IP4 or IP6?',m.host);return}if(f.includes(h)){this.log("already have response from network segment %d - %s",h,m.host);return}f.push(h)}return p.dialResponse}catch(c){this.log.error("error asking remote to verify multiaddr",c)}finally{n.removeEventListener("abort",l)}};for await(let a of Ao(gi(this.components.randomWalk.walk({signal:n}),l=>async()=>u(l)),{concurrency:Lo}))try{if(a==null)continue;let l=a.addr==null?e[0]:Be(a.addr);if(this.log("autonat response for %a is %s",l,a.status),a.status===M.ResponseStatus.E_BAD_REQUEST||a.status===M.ResponseStatus.E_DIAL_REFUSED||a.addr==null&&e.length>1)continue;if(!e.some(d=>d.equals(l))){this.log("peer reported %a as %s but it was not in our observed address list",l,a.status);continue}let c=l.toString();if(i[c]==null&&(i[c]={success:0,failure:0}),a.status===M.ResponseStatus.OK?i[c].success++:a.status===M.ResponseStatus.E_DIAL_ERROR&&i[c].failure++,i[c].success===Lo){this.log("%a is externally dialable",l),t.confirmObservedAddr(l);return}if(i[c].failure===Lo){this.log("%a is not externally dialable",l),t.removeObservedAddr(l);return}}catch(l){this.log.error("could not verify external address",l)}}finally{this.verifyAddressTimeout=setTimeout(this._verifyExternalAddresses,this.refreshInterval)}}};function pf(r={}){return t=>new Vr(t,r)}return Fi(mf);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/hashes/esm/utils.js:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/autonat",
3
- "version": "2.0.12-4761dd701",
3
+ "version": "2.0.12-6ab85ea68",
4
4
  "description": "Implementation of Autonat Protocol",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/protocol-autonat#readme",
@@ -52,28 +52,28 @@
52
52
  "doc-check": "aegir doc-check"
53
53
  },
54
54
  "dependencies": {
55
- "@libp2p/interface": "2.2.1-4761dd701",
56
- "@libp2p/interface-internal": "2.1.1-4761dd701",
57
- "@libp2p/peer-id": "5.0.8-4761dd701",
58
- "@libp2p/utils": "6.2.1-4761dd701",
59
- "@multiformats/multiaddr": "^12.2.3",
55
+ "@libp2p/interface": "2.2.1-6ab85ea68",
56
+ "@libp2p/interface-internal": "2.1.1-6ab85ea68",
57
+ "@libp2p/peer-id": "5.0.8-6ab85ea68",
58
+ "@libp2p/utils": "6.2.1-6ab85ea68",
59
+ "@multiformats/multiaddr": "^12.3.3",
60
60
  "it-first": "^3.0.6",
61
- "it-length-prefixed": "^9.0.4",
62
- "it-map": "^3.1.0",
63
- "it-parallel": "^3.0.7",
61
+ "it-length-prefixed": "^9.1.0",
62
+ "it-map": "^3.1.1",
63
+ "it-parallel": "^3.0.8",
64
64
  "it-pipe": "^3.0.1",
65
- "multiformats": "^13.2.2",
66
- "protons-runtime": "^5.4.0",
65
+ "multiformats": "^13.3.1",
66
+ "protons-runtime": "^5.5.0",
67
67
  "uint8arraylist": "^2.4.8"
68
68
  },
69
69
  "devDependencies": {
70
- "@libp2p/crypto": "5.0.7-4761dd701",
71
- "@libp2p/logger": "5.1.4-4761dd701",
72
- "aegir": "^44.0.1",
70
+ "@libp2p/crypto": "5.0.7-6ab85ea68",
71
+ "@libp2p/logger": "5.1.4-6ab85ea68",
72
+ "aegir": "^45.0.5",
73
73
  "it-all": "^3.0.6",
74
74
  "it-pushable": "^3.2.3",
75
- "protons": "^7.5.0",
76
- "sinon": "^18.0.0",
75
+ "protons": "^7.6.0",
76
+ "sinon": "^19.0.2",
77
77
  "sinon-ts": "^2.0.0"
78
78
  },
79
79
  "sideEffects": false
package/LICENSE DELETED
@@ -1,4 +0,0 @@
1
- This project is dual licensed under MIT and Apache-2.0.
2
-
3
- MIT: https://www.opensource.org/licenses/mit
4
- Apache-2.0: https://www.apache.org/licenses/license-2.0