@libp2p/identify 3.0.29-f1de46607 → 3.0.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PIdentify = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PIdentify=(()=>{var Cc=Object.create;var qr=Object.defineProperty;var _c=Object.getOwnPropertyDescriptor;var Tc=Object.getOwnPropertyNames;var Lc=Object.getPrototypeOf,Dc=Object.prototype.hasOwnProperty;var Rc=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),vt=(r,t)=>{for(var e in t)qr(r,e,{get:t[e],enumerable:!0})},zs=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Tc(t))!Dc.call(r,o)&&o!==e&&qr(r,o,{get:()=>t[o],enumerable:!(n=_c(t,o))||n.enumerable});return r};var Uc=(r,t,e)=>(e=r!=null?Cc(Lc(r)):{},zs(t||!r||!r.__esModule?qr(e,"default",{value:r,enumerable:!0}):e,r)),Oc=r=>zs(qr({},"__esModule",{value:!0}),r);var lc=Rc(kr=>{(function(){var r,t,e,n,o,s,i,c;c=function(a){var u,f,l,d;return u=(a&255<<24)>>>24,f=(a&255<<16)>>>16,l=(a&65280)>>>8,d=a&255,[u,f,l,d].join(".")},i=function(a){var u,f,l,d,b,m;for(u=[],l=d=0;d<=3&&a.length!==0;l=++d){if(l>0){if(a[0]!==".")throw new Error("Invalid IP");a=a.substring(1)}m=t(a),b=m[0],f=m[1],a=a.substring(f),u.push(b)}if(a.length!==0)throw new Error("Invalid IP");switch(u.length){case 1:if(u[0]>4294967295)throw new Error("Invalid IP");return u[0]>>>0;case 2:if(u[0]>255||u[1]>16777215)throw new Error("Invalid IP");return(u[0]<<24|u[1])>>>0;case 3:if(u[0]>255||u[1]>255||u[2]>65535)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2])>>>0;case 4:if(u[0]>255||u[1]>255||u[2]>255||u[3]>255)throw new Error("Invalid IP");return(u[0]<<24|u[1]<<16|u[2]<<8|u[3])>>>0;default:throw new Error("Invalid IP")}},e=function(a){return a.charCodeAt(0)},n=e("0"),s=e("a"),o=e("A"),t=function(a){var u,f,l,d,b;for(d=0,u=10,f="9",l=0,a.length>1&&a[l]==="0"&&(a[l+1]==="x"||a[l+1]==="X"?(l+=2,u=16):"0"<=a[l+1]&&a[l+1]<="9"&&(l++,u=8,f="7")),b=l;l<a.length;){if("0"<=a[l]&&a[l]<=f)d=d*u+(e(a[l])-n)>>>0;else if(u===16)if("a"<=a[l]&&a[l]<="f")d=d*u+(10+e(a[l])-s)>>>0;else if("A"<=a[l]&&a[l]<="F")d=d*u+(10+e(a[l])-o)>>>0;else break;else break;if(d>4294967295)throw new Error("too large");l++}if(l===b)throw new Error("empty octet");return[d,l]},r=function(){function a(u,f){var l,d,b,m;if(typeof u!="string")throw new Error("Missing `net' parameter");if(f||(m=u.split("/",2),u=m[0],f=m[1]),f||(f=32),typeof f=="string"&&f.indexOf(".")>-1){try{this.maskLong=i(f)}catch(g){throw l=g,new Error("Invalid mask: "+f)}for(d=b=32;b>=0;d=--b)if(this.maskLong===4294967295<<32-d>>>0){this.bitmask=d;break}}else if(f||f===0)this.bitmask=parseInt(f,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(u)&this.maskLong)>>>0}catch(g){throw l=g,new Error("Invalid net address: "+u)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+f);this.size=Math.pow(2,32-this.bitmask),this.base=c(this.netLong),this.mask=c(this.maskLong),this.hostmask=c(~this.maskLong),this.first=this.bitmask<=30?c(this.netLong+1):this.base,this.last=this.bitmask<=30?c(this.netLong+this.size-2):c(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?c(this.netLong+this.size-1):void 0}return a.prototype.contains=function(u){return typeof u=="string"&&(u.indexOf("/")>0||u.split(".").length!==4)&&(u=new a(u)),u instanceof a?this.contains(u.base)&&this.contains(u.broadcast||u.last):(i(u)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},a.prototype.next=function(u){return u==null&&(u=1),new a(c(this.netLong+this.size*u),this.mask)},a.prototype.forEach=function(u){var f,l,d;for(d=i(this.first),l=i(this.last),f=0;d<=l;)u(c(d),d,f),f++,d++},a.prototype.toString=function(){return this.base+"/"+this.bitmask},a}(),kr.ip2long=i,kr.long2ip=c,kr.Netmask=r}).call(kr)});var Yl={};vt(Yl,{identify:()=>jl,identifyPush:()=>Wl});var Vn=Symbol.for("@libp2p/peer-id");var ct=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Fe=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Hr=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},zr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}},Gr=class extends Error{static name="UnsupportedProtocolError";constructor(t="Unsupported protocol error"){super(t),this.name="UnsupportedProtocolError"}},Ut=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var Ee=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var $r=Symbol.for("@libp2p/service-capabilities"),td=Symbol.for("@libp2p/service-dependencies");var $n={};vt($n,{base58btc:()=>Y,base58flickr:()=>Vc});var Sd=new Uint8Array(0);function Gs(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 Xt(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 $s(r){return new TextEncoder().encode(r)}function Zs(r){return new TextDecoder().decode(r)}function Nc(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 c=r.length,a=r.charAt(0),u=Math.log(c)/Math.log(256),f=Math.log(256)/Math.log(c);function l(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var g=0,h=0,w=0,v=m.length;w!==v&&m[w]===0;)w++,g++;for(var y=(v-w)*f+1>>>0,I=new Uint8Array(y);w!==v;){for(var D=m[w],L=0,P=y-1;(D!==0||L<h)&&P!==-1;P--,L++)D+=256*I[P]>>>0,I[P]=D%c>>>0,D=D/c>>>0;if(D!==0)throw new Error("Non-zero carry");h=L,w++}for(var C=y-h;C!==y&&I[C]===0;)C++;for(var _=a.repeat(g);C<y;++C)_+=r.charAt(I[C]);return _}function d(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var g=0;if(m[g]!==" "){for(var h=0,w=0;m[g]===a;)h++,g++;for(var v=(m.length-g)*u+1>>>0,y=new Uint8Array(v);m[g];){var I=e[m.charCodeAt(g)];if(I===255)return;for(var D=0,L=v-1;(I!==0||D<w)&&L!==-1;L--,D++)I+=c*y[L]>>>0,y[L]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");w=D,g++}if(m[g]!==" "){for(var P=v-w;P!==v&&y[P]===0;)P++;for(var C=new Uint8Array(h+(v-P)),_=h;P!==v;)C[_++]=y[P++];return C}}}function b(m){var g=d(m);if(g)return g;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:d,decode:b}}var Kc=Nc,kc=Kc,Ws=kc;var qn=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")}},Hn=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 Ys(this,t)}},zn=class{decoders;constructor(t){this.decoders=t}or(t){return Ys(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 Ys(r,t){return new zn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Gn=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 qn(t,e,n),this.decoder=new Hn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ve({name:r,prefix:t,encode:e,decode:n}){return new Gn(r,t,e,n)}function fe({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Ws(e,r);return Ve({prefix:t,name:r,encode:n,decode:s=>Xt(o(s))})}function Mc(r,t,e,n){let o={};for(let f=0;f<t.length;++f)o[t[f]]=f;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*e/8|0),c=0,a=0,u=0;for(let f=0;f<s;++f){let l=o[r[f]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|l,c+=e,c>=8&&(c-=8,i[u++]=255&a>>c)}if(c>=e||(255&a<<8-c)!==0)throw new SyntaxError("Unexpected end of data");return i}function Fc(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,c=0;for(let a=0;a<r.length;++a)for(c=c<<8|r[a],i+=8;i>e;)i-=e,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function et({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return Ve({prefix:t,name:r,encode(o){return Fc(o,n,e)},decode(o){return Mc(o,n,e,r)}})}var Y=fe({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Vc=fe({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Zn={};vt(Zn,{base32:()=>Jt,base32hex:()=>Gc,base32hexpad:()=>Zc,base32hexpadupper:()=>jc,base32hexupper:()=>$c,base32pad:()=>Hc,base32padupper:()=>zc,base32upper:()=>qc,base32z:()=>Wc});var Jt=et({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),qc=et({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Hc=et({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),zc=et({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Gc=et({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),$c=et({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Zc=et({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),jc=et({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Wc=et({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var jn={};vt(jn,{base36:()=>ur,base36upper:()=>Yc});var ur=fe({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Yc=fe({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Xc=Qs,Xs=128,Jc=127,Qc=~Jc,tu=Math.pow(2,31);function Qs(r,t,e){t=t||[],e=e||0;for(var n=e;r>=tu;)t[e++]=r&255|Xs,r/=128;for(;r&Qc;)t[e++]=r&255|Xs,r>>>=7;return t[e]=r|0,Qs.bytes=e-n+1,t}var eu=Wn,ru=128,Js=127;function Wn(r,n){var e=0,n=n||0,o=0,s=n,i,c=r.length;do{if(s>=c)throw Wn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&Js)<<o:(i&Js)*Math.pow(2,o),o+=7}while(i>=ru);return Wn.bytes=s-n,e}var nu=Math.pow(2,7),ou=Math.pow(2,14),su=Math.pow(2,21),iu=Math.pow(2,28),au=Math.pow(2,35),cu=Math.pow(2,42),uu=Math.pow(2,49),fu=Math.pow(2,56),lu=Math.pow(2,63),du=function(r){return r<nu?1:r<ou?2:r<su?3:r<iu?4:r<au?5:r<cu?6:r<uu?7:r<fu?8:r<lu?9:10},hu={encode:Xc,decode:eu,encodingLength:du},pu=hu,fr=pu;function lr(r,t=0){return[fr.decode(r,t),fr.decode.bytes]}function qe(r,t,e=0){return fr.encode(r,t,e),t}function He(r){return fr.encodingLength(r)}function Ot(r,t){let e=t.byteLength,n=He(r),o=n+He(e),s=new Uint8Array(o+e);return qe(r,s,0),qe(e,s,n),s.set(t,o),new ze(r,e,t,s)}function Ae(r){let t=Xt(r),[e,n]=lr(t),[o,s]=lr(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ze(e,o,i,t)}function ti(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Gs(r.bytes,e.bytes)}}var ze=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function ei(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return yu(e,Yn(r),t??Y.encoder);default:return gu(e,Yn(r),t??Jt.encoder)}}var ri=new WeakMap;function Yn(r){let t=ri.get(r);if(t==null){let e=new Map;return ri.set(r,e),e}return t}var it=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!==dr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==bu)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=Ot(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&&ti(t.multihash,n.multihash)}toString(t){return ei(this,t)}toJSON(){return{"/":ei(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??ni(n,o,s.bytes))}else if(e[xu]===!0){let{version:n,multihash:o,code:s}=e,i=Ae(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!==dr)throw new Error(`Version 0 CID must use dag-pb (code: ${dr}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=ni(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,dr,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=Xt(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 ze(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[l,d]=lr(t.subarray(e));return e+=d,l},o=n(),s=dr;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,c=n(),a=n(),u=e+a,f=u-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:f,size:u}}static parse(t,e){let[n,o]=mu(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 Yn(s).set(n,t),s}};function mu(r,t){switch(r[0]){case"Q":{let e=t??Y;return[Y.prefix,e.decode(`${Y.prefix}${r}`)]}case Y.prefix:{let e=t??Y;return[Y.prefix,e.decode(r)]}case Jt.prefix:{let e=t??Jt;return[Jt.prefix,e.decode(r)]}case ur.prefix:{let e=t??ur;return[ur.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 yu(r,t,e){let{prefix:n}=e;if(n!==Y.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 gu(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 dr=112,bu=18;function ni(r,t,e){let n=He(r),o=n+He(t),s=new Uint8Array(o+e.byteLength);return qe(r,s,0),qe(t,s,n),s.set(e,o),s}var xu=Symbol.for("@ipld/js-cid/CID");var Xn={};vt(Xn,{identity:()=>Nt});var oi=0,wu="identity",si=Xt;function Eu(r){return Ot(oi,si(r))}var Nt={code:oi,name:wu,encode:si,digest:Eu};function lt(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 pt(r=0){return new Uint8Array(r)}function It(r=0){return new Uint8Array(r)}function _t(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=It(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var ai=Symbol.for("@achingbrain/uint8arraylist");function ii(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 jr(r){return!!r?.[ai]}var nt=class r{bufs;length;[ai]=!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(jr(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(jr(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=ii(this.bufs,t);return e.buf[e.index]}set(t,e){let n=ii(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(jr(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 _t(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:_t(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],c=o,a=c+i.byteLength;if(o=a,t>=a)continue;let u=t>=c&&t<a,f=e>c&&e<=a;if(u&&f){if(t===c&&e===a){n.push(i);break}let l=t-c;n.push(i.subarray(l,l+(e-t)));break}if(u){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(f){if(e===a){n.push(i);break}n.push(i.subarray(0,e-c));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!jr(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 l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let c=i,a=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=e;l<=a;l+=f){f=0;for(let d=u;d>=0;d--){let b=this.get(l+d);if(n[d]!==b){f=Math.max(1,d-c[b]);break}}if(f===0)return l}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=It(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=It(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(!lt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var Jn={};vt(Jn,{base10:()=>Au});var Au=fe({prefix:"9",name:"base10",alphabet:"0123456789"});var Qn={};vt(Qn,{base16:()=>Su,base16upper:()=>vu});var Su=et({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),vu=et({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var to={};vt(to,{base2:()=>Iu});var Iu=et({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var eo={};vt(eo,{base256emoji:()=>Tu});var ci=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}"),Bu=ci.reduce((r,t,e)=>(r[e]=t,r),[]),Pu=ci.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Cu(r){return r.reduce((t,e)=>(t+=Bu[e],t),"")}function _u(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Pu[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Tu=Ve({prefix:"\u{1F680}",name:"base256emoji",encode:Cu,decode:_u});var no={};vt(no,{base64:()=>Lu,base64pad:()=>Du,base64url:()=>ro,base64urlpad:()=>Ru});var Lu=et({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Du=et({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ro=et({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ru=et({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var oo={};vt(oo,{base8:()=>Uu});var Uu=et({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var so={};vt(so,{identity:()=>Ou});var Ou=Ve({prefix:"\0",name:"identity",encode:r=>Zs(r),decode:r=>$s(r)});var ih=new TextEncoder,ah=new TextDecoder;var co={};vt(co,{sha256:()=>hr,sha512:()=>ku});function ao({name:r,code:t,encode:e}){return new io(r,t,e)}var io=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?Ot(this.code,e):e.then(n=>Ot(this.code,n))}else throw Error("Unknown type, must be binary type")}};function fi(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var hr=ao({name:"sha2-256",code:18,encode:fi("SHA-256")}),ku=ao({name:"sha2-512",code:19,encode:fi("SHA-512")});var pr={...so,...to,...oo,...Jn,...Qn,...Zn,...jn,...$n,...no,...eo},xh={...co,...Xn};function di(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var li=di("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),uo=di("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=It(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Mu={utf8:li,"utf-8":li,hex:pr.base16,latin1:uo,ascii:uo,binary:uo,...pr},Wr=Mu;function k(r,t="utf8"){let e=Wr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function U(r,t="utf8"){let e=Wr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Fu=parseInt("11111",2),fo=parseInt("10000000",2),Vu=parseInt("01111111",2),hi={0:mr,1:mr,2:qu,3:Gu,4:$u,5:zu,6:Hu,16:mr,22:mr,48:mr};function Qt(r,t={offset:0}){let e=r[t.offset]&Fu;if(t.offset++,hi[e]!=null)return hi[e](r,t);throw new Error("No decoder for tag "+e)}function yr(r,t){let e=0;if((r[t.offset]&fo)===fo){let n=r[t.offset]&Vu,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(o,16)}else e=r[t.offset],t.offset++;return e}function mr(r,t){yr(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=Qt(r,t);if(n===null)break;e.push(n)}return e}function qu(r,t){let e=yr(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function Hu(r,t){let e=yr(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let c=`${s}.${i}`,a=[];for(;t.offset<n;){let u=r[t.offset];if(t.offset++,a.push(u&127),u<128){a.reverse();let f=0;for(let l=0;l<a.length;l++)f+=a[l]<<l*7;c+=`.${f}`,a=[]}}return c}function zu(r,t){return t.offset++,null}function Gu(r,t){let e=yr(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function $u(r,t){let e=yr(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function Zu(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new nt;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function lo(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Zu(r.byteLength);return new nt(Uint8Array.from([t.byteLength|fo]),t)}function Bt(r){let t=new nt,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new nt(Uint8Array.from([2]),lo(t),t)}function Yr(r){let t=Uint8Array.from([0]),e=new nt(t,r);return new nt(Uint8Array.from([3]),lo(e),e)}function de(r,t=48){let e=new nt;for(let n of r)e.append(n);return new nt(Uint8Array.from([t]),lo(e),e)}async function pi(r,t,e){let n=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);return crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},n,t,e.subarray())}var ju=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Wu=Uint8Array.from([6,5,43,129,4,0,34]),Yu=Uint8Array.from([6,5,43,129,4,0,35]),Xu={ext:!0,kty:"EC",crv:"P-256"},Ju={ext:!0,kty:"EC",crv:"P-384"},Qu={ext:!0,kty:"EC",crv:"P-521"},ho=32,po=48,mo=66;function yo(r){let t=Qt(r);return mi(t)}function mi(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===ho*2+1)return n=U(t.subarray(e,e+ho),"base64url"),o=U(t.subarray(e+ho),"base64url"),new Ge({...Xu,key_ops:["verify"],x:n,y:o});if(t.byteLength===po*2+1)return n=U(t.subarray(e,e+po),"base64url"),o=U(t.subarray(e+po),"base64url"),new Ge({...Ju,key_ops:["verify"],x:n,y:o});if(t.byteLength===mo*2+1)return n=U(t.subarray(e,e+mo),"base64url"),o=U(t.subarray(e+mo),"base64url"),new Ge({...Qu,key_ops:["verify"],x:n,y:o});throw new ct(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function yi(r){return de([Bt(Uint8Array.from([1])),de([tf(r.crv)],160),de([Yr(new nt(Uint8Array.from([4]),k(r.x??"","base64url"),k(r.y??"","base64url")))],161)]).subarray()}function tf(r){if(r==="P-256")return ju;if(r==="P-384")return Wu;if(r==="P-521")return Yu;throw new ct(`Invalid curve ${r}`)}var Ge=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=yi(this.jwk)),this._raw}toMultihash(){return Nt.digest(zt(this))}toCID(){return it.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}async verify(t,e){return pi(this.jwk,e,t)}};var Se=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function ef(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Xr(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function ve(r,...t){if(!ef(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 gi(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Xr(r.outputLen),Xr(r.blockLen)}function Ze(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 bi(r,t){ve(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}function te(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Jr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Kt(r,t){return r<<32-t|r>>>t}function xi(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function gr(r){return typeof r=="string"&&(r=xi(r)),ve(r),r}function go(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];ve(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 $e=class{};function bo(r){let t=n=>r().update(gr(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function Qr(r=32){if(Se&&typeof Se.getRandomValues=="function")return Se.getRandomValues(new Uint8Array(r));if(Se&&typeof Se.randomBytes=="function")return Uint8Array.from(Se.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function rf(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),c=Number(e&s),a=n?4:0,u=n?0:4;r.setUint32(t+a,i,n),r.setUint32(t+u,c,n)}function wi(r,t,e){return r&t^~r&e}function Ei(r,t,e){return r&t^r&e^t&e}var br=class extends $e{constructor(t,e,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Jr(this.buffer)}update(t){Ze(this),t=gr(t),ve(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=Jr(t);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ze(this),bi(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,te(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)e[l]=0;rf(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=Jr(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=a/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)c.setUint32(4*l,f[l],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:c}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=c,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},ee=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var mt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var tn=BigInt(4294967295),Ai=BigInt(32);function nf(r,t=!1){return t?{h:Number(r&tn),l:Number(r>>Ai&tn)}:{h:Number(r>>Ai&tn)|0,l:Number(r&tn)|0}}function Si(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:c}=nf(r[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var xo=(r,t,e)=>r>>>e,wo=(r,t,e)=>r<<32-e|t>>>e,Ie=(r,t,e)=>r>>>e|t<<32-e,Be=(r,t,e)=>r<<32-e|t>>>e,xr=(r,t,e)=>r<<64-e|t>>>e-32,wr=(r,t,e)=>r>>>e-32|t<<64-e;function Gt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var vi=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Ii=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Bi=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Pi=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Ci=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),_i=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var sf=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),he=new Uint32Array(64),en=class extends br{constructor(t=32){super(64,t,8,!1),this.A=ee[0]|0,this.B=ee[1]|0,this.C=ee[2]|0,this.D=ee[3]|0,this.E=ee[4]|0,this.F=ee[5]|0,this.G=ee[6]|0,this.H=ee[7]|0}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[t,e,n,o,s,i,c,a]}set(t,e,n,o,s,i,c,a){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=c|0,this.H=a|0}process(t,e){for(let l=0;l<16;l++,e+=4)he[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let d=he[l-15],b=he[l-2],m=Kt(d,7)^Kt(d,18)^d>>>3,g=Kt(b,17)^Kt(b,19)^b>>>10;he[l]=g+he[l-7]+m+he[l-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:u,H:f}=this;for(let l=0;l<64;l++){let d=Kt(c,6)^Kt(c,11)^Kt(c,25),b=f+d+wi(c,a,u)+sf[l]+he[l]|0,g=(Kt(n,2)^Kt(n,13)^Kt(n,22))+Ei(n,o,s)|0;f=u,u=a,a=c,c=i+b|0,i=s,s=o,o=n,n=b+g|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,o,s,i,c,a,u,f)}roundClean(){te(he)}destroy(){this.set(0,0,0,0,0,0,0,0),te(this.buffer)}};var Ti=Si(["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))),af=Ti[0],cf=Ti[1],pe=new Uint32Array(80),me=new Uint32Array(80),Eo=class extends br{constructor(t=64){super(128,t,16,!1),this.Ah=mt[0]|0,this.Al=mt[1]|0,this.Bh=mt[2]|0,this.Bl=mt[3]|0,this.Ch=mt[4]|0,this.Cl=mt[5]|0,this.Dh=mt[6]|0,this.Dl=mt[7]|0,this.Eh=mt[8]|0,this.El=mt[9]|0,this.Fh=mt[10]|0,this.Fl=mt[11]|0,this.Gh=mt[12]|0,this.Gl=mt[13]|0,this.Hh=mt[14]|0,this.Hl=mt[15]|0}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:u,El:f,Fh:l,Fl:d,Gh:b,Gl:m,Hh:g,Hl:h}=this;return[t,e,n,o,s,i,c,a,u,f,l,d,b,m,g,h]}set(t,e,n,o,s,i,c,a,u,f,l,d,b,m,g,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=c|0,this.Dl=a|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=d|0,this.Gh=b|0,this.Gl=m|0,this.Hh=g|0,this.Hl=h|0}process(t,e){for(let y=0;y<16;y++,e+=4)pe[y]=t.getUint32(e),me[y]=t.getUint32(e+=4);for(let y=16;y<80;y++){let I=pe[y-15]|0,D=me[y-15]|0,L=Ie(I,D,1)^Ie(I,D,8)^xo(I,D,7),P=Be(I,D,1)^Be(I,D,8)^wo(I,D,7),C=pe[y-2]|0,_=me[y-2]|0,X=Ie(C,_,19)^xr(C,_,61)^xo(C,_,6),G=Be(C,_,19)^wr(C,_,61)^wo(C,_,6),N=Bi(P,G,me[y-7],me[y-16]),at=Pi(N,L,X,pe[y-7],pe[y-16]);pe[y]=at|0,me[y]=N|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:u,Dl:f,Eh:l,El:d,Fh:b,Fl:m,Gh:g,Gl:h,Hh:w,Hl:v}=this;for(let y=0;y<80;y++){let I=Ie(l,d,14)^Ie(l,d,18)^xr(l,d,41),D=Be(l,d,14)^Be(l,d,18)^wr(l,d,41),L=l&b^~l&g,P=d&m^~d&h,C=Ci(v,D,P,cf[y],me[y]),_=_i(C,w,I,L,af[y],pe[y]),X=C|0,G=Ie(n,o,28)^xr(n,o,34)^xr(n,o,39),N=Be(n,o,28)^wr(n,o,34)^wr(n,o,39),at=n&s^n&c^s&c,A=o&i^o&a^i&a;w=g|0,v=h|0,g=b|0,h=m|0,b=l|0,m=d|0,{h:l,l:d}=Gt(u|0,f|0,_|0,X|0),u=c|0,f=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let B=vi(X,N,A);n=Ii(B,_,G,at),o=B|0}({h:n,l:o}=Gt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Gt(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=Gt(this.Ch|0,this.Cl|0,c|0,a|0),{h:u,l:f}=Gt(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:d}=Gt(this.Eh|0,this.El|0,l|0,d|0),{h:b,l:m}=Gt(this.Fh|0,this.Fl|0,b|0,m|0),{h:g,l:h}=Gt(this.Gh|0,this.Gl|0,g|0,h|0),{h:w,l:v}=Gt(this.Hh|0,this.Hl|0,w|0,v|0),this.set(n,o,s,i,c,a,u,f,l,d,b,m,g,h,w,v)}roundClean(){te(pe,me)}destroy(){te(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var rn=bo(()=>new en);var Li=bo(()=>new Eo);var Io=BigInt(0),vo=BigInt(1);function Pe(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Bo(r){if(!Pe(r))throw new Error("Uint8Array expected")}function $t(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}function Er(r){let t=r.toString(16);return t.length&1?"0"+t:t}function Ui(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?Io:BigInt("0x"+r)}var Oi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",uf=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function ye(r){if(Bo(r),Oi)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=uf[r[e]];return t}var re={_0:48,_9:57,A:65,F:70,a:97,f:102};function Di(r){if(r>=re._0&&r<=re._9)return r-re._0;if(r>=re.A&&r<=re.F)return r-(re.A-10);if(r>=re.a&&r<=re.f)return r-(re.a-10)}function Ar(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(Oi)return Uint8Array.fromHex(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=Di(r.charCodeAt(s)),c=Di(r.charCodeAt(s+1));if(i===void 0||c===void 0){let a=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function ne(r){return Ui(ye(r))}function Ce(r){return Bo(r),Ui(ye(Uint8Array.from(r).reverse()))}function _e(r,t){return Ar(r.toString(16).padStart(t*2,"0"))}function je(r,t){return _e(r,t).reverse()}function tt(r,t,e){let n;if(typeof t=="string")try{n=Ar(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(Pe(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 ge(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Bo(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 Ao=r=>typeof r=="bigint"&&Io<=r;function nn(r,t,e){return Ao(r)&&Ao(t)&&Ao(e)&&t<=r&&r<e}function Tt(r,t,e,n){if(!nn(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function Ni(r){let t;for(t=0;r>Io;r>>=vo,t+=1);return t}var Te=r=>(vo<<BigInt(r))-vo,So=r=>new Uint8Array(r),Ri=r=>Uint8Array.from(r);function Ki(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=So(r),o=So(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},c=(...l)=>e(o,n,...l),a=(l=So(0))=>{o=c(Ri([0]),l),n=c(),l.length!==0&&(o=c(Ri([1]),l),n=c())},u=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,d=[];for(;l<t;){n=c();let b=n.slice();d.push(b),l+=n.length}return ge(...d)};return(l,d)=>{i(),a(l);let b;for(;!(b=d(u()));)a();return i(),b}}var ff={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"||Pe(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 oe(r,t,e={}){let n=(o,s,i)=>{let c=ff[s];if(typeof c!="function")throw new Error("invalid validator function");let a=r[o];if(!(i&&a===void 0)&&!c(a,r))throw new Error("param "+String(o)+" is invalid. Expected "+s+", got "+a)};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}function We(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 Et=BigInt(0),ut=BigInt(1),Le=BigInt(2),lf=BigInt(3),Po=BigInt(4),ki=BigInt(5),Mi=BigInt(8),df=BigInt(9),hf=BigInt(16);function W(r,t){let e=r%t;return e>=Et?e:t+e}function J(r,t,e){let n=r;for(;t-- >Et;)n*=n,n%=e;return n}function on(r,t){if(r===Et)throw new Error("invert: expected non-zero number");if(t<=Et)throw new Error("invert: expected positive modulus, got "+t);let e=W(r,t),n=t,o=Et,s=ut,i=ut,c=Et;for(;e!==Et;){let u=n/e,f=n%e,l=o-i*u,d=s-c*u;n=e,e=f,o=i,s=c,i=l,c=d}if(n!==ut)throw new Error("invert: does not exist");return W(o,t)}function pf(r){let t=r-ut,e=0;for(;t%Le===Et;)t/=Le,e++;let n=Le,o=se(r);for(;n<r&&Fi(o,n);)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1){let i=(r+ut)/Po;return function(a,u){let f=a.pow(u,i);if(!a.eql(a.sqr(f),u))throw new Error("Cannot find square root");return f}}let s=(t+ut)/Le;return function(c,a){if(!Fi(c,a))throw new Error("Cannot find square root");let u=e,f=c.pow(c.mul(c.ONE,n),t),l=c.pow(a,s),d=c.pow(a,t);for(;!c.eql(d,c.ONE);){if(c.eql(d,c.ZERO))return c.ZERO;let b=1;for(let g=c.sqr(d);b<u&&!c.eql(g,c.ONE);b++)g=c.sqr(g);let m=c.pow(f,ut<<BigInt(u-b-1));f=c.sqr(m),l=c.mul(l,m),d=c.mul(d,f),u=b}return l}}function mf(r){return r%Po===lf?function(e,n){let o=(r+ut)/Po,s=e.pow(n,o);if(!e.eql(e.sqr(s),n))throw new Error("Cannot find square root");return s}:r%Mi===ki?function(e,n){let o=e.mul(n,Le),s=(r-ki)/Mi,i=e.pow(o,s),c=e.mul(n,i),a=e.mul(e.mul(c,Le),i),u=e.mul(c,e.sub(a,e.ONE));if(!e.eql(e.sqr(u),n))throw new Error("Cannot find square root");return u}:(r%hf,pf(r))}var Vi=(r,t)=>(W(r,t)&ut)===ut,yf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Co(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=yf.reduce((n,o)=>(n[o]="function",n),t);return oe(r,e)}function gf(r,t,e){if(e<Et)throw new Error("invalid exponent, negatives unsupported");if(e===Et)return r.ONE;if(e===ut)return t;let n=r.ONE,o=t;for(;e>Et;)e&ut&&(n=r.mul(n,o)),o=r.sqr(o),e>>=ut;return n}function Ye(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,c,a)=>r.is0(c)?i:(n[a]=i,r.mul(i,c)),r.ONE),s=r.inv(o);return t.reduceRight((i,c,a)=>r.is0(c)?i:(n[a]=r.mul(i,n[a]),r.mul(i,c)),s),n}function bf(r,t){let e=(r.ORDER-ut)/Le,n=r.pow(t,e),o=r.eql(n,r.ONE),s=r.eql(n,r.ZERO),i=r.eql(n,r.neg(r.ONE));if(!o&&!s&&!i)throw new Error("Cannot find square root: probably non-prime P");return o?1:s?0:-1}function Fi(r,t){let e=bf(r,t);return e===0||e===1}function _o(r,t){t!==void 0&&Xr(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function se(r,t,e=!1,n={}){if(r<=Et)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:s}=_o(r,t);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let i,c=Object.freeze({ORDER:r,isLE:e,BITS:o,BYTES:s,MASK:Te(o),ZERO:Et,ONE:ut,create:a=>W(a,r),isValid:a=>{if(typeof a!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof a);return Et<=a&&a<r},is0:a=>a===Et,isOdd:a=>(a&ut)===ut,neg:a=>W(-a,r),eql:(a,u)=>a===u,sqr:a=>W(a*a,r),add:(a,u)=>W(a+u,r),sub:(a,u)=>W(a-u,r),mul:(a,u)=>W(a*u,r),pow:(a,u)=>gf(c,a,u),div:(a,u)=>W(a*on(u,r),r),sqrN:a=>a*a,addN:(a,u)=>a+u,subN:(a,u)=>a-u,mulN:(a,u)=>a*u,inv:a=>on(a,r),sqrt:n.sqrt||(a=>(i||(i=mf(r)),i(c,a))),toBytes:a=>e?je(a,s):_e(a,s),fromBytes:a=>{if(a.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+a.length);return e?Ce(a):ne(a)},invertBatch:a=>Ye(c,a),cmov:(a,u,f)=>f?u:a});return Object.freeze(c)}function qi(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 To(r){let t=qi(r);return t+Math.ceil(t/2)}function Hi(r,t,e=!1){let n=r.length,o=qi(t),s=To(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?Ce(r):ne(r),c=W(i,t-ut)+ut;return e?je(c,o):_e(c,o)}var zi=BigInt(0),Oo=BigInt(1);function Lo(r,t){let e=t.negate();return r?e:t}function $i(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function Do(r,t){$i(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=Te(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Gi(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,c=Number(r&o),a=r>>i;c>n&&(c-=s,a+=Oo);let u=t*n,f=u+Math.abs(c)-1,l=c===0,d=c<0,b=t%2!==0;return{nextN:a,offset:f,isZero:l,isNeg:d,isNegF:b,offsetF:u}}function xf(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 wf(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 Ro=new WeakMap,Zi=new WeakMap;function Uo(r){return Zi.get(r)||1}function sn(r,t){return{constTimeNegate:Lo,hasPrecomputes(e){return Uo(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>zi;)n&Oo&&(o=o.add(s)),s=s.double(),n>>=Oo;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=Do(n,t),i=[],c=e,a=c;for(let u=0;u<o;u++){a=c,i.push(a);for(let f=1;f<s;f++)a=a.add(c),i.push(a);c=a.double()}return i},wNAF(e,n,o){let s=r.ZERO,i=r.BASE,c=Do(e,t);for(let a=0;a<c.windows;a++){let{nextN:u,offset:f,isZero:l,isNeg:d,isNegF:b,offsetF:m}=Gi(o,a,c);o=u,l?i=i.add(Lo(b,n[m])):s=s.add(Lo(d,n[f]))}return{p:s,f:i}},wNAFUnsafe(e,n,o,s=r.ZERO){let i=Do(e,t);for(let c=0;c<i.windows&&o!==zi;c++){let{nextN:a,offset:u,isZero:f,isNeg:l}=Gi(o,c,i);if(o=a,!f){let d=n[u];s=s.add(l?d.negate():d)}}return s},getPrecomputes(e,n,o){let s=Ro.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&Ro.set(n,o(s))),s},wNAFCached(e,n,o){let s=Uo(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=Uo(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){$i(n,t),Zi.set(e,n),Ro.delete(e)}}}function an(r,t,e,n){if(xf(e,r),wf(n,t),e.length!==n.length)throw new Error("arrays of points and scalars must have equal length");let o=r.ZERO,s=Ni(BigInt(e.length)),i=s>12?s-3:s>4?s-2:s?2:1,c=Te(i),a=new Array(Number(c)+1).fill(o),u=Math.floor((t.BITS-1)/i)*i,f=o;for(let l=u;l>=0;l-=i){a.fill(o);for(let b=0;b<n.length;b++){let m=n[b],g=Number(m>>BigInt(l)&c);a[g]=a[g].add(e[b])}let d=o;for(let b=a.length-1,m=o;b>0;b--)m=m.add(a[b]),d=d.add(m);if(f=f.add(d),l!==0)for(let b=0;b<i;b++)f=f.double()}return f}function Sr(r){return Co(r.Fp),oe(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({..._o(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Zt=BigInt(0),At=BigInt(1),ji=BigInt(2),Ef=BigInt(8),Af={zip215:!0};function Sf(r){let t=Sr(r);return oe(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Wi(r){let t=Sf(r),{Fp:e,n,prehash:o,hash:s,randomBytes:i,nByteLength:c,h:a}=t,u=ji<<BigInt(c*8)-At,f=e.create,l=se(t.n,t.nBitLength),d=t.uvRatio||((x,p)=>{try{return{isValid:!0,value:e.sqrt(x*e.inv(p))}}catch{return{isValid:!1,value:Zt}}}),b=t.adjustScalarBytes||(x=>x),m=t.domain||((x,p,E)=>{if($t("phflag",E),p.length||E)throw new Error("Contexts/pre-hash are not supported");return x});function g(x,p,E=!1){let S=E?At:Zt;Tt("coordinate "+x,p,S,u)}function h(x){if(!(x instanceof y))throw new Error("ExtendedPoint expected")}let w=We((x,p)=>{let{ex:E,ey:S,ez:R}=x,O=x.is0();p==null&&(p=O?Ef:e.inv(R));let K=f(E*p),M=f(S*p),q=f(R*p);if(O)return{x:Zt,y:At};if(q!==At)throw new Error("invZ was invalid");return{x:K,y:M}}),v=We(x=>{let{a:p,d:E}=t;if(x.is0())throw new Error("bad point: ZERO");let{ex:S,ey:R,ez:O,et:K}=x,M=f(S*S),q=f(R*R),Z=f(O*O),st=f(Z*Z),rt=f(M*p),ht=f(Z*f(rt+q)),St=f(st+f(E*f(M*q)));if(ht!==St)throw new Error("bad point: equation left != right (1)");let ft=f(S*R),yt=f(O*K);if(ft!==yt)throw new Error("bad point: equation left != right (2)");return!0});class y{constructor(p,E,S,R){g("x",p),g("y",E),g("z",S,!0),g("t",R),this.ex=p,this.ey=E,this.ez=S,this.et=R,Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(p){if(p instanceof y)throw new Error("extended point not allowed");let{x:E,y:S}=p||{};return g("x",E),g("y",S),new y(E,S,At,f(E*S))}static normalizeZ(p){let E=Ye(e,p.map(S=>S.ez));return p.map((S,R)=>S.toAffine(E[R])).map(y.fromAffine)}static msm(p,E){return an(y,l,p,E)}_setWindowSize(p){L.setWindowSize(this,p)}assertValidity(){v(this)}equals(p){h(p);let{ex:E,ey:S,ez:R}=this,{ex:O,ey:K,ez:M}=p,q=f(E*M),Z=f(O*R),st=f(S*M),rt=f(K*R);return q===Z&&st===rt}is0(){return this.equals(y.ZERO)}negate(){return new y(f(-this.ex),this.ey,this.ez,f(-this.et))}double(){let{a:p}=t,{ex:E,ey:S,ez:R}=this,O=f(E*E),K=f(S*S),M=f(ji*f(R*R)),q=f(p*O),Z=E+S,st=f(f(Z*Z)-O-K),rt=q+K,ht=rt-M,St=q-K,ft=f(st*ht),yt=f(rt*St),Ct=f(st*St),Rt=f(ht*rt);return new y(ft,yt,Rt,Ct)}add(p){h(p);let{a:E,d:S}=t,{ex:R,ey:O,ez:K,et:M}=this,{ex:q,ey:Z,ez:st,et:rt}=p,ht=f(R*q),St=f(O*Z),ft=f(M*S*rt),yt=f(K*st),Ct=f((R+O)*(q+Z)-ht-St),Rt=yt-ft,cr=yt+ft,Hs=f(St-E*ht),vc=f(Ct*Rt),Ic=f(cr*Hs),Bc=f(Ct*Hs),Pc=f(Rt*cr);return new y(vc,Ic,Pc,Bc)}subtract(p){return this.add(p.negate())}wNAF(p){return L.wNAFCached(this,p,y.normalizeZ)}multiply(p){let E=p;Tt("scalar",E,At,n);let{p:S,f:R}=this.wNAF(E);return y.normalizeZ([S,R])[0]}multiplyUnsafe(p,E=y.ZERO){let S=p;return Tt("scalar",S,Zt,n),S===Zt?D:this.is0()||S===At?this:L.wNAFCachedUnsafe(this,S,y.normalizeZ,E)}isSmallOrder(){return this.multiplyUnsafe(a).is0()}isTorsionFree(){return L.unsafeLadder(this,n).is0()}toAffine(p){return w(this,p)}clearCofactor(){let{h:p}=t;return p===At?this:this.multiplyUnsafe(p)}static fromHex(p,E=!1){let{d:S,a:R}=t,O=e.BYTES;p=tt("pointHex",p,O),$t("zip215",E);let K=p.slice(),M=p[O-1];K[O-1]=M&-129;let q=Ce(K),Z=E?u:e.ORDER;Tt("pointHex.y",q,Zt,Z);let st=f(q*q),rt=f(st-At),ht=f(S*st-R),{isValid:St,value:ft}=d(rt,ht);if(!St)throw new Error("Point.fromHex: invalid y coordinate");let yt=(ft&At)===At,Ct=(M&128)!==0;if(!E&&ft===Zt&&Ct)throw new Error("Point.fromHex: x=0 and x_0=1");return Ct!==yt&&(ft=f(-ft)),y.fromAffine({x:ft,y:q})}static fromPrivateKey(p){let{scalar:E}=_(p);return I.multiply(E)}toRawBytes(){let{x:p,y:E}=this.toAffine(),S=je(E,e.BYTES);return S[S.length-1]|=p&At?128:0,S}toHex(){return ye(this.toRawBytes())}}y.BASE=new y(t.Gx,t.Gy,At,f(t.Gx*t.Gy)),y.ZERO=new y(Zt,At,At,Zt);let{BASE:I,ZERO:D}=y,L=sn(y,c*8);function P(x){return W(x,n)}function C(x){return P(Ce(x))}function _(x){let p=e.BYTES;x=tt("private key",x,p);let E=tt("hashed private key",s(x),2*p),S=b(E.slice(0,p)),R=E.slice(p,2*p),O=C(S);return{head:S,prefix:R,scalar:O}}function X(x){let{head:p,prefix:E,scalar:S}=_(x),R=I.multiply(S),O=R.toRawBytes();return{head:p,prefix:E,scalar:S,point:R,pointBytes:O}}function G(x){return X(x).pointBytes}function N(x=Uint8Array.of(),...p){let E=ge(...p);return C(s(m(E,tt("context",x),!!o)))}function at(x,p,E={}){x=tt("message",x),o&&(x=o(x));let{prefix:S,scalar:R,pointBytes:O}=X(p),K=N(E.context,S,x),M=I.multiply(K).toRawBytes(),q=N(E.context,M,O,x),Z=P(K+q*R);Tt("signature.s",Z,Zt,n);let st=ge(M,je(Z,e.BYTES));return tt("result",st,e.BYTES*2)}let A=Af;function B(x,p,E,S=A){let{context:R,zip215:O}=S,K=e.BYTES;x=tt("signature",x,2*K),p=tt("message",p),E=tt("publicKey",E,K),O!==void 0&&$t("zip215",O),o&&(p=o(p));let M=Ce(x.slice(K,2*K)),q,Z,st;try{q=y.fromHex(E,O),Z=y.fromHex(x.slice(0,K),O),st=I.multiplyUnsafe(M)}catch{return!1}if(!O&&q.isSmallOrder())return!1;let rt=N(R,Z.toRawBytes(),q.toRawBytes(),p);return Z.add(q.multiplyUnsafe(rt)).subtract(st).clearCofactor().equals(y.ZERO)}return I._setWindowSize(8),{CURVE:t,getPublicKey:G,sign:at,verify:B,ExtendedPoint:y,utils:{getExtendedPublicKey:X,randomPrivateKey:()=>i(e.BYTES),precompute(x=8,p=y.BASE){return p._setWindowSize(x),p.multiply(BigInt(3)),p}}}}var No=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Yi=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Ap=BigInt(0),vf=BigInt(1),Xi=BigInt(2),Sp=BigInt(3),If=BigInt(5),Bf=BigInt(8);function Pf(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=No,c=r*r%s*r%s,a=J(c,Xi,s)*c%s,u=J(a,vf,s)*r%s,f=J(u,If,s)*u%s,l=J(f,t,s)*f%s,d=J(l,e,s)*l%s,b=J(d,n,s)*d%s,m=J(b,o,s)*b%s,g=J(m,o,s)*b%s,h=J(g,t,s)*f%s;return{pow_p_5_8:J(h,Xi,s)*r%s,b2:c}}function Cf(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function _f(r,t){let e=No,n=W(t*t*t,e),o=W(n*n*t,e),s=Pf(r*o).pow_p_5_8,i=W(r*n*s,e),c=W(t*i*i,e),a=i,u=W(i*Yi,e),f=c===r,l=c===W(-r,e),d=c===W(-r*Yi,e);return f&&(i=a),(l||d)&&(i=u),Vi(i,e)&&(i=W(-i,e)),{isValid:f||l,value:i}}var Ji=se(No,void 0,!0),Tf={a:Ji.create(BigInt(-1)),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Ji,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:Bf,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Li,randomBytes:Qr,adjustScalarBytes:Cf,uvRatio:_f},Qi=Wi(Tf);var cn=32;function ta(r,t,e){return Qi.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var un=class{type="Ed25519";raw;constructor(t){this.raw=Ko(t,cn)}toMultihash(){return Nt.digest(zt(this))}toCID(){return it.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}verify(t,e){return ta(this.raw,e,t)}};function ko(r){return r=Ko(r,cn),new un(r)}function Ko(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new ct(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var Df=Math.pow(2,7),Rf=Math.pow(2,14),Uf=Math.pow(2,21),Mo=Math.pow(2,28),Fo=Math.pow(2,35),Vo=Math.pow(2,42),qo=Math.pow(2,49),$=128,gt=127;function bt(r){if(r<Df)return 1;if(r<Rf)return 2;if(r<Uf)return 3;if(r<Mo)return 4;if(r<Fo)return 5;if(r<Vo)return 6;if(r<qo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ho(r,t,e=0){switch(bt(r)){case 8:t[e++]=r&255|$,r/=128;case 7:t[e++]=r&255|$,r/=128;case 6:t[e++]=r&255|$,r/=128;case 5:t[e++]=r&255|$,r/=128;case 4:t[e++]=r&255|$,r>>>=7;case 3:t[e++]=r&255|$,r>>>=7;case 2:t[e++]=r&255|$,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Of(r,t,e=0){switch(bt(r)){case 8:t.set(e++,r&255|$),r/=128;case 7:t.set(e++,r&255|$),r/=128;case 6:t.set(e++,r&255|$),r/=128;case 5:t.set(e++,r&255|$),r/=128;case 4:t.set(e++,r&255|$),r>>>=7;case 3:t.set(e++,r&255|$),r>>>=7;case 2:t.set(e++,r&255|$),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function zo(r,t){let e=r[t],n=0;if(n+=e&gt,e<$||(e=r[t+1],n+=(e&gt)<<7,e<$)||(e=r[t+2],n+=(e&gt)<<14,e<$)||(e=r[t+3],n+=(e&gt)<<21,e<$)||(e=r[t+4],n+=(e&gt)*Mo,e<$)||(e=r[t+5],n+=(e&gt)*Fo,e<$)||(e=r[t+6],n+=(e&gt)*Vo,e<$)||(e=r[t+7],n+=(e&gt)*qo,e<$))return n;throw new RangeError("Could not decode varint")}function Nf(r,t){let e=r.get(t),n=0;if(n+=e&gt,e<$||(e=r.get(t+1),n+=(e&gt)<<7,e<$)||(e=r.get(t+2),n+=(e&gt)<<14,e<$)||(e=r.get(t+3),n+=(e&gt)<<21,e<$)||(e=r.get(t+4),n+=(e&gt)*Mo,e<$)||(e=r.get(t+5),n+=(e&gt)*Fo,e<$)||(e=r.get(t+6),n+=(e&gt)*Vo,e<$)||(e=r.get(t+7),n+=(e&gt)*qo,e<$))return n;throw new RangeError("Could not decode varint")}function Dt(r,t,e=0){return t==null&&(t=It(bt(r))),t instanceof Uint8Array?Ho(r,t,e):Of(r,t,e)}function ie(r,t=0){return r instanceof Uint8Array?zo(r,t):Nf(r,t)}var Go=new Float32Array([-0]),be=new Uint8Array(Go.buffer);function ra(r,t,e){Go[0]=r,t[e]=be[0],t[e+1]=be[1],t[e+2]=be[2],t[e+3]=be[3]}function na(r,t){return be[0]=r[t],be[1]=r[t+1],be[2]=r[t+2],be[3]=r[t+3],Go[0]}var $o=new Float64Array([-0]),xt=new Uint8Array($o.buffer);function oa(r,t,e){$o[0]=r,t[e]=xt[0],t[e+1]=xt[1],t[e+2]=xt[2],t[e+3]=xt[3],t[e+4]=xt[4],t[e+5]=xt[5],t[e+6]=xt[6],t[e+7]=xt[7]}function sa(r,t){return xt[0]=r[t],xt[1]=r[t+1],xt[2]=r[t+2],xt[3]=r[t+3],xt[4]=r[t+4],xt[5]=r[t+5],xt[6]=r[t+6],xt[7]=r[t+7],$o[0]}var Kf=BigInt(Number.MAX_SAFE_INTEGER),kf=BigInt(Number.MIN_SAFE_INTEGER),Lt=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 De;if(t<Kf&&t>kf)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>ia&&(o=0n,++n>ia&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return De;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):De}},De=new Lt(0,0);De.toBigInt=function(){return 0n};De.zzEncode=De.zzDecode=function(){return this};De.length=function(){return 1};var ia=4294967296n;function aa(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 ca(r,t,e){if(e-t<1)return"";let o,s=[],i=0,c;for(;t<e;)c=r[t++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|r[t++]&63:c>239&&c<365?(c=((c&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&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 Zo(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 kt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function ln(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var jo=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,kt(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 kt(this,4);return ln(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw kt(this,4);return ln(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw kt(this,4);let t=na(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw kt(this,4);let t=sa(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 kt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return ca(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw kt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw kt(this);while((this.buf[this.pos++]&128)!==0);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 Lt(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 kt(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 kt(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 kt(this,8);let t=ln(this.buf,this.pos+=4),e=ln(this.buf,this.pos+=4);return new Lt(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=zo(this.buf,this.pos);return this.pos+=bt(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 Wo(r){return new jo(r instanceof Uint8Array?r:r.subarray())}function Mt(r,t,e){let n=Wo(r);return t.decode(n,void 0,e)}function Yo(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return It(i);o+i>t&&(n=It(t),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var Re=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Xo(){}var Qo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Mf=Yo();function Ff(r){return globalThis.Buffer!=null?It(r):Mf(r)}var Ir=class{len;head;tail;states;constructor(){this.len=0,this.head=new Re(Xo,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new Re(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new ts((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(dn,10,Lt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=Lt.fromBigInt(t);return this._push(dn,e.length(),e)}uint64Number(t){return this._push(Ho,bt(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=Lt.fromBigInt(t).zzEncode();return this._push(dn,e.length(),e)}sint64Number(t){let e=Lt.fromNumber(t).zzEncode();return this._push(dn,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Jo,1,t?1:0)}fixed32(t){return this._push(vr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Lt.fromBigInt(t);return this._push(vr,4,e.lo)._push(vr,4,e.hi)}fixed64Number(t){let e=Lt.fromNumber(t);return this._push(vr,4,e.lo)._push(vr,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(ra,4,t)}double(t){return this._push(oa,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Jo,1,0):this.uint32(e)._push(qf,e,t)}string(t){let e=aa(t);return e!==0?this.uint32(e)._push(Zo,e,t):this._push(Jo,1,0)}fork(){return this.states=new Qo(this),this.head=this.tail=new Re(Xo,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 Re(Xo,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=Ff(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Jo(r,t,e){t[e]=r&255}function Vf(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var ts=class extends Re{next;constructor(t,e){super(Vf,t,e),this.next=void 0}};function dn(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 vr(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 qf(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Ir.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(Hf,t,r),this},Ir.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(zf,t,r),this});function Hf(r,t,e){t.set(r,e)}function zf(r,t,e){r.length<40?Zo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(k(r),e)}function es(){return new Ir}function Ft(r,t){let e=es();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Xe;(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"})(Xe||(Xe={}));function hn(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function rs(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let c=t(s);i.int32(c)},n=function(s){let i=s.int32();return t(i)};return hn("enum",Xe.VARINT,e,n)}function Vt(r,t){return hn("message",Xe.LENGTH_DELIMITED,r,t)}var Ue=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var ot;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(ot||(ot={}));var ns;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(ns||(ns={}));(function(r){r.codec=()=>rs(ns)})(ot||(ot={}));var jt;(function(r){let t;r.codec=()=>(t==null&&(t=Vt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),ot.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 c=e.uint32();switch(c>>>3){case 1:{s.Type=ot.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return s})),t),r.encode=e=>Ft(e,r.codec()),r.decode=(e,n)=>Mt(e,r.codec(),n)})(jt||(jt={}));var os;(function(r){let t;r.codec=()=>(t==null&&(t=Vt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),ot.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 c=e.uint32();switch(c>>>3){case 1:{s.Type=ot.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return s})),t),r.encode=e=>Ft(e,r.codec()),r.decode=(e,n)=>Mt(e,r.codec(),n)})(os||(os={}));var Br=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},pn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var la={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new pn("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var xe=la;var Cr={};vt(Cr,{MAX_RSA_KEY_SIZE:()=>ss,generateRSAKeyPair:()=>ma,jwkToJWKKeyPair:()=>ya,jwkToPkcs1:()=>jf,jwkToPkix:()=>us,jwkToRSAPrivateKey:()=>hs,pkcs1MessageToJwk:()=>as,pkcs1MessageToRSAPrivateKey:()=>fs,pkcs1ToJwk:()=>Zf,pkcs1ToRSAPrivateKey:()=>pa,pkixMessageToJwk:()=>cs,pkixMessageToRSAPublicKey:()=>ds,pkixToJwk:()=>Wf,pkixToRSAPublicKey:()=>ls});var mn=rn;var Je=class{type="RSA";jwk;_raw;_multihash;constructor(t,e){this.jwk=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=Cr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return it.createV1(114,this._multihash)}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}verify(t,e){return ha(this.jwk,e,t)}},Pr=class{type="RSA";jwk;_raw;publicKey;constructor(t,e){this.jwk=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=Cr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}sign(t){return da(this.jwk,t)}};var ss=8192,is=18,Gf=1062,$f=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Zf(r){let t=Qt(r);return as(t)}function as(r){return{n:U(r[1],"base64url"),e:U(r[2],"base64url"),d:U(r[3],"base64url"),p:U(r[4],"base64url"),q:U(r[5],"base64url"),dp:U(r[6],"base64url"),dq:U(r[7],"base64url"),qi:U(r[8],"base64url"),kty:"RSA"}}function jf(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new ct("JWK was missing components");return de([Bt(Uint8Array.from([0])),Bt(k(r.n,"base64url")),Bt(k(r.e,"base64url")),Bt(k(r.d,"base64url")),Bt(k(r.p,"base64url")),Bt(k(r.q,"base64url")),Bt(k(r.dp,"base64url")),Bt(k(r.dq,"base64url")),Bt(k(r.qi,"base64url"))]).subarray()}function Wf(r){let t=Qt(r,{offset:0});return cs(t)}function cs(r){let t=Qt(r[1],{offset:0});return{kty:"RSA",n:U(t[0],"base64url"),e:U(t[1],"base64url")}}function us(r){if(r.n==null||r.e==null)throw new ct("JWK was missing components");return de([$f,Yr(de([Bt(k(r.n,"base64url")),Bt(k(r.e,"base64url"))]))]).subarray()}function pa(r){let t=Qt(r);return fs(t)}function fs(r){let t=as(r);return hs(t)}function ls(r,t){if(r.byteLength>=Gf)throw new Fe("Key size is too large");let e=Qt(r,{offset:0});return ds(e,r,t)}function ds(r,t,e){let n=cs(r);if(e==null){let o=mn(jt.encode({Type:ot.RSA,Data:t}));e=Ot(is,o)}return new Je(n,e)}function hs(r){if(ba(r)>ss)throw new ct("Key size is too large");let t=ya(r),e=mn(jt.encode({Type:ot.RSA,Data:us(t.publicKey)})),n=Ot(is,e);return new Pr(t.privateKey,new Je(t.publicKey,n))}async function ma(r){if(r>ss)throw new ct("Key size is too large");let t=await ga(r),e=mn(jt.encode({Type:ot.RSA,Data:us(t.publicKey)})),n=Ot(is,e);return new Pr(t.privateKey,new Je(t.publicKey,n))}function ya(r){if(r==null)throw new ct("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function ga(r){let t=await xe.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),e=await Yf(t);return{privateKey:e[0],publicKey:e[1]}}async function da(r,t){let e=await xe.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await xe.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},e,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function ha(r,t,e){let n=await xe.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return xe.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,e instanceof Uint8Array?e:e.subarray())}async function Yf(r){if(r.privateKey==null||r.publicKey==null)throw new ct("Private and public key are required");return Promise.all([xe.get().subtle.exportKey("jwk",r.privateKey),xe.get().subtle.exportKey("jwk",r.publicKey)])}function ba(r){if(r.kty!=="RSA")throw new ct("invalid key type");if(r.n==null)throw new ct("invalid key modulus");return k(r.n,"base64url").length*8}var yn=class extends $e{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,gi(t);let n=gr(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),te(s)}update(t){return Ze(this),this.iHash.update(t),this}digestInto(t){Ze(this),ve(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:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},ps=(r,t,e)=>new yn(r,t).update(e).digest();ps.create=(r,t)=>new yn(r,t);function xa(r){r.lowS!==void 0&&$t("lowS",r.lowS),r.prehash!==void 0&&$t("prehash",r.prehash)}function Xf(r){let t=Sr(r);oe(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 ms=class extends Error{constructor(t=""){super(t)}},ae={Err:ms,_tlv:{encode:(r,t)=>{let{Err:e}=ae;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=Er(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?Er(o.length/2|128):"";return Er(r)+s+o+t},decode(r,t){let{Err:e}=ae,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 a=o&127;if(!a)throw new e("tlv.decode(long): indefinite length not supported");if(a>4)throw new e("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+a);if(u.length!==a)throw new e("tlv.decode: length bytes not complete");if(u[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=a,i<128)throw new e("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new e("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=ae;if(r<ce)throw new t("integer: negative integers are not allowed");let e=Er(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}=ae;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 ne(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=ae,o=tt("signature",r),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,s),{v:u,l:f}=n.decode(2,a);if(f.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(c),s:e.decode(u)}},hexFromSig(r){let{_tlv:t,_int:e}=ae,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},ce=BigInt(0),dt=BigInt(1),J0=BigInt(2),wa=BigInt(3),Q0=BigInt(4);function Jf(r){let t=Xf(r),{Fp:e}=t,n=se(t.n,t.nBitLength),o=t.toBytes||((g,h,w)=>{let v=h.toAffine();return ge(Uint8Array.from([4]),e.toBytes(v.x),e.toBytes(v.y))}),s=t.fromBytes||(g=>{let h=g.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(g){let{a:h,b:w}=t,v=e.sqr(g),y=e.mul(v,g);return e.add(e.add(y,e.mul(g,h)),w)}if(!e.eql(e.sqr(t.Gy),i(t.Gx)))throw new Error("bad generator point: equation left != right");function c(g){return nn(g,dt,t.n)}function a(g){let{allowedPrivateKeyLengths:h,nByteLength:w,wrapPrivateKey:v,n:y}=t;if(h&&typeof g!="bigint"){if(Pe(g)&&(g=ye(g)),typeof g!="string"||!h.includes(g.length))throw new Error("invalid private key");g=g.padStart(w*2,"0")}let I;try{I=typeof g=="bigint"?g:ne(tt("private key",g,w))}catch{throw new Error("invalid private key, expected hex or "+w+" bytes, got "+typeof g)}return v&&(I=W(I,y)),Tt("private key",I,dt,y),I}function u(g){if(!(g instanceof d))throw new Error("ProjectivePoint expected")}let f=We((g,h)=>{let{px:w,py:v,pz:y}=g;if(e.eql(y,e.ONE))return{x:w,y:v};let I=g.is0();h==null&&(h=I?e.ONE:e.inv(y));let D=e.mul(w,h),L=e.mul(v,h),P=e.mul(y,h);if(I)return{x:e.ZERO,y:e.ZERO};if(!e.eql(P,e.ONE))throw new Error("invZ was invalid");return{x:D,y:L}}),l=We(g=>{if(g.is0()){if(t.allowInfinityPoint&&!e.is0(g.py))return;throw new Error("bad point: ZERO")}let{x:h,y:w}=g.toAffine();if(!e.isValid(h)||!e.isValid(w))throw new Error("bad point: x or y not FE");let v=e.sqr(w),y=i(h);if(!e.eql(v,y))throw new Error("bad point: equation left != right");if(!g.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class d{constructor(h,w,v){if(h==null||!e.isValid(h))throw new Error("x required");if(w==null||!e.isValid(w)||e.is0(w))throw new Error("y required");if(v==null||!e.isValid(v))throw new Error("z required");this.px=h,this.py=w,this.pz=v,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 y=I=>e.eql(I,e.ZERO);return y(w)&&y(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=Ye(e,h.map(v=>v.pz));return h.map((v,y)=>v.toAffine(w[y])).map(d.fromAffine)}static fromHex(h){let w=d.fromAffine(s(tt("pointHex",h)));return w.assertValidity(),w}static fromPrivateKey(h){return d.BASE.multiply(a(h))}static msm(h,w){return an(d,n,h,w)}_setWindowSize(h){m.setWindowSize(this,h)}assertValidity(){l(this)}hasEvenY(){let{y:h}=this.toAffine();if(e.isOdd)return!e.isOdd(h);throw new Error("Field doesn't support isOdd")}equals(h){u(h);let{px:w,py:v,pz:y}=this,{px:I,py:D,pz:L}=h,P=e.eql(e.mul(w,L),e.mul(I,y)),C=e.eql(e.mul(v,L),e.mul(D,y));return P&&C}negate(){return new d(this.px,e.neg(this.py),this.pz)}double(){let{a:h,b:w}=t,v=e.mul(w,wa),{px:y,py:I,pz:D}=this,L=e.ZERO,P=e.ZERO,C=e.ZERO,_=e.mul(y,y),X=e.mul(I,I),G=e.mul(D,D),N=e.mul(y,I);return N=e.add(N,N),C=e.mul(y,D),C=e.add(C,C),L=e.mul(h,C),P=e.mul(v,G),P=e.add(L,P),L=e.sub(X,P),P=e.add(X,P),P=e.mul(L,P),L=e.mul(N,L),C=e.mul(v,C),G=e.mul(h,G),N=e.sub(_,G),N=e.mul(h,N),N=e.add(N,C),C=e.add(_,_),_=e.add(C,_),_=e.add(_,G),_=e.mul(_,N),P=e.add(P,_),G=e.mul(I,D),G=e.add(G,G),_=e.mul(G,N),L=e.sub(L,_),C=e.mul(G,X),C=e.add(C,C),C=e.add(C,C),new d(L,P,C)}add(h){u(h);let{px:w,py:v,pz:y}=this,{px:I,py:D,pz:L}=h,P=e.ZERO,C=e.ZERO,_=e.ZERO,X=t.a,G=e.mul(t.b,wa),N=e.mul(w,I),at=e.mul(v,D),A=e.mul(y,L),B=e.add(w,v),T=e.add(I,D);B=e.mul(B,T),T=e.add(N,at),B=e.sub(B,T),T=e.add(w,y);let x=e.add(I,L);return T=e.mul(T,x),x=e.add(N,A),T=e.sub(T,x),x=e.add(v,y),P=e.add(D,L),x=e.mul(x,P),P=e.add(at,A),x=e.sub(x,P),_=e.mul(X,T),P=e.mul(G,A),_=e.add(P,_),P=e.sub(at,_),_=e.add(at,_),C=e.mul(P,_),at=e.add(N,N),at=e.add(at,N),A=e.mul(X,A),T=e.mul(G,T),at=e.add(at,A),A=e.sub(N,A),A=e.mul(X,A),T=e.add(T,A),N=e.mul(at,T),C=e.add(C,N),N=e.mul(x,T),P=e.mul(B,P),P=e.sub(P,N),N=e.mul(B,at),_=e.mul(x,_),_=e.add(_,N),new d(P,C,_)}subtract(h){return this.add(h.negate())}is0(){return this.equals(d.ZERO)}wNAF(h){return m.wNAFCached(this,h,d.normalizeZ)}multiplyUnsafe(h){let{endo:w,n:v}=t;Tt("scalar",h,ce,v);let y=d.ZERO;if(h===ce)return y;if(this.is0()||h===dt)return this;if(!w||m.hasPrecomputes(this))return m.wNAFCachedUnsafe(this,h,d.normalizeZ);let{k1neg:I,k1:D,k2neg:L,k2:P}=w.splitScalar(h),C=y,_=y,X=this;for(;D>ce||P>ce;)D&dt&&(C=C.add(X)),P&dt&&(_=_.add(X)),X=X.double(),D>>=dt,P>>=dt;return I&&(C=C.negate()),L&&(_=_.negate()),_=new d(e.mul(_.px,w.beta),_.py,_.pz),C.add(_)}multiply(h){let{endo:w,n:v}=t;Tt("scalar",h,dt,v);let y,I;if(w){let{k1neg:D,k1:L,k2neg:P,k2:C}=w.splitScalar(h),{p:_,f:X}=this.wNAF(L),{p:G,f:N}=this.wNAF(C);_=m.constTimeNegate(D,_),G=m.constTimeNegate(P,G),G=new d(e.mul(G.px,w.beta),G.py,G.pz),y=_.add(G),I=X.add(N)}else{let{p:D,f:L}=this.wNAF(h);y=D,I=L}return d.normalizeZ([y,I])[0]}multiplyAndAddUnsafe(h,w,v){let y=d.BASE,I=(L,P)=>P===ce||P===dt||!L.equals(y)?L.multiplyUnsafe(P):L.multiply(P),D=I(this,w).add(I(h,v));return D.is0()?void 0:D}toAffine(h){return f(this,h)}isTorsionFree(){let{h,isTorsionFree:w}=t;if(h===dt)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===dt?this:w?w(d,this):this.multiplyUnsafe(t.h)}toRawBytes(h=!0){return $t("isCompressed",h),this.assertValidity(),o(d,this,h)}toHex(h=!0){return $t("isCompressed",h),ye(this.toRawBytes(h))}}d.BASE=new d(t.Gx,t.Gy,e.ONE),d.ZERO=new d(e.ZERO,e.ONE,e.ZERO);let b=t.nBitLength,m=sn(d,t.endo?Math.ceil(b/2):b);return{CURVE:t,ProjectivePoint:d,normPrivateKeyToScalar:a,weierstrassEquation:i,isWithinCurveOrder:c}}function Qf(r){let t=Sr(r);return oe(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function Ea(r){let t=Qf(r),{Fp:e,n}=t,o=e.BYTES+1,s=2*e.BYTES+1;function i(A){return W(A,n)}function c(A){return on(A,n)}let{ProjectivePoint:a,normPrivateKeyToScalar:u,weierstrassEquation:f,isWithinCurveOrder:l}=Jf({...t,toBytes(A,B,T){let x=B.toAffine(),p=e.toBytes(x.x),E=ge;return $t("isCompressed",T),T?E(Uint8Array.from([B.hasEvenY()?2:3]),p):E(Uint8Array.from([4]),p,e.toBytes(x.y))},fromBytes(A){let B=A.length,T=A[0],x=A.subarray(1);if(B===o&&(T===2||T===3)){let p=ne(x);if(!nn(p,dt,e.ORDER))throw new Error("Point is not on curve");let E=f(p),S;try{S=e.sqrt(E)}catch(K){let M=K instanceof Error?": "+K.message:"";throw new Error("Point is not on curve"+M)}let R=(S&dt)===dt;return(T&1)===1!==R&&(S=e.neg(S)),{x:p,y:S}}else if(B===s&&T===4){let p=e.fromBytes(x.subarray(0,e.BYTES)),E=e.fromBytes(x.subarray(e.BYTES,2*e.BYTES));return{x:p,y:E}}else{let p=o,E=s;throw new Error("invalid Point, expected length of "+p+", or uncompressed "+E+", got "+B)}}}),d=A=>ye(_e(A,t.nByteLength));function b(A){let B=n>>dt;return A>B}function m(A){return b(A)?i(-A):A}let g=(A,B,T)=>ne(A.slice(B,T));class h{constructor(B,T,x){Tt("r",B,dt,n),Tt("s",T,dt,n),this.r=B,this.s=T,x!=null&&(this.recovery=x),Object.freeze(this)}static fromCompact(B){let T=t.nByteLength;return B=tt("compactSignature",B,T*2),new h(g(B,0,T),g(B,T,2*T))}static fromDER(B){let{r:T,s:x}=ae.toSig(tt("DER",B));return new h(T,x)}assertValidity(){}addRecoveryBit(B){return new h(this.r,this.s,B)}recoverPublicKey(B){let{r:T,s:x,recovery:p}=this,E=L(tt("msgHash",B));if(p==null||![0,1,2,3].includes(p))throw new Error("recovery id invalid");let S=p===2||p===3?T+t.n:T;if(S>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let R=(p&1)===0?"02":"03",O=a.fromHex(R+d(S)),K=c(S),M=i(-E*K),q=i(x*K),Z=a.BASE.multiplyAndAddUnsafe(O,M,q);if(!Z)throw new Error("point at infinify");return Z.assertValidity(),Z}hasHighS(){return b(this.s)}normalizeS(){return this.hasHighS()?new h(this.r,i(-this.s),this.recovery):this}toDERRawBytes(){return Ar(this.toDERHex())}toDERHex(){return ae.hexFromSig(this)}toCompactRawBytes(){return Ar(this.toCompactHex())}toCompactHex(){return d(this.r)+d(this.s)}}let w={isValidPrivateKey(A){try{return u(A),!0}catch{return!1}},normPrivateKeyToScalar:u,randomPrivateKey:()=>{let A=To(t.n);return Hi(t.randomBytes(A),t.n)},precompute(A=8,B=a.BASE){return B._setWindowSize(A),B.multiply(BigInt(3)),B}};function v(A,B=!0){return a.fromPrivateKey(A).toRawBytes(B)}function y(A){let B=Pe(A),T=typeof A=="string",x=(B||T)&&A.length;return B?x===o||x===s:T?x===2*o||x===2*s:A instanceof a}function I(A,B,T=!0){if(y(A))throw new Error("first arg must be private key");if(!y(B))throw new Error("second arg must be public key");return a.fromHex(B).multiply(u(A)).toRawBytes(T)}let D=t.bits2int||function(A){if(A.length>8192)throw new Error("input is too large");let B=ne(A),T=A.length*8-t.nBitLength;return T>0?B>>BigInt(T):B},L=t.bits2int_modN||function(A){return i(D(A))},P=Te(t.nBitLength);function C(A){return Tt("num < 2^"+t.nBitLength,A,ce,P),_e(A,t.nByteLength)}function _(A,B,T=X){if(["recovered","canonical"].some(rt=>rt in T))throw new Error("sign() legacy options not supported");let{hash:x,randomBytes:p}=t,{lowS:E,prehash:S,extraEntropy:R}=T;E==null&&(E=!0),A=tt("msgHash",A),xa(T),S&&(A=tt("prehashed msgHash",x(A)));let O=L(A),K=u(B),M=[C(K),C(O)];if(R!=null&&R!==!1){let rt=R===!0?p(e.BYTES):R;M.push(tt("extraEntropy",rt))}let q=ge(...M),Z=O;function st(rt){let ht=D(rt);if(!l(ht))return;let St=c(ht),ft=a.BASE.multiply(ht).toAffine(),yt=i(ft.x);if(yt===ce)return;let Ct=i(St*i(Z+yt*K));if(Ct===ce)return;let Rt=(ft.x===yt?0:2)|Number(ft.y&dt),cr=Ct;return E&&b(Ct)&&(cr=m(Ct),Rt^=1),new h(yt,cr,Rt)}return{seed:q,k2sig:st}}let X={lowS:t.lowS,prehash:!1},G={lowS:t.lowS,prehash:!1};function N(A,B,T=X){let{seed:x,k2sig:p}=_(A,B,T),E=t;return Ki(E.hash.outputLen,E.nByteLength,E.hmac)(x,p)}a.BASE._setWindowSize(8);function at(A,B,T,x=G){let p=A;B=tt("msgHash",B),T=tt("publicKey",T);let{lowS:E,prehash:S,format:R}=x;if(xa(x),"strict"in x)throw new Error("options.strict was renamed to lowS");if(R!==void 0&&R!=="compact"&&R!=="der")throw new Error("format must be compact or der");let O=typeof p=="string"||Pe(p),K=!O&&!R&&typeof p=="object"&&p!==null&&typeof p.r=="bigint"&&typeof p.s=="bigint";if(!O&&!K)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let M,q;try{if(K&&(M=new h(p.r,p.s)),O){try{R!=="compact"&&(M=h.fromDER(p))}catch(Rt){if(!(Rt instanceof ae.Err))throw Rt}!M&&R!=="der"&&(M=h.fromCompact(p))}q=a.fromHex(T)}catch{return!1}if(!M||E&&M.hasHighS())return!1;S&&(B=t.hash(B));let{r:Z,s:st}=M,rt=L(B),ht=c(st),St=i(rt*ht),ft=i(Z*ht),yt=a.BASE.multiplyAndAddUnsafe(q,St,ft)?.toAffine();return yt?i(yt.x)===Z:!1}return{CURVE:t,getPublicKey:v,getSharedSecret:I,sign:N,verify:at,ProjectivePoint:a,Signature:h,utils:w}}function tl(r){return{hash:r,hmac:(t,...e)=>ps(r,t,go(...e)),randomBytes:Qr}}function Aa(r,t){let e=n=>Ea({...r,...tl(n)});return{...e(t),create:e}}var Ia=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Sa=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),el=BigInt(1),ys=BigInt(2),va=(r,t)=>(r+t/ys)/t;function rl(r){let t=Ia,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),u=r*r*r%t,f=u*u*r%t,l=J(f,e,t)*f%t,d=J(l,e,t)*f%t,b=J(d,ys,t)*u%t,m=J(b,o,t)*b%t,g=J(m,s,t)*m%t,h=J(g,c,t)*g%t,w=J(h,a,t)*h%t,v=J(w,c,t)*g%t,y=J(v,e,t)*f%t,I=J(y,i,t)*m%t,D=J(I,n,t)*u%t,L=J(D,ys,t);if(!gs.eql(gs.sqr(L),r))throw new Error("Cannot find square root");return L}var gs=se(Ia,void 0,void 0,{sqrt:rl}),Oe=Aa({a:BigInt(0),b:BigInt(7),Fp:gs,n:Sa,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Sa,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-el*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),c=va(s*r,t),a=va(-n*r,t),u=W(r-c*e-a*o,t),f=W(-c*n-a*s,t),l=u>i,d=f>i;if(l&&(u=t-u),d&&(f=t-f),u>i||f>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:l,k1:u,k2neg:d,k2:f}}}},rn),cm=BigInt(0);var um=Oe.ProjectivePoint;function Ba(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Pa(r,t,e){let n=hr.digest(e instanceof Uint8Array?e:e.subarray());if(Ba(n))return n.then(({digest:o})=>Oe.verify(t,o,r)).catch(o=>{throw new Br(String(o))});try{return Oe.verify(t,n.digest,r)}catch(o){throw new Br(String(o))}}var gn=class{type="secp256k1";raw;_key;constructor(t){this._key=_a(t),this.raw=Ca(this._key)}toMultihash(){return Nt.digest(zt(this))}toCID(){return it.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}verify(t,e){return Pa(this._key,e,t)}};function bs(r){return new gn(r)}function Ca(r){return Oe.ProjectivePoint.fromHex(r).toRawBytes(!0)}function _a(r){try{return Oe.ProjectivePoint.fromHex(r),r}catch(t){throw new Fe(String(t))}}function Qe(r,t){let{Type:e,Data:n}=jt.decode(r),o=n??new Uint8Array;switch(e){case ot.RSA:return ls(o,t);case ot.Ed25519:return ko(o);case ot.secp256k1:return bs(o);case ot.ECDSA:return yo(o);default:throw new Ee}}function Ta(r){let{Type:t,Data:e}=jt.decode(r.digest),n=e??new Uint8Array;switch(t){case ot.Ed25519:return ko(n);case ot.secp256k1:return bs(n);case ot.ECDSA:return yo(n);default:throw new Ee}}function zt(r){return jt.encode({Type:ot[r.type],Data:r.raw})}var _r;(function(r){let t;r.codec=()=>(t==null&&(t=Vt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.publicKey!=null&&e.publicKey.byteLength>0&&(n.uint32(10),n.bytes(e.publicKey)),e.payloadType!=null&&e.payloadType.byteLength>0&&(n.uint32(18),n.bytes(e.payloadType)),e.payload!=null&&e.payload.byteLength>0&&(n.uint32(26),n.bytes(e.payload)),e.signature!=null&&e.signature.byteLength>0&&(n.uint32(42),n.bytes(e.signature)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={publicKey:pt(0),payloadType:pt(0),payload:pt(0),signature:pt(0)},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let c=e.uint32();switch(c>>>3){case 1:{s.publicKey=e.bytes();break}case 2:{s.payloadType=e.bytes();break}case 3:{s.payload=e.bytes();break}case 5:{s.signature=e.bytes();break}default:{e.skipType(c&7);break}}}return s})),t),r.encode=e=>Ft(e,r.codec()),r.decode=(e,n)=>Mt(e,r.codec(),n)})(_r||(_r={}));var bn=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var Wt=class r{static createFromProtobuf=async t=>{let e=_r.decode(t),n=Qe(e.publicKey);return new r({publicKey:n,payloadType:e.payloadType,payload:e.payload,signature:e.signature})};static seal=async(t,e)=>{if(e==null)throw new Error("Missing private key");let n=t.domain,o=t.codec,s=t.marshal(),i=La(n,o,s),c=await e.sign(i.subarray());return new r({publicKey:e.publicKey,payloadType:o,payload:s,signature:c})};static openAndCertify=async(t,e)=>{let n=await r.createFromProtobuf(t);if(!await n.validate(e))throw new bn("Envelope signature is not valid for the given domain");return n};publicKey;payloadType;payload;signature;marshaled;constructor(t){let{publicKey:e,payloadType:n,payload:o,signature:s}=t;this.publicKey=e,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=_r.encode({publicKey:zt(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return lt(this.marshal(),t.marshal())}async validate(t){let e=La(t,this.payloadType,this.payload);return this.publicKey.verify(e.subarray(),this.signature)}},La=(r,t,e)=>{let n=k(r),o=Dt(n.byteLength),s=Dt(t.length),i=Dt(e.length);return new nt(o,n,s,t,i,e)};var Da=Symbol.for("nodejs.util.inspect.custom"),nl=114,Tr=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()})`}[Vn]=!0;toString(){return this.string==null&&(this.string=Y.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return it.createV1(nl,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return lt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return lt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Da](){return`PeerId(${this.toString()})`}},Lr=class extends Tr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Dr=class extends Tr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Rr=class extends Tr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},ol=2336,Ur=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Nt.digest(k(this.url))}[Da](){return`PeerId(${this.url})`}[Vn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return it.createV1(ol,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=U(t)),t.toString()===this.toString())}};var sl=114,Ra=2336;function Ua(r){if(r.type==="Ed25519")return new Dr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new Rr({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new Lr({multihash:r.toCID().multihash,publicKey:r});throw new Ee}function xs(r){if(al(r))return new Lr({multihash:r});if(il(r))try{let t=Ta(r);if(t.type==="Ed25519")return new Dr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new Rr({multihash:r,publicKey:t})}catch{let e=U(r.digest);return new Ur(new URL(e))}throw new zr("Supplied PeerID Multihash is invalid")}function xn(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==sl&&r.code!==Ra)throw new Hr("Supplied PeerID CID is invalid");if(r.code===Ra){let t=U(r.multihash.digest);return new Ur(new URL(t))}return xs(r.multihash)}function il(r){return r.code===Nt.code}function al(r){return r.code===hr.code}function Oa(r,t){let e=(n,o)=>n.toString().localeCompare(o.toString());return r.length!==t.length?!1:(t.sort(e),r.sort(e).every((n,o)=>t[o].equals(n)))}var wn=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,c=this.peekChar();if(c===void 0)return;let a=c==="0",u=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let d=Number.parseInt(l,t);if(!Number.isNaN(d))return d});if(f===void 0)break;if(s*=t,s+=f,s>u||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&a&&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),[c]=t(s.subarray(0,i));return e.set(s.subarray(0,c),16-c),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Na=45,cl=15,tr=new wn;function En(r){if(!(r.length>cl))return tr.new(r).parseWith(()=>tr.readIPv4Addr())}function An(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Na))return tr.new(r).parseWith(()=>tr.readIPv6Addr())}function Ne(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>Na)return;let e=tr.new(r).parseWith(()=>tr.readIPAddr());if(e)return t&&e.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,e[0],e[1],e[2],e[3]]):e}function Ka(r,t,e){let n=0;for(let o of r)if(!(n<t)){if(n>e)break;if(o!==255)return!1;n++}return!0}function ka(r,t,e,n){let o=0;for(let s of r)if(!(o<e)){if(o>n)break;if(s!==t[o])return!1;o++}return!0}function ws(r){switch(r.length){case Ke:return r.join(".");case ke:{let t=[];for(let e=0;e<r.length;e++)e%2===0&&t.push(r[e].toString(16).padStart(2,"0")+r[e+1].toString(16).padStart(2,"0"));return t.join(":")}default:throw new Error("Invalid ip length")}}function Ma(r){let t=0;for(let[e,n]of r.entries()){if(n===255){t+=8;continue}for(;(n&128)!=0;)t++,n=n<<1;if((n&128)!=0)return-1;for(let o=e+1;o<r.length;o++)if(r[o]!=0)return-1;break}return t}function Fa(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var Ke=4,ke=16,Ry=parseInt("0xFFFF",16),ul=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Or(r,t){t.length===ke&&r.length===Ke&&Ka(t,0,11)&&(t=t.slice(12)),t.length===Ke&&r.length===ke&&ka(r,ul,0,11)&&(r=r.slice(12));let e=r.length;if(e!=t.length)throw new Error("Failed to mask ip");let n=new Uint8Array(e);for(let o=0;o<e;o++)n[o]=r[o]&t[o];return n}function Va(r,t){if(typeof t=="string"&&(t=Ne(t)),t==null)throw new Error("Invalid ip");if(t.length!==r.network.length)return!1;for(let e=0;e<t.length;e++)if((r.network[e]&r.mask[e])!==(t[e]&r.mask[e]))return!1;return!0}function Es(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=Ke,o=En(t);if(o==null&&(n=ke,o=An(t),o==null))throw new Error("Failed to parse given CIDR: "+r);let s=parseInt(e,10);if(Number.isNaN(s)||String(s).length!==e.length||s<0||s>n*8)throw new Error("Failed to parse given CIDR: "+r);let i=As(s,8*n);return{network:Or(o,i),mask:i}}function As(r,t){if(t!==8*Ke&&t!==8*ke)throw new Error("Invalid CIDR mask");if(r<0||r>t)throw new Error("Invalid CIDR mask");let e=t/8,n=new Uint8Array(e);for(let o=0;o<e;o++){if(r>=8){n[o]=255,r-=8;continue}n[o]=255-(255>>r),r=0}return n}var er=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=Es(t));else{let n=Ne(t);if(n==null)throw new Error("Failed to parse network");e=String(e);let o=parseInt(e,10);if(Number.isNaN(o)||String(o).length!==e.length||o<0||o>n.length*8){let s=Ne(e);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=As(o,8*n.length);this.network=Or(n,this.mask)}}contains(t){return Va({network:this.network,mask:this.mask},t)}toString(){let t=Ma(this.mask),e=t!==-1?String(t):Fa(this.mask);return ws(this.network)+"/"+e}};function qa(r,t){return new er(r).contains(t)}function rr(r){return!!En(r)}function nr(r){return!!An(r)}function Sn(r){return!!Ne(r)}var Ha=rr,fl=nr,Ss=function(r){let t=0;if(r=r.toString().trim(),Ha(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(fl(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=Ha(e[n]),i;s&&(i=Ss(e[n]),e[n]=U(i.slice(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,U(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")},za=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 or={},vs={},dl=[[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"]];dl.forEach(r=>{let t=hl(...r);vs[t.code]=t,or[t.name]=t});function hl(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function H(r){if(typeof r=="number"){if(vs[r]!=null)return vs[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(or[r]!=null)return or[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var dg=H("ip4"),hg=H("ip6"),pg=H("ipcidr");function Cs(r,t){switch(H(r).code){case 4:case 41:return ml(t);case 42:return Ps(t);case 43:return U(t,"base10");case 6:case 273:case 33:case 132:return Za(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Ps(t);case 421:return xl(t);case 444:return $a(t);case 445:return $a(t);case 466:return bl(t);case 481:return globalThis.encodeURIComponent(Ps(t));default:return U(t,"base16")}}function _s(r,t){switch(H(r).code){case 4:return Ga(t);case 41:return Ga(t);case 42:return Bs(t);case 43:return k(t,"base10");case 6:case 273:case 33:case 132:return Ts(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Bs(t);case 421:return yl(t);case 444:return wl(t);case 445:return El(t);case 466:return gl(t);case 481:return Bs(globalThis.decodeURIComponent(t));default:return k(t,"base16")}}var Is=Object.values(pr).map(r=>r.decoder),pl=function(){let r=Is[0].or(Is[1]);return Is.slice(2).forEach(t=>r=r.or(t)),r}();function Ga(r){if(!Sn(r))throw new Error("invalid ip address");return Ss(r)}function ml(r){let t=za(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!Sn(t))throw new Error("invalid ip address");return t}function Ts(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Za(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Bs(r){let t=k(r),e=Uint8Array.from(Dt(t.length));return _t([e,t],e.length+t.length)}function Ps(r){let t=ie(r);if(r=r.slice(bt(t)),r.length!==t)throw new Error("inconsistent lengths");return U(r)}function yl(r){let t;r[0]==="Q"||r[0]==="1"?t=Ae(Y.decode(`z${r}`)).bytes:t=it.parse(r).multihash.bytes;let e=Uint8Array.from(Dt(t.length));return _t([e,t],e.length+t.length)}function gl(r){let t=pl.decode(r),e=Uint8Array.from(Dt(t.length));return _t([e,t],e.length+t.length)}function bl(r){let t=ie(r),e=r.slice(bt(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+U(e,"base64url")}function xl(r){let t=ie(r),e=r.slice(bt(t));if(e.length!==t)throw new Error("inconsistent lengths");return U(e,"base58btc")}function wl(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=Jt.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=Ts(n);return _t([e,o],e.length+o.length)}function El(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=Jt.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=Ts(n);return _t([e,o],e.length+o.length)}function $a(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=U(t,"base32"),o=Za(e);return`${n}:${o}`}function ja(r){r=Ls(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],c=H(i);if(c.size===0){t.push([c.code]),e.push([c.code]);continue}if(s++,s>=o.length)throw new vn("invalid address: "+r);if(c.path===!0){n=Ls(o.slice(s).join("/")),t.push([c.code,_s(c.code,n)]),e.push([c.code,n]);break}let a=_s(c.code,o[s]);t.push([c.code,a]),e.push([c.code,Cs(c.code,a)])}return{string:Wa(e),bytes:In(t),tuples:t,stringTuples:e,path:n}}function Ds(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let s=ie(r,o),i=bt(s),c=H(s),a=Al(c,r.slice(o+i));if(a===0){t.push([s]),e.push([s]),o+=i;continue}let u=r.slice(o+i,o+i+a);if(o+=a+i,o>r.length)throw new vn("Invalid address Uint8Array: "+U(r,"base16"));t.push([s,u]);let f=Cs(s,u);if(e.push([s,f]),c.path===!0){n=f;break}}return{bytes:Uint8Array.from(r),string:Wa(e),tuples:t,stringTuples:e,path:n}}function Wa(r){let t=[];return r.map(e=>{let n=H(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),Ls(t.join("/"))}function In(r){return _t(r.map(t=>{let e=H(t[0]),n=Uint8Array.from(Dt(e.code));return t.length>1&&t[1]!=null&&(n=_t([n,t[1]])),n}))}function Al(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=ie(t instanceof Uint8Array?t:Uint8Array.from(t));return e+bt(e)}}function Ls(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}var vn=class extends Error{static name="ParseError";name="ParseError";constructor(t){super(`Error parsing address: ${t}`)}};var Sl=Symbol.for("nodejs.util.inspect.custom"),Us=Symbol.for("@multiformats/js-multiaddr/multiaddr"),vl=[H("dns").code,H("dns4").code,H("dns6").code,H("dnsaddr").code],Rs=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},Bn=class r{bytes;#e;#t;#r;#n;[Us]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=Ds(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=ja(t)}else if(Xa(t))e=Ds(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=H("tcp"),c=H("udp"),a=H("ip4"),u=H("ip6"),f=H("dns6"),l=H("ip6zone");for(let[b,m]of this.stringTuples())b===l.code&&(s=`%${m??""}`),vl.includes(b)&&(e=i.name==="tcp"?"tcp":"udp",o=443,n=`${m??""}${s}`,t=b===f.code?6:4),(b===i.code||b===c.code)&&(e=H(b).name==="tcp"?"tcp":"udp",o=parseInt(m??"")),(b===a.code||b===u.code)&&(e=H(b).name==="tcp"?"tcp":"udp",n=`${m??""}${s}`,t=b===u.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({},H(t)))}protoCodes(){return this.#t.map(([t])=>t)}protoNames(){return this.#t.map(([t])=>H(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(In(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===or.p2p.code&&t.push([n,o]),n===or["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?U(Y.decode(`z${n}`),"base58btc"):U(it.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return lt(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(s=>s.resolvable);if(e==null)return[this];let n=Ya.get(e.name);if(n==null)throw new Rs(`no available resolver for ${e.name}`);return(await n(this,t)).map(s=>Yt(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)}[Sl](){return`Multiaddr(${this.#e})`}};var Ya=new Map;function Xa(r){return!!r?.[Us]}function Yt(r){return new Bn(r)}var Ja="libp2p-peer-record",Qa=Uint8Array.from([3,1]);var Nr;(function(r){let t;(function(n){let o;n.codec=()=>(o==null&&(o=Vt((s,i,c={})=>{c.lengthDelimited!==!1&&i.fork(),s.multiaddr!=null&&s.multiaddr.byteLength>0&&(i.uint32(10),i.bytes(s.multiaddr)),c.lengthDelimited!==!1&&i.ldelim()},(s,i,c={})=>{let a={multiaddr:pt(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{a.multiaddr=s.bytes();break}default:{s.skipType(f&7);break}}}return a})),o),n.encode=s=>Ft(s,n.codec()),n.decode=(s,i)=>Mt(s,n.codec(),i)})(t=r.AddressInfo||(r.AddressInfo={}));let e;r.codec=()=>(e==null&&(e=Vt((n,o,s={})=>{if(s.lengthDelimited!==!1&&o.fork(),n.peerId!=null&&n.peerId.byteLength>0&&(o.uint32(10),o.bytes(n.peerId)),n.seq!=null&&n.seq!==0n&&(o.uint32(16),o.uint64(n.seq)),n.addresses!=null)for(let i of n.addresses)o.uint32(26),r.AddressInfo.codec().encode(i,o);s.lengthDelimited!==!1&&o.ldelim()},(n,o,s={})=>{let i={peerId:pt(0),seq:0n,addresses:[]},c=o==null?n.len:n.pos+o;for(;n.pos<c;){let a=n.uint32();switch(a>>>3){case 1:{i.peerId=n.bytes();break}case 2:{i.seq=n.uint64();break}case 3:{if(s.limits?.addresses!=null&&i.addresses.length===s.limits.addresses)throw new Ue('Decode error - map field "addresses" had too many elements');i.addresses.push(r.AddressInfo.codec().decode(n,n.uint32(),{limits:s.limits?.addresses$}));break}default:{n.skipType(a&7);break}}}return i})),e),r.encode=n=>Ft(n,r.codec()),r.decode=(n,o)=>Mt(n,r.codec(),o)})(Nr||(Nr={}));var qt=class r{static createFromProtobuf=t=>{let e=Nr.decode(t),n=xs(Ae(e.peerId)),o=(e.addresses??[]).map(i=>Yt(i.multiaddr)),s=e.seq;return new r({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=Ja;static CODEC=Qa;peerId;multiaddrs;seqNumber;domain=r.DOMAIN;codec=r.CODEC;marshaled;constructor(t){let{peerId:e,multiaddrs:n,seqNumber:o}=t;this.peerId=e,this.multiaddrs=n??[],this.seqNumber=o??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=Nr.encode({peerId:this.peerId.toMultihash().bytes,seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(t=>({multiaddr:t.bytes}))})),this.marshaled}equals(t){return!(!(t instanceof r)||!this.peerId.equals(t.peerId)||this.seqNumber!==t.seqNumber||!Oa(this.multiaddrs,t.multiaddrs))}};function Il(r){return r[Symbol.asyncIterator]!=null}function Bl(r){if(Il(r))return(async()=>{for await(let t of r);})();for(let t of r);}var tc=Bl;function Ht(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Pn=globalThis.CustomEvent??Event;async function*Os(r,t={}){let e=t.concurrency??1/0;e<1&&(e=1/0);let n=t.ordered??!1,o=new EventTarget,s=[],i=Ht(),c=Ht(),a=!1,u,f=!1;o.addEventListener("task-complete",()=>{c.resolve()}),Promise.resolve().then(async()=>{try{for await(let m of r){if(s.length===e&&(i=Ht(),await i.promise),f)break;let g={done:!1};s.push(g),m().then(h=>{g.done=!0,g.ok=!0,g.value=h,o.dispatchEvent(new Pn("task-complete"))},h=>{g.done=!0,g.err=h,o.dispatchEvent(new Pn("task-complete"))})}a=!0,o.dispatchEvent(new Pn("task-complete"))}catch(m){u=m,o.dispatchEvent(new Pn("task-complete"))}});function l(){return n?s[0]?.done:!!s.find(m=>m.done)}function*d(){for(;s.length>0&&s[0].done;){let m=s[0];if(s.shift(),m.ok)yield m.value;else throw f=!0,i.resolve(),m.err;i.resolve()}}function*b(){for(;l();)for(let m=0;m<s.length;m++)if(s[m].done){let g=s[m];if(s.splice(m,1),m--,g.ok)yield g.value;else throw f=!0,i.resolve(),g.err;i.resolve()}}for(;;){if(l()||(c=Ht(),await c.promise),u!=null||(n?yield*d():yield*b(),u!=null))throw u;if(a&&s.length===0)break}}var Cn=class extends Error{type;code;constructor(t,e,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=e??"ABORT_ERR"}};async function Kr(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new Cn(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new Cn(e?.errorMessage,e?.errorCode,e?.errorName);try{return await Promise.race([r,new Promise((s,i)=>{n=()=>{i(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var Ns=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=Ht(),this.haveNext=Ht()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=Ht(),t}async throw(t){return this.ended=!0,this.error=t,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return this.ended=!0,this.nextResult=t,this.haveNext.resolve(),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=Ht(),await Kr(this.readNext.promise,e?.signal,e)}};function ec(){return new Ns}var _n=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function rc(r,t){let e=ec();r.sink(e).catch(async i=>{await e.end(i)}),r.sink=async i=>{for await(let c of i)await e.push(c);await e.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let o=new nt;return{read:async i=>{if(i?.signal?.throwIfAborted(),i?.bytes==null){let{done:a,value:u}=await Kr(n.next(),i?.signal);return a===!0?null:u}for(;o.byteLength<i.bytes;){let{value:a,done:u}=await Kr(n.next(),i?.signal);if(u===!0)throw new _n("unexpected end of input");o.append(a)}let c=o.sublist(0,i.bytes);return o.consume(i.bytes),c},write:async(i,c)=>{c?.signal?.throwIfAborted(),i instanceof Uint8Array?await e.push(i,c):await e.push(i.subarray(),c)},unwrap:()=>{if(o.byteLength>0){let i=r.source;r.source=async function*(){t?.yieldBytes===!1?yield o:yield*o,yield*i}()}return r}}}var Tn=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Ln=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Dn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function nc(r,t={}){let e=rc(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=bt(t.maxDataLength));let n=t?.lengthDecoder??ie,o=t?.lengthEncoder??Dt;return{read:async i=>{let c=-1,a=new nt;for(;;){a.append(await e.read({...i,bytes:1}));try{c=n(a)}catch(u){if(u instanceof RangeError)continue;throw u}if(c<0)throw new Tn("Invalid message length");if(t?.maxLengthLength!=null&&a.byteLength>t.maxLengthLength)throw new Dn("message length length too long");if(c>-1)break}if(t?.maxDataLength!=null&&c>t.maxDataLength)throw new Ln("message length too long");return e.read({...i,bytes:c})},write:async(i,c)=>{await e.write(new nt(o(i.byteLength),i),c)},writeV:async(i,c)=>{let a=new nt(...i.flatMap(u=>[o(u.byteLength),u]));await e.write(a,c)},unwrap:()=>e.unwrap()}}function sr(r,t){let e=nc(r,t),n={read:async(o,s)=>{let i=await e.read(s);return o.decode(i)},write:async(o,s,i)=>{await e.write(s.encode(o),i)},writeV:async(o,s,i)=>{await e.writeV(o.map(c=>s.encode(c)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var oc="0.1.0",sc="id",ic="id/push",ac="1.0.0",cc="1.0.0";var we;(function(r){let t;r.codec=()=>(t==null&&(t=Vt((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.protocolVersion!=null&&(n.uint32(42),n.string(e.protocolVersion)),e.agentVersion!=null&&(n.uint32(50),n.string(e.agentVersion)),e.publicKey!=null&&(n.uint32(10),n.bytes(e.publicKey)),e.listenAddrs!=null)for(let s of e.listenAddrs)n.uint32(18),n.bytes(s);if(e.observedAddr!=null&&(n.uint32(34),n.bytes(e.observedAddr)),e.protocols!=null)for(let s of e.protocols)n.uint32(26),n.string(s);e.signedPeerRecord!=null&&(n.uint32(66),n.bytes(e.signedPeerRecord)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={listenAddrs:[],protocols:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let c=e.uint32();switch(c>>>3){case 5:{s.protocolVersion=e.string();break}case 6:{s.agentVersion=e.string();break}case 1:{s.publicKey=e.bytes();break}case 2:{if(o.limits?.listenAddrs!=null&&s.listenAddrs.length===o.limits.listenAddrs)throw new Ue('Decode error - map field "listenAddrs" had too many elements');s.listenAddrs.push(e.bytes());break}case 4:{s.observedAddr=e.bytes();break}case 3:{if(o.limits?.protocols!=null&&s.protocols.length===o.limits.protocols)throw new Ue('Decode error - map field "protocols" had too many elements');s.protocols.push(e.string());break}case 8:{s.signedPeerRecord=e.bytes();break}default:{e.skipType(c&7);break}}}return s})),t),r.encode=e=>Ft(e,r.codec()),r.decode=(e,n)=>Mt(e,r.codec(),n)})(we||(we={}));var Pt={protocolPrefix:"ipfs",timeout:5e3,maxInboundStreams:1,maxOutboundStreams:1,maxObservedAddresses:10,maxMessageSize:8192,runOnConnectionOpen:!0,runOnSelfUpdate:!0,runOnLimitedConnection:!0,concurrency:32};function uc(r){if(r!=null&&r.length>0)try{return Yt(r)}catch{}}function _l(r,t){return t??r.userAgent}async function Rn(r,t,e,n,o){if(e("received identify from %p",n.remotePeer),o==null)throw new Ut("message was null or undefined");let s={};if(o.listenAddrs.length>0&&(s.addresses=o.listenAddrs.map(a=>({isCertified:!1,multiaddr:Yt(a)}))),o.protocols.length>0&&(s.protocols=o.protocols),o.publicKey!=null){let a=Qe(o.publicKey);if(!Ua(a).equals(n.remotePeer))throw new Ut("public key did not match remote PeerId");s.publicKey=a}let i;if(o.signedPeerRecord!=null){e.trace("received signedPeerRecord from %p",n.remotePeer);let a=o.signedPeerRecord,u=await Wt.openAndCertify(a,qt.DOMAIN),f=qt.createFromProtobuf(u.payload),l=xn(u.publicKey.toCID());if(!f.peerId.equals(l))throw new Ut("signing key does not match PeerId in the PeerRecord");if(!n.remotePeer.equals(f.peerId))throw new Ut("signing key does not match remote PeerId");let d;try{d=await r.get(f.peerId)}catch(b){if(b.name!=="NotFoundError")throw b}if(d!=null&&(s.metadata=d.metadata,d.peerRecordEnvelope!=null)){let b=await Wt.createFromProtobuf(d.peerRecordEnvelope),m=qt.createFromProtobuf(b.payload);m.seqNumber>=f.seqNumber&&(e("sequence number was lower or equal to existing sequence number - stored: %d received: %d",m.seqNumber,f.seqNumber),f=m,a=d.peerRecordEnvelope)}s.peerRecordEnvelope=a,s.addresses=f.multiaddrs.map(b=>({isCertified:!0,multiaddr:b})),i={seq:f.seqNumber,addresses:f.multiaddrs}}else e("%p did not send a signed peer record",n.remotePeer);if(e.trace("patching %p with",n.remotePeer,s),await r.patch(n.remotePeer,s),o.agentVersion!=null||o.protocolVersion!=null){let a={};o.agentVersion!=null&&(a.AgentVersion=k(o.agentVersion)),o.protocolVersion!=null&&(a.ProtocolVersion=k(o.protocolVersion)),e.trace("merging %p metadata",n.remotePeer,a),await r.merge(n.remotePeer,{metadata:a})}let c={peerId:n.remotePeer,protocolVersion:o.protocolVersion,agentVersion:o.agentVersion,publicKey:o.publicKey,listenAddrs:o.listenAddrs.map(a=>Yt(a)),observedAddr:o.observedAddr==null?void 0:Yt(o.observedAddr),protocols:o.protocols,signedPeerRecord:i,connection:n};return t.safeDispatchEvent("peer:identify",{detail:c}),c}var ir=class{host;protocol;started;timeout;peerId;privateKey;peerStore;registrar;addressManager;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxObservedAddresses;events;runOnLimitedConnection;log;constructor(t,e){this.protocol=e.protocol,this.started=!1,this.peerId=t.peerId,this.privateKey=t.privateKey,this.peerStore=t.peerStore,this.registrar=t.registrar,this.addressManager=t.addressManager,this.events=t.events,this.log=e.log,this.timeout=e.timeout??Pt.timeout,this.maxInboundStreams=e.maxInboundStreams??Pt.maxInboundStreams,this.maxOutboundStreams=e.maxOutboundStreams??Pt.maxOutboundStreams,this.maxMessageSize=e.maxMessageSize??Pt.maxMessageSize,this.maxObservedAddresses=e.maxObservedAddresses??Pt.maxObservedAddresses,this.runOnLimitedConnection=e.runOnLimitedConnection??Pt.runOnLimitedConnection,this.host={protocolVersion:`${e.protocolPrefix??Pt.protocolPrefix}/${oc}`,agentVersion:_l(t.nodeInfo,e.agentVersion)}}isStarted(){return this.started}async start(){this.started||(await this.peerStore.merge(this.peerId,{metadata:{AgentVersion:k(this.host.agentVersion),ProtocolVersion:k(this.host.protocolVersion)}}),await this.registrar.handle(this.protocol,t=>{this.handleProtocol(t).catch(e=>{this.log.error(e)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams,runOnLimitedConnection:this.runOnLimitedConnection}),this.started=!0)}async stop(){await this.registrar.unhandle(this.protocol),this.started=!1}};var Un=class extends ir{connectionManager;concurrency;constructor(t,e={}){super(t,{...e,protocol:`/${e.protocolPrefix??Pt.protocolPrefix}/${ic}/${cc}`,log:t.logger.forComponent("libp2p:identify-push")}),this.connectionManager=t.connectionManager,this.concurrency=e.concurrency??Pt.concurrency,(e.runOnSelfUpdate??Pt.runOnSelfUpdate)&&t.events.addEventListener("self:peer:update",n=>{this.push().catch(o=>{this.log.error(o)})})}[$r]=["@libp2p/identify-push"];async push(){if(!this.isStarted())return;let t=this.addressManager.getAddresses().map(f=>f.decapsulateCode(H("p2p").code)),e=new qt({peerId:this.peerId,multiaddrs:t}),n=await Wt.seal(e,this.privateKey),o=this.registrar.getProtocols(),s=await this.peerStore.get(this.peerId),i=U(s.metadata.get("AgentVersion")??k(this.host.agentVersion)),c=U(s.metadata.get("ProtocolVersion")??k(this.host.protocolVersion)),a=this;async function*u(){for(let f of a.connectionManager.getConnections())(await a.peerStore.get(f.remotePeer)).protocols.includes(a.protocol)&&(yield async()=>{let d,b=AbortSignal.timeout(a.timeout);try{d=await f.newStream(a.protocol,{signal:b,runOnLimitedConnection:a.runOnLimitedConnection}),await sr(d,{maxDataLength:a.maxMessageSize}).pb(we).write({listenAddrs:t.map(g=>g.bytes),signedPeerRecord:n.marshal(),protocols:o,agentVersion:i,protocolVersion:c},{signal:b}),await d.close({signal:b})}catch(m){a.log.error("could not push identify update to peer",m),d?.abort(m)}})}await tc(Os(u(),{concurrency:this.concurrency}))}async handleProtocol(t){let{connection:e,stream:n}=t;try{if(this.peerId.equals(e.remotePeer))throw new Error("received push from ourselves?");let o={signal:AbortSignal.timeout(this.timeout)},i=await sr(n,{maxDataLength:this.maxMessageSize}).pb(we).read(o);await n.close(o),await Rn(this.peerStore,this.events,this.log,e,i)}catch(o){this.log.error("received invalid message",o),n.abort(o);return}this.log.trace("handled push from %p",e.remotePeer)}};var Ll=41;function fc(r){try{let[[t,e]]=r.stringTuples();if(e==null)return!1;if(t===Ll)return qa("2000::/3",e)}catch{}return!1}var dc=Uc(lc(),1),Dl=["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"],Rl=Dl.map(r=>new dc.Netmask(r));function Ks(r){for(let t of Rl)if(t.contains(r))return!0;return!1}function Ul(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function Ol(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 Ks(o)}function Nl(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function Kl(r){let t=r.split(":"),e=t[t.length-1];return Ks(e)}function kl(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 hc(r){return rr(r)?Ks(r):Ul(r)?Ol(r):Nl(r)?Kl(r):nr(r)?kl(r):void 0}function pc(r){try{let[[t]]=r.stringTuples();return t===4||t===41}catch{}return!1}function mc(r){try{if(!pc(r))return!1;let[[,t]]=r.stringTuples();return t==null?!1:hc(t)??!1}catch{}return!0}var Ml=r=>r.toString().split("/").slice(1),ar=r=>({match:t=>t.length<1?!1:r(t[0])?t.slice(1):!1,pattern:"fn"}),F=r=>({match:t=>ar(e=>e===r).match(t),pattern:r}),Me=()=>({match:r=>ar(t=>typeof t=="string").match(r),pattern:"{string}"}),Mr=()=>({match:r=>ar(t=>!isNaN(parseInt(t))).match(r),pattern:"{number}"}),j=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{Y.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),Fr=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{ro.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),z=r=>({match:t=>{let e=r.match(t);return e===!1?t:e},pattern:`optional(${r.pattern})`}),wt=(...r)=>({match:t=>{let e;for(let n of r){let o=n.match(t);o!==!1&&(e==null||o.length<e.length)&&(e=o)}return e??!1},pattern:`or(${r.map(t=>t.pattern).join(", ")})`}),V=(...r)=>({match:t=>{for(let e of r){let n=e.match(t);if(n===!1)return!1;t=n}return t},pattern:`and(${r.map(t=>t.pattern).join(", ")})`});function Q(...r){function t(o){let s=Ml(o);for(let i of r){let c=i.match(s);if(c===!1)return!1;s=c}return s}function e(o){return t(o)!==!1}function n(o){let s=t(o);return s===!1?!1:s.length===0}return{matchers:r,matches:e,exactMatch:n}}var Fl=j(),nx=Q(Fl),Nn=V(F("dns4"),Me()),Kn=V(F("dns6"),Me()),kn=V(F("dnsaddr"),Me()),Ms=V(F("dns"),Me()),ox=Q(Nn,z(j())),sx=Q(Kn,z(j())),ix=Q(kn,z(j())),ax=Q(wt(Ms,kn,Nn,Kn),z(j())),yc=V(F("ip4"),ar(rr)),gc=V(F("ip6"),ar(nr)),Fs=wt(yc,gc),ue=wt(Fs,Ms,Nn,Kn,kn),bc=Q(wt(Fs,V(wt(Ms,kn,Nn,Kn),z(j())))),cx=Q(yc),ux=Q(gc),fx=Q(Fs),Vs=V(ue,F("tcp"),Mr()),Vr=V(ue,F("udp"),Mr()),xc=Q(V(Vs,z(j()))),lx=Q(Vr),qs=V(Vr,F("quic"),z(j())),Mn=V(Vr,F("quic-v1"),z(j())),Vl=wt(qs,Mn),dx=Q(qs),hx=Q(Mn),ks=wt(ue,Vs,Vr,qs,Mn),wc=wt(V(ks,F("ws"),z(j()))),px=Q(wc),Ec=wt(V(ks,F("wss"),z(j())),V(ks,F("tls"),z(V(F("sni"),Me())),F("ws"),z(j()))),mx=Q(Ec),Ac=V(Vr,F("webrtc-direct"),z(Fr()),z(Fr()),z(j())),yx=Q(Ac),Sc=V(Mn,F("webtransport"),z(Fr()),z(Fr()),z(j())),gx=Q(Sc),On=wt(wc,Ec,V(Vs,z(j())),V(Vl,z(j())),V(ue,z(j())),Ac,Sc,j()),bx=Q(On),ql=V(On,F("p2p-circuit"),j()),xx=Q(ql),Hl=wt(V(On,F("p2p-circuit"),F("webrtc"),z(j())),V(On,F("webrtc"),z(j())),V(F("webrtc"),z(j()))),wx=Q(Hl),zl=wt(V(ue,F("tcp"),Mr(),F("http"),z(j())),V(ue,F("http"),z(j()))),Ex=Q(zl),Gl=wt(V(ue,F("tcp"),wt(V(F("443"),F("http")),V(Mr(),F("https"))),z(j())),V(ue,F("tls"),F("http"),z(j())),V(ue,F("https"),z(j()))),Ax=Q(Gl),$l=wt(V(F("memory"),Me(),z(j()))),Sx=Q($l);var Zl=41,Fn=class extends ir{constructor(t,e={}){super(t,{...e,protocol:`/${e.protocolPrefix??Pt.protocolPrefix}/${sc}/${ac}`,log:t.logger.forComponent("libp2p:identify")}),(e.runOnConnectionOpen??Pt.runOnConnectionOpen)&&t.events.addEventListener("connection:open",n=>{let o=n.detail;this.identify(o).catch(s=>{s.name!==Gr.name&&this.log.error("error during identify trigged by connection:open",s)})})}[$r]=["@libp2p/identify"];async _identify(t,e={}){let n;if(e.signal==null){let o=AbortSignal.timeout(this.timeout);e={...e,signal:o}}try{n=await t.newStream(this.protocol,{...e,runOnLimitedConnection:this.runOnLimitedConnection});let s=await sr(n,{maxDataLength:this.maxMessageSize}).pb(we).read(e);return await n.close(e),s}catch(o){throw n?.abort(o),o}}async identify(t,e={}){let n=await this._identify(t,e),{publicKey:o,protocols:s,observedAddr:i}=n;if(o==null)throw new Ut("public key was missing from identify message");let c=Qe(o),a=xn(c.toCID());if(!t.remotePeer.equals(a))throw new Ut("identified peer does not match the expected peer");if(this.peerId.equals(a))throw new Ut("identified peer is our own peer id?");return this.maybeAddObservedAddress(i),this.log("identify completed for peer %p and protocols %o",a,s),Rn(this.peerStore,this.events,this.log,t,n)}maybeAddObservedAddress(t){let e=uc(t);if(e==null)return;if(this.log.trace("our observed address was %a",e),mc(e)){this.log.trace("our observed address was private");return}if(e.stringTuples()[0][0]===Zl&&!fc(e)){this.log.trace("our observed address was IPv6 but not a global unicast address");return}xc.exactMatch(e)||(this.log.trace("storing the observed address"),this.addressManager.addObservedAddr(e))}async handleProtocol(t){let{connection:e,stream:n}=t,o=AbortSignal.timeout(this.timeout);try{let s=await this.peerStore.get(this.peerId),i=this.addressManager.getAddresses().map(f=>f.decapsulateCode(H("p2p").code)),c=s.peerRecordEnvelope;if(i.length>0&&c==null){let f=new qt({peerId:this.peerId,multiaddrs:i});c=(await Wt.seal(f,this.privateKey)).marshal().subarray()}let a=e.remoteAddr.bytes;bc.matches(e.remoteAddr)||(a=void 0),await sr(n).pb(we).write({protocolVersion:this.host.protocolVersion,agentVersion:this.host.agentVersion,publicKey:zt(this.privateKey.publicKey),listenAddrs:i.map(f=>f.bytes),signedPeerRecord:c,observedAddr:a,protocols:s.protocols},{signal:o}),await n.close({signal:o})}catch(s){this.log.error("could not respond to identify request",s),n.abort(s)}}};function jl(r={}){return t=>new Fn(t,r)}function Wl(r={}){return t=>new Un(t,r)}return Oc(Yl);})();
2
+ "use strict";var Libp2PIdentify=(()=>{var Lc=Object.create;var Hr=Object.defineProperty;var Dc=Object.getOwnPropertyDescriptor;var Rc=Object.getOwnPropertyNames;var Uc=Object.getPrototypeOf,Oc=Object.prototype.hasOwnProperty;var Nc=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),It=(r,t)=>{for(var e in t)Hr(r,e,{get:t[e],enumerable:!0})},$s=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Rc(t))!Oc.call(r,o)&&o!==e&&Hr(r,o,{get:()=>t[o],enumerable:!(n=Dc(t,o))||n.enumerable});return r};var Kc=(r,t,e)=>(e=r!=null?Lc(Uc(r)):{},$s(t||!r||!r.__esModule?Hr(e,"default",{value:r,enumerable:!0}):e,r)),kc=r=>$s(Hr({},"__esModule",{value:!0}),r);var pc=Nc(Fr=>{(function(){var r,t,e,n,o,s,i,c;c=function(a){var f,u,l,h;return f=(a&255<<24)>>>24,u=(a&255<<16)>>>16,l=(a&65280)>>>8,h=a&255,[f,u,l,h].join(".")},i=function(a){var f,u,l,h,b,m;for(f=[],l=h=0;h<=3&&a.length!==0;l=++h){if(l>0){if(a[0]!==".")throw new Error("Invalid IP");a=a.substring(1)}m=t(a),b=m[0],u=m[1],a=a.substring(u),f.push(b)}if(a.length!==0)throw new Error("Invalid IP");switch(f.length){case 1:if(f[0]>4294967295)throw new Error("Invalid IP");return f[0]>>>0;case 2:if(f[0]>255||f[1]>16777215)throw new Error("Invalid IP");return(f[0]<<24|f[1])>>>0;case 3:if(f[0]>255||f[1]>255||f[2]>65535)throw new Error("Invalid IP");return(f[0]<<24|f[1]<<16|f[2])>>>0;case 4:if(f[0]>255||f[1]>255||f[2]>255||f[3]>255)throw new Error("Invalid IP");return(f[0]<<24|f[1]<<16|f[2]<<8|f[3])>>>0;default:throw new Error("Invalid IP")}},e=function(a){return a.charCodeAt(0)},n=e("0"),s=e("a"),o=e("A"),t=function(a){var f,u,l,h,b;for(h=0,f=10,u="9",l=0,a.length>1&&a[l]==="0"&&(a[l+1]==="x"||a[l+1]==="X"?(l+=2,f=16):"0"<=a[l+1]&&a[l+1]<="9"&&(l++,f=8,u="7")),b=l;l<a.length;){if("0"<=a[l]&&a[l]<=u)h=h*f+(e(a[l])-n)>>>0;else if(f===16)if("a"<=a[l]&&a[l]<="f")h=h*f+(10+e(a[l])-s)>>>0;else if("A"<=a[l]&&a[l]<="F")h=h*f+(10+e(a[l])-o)>>>0;else break;else break;if(h>4294967295)throw new Error("too large");l++}if(l===b)throw new Error("empty octet");return[h,l]},r=function(){function a(f,u){var l,h,b,m;if(typeof f!="string")throw new Error("Missing `net' parameter");if(u||(m=f.split("/",2),f=m[0],u=m[1]),u||(u=32),typeof u=="string"&&u.indexOf(".")>-1){try{this.maskLong=i(u)}catch(y){throw l=y,new Error("Invalid mask: "+u)}for(h=b=32;b>=0;h=--b)if(this.maskLong===4294967295<<32-h>>>0){this.bitmask=h;break}}else if(u||u===0)this.bitmask=parseInt(u,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(f)&this.maskLong)>>>0}catch(y){throw l=y,new Error("Invalid net address: "+f)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+u);this.size=Math.pow(2,32-this.bitmask),this.base=c(this.netLong),this.mask=c(this.maskLong),this.hostmask=c(~this.maskLong),this.first=this.bitmask<=30?c(this.netLong+1):this.base,this.last=this.bitmask<=30?c(this.netLong+this.size-2):c(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?c(this.netLong+this.size-1):void 0}return a.prototype.contains=function(f){return typeof f=="string"&&(f.indexOf("/")>0||f.split(".").length!==4)&&(f=new a(f)),f instanceof a?this.contains(f.base)&&this.contains(f.broadcast||f.last):(i(f)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},a.prototype.next=function(f){return f==null&&(f=1),new a(c(this.netLong+this.size*f),this.mask)},a.prototype.forEach=function(f){var u,l,h;for(h=i(this.first),l=i(this.last),u=0;h<=l;)f(c(h),h,u),u++,h++},a.prototype.toString=function(){return this.base+"/"+this.bitmask},a}(),Fr.ip2long=i,Fr.long2ip=c,Fr.Netmask=r}).call(Fr)});var Ql={};It(Ql,{identify:()=>Xl,identifyPush:()=>Jl});var qn=Symbol.for("@libp2p/peer-id");var ut=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Me=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var zr=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},Gr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}},$r=class extends Error{static name="UnsupportedProtocolError";constructor(t="Unsupported protocol error"){super(t),this.name="UnsupportedProtocolError"}},Ot=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var Ae=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Yr=Symbol.for("@libp2p/service-capabilities"),nd=Symbol.for("@libp2p/service-dependencies");var Yn={};It(Yn,{base58btc:()=>J,base58flickr:()=>zc});var Pd=new Uint8Array(0);function Ys(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 Jt(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 Zs(r){return new TextEncoder().encode(r)}function js(r){return new TextDecoder().decode(r)}function Mc(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 c=r.length,a=r.charAt(0),f=Math.log(c)/Math.log(256),u=Math.log(256)/Math.log(c);function l(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var y=0,D=0,U=0,Z=m.length;U!==Z&&m[U]===0;)U++,y++;for(var v=(Z-U)*u+1>>>0,d=new Uint8Array(v);U!==Z;){for(var x=m[U],I=0,P=v-1;(x!==0||I<D)&&P!==-1;P--,I++)x+=256*d[P]>>>0,d[P]=x%c>>>0,x=x/c>>>0;if(x!==0)throw new Error("Non-zero carry");D=I,U++}for(var B=v-D;B!==v&&d[B]===0;)B++;for(var R=a.repeat(y);B<v;++B)R+=r.charAt(d[B]);return R}function h(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var y=0;if(m[y]!==" "){for(var D=0,U=0;m[y]===a;)D++,y++;for(var Z=(m.length-y)*f+1>>>0,v=new Uint8Array(Z);m[y];){var d=e[m.charCodeAt(y)];if(d===255)return;for(var x=0,I=Z-1;(d!==0||x<U)&&I!==-1;I--,x++)d+=c*v[I]>>>0,v[I]=d%256>>>0,d=d/256>>>0;if(d!==0)throw new Error("Non-zero carry");U=x,y++}if(m[y]!==" "){for(var P=Z-U;P!==Z&&v[P]===0;)P++;for(var B=new Uint8Array(D+(Z-P)),R=D;P!==Z;)B[R++]=v[P++];return B}}}function b(m){var y=h(m);if(y)return y;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:h,decode:b}}var Fc=Mc,Vc=Fc,Xs=Vc;var Hn=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")}},zn=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 Js(this,t)}},Gn=class{decoders;constructor(t){this.decoders=t}or(t){return Js(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 Js(r,t){return new Gn({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var $n=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 Hn(t,e,n),this.decoder=new zn(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Fe({name:r,prefix:t,encode:e,decode:n}){return new $n(r,t,e,n)}function le({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Xs(e,r);return Fe({prefix:t,name:r,encode:n,decode:s=>Jt(o(s))})}function qc(r,t,e,n){let o={};for(let u=0;u<t.length;++u)o[t[u]]=u;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*e/8|0),c=0,a=0,f=0;for(let u=0;u<s;++u){let l=o[r[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|l,c+=e,c>=8&&(c-=8,i[f++]=255&a>>c)}if(c>=e||(255&a<<8-c)!==0)throw new SyntaxError("Unexpected end of data");return i}function Hc(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,c=0;for(let a=0;a<r.length;++a)for(c=c<<8|r[a],i+=8;i>e;)i-=e,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function rt({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return Fe({prefix:t,name:r,encode(o){return Hc(o,n,e)},decode(o){return qc(o,n,e,r)}})}var J=le({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),zc=le({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Zn={};It(Zn,{base32:()=>Qt,base32hex:()=>Zc,base32hexpad:()=>Wc,base32hexpadupper:()=>Xc,base32hexupper:()=>jc,base32pad:()=>$c,base32padupper:()=>Yc,base32upper:()=>Gc,base32z:()=>Jc});var Qt=rt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Gc=rt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),$c=rt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Yc=rt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Zc=rt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),jc=rt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Wc=rt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Xc=rt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Jc=rt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var jn={};It(jn,{base36:()=>lr,base36upper:()=>Qc});var lr=le({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Qc=le({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var tu=ei,Qs=128,eu=127,ru=~eu,nu=Math.pow(2,31);function ei(r,t,e){t=t||[],e=e||0;for(var n=e;r>=nu;)t[e++]=r&255|Qs,r/=128;for(;r&ru;)t[e++]=r&255|Qs,r>>>=7;return t[e]=r|0,ei.bytes=e-n+1,t}var ou=Wn,su=128,ti=127;function Wn(r,n){var e=0,n=n||0,o=0,s=n,i,c=r.length;do{if(s>=c)throw Wn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&ti)<<o:(i&ti)*Math.pow(2,o),o+=7}while(i>=su);return Wn.bytes=s-n,e}var iu=Math.pow(2,7),au=Math.pow(2,14),cu=Math.pow(2,21),uu=Math.pow(2,28),fu=Math.pow(2,35),lu=Math.pow(2,42),du=Math.pow(2,49),hu=Math.pow(2,56),pu=Math.pow(2,63),mu=function(r){return r<iu?1:r<au?2:r<cu?3:r<uu?4:r<fu?5:r<lu?6:r<du?7:r<hu?8:r<pu?9:10},yu={encode:tu,decode:ou,encodingLength:mu},gu=yu,dr=gu;function hr(r,t=0){return[dr.decode(r,t),dr.decode.bytes]}function Ve(r,t,e=0){return dr.encode(r,t,e),t}function qe(r){return dr.encodingLength(r)}function Nt(r,t){let e=t.byteLength,n=qe(r),o=n+qe(e),s=new Uint8Array(o+e);return Ve(r,s,0),Ve(e,s,n),s.set(t,o),new He(r,e,t,s)}function Se(r){let t=Jt(r),[e,n]=hr(t),[o,s]=hr(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new He(e,o,i,t)}function ri(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Ys(r.bytes,e.bytes)}}var He=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function ni(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return xu(e,Xn(r),t??J.encoder);default:return wu(e,Xn(r),t??Qt.encoder)}}var oi=new WeakMap;function Xn(r){let t=oi.get(r);if(t==null){let e=new Map;return oi.set(r,e),e}return t}var ct=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!==pr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Eu)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=Nt(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&&ri(t.multihash,n.multihash)}toString(t){return ni(this,t)}toJSON(){return{"/":ni(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??si(n,o,s.bytes))}else if(e[Au]===!0){let{version:n,multihash:o,code:s}=e,i=Se(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!==pr)throw new Error(`Version 0 CID must use dag-pb (code: ${pr}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=si(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,pr,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=Jt(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 He(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[l,h]=hr(t.subarray(e));return e+=h,l},o=n(),s=pr;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,c=n(),a=n(),f=e+a,u=f-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:u,size:f}}static parse(t,e){let[n,o]=bu(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 Xn(s).set(n,t),s}};function bu(r,t){switch(r[0]){case"Q":{let e=t??J;return[J.prefix,e.decode(`${J.prefix}${r}`)]}case J.prefix:{let e=t??J;return[J.prefix,e.decode(r)]}case Qt.prefix:{let e=t??Qt;return[Qt.prefix,e.decode(r)]}case lr.prefix:{let e=t??lr;return[lr.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 xu(r,t,e){let{prefix:n}=e;if(n!==J.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 wu(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 pr=112,Eu=18;function si(r,t,e){let n=qe(r),o=n+qe(t),s=new Uint8Array(o+e.byteLength);return Ve(r,s,0),Ve(t,s,n),s.set(e,o),s}var Au=Symbol.for("@ipld/js-cid/CID");var Jn={};It(Jn,{identity:()=>Kt});var ii=0,Su="identity",ai=Jt;function vu(r){return Nt(ii,ai(r))}var Kt={code:ii,name:Su,encode:ai,digest:vu};function lt(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 mt(r=0){return new Uint8Array(r)}function Pt(r=0){return new Uint8Array(r)}function Tt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=Pt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var ui=Symbol.for("@achingbrain/uint8arraylist");function ci(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 jr(r){return!!r?.[ui]}var ot=class r{bufs;length;[ui]=!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(jr(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(jr(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=ci(this.bufs,t);return e.buf[e.index]}set(t,e){let n=ci(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(jr(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 Tt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:Tt(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],c=o,a=c+i.byteLength;if(o=a,t>=a)continue;let f=t>=c&&t<a,u=e>c&&e<=a;if(f&&u){if(t===c&&e===a){n.push(i);break}let l=t-c;n.push(i.subarray(l,l+(e-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(u){if(e===a){n.push(i);break}n.push(i.subarray(0,e-c));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!jr(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 l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let c=i,a=this.byteLength-n.byteLength,f=n.byteLength-1,u;for(let l=e;l<=a;l+=u){u=0;for(let h=f;h>=0;h--){let b=this.get(l+h);if(n[h]!==b){u=Math.max(1,h-c[b]);break}}if(u===0)return l}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=Pt(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=mt(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=mt(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=mt(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=Pt(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=mt(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=mt(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=mt(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=mt(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=mt(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(!lt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var Qn={};It(Qn,{base10:()=>Iu});var Iu=le({prefix:"9",name:"base10",alphabet:"0123456789"});var to={};It(to,{base16:()=>Pu,base16upper:()=>Bu});var Pu=rt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Bu=rt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var eo={};It(eo,{base2:()=>Cu});var Cu=rt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ro={};It(ro,{base256emoji:()=>Ru});var fi=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}"),_u=fi.reduce((r,t,e)=>(r[e]=t,r),[]),Tu=fi.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Lu(r){return r.reduce((t,e)=>(t+=_u[e],t),"")}function Du(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Tu[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Ru=Fe({prefix:"\u{1F680}",name:"base256emoji",encode:Lu,decode:Du});var oo={};It(oo,{base64:()=>Uu,base64pad:()=>Ou,base64url:()=>no,base64urlpad:()=>Nu});var Uu=rt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ou=rt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),no=rt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Nu=rt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var so={};It(so,{base8:()=>Ku});var Ku=rt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var io={};It(io,{identity:()=>ku});var ku=Fe({prefix:"\0",name:"identity",encode:r=>js(r),decode:r=>Zs(r)});var uh=new TextEncoder,fh=new TextDecoder;var uo={};It(uo,{sha256:()=>mr,sha512:()=>Vu});function co({name:r,code:t,encode:e}){return new ao(r,t,e)}var ao=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?Nt(this.code,e):e.then(n=>Nt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function di(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var mr=co({name:"sha2-256",code:18,encode:di("SHA-256")}),Vu=co({name:"sha2-512",code:19,encode:di("SHA-512")});var yr={...io,...eo,...so,...Qn,...to,...Zn,...jn,...Yn,...oo,...ro},Ah={...uo,...Jn};function pi(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var hi=pi("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),fo=pi("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=Pt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),qu={utf8:hi,"utf-8":hi,hex:yr.base16,latin1:fo,ascii:fo,binary:fo,...yr},Wr=qu;function V(r,t="utf8"){let e=Wr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function K(r,t="utf8"){let e=Wr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Hu=parseInt("11111",2),lo=parseInt("10000000",2),zu=parseInt("01111111",2),mi={0:gr,1:gr,2:Gu,3:Zu,4:ju,5:Yu,6:$u,16:gr,22:gr,48:gr};function te(r,t={offset:0}){let e=r[t.offset]&Hu;if(t.offset++,mi[e]!=null)return mi[e](r,t);throw new Error("No decoder for tag "+e)}function br(r,t){let e=0;if((r[t.offset]&lo)===lo){let n=r[t.offset]&zu,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(o,16)}else e=r[t.offset],t.offset++;return e}function gr(r,t){br(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=te(r,t);if(n===null)break;e.push(n)}return e}function Gu(r,t){let e=br(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function $u(r,t){let e=br(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let c=`${s}.${i}`,a=[];for(;t.offset<n;){let f=r[t.offset];if(t.offset++,a.push(f&127),f<128){a.reverse();let u=0;for(let l=0;l<a.length;l++)u+=a[l]<<l*7;c+=`.${u}`,a=[]}}return c}function Yu(r,t){return t.offset++,null}function Zu(r,t){let e=br(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function ju(r,t){let e=br(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function Wu(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new ot;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function ho(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Wu(r.byteLength);return new ot(Uint8Array.from([t.byteLength|lo]),t)}function Bt(r){let t=new ot,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new ot(Uint8Array.from([2]),ho(t),t)}function Xr(r){let t=Uint8Array.from([0]),e=new ot(t,r);return new ot(Uint8Array.from([3]),ho(e),e)}function he(r,t=48){let e=new ot;for(let n of r)e.append(n);return new ot(Uint8Array.from([t]),ho(e),e)}async function yi(r,t,e){let n=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);return crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},n,t,e.subarray())}var Xu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Ju=Uint8Array.from([6,5,43,129,4,0,34]),Qu=Uint8Array.from([6,5,43,129,4,0,35]),tf={ext:!0,kty:"EC",crv:"P-256"},ef={ext:!0,kty:"EC",crv:"P-384"},rf={ext:!0,kty:"EC",crv:"P-521"},po=32,mo=48,yo=66;function go(r){let t=te(r);return gi(t)}function gi(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===po*2+1)return n=K(t.subarray(e,e+po),"base64url"),o=K(t.subarray(e+po),"base64url"),new ze({...tf,key_ops:["verify"],x:n,y:o});if(t.byteLength===mo*2+1)return n=K(t.subarray(e,e+mo),"base64url"),o=K(t.subarray(e+mo),"base64url"),new ze({...ef,key_ops:["verify"],x:n,y:o});if(t.byteLength===yo*2+1)return n=K(t.subarray(e,e+yo),"base64url"),o=K(t.subarray(e+yo),"base64url"),new ze({...rf,key_ops:["verify"],x:n,y:o});throw new ut(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function bi(r){return he([Bt(Uint8Array.from([1])),he([nf(r.crv)],160),he([Xr(new ot(Uint8Array.from([4]),V(r.x??"","base64url"),V(r.y??"","base64url")))],161)]).subarray()}function nf(r){if(r==="P-256")return Xu;if(r==="P-384")return Ju;if(r==="P-521")return Qu;throw new ut(`Invalid curve ${r}`)}var ze=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=bi(this.jwk)),this._raw}toMultihash(){return Kt.digest(Gt(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}async verify(t,e){return yi(this.jwk,e,t)}};var ve=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function of(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Jr(r){if(!Number.isSafeInteger(r)||r<0)throw new Error("positive integer expected, got "+r)}function Ie(r,...t){if(!of(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 xi(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Jr(r.outputLen),Jr(r.blockLen)}function $e(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 wi(r,t){Ie(r);let e=t.outputLen;if(r.length<e)throw new Error("digestInto() expects output buffer of length at least "+e)}function ee(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function Qr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function kt(r,t){return r<<32-t|r>>>t}function Ei(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function xr(r){return typeof r=="string"&&(r=Ei(r)),Ie(r),r}function bo(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Ie(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 Ge=class{};function xo(r){let t=n=>r().update(xr(n)).digest(),e=r();return t.outputLen=e.outputLen,t.blockLen=e.blockLen,t.create=()=>r(),t}function tn(r=32){if(ve&&typeof ve.getRandomValues=="function")return ve.getRandomValues(new Uint8Array(r));if(ve&&typeof ve.randomBytes=="function")return Uint8Array.from(ve.randomBytes(r));throw new Error("crypto.getRandomValues must be defined")}function sf(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),c=Number(e&s),a=n?4:0,f=n?0:4;r.setUint32(t+a,i,n),r.setUint32(t+f,c,n)}function Ai(r,t,e){return r&t^~r&e}function Si(r,t,e){return r&t^r&e^t&e}var wr=class extends Ge{constructor(t,e,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Qr(this.buffer)}update(t){$e(this),t=xr(t),Ie(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=Qr(t);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){$e(this),wi(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,ee(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)e[l]=0;sf(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=Qr(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=a/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)c.setUint32(4*l,u[l],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:c}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=c,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},re=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var yt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var en=BigInt(4294967295),vi=BigInt(32);function af(r,t=!1){return t?{h:Number(r&en),l:Number(r>>vi&en)}:{h:Number(r>>vi&en)|0,l:Number(r&en)|0}}function Ii(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:c}=af(r[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var wo=(r,t,e)=>r>>>e,Eo=(r,t,e)=>r<<32-e|t>>>e,Pe=(r,t,e)=>r>>>e|t<<32-e,Be=(r,t,e)=>r<<32-e|t>>>e,Er=(r,t,e)=>r<<64-e|t>>>e-32,Ar=(r,t,e)=>r>>>e-32|t<<64-e;function $t(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Pi=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),Bi=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Ci=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),_i=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Ti=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),Li=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var uf=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),pe=new Uint32Array(64),rn=class extends wr{constructor(t=32){super(64,t,8,!1),this.A=re[0]|0,this.B=re[1]|0,this.C=re[2]|0,this.D=re[3]|0,this.E=re[4]|0,this.F=re[5]|0,this.G=re[6]|0,this.H=re[7]|0}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[t,e,n,o,s,i,c,a]}set(t,e,n,o,s,i,c,a){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=c|0,this.H=a|0}process(t,e){for(let l=0;l<16;l++,e+=4)pe[l]=t.getUint32(e,!1);for(let l=16;l<64;l++){let h=pe[l-15],b=pe[l-2],m=kt(h,7)^kt(h,18)^h>>>3,y=kt(b,17)^kt(b,19)^b>>>10;pe[l]=y+pe[l-7]+m+pe[l-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:f,H:u}=this;for(let l=0;l<64;l++){let h=kt(c,6)^kt(c,11)^kt(c,25),b=u+h+Ai(c,a,f)+uf[l]+pe[l]|0,y=(kt(n,2)^kt(n,13)^kt(n,22))+Si(n,o,s)|0;u=f,f=a,a=c,c=i+b|0,i=s,s=o,o=n,n=b+y|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,o,s,i,c,a,f,u)}roundClean(){ee(pe)}destroy(){this.set(0,0,0,0,0,0,0,0),ee(this.buffer)}};var Di=Ii(["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))),ff=Di[0],lf=Di[1],me=new Uint32Array(80),ye=new Uint32Array(80),Ao=class extends wr{constructor(t=64){super(128,t,16,!1),this.Ah=yt[0]|0,this.Al=yt[1]|0,this.Bh=yt[2]|0,this.Bl=yt[3]|0,this.Ch=yt[4]|0,this.Cl=yt[5]|0,this.Dh=yt[6]|0,this.Dl=yt[7]|0,this.Eh=yt[8]|0,this.El=yt[9]|0,this.Fh=yt[10]|0,this.Fl=yt[11]|0,this.Gh=yt[12]|0,this.Gl=yt[13]|0,this.Hh=yt[14]|0,this.Hl=yt[15]|0}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:f,El:u,Fh:l,Fl:h,Gh:b,Gl:m,Hh:y,Hl:D}=this;return[t,e,n,o,s,i,c,a,f,u,l,h,b,m,y,D]}set(t,e,n,o,s,i,c,a,f,u,l,h,b,m,y,D){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=c|0,this.Dl=a|0,this.Eh=f|0,this.El=u|0,this.Fh=l|0,this.Fl=h|0,this.Gh=b|0,this.Gl=m|0,this.Hh=y|0,this.Hl=D|0}process(t,e){for(let v=0;v<16;v++,e+=4)me[v]=t.getUint32(e),ye[v]=t.getUint32(e+=4);for(let v=16;v<80;v++){let d=me[v-15]|0,x=ye[v-15]|0,I=Pe(d,x,1)^Pe(d,x,8)^wo(d,x,7),P=Be(d,x,1)^Be(d,x,8)^Eo(d,x,7),B=me[v-2]|0,R=ye[v-2]|0,k=Pe(B,R,19)^Er(B,R,61)^wo(B,R,6),_=Be(B,R,19)^Ar(B,R,61)^Eo(B,R,6),O=Ci(P,_,ye[v-7],ye[v-16]),L=_i(O,I,k,me[v-7],me[v-16]);me[v]=L|0,ye[v]=O|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:f,Dl:u,Eh:l,El:h,Fh:b,Fl:m,Gh:y,Gl:D,Hh:U,Hl:Z}=this;for(let v=0;v<80;v++){let d=Pe(l,h,14)^Pe(l,h,18)^Er(l,h,41),x=Be(l,h,14)^Be(l,h,18)^Ar(l,h,41),I=l&b^~l&y,P=h&m^~h&D,B=Ti(Z,x,P,lf[v],ye[v]),R=Li(B,U,d,I,ff[v],me[v]),k=B|0,_=Pe(n,o,28)^Er(n,o,34)^Er(n,o,39),O=Be(n,o,28)^Ar(n,o,34)^Ar(n,o,39),L=n&s^n&c^s&c,it=o&i^o&a^i&a;U=y|0,Z=D|0,y=b|0,D=m|0,b=l|0,m=h|0,{h:l,l:h}=$t(f|0,u|0,R|0,k|0),f=c|0,u=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let A=Pi(k,O,it);n=Bi(A,R,_,L),o=A|0}({h:n,l:o}=$t(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=$t(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=$t(this.Ch|0,this.Cl|0,c|0,a|0),{h:f,l:u}=$t(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:h}=$t(this.Eh|0,this.El|0,l|0,h|0),{h:b,l:m}=$t(this.Fh|0,this.Fl|0,b|0,m|0),{h:y,l:D}=$t(this.Gh|0,this.Gl|0,y|0,D|0),{h:U,l:Z}=$t(this.Hh|0,this.Hl|0,U|0,Z|0),this.set(n,o,s,i,c,a,f,u,l,h,b,m,y,D,U,Z)}roundClean(){ee(me,ye)}destroy(){ee(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var nn=xo(()=>new rn);var Ri=xo(()=>new Ao);var Po=BigInt(0),Io=BigInt(1);function Ye(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function Bo(r){if(!Ye(r))throw new Error("Uint8Array expected")}function Yt(r,t){if(typeof t!="boolean")throw new Error(r+" boolean expected, got "+t)}function Sr(r){let t=r.toString(16);return t.length&1?"0"+t:t}function Ni(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?Po:BigInt("0x"+r)}var Ki=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",df=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function ge(r){if(Bo(r),Ki)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=df[r[e]];return t}var ne={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ui(r){if(r>=ne._0&&r<=ne._9)return r-ne._0;if(r>=ne.A&&r<=ne.F)return r-(ne.A-10);if(r>=ne.a&&r<=ne.f)return r-(ne.a-10)}function vr(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(Ki)return Uint8Array.fromHex(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=Ui(r.charCodeAt(s)),c=Ui(r.charCodeAt(s+1));if(i===void 0||c===void 0){let a=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function oe(r){return Ni(ge(r))}function Ce(r){return Bo(r),Ni(ge(Uint8Array.from(r).reverse()))}function _e(r,t){return vr(r.toString(16).padStart(t*2,"0"))}function Ze(r,t){return _e(r,t).reverse()}function Q(r,t,e){let n;if(typeof t=="string")try{n=vr(t)}catch(s){throw new Error(r+" must be hex string or Uint8Array, cause: "+s)}else if(Ye(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 be(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];Bo(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 So=r=>typeof r=="bigint"&&Po<=r;function on(r,t,e){return So(r)&&So(t)&&So(e)&&t<=r&&r<e}function Lt(r,t,e,n){if(!on(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function ki(r){let t;for(t=0;r>Po;r>>=Io,t+=1);return t}var Te=r=>(Io<<BigInt(r))-Io,vo=r=>new Uint8Array(r),Oi=r=>Uint8Array.from(r);function Mi(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=vo(r),o=vo(r),s=0,i=()=>{n.fill(1),o.fill(0),s=0},c=(...l)=>e(o,n,...l),a=(l=vo(0))=>{o=c(Oi([0]),l),n=c(),l.length!==0&&(o=c(Oi([1]),l),n=c())},f=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let l=0,h=[];for(;l<t;){n=c();let b=n.slice();h.push(b),l+=n.length}return be(...h)};return(l,h)=>{i(),a(l);let b;for(;!(b=h(f()));)a();return i(),b}}var hf={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"||Ye(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 se(r,t,e={}){let n=(o,s,i)=>{let c=hf[s];if(typeof c!="function")throw new Error("invalid validator function");let a=r[o];if(!(i&&a===void 0)&&!c(a,r))throw new Error("param "+String(o)+" is invalid. Expected "+s+", got "+a)};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}function je(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 At=BigInt(0),dt=BigInt(1),Le=BigInt(2),pf=BigInt(3),Vi=BigInt(4),qi=BigInt(5),Hi=BigInt(8);function X(r,t){let e=r%t;return e>=At?e:t+e}function tt(r,t,e){let n=r;for(;t-- >At;)n*=n,n%=e;return n}function sn(r,t){if(r===At)throw new Error("invert: expected non-zero number");if(t<=At)throw new Error("invert: expected positive modulus, got "+t);let e=X(r,t),n=t,o=At,s=dt,i=dt,c=At;for(;e!==At;){let f=n/e,u=n%e,l=o-i*f,h=s-c*f;n=e,e=u,o=i,s=c,i=l,c=h}if(n!==dt)throw new Error("invert: does not exist");return X(o,t)}function zi(r,t){let e=(r.ORDER+dt)/Vi,n=r.pow(t,e);if(!r.eql(r.sqr(n),t))throw new Error("Cannot find square root");return n}function mf(r,t){let e=(r.ORDER-qi)/Hi,n=r.mul(t,Le),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,Le),o),c=r.mul(s,r.sub(i,r.ONE));if(!r.eql(r.sqr(c),t))throw new Error("Cannot find square root");return c}function yf(r){if(r<BigInt(3))throw new Error("sqrt is not defined for small field");let t=r-dt,e=0;for(;t%Le===At;)t/=Le,e++;let n=Le,o=ie(r);for(;Fi(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return zi;let s=o.pow(n,t),i=(t+dt)/Le;return function(a,f){if(a.is0(f))return f;if(Fi(a,f)!==1)throw new Error("Cannot find square root");let u=e,l=a.mul(a.ONE,s),h=a.pow(f,t),b=a.pow(f,i);for(;!a.eql(h,a.ONE);){if(a.is0(h))return a.ZERO;let m=1,y=a.sqr(h);for(;!a.eql(y,a.ONE);)if(m++,y=a.sqr(y),m===u)throw new Error("Cannot find square root");let D=dt<<BigInt(u-m-1),U=a.pow(l,D);u=m,l=a.sqr(U),h=a.mul(h,l),b=a.mul(b,U)}return b}}function gf(r){return r%Vi===pf?zi:r%Hi===qi?mf:yf(r)}var Gi=(r,t)=>(X(r,t)&dt)===dt,bf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Co(r){let t={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},e=bf.reduce((n,o)=>(n[o]="function",n),t);return se(r,e)}function xf(r,t,e){if(e<At)throw new Error("invalid exponent, negatives unsupported");if(e===At)return r.ONE;if(e===dt)return t;let n=r.ONE,o=t;for(;e>At;)e&dt&&(n=r.mul(n,o)),o=r.sqr(o),e>>=dt;return n}function We(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,c,a)=>r.is0(c)?i:(n[a]=i,r.mul(i,c)),r.ONE),s=r.inv(o);return t.reduceRight((i,c,a)=>r.is0(c)?i:(n[a]=r.mul(i,n[a]),r.mul(i,c)),s),n}function Fi(r,t){let e=(r.ORDER-dt)/Le,n=r.pow(t,e),o=r.eql(n,r.ONE),s=r.eql(n,r.ZERO),i=r.eql(n,r.neg(r.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function _o(r,t){t!==void 0&&Jr(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}function ie(r,t,e=!1,n={}){if(r<=At)throw new Error("invalid field: expected ORDER > 0, got "+r);let{nBitLength:o,nByteLength:s}=_o(r,t);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let i,c=Object.freeze({ORDER:r,isLE:e,BITS:o,BYTES:s,MASK:Te(o),ZERO:At,ONE:dt,create:a=>X(a,r),isValid:a=>{if(typeof a!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof a);return At<=a&&a<r},is0:a=>a===At,isOdd:a=>(a&dt)===dt,neg:a=>X(-a,r),eql:(a,f)=>a===f,sqr:a=>X(a*a,r),add:(a,f)=>X(a+f,r),sub:(a,f)=>X(a-f,r),mul:(a,f)=>X(a*f,r),pow:(a,f)=>xf(c,a,f),div:(a,f)=>X(a*sn(f,r),r),sqrN:a=>a*a,addN:(a,f)=>a+f,subN:(a,f)=>a-f,mulN:(a,f)=>a*f,inv:a=>sn(a,r),sqrt:n.sqrt||(a=>(i||(i=gf(r)),i(c,a))),toBytes:a=>e?Ze(a,s):_e(a,s),fromBytes:a=>{if(a.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+a.length);return e?Ce(a):oe(a)},invertBatch:a=>We(c,a),cmov:(a,f,u)=>u?f:a});return Object.freeze(c)}function $i(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 To(r){let t=$i(r);return t+Math.ceil(t/2)}function Yi(r,t,e=!1){let n=r.length,o=$i(t),s=To(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?Ce(r):oe(r),c=X(i,t-dt)+dt;return e?Ze(c,o):_e(c,o)}var Zi=BigInt(0),Oo=BigInt(1);function Lo(r,t){let e=t.negate();return r?e:t}function Wi(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function Do(r,t){Wi(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=Te(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function ji(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,c=Number(r&o),a=r>>i;c>n&&(c-=s,a+=Oo);let f=t*n,u=f+Math.abs(c)-1,l=c===0,h=c<0,b=t%2!==0;return{nextN:a,offset:u,isZero:l,isNeg:h,isNegF:b,offsetF:f}}function wf(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 Ef(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 Ro=new WeakMap,Xi=new WeakMap;function Uo(r){return Xi.get(r)||1}function an(r,t){return{constTimeNegate:Lo,hasPrecomputes(e){return Uo(e)!==1},unsafeLadder(e,n,o=r.ZERO){let s=e;for(;n>Zi;)n&Oo&&(o=o.add(s)),s=s.double(),n>>=Oo;return o},precomputeWindow(e,n){let{windows:o,windowSize:s}=Do(n,t),i=[],c=e,a=c;for(let f=0;f<o;f++){a=c,i.push(a);for(let u=1;u<s;u++)a=a.add(c),i.push(a);c=a.double()}return i},wNAF(e,n,o){let s=r.ZERO,i=r.BASE,c=Do(e,t);for(let a=0;a<c.windows;a++){let{nextN:f,offset:u,isZero:l,isNeg:h,isNegF:b,offsetF:m}=ji(o,a,c);o=f,l?i=i.add(Lo(b,n[m])):s=s.add(Lo(h,n[u]))}return{p:s,f:i}},wNAFUnsafe(e,n,o,s=r.ZERO){let i=Do(e,t);for(let c=0;c<i.windows&&o!==Zi;c++){let{nextN:a,offset:f,isZero:u,isNeg:l}=ji(o,c,i);if(o=a,!u){let h=n[f];s=s.add(l?h.negate():h)}}return s},getPrecomputes(e,n,o){let s=Ro.get(n);return s||(s=this.precomputeWindow(n,e),e!==1&&Ro.set(n,o(s))),s},wNAFCached(e,n,o){let s=Uo(e);return this.wNAF(s,this.getPrecomputes(s,e,o),n)},wNAFCachedUnsafe(e,n,o,s){let i=Uo(e);return i===1?this.unsafeLadder(e,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,e,o),n,s)},setWindowSize(e,n){Wi(n,t),Xi.set(e,n),Ro.delete(e)}}}function cn(r,t,e,n){wf(e,r),Ef(n,t);let o=e.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=r.ZERO,c=ki(BigInt(o)),a=1;c>12?a=c-3:c>4?a=c-2:c>0&&(a=2);let f=Te(a),u=new Array(Number(f)+1).fill(i),l=Math.floor((t.BITS-1)/a)*a,h=i;for(let b=l;b>=0;b-=a){u.fill(i);for(let y=0;y<s;y++){let D=n[y],U=Number(D>>BigInt(b)&f);u[U]=u[U].add(e[y])}let m=i;for(let y=u.length-1,D=i;y>0;y--)D=D.add(u[y]),m=m.add(D);if(h=h.add(m),b!==0)for(let y=0;y<a;y++)h=h.double()}return h}function Ir(r){return Co(r.Fp),se(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({..._o(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Zt=BigInt(0),St=BigInt(1),Ji=BigInt(2),Af=BigInt(8),Sf={zip215:!0};function vf(r){let t=Ir(r);return se(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...t})}function Qi(r){let t=vf(r),{Fp:e,n,prehash:o,hash:s,randomBytes:i,nByteLength:c,h:a}=t,f=Ji<<BigInt(c*8)-St,u=e.create,l=ie(t.n,t.nBitLength);function h(w,p){let g=e.sqr(w),S=e.sqr(p),T=e.add(e.mul(t.a,g),S),N=e.add(e.ONE,e.mul(t.d,e.mul(g,S)));return e.eql(T,N)}if(!h(t.Gx,t.Gy))throw new Error("bad curve params: generator point");let b=t.uvRatio||((w,p)=>{try{return{isValid:!0,value:e.sqrt(w*e.inv(p))}}catch{return{isValid:!1,value:Zt}}}),m=t.adjustScalarBytes||(w=>w),y=t.domain||((w,p,g)=>{if(Yt("phflag",g),p.length||g)throw new Error("Contexts/pre-hash are not supported");return w});function D(w,p,g=!1){let S=g?St:Zt;Lt("coordinate "+w,p,S,f)}function U(w){if(!(w instanceof d))throw new Error("ExtendedPoint expected")}let Z=je((w,p)=>{let{ex:g,ey:S,ez:T}=w,N=w.is0();p==null&&(p=N?Af:e.inv(T));let F=u(g*p),H=u(S*p),z=u(T*p);if(N)return{x:Zt,y:St};if(z!==St)throw new Error("invZ was invalid");return{x:F,y:H}}),v=je(w=>{let{a:p,d:g}=t;if(w.is0())throw new Error("bad point: ZERO");let{ex:S,ey:T,ez:N,et:F}=w,H=u(S*S),z=u(T*T),j=u(N*N),at=u(j*j),nt=u(H*p),pt=u(j*u(nt+z)),vt=u(at+u(g*u(H*z)));if(pt!==vt)throw new Error("bad point: equation left != right (1)");let ft=u(S*T),gt=u(N*F);if(ft!==gt)throw new Error("bad point: equation left != right (2)");return!0});class d{constructor(p,g,S,T){D("x",p),D("y",g),D("z",S,!0),D("t",T),this.ex=p,this.ey=g,this.ez=S,this.et=T,Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(p){if(p instanceof d)throw new Error("extended point not allowed");let{x:g,y:S}=p||{};return D("x",g),D("y",S),new d(g,S,St,u(g*S))}static normalizeZ(p){let g=We(e,p.map(S=>S.ez));return p.map((S,T)=>S.toAffine(g[T])).map(d.fromAffine)}static msm(p,g){return cn(d,l,p,g)}_setWindowSize(p){P.setWindowSize(this,p)}assertValidity(){v(this)}equals(p){U(p);let{ex:g,ey:S,ez:T}=this,{ex:N,ey:F,ez:H}=p,z=u(g*H),j=u(N*T),at=u(S*H),nt=u(F*T);return z===j&&at===nt}is0(){return this.equals(d.ZERO)}negate(){return new d(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:p}=t,{ex:g,ey:S,ez:T}=this,N=u(g*g),F=u(S*S),H=u(Ji*u(T*T)),z=u(p*N),j=g+S,at=u(u(j*j)-N-F),nt=z+F,pt=nt-H,vt=z-F,ft=u(at*pt),gt=u(nt*vt),_t=u(at*vt),Ut=u(pt*nt);return new d(ft,gt,Ut,_t)}add(p){U(p);let{a:g,d:S}=t,{ex:T,ey:N,ez:F,et:H}=this,{ex:z,ey:j,ez:at,et:nt}=p,pt=u(T*z),vt=u(N*j),ft=u(H*S*nt),gt=u(F*at),_t=u((T+N)*(z+j)-pt-vt),Ut=gt-ft,fr=gt+ft,Gs=u(vt-g*pt),Bc=u(_t*Ut),Cc=u(fr*Gs),_c=u(_t*Gs),Tc=u(Ut*fr);return new d(Bc,Cc,Tc,_c)}subtract(p){return this.add(p.negate())}wNAF(p){return P.wNAFCached(this,p,d.normalizeZ)}multiply(p){let g=p;Lt("scalar",g,St,n);let{p:S,f:T}=this.wNAF(g);return d.normalizeZ([S,T])[0]}multiplyUnsafe(p,g=d.ZERO){let S=p;return Lt("scalar",S,Zt,n),S===Zt?I:this.is0()||S===St?this:P.wNAFCachedUnsafe(this,S,d.normalizeZ,g)}isSmallOrder(){return this.multiplyUnsafe(a).is0()}isTorsionFree(){return P.unsafeLadder(this,n).is0()}toAffine(p){return Z(this,p)}clearCofactor(){let{h:p}=t;return p===St?this:this.multiplyUnsafe(p)}static fromHex(p,g=!1){let{d:S,a:T}=t,N=e.BYTES;p=Q("pointHex",p,N),Yt("zip215",g);let F=p.slice(),H=p[N-1];F[N-1]=H&-129;let z=Ce(F),j=g?f:e.ORDER;Lt("pointHex.y",z,Zt,j);let at=u(z*z),nt=u(at-St),pt=u(S*at-T),{isValid:vt,value:ft}=b(nt,pt);if(!vt)throw new Error("Point.fromHex: invalid y coordinate");let gt=(ft&St)===St,_t=(H&128)!==0;if(!g&&ft===Zt&&_t)throw new Error("Point.fromHex: x=0 and x_0=1");return _t!==gt&&(ft=u(-ft)),d.fromAffine({x:ft,y:z})}static fromPrivateKey(p){let{scalar:g}=k(p);return x.multiply(g)}toRawBytes(){let{x:p,y:g}=this.toAffine(),S=Ze(g,e.BYTES);return S[S.length-1]|=p&St?128:0,S}toHex(){return ge(this.toRawBytes())}}d.BASE=new d(t.Gx,t.Gy,St,u(t.Gx*t.Gy)),d.ZERO=new d(Zt,St,St,Zt);let{BASE:x,ZERO:I}=d,P=an(d,c*8);function B(w){return X(w,n)}function R(w){return B(Ce(w))}function k(w){let p=e.BYTES;w=Q("private key",w,p);let g=Q("hashed private key",s(w),2*p),S=m(g.slice(0,p)),T=g.slice(p,2*p),N=R(S);return{head:S,prefix:T,scalar:N}}function _(w){let{head:p,prefix:g,scalar:S}=k(w),T=x.multiply(S),N=T.toRawBytes();return{head:p,prefix:g,scalar:S,point:T,pointBytes:N}}function O(w){return _(w).pointBytes}function L(w=Uint8Array.of(),...p){let g=be(...p);return R(s(y(g,Q("context",w),!!o)))}function it(w,p,g={}){w=Q("message",w),o&&(w=o(w));let{prefix:S,scalar:T,pointBytes:N}=_(p),F=L(g.context,S,w),H=x.multiply(F).toRawBytes(),z=L(g.context,H,N,w),j=B(F+z*T);Lt("signature.s",j,Zt,n);let at=be(H,Ze(j,e.BYTES));return Q("result",at,e.BYTES*2)}let A=Sf;function E(w,p,g,S=A){let{context:T,zip215:N}=S,F=e.BYTES;w=Q("signature",w,2*F),p=Q("message",p),g=Q("publicKey",g,F),N!==void 0&&Yt("zip215",N),o&&(p=o(p));let H=Ce(w.slice(F,2*F)),z,j,at;try{z=d.fromHex(g,N),j=d.fromHex(w.slice(0,F),N),at=x.multiplyUnsafe(H)}catch{return!1}if(!N&&z.isSmallOrder())return!1;let nt=L(T,j.toRawBytes(),z.toRawBytes(),p);return j.add(z.multiplyUnsafe(nt)).subtract(at).clearCofactor().equals(d.ZERO)}return x._setWindowSize(8),{CURVE:t,getPublicKey:O,sign:it,verify:E,ExtendedPoint:d,utils:{getExtendedPublicKey:_,randomPrivateKey:()=>i(e.BYTES),precompute(w=8,p=d.BASE){return p._setWindowSize(w),p.multiply(BigInt(3)),p}}}}var No=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),ta=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Ip=BigInt(0),If=BigInt(1),ea=BigInt(2),Pp=BigInt(3),Pf=BigInt(5),Bf=BigInt(8);function Cf(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=No,c=r*r%s*r%s,a=tt(c,ea,s)*c%s,f=tt(a,If,s)*r%s,u=tt(f,Pf,s)*f%s,l=tt(u,t,s)*u%s,h=tt(l,e,s)*l%s,b=tt(h,n,s)*h%s,m=tt(b,o,s)*b%s,y=tt(m,o,s)*b%s,D=tt(y,t,s)*u%s;return{pow_p_5_8:tt(D,ea,s)*r%s,b2:c}}function _f(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function Tf(r,t){let e=No,n=X(t*t*t,e),o=X(n*n*t,e),s=Cf(r*o).pow_p_5_8,i=X(r*n*s,e),c=X(t*i*i,e),a=i,f=X(i*ta,e),u=c===r,l=c===X(-r,e),h=c===X(-r*ta,e);return u&&(i=a),(l||h)&&(i=f),Gi(i,e)&&(i=X(-i,e)),{isValid:u||l,value:i}}var ra=ie(No,void 0,!0),Lf={a:ra.create(BigInt(-1)),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:ra,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:Bf,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Ri,randomBytes:tn,adjustScalarBytes:_f,uvRatio:Tf},na=Qi(Lf);var un=32;function oa(r,t,e){return na.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}var fn=class{type="Ed25519";raw;constructor(t){this.raw=Ko(t,un)}toMultihash(){return Kt.digest(Gt(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}verify(t,e){return oa(this.raw,e,t)}};function ko(r){return r=Ko(r,un),new fn(r)}function Ko(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new ut(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var Rf=Math.pow(2,7),Uf=Math.pow(2,14),Of=Math.pow(2,21),Mo=Math.pow(2,28),Fo=Math.pow(2,35),Vo=Math.pow(2,42),qo=Math.pow(2,49),Y=128,bt=127;function xt(r){if(r<Rf)return 1;if(r<Uf)return 2;if(r<Of)return 3;if(r<Mo)return 4;if(r<Fo)return 5;if(r<Vo)return 6;if(r<qo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ho(r,t,e=0){switch(xt(r)){case 8:t[e++]=r&255|Y,r/=128;case 7:t[e++]=r&255|Y,r/=128;case 6:t[e++]=r&255|Y,r/=128;case 5:t[e++]=r&255|Y,r/=128;case 4:t[e++]=r&255|Y,r>>>=7;case 3:t[e++]=r&255|Y,r>>>=7;case 2:t[e++]=r&255|Y,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Nf(r,t,e=0){switch(xt(r)){case 8:t.set(e++,r&255|Y),r/=128;case 7:t.set(e++,r&255|Y),r/=128;case 6:t.set(e++,r&255|Y),r/=128;case 5:t.set(e++,r&255|Y),r/=128;case 4:t.set(e++,r&255|Y),r>>>=7;case 3:t.set(e++,r&255|Y),r>>>=7;case 2:t.set(e++,r&255|Y),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function zo(r,t){let e=r[t],n=0;if(n+=e&bt,e<Y||(e=r[t+1],n+=(e&bt)<<7,e<Y)||(e=r[t+2],n+=(e&bt)<<14,e<Y)||(e=r[t+3],n+=(e&bt)<<21,e<Y)||(e=r[t+4],n+=(e&bt)*Mo,e<Y)||(e=r[t+5],n+=(e&bt)*Fo,e<Y)||(e=r[t+6],n+=(e&bt)*Vo,e<Y)||(e=r[t+7],n+=(e&bt)*qo,e<Y))return n;throw new RangeError("Could not decode varint")}function Kf(r,t){let e=r.get(t),n=0;if(n+=e&bt,e<Y||(e=r.get(t+1),n+=(e&bt)<<7,e<Y)||(e=r.get(t+2),n+=(e&bt)<<14,e<Y)||(e=r.get(t+3),n+=(e&bt)<<21,e<Y)||(e=r.get(t+4),n+=(e&bt)*Mo,e<Y)||(e=r.get(t+5),n+=(e&bt)*Fo,e<Y)||(e=r.get(t+6),n+=(e&bt)*Vo,e<Y)||(e=r.get(t+7),n+=(e&bt)*qo,e<Y))return n;throw new RangeError("Could not decode varint")}function Rt(r,t,e=0){return t==null&&(t=Pt(xt(r))),t instanceof Uint8Array?Ho(r,t,e):Nf(r,t,e)}function ae(r,t=0){return r instanceof Uint8Array?zo(r,t):Kf(r,t)}var Go=new Float32Array([-0]),xe=new Uint8Array(Go.buffer);function ia(r,t,e){Go[0]=r,t[e]=xe[0],t[e+1]=xe[1],t[e+2]=xe[2],t[e+3]=xe[3]}function aa(r,t){return xe[0]=r[t],xe[1]=r[t+1],xe[2]=r[t+2],xe[3]=r[t+3],Go[0]}var $o=new Float64Array([-0]),wt=new Uint8Array($o.buffer);function ca(r,t,e){$o[0]=r,t[e]=wt[0],t[e+1]=wt[1],t[e+2]=wt[2],t[e+3]=wt[3],t[e+4]=wt[4],t[e+5]=wt[5],t[e+6]=wt[6],t[e+7]=wt[7]}function ua(r,t){return wt[0]=r[t],wt[1]=r[t+1],wt[2]=r[t+2],wt[3]=r[t+3],wt[4]=r[t+4],wt[5]=r[t+5],wt[6]=r[t+6],wt[7]=r[t+7],$o[0]}var kf=BigInt(Number.MAX_SAFE_INTEGER),Mf=BigInt(Number.MIN_SAFE_INTEGER),Dt=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 De;if(t<kf&&t>Mf)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>fa&&(o=0n,++n>fa&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return De;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):De}},De=new Dt(0,0);De.toBigInt=function(){return 0n};De.zzEncode=De.zzDecode=function(){return this};De.length=function(){return 1};var fa=4294967296n;function la(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 da(r,t,e){if(e-t<1)return"";let o,s=[],i=0,c;for(;t<e;)c=r[t++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|r[t++]&63:c>239&&c<365?(c=((c&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&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 Yo(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 Mt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function dn(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Zo=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,Mt(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 Mt(this,4);return dn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Mt(this,4);return dn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Mt(this,4);let t=aa(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Mt(this,4);let t=ua(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 Mt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return da(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Mt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Mt(this);while((this.buf[this.pos++]&128)!==0);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 Dt(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 Mt(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 Mt(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 Mt(this,8);let t=dn(this.buf,this.pos+=4),e=dn(this.buf,this.pos+=4);return new Dt(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=zo(this.buf,this.pos);return this.pos+=xt(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 jo(r){return new Zo(r instanceof Uint8Array?r:r.subarray())}function Ft(r,t,e){let n=jo(r);return t.decode(n,void 0,e)}function Wo(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return Pt(i);o+i>t&&(n=Pt(t),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var Re=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function Xo(){}var Qo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Ff=Wo();function Vf(r){return globalThis.Buffer!=null?Pt(r):Ff(r)}var Br=class{len;head;tail;states;constructor(){this.len=0,this.head=new Re(Xo,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new Re(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new ts((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(hn,10,Dt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=Dt.fromBigInt(t);return this._push(hn,e.length(),e)}uint64Number(t){return this._push(Ho,xt(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=Dt.fromBigInt(t).zzEncode();return this._push(hn,e.length(),e)}sint64Number(t){let e=Dt.fromNumber(t).zzEncode();return this._push(hn,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Jo,1,t?1:0)}fixed32(t){return this._push(Pr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=Dt.fromBigInt(t);return this._push(Pr,4,e.lo)._push(Pr,4,e.hi)}fixed64Number(t){let e=Dt.fromNumber(t);return this._push(Pr,4,e.lo)._push(Pr,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(ia,4,t)}double(t){return this._push(ca,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Jo,1,0):this.uint32(e)._push(Hf,e,t)}string(t){let e=la(t);return e!==0?this.uint32(e)._push(Yo,e,t):this._push(Jo,1,0)}fork(){return this.states=new Qo(this),this.head=this.tail=new Re(Xo,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 Re(Xo,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=Vf(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Jo(r,t,e){t[e]=r&255}function qf(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var ts=class extends Re{next;constructor(t,e){super(qf,t,e),this.next=void 0}};function hn(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 Pr(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 Hf(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Br.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(zf,t,r),this},Br.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Gf,t,r),this});function zf(r,t,e){t.set(r,e)}function Gf(r,t,e){r.length<40?Yo(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(V(r),e)}function es(){return new Br}function Vt(r,t){let e=es();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}var Xe;(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"})(Xe||(Xe={}));function pn(r,t,e,n){return{name:r,type:t,encode:e,decode:n}}function rs(r){function t(o){if(r[o.toString()]==null)throw new Error("Invalid enum value");return r[o]}let e=function(s,i){let c=t(s);i.int32(c)},n=function(s){let i=s.int32();return t(i)};return pn("enum",Xe.VARINT,e,n)}function qt(r,t){return pn("message",Xe.LENGTH_DELIMITED,r,t)}var Ue=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var st;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(st||(st={}));var ns;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(ns||(ns={}));(function(r){r.codec=()=>rs(ns)})(st||(st={}));var jt;(function(r){let t;r.codec=()=>(t==null&&(t=qt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),st.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 c=e.uint32();switch(c>>>3){case 1:{s.Type=st.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return s})),t),r.encode=e=>Vt(e,r.codec()),r.decode=(e,n)=>Ft(e,r.codec(),n)})(jt||(jt={}));var os;(function(r){let t;r.codec=()=>(t==null&&(t=qt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.Type!=null&&(n.uint32(8),st.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 c=e.uint32();switch(c>>>3){case 1:{s.Type=st.codec().decode(e);break}case 2:{s.Data=e.bytes();break}default:{e.skipType(c&7);break}}}return s})),t),r.encode=e=>Vt(e,r.codec()),r.decode=(e,n)=>Ft(e,r.codec(),n)})(os||(os={}));var Cr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},mn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var ma={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new mn("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var we=ma;var Tr={};It(Tr,{MAX_RSA_KEY_SIZE:()=>ss,generateRSAKeyPair:()=>xa,jwkToJWKKeyPair:()=>wa,jwkToPkcs1:()=>jf,jwkToPkix:()=>us,jwkToRSAPrivateKey:()=>hs,pkcs1MessageToJwk:()=>as,pkcs1MessageToRSAPrivateKey:()=>fs,pkcs1ToJwk:()=>Zf,pkcs1ToRSAPrivateKey:()=>ba,pkixMessageToJwk:()=>cs,pkixMessageToRSAPublicKey:()=>ds,pkixToJwk:()=>Wf,pkixToRSAPublicKey:()=>ls});var yn=nn;var Je=class{type="RSA";jwk;_raw;_multihash;constructor(t,e){this.jwk=t,this._multihash=e}get raw(){return this._raw==null&&(this._raw=Tr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return ct.createV1(114,this._multihash)}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}verify(t,e){return ga(this.jwk,e,t)}},_r=class{type="RSA";jwk;_raw;publicKey;constructor(t,e){this.jwk=t,this.publicKey=e}get raw(){return this._raw==null&&(this._raw=Tr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}sign(t){return ya(this.jwk,t)}};var ss=8192,is=18,$f=1062,Yf=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Zf(r){let t=te(r);return as(t)}function as(r){return{n:K(r[1],"base64url"),e:K(r[2],"base64url"),d:K(r[3],"base64url"),p:K(r[4],"base64url"),q:K(r[5],"base64url"),dp:K(r[6],"base64url"),dq:K(r[7],"base64url"),qi:K(r[8],"base64url"),kty:"RSA"}}function jf(r){if(r.n==null||r.e==null||r.d==null||r.p==null||r.q==null||r.dp==null||r.dq==null||r.qi==null)throw new ut("JWK was missing components");return he([Bt(Uint8Array.from([0])),Bt(V(r.n,"base64url")),Bt(V(r.e,"base64url")),Bt(V(r.d,"base64url")),Bt(V(r.p,"base64url")),Bt(V(r.q,"base64url")),Bt(V(r.dp,"base64url")),Bt(V(r.dq,"base64url")),Bt(V(r.qi,"base64url"))]).subarray()}function Wf(r){let t=te(r,{offset:0});return cs(t)}function cs(r){let t=te(r[1],{offset:0});return{kty:"RSA",n:K(t[0],"base64url"),e:K(t[1],"base64url")}}function us(r){if(r.n==null||r.e==null)throw new ut("JWK was missing components");return he([Yf,Xr(he([Bt(V(r.n,"base64url")),Bt(V(r.e,"base64url"))]))]).subarray()}function ba(r){let t=te(r);return fs(t)}function fs(r){let t=as(r);return hs(t)}function ls(r,t){if(r.byteLength>=$f)throw new Me("Key size is too large");let e=te(r,{offset:0});return ds(e,r,t)}function ds(r,t,e){let n=cs(r);if(e==null){let o=yn(jt.encode({Type:st.RSA,Data:t}));e=Nt(is,o)}return new Je(n,e)}function hs(r){if(Aa(r)>ss)throw new ut("Key size is too large");let t=wa(r),e=yn(jt.encode({Type:st.RSA,Data:us(t.publicKey)})),n=Nt(is,e);return new _r(t.privateKey,new Je(t.publicKey,n))}async function xa(r){if(r>ss)throw new ut("Key size is too large");let t=await Ea(r),e=yn(jt.encode({Type:st.RSA,Data:us(t.publicKey)})),n=Nt(is,e);return new _r(t.privateKey,new Je(t.publicKey,n))}function wa(r){if(r==null)throw new ut("Missing key parameter");return{privateKey:r,publicKey:{kty:r.kty,n:r.n,e:r.e}}}async function Ea(r){let t=await we.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:r,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]),e=await Xf(t);return{privateKey:e[0],publicKey:e[1]}}async function ya(r,t){let e=await we.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]),n=await we.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},e,t instanceof Uint8Array?t:t.subarray());return new Uint8Array(n,0,n.byteLength)}async function ga(r,t,e){let n=await we.get().subtle.importKey("jwk",r,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);return we.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,t,e instanceof Uint8Array?e:e.subarray())}async function Xf(r){if(r.privateKey==null||r.publicKey==null)throw new ut("Private and public key are required");return Promise.all([we.get().subtle.exportKey("jwk",r.privateKey),we.get().subtle.exportKey("jwk",r.publicKey)])}function Aa(r){if(r.kty!=="RSA")throw new ut("invalid key type");if(r.n==null)throw new ut("invalid key modulus");return V(r.n,"base64url").length*8}var gn=class extends Ge{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,xi(t);let n=xr(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),ee(s)}update(t){return $e(this),this.iHash.update(t),this}digestInto(t){$e(this),Ie(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:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},ps=(r,t,e)=>new gn(r,t).update(e).digest();ps.create=(r,t)=>new gn(r,t);function Sa(r){r.lowS!==void 0&&Yt("lowS",r.lowS),r.prehash!==void 0&&Yt("prehash",r.prehash)}function Jf(r){let t=Ir(r);se(t,{a:"field",b:"field"},{allowInfinityPoint:"boolean",allowedPrivateKeyLengths:"array",clearCofactor:"function",fromBytes:"function",isTorsionFree:"function",toBytes:"function",wrapPrivateKey:"boolean"});let{endo:e,Fp:n,a:o}=t;if(e){if(!n.eql(o,n.ZERO))throw new Error("invalid endo: CURVE.a must be 0");if(typeof e!="object"||typeof e.beta!="bigint"||typeof e.splitScalar!="function")throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function')}return Object.freeze({...t})}var gs=class extends Error{constructor(t=""){super(t)}},ce={Err:gs,_tlv:{encode:(r,t)=>{let{Err:e}=ce;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=Sr(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?Sr(o.length/2|128):"";return Sr(r)+s+o+t},decode(r,t){let{Err:e}=ce,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 a=o&127;if(!a)throw new e("tlv.decode(long): indefinite length not supported");if(a>4)throw new e("tlv.decode(long): byte length is too big");let f=t.subarray(n,n+a);if(f.length!==a)throw new e("tlv.decode: length bytes not complete");if(f[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let u of f)i=i<<8|u;if(n+=a,i<128)throw new e("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new e("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=ce;if(r<ue)throw new t("integer: negative integers are not allowed");let e=Sr(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}=ce;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 oe(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=ce,o=Q("signature",r),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,s),{v:f,l:u}=n.decode(2,a);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(c),s:e.decode(f)}},hexFromSig(r){let{_tlv:t,_int:e}=ce,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}};function ms(r,t){return ge(_e(r,t))}var ue=BigInt(0),ht=BigInt(1),em=BigInt(2),ys=BigInt(3),Qf=BigInt(4);function tl(r){let t=Jf(r),{Fp:e}=t,n=ie(t.n,t.nBitLength),o=t.toBytes||((v,d,x)=>{let I=d.toAffine();return be(Uint8Array.from([4]),e.toBytes(I.x),e.toBytes(I.y))}),s=t.fromBytes||(v=>{let d=v.subarray(1),x=e.fromBytes(d.subarray(0,e.BYTES)),I=e.fromBytes(d.subarray(e.BYTES,2*e.BYTES));return{x,y:I}});function i(v){let{a:d,b:x}=t,I=e.sqr(v),P=e.mul(I,v);return e.add(e.add(P,e.mul(v,d)),x)}function c(v,d){let x=e.sqr(d),I=i(v);return e.eql(x,I)}if(!c(t.Gx,t.Gy))throw new Error("bad curve params: generator point");let a=e.mul(e.pow(t.a,ys),Qf),f=e.mul(e.sqr(t.b),BigInt(27));if(e.is0(e.add(a,f)))throw new Error("bad curve params: a or b");function u(v){return on(v,ht,t.n)}function l(v){let{allowedPrivateKeyLengths:d,nByteLength:x,wrapPrivateKey:I,n:P}=t;if(d&&typeof v!="bigint"){if(Ye(v)&&(v=ge(v)),typeof v!="string"||!d.includes(v.length))throw new Error("invalid private key");v=v.padStart(x*2,"0")}let B;try{B=typeof v=="bigint"?v:oe(Q("private key",v,x))}catch{throw new Error("invalid private key, expected hex or "+x+" bytes, got "+typeof v)}return I&&(B=X(B,P)),Lt("private key",B,ht,P),B}function h(v){if(!(v instanceof y))throw new Error("ProjectivePoint expected")}let b=je((v,d)=>{let{px:x,py:I,pz:P}=v;if(e.eql(P,e.ONE))return{x,y:I};let B=v.is0();d==null&&(d=B?e.ONE:e.inv(P));let R=e.mul(x,d),k=e.mul(I,d),_=e.mul(P,d);if(B)return{x:e.ZERO,y:e.ZERO};if(!e.eql(_,e.ONE))throw new Error("invZ was invalid");return{x:R,y:k}}),m=je(v=>{if(v.is0()){if(t.allowInfinityPoint&&!e.is0(v.py))return;throw new Error("bad point: ZERO")}let{x:d,y:x}=v.toAffine();if(!e.isValid(d)||!e.isValid(x))throw new Error("bad point: x or y not FE");if(!c(d,x))throw new Error("bad point: equation left != right");if(!v.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class y{constructor(d,x,I){if(d==null||!e.isValid(d))throw new Error("x required");if(x==null||!e.isValid(x)||e.is0(x))throw new Error("y required");if(I==null||!e.isValid(I))throw new Error("z required");this.px=d,this.py=x,this.pz=I,Object.freeze(this)}static fromAffine(d){let{x,y:I}=d||{};if(!d||!e.isValid(x)||!e.isValid(I))throw new Error("invalid affine point");if(d instanceof y)throw new Error("projective point not allowed");let P=B=>e.eql(B,e.ZERO);return P(x)&&P(I)?y.ZERO:new y(x,I,e.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(d){let x=We(e,d.map(I=>I.pz));return d.map((I,P)=>I.toAffine(x[P])).map(y.fromAffine)}static fromHex(d){let x=y.fromAffine(s(Q("pointHex",d)));return x.assertValidity(),x}static fromPrivateKey(d){return y.BASE.multiply(l(d))}static msm(d,x){return cn(y,n,d,x)}_setWindowSize(d){Z.setWindowSize(this,d)}assertValidity(){m(this)}hasEvenY(){let{y:d}=this.toAffine();if(e.isOdd)return!e.isOdd(d);throw new Error("Field doesn't support isOdd")}equals(d){h(d);let{px:x,py:I,pz:P}=this,{px:B,py:R,pz:k}=d,_=e.eql(e.mul(x,k),e.mul(B,P)),O=e.eql(e.mul(I,k),e.mul(R,P));return _&&O}negate(){return new y(this.px,e.neg(this.py),this.pz)}double(){let{a:d,b:x}=t,I=e.mul(x,ys),{px:P,py:B,pz:R}=this,k=e.ZERO,_=e.ZERO,O=e.ZERO,L=e.mul(P,P),it=e.mul(B,B),A=e.mul(R,R),E=e.mul(P,B);return E=e.add(E,E),O=e.mul(P,R),O=e.add(O,O),k=e.mul(d,O),_=e.mul(I,A),_=e.add(k,_),k=e.sub(it,_),_=e.add(it,_),_=e.mul(k,_),k=e.mul(E,k),O=e.mul(I,O),A=e.mul(d,A),E=e.sub(L,A),E=e.mul(d,E),E=e.add(E,O),O=e.add(L,L),L=e.add(O,L),L=e.add(L,A),L=e.mul(L,E),_=e.add(_,L),A=e.mul(B,R),A=e.add(A,A),L=e.mul(A,E),k=e.sub(k,L),O=e.mul(A,it),O=e.add(O,O),O=e.add(O,O),new y(k,_,O)}add(d){h(d);let{px:x,py:I,pz:P}=this,{px:B,py:R,pz:k}=d,_=e.ZERO,O=e.ZERO,L=e.ZERO,it=t.a,A=e.mul(t.b,ys),E=e.mul(x,B),C=e.mul(I,R),w=e.mul(P,k),p=e.add(x,I),g=e.add(B,R);p=e.mul(p,g),g=e.add(E,C),p=e.sub(p,g),g=e.add(x,P);let S=e.add(B,k);return g=e.mul(g,S),S=e.add(E,w),g=e.sub(g,S),S=e.add(I,P),_=e.add(R,k),S=e.mul(S,_),_=e.add(C,w),S=e.sub(S,_),L=e.mul(it,g),_=e.mul(A,w),L=e.add(_,L),_=e.sub(C,L),L=e.add(C,L),O=e.mul(_,L),C=e.add(E,E),C=e.add(C,E),w=e.mul(it,w),g=e.mul(A,g),C=e.add(C,w),w=e.sub(E,w),w=e.mul(it,w),g=e.add(g,w),E=e.mul(C,g),O=e.add(O,E),E=e.mul(S,g),_=e.mul(p,_),_=e.sub(_,E),E=e.mul(p,C),L=e.mul(S,L),L=e.add(L,E),new y(_,O,L)}subtract(d){return this.add(d.negate())}is0(){return this.equals(y.ZERO)}wNAF(d){return Z.wNAFCached(this,d,y.normalizeZ)}multiplyUnsafe(d){let{endo:x,n:I}=t;Lt("scalar",d,ue,I);let P=y.ZERO;if(d===ue)return P;if(this.is0()||d===ht)return this;if(!x||Z.hasPrecomputes(this))return Z.wNAFCachedUnsafe(this,d,y.normalizeZ);let{k1neg:B,k1:R,k2neg:k,k2:_}=x.splitScalar(d),O=P,L=P,it=this;for(;R>ue||_>ue;)R&ht&&(O=O.add(it)),_&ht&&(L=L.add(it)),it=it.double(),R>>=ht,_>>=ht;return B&&(O=O.negate()),k&&(L=L.negate()),L=new y(e.mul(L.px,x.beta),L.py,L.pz),O.add(L)}multiply(d){let{endo:x,n:I}=t;Lt("scalar",d,ht,I);let P,B;if(x){let{k1neg:R,k1:k,k2neg:_,k2:O}=x.splitScalar(d),{p:L,f:it}=this.wNAF(k),{p:A,f:E}=this.wNAF(O);L=Z.constTimeNegate(R,L),A=Z.constTimeNegate(_,A),A=new y(e.mul(A.px,x.beta),A.py,A.pz),P=L.add(A),B=it.add(E)}else{let{p:R,f:k}=this.wNAF(d);P=R,B=k}return y.normalizeZ([P,B])[0]}multiplyAndAddUnsafe(d,x,I){let P=y.BASE,B=(k,_)=>_===ue||_===ht||!k.equals(P)?k.multiplyUnsafe(_):k.multiply(_),R=B(this,x).add(B(d,I));return R.is0()?void 0:R}toAffine(d){return b(this,d)}isTorsionFree(){let{h:d,isTorsionFree:x}=t;if(d===ht)return!0;if(x)return x(y,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){let{h:d,clearCofactor:x}=t;return d===ht?this:x?x(y,this):this.multiplyUnsafe(t.h)}toRawBytes(d=!0){return Yt("isCompressed",d),this.assertValidity(),o(y,this,d)}toHex(d=!0){return Yt("isCompressed",d),ge(this.toRawBytes(d))}}y.BASE=new y(t.Gx,t.Gy,e.ONE),y.ZERO=new y(e.ZERO,e.ONE,e.ZERO);let{endo:D,nBitLength:U}=t,Z=an(y,D?Math.ceil(U/2):U);return{CURVE:t,ProjectivePoint:y,normPrivateKeyToScalar:l,weierstrassEquation:i,isWithinCurveOrder:u}}function el(r){let t=Ir(r);return se(t,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...t})}function va(r){let t=el(r),{Fp:e,n,nByteLength:o,nBitLength:s}=t,i=e.BYTES+1,c=2*e.BYTES+1;function a(A){return X(A,n)}function f(A){return sn(A,n)}let{ProjectivePoint:u,normPrivateKeyToScalar:l,weierstrassEquation:h,isWithinCurveOrder:b}=tl({...t,toBytes(A,E,C){let w=E.toAffine(),p=e.toBytes(w.x),g=be;return Yt("isCompressed",C),C?g(Uint8Array.from([E.hasEvenY()?2:3]),p):g(Uint8Array.from([4]),p,e.toBytes(w.y))},fromBytes(A){let E=A.length,C=A[0],w=A.subarray(1);if(E===i&&(C===2||C===3)){let p=oe(w);if(!on(p,ht,e.ORDER))throw new Error("Point is not on curve");let g=h(p),S;try{S=e.sqrt(g)}catch(F){let H=F instanceof Error?": "+F.message:"";throw new Error("Point is not on curve"+H)}let T=(S&ht)===ht;return(C&1)===1!==T&&(S=e.neg(S)),{x:p,y:S}}else if(E===c&&C===4){let p=e.fromBytes(w.subarray(0,e.BYTES)),g=e.fromBytes(w.subarray(e.BYTES,2*e.BYTES));return{x:p,y:g}}else{let p=i,g=c;throw new Error("invalid Point, expected length of "+p+", or uncompressed "+g+", got "+E)}}});function m(A){let E=n>>ht;return A>E}function y(A){return m(A)?a(-A):A}let D=(A,E,C)=>oe(A.slice(E,C));class U{constructor(E,C,w){Lt("r",E,ht,n),Lt("s",C,ht,n),this.r=E,this.s=C,w!=null&&(this.recovery=w),Object.freeze(this)}static fromCompact(E){let C=o;return E=Q("compactSignature",E,C*2),new U(D(E,0,C),D(E,C,2*C))}static fromDER(E){let{r:C,s:w}=ce.toSig(Q("DER",E));return new U(C,w)}assertValidity(){}addRecoveryBit(E){return new U(this.r,this.s,E)}recoverPublicKey(E){let{r:C,s:w,recovery:p}=this,g=P(Q("msgHash",E));if(p==null||![0,1,2,3].includes(p))throw new Error("recovery id invalid");let S=p===2||p===3?C+t.n:C;if(S>=e.ORDER)throw new Error("recovery id 2 or 3 invalid");let T=(p&1)===0?"02":"03",N=u.fromHex(T+ms(S,e.BYTES)),F=f(S),H=a(-g*F),z=a(w*F),j=u.BASE.multiplyAndAddUnsafe(N,H,z);if(!j)throw new Error("point at infinify");return j.assertValidity(),j}hasHighS(){return m(this.s)}normalizeS(){return this.hasHighS()?new U(this.r,a(-this.s),this.recovery):this}toDERRawBytes(){return vr(this.toDERHex())}toDERHex(){return ce.hexFromSig(this)}toCompactRawBytes(){return vr(this.toCompactHex())}toCompactHex(){let E=o;return ms(this.r,E)+ms(this.s,E)}}let Z={isValidPrivateKey(A){try{return l(A),!0}catch{return!1}},normPrivateKeyToScalar:l,randomPrivateKey:()=>{let A=To(t.n);return Yi(t.randomBytes(A),t.n)},precompute(A=8,E=u.BASE){return E._setWindowSize(A),E.multiply(BigInt(3)),E}};function v(A,E=!0){return u.fromPrivateKey(A).toRawBytes(E)}function d(A){if(typeof A=="bigint")return!1;if(A instanceof u)return!0;let C=Q("key",A).length,w=e.BYTES,p=w+1,g=2*w+1;if(!(t.allowedPrivateKeyLengths||o===p))return C===p||C===g}function x(A,E,C=!0){if(d(A)===!0)throw new Error("first arg must be private key");if(d(E)===!1)throw new Error("second arg must be public key");return u.fromHex(E).multiply(l(A)).toRawBytes(C)}let I=t.bits2int||function(A){if(A.length>8192)throw new Error("input is too large");let E=oe(A),C=A.length*8-s;return C>0?E>>BigInt(C):E},P=t.bits2int_modN||function(A){return a(I(A))},B=Te(s);function R(A){return Lt("num < 2^"+s,A,ue,B),_e(A,o)}function k(A,E,C=_){if(["recovered","canonical"].some(nt=>nt in C))throw new Error("sign() legacy options not supported");let{hash:w,randomBytes:p}=t,{lowS:g,prehash:S,extraEntropy:T}=C;g==null&&(g=!0),A=Q("msgHash",A),Sa(C),S&&(A=Q("prehashed msgHash",w(A)));let N=P(A),F=l(E),H=[R(F),R(N)];if(T!=null&&T!==!1){let nt=T===!0?p(e.BYTES):T;H.push(Q("extraEntropy",nt))}let z=be(...H),j=N;function at(nt){let pt=I(nt);if(!b(pt))return;let vt=f(pt),ft=u.BASE.multiply(pt).toAffine(),gt=a(ft.x);if(gt===ue)return;let _t=a(vt*a(j+gt*F));if(_t===ue)return;let Ut=(ft.x===gt?0:2)|Number(ft.y&ht),fr=_t;return g&&m(_t)&&(fr=y(_t),Ut^=1),new U(gt,fr,Ut)}return{seed:z,k2sig:at}}let _={lowS:t.lowS,prehash:!1},O={lowS:t.lowS,prehash:!1};function L(A,E,C=_){let{seed:w,k2sig:p}=k(A,E,C),g=t;return Mi(g.hash.outputLen,g.nByteLength,g.hmac)(w,p)}u.BASE._setWindowSize(8);function it(A,E,C,w=O){let p=A;E=Q("msgHash",E),C=Q("publicKey",C);let{lowS:g,prehash:S,format:T}=w;if(Sa(w),"strict"in w)throw new Error("options.strict was renamed to lowS");if(T!==void 0&&T!=="compact"&&T!=="der")throw new Error("format must be compact or der");let N=typeof p=="string"||Ye(p),F=!N&&!T&&typeof p=="object"&&p!==null&&typeof p.r=="bigint"&&typeof p.s=="bigint";if(!N&&!F)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let H,z;try{if(F&&(H=new U(p.r,p.s)),N){try{T!=="compact"&&(H=U.fromDER(p))}catch(Ut){if(!(Ut instanceof ce.Err))throw Ut}!H&&T!=="der"&&(H=U.fromCompact(p))}z=u.fromHex(C)}catch{return!1}if(!H||g&&H.hasHighS())return!1;S&&(E=t.hash(E));let{r:j,s:at}=H,nt=P(E),pt=f(at),vt=a(nt*pt),ft=a(j*pt),gt=u.BASE.multiplyAndAddUnsafe(z,vt,ft)?.toAffine();return gt?a(gt.x)===j:!1}return{CURVE:t,getPublicKey:v,getSharedSecret:x,sign:L,verify:it,ProjectivePoint:u,Signature:U,utils:Z}}function rl(r){return{hash:r,hmac:(t,...e)=>ps(r,t,bo(...e)),randomBytes:tn}}function Ia(r,t){let e=n=>va({...r,...rl(n)});return{...e(t),create:e}}var Ca=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Pa=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),nl=BigInt(0),ol=BigInt(1),bs=BigInt(2),Ba=(r,t)=>(r+t/bs)/t;function sl(r){let t=Ca,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),f=r*r*r%t,u=f*f*r%t,l=tt(u,e,t)*u%t,h=tt(l,e,t)*u%t,b=tt(h,bs,t)*f%t,m=tt(b,o,t)*b%t,y=tt(m,s,t)*m%t,D=tt(y,c,t)*y%t,U=tt(D,a,t)*D%t,Z=tt(U,c,t)*y%t,v=tt(Z,e,t)*u%t,d=tt(v,i,t)*m%t,x=tt(d,n,t)*f%t,I=tt(x,bs,t);if(!xs.eql(xs.sqr(I),r))throw new Error("Cannot find square root");return I}var xs=ie(Ca,void 0,void 0,{sqrt:sl}),Qe=Ia({a:nl,b:BigInt(7),Fp:xs,n:Pa,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:r=>{let t=Pa,e=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-ol*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),o=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=e,i=BigInt("0x100000000000000000000000000000000"),c=Ba(s*r,t),a=Ba(-n*r,t),f=X(r-c*e-a*o,t),u=X(-c*n-a*s,t),l=f>i,h=u>i;if(l&&(f=t-f),h&&(u=t-u),f>i||u>i)throw new Error("splitScalar: Endomorphism failed, k="+r);return{k1neg:l,k1:f,k2neg:h,k2:u}}}},nn);function _a(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}function Ta(r,t,e){let n=mr.digest(e instanceof Uint8Array?e:e.subarray());if(_a(n))return n.then(({digest:o})=>Qe.verify(t,o,r)).catch(o=>{throw new Cr(String(o))});try{return Qe.verify(t,n.digest,r)}catch(o){throw new Cr(String(o))}}var bn=class{type="secp256k1";raw;_key;constructor(t){this._key=Da(t),this.raw=La(this._key)}toMultihash(){return Kt.digest(Gt(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:lt(this.raw,t.raw)}verify(t,e){return Ta(this._key,e,t)}};function ws(r){return new bn(r)}function La(r){return Qe.ProjectivePoint.fromHex(r).toRawBytes(!0)}function Da(r){try{return Qe.ProjectivePoint.fromHex(r),r}catch(t){throw new Me(String(t))}}function tr(r,t){let{Type:e,Data:n}=jt.decode(r),o=n??new Uint8Array;switch(e){case st.RSA:return ls(o,t);case st.Ed25519:return ko(o);case st.secp256k1:return ws(o);case st.ECDSA:return go(o);default:throw new Ae}}function Ra(r){let{Type:t,Data:e}=jt.decode(r.digest),n=e??new Uint8Array;switch(t){case st.Ed25519:return ko(n);case st.secp256k1:return ws(n);case st.ECDSA:return go(n);default:throw new Ae}}function Gt(r){return jt.encode({Type:st[r.type],Data:r.raw})}var Lr;(function(r){let t;r.codec=()=>(t==null&&(t=qt((e,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),e.publicKey!=null&&e.publicKey.byteLength>0&&(n.uint32(10),n.bytes(e.publicKey)),e.payloadType!=null&&e.payloadType.byteLength>0&&(n.uint32(18),n.bytes(e.payloadType)),e.payload!=null&&e.payload.byteLength>0&&(n.uint32(26),n.bytes(e.payload)),e.signature!=null&&e.signature.byteLength>0&&(n.uint32(42),n.bytes(e.signature)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={publicKey:mt(0),payloadType:mt(0),payload:mt(0),signature:mt(0)},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let c=e.uint32();switch(c>>>3){case 1:{s.publicKey=e.bytes();break}case 2:{s.payloadType=e.bytes();break}case 3:{s.payload=e.bytes();break}case 5:{s.signature=e.bytes();break}default:{e.skipType(c&7);break}}}return s})),t),r.encode=e=>Vt(e,r.codec()),r.decode=(e,n)=>Ft(e,r.codec(),n)})(Lr||(Lr={}));var xn=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var Wt=class r{static createFromProtobuf=async t=>{let e=Lr.decode(t),n=tr(e.publicKey);return new r({publicKey:n,payloadType:e.payloadType,payload:e.payload,signature:e.signature})};static seal=async(t,e)=>{if(e==null)throw new Error("Missing private key");let n=t.domain,o=t.codec,s=t.marshal(),i=Ua(n,o,s),c=await e.sign(i.subarray());return new r({publicKey:e.publicKey,payloadType:o,payload:s,signature:c})};static openAndCertify=async(t,e)=>{let n=await r.createFromProtobuf(t);if(!await n.validate(e))throw new xn("Envelope signature is not valid for the given domain");return n};publicKey;payloadType;payload;signature;marshaled;constructor(t){let{publicKey:e,payloadType:n,payload:o,signature:s}=t;this.publicKey=e,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=Lr.encode({publicKey:Gt(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return t==null?!1:lt(this.marshal(),t.marshal())}async validate(t){let e=Ua(t,this.payloadType,this.payload);return this.publicKey.verify(e.subarray(),this.signature)}},Ua=(r,t,e)=>{let n=V(r),o=Rt(n.byteLength),s=Rt(t.length),i=Rt(e.length);return new ot(o,n,s,t,i,e)};var Oa=Symbol.for("nodejs.util.inspect.custom"),il=114,Dr=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()})`}[qn]=!0;toString(){return this.string==null&&(this.string=J.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ct.createV1(il,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return lt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return lt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Oa](){return`PeerId(${this.toString()})`}},Rr=class extends Dr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Ur=class extends Dr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Or=class extends Dr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},al=2336,Nr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Kt.digest(V(this.url))}[Oa](){return`PeerId(${this.url})`}[qn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ct.createV1(al,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=K(t)),t.toString()===this.toString())}};var cl=114,Na=2336;function Ka(r){if(r.type==="Ed25519")return new Ur({multihash:r.toCID().multihash,publicKey:r});if(r.type==="secp256k1")return new Or({multihash:r.toCID().multihash,publicKey:r});if(r.type==="RSA")return new Rr({multihash:r.toCID().multihash,publicKey:r});throw new Ae}function Es(r){if(fl(r))return new Rr({multihash:r});if(ul(r))try{let t=Ra(r);if(t.type==="Ed25519")return new Ur({multihash:r,publicKey:t});if(t.type==="secp256k1")return new Or({multihash:r,publicKey:t})}catch{let e=K(r.digest);return new Nr(new URL(e))}throw new Gr("Supplied PeerID Multihash is invalid")}function wn(r){if(r?.multihash==null||r.version==null||r.version===1&&r.code!==cl&&r.code!==Na)throw new zr("Supplied PeerID CID is invalid");if(r.code===Na){let t=K(r.multihash.digest);return new Nr(new URL(t))}return Es(r.multihash)}function ul(r){return r.code===Kt.code}function fl(r){return r.code===mr.code}function ka(r,t){let e=(n,o)=>n.toString().localeCompare(o.toString());return r.length!==t.length?!1:(t.sort(e),r.sort(e).every((n,o)=>t[o].equals(n)))}var En=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,c=this.peekChar();if(c===void 0)return;let a=c==="0",f=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let h=Number.parseInt(l,t);if(!Number.isNaN(h))return h});if(u===void 0)break;if(s*=t,s+=u,s>f||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&a&&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),[c]=t(s.subarray(0,i));return e.set(s.subarray(0,c),16-c),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Ma=45,ll=15,er=new En;function An(r){if(!(r.length>ll))return er.new(r).parseWith(()=>er.readIPv4Addr())}function Sn(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Ma))return er.new(r).parseWith(()=>er.readIPv6Addr())}function Oe(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>Ma)return;let e=er.new(r).parseWith(()=>er.readIPAddr());if(e)return t&&e.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,e[0],e[1],e[2],e[3]]):e}function Fa(r,t,e){let n=0;for(let o of r)if(!(n<t)){if(n>e)break;if(o!==255)return!1;n++}return!0}function Va(r,t,e,n){let o=0;for(let s of r)if(!(o<e)){if(o>n)break;if(s!==t[o])return!1;o++}return!0}function As(r){switch(r.length){case Ne:return r.join(".");case Ke:{let t=[];for(let e=0;e<r.length;e++)e%2===0&&t.push(r[e].toString(16).padStart(2,"0")+r[e+1].toString(16).padStart(2,"0"));return t.join(":")}default:throw new Error("Invalid ip length")}}function qa(r){let t=0;for(let[e,n]of r.entries()){if(n===255){t+=8;continue}for(;(n&128)!=0;)t++,n=n<<1;if((n&128)!=0)return-1;for(let o=e+1;o<r.length;o++)if(r[o]!=0)return-1;break}return t}function Ha(r){let t="0x";for(let e of r)t+=(e>>4).toString(16)+(e&15).toString(16);return t}var Ne=4,Ke=16,Ry=parseInt("0xFFFF",16),dl=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Kr(r,t){t.length===Ke&&r.length===Ne&&Fa(t,0,11)&&(t=t.slice(12)),t.length===Ne&&r.length===Ke&&Va(r,dl,0,11)&&(r=r.slice(12));let e=r.length;if(e!=t.length)throw new Error("Failed to mask ip");let n=new Uint8Array(e);for(let o=0;o<e;o++)n[o]=r[o]&t[o];return n}function za(r,t){if(typeof t=="string"&&(t=Oe(t)),t==null)throw new Error("Invalid ip");if(t.length!==r.network.length)return!1;for(let e=0;e<t.length;e++)if((r.network[e]&r.mask[e])!==(t[e]&r.mask[e]))return!1;return!0}function Ss(r){let[t,e]=r.split("/");if(!t||!e)throw new Error("Failed to parse given CIDR: "+r);let n=Ne,o=An(t);if(o==null&&(n=Ke,o=Sn(t),o==null))throw new Error("Failed to parse given CIDR: "+r);let s=parseInt(e,10);if(Number.isNaN(s)||String(s).length!==e.length||s<0||s>n*8)throw new Error("Failed to parse given CIDR: "+r);let i=vs(s,8*n);return{network:Kr(o,i),mask:i}}function vs(r,t){if(t!==8*Ne&&t!==8*Ke)throw new Error("Invalid CIDR mask");if(r<0||r>t)throw new Error("Invalid CIDR mask");let e=t/8,n=new Uint8Array(e);for(let o=0;o<e;o++){if(r>=8){n[o]=255,r-=8;continue}n[o]=255-(255>>r),r=0}return n}var rr=class{constructor(t,e){if(e==null)({network:this.network,mask:this.mask}=Ss(t));else{let n=Oe(t);if(n==null)throw new Error("Failed to parse network");e=String(e);let o=parseInt(e,10);if(Number.isNaN(o)||String(o).length!==e.length||o<0||o>n.length*8){let s=Oe(e);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=vs(o,8*n.length);this.network=Kr(n,this.mask)}}contains(t){return za({network:this.network,mask:this.mask},t)}toString(){let t=qa(this.mask),e=t!==-1?String(t):Ha(this.mask);return As(this.network)+"/"+e}};function Ga(r,t){return new rr(r).contains(t)}function nr(r){return!!An(r)}function or(r){return!!Sn(r)}function vn(r){return!!Oe(r)}var $a=nr,hl=or,Is=function(r){let t=0;if(r=r.toString().trim(),$a(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(hl(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=$a(e[n]),i;s&&(i=Is(e[n]),e[n]=K(i.slice(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,K(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")},Ya=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 sr={},Ps={},ml=[[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"]];ml.forEach(r=>{let t=yl(...r);Ps[t.code]=t,sr[t.name]=t});function yl(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function G(r){if(typeof r=="number"){if(Ps[r]!=null)return Ps[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(sr[r]!=null)return sr[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var dg=G("ip4"),hg=G("ip6"),pg=G("ipcidr");function Ts(r,t){switch(G(r).code){case 4:case 41:return bl(t);case 42:return _s(t);case 43:return K(t,"base10");case 6:case 273:case 33:case 132:return Wa(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return _s(t);case 421:return Al(t);case 444:return ja(t);case 445:return ja(t);case 466:return El(t);case 481:return globalThis.encodeURIComponent(_s(t));default:return K(t,"base16")}}function Ls(r,t){switch(G(r).code){case 4:return Za(t);case 41:return Za(t);case 42:return Cs(t);case 43:return V(t,"base10");case 6:case 273:case 33:case 132:return Ds(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Cs(t);case 421:return xl(t);case 444:return Sl(t);case 445:return vl(t);case 466:return wl(t);case 481:return Cs(globalThis.decodeURIComponent(t));default:return V(t,"base16")}}var Bs=Object.values(yr).map(r=>r.decoder),gl=function(){let r=Bs[0].or(Bs[1]);return Bs.slice(2).forEach(t=>r=r.or(t)),r}();function Za(r){if(!vn(r))throw new Error("invalid ip address");return Is(r)}function bl(r){let t=Ya(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!vn(t))throw new Error("invalid ip address");return t}function Ds(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Wa(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Cs(r){let t=V(r),e=Uint8Array.from(Rt(t.length));return Tt([e,t],e.length+t.length)}function _s(r){let t=ae(r);if(r=r.slice(xt(t)),r.length!==t)throw new Error("inconsistent lengths");return K(r)}function xl(r){let t;r[0]==="Q"||r[0]==="1"?t=Se(J.decode(`z${r}`)).bytes:t=ct.parse(r).multihash.bytes;let e=Uint8Array.from(Rt(t.length));return Tt([e,t],e.length+t.length)}function wl(r){let t=gl.decode(r),e=Uint8Array.from(Rt(t.length));return Tt([e,t],e.length+t.length)}function El(r){let t=ae(r),e=r.slice(xt(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+K(e,"base64url")}function Al(r){let t=ae(r),e=r.slice(xt(t));if(e.length!==t)throw new Error("inconsistent lengths");return K(e,"base58btc")}function Sl(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=Qt.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=Ds(n);return Tt([e,o],e.length+o.length)}function vl(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=Qt.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=Ds(n);return Tt([e,o],e.length+o.length)}function ja(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=K(t,"base32"),o=Wa(e);return`${n}:${o}`}function Xa(r){r=Rs(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],c=G(i);if(c.size===0){t.push([c.code]),e.push([c.code]);continue}if(s++,s>=o.length)throw new In("invalid address: "+r);if(c.path===!0){n=Rs(o.slice(s).join("/")),t.push([c.code,Ls(c.code,n)]),e.push([c.code,n]);break}let a=Ls(c.code,o[s]);t.push([c.code,a]),e.push([c.code,Ts(c.code,a)])}return{string:Ja(e),bytes:Pn(t),tuples:t,stringTuples:e,path:n}}function Us(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let s=ae(r,o),i=xt(s),c=G(s),a=Il(c,r.slice(o+i));if(a===0){t.push([s]),e.push([s]),o+=i;continue}let f=r.slice(o+i,o+i+a);if(o+=a+i,o>r.length)throw new In("Invalid address Uint8Array: "+K(r,"base16"));t.push([s,f]);let u=Ts(s,f);if(e.push([s,u]),c.path===!0){n=u;break}}return{bytes:Uint8Array.from(r),string:Ja(e),tuples:t,stringTuples:e,path:n}}function Ja(r){let t=[];return r.map(e=>{let n=G(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),Rs(t.join("/"))}function Pn(r){return Tt(r.map(t=>{let e=G(t[0]),n=Uint8Array.from(Rt(e.code));return t.length>1&&t[1]!=null&&(n=Tt([n,t[1]])),n}))}function Il(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=ae(t instanceof Uint8Array?t:Uint8Array.from(t));return e+xt(e)}}function Rs(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}var In=class extends Error{static name="ParseError";name="ParseError";constructor(t){super(`Error parsing address: ${t}`)}};var Pl=Symbol.for("nodejs.util.inspect.custom"),Ns=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Bl=[G("dns").code,G("dns4").code,G("dns6").code,G("dnsaddr").code],Os=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},Bn=class r{bytes;#e;#t;#r;#n;[Ns]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=Us(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=Xa(t)}else if(tc(t))e=Us(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=G("tcp"),c=G("udp"),a=G("ip4"),f=G("ip6"),u=G("dns6"),l=G("ip6zone");for(let[b,m]of this.stringTuples())b===l.code&&(s=`%${m??""}`),Bl.includes(b)&&(e=i.name==="tcp"?"tcp":"udp",o=443,n=`${m??""}${s}`,t=b===u.code?6:4),(b===i.code||b===c.code)&&(e=G(b).name==="tcp"?"tcp":"udp",o=parseInt(m??"")),(b===a.code||b===f.code)&&(e=G(b).name==="tcp"?"tcp":"udp",n=`${m??""}${s}`,t=b===f.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({},G(t)))}protoCodes(){return this.#t.map(([t])=>t)}protoNames(){return this.#t.map(([t])=>G(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(Pn(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===sr.p2p.code&&t.push([n,o]),n===sr["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?K(J.decode(`z${n}`),"base58btc"):K(ct.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return lt(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(s=>s.resolvable);if(e==null)return[this];let n=Qa.get(e.name);if(n==null)throw new Os(`no available resolver for ${e.name}`);return(await n(this,t)).map(s=>Xt(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)}[Pl](){return`Multiaddr(${this.#e})`}};var Qa=new Map;function tc(r){return!!r?.[Ns]}function Xt(r){return new Bn(r)}var ec="libp2p-peer-record",rc=Uint8Array.from([3,1]);var kr;(function(r){let t;(function(n){let o;n.codec=()=>(o==null&&(o=qt((s,i,c={})=>{c.lengthDelimited!==!1&&i.fork(),s.multiaddr!=null&&s.multiaddr.byteLength>0&&(i.uint32(10),i.bytes(s.multiaddr)),c.lengthDelimited!==!1&&i.ldelim()},(s,i,c={})=>{let a={multiaddr:mt(0)},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{a.multiaddr=s.bytes();break}default:{s.skipType(u&7);break}}}return a})),o),n.encode=s=>Vt(s,n.codec()),n.decode=(s,i)=>Ft(s,n.codec(),i)})(t=r.AddressInfo||(r.AddressInfo={}));let e;r.codec=()=>(e==null&&(e=qt((n,o,s={})=>{if(s.lengthDelimited!==!1&&o.fork(),n.peerId!=null&&n.peerId.byteLength>0&&(o.uint32(10),o.bytes(n.peerId)),n.seq!=null&&n.seq!==0n&&(o.uint32(16),o.uint64(n.seq)),n.addresses!=null)for(let i of n.addresses)o.uint32(26),r.AddressInfo.codec().encode(i,o);s.lengthDelimited!==!1&&o.ldelim()},(n,o,s={})=>{let i={peerId:mt(0),seq:0n,addresses:[]},c=o==null?n.len:n.pos+o;for(;n.pos<c;){let a=n.uint32();switch(a>>>3){case 1:{i.peerId=n.bytes();break}case 2:{i.seq=n.uint64();break}case 3:{if(s.limits?.addresses!=null&&i.addresses.length===s.limits.addresses)throw new Ue('Decode error - map field "addresses" had too many elements');i.addresses.push(r.AddressInfo.codec().decode(n,n.uint32(),{limits:s.limits?.addresses$}));break}default:{n.skipType(a&7);break}}}return i})),e),r.encode=n=>Vt(n,r.codec()),r.decode=(n,o)=>Ft(n,r.codec(),o)})(kr||(kr={}));var Ht=class r{static createFromProtobuf=t=>{let e=kr.decode(t),n=Es(Se(e.peerId)),o=(e.addresses??[]).map(i=>Xt(i.multiaddr)),s=e.seq;return new r({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=ec;static CODEC=rc;peerId;multiaddrs;seqNumber;domain=r.DOMAIN;codec=r.CODEC;marshaled;constructor(t){let{peerId:e,multiaddrs:n,seqNumber:o}=t;this.peerId=e,this.multiaddrs=n??[],this.seqNumber=o??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=kr.encode({peerId:this.peerId.toMultihash().bytes,seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(t=>({multiaddr:t.bytes}))})),this.marshaled}equals(t){return!(!(t instanceof r)||!this.peerId.equals(t.peerId)||this.seqNumber!==t.seqNumber||!ka(this.multiaddrs,t.multiaddrs))}};function Cl(r){return r[Symbol.asyncIterator]!=null}function _l(r){if(Cl(r))return(async()=>{for await(let t of r);})();for(let t of r);}var nc=_l;function zt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var Cn=globalThis.CustomEvent??Event;async function*Ks(r,t={}){let e=t.concurrency??1/0;e<1&&(e=1/0);let n=t.ordered??!1,o=new EventTarget,s=[],i=zt(),c=zt(),a=!1,f,u=!1;o.addEventListener("task-complete",()=>{c.resolve()}),Promise.resolve().then(async()=>{try{for await(let m of r){if(s.length===e&&(i=zt(),await i.promise),u)break;let y={done:!1};s.push(y),m().then(D=>{y.done=!0,y.ok=!0,y.value=D,o.dispatchEvent(new Cn("task-complete"))},D=>{y.done=!0,y.err=D,o.dispatchEvent(new Cn("task-complete"))})}a=!0,o.dispatchEvent(new Cn("task-complete"))}catch(m){f=m,o.dispatchEvent(new Cn("task-complete"))}});function l(){return n?s[0]?.done:!!s.find(m=>m.done)}function*h(){for(;s.length>0&&s[0].done;){let m=s[0];if(s.shift(),m.ok)yield m.value;else throw u=!0,i.resolve(),m.err;i.resolve()}}function*b(){for(;l();)for(let m=0;m<s.length;m++)if(s[m].done){let y=s[m];if(s.splice(m,1),m--,y.ok)yield y.value;else throw u=!0,i.resolve(),y.err;i.resolve()}}for(;;){if(l()||(c=zt(),await c.promise),f!=null||(n?yield*h():yield*b(),f!=null))throw f;if(a&&s.length===0)break}}var _n=class extends Error{type;code;constructor(t,e,n){super(t??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=e??"ABORT_ERR"}};async function Mr(r,t,e){if(t==null)return r;if(t.aborted)return r.catch(()=>{}),Promise.reject(new _n(e?.errorMessage,e?.errorCode,e?.errorName));let n,o=new _n(e?.errorMessage,e?.errorCode,e?.errorName);try{return await Promise.race([r,new Promise((s,i)=>{n=()=>{i(o)},t.addEventListener("abort",n)})])}finally{n!=null&&t.removeEventListener("abort",n)}}var ks=class{readNext;haveNext;ended;nextResult;error;constructor(){this.ended=!1,this.readNext=zt(),this.haveNext=zt()}[Symbol.asyncIterator](){return this}async next(){if(this.nextResult==null&&await this.haveNext.promise,this.nextResult==null)throw new Error("HaveNext promise resolved but nextResult was undefined");let t=this.nextResult;return this.nextResult=void 0,this.readNext.resolve(),this.readNext=zt(),t}async throw(t){return this.ended=!0,this.error=t,t!=null&&(this.haveNext.promise.catch(()=>{}),this.haveNext.reject(t)),{done:!0,value:void 0}}async return(){let t={done:!0,value:void 0};return this.ended=!0,this.nextResult=t,this.haveNext.resolve(),t}async push(t,e){await this._push(t,e)}async end(t,e){t!=null?await this.throw(t):await this._push(void 0,e)}async _push(t,e){if(t!=null&&this.ended)throw this.error??new Error("Cannot push value onto an ended pushable");for(;this.nextResult!=null;)await this.readNext.promise;t!=null?this.nextResult={done:!1,value:t}:(this.ended=!0,this.nextResult={done:!0,value:void 0}),this.haveNext.resolve(),this.haveNext=zt(),await Mr(this.readNext.promise,e?.signal,e)}};function oc(){return new ks}var Tn=class extends Error{name="UnexpectedEOFError";code="ERR_UNEXPECTED_EOF"};function sc(r,t){let e=oc();r.sink(e).catch(async i=>{await e.end(i)}),r.sink=async i=>{for await(let c of i)await e.push(c);await e.end()};let n=r.source;r.source[Symbol.iterator]!=null?n=r.source[Symbol.iterator]():r.source[Symbol.asyncIterator]!=null&&(n=r.source[Symbol.asyncIterator]());let o=new ot;return{read:async i=>{if(i?.signal?.throwIfAborted(),i?.bytes==null){let{done:a,value:f}=await Mr(n.next(),i?.signal);return a===!0?null:f}for(;o.byteLength<i.bytes;){let{value:a,done:f}=await Mr(n.next(),i?.signal);if(f===!0)throw new Tn("unexpected end of input");o.append(a)}let c=o.sublist(0,i.bytes);return o.consume(i.bytes),c},write:async(i,c)=>{c?.signal?.throwIfAborted(),i instanceof Uint8Array?await e.push(i,c):await e.push(i.subarray(),c)},unwrap:()=>{if(o.byteLength>0){let i=r.source;r.source=async function*(){t?.yieldBytes===!1?yield o:yield*o,yield*i}()}return r}}}var Ln=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Dn=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Rn=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function ic(r,t={}){let e=sc(r,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=xt(t.maxDataLength));let n=t?.lengthDecoder??ae,o=t?.lengthEncoder??Rt;return{read:async i=>{let c=-1,a=new ot;for(;;){a.append(await e.read({...i,bytes:1}));try{c=n(a)}catch(f){if(f instanceof RangeError)continue;throw f}if(c<0)throw new Ln("Invalid message length");if(t?.maxLengthLength!=null&&a.byteLength>t.maxLengthLength)throw new Rn("message length length too long");if(c>-1)break}if(t?.maxDataLength!=null&&c>t.maxDataLength)throw new Dn("message length too long");return e.read({...i,bytes:c})},write:async(i,c)=>{await e.write(new ot(o(i.byteLength),i),c)},writeV:async(i,c)=>{let a=new ot(...i.flatMap(f=>[o(f.byteLength),f]));await e.write(a,c)},unwrap:()=>e.unwrap()}}function ir(r,t){let e=ic(r,t),n={read:async(o,s)=>{let i=await e.read(s);return o.decode(i)},write:async(o,s,i)=>{await e.write(s.encode(o),i)},writeV:async(o,s,i)=>{await e.writeV(o.map(c=>s.encode(c)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>e.unwrap()};return n}var ac="0.1.0",cc="id",uc="id/push",fc="1.0.0",lc="1.0.0";var Ee;(function(r){let t;r.codec=()=>(t==null&&(t=qt((e,n,o={})=>{if(o.lengthDelimited!==!1&&n.fork(),e.protocolVersion!=null&&(n.uint32(42),n.string(e.protocolVersion)),e.agentVersion!=null&&(n.uint32(50),n.string(e.agentVersion)),e.publicKey!=null&&(n.uint32(10),n.bytes(e.publicKey)),e.listenAddrs!=null)for(let s of e.listenAddrs)n.uint32(18),n.bytes(s);if(e.observedAddr!=null&&(n.uint32(34),n.bytes(e.observedAddr)),e.protocols!=null)for(let s of e.protocols)n.uint32(26),n.string(s);e.signedPeerRecord!=null&&(n.uint32(66),n.bytes(e.signedPeerRecord)),o.lengthDelimited!==!1&&n.ldelim()},(e,n,o={})=>{let s={listenAddrs:[],protocols:[]},i=n==null?e.len:e.pos+n;for(;e.pos<i;){let c=e.uint32();switch(c>>>3){case 5:{s.protocolVersion=e.string();break}case 6:{s.agentVersion=e.string();break}case 1:{s.publicKey=e.bytes();break}case 2:{if(o.limits?.listenAddrs!=null&&s.listenAddrs.length===o.limits.listenAddrs)throw new Ue('Decode error - map field "listenAddrs" had too many elements');s.listenAddrs.push(e.bytes());break}case 4:{s.observedAddr=e.bytes();break}case 3:{if(o.limits?.protocols!=null&&s.protocols.length===o.limits.protocols)throw new Ue('Decode error - map field "protocols" had too many elements');s.protocols.push(e.string());break}case 8:{s.signedPeerRecord=e.bytes();break}default:{e.skipType(c&7);break}}}return s})),t),r.encode=e=>Vt(e,r.codec()),r.decode=(e,n)=>Ft(e,r.codec(),n)})(Ee||(Ee={}));var Ct={protocolPrefix:"ipfs",timeout:5e3,maxInboundStreams:1,maxOutboundStreams:1,maxObservedAddresses:10,maxMessageSize:8192,runOnConnectionOpen:!0,runOnSelfUpdate:!0,runOnLimitedConnection:!0,concurrency:32};function dc(r){if(r!=null&&r.length>0)try{return Xt(r)}catch{}}function Dl(r,t){return t??r.userAgent}async function Un(r,t,e,n,o){if(e("received identify from %p",n.remotePeer),o==null)throw new Ot("message was null or undefined");let s={};if(o.listenAddrs.length>0&&(s.addresses=o.listenAddrs.map(a=>({isCertified:!1,multiaddr:Xt(a)}))),o.protocols.length>0&&(s.protocols=o.protocols),o.publicKey!=null){let a=tr(o.publicKey);if(!Ka(a).equals(n.remotePeer))throw new Ot("public key did not match remote PeerId");s.publicKey=a}let i;if(o.signedPeerRecord!=null){e.trace("received signedPeerRecord from %p",n.remotePeer);let a=o.signedPeerRecord,f=await Wt.openAndCertify(a,Ht.DOMAIN),u=Ht.createFromProtobuf(f.payload),l=wn(f.publicKey.toCID());if(!u.peerId.equals(l))throw new Ot("signing key does not match PeerId in the PeerRecord");if(!n.remotePeer.equals(u.peerId))throw new Ot("signing key does not match remote PeerId");let h;try{h=await r.get(u.peerId)}catch(b){if(b.name!=="NotFoundError")throw b}if(h!=null&&(s.metadata=h.metadata,h.peerRecordEnvelope!=null)){let b=await Wt.createFromProtobuf(h.peerRecordEnvelope),m=Ht.createFromProtobuf(b.payload);m.seqNumber>=u.seqNumber&&(e("sequence number was lower or equal to existing sequence number - stored: %d received: %d",m.seqNumber,u.seqNumber),u=m,a=h.peerRecordEnvelope)}s.peerRecordEnvelope=a,s.addresses=u.multiaddrs.map(b=>({isCertified:!0,multiaddr:b})),i={seq:u.seqNumber,addresses:u.multiaddrs}}else e("%p did not send a signed peer record",n.remotePeer);if(e.trace("patching %p with",n.remotePeer,s),await r.patch(n.remotePeer,s),o.agentVersion!=null||o.protocolVersion!=null){let a={};o.agentVersion!=null&&(a.AgentVersion=V(o.agentVersion)),o.protocolVersion!=null&&(a.ProtocolVersion=V(o.protocolVersion)),e.trace("merging %p metadata",n.remotePeer,a),await r.merge(n.remotePeer,{metadata:a})}let c={peerId:n.remotePeer,protocolVersion:o.protocolVersion,agentVersion:o.agentVersion,publicKey:o.publicKey,listenAddrs:o.listenAddrs.map(a=>Xt(a)),observedAddr:o.observedAddr==null?void 0:Xt(o.observedAddr),protocols:o.protocols,signedPeerRecord:i,connection:n};return t.safeDispatchEvent("peer:identify",{detail:c}),c}var ar=class{host;protocol;started;timeout;peerId;privateKey;peerStore;registrar;addressManager;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxObservedAddresses;events;runOnLimitedConnection;log;constructor(t,e){this.protocol=e.protocol,this.started=!1,this.peerId=t.peerId,this.privateKey=t.privateKey,this.peerStore=t.peerStore,this.registrar=t.registrar,this.addressManager=t.addressManager,this.events=t.events,this.log=e.log,this.timeout=e.timeout??Ct.timeout,this.maxInboundStreams=e.maxInboundStreams??Ct.maxInboundStreams,this.maxOutboundStreams=e.maxOutboundStreams??Ct.maxOutboundStreams,this.maxMessageSize=e.maxMessageSize??Ct.maxMessageSize,this.maxObservedAddresses=e.maxObservedAddresses??Ct.maxObservedAddresses,this.runOnLimitedConnection=e.runOnLimitedConnection??Ct.runOnLimitedConnection,this.host={protocolVersion:`${e.protocolPrefix??Ct.protocolPrefix}/${ac}`,agentVersion:Dl(t.nodeInfo,e.agentVersion)}}isStarted(){return this.started}async start(){this.started||(await this.peerStore.merge(this.peerId,{metadata:{AgentVersion:V(this.host.agentVersion),ProtocolVersion:V(this.host.protocolVersion)}}),await this.registrar.handle(this.protocol,t=>{this.handleProtocol(t).catch(e=>{this.log.error(e)})},{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams,runOnLimitedConnection:this.runOnLimitedConnection}),this.started=!0)}async stop(){await this.registrar.unhandle(this.protocol),this.started=!1}};var On=class extends ar{connectionManager;concurrency;constructor(t,e={}){super(t,{...e,protocol:`/${e.protocolPrefix??Ct.protocolPrefix}/${uc}/${lc}`,log:t.logger.forComponent("libp2p:identify-push")}),this.connectionManager=t.connectionManager,this.concurrency=e.concurrency??Ct.concurrency,(e.runOnSelfUpdate??Ct.runOnSelfUpdate)&&t.events.addEventListener("self:peer:update",n=>{this.push().catch(o=>{this.log.error(o)})})}[Yr]=["@libp2p/identify-push"];async push(){if(!this.isStarted())return;let t=this.addressManager.getAddresses().map(u=>u.decapsulateCode(G("p2p").code)),e=new Ht({peerId:this.peerId,multiaddrs:t}),n=await Wt.seal(e,this.privateKey),o=this.registrar.getProtocols(),s=await this.peerStore.get(this.peerId),i=K(s.metadata.get("AgentVersion")??V(this.host.agentVersion)),c=K(s.metadata.get("ProtocolVersion")??V(this.host.protocolVersion)),a=this;async function*f(){for(let u of a.connectionManager.getConnections())(await a.peerStore.get(u.remotePeer)).protocols.includes(a.protocol)&&(yield async()=>{let h,b=AbortSignal.timeout(a.timeout);try{h=await u.newStream(a.protocol,{signal:b,runOnLimitedConnection:a.runOnLimitedConnection}),await ir(h,{maxDataLength:a.maxMessageSize}).pb(Ee).write({listenAddrs:t.map(y=>y.bytes),signedPeerRecord:n.marshal(),protocols:o,agentVersion:i,protocolVersion:c},{signal:b}),await h.close({signal:b})}catch(m){a.log.error("could not push identify update to peer",m),h?.abort(m)}})}await nc(Ks(f(),{concurrency:this.concurrency}))}async handleProtocol(t){let{connection:e,stream:n}=t;try{if(this.peerId.equals(e.remotePeer))throw new Error("received push from ourselves?");let o={signal:AbortSignal.timeout(this.timeout)},i=await ir(n,{maxDataLength:this.maxMessageSize}).pb(Ee).read(o);await n.close(o),await Un(this.peerStore,this.events,this.log,e,i)}catch(o){this.log.error("received invalid message",o),n.abort(o);return}this.log.trace("handled push from %p",e.remotePeer)}};var Ul=41;function hc(r){try{let[[t,e]]=r.stringTuples();if(e==null)return!1;if(t===Ul)return Ga("2000::/3",e)}catch{}return!1}var mc=Kc(pc(),1),Ol=["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"],Nl=Ol.map(r=>new mc.Netmask(r));function Ms(r){for(let t of Nl)if(t.contains(r))return!0;return!1}function Kl(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function kl(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 Ms(o)}function Ml(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function Fl(r){let t=r.split(":"),e=t[t.length-1];return Ms(e)}function Vl(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 yc(r){return nr(r)?Ms(r):Kl(r)?kl(r):Ml(r)?Fl(r):or(r)?Vl(r):void 0}function gc(r){try{let[[t]]=r.stringTuples();return t===4||t===41}catch{}return!1}function bc(r){try{if(!gc(r))return!1;let[[,t]]=r.stringTuples();return t==null?!1:yc(t)??!1}catch{}return!0}var ql=r=>r.toString().split("/").slice(1),cr=r=>({match:t=>t.length<1?!1:r(t[0])?t.slice(1):!1,pattern:"fn"}),M=r=>({match:t=>cr(e=>e===r).match(t),pattern:r}),ke=()=>({match:r=>cr(t=>typeof t=="string").match(r),pattern:"{string}"}),ur=()=>({match:r=>cr(t=>!isNaN(parseInt(t))).match(r),pattern:"{number}"}),W=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{J.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),Vr=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{no.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),$=r=>({match:t=>{let e=r.match(t);return e===!1?t:e},pattern:`optional(${r.pattern})`}),Et=(...r)=>({match:t=>{let e;for(let n of r){let o=n.match(t);o!==!1&&(e==null||o.length<e.length)&&(e=o)}return e??!1},pattern:`or(${r.map(t=>t.pattern).join(", ")})`}),q=(...r)=>({match:t=>{for(let e of r){let n=e.match(t);if(n===!1)return!1;t=n}return t},pattern:`and(${r.map(t=>t.pattern).join(", ")})`});function et(...r){function t(o){let s=ql(o);for(let i of r){let c=i.match(s);if(c===!1)return!1;s=c}return s}function e(o){return t(o)!==!1}function n(o){let s=t(o);return s===!1?!1:s.length===0}return{matchers:r,matches:e,exactMatch:n}}var Hl=W(),nx=et(Hl),Kn=q(M("dns4"),ke()),kn=q(M("dns6"),ke()),Mn=q(M("dnsaddr"),ke()),Vs=q(M("dns"),ke()),ox=et(Kn,$(W())),sx=et(kn,$(W())),ix=et(Mn,$(W())),ax=et(Et(Vs,Mn,Kn,kn),$(W())),xc=q(M("ip4"),cr(nr)),wc=q(M("ip6"),cr(or)),qs=Et(xc,wc),fe=Et(qs,Vs,Kn,kn,Mn),Ec=et(Et(qs,q(Et(Vs,Mn,Kn,kn),$(W())))),cx=et(xc),ux=et(wc),fx=et(qs),Hs=q(fe,M("tcp"),ur()),qr=q(fe,M("udp"),ur()),Ac=et(q(Hs,$(W()))),lx=et(qr),zs=q(qr,M("quic"),$(W())),Fn=q(qr,M("quic-v1"),$(W())),zl=Et(zs,Fn),dx=et(zs),hx=et(Fn),Fs=Et(fe,Hs,qr,zs,Fn),Sc=Et(q(Fs,M("ws"),$(W()))),px=et(Sc),vc=Et(q(Fs,M("wss"),$(W())),q(Fs,M("tls"),$(q(M("sni"),ke())),M("ws"),$(W()))),mx=et(vc),Ic=q(qr,M("webrtc-direct"),$(Vr()),$(Vr()),$(W())),yx=et(Ic),Pc=q(Fn,M("webtransport"),$(Vr()),$(Vr()),$(W())),gx=et(Pc),Nn=Et(Sc,vc,q(Hs,$(W())),q(zl,$(W())),q(fe,$(W())),Ic,Pc,W()),bx=et(Nn),Gl=q(Nn,M("p2p-circuit"),W()),xx=et(Gl),$l=Et(q(Nn,M("p2p-circuit"),M("webrtc"),$(W())),q(Nn,M("webrtc"),$(W())),q(M("webrtc"),$(W()))),wx=et($l),Yl=Et(q(fe,M("tcp"),ur(),M("http"),$(W())),q(fe,M("http"),$(W()))),Ex=et(Yl),Zl=Et(q(fe,M("tcp"),Et(q(M("443"),M("http")),q(ur(),M("https")),q(ur(),M("tls"),M("http"))),$(W())),q(fe,M("tls"),M("http"),$(W())),q(fe,M("https"),$(W()))),Ax=et(Zl),jl=Et(q(M("memory"),ke(),$(W()))),Sx=et(jl);var Wl=41,Vn=class extends ar{constructor(t,e={}){super(t,{...e,protocol:`/${e.protocolPrefix??Ct.protocolPrefix}/${cc}/${fc}`,log:t.logger.forComponent("libp2p:identify")}),(e.runOnConnectionOpen??Ct.runOnConnectionOpen)&&t.events.addEventListener("connection:open",n=>{let o=n.detail;this.identify(o).catch(s=>{s.name!==$r.name&&this.log.error("error during identify trigged by connection:open",s)})})}[Yr]=["@libp2p/identify"];async _identify(t,e={}){let n;if(e.signal==null){let o=AbortSignal.timeout(this.timeout);e={...e,signal:o}}try{n=await t.newStream(this.protocol,{...e,runOnLimitedConnection:this.runOnLimitedConnection});let s=await ir(n,{maxDataLength:this.maxMessageSize}).pb(Ee).read(e);return await n.close(e),s}catch(o){throw n?.abort(o),o}}async identify(t,e={}){let n=await this._identify(t,e),{publicKey:o,protocols:s,observedAddr:i}=n;if(o==null)throw new Ot("public key was missing from identify message");let c=tr(o),a=wn(c.toCID());if(!t.remotePeer.equals(a))throw new Ot("identified peer does not match the expected peer");if(this.peerId.equals(a))throw new Ot("identified peer is our own peer id?");return this.maybeAddObservedAddress(i),this.log("identify completed for peer %p and protocols %o",a,s),Un(this.peerStore,this.events,this.log,t,n)}maybeAddObservedAddress(t){let e=dc(t);if(e==null)return;if(this.log.trace("our observed address was %a",e),bc(e)){this.log.trace("our observed address was private");return}if(e.stringTuples()[0][0]===Wl&&!hc(e)){this.log.trace("our observed address was IPv6 but not a global unicast address");return}Ac.exactMatch(e)||(this.log.trace("storing the observed address"),this.addressManager.addObservedAddr(e))}async handleProtocol(t){let{connection:e,stream:n}=t,o=AbortSignal.timeout(this.timeout);try{let s=await this.peerStore.get(this.peerId),i=this.addressManager.getAddresses().map(u=>u.decapsulateCode(G("p2p").code)),c=s.peerRecordEnvelope;if(i.length>0&&c==null){let u=new Ht({peerId:this.peerId,multiaddrs:i});c=(await Wt.seal(u,this.privateKey)).marshal().subarray()}let a=e.remoteAddr.bytes;Ec.matches(e.remoteAddr)||(a=void 0),await ir(n).pb(Ee).write({protocolVersion:this.host.protocolVersion,agentVersion:this.host.agentVersion,publicKey:Gt(this.privateKey.publicKey),listenAddrs:i.map(u=>u.bytes),signedPeerRecord:c,observedAddr:a,protocols:s.protocols},{signal:o}),await n.close({signal:o})}catch(s){this.log.error("could not respond to identify request",s),n.abort(s)}}};function Xl(r={}){return t=>new Vn(t,r)}function Jl(r={}){return t=>new On(t,r)}return kc(Ql);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/hashes/esm/utils.js: