@libp2p/identify 4.1.0-90100be0c → 4.1.0-b30baa93a
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 +2 -2
- package/package.json +8 -8
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 gu=Object.create;var tn=Object.defineProperty;var xu=Object.getOwnPropertyDescriptor;var wu=Object.getOwnPropertyNames;var Eu=Object.getPrototypeOf,vu=Object.prototype.hasOwnProperty;var to=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Et=(e,t)=>{for(var r in t)tn(e,r,{get:t[r],enumerable:!0})},Bi=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of wu(t))!vu.call(e,o)&&o!==r&&tn(e,o,{get:()=>t[o],enumerable:!(n=xu(t,o))||n.enumerable});return e};var Su=(e,t,r)=>(r=e!=null?gu(Eu(e)):{},Bi(t||!e||!e.__esModule?tn(r,"default",{value:e,enumerable:!0}):r,e)),Iu=e=>Bi(tn({},"__esModule",{value:!0}),e);var ui=to(lr=>{"use strict";Object.defineProperty(lr,"__esModule",{value:!0});lr.Netmask4Impl=void 0;lr.ip2long=fr;lr.long2ip=Yt;function Yt(e){let t=(e&-16777216)>>>24,r=(e&255<<16)>>>16,n=(e&65280)>>>8,o=e&255;return[t,r,n,o].join(".")}var Id=48,Ad=97,_d=65;function Cd(e){let t=0,r=10,n="9",o=0;e.length>1&&e[o]==="0"&&(e[o+1]==="x"||e[o+1]==="X"?(o+=2,r=16):"0"<=e[o+1]&&e[o+1]<="9"&&(o++,r=8,n="7"));let s=o;for(;o<e.length;){if("0"<=e[o]&&e[o]<=n)t=t*r+(e.charCodeAt(o)-Id)>>>0;else if(r===16)if("a"<=e[o]&&e[o]<="f")t=t*r+(10+e.charCodeAt(o)-Ad)>>>0;else if("A"<=e[o]&&e[o]<="F")t=t*r+(10+e.charCodeAt(o)-_d)>>>0;else break;else break;if(t>4294967295)throw new Error("too large");o++}if(o===s)throw new Error("empty octet");return[t,o]}function fr(e){let t=[];for(let r=0;r<=3&&e.length!==0;r++){if(r>0){if(e[0]!==".")throw new Error("Invalid IP");e=e.substring(1)}let[n,o]=Cd(e);e=e.substring(o),t.push(n)}if(e.length!==0)throw new Error("Invalid IP");switch(t.length){case 1:if(t[0]>4294967295)throw new Error("Invalid IP");return t[0]>>>0;case 2:if(t[0]>255||t[1]>16777215)throw new Error("Invalid IP");return(t[0]<<24|t[1])>>>0;case 3:if(t[0]>255||t[1]>255||t[2]>65535)throw new Error("Invalid IP");return(t[0]<<24|t[1]<<16|t[2])>>>0;case 4:if(t[0]>255||t[1]>255||t[2]>255||t[3]>255)throw new Error("Invalid IP");return(t[0]<<24|t[1]<<16|t[2]<<8|t[3])>>>0;default:throw new Error("Invalid IP")}}var ci=class e{constructor(t,r){if(typeof t!="string")throw new Error("Missing `net' parameter");let n=r;if(!n){let o=t.split("/",2);t=o[0],n=o[1]}if(n||(n=32),typeof n=="string"&&n.indexOf(".")>-1){try{this.maskLong=fr(n)}catch{throw new Error("Invalid mask: "+n)}this.bitmask=NaN;for(let o=32;o>=0;o--)if(this.maskLong===4294967295<<32-o>>>0){this.bitmask=o;break}}else if(n||n===0)this.bitmask=parseInt(n,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(fr(t)&this.maskLong)>>>0}catch{throw new Error("Invalid net address: "+t)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+n);this.size=Math.pow(2,32-this.bitmask),this.base=Yt(this.netLong),this.mask=Yt(this.maskLong),this.hostmask=Yt(~this.maskLong),this.first=this.bitmask<=30?Yt(this.netLong+1):this.base,this.last=this.bitmask<=30?Yt(this.netLong+this.size-2):Yt(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?Yt(this.netLong+this.size-1):void 0}contains(t){return typeof t=="string"&&(t.indexOf("/")>0||t.split(".").length!==4)&&(t=new e(t)),t instanceof e?this.contains(t.base)&&this.contains(t.broadcast||t.last):(fr(t)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(t=1){return new e(Yt(this.netLong+this.size*t),this.mask)}forEach(t){let r=fr(this.first),n=fr(this.last),o=0;for(;r<=n;)t(Yt(r),r,o),o++,r++}toString(){return this.base+"/"+this.bitmask}};lr.Netmask4Impl=ci});var Wc=to(dr=>{"use strict";Object.defineProperty(dr,"__esModule",{value:!0});dr.Netmask6Impl=void 0;dr.ip6bigint=li;dr.bigint2ip6=Re;var Dd=ui(),fi=(1n<<128n)-1n;function li(e){let t=e.indexOf("%");t!==-1&&(e=e.substring(0,t));let r=e.lastIndexOf(":");if(r!==-1&&e.indexOf(".",r)!==-1){let n=e.substring(r+1),o=(0,Dd.ip2long)(n),s=e.substring(0,r+1)+"0:0";return Gc(s)&~0xffffffffn|BigInt(o)}return Gc(e)}function Gc(e){let t=e.indexOf("::"),r;if(t!==-1){let o=e.substring(0,t),s=e.substring(t+2),i=o===""?[]:o.split(":"),c=s===""?[]:s.split(":"),a=8-i.length-c.length;if(a<0)throw new Error("Invalid IPv6: too many groups");r=[...i,...Array(a).fill("0"),...c]}else r=e.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 Re(e){if(e<0n||e>fi)throw new Error("Invalid IPv6 address value");let t=[];for(let i=0;i<8;i++)t.unshift(Number(e&0xffffn)),e>>=16n;let r=-1,n=0,o=-1,s=0;for(let i=0;i<8;i++)t[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 t.slice(0,r).map(c=>c.toString(16)).join(":")+"::";if(r===0)return"::"+t.slice(n).map(c=>c.toString(16)).join(":");if(r>0){let i=t.slice(0,r).map(a=>a.toString(16)),c=t.slice(r+n).map(a=>a.toString(16));return i.join(":")+"::"+c.join(":")}else return t.map(i=>i.toString(16)).join(":")}var di=class e{constructor(t,r){if(typeof t!="string")throw new Error("Missing `net' parameter");let n=r;if(n==null){let o=t.indexOf("/");o!==-1?(n=parseInt(t.substring(o+1),10),t=t.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=fi>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=li(t)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+t)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=Re(this.netBigint),this.mask=Re(this.maskBigint),this.hostmask=Re(~this.maskBigint&fi),this.first=this.base,this.last=Re(this.netBigint+(1n<<BigInt(128-this.bitmask))-1n),this.broadcast=void 0}contains(t){return typeof t=="string"&&t.indexOf("/")>0&&(t=new e(t)),t instanceof e?this.contains(t.base)&&this.contains(t.last):(li(t)&this.maskBigint)===this.netBigint}next(t=1){let r=1n<<BigInt(128-this.bitmask);return new e(Re(this.netBigint+r*BigInt(t)),this.bitmask)}forEach(t){let r=this.netBigint,n=1n<<BigInt(128-this.bitmask),o=this.netBigint+n-1n,s=0;for(;r<=o;)t(Re(r),Number(r),s),s++,r++}toString(){return this.base+"/"+this.bitmask}};dr.Netmask6Impl=di});var jc=to(ye=>{"use strict";Object.defineProperty(ye,"__esModule",{value:!0});ye.long2ip=ye.ip2long=ye.Netmask=void 0;var Hn=ui();Object.defineProperty(ye,"ip2long",{enumerable:!0,get:function(){return Hn.ip2long}});Object.defineProperty(ye,"long2ip",{enumerable:!0,get:function(){return Hn.long2ip}});var Td=Wc(),hi=class e{constructor(t,r){if(typeof t!="string")throw new Error("Missing `net' parameter");(t.indexOf("/")!==-1?t.substring(0,t.indexOf("/")):t).indexOf(":")!==-1?this._impl=new Td.Netmask6Impl(t,r):this._impl=new Hn.Netmask4Impl(t,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 Hn.Netmask4Impl?(this.maskLong=this._impl.maskLong,this.netLong=this._impl.netLong):(this.maskLong=0,this.netLong=0)}contains(t){return typeof t=="string"&&(t.indexOf("/")>0?t=new e(t):t.indexOf(":")===-1&&t.split(".").length!==4&&(t=new e(t))),t instanceof e?this.contains(t.base)&&this.contains(t.broadcast||t.last):this._impl.contains(t)}next(t=1){let r=this._impl.next(t);return new e(r.base,r.bitmask)}forEach(t){this._impl.forEach(t)}toString(){return this._impl.toString()}};ye.Netmask=hi});var uh={};Et(uh,{identify:()=>ah,identifyPush:()=>ch});var Q=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},ke=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var en=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},rn=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Tt=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var ge=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var eo=Symbol.for("@libp2p/peer-id");var nn=Symbol.for("@libp2p/service-capabilities"),hh=Symbol.for("@libp2p/service-dependencies");var io={};Et(io,{base58btc:()=>ot,base58flickr:()=>Pu});var Mh=new Uint8Array(0);function Pi(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Zt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function Li(e){return new TextEncoder().encode(e)}function Oi(e){return new TextDecoder().decode(e)}function Au(e,t){if(e.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<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var c=e.length,a=e.charAt(0),f=Math.log(c)/Math.log(256),u=Math.log(256)/Math.log(c);function l(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var E=0,S=0,g=0,A=d.length;g!==A&&d[g]===0;)g++,E++;for(var x=(A-g)*u+1>>>0,_=new Uint8Array(x);g!==A;){for(var R=d[g],K=0,M=x-1;(R!==0||K<S)&&M!==-1;M--,K++)R+=256*_[M]>>>0,_[M]=R%c>>>0,R=R/c>>>0;if(R!==0)throw new Error("Non-zero carry");S=K,g++}for(var v=x-S;v!==x&&_[v]===0;)v++;for(var w=a.repeat(E);v<x;++v)w+=e.charAt(_[v]);return w}function h(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var E=0;if(d[E]!==" "){for(var S=0,g=0;d[E]===a;)S++,E++;for(var A=(d.length-E)*f+1>>>0,x=new Uint8Array(A);d[E];){var _=r[d.charCodeAt(E)];if(_===255)return;for(var R=0,K=A-1;(_!==0||R<g)&&K!==-1;K--,R++)_+=c*x[K]>>>0,x[K]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");g=R,E++}if(d[E]!==" "){for(var M=A-g;M!==A&&x[M]===0;)M++;for(var v=new Uint8Array(S+(A-M)),w=S;M!==A;)v[w++]=x[M++];return v}}}function p(d){var E=h(d);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:h,decode:p}}var _u=Au,Cu=_u,Ni=Cu;var ro=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},no=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,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(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return ki(this,t)}},oo=class{decoders;constructor(t){this.decoders=t}or(t){return ki(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function ki(e,t){return new oo({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var so=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new ro(t,r,n),this.decoder=new no(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ue({name:e,prefix:t,encode:r,decode:n}){return new so(e,t,r,n)}function ie({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Ni(r,e);return Ue({prefix:t,name:e,encode:n,decode:s=>Zt(o(s))})}function Du(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,c=0,a=0;for(let f=0;f<o;++f){let u=t[e[f]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|u,i+=r,i>=8&&(i-=8,s[a++]=255&c>>i)}if(i>=r||(255&c<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Tu(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,c=0;for(let a=0;a<e.length;++a)for(c=c<<8|e[a],i+=8;i>r;)i-=r,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Bu(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function nt({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Bu(n);return Ue({prefix:t,name:e,encode(s){return Tu(s,n,r)},decode(s){return Du(s,o,r,e)}})}var ot=ie({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Pu=ie({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ao={};Et(ao,{base32:()=>ae,base32hex:()=>Nu,base32hexpad:()=>Uu,base32hexpadupper:()=>Ku,base32hexupper:()=>ku,base32pad:()=>Ou,base32padupper:()=>Ru,base32upper:()=>Lu,base32z:()=>Mu});var ae=nt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Lu=nt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ou=nt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ru=nt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Nu=nt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ku=nt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Uu=nt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ku=nt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Mu=nt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var co={};Et(co,{base36:()=>br,base36upper:()=>Vu});var br=ie({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Vu=ie({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Fu=Mi,Ui=128,qu=127,Hu=~qu,zu=Math.pow(2,31);function Mi(e,t,r){t=t||[],r=r||0;for(var n=r;e>=zu;)t[r++]=e&255|Ui,e/=128;for(;e&Hu;)t[r++]=e&255|Ui,e>>>=7;return t[r]=e|0,Mi.bytes=r-n+1,t}var $u=uo,Yu=128,Ki=127;function uo(e,n){var r=0,n=n||0,o=0,s=n,i,c=e.length;do{if(s>=c)throw uo.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Ki)<<o:(i&Ki)*Math.pow(2,o),o+=7}while(i>=Yu);return uo.bytes=s-n,r}var Zu=Math.pow(2,7),Gu=Math.pow(2,14),Wu=Math.pow(2,21),ju=Math.pow(2,28),Xu=Math.pow(2,35),Qu=Math.pow(2,42),Ju=Math.pow(2,49),tf=Math.pow(2,56),ef=Math.pow(2,63),rf=function(e){return e<Zu?1:e<Gu?2:e<Wu?3:e<ju?4:e<Xu?5:e<Qu?6:e<Ju?7:e<tf?8:e<ef?9:10},nf={encode:Fu,decode:$u,encodingLength:rf},of=nf,gr=of;function xr(e,t=0){return[gr.decode(e,t),gr.decode.bytes]}function Ke(e,t,r=0){return gr.encode(e,t,r),t}function Me(e){return gr.encodingLength(e)}function Mt(e,t){let r=t.byteLength,n=Me(e),o=n+Me(r),s=new Uint8Array(o+r);return Ke(e,s,0),Ke(r,s,n),s.set(t,o),new Ve(e,r,t,s)}function wr(e){let t=Zt(e),[r,n]=xr(t),[o,s]=xr(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Ve(r,o,i,t)}function Vi(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Pi(e.bytes,r.bytes)}}var Ve=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function Fi(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return af(r,fo(e),t??ot.encoder);default:return cf(r,fo(e),t??ae.encoder)}}var qi=new WeakMap;function fo(e){let t=qi.get(e);if(t==null){let r=new Map;return qi.set(e,r),r}return t}var at=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==Er)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==uf)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.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:t,digest:r}=this.multihash,n=Mt(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&Vi(t.multihash,n.multihash)}toString(t){return Fi(this,t)}toJSON(){return{"/":Fi(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new e(n,o,s,i??Hi(n,o,s.bytes))}else if(r[ff]===!0){let{version:n,multihash:o,code:s}=r,i=wr(o);return e.create(n,s,i)}else return null}static create(t,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(t){case 0:{if(r!==Er)throw new Error(`Version 0 CID must use dag-pb (code: ${Er}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Hi(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Er,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Zt(t.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 Ve(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,h]=xr(t.subarray(r));return r+=h,l},o=n(),s=Er;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,c=n(),a=n(),f=r+a,u=f-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:u,size:f}}static parse(t,r){let[n,o]=sf(t,r),s=e.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return fo(s).set(n,t),s}};function sf(e,t){switch(e[0]){case"Q":{let r=t??ot;return[ot.prefix,r.decode(`${ot.prefix}${e}`)]}case ot.prefix:{let r=t??ot;return[ot.prefix,r.decode(e)]}case ae.prefix:{let r=t??ae;return[ae.prefix,r.decode(e)]}case br.prefix:{let r=t??br;return[br.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function af(e,t,r){let{prefix:n}=r;if(n!==ot.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function cf(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var Er=112,uf=18;function Hi(e,t,r){let n=Me(e),o=n+Me(t),s=new Uint8Array(o+r.byteLength);return Ke(e,s,0),Ke(t,s,n),s.set(r,o),s}var ff=Symbol.for("@ipld/js-cid/CID");var lo={};Et(lo,{identity:()=>Bt});var zi=0,lf="identity",$i=Zt;function df(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return Mt(zi,$i(e))}var Bt={code:zi,name:lf,encode:$i,digest:df};function ct(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function ht(e=0){return new Uint8Array(e)}function vt(e=0){return new Uint8Array(e)}function Gt(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=vt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var Zi=Symbol.for("@achingbrain/uint8arraylist");function Yi(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function sn(e){return!!e?.[Zi]}var it=class e{bufs;length;[Zi]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(sn(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(sn(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(t){let r=Yi(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Yi(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(sn(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return Gt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Gt(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=[...n],s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===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],c=o,a=c+i.byteLength;if(o=a,t>=a)continue;let f=t>=c&&t<a,u=r>c&&r<=a;if(f&&u){if(t===c&&r===a){n.push(i);break}let l=t-c;n.push(i.subarray(l,l+(r-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(u){if(r===a){n.push(i);break}n.push(i.subarray(0,r-c));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!sn(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.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 c=i,a=this.byteLength-n.byteLength,f=n.byteLength-1,u;for(let l=r;l<=a;l+=u){u=0;for(let h=f;h>=0;h--){let p=this.get(l+h);if(n[h]!==p){u=Math.max(1,h-c[p]);break}}if(u===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=vt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=ht(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=ht(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=ht(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=vt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=ht(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=ht(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=ht(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=ht(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=ht(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!ct(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var ho={};Et(ho,{base10:()=>hf});var hf=ie({prefix:"9",name:"base10",alphabet:"0123456789"});var po={};Et(po,{base16:()=>pf,base16upper:()=>mf});var pf=nt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),mf=nt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var mo={};Et(mo,{base2:()=>yf});var yf=nt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var yo={};Et(yo,{base256emoji:()=>Ef});var Gi=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}"),bf=Gi.reduce((e,t,r)=>(e[r]=t,e),[]),gf=Gi.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function xf(e){return e.reduce((t,r)=>(t+=bf[r],t),"")}function wf(e){let t=[];for(let r of e){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}`);t.push(o)}return new Uint8Array(t)}var Ef=Ue({prefix:"\u{1F680}",name:"base256emoji",encode:xf,decode:wf});var go={};Et(go,{base64:()=>vf,base64pad:()=>Sf,base64url:()=>bo,base64urlpad:()=>If});var vf=nt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Sf=nt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),bo=nt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),If=nt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var xo={};Et(xo,{base8:()=>Af});var Af=nt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var wo={};Et(wo,{identity:()=>_f});var _f=Ue({prefix:"\0",name:"identity",encode:e=>Oi(e),decode:e=>Li(e)});var vp=new TextEncoder,Sp=new TextDecoder;var So={};Et(So,{sha256:()=>vr,sha512:()=>Bf});var Tf=20;function vo({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Eo(e,t,r,n,o)}var Eo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??Tf,this.maxDigestLength=s}digest(t,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(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Wi(n,this.code,r?.truncate):n.then(o=>Wi(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Wi(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return Mt(t,e)}function Xi(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var vr=vo({name:"sha2-256",code:18,encode:Xi("SHA-256")}),Bf=vo({name:"sha2-512",code:19,encode:Xi("SHA-512")});var Sr={...wo,...mo,...xo,...ho,...po,...ao,...co,...io,...go,...yo},Np={...So,...lo};function Ji(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Qi=Ji("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Io=Ji("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=vt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Pf={utf8:Qi,"utf-8":Qi,hex:Sr.base16,latin1:Io,ascii:Io,binary:Io,...Sr},an=Pf;function F(e,t="utf8"){let r=an[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function H(e,t="utf8"){let r=an[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Lf=parseInt("11111",2),Ao=parseInt("10000000",2),Of=parseInt("01111111",2),ta={0:Ir,1:Ir,2:Rf,3:Uf,4:Kf,5:kf,6:Nf,16:Ir,22:Ir,48:Ir};function Wt(e,t={offset:0}){let r=e[t.offset]&Lf;if(t.offset++,ta[r]!=null)return ta[r](e,t);throw new Error("No decoder for tag "+r)}function Ar(e,t){let r=0;if((e[t.offset]&Ao)===Ao){let n=e[t.offset]&Of,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function Ir(e,t){Ar(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Wt(e,t);if(n===null)break;r.push(n)}return r}function Rf(e,t){let r=Ar(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function Nf(e,t){let r=Ar(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let c=`${s}.${i}`,a=[];for(;t.offset<n;){let f=e[t.offset];if(t.offset++,a.push(f&127),f<128){a.reverse();let u=0;for(let l=0;l<a.length;l++)u+=a[l]<<l*7;c+=`.${u}`,a=[]}}return c}function kf(e,t){return t.offset++,null}function Uf(e,t){let r=Ar(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Kf(e,t){let r=Ar(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Mf(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new it;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function _o(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Mf(e.byteLength);return new it(Uint8Array.from([t.byteLength|Ao]),t)}function St(e){let t=new it,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new it(Uint8Array.from([2]),_o(t),t)}function cn(e){let t=Uint8Array.from([0]),r=new it(t,e);return new it(Uint8Array.from([3]),_o(r),r)}function ce(e,t=48){let r=new it;for(let n of e)r.append(n);return new it(Uint8Array.from([t]),_o(r),r)}async function ea(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),s}var Vf=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Ff=Uint8Array.from([6,5,43,129,4,0,34]),qf=Uint8Array.from([6,5,43,129,4,0,35]),Hf={ext:!0,kty:"EC",crv:"P-256"},zf={ext:!0,kty:"EC",crv:"P-384"},$f={ext:!0,kty:"EC",crv:"P-521"},Co=32,Do=48,To=66;function Bo(e){let t=Wt(e);return ra(t)}function ra(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Co*2+1)return n=H(t.subarray(r,r+Co),"base64url"),o=H(t.subarray(r+Co),"base64url"),new Fe({...Hf,key_ops:["verify"],x:n,y:o});if(t.byteLength===Do*2+1)return n=H(t.subarray(r,r+Do),"base64url"),o=H(t.subarray(r+Do),"base64url"),new Fe({...zf,key_ops:["verify"],x:n,y:o});if(t.byteLength===To*2+1)return n=H(t.subarray(r,r+To),"base64url"),o=H(t.subarray(r+To),"base64url"),new Fe({...$f,key_ops:["verify"],x:n,y:o});throw new Q(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function na(e){return ce([St(Uint8Array.from([1])),ce([Yf(e.crv)],160),ce([cn(new it(Uint8Array.from([4]),F(e.x??"","base64url"),F(e.y??"","base64url")))],161)]).subarray()}function Yf(e){if(e==="P-256")return Vf;if(e==="P-384")return Ff;if(e==="P-521")return qf;throw new Q(`Invalid curve ${e}`)}var Fe=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=na(this.jwk)),this._raw}toMultihash(){return Bt.digest(Vt(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}async verify(t,r,n){return ea(this.jwk,r,t,n)}};function we(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Ft(e,t=""){if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new Error(`${r}expected integer >= 0, got ${e}`)}}function U(e,t,r=""){let n=we(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,c=s?` of length ${t}`:"",a=n?`length=${o}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+c+", got "+a)}return e}function un(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash must wrapped by utils.createHasher");Ft(e.outputLen),Ft(e.blockLen)}function qe(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function sa(e,t){U(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function Xt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function fn(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Pt(e,t){return e<<32-t|e>>>t}var ia=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Zf=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Qt(e){if(U(e),ia)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Zf[e[r]];return t}var jt={_0:48,_9:57,A:65,F:70,a:97,f:102};function oa(e){if(e>=jt._0&&e<=jt._9)return e-jt._0;if(e>=jt.A&&e<=jt.F)return e-(jt.A-10);if(e>=jt.a&&e<=jt.f)return e-(jt.a-10)}function Jt(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(ia)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=oa(e.charCodeAt(s)),c=oa(e.charCodeAt(s+1));if(i===void 0||c===void 0){let a=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function It(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];U(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}function Po(e,t={}){let r=(o,s)=>e(s).update(o).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function He(e=32){let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(e))}var Lo=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function aa(e,t,r){return e&t^~e&r}function ca(e,t,r){return e&t^e&r^t&r}var _r=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,o){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=fn(this.buffer)}update(t){qe(this),U(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=fn(t);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){qe(this),sa(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Xt(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 c=fn(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let f=a/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)c.setUint32(4*l,u[l],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=c,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},te=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var pt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var ln=BigInt(4294967295),ua=BigInt(32);function Gf(e,t=!1){return t?{h:Number(e&ln),l:Number(e>>ua&ln)}:{h:Number(e>>ua&ln)|0,l:Number(e&ln)|0}}function fa(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:c}=Gf(e[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var Oo=(e,t,r)=>e>>>r,Ro=(e,t,r)=>e<<32-r|t>>>r,Ee=(e,t,r)=>e>>>r|t<<32-r,ve=(e,t,r)=>e<<32-r|t>>>r,Cr=(e,t,r)=>e<<64-r|t>>>r-32,Dr=(e,t,r)=>e>>>r-32|t<<64-r;function qt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var la=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),da=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,ha=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),pa=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,ma=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),ya=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var jf=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]),ue=new Uint32Array(64),No=class extends _r{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[t,r,n,o,s,i,c,a]}set(t,r,n,o,s,i,c,a){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=a|0}process(t,r){for(let l=0;l<16;l++,r+=4)ue[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let h=ue[l-15],p=ue[l-2],d=Pt(h,7)^Pt(h,18)^h>>>3,E=Pt(p,17)^Pt(p,19)^p>>>10;ue[l]=E+ue[l-7]+d+ue[l-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:f,H:u}=this;for(let l=0;l<64;l++){let h=Pt(c,6)^Pt(c,11)^Pt(c,25),p=u+h+aa(c,a,f)+jf[l]+ue[l]|0,E=(Pt(n,2)^Pt(n,13)^Pt(n,22))+ca(n,o,s)|0;u=f,f=a,a=c,c=i+p|0,i=s,s=o,o=n,n=p+E|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,o,s,i,c,a,f,u)}roundClean(){Xt(ue)}destroy(){this.set(0,0,0,0,0,0,0,0),Xt(this.buffer)}},ko=class extends No{A=te[0]|0;B=te[1]|0;C=te[2]|0;D=te[3]|0;E=te[4]|0;F=te[5]|0;G=te[6]|0;H=te[7]|0;constructor(){super(32)}};var ba=fa(["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(e=>BigInt(e))),Xf=ba[0],Qf=ba[1],fe=new Uint32Array(80),le=new Uint32Array(80),Uo=class extends _r{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:f,El:u,Fh:l,Fl:h,Gh:p,Gl:d,Hh:E,Hl:S}=this;return[t,r,n,o,s,i,c,a,f,u,l,h,p,d,E,S]}set(t,r,n,o,s,i,c,a,f,u,l,h,p,d,E,S){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=c|0,this.Dl=a|0,this.Eh=f|0,this.El=u|0,this.Fh=l|0,this.Fl=h|0,this.Gh=p|0,this.Gl=d|0,this.Hh=E|0,this.Hl=S|0}process(t,r){for(let x=0;x<16;x++,r+=4)fe[x]=t.getUint32(r),le[x]=t.getUint32(r+=4);for(let x=16;x<80;x++){let _=fe[x-15]|0,R=le[x-15]|0,K=Ee(_,R,1)^Ee(_,R,8)^Oo(_,R,7),M=ve(_,R,1)^ve(_,R,8)^Ro(_,R,7),v=fe[x-2]|0,w=le[x-2]|0,N=Ee(v,w,19)^Cr(v,w,61)^Oo(v,w,6),V=ve(v,w,19)^Dr(v,w,61)^Ro(v,w,6),B=ha(M,V,le[x-7],le[x-16]),y=pa(B,K,N,fe[x-7],fe[x-16]);fe[x]=y|0,le[x]=B|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:f,Dl:u,Eh:l,El:h,Fh:p,Fl:d,Gh:E,Gl:S,Hh:g,Hl:A}=this;for(let x=0;x<80;x++){let _=Ee(l,h,14)^Ee(l,h,18)^Cr(l,h,41),R=ve(l,h,14)^ve(l,h,18)^Dr(l,h,41),K=l&p^~l&E,M=h&d^~h&S,v=ma(A,R,M,Qf[x],le[x]),w=ya(v,g,_,K,Xf[x],fe[x]),N=v|0,V=Ee(n,o,28)^Cr(n,o,34)^Cr(n,o,39),B=ve(n,o,28)^Dr(n,o,34)^Dr(n,o,39),y=n&s^n&c^s&c,b=o&i^o&a^i&a;g=E|0,A=S|0,E=p|0,S=d|0,p=l|0,d=h|0,{h:l,l:h}=qt(f|0,u|0,w|0,N|0),f=c|0,u=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let m=la(N,B,b);n=da(m,w,V,y),o=m|0}({h:n,l:o}=qt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=qt(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=qt(this.Ch|0,this.Cl|0,c|0,a|0),{h:f,l:u}=qt(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:h}=qt(this.Eh|0,this.El|0,l|0,h|0),{h:p,l:d}=qt(this.Fh|0,this.Fl|0,p|0,d|0),{h:E,l:S}=qt(this.Gh|0,this.Gl|0,E|0,S|0),{h:g,l:A}=qt(this.Hh|0,this.Hl|0,g|0,A|0),this.set(n,o,s,i,c,a,f,u,l,h,p,d,E,S,g,A)}roundClean(){Xt(fe,le)}destroy(){Xt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Ko=class extends Uo{Ah=pt[0]|0;Al=pt[1]|0;Bh=pt[2]|0;Bl=pt[3]|0;Ch=pt[4]|0;Cl=pt[5]|0;Dh=pt[6]|0;Dl=pt[7]|0;Eh=pt[8]|0;El=pt[9]|0;Fh=pt[10]|0;Fl=pt[11]|0;Gh=pt[12]|0;Gl=pt[13]|0;Hh=pt[14]|0;Hl=pt[15]|0;constructor(){super(64)}};var ze=Po(()=>new ko,Lo(1));var ga=Po(()=>new Ko,Lo(3));var Vo=BigInt(0),Mo=BigInt(1);function ee(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function xa(e){if(typeof e=="bigint"){if(!dn(e))throw new Error("positive bigint expected, got "+e)}else Ft(e);return e}function Tr(e){let t=xa(e).toString(16);return t.length&1?"0"+t:t}function wa(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?Vo:BigInt("0x"+e)}function $e(e){return wa(Qt(e))}function Se(e){return wa(Qt(pn(U(e)).reverse()))}function hn(e,t){Ft(t),e=xa(e);let r=Jt(e.toString(16).padStart(t*2,"0"));if(r.length!==t)throw new Error("number too large");return r}function Fo(e,t){return hn(e,t).reverse()}function pn(e){return Uint8Array.from(e)}var dn=e=>typeof e=="bigint"&&Vo<=e;function Jf(e,t,r){return dn(e)&&dn(t)&&dn(r)&&t<=e&&e<r}function Br(e,t,r,n){if(!Jf(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function qo(e){let t;for(t=0;e>Vo;e>>=Mo,t+=1);return t}var Pr=e=>(Mo<<BigInt(e))-Mo;function Ea(e,t,r){if(Ft(e,"hashLen"),Ft(t,"qByteLen"),typeof r!="function")throw new Error("hmacFn must be a function");let n=S=>new Uint8Array(S),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),c=1e3,a=n(e),f=n(e),u=0,l=()=>{a.fill(1),f.fill(0),u=0},h=(...S)=>r(f,It(a,...S)),p=(S=o)=>{f=h(s,S),a=h(),S.length!==0&&(f=h(i,S),a=h())},d=()=>{if(u++>=c)throw new Error("drbg: tried max amount of iterations");let S=0,g=[];for(;S<t;){a=h();let A=a.slice();g.push(A),S+=a.length}return It(...g)};return(S,g)=>{l(),p(S);let A;for(;!(A=g(d()));)p();return l(),A}}function de(e,t={},r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(s,i,c){let a=e[s];if(c&&a===void 0)return;let f=typeof a;if(f!==i||a===null)throw new Error(`param "${s}" is invalid: expected ${i}, got ${f}`)}let o=(s,i)=>Object.entries(s).forEach(([c,a])=>n(c,a,i));o(t,!1),o(r,!0)}function Ye(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let s=e(r,...n);return t.set(r,s),s}}var wt=BigInt(0),ut=BigInt(1),Ie=BigInt(2),Ia=BigInt(3),Aa=BigInt(4),_a=BigInt(5),tl=BigInt(7),Ca=BigInt(8),el=BigInt(9),Da=BigInt(16);function st(e,t){let r=e%t;return r>=wt?r:t+r}function X(e,t,r){let n=e;for(;t-- >wt;)n*=n,n%=r;return n}function va(e,t){if(e===wt)throw new Error("invert: expected non-zero number");if(t<=wt)throw new Error("invert: expected positive modulus, got "+t);let r=st(e,t),n=t,o=wt,s=ut,i=ut,c=wt;for(;r!==wt;){let f=n/r,u=n%r,l=o-i*f,h=s-c*f;n=r,r=u,o=i,s=c,i=l,c=h}if(n!==ut)throw new Error("invert: does not exist");return st(o,t)}function zo(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function Ta(e,t){let r=(e.ORDER+ut)/Aa,n=e.pow(t,r);return zo(e,n,t),n}function rl(e,t){let r=(e.ORDER-_a)/Ca,n=e.mul(t,Ie),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,Ie),o),c=e.mul(s,e.sub(i,e.ONE));return zo(e,c,t),c}function nl(e){let t=Ze(e),r=Ba(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+tl)/Da;return(c,a)=>{let f=c.pow(a,i),u=c.mul(f,n),l=c.mul(f,o),h=c.mul(f,s),p=c.eql(c.sqr(u),a),d=c.eql(c.sqr(l),a);f=c.cmov(f,u,p),u=c.cmov(h,l,d);let E=c.eql(c.sqr(u),a),S=c.cmov(f,u,E);return zo(c,S,a),S}}function Ba(e){if(e<Ia)throw new Error("sqrt is not defined for small field");let t=e-ut,r=0;for(;t%Ie===wt;)t/=Ie,r++;let n=Ie,o=Ze(e);for(;Sa(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Ta;let s=o.pow(n,t),i=(t+ut)/Ie;return function(a,f){if(a.is0(f))return f;if(Sa(a,f)!==1)throw new Error("Cannot find square root");let u=r,l=a.mul(a.ONE,s),h=a.pow(f,t),p=a.pow(f,i);for(;!a.eql(h,a.ONE);){if(a.is0(h))return a.ZERO;let d=1,E=a.sqr(h);for(;!a.eql(E,a.ONE);)if(d++,E=a.sqr(E),d===u)throw new Error("Cannot find square root");let S=ut<<BigInt(u-d-1),g=a.pow(l,S);u=d,l=a.sqr(g),h=a.mul(h,l),p=a.mul(p,g)}return p}}function ol(e){return e%Aa===Ia?Ta:e%Ca===_a?rl:e%Da===el?nl(e):Ba(e)}var Pa=(e,t)=>(st(e,t)&ut)===ut,sl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function $o(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=sl.reduce((n,o)=>(n[o]="function",n),t);return de(e,r),e}function il(e,t,r){if(r<wt)throw new Error("invalid exponent, negatives unsupported");if(r===wt)return e.ONE;if(r===ut)return t;let n=e.ONE,o=t;for(;r>wt;)r&ut&&(n=e.mul(n,o)),o=e.sqr(o),r>>=ut;return n}function Lr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,c,a)=>e.is0(c)?i:(n[a]=i,e.mul(i,c)),e.ONE),s=e.inv(o);return t.reduceRight((i,c,a)=>e.is0(c)?i:(n[a]=e.mul(i,n[a]),e.mul(i,c)),s),n}function Sa(e,t){let r=(e.ORDER-ut)/Ie,n=e.pow(t,r),o=e.eql(n,e.ONE),s=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function al(e,t){t!==void 0&&Ft(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}var Ho=class{ORDER;BITS;BYTES;isLE;ZERO=wt;ONE=ut;_lengths;_sqrt;_mod;constructor(t,r={}){if(t<=wt)throw new Error("invalid field: expected ORDER > 0, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&(this.sqrt=r.sqrt),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=r.allowedLengths?.slice()),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=al(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=s,this._sqrt=void 0,Object.preventExtensions(this)}create(t){return st(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof t);return wt<=t&&t<this.ORDER}is0(t){return t===wt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&ut)===ut}neg(t){return st(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return st(t*t,this.ORDER)}add(t,r){return st(t+r,this.ORDER)}sub(t,r){return st(t-r,this.ORDER)}mul(t,r){return st(t*r,this.ORDER)}pow(t,r){return il(this,t,r)}div(t,r){return st(t*va(r,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,r){return t+r}subN(t,r){return t-r}mulN(t,r){return t*r}inv(t){return va(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=ol(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?Fo(t,this.BYTES):hn(t,this.BYTES)}fromBytes(t,r=!1){U(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:c}=this;if(n){if(!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let f=new Uint8Array(o);f.set(t,s?0:f.length-t.length),t=f}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let a=s?Se(t):$e(t);if(c&&(a=st(a,i)),!r&&!this.isValid(a))throw new Error("invalid field element: outside of range 0..ORDER");return a}invertBatch(t){return Lr(this,t)}cmov(t,r,n){return n?r:t}};function Ze(e,t={}){return new Ho(e,t)}function La(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function Yo(e){let t=La(e);return t+Math.ceil(t/2)}function Zo(e,t,r=!1){U(e);let n=e.length,o=La(t),s=Yo(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Se(e):$e(e),c=st(i,t-ut)+ut;return r?Fo(c,o):hn(c,o)}var Ge=BigInt(0),Ae=BigInt(1);function Or(e,t){let r=t.negate();return e?r:t}function _e(e,t){let r=Lr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function ka(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Go(e,t){ka(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=Pr(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Oa(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,c=Number(e&o),a=e>>i;c>n&&(c-=s,a+=Ae);let f=t*n,u=f+Math.abs(c)-1,l=c===0,h=c<0,p=t%2!==0;return{nextN:a,offset:u,isZero:l,isNeg:h,isNegF:p,offsetF:f}}var Wo=new WeakMap,Ua=new WeakMap;function jo(e){return Ua.get(e)||1}function Ra(e){if(e!==Ge)throw new Error("invalid wNAF")}var We=class{BASE;ZERO;Fn;bits;constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>Ge;)r&Ae&&(n=n.add(o)),o=o.double(),r>>=Ae;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=Go(r,this.bits),s=[],i=t,c=i;for(let a=0;a<n;a++){c=i,s.push(c);for(let f=1;f<o;f++)c=c.add(i),s.push(c);i=c.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=Go(t,this.bits);for(let c=0;c<i.windows;c++){let{nextN:a,offset:f,isZero:u,isNeg:l,isNegF:h,offsetF:p}=Oa(n,c,i);n=a,u?s=s.add(Or(h,r[p])):o=o.add(Or(l,r[f]))}return Ra(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=Go(t,this.bits);for(let i=0;i<s.windows&&n!==Ge;i++){let{nextN:c,offset:a,isZero:f,isNeg:u}=Oa(n,i,s);if(n=c,!f){let l=r[a];o=o.add(u?l.negate():l)}}return Ra(n),o}getPrecomputes(t,r,n){let o=Wo.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),Wo.set(r,o))),o}cached(t,r,n){let o=jo(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=jo(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){ka(r,this.bits),Ua.set(t,r),Wo.delete(t)}hasCache(t){return jo(t)!==1}};function Ka(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>Ge||n>Ge;)r&Ae&&(s=s.add(o)),n&Ae&&(i=i.add(o)),o=o.double(),r>>=Ae,n>>=Ae;return{p1:s,p2:i}}function Na(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return $o(t),t}else return Ze(e,{isLE:r})}function mn(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let a of["p","n","h"]){let f=t[a];if(!(typeof f=="bigint"&&f>Ge))throw new Error(`CURVE.${a} must be positive bigint`)}let o=Na(t.p,r.Fp,n),s=Na(t.n,r.Fn,n),c=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let a of c)if(!o.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}function yn(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var he=BigInt(0),ft=BigInt(1),Xo=BigInt(2),cl=BigInt(8);function ul(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),c=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,c)}function Ma(e,t={}){let r=mn("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i}=s;de(t,{},{uvRatio:"function"});let c=Xo<<BigInt(o.BYTES*8)-ft,a=S=>n.create(S),f=t.uvRatio||((S,g)=>{try{return{isValid:!0,value:n.sqrt(n.div(S,g))}}catch{return{isValid:!1,value:he}}});if(!ul(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function u(S,g,A=!1){let x=A?ft:he;return Br("coordinate "+S,g,x,c),g}function l(S){if(!(S instanceof d))throw new Error("EdwardsPoint expected")}let h=Ye((S,g)=>{let{X:A,Y:x,Z:_}=S,R=S.is0();g==null&&(g=R?cl:n.inv(_));let K=a(A*g),M=a(x*g),v=n.mul(_,g);if(R)return{x:he,y:ft};if(v!==ft)throw new Error("invZ was invalid");return{x:K,y:M}}),p=Ye(S=>{let{a:g,d:A}=s;if(S.is0())throw new Error("bad point: ZERO");let{X:x,Y:_,Z:R,T:K}=S,M=a(x*x),v=a(_*_),w=a(R*R),N=a(w*w),V=a(M*g),B=a(w*a(V+v)),y=a(N+a(A*a(M*v)));if(B!==y)throw new Error("bad point: equation left != right (1)");let b=a(x*_),m=a(R*K);if(b!==m)throw new Error("bad point: equation left != right (2)");return!0});class d{static BASE=new d(s.Gx,s.Gy,ft,a(s.Gx*s.Gy));static ZERO=new d(he,ft,ft,he);static Fp=n;static Fn=o;X;Y;Z;T;constructor(g,A,x,_){this.X=u("x",g),this.Y=u("y",A),this.Z=u("z",x,!0),this.T=u("t",_),Object.freeze(this)}static CURVE(){return s}static fromAffine(g){if(g instanceof d)throw new Error("extended point not allowed");let{x:A,y:x}=g||{};return u("x",A),u("y",x),new d(A,x,ft,a(A*x))}static fromBytes(g,A=!1){let x=n.BYTES,{a:_,d:R}=s;g=pn(U(g,x,"point")),ee(A,"zip215");let K=pn(g),M=g[x-1];K[x-1]=M&-129;let v=Se(K),w=A?c:n.ORDER;Br("point.y",v,he,w);let N=a(v*v),V=a(N-ft),B=a(R*N-_),{isValid:y,value:b}=f(V,B);if(!y)throw new Error("bad point: invalid y coordinate");let m=(b&ft)===ft,I=(M&128)!==0;if(!A&&b===he&&I)throw new Error("bad point: x=0 and x_0=1");return I!==m&&(b=a(-b)),d.fromAffine({x:b,y:v})}static fromHex(g,A=!1){return d.fromBytes(Jt(g),A)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,A=!0){return E.createCache(this,g),A||this.multiply(Xo),this}assertValidity(){p(this)}equals(g){l(g);let{X:A,Y:x,Z:_}=this,{X:R,Y:K,Z:M}=g,v=a(A*M),w=a(R*_),N=a(x*M),V=a(K*_);return v===w&&N===V}is0(){return this.equals(d.ZERO)}negate(){return new d(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:g}=s,{X:A,Y:x,Z:_}=this,R=a(A*A),K=a(x*x),M=a(Xo*a(_*_)),v=a(g*R),w=A+x,N=a(a(w*w)-R-K),V=v+K,B=V-M,y=v-K,b=a(N*B),m=a(V*y),I=a(N*y),C=a(B*V);return new d(b,m,C,I)}add(g){l(g);let{a:A,d:x}=s,{X:_,Y:R,Z:K,T:M}=this,{X:v,Y:w,Z:N,T:V}=g,B=a(_*v),y=a(R*w),b=a(M*x*V),m=a(K*N),I=a((_+R)*(v+w)-B-y),C=m-b,T=m+b,P=a(y-A*B),D=a(I*C),O=a(T*P),k=a(I*P),tt=a(C*T);return new d(D,O,tt,k)}subtract(g){return this.add(g.negate())}multiply(g){if(!o.isValidNot0(g))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:A,f:x}=E.cached(this,g,_=>_e(d,_));return _e(d,[A,x])[0]}multiplyUnsafe(g,A=d.ZERO){if(!o.isValid(g))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return g===he?d.ZERO:this.is0()||g===ft?this:E.unsafe(this,g,x=>_e(d,x),A)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return E.unsafe(this,s.n).is0()}toAffine(g){return h(this,g)}clearCofactor(){return i===ft?this:this.multiplyUnsafe(i)}toBytes(){let{x:g,y:A}=this.toAffine(),x=n.toBytes(A);return x[x.length-1]|=g&ft?128:0,x}toHex(){return Qt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let E=new We(d,o.BITS);return d.BASE.precompute(8),d}function Va(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');de(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:s,Fn:i}=e,c=r.randomBytes||He,a=r.adjustScalarBytes||(v=>v),f=r.domain||((v,w,N)=>{if(ee(N,"phflag"),w.length||N)throw new Error("Contexts/pre-hash are not supported");return v});function u(v){return i.create(Se(v))}function l(v){let w=x.secretKey;U(v,x.secretKey,"secretKey");let N=U(t(v),2*w,"hashedSecretKey"),V=a(N.slice(0,w)),B=N.slice(w,2*w),y=u(V);return{head:V,prefix:B,scalar:y}}function h(v){let{head:w,prefix:N,scalar:V}=l(v),B=o.multiply(V),y=B.toBytes();return{head:w,prefix:N,scalar:V,point:B,pointBytes:y}}function p(v){return h(v).pointBytes}function d(v=Uint8Array.of(),...w){let N=It(...w);return u(t(f(N,U(v,void 0,"context"),!!n)))}function E(v,w,N={}){v=U(v,void 0,"message"),n&&(v=n(v));let{prefix:V,scalar:B,pointBytes:y}=h(w),b=d(N.context,V,v),m=o.multiply(b).toBytes(),I=d(N.context,m,y,v),C=i.create(b+I*B);if(!i.isValid(C))throw new Error("sign failed: invalid s");let T=It(m,i.toBytes(C));return U(T,x.signature,"result")}let S={zip215:!0};function g(v,w,N,V=S){let{context:B,zip215:y}=V,b=x.signature;v=U(v,b,"signature"),w=U(w,void 0,"message"),N=U(N,x.publicKey,"publicKey"),y!==void 0&&ee(y,"zip215"),n&&(w=n(w));let m=b/2,I=v.subarray(0,m),C=Se(v.subarray(m,b)),T,P,D;try{T=e.fromBytes(N,y),P=e.fromBytes(I,y),D=o.multiplyUnsafe(C)}catch{return!1}if(!y&&T.isSmallOrder())return!1;let O=d(B,P.toBytes(),T.toBytes(),w);return P.add(T.multiplyUnsafe(O)).subtract(D).clearCofactor().is0()}let A=s.BYTES,x={secretKey:A,publicKey:A,signature:2*A,seed:A};function _(v=c(x.seed)){return U(v,x.seed,"seed")}function R(v){return we(v)&&v.length===i.BYTES}function K(v,w){try{return!!e.fromBytes(v,w)}catch{return!1}}let M={getExtendedPublicKey:h,randomSecretKey:_,isValidSecretKey:R,isValidPublicKey:K,toMontgomery(v){let{y:w}=e.fromBytes(v),N=x.publicKey,V=N===32;if(!V&&N!==57)throw new Error("only defined for 25519 and 448");let B=V?s.div(ft+w,ft-w):s.div(w-ft,w+ft);return s.toBytes(B)},toMontgomerySecret(v){let w=x.secretKey;U(v,w);let N=t(v.subarray(0,w));return a(N).subarray(0,w)}};return Object.freeze({keygen:yn(_,p),getPublicKey:p,sign:E,verify:g,utils:M,Point:e,lengths:x})}var fl=BigInt(1),Fa=BigInt(2);var ll=BigInt(5),dl=BigInt(8),Qo=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),hl={p:Qo,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:dl,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function pl(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Qo,c=e*e%s*e%s,a=X(c,Fa,s)*c%s,f=X(a,fl,s)*e%s,u=X(f,ll,s)*f%s,l=X(u,t,s)*u%s,h=X(l,r,s)*l%s,p=X(h,n,s)*h%s,d=X(p,o,s)*p%s,E=X(d,o,s)*p%s,S=X(E,t,s)*u%s;return{pow_p_5_8:X(S,Fa,s)*e%s,b2:c}}function ml(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var qa=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function yl(e,t){let r=Qo,n=st(t*t*t,r),o=st(n*n*t,r),s=pl(e*o).pow_p_5_8,i=st(e*n*s,r),c=st(t*i*i,r),a=i,f=st(i*qa,r),u=c===e,l=c===st(-e,r),h=c===st(-e*qa,r);return u&&(i=a),(l||h)&&(i=f),Pa(i,r)&&(i=st(-i,r)),{isValid:u||l,value:i}}var bl=Ma(hl,{uvRatio:yl});function gl(e){return Va(bl,ga,Object.assign({adjustScalarBytes:ml},e))}var Ha=gl({});var Rr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},bn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var za={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new bn("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var Dt=za;var gn=32;var Jo,xl=(async()=>{try{return await Dt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function wl(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Dt.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Dt.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function El(e,t,r){return Ha.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function $a(e,t,r){return Jo==null&&(Jo=await xl),Jo?wl(e,t,r):El(e,t,r)}function xn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var wn=class{type="Ed25519";raw;constructor(t){this.raw=ts(t,gn)}toMultihash(){return Bt.digest(Vt(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=$a(this.raw,r,t);return xn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function es(e){return e=ts(e,gn),new wn(e)}function ts(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new Q(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Sl=Math.pow(2,7),Il=Math.pow(2,14),Al=Math.pow(2,21),rs=Math.pow(2,28),ns=Math.pow(2,35),os=Math.pow(2,42),ss=Math.pow(2,49),Z=128,bt=127;function At(e){if(e<Sl)return 1;if(e<Il)return 2;if(e<Al)return 3;if(e<rs)return 4;if(e<ns)return 5;if(e<os)return 6;if(e<ss)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function je(e,t,r=0){switch(At(e)){case 8:t[r++]=e&255|Z,e/=128;case 7:t[r++]=e&255|Z,e/=128;case 6:t[r++]=e&255|Z,e/=128;case 5:t[r++]=e&255|Z,e/=128;case 4:t[r++]=e&255|Z,e>>>=7;case 3:t[r++]=e&255|Z,e>>>=7;case 2:t[r++]=e&255|Z,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function _l(e,t,r=0){switch(At(e)){case 8:t.set(r++,e&255|Z),e/=128;case 7:t.set(r++,e&255|Z),e/=128;case 6:t.set(r++,e&255|Z),e/=128;case 5:t.set(r++,e&255|Z),e/=128;case 4:t.set(r++,e&255|Z),e>>>=7;case 3:t.set(r++,e&255|Z),e>>>=7;case 2:t.set(r++,e&255|Z),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function is(e,t){let r=e[t],n=0;if(n+=r&bt,r<Z||(r=e[t+1],n+=(r&bt)<<7,r<Z)||(r=e[t+2],n+=(r&bt)<<14,r<Z)||(r=e[t+3],n+=(r&bt)<<21,r<Z)||(r=e[t+4],n+=(r&bt)*rs,r<Z)||(r=e[t+5],n+=(r&bt)*ns,r<Z)||(r=e[t+6],n+=(r&bt)*os,r<Z)||(r=e[t+7],n+=(r&bt)*ss,r<Z))return n;throw new RangeError("Could not decode varint")}function Cl(e,t){let r=e.get(t),n=0;if(n+=r&bt,r<Z||(r=e.get(t+1),n+=(r&bt)<<7,r<Z)||(r=e.get(t+2),n+=(r&bt)<<14,r<Z)||(r=e.get(t+3),n+=(r&bt)<<21,r<Z)||(r=e.get(t+4),n+=(r&bt)*rs,r<Z)||(r=e.get(t+5),n+=(r&bt)*ns,r<Z)||(r=e.get(t+6),n+=(r&bt)*os,r<Z)||(r=e.get(t+7),n+=(r&bt)*ss,r<Z))return n;throw new RangeError("Could not decode varint")}function Xe(e,t,r=0){return t==null&&(t=vt(At(e))),t instanceof Uint8Array?je(e,t,r):_l(e,t,r)}function Nr(e,t=0){return e instanceof Uint8Array?is(e,t):Cl(e,t)}var cs=new Float32Array([-0]),pe=new Uint8Array(cs.buffer);function Za(e,t,r){cs[0]=e,t[r]=pe[0],t[r+1]=pe[1],t[r+2]=pe[2],t[r+3]=pe[3]}function Ga(e,t){return pe[0]=e[t],pe[1]=e[t+1],pe[2]=e[t+2],pe[3]=e[t+3],cs[0]}var us=new Float64Array([-0]),gt=new Uint8Array(us.buffer);function Wa(e,t,r){us[0]=e,t[r]=gt[0],t[r+1]=gt[1],t[r+2]=gt[2],t[r+3]=gt[3],t[r+4]=gt[4],t[r+5]=gt[5],t[r+6]=gt[6],t[r+7]=gt[7]}function ja(e,t){return gt[0]=e[t],gt[1]=e[t+1],gt[2]=e[t+2],gt[3]=e[t+3],gt[4]=e[t+4],gt[5]=e[t+5],gt[6]=e[t+6],gt[7]=e[t+7],us[0]}var Dl=BigInt(Number.MAX_SAFE_INTEGER),Tl=BigInt(Number.MIN_SAFE_INTEGER),Ct=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&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(t=!1){if(t)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(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return Ce;if(t<Dl&&t>Tl)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Xa&&(o=0n,++n>Xa&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return Ce;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):Ce}},Ce=new Ct(0,0);Ce.toBigInt=function(){return 0n};Ce.zzEncode=Ce.zzDecode=function(){return this};Ce.length=function(){return 1};var Xa=4294967296n;function Qa(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Ja(e,t,r){if(r-t<1)return"";let o,s=[],i=0,c;for(;t<r;)c=e[t++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|e[t++]&63:c>239&&c<365?(c=((c&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&15)<<12|(e[t++]&63)<<6|e[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function fs(e,t,r){let n=r,o,s;for(let i=0;i<e.length;++i)o=e.charCodeAt(i),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((s=e.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function Lt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function En(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var ls=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Lt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Lt(this,4);return En(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Lt(this,4);return En(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Lt(this,4);let t=Ga(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Lt(this,4);let t=ja(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Lt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Ja(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Lt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Lt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Ct(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Lt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Lt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Lt(this,8);let t=En(this.buf,this.pos+=4),r=En(this.buf,this.pos+=4);return new Ct(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=is(this.buf,this.pos);return this.pos+=At(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function kr(e){return new ls(e instanceof Uint8Array?e:e.subarray())}function Ot(e,t,r){let n=kr(e);return t.decode(n,void 0,r)}function ds(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return vt(i);o+i>t&&(n=vt(t),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var De=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function hs(){}var ms=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Bl=ds();function Pl(e){return globalThis.Buffer!=null?vt(e):Bl(e)}var Kr=class{len;head;tail;states;constructor(){this.len=0,this.head=new De(hs,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new De(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new ys((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(vn,10,Ct.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=Ct.fromBigInt(t);return this._push(vn,r.length(),r)}uint64Number(t){return this._push(je,At(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=Ct.fromBigInt(t).zzEncode();return this._push(vn,r.length(),r)}sint64Number(t){let r=Ct.fromNumber(t).zzEncode();return this._push(vn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ps,1,t?1:0)}fixed32(t){return this._push(Ur,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=Ct.fromBigInt(t);return this._push(Ur,4,r.lo)._push(Ur,4,r.hi)}fixed64Number(t){let r=Ct.fromNumber(t);return this._push(Ur,4,r.lo)._push(Ur,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Za,4,t)}double(t){return this._push(Wa,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(ps,1,0):this.uint32(r)._push(Ol,r,t)}string(t){let r=Qa(t);return r!==0?this.uint32(r)._push(fs,r,t):this._push(ps,1,0)}fork(){return this.states=new ms(this),this.head=this.tail=new De(hs,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new De(hs,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=Pl(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function ps(e,t,r){t[r]=e&255}function Ll(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var ys=class extends De{next;constructor(t,r){super(Ll,t,r),this.next=void 0}};function vn(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function Ur(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function Ol(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Kr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Rl,t,e),this},Kr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Nl,t,e),this});function Rl(e,t,r){t.set(e,r)}function Nl(e,t,r){e.length<40?fs(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(F(e),r)}function bs(){return new Kr}function Rt(e,t){let r=bs();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*Nt(e,t,r){let n=kr(e);yield*t.stream(n,void 0,"$",r)}var Sn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function In(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function gs(e){function t(s){if(e[s.toString()]==null)throw new Error("Invalid enum value");return e[s]}let r=function(i,c){let a=t(i);c.int32(a)},n=function(i){let c=i.int32();return t(c)},o=function*(i){let c=i.int32();yield t(c)};return In("enum",Sn.VARINT,r,n,o)}function kt(e,t,r){return In("message",Sn.LENGTH_DELIMITED,e,t,r)}var Ht=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var J;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(J||(J={}));var xs;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(xs||(xs={}));(function(e){e.codec=()=>gs(xs)})(J||(J={}));var zt;(function(e){let t;e.codec=()=>(t==null&&(t=kt((s,i,c={})=>{c.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)),c.lengthDelimited!==!1&&i.ldelim()},(s,i,c={})=>{let a={},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{a.Type=J.codec().decode(s);break}case 2:{a.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return a},function*(s,i,c,a={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${c}.Type`,value:J.codec().decode(s)};break}case 2:{yield{field:`${c}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return Rt(s,e.codec())}e.encode=r;function n(s,i){return Ot(s,e.codec(),i)}e.decode=n;function o(s,i){return Nt(s,e.codec(),i)}e.stream=o})(zt||(zt={}));var ws;(function(e){let t;e.codec=()=>(t==null&&(t=kt((s,i,c={})=>{c.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)),c.lengthDelimited!==!1&&i.ldelim()},(s,i,c={})=>{let a={},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{a.Type=J.codec().decode(s);break}case 2:{a.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return a},function*(s,i,c,a={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${c}.Type`,value:J.codec().decode(s)};break}case 2:{yield{field:`${c}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return Rt(s,e.codec())}e.encode=r;function n(s,i){return Ot(s,e.codec(),i)}e.decode=n;function o(s,i){return Nt(s,e.codec(),i)}e.stream=o})(ws||(ws={}));var Vr={};Et(Vr,{MAX_RSA_KEY_SIZE:()=>Es,generateRSAKeyPair:()=>sc,jwkToJWKKeyPair:()=>ic,jwkToPkcs1:()=>Ml,jwkToPkix:()=>As,jwkToRSAPrivateKey:()=>Ts,pkcs1MessageToJwk:()=>Ss,pkcs1MessageToRSAPrivateKey:()=>_s,pkcs1ToJwk:()=>Kl,pkcs1ToRSAPrivateKey:()=>oc,pkixMessageToJwk:()=>Is,pkixMessageToRSAPublicKey:()=>Ds,pkixToJwk:()=>Vl,pkixToRSAPublicKey:()=>Cs});var Qe=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Vr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return at.createV1(114,this._multihash)}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}verify(t,r,n){return nc(this.jwk,r,t,n)}},Mr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Vr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}sign(t,r){return rc(this.jwk,t,r)}};var Es=8192,vs=18,kl=1062,Ul=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Kl(e){let t=Wt(e);return Ss(t)}function Ss(e){return{n:H(e[1],"base64url"),e:H(e[2],"base64url"),d:H(e[3],"base64url"),p:H(e[4],"base64url"),q:H(e[5],"base64url"),dp:H(e[6],"base64url"),dq:H(e[7],"base64url"),qi:H(e[8],"base64url"),kty:"RSA"}}function Ml(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new Q("JWK was missing components");return ce([St(Uint8Array.from([0])),St(F(e.n,"base64url")),St(F(e.e,"base64url")),St(F(e.d,"base64url")),St(F(e.p,"base64url")),St(F(e.q,"base64url")),St(F(e.dp,"base64url")),St(F(e.dq,"base64url")),St(F(e.qi,"base64url"))]).subarray()}function Vl(e){let t=Wt(e,{offset:0});return Is(t)}function Is(e){let t=Wt(e[1],{offset:0});return{kty:"RSA",n:H(t[0],"base64url"),e:H(t[1],"base64url")}}function As(e){if(e.n==null||e.e==null)throw new Q("JWK was missing components");return ce([Ul,cn(ce([St(F(e.n,"base64url")),St(F(e.e,"base64url"))]))]).subarray()}function oc(e){let t=Wt(e);return _s(t)}function _s(e){let t=Ss(e);return Ts(t)}function Cs(e,t){if(e.byteLength>=kl)throw new ke("Key size is too large");let r=Wt(e,{offset:0});return Ds(r,e,t)}function Ds(e,t,r){let n=Is(e);if(r==null){let o=ze(zt.encode({Type:J.RSA,Data:t}));r=Mt(vs,o)}return new Qe(n,r)}function Ts(e){if(cc(e)>Es)throw new Q("Key size is too large");let t=ic(e),r=ze(zt.encode({Type:J.RSA,Data:As(t.publicKey)})),n=Mt(vs,r);return new Mr(t.privateKey,new Qe(t.publicKey,n))}async function sc(e){if(e>Es)throw new Q("Key size is too large");let t=await ac(e),r=ze(zt.encode({Type:J.RSA,Data:As(t.publicKey)})),n=Mt(vs,r);return new Mr(t.privateKey,new Qe(t.publicKey,n))}function ic(e){if(e==null)throw new Q("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function ac(e,t){let r=await Dt.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await Fl(r,t);return{privateKey:n[0],publicKey:n[1]}}async function rc(e,t,r){let n=await Dt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Dt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function nc(e,t,r,n){let o=await Dt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Dt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),s}async function Fl(e,t){if(e.privateKey==null||e.publicKey==null)throw new Q("Private and public key are required");let r=await Promise.all([Dt.get().subtle.exportKey("jwk",e.privateKey),Dt.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function cc(e){if(e.kty!=="RSA")throw new Q("invalid key type");if(e.n==null)throw new Q("invalid key modulus");return F(e.n,"base64url").length*8}var An=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,r){if(un(t),U(r,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?t.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),Xt(o)}update(t){return qe(this),this.iHash.update(t),this}digestInto(t){qe(this),U(t,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Bs=(e,t,r)=>new An(e,t).update(r).digest();Bs.create=(e,t)=>new An(e,t);var uc=(e,t)=>(e+(e>=0?t:-t)/fc)/t;function ql(e,t,r){let[[n,o],[s,i]]=t,c=uc(i*e,r),a=uc(-o*e,r),f=e-c*n-a*s,u=-c*o-a*i,l=f<re,h=u<re;l&&(f=-f),h&&(u=-u);let p=Pr(Math.ceil(qo(r)/2))+Je;if(f<re||f>=p||u<re||u>=p)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:l,k1:f,k2neg:h,k2:u}}function Ls(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Ps(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return ee(r.lowS,"lowS"),ee(r.prehash,"prehash"),r.format!==void 0&&Ls(r.format),r}var Os=class extends Error{constructor(t=""){super(t)}},me={Err:Os,_tlv:{encode:(e,t)=>{let{Err:r}=me;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=Tr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Tr(o.length/2|128):"";return Tr(e)+s+o+t},decode(e,t){let{Err:r}=me,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let a=o&127;if(!a)throw new r("tlv.decode(long): indefinite length not supported");if(a>4)throw new r("tlv.decode(long): byte length is too big");let f=t.subarray(n,n+a);if(f.length!==a)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let u of f)i=i<<8|u;if(n+=a,i<128)throw new r("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new r("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=me;if(e<re)throw new t("integer: negative integers are not allowed");let r=Tr(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=me;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return $e(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=me,o=U(e,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,s),{v:f,l:u}=n.decode(2,a);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(f)}},hexFromSig(e){let{_tlv:t,_int:r}=me,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},re=BigInt(0),Je=BigInt(1),fc=BigInt(2),_n=BigInt(3),Hl=BigInt(4);function lc(e,t={}){let r=mn("weierstrass",e,t),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:c}=s;de(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:a}=t;if(a&&(!n.is0(s.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=hc(n,o);function u(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(B,y,b){let{x:m,y:I}=y.toAffine(),C=n.toBytes(m);if(ee(b,"isCompressed"),b){u();let T=!n.isOdd(I);return It(dc(T),C)}else return It(Uint8Array.of(4),C,n.toBytes(I))}function h(B){U(B,void 0,"Point");let{publicKey:y,publicKeyUncompressed:b}=f,m=B.length,I=B[0],C=B.subarray(1);if(m===y&&(I===2||I===3)){let T=n.fromBytes(C);if(!n.isValid(T))throw new Error("bad point: is not on curve, wrong x");let P=E(T),D;try{D=n.sqrt(P)}catch(tt){let j=tt instanceof Error?": "+tt.message:"";throw new Error("bad point: is not on curve, sqrt error"+j)}u();let O=n.isOdd(D);return(I&1)===1!==O&&(D=n.neg(D)),{x:T,y:D}}else if(m===b&&I===4){let T=n.BYTES,P=n.fromBytes(C.subarray(0,T)),D=n.fromBytes(C.subarray(T,T*2));if(!S(P,D))throw new Error("bad point: is not on curve");return{x:P,y:D}}else throw new Error(`bad point: got length ${m}, expected compressed=${y} or uncompressed=${b}`)}let p=t.toBytes||l,d=t.fromBytes||h;function E(B){let y=n.sqr(B),b=n.mul(y,B);return n.add(n.add(b,n.mul(B,s.a)),s.b)}function S(B,y){let b=n.sqr(y),m=E(B);return n.eql(b,m)}if(!S(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let g=n.mul(n.pow(s.a,_n),Hl),A=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(g,A)))throw new Error("bad curve params: a or b");function x(B,y,b=!1){if(!n.isValid(y)||b&&n.is0(y))throw new Error(`bad point coordinate ${B}`);return y}function _(B){if(!(B instanceof w))throw new Error("Weierstrass Point expected")}function R(B){if(!a||!a.basises)throw new Error("no endo");return ql(B,a.basises,o.ORDER)}let K=Ye((B,y)=>{let{X:b,Y:m,Z:I}=B;if(n.eql(I,n.ONE))return{x:b,y:m};let C=B.is0();y==null&&(y=C?n.ONE:n.inv(I));let T=n.mul(b,y),P=n.mul(m,y),D=n.mul(I,y);if(C)return{x:n.ZERO,y:n.ZERO};if(!n.eql(D,n.ONE))throw new Error("invZ was invalid");return{x:T,y:P}}),M=Ye(B=>{if(B.is0()){if(t.allowInfinityPoint&&!n.is0(B.Y))return;throw new Error("bad point: ZERO")}let{x:y,y:b}=B.toAffine();if(!n.isValid(y)||!n.isValid(b))throw new Error("bad point: x or y not field elements");if(!S(y,b))throw new Error("bad point: equation left != right");if(!B.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function v(B,y,b,m,I){return b=new w(n.mul(b.X,B),b.Y,b.Z),y=Or(m,y),b=Or(I,b),y.add(b)}class w{static BASE=new w(s.Gx,s.Gy,n.ONE);static ZERO=new w(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(y,b,m){this.X=x("x",y),this.Y=x("y",b,!0),this.Z=x("z",m),Object.freeze(this)}static CURVE(){return s}static fromAffine(y){let{x:b,y:m}=y||{};if(!y||!n.isValid(b)||!n.isValid(m))throw new Error("invalid affine point");if(y instanceof w)throw new Error("projective point not allowed");return n.is0(b)&&n.is0(m)?w.ZERO:new w(b,m,n.ONE)}static fromBytes(y){let b=w.fromAffine(d(U(y,void 0,"point")));return b.assertValidity(),b}static fromHex(y){return w.fromBytes(Jt(y))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,b=!0){return V.createCache(this,y),b||this.multiply(_n),this}assertValidity(){M(this)}hasEvenY(){let{y}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(y)}equals(y){_(y);let{X:b,Y:m,Z:I}=this,{X:C,Y:T,Z:P}=y,D=n.eql(n.mul(b,P),n.mul(C,I)),O=n.eql(n.mul(m,P),n.mul(T,I));return D&&O}negate(){return new w(this.X,n.neg(this.Y),this.Z)}double(){let{a:y,b}=s,m=n.mul(b,_n),{X:I,Y:C,Z:T}=this,P=n.ZERO,D=n.ZERO,O=n.ZERO,k=n.mul(I,I),tt=n.mul(C,C),j=n.mul(T,T),z=n.mul(I,C);return z=n.add(z,z),O=n.mul(I,T),O=n.add(O,O),P=n.mul(y,O),D=n.mul(m,j),D=n.add(P,D),P=n.sub(tt,D),D=n.add(tt,D),D=n.mul(P,D),P=n.mul(z,P),O=n.mul(m,O),j=n.mul(y,j),z=n.sub(k,j),z=n.mul(y,z),z=n.add(z,O),O=n.add(k,k),k=n.add(O,k),k=n.add(k,j),k=n.mul(k,z),D=n.add(D,k),j=n.mul(C,T),j=n.add(j,j),k=n.mul(j,z),P=n.sub(P,k),O=n.mul(j,tt),O=n.add(O,O),O=n.add(O,O),new w(P,D,O)}add(y){_(y);let{X:b,Y:m,Z:I}=this,{X:C,Y:T,Z:P}=y,D=n.ZERO,O=n.ZERO,k=n.ZERO,tt=s.a,j=n.mul(s.b,_n),z=n.mul(b,C),et=n.mul(m,T),dt=n.mul(I,P),Kt=n.add(b,m),rt=n.add(C,T);Kt=n.mul(Kt,rt),rt=n.add(z,et),Kt=n.sub(Kt,rt),rt=n.add(b,I);let yt=n.add(C,P);return rt=n.mul(rt,yt),yt=n.add(z,dt),rt=n.sub(rt,yt),yt=n.add(m,I),D=n.add(T,P),yt=n.mul(yt,D),D=n.add(et,dt),yt=n.sub(yt,D),k=n.mul(tt,rt),D=n.mul(j,dt),k=n.add(D,k),D=n.sub(et,k),k=n.add(et,k),O=n.mul(D,k),et=n.add(z,z),et=n.add(et,z),dt=n.mul(tt,dt),rt=n.mul(j,rt),et=n.add(et,dt),dt=n.sub(z,dt),dt=n.mul(tt,dt),rt=n.add(rt,dt),z=n.mul(et,rt),O=n.add(O,z),z=n.mul(yt,rt),D=n.mul(Kt,D),D=n.sub(D,z),z=n.mul(Kt,et),k=n.mul(yt,k),k=n.add(k,z),new w(D,O,k)}subtract(y){return this.add(y.negate())}is0(){return this.equals(w.ZERO)}multiply(y){let{endo:b}=t;if(!o.isValidNot0(y))throw new Error("invalid scalar: out of range");let m,I,C=T=>V.cached(this,T,P=>_e(w,P));if(b){let{k1neg:T,k1:P,k2neg:D,k2:O}=R(y),{p:k,f:tt}=C(P),{p:j,f:z}=C(O);I=tt.add(z),m=v(b.beta,k,j,T,D)}else{let{p:T,f:P}=C(y);m=T,I=P}return _e(w,[m,I])[0]}multiplyUnsafe(y){let{endo:b}=t,m=this;if(!o.isValid(y))throw new Error("invalid scalar: out of range");if(y===re||m.is0())return w.ZERO;if(y===Je)return m;if(V.hasCache(this))return this.multiply(y);if(b){let{k1neg:I,k1:C,k2neg:T,k2:P}=R(y),{p1:D,p2:O}=Ka(w,m,C,P);return v(b.beta,D,O,I,T)}else return V.unsafe(m,y)}toAffine(y){return K(this,y)}isTorsionFree(){let{isTorsionFree:y}=t;return i===Je?!0:y?y(w,this):V.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:y}=t;return i===Je?this:y?y(w,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(y=!0){return ee(y,"isCompressed"),this.assertValidity(),p(w,this,y)}toHex(y=!0){return Qt(this.toBytes(y))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let N=o.BITS,V=new We(w,t.endo?Math.ceil(N/2):N);return w.BASE.precompute(8),w}function dc(e){return Uint8Array.of(e?2:3)}function hc(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function zl(e,t={}){let{Fn:r}=e,n=t.randomBytes||He,o=Object.assign(hc(e.Fp,r),{seed:Yo(r.ORDER)});function s(p){try{let d=r.fromBytes(p);return r.isValidNot0(d)}catch{return!1}}function i(p,d){let{publicKey:E,publicKeyUncompressed:S}=o;try{let g=p.length;return d===!0&&g!==E||d===!1&&g!==S?!1:!!e.fromBytes(p)}catch{return!1}}function c(p=n(o.seed)){return Zo(U(p,o.seed,"seed"),r.ORDER)}function a(p,d=!0){return e.BASE.multiply(r.fromBytes(p)).toBytes(d)}function f(p){let{secretKey:d,publicKey:E,publicKeyUncompressed:S}=o;if(!we(p)||"_lengths"in r&&r._lengths||d===E)return;let g=U(p,void 0,"key").length;return g===E||g===S}function u(p,d,E=!0){if(f(p)===!0)throw new Error("first arg must be private key");if(f(d)===!1)throw new Error("second arg must be public key");let S=r.fromBytes(p);return e.fromBytes(d).multiply(S).toBytes(E)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:c},h=yn(c,a);return Object.freeze({getPublicKey:a,getSharedSecret:u,keygen:h,Point:e,utils:l,lengths:o})}function pc(e,t,r={}){un(t),de(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let n=r.randomBytes||He,o=r.hmac||((b,m)=>Bs(t,b,m)),{Fp:s,Fn:i}=e,{ORDER:c,BITS:a}=i,{keygen:f,getPublicKey:u,getSharedSecret:l,utils:h,lengths:p}=zl(e,r),d={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},E=c*fc<s.ORDER;function S(b){let m=c>>Je;return b>m}function g(b,m){if(!i.isValidNot0(m))throw new Error(`invalid signature ${b}: out of range 1..Point.Fn.ORDER`);return m}function A(){if(E)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function x(b,m){Ls(m);let I=p.signature,C=m==="compact"?I:m==="recovered"?I+1:void 0;return U(b,C)}class _{r;s;recovery;constructor(m,I,C){if(this.r=g("r",m),this.s=g("s",I),C!=null){if(A(),![0,1,2,3].includes(C))throw new Error("invalid recovery id");this.recovery=C}Object.freeze(this)}static fromBytes(m,I=d.format){x(m,I);let C;if(I==="der"){let{r:O,s:k}=me.toSig(U(m));return new _(O,k)}I==="recovered"&&(C=m[0],I="compact",m=m.subarray(1));let T=p.signature/2,P=m.subarray(0,T),D=m.subarray(T,T*2);return new _(i.fromBytes(P),i.fromBytes(D),C)}static fromHex(m,I){return this.fromBytes(Jt(m),I)}assertRecovery(){let{recovery:m}=this;if(m==null)throw new Error("invalid recovery id: must be present");return m}addRecoveryBit(m){return new _(this.r,this.s,m)}recoverPublicKey(m){let{r:I,s:C}=this,T=this.assertRecovery(),P=T===2||T===3?I+c:I;if(!s.isValid(P))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let D=s.toBytes(P),O=e.fromBytes(It(dc((T&1)===0),D)),k=i.inv(P),tt=K(U(m,void 0,"msgHash")),j=i.create(-tt*k),z=i.create(C*k),et=e.BASE.multiplyUnsafe(j).add(O.multiplyUnsafe(z));if(et.is0())throw new Error("invalid recovery: point at infinify");return et.assertValidity(),et}hasHighS(){return S(this.s)}toBytes(m=d.format){if(Ls(m),m==="der")return Jt(me.hexFromSig(this));let{r:I,s:C}=this,T=i.toBytes(I),P=i.toBytes(C);return m==="recovered"?(A(),It(Uint8Array.of(this.assertRecovery()),T,P)):It(T,P)}toHex(m){return Qt(this.toBytes(m))}}let R=r.bits2int||function(m){if(m.length>8192)throw new Error("input is too large");let I=$e(m),C=m.length*8-a;return C>0?I>>BigInt(C):I},K=r.bits2int_modN||function(m){return i.create(R(m))},M=Pr(a);function v(b){return Br("num < 2^"+a,b,re,M),i.toBytes(b)}function w(b,m){return U(b,void 0,"message"),m?U(t(b),void 0,"prehashed message"):b}function N(b,m,I){let{lowS:C,prehash:T,extraEntropy:P}=Ps(I,d);b=w(b,T);let D=K(b),O=i.fromBytes(m);if(!i.isValidNot0(O))throw new Error("invalid private key");let k=[v(O),v(D)];if(P!=null&&P!==!1){let et=P===!0?n(p.secretKey):P;k.push(U(et,void 0,"extraEntropy"))}let tt=It(...k),j=D;function z(et){let dt=R(et);if(!i.isValidNot0(dt))return;let Kt=i.inv(dt),rt=e.BASE.multiply(dt).toAffine(),yt=i.create(rt.x);if(yt===re)return;let Jr=i.create(Kt*i.create(j+yt*O));if(Jr===re)return;let Di=(rt.x===yt?0:2)|Number(rt.y&Je),Ti=Jr;return C&&S(Jr)&&(Ti=i.neg(Jr),Di^=1),new _(yt,Ti,E?void 0:Di)}return{seed:tt,k2sig:z}}function V(b,m,I={}){let{seed:C,k2sig:T}=N(b,m,I);return Ea(t.outputLen,i.BYTES,o)(C,T).toBytes(I.format)}function B(b,m,I,C={}){let{lowS:T,prehash:P,format:D}=Ps(C,d);if(I=U(I,void 0,"publicKey"),m=w(m,P),!we(b)){let O=b instanceof _?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+O)}x(b,D);try{let O=_.fromBytes(b,D),k=e.fromBytes(I);if(T&&O.hasHighS())return!1;let{r:tt,s:j}=O,z=K(m),et=i.inv(j),dt=i.create(z*et),Kt=i.create(tt*et),rt=e.BASE.multiplyUnsafe(dt).add(k.multiplyUnsafe(Kt));return rt.is0()?!1:i.create(rt.x)===tt}catch{return!1}}function y(b,m,I={}){let{prehash:C}=Ps(I,d);return m=w(m,C),_.fromBytes(b,"recovered").recoverPublicKey(m).toBytes()}return Object.freeze({keygen:f,getPublicKey:u,getSharedSecret:l,utils:h,lengths:p,Point:e,sign:V,verify:B,recoverPublicKey:y,Signature:_,hash:t})}var Ns={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},$l={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var mc=BigInt(2);function Yl(e){let t=Ns.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),f=e*e*e%t,u=f*f*e%t,l=X(u,r,t)*u%t,h=X(l,r,t)*u%t,p=X(h,mc,t)*f%t,d=X(p,o,t)*p%t,E=X(d,s,t)*d%t,S=X(E,c,t)*E%t,g=X(S,a,t)*S%t,A=X(g,c,t)*E%t,x=X(A,r,t)*u%t,_=X(x,i,t)*d%t,R=X(_,n,t)*f%t,K=X(R,mc,t);if(!Rs.eql(Rs.sqr(K),e))throw new Error("Cannot find square root");return K}var Rs=Ze(Ns.p,{sqrt:Yl}),Zl=lc(Ns,{Fp:Rs,endo:$l}),tr=pc(Zl,ze);function yc(e,t,r,n){let o=vr.digest(r instanceof Uint8Array?r:r.subarray());if(xn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),tr.verify(t,s,e,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Rr(String(s))});try{return n?.signal?.throwIfAborted(),tr.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(s){throw new Rr(String(s))}}var Cn=class{type="secp256k1";raw;_key;constructor(t){this._key=gc(t),this.raw=bc(this._key)}toMultihash(){return Bt.digest(Vt(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}verify(t,r,n){return yc(this._key,r,t,n)}};function ks(e){return new Cn(e)}function bc(e){return tr.Point.fromBytes(e).toBytes()}function gc(e){try{return tr.Point.fromBytes(e),e}catch(t){throw new ke(String(t))}}function er(e,t){let{Type:r,Data:n}=zt.decode(e),o=n??new Uint8Array;switch(r){case J.RSA:return Cs(o,t);case J.Ed25519:return es(o);case J.secp256k1:return ks(o);case J.ECDSA:return Bo(o);default:throw new ge}}function xc(e){let{Type:t,Data:r}=zt.decode(e.digest),n=r??new Uint8Array;switch(t){case J.Ed25519:return es(n);case J.secp256k1:return ks(n);case J.ECDSA:return Bo(n);default:throw new ge}}function Vt(e){return zt.encode({Type:J[e.type],Data:e.raw})}var Fr;(function(e){let t;e.codec=()=>(t==null&&(t=kt((s,i,c={})=>{c.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)),c.lengthDelimited!==!1&&i.ldelim()},(s,i,c={})=>{let a={publicKey:ht(0),payloadType:ht(0),payload:ht(0),signature:ht(0)},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{a.publicKey=s.bytes();break}case 2:{a.payloadType=s.bytes();break}case 3:{a.payload=s.bytes();break}case 5:{a.signature=s.bytes();break}default:{s.skipType(u&7);break}}}return a},function*(s,i,c,a={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${c}.publicKey`,value:s.bytes()};break}case 2:{yield{field:`${c}.payloadType`,value:s.bytes()};break}case 3:{yield{field:`${c}.payload`,value:s.bytes()};break}case 5:{yield{field:`${c}.signature`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return Rt(s,e.codec())}e.encode=r;function n(s,i){return Ot(s,e.codec(),i)}e.decode=n;function o(s,i){return Nt(s,e.codec(),i)}e.stream=o})(Fr||(Fr={}));var Dn=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var $t=class e{static createFromProtobuf=t=>{let r=Fr.decode(t),n=er(r.publicKey);return new e({publicKey:n,payloadType:r.payloadType,payload:r.payload,signature:r.signature})};static seal=async(t,r,n)=>{if(r==null)throw new Error("Missing private key");let o=t.domain,s=t.codec,i=t.marshal(),c=wc(o,s,i),a=await r.sign(c.subarray(),n);return new e({publicKey:r.publicKey,payloadType:s,payload:i,signature:a})};static openAndCertify=async(t,r,n)=>{let o=e.createFromProtobuf(t);if(!await o.validate(r,n))throw new Dn("Envelope signature is not valid for the given domain");return o};publicKey;payloadType;payload;signature;marshaled;constructor(t){let{publicKey:r,payloadType:n,payload:o,signature:s}=t;this.publicKey=r,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=Fr.encode({publicKey:Vt(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return t==null?!1:ct(this.marshal(),t.marshal())}async validate(t,r){let n=wc(t,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},wc=(e,t,r)=>{let n=F(e),o=Xe(n.byteLength),s=Xe(t.length),i=Xe(r.length);return new it(o,n,s,t,i,r)};var Ec=Symbol.for("nodejs.util.inspect.custom"),Gl=114,qr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[eo]=!0;toString(){return this.string==null&&(this.string=ot.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return at.createV1(Gl,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return ct(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return ct(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Ec](){return`PeerId(${this.toString()})`}},Hr=class extends qr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},zr=class extends qr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},$r=class extends qr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Wl=2336,Yr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Bt.digest(F(this.url))}[Ec](){return`PeerId(${this.url})`}[eo]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return at.createV1(Wl,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=H(t)),t.toString()===this.toString())}};var jl=114,vc=2336;function Sc(e){if(e.type==="Ed25519")return new zr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new $r({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new Hr({multihash:e.toCID().multihash,publicKey:e});throw new ge}function Us(e){if(Ql(e))return new Hr({multihash:e});if(Xl(e))try{let t=xc(e);if(t.type==="Ed25519")return new zr({multihash:e,publicKey:t});if(t.type==="secp256k1")return new $r({multihash:e,publicKey:t})}catch{let r=H(e.digest);return new Yr(new URL(r))}throw new rn("Supplied PeerID Multihash is invalid")}function Tn(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==jl&&e.code!==vc)throw new en("Supplied PeerID CID is invalid");if(e.code===vc){let t=H(e.multihash.digest);return new Yr(new URL(t))}return Us(e.multihash)}function Xl(e){return e.code===Bt.code}function Ql(e){return e.code===vr.code}var mt=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},ne=class extends Error{static name="ValidationError";name="ValidationError"},Bn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Pn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var Ln=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let r=this.index,n=t();return n===void 0&&(this.index=r),n}parseWith(t){let r=t();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(t){return this.readAtomically(()=>{let r=this.readChar();if(r===t)return r})}readSeparator(t,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,r,n,o){return this.readAtomically(()=>{let s=0,i=0,c=this.peekChar();if(c===void 0)return;let a=c==="0",f=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let h=Number.parseInt(l,t);if(!Number.isNaN(h))return h});if(u===void 0)break;if(s*=t,s+=u,s>f||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&a&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let r=0;r<t.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[r]=n}return t})}readIPv6Addr(){let t=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]=t(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),[c]=t(s.subarray(0,i));return r.set(s.subarray(0,c),16-c),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Ic=45,Jl=15,rr=new Ln;function On(e){if(!(e.length>Jl))return rr.new(e).parseWith(()=>rr.readIPv4Addr())}function Rn(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>Ic))return rr.new(e).parseWith(()=>rr.readIPv6Addr())}function nr(e,t=!1){if(e.includes("%")&&(e=e.split("%")[0]),e.length>Ic)return;let r=rr.new(e).parseWith(()=>rr.readIPAddr());if(r)return t&&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 or(e){return!!On(e)}function Nn(e){return!!Rn(e)}function Ms(e){return t=>H(t,e)}function Vs(e){return t=>F(t,e)}function sr(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function Te(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function Ac(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let r=F(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Te(n);return Gt([r,o],r.length+o.length)}function _c(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let r=ae.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Te(n);return Gt([r,o],r.length+o.length)}function Fs(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=H(t,"base32"),o=sr(r);return`${n}:${o}`}var qs=function(e){e=e.toString().trim();let t=new Uint8Array(4);return e.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new mt("Invalid byte value in IP address");t[n]=o}),t},Cc=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let s=or(r[n]),i;s&&(i=qs(r[n]),r[n]=H(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,H(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(t+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 mt("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Dc=function(e){if(e.byteLength!==4)throw new mt("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},Tc=function(e){if(e.byteLength!==16)throw new mt("IPv6 address was incorrect length");let t=[];for(let n=0;n<e.byteLength;n+=2){let o=e[n],s=e[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let r=t.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new mt(`Invalid IPv6 address "${r}"`)}};function Bc(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new mt(`Invalid IPv6 address "${e}"`)}}var Ks=Object.values(Sr).map(e=>e.decoder),td=(function(){let e=Ks[0].or(Ks[1]);return Ks.slice(2).forEach(t=>e=e.or(t)),e})();function Pc(e){return td.decode(e)}function Lc(e){return t=>e.encoder.encode(t)}function ed(e){if(parseInt(e).toString()!==e)throw new ne("Value must be an integer")}function rd(e){if(e<0)throw new ne("Value must be a positive integer, or zero")}function nd(e){return t=>{if(t>e)throw new ne(`Value must be smaller than or equal to ${e}`)}}function od(...e){return t=>{for(let r of e)r(t)}}var Zr=od(ed,rd,nd(65535));var lt=-1,Hs=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let r;if(typeof t=="string"?r=this.protocolsByName.get(t):r=this.protocolsByCode.get(t),r==null)throw new Pn(`Protocol ${t} was unknown`);return r}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(r=>{this.protocolsByName.set(r,t)})}removeProtocol(t){let r=this.protocolsByCode.get(t);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},se=new Hs,gd=[{code:4,name:"ip4",size:32,valueToBytes:qs,bytesToValue:Dc,validate:e=>{if(!or(e))throw new ne(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Te,bytesToValue:sr,validate:Zr},{code:273,name:"udp",size:16,valueToBytes:Te,bytesToValue:sr,validate:Zr},{code:33,name:"dccp",size:16,valueToBytes:Te,bytesToValue:sr,validate:Zr},{code:41,name:"ip6",size:128,valueToBytes:Cc,bytesToValue:Tc,stringToValue:Bc,validate:e=>{if(!Nn(e))throw new ne(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:lt},{code:43,name:"ipcidr",size:8,bytesToValue:Ms("base10"),valueToBytes:Vs("base10")},{code:53,name:"dns",size:lt},{code:54,name:"dns4",size:lt},{code:55,name:"dns6",size:lt},{code:56,name:"dnsaddr",size:lt},{code:132,name:"sctp",size:16,valueToBytes:Te,bytesToValue:sr,validate:Zr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:lt,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:lt,bytesToValue:Ms("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?Vs("base58btc")(e):at.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Fs,valueToBytes:Ac},{code:445,name:"onion3",size:296,bytesToValue:Fs,valueToBytes:_c},{code:446,name:"garlic64",size:lt},{code:447,name:"garlic32",size:lt},{code:448,name:"tls"},{code:449,name:"sni",size:lt},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:lt,bytesToValue:Lc(bo),valueToBytes:Pc},{code:480,name:"http"},{code:481,name:"http-path",size:lt,stringToValue:e=>`/${decodeURIComponent(e)}`,valueToString:e=>encodeURIComponent(e.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:lt}];gd.forEach(e=>{se.addProtocol(e)});function Oc(e){let t=[],r=0;for(;r<e.length;){let n=Nr(e,r),o=se.getProtocol(n),s=At(n),i=xd(o,e,r+s),c=0;i>0&&o.size===lt&&(c=At(i));let a=s+c+i,f={code:n,name:o.name,bytes:e.subarray(r,r+a)};if(i>0){let u=r+s+c,l=e.subarray(u,u+i);f.value=o.bytesToValue?.(l)??H(l)}t.push(f),r+=a}return t}function Rc(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=se.getProtocol(n.code),s=At(n.code),i,c=0,a=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??F(n.value),c=i.byteLength,o.size===lt&&(a=At(c)));let f=new Uint8Array(s+a+c),u=0;je(n.code,f,u),u+=s,i!=null&&(o.size===lt&&(je(c,f,u),u+=a),f.set(i,u)),n.bytes=f}r.push(n.bytes),t+=n.bytes.byteLength}return Gt(r,t)}function Nc(e){if(e.charAt(0)!=="/")throw new mt('String multiaddr must start with "/"');let t=[],r="protocol",n="",o="";for(let s=1;s<e.length;s++){let i=e.charAt(s);i!=="/"&&(r==="protocol"?o+=e.charAt(s):n+=e.charAt(s));let c=s===e.length-1;if(i==="/"||c){let a=se.getProtocol(o);if(r==="protocol"){if(a.size==null||a.size===0){t.push({code:a.code,name:a.name}),n="",o="",r="protocol";continue}else if(c)throw new mt(`Component ${o} was missing value`);r="value"}else if(r==="value"){let f={code:a.code,name:a.name};if(a.size!=null&&a.size!==0){if(n==="")throw new mt(`Component ${o} was missing value`);f.value=a.stringToValue?.(n)??n}t.push(f),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new mt("Incomplete multiaddr");return t}function kc(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=se.getProtocol(t.code);if(r==null)throw new mt(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function xd(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:Nr(t,r)}var wd=Symbol.for("nodejs.util.inspect.custom"),oi=Symbol.for("@multiformats/multiaddr");function Ed(e){if(e==null&&(e="/"),Uc(e))return e.getComponents();if(e instanceof Uint8Array)return Oc(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),Nc(e);if(Array.isArray(e))return e;throw new mt("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Fn=class e{[oi]=!0;#t;#e;#r;constructor(t="/",r={}){this.#t=Ed(t),r.validate!==!1&&vd(this)}get bytes(){return this.#r==null&&(this.#r=Rc(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=kc(this.#t)),this.#e}toJSON(){return this.toString()}getComponents(){return[...this.#t.map(t=>({...t}))]}encapsulate(t){let r=new e(t);return new e([...this.#t,...r.getComponents()],{validate:!1})}decapsulate(t){let r=t.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new Bn(`Address ${this.toString()} does not contain subaddress: ${r}`);return new e(n.slice(0,o),{validate:!1})}decapsulateCode(t){let r;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){r=n;break}return new e(this.#t.slice(0,r),{validate:!1})}equals(t){return ct(this.bytes,t.bytes)}[wd](){return`Multiaddr(${this.toString()})`}};function vd(e){e.getComponents().forEach(t=>{let r=se.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function Uc(e){return!!e?.[oi]}function Pe(e){return new Fn(e)}var Kc="libp2p-peer-record",Mc=Uint8Array.from([3,1]);var Wr;(function(e){let t;(function(i){let c;i.codec=()=>(c==null&&(c=kt((l,h,p={})=>{p.lengthDelimited!==!1&&h.fork(),l.multiaddr!=null&&l.multiaddr.byteLength>0&&(h.uint32(10),h.bytes(l.multiaddr)),p.lengthDelimited!==!1&&h.ldelim()},(l,h,p={})=>{let d={multiaddr:ht(0)},E=h==null?l.len:l.pos+h;for(;l.pos<E;){let S=l.uint32();switch(S>>>3){case 1:{d.multiaddr=l.bytes();break}default:{l.skipType(S&7);break}}}return d},function*(l,h,p,d={}){let E=h==null?l.len:l.pos+h;for(;l.pos<E;){let S=l.uint32();switch(S>>>3){case 1:{yield{field:`${p}.multiaddr`,value:l.bytes()};break}default:{l.skipType(S&7);break}}}})),c);function a(l){return Rt(l,i.codec())}i.encode=a;function f(l,h){return Ot(l,i.codec(),h)}i.decode=f;function u(l,h){return Nt(l,i.codec(),h)}i.stream=u})(t=e.AddressInfo||(e.AddressInfo={}));let r;e.codec=()=>(r==null&&(r=kt((i,c,a={})=>{if(a.lengthDelimited!==!1&&c.fork(),i.peerId!=null&&i.peerId.byteLength>0&&(c.uint32(10),c.bytes(i.peerId)),i.seq!=null&&i.seq!==0n&&(c.uint32(16),c.uint64(i.seq)),i.addresses!=null&&i.addresses.length>0)for(let f of i.addresses)c.uint32(26),e.AddressInfo.codec().encode(f,c);a.lengthDelimited!==!1&&c.ldelim()},(i,c,a={})=>{let f={peerId:ht(0),seq:0n,addresses:[]},u=c==null?i.len:i.pos+c;for(;i.pos<u;){let l=i.uint32();switch(l>>>3){case 1:{f.peerId=i.bytes();break}case 2:{f.seq=i.uint64();break}case 3:{if(a.limits?.addresses!=null&&f.addresses.length===a.limits.addresses)throw new Ht('Decode error - repeated field "addresses" had too many elements');f.addresses.push(e.AddressInfo.codec().decode(i,i.uint32(),{limits:a.limits?.addresses$}));break}default:{i.skipType(l&7);break}}}return f},function*(i,c,a,f={}){let u={addresses:0},l=c==null?i.len:i.pos+c;for(;i.pos<l;){let h=i.uint32();switch(h>>>3){case 1:{yield{field:`${a}.peerId`,value:i.bytes()};break}case 2:{yield{field:`${a}.seq`,value:i.uint64()};break}case 3:{if(f.limits?.addresses!=null&&u.addresses===f.limits.addresses)throw new Ht('Streaming decode error - repeated field "addresses" had too many elements');for(let p of e.AddressInfo.codec().stream(i,i.uint32(),`${a}.addresses[]`,{limits:f.limits?.addresses$}))yield{...p,index:u.addresses};u.addresses++;break}default:{i.skipType(h&7);break}}}})),r);function n(i){return Rt(i,e.codec())}e.encode=n;function o(i,c){return Ot(i,e.codec(),c)}e.decode=o;function s(i,c){return Nt(i,e.codec(),c)}e.stream=s})(Wr||(Wr={}));function Vc(e,t){let r=(n,o)=>n.toString().localeCompare(o.toString());return e.length!==t.length?!1:(t.sort(r),e.sort(r).every((n,o)=>t[o].equals(n)))}var Ut=class e{static createFromProtobuf=t=>{let r=Wr.decode(t),n=Us(wr(r.peerId)),o=(r.addresses??[]).map(i=>Pe(i.multiaddr)),s=r.seq;return new e({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=Kc;static CODEC=Mc;peerId;multiaddrs;seqNumber;domain=e.DOMAIN;codec=e.CODEC;marshaled;constructor(t){let{peerId:r,multiaddrs:n,seqNumber:o}=t;this.peerId=r,this.multiaddrs=n??[],this.seqNumber=o??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=Wr.encode({peerId:this.peerId.toMultihash().bytes,seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(t=>({multiaddr:t.bytes}))})),this.marshaled}equals(t){return!(!(t instanceof e)||!this.peerId.equals(t.peerId)||this.seqNumber!==t.seqNumber||!Vc(this.multiaddrs,t.multiaddrs))}};function qn(e){let t=e.getComponents(),r={},n=0;if(t[n]?.name==="ip6zone"&&(r.zone=`${t[n].value}`,n++),t[n].name==="ip4"||t[n].name==="ip6"||t[n].name==="dns"||t[n].name==="dns4"||t[n].name==="dns6"?(r.type=t[n].name,r.host=t[n].value,n++):t[n].name==="dnsaddr"&&(r.type=t[n].name,r.host=`_dnsaddr.${t[n].value}`,n++),(t[n]?.name==="tcp"||t[n]?.name==="udp")&&(r.protocol=t[n].name==="tcp"?"tcp":"udp",r.port=parseInt(`${t[n].value}`),n++),t[n]?.name==="ipcidr"&&(r.type==="ip4"?r.cidr=parseInt(`${t[n].value}`):r.type==="ip6"&&(r.cidr=`${t[n].value}`),n++),r.type==null||r.host==null)throw new Q(`Multiaddr ${e} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return t[n]?.name==="tls"&&t[n+1]?.name==="sni"&&(r.sni=t[n+1].value,n+=2),r}function Fc(e,t,r){let n=0;for(let o of e)if(!(n<t)){if(n>r)break;if(o!==255)return!1;n++}return!0}function qc(e,t,r,n){let o=0;for(let s of e)if(!(o<r)){if(o>n)break;if(s!==t[o])return!1;o++}return!0}function si(e){switch(e.length){case Le:return e.join(".");case Oe:{let t=[];for(let r=0;r<e.length;r++)r%2===0&&t.push(e[r].toString(16).padStart(2,"0")+e[r+1].toString(16).padStart(2,"0"));return t.join(":")}default:throw new Error("Invalid ip length")}}function Hc(e){let t=0;for(let[r,n]of e.entries()){if(n===255){t+=8;continue}for(;(n&128)!=0;)t++,n=n<<1;if((n&128)!=0)return-1;for(let o=r+1;o<e.length;o++)if(e[o]!=0)return-1;break}return t}function zc(e){let t="0x";for(let r of e)t+=(r>>4).toString(16)+(r&15).toString(16);return t}var Le=4,Oe=16,Vg=parseInt("0xFFFF",16),Sd=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function jr(e,t){t.length===Oe&&e.length===Le&&Fc(t,0,11)&&(t=t.slice(12)),t.length===Le&&e.length===Oe&&qc(e,Sd,0,11)&&(e=e.slice(12));let r=e.length;if(r!=t.length)throw new Error("Failed to mask ip");let n=new Uint8Array(r);for(let o=0;o<r;o++)n[o]=e[o]&t[o];return n}function $c(e,t){if(typeof t=="string"&&(t=nr(t)),t==null)throw new Error("Invalid ip");if(t.length!==e.network.length)return!1;for(let r=0;r<t.length;r++)if((e.network[r]&e.mask[r])!==(t[r]&e.mask[r]))return!1;return!0}function ii(e){let[t,r]=e.split("/");if(!t||!r)throw new Error("Failed to parse given CIDR: "+e);let n=Le,o=On(t);if(o==null&&(n=Oe,o=Rn(t),o==null))throw new Error("Failed to parse given CIDR: "+e);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: "+e);let i=ai(s,8*n);return{network:jr(o,i),mask:i}}function ai(e,t){if(t!==8*Le&&t!==8*Oe)throw new Error("Invalid CIDR mask");if(e<0||e>t)throw new Error("Invalid CIDR mask");let r=t/8,n=new Uint8Array(r);for(let o=0;o<r;o++){if(e>=8){n[o]=255,e-=8;continue}n[o]=255-(255>>e),e=0}return n}var Xr=class{constructor(t,r){if(r==null)({network:this.network,mask:this.mask}=ii(t));else{let n=nr(t);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=nr(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=ai(o,8*n.length);this.network=jr(n,this.mask)}}contains(t){return $c({network:this.network,mask:this.mask},t)}toString(){let t=Hc(this.mask),r=t!==-1?String(t):zc(this.mask);return si(this.network)+"/"+r}};function Yc(e,t){return new Xr(e).contains(t)}function Zc(e){try{let t=qn(e);switch(t.type){case"ip6":return Yc("2000::/3",t.host);default:return!1}}catch{return!1}}var Xc=Su(jc(),1),Bd=["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"],Pd=Bd.map(e=>new Xc.Netmask(e));function pi(e){for(let t of Pd)if(t.contains(e))return!0;return!1}function Ld(e){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(e)}function Od(e){let t=e.split(":");if(t.length<2)return!1;let r=t[t.length-1].padStart(4,"0"),n=t[t.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(r.substring(0,2),16)}.${parseInt(r.substring(2),16)}`;return pi(o)}function Rd(e){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(e)}function Nd(e){let t=e.split(":"),r=t[t.length-1];return pi(r)}function kd(e){return/^::$/.test(e)||/^::1$/.test(e)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(e)||/^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(e)||/^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(e)||/^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(e)||/^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(e)||/^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(e)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(e)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(e)||/^ff([0-9a-fA-F]{2,2}):/i.test(e)}function Qc(e){if(or(e))return pi(e);if(Ld(e))return Od(e);if(Rd(e))return Nd(e);if(Nn(e))return kd(e)}function Jc(e){try{let t=qn(e);switch(t.type){case"ip4":case"ip6":return Qc(t.host)??!1;default:return t.host==="localhost"}}catch{return!1}}function hr(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var mi=class e extends Error{name="TimeoutError";constructor(t,r){super(t,r),Error.captureStackTrace?.(this,e)}},tu=e=>e.reason??new DOMException("This operation was aborted.","AbortError");function yi(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=t,c,a,u=new Promise((l,h)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){h(tu(i));return}if(i&&(a=()=>{h(tu(i))},i.addEventListener("abort",a,{once:!0})),e.then(l,h),r===Number.POSITIVE_INFINITY)return;let p=new mi;c=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(d){h(d)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?l():o instanceof Error?h(o):(p.message=o??`Promise timed out after ${r} milliseconds`,h(p))},r)}).finally(()=>{u.clear(),a&&i&&i.removeEventListener("abort",a)});return u.clear=()=>{s.clearTimeout.call(void 0,c),c=void 0},u}var Ud=e=>{let t=e.addEventListener||e.on||e.addListener,r=e.removeEventListener||e.off||e.removeListener;if(!t||!r)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(e),removeListener:r.bind(e)}};function Kd(e,t,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 c=[t].flat(),a=[],{addListener:f,removeListener:u}=Ud(e),l=async(...p)=>{let d=r.multiArgs?p:p[0];if(r.filter)try{if(!await r.filter(d))return}catch(E){n(),i(E);return}a.push(d),r.count===a.length&&(n(),s(a))},h=(...p)=>{n(),i(r.rejectionMultiArgs?p:p[0])};n=()=>{for(let p of c)u(p,l);for(let p of r.rejectionEvents)c.includes(p)||u(p,h)};for(let p of c)f(p,l);for(let p of r.rejectionEvents)c.includes(p)||f(p,h);r.signal&&r.signal.addEventListener("abort",()=>{h(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(a)});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 eu(e,t,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Kd(e,t,r),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function ru(e,t){let r,n=function(){let o=function(){r=void 0,e()};clearTimeout(r),r=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var Ne=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Md(e){return e.reason}async function bi(e,t,r){if(t==null)return e;let n=r?.translateError??Md;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let o;try{return await Promise.race([e,new Promise((s,i)=>{o=()=>{i(n(t))},t.addEventListener("abort",o)})])}finally{o!=null&&t.removeEventListener("abort",o)}}var Fd=4194304,zn=class extends Error{static name="UnwrappedError";name="UnwrappedError"},xi=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},wi=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Ei=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function qd(e){return typeof e?.closeRead=="function"}function Hd(e){return typeof e?.close=="function"}function gi(e){return qd(e)?e.remoteWriteStatus!=="writable"&&e.readBufferLength===0:Hd(e)?e.status!=="open":!1}function zd(e){return e?.addEventListener!=null&&e?.removeEventListener!=null&&e?.send!=null&&e?.push!=null&&e?.log!=null}function $d(e,t){let r=t?.maxBufferSize??Fd,n=new it,o,s=!1;if(!zd(e))throw new Q("Argument should be a Stream or a Multiaddr");let i=u=>{if(n.append(u.data),n.byteLength>r){let l=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${l} > ${r}`))}o?.resolve()};e.addEventListener("message",i);let c=u=>{u.error!=null?o?.reject(u.error):o?.resolve()};e.addEventListener("close",c);let a=()=>{o?.resolve()};e.addEventListener("remoteCloseWrite",a);let f={readBuffer:n,async read(u){if(s===!0)throw new zn("Stream was unwrapped");if(gi(e)){if(n.byteLength===0&&u?.bytes==null)return null;if(u?.bytes!=null&&n.byteLength<u.bytes)throw e.log.error("closed after reading %d/%d bytes",n.byteLength,u.bytes),new Ne(`Unexpected EOF - stream closed after reading ${n.byteLength}/${u.bytes} bytes`)}let l=u?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=l){o.resolve();break}if(await bi(o.promise,u?.signal),gi(e)){if(n.byteLength===0&&u?.bytes==null)return null;break}o=Promise.withResolvers()}let h=u?.bytes??n.byteLength;if(n.byteLength<h){if(gi(e))throw e.log.error("closed while reading %d/%d bytes",n.byteLength,h),new Ne(`Unexpected EOF - stream closed while reading ${n.byteLength}/${h} bytes`);return f.read(u)}let p=n.sublist(0,h);return n.consume(h),p},async write(u,l){if(s===!0)throw new zn("Stream was unwrapped");e.send(u)||await eu(e,"drain",{signal:l?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,e.removeEventListener("message",i),e.removeEventListener("close",c),e.removeEventListener("remoteCloseWrite",a),n.byteLength>0&&(e.log("stream unwrapped with %d unread bytes",n.byteLength),e.push(n))),e}};return f}function Yd(e,t={}){let r=$d(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=At(t.maxDataLength));let n=t?.lengthDecoder??Nr,o=t?.lengthEncoder??Xe;return{async read(i){let c=-1,a=new it;for(;;){let u=await r.read({...i,bytes:1});if(u==null)break;a.append(u);try{c=n(a)}catch(l){if(l instanceof RangeError)continue;throw l}if(c<0)throw new xi("Invalid message length");if(t?.maxLengthLength!=null&&a.byteLength>t.maxLengthLength)throw new Ei(`Message length length too long - ${a.byteLength} > ${t.maxLengthLength}`);if(c>-1)break}if(t?.maxDataLength!=null&&c>t.maxDataLength)throw new wi(`Message length too long - ${c} > ${t.maxDataLength}`);let f=await r.read({...i,bytes:c});if(f==null)throw e.log.error("tried to read %d bytes but the stream closed",c),new Ne(`Unexpected EOF - tried to read ${c} bytes but the stream closed`);if(f.byteLength!==c)throw e.log.error("read %d/%d bytes before the stream closed",f.byteLength,c),new Ne(`Unexpected EOF - read ${f.byteLength}/${c} bytes before the stream closed`);return f},async write(i,c){await r.write(new it(o(i.byteLength),i),c)},async writeV(i,c){let a=new it(...i.flatMap(f=>[o(f.byteLength),f]));await r.write(a,c)},unwrap(){return r.unwrap()}}}function pr(e,t){let r=Yd(e,t),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(c=>s.encode(c)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}function Zd(e){return e[Symbol.asyncIterator]!=null}function Gd(e){if(Zd(e))return(async()=>{for await(let t of e);})();for(let t of e);}var nu=Gd;var $n=globalThis.CustomEvent??Event;async function*vi(e,t={}){let r=t.concurrency??1/0;r<1&&(r=1/0);let n=t.ordered??!1,o=new EventTarget,s=[],i=hr(),c=hr(),a=!1,f,u=!1;o.addEventListener("task-complete",()=>{c.resolve()}),Promise.resolve().then(async()=>{try{for await(let d of e){if(s.length===r&&(i=hr(),await i.promise),u)break;let E={done:!1};s.push(E),d().then(S=>{E.done=!0,E.ok=!0,E.value=S,o.dispatchEvent(new $n("task-complete"))},S=>{E.done=!0,E.err=S,o.dispatchEvent(new $n("task-complete"))})}a=!0,o.dispatchEvent(new $n("task-complete"))}catch(d){f=d,o.dispatchEvent(new $n("task-complete"))}});function l(){return n?s[0]?.done:!!s.find(d=>d.done)}function*h(){for(;s.length>0&&s[0].done;){let d=s[0];if(s.shift(),d.ok)yield d.value;else throw u=!0,i.resolve(),d.err;i.resolve()}}function*p(){for(;l();)for(let d=0;d<s.length;d++)if(s[d].done){let E=s[d];if(s.splice(d,1),d--,E.ok)yield E.value;else throw u=!0,i.resolve(),E.err;i.resolve()}}for(;;){if(l()||(c=hr(),await c.promise),f!=null||(n?yield*h():yield*p(),f!=null))throw f;if(a&&s.length===0)break}}var ou="0.1.0";var su="id/push",iu="1.0.0",au="1.0.0";var be;(function(e){let t;e.codec=()=>(t==null&&(t=kt((s,i,c={})=>{if(c.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 a of s.listenAddrs)i.uint32(18),i.bytes(a);if(s.observedAddr!=null&&(i.uint32(34),i.bytes(s.observedAddr)),s.protocols!=null&&s.protocols.length>0)for(let a of s.protocols)i.uint32(26),i.string(a);s.signedPeerRecord!=null&&(i.uint32(66),i.bytes(s.signedPeerRecord)),c.lengthDelimited!==!1&&i.ldelim()},(s,i,c={})=>{let a={listenAddrs:[],protocols:[]},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 5:{a.protocolVersion=s.string();break}case 6:{a.agentVersion=s.string();break}case 1:{a.publicKey=s.bytes();break}case 2:{if(c.limits?.listenAddrs!=null&&a.listenAddrs.length===c.limits.listenAddrs)throw new Ht('Decode error - repeated field "listenAddrs" had too many elements');a.listenAddrs.push(s.bytes());break}case 4:{a.observedAddr=s.bytes();break}case 3:{if(c.limits?.protocols!=null&&a.protocols.length===c.limits.protocols)throw new Ht('Decode error - repeated field "protocols" had too many elements');a.protocols.push(s.string());break}case 8:{a.signedPeerRecord=s.bytes();break}default:{s.skipType(u&7);break}}}return a},function*(s,i,c,a={}){let f={listenAddrs:0,protocols:0},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let l=s.uint32();switch(l>>>3){case 5:{yield{field:`${c}.protocolVersion`,value:s.string()};break}case 6:{yield{field:`${c}.agentVersion`,value:s.string()};break}case 1:{yield{field:`${c}.publicKey`,value:s.bytes()};break}case 2:{if(a.limits?.listenAddrs!=null&&f.listenAddrs===a.limits.listenAddrs)throw new Ht('Streaming decode error - repeated field "listenAddrs" had too many elements');yield{field:`${c}.listenAddrs[]`,index:f.listenAddrs,value:s.bytes()},f.listenAddrs++;break}case 4:{yield{field:`${c}.observedAddr`,value:s.bytes()};break}case 3:{if(a.limits?.protocols!=null&&f.protocols===a.limits.protocols)throw new Ht('Streaming decode error - repeated field "protocols" had too many elements');yield{field:`${c}.protocols[]`,index:f.protocols,value:s.string()},f.protocols++;break}case 8:{yield{field:`${c}.signedPeerRecord`,value:s.bytes()};break}default:{s.skipType(l&7);break}}}})),t);function r(s){return Rt(s,e.codec())}e.encode=r;function n(s,i){return Ot(s,e.codec(),i)}e.decode=n;function o(s,i){return Nt(s,e.codec(),i)}e.stream=o})(be||(be={}));var _t={protocolPrefix:"ipfs",timeout:5e3,maxInboundStreams:1,maxOutboundStreams:1,maxObservedAddresses:10,maxMessageSize:8192,runOnConnectionOpen:!0,runOnSelfUpdate:!0,runOnLimitedConnection:!0,concurrency:32};function cu(e){if(e!=null&&e.length>0)try{return Pe(e)}catch{}}async function Yn(e,t,r,n,o){if(r("received identify from %p",n.remotePeer),o==null)throw new Tt("message was null or undefined");let s={};if(o.listenAddrs.length>0&&(s.addresses=o.listenAddrs.map(a=>({isCertified:!1,multiaddr:Pe(a)}))),o.protocols.length>0&&(s.protocols=o.protocols),o.publicKey!=null){let a=er(o.publicKey);if(!Sc(a).equals(n.remotePeer))throw new Tt("public key did not match remote PeerId");s.publicKey=a}let i;if(o.signedPeerRecord!=null){r.trace("received signedPeerRecord from %p",n.remotePeer);let a=o.signedPeerRecord,f=await $t.openAndCertify(a,Ut.DOMAIN),u=Ut.createFromProtobuf(f.payload),l=Tn(f.publicKey.toCID());if(!u.peerId.equals(l))throw new Tt("signing key does not match PeerId in the PeerRecord");if(!n.remotePeer.equals(u.peerId))throw new Tt("signing key does not match remote PeerId");let h;try{h=await e.get(u.peerId)}catch(p){if(p.name!=="NotFoundError")throw p}if(h!=null&&(s.metadata=h.metadata,h.peerRecordEnvelope!=null)){let p=$t.createFromProtobuf(h.peerRecordEnvelope),d=Ut.createFromProtobuf(p.payload);d.seqNumber>=u.seqNumber&&(r("sequence number was lower or equal to existing sequence number - stored: %d received: %d",d.seqNumber,u.seqNumber),u=d,a=h.peerRecordEnvelope)}s.peerRecordEnvelope=a,s.addresses=u.multiaddrs.map(p=>({isCertified:!0,multiaddr:p})),i={seq:u.seqNumber,addresses:u.multiaddrs}}else r("%p did not send a signed peer record",n.remotePeer);if(r.trace("patching %p with",n.remotePeer,s),await e.patch(n.remotePeer,s),o.agentVersion!=null||o.protocolVersion!=null){let a={};o.agentVersion!=null&&(a.AgentVersion=F(o.agentVersion)),o.protocolVersion!=null&&(a.ProtocolVersion=F(o.protocolVersion)),r.trace("merging %p metadata",n.remotePeer,a),await e.merge(n.remotePeer,{metadata:a})}let c={peerId:n.remotePeer,protocolVersion:o.protocolVersion,agentVersion:o.agentVersion,publicKey:o.publicKey,listenAddrs:o.listenAddrs.map(a=>Pe(a)),observedAddr:o.observedAddr==null?void 0:Pe(o.observedAddr),protocols:o.protocols,signedPeerRecord:i,connection:n};return t.safeDispatchEvent("peer:identify",{detail:c}),c}var mr=class{host;components;protocol;started;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxObservedAddresses;runOnLimitedConnection;log;constructor(t,r){this.protocol=r.protocol,this.started=!1,this.components=t,this.log=r.log,this.timeout=r.timeout??_t.timeout,this.maxInboundStreams=r.maxInboundStreams??_t.maxInboundStreams,this.maxOutboundStreams=r.maxOutboundStreams??_t.maxOutboundStreams,this.maxMessageSize=r.maxMessageSize??_t.maxMessageSize,this.maxObservedAddresses=r.maxObservedAddresses??_t.maxObservedAddresses,this.runOnLimitedConnection=r.runOnLimitedConnection??_t.runOnLimitedConnection,this.host={protocolVersion:`${r.protocolPrefix??_t.protocolPrefix}/${ou}`,agentVersion:t.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:F(this.host.agentVersion),ProtocolVersion:F(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 Zn=class extends mr{connectionManager;concurrency;_push;constructor(t,r={}){super(t,{...r,protocol:`/${r.protocolPrefix??_t.protocolPrefix}/${su}/${au}`,log:t.logger.forComponent("libp2p:identify-push")}),this.connectionManager=t.connectionManager,this.concurrency=r.concurrency??_t.concurrency,this._push=ru(this.sendPushMessage.bind(this),r.debounce??1e3),(r.runOnSelfUpdate??_t.runOnSelfUpdate)&&t.events.addEventListener("self:peer:update",n=>{this.push().catch(o=>{this.log.error("error pushing updates to peers - %e",o)})})}[nn]=["@libp2p/identify-push"];async push(){this._push()}async sendPushMessage(){if(this.isStarted())try{let t=this.components.addressManager.getAddresses().map(u=>u.decapsulateCode(421)),r=new Ut({peerId:this.components.peerId,multiaddrs:t}),n=await $t.seal(r,this.components.privateKey),o=this.components.registrar.getProtocols(),s=await this.components.peerStore.get(this.components.peerId),i=H(s.metadata.get("AgentVersion")??F(this.host.agentVersion)),c=H(s.metadata.get("ProtocolVersion")??F(this.host.protocolVersion)),a=this;async function*f(){for(let u of a.connectionManager.getConnections())(await a.components.peerStore.get(u.remotePeer)).protocols.includes(a.protocol)&&(yield async()=>{let h,p=AbortSignal.timeout(a.timeout);try{h=await u.newStream(a.protocol,{signal:p,runOnLimitedConnection:a.runOnLimitedConnection}),await pr(h,{maxDataLength:a.maxMessageSize}).pb(be).write({listenAddrs:t.map(E=>E.bytes),signedPeerRecord:n.marshal(),protocols:o,agentVersion:i,protocolVersion:c},{signal:p}),await h.close({signal:p})}catch(d){h?.log.newScope("identify-push")?.error("could not push identify update to peer",d),h?.abort(d)}})}await nu(vi(f(),{concurrency:this.concurrency}))}catch(t){this.log.error("error pushing updates to peers - %e",t)}}async handleProtocol(t,r){let n=t.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)},i=await pr(t,{maxDataLength:this.maxMessageSize}).pb(be).read(o);await t.close(o),await Yn(this.components.peerStore,this.components.events,n,r,i),n.trace("handled push from %p",r.remotePeer)}};var G=e=>({match:t=>{let r=t[0];return r==null||r.code!==e||r.value!=null?!1:t.slice(1)}}),L=(e,t)=>({match:r=>{let n=r[0];return n?.code!==e||n.value==null||t!=null&&n.value!==t?!1:r.slice(1)}}),uu=e=>({match:t=>e.match(t)===!1?t:!1}),q=e=>({match:t=>{let r=e.match(t);return r===!1?t:r}}),xt=(...e)=>({match:t=>{let r;for(let n of e){let o=n.match(t);o!==!1&&(r==null||o.length<r.length)&&(r=o)}return r??!1}}),Y=(...e)=>({match:t=>{for(let r of e){let n=r.match(t);if(n===!1)return!1;t=n}return t}});function W(...e){function t(o){if(o==null)return!1;let s=o.getComponents();for(let i of e){let c=i.match(s);if(c===!1)return!1;s=c}return s}function r(o){return t(o)!==!1}function n(o){let s=t(o);return s===!1?!1:s.length===0}return{matchers:e,matches:r,exactMatch:n}}var Qd=L(421),Ew=W(Qd),Wn=L(54),jn=L(55),Xn=L(56),Ii=L(53),vw=W(Wn,q(L(421))),Sw=W(jn,q(L(421))),Iw=W(Xn,q(L(421))),Aw=W(xt(Ii,Xn,Wn,jn),q(L(421))),fu=Y(L(4),q(L(43))),lu=Y(q(L(42)),L(41),q(L(43))),Ai=xt(fu,lu),yr=xt(Ai,Ii,Wn,jn,Xn),du=W(xt(Ai,Y(xt(Ii,Xn,Wn,jn),q(L(421))))),_w=W(fu),Cw=W(lu),Dw=W(Ai),_i=Y(yr,L(6)),Qr=Y(yr,L(273)),hu=W(Y(_i,q(L(421)))),Tw=W(Qr),Ci=Y(Qr,G(460),q(L(421))),Qn=Y(Qr,G(461),q(L(421))),Jd=xt(Ci,Qn),Bw=W(Ci),Pw=W(Qn),Si=xt(yr,_i,Qr,Ci,Qn),pu=xt(Y(Si,G(477),q(L(421)))),Lw=W(pu),mu=xt(Y(Si,G(478),q(L(421))),Y(Si,G(448),q(L(449)),G(477),q(L(421)))),Ow=W(mu),yu=Y(Qr,G(280),q(L(466)),q(L(466)),q(L(421))),Rw=W(yu),bu=Y(Qn,G(465),q(L(466)),q(L(466)),q(L(421))),Nw=W(bu),Gn=xt(pu,mu,Y(_i,q(L(421))),Y(Jd,q(L(421))),Y(yr,q(L(421))),yu,bu,L(421)),kw=W(Gn),th=Y(q(Gn),G(290),uu(G(281)),q(L(421))),Uw=W(th),eh=xt(Y(Gn,G(290),G(281),q(L(421))),Y(Gn,G(281),q(L(421))),Y(G(281),q(L(421)))),Kw=W(eh),rh=Y(yr,xt(Y(L(6,"80")),Y(L(6),G(480)),G(480)),q(L(481)),q(L(421))),Mw=W(rh),nh=Y(yr,xt(Y(L(6,"443")),Y(L(6,"443"),G(480)),Y(L(6),G(443)),Y(L(6),G(448),G(480)),Y(G(448),G(480)),G(448),G(443)),q(L(481)),q(L(421))),Vw=W(nh),oh=xt(Y(L(777),q(L(421)))),Fw=W(oh),sh=xt(Y(L(400),q(L(421)))),qw=W(sh);var Jn=class extends mr{constructor(t,r={}){super(t,{...r,protocol:`/${r.protocolPrefix??_t.protocolPrefix}/${"id"}/${iu}`,log:t.logger.forComponent("libp2p:identify")}),(r.runOnConnectionOpen??_t.runOnConnectionOpen)&&t.events.addEventListener("connection:open",n=>{let o=n.detail;this.identify(o).catch(()=>{})})}[nn]=["@libp2p/identify"];async _identify(t,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",t.remoteAddr);try{n=await t.newStream(this.protocol,{...r,runOnLimitedConnection:this.runOnLimitedConnection}),o=n.log.newScope("identify");let s=pr(n,{maxDataLength:this.maxMessageSize}).pb(be),i=await s.read(r);return await s.unwrap().unwrap().close(r),i}catch(s){throw o?.error("identify failed - %e",s),n?.abort(s),s}}async identify(t,r={}){let n=await this._identify(t,r),{publicKey:o,protocols:s,observedAddr:i}=n;if(o==null)throw new Tt("Public key was missing from identify message");let c=er(o),a=Tn(c.toCID());if(!t.remotePeer.equals(a))throw new Tt("Identified peer does not match the expected peer");if(this.components.peerId.equals(a))throw new Tt("Identified peer is our own peer id?");return this.maybeAddObservedAddress(i),this.log("completed for peer %p and protocols %o",a,s),Yn(this.components.peerStore,this.components.events,this.log,t,n)}maybeAddObservedAddress(t){let r=cu(t);if(r==null||(this.log.trace("our observed address was %a",r),Jc(r)))return;let n=r.getComponents();if((n[0].code===41||n[0].code===42&&n[1].code===41)&&!Zc(r)){this.log.trace("our observed address was IPv6 but not a global unicast address");return}hu.exactMatch(r)||(this.log.trace("storing the observed address"),this.components.addressManager.addObservedAddr(r))}async handleProtocol(t,r){let n=t.log.newScope("identify");n("responding to identify");let o=AbortSignal.timeout(this.timeout);let s=await this.components.peerStore.get(this.components.peerId,{signal:o}),i=this.components.addressManager.getAddresses().map(u=>u.decapsulateCode(421)),c=s.peerRecordEnvelope;if(i.length>0&&c==null){let u=new Ut({peerId:this.components.peerId,multiaddrs:i});c=(await $t.seal(u,this.components.privateKey,{signal:o})).marshal().subarray()}let a=r.remoteAddr.bytes;du.matches(r.remoteAddr)||(a=void 0);let f=pr(t).pb(be);n("send response"),await f.write({protocolVersion:this.host.protocolVersion,agentVersion:this.host.agentVersion,publicKey:Vt(this.components.privateKey.publicKey),listenAddrs:i.map(u=>u.bytes),signedPeerRecord:c,observedAddr:a,protocols:s.protocols},{signal:o}),n("close write"),await f.unwrap().unwrap().close({signal:o})}};function ah(e={}){return t=>new Jn(t,e)}function ch(e={}){return t=>new Zn(t,e)}return Iu(uh);})();
|
|
2
|
+
"use strict";var Libp2PIdentify=(()=>{var gu=Object.create;var tn=Object.defineProperty;var xu=Object.getOwnPropertyDescriptor;var wu=Object.getOwnPropertyNames;var Eu=Object.getPrototypeOf,vu=Object.prototype.hasOwnProperty;var to=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Et=(e,t)=>{for(var r in t)tn(e,r,{get:t[r],enumerable:!0})},Bi=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of wu(t))!vu.call(e,o)&&o!==r&&tn(e,o,{get:()=>t[o],enumerable:!(n=xu(t,o))||n.enumerable});return e};var Su=(e,t,r)=>(r=e!=null?gu(Eu(e)):{},Bi(t||!e||!e.__esModule?tn(r,"default",{value:e,enumerable:!0}):r,e)),Iu=e=>Bi(tn({},"__esModule",{value:!0}),e);var ui=to(lr=>{"use strict";Object.defineProperty(lr,"__esModule",{value:!0});lr.Netmask4Impl=void 0;lr.ip2long=fr;lr.long2ip=Yt;function Yt(e){let t=(e&-16777216)>>>24,r=(e&255<<16)>>>16,n=(e&65280)>>>8,o=e&255;return[t,r,n,o].join(".")}var Id=48,Ad=97,_d=65;function Cd(e){let t=0,r=10,n="9",o=0;e.length>1&&e[o]==="0"&&(e[o+1]==="x"||e[o+1]==="X"?(o+=2,r=16):"0"<=e[o+1]&&e[o+1]<="9"&&(o++,r=8,n="7"));let s=o;for(;o<e.length;){if("0"<=e[o]&&e[o]<=n)t=t*r+(e.charCodeAt(o)-Id)>>>0;else if(r===16)if("a"<=e[o]&&e[o]<="f")t=t*r+(10+e.charCodeAt(o)-Ad)>>>0;else if("A"<=e[o]&&e[o]<="F")t=t*r+(10+e.charCodeAt(o)-_d)>>>0;else break;else break;if(t>4294967295)throw new Error("too large");o++}if(o===s)throw new Error("empty octet");return[t,o]}function fr(e){let t=[];for(let r=0;r<=3&&e.length!==0;r++){if(r>0){if(e[0]!==".")throw new Error("Invalid IP");e=e.substring(1)}let[n,o]=Cd(e);e=e.substring(o),t.push(n)}if(e.length!==0)throw new Error("Invalid IP");switch(t.length){case 1:if(t[0]>4294967295)throw new Error("Invalid IP");return t[0]>>>0;case 2:if(t[0]>255||t[1]>16777215)throw new Error("Invalid IP");return(t[0]<<24|t[1])>>>0;case 3:if(t[0]>255||t[1]>255||t[2]>65535)throw new Error("Invalid IP");return(t[0]<<24|t[1]<<16|t[2])>>>0;case 4:if(t[0]>255||t[1]>255||t[2]>255||t[3]>255)throw new Error("Invalid IP");return(t[0]<<24|t[1]<<16|t[2]<<8|t[3])>>>0;default:throw new Error("Invalid IP")}}var ci=class e{constructor(t,r){if(typeof t!="string")throw new Error("Missing `net' parameter");let n=r;if(!n){let o=t.split("/",2);t=o[0],n=o[1]}if(n||(n=32),typeof n=="string"&&n.indexOf(".")>-1){try{this.maskLong=fr(n)}catch{throw new Error("Invalid mask: "+n)}this.bitmask=NaN;for(let o=32;o>=0;o--)if(this.maskLong===4294967295<<32-o>>>0){this.bitmask=o;break}}else if(n||n===0)this.bitmask=parseInt(n,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(fr(t)&this.maskLong)>>>0}catch{throw new Error("Invalid net address: "+t)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+n);this.size=Math.pow(2,32-this.bitmask),this.base=Yt(this.netLong),this.mask=Yt(this.maskLong),this.hostmask=Yt(~this.maskLong),this.first=this.bitmask<=30?Yt(this.netLong+1):this.base,this.last=this.bitmask<=30?Yt(this.netLong+this.size-2):Yt(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?Yt(this.netLong+this.size-1):void 0}contains(t){return typeof t=="string"&&(t.indexOf("/")>0||t.split(".").length!==4)&&(t=new e(t)),t instanceof e?this.contains(t.base)&&this.contains(t.broadcast||t.last):(fr(t)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(t=1){return new e(Yt(this.netLong+this.size*t),this.mask)}forEach(t){let r=fr(this.first),n=fr(this.last),o=0;for(;r<=n;)t(Yt(r),r,o),o++,r++}toString(){return this.base+"/"+this.bitmask}};lr.Netmask4Impl=ci});var Wc=to(dr=>{"use strict";Object.defineProperty(dr,"__esModule",{value:!0});dr.Netmask6Impl=void 0;dr.ip6bigint=li;dr.bigint2ip6=Re;var Dd=ui(),fi=(1n<<128n)-1n;function li(e){let t=e.indexOf("%");t!==-1&&(e=e.substring(0,t));let r=e.lastIndexOf(":");if(r!==-1&&e.indexOf(".",r)!==-1){let n=e.substring(r+1),o=(0,Dd.ip2long)(n),s=e.substring(0,r+1)+"0:0";return Gc(s)&~0xffffffffn|BigInt(o)}return Gc(e)}function Gc(e){let t=e.indexOf("::"),r;if(t!==-1){let o=e.substring(0,t),s=e.substring(t+2),i=o===""?[]:o.split(":"),c=s===""?[]:s.split(":"),a=8-i.length-c.length;if(a<0)throw new Error("Invalid IPv6: too many groups");r=[...i,...Array(a).fill("0"),...c]}else r=e.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 Re(e){if(e<0n||e>fi)throw new Error("Invalid IPv6 address value");let t=[];for(let i=0;i<8;i++)t.unshift(Number(e&0xffffn)),e>>=16n;let r=-1,n=0,o=-1,s=0;for(let i=0;i<8;i++)t[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 t.slice(0,r).map(c=>c.toString(16)).join(":")+"::";if(r===0)return"::"+t.slice(n).map(c=>c.toString(16)).join(":");if(r>0){let i=t.slice(0,r).map(a=>a.toString(16)),c=t.slice(r+n).map(a=>a.toString(16));return i.join(":")+"::"+c.join(":")}else return t.map(i=>i.toString(16)).join(":")}var di=class e{constructor(t,r){if(typeof t!="string")throw new Error("Missing `net' parameter");let n=r;if(n==null){let o=t.indexOf("/");o!==-1?(n=parseInt(t.substring(o+1),10),t=t.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=fi>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=li(t)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+t)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=Re(this.netBigint),this.mask=Re(this.maskBigint),this.hostmask=Re(~this.maskBigint&fi),this.first=this.base,this.last=Re(this.netBigint+(1n<<BigInt(128-this.bitmask))-1n),this.broadcast=void 0}contains(t){return typeof t=="string"&&t.indexOf("/")>0&&(t=new e(t)),t instanceof e?this.contains(t.base)&&this.contains(t.last):(li(t)&this.maskBigint)===this.netBigint}next(t=1){let r=1n<<BigInt(128-this.bitmask);return new e(Re(this.netBigint+r*BigInt(t)),this.bitmask)}forEach(t){let r=this.netBigint,n=1n<<BigInt(128-this.bitmask),o=this.netBigint+n-1n,s=0;for(;r<=o;)t(Re(r),Number(r),s),s++,r++}toString(){return this.base+"/"+this.bitmask}};dr.Netmask6Impl=di});var jc=to(ye=>{"use strict";Object.defineProperty(ye,"__esModule",{value:!0});ye.long2ip=ye.ip2long=ye.Netmask=void 0;var Hn=ui();Object.defineProperty(ye,"ip2long",{enumerable:!0,get:function(){return Hn.ip2long}});Object.defineProperty(ye,"long2ip",{enumerable:!0,get:function(){return Hn.long2ip}});var Td=Wc(),hi=class e{constructor(t,r){if(typeof t!="string")throw new Error("Missing `net' parameter");(t.indexOf("/")!==-1?t.substring(0,t.indexOf("/")):t).indexOf(":")!==-1?this._impl=new Td.Netmask6Impl(t,r):this._impl=new Hn.Netmask4Impl(t,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 Hn.Netmask4Impl?(this.maskLong=this._impl.maskLong,this.netLong=this._impl.netLong):(this.maskLong=0,this.netLong=0)}contains(t){return typeof t=="string"&&(t.indexOf("/")>0?t=new e(t):t.indexOf(":")===-1&&t.split(".").length!==4&&(t=new e(t))),t instanceof e?this.contains(t.base)&&this.contains(t.broadcast||t.last):this._impl.contains(t)}next(t=1){let r=this._impl.next(t);return new e(r.base,r.bitmask)}forEach(t){this._impl.forEach(t)}toString(){return this._impl.toString()}};ye.Netmask=hi});var uh={};Et(uh,{identify:()=>ah,identifyPush:()=>ch});var Q=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},ke=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var en=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},rn=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Tt=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var ge=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var eo=Symbol.for("@libp2p/peer-id");var nn=Symbol.for("@libp2p/service-capabilities");var io={};Et(io,{base58btc:()=>ot,base58flickr:()=>Pu});var Kh=new Uint8Array(0);function Pi(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Zt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function Li(e){return new TextEncoder().encode(e)}function Oi(e){return new TextDecoder().decode(e)}function Au(e,t){if(e.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<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var c=e.length,a=e.charAt(0),f=Math.log(c)/Math.log(256),u=Math.log(256)/Math.log(c);function l(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var E=0,S=0,g=0,A=d.length;g!==A&&d[g]===0;)g++,E++;for(var x=(A-g)*u+1>>>0,_=new Uint8Array(x);g!==A;){for(var R=d[g],K=0,M=x-1;(R!==0||K<S)&&M!==-1;M--,K++)R+=256*_[M]>>>0,_[M]=R%c>>>0,R=R/c>>>0;if(R!==0)throw new Error("Non-zero carry");S=K,g++}for(var v=x-S;v!==x&&_[v]===0;)v++;for(var w=a.repeat(E);v<x;++v)w+=e.charAt(_[v]);return w}function h(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var E=0;if(d[E]!==" "){for(var S=0,g=0;d[E]===a;)S++,E++;for(var A=(d.length-E)*f+1>>>0,x=new Uint8Array(A);d[E];){var _=r[d.charCodeAt(E)];if(_===255)return;for(var R=0,K=A-1;(_!==0||R<g)&&K!==-1;K--,R++)_+=c*x[K]>>>0,x[K]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");g=R,E++}if(d[E]!==" "){for(var M=A-g;M!==A&&x[M]===0;)M++;for(var v=new Uint8Array(S+(A-M)),w=S;M!==A;)v[w++]=x[M++];return v}}}function p(d){var E=h(d);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:h,decode:p}}var _u=Au,Cu=_u,Ni=Cu;var ro=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},no=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,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(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return ki(this,t)}},oo=class{decoders;constructor(t){this.decoders=t}or(t){return ki(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function ki(e,t){return new oo({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var so=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new ro(t,r,n),this.decoder=new no(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ue({name:e,prefix:t,encode:r,decode:n}){return new so(e,t,r,n)}function ie({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Ni(r,e);return Ue({prefix:t,name:e,encode:n,decode:s=>Zt(o(s))})}function Du(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,c=0,a=0;for(let f=0;f<o;++f){let u=t[e[f]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|u,i+=r,i>=8&&(i-=8,s[a++]=255&c>>i)}if(i>=r||(255&c<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Tu(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,c=0;for(let a=0;a<e.length;++a)for(c=c<<8|e[a],i+=8;i>r;)i-=r,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Bu(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function nt({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Bu(n);return Ue({prefix:t,name:e,encode(s){return Tu(s,n,r)},decode(s){return Du(s,o,r,e)}})}var ot=ie({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Pu=ie({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ao={};Et(ao,{base32:()=>ae,base32hex:()=>Nu,base32hexpad:()=>Uu,base32hexpadupper:()=>Ku,base32hexupper:()=>ku,base32pad:()=>Ou,base32padupper:()=>Ru,base32upper:()=>Lu,base32z:()=>Mu});var ae=nt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Lu=nt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ou=nt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ru=nt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Nu=nt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ku=nt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Uu=nt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ku=nt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Mu=nt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var co={};Et(co,{base36:()=>br,base36upper:()=>Vu});var br=ie({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Vu=ie({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Fu=Mi,Ui=128,qu=127,Hu=~qu,zu=Math.pow(2,31);function Mi(e,t,r){t=t||[],r=r||0;for(var n=r;e>=zu;)t[r++]=e&255|Ui,e/=128;for(;e&Hu;)t[r++]=e&255|Ui,e>>>=7;return t[r]=e|0,Mi.bytes=r-n+1,t}var $u=uo,Yu=128,Ki=127;function uo(e,n){var r=0,n=n||0,o=0,s=n,i,c=e.length;do{if(s>=c)throw uo.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Ki)<<o:(i&Ki)*Math.pow(2,o),o+=7}while(i>=Yu);return uo.bytes=s-n,r}var Zu=Math.pow(2,7),Gu=Math.pow(2,14),Wu=Math.pow(2,21),ju=Math.pow(2,28),Xu=Math.pow(2,35),Qu=Math.pow(2,42),Ju=Math.pow(2,49),tf=Math.pow(2,56),ef=Math.pow(2,63),rf=function(e){return e<Zu?1:e<Gu?2:e<Wu?3:e<ju?4:e<Xu?5:e<Qu?6:e<Ju?7:e<tf?8:e<ef?9:10},nf={encode:Fu,decode:$u,encodingLength:rf},of=nf,gr=of;function xr(e,t=0){return[gr.decode(e,t),gr.decode.bytes]}function Ke(e,t,r=0){return gr.encode(e,t,r),t}function Me(e){return gr.encodingLength(e)}function Mt(e,t){let r=t.byteLength,n=Me(e),o=n+Me(r),s=new Uint8Array(o+r);return Ke(e,s,0),Ke(r,s,n),s.set(t,o),new Ve(e,r,t,s)}function wr(e){let t=Zt(e),[r,n]=xr(t),[o,s]=xr(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Ve(r,o,i,t)}function Vi(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Pi(e.bytes,r.bytes)}}var Ve=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function Fi(e,t){let{bytes:r,version:n}=e;return n===0?af(r,fo(e),t??ot.encoder):cf(r,fo(e),t??ae.encoder)}var qi=new WeakMap;function fo(e){let t=qi.get(e);if(t==null){let r=new Map;return qi.set(e,r),r}return t}var at=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==Er)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==uf)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.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:t,digest:r}=this.multihash,n=Mt(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&Vi(t.multihash,n.multihash)}toString(t){return Fi(this,t)}toJSON(){return{"/":Fi(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new e(n,o,s,i??Hi(n,o,s.bytes))}else if(r[ff]===!0){let{version:n,multihash:o,code:s}=r,i=wr(o);return e.create(n,s,i)}else return null}static create(t,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(t){case 0:{if(r!==Er)throw new Error(`Version 0 CID must use dag-pb (code: ${Er}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Hi(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Er,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Zt(t.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 Ve(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,h]=xr(t.subarray(r));return r+=h,l},o=n(),s=Er;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,c=n(),a=n(),f=r+a,u=f-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:u,size:f}}static parse(t,r){let[n,o]=sf(t,r),s=e.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return fo(s).set(n,t),s}};function sf(e,t){switch(e[0]){case"Q":{let r=t??ot;return[ot.prefix,r.decode(`${ot.prefix}${e}`)]}case ot.prefix:{let r=t??ot;return[ot.prefix,r.decode(e)]}case ae.prefix:{let r=t??ae;return[ae.prefix,r.decode(e)]}case br.prefix:{let r=t??br;return[br.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function af(e,t,r){let{prefix:n}=r;if(n!==ot.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function cf(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var Er=112,uf=18;function Hi(e,t,r){let n=Me(e),o=n+Me(t),s=new Uint8Array(o+r.byteLength);return Ke(e,s,0),Ke(t,s,n),s.set(r,o),s}var ff=Symbol.for("@ipld/js-cid/CID");var lo={};Et(lo,{identity:()=>Bt});var zi=0,lf="identity",$i=Zt;function df(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return Mt(zi,$i(e))}var Bt={code:zi,name:lf,encode:$i,digest:df};function ct(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function ht(e=0){return new Uint8Array(e)}function vt(e=0){return new Uint8Array(e)}function Gt(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=vt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var Zi=Symbol.for("@achingbrain/uint8arraylist");function Yi(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function sn(e){return!!e?.[Zi]}var it=class e{bufs;length;[Zi]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(sn(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(sn(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(t){let r=Yi(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Yi(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(sn(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return Gt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Gt(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=[...n],s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===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],c=o,a=c+i.byteLength;if(o=a,t>=a)continue;let f=t>=c&&t<a,u=r>c&&r<=a;if(f&&u){if(t===c&&r===a){n.push(i);break}let l=t-c;n.push(i.subarray(l,l+(r-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(u){if(r===a){n.push(i);break}n.push(i.subarray(0,r-c));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!sn(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.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 c=i,a=this.byteLength-n.byteLength,f=n.byteLength-1,u;for(let l=r;l<=a;l+=u){u=0;for(let h=f;h>=0;h--){let p=this.get(l+h);if(n[h]!==p){u=Math.max(1,h-c[p]);break}}if(u===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=vt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=ht(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=ht(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=ht(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=vt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=ht(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=ht(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=ht(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=ht(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=ht(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!ct(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var ho={};Et(ho,{base10:()=>hf});var hf=ie({prefix:"9",name:"base10",alphabet:"0123456789"});var po={};Et(po,{base16:()=>pf,base16upper:()=>mf});var pf=nt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),mf=nt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var mo={};Et(mo,{base2:()=>yf});var yf=nt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var yo={};Et(yo,{base256emoji:()=>Ef});var Gi=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}"),bf=Gi.reduce((e,t,r)=>(e[r]=t,e),[]),gf=Gi.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function xf(e){return e.reduce((t,r)=>(t+=bf[r],t),"")}function wf(e){let t=[];for(let r of e){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}`);t.push(o)}return new Uint8Array(t)}var Ef=Ue({prefix:"\u{1F680}",name:"base256emoji",encode:xf,decode:wf});var go={};Et(go,{base64:()=>vf,base64pad:()=>Sf,base64url:()=>bo,base64urlpad:()=>If});var vf=nt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Sf=nt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),bo=nt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),If=nt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var xo={};Et(xo,{base8:()=>Af});var Af=nt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var wo={};Et(wo,{identity:()=>_f});var _f=Ue({prefix:"\0",name:"identity",encode:e=>Oi(e),decode:e=>Li(e)});var Ep=new TextEncoder,vp=new TextDecoder;var So={};Et(So,{sha256:()=>vr,sha512:()=>Bf});var Tf=20;function vo({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Eo(e,t,r,n,o)}var Eo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??Tf,this.maxDigestLength=s}digest(t,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(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Wi(n,this.code,r?.truncate):n.then(o=>Wi(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Wi(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return Mt(t,e)}function Xi(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var vr=vo({name:"sha2-256",code:18,encode:Xi("SHA-256")}),Bf=vo({name:"sha2-512",code:19,encode:Xi("SHA-512")});var Sr={...wo,...mo,...xo,...ho,...po,...ao,...co,...io,...go,...yo},Rp={...So,...lo};function Ji(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Qi=Ji("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Io=Ji("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=vt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Pf={utf8:Qi,"utf-8":Qi,hex:Sr.base16,latin1:Io,ascii:Io,binary:Io,...Sr},an=Pf;function F(e,t="utf8"){let r=an[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function H(e,t="utf8"){let r=an[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Lf=parseInt("11111",2),Ao=parseInt("10000000",2),Of=parseInt("01111111",2),ta={0:Ir,1:Ir,2:Rf,3:Uf,4:Kf,5:kf,6:Nf,16:Ir,22:Ir,48:Ir};function Wt(e,t={offset:0}){let r=e[t.offset]&Lf;if(t.offset++,ta[r]!=null)return ta[r](e,t);throw new Error("No decoder for tag "+r)}function Ar(e,t){let r=0;if((e[t.offset]&Ao)===Ao){let n=e[t.offset]&Of,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function Ir(e,t){Ar(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Wt(e,t);if(n===null)break;r.push(n)}return r}function Rf(e,t){let r=Ar(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function Nf(e,t){let r=Ar(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let c=`${s}.${i}`,a=[];for(;t.offset<n;){let f=e[t.offset];if(t.offset++,a.push(f&127),f<128){a.reverse();let u=0;for(let l=0;l<a.length;l++)u+=a[l]<<l*7;c+=`.${u}`,a=[]}}return c}function kf(e,t){return t.offset++,null}function Uf(e,t){let r=Ar(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Kf(e,t){let r=Ar(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Mf(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new it;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function _o(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Mf(e.byteLength);return new it(Uint8Array.from([t.byteLength|Ao]),t)}function St(e){let t=new it,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new it(Uint8Array.from([2]),_o(t),t)}function cn(e){let t=Uint8Array.from([0]),r=new it(t,e);return new it(Uint8Array.from([3]),_o(r),r)}function ce(e,t=48){let r=new it;for(let n of e)r.append(n);return new it(Uint8Array.from([t]),_o(r),r)}async function ea(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),s}var Vf=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Ff=Uint8Array.from([6,5,43,129,4,0,34]),qf=Uint8Array.from([6,5,43,129,4,0,35]),Hf={ext:!0,kty:"EC",crv:"P-256"},zf={ext:!0,kty:"EC",crv:"P-384"},$f={ext:!0,kty:"EC",crv:"P-521"},Co=32,Do=48,To=66;function Bo(e){let t=Wt(e);return ra(t)}function ra(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Co*2+1)return n=H(t.subarray(r,r+Co),"base64url"),o=H(t.subarray(r+Co),"base64url"),new Fe({...Hf,key_ops:["verify"],x:n,y:o});if(t.byteLength===Do*2+1)return n=H(t.subarray(r,r+Do),"base64url"),o=H(t.subarray(r+Do),"base64url"),new Fe({...zf,key_ops:["verify"],x:n,y:o});if(t.byteLength===To*2+1)return n=H(t.subarray(r,r+To),"base64url"),o=H(t.subarray(r+To),"base64url"),new Fe({...$f,key_ops:["verify"],x:n,y:o});throw new Q(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function na(e){return ce([St(Uint8Array.from([1])),ce([Yf(e.crv)],160),ce([cn(new it(Uint8Array.from([4]),F(e.x??"","base64url"),F(e.y??"","base64url")))],161)]).subarray()}function Yf(e){if(e==="P-256")return Vf;if(e==="P-384")return Ff;if(e==="P-521")return qf;throw new Q(`Invalid curve ${e}`)}var Fe=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=na(this.jwk)),this._raw}toMultihash(){return Bt.digest(Vt(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}async verify(t,r,n){return ea(this.jwk,r,t,n)}};function we(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Ft(e,t=""){if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new Error(`${r}expected integer >= 0, got ${e}`)}}function U(e,t,r=""){let n=we(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,c=s?` of length ${t}`:"",a=n?`length=${o}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+c+", got "+a)}return e}function un(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash must wrapped by utils.createHasher");Ft(e.outputLen),Ft(e.blockLen)}function qe(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function sa(e,t){U(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function Xt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function fn(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Pt(e,t){return e<<32-t|e>>>t}var ia=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Zf=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Qt(e){if(U(e),ia)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Zf[e[r]];return t}var jt={_0:48,_9:57,A:65,F:70,a:97,f:102};function oa(e){if(e>=jt._0&&e<=jt._9)return e-jt._0;if(e>=jt.A&&e<=jt.F)return e-(jt.A-10);if(e>=jt.a&&e<=jt.f)return e-(jt.a-10)}function Jt(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(ia)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=oa(e.charCodeAt(s)),c=oa(e.charCodeAt(s+1));if(i===void 0||c===void 0){let a=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function It(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];U(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}function Po(e,t={}){let r=(o,s)=>e(s).update(o).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function He(e=32){let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(e))}var Lo=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function aa(e,t,r){return e&t^~e&r}function ca(e,t,r){return e&t^e&r^t&r}var _r=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,o){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=fn(this.buffer)}update(t){qe(this),U(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=fn(t);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){qe(this),sa(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Xt(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 c=fn(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let f=a/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)c.setUint32(4*l,u[l],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=c,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},te=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var pt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var ln=BigInt(4294967295),ua=BigInt(32);function Gf(e,t=!1){return t?{h:Number(e&ln),l:Number(e>>ua&ln)}:{h:Number(e>>ua&ln)|0,l:Number(e&ln)|0}}function fa(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:c}=Gf(e[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var Oo=(e,t,r)=>e>>>r,Ro=(e,t,r)=>e<<32-r|t>>>r,Ee=(e,t,r)=>e>>>r|t<<32-r,ve=(e,t,r)=>e<<32-r|t>>>r,Cr=(e,t,r)=>e<<64-r|t>>>r-32,Dr=(e,t,r)=>e>>>r-32|t<<64-r;function qt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var la=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),da=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,ha=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),pa=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,ma=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),ya=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var jf=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]),ue=new Uint32Array(64),No=class extends _r{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:c,H:a}=this;return[t,r,n,o,s,i,c,a]}set(t,r,n,o,s,i,c,a){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=a|0}process(t,r){for(let l=0;l<16;l++,r+=4)ue[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let h=ue[l-15],p=ue[l-2],d=Pt(h,7)^Pt(h,18)^h>>>3,E=Pt(p,17)^Pt(p,19)^p>>>10;ue[l]=E+ue[l-7]+d+ue[l-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:f,H:u}=this;for(let l=0;l<64;l++){let h=Pt(c,6)^Pt(c,11)^Pt(c,25),p=u+h+aa(c,a,f)+jf[l]+ue[l]|0,E=(Pt(n,2)^Pt(n,13)^Pt(n,22))+ca(n,o,s)|0;u=f,f=a,a=c,c=i+p|0,i=s,s=o,o=n,n=p+E|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(n,o,s,i,c,a,f,u)}roundClean(){Xt(ue)}destroy(){this.set(0,0,0,0,0,0,0,0),Xt(this.buffer)}},ko=class extends No{A=te[0]|0;B=te[1]|0;C=te[2]|0;D=te[3]|0;E=te[4]|0;F=te[5]|0;G=te[6]|0;H=te[7]|0;constructor(){super(32)}};var ba=fa(["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(e=>BigInt(e))),Xf=ba[0],Qf=ba[1],fe=new Uint32Array(80),le=new Uint32Array(80),Uo=class extends _r{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:f,El:u,Fh:l,Fl:h,Gh:p,Gl:d,Hh:E,Hl:S}=this;return[t,r,n,o,s,i,c,a,f,u,l,h,p,d,E,S]}set(t,r,n,o,s,i,c,a,f,u,l,h,p,d,E,S){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=c|0,this.Dl=a|0,this.Eh=f|0,this.El=u|0,this.Fh=l|0,this.Fl=h|0,this.Gh=p|0,this.Gl=d|0,this.Hh=E|0,this.Hl=S|0}process(t,r){for(let x=0;x<16;x++,r+=4)fe[x]=t.getUint32(r),le[x]=t.getUint32(r+=4);for(let x=16;x<80;x++){let _=fe[x-15]|0,R=le[x-15]|0,K=Ee(_,R,1)^Ee(_,R,8)^Oo(_,R,7),M=ve(_,R,1)^ve(_,R,8)^Ro(_,R,7),v=fe[x-2]|0,w=le[x-2]|0,N=Ee(v,w,19)^Cr(v,w,61)^Oo(v,w,6),V=ve(v,w,19)^Dr(v,w,61)^Ro(v,w,6),B=ha(M,V,le[x-7],le[x-16]),y=pa(B,K,N,fe[x-7],fe[x-16]);fe[x]=y|0,le[x]=B|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:f,Dl:u,Eh:l,El:h,Fh:p,Fl:d,Gh:E,Gl:S,Hh:g,Hl:A}=this;for(let x=0;x<80;x++){let _=Ee(l,h,14)^Ee(l,h,18)^Cr(l,h,41),R=ve(l,h,14)^ve(l,h,18)^Dr(l,h,41),K=l&p^~l&E,M=h&d^~h&S,v=ma(A,R,M,Qf[x],le[x]),w=ya(v,g,_,K,Xf[x],fe[x]),N=v|0,V=Ee(n,o,28)^Cr(n,o,34)^Cr(n,o,39),B=ve(n,o,28)^Dr(n,o,34)^Dr(n,o,39),y=n&s^n&c^s&c,b=o&i^o&a^i&a;g=E|0,A=S|0,E=p|0,S=d|0,p=l|0,d=h|0,{h:l,l:h}=qt(f|0,u|0,w|0,N|0),f=c|0,u=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let m=la(N,B,b);n=da(m,w,V,y),o=m|0}({h:n,l:o}=qt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=qt(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=qt(this.Ch|0,this.Cl|0,c|0,a|0),{h:f,l:u}=qt(this.Dh|0,this.Dl|0,f|0,u|0),{h:l,l:h}=qt(this.Eh|0,this.El|0,l|0,h|0),{h:p,l:d}=qt(this.Fh|0,this.Fl|0,p|0,d|0),{h:E,l:S}=qt(this.Gh|0,this.Gl|0,E|0,S|0),{h:g,l:A}=qt(this.Hh|0,this.Hl|0,g|0,A|0),this.set(n,o,s,i,c,a,f,u,l,h,p,d,E,S,g,A)}roundClean(){Xt(fe,le)}destroy(){Xt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Ko=class extends Uo{Ah=pt[0]|0;Al=pt[1]|0;Bh=pt[2]|0;Bl=pt[3]|0;Ch=pt[4]|0;Cl=pt[5]|0;Dh=pt[6]|0;Dl=pt[7]|0;Eh=pt[8]|0;El=pt[9]|0;Fh=pt[10]|0;Fl=pt[11]|0;Gh=pt[12]|0;Gl=pt[13]|0;Hh=pt[14]|0;Hl=pt[15]|0;constructor(){super(64)}};var ze=Po(()=>new ko,Lo(1));var ga=Po(()=>new Ko,Lo(3));var Vo=BigInt(0),Mo=BigInt(1);function ee(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function xa(e){if(typeof e=="bigint"){if(!dn(e))throw new Error("positive bigint expected, got "+e)}else Ft(e);return e}function Tr(e){let t=xa(e).toString(16);return t.length&1?"0"+t:t}function wa(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?Vo:BigInt("0x"+e)}function $e(e){return wa(Qt(e))}function Se(e){return wa(Qt(pn(U(e)).reverse()))}function hn(e,t){Ft(t),e=xa(e);let r=Jt(e.toString(16).padStart(t*2,"0"));if(r.length!==t)throw new Error("number too large");return r}function Fo(e,t){return hn(e,t).reverse()}function pn(e){return Uint8Array.from(e)}var dn=e=>typeof e=="bigint"&&Vo<=e;function Jf(e,t,r){return dn(e)&&dn(t)&&dn(r)&&t<=e&&e<r}function Br(e,t,r,n){if(!Jf(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function qo(e){let t;for(t=0;e>Vo;e>>=Mo,t+=1);return t}var Pr=e=>(Mo<<BigInt(e))-Mo;function Ea(e,t,r){if(Ft(e,"hashLen"),Ft(t,"qByteLen"),typeof r!="function")throw new Error("hmacFn must be a function");let n=S=>new Uint8Array(S),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),c=1e3,a=n(e),f=n(e),u=0,l=()=>{a.fill(1),f.fill(0),u=0},h=(...S)=>r(f,It(a,...S)),p=(S=o)=>{f=h(s,S),a=h(),S.length!==0&&(f=h(i,S),a=h())},d=()=>{if(u++>=c)throw new Error("drbg: tried max amount of iterations");let S=0,g=[];for(;S<t;){a=h();let A=a.slice();g.push(A),S+=a.length}return It(...g)};return(S,g)=>{l(),p(S);let A;for(;!(A=g(d()));)p();return l(),A}}function de(e,t={},r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(s,i,c){let a=e[s];if(c&&a===void 0)return;let f=typeof a;if(f!==i||a===null)throw new Error(`param "${s}" is invalid: expected ${i}, got ${f}`)}let o=(s,i)=>Object.entries(s).forEach(([c,a])=>n(c,a,i));o(t,!1),o(r,!0)}function Ye(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let s=e(r,...n);return t.set(r,s),s}}var wt=BigInt(0),ut=BigInt(1),Ie=BigInt(2),Ia=BigInt(3),Aa=BigInt(4),_a=BigInt(5),tl=BigInt(7),Ca=BigInt(8),el=BigInt(9),Da=BigInt(16);function st(e,t){let r=e%t;return r>=wt?r:t+r}function X(e,t,r){let n=e;for(;t-- >wt;)n*=n,n%=r;return n}function va(e,t){if(e===wt)throw new Error("invert: expected non-zero number");if(t<=wt)throw new Error("invert: expected positive modulus, got "+t);let r=st(e,t),n=t,o=wt,s=ut,i=ut,c=wt;for(;r!==wt;){let f=n/r,u=n%r,l=o-i*f,h=s-c*f;n=r,r=u,o=i,s=c,i=l,c=h}if(n!==ut)throw new Error("invert: does not exist");return st(o,t)}function zo(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function Ta(e,t){let r=(e.ORDER+ut)/Aa,n=e.pow(t,r);return zo(e,n,t),n}function rl(e,t){let r=(e.ORDER-_a)/Ca,n=e.mul(t,Ie),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,Ie),o),c=e.mul(s,e.sub(i,e.ONE));return zo(e,c,t),c}function nl(e){let t=Ze(e),r=Ba(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+tl)/Da;return(c,a)=>{let f=c.pow(a,i),u=c.mul(f,n),l=c.mul(f,o),h=c.mul(f,s),p=c.eql(c.sqr(u),a),d=c.eql(c.sqr(l),a);f=c.cmov(f,u,p),u=c.cmov(h,l,d);let E=c.eql(c.sqr(u),a),S=c.cmov(f,u,E);return zo(c,S,a),S}}function Ba(e){if(e<Ia)throw new Error("sqrt is not defined for small field");let t=e-ut,r=0;for(;t%Ie===wt;)t/=Ie,r++;let n=Ie,o=Ze(e);for(;Sa(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Ta;let s=o.pow(n,t),i=(t+ut)/Ie;return function(a,f){if(a.is0(f))return f;if(Sa(a,f)!==1)throw new Error("Cannot find square root");let u=r,l=a.mul(a.ONE,s),h=a.pow(f,t),p=a.pow(f,i);for(;!a.eql(h,a.ONE);){if(a.is0(h))return a.ZERO;let d=1,E=a.sqr(h);for(;!a.eql(E,a.ONE);)if(d++,E=a.sqr(E),d===u)throw new Error("Cannot find square root");let S=ut<<BigInt(u-d-1),g=a.pow(l,S);u=d,l=a.sqr(g),h=a.mul(h,l),p=a.mul(p,g)}return p}}function ol(e){return e%Aa===Ia?Ta:e%Ca===_a?rl:e%Da===el?nl(e):Ba(e)}var Pa=(e,t)=>(st(e,t)&ut)===ut,sl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function $o(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=sl.reduce((n,o)=>(n[o]="function",n),t);return de(e,r),e}function il(e,t,r){if(r<wt)throw new Error("invalid exponent, negatives unsupported");if(r===wt)return e.ONE;if(r===ut)return t;let n=e.ONE,o=t;for(;r>wt;)r&ut&&(n=e.mul(n,o)),o=e.sqr(o),r>>=ut;return n}function Lr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,c,a)=>e.is0(c)?i:(n[a]=i,e.mul(i,c)),e.ONE),s=e.inv(o);return t.reduceRight((i,c,a)=>e.is0(c)?i:(n[a]=e.mul(i,n[a]),e.mul(i,c)),s),n}function Sa(e,t){let r=(e.ORDER-ut)/Ie,n=e.pow(t,r),o=e.eql(n,e.ONE),s=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function al(e,t){t!==void 0&&Ft(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}var Ho=class{ORDER;BITS;BYTES;isLE;ZERO=wt;ONE=ut;_lengths;_sqrt;_mod;constructor(t,r={}){if(t<=wt)throw new Error("invalid field: expected ORDER > 0, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&(this.sqrt=r.sqrt),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=r.allowedLengths?.slice()),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=al(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=s,this._sqrt=void 0,Object.preventExtensions(this)}create(t){return st(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof t);return wt<=t&&t<this.ORDER}is0(t){return t===wt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&ut)===ut}neg(t){return st(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return st(t*t,this.ORDER)}add(t,r){return st(t+r,this.ORDER)}sub(t,r){return st(t-r,this.ORDER)}mul(t,r){return st(t*r,this.ORDER)}pow(t,r){return il(this,t,r)}div(t,r){return st(t*va(r,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,r){return t+r}subN(t,r){return t-r}mulN(t,r){return t*r}inv(t){return va(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=ol(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?Fo(t,this.BYTES):hn(t,this.BYTES)}fromBytes(t,r=!1){U(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:c}=this;if(n){if(!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let f=new Uint8Array(o);f.set(t,s?0:f.length-t.length),t=f}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let a=s?Se(t):$e(t);if(c&&(a=st(a,i)),!r&&!this.isValid(a))throw new Error("invalid field element: outside of range 0..ORDER");return a}invertBatch(t){return Lr(this,t)}cmov(t,r,n){return n?r:t}};function Ze(e,t={}){return new Ho(e,t)}function La(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function Yo(e){let t=La(e);return t+Math.ceil(t/2)}function Zo(e,t,r=!1){U(e);let n=e.length,o=La(t),s=Yo(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Se(e):$e(e),c=st(i,t-ut)+ut;return r?Fo(c,o):hn(c,o)}var Ge=BigInt(0),Ae=BigInt(1);function Or(e,t){let r=t.negate();return e?r:t}function _e(e,t){let r=Lr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function ka(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Go(e,t){ka(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=Pr(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Oa(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,c=Number(e&o),a=e>>i;c>n&&(c-=s,a+=Ae);let f=t*n,u=f+Math.abs(c)-1,l=c===0,h=c<0,p=t%2!==0;return{nextN:a,offset:u,isZero:l,isNeg:h,isNegF:p,offsetF:f}}var Wo=new WeakMap,Ua=new WeakMap;function jo(e){return Ua.get(e)||1}function Ra(e){if(e!==Ge)throw new Error("invalid wNAF")}var We=class{BASE;ZERO;Fn;bits;constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>Ge;)r&Ae&&(n=n.add(o)),o=o.double(),r>>=Ae;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=Go(r,this.bits),s=[],i=t,c=i;for(let a=0;a<n;a++){c=i,s.push(c);for(let f=1;f<o;f++)c=c.add(i),s.push(c);i=c.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=Go(t,this.bits);for(let c=0;c<i.windows;c++){let{nextN:a,offset:f,isZero:u,isNeg:l,isNegF:h,offsetF:p}=Oa(n,c,i);n=a,u?s=s.add(Or(h,r[p])):o=o.add(Or(l,r[f]))}return Ra(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=Go(t,this.bits);for(let i=0;i<s.windows&&n!==Ge;i++){let{nextN:c,offset:a,isZero:f,isNeg:u}=Oa(n,i,s);if(n=c,!f){let l=r[a];o=o.add(u?l.negate():l)}}return Ra(n),o}getPrecomputes(t,r,n){let o=Wo.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),Wo.set(r,o))),o}cached(t,r,n){let o=jo(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=jo(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){ka(r,this.bits),Ua.set(t,r),Wo.delete(t)}hasCache(t){return jo(t)!==1}};function Ka(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>Ge||n>Ge;)r&Ae&&(s=s.add(o)),n&Ae&&(i=i.add(o)),o=o.double(),r>>=Ae,n>>=Ae;return{p1:s,p2:i}}function Na(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return $o(t),t}else return Ze(e,{isLE:r})}function mn(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let a of["p","n","h"]){let f=t[a];if(!(typeof f=="bigint"&&f>Ge))throw new Error(`CURVE.${a} must be positive bigint`)}let o=Na(t.p,r.Fp,n),s=Na(t.n,r.Fn,n),c=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let a of c)if(!o.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}function yn(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var he=BigInt(0),ft=BigInt(1),Xo=BigInt(2),cl=BigInt(8);function ul(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),c=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,c)}function Ma(e,t={}){let r=mn("edwards",e,t,t.FpFnLE),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i}=s;de(t,{},{uvRatio:"function"});let c=Xo<<BigInt(o.BYTES*8)-ft,a=S=>n.create(S),f=t.uvRatio||((S,g)=>{try{return{isValid:!0,value:n.sqrt(n.div(S,g))}}catch{return{isValid:!1,value:he}}});if(!ul(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function u(S,g,A=!1){let x=A?ft:he;return Br("coordinate "+S,g,x,c),g}function l(S){if(!(S instanceof d))throw new Error("EdwardsPoint expected")}let h=Ye((S,g)=>{let{X:A,Y:x,Z:_}=S,R=S.is0();g==null&&(g=R?cl:n.inv(_));let K=a(A*g),M=a(x*g),v=n.mul(_,g);if(R)return{x:he,y:ft};if(v!==ft)throw new Error("invZ was invalid");return{x:K,y:M}}),p=Ye(S=>{let{a:g,d:A}=s;if(S.is0())throw new Error("bad point: ZERO");let{X:x,Y:_,Z:R,T:K}=S,M=a(x*x),v=a(_*_),w=a(R*R),N=a(w*w),V=a(M*g),B=a(w*a(V+v)),y=a(N+a(A*a(M*v)));if(B!==y)throw new Error("bad point: equation left != right (1)");let b=a(x*_),m=a(R*K);if(b!==m)throw new Error("bad point: equation left != right (2)");return!0});class d{static BASE=new d(s.Gx,s.Gy,ft,a(s.Gx*s.Gy));static ZERO=new d(he,ft,ft,he);static Fp=n;static Fn=o;X;Y;Z;T;constructor(g,A,x,_){this.X=u("x",g),this.Y=u("y",A),this.Z=u("z",x,!0),this.T=u("t",_),Object.freeze(this)}static CURVE(){return s}static fromAffine(g){if(g instanceof d)throw new Error("extended point not allowed");let{x:A,y:x}=g||{};return u("x",A),u("y",x),new d(A,x,ft,a(A*x))}static fromBytes(g,A=!1){let x=n.BYTES,{a:_,d:R}=s;g=pn(U(g,x,"point")),ee(A,"zip215");let K=pn(g),M=g[x-1];K[x-1]=M&-129;let v=Se(K),w=A?c:n.ORDER;Br("point.y",v,he,w);let N=a(v*v),V=a(N-ft),B=a(R*N-_),{isValid:y,value:b}=f(V,B);if(!y)throw new Error("bad point: invalid y coordinate");let m=(b&ft)===ft,I=(M&128)!==0;if(!A&&b===he&&I)throw new Error("bad point: x=0 and x_0=1");return I!==m&&(b=a(-b)),d.fromAffine({x:b,y:v})}static fromHex(g,A=!1){return d.fromBytes(Jt(g),A)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(g=8,A=!0){return E.createCache(this,g),A||this.multiply(Xo),this}assertValidity(){p(this)}equals(g){l(g);let{X:A,Y:x,Z:_}=this,{X:R,Y:K,Z:M}=g,v=a(A*M),w=a(R*_),N=a(x*M),V=a(K*_);return v===w&&N===V}is0(){return this.equals(d.ZERO)}negate(){return new d(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:g}=s,{X:A,Y:x,Z:_}=this,R=a(A*A),K=a(x*x),M=a(Xo*a(_*_)),v=a(g*R),w=A+x,N=a(a(w*w)-R-K),V=v+K,B=V-M,y=v-K,b=a(N*B),m=a(V*y),I=a(N*y),C=a(B*V);return new d(b,m,C,I)}add(g){l(g);let{a:A,d:x}=s,{X:_,Y:R,Z:K,T:M}=this,{X:v,Y:w,Z:N,T:V}=g,B=a(_*v),y=a(R*w),b=a(M*x*V),m=a(K*N),I=a((_+R)*(v+w)-B-y),C=m-b,T=m+b,P=a(y-A*B),D=a(I*C),O=a(T*P),k=a(I*P),tt=a(C*T);return new d(D,O,tt,k)}subtract(g){return this.add(g.negate())}multiply(g){if(!o.isValidNot0(g))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:A,f:x}=E.cached(this,g,_=>_e(d,_));return _e(d,[A,x])[0]}multiplyUnsafe(g,A=d.ZERO){if(!o.isValid(g))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return g===he?d.ZERO:this.is0()||g===ft?this:E.unsafe(this,g,x=>_e(d,x),A)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return E.unsafe(this,s.n).is0()}toAffine(g){return h(this,g)}clearCofactor(){return i===ft?this:this.multiplyUnsafe(i)}toBytes(){let{x:g,y:A}=this.toAffine(),x=n.toBytes(A);return x[x.length-1]|=g&ft?128:0,x}toHex(){return Qt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let E=new We(d,o.BITS);return d.BASE.precompute(8),d}function Va(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');de(r,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=r,{BASE:o,Fp:s,Fn:i}=e,c=r.randomBytes||He,a=r.adjustScalarBytes||(v=>v),f=r.domain||((v,w,N)=>{if(ee(N,"phflag"),w.length||N)throw new Error("Contexts/pre-hash are not supported");return v});function u(v){return i.create(Se(v))}function l(v){let w=x.secretKey;U(v,x.secretKey,"secretKey");let N=U(t(v),2*w,"hashedSecretKey"),V=a(N.slice(0,w)),B=N.slice(w,2*w),y=u(V);return{head:V,prefix:B,scalar:y}}function h(v){let{head:w,prefix:N,scalar:V}=l(v),B=o.multiply(V),y=B.toBytes();return{head:w,prefix:N,scalar:V,point:B,pointBytes:y}}function p(v){return h(v).pointBytes}function d(v=Uint8Array.of(),...w){let N=It(...w);return u(t(f(N,U(v,void 0,"context"),!!n)))}function E(v,w,N={}){v=U(v,void 0,"message"),n&&(v=n(v));let{prefix:V,scalar:B,pointBytes:y}=h(w),b=d(N.context,V,v),m=o.multiply(b).toBytes(),I=d(N.context,m,y,v),C=i.create(b+I*B);if(!i.isValid(C))throw new Error("sign failed: invalid s");let T=It(m,i.toBytes(C));return U(T,x.signature,"result")}let S={zip215:!0};function g(v,w,N,V=S){let{context:B,zip215:y}=V,b=x.signature;v=U(v,b,"signature"),w=U(w,void 0,"message"),N=U(N,x.publicKey,"publicKey"),y!==void 0&&ee(y,"zip215"),n&&(w=n(w));let m=b/2,I=v.subarray(0,m),C=Se(v.subarray(m,b)),T,P,D;try{T=e.fromBytes(N,y),P=e.fromBytes(I,y),D=o.multiplyUnsafe(C)}catch{return!1}if(!y&&T.isSmallOrder())return!1;let O=d(B,P.toBytes(),T.toBytes(),w);return P.add(T.multiplyUnsafe(O)).subtract(D).clearCofactor().is0()}let A=s.BYTES,x={secretKey:A,publicKey:A,signature:2*A,seed:A};function _(v=c(x.seed)){return U(v,x.seed,"seed")}function R(v){return we(v)&&v.length===i.BYTES}function K(v,w){try{return!!e.fromBytes(v,w)}catch{return!1}}let M={getExtendedPublicKey:h,randomSecretKey:_,isValidSecretKey:R,isValidPublicKey:K,toMontgomery(v){let{y:w}=e.fromBytes(v),N=x.publicKey,V=N===32;if(!V&&N!==57)throw new Error("only defined for 25519 and 448");let B=V?s.div(ft+w,ft-w):s.div(w-ft,w+ft);return s.toBytes(B)},toMontgomerySecret(v){let w=x.secretKey;U(v,w);let N=t(v.subarray(0,w));return a(N).subarray(0,w)}};return Object.freeze({keygen:yn(_,p),getPublicKey:p,sign:E,verify:g,utils:M,Point:e,lengths:x})}var fl=BigInt(1),Fa=BigInt(2);var ll=BigInt(5),dl=BigInt(8),Qo=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),hl={p:Qo,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:dl,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function pl(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Qo,c=e*e%s*e%s,a=X(c,Fa,s)*c%s,f=X(a,fl,s)*e%s,u=X(f,ll,s)*f%s,l=X(u,t,s)*u%s,h=X(l,r,s)*l%s,p=X(h,n,s)*h%s,d=X(p,o,s)*p%s,E=X(d,o,s)*p%s,S=X(E,t,s)*u%s;return{pow_p_5_8:X(S,Fa,s)*e%s,b2:c}}function ml(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var qa=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function yl(e,t){let r=Qo,n=st(t*t*t,r),o=st(n*n*t,r),s=pl(e*o).pow_p_5_8,i=st(e*n*s,r),c=st(t*i*i,r),a=i,f=st(i*qa,r),u=c===e,l=c===st(-e,r),h=c===st(-e*qa,r);return u&&(i=a),(l||h)&&(i=f),Pa(i,r)&&(i=st(-i,r)),{isValid:u||l,value:i}}var bl=Ma(hl,{uvRatio:yl});function gl(e){return Va(bl,ga,Object.assign({adjustScalarBytes:ml},e))}var Ha=gl({});var Rr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},bn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var za={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new bn("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var Dt=za;var gn=32;var Jo,xl=(async()=>{try{return await Dt.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function wl(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await Dt.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await Dt.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function El(e,t,r){return Ha.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function $a(e,t,r){return Jo==null&&(Jo=await xl),Jo?wl(e,t,r):El(e,t,r)}function xn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var wn=class{type="Ed25519";raw;constructor(t){this.raw=ts(t,gn)}toMultihash(){return Bt.digest(Vt(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=$a(this.raw,r,t);return xn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function es(e){return e=ts(e,gn),new wn(e)}function ts(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new Q(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Sl=Math.pow(2,7),Il=Math.pow(2,14),Al=Math.pow(2,21),rs=Math.pow(2,28),ns=Math.pow(2,35),os=Math.pow(2,42),ss=Math.pow(2,49),Z=128,bt=127;function At(e){if(e<Sl)return 1;if(e<Il)return 2;if(e<Al)return 3;if(e<rs)return 4;if(e<ns)return 5;if(e<os)return 6;if(e<ss)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function je(e,t,r=0){switch(At(e)){case 8:t[r++]=e&255|Z,e/=128;case 7:t[r++]=e&255|Z,e/=128;case 6:t[r++]=e&255|Z,e/=128;case 5:t[r++]=e&255|Z,e/=128;case 4:t[r++]=e&255|Z,e>>>=7;case 3:t[r++]=e&255|Z,e>>>=7;case 2:t[r++]=e&255|Z,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function _l(e,t,r=0){switch(At(e)){case 8:t.set(r++,e&255|Z),e/=128;case 7:t.set(r++,e&255|Z),e/=128;case 6:t.set(r++,e&255|Z),e/=128;case 5:t.set(r++,e&255|Z),e/=128;case 4:t.set(r++,e&255|Z),e>>>=7;case 3:t.set(r++,e&255|Z),e>>>=7;case 2:t.set(r++,e&255|Z),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function is(e,t){let r=e[t],n=0;if(n+=r&bt,r<Z||(r=e[t+1],n+=(r&bt)<<7,r<Z)||(r=e[t+2],n+=(r&bt)<<14,r<Z)||(r=e[t+3],n+=(r&bt)<<21,r<Z)||(r=e[t+4],n+=(r&bt)*rs,r<Z)||(r=e[t+5],n+=(r&bt)*ns,r<Z)||(r=e[t+6],n+=(r&bt)*os,r<Z)||(r=e[t+7],n+=(r&bt)*ss,r<Z))return n;throw new RangeError("Could not decode varint")}function Cl(e,t){let r=e.get(t),n=0;if(n+=r&bt,r<Z||(r=e.get(t+1),n+=(r&bt)<<7,r<Z)||(r=e.get(t+2),n+=(r&bt)<<14,r<Z)||(r=e.get(t+3),n+=(r&bt)<<21,r<Z)||(r=e.get(t+4),n+=(r&bt)*rs,r<Z)||(r=e.get(t+5),n+=(r&bt)*ns,r<Z)||(r=e.get(t+6),n+=(r&bt)*os,r<Z)||(r=e.get(t+7),n+=(r&bt)*ss,r<Z))return n;throw new RangeError("Could not decode varint")}function Xe(e,t,r=0){return t==null&&(t=vt(At(e))),t instanceof Uint8Array?je(e,t,r):_l(e,t,r)}function Nr(e,t=0){return e instanceof Uint8Array?is(e,t):Cl(e,t)}var cs=new Float32Array([-0]),pe=new Uint8Array(cs.buffer);function Za(e,t,r){cs[0]=e,t[r]=pe[0],t[r+1]=pe[1],t[r+2]=pe[2],t[r+3]=pe[3]}function Ga(e,t){return pe[0]=e[t],pe[1]=e[t+1],pe[2]=e[t+2],pe[3]=e[t+3],cs[0]}var us=new Float64Array([-0]),gt=new Uint8Array(us.buffer);function Wa(e,t,r){us[0]=e,t[r]=gt[0],t[r+1]=gt[1],t[r+2]=gt[2],t[r+3]=gt[3],t[r+4]=gt[4],t[r+5]=gt[5],t[r+6]=gt[6],t[r+7]=gt[7]}function ja(e,t){return gt[0]=e[t],gt[1]=e[t+1],gt[2]=e[t+2],gt[3]=e[t+3],gt[4]=e[t+4],gt[5]=e[t+5],gt[6]=e[t+6],gt[7]=e[t+7],us[0]}var Dl=BigInt(Number.MAX_SAFE_INTEGER),Tl=BigInt(Number.MIN_SAFE_INTEGER),Ct=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&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(t=!1){if(t)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(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return Ce;if(t<Dl&&t>Tl)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>Xa&&(o=0n,++n>Xa&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return Ce;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):Ce}},Ce=new Ct(0,0);Ce.toBigInt=function(){return 0n};Ce.zzEncode=Ce.zzDecode=function(){return this};Ce.length=function(){return 1};var Xa=4294967296n;function Qa(e){let t=0,r=0;for(let n=0;n<e.length;++n)r=e.charCodeAt(n),r<128?t+=1:r<2048?t+=2:(r&64512)===55296&&(e.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Ja(e,t,r){if(r-t<1)return"";let o,s=[],i=0,c;for(;t<r;)c=e[t++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|e[t++]&63:c>239&&c<365?(c=((c&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&15)<<12|(e[t++]&63)<<6|e[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function fs(e,t,r){let n=r,o,s;for(let i=0;i<e.length;++i)o=e.charCodeAt(i),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((s=e.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function Lt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function En(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var ls=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Lt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Lt(this,4);return En(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Lt(this,4);return En(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Lt(this,4);let t=Ga(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Lt(this,4);let t=ja(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw Lt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return Ja(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Lt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Lt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Ct(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw Lt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw Lt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Lt(this,8);let t=En(this.buf,this.pos+=4),r=En(this.buf,this.pos+=4);return new Ct(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=is(this.buf,this.pos);return this.pos+=At(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function kr(e){return new ls(e instanceof Uint8Array?e:e.subarray())}function Ot(e,t,r){let n=kr(e);return t.decode(n,void 0,r)}function ds(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return vt(i);o+i>t&&(n=vt(t),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var De=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function hs(){}var ms=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Bl=ds();function Pl(e){return globalThis.Buffer!=null?vt(e):Bl(e)}var Kr=class{len;head;tail;states;constructor(){this.len=0,this.head=new De(hs,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new De(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new ys((t=t>>>0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this}int32(t){return t<0?this._push(vn,10,Ct.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=Ct.fromBigInt(t);return this._push(vn,r.length(),r)}uint64Number(t){return this._push(je,At(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=Ct.fromBigInt(t).zzEncode();return this._push(vn,r.length(),r)}sint64Number(t){let r=Ct.fromNumber(t).zzEncode();return this._push(vn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ps,1,t?1:0)}fixed32(t){return this._push(Ur,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=Ct.fromBigInt(t);return this._push(Ur,4,r.lo)._push(Ur,4,r.hi)}fixed64Number(t){let r=Ct.fromNumber(t);return this._push(Ur,4,r.lo)._push(Ur,4,r.hi)}fixed64String(t){return this.fixed64(BigInt(t))}sfixed64(t){return this.fixed64(t)}sfixed64Number(t){return this.fixed64Number(t)}sfixed64String(t){return this.fixed64String(t)}float(t){return this._push(Za,4,t)}double(t){return this._push(Wa,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(ps,1,0):this.uint32(r)._push(Ol,r,t)}string(t){let r=Qa(t);return r!==0?this.uint32(r)._push(fs,r,t):this._push(ps,1,0)}fork(){return this.states=new ms(this),this.head=this.tail=new De(hs,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new De(hs,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=Pl(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function ps(e,t,r){t[r]=e&255}function Ll(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var ys=class extends De{next;constructor(t,r){super(Ll,t,r),this.next=void 0}};function vn(e,t,r){for(;e.hi!==0;)t[r++]=e.lo&127|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=e.lo&127|128,e.lo=e.lo>>>7;t[r++]=e.lo}function Ur(e,t,r){t[r]=e&255,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function Ol(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Kr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Rl,t,e),this},Kr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Nl,t,e),this});function Rl(e,t,r){t.set(e,r)}function Nl(e,t,r){e.length<40?fs(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(F(e),r)}function bs(){return new Kr}function Rt(e,t){let r=bs();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*Nt(e,t,r){let n=kr(e);yield*t.stream(n,void 0,"$",r)}var Sn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function In(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function gs(e){function t(s){if(e[s.toString()]==null)throw new Error("Invalid enum value");return e[s]}let r=function(i,c){let a=t(i);c.int32(a)},n=function(i){let c=i.int32();return t(c)},o=function*(i){let c=i.int32();yield t(c)};return In("enum",Sn.VARINT,r,n,o)}function kt(e,t,r){return In("message",Sn.LENGTH_DELIMITED,e,t,r)}var Ht=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var J;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(J||(J={}));var xs;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(xs||(xs={}));(function(e){e.codec=()=>gs(xs)})(J||(J={}));var zt;(function(e){let t;e.codec=()=>(t==null&&(t=kt((s,i,c={})=>{c.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)),c.lengthDelimited!==!1&&i.ldelim()},(s,i,c={})=>{let a={},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{a.Type=J.codec().decode(s);break}case 2:{a.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return a},function*(s,i,c,a={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${c}.Type`,value:J.codec().decode(s)};break}case 2:{yield{field:`${c}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return Rt(s,e.codec())}e.encode=r;function n(s,i){return Ot(s,e.codec(),i)}e.decode=n;function o(s,i){return Nt(s,e.codec(),i)}e.stream=o})(zt||(zt={}));var ws;(function(e){let t;e.codec=()=>(t==null&&(t=kt((s,i,c={})=>{c.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)),c.lengthDelimited!==!1&&i.ldelim()},(s,i,c={})=>{let a={},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{a.Type=J.codec().decode(s);break}case 2:{a.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return a},function*(s,i,c,a={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${c}.Type`,value:J.codec().decode(s)};break}case 2:{yield{field:`${c}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return Rt(s,e.codec())}e.encode=r;function n(s,i){return Ot(s,e.codec(),i)}e.decode=n;function o(s,i){return Nt(s,e.codec(),i)}e.stream=o})(ws||(ws={}));var Vr={};Et(Vr,{MAX_RSA_KEY_SIZE:()=>Es,generateRSAKeyPair:()=>sc,jwkToJWKKeyPair:()=>ic,jwkToPkcs1:()=>Ml,jwkToPkix:()=>As,jwkToRSAPrivateKey:()=>Ts,pkcs1MessageToJwk:()=>Ss,pkcs1MessageToRSAPrivateKey:()=>_s,pkcs1ToJwk:()=>Kl,pkcs1ToRSAPrivateKey:()=>oc,pkixMessageToJwk:()=>Is,pkixMessageToRSAPublicKey:()=>Ds,pkixToJwk:()=>Vl,pkixToRSAPublicKey:()=>Cs});var Qe=class{type="RSA";jwk;_raw;_multihash;constructor(t,r){this.jwk=t,this._multihash=r}get raw(){return this._raw==null&&(this._raw=Vr.jwkToPkix(this.jwk)),this._raw}toMultihash(){return this._multihash}toCID(){return at.createV1(114,this._multihash)}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}verify(t,r,n){return nc(this.jwk,r,t,n)}},Mr=class{type="RSA";jwk;_raw;publicKey;constructor(t,r){this.jwk=t,this.publicKey=r}get raw(){return this._raw==null&&(this._raw=Vr.jwkToPkcs1(this.jwk)),this._raw}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}sign(t,r){return rc(this.jwk,t,r)}};var Es=8192,vs=18,kl=1062,Ul=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Kl(e){let t=Wt(e);return Ss(t)}function Ss(e){return{n:H(e[1],"base64url"),e:H(e[2],"base64url"),d:H(e[3],"base64url"),p:H(e[4],"base64url"),q:H(e[5],"base64url"),dp:H(e[6],"base64url"),dq:H(e[7],"base64url"),qi:H(e[8],"base64url"),kty:"RSA"}}function Ml(e){if(e.n==null||e.e==null||e.d==null||e.p==null||e.q==null||e.dp==null||e.dq==null||e.qi==null)throw new Q("JWK was missing components");return ce([St(Uint8Array.from([0])),St(F(e.n,"base64url")),St(F(e.e,"base64url")),St(F(e.d,"base64url")),St(F(e.p,"base64url")),St(F(e.q,"base64url")),St(F(e.dp,"base64url")),St(F(e.dq,"base64url")),St(F(e.qi,"base64url"))]).subarray()}function Vl(e){let t=Wt(e,{offset:0});return Is(t)}function Is(e){let t=Wt(e[1],{offset:0});return{kty:"RSA",n:H(t[0],"base64url"),e:H(t[1],"base64url")}}function As(e){if(e.n==null||e.e==null)throw new Q("JWK was missing components");return ce([Ul,cn(ce([St(F(e.n,"base64url")),St(F(e.e,"base64url"))]))]).subarray()}function oc(e){let t=Wt(e);return _s(t)}function _s(e){let t=Ss(e);return Ts(t)}function Cs(e,t){if(e.byteLength>=kl)throw new ke("Key size is too large");let r=Wt(e,{offset:0});return Ds(r,e,t)}function Ds(e,t,r){let n=Is(e);if(r==null){let o=ze(zt.encode({Type:J.RSA,Data:t}));r=Mt(vs,o)}return new Qe(n,r)}function Ts(e){if(cc(e)>Es)throw new Q("Key size is too large");let t=ic(e),r=ze(zt.encode({Type:J.RSA,Data:As(t.publicKey)})),n=Mt(vs,r);return new Mr(t.privateKey,new Qe(t.publicKey,n))}async function sc(e){if(e>Es)throw new Q("Key size is too large");let t=await ac(e),r=ze(zt.encode({Type:J.RSA,Data:As(t.publicKey)})),n=Mt(vs,r);return new Mr(t.privateKey,new Qe(t.publicKey,n))}function ic(e){if(e==null)throw new Q("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function ac(e,t){let r=await Dt.get().subtle.generateKey({name:"RSASSA-PKCS1-v1_5",modulusLength:e,publicExponent:new Uint8Array([1,0,1]),hash:{name:"SHA-256"}},!0,["sign","verify"]);t?.signal?.throwIfAborted();let n=await Fl(r,t);return{privateKey:n[0],publicKey:n[1]}}async function rc(e,t,r){let n=await Dt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let o=await Dt.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,t instanceof Uint8Array?t:t.subarray());return r?.signal?.throwIfAborted(),new Uint8Array(o,0,o.byteLength)}async function nc(e,t,r,n){let o=await Dt.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let s=await Dt.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},o,t,r instanceof Uint8Array?r:r.subarray());return n?.signal?.throwIfAborted(),s}async function Fl(e,t){if(e.privateKey==null||e.publicKey==null)throw new Q("Private and public key are required");let r=await Promise.all([Dt.get().subtle.exportKey("jwk",e.privateKey),Dt.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function cc(e){if(e.kty!=="RSA")throw new Q("invalid key type");if(e.n==null)throw new Q("invalid key modulus");return F(e.n,"base64url").length*8}var An=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,r){if(un(t),U(r,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?t.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),Xt(o)}update(t){return qe(this),this.iHash.update(t),this}digestInto(t){qe(this),U(t,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Bs=(e,t,r)=>new An(e,t).update(r).digest();Bs.create=(e,t)=>new An(e,t);var uc=(e,t)=>(e+(e>=0?t:-t)/fc)/t;function ql(e,t,r){let[[n,o],[s,i]]=t,c=uc(i*e,r),a=uc(-o*e,r),f=e-c*n-a*s,u=-c*o-a*i,l=f<re,h=u<re;l&&(f=-f),h&&(u=-u);let p=Pr(Math.ceil(qo(r)/2))+Je;if(f<re||f>=p||u<re||u>=p)throw new Error("splitScalar (endomorphism): failed, k="+e);return{k1neg:l,k1:f,k2neg:h,k2:u}}function Ls(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Ps(e,t){let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return ee(r.lowS,"lowS"),ee(r.prehash,"prehash"),r.format!==void 0&&Ls(r.format),r}var Os=class extends Error{constructor(t=""){super(t)}},me={Err:Os,_tlv:{encode:(e,t)=>{let{Err:r}=me;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=Tr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?Tr(o.length/2|128):"";return Tr(e)+s+o+t},decode(e,t){let{Err:r}=me,n=0;if(e<0||e>256)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let a=o&127;if(!a)throw new r("tlv.decode(long): indefinite length not supported");if(a>4)throw new r("tlv.decode(long): byte length is too big");let f=t.subarray(n,n+a);if(f.length!==a)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let u of f)i=i<<8|u;if(n+=a,i<128)throw new r("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new r("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=me;if(e<re)throw new t("integer: negative integers are not allowed");let r=Tr(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=me;if(e[0]&128)throw new t("invalid signature integer: negative");if(e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return $e(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=me,o=U(e,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:a}=n.decode(2,s),{v:f,l:u}=n.decode(2,a);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(f)}},hexFromSig(e){let{_tlv:t,_int:r}=me,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}},re=BigInt(0),Je=BigInt(1),fc=BigInt(2),_n=BigInt(3),Hl=BigInt(4);function lc(e,t={}){let r=mn("weierstrass",e,t),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:c}=s;de(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:a}=t;if(a&&(!n.is0(s.a)||typeof a.beta!="bigint"||!Array.isArray(a.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=hc(n,o);function u(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function l(B,y,b){let{x:m,y:I}=y.toAffine(),C=n.toBytes(m);if(ee(b,"isCompressed"),b){u();let T=!n.isOdd(I);return It(dc(T),C)}else return It(Uint8Array.of(4),C,n.toBytes(I))}function h(B){U(B,void 0,"Point");let{publicKey:y,publicKeyUncompressed:b}=f,m=B.length,I=B[0],C=B.subarray(1);if(m===y&&(I===2||I===3)){let T=n.fromBytes(C);if(!n.isValid(T))throw new Error("bad point: is not on curve, wrong x");let P=E(T),D;try{D=n.sqrt(P)}catch(tt){let j=tt instanceof Error?": "+tt.message:"";throw new Error("bad point: is not on curve, sqrt error"+j)}u();let O=n.isOdd(D);return(I&1)===1!==O&&(D=n.neg(D)),{x:T,y:D}}else if(m===b&&I===4){let T=n.BYTES,P=n.fromBytes(C.subarray(0,T)),D=n.fromBytes(C.subarray(T,T*2));if(!S(P,D))throw new Error("bad point: is not on curve");return{x:P,y:D}}else throw new Error(`bad point: got length ${m}, expected compressed=${y} or uncompressed=${b}`)}let p=t.toBytes||l,d=t.fromBytes||h;function E(B){let y=n.sqr(B),b=n.mul(y,B);return n.add(n.add(b,n.mul(B,s.a)),s.b)}function S(B,y){let b=n.sqr(y),m=E(B);return n.eql(b,m)}if(!S(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let g=n.mul(n.pow(s.a,_n),Hl),A=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(g,A)))throw new Error("bad curve params: a or b");function x(B,y,b=!1){if(!n.isValid(y)||b&&n.is0(y))throw new Error(`bad point coordinate ${B}`);return y}function _(B){if(!(B instanceof w))throw new Error("Weierstrass Point expected")}function R(B){if(!a||!a.basises)throw new Error("no endo");return ql(B,a.basises,o.ORDER)}let K=Ye((B,y)=>{let{X:b,Y:m,Z:I}=B;if(n.eql(I,n.ONE))return{x:b,y:m};let C=B.is0();y==null&&(y=C?n.ONE:n.inv(I));let T=n.mul(b,y),P=n.mul(m,y),D=n.mul(I,y);if(C)return{x:n.ZERO,y:n.ZERO};if(!n.eql(D,n.ONE))throw new Error("invZ was invalid");return{x:T,y:P}}),M=Ye(B=>{if(B.is0()){if(t.allowInfinityPoint&&!n.is0(B.Y))return;throw new Error("bad point: ZERO")}let{x:y,y:b}=B.toAffine();if(!n.isValid(y)||!n.isValid(b))throw new Error("bad point: x or y not field elements");if(!S(y,b))throw new Error("bad point: equation left != right");if(!B.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function v(B,y,b,m,I){return b=new w(n.mul(b.X,B),b.Y,b.Z),y=Or(m,y),b=Or(I,b),y.add(b)}class w{static BASE=new w(s.Gx,s.Gy,n.ONE);static ZERO=new w(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(y,b,m){this.X=x("x",y),this.Y=x("y",b,!0),this.Z=x("z",m),Object.freeze(this)}static CURVE(){return s}static fromAffine(y){let{x:b,y:m}=y||{};if(!y||!n.isValid(b)||!n.isValid(m))throw new Error("invalid affine point");if(y instanceof w)throw new Error("projective point not allowed");return n.is0(b)&&n.is0(m)?w.ZERO:new w(b,m,n.ONE)}static fromBytes(y){let b=w.fromAffine(d(U(y,void 0,"point")));return b.assertValidity(),b}static fromHex(y){return w.fromBytes(Jt(y))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,b=!0){return V.createCache(this,y),b||this.multiply(_n),this}assertValidity(){M(this)}hasEvenY(){let{y}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(y)}equals(y){_(y);let{X:b,Y:m,Z:I}=this,{X:C,Y:T,Z:P}=y,D=n.eql(n.mul(b,P),n.mul(C,I)),O=n.eql(n.mul(m,P),n.mul(T,I));return D&&O}negate(){return new w(this.X,n.neg(this.Y),this.Z)}double(){let{a:y,b}=s,m=n.mul(b,_n),{X:I,Y:C,Z:T}=this,P=n.ZERO,D=n.ZERO,O=n.ZERO,k=n.mul(I,I),tt=n.mul(C,C),j=n.mul(T,T),z=n.mul(I,C);return z=n.add(z,z),O=n.mul(I,T),O=n.add(O,O),P=n.mul(y,O),D=n.mul(m,j),D=n.add(P,D),P=n.sub(tt,D),D=n.add(tt,D),D=n.mul(P,D),P=n.mul(z,P),O=n.mul(m,O),j=n.mul(y,j),z=n.sub(k,j),z=n.mul(y,z),z=n.add(z,O),O=n.add(k,k),k=n.add(O,k),k=n.add(k,j),k=n.mul(k,z),D=n.add(D,k),j=n.mul(C,T),j=n.add(j,j),k=n.mul(j,z),P=n.sub(P,k),O=n.mul(j,tt),O=n.add(O,O),O=n.add(O,O),new w(P,D,O)}add(y){_(y);let{X:b,Y:m,Z:I}=this,{X:C,Y:T,Z:P}=y,D=n.ZERO,O=n.ZERO,k=n.ZERO,tt=s.a,j=n.mul(s.b,_n),z=n.mul(b,C),et=n.mul(m,T),dt=n.mul(I,P),Kt=n.add(b,m),rt=n.add(C,T);Kt=n.mul(Kt,rt),rt=n.add(z,et),Kt=n.sub(Kt,rt),rt=n.add(b,I);let yt=n.add(C,P);return rt=n.mul(rt,yt),yt=n.add(z,dt),rt=n.sub(rt,yt),yt=n.add(m,I),D=n.add(T,P),yt=n.mul(yt,D),D=n.add(et,dt),yt=n.sub(yt,D),k=n.mul(tt,rt),D=n.mul(j,dt),k=n.add(D,k),D=n.sub(et,k),k=n.add(et,k),O=n.mul(D,k),et=n.add(z,z),et=n.add(et,z),dt=n.mul(tt,dt),rt=n.mul(j,rt),et=n.add(et,dt),dt=n.sub(z,dt),dt=n.mul(tt,dt),rt=n.add(rt,dt),z=n.mul(et,rt),O=n.add(O,z),z=n.mul(yt,rt),D=n.mul(Kt,D),D=n.sub(D,z),z=n.mul(Kt,et),k=n.mul(yt,k),k=n.add(k,z),new w(D,O,k)}subtract(y){return this.add(y.negate())}is0(){return this.equals(w.ZERO)}multiply(y){let{endo:b}=t;if(!o.isValidNot0(y))throw new Error("invalid scalar: out of range");let m,I,C=T=>V.cached(this,T,P=>_e(w,P));if(b){let{k1neg:T,k1:P,k2neg:D,k2:O}=R(y),{p:k,f:tt}=C(P),{p:j,f:z}=C(O);I=tt.add(z),m=v(b.beta,k,j,T,D)}else{let{p:T,f:P}=C(y);m=T,I=P}return _e(w,[m,I])[0]}multiplyUnsafe(y){let{endo:b}=t,m=this;if(!o.isValid(y))throw new Error("invalid scalar: out of range");if(y===re||m.is0())return w.ZERO;if(y===Je)return m;if(V.hasCache(this))return this.multiply(y);if(b){let{k1neg:I,k1:C,k2neg:T,k2:P}=R(y),{p1:D,p2:O}=Ka(w,m,C,P);return v(b.beta,D,O,I,T)}else return V.unsafe(m,y)}toAffine(y){return K(this,y)}isTorsionFree(){let{isTorsionFree:y}=t;return i===Je?!0:y?y(w,this):V.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:y}=t;return i===Je?this:y?y(w,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(y=!0){return ee(y,"isCompressed"),this.assertValidity(),p(w,this,y)}toHex(y=!0){return Qt(this.toBytes(y))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let N=o.BITS,V=new We(w,t.endo?Math.ceil(N/2):N);return w.BASE.precompute(8),w}function dc(e){return Uint8Array.of(e?2:3)}function hc(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function zl(e,t={}){let{Fn:r}=e,n=t.randomBytes||He,o=Object.assign(hc(e.Fp,r),{seed:Yo(r.ORDER)});function s(p){try{let d=r.fromBytes(p);return r.isValidNot0(d)}catch{return!1}}function i(p,d){let{publicKey:E,publicKeyUncompressed:S}=o;try{let g=p.length;return d===!0&&g!==E||d===!1&&g!==S?!1:!!e.fromBytes(p)}catch{return!1}}function c(p=n(o.seed)){return Zo(U(p,o.seed,"seed"),r.ORDER)}function a(p,d=!0){return e.BASE.multiply(r.fromBytes(p)).toBytes(d)}function f(p){let{secretKey:d,publicKey:E,publicKeyUncompressed:S}=o;if(!we(p)||"_lengths"in r&&r._lengths||d===E)return;let g=U(p,void 0,"key").length;return g===E||g===S}function u(p,d,E=!0){if(f(p)===!0)throw new Error("first arg must be private key");if(f(d)===!1)throw new Error("second arg must be public key");let S=r.fromBytes(p);return e.fromBytes(d).multiply(S).toBytes(E)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:c},h=yn(c,a);return Object.freeze({getPublicKey:a,getSharedSecret:u,keygen:h,Point:e,utils:l,lengths:o})}function pc(e,t,r={}){un(t),de(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let n=r.randomBytes||He,o=r.hmac||((b,m)=>Bs(t,b,m)),{Fp:s,Fn:i}=e,{ORDER:c,BITS:a}=i,{keygen:f,getPublicKey:u,getSharedSecret:l,utils:h,lengths:p}=zl(e,r),d={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},E=c*fc<s.ORDER;function S(b){let m=c>>Je;return b>m}function g(b,m){if(!i.isValidNot0(m))throw new Error(`invalid signature ${b}: out of range 1..Point.Fn.ORDER`);return m}function A(){if(E)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function x(b,m){Ls(m);let I=p.signature,C=m==="compact"?I:m==="recovered"?I+1:void 0;return U(b,C)}class _{r;s;recovery;constructor(m,I,C){if(this.r=g("r",m),this.s=g("s",I),C!=null){if(A(),![0,1,2,3].includes(C))throw new Error("invalid recovery id");this.recovery=C}Object.freeze(this)}static fromBytes(m,I=d.format){x(m,I);let C;if(I==="der"){let{r:O,s:k}=me.toSig(U(m));return new _(O,k)}I==="recovered"&&(C=m[0],I="compact",m=m.subarray(1));let T=p.signature/2,P=m.subarray(0,T),D=m.subarray(T,T*2);return new _(i.fromBytes(P),i.fromBytes(D),C)}static fromHex(m,I){return this.fromBytes(Jt(m),I)}assertRecovery(){let{recovery:m}=this;if(m==null)throw new Error("invalid recovery id: must be present");return m}addRecoveryBit(m){return new _(this.r,this.s,m)}recoverPublicKey(m){let{r:I,s:C}=this,T=this.assertRecovery(),P=T===2||T===3?I+c:I;if(!s.isValid(P))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let D=s.toBytes(P),O=e.fromBytes(It(dc((T&1)===0),D)),k=i.inv(P),tt=K(U(m,void 0,"msgHash")),j=i.create(-tt*k),z=i.create(C*k),et=e.BASE.multiplyUnsafe(j).add(O.multiplyUnsafe(z));if(et.is0())throw new Error("invalid recovery: point at infinify");return et.assertValidity(),et}hasHighS(){return S(this.s)}toBytes(m=d.format){if(Ls(m),m==="der")return Jt(me.hexFromSig(this));let{r:I,s:C}=this,T=i.toBytes(I),P=i.toBytes(C);return m==="recovered"?(A(),It(Uint8Array.of(this.assertRecovery()),T,P)):It(T,P)}toHex(m){return Qt(this.toBytes(m))}}let R=r.bits2int||function(m){if(m.length>8192)throw new Error("input is too large");let I=$e(m),C=m.length*8-a;return C>0?I>>BigInt(C):I},K=r.bits2int_modN||function(m){return i.create(R(m))},M=Pr(a);function v(b){return Br("num < 2^"+a,b,re,M),i.toBytes(b)}function w(b,m){return U(b,void 0,"message"),m?U(t(b),void 0,"prehashed message"):b}function N(b,m,I){let{lowS:C,prehash:T,extraEntropy:P}=Ps(I,d);b=w(b,T);let D=K(b),O=i.fromBytes(m);if(!i.isValidNot0(O))throw new Error("invalid private key");let k=[v(O),v(D)];if(P!=null&&P!==!1){let et=P===!0?n(p.secretKey):P;k.push(U(et,void 0,"extraEntropy"))}let tt=It(...k),j=D;function z(et){let dt=R(et);if(!i.isValidNot0(dt))return;let Kt=i.inv(dt),rt=e.BASE.multiply(dt).toAffine(),yt=i.create(rt.x);if(yt===re)return;let Jr=i.create(Kt*i.create(j+yt*O));if(Jr===re)return;let Di=(rt.x===yt?0:2)|Number(rt.y&Je),Ti=Jr;return C&&S(Jr)&&(Ti=i.neg(Jr),Di^=1),new _(yt,Ti,E?void 0:Di)}return{seed:tt,k2sig:z}}function V(b,m,I={}){let{seed:C,k2sig:T}=N(b,m,I);return Ea(t.outputLen,i.BYTES,o)(C,T).toBytes(I.format)}function B(b,m,I,C={}){let{lowS:T,prehash:P,format:D}=Ps(C,d);if(I=U(I,void 0,"publicKey"),m=w(m,P),!we(b)){let O=b instanceof _?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+O)}x(b,D);try{let O=_.fromBytes(b,D),k=e.fromBytes(I);if(T&&O.hasHighS())return!1;let{r:tt,s:j}=O,z=K(m),et=i.inv(j),dt=i.create(z*et),Kt=i.create(tt*et),rt=e.BASE.multiplyUnsafe(dt).add(k.multiplyUnsafe(Kt));return rt.is0()?!1:i.create(rt.x)===tt}catch{return!1}}function y(b,m,I={}){let{prehash:C}=Ps(I,d);return m=w(m,C),_.fromBytes(b,"recovered").recoverPublicKey(m).toBytes()}return Object.freeze({keygen:f,getPublicKey:u,getSharedSecret:l,utils:h,lengths:p,Point:e,sign:V,verify:B,recoverPublicKey:y,Signature:_,hash:t})}var Ns={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},$l={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var mc=BigInt(2);function Yl(e){let t=Ns.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),a=BigInt(88),f=e*e*e%t,u=f*f*e%t,l=X(u,r,t)*u%t,h=X(l,r,t)*u%t,p=X(h,mc,t)*f%t,d=X(p,o,t)*p%t,E=X(d,s,t)*d%t,S=X(E,c,t)*E%t,g=X(S,a,t)*S%t,A=X(g,c,t)*E%t,x=X(A,r,t)*u%t,_=X(x,i,t)*d%t,R=X(_,n,t)*f%t,K=X(R,mc,t);if(!Rs.eql(Rs.sqr(K),e))throw new Error("Cannot find square root");return K}var Rs=Ze(Ns.p,{sqrt:Yl}),Zl=lc(Ns,{Fp:Rs,endo:$l}),tr=pc(Zl,ze);function yc(e,t,r,n){let o=vr.digest(r instanceof Uint8Array?r:r.subarray());if(xn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),tr.verify(t,s,e,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Rr(String(s))});try{return n?.signal?.throwIfAborted(),tr.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(s){throw new Rr(String(s))}}var Cn=class{type="secp256k1";raw;_key;constructor(t){this._key=gc(t),this.raw=bc(this._key)}toMultihash(){return Bt.digest(Vt(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return ot.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:ct(this.raw,t.raw)}verify(t,r,n){return yc(this._key,r,t,n)}};function ks(e){return new Cn(e)}function bc(e){return tr.Point.fromBytes(e).toBytes()}function gc(e){try{return tr.Point.fromBytes(e),e}catch(t){throw new ke(String(t))}}function er(e,t){let{Type:r,Data:n}=zt.decode(e),o=n??new Uint8Array;switch(r){case J.RSA:return Cs(o,t);case J.Ed25519:return es(o);case J.secp256k1:return ks(o);case J.ECDSA:return Bo(o);default:throw new ge}}function xc(e){let{Type:t,Data:r}=zt.decode(e.digest),n=r??new Uint8Array;switch(t){case J.Ed25519:return es(n);case J.secp256k1:return ks(n);case J.ECDSA:return Bo(n);default:throw new ge}}function Vt(e){return zt.encode({Type:J[e.type],Data:e.raw})}var Fr;(function(e){let t;e.codec=()=>(t==null&&(t=kt((s,i,c={})=>{c.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)),c.lengthDelimited!==!1&&i.ldelim()},(s,i,c={})=>{let a={publicKey:ht(0),payloadType:ht(0),payload:ht(0),signature:ht(0)},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{a.publicKey=s.bytes();break}case 2:{a.payloadType=s.bytes();break}case 3:{a.payload=s.bytes();break}case 5:{a.signature=s.bytes();break}default:{s.skipType(u&7);break}}}return a},function*(s,i,c,a={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${c}.publicKey`,value:s.bytes()};break}case 2:{yield{field:`${c}.payloadType`,value:s.bytes()};break}case 3:{yield{field:`${c}.payload`,value:s.bytes()};break}case 5:{yield{field:`${c}.signature`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return Rt(s,e.codec())}e.encode=r;function n(s,i){return Ot(s,e.codec(),i)}e.decode=n;function o(s,i){return Nt(s,e.codec(),i)}e.stream=o})(Fr||(Fr={}));var Dn=class extends Error{constructor(t="Invalid signature"){super(t),this.name="InvalidSignatureError"}};var $t=class e{static createFromProtobuf=t=>{let r=Fr.decode(t),n=er(r.publicKey);return new e({publicKey:n,payloadType:r.payloadType,payload:r.payload,signature:r.signature})};static seal=async(t,r,n)=>{if(r==null)throw new Error("Missing private key");let o=t.domain,s=t.codec,i=t.marshal(),c=wc(o,s,i),a=await r.sign(c.subarray(),n);return new e({publicKey:r.publicKey,payloadType:s,payload:i,signature:a})};static openAndCertify=async(t,r,n)=>{let o=e.createFromProtobuf(t);if(!await o.validate(r,n))throw new Dn("Envelope signature is not valid for the given domain");return o};publicKey;payloadType;payload;signature;marshaled;constructor(t){let{publicKey:r,payloadType:n,payload:o,signature:s}=t;this.publicKey=r,this.payloadType=n,this.payload=o,this.signature=s}marshal(){return this.marshaled==null&&(this.marshaled=Fr.encode({publicKey:Vt(this.publicKey),payloadType:this.payloadType,payload:this.payload.subarray(),signature:this.signature})),this.marshaled}equals(t){return t==null?!1:ct(this.marshal(),t.marshal())}async validate(t,r){let n=wc(t,this.payloadType,this.payload);return this.publicKey.verify(n.subarray(),this.signature,r)}},wc=(e,t,r)=>{let n=F(e),o=Xe(n.byteLength),s=Xe(t.length),i=Xe(r.length);return new it(o,n,s,t,i,r)};var Ec=Symbol.for("nodejs.util.inspect.custom"),Gl=114,qr=class{type;multihash;publicKey;string;constructor(t){this.type=t.type,this.multihash=t.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[eo]=!0;toString(){return this.string==null&&(this.string=ot.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return at.createV1(Gl,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return ct(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return ct(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Ec](){return`PeerId(${this.toString()})`}},Hr=class extends qr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},zr=class extends qr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},$r=class extends qr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Wl=2336,Yr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Bt.digest(F(this.url))}[Ec](){return`PeerId(${this.url})`}[eo]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return at.createV1(Wl,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=H(t)),t.toString()===this.toString())}};var jl=114,vc=2336;function Sc(e){if(e.type==="Ed25519")return new zr({multihash:e.toCID().multihash,publicKey:e});if(e.type==="secp256k1")return new $r({multihash:e.toCID().multihash,publicKey:e});if(e.type==="RSA")return new Hr({multihash:e.toCID().multihash,publicKey:e});throw new ge}function Us(e){if(Ql(e))return new Hr({multihash:e});if(Xl(e))try{let t=xc(e);if(t.type==="Ed25519")return new zr({multihash:e,publicKey:t});if(t.type==="secp256k1")return new $r({multihash:e,publicKey:t})}catch{let r=H(e.digest);return new Yr(new URL(r))}throw new rn("Supplied PeerID Multihash is invalid")}function Tn(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==jl&&e.code!==vc)throw new en("Supplied PeerID CID is invalid");if(e.code===vc){let t=H(e.multihash.digest);return new Yr(new URL(t))}return Us(e.multihash)}function Xl(e){return e.code===Bt.code}function Ql(e){return e.code===vr.code}var mt=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},ne=class extends Error{static name="ValidationError";name="ValidationError"},Bn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Pn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var Ln=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let r=this.index,n=t();return n===void 0&&(this.index=r),n}parseWith(t){let r=t();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(t){return this.readAtomically(()=>{let r=this.readChar();if(r===t)return r})}readSeparator(t,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,r,n,o){return this.readAtomically(()=>{let s=0,i=0,c=this.peekChar();if(c===void 0)return;let a=c==="0",f=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let h=Number.parseInt(l,t);if(!Number.isNaN(h))return h});if(u===void 0)break;if(s*=t,s+=u,s>f||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&a&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let r=0;r<t.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[r]=n}return t})}readIPv6Addr(){let t=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]=t(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),[c]=t(s.subarray(0,i));return r.set(s.subarray(0,c),16-c),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Ic=45,Jl=15,rr=new Ln;function On(e){if(!(e.length>Jl))return rr.new(e).parseWith(()=>rr.readIPv4Addr())}function Rn(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>Ic))return rr.new(e).parseWith(()=>rr.readIPv6Addr())}function nr(e,t=!1){if(e.includes("%")&&(e=e.split("%")[0]),e.length>Ic)return;let r=rr.new(e).parseWith(()=>rr.readIPAddr());if(r)return t&&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 or(e){return!!On(e)}function Nn(e){return!!Rn(e)}function Ms(e){return t=>H(t,e)}function Vs(e){return t=>F(t,e)}function sr(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function Te(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function Ac(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let r=F(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Te(n);return Gt([r,o],r.length+o.length)}function _c(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let r=ae.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Te(n);return Gt([r,o],r.length+o.length)}function Fs(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=H(t,"base32"),o=sr(r);return`${n}:${o}`}var qs=function(e){e=e.toString().trim();let t=new Uint8Array(4);return e.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new mt("Invalid byte value in IP address");t[n]=o}),t},Cc=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let s=or(r[n]),i;s&&(i=qs(r[n]),r[n]=H(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,H(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(t+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 mt("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Dc=function(e){if(e.byteLength!==4)throw new mt("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},Tc=function(e){if(e.byteLength!==16)throw new mt("IPv6 address was incorrect length");let t=[];for(let n=0;n<e.byteLength;n+=2){let o=e[n],s=e[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let r=t.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new mt(`Invalid IPv6 address "${r}"`)}};function Bc(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new mt(`Invalid IPv6 address "${e}"`)}}var Ks=Object.values(Sr).map(e=>e.decoder),td=(function(){let e=Ks[0].or(Ks[1]);return Ks.slice(2).forEach(t=>e=e.or(t)),e})();function Pc(e){return td.decode(e)}function Lc(e){return t=>e.encoder.encode(t)}function ed(e){if(parseInt(e).toString()!==e)throw new ne("Value must be an integer")}function rd(e){if(e<0)throw new ne("Value must be a positive integer, or zero")}function nd(e){return t=>{if(t>e)throw new ne(`Value must be smaller than or equal to ${e}`)}}function od(...e){return t=>{for(let r of e)r(t)}}var Zr=od(ed,rd,nd(65535));var lt=-1,Hs=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let r;if(typeof t=="string"?r=this.protocolsByName.get(t):r=this.protocolsByCode.get(t),r==null)throw new Pn(`Protocol ${t} was unknown`);return r}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(r=>{this.protocolsByName.set(r,t)})}removeProtocol(t){let r=this.protocolsByCode.get(t);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},se=new Hs,gd=[{code:4,name:"ip4",size:32,valueToBytes:qs,bytesToValue:Dc,validate:e=>{if(!or(e))throw new ne(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Te,bytesToValue:sr,validate:Zr},{code:273,name:"udp",size:16,valueToBytes:Te,bytesToValue:sr,validate:Zr},{code:33,name:"dccp",size:16,valueToBytes:Te,bytesToValue:sr,validate:Zr},{code:41,name:"ip6",size:128,valueToBytes:Cc,bytesToValue:Tc,stringToValue:Bc,validate:e=>{if(!Nn(e))throw new ne(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:lt},{code:43,name:"ipcidr",size:8,bytesToValue:Ms("base10"),valueToBytes:Vs("base10")},{code:53,name:"dns",size:lt},{code:54,name:"dns4",size:lt},{code:55,name:"dns6",size:lt},{code:56,name:"dnsaddr",size:lt},{code:132,name:"sctp",size:16,valueToBytes:Te,bytesToValue:sr,validate:Zr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:lt,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:lt,bytesToValue:Ms("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?Vs("base58btc")(e):at.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Fs,valueToBytes:Ac},{code:445,name:"onion3",size:296,bytesToValue:Fs,valueToBytes:_c},{code:446,name:"garlic64",size:lt},{code:447,name:"garlic32",size:lt},{code:448,name:"tls"},{code:449,name:"sni",size:lt},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:lt,bytesToValue:Lc(bo),valueToBytes:Pc},{code:480,name:"http"},{code:481,name:"http-path",size:lt,stringToValue:e=>`/${decodeURIComponent(e)}`,valueToString:e=>encodeURIComponent(e.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:lt}];gd.forEach(e=>{se.addProtocol(e)});function Oc(e){let t=[],r=0;for(;r<e.length;){let n=Nr(e,r),o=se.getProtocol(n),s=At(n),i=xd(o,e,r+s),c=0;i>0&&o.size===lt&&(c=At(i));let a=s+c+i,f={code:n,name:o.name,bytes:e.subarray(r,r+a)};if(i>0){let u=r+s+c,l=e.subarray(u,u+i);f.value=o.bytesToValue?.(l)??H(l)}t.push(f),r+=a}return t}function Rc(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=se.getProtocol(n.code),s=At(n.code),i,c=0,a=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??F(n.value),c=i.byteLength,o.size===lt&&(a=At(c)));let f=new Uint8Array(s+a+c),u=0;je(n.code,f,u),u+=s,i!=null&&(o.size===lt&&(je(c,f,u),u+=a),f.set(i,u)),n.bytes=f}r.push(n.bytes),t+=n.bytes.byteLength}return Gt(r,t)}function Nc(e){if(e.charAt(0)!=="/")throw new mt('String multiaddr must start with "/"');let t=[],r="protocol",n="",o="";for(let s=1;s<e.length;s++){let i=e.charAt(s);i!=="/"&&(r==="protocol"?o+=e.charAt(s):n+=e.charAt(s));let c=s===e.length-1;if(i==="/"||c){let a=se.getProtocol(o);if(r==="protocol"){if(a.size==null||a.size===0){t.push({code:a.code,name:a.name}),n="",o="",r="protocol";continue}else if(c)throw new mt(`Component ${o} was missing value`);r="value"}else if(r==="value"){let f={code:a.code,name:a.name};if(a.size!=null&&a.size!==0){if(n==="")throw new mt(`Component ${o} was missing value`);f.value=a.stringToValue?.(n)??n}t.push(f),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new mt("Incomplete multiaddr");return t}function kc(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=se.getProtocol(t.code);if(r==null)throw new mt(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function xd(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:Nr(t,r)}var wd=Symbol.for("nodejs.util.inspect.custom"),oi=Symbol.for("@multiformats/multiaddr");function Ed(e){if(e==null&&(e="/"),Uc(e))return e.getComponents();if(e instanceof Uint8Array)return Oc(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),Nc(e);if(Array.isArray(e))return e;throw new mt("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Fn=class e{[oi]=!0;#t;#e;#r;constructor(t="/",r={}){this.#t=Ed(t),r.validate!==!1&&vd(this)}get bytes(){return this.#r==null&&(this.#r=Rc(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=kc(this.#t)),this.#e}toJSON(){return this.toString()}getComponents(){return[...this.#t.map(t=>({...t}))]}encapsulate(t){let r=new e(t);return new e([...this.#t,...r.getComponents()],{validate:!1})}decapsulate(t){let r=t.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new Bn(`Address ${this.toString()} does not contain subaddress: ${r}`);return new e(n.slice(0,o),{validate:!1})}decapsulateCode(t){let r;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){r=n;break}return new e(this.#t.slice(0,r),{validate:!1})}equals(t){return ct(this.bytes,t.bytes)}[wd](){return`Multiaddr(${this.toString()})`}};function vd(e){e.getComponents().forEach(t=>{let r=se.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function Uc(e){return!!e?.[oi]}function Pe(e){return new Fn(e)}var Kc="libp2p-peer-record",Mc=Uint8Array.from([3,1]);var Wr;(function(e){let t;(function(i){let c;i.codec=()=>(c==null&&(c=kt((l,h,p={})=>{p.lengthDelimited!==!1&&h.fork(),l.multiaddr!=null&&l.multiaddr.byteLength>0&&(h.uint32(10),h.bytes(l.multiaddr)),p.lengthDelimited!==!1&&h.ldelim()},(l,h,p={})=>{let d={multiaddr:ht(0)},E=h==null?l.len:l.pos+h;for(;l.pos<E;){let S=l.uint32();S>>>3===1?d.multiaddr=l.bytes():l.skipType(S&7)}return d},function*(l,h,p,d={}){let E=h==null?l.len:l.pos+h;for(;l.pos<E;){let S=l.uint32();S>>>3===1?yield{field:`${p}.multiaddr`,value:l.bytes()}:l.skipType(S&7)}})),c);function a(l){return Rt(l,i.codec())}i.encode=a;function f(l,h){return Ot(l,i.codec(),h)}i.decode=f;function u(l,h){return Nt(l,i.codec(),h)}i.stream=u})(t=e.AddressInfo||(e.AddressInfo={}));let r;e.codec=()=>(r==null&&(r=kt((i,c,a={})=>{if(a.lengthDelimited!==!1&&c.fork(),i.peerId!=null&&i.peerId.byteLength>0&&(c.uint32(10),c.bytes(i.peerId)),i.seq!=null&&i.seq!==0n&&(c.uint32(16),c.uint64(i.seq)),i.addresses!=null&&i.addresses.length>0)for(let f of i.addresses)c.uint32(26),e.AddressInfo.codec().encode(f,c);a.lengthDelimited!==!1&&c.ldelim()},(i,c,a={})=>{let f={peerId:ht(0),seq:0n,addresses:[]},u=c==null?i.len:i.pos+c;for(;i.pos<u;){let l=i.uint32();switch(l>>>3){case 1:{f.peerId=i.bytes();break}case 2:{f.seq=i.uint64();break}case 3:{if(a.limits?.addresses!=null&&f.addresses.length===a.limits.addresses)throw new Ht('Decode error - repeated field "addresses" had too many elements');f.addresses.push(e.AddressInfo.codec().decode(i,i.uint32(),{limits:a.limits?.addresses$}));break}default:{i.skipType(l&7);break}}}return f},function*(i,c,a,f={}){let u={addresses:0},l=c==null?i.len:i.pos+c;for(;i.pos<l;){let h=i.uint32();switch(h>>>3){case 1:{yield{field:`${a}.peerId`,value:i.bytes()};break}case 2:{yield{field:`${a}.seq`,value:i.uint64()};break}case 3:{if(f.limits?.addresses!=null&&u.addresses===f.limits.addresses)throw new Ht('Streaming decode error - repeated field "addresses" had too many elements');for(let p of e.AddressInfo.codec().stream(i,i.uint32(),`${a}.addresses[]`,{limits:f.limits?.addresses$}))yield{...p,index:u.addresses};u.addresses++;break}default:{i.skipType(h&7);break}}}})),r);function n(i){return Rt(i,e.codec())}e.encode=n;function o(i,c){return Ot(i,e.codec(),c)}e.decode=o;function s(i,c){return Nt(i,e.codec(),c)}e.stream=s})(Wr||(Wr={}));function Vc(e,t){let r=(n,o)=>n.toString().localeCompare(o.toString());return e.length!==t.length?!1:(t.sort(r),e.sort(r).every((n,o)=>t[o].equals(n)))}var Ut=class e{static createFromProtobuf=t=>{let r=Wr.decode(t),n=Us(wr(r.peerId)),o=(r.addresses??[]).map(i=>Pe(i.multiaddr)),s=r.seq;return new e({peerId:n,multiaddrs:o,seqNumber:s})};static DOMAIN=Kc;static CODEC=Mc;peerId;multiaddrs;seqNumber;domain=e.DOMAIN;codec=e.CODEC;marshaled;constructor(t){let{peerId:r,multiaddrs:n,seqNumber:o}=t;this.peerId=r,this.multiaddrs=n??[],this.seqNumber=o??BigInt(Date.now())}marshal(){return this.marshaled==null&&(this.marshaled=Wr.encode({peerId:this.peerId.toMultihash().bytes,seq:BigInt(this.seqNumber),addresses:this.multiaddrs.map(t=>({multiaddr:t.bytes}))})),this.marshaled}equals(t){return!(!(t instanceof e)||!this.peerId.equals(t.peerId)||this.seqNumber!==t.seqNumber||!Vc(this.multiaddrs,t.multiaddrs))}};function qn(e){let t=e.getComponents(),r={},n=0;if(t[n]?.name==="ip6zone"&&(r.zone=`${t[n].value}`,n++),t[n].name==="ip4"||t[n].name==="ip6"||t[n].name==="dns"||t[n].name==="dns4"||t[n].name==="dns6"?(r.type=t[n].name,r.host=t[n].value,n++):t[n].name==="dnsaddr"&&(r.type=t[n].name,r.host=`_dnsaddr.${t[n].value}`,n++),(t[n]?.name==="tcp"||t[n]?.name==="udp")&&(r.protocol=t[n].name==="tcp"?"tcp":"udp",r.port=parseInt(`${t[n].value}`),n++),t[n]?.name==="ipcidr"&&(r.type==="ip4"?r.cidr=parseInt(`${t[n].value}`):r.type==="ip6"&&(r.cidr=`${t[n].value}`),n++),r.type==null||r.host==null)throw new Q(`Multiaddr ${e} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return t[n]?.name==="tls"&&t[n+1]?.name==="sni"&&(r.sni=t[n+1].value,n+=2),r}function Fc(e,t,r){let n=0;for(let o of e)if(!(n<t)){if(n>r)break;if(o!==255)return!1;n++}return!0}function qc(e,t,r,n){let o=0;for(let s of e)if(!(o<r)){if(o>n)break;if(s!==t[o])return!1;o++}return!0}function si(e){switch(e.length){case Le:return e.join(".");case Oe:{let t=[];for(let r=0;r<e.length;r++)r%2===0&&t.push(e[r].toString(16).padStart(2,"0")+e[r+1].toString(16).padStart(2,"0"));return t.join(":")}default:throw new Error("Invalid ip length")}}function Hc(e){let t=0;for(let[r,n]of e.entries()){if(n===255){t+=8;continue}for(;(n&128)!=0;)t++,n=n<<1;if((n&128)!=0)return-1;for(let o=r+1;o<e.length;o++)if(e[o]!=0)return-1;break}return t}function zc(e){let t="0x";for(let r of e)t+=(r>>4).toString(16)+(r&15).toString(16);return t}var Le=4,Oe=16,Mg=parseInt("0xFFFF",16),Sd=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function jr(e,t){t.length===Oe&&e.length===Le&&Fc(t,0,11)&&(t=t.slice(12)),t.length===Le&&e.length===Oe&&qc(e,Sd,0,11)&&(e=e.slice(12));let r=e.length;if(r!=t.length)throw new Error("Failed to mask ip");let n=new Uint8Array(r);for(let o=0;o<r;o++)n[o]=e[o]&t[o];return n}function $c(e,t){if(typeof t=="string"&&(t=nr(t)),t==null)throw new Error("Invalid ip");if(t.length!==e.network.length)return!1;for(let r=0;r<t.length;r++)if((e.network[r]&e.mask[r])!==(t[r]&e.mask[r]))return!1;return!0}function ii(e){let[t,r]=e.split("/");if(!t||!r)throw new Error("Failed to parse given CIDR: "+e);let n=Le,o=On(t);if(o==null&&(n=Oe,o=Rn(t),o==null))throw new Error("Failed to parse given CIDR: "+e);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: "+e);let i=ai(s,8*n);return{network:jr(o,i),mask:i}}function ai(e,t){if(t!==8*Le&&t!==8*Oe)throw new Error("Invalid CIDR mask");if(e<0||e>t)throw new Error("Invalid CIDR mask");let r=t/8,n=new Uint8Array(r);for(let o=0;o<r;o++){if(e>=8){n[o]=255,e-=8;continue}n[o]=255-(255>>e),e=0}return n}var Xr=class{constructor(t,r){if(r==null)({network:this.network,mask:this.mask}=ii(t));else{let n=nr(t);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=nr(r);if(s==null)throw new Error("Failed to parse mask");this.mask=s}else this.mask=ai(o,8*n.length);this.network=jr(n,this.mask)}}contains(t){return $c({network:this.network,mask:this.mask},t)}toString(){let t=Hc(this.mask),r=t!==-1?String(t):zc(this.mask);return si(this.network)+"/"+r}};function Yc(e,t){return new Xr(e).contains(t)}function Zc(e){try{let t=qn(e);return t.type==="ip6"?Yc("2000::/3",t.host):!1}catch{return!1}}var Xc=Su(jc(),1),Bd=["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"],Pd=Bd.map(e=>new Xc.Netmask(e));function pi(e){for(let t of Pd)if(t.contains(e))return!0;return!1}function Ld(e){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(e)}function Od(e){let t=e.split(":");if(t.length<2)return!1;let r=t[t.length-1].padStart(4,"0"),n=t[t.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(r.substring(0,2),16)}.${parseInt(r.substring(2),16)}`;return pi(o)}function Rd(e){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(e)}function Nd(e){let t=e.split(":"),r=t[t.length-1];return pi(r)}function kd(e){return/^::$/.test(e)||/^::1$/.test(e)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(e)||/^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(e)||/^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(e)||/^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(e)||/^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(e)||/^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(e)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(e)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(e)||/^ff([0-9a-fA-F]{2,2}):/i.test(e)}function Qc(e){if(or(e))return pi(e);if(Ld(e))return Od(e);if(Rd(e))return Nd(e);if(Nn(e))return kd(e)}function Jc(e){try{let t=qn(e);switch(t.type){case"ip4":case"ip6":return Qc(t.host)??!1;default:return t.host==="localhost"}}catch{return!1}}function hr(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var mi=class e extends Error{name="TimeoutError";constructor(t,r){super(t,r),Error.captureStackTrace?.(this,e)}},tu=e=>e.reason??new DOMException("This operation was aborted.","AbortError");function yi(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=t,c,a,u=new Promise((l,h)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){h(tu(i));return}if(i&&(a=()=>{h(tu(i))},i.addEventListener("abort",a,{once:!0})),e.then(l,h),r===Number.POSITIVE_INFINITY)return;let p=new mi;c=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(d){h(d)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?l():o instanceof Error?h(o):(p.message=o??`Promise timed out after ${r} milliseconds`,h(p))},r)}).finally(()=>{u.clear(),a&&i&&i.removeEventListener("abort",a)});return u.clear=()=>{s.clearTimeout.call(void 0,c),c=void 0},u}var Ud=e=>{let t=e.addEventListener||e.on||e.addListener,r=e.removeEventListener||e.off||e.removeListener;if(!t||!r)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(e),removeListener:r.bind(e)}};function Kd(e,t,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 c=[t].flat(),a=[],{addListener:f,removeListener:u}=Ud(e),l=async(...p)=>{let d=r.multiArgs?p:p[0];if(r.filter)try{if(!await r.filter(d))return}catch(E){n(),i(E);return}a.push(d),r.count===a.length&&(n(),s(a))},h=(...p)=>{n(),i(r.rejectionMultiArgs?p:p[0])};n=()=>{for(let p of c)u(p,l);for(let p of r.rejectionEvents)c.includes(p)||u(p,h)};for(let p of c)f(p,l);for(let p of r.rejectionEvents)c.includes(p)||f(p,h);r.signal&&r.signal.addEventListener("abort",()=>{h(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(a)});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 eu(e,t,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=Kd(e,t,r),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function ru(e,t){let r,n=function(){let o=function(){r=void 0,e()};clearTimeout(r),r=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(r)},n}var Ne=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Md(e){return e.reason}async function bi(e,t,r){if(t==null)return e;let n=r?.translateError??Md;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let o;try{return await Promise.race([e,new Promise((s,i)=>{o=()=>{i(n(t))},t.addEventListener("abort",o)})])}finally{o!=null&&t.removeEventListener("abort",o)}}var Fd=4194304,zn=class extends Error{static name="UnwrappedError";name="UnwrappedError"},xi=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},wi=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},Ei=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function qd(e){return typeof e?.closeRead=="function"}function Hd(e){return typeof e?.close=="function"}function gi(e){return qd(e)?e.remoteWriteStatus!=="writable"&&e.readBufferLength===0:Hd(e)?e.status!=="open":!1}function zd(e){return e?.addEventListener!=null&&e?.removeEventListener!=null&&e?.send!=null&&e?.push!=null&&e?.log!=null}function $d(e,t){let r=t?.maxBufferSize??Fd,n=new it,o,s=!1;if(!zd(e))throw new Q("Argument should be a Stream or a Multiaddr");let i=u=>{if(n.append(u.data),n.byteLength>r){let l=n.byteLength;n.consume(n.byteLength),o?.reject(new Error(`Read buffer overflow - ${l} > ${r}`))}o?.resolve()};e.addEventListener("message",i);let c=u=>{u.error!=null?o?.reject(u.error):o?.resolve()};e.addEventListener("close",c);let a=()=>{o?.resolve()};e.addEventListener("remoteCloseWrite",a);let f={readBuffer:n,async read(u){if(s===!0)throw new zn("Stream was unwrapped");if(gi(e)){if(n.byteLength===0&&u?.bytes==null)return null;if(u?.bytes!=null&&n.byteLength<u.bytes)throw e.log.error("closed after reading %d/%d bytes",n.byteLength,u.bytes),new Ne(`Unexpected EOF - stream closed after reading ${n.byteLength}/${u.bytes} bytes`)}let l=u?.bytes??1;for(o=Promise.withResolvers();;){if(n.byteLength>=l){o.resolve();break}if(await bi(o.promise,u?.signal),gi(e)){if(n.byteLength===0&&u?.bytes==null)return null;break}o=Promise.withResolvers()}let h=u?.bytes??n.byteLength;if(n.byteLength<h){if(gi(e))throw e.log.error("closed while reading %d/%d bytes",n.byteLength,h),new Ne(`Unexpected EOF - stream closed while reading ${n.byteLength}/${h} bytes`);return f.read(u)}let p=n.sublist(0,h);return n.consume(h),p},async write(u,l){if(s===!0)throw new zn("Stream was unwrapped");e.send(u)||await eu(e,"drain",{signal:l?.signal,rejectionEvents:["close"]})},unwrap(){return s||(s=!0,e.removeEventListener("message",i),e.removeEventListener("close",c),e.removeEventListener("remoteCloseWrite",a),n.byteLength>0&&(e.log("stream unwrapped with %d unread bytes",n.byteLength),e.push(n))),e}};return f}function Yd(e,t={}){let r=$d(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=At(t.maxDataLength));let n=t?.lengthDecoder??Nr,o=t?.lengthEncoder??Xe;return{async read(i){let c=-1,a=new it;for(;;){let u=await r.read({...i,bytes:1});if(u==null)break;a.append(u);try{c=n(a)}catch(l){if(l instanceof RangeError)continue;throw l}if(c<0)throw new xi("Invalid message length");if(t?.maxLengthLength!=null&&a.byteLength>t.maxLengthLength)throw new Ei(`Message length length too long - ${a.byteLength} > ${t.maxLengthLength}`);if(c>-1)break}if(t?.maxDataLength!=null&&c>t.maxDataLength)throw new wi(`Message length too long - ${c} > ${t.maxDataLength}`);let f=await r.read({...i,bytes:c});if(f==null)throw e.log.error("tried to read %d bytes but the stream closed",c),new Ne(`Unexpected EOF - tried to read ${c} bytes but the stream closed`);if(f.byteLength!==c)throw e.log.error("read %d/%d bytes before the stream closed",f.byteLength,c),new Ne(`Unexpected EOF - read ${f.byteLength}/${c} bytes before the stream closed`);return f},async write(i,c){await r.write(new it(o(i.byteLength),i),c)},async writeV(i,c){let a=new it(...i.flatMap(f=>[o(f.byteLength),f]));await r.write(a,c)},unwrap(){return r.unwrap()}}}function pr(e,t){let r=Yd(e,t),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(c=>s.encode(c)),i)},pb:o=>({read:async s=>n.read(o,s),write:async(s,i)=>n.write(s,o,i),writeV:async(s,i)=>n.writeV(s,o,i),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}function Zd(e){return e[Symbol.asyncIterator]!=null}function Gd(e){if(Zd(e))return(async()=>{for await(let t of e);})();for(let t of e);}var nu=Gd;var $n=globalThis.CustomEvent??Event;async function*vi(e,t={}){let r=t.concurrency??1/0;r<1&&(r=1/0);let n=t.ordered??!1,o=new EventTarget,s=[],i=hr(),c=hr(),a=!1,f,u=!1;o.addEventListener("task-complete",()=>{c.resolve()}),Promise.resolve().then(async()=>{try{for await(let d of e){if(s.length===r&&(i=hr(),await i.promise),u)break;let E={done:!1};s.push(E),d().then(S=>{E.done=!0,E.ok=!0,E.value=S,o.dispatchEvent(new $n("task-complete"))},S=>{E.done=!0,E.err=S,o.dispatchEvent(new $n("task-complete"))})}a=!0,o.dispatchEvent(new $n("task-complete"))}catch(d){f=d,o.dispatchEvent(new $n("task-complete"))}});function l(){return n?s[0]?.done:!!s.find(d=>d.done)}function*h(){for(;s.length>0&&s[0].done;){let d=s[0];if(s.shift(),d.ok)yield d.value;else throw u=!0,i.resolve(),d.err;i.resolve()}}function*p(){for(;l();)for(let d=0;d<s.length;d++)if(s[d].done){let E=s[d];if(s.splice(d,1),d--,E.ok)yield E.value;else throw u=!0,i.resolve(),E.err;i.resolve()}}for(;;){if(l()||(c=hr(),await c.promise),f!=null||(n?yield*h():yield*p(),f!=null))throw f;if(a&&s.length===0)break}}var ou="0.1.0";var su="id/push",iu="1.0.0",au="1.0.0";var be;(function(e){let t;e.codec=()=>(t==null&&(t=kt((s,i,c={})=>{if(c.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 a of s.listenAddrs)i.uint32(18),i.bytes(a);if(s.observedAddr!=null&&(i.uint32(34),i.bytes(s.observedAddr)),s.protocols!=null&&s.protocols.length>0)for(let a of s.protocols)i.uint32(26),i.string(a);s.signedPeerRecord!=null&&(i.uint32(66),i.bytes(s.signedPeerRecord)),c.lengthDelimited!==!1&&i.ldelim()},(s,i,c={})=>{let a={listenAddrs:[],protocols:[]},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let u=s.uint32();switch(u>>>3){case 5:{a.protocolVersion=s.string();break}case 6:{a.agentVersion=s.string();break}case 1:{a.publicKey=s.bytes();break}case 2:{if(c.limits?.listenAddrs!=null&&a.listenAddrs.length===c.limits.listenAddrs)throw new Ht('Decode error - repeated field "listenAddrs" had too many elements');a.listenAddrs.push(s.bytes());break}case 4:{a.observedAddr=s.bytes();break}case 3:{if(c.limits?.protocols!=null&&a.protocols.length===c.limits.protocols)throw new Ht('Decode error - repeated field "protocols" had too many elements');a.protocols.push(s.string());break}case 8:{a.signedPeerRecord=s.bytes();break}default:{s.skipType(u&7);break}}}return a},function*(s,i,c,a={}){let f={listenAddrs:0,protocols:0},u=i==null?s.len:s.pos+i;for(;s.pos<u;){let l=s.uint32();switch(l>>>3){case 5:{yield{field:`${c}.protocolVersion`,value:s.string()};break}case 6:{yield{field:`${c}.agentVersion`,value:s.string()};break}case 1:{yield{field:`${c}.publicKey`,value:s.bytes()};break}case 2:{if(a.limits?.listenAddrs!=null&&f.listenAddrs===a.limits.listenAddrs)throw new Ht('Streaming decode error - repeated field "listenAddrs" had too many elements');yield{field:`${c}.listenAddrs[]`,index:f.listenAddrs,value:s.bytes()},f.listenAddrs++;break}case 4:{yield{field:`${c}.observedAddr`,value:s.bytes()};break}case 3:{if(a.limits?.protocols!=null&&f.protocols===a.limits.protocols)throw new Ht('Streaming decode error - repeated field "protocols" had too many elements');yield{field:`${c}.protocols[]`,index:f.protocols,value:s.string()},f.protocols++;break}case 8:{yield{field:`${c}.signedPeerRecord`,value:s.bytes()};break}default:{s.skipType(l&7);break}}}})),t);function r(s){return Rt(s,e.codec())}e.encode=r;function n(s,i){return Ot(s,e.codec(),i)}e.decode=n;function o(s,i){return Nt(s,e.codec(),i)}e.stream=o})(be||(be={}));var _t={protocolPrefix:"ipfs",timeout:5e3,maxInboundStreams:1,maxOutboundStreams:1,maxObservedAddresses:10,maxMessageSize:8192,runOnConnectionOpen:!0,runOnSelfUpdate:!0,runOnLimitedConnection:!0,concurrency:32};function cu(e){if(e!=null&&e.length>0)try{return Pe(e)}catch{}}async function Yn(e,t,r,n,o){if(r("received identify from %p",n.remotePeer),o==null)throw new Tt("message was null or undefined");let s={};if(o.listenAddrs.length>0&&(s.addresses=o.listenAddrs.map(a=>({isCertified:!1,multiaddr:Pe(a)}))),o.protocols.length>0&&(s.protocols=o.protocols),o.publicKey!=null){let a=er(o.publicKey);if(!Sc(a).equals(n.remotePeer))throw new Tt("public key did not match remote PeerId");s.publicKey=a}let i;if(o.signedPeerRecord!=null){r.trace("received signedPeerRecord from %p",n.remotePeer);let a=o.signedPeerRecord,f=await $t.openAndCertify(a,Ut.DOMAIN),u=Ut.createFromProtobuf(f.payload),l=Tn(f.publicKey.toCID());if(!u.peerId.equals(l))throw new Tt("signing key does not match PeerId in the PeerRecord");if(!n.remotePeer.equals(u.peerId))throw new Tt("signing key does not match remote PeerId");let h;try{h=await e.get(u.peerId)}catch(p){if(p.name!=="NotFoundError")throw p}if(h!=null&&(s.metadata=h.metadata,h.peerRecordEnvelope!=null)){let p=$t.createFromProtobuf(h.peerRecordEnvelope),d=Ut.createFromProtobuf(p.payload);d.seqNumber>=u.seqNumber&&(r("sequence number was lower or equal to existing sequence number - stored: %d received: %d",d.seqNumber,u.seqNumber),u=d,a=h.peerRecordEnvelope)}s.peerRecordEnvelope=a,s.addresses=u.multiaddrs.map(p=>({isCertified:!0,multiaddr:p})),i={seq:u.seqNumber,addresses:u.multiaddrs}}else r("%p did not send a signed peer record",n.remotePeer);if(r.trace("patching %p with",n.remotePeer,s),await e.patch(n.remotePeer,s),o.agentVersion!=null||o.protocolVersion!=null){let a={};o.agentVersion!=null&&(a.AgentVersion=F(o.agentVersion)),o.protocolVersion!=null&&(a.ProtocolVersion=F(o.protocolVersion)),r.trace("merging %p metadata",n.remotePeer,a),await e.merge(n.remotePeer,{metadata:a})}let c={peerId:n.remotePeer,protocolVersion:o.protocolVersion,agentVersion:o.agentVersion,publicKey:o.publicKey,listenAddrs:o.listenAddrs.map(a=>Pe(a)),observedAddr:o.observedAddr==null?void 0:Pe(o.observedAddr),protocols:o.protocols,signedPeerRecord:i,connection:n};return t.safeDispatchEvent("peer:identify",{detail:c}),c}var mr=class{host;components;protocol;started;timeout;maxInboundStreams;maxOutboundStreams;maxMessageSize;maxObservedAddresses;runOnLimitedConnection;log;constructor(t,r){this.protocol=r.protocol,this.started=!1,this.components=t,this.log=r.log,this.timeout=r.timeout??_t.timeout,this.maxInboundStreams=r.maxInboundStreams??_t.maxInboundStreams,this.maxOutboundStreams=r.maxOutboundStreams??_t.maxOutboundStreams,this.maxMessageSize=r.maxMessageSize??_t.maxMessageSize,this.maxObservedAddresses=r.maxObservedAddresses??_t.maxObservedAddresses,this.runOnLimitedConnection=r.runOnLimitedConnection??_t.runOnLimitedConnection,this.host={protocolVersion:`${r.protocolPrefix??_t.protocolPrefix}/${ou}`,agentVersion:t.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:F(this.host.agentVersion),ProtocolVersion:F(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 Zn=class extends mr{connectionManager;concurrency;_push;constructor(t,r={}){super(t,{...r,protocol:`/${r.protocolPrefix??_t.protocolPrefix}/${su}/${au}`,log:t.logger.forComponent("libp2p:identify-push")}),this.connectionManager=t.connectionManager,this.concurrency=r.concurrency??_t.concurrency,this._push=ru(this.sendPushMessage.bind(this),r.debounce??1e3),(r.runOnSelfUpdate??_t.runOnSelfUpdate)&&t.events.addEventListener("self:peer:update",n=>{this.push().catch(o=>{this.log.error("error pushing updates to peers - %e",o)})})}[nn]=["@libp2p/identify-push"];async push(){this._push()}async sendPushMessage(){if(this.isStarted())try{let t=this.components.addressManager.getAddresses().map(u=>u.decapsulateCode(421)),r=new Ut({peerId:this.components.peerId,multiaddrs:t}),n=await $t.seal(r,this.components.privateKey),o=this.components.registrar.getProtocols(),s=await this.components.peerStore.get(this.components.peerId),i=H(s.metadata.get("AgentVersion")??F(this.host.agentVersion)),c=H(s.metadata.get("ProtocolVersion")??F(this.host.protocolVersion)),a=this;async function*f(){for(let u of a.connectionManager.getConnections())(await a.components.peerStore.get(u.remotePeer)).protocols.includes(a.protocol)&&(yield async()=>{let h,p=AbortSignal.timeout(a.timeout);try{h=await u.newStream(a.protocol,{signal:p,runOnLimitedConnection:a.runOnLimitedConnection}),await pr(h,{maxDataLength:a.maxMessageSize}).pb(be).write({listenAddrs:t.map(E=>E.bytes),signedPeerRecord:n.marshal(),protocols:o,agentVersion:i,protocolVersion:c},{signal:p}),await h.close({signal:p})}catch(d){h?.log.newScope("identify-push")?.error("could not push identify update to peer",d),h?.abort(d)}})}await nu(vi(f(),{concurrency:this.concurrency}))}catch(t){this.log.error("error pushing updates to peers - %e",t)}}async handleProtocol(t,r){let n=t.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)},i=await pr(t,{maxDataLength:this.maxMessageSize}).pb(be).read(o);await t.close(o),await Yn(this.components.peerStore,this.components.events,n,r,i),n.trace("handled push from %p",r.remotePeer)}};var G=e=>({match:t=>{let r=t[0];return r==null||r.code!==e||r.value!=null?!1:t.slice(1)}}),L=(e,t)=>({match:r=>{let n=r[0];return n?.code!==e||n.value==null||t!=null&&n.value!==t?!1:r.slice(1)}}),uu=e=>({match:t=>e.match(t)===!1?t:!1}),q=e=>({match:t=>{let r=e.match(t);return r===!1?t:r}}),xt=(...e)=>({match:t=>{let r;for(let n of e){let o=n.match(t);o!==!1&&(r==null||o.length<r.length)&&(r=o)}return r??!1}}),Y=(...e)=>({match:t=>{for(let r of e){let n=r.match(t);if(n===!1)return!1;t=n}return t}});function W(...e){function t(o){if(o==null)return!1;let s=o.getComponents();for(let i of e){let c=i.match(s);if(c===!1)return!1;s=c}return s}function r(o){return t(o)!==!1}function n(o){let s=t(o);return s===!1?!1:s.length===0}return{matchers:e,matches:r,exactMatch:n}}var Qd=L(421),ww=W(Qd),Wn=L(54),jn=L(55),Xn=L(56),Ii=L(53),Ew=W(Wn,q(L(421))),vw=W(jn,q(L(421))),Sw=W(Xn,q(L(421))),Iw=W(xt(Ii,Xn,Wn,jn),q(L(421))),fu=Y(L(4),q(L(43))),lu=Y(q(L(42)),L(41),q(L(43))),Ai=xt(fu,lu),yr=xt(Ai,Ii,Wn,jn,Xn),du=W(xt(Ai,Y(xt(Ii,Xn,Wn,jn),q(L(421))))),Aw=W(fu),_w=W(lu),Cw=W(Ai),_i=Y(yr,L(6)),Qr=Y(yr,L(273)),hu=W(Y(_i,q(L(421)))),Dw=W(Qr),Ci=Y(Qr,G(460),q(L(421))),Qn=Y(Qr,G(461),q(L(421))),Jd=xt(Ci,Qn),Tw=W(Ci),Bw=W(Qn),Si=xt(yr,_i,Qr,Ci,Qn),pu=xt(Y(Si,G(477),q(L(421)))),Pw=W(pu),mu=xt(Y(Si,G(478),q(L(421))),Y(Si,G(448),q(L(449)),G(477),q(L(421)))),Lw=W(mu),yu=Y(Qr,G(280),q(L(466)),q(L(466)),q(L(421))),Ow=W(yu),bu=Y(Qn,G(465),q(L(466)),q(L(466)),q(L(421))),Rw=W(bu),Gn=xt(pu,mu,Y(_i,q(L(421))),Y(Jd,q(L(421))),Y(yr,q(L(421))),yu,bu,L(421)),Nw=W(Gn),th=Y(q(Gn),G(290),uu(G(281)),q(L(421))),kw=W(th),eh=xt(Y(Gn,G(290),G(281),q(L(421))),Y(Gn,G(281),q(L(421))),Y(G(281),q(L(421)))),Uw=W(eh),rh=Y(yr,xt(Y(L(6,"80")),Y(L(6),G(480)),G(480)),q(L(481)),q(L(421))),Kw=W(rh),nh=Y(yr,xt(Y(L(6,"443")),Y(L(6,"443"),G(480)),Y(L(6),G(443)),Y(L(6),G(448),G(480)),Y(G(448),G(480)),G(448),G(443)),q(L(481)),q(L(421))),Mw=W(nh),oh=xt(Y(L(777),q(L(421)))),Vw=W(oh),sh=xt(Y(L(400),q(L(421)))),Fw=W(sh);var Jn=class extends mr{constructor(t,r={}){super(t,{...r,protocol:`/${r.protocolPrefix??_t.protocolPrefix}/${"id"}/${iu}`,log:t.logger.forComponent("libp2p:identify")}),(r.runOnConnectionOpen??_t.runOnConnectionOpen)&&t.events.addEventListener("connection:open",n=>{let o=n.detail;this.identify(o).catch(()=>{})})}[nn]=["@libp2p/identify"];async _identify(t,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",t.remoteAddr);try{n=await t.newStream(this.protocol,{...r,runOnLimitedConnection:this.runOnLimitedConnection}),o=n.log.newScope("identify");let s=pr(n,{maxDataLength:this.maxMessageSize}).pb(be),i=await s.read(r);return await s.unwrap().unwrap().close(r),i}catch(s){throw o?.error("identify failed - %e",s),n?.abort(s),s}}async identify(t,r={}){let n=await this._identify(t,r),{publicKey:o,protocols:s,observedAddr:i}=n;if(o==null)throw new Tt("Public key was missing from identify message");let c=er(o),a=Tn(c.toCID());if(!t.remotePeer.equals(a))throw new Tt("Identified peer does not match the expected peer");if(this.components.peerId.equals(a))throw new Tt("Identified peer is our own peer id?");return this.maybeAddObservedAddress(i),this.log("completed for peer %p and protocols %o",a,s),Yn(this.components.peerStore,this.components.events,this.log,t,n)}maybeAddObservedAddress(t){let r=cu(t);if(r==null||(this.log.trace("our observed address was %a",r),Jc(r)))return;let n=r.getComponents();if((n[0].code===41||n[0].code===42&&n[1].code===41)&&!Zc(r)){this.log.trace("our observed address was IPv6 but not a global unicast address");return}hu.exactMatch(r)||(this.log.trace("storing the observed address"),this.components.addressManager.addObservedAddr(r))}async handleProtocol(t,r){let n=t.log.newScope("identify");n("responding to identify");let o=AbortSignal.timeout(this.timeout);let s=await this.components.peerStore.get(this.components.peerId,{signal:o}),i=this.components.addressManager.getAddresses().map(u=>u.decapsulateCode(421)),c=s.peerRecordEnvelope;if(i.length>0&&c==null){let u=new Ut({peerId:this.components.peerId,multiaddrs:i});c=(await $t.seal(u,this.components.privateKey,{signal:o})).marshal().subarray()}let a=r.remoteAddr.bytes;du.matches(r.remoteAddr)||(a=void 0);let f=pr(t).pb(be);n("send response"),await f.write({protocolVersion:this.host.protocolVersion,agentVersion:this.host.agentVersion,publicKey:Vt(this.components.privateKey.publicKey),listenAddrs:i.map(u=>u.bytes),signedPeerRecord:c,observedAddr:a,protocols:s.protocols},{signal:o}),n("close write"),await f.unwrap().unwrap().close({signal:o})}};function ah(e={}){return t=>new Jn(t,e)}function ch(e={}){return t=>new Zn(t,e)}return Iu(uh);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/hashes/utils.js:
|