@libp2p/identify 4.1.5-9eb27be79 → 4.1.5-cc151e147
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 +1 -1
- package/dist/index.min.js.map +3 -3
- package/dist/src/utils.d.ts +2 -1
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +18 -7
- package/dist/src/utils.js.map +1 -1
- package/package.json +8 -8
- package/src/utils.ts +21 -7
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 Zu=Object.create;var hn=Object.defineProperty;var Gu=Object.getOwnPropertyDescriptor;var Wu=Object.getOwnPropertyNames;var Xu=Object.getPrototypeOf,Qu=Object.prototype.hasOwnProperty;var vo=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),ve=(t,e)=>{for(var r in e)hn(t,r,{get:e[r],enumerable:!0})},ra=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Wu(e))!Qu.call(t,o)&&o!==r&&hn(t,o,{get:()=>e[o],enumerable:!(n=Gu(e,o))||n.enumerable});return t};var Ju=(t,e,r)=>(r=t!=null?Zu(Xu(t)):{},ra(e||!t||!t.__esModule?hn(r,"default",{value:t,enumerable:!0}):r,t)),ef=t=>ra(hn({},"__esModule",{value:!0}),t);var Fi=vo(xr=>{"use strict";Object.defineProperty(xr,"__esModule",{value:!0});xr.Netmask4Impl=void 0;xr.ip2long=gr;xr.long2ip=Xe;function Xe(t){let e=(t&-16777216)>>>24,r=(t&255<<16)>>>16,n=(t&65280)>>>8,o=t&255;return[e,r,n,o].join(".")}var ih=48,ah=97,ch=65;function uh(t){let e=0,r=10,n="9",o=0;t.length>1&&t[o]==="0"&&(t[o+1]==="x"||t[o+1]==="X"?(o+=2,r=16):"0"<=t[o+1]&&t[o+1]<="9"&&(o++,r=8,n="7"));let s=o;for(;o<t.length;){if("0"<=t[o]&&t[o]<=n)e=e*r+(t.charCodeAt(o)-ih)>>>0;else if(r===16)if("a"<=t[o]&&t[o]<="f")e=e*r+(10+t.charCodeAt(o)-ah)>>>0;else if("A"<=t[o]&&t[o]<="F")e=e*r+(10+t.charCodeAt(o)-ch)>>>0;else break;else break;if(e>4294967295)throw new Error("too large");o++}if(o===s)throw new Error("empty octet");return[e,o]}function gr(t){let e=[];for(let r=0;r<=3&&t.length!==0;r++){if(r>0){if(t[0]!==".")throw new Error("Invalid IP");t=t.substring(1)}let[n,o]=uh(t);t=t.substring(o),e.push(n)}if(t.length!==0)throw new Error("Invalid IP");switch(e.length){case 1:if(e[0]>4294967295)throw new Error("Invalid IP");return e[0]>>>0;case 2:if(e[0]>255||e[1]>16777215)throw new Error("Invalid IP");return(e[0]<<24|e[1])>>>0;case 3:if(e[0]>255||e[1]>255||e[2]>65535)throw new Error("Invalid IP");return(e[0]<<24|e[1]<<16|e[2])>>>0;case 4:if(e[0]>255||e[1]>255||e[2]>255||e[3]>255)throw new Error("Invalid IP");return(e[0]<<24|e[1]<<16|e[2]<<8|e[3])>>>0;default:throw new Error("Invalid IP")}}var Ri=class t{constructor(e,r){if(typeof e!="string")throw new Error("Missing `net' parameter");let n=r;if(!n){let o=e.split("/",2);e=o[0],n=o[1]}if(n||(n=32),typeof n=="string"&&n.indexOf(".")>-1){try{this.maskLong=gr(n)}catch{throw new Error("Invalid mask: "+n)}this.bitmask=NaN;for(let o=32;o>=0;o--)if(this.maskLong===4294967295<<32-o>>>0){this.bitmask=o;break}}else if(n||n===0)this.bitmask=parseInt(n,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(gr(e)&this.maskLong)>>>0}catch{throw new Error("Invalid net address: "+e)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+n);this.size=Math.pow(2,32-this.bitmask),this.base=Xe(this.netLong),this.mask=Xe(this.maskLong),this.hostmask=Xe(~this.maskLong),this.first=this.bitmask<=30?Xe(this.netLong+1):this.base,this.last=this.bitmask<=30?Xe(this.netLong+this.size-2):Xe(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?Xe(this.netLong+this.size-1):void 0}contains(e){return typeof e=="string"&&(e.indexOf("/")>0||e.split(".").length!==4)&&(e=new t(e)),e instanceof t?this.contains(e.base)&&this.contains(e.broadcast||e.last):(gr(e)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(e=1){return new t(Xe(this.netLong+this.size*e),this.mask)}forEach(e){let r=gr(this.first),n=gr(this.last),o=0;for(;r<=n;)e(Xe(r),r,o),o++,r++}toString(){return this.base+"/"+this.bitmask}};xr.Netmask4Impl=Ri});var Iu=vo(wr=>{"use strict";Object.defineProperty(wr,"__esModule",{value:!0});wr.Netmask6Impl=void 0;wr.ip6bigint=ki;wr.bigint2ip6=Mt;var fh=Fi(),Ni=(1n<<128n)-1n;function ki(t){let e=t.indexOf("%");e!==-1&&(t=t.substring(0,e));let r=t.lastIndexOf(":");if(r!==-1&&t.indexOf(".",r)!==-1){let n=t.substring(r+1),o=(0,fh.ip2long)(n),s=t.substring(0,r+1)+"0:0";return Su(s)&~0xffffffffn|BigInt(o)}return Su(t)}function Su(t){let e=t.indexOf("::"),r;if(e!==-1){let o=t.substring(0,e),s=t.substring(e+2),i=o===""?[]:o.split(":"),a=s===""?[]:s.split(":"),c=8-i.length-a.length;if(c<0)throw new Error("Invalid IPv6: too many groups");r=[...i,...Array(c).fill("0"),...a]}else r=t.split(":");if(r.length!==8)throw new Error("Invalid IPv6: expected 8 groups, got "+r.length);let n=0n;for(let o=0;o<8;o++){let s=r[o];if(s.length===0||s.length>4)throw new Error('Invalid IPv6: bad group "'+s+'"');let i=parseInt(s,16);if(isNaN(i)||i<0||i>65535)throw new Error('Invalid IPv6: bad group "'+s+'"');n=n<<16n|BigInt(i)}return n}function Mt(t){if(t<0n||t>Ni)throw new Error("Invalid IPv6 address value");let e=[];for(let i=0;i<8;i++)e.unshift(Number(t&0xffffn)),t>>=16n;let r=-1,n=0,o=-1,s=0;for(let i=0;i<8;i++)e[i]===0?o===-1?(o=i,s=1):s++:(s>n&&s>=2&&(r=o,n=s),o=-1,s=0);if(s>n&&s>=2&&(r=o,n=s),r!==-1&&r+n===8&&r>0)return e.slice(0,r).map(a=>a.toString(16)).join(":")+"::";if(r===0)return"::"+e.slice(n).map(a=>a.toString(16)).join(":");if(r>0){let i=e.slice(0,r).map(c=>c.toString(16)),a=e.slice(r+n).map(c=>c.toString(16));return i.join(":")+"::"+a.join(":")}else return e.map(i=>i.toString(16)).join(":")}var Ui=class t{constructor(e,r){if(typeof e!="string")throw new Error("Missing `net' parameter");let n=r;if(n==null){let o=e.indexOf("/");o!==-1?(n=parseInt(e.substring(o+1),10),e=e.substring(0,o)):n=128}if(isNaN(n)||n<0||n>128)throw new Error("Invalid mask for IPv6: "+n);this.bitmask=n,this.bitmask===0?this.maskBigint=0n:this.maskBigint=Ni>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=ki(e)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+e)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=Mt(this.netBigint),this.mask=Mt(this.maskBigint),this.hostmask=Mt(~this.maskBigint&Ni),this.first=this.base,this.last=Mt(this.netBigint+(1n<<BigInt(128-this.bitmask))-1n),this.broadcast=void 0}contains(e){return typeof e=="string"&&e.indexOf("/")>0&&(e=new t(e)),e instanceof t?this.contains(e.base)&&this.contains(e.last):(ki(e)&this.maskBigint)===this.netBigint}next(e=1){let r=1n<<BigInt(128-this.bitmask);return new t(Mt(this.netBigint+r*BigInt(e)),this.bitmask)}forEach(e){let r=this.netBigint,n=1n<<BigInt(128-this.bitmask),o=this.netBigint+n-1n,s=0;for(;r<=o;)e(Mt(r),Number(r),s),s++,r++}toString(){return this.base+"/"+this.bitmask}};wr.Netmask6Impl=Ui});var Au=vo(vt=>{"use strict";Object.defineProperty(vt,"__esModule",{value:!0});vt.long2ip=vt.ip2long=vt.Netmask=void 0;var co=Fi();Object.defineProperty(vt,"ip2long",{enumerable:!0,get:function(){return co.ip2long}});Object.defineProperty(vt,"long2ip",{enumerable:!0,get:function(){return co.long2ip}});var lh=Iu(),Ki=class t{constructor(e,r){if(typeof e!="string")throw new Error("Missing `net' parameter");(e.indexOf("/")!==-1?e.substring(0,e.indexOf("/")):e).indexOf(":")!==-1?this._impl=new lh.Netmask6Impl(e,r):this._impl=new co.Netmask4Impl(e,r),this.base=this._impl.base,this.mask=this._impl.mask,this.hostmask=this._impl.hostmask,this.bitmask=this._impl.bitmask,this.size=this._impl.size,this.first=this._impl.first,this.last=this._impl.last,this.broadcast=this._impl.broadcast,this._impl instanceof co.Netmask4Impl?(this.maskLong=this._impl.maskLong,this.netLong=this._impl.netLong):(this.maskLong=0,this.netLong=0)}contains(e){return typeof e=="string"&&(e.indexOf("/")>0?e=new t(e):e.indexOf(":")===-1&&e.split(".").length!==4&&(e=new t(e))),e instanceof t?this.contains(e.base)&&this.contains(e.broadcast||e.last):this._impl.contains(e)}next(e=1){let r=this._impl.next(e);return new t(r.base,r.bitmask)}forEach(e){this._impl.forEach(e)}toString(){return this._impl.toString()}};vt.Netmask=Ki});var $h={};ve($h,{identify:()=>Hh,identifyPush:()=>zh});var Q=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Ht=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var pn=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},mn=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var De=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var It=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var So=Symbol.for("@libp2p/peer-id");var yn=Symbol.for("@libp2p/service-capabilities");var To={};ve(To,{base58btc:()=>ne,base58flickr:()=>cf});var wp=new Uint8Array(0);function na(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Qe(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function oa(t){return new TextEncoder().encode(t)}function sa(t){return new TextDecoder().decode(t)}function tf(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var s=t.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);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,y=0,E=0,S=m.length;E!==S&&m[E]===0;)E++,g++;for(var A=(S-E)*f+1>>>0,O=new Uint8Array(A);E!==S;){for(var B=m[E],F=0,P=A-1;(B!==0||F<y)&&P!==-1;P--,F++)B+=256*O[P]>>>0,O[P]=B%a>>>0,B=B/a>>>0;if(B!==0)throw new Error("Non-zero carry");y=F,E++}for(var C=A-y;C!==A&&O[C]===0;)C++;for(var N=c.repeat(g);C<A;++C)N+=t.charAt(O[C]);return N}function h(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 y=0,E=0;m[g]===c;)y++,g++;for(var S=(m.length-g)*u+1>>>0,A=new Uint8Array(S);m[g];){var O=r[m.charCodeAt(g)];if(O===255)return;for(var B=0,F=S-1;(O!==0||B<E)&&F!==-1;F--,B++)O+=a*A[F]>>>0,A[F]=O%256>>>0,O=O/256>>>0;if(O!==0)throw new Error("Non-zero carry");E=B,g++}if(m[g]!==" "){for(var P=S-E;P!==S&&A[P]===0;)P++;for(var C=new Uint8Array(y+(S-P)),N=y;P!==S;)C[N++]=A[P++];return C}}}function d(m){var g=h(m);if(g)return g;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:h,decode:d}}var rf=tf,nf=rf,aa=nf;var Io=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Ao=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return ca(this,e)}},_o=class{decoders;constructor(e){this.decoders=e}or(e){return ca(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function ca(t,e){return new _o({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Co=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Io(e,r,n),this.decoder=new Ao(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function zt({name:t,prefix:e,encode:r,decode:n}){return new Co(t,e,r,n)}function ut({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=aa(r,t);return zt({prefix:e,name:t,encode:n,decode:s=>Qe(o(s))})}function of(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function sf(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function af(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function ee({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=af(n);return zt({prefix:e,name:t,encode(s){return sf(s,n,r)},decode(s){return of(s,o,r,t)}})}var ne=ut({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),cf=ut({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Bo={};ve(Bo,{base32:()=>ft,base32hex:()=>df,base32hexpad:()=>pf,base32hexpadupper:()=>mf,base32hexupper:()=>hf,base32pad:()=>ff,base32padupper:()=>lf,base32upper:()=>uf,base32z:()=>yf});var ft=ee({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),uf=ee({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),ff=ee({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),lf=ee({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),df=ee({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),hf=ee({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),pf=ee({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),mf=ee({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),yf=ee({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Do={};ve(Do,{base36:()=>_r,base36upper:()=>bf});var _r=ut({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),bf=ut({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var gf=la,ua=128,xf=127,wf=~xf,Ef=Math.pow(2,31);function la(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Ef;)e[r++]=t&255|ua,t/=128;for(;t&wf;)e[r++]=t&255|ua,t>>>=7;return e[r]=t|0,la.bytes=r-n+1,e}var vf=Oo,Sf=128,fa=127;function Oo(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw Oo.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&fa)<<o:(i&fa)*Math.pow(2,o),o+=7}while(i>=Sf);return Oo.bytes=s-n,r}var If=Math.pow(2,7),Af=Math.pow(2,14),_f=Math.pow(2,21),Cf=Math.pow(2,28),Tf=Math.pow(2,35),Bf=Math.pow(2,42),Df=Math.pow(2,49),Of=Math.pow(2,56),Pf=Math.pow(2,63),Lf=function(t){return t<If?1:t<Af?2:t<_f?3:t<Cf?4:t<Tf?5:t<Bf?6:t<Df?7:t<Of?8:t<Pf?9:10},Rf={encode:gf,decode:vf,encodingLength:Lf},Ff=Rf,Cr=Ff;function Tr(t,e=0){return[Cr.decode(t,e),Cr.decode.bytes]}function $t(t,e,r=0){return Cr.encode(t,e,r),e}function jt(t){return Cr.encodingLength(t)}function He(t,e){let r=e.byteLength,n=jt(t),o=n+jt(r),s=new Uint8Array(o+r);return $t(t,s,0),$t(r,s,n),s.set(e,o),new Yt(t,r,e,s)}function Br(t){let e=Qe(t),[r,n]=Tr(e),[o,s]=Tr(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Yt(r,o,i,e)}function da(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&na(t.bytes,r.bytes)}}var Yt=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};function ha(t,e){let{bytes:r,version:n}=t;return n===0?kf(r,Po(t),e??ne.encoder):Uf(r,Po(t),e??ft.encoder)}var pa=new WeakMap;function Po(t){let e=pa.get(t);if(e==null){let r=new Map;return pa.set(t,r),r}return e}var fe=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==Dr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Kf)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=He(e,r);return t.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&da(e.multihash,n.multihash)}toString(e){return ha(this,e)}toJSON(){return{"/":ha(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new t(n,o,s,i??ma(n,o,s.bytes))}else if(r[Mf]===!0){let{version:n,multihash:o,code:s}=r,i=Br(o);return t.create(n,s,i)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==Dr)throw new Error(`Version 0 CID must use dag-pb (code: ${Dr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=ma(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Dr,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=Qe(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Yt(r.multihashCode,r.digestSize,s,o);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[l,h]=Tr(e.subarray(r));return r+=h,l},o=n(),s=Dr;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,f=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,o]=Nf(e,r),s=t.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Po(s).set(n,e),s}};function Nf(t,e){switch(t[0]){case"Q":{let r=e??ne;return[ne.prefix,r.decode(`${ne.prefix}${t}`)]}case ne.prefix:{let r=e??ne;return[ne.prefix,r.decode(t)]}case ft.prefix:{let r=e??ft;return[ft.prefix,r.decode(t)]}case _r.prefix:{let r=e??_r;return[_r.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function kf(t,e,r){let{prefix:n}=r;if(n!==ne.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o}function Uf(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let s=r.encode(t);return e.set(n,s),s}else return o}var Dr=112,Kf=18;function ma(t,e,r){let n=jt(t),o=n+jt(e),s=new Uint8Array(o+r.byteLength);return $t(t,s,0),$t(e,s,n),s.set(r,o),s}var Mf=Symbol.for("@ipld/js-cid/CID");var Lo={};ve(Lo,{identity:()=>Oe});var ya=0,Vf="identity",ba=Qe;function qf(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return He(ya,ba(t))}var Oe={code:ya,name:Vf,encode:ba,digest:qf};function le(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}async function ga(t,e,r,n){let o=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,e,r.subarray());return n?.signal?.throwIfAborted(),s}function pe(t=0){return new Uint8Array(t)}function Se(t=0){return new Uint8Array(t)}function Je(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=Se(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}var wa=Symbol.for("@achingbrain/uint8arraylist");function xa(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let o=r+n.byteLength;if(e<o)return{buf:n,index:e-r};r=o}throw new RangeError("index is out of bounds")}function gn(t){return!!t?.[wa]}var se=class t{bufs;length;[wa]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let r=0;for(let n of e)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(gn(n)){r+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(gn(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(e){let r=xa(this.bufs,e);return r.buf[r.index]}set(e,r){let n=xa(this.bufs,e);n.buf[n.index]=r}write(e,r=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(r+n,e[n]);else if(gn(e))for(let n=0;n<e.length;n++)this.set(r+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,r){let{bufs:n,length:o}=this._subList(e,r);return Je(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:Je(n,o)}sublist(e,r){let{bufs:n,length:o}=this._subList(e,r),s=new t;return s.length=o,s.bufs=n,s}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,e>=c)continue;let u=e>=a&&e<c,f=r>a&&r<=c;if(u&&f){if(e===a&&r===c){n.push(i);break}let l=e-a;n.push(i.subarray(l,l+(r-e)));break}if(u){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!gn(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let h=u;h>=0;h--){let d=this.get(l+h);if(n[h]!==d){f=Math.max(1,h-a[d]);break}}if(f===0)return l}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=Se(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let o=pe(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let o=pe(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let o=pe(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=Se(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let o=pe(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let o=pe(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let o=pe(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let o=pe(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let o=pe(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!le(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var Ro={};ve(Ro,{base10:()=>Hf});var Hf=ut({prefix:"9",name:"base10",alphabet:"0123456789"});var Fo={};ve(Fo,{base16:()=>zf,base16upper:()=>$f});var zf=ee({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),$f=ee({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var No={};ve(No,{base2:()=>jf});var jf=ee({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ko={};ve(ko,{base256emoji:()=>Xf});var Ea=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}"),Yf=Ea.reduce((t,e,r)=>(t[r]=e,t),[]),Zf=Ea.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Gf(t){return t.reduce((e,r)=>(e+=Yf[r],e),"")}function Wf(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Zf[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Xf=zt({prefix:"\u{1F680}",name:"base256emoji",encode:Gf,decode:Wf});var Ko={};ve(Ko,{base64:()=>Qf,base64pad:()=>Jf,base64url:()=>Uo,base64urlpad:()=>el});var Qf=ee({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Jf=ee({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Uo=ee({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),el=ee({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Mo={};ve(Mo,{base8:()=>tl});var tl=ee({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Vo={};ve(Vo,{identity:()=>rl});var rl=zt({prefix:"\0",name:"identity",encode:t=>sa(t),decode:t=>oa(t)});var o0=new TextEncoder,s0=new TextDecoder;var zo={};ve(zo,{sha256:()=>Or,sha512:()=>il});var sl=20;function Ho({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new qo(t,e,r,n,o)}var qo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??sl,this.maxDigestLength=s}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?va(n,this.code,r?.truncate):n.then(o=>va(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function va(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return He(e,t)}function Ia(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Or=Ho({name:"sha2-256",code:18,encode:Ia("SHA-256")}),il=Ho({name:"sha2-512",code:19,encode:Ia("SHA-512")});var Pr={...Vo,...No,...Mo,...Ro,...Fo,...Bo,...Do,...To,...Ko,...ko},b0={...zo,...Lo};function _a(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Aa=_a("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),$o=_a("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=Se(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),al={utf8:Aa,"utf-8":Aa,hex:Pr.base16,latin1:$o,ascii:$o,binary:$o,...Pr},xn=al;function K(t,e="utf8"){let r=xn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function q(t,e="utf8"){let r=xn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var cl=parseInt("11111",2),jo=parseInt("10000000",2),ul=parseInt("01111111",2),Ca={0:Lr,1:Lr,2:fl,3:hl,4:pl,5:dl,6:ll,16:Lr,22:Lr,48:Lr};function et(t,e={offset:0}){let r=t[e.offset]&cl;if(e.offset++,Ca[r]!=null)return Ca[r](t,e);throw new Error("No decoder for tag "+r)}function Rr(t,e){let r=0;if((t[e.offset]&jo)===jo){let n=t[e.offset]&ul,o="0x";e.offset++;for(let s=0;s<n;s++,e.offset++)o+=t[e.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=t[e.offset],e.offset++;return r}function Lr(t,e){Rr(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=et(t,e);if(n===null)break;r.push(n)}return r}function fl(t,e){let r=Rr(t,e),n=e.offset,o=e.offset+r,s=[];for(let i=n;i<o;i++)i===n&&t[i]===0||s.push(t[i]);return e.offset+=r,Uint8Array.from(s)}function ll(t,e){let r=Rr(t,e),n=e.offset+r,o=t[e.offset];e.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;e.offset<n;){let u=t[e.offset];if(e.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function dl(t,e){return e.offset++,null}function hl(t,e){let r=Rr(t,e),n=t[e.offset];e.offset++;let o=t.subarray(e.offset,e.offset+r-1);if(e.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function pl(t,e){let r=Rr(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function ml(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new se;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function Yo(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=ml(t.byteLength);return new se(Uint8Array.from([e.byteLength|jo]),e)}function Ie(t){let e=new se,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new se(Uint8Array.from([2]),Yo(e),e)}function wn(t){let e=Uint8Array.from([0]),r=new se(e,t);return new se(Uint8Array.from([3]),Yo(r),r)}function lt(t,e=48){let r=new se;for(let n of t)r.append(n);return new se(Uint8Array.from([e]),Yo(r),r)}var yl=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),bl=Uint8Array.from([6,5,43,129,4,0,34]),gl=Uint8Array.from([6,5,43,129,4,0,35]),xl={ext:!0,kty:"EC",crv:"P-256"},wl={ext:!0,kty:"EC",crv:"P-384"},El={ext:!0,kty:"EC",crv:"P-521"},Zo=32,Go=48,Wo=66;function Xo(t){let e=et(t);return Ta(e)}function Ta(t){let e=t[1][1][0],r=1,n,o;if(e.byteLength===Zo*2+1)return n=q(e.subarray(r,r+Zo),"base64url"),o=q(e.subarray(r+Zo),"base64url"),new Zt({...xl,key_ops:["verify"],x:n,y:o});if(e.byteLength===Go*2+1)return n=q(e.subarray(r,r+Go),"base64url"),o=q(e.subarray(r+Go),"base64url"),new Zt({...wl,key_ops:["verify"],x:n,y:o});if(e.byteLength===Wo*2+1)return n=q(e.subarray(r,r+Wo),"base64url"),o=q(e.subarray(r+Wo),"base64url"),new Zt({...El,key_ops:["verify"],x:n,y:o});throw new Q(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Ba(t){return lt([Ie(Uint8Array.from([1])),lt([vl(t.crv)],160),lt([wn(new se(Uint8Array.from([4]),K(t.x??"","base64url"),K(t.y??"","base64url")))],161)]).subarray()}function vl(t){if(t==="P-256")return yl;if(t==="P-384")return bl;if(t==="P-521")return gl;throw new Q(`Invalid curve ${t}`)}var Zt=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=Ba(this.jwk)),this._raw}toMultihash(){return Oe.digest(ze(this))}toCID(){return fe.createV1(114,this.toMultihash())}toString(){return ne.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:le(this.raw,e.raw)}async verify(e,r,n){return ga(this.jwk,r,e,n)}};function Qo(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}function dt(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(`${r}expected number, got ${typeof t}`)}if(!Number.isSafeInteger(t)||t<0){let r=e&&`"${e}" `;throw new RangeError(`${r}expected integer >= 0, got ${t}`)}}function Ce(t,e,r=""){let n=Qo(t),o=t?.length,s=e!==void 0;if(!n||s&&o!==e){let i=r&&`"${r}" `,a=s?` of length ${e}`:"",c=n?`length=${o}`:`type=${typeof t}`,u=i+"expected Uint8Array"+a+", got "+c;throw n?new RangeError(u):new TypeError(u)}return t}function En(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(dt(t.outputLen),dt(t.blockLen),t.outputLen<1)throw new Error('"outputLen" must be >= 1');if(t.blockLen<1)throw new Error('"blockLen" must be >= 1')}function Gt(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function vn(t,e){Ce(t,void 0,"digestInto() output");let r=e.outputLen;if(t.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function rt(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Sn(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Pe(t,e){return t<<32-e|t>>>e}var Oa=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Sl=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function In(t){if(Ce(t),Oa)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=Sl[t[r]];return e}var tt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Da(t){if(t>=tt._0&&t<=tt._9)return t-tt._0;if(t>=tt.A&&t<=tt.F)return t-(tt.A-10);if(t>=tt.a&&t<=tt.f)return t-(tt.a-10)}function Fr(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(Oa)try{return Uint8Array.fromHex(t)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let e=t.length,r=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=Da(t.charCodeAt(s)),a=Da(t.charCodeAt(s+1));if(i===void 0||a===void 0){let c=t[s]+t[s+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Jo(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];Ce(o),e+=o.length}let r=new Uint8Array(e);for(let n=0,o=0;n<t.length;n++){let s=t[n];r.set(s,o),o+=s.length}return r}function es(t,e={}){let r=(o,s)=>t(s).update(o).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>t(o),Object.assign(r,e),Object.freeze(r)}function Pa(t=32){dt(t,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(t>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);return e.getRandomValues(new Uint8Array(t))}var ts=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function La(t,e,r){return t&e^~t&r}function Ra(t,e,r){return t&e^t&r^e&r}var Nr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,o){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=Sn(this.buffer)}update(e){Gt(this),Ce(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=Sn(e);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Gt(this),vn(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,rt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=Sn(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],s)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return e.destroyed=i,e.finished=s,e.length=o,e.pos=a,o%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},nt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var me=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var An=BigInt(4294967295),Fa=BigInt(32);function Il(t,e=!1){return e?{h:Number(t&An),l:Number(t>>Fa&An)}:{h:Number(t>>Fa&An)|0,l:Number(t&An)|0}}function Na(t,e=!1){let r=t.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=Il(t[s],e);[n[s],o[s]]=[i,a]}return[n,o]}var rs=(t,e,r)=>t>>>r,ns=(t,e,r)=>t<<32-r|e>>>r,_t=(t,e,r)=>t>>>r|e<<32-r,Ct=(t,e,r)=>t<<32-r|e>>>r,kr=(t,e,r)=>t<<64-r|e>>>r-32,Ur=(t,e,r)=>t>>>r-32|e<<64-r;function $e(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var ka=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Ua=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,Ka=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),Ma=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,Va=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),qa=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0;var _l=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),ht=new Uint32Array(64),os=class extends Nr{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[e,r,n,o,s,i,a,c]}set(e,r,n,o,s,i,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(e,r){for(let l=0;l<16;l++,r+=4)ht[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let h=ht[l-15],d=ht[l-2],m=Pe(h,7)^Pe(h,18)^h>>>3,g=Pe(d,17)^Pe(d,19)^d>>>10;ht[l]=g+ht[l-7]+m+ht[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let h=Pe(a,6)^Pe(a,11)^Pe(a,25),d=f+h+La(a,c,u)+_l[l]+ht[l]|0,g=(Pe(n,2)^Pe(n,13)^Pe(n,22))+Ra(n,o,s)|0;f=u,u=c,c=a,a=i+d|0,i=s,s=o,o=n,n=d+g|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,o,s,i,a,c,u,f)}roundClean(){rt(ht)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),rt(this.buffer)}},ss=class extends os{A=nt[0]|0;B=nt[1]|0;C=nt[2]|0;D=nt[3]|0;E=nt[4]|0;F=nt[5]|0;G=nt[6]|0;H=nt[7]|0;constructor(){super(32)}};var Ha=Na(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),Cl=Ha[0],Tl=Ha[1],pt=new Uint32Array(80),mt=new Uint32Array(80),is=class extends Nr{constructor(e){super(128,e,16,!1)}get(){let{Ah:e,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:h,Gh:d,Gl:m,Hh:g,Hl:y}=this;return[e,r,n,o,s,i,a,c,u,f,l,h,d,m,g,y]}set(e,r,n,o,s,i,a,c,u,f,l,h,d,m,g,y){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=h|0,this.Gh=d|0,this.Gl=m|0,this.Hh=g|0,this.Hl=y|0}process(e,r){for(let A=0;A<16;A++,r+=4)pt[A]=e.getUint32(r),mt[A]=e.getUint32(r+=4);for(let A=16;A<80;A++){let O=pt[A-15]|0,B=mt[A-15]|0,F=_t(O,B,1)^_t(O,B,8)^rs(O,B,7),P=Ct(O,B,1)^Ct(O,B,8)^ns(O,B,7),C=pt[A-2]|0,N=mt[A-2]|0,Z=_t(C,N,19)^kr(C,N,61)^rs(C,N,6),k=Ct(C,N,19)^Ur(C,N,61)^ns(C,N,6),p=Ka(P,k,mt[A-7],mt[A-16]),b=Ma(p,F,Z,pt[A-7],pt[A-16]);pt[A]=b|0,mt[A]=p|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:h,Fh:d,Fl:m,Gh:g,Gl:y,Hh:E,Hl:S}=this;for(let A=0;A<80;A++){let O=_t(l,h,14)^_t(l,h,18)^kr(l,h,41),B=Ct(l,h,14)^Ct(l,h,18)^Ur(l,h,41),F=l&d^~l&g,P=h&m^~h&y,C=Va(S,B,P,Tl[A],mt[A]),N=qa(C,E,O,F,Cl[A],pt[A]),Z=C|0,k=_t(n,o,28)^kr(n,o,34)^kr(n,o,39),p=Ct(n,o,28)^Ur(n,o,34)^Ur(n,o,39),b=n&s^n&a^s&a,v=o&i^o&c^i&c;E=g|0,S=y|0,g=d|0,y=m|0,d=l|0,m=h|0,{h:l,l:h}=$e(u|0,f|0,N|0,Z|0),u=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let w=ka(Z,p,v);n=Ua(w,N,k,b),o=w|0}({h:n,l:o}=$e(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=$e(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=$e(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=$e(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:h}=$e(this.Eh|0,this.El|0,l|0,h|0),{h:d,l:m}=$e(this.Fh|0,this.Fl|0,d|0,m|0),{h:g,l:y}=$e(this.Gh|0,this.Gl|0,g|0,y|0),{h:E,l:S}=$e(this.Hh|0,this.Hl|0,E|0,S|0),this.set(n,o,s,i,a,c,u,f,l,h,d,m,g,y,E,S)}roundClean(){rt(pt,mt)}destroy(){this.destroyed=!0,rt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},as=class extends is{Ah=me[0]|0;Al=me[1]|0;Bh=me[2]|0;Bl=me[3]|0;Ch=me[4]|0;Cl=me[5]|0;Dh=me[6]|0;Dl=me[7]|0;Eh=me[8]|0;El=me[9]|0;Fh=me[10]|0;Fl=me[11]|0;Gh=me[12]|0;Gl=me[13]|0;Hh=me[14]|0;Hl=me[15]|0;constructor(){super(64)}};var Wt=es(()=>new ss,ts(1));var _n=es(()=>new as,ts(3));var H=(t,e,r)=>Ce(t,e,r),us=dt,Xt=In,ae=(...t)=>Jo(...t),Qt=t=>Fr(t),Tt=Qo,Kr=t=>Pa(t),Tn=BigInt(0),cs=BigInt(1);function Le(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}" `;throw new TypeError(r+"expected boolean, got type="+typeof t)}return t}function Bn(t){if(typeof t=="bigint"){if(!Cn(t))throw new RangeError("positive bigint expected, got "+t)}else us(t);return t}function Re(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(r+"expected number, got type="+typeof t)}if(!Number.isSafeInteger(t)){let r=e&&`"${e}" `;throw new RangeError(r+"expected safe integer, got "+t)}}function Mr(t){let e=Bn(t).toString(16);return e.length&1?"0"+e:e}function za(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?Tn:BigInt("0x"+t)}function Bt(t){return za(In(t))}function je(t){return za(In(Vr(Ce(t)).reverse()))}function Dn(t,e){if(dt(e),e===0)throw new RangeError("zero length");t=Bn(t);let r=t.toString(16);if(r.length>e*2)throw new RangeError("number too large");return Fr(r.padStart(e*2,"0"))}function fs(t,e){return Dn(t,e).reverse()}function $a(t,e){if(t=H(t),e=H(e),t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function Vr(t){return Uint8Array.from(H(t))}function On(t){if(typeof t!="string")throw new TypeError("ascii string expected, got "+typeof t);return Uint8Array.from(t,(e,r)=>{let n=e.charCodeAt(0);if(e.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${t[r]}" with code ${n} at position ${r}`);return n})}var Cn=t=>typeof t=="bigint"&&Tn<=t;function Bl(t,e,r){return Cn(t)&&Cn(e)&&Cn(r)&&e<=t&&t<r}function Jt(t,e,r,n){if(!Bl(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function er(t){if(t<Tn)throw new Error("expected non-negative bigint, got "+t);let e;for(e=0;t>Tn;t>>=cs,e+=1);return e}var qr=t=>(cs<<BigInt(t))-cs;function ja(t,e,r){if(dt(t,"hashLen"),dt(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=y=>new Uint8Array(y),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(t),u=n(t),f=0,l=()=>{c.fill(1),u.fill(0),f=0},h=(...y)=>r(u,ae(c,...y)),d=(y=o)=>{u=h(s,y),c=h(),y.length!==0&&(u=h(i,y),c=h())},m=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let y=0,E=[];for(;y<e;){c=h();let S=c.slice();E.push(S),y+=c.length}return ae(...E)};return(y,E)=>{l(),d(y);let S;for(;(S=E(m()))===void 0;)d();return l(),S}}function Fe(t,e={},r={}){if(Object.prototype.toString.call(t)!=="[object Object]")throw new TypeError("expected valid options object");function n(s,i,a){if(!a&&i!=="function"&&!Object.hasOwn(t,s))throw new TypeError(`param "${s}" is invalid: expected own property`);let c=t[s];if(a&&c===void 0)return;let u=typeof c;if(u!==i||c===null)throw new TypeError(`param "${s}" is invalid: expected ${i}, got ${u}`)}let o=(s,i)=>Object.entries(s).forEach(([a,c])=>n(a,c,i));o(e,!1),o(r,!0)}var ls=()=>{throw new Error("not implemented")};var ye=BigInt(0),te=BigInt(1),Dt=BigInt(2),Wa=BigInt(3),Xa=BigInt(4),Qa=BigInt(5),Dl=BigInt(7),Ja=BigInt(8),Ol=BigInt(9),ec=BigInt(16);function oe(t,e){if(e<=ye)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=ye?r:e+r}function X(t,e,r){if(e<ye)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >ye;)n*=n,n%=r;return n}function Ya(t,e){if(t===ye)throw new Error("invert: expected non-zero number");if(e<=ye)throw new Error("invert: expected positive modulus, got "+e);let r=oe(t,e),n=e,o=ye,s=te,i=te,a=ye;for(;r!==ye;){let u=n/r,f=n-r*u,l=o-i*u,h=s-a*u;n=r,r=f,o=i,s=a,i=l,a=h}if(n!==te)throw new Error("invert: does not exist");return oe(o,e)}function ds(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function tc(t,e){let r=t,n=(r.ORDER+te)/Xa,o=r.pow(e,n);return ds(r,o,e),o}function Pl(t,e){let r=t,n=(r.ORDER-Qa)/Ja,o=r.mul(e,Dt),s=r.pow(o,n),i=r.mul(e,s),a=r.mul(r.mul(i,Dt),s),c=r.mul(i,r.sub(a,r.ONE));return ds(r,c,e),c}function Ll(t){let e=tr(t),r=rc(t),n=r(e,e.neg(e.ONE)),o=r(e,n),s=r(e,e.neg(n)),i=(t+Dl)/ec;return((a,c)=>{let u=a,f=u.pow(c,i),l=u.mul(f,n),h=u.mul(f,o),d=u.mul(f,s),m=u.eql(u.sqr(l),c),g=u.eql(u.sqr(h),c);f=u.cmov(f,l,m),l=u.cmov(d,h,g);let y=u.eql(u.sqr(l),c),E=u.cmov(f,l,y);return ds(u,E,c),E})}function rc(t){if(t<Wa)throw new Error("sqrt is not defined for small field");let e=t-te,r=0;for(;e%Dt===ye;)e/=Dt,r++;let n=Dt,o=tr(t);for(;Za(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return tc;let s=o.pow(n,e),i=(e+te)/Dt;return function(c,u){let f=c;if(f.is0(u))return u;if(Za(f,u)!==1)throw new Error("Cannot find square root");let l=r,h=f.mul(f.ONE,s),d=f.pow(u,e),m=f.pow(u,i);for(;!f.eql(d,f.ONE);){if(f.is0(d))return f.ZERO;let g=1,y=f.sqr(d);for(;!f.eql(y,f.ONE);)if(g++,y=f.sqr(y),g===l)throw new Error("Cannot find square root");let E=te<<BigInt(l-g-1),S=f.pow(h,E);l=g,h=f.sqr(S),d=f.mul(d,h),m=f.mul(m,S)}return m}}function Rl(t){return t%Xa===Wa?tc:t%Ja===Qa?Pl:t%ec===Ol?Ll(t):rc(t)}var ot=(t,e)=>(oe(t,e)&te)===te,Fl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function hs(t){let e={ORDER:"bigint",BYTES:"number",BITS:"number"},r=Fl.reduce((n,o)=>(n[o]="function",n),e);if(Fe(t,r),Re(t.BYTES,"BYTES"),Re(t.BITS,"BITS"),t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=te)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function Nl(t,e,r){let n=t;if(r<ye)throw new Error("invalid exponent, negatives unsupported");if(r===ye)return n.ONE;if(r===te)return e;let o=n.ONE,s=e;for(;r>ye;)r&te&&(o=n.mul(o,s)),s=n.sqr(s),r>>=te;return o}function Hr(t,e,r=!1){let n=t,o=new Array(e.length).fill(r?n.ZERO:void 0),s=e.reduce((a,c,u)=>n.is0(c)?a:(o[u]=a,n.mul(a,c)),n.ONE),i=n.inv(s);return e.reduceRight((a,c,u)=>n.is0(c)?a:(o[u]=n.mul(a,o[u]),n.mul(a,c)),i),o}function Za(t,e){let r=t,n=(r.ORDER-te)/Dt,o=r.pow(e,n),s=r.eql(o,r.ONE),i=r.eql(o,r.ZERO),a=r.eql(o,r.neg(r.ONE));if(!s&&!i&&!a)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function kl(t,e){if(e!==void 0&&us(e),t<=ye)throw new Error("invalid n length: expected positive n, got "+t);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let r=er(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected bit length (${r}) >= n.length (${e})`);let n=e!==void 0?e:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var Ga=new WeakMap,Pn=class{ORDER;BITS;BYTES;isLE;ZERO=ye;ONE=te;_lengths;_mod;constructor(e,r={}){if(e<=te)throw new Error("invalid field: expected ORDER > 1, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=kl(e,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(e){return oe(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return ye<=e&&e<this.ORDER}is0(e){return e===ye}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&te)===te}neg(e){return oe(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return oe(e*e,this.ORDER)}add(e,r){return oe(e+r,this.ORDER)}sub(e,r){return oe(e-r,this.ORDER)}mul(e,r){return oe(e*r,this.ORDER)}pow(e,r){return Nl(this,e,r)}div(e,r){return oe(e*Ya(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return Ya(e,this.ORDER)}sqrt(e){let r=Ga.get(this);return r||Ga.set(this,r=Rl(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?fs(e,this.BYTES):Dn(e,this.BYTES)}fromBytes(e,r=!1){H(e);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let u=new Uint8Array(o);u.set(e,s?0:u.length-e.length),e=u}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let c=s?je(e):Bt(e);if(a&&(c=oe(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return Hr(this,e)}cmov(e,r,n){return Le(n,"condition"),n?r:e}};Object.freeze(Pn.prototype);function tr(t,e={}){return new Pn(t,e)}function nc(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=te)throw new Error("field order must be greater than 1");let e=er(t-te);return Math.ceil(e/8)}function ps(t){let e=nc(t);return e+Math.ceil(e/2)}function ms(t,e,r=!1){H(t);let n=t.length,o=nc(e),s=Math.max(ps(e),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?je(t):Bt(t),a=oe(i,e-te)+te;return r?fs(a,o):Dn(a,o)}var rr=BigInt(0),Ot=BigInt(1);function zr(t,e){let r=e.negate();return t?r:e}function Pt(t,e){let r=Hr(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function ac(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function ys(t,e){ac(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),o=2**t,s=qr(t),i=BigInt(t);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function oc(t,e,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(t&o),c=t>>i;a>n&&(a-=s,c+=Ot);let u=e*n,f=u+Math.abs(a)-1,l=a===0,h=a<0,d=e%2!==0;return{nextN:c,offset:f,isZero:l,isNeg:h,isNegF:d,offsetF:u}}var bs=new WeakMap,cc=new WeakMap;function gs(t){return cc.get(t)||1}function sc(t){if(t!==rr)throw new Error("invalid wNAF")}var nr=class{BASE;ZERO;Fn;bits;constructor(e,r){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=r}_unsafeLadder(e,r,n=this.ZERO){let o=e;for(;r>rr;)r&Ot&&(n=n.add(o)),o=o.double(),r>>=Ot;return n}precomputeWindow(e,r){let{windows:n,windowSize:o}=ys(r,this.bits),s=[],i=e,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let u=1;u<o;u++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=ys(e,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:u,isZero:f,isNeg:l,isNegF:h,offsetF:d}=oc(n,a,i);n=c,f?s=s.add(zr(h,r[d])):o=o.add(zr(l,r[u]))}return sc(n),{p:o,f:s}}wNAFUnsafe(e,r,n,o=this.ZERO){let s=ys(e,this.bits);for(let i=0;i<s.windows&&n!==rr;i++){let{nextN:a,offset:c,isZero:u,isNeg:f}=oc(n,i,s);if(n=a,!u){let l=r[c];o=o.add(f?l.negate():l)}}return sc(n),o}getPrecomputes(e,r,n){let o=bs.get(r);return o||(o=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(o=n(o)),bs.set(r,o))),o}cached(e,r,n){let o=gs(e);return this.wNAF(o,this.getPrecomputes(o,e,n),r)}unsafe(e,r,n,o){let s=gs(e);return s===1?this._unsafeLadder(e,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,e,n),r,o)}createCache(e,r){ac(r,this.bits),cc.set(e,r),bs.delete(e)}hasCache(e){return gs(e)!==1}};function uc(t,e,r,n){let o=e,s=t.ZERO,i=t.ZERO;for(;r>rr||n>rr;)r&Ot&&(s=s.add(o)),n&Ot&&(i=i.add(o)),o=o.double(),r>>=Ot,n>>=Ot;return{p1:s,p2:i}}function ic(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return hs(e),e}else return tr(t,{isLE:r})}function Ln(t,e,r={},n){if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(let c of["p","n","h"]){let u=e[c];if(!(typeof u=="bigint"&&u>rr))throw new Error(`CURVE.${c} must be positive bigint`)}let o=ic(e.p,r.Fp,n),s=ic(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:s}}function Rn(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}var yt=BigInt(0),de=BigInt(1),xs=BigInt(2),Ul=BigInt(8);function Kl(t,e,r,n){let o=t.sqr(r),s=t.sqr(n),i=t.add(t.mul(e.a,o),s),a=t.add(t.ONE,t.mul(e.d,t.mul(o,s)));return t.eql(i,a)}function fc(t,e={}){let r=e,n=Ln("edwards",t,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;Fe(r,{},{uvRatio:"function"});let c=xs<<BigInt(s.BYTES*8)-de,u=g=>o.create(g),f=r.uvRatio===void 0?(g,y)=>{try{return{isValid:!0,value:o.sqrt(o.div(g,y))}}catch{return{isValid:!1,value:yt}}}:r.uvRatio;if(!Kl(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function l(g,y,E=!1){let S=E?de:yt;return Jt("coordinate "+g,y,S,c),y}function h(g){if(!(g instanceof d))throw new Error("EdwardsPoint expected")}class d{static BASE=new d(i.Gx,i.Gy,de,u(i.Gx*i.Gy));static ZERO=new d(yt,de,de,yt);static Fp=o;static Fn=s;X;Y;Z;T;constructor(y,E,S,A){this.X=l("x",y),this.Y=l("y",E),this.Z=l("z",S,!0),this.T=l("t",A),Object.freeze(this)}static CURVE(){return i}static fromAffine(y){if(y instanceof d)throw new Error("extended point not allowed");let{x:E,y:S}=y||{};return l("x",E),l("y",S),new d(E,S,de,u(E*S))}static fromBytes(y,E=!1){let S=o.BYTES,{a:A,d:O}=i;y=Vr(H(y,S,"point")),Le(E,"zip215");let B=Vr(y),F=y[S-1];B[S-1]=F&-129;let P=je(B),C=E?c:o.ORDER;Jt("point.y",P,yt,C);let N=u(P*P),Z=u(N-de),k=u(O*N-A),{isValid:p,value:b}=f(Z,k);if(!p)throw new Error("bad point: invalid y coordinate");let v=(b&de)===de,w=(F&128)!==0;if(!E&&b===yt&&w)throw new Error("bad point: x=0 and x_0=1");return w!==v&&(b=u(-b)),d.fromAffine({x:b,y:P})}static fromHex(y,E=!1){return d.fromBytes(Qt(y),E)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,E=!0){return m.createCache(this,y),E||this.multiply(xs),this}assertValidity(){let y=this,{a:E,d:S}=i;if(y.is0())throw new Error("bad point: ZERO");let{X:A,Y:O,Z:B,T:F}=y,P=u(A*A),C=u(O*O),N=u(B*B),Z=u(N*N),k=u(P*E),p=u(N*u(k+C)),b=u(Z+u(S*u(P*C)));if(p!==b)throw new Error("bad point: equation left != right (1)");let v=u(A*O),w=u(B*F);if(v!==w)throw new Error("bad point: equation left != right (2)")}equals(y){h(y);let{X:E,Y:S,Z:A}=this,{X:O,Y:B,Z:F}=y,P=u(E*F),C=u(O*A),N=u(S*F),Z=u(B*A);return P===C&&N===Z}is0(){return this.equals(d.ZERO)}negate(){return new d(u(-this.X),this.Y,this.Z,u(-this.T))}double(){let{a:y}=i,{X:E,Y:S,Z:A}=this,O=u(E*E),B=u(S*S),F=u(xs*u(A*A)),P=u(y*O),C=E+S,N=u(u(C*C)-O-B),Z=P+B,k=Z-F,p=P-B,b=u(N*k),v=u(Z*p),w=u(N*p),x=u(k*Z);return new d(b,v,x,w)}add(y){h(y);let{a:E,d:S}=i,{X:A,Y:O,Z:B,T:F}=this,{X:P,Y:C,Z:N,T:Z}=y,k=u(A*P),p=u(O*C),b=u(F*S*Z),v=u(B*N),w=u((A+O)*(P+C)-k-p),x=v-b,I=v+b,T=u(p-E*k),_=u(w*x),D=u(I*T),R=u(w*T),V=u(x*I);return new d(_,D,V,R)}subtract(y){return h(y),this.add(y.negate())}multiply(y){if(!s.isValidNot0(y))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:E,f:S}=m.cached(this,y,A=>Pt(d,A));return Pt(d,[E,S])[0]}multiplyUnsafe(y){if(!s.isValid(y))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return y===yt?d.ZERO:this.is0()||y===de?this:m.unsafe(this,y,E=>Pt(d,E))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return m.unsafe(this,i.n).is0()}toAffine(y){let E=this,S=y,{X:A,Y:O,Z:B}=E,F=E.is0();S==null&&(S=F?Ul:o.inv(B));let P=u(A*S),C=u(O*S),N=o.mul(B,S);if(F)return{x:yt,y:de};if(N!==de)throw new Error("invZ was invalid");return{x:P,y:C}}clearCofactor(){return a===de?this:this.multiplyUnsafe(a)}toBytes(){let{x:y,y:E}=this.toAffine(),S=o.toBytes(E);return S[S.length-1]|=y&de?128:0,S}toHex(){return Xt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let m=new nr(d,s.BITS);return s.BITS>=8&&d.BASE.precompute(8),Object.freeze(d.prototype),Object.freeze(d),d}var Fn=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(e){this.ep=e}static fromBytes(e){ls()}static fromHex(e){ls()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(e){return this.ep.toAffine(e)}toHex(){return Xt(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(e){return this.assertSame(e),this.init(this.ep.add(e.ep))}subtract(e){return this.assertSame(e),this.init(this.ep.subtract(e.ep))}multiply(e){return this.init(this.ep.multiply(e))}multiplyUnsafe(e){return this.init(this.ep.multiplyUnsafe(e))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(e,r){return this.ep.precompute(e,r),this}};function lc(t,e,r={}){if(typeof e!="function")throw new Error('"hash" function param is required');let n=e,o=r;Fe(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:c}=t,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(Re(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=o.randomBytes===void 0?Kr:o.randomBytes,h=o.adjustScalarBytes===void 0?p=>p:o.adjustScalarBytes,d=o.domain===void 0?(p,b,v)=>{if(Le(v,"phflag"),b.length||v)throw new Error("Contexts/pre-hash are not supported");return p}:o.domain;function m(p){return c.create(je(p))}function g(p){let b=P.secretKey;H(p,P.secretKey,"secretKey");let v=H(n(p),2*b,"hashedSecretKey"),w=h(v.slice(0,b)),x=v.slice(b,2*b),I=m(w);return{head:w,prefix:x,scalar:I}}function y(p){let{head:b,prefix:v,scalar:w}=g(p),x=i.multiply(w),I=x.toBytes();return{head:b,prefix:v,scalar:w,point:x,pointBytes:I}}function E(p){return y(p).pointBytes}function S(p=Uint8Array.of(),...b){let v=ae(...b);return m(n(d(v,H(p,void 0,"context"),!!s)))}function A(p,b,v={}){p=H(p,void 0,"message"),s&&(p=s(p));let{prefix:w,scalar:x,pointBytes:I}=y(b),T=S(v.context,w,p),_=i.multiply(T).toBytes(),D=S(v.context,_,I,p),R=c.create(T+D*x);if(!c.isValid(R))throw new Error("sign failed: invalid s");let V=ae(_,c.toBytes(R));return H(V,P.signature,"result")}let O={zip215:o.zip215};function B(p,b,v,w=O){let{context:x}=w,I=w.zip215===void 0?!!O.zip215:w.zip215,T=P.signature;p=H(p,T,"signature"),b=H(b,void 0,"message"),v=H(v,P.publicKey,"publicKey"),I!==void 0&&Le(I,"zip215"),s&&(b=s(b));let _=T/2,D=p.subarray(0,_),R=je(p.subarray(_,T)),V,j,U;try{V=t.fromBytes(v,I),j=t.fromBytes(D,I),U=i.multiplyUnsafe(R)}catch{return!1}if(!I&&V.isSmallOrder())return!1;let ie=S(x,D,v,b);return j.add(V.multiplyUnsafe(ie)).subtract(U).clearCofactor().is0()}let F=a.BYTES,P={secretKey:F,publicKey:F,signature:2*F,seed:F};function C(p){return p=p===void 0?l(P.seed):p,H(p,P.seed,"seed")}function N(p){return Tt(p)&&p.length===P.secretKey}function Z(p,b){try{return!!t.fromBytes(p,b===void 0?O.zip215:b)}catch{return!1}}let k={getExtendedPublicKey:y,randomSecretKey:C,isValidSecretKey:N,isValidPublicKey:Z,toMontgomery(p){let{y:b}=t.fromBytes(p),v=P.publicKey,w=v===32;if(!w&&v!==57)throw new Error("only defined for 25519 and 448");let x=w?a.div(de+b,de-b):a.div(b-de,b+de);return a.toBytes(x)},toMontgomerySecret(p){let b=P.secretKey;H(p,b);let v=n(p.subarray(0,b));return h(v).subarray(0,b)}};return Object.freeze(P),Object.freeze(k),Object.freeze({keygen:Rn(C,E),getPublicKey:E,sign:A,verify:B,utils:k,Point:t,lengths:P})}function $r(t,e){if(Re(t),Re(e),e<0||e>4)throw new Error("invalid I2OSP length: "+e);if(t<0||t>2**(8*e)-1)throw new Error("invalid I2OSP input: "+t);let r=Array.from({length:e}).fill(0);for(let n=e-1;n>=0;n--)r[n]=t&255,t>>>=8;return new Uint8Array(r)}function Ml(t,e){let r=new Uint8Array(t.length);for(let n=0;n<t.length;n++)r[n]=t[n]^e[n];return r}function Vl(t){if(!Tt(t)&&typeof t!="string")throw new Error("DST must be Uint8Array or ascii string");let e=typeof t=="string"?On(t):t;if(e.length===0)throw new Error("DST must be non-empty");return e}function ws(t,e,r,n){H(t),Re(r),e=Vl(e),e.length>255&&(e=n(ae(On("H2C-OVERSIZE-DST-"),e)));let{outputLen:o,blockLen:s}=n,i=Math.ceil(r/o);if(r>65535||i>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=ae(e,$r(e.length,1)),c=new Uint8Array(s),u=$r(r,2),f=new Array(i),l=n(ae(c,t,u,$r(0,1),a));f[0]=n(ae(l,$r(1,1),a));for(let d=1;d<i;d++){let m=[Ml(l,f[d-1]),$r(d+1,1),a];f[d]=n(ae(...m))}return ae(...f).slice(0,r)}var dc="HashToScalar-";var ql=BigInt(0),st=BigInt(1),hc=BigInt(2);var Hl=BigInt(5),zl=BigInt(8),or=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Is={p:or,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:zl,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function $l(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=or,a=t*t%s*t%s,c=X(a,hc,s)*a%s,u=X(c,st,s)*t%s,f=X(u,Hl,s)*u%s,l=X(f,e,s)*f%s,h=X(l,r,s)*l%s,d=X(h,n,s)*h%s,m=X(d,o,s)*d%s,g=X(m,o,s)*d%s,y=X(g,e,s)*f%s;return{pow_p_5_8:X(y,hc,s)*t%s,b2:a}}function jl(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var Es=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function As(t,e){let r=or,n=oe(e*e*e,r),o=oe(n*n*e,r),s=$l(t*o).pow_p_5_8,i=oe(t*n*s,r),a=oe(e*i*i,r),c=i,u=oe(i*Es,r),f=a===t,l=a===oe(-t,r),h=a===oe(-t*Es,r);return f&&(i=c),(l||h)&&(i=u),ot(i,r)&&(i=oe(-i,r)),{isValid:f||l,value:i}}var gt=fc(Is,{uvRatio:As}),bt=gt.Fp,yc=gt.Fn;function Yl(t){return lc(gt,_n,Object.assign({adjustScalarBytes:jl,zip215:!0},t))}var bc=Yl({});var vs=Es,Zl=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Gl=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Wl=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Xl=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),pc=t=>As(st,t),Ql=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Ss=t=>bt.create(je(t)&Ql);function mc(t){let{d:e}=Is,r=or,n=E=>bt.create(E),o=n(vs*t*t),s=n((o+st)*Wl),i=BigInt(-1),a=n((i-e*o)*n(o+e)),{isValid:c,value:u}=As(s,a),f=n(u*t);ot(f,r)||(f=n(-f)),c||(u=f),c||(i=o);let l=n(i*(o-st)*Xl-a),h=u*u,d=n((u+u)*a),m=n(l*Zl),g=n(st-h),y=n(st+h);return new gt(n(d*y),n(g*m),n(m*y),n(d*g))}var xt=class t extends Fn{static BASE=new t(gt.BASE);static ZERO=new t(gt.ZERO);static Fp=bt;static Fn=yc;constructor(e){super(e)}static fromAffine(e){return new t(gt.fromAffine(e))}assertSame(e){if(!(e instanceof t))throw new Error("RistrettoPoint expected")}init(e){return new t(e)}static fromBytes(e){Ce(e,32);let{a:r,d:n}=Is,o=or,s=O=>bt.create(O),i=Ss(e);if(!$a(bt.toBytes(i),e)||ot(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),c=s(st+r*a),u=s(st-r*a),f=s(c*c),l=s(u*u),h=s(r*n*f-l),{isValid:d,value:m}=pc(s(h*l)),g=s(m*u),y=s(m*g*h),E=s((i+i)*g);ot(E,o)&&(E=s(-E));let S=s(c*y),A=s(E*S);if(!d||ot(A,o)||S===ql)throw new Error("invalid ristretto255 encoding 2");return new t(new gt(E,S,st,A))}static fromHex(e){return t.fromBytes(Fr(e))}toBytes(){let{X:e,Y:r,Z:n,T:o}=this.ep,s=or,i=y=>bt.create(y),a=i(i(n+r)*i(n-r)),c=i(e*r),u=i(c*c),{value:f}=pc(i(a*u)),l=i(f*a),h=i(f*c),d=i(l*h*o),m;if(ot(o*d,s)){let y=i(r*vs),E=i(e*vs);e=y,r=E,m=i(l*Gl)}else m=h;ot(e*d,s)&&(r=i(-r));let g=i((n-r)*m);return ot(g,s)&&(g=i(-g)),bt.toBytes(g)}equals(e){this.assertSame(e);let{X:r,Y:n}=this.ep,{X:o,Y:s}=e.ep,i=u=>bt.create(u),a=i(r*s)===i(n*o),c=i(n*s)===i(r*o);return a||c}is0(){return this.equals(t.ZERO)}};Object.freeze(xt.BASE);Object.freeze(xt.ZERO);Object.freeze(xt.prototype);Object.freeze(xt);var Jl=Object.freeze({Point:xt,hashToCurve(t,e){let r=e?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":e.DST,n=ws(t,r,64,_n);return Jl.deriveToCurve(n)},hashToScalar(t,e={DST:dc}){let r=ws(t,e.DST,64,_n);return yc.create(je(r))},deriveToCurve(t){Ce(t,64);let e=Ss(t.subarray(0,32)),r=mc(e),n=Ss(t.subarray(32,64)),o=mc(n);return new xt(r.add(o))}});var jr=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},Nn=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var gc={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new Nn("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return e}};var Be=gc;var kn=32;var _s,ed=(async()=>{try{return await Be.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function td(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await Be.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await Be.get().subtle.verify({name:"Ed25519"},n,e,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function rd(t,e,r){return bc.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function xc(t,e,r){return _s==null&&(_s=await ed),_s?td(t,e,r):rd(t,e,r)}function Un(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Kn=class{type="Ed25519";raw;constructor(e){this.raw=Cs(e,kn)}toMultihash(){return Oe.digest(ze(this))}toCID(){return fe.createV1(114,this.toMultihash())}toString(){return ne.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:le(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let o=xc(this.raw,r,e);return Un(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Ts(t){return t=Cs(t,kn),new Kn(t)}function Cs(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new Q(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}var od=Math.pow(2,7),sd=Math.pow(2,14),id=Math.pow(2,21),Bs=Math.pow(2,28),Ds=Math.pow(2,35),Os=Math.pow(2,42),Ps=Math.pow(2,49),Y=128,ge=127;function Ae(t){if(t<od)return 1;if(t<sd)return 2;if(t<id)return 3;if(t<Bs)return 4;if(t<Ds)return 5;if(t<Os)return 6;if(t<Ps)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function sr(t,e,r=0){switch(Ae(t)){case 8:e[r++]=t&255|Y,t/=128;case 7:e[r++]=t&255|Y,t/=128;case 6:e[r++]=t&255|Y,t/=128;case 5:e[r++]=t&255|Y,t/=128;case 4:e[r++]=t&255|Y,t>>>=7;case 3:e[r++]=t&255|Y,t>>>=7;case 2:e[r++]=t&255|Y,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function ad(t,e,r=0){switch(Ae(t)){case 8:e.set(r++,t&255|Y),t/=128;case 7:e.set(r++,t&255|Y),t/=128;case 6:e.set(r++,t&255|Y),t/=128;case 5:e.set(r++,t&255|Y),t/=128;case 4:e.set(r++,t&255|Y),t>>>=7;case 3:e.set(r++,t&255|Y),t>>>=7;case 2:e.set(r++,t&255|Y),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function Ls(t,e){let r=t[e],n=0;if(n+=r&ge,r<Y||(r=t[e+1],n+=(r&ge)<<7,r<Y)||(r=t[e+2],n+=(r&ge)<<14,r<Y)||(r=t[e+3],n+=(r&ge)<<21,r<Y)||(r=t[e+4],n+=(r&ge)*Bs,r<Y)||(r=t[e+5],n+=(r&ge)*Ds,r<Y)||(r=t[e+6],n+=(r&ge)*Os,r<Y)||(r=t[e+7],n+=(r&ge)*Ps,r<Y))return n;throw new RangeError("Could not decode varint")}function cd(t,e){let r=t.get(e),n=0;if(n+=r&ge,r<Y||(r=t.get(e+1),n+=(r&ge)<<7,r<Y)||(r=t.get(e+2),n+=(r&ge)<<14,r<Y)||(r=t.get(e+3),n+=(r&ge)<<21,r<Y)||(r=t.get(e+4),n+=(r&ge)*Bs,r<Y)||(r=t.get(e+5),n+=(r&ge)*Ds,r<Y)||(r=t.get(e+6),n+=(r&ge)*Os,r<Y)||(r=t.get(e+7),n+=(r&ge)*Ps,r<Y))return n;throw new RangeError("Could not decode varint")}function ir(t,e,r=0){return e==null&&(e=Se(Ae(t))),e instanceof Uint8Array?sr(t,e,r):ad(t,e,r)}function Yr(t,e=0){return t instanceof Uint8Array?Ls(t,e):cd(t,e)}var Fs=new Float32Array([-0]),wt=new Uint8Array(Fs.buffer);function Ec(t,e,r){Fs[0]=t,e[r]=wt[0],e[r+1]=wt[1],e[r+2]=wt[2],e[r+3]=wt[3]}function vc(t,e){return wt[0]=t[e],wt[1]=t[e+1],wt[2]=t[e+2],wt[3]=t[e+3],Fs[0]}var Ns=new Float64Array([-0]),xe=new Uint8Array(Ns.buffer);function Sc(t,e,r){Ns[0]=t,e[r]=xe[0],e[r+1]=xe[1],e[r+2]=xe[2],e[r+3]=xe[3],e[r+4]=xe[4],e[r+5]=xe[5],e[r+6]=xe[6],e[r+7]=xe[7]}function Ic(t,e){return xe[0]=t[e],xe[1]=t[e+1],xe[2]=t[e+2],xe[3]=t[e+3],xe[4]=t[e+4],xe[5]=t[e+5],xe[6]=t[e+6],xe[7]=t[e+7],Ns[0]}var ud=BigInt(Number.MAX_SAFE_INTEGER),fd=BigInt(Number.MIN_SAFE_INTEGER),Te=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Lt;if(e<ud&&e>fd)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,o=e-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Ac&&(o=0n,++n>Ac&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return Lt;let r=e<0;r&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new t(n,o)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):Lt}},Lt=new Te(0,0);Lt.toBigInt=function(){return 0n};Lt.zzEncode=Lt.zzDecode=function(){return this};Lt.length=function(){return 1};var Ac=4294967296n;function _c(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function Cc(t,e,r){if(r-e<1)return"";let o,s=[],i=0,a;for(;e<r;)a=t[e++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function ks(t,e,r){let n=r,o,s;for(let i=0;i<t.length;++i)o=t.charCodeAt(i),o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&((s=t.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128);return r-n}function Ne(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function Mn(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var Us=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Ne(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Ne(this,4);return Mn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ne(this,4);return Mn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ne(this,4);let e=vc(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ne(this,4);let e=Ic(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw Ne(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return Cc(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ne(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ne(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Te(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Ne(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw Ne(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ne(this,8);let e=Mn(this.buf,this.pos+=4),r=Mn(this.buf,this.pos+=4);return new Te(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Ls(this.buf,this.pos);return this.pos+=Ae(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Zr(t){return new Us(t instanceof Uint8Array?t:t.subarray())}function ke(t,e,r){let n=Zr(t);return e.decode(n,void 0,r)}function Ks(t){let e=t??8192,r=e>>>1,n,o=e;return function(i){if(i<1||i>r)return Se(i);o+i>e&&(n=Se(e),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Rt=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function Ms(){}var qs=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},ld=Ks();function dd(t){return globalThis.Buffer!=null?Se(t):ld(t)}var Wr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Rt(Ms,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Rt(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Hs((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(Vn,10,Te.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=Te.fromBigInt(e);return this._push(Vn,r.length(),r)}uint64Number(e){return this._push(sr,Ae(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=Te.fromBigInt(e).zzEncode();return this._push(Vn,r.length(),r)}sint64Number(e){let r=Te.fromNumber(e).zzEncode();return this._push(Vn,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Vs,1,e?1:0)}fixed32(e){return this._push(Gr,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=Te.fromBigInt(e);return this._push(Gr,4,r.lo)._push(Gr,4,r.hi)}fixed64Number(e){let r=Te.fromNumber(e);return this._push(Gr,4,r.lo)._push(Gr,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(Ec,4,e)}double(e){return this._push(Sc,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(Vs,1,0):this.uint32(r)._push(pd,r,e)}string(e){let r=_c(e);return r!==0?this.uint32(r)._push(ks,r,e):this._push(Vs,1,0)}fork(){return this.states=new qs(this),this.head=this.tail=new Rt(Ms,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 Rt(Ms,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=dd(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function Vs(t,e,r){e[r]=t&255}function hd(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var Hs=class extends Rt{next;constructor(e,r){super(hd,e,r),this.next=void 0}};function Vn(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function Gr(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function pd(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(Wr.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(md,e,t),this},Wr.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(yd,e,t),this});function md(t,e,r){e.set(t,r)}function yd(t,e,r){t.length<40?ks(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(K(t),r)}function zs(){return new Wr}function Ue(t,e){let r=zs();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*Ke(t,e,r){let n=Zr(t);yield*e.stream(n,void 0,"$",r)}var qn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Hn(t,e,r,n,o){return{name:t,type:e,encode:r,decode:n,stream:o}}function $s(t){function e(s){if(t[s.toString()]==null)throw new Error("Invalid enum value");return t[s]}let r=function(i,a){let c=e(i);a.int32(c)},n=function(i){let a=i.int32();return e(a)},o=function*(i){let a=i.int32();yield e(a)};return Hn("enum",qn.VARINT,r,n,o)}function Me(t,e,r){return Hn("message",qn.LENGTH_DELIMITED,t,e,r)}var Ye=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var J;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(J||(J={}));var js;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(js||(js={}));(function(t){t.codec=()=>$s(js)})(J||(J={}));var Ze;(function(t){let e;t.codec=()=>(e==null&&(e=Me((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),J.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=J.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:J.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return Ue(s,t.codec())}t.encode=r;function n(s,i){return ke(s,t.codec(),i)}t.decode=n;function o(s,i){return Ke(s,t.codec(),i)}t.stream=o})(Ze||(Ze={}));var Ys;(function(t){let e;t.codec=()=>(e==null&&(e=Me((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),J.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.Type=J.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:J.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return Ue(s,t.codec())}t.encode=r;function n(s,i){return ke(s,t.codec(),i)}t.decode=n;function o(s,i){return Ke(s,t.codec(),i)}t.stream=o})(Ys||(Ys={}));var Qr={};ve(Qr,{MAX_RSA_KEY_SIZE:()=>Zs,generateRSAKeyPair:()=>Lc,jwkToJWKKeyPair:()=>Rc,jwkToPkcs1:()=>wd,jwkToPkix:()=>Qs,jwkToRSAPrivateKey:()=>ri,pkcs1MessageToJwk:()=>Ws,pkcs1MessageToRSAPrivateKey:()=>Js,pkcs1ToJwk:()=>xd,pkcs1ToRSAPrivateKey:()=>Pc,pkixMessageToJwk:()=>Xs,pkixMessageToRSAPublicKey:()=>ti,pkixToJwk:()=>Ed,pkixToRSAPublicKey:()=>ei});var ar=class{type="RSA";jwk;_raw;_multihash;constructor(e,r){this.jwk=e,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Qr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return fe.createV1(114,this._multihash)}toString(){return ne.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:le(this.raw,e.raw)}verify(e,r,n){return Oc(this.jwk,r,e,n)}},Xr=class{type="RSA";jwk;_raw;publicKey;constructor(e,r){this.jwk=e,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Qr.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:le(this.raw,e.raw)}sign(e,r){return Dc(this.jwk,e,r)}};var Zs=8192,Gs=18,bd=1062,gd=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function xd(t){let e=et(t);return Ws(e)}function Ws(t){return{n:q(t[1],"base64url"),e:q(t[2],"base64url"),d:q(t[3],"base64url"),p:q(t[4],"base64url"),q:q(t[5],"base64url"),dp:q(t[6],"base64url"),dq:q(t[7],"base64url"),qi:q(t[8],"base64url"),kty:"RSA"}}function wd(t){if(t.n==null||t.e==null||t.d==null||t.p==null||t.q==null||t.dp==null||t.dq==null||t.qi==null)throw new Q("JWK was missing components");return lt([Ie(Uint8Array.from([0])),Ie(K(t.n,"base64url")),Ie(K(t.e,"base64url")),Ie(K(t.d,"base64url")),Ie(K(t.p,"base64url")),Ie(K(t.q,"base64url")),Ie(K(t.dp,"base64url")),Ie(K(t.dq,"base64url")),Ie(K(t.qi,"base64url"))]).subarray()}function Ed(t){let e=et(t,{offset:0});return Xs(e)}function Xs(t){let e=et(t[1],{offset:0});return{kty:"RSA",n:q(e[0],"base64url"),e:q(e[1],"base64url")}}function Qs(t){if(t.n==null||t.e==null)throw new Q("JWK was missing components");return lt([gd,wn(lt([Ie(K(t.n,"base64url")),Ie(K(t.e,"base64url"))]))]).subarray()}function Pc(t){let e=et(t);return Js(e)}function Js(t){let e=Ws(t);return ri(e)}function ei(t,e){if(t.byteLength>=bd)throw new Ht("Key size is too large");let r=et(t,{offset:0});return ti(r,t,e)}function ti(t,e,r){let n=Xs(t);if(r==null){let o=Wt(Ze.encode({Type:J.RSA,Data:e}));r=He(Gs,o)}return new ar(n,r)}function ri(t){if(Nc(t)>Zs)throw new Q("Key size is too large");let e=Rc(t),r=Wt(Ze.encode({Type:J.RSA,Data:Qs(e.publicKey)})),n=He(Gs,r);return new Xr(e.privateKey,new ar(e.publicKey,n))}async function Lc(t){if(t>Zs)throw new Q("Key size is too large");let e=await Fc(t),r=Wt(Ze.encode({Type:J.RSA,Data:Qs(e.publicKey)})),n=He(Gs,r);return new Xr(e.privateKey,new ar(e.publicKey,n))}function Rc(t){if(t==null)throw new Q("Missing key parameter");return{privateKey:t,publicKey:{kty:t.kty,n:t.n,e:t.e}}}async function Fc(t,e){let r=await Be.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:t,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);e?.signal?.throwIfAborted();let n=await vd(r,e);return{privateKey:n[0],publicKey:n[1]}}async function Dc(t,e,r){let n=await Be.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Be.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,e instanceof Uint8Array?e:e.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Oc(t,e,r,n){let o=await Be.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Be.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,e,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),s}async function vd(t,e){if(t.privateKey==null||t.publicKey==null)throw new Q("Private and public key are required");let r=await Promise.all([Be.get().subtle.exportKey("jwk",t.privateKey),Be.get().subtle.exportKey("jwk",t.publicKey)]);return e?.signal?.throwIfAborted(),r}function Nc(t){if(t.kty!=="RSA")throw new Q("invalid key type");if(t.n==null)throw new Q("invalid key modulus");return K(t.n,"base64url").length*8}var zn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(En(e),Ce(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),rt(o)}update(e){return Gt(this),this.iHash.update(e),this}digestInto(e){Gt(this),vn(e,this),this.finished=!0;let r=e.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=a,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},kc=(()=>{let t=((e,r,n)=>new zn(e,r).update(n).digest());return t.create=(e,r)=>new zn(e,r),t})();var Uc=(t,e)=>(t+(t>=0?e:-e)/Kc)/e;function Sd(t,e,r){Jt("scalar",t,Ge,r);let[[n,o],[s,i]]=e,a=Uc(i*t,r),c=Uc(-o*t,r),u=t-a*n-c*s,f=-a*o-c*i,l=u<Ge,h=f<Ge;l&&(u=-u),h&&(f=-f);let d=qr(Math.ceil(er(r)/2))+Et;if(u<Ge||u>=d||f<Ge||f>=d)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:h,k2:f}}function oi(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function ni(t,e){Fe(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Le(r.lowS,"lowS"),Le(r.prehash,"prehash"),r.format!==void 0&&oi(r.format),r}var si=class extends Error{constructor(e=""){super(e)}},Ve={Err:si,_tlv:{encode:(t,e)=>{let{Err:r}=Ve;if(Re(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(typeof e!="string")throw new TypeError('"data" expected string, got type='+typeof e);if(e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,o=Mr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Mr(o.length/2|128):"";return Mr(t)+s+o+e},decode(t,e){let{Err:r}=Ve;e=H(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.encode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let o=e[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)i=i<<8|f;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+i)}}},_int:{encode(t){let{Err:e}=Ve;if(Bn(t),t<Ge)throw new e("integer: negative integers are not allowed");let r=Mr(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=Ve;if(t.length<1)throw new e("invalid signature integer: empty");if(t[0]&128)throw new e("invalid signature integer: negative");if(t.length>1&&t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return Bt(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=Ve,o=H(t,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:u,l:f}=n.decode(2,c);if(f.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(u)}},hexFromSig(t){let{_tlv:e,_int:r}=Ve,n=e.encode(2,r.encode(t.r)),o=e.encode(2,r.encode(t.s)),s=n+o;return e.encode(48,s)}};Object.freeze(Ve._tlv);Object.freeze(Ve._int);Object.freeze(Ve);var Ge=BigInt(0),Et=BigInt(1),Kc=BigInt(2),$n=BigInt(3),Id=BigInt(4);function Mc(t,e={}){let r=Ln("weierstrass",t,e),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;Fe(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c,allowInfinityPoint:u}=e;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=qc(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function h(k,p,b){if(u&&p.is0())return Uint8Array.of(0);let{x:v,y:w}=p.toAffine(),x=n.toBytes(v);if(Le(b,"isCompressed"),b){l();let I=!n.isOdd(w);return ae(Vc(I),x)}else return ae(Uint8Array.of(4),x,n.toBytes(w))}function d(k){H(k,void 0,"Point");let{publicKey:p,publicKeyUncompressed:b}=f,v=k.length,w=k[0],x=k.subarray(1);if(u&&v===1&&w===0)return{x:n.ZERO,y:n.ZERO};if(v===p&&(w===2||w===3)){let I=n.fromBytes(x);if(!n.isValid(I))throw new Error("bad point: is not on curve, wrong x");let T=y(I),_;try{_=n.sqrt(T)}catch(V){let j=V instanceof Error?": "+V.message:"";throw new Error("bad point: is not on curve, sqrt error"+j)}l();let D=n.isOdd(_);return(w&1)===1!==D&&(_=n.neg(_)),{x:I,y:_}}else if(v===b&&w===4){let I=n.BYTES,T=n.fromBytes(x.subarray(0,I)),_=n.fromBytes(x.subarray(I,I*2));if(!E(T,_))throw new Error("bad point: is not on curve");return{x:T,y:_}}else throw new Error(`bad point: got length ${v}, expected compressed=${p} or uncompressed=${b}`)}let m=e.toBytes===void 0?h:e.toBytes,g=e.fromBytes===void 0?d:e.fromBytes;function y(k){let p=n.sqr(k),b=n.mul(p,k);return n.add(n.add(b,n.mul(k,s.a)),s.b)}function E(k,p){let b=n.sqr(p),v=y(k);return n.eql(b,v)}if(!E(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let S=n.mul(n.pow(s.a,$n),Id),A=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(S,A)))throw new Error("bad curve params: a or b");function O(k,p,b=!1){if(!n.isValid(p)||b&&n.is0(p))throw new Error(`bad point coordinate ${k}`);return p}function B(k){if(!(k instanceof C))throw new Error("Weierstrass Point expected")}function F(k){if(!c||!c.basises)throw new Error("no endo");return Sd(k,c.basises,o.ORDER)}function P(k,p,b,v,w){return b=new C(n.mul(b.X,k),b.Y,b.Z),p=zr(v,p),b=zr(w,b),p.add(b)}class C{static BASE=new C(s.Gx,s.Gy,n.ONE);static ZERO=new C(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(p,b,v){this.X=O("x",p),this.Y=O("y",b,!0),this.Z=O("z",v),Object.freeze(this)}static CURVE(){return s}static fromAffine(p){let{x:b,y:v}=p||{};if(!p||!n.isValid(b)||!n.isValid(v))throw new Error("invalid affine point");if(p instanceof C)throw new Error("projective point not allowed");return n.is0(b)&&n.is0(v)?C.ZERO:new C(b,v,n.ONE)}static fromBytes(p){let b=C.fromAffine(g(H(p,void 0,"point")));return b.assertValidity(),b}static fromHex(p){return C.fromBytes(Qt(p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=8,b=!0){return Z.createCache(this,p),b||this.multiply($n),this}assertValidity(){let p=this;if(p.is0()){if(e.allowInfinityPoint&&n.is0(p.X)&&n.eql(p.Y,n.ONE)&&n.is0(p.Z))return;throw new Error("bad point: ZERO")}let{x:b,y:v}=p.toAffine();if(!n.isValid(b)||!n.isValid(v))throw new Error("bad point: x or y not field elements");if(!E(b,v))throw new Error("bad point: equation left != right");if(!p.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:p}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(p)}equals(p){B(p);let{X:b,Y:v,Z:w}=this,{X:x,Y:I,Z:T}=p,_=n.eql(n.mul(b,T),n.mul(x,w)),D=n.eql(n.mul(v,T),n.mul(I,w));return _&&D}negate(){return new C(this.X,n.neg(this.Y),this.Z)}double(){let{a:p,b}=s,v=n.mul(b,$n),{X:w,Y:x,Z:I}=this,T=n.ZERO,_=n.ZERO,D=n.ZERO,R=n.mul(w,w),V=n.mul(x,x),j=n.mul(I,I),U=n.mul(w,x);return U=n.add(U,U),D=n.mul(w,I),D=n.add(D,D),T=n.mul(p,D),_=n.mul(v,j),_=n.add(T,_),T=n.sub(V,_),_=n.add(V,_),_=n.mul(T,_),T=n.mul(U,T),D=n.mul(v,D),j=n.mul(p,j),U=n.sub(R,j),U=n.mul(p,U),U=n.add(U,D),D=n.add(R,R),R=n.add(D,R),R=n.add(R,j),R=n.mul(R,U),_=n.add(_,R),j=n.mul(x,I),j=n.add(j,j),R=n.mul(j,U),T=n.sub(T,R),D=n.mul(j,V),D=n.add(D,D),D=n.add(D,D),new C(T,_,D)}add(p){B(p);let{X:b,Y:v,Z:w}=this,{X:x,Y:I,Z:T}=p,_=n.ZERO,D=n.ZERO,R=n.ZERO,V=s.a,j=n.mul(s.b,$n),U=n.mul(b,x),ie=n.mul(v,I),ce=n.mul(w,T),ue=n.add(b,v),re=n.add(x,I);ue=n.mul(ue,re),re=n.add(U,ie),ue=n.sub(ue,re),re=n.add(b,w);let Ee=n.add(x,T);return re=n.mul(re,Ee),Ee=n.add(U,ce),re=n.sub(re,Ee),Ee=n.add(v,w),_=n.add(I,T),Ee=n.mul(Ee,_),_=n.add(ie,ce),Ee=n.sub(Ee,_),R=n.mul(V,re),_=n.mul(j,ce),R=n.add(_,R),_=n.sub(ie,R),R=n.add(ie,R),D=n.mul(_,R),ie=n.add(U,U),ie=n.add(ie,U),ce=n.mul(V,ce),re=n.mul(j,re),ie=n.add(ie,ce),ce=n.sub(U,ce),ce=n.mul(V,ce),re=n.add(re,ce),U=n.mul(ie,re),D=n.add(D,U),U=n.mul(Ee,re),_=n.mul(ue,_),_=n.sub(_,U),U=n.mul(ue,ie),R=n.mul(Ee,R),R=n.add(R,U),new C(_,D,R)}subtract(p){return B(p),this.add(p.negate())}is0(){return this.equals(C.ZERO)}multiply(p){let{endo:b}=e;if(!o.isValidNot0(p))throw new RangeError("invalid scalar: out of range");let v,w,x=I=>Z.cached(this,I,T=>Pt(C,T));if(b){let{k1neg:I,k1:T,k2neg:_,k2:D}=F(p),{p:R,f:V}=x(T),{p:j,f:U}=x(D);w=V.add(U),v=P(b.beta,R,j,I,_)}else{let{p:I,f:T}=x(p);v=I,w=T}return Pt(C,[v,w])[0]}multiplyUnsafe(p){let{endo:b}=e,v=this,w=p;if(!o.isValid(w))throw new RangeError("invalid scalar: out of range");if(w===Ge||v.is0())return C.ZERO;if(w===Et)return v;if(Z.hasCache(this))return this.multiply(w);if(b){let{k1neg:x,k1:I,k2neg:T,k2:_}=F(w),{p1:D,p2:R}=uc(C,v,I,_);return P(b.beta,D,R,x,T)}else return Z.unsafe(v,w)}toAffine(p){let b=this,v=p,{X:w,Y:x,Z:I}=b;if(n.eql(I,n.ONE))return{x:w,y:x};let T=b.is0();v==null&&(v=T?n.ONE:n.inv(I));let _=n.mul(w,v),D=n.mul(x,v),R=n.mul(I,v);if(T)return{x:n.ZERO,y:n.ZERO};if(!n.eql(R,n.ONE))throw new Error("invZ was invalid");return{x:_,y:D}}isTorsionFree(){let{isTorsionFree:p}=e;return i===Et?!0:p?p(C,this):Z.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:p}=e;return i===Et?this:p?p(C,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===Et?this.is0():this.clearCofactor().is0()}toBytes(p=!0){return Le(p,"isCompressed"),this.assertValidity(),m(C,this,p)}toHex(p=!0){return Xt(this.toBytes(p))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let N=o.BITS,Z=new nr(C,e.endo?Math.ceil(N/2):N);return N>=8&&C.BASE.precompute(8),Object.freeze(C.prototype),Object.freeze(C),C}function Vc(t){return Uint8Array.of(t?2:3)}function qc(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function Ad(t,e={}){let{Fn:r}=t,n=e.randomBytes===void 0?Kr:e.randomBytes,o=Object.assign(qc(t.Fp,r),{seed:Math.max(ps(r.ORDER),16)});function s(d){try{let m=r.fromBytes(d);return r.isValidNot0(m)}catch{return!1}}function i(d,m){let{publicKey:g,publicKeyUncompressed:y}=o;try{let E=d.length;return m===!0&&E!==g||m===!1&&E!==y?!1:!!t.fromBytes(d)}catch{return!1}}function a(d){return d=d===void 0?n(o.seed):d,ms(H(d,o.seed,"seed"),r.ORDER)}function c(d,m=!0){return t.BASE.multiply(r.fromBytes(d)).toBytes(m)}function u(d){let{secretKey:m,publicKey:g,publicKeyUncompressed:y}=o,E=r._lengths;if(!Tt(d))return;let S=H(d,void 0,"key").length,A=S===g||S===y,O=S===m||!!E?.includes(S);if(!(A&&O))return A}function f(d,m,g=!0){if(u(d)===!0)throw new Error("first arg must be private key");if(u(m)===!1)throw new Error("second arg must be public key");let y=r.fromBytes(d);return t.fromBytes(m).multiply(y).toBytes(g)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},h=Rn(a,c);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:h,Point:t,utils:l,lengths:o})}function Hc(t,e,r={}){let n=e;En(n),Fe(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let o=r.randomBytes===void 0?Kr:r.randomBytes,s=r.hmac===void 0?(w,x)=>kc(n,w,x):r.hmac,{Fp:i,Fn:a}=t,{ORDER:c,BITS:u}=a,{keygen:f,getPublicKey:l,getSharedSecret:h,utils:d,lengths:m}=Ad(t,r),g={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},y=c*Kc+Et<i.ORDER;function E(w){let x=c>>Et;return w>x}function S(w,x){if(!a.isValidNot0(x))throw new Error(`invalid signature ${w}: out of range 1..Point.Fn.ORDER`);return x}function A(){if(y)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function O(w,x){oi(x);let I=m.signature,T=x==="compact"?I:x==="recovered"?I+1:void 0;return H(w,T)}class B{r;s;recovery;constructor(x,I,T){if(this.r=S("r",x),this.s=S("s",I),T!=null){if(A(),![0,1,2,3].includes(T))throw new Error("invalid recovery id");this.recovery=T}Object.freeze(this)}static fromBytes(x,I=g.format){O(x,I);let T;if(I==="der"){let{r:V,s:j}=Ve.toSig(H(x));return new B(V,j)}I==="recovered"&&(T=x[0],I="compact",x=x.subarray(1));let _=m.signature/2,D=x.subarray(0,_),R=x.subarray(_,_*2);return new B(a.fromBytes(D),a.fromBytes(R),T)}static fromHex(x,I){return this.fromBytes(Qt(x),I)}assertRecovery(){let{recovery:x}=this;if(x==null)throw new Error("invalid recovery id: must be present");return x}addRecoveryBit(x){return new B(this.r,this.s,x)}recoverPublicKey(x){let{r:I,s:T}=this,_=this.assertRecovery(),D=_===2||_===3?I+c:I;if(!i.isValid(D))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let R=i.toBytes(D),V=t.fromBytes(ae(Vc((_&1)===0),R)),j=a.inv(D),U=P(H(x,void 0,"msgHash")),ie=a.create(-U*j),ce=a.create(T*j),ue=t.BASE.multiplyUnsafe(ie).add(V.multiplyUnsafe(ce));if(ue.is0())throw new Error("invalid recovery: point at infinify");return ue.assertValidity(),ue}hasHighS(){return E(this.s)}toBytes(x=g.format){if(oi(x),x==="der")return Qt(Ve.hexFromSig(this));let{r:I,s:T}=this,_=a.toBytes(I),D=a.toBytes(T);return x==="recovered"?(A(),ae(Uint8Array.of(this.assertRecovery()),_,D)):ae(_,D)}toHex(x){return Xt(this.toBytes(x))}}Object.freeze(B.prototype),Object.freeze(B);let F=r.bits2int===void 0?function(x){if(x.length>8192)throw new Error("input is too large");let I=Bt(x),T=x.length*8-u;return T>0?I>>BigInt(T):I}:r.bits2int,P=r.bits2int_modN===void 0?function(x){return a.create(F(x))}:r.bits2int_modN,C=qr(u);function N(w){return Jt("num < 2^"+u,w,Ge,C),a.toBytes(w)}function Z(w,x){return H(w,void 0,"message"),x?H(n(w),void 0,"prehashed message"):w}function k(w,x,I){let{lowS:T,prehash:_,extraEntropy:D}=ni(I,g);w=Z(w,_);let R=P(w),V=a.fromBytes(x);if(!a.isValidNot0(V))throw new Error("invalid private key");let j=[N(V),N(R)];if(D!=null&&D!==!1){let ue=D===!0?o(m.secretKey):D;j.push(H(ue,void 0,"extraEntropy"))}let U=ae(...j),ie=R;function ce(ue){let re=F(ue);if(!a.isValidNot0(re))return;let Ee=a.inv(re),qt=t.BASE.multiply(re).toAffine(),Ar=a.create(qt.x);if(Ar===Ge)return;let dn=a.create(Ee*a.create(ie+Ar*V));if(dn===Ge)return;let ea=(qt.x===Ar?0:2)|Number(qt.y&Et),ta=dn;return T&&E(dn)&&(ta=a.neg(dn),ea^=1),new B(Ar,ta,y?void 0:ea)}return{seed:U,k2sig:ce}}function p(w,x,I={}){let{seed:T,k2sig:_}=k(w,x,I);return ja(n.outputLen,a.BYTES,s)(T,_).toBytes(I.format)}function b(w,x,I,T={}){let{lowS:_,prehash:D,format:R}=ni(T,g);if(I=H(I,void 0,"publicKey"),x=Z(x,D),!Tt(w)){let V=w instanceof B?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+V)}O(w,R);try{let V=B.fromBytes(w,R),j=t.fromBytes(I);if(_&&V.hasHighS())return!1;let{r:U,s:ie}=V,ce=P(x),ue=a.inv(ie),re=a.create(ce*ue),Ee=a.create(U*ue),qt=t.BASE.multiplyUnsafe(re).add(j.multiplyUnsafe(Ee));return qt.is0()?!1:a.create(qt.x)===U}catch{return!1}}function v(w,x,I={}){let{prehash:T}=ni(I,g);return x=Z(x,T),B.fromBytes(w,"recovered").recoverPublicKey(x).toBytes()}return Object.freeze({keygen:f,getPublicKey:l,getSharedSecret:h,utils:d,lengths:m,Point:t,sign:p,verify:b,recoverPublicKey:v,Signature:B,hash:n})}var ai={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},_d={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var zc=BigInt(2);function Cd(t){let e=ai.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=t*t*t%e,f=u*u*t%e,l=X(f,r,e)*f%e,h=X(l,r,e)*f%e,d=X(h,zc,e)*u%e,m=X(d,o,e)*d%e,g=X(m,s,e)*m%e,y=X(g,a,e)*g%e,E=X(y,c,e)*y%e,S=X(E,a,e)*g%e,A=X(S,r,e)*f%e,O=X(A,i,e)*m%e,B=X(O,n,e)*u%e,F=X(B,zc,e);if(!ii.eql(ii.sqr(F),t))throw new Error("Cannot find square root");return F}var ii=tr(ai.p,{sqrt:Cd}),Td=Mc(ai,{Fp:ii,endo:_d}),cr=Hc(Td,Wt);function $c(t,e,r,n){let o=Or.digest(r instanceof Uint8Array?r:r.subarray());if(Un(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),cr.verify(e,s,t,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new jr(String(s))});try{return n?.signal?.throwIfAborted(),cr.verify(e,o.digest,t,{prehash:!1,format:"der"})}catch(s){throw new jr(String(s))}}var jn=class{type="secp256k1";raw;_key;constructor(e){this._key=Yc(e),this.raw=jc(this._key)}toMultihash(){return Oe.digest(ze(this))}toCID(){return fe.createV1(114,this.toMultihash())}toString(){return ne.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:le(this.raw,e.raw)}verify(e,r,n){return $c(this._key,r,e,n)}};function ci(t){return new jn(t)}function jc(t){return cr.Point.fromBytes(t).toBytes()}function Yc(t){try{return cr.Point.fromBytes(t),t}catch(e){throw new Ht(String(e))}}function ur(t,e){let{Type:r,Data:n}=Ze.decode(t),o=n??new Uint8Array;switch(r){case J.RSA:return ei(o,e);case J.Ed25519:return Ts(o);case J.secp256k1:return ci(o);case J.ECDSA:return Xo(o);default:throw new It}}function Zc(t){let{Type:e,Data:r}=Ze.decode(t.digest),n=r??new Uint8Array;switch(e){case J.Ed25519:return Ts(n);case J.secp256k1:return ci(n);case J.ECDSA:return Xo(n);default:throw new It}}function ze(t){return Ze.encode({Type:J[t.type],Data:t.raw})}var Jr;(function(t){let e;t.codec=()=>(e==null&&(e=Me((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.publicKey!=null&&s.publicKey.byteLength>0&&(i.uint32(10),i.bytes(s.publicKey)),s.payloadType!=null&&s.payloadType.byteLength>0&&(i.uint32(18),i.bytes(s.payloadType)),s.payload!=null&&s.payload.byteLength>0&&(i.uint32(26),i.bytes(s.payload)),s.signature!=null&&s.signature.byteLength>0&&(i.uint32(42),i.bytes(s.signature)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={publicKey:pe(0),payloadType:pe(0),payload:pe(0),signature:pe(0)},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{c.publicKey=s.bytes();break}case 2:{c.payloadType=s.bytes();break}case 3:{c.payload=s.bytes();break}case 5:{c.signature=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.publicKey`,value:s.bytes()};break}case 2:{yield{field:`${a}.payloadType`,value:s.bytes()};break}case 3:{yield{field:`${a}.payload`,value:s.bytes()};break}case 5:{yield{field:`${a}.signature`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return Ue(s,t.codec())}t.encode=r;function n(s,i){return ke(s,t.codec(),i)}t.decode=n;function o(s,i){return Ke(s,t.codec(),i)}t.stream=o})(Jr||(Jr={}));var Yn=class extends Error{constructor(e="Invalid signature"){super(e),this.name="InvalidSignatureError"}};var We=class t{static createFromProtobuf=e=>{let r=Jr.decode(e),n=ur(r.publicKey);return new t({publicKey:n,payloadType:r.payloadType,payload:r.payload,signature:r.signature})};static seal=async(e,r,n)=>{if(r==null)throw new Error("Missing private key");let o=e.domain,s=e.codec,i=e.marshal(),a=Gc(o,s,i),c=await r.sign(a.subarray(),n);return new t({publicKey:r.publicKey,payloadType:s,payload:i,signature:c})};static openAndCertify=async(e,r,n)=>{let o=t.createFromProtobuf(e);if(!await o.validate(r,n))throw new Yn("Envelope signature is not valid for the given domain");return o};publicKey;payloadType;payload;signature;marshaled;constructor(e){let{publicKey:r,payloadType:n,payload:o,signature:s}=e;this.publicKey=r,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=Jr.encode({publicKey:ze(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(e){return e==null?!1:le(this.marshal(),e.marshal())}async validate(e,r){let n=Gc(e,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},Gc=(t,e,r)=>{let n=K(t),o=ir(n.byteLength),s=ir(e.length),i=ir(r.length);return new se(o,n,s,e,i,r)};var Wc=Symbol.for("nodejs.util.inspect.custom"),Bd=114,en=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[So]=!0;toString(){return this.string==null&&(this.string=ne.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return fe.createV1(Bd,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return le(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return le(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[Wc](){return`PeerId(${this.toString()})`}},tn=class extends en{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},rn=class extends en{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},nn=class extends en{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},Dd=2336,on=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Oe.digest(K(this.url))}[Wc](){return`PeerId(${this.url})`}[So]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return fe.createV1(Dd,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=q(e)),e.toString()===this.toString())}};var Od=114,Xc=2336;function Qc(t){if(t.type==="Ed25519")return new rn({multihash:t.toCID().multihash,publicKey:t});if(t.type==="secp256k1")return new nn({multihash:t.toCID().multihash,publicKey:t});if(t.type==="RSA")return new tn({multihash:t.toCID().multihash,publicKey:t});throw new It}function ui(t){if(Ld(t))return new tn({multihash:t});if(Pd(t))try{let e=Zc(t);if(e.type==="Ed25519")return new rn({multihash:t,publicKey:e});if(e.type==="secp256k1")return new nn({multihash:t,publicKey:e})}catch{let r=q(t.digest);return new on(new URL(r))}throw new mn("Supplied PeerID Multihash is invalid")}function Zn(t){if(t?.multihash==null||t.version==null||t.version===1&&t.code!==Od&&t.code!==Xc)throw new pn("Supplied PeerID CID is invalid");if(t.code===Xc){let e=q(t.multihash.digest);return new on(new URL(e))}return ui(t.multihash)}function Pd(t){return t.code===Oe.code}function Ld(t){return t.code===Or.code}var be=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},it=class extends Error{static name="ValidationError";name="ValidationError"},Gn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Wn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var Xn=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let r=this.index,n=e();return n===void 0&&(this.index=r),n}parseWith(e){let r=e();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let r=this.readChar();if(r===e)return r})}readSeparator(e,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,r,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",u=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let h=Number.parseInt(l,e);if(!Number.isNaN(h))return h});if(f===void 0)break;if(s*=e,s+=f,s>u||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let r=0;r<e.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[r]=n}return e})}readIPv6Addr(){let e=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=e(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Jc=45,Rd=15,fr=new Xn;function Qn(t){if(!(t.length>Rd))return fr.new(t).parseWith(()=>fr.readIPv4Addr())}function Jn(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>Jc))return fr.new(t).parseWith(()=>fr.readIPv6Addr())}function lr(t,e=!1){if(t.includes("%")&&(t=t.split("%")[0]),t.length>Jc)return;let r=fr.new(t).parseWith(()=>fr.readIPAddr());if(r)return e&&r.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,r[0],r[1],r[2],r[3]]):r}function dr(t){return!!Qn(t)}function eo(t){return!!Jn(t)}function li(t){return e=>q(e,t)}function di(t){return e=>K(e,t)}function hr(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function Ft(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function eu(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let r=K(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Ft(n);return Je([r,o],r.length+o.length)}function tu(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let r=ft.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Ft(n);return Je([r,o],r.length+o.length)}function hi(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=q(e,"base32"),o=hr(r);return`${n}:${o}`}var pi=function(t){t=t.toString().trim();let e=new Uint8Array(4);return t.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new be("Invalid byte value in IP address");e[n]=o}),e},ru=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let s=dr(r[n]),i;s&&(i=pi(r[n]),r[n]=q(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,q(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(e+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new be("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},nu=function(t){if(t.byteLength!==4)throw new be("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},ou=function(t){if(t.byteLength!==16)throw new be("IPv6 address was incorrect length");let e=[];for(let n=0;n<t.byteLength;n+=2){let o=t[n],s=t[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;e.push(i)}let r=e.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new be(`Invalid IPv6 address "${r}"`)}};function su(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new be(`Invalid IPv6 address "${t}"`)}}var fi=Object.values(Pr).map(t=>t.decoder),Fd=(function(){let t=fi[0].or(fi[1]);return fi.slice(2).forEach(e=>t=t.or(e)),t})();function iu(t){return Fd.decode(t)}function au(t){return e=>t.encoder.encode(e)}function Nd(t){if(parseInt(t).toString()!==t)throw new it("Value must be an integer")}function kd(t){if(t<0)throw new it("Value must be a positive integer, or zero")}function Ud(t){return e=>{if(e>t)throw new it(`Value must be smaller than or equal to ${t}`)}}function Kd(...t){return e=>{for(let r of t)r(e)}}var sn=Kd(Nd,kd,Ud(65535));var he=-1,mi=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let r;if(typeof e=="string"?r=this.protocolsByName.get(e):r=this.protocolsByCode.get(e),r==null)throw new Wn(`Protocol ${e} was unknown`);return r}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(r=>{this.protocolsByName.set(r,e)})}removeProtocol(e){let r=this.protocolsByCode.get(e);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},ct=new mi,Jd=[{code:4,name:"ip4",size:32,valueToBytes:pi,bytesToValue:nu,validate:t=>{if(!dr(t))throw new it(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Ft,bytesToValue:hr,validate:sn},{code:273,name:"udp",size:16,valueToBytes:Ft,bytesToValue:hr,validate:sn},{code:33,name:"dccp",size:16,valueToBytes:Ft,bytesToValue:hr,validate:sn},{code:41,name:"ip6",size:128,valueToBytes:ru,bytesToValue:ou,stringToValue:su,validate:t=>{if(!eo(t))throw new it(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:he},{code:43,name:"ipcidr",size:8,bytesToValue:li("base10"),valueToBytes:di("base10")},{code:53,name:"dns",size:he},{code:54,name:"dns4",size:he},{code:55,name:"dns6",size:he},{code:56,name:"dnsaddr",size:he},{code:132,name:"sctp",size:16,valueToBytes:Ft,bytesToValue:hr,validate:sn},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:he,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:he,bytesToValue:li("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?di("base58btc")(t):fe.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:hi,valueToBytes:eu},{code:445,name:"onion3",size:296,bytesToValue:hi,valueToBytes:tu},{code:446,name:"garlic64",size:he},{code:447,name:"garlic32",size:he},{code:448,name:"tls"},{code:449,name:"sni",size:he},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:he,bytesToValue:au(Uo),valueToBytes:iu},{code:480,name:"http"},{code:481,name:"http-path",size:he,stringToValue:t=>`/${decodeURIComponent(t)}`,valueToString:t=>encodeURIComponent(t.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:he}];Jd.forEach(t=>{ct.addProtocol(t)});function cu(t){let e=[],r=0;for(;r<t.length;){let n=Yr(t,r),o=ct.getProtocol(n),s=Ae(n),i=eh(o,t,r+s),a=0;i>0&&o.size===he&&(a=Ae(i));let c=s+a+i,u={code:n,name:o.name,bytes:t.subarray(r,r+c)};if(i>0){let f=r+s+a,l=t.subarray(f,f+i);u.value=o.bytesToValue?.(l)??q(l)}e.push(u),r+=c}return e}function uu(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let o=ct.getProtocol(n.code),s=Ae(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??K(n.value),a=i.byteLength,o.size===he&&(c=Ae(a)));let u=new Uint8Array(s+c+a),f=0;sr(n.code,u,f),f+=s,i!=null&&(o.size===he&&(sr(a,u,f),f+=c),u.set(i,f)),n.bytes=u}r.push(n.bytes),e+=n.bytes.byteLength}return Je(r,e)}function fu(t){if(t.charAt(0)!=="/")throw new be('String multiaddr must start with "/"');let e=[],r="protocol",n="",o="";for(let s=1;s<t.length;s++){let i=t.charAt(s);i!=="/"&&(r==="protocol"?o+=t.charAt(s):n+=t.charAt(s));let a=s===t.length-1;if(i==="/"||a){let c=ct.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new be(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new be(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}e.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new be("Incomplete multiaddr");return e}function lu(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=ct.getProtocol(e.code);if(r==null)throw new be(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function eh(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:Yr(e,r)}var th=Symbol.for("nodejs.util.inspect.custom"),Di=Symbol.for("@multiformats/multiaddr");function rh(t){if(t==null&&(t="/"),du(t))return t.getComponents();if(t instanceof Uint8Array)return cu(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),fu(t);if(Array.isArray(t))return t;throw new be("Must be a string, Uint8Array, Component[], or another Multiaddr")}var io=class t{[Di]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=rh(e),r.validate!==!1&&nh(this)}get bytes(){return this.#r==null&&(this.#r=uu(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=lu(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}encapsulate(e){let r=new t(e);return new t([...this.#e,...r.getComponents()],{validate:!1})}decapsulate(e){let r=e.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new Gn(`Address ${this.toString()} does not contain subaddress: ${r}`);return new t(n.slice(0,o),{validate:!1})}decapsulateCode(e){let r;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){r=n;break}return new t(this.#e.slice(0,r),{validate:!1})}equals(e){return le(this.bytes,e.bytes)}[th](){return`Multiaddr(${this.toString()})`}};function nh(t){t.getComponents().forEach(e=>{let r=ct.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function du(t){return!!t?.[Di]}function kt(t){return new io(t)}var hu="libp2p-peer-record",pu=Uint8Array.from([3,1]);var cn;(function(t){let e;(function(i){let a;i.codec=()=>(a==null&&(a=Me((l,h,d={})=>{d.lengthDelimited!==!1&&h.fork(),l.multiaddr!=null&&l.multiaddr.byteLength>0&&(h.uint32(10),h.bytes(l.multiaddr)),d.lengthDelimited!==!1&&h.ldelim()},(l,h,d={})=>{let m={multiaddr:pe(0)},g=h==null?l.len:l.pos+h;for(;l.pos<g;){let y=l.uint32();y>>>3===1?m.multiaddr=l.bytes():l.skipType(y&7)}return m},function*(l,h,d,m={}){let g=h==null?l.len:l.pos+h;for(;l.pos<g;){let y=l.uint32();y>>>3===1?yield{field:`${d}.multiaddr`,value:l.bytes()}:l.skipType(y&7)}})),a);function c(l){return Ue(l,i.codec())}i.encode=c;function u(l,h){return ke(l,i.codec(),h)}i.decode=u;function f(l,h){return Ke(l,i.codec(),h)}i.stream=f})(e=t.AddressInfo||(t.AddressInfo={}));let r;t.codec=()=>(r==null&&(r=Me((i,a,c={})=>{if(c.lengthDelimited!==!1&&a.fork(),i.peerId!=null&&i.peerId.byteLength>0&&(a.uint32(10),a.bytes(i.peerId)),i.seq!=null&&i.seq!==0n&&(a.uint32(16),a.uint64(i.seq)),i.addresses!=null&&i.addresses.length>0)for(let u of i.addresses)a.uint32(26),t.AddressInfo.codec().encode(u,a);c.lengthDelimited!==!1&&a.ldelim()},(i,a,c={})=>{let u={peerId:pe(0),seq:0n,addresses:[]},f=a==null?i.len:i.pos+a;for(;i.pos<f;){let l=i.uint32();switch(l>>>3){case 1:{u.peerId=i.bytes();break}case 2:{u.seq=i.uint64();break}case 3:{if(c.limits?.addresses!=null&&u.addresses.length===c.limits.addresses)throw new Ye('Decode error - repeated field "addresses" had too many elements');u.addresses.push(t.AddressInfo.codec().decode(i,i.uint32(),{limits:c.limits?.addresses$}));break}default:{i.skipType(l&7);break}}}return u},function*(i,a,c,u={}){let f={addresses:0},l=a==null?i.len:i.pos+a;for(;i.pos<l;){let h=i.uint32();switch(h>>>3){case 1:{yield{field:`${c}.peerId`,value:i.bytes()};break}case 2:{yield{field:`${c}.seq`,value:i.uint64()};break}case 3:{if(u.limits?.addresses!=null&&f.addresses===u.limits.addresses)throw new Ye('Streaming decode error - repeated field "addresses" had too many elements');for(let d of t.AddressInfo.codec().stream(i,i.uint32(),`${c}.addresses[]`,{limits:u.limits?.addresses$}))yield{...d,index:f.addresses};f.addresses++;break}default:{i.skipType(h&7);break}}}})),r);function n(i){return Ue(i,t.codec())}t.encode=n;function o(i,a){return ke(i,t.codec(),a)}t.decode=o;function s(i,a){return Ke(i,t.codec(),a)}t.stream=s})(cn||(cn={}));function mu(t,e){let r=(n,o)=>n.toString().localeCompare(o.toString());return t.length!==e.length?!1:(e.sort(r),t.sort(r).every((n,o)=>e[o].equals(n)))}var qe=class t{static createFromProtobuf=e=>{let r=cn.decode(e),n=ui(Br(r.peerId)),o=(r.addresses??[]).map(i=>kt(i.multiaddr)),s=r.seq;return new t({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=hu;static CODEC=pu;peerId;multiaddrs;seqNumber;domain=t.DOMAIN;codec=t.CODEC;marshaled;constructor(e){let{peerId:r,multiaddrs:n,seqNumber:o}=e;this.peerId=r,this.multiaddrs=n??[],this.seqNumber=o??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=cn.encode({peerId:this.peerId.toMultihash().bytes,seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(e=>({multiaddr:e.bytes}))})),this.marshaled}equals(e){return!(!(e instanceof t)||!this.peerId.equals(e.peerId)||this.seqNumber!==e.seqNumber||!mu(this.multiaddrs,e.multiaddrs))}};function oh(t){let e=t.getComponents(),r={},n=0;return e[n]?.name==="ip6zone"&&(r.zone=`${e[n].value}`,n++),e[n]?.name==="ip4"||e[n]?.name==="ip6"||e[n]?.name==="dns"||e[n]?.name==="dns4"||e[n]?.name==="dns6"?(r.type=e[n].name,r.host=e[n].value,n++):e[n]?.name==="dnsaddr"&&(r.type=e[n].name,r.host=`_dnsaddr.${e[n].value}`,n++),(e[n]?.name==="tcp"||e[n]?.name==="udp")&&(r.protocol=e[n].name==="tcp"?"tcp":"udp",r.port=parseInt(`${e[n].value}`),n++),e[n]?.name==="ipcidr"&&(r.type==="ip4"?r.cidr=parseInt(`${e[n].value}`):r.type==="ip6"&&(r.cidr=`${e[n].value}`),n++),r.type==null||r.host==null?null:(e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(r.sni=e[n+1].value,n+=2),r)}function ao(t){let e=oh(t);if(e==null)throw new Q(`Multiaddr ${t} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}function yu(t,e,r){let n=0;for(let o of t)if(!(n<e)){if(n>r)break;if(o!==255)return!1;n++}return!0}function bu(t,e,r,n){let o=0;for(let s of t)if(!(o<r)){if(o>n)break;if(s!==e[o])return!1;o++}return!0}function Oi(t){switch(t.length){case Ut:return t.join(".");case Kt:{let e=[];for(let r=0;r<t.length;r++)r%2===0&&e.push(t[r].toString(16).padStart(2,"0")+t[r+1].toString(16).padStart(2,"0"));return e.join(":")}default:throw new Error("Invalid ip length")}}function gu(t){let e=0;for(let[r,n]of t.entries()){if(n===255){e+=8;continue}for(;(n&128)!=0;)e++,n=n<<1;if((n&128)!=0)return-1;for(let o=r+1;o<t.length;o++)if(t[o]!=0)return-1;break}return e}function xu(t){let e="0x";for(let r of t)e+=(r>>4).toString(16)+(r&15).toString(16);return e}var Ut=4,Kt=16,Ax=parseInt("0xFFFF",16),sh=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function un(t,e){e.length===Kt&&t.length===Ut&&yu(e,0,11)&&(e=e.slice(12)),e.length===Ut&&t.length===Kt&&bu(t,sh,0,11)&&(t=t.slice(12));let r=t.length;if(r!=e.length)throw new Error("Failed to mask ip");let n=new Uint8Array(r);for(let o=0;o<r;o++)n[o]=t[o]&e[o];return n}function wu(t,e){if(typeof e=="string"&&(e=lr(e)),e==null)throw new Error("Invalid ip");if(e.length!==t.network.length)return!1;for(let r=0;r<e.length;r++)if((t.network[r]&t.mask[r])!==(e[r]&t.mask[r]))return!1;return!0}function Pi(t){let[e,r]=t.split("/");if(!e||!r)throw new Error("Failed to parse given CIDR: "+t);let n=Ut,o=Qn(e);if(o==null&&(n=Kt,o=Jn(e),o==null))throw new Error("Failed to parse given CIDR: "+t);let s=parseInt(r,10);if(Number.isNaN(s)||String(s).length!==r.length||s<0||s>n*8)throw new Error("Failed to parse given CIDR: "+t);let i=Li(s,8*n);return{network:un(o,i),mask:i}}function Li(t,e){if(e!==8*Ut&&e!==8*Kt)throw new Error("Invalid CIDR mask");if(t<0||t>e)throw new Error("Invalid CIDR mask");let r=e/8,n=new Uint8Array(r);for(let o=0;o<r;o++){if(t>=8){n[o]=255,t-=8;continue}n[o]=255-(255>>t),t=0}return n}var fn=class{constructor(e,r){if(r==null)({network:this.network,mask:this.mask}=Pi(e));else{let n=lr(e);if(n==null)throw new Error("Failed to parse network");r=String(r);let o=parseInt(r,10);if(Number.isNaN(o)||String(o).length!==r.length||o<0||o>n.length*8){let s=lr(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Li(o,8*n.length);this.network=un(n,this.mask)}}contains(e){return wu({network:this.network,mask:this.mask},e)}toString(){let e=gu(this.mask),r=e!==-1?String(e):xu(this.mask);return Oi(this.network)+"/"+r}};function Eu(t,e){return new fn(t).contains(e)}function vu(t){try{let e=ao(t);return e.type==="ip6"?Eu("2000::/3",e.host):!1}catch{return!1}}var _u=Ju(Au(),1),dh=["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"],hh=dh.map(t=>new _u.Netmask(t));function Mi(t){for(let e of hh)if(e.contains(t))return!0;return!1}function ph(t){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(t)}function mh(t){let e=t.split(":");if(e.length<2)return!1;let r=e[e.length-1].padStart(4,"0"),n=e[e.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(r.substring(0,2),16)}.${parseInt(r.substring(2),16)}`;return Mi(o)}function yh(t){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)}function bh(t){let e=t.split(":"),r=e[e.length-1];return Mi(r)}function gh(t){return/^::$/.test(t)||/^::1$/.test(t)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(t)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(t)||/^ff([0-9a-fA-F]{2,2}):/i.test(t)}function Cu(t){if(dr(t))return Mi(t);if(ph(t))return mh(t);if(yh(t))return bh(t);if(eo(t))return gh(t)}function Tu(t){try{let e=ao(t);switch(e.type){case"ip4":case"ip6":return Cu(e.host)??!1;default:return e.host==="localhost"}}catch{return!1}}var G=t=>({match:e=>{let r=e[0];return r==null||r.code!==t||r.value!=null?!1:e.slice(1)}}),L=(t,e)=>({match:r=>{let n=r[0];return n?.code!==t||n.value==null||e!=null&&n.value!==e?!1:r.slice(1)}}),Bu=t=>({match:e=>t.match(e)===!1?e:!1}),M=t=>({match:e=>{let r=t.match(e);return r===!1?e:r}}),we=(...t)=>({match:e=>{let r;for(let n of t){let o=n.match(e);o!==!1&&(r==null||o.length<r.length)&&(r=o)}return r??!1}}),$=(...t)=>({match:e=>{for(let r of t){let n=r.match(e);if(n===!1)return!1;e=n}return e}});function W(...t){function e(o){if(o==null)return!1;let s=o.getComponents();for(let i of t){let a=i.match(s);if(a===!1)return!1;s=a}return s}function r(o){return e(o)!==!1}function n(o){let s=e(o);return s===!1?!1:s.length===0}return{matchers:t,matches:r,exactMatch:n}}var xh=L(421),nw=W(xh),fo=L(54),lo=L(55),ho=L(56),qi=L(53),ow=W(fo,M(L(421))),sw=W(lo,M(L(421))),iw=W(ho,M(L(421))),aw=W(we(qi,ho,fo,lo),M(L(421))),Du=$(L(4),M(L(43))),Ou=$(M(L(42)),L(41),M(L(43))),Hi=we(Du,Ou),Er=we(Hi,qi,fo,lo,ho),Pu=W(we(Hi,$(we(qi,ho,fo,lo),M(L(421))))),cw=W(Du),uw=W(Ou),fw=W(Hi),zi=$(Er,L(6)),ln=$(Er,L(273)),Lu=W($(zi,M(L(421)))),lw=W(ln),$i=$(ln,G(460),M(L(421))),po=$(ln,G(461),M(L(421))),wh=we($i,po),dw=W($i),hw=W(po),Vi=we(Er,zi,ln,$i,po),Ru=we($(Vi,G(477),M(L(421)))),pw=W(Ru),Fu=we($(Vi,G(478),M(L(421))),$(Vi,G(448),M(L(449)),G(477),M(L(421)))),mw=W(Fu),Nu=$(ln,G(280),M(L(466)),M(L(466)),M(L(421))),yw=W(Nu),ku=$(po,G(465),M(L(466)),M(L(466)),M(L(421))),bw=W(ku),uo=we(Ru,Fu,$(zi,M(L(421))),$(wh,M(L(421))),$(Er,M(L(421))),Nu,ku,L(421)),gw=W(uo),Eh=$(M(uo),G(290),Bu(G(281)),M(L(421))),xw=W(Eh),vh=we($(uo,G(290),G(281),M(L(421))),$(uo,G(281),M(L(421))),$(G(281),M(L(421)))),ww=W(vh),Sh=$(Er,we($(L(6,"80")),$(L(6),G(480)),G(480)),M(L(481)),M(L(421))),Ew=W(Sh),Ih=$(Er,we($(L(6,"443")),$(L(6,"443"),G(480)),$(L(6),G(443)),$(L(6),G(448),G(480)),$(G(448),G(480)),G(448),G(443)),M(L(481)),M(L(421))),vw=W(Ih),Ah=we($(L(777),M(L(421)))),Sw=W(Ah),_h=we($(L(400),M(L(421)))),Iw=W(_h);function vr(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var ji=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},Uu=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function Yi(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=e,a,c,f=new Promise((l,h)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){h(Uu(i));return}if(i&&(c=()=>{h(Uu(i))},i.addEventListener("abort",c,{once:!0})),t.then(l,h),r===Number.POSITIVE_INFINITY)return;let d=new ji;a=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(m){h(m)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?l():o instanceof Error?h(o):(d.message=o??`Promise timed out after ${r} milliseconds`,h(d))},r)}).finally(()=>{f.clear(),c&&i&&i.removeEventListener("abort",c)});return f.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},f}var Ch=t=>{let e=t.addEventListener||t.on||t.addListener,r=t.removeEventListener||t.off||t.removeListener;if(!e||!r)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(t),removeListener:r.bind(t)}};function Th(t,e,r){let n,o=new Promise((s,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:u,removeListener:f}=Ch(t),l=async(...d)=>{let m=r.multiArgs?d:d[0];if(r.filter)try{if(!await r.filter(m))return}catch(g){n(),i(g);return}c.push(m),r.count===c.length&&(n(),s(c))},h=(...d)=>{n(),i(r.rejectionMultiArgs?d:d[0])};n=()=>{for(let d of a)f(d,l);for(let d of r.rejectionEvents)a.includes(d)||f(d,h)};for(let d of a)u(d,l);for(let d of r.rejectionEvents)a.includes(d)||u(d,h);r.signal&&r.signal.addEventListener("abort",()=>{h(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(c)});if(o.cancel=n,typeof r.timeout=="number"){let s=Yi(o,{milliseconds:r.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function Ku(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Th(t,e,r),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function Mu(t,e){let r,n=function(){let o=function(){r=void 0,t()};clearTimeout(r),r=setTimeout(o,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var Vt=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Bh(t){return t.reason}async function Zi(t,e,r){if(e==null)return t;let n=r?.translateError??Bh;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([t,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var Oh=4194304,mo=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Wi=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Xi=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Qi=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Ph(t){return typeof t?.closeRead=="function"}function Lh(t){return typeof t?.close=="function"}function Gi(t){return Ph(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:Lh(t)?t.status!=="open":!1}function Rh(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function Fh(t,e){let r=e?.maxBufferSize??Oh,n=new se,o,s=!1;if(!Rh(t))throw new Q("Argument should be a Stream or a Multiaddr");let i=f=>{if(n.append(f.data),n.byteLength>r){let l=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${l} > ${r}`))}o?.resolve()};t.addEventListener("message",i);let a=f=>{f.error!=null?o?.reject(f.error):o?.resolve()};t.addEventListener("close",a);let c=()=>{o?.resolve()};t.addEventListener("remoteCloseWrite",c);let u={readBuffer:n,async read(f){if(s===!0)throw new mo("Stream was unwrapped");if(Gi(t)){if(n.byteLength===0&&f?.bytes==null)return null;if(f?.bytes!=null&&n.byteLength<f.bytes)throw t.log.error("closed after reading %d/%d bytes",n.byteLength,f.bytes),new Vt(`Unexpected EOF - stream closed after reading ${n.byteLength}/${f.bytes} bytes`)}let l=f?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=l){o.resolve();break}if(await Zi(o.promise,f?.signal),Gi(t)){if(n.byteLength===0&&f?.bytes==null)return null;break}o=Promise.withResolvers()}let h=f?.bytes??n.byteLength;if(n.byteLength<h){if(Gi(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,h),new Vt(`Unexpected EOF - stream closed while reading ${n.byteLength}/${h} bytes`);return u.read(f)}let d=n.sublist(0,h);return n.consume(h),d},async write(f,l){if(s===!0)throw new mo("Stream was unwrapped");t.send(f)||await Ku(t,"drain",{signal:l?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,t.removeEventListener("message",i),t.removeEventListener("close",a),t.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.unshift(n))),t}};return u}function Nh(t,e={}){let r=Fh(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Ae(e.maxDataLength));let n=e?.lengthDecoder??Yr,o=e?.lengthEncoder??ir;return{async read(i){let a=-1,c=new se;for(;;){let f=await r.read({...i,bytes:1});if(f==null)break;c.append(f);try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new Wi("Invalid message length");if(e?.maxLengthLength!=null&&c.byteLength>e.maxLengthLength)throw new Qi(`Message length length too long - ${c.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new Xi(`Message length too long - ${a} > ${e.maxDataLength}`);let u=await r.read({...i,bytes:a});if(u==null)throw t.log.error("tried to read %d bytes but the stream closed",a),new Vt(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw t.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new Vt(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(i,a){await r.write(new se(o(i.byteLength),i),a)},async writeV(i,a){let c=new se(...i.flatMap(u=>[o(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}function Sr(t,e){let r=Nh(t,e),n={read:async(o,s)=>{let i=await r.read(s);return o.decode(i)},write:async(o,s,i)=>{await r.write(s.encode(o),i)},writeV:async(o,s,i)=>{await r.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}function kh(t){return t[Symbol.asyncIterator]!=null}function Uh(t){if(kh(t))return(async()=>{for await(let e of t);})();for(let e of t);}var Vu=Uh;var yo=globalThis.CustomEvent??Event;async function*Ji(t,e={}){let r=e.concurrency??1/0;r<1&&(r=1/0);let n=e.ordered??!1,o=new EventTarget,s=[],i=vr(),a=vr(),c=!1,u,f=!1;o.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let m of t){if(s.length===r&&(i=vr(),await i.promise),f)break;let g={done:!1};s.push(g),m().then(y=>{g.done=!0,g.ok=!0,g.value=y,o.dispatchEvent(new yo("task-complete"))},y=>{g.done=!0,g.err=y,o.dispatchEvent(new yo("task-complete"))})}c=!0,o.dispatchEvent(new yo("task-complete"))}catch(m){u=m,o.dispatchEvent(new yo("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 f=!0,i.resolve(),m.err;i.resolve()}}function*d(){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()||(a=vr(),await a.promise),u!=null||(n?yield*h():yield*d(),u!=null))throw u;if(c&&s.length===0)break}}var qu="0.1.0";var Hu="id/push",zu="1.0.0",$u="1.0.0";var St;(function(t){let e;t.codec=()=>(e==null&&(e=Me((s,i,a={})=>{if(a.lengthDelimited!==!1&&i.fork(),s.protocolVersion!=null&&(i.uint32(42),i.string(s.protocolVersion)),s.agentVersion!=null&&(i.uint32(50),i.string(s.agentVersion)),s.publicKey!=null&&(i.uint32(10),i.bytes(s.publicKey)),s.listenAddrs!=null&&s.listenAddrs.length>0)for(let c of s.listenAddrs)i.uint32(18),i.bytes(c);if(s.observedAddr!=null&&(i.uint32(34),i.bytes(s.observedAddr)),s.protocols!=null&&s.protocols.length>0)for(let c of s.protocols)i.uint32(26),i.string(c);s.signedPeerRecord!=null&&(i.uint32(66),i.bytes(s.signedPeerRecord)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={listenAddrs:[],protocols:[]},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let f=s.uint32();switch(f>>>3){case 5:{c.protocolVersion=s.string();break}case 6:{c.agentVersion=s.string();break}case 1:{c.publicKey=s.bytes();break}case 2:{if(a.limits?.listenAddrs!=null&&c.listenAddrs.length===a.limits.listenAddrs)throw new Ye('Decode error - repeated field "listenAddrs" had too many elements');c.listenAddrs.push(s.bytes());break}case 4:{c.observedAddr=s.bytes();break}case 3:{if(a.limits?.protocols!=null&&c.protocols.length===a.limits.protocols)throw new Ye('Decode error - repeated field "protocols" had too many elements');c.protocols.push(s.string());break}case 8:{c.signedPeerRecord=s.bytes();break}default:{s.skipType(f&7);break}}}return c},function*(s,i,a,c={}){let u={listenAddrs:0,protocols:0},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let l=s.uint32();switch(l>>>3){case 5:{yield{field:`${a}.protocolVersion`,value:s.string()};break}case 6:{yield{field:`${a}.agentVersion`,value:s.string()};break}case 1:{yield{field:`${a}.publicKey`,value:s.bytes()};break}case 2:{if(c.limits?.listenAddrs!=null&&u.listenAddrs===c.limits.listenAddrs)throw new Ye('Streaming decode error - repeated field "listenAddrs" had too many elements');yield{field:`${a}.listenAddrs[]`,index:u.listenAddrs,value:s.bytes()},u.listenAddrs++;break}case 4:{yield{field:`${a}.observedAddr`,value:s.bytes()};break}case 3:{if(c.limits?.protocols!=null&&u.protocols===c.limits.protocols)throw new Ye('Streaming decode error - repeated field "protocols" had too many elements');yield{field:`${a}.protocols[]`,index:u.protocols,value:s.string()},u.protocols++;break}case 8:{yield{field:`${a}.signedPeerRecord`,value:s.bytes()};break}default:{s.skipType(l&7);break}}}})),e);function r(s){return Ue(s,t.codec())}t.encode=r;function n(s,i){return ke(s,t.codec(),i)}t.decode=n;function o(s,i){return Ke(s,t.codec(),i)}t.stream=o})(St||(St={}));var _e={protocolPrefix:"ipfs",timeout:5e3,maxInboundStreams:1,maxOutboundStreams:1,maxObservedAddresses:10,maxMessageSize:8192,runOnConnectionOpen:!0,runOnSelfUpdate:!0,runOnLimitedConnection:!0,concurrency:32};function Yu(t){if(t!=null&&t.length>0)try{return kt(t)}catch{}}async function bo(t,e,r,n,o){if(r("received identify from %p",n.remotePeer),o==null)throw new De("message was null or undefined");let s={};if(o.listenAddrs.length>0&&(s.addresses=o.listenAddrs.map(c=>({isCertified:!1,multiaddr:kt(c)}))),o.protocols.length>0&&(s.protocols=o.protocols),o.publicKey!=null){let c=ur(o.publicKey);if(!Qc(c).equals(n.remotePeer))throw new De("public key did not match remote PeerId");s.publicKey=c}let i;if(o.signedPeerRecord!=null){r.trace("received signedPeerRecord from %p",n.remotePeer);let c=o.signedPeerRecord,u=await We.openAndCertify(c,qe.DOMAIN),f=qe.createFromProtobuf(u.payload),l=Zn(u.publicKey.toCID());if(!f.peerId.equals(l))throw new De("signing key does not match PeerId in the PeerRecord");if(!n.remotePeer.equals(f.peerId))throw new De("signing key does not match remote PeerId");let h;try{h=await t.get(f.peerId)}catch(d){if(d.name!=="NotFoundError")throw d}if(h!=null&&(s.metadata=h.metadata,h.peerRecordEnvelope!=null)){let d=We.createFromProtobuf(h.peerRecordEnvelope),m=qe.createFromProtobuf(d.payload);m.seqNumber>=f.seqNumber&&(r("sequence number was lower or equal to existing sequence number - stored: %d received: %d",m.seqNumber,f.seqNumber),f=m,c=h.peerRecordEnvelope)}s.peerRecordEnvelope=c,s.addresses=f.multiaddrs.map(d=>({isCertified:!0,multiaddr:d})),i={seq:f.seqNumber,addresses:f.multiaddrs}}else r("%p did not send a signed peer record",n.remotePeer);if(r.trace("patching %p with",n.remotePeer,s),await t.patch(n.remotePeer,s),o.agentVersion!=null||o.protocolVersion!=null){let c={};o.agentVersion!=null&&(c.AgentVersion=K(o.agentVersion)),o.protocolVersion!=null&&(c.ProtocolVersion=K(o.protocolVersion)),r.trace("merging %p metadata",n.remotePeer,c),await t.merge(n.remotePeer,{metadata:c})}let a={peerId:n.remotePeer,protocolVersion:o.protocolVersion,agentVersion:o.agentVersion,publicKey:o.publicKey,listenAddrs:o.listenAddrs.map(c=>kt(c)),observedAddr:o.observedAddr==null?void 0:kt(o.observedAddr),protocols:o.protocols,signedPeerRecord:i,connection:n};return e.safeDispatchEvent("peer:identify",{detail:a}),a}function go(t){let e={...t[0]};for(let r of t.slice(1))r.protocolVersion!=null&&(e.protocolVersion=r.protocolVersion),r.agentVersion!=null&&(e.agentVersion=r.agentVersion),r.publicKey!=null&&(e.publicKey=r.publicKey),r.observedAddr!=null&&(e.observedAddr=r.observedAddr),r.signedPeerRecord!=null&&(e.signedPeerRecord=r.signedPeerRecord),e.listenAddrs=[...e.listenAddrs,...r.listenAddrs],e.protocols=[...new Set([...e.protocols,...r.protocols])];return e}async function xo(t,e,r,n){let o=Sr(t,{maxDataLength:e}).pb(St),s=[];for(let i=0;i<10;i++)try{s.push(await o.read(r))}catch(a){if(s.length===0)throw a;n.trace("stopped reading identify - %e",a);break}s.length>=10&&n("reached MAX_IDENTIFY_MESSAGES, returning truncated identify");try{await t.close(r)}catch(i){n.trace("error closing identify stream after read - %e",i),t.abort(i)}return s}var Ir=class{host;components;protocol;started;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxObservedAddresses;runOnLimitedConnection;log;constructor(e,r){this.protocol=r.protocol,this.started=!1,this.components=e,this.log=r.log,this.timeout=r.timeout??_e.timeout,this.maxInboundStreams=r.maxInboundStreams??_e.maxInboundStreams,this.maxOutboundStreams=r.maxOutboundStreams??_e.maxOutboundStreams,this.maxMessageSize=r.maxMessageSize??_e.maxMessageSize,this.maxObservedAddresses=r.maxObservedAddresses??_e.maxObservedAddresses,this.runOnLimitedConnection=r.runOnLimitedConnection??_e.runOnLimitedConnection,this.host={protocolVersion:`${r.protocolPrefix??_e.protocolPrefix}/${qu}`,agentVersion:e.nodeInfo.userAgent},this.handleProtocol=this.handleProtocol.bind(this)}isStarted(){return this.started}async start(){this.started||(await this.components.peerStore.merge(this.components.peerId,{metadata:{AgentVersion:K(this.host.agentVersion),ProtocolVersion:K(this.host.protocolVersion)}}),await this.components.registrar.handle(this.protocol,this.handleProtocol,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams,runOnLimitedConnection:this.runOnLimitedConnection}),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.protocol),this.started=!1}};var wo=class extends Ir{connectionManager;concurrency;_push;constructor(e,r={}){super(e,{...r,protocol:`/${r.protocolPrefix??_e.protocolPrefix}/${Hu}/${$u}`,log:e.logger.forComponent("libp2p:identify-push")}),this.connectionManager=e.connectionManager,this.concurrency=r.concurrency??_e.concurrency,this._push=Mu(this.sendPushMessage.bind(this),r.debounce??1e3),(r.runOnSelfUpdate??_e.runOnSelfUpdate)&&e.events.addEventListener("self:peer:update",n=>{this.push().catch(o=>{this.log.error("error pushing updates to peers - %e",o)})})}[yn]=["@libp2p/identify-push"];async push(){this._push()}async sendPushMessage(){if(this.isStarted())try{let e=this.components.addressManager.getAddresses().map(f=>f.decapsulateCode(421)),r=new qe({peerId:this.components.peerId,multiaddrs:e}),n=await We.seal(r,this.components.privateKey),o=this.components.registrar.getProtocols(),s=await this.components.peerStore.get(this.components.peerId),i=q(s.metadata.get("AgentVersion")??K(this.host.agentVersion)),a=q(s.metadata.get("ProtocolVersion")??K(this.host.protocolVersion)),c=this;async function*u(){for(let f of c.connectionManager.getConnections())(await c.components.peerStore.get(f.remotePeer)).protocols.includes(c.protocol)&&(yield async()=>{let h,d=AbortSignal.timeout(c.timeout);try{h=await f.newStream(c.protocol,{signal:d,runOnLimitedConnection:c.runOnLimitedConnection}),await Sr(h,{maxDataLength:c.maxMessageSize}).pb(St).write({listenAddrs:e.map(g=>g.bytes),signedPeerRecord:n.marshal(),protocols:o,agentVersion:i,protocolVersion:a},{signal:d}),await h.close({signal:d})}catch(m){h?.log.newScope("identify-push")?.error("could not push identify update to peer",m),h?.abort(m)}})}await Vu(Ji(u(),{concurrency:this.concurrency}))}catch(e){this.log.error("error pushing updates to peers - %e",e)}}async handleProtocol(e,r){let n=e.log.newScope("identify-push");if(this.components.peerId.equals(r.remotePeer))throw new Error("received push from ourselves?");let o={signal:AbortSignal.timeout(this.timeout)},s=await xo(e,this.maxMessageSize,o,n);await bo(this.components.peerStore,this.components.events,n,r,go(s)),n.trace("handled push from %p",r.remotePeer)}};var Eo=class extends Ir{constructor(e,r={}){super(e,{...r,protocol:`/${r.protocolPrefix??_e.protocolPrefix}/${"id"}/${zu}`,log:e.logger.forComponent("libp2p:identify")}),(r.runOnConnectionOpen??_e.runOnConnectionOpen)&&e.events.addEventListener("connection:open",n=>{let o=n.detail;this.identify(o).catch(()=>{})})}[yn]=["@libp2p/identify"];async _identify(e,r={}){let n,o;if(r.signal==null){let s=AbortSignal.timeout(this.timeout);r={...r,signal:s}}this.log("run identify on new connection %a",e.remoteAddr);try{n=await e.newStream(this.protocol,{...r,runOnLimitedConnection:this.runOnLimitedConnection}),o=n.log.newScope("identify");let s=await xo(n,this.maxMessageSize,r,o);return go(s)}catch(s){throw o?.error("identify failed - %e",s),n?.abort(s),s}}async identify(e,r={}){let n=await this._identify(e,r),{publicKey:o,protocols:s,observedAddr:i}=n;if(o==null)throw new De("Public key was missing from identify message");let a=ur(o),c=Zn(a.toCID());if(!e.remotePeer.equals(c))throw new De("Identified peer does not match the expected peer");if(this.components.peerId.equals(c))throw new De("Identified peer is our own peer id?");return this.maybeAddObservedAddress(i),this.log("completed for peer %p and protocols %o",c,s),bo(this.components.peerStore,this.components.events,this.log,e,n)}maybeAddObservedAddress(e){let r=Yu(e);if(r==null||(this.log.trace("our observed address was %a",r),Tu(r)))return;let n=r.getComponents();if((n[0].code===41||n[0].code===42&&n[1].code===41)&&!vu(r)){this.log.trace("our observed address was IPv6 but not a global unicast address");return}Lu.exactMatch(r)||(this.log.trace("storing the observed address"),this.components.addressManager.addObservedAddr(r))}async handleProtocol(e,r){let n=e.log.newScope("identify");n("responding to identify");let o=AbortSignal.timeout(this.timeout);let s=await this.components.peerStore.get(this.components.peerId,{signal:o}),i=this.components.addressManager.getAddresses().map(f=>f.decapsulateCode(421)),a=s.peerRecordEnvelope;if(i.length>0&&a==null){let f=new qe({peerId:this.components.peerId,multiaddrs:i});a=(await We.seal(f,this.components.privateKey,{signal:o})).marshal().subarray()}let c=r.remoteAddr.bytes;Pu.matches(r.remoteAddr)||(c=void 0);let u=Sr(e).pb(St);n("send response"),await u.write({protocolVersion:this.host.protocolVersion,agentVersion:this.host.agentVersion,publicKey:ze(this.components.privateKey.publicKey),listenAddrs:i.map(f=>f.bytes),signedPeerRecord:a,observedAddr:c,protocols:s.protocols},{signal:o}),n("close write"),await u.unwrap().unwrap().close({signal:o})}};function Hh(t={}){return e=>new Eo(e,t)}function zh(t={}){return e=>new wo(e,t)}return ef($h);})();
|
|
2
|
+
"use strict";var Libp2PIdentify=(()=>{var Gu=Object.create;var hn=Object.defineProperty;var Wu=Object.getOwnPropertyDescriptor;var Xu=Object.getOwnPropertyNames;var Qu=Object.getPrototypeOf,Ju=Object.prototype.hasOwnProperty;var vo=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),ve=(t,e)=>{for(var r in e)hn(t,r,{get:e[r],enumerable:!0})},na=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Xu(e))!Ju.call(t,o)&&o!==r&&hn(t,o,{get:()=>e[o],enumerable:!(n=Wu(e,o))||n.enumerable});return t};var ef=(t,e,r)=>(r=t!=null?Gu(Qu(t)):{},na(e||!t||!t.__esModule?hn(r,"default",{value:t,enumerable:!0}):r,t)),tf=t=>na(hn({},"__esModule",{value:!0}),t);var Fi=vo(gr=>{"use strict";Object.defineProperty(gr,"__esModule",{value:!0});gr.Netmask4Impl=void 0;gr.ip2long=br;gr.long2ip=Xe;function Xe(t){let e=(t&-16777216)>>>24,r=(t&255<<16)>>>16,n=(t&65280)>>>8,o=t&255;return[e,r,n,o].join(".")}var ah=48,ch=97,uh=65;function fh(t){let e=0,r=10,n="9",o=0;t.length>1&&t[o]==="0"&&(t[o+1]==="x"||t[o+1]==="X"?(o+=2,r=16):"0"<=t[o+1]&&t[o+1]<="9"&&(o++,r=8,n="7"));let s=o;for(;o<t.length;){if("0"<=t[o]&&t[o]<=n)e=e*r+(t.charCodeAt(o)-ah)>>>0;else if(r===16)if("a"<=t[o]&&t[o]<="f")e=e*r+(10+t.charCodeAt(o)-ch)>>>0;else if("A"<=t[o]&&t[o]<="F")e=e*r+(10+t.charCodeAt(o)-uh)>>>0;else break;else break;if(e>4294967295)throw new Error("too large");o++}if(o===s)throw new Error("empty octet");return[e,o]}function br(t){let e=[];for(let r=0;r<=3&&t.length!==0;r++){if(r>0){if(t[0]!==".")throw new Error("Invalid IP");t=t.substring(1)}let[n,o]=fh(t);t=t.substring(o),e.push(n)}if(t.length!==0)throw new Error("Invalid IP");switch(e.length){case 1:if(e[0]>4294967295)throw new Error("Invalid IP");return e[0]>>>0;case 2:if(e[0]>255||e[1]>16777215)throw new Error("Invalid IP");return(e[0]<<24|e[1])>>>0;case 3:if(e[0]>255||e[1]>255||e[2]>65535)throw new Error("Invalid IP");return(e[0]<<24|e[1]<<16|e[2])>>>0;case 4:if(e[0]>255||e[1]>255||e[2]>255||e[3]>255)throw new Error("Invalid IP");return(e[0]<<24|e[1]<<16|e[2]<<8|e[3])>>>0;default:throw new Error("Invalid IP")}}var Ri=class t{constructor(e,r){if(typeof e!="string")throw new Error("Missing `net' parameter");let n=r;if(!n){let o=e.split("/",2);e=o[0],n=o[1]}if(n||(n=32),typeof n=="string"&&n.indexOf(".")>-1){try{this.maskLong=br(n)}catch{throw new Error("Invalid mask: "+n)}this.bitmask=NaN;for(let o=32;o>=0;o--)if(this.maskLong===4294967295<<32-o>>>0){this.bitmask=o;break}}else if(n||n===0)this.bitmask=parseInt(n,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(br(e)&this.maskLong)>>>0}catch{throw new Error("Invalid net address: "+e)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+n);this.size=Math.pow(2,32-this.bitmask),this.base=Xe(this.netLong),this.mask=Xe(this.maskLong),this.hostmask=Xe(~this.maskLong),this.first=this.bitmask<=30?Xe(this.netLong+1):this.base,this.last=this.bitmask<=30?Xe(this.netLong+this.size-2):Xe(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?Xe(this.netLong+this.size-1):void 0}contains(e){return typeof e=="string"&&(e.indexOf("/")>0||e.split(".").length!==4)&&(e=new t(e)),e instanceof t?this.contains(e.base)&&this.contains(e.broadcast||e.last):(br(e)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(e=1){return new t(Xe(this.netLong+this.size*e),this.mask)}forEach(e){let r=br(this.first),n=br(this.last),o=0;for(;r<=n;)e(Xe(r),r,o),o++,r++}toString(){return this.base+"/"+this.bitmask}};gr.Netmask4Impl=Ri});var Au=vo(xr=>{"use strict";Object.defineProperty(xr,"__esModule",{value:!0});xr.Netmask6Impl=void 0;xr.ip6bigint=ki;xr.bigint2ip6=Kt;var lh=Fi(),Ni=(1n<<128n)-1n;function ki(t){let e=t.indexOf("%");e!==-1&&(t=t.substring(0,e));let r=t.lastIndexOf(":");if(r!==-1&&t.indexOf(".",r)!==-1){let n=t.substring(r+1),o=(0,lh.ip2long)(n),s=t.substring(0,r+1)+"0:0";return Iu(s)&~0xffffffffn|BigInt(o)}return Iu(t)}function Iu(t){let e=t.indexOf("::"),r;if(e!==-1){let o=t.substring(0,e),s=t.substring(e+2),i=o===""?[]:o.split(":"),a=s===""?[]:s.split(":"),u=8-i.length-a.length;if(u<0)throw new Error("Invalid IPv6: too many groups");r=[...i,...Array(u).fill("0"),...a]}else r=t.split(":");if(r.length!==8)throw new Error("Invalid IPv6: expected 8 groups, got "+r.length);let n=0n;for(let o=0;o<8;o++){let s=r[o];if(s.length===0||s.length>4)throw new Error('Invalid IPv6: bad group "'+s+'"');let i=parseInt(s,16);if(isNaN(i)||i<0||i>65535)throw new Error('Invalid IPv6: bad group "'+s+'"');n=n<<16n|BigInt(i)}return n}function Kt(t){if(t<0n||t>Ni)throw new Error("Invalid IPv6 address value");let e=[];for(let i=0;i<8;i++)e.unshift(Number(t&0xffffn)),t>>=16n;let r=-1,n=0,o=-1,s=0;for(let i=0;i<8;i++)e[i]===0?o===-1?(o=i,s=1):s++:(s>n&&s>=2&&(r=o,n=s),o=-1,s=0);if(s>n&&s>=2&&(r=o,n=s),r!==-1&&r+n===8&&r>0)return e.slice(0,r).map(a=>a.toString(16)).join(":")+"::";if(r===0)return"::"+e.slice(n).map(a=>a.toString(16)).join(":");if(r>0){let i=e.slice(0,r).map(u=>u.toString(16)),a=e.slice(r+n).map(u=>u.toString(16));return i.join(":")+"::"+a.join(":")}else return e.map(i=>i.toString(16)).join(":")}var Ui=class t{constructor(e,r){if(typeof e!="string")throw new Error("Missing `net' parameter");let n=r;if(n==null){let o=e.indexOf("/");o!==-1?(n=parseInt(e.substring(o+1),10),e=e.substring(0,o)):n=128}if(isNaN(n)||n<0||n>128)throw new Error("Invalid mask for IPv6: "+n);this.bitmask=n,this.bitmask===0?this.maskBigint=0n:this.maskBigint=Ni>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=ki(e)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+e)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=Kt(this.netBigint),this.mask=Kt(this.maskBigint),this.hostmask=Kt(~this.maskBigint&Ni),this.first=this.base,this.last=Kt(this.netBigint+(1n<<BigInt(128-this.bitmask))-1n),this.broadcast=void 0}contains(e){return typeof e=="string"&&e.indexOf("/")>0&&(e=new t(e)),e instanceof t?this.contains(e.base)&&this.contains(e.last):(ki(e)&this.maskBigint)===this.netBigint}next(e=1){let r=1n<<BigInt(128-this.bitmask);return new t(Kt(this.netBigint+r*BigInt(e)),this.bitmask)}forEach(e){let r=this.netBigint,n=1n<<BigInt(128-this.bitmask),o=this.netBigint+n-1n,s=0;for(;r<=o;)e(Kt(r),Number(r),s),s++,r++}toString(){return this.base+"/"+this.bitmask}};xr.Netmask6Impl=Ui});var _u=vo(vt=>{"use strict";Object.defineProperty(vt,"__esModule",{value:!0});vt.long2ip=vt.ip2long=vt.Netmask=void 0;var co=Fi();Object.defineProperty(vt,"ip2long",{enumerable:!0,get:function(){return co.ip2long}});Object.defineProperty(vt,"long2ip",{enumerable:!0,get:function(){return co.long2ip}});var dh=Au(),Ki=class t{constructor(e,r){if(typeof e!="string")throw new Error("Missing `net' parameter");(e.indexOf("/")!==-1?e.substring(0,e.indexOf("/")):e).indexOf(":")!==-1?this._impl=new dh.Netmask6Impl(e,r):this._impl=new co.Netmask4Impl(e,r),this.base=this._impl.base,this.mask=this._impl.mask,this.hostmask=this._impl.hostmask,this.bitmask=this._impl.bitmask,this.size=this._impl.size,this.first=this._impl.first,this.last=this._impl.last,this.broadcast=this._impl.broadcast,this._impl instanceof co.Netmask4Impl?(this.maskLong=this._impl.maskLong,this.netLong=this._impl.netLong):(this.maskLong=0,this.netLong=0)}contains(e){return typeof e=="string"&&(e.indexOf("/")>0?e=new t(e):e.indexOf(":")===-1&&e.split(".").length!==4&&(e=new t(e))),e instanceof t?this.contains(e.base)&&this.contains(e.broadcast||e.last):this._impl.contains(e)}next(e=1){let r=this._impl.next(e);return new t(r.base,r.bitmask)}forEach(e){this._impl.forEach(e)}toString(){return this._impl.toString()}};vt.Netmask=Ki});var jh={};ve(jh,{identify:()=>zh,identifyPush:()=>$h});var Q=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},qt=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var pn=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},mn=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var De=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var It=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var So=Symbol.for("@libp2p/peer-id");var yn=Symbol.for("@libp2p/service-capabilities");var To={};ve(To,{base58btc:()=>ne,base58flickr:()=>uf});var Ep=new Uint8Array(0);function oa(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Qe(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function sa(t){return new TextEncoder().encode(t)}function ia(t){return new TextDecoder().decode(t)}function rf(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var s=t.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=t.length,u=t.charAt(0),c=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);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 b=0,y=0,E=0,S=m.length;E!==S&&m[E]===0;)E++,b++;for(var A=(S-E)*f+1>>>0,O=new Uint8Array(A);E!==S;){for(var B=m[E],F=0,P=A-1;(B!==0||F<y)&&P!==-1;P--,F++)B+=256*O[P]>>>0,O[P]=B%a>>>0,B=B/a>>>0;if(B!==0)throw new Error("Non-zero carry");y=F,E++}for(var C=A-y;C!==A&&O[C]===0;)C++;for(var N=u.repeat(b);C<A;++C)N+=t.charAt(O[C]);return N}function h(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var b=0;if(m[b]!==" "){for(var y=0,E=0;m[b]===u;)y++,b++;for(var S=(m.length-b)*c+1>>>0,A=new Uint8Array(S);m[b];){var O=r[m.charCodeAt(b)];if(O===255)return;for(var B=0,F=S-1;(O!==0||B<E)&&F!==-1;F--,B++)O+=a*A[F]>>>0,A[F]=O%256>>>0,O=O/256>>>0;if(O!==0)throw new Error("Non-zero carry");E=B,b++}if(m[b]!==" "){for(var P=S-E;P!==S&&A[P]===0;)P++;for(var C=new Uint8Array(y+(S-P)),N=y;P!==S;)C[N++]=A[P++];return C}}}function d(m){var b=h(m);if(b)return b;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:h,decode:d}}var nf=rf,of=nf,ca=of;var Io=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Ao=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return ua(this,e)}},_o=class{decoders;constructor(e){this.decoders=e}or(e){return ua(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function ua(t,e){return new _o({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Co=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Io(e,r,n),this.decoder=new Ao(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Ht({name:t,prefix:e,encode:r,decode:n}){return new Co(t,e,r,n)}function ut({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=ca(r,t);return Ht({prefix:e,name:t,encode:n,decode:s=>Qe(o(s))})}function sf(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,u=0;for(let c=0;c<o;++c){let f=e[t[c]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,s[u++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function af(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let u=0;u<t.length;++u)for(a=a<<8|t[u],i+=8;i>r;)i-=r,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function cf(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function ee({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=cf(n);return Ht({prefix:e,name:t,encode(s){return af(s,n,r)},decode(s){return sf(s,o,r,t)}})}var ne=ut({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),uf=ut({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Bo={};ve(Bo,{base32:()=>ft,base32hex:()=>hf,base32hexpad:()=>mf,base32hexpadupper:()=>yf,base32hexupper:()=>pf,base32pad:()=>lf,base32padupper:()=>df,base32upper:()=>ff,base32z:()=>bf});var ft=ee({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ff=ee({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),lf=ee({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),df=ee({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),hf=ee({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),pf=ee({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),mf=ee({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),yf=ee({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),bf=ee({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Do={};ve(Do,{base36:()=>Ar,base36upper:()=>gf});var Ar=ut({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),gf=ut({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var xf=da,fa=128,wf=127,Ef=~wf,vf=Math.pow(2,31);function da(t,e,r){e=e||[],r=r||0;for(var n=r;t>=vf;)e[r++]=t&255|fa,t/=128;for(;t&Ef;)e[r++]=t&255|fa,t>>>=7;return e[r]=t|0,da.bytes=r-n+1,e}var Sf=Oo,If=128,la=127;function Oo(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw Oo.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&la)<<o:(i&la)*Math.pow(2,o),o+=7}while(i>=If);return Oo.bytes=s-n,r}var Af=Math.pow(2,7),_f=Math.pow(2,14),Cf=Math.pow(2,21),Tf=Math.pow(2,28),Bf=Math.pow(2,35),Df=Math.pow(2,42),Of=Math.pow(2,49),Pf=Math.pow(2,56),Lf=Math.pow(2,63),Rf=function(t){return t<Af?1:t<_f?2:t<Cf?3:t<Tf?4:t<Bf?5:t<Df?6:t<Of?7:t<Pf?8:t<Lf?9:10},Ff={encode:xf,decode:Sf,encodingLength:Rf},Nf=Ff,_r=Nf;function Cr(t,e=0){return[_r.decode(t,e),_r.decode.bytes]}function zt(t,e,r=0){return _r.encode(t,e,r),e}function $t(t){return _r.encodingLength(t)}function He(t,e){let r=e.byteLength,n=$t(t),o=n+$t(r),s=new Uint8Array(o+r);return zt(t,s,0),zt(r,s,n),s.set(e,o),new jt(t,r,e,s)}function Tr(t){let e=Qe(t),[r,n]=Cr(e),[o,s]=Cr(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new jt(r,o,i,e)}function ha(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&oa(t.bytes,r.bytes)}}var jt=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};function pa(t,e){let{bytes:r,version:n}=t;return n===0?Uf(r,Po(t),e??ne.encoder):Kf(r,Po(t),e??ft.encoder)}var ma=new WeakMap;function Po(t){let e=ma.get(t);if(e==null){let r=new Map;return ma.set(t,r),r}return e}var fe=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==Br)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Mf)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=He(e,r);return t.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&ha(e.multihash,n.multihash)}toString(e){return pa(this,e)}toJSON(){return{"/":pa(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new t(n,o,s,i??ya(n,o,s.bytes))}else if(r[Vf]===!0){let{version:n,multihash:o,code:s}=r,i=Tr(o);return t.create(n,s,i)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==Br)throw new Error(`Version 0 CID must use dag-pb (code: ${Br}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=ya(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Br,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=Qe(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new jt(r.multihashCode,r.digestSize,s,o);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[l,h]=Cr(e.subarray(r));return r+=h,l},o=n(),s=Br;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),u=n(),c=r+u,f=c-i;return{version:o,codec:s,multihashCode:a,digestSize:u,multihashSize:f,size:c}}static parse(e,r){let[n,o]=kf(e,r),s=t.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Po(s).set(n,e),s}};function kf(t,e){switch(t[0]){case"Q":{let r=e??ne;return[ne.prefix,r.decode(`${ne.prefix}${t}`)]}case ne.prefix:{let r=e??ne;return[ne.prefix,r.decode(t)]}case ft.prefix:{let r=e??ft;return[ft.prefix,r.decode(t)]}case Ar.prefix:{let r=e??Ar;return[Ar.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function Uf(t,e,r){let{prefix:n}=r;if(n!==ne.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o}function Kf(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let s=r.encode(t);return e.set(n,s),s}else return o}var Br=112,Mf=18;function ya(t,e,r){let n=$t(t),o=n+$t(e),s=new Uint8Array(o+r.byteLength);return zt(t,s,0),zt(e,s,n),s.set(r,o),s}var Vf=Symbol.for("@ipld/js-cid/CID");var Lo={};ve(Lo,{identity:()=>Oe});var ba=0,qf="identity",ga=Qe;function Hf(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return He(ba,ga(t))}var Oe={code:ba,name:qf,encode:ga,digest:Hf};function le(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}async function xa(t,e,r,n){let o=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,e,r.subarray());return n?.signal?.throwIfAborted(),s}function pe(t=0){return new Uint8Array(t)}function Se(t=0){return new Uint8Array(t)}function Je(t,e){e==null&&(e=t.reduce((o,s)=>o+s.length,0));let r=Se(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}var Ea=Symbol.for("@achingbrain/uint8arraylist");function wa(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let o=r+n.byteLength;if(e<o)return{buf:n,index:e-r};r=o}throw new RangeError("index is out of bounds")}function gn(t){return!!t?.[Ea]}var se=class t{bufs;length;[Ea]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let r=0;for(let n of e)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(gn(n)){r+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(gn(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(e){let r=wa(this.bufs,e);return r.buf[r.index]}set(e,r){let n=wa(this.bufs,e);n.buf[n.index]=r}write(e,r=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(r+n,e[n]);else if(gn(e))for(let n=0;n<e.length;n++)this.set(r+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,r){let{bufs:n,length:o}=this._subList(e,r);return Je(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:Je(n,o)}sublist(e,r){let{bufs:n,length:o}=this._subList(e,r),s=new t;return s.length=o,s.bufs=n,s}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,u=a+i.byteLength;if(o=u,e>=u)continue;let c=e>=a&&e<u,f=r>a&&r<=u;if(c&&f){if(e===a&&r===u){n.push(i);break}let l=e-a;n.push(i.subarray(l,l+(r-e)));break}if(c){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(f){if(r===u){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!gn(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let a=i,u=this.byteLength-n.byteLength,c=n.byteLength-1,f;for(let l=r;l<=u;l+=f){f=0;for(let h=c;h>=0;h--){let d=this.get(l+h);if(n[h]!==d){f=Math.max(1,h-a[d]);break}}if(f===0)return l}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=Se(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let o=pe(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let o=pe(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let o=pe(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=Se(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let o=pe(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let o=pe(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let o=pe(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let o=pe(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let o=pe(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!le(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var Ro={};ve(Ro,{base10:()=>zf});var zf=ut({prefix:"9",name:"base10",alphabet:"0123456789"});var Fo={};ve(Fo,{base16:()=>$f,base16upper:()=>jf});var $f=ee({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),jf=ee({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var No={};ve(No,{base2:()=>Yf});var Yf=ee({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ko={};ve(ko,{base256emoji:()=>Qf});var va=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}"),Zf=va.reduce((t,e,r)=>(t[r]=e,t),[]),Gf=va.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Wf(t){return t.reduce((e,r)=>(e+=Zf[r],e),"")}function Xf(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Gf[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var Qf=Ht({prefix:"\u{1F680}",name:"base256emoji",encode:Wf,decode:Xf});var Ko={};ve(Ko,{base64:()=>Jf,base64pad:()=>el,base64url:()=>Uo,base64urlpad:()=>tl});var Jf=ee({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),el=ee({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Uo=ee({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),tl=ee({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Mo={};ve(Mo,{base8:()=>rl});var rl=ee({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Vo={};ve(Vo,{identity:()=>nl});var nl=Ht({prefix:"\0",name:"identity",encode:t=>ia(t),decode:t=>sa(t)});var s0=new TextEncoder,i0=new TextDecoder;var zo={};ve(zo,{sha256:()=>Dr,sha512:()=>al});var il=20;function Ho({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new qo(t,e,r,n,o)}var qo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??il,this.maxDigestLength=s}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?Sa(n,this.code,r?.truncate):n.then(o=>Sa(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Sa(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return He(e,t)}function Aa(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Dr=Ho({name:"sha2-256",code:18,encode:Aa("SHA-256")}),al=Ho({name:"sha2-512",code:19,encode:Aa("SHA-512")});var Or={...Vo,...No,...Mo,...Ro,...Fo,...Bo,...Do,...To,...Ko,...ko},g0={...zo,...Lo};function Ca(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var _a=Ca("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),$o=Ca("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=Se(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),cl={utf8:_a,"utf-8":_a,hex:Or.base16,latin1:$o,ascii:$o,binary:$o,...Or},xn=cl;function K(t,e="utf8"){let r=xn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function q(t,e="utf8"){let r=xn[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var ul=parseInt("11111",2),jo=parseInt("10000000",2),fl=parseInt("01111111",2),Ta={0:Pr,1:Pr,2:ll,3:pl,4:ml,5:hl,6:dl,16:Pr,22:Pr,48:Pr};function et(t,e={offset:0}){let r=t[e.offset]&ul;if(e.offset++,Ta[r]!=null)return Ta[r](t,e);throw new Error("No decoder for tag "+r)}function Lr(t,e){let r=0;if((t[e.offset]&jo)===jo){let n=t[e.offset]&fl,o="0x";e.offset++;for(let s=0;s<n;s++,e.offset++)o+=t[e.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=t[e.offset],e.offset++;return r}function Pr(t,e){Lr(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=et(t,e);if(n===null)break;r.push(n)}return r}function ll(t,e){let r=Lr(t,e),n=e.offset,o=e.offset+r,s=[];for(let i=n;i<o;i++)i===n&&t[i]===0||s.push(t[i]);return e.offset+=r,Uint8Array.from(s)}function dl(t,e){let r=Lr(t,e),n=e.offset+r,o=t[e.offset];e.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,u=[];for(;e.offset<n;){let c=t[e.offset];if(e.offset++,u.push(c&127),c<128){u.reverse();let f=0;for(let l=0;l<u.length;l++)f+=u[l]<<l*7;a+=`.${f}`,u=[]}}return a}function hl(t,e){return e.offset++,null}function pl(t,e){let r=Lr(t,e),n=t[e.offset];e.offset++;let o=t.subarray(e.offset,e.offset+r-1);if(e.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function ml(t,e){let r=Lr(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function yl(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new se;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function Yo(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=yl(t.byteLength);return new se(Uint8Array.from([e.byteLength|jo]),e)}function Ie(t){let e=new se,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new se(Uint8Array.from([2]),Yo(e),e)}function wn(t){let e=Uint8Array.from([0]),r=new se(e,t);return new se(Uint8Array.from([3]),Yo(r),r)}function lt(t,e=48){let r=new se;for(let n of t)r.append(n);return new se(Uint8Array.from([e]),Yo(r),r)}var bl=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),gl=Uint8Array.from([6,5,43,129,4,0,34]),xl=Uint8Array.from([6,5,43,129,4,0,35]),wl={ext:!0,kty:"EC",crv:"P-256"},El={ext:!0,kty:"EC",crv:"P-384"},vl={ext:!0,kty:"EC",crv:"P-521"},Zo=32,Go=48,Wo=66;function Xo(t){let e=et(t);return Ba(e)}function Ba(t){let e=t[1][1][0],r=1,n,o;if(e.byteLength===Zo*2+1)return n=q(e.subarray(r,r+Zo),"base64url"),o=q(e.subarray(r+Zo),"base64url"),new Yt({...wl,key_ops:["verify"],x:n,y:o});if(e.byteLength===Go*2+1)return n=q(e.subarray(r,r+Go),"base64url"),o=q(e.subarray(r+Go),"base64url"),new Yt({...El,key_ops:["verify"],x:n,y:o});if(e.byteLength===Wo*2+1)return n=q(e.subarray(r,r+Wo),"base64url"),o=q(e.subarray(r+Wo),"base64url"),new Yt({...vl,key_ops:["verify"],x:n,y:o});throw new Q(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Da(t){return lt([Ie(Uint8Array.from([1])),lt([Sl(t.crv)],160),lt([wn(new se(Uint8Array.from([4]),K(t.x??"","base64url"),K(t.y??"","base64url")))],161)]).subarray()}function Sl(t){if(t==="P-256")return bl;if(t==="P-384")return gl;if(t==="P-521")return xl;throw new Q(`Invalid curve ${t}`)}var Yt=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=Da(this.jwk)),this._raw}toMultihash(){return Oe.digest(ze(this))}toCID(){return fe.createV1(114,this.toMultihash())}toString(){return ne.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:le(this.raw,e.raw)}async verify(e,r,n){return xa(this.jwk,r,e,n)}};function Qo(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}function dt(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(`${r}expected number, got ${typeof t}`)}if(!Number.isSafeInteger(t)||t<0){let r=e&&`"${e}" `;throw new RangeError(`${r}expected integer >= 0, got ${t}`)}}function Ce(t,e,r=""){let n=Qo(t),o=t?.length,s=e!==void 0;if(!n||s&&o!==e){let i=r&&`"${r}" `,a=s?` of length ${e}`:"",u=n?`length=${o}`:`type=${typeof t}`,c=i+"expected Uint8Array"+a+", got "+u;throw n?new RangeError(c):new TypeError(c)}return t}function En(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(dt(t.outputLen),dt(t.blockLen),t.outputLen<1)throw new Error('"outputLen" must be >= 1');if(t.blockLen<1)throw new Error('"blockLen" must be >= 1')}function Zt(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function vn(t,e){Ce(t,void 0,"digestInto() output");let r=e.outputLen;if(t.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function rt(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Sn(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Pe(t,e){return t<<32-e|t>>>e}var Pa=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Il=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function In(t){if(Ce(t),Pa)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=Il[t[r]];return e}var tt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Oa(t){if(t>=tt._0&&t<=tt._9)return t-tt._0;if(t>=tt.A&&t<=tt.F)return t-(tt.A-10);if(t>=tt.a&&t<=tt.f)return t-(tt.a-10)}function Rr(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(Pa)try{return Uint8Array.fromHex(t)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let e=t.length,r=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=Oa(t.charCodeAt(s)),a=Oa(t.charCodeAt(s+1));if(i===void 0||a===void 0){let u=t[s]+t[s+1];throw new RangeError('hex string expected, got non-hex character "'+u+'" at index '+s)}n[o]=i*16+a}return n}function Jo(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];Ce(o),e+=o.length}let r=new Uint8Array(e);for(let n=0,o=0;n<t.length;n++){let s=t[n];r.set(s,o),o+=s.length}return r}function es(t,e={}){let r=(o,s)=>t(s).update(o).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>t(o),Object.assign(r,e),Object.freeze(r)}function La(t=32){dt(t,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(t>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);return e.getRandomValues(new Uint8Array(t))}var ts=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function Ra(t,e,r){return t&e^~t&r}function Fa(t,e,r){return t&e^t&r^e&r}var Fr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,o){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=Sn(this.buffer)}update(e){Zt(this),Ce(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let u=Sn(e);for(;o<=s-i;i+=o)this.process(u,i);continue}n.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Zt(this),vn(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,rt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=Sn(e),u=this.outputLen;if(u%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let c=u/4,f=this.get();if(c>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<c;l++)a.setUint32(4*l,f[l],s)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return e.destroyed=i,e.finished=s,e.length=o,e.pos=a,o%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},nt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var me=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var An=BigInt(4294967295),Na=BigInt(32);function Al(t,e=!1){return e?{h:Number(t&An),l:Number(t>>Na&An)}:{h:Number(t>>Na&An)|0,l:Number(t&An)|0}}function ka(t,e=!1){let r=t.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=Al(t[s],e);[n[s],o[s]]=[i,a]}return[n,o]}var rs=(t,e,r)=>t>>>r,ns=(t,e,r)=>t<<32-r|e>>>r,_t=(t,e,r)=>t>>>r|e<<32-r,Ct=(t,e,r)=>t<<32-r|e>>>r,Nr=(t,e,r)=>t<<64-r|e>>>r-32,kr=(t,e,r)=>t>>>r-32|e<<64-r;function $e(t,e,r,n){let o=(e>>>0)+(n>>>0);return{h:t+r+(o/2**32|0)|0,l:o|0}}var Ua=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Ka=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,Ma=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),Va=(t,e,r,n,o)=>e+r+n+o+(t/2**32|0)|0,qa=(t,e,r,n,o)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Ha=(t,e,r,n,o,s)=>e+r+n+o+s+(t/2**32|0)|0;var Cl=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),ht=new Uint32Array(64),os=class extends Fr{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:r,C:n,D:o,E:s,F:i,G:a,H:u}=this;return[e,r,n,o,s,i,a,u]}set(e,r,n,o,s,i,a,u){this.A=e|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=u|0}process(e,r){for(let l=0;l<16;l++,r+=4)ht[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let h=ht[l-15],d=ht[l-2],m=Pe(h,7)^Pe(h,18)^h>>>3,b=Pe(d,17)^Pe(d,19)^d>>>10;ht[l]=b+ht[l-7]+m+ht[l-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:u,G:c,H:f}=this;for(let l=0;l<64;l++){let h=Pe(a,6)^Pe(a,11)^Pe(a,25),d=f+h+Ra(a,u,c)+Cl[l]+ht[l]|0,b=(Pe(n,2)^Pe(n,13)^Pe(n,22))+Fa(n,o,s)|0;f=c,c=u,u=a,a=i+d|0,i=s,s=o,o=n,n=d+b|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,u=u+this.F|0,c=c+this.G|0,f=f+this.H|0,this.set(n,o,s,i,a,u,c,f)}roundClean(){rt(ht)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),rt(this.buffer)}},ss=class extends os{A=nt[0]|0;B=nt[1]|0;C=nt[2]|0;D=nt[3]|0;E=nt[4]|0;F=nt[5]|0;G=nt[6]|0;H=nt[7]|0;constructor(){super(32)}};var za=ka(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))),Tl=za[0],Bl=za[1],pt=new Uint32Array(80),mt=new Uint32Array(80),is=class extends Fr{constructor(e){super(128,e,16,!1)}get(){let{Ah:e,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:u,Eh:c,El:f,Fh:l,Fl:h,Gh:d,Gl:m,Hh:b,Hl:y}=this;return[e,r,n,o,s,i,a,u,c,f,l,h,d,m,b,y]}set(e,r,n,o,s,i,a,u,c,f,l,h,d,m,b,y){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=u|0,this.Eh=c|0,this.El=f|0,this.Fh=l|0,this.Fl=h|0,this.Gh=d|0,this.Gl=m|0,this.Hh=b|0,this.Hl=y|0}process(e,r){for(let A=0;A<16;A++,r+=4)pt[A]=e.getUint32(r),mt[A]=e.getUint32(r+=4);for(let A=16;A<80;A++){let O=pt[A-15]|0,B=mt[A-15]|0,F=_t(O,B,1)^_t(O,B,8)^rs(O,B,7),P=Ct(O,B,1)^Ct(O,B,8)^ns(O,B,7),C=pt[A-2]|0,N=mt[A-2]|0,Z=_t(C,N,19)^Nr(C,N,61)^rs(C,N,6),k=Ct(C,N,19)^kr(C,N,61)^ns(C,N,6),p=Ma(P,k,mt[A-7],mt[A-16]),g=Va(p,F,Z,pt[A-7],pt[A-16]);pt[A]=g|0,mt[A]=p|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:u,Dh:c,Dl:f,Eh:l,El:h,Fh:d,Fl:m,Gh:b,Gl:y,Hh:E,Hl:S}=this;for(let A=0;A<80;A++){let O=_t(l,h,14)^_t(l,h,18)^Nr(l,h,41),B=Ct(l,h,14)^Ct(l,h,18)^kr(l,h,41),F=l&d^~l&b,P=h&m^~h&y,C=qa(S,B,P,Bl[A],mt[A]),N=Ha(C,E,O,F,Tl[A],pt[A]),Z=C|0,k=_t(n,o,28)^Nr(n,o,34)^Nr(n,o,39),p=Ct(n,o,28)^kr(n,o,34)^kr(n,o,39),g=n&s^n&a^s&a,v=o&i^o&u^i&u;E=b|0,S=y|0,b=d|0,y=m|0,d=l|0,m=h|0,{h:l,l:h}=$e(c|0,f|0,N|0,Z|0),c=a|0,f=u|0,a=s|0,u=i|0,s=n|0,i=o|0;let w=Ua(Z,p,v);n=Ka(w,N,k,g),o=w|0}({h:n,l:o}=$e(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=$e(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:u}=$e(this.Ch|0,this.Cl|0,a|0,u|0),{h:c,l:f}=$e(this.Dh|0,this.Dl|0,c|0,f|0),{h:l,l:h}=$e(this.Eh|0,this.El|0,l|0,h|0),{h:d,l:m}=$e(this.Fh|0,this.Fl|0,d|0,m|0),{h:b,l:y}=$e(this.Gh|0,this.Gl|0,b|0,y|0),{h:E,l:S}=$e(this.Hh|0,this.Hl|0,E|0,S|0),this.set(n,o,s,i,a,u,c,f,l,h,d,m,b,y,E,S)}roundClean(){rt(pt,mt)}destroy(){this.destroyed=!0,rt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},as=class extends is{Ah=me[0]|0;Al=me[1]|0;Bh=me[2]|0;Bl=me[3]|0;Ch=me[4]|0;Cl=me[5]|0;Dh=me[6]|0;Dl=me[7]|0;Eh=me[8]|0;El=me[9]|0;Fh=me[10]|0;Fl=me[11]|0;Gh=me[12]|0;Gl=me[13]|0;Hh=me[14]|0;Hl=me[15]|0;constructor(){super(64)}};var Gt=es(()=>new ss,ts(1));var _n=es(()=>new as,ts(3));var H=(t,e,r)=>Ce(t,e,r),us=dt,Wt=In,ae=(...t)=>Jo(...t),Xt=t=>Rr(t),Tt=Qo,Ur=t=>La(t),Tn=BigInt(0),cs=BigInt(1);function Le(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}" `;throw new TypeError(r+"expected boolean, got type="+typeof t)}return t}function Bn(t){if(typeof t=="bigint"){if(!Cn(t))throw new RangeError("positive bigint expected, got "+t)}else us(t);return t}function Re(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(r+"expected number, got type="+typeof t)}if(!Number.isSafeInteger(t)){let r=e&&`"${e}" `;throw new RangeError(r+"expected safe integer, got "+t)}}function Kr(t){let e=Bn(t).toString(16);return e.length&1?"0"+e:e}function $a(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?Tn:BigInt("0x"+t)}function Bt(t){return $a(In(t))}function je(t){return $a(In(Mr(Ce(t)).reverse()))}function Dn(t,e){if(dt(e),e===0)throw new RangeError("zero length");t=Bn(t);let r=t.toString(16);if(r.length>e*2)throw new RangeError("number too large");return Rr(r.padStart(e*2,"0"))}function fs(t,e){return Dn(t,e).reverse()}function ja(t,e){if(t=H(t),e=H(e),t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function Mr(t){return Uint8Array.from(H(t))}function On(t){if(typeof t!="string")throw new TypeError("ascii string expected, got "+typeof t);return Uint8Array.from(t,(e,r)=>{let n=e.charCodeAt(0);if(e.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${t[r]}" with code ${n} at position ${r}`);return n})}var Cn=t=>typeof t=="bigint"&&Tn<=t;function Dl(t,e,r){return Cn(t)&&Cn(e)&&Cn(r)&&e<=t&&t<r}function Qt(t,e,r,n){if(!Dl(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Jt(t){if(t<Tn)throw new Error("expected non-negative bigint, got "+t);let e;for(e=0;t>Tn;t>>=cs,e+=1);return e}var Vr=t=>(cs<<BigInt(t))-cs;function Ya(t,e,r){if(dt(t,"hashLen"),dt(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=y=>new Uint8Array(y),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,u=n(t),c=n(t),f=0,l=()=>{u.fill(1),c.fill(0),f=0},h=(...y)=>r(c,ae(u,...y)),d=(y=o)=>{c=h(s,y),u=h(),y.length!==0&&(c=h(i,y),u=h())},m=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let y=0,E=[];for(;y<e;){u=h();let S=u.slice();E.push(S),y+=u.length}return ae(...E)};return(y,E)=>{l(),d(y);let S;for(;(S=E(m()))===void 0;)d();return l(),S}}function Fe(t,e={},r={}){if(Object.prototype.toString.call(t)!=="[object Object]")throw new TypeError("expected valid options object");function n(s,i,a){if(!a&&i!=="function"&&!Object.hasOwn(t,s))throw new TypeError(`param "${s}" is invalid: expected own property`);let u=t[s];if(a&&u===void 0)return;let c=typeof u;if(c!==i||u===null)throw new TypeError(`param "${s}" is invalid: expected ${i}, got ${c}`)}let o=(s,i)=>Object.entries(s).forEach(([a,u])=>n(a,u,i));o(e,!1),o(r,!0)}var ls=()=>{throw new Error("not implemented")};var ye=BigInt(0),te=BigInt(1),Dt=BigInt(2),Xa=BigInt(3),Qa=BigInt(4),Ja=BigInt(5),Ol=BigInt(7),ec=BigInt(8),Pl=BigInt(9),tc=BigInt(16);function oe(t,e){if(e<=ye)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=ye?r:e+r}function X(t,e,r){if(e<ye)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >ye;)n*=n,n%=r;return n}function Za(t,e){if(t===ye)throw new Error("invert: expected non-zero number");if(e<=ye)throw new Error("invert: expected positive modulus, got "+e);let r=oe(t,e),n=e,o=ye,s=te,i=te,a=ye;for(;r!==ye;){let c=n/r,f=n-r*c,l=o-i*c,h=s-a*c;n=r,r=f,o=i,s=a,i=l,a=h}if(n!==te)throw new Error("invert: does not exist");return oe(o,e)}function ds(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function rc(t,e){let r=t,n=(r.ORDER+te)/Qa,o=r.pow(e,n);return ds(r,o,e),o}function Ll(t,e){let r=t,n=(r.ORDER-Ja)/ec,o=r.mul(e,Dt),s=r.pow(o,n),i=r.mul(e,s),a=r.mul(r.mul(i,Dt),s),u=r.mul(i,r.sub(a,r.ONE));return ds(r,u,e),u}function Rl(t){let e=er(t),r=nc(t),n=r(e,e.neg(e.ONE)),o=r(e,n),s=r(e,e.neg(n)),i=(t+Ol)/tc;return((a,u)=>{let c=a,f=c.pow(u,i),l=c.mul(f,n),h=c.mul(f,o),d=c.mul(f,s),m=c.eql(c.sqr(l),u),b=c.eql(c.sqr(h),u);f=c.cmov(f,l,m),l=c.cmov(d,h,b);let y=c.eql(c.sqr(l),u),E=c.cmov(f,l,y);return ds(c,E,u),E})}function nc(t){if(t<Xa)throw new Error("sqrt is not defined for small field");let e=t-te,r=0;for(;e%Dt===ye;)e/=Dt,r++;let n=Dt,o=er(t);for(;Ga(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return rc;let s=o.pow(n,e),i=(e+te)/Dt;return function(u,c){let f=u;if(f.is0(c))return c;if(Ga(f,c)!==1)throw new Error("Cannot find square root");let l=r,h=f.mul(f.ONE,s),d=f.pow(c,e),m=f.pow(c,i);for(;!f.eql(d,f.ONE);){if(f.is0(d))return f.ZERO;let b=1,y=f.sqr(d);for(;!f.eql(y,f.ONE);)if(b++,y=f.sqr(y),b===l)throw new Error("Cannot find square root");let E=te<<BigInt(l-b-1),S=f.pow(h,E);l=b,h=f.sqr(S),d=f.mul(d,h),m=f.mul(m,S)}return m}}function Fl(t){return t%Qa===Xa?rc:t%ec===Ja?Ll:t%tc===Pl?Rl(t):nc(t)}var ot=(t,e)=>(oe(t,e)&te)===te,Nl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function hs(t){let e={ORDER:"bigint",BYTES:"number",BITS:"number"},r=Nl.reduce((n,o)=>(n[o]="function",n),e);if(Fe(t,r),Re(t.BYTES,"BYTES"),Re(t.BITS,"BITS"),t.BYTES<1||t.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(t.ORDER<=te)throw new Error("invalid field: expected ORDER > 1, got "+t.ORDER);return t}function kl(t,e,r){let n=t;if(r<ye)throw new Error("invalid exponent, negatives unsupported");if(r===ye)return n.ONE;if(r===te)return e;let o=n.ONE,s=e;for(;r>ye;)r&te&&(o=n.mul(o,s)),s=n.sqr(s),r>>=te;return o}function qr(t,e,r=!1){let n=t,o=new Array(e.length).fill(r?n.ZERO:void 0),s=e.reduce((a,u,c)=>n.is0(u)?a:(o[c]=a,n.mul(a,u)),n.ONE),i=n.inv(s);return e.reduceRight((a,u,c)=>n.is0(u)?a:(o[c]=n.mul(a,o[c]),n.mul(a,u)),i),o}function Ga(t,e){let r=t,n=(r.ORDER-te)/Dt,o=r.pow(e,n),s=r.eql(o,r.ONE),i=r.eql(o,r.ZERO),a=r.eql(o,r.neg(r.ONE));if(!s&&!i&&!a)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function Ul(t,e){if(e!==void 0&&us(e),t<=ye)throw new Error("invalid n length: expected positive n, got "+t);if(e!==void 0&&e<1)throw new Error("invalid n length: expected positive bit length, got "+e);let r=Jt(t);if(e!==void 0&&e<r)throw new Error(`invalid n length: expected bit length (${r}) >= n.length (${e})`);let n=e!==void 0?e:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var Wa=new WeakMap,Pn=class{ORDER;BITS;BYTES;isLE;ZERO=ye;ONE=te;_lengths;_mod;constructor(e,r={}){if(e<=te)throw new Error("invalid field: expected ORDER > 1, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=Ul(e,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(e){return oe(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof e);return ye<=e&&e<this.ORDER}is0(e){return e===ye}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&te)===te}neg(e){return oe(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return oe(e*e,this.ORDER)}add(e,r){return oe(e+r,this.ORDER)}sub(e,r){return oe(e-r,this.ORDER)}mul(e,r){return oe(e*r,this.ORDER)}pow(e,r){return kl(this,e,r)}div(e,r){return oe(e*Za(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return Za(e,this.ORDER)}sqrt(e){let r=Wa.get(this);return r||Wa.set(this,r=Fl(this.ORDER)),r(this,e)}toBytes(e){return this.isLE?fs(e,this.BYTES):Dn(e,this.BYTES)}fromBytes(e,r=!1){H(e);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let c=new Uint8Array(o);c.set(e,s?0:c.length-e.length),e=c}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let u=s?je(e):Bt(e);if(a&&(u=oe(u,i)),!r&&!this.isValid(u))throw new Error("invalid field element: outside of range 0..ORDER");return u}invertBatch(e){return qr(this,e)}cmov(e,r,n){return Le(n,"condition"),n?r:e}};Object.freeze(Pn.prototype);function er(t,e={}){return new Pn(t,e)}function oc(t){if(typeof t!="bigint")throw new Error("field order must be bigint");if(t<=te)throw new Error("field order must be greater than 1");let e=Jt(t-te);return Math.ceil(e/8)}function ps(t){let e=oc(t);return e+Math.ceil(e/2)}function ms(t,e,r=!1){H(t);let n=t.length,o=oc(e),s=Math.max(ps(e),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?je(t):Bt(t),a=oe(i,e-te)+te;return r?fs(a,o):Dn(a,o)}var tr=BigInt(0),Ot=BigInt(1);function Hr(t,e){let r=e.negate();return t?r:e}function Pt(t,e){let r=qr(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function cc(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function ys(t,e){cc(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),o=2**t,s=Vr(t),i=BigInt(t);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function sc(t,e,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(t&o),u=t>>i;a>n&&(a-=s,u+=Ot);let c=e*n,f=c+Math.abs(a)-1,l=a===0,h=a<0,d=e%2!==0;return{nextN:u,offset:f,isZero:l,isNeg:h,isNegF:d,offsetF:c}}var bs=new WeakMap,uc=new WeakMap;function gs(t){return uc.get(t)||1}function ic(t){if(t!==tr)throw new Error("invalid wNAF")}var rr=class{BASE;ZERO;Fn;bits;constructor(e,r){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=r}_unsafeLadder(e,r,n=this.ZERO){let o=e;for(;r>tr;)r&Ot&&(n=n.add(o)),o=o.double(),r>>=Ot;return n}precomputeWindow(e,r){let{windows:n,windowSize:o}=ys(r,this.bits),s=[],i=e,a=i;for(let u=0;u<n;u++){a=i,s.push(a);for(let c=1;c<o;c++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=ys(e,this.bits);for(let a=0;a<i.windows;a++){let{nextN:u,offset:c,isZero:f,isNeg:l,isNegF:h,offsetF:d}=sc(n,a,i);n=u,f?s=s.add(Hr(h,r[d])):o=o.add(Hr(l,r[c]))}return ic(n),{p:o,f:s}}wNAFUnsafe(e,r,n,o=this.ZERO){let s=ys(e,this.bits);for(let i=0;i<s.windows&&n!==tr;i++){let{nextN:a,offset:u,isZero:c,isNeg:f}=sc(n,i,s);if(n=a,!c){let l=r[u];o=o.add(f?l.negate():l)}}return ic(n),o}getPrecomputes(e,r,n){let o=bs.get(r);return o||(o=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(o=n(o)),bs.set(r,o))),o}cached(e,r,n){let o=gs(e);return this.wNAF(o,this.getPrecomputes(o,e,n),r)}unsafe(e,r,n,o){let s=gs(e);return s===1?this._unsafeLadder(e,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,e,n),r,o)}createCache(e,r){cc(r,this.bits),uc.set(e,r),bs.delete(e)}hasCache(e){return gs(e)!==1}};function fc(t,e,r,n){let o=e,s=t.ZERO,i=t.ZERO;for(;r>tr||n>tr;)r&Ot&&(s=s.add(o)),n&Ot&&(i=i.add(o)),o=o.double(),r>>=Ot,n>>=Ot;return{p1:s,p2:i}}function ac(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return hs(e),e}else return er(t,{isLE:r})}function Ln(t,e,r={},n){if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(let u of["p","n","h"]){let c=e[u];if(!(typeof c=="bigint"&&c>tr))throw new Error(`CURVE.${u} must be positive bigint`)}let o=ac(e.p,r.Fp,n),s=ac(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let u of a)if(!o.isValid(e[u]))throw new Error(`CURVE.${u} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:s}}function Rn(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}var yt=BigInt(0),de=BigInt(1),xs=BigInt(2),Kl=BigInt(8);function Ml(t,e,r,n){let o=t.sqr(r),s=t.sqr(n),i=t.add(t.mul(e.a,o),s),a=t.add(t.ONE,t.mul(e.d,t.mul(o,s)));return t.eql(i,a)}function lc(t,e={}){let r=e,n=Ln("edwards",t,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;Fe(r,{},{uvRatio:"function"});let u=xs<<BigInt(s.BYTES*8)-de,c=b=>o.create(b),f=r.uvRatio===void 0?(b,y)=>{try{return{isValid:!0,value:o.sqrt(o.div(b,y))}}catch{return{isValid:!1,value:yt}}}:r.uvRatio;if(!Ml(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function l(b,y,E=!1){let S=E?de:yt;return Qt("coordinate "+b,y,S,u),y}function h(b){if(!(b instanceof d))throw new Error("EdwardsPoint expected")}class d{static BASE=new d(i.Gx,i.Gy,de,c(i.Gx*i.Gy));static ZERO=new d(yt,de,de,yt);static Fp=o;static Fn=s;X;Y;Z;T;constructor(y,E,S,A){this.X=l("x",y),this.Y=l("y",E),this.Z=l("z",S,!0),this.T=l("t",A),Object.freeze(this)}static CURVE(){return i}static fromAffine(y){if(y instanceof d)throw new Error("extended point not allowed");let{x:E,y:S}=y||{};return l("x",E),l("y",S),new d(E,S,de,c(E*S))}static fromBytes(y,E=!1){let S=o.BYTES,{a:A,d:O}=i;y=Mr(H(y,S,"point")),Le(E,"zip215");let B=Mr(y),F=y[S-1];B[S-1]=F&-129;let P=je(B),C=E?u:o.ORDER;Qt("point.y",P,yt,C);let N=c(P*P),Z=c(N-de),k=c(O*N-A),{isValid:p,value:g}=f(Z,k);if(!p)throw new Error("bad point: invalid y coordinate");let v=(g&de)===de,w=(F&128)!==0;if(!E&&g===yt&&w)throw new Error("bad point: x=0 and x_0=1");return w!==v&&(g=c(-g)),d.fromAffine({x:g,y:P})}static fromHex(y,E=!1){return d.fromBytes(Xt(y),E)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,E=!0){return m.createCache(this,y),E||this.multiply(xs),this}assertValidity(){let y=this,{a:E,d:S}=i;if(y.is0())throw new Error("bad point: ZERO");let{X:A,Y:O,Z:B,T:F}=y,P=c(A*A),C=c(O*O),N=c(B*B),Z=c(N*N),k=c(P*E),p=c(N*c(k+C)),g=c(Z+c(S*c(P*C)));if(p!==g)throw new Error("bad point: equation left != right (1)");let v=c(A*O),w=c(B*F);if(v!==w)throw new Error("bad point: equation left != right (2)")}equals(y){h(y);let{X:E,Y:S,Z:A}=this,{X:O,Y:B,Z:F}=y,P=c(E*F),C=c(O*A),N=c(S*F),Z=c(B*A);return P===C&&N===Z}is0(){return this.equals(d.ZERO)}negate(){return new d(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:y}=i,{X:E,Y:S,Z:A}=this,O=c(E*E),B=c(S*S),F=c(xs*c(A*A)),P=c(y*O),C=E+S,N=c(c(C*C)-O-B),Z=P+B,k=Z-F,p=P-B,g=c(N*k),v=c(Z*p),w=c(N*p),x=c(k*Z);return new d(g,v,x,w)}add(y){h(y);let{a:E,d:S}=i,{X:A,Y:O,Z:B,T:F}=this,{X:P,Y:C,Z:N,T:Z}=y,k=c(A*P),p=c(O*C),g=c(F*S*Z),v=c(B*N),w=c((A+O)*(P+C)-k-p),x=v-g,I=v+g,T=c(p-E*k),_=c(w*x),D=c(I*T),R=c(w*T),V=c(x*I);return new d(_,D,V,R)}subtract(y){return h(y),this.add(y.negate())}multiply(y){if(!s.isValidNot0(y))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:E,f:S}=m.cached(this,y,A=>Pt(d,A));return Pt(d,[E,S])[0]}multiplyUnsafe(y){if(!s.isValid(y))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return y===yt?d.ZERO:this.is0()||y===de?this:m.unsafe(this,y,E=>Pt(d,E))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return m.unsafe(this,i.n).is0()}toAffine(y){let E=this,S=y,{X:A,Y:O,Z:B}=E,F=E.is0();S==null&&(S=F?Kl:o.inv(B));let P=c(A*S),C=c(O*S),N=o.mul(B,S);if(F)return{x:yt,y:de};if(N!==de)throw new Error("invZ was invalid");return{x:P,y:C}}clearCofactor(){return a===de?this:this.multiplyUnsafe(a)}toBytes(){let{x:y,y:E}=this.toAffine(),S=o.toBytes(E);return S[S.length-1]|=y&de?128:0,S}toHex(){return Wt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let m=new rr(d,s.BITS);return s.BITS>=8&&d.BASE.precompute(8),Object.freeze(d.prototype),Object.freeze(d),d}var Fn=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(e){this.ep=e}static fromBytes(e){ls()}static fromHex(e){ls()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(e){return this.ep.toAffine(e)}toHex(){return Wt(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(e){return this.assertSame(e),this.init(this.ep.add(e.ep))}subtract(e){return this.assertSame(e),this.init(this.ep.subtract(e.ep))}multiply(e){return this.init(this.ep.multiply(e))}multiplyUnsafe(e){return this.init(this.ep.multiplyUnsafe(e))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(e,r){return this.ep.precompute(e,r),this}};function dc(t,e,r={}){if(typeof e!="function")throw new Error('"hash" function param is required');let n=e,o=r;Fe(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:u}=t,c=n.outputLen,f=2*a.BYTES;if(c!==void 0&&(Re(c,"hash.outputLen"),c!==f))throw new Error(`hash.outputLen must be ${f}, got ${c}`);let l=o.randomBytes===void 0?Ur:o.randomBytes,h=o.adjustScalarBytes===void 0?p=>p:o.adjustScalarBytes,d=o.domain===void 0?(p,g,v)=>{if(Le(v,"phflag"),g.length||v)throw new Error("Contexts/pre-hash are not supported");return p}:o.domain;function m(p){return u.create(je(p))}function b(p){let g=P.secretKey;H(p,P.secretKey,"secretKey");let v=H(n(p),2*g,"hashedSecretKey"),w=h(v.slice(0,g)),x=v.slice(g,2*g),I=m(w);return{head:w,prefix:x,scalar:I}}function y(p){let{head:g,prefix:v,scalar:w}=b(p),x=i.multiply(w),I=x.toBytes();return{head:g,prefix:v,scalar:w,point:x,pointBytes:I}}function E(p){return y(p).pointBytes}function S(p=Uint8Array.of(),...g){let v=ae(...g);return m(n(d(v,H(p,void 0,"context"),!!s)))}function A(p,g,v={}){p=H(p,void 0,"message"),s&&(p=s(p));let{prefix:w,scalar:x,pointBytes:I}=y(g),T=S(v.context,w,p),_=i.multiply(T).toBytes(),D=S(v.context,_,I,p),R=u.create(T+D*x);if(!u.isValid(R))throw new Error("sign failed: invalid s");let V=ae(_,u.toBytes(R));return H(V,P.signature,"result")}let O={zip215:o.zip215};function B(p,g,v,w=O){let{context:x}=w,I=w.zip215===void 0?!!O.zip215:w.zip215,T=P.signature;p=H(p,T,"signature"),g=H(g,void 0,"message"),v=H(v,P.publicKey,"publicKey"),I!==void 0&&Le(I,"zip215"),s&&(g=s(g));let _=T/2,D=p.subarray(0,_),R=je(p.subarray(_,T)),V,j,U;try{V=t.fromBytes(v,I),j=t.fromBytes(D,I),U=i.multiplyUnsafe(R)}catch{return!1}if(!I&&V.isSmallOrder())return!1;let ie=S(x,D,v,g);return j.add(V.multiplyUnsafe(ie)).subtract(U).clearCofactor().is0()}let F=a.BYTES,P={secretKey:F,publicKey:F,signature:2*F,seed:F};function C(p){return p=p===void 0?l(P.seed):p,H(p,P.seed,"seed")}function N(p){return Tt(p)&&p.length===P.secretKey}function Z(p,g){try{return!!t.fromBytes(p,g===void 0?O.zip215:g)}catch{return!1}}let k={getExtendedPublicKey:y,randomSecretKey:C,isValidSecretKey:N,isValidPublicKey:Z,toMontgomery(p){let{y:g}=t.fromBytes(p),v=P.publicKey,w=v===32;if(!w&&v!==57)throw new Error("only defined for 25519 and 448");let x=w?a.div(de+g,de-g):a.div(g-de,g+de);return a.toBytes(x)},toMontgomerySecret(p){let g=P.secretKey;H(p,g);let v=n(p.subarray(0,g));return h(v).subarray(0,g)}};return Object.freeze(P),Object.freeze(k),Object.freeze({keygen:Rn(C,E),getPublicKey:E,sign:A,verify:B,utils:k,Point:t,lengths:P})}function zr(t,e){if(Re(t),Re(e),e<0||e>4)throw new Error("invalid I2OSP length: "+e);if(t<0||t>2**(8*e)-1)throw new Error("invalid I2OSP input: "+t);let r=Array.from({length:e}).fill(0);for(let n=e-1;n>=0;n--)r[n]=t&255,t>>>=8;return new Uint8Array(r)}function Vl(t,e){let r=new Uint8Array(t.length);for(let n=0;n<t.length;n++)r[n]=t[n]^e[n];return r}function ql(t){if(!Tt(t)&&typeof t!="string")throw new Error("DST must be Uint8Array or ascii string");let e=typeof t=="string"?On(t):t;if(e.length===0)throw new Error("DST must be non-empty");return e}function ws(t,e,r,n){H(t),Re(r),e=ql(e),e.length>255&&(e=n(ae(On("H2C-OVERSIZE-DST-"),e)));let{outputLen:o,blockLen:s}=n,i=Math.ceil(r/o);if(r>65535||i>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=ae(e,zr(e.length,1)),u=new Uint8Array(s),c=zr(r,2),f=new Array(i),l=n(ae(u,t,c,zr(0,1),a));f[0]=n(ae(l,zr(1,1),a));for(let d=1;d<i;d++){let m=[Vl(l,f[d-1]),zr(d+1,1),a];f[d]=n(ae(...m))}return ae(...f).slice(0,r)}var hc="HashToScalar-";var Hl=BigInt(0),st=BigInt(1),pc=BigInt(2);var zl=BigInt(5),$l=BigInt(8),nr=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Is={p:nr,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:$l,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function jl(t){let e=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=nr,a=t*t%s*t%s,u=X(a,pc,s)*a%s,c=X(u,st,s)*t%s,f=X(c,zl,s)*c%s,l=X(f,e,s)*f%s,h=X(l,r,s)*l%s,d=X(h,n,s)*h%s,m=X(d,o,s)*d%s,b=X(m,o,s)*d%s,y=X(b,e,s)*f%s;return{pow_p_5_8:X(y,pc,s)*t%s,b2:a}}function Yl(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}var Es=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function As(t,e){let r=nr,n=oe(e*e*e,r),o=oe(n*n*e,r),s=jl(t*o).pow_p_5_8,i=oe(t*n*s,r),a=oe(e*i*i,r),u=i,c=oe(i*Es,r),f=a===t,l=a===oe(-t,r),h=a===oe(-t*Es,r);return f&&(i=u),(l||h)&&(i=c),ot(i,r)&&(i=oe(-i,r)),{isValid:f||l,value:i}}var gt=lc(Is,{uvRatio:As}),bt=gt.Fp,bc=gt.Fn;function Zl(t){return dc(gt,_n,Object.assign({adjustScalarBytes:Yl,zip215:!0},t))}var gc=Zl({});var vs=Es,Gl=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Wl=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Xl=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Ql=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),mc=t=>As(st,t),Jl=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Ss=t=>bt.create(je(t)&Jl);function yc(t){let{d:e}=Is,r=nr,n=E=>bt.create(E),o=n(vs*t*t),s=n((o+st)*Xl),i=BigInt(-1),a=n((i-e*o)*n(o+e)),{isValid:u,value:c}=As(s,a),f=n(c*t);ot(f,r)||(f=n(-f)),u||(c=f),u||(i=o);let l=n(i*(o-st)*Ql-a),h=c*c,d=n((c+c)*a),m=n(l*Gl),b=n(st-h),y=n(st+h);return new gt(n(d*y),n(b*m),n(m*y),n(d*b))}var xt=class t extends Fn{static BASE=new t(gt.BASE);static ZERO=new t(gt.ZERO);static Fp=bt;static Fn=bc;constructor(e){super(e)}static fromAffine(e){return new t(gt.fromAffine(e))}assertSame(e){if(!(e instanceof t))throw new Error("RistrettoPoint expected")}init(e){return new t(e)}static fromBytes(e){Ce(e,32);let{a:r,d:n}=Is,o=nr,s=O=>bt.create(O),i=Ss(e);if(!ja(bt.toBytes(i),e)||ot(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),u=s(st+r*a),c=s(st-r*a),f=s(u*u),l=s(c*c),h=s(r*n*f-l),{isValid:d,value:m}=mc(s(h*l)),b=s(m*c),y=s(m*b*h),E=s((i+i)*b);ot(E,o)&&(E=s(-E));let S=s(u*y),A=s(E*S);if(!d||ot(A,o)||S===Hl)throw new Error("invalid ristretto255 encoding 2");return new t(new gt(E,S,st,A))}static fromHex(e){return t.fromBytes(Rr(e))}toBytes(){let{X:e,Y:r,Z:n,T:o}=this.ep,s=nr,i=y=>bt.create(y),a=i(i(n+r)*i(n-r)),u=i(e*r),c=i(u*u),{value:f}=mc(i(a*c)),l=i(f*a),h=i(f*u),d=i(l*h*o),m;if(ot(o*d,s)){let y=i(r*vs),E=i(e*vs);e=y,r=E,m=i(l*Wl)}else m=h;ot(e*d,s)&&(r=i(-r));let b=i((n-r)*m);return ot(b,s)&&(b=i(-b)),bt.toBytes(b)}equals(e){this.assertSame(e);let{X:r,Y:n}=this.ep,{X:o,Y:s}=e.ep,i=c=>bt.create(c),a=i(r*s)===i(n*o),u=i(n*s)===i(r*o);return a||u}is0(){return this.equals(t.ZERO)}};Object.freeze(xt.BASE);Object.freeze(xt.ZERO);Object.freeze(xt.prototype);Object.freeze(xt);var ed=Object.freeze({Point:xt,hashToCurve(t,e){let r=e?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":e.DST,n=ws(t,r,64,_n);return ed.deriveToCurve(n)},hashToScalar(t,e={DST:hc}){let r=ws(t,e.DST,64,_n);return bc.create(je(r))},deriveToCurve(t){Ce(t,64);let e=Ss(t.subarray(0,32)),r=yc(e),n=Ss(t.subarray(32,64)),o=yc(n);return new xt(r.add(o))}});var $r=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}},Nn=class extends Error{constructor(e="Missing Web Crypto API"){super(e),this.name="WebCryptoMissingError"}};var xc={get(t=globalThis){let e=t.crypto;if(e?.subtle==null)throw new Nn("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return e}};var Be=xc;var kn=32;var _s,td=(async()=>{try{return await Be.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function rd(t,e,r){if(t.buffer instanceof ArrayBuffer){let n=await Be.get().subtle.importKey("raw",t.buffer,{name:"Ed25519"},!1,["verify"]);return await Be.get().subtle.verify({name:"Ed25519"},n,e,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function nd(t,e,r){return gc.verify(e,r instanceof Uint8Array?r:r.subarray(),t)}async function wc(t,e,r){return _s==null&&(_s=await td),_s?rd(t,e,r):nd(t,e,r)}function Un(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Kn=class{type="Ed25519";raw;constructor(e){this.raw=Cs(e,kn)}toMultihash(){return Oe.digest(ze(this))}toCID(){return fe.createV1(114,this.toMultihash())}toString(){return ne.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:le(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let o=wc(this.raw,r,e);return Un(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Ts(t){return t=Cs(t,kn),new Kn(t)}function Cs(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new Q(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}var sd=Math.pow(2,7),id=Math.pow(2,14),ad=Math.pow(2,21),Bs=Math.pow(2,28),Ds=Math.pow(2,35),Os=Math.pow(2,42),Ps=Math.pow(2,49),Y=128,ge=127;function Ae(t){if(t<sd)return 1;if(t<id)return 2;if(t<ad)return 3;if(t<Bs)return 4;if(t<Ds)return 5;if(t<Os)return 6;if(t<Ps)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function or(t,e,r=0){switch(Ae(t)){case 8:e[r++]=t&255|Y,t/=128;case 7:e[r++]=t&255|Y,t/=128;case 6:e[r++]=t&255|Y,t/=128;case 5:e[r++]=t&255|Y,t/=128;case 4:e[r++]=t&255|Y,t>>>=7;case 3:e[r++]=t&255|Y,t>>>=7;case 2:e[r++]=t&255|Y,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function cd(t,e,r=0){switch(Ae(t)){case 8:e.set(r++,t&255|Y),t/=128;case 7:e.set(r++,t&255|Y),t/=128;case 6:e.set(r++,t&255|Y),t/=128;case 5:e.set(r++,t&255|Y),t/=128;case 4:e.set(r++,t&255|Y),t>>>=7;case 3:e.set(r++,t&255|Y),t>>>=7;case 2:e.set(r++,t&255|Y),t>>>=7;case 1:{e.set(r++,t&255),t>>>=7;break}default:throw new Error("unreachable")}return e}function Ls(t,e){let r=t[e],n=0;if(n+=r&ge,r<Y||(r=t[e+1],n+=(r&ge)<<7,r<Y)||(r=t[e+2],n+=(r&ge)<<14,r<Y)||(r=t[e+3],n+=(r&ge)<<21,r<Y)||(r=t[e+4],n+=(r&ge)*Bs,r<Y)||(r=t[e+5],n+=(r&ge)*Ds,r<Y)||(r=t[e+6],n+=(r&ge)*Os,r<Y)||(r=t[e+7],n+=(r&ge)*Ps,r<Y))return n;throw new RangeError("Could not decode varint")}function ud(t,e){let r=t.get(e),n=0;if(n+=r&ge,r<Y||(r=t.get(e+1),n+=(r&ge)<<7,r<Y)||(r=t.get(e+2),n+=(r&ge)<<14,r<Y)||(r=t.get(e+3),n+=(r&ge)<<21,r<Y)||(r=t.get(e+4),n+=(r&ge)*Bs,r<Y)||(r=t.get(e+5),n+=(r&ge)*Ds,r<Y)||(r=t.get(e+6),n+=(r&ge)*Os,r<Y)||(r=t.get(e+7),n+=(r&ge)*Ps,r<Y))return n;throw new RangeError("Could not decode varint")}function sr(t,e,r=0){return e==null&&(e=Se(Ae(t))),e instanceof Uint8Array?or(t,e,r):cd(t,e,r)}function jr(t,e=0){return t instanceof Uint8Array?Ls(t,e):ud(t,e)}var Fs=new Float32Array([-0]),wt=new Uint8Array(Fs.buffer);function vc(t,e,r){Fs[0]=t,e[r]=wt[0],e[r+1]=wt[1],e[r+2]=wt[2],e[r+3]=wt[3]}function Sc(t,e){return wt[0]=t[e],wt[1]=t[e+1],wt[2]=t[e+2],wt[3]=t[e+3],Fs[0]}var Ns=new Float64Array([-0]),xe=new Uint8Array(Ns.buffer);function Ic(t,e,r){Ns[0]=t,e[r]=xe[0],e[r+1]=xe[1],e[r+2]=xe[2],e[r+3]=xe[3],e[r+4]=xe[4],e[r+5]=xe[5],e[r+6]=xe[6],e[r+7]=xe[7]}function Ac(t,e){return xe[0]=t[e],xe[1]=t[e+1],xe[2]=t[e+2],xe[3]=t[e+3],xe[4]=t[e+4],xe[5]=t[e+5],xe[6]=t[e+6],xe[7]=t[e+7],Ns[0]}var fd=BigInt(Number.MAX_SAFE_INTEGER),ld=BigInt(Number.MIN_SAFE_INTEGER),Te=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Lt;if(e<fd&&e>ld)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,o=e-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>_c&&(o=0n,++n>_c&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return Lt;let r=e<0;r&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new t(n,o)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):Lt}},Lt=new Te(0,0);Lt.toBigInt=function(){return 0n};Lt.zzEncode=Lt.zzDecode=function(){return this};Lt.length=function(){return 1};var _c=4294967296n;function Cc(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function Tc(t,e,r){if(r-e<1)return"";let o,s=[],i=0,a;for(;e<r;)a=t[e++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function ks(t,e,r){let n=r,o,s;for(let i=0;i<t.length;++i)o=t.charCodeAt(i),o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&((s=t.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128);return r-n}function Ne(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function Mn(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var Us=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Ne(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Ne(this,4);return Mn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ne(this,4);return Mn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ne(this,4);let e=Sc(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ne(this,4);let e=Ac(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw Ne(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return Tc(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ne(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ne(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Te(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Ne(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw Ne(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ne(this,8);let e=Mn(this.buf,this.pos+=4),r=Mn(this.buf,this.pos+=4);return new Te(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Ls(this.buf,this.pos);return this.pos+=Ae(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Yr(t){return new Us(t instanceof Uint8Array?t:t.subarray())}function ke(t,e,r){let n=Yr(t);return e.decode(n,void 0,r)}function Ks(t){let e=t??8192,r=e>>>1,n,o=e;return function(i){if(i<1||i>r)return Se(i);o+i>e&&(n=Se(e),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Rt=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function Ms(){}var qs=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},dd=Ks();function hd(t){return globalThis.Buffer!=null?Se(t):dd(t)}var Gr=class{len;head;tail;states;constructor(){this.len=0,this.head=new Rt(Ms,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Rt(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new Hs((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(Vn,10,Te.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=Te.fromBigInt(e);return this._push(Vn,r.length(),r)}uint64Number(e){return this._push(or,Ae(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=Te.fromBigInt(e).zzEncode();return this._push(Vn,r.length(),r)}sint64Number(e){let r=Te.fromNumber(e).zzEncode();return this._push(Vn,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(Vs,1,e?1:0)}fixed32(e){return this._push(Zr,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=Te.fromBigInt(e);return this._push(Zr,4,r.lo)._push(Zr,4,r.hi)}fixed64Number(e){let r=Te.fromNumber(e);return this._push(Zr,4,r.lo)._push(Zr,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(vc,4,e)}double(e){return this._push(Ic,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(Vs,1,0):this.uint32(r)._push(md,r,e)}string(e){let r=Cc(e);return r!==0?this.uint32(r)._push(ks,r,e):this._push(Vs,1,0)}fork(){return this.states=new qs(this),this.head=this.tail=new Rt(Ms,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 Rt(Ms,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=hd(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function Vs(t,e,r){e[r]=t&255}function pd(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var Hs=class extends Rt{next;constructor(e,r){super(pd,e,r),this.next=void 0}};function Vn(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function Zr(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function md(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(Gr.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(yd,e,t),this},Gr.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(bd,e,t),this});function yd(t,e,r){e.set(t,r)}function bd(t,e,r){t.length<40?ks(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(K(t),r)}function zs(){return new Gr}function Ue(t,e){let r=zs();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}function*Ke(t,e,r){let n=Yr(t);yield*e.stream(n,void 0,"$",r)}var qn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Hn(t,e,r,n,o){return{name:t,type:e,encode:r,decode:n,stream:o}}function $s(t){function e(s){if(t[s.toString()]==null)throw new Error("Invalid enum value");return t[s]}let r=function(i,a){let u=e(i);a.int32(u)},n=function(i){let a=i.int32();return e(a)},o=function*(i){let a=i.int32();yield e(a)};return Hn("enum",qn.VARINT,r,n,o)}function Me(t,e,r){return Hn("message",qn.LENGTH_DELIMITED,t,e,r)}var Ye=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var J;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(J||(J={}));var js;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(js||(js={}));(function(t){t.codec=()=>$s(js)})(J||(J={}));var Ze;(function(t){let e;t.codec=()=>(e==null&&(e=Me((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),J.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let u={},c=i==null?s.len:s.pos+i;for(;s.pos<c;){let f=s.uint32();switch(f>>>3){case 1:{u.Type=J.codec().decode(s);break}case 2:{u.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return u},function*(s,i,a,u={}){let c=i==null?s.len:s.pos+i;for(;s.pos<c;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:J.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return Ue(s,t.codec())}t.encode=r;function n(s,i){return ke(s,t.codec(),i)}t.decode=n;function o(s,i){return Ke(s,t.codec(),i)}t.stream=o})(Ze||(Ze={}));var Ys;(function(t){let e;t.codec=()=>(e==null&&(e=Me((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),J.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let u={},c=i==null?s.len:s.pos+i;for(;s.pos<c;){let f=s.uint32();switch(f>>>3){case 1:{u.Type=J.codec().decode(s);break}case 2:{u.Data=s.bytes();break}default:{s.skipType(f&7);break}}}return u},function*(s,i,a,u={}){let c=i==null?s.len:s.pos+i;for(;s.pos<c;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:J.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return Ue(s,t.codec())}t.encode=r;function n(s,i){return ke(s,t.codec(),i)}t.decode=n;function o(s,i){return Ke(s,t.codec(),i)}t.stream=o})(Ys||(Ys={}));var Xr={};ve(Xr,{MAX_RSA_KEY_SIZE:()=>Zs,generateRSAKeyPair:()=>Rc,jwkToJWKKeyPair:()=>Fc,jwkToPkcs1:()=>Ed,jwkToPkix:()=>Qs,jwkToRSAPrivateKey:()=>ri,pkcs1MessageToJwk:()=>Ws,pkcs1MessageToRSAPrivateKey:()=>Js,pkcs1ToJwk:()=>wd,pkcs1ToRSAPrivateKey:()=>Lc,pkixMessageToJwk:()=>Xs,pkixMessageToRSAPublicKey:()=>ti,pkixToJwk:()=>vd,pkixToRSAPublicKey:()=>ei});var ir=class{type="RSA";jwk;_raw;_multihash;constructor(e,r){this.jwk=e,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Xr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return fe.createV1(114,this._multihash)}toString(){return ne.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:le(this.raw,e.raw)}verify(e,r,n){return Pc(this.jwk,r,e,n)}},Wr=class{type="RSA";jwk;_raw;publicKey;constructor(e,r){this.jwk=e,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Xr.jwkToPkcs1(this.jwk)),this._raw}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:le(this.raw,e.raw)}sign(e,r){return Oc(this.jwk,e,r)}};var Zs=8192,Gs=18,gd=1062,xd=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function wd(t){let e=et(t);return Ws(e)}function Ws(t){return{n:q(t[1],"base64url"),e:q(t[2],"base64url"),d:q(t[3],"base64url"),p:q(t[4],"base64url"),q:q(t[5],"base64url"),dp:q(t[6],"base64url"),dq:q(t[7],"base64url"),qi:q(t[8],"base64url"),kty:"RSA"}}function Ed(t){if(t.n==null||t.e==null||t.d==null||t.p==null||t.q==null||t.dp==null||t.dq==null||t.qi==null)throw new Q("JWK was missing components");return lt([Ie(Uint8Array.from([0])),Ie(K(t.n,"base64url")),Ie(K(t.e,"base64url")),Ie(K(t.d,"base64url")),Ie(K(t.p,"base64url")),Ie(K(t.q,"base64url")),Ie(K(t.dp,"base64url")),Ie(K(t.dq,"base64url")),Ie(K(t.qi,"base64url"))]).subarray()}function vd(t){let e=et(t,{offset:0});return Xs(e)}function Xs(t){let e=et(t[1],{offset:0});return{kty:"RSA",n:q(e[0],"base64url"),e:q(e[1],"base64url")}}function Qs(t){if(t.n==null||t.e==null)throw new Q("JWK was missing components");return lt([xd,wn(lt([Ie(K(t.n,"base64url")),Ie(K(t.e,"base64url"))]))]).subarray()}function Lc(t){let e=et(t);return Js(e)}function Js(t){let e=Ws(t);return ri(e)}function ei(t,e){if(t.byteLength>=gd)throw new qt("Key size is too large");let r=et(t,{offset:0});return ti(r,t,e)}function ti(t,e,r){let n=Xs(t);if(r==null){let o=Gt(Ze.encode({Type:J.RSA,Data:e}));r=He(Gs,o)}return new ir(n,r)}function ri(t){if(kc(t)>Zs)throw new Q("Key size is too large");let e=Fc(t),r=Gt(Ze.encode({Type:J.RSA,Data:Qs(e.publicKey)})),n=He(Gs,r);return new Wr(e.privateKey,new ir(e.publicKey,n))}async function Rc(t){if(t>Zs)throw new Q("Key size is too large");let e=await Nc(t),r=Gt(Ze.encode({Type:J.RSA,Data:Qs(e.publicKey)})),n=He(Gs,r);return new Wr(e.privateKey,new ir(e.publicKey,n))}function Fc(t){if(t==null)throw new Q("Missing key parameter");return{privateKey:t,publicKey:{kty:t.kty,n:t.n,e:t.e}}}async function Nc(t,e){let r=await Be.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:t,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);e?.signal?.throwIfAborted();let n=await Sd(r,e);return{privateKey:n[0],publicKey:n[1]}}async function Oc(t,e,r){let n=await Be.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Be.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,e instanceof Uint8Array?e:e.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function Pc(t,e,r,n){let o=await Be.get().subtle.importKey("jwk",t,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Be.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,e,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),s}async function Sd(t,e){if(t.privateKey==null||t.publicKey==null)throw new Q("Private and public key are required");let r=await Promise.all([Be.get().subtle.exportKey("jwk",t.privateKey),Be.get().subtle.exportKey("jwk",t.publicKey)]);return e?.signal?.throwIfAborted(),r}function kc(t){if(t.kty!=="RSA")throw new Q("invalid key type");if(t.n==null)throw new Q("invalid key modulus");return K(t.n,"base64url").length*8}var zn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,r){if(En(e),Ce(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),rt(o)}update(e){return Zt(this),this.iHash.update(e),this}digestInto(e){Zt(this),vn(e,this),this.finished=!0;let r=e.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=a,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Uc=(()=>{let t=((e,r,n)=>new zn(e,r).update(n).digest());return t.create=(e,r)=>new zn(e,r),t})();var Kc=(t,e)=>(t+(t>=0?e:-e)/Mc)/e;function Id(t,e,r){Qt("scalar",t,Ge,r);let[[n,o],[s,i]]=e,a=Kc(i*t,r),u=Kc(-o*t,r),c=t-a*n-u*s,f=-a*o-u*i,l=c<Ge,h=f<Ge;l&&(c=-c),h&&(f=-f);let d=Vr(Math.ceil(Jt(r)/2))+Et;if(c<Ge||c>=d||f<Ge||f>=d)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:c,k2neg:h,k2:f}}function oi(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function ni(t,e){Fe(t);let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return Le(r.lowS,"lowS"),Le(r.prehash,"prehash"),r.format!==void 0&&oi(r.format),r}var si=class extends Error{constructor(e=""){super(e)}},Ve={Err:si,_tlv:{encode:(t,e)=>{let{Err:r}=Ve;if(Re(t,"tag"),t<0||t>255)throw new r("tlv.encode: wrong tag");if(typeof e!="string")throw new TypeError('"data" expected string, got type='+typeof e);if(e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,o=Kr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Kr(o.length/2|128):"";return Kr(t)+s+o+e},decode(t,e){let{Err:r}=Ve;e=H(e,void 0,"DER data");let n=0;if(t<0||t>255)throw new r("tlv.encode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let o=e[n++],s=!!(o&128),i=0;if(!s)i=o;else{let u=o&127;if(!u)throw new r("tlv.decode(long): indefinite length not supported");if(u>4)throw new r("tlv.decode(long): byte length is too big");let c=e.subarray(n,n+u);if(c.length!==u)throw new r("tlv.decode: length bytes not complete");if(c[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of c)i=i<<8|f;if(n+=u,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+i)}}},_int:{encode(t){let{Err:e}=Ve;if(Bn(t),t<Ge)throw new e("integer: negative integers are not allowed");let r=Kr(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=Ve;if(t.length<1)throw new e("invalid signature integer: empty");if(t[0]&128)throw new e("invalid signature integer: negative");if(t.length>1&&t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return Bt(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=Ve,o=H(t,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:u}=n.decode(2,s),{v:c,l:f}=n.decode(2,u);if(f.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(c)}},hexFromSig(t){let{_tlv:e,_int:r}=Ve,n=e.encode(2,r.encode(t.r)),o=e.encode(2,r.encode(t.s)),s=n+o;return e.encode(48,s)}};Object.freeze(Ve._tlv);Object.freeze(Ve._int);Object.freeze(Ve);var Ge=BigInt(0),Et=BigInt(1),Mc=BigInt(2),$n=BigInt(3),Ad=BigInt(4);function Vc(t,e={}){let r=Ln("weierstrass",t,e),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;Fe(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:u,allowInfinityPoint:c}=e;if(u&&(!n.is0(s.a)||typeof u.beta!="bigint"||!Array.isArray(u.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=Hc(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function h(k,p,g){if(c&&p.is0())return Uint8Array.of(0);let{x:v,y:w}=p.toAffine(),x=n.toBytes(v);if(Le(g,"isCompressed"),g){l();let I=!n.isOdd(w);return ae(qc(I),x)}else return ae(Uint8Array.of(4),x,n.toBytes(w))}function d(k){H(k,void 0,"Point");let{publicKey:p,publicKeyUncompressed:g}=f,v=k.length,w=k[0],x=k.subarray(1);if(c&&v===1&&w===0)return{x:n.ZERO,y:n.ZERO};if(v===p&&(w===2||w===3)){let I=n.fromBytes(x);if(!n.isValid(I))throw new Error("bad point: is not on curve, wrong x");let T=y(I),_;try{_=n.sqrt(T)}catch(V){let j=V instanceof Error?": "+V.message:"";throw new Error("bad point: is not on curve, sqrt error"+j)}l();let D=n.isOdd(_);return(w&1)===1!==D&&(_=n.neg(_)),{x:I,y:_}}else if(v===g&&w===4){let I=n.BYTES,T=n.fromBytes(x.subarray(0,I)),_=n.fromBytes(x.subarray(I,I*2));if(!E(T,_))throw new Error("bad point: is not on curve");return{x:T,y:_}}else throw new Error(`bad point: got length ${v}, expected compressed=${p} or uncompressed=${g}`)}let m=e.toBytes===void 0?h:e.toBytes,b=e.fromBytes===void 0?d:e.fromBytes;function y(k){let p=n.sqr(k),g=n.mul(p,k);return n.add(n.add(g,n.mul(k,s.a)),s.b)}function E(k,p){let g=n.sqr(p),v=y(k);return n.eql(g,v)}if(!E(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let S=n.mul(n.pow(s.a,$n),Ad),A=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(S,A)))throw new Error("bad curve params: a or b");function O(k,p,g=!1){if(!n.isValid(p)||g&&n.is0(p))throw new Error(`bad point coordinate ${k}`);return p}function B(k){if(!(k instanceof C))throw new Error("Weierstrass Point expected")}function F(k){if(!u||!u.basises)throw new Error("no endo");return Id(k,u.basises,o.ORDER)}function P(k,p,g,v,w){return g=new C(n.mul(g.X,k),g.Y,g.Z),p=Hr(v,p),g=Hr(w,g),p.add(g)}class C{static BASE=new C(s.Gx,s.Gy,n.ONE);static ZERO=new C(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(p,g,v){this.X=O("x",p),this.Y=O("y",g,!0),this.Z=O("z",v),Object.freeze(this)}static CURVE(){return s}static fromAffine(p){let{x:g,y:v}=p||{};if(!p||!n.isValid(g)||!n.isValid(v))throw new Error("invalid affine point");if(p instanceof C)throw new Error("projective point not allowed");return n.is0(g)&&n.is0(v)?C.ZERO:new C(g,v,n.ONE)}static fromBytes(p){let g=C.fromAffine(b(H(p,void 0,"point")));return g.assertValidity(),g}static fromHex(p){return C.fromBytes(Xt(p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=8,g=!0){return Z.createCache(this,p),g||this.multiply($n),this}assertValidity(){let p=this;if(p.is0()){if(e.allowInfinityPoint&&n.is0(p.X)&&n.eql(p.Y,n.ONE)&&n.is0(p.Z))return;throw new Error("bad point: ZERO")}let{x:g,y:v}=p.toAffine();if(!n.isValid(g)||!n.isValid(v))throw new Error("bad point: x or y not field elements");if(!E(g,v))throw new Error("bad point: equation left != right");if(!p.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:p}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(p)}equals(p){B(p);let{X:g,Y:v,Z:w}=this,{X:x,Y:I,Z:T}=p,_=n.eql(n.mul(g,T),n.mul(x,w)),D=n.eql(n.mul(v,T),n.mul(I,w));return _&&D}negate(){return new C(this.X,n.neg(this.Y),this.Z)}double(){let{a:p,b:g}=s,v=n.mul(g,$n),{X:w,Y:x,Z:I}=this,T=n.ZERO,_=n.ZERO,D=n.ZERO,R=n.mul(w,w),V=n.mul(x,x),j=n.mul(I,I),U=n.mul(w,x);return U=n.add(U,U),D=n.mul(w,I),D=n.add(D,D),T=n.mul(p,D),_=n.mul(v,j),_=n.add(T,_),T=n.sub(V,_),_=n.add(V,_),_=n.mul(T,_),T=n.mul(U,T),D=n.mul(v,D),j=n.mul(p,j),U=n.sub(R,j),U=n.mul(p,U),U=n.add(U,D),D=n.add(R,R),R=n.add(D,R),R=n.add(R,j),R=n.mul(R,U),_=n.add(_,R),j=n.mul(x,I),j=n.add(j,j),R=n.mul(j,U),T=n.sub(T,R),D=n.mul(j,V),D=n.add(D,D),D=n.add(D,D),new C(T,_,D)}add(p){B(p);let{X:g,Y:v,Z:w}=this,{X:x,Y:I,Z:T}=p,_=n.ZERO,D=n.ZERO,R=n.ZERO,V=s.a,j=n.mul(s.b,$n),U=n.mul(g,x),ie=n.mul(v,I),ce=n.mul(w,T),ue=n.add(g,v),re=n.add(x,I);ue=n.mul(ue,re),re=n.add(U,ie),ue=n.sub(ue,re),re=n.add(g,w);let Ee=n.add(x,T);return re=n.mul(re,Ee),Ee=n.add(U,ce),re=n.sub(re,Ee),Ee=n.add(v,w),_=n.add(I,T),Ee=n.mul(Ee,_),_=n.add(ie,ce),Ee=n.sub(Ee,_),R=n.mul(V,re),_=n.mul(j,ce),R=n.add(_,R),_=n.sub(ie,R),R=n.add(ie,R),D=n.mul(_,R),ie=n.add(U,U),ie=n.add(ie,U),ce=n.mul(V,ce),re=n.mul(j,re),ie=n.add(ie,ce),ce=n.sub(U,ce),ce=n.mul(V,ce),re=n.add(re,ce),U=n.mul(ie,re),D=n.add(D,U),U=n.mul(Ee,re),_=n.mul(ue,_),_=n.sub(_,U),U=n.mul(ue,ie),R=n.mul(Ee,R),R=n.add(R,U),new C(_,D,R)}subtract(p){return B(p),this.add(p.negate())}is0(){return this.equals(C.ZERO)}multiply(p){let{endo:g}=e;if(!o.isValidNot0(p))throw new RangeError("invalid scalar: out of range");let v,w,x=I=>Z.cached(this,I,T=>Pt(C,T));if(g){let{k1neg:I,k1:T,k2neg:_,k2:D}=F(p),{p:R,f:V}=x(T),{p:j,f:U}=x(D);w=V.add(U),v=P(g.beta,R,j,I,_)}else{let{p:I,f:T}=x(p);v=I,w=T}return Pt(C,[v,w])[0]}multiplyUnsafe(p){let{endo:g}=e,v=this,w=p;if(!o.isValid(w))throw new RangeError("invalid scalar: out of range");if(w===Ge||v.is0())return C.ZERO;if(w===Et)return v;if(Z.hasCache(this))return this.multiply(w);if(g){let{k1neg:x,k1:I,k2neg:T,k2:_}=F(w),{p1:D,p2:R}=fc(C,v,I,_);return P(g.beta,D,R,x,T)}else return Z.unsafe(v,w)}toAffine(p){let g=this,v=p,{X:w,Y:x,Z:I}=g;if(n.eql(I,n.ONE))return{x:w,y:x};let T=g.is0();v==null&&(v=T?n.ONE:n.inv(I));let _=n.mul(w,v),D=n.mul(x,v),R=n.mul(I,v);if(T)return{x:n.ZERO,y:n.ZERO};if(!n.eql(R,n.ONE))throw new Error("invZ was invalid");return{x:_,y:D}}isTorsionFree(){let{isTorsionFree:p}=e;return i===Et?!0:p?p(C,this):Z.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:p}=e;return i===Et?this:p?p(C,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===Et?this.is0():this.clearCofactor().is0()}toBytes(p=!0){return Le(p,"isCompressed"),this.assertValidity(),m(C,this,p)}toHex(p=!0){return Wt(this.toBytes(p))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let N=o.BITS,Z=new rr(C,e.endo?Math.ceil(N/2):N);return N>=8&&C.BASE.precompute(8),Object.freeze(C.prototype),Object.freeze(C),C}function qc(t){return Uint8Array.of(t?2:3)}function Hc(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function _d(t,e={}){let{Fn:r}=t,n=e.randomBytes===void 0?Ur:e.randomBytes,o=Object.assign(Hc(t.Fp,r),{seed:Math.max(ps(r.ORDER),16)});function s(d){try{let m=r.fromBytes(d);return r.isValidNot0(m)}catch{return!1}}function i(d,m){let{publicKey:b,publicKeyUncompressed:y}=o;try{let E=d.length;return m===!0&&E!==b||m===!1&&E!==y?!1:!!t.fromBytes(d)}catch{return!1}}function a(d){return d=d===void 0?n(o.seed):d,ms(H(d,o.seed,"seed"),r.ORDER)}function u(d,m=!0){return t.BASE.multiply(r.fromBytes(d)).toBytes(m)}function c(d){let{secretKey:m,publicKey:b,publicKeyUncompressed:y}=o,E=r._lengths;if(!Tt(d))return;let S=H(d,void 0,"key").length,A=S===b||S===y,O=S===m||!!E?.includes(S);if(!(A&&O))return A}function f(d,m,b=!0){if(c(d)===!0)throw new Error("first arg must be private key");if(c(m)===!1)throw new Error("second arg must be public key");let y=r.fromBytes(d);return t.fromBytes(m).multiply(y).toBytes(b)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},h=Rn(a,u);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:u,getSharedSecret:f,keygen:h,Point:t,utils:l,lengths:o})}function zc(t,e,r={}){let n=e;En(n),Fe(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let o=r.randomBytes===void 0?Ur:r.randomBytes,s=r.hmac===void 0?(w,x)=>Uc(n,w,x):r.hmac,{Fp:i,Fn:a}=t,{ORDER:u,BITS:c}=a,{keygen:f,getPublicKey:l,getSharedSecret:h,utils:d,lengths:m}=_d(t,r),b={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},y=u*Mc+Et<i.ORDER;function E(w){let x=u>>Et;return w>x}function S(w,x){if(!a.isValidNot0(x))throw new Error(`invalid signature ${w}: out of range 1..Point.Fn.ORDER`);return x}function A(){if(y)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function O(w,x){oi(x);let I=m.signature,T=x==="compact"?I:x==="recovered"?I+1:void 0;return H(w,T)}class B{r;s;recovery;constructor(x,I,T){if(this.r=S("r",x),this.s=S("s",I),T!=null){if(A(),![0,1,2,3].includes(T))throw new Error("invalid recovery id");this.recovery=T}Object.freeze(this)}static fromBytes(x,I=b.format){O(x,I);let T;if(I==="der"){let{r:V,s:j}=Ve.toSig(H(x));return new B(V,j)}I==="recovered"&&(T=x[0],I="compact",x=x.subarray(1));let _=m.signature/2,D=x.subarray(0,_),R=x.subarray(_,_*2);return new B(a.fromBytes(D),a.fromBytes(R),T)}static fromHex(x,I){return this.fromBytes(Xt(x),I)}assertRecovery(){let{recovery:x}=this;if(x==null)throw new Error("invalid recovery id: must be present");return x}addRecoveryBit(x){return new B(this.r,this.s,x)}recoverPublicKey(x){let{r:I,s:T}=this,_=this.assertRecovery(),D=_===2||_===3?I+u:I;if(!i.isValid(D))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let R=i.toBytes(D),V=t.fromBytes(ae(qc((_&1)===0),R)),j=a.inv(D),U=P(H(x,void 0,"msgHash")),ie=a.create(-U*j),ce=a.create(T*j),ue=t.BASE.multiplyUnsafe(ie).add(V.multiplyUnsafe(ce));if(ue.is0())throw new Error("invalid recovery: point at infinify");return ue.assertValidity(),ue}hasHighS(){return E(this.s)}toBytes(x=b.format){if(oi(x),x==="der")return Xt(Ve.hexFromSig(this));let{r:I,s:T}=this,_=a.toBytes(I),D=a.toBytes(T);return x==="recovered"?(A(),ae(Uint8Array.of(this.assertRecovery()),_,D)):ae(_,D)}toHex(x){return Wt(this.toBytes(x))}}Object.freeze(B.prototype),Object.freeze(B);let F=r.bits2int===void 0?function(x){if(x.length>8192)throw new Error("input is too large");let I=Bt(x),T=x.length*8-c;return T>0?I>>BigInt(T):I}:r.bits2int,P=r.bits2int_modN===void 0?function(x){return a.create(F(x))}:r.bits2int_modN,C=Vr(c);function N(w){return Qt("num < 2^"+c,w,Ge,C),a.toBytes(w)}function Z(w,x){return H(w,void 0,"message"),x?H(n(w),void 0,"prehashed message"):w}function k(w,x,I){let{lowS:T,prehash:_,extraEntropy:D}=ni(I,b);w=Z(w,_);let R=P(w),V=a.fromBytes(x);if(!a.isValidNot0(V))throw new Error("invalid private key");let j=[N(V),N(R)];if(D!=null&&D!==!1){let ue=D===!0?o(m.secretKey):D;j.push(H(ue,void 0,"extraEntropy"))}let U=ae(...j),ie=R;function ce(ue){let re=F(ue);if(!a.isValidNot0(re))return;let Ee=a.inv(re),Vt=t.BASE.multiply(re).toAffine(),Ir=a.create(Vt.x);if(Ir===Ge)return;let dn=a.create(Ee*a.create(ie+Ir*V));if(dn===Ge)return;let ta=(Vt.x===Ir?0:2)|Number(Vt.y&Et),ra=dn;return T&&E(dn)&&(ra=a.neg(dn),ta^=1),new B(Ir,ra,y?void 0:ta)}return{seed:U,k2sig:ce}}function p(w,x,I={}){let{seed:T,k2sig:_}=k(w,x,I);return Ya(n.outputLen,a.BYTES,s)(T,_).toBytes(I.format)}function g(w,x,I,T={}){let{lowS:_,prehash:D,format:R}=ni(T,b);if(I=H(I,void 0,"publicKey"),x=Z(x,D),!Tt(w)){let V=w instanceof B?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+V)}O(w,R);try{let V=B.fromBytes(w,R),j=t.fromBytes(I);if(_&&V.hasHighS())return!1;let{r:U,s:ie}=V,ce=P(x),ue=a.inv(ie),re=a.create(ce*ue),Ee=a.create(U*ue),Vt=t.BASE.multiplyUnsafe(re).add(j.multiplyUnsafe(Ee));return Vt.is0()?!1:a.create(Vt.x)===U}catch{return!1}}function v(w,x,I={}){let{prehash:T}=ni(I,b);return x=Z(x,T),B.fromBytes(w,"recovered").recoverPublicKey(x).toBytes()}return Object.freeze({keygen:f,getPublicKey:l,getSharedSecret:h,utils:d,lengths:m,Point:t,sign:p,verify:g,recoverPublicKey:v,Signature:B,hash:n})}var ai={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Cd={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var $c=BigInt(2);function Td(t){let e=ai.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),u=BigInt(88),c=t*t*t%e,f=c*c*t%e,l=X(f,r,e)*f%e,h=X(l,r,e)*f%e,d=X(h,$c,e)*c%e,m=X(d,o,e)*d%e,b=X(m,s,e)*m%e,y=X(b,a,e)*b%e,E=X(y,u,e)*y%e,S=X(E,a,e)*b%e,A=X(S,r,e)*f%e,O=X(A,i,e)*m%e,B=X(O,n,e)*c%e,F=X(B,$c,e);if(!ii.eql(ii.sqr(F),t))throw new Error("Cannot find square root");return F}var ii=er(ai.p,{sqrt:Td}),Bd=Vc(ai,{Fp:ii,endo:Cd}),ar=zc(Bd,Gt);function jc(t,e,r,n){let o=Dr.digest(r instanceof Uint8Array?r:r.subarray());if(Un(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),ar.verify(e,s,t,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new $r(String(s))});try{return n?.signal?.throwIfAborted(),ar.verify(e,o.digest,t,{prehash:!1,format:"der"})}catch(s){throw new $r(String(s))}}var jn=class{type="secp256k1";raw;_key;constructor(e){this._key=Zc(e),this.raw=Yc(this._key)}toMultihash(){return Oe.digest(ze(this))}toCID(){return fe.createV1(114,this.toMultihash())}toString(){return ne.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:le(this.raw,e.raw)}verify(e,r,n){return jc(this._key,r,e,n)}};function ci(t){return new jn(t)}function Yc(t){return ar.Point.fromBytes(t).toBytes()}function Zc(t){try{return ar.Point.fromBytes(t),t}catch(e){throw new qt(String(e))}}function cr(t,e){let{Type:r,Data:n}=Ze.decode(t),o=n??new Uint8Array;switch(r){case J.RSA:return ei(o,e);case J.Ed25519:return Ts(o);case J.secp256k1:return ci(o);case J.ECDSA:return Xo(o);default:throw new It}}function Gc(t){let{Type:e,Data:r}=Ze.decode(t.digest),n=r??new Uint8Array;switch(e){case J.Ed25519:return Ts(n);case J.secp256k1:return ci(n);case J.ECDSA:return Xo(n);default:throw new It}}function ze(t){return Ze.encode({Type:J[t.type],Data:t.raw})}var Qr;(function(t){let e;t.codec=()=>(e==null&&(e=Me((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.publicKey!=null&&s.publicKey.byteLength>0&&(i.uint32(10),i.bytes(s.publicKey)),s.payloadType!=null&&s.payloadType.byteLength>0&&(i.uint32(18),i.bytes(s.payloadType)),s.payload!=null&&s.payload.byteLength>0&&(i.uint32(26),i.bytes(s.payload)),s.signature!=null&&s.signature.byteLength>0&&(i.uint32(42),i.bytes(s.signature)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let u={publicKey:pe(0),payloadType:pe(0),payload:pe(0),signature:pe(0)},c=i==null?s.len:s.pos+i;for(;s.pos<c;){let f=s.uint32();switch(f>>>3){case 1:{u.publicKey=s.bytes();break}case 2:{u.payloadType=s.bytes();break}case 3:{u.payload=s.bytes();break}case 5:{u.signature=s.bytes();break}default:{s.skipType(f&7);break}}}return u},function*(s,i,a,u={}){let c=i==null?s.len:s.pos+i;for(;s.pos<c;){let f=s.uint32();switch(f>>>3){case 1:{yield{field:`${a}.publicKey`,value:s.bytes()};break}case 2:{yield{field:`${a}.payloadType`,value:s.bytes()};break}case 3:{yield{field:`${a}.payload`,value:s.bytes()};break}case 5:{yield{field:`${a}.signature`,value:s.bytes()};break}default:{s.skipType(f&7);break}}}})),e);function r(s){return Ue(s,t.codec())}t.encode=r;function n(s,i){return ke(s,t.codec(),i)}t.decode=n;function o(s,i){return Ke(s,t.codec(),i)}t.stream=o})(Qr||(Qr={}));var Yn=class extends Error{constructor(e="Invalid signature"){super(e),this.name="InvalidSignatureError"}};var We=class t{static createFromProtobuf=e=>{let r=Qr.decode(e),n=cr(r.publicKey);return new t({publicKey:n,payloadType:r.payloadType,payload:r.payload,signature:r.signature})};static seal=async(e,r,n)=>{if(r==null)throw new Error("Missing private key");let o=e.domain,s=e.codec,i=e.marshal(),a=Wc(o,s,i),u=await r.sign(a.subarray(),n);return new t({publicKey:r.publicKey,payloadType:s,payload:i,signature:u})};static openAndCertify=async(e,r,n)=>{let o=t.createFromProtobuf(e);if(!await o.validate(r,n))throw new Yn("Envelope signature is not valid for the given domain");return o};publicKey;payloadType;payload;signature;marshaled;constructor(e){let{publicKey:r,payloadType:n,payload:o,signature:s}=e;this.publicKey=r,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=Qr.encode({publicKey:ze(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(e){return e==null?!1:le(this.marshal(),e.marshal())}async validate(e,r){let n=Wc(e,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},Wc=(t,e,r)=>{let n=K(t),o=sr(n.byteLength),s=sr(e.length),i=sr(r.length);return new se(o,n,s,e,i,r)};var Xc=Symbol.for("nodejs.util.inspect.custom"),Dd=114,Jr=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[So]=!0;toString(){return this.string==null&&(this.string=ne.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return fe.createV1(Dd,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return le(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return le(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[Xc](){return`PeerId(${this.toString()})`}},en=class extends Jr{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},tn=class extends Jr{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},rn=class extends Jr{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},Od=2336,nn=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Oe.digest(K(this.url))}[Xc](){return`PeerId(${this.url})`}[So]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return fe.createV1(Od,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=q(e)),e.toString()===this.toString())}};var Pd=114,Qc=2336;function Jc(t){if(t.type==="Ed25519")return new tn({multihash:t.toCID().multihash,publicKey:t});if(t.type==="secp256k1")return new rn({multihash:t.toCID().multihash,publicKey:t});if(t.type==="RSA")return new en({multihash:t.toCID().multihash,publicKey:t});throw new It}function ui(t){if(Rd(t))return new en({multihash:t});if(Ld(t))try{let e=Gc(t);if(e.type==="Ed25519")return new tn({multihash:t,publicKey:e});if(e.type==="secp256k1")return new rn({multihash:t,publicKey:e})}catch{let r=q(t.digest);return new nn(new URL(r))}throw new mn("Supplied PeerID Multihash is invalid")}function Zn(t){if(t?.multihash==null||t.version==null||t.version===1&&t.code!==Pd&&t.code!==Qc)throw new pn("Supplied PeerID CID is invalid");if(t.code===Qc){let e=q(t.multihash.digest);return new nn(new URL(e))}return ui(t.multihash)}function Ld(t){return t.code===Oe.code}function Rd(t){return t.code===Dr.code}var be=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},it=class extends Error{static name="ValidationError";name="ValidationError"},Gn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Wn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var Xn=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let r=this.index,n=e();return n===void 0&&(this.index=r),n}parseWith(e){let r=e();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let r=this.readChar();if(r===e)return r})}readSeparator(e,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,r,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let u=a==="0",c=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let h=Number.parseInt(l,e);if(!Number.isNaN(h))return h});if(f===void 0)break;if(s*=e,s+=f,s>c||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&u&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let r=0;r<e.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[r]=n}return e})}readIPv6Addr(){let e=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=e(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var eu=45,Fd=15,ur=new Xn;function Qn(t){if(!(t.length>Fd))return ur.new(t).parseWith(()=>ur.readIPv4Addr())}function Jn(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>eu))return ur.new(t).parseWith(()=>ur.readIPv6Addr())}function fr(t,e=!1){if(t.includes("%")&&(t=t.split("%")[0]),t.length>eu)return;let r=ur.new(t).parseWith(()=>ur.readIPAddr());if(r)return e&&r.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,r[0],r[1],r[2],r[3]]):r}function lr(t){return!!Qn(t)}function eo(t){return!!Jn(t)}function li(t){return e=>q(e,t)}function di(t){return e=>K(e,t)}function dr(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function Ft(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function tu(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let r=K(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Ft(n);return Je([r,o],r.length+o.length)}function ru(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let r=ft.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Ft(n);return Je([r,o],r.length+o.length)}function hi(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=q(e,"base32"),o=dr(r);return`${n}:${o}`}var pi=function(t){t=t.toString().trim();let e=new Uint8Array(4);return t.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new be("Invalid byte value in IP address");e[n]=o}),e},nu=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let s=lr(r[n]),i;s&&(i=pi(r[n]),r[n]=q(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,q(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(e+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new be("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},ou=function(t){if(t.byteLength!==4)throw new be("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},su=function(t){if(t.byteLength!==16)throw new be("IPv6 address was incorrect length");let e=[];for(let n=0;n<t.byteLength;n+=2){let o=t[n],s=t[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;e.push(i)}let r=e.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new be(`Invalid IPv6 address "${r}"`)}};function iu(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new be(`Invalid IPv6 address "${t}"`)}}var fi=Object.values(Or).map(t=>t.decoder),Nd=(function(){let t=fi[0].or(fi[1]);return fi.slice(2).forEach(e=>t=t.or(e)),t})();function au(t){return Nd.decode(t)}function cu(t){return e=>t.encoder.encode(e)}function kd(t){if(parseInt(t).toString()!==t)throw new it("Value must be an integer")}function Ud(t){if(t<0)throw new it("Value must be a positive integer, or zero")}function Kd(t){return e=>{if(e>t)throw new it(`Value must be smaller than or equal to ${t}`)}}function Md(...t){return e=>{for(let r of t)r(e)}}var on=Md(kd,Ud,Kd(65535));var he=-1,mi=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let r;if(typeof e=="string"?r=this.protocolsByName.get(e):r=this.protocolsByCode.get(e),r==null)throw new Wn(`Protocol ${e} was unknown`);return r}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(r=>{this.protocolsByName.set(r,e)})}removeProtocol(e){let r=this.protocolsByCode.get(e);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},ct=new mi,eh=[{code:4,name:"ip4",size:32,valueToBytes:pi,bytesToValue:ou,validate:t=>{if(!lr(t))throw new it(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Ft,bytesToValue:dr,validate:on},{code:273,name:"udp",size:16,valueToBytes:Ft,bytesToValue:dr,validate:on},{code:33,name:"dccp",size:16,valueToBytes:Ft,bytesToValue:dr,validate:on},{code:41,name:"ip6",size:128,valueToBytes:nu,bytesToValue:su,stringToValue:iu,validate:t=>{if(!eo(t))throw new it(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:he},{code:43,name:"ipcidr",size:8,bytesToValue:li("base10"),valueToBytes:di("base10")},{code:53,name:"dns",size:he},{code:54,name:"dns4",size:he},{code:55,name:"dns6",size:he},{code:56,name:"dnsaddr",size:he},{code:132,name:"sctp",size:16,valueToBytes:Ft,bytesToValue:dr,validate:on},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:he,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:he,bytesToValue:li("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?di("base58btc")(t):fe.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:hi,valueToBytes:tu},{code:445,name:"onion3",size:296,bytesToValue:hi,valueToBytes:ru},{code:446,name:"garlic64",size:he},{code:447,name:"garlic32",size:he},{code:448,name:"tls"},{code:449,name:"sni",size:he},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:he,bytesToValue:cu(Uo),valueToBytes:au},{code:480,name:"http"},{code:481,name:"http-path",size:he,stringToValue:t=>`/${decodeURIComponent(t)}`,valueToString:t=>encodeURIComponent(t.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:he}];eh.forEach(t=>{ct.addProtocol(t)});function uu(t){let e=[],r=0;for(;r<t.length;){let n=jr(t,r),o=ct.getProtocol(n),s=Ae(n),i=th(o,t,r+s),a=0;i>0&&o.size===he&&(a=Ae(i));let u=s+a+i,c={code:n,name:o.name,bytes:t.subarray(r,r+u)};if(i>0){let f=r+s+a,l=t.subarray(f,f+i);c.value=o.bytesToValue?.(l)??q(l)}e.push(c),r+=u}return e}function fu(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let o=ct.getProtocol(n.code),s=Ae(n.code),i,a=0,u=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??K(n.value),a=i.byteLength,o.size===he&&(u=Ae(a)));let c=new Uint8Array(s+u+a),f=0;or(n.code,c,f),f+=s,i!=null&&(o.size===he&&(or(a,c,f),f+=u),c.set(i,f)),n.bytes=c}r.push(n.bytes),e+=n.bytes.byteLength}return Je(r,e)}function lu(t){if(t.charAt(0)!=="/")throw new be('String multiaddr must start with "/"');let e=[],r="protocol",n="",o="";for(let s=1;s<t.length;s++){let i=t.charAt(s);i!=="/"&&(r==="protocol"?o+=t.charAt(s):n+=t.charAt(s));let a=s===t.length-1;if(i==="/"||a){let u=ct.getProtocol(o);if(r==="protocol"){if(u.size==null||u.size===0){e.push({code:u.code,name:u.name}),n="",o="",r="protocol";continue}else if(a)throw new be(`Component ${o} was missing value`);r="value"}else if(r==="value"){let c={code:u.code,name:u.name};if(u.size!=null&&u.size!==0){if(n==="")throw new be(`Component ${o} was missing value`);c.value=u.stringToValue?.(n)??n}e.push(c),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new be("Incomplete multiaddr");return e}function du(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=ct.getProtocol(e.code);if(r==null)throw new be(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function th(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:jr(e,r)}var rh=Symbol.for("nodejs.util.inspect.custom"),Di=Symbol.for("@multiformats/multiaddr");function nh(t){if(t==null&&(t="/"),hu(t))return t.getComponents();if(t instanceof Uint8Array)return uu(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),lu(t);if(Array.isArray(t))return t;throw new be("Must be a string, Uint8Array, Component[], or another Multiaddr")}var io=class t{[Di]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=nh(e),r.validate!==!1&&oh(this)}get bytes(){return this.#r==null&&(this.#r=fu(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=du(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}encapsulate(e){let r=new t(e);return new t([...this.#e,...r.getComponents()],{validate:!1})}decapsulate(e){let r=e.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new Gn(`Address ${this.toString()} does not contain subaddress: ${r}`);return new t(n.slice(0,o),{validate:!1})}decapsulateCode(e){let r;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){r=n;break}return new t(this.#e.slice(0,r),{validate:!1})}equals(e){return le(this.bytes,e.bytes)}[rh](){return`Multiaddr(${this.toString()})`}};function oh(t){t.getComponents().forEach(e=>{let r=ct.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function hu(t){return!!t?.[Di]}function an(t){return new io(t)}var pu="libp2p-peer-record",mu=Uint8Array.from([3,1]);var cn;(function(t){let e;(function(i){let a;i.codec=()=>(a==null&&(a=Me((l,h,d={})=>{d.lengthDelimited!==!1&&h.fork(),l.multiaddr!=null&&l.multiaddr.byteLength>0&&(h.uint32(10),h.bytes(l.multiaddr)),d.lengthDelimited!==!1&&h.ldelim()},(l,h,d={})=>{let m={multiaddr:pe(0)},b=h==null?l.len:l.pos+h;for(;l.pos<b;){let y=l.uint32();y>>>3===1?m.multiaddr=l.bytes():l.skipType(y&7)}return m},function*(l,h,d,m={}){let b=h==null?l.len:l.pos+h;for(;l.pos<b;){let y=l.uint32();y>>>3===1?yield{field:`${d}.multiaddr`,value:l.bytes()}:l.skipType(y&7)}})),a);function u(l){return Ue(l,i.codec())}i.encode=u;function c(l,h){return ke(l,i.codec(),h)}i.decode=c;function f(l,h){return Ke(l,i.codec(),h)}i.stream=f})(e=t.AddressInfo||(t.AddressInfo={}));let r;t.codec=()=>(r==null&&(r=Me((i,a,u={})=>{if(u.lengthDelimited!==!1&&a.fork(),i.peerId!=null&&i.peerId.byteLength>0&&(a.uint32(10),a.bytes(i.peerId)),i.seq!=null&&i.seq!==0n&&(a.uint32(16),a.uint64(i.seq)),i.addresses!=null&&i.addresses.length>0)for(let c of i.addresses)a.uint32(26),t.AddressInfo.codec().encode(c,a);u.lengthDelimited!==!1&&a.ldelim()},(i,a,u={})=>{let c={peerId:pe(0),seq:0n,addresses:[]},f=a==null?i.len:i.pos+a;for(;i.pos<f;){let l=i.uint32();switch(l>>>3){case 1:{c.peerId=i.bytes();break}case 2:{c.seq=i.uint64();break}case 3:{if(u.limits?.addresses!=null&&c.addresses.length===u.limits.addresses)throw new Ye('Decode error - repeated field "addresses" had too many elements');c.addresses.push(t.AddressInfo.codec().decode(i,i.uint32(),{limits:u.limits?.addresses$}));break}default:{i.skipType(l&7);break}}}return c},function*(i,a,u,c={}){let f={addresses:0},l=a==null?i.len:i.pos+a;for(;i.pos<l;){let h=i.uint32();switch(h>>>3){case 1:{yield{field:`${u}.peerId`,value:i.bytes()};break}case 2:{yield{field:`${u}.seq`,value:i.uint64()};break}case 3:{if(c.limits?.addresses!=null&&f.addresses===c.limits.addresses)throw new Ye('Streaming decode error - repeated field "addresses" had too many elements');for(let d of t.AddressInfo.codec().stream(i,i.uint32(),`${u}.addresses[]`,{limits:c.limits?.addresses$}))yield{...d,index:f.addresses};f.addresses++;break}default:{i.skipType(h&7);break}}}})),r);function n(i){return Ue(i,t.codec())}t.encode=n;function o(i,a){return ke(i,t.codec(),a)}t.decode=o;function s(i,a){return Ke(i,t.codec(),a)}t.stream=s})(cn||(cn={}));function yu(t,e){let r=(n,o)=>n.toString().localeCompare(o.toString());return t.length!==e.length?!1:(e.sort(r),t.sort(r).every((n,o)=>e[o].equals(n)))}var qe=class t{static createFromProtobuf=e=>{let r=cn.decode(e),n=ui(Tr(r.peerId)),o=(r.addresses??[]).map(i=>an(i.multiaddr)),s=r.seq;return new t({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=pu;static CODEC=mu;peerId;multiaddrs;seqNumber;domain=t.DOMAIN;codec=t.CODEC;marshaled;constructor(e){let{peerId:r,multiaddrs:n,seqNumber:o}=e;this.peerId=r,this.multiaddrs=n??[],this.seqNumber=o??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=cn.encode({peerId:this.peerId.toMultihash().bytes,seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(e=>({multiaddr:e.bytes}))})),this.marshaled}equals(e){return!(!(e instanceof t)||!this.peerId.equals(e.peerId)||this.seqNumber!==e.seqNumber||!yu(this.multiaddrs,e.multiaddrs))}};function sh(t){let e=t.getComponents(),r={},n=0;return e[n]?.name==="ip6zone"&&(r.zone=`${e[n].value}`,n++),e[n]?.name==="ip4"||e[n]?.name==="ip6"||e[n]?.name==="dns"||e[n]?.name==="dns4"||e[n]?.name==="dns6"?(r.type=e[n].name,r.host=e[n].value,n++):e[n]?.name==="dnsaddr"&&(r.type=e[n].name,r.host=`_dnsaddr.${e[n].value}`,n++),(e[n]?.name==="tcp"||e[n]?.name==="udp")&&(r.protocol=e[n].name==="tcp"?"tcp":"udp",r.port=parseInt(`${e[n].value}`),n++),e[n]?.name==="ipcidr"&&(r.type==="ip4"?r.cidr=parseInt(`${e[n].value}`):r.type==="ip6"&&(r.cidr=`${e[n].value}`),n++),r.type==null||r.host==null?null:(e[n]?.name==="tls"&&e[n+1]?.name==="sni"&&(r.sni=e[n+1].value,n+=2),r)}function ao(t){let e=sh(t);if(e==null)throw new Q(`Multiaddr ${t} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return e}function bu(t,e,r){let n=0;for(let o of t)if(!(n<e)){if(n>r)break;if(o!==255)return!1;n++}return!0}function gu(t,e,r,n){let o=0;for(let s of t)if(!(o<r)){if(o>n)break;if(s!==e[o])return!1;o++}return!0}function Oi(t){switch(t.length){case kt:return t.join(".");case Ut:{let e=[];for(let r=0;r<t.length;r++)r%2===0&&e.push(t[r].toString(16).padStart(2,"0")+t[r+1].toString(16).padStart(2,"0"));return e.join(":")}default:throw new Error("Invalid ip length")}}function xu(t){let e=0;for(let[r,n]of t.entries()){if(n===255){e+=8;continue}for(;(n&128)!=0;)e++,n=n<<1;if((n&128)!=0)return-1;for(let o=r+1;o<t.length;o++)if(t[o]!=0)return-1;break}return e}function wu(t){let e="0x";for(let r of t)e+=(r>>4).toString(16)+(r&15).toString(16);return e}var kt=4,Ut=16,_x=parseInt("0xFFFF",16),ih=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function un(t,e){e.length===Ut&&t.length===kt&&bu(e,0,11)&&(e=e.slice(12)),e.length===kt&&t.length===Ut&&gu(t,ih,0,11)&&(t=t.slice(12));let r=t.length;if(r!=e.length)throw new Error("Failed to mask ip");let n=new Uint8Array(r);for(let o=0;o<r;o++)n[o]=t[o]&e[o];return n}function Eu(t,e){if(typeof e=="string"&&(e=fr(e)),e==null)throw new Error("Invalid ip");if(e.length!==t.network.length)return!1;for(let r=0;r<e.length;r++)if((t.network[r]&t.mask[r])!==(e[r]&t.mask[r]))return!1;return!0}function Pi(t){let[e,r]=t.split("/");if(!e||!r)throw new Error("Failed to parse given CIDR: "+t);let n=kt,o=Qn(e);if(o==null&&(n=Ut,o=Jn(e),o==null))throw new Error("Failed to parse given CIDR: "+t);let s=parseInt(r,10);if(Number.isNaN(s)||String(s).length!==r.length||s<0||s>n*8)throw new Error("Failed to parse given CIDR: "+t);let i=Li(s,8*n);return{network:un(o,i),mask:i}}function Li(t,e){if(e!==8*kt&&e!==8*Ut)throw new Error("Invalid CIDR mask");if(t<0||t>e)throw new Error("Invalid CIDR mask");let r=e/8,n=new Uint8Array(r);for(let o=0;o<r;o++){if(t>=8){n[o]=255,t-=8;continue}n[o]=255-(255>>t),t=0}return n}var fn=class{constructor(e,r){if(r==null)({network:this.network,mask:this.mask}=Pi(e));else{let n=fr(e);if(n==null)throw new Error("Failed to parse network");r=String(r);let o=parseInt(r,10);if(Number.isNaN(o)||String(o).length!==r.length||o<0||o>n.length*8){let s=fr(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=Li(o,8*n.length);this.network=un(n,this.mask)}}contains(e){return Eu({network:this.network,mask:this.mask},e)}toString(){let e=xu(this.mask),r=e!==-1?String(e):wu(this.mask);return Oi(this.network)+"/"+r}};function vu(t,e){return new fn(t).contains(e)}function Su(t){try{let e=ao(t);return e.type==="ip6"?vu("2000::/3",e.host):!1}catch{return!1}}var Cu=ef(_u(),1),hh=["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"],ph=hh.map(t=>new Cu.Netmask(t));function Mi(t){for(let e of ph)if(e.contains(t))return!0;return!1}function mh(t){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(t)}function yh(t){let e=t.split(":");if(e.length<2)return!1;let r=e[e.length-1].padStart(4,"0"),n=e[e.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(r.substring(0,2),16)}.${parseInt(r.substring(2),16)}`;return Mi(o)}function bh(t){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)}function gh(t){let e=t.split(":"),r=e[e.length-1];return Mi(r)}function xh(t){return/^::$/.test(t)||/^::1$/.test(t)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(t)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(t)||/^ff([0-9a-fA-F]{2,2}):/i.test(t)}function Tu(t){if(lr(t))return Mi(t);if(mh(t))return yh(t);if(bh(t))return gh(t);if(eo(t))return xh(t)}function Bu(t){try{let e=ao(t);switch(e.type){case"ip4":case"ip6":return Tu(e.host)??!1;default:return e.host==="localhost"}}catch{return!1}}var G=t=>({match:e=>{let r=e[0];return r==null||r.code!==t||r.value!=null?!1:e.slice(1)}}),L=(t,e)=>({match:r=>{let n=r[0];return n?.code!==t||n.value==null||e!=null&&n.value!==e?!1:r.slice(1)}}),Du=t=>({match:e=>t.match(e)===!1?e:!1}),M=t=>({match:e=>{let r=t.match(e);return r===!1?e:r}}),we=(...t)=>({match:e=>{let r;for(let n of t){let o=n.match(e);o!==!1&&(r==null||o.length<r.length)&&(r=o)}return r??!1}}),$=(...t)=>({match:e=>{for(let r of t){let n=r.match(e);if(n===!1)return!1;e=n}return e}});function W(...t){function e(o){if(o==null)return!1;let s=o.getComponents();for(let i of t){let a=i.match(s);if(a===!1)return!1;s=a}return s}function r(o){return e(o)!==!1}function n(o){let s=e(o);return s===!1?!1:s.length===0}return{matchers:t,matches:r,exactMatch:n}}var wh=L(421),ow=W(wh),fo=L(54),lo=L(55),ho=L(56),qi=L(53),sw=W(fo,M(L(421))),iw=W(lo,M(L(421))),aw=W(ho,M(L(421))),cw=W(we(qi,ho,fo,lo),M(L(421))),Ou=$(L(4),M(L(43))),Pu=$(M(L(42)),L(41),M(L(43))),Hi=we(Ou,Pu),wr=we(Hi,qi,fo,lo,ho),Lu=W(we(Hi,$(we(qi,ho,fo,lo),M(L(421))))),uw=W(Ou),fw=W(Pu),lw=W(Hi),zi=$(wr,L(6)),ln=$(wr,L(273)),Ru=W($(zi,M(L(421)))),dw=W(ln),$i=$(ln,G(460),M(L(421))),po=$(ln,G(461),M(L(421))),Eh=we($i,po),hw=W($i),pw=W(po),Vi=we(wr,zi,ln,$i,po),Fu=we($(Vi,G(477),M(L(421)))),mw=W(Fu),Nu=we($(Vi,G(478),M(L(421))),$(Vi,G(448),M(L(449)),G(477),M(L(421)))),yw=W(Nu),ku=$(ln,G(280),M(L(466)),M(L(466)),M(L(421))),bw=W(ku),Uu=$(po,G(465),M(L(466)),M(L(466)),M(L(421))),gw=W(Uu),uo=we(Fu,Nu,$(zi,M(L(421))),$(Eh,M(L(421))),$(wr,M(L(421))),ku,Uu,L(421)),xw=W(uo),vh=$(M(uo),G(290),Du(G(281)),M(L(421))),ww=W(vh),Sh=we($(uo,G(290),G(281),M(L(421))),$(uo,G(281),M(L(421))),$(G(281),M(L(421)))),Ew=W(Sh),Ih=$(wr,we($(L(6,"80")),$(L(6),G(480)),G(480)),M(L(481)),M(L(421))),vw=W(Ih),Ah=$(wr,we($(L(6,"443")),$(L(6,"443"),G(480)),$(L(6),G(443)),$(L(6),G(448),G(480)),$(G(448),G(480)),G(448),G(443)),M(L(481)),M(L(421))),Sw=W(Ah),_h=we($(L(777),M(L(421)))),Iw=W(_h),Ch=we($(L(400),M(L(421)))),Aw=W(Ch);function Er(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var ji=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},Ku=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function Yi(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=e,a,u,f=new Promise((l,h)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){h(Ku(i));return}if(i&&(u=()=>{h(Ku(i))},i.addEventListener("abort",u,{once:!0})),t.then(l,h),r===Number.POSITIVE_INFINITY)return;let d=new ji;a=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(m){h(m)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?l():o instanceof Error?h(o):(d.message=o??`Promise timed out after ${r} milliseconds`,h(d))},r)}).finally(()=>{f.clear(),u&&i&&i.removeEventListener("abort",u)});return f.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},f}var Th=t=>{let e=t.addEventListener||t.on||t.addListener,r=t.removeEventListener||t.off||t.removeListener;if(!e||!r)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(t),removeListener:r.bind(t)}};function Bh(t,e,r){let n,o=new Promise((s,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[e].flat(),u=[],{addListener:c,removeListener:f}=Th(t),l=async(...d)=>{let m=r.multiArgs?d:d[0];if(r.filter)try{if(!await r.filter(m))return}catch(b){n(),i(b);return}u.push(m),r.count===u.length&&(n(),s(u))},h=(...d)=>{n(),i(r.rejectionMultiArgs?d:d[0])};n=()=>{for(let d of a)f(d,l);for(let d of r.rejectionEvents)a.includes(d)||f(d,h)};for(let d of a)c(d,l);for(let d of r.rejectionEvents)a.includes(d)||c(d,h);r.signal&&r.signal.addEventListener("abort",()=>{h(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(u)});if(o.cancel=n,typeof r.timeout=="number"){let s=Yi(o,{milliseconds:r.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function Mu(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Bh(t,e,r),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function Vu(t,e){let r,n=function(){let o=function(){r=void 0,t()};clearTimeout(r),r=setTimeout(o,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var Mt=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Dh(t){return t.reason}async function Zi(t,e,r){if(e==null)return t;let n=r?.translateError??Dh;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([t,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var Ph=4194304,mo=class extends Error{static name="UnwrappedError";name="UnwrappedError"},Wi=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},Xi=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Qi=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Lh(t){return typeof t?.closeRead=="function"}function Rh(t){return typeof t?.close=="function"}function Gi(t){return Lh(t)?t.remoteWriteStatus!=="writable"&&t.readBufferLength===0:Rh(t)?t.status!=="open":!1}function Fh(t){return t?.addEventListener!=null&&t?.removeEventListener!=null&&t?.send!=null&&t?.push!=null&&t?.log!=null}function Nh(t,e){let r=e?.maxBufferSize??Ph,n=new se,o,s=!1;if(!Fh(t))throw new Q("Argument should be a Stream or a Multiaddr");let i=f=>{if(n.append(f.data),n.byteLength>r){let l=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${l} > ${r}`))}o?.resolve()};t.addEventListener("message",i);let a=f=>{f.error!=null?o?.reject(f.error):o?.resolve()};t.addEventListener("close",a);let u=()=>{o?.resolve()};t.addEventListener("remoteCloseWrite",u);let c={readBuffer:n,async read(f){if(s===!0)throw new mo("Stream was unwrapped");if(Gi(t)){if(n.byteLength===0&&f?.bytes==null)return null;if(f?.bytes!=null&&n.byteLength<f.bytes)throw t.log.error("closed after reading %d/%d bytes",n.byteLength,f.bytes),new Mt(`Unexpected EOF - stream closed after reading ${n.byteLength}/${f.bytes} bytes`)}let l=f?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=l){o.resolve();break}if(await Zi(o.promise,f?.signal),Gi(t)){if(n.byteLength===0&&f?.bytes==null)return null;break}o=Promise.withResolvers()}let h=f?.bytes??n.byteLength;if(n.byteLength<h){if(Gi(t))throw t.log.error("closed while reading %d/%d bytes",n.byteLength,h),new Mt(`Unexpected EOF - stream closed while reading ${n.byteLength}/${h} bytes`);return c.read(f)}let d=n.sublist(0,h);return n.consume(h),d},async write(f,l){if(s===!0)throw new mo("Stream was unwrapped");t.send(f)||await Mu(t,"drain",{signal:l?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,t.removeEventListener("message",i),t.removeEventListener("close",a),t.removeEventListener("remoteCloseWrite",u),n.byteLength>0&&(t.log("stream unwrapped with %d unread bytes",n.byteLength),t.unshift(n))),t}};return c}function kh(t,e={}){let r=Nh(t,e);e.maxDataLength!=null&&e.maxLengthLength==null&&(e.maxLengthLength=Ae(e.maxDataLength));let n=e?.lengthDecoder??jr,o=e?.lengthEncoder??sr;return{async read(i){let a=-1,u=new se;for(;;){let f=await r.read({...i,bytes:1});if(f==null)break;u.append(f);try{a=n(u)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new Wi("Invalid message length");if(e?.maxLengthLength!=null&&u.byteLength>e.maxLengthLength)throw new Qi(`Message length length too long - ${u.byteLength} > ${e.maxLengthLength}`);if(a>-1)break}if(e?.maxDataLength!=null&&a>e.maxDataLength)throw new Xi(`Message length too long - ${a} > ${e.maxDataLength}`);let c=await r.read({...i,bytes:a});if(c==null)throw t.log.error("tried to read %d bytes but the stream closed",a),new Mt(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(c.byteLength!==a)throw t.log.error("read %d/%d bytes before the stream closed",c.byteLength,a),new Mt(`Unexpected EOF - read ${c.byteLength}/${a} bytes before the stream closed`);return c},async write(i,a){await r.write(new se(o(i.byteLength),i),a)},async writeV(i,a){let u=new se(...i.flatMap(c=>[o(c.byteLength),c]));await r.write(u,a)},unwrap(){return r.unwrap()}}}function vr(t,e){let r=kh(t,e),n={read:async(o,s)=>{let i=await r.read(s);return o.decode(i)},write:async(o,s,i)=>{await r.write(s.encode(o),i)},writeV:async(o,s,i)=>{await r.writeV(o.map(a=>s.encode(a)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}function Uh(t){return t[Symbol.asyncIterator]!=null}function Kh(t){if(Uh(t))return(async()=>{for await(let e of t);})();for(let e of t);}var qu=Kh;var yo=globalThis.CustomEvent??Event;async function*Ji(t,e={}){let r=e.concurrency??1/0;r<1&&(r=1/0);let n=e.ordered??!1,o=new EventTarget,s=[],i=Er(),a=Er(),u=!1,c,f=!1;o.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let m of t){if(s.length===r&&(i=Er(),await i.promise),f)break;let b={done:!1};s.push(b),m().then(y=>{b.done=!0,b.ok=!0,b.value=y,o.dispatchEvent(new yo("task-complete"))},y=>{b.done=!0,b.err=y,o.dispatchEvent(new yo("task-complete"))})}u=!0,o.dispatchEvent(new yo("task-complete"))}catch(m){c=m,o.dispatchEvent(new yo("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 f=!0,i.resolve(),m.err;i.resolve()}}function*d(){for(;l();)for(let m=0;m<s.length;m++)if(s[m].done){let b=s[m];if(s.splice(m,1),m--,b.ok)yield b.value;else throw f=!0,i.resolve(),b.err;i.resolve()}}for(;;){if(l()||(a=Er(),await a.promise),c!=null||(n?yield*h():yield*d(),c!=null))throw c;if(u&&s.length===0)break}}var Hu="0.1.0";var zu="id/push",$u="1.0.0",ju="1.0.0";var St;(function(t){let e;t.codec=()=>(e==null&&(e=Me((s,i,a={})=>{if(a.lengthDelimited!==!1&&i.fork(),s.protocolVersion!=null&&(i.uint32(42),i.string(s.protocolVersion)),s.agentVersion!=null&&(i.uint32(50),i.string(s.agentVersion)),s.publicKey!=null&&(i.uint32(10),i.bytes(s.publicKey)),s.listenAddrs!=null&&s.listenAddrs.length>0)for(let u of s.listenAddrs)i.uint32(18),i.bytes(u);if(s.observedAddr!=null&&(i.uint32(34),i.bytes(s.observedAddr)),s.protocols!=null&&s.protocols.length>0)for(let u of s.protocols)i.uint32(26),i.string(u);s.signedPeerRecord!=null&&(i.uint32(66),i.bytes(s.signedPeerRecord)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let u={listenAddrs:[],protocols:[]},c=i==null?s.len:s.pos+i;for(;s.pos<c;){let f=s.uint32();switch(f>>>3){case 5:{u.protocolVersion=s.string();break}case 6:{u.agentVersion=s.string();break}case 1:{u.publicKey=s.bytes();break}case 2:{if(a.limits?.listenAddrs!=null&&u.listenAddrs.length===a.limits.listenAddrs)throw new Ye('Decode error - repeated field "listenAddrs" had too many elements');u.listenAddrs.push(s.bytes());break}case 4:{u.observedAddr=s.bytes();break}case 3:{if(a.limits?.protocols!=null&&u.protocols.length===a.limits.protocols)throw new Ye('Decode error - repeated field "protocols" had too many elements');u.protocols.push(s.string());break}case 8:{u.signedPeerRecord=s.bytes();break}default:{s.skipType(f&7);break}}}return u},function*(s,i,a,u={}){let c={listenAddrs:0,protocols:0},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let l=s.uint32();switch(l>>>3){case 5:{yield{field:`${a}.protocolVersion`,value:s.string()};break}case 6:{yield{field:`${a}.agentVersion`,value:s.string()};break}case 1:{yield{field:`${a}.publicKey`,value:s.bytes()};break}case 2:{if(u.limits?.listenAddrs!=null&&c.listenAddrs===u.limits.listenAddrs)throw new Ye('Streaming decode error - repeated field "listenAddrs" had too many elements');yield{field:`${a}.listenAddrs[]`,index:c.listenAddrs,value:s.bytes()},c.listenAddrs++;break}case 4:{yield{field:`${a}.observedAddr`,value:s.bytes()};break}case 3:{if(u.limits?.protocols!=null&&c.protocols===u.limits.protocols)throw new Ye('Streaming decode error - repeated field "protocols" had too many elements');yield{field:`${a}.protocols[]`,index:c.protocols,value:s.string()},c.protocols++;break}case 8:{yield{field:`${a}.signedPeerRecord`,value:s.bytes()};break}default:{s.skipType(l&7);break}}}})),e);function r(s){return Ue(s,t.codec())}t.encode=r;function n(s,i){return ke(s,t.codec(),i)}t.decode=n;function o(s,i){return Ke(s,t.codec(),i)}t.stream=o})(St||(St={}));var _e={protocolPrefix:"ipfs",timeout:5e3,maxInboundStreams:1,maxOutboundStreams:1,maxObservedAddresses:10,maxMessageSize:8192,runOnConnectionOpen:!0,runOnSelfUpdate:!0,runOnLimitedConnection:!0,concurrency:32};function Zu(t){return t.bytes.length===0}function ea(t){if(t!=null&&t.length>0)try{let e=an(t);if(!Zu(e))return e}catch{}}async function bo(t,e,r,n,o){if(r("received identify from %p",n.remotePeer),o==null)throw new De("message was null or undefined");let s={},i=o.listenAddrs.map(ea).filter(c=>c!=null);if(o.listenAddrs.length>0&&(s.addresses=i.map(c=>({isCertified:!1,multiaddr:c}))),o.protocols.length>0&&(s.protocols=o.protocols),o.publicKey!=null){let c=cr(o.publicKey);if(!Jc(c).equals(n.remotePeer))throw new De("public key did not match remote PeerId");s.publicKey=c}let a;if(o.signedPeerRecord!=null){r.trace("received signedPeerRecord from %p",n.remotePeer);let c=o.signedPeerRecord,f=await We.openAndCertify(c,qe.DOMAIN),l=qe.createFromProtobuf(f.payload),h=Zn(f.publicKey.toCID());if(!l.peerId.equals(h))throw new De("signing key does not match PeerId in the PeerRecord");if(!n.remotePeer.equals(l.peerId))throw new De("signing key does not match remote PeerId");let d;try{d=await t.get(l.peerId)}catch(b){if(b.name!=="NotFoundError")throw b}if(d!=null&&(s.metadata=d.metadata,d.peerRecordEnvelope!=null)){let b=We.createFromProtobuf(d.peerRecordEnvelope),y=qe.createFromProtobuf(b.payload);y.seqNumber>=l.seqNumber&&(r("sequence number was lower or equal to existing sequence number - stored: %d received: %d",y.seqNumber,l.seqNumber),l=y,c=d.peerRecordEnvelope)}s.peerRecordEnvelope=c;let m=l.multiaddrs.filter(b=>!Zu(b));s.addresses=m.map(b=>({isCertified:!0,multiaddr:b})),a={seq:l.seqNumber,addresses:m}}else r("%p did not send a signed peer record",n.remotePeer);if(r.trace("patching %p with",n.remotePeer,s),await t.patch(n.remotePeer,s),o.agentVersion!=null||o.protocolVersion!=null){let c={};o.agentVersion!=null&&(c.AgentVersion=K(o.agentVersion)),o.protocolVersion!=null&&(c.ProtocolVersion=K(o.protocolVersion)),r.trace("merging %p metadata",n.remotePeer,c),await t.merge(n.remotePeer,{metadata:c})}let u={peerId:n.remotePeer,protocolVersion:o.protocolVersion,agentVersion:o.agentVersion,publicKey:o.publicKey,listenAddrs:i,observedAddr:o.observedAddr==null?void 0:an(o.observedAddr),protocols:o.protocols,signedPeerRecord:a,connection:n};return e.safeDispatchEvent("peer:identify",{detail:u}),u}function go(t){let e={...t[0]};for(let r of t.slice(1))r.protocolVersion!=null&&(e.protocolVersion=r.protocolVersion),r.agentVersion!=null&&(e.agentVersion=r.agentVersion),r.publicKey!=null&&(e.publicKey=r.publicKey),r.observedAddr!=null&&(e.observedAddr=r.observedAddr),r.signedPeerRecord!=null&&(e.signedPeerRecord=r.signedPeerRecord),e.listenAddrs=[...e.listenAddrs,...r.listenAddrs],e.protocols=[...new Set([...e.protocols,...r.protocols])];return e}async function xo(t,e,r,n){let o=vr(t,{maxDataLength:e}).pb(St),s=[];for(let i=0;i<10;i++)try{s.push(await o.read(r))}catch(a){if(s.length===0)throw a;n.trace("stopped reading identify - %e",a);break}s.length>=10&&n("reached MAX_IDENTIFY_MESSAGES, returning truncated identify");try{await t.close(r)}catch(i){n.trace("error closing identify stream after read - %e",i),t.abort(i)}return s}var Sr=class{host;components;protocol;started;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxObservedAddresses;runOnLimitedConnection;log;constructor(e,r){this.protocol=r.protocol,this.started=!1,this.components=e,this.log=r.log,this.timeout=r.timeout??_e.timeout,this.maxInboundStreams=r.maxInboundStreams??_e.maxInboundStreams,this.maxOutboundStreams=r.maxOutboundStreams??_e.maxOutboundStreams,this.maxMessageSize=r.maxMessageSize??_e.maxMessageSize,this.maxObservedAddresses=r.maxObservedAddresses??_e.maxObservedAddresses,this.runOnLimitedConnection=r.runOnLimitedConnection??_e.runOnLimitedConnection,this.host={protocolVersion:`${r.protocolPrefix??_e.protocolPrefix}/${Hu}`,agentVersion:e.nodeInfo.userAgent},this.handleProtocol=this.handleProtocol.bind(this)}isStarted(){return this.started}async start(){this.started||(await this.components.peerStore.merge(this.components.peerId,{metadata:{AgentVersion:K(this.host.agentVersion),ProtocolVersion:K(this.host.protocolVersion)}}),await this.components.registrar.handle(this.protocol,this.handleProtocol,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams,runOnLimitedConnection:this.runOnLimitedConnection}),this.started=!0)}async stop(){await this.components.registrar.unhandle(this.protocol),this.started=!1}};var wo=class extends Sr{connectionManager;concurrency;_push;constructor(e,r={}){super(e,{...r,protocol:`/${r.protocolPrefix??_e.protocolPrefix}/${zu}/${ju}`,log:e.logger.forComponent("libp2p:identify-push")}),this.connectionManager=e.connectionManager,this.concurrency=r.concurrency??_e.concurrency,this._push=Vu(this.sendPushMessage.bind(this),r.debounce??1e3),(r.runOnSelfUpdate??_e.runOnSelfUpdate)&&e.events.addEventListener("self:peer:update",n=>{this.push().catch(o=>{this.log.error("error pushing updates to peers - %e",o)})})}[yn]=["@libp2p/identify-push"];async push(){this._push()}async sendPushMessage(){if(this.isStarted())try{let e=this.components.addressManager.getAddresses().map(f=>f.decapsulateCode(421)),r=new qe({peerId:this.components.peerId,multiaddrs:e}),n=await We.seal(r,this.components.privateKey),o=this.components.registrar.getProtocols(),s=await this.components.peerStore.get(this.components.peerId),i=q(s.metadata.get("AgentVersion")??K(this.host.agentVersion)),a=q(s.metadata.get("ProtocolVersion")??K(this.host.protocolVersion)),u=this;async function*c(){for(let f of u.connectionManager.getConnections())(await u.components.peerStore.get(f.remotePeer)).protocols.includes(u.protocol)&&(yield async()=>{let h,d=AbortSignal.timeout(u.timeout);try{h=await f.newStream(u.protocol,{signal:d,runOnLimitedConnection:u.runOnLimitedConnection}),await vr(h,{maxDataLength:u.maxMessageSize}).pb(St).write({listenAddrs:e.map(b=>b.bytes),signedPeerRecord:n.marshal(),protocols:o,agentVersion:i,protocolVersion:a},{signal:d}),await h.close({signal:d})}catch(m){h?.log.newScope("identify-push")?.error("could not push identify update to peer",m),h?.abort(m)}})}await qu(Ji(c(),{concurrency:this.concurrency}))}catch(e){this.log.error("error pushing updates to peers - %e",e)}}async handleProtocol(e,r){let n=e.log.newScope("identify-push");if(this.components.peerId.equals(r.remotePeer))throw new Error("received push from ourselves?");let o={signal:AbortSignal.timeout(this.timeout)},s=await xo(e,this.maxMessageSize,o,n);await bo(this.components.peerStore,this.components.events,n,r,go(s)),n.trace("handled push from %p",r.remotePeer)}};var Eo=class extends Sr{constructor(e,r={}){super(e,{...r,protocol:`/${r.protocolPrefix??_e.protocolPrefix}/${"id"}/${$u}`,log:e.logger.forComponent("libp2p:identify")}),(r.runOnConnectionOpen??_e.runOnConnectionOpen)&&e.events.addEventListener("connection:open",n=>{let o=n.detail;this.identify(o).catch(()=>{})})}[yn]=["@libp2p/identify"];async _identify(e,r={}){let n,o;if(r.signal==null){let s=AbortSignal.timeout(this.timeout);r={...r,signal:s}}this.log("run identify on new connection %a",e.remoteAddr);try{n=await e.newStream(this.protocol,{...r,runOnLimitedConnection:this.runOnLimitedConnection}),o=n.log.newScope("identify");let s=await xo(n,this.maxMessageSize,r,o);return go(s)}catch(s){throw o?.error("identify failed - %e",s),n?.abort(s),s}}async identify(e,r={}){let n=await this._identify(e,r),{publicKey:o,protocols:s,observedAddr:i}=n;if(o==null)throw new De("Public key was missing from identify message");let a=cr(o),u=Zn(a.toCID());if(!e.remotePeer.equals(u))throw new De("Identified peer does not match the expected peer");if(this.components.peerId.equals(u))throw new De("Identified peer is our own peer id?");return this.maybeAddObservedAddress(i),this.log("completed for peer %p and protocols %o",u,s),bo(this.components.peerStore,this.components.events,this.log,e,n)}maybeAddObservedAddress(e){let r=ea(e);if(r==null||(this.log.trace("our observed address was %a",r),Bu(r)))return;let n=r.getComponents();if((n[0].code===41||n[0].code===42&&n[1].code===41)&&!Su(r)){this.log.trace("our observed address was IPv6 but not a global unicast address");return}Ru.exactMatch(r)||(this.log.trace("storing the observed address"),this.components.addressManager.addObservedAddr(r))}async handleProtocol(e,r){let n=e.log.newScope("identify");n("responding to identify");let o=AbortSignal.timeout(this.timeout);let s=await this.components.peerStore.get(this.components.peerId,{signal:o}),i=this.components.addressManager.getAddresses().map(f=>f.decapsulateCode(421)),a=s.peerRecordEnvelope;if(i.length>0&&a==null){let f=new qe({peerId:this.components.peerId,multiaddrs:i});a=(await We.seal(f,this.components.privateKey,{signal:o})).marshal().subarray()}let u=r.remoteAddr.bytes;Lu.matches(r.remoteAddr)||(u=void 0);let c=vr(e).pb(St);n("send response"),await c.write({protocolVersion:this.host.protocolVersion,agentVersion:this.host.agentVersion,publicKey:ze(this.components.privateKey.publicKey),listenAddrs:i.map(f=>f.bytes),signedPeerRecord:a,observedAddr:u,protocols:s.protocols},{signal:o}),n("close write"),await c.unwrap().unwrap().close({signal:o})}};function zh(t={}){return e=>new Eo(e,t)}function $h(t={}){return e=>new wo(e,t)}return tf(jh);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/curves/utils.js:
|